@tscircuit/runframe 0.0.3047 → 0.0.3048

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.
@@ -5416,7 +5416,7 @@ ${e.svg()}`;return I+=`" >
5416
5416
  `).map(I=>I.match(/\(([^)]+)\)/)[1]).map(gIg)}function cIo(g){return g.split(`
5417
5417
  `).map(I=>I.match(/\(([^)]+)\)/)[1]).map(IIg).reduce((I,e)=>[...I,...e],[])}function TMI(g){if(g.startsWith("POINT")){const A=g.replace(/^POINT \(/,"").replace(/\)$/,"");return gIg(A)}else if(g.startsWith("MULTIPOINT")){const A=g.replace(/^MULTIPOINT \(/,"").replace(/\)$/,"");return vMI(A)}else if(g.startsWith("LINESTRING")){const A=g.replace(/^LINESTRING \(/,"").replace(/\)$/,"");return IIg(A)}else if(g.startsWith("MULTILINESTRING")){const A=g.replace(/^MULTILINESTRING /,"");return nIo(A)}else{if(g.startsWith("POLYGON")||g.startsWith("MULTIPOLYGON"))return aIo(g);if(g.startsWith("GEOMETRYCOLLECTION")){const A=/(?<type>POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON) \((?:[^\(\)]|\([^\)]*\))*\)/g,I=g.match(A);return I[0].startsWith("GEOMETRYCOLLECTION")&&(I[0]=I[0].replace("GEOMETRYCOLLECTION (","")),I.map(TMI).map(t=>t instanceof Array?t:[t]).reduce((t,o)=>[...t,...o],[])}else{if(ZMI(g))return rIo(g);if(OMI(g))return cIo(g)}}return[]}function ZMI(g){return g.split(`
5418
5418
  `)?.every(A=>A.includes("POINT"))}function OMI(g){return g.split(`
5419
- `)?.every(A=>A.includes("LINESTRING"))}function hIo(g){return g.startsWith("POINT")||ZMI(g)||g.startsWith("LINESTRING")||OMI(g)||g.startsWith("MULTILINESTRING")||g.startsWith("POLYGON")||g.startsWith("MULTIPOINT")||g.startsWith("MULTIPOLYGON")||g.startsWith("GEOMETRYCOLLECTION")}jA.isWktString=hIo,jA.parseWKT=TMI,jA.BooleanOperations=wgo,jA.Relations=Jgo;function WMI(g,A,I){if(!A||!I)return;let e=g.get(A);e||(e=new Set,g.set(A,e)),e.add(I);let t=g.get(I);t||(t=new Set,g.set(I,t)),t.add(A)}function VMI(g,A){if(!A.subcircuit_id&&!A.source_group_id)return[...g];let I=A;if(A.subcircuit_id){const C=new Set([A.subcircuit_id]),Q=new Map,i=new Map;for(const n of g)if(n.type==="source_group"){const s=n.source_group_id,r=n.subcircuit_id;r&&i.set(s,r);const a=n.parent_source_group_id;a&&(Q.has(a)||Q.set(a,[]),Q.get(a).push(s))}let E;for(const[n,s]of i)if(s===A.subcircuit_id){E=n;break}if(E){const n=s=>{const r=Q.get(s)||[];for(const a of r){const c=i.get(a);c&&C.add(c),n(a)}};n(E),I={...A,subcircuit_ids:Array.from(C)}}}const e=new Map;for(const C of g){const Q=`${C.type}_id`,i=C[Q];typeof i=="string"&&e.set(i,C)}const t=new Map;for(const C of g){const Q=Object.entries(C);for(const[i,E]of Q)if(i!=="parent_source_group_id"){if(i.endsWith("_id")&&typeof E=="string"){const n=e.get(E);WMI(t,C,n)}else if(i.endsWith("_ids")&&Array.isArray(E)){for(const n of E)if(typeof n=="string"){const s=e.get(n);WMI(t,C,s)}}}}const o=[],B=new Set;for(const C of g){let Q=!1;(I.subcircuit_id&&"subcircuit_id"in C&&C.subcircuit_id===I.subcircuit_id||I.subcircuit_ids&&"subcircuit_id"in C&&C.subcircuit_id&&I.subcircuit_ids.includes(C.subcircuit_id)||I.source_group_id&&"source_group_id"in C&&C.source_group_id===I.source_group_id||I.source_group_id&&"member_source_group_ids"in C&&Array.isArray(C.member_source_group_ids)&&C.member_source_group_ids.includes(I.source_group_id))&&(Q=!0),Q&&(o.push(C),B.add(C))}for(;o.length>0;){const C=o.shift(),Q=t.get(C);if(Q)for(const i of Q)B.has(i)||(B.add(i),o.push(i))}return g.filter(C=>B.has(C))}var CwA=(g,A={})=>{const I=g;let e=I._internal_store;if(!e){e={counts:{},editCount:0},I._internal_store=e;for(const o of I){const B=o.type,C=o[`${B}_id`];if(!C)continue;const Q=Number.parseInt(C.split("_").pop());Number.isNaN(Q)||(e.counts[B]=Math.max(e.counts[B]??0,Q))}}const t=new Proxy({},{get:(o,B)=>{if(B==="toArray")return()=>(I.editCount=e.editCount,I);if(B==="editCount")return e.editCount;if(B==="subtree")return Q=>CwA(VMI(I,Q),A);if(B==="insert")return Q=>{const i=Q.type;if(!i)throw new Error("insert requires an element with a type");e.counts[i]??=-1,e.counts[i]++;const E=e.counts[i],n={...Q,type:i,[`${i}_id`]:`${i}_${E}`};return A.validateInserts&&(uN[i]??wf).parse(n),I.push(n),e.editCount++,n};if(B==="insertAll")return Q=>Q.map(i=>t.insert(i));const C=B;return{get:Q=>I.find(i=>i.type===C&&i[`${C}_id`]===Q),getUsing:Q=>{const i=Object.keys(Q);if(i.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const E=i[0],n=E.replace("_id",""),s=I.find(r=>r.type===n&&r[E]===Q[E]);return s?I.find(r=>r.type===C&&r[`${C}_id`]===s[`${C}_id`]):null},getWhere:Q=>{const i=Object.keys(Q);return I.find(E=>E.type===C&&i.every(n=>E[n]===Q[n]))},list:Q=>{const i=Q?Object.keys(Q):[];return I.filter(E=>E.type===C&&i.every(n=>E[n]===Q[n]))},insert:Q=>{e.counts[C]??=-1,e.counts[C]++;const i=e.counts[C],E={type:C,[`${C}_id`]:`${C}_${i}`,...Q};return A.validateInserts&&(uN[C]??wf).parse(E),I.push(E),e.editCount++,E},delete:Q=>{const i=I.find(E=>E[`${C}_id`]===Q);i&&(I.splice(I.indexOf(i),1),e.editCount++)},update:(Q,i)=>{const E=I.find(n=>n.type===C&&n[`${C}_id`]===Q);return E?(Object.assign(E,i),e.editCount++,E):null},select:Q=>{if(C==="source_component")return I.find(i=>i.type==="source_component"&&i.name===Q.replace(/\./g,""));if(C==="pcb_port"||C==="source_port"||C==="schematic_port"){const[i,E]=Q.replace(/\./g,"").split(/[\s\>]+/),n=I.find(r=>r.type==="source_component"&&r.name===i);if(!n)return null;const s=I.find(r=>r.type==="source_port"&&r.source_component_id===n.source_component_id&&(r.name===E||(r.port_hints??[]).includes(E)));if(!s)return null;if(C==="source_port")return s;if(C==="pcb_port")return I.find(r=>r.type==="pcb_port"&&r.source_port_id===s.source_port_id);if(C==="schematic_port")return I.find(r=>r.type==="schematic_port"&&r.source_port_id===s.source_port_id)}}}}});return t};CwA.unparsed=CwA;var p5=CwA;function eIg(g){const A=g.type;return`${A}:${g[`${A}_id`]}`}var tIg=(g,A={})=>{let I=g._internal_store_indexed;if(!I){I={counts:{},editCount:0,indexes:{}};for(const B of g){const C=B.type,Q=B[`${C}_id`];if(!Q)continue;const i=Number.parseInt(Q.split("_").pop()||"");Number.isNaN(i)||(I.counts[C]=Math.max(I.counts[C]??0,i))}const t=A.indexConfig||{},o=I.indexes;if(t.byId&&(o.byId=new Map),t.byType&&(o.byType=new Map),t.byRelation&&(o.byRelation=new Map),t.bySubcircuit&&(o.bySubcircuit=new Map),t.byCustomField&&t.byCustomField.length>0){o.byCustomField=new Map;for(const B of t.byCustomField)o.byCustomField.set(B,new Map)}for(const B of g){if(t.byId){const C=eIg(B);o.byId.set(C,B)}if(t.byType){const C=o.byType.get(B.type)||[];C.push(B),o.byType.set(B.type,C)}if(t.byRelation){const C=Object.entries(B);for(const[Q,i]of C)if(Q.endsWith("_id")&&Q!==`${B.type}_id`&&typeof i=="string"){const E=o.byRelation.get(Q)||new Map,n=E.get(i)||[];n.push(B),E.set(i,n),o.byRelation.set(Q,E)}}if(t.bySubcircuit&&"subcircuit_id"in B){const C=B.subcircuit_id;if(C&&typeof C=="string"){const Q=o.bySubcircuit.get(C)||[];Q.push(B),o.bySubcircuit.set(C,Q)}}if(t.byCustomField&&o.byCustomField){for(const C of t.byCustomField)if(C in B){const Q=B[C];if(Q!==void 0&&(typeof Q=="string"||typeof Q=="number")){const i=String(Q),E=o.byCustomField.get(C),n=E.get(i)||[];n.push(B),E.set(i,n)}}}}g._internal_store_indexed=I}const e=new Proxy({},{get:(t,o)=>{if(o==="toArray")return()=>(g.editCount=I.editCount,g);if(o==="editCount")return I.editCount;if(o==="insert")return C=>{const{type:Q,...i}=C;if(!Q)throw new Error("insert requires an element with a type");return delete i[`${Q}_id`],e[Q].insert(i)};if(o==="insertAll")return C=>C.map(Q=>e.insert(Q));if(o==="subtree")return C=>tIg(VMI(g,C),A);const B=o;return{get:C=>{const Q=A.indexConfig||{};return Q.byId&&I.indexes.byId?I.indexes.byId.get(`${B}:${C}`)||null:Q.byType&&I.indexes.byType?(I.indexes.byType.get(B)||[]).find(E=>E[`${B}_id`]===C)||null:g.find(i=>i.type===B&&i[`${B}_id`]===C)||null},getUsing:C=>{const Q=A.indexConfig||{},i=Object.keys(C);if(i.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const E=i[0],n=E.replace("_id","");if(Q.byRelation&&I.indexes.byRelation){const r=I.indexes.byRelation.get(E);if(r){const c=(r.get(C[E])||[]).find(l=>l.type===n);if(!c)return null;const h=c[`${B}_id`];return Q.byId&&I.indexes.byId?I.indexes.byId.get(`${B}:${h}`)||null:Q.byType&&I.indexes.byType?(I.indexes.byType.get(B)||[]).find(D=>D[`${B}_id`]===h)||null:g.find(l=>l.type===B&&l[`${B}_id`]===h)||null}}const s=g.find(r=>r.type===n&&r[E]===C[E]);return s&&g.find(r=>r.type===B&&r[`${B}_id`]===s[`${B}_id`])||null},getWhere:C=>{const Q=A.indexConfig||{},i=Object.keys(C);if(i.length===1&&Q.byCustomField&&I.indexes.byCustomField){const E=i[0],n=I.indexes.byCustomField.get(E);if(n){const s=String(C[E]);return(n.get(s)||[]).find(a=>a.type===B)||null}}if("subcircuit_id"in C&&Q.bySubcircuit&&I.indexes.bySubcircuit){const E=C.subcircuit_id;return(I.indexes.bySubcircuit.get(E)||[]).find(s=>s.type===B&&i.every(r=>s[r]===C[r]))||null}return Q.byType&&I.indexes.byType?(I.indexes.byType.get(B)||[]).find(n=>i.every(s=>n[s]===C[s]))||null:g.find(E=>E.type===B&&i.every(n=>E[n]===C[n]))||null},list:C=>{const Q=A.indexConfig||{},i=C?Object.keys(C):[];if(i.length===0&&Q.byType&&I.indexes.byType)return(I.indexes.byType.get(B)||[]).slice();if(i.length===1&&i[0]==="subcircuit_id"&&Q.bySubcircuit&&I.indexes.bySubcircuit){const n=C.subcircuit_id;return(I.indexes.bySubcircuit.get(n)||[]).filter(r=>r.type===B)}let E;return Q.byType&&I.indexes.byType?E=I.indexes.byType.get(B)||[]:E=g.filter(n=>n.type===B),i.length>0?E.filter(n=>i.every(s=>n[s]===C[s])):E.slice()},insert:C=>{I.counts[B]??=-1,I.counts[B]++;const Q=I.counts[B],i={type:B,[`${B}_id`]:`${B}_${Q}`,...C};A.validateInserts&&(uN[B]??wf).parse(i),g.push(i),I.editCount++;const E=A.indexConfig||{};if(E.byId&&I.indexes.byId){const n=eIg(i);I.indexes.byId.set(n,i)}if(E.byType&&I.indexes.byType){const n=I.indexes.byType.get(B)||[];n.push(i),I.indexes.byType.set(B,n)}if(E.byRelation&&I.indexes.byRelation){const n=Object.entries(i);for(const[s,r]of n)if(s.endsWith("_id")&&s!==`${i.type}_id`&&typeof r=="string"){const a=I.indexes.byRelation.get(s)||new Map,c=a.get(r)||[];c.push(i),a.set(r,c),I.indexes.byRelation.set(s,a)}}if(E.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in i){const n=i.subcircuit_id;if(n&&typeof n=="string"){const s=I.indexes.bySubcircuit.get(n)||[];s.push(i),I.indexes.bySubcircuit.set(n,s)}}if(E.byCustomField&&I.indexes.byCustomField){for(const n of E.byCustomField)if(n in i){const s=i[n];if(s!==void 0&&(typeof s=="string"||typeof s=="number")){const r=String(s),a=I.indexes.byCustomField.get(n),c=a.get(r)||[];c.push(i),a.set(r,c)}}}return i},delete:C=>{const Q=A.indexConfig||{};let i;if(Q.byId&&I.indexes.byId?i=I.indexes.byId.get(`${B}:${C}`):Q.byType&&I.indexes.byType?i=(I.indexes.byType.get(B)||[]).find(s=>s[`${B}_id`]===C):i=g.find(n=>n[`${B}_id`]===C),!i)return;const E=g.indexOf(i);if(E>=0&&(g.splice(E,1),I.editCount++),Q.byId&&I.indexes.byId){const n=eIg(i);I.indexes.byId.delete(n)}if(Q.byType&&I.indexes.byType){const s=(I.indexes.byType.get(B)||[]).filter(r=>r[`${B}_id`]!==C);I.indexes.byType.set(B,s)}if(Q.byRelation&&I.indexes.byRelation)for(const[n,s]of I.indexes.byRelation.entries())for(const[r,a]of s.entries()){const c=a.filter(h=>h!==i);c.length===0?s.delete(r):s.set(r,c)}if(Q.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in i){const n=i.subcircuit_id;if(n){const r=(I.indexes.bySubcircuit.get(n)||[]).filter(a=>a!==i);r.length===0?I.indexes.bySubcircuit.delete(n):I.indexes.bySubcircuit.set(n,r)}}if(Q.byCustomField&&I.indexes.byCustomField)for(const n of I.indexes.byCustomField.values())for(const[s,r]of n.entries()){const a=r.filter(c=>c!==i);a.length===0?n.delete(s):n.set(s,a)}},update:(C,Q)=>{const i=A.indexConfig||{};let E;if(i.byId&&I.indexes.byId?E=I.indexes.byId.get(`${B}:${C}`):i.byType&&I.indexes.byType?E=(I.indexes.byType.get(B)||[]).find(s=>s[`${B}_id`]===C):E=g.find(n=>n.type===B&&n[`${B}_id`]===C),!E)return null;if(i.byRelation&&I.indexes.byRelation){const n=Object.entries(E);for(const[s,r]of n)if(s.endsWith("_id")&&s!==`${E.type}_id`&&typeof r=="string"&&s in Q&&Q[s]!==r){const a=I.indexes.byRelation.get(s);if(a){const h=(a.get(r)||[]).filter(l=>l!==E);h.length===0?a.delete(r):a.set(r,h)}}}if(i.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in E&&"subcircuit_id"in Q){const n=E.subcircuit_id,s=Q.subcircuit_id;if(n!==s){const a=(I.indexes.bySubcircuit.get(n)||[]).filter(c=>c!==E);a.length===0?I.indexes.bySubcircuit.delete(n):I.indexes.bySubcircuit.set(n,a)}}if(i.byCustomField&&I.indexes.byCustomField){for(const n of i.byCustomField)if(n in E&&n in Q&&E[n]!==Q[n]){const s=I.indexes.byCustomField.get(n);if(s){const r=String(E[n]),c=(s.get(r)||[]).filter(h=>h!==E);c.length===0?s.delete(r):s.set(r,c)}}}if(Object.assign(E,Q),I.editCount++,i.byRelation&&I.indexes.byRelation){const n=Object.entries(E);for(const[s,r]of n)if(s.endsWith("_id")&&s!==`${E.type}_id`&&typeof r=="string"&&s in Q){const a=I.indexes.byRelation.get(s)||new Map,c=a.get(r)||[];c.includes(E)||(c.push(E),a.set(r,c),I.indexes.byRelation.set(s,a))}}if(i.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in E&&"subcircuit_id"in Q){const n=E.subcircuit_id;if(n&&typeof n=="string"){const s=I.indexes.bySubcircuit.get(n)||[];s.includes(E)||(s.push(E),I.indexes.bySubcircuit.set(n,s))}}if(i.byCustomField&&I.indexes.byCustomField){for(const n of i.byCustomField)if(n in E&&n in Q){const s=E[n];if(s!==void 0&&(typeof s=="string"||typeof s=="number")){const r=String(s),a=I.indexes.byCustomField.get(n),c=a.get(r)||[];c.includes(E)||(c.push(E),a.set(r,c))}}}return E},select:C=>{if(B==="source_component")return g.find(Q=>Q.type==="source_component"&&Q.name===C.replace(/\./g,""))||null;if(B==="pcb_port"||B==="source_port"||B==="schematic_port"){const[Q,i]=C.replace(/\./g,"").split(/[\s\>]+/),E=g.find(s=>s.type==="source_component"&&s.name===Q);if(!E)return null;const n=g.find(s=>s.type==="source_port"&&s.source_component_id===E.source_component_id&&(s.name===i||(s.port_hints??[]).includes(i)));if(!n)return null;if(B==="source_port")return n;if(B==="pcb_port")return g.find(s=>s.type==="pcb_port"&&s.source_port_id===n.source_port_id)||null;if(B==="schematic_port")return g.find(s=>s.type==="schematic_port"&&s.source_port_id===n.source_port_id)||null}return null}}}});return e};tIg.unparsed=tIg;var lIo=g=>Math.round(g/(Math.PI/2)),DIo=g=>{switch(g){case"from_left":return{x:-1,y:0};case"from_right":return{x:1,y:0};case"from_top":return{x:0,y:1};case"from_bottom":return{x:0,y:-1}}},dIo=({x:g,y:A})=>g>0?"from_right":g<0?"from_left":A>0?"from_top":"from_bottom",yIo=(g,A)=>{if(!g)return g;if(g==="from_above"||g==="from_below")return A.isFlipped?g==="from_above"?"from_below":"from_above":g;let{x:I,y:e}=DIo(g),t=Math.round(A.rotationDegrees/90);for(;t>0;)[I,e]=[-e,I],t--;for(;t<0;)[I,e]=[e,-I],t++;return A.isFlipped&&(e=-e),dIo({x:I,y:e})},wIo=(g,A)=>{if(g.shape==="polygon")return g.points=g.points.map(B=>Mt(A,B)),g;const I=Mt(A,{x:g.x,y:g.y});if(g.x=I.x,g.y=I.y,g.shape==="circle")return g;const e=g.shape==="rotated_rect"?g.ccw_rotation:0,t=A.a*A.d-A.b*A.c<0,o=tkI(Yw(A,B$t(e)),!1,t).rotation.angle*180/Math.PI;return Math.abs(o)<1e-8?(Object.assign(g,{shape:"rect"}),Reflect.deleteProperty(g,"ccw_rotation")):Object.assign(g,{shape:"rotated_rect",ccw_rotation:o}),g},uIo=(g,A)=>{if(g.type==="pcb_soldermask_opening")return wIo(g,A);if((g.type==="pcb_smtpad"||g.type==="pcb_solder_paste")&&g.shape==="polygon")return g.points=g.points.map(B=>Mt(A,B)),g.type==="pcb_solder_paste"&&g.holes&&(g.holes=g.holes.map(B=>B.map(C=>Mt(A,C)))),g;const I=tkI(A),e=Math.abs(lIo(I.rotation.angle))%2===1,t=I.rotation.angle/Math.PI*180,o=I.scale.sy<0;if(g.type==="pcb_plated_hole"||g.type==="pcb_hole"||g.type==="pcb_via"||g.type==="pcb_smtpad"||g.type==="pcb_solder_paste"||g.type==="pcb_port"){const{x:B,y:C}=Mt(A,{x:g.x,y:g.y});g.x=B,g.y=C}else if(g.type==="pcb_keepout"&&g.shape==="outline")g.outline=g.outline.map(B=>Mt(A,B));else if(g.type==="pcb_keepout"||g.type==="pcb_board")g.center=Mt(A,g.center);else if(g.type==="pcb_silkscreen_text"||g.type==="pcb_fabrication_note_text"||g.type==="pcb_note_text")g.anchor_position=Mt(A,g.anchor_position);else if(g.type==="pcb_copper_text")g.anchor_position&&(g.anchor_position=Mt(A,g.anchor_position));else if(g.type==="pcb_courtyard_rect")g.center=Mt(A,g.center),g.ccw_rotation=((g.ccw_rotation??0)+t)%360;else if(g.type==="pcb_silkscreen_circle"||g.type==="pcb_silkscreen_rect"||g.type==="pcb_silkscreen_pill"||g.type==="pcb_silkscreen_oval"||g.type==="pcb_note_rect"||g.type==="pcb_courtyard_circle")g.center=Mt(A,g.center);else if(g.type==="pcb_component")g.center=Mt(A,g.center),g.rotation=g.rotation+t,g.rotation=g.rotation%360,g.cable_insertion_center&&(g.cable_insertion_center=Mt(A,g.cable_insertion_center)),g.insertion_direction=yIo(g.insertion_direction,{rotationDegrees:t,isFlipped:o}),e&&([g.width,g.height]=[g.height,g.width]);else if(g.type==="pcb_courtyard_outline")g.outline=g.outline.map(B=>{const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_courtyard_polygon")g.points=g.points.map(B=>{const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_trace")g.route=g.route.map(B=>{if(!("x"in B))return B.start=Mt(A,B.start),B.end=Mt(A,B.end),B;const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_silkscreen_path"||g.type==="pcb_trace_hint"||g.type==="pcb_fabrication_note_path"||g.type==="pcb_note_path")g.route=g.route.map(B=>{const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_silkscreen_line"||g.type==="pcb_note_line"){const B={x:g.x1,y:g.y1},C={x:g.x2,y:g.y2},Q=Mt(A,B),i=Mt(A,C);g.x1=Q.x,g.y1=Q.y,g.x2=i.x,g.y2=i.y}else if(g.type==="cad_component"){const B=Mt(A,{x:g.position.x,y:g.position.y});g.position.x=B.x,g.position.y=B.y}return g},GIo=g=>{const A=g.type;return g[`${A}_id`]},oIg=(g,A)=>({minX:Math.min(g.minX,A.minX),minY:Math.min(g.minY,A.minY),maxX:Math.max(g.maxX,A.maxX),maxY:Math.max(g.maxY,A.maxY)}),bIA=(g,A,I)=>{const e=I/2;return{minX:g-e,minY:A-e,maxX:g+e,maxY:A+e}},jMI=(g,A,I,e,t)=>{const o=I/2,B=e/2,C=t*Math.PI/180,Q=Math.cos(C),i=Math.sin(C),E=[{x:-o,y:-B},{x:o,y:-B},{x:o,y:B},{x:-o,y:B}].map(n=>({x:g+n.x*Q-n.y*i,y:A+n.x*i+n.y*Q}));return{minX:Math.min(...E.map(n=>n.x)),minY:Math.min(...E.map(n=>n.y)),maxX:Math.max(...E.map(n=>n.x)),maxY:Math.max(...E.map(n=>n.y))}},mIo=(g,A,I,e,t)=>{const o=I/2,B=e/2,C=t*Math.PI/180,Q=Math.cos(C),i=Math.sin(C),E=Math.hypot(o*Q,B*i),n=Math.hypot(o*i,B*Q);return{minX:g-E,minY:A-n,maxX:g+E,maxY:A+n}},pIo=(g,A,I,e,t)=>{const o=Math.min(I,e)/2,B=Math.max(I,e)/2-o,C=t*Math.PI/180,Q=I>=e?{x:B,y:0}:{x:0,y:B},i={x:Q.x*Math.cos(C)-Q.y*Math.sin(C),y:Q.x*Math.sin(C)+Q.y*Math.cos(C)},E=Math.abs(i.x)+o,n=Math.abs(i.y)+o;return{minX:g-E,minY:A-n,maxX:g+E,maxY:A+n}},QwA=g=>g.length===0?null:{minX:Math.min(...g.map(A=>A.x)),minY:Math.min(...g.map(A=>A.y)),maxX:Math.max(...g.map(A=>A.x)),maxY:Math.max(...g.map(A=>A.y))},BIg=g=>Array.isArray(g)?g.flatMap(A=>!A||typeof A!="object"?[]:"x"in A&&"y"in A&&typeof A.x=="number"&&typeof A.y=="number"?[{x:A.x,y:A.y}]:"start"in A&&"end"in A?[A.start,A.end].filter(e=>!!(e&&typeof e=="object"&&"x"in e&&"y"in e&&typeof e.x=="number"&&typeof e.y=="number")):[]):[],zMI=g=>{if(!g.type.startsWith("pcb_"))return null;if(g.type==="pcb_smtpad"&&g.shape==="polygon"&&Array.isArray(g.points))return QwA(g.points);if(g.type==="pcb_hole"&&g.hole_shape==="circle")return bIA(g.x,g.y,g.hole_diameter);if(g.type==="pcb_plated_hole"){let n;if("outer_diameter"in g&&typeof g.outer_diameter=="number"?n=bIA(g.x,g.y,g.outer_diameter):"hole_diameter"in g&&typeof g.hole_diameter=="number"&&(n=bIA(g.x,g.y,g.hole_diameter)),(g.shape==="oval"||g.shape==="pill")&&typeof g.outer_width=="number"&&typeof g.outer_height=="number"&&(n=(g.shape==="pill"?pIo:mIo)(g.x,g.y,g.outer_width,g.outer_height,g.ccw_rotation??0)),"rect_pad_width"in g&&typeof g.rect_pad_width=="number"&&"rect_pad_height"in g&&typeof g.rect_pad_height=="number"){const s=jMI(g.x,g.y,g.rect_pad_width,g.rect_pad_height,"rect_ccw_rotation"in g?g.rect_ccw_rotation??0:0);n=n?oIg(n,s):s}if("hole_diameter"in g&&typeof g.hole_diameter=="number"){const s=bIA(g.x+("hole_offset_x"in g?g.hole_offset_x??0:0),g.y+("hole_offset_y"in g?g.hole_offset_y??0:0),g.hole_diameter);n=n?oIg(n,s):s}if(n)return n}const A=g,I=QwA(BIg(A.route));if(I)return I;const e=QwA(BIg(A.outline));if(e)return e;const t=QwA(BIg(A.points));if(t)return t;let o,B,C,Q;"x"in g&&"y"in g&&(o=Number(g.x),B=Number(g.y)),"outer_diameter"in g&&(C=Number(g.outer_diameter),Q=Number(g.outer_diameter)),"width"in g&&(C=Number(g.width)),"height"in g&&(Q=Number(g.height)),"center"in g&&g.center&&typeof g.center=="object"&&"x"in g.center&&"y"in g.center&&(o=Number(g.center.x),B=Number(g.center.y));let i=0;if("rotation"in g&&typeof g.rotation=="number"&&(i=g.rotation),"ccw_rotation"in g&&typeof g.ccw_rotation=="number"&&(i=g.ccw_rotation),o!==void 0&&B!==void 0)return C!==void 0&&Q!==void 0?i?jMI(o,B,C,Q,i):{minX:o-C/2,minY:B-Q/2,maxX:o+C/2,maxY:B+Q/2}:"radius"in g&&typeof g.radius=="number"?bIA(o,B,g.radius*2):{minX:o,minY:B,maxX:o,maxY:B};const E=[A.anchor_position,A.position].filter(n=>!!(n&&typeof n=="object"&&"x"in n&&"y"in n&&typeof n.x=="number"&&typeof n.y=="number")).at(0);return E?{minX:E.x,minY:E.y,maxX:E.x,maxY:E.y}:null},CIg=g=>{let A={minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY};for(const I of g){const e=zMI(I);e&&(A=oIg(A,e))}return A};function kIo(g){let A=0;if(g.length==0)return A;for(var I=0;I<g.length;I++){var e=g.charCodeAt(I);A=(A<<5)-A+e,A=A&A}return Math.abs(A)}var XMI=[["#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"]],MIo=g=>{let{x:A,y:I,width:e,height:t}={...g,...g.size,...g.center,...g.position};if(g.x1!==void 0&&g.x2!==void 0&&g.y1!==void 0&&g.y2!==void 0&&(A=(g.x1+g.x2)/2,I=(g.y1+g.y2)/2,e=Math.abs(g.x1-g.x2),t=Math.abs(g.y1-g.y2)),g.points&&Array.isArray(g.points)&&g.points.length>0){const C=g.points.map(r=>r.x),Q=g.points.map(r=>r.y),i=Math.min(...C),E=Math.max(...C),n=Math.min(...Q),s=Math.max(...Q);A=(i+E)/2,I=(n+s)/2,e=E-i,t=s-n}const o=g.text||g.name||g.source?.text||g.source?.name||"?",B=g;return A===void 0||I===void 0?null:(e===void 0&&("radius"in g?(e=g.radius*2,t=g.radius*2):"outer_diameter"in g?(e=g.outer_diameter,t=g.outer_diameter):"rect_pad_width"in g&&"rect_pad_height"in g?(e=g.rect_pad_width,t=g.rect_pad_height,"hole_diameter"in g&&(e=Math.max(e,g.hole_diameter),t=Math.max(t,g.hole_diameter))):"hole_diameter"in g&&(e=g.hole_diameter,t=g.hole_diameter)),(e===void 0||t===void 0)&&(e=.1,t=.1),{x:A,y:I,width:e,height:t,title:o,content:B,bg_color:XMI[kIo(g.type||o)%XMI.length]?.[4]??"#f00"})},SIo=g=>!!g,fIo=g=>{const A=g.filter(i=>i.type.startsWith("pcb_")||i.type.startsWith("schematic_")).concat(g.filter(i=>i.type==="pcb_trace"||i.type==="schematic_trace").flatMap(i=>i.route)).map(i=>MIo(i)).filter(SIo);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let I=A[0].x-A[0].width/2,e=A[0].x+A[0].width/2,t=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const i of A.slice(1))I=Math.min(I,i.x-i.width/2),e=Math.max(e,i.x+i.width/2),t=Math.min(t,i.y-i.height/2),o=Math.max(o,i.y+i.height/2);const B=e-I,C=o-t;return{center:{x:I+B/2,y:t+C/2},width:B,height:C}};function RIo({circuitJson:g,editEvents:A}){if(A.length===0)return g;let I=structuredClone(g);for(const e of A){if(e.edit_event_type==="edit_pcb_component_location"){const C=p5(I).pcb_component.get(e.pcb_component_id);if(C?.center.x===e.new_center.x&&C.center.y===e.new_center.y)continue;const i=vc(e.new_center.x-e.original_center.x,e.new_center.y-e.original_center.y);I=I.map(E=>"pcb_component_id"in E&&E.pcb_component_id===e.pcb_component_id?uIo(E,i):E);continue}if(e.edit_event_type==="edit_schematic_component_location"){I=I.map(C=>C.type==="schematic_component"&&C.schematic_component_id===e.schematic_component_id?{...C,center:e.new_center}:C);continue}if(e.edit_event_type!=="edit_pcb_trace_hint"||!e.pcb_trace_hint_id)continue;if(p5(I).pcb_trace_hint.get(e.pcb_trace_hint_id)){I=I.map(C=>C.type==="pcb_trace_hint"&&C.pcb_trace_hint_id===e.pcb_trace_hint_id?{...C,route:e.route}:C);continue}const o=p5(I).pcb_port.get(e.pcb_port_id);if(!o?.pcb_component_id)continue;const B={type:"pcb_trace_hint",pcb_trace_hint_id:e.pcb_trace_hint_id,route:e.route,pcb_port_id:e.pcb_port_id,pcb_component_id:o.pcb_component_id};I=I.filter(C=>C.type!=="pcb_trace_hint"||C.pcb_port_id!==e.pcb_port_id).concat(B)}return I}var NIo=g=>{if(!g)return"empty";const A=g.find(e=>e.type==="pcb_board");if(!A)return"no-board";const I=e=>Math.round(e*1e3)/1e3;return A.outline?A.outline.map(e=>`${I(e.x)}_${I(e.y)}`).join(","):`${I(A.width)}_${I(A.height)}`},iwA=g=>Number.isFinite(g)?g.toFixed(4):"NaN",xIo=g=>{let A=5381;for(let I=0;I<g.length;I++)A=(A<<5)+A+g.charCodeAt(I);return Math.abs(A)},FIo=g=>{if(!g?.length)return"0";const A=[];for(const t of g){if(!t?.type?.startsWith("pcb_"))continue;const o=GIo(t),B=CIg([t]),C=[iwA(B.minX),iwA(B.minY),iwA(B.maxX),iwA(B.maxY)].join(",");let Q=`${o}:${C}`;if(t.type==="pcb_trace"){const i=(t.route??[]).length;Q+=`:${i}`;for(const E of t.route??[])E.route_type==="via"&&(Q+=`:${E.tented_on_top}:${E.tented_on_bottom}`)}t.type==="pcb_board"&&(Q+=`:${t.default_via_tented_on_top}:${t.default_via_tented_on_bottom}`),t.type==="pcb_via"&&(Q+=`:${t.tented_on_top}:${t.tented_on_bottom}`),A.push(Q)}if(A.length===0)return"0";A.sort();const I=A.join(","),e=xIo(I);return`${A.length}_${e.toString(36)}`},$MI=gA.createContext(null),UIo=({children:g,initialState:A,disablePcbGroups:I})=>{const e=gA.useMemo(()=>KIo(A,I),[I]);return W.jsx($MI.Provider,{value:e,children:g})},kh={RENDERING_ENGINE:"pcb_viewer_rendering_engine",COPPER_POUR_OPACITY:"pcb_viewer_copper_pour_opacity",HIDDEN_LAYER_OPACITY:"pcb_viewer_hidden_layer_opacity",IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_PCB_NOTES:"pcb_viewer_is_showing_pcb_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},m3=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},p3=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},ASI=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},gSI=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},ISI=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g),e=I!==null?JSON.parse(I):null;return typeof e=="number"&&Number.isFinite(e)?e:A}catch{return A}},eSI=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},JIo="named_only",KIo=(g={},A=!1)=>BkI(I=>({copper_pour_opacity:Math.max(0,Math.min(1,ISI(kh.COPPER_POUR_OPACITY,1))),setCopperPourOpacity:e=>{if(!Number.isFinite(e))return;const t=Math.max(0,Math.min(1,e));eSI(kh.COPPER_POUR_OPACITY,t),I({copper_pour_opacity:t})},hidden_layer_opacity:Math.max(0,Math.min(1,ISI(kh.HIDDEN_LAYER_OPACITY,.2))),setHiddenLayerOpacity:e=>{if(!Number.isFinite(e))return;const t=Math.max(0,Math.min(1,e));eSI(kh.HIDDEN_LAYER_OPACITY,t),I({hidden_layer_opacity:t})},selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,is_moving_component:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_drc_warnings:!0,is_showing_copper_pours:m3(kh.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:m3(kh.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:m3(kh.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:m3(kh.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:m3(kh.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:m3(kh.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:m3(kh.IS_SHOWING_FABRICATION_NOTES,!1),is_showing_pcb_notes:m3(kh.IS_SHOWING_PCB_NOTES,!0),pcb_group_view_mode:A?"all":ASI(kh.PCB_GROUP_VIEW_MODE,JIo),hovered_error_id:null,focused_error_id:null,...g,selectLayer:e=>I({selected_layer:e}),setEditMode:e=>I({in_edit_mode:e!=="off",in_move_footprint_mode:e==="move_footprint",is_moving_component:!1}),setIsShowingRatsNest:e=>I({is_showing_rats_nest:e}),setIsMovingComponent:e=>I({is_moving_component:e}),setIsMouseOverContainer:e=>I({is_mouse_over_container:e}),setIsShowingMultipleTracesLength:e=>I({is_showing_multiple_traces_length:e}),setIsShowingAutorouting:e=>I({is_showing_autorouting:e}),setIsShowingDrcErrors:e=>I({is_showing_drc_errors:e}),setIsShowingDrcWarnings:e=>I({is_showing_drc_warnings:e}),setIsShowingCopperPours:e=>{p3(kh.IS_SHOWING_COPPER_POURS,e),I({is_showing_copper_pours:e})},setIsShowingCourtyards:e=>{p3(kh.IS_SHOWING_COURTYARDS,e),I({is_showing_courtyards:e})},setIsShowingPcbGroups:e=>{A||(p3(kh.IS_SHOWING_PCB_GROUPS,e),I({is_showing_pcb_groups:e}))},setIsShowingGroupAnchorOffsets:e=>{p3(kh.IS_SHOWING_GROUP_ANCHOR_OFFSETS,e),I({is_showing_group_anchor_offsets:e})},setIsShowingSolderMask:e=>{p3(kh.IS_SHOWING_SOLDER_MASK,e),I({is_showing_solder_mask:e})},setIsShowingSilkscreen:e=>{p3(kh.IS_SHOWING_SILKSCREEN,e),I({is_showing_silkscreen:e})},setIsShowingFabricationNotes:e=>{p3(kh.IS_SHOWING_FABRICATION_NOTES,e),I({is_showing_fabrication_notes:e})},setIsShowingPcbNotes:e=>{p3(kh.IS_SHOWING_PCB_NOTES,e),I({is_showing_pcb_notes:e})},setPcbGroupViewMode:e=>{A||(gSI(kh.PCB_GROUP_VIEW_MODE,e),I({pcb_group_view_mode:e}))},setHoveredErrorId:e=>I({hovered_error_id:e}),setFocusedErrorId:e=>I({focused_error_id:e})})),Qi=g=>{const A=gA.useContext($MI);return hkI(A,g)},PIo=()=>{gA.useEffect(()=>{x$t()},[]);const g=Qi(A=>A.pcb_viewer_id);return W.jsx(N$t,{position:"top-center",containerId:g})},Da={elementOverlay:40,dimensionOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:30,clickToInteractOverlay:100};function LIo(){var g=gA.useRef(!1),A=gA.useCallback(function(){return g.current},[]);return gA.useEffect(function(){return g.current=!0,function(){g.current=!1}},[]),A}var YIo=function(g){g===void 0&&(g={});var A=gA.useState(g),I=A[0],e=A[1],t=gA.useCallback(function(o){e(function(B){return Object.assign({},B,o instanceof Function?o(B):o)})},[]);return[I,t]},_Io=YIo,bIo=function(){},tSI=typeof window<"u",HIo=XkI(LAo()),vIo=function(){var g=LIo(),A=_Io({value:void 0,error:void 0,noUserInteraction:!0}),I=A[0],e=A[1],t=gA.useCallback(function(o){if(g()){var B,C;try{if(typeof o!="string"&&typeof o!="number"){var Q=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(Q),e({value:o,error:Q,noUserInteraction:!0});return}else if(o===""){var Q=new Error("Cannot copy empty string to clipboard.");console.error(Q),e({value:o,error:Q,noUserInteraction:!0});return}C=o.toString(),B=(0,HIo.default)(C),e({value:C,error:void 0,noUserInteraction:B})}catch(i){e({value:C,error:i,noUserInteraction:B})}}},[]);return[I,t]},qIo=vIo,TIo=tSI?gA.useLayoutEffect:gA.useEffect,ZIo=TIo,oSI={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function OIo(){var g=gA.useState(null),A=g[0],I=g[1],e=gA.useState(oSI),t=e[0],o=e[1],B=gA.useMemo(function(){return new window.ResizeObserver(function(C){if(C[0]){var Q=C[0].contentRect,i=Q.x,E=Q.y,n=Q.width,s=Q.height,r=Q.top,a=Q.left,c=Q.bottom,h=Q.right;o({x:i,y:E,width:n,height:s,top:r,left:a,bottom:c,right:h})}})},[]);return ZIo(function(){if(A)return B.observe(A),function(){B.disconnect()}},[A]),[I,t]}var HIA=tSI&&typeof window.ResizeObserver<"u"?OIo:function(){return[bIo,oSI]},BSI=({initialTransform:g,initialTouch1:A,initialTouch2:I,finalTouch1:e,finalTouch2:t})=>{if(!e||!t)return g;const o={x:(A.x+I.x)/2,y:(A.y+I.y)/2},B={x:(e.x+t.x)/2,y:(e.y+t.y)/2},C=Math.hypot(I.x-A.x,I.y-A.y),Q=Math.hypot(t.x-e.x,t.y-e.y),i=C===0?1:Q/C,E=B.x-o.x,n=B.y-o.y;return Yw(vc(E,n),vc(o.x,o.y),rJ(i,i),vc(-o.x,-o.y),g)},WIo=(g={})=>{const A=gA.useRef(null),[I,e]=gA.useState(0),t=g.canvasElm??A.current,[o,B]=gA.useState(g.initialTransform??aJ()),[C,Q]=gA.useState(0),[i,E]=gA.useReducer(d=>d+1,0),n=gA.useCallback(d=>{g.onSetTransform&&g.onSetTransform(d),g.transform||B(d)},[g.onSetTransform,B]),s=gA.useCallback(d=>{n(d),E()},[n]),r=g.transform??o,a=gA.useCallback(()=>{e(Date.now())},[]),c=gA.useRef("none"),h=gA.useRef(null),l=gA.useRef(null);gA.useEffect(()=>{const d=g.canvasElm??A.current;if(d&&!t){Q(C+1);return}if(!d){const b=setTimeout(()=>{Q(C+1)},100);return()=>clearTimeout(b)}let y=g.transform??o,w={x:0,y:0},u={x:0,y:0},G=!1;const m=b=>({x:b.pageX-d.getBoundingClientRect().left-window.scrollX,y:b.pageY-d.getBoundingClientRect().top-window.scrollY});function p(b){g.enabled!==!1&&(g.shouldDrag&&!g.shouldDrag(b)||(w=m(b),!(Date.now()-I<100)&&(G=!0,b.preventDefault())))}function k(b){if(!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Yw(vc(u.x-w.x,u.y-w.y),y);n(H),y=H,G=!1}function S(b){if(m(b),!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Yw(vc(u.x-w.x,u.y-w.y),y);n(H)}function R(b){if(g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;const H=m(b),q=Yw(vc(H.x,H.y),rJ(1-b.deltaY/1e3,1-b.deltaY/1e3),vc(-H.x,-H.y),y);n(q),y=q,b.preventDefault()}function F(b){if(!G||g.shouldDrag&&!g.shouldDrag(b))return;if(d){const q=d.getBoundingClientRect();if(b.clientX>=q.left+10&&b.clientX<=q.right-10&&b.clientY>=q.top+10&&b.clientY<=q.bottom-10)return}G=!1,u=m(b);const H=Yw(vc(u.x-w.x,u.y-w.y),y);n(H),y=H}function N(b){if(b.preventDefault(),g.enabled!==!1){if(b.touches.length===1){c.current="drag";const H=b.touches[0];h.current={initialTransform:y,initialTouch:{x:H.clientX,y:H.clientY}}}else if(b.touches.length===2){c.current="pinch";const H=b.touches[0],q=b.touches[1];l.current={initialTransform:y,initialTouch1:{x:H.clientX,y:H.clientY},initialTouch2:{x:q.clientX,y:q.clientY},finalTouch1:null,finalTouch2:null}}}}function U(b){if(b.preventDefault(),g.enabled!==!1){if(c.current==="drag"&&b.touches.length===1&&h.current){const H=b.touches[0],q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Yw(vc(j,Z),h.current.initialTransform);n(O)}else if(c.current==="pinch"&&b.touches.length===2&&l.current){const H=b.touches[0],q=b.touches[1];l.current.finalTouch1={x:H.clientX,y:H.clientY},l.current.finalTouch2={x:q.clientX,y:q.clientY};const j=BSI(l.current);n(j)}}}function L(b){b.preventDefault();const H=b.changedTouches[0];if(c.current==="drag"&&h.current&&H){const q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Yw(vc(j,Z),h.current.initialTransform);n(O),y=O}else if(c.current==="pinch"&&l.current){const q=BSI(l.current);n(q),y=q}c.current="none",h.current=null,l.current=null}return d.addEventListener("mousedown",p),d.addEventListener("mouseup",k),window.addEventListener("mousemove",S),d.addEventListener("mouseout",F),d.addEventListener("wheel",R),d.addEventListener("touchstart",N,{passive:!1}),d.addEventListener("touchmove",U,{passive:!1}),d.addEventListener("touchend",L,{passive:!1}),d.addEventListener("touchcancel",L,{passive:!1}),()=>{d.removeEventListener("mousedown",p),d.removeEventListener("mouseup",k),window.removeEventListener("mousemove",S),d.removeEventListener("mouseout",F),d.removeEventListener("wheel",R),d.removeEventListener("touchstart",N),d.removeEventListener("touchmove",U),d.removeEventListener("touchend",L),d.removeEventListener("touchcancel",L)}},[t,C,i,I,g.enabled,g.shouldDrag]);const D=gA.useCallback(d=>Mt(r,d),[r]);return{ref:A,transform:r,applyTransformToPoint:D,setTransform:s,cancelDrag:a}},VIo=WIo;function CSI(g){let A=g;for(;A.parent!==null;)A=A.parent;let I=g;for(;I.parent!==null&&I.parent!==A;){const e=I.parent;I.parent=A,I=e}return A}function jIo(g,A){const I={nodeId:g,nextMember:null},e={parent:null,networkId:`connectivity_net${A.nextNetworkNumber++}`,firstMember:I,lastMember:I};return A.rootByNodeId.set(g,e),e}function zIo(g,A){const I=A.rootByNodeId.get(g);return I===void 0?jIo(g,A):CSI(I)}function XIo({targetRoot:g,sourceRoot:A}){g.lastMember.nextMember=A.firstMember,g.lastMember=A.lastMember,A.parent=g}function $Io(g){const A=[];let I=g.firstMember;for(;I!==null;)A.push(I.nodeId),I=I.nextMember;return A}function Aeo(g){const A={rootByNodeId:new Map,nextNetworkNumber:0};for(const e of g){let t=null;for(const o of e){const B=zIo(o,A);if(t===null){t=B;continue}t=CSI(t),B!==t&&XIo({targetRoot:t,sourceRoot:B})}}const I={};for(const e of A.rootByNodeId.values())e.parent===null&&(I[e.networkId]=$Io(e));return I}var geo=class{netMap;idToNetMap;constructor(g){this.netMap=g,this.idToNetMap={};for(const[A,I]of Object.entries(g))for(const e of I)this.idToNetMap[e]=A}addConnections(g){for(const A of g){const I=new Set;for(const t of A){const o=this.idToNetMap[t];o&&I.add(o)}let e;if(I.size===0)e=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[e]=[];else if(I.size===1)e=I.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{e=I.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const t of I)if(t!==e){this.netMap[e].push(...this.netMap[t]),this.netMap[t]=this.netMap[e];for(const o of this.netMap[e])this.idToNetMap[o]=e}}for(const t of A)this.netMap[e].includes(t)||this.netMap[e].push(t),this.idToNetMap[t]=e}}getIdsConnectedToNet(g){return this.netMap[g]||[]}getNetConnectedToId(g){return this.idToNetMap[g]}areIdsConnected(g,A){if(g===A)return!0;const I=this.getNetConnectedToId(g);if(!I)return!1;const e=this.getNetConnectedToId(A);return e?I===e||e===g||e===g:!1}areAllIdsConnected(g){const A=this.getNetConnectedToId(g[0]);for(const I of g){const e=this.getNetConnectedToId(I);if(e===void 0||e!==A)return!1}return!0}},Ieo=g=>{const A=[];for(const e of g)if(e.type==="source_trace")A.push([e.source_trace_id,...e.connected_source_port_ids??[],...e.connected_source_net_ids??[]].filter(Boolean));else if(e.type==="pcb_port"){const{pcb_port_id:t,source_port_id:o}=e;o&&t&&A.push([o,t])}else if(e.type==="pcb_smtpad"){const{pcb_smtpad_id:t,pcb_port_id:o}=e;o&&t&&A.push([t,o])}else if(e.type==="pcb_plated_hole"){const{pcb_plated_hole_id:t,pcb_port_id:o}=e;o&&t&&A.push([t,o])}else if(e.type==="pcb_trace"){const{pcb_trace_id:t,source_trace_id:o}=e,B=Array.isArray(e.route)?e.route.filter(C=>C&&C.route_type==="wire"):[];if(o&&t&&A.push([t,o]),Array.isArray(B)){const C=B.find(i=>i?.start_pcb_port_id)?.start_pcb_port_id,Q=B.find(i=>i?.end_pcb_port_id)?.end_pcb_port_id;C&&t&&A.push([C,t]),t&&Q&&A.push([t,Q])}}else if(e.type==="pcb_via"){const{pcb_via_id:t,pcb_trace_id:o,source_trace_id:B,source_net_id:C}=e,Q=[...e.pcb_port_ids??[],o,B,C].filter(i=>!!i);t&&Q.length>0&&A.push([t,...Q])}else if(e.type==="source_component"&&e.internally_connected_source_port_ids)for(const t of e.internally_connected_source_port_ids)A.push(t);const I=Aeo(A);return new geo(I)};function eeo(g,A){if(g.length<2)throw new Error("Stroke must have at least two points");const I=g.map(n=>Array.isArray(n)?{x:n[0],y:n[1]}:n),e=[],t=[];function o(n,s){const r=s.x-n.x,a=s.y-n.y,c=Math.sqrt(r*r+a*a);return{x:-a/c,y:r/c}}function B(n,s,r,a){const c=a/2,h={x:n.x+s.x*c*r,y:n.y+s.y*c*r};r>0?e.push(h):t.unshift(h)}const C=o(I[0],I[1]),Q=I[0].trace_width??A;B(I[0],C,1,Q),B(I[0],C,-1,Q);for(let n=1;n<I.length-1;n++){const s=I[n-1],r=I[n],a=I[n+1],c=o(s,r),h=o(r,a),l=c.x+h.x,D=c.y+h.y,d=Math.sqrt(l*l+D*D),y=r.trace_width??A;if(d/2>2*(y/2))B(r,c,1,y),B(r,h,1,y),B(r,c,-1,y),B(r,h,-1,y);else{const u=1/d;B(r,{x:l*u,y:D*u},1,y),B(r,{x:l*u,y:D*u},-1,y)}}const i=o(I[I.length-2],I[I.length-1]),E=I[I.length-1].trace_width??A;return B(I[I.length-1],i,1,E),B(I[I.length-1],i,-1,E),[...e,...t]}var teo=(g,A)=>{const{x:I,y:e,width:t,height:o,layer:B,rect_border_radius:C}=g,Q=g.corner_radius??C??0,i=[{_pcb_drawing_object_id:MR("rect"),pcb_drawing_type:"rect",x:I,y:e,w:t,h:o,layer:B||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:Q,...g.shape==="rotated_rect"&&g.ccw_rotation!==void 0?{ccw_rotation:g.ccw_rotation}:{}}];if(g.is_covered_with_solder_mask){const E=B==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={...{_pcb_drawing_object_id:MR("rect"),pcb_drawing_type:"rect",x:I,y:e,w:t,h:o,layer:E,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:Q,...g.shape==="rotated_rect"&&g.ccw_rotation!==void 0?{ccw_rotation:g.ccw_rotation}:{}},..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};i.push(s)}return i},oeo=(g,A)=>{const{x:I,y:e,radius:t,layer:o}=g,B=[{_pcb_drawing_object_id:MR("circle"),pcb_drawing_type:"circle",x:I,y:e,r:t,layer:o||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(g.is_covered_with_solder_mask){const C=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",Q={_pcb_drawing_object_id:MR("circle"),pcb_drawing_type:"circle",x:I,y:e,r:t,layer:C,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};B.push(Q)}return B},Beo=(g,A)=>{const{layer:I,points:e}=g,t=[{_pcb_drawing_object_id:MR("polygon"),pcb_drawing_type:"polygon",points:QIg(e),layer:I||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(g.is_covered_with_solder_mask){const o=I==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",B={_pcb_drawing_object_id:MR("polygon"),pcb_drawing_type:"polygon",points:QIg(e),layer:o,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};t.push(B)}return t},Ceo=(g,A)=>{const{x:I,y:e,width:t,height:o,layer:B}=g,C=[{_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:B||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(g.is_covered_with_solder_mask){const Q=B==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",i={_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:Q,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};C.push(i)}return C},Qeo=(g,A)=>{const{x:I,y:e,width:t,height:o,layer:B,ccw_rotation:C}=g,Q=[{_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:B||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:C}];if(g.is_covered_with_solder_mask){const i=B==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",E={_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:i,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:C,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};Q.push(E)}return Q},Zc=0,MR=g=>`${g}_${Zc++}`,QIg=g=>(g??[]).map(A=>({x:sg.parse(A.x),y:sg.parse(A.y)}));function ieo(g){const A=new Map;for(const I of g){const e=I[`${I.type}_id`];e!==void 0&&!A.has(`${I.type}:${e}`)&&A.set(`${I.type}:${e}`,I)}return A}var Eeo=(g,A,I)=>{const e=(Q,i)=>{if(i!==void 0)return I?I.get(`${Q}:${i}`):A.find(E=>E.type===Q&&E[`${Q}_id`]===i)},t=e("pcb_component","pcb_component_id"in g?g.pcb_component_id:void 0),o=e("source_component",t?.source_component_id),B="source_port_id"in g?g.source_port_id:"pcb_port_id"in g?e("pcb_port",g.pcb_port_id)?.source_port_id:void 0,C=e("source_port",B);switch(g.type){case"pcb_smtpad":{const Q={_parent_pcb_component:t,_parent_source_component:o,_source_port:C};return g.shape==="rect"||g.shape==="rotated_rect"?teo(g,Q):g.shape==="circle"?oeo(g,Q):g.shape==="polygon"?Beo(g,Q):g.shape==="pill"?Ceo(g,Q):g.shape==="rotated_pill"?Qeo(g,Q):[]}case"pcb_trace":{const Q=[];if(g.route_thickness_mode==="interpolated"){const n=g.route.flatMap(a=>a.route_type==="through_pad"?[{...a.start,trace_width:a.width},{...a.end,trace_width:a.width}]:[{x:a.x,y:a.y,trace_width:a.route_type==="wire"?a.width:.5}]),s=eeo(n,.5),r=g.route[0].layer;return Q.push({_pcb_drawing_object_id:`polygon_${Zc++}`,_element:g,pcb_drawing_type:"polygon",points:s,layer:r}),g.route.forEach(a=>{a.route_type==="via"&&Q.push({_pcb_drawing_object_id:`circle_${Zc++}`,_element:g,pcb_drawing_type:"circle",x:a.x,y:a.y,r:a.outer_diameter/2,layer:a.from_layer})}),Q}let i=null,E=null;for(const n of g.route)n.route_type==="wire"&&(i!==null&&E!==null&&Q.push({_pcb_drawing_object_id:`line_${Zc++}`,_element:g,pcb_drawing_type:"line",x1:i,y1:E,x2:n.x,y2:n.y,width:n.width,squareCap:!1,layer:n.layer}),i=n.x,E=n.y);return Q}case"pcb_via":{const{x:Q,y:i,outer_diameter:E,hole_diameter:n}=g,s=g.from_layer,r=g.to_layer,a=g.layers,c=[];s&&r?c.push(s,r):a&&Array.isArray(a)?c.push(...a):c.push("top","bottom");const h=[];for(const l of c)h.push({_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:E/2,layer:l,_element:g,_parent_pcb_component:t,_parent_source_component:o});return h.push({_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:n/2,layer:"drill",_element:g}),h}case"pcb_plated_hole":if(g.shape==="circle"){const{x:Q,y:i,hole_diameter:E,outer_diameter:n}=g;return[{_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:n/2,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C},{_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:E/2,layer:"drill",_element:g}]}else if(g.shape==="oval"){const{x:Q,y:i,outer_height:E,outer_width:n,hole_height:s,hole_width:r}=g;return[{_pcb_drawing_object_id:`oval_${Zc++}`,pcb_drawing_type:"oval",x:Q,y:i,rX:n/2,rY:E/2,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C},{_pcb_drawing_object_id:`oval_${Zc++}`,_element:g,pcb_drawing_type:"oval",x:Q,y:i,rX:r/2,rY:s/2,layer:"drill"}]}else if(g.shape==="pill"){const{x:Q,y:i,outer_height:E,outer_width:n,hole_height:s,hole_width:r}=g;return[{_pcb_drawing_object_id:`pill_${Zc++}`,pcb_drawing_type:"pill",x:Q,y:i,w:n,h:E,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,ccw_rotation:g.ccw_rotation},{_pcb_drawing_object_id:`pill_${Zc++}`,_element:g,pcb_drawing_type:"pill",x:Q,y:i,w:r,h:s,layer:"drill",ccw_rotation:g.ccw_rotation}]}else if(g.shape==="circular_hole_with_rect_pad"){const{x:Q,y:i,hole_diameter:E,rect_pad_width:n,rect_pad_height:s,rect_border_radius:r,hole_offset_x:a,hole_offset_y:c}=g,h=sg.parse(a??0),l=sg.parse(c??0);return[{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:n,h:s,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:r},{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:n,h:s,layer:"bottom",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:r,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${Zc++}`,_element:g,pcb_drawing_type:"circle",x:Q+h,y:i+l,r:E/2,layer:"drill",is_hoverable:!1}]}else if(g.shape==="pill_hole_with_rect_pad"){const{x:Q,y:i,hole_width:E,hole_height:n,rect_pad_width:s,rect_pad_height:r,rect_border_radius:a}=g;return[{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:s,h:r,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:a},{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:s,h:r,layer:"bottom",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:a,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${Zc++}`,_element:g,pcb_drawing_type:"pill",x:Q,y:i,w:E,h:n,layer:"drill",is_hoverable:!1}]}else if(g.shape==="rotated_pill_hole_with_rect_pad"){const{x:Q,y:i,hole_width:E,hole_height:n,hole_ccw_rotation:s,rect_pad_width:r,rect_pad_height:a,rect_ccw_rotation:c,rect_border_radius:h}=g;return[{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:r,h:a,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,ccw_rotation:c,roundness:h},{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:r,h:a,layer:"bottom",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,ccw_rotation:c,roundness:h,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${Zc++}`,_element:g,pcb_drawing_type:"pill",x:Q,y:i,w:E,h:n,layer:"drill",ccw_rotation:s,is_hoverable:!1}]}else if(g.shape==="hole_with_polygon_pad"){const{x:Q,y:i,pad_outline:E,hole_shape:n,hole_diameter:s,hole_width:r,hole_height:a,layers:c,hole_offset_x:h,hole_offset_y:l}=g,D=sg.parse(h??0),d=sg.parse(l??0),y=E,w=[];if(y&&Array.isArray(y)){const m=QIg(y).map(p=>({x:p.x+Q,y:p.y+i}));for(const p of c||["top","bottom"])w.push({_pcb_drawing_object_id:`polygon_${Zc++}`,pcb_drawing_type:"polygon",points:m,layer:p,_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C})}const u={x:Q+D,y:i+d},G=[];return n==="circle"?G.push({_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:u.x,y:u.y,r:(s??0)/2,layer:"drill",_element:g,_parent_pcb_component:t,_parent_source_component:o}):n==="oval"?G.push({_pcb_drawing_object_id:`oval_${Zc++}`,pcb_drawing_type:"oval",x:u.x,y:u.y,rX:(r??0)/2,rY:(a??0)/2,layer:"drill",_element:g,_parent_pcb_component:t,_parent_source_component:o}):(n==="pill"||n==="rotated_pill")&&G.push({_pcb_drawing_object_id:`pill_${Zc++}`,pcb_drawing_type:"pill",x:u.x,y:u.y,w:r??0,h:a??0,layer:"drill",_element:g,_parent_pcb_component:t,_parent_source_component:o,ccw_rotation:g.ccw_rotation}),[...w,...G]}else return[]}return[]};function neo(g,A,I){const e=document.createElement("canvas");e.width=e.height=1;const t=e.getContext("2d");return g.filter(o=>o.type!=="pcb_copper_pour"||o.layer!==I?!1:(UlI({ctx:t,pour:o,realToCanvasMat:aJ(),colorMap:Kw}),t.isPointInPath(A.x,A.y,o.shape==="brep"?"evenodd":"nonzero")))}function seo(g){return g.type==="pcb_copper_pour"}function QSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,opacity:t=1}){const o=A.filter(seo);if(o.length===0||t<=0)return;const B=new VE(g);B.configure({colorOverrides:{copper:Object.fromEntries(Object.entries(Kw.copper).map(([C,Q])=>[C,wQ(Q).alpha(t).rgb().string()]))}}),B.realToCanvasMat=e,B.drawElements(o,{layers:I})}var EwA=(g,A,I)=>I(g,A),iSI=(g,A,I,e,t)=>{const o=t*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=g-I,i=A-e,E=Q*B-i*C,n=Q*C+i*B;return{x:E+I,y:n+e}},vIA=g=>{if(g.length===0)return null;let A=g[0].x,I=g[0].x,e=g[0].y,t=g[0].y;for(const o of g)A=EwA(A,o.x,Math.min),I=EwA(I,o.x,Math.max),e=EwA(e,o.y,Math.min),t=EwA(t,o.y,Math.max);return{minX:A,maxX:I,minY:e,maxY:t}},aeo=(g,A)=>({minX:Math.min(g.minX,A.minX),maxX:Math.max(g.maxX,A.maxX),minY:Math.min(g.minY,A.minY),maxY:Math.max(g.maxY,A.maxY)}),reo=(g,A)=>g?aeo(g,A):A,iIg=g=>{switch(g.pcb_drawing_type){case"line":{const A=(g.width??0)/2,I=[{x:g.x1,y:g.y1},{x:g.x2,y:g.y2}],e=vIA(I);return e?{minX:e.minX-A,maxX:e.maxX+A,minY:e.minY-A,maxY:e.maxY+A}:null}case"rect":{const A=g.w/2,I=g.h/2,e=[{x:g.x-A,y:g.y-I},{x:g.x+A,y:g.y-I},{x:g.x+A,y:g.y+I},{x:g.x-A,y:g.y+I}],t=g.ccw_rotation??0,o=t===0?e:e.map(B=>iSI(B.x,B.y,g.x,g.y,t));return vIA(o)}case"circle":return{minX:g.x-g.r,maxX:g.x+g.r,minY:g.y-g.r,maxY:g.y+g.r};case"oval":return{minX:g.x-g.rX,maxX:g.x+g.rX,minY:g.y-g.rY,maxY:g.y+g.rY};case"pill":{const A=g.w/2,I=g.h/2,e=[{x:g.x-A,y:g.y-I},{x:g.x+A,y:g.y-I},{x:g.x+A,y:g.y+I},{x:g.x-A,y:g.y+I}],t=g.ccw_rotation??0,o=t===0?e:e.map(B=>iSI(B.x,B.y,g.x,g.y,t));return vIA(o)}case"polygon":return vIA(g.points);case"polygon_with_arcs":{const A=g.brep_shape.outer_ring.vertices.map(I=>({x:I.x,y:I.y}));return vIA(A)}case"text":{const A=g.size??0,I=g.text?g.text.length*A*.6:0,e=A;if(I===0&&e===0)return{minX:g.x,maxX:g.x,minY:g.y,maxY:g.y};const t=I/2,o=e/2;return{minX:g.x-t,maxX:g.x+t,minY:g.y-o,maxY:g.y+o}}default:return null}},ceo=64,heo=256,leo=8;function ESI({cellX:g,cellY:A}){return`${g}:${A}`}function Deo(g){let A=1/0,I=1/0,e=-1/0,t=-1/0;for(const C of g){const Q=iIg(C);Q&&(A=Math.min(A,Q.minX),I=Math.min(I,Q.minY),e=Math.max(e,Q.maxX),t=Math.max(t,Q.maxY))}if(!Number.isFinite(A))return 1;const o=Math.max(e-A,t-I),B=Math.sqrt(Math.max(1,g.length/leo));return Math.max(.5,Math.min(20,o/B))}function nSI(g){const A=Deo(g),I=new Map,e=new Map,t=[];let o=0;for(const[B,C]of g.entries()){e.set(C,B),C.pcb_drawing_type==="line"&&C._element?.type==="pcb_trace"&&(o=Math.max(o,C.width));const Q=iIg(C);if(!Q){t.push(C);continue}const i=Math.floor(Q.minX/A),E=Math.floor(Q.maxX/A),n=Math.floor(Q.minY/A),s=Math.floor(Q.maxY/A);if((E-i+1)*(s-n+1)>ceo){t.push(C);continue}for(let a=i;a<=E;a++)for(let c=n;c<=s;c++){const h=ESI({cellX:a,cellY:c}),l=I.get(h)??[];l.push(C),I.set(h,l)}}return{cellSize:A,globalPrimitives:t,maxTraceWidth:o,primitiveIndexByPrimitive:e,primitives:g,primitivesByCell:I}}function sSI({point:g,realToScreenScale:A,spatialIndex:I}){const e=Math.max(Math.abs(A),Number.EPSILON),t=Math.max(I.maxTraceWidth*25,2)/e,o=Math.floor((g.x-t)/I.cellSize),B=Math.floor((g.x+t)/I.cellSize),C=Math.floor((g.y-t)/I.cellSize),Q=Math.floor((g.y+t)/I.cellSize);if((B-o+1)*(Q-C+1)>heo)return I.primitives;const E=new Set(I.globalPrimitives);for(let n=o;n<=B;n++)for(let s=C;s<=Q;s++){const r=ESI({cellX:n,cellY:s}),a=I.primitivesByCell.get(r);if(a)for(const c of a)E.add(c)}return[...E].sort((n,s)=>(I.primitiveIndexByPrimitive.get(n)??Number.MAX_SAFE_INTEGER)-(I.primitiveIndexByPrimitive.get(s)??Number.MAX_SAFE_INTEGER))}function deo({primitivesWithoutInteractionMetadata:g,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:I}){const e=[],t=new Set(I);for(const o of g){const B={...o},C=o._element,Q=o._parent_pcb_component;o?.layer==="drill"?(B.is_in_highlighted_net=!1,B.is_mouse_over=!1):A.has(o._pcb_drawing_object_id)?B.is_mouse_over=!0:C&&("pcb_trace_id"in C&&t.has(C.pcb_trace_id)||"pcb_port_id"in C&&t.has(C.pcb_port_id)||"pcb_via_id"in C&&t.has(C.pcb_via_id)||"pcb_component_id"in C&&t.has(C.pcb_component_id)||Q&&"pcb_component_id"in Q&&t.has(Q.pcb_component_id))?B.is_in_highlighted_net=!0:(B.is_in_highlighted_net=!1,B.is_mouse_over=!1),e.push(B)}return e}var aSI=g=>{const A=new Map,I=new Map,e=new Map,t=new Map,o=new Map;for(const B of g)B.type==="pcb_trace"&&B.pcb_trace_id?A.set(B.pcb_trace_id,B):B.type==="pcb_port"&&B.pcb_port_id?I.set(B.pcb_port_id,B):B.type==="pcb_via"&&B.pcb_via_id?e.set(B.pcb_via_id,B):B.type==="pcb_component"&&B.pcb_component_id?t.set(B.pcb_component_id,B):B.type==="pcb_board"&&B.pcb_board_id&&o.set(B.pcb_board_id,B);return{tracesById:A,portsById:I,viasById:e,componentsById:t,boardsById:o}},Y2=(g,A)=>A?g?{minX:Math.min(g.minX,A.minX),maxX:Math.max(g.maxX,A.maxX),minY:Math.min(g.minY,A.minY),maxY:Math.max(g.maxY,A.maxY)}:A:g,k5=(g,A=.45)=>({minX:g.x-A,maxX:g.x+A,minY:g.y-A,maxY:g.y+A}),yeo=g=>{if(g.length===0)return null;let A=null;for(const I of g){const e=Math.max((I.width??.2)/2,.3);A=Y2(A,k5(I,e))}return A},rSI=g=>{if(!g?.center)return null;const A=Math.max(g.width??0,1.2),I=Math.max(g.height??0,1.2);return{minX:g.center.x-A/2,maxX:g.center.x+A/2,minY:g.center.y-I/2,maxY:g.center.y+I/2}},weo=g=>!g?.center||typeof g.width!="number"||typeof g.height!="number"?null:{minX:g.center.x-g.width/2,maxX:g.center.x+g.width/2,minY:g.center.y-g.height/2,maxY:g.center.y+g.height/2},ueo=(g,A)=>({minX:g.minX-A,maxX:g.maxX+A,minY:g.minY-A,maxY:g.maxY+A}),Geo=(g,A=.35)=>{const I=I0(g);return I?ueo(I,A):null},cSI=({error:g,tracesById:A,portsById:I,viasById:e,componentsById:t})=>{if(g.center)return g.center;if(g.pcb_center)return g.pcb_center;if(g.component_center)return g.component_center;if(g.pcb_via_ids?.length){const o=g.pcb_via_ids.map(B=>e.get(B)).filter(Boolean);if(o.length>0)return{x:o.reduce((B,C)=>B+C.x,0)/o.length,y:o.reduce((B,C)=>B+C.y,0)/o.length}}if(g.pcb_port_ids?.length){const o=g.pcb_port_ids.map(B=>I.get(B)).filter(Boolean);if(o.length>0)return{x:o.reduce((B,C)=>B+C.x,0)/o.length,y:o.reduce((B,C)=>B+C.y,0)/o.length}}if(g.pcb_trace_id){const o=A.get(g.pcb_trace_id);if(o?.route?.length){const B=Math.floor(o.route.length/2);return{x:o.route[B].x,y:o.route[B].y}}}return g.pcb_component_id?t.get(g.pcb_component_id)?.center??null:null},meo=({error:g,indexes:A})=>cSI({error:g,...A}),peo=({error:g,boardsById:A})=>{if(!g.component_bounds||!g.pcb_board_id)return null;const I=weo(A.get(g.pcb_board_id));if(!I)return null;const e=g.component_bounds,t=[];return e.min_x<I.minX&&(t.push({x:I.minX,y:Math.max(e.min_y,I.minY)}),t.push({x:I.minX,y:Math.min(e.max_y,I.maxY)})),e.max_x>I.maxX&&(t.push({x:I.maxX,y:Math.max(e.min_y,I.minY)}),t.push({x:I.maxX,y:Math.min(e.max_y,I.maxY)})),e.min_y<I.minY&&(t.push({x:Math.max(e.min_x,I.minX),y:I.minY}),t.push({x:Math.min(e.max_x,I.maxX),y:I.minY})),e.max_y>I.maxY&&(t.push({x:Math.max(e.min_x,I.minX),y:I.maxY}),t.push({x:Math.min(e.max_x,I.maxX),y:I.maxY})),Geo(t,.3)},hSI=new Set(["source_failed_to_create_component_error"]),keo=({error:g,indexes:A})=>{if(hSI.has(g.error_type)||hSI.has(g.type))return null;let I=null;const e=cSI({error:g,...A});if(e&&(I=Y2(I,k5(e,.35))),g.error_type==="pcb_component_outside_board_error"?I=Y2(I,peo({error:g,boardsById:A.boardsById})):g.component_bounds&&!e&&(I=Y2(I,{minX:g.component_bounds.min_x,maxX:g.component_bounds.max_x,minY:g.component_bounds.min_y,maxY:g.component_bounds.max_y})),g.center&&!e&&(I=Y2(I,k5(g.center))),g.pcb_center&&!e&&(I=Y2(I,k5(g.pcb_center))),g.component_center&&!e&&(I=Y2(I,k5(g.component_center))),g.pcb_port_ids&&!e)for(const t of g.pcb_port_ids){const o=A.portsById.get(t);o&&(I=Y2(I,k5({x:o.x,y:o.y},.4)))}if(g.pcb_trace_id&&!e){const t=A.tracesById.get(g.pcb_trace_id);t?.route&&(I=Y2(I,yeo(t.route)))}if(g.pcb_via_ids)for(const t of g.pcb_via_ids){const o=A.viasById.get(t);o&&(I=Y2(I,k5({x:o.x,y:o.y},Math.max((o.outer_diameter??.5)/2,.28))))}if(g.pcb_component_id&&!e&&(I=Y2(I,rSI(A.componentsById.get(g.pcb_component_id)))),g.pcb_component_ids&&!e)for(const t of g.pcb_component_ids)I=Y2(I,rSI(A.componentsById.get(t)));return I},lSI=({bounds:g,width:A,height:I})=>{const e={x:(g.minX+g.maxX)/2,y:(g.minY+g.maxY)/2},t=Math.max(g.maxX-g.minX,.8)+1.4,o=Math.max(g.maxY-g.minY,.8)+1.4,B=Math.min(A/t,I/o,240)*.92;return Yw(vc(A/2,I/2),rJ(B,-B,0,0),vc(-e.x,-e.y))},Meo=g=>{const A=new Set;g.pcb_trace_id&&A.add(g.pcb_trace_id);for(const I of g.pcb_port_ids??[])A.add(I);for(const I of g.pcb_via_ids??[])A.add(I);g.pcb_component_id&&A.add(g.pcb_component_id);for(const I of g.pcb_component_ids??[])A.add(I);return[...A]},q7=(g,A)=>{const I=["pcb_trace_error_id","pcb_via_clearance_error_id","pcb_component_outside_board_error_id","source_failed_to_create_component_error_id","pcb_error_id"];for(const e of I)if(typeof g?.[e]=="string"&&g[e].length>0)return g[e];for(const[e,t]of Object.entries(g??{}))if(e.endsWith("_error_id")&&typeof t=="string"&&t.length>0)return t;return`error_${A}_${g?.error_type}_${g?.message?.slice(0,20)}`},DSI=(g,A)=>A?g.find((I,e)=>I.type?.includes("error")?q7(I,e)===A:!1)??null:null,Seo=g=>1-(1-g)**3,feo=(g,A,I)=>({a:g.a+(A.a-g.a)*I,b:g.b+(A.b-g.b)*I,c:g.c+(A.c-g.c)*I,d:g.d+(A.d-g.d)*I,e:g.e+(A.e-g.e)*I,f:g.f+(A.f-g.f)*I}),dSI=g=>{g!==null&&window.cancelAnimationFrame(g)},Reo=({startTransform:g,endTransform:A,durationMs:I,onUpdate:e,setAnimationFrameId:t,onComplete:o})=>{const B=performance.now(),C=i=>{const E=i-B,n=Math.min(1,E/I),s=Seo(n);if(e(feo(g,A,s)),n<1){t(window.requestAnimationFrame(C));return}t(null),o?.()},Q=window.requestAnimationFrame(C);return t(Q),Q},nwA=g=>g?.trim()||null;function ySI(g){const A=new Map,I=new Map;for(const e of g)e.type==="source_net"?A.set(e.source_net_id,e):e.type==="source_trace"&&I.set(e.source_trace_id,e);return{sourceNetById:A,sourceTraceById:I}}function EIg({primitiveElement:g,traceOverlayElementIndex:A}){const I=g.source_trace_id;if(!I)return null;const e=A.sourceTraceById.get(I),t=nwA(e?.name);if(t)return t;const o=A.sourceNetById.get(I),B=nwA(o?.name);if(B)return B;for(const C of e?.connected_source_net_ids??[]){const Q=nwA(A.sourceNetById.get(C)?.name);if(Q)return Q}return null}function wSI({primitiveElement:g,traceOverlayElementIndex:A}){const I=g.source_trace_id,e=I?A.sourceTraceById.get(I):void 0,t=g.trace_length,o=typeof t=="number",B=e?.max_length,C=o?`${t.toFixed(3)}${typeof B=="number"?` / ${B}`:""} mm`:"",Q=EIg({primitiveElement:g,traceOverlayElementIndex:A})??nwA(e?.display_name);if(!C&&!Q)return null;const i=!!(o&&typeof B=="number"&&t>B);return{text:C,name:Q,isOverLength:i}}function T7(g,A){if(!g)return;const I=[];for(const e of[`${g.type}_id`,"pcb_port_id","pcb_trace_id","source_trace_id","source_net_id"]){const t=g[e];typeof t=="string"&&I.push(t)}for(const e of I){const t=A.getNetConnectedToId(e);if(t)return t}if("source_net_id"in g)return g.source_net_id}function uSI(g){return g&&["pcb_trace","pcb_smtpad","pcb_plated_hole","pcb_via","pcb_copper_pour"].includes(g.type)}function Neo(g,A,I){const e=ySI(A),t=g.type==="pcb_trace"?EIg({primitiveElement:g,traceOverlayElementIndex:e}):null;if(t)return t;const o=T7(g,I),B=o?A.filter(C=>T7(C,I)===o):[];for(const C of["source_net","source_trace"])for(const Q of B)if(Q.type===C&&"name"in Q&&typeof Q.name=="string"&&Q.name.trim())return Q.name.trim();if(g.type==="pcb_trace"){const C=wSI({primitiveElement:g,traceOverlayElementIndex:e})?.name;if(C)return C}for(const C of B)if(C.type==="source_trace"&&C.display_name?.trim())return C.display_name.trim();return"Net"}function xeo(g,A,I){return A.flatMap(e=>{if(e.type!=="source_bus")return[];const t=[...new Set(e.source_trace_ids.flatMap(o=>{const B=I.getNetConnectedToId(o);return B?[B]:[]}))];return t.includes(g)?[{id:e.source_bus_id,name:e.name?.trim()||"Bus",netIds:t}]:[]})}var Feo=(g,A)=>{if(g?.type!=="pcb_smtpad"&&g?.type!=="pcb_plated_hole")return;const I=A.find(t=>t.type==="pcb_component"&&t.pcb_component_id===g.pcb_component_id);if(I?.type!=="pcb_component")return;const e=A.find(t=>t.type==="source_component"&&t.source_component_id===I.source_component_id);if(e?.type==="source_component")return{source_component_id:e.source_component_id,pcb_component_id:I.pcb_component_id,refdes:e.name,manufacturer_part_number:e.manufacturer_part_number}},co={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)"}},rk=(g,A=1)=>{if(Math.abs(g.a)!==Math.abs(g.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(g.a)},qIA={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:co.board.copper.f,inner1:co.board.copper.in1,inner2:co.board.copper.in2,inner3:co.board.copper.in3,inner4:co.board.copper.in4,inner5:co.board.copper.in5,inner6:co.board.copper.in6,inner7:co.board.copper.in7,inner8:co.board.copper.in8,bottom:co.board.copper.b,drill:co.board.anchor,keepout:co.board.background,tkeepout:co.board.b_crtyd,tplace:co.board.b_silks,top_courtyard:co.board.f_crtyd,bottom_courtyard:co.board.b_crtyd,top_silkscreen:co.board.f_silks,bottom_silkscreen:co.board.b_silks,top_fabrication:co.board.f_fab,bottom_fabrication:co.board.b_fab,soldermask_top:co.board.soldermask.top,soldermask_bottom:co.board.soldermask.bottom,soldermask_with_copper_top:co.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:co.board.soldermaskWithCopper.bottom,bottom_notes:co.board.user_2,top_notes:co.board.user_2,...co.board},Ueo=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Jeo=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";hiddenLayerOpacity=.2;xRayNetActive=!1;lastPoint;constructor(g){this.canvasLayerMap=g,this.ctxLayerMap=Object.fromEntries(Object.entries(g).map(([A,I])=>[A,I.getContext("2d")])),this.transform=aJ(),this.transform.d*=-1,this.transform=Yw(this.transform,vc(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const g of Object.values(this.ctxLayerMap))g.clearRect(0,0,g.canvas.width,g.canvas.height)}equip(g){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===g.color?1:.5,...g}}drawMeshPattern(g,A,I,e,t,o=45){const B=this.getLayerCtx(),[C,Q]=Mt(this.transform,[g,A]),[i,E]=Mt(this.transform,[g+I,A+e]),n=rk(this.transform,t);B.lineWidth=1,B.strokeStyle=this.aperture.color;const s=r=>{const a=Math.sin(r),c=Math.cos(r),h=Math.sqrt((i-C)**2+(E-Q)**2);for(let l=-h;l<=h;l+=n)B.beginPath(),B.moveTo(C+l*c-h*a,Q+l*a+h*c),B.lineTo(C+l*c+h*a,Q+l*a-h*c),B.stroke()};s(o*Math.PI/180),s((o+90)*Math.PI/180)}rect({x:g,y:A,w:I,h:e,mesh_fill:t,is_filled:o=!0,has_stroke:B,is_stroke_dashed:C,stroke_width:Q,roundness:i}){const[E,n]=Mt(this.transform,[g-I/2,A-e/2]),[s,r]=Mt(this.transform,[g+I/2,A+e/2]);this.applyAperture();const a=this.getLayerCtx(),c=i?rk(this.transform,i):0,h=B===void 0?o===!1:B;if(t)a.save(),a.beginPath(),c>0&&a.roundRect?a.roundRect(E,n,s-E,r-n,c):a.rect(E,n,s-E,r-n),a.clip(),this.drawMeshPattern(g-I/2,A-e/2,I,e,.15),a.restore(),c>0&&a.roundRect?(a.beginPath(),a.roundRect(E,n,s-E,r-n,c),a.stroke()):a.strokeRect(E,n,s-E,r-n);else if(o!==!1&&(c>0&&a.roundRect?(a.beginPath(),a.roundRect(E,n,s-E,r-n,c),a.fill()):a.fillRect(E,n,s-E,r-n)),h){const l=a.lineWidth;if(Q!==void 0&&(a.lineWidth=rk(this.transform,Q)),C){let D=[];const d=Math.abs(this.transform.a);if(d>0){const w=.1*d,u=w*1.3;w>.5&&(D=[w,u])}a.setLineDash(D)}c>0&&a.roundRect?(a.beginPath(),a.roundRect(E,n,s-E,r-n,c),a.stroke()):a.strokeRect(E,n,s-E,r-n),C&&a.setLineDash([]),Q!==void 0&&(a.lineWidth=l)}}rotatedRect(g,A,I,e,t,o,B){const C=this.getLayerCtx();this.applyAperture();const[Q,i]=Mt(this.transform,[g-I/2,A-e/2]),[E,n]=Mt(this.transform,[g+I/2,A+e/2]),s=o?rk(this.transform,o):0;C.save();const[r,a]=Mt(this.transform,[g,A]);C.translate(r,a);const c=360-t;t&&C.rotate(c*Math.PI/180),C.translate(-r,-a),B?(C.beginPath(),s>0&&C.roundRect?C.roundRect(Q,i,E-Q,n-i,s):C.rect(Q,i,E-Q,n-i),C.clip(),this.drawMeshPattern(g-I/2,A-e/2,I,e,.15),s>0&&C.roundRect?(C.beginPath(),C.roundRect(Q,i,E-Q,n-i,s),C.stroke()):C.strokeRect(Q,i,E-Q,n-i)):s>0&&C.roundRect?(C.beginPath(),C.roundRect(Q,i,E-Q,n-i,s),C.fill()):C.fillRect(Q,i,E-Q,n-i),C.restore()}rotatedPill(g,A,I,e,t){const o=this.getLayerCtx();this.applyAperture(),o.save();const[B,C]=Mt(this.transform,[g,A]);o.translate(B,C);const Q=360-t;t&&o.rotate(Q*Math.PI/180),o.translate(-B,-C),this.pill(g,A,I,e),o.restore()}circle(g,A,I,e,t=!0){const o=rk(this.transform,I),[B,C]=Mt(this.transform,[g,A]);this.applyAperture();const Q=this.getLayerCtx();e?(Q.save(),Q.beginPath(),Q.arc(B,C,o,0,2*Math.PI),Q.clip(),this.drawMeshPattern(g-I,A-I,I*2,I*2,.15),Q.restore(),Q.beginPath(),Q.arc(B,C,o,0,2*Math.PI),Q.stroke()):(Q.beginPath(),Q.arc(B,C,o,0,2*Math.PI),Q.fill())}oval(g,A,I,e){const t=rk(this.transform,I),o=rk(this.transform,e),[B,C]=Mt(this.transform,[g,A]);this.applyAperture();const Q=this.getLayerCtx();Q.beginPath(),Q.ellipse(B,C,t,o,0,0,2*Math.PI),Q.fill(),Q.closePath()}pill(g,A,I,e){const[t,o]=Mt(this.transform,[g-I/2,A+e/2]),B=rk(this.transform,I),C=rk(this.transform,e),Q=Math.min(B,C)/2;this.applyAperture();const i=this.getLayerCtx();i.beginPath(),i.arc(t+Q,o+Q,Q,Math.PI,Math.PI*1.5),i.arc(t+B-Q,o+Q,Q,Math.PI*1.5,0),i.arc(t+B-Q,o+C-Q,Q,0,Math.PI*.5),i.arc(t+Q,o+C-Q,Q,Math.PI*.5,Math.PI),i.fill(),i.closePath()}polygon(g){if(g.length<3)return;this.applyAperture();const A=this.getLayerCtx(),I=g.map(t=>Mt(this.transform,[t.x,t.y]));A.beginPath(),A.moveTo(I[0][0],I[0][1]);for(let t=1;t<I.length;t++)A.lineTo(I[t][0],I[t][1]);A.closePath(),A.fill("evenodd");const e=rk(this.transform,this.aperture.size);e>0&&(A.lineWidth=e,A.stroke())}debugText(g,A,I){const[e,t]=Mt(this.transform,[A,I]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(g,e,t)}getLayerCtx(){const g=this.ctxLayerMap[this.aperture.layer];if(!g)throw new Error(`No context for layer "${this.aperture.layer}"`);return g}getLayerOpacity(g){if(this.xRayNetActive)return/^(top|bottom|inner\d+)$/.test(g)?this.hiddenLayerOpacity:0;const A=this.foregroundLayer,I=(A==="top"||A==="bottom")&&(g.startsWith(`${A}_`)||g.endsWith(`_${A}`)),e=["board","drill","edge_cuts","other"].includes(g);return g===A||I||e?1:this.hiddenLayerOpacity}orderAndFadeLayers(){const{canvasLayerMap:g,foregroundLayer:A}=this,e=["board",...Object.keys(g).filter(n=>/^inner\d+$/.test(n)).sort((n,s)=>Number(s.slice(5))-Number(n.slice(5))),...Ueo.filter(n=>n!=="board")],t=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,o=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,B=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,C=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,Q=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,i=[A,"edge_cuts",...t?[t]:[],...o?[o]:[],...B?[B]:[],...C?[C]:[],...Q?[Q]:[]],E=[...e.filter(n=>!i.includes(n)),...A==="drill"?[]:[A],...t?[t]:[],"edge_cuts",...o?[o]:[],...B?[B]:[],...C?[C]:[],...Q?[Q]:[],"drill"];E.forEach((n,s)=>{const r=g[n];r&&(r.style.zIndex=`${Da.topLayer-(E.length-s)}`)});for(const[n,s]of Object.entries(g)){const r=this.getLayerOpacity(n);s.style.opacity=String(r),s.style.display=r===0?"none":""}}applyAperture(){const{transform:g,aperture:A}=this;let{size:I,mode:e,color:t,fontSize:o,layer:B}=A;B in this.ctxLayerMap||(this.aperture.layer="other");const C=this.getLayerCtx();if(!C)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(t||(t="undefined"),C.lineWidth=rk(g,I),C.lineCap="round",e==="add"){C.globalCompositeOperation="source-over";let Q=qIA[t.toLowerCase()];if(!Q)try{Q=wQ(t).rgb().toString()}catch{console.warn(`Invalid color format: '${t}'`),Q="white"}C.fillStyle=Q,C.strokeStyle=Q}else C.globalCompositeOperation="destination-out",C.fillStyle="rgba(0,0,0,1)",C.strokeStyle="rgba(0,0,0,1)";C.font=`${rk(Gx(g),o)}px sans-serif`}moveTo(g,A){this.lastPoint={x:g,y:A}}lineTo(g,A){const[I,e]=Mt(this.transform,[g,A]),{size:t,shape:o,mode:B}=this.aperture,C=rk(this.transform,t),{lastPoint:Q}=this,i=Mt(this.transform,Q);this.applyAperture();const E=this.getLayerCtx();o==="square"&&E.fillRect(i.x-C/2,i.y-C/2,C,C),E.beginPath(),E.moveTo(i.x,i.y),E.lineTo(I,e),E.stroke(),E.closePath(),o==="square"&&E.fillRect(I-C/2,e-C/2,C,C),this.lastPoint={x:g,y:A}}polygonWithArcs(g){const A=this.getLayerCtx(),I=e=>{if(e.vertices.length===0)return;const t=e.vertices[0],o=Mt(this.transform,[t.x,t.y]);A.moveTo(o[0],o[1]);for(let B=0;B<e.vertices.length;B++){const C=e.vertices[B],Q=e.vertices[(B+1)%e.vertices.length];if(C.bulge&&C.bulge!==0){const i=C.bulge,E=Q.x-C.x,n=Q.y-C.y,s=Math.sqrt(E*E+n*n);if(s<1e-9){const R=Mt(this.transform,[Q.x,Q.y]);A.lineTo(R[0],R[1]);continue}const r=4*Math.atan(i),a=Math.abs(s/(2*Math.sin(r/2))),c=(C.x+Q.x)/2,h=(C.y+Q.y)/2,l=E/s,d=-(n/s),y=l,w=Math.sqrt(Math.max(0,a*a-(s/2)**2)),u=c+w*d*Math.sign(i),G=h+w*y*Math.sign(i),m=Math.atan2(C.y-G,C.x-u);let p=Math.atan2(Q.y-G,Q.x-u);i>0&&p<m?p+=2*Math.PI:i<0&&p>m&&(p-=2*Math.PI);const k=Mt(this.transform,[u,G]),S=rk(this.transform,a);A.arc(k[0],k[1],S,-m,-p,i>0)}else{const i=Mt(this.transform,[Q.x,Q.y]);A.lineTo(i[0],i[1])}}A.closePath()};if(A.beginPath(),I(g.outer_ring),g.inner_rings)for(const e of g.inner_rings)I(e);A.fill("evenodd")}},Keo=(g=2)=>{const A=Math.max(2,Math.min(10,Math.floor(g)));return["top",...Array.from({length:A-2},(I,e)=>`inner${e+1}`),"bottom"]},swA=g=>{const A=g.find(I=>I.type==="pcb_board");return Keo(A?.num_layers??2)},nIg=g=>`${g}_copper`,GSI=g=>g.map(A=>A.endsWith("_copper")?A.slice(0,-7):A),Peo=g=>["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication",...swA(g).filter(I=>I.startsWith("inner")),"drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],Leo=(g,A)=>{const I=swA(g).reverse();return[...I.filter(e=>e!==A),...I.filter(e=>e===A)]},Yeo={...Kw,courtyard:{top:co.board.f_crtyd,bottom:co.board.b_crtyd}};function _eo(g){return g.type==="pcb_courtyard_circle"||g.type==="pcb_courtyard_rect"||g.type==="pcb_courtyard_outline"}function mSI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.configure({colorOverrides:Yeo}),t.realToCanvasMat=e;const o=A.filter(_eo);t.drawElements(o,{layers:I})}var beo={...Kw,silkscreen:{top:co.board.f_fab,bottom:co.board.b_fab}};function Heo(g){return g.type.includes("pcb_fabrication_note")}function pSI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.configure({colorOverrides:beo}),t.realToCanvasMat=e;const o=A.filter(Heo);t.drawElements(o,{layers:I})}function veo(g){return g.type==="pcb_hole"}function qeo({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermask:t}){const o=new VE(g);o.realToCanvasMat=e;const B=A.filter(veo);o.drawElements(B,{layers:I,drawSoldermask:t})}function Teo(g){return g.type==="pcb_board"}function kSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermask:t}){const o=new VE(g);o.realToCanvasMat=e;const B=A.filter(Teo);for(const C of B)o.drawElements([C],{layers:I,drawSoldermask:!1,drawBoardMaterial:t??!1,minBoardOutlineStrokePx:2})}function Zeo(g){return g.type==="pcb_copper_text"}function Oeo({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=A.filter(Zeo);if(t.length===0)return;const o=new VE(g);o.realToCanvasMat=e,o.drawElements(t,{layers:I})}function Weo(g){return g.type==="pcb_cutout"}function Veo({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.realToCanvasMat=e;const o=A.filter(Weo);t.drawElements(o,{layers:I})}function jeo(g){return g.type==="pcb_keepout"}function zeo({elements:g,layer:A}){return g.filter(jeo).filter(I=>I.layers.includes(A))}function Xeo(g){return wQ(qIA[g]).lighten(.4).hex()}function $eo({canvas:g,elements:A,layer:I,realToCanvasMat:e}){const t=zeo({elements:A,layer:I});if(t.length===0)return;const o=new VE(g),B=Xeo(I);o.configure({colorOverrides:{keepout:{top:B,bottom:B}}}),o.realToCanvasMat=e,o.drawElements(t,{layers:[nIg(I)]})}function Ato(g){return g.type.startsWith("pcb_note_")}function MSI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.realToCanvasMat=e;const o=A.filter(Ato);t.drawElements(o,{layers:I})}function gto(g){return g.type==="pcb_panel"}function Ito({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermask:t}){const o=new VE(g);o.realToCanvasMat=e;const B=A.filter(gto);for(const C of B)o.drawElements([C],{layers:I})}var eto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()}};function tto(g){return g.type==="pcb_smtpad"}function SSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,drawSoldermask:o}){const B=new Set(GSI(I)),C=A.filter(tto).filter(n=>B.has(n.layer));if(C.length===0)return;const Q=new Set;if(t)for(const n of t)(n.is_mouse_over||n.is_in_highlighted_net)&&n._element?.type==="pcb_smtpad"&&Q.add(n._element.pcb_smtpad_id);const i=C.filter(n=>Q.has(n.pcb_smtpad_id)),E=C.filter(n=>!Q.has(n.pcb_smtpad_id));if(E.length>0){const n=new VE(g);n.realToCanvasMat=e,n.drawElements(E,{layers:I,drawSoldermask:o})}if(i.length>0){const n=new VE(g);n.configure({colorOverrides:eto}),n.realToCanvasMat=e,n.drawElements(i,{layers:I,drawSoldermask:o})}}var oto={...Kw,copper:Object.fromEntries(Object.entries(Kw.copper).map(([g,A])=>[g,wQ(A).lighten(.5).toString()]))};function Bto(g){return g.type==="pcb_trace"}var Cto=(g,A)=>{const I=g.route.filter(o=>o.route_type==="wire"&&"layer"in o&&A.has(o.layer)?!0:o.route_type==="via"?A.has(o.from_layer)||A.has(o.to_layer):!1),e=I.filter(o=>o.route_type==="wire").length,t=I.some(o=>o.route_type==="via");return e<2&&!t?null:{...g,route:I}},Qto=g=>({...g,route:g.route.map(A=>!("is_inside_copper_pour"in A)||A.is_inside_copper_pour!==!0?A:{...A,is_inside_copper_pour:!1})}),ito=(g,A)=>A?g:g.filter(I=>I.type!=="pcb_copper_pour"),Eto=({primitives:g})=>{const A=new Set;for(const I of g)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_trace"&&A.add(I._element.pcb_trace_id);return A};function fSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,showCopperPours:o}){const B=new Set(GSI(I)),C=A.filter(Bto).map(s=>Cto(s,B)).filter(s=>s!==null).map(s=>o?s:Qto(s));if(C.length===0)return;const Q=Eto({primitives:t??[]}),i=[],E=[];for(const s of C)Q.has(s.pcb_trace_id)?i.push(s):E.push(s);const n=ito(A,o);if(E.length>0){const s=new VE(g);s.realToCanvasMat=e,s.drawElements(E,{layers:I,clipContextElements:n})}if(i.length>0){const s=new VE(g);s.configure({colorOverrides:oto}),s.realToCanvasMat=e,s.drawElements(i,{layers:I,clipContextElements:n})}}var nto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()}};function sto(g){return g.type==="pcb_plated_hole"}function RSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,drawSoldermask:o}){const B=A.filter(sto);if(B.length===0)return;const C=new Set;if(t)for(const E of t)(E.is_mouse_over||E.is_in_highlighted_net)&&E._element?.type==="pcb_plated_hole"&&C.add(E._element.pcb_plated_hole_id);const Q=B.filter(E=>C.has(E.pcb_plated_hole_id)),i=B.filter(E=>!C.has(E.pcb_plated_hole_id));if(i.length>0){const E=new VE(g);E.realToCanvasMat=e,E.drawElements(i,{layers:I,drawSoldermask:o})}if(Q.length>0){const E=new VE(g);E.configure({colorOverrides:nto}),E.realToCanvasMat=e,E.drawElements(Q,{layers:I,drawSoldermask:o})}}function NSI(g){const{lines:A,anchorPoint:I,ccwRotation:e}=g;if(!e)return A;const t=e*Math.PI/180,o=ekI(t),B=Yw(vc(I.x,I.y),o,vc(-I.x,-I.y));return Mt(B,I),A.map(C=>({...C,x1:Mt(B,{x:C.x1,y:C.y1}).x,y1:Mt(B,{x:C.x1,y:C.y1}).y,x2:Mt(B,{x:C.x2,y:C.y2}).x,y2:Mt(B,{x:C.x2,y:C.y2}).y}))}var ato=.6,xSI=.2,FSI=g=>{const A=g.size*.7,I=A*ato,e=A*xSI,t=A*xSI,o=g.text.split(/\r?\n/),B=g.text.length>0&&A>0,C=B?o.length:0,Q=B?o.map(n=>n.length===0?0:n.length*I+(n.length-1)*e):[],i=Q.length>0?Math.max(...Q):0,E=C>0?C*A+(C-1)*t:0;return{text_lines:o,line_count:C,line_widths:Q,target_height:A,target_width_char:I,space_between_chars:e,space_between_lines:t,width:i,height:E}},USI=g=>{const A=FSI(g);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},JSI=g=>{const{text_lines:A,line_count:I,line_widths:e,target_height:t,target_width_char:o,space_between_chars:B,space_between_lines:C,width:Q}=FSI(g);if(t<=0||I===0)return[];const i=t/12,E=[];for(let n=0;n<I;n++){const s=-n*(t+C),r=e[n],a=(Q-r)/2;let c=g.x+a;for(let h=0;h<A[n].length;h++){const l=A[n][h],D=NF[l]??NF[l.toUpperCase()];if(!D){c+=o+B;continue}for(const{x1:d,y1:y,x2:w,y2:u}of D)E.push({_pcb_drawing_object_id:MR("line"),pcb_drawing_type:"line",x1:c+o*d,y1:g.y+s+t*y,x2:c+o*w,y2:g.y+s+t*u,width:i,layer:g.layer,unit:g.unit,color:g.color});c+=o+B}}return E};function Rx(g){const I=g.color??qIA[g.layer];let e=wQ(I);return g._element?.type==="pcb_copper_pour"&&(e=e.alpha(.7)),g.is_mouse_over||g.is_in_highlighted_net?e.lighten(.5).rgb().toString():e.rgb().toString()}var KSI=(g,A)=>{g.equip({size:A.zoomIndependent?A.width/g.transform.a:A.width,shape:A.squareCap?"square":"circle",color:Rx(A),layer:A.layer}),g.moveTo(A.x1,A.y1),g.lineTo(A.x2,A.y2)},rto=(g,A,I)=>{switch(I){case"top_left":return{x:0,y:-A};case"top_center":return{x:-g/2,y:-A};case"top_right":return{x:-g,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-g/2,y:-A/2};case"center_right":return{x:-g,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-g/2,y:0};case"bottom_right":return{x:-g,y:0};default:return{x:0,y:0}}},PSI=g=>g.layer==="bottom_silkscreen"||g.layer==="bottom"?g.is_mirrored!==!1:g.is_mirrored===!0,cto=(g,A)=>{g.equip({fontSize:A.size,color:Rx(A),layer:A.layer});const{width:I,height:e}=USI(A),t=rto(I,e,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let B=JSI({...A,x:A.x+t.x,y:A.y+t.y});if(PSI(A)&&(B=B.map(C=>({...C,x1:2*A.x-C.x1,x2:2*A.x-C.x2}))),A.ccw_rotation){const C={lines:B,anchorPoint:o,ccwRotation:A.ccw_rotation};B=NSI(C)}for(const C of B)KSI(g,C)},hto=(g,A)=>{const{width:I,height:e,lineHeight:t}=USI(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},B=I+o.left+o.right,C=e+o.top+o.bottom,Q=I/2,i=t-e/2,E=A.x-Q,n=A.y-i,s={x:A.x,y:A.y},r={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:B,h:C,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?YSI(g,r):LSI(g,r);let a=JSI({...A,x:E,y:n});if(PSI(A)&&(a=a.map(c=>({...c,x1:2*A.x-c.x1,x2:2*A.x-c.x2}))),A.ccw_rotation){const c={lines:a,anchorPoint:s,ccwRotation:A.ccw_rotation};a=NSI(c)}for(const c of a)g.equip({size:c.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),g.moveTo(c.x1,c.y1),g.lineTo(c.x2,c.y2);g.equip({mode:"add"})},LSI=(g,A)=>{g.equip({color:Rx(A),layer:A.layer,size:A.stroke_width}),g.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},YSI=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},lto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},Dto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.circle(A.x,A.y,A.r,A.mesh_fill)},dto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.oval(A.x,A.y,A.rX,A.rY)},yto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.pill(A.x,A.y,A.w,A.h)},wto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.polygon(A.points)},uto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.polygonWithArcs(A.brep_shape)},Gto=(g,A)=>{switch(A.pcb_drawing_type){case"line":return KSI(g,A);case"text":return A.is_knockout?hto(g,A):cto(g,A);case"rect":return A.ccw_rotation?YSI(g,A):LSI(g,A);case"circle":return Dto(g,A);case"oval":return dto(g,A);case"pill":return A.ccw_rotation?lto(g,A):yto(g,A);case"polygon":return wto(g,A);case"polygon_with_arcs":return uto(g,A)}},mto=(g,A)=>{for(const I of A)Gto(g,I)},pto={...Kw,silkscreen:{top:co.board.f_silks,bottom:co.board.b_silks}};function kto(g){return g.type.includes("pcb_silkscreen")}function _SI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.configure({colorOverrides:pto}),t.realToCanvasMat=e;const o=A.filter(kto);t.drawElements(o,{layers:I})}var Mto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()},soldermask:{...Kw.soldermask,top:wQ(co.board.soldermask.top).lighten(.35).toString(),bottom:wQ(co.board.soldermask.bottom).lighten(.35).toString()}};function bSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermaskTop:t,drawSoldermaskBottom:o,primitives:B}){const C=new VE(g);C.realToCanvasMat=e;const Q=A.filter(s=>s.type==="pcb_board");if(C.drawElements(A,{layers:I,drawSoldermask:!0,drawSoldermaskTop:t,drawSoldermaskBottom:o,drawBoardMaterial:!1}),Q.length>1&&kSI({canvas:g,elements:Q,layers:[],realToCanvasMat:e,drawSoldermask:!1}),!B)return;const i=new Set;for(const s of B){if(!(s.is_mouse_over||s.is_in_highlighted_net))continue;const r=s._element;r?.type==="pcb_smtpad"?i.add(r.pcb_smtpad_id):r?.type==="pcb_plated_hole"?i.add(r.pcb_plated_hole_id):r?.type==="pcb_via"&&i.add(r.pcb_via_id)}if(i.size===0)return;const E=A.filter(s=>s.type==="pcb_smtpad"?i.has(s.pcb_smtpad_id):s.type==="pcb_plated_hole"?i.has(s.pcb_plated_hole_id):s.type==="pcb_via"?i.has(s.pcb_via_id):!1);if(E.length===0)return;const n=new VE(g);n.configure({colorOverrides:Mto}),n.realToCanvasMat=e,n.drawElements(E,{layers:I,clipContextElements:A,drawSoldermask:!0,drawSoldermaskTop:t,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var Sto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()}};function fto(g){return g.type==="pcb_via"}function HSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,drawSoldermask:o}){const B=A.filter(fto).filter(E=>I.some(n=>n.includes("copper")));if(B.length===0)return;const C=new Set;if(t)for(const E of t)(E.is_mouse_over||E.is_in_highlighted_net)&&E._element?.type==="pcb_via"&&C.add(E._element.pcb_via_id);const Q=B.filter(E=>C.has(E.pcb_via_id)),i=B.filter(E=>!C.has(E.pcb_via_id));if(i.length>0){const E=new VE(g);E.realToCanvasMat=e,E.drawElements(i,{layers:I,drawSoldermask:o,drawSoldermaskTop:I.includes("top_copper"),drawSoldermaskBottom:I.includes("bottom_copper"),clipContextElements:A})}if(Q.length>0){const E=new VE(g);E.configure({colorOverrides:Sto}),E.realToCanvasMat=e,E.drawElements(Q,{layers:I,drawSoldermask:o,drawSoldermaskTop:I.includes("top_copper"),drawSoldermaskBottom:I.includes("bottom_copper"),clipContextElements:A})}}var Rto=({primitives:g,isShowingSolderMask:A,isShowingSilkscreen:I,isShowingFabricationNotes:e})=>g.filter(t=>A||!t.layer?.includes("soldermask")).filter(t=>I||!t.layer?.includes("silkscreen")).filter(t=>e||!t.layer?.includes("fabrication")).filter(t=>t.layer!=="board").filter(t=>t._element?.type!=="pcb_smtpad").filter(t=>t._element?.type!=="pcb_plated_hole"||t.layer==="drill").filter(t=>t._element?.type!=="pcb_via").filter(t=>t._element?.type!=="pcb_trace").filter(t=>t._element?.type!=="pcb_copper_text"),Nto=({primitives:g,elements:A,circuitJson:I,xRayElements:e,transform:t,grid:o,width:B=500,height:C=500,onRenderComplete:Q})=>{const i=gA.useRef(null),E=gA.useRef({}),n=gA.useRef(Q),s=gA.useRef(void 0),r=Qi(u=>u.hidden_layer_opacity),a=Qi(u=>u.selected_layer),c=Qi(u=>u.copper_pour_opacity),h=Qi(u=>u.is_showing_copper_pours),l=Qi(u=>u.is_showing_solder_mask),D=Qi(u=>u.is_showing_fabrication_notes),d=Qi(u=>u.is_showing_pcb_notes),y=Qi(u=>u.is_showing_courtyards),w=Qi(u=>u.is_showing_silkscreen);return gA.useEffect(()=>{n.current=Q},[Q]),gA.useEffect(()=>{if(!E.current||Object.keys(E.current).length===0)return;const u=Object.fromEntries(Object.entries(E.current).filter(([S,R])=>!!R));if(Object.keys(u).length===0)return;const G=new Jeo(u);t&&(G.transform=t),G.clear(),G.foregroundLayer=a,G.hiddenLayerOpacity=r,G.xRayNetActive=!!e;const m=Object.fromEntries(Object.entries(u).filter(([S])=>G.getLayerOpacity(S)>0)),p=Rto({primitives:g,isShowingSolderMask:l,isShowingSilkscreen:w,isShowingFabricationNotes:D});if(mto(G,p.filter(S=>G.getLayerOpacity(S.layer??"other")>0)),t){const S=swA(A).map(U=>({canvas:m[U],layer:U,copperLayer:nIg(U)}));for(const{canvas:U,copperLayer:L}of S)U&&fSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,showCopperPours:h&&c>0});for(const{canvas:U,copperLayer:L}of S)U&&Oeo({canvas:U,elements:A,layers:[L],realToCanvasMat:t});for(const{canvas:U,copperLayer:L,layer:b}of S)U&&RSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,drawSoldermask:l&&(b==="top"||b==="bottom")});for(const{canvas:U,copperLayer:L}of S)U&&QSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,opacity:h?c:0});for(const{canvas:U,copperLayer:L}of S)U&&SSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,drawSoldermask:l});for(const{canvas:U,copperLayer:L,layer:b}of S)U&&HSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,drawSoldermask:l&&(b==="top"||b==="bottom")});if(l){const U=a==="bottom"?"bottom":"top",L=U==="top",b=U==="bottom",H=m.soldermask_top;H&&U==="top"&&bSI({canvas:H,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:L,drawSoldermaskBottom:b,primitives:g});const q=m.soldermask_bottom;q&&U==="bottom"&&bSI({canvas:q,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:L,drawSoldermaskBottom:b,primitives:g})}const R=m.drill;if(R&&qeo({canvas:R,elements:A,layers:["drill"],realToCanvasMat:t}),w){const U=m.top_silkscreen;U&&_SI({canvas:U,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const L=m.bottom_silkscreen;L&&_SI({canvas:L,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(D){const U=m.top_fabrication;U&&pSI({canvas:U,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const L=m.bottom_fabrication;L&&pSI({canvas:L,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t})}if(d){const U=m.bottom_notes;U&&MSI({canvas:U,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const L=m.top_notes;L&&MSI({canvas:L,elements:A,layers:["top_user_note"],realToCanvasMat:t})}if(y){const U=m.top_courtyard;U&&mSI({canvas:U,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const L=m.bottom_courtyard;L&&mSI({canvas:L,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t})}const F=m.board;F&&(Ito({canvas:F,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:l}),kSI({canvas:F,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:l}));const N=m.edge_cuts;N&&Veo({canvas:N,elements:A,layers:["edge_cuts"],realToCanvasMat:t});for(const{canvas:U,layer:L}of S)U&&$eo({canvas:U,elements:A,layer:L,realToCanvasMat:t})}G.orderAndFadeLayers();const k=i.current;if(k&&t&&e){k.getContext("2d").clearRect(0,0,B,C);for(const R of Leo(A,a)){const F={canvas:k,elements:e,layers:[nIg(R)],realToCanvasMat:t,drawSoldermask:!1};h&&QSI({...F,opacity:c}),fSI({...F,showCopperPours:!1}),SSI(F),RSI(F),HSI(F)}const S=new VE(k);S.realToCanvasMat=t,S.drawElements(e.filter(R=>R.type==="pcb_via"||R.type==="pcb_plated_hole"),{layers:["drill"],drawSoldermask:!1})}s.current!==I&&(s.current=I,n.current?.())},[g,A,I,e,B,C,t,a,r,c,h,l,D,d,y,w]),W.jsxs("div",{style:{backgroundColor:"black",width:B,height:C,position:"relative"},children:[W.jsx(d5.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:B,height:C,transform:t,stringifyCoord:(u,G,m)=>`${d5.toMMSI(u,m)}, ${d5.toMMSI(G,m)}`}),e&&W.jsx("canvas",{ref:i,className:"pcb-x-ray-net",width:B,height:C,style:{position:"absolute",left:0,top:0,zIndex:Da.topLayer,pointerEvents:"none"}}),Peo(A).filter(u=>!(!l&&u.includes("soldermask")||!w&&u.includes("silkscreen"))).map(u=>u.replace(/-/g,"")).map((u,G)=>W.jsx("canvas",{className:`pcb-layer-${u}`,ref:m=>{E.current??={},m?E.current[u]=m:delete E.current[u]},style:{position:"absolute",zIndex:G,left:0,top:0,pointerEvents:"none"},width:B,height:C},u))]})};new TextEncoder,(()=>{const g=new Uint8Array(4),A=new Uint32Array(g.buffer);return!((A[0]=1)&g[0])})();var xto=new Uint16Array([255]),Fto=new Uint8Array(xto.buffer);Fto[0];var Uto=new Uint16Array([255]),Jto=new Uint8Array(Uto.buffer);Jto[0],new TextDecoder("latin1");var k3=1e-9,awA=(g,A,I)=>g>=A-k3&&g<=I+k3,Kto=g=>{const A=[];for(const I of g)A.some(e=>Math.abs(e.x-I.x)<k3&&Math.abs(e.y-I.y)<k3)||A.push(I);return A};function Pto(g,A){const{origin:I,directionVector:e}=g;if(Math.abs(e.x)<k3&&Math.abs(e.y)<k3)return null;const t=[];if(Math.abs(e.x)>=k3){const i=(A.minX-I.x)/e.x,E=I.y+i*e.y;awA(E,A.minY,A.maxY)&&t.push({x:A.minX,y:E});const n=(A.maxX-I.x)/e.x,s=I.y+n*e.y;awA(s,A.minY,A.maxY)&&t.push({x:A.maxX,y:s})}if(Math.abs(e.y)>=k3){const i=(A.minY-I.y)/e.y,E=I.x+i*e.x;awA(E,A.minX,A.maxX)&&t.push({x:E,y:A.minY});const n=(A.maxY-I.y)/e.y,s=I.x+n*e.x;awA(s,A.minX,A.maxX)&&t.push({x:s,y:A.maxY})}const o=Kto(t);if(o.length<2)return null;let B=o[0],C=o[1],Q=(B.x-C.x)**2+(B.y-C.y)**2;for(let i=0;i<o.length;i++)for(let E=i+1;E<o.length;E++){const n=o[i],s=o[E],r=(n.x-s.x)**2+(n.y-s.y)**2;r>Q&&(B=n,C=s,Q=r)}return[B,C]}function Lto(g,A,I){const e=Gx(g),t=[Mt(e,{x:0,y:0}),Mt(e,{x:A,y:0}),Mt(e,{x:0,y:I}),Mt(e,{x:A,y:I})];return{minX:Math.min(...t.map(o=>o.x)),maxX:Math.max(...t.map(o=>o.x)),minY:Math.min(...t.map(o=>o.y)),maxY:Math.max(...t.map(o=>o.y))}}var Yto=.6,_to=1,vSI=(g,A)=>Math.hypot(g.x-A.x,g.y-A.y),qSI=g=>(g.ccwRotationDegrees??0)*Math.PI/180,bto=g=>g.a*g.d-g.b*g.c<0?1:-1,Hto=(g,A)=>qSI(g)*bto(A),vto=(g,A)=>{const I=Math.cos(A),e=Math.sin(A);return{x:g.x*I-g.y*e,y:g.x*e+g.y*I}},qto=g=>TSI(g,qSI(g)),Tto=(g,A)=>TSI(g,Hto(g,A)),TSI=(g,A)=>{const I=g.width/2,e=g.height/2;return[{x:-I,y:-e},{x:I,y:-e},{x:I,y:e},{x:-I,y:e}].map(t=>{const o=vto(t,A);return{x:g.center.x+o.x,y:g.center.y+o.y}})},Zto=(g,A)=>{const I=Tto(g,A).map(i=>Mt(A,i)),e=Mt(A,g.center),t=vSI(I[0],I[1]),o=vSI(I[1],I[2]),B=I.length>=2?Math.atan2(I[1].y-I[0].y,I[1].x-I[0].x):0,C=B*180/Math.PI,Q=I.reduce((i,E)=>({minX:Math.min(i.minX,E.x),maxX:Math.max(i.maxX,E.x),minY:Math.min(i.minY,E.y),maxY:Math.max(i.maxY,E.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0});return{center:e,corners:I,width:t,height:o,angleRadians:B,angleDegrees:C,bounds:Q}},Oto=2,Wto=12,Vto=12,rwA=g=>({tip:{...g},base:{...g},leftWing:{...g},rightWing:{...g}}),ZSI=(g,A,I)=>{const e=g.x-A.x,t=g.y-A.y,o=Math.hypot(e,t);if(o===0)return rwA(g);const B=e/o,Q=-(t/o)*(I/2),i=B*(I/2);return{tip:{...g},base:{...A},leftWing:{x:A.x+Q,y:A.y+i},rightWing:{x:A.x-Q,y:A.y-i}}};function OSI(g){const{start:A,end:I}=g,e=I.x-A.x,t=I.y-A.y,o=Math.hypot(e,t),B=Oto,C=Wto;if(o===0){const D=g.doubleSided?[rwA(A),rwA(A)]:[rwA(A)];return{shaftStart:{...A},shaftEnd:{...A},heads:D,shaftWidth:B,headLength:0,headWidth:C,length:o}}const Q=e/o,i=t/o,E=Math.min(Vto,o*.5),n=Math.max(E,B*2),s=g.doubleSided?o/2:o,r=Math.min(n,s),a={x:I.x-Q*r,y:I.y-i*r},c=[ZSI(I,a,C)];let h={...A};const l={...a};if(g.doubleSided){const D={x:A.x+Q*r,y:A.y+i*r};c.unshift(ZSI(A,D,C)),h=D}return{shaftStart:h,shaftEnd:l,heads:c,shaftWidth:B,headLength:r,headWidth:C,length:o}}function jto(g){const A=OSI(g);return[A.shaftStart,A.shaftEnd,...A.heads.flatMap(e=>[e.tip,e.base,e.leftWing,e.rightWing])].reduce((e,t)=>({minX:Math.min(e.minX,t.x),maxX:Math.max(e.maxX,t.x),minY:Math.min(e.minY,t.y),maxY:Math.max(e.maxY,t.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function WSI(g,A,{fontSize:I=12,strokeWidth:e=2,normalPadding:t=6,alongOffset:o=0}={}){const B={x:(g.x+A.x)/2,y:(g.y+A.y)/2},C=A.x-g.x,Q=A.y-g.y,i=Math.hypot(C,Q);if(i===0)return{x:B.x+o,y:B.y-(e/2+I*.65+t),angleRadians:0,angleDegrees:0,direction:{x:1,y:0},normal:{x:0,y:-1}};let E=C/i,n=Q/i,s=-n,r=E;(E<0||E===0&&n<0)&&(E=-E,n=-n,s=-s,r=-r);const c=Math.atan2(n,E),h=e/2+I*.65+t;return{x:B.x+s*h+E*o,y:B.y+r*h+n*o,angleRadians:c,angleDegrees:c*180/Math.PI,direction:{x:E,y:n},normal:{x:s,y:r}}}var M3=["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 VSI(g,A,I,e={}){const t=e.padding??40,o=e.yFlip??!1;let B;if("center"in g){const E=g.width/2,n=g.height/2;B={minX:g.center.x-E,maxX:g.center.x+E,minY:g.center.y-n,maxY:g.center.y+n}}else B=g;const C=B.maxX-B.minX||1,Q=B.maxY-B.minY||1,i=Math.min((A-2*t)/C,(I-2*t)/Q);return Yw(vc(A/2,I/2),rJ(i,o?-i:i),vc(-(B.minX+C/2),-(B.minY+Q/2)))}function zto(g){const A=[...g.points||[],...(g.lines||[]).flatMap(I=>I.points),...(g.polygons||[]).flatMap(I=>I.points),...(g.rects||[]).flatMap(I=>qto(I)),...(g.circles||[]).flatMap(I=>[{x:I.center.x-I.radius,y:I.center.y},{x:I.center.x+I.radius,y:I.center.y},{x:I.center.x,y:I.center.y-I.radius},{x:I.center.x,y:I.center.y+I.radius}]),...(g.arrows||[]).flatMap(I=>{const e=jto(I);return[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]}),...(g.texts||[]).flatMap(I=>{const e=I.fontSize??12,t=I.text.length*e*Yto,o=e*_to,B=I.anchorSide??"center",C={top_left:{dx:0,dy:0},top_center:{dx:-t/2,dy:0},top_right:{dx:-t,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-t/2,dy:-o/2},center_right:{dx:-t,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-t/2,dy:-o},bottom_right:{dx:-t,dy:-o}},{dx:Q,dy:i}=C[B],E=I.x+Q,n=I.y+i;return[{x:E,y:n},{x:E+t,y:n+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((I,e)=>({minX:Math.min(I.minX,e.x),maxX:Math.max(I.maxX,e.x),minY:Math.min(I.minY,e.y),maxY:Math.max(I.maxY,e.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function Xto(g,A,I={}){const e=I.disableLabels!==!1,t=I.hideInlineLabels??e,o=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!o)throw new Error("Could not get 2D context from canvas");const B=A instanceof HTMLCanvasElement?A.width:A.canvas.width,C=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let Q;if(I.transform)Q=I.transform;else if(I.viewbox)Q=VSI(I.viewbox,B,C,{padding:I.padding,yFlip:I.yFlip});else{const i=zto(g),E=g.coordinateSystem==="cartesian";Q=VSI(i,B,C,{padding:I.padding??40,yFlip:E})}if(o.clearRect(0,0,B,C),o.save(),g.rects&&g.rects.length>0&&g.rects.forEach(i=>{const E=Zto(i,Q);o.save(),o.translate(E.center.x,E.center.y),Math.abs(E.angleRadians)>1e-6&&o.rotate(E.angleRadians),o.beginPath(),o.rect(-E.width/2,-E.height/2,E.width,E.height),i.fill&&(o.fillStyle=i.fill,o.fill()),i.stroke&&(o.strokeStyle=i.stroke,o.stroke()),o.restore()}),g.circles&&g.circles.length>0&&g.circles.forEach(i=>{const E=Mt(Q,i.center),n=i.radius*Math.abs(Q.a);o.beginPath(),o.arc(E.x,E.y,n,0,2*Math.PI),i.fill&&(o.fillStyle=i.fill,o.fill()),i.stroke&&(o.strokeStyle=i.stroke??"transparent",o.stroke())}),g.polygons&&g.polygons.length>0&&g.polygons.forEach(i=>{if(i.points.length===0)return;const E=i.points.map(n=>Mt(Q,n));o.beginPath(),o.moveTo(E[0].x,E[0].y);for(let n=1;n<E.length;n++)o.lineTo(E[n].x,E[n].y);o.closePath(),i.fill&&(o.fillStyle=i.fill,o.fill()),i.stroke&&(o.strokeStyle=i.stroke,i.strokeWidth!==void 0&&(o.lineWidth=i.strokeWidth*Math.abs(Q.a)),o.stroke())}),g.arrows&&g.arrows.length>0&&g.arrows.forEach((i,E)=>{const n=OSI(i),s=Mt(Q,n.shaftStart),r=Mt(Q,n.shaftEnd),a=i.color||M3[E%M3.length],c=Math.hypot(Q.a,Q.b);o.strokeStyle=a,o.fillStyle=a,o.lineWidth=n.shaftWidth*(c||1),o.lineCap="round",o.setLineDash([]),o.beginPath(),o.moveTo(s.x,s.y),o.lineTo(r.x,r.y),o.stroke(),n.heads.forEach(w=>{const u=Mt(Q,w.tip),G=Mt(Q,w.leftWing),m=Mt(Q,w.rightWing);o.beginPath(),o.moveTo(u.x,u.y),o.lineTo(G.x,G.y),o.lineTo(m.x,m.y),o.closePath(),o.fill()});const h=12,l=n.shaftWidth*(c||1),D=h*.6,d=WSI(s,r,{fontSize:h,strokeWidth:l,normalPadding:6,alongOffset:i.label?D:0}),y=WSI(s,r,{fontSize:h,strokeWidth:l,normalPadding:12,alongOffset:i.inlineLabel?-D:0});if(o.fillStyle=a,o.font=`${h}px sans-serif`,!e&&i.label){const w=y.x,u=y.y;o.save(),o.textAlign="center",o.textBaseline="middle",o.fillText(i.label,w,u),o.restore()}!t&&i.inlineLabel&&(o.save(),o.translate(d.x,d.y),o.rotate(d.angleRadians),o.textAlign="center",o.textBaseline="middle",o.fillText(i.inlineLabel,0,0),o.restore())}),g.lines&&g.lines.length>0&&g.lines.map((i,E)=>({line:i,originalIndex:E})).sort((i,E)=>(i.line.zIndex??0)-(E.line.zIndex??0)||i.originalIndex-E.originalIndex).forEach(({line:i,originalIndex:E})=>{if(i.points.length===0)return;o.beginPath();const n=Mt(Q,i.points[0]);o.moveTo(n.x,n.y);for(let s=1;s<i.points.length;s++){const r=Mt(Q,i.points[s]);o.lineTo(r.x,r.y)}if(o.strokeStyle=i.strokeColor||M3[E%M3.length],i.strokeWidth?o.lineWidth=i.strokeWidth*Q.a:o.lineWidth=2,o.lineCap="round",i.strokeDash)if(typeof i.strokeDash=="string"){let s;if(i.strokeDash.includes(","))s=i.strokeDash.split(",").map(r=>parseFloat(r.trim())).filter(r=>!Number.isNaN(r));else{const r=parseFloat(i.strokeDash.trim());s=Number.isNaN(r)?[]:[r]}o.setLineDash(s)}else o.setLineDash(i.strokeDash.map(s=>s*Math.abs(Q.a)));else o.setLineDash([]);o.stroke()}),g.infiniteLines&&g.infiniteLines.length>0){const i=Lto(Q,B,C);g.infiniteLines.forEach((E,n)=>{const s=Pto(E,i);if(!s)return;const[r,a]=s,c=Mt(Q,r),h=Mt(Q,a);if(o.beginPath(),o.moveTo(c.x,c.y),o.lineTo(h.x,h.y),o.strokeStyle=E.strokeColor||M3[n%M3.length],o.lineWidth=E.strokeWidth?E.strokeWidth*Math.abs(Q.a):2,o.lineCap="round",E.strokeDash)if(typeof E.strokeDash=="string"){let l;if(E.strokeDash.includes(","))l=E.strokeDash.split(",").map(D=>parseFloat(D.trim())).filter(D=>!Number.isNaN(D));else{const D=parseFloat(E.strokeDash.trim());l=Number.isNaN(D)?[]:[D]}o.setLineDash(l)}else o.setLineDash(E.strokeDash.map(l=>l*Math.abs(Q.a)));else o.setLineDash([]);o.stroke()})}g.texts&&g.texts.length>0&&g.texts.forEach(i=>{const E=Mt(Q,{x:i.x,y:i.y});o.fillStyle=i.color||"black",o.font=`${(i.fontSize??12)*Math.abs(Q.a)}px sans-serif`;const n=i.anchorSide??"center",s={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"},r={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};o.textAlign=s[n],o.textBaseline=r[n],o.fillText(i.text,E.x,E.y)}),g.points&&g.points.length>0&&g.points.forEach((i,E)=>{const n=Mt(Q,i);o.beginPath(),o.arc(n.x,n.y,3,0,2*Math.PI),o.fillStyle=i.color||M3[E%M3.length],o.fill(),i.label&&!e&&(o.fillStyle=i.color||"black",o.font="12px sans-serif",o.fillText(i.label,n.x+5,n.y-5))}),o.restore()}XkI(YAo(),1);var $to=({children:g,transform:A,debugGraphics:I})=>{const e=gA.useRef(null),[t,{width:o,height:B}]=HIA(),C=Qi(Q=>Q.is_showing_autorouting);return gA.useEffect(()=>{C&&e.current&&I&&o&&B&&(e.current.width=o,e.current.height=B,Xto(I,e.current,{transform:A,disableLabels:!0}))},[I,A,o,B,C]),C?W.jsxs("div",{ref:t,style:{position:"relative",width:"100%",height:"100%"},children:[g,W.jsx("canvas",{ref:e,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):g};function Aoo(g){const{dimensionStart:A,dimensionEnd:I,screenDimensionStart:e,screenDimensionEnd:t,flipX:o,flipY:B}=g,C=I.x-A.x,Q=I.y-A.y,i=Math.sqrt(C*C+Q*Q),E=t.x-e.x,n=t.y-e.y,s=Math.sqrt(E*E+n*n),r=Math.atan2(n,E)*(180/Math.PI),a=Math.abs(r)%90,h=Math.min(a,90-a)>15,l=(e.x+t.x)/2,D=(e.y+t.y)/2,d=15,y=r+90;let w=Math.cos(y*Math.PI/180)*d,u=Math.sin(y*Math.PI/180)*d;const G=E>0&&n<0,m=E>0&&n>0,p=E<0&&n>0;o!==B&&!G&&(w=-w,u=-u),G&&(w+=Math.cos(y*Math.PI/180)*-45,u+=Math.sin(y*Math.PI/180)*-45),m&&(w+=Math.cos(y*Math.PI/180)+-20,u+=Math.sin(y*Math.PI/180)+-10),p&&(w+=Math.cos(y*Math.PI/180)*10,u+=Math.sin(y*Math.PI/180)*10);const k=l+w,S=D+u;return{distance:i,screenDistance:s,x:k,y:S,show:i>.01&&s>30&&h}}function goo(g){const{dimensionStart:A,dimensionEnd:I,screenDimensionStart:e,screenDimensionEnd:t,flipX:o,flipY:B}=g;return gA.useMemo(()=>Aoo({dimensionStart:A,dimensionEnd:I,screenDimensionStart:e,screenDimensionEnd:t,flipX:o,flipY:B}),[A,I,e,t,o,B])}var Ioo=(g,A,I)=>{const e=I*Math.PI/180,t=Math.cos(e),o=Math.sin(e),B=g.x-A.x,C=g.y-A.y,Q=B*t-C*o,i=B*o+C*t;return{x:Q+A.x,y:i+A.y}},jSI=(g,A,I,e)=>{const t={top_left:{x:g.x-A,y:g.y-I},top_center:{x:g.x,y:g.y-I},top_right:{x:g.x+A,y:g.y-I},center_left:{x:g.x-A,y:g.y},center:{x:g.x,y:g.y},center_right:{x:g.x+A,y:g.y},bottom_left:{x:g.x-A,y:g.y+I},bottom_center:{x:g.x,y:g.y+I},bottom_right:{x:g.x+A,y:g.y+I}};return e===0?Object.entries(t).map(([o,B])=>({anchor:o,point:B})):Object.entries(t).map(([o,B])=>({anchor:o,point:Ioo(B,g,e)}))},eoo=g=>{switch(g.pcb_drawing_type){case"rect":{const A=g.ccw_rotation??0;return jSI({x:g.x,y:g.y},g.w/2,g.h/2,A)}case"pill":{const A=g.ccw_rotation??0;return jSI({x:g.x,y:g.y},g.w/2,g.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:g.x,y:g.y}},{anchor:"circle_right",point:{x:g.x+g.r,y:g.y}},{anchor:"circle_left",point:{x:g.x-g.r,y:g.y}},{anchor:"circle_top",point:{x:g.x,y:g.y-g.r}},{anchor:"circle_bottom",point:{x:g.x,y:g.y+g.r}}];case"oval":return[{anchor:"oval_center",point:{x:g.x,y:g.y}},{anchor:"oval_right",point:{x:g.x+g.rX,y:g.y}},{anchor:"oval_left",point:{x:g.x-g.rX,y:g.y}},{anchor:"oval_top",point:{x:g.x,y:g.y-g.rY}},{anchor:"oval_bottom",point:{x:g.x,y:g.y+g.rY}}];case"line":{const A={x:(g.x1+g.x2)/2,y:(g.y1+g.y2)/2};return[{anchor:"line_start",point:{x:g.x1,y:g.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:g.x2,y:g.y2}}]}case"polygon":return g.points.map((A,I)=>({anchor:`polygon_vertex_${I}`,point:A}));case"polygon_with_arcs":return g.brep_shape.outer_ring.vertices.map((A,I)=>({anchor:`polygon_with_arcs_vertex_${I}`,point:{x:A.x,y:A.y}}));default:return[]}},too=[];function zSI({snappingPoints:g,realToScreenTransform:A,isEnabled:I}){return I?g.map((e,t)=>({...e,id:`${t}-${e.anchor}`,screenPoint:Mt(A,e.point)})):too}var XSI=({screenPoint:{x:g,y:A}})=>`M${g-2.5},${A-2.5}l5,5m0,-5l-5,5`,ooo=gA.memo(function({points:A,startId:I,endId:e}){const{path:t,pointsById:o}=gA.useMemo(()=>({path:A.map(XSI).join(""),pointsById:new Map(A.map(C=>[C.id,C]))}),[A]),B=[...new Set([I,e])].flatMap(C=>{const Q=C===null?void 0:o.get(C);return Q?[XSI(Q)]:[]}).join("");return W.jsxs("svg",{"aria-hidden":"true",width:"100%",height:"100%",style:{position:"absolute",left:0,top:0,overflow:"visible",pointerEvents:"none",zIndex:Da.dimensionOverlay},fill:"none",strokeWidth:1,children:[W.jsx("path",{d:t,stroke:"white"}),W.jsx("path",{d:B,stroke:"#66ccff"})]})}),Boo=16,Coo=[],Qoo=aJ(),$SI=g=>{if(g.pcb_drawing_type==="text")return!0;const A=g._element;if(!A||typeof A!="object")return!1;const I=typeof A.type=="string"?A.type:void 0;return I?!!(I.startsWith("pcb_silkscreen_")||I.startsWith("pcb_note_")||I==="pcb_text"||I.startsWith("pcb_fabrication_note_")&&I!=="pcb_fabrication_note_rect"):!1},ioo=({children:g,transform:A,focusOnHover:I=!1,primitives:e=Coo,onBoundsSelected:t,cancelPanDrag:o})=>{A||(A=Qoo);const[B,C]=gA.useState(!1),[Q,i]=gA.useState(!1),[E,n]=gA.useState(!1),[s,r]=gA.useState(!1),[a,c]=gA.useState(!1),[h,l]=gA.useState(!1),[D,d]=gA.useState({start:null,end:null}),y=Qi(FA=>FA.is_mouse_over_container),w=gA.useCallback(()=>{E&&(n(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[E]),u=gA.useCallback(()=>{s&&(r(!1),window.dispatchEvent(new Event("disarm-bounds-tool")))},[s]),[G,m]=gA.useState({x:0,y:0}),[p,k]=gA.useState({x:0,y:0}),[S,R]=gA.useState({x:0,y:0}),[F,N]=gA.useState({x:0,y:0}),U=gA.useRef({x:0,y:0}),L=gA.useRef(!1),b=gA.useRef(null),q=b.current?.getBoundingClientRect(),j=gA.useMemo(()=>{const FA=new Map;for(const rA of e){if(!rA._element||$SI(rA)||rA.pcb_drawing_type==="pill"||rA.pcb_drawing_type==="rect"&&rA.ccw_rotation&&rA.ccw_rotation!==0)continue;const NA=iIg(rA);if(!NA)continue;const RA=FA.get(rA._element);FA.set(rA._element,reo(RA??void 0,NA))}return FA},[e]),Z=gA.useMemo(()=>{const FA=[];for(const rA of e){if(!rA._element||$SI(rA))continue;const NA=eoo(rA);if(NA.length!==0)for(const RA of NA)FA.push({anchor:RA.anchor,point:RA.point,element:rA._element})}return FA},[e]),O=gA.useMemo(()=>{const FA=[];j.forEach((rA,NA)=>{if(!rA)return;const RA=(rA.minX+rA.maxX)/2,UA=(rA.minY+rA.maxY)/2,bA={top_left:{x:rA.minX,y:rA.minY},top_center:{x:RA,y:rA.minY},top_right:{x:rA.maxX,y:rA.minY},center_left:{x:rA.minX,y:UA},center:{x:RA,y:UA},center_right:{x:rA.maxX,y:UA},bottom_left:{x:rA.minX,y:rA.maxY},bottom_center:{x:RA,y:rA.maxY},bottom_right:{x:rA.maxX,y:rA.maxY}};for(const[PA,kA]of Object.entries(bA))FA.push({anchor:PA,point:kA,element:NA})});for(const rA of Z)FA.push(rA);return FA.push({anchor:"origin",point:{x:0,y:0},element:null}),FA},[j,Z]),AA=gA.useMemo(()=>zSI({snappingPoints:O,realToScreenTransform:A,isEnabled:E||Q}),[O,A,E,Q]),tA=gA.useCallback(FA=>{let rA=AA;if(rA.length===0&&(rA=zSI({snappingPoints:O,realToScreenTransform:A,isEnabled:!0})),rA.length===0)return{point:FA,id:null};const NA=Mt(A,FA);let RA=null;for(const UA of rA){const bA=UA.screenPoint.x-NA.x,PA=UA.screenPoint.y-NA.y,kA=Math.hypot(bA,PA);kA>Boo||(!RA||kA<RA.distance)&&(RA={distance:kA,id:UA.id,point:UA.point})}return RA?{point:RA.point,id:RA.id}:{point:FA,id:null}},[O,AA,A]);gA.useEffect(()=>{const FA=RA=>{const UA=RA.target;if(UA.tagName==="INPUT"||UA.tagName==="TEXTAREA"||UA.isContentEditable)return;const bA=b.current?.contains(document.activeElement)||document.activeElement===b.current;if(!(!y&&!bA)){if(RA.key==="d"){const PA=tA({x:U.current.x,y:U.current.y});m({x:PA.point.x,y:PA.point.y}),k({x:PA.point.x,y:PA.point.y}),d({start:PA.id,end:PA.id}),B?(C(!1),i(!1),d({start:null,end:null})):(C(!0),i(!0)),w()}RA.key==="Escape"&&(C(!1),i(!1),d({start:null,end:null}),c(!1),l(!1),w(),u())}},rA=()=>{n(!0),r(!1),window.dispatchEvent(new Event("disarm-bounds-tool"))},NA=()=>{r(!0),n(!1),C(!1),i(!1),window.dispatchEvent(new Event("disarm-dimension-tool"))};return window.addEventListener("keydown",FA),window.addEventListener("arm-dimension-tool",rA),window.addEventListener("arm-bounds-tool",NA),()=>{window.removeEventListener("keydown",FA),window.removeEventListener("arm-dimension-tool",rA),window.removeEventListener("arm-bounds-tool",NA),w(),u()}},[y,B,w,u,tA]);const eA=Mt(A,G),QA=Mt(A,p),sA=Mt(A,S),DA=Mt(A,F),CA={minX:Math.min(S.x,F.x),minY:Math.min(S.y,F.y),maxX:Math.max(S.x,F.x),maxY:Math.max(S.y,F.y)},hA={left:Math.min(sA.x,DA.x),top:Math.min(sA.y,DA.y),width:Math.abs(sA.x-DA.x),height:Math.abs(sA.y-DA.y)},nA=gA.useCallback((FA,rA)=>{const NA={minX:Math.min(FA.x,rA.x),minY:Math.min(FA.y,rA.y),maxX:Math.max(FA.x,rA.x),maxY:Math.max(FA.y,rA.y)};t?.(NA),window.dispatchEvent(new CustomEvent("pcb-viewer:bounds-selected",{detail:NA}))},[t]),cA={left:Math.min(eA.x,QA.x),right:Math.max(eA.x,QA.x),top:Math.min(eA.y,QA.y),bottom:Math.max(eA.y,QA.y),flipX:eA.x>QA.x,flipY:eA.y>QA.y,width:0,height:0};cA.width=cA.right-cA.left,cA.height=cA.bottom-cA.top;const fA=goo({dimensionStart:G,dimensionEnd:p,screenDimensionStart:eA,screenDimensionEnd:QA,flipX:cA.flipX,flipY:cA.flipY});return W.jsxs("div",{ref:b,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseDownCapture:()=>{L.current=!1},onClickCapture:FA=>{L.current&&(L.current=!1,FA.stopPropagation(),b.current?.focus())},onContextMenuCapture:FA=>{!E&&!B&&!L.current||(FA.preventDefault(),FA.stopPropagation())},onMouseEnter:()=>{I&&b.current&&b.current.focus()},onMouseLeave:()=>{b.current&&b.current.blur()},onClick:()=>{b.current&&b.current.focus()},onMouseMove:FA=>{const rA=FA.currentTarget.getBoundingClientRect(),NA=FA.clientX-rA.left,RA=FA.clientY-rA.top,UA=Mt(Gx(A),{x:NA,y:RA});if(U.current.x=UA.x,U.current.y=UA.y,Q){const bA=tA(UA);k({x:bA.point.x,y:bA.point.y}),d(PA=>({...PA,end:bA.id}))}h&&(o?.(),N({x:UA.x,y:UA.y}))},onMouseDown:FA=>{L.current=E||B;const rA=FA.currentTarget.getBoundingClientRect(),NA=FA.clientX-rA.left,RA=FA.clientY-rA.top,UA=Mt(Gx(A),{x:NA,y:RA});if(s)FA.preventDefault(),FA.stopPropagation(),o?.(),R({x:UA.x,y:UA.y}),N({x:UA.x,y:UA.y}),c(!0),l(!0),u();else if(E&&!B){const bA=tA(UA);m({x:bA.point.x,y:bA.point.y}),k({x:bA.point.x,y:bA.point.y}),d({start:bA.id,end:bA.id}),C(!0),i(!0),w()}else Q?(i(!1),d(bA=>({...bA,end:null}))):B&&(C(!1),d({start:null,end:null}))},onMouseUp:FA=>{if(!h)return;const rA=FA.currentTarget.getBoundingClientRect(),NA=FA.clientX-rA.left,RA=FA.clientY-rA.top,UA=Mt(Gx(A),{x:NA,y:RA}),bA={x:UA.x,y:UA.y};FA.preventDefault(),FA.stopPropagation(),o?.(),N(bA),l(!1),nA(S,bA)},children:[g,a&&W.jsxs(W.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.dimensionOverlay},width:q.width,height:q.height,children:W.jsx("rect",{x:hA.left,y:hA.top,width:hA.width,height:hA.height,stroke:"red",strokeWidth:1.5,strokeDasharray:"4,3",fill:"rgba(255, 0, 0, 0.12)"})}),W.jsxs("div",{style:{left:0,bottom:B?58:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.dimensionOverlay},children:["minX: ",CA.minX.toFixed(2),", minY:"," ",CA.minY.toFixed(2),W.jsx("br",{}),"maxX: ",CA.maxX.toFixed(2),", maxY:"," ",CA.maxY.toFixed(2)]})]}),B&&W.jsxs(W.Fragment,{children:[fA.show&&W.jsx("div",{style:{position:"absolute",left:fA.x,top:fA.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Da.dimensionOverlay},children:fA.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:cA.left,width:cA.width,textAlign:"center",top:eA.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:cA.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Da.dimensionOverlay},children:Math.abs(G.x-p.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:QA.x,height:cA.height,display:"flex",flexDirection:"column",justifyContent:"center",top:cA.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Da.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:cA.flipX?"-100%":4,paddingRight:4},children:Math.abs(G.y-p.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.dimensionOverlay},width:q.width,height:q.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:eA.x,y1:eA.y,x2:QA.x,y2:QA.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:eA.x,y1:eA.y,x2:QA.x,y2:eA.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:QA.x,y1:eA.y,x2:QA.x,y2:QA.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),Q&&W.jsx(ooo,{points:AA,startId:D.start,endId:D.end}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",G.x.toFixed(2),",",G.y.toFixed(2),")",W.jsx("br",{}),"(",p.x.toFixed(2),",",p.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((p.x-G.x)**2+(p.y-G.y)**2).toFixed(2)]})]})]})},Eoo=(g,A,I=0)=>{const e=g.width/2,t=g.height/2,o=g.center.x-e-I,B=g.center.x+e+I,C=g.center.y-t-I,Q=g.center.y+t+I;return A.x>o&&A.x<B&&A.y>C&&A.y<Q},noo=({children:g,disabled:A,transform:I,soup:e,cancelPanDrag:t,onCreateEditEvent:o,onModifyEditEvent:B})=>{I||(I=aJ());const C=gA.useRef(null),[Q,i]=gA.useState(null),[E,n]=gA.useState(null),s=Q!==null;Qi(h=>h.in_edit_mode);const r=Qi(h=>h.in_move_footprint_mode),a=Qi(h=>h.setIsMovingComponent),c=A||!r;return W.jsxs("div",{ref:C,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(c)return;const l=h.currentTarget.getBoundingClientRect(),D=h.clientX-l.left,d=h.clientY-l.top;if(Number.isNaN(D)||Number.isNaN(d))return;const y=Mt(Gx(I),{x:D,y:d});let w=!1;for(const u of e)if(u.type==="pcb_component"&&Eoo(u,y,10/I.a)){t(),i(u.pcb_component_id),w=!0;const G=Math.random().toString();n({dragStart:y,originalCenter:u.center,dragEnd:y,edit_event_id:G}),o({edit_event_id:G,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:u.pcb_component_id,original_center:u.center,new_center:u.center,in_progress:!0,created_at:Date.now()}),a(!0);break}if(w||i(null),w)return h.preventDefault(),!1},onMouseMove:h=>{if(!Q||!E)return;const l=h.currentTarget.getBoundingClientRect(),D=h.clientX-l.left,d=h.clientY-l.top;if(Number.isNaN(D)||Number.isNaN(d))return;const y=Mt(Gx(I),{x:D,y:d});n({...E,dragEnd:y}),B({edit_event_id:E.edit_event_id,new_center:{x:E.originalCenter.x+y.x-E.dragStart.x,y:E.originalCenter.y+y.y-E.dragStart.y}})},onMouseUp:h=>{Q&&(i(null),a(!1),E&&(B({edit_event_id:E.edit_event_id,in_progress:!1}),n(null)))},children:[g,!c&&e.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const l=Mt(I,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:l.x,top:l.y,width:h.width*I.a+20,height:h.height*I.a+20,transform:"translate(-50%, -50%)",background:s&&Q===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},sIg=(g,A)=>{const I=A.current;if(!I)return{transform:"translate(-50%, -100%)",left:g.x,top:g.y};const e=I.getBoundingClientRect(),t=200,o=10,B=60;let C="-50%",Q="-100%",i=g.x,E=g.y;return g.x+B+t<e.width-o?(i=g.x+B,C="0%"):g.x-B-t>o?(i=g.x-B,C="-100%"):(i=g.x,C="-50%"),{transform:`translate(${C}, ${Q})`,left:i,top:E}},soo=({center:g})=>W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.errorOverlay+30},width:"100%",height:"100%",children:[W.jsx("circle",{cx:g.x,cy:g.y,r:11,fill:"none",stroke:"#ff6b6b",strokeWidth:2.5,opacity:.95}),W.jsx("circle",{cx:g.x,cy:g.y,r:4.5,fill:"#ff6b6b",opacity:.95}),W.jsx("line",{x1:g.x-18,y1:g.y,x2:g.x-8,y2:g.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:g.x+8,y1:g.y,x2:g.x+18,y2:g.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:g.x,y1:g.y-18,x2:g.x,y2:g.y-8,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:g.x,y1:g.y+8,x2:g.x,y2:g.y+18,stroke:"#ff6b6b",strokeWidth:2})]}),A2I=({errorCenter:g,isHighlighted:A=!1})=>W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.errorOverlay},width:"100%",height:"100%",children:W.jsx("rect",{x:g.x-7,y:g.y-7,width:14,height:14,transform:`rotate(45 ${g.x} ${g.y})`,fill:A?"#ff4444":"transparent",stroke:A?"#ff4444":"red",strokeWidth:A?2.5:1.5})}),aIg=F7`
5419
+ `)?.every(A=>A.includes("LINESTRING"))}function hIo(g){return g.startsWith("POINT")||ZMI(g)||g.startsWith("LINESTRING")||OMI(g)||g.startsWith("MULTILINESTRING")||g.startsWith("POLYGON")||g.startsWith("MULTIPOINT")||g.startsWith("MULTIPOLYGON")||g.startsWith("GEOMETRYCOLLECTION")}jA.isWktString=hIo,jA.parseWKT=TMI,jA.BooleanOperations=wgo,jA.Relations=Jgo;function WMI(g,A,I){if(!A||!I)return;let e=g.get(A);e||(e=new Set,g.set(A,e)),e.add(I);let t=g.get(I);t||(t=new Set,g.set(I,t)),t.add(A)}function VMI(g,A){if(!A.subcircuit_id&&!A.source_group_id)return[...g];let I=A;if(A.subcircuit_id){const C=new Set([A.subcircuit_id]),Q=new Map,i=new Map;for(const n of g)if(n.type==="source_group"){const s=n.source_group_id,r=n.subcircuit_id;r&&i.set(s,r);const a=n.parent_source_group_id;a&&(Q.has(a)||Q.set(a,[]),Q.get(a).push(s))}let E;for(const[n,s]of i)if(s===A.subcircuit_id){E=n;break}if(E){const n=s=>{const r=Q.get(s)||[];for(const a of r){const c=i.get(a);c&&C.add(c),n(a)}};n(E),I={...A,subcircuit_ids:Array.from(C)}}}const e=new Map;for(const C of g){const Q=`${C.type}_id`,i=C[Q];typeof i=="string"&&e.set(i,C)}const t=new Map;for(const C of g){const Q=Object.entries(C);for(const[i,E]of Q)if(i!=="parent_source_group_id"){if(i.endsWith("_id")&&typeof E=="string"){const n=e.get(E);WMI(t,C,n)}else if(i.endsWith("_ids")&&Array.isArray(E)){for(const n of E)if(typeof n=="string"){const s=e.get(n);WMI(t,C,s)}}}}const o=[],B=new Set;for(const C of g){let Q=!1;(I.subcircuit_id&&"subcircuit_id"in C&&C.subcircuit_id===I.subcircuit_id||I.subcircuit_ids&&"subcircuit_id"in C&&C.subcircuit_id&&I.subcircuit_ids.includes(C.subcircuit_id)||I.source_group_id&&"source_group_id"in C&&C.source_group_id===I.source_group_id||I.source_group_id&&"member_source_group_ids"in C&&Array.isArray(C.member_source_group_ids)&&C.member_source_group_ids.includes(I.source_group_id))&&(Q=!0),Q&&(o.push(C),B.add(C))}for(;o.length>0;){const C=o.shift(),Q=t.get(C);if(Q)for(const i of Q)B.has(i)||(B.add(i),o.push(i))}return g.filter(C=>B.has(C))}var CwA=(g,A={})=>{const I=g;let e=I._internal_store;if(!e){e={counts:{},editCount:0},I._internal_store=e;for(const o of I){const B=o.type,C=o[`${B}_id`];if(!C)continue;const Q=Number.parseInt(C.split("_").pop());Number.isNaN(Q)||(e.counts[B]=Math.max(e.counts[B]??0,Q))}}const t=new Proxy({},{get:(o,B)=>{if(B==="toArray")return()=>(I.editCount=e.editCount,I);if(B==="editCount")return e.editCount;if(B==="subtree")return Q=>CwA(VMI(I,Q),A);if(B==="insert")return Q=>{const i=Q.type;if(!i)throw new Error("insert requires an element with a type");e.counts[i]??=-1,e.counts[i]++;const E=e.counts[i],n={...Q,type:i,[`${i}_id`]:`${i}_${E}`};return A.validateInserts&&(uN[i]??wf).parse(n),I.push(n),e.editCount++,n};if(B==="insertAll")return Q=>Q.map(i=>t.insert(i));const C=B;return{get:Q=>I.find(i=>i.type===C&&i[`${C}_id`]===Q),getUsing:Q=>{const i=Object.keys(Q);if(i.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const E=i[0],n=E.replace("_id",""),s=I.find(r=>r.type===n&&r[E]===Q[E]);return s?I.find(r=>r.type===C&&r[`${C}_id`]===s[`${C}_id`]):null},getWhere:Q=>{const i=Object.keys(Q);return I.find(E=>E.type===C&&i.every(n=>E[n]===Q[n]))},list:Q=>{const i=Q?Object.keys(Q):[];return I.filter(E=>E.type===C&&i.every(n=>E[n]===Q[n]))},insert:Q=>{e.counts[C]??=-1,e.counts[C]++;const i=e.counts[C],E={type:C,[`${C}_id`]:`${C}_${i}`,...Q};return A.validateInserts&&(uN[C]??wf).parse(E),I.push(E),e.editCount++,E},delete:Q=>{const i=I.find(E=>E[`${C}_id`]===Q);i&&(I.splice(I.indexOf(i),1),e.editCount++)},update:(Q,i)=>{const E=I.find(n=>n.type===C&&n[`${C}_id`]===Q);return E?(Object.assign(E,i),e.editCount++,E):null},select:Q=>{if(C==="source_component")return I.find(i=>i.type==="source_component"&&i.name===Q.replace(/\./g,""));if(C==="pcb_port"||C==="source_port"||C==="schematic_port"){const[i,E]=Q.replace(/\./g,"").split(/[\s\>]+/),n=I.find(r=>r.type==="source_component"&&r.name===i);if(!n)return null;const s=I.find(r=>r.type==="source_port"&&r.source_component_id===n.source_component_id&&(r.name===E||(r.port_hints??[]).includes(E)));if(!s)return null;if(C==="source_port")return s;if(C==="pcb_port")return I.find(r=>r.type==="pcb_port"&&r.source_port_id===s.source_port_id);if(C==="schematic_port")return I.find(r=>r.type==="schematic_port"&&r.source_port_id===s.source_port_id)}}}}});return t};CwA.unparsed=CwA;var p5=CwA;function eIg(g){const A=g.type;return`${A}:${g[`${A}_id`]}`}var tIg=(g,A={})=>{let I=g._internal_store_indexed;if(!I){I={counts:{},editCount:0,indexes:{}};for(const B of g){const C=B.type,Q=B[`${C}_id`];if(!Q)continue;const i=Number.parseInt(Q.split("_").pop()||"");Number.isNaN(i)||(I.counts[C]=Math.max(I.counts[C]??0,i))}const t=A.indexConfig||{},o=I.indexes;if(t.byId&&(o.byId=new Map),t.byType&&(o.byType=new Map),t.byRelation&&(o.byRelation=new Map),t.bySubcircuit&&(o.bySubcircuit=new Map),t.byCustomField&&t.byCustomField.length>0){o.byCustomField=new Map;for(const B of t.byCustomField)o.byCustomField.set(B,new Map)}for(const B of g){if(t.byId){const C=eIg(B);o.byId.set(C,B)}if(t.byType){const C=o.byType.get(B.type)||[];C.push(B),o.byType.set(B.type,C)}if(t.byRelation){const C=Object.entries(B);for(const[Q,i]of C)if(Q.endsWith("_id")&&Q!==`${B.type}_id`&&typeof i=="string"){const E=o.byRelation.get(Q)||new Map,n=E.get(i)||[];n.push(B),E.set(i,n),o.byRelation.set(Q,E)}}if(t.bySubcircuit&&"subcircuit_id"in B){const C=B.subcircuit_id;if(C&&typeof C=="string"){const Q=o.bySubcircuit.get(C)||[];Q.push(B),o.bySubcircuit.set(C,Q)}}if(t.byCustomField&&o.byCustomField){for(const C of t.byCustomField)if(C in B){const Q=B[C];if(Q!==void 0&&(typeof Q=="string"||typeof Q=="number")){const i=String(Q),E=o.byCustomField.get(C),n=E.get(i)||[];n.push(B),E.set(i,n)}}}}g._internal_store_indexed=I}const e=new Proxy({},{get:(t,o)=>{if(o==="toArray")return()=>(g.editCount=I.editCount,g);if(o==="editCount")return I.editCount;if(o==="insert")return C=>{const{type:Q,...i}=C;if(!Q)throw new Error("insert requires an element with a type");return delete i[`${Q}_id`],e[Q].insert(i)};if(o==="insertAll")return C=>C.map(Q=>e.insert(Q));if(o==="subtree")return C=>tIg(VMI(g,C),A);const B=o;return{get:C=>{const Q=A.indexConfig||{};return Q.byId&&I.indexes.byId?I.indexes.byId.get(`${B}:${C}`)||null:Q.byType&&I.indexes.byType?(I.indexes.byType.get(B)||[]).find(E=>E[`${B}_id`]===C)||null:g.find(i=>i.type===B&&i[`${B}_id`]===C)||null},getUsing:C=>{const Q=A.indexConfig||{},i=Object.keys(C);if(i.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const E=i[0],n=E.replace("_id","");if(Q.byRelation&&I.indexes.byRelation){const r=I.indexes.byRelation.get(E);if(r){const c=(r.get(C[E])||[]).find(l=>l.type===n);if(!c)return null;const h=c[`${B}_id`];return Q.byId&&I.indexes.byId?I.indexes.byId.get(`${B}:${h}`)||null:Q.byType&&I.indexes.byType?(I.indexes.byType.get(B)||[]).find(D=>D[`${B}_id`]===h)||null:g.find(l=>l.type===B&&l[`${B}_id`]===h)||null}}const s=g.find(r=>r.type===n&&r[E]===C[E]);return s&&g.find(r=>r.type===B&&r[`${B}_id`]===s[`${B}_id`])||null},getWhere:C=>{const Q=A.indexConfig||{},i=Object.keys(C);if(i.length===1&&Q.byCustomField&&I.indexes.byCustomField){const E=i[0],n=I.indexes.byCustomField.get(E);if(n){const s=String(C[E]);return(n.get(s)||[]).find(a=>a.type===B)||null}}if("subcircuit_id"in C&&Q.bySubcircuit&&I.indexes.bySubcircuit){const E=C.subcircuit_id;return(I.indexes.bySubcircuit.get(E)||[]).find(s=>s.type===B&&i.every(r=>s[r]===C[r]))||null}return Q.byType&&I.indexes.byType?(I.indexes.byType.get(B)||[]).find(n=>i.every(s=>n[s]===C[s]))||null:g.find(E=>E.type===B&&i.every(n=>E[n]===C[n]))||null},list:C=>{const Q=A.indexConfig||{},i=C?Object.keys(C):[];if(i.length===0&&Q.byType&&I.indexes.byType)return(I.indexes.byType.get(B)||[]).slice();if(i.length===1&&i[0]==="subcircuit_id"&&Q.bySubcircuit&&I.indexes.bySubcircuit){const n=C.subcircuit_id;return(I.indexes.bySubcircuit.get(n)||[]).filter(r=>r.type===B)}let E;return Q.byType&&I.indexes.byType?E=I.indexes.byType.get(B)||[]:E=g.filter(n=>n.type===B),i.length>0?E.filter(n=>i.every(s=>n[s]===C[s])):E.slice()},insert:C=>{I.counts[B]??=-1,I.counts[B]++;const Q=I.counts[B],i={type:B,[`${B}_id`]:`${B}_${Q}`,...C};A.validateInserts&&(uN[B]??wf).parse(i),g.push(i),I.editCount++;const E=A.indexConfig||{};if(E.byId&&I.indexes.byId){const n=eIg(i);I.indexes.byId.set(n,i)}if(E.byType&&I.indexes.byType){const n=I.indexes.byType.get(B)||[];n.push(i),I.indexes.byType.set(B,n)}if(E.byRelation&&I.indexes.byRelation){const n=Object.entries(i);for(const[s,r]of n)if(s.endsWith("_id")&&s!==`${i.type}_id`&&typeof r=="string"){const a=I.indexes.byRelation.get(s)||new Map,c=a.get(r)||[];c.push(i),a.set(r,c),I.indexes.byRelation.set(s,a)}}if(E.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in i){const n=i.subcircuit_id;if(n&&typeof n=="string"){const s=I.indexes.bySubcircuit.get(n)||[];s.push(i),I.indexes.bySubcircuit.set(n,s)}}if(E.byCustomField&&I.indexes.byCustomField){for(const n of E.byCustomField)if(n in i){const s=i[n];if(s!==void 0&&(typeof s=="string"||typeof s=="number")){const r=String(s),a=I.indexes.byCustomField.get(n),c=a.get(r)||[];c.push(i),a.set(r,c)}}}return i},delete:C=>{const Q=A.indexConfig||{};let i;if(Q.byId&&I.indexes.byId?i=I.indexes.byId.get(`${B}:${C}`):Q.byType&&I.indexes.byType?i=(I.indexes.byType.get(B)||[]).find(s=>s[`${B}_id`]===C):i=g.find(n=>n[`${B}_id`]===C),!i)return;const E=g.indexOf(i);if(E>=0&&(g.splice(E,1),I.editCount++),Q.byId&&I.indexes.byId){const n=eIg(i);I.indexes.byId.delete(n)}if(Q.byType&&I.indexes.byType){const s=(I.indexes.byType.get(B)||[]).filter(r=>r[`${B}_id`]!==C);I.indexes.byType.set(B,s)}if(Q.byRelation&&I.indexes.byRelation)for(const[n,s]of I.indexes.byRelation.entries())for(const[r,a]of s.entries()){const c=a.filter(h=>h!==i);c.length===0?s.delete(r):s.set(r,c)}if(Q.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in i){const n=i.subcircuit_id;if(n){const r=(I.indexes.bySubcircuit.get(n)||[]).filter(a=>a!==i);r.length===0?I.indexes.bySubcircuit.delete(n):I.indexes.bySubcircuit.set(n,r)}}if(Q.byCustomField&&I.indexes.byCustomField)for(const n of I.indexes.byCustomField.values())for(const[s,r]of n.entries()){const a=r.filter(c=>c!==i);a.length===0?n.delete(s):n.set(s,a)}},update:(C,Q)=>{const i=A.indexConfig||{};let E;if(i.byId&&I.indexes.byId?E=I.indexes.byId.get(`${B}:${C}`):i.byType&&I.indexes.byType?E=(I.indexes.byType.get(B)||[]).find(s=>s[`${B}_id`]===C):E=g.find(n=>n.type===B&&n[`${B}_id`]===C),!E)return null;if(i.byRelation&&I.indexes.byRelation){const n=Object.entries(E);for(const[s,r]of n)if(s.endsWith("_id")&&s!==`${E.type}_id`&&typeof r=="string"&&s in Q&&Q[s]!==r){const a=I.indexes.byRelation.get(s);if(a){const h=(a.get(r)||[]).filter(l=>l!==E);h.length===0?a.delete(r):a.set(r,h)}}}if(i.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in E&&"subcircuit_id"in Q){const n=E.subcircuit_id,s=Q.subcircuit_id;if(n!==s){const a=(I.indexes.bySubcircuit.get(n)||[]).filter(c=>c!==E);a.length===0?I.indexes.bySubcircuit.delete(n):I.indexes.bySubcircuit.set(n,a)}}if(i.byCustomField&&I.indexes.byCustomField){for(const n of i.byCustomField)if(n in E&&n in Q&&E[n]!==Q[n]){const s=I.indexes.byCustomField.get(n);if(s){const r=String(E[n]),c=(s.get(r)||[]).filter(h=>h!==E);c.length===0?s.delete(r):s.set(r,c)}}}if(Object.assign(E,Q),I.editCount++,i.byRelation&&I.indexes.byRelation){const n=Object.entries(E);for(const[s,r]of n)if(s.endsWith("_id")&&s!==`${E.type}_id`&&typeof r=="string"&&s in Q){const a=I.indexes.byRelation.get(s)||new Map,c=a.get(r)||[];c.includes(E)||(c.push(E),a.set(r,c),I.indexes.byRelation.set(s,a))}}if(i.bySubcircuit&&I.indexes.bySubcircuit&&"subcircuit_id"in E&&"subcircuit_id"in Q){const n=E.subcircuit_id;if(n&&typeof n=="string"){const s=I.indexes.bySubcircuit.get(n)||[];s.includes(E)||(s.push(E),I.indexes.bySubcircuit.set(n,s))}}if(i.byCustomField&&I.indexes.byCustomField){for(const n of i.byCustomField)if(n in E&&n in Q){const s=E[n];if(s!==void 0&&(typeof s=="string"||typeof s=="number")){const r=String(s),a=I.indexes.byCustomField.get(n),c=a.get(r)||[];c.includes(E)||(c.push(E),a.set(r,c))}}}return E},select:C=>{if(B==="source_component")return g.find(Q=>Q.type==="source_component"&&Q.name===C.replace(/\./g,""))||null;if(B==="pcb_port"||B==="source_port"||B==="schematic_port"){const[Q,i]=C.replace(/\./g,"").split(/[\s\>]+/),E=g.find(s=>s.type==="source_component"&&s.name===Q);if(!E)return null;const n=g.find(s=>s.type==="source_port"&&s.source_component_id===E.source_component_id&&(s.name===i||(s.port_hints??[]).includes(i)));if(!n)return null;if(B==="source_port")return n;if(B==="pcb_port")return g.find(s=>s.type==="pcb_port"&&s.source_port_id===n.source_port_id)||null;if(B==="schematic_port")return g.find(s=>s.type==="schematic_port"&&s.source_port_id===n.source_port_id)||null}return null}}}});return e};tIg.unparsed=tIg;var lIo=g=>Math.round(g/(Math.PI/2)),DIo=g=>{switch(g){case"from_left":return{x:-1,y:0};case"from_right":return{x:1,y:0};case"from_top":return{x:0,y:1};case"from_bottom":return{x:0,y:-1}}},dIo=({x:g,y:A})=>g>0?"from_right":g<0?"from_left":A>0?"from_top":"from_bottom",yIo=(g,A)=>{if(!g)return g;if(g==="from_above"||g==="from_below")return A.isFlipped?g==="from_above"?"from_below":"from_above":g;let{x:I,y:e}=DIo(g),t=Math.round(A.rotationDegrees/90);for(;t>0;)[I,e]=[-e,I],t--;for(;t<0;)[I,e]=[e,-I],t++;return A.isFlipped&&(e=-e),dIo({x:I,y:e})},wIo=(g,A)=>{if(g.shape==="polygon")return g.points=g.points.map(B=>Mt(A,B)),g;const I=Mt(A,{x:g.x,y:g.y});if(g.x=I.x,g.y=I.y,g.shape==="circle")return g;const e=g.shape==="rotated_rect"?g.ccw_rotation:0,t=A.a*A.d-A.b*A.c<0,o=tkI(Yw(A,B$t(e)),!1,t).rotation.angle*180/Math.PI;return Math.abs(o)<1e-8?(Object.assign(g,{shape:"rect"}),Reflect.deleteProperty(g,"ccw_rotation")):Object.assign(g,{shape:"rotated_rect",ccw_rotation:o}),g},uIo=(g,A)=>{if(g.type==="pcb_soldermask_opening")return wIo(g,A);if((g.type==="pcb_smtpad"||g.type==="pcb_solder_paste")&&g.shape==="polygon")return g.points=g.points.map(B=>Mt(A,B)),g.type==="pcb_solder_paste"&&g.holes&&(g.holes=g.holes.map(B=>B.map(C=>Mt(A,C)))),g;const I=tkI(A),e=Math.abs(lIo(I.rotation.angle))%2===1,t=I.rotation.angle/Math.PI*180,o=I.scale.sy<0;if(g.type==="pcb_plated_hole"||g.type==="pcb_hole"||g.type==="pcb_via"||g.type==="pcb_smtpad"||g.type==="pcb_solder_paste"||g.type==="pcb_port"){const{x:B,y:C}=Mt(A,{x:g.x,y:g.y});g.x=B,g.y=C}else if(g.type==="pcb_keepout"&&g.shape==="outline")g.outline=g.outline.map(B=>Mt(A,B));else if(g.type==="pcb_keepout"||g.type==="pcb_board")g.center=Mt(A,g.center);else if(g.type==="pcb_silkscreen_text"||g.type==="pcb_fabrication_note_text"||g.type==="pcb_note_text")g.anchor_position=Mt(A,g.anchor_position);else if(g.type==="pcb_copper_text")g.anchor_position&&(g.anchor_position=Mt(A,g.anchor_position));else if(g.type==="pcb_courtyard_rect")g.center=Mt(A,g.center),g.ccw_rotation=((g.ccw_rotation??0)+t)%360;else if(g.type==="pcb_silkscreen_circle"||g.type==="pcb_silkscreen_rect"||g.type==="pcb_silkscreen_pill"||g.type==="pcb_silkscreen_oval"||g.type==="pcb_note_rect"||g.type==="pcb_courtyard_circle")g.center=Mt(A,g.center);else if(g.type==="pcb_component")g.center=Mt(A,g.center),g.rotation=g.rotation+t,g.rotation=g.rotation%360,g.cable_insertion_center&&(g.cable_insertion_center=Mt(A,g.cable_insertion_center)),g.insertion_direction=yIo(g.insertion_direction,{rotationDegrees:t,isFlipped:o}),e&&([g.width,g.height]=[g.height,g.width]);else if(g.type==="pcb_courtyard_outline")g.outline=g.outline.map(B=>{const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_courtyard_polygon")g.points=g.points.map(B=>{const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_trace")g.route=g.route.map(B=>{if(!("x"in B))return B.start=Mt(A,B.start),B.end=Mt(A,B.end),B;const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_silkscreen_path"||g.type==="pcb_trace_hint"||g.type==="pcb_fabrication_note_path"||g.type==="pcb_note_path")g.route=g.route.map(B=>{const C=Mt(A,B);return B.x=C.x,B.y=C.y,B});else if(g.type==="pcb_silkscreen_line"||g.type==="pcb_note_line"){const B={x:g.x1,y:g.y1},C={x:g.x2,y:g.y2},Q=Mt(A,B),i=Mt(A,C);g.x1=Q.x,g.y1=Q.y,g.x2=i.x,g.y2=i.y}else if(g.type==="cad_component"){const B=Mt(A,{x:g.position.x,y:g.position.y});g.position.x=B.x,g.position.y=B.y}return g},GIo=g=>{const A=g.type;return g[`${A}_id`]},oIg=(g,A)=>({minX:Math.min(g.minX,A.minX),minY:Math.min(g.minY,A.minY),maxX:Math.max(g.maxX,A.maxX),maxY:Math.max(g.maxY,A.maxY)}),bIA=(g,A,I)=>{const e=I/2;return{minX:g-e,minY:A-e,maxX:g+e,maxY:A+e}},jMI=(g,A,I,e,t)=>{const o=I/2,B=e/2,C=t*Math.PI/180,Q=Math.cos(C),i=Math.sin(C),E=[{x:-o,y:-B},{x:o,y:-B},{x:o,y:B},{x:-o,y:B}].map(n=>({x:g+n.x*Q-n.y*i,y:A+n.x*i+n.y*Q}));return{minX:Math.min(...E.map(n=>n.x)),minY:Math.min(...E.map(n=>n.y)),maxX:Math.max(...E.map(n=>n.x)),maxY:Math.max(...E.map(n=>n.y))}},mIo=(g,A,I,e,t)=>{const o=I/2,B=e/2,C=t*Math.PI/180,Q=Math.cos(C),i=Math.sin(C),E=Math.hypot(o*Q,B*i),n=Math.hypot(o*i,B*Q);return{minX:g-E,minY:A-n,maxX:g+E,maxY:A+n}},pIo=(g,A,I,e,t)=>{const o=Math.min(I,e)/2,B=Math.max(I,e)/2-o,C=t*Math.PI/180,Q=I>=e?{x:B,y:0}:{x:0,y:B},i={x:Q.x*Math.cos(C)-Q.y*Math.sin(C),y:Q.x*Math.sin(C)+Q.y*Math.cos(C)},E=Math.abs(i.x)+o,n=Math.abs(i.y)+o;return{minX:g-E,minY:A-n,maxX:g+E,maxY:A+n}},QwA=g=>g.length===0?null:{minX:Math.min(...g.map(A=>A.x)),minY:Math.min(...g.map(A=>A.y)),maxX:Math.max(...g.map(A=>A.x)),maxY:Math.max(...g.map(A=>A.y))},BIg=g=>Array.isArray(g)?g.flatMap(A=>!A||typeof A!="object"?[]:"x"in A&&"y"in A&&typeof A.x=="number"&&typeof A.y=="number"?[{x:A.x,y:A.y}]:"start"in A&&"end"in A?[A.start,A.end].filter(e=>!!(e&&typeof e=="object"&&"x"in e&&"y"in e&&typeof e.x=="number"&&typeof e.y=="number")):[]):[],zMI=g=>{if(!g.type.startsWith("pcb_"))return null;if(g.type==="pcb_smtpad"&&g.shape==="polygon"&&Array.isArray(g.points))return QwA(g.points);if(g.type==="pcb_hole"&&g.hole_shape==="circle")return bIA(g.x,g.y,g.hole_diameter);if(g.type==="pcb_plated_hole"){let n;if("outer_diameter"in g&&typeof g.outer_diameter=="number"?n=bIA(g.x,g.y,g.outer_diameter):"hole_diameter"in g&&typeof g.hole_diameter=="number"&&(n=bIA(g.x,g.y,g.hole_diameter)),(g.shape==="oval"||g.shape==="pill")&&typeof g.outer_width=="number"&&typeof g.outer_height=="number"&&(n=(g.shape==="pill"?pIo:mIo)(g.x,g.y,g.outer_width,g.outer_height,g.ccw_rotation??0)),"rect_pad_width"in g&&typeof g.rect_pad_width=="number"&&"rect_pad_height"in g&&typeof g.rect_pad_height=="number"){const s=jMI(g.x,g.y,g.rect_pad_width,g.rect_pad_height,"rect_ccw_rotation"in g?g.rect_ccw_rotation??0:0);n=n?oIg(n,s):s}if("hole_diameter"in g&&typeof g.hole_diameter=="number"){const s=bIA(g.x+("hole_offset_x"in g?g.hole_offset_x??0:0),g.y+("hole_offset_y"in g?g.hole_offset_y??0:0),g.hole_diameter);n=n?oIg(n,s):s}if(n)return n}const A=g,I=QwA(BIg(A.route));if(I)return I;const e=QwA(BIg(A.outline));if(e)return e;const t=QwA(BIg(A.points));if(t)return t;let o,B,C,Q;"x"in g&&"y"in g&&(o=Number(g.x),B=Number(g.y)),"outer_diameter"in g&&(C=Number(g.outer_diameter),Q=Number(g.outer_diameter)),"width"in g&&(C=Number(g.width)),"height"in g&&(Q=Number(g.height)),"center"in g&&g.center&&typeof g.center=="object"&&"x"in g.center&&"y"in g.center&&(o=Number(g.center.x),B=Number(g.center.y));let i=0;if("rotation"in g&&typeof g.rotation=="number"&&(i=g.rotation),"ccw_rotation"in g&&typeof g.ccw_rotation=="number"&&(i=g.ccw_rotation),o!==void 0&&B!==void 0)return C!==void 0&&Q!==void 0?i?jMI(o,B,C,Q,i):{minX:o-C/2,minY:B-Q/2,maxX:o+C/2,maxY:B+Q/2}:"radius"in g&&typeof g.radius=="number"?bIA(o,B,g.radius*2):{minX:o,minY:B,maxX:o,maxY:B};const E=[A.anchor_position,A.position].filter(n=>!!(n&&typeof n=="object"&&"x"in n&&"y"in n&&typeof n.x=="number"&&typeof n.y=="number")).at(0);return E?{minX:E.x,minY:E.y,maxX:E.x,maxY:E.y}:null},CIg=g=>{let A={minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY};for(const I of g){const e=zMI(I);e&&(A=oIg(A,e))}return A};function kIo(g){let A=0;if(g.length==0)return A;for(var I=0;I<g.length;I++){var e=g.charCodeAt(I);A=(A<<5)-A+e,A=A&A}return Math.abs(A)}var XMI=[["#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"]],MIo=g=>{let{x:A,y:I,width:e,height:t}={...g,...g.size,...g.center,...g.position};if(g.x1!==void 0&&g.x2!==void 0&&g.y1!==void 0&&g.y2!==void 0&&(A=(g.x1+g.x2)/2,I=(g.y1+g.y2)/2,e=Math.abs(g.x1-g.x2),t=Math.abs(g.y1-g.y2)),g.points&&Array.isArray(g.points)&&g.points.length>0){const C=g.points.map(r=>r.x),Q=g.points.map(r=>r.y),i=Math.min(...C),E=Math.max(...C),n=Math.min(...Q),s=Math.max(...Q);A=(i+E)/2,I=(n+s)/2,e=E-i,t=s-n}const o=g.text||g.name||g.source?.text||g.source?.name||"?",B=g;return A===void 0||I===void 0?null:(e===void 0&&("radius"in g?(e=g.radius*2,t=g.radius*2):"outer_diameter"in g?(e=g.outer_diameter,t=g.outer_diameter):"rect_pad_width"in g&&"rect_pad_height"in g?(e=g.rect_pad_width,t=g.rect_pad_height,"hole_diameter"in g&&(e=Math.max(e,g.hole_diameter),t=Math.max(t,g.hole_diameter))):"hole_diameter"in g&&(e=g.hole_diameter,t=g.hole_diameter)),(e===void 0||t===void 0)&&(e=.1,t=.1),{x:A,y:I,width:e,height:t,title:o,content:B,bg_color:XMI[kIo(g.type||o)%XMI.length]?.[4]??"#f00"})},SIo=g=>!!g,fIo=g=>{const A=g.filter(i=>i.type.startsWith("pcb_")||i.type.startsWith("schematic_")).concat(g.filter(i=>i.type==="pcb_trace"||i.type==="schematic_trace").flatMap(i=>i.route)).map(i=>MIo(i)).filter(SIo);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let I=A[0].x-A[0].width/2,e=A[0].x+A[0].width/2,t=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const i of A.slice(1))I=Math.min(I,i.x-i.width/2),e=Math.max(e,i.x+i.width/2),t=Math.min(t,i.y-i.height/2),o=Math.max(o,i.y+i.height/2);const B=e-I,C=o-t;return{center:{x:I+B/2,y:t+C/2},width:B,height:C}};function RIo({circuitJson:g,editEvents:A}){if(A.length===0)return g;let I=structuredClone(g);for(const e of A){if(e.edit_event_type==="edit_pcb_component_location"){const C=p5(I).pcb_component.get(e.pcb_component_id);if(C?.center.x===e.new_center.x&&C.center.y===e.new_center.y)continue;const i=vc(e.new_center.x-e.original_center.x,e.new_center.y-e.original_center.y);I=I.map(E=>"pcb_component_id"in E&&E.pcb_component_id===e.pcb_component_id?uIo(E,i):E);continue}if(e.edit_event_type==="edit_schematic_component_location"){I=I.map(C=>C.type==="schematic_component"&&C.schematic_component_id===e.schematic_component_id?{...C,center:e.new_center}:C);continue}if(e.edit_event_type!=="edit_pcb_trace_hint"||!e.pcb_trace_hint_id)continue;if(p5(I).pcb_trace_hint.get(e.pcb_trace_hint_id)){I=I.map(C=>C.type==="pcb_trace_hint"&&C.pcb_trace_hint_id===e.pcb_trace_hint_id?{...C,route:e.route}:C);continue}const o=p5(I).pcb_port.get(e.pcb_port_id);if(!o?.pcb_component_id)continue;const B={type:"pcb_trace_hint",pcb_trace_hint_id:e.pcb_trace_hint_id,route:e.route,pcb_port_id:e.pcb_port_id,pcb_component_id:o.pcb_component_id};I=I.filter(C=>C.type!=="pcb_trace_hint"||C.pcb_port_id!==e.pcb_port_id).concat(B)}return I}var NIo=g=>{if(!g)return"empty";const A=g.find(e=>e.type==="pcb_board");if(!A)return"no-board";const I=e=>Math.round(e*1e3)/1e3;return A.outline?A.outline.map(e=>`${I(e.x)}_${I(e.y)}`).join(","):`${I(A.width)}_${I(A.height)}`},iwA=g=>Number.isFinite(g)?g.toFixed(4):"NaN",xIo=g=>{let A=5381;for(let I=0;I<g.length;I++)A=(A<<5)+A+g.charCodeAt(I);return Math.abs(A)},FIo=g=>{if(!g?.length)return"0";const A=[];for(const t of g){if(!t?.type?.startsWith("pcb_"))continue;const o=GIo(t),B=CIg([t]),C=[iwA(B.minX),iwA(B.minY),iwA(B.maxX),iwA(B.maxY)].join(",");let Q=`${o}:${C}`;if(t.type==="pcb_trace"){const i=(t.route??[]).length;Q+=`:${i}`;for(const E of t.route??[])E.route_type==="via"&&(Q+=`:${E.tented_on_top}:${E.tented_on_bottom}`)}t.type==="pcb_board"&&(Q+=`:${t.default_via_tented_on_top}:${t.default_via_tented_on_bottom}`),t.type==="pcb_via"&&(Q+=`:${t.tented_on_top}:${t.tented_on_bottom}`),A.push(Q)}if(A.length===0)return"0";A.sort();const I=A.join(","),e=xIo(I);return`${A.length}_${e.toString(36)}`},$MI=gA.createContext(null),UIo=({children:g,initialState:A,disablePcbGroups:I})=>{const e=gA.useMemo(()=>KIo(A,I),[I]);return W.jsx($MI.Provider,{value:e,children:g})},kh={RENDERING_ENGINE:"pcb_viewer_rendering_engine",COPPER_POUR_OPACITY:"pcb_viewer_copper_pour_opacity",HIDDEN_LAYER_OPACITY:"pcb_viewer_hidden_layer_opacity",IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_COURTYARDS:"pcb_viewer_is_showing_courtyards",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask",IS_SHOWING_FABRICATION_NOTES:"pcb_viewer_is_showing_fabrication_notes",IS_SHOWING_PCB_NOTES:"pcb_viewer_is_showing_pcb_notes",IS_SHOWING_SILKSCREEN:"pcb_viewer_is_showing_silkscreen"},m3=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},p3=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},ASI=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g);return I!==null?JSON.parse(I):A}catch{return A}},gSI=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},ISI=(g,A)=>{if(typeof window>"u")return A;try{const I=localStorage.getItem(g),e=I!==null?JSON.parse(I):null;return typeof e=="number"&&Number.isFinite(e)?e:A}catch{return A}},eSI=(g,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(g,JSON.stringify(A))}catch{}},JIo="named_only",KIo=(g={},A=!1)=>BkI(I=>({copper_pour_opacity:Math.max(0,Math.min(1,ISI(kh.COPPER_POUR_OPACITY,1))),setCopperPourOpacity:e=>{if(!Number.isFinite(e))return;const t=Math.max(0,Math.min(1,e));eSI(kh.COPPER_POUR_OPACITY,t),I({copper_pour_opacity:t})},hidden_layer_opacity:Math.max(0,Math.min(1,ISI(kh.HIDDEN_LAYER_OPACITY,.2))),setHiddenLayerOpacity:e=>{if(!Number.isFinite(e))return;const t=Math.max(0,Math.min(1,e));eSI(kh.HIDDEN_LAYER_OPACITY,t),I({hidden_layer_opacity:t})},selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,is_moving_component:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_drc_warnings:!0,is_showing_copper_pours:m3(kh.IS_SHOWING_COPPER_POURS,!0),is_showing_courtyards:m3(kh.IS_SHOWING_COURTYARDS,!0),is_showing_pcb_groups:A?!1:m3(kh.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:m3(kh.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!1),is_showing_solder_mask:m3(kh.IS_SHOWING_SOLDER_MASK,!1),is_showing_silkscreen:m3(kh.IS_SHOWING_SILKSCREEN,!0),is_showing_fabrication_notes:m3(kh.IS_SHOWING_FABRICATION_NOTES,!1),is_showing_pcb_notes:m3(kh.IS_SHOWING_PCB_NOTES,!0),pcb_group_view_mode:A?"all":ASI(kh.PCB_GROUP_VIEW_MODE,JIo),hovered_error_id:null,focused_error_id:null,...g,selectLayer:e=>I({selected_layer:e}),setEditMode:e=>I({in_edit_mode:e!=="off",in_move_footprint_mode:e==="move_footprint",is_moving_component:!1}),setIsShowingRatsNest:e=>I({is_showing_rats_nest:e}),setIsMovingComponent:e=>I({is_moving_component:e}),setIsMouseOverContainer:e=>I({is_mouse_over_container:e}),setIsShowingMultipleTracesLength:e=>I({is_showing_multiple_traces_length:e}),setIsShowingAutorouting:e=>I({is_showing_autorouting:e}),setIsShowingDrcErrors:e=>I({is_showing_drc_errors:e}),setIsShowingDrcWarnings:e=>I({is_showing_drc_warnings:e}),setIsShowingCopperPours:e=>{p3(kh.IS_SHOWING_COPPER_POURS,e),I({is_showing_copper_pours:e})},setIsShowingCourtyards:e=>{p3(kh.IS_SHOWING_COURTYARDS,e),I({is_showing_courtyards:e})},setIsShowingPcbGroups:e=>{A||(p3(kh.IS_SHOWING_PCB_GROUPS,e),I({is_showing_pcb_groups:e}))},setIsShowingGroupAnchorOffsets:e=>{p3(kh.IS_SHOWING_GROUP_ANCHOR_OFFSETS,e),I({is_showing_group_anchor_offsets:e})},setIsShowingSolderMask:e=>{p3(kh.IS_SHOWING_SOLDER_MASK,e),I({is_showing_solder_mask:e})},setIsShowingSilkscreen:e=>{p3(kh.IS_SHOWING_SILKSCREEN,e),I({is_showing_silkscreen:e})},setIsShowingFabricationNotes:e=>{p3(kh.IS_SHOWING_FABRICATION_NOTES,e),I({is_showing_fabrication_notes:e})},setIsShowingPcbNotes:e=>{p3(kh.IS_SHOWING_PCB_NOTES,e),I({is_showing_pcb_notes:e})},setPcbGroupViewMode:e=>{A||(gSI(kh.PCB_GROUP_VIEW_MODE,e),I({pcb_group_view_mode:e}))},setHoveredErrorId:e=>I({hovered_error_id:e}),setFocusedErrorId:e=>I({focused_error_id:e})})),Qi=g=>{const A=gA.useContext($MI);return hkI(A,g)},PIo=()=>{gA.useEffect(()=>{x$t()},[]);const g=Qi(A=>A.pcb_viewer_id);return W.jsx(N$t,{position:"top-center",containerId:g})},Da={elementOverlay:40,dimensionOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:30,clickToInteractOverlay:100};function LIo(){var g=gA.useRef(!1),A=gA.useCallback(function(){return g.current},[]);return gA.useEffect(function(){return g.current=!0,function(){g.current=!1}},[]),A}var YIo=function(g){g===void 0&&(g={});var A=gA.useState(g),I=A[0],e=A[1],t=gA.useCallback(function(o){e(function(B){return Object.assign({},B,o instanceof Function?o(B):o)})},[]);return[I,t]},_Io=YIo,bIo=function(){},tSI=typeof window<"u",HIo=XkI(LAo()),vIo=function(){var g=LIo(),A=_Io({value:void 0,error:void 0,noUserInteraction:!0}),I=A[0],e=A[1],t=gA.useCallback(function(o){if(g()){var B,C;try{if(typeof o!="string"&&typeof o!="number"){var Q=new Error("Cannot copy typeof "+typeof o+" to clipboard, must be a string");console.error(Q),e({value:o,error:Q,noUserInteraction:!0});return}else if(o===""){var Q=new Error("Cannot copy empty string to clipboard.");console.error(Q),e({value:o,error:Q,noUserInteraction:!0});return}C=o.toString(),B=(0,HIo.default)(C),e({value:C,error:void 0,noUserInteraction:B})}catch(i){e({value:C,error:i,noUserInteraction:B})}}},[]);return[I,t]},qIo=vIo,TIo=tSI?gA.useLayoutEffect:gA.useEffect,ZIo=TIo,oSI={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function OIo(){var g=gA.useState(null),A=g[0],I=g[1],e=gA.useState(oSI),t=e[0],o=e[1],B=gA.useMemo(function(){return new window.ResizeObserver(function(C){if(C[0]){var Q=C[0].contentRect,i=Q.x,E=Q.y,n=Q.width,s=Q.height,r=Q.top,a=Q.left,c=Q.bottom,h=Q.right;o({x:i,y:E,width:n,height:s,top:r,left:a,bottom:c,right:h})}})},[]);return ZIo(function(){if(A)return B.observe(A),function(){B.disconnect()}},[A]),[I,t]}var HIA=tSI&&typeof window.ResizeObserver<"u"?OIo:function(){return[bIo,oSI]},BSI=({initialTransform:g,initialTouch1:A,initialTouch2:I,finalTouch1:e,finalTouch2:t})=>{if(!e||!t)return g;const o={x:(A.x+I.x)/2,y:(A.y+I.y)/2},B={x:(e.x+t.x)/2,y:(e.y+t.y)/2},C=Math.hypot(I.x-A.x,I.y-A.y),Q=Math.hypot(t.x-e.x,t.y-e.y),i=C===0?1:Q/C,E=B.x-o.x,n=B.y-o.y;return Yw(vc(E,n),vc(o.x,o.y),rJ(i,i),vc(-o.x,-o.y),g)},WIo=(g={})=>{const A=gA.useRef(null),[I,e]=gA.useState(0),t=g.canvasElm??A.current,[o,B]=gA.useState(g.initialTransform??aJ()),[C,Q]=gA.useState(0),[i,E]=gA.useReducer(d=>d+1,0),n=gA.useCallback(d=>{g.onSetTransform&&g.onSetTransform(d),g.transform||B(d)},[g.onSetTransform,B]),s=gA.useCallback(d=>{n(d),E()},[n]),r=g.transform??o,a=gA.useCallback(()=>{e(Date.now())},[]),c=gA.useRef("none"),h=gA.useRef(null),l=gA.useRef(null);gA.useEffect(()=>{const d=g.canvasElm??A.current;if(d&&!t){Q(C+1);return}if(!d){const b=setTimeout(()=>{Q(C+1)},100);return()=>clearTimeout(b)}let y=g.transform??o,w={x:0,y:0},u={x:0,y:0},G=!1;const m=b=>({x:b.pageX-d.getBoundingClientRect().left-window.scrollX,y:b.pageY-d.getBoundingClientRect().top-window.scrollY});function p(b){g.enabled!==!1&&(g.shouldDrag&&!g.shouldDrag(b)||(w=m(b),!(Date.now()-I<100)&&(G=!0,b.preventDefault())))}function k(b){if(!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Yw(vc(u.x-w.x,u.y-w.y),y);n(H),y=H,G=!1}function S(b){if(m(b),!G||g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;u=m(b);const H=Yw(vc(u.x-w.x,u.y-w.y),y);n(H)}function R(b){if(g.enabled===!1||g.shouldDrag&&!g.shouldDrag(b))return;const H=m(b),q=Yw(vc(H.x,H.y),rJ(1-b.deltaY/1e3,1-b.deltaY/1e3),vc(-H.x,-H.y),y);n(q),y=q,b.preventDefault()}function F(b){if(!G||g.shouldDrag&&!g.shouldDrag(b))return;if(d){const q=d.getBoundingClientRect();if(b.clientX>=q.left+10&&b.clientX<=q.right-10&&b.clientY>=q.top+10&&b.clientY<=q.bottom-10)return}G=!1,u=m(b);const H=Yw(vc(u.x-w.x,u.y-w.y),y);n(H),y=H}function N(b){if(b.preventDefault(),g.enabled!==!1){if(b.touches.length===1){c.current="drag";const H=b.touches[0];h.current={initialTransform:y,initialTouch:{x:H.clientX,y:H.clientY}}}else if(b.touches.length===2){c.current="pinch";const H=b.touches[0],q=b.touches[1];l.current={initialTransform:y,initialTouch1:{x:H.clientX,y:H.clientY},initialTouch2:{x:q.clientX,y:q.clientY},finalTouch1:null,finalTouch2:null}}}}function U(b){if(b.preventDefault(),g.enabled!==!1){if(c.current==="drag"&&b.touches.length===1&&h.current){const H=b.touches[0],q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Yw(vc(j,Z),h.current.initialTransform);n(O)}else if(c.current==="pinch"&&b.touches.length===2&&l.current){const H=b.touches[0],q=b.touches[1];l.current.finalTouch1={x:H.clientX,y:H.clientY},l.current.finalTouch2={x:q.clientX,y:q.clientY};const j=BSI(l.current);n(j)}}}function L(b){b.preventDefault();const H=b.changedTouches[0];if(c.current==="drag"&&h.current&&H){const q={x:H.clientX,y:H.clientY},j=q.x-h.current.initialTouch.x,Z=q.y-h.current.initialTouch.y,O=Yw(vc(j,Z),h.current.initialTransform);n(O),y=O}else if(c.current==="pinch"&&l.current){const q=BSI(l.current);n(q),y=q}c.current="none",h.current=null,l.current=null}return d.addEventListener("mousedown",p),d.addEventListener("mouseup",k),window.addEventListener("mousemove",S),d.addEventListener("mouseout",F),d.addEventListener("wheel",R),d.addEventListener("touchstart",N,{passive:!1}),d.addEventListener("touchmove",U,{passive:!1}),d.addEventListener("touchend",L,{passive:!1}),d.addEventListener("touchcancel",L,{passive:!1}),()=>{d.removeEventListener("mousedown",p),d.removeEventListener("mouseup",k),window.removeEventListener("mousemove",S),d.removeEventListener("mouseout",F),d.removeEventListener("wheel",R),d.removeEventListener("touchstart",N),d.removeEventListener("touchmove",U),d.removeEventListener("touchend",L),d.removeEventListener("touchcancel",L)}},[t,C,i,I,g.enabled,g.shouldDrag]);const D=gA.useCallback(d=>Mt(r,d),[r]);return{ref:A,transform:r,applyTransformToPoint:D,setTransform:s,cancelDrag:a}},VIo=WIo;function CSI(g){let A=g;for(;A.parent!==null;)A=A.parent;let I=g;for(;I.parent!==null&&I.parent!==A;){const e=I.parent;I.parent=A,I=e}return A}function jIo(g,A){const I={nodeId:g,nextMember:null},e={parent:null,networkId:`connectivity_net${A.nextNetworkNumber++}`,firstMember:I,lastMember:I};return A.rootByNodeId.set(g,e),e}function zIo(g,A){const I=A.rootByNodeId.get(g);return I===void 0?jIo(g,A):CSI(I)}function XIo({targetRoot:g,sourceRoot:A}){g.lastMember.nextMember=A.firstMember,g.lastMember=A.lastMember,A.parent=g}function $Io(g){const A=[];let I=g.firstMember;for(;I!==null;)A.push(I.nodeId),I=I.nextMember;return A}function Aeo(g){const A={rootByNodeId:new Map,nextNetworkNumber:0};for(const e of g){let t=null;for(const o of e){const B=zIo(o,A);if(t===null){t=B;continue}t=CSI(t),B!==t&&XIo({targetRoot:t,sourceRoot:B})}}const I={};for(const e of A.rootByNodeId.values())e.parent===null&&(I[e.networkId]=$Io(e));return I}var geo=class{netMap;idToNetMap;constructor(g){this.netMap=g,this.idToNetMap={};for(const[A,I]of Object.entries(g))for(const e of I)this.idToNetMap[e]=A}addConnections(g){for(const A of g){const I=new Set;for(const t of A){const o=this.idToNetMap[t];o&&I.add(o)}let e;if(I.size===0)e=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[e]=[];else if(I.size===1)e=I.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{e=I.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const t of I)if(t!==e){this.netMap[e].push(...this.netMap[t]),this.netMap[t]=this.netMap[e];for(const o of this.netMap[e])this.idToNetMap[o]=e}}for(const t of A)this.netMap[e].includes(t)||this.netMap[e].push(t),this.idToNetMap[t]=e}}getIdsConnectedToNet(g){return this.netMap[g]||[]}getNetConnectedToId(g){return this.idToNetMap[g]}areIdsConnected(g,A){if(g===A)return!0;const I=this.getNetConnectedToId(g);if(!I)return!1;const e=this.getNetConnectedToId(A);return e?I===e||e===g||e===g:!1}areAllIdsConnected(g){const A=this.getNetConnectedToId(g[0]);for(const I of g){const e=this.getNetConnectedToId(I);if(e===void 0||e!==A)return!1}return!0}},Ieo=g=>{const A=[];for(const e of g)if(e.type==="source_trace")A.push([e.source_trace_id,...e.connected_source_port_ids??[],...e.connected_source_net_ids??[]].filter(Boolean));else if(e.type==="pcb_port"){const{pcb_port_id:t,source_port_id:o}=e;o&&t&&A.push([o,t])}else if(e.type==="pcb_smtpad"){const{pcb_smtpad_id:t,pcb_port_id:o}=e;o&&t&&A.push([t,o])}else if(e.type==="pcb_plated_hole"){const{pcb_plated_hole_id:t,pcb_port_id:o}=e;o&&t&&A.push([t,o])}else if(e.type==="pcb_trace"){const{pcb_trace_id:t,source_trace_id:o}=e,B=Array.isArray(e.route)?e.route.filter(C=>C&&C.route_type==="wire"):[];if(o&&t&&A.push([t,o]),Array.isArray(B)){const C=B.find(i=>i?.start_pcb_port_id)?.start_pcb_port_id,Q=B.find(i=>i?.end_pcb_port_id)?.end_pcb_port_id;C&&t&&A.push([C,t]),t&&Q&&A.push([t,Q])}}else if(e.type==="pcb_via"){const{pcb_via_id:t,pcb_trace_id:o,source_trace_id:B,source_net_id:C}=e,Q=[...e.pcb_port_ids??[],o,B,C].filter(i=>!!i);t&&Q.length>0&&A.push([t,...Q])}else if(e.type==="source_component"&&e.internally_connected_source_port_ids)for(const t of e.internally_connected_source_port_ids)A.push(t);const I=Aeo(A);return new geo(I)};function eeo(g,A){if(g.length<2)throw new Error("Stroke must have at least two points");const I=g.map(n=>Array.isArray(n)?{x:n[0],y:n[1]}:n),e=[],t=[];function o(n,s){const r=s.x-n.x,a=s.y-n.y,c=Math.sqrt(r*r+a*a);return{x:-a/c,y:r/c}}function B(n,s,r,a){const c=a/2,h={x:n.x+s.x*c*r,y:n.y+s.y*c*r};r>0?e.push(h):t.unshift(h)}const C=o(I[0],I[1]),Q=I[0].trace_width??A;B(I[0],C,1,Q),B(I[0],C,-1,Q);for(let n=1;n<I.length-1;n++){const s=I[n-1],r=I[n],a=I[n+1],c=o(s,r),h=o(r,a),l=c.x+h.x,D=c.y+h.y,d=Math.sqrt(l*l+D*D),y=r.trace_width??A;if(d/2>2*(y/2))B(r,c,1,y),B(r,h,1,y),B(r,c,-1,y),B(r,h,-1,y);else{const u=1/d;B(r,{x:l*u,y:D*u},1,y),B(r,{x:l*u,y:D*u},-1,y)}}const i=o(I[I.length-2],I[I.length-1]),E=I[I.length-1].trace_width??A;return B(I[I.length-1],i,1,E),B(I[I.length-1],i,-1,E),[...e,...t]}var teo=(g,A)=>{const{x:I,y:e,width:t,height:o,layer:B,rect_border_radius:C}=g,Q=g.corner_radius??C??0,i=[{_pcb_drawing_object_id:MR("rect"),pcb_drawing_type:"rect",x:I,y:e,w:t,h:o,layer:B||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:Q,...g.shape==="rotated_rect"&&g.ccw_rotation!==void 0?{ccw_rotation:g.ccw_rotation}:{}}];if(g.is_covered_with_solder_mask){const E=B==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={...{_pcb_drawing_object_id:MR("rect"),pcb_drawing_type:"rect",x:I,y:e,w:t,h:o,layer:E,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:Q,...g.shape==="rotated_rect"&&g.ccw_rotation!==void 0?{ccw_rotation:g.ccw_rotation}:{}},..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};i.push(s)}return i},oeo=(g,A)=>{const{x:I,y:e,radius:t,layer:o}=g,B=[{_pcb_drawing_object_id:MR("circle"),pcb_drawing_type:"circle",x:I,y:e,r:t,layer:o||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(g.is_covered_with_solder_mask){const C=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",Q={_pcb_drawing_object_id:MR("circle"),pcb_drawing_type:"circle",x:I,y:e,r:t,layer:C,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};B.push(Q)}return B},Beo=(g,A)=>{const{layer:I,points:e}=g,t=[{_pcb_drawing_object_id:MR("polygon"),pcb_drawing_type:"polygon",points:QIg(e),layer:I||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(g.is_covered_with_solder_mask){const o=I==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",B={_pcb_drawing_object_id:MR("polygon"),pcb_drawing_type:"polygon",points:QIg(e),layer:o,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};t.push(B)}return t},Ceo=(g,A)=>{const{x:I,y:e,width:t,height:o,layer:B}=g,C=[{_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:B||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(g.is_covered_with_solder_mask){const Q=B==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",i={_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:Q,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};C.push(i)}return C},Qeo=(g,A)=>{const{x:I,y:e,width:t,height:o,layer:B,ccw_rotation:C}=g,Q=[{_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:B||"top",_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:C}];if(g.is_covered_with_solder_mask){const i=B==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",E={_pcb_drawing_object_id:MR("pill"),pcb_drawing_type:"pill",x:I,y:e,w:t,h:o,layer:i,_element:g,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:C,..."solder_mask_color"in g&&g.solder_mask_color?{color:g.solder_mask_color}:{}};Q.push(E)}return Q},Zc=0,MR=g=>`${g}_${Zc++}`,QIg=g=>(g??[]).map(A=>({x:sg.parse(A.x),y:sg.parse(A.y)}));function ieo(g){const A=new Map;for(const I of g){const e=I[`${I.type}_id`];e!==void 0&&!A.has(`${I.type}:${e}`)&&A.set(`${I.type}:${e}`,I)}return A}var Eeo=(g,A,I)=>{const e=(Q,i)=>{if(i!==void 0)return I?I.get(`${Q}:${i}`):A.find(E=>E.type===Q&&E[`${Q}_id`]===i)},t=e("pcb_component","pcb_component_id"in g?g.pcb_component_id:void 0),o=e("source_component",t?.source_component_id),B="source_port_id"in g?g.source_port_id:"pcb_port_id"in g?e("pcb_port",g.pcb_port_id)?.source_port_id:void 0,C=e("source_port",B);switch(g.type){case"pcb_smtpad":{const Q={_parent_pcb_component:t,_parent_source_component:o,_source_port:C};return g.shape==="rect"||g.shape==="rotated_rect"?teo(g,Q):g.shape==="circle"?oeo(g,Q):g.shape==="polygon"?Beo(g,Q):g.shape==="pill"?Ceo(g,Q):g.shape==="rotated_pill"?Qeo(g,Q):[]}case"pcb_trace":{const Q=[];if(g.route_thickness_mode==="interpolated"){const n=g.route.flatMap(a=>a.route_type==="through_pad"?[{...a.start,trace_width:a.width},{...a.end,trace_width:a.width}]:[{x:a.x,y:a.y,trace_width:a.route_type==="wire"?a.width:.5}]),s=eeo(n,.5),r=g.route[0].layer;return Q.push({_pcb_drawing_object_id:`polygon_${Zc++}`,_element:g,pcb_drawing_type:"polygon",points:s,layer:r}),g.route.forEach(a=>{a.route_type==="via"&&Q.push({_pcb_drawing_object_id:`circle_${Zc++}`,_element:g,pcb_drawing_type:"circle",x:a.x,y:a.y,r:a.outer_diameter/2,layer:a.from_layer})}),Q}let i=null,E=null;for(const n of g.route)n.route_type==="wire"&&(i!==null&&E!==null&&Q.push({_pcb_drawing_object_id:`line_${Zc++}`,_element:g,pcb_drawing_type:"line",x1:i,y1:E,x2:n.x,y2:n.y,width:n.width,squareCap:!1,layer:n.layer}),i=n.x,E=n.y);return Q}case"pcb_via":{const{x:Q,y:i,outer_diameter:E,hole_diameter:n}=g,s=g.from_layer,r=g.to_layer,a=g.layers,c=[];s&&r?c.push(s,r):a&&Array.isArray(a)?c.push(...a):c.push("top","bottom");const h=[];for(const l of c)h.push({_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:E/2,layer:l,_element:g,_parent_pcb_component:t,_parent_source_component:o});return h.push({_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:n/2,layer:"drill",_element:g}),h}case"pcb_plated_hole":if(g.shape==="circle"){const{x:Q,y:i,hole_diameter:E,outer_diameter:n}=g;return[{_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:n/2,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C},{_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:Q,y:i,r:E/2,layer:"drill",_element:g}]}else if(g.shape==="oval"){const{x:Q,y:i,outer_height:E,outer_width:n,hole_height:s,hole_width:r}=g;return[{_pcb_drawing_object_id:`oval_${Zc++}`,pcb_drawing_type:"oval",x:Q,y:i,rX:n/2,rY:E/2,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C},{_pcb_drawing_object_id:`oval_${Zc++}`,_element:g,pcb_drawing_type:"oval",x:Q,y:i,rX:r/2,rY:s/2,layer:"drill"}]}else if(g.shape==="pill"){const{x:Q,y:i,outer_height:E,outer_width:n,hole_height:s,hole_width:r}=g;return[{_pcb_drawing_object_id:`pill_${Zc++}`,pcb_drawing_type:"pill",x:Q,y:i,w:n,h:E,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,ccw_rotation:g.ccw_rotation},{_pcb_drawing_object_id:`pill_${Zc++}`,_element:g,pcb_drawing_type:"pill",x:Q,y:i,w:r,h:s,layer:"drill",ccw_rotation:g.ccw_rotation}]}else if(g.shape==="circular_hole_with_rect_pad"){const{x:Q,y:i,hole_diameter:E,rect_pad_width:n,rect_pad_height:s,rect_border_radius:r,hole_offset_x:a,hole_offset_y:c}=g,h=sg.parse(a??0),l=sg.parse(c??0);return[{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:n,h:s,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:r},{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:n,h:s,layer:"bottom",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:r,is_hoverable:!1},{_pcb_drawing_object_id:`circle_${Zc++}`,_element:g,pcb_drawing_type:"circle",x:Q+h,y:i+l,r:E/2,layer:"drill",is_hoverable:!1}]}else if(g.shape==="pill_hole_with_rect_pad"){const{x:Q,y:i,hole_width:E,hole_height:n,rect_pad_width:s,rect_pad_height:r,rect_border_radius:a}=g;return[{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:s,h:r,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:a},{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:s,h:r,layer:"bottom",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,roundness:a,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${Zc++}`,_element:g,pcb_drawing_type:"pill",x:Q,y:i,w:E,h:n,layer:"drill",is_hoverable:!1}]}else if(g.shape==="rotated_pill_hole_with_rect_pad"){const{x:Q,y:i,hole_width:E,hole_height:n,hole_ccw_rotation:s,rect_pad_width:r,rect_pad_height:a,rect_ccw_rotation:c,rect_border_radius:h}=g;return[{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:r,h:a,layer:"top",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,ccw_rotation:c,roundness:h},{_pcb_drawing_object_id:`rect_${Zc++}`,pcb_drawing_type:"rect",x:Q,y:i,w:r,h:a,layer:"bottom",_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C,ccw_rotation:c,roundness:h,is_hoverable:!1},{_pcb_drawing_object_id:`pill_${Zc++}`,_element:g,pcb_drawing_type:"pill",x:Q,y:i,w:E,h:n,layer:"drill",ccw_rotation:s,is_hoverable:!1}]}else if(g.shape==="hole_with_polygon_pad"){const{x:Q,y:i,pad_outline:E,hole_shape:n,hole_diameter:s,hole_width:r,hole_height:a,layers:c,hole_offset_x:h,hole_offset_y:l}=g,D=sg.parse(h??0),d=sg.parse(l??0),y=E,w=[];if(y&&Array.isArray(y)){const m=QIg(y).map(p=>({x:p.x+Q,y:p.y+i}));for(const p of c||["top","bottom"])w.push({_pcb_drawing_object_id:`polygon_${Zc++}`,pcb_drawing_type:"polygon",points:m,layer:p,_element:g,_parent_pcb_component:t,_parent_source_component:o,_source_port:C})}const u={x:Q+D,y:i+d},G=[];return n==="circle"?G.push({_pcb_drawing_object_id:`circle_${Zc++}`,pcb_drawing_type:"circle",x:u.x,y:u.y,r:(s??0)/2,layer:"drill",_element:g,_parent_pcb_component:t,_parent_source_component:o}):n==="oval"?G.push({_pcb_drawing_object_id:`oval_${Zc++}`,pcb_drawing_type:"oval",x:u.x,y:u.y,rX:(r??0)/2,rY:(a??0)/2,layer:"drill",_element:g,_parent_pcb_component:t,_parent_source_component:o}):(n==="pill"||n==="rotated_pill")&&G.push({_pcb_drawing_object_id:`pill_${Zc++}`,pcb_drawing_type:"pill",x:u.x,y:u.y,w:r??0,h:a??0,layer:"drill",_element:g,_parent_pcb_component:t,_parent_source_component:o,ccw_rotation:g.ccw_rotation}),[...w,...G]}else return[]}return[]};function neo(g,A,I){const e=document.createElement("canvas");e.width=e.height=1;const t=e.getContext("2d");return g.filter(o=>o.type!=="pcb_copper_pour"||o.layer!==I?!1:(UlI({ctx:t,pour:o,realToCanvasMat:aJ(),colorMap:Kw}),t.isPointInPath(A.x,A.y,o.shape==="brep"?"evenodd":"nonzero")))}function seo(g){return g.type==="pcb_copper_pour"}function QSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,opacity:t=1}){const o=A.filter(seo);if(o.length===0||t<=0)return;const B=new VE(g);B.configure({colorOverrides:{copper:Object.fromEntries(Object.entries(Kw.copper).map(([C,Q])=>[C,wQ(Q).alpha(t).rgb().string()]))}}),B.realToCanvasMat=e,B.drawElements(o,{layers:I})}var EwA=(g,A,I)=>I(g,A),iSI=(g,A,I,e,t)=>{const o=t*Math.PI/180,B=Math.cos(o),C=Math.sin(o),Q=g-I,i=A-e,E=Q*B-i*C,n=Q*C+i*B;return{x:E+I,y:n+e}},vIA=g=>{if(g.length===0)return null;let A=g[0].x,I=g[0].x,e=g[0].y,t=g[0].y;for(const o of g)A=EwA(A,o.x,Math.min),I=EwA(I,o.x,Math.max),e=EwA(e,o.y,Math.min),t=EwA(t,o.y,Math.max);return{minX:A,maxX:I,minY:e,maxY:t}},aeo=(g,A)=>({minX:Math.min(g.minX,A.minX),maxX:Math.max(g.maxX,A.maxX),minY:Math.min(g.minY,A.minY),maxY:Math.max(g.maxY,A.maxY)}),reo=(g,A)=>g?aeo(g,A):A,iIg=g=>{switch(g.pcb_drawing_type){case"line":{const A=(g.width??0)/2,I=[{x:g.x1,y:g.y1},{x:g.x2,y:g.y2}],e=vIA(I);return e?{minX:e.minX-A,maxX:e.maxX+A,minY:e.minY-A,maxY:e.maxY+A}:null}case"rect":{const A=g.w/2,I=g.h/2,e=[{x:g.x-A,y:g.y-I},{x:g.x+A,y:g.y-I},{x:g.x+A,y:g.y+I},{x:g.x-A,y:g.y+I}],t=g.ccw_rotation??0,o=t===0?e:e.map(B=>iSI(B.x,B.y,g.x,g.y,t));return vIA(o)}case"circle":return{minX:g.x-g.r,maxX:g.x+g.r,minY:g.y-g.r,maxY:g.y+g.r};case"oval":return{minX:g.x-g.rX,maxX:g.x+g.rX,minY:g.y-g.rY,maxY:g.y+g.rY};case"pill":{const A=g.w/2,I=g.h/2,e=[{x:g.x-A,y:g.y-I},{x:g.x+A,y:g.y-I},{x:g.x+A,y:g.y+I},{x:g.x-A,y:g.y+I}],t=g.ccw_rotation??0,o=t===0?e:e.map(B=>iSI(B.x,B.y,g.x,g.y,t));return vIA(o)}case"polygon":return vIA(g.points);case"polygon_with_arcs":{const A=g.brep_shape.outer_ring.vertices.map(I=>({x:I.x,y:I.y}));return vIA(A)}case"text":{const A=g.size??0,I=g.text?g.text.length*A*.6:0,e=A;if(I===0&&e===0)return{minX:g.x,maxX:g.x,minY:g.y,maxY:g.y};const t=I/2,o=e/2;return{minX:g.x-t,maxX:g.x+t,minY:g.y-o,maxY:g.y+o}}default:return null}},ceo=64,heo=256,leo=8;function ESI({cellX:g,cellY:A}){return`${g}:${A}`}function Deo(g){let A=1/0,I=1/0,e=-1/0,t=-1/0;for(const C of g){const Q=iIg(C);Q&&(A=Math.min(A,Q.minX),I=Math.min(I,Q.minY),e=Math.max(e,Q.maxX),t=Math.max(t,Q.maxY))}if(!Number.isFinite(A))return 1;const o=Math.max(e-A,t-I),B=Math.sqrt(Math.max(1,g.length/leo));return Math.max(.5,Math.min(20,o/B))}function nSI(g){const A=Deo(g),I=new Map,e=new Map,t=[];let o=0;for(const[B,C]of g.entries()){e.set(C,B),C.pcb_drawing_type==="line"&&C._element?.type==="pcb_trace"&&(o=Math.max(o,C.width));const Q=iIg(C);if(!Q){t.push(C);continue}const i=Math.floor(Q.minX/A),E=Math.floor(Q.maxX/A),n=Math.floor(Q.minY/A),s=Math.floor(Q.maxY/A);if((E-i+1)*(s-n+1)>ceo){t.push(C);continue}for(let a=i;a<=E;a++)for(let c=n;c<=s;c++){const h=ESI({cellX:a,cellY:c}),l=I.get(h)??[];l.push(C),I.set(h,l)}}return{cellSize:A,globalPrimitives:t,maxTraceWidth:o,primitiveIndexByPrimitive:e,primitives:g,primitivesByCell:I}}function sSI({point:g,realToScreenScale:A,spatialIndex:I}){const e=Math.max(Math.abs(A),Number.EPSILON),t=Math.max(I.maxTraceWidth*25,2)/e,o=Math.floor((g.x-t)/I.cellSize),B=Math.floor((g.x+t)/I.cellSize),C=Math.floor((g.y-t)/I.cellSize),Q=Math.floor((g.y+t)/I.cellSize);if((B-o+1)*(Q-C+1)>heo)return I.primitives;const E=new Set(I.globalPrimitives);for(let n=o;n<=B;n++)for(let s=C;s<=Q;s++){const r=ESI({cellX:n,cellY:s}),a=I.primitivesByCell.get(r);if(a)for(const c of a)E.add(c)}return[...E].sort((n,s)=>(I.primitiveIndexByPrimitive.get(n)??Number.MAX_SAFE_INTEGER)-(I.primitiveIndexByPrimitive.get(s)??Number.MAX_SAFE_INTEGER))}function deo({primitivesWithoutInteractionMetadata:g,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:I}){const e=[],t=new Set(I);for(const o of g){const B={...o},C=o._element,Q=o._parent_pcb_component;o?.layer==="drill"?(B.is_in_highlighted_net=!1,B.is_mouse_over=!1):A.has(o._pcb_drawing_object_id)?B.is_mouse_over=!0:C&&("pcb_trace_id"in C&&t.has(C.pcb_trace_id)||"pcb_port_id"in C&&t.has(C.pcb_port_id)||"pcb_via_id"in C&&t.has(C.pcb_via_id)||"pcb_component_id"in C&&t.has(C.pcb_component_id)||Q&&"pcb_component_id"in Q&&t.has(Q.pcb_component_id))?B.is_in_highlighted_net=!0:(B.is_in_highlighted_net=!1,B.is_mouse_over=!1),e.push(B)}return e}var aSI=g=>{const A=new Map,I=new Map,e=new Map,t=new Map,o=new Map;for(const B of g)B.type==="pcb_trace"&&B.pcb_trace_id?A.set(B.pcb_trace_id,B):B.type==="pcb_port"&&B.pcb_port_id?I.set(B.pcb_port_id,B):B.type==="pcb_via"&&B.pcb_via_id?e.set(B.pcb_via_id,B):B.type==="pcb_component"&&B.pcb_component_id?t.set(B.pcb_component_id,B):B.type==="pcb_board"&&B.pcb_board_id&&o.set(B.pcb_board_id,B);return{tracesById:A,portsById:I,viasById:e,componentsById:t,boardsById:o}},Y2=(g,A)=>A?g?{minX:Math.min(g.minX,A.minX),maxX:Math.max(g.maxX,A.maxX),minY:Math.min(g.minY,A.minY),maxY:Math.max(g.maxY,A.maxY)}:A:g,k5=(g,A=.45)=>({minX:g.x-A,maxX:g.x+A,minY:g.y-A,maxY:g.y+A}),yeo=g=>{if(g.length===0)return null;let A=null;for(const I of g){const e=Math.max((I.width??.2)/2,.3);A=Y2(A,k5(I,e))}return A},rSI=g=>{if(!g?.center)return null;const A=Math.max(g.width??0,1.2),I=Math.max(g.height??0,1.2);return{minX:g.center.x-A/2,maxX:g.center.x+A/2,minY:g.center.y-I/2,maxY:g.center.y+I/2}},weo=g=>!g?.center||typeof g.width!="number"||typeof g.height!="number"?null:{minX:g.center.x-g.width/2,maxX:g.center.x+g.width/2,minY:g.center.y-g.height/2,maxY:g.center.y+g.height/2},ueo=(g,A)=>({minX:g.minX-A,maxX:g.maxX+A,minY:g.minY-A,maxY:g.maxY+A}),Geo=(g,A=.35)=>{const I=I0(g);return I?ueo(I,A):null},cSI=({error:g,tracesById:A,portsById:I,viasById:e,componentsById:t})=>{if(g.center)return g.center;if(g.pcb_center)return g.pcb_center;if(g.component_center)return g.component_center;if(g.pcb_via_ids?.length){const o=g.pcb_via_ids.map(B=>e.get(B)).filter(Boolean);if(o.length>0)return{x:o.reduce((B,C)=>B+C.x,0)/o.length,y:o.reduce((B,C)=>B+C.y,0)/o.length}}if(g.pcb_port_ids?.length){const o=g.pcb_port_ids.map(B=>I.get(B)).filter(Boolean);if(o.length>0)return{x:o.reduce((B,C)=>B+C.x,0)/o.length,y:o.reduce((B,C)=>B+C.y,0)/o.length}}if(g.pcb_trace_id){const o=A.get(g.pcb_trace_id);if(o?.route?.length){const B=Math.floor(o.route.length/2);return{x:o.route[B].x,y:o.route[B].y}}}return g.pcb_component_id?t.get(g.pcb_component_id)?.center??null:null},meo=({error:g,indexes:A})=>cSI({error:g,...A}),peo=({error:g,boardsById:A})=>{if(!g.component_bounds||!g.pcb_board_id)return null;const I=weo(A.get(g.pcb_board_id));if(!I)return null;const e=g.component_bounds,t=[];return e.min_x<I.minX&&(t.push({x:I.minX,y:Math.max(e.min_y,I.minY)}),t.push({x:I.minX,y:Math.min(e.max_y,I.maxY)})),e.max_x>I.maxX&&(t.push({x:I.maxX,y:Math.max(e.min_y,I.minY)}),t.push({x:I.maxX,y:Math.min(e.max_y,I.maxY)})),e.min_y<I.minY&&(t.push({x:Math.max(e.min_x,I.minX),y:I.minY}),t.push({x:Math.min(e.max_x,I.maxX),y:I.minY})),e.max_y>I.maxY&&(t.push({x:Math.max(e.min_x,I.minX),y:I.maxY}),t.push({x:Math.min(e.max_x,I.maxX),y:I.maxY})),Geo(t,.3)},hSI=new Set(["source_failed_to_create_component_error"]),keo=({error:g,indexes:A})=>{if(hSI.has(g.error_type)||hSI.has(g.type))return null;let I=null;const e=cSI({error:g,...A});if(e&&(I=Y2(I,k5(e,.35))),g.error_type==="pcb_component_outside_board_error"?I=Y2(I,peo({error:g,boardsById:A.boardsById})):g.component_bounds&&!e&&(I=Y2(I,{minX:g.component_bounds.min_x,maxX:g.component_bounds.max_x,minY:g.component_bounds.min_y,maxY:g.component_bounds.max_y})),g.center&&!e&&(I=Y2(I,k5(g.center))),g.pcb_center&&!e&&(I=Y2(I,k5(g.pcb_center))),g.component_center&&!e&&(I=Y2(I,k5(g.component_center))),g.pcb_port_ids&&!e)for(const t of g.pcb_port_ids){const o=A.portsById.get(t);o&&(I=Y2(I,k5({x:o.x,y:o.y},.4)))}if(g.pcb_trace_id&&!e){const t=A.tracesById.get(g.pcb_trace_id);t?.route&&(I=Y2(I,yeo(t.route)))}if(g.pcb_via_ids)for(const t of g.pcb_via_ids){const o=A.viasById.get(t);o&&(I=Y2(I,k5({x:o.x,y:o.y},Math.max((o.outer_diameter??.5)/2,.28))))}if(g.pcb_component_id&&!e&&(I=Y2(I,rSI(A.componentsById.get(g.pcb_component_id)))),g.pcb_component_ids&&!e)for(const t of g.pcb_component_ids)I=Y2(I,rSI(A.componentsById.get(t)));return I},lSI=({bounds:g,width:A,height:I})=>{const e={x:(g.minX+g.maxX)/2,y:(g.minY+g.maxY)/2},t=Math.max(g.maxX-g.minX,.8)+1.4,o=Math.max(g.maxY-g.minY,.8)+1.4,B=Math.min(A/t,I/o,240)*.92;return Yw(vc(A/2,I/2),rJ(B,-B,0,0),vc(-e.x,-e.y))},Meo=g=>{const A=new Set;g.pcb_trace_id&&A.add(g.pcb_trace_id);for(const I of g.pcb_port_ids??[])A.add(I);for(const I of g.pcb_via_ids??[])A.add(I);g.pcb_component_id&&A.add(g.pcb_component_id);for(const I of g.pcb_component_ids??[])A.add(I);return[...A]},q7=(g,A)=>{const I=["pcb_trace_error_id","pcb_via_clearance_error_id","pcb_component_outside_board_error_id","source_failed_to_create_component_error_id","pcb_error_id"];for(const e of I)if(typeof g?.[e]=="string"&&g[e].length>0)return g[e];for(const[e,t]of Object.entries(g??{}))if(e.endsWith("_error_id")&&typeof t=="string"&&t.length>0)return t;return`error_${A}_${g?.error_type}_${g?.message?.slice(0,20)}`},DSI=(g,A)=>A?g.find((I,e)=>I.type?.includes("error")?q7(I,e)===A:!1)??null:null,Seo=g=>1-(1-g)**3,feo=(g,A,I)=>({a:g.a+(A.a-g.a)*I,b:g.b+(A.b-g.b)*I,c:g.c+(A.c-g.c)*I,d:g.d+(A.d-g.d)*I,e:g.e+(A.e-g.e)*I,f:g.f+(A.f-g.f)*I}),dSI=g=>{g!==null&&window.cancelAnimationFrame(g)},Reo=({startTransform:g,endTransform:A,durationMs:I,onUpdate:e,setAnimationFrameId:t,onComplete:o})=>{const B=performance.now(),C=i=>{const E=i-B,n=Math.min(1,E/I),s=Seo(n);if(e(feo(g,A,s)),n<1){t(window.requestAnimationFrame(C));return}t(null),o?.()},Q=window.requestAnimationFrame(C);return t(Q),Q},nwA=g=>g?.trim()||null;function ySI(g){const A=new Map,I=new Map;for(const e of g)e.type==="source_net"?A.set(e.source_net_id,e):e.type==="source_trace"&&I.set(e.source_trace_id,e);return{sourceNetById:A,sourceTraceById:I}}function EIg({primitiveElement:g,traceOverlayElementIndex:A}){const I=g.source_trace_id;if(!I)return null;const e=A.sourceTraceById.get(I),t=nwA(e?.name);if(t)return t;const o=A.sourceNetById.get(I),B=nwA(o?.name);if(B)return B;for(const C of e?.connected_source_net_ids??[]){const Q=nwA(A.sourceNetById.get(C)?.name);if(Q)return Q}return null}function wSI({primitiveElement:g,traceOverlayElementIndex:A}){const I=g.source_trace_id,e=I?A.sourceTraceById.get(I):void 0,t=g.trace_length,o=typeof t=="number",B=e?.max_length,C=o?`${t.toFixed(3)}${typeof B=="number"?` / ${B}`:""} mm`:"",Q=EIg({primitiveElement:g,traceOverlayElementIndex:A})??nwA(e?.display_name);if(!C&&!Q)return null;const i=!!(o&&typeof B=="number"&&t>B);return{text:C,name:Q,isOverLength:i}}function T7(g,A){if(!g)return;const I=[];for(const e of[`${g.type}_id`,"pcb_port_id","pcb_trace_id","source_trace_id","source_net_id"]){const t=g[e];typeof t=="string"&&I.push(t)}for(const e of I){const t=A.getNetConnectedToId(e);if(t)return t}if("source_net_id"in g)return g.source_net_id}function uSI(g){return g&&["pcb_trace","pcb_smtpad","pcb_plated_hole","pcb_via","pcb_copper_pour"].includes(g.type)}function Neo(g,A,I){const e=ySI(A),t=g.type==="pcb_trace"?EIg({primitiveElement:g,traceOverlayElementIndex:e}):null;if(t)return t;const o=T7(g,I),B=o?A.filter(C=>T7(C,I)===o):[];for(const C of["source_net","source_trace"])for(const Q of B)if(Q.type===C&&"name"in Q&&typeof Q.name=="string"&&Q.name.trim())return Q.name.trim();if(g.type==="pcb_trace"){const C=wSI({primitiveElement:g,traceOverlayElementIndex:e})?.name;if(C)return C}for(const C of B)if(C.type==="source_trace"&&C.display_name?.trim())return C.display_name.trim();return"Net"}function xeo(g,A,I){return A.flatMap(e=>{if(e.type!=="source_bus")return[];const t=[...new Set(e.source_trace_ids.flatMap(o=>{const B=I.getNetConnectedToId(o);return B?[B]:[]}))];return t.includes(g)?[{id:e.source_bus_id,name:e.name?.trim()||"Bus",netIds:t}]:[]})}var Feo=(g,A)=>{if(g?.type!=="pcb_smtpad"&&g?.type!=="pcb_plated_hole")return;const I=A.find(t=>t.type==="pcb_component"&&t.pcb_component_id===g.pcb_component_id);if(I?.type!=="pcb_component")return;const e=A.find(t=>t.type==="source_component"&&t.source_component_id===I.source_component_id);if(e?.type==="source_component")return{source_component_id:e.source_component_id,pcb_component_id:I.pcb_component_id,refdes:e.name,manufacturer_part_number:e.manufacturer_part_number}},co={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)"}},rk=(g,A=1)=>{if(Math.abs(g.a)!==Math.abs(g.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(g.a)},qIA={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:co.board.copper.f,inner1:co.board.copper.in1,inner2:co.board.copper.in2,inner3:co.board.copper.in3,inner4:co.board.copper.in4,inner5:co.board.copper.in5,inner6:co.board.copper.in6,inner7:co.board.copper.in7,inner8:co.board.copper.in8,bottom:co.board.copper.b,drill:co.board.anchor,keepout:co.board.background,tkeepout:co.board.b_crtyd,tplace:co.board.b_silks,top_courtyard:co.board.f_crtyd,bottom_courtyard:co.board.b_crtyd,top_silkscreen:co.board.f_silks,bottom_silkscreen:co.board.b_silks,top_fabrication:co.board.f_fab,bottom_fabrication:co.board.b_fab,soldermask_top:co.board.soldermask.top,soldermask_bottom:co.board.soldermask.bottom,soldermask_with_copper_top:co.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:co.board.soldermaskWithCopper.bottom,bottom_notes:co.board.user_2,top_notes:co.board.user_2,...co.board},Ueo=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","bottom_courtyard","bottom_fabrication","top_courtyard","top_fabrication","edge_cuts","top_silkscreen"],Jeo=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";hiddenLayerOpacity=.2;xRayNetActive=!1;lastPoint;constructor(g){this.canvasLayerMap=g,this.ctxLayerMap=Object.fromEntries(Object.entries(g).map(([A,I])=>[A,I.getContext("2d")])),this.transform=aJ(),this.transform.d*=-1,this.transform=Yw(this.transform,vc(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const g of Object.values(this.ctxLayerMap))g.clearRect(0,0,g.canvas.width,g.canvas.height)}equip(g){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===g.color?1:.5,...g}}drawMeshPattern(g,A,I,e,t,o=45){const B=this.getLayerCtx(),[C,Q]=Mt(this.transform,[g,A]),[i,E]=Mt(this.transform,[g+I,A+e]),n=rk(this.transform,t);B.lineWidth=1,B.strokeStyle=this.aperture.color;const s=r=>{const a=Math.sin(r),c=Math.cos(r),h=Math.sqrt((i-C)**2+(E-Q)**2);for(let l=-h;l<=h;l+=n)B.beginPath(),B.moveTo(C+l*c-h*a,Q+l*a+h*c),B.lineTo(C+l*c+h*a,Q+l*a-h*c),B.stroke()};s(o*Math.PI/180),s((o+90)*Math.PI/180)}rect({x:g,y:A,w:I,h:e,mesh_fill:t,is_filled:o=!0,has_stroke:B,is_stroke_dashed:C,stroke_width:Q,roundness:i}){const[E,n]=Mt(this.transform,[g-I/2,A-e/2]),[s,r]=Mt(this.transform,[g+I/2,A+e/2]);this.applyAperture();const a=this.getLayerCtx(),c=i?rk(this.transform,i):0,h=B===void 0?o===!1:B;if(t)a.save(),a.beginPath(),c>0&&a.roundRect?a.roundRect(E,n,s-E,r-n,c):a.rect(E,n,s-E,r-n),a.clip(),this.drawMeshPattern(g-I/2,A-e/2,I,e,.15),a.restore(),c>0&&a.roundRect?(a.beginPath(),a.roundRect(E,n,s-E,r-n,c),a.stroke()):a.strokeRect(E,n,s-E,r-n);else if(o!==!1&&(c>0&&a.roundRect?(a.beginPath(),a.roundRect(E,n,s-E,r-n,c),a.fill()):a.fillRect(E,n,s-E,r-n)),h){const l=a.lineWidth;if(Q!==void 0&&(a.lineWidth=rk(this.transform,Q)),C){let D=[];const d=Math.abs(this.transform.a);if(d>0){const w=.1*d,u=w*1.3;w>.5&&(D=[w,u])}a.setLineDash(D)}c>0&&a.roundRect?(a.beginPath(),a.roundRect(E,n,s-E,r-n,c),a.stroke()):a.strokeRect(E,n,s-E,r-n),C&&a.setLineDash([]),Q!==void 0&&(a.lineWidth=l)}}rotatedRect(g,A,I,e,t,o,B){const C=this.getLayerCtx();this.applyAperture();const[Q,i]=Mt(this.transform,[g-I/2,A-e/2]),[E,n]=Mt(this.transform,[g+I/2,A+e/2]),s=o?rk(this.transform,o):0;C.save();const[r,a]=Mt(this.transform,[g,A]);C.translate(r,a);const c=360-t;t&&C.rotate(c*Math.PI/180),C.translate(-r,-a),B?(C.beginPath(),s>0&&C.roundRect?C.roundRect(Q,i,E-Q,n-i,s):C.rect(Q,i,E-Q,n-i),C.clip(),this.drawMeshPattern(g-I/2,A-e/2,I,e,.15),s>0&&C.roundRect?(C.beginPath(),C.roundRect(Q,i,E-Q,n-i,s),C.stroke()):C.strokeRect(Q,i,E-Q,n-i)):s>0&&C.roundRect?(C.beginPath(),C.roundRect(Q,i,E-Q,n-i,s),C.fill()):C.fillRect(Q,i,E-Q,n-i),C.restore()}rotatedPill(g,A,I,e,t){const o=this.getLayerCtx();this.applyAperture(),o.save();const[B,C]=Mt(this.transform,[g,A]);o.translate(B,C);const Q=360-t;t&&o.rotate(Q*Math.PI/180),o.translate(-B,-C),this.pill(g,A,I,e),o.restore()}circle(g,A,I,e,t=!0){const o=rk(this.transform,I),[B,C]=Mt(this.transform,[g,A]);this.applyAperture();const Q=this.getLayerCtx();e?(Q.save(),Q.beginPath(),Q.arc(B,C,o,0,2*Math.PI),Q.clip(),this.drawMeshPattern(g-I,A-I,I*2,I*2,.15),Q.restore(),Q.beginPath(),Q.arc(B,C,o,0,2*Math.PI),Q.stroke()):(Q.beginPath(),Q.arc(B,C,o,0,2*Math.PI),Q.fill())}oval(g,A,I,e){const t=rk(this.transform,I),o=rk(this.transform,e),[B,C]=Mt(this.transform,[g,A]);this.applyAperture();const Q=this.getLayerCtx();Q.beginPath(),Q.ellipse(B,C,t,o,0,0,2*Math.PI),Q.fill(),Q.closePath()}pill(g,A,I,e){const[t,o]=Mt(this.transform,[g-I/2,A+e/2]),B=rk(this.transform,I),C=rk(this.transform,e),Q=Math.min(B,C)/2;this.applyAperture();const i=this.getLayerCtx();i.beginPath(),i.arc(t+Q,o+Q,Q,Math.PI,Math.PI*1.5),i.arc(t+B-Q,o+Q,Q,Math.PI*1.5,0),i.arc(t+B-Q,o+C-Q,Q,0,Math.PI*.5),i.arc(t+Q,o+C-Q,Q,Math.PI*.5,Math.PI),i.fill(),i.closePath()}polygon(g){if(g.length<3)return;this.applyAperture();const A=this.getLayerCtx(),I=g.map(t=>Mt(this.transform,[t.x,t.y]));A.beginPath(),A.moveTo(I[0][0],I[0][1]);for(let t=1;t<I.length;t++)A.lineTo(I[t][0],I[t][1]);A.closePath(),A.fill("evenodd");const e=rk(this.transform,this.aperture.size);e>0&&(A.lineWidth=e,A.stroke())}debugText(g,A,I){const[e,t]=Mt(this.transform,[A,I]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(g,e,t)}getLayerCtx(){const g=this.ctxLayerMap[this.aperture.layer];if(!g)throw new Error(`No context for layer "${this.aperture.layer}"`);return g}getLayerOpacity(g){if(this.xRayNetActive)return/^(top|bottom|inner\d+)$/.test(g)?this.hiddenLayerOpacity:0;const A=this.foregroundLayer,I=(A==="top"||A==="bottom")&&(g.startsWith(`${A}_`)||g.endsWith(`_${A}`)),e=["board","drill","edge_cuts","other"].includes(g);return g===A||I||e?1:this.hiddenLayerOpacity}orderAndFadeLayers(){const{canvasLayerMap:g,foregroundLayer:A}=this,e=["board",...Object.keys(g).filter(n=>/^inner\d+$/.test(n)).sort((n,s)=>Number(s.slice(5))-Number(n.slice(5))),...Ueo.filter(n=>n!=="board")],t=A==="top"?"soldermask_top":A==="bottom"?"soldermask_bottom":void 0,o=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,B=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,C=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,Q=A==="top"?"top_courtyard":A==="bottom"?"bottom_courtyard":void 0,i=[A,"edge_cuts",...t?[t]:[],...o?[o]:[],...B?[B]:[],...C?[C]:[],...Q?[Q]:[]],E=[...e.filter(n=>!i.includes(n)),...A==="drill"?[]:[A],...t?[t]:[],"edge_cuts",...o?[o]:[],...B?[B]:[],...C?[C]:[],...Q?[Q]:[],"drill"];E.forEach((n,s)=>{const r=g[n];r&&(r.style.zIndex=`${Da.topLayer-(E.length-s)}`)});for(const[n,s]of Object.entries(g)){const r=this.getLayerOpacity(n);s.style.opacity=String(r),s.style.display=r===0?"none":""}}applyAperture(){const{transform:g,aperture:A}=this;let{size:I,mode:e,color:t,fontSize:o,layer:B}=A;B in this.ctxLayerMap||(this.aperture.layer="other");const C=this.getLayerCtx();if(!C)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(t||(t="undefined"),C.lineWidth=rk(g,I),C.lineCap="round",e==="add"){C.globalCompositeOperation="source-over";let Q=qIA[t.toLowerCase()];if(!Q)try{Q=wQ(t).rgb().toString()}catch{console.warn(`Invalid color format: '${t}'`),Q="white"}C.fillStyle=Q,C.strokeStyle=Q}else C.globalCompositeOperation="destination-out",C.fillStyle="rgba(0,0,0,1)",C.strokeStyle="rgba(0,0,0,1)";C.font=`${rk(Gx(g),o)}px sans-serif`}moveTo(g,A){this.lastPoint={x:g,y:A}}lineTo(g,A){const[I,e]=Mt(this.transform,[g,A]),{size:t,shape:o,mode:B}=this.aperture,C=rk(this.transform,t),{lastPoint:Q}=this,i=Mt(this.transform,Q);this.applyAperture();const E=this.getLayerCtx();o==="square"&&E.fillRect(i.x-C/2,i.y-C/2,C,C),E.beginPath(),E.moveTo(i.x,i.y),E.lineTo(I,e),E.stroke(),E.closePath(),o==="square"&&E.fillRect(I-C/2,e-C/2,C,C),this.lastPoint={x:g,y:A}}polygonWithArcs(g){const A=this.getLayerCtx(),I=e=>{if(e.vertices.length===0)return;const t=e.vertices[0],o=Mt(this.transform,[t.x,t.y]);A.moveTo(o[0],o[1]);for(let B=0;B<e.vertices.length;B++){const C=e.vertices[B],Q=e.vertices[(B+1)%e.vertices.length];if(C.bulge&&C.bulge!==0){const i=C.bulge,E=Q.x-C.x,n=Q.y-C.y,s=Math.sqrt(E*E+n*n);if(s<1e-9){const R=Mt(this.transform,[Q.x,Q.y]);A.lineTo(R[0],R[1]);continue}const r=4*Math.atan(i),a=Math.abs(s/(2*Math.sin(r/2))),c=(C.x+Q.x)/2,h=(C.y+Q.y)/2,l=E/s,d=-(n/s),y=l,w=Math.sqrt(Math.max(0,a*a-(s/2)**2)),u=c+w*d*Math.sign(i),G=h+w*y*Math.sign(i),m=Math.atan2(C.y-G,C.x-u);let p=Math.atan2(Q.y-G,Q.x-u);i>0&&p<m?p+=2*Math.PI:i<0&&p>m&&(p-=2*Math.PI);const k=Mt(this.transform,[u,G]),S=rk(this.transform,a);A.arc(k[0],k[1],S,-m,-p,i>0)}else{const i=Mt(this.transform,[Q.x,Q.y]);A.lineTo(i[0],i[1])}}A.closePath()};if(A.beginPath(),I(g.outer_ring),g.inner_rings)for(const e of g.inner_rings)I(e);A.fill("evenodd")}},Keo=(g=2)=>{const A=Math.max(2,Math.min(10,Math.floor(g)));return["top",...Array.from({length:A-2},(I,e)=>`inner${e+1}`),"bottom"]},swA=g=>{const A=g.find(I=>I.type==="pcb_board");return Keo(A?.num_layers??2)},nIg=g=>`${g}_copper`,GSI=g=>g.map(A=>A.endsWith("_copper")?A.slice(0,-7):A),Peo=g=>["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication",...swA(g).filter(I=>I.startsWith("inner")),"drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","top_courtyard","bottom_courtyard","other"],Leo=(g,A)=>{const I=swA(g).reverse();return[...I.filter(e=>e!==A),...I.filter(e=>e===A)]},Yeo={...Kw,courtyard:{top:co.board.f_crtyd,bottom:co.board.b_crtyd}};function _eo(g){return g.type==="pcb_courtyard_circle"||g.type==="pcb_courtyard_rect"||g.type==="pcb_courtyard_outline"}function mSI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.configure({colorOverrides:Yeo}),t.realToCanvasMat=e;const o=A.filter(_eo);t.drawElements(o,{layers:I})}var beo={...Kw,silkscreen:{top:co.board.f_fab,bottom:co.board.b_fab}};function Heo(g){return g.type.startsWith("pcb_fabrication_note_")}function pSI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.configure({colorOverrides:beo}),t.realToCanvasMat=e;const o=A.filter(B=>Heo(B)&&"layer"in B&&(I.length===0||B.layer==="top"&&I.includes("top_fabrication_note")||B.layer==="bottom"&&I.includes("bottom_fabrication_note")));t.drawElements(o,{layers:I})}function veo(g){return g.type==="pcb_hole"}function qeo({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermask:t}){const o=new VE(g);o.realToCanvasMat=e;const B=A.filter(veo);o.drawElements(B,{layers:I,drawSoldermask:t})}function Teo(g){return g.type==="pcb_board"}function kSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermask:t}){const o=new VE(g);o.realToCanvasMat=e;const B=A.filter(Teo);for(const C of B)o.drawElements([C],{layers:I,drawSoldermask:!1,drawBoardMaterial:t??!1,minBoardOutlineStrokePx:2})}function Zeo(g){return g.type==="pcb_copper_text"}function Oeo({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=A.filter(Zeo);if(t.length===0)return;const o=new VE(g);o.realToCanvasMat=e,o.drawElements(t,{layers:I})}function Weo(g){return g.type==="pcb_cutout"}function Veo({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.realToCanvasMat=e;const o=A.filter(Weo);t.drawElements(o,{layers:I})}function jeo(g){return g.type==="pcb_keepout"}function zeo({elements:g,layer:A}){return g.filter(jeo).filter(I=>I.layers.includes(A))}function Xeo(g){return wQ(qIA[g]).lighten(.4).hex()}function $eo({canvas:g,elements:A,layer:I,realToCanvasMat:e}){const t=zeo({elements:A,layer:I});if(t.length===0)return;const o=new VE(g),B=Xeo(I);o.configure({colorOverrides:{keepout:{top:B,bottom:B}}}),o.realToCanvasMat=e,o.drawElements(t,{layers:[nIg(I)]})}function Ato(g){return g.type.startsWith("pcb_note_")}function MSI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.realToCanvasMat=e;const o=A.filter(Ato);t.drawElements(o,{layers:I})}function gto(g){return g.type==="pcb_panel"}function Ito({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermask:t}){const o=new VE(g);o.realToCanvasMat=e;const B=A.filter(gto);for(const C of B)o.drawElements([C],{layers:I})}var eto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()}};function tto(g){return g.type==="pcb_smtpad"}function SSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,drawSoldermask:o}){const B=new Set(GSI(I)),C=A.filter(tto).filter(n=>B.has(n.layer));if(C.length===0)return;const Q=new Set;if(t)for(const n of t)(n.is_mouse_over||n.is_in_highlighted_net)&&n._element?.type==="pcb_smtpad"&&Q.add(n._element.pcb_smtpad_id);const i=C.filter(n=>Q.has(n.pcb_smtpad_id)),E=C.filter(n=>!Q.has(n.pcb_smtpad_id));if(E.length>0){const n=new VE(g);n.realToCanvasMat=e,n.drawElements(E,{layers:I,drawSoldermask:o})}if(i.length>0){const n=new VE(g);n.configure({colorOverrides:eto}),n.realToCanvasMat=e,n.drawElements(i,{layers:I,drawSoldermask:o})}}var oto={...Kw,copper:Object.fromEntries(Object.entries(Kw.copper).map(([g,A])=>[g,wQ(A).lighten(.5).toString()]))};function Bto(g){return g.type==="pcb_trace"}var Cto=(g,A)=>{const I=g.route.filter(o=>o.route_type==="wire"&&"layer"in o&&A.has(o.layer)?!0:o.route_type==="via"?A.has(o.from_layer)||A.has(o.to_layer):!1),e=I.filter(o=>o.route_type==="wire").length,t=I.some(o=>o.route_type==="via");return e<2&&!t?null:{...g,route:I}},Qto=g=>({...g,route:g.route.map(A=>!("is_inside_copper_pour"in A)||A.is_inside_copper_pour!==!0?A:{...A,is_inside_copper_pour:!1})}),ito=(g,A)=>A?g:g.filter(I=>I.type!=="pcb_copper_pour"),Eto=({primitives:g})=>{const A=new Set;for(const I of g)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_trace"&&A.add(I._element.pcb_trace_id);return A};function fSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,showCopperPours:o}){const B=new Set(GSI(I)),C=A.filter(Bto).map(s=>Cto(s,B)).filter(s=>s!==null).map(s=>o?s:Qto(s));if(C.length===0)return;const Q=Eto({primitives:t??[]}),i=[],E=[];for(const s of C)Q.has(s.pcb_trace_id)?i.push(s):E.push(s);const n=ito(A,o);if(E.length>0){const s=new VE(g);s.realToCanvasMat=e,s.drawElements(E,{layers:I,clipContextElements:n})}if(i.length>0){const s=new VE(g);s.configure({colorOverrides:oto}),s.realToCanvasMat=e,s.drawElements(i,{layers:I,clipContextElements:n})}}var nto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()}};function sto(g){return g.type==="pcb_plated_hole"}function RSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,drawSoldermask:o}){const B=A.filter(sto);if(B.length===0)return;const C=new Set;if(t)for(const E of t)(E.is_mouse_over||E.is_in_highlighted_net)&&E._element?.type==="pcb_plated_hole"&&C.add(E._element.pcb_plated_hole_id);const Q=B.filter(E=>C.has(E.pcb_plated_hole_id)),i=B.filter(E=>!C.has(E.pcb_plated_hole_id));if(i.length>0){const E=new VE(g);E.realToCanvasMat=e,E.drawElements(i,{layers:I,drawSoldermask:o})}if(Q.length>0){const E=new VE(g);E.configure({colorOverrides:nto}),E.realToCanvasMat=e,E.drawElements(Q,{layers:I,drawSoldermask:o})}}function NSI(g){const{lines:A,anchorPoint:I,ccwRotation:e}=g;if(!e)return A;const t=e*Math.PI/180,o=ekI(t),B=Yw(vc(I.x,I.y),o,vc(-I.x,-I.y));return Mt(B,I),A.map(C=>({...C,x1:Mt(B,{x:C.x1,y:C.y1}).x,y1:Mt(B,{x:C.x1,y:C.y1}).y,x2:Mt(B,{x:C.x2,y:C.y2}).x,y2:Mt(B,{x:C.x2,y:C.y2}).y}))}var ato=.6,xSI=.2,FSI=g=>{const A=g.size*.7,I=A*ato,e=A*xSI,t=A*xSI,o=g.text.split(/\r?\n/),B=g.text.length>0&&A>0,C=B?o.length:0,Q=B?o.map(n=>n.length===0?0:n.length*I+(n.length-1)*e):[],i=Q.length>0?Math.max(...Q):0,E=C>0?C*A+(C-1)*t:0;return{text_lines:o,line_count:C,line_widths:Q,target_height:A,target_width_char:I,space_between_chars:e,space_between_lines:t,width:i,height:E}},USI=g=>{const A=FSI(g);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},JSI=g=>{const{text_lines:A,line_count:I,line_widths:e,target_height:t,target_width_char:o,space_between_chars:B,space_between_lines:C,width:Q}=FSI(g);if(t<=0||I===0)return[];const i=t/12,E=[];for(let n=0;n<I;n++){const s=-n*(t+C),r=e[n],a=(Q-r)/2;let c=g.x+a;for(let h=0;h<A[n].length;h++){const l=A[n][h],D=NF[l]??NF[l.toUpperCase()];if(!D){c+=o+B;continue}for(const{x1:d,y1:y,x2:w,y2:u}of D)E.push({_pcb_drawing_object_id:MR("line"),pcb_drawing_type:"line",x1:c+o*d,y1:g.y+s+t*y,x2:c+o*w,y2:g.y+s+t*u,width:i,layer:g.layer,unit:g.unit,color:g.color});c+=o+B}}return E};function Rx(g){const I=g.color??qIA[g.layer];let e=wQ(I);return g._element?.type==="pcb_copper_pour"&&(e=e.alpha(.7)),g.is_mouse_over||g.is_in_highlighted_net?e.lighten(.5).rgb().toString():e.rgb().toString()}var KSI=(g,A)=>{g.equip({size:A.zoomIndependent?A.width/g.transform.a:A.width,shape:A.squareCap?"square":"circle",color:Rx(A),layer:A.layer}),g.moveTo(A.x1,A.y1),g.lineTo(A.x2,A.y2)},rto=(g,A,I)=>{switch(I){case"top_left":return{x:0,y:-A};case"top_center":return{x:-g/2,y:-A};case"top_right":return{x:-g,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-g/2,y:-A/2};case"center_right":return{x:-g,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-g/2,y:0};case"bottom_right":return{x:-g,y:0};default:return{x:0,y:0}}},PSI=g=>g.layer==="bottom_silkscreen"||g.layer==="bottom"?g.is_mirrored!==!1:g.is_mirrored===!0,cto=(g,A)=>{g.equip({fontSize:A.size,color:Rx(A),layer:A.layer});const{width:I,height:e}=USI(A),t=rto(I,e,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let B=JSI({...A,x:A.x+t.x,y:A.y+t.y});if(PSI(A)&&(B=B.map(C=>({...C,x1:2*A.x-C.x1,x2:2*A.x-C.x2}))),A.ccw_rotation){const C={lines:B,anchorPoint:o,ccwRotation:A.ccw_rotation};B=NSI(C)}for(const C of B)KSI(g,C)},hto=(g,A)=>{const{width:I,height:e,lineHeight:t}=USI(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},B=I+o.left+o.right,C=e+o.top+o.bottom,Q=I/2,i=t-e/2,E=A.x-Q,n=A.y-i,s={x:A.x,y:A.y},r={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:B,h:C,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?YSI(g,r):LSI(g,r);let a=JSI({...A,x:E,y:n});if(PSI(A)&&(a=a.map(c=>({...c,x1:2*A.x-c.x1,x2:2*A.x-c.x2}))),A.ccw_rotation){const c={lines:a,anchorPoint:s,ccwRotation:A.ccw_rotation};a=NSI(c)}for(const c of a)g.equip({size:c.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),g.moveTo(c.x1,c.y1),g.lineTo(c.x2,c.y2);g.equip({mode:"add"})},LSI=(g,A)=>{g.equip({color:Rx(A),layer:A.layer,size:A.stroke_width}),g.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},YSI=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},lto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},Dto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.circle(A.x,A.y,A.r,A.mesh_fill)},dto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.oval(A.x,A.y,A.rX,A.rY)},yto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.pill(A.x,A.y,A.w,A.h)},wto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.polygon(A.points)},uto=(g,A)=>{g.equip({color:Rx(A),layer:A.layer}),g.polygonWithArcs(A.brep_shape)},Gto=(g,A)=>{switch(A.pcb_drawing_type){case"line":return KSI(g,A);case"text":return A.is_knockout?hto(g,A):cto(g,A);case"rect":return A.ccw_rotation?YSI(g,A):LSI(g,A);case"circle":return Dto(g,A);case"oval":return dto(g,A);case"pill":return A.ccw_rotation?lto(g,A):yto(g,A);case"polygon":return wto(g,A);case"polygon_with_arcs":return uto(g,A)}},mto=(g,A)=>{for(const I of A)Gto(g,I)},pto={...Kw,silkscreen:{top:co.board.f_silks,bottom:co.board.b_silks}};function kto(g){return g.type.includes("pcb_silkscreen")}function _SI({canvas:g,elements:A,layers:I,realToCanvasMat:e}){const t=new VE(g);t.configure({colorOverrides:pto}),t.realToCanvasMat=e;const o=A.filter(kto);t.drawElements(o,{layers:I})}var Mto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()},soldermask:{...Kw.soldermask,top:wQ(co.board.soldermask.top).lighten(.35).toString(),bottom:wQ(co.board.soldermask.bottom).lighten(.35).toString()}};function bSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,drawSoldermaskTop:t,drawSoldermaskBottom:o,primitives:B}){const C=new VE(g);C.realToCanvasMat=e;const Q=A.filter(s=>s.type==="pcb_board");if(C.drawElements(A,{layers:I,drawSoldermask:!0,drawSoldermaskTop:t,drawSoldermaskBottom:o,drawBoardMaterial:!1}),Q.length>1&&kSI({canvas:g,elements:Q,layers:[],realToCanvasMat:e,drawSoldermask:!1}),!B)return;const i=new Set;for(const s of B){if(!(s.is_mouse_over||s.is_in_highlighted_net))continue;const r=s._element;r?.type==="pcb_smtpad"?i.add(r.pcb_smtpad_id):r?.type==="pcb_plated_hole"?i.add(r.pcb_plated_hole_id):r?.type==="pcb_via"&&i.add(r.pcb_via_id)}if(i.size===0)return;const E=A.filter(s=>s.type==="pcb_smtpad"?i.has(s.pcb_smtpad_id):s.type==="pcb_plated_hole"?i.has(s.pcb_plated_hole_id):s.type==="pcb_via"?i.has(s.pcb_via_id):!1);if(E.length===0)return;const n=new VE(g);n.configure({colorOverrides:Mto}),n.realToCanvasMat=e,n.drawElements(E,{layers:I,clipContextElements:A,drawSoldermask:!0,drawSoldermaskTop:t,drawSoldermaskBottom:o,drawBoardMaterial:!1})}var Sto={...Kw,copper:{...Kw.copper,top:wQ(co.board.pad_front).lighten(.5).toString(),bottom:wQ(co.board.pad_back).lighten(.5).toString(),inner1:wQ(co.board.copper.in1).lighten(.5).toString(),inner2:wQ(co.board.copper.in2).lighten(.5).toString(),inner3:wQ(co.board.copper.in3).lighten(.5).toString(),inner4:wQ(co.board.copper.in4).lighten(.5).toString(),inner5:wQ(co.board.copper.in5).lighten(.5).toString(),inner6:wQ(co.board.copper.in6).lighten(.5).toString(),inner7:wQ(co.board.copper.in7).lighten(.5).toString(),inner8:wQ(co.board.copper.in8).lighten(.5).toString()}};function fto(g){return g.type==="pcb_via"}function HSI({canvas:g,elements:A,layers:I,realToCanvasMat:e,primitives:t,drawSoldermask:o}){const B=A.filter(fto).filter(E=>I.some(n=>n.includes("copper")));if(B.length===0)return;const C=new Set;if(t)for(const E of t)(E.is_mouse_over||E.is_in_highlighted_net)&&E._element?.type==="pcb_via"&&C.add(E._element.pcb_via_id);const Q=B.filter(E=>C.has(E.pcb_via_id)),i=B.filter(E=>!C.has(E.pcb_via_id));if(i.length>0){const E=new VE(g);E.realToCanvasMat=e,E.drawElements(i,{layers:I,drawSoldermask:o,drawSoldermaskTop:I.includes("top_copper"),drawSoldermaskBottom:I.includes("bottom_copper"),clipContextElements:A})}if(Q.length>0){const E=new VE(g);E.configure({colorOverrides:Sto}),E.realToCanvasMat=e,E.drawElements(Q,{layers:I,drawSoldermask:o,drawSoldermaskTop:I.includes("top_copper"),drawSoldermaskBottom:I.includes("bottom_copper"),clipContextElements:A})}}var Rto=({primitives:g,isShowingSolderMask:A,isShowingSilkscreen:I,isShowingFabricationNotes:e})=>g.filter(t=>A||!t.layer?.includes("soldermask")).filter(t=>I||!t.layer?.includes("silkscreen")).filter(t=>e||!t.layer?.includes("fabrication")).filter(t=>t.layer!=="board").filter(t=>t._element?.type!=="pcb_smtpad").filter(t=>t._element?.type!=="pcb_plated_hole"||t.layer==="drill").filter(t=>t._element?.type!=="pcb_via").filter(t=>t._element?.type!=="pcb_trace").filter(t=>t._element?.type!=="pcb_copper_text"),Nto=({primitives:g,elements:A,circuitJson:I,xRayElements:e,transform:t,grid:o,width:B=500,height:C=500,onRenderComplete:Q})=>{const i=gA.useRef(null),E=gA.useRef({}),n=gA.useRef(Q),s=gA.useRef(void 0),r=Qi(u=>u.hidden_layer_opacity),a=Qi(u=>u.selected_layer),c=Qi(u=>u.copper_pour_opacity),h=Qi(u=>u.is_showing_copper_pours),l=Qi(u=>u.is_showing_solder_mask),D=Qi(u=>u.is_showing_fabrication_notes),d=Qi(u=>u.is_showing_pcb_notes),y=Qi(u=>u.is_showing_courtyards),w=Qi(u=>u.is_showing_silkscreen);return gA.useEffect(()=>{n.current=Q},[Q]),gA.useEffect(()=>{if(!E.current||Object.keys(E.current).length===0)return;const u=Object.fromEntries(Object.entries(E.current).filter(([S,R])=>!!R));if(Object.keys(u).length===0)return;const G=new Jeo(u);t&&(G.transform=t),G.clear(),G.foregroundLayer=a,G.hiddenLayerOpacity=r,G.xRayNetActive=!!e;const m=Object.fromEntries(Object.entries(u).filter(([S])=>G.getLayerOpacity(S)>0)),p=Rto({primitives:g,isShowingSolderMask:l,isShowingSilkscreen:w,isShowingFabricationNotes:D});if(mto(G,p.filter(S=>G.getLayerOpacity(S.layer??"other")>0)),t){const S=swA(A).map(U=>({canvas:m[U],layer:U,copperLayer:nIg(U)}));for(const{canvas:U,copperLayer:L}of S)U&&fSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,showCopperPours:h&&c>0});for(const{canvas:U,copperLayer:L}of S)U&&Oeo({canvas:U,elements:A,layers:[L],realToCanvasMat:t});for(const{canvas:U,copperLayer:L,layer:b}of S)U&&RSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,drawSoldermask:l&&(b==="top"||b==="bottom")});for(const{canvas:U,copperLayer:L}of S)U&&QSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,opacity:h?c:0});for(const{canvas:U,copperLayer:L}of S)U&&SSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,drawSoldermask:l});for(const{canvas:U,copperLayer:L,layer:b}of S)U&&HSI({canvas:U,elements:A,layers:[L],realToCanvasMat:t,primitives:g,drawSoldermask:l&&(b==="top"||b==="bottom")});if(l){const U=a==="bottom"?"bottom":"top",L=U==="top",b=U==="bottom",H=m.soldermask_top;H&&U==="top"&&bSI({canvas:H,elements:A,layers:["top_soldermask"],realToCanvasMat:t,drawSoldermaskTop:L,drawSoldermaskBottom:b,primitives:g});const q=m.soldermask_bottom;q&&U==="bottom"&&bSI({canvas:q,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,drawSoldermaskTop:L,drawSoldermaskBottom:b,primitives:g})}const R=m.drill;if(R&&qeo({canvas:R,elements:A,layers:["drill"],realToCanvasMat:t}),w){const U=m.top_silkscreen;U&&_SI({canvas:U,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const L=m.bottom_silkscreen;L&&_SI({canvas:L,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t})}if(D){const U=m.top_fabrication;U&&pSI({canvas:U,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const L=m.bottom_fabrication;L&&pSI({canvas:L,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t})}if(d){const U=m.bottom_notes;U&&MSI({canvas:U,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const L=m.top_notes;L&&MSI({canvas:L,elements:A,layers:["top_user_note"],realToCanvasMat:t})}if(y){const U=m.top_courtyard;U&&mSI({canvas:U,elements:A,layers:["top_courtyard"],realToCanvasMat:t});const L=m.bottom_courtyard;L&&mSI({canvas:L,elements:A,layers:["bottom_courtyard"],realToCanvasMat:t})}const F=m.board;F&&(Ito({canvas:F,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:l}),kSI({canvas:F,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:l}));const N=m.edge_cuts;N&&Veo({canvas:N,elements:A,layers:["edge_cuts"],realToCanvasMat:t});for(const{canvas:U,layer:L}of S)U&&$eo({canvas:U,elements:A,layer:L,realToCanvasMat:t})}G.orderAndFadeLayers();const k=i.current;if(k&&t&&e){k.getContext("2d").clearRect(0,0,B,C);for(const R of Leo(A,a)){const F={canvas:k,elements:e,layers:[nIg(R)],realToCanvasMat:t,drawSoldermask:!1};h&&QSI({...F,opacity:c}),fSI({...F,showCopperPours:!1}),SSI(F),RSI(F),HSI(F)}const S=new VE(k);S.realToCanvasMat=t,S.drawElements(e.filter(R=>R.type==="pcb_via"||R.type==="pcb_plated_hole"),{layers:["drill"],drawSoldermask:!1})}s.current!==I&&(s.current=I,n.current?.())},[g,A,I,e,B,C,t,a,r,c,h,l,D,d,y,w]),W.jsxs("div",{style:{backgroundColor:"black",width:B,height:C,position:"relative"},children:[W.jsx(d5.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:B,height:C,transform:t,stringifyCoord:(u,G,m)=>`${d5.toMMSI(u,m)}, ${d5.toMMSI(G,m)}`}),e&&W.jsx("canvas",{ref:i,className:"pcb-x-ray-net",width:B,height:C,style:{position:"absolute",left:0,top:0,zIndex:Da.topLayer,pointerEvents:"none"}}),Peo(A).filter(u=>!(!l&&u.includes("soldermask")||!w&&u.includes("silkscreen"))).map(u=>u.replace(/-/g,"")).map((u,G)=>W.jsx("canvas",{className:`pcb-layer-${u}`,ref:m=>{E.current??={},m?E.current[u]=m:delete E.current[u]},style:{position:"absolute",zIndex:G,left:0,top:0,pointerEvents:"none"},width:B,height:C},u))]})};new TextEncoder,(()=>{const g=new Uint8Array(4),A=new Uint32Array(g.buffer);return!((A[0]=1)&g[0])})();var xto=new Uint16Array([255]),Fto=new Uint8Array(xto.buffer);Fto[0];var Uto=new Uint16Array([255]),Jto=new Uint8Array(Uto.buffer);Jto[0],new TextDecoder("latin1");var k3=1e-9,awA=(g,A,I)=>g>=A-k3&&g<=I+k3,Kto=g=>{const A=[];for(const I of g)A.some(e=>Math.abs(e.x-I.x)<k3&&Math.abs(e.y-I.y)<k3)||A.push(I);return A};function Pto(g,A){const{origin:I,directionVector:e}=g;if(Math.abs(e.x)<k3&&Math.abs(e.y)<k3)return null;const t=[];if(Math.abs(e.x)>=k3){const i=(A.minX-I.x)/e.x,E=I.y+i*e.y;awA(E,A.minY,A.maxY)&&t.push({x:A.minX,y:E});const n=(A.maxX-I.x)/e.x,s=I.y+n*e.y;awA(s,A.minY,A.maxY)&&t.push({x:A.maxX,y:s})}if(Math.abs(e.y)>=k3){const i=(A.minY-I.y)/e.y,E=I.x+i*e.x;awA(E,A.minX,A.maxX)&&t.push({x:E,y:A.minY});const n=(A.maxY-I.y)/e.y,s=I.x+n*e.x;awA(s,A.minX,A.maxX)&&t.push({x:s,y:A.maxY})}const o=Kto(t);if(o.length<2)return null;let B=o[0],C=o[1],Q=(B.x-C.x)**2+(B.y-C.y)**2;for(let i=0;i<o.length;i++)for(let E=i+1;E<o.length;E++){const n=o[i],s=o[E],r=(n.x-s.x)**2+(n.y-s.y)**2;r>Q&&(B=n,C=s,Q=r)}return[B,C]}function Lto(g,A,I){const e=Gx(g),t=[Mt(e,{x:0,y:0}),Mt(e,{x:A,y:0}),Mt(e,{x:0,y:I}),Mt(e,{x:A,y:I})];return{minX:Math.min(...t.map(o=>o.x)),maxX:Math.max(...t.map(o=>o.x)),minY:Math.min(...t.map(o=>o.y)),maxY:Math.max(...t.map(o=>o.y))}}var Yto=.6,_to=1,vSI=(g,A)=>Math.hypot(g.x-A.x,g.y-A.y),qSI=g=>(g.ccwRotationDegrees??0)*Math.PI/180,bto=g=>g.a*g.d-g.b*g.c<0?1:-1,Hto=(g,A)=>qSI(g)*bto(A),vto=(g,A)=>{const I=Math.cos(A),e=Math.sin(A);return{x:g.x*I-g.y*e,y:g.x*e+g.y*I}},qto=g=>TSI(g,qSI(g)),Tto=(g,A)=>TSI(g,Hto(g,A)),TSI=(g,A)=>{const I=g.width/2,e=g.height/2;return[{x:-I,y:-e},{x:I,y:-e},{x:I,y:e},{x:-I,y:e}].map(t=>{const o=vto(t,A);return{x:g.center.x+o.x,y:g.center.y+o.y}})},Zto=(g,A)=>{const I=Tto(g,A).map(i=>Mt(A,i)),e=Mt(A,g.center),t=vSI(I[0],I[1]),o=vSI(I[1],I[2]),B=I.length>=2?Math.atan2(I[1].y-I[0].y,I[1].x-I[0].x):0,C=B*180/Math.PI,Q=I.reduce((i,E)=>({minX:Math.min(i.minX,E.x),maxX:Math.max(i.maxX,E.x),minY:Math.min(i.minY,E.y),maxY:Math.max(i.maxY,E.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0});return{center:e,corners:I,width:t,height:o,angleRadians:B,angleDegrees:C,bounds:Q}},Oto=2,Wto=12,Vto=12,rwA=g=>({tip:{...g},base:{...g},leftWing:{...g},rightWing:{...g}}),ZSI=(g,A,I)=>{const e=g.x-A.x,t=g.y-A.y,o=Math.hypot(e,t);if(o===0)return rwA(g);const B=e/o,Q=-(t/o)*(I/2),i=B*(I/2);return{tip:{...g},base:{...A},leftWing:{x:A.x+Q,y:A.y+i},rightWing:{x:A.x-Q,y:A.y-i}}};function OSI(g){const{start:A,end:I}=g,e=I.x-A.x,t=I.y-A.y,o=Math.hypot(e,t),B=Oto,C=Wto;if(o===0){const D=g.doubleSided?[rwA(A),rwA(A)]:[rwA(A)];return{shaftStart:{...A},shaftEnd:{...A},heads:D,shaftWidth:B,headLength:0,headWidth:C,length:o}}const Q=e/o,i=t/o,E=Math.min(Vto,o*.5),n=Math.max(E,B*2),s=g.doubleSided?o/2:o,r=Math.min(n,s),a={x:I.x-Q*r,y:I.y-i*r},c=[ZSI(I,a,C)];let h={...A};const l={...a};if(g.doubleSided){const D={x:A.x+Q*r,y:A.y+i*r};c.unshift(ZSI(A,D,C)),h=D}return{shaftStart:h,shaftEnd:l,heads:c,shaftWidth:B,headLength:r,headWidth:C,length:o}}function jto(g){const A=OSI(g);return[A.shaftStart,A.shaftEnd,...A.heads.flatMap(e=>[e.tip,e.base,e.leftWing,e.rightWing])].reduce((e,t)=>({minX:Math.min(e.minX,t.x),maxX:Math.max(e.maxX,t.x),minY:Math.min(e.minY,t.y),maxY:Math.max(e.maxY,t.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function WSI(g,A,{fontSize:I=12,strokeWidth:e=2,normalPadding:t=6,alongOffset:o=0}={}){const B={x:(g.x+A.x)/2,y:(g.y+A.y)/2},C=A.x-g.x,Q=A.y-g.y,i=Math.hypot(C,Q);if(i===0)return{x:B.x+o,y:B.y-(e/2+I*.65+t),angleRadians:0,angleDegrees:0,direction:{x:1,y:0},normal:{x:0,y:-1}};let E=C/i,n=Q/i,s=-n,r=E;(E<0||E===0&&n<0)&&(E=-E,n=-n,s=-s,r=-r);const c=Math.atan2(n,E),h=e/2+I*.65+t;return{x:B.x+s*h+E*o,y:B.y+r*h+n*o,angleRadians:c,angleDegrees:c*180/Math.PI,direction:{x:E,y:n},normal:{x:s,y:r}}}var M3=["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 VSI(g,A,I,e={}){const t=e.padding??40,o=e.yFlip??!1;let B;if("center"in g){const E=g.width/2,n=g.height/2;B={minX:g.center.x-E,maxX:g.center.x+E,minY:g.center.y-n,maxY:g.center.y+n}}else B=g;const C=B.maxX-B.minX||1,Q=B.maxY-B.minY||1,i=Math.min((A-2*t)/C,(I-2*t)/Q);return Yw(vc(A/2,I/2),rJ(i,o?-i:i),vc(-(B.minX+C/2),-(B.minY+Q/2)))}function zto(g){const A=[...g.points||[],...(g.lines||[]).flatMap(I=>I.points),...(g.polygons||[]).flatMap(I=>I.points),...(g.rects||[]).flatMap(I=>qto(I)),...(g.circles||[]).flatMap(I=>[{x:I.center.x-I.radius,y:I.center.y},{x:I.center.x+I.radius,y:I.center.y},{x:I.center.x,y:I.center.y-I.radius},{x:I.center.x,y:I.center.y+I.radius}]),...(g.arrows||[]).flatMap(I=>{const e=jto(I);return[{x:e.minX,y:e.minY},{x:e.maxX,y:e.maxY}]}),...(g.texts||[]).flatMap(I=>{const e=I.fontSize??12,t=I.text.length*e*Yto,o=e*_to,B=I.anchorSide??"center",C={top_left:{dx:0,dy:0},top_center:{dx:-t/2,dy:0},top_right:{dx:-t,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-t/2,dy:-o/2},center_right:{dx:-t,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-t/2,dy:-o},bottom_right:{dx:-t,dy:-o}},{dx:Q,dy:i}=C[B],E=I.x+Q,n=I.y+i;return[{x:E,y:n},{x:E+t,y:n+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((I,e)=>({minX:Math.min(I.minX,e.x),maxX:Math.max(I.maxX,e.x),minY:Math.min(I.minY,e.y),maxY:Math.max(I.maxY,e.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function Xto(g,A,I={}){const e=I.disableLabels!==!1,t=I.hideInlineLabels??e,o=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!o)throw new Error("Could not get 2D context from canvas");const B=A instanceof HTMLCanvasElement?A.width:A.canvas.width,C=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let Q;if(I.transform)Q=I.transform;else if(I.viewbox)Q=VSI(I.viewbox,B,C,{padding:I.padding,yFlip:I.yFlip});else{const i=zto(g),E=g.coordinateSystem==="cartesian";Q=VSI(i,B,C,{padding:I.padding??40,yFlip:E})}if(o.clearRect(0,0,B,C),o.save(),g.rects&&g.rects.length>0&&g.rects.forEach(i=>{const E=Zto(i,Q);o.save(),o.translate(E.center.x,E.center.y),Math.abs(E.angleRadians)>1e-6&&o.rotate(E.angleRadians),o.beginPath(),o.rect(-E.width/2,-E.height/2,E.width,E.height),i.fill&&(o.fillStyle=i.fill,o.fill()),i.stroke&&(o.strokeStyle=i.stroke,o.stroke()),o.restore()}),g.circles&&g.circles.length>0&&g.circles.forEach(i=>{const E=Mt(Q,i.center),n=i.radius*Math.abs(Q.a);o.beginPath(),o.arc(E.x,E.y,n,0,2*Math.PI),i.fill&&(o.fillStyle=i.fill,o.fill()),i.stroke&&(o.strokeStyle=i.stroke??"transparent",o.stroke())}),g.polygons&&g.polygons.length>0&&g.polygons.forEach(i=>{if(i.points.length===0)return;const E=i.points.map(n=>Mt(Q,n));o.beginPath(),o.moveTo(E[0].x,E[0].y);for(let n=1;n<E.length;n++)o.lineTo(E[n].x,E[n].y);o.closePath(),i.fill&&(o.fillStyle=i.fill,o.fill()),i.stroke&&(o.strokeStyle=i.stroke,i.strokeWidth!==void 0&&(o.lineWidth=i.strokeWidth*Math.abs(Q.a)),o.stroke())}),g.arrows&&g.arrows.length>0&&g.arrows.forEach((i,E)=>{const n=OSI(i),s=Mt(Q,n.shaftStart),r=Mt(Q,n.shaftEnd),a=i.color||M3[E%M3.length],c=Math.hypot(Q.a,Q.b);o.strokeStyle=a,o.fillStyle=a,o.lineWidth=n.shaftWidth*(c||1),o.lineCap="round",o.setLineDash([]),o.beginPath(),o.moveTo(s.x,s.y),o.lineTo(r.x,r.y),o.stroke(),n.heads.forEach(w=>{const u=Mt(Q,w.tip),G=Mt(Q,w.leftWing),m=Mt(Q,w.rightWing);o.beginPath(),o.moveTo(u.x,u.y),o.lineTo(G.x,G.y),o.lineTo(m.x,m.y),o.closePath(),o.fill()});const h=12,l=n.shaftWidth*(c||1),D=h*.6,d=WSI(s,r,{fontSize:h,strokeWidth:l,normalPadding:6,alongOffset:i.label?D:0}),y=WSI(s,r,{fontSize:h,strokeWidth:l,normalPadding:12,alongOffset:i.inlineLabel?-D:0});if(o.fillStyle=a,o.font=`${h}px sans-serif`,!e&&i.label){const w=y.x,u=y.y;o.save(),o.textAlign="center",o.textBaseline="middle",o.fillText(i.label,w,u),o.restore()}!t&&i.inlineLabel&&(o.save(),o.translate(d.x,d.y),o.rotate(d.angleRadians),o.textAlign="center",o.textBaseline="middle",o.fillText(i.inlineLabel,0,0),o.restore())}),g.lines&&g.lines.length>0&&g.lines.map((i,E)=>({line:i,originalIndex:E})).sort((i,E)=>(i.line.zIndex??0)-(E.line.zIndex??0)||i.originalIndex-E.originalIndex).forEach(({line:i,originalIndex:E})=>{if(i.points.length===0)return;o.beginPath();const n=Mt(Q,i.points[0]);o.moveTo(n.x,n.y);for(let s=1;s<i.points.length;s++){const r=Mt(Q,i.points[s]);o.lineTo(r.x,r.y)}if(o.strokeStyle=i.strokeColor||M3[E%M3.length],i.strokeWidth?o.lineWidth=i.strokeWidth*Q.a:o.lineWidth=2,o.lineCap="round",i.strokeDash)if(typeof i.strokeDash=="string"){let s;if(i.strokeDash.includes(","))s=i.strokeDash.split(",").map(r=>parseFloat(r.trim())).filter(r=>!Number.isNaN(r));else{const r=parseFloat(i.strokeDash.trim());s=Number.isNaN(r)?[]:[r]}o.setLineDash(s)}else o.setLineDash(i.strokeDash.map(s=>s*Math.abs(Q.a)));else o.setLineDash([]);o.stroke()}),g.infiniteLines&&g.infiniteLines.length>0){const i=Lto(Q,B,C);g.infiniteLines.forEach((E,n)=>{const s=Pto(E,i);if(!s)return;const[r,a]=s,c=Mt(Q,r),h=Mt(Q,a);if(o.beginPath(),o.moveTo(c.x,c.y),o.lineTo(h.x,h.y),o.strokeStyle=E.strokeColor||M3[n%M3.length],o.lineWidth=E.strokeWidth?E.strokeWidth*Math.abs(Q.a):2,o.lineCap="round",E.strokeDash)if(typeof E.strokeDash=="string"){let l;if(E.strokeDash.includes(","))l=E.strokeDash.split(",").map(D=>parseFloat(D.trim())).filter(D=>!Number.isNaN(D));else{const D=parseFloat(E.strokeDash.trim());l=Number.isNaN(D)?[]:[D]}o.setLineDash(l)}else o.setLineDash(E.strokeDash.map(l=>l*Math.abs(Q.a)));else o.setLineDash([]);o.stroke()})}g.texts&&g.texts.length>0&&g.texts.forEach(i=>{const E=Mt(Q,{x:i.x,y:i.y});o.fillStyle=i.color||"black",o.font=`${(i.fontSize??12)*Math.abs(Q.a)}px sans-serif`;const n=i.anchorSide??"center",s={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"},r={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};o.textAlign=s[n],o.textBaseline=r[n],o.fillText(i.text,E.x,E.y)}),g.points&&g.points.length>0&&g.points.forEach((i,E)=>{const n=Mt(Q,i);o.beginPath(),o.arc(n.x,n.y,3,0,2*Math.PI),o.fillStyle=i.color||M3[E%M3.length],o.fill(),i.label&&!e&&(o.fillStyle=i.color||"black",o.font="12px sans-serif",o.fillText(i.label,n.x+5,n.y-5))}),o.restore()}XkI(YAo(),1);var $to=({children:g,transform:A,debugGraphics:I})=>{const e=gA.useRef(null),[t,{width:o,height:B}]=HIA(),C=Qi(Q=>Q.is_showing_autorouting);return gA.useEffect(()=>{C&&e.current&&I&&o&&B&&(e.current.width=o,e.current.height=B,Xto(I,e.current,{transform:A,disableLabels:!0}))},[I,A,o,B,C]),C?W.jsxs("div",{ref:t,style:{position:"relative",width:"100%",height:"100%"},children:[g,W.jsx("canvas",{ref:e,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):g};function Aoo(g){const{dimensionStart:A,dimensionEnd:I,screenDimensionStart:e,screenDimensionEnd:t,flipX:o,flipY:B}=g,C=I.x-A.x,Q=I.y-A.y,i=Math.sqrt(C*C+Q*Q),E=t.x-e.x,n=t.y-e.y,s=Math.sqrt(E*E+n*n),r=Math.atan2(n,E)*(180/Math.PI),a=Math.abs(r)%90,h=Math.min(a,90-a)>15,l=(e.x+t.x)/2,D=(e.y+t.y)/2,d=15,y=r+90;let w=Math.cos(y*Math.PI/180)*d,u=Math.sin(y*Math.PI/180)*d;const G=E>0&&n<0,m=E>0&&n>0,p=E<0&&n>0;o!==B&&!G&&(w=-w,u=-u),G&&(w+=Math.cos(y*Math.PI/180)*-45,u+=Math.sin(y*Math.PI/180)*-45),m&&(w+=Math.cos(y*Math.PI/180)+-20,u+=Math.sin(y*Math.PI/180)+-10),p&&(w+=Math.cos(y*Math.PI/180)*10,u+=Math.sin(y*Math.PI/180)*10);const k=l+w,S=D+u;return{distance:i,screenDistance:s,x:k,y:S,show:i>.01&&s>30&&h}}function goo(g){const{dimensionStart:A,dimensionEnd:I,screenDimensionStart:e,screenDimensionEnd:t,flipX:o,flipY:B}=g;return gA.useMemo(()=>Aoo({dimensionStart:A,dimensionEnd:I,screenDimensionStart:e,screenDimensionEnd:t,flipX:o,flipY:B}),[A,I,e,t,o,B])}var Ioo=(g,A,I)=>{const e=I*Math.PI/180,t=Math.cos(e),o=Math.sin(e),B=g.x-A.x,C=g.y-A.y,Q=B*t-C*o,i=B*o+C*t;return{x:Q+A.x,y:i+A.y}},jSI=(g,A,I,e)=>{const t={top_left:{x:g.x-A,y:g.y-I},top_center:{x:g.x,y:g.y-I},top_right:{x:g.x+A,y:g.y-I},center_left:{x:g.x-A,y:g.y},center:{x:g.x,y:g.y},center_right:{x:g.x+A,y:g.y},bottom_left:{x:g.x-A,y:g.y+I},bottom_center:{x:g.x,y:g.y+I},bottom_right:{x:g.x+A,y:g.y+I}};return e===0?Object.entries(t).map(([o,B])=>({anchor:o,point:B})):Object.entries(t).map(([o,B])=>({anchor:o,point:Ioo(B,g,e)}))},eoo=g=>{switch(g.pcb_drawing_type){case"rect":{const A=g.ccw_rotation??0;return jSI({x:g.x,y:g.y},g.w/2,g.h/2,A)}case"pill":{const A=g.ccw_rotation??0;return jSI({x:g.x,y:g.y},g.w/2,g.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:g.x,y:g.y}},{anchor:"circle_right",point:{x:g.x+g.r,y:g.y}},{anchor:"circle_left",point:{x:g.x-g.r,y:g.y}},{anchor:"circle_top",point:{x:g.x,y:g.y-g.r}},{anchor:"circle_bottom",point:{x:g.x,y:g.y+g.r}}];case"oval":return[{anchor:"oval_center",point:{x:g.x,y:g.y}},{anchor:"oval_right",point:{x:g.x+g.rX,y:g.y}},{anchor:"oval_left",point:{x:g.x-g.rX,y:g.y}},{anchor:"oval_top",point:{x:g.x,y:g.y-g.rY}},{anchor:"oval_bottom",point:{x:g.x,y:g.y+g.rY}}];case"line":{const A={x:(g.x1+g.x2)/2,y:(g.y1+g.y2)/2};return[{anchor:"line_start",point:{x:g.x1,y:g.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:g.x2,y:g.y2}}]}case"polygon":return g.points.map((A,I)=>({anchor:`polygon_vertex_${I}`,point:A}));case"polygon_with_arcs":return g.brep_shape.outer_ring.vertices.map((A,I)=>({anchor:`polygon_with_arcs_vertex_${I}`,point:{x:A.x,y:A.y}}));default:return[]}},too=[];function zSI({snappingPoints:g,realToScreenTransform:A,isEnabled:I}){return I?g.map((e,t)=>({...e,id:`${t}-${e.anchor}`,screenPoint:Mt(A,e.point)})):too}var XSI=({screenPoint:{x:g,y:A}})=>`M${g-2.5},${A-2.5}l5,5m0,-5l-5,5`,ooo=gA.memo(function({points:A,startId:I,endId:e}){const{path:t,pointsById:o}=gA.useMemo(()=>({path:A.map(XSI).join(""),pointsById:new Map(A.map(C=>[C.id,C]))}),[A]),B=[...new Set([I,e])].flatMap(C=>{const Q=C===null?void 0:o.get(C);return Q?[XSI(Q)]:[]}).join("");return W.jsxs("svg",{"aria-hidden":"true",width:"100%",height:"100%",style:{position:"absolute",left:0,top:0,overflow:"visible",pointerEvents:"none",zIndex:Da.dimensionOverlay},fill:"none",strokeWidth:1,children:[W.jsx("path",{d:t,stroke:"white"}),W.jsx("path",{d:B,stroke:"#66ccff"})]})}),Boo=16,Coo=[],Qoo=aJ(),$SI=g=>{if(g.pcb_drawing_type==="text")return!0;const A=g._element;if(!A||typeof A!="object")return!1;const I=typeof A.type=="string"?A.type:void 0;return I?!!(I.startsWith("pcb_silkscreen_")||I.startsWith("pcb_note_")||I==="pcb_text"||I.startsWith("pcb_fabrication_note_")&&I!=="pcb_fabrication_note_rect"):!1},ioo=({children:g,transform:A,focusOnHover:I=!1,primitives:e=Coo,onBoundsSelected:t,cancelPanDrag:o})=>{A||(A=Qoo);const[B,C]=gA.useState(!1),[Q,i]=gA.useState(!1),[E,n]=gA.useState(!1),[s,r]=gA.useState(!1),[a,c]=gA.useState(!1),[h,l]=gA.useState(!1),[D,d]=gA.useState({start:null,end:null}),y=Qi(FA=>FA.is_mouse_over_container),w=gA.useCallback(()=>{E&&(n(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[E]),u=gA.useCallback(()=>{s&&(r(!1),window.dispatchEvent(new Event("disarm-bounds-tool")))},[s]),[G,m]=gA.useState({x:0,y:0}),[p,k]=gA.useState({x:0,y:0}),[S,R]=gA.useState({x:0,y:0}),[F,N]=gA.useState({x:0,y:0}),U=gA.useRef({x:0,y:0}),L=gA.useRef(!1),b=gA.useRef(null),q=b.current?.getBoundingClientRect(),j=gA.useMemo(()=>{const FA=new Map;for(const rA of e){if(!rA._element||$SI(rA)||rA.pcb_drawing_type==="pill"||rA.pcb_drawing_type==="rect"&&rA.ccw_rotation&&rA.ccw_rotation!==0)continue;const NA=iIg(rA);if(!NA)continue;const RA=FA.get(rA._element);FA.set(rA._element,reo(RA??void 0,NA))}return FA},[e]),Z=gA.useMemo(()=>{const FA=[];for(const rA of e){if(!rA._element||$SI(rA))continue;const NA=eoo(rA);if(NA.length!==0)for(const RA of NA)FA.push({anchor:RA.anchor,point:RA.point,element:rA._element})}return FA},[e]),O=gA.useMemo(()=>{const FA=[];j.forEach((rA,NA)=>{if(!rA)return;const RA=(rA.minX+rA.maxX)/2,UA=(rA.minY+rA.maxY)/2,bA={top_left:{x:rA.minX,y:rA.minY},top_center:{x:RA,y:rA.minY},top_right:{x:rA.maxX,y:rA.minY},center_left:{x:rA.minX,y:UA},center:{x:RA,y:UA},center_right:{x:rA.maxX,y:UA},bottom_left:{x:rA.minX,y:rA.maxY},bottom_center:{x:RA,y:rA.maxY},bottom_right:{x:rA.maxX,y:rA.maxY}};for(const[PA,kA]of Object.entries(bA))FA.push({anchor:PA,point:kA,element:NA})});for(const rA of Z)FA.push(rA);return FA.push({anchor:"origin",point:{x:0,y:0},element:null}),FA},[j,Z]),AA=gA.useMemo(()=>zSI({snappingPoints:O,realToScreenTransform:A,isEnabled:E||Q}),[O,A,E,Q]),tA=gA.useCallback(FA=>{let rA=AA;if(rA.length===0&&(rA=zSI({snappingPoints:O,realToScreenTransform:A,isEnabled:!0})),rA.length===0)return{point:FA,id:null};const NA=Mt(A,FA);let RA=null;for(const UA of rA){const bA=UA.screenPoint.x-NA.x,PA=UA.screenPoint.y-NA.y,kA=Math.hypot(bA,PA);kA>Boo||(!RA||kA<RA.distance)&&(RA={distance:kA,id:UA.id,point:UA.point})}return RA?{point:RA.point,id:RA.id}:{point:FA,id:null}},[O,AA,A]);gA.useEffect(()=>{const FA=RA=>{const UA=RA.target;if(UA.tagName==="INPUT"||UA.tagName==="TEXTAREA"||UA.isContentEditable)return;const bA=b.current?.contains(document.activeElement)||document.activeElement===b.current;if(!(!y&&!bA)){if(RA.key==="d"){const PA=tA({x:U.current.x,y:U.current.y});m({x:PA.point.x,y:PA.point.y}),k({x:PA.point.x,y:PA.point.y}),d({start:PA.id,end:PA.id}),B?(C(!1),i(!1),d({start:null,end:null})):(C(!0),i(!0)),w()}RA.key==="Escape"&&(C(!1),i(!1),d({start:null,end:null}),c(!1),l(!1),w(),u())}},rA=()=>{n(!0),r(!1),window.dispatchEvent(new Event("disarm-bounds-tool"))},NA=()=>{r(!0),n(!1),C(!1),i(!1),window.dispatchEvent(new Event("disarm-dimension-tool"))};return window.addEventListener("keydown",FA),window.addEventListener("arm-dimension-tool",rA),window.addEventListener("arm-bounds-tool",NA),()=>{window.removeEventListener("keydown",FA),window.removeEventListener("arm-dimension-tool",rA),window.removeEventListener("arm-bounds-tool",NA),w(),u()}},[y,B,w,u,tA]);const eA=Mt(A,G),QA=Mt(A,p),sA=Mt(A,S),DA=Mt(A,F),CA={minX:Math.min(S.x,F.x),minY:Math.min(S.y,F.y),maxX:Math.max(S.x,F.x),maxY:Math.max(S.y,F.y)},hA={left:Math.min(sA.x,DA.x),top:Math.min(sA.y,DA.y),width:Math.abs(sA.x-DA.x),height:Math.abs(sA.y-DA.y)},nA=gA.useCallback((FA,rA)=>{const NA={minX:Math.min(FA.x,rA.x),minY:Math.min(FA.y,rA.y),maxX:Math.max(FA.x,rA.x),maxY:Math.max(FA.y,rA.y)};t?.(NA),window.dispatchEvent(new CustomEvent("pcb-viewer:bounds-selected",{detail:NA}))},[t]),cA={left:Math.min(eA.x,QA.x),right:Math.max(eA.x,QA.x),top:Math.min(eA.y,QA.y),bottom:Math.max(eA.y,QA.y),flipX:eA.x>QA.x,flipY:eA.y>QA.y,width:0,height:0};cA.width=cA.right-cA.left,cA.height=cA.bottom-cA.top;const fA=goo({dimensionStart:G,dimensionEnd:p,screenDimensionStart:eA,screenDimensionEnd:QA,flipX:cA.flipX,flipY:cA.flipY});return W.jsxs("div",{ref:b,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseDownCapture:()=>{L.current=!1},onClickCapture:FA=>{L.current&&(L.current=!1,FA.stopPropagation(),b.current?.focus())},onContextMenuCapture:FA=>{!E&&!B&&!L.current||(FA.preventDefault(),FA.stopPropagation())},onMouseEnter:()=>{I&&b.current&&b.current.focus()},onMouseLeave:()=>{b.current&&b.current.blur()},onClick:()=>{b.current&&b.current.focus()},onMouseMove:FA=>{const rA=FA.currentTarget.getBoundingClientRect(),NA=FA.clientX-rA.left,RA=FA.clientY-rA.top,UA=Mt(Gx(A),{x:NA,y:RA});if(U.current.x=UA.x,U.current.y=UA.y,Q){const bA=tA(UA);k({x:bA.point.x,y:bA.point.y}),d(PA=>({...PA,end:bA.id}))}h&&(o?.(),N({x:UA.x,y:UA.y}))},onMouseDown:FA=>{L.current=E||B;const rA=FA.currentTarget.getBoundingClientRect(),NA=FA.clientX-rA.left,RA=FA.clientY-rA.top,UA=Mt(Gx(A),{x:NA,y:RA});if(s)FA.preventDefault(),FA.stopPropagation(),o?.(),R({x:UA.x,y:UA.y}),N({x:UA.x,y:UA.y}),c(!0),l(!0),u();else if(E&&!B){const bA=tA(UA);m({x:bA.point.x,y:bA.point.y}),k({x:bA.point.x,y:bA.point.y}),d({start:bA.id,end:bA.id}),C(!0),i(!0),w()}else Q?(i(!1),d(bA=>({...bA,end:null}))):B&&(C(!1),d({start:null,end:null}))},onMouseUp:FA=>{if(!h)return;const rA=FA.currentTarget.getBoundingClientRect(),NA=FA.clientX-rA.left,RA=FA.clientY-rA.top,UA=Mt(Gx(A),{x:NA,y:RA}),bA={x:UA.x,y:UA.y};FA.preventDefault(),FA.stopPropagation(),o?.(),N(bA),l(!1),nA(S,bA)},children:[g,a&&W.jsxs(W.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.dimensionOverlay},width:q.width,height:q.height,children:W.jsx("rect",{x:hA.left,y:hA.top,width:hA.width,height:hA.height,stroke:"red",strokeWidth:1.5,strokeDasharray:"4,3",fill:"rgba(255, 0, 0, 0.12)"})}),W.jsxs("div",{style:{left:0,bottom:B?58:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.dimensionOverlay},children:["minX: ",CA.minX.toFixed(2),", minY:"," ",CA.minY.toFixed(2),W.jsx("br",{}),"maxX: ",CA.maxX.toFixed(2),", maxY:"," ",CA.maxY.toFixed(2)]})]}),B&&W.jsxs(W.Fragment,{children:[fA.show&&W.jsx("div",{style:{position:"absolute",left:fA.x,top:fA.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:Da.dimensionOverlay},children:fA.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:cA.left,width:cA.width,textAlign:"center",top:eA.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:cA.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:Da.dimensionOverlay},children:Math.abs(G.x-p.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:QA.x,height:cA.height,display:"flex",flexDirection:"column",justifyContent:"center",top:cA.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:Da.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:cA.flipX?"-100%":4,paddingRight:4},children:Math.abs(G.y-p.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.dimensionOverlay},width:q.width,height:q.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:eA.x,y1:eA.y,x2:QA.x,y2:QA.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:eA.x,y1:eA.y,x2:QA.x,y2:eA.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.jsx("line",{x1:QA.x,y1:eA.y,x2:QA.x,y2:QA.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),Q&&W.jsx(ooo,{points:AA,startId:D.start,endId:D.end}),W.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",G.x.toFixed(2),",",G.y.toFixed(2),")",W.jsx("br",{}),"(",p.x.toFixed(2),",",p.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((p.x-G.x)**2+(p.y-G.y)**2).toFixed(2)]})]})]})},Eoo=(g,A,I=0)=>{const e=g.width/2,t=g.height/2,o=g.center.x-e-I,B=g.center.x+e+I,C=g.center.y-t-I,Q=g.center.y+t+I;return A.x>o&&A.x<B&&A.y>C&&A.y<Q},noo=({children:g,disabled:A,transform:I,soup:e,cancelPanDrag:t,onCreateEditEvent:o,onModifyEditEvent:B})=>{I||(I=aJ());const C=gA.useRef(null),[Q,i]=gA.useState(null),[E,n]=gA.useState(null),s=Q!==null;Qi(h=>h.in_edit_mode);const r=Qi(h=>h.in_move_footprint_mode),a=Qi(h=>h.setIsMovingComponent),c=A||!r;return W.jsxs("div",{ref:C,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(c)return;const l=h.currentTarget.getBoundingClientRect(),D=h.clientX-l.left,d=h.clientY-l.top;if(Number.isNaN(D)||Number.isNaN(d))return;const y=Mt(Gx(I),{x:D,y:d});let w=!1;for(const u of e)if(u.type==="pcb_component"&&Eoo(u,y,10/I.a)){t(),i(u.pcb_component_id),w=!0;const G=Math.random().toString();n({dragStart:y,originalCenter:u.center,dragEnd:y,edit_event_id:G}),o({edit_event_id:G,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:u.pcb_component_id,original_center:u.center,new_center:u.center,in_progress:!0,created_at:Date.now()}),a(!0);break}if(w||i(null),w)return h.preventDefault(),!1},onMouseMove:h=>{if(!Q||!E)return;const l=h.currentTarget.getBoundingClientRect(),D=h.clientX-l.left,d=h.clientY-l.top;if(Number.isNaN(D)||Number.isNaN(d))return;const y=Mt(Gx(I),{x:D,y:d});n({...E,dragEnd:y}),B({edit_event_id:E.edit_event_id,new_center:{x:E.originalCenter.x+y.x-E.dragStart.x,y:E.originalCenter.y+y.y-E.dragStart.y}})},onMouseUp:h=>{Q&&(i(null),a(!1),E&&(B({edit_event_id:E.edit_event_id,in_progress:!1}),n(null)))},children:[g,!c&&e.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const l=Mt(I,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:l.x,top:l.y,width:h.width*I.a+20,height:h.height*I.a+20,transform:"translate(-50%, -50%)",background:s&&Q===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},sIg=(g,A)=>{const I=A.current;if(!I)return{transform:"translate(-50%, -100%)",left:g.x,top:g.y};const e=I.getBoundingClientRect(),t=200,o=10,B=60;let C="-50%",Q="-100%",i=g.x,E=g.y;return g.x+B+t<e.width-o?(i=g.x+B,C="0%"):g.x-B-t>o?(i=g.x-B,C="-100%"):(i=g.x,C="-50%"),{transform:`translate(${C}, ${Q})`,left:i,top:E}},soo=({center:g})=>W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.errorOverlay+30},width:"100%",height:"100%",children:[W.jsx("circle",{cx:g.x,cy:g.y,r:11,fill:"none",stroke:"#ff6b6b",strokeWidth:2.5,opacity:.95}),W.jsx("circle",{cx:g.x,cy:g.y,r:4.5,fill:"#ff6b6b",opacity:.95}),W.jsx("line",{x1:g.x-18,y1:g.y,x2:g.x-8,y2:g.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:g.x+8,y1:g.y,x2:g.x+18,y2:g.y,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:g.x,y1:g.y-18,x2:g.x,y2:g.y-8,stroke:"#ff6b6b",strokeWidth:2}),W.jsx("line",{x1:g.x,y1:g.y+8,x2:g.x,y2:g.y+18,stroke:"#ff6b6b",strokeWidth:2})]}),A2I=({errorCenter:g,isHighlighted:A=!1})=>W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.errorOverlay},width:"100%",height:"100%",children:W.jsx("rect",{x:g.x-7,y:g.y-7,width:14,height:14,transform:`rotate(45 ${g.x} ${g.y})`,fill:A?"#ff4444":"transparent",stroke:A?"#ff4444":"red",strokeWidth:A?2.5:1.5})}),aIg=F7`
5420
5420
  opacity: 0;
5421
5421
  pointer-events: none;
5422
5422
  background-color: rgba(0, 0, 0, 0.8);
@@ -5429,7 +5429,7 @@ ${e.svg()}`;return I+=`" >
5429
5429
  transition: opacity 0.2s;
5430
5430
  margin-bottom: 10px;
5431
5431
  color: red;
5432
- `,aoo=[];function roo(g){return g.type==="source_component"?g.source_component_id:g.type==="pcb_component"?g.pcb_component_id:"component"}var coo=({children:g,transform:A=aJ(),elements:I})=>{const e=gA.useRef(null),{isShowingDRCErrors:t,hoveredErrorId:o,focusedErrorId:B}=Qi(l=>({isShowingDRCErrors:l.is_showing_drc_errors,hoveredErrorId:l.hovered_error_id,focusedErrorId:l.focused_error_id})),C=B??o,Q=I??aoo,i=gA.useMemo(()=>Q.filter(l=>l.type==="pcb_trace_error"&&!l.message?.includes("Multiple components found with name")),[Q]),E=gA.useMemo(()=>Q.filter(l=>l.type==="pcb_via_clearance_error"),[Q]),n=gA.useMemo(()=>Q.filter(l=>l.type==="pcb_trace_error"&&!!l.message?.includes("Multiple components found with name")),[Q]),s=gA.useMemo(()=>aSI(Q),[Q]),r=gA.useMemo(()=>DSI(Q,C),[C,Q]),a=gA.useMemo(()=>n.map((l,D)=>{const d=("component_name"in l&&typeof l.component_name=="string"?l.component_name:void 0)??l.message?.match(/name "([^"]+)"/)?.[1];return d?{components:Q.filter(w=>w.type==="source_component"&&w.name===d||w.type==="pcb_component"&&Q.some(u=>u.type==="source_component"&&u.source_component_id===w.source_component_id&&u.name===d)),error:l,errorIndex:D}:{components:[],error:l,errorIndex:D}}),[n,Q]);if(!I)return W.jsx("div",{style:{position:"relative"},ref:e,children:g});const c=l=>{const D=meo({error:l,indexes:s});if(!D||typeof D.x!="number"||typeof D.y!="number")return null;const d=Mt(A,D);return Number.isNaN(d.x)||Number.isNaN(d.y)?null:d};let h=null;return r&&(h=c(r)),W.jsxs("div",{style:{position:"relative"},ref:e,children:[g,i.map((l,D)=>{const d=q7(l,D),y=C===d;if(!y&&!t)return null;const w=c(l);if(!w)return null;const u=sIg(w,e);return W.jsxs(gA.Fragment,{children:[W.jsx(A2I,{errorCenter:w,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Da.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="1")}},onMouseLeave:G=>{if(!y){const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:u.left,top:u.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:t||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:u.transform},children:W.jsx("div",{className:`error-message ${aIg}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},d)}),E.map((l,D)=>{const d=q7(l,D),y=C===d;if(!y&&!t)return null;const w=c(l);if(!w)return null;const u=sIg({x:w.x,y:w.y},e);return W.jsxs(gA.Fragment,{children:[W.jsx(A2I,{errorCenter:w,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Da.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="1")}},onMouseLeave:G=>{if(!y){const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?Da.errorOverlay+10:Da.errorOverlay+1,left:u.left,top:u.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:u.transform},children:W.jsx("div",{className:`error-message ${aIg}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},d)}),a.map(({components:l,error:D,errorIndex:d})=>{const y=q7(D,d),w=C===y;return!w&&!t?null:l.map(u=>{let G={x:0,y:0};if(u.type==="pcb_component")G=u.center||{x:0,y:0};else if(u.type==="source_component"){const U=I?.find(L=>L.type==="pcb_component"&&L.source_component_id===u.source_component_id);U&&U.type==="pcb_component"&&(G=U.center||{x:0,y:0})}const m=Mt(A,G);if(Number.isNaN(m.x)||Number.isNaN(m.y))return null;const p=Math.abs(A.a),F=Math.max(8,Math.min(30,.5*p)),N=sIg(m,e);return W.jsxs(gA.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.errorOverlay},width:"100%",height:"100%",children:w?W.jsx("polygon",{points:`${m.x},${m.y-F*1.25} ${m.x+F},${m.y} ${m.x},${m.y+F*1.25} ${m.x-F},${m.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:m.x,cy:m.y,r:F,fill:"none",stroke:w?"#ff4444":"red",strokeWidth:w?Math.max(2,F*.15):Math.max(1,F*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:m.x-(F+10),top:m.y-(F+10),width:(F+10)*2,height:(F+10)*2,zIndex:Da.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:U=>{const L=U.currentTarget.nextElementSibling;if(L){const b=L.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:U=>{if(!w){const L=U.currentTarget.nextElementSibling;if(L){const b=L.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:w?Da.errorOverlay+20:Da.errorOverlay+10,left:N.left,top:N.top,color:w?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:t||w?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:N.transform},children:W.jsx("div",{className:`error-message ${aIg}`,style:{opacity:w?1:0,border:`1px solid ${w?"#ff4444":"red"}`},children:D.message})})]},`${y}_${u.type}_${roo(u)}`)})}),h&&W.jsx(soo,{center:h})]})},g2I=(g,A,I,e)=>{if(I<=0||e<=0)return;const t=g.find(B=>B.type==="pcb_component"&&B.pcb_component_id===A);if(t?.type!=="pcb_component")return;const o=zMI(t);if(o)return{component:t,bounds:o,transform:lSI({bounds:o,width:I,height:e})}},hoo=({focusRequest:g,elements:A,transform:I})=>{const e=g?.pcbComponentId,t=Qi(E=>E.selectLayer),o=e?g2I(A,e,1,1):void 0,B=o?.component.layer;if(gA.useEffect(()=>{B&&t(B)},[g,B,t]),!o||!I)return null;const{bounds:C}=o,Q=Mt(I,{x:C.minX,y:C.minY}),i=Mt(I,{x:C.maxX,y:C.maxY});return W.jsx("div",{"data-focused-pcb-component-id":e,style:{position:"absolute",left:Math.min(Q.x,i.x)-4,top:Math.min(Q.y,i.y)-4,width:Math.abs(i.x-Q.x)+8,height:Math.abs(i.y-Q.y)+8,border:"2px solid #3399ff",borderRadius:4,boxSizing:"border-box",pointerEvents:"none",zIndex:Da.elementOverlay}})};function loo(g,A){return g.size!==A.size?!1:Array.from(g).every(I=>A.has(I))}var ec={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},$M={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},rIg=({targets:g,transform:A,containerWidth:I,containerHeight:e})=>{if(g.length===0)return null;const t={color:$M.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:ec.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return g.forEach(B=>{if(!o.has(B.anchor_id)){const C=Mt(A,B.anchor);o.set(B.anchor_id,C)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:I,height:e,overflow:"hidden",pointerEvents:"none",zIndex:Da.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:I,height:e,children:[g.map(B=>{const C=B.anchor,Q=B.anchor_id,i=B.target,E=o.get(Q),n=Mt(A,i),s=i.x-C.x,r=i.y-C.y,a=Math.abs(n.x-E.x),c=Math.abs(n.y-E.y),h=n.y<E.y,l=n.x>E.x,D=h?ec.LABEL_OFFSET_ABOVE:ec.LABEL_OFFSET_BELOW,d=l?ec.LABEL_OFFSET_RIGHT:ec.LABEL_OFFSET_LEFT,y=a>ec.MIN_LINE_LENGTH_FOR_LABEL,w=c>ec.MIN_LINE_LENGTH_FOR_LABEL,u=`${B.display_offset_x??s.toFixed(2)}mm`,G=`${B.display_offset_y??r.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:E.x,y1:E.y,x2:n.x,y2:E.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.LINE_STROKE_WIDTH,strokeDasharray:ec.LINE_DASH_PATTERN}),W.jsx("line",{x1:n.x,y1:E.y,x2:n.x,y2:n.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.LINE_STROKE_WIDTH,strokeDasharray:ec.LINE_DASH_PATTERN}),B.type==="component"||B.type==="board"?W.jsx("circle",{cx:n.x,cy:n.y,r:ec.COMPONENT_MARKER_RADIUS,fill:$M.COMPONENT_MARKER_FILL,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:n.x-ec.ANCHOR_MARKER_SIZE,y1:n.y,x2:n.x+ec.ANCHOR_MARKER_SIZE,y2:n.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:n.x,y1:n.y-ec.ANCHOR_MARKER_SIZE,x2:n.x,y2:n.y+ec.ANCHOR_MARKER_SIZE,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH})]}),y&&W.jsx("foreignObject",{x:Math.min(E.x,n.x),y:E.y+D,width:Math.abs(n.x-E.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...t,textAlign:"center"},children:u})}),w&&W.jsx("foreignObject",{x:n.x+d,y:Math.min(E.y,n.y),width:ec.Y_LABEL_MIN_WIDTH,height:Math.abs(n.y-E.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...t,display:"flex",alignItems:"center",justifyContent:l?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:G})})]},B.id)}),Array.from(o.entries()).map(([B,C])=>W.jsxs("g",{children:[W.jsx("line",{x1:C.x-ec.ANCHOR_MARKER_SIZE,y1:C.y,x2:C.x+ec.ANCHOR_MARKER_SIZE,y2:C.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:C.x,y1:C.y-ec.ANCHOR_MARKER_SIZE,x2:C.x,y2:C.y+ec.ANCHOR_MARKER_SIZE,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${B}`))]})})},S3=g=>g?.type==="pcb_component",I2I=g=>g?.type==="pcb_group",Doo=g=>g?.type==="pcb_panel",cIg=g=>g?.type==="pcb_board",doo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=Qi(l=>l.is_showing_group_anchor_offsets),B=A.map(l=>S3(l._parent_pcb_component)?l._parent_pcb_component.pcb_component_id:S3(l._element)?l._element.pcb_component_id:null).filter(l=>!!l);if(!o&&B.length===0)return null;const C=g.filter(l=>cIg(l)),Q=g.filter(l=>S3(l)),i=g.filter(l=>I2I(l)),E=new Set;B.forEach(l=>{const D=Q.find(d=>d.pcb_component_id===l);D?.pcb_group_id&&E.add(D.pcb_group_id)});const n=Q.map(l=>{const D=l.positioned_relative_to_pcb_board_id;if(!D)return null;const d=C.find(y=>y.pcb_board_id===D);return d?{component:l,board:d,type:"component"}:null}).filter(l=>!!l),s=i.map(l=>{const D=l.positioned_relative_to_pcb_board_id;if(!D||!l.center)return null;const d=C.find(y=>y.pcb_board_id===D);return d?{group:l,board:d,type:"group"}:null}).filter(l=>!!l),r=[...n,...s];if(r.length===0)return null;const a=B.length===0,c=r.filter(l=>l.type==="component"?a||B.includes(l.component.pcb_component_id):a||E.has(l.group.pcb_group_id));if(c.length===0)return null;const h=c.map(l=>l.type==="component"?{id:`${l.board.pcb_board_id}-${l.component.pcb_component_id}-${l.type}`,anchor:l.board.center,anchor_id:l.board.pcb_board_id,target:l.component.center,type:"component",display_offset_x:l.component.display_offset_x,display_offset_y:l.component.display_offset_y}:{id:`${l.board.pcb_board_id}-${l.group.pcb_group_id}-${l.type}`,anchor:l.board.center,anchor_id:l.board.pcb_board_id,target:{x:l.group.anchor_position?.x??l.group.center.x,y:l.group.anchor_position?.y??l.group.center.y},type:"group",display_offset_x:l.group.display_offset_x,display_offset_y:l.group.display_offset_y}).filter(l=>!!l);return W.jsx(rIg,{targets:h,transform:I,containerWidth:e,containerHeight:t})},yoo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=Qi(l=>l.is_showing_group_anchor_offsets),B=A.map(l=>S3(l._parent_pcb_component)?l._parent_pcb_component.pcb_component_id:S3(l._element)?l._element.pcb_component_id:null).filter(l=>!!l);if(!o&&B.length===0)return null;const C=g.filter(l=>I2I(l)),Q=g.filter(l=>S3(l)),i=(l,D)=>{if(D.has(l))return;D.add(l);const d=C.find(y=>y.pcb_group_id===l);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&i(d.positioned_relative_to_pcb_group_id,D)},E=new Set;B.forEach(l=>{const D=Q.find(d=>d.pcb_component_id===l);D&&(D.position_mode==="relative_to_group_anchor"&&D.positioned_relative_to_pcb_group_id&&i(D.positioned_relative_to_pcb_group_id,E),D.pcb_group_id&&i(D.pcb_group_id,E))});const n=Q.map(l=>{if(l.position_mode==="relative_to_group_anchor"&&l.positioned_relative_to_pcb_group_id){const D=C.find(d=>d.pcb_group_id===l.positioned_relative_to_pcb_group_id);return D?.anchor_position?{component:l,parentGroup:D,type:"component"}:null}if(l.pcb_group_id){const D=C.find(d=>d.pcb_group_id===l.pcb_group_id);return D?.anchor_position?{component:l,parentGroup:D,type:"component"}:null}return null}).filter(l=>!!l),s=C.map(l=>{if(l.position_mode==="relative_to_group_anchor"&&l.positioned_relative_to_pcb_group_id){const D=C.find(d=>d.pcb_group_id===l.positioned_relative_to_pcb_group_id);if(D?.anchor_position&&l.anchor_position)return{group:l,parentGroup:D,type:"group"}}return null}).filter(l=>!!l),r=[...n,...s];if(r.length===0)return null;const a=B.length===0,c=r.filter(l=>l.type==="component"?a||B.includes(l.component.pcb_component_id):a||E.has(l.group.pcb_group_id)||E.has(l.parentGroup.pcb_group_id));if(c.length===0)return null;const h=c.map(l=>{const D=l.parentGroup.anchor_position;return D?l.type==="component"?l.component.center?{id:`${l.parentGroup.pcb_group_id}-${l.component.pcb_component_id}-${l.type}`,anchor:D,anchor_id:l.parentGroup.pcb_group_id,target:l.component.center,type:"component",display_offset_x:l.component.display_offset_x,display_offset_y:l.component.display_offset_y}:null:l.group.anchor_position?{id:`${l.parentGroup.pcb_group_id}-${l.group.pcb_group_id}-${l.type}`,anchor:D,anchor_id:l.parentGroup.pcb_group_id,target:l.group.anchor_position,type:"group",display_offset_x:l.group.display_offset_x,display_offset_y:l.group.display_offset_y}:null:null}).filter(l=>!!l);return W.jsx(rIg,{targets:h,transform:I,containerWidth:e,containerHeight:t})},woo=(g,A)=>{const I=g.pcb_component_id,e=A.filter(t=>(t.type==="pcb_smtpad"||t.type==="pcb_plated_hole")&&t.pcb_component_id===I||t.type==="pcb_hole"&&t.pcb_component_id===I);return e.length===0?CIg([g]):CIg(e)},uoo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=new Map;for(const C of A)S3(C._parent_pcb_component)&&o.set(C._parent_pcb_component.pcb_component_id,C._parent_pcb_component),S3(C._element)&&o.set(C._element.pcb_component_id,C._element);if(o.size===0)return null;const B=[];for(const C of o.values()){const Q=woo(C,g);if(!Q)continue;const i=C.positioned_relative_to_pcb_group_id??C.pcb_group_id,E=i?p5(g).pcb_group.get(i):null;B.push({component:C,bbox:Q,group:E})}return B.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:t,overflow:"hidden",pointerEvents:"none",zIndex:Da.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:t,children:B.map(({component:C,bbox:Q,group:i})=>{const E=Mt(I,{x:Q.minX,y:Q.maxY}),n=Mt(I,{x:Q.maxX,y:Q.minY}),s={x:Math.min(E.x,n.x),y:Math.min(E.y,n.y),width:Math.abs(n.x-E.x),height:Math.abs(n.y-E.y)},r=C.center??{x:(Q.minX+Q.maxX)/2,y:(Q.minY+Q.maxY)/2},a=Mt(I,r);return W.jsxs("g",{children:[W.jsx("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:a.x-6,y1:a.y,x2:a.x+6,y2:a.y,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:a.x,y1:a.y-6,x2:a.x,y2:a.y+6,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:a.x,cy:a.y,r:ec.COMPONENT_MARKER_RADIUS,fill:$M.COMPONENT_MARKER_FILL,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1})]},C.pcb_component_id)})})})},Goo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=Qi(r=>r.is_showing_group_anchor_offsets),B=A.map(r=>cIg(r._element)?r._element.pcb_board_id:null).filter(r=>!!r);if(!o&&B.length===0)return null;const C=g.filter(r=>Doo(r)),i=g.filter(r=>cIg(r)).map(r=>{const a=r.pcb_panel_id,c=r.position_mode;if(!a||c!=="relative_to_panel_anchor")return null;const h=C.find(l=>l.pcb_panel_id===a);return h?{board:r,panel:h,type:"board"}:null}).filter(r=>!!r);if(i.length===0)return null;const E=B.length===0,n=i.filter(r=>E||B.includes(r.board.pcb_board_id));if(n.length===0)return null;const s=n.map(r=>r.board.center?{id:`${r.panel.pcb_panel_id}-${r.board.pcb_board_id}-${r.type}`,anchor:r.panel.center,anchor_id:r.panel.pcb_panel_id,target:r.board.center,type:"board",display_offset_x:r.board.display_offset_x,display_offset_y:r.board.display_offset_y}:null).filter(r=>!!r);return W.jsx(rIg,{targets:s,transform:I,containerWidth:e,containerHeight:t})};function moo(g){const{primitives:A,is_showing_multiple_traces_length:I,traceOverlayElementIndex:e}=g,t=A.filter(C=>C._element.type==="pcb_trace"),o=A.filter(C=>C._element.type!=="pcb_trace"),B=t.filter(C=>(C._element.source_trace_id?e.sourceTraceById.get(C._element.source_trace_id):void 0)?.max_length!==void 0||EIg({primitiveElement:C._element,traceOverlayElementIndex:e})!==null);if(!I)return[...o,...B];if(t.length>1){const C=t.reduce((Q,i)=>{const E=Q._element.trace_length;return i._element.trace_length<E?i:Q},t[0]);return[...o,C]}return A}var poo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},koo=g=>{const{_element:A,_parent_pcb_component:I,_parent_source_component:e,_source_port:t}=g;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],B=Array.from(new Set((A.port_hints??[]).concat(t?.port_hints??[]))).filter(Q=>!/^[0-9]+$/.test(Q)).filter(Q=>!Q.includes("unnamed_")).sort((Q,i)=>i.localeCompare(Q)),C=e&&"name"in e&&e.name&&!e.name.includes("unnamed_")?e.name:null;return B.length>0?C?o.push(...B.map(Q=>`${C}.${Q}`)):o.push(...B):C&&o.push(C),o.join(", ")}default:return""}},Moo={top:"red",bottom:"aqua"},Soo=({primitive:g,mousePos:A,traceOverlayElementIndex:I})=>{const[e,t]=gA.useState(!1),o=g._element;gA.useEffect(()=>{setTimeout(()=>{t(!0)},100)},[]);const[B,C,Q,i]=[g.screen_x,g.screen_y,g.screen_w,g.screen_h],E=g.same_space_index??0,n=26,s=Moo[g?._element?.layer]??"red";let r=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?r=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in g||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in g)&&(r=o.ccw_rotation??0),o.type==="pcb_trace"){const h=wSI({primitiveElement:o,traceOverlayElementIndex:I});return h?W.jsx("div",{style:{zIndex:Da.elementOverlay,position:"absolute",left:A.x+12,top:A.y+12,color:s,pointerEvents:"none"},children:W.jsxs("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[h.text&&W.jsx("div",{children:h.text}),h.name&&W.jsx("div",{style:{marginTop:h.text?"2px":0},children:h.name})]})}):null}const a=koo(g);return a.trim().length===0?null:W.jsx("div",{style:{zIndex:Da.elementOverlay,position:"absolute",left:B-Q/2-8,top:C-i/2-8,width:Q+16,height:i+16,color:s,transform:`rotate(${-r}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:e?`calc(100% + ${n*2*E}px)`:"100%",height:e?`calc(100% + ${n*2*E}px)`:"100%",marginLeft:e?`${-n*E}px`:0,marginTop:e?`${-n*E}px`:0,border:`1px solid ${s}`,opacity:e||E===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:i+20+n*E,marginRight:e?`${-n*E}px`:0,marginBottom:e?0:-n*E,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(${r}deg)`,minWidth:"45px",textAlign:"center"},children:a})})})},foo=({highlightedPrimitives:g,mousePos:A,elements:I})=>{const[e,t]=Qi(Q=>[Q.is_moving_component,Q.is_showing_multiple_traces_length]),o=gA.useMemo(()=>ySI(I),[I]),B=g.some(Q=>Q._element.type==="pcb_smtpad")&&g.some(Q=>Q._element.type==="pcb_trace");let C=g;return B&&(C=C.filter(Q=>Q._element.type==="pcb_smtpad")),C=moo({primitives:C,is_showing_multiple_traces_length:t,traceOverlayElementIndex:o}),W.jsx("div",{style:poo,children:!e&&C.map(Q=>W.jsx(Soo,{primitive:Q,mousePos:A,traceOverlayElementIndex:o},Q._pcb_drawing_object_id))})},cwA=g=>{if(g.length===0)return null;let A=g[0].x,I=g[0].y,e=g[0].x,t=g[0].y;for(const o of g)o.x<A&&(A=o.x),o.y<I&&(I=o.y),o.x>e&&(e=o.x),o.y>t&&(t=o.y);return{center:{x:(A+e)/2,y:(I+t)/2},width:e-A,height:t-I}},e2I=(g,A)=>{if(A.length<3)return!1;let I=!1;for(let e=0,t=A.length-1;e<A.length;t=e++){const o=A[e].x,B=A[e].y,C=A[t].x,Q=A[t].y;B>g.y!=Q>g.y&&g.x<(C-o)*(g.y-B)/(Q-B||Number.EPSILON)+o&&(I=!I)}return I},hIg=({includeHiddenTraces:g=!1,primitives:A,rwPoint:I,selectedLayer:e,transform:t})=>{const o=[];for(const B of A){if(!B._element||!g&&B._element.type==="pcb_trace"&&B.layer!==e)continue;if("x1"in B&&B._element?.type==="pcb_trace"){const i=hh({x:I.x,y:I.y},{x:B.x1,y:B.y1},{x:B.x2,y:B.y2}),E=B.width||.5,n=Math.max(E*25,2)/t.a;i<n&&o.push(B);continue}if(B.pcb_drawing_type==="polygon"){const i=B.points.map(n=>({x:sg.parse(n.x),y:sg.parse(n.y)})),E=cwA(i);if(!E||I.x<E.center.x-E.width/2||I.x>E.center.x+E.width/2||I.y<E.center.y-E.height/2||I.y>E.center.y+E.height/2)continue;e2I(I,i)&&o.push(B);continue}if(B.pcb_drawing_type==="polygon_with_arcs"){const i=B.brep_shape.outer_ring.vertices.map(n=>({x:sg.parse(n.x),y:sg.parse(n.y)})),E=cwA(i);if(!E||I.x<E.center.x-E.width/2||I.x>E.center.x+E.width/2||I.y<E.center.y-E.height/2||I.y>E.center.y+E.height/2)continue;e2I(I,i)&&o.push(B);continue}if(!("x"in B&&"y"in B))continue;let C=0,Q=0;if("w"in B&&"h"in B)C=B.w,Q=B.h;else if("r"in B)C=B.r*2,Q=B.r*2;else if("rX"in B&&"rY"in B)C=B.rX*2,Q=B.rY*2;else continue;Math.abs(B.x-I.x)<C/2&&Math.abs(B.y-I.y)<Q/2&&o.push(B)}return o},Roo=({elements:g,children:A,transform:I,primitives:e,selectedLayer:t,onMouseHoverOverPrimitives:o})=>{const[B,C]=gA.useState([]),[Q,i]=gA.useState({x:0,y:0}),[E,{width:n,height:s}]=HIA(),r=gA.useMemo(()=>nSI(e),[e]);gA.useEffect(()=>{C([]),o([])},[t,e,o]);const a=gA.useMemo(()=>{const h=[];for(const l of B){if(l._element?.type==="pcb_via"||l._element?.type==="pcb_component"||l?.layer==="drill"||l?.is_hoverable===!1)continue;let D=null,d=0,y=0;if(l.pcb_drawing_type==="polygon"){const m=cwA(l.points);if(!m)continue;D=m.center,d=m.width,y=m.height}else if(l.pcb_drawing_type==="polygon_with_arcs"){const m=l.brep_shape.outer_ring.vertices.map(k=>({x:k.x,y:k.y})),p=cwA(m);if(!p)continue;D=p.center,d=p.width,y=p.height}else l.pcb_drawing_type==="line"?(D={x:(l.x1+l.x2)/2,y:(l.y1+l.y2)/2},d=Math.abs(l.x2-l.x1),y=Math.abs(l.y2-l.y1)):"x"in l&&"y"in l&&(D={x:l.x,y:l.y},d="w"in l?l.w:"r"in l?l.r*2:"rX"in l&&"rY"in l?l.rX*2:0,y="h"in l?l.h:"r"in l?l.r*2:"rX"in l&&"rY"in l?l.rY*2:0);if(!D)continue;const w=Mt(I,D),u={w:d*I.a,h:y*I.a},G=h.filter(m=>w.x===m.screen_x&&w.y===m.screen_y&&u.w===m.screen_w&&u.h===m.screen_h).length;h.push({...l,x:D.x,y:D.y,w:d,h:y,screen_x:w.x,screen_y:w.y,screen_w:u.w,screen_h:u.h,same_space_index:G})}return h},[B,I]),c=({screenPoint:h,transform:l})=>{const{x:D,y:d}=h;i({x:D,y:d});const y=Mt(Gx(l),{x:D,y:d}),w=sSI({point:y,realToScreenScale:l.a,spatialIndex:r}),u=hIg({primitives:w,rwPoint:y,selectedLayer:t,transform:l});loo(new Set(u.map(G=>G._pcb_drawing_object_id)),new Set(B.map(G=>G._pcb_drawing_object_id)))||(C(u),o(u))};return W.jsxs("div",{ref:E,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:h=>{if(h.buttons===0&&I){const l=h.currentTarget.getBoundingClientRect(),D=h.clientX-l.left,d=h.clientY-l.top;c({screenPoint:{x:D,y:d},transform:I})}},onTouchStart:h=>{if(I){const l=h.touches[0],D=h.currentTarget.getBoundingClientRect(),d=l.clientX-D.left,y=l.clientY-D.top;c({screenPoint:{x:d,y},transform:I})}},children:[A,W.jsx(foo,{elements:g,mousePos:Q,highlightedPrimitives:a}),I&&W.jsxs(W.Fragment,{children:[W.jsx(doo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s}),W.jsx(yoo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s}),W.jsx(uoo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s}),W.jsx(Goo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s})]})]})},t2I=["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)"];function o2I(g){if("parent_source_group_id"in g)return typeof g.parent_source_group_id=="string"?g.parent_source_group_id:void 0}function lIg(g,A){const I=[],e=A.get(g)??[];for(const t of e)I.push(t),I.push(...lIg(t,A));return I}function B2I(g,A){const I=A.get(g);if(!I)return 0;const e=o2I(I);return e?1+B2I(e,A):0}var Noo=({children:g,transform:A=aJ(),elements:I=[],hoveredComponentIds:e=[]})=>{const[t,{width:o,height:B}]=HIA(),C=gA.useRef(null),{is_showing_pcb_groups:Q,pcb_group_view_mode:i,is_showing_group_anchor_offsets:E}=Qi(a=>({is_showing_pcb_groups:a.is_showing_pcb_groups,pcb_group_view_mode:a.pcb_group_view_mode,is_showing_group_anchor_offsets:a.is_showing_group_anchor_offsets})),{pcbComponents:n,pcbGroups:s,sourceGroups:r}=gA.useMemo(()=>{const a=[],c=[],h=[];for(const l of I)l.type==="pcb_component"?a.push(l):l.type==="pcb_group"?c.push(l):l.type==="source_group"&&h.push(l);return{pcbComponents:a,pcbGroups:c,sourceGroups:h}},[I]);return gA.useEffect(()=>{const a=C.current;if(!a||!o||!B)return;a.width=o,a.height=B;const c=a.getContext("2d");if(!c||(c.clearRect(0,0,o,B),!Q))return;const h=new Map(r.map(y=>[y.source_group_id,y])),l=s.filter(y=>{if(y.name?.toLowerCase().includes("subpanel"))return!1;if(i==="all")return!0;if(!y.source_group_id)return!1;const w=h.get(y.source_group_id);return w?w.was_automatically_named!==!0:!1}),D=new Map;r.forEach(y=>{const w=o2I(y);if(w){const u=D.get(w)??[];u.push(y.source_group_id),D.set(w,u)}});const d=new Set;if(e.length>0)for(const y of n){if(!e.includes(y.pcb_component_id))continue;const w=y.positioned_relative_to_pcb_group_id??y.pcb_group_id;w&&d.add(w)}l.forEach((y,w)=>{let u=n.filter(NA=>NA.pcb_group_id===y.pcb_group_id);if(y.source_group_id){const NA=lIg(y.source_group_id,D),RA=s.filter(UA=>UA.source_group_id&&NA.includes(UA.source_group_id));for(const UA of RA){const bA=n.filter(PA=>PA.pcb_group_id===UA.pcb_group_id);u=[...u,...bA]}}let G,m,p,k,S=!1;if(y.center&&y.width&&y.height){S=!0;const NA=y.width/2,RA=y.height/2;G=y.center.x-NA,p=y.center.x+NA,m=y.center.y-RA,k=y.center.y+RA}else if(u.length===0||(G=1/0,m=1/0,p=-1/0,k=-1/0,u.forEach(NA=>{if(NA.center&&typeof NA.width=="number"&&typeof NA.height=="number"){const RA=NA.center.x-NA.width/2,UA=NA.center.x+NA.width/2,bA=NA.center.y+NA.height/2,PA=NA.center.y-NA.height/2;G=Math.min(G,RA),p=Math.max(p,UA),m=Math.min(m,PA),k=Math.max(k,bA)}}),G===1/0||p===-1/0))return;const R=y.source_group_id?B2I(y.source_group_id,h):0,F=y.source_group_id?lIg(y.source_group_id,D).length>0:!1;if(!S){const UA=1+(F?.5:0);G-=UA,p+=UA,m-=UA,k+=UA}const N=Mt(A,{x:G,y:k}),U=Mt(A,{x:p,y:k}),L=Mt(A,{x:G,y:m}),b=Mt(A,{x:p,y:m}),H=t2I[w%t2I.length];c.strokeStyle=H,c.lineWidth=2;const q=Math.max(4,Math.min(12,8*Math.abs(A.a))),j=Math.max(2,Math.min(6,4*Math.abs(A.a))),O=q*(F?1.3:1),AA=j;c.setLineDash([O,AA]),c.beginPath(),c.moveTo(N.x,N.y),c.lineTo(U.x,U.y),c.lineTo(b.x,b.y),c.lineTo(L.x,L.y),c.closePath(),c.stroke();const tA=Math.max(8,Math.min(12,10*Math.abs(A.a))),eA=R===0||R===1?0:R*.11,QA=tA*(1-eA),sA=4,DA=y.name||`Group ${w+1}`;c.font=`${QA}px sans-serif`,c.setLineDash([]);const hA=c.measureText(DA).width+sA*2,nA=QA+sA*2,cA=N.x-5,fA=N.y-5,FA=3;if(c.fillStyle="rgba(0, 0, 0, 0.8)",c.beginPath(),c.roundRect(cA,fA-nA,hA,nA,FA),c.fill(),c.fillStyle=H,c.textAlign="left",c.textBaseline="middle",c.fillText(DA,cA+sA,fA-nA/2),E&&d.has(y.pcb_group_id)&&!!y.anchor_position&&y.anchor_position){const NA=Array.isArray(y.anchor_position)?{x:y.anchor_position[0]??0,y:y.anchor_position[1]??0}:{x:y.anchor_position.x,y:y.anchor_position.y},RA=Mt(A,NA);c.strokeStyle="white",c.lineWidth=1.5,c.setLineDash([]);const UA=Math.max(4,Math.min(8,6*Math.abs(A.a)));c.beginPath(),c.moveTo(RA.x-UA,RA.y),c.lineTo(RA.x+UA,RA.y),c.stroke(),c.beginPath(),c.moveTo(RA.x,RA.y-UA),c.lineTo(RA.x,RA.y+UA),c.stroke()}})},[B,Q,E,e,n,s,i,r,A,o]),W.jsxs("div",{ref:t,style:{position:"relative",width:"100%",height:"100%"},children:[g,W.jsx("canvas",{ref:C,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Da.pcbGroupOverlay,display:Q?"block":"none"}})]})},xoo=({transform:g,soup:A,connectivityMap:I,children:e})=>{const t=Qi(Q=>Q.is_showing_rats_nest),{netMap:o,idToNetMap:B}=I,C=gA.useMemo(()=>{if(!A||!t)return[];const Q=r=>{const a=p5(A)[r.replace(/_\d+$/,"")].get(r);return a&&"x"in a&&"y"in a?{x:a.x,y:a.y}:null},i=(r,a)=>{const c=o[a]||[];let h=null,l=1/0;return c.forEach(D=>{const d=Q(D);if(d){const y=Math.sqrt((r.x-d.x)**2+(r.y-d.y)**2);y<l&&y>0&&(l=y,h=d)}}),h},E=p5(A).pcb_port.list(),n=p5(A).source_trace.list(),s=[];return E.forEach((r,a)=>{const c=B[r.pcb_port_id];let h=!1;for(const d of n)d.connected_source_port_ids.includes(r.source_port_id)&&d.connected_source_net_ids.length>0&&(h=!0);if(!c)return;const l={x:r.x,y:r.y},D=i(l,c);D&&s.push({key:`${r.pcb_port_id}-${a}`,startPoint:l,endPoint:D,isInNet:h})}),s},[A,o,B,t]);return!A||!t?e:(g||(g=aJ()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Da.ratsNestOverlay},children:C.map(({key:Q,startPoint:i,endPoint:E,isInNet:n})=>{const s=Mt(g,i),r=Mt(g,E);return W.jsx("line",{x1:s.x,y1:s.y,x2:r.x,y2:r.y,stroke:"white",strokeWidth:"1",strokeDasharray:n?"6,6":void 0},Q)})})]}))},Nx=(g,A,I)=>{const e=Qi(B=>B.is_mouse_over_container),t=gA.useRef(e),o=gA.useRef(A);gA.useEffect(()=>{t.current=e},[e]),gA.useEffect(()=>{o.current=A},[A]),gA.useEffect(()=>{if(!g)return;const B=C=>{const Q=C.target;if(Q.tagName==="INPUT"||Q.tagName==="TEXTAREA"||Q.isContentEditable)return;const i=g.split("+"),E=i.includes("ctrl"),n=i.includes("shift"),s=i.includes("alt"),r=i.includes("meta"),a=i[i.length-1],c=I?.current?I.current.contains(document.activeElement)||document.activeElement===I.current:!1;(t.current||c)&&(!E||C.ctrlKey)&&(!n||C.shiftKey)&&(!s||C.altKey)&&(!r||C.metaKey)&&C.key.toLowerCase()===a.toLowerCase()&&(C.preventDefault(),o.current())};return window.addEventListener("keydown",B),()=>{window.removeEventListener("keydown",B)}},[g])},Foo=()=>{const[g,A]=gA.useState(!1);return gA.useEffect(()=>{const I=()=>{A(window.innerWidth<=768)};return I(),window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[]),g},TIA=(g,A={stopPropagation:!0})=>{const I=gA.useRef(0),e=gA.useCallback(B=>{A.stopPropagation&&B.stopPropagation();const C=Date.now();C-I.current<300||(I.current=C,g?.(B))},[g,A.stopPropagation]),t=gA.useCallback(B=>{B.preventDefault(),e(B)},[e]);return{onClick:e,onTouchEnd:t,style:{touchAction:"manipulation"}}},Uoo={version:"1.11.430"},Z7=({children:g,isSmallScreen:A,onClick:I,...e})=>{const{style:t,...o}=TIA(I);return W.jsx("div",{...e,...o,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:A?8:6,paddingRight:A?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...t,...e.style},children:g})},Joo=g=>{const A=new Map;return g.forEach((I,e)=>{const t=I.error_type||"unknown_error",o=A.get(t)||[];o.push({error:I,index:e,errorId:q7(I,e)}),A.set(t,o)}),Array.from(A.entries()).map(([I,e])=>({errorType:I,errors:e}))},Koo=({onClose:g,setHoveredErrorId:A,setFocusedErrorId:I,highlightDurationMs:e=3e3})=>{const t=gA.useRef(null),o=gA.useRef(null),B=gA.useRef(null),C=gA.useCallback(()=>{t.current!==null&&(window.clearTimeout(t.current),t.current=null),o.current!==null&&(window.cancelAnimationFrame(o.current),o.current=null)},[]);gA.useEffect(()=>C,[C]);const Q=gA.useCallback(E=>{C(),B.current=E,A(E),I(null),o.current=window.requestAnimationFrame(()=>{I(E),o.current=null}),g(),t.current=window.setTimeout(()=>{B.current=null,A(null),I(null),t.current=null},e)},[C,e,g,I,A]),i=gA.useCallback(E=>B.current===E,[]);return{handleErrorSelect:Q,isSelectedError:i}},Poo=({errorId:g,errorMessage:A,copiedErrorId:I,onCopy:e})=>{const{style:t,...o}=TIA(()=>e(A,g));return W.jsx("button",{type:"button","aria-label":I===g?"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",...t},...o,children:I===g?W.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:W.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},Loo=({elements:g,isOpen:A,isSmallScreen:I,onToggle:e,onClose:t,setHoveredErrorId:o,setFocusedErrorId:B})=>{const[C,Q]=gA.useState(null),[i,E]=gA.useState(new Set),[n,s]=gA.useState(new Set),[,r]=qIo(),{handleErrorSelect:a,isSelectedError:c}=Koo({onClose:t,setHoveredErrorId:o,setFocusedErrorId:B}),h=gA.useMemo(()=>g?.filter(w=>w.type.includes("error"))??[],[g]),l=h.length,D=gA.useMemo(()=>Joo(h),[h]),d=gA.useCallback(w=>{E(u=>{const G=new Set(u);return G.has(w)?G.delete(w):G.add(w),G})},[]),y=gA.useCallback(w=>{s(u=>{const G=new Set(u);return G.has(w)?G.delete(w):G.add(w),G})},[]);return W.jsxs("div",{style:{position:"relative"},children:[W.jsx(Z7,{isSmallScreen:I,style:l>0?{color:"red"}:void 0,onClick:e,children:W.jsxs("div",{children:[l," errors"]})}),A&&l>0&&W.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:I?"280px":"400px",maxWidth:I?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:D.map(({errorType:w,errors:u},G)=>{const m=i.has(w);return W.jsxs("div",{style:{borderBottom:G<D.length-1?"1px solid #444":"none"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:p=>{p.currentTarget.style.backgroundColor="#303030"},onMouseLeave:p=>{p.currentTarget.style.backgroundColor="#232323"},onTouchStart:p=>{p.stopPropagation(),p.currentTarget.style.backgroundColor="#303030"},onTouchEnd:p=>{p.stopPropagation(),p.preventDefault(),p.currentTarget.style.backgroundColor="#232323",d(w)},onClick:p=>{p.stopPropagation(),d(w)},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[W.jsx("div",{style:{color:"#888",fontSize:"16px",transform:m?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),W.jsx("div",{style:{fontWeight:"bold",fontSize:I?"12px":"13px"},children:w})]}),W.jsx("div",{style:{fontSize:I?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:u.length})]}),!m&&u.map(({error:p,index:k,errorId:S})=>{const R=n.has(S),F=p.message??"No error message";return W.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:N=>{N.currentTarget.style.backgroundColor="#333",o(S)},onMouseLeave:N=>{N.currentTarget.style.backgroundColor="#2a2a2a",c(S)||o(null)},onTouchStart:N=>{N.stopPropagation(),N.currentTarget.style.backgroundColor="#333",o(S)},onTouchEnd:N=>{N.stopPropagation(),N.preventDefault(),N.currentTarget.style.backgroundColor="#2a2a2a",a(S)},onClick:N=>{N.stopPropagation(),a(S)},children:[W.jsx("div",{style:{flex:1,fontSize:I?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:F}),W.jsx("button",{type:"button","aria-label":R?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:R?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:N=>N.stopPropagation(),onClick:N=>{N.stopPropagation(),y(S)},onTouchEnd:N=>{N.stopPropagation(),N.preventDefault(),y(S)},children:"›"})]}),R&&W.jsxs("div",{"data-error-id":k,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[W.jsx("div",{style:{fontSize:I?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:N=>N.stopPropagation(),onClick:N=>N.stopPropagation(),children:F}),W.jsx(Poo,{errorId:S,errorMessage:F,copiedErrorId:C,onCopy:(N,U)=>{r(N),Q(U),setTimeout(()=>Q(null),2e3)}})]})]},S)})]},w)})})]})},C2I=gA.createContext(null),Yoo=()=>gA.useContext(C2I),ZIA=F7`
5432
+ `,aoo=[];function roo(g){return g.type==="source_component"?g.source_component_id:g.type==="pcb_component"?g.pcb_component_id:"component"}var coo=({children:g,transform:A=aJ(),elements:I})=>{const e=gA.useRef(null),{isShowingDRCErrors:t,hoveredErrorId:o,focusedErrorId:B}=Qi(l=>({isShowingDRCErrors:l.is_showing_drc_errors,hoveredErrorId:l.hovered_error_id,focusedErrorId:l.focused_error_id})),C=B??o,Q=I??aoo,i=gA.useMemo(()=>Q.filter(l=>l.type==="pcb_trace_error"&&!l.message?.includes("Multiple components found with name")),[Q]),E=gA.useMemo(()=>Q.filter(l=>l.type==="pcb_via_clearance_error"),[Q]),n=gA.useMemo(()=>Q.filter(l=>l.type==="pcb_trace_error"&&!!l.message?.includes("Multiple components found with name")),[Q]),s=gA.useMemo(()=>aSI(Q),[Q]),r=gA.useMemo(()=>DSI(Q,C),[C,Q]),a=gA.useMemo(()=>n.map((l,D)=>{const d=("component_name"in l&&typeof l.component_name=="string"?l.component_name:void 0)??l.message?.match(/name "([^"]+)"/)?.[1];return d?{components:Q.filter(w=>w.type==="source_component"&&w.name===d||w.type==="pcb_component"&&Q.some(u=>u.type==="source_component"&&u.source_component_id===w.source_component_id&&u.name===d)),error:l,errorIndex:D}:{components:[],error:l,errorIndex:D}}),[n,Q]);if(!I)return W.jsx("div",{style:{position:"relative"},ref:e,children:g});const c=l=>{const D=meo({error:l,indexes:s});if(!D||typeof D.x!="number"||typeof D.y!="number")return null;const d=Mt(A,D);return Number.isNaN(d.x)||Number.isNaN(d.y)?null:d};let h=null;return r&&(h=c(r)),W.jsxs("div",{style:{position:"relative"},ref:e,children:[g,i.map((l,D)=>{const d=q7(l,D),y=C===d;if(!y&&!t)return null;const w=c(l);if(!w)return null;const u=sIg(w,e);return W.jsxs(gA.Fragment,{children:[W.jsx(A2I,{errorCenter:w,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Da.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="1")}},onMouseLeave:G=>{if(!y){const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:u.left,top:u.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:t||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:u.transform},children:W.jsx("div",{className:`error-message ${aIg}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},d)}),E.map((l,D)=>{const d=q7(l,D),y=C===d;if(!y&&!t)return null;const w=c(l);if(!w)return null;const u=sIg({x:w.x,y:w.y},e);return W.jsxs(gA.Fragment,{children:[W.jsx(A2I,{errorCenter:w,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:Da.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="1")}},onMouseLeave:G=>{if(!y){const m=G.currentTarget.nextElementSibling;if(m){const p=m.querySelector(".error-message");p&&(p.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?Da.errorOverlay+10:Da.errorOverlay+1,left:u.left,top:u.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:u.transform},children:W.jsx("div",{className:`error-message ${aIg}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:l.message})})]},d)}),a.map(({components:l,error:D,errorIndex:d})=>{const y=q7(D,d),w=C===y;return!w&&!t?null:l.map(u=>{let G={x:0,y:0};if(u.type==="pcb_component")G=u.center||{x:0,y:0};else if(u.type==="source_component"){const U=I?.find(L=>L.type==="pcb_component"&&L.source_component_id===u.source_component_id);U&&U.type==="pcb_component"&&(G=U.center||{x:0,y:0})}const m=Mt(A,G);if(Number.isNaN(m.x)||Number.isNaN(m.y))return null;const p=Math.abs(A.a),F=Math.max(8,Math.min(30,.5*p)),N=sIg(m,e);return W.jsxs(gA.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Da.errorOverlay},width:"100%",height:"100%",children:w?W.jsx("polygon",{points:`${m.x},${m.y-F*1.25} ${m.x+F},${m.y} ${m.x},${m.y+F*1.25} ${m.x-F},${m.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:m.x,cy:m.y,r:F,fill:"none",stroke:w?"#ff4444":"red",strokeWidth:w?Math.max(2,F*.15):Math.max(1,F*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:m.x-(F+10),top:m.y-(F+10),width:(F+10)*2,height:(F+10)*2,zIndex:Da.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:U=>{const L=U.currentTarget.nextElementSibling;if(L){const b=L.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:U=>{if(!w){const L=U.currentTarget.nextElementSibling;if(L){const b=L.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:w?Da.errorOverlay+20:Da.errorOverlay+10,left:N.left,top:N.top,color:w?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:t||w?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:N.transform},children:W.jsx("div",{className:`error-message ${aIg}`,style:{opacity:w?1:0,border:`1px solid ${w?"#ff4444":"red"}`},children:D.message})})]},`${y}_${u.type}_${roo(u)}`)})}),h&&W.jsx(soo,{center:h})]})},g2I=(g,A,I,e)=>{if(I<=0||e<=0)return;const t=g.find(B=>B.type==="pcb_component"&&B.pcb_component_id===A);if(t?.type!=="pcb_component")return;const o=zMI(t);if(o)return{component:t,bounds:o,transform:lSI({bounds:o,width:I,height:e})}},hoo=({focusRequest:g,elements:A,transform:I})=>{const e=g?.pcbComponentId,t=Qi(E=>E.selectLayer),o=e?g2I(A,e,1,1):void 0,B=o?.component.layer;if(gA.useEffect(()=>{B&&t(B)},[g,B,t]),!o||!I)return null;const{bounds:C}=o,Q=Mt(I,{x:C.minX,y:C.minY}),i=Mt(I,{x:C.maxX,y:C.maxY});return W.jsx("div",{"data-focused-pcb-component-id":e,style:{position:"absolute",left:Math.min(Q.x,i.x)-4,top:Math.min(Q.y,i.y)-4,width:Math.abs(i.x-Q.x)+8,height:Math.abs(i.y-Q.y)+8,border:"2px solid #3399ff",borderRadius:4,boxSizing:"border-box",pointerEvents:"none",zIndex:Da.elementOverlay}})};function loo(g,A){return g.size!==A.size?!1:Array.from(g).every(I=>A.has(I))}var ec={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},$M={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},rIg=({targets:g,transform:A,containerWidth:I,containerHeight:e})=>{if(g.length===0)return null;const t={color:$M.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:ec.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return g.forEach(B=>{if(!o.has(B.anchor_id)){const C=Mt(A,B.anchor);o.set(B.anchor_id,C)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:I,height:e,overflow:"hidden",pointerEvents:"none",zIndex:Da.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:I,height:e,children:[g.map(B=>{const C=B.anchor,Q=B.anchor_id,i=B.target,E=o.get(Q),n=Mt(A,i),s=i.x-C.x,r=i.y-C.y,a=Math.abs(n.x-E.x),c=Math.abs(n.y-E.y),h=n.y<E.y,l=n.x>E.x,D=h?ec.LABEL_OFFSET_ABOVE:ec.LABEL_OFFSET_BELOW,d=l?ec.LABEL_OFFSET_RIGHT:ec.LABEL_OFFSET_LEFT,y=a>ec.MIN_LINE_LENGTH_FOR_LABEL,w=c>ec.MIN_LINE_LENGTH_FOR_LABEL,u=`${B.display_offset_x??s.toFixed(2)}mm`,G=`${B.display_offset_y??r.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:E.x,y1:E.y,x2:n.x,y2:E.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.LINE_STROKE_WIDTH,strokeDasharray:ec.LINE_DASH_PATTERN}),W.jsx("line",{x1:n.x,y1:E.y,x2:n.x,y2:n.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.LINE_STROKE_WIDTH,strokeDasharray:ec.LINE_DASH_PATTERN}),B.type==="component"||B.type==="board"?W.jsx("circle",{cx:n.x,cy:n.y,r:ec.COMPONENT_MARKER_RADIUS,fill:$M.COMPONENT_MARKER_FILL,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:n.x-ec.ANCHOR_MARKER_SIZE,y1:n.y,x2:n.x+ec.ANCHOR_MARKER_SIZE,y2:n.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:n.x,y1:n.y-ec.ANCHOR_MARKER_SIZE,x2:n.x,y2:n.y+ec.ANCHOR_MARKER_SIZE,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH})]}),y&&W.jsx("foreignObject",{x:Math.min(E.x,n.x),y:E.y+D,width:Math.abs(n.x-E.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...t,textAlign:"center"},children:u})}),w&&W.jsx("foreignObject",{x:n.x+d,y:Math.min(E.y,n.y),width:ec.Y_LABEL_MIN_WIDTH,height:Math.abs(n.y-E.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...t,display:"flex",alignItems:"center",justifyContent:l?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:G})})]},B.id)}),Array.from(o.entries()).map(([B,C])=>W.jsxs("g",{children:[W.jsx("line",{x1:C.x-ec.ANCHOR_MARKER_SIZE,y1:C.y,x2:C.x+ec.ANCHOR_MARKER_SIZE,y2:C.y,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:C.x,y1:C.y-ec.ANCHOR_MARKER_SIZE,x2:C.x,y2:C.y+ec.ANCHOR_MARKER_SIZE,stroke:$M.OFFSET_LINE,strokeWidth:ec.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${B}`))]})})},S3=g=>g?.type==="pcb_component",I2I=g=>g?.type==="pcb_group",Doo=g=>g?.type==="pcb_panel",cIg=g=>g?.type==="pcb_board",doo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=Qi(l=>l.is_showing_group_anchor_offsets),B=A.map(l=>S3(l._parent_pcb_component)?l._parent_pcb_component.pcb_component_id:S3(l._element)?l._element.pcb_component_id:null).filter(l=>!!l);if(!o&&B.length===0)return null;const C=g.filter(l=>cIg(l)),Q=g.filter(l=>S3(l)),i=g.filter(l=>I2I(l)),E=new Set;B.forEach(l=>{const D=Q.find(d=>d.pcb_component_id===l);D?.pcb_group_id&&E.add(D.pcb_group_id)});const n=Q.map(l=>{const D=l.positioned_relative_to_pcb_board_id;if(!D)return null;const d=C.find(y=>y.pcb_board_id===D);return d?{component:l,board:d,type:"component"}:null}).filter(l=>!!l),s=i.map(l=>{const D=l.positioned_relative_to_pcb_board_id;if(!D||!l.center)return null;const d=C.find(y=>y.pcb_board_id===D);return d?{group:l,board:d,type:"group"}:null}).filter(l=>!!l),r=[...n,...s];if(r.length===0)return null;const a=B.length===0,c=r.filter(l=>l.type==="component"?a||B.includes(l.component.pcb_component_id):a||E.has(l.group.pcb_group_id));if(c.length===0)return null;const h=c.map(l=>l.type==="component"?{id:`${l.board.pcb_board_id}-${l.component.pcb_component_id}-${l.type}`,anchor:l.board.center,anchor_id:l.board.pcb_board_id,target:l.component.center,type:"component",display_offset_x:l.component.display_offset_x,display_offset_y:l.component.display_offset_y}:{id:`${l.board.pcb_board_id}-${l.group.pcb_group_id}-${l.type}`,anchor:l.board.center,anchor_id:l.board.pcb_board_id,target:{x:l.group.anchor_position?.x??l.group.center.x,y:l.group.anchor_position?.y??l.group.center.y},type:"group",display_offset_x:l.group.display_offset_x,display_offset_y:l.group.display_offset_y}).filter(l=>!!l);return W.jsx(rIg,{targets:h,transform:I,containerWidth:e,containerHeight:t})},yoo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=Qi(l=>l.is_showing_group_anchor_offsets),B=A.map(l=>S3(l._parent_pcb_component)?l._parent_pcb_component.pcb_component_id:S3(l._element)?l._element.pcb_component_id:null).filter(l=>!!l);if(!o&&B.length===0)return null;const C=g.filter(l=>I2I(l)),Q=g.filter(l=>S3(l)),i=(l,D)=>{if(D.has(l))return;D.add(l);const d=C.find(y=>y.pcb_group_id===l);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&i(d.positioned_relative_to_pcb_group_id,D)},E=new Set;B.forEach(l=>{const D=Q.find(d=>d.pcb_component_id===l);D&&(D.position_mode==="relative_to_group_anchor"&&D.positioned_relative_to_pcb_group_id&&i(D.positioned_relative_to_pcb_group_id,E),D.pcb_group_id&&i(D.pcb_group_id,E))});const n=Q.map(l=>{if(l.position_mode==="relative_to_group_anchor"&&l.positioned_relative_to_pcb_group_id){const D=C.find(d=>d.pcb_group_id===l.positioned_relative_to_pcb_group_id);return D?.anchor_position?{component:l,parentGroup:D,type:"component"}:null}if(l.pcb_group_id){const D=C.find(d=>d.pcb_group_id===l.pcb_group_id);return D?.anchor_position?{component:l,parentGroup:D,type:"component"}:null}return null}).filter(l=>!!l),s=C.map(l=>{if(l.position_mode==="relative_to_group_anchor"&&l.positioned_relative_to_pcb_group_id){const D=C.find(d=>d.pcb_group_id===l.positioned_relative_to_pcb_group_id);if(D?.anchor_position&&l.anchor_position)return{group:l,parentGroup:D,type:"group"}}return null}).filter(l=>!!l),r=[...n,...s];if(r.length===0)return null;const a=B.length===0,c=r.filter(l=>l.type==="component"?a||B.includes(l.component.pcb_component_id):a||E.has(l.group.pcb_group_id)||E.has(l.parentGroup.pcb_group_id));if(c.length===0)return null;const h=c.map(l=>{const D=l.parentGroup.anchor_position;return D?l.type==="component"?l.component.center?{id:`${l.parentGroup.pcb_group_id}-${l.component.pcb_component_id}-${l.type}`,anchor:D,anchor_id:l.parentGroup.pcb_group_id,target:l.component.center,type:"component",display_offset_x:l.component.display_offset_x,display_offset_y:l.component.display_offset_y}:null:l.group.anchor_position?{id:`${l.parentGroup.pcb_group_id}-${l.group.pcb_group_id}-${l.type}`,anchor:D,anchor_id:l.parentGroup.pcb_group_id,target:l.group.anchor_position,type:"group",display_offset_x:l.group.display_offset_x,display_offset_y:l.group.display_offset_y}:null:null}).filter(l=>!!l);return W.jsx(rIg,{targets:h,transform:I,containerWidth:e,containerHeight:t})},woo=(g,A)=>{const I=g.pcb_component_id,e=A.filter(t=>(t.type==="pcb_smtpad"||t.type==="pcb_plated_hole")&&t.pcb_component_id===I||t.type==="pcb_hole"&&t.pcb_component_id===I);return e.length===0?CIg([g]):CIg(e)},uoo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=new Map;for(const C of A)S3(C._parent_pcb_component)&&o.set(C._parent_pcb_component.pcb_component_id,C._parent_pcb_component),S3(C._element)&&o.set(C._element.pcb_component_id,C._element);if(o.size===0)return null;const B=[];for(const C of o.values()){const Q=woo(C,g);if(!Q)continue;const i=C.positioned_relative_to_pcb_group_id??C.pcb_group_id,E=i?p5(g).pcb_group.get(i):null;B.push({component:C,bbox:Q,group:E})}return B.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:t,overflow:"hidden",pointerEvents:"none",zIndex:Da.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:t,children:B.map(({component:C,bbox:Q,group:i})=>{const E=Mt(I,{x:Q.minX,y:Q.maxY}),n=Mt(I,{x:Q.maxX,y:Q.minY}),s={x:Math.min(E.x,n.x),y:Math.min(E.y,n.y),width:Math.abs(n.x-E.x),height:Math.abs(n.y-E.y)},r=C.center??{x:(Q.minX+Q.maxX)/2,y:(Q.minY+Q.maxY)/2},a=Mt(I,r);return W.jsxs("g",{children:[W.jsx("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:a.x-6,y1:a.y,x2:a.x+6,y2:a.y,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:a.x,y1:a.y-6,x2:a.x,y2:a.y+6,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:a.x,cy:a.y,r:ec.COMPONENT_MARKER_RADIUS,fill:$M.COMPONENT_MARKER_FILL,stroke:$M.COMPONENT_MARKER_STROKE,strokeWidth:1})]},C.pcb_component_id)})})})},Goo=({elements:g,highlightedPrimitives:A,transform:I,containerWidth:e,containerHeight:t})=>{const o=Qi(r=>r.is_showing_group_anchor_offsets),B=A.map(r=>cIg(r._element)?r._element.pcb_board_id:null).filter(r=>!!r);if(!o&&B.length===0)return null;const C=g.filter(r=>Doo(r)),i=g.filter(r=>cIg(r)).map(r=>{const a=r.pcb_panel_id,c=r.position_mode;if(!a||c!=="relative_to_panel_anchor")return null;const h=C.find(l=>l.pcb_panel_id===a);return h?{board:r,panel:h,type:"board"}:null}).filter(r=>!!r);if(i.length===0)return null;const E=B.length===0,n=i.filter(r=>E||B.includes(r.board.pcb_board_id));if(n.length===0)return null;const s=n.map(r=>r.board.center?{id:`${r.panel.pcb_panel_id}-${r.board.pcb_board_id}-${r.type}`,anchor:r.panel.center,anchor_id:r.panel.pcb_panel_id,target:r.board.center,type:"board",display_offset_x:r.board.display_offset_x,display_offset_y:r.board.display_offset_y}:null).filter(r=>!!r);return W.jsx(rIg,{targets:s,transform:I,containerWidth:e,containerHeight:t})};function moo(g){const{primitives:A,is_showing_multiple_traces_length:I,traceOverlayElementIndex:e}=g,t=A.filter(C=>C._element.type==="pcb_trace"),o=A.filter(C=>C._element.type!=="pcb_trace"),B=t.filter(C=>(C._element.source_trace_id?e.sourceTraceById.get(C._element.source_trace_id):void 0)?.max_length!==void 0||EIg({primitiveElement:C._element,traceOverlayElementIndex:e})!==null);if(!I)return[...o,...B];if(t.length>1){const C=t.reduce((Q,i)=>{const E=Q._element.trace_length;return i._element.trace_length<E?i:Q},t[0]);return[...o,C]}return A}var poo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},koo=g=>{const{_element:A,_parent_pcb_component:I,_parent_source_component:e,_source_port:t}=g;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],B=Array.from(new Set((A.port_hints??[]).concat(t?.port_hints??[]))).filter(Q=>!/^[0-9]+$/.test(Q)).filter(Q=>!Q.includes("unnamed_")).sort((Q,i)=>i.localeCompare(Q)),C=e&&"name"in e&&e.name&&!e.name.includes("unnamed_")?e.name:null;return B.length>0?C?o.push(...B.map(Q=>`${C}.${Q}`)):o.push(...B):C&&o.push(C),o.join(", ")}default:return""}},Moo={top:"red",bottom:"aqua"},Soo=({primitive:g,mousePos:A,traceOverlayElementIndex:I})=>{const[e,t]=gA.useState(!1),o=g._element;gA.useEffect(()=>{setTimeout(()=>{t(!0)},100)},[]);const[B,C,Q,i]=[g.screen_x,g.screen_y,g.screen_w,g.screen_h],E=g.same_space_index??0,n=26,s=Moo[g?._element?.layer]??"red";let r=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?r=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in g||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in g)&&(r=o.ccw_rotation??0),o.type==="pcb_trace"){const h=wSI({primitiveElement:o,traceOverlayElementIndex:I});return h?W.jsx("div",{style:{zIndex:Da.elementOverlay,position:"absolute",left:A.x+12,top:A.y+12,color:s,pointerEvents:"none"},children:W.jsxs("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[h.text&&W.jsx("div",{children:h.text}),h.name&&W.jsx("div",{style:{marginTop:h.text?"2px":0},children:h.name})]})}):null}const a=koo(g);return a.trim().length===0?null:W.jsx("div",{style:{zIndex:Da.elementOverlay,position:"absolute",left:B-Q/2-8,top:C-i/2-8,width:Q+16,height:i+16,color:s,transform:`rotate(${-r}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:e?`calc(100% + ${n*2*E}px)`:"100%",height:e?`calc(100% + ${n*2*E}px)`:"100%",marginLeft:e?`${-n*E}px`:0,marginTop:e?`${-n*E}px`:0,border:`1px solid ${s}`,opacity:e||E===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:i+20+n*E,marginRight:e?`${-n*E}px`:0,marginBottom:e?0:-n*E,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(${r}deg)`,minWidth:"45px",textAlign:"center"},children:a})})})},foo=({highlightedPrimitives:g,mousePos:A,elements:I})=>{const[e,t]=Qi(Q=>[Q.is_moving_component,Q.is_showing_multiple_traces_length]),o=gA.useMemo(()=>ySI(I),[I]),B=g.some(Q=>Q._element.type==="pcb_smtpad")&&g.some(Q=>Q._element.type==="pcb_trace");let C=g;return B&&(C=C.filter(Q=>Q._element.type==="pcb_smtpad")),C=moo({primitives:C,is_showing_multiple_traces_length:t,traceOverlayElementIndex:o}),W.jsx("div",{style:poo,children:!e&&C.map(Q=>W.jsx(Soo,{primitive:Q,mousePos:A,traceOverlayElementIndex:o},Q._pcb_drawing_object_id))})},cwA=g=>{if(g.length===0)return null;let A=g[0].x,I=g[0].y,e=g[0].x,t=g[0].y;for(const o of g)o.x<A&&(A=o.x),o.y<I&&(I=o.y),o.x>e&&(e=o.x),o.y>t&&(t=o.y);return{center:{x:(A+e)/2,y:(I+t)/2},width:e-A,height:t-I}},e2I=(g,A)=>{if(A.length<3)return!1;let I=!1;for(let e=0,t=A.length-1;e<A.length;t=e++){const o=A[e].x,B=A[e].y,C=A[t].x,Q=A[t].y;B>g.y!=Q>g.y&&g.x<(C-o)*(g.y-B)/(Q-B||Number.EPSILON)+o&&(I=!I)}return I},hIg=({includeHiddenTraces:g=!1,primitives:A,rwPoint:I,selectedLayer:e,transform:t})=>{const o=[];for(const B of A){if(!B._element||!g&&B._element.type==="pcb_trace"&&B.layer!==e)continue;if("x1"in B&&B._element?.type==="pcb_trace"){const i=hh({x:I.x,y:I.y},{x:B.x1,y:B.y1},{x:B.x2,y:B.y2}),E=B.width||.5,n=Math.max(E*25,2)/t.a;i<n&&o.push(B);continue}if(B.pcb_drawing_type==="polygon"){const i=B.points.map(n=>({x:sg.parse(n.x),y:sg.parse(n.y)})),E=cwA(i);if(!E||I.x<E.center.x-E.width/2||I.x>E.center.x+E.width/2||I.y<E.center.y-E.height/2||I.y>E.center.y+E.height/2)continue;e2I(I,i)&&o.push(B);continue}if(B.pcb_drawing_type==="polygon_with_arcs"){const i=B.brep_shape.outer_ring.vertices.map(n=>({x:sg.parse(n.x),y:sg.parse(n.y)})),E=cwA(i);if(!E||I.x<E.center.x-E.width/2||I.x>E.center.x+E.width/2||I.y<E.center.y-E.height/2||I.y>E.center.y+E.height/2)continue;e2I(I,i)&&o.push(B);continue}if(!("x"in B&&"y"in B))continue;let C=0,Q=0;if("w"in B&&"h"in B)C=B.w,Q=B.h;else if("r"in B)C=B.r*2,Q=B.r*2;else if("rX"in B&&"rY"in B)C=B.rX*2,Q=B.rY*2;else continue;Math.abs(B.x-I.x)<C/2&&Math.abs(B.y-I.y)<Q/2&&o.push(B)}return o},Roo=({elements:g,children:A,transform:I,primitives:e,selectedLayer:t,onMouseHoverOverPrimitives:o})=>{const[B,C]=gA.useState([]),[Q,i]=gA.useState({x:0,y:0}),[E,{width:n,height:s}]=HIA(),r=gA.useMemo(()=>nSI(e),[e]);gA.useEffect(()=>{C([]),o([])},[t,e,o]);const a=gA.useMemo(()=>{const h=[];for(const l of B){if(l._element?.type==="pcb_via"||l._element?.type==="pcb_component"||l?.layer==="drill"||l?.is_hoverable===!1)continue;let D=null,d=0,y=0;if(l.pcb_drawing_type==="polygon"){const m=cwA(l.points);if(!m)continue;D=m.center,d=m.width,y=m.height}else if(l.pcb_drawing_type==="polygon_with_arcs"){const m=l.brep_shape.outer_ring.vertices.map(k=>({x:k.x,y:k.y})),p=cwA(m);if(!p)continue;D=p.center,d=p.width,y=p.height}else l.pcb_drawing_type==="line"?(D={x:(l.x1+l.x2)/2,y:(l.y1+l.y2)/2},d=Math.abs(l.x2-l.x1),y=Math.abs(l.y2-l.y1)):"x"in l&&"y"in l&&(D={x:l.x,y:l.y},d="w"in l?l.w:"r"in l?l.r*2:"rX"in l&&"rY"in l?l.rX*2:0,y="h"in l?l.h:"r"in l?l.r*2:"rX"in l&&"rY"in l?l.rY*2:0);if(!D)continue;const w=Mt(I,D),u={w:d*I.a,h:y*I.a},G=h.filter(m=>w.x===m.screen_x&&w.y===m.screen_y&&u.w===m.screen_w&&u.h===m.screen_h).length;h.push({...l,x:D.x,y:D.y,w:d,h:y,screen_x:w.x,screen_y:w.y,screen_w:u.w,screen_h:u.h,same_space_index:G})}return h},[B,I]),c=({screenPoint:h,transform:l})=>{const{x:D,y:d}=h;i({x:D,y:d});const y=Mt(Gx(l),{x:D,y:d}),w=sSI({point:y,realToScreenScale:l.a,spatialIndex:r}),u=hIg({primitives:w,rwPoint:y,selectedLayer:t,transform:l});loo(new Set(u.map(G=>G._pcb_drawing_object_id)),new Set(B.map(G=>G._pcb_drawing_object_id)))||(C(u),o(u))};return W.jsxs("div",{ref:E,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:h=>{if(h.buttons===0&&I){const l=h.currentTarget.getBoundingClientRect(),D=h.clientX-l.left,d=h.clientY-l.top;c({screenPoint:{x:D,y:d},transform:I})}},onTouchStart:h=>{if(I){const l=h.touches[0],D=h.currentTarget.getBoundingClientRect(),d=l.clientX-D.left,y=l.clientY-D.top;c({screenPoint:{x:d,y},transform:I})}},children:[A,W.jsx(foo,{elements:g,mousePos:Q,highlightedPrimitives:a}),I&&W.jsxs(W.Fragment,{children:[W.jsx(doo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s}),W.jsx(yoo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s}),W.jsx(uoo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s}),W.jsx(Goo,{elements:g,highlightedPrimitives:a,transform:I,containerWidth:n,containerHeight:s})]})]})},t2I=["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)"];function o2I(g){if("parent_source_group_id"in g)return typeof g.parent_source_group_id=="string"?g.parent_source_group_id:void 0}function lIg(g,A){const I=[],e=A.get(g)??[];for(const t of e)I.push(t),I.push(...lIg(t,A));return I}function B2I(g,A){const I=A.get(g);if(!I)return 0;const e=o2I(I);return e?1+B2I(e,A):0}var Noo=({children:g,transform:A=aJ(),elements:I=[],hoveredComponentIds:e=[]})=>{const[t,{width:o,height:B}]=HIA(),C=gA.useRef(null),{is_showing_pcb_groups:Q,pcb_group_view_mode:i,is_showing_group_anchor_offsets:E}=Qi(a=>({is_showing_pcb_groups:a.is_showing_pcb_groups,pcb_group_view_mode:a.pcb_group_view_mode,is_showing_group_anchor_offsets:a.is_showing_group_anchor_offsets})),{pcbComponents:n,pcbGroups:s,sourceGroups:r}=gA.useMemo(()=>{const a=[],c=[],h=[];for(const l of I)l.type==="pcb_component"?a.push(l):l.type==="pcb_group"?c.push(l):l.type==="source_group"&&h.push(l);return{pcbComponents:a,pcbGroups:c,sourceGroups:h}},[I]);return gA.useEffect(()=>{const a=C.current;if(!a||!o||!B)return;a.width=o,a.height=B;const c=a.getContext("2d");if(!c||(c.clearRect(0,0,o,B),!Q))return;const h=new Map(r.map(y=>[y.source_group_id,y])),l=s.filter(y=>{if(y.name?.toLowerCase().includes("subpanel"))return!1;if(i==="all")return!0;if(!y.source_group_id)return!1;const w=h.get(y.source_group_id);return w?w.was_automatically_named!==!0:!1}),D=new Map;r.forEach(y=>{const w=o2I(y);if(w){const u=D.get(w)??[];u.push(y.source_group_id),D.set(w,u)}});const d=new Set;if(e.length>0)for(const y of n){if(!e.includes(y.pcb_component_id))continue;const w=y.positioned_relative_to_pcb_group_id??y.pcb_group_id;w&&d.add(w)}l.forEach((y,w)=>{let u=n.filter(NA=>NA.pcb_group_id===y.pcb_group_id);if(y.source_group_id){const NA=lIg(y.source_group_id,D),RA=s.filter(UA=>UA.source_group_id&&NA.includes(UA.source_group_id));for(const UA of RA){const bA=n.filter(PA=>PA.pcb_group_id===UA.pcb_group_id);u=[...u,...bA]}}let G,m,p,k,S=!1;if(y.center&&y.width&&y.height){S=!0;const NA=y.width/2,RA=y.height/2;G=y.center.x-NA,p=y.center.x+NA,m=y.center.y-RA,k=y.center.y+RA}else if(u.length===0||(G=1/0,m=1/0,p=-1/0,k=-1/0,u.forEach(NA=>{if(NA.center&&typeof NA.width=="number"&&typeof NA.height=="number"){const RA=NA.center.x-NA.width/2,UA=NA.center.x+NA.width/2,bA=NA.center.y+NA.height/2,PA=NA.center.y-NA.height/2;G=Math.min(G,RA),p=Math.max(p,UA),m=Math.min(m,PA),k=Math.max(k,bA)}}),G===1/0||p===-1/0))return;const R=y.source_group_id?B2I(y.source_group_id,h):0,F=y.source_group_id?lIg(y.source_group_id,D).length>0:!1;if(!S){const UA=1+(F?.5:0);G-=UA,p+=UA,m-=UA,k+=UA}const N=Mt(A,{x:G,y:k}),U=Mt(A,{x:p,y:k}),L=Mt(A,{x:G,y:m}),b=Mt(A,{x:p,y:m}),H=t2I[w%t2I.length];c.strokeStyle=H,c.lineWidth=2;const q=Math.max(4,Math.min(12,8*Math.abs(A.a))),j=Math.max(2,Math.min(6,4*Math.abs(A.a))),O=q*(F?1.3:1),AA=j;c.setLineDash([O,AA]),c.beginPath(),c.moveTo(N.x,N.y),c.lineTo(U.x,U.y),c.lineTo(b.x,b.y),c.lineTo(L.x,L.y),c.closePath(),c.stroke();const tA=Math.max(8,Math.min(12,10*Math.abs(A.a))),eA=R===0||R===1?0:R*.11,QA=tA*(1-eA),sA=4,DA=y.name||`Group ${w+1}`;c.font=`${QA}px sans-serif`,c.setLineDash([]);const hA=c.measureText(DA).width+sA*2,nA=QA+sA*2,cA=N.x-5,fA=N.y-5,FA=3;if(c.fillStyle="rgba(0, 0, 0, 0.8)",c.beginPath(),c.roundRect(cA,fA-nA,hA,nA,FA),c.fill(),c.fillStyle=H,c.textAlign="left",c.textBaseline="middle",c.fillText(DA,cA+sA,fA-nA/2),E&&d.has(y.pcb_group_id)&&!!y.anchor_position&&y.anchor_position){const NA=Array.isArray(y.anchor_position)?{x:y.anchor_position[0]??0,y:y.anchor_position[1]??0}:{x:y.anchor_position.x,y:y.anchor_position.y},RA=Mt(A,NA);c.strokeStyle="white",c.lineWidth=1.5,c.setLineDash([]);const UA=Math.max(4,Math.min(8,6*Math.abs(A.a)));c.beginPath(),c.moveTo(RA.x-UA,RA.y),c.lineTo(RA.x+UA,RA.y),c.stroke(),c.beginPath(),c.moveTo(RA.x,RA.y-UA),c.lineTo(RA.x,RA.y+UA),c.stroke()}})},[B,Q,E,e,n,s,i,r,A,o]),W.jsxs("div",{ref:t,style:{position:"relative",width:"100%",height:"100%"},children:[g,W.jsx("canvas",{ref:C,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Da.pcbGroupOverlay,display:Q?"block":"none"}})]})},xoo=({transform:g,soup:A,connectivityMap:I,children:e})=>{const t=Qi(Q=>Q.is_showing_rats_nest),{netMap:o,idToNetMap:B}=I,C=gA.useMemo(()=>{if(!A||!t)return[];const Q=r=>{const a=p5(A)[r.replace(/_\d+$/,"")].get(r);return a&&"x"in a&&"y"in a?{x:a.x,y:a.y}:null},i=(r,a)=>{const c=o[a]||[];let h=null,l=1/0;return c.forEach(D=>{const d=Q(D);if(d){const y=Math.sqrt((r.x-d.x)**2+(r.y-d.y)**2);y<l&&y>0&&(l=y,h=d)}}),h},E=p5(A).pcb_port.list(),n=p5(A).source_trace.list(),s=[];return E.forEach((r,a)=>{const c=B[r.pcb_port_id];let h=!1;for(const d of n)d.connected_source_port_ids.includes(r.source_port_id)&&d.connected_source_net_ids.length>0&&(h=!0);if(!c)return;const l={x:r.x,y:r.y},D=i(l,c);D&&s.push({key:`${r.pcb_port_id}-${a}`,startPoint:l,endPoint:D,isInNet:h})}),s},[A,o,B,t]);return!A||!t?e:(g||(g=aJ()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Da.ratsNestOverlay},children:C.map(({key:Q,startPoint:i,endPoint:E,isInNet:n})=>{const s=Mt(g,i),r=Mt(g,E);return W.jsx("line",{x1:s.x,y1:s.y,x2:r.x,y2:r.y,stroke:"white",strokeWidth:"1",strokeDasharray:n?"6,6":void 0},Q)})})]}))},Nx=(g,A,I)=>{const e=Qi(B=>B.is_mouse_over_container),t=gA.useRef(e),o=gA.useRef(A);gA.useEffect(()=>{t.current=e},[e]),gA.useEffect(()=>{o.current=A},[A]),gA.useEffect(()=>{if(!g)return;const B=C=>{const Q=C.target;if(Q.tagName==="INPUT"||Q.tagName==="TEXTAREA"||Q.isContentEditable)return;const i=g.split("+"),E=i.includes("ctrl"),n=i.includes("shift"),s=i.includes("alt"),r=i.includes("meta"),a=i[i.length-1],c=I?.current?I.current.contains(document.activeElement)||document.activeElement===I.current:!1;(t.current||c)&&(!E||C.ctrlKey)&&(!n||C.shiftKey)&&(!s||C.altKey)&&(!r||C.metaKey)&&C.key.toLowerCase()===a.toLowerCase()&&(C.preventDefault(),o.current())};return window.addEventListener("keydown",B),()=>{window.removeEventListener("keydown",B)}},[g])},Foo=()=>{const[g,A]=gA.useState(!1);return gA.useEffect(()=>{const I=()=>{A(window.innerWidth<=768)};return I(),window.addEventListener("resize",I),()=>window.removeEventListener("resize",I)},[]),g},TIA=(g,A={stopPropagation:!0})=>{const I=gA.useRef(0),e=gA.useCallback(B=>{A.stopPropagation&&B.stopPropagation();const C=Date.now();C-I.current<300||(I.current=C,g?.(B))},[g,A.stopPropagation]),t=gA.useCallback(B=>{B.preventDefault(),e(B)},[e]);return{onClick:e,onTouchEnd:t,style:{touchAction:"manipulation"}}},Uoo={version:"1.11.431"},Z7=({children:g,isSmallScreen:A,onClick:I,...e})=>{const{style:t,...o}=TIA(I);return W.jsx("div",{...e,...o,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:A?8:6,paddingRight:A?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...t,...e.style},children:g})},Joo=g=>{const A=new Map;return g.forEach((I,e)=>{const t=I.error_type||"unknown_error",o=A.get(t)||[];o.push({error:I,index:e,errorId:q7(I,e)}),A.set(t,o)}),Array.from(A.entries()).map(([I,e])=>({errorType:I,errors:e}))},Koo=({onClose:g,setHoveredErrorId:A,setFocusedErrorId:I,highlightDurationMs:e=3e3})=>{const t=gA.useRef(null),o=gA.useRef(null),B=gA.useRef(null),C=gA.useCallback(()=>{t.current!==null&&(window.clearTimeout(t.current),t.current=null),o.current!==null&&(window.cancelAnimationFrame(o.current),o.current=null)},[]);gA.useEffect(()=>C,[C]);const Q=gA.useCallback(E=>{C(),B.current=E,A(E),I(null),o.current=window.requestAnimationFrame(()=>{I(E),o.current=null}),g(),t.current=window.setTimeout(()=>{B.current=null,A(null),I(null),t.current=null},e)},[C,e,g,I,A]),i=gA.useCallback(E=>B.current===E,[]);return{handleErrorSelect:Q,isSelectedError:i}},Poo=({errorId:g,errorMessage:A,copiedErrorId:I,onCopy:e})=>{const{style:t,...o}=TIA(()=>e(A,g));return W.jsx("button",{type:"button","aria-label":I===g?"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",...t},...o,children:I===g?W.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:W.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},Loo=({elements:g,isOpen:A,isSmallScreen:I,onToggle:e,onClose:t,setHoveredErrorId:o,setFocusedErrorId:B})=>{const[C,Q]=gA.useState(null),[i,E]=gA.useState(new Set),[n,s]=gA.useState(new Set),[,r]=qIo(),{handleErrorSelect:a,isSelectedError:c}=Koo({onClose:t,setHoveredErrorId:o,setFocusedErrorId:B}),h=gA.useMemo(()=>g?.filter(w=>w.type.includes("error"))??[],[g]),l=h.length,D=gA.useMemo(()=>Joo(h),[h]),d=gA.useCallback(w=>{E(u=>{const G=new Set(u);return G.has(w)?G.delete(w):G.add(w),G})},[]),y=gA.useCallback(w=>{s(u=>{const G=new Set(u);return G.has(w)?G.delete(w):G.add(w),G})},[]);return W.jsxs("div",{style:{position:"relative"},children:[W.jsx(Z7,{isSmallScreen:I,style:l>0?{color:"red"}:void 0,onClick:e,children:W.jsxs("div",{children:[l," errors"]})}),A&&l>0&&W.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:I?"280px":"400px",maxWidth:I?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:D.map(({errorType:w,errors:u},G)=>{const m=i.has(w);return W.jsxs("div",{style:{borderBottom:G<D.length-1?"1px solid #444":"none"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:p=>{p.currentTarget.style.backgroundColor="#303030"},onMouseLeave:p=>{p.currentTarget.style.backgroundColor="#232323"},onTouchStart:p=>{p.stopPropagation(),p.currentTarget.style.backgroundColor="#303030"},onTouchEnd:p=>{p.stopPropagation(),p.preventDefault(),p.currentTarget.style.backgroundColor="#232323",d(w)},onClick:p=>{p.stopPropagation(),d(w)},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[W.jsx("div",{style:{color:"#888",fontSize:"16px",transform:m?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),W.jsx("div",{style:{fontWeight:"bold",fontSize:I?"12px":"13px"},children:w})]}),W.jsx("div",{style:{fontSize:I?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:u.length})]}),!m&&u.map(({error:p,index:k,errorId:S})=>{const R=n.has(S),F=p.message??"No error message";return W.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:N=>{N.currentTarget.style.backgroundColor="#333",o(S)},onMouseLeave:N=>{N.currentTarget.style.backgroundColor="#2a2a2a",c(S)||o(null)},onTouchStart:N=>{N.stopPropagation(),N.currentTarget.style.backgroundColor="#333",o(S)},onTouchEnd:N=>{N.stopPropagation(),N.preventDefault(),N.currentTarget.style.backgroundColor="#2a2a2a",a(S)},onClick:N=>{N.stopPropagation(),a(S)},children:[W.jsx("div",{style:{flex:1,fontSize:I?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:F}),W.jsx("button",{type:"button","aria-label":R?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:R?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:N=>N.stopPropagation(),onClick:N=>{N.stopPropagation(),y(S)},onTouchEnd:N=>{N.stopPropagation(),N.preventDefault(),y(S)},children:"›"})]}),R&&W.jsxs("div",{"data-error-id":k,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[W.jsx("div",{style:{fontSize:I?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:N=>N.stopPropagation(),onClick:N=>N.stopPropagation(),children:F}),W.jsx(Poo,{errorId:S,errorMessage:F,copiedErrorId:C,onCopy:(N,U)=>{r(N),Q(U),setTimeout(()=>Q(null),2e3)}})]})]},S)})]},w)})})]})},C2I=gA.createContext(null),Yoo=()=>gA.useContext(C2I),ZIA=F7`
5433
5433
  background: #222;
5434
5434
  color: #eee;
5435
5435
  border: 1px solid #555;
@@ -5661,7 +5661,7 @@ test("${i} should solve problem correctly", () => {
5661
5661
  // Add more specific assertions based on expected output
5662
5662
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5663
5663
  })
5664
- `,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},G1I=g=>g.activeSubSolver?[g,...G1I(g.activeSubSolver)]:[g],P0o=({solver:g})=>{const A=G1I(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(K0o,{solver:I})]},I.getSolverName()))})},L0o=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:o,onDownloadVisualization:B,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:W.jsx("button",{type:"button",onClick:()=>{B(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{o(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(P0o,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),W.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},Y0o=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),_0o=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},b0o=(g,A)=>{const e=g.pipelineDef[A].solverName,t=_0o(g,A),o=g[e],B=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&B!==null?Q=r-B:B!==null&&(Q=C-B)}else t==="In Progress"&&B!==null&&(Q=C-B);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&o&&(E=o.progress??0);const n=o?.stats??null;return{index:A,name:e,status:t,firstIteration:B,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:o??null}},H0o=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},v0o=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},m1I=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},q0o=g=>Object.entries(g).map(([A,I])=>`${A}: ${m1I(I)}`).join(", "),T0o=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=q0o(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",m1I(t)]},e))})]})},ntg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(ntg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=ntg(e));return A},Z0o=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=ntg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},O0o=({expanded:g})=>W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),p1I=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},k1I=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:o})=>{const[B,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>b0o(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):Z0o(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););o?.()}},a=()=>{if(!g.solved&&!g.failed){const h=p1I(g);for(;!g.solved&&!g.failed&&(g.step(),p1I(g)===h););o?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),W.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=Y0o(h.solverInstance),D=B.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(O0o,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(H0o,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(v0o,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(T0o,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx(k1I,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:o})})})]},h.name)})})]})})]})};function W0o({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],o=g.texts??[];let B=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<B&&(B=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of o)E(h.x,h.y);(!isFinite(B)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(B=-20,C=-20,Q=20,i=20);const n=10,s=B-n,r=C-n,a=Math.max(1,Q-B+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),o.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var V0o=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},j0o=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[o,B]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,o]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();B()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(L0o,{solver:C,triggerRender:B,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(V0o,{fallback:W.jsx(W0o,{graphics:s}),children:Q==="canvas"?W.jsx(J0o,{graphics:s}):W.jsx(x0o,{graphics:s})}),a&&W.jsx(k1I,{solver:C,onStepUntilPhase:c,triggerRender:B})]})};const z0o=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},X0o=1e3,yk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),o=URL.createObjectURL(t),B=document.createElement("a");B.href=o,B.download=I,B.target="_blank",B.rel="noopener noreferrer",B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),setTimeout(()=>{URL.revokeObjectURL(o)},X0o)},stg=g=>{let A=g.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},$0o=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},Lx="https://github.com/tscircuit/tscircuit-autorouter/issues/new",M1I="https://github.com/tscircuit/copper-pour-solver/issues/new",S1I="https://github.com/tscircuit/calculate-packing/issues/new",Alo="https://github.com/tscircuit/matchpack/issues/new",f1I="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",glo={PackSolver2:S1I,LayoutPipelineSolver:Alo,AutoroutingPipelineSolver:Lx,AssignableAutoroutingPipeline2:Lx,AssignableAutoroutingPipeline3:Lx,AutoroutingPipeline1_OriginalUnravel:Lx,AutoroutingPipelineSolver3_HgPortPointPathing:Lx,AutoroutingPipelineSolver4:Lx,AutoroutingPipelineSolver5:Lx,AutoroutingPipelineSolver7_MultiGraph:Lx,AutoroutingPipelineSolver8:Lx,CopperPourPipelineSolver:M1I,SchematicTracePipelineSolver:f1I},Ilo=g=>g.toLowerCase().includes("pack")?hBo:g.toLowerCase().includes("rout")?c2I:QBo,R1I=g=>{const A=glo[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?Lx:I.includes("schematic")&&I.includes("trace")?f1I:I.includes("copperpour")?M1I:I.includes("pack")?S1I:null},elo=g=>`${stg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,N1I=g=>{yk(JSON.stringify(g.solverParams,null,2),{fileName:elo(g),mimeType:"application/json"})},tlo=({solverEvent:g})=>{const A=R1I(g.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[W.jsxs(XE,{type:"button",variant:"outline",size:"sm",onClick:()=>N1I(g),children:[W.jsx(OIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(XE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(hwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(XE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(hwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},olo=({solverEvent:g})=>{const A=R1I(g.solverName);return A?W.jsx(XE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(hwA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:W.jsx(hwA,{className:"rf-w-4 rf-h-4"})})},Blo=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);z0o();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),o=A?e.get(A):null,B=gA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const C=K6A[o.solverName];if(!C)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(K6A).join(", ")}`,classFound:!1};try{return{instance:new C(...$0o(o)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[o]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=Ilo(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?B.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(tlo,{solverEvent:o}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(j0o,{solver:B.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),B.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${B.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${B.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:B.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(olo,{solverEvent:o}),W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>N1I(o),children:W.jsx(OIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Clo=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Qlo=new Set(["tscircuit","default","auto","auto_local"]);function ilo(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function Elo(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&Clo.get(I);if(e)return e;if(I&&!Qlo.has(I))return A;const t=g.solverName?.trim();if(t)return ilo(t);const o=g.autorouterVersion?.trim();if(o){const B=o.match(/^beta[_-]pipeline(\d+)$/);return B?`Pipeline${B[1]}`:o==="latest"?"default":o}return A?"default":"Unknown"}const atg="#fbbf24";function nlo(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(o=>o!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function x1I(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function slo(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function F1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...slo(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),o=[];let B=0;for(const[C,Q]of t)C>=B&&o.push(I.slice(B,C+1)),B=Math.max(B,Q);return B<I.length&&o.push(I.slice(B)),o}function alo(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(x1I(g));for(const o of e.traces??[])if(t.has(o.pcb_trace_id))for(const B of F1I(o,e)){let C;for(const Q of B){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:atg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:atg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function rlo(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const clo=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function hlo(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!clo.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const o=I==="input"?e.traces??[]:nlo(A),B=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of o){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=F1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${rlo(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:B.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const rtg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,U1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",J1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,llo={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},Dlo=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[o,B]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&J1I(N)===J1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=o==="output"&&!D?"input":o==="input"&&!y?"output":o,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:hlo(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?alo(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const U=()=>r(Math.max(360,N.clientHeight));U();const L=new ResizeObserver(U);return L.observe(N),()=>L.disconnect()},[!!h]),!h)return W.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[W.jsx(c2I,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=rtg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,F=G?.filter(N=>N.type==="pcb_trace").length??0;return W.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[W.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,U)=>{const L=x1I(N).length,b=N.endSimpleRouteJson?`${L} ${L===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":U===c,title:`${U1I(N)} · ${b}`,onClick:()=>t(N),className:sB("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",U===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:sB("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",U===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:U+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:rtg(N,U),children:rtg(N,U)}),N.status==="complete"?W.jsx(W7,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(wIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(H2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[Elo(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>B(N),className:sB("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:atg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",F," traces"]})]}),S&&W.jsx("div",{className:sB("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(DIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:llo,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${U1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>yk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(OIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(V7,{className:sB("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},K1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(GF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{h9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(GF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{h9.captureException(t,{error_type:e.type})}catch{}}},[I])},dlo=g=>{gA.useEffect(()=>{try{WVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},P1I="0.0.3046",ylo={version:P1I},ctg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},htg=new Map,UuA=g=>{const A=htg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},wlo=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=htg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return htg.set(I.name,t),{type:"tracked",store:g,...t}},L1I=(g,A={})=>(I,e,t)=>{const{enabled:o,anonymousActionType:B,store:C,...Q}=A;let i;try{i=(o??(ctg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(ctg?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=wlo(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:B||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...UuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(ctg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ltg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
5664
+ `,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},G1I=g=>g.activeSubSolver?[g,...G1I(g.activeSubSolver)]:[g],P0o=({solver:g})=>{const A=G1I(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(K0o,{solver:I})]},I.getSolverName()))})},L0o=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:o,onDownloadVisualization:B,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:W.jsx("button",{type:"button",onClick:()=>{B(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{o(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(P0o,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),W.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},Y0o=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),_0o=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},b0o=(g,A)=>{const e=g.pipelineDef[A].solverName,t=_0o(g,A),o=g[e],B=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&B!==null?Q=r-B:B!==null&&(Q=C-B)}else t==="In Progress"&&B!==null&&(Q=C-B);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&o&&(E=o.progress??0);const n=o?.stats??null;return{index:A,name:e,status:t,firstIteration:B,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:o??null}},H0o=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},v0o=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},m1I=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},q0o=g=>Object.entries(g).map(([A,I])=>`${A}: ${m1I(I)}`).join(", "),T0o=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=q0o(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",m1I(t)]},e))})]})},ntg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(ntg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=ntg(e));return A},Z0o=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=ntg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},O0o=({expanded:g})=>W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),p1I=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},k1I=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:o})=>{const[B,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>b0o(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):Z0o(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););o?.()}},a=()=>{if(!g.solved&&!g.failed){const h=p1I(g);for(;!g.solved&&!g.failed&&(g.step(),p1I(g)===h););o?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),W.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=Y0o(h.solverInstance),D=B.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(O0o,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(H0o,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(v0o,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(T0o,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx(k1I,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:o})})})]},h.name)})})]})})]})};function W0o({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],o=g.texts??[];let B=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<B&&(B=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of o)E(h.x,h.y);(!isFinite(B)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(B=-20,C=-20,Q=20,i=20);const n=10,s=B-n,r=C-n,a=Math.max(1,Q-B+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),o.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var V0o=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},j0o=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[o,B]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,o]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();B()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(L0o,{solver:C,triggerRender:B,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(V0o,{fallback:W.jsx(W0o,{graphics:s}),children:Q==="canvas"?W.jsx(J0o,{graphics:s}):W.jsx(x0o,{graphics:s})}),a&&W.jsx(k1I,{solver:C,onStepUntilPhase:c,triggerRender:B})]})};const z0o=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},X0o=1e3,yk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),o=URL.createObjectURL(t),B=document.createElement("a");B.href=o,B.download=I,B.target="_blank",B.rel="noopener noreferrer",B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),setTimeout(()=>{URL.revokeObjectURL(o)},X0o)},stg=g=>{let A=g.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},$0o=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},Lx="https://github.com/tscircuit/tscircuit-autorouter/issues/new",M1I="https://github.com/tscircuit/copper-pour-solver/issues/new",S1I="https://github.com/tscircuit/calculate-packing/issues/new",Alo="https://github.com/tscircuit/matchpack/issues/new",f1I="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",glo={PackSolver2:S1I,LayoutPipelineSolver:Alo,AutoroutingPipelineSolver:Lx,AssignableAutoroutingPipeline2:Lx,AssignableAutoroutingPipeline3:Lx,AutoroutingPipeline1_OriginalUnravel:Lx,AutoroutingPipelineSolver3_HgPortPointPathing:Lx,AutoroutingPipelineSolver4:Lx,AutoroutingPipelineSolver5:Lx,AutoroutingPipelineSolver7_MultiGraph:Lx,AutoroutingPipelineSolver8:Lx,CopperPourPipelineSolver:M1I,SchematicTracePipelineSolver:f1I},Ilo=g=>g.toLowerCase().includes("pack")?hBo:g.toLowerCase().includes("rout")?c2I:QBo,R1I=g=>{const A=glo[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?Lx:I.includes("schematic")&&I.includes("trace")?f1I:I.includes("copperpour")?M1I:I.includes("pack")?S1I:null},elo=g=>`${stg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,N1I=g=>{yk(JSON.stringify(g.solverParams,null,2),{fileName:elo(g),mimeType:"application/json"})},tlo=({solverEvent:g})=>{const A=R1I(g.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[W.jsxs(XE,{type:"button",variant:"outline",size:"sm",onClick:()=>N1I(g),children:[W.jsx(OIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(XE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(hwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(XE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(hwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},olo=({solverEvent:g})=>{const A=R1I(g.solverName);return A?W.jsx(XE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(hwA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:W.jsx(hwA,{className:"rf-w-4 rf-h-4"})})},Blo=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);z0o();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),o=A?e.get(A):null,B=gA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const C=K6A[o.solverName];if(!C)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(K6A).join(", ")}`,classFound:!1};try{return{instance:new C(...$0o(o)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[o]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=Ilo(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?B.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(tlo,{solverEvent:o}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(j0o,{solver:B.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),B.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${B.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${B.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:B.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(olo,{solverEvent:o}),W.jsx(XE,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>N1I(o),children:W.jsx(OIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Clo=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Qlo=new Set(["tscircuit","default","auto","auto_local"]);function ilo(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function Elo(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&Clo.get(I);if(e)return e;if(I&&!Qlo.has(I))return A;const t=g.solverName?.trim();if(t)return ilo(t);const o=g.autorouterVersion?.trim();if(o){const B=o.match(/^beta[_-]pipeline(\d+)$/);return B?`Pipeline${B[1]}`:o==="latest"?"default":o}return A?"default":"Unknown"}const atg="#fbbf24";function nlo(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(o=>o!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function x1I(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function slo(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function F1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...slo(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),o=[];let B=0;for(const[C,Q]of t)C>=B&&o.push(I.slice(B,C+1)),B=Math.max(B,Q);return B<I.length&&o.push(I.slice(B)),o}function alo(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(x1I(g));for(const o of e.traces??[])if(t.has(o.pcb_trace_id))for(const B of F1I(o,e)){let C;for(const Q of B){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:atg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:atg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function rlo(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const clo=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function hlo(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!clo.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const o=I==="input"?e.traces??[]:nlo(A),B=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of o){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=F1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${rlo(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:B.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const rtg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,U1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",J1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,llo={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},Dlo=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[o,B]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&J1I(N)===J1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=o==="output"&&!D?"input":o==="input"&&!y?"output":o,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:hlo(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?alo(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const U=()=>r(Math.max(360,N.clientHeight));U();const L=new ResizeObserver(U);return L.observe(N),()=>L.disconnect()},[!!h]),!h)return W.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[W.jsx(c2I,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=rtg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,F=G?.filter(N=>N.type==="pcb_trace").length??0;return W.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[W.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[W.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,U)=>{const L=x1I(N).length,b=N.endSimpleRouteJson?`${L} ${L===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":U===c,title:`${U1I(N)} · ${b}`,onClick:()=>t(N),className:sB("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",U===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:sB("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",U===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:U+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:rtg(N,U),children:rtg(N,U)}),N.status==="complete"?W.jsx(W7,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(wIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(H2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[Elo(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>B(N),className:sB("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:atg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",F," traces"]})]}),S&&W.jsx("div",{className:sB("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(DIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:llo,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${U1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>yk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(OIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(V7,{className:sB("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},K1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(GF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{h9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(GF("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{h9.captureException(t,{error_type:e.type})}catch{}}},[I])},dlo=g=>{gA.useEffect(()=>{try{WVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},P1I="0.0.3047",ylo={version:P1I},ctg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},htg=new Map,UuA=g=>{const A=htg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},wlo=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=htg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return htg.set(I.name,t),{type:"tracked",store:g,...t}},L1I=(g,A={})=>(I,e,t)=>{const{enabled:o,anonymousActionType:B,store:C,...Q}=A;let i;try{i=(o??(ctg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(ctg?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=wlo(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:B||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...UuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(ctg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ltg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
5665
5665
  [zustand devtools middleware] Unsupported __setState action format.
5666
5666
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5667
5667
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }