@tscircuit/runframe 0.0.2787 → 0.0.2789

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.
@@ -2861,7 +2861,7 @@ var usePostHogActivity = (properties) => {
2861
2861
  };
2862
2862
 
2863
2863
  // package.json
2864
- var version = "0.0.2786";
2864
+ var version = "0.0.2788";
2865
2865
  var package_default = {
2866
2866
  name: "@tscircuit/runframe",
2867
2867
  main: "dist/preview.js",
@@ -2921,7 +2921,7 @@ var package_default = {
2921
2921
  "@tscircuit/fake-snippets": "^0.0.163",
2922
2922
  "@tscircuit/file-server": "^0.0.32",
2923
2923
  "@tscircuit/internal-dynamic-import": "^0.0.15",
2924
- "@tscircuit/pcb-viewer": "1.11.405",
2924
+ "@tscircuit/pcb-viewer": "1.11.406",
2925
2925
  "@tscircuit/props": "^0.0.657",
2926
2926
  "@tscircuit/schematic-viewer": "^2.0.95",
2927
2927
  "@types/bun": "latest",
@@ -2985,7 +2985,7 @@ var package_default = {
2985
2985
  },
2986
2986
  dependencies: {
2987
2987
  "@tscircuit/core": "^0.0.1911",
2988
- "@tscircuit/eval": "0.0.1441",
2988
+ "@tscircuit/eval": "0.0.1442",
2989
2989
  "@tscircuit/solver-utils": "^0.0.16",
2990
2990
  debug: "^4.4.0",
2991
2991
  "format-si-unit": "^0.0.12"
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  SchematicViewer,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-25RREXE7.js";
11
+ } from "./chunk-2JUUNS7E.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -41,7 +41,7 @@ import {
41
41
  useRunFrameStore,
42
42
  useRunnerStore,
43
43
  useStyles
44
- } from "./chunk-25RREXE7.js";
44
+ } from "./chunk-2JUUNS7E.js";
45
45
 
46
46
  // lib/components/RunFrame/RunFrame.tsx
47
47
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5487,7 +5487,7 @@ ${b.type}: ${k}
5487
5487
  transition: opacity 0.2s;
5488
5488
  margin-bottom: 10px;
5489
5489
  color: red;
5490
- `,zbi=({children:t,transform:e=O0(),elements:n})=>{const o=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=Nc(m=>({isShowingDRCErrors:m.is_showing_drc_errors,hoveredErrorId:m.hovered_error_id,focusedErrorId:m.focused_error_id})),a=s??r;if(!n)return z.jsx("div",{style:{position:"relative"},ref:o,children:t});const A=n.filter(m=>m.type==="pcb_trace_error"&&!m.message?.includes("Multiple components found with name")),c=n.filter(m=>m.type==="pcb_via_clearance_error"),l=n.filter(m=>m.type==="pcb_trace_error"&&m.message?.includes("Multiple components found with name")),g=rAn(n),u=cAn(n,a),h=m=>{const p=$8i({error:m,indexes:g});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const _=xt(e,p);return Number.isNaN(_.x)||Number.isNaN(_.y)?null:_};let d=null;return u&&(d=h(u)),z.jsxs("div",{style:{position:"relative"},ref:o,children:[t,A.map((m,p)=>{const _=CY(m,p),f=a===_;if(!f&&!i)return null;const I=h(m);if(!I)return null;const C=vze(I,o);return z.jsxs(te.Fragment,{children:[z.jsx(KAn,{errorCenter:I,isHighlighted:f}),z.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Eg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="1")}},onMouseLeave:y=>{if(!f){const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:f?200:100,left:C.left,top:C.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||f?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${Pze}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},_)}),c.map((m,p)=>{const _=CY(m,p),f=a===_;if(!f&&!i)return null;const I=h(m);if(!I)return null;const C=vze({x:I.x,y:I.y},o);return z.jsxs(te.Fragment,{children:[z.jsx(KAn,{errorCenter:I,isHighlighted:f}),z.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Eg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="1")}},onMouseLeave:y=>{if(!f){const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:f?Eg.errorOverlay+10:Eg.errorOverlay+1,left:C.left,top:C.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${Pze}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},_)}),l.map((m,p)=>{const _=m.component_name||m.message?.match(/name "([^"]+)"/)?.[1];if(!_)return null;const f=n?.filter(y=>y.type==="source_component"&&y.name===_||y.type==="pcb_component"&&n?.find(x=>x.type==="source_component"&&x.source_component_id===y.source_component_id&&x.name===_))||[],I=CY(m,p),C=a===I;return!C&&!i?null:f.map((y,x)=>{let E={x:0,y:0};if(y.type==="pcb_component")E=y.center||{x:0,y:0};else if(y.type==="source_component"){const L=n?.find(G=>G.type==="pcb_component"&&G.source_component_id===y.source_component_id);L&&L.type==="pcb_component"&&(E=L.center||{x:0,y:0})}const B=xt(e,E);if(Number.isNaN(B.x)||Number.isNaN(B.y))return null;const b=Math.abs(e.a),k=Math.max(8,Math.min(30,.5*b)),R=vze(B,o);return z.jsxs(te.Fragment,{children:[z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Eg.errorOverlay},width:"100%",height:"100%",children:C?z.jsx("polygon",{points:`${B.x},${B.y-k*1.25} ${B.x+k},${B.y} ${B.x},${B.y+k*1.25} ${B.x-k},${B.y}`,fill:"#ff4444"}):z.jsx("circle",{cx:B.x,cy:B.y,r:k,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,k*.15):Math.max(1,k*.1),opacity:1})}),z.jsx("div",{style:{position:"absolute",left:B.x-(k+10),top:B.y-(k+10),width:(k+10)*2,height:(k+10)*2,zIndex:Eg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:L=>{const G=L.currentTarget.nextElementSibling;if(G){const U=G.querySelector(".error-message");U&&(U.style.opacity="1")}},onMouseLeave:L=>{if(!C){const G=L.currentTarget.nextElementSibling;if(G){const U=G.querySelector(".error-message");U&&(U.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:C?Eg.errorOverlay+20:Eg.errorOverlay+10,left:R.left,top:R.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:R.transform},children:z.jsx("div",{className:`error-message ${Pze}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:m.message})})]},`${I}_${x}`)})}),d&&z.jsx(Vbi,{center:d})]})};function Jbi(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}var XP=t=>t?.type==="pcb_component",VAn=t=>t?.type==="pcb_group",Wbi=t=>t?.type==="pcb_panel",wze=t=>t?.type==="pcb_board",wu={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},sE={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},Mze=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:sE.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:wu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=xt(e,s.anchor);r.set(s.anchor_id,a)}}),z.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Eg.dimensionOverlay},children:z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,A=s.anchor_id,c=s.target,l=r.get(A),g=xt(e,c),u=c.x-a.x,h=c.y-a.y,d=Math.abs(g.x-l.x),m=Math.abs(g.y-l.y),p=g.y<l.y,_=g.x>l.x,f=p?wu.LABEL_OFFSET_ABOVE:wu.LABEL_OFFSET_BELOW,I=_?wu.LABEL_OFFSET_RIGHT:wu.LABEL_OFFSET_LEFT,C=d>wu.MIN_LINE_LENGTH_FOR_LABEL,y=m>wu.MIN_LINE_LENGTH_FOR_LABEL,x=`${s.display_offset_x??u.toFixed(2)}mm`,E=`${s.display_offset_y??h.toFixed(2)}mm`;return z.jsxs("g",{children:[z.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.LINE_STROKE_WIDTH,strokeDasharray:wu.LINE_DASH_PATTERN}),z.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.LINE_STROKE_WIDTH,strokeDasharray:wu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?z.jsx("circle",{cx:g.x,cy:g.y,r:wu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1}):z.jsxs(z.Fragment,{children:[z.jsx("line",{x1:g.x-wu.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+wu.ANCHOR_MARKER_SIZE,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:g.x,y1:g.y-wu.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+wu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH})]}),C&&z.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+f,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:z.jsx("div",{style:{...i,textAlign:"center"},children:x})}),y&&z.jsx("foreignObject",{x:g.x+I,y:Math.min(l.y,g.y),width:wu.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:z.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:_?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:E})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>z.jsxs("g",{children:[z.jsx("line",{x1:a.x-wu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+wu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:a.x,y1:a.y-wu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+wu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},jbi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(_=>wze(_)),s=t.filter(_=>XP(_)),a=t.filter(_=>VAn(_)),A=e.map(_=>XP(_._parent_pcb_component)?_._parent_pcb_component.pcb_component_id:XP(_._element)?_._element.pcb_component_id:null).filter(_=>!!_),c=new Set;if(A.forEach(_=>{const f=s.find(I=>I.pcb_component_id===_);f?.pcb_group_id&&c.add(f.pcb_group_id)}),!Nc(_=>_.is_showing_group_anchor_offsets)&&A.length===0)return null;const g=s.map(_=>{const f=_.positioned_relative_to_pcb_board_id;if(!f)return null;const I=r.find(C=>C.pcb_board_id===f);return I?{component:_,board:I,type:"component"}:null}).filter(_=>!!_),u=a.map(_=>{const f=_.positioned_relative_to_pcb_board_id;if(!f||!_.center)return null;const I=r.find(C=>C.pcb_board_id===f);return I?{group:_,board:I,type:"group"}:null}).filter(_=>!!_),h=[...g,...u];if(h.length===0)return null;const d=A.length===0,m=h.filter(_=>_.type==="component"?d||A.includes(_.component.pcb_component_id):d||c.has(_.group.pcb_group_id));if(m.length===0)return null;const p=m.map(_=>_.type==="component"?{id:`${_.board.pcb_board_id}-${_.component.pcb_component_id}-${_.type}`,anchor:_.board.center,anchor_id:_.board.pcb_board_id,target:_.component.center,type:"component",display_offset_x:_.component.display_offset_x,display_offset_y:_.component.display_offset_y}:{id:`${_.board.pcb_board_id}-${_.group.pcb_group_id}-${_.type}`,anchor:_.board.center,anchor_id:_.board.pcb_board_id,target:{x:_.group.anchor_position?.x??_.group.center.x,y:_.group.anchor_position?.y??_.group.center.y},type:"group",display_offset_x:_.group.display_offset_x,display_offset_y:_.group.display_offset_y}).filter(_=>!!_);return z.jsx(Mze,{targets:p,transform:n,containerWidth:o,containerHeight:i})},Xbi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(_=>VAn(_)),s=t.filter(_=>XP(_)),a=e.map(_=>XP(_._parent_pcb_component)?_._parent_pcb_component.pcb_component_id:XP(_._element)?_._element.pcb_component_id:null).filter(_=>!!_),A=(_,f)=>{if(f.has(_))return;f.add(_);const I=r.find(C=>C.pcb_group_id===_);I?.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&A(I.positioned_relative_to_pcb_group_id,f)},c=new Set;if(a.forEach(_=>{const f=s.find(I=>I.pcb_component_id===_);f&&(f.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&A(f.positioned_relative_to_pcb_group_id,c),f.pcb_group_id&&A(f.pcb_group_id,c))}),!Nc(_=>_.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=s.map(_=>{if(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id){const f=r.find(I=>I.pcb_group_id===_.positioned_relative_to_pcb_group_id);return f&&f.anchor_position?{component:_,parentGroup:f,type:"component"}:null}if(_.pcb_group_id){const f=r.find(I=>I.pcb_group_id===_.pcb_group_id);return f&&f.anchor_position?{component:_,parentGroup:f,type:"component"}:null}return null}).filter(_=>!!_),u=r.map(_=>{if(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id){const f=r.find(I=>I.pcb_group_id===_.positioned_relative_to_pcb_group_id);if(f&&f.anchor_position&&_.anchor_position)return{group:_,parentGroup:f,type:"group"}}return null}).filter(_=>!!_),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,m=h.filter(_=>_.type==="component"?d||a.includes(_.component.pcb_component_id):d||c.has(_.group.pcb_group_id)||c.has(_.parentGroup.pcb_group_id));if(m.length===0)return null;const p=m.map(_=>{const f=_.parentGroup.anchor_position;return f?_.type==="component"?_.component.center?{id:`${_.parentGroup.pcb_group_id}-${_.component.pcb_component_id}-${_.type}`,anchor:f,anchor_id:_.parentGroup.pcb_group_id,target:_.component.center,type:"component",display_offset_x:_.component.display_offset_x,display_offset_y:_.component.display_offset_y}:null:_.group.anchor_position?{id:`${_.parentGroup.pcb_group_id}-${_.group.pcb_group_id}-${_.type}`,anchor:f,anchor_id:_.parentGroup.pcb_group_id,target:_.group.anchor_position,type:"group",display_offset_x:_.group.display_offset_x,display_offset_y:_.group.display_offset_y}:null:null}).filter(_=>!!_);return z.jsx(Mze,{targets:p,transform:n,containerWidth:o,containerHeight:i})},qbi=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?Eze([t]):Eze(o)},$bi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)XP(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),XP(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const A=qbi(a,t);if(!A)continue;const c=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,l=c?IY(t).pcb_group.get(c):null;s.push({component:a,bbox:A,group:l})}return s.length===0?null:z.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Eg.dimensionOverlay},children:z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:A,group:c})=>{const l=xt(n,{x:A.minX,y:A.maxY}),g=xt(n,{x:A.maxX,y:A.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=a.center??{x:(A.minX+A.maxX)/2,y:(A.minY+A.maxY)/2},d=xt(n,h);return z.jsxs("g",{children:[z.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),z.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("circle",{cx:d.x,cy:d.y,r:wu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},Zbi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>Wbi(h)),s=t.filter(h=>wze(h)),a=e.map(h=>wze(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!Nc(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const d=h.pcb_panel_id,m=h.position_mode;if(!d||m!=="relative_to_panel_anchor")return null;const p=r.find(_=>_.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=a.length===0,g=c.filter(h=>l||a.includes(h.board.pcb_board_id));if(g.length===0)return null;const u=g.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return z.jsx(Mze,{targets:u,transform:n,containerWidth:o,containerHeight:i})};function eQi(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(A=>A._element.type==="pcb_trace"),r=o.filter(A=>A.type==="source_trace"),s=e.filter(A=>A._element.type!=="pcb_trace"),a=i.filter(A=>r.some(l=>A._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0)||Sze({primitiveElement:A._element,elements:o})!==null);if(!n)return[...s,...a];if(i.length>1){const A=i.reduce((c,l)=>{const g=c._element.trace_length;return l._element.trace_length<g?l:c},i[0]);return[...s,A]}return e}var tQi={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},nQi=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(A=>!/^[0-9]+$/.test(A)).filter(A=>!A.includes("unnamed_")).sort((A,c)=>c.localeCompare(A)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(A=>`${a}.${A}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},oQi={top:"red",bottom:"aqua"},iQi=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=te.useState(!1),r=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,A,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=oQi[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const p=gAn({primitiveElement:r,elements:n});return p?z.jsx("div",{style:{zIndex:Eg.elementOverlay,position:"absolute",left:e.x+12,top:e.y+12,color:u,pointerEvents:"none"},children:z.jsxs("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[p.text&&z.jsx("div",{children:p.text}),p.name&&z.jsx("div",{style:{marginTop:p.text?"2px":0},children:p.name})]})}):null}const d=nQi(t);return d.trim().length===0?null:z.jsx("div",{style:{zIndex:Eg.elementOverlay,position:"absolute",left:s-A/2-8,top:a-c/2-8,width:A+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:z.jsx("div",{style:{width:o?`calc(100% + ${g*2*l}px)`:"100%",height:o?`calc(100% + ${g*2*l}px)`:"100%",marginLeft:o?`${-g*l}px`:0,marginTop:o?`${-g*l}px`:0,border:`1px solid ${u}`,opacity:o||l===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:z.jsx("div",{style:{position:"absolute",bottom:c+20+g*l,marginRight:o?`${-g*l}px`:0,marginBottom:o?0:-g*l,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},rQi=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=Nc(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=eQi({primitives:s,is_showing_multiple_traces_length:i,elements:n}),z.jsx("div",{style:tQi,children:!o&&s.map(a=>z.jsx(iQi,{primitive:a,mousePos:e,elements:n},a._pcb_drawing_object_id))})},gme=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},zAn=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,A=e[i].y;s>t.y!=A>t.y&&t.x<(a-r)*(t.y-s)/(A-s||Number.EPSILON)+r&&(n=!n)}return n},JAn=(t,e,n,o,i=!1)=>{const r=[];for(const s of t){if(!s._element||!i&&s._element.type==="pcb_trace"&&s.layer!==o)continue;if("x1"in s&&s._element?.type==="pcb_trace"){const c=Hd({x:e.x,y:e.y},{x:s.x1,y:s.y1},{x:s.x2,y:s.y2}),l=s.width||.5,g=Math.max(l*25,2)/n.a;c<g&&r.push(s);continue}if(s.pcb_drawing_type==="polygon"){const c=s.points.map(g=>({x:ct.parse(g.x),y:ct.parse(g.y)})),l=gme(c);if(!l||e.x<l.center.x-l.width/2||e.x>l.center.x+l.width/2||e.y<l.center.y-l.height/2||e.y>l.center.y+l.height/2)continue;zAn(e,c)&&r.push(s);continue}if(s.pcb_drawing_type==="polygon_with_arcs"){const c=s.brep_shape.outer_ring.vertices.map(g=>({x:ct.parse(g.x),y:ct.parse(g.y)})),l=gme(c);if(!l||e.x<l.center.x-l.width/2||e.x>l.center.x+l.width/2||e.y<l.center.y-l.height/2||e.y>l.center.y+l.height/2)continue;zAn(e,c)&&r.push(s);continue}if(!("x"in s&&"y"in s))continue;let a=0,A=0;if("w"in s&&"h"in s)a=s.w,A=s.h;else if("r"in s)a=s.r*2,A=s.r*2;else if("rX"in s&&"rY"in s)a=s.rX*2,A=s.rY*2;else continue;Math.abs(s.x-e.x)<a/2&&Math.abs(s.y-e.y)<A/2&&r.push(s)}return r},sQi=({elements:t,children:e,transform:n,primitives:o,selectedLayer:i,onMouseHoverOverPrimitives:r})=>{const[s,a]=te.useState([]),[A,c]=te.useState({x:0,y:0}),[l,{width:g,height:u}]=e$();te.useEffect(()=>{a([]),r([])},[i,o,r]);const h=te.useMemo(()=>{const m=[];for(const p of s){if(p._element?.type==="pcb_via"||p._element?.type==="pcb_component"||p?.layer==="drill"||p?.is_hoverable===!1)continue;let _=null,f=0,I=0;if(p.pcb_drawing_type==="polygon"){const E=gme(p.points);if(!E)continue;_=E.center,f=E.width,I=E.height}else if(p.pcb_drawing_type==="polygon_with_arcs"){const E=p.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),B=gme(E);if(!B)continue;_=B.center,f=B.width,I=B.height}else p.pcb_drawing_type==="line"?(_={x:(p.x1+p.x2)/2,y:(p.y1+p.y2)/2},f=Math.abs(p.x2-p.x1),I=Math.abs(p.y2-p.y1)):"x"in p&&"y"in p&&(_={x:p.x,y:p.y},f="w"in p?p.w:"r"in p?p.r*2:"rX"in p&&"rY"in p?p.rX*2:0,I="h"in p?p.h:"r"in p?p.r*2:"rX"in p&&"rY"in p?p.rY*2:0);if(!_)continue;const C=xt(n,_),y={w:f*n.a,h:I*n.a},x=m.filter(E=>C.x===E.screen_x&&C.y===E.screen_y&&y.w===E.screen_w&&y.h===E.screen_h).length;m.push({...p,x:_.x,y:_.y,w:f,h:I,screen_x:C.x,screen_y:C.y,screen_w:y.w,screen_h:y.h,same_space_index:x})}return m},[s,n]),d=(m,p,_,f)=>{c({x:m,y:p});const I=xt(n5(_),{x:m,y:p}),C=JAn(f,I,_,i);Jbi(new Set(C.map(y=>y._pcb_drawing_object_id)),new Set(s.map(y=>y._pcb_drawing_object_id)))||(a(C),r(C))};return z.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:m=>{if(n){const p=m.currentTarget.getBoundingClientRect(),_=m.clientX-p.left,f=m.clientY-p.top;d(_,f,n,o)}},onTouchStart:m=>{if(n){const p=m.touches[0],_=m.currentTarget.getBoundingClientRect(),f=p.clientX-_.left,I=p.clientY-_.top;d(f,I,n,o)}},children:[e,z.jsx(rQi,{elements:t,mousePos:A,highlightedPrimitives:h}),n&&z.jsxs(z.Fragment,{children:[z.jsx(jbi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(Xbi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx($bi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(Zbi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u})]})]})},WAn=["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)"],aQi=({children:t,transform:e=O0(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=e$(),a=te.useRef(null),{is_showing_pcb_groups:A,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=Nc(g=>({is_showing_pcb_groups:g.is_showing_pcb_groups,pcb_group_view_mode:g.pcb_group_view_mode,is_showing_group_anchor_offsets:g.is_showing_group_anchor_offsets}));return te.useEffect(()=>{const g=a.current;if(!g||!r||!s)return;g.width=r,g.height=s;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,s),!A))return;const h=n.filter(x=>x.type==="pcb_group"),d=n.filter(x=>x.type==="pcb_component"),m=n.filter(x=>x.type==="source_group"),p=new Map(m.map(x=>[x.source_group_id,x])),_=h.filter(x=>{if(x.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!x.source_group_id)return!1;const E=p.get(x.source_group_id);return E?E.was_automatically_named!==!0:!1}),f=new Map;m.forEach(x=>{const E=x;if(E.parent_source_group_id){const B=f.get(E.parent_source_group_id)||[];B.push(x.source_group_id),f.set(E.parent_source_group_id,B)}});const I=x=>{const E=[],B=f.get(x)||[];for(const b of B)E.push(b),E.push(...I(b));return E},C=x=>{const E=m.find(B=>B.source_group_id===x);return E?.parent_source_group_id?1+C(E.parent_source_group_id):0},y=new Set;if(o.length>0)for(const x of d){if(!o.includes(x.pcb_component_id))continue;const E=x.positioned_relative_to_pcb_group_id??x.pcb_group_id;E&&y.add(E)}_.forEach((x,E)=>{let B=d.filter(Me=>Me.pcb_group_id===x.pcb_group_id);if(x.source_group_id){const Me=I(x.source_group_id),Oe=h.filter(Te=>Te.source_group_id&&Me.includes(Te.source_group_id));for(const Te of Oe){const Se=d.filter(Fe=>Fe.pcb_group_id===Te.pcb_group_id);B=[...B,...Se]}}let b,Q,w,M,k=!1;if(x.center&&x.width&&x.height){k=!0;const Me=x.width/2,Oe=x.height/2;b=x.center.x-Me,w=x.center.x+Me,Q=x.center.y-Oe,M=x.center.y+Oe}else if(B.length===0||(b=1/0,Q=1/0,w=-1/0,M=-1/0,B.forEach(Me=>{if(Me.center&&typeof Me.width=="number"&&typeof Me.height=="number"){const Oe=Me.center.x-Me.width/2,Te=Me.center.x+Me.width/2,Se=Me.center.y+Me.height/2,Fe=Me.center.y-Me.height/2;b=Math.min(b,Oe),w=Math.max(w,Te),Q=Math.min(Q,Fe),M=Math.max(M,Se)}}),b===1/0||w===-1/0))return;const R=x.source_group_id?C(x.source_group_id):0,L=x.source_group_id?I(x.source_group_id).length>0:!1;if(!k){const Te=1+(L?.5:0);b-=Te,w+=Te,Q-=Te,M+=Te}const G=xt(e,{x:b,y:M}),U=xt(e,{x:w,y:M}),Y=xt(e,{x:b,y:Q}),J=xt(e,{x:w,y:Q}),ee=WAn[E%WAn.length];u.strokeStyle=ee,u.lineWidth=2;const j=Math.max(4,Math.min(12,8*Math.abs(e.a))),q=Math.max(2,Math.min(6,4*Math.abs(e.a))),se=j*(L?1.3:1),ne=q;u.setLineDash([se,ne]),u.beginPath(),u.moveTo(G.x,G.y),u.lineTo(U.x,U.y),u.lineTo(J.x,J.y),u.lineTo(Y.x,Y.y),u.closePath(),u.stroke();const ge=Math.max(8,Math.min(12,10*Math.abs(e.a))),he=R==0||R==1?0:R*.11,Ce=ge*(1-he),le=4,_e=x.name||`Group ${E+1}`;u.font=`${Ce}px sans-serif`,u.setLineDash([]);const ye=u.measureText(_e).width+le*2,ve=Ce+le*2,Pe=G.x-5,pe=G.y-5,Qe=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(Pe,pe-ve,ye,ve,Qe),u.fill(),u.fillStyle=ee,u.textAlign="left",u.textBaseline="middle",u.fillText(_e,Pe+le,pe-ve/2),l&&y.has(x.pcb_group_id)&&!!x.anchor_position&&x.anchor_position){const Me=Array.isArray(x.anchor_position)?{x:x.anchor_position[0]??0,y:x.anchor_position[1]??0}:{x:x.anchor_position.x,y:x.anchor_position.y},Oe=xt(e,Me);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const Te=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Oe.x-Te,Oe.y),u.lineTo(Oe.x+Te,Oe.y),u.stroke(),u.beginPath(),u.moveTo(Oe.x,Oe.y-Te),u.lineTo(Oe.x,Oe.y+Te),u.stroke()}})},[n,e,r,s,A,c,l,o]),z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,z.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Eg.pcbGroupOverlay,display:A?"block":"none"}})]})},AQi=({transform:t,soup:e,children:n})=>{const o=Nc(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=te.useMemo(()=>iAn(e||[]),[e]),s=te.useMemo(()=>{if(!e||!o)return[];const a=u=>{const h=IY(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},A=(u,h)=>{const d=i[h]||[];let m=null,p=1/0;return d.forEach(_=>{const f=a(_);if(f){const I=Math.sqrt((u.x-f.x)**2+(u.y-f.y)**2);I<p&&I>0&&(p=I,m=f)}}),m},c=IY(e).pcb_port.list(),l=IY(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let m=!1;for(const f of l)f.connected_source_port_ids.includes(u.source_port_id)&&f.connected_source_net_ids.length>0&&(m=!0);if(!d)return;const p={x:u.x,y:u.y},_=A(p,d);_&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:p,endPoint:_,isInNet:m})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=O0()),z.jsxs("div",{style:{position:"relative"},children:[n,z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Eg.ratsNestOverlay},children:s.map(({key:a,startPoint:A,endPoint:c,isInNet:l})=>{const g=xt(t,A),u=xt(t,c);return z.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},a)})})]}))},cQi={version:"1.11.404"},_7=(t,e,n)=>{const o=Nc(s=>s.is_mouse_over_container),i=te.useRef(o),r=te.useRef(e);te.useEffect(()=>{i.current=o},[o]),te.useEffect(()=>{r.current=e},[e]),te.useEffect(()=>{if(!t)return;const s=a=>{const A=a.target;if(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!l||a.ctrlKey)&&(!g||a.shiftKey)&&(!u||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},lQi=()=>{const[t,e]=te.useState(!1);return te.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},i$=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),o=te.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=te.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},ume=fY`
5490
+ `,zbi=({children:t,transform:e=O0(),elements:n})=>{const o=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=Nc(m=>({isShowingDRCErrors:m.is_showing_drc_errors,hoveredErrorId:m.hovered_error_id,focusedErrorId:m.focused_error_id})),a=s??r;if(!n)return z.jsx("div",{style:{position:"relative"},ref:o,children:t});const A=n.filter(m=>m.type==="pcb_trace_error"&&!m.message?.includes("Multiple components found with name")),c=n.filter(m=>m.type==="pcb_via_clearance_error"),l=n.filter(m=>m.type==="pcb_trace_error"&&m.message?.includes("Multiple components found with name")),g=rAn(n),u=cAn(n,a),h=m=>{const p=$8i({error:m,indexes:g});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const _=xt(e,p);return Number.isNaN(_.x)||Number.isNaN(_.y)?null:_};let d=null;return u&&(d=h(u)),z.jsxs("div",{style:{position:"relative"},ref:o,children:[t,A.map((m,p)=>{const _=CY(m,p),f=a===_;if(!f&&!i)return null;const I=h(m);if(!I)return null;const C=vze(I,o);return z.jsxs(te.Fragment,{children:[z.jsx(KAn,{errorCenter:I,isHighlighted:f}),z.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Eg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="1")}},onMouseLeave:y=>{if(!f){const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:f?200:100,left:C.left,top:C.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||f?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${Pze}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},_)}),c.map((m,p)=>{const _=CY(m,p),f=a===_;if(!f&&!i)return null;const I=h(m);if(!I)return null;const C=vze({x:I.x,y:I.y},o);return z.jsxs(te.Fragment,{children:[z.jsx(KAn,{errorCenter:I,isHighlighted:f}),z.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Eg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="1")}},onMouseLeave:y=>{if(!f){const x=y.currentTarget.nextElementSibling;if(x){const E=x.querySelector(".error-message");E&&(E.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:f?Eg.errorOverlay+10:Eg.errorOverlay+1,left:C.left,top:C.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:C.transform},children:z.jsx("div",{className:`error-message ${Pze}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},_)}),l.map((m,p)=>{const _=m.component_name||m.message?.match(/name "([^"]+)"/)?.[1];if(!_)return null;const f=n?.filter(y=>y.type==="source_component"&&y.name===_||y.type==="pcb_component"&&n?.find(x=>x.type==="source_component"&&x.source_component_id===y.source_component_id&&x.name===_))||[],I=CY(m,p),C=a===I;return!C&&!i?null:f.map((y,x)=>{let E={x:0,y:0};if(y.type==="pcb_component")E=y.center||{x:0,y:0};else if(y.type==="source_component"){const L=n?.find(G=>G.type==="pcb_component"&&G.source_component_id===y.source_component_id);L&&L.type==="pcb_component"&&(E=L.center||{x:0,y:0})}const B=xt(e,E);if(Number.isNaN(B.x)||Number.isNaN(B.y))return null;const b=Math.abs(e.a),k=Math.max(8,Math.min(30,.5*b)),R=vze(B,o);return z.jsxs(te.Fragment,{children:[z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Eg.errorOverlay},width:"100%",height:"100%",children:C?z.jsx("polygon",{points:`${B.x},${B.y-k*1.25} ${B.x+k},${B.y} ${B.x},${B.y+k*1.25} ${B.x-k},${B.y}`,fill:"#ff4444"}):z.jsx("circle",{cx:B.x,cy:B.y,r:k,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,k*.15):Math.max(1,k*.1),opacity:1})}),z.jsx("div",{style:{position:"absolute",left:B.x-(k+10),top:B.y-(k+10),width:(k+10)*2,height:(k+10)*2,zIndex:Eg.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:L=>{const G=L.currentTarget.nextElementSibling;if(G){const U=G.querySelector(".error-message");U&&(U.style.opacity="1")}},onMouseLeave:L=>{if(!C){const G=L.currentTarget.nextElementSibling;if(G){const U=G.querySelector(".error-message");U&&(U.style.opacity="0")}}}}),z.jsx("div",{style:{position:"absolute",zIndex:C?Eg.errorOverlay+20:Eg.errorOverlay+10,left:R.left,top:R.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:R.transform},children:z.jsx("div",{className:`error-message ${Pze}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:m.message})})]},`${I}_${x}`)})}),d&&z.jsx(Vbi,{center:d})]})};function Jbi(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}var XP=t=>t?.type==="pcb_component",VAn=t=>t?.type==="pcb_group",Wbi=t=>t?.type==="pcb_panel",wze=t=>t?.type==="pcb_board",wu={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},sE={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},Mze=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:sE.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:wu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=xt(e,s.anchor);r.set(s.anchor_id,a)}}),z.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Eg.dimensionOverlay},children:z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,A=s.anchor_id,c=s.target,l=r.get(A),g=xt(e,c),u=c.x-a.x,h=c.y-a.y,d=Math.abs(g.x-l.x),m=Math.abs(g.y-l.y),p=g.y<l.y,_=g.x>l.x,f=p?wu.LABEL_OFFSET_ABOVE:wu.LABEL_OFFSET_BELOW,I=_?wu.LABEL_OFFSET_RIGHT:wu.LABEL_OFFSET_LEFT,C=d>wu.MIN_LINE_LENGTH_FOR_LABEL,y=m>wu.MIN_LINE_LENGTH_FOR_LABEL,x=`${s.display_offset_x??u.toFixed(2)}mm`,E=`${s.display_offset_y??h.toFixed(2)}mm`;return z.jsxs("g",{children:[z.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.LINE_STROKE_WIDTH,strokeDasharray:wu.LINE_DASH_PATTERN}),z.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.LINE_STROKE_WIDTH,strokeDasharray:wu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?z.jsx("circle",{cx:g.x,cy:g.y,r:wu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1}):z.jsxs(z.Fragment,{children:[z.jsx("line",{x1:g.x-wu.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+wu.ANCHOR_MARKER_SIZE,y2:g.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:g.x,y1:g.y-wu.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+wu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH})]}),C&&z.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+f,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:z.jsx("div",{style:{...i,textAlign:"center"},children:x})}),y&&z.jsx("foreignObject",{x:g.x+I,y:Math.min(l.y,g.y),width:wu.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:z.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:_?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:E})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>z.jsxs("g",{children:[z.jsx("line",{x1:a.x-wu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+wu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH}),z.jsx("line",{x1:a.x,y1:a.y-wu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+wu.ANCHOR_MARKER_SIZE,stroke:sE.OFFSET_LINE,strokeWidth:wu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},jbi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(_=>wze(_)),s=t.filter(_=>XP(_)),a=t.filter(_=>VAn(_)),A=e.map(_=>XP(_._parent_pcb_component)?_._parent_pcb_component.pcb_component_id:XP(_._element)?_._element.pcb_component_id:null).filter(_=>!!_),c=new Set;if(A.forEach(_=>{const f=s.find(I=>I.pcb_component_id===_);f?.pcb_group_id&&c.add(f.pcb_group_id)}),!Nc(_=>_.is_showing_group_anchor_offsets)&&A.length===0)return null;const g=s.map(_=>{const f=_.positioned_relative_to_pcb_board_id;if(!f)return null;const I=r.find(C=>C.pcb_board_id===f);return I?{component:_,board:I,type:"component"}:null}).filter(_=>!!_),u=a.map(_=>{const f=_.positioned_relative_to_pcb_board_id;if(!f||!_.center)return null;const I=r.find(C=>C.pcb_board_id===f);return I?{group:_,board:I,type:"group"}:null}).filter(_=>!!_),h=[...g,...u];if(h.length===0)return null;const d=A.length===0,m=h.filter(_=>_.type==="component"?d||A.includes(_.component.pcb_component_id):d||c.has(_.group.pcb_group_id));if(m.length===0)return null;const p=m.map(_=>_.type==="component"?{id:`${_.board.pcb_board_id}-${_.component.pcb_component_id}-${_.type}`,anchor:_.board.center,anchor_id:_.board.pcb_board_id,target:_.component.center,type:"component",display_offset_x:_.component.display_offset_x,display_offset_y:_.component.display_offset_y}:{id:`${_.board.pcb_board_id}-${_.group.pcb_group_id}-${_.type}`,anchor:_.board.center,anchor_id:_.board.pcb_board_id,target:{x:_.group.anchor_position?.x??_.group.center.x,y:_.group.anchor_position?.y??_.group.center.y},type:"group",display_offset_x:_.group.display_offset_x,display_offset_y:_.group.display_offset_y}).filter(_=>!!_);return z.jsx(Mze,{targets:p,transform:n,containerWidth:o,containerHeight:i})},Xbi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(_=>VAn(_)),s=t.filter(_=>XP(_)),a=e.map(_=>XP(_._parent_pcb_component)?_._parent_pcb_component.pcb_component_id:XP(_._element)?_._element.pcb_component_id:null).filter(_=>!!_),A=(_,f)=>{if(f.has(_))return;f.add(_);const I=r.find(C=>C.pcb_group_id===_);I?.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&A(I.positioned_relative_to_pcb_group_id,f)},c=new Set;if(a.forEach(_=>{const f=s.find(I=>I.pcb_component_id===_);f&&(f.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&A(f.positioned_relative_to_pcb_group_id,c),f.pcb_group_id&&A(f.pcb_group_id,c))}),!Nc(_=>_.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=s.map(_=>{if(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id){const f=r.find(I=>I.pcb_group_id===_.positioned_relative_to_pcb_group_id);return f&&f.anchor_position?{component:_,parentGroup:f,type:"component"}:null}if(_.pcb_group_id){const f=r.find(I=>I.pcb_group_id===_.pcb_group_id);return f&&f.anchor_position?{component:_,parentGroup:f,type:"component"}:null}return null}).filter(_=>!!_),u=r.map(_=>{if(_.position_mode==="relative_to_group_anchor"&&_.positioned_relative_to_pcb_group_id){const f=r.find(I=>I.pcb_group_id===_.positioned_relative_to_pcb_group_id);if(f&&f.anchor_position&&_.anchor_position)return{group:_,parentGroup:f,type:"group"}}return null}).filter(_=>!!_),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,m=h.filter(_=>_.type==="component"?d||a.includes(_.component.pcb_component_id):d||c.has(_.group.pcb_group_id)||c.has(_.parentGroup.pcb_group_id));if(m.length===0)return null;const p=m.map(_=>{const f=_.parentGroup.anchor_position;return f?_.type==="component"?_.component.center?{id:`${_.parentGroup.pcb_group_id}-${_.component.pcb_component_id}-${_.type}`,anchor:f,anchor_id:_.parentGroup.pcb_group_id,target:_.component.center,type:"component",display_offset_x:_.component.display_offset_x,display_offset_y:_.component.display_offset_y}:null:_.group.anchor_position?{id:`${_.parentGroup.pcb_group_id}-${_.group.pcb_group_id}-${_.type}`,anchor:f,anchor_id:_.parentGroup.pcb_group_id,target:_.group.anchor_position,type:"group",display_offset_x:_.group.display_offset_x,display_offset_y:_.group.display_offset_y}:null:null}).filter(_=>!!_);return z.jsx(Mze,{targets:p,transform:n,containerWidth:o,containerHeight:i})},qbi=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?Eze([t]):Eze(o)},$bi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)XP(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),XP(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const A=qbi(a,t);if(!A)continue;const c=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,l=c?IY(t).pcb_group.get(c):null;s.push({component:a,bbox:A,group:l})}return s.length===0?null:z.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Eg.dimensionOverlay},children:z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:A,group:c})=>{const l=xt(n,{x:A.minX,y:A.maxY}),g=xt(n,{x:A.maxX,y:A.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=a.center??{x:(A.minX+A.maxX)/2,y:(A.minY+A.maxY)/2},d=xt(n,h);return z.jsxs("g",{children:[z.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),z.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),z.jsx("circle",{cx:d.x,cy:d.y,r:wu.COMPONENT_MARKER_RADIUS,fill:sE.COMPONENT_MARKER_FILL,stroke:sE.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},Zbi=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>Wbi(h)),s=t.filter(h=>wze(h)),a=e.map(h=>wze(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!Nc(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const d=h.pcb_panel_id,m=h.position_mode;if(!d||m!=="relative_to_panel_anchor")return null;const p=r.find(_=>_.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=a.length===0,g=c.filter(h=>l||a.includes(h.board.pcb_board_id));if(g.length===0)return null;const u=g.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return z.jsx(Mze,{targets:u,transform:n,containerWidth:o,containerHeight:i})};function eQi(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(A=>A._element.type==="pcb_trace"),r=o.filter(A=>A.type==="source_trace"),s=e.filter(A=>A._element.type!=="pcb_trace"),a=i.filter(A=>r.some(l=>A._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0)||Sze({primitiveElement:A._element,elements:o})!==null);if(!n)return[...s,...a];if(i.length>1){const A=i.reduce((c,l)=>{const g=c._element.trace_length;return l._element.trace_length<g?l:c},i[0]);return[...s,A]}return e}var tQi={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},nQi=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(A=>!/^[0-9]+$/.test(A)).filter(A=>!A.includes("unnamed_")).sort((A,c)=>c.localeCompare(A)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(A=>`${a}.${A}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},oQi={top:"red",bottom:"aqua"},iQi=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=te.useState(!1),r=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,A,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=oQi[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const p=gAn({primitiveElement:r,elements:n});return p?z.jsx("div",{style:{zIndex:Eg.elementOverlay,position:"absolute",left:e.x+12,top:e.y+12,color:u,pointerEvents:"none"},children:z.jsxs("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"4px 6px",borderRadius:"4px",fontSize:"11px",lineHeight:1.2,textAlign:"left",whiteSpace:"nowrap"},children:[p.text&&z.jsx("div",{children:p.text}),p.name&&z.jsx("div",{style:{marginTop:p.text?"2px":0},children:p.name})]})}):null}const d=nQi(t);return d.trim().length===0?null:z.jsx("div",{style:{zIndex:Eg.elementOverlay,position:"absolute",left:s-A/2-8,top:a-c/2-8,width:A+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:z.jsx("div",{style:{width:o?`calc(100% + ${g*2*l}px)`:"100%",height:o?`calc(100% + ${g*2*l}px)`:"100%",marginLeft:o?`${-g*l}px`:0,marginTop:o?`${-g*l}px`:0,border:`1px solid ${u}`,opacity:o||l===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:z.jsx("div",{style:{position:"absolute",bottom:c+20+g*l,marginRight:o?`${-g*l}px`:0,marginBottom:o?0:-g*l,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},rQi=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=Nc(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=eQi({primitives:s,is_showing_multiple_traces_length:i,elements:n}),z.jsx("div",{style:tQi,children:!o&&s.map(a=>z.jsx(iQi,{primitive:a,mousePos:e,elements:n},a._pcb_drawing_object_id))})},gme=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},zAn=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,A=e[i].y;s>t.y!=A>t.y&&t.x<(a-r)*(t.y-s)/(A-s||Number.EPSILON)+r&&(n=!n)}return n},JAn=(t,e,n,o,i=!1)=>{const r=[];for(const s of t){if(!s._element||!i&&s._element.type==="pcb_trace"&&s.layer!==o)continue;if("x1"in s&&s._element?.type==="pcb_trace"){const c=Hd({x:e.x,y:e.y},{x:s.x1,y:s.y1},{x:s.x2,y:s.y2}),l=s.width||.5,g=Math.max(l*25,2)/n.a;c<g&&r.push(s);continue}if(s.pcb_drawing_type==="polygon"){const c=s.points.map(g=>({x:ct.parse(g.x),y:ct.parse(g.y)})),l=gme(c);if(!l||e.x<l.center.x-l.width/2||e.x>l.center.x+l.width/2||e.y<l.center.y-l.height/2||e.y>l.center.y+l.height/2)continue;zAn(e,c)&&r.push(s);continue}if(s.pcb_drawing_type==="polygon_with_arcs"){const c=s.brep_shape.outer_ring.vertices.map(g=>({x:ct.parse(g.x),y:ct.parse(g.y)})),l=gme(c);if(!l||e.x<l.center.x-l.width/2||e.x>l.center.x+l.width/2||e.y<l.center.y-l.height/2||e.y>l.center.y+l.height/2)continue;zAn(e,c)&&r.push(s);continue}if(!("x"in s&&"y"in s))continue;let a=0,A=0;if("w"in s&&"h"in s)a=s.w,A=s.h;else if("r"in s)a=s.r*2,A=s.r*2;else if("rX"in s&&"rY"in s)a=s.rX*2,A=s.rY*2;else continue;Math.abs(s.x-e.x)<a/2&&Math.abs(s.y-e.y)<A/2&&r.push(s)}return r},sQi=({elements:t,children:e,transform:n,primitives:o,selectedLayer:i,onMouseHoverOverPrimitives:r})=>{const[s,a]=te.useState([]),[A,c]=te.useState({x:0,y:0}),[l,{width:g,height:u}]=e$();te.useEffect(()=>{a([]),r([])},[i,o,r]);const h=te.useMemo(()=>{const m=[];for(const p of s){if(p._element?.type==="pcb_via"||p._element?.type==="pcb_component"||p?.layer==="drill"||p?.is_hoverable===!1)continue;let _=null,f=0,I=0;if(p.pcb_drawing_type==="polygon"){const E=gme(p.points);if(!E)continue;_=E.center,f=E.width,I=E.height}else if(p.pcb_drawing_type==="polygon_with_arcs"){const E=p.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),B=gme(E);if(!B)continue;_=B.center,f=B.width,I=B.height}else p.pcb_drawing_type==="line"?(_={x:(p.x1+p.x2)/2,y:(p.y1+p.y2)/2},f=Math.abs(p.x2-p.x1),I=Math.abs(p.y2-p.y1)):"x"in p&&"y"in p&&(_={x:p.x,y:p.y},f="w"in p?p.w:"r"in p?p.r*2:"rX"in p&&"rY"in p?p.rX*2:0,I="h"in p?p.h:"r"in p?p.r*2:"rX"in p&&"rY"in p?p.rY*2:0);if(!_)continue;const C=xt(n,_),y={w:f*n.a,h:I*n.a},x=m.filter(E=>C.x===E.screen_x&&C.y===E.screen_y&&y.w===E.screen_w&&y.h===E.screen_h).length;m.push({...p,x:_.x,y:_.y,w:f,h:I,screen_x:C.x,screen_y:C.y,screen_w:y.w,screen_h:y.h,same_space_index:x})}return m},[s,n]),d=(m,p,_,f)=>{c({x:m,y:p});const I=xt(n5(_),{x:m,y:p}),C=JAn(f,I,_,i);Jbi(new Set(C.map(y=>y._pcb_drawing_object_id)),new Set(s.map(y=>y._pcb_drawing_object_id)))||(a(C),r(C))};return z.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:m=>{if(n){const p=m.currentTarget.getBoundingClientRect(),_=m.clientX-p.left,f=m.clientY-p.top;d(_,f,n,o)}},onTouchStart:m=>{if(n){const p=m.touches[0],_=m.currentTarget.getBoundingClientRect(),f=p.clientX-_.left,I=p.clientY-_.top;d(f,I,n,o)}},children:[e,z.jsx(rQi,{elements:t,mousePos:A,highlightedPrimitives:h}),n&&z.jsxs(z.Fragment,{children:[z.jsx(jbi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(Xbi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx($bi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u}),z.jsx(Zbi,{elements:t,highlightedPrimitives:h,transform:n,containerWidth:g,containerHeight:u})]})]})},WAn=["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)"],aQi=({children:t,transform:e=O0(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=e$(),a=te.useRef(null),{is_showing_pcb_groups:A,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=Nc(g=>({is_showing_pcb_groups:g.is_showing_pcb_groups,pcb_group_view_mode:g.pcb_group_view_mode,is_showing_group_anchor_offsets:g.is_showing_group_anchor_offsets}));return te.useEffect(()=>{const g=a.current;if(!g||!r||!s)return;g.width=r,g.height=s;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,s),!A))return;const h=n.filter(x=>x.type==="pcb_group"),d=n.filter(x=>x.type==="pcb_component"),m=n.filter(x=>x.type==="source_group"),p=new Map(m.map(x=>[x.source_group_id,x])),_=h.filter(x=>{if(x.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!x.source_group_id)return!1;const E=p.get(x.source_group_id);return E?E.was_automatically_named!==!0:!1}),f=new Map;m.forEach(x=>{const E=x;if(E.parent_source_group_id){const B=f.get(E.parent_source_group_id)||[];B.push(x.source_group_id),f.set(E.parent_source_group_id,B)}});const I=x=>{const E=[],B=f.get(x)||[];for(const b of B)E.push(b),E.push(...I(b));return E},C=x=>{const E=m.find(B=>B.source_group_id===x);return E?.parent_source_group_id?1+C(E.parent_source_group_id):0},y=new Set;if(o.length>0)for(const x of d){if(!o.includes(x.pcb_component_id))continue;const E=x.positioned_relative_to_pcb_group_id??x.pcb_group_id;E&&y.add(E)}_.forEach((x,E)=>{let B=d.filter(Me=>Me.pcb_group_id===x.pcb_group_id);if(x.source_group_id){const Me=I(x.source_group_id),Oe=h.filter(Te=>Te.source_group_id&&Me.includes(Te.source_group_id));for(const Te of Oe){const Se=d.filter(Fe=>Fe.pcb_group_id===Te.pcb_group_id);B=[...B,...Se]}}let b,Q,w,M,k=!1;if(x.center&&x.width&&x.height){k=!0;const Me=x.width/2,Oe=x.height/2;b=x.center.x-Me,w=x.center.x+Me,Q=x.center.y-Oe,M=x.center.y+Oe}else if(B.length===0||(b=1/0,Q=1/0,w=-1/0,M=-1/0,B.forEach(Me=>{if(Me.center&&typeof Me.width=="number"&&typeof Me.height=="number"){const Oe=Me.center.x-Me.width/2,Te=Me.center.x+Me.width/2,Se=Me.center.y+Me.height/2,Fe=Me.center.y-Me.height/2;b=Math.min(b,Oe),w=Math.max(w,Te),Q=Math.min(Q,Fe),M=Math.max(M,Se)}}),b===1/0||w===-1/0))return;const R=x.source_group_id?C(x.source_group_id):0,L=x.source_group_id?I(x.source_group_id).length>0:!1;if(!k){const Te=1+(L?.5:0);b-=Te,w+=Te,Q-=Te,M+=Te}const G=xt(e,{x:b,y:M}),U=xt(e,{x:w,y:M}),Y=xt(e,{x:b,y:Q}),J=xt(e,{x:w,y:Q}),ee=WAn[E%WAn.length];u.strokeStyle=ee,u.lineWidth=2;const j=Math.max(4,Math.min(12,8*Math.abs(e.a))),q=Math.max(2,Math.min(6,4*Math.abs(e.a))),se=j*(L?1.3:1),ne=q;u.setLineDash([se,ne]),u.beginPath(),u.moveTo(G.x,G.y),u.lineTo(U.x,U.y),u.lineTo(J.x,J.y),u.lineTo(Y.x,Y.y),u.closePath(),u.stroke();const ge=Math.max(8,Math.min(12,10*Math.abs(e.a))),he=R==0||R==1?0:R*.11,Ce=ge*(1-he),le=4,_e=x.name||`Group ${E+1}`;u.font=`${Ce}px sans-serif`,u.setLineDash([]);const ye=u.measureText(_e).width+le*2,ve=Ce+le*2,Pe=G.x-5,pe=G.y-5,Qe=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(Pe,pe-ve,ye,ve,Qe),u.fill(),u.fillStyle=ee,u.textAlign="left",u.textBaseline="middle",u.fillText(_e,Pe+le,pe-ve/2),l&&y.has(x.pcb_group_id)&&!!x.anchor_position&&x.anchor_position){const Me=Array.isArray(x.anchor_position)?{x:x.anchor_position[0]??0,y:x.anchor_position[1]??0}:{x:x.anchor_position.x,y:x.anchor_position.y},Oe=xt(e,Me);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const Te=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Oe.x-Te,Oe.y),u.lineTo(Oe.x+Te,Oe.y),u.stroke(),u.beginPath(),u.moveTo(Oe.x,Oe.y-Te),u.lineTo(Oe.x,Oe.y+Te),u.stroke()}})},[n,e,r,s,A,c,l,o]),z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,z.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Eg.pcbGroupOverlay,display:A?"block":"none"}})]})},AQi=({transform:t,soup:e,children:n})=>{const o=Nc(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=te.useMemo(()=>iAn(e||[]),[e]),s=te.useMemo(()=>{if(!e||!o)return[];const a=u=>{const h=IY(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},A=(u,h)=>{const d=i[h]||[];let m=null,p=1/0;return d.forEach(_=>{const f=a(_);if(f){const I=Math.sqrt((u.x-f.x)**2+(u.y-f.y)**2);I<p&&I>0&&(p=I,m=f)}}),m},c=IY(e).pcb_port.list(),l=IY(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let m=!1;for(const f of l)f.connected_source_port_ids.includes(u.source_port_id)&&f.connected_source_net_ids.length>0&&(m=!0);if(!d)return;const p={x:u.x,y:u.y},_=A(p,d);_&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:p,endPoint:_,isInNet:m})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=O0()),z.jsxs("div",{style:{position:"relative"},children:[n,z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Eg.ratsNestOverlay},children:s.map(({key:a,startPoint:A,endPoint:c,isInNet:l})=>{const g=xt(t,A),u=xt(t,c);return z.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},a)})})]}))},cQi={version:"1.11.405"},_7=(t,e,n)=>{const o=Nc(s=>s.is_mouse_over_container),i=te.useRef(o),r=te.useRef(e);te.useEffect(()=>{i.current=o},[o]),te.useEffect(()=>{r.current=e},[e]),te.useEffect(()=>{if(!t)return;const s=a=>{const A=a.target;if(A.tagName==="INPUT"||A.tagName==="TEXTAREA"||A.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!l||a.ctrlKey)&&(!g||a.shiftKey)&&(!u||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},lQi=()=>{const[t,e]=te.useState(!1);return te.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},i$=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),o=te.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=te.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},ume=fY`
5491
5491
  background: #222;
5492
5492
  color: #eee;
5493
5493
  border: 1px solid #555;
@@ -5580,7 +5580,7 @@ test("${c} should solve problem correctly", () => {
5580
5580
  // Add more specific assertions based on expected output
5581
5581
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5582
5582
  })
5583
- `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},rcn=t=>t.activeSubSolver?[t,...rcn(t.activeSubSolver)]:[t],Evi=({solver:t})=>{const e=rcn(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(xvi,{solver:n})]},n.getSolverName()))})},Bvi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=te.useReducer(B=>!B,!1),g=te.useRef(void 0),u=te.useRef(null),h="solver-debugger-last-iteration",[d,m]=te.useState(null),p=te.useRef(null),_=te.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"}],[]),f=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(B===null)return;u.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return te.useEffect(()=>()=>{I()},[]),te.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),te.useEffect(()=>{c&&(I(),f())},[n,c]),te.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[z.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&z.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(B=>z.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&z.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:z.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&z.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:_.map(B=>z.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&z.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),z.jsx(Evi,{solver:t})]})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),z.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Svi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),bvi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Qvi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=bvi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},vvi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Pvi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},scn=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},wvi=t=>Object.entries(t).map(([e,n])=>`${e}: ${scn(n)}`).join(", "),Mvi=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=wvi(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",scn(i)]},o))})]})},Hze=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Hze);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Hze(o));return e},Dvi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Hze(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},Nvi=({expanded:t})=>z.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 ${t?"rotate-90":""}`,children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),acn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},Acn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=te.useState(new Set),A=t.pipelineDef.map((p,_)=>Qvi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):Dvi(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=acn(t);for(;!t.solved&&!t.failed&&(t.step(),acn(t)===p););r?.()}},m=i*24;return z.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&z.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),z.jsxs("div",{className:"flex gap-2",children:[z.jsx("button",{onClick:d,disabled:t.solved||t.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"}),z.jsx("button",{onClick:h,disabled:t.solved||t.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"})]})]}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[!o&&z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:A.map(p=>{const _=Svi(p.solverInstance),f=s.has(p.name);return z.jsxs(ws.Fragment,{children:[z.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?z.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:z.jsx(Nvi,{expanded:f})}):z.jsx("span",{className:"w-4"}),z.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>l(p.name),disabled:p.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${p.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(vvi,{status:p.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(Pvi,{progress:p.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(Mvi,{stats:p.stats})}),z.jsx("td",{className:"px-4 py-2",children:p.solverInstance?z.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),z.jsx("span",{children:"Input"})]}):null})]}),_&&f&&z.jsx("tr",{children:z.jsx("td",{colSpan:8,className:"p-0",children:z.jsx(Acn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function Rvi({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>z.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>z.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>z.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var Tvi=class extends ws.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}},kvi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(f=>f+1,0),[a]=te.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=te.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=te.useState(n),u=te.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=te.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),te.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return z.jsxs("div",{children:[z.jsx(Bvi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(Tvi,{fallback:z.jsx(Rvi,{graphics:u}),children:A==="canvas"?z.jsx(yvi,{graphics:u}):z.jsx(fvi,{graphics:u})}),d&&z.jsx(Acn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const Fvi=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},Lvi=1e3,aE=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},Lvi)},Oze=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},Hvi=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},f7="https://github.com/tscircuit/tscircuit-autorouter/issues/new",ccn="https://github.com/tscircuit/copper-pour-solver/issues/new",lcn="https://github.com/tscircuit/calculate-packing/issues/new",Ovi="https://github.com/tscircuit/matchpack/issues/new",gcn="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",Gvi={PackSolver2:lcn,LayoutPipelineSolver:Ovi,AutoroutingPipelineSolver:f7,AssignableAutoroutingPipeline2:f7,AssignableAutoroutingPipeline3:f7,AutoroutingPipeline1_OriginalUnravel:f7,AutoroutingPipelineSolver3_HgPortPointPathing:f7,AutoroutingPipelineSolver4:f7,AutoroutingPipelineSolver5:f7,AutoroutingPipelineSolver7_MultiGraph:f7,AutoroutingPipelineSolver8:f7,CopperPourPipelineSolver:ccn,SchematicTracePipelineSolver:gcn},Yvi=t=>t.toLowerCase().includes("pack")?P2i:t.toLowerCase().includes("rout")?Cin:y2i,ucn=t=>{const e=Gvi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?f7:n.includes("schematic")&&n.includes("trace")?gcn:n.includes("copperpour")?ccn:n.includes("pack")?lcn:null},Uvi=t=>`${Oze(`${t.componentName}-${t.solverName}`)}-solver-input.json`,dcn=t=>{aE(JSON.stringify(t.solverParams,null,2),{fileName:Uvi(t),mimeType:"application/json"})},Kvi=({solverEvent:t})=>{const e=ucn(t.solverName);return z.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:[z.jsxs(Vc,{type:"button",variant:"outline",size:"sm",onClick:()=>dcn(t),children:[z.jsx(Sq,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(Vc,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx(Yde,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(Vc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx(Yde,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},Vvi=({solverEvent:t})=>{const e=ucn(t.solverName);return e?z.jsx(Vc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx(Yde,{className:"rf-w-4 rf-h-4"})})}):z.jsx(Vc,{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:z.jsx(Yde,{className:"rf-w-4 rf-h-4"})})},zvi=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);Fvi();const o=te.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=kDe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(kDe).join(", ")}`,classFound:!1};try{return{instance:new a(...Hvi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=Yvi(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(Kvi,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(bB,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(kvi,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.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:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(Vvi,{solverEvent:r}),z.jsx(Vc,{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:()=>dcn(r),children:z.jsx(Sq,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Jvi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Wvi=new Set(["tscircuit","default","auto","auto_local"]);function jvi(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function Xvi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&Jvi.get(n);if(o)return o;if(n&&!Wvi.has(n))return e;const i=t.solverName?.trim();if(i)return jvi(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const Gze="#fbbf24";function qvi(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function hcn(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function $vi(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function mcn(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...$vi(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function Zvi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(hcn(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of mcn(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:Gze,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:Gze,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function ePi(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const tPi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function nPi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!tPi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:qvi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=mcn(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${ePi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const Yze=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,pcn=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",_cn=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,oPi={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},iPi=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=te.useState(null),[r,s]=te.useState("output"),[a,A]=te.useState(!0),[c,l]=te.useState(!1),g=te.useRef(null),[u,h]=te.useState(480),d=o?e.findIndex(R=>R.id===o.id&&_cn(R)===_cn(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=te.useMemo(()=>!p||!x?null:nPi(t??[],p,y),[t,p,x,y]),B=te.useMemo(()=>p&&y==="output"&&a?Zvi(p):{lines:[],circles:[]},[p,y,a]);if(te.useLayoutEffect(()=>{const R=g.current;if(!R)return;const L=()=>h(Math.max(360,R.clientHeight));L();const G=new ResizeObserver(L);return G.observe(R),()=>G.disconnect()},[!!p]),!p)return z.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:[z.jsx(Cin,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),z.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),z.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"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 b=Yze(p,m),Q=p.status==="running"&&n,w=!f,M=I?.connections.length,k=E?.filter(R=>R.type==="pcb_trace").length??0;return z.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:[z.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:[z.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:[z.jsx("span",{children:"Routing phases"}),z.jsx("span",{children:e.length})]}),z.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:e.map((R,L)=>{const G=hcn(R).length,U=R.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:R.status==="error"?"Failed":R.status==="running"&&n?"Routing…":"No output";return z.jsxs("button",{type:"button","aria-pressed":L===m,title:`${pcn(R)} · ${U}`,onClick:()=>i(R),className:Ur("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",L===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[z.jsx("span",{className:Ur("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",L===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:L+1}),z.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[z.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[z.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:Yze(R,L),children:Yze(R,L)}),R.status==="complete"?z.jsx(Bq,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):R.status==="error"?z.jsx(PKe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?z.jsx(K5,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),z.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[Xvi(R)," · ",U]})]})]},R.id)})})]}),z.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[z.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:[z.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,z.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&z.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),z.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(R=>z.jsx("button",{type:"button","aria-pressed":y===R,disabled:R==="input"?!C:!f,onClick:()=>s(R),className:Ur("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===R?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:R==="input"?"Input":"Output"},R))})]}),z.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:[z.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:R=>A(R.target.checked),className:"rf-accent-blue-600"}),z.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Gze}}),"Highlight changes (all layers)"]}),z.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&z.jsx("div",{className:Ur("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.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:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),z.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?z.jsx(Dze,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:oPi,debugGraphics:B}):z.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),z.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:[z.jsxs("span",{children:[M===void 0?"Input unavailable":`${M} input connections`,` · ${pcn(p)}`]}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[z.jsxs("button",{type:"button",disabled:!x,onClick:()=>aE(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[z.jsx(Sq,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),z.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(qG,{className:Ur("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&z.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":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},fcn=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{qT.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{qT.captureException(i,{error_type:o.type})}catch{}}},[n])},rPi=t=>{te.useEffect(()=>{try{l3n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},Icn="0.0.2786",sPi={version:Icn},Uze={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Kze=new Map,hme=t=>{const e=Kze.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},aPi=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Kze.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return Kze.set(n.name,i),{type:"tracked",store:t,...i}},Ccn=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(Uze?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Uze?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=aPi(a,c,A);let u=!0;i.setState=(m,p,_)=>{const f=n(m,p);if(!u)return f;const I=_===void 0?{type:s||"anonymous"}:typeof _=="string"?{type:_}:_;return a===void 0?(l?.send(I,o()),f):(l?.send({...I,type:`${a}/${I.type}`},{...hme(A.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=u;u=!1,n(...m),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([m,p])=>[m,m===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(..._)=>{(Uze?"production":void 0)!=="production"&&_[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(..._)}}return l.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Vze(m.payload,_=>{if(_.type==="__setState"){if(a===void 0){h(_.state);return}Object.keys(_.state).length!==1&&console.error(`
5583
+ `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},rcn=t=>t.activeSubSolver?[t,...rcn(t.activeSubSolver)]:[t],Evi=({solver:t})=>{const e=rcn(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(xvi,{solver:n})]},n.getSolverName()))})},Bvi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=te.useReducer(B=>!B,!1),g=te.useRef(void 0),u=te.useRef(null),h="solver-debugger-last-iteration",[d,m]=te.useState(null),p=te.useRef(null),_=te.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"}],[]),f=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(B===null)return;u.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return te.useEffect(()=>()=>{I()},[]),te.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),te.useEffect(()=>{c&&(I(),f())},[n,c]),te.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[z.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&z.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(B=>z.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&z.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:z.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&z.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:_.map(B=>z.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&z.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),z.jsx(Evi,{solver:t})]})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),z.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Svi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),bvi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Qvi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=bvi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},vvi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Pvi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},scn=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},wvi=t=>Object.entries(t).map(([e,n])=>`${e}: ${scn(n)}`).join(", "),Mvi=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=wvi(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",scn(i)]},o))})]})},Hze=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Hze);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Hze(o));return e},Dvi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Hze(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},Nvi=({expanded:t})=>z.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 ${t?"rotate-90":""}`,children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),acn=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},Acn=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=te.useState(new Set),A=t.pipelineDef.map((p,_)=>Qvi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):Dvi(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=acn(t);for(;!t.solved&&!t.failed&&(t.step(),acn(t)===p););r?.()}},m=i*24;return z.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&z.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),z.jsxs("div",{className:"flex gap-2",children:[z.jsx("button",{onClick:d,disabled:t.solved||t.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"}),z.jsx("button",{onClick:h,disabled:t.solved||t.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"})]})]}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[!o&&z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:A.map(p=>{const _=Svi(p.solverInstance),f=s.has(p.name);return z.jsxs(ws.Fragment,{children:[z.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?z.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:z.jsx(Nvi,{expanded:f})}):z.jsx("span",{className:"w-4"}),z.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>l(p.name),disabled:p.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${p.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(vvi,{status:p.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(Pvi,{progress:p.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(Mvi,{stats:p.stats})}),z.jsx("td",{className:"px-4 py-2",children:p.solverInstance?z.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),z.jsx("span",{children:"Input"})]}):null})]}),_&&f&&z.jsx("tr",{children:z.jsx("td",{colSpan:8,className:"p-0",children:z.jsx(Acn,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function Rvi({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>z.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>z.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>z.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var Tvi=class extends ws.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}},kvi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(f=>f+1,0),[a]=te.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=te.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=te.useState(n),u=te.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=te.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),te.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return z.jsxs("div",{children:[z.jsx(Bvi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(Tvi,{fallback:z.jsx(Rvi,{graphics:u}),children:A==="canvas"?z.jsx(yvi,{graphics:u}):z.jsx(fvi,{graphics:u})}),d&&z.jsx(Acn,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const Fvi=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},Lvi=1e3,aE=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},Lvi)},Oze=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},Hvi=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},f7="https://github.com/tscircuit/tscircuit-autorouter/issues/new",ccn="https://github.com/tscircuit/copper-pour-solver/issues/new",lcn="https://github.com/tscircuit/calculate-packing/issues/new",Ovi="https://github.com/tscircuit/matchpack/issues/new",gcn="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",Gvi={PackSolver2:lcn,LayoutPipelineSolver:Ovi,AutoroutingPipelineSolver:f7,AssignableAutoroutingPipeline2:f7,AssignableAutoroutingPipeline3:f7,AutoroutingPipeline1_OriginalUnravel:f7,AutoroutingPipelineSolver3_HgPortPointPathing:f7,AutoroutingPipelineSolver4:f7,AutoroutingPipelineSolver5:f7,AutoroutingPipelineSolver7_MultiGraph:f7,AutoroutingPipelineSolver8:f7,CopperPourPipelineSolver:ccn,SchematicTracePipelineSolver:gcn},Yvi=t=>t.toLowerCase().includes("pack")?P2i:t.toLowerCase().includes("rout")?Cin:y2i,ucn=t=>{const e=Gvi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?f7:n.includes("schematic")&&n.includes("trace")?gcn:n.includes("copperpour")?ccn:n.includes("pack")?lcn:null},Uvi=t=>`${Oze(`${t.componentName}-${t.solverName}`)}-solver-input.json`,dcn=t=>{aE(JSON.stringify(t.solverParams,null,2),{fileName:Uvi(t),mimeType:"application/json"})},Kvi=({solverEvent:t})=>{const e=ucn(t.solverName);return z.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:[z.jsxs(Vc,{type:"button",variant:"outline",size:"sm",onClick:()=>dcn(t),children:[z.jsx(Sq,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(Vc,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx(Yde,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(Vc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx(Yde,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},Vvi=({solverEvent:t})=>{const e=ucn(t.solverName);return e?z.jsx(Vc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx(Yde,{className:"rf-w-4 rf-h-4"})})}):z.jsx(Vc,{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:z.jsx(Yde,{className:"rf-w-4 rf-h-4"})})},zvi=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);Fvi();const o=te.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=kDe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(kDe).join(", ")}`,classFound:!1};try{return{instance:new a(...Hvi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=Yvi(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(Kvi,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(bB,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(kvi,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.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:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(Vvi,{solverEvent:r}),z.jsx(Vc,{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:()=>dcn(r),children:z.jsx(Sq,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Jvi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Wvi=new Set(["tscircuit","default","auto","auto_local"]);function jvi(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function Xvi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&Jvi.get(n);if(o)return o;if(n&&!Wvi.has(n))return e;const i=t.solverName?.trim();if(i)return jvi(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const Gze="#fbbf24";function qvi(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function hcn(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function $vi(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function mcn(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...$vi(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function Zvi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(hcn(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of mcn(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:Gze,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:Gze,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function ePi(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const tPi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function nPi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!tPi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:qvi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=mcn(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${ePi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const Yze=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,pcn=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",_cn=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,oPi={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},iPi=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=te.useState(null),[r,s]=te.useState("output"),[a,A]=te.useState(!0),[c,l]=te.useState(!1),g=te.useRef(null),[u,h]=te.useState(480),d=o?e.findIndex(R=>R.id===o.id&&_cn(R)===_cn(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=te.useMemo(()=>!p||!x?null:nPi(t??[],p,y),[t,p,x,y]),B=te.useMemo(()=>p&&y==="output"&&a?Zvi(p):{lines:[],circles:[]},[p,y,a]);if(te.useLayoutEffect(()=>{const R=g.current;if(!R)return;const L=()=>h(Math.max(360,R.clientHeight));L();const G=new ResizeObserver(L);return G.observe(R),()=>G.disconnect()},[!!p]),!p)return z.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:[z.jsx(Cin,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),z.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),z.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"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 b=Yze(p,m),Q=p.status==="running"&&n,w=!f,M=I?.connections.length,k=E?.filter(R=>R.type==="pcb_trace").length??0;return z.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:[z.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:[z.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:[z.jsx("span",{children:"Routing phases"}),z.jsx("span",{children:e.length})]}),z.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:e.map((R,L)=>{const G=hcn(R).length,U=R.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:R.status==="error"?"Failed":R.status==="running"&&n?"Routing…":"No output";return z.jsxs("button",{type:"button","aria-pressed":L===m,title:`${pcn(R)} · ${U}`,onClick:()=>i(R),className:Ur("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",L===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[z.jsx("span",{className:Ur("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",L===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:L+1}),z.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[z.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[z.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:Yze(R,L),children:Yze(R,L)}),R.status==="complete"?z.jsx(Bq,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):R.status==="error"?z.jsx(PKe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?z.jsx(K5,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),z.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[Xvi(R)," · ",U]})]})]},R.id)})})]}),z.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[z.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:[z.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,z.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&z.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),z.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(R=>z.jsx("button",{type:"button","aria-pressed":y===R,disabled:R==="input"?!C:!f,onClick:()=>s(R),className:Ur("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===R?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:R==="input"?"Input":"Output"},R))})]}),z.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:[z.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:R=>A(R.target.checked),className:"rf-accent-blue-600"}),z.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Gze}}),"Highlight changes (all layers)"]}),z.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),w&&z.jsx("div",{className:Ur("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.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:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),z.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?z.jsx(Dze,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:oPi,debugGraphics:B}):z.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),z.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:[z.jsxs("span",{children:[M===void 0?"Input unavailable":`${M} input connections`,` · ${pcn(p)}`]}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[z.jsxs("button",{type:"button",disabled:!x,onClick:()=>aE(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[z.jsx(Sq,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),z.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(qG,{className:Ur("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&z.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":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},fcn=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{qT.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{qT.captureException(i,{error_type:o.type})}catch{}}},[n])},rPi=t=>{te.useEffect(()=>{try{l3n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},Icn="0.0.2788",sPi={version:Icn},Uze={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Kze=new Map,hme=t=>{const e=Kze.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},aPi=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Kze.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return Kze.set(n.name,i),{type:"tracked",store:t,...i}},Ccn=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(Uze?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Uze?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=aPi(a,c,A);let u=!0;i.setState=(m,p,_)=>{const f=n(m,p);if(!u)return f;const I=_===void 0?{type:s||"anonymous"}:typeof _=="string"?{type:_}:_;return a===void 0?(l?.send(I,o()),f):(l?.send({...I,type:`${a}/${I.type}`},{...hme(A.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=u;u=!1,n(...m),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([m,p])=>[m,m===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(..._)=>{(Uze?"production":void 0)!=="production"&&_[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(..._)}}return l.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Vze(m.payload,_=>{if(_.type==="__setState"){if(a===void 0){h(_.state);return}Object.keys(_.state).length!==1&&console.error(`
5584
5584
  [zustand devtools middleware] Unsupported __setState action format.
5585
5585
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5586
5586
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }