@tscircuit/runframe 0.0.2377 → 0.0.2378

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.
@@ -2181,7 +2181,7 @@ var usePostHogActivity = (properties) => {
2181
2181
  };
2182
2182
 
2183
2183
  // package.json
2184
- var version = "0.0.2376";
2184
+ var version = "0.0.2377";
2185
2185
  var package_default = {
2186
2186
  name: "@tscircuit/runframe",
2187
2187
  main: "dist/preview.js",
@@ -2236,7 +2236,7 @@ var package_default = {
2236
2236
  "@tscircuit/fake-snippets": "^0.0.163",
2237
2237
  "@tscircuit/file-server": "^0.0.32",
2238
2238
  "@tscircuit/internal-dynamic-import": "^0.0.13",
2239
- "@tscircuit/pcb-viewer": "1.11.378",
2239
+ "@tscircuit/pcb-viewer": "1.11.379",
2240
2240
  "@tscircuit/props": "^0.0.612",
2241
2241
  "@tscircuit/schematic-viewer": "^2.0.76",
2242
2242
  "@types/bun": "latest",
package/dist/preview.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  SchematicViewer,
8
8
  useOrderDialog,
9
9
  useOrderDialogCli
10
- } from "./chunk-SFBHPQFJ.js";
10
+ } from "./chunk-TE4NKB6D.js";
11
11
  export {
12
12
  BomTable,
13
13
  CadViewer,
package/dist/runner.js CHANGED
@@ -39,7 +39,7 @@ import {
39
39
  useRunFrameStore,
40
40
  useRunnerStore,
41
41
  useStyles
42
- } from "./chunk-SFBHPQFJ.js";
42
+ } from "./chunk-TE4NKB6D.js";
43
43
 
44
44
  // lib/components/RunFrame/RunFrame.tsx
45
45
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5681,7 +5681,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function h7t(t,e,n){if(!e||!n)retu
5681
5681
  transition: opacity 0.2s;
5682
5682
  margin-bottom: 10px;
5683
5683
  color: red;
5684
- `,Eko=({children:t,transform:e=vl(),elements:n})=>{const o=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:A}=sd(_=>({isShowingDRCErrors:_.is_showing_drc_errors,hoveredErrorId:_.hovered_error_id,focusedErrorId:_.focused_error_id})),s=A??r;if(!n)return q.jsx("div",{style:{position:"relative"},ref:o,children:t});const a=n.filter(_=>_.type==="pcb_trace_error"&&!_.message?.includes("Multiple components found with name")),c=n.filter(_=>_.type==="pcb_via_clearance_error"),l=n.filter(_=>_.type==="pcb_trace_error"&&_.message?.includes("Multiple components found with name")),g=Q7t(n),u=B7t(n,s),h=_=>{const p=GRo({error:_,indexes:g});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const m=mt(e,p);return Number.isNaN(m.x)||Number.isNaN(m.y)?null:m};let d=null;return u&&(d=h(u)),q.jsxs("div",{style:{position:"relative"},ref:o,children:[t,a.map((_,p)=>{const m=gT(_,p),C=s===m;if(!C&&!i)return null;const I=h(_);if(!I)return null;const f=C3e(I,o);return q.jsxs(te.Fragment,{children:[q.jsx(W7t,{errorCenter:I,isHighlighted:C}),q.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Yl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!C){const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),q.jsx("div",{style:{position:"absolute",zIndex:C?200:100,left:f.left,top:f.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:f.transform},children:q.jsx("div",{className:`error-message ${f3e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},m)}),c.map((_,p)=>{const m=gT(_,p),C=s===m;if(!C&&!i)return null;const I=h(_);if(!I)return null;const f=C3e({x:I.x,y:I.y},o);return q.jsxs(te.Fragment,{children:[q.jsx(W7t,{errorCenter:I,isHighlighted:C}),q.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Yl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!C){const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),q.jsx("div",{style:{position:"absolute",zIndex:C?Yl.errorOverlay+10:Yl.errorOverlay+1,left:f.left,top:f.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:f.transform},children:q.jsx("div",{className:`error-message ${f3e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},m)}),l.map((_,p)=>{const m=_.component_name||_.message?.match(/name "([^"]+)"/)?.[1];if(!m)return null;const C=n?.filter(y=>y.type==="source_component"&&y.name===m||y.type==="pcb_component"&&n?.find(x=>x.type==="source_component"&&x.source_component_id===y.source_component_id&&x.name===m))||[],I=gT(_,p),f=s===I;return!f&&!i?null:C.map((y,x)=>{let B={x:0,y:0};if(y.type==="pcb_component")B=y.center||{x:0,y:0};else if(y.type==="source_component"){const K=n?.find(J=>J.type==="pcb_component"&&J.source_component_id===y.source_component_id);K&&K.type==="pcb_component"&&(B=K.center||{x:0,y:0})}const S=mt(e,B);if(Number.isNaN(S.x)||Number.isNaN(S.y))return null;const D=Math.abs(e.a),H=Math.max(8,Math.min(30,.5*D)),G=C3e(S,o);return q.jsxs(te.Fragment,{children:[q.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yl.errorOverlay},width:"100%",height:"100%",children:f?q.jsx("polygon",{points:`${S.x},${S.y-H*1.25} ${S.x+H},${S.y} ${S.x},${S.y+H*1.25} ${S.x-H},${S.y}`,fill:"#ff4444"}):q.jsx("circle",{cx:S.x,cy:S.y,r:H,fill:"none",stroke:f?"#ff4444":"red",strokeWidth:f?Math.max(2,H*.15):Math.max(1,H*.1),opacity:1})}),q.jsx("div",{style:{position:"absolute",left:S.x-(H+10),top:S.y-(H+10),width:(H+10)*2,height:(H+10)*2,zIndex:Yl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:K=>{const J=K.currentTarget.nextElementSibling;if(J){const W=J.querySelector(".error-message");W&&(W.style.opacity="1")}},onMouseLeave:K=>{if(!f){const J=K.currentTarget.nextElementSibling;if(J){const W=J.querySelector(".error-message");W&&(W.style.opacity="0")}}}}),q.jsx("div",{style:{position:"absolute",zIndex:f?Yl.errorOverlay+20:Yl.errorOverlay+10,left:G.left,top:G.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||f?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:G.transform},children:q.jsx("div",{className:`error-message ${f3e}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:_.message})})]},`${I}_${x}`)})}),d&&q.jsx(yko,{center:d})]})};function xko(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function Bko({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const o=nw(e).source_trace.get(t?.source_trace_id);if(o?.display_name&&(o?.max_length?n+=` / ${o.max_length}mm `:n+=" mm ",n+=`(${o.display_name})`),!n)return null;const i=t.trace_length&&o?.max_length&&t.trace_length>o.max_length;return{text:n,isOverLength:i}}function Qko(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"),A=e.filter(a=>a._element.type!=="pcb_trace"),s=i.filter(a=>r.some(c=>a._element.type==="pcb_trace"&&a._element.source_trace_id===c.source_trace_id&&c.max_length!==void 0));if(!n)return[...A,...s];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[...A,a]}return e}var Sko={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},bko=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=[],A=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)),s=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return A.length>0?s?r.push(...A.map(a=>`${s}.${a}`)):r.push(...A):s&&r.push(s),r.join(", ")}default:return""}},Dko={top:"red",bottom:"aqua"},Mko=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=te.useState(!1),r=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[A,s,a,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=Dko[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=Bko({primitiveElement:r,elements:n});if(!p)return null;const m=e.y-35;return q.jsx("div",{style:{zIndex:Yl.elementOverlay,position:"absolute",left:e.x,top:m,color:u,pointerEvents:"none",transform:"translateX(-50%)"},children:q.jsx("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:p.text})})}const d=bko(t);return d.trim().length===0?null:q.jsx("div",{style:{zIndex:Yl.elementOverlay,position:"absolute",left:A-a/2-8,top:s-c/2-8,width:a+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:q.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:q.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})})})},wko=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=sd(s=>[s.is_moving_component,s.is_showing_multiple_traces_length]),r=t.some(s=>s._element.type==="pcb_smtpad")&&t.some(s=>s._element.type==="pcb_trace");let A=t;return r&&(A=A.filter(s=>s._element.type==="pcb_smtpad")),A=Qko({primitives:A,is_showing_multiple_traces_length:i,elements:n}),q.jsx("div",{style:Sko,children:!o&&A.map((s,a)=>q.jsx(Mko,{primitive:s,mousePos:e,elements:n},a))})},ow=t=>t?.type==="pcb_component",j7t=t=>t?.type==="pcb_group",Pko=t=>t?.type==="pcb_panel",y3e=t=>t?.type==="pcb_board",p0={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},R2={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},E3e=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:R2.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:p0.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(A=>{if(!r.has(A.anchor_id)){const s=mt(e,A.anchor);r.set(A.anchor_id,s)}}),q.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Yl.dimensionOverlay},children:q.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(A=>{const s=A.anchor,a=A.anchor_id,c=A.target,l=r.get(a),g=mt(e,c),u=c.x-s.x,h=c.y-s.y,d=Math.abs(g.x-l.x),_=Math.abs(g.y-l.y),p=g.y<l.y,m=g.x>l.x,C=p?p0.LABEL_OFFSET_ABOVE:p0.LABEL_OFFSET_BELOW,I=m?p0.LABEL_OFFSET_RIGHT:p0.LABEL_OFFSET_LEFT,f=d>p0.MIN_LINE_LENGTH_FOR_LABEL,y=_>p0.MIN_LINE_LENGTH_FOR_LABEL,x=`${A.display_offset_x??u.toFixed(2)}mm`,B=`${A.display_offset_y??h.toFixed(2)}mm`;return q.jsxs("g",{children:[q.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.LINE_STROKE_WIDTH,strokeDasharray:p0.LINE_DASH_PATTERN}),q.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.LINE_STROKE_WIDTH,strokeDasharray:p0.LINE_DASH_PATTERN}),A.type==="component"||A.type==="board"?q.jsx("circle",{cx:g.x,cy:g.y,r:p0.COMPONENT_MARKER_RADIUS,fill:R2.COMPONENT_MARKER_FILL,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1}):q.jsxs(q.Fragment,{children:[q.jsx("line",{x1:g.x-p0.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+p0.ANCHOR_MARKER_SIZE,y2:g.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH}),q.jsx("line",{x1:g.x,y1:g.y-p0.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+p0.ANCHOR_MARKER_SIZE,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&q.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+C,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:q.jsx("div",{style:{...i,textAlign:"center"},children:x})}),y&&q.jsx("foreignObject",{x:g.x+I,y:Math.min(l.y,g.y),width:p0.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:q.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:m?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:B})})]},A.id)}),Array.from(r.entries()).map(([A,s])=>q.jsxs("g",{children:[q.jsx("line",{x1:s.x-p0.ANCHOR_MARKER_SIZE,y1:s.y,x2:s.x+p0.ANCHOR_MARKER_SIZE,y2:s.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH}),q.jsx("line",{x1:s.x,y1:s.y-p0.ANCHOR_MARKER_SIZE,x2:s.x,y2:s.y+p0.ANCHOR_MARKER_SIZE,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${A}`))]})})},vko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(m=>y3e(m)),A=t.filter(m=>ow(m)),s=t.filter(m=>j7t(m)),a=e.map(m=>ow(m._parent_pcb_component)?m._parent_pcb_component.pcb_component_id:ow(m._element)?m._element.pcb_component_id:null).filter(m=>!!m),c=new Set;if(a.forEach(m=>{const C=A.find(I=>I.pcb_component_id===m);C?.pcb_group_id&&c.add(C.pcb_group_id)}),!sd(m=>m.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=A.map(m=>{const C=m.positioned_relative_to_pcb_board_id;if(!C)return null;const I=r.find(f=>f.pcb_board_id===C);return I?{component:m,board:I,type:"component"}:null}).filter(m=>!!m),u=s.map(m=>{const C=m.positioned_relative_to_pcb_board_id;if(!C||!m.center)return null;const I=r.find(f=>f.pcb_board_id===C);return I?{group:m,board:I,type:"group"}:null}).filter(m=>!!m),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,_=h.filter(m=>m.type==="component"?d||a.includes(m.component.pcb_component_id):d||c.has(m.group.pcb_group_id));if(_.length===0)return null;const p=_.map(m=>m.type==="component"?{id:`${m.board.pcb_board_id}-${m.component.pcb_component_id}-${m.type}`,anchor:m.board.center,anchor_id:m.board.pcb_board_id,target:m.component.center,type:"component",display_offset_x:m.component.display_offset_x,display_offset_y:m.component.display_offset_y}:{id:`${m.board.pcb_board_id}-${m.group.pcb_group_id}-${m.type}`,anchor:m.board.center,anchor_id:m.board.pcb_board_id,target:{x:m.group.anchor_position?.x??m.group.center.x,y:m.group.anchor_position?.y??m.group.center.y},type:"group",display_offset_x:m.group.display_offset_x,display_offset_y:m.group.display_offset_y}).filter(m=>!!m);return q.jsx(E3e,{targets:p,transform:n,containerWidth:o,containerHeight:i})},Nko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(m=>j7t(m)),A=t.filter(m=>ow(m)),s=e.map(m=>ow(m._parent_pcb_component)?m._parent_pcb_component.pcb_component_id:ow(m._element)?m._element.pcb_component_id:null).filter(m=>!!m),a=(m,C)=>{if(C.has(m))return;C.add(m);const I=r.find(f=>f.pcb_group_id===m);I?.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&a(I.positioned_relative_to_pcb_group_id,C)},c=new Set;if(s.forEach(m=>{const C=A.find(I=>I.pcb_component_id===m);C&&(C.position_mode==="relative_to_group_anchor"&&C.positioned_relative_to_pcb_group_id&&a(C.positioned_relative_to_pcb_group_id,c),C.pcb_group_id&&a(C.pcb_group_id,c))}),!sd(m=>m.is_showing_group_anchor_offsets)&&s.length===0)return null;const g=A.map(m=>{if(m.position_mode==="relative_to_group_anchor"&&m.positioned_relative_to_pcb_group_id){const C=r.find(I=>I.pcb_group_id===m.positioned_relative_to_pcb_group_id);return C&&C.anchor_position?{component:m,parentGroup:C,type:"component"}:null}if(m.pcb_group_id){const C=r.find(I=>I.pcb_group_id===m.pcb_group_id);return C&&C.anchor_position?{component:m,parentGroup:C,type:"component"}:null}return null}).filter(m=>!!m),u=r.map(m=>{if(m.position_mode==="relative_to_group_anchor"&&m.positioned_relative_to_pcb_group_id){const C=r.find(I=>I.pcb_group_id===m.positioned_relative_to_pcb_group_id);if(C&&C.anchor_position&&m.anchor_position)return{group:m,parentGroup:C,type:"group"}}return null}).filter(m=>!!m),h=[...g,...u];if(h.length===0)return null;const d=s.length===0,_=h.filter(m=>m.type==="component"?d||s.includes(m.component.pcb_component_id):d||c.has(m.group.pcb_group_id)||c.has(m.parentGroup.pcb_group_id));if(_.length===0)return null;const p=_.map(m=>{const C=m.parentGroup.anchor_position;return C?m.type==="component"?m.component.center?{id:`${m.parentGroup.pcb_group_id}-${m.component.pcb_component_id}-${m.type}`,anchor:C,anchor_id:m.parentGroup.pcb_group_id,target:m.component.center,type:"component",display_offset_x:m.component.display_offset_x,display_offset_y:m.component.display_offset_y}:null:m.group.anchor_position?{id:`${m.parentGroup.pcb_group_id}-${m.group.pcb_group_id}-${m.type}`,anchor:C,anchor_id:m.parentGroup.pcb_group_id,target:m.group.anchor_position,type:"group",display_offset_x:m.group.display_offset_x,display_offset_y:m.group.display_offset_y}:null:null}).filter(m=>!!m);return q.jsx(E3e,{targets:p,transform:n,containerWidth:o,containerHeight:i})},Rko=(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?m3e([t]):m3e(o)},Tko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const s of e)ow(s._parent_pcb_component)&&r.set(s._parent_pcb_component.pcb_component_id,s._parent_pcb_component),ow(s._element)&&r.set(s._element.pcb_component_id,s._element);if(r.size===0)return null;const A=[];for(const s of r.values()){const a=Rko(s,t);if(!a)continue;const c=s.positioned_relative_to_pcb_group_id??s.pcb_group_id,l=c?nw(t).pcb_group.get(c):null;A.push({component:s,bbox:a,group:l})}return A.length===0?null:q.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Yl.dimensionOverlay},children:q.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:A.map(({component:s,bbox:a,group:c})=>{const l=mt(n,{x:a.minX,y:a.maxY}),g=mt(n,{x:a.maxX,y:a.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=s.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},d=mt(n,h);return q.jsxs("g",{children:[q.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),q.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),q.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),q.jsx("circle",{cx:d.x,cy:d.y,r:p0.COMPONENT_MARKER_RADIUS,fill:R2.COMPONENT_MARKER_FILL,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1})]},s.pcb_component_id)})})})},kko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>Pko(h)),A=t.filter(h=>y3e(h)),s=e.map(h=>y3e(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!sd(h=>h.is_showing_group_anchor_offsets)&&s.length===0)return null;const c=A.map(h=>{const d=h.pcb_panel_id,_=h.position_mode;if(!d||_!=="relative_to_panel_anchor")return null;const p=r.find(m=>m.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=s.length===0,g=c.filter(h=>l||s.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 q.jsx(E3e,{targets:u,transform:n,containerWidth:o,containerHeight:i})},Woe=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}},X7t=(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,A=e[o].y,s=e[i].x,a=e[i].y;A>t.y!=a>t.y&&t.x<(s-r)*(t.y-A)/(a-A||Number.EPSILON)+r&&(n=!n)}return n},Fko=(t,e,n)=>{const o=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const s=Z_({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),a=i.width||.5,c=Math.max(a*25,2)/n.a;s<c&&o.push(i);continue}if(i.pcb_drawing_type==="polygon"){const s=i.points.map(c=>({x:Bn.parse(c.x),y:Bn.parse(c.y)})),a=Woe(s);if(!a||e.x<a.center.x-a.width/2||e.x>a.center.x+a.width/2||e.y<a.center.y-a.height/2||e.y>a.center.y+a.height/2)continue;X7t(e,s)&&o.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const s=i.brep_shape.outer_ring.vertices.map(c=>({x:Bn.parse(c.x),y:Bn.parse(c.y)})),a=Woe(s);if(!a||e.x<a.center.x-a.width/2||e.x>a.center.x+a.width/2||e.y<a.center.y-a.height/2||e.y>a.center.y+a.height/2)continue;X7t(e,s)&&o.push(i);continue}if(!("x"in i&&"y"in i))continue;let r=0,A=0;if("w"in i&&"h"in i)r=i.w,A=i.h;else if("r"in i)r=i.r*2,A=i.r*2;else if("rX"in i&&"rY"in i)r=i.rX*2,A=i.rY*2;else continue;Math.abs(i.x-e.x)<r/2&&Math.abs(i.y-e.y)<A/2&&o.push(i)}return o},Lko=({elements:t,children:e,transform:n,primitives:o,onMouseHoverOverPrimitives:i})=>{const[r,A]=te.useState([]),[s,a]=te.useState({x:0,y:0}),[c,{width:l,height:g}]=MK(),u=te.useMemo(()=>{const d=[];for(const _ of r){if(_._element?.type==="pcb_via"||_._element?.type==="pcb_component"||_?.layer==="drill"||_?.is_hoverable===!1)continue;let p=null,m=0,C=0;if(_.pcb_drawing_type==="polygon"){const x=Woe(_.points);if(!x)continue;p=x.center,m=x.width,C=x.height}else if(_.pcb_drawing_type==="polygon_with_arcs"){const x=_.brep_shape.outer_ring.vertices.map(S=>({x:S.x,y:S.y})),B=Woe(x);if(!B)continue;p=B.center,m=B.width,C=B.height}else"x"in _&&"y"in _&&(p={x:_.x,y:_.y},m="w"in _?_.w:"r"in _?_.r*2:"rX"in _&&"rY"in _?_.rX*2:0,C="h"in _?_.h:"r"in _?_.r*2:"rX"in _&&"rY"in _?_.rY*2:0);if(!p)continue;const I=mt(n,p),f={w:m*n.a,h:C*n.a},y=d.filter(x=>I.x===x.screen_x&&I.y===x.screen_y&&f.w===x.screen_w&&f.h===x.screen_h).length;d.push({..._,x:p.x,y:p.y,w:m,h:C,screen_x:I.x,screen_y:I.y,screen_w:f.w,screen_h:f.h,same_space_index:y})}return d},[r,n]),h=(d,_,p,m)=>{a({x:d,y:_});const C=mt(Wy(p),{x:d,y:_}),I=Fko(m,C,p);xko(new Set(I.map(f=>f._pcb_drawing_object_id)),new Set(r.map(f=>f._pcb_drawing_object_id)))||(A(I),i(I))};return q.jsxs("div",{ref:c,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:d=>{if(n){const _=d.currentTarget.getBoundingClientRect(),p=d.clientX-_.left,m=d.clientY-_.top;h(p,m,n,o)}},onTouchStart:d=>{if(n){const _=d.touches[0],p=d.currentTarget.getBoundingClientRect(),m=_.clientX-p.left,C=_.clientY-p.top;h(m,C,n,o)}},children:[e,q.jsx(wko,{elements:t,mousePos:s,highlightedPrimitives:u}),n&&q.jsxs(q.Fragment,{children:[q.jsx(vko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g}),q.jsx(Nko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g}),q.jsx(Tko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g}),q.jsx(kko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g})]})]})},$7t=["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)"],Hko=({children:t,transform:e=vl(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:A}]=MK(),s=te.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=sd(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=s.current;if(!g||!r||!A)return;g.width=r,g.height=A;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,A),!a))return;const h=n.filter(x=>x.type==="pcb_group"),d=n.filter(x=>x.type==="pcb_component"),_=n.filter(x=>x.type==="source_group"),p=new Map(_.map(x=>[x.source_group_id,x])),m=h.filter(x=>{if(x.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!x.source_group_id)return!1;const B=p.get(x.source_group_id);return B?B.was_automatically_named!==!0:!1}),C=new Map;_.forEach(x=>{const B=x;if(B.parent_source_group_id){const S=C.get(B.parent_source_group_id)||[];S.push(x.source_group_id),C.set(B.parent_source_group_id,S)}});const I=x=>{const B=[],S=C.get(x)||[];for(const D of S)B.push(D),B.push(...I(D));return B},f=x=>{const B=_.find(S=>S.source_group_id===x);return B?.parent_source_group_id?1+f(B.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 B=x.positioned_relative_to_pcb_group_id??x.pcb_group_id;B&&y.add(B)}m.forEach((x,B)=>{let S=d.filter(Ue=>Ue.pcb_group_id===x.pcb_group_id);if(x.source_group_id){const Ue=I(x.source_group_id),Je=h.filter(He=>He.source_group_id&&Ue.includes(He.source_group_id));for(const He of Je){const Me=d.filter(ve=>ve.pcb_group_id===He.pcb_group_id);S=[...S,...Me]}}let D,w,F,R,H=!1;if(x.center&&x.width&&x.height){H=!0;const Ue=x.width/2,Je=x.height/2;D=x.center.x-Ue,F=x.center.x+Ue,w=x.center.y-Je,R=x.center.y+Je}else if(S.length===0||(D=1/0,w=1/0,F=-1/0,R=-1/0,S.forEach(Ue=>{if(Ue.center&&typeof Ue.width=="number"&&typeof Ue.height=="number"){const Je=Ue.center.x-Ue.width/2,He=Ue.center.x+Ue.width/2,Me=Ue.center.y+Ue.height/2,ve=Ue.center.y-Ue.height/2;D=Math.min(D,Je),F=Math.max(F,He),w=Math.min(w,ve),R=Math.max(R,Me)}}),D===1/0||F===-1/0))return;const G=x.source_group_id?f(x.source_group_id):0,K=x.source_group_id?I(x.source_group_id).length>0:!1;if(!H){const He=1+(K?.5:0);D-=He,F+=He,w-=He,R+=He}const J=mt(e,{x:D,y:R}),W=mt(e,{x:F,y:R}),j=mt(e,{x:D,y:w}),Ae=mt(e,{x:F,y:w}),re=$7t[B%$7t.length];u.strokeStyle=re,u.lineWidth=2;const Z=Math.max(4,Math.min(12,8*Math.abs(e.a))),oe=Math.max(2,Math.min(6,4*Math.abs(e.a))),ce=Z*(K?1.3:1),ge=oe;u.setLineDash([ce,ge]),u.beginPath(),u.moveTo(J.x,J.y),u.lineTo(W.x,W.y),u.lineTo(Ae.x,Ae.y),u.lineTo(j.x,j.y),u.closePath(),u.stroke();const xe=Math.max(8,Math.min(12,10*Math.abs(e.a))),we=G==0||G==1?0:G*.11,De=xe*(1-we),_e=4,Qe=x.name||`Group ${B+1}`;u.font=`${De}px sans-serif`,u.setLineDash([]);const Ye=u.measureText(Qe).width+_e*2,We=De+_e*2,ot=J.x-5,Ce=J.y-5,Ze=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(ot,Ce-We,Ye,We,Ze),u.fill(),u.fillStyle=re,u.textAlign="left",u.textBaseline="middle",u.fillText(Qe,ot+_e,Ce-We/2),l&&y.has(x.pcb_group_id)&&!!x.anchor_position&&x.anchor_position){const Ue=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},Je=mt(e,Ue);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const He=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Je.x-He,Je.y),u.lineTo(Je.x+He,Je.y),u.stroke(),u.beginPath(),u.moveTo(Je.x,Je.y-He),u.lineTo(Je.x,Je.y+He),u.stroke()}})},[n,e,r,A,a,c,l,o]),q.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,q.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Yl.pcbGroupOverlay,display:a?"block":"none"}})]})},Gko=({transform:t,soup:e,children:n})=>{const o=sd(s=>s.is_showing_rats_nest),{netMap:i,idToNetMap:r}=te.useMemo(()=>x7t(e||[]),[e]),A=te.useMemo(()=>{if(!e||!o)return[];const s=u=>{const h=nw(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},a=(u,h)=>{const d=i[h]||[];let _=null,p=1/0;return d.forEach(m=>{const C=s(m);if(C){const I=Math.sqrt((u.x-C.x)**2+(u.y-C.y)**2);I<p&&I>0&&(p=I,_=C)}}),_},c=nw(e).pcb_port.list(),l=nw(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let _=!1;for(const C of l)C.connected_source_port_ids.includes(u.source_port_id)&&C.connected_source_net_ids.length>0&&(_=!0);if(!d)return;const p={x:u.x,y:u.y},m=a(p,d);m&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:p,endPoint:m,isInNet:_})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=vl()),q.jsxs("div",{style:{position:"relative"},children:[n,q.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Yl.ratsNestOverlay},children:A.map(({key:s,startPoint:a,endPoint:c,isInNet:l})=>{const g=mt(t,a),u=mt(t,c);return q.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},s)})})]}))},Oko={version:"1.11.377"},IS=(t,e,n)=>{const o=sd(A=>A.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 A=s=>{const a=s.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],_=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||_)&&(!l||s.ctrlKey)&&(!g||s.shiftKey)&&(!u||s.altKey)&&(!h||s.metaKey)&&s.key.toLowerCase()===d.toLowerCase()&&(s.preventDefault(),r.current())};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t])},Kko=()=>{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},PK=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),o=te.useCallback(A=>{e.stopPropagation&&A.stopPropagation();const s=Date.now();s-n.current<300||(n.current=s,t?.(A))},[t,e.stopPropagation]),i=te.useCallback(A=>{A.preventDefault(),o(A)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},iw=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=PK(n);return q.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},Uko=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:gT(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},Yko=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=te.useRef(null),r=te.useRef(null),A=te.useRef(null),s=te.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);te.useEffect(()=>s,[s]);const a=te.useCallback(l=>{s(),A.current=l,e(l),n(null),r.current=window.requestAnimationFrame(()=>{n(l),r.current=null}),t(),i.current=window.setTimeout(()=>{A.current=null,e(null),n(null),i.current=null},o)},[s,o,t,n,e]),c=te.useCallback(l=>A.current===l,[]);return{handleErrorSelect:a,isSelectedError:c}},zko=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=PK(()=>o(e,t));return q.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?q.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):q.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},Vko=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:A})=>{const[s,a]=te.useState(null),[c,l]=te.useState(new Set),[g,u]=te.useState(new Set),[,h]=bRo(),{handleErrorSelect:d,isSelectedError:_}=Yko({onClose:i,setHoveredErrorId:r,setFocusedErrorId:A}),p=te.useMemo(()=>t?.filter(y=>y.type.includes("error"))??[],[t]),m=p.length,C=te.useMemo(()=>Uko(p),[p]),I=te.useCallback(y=>{l(x=>{const B=new Set(x);return B.has(y)?B.delete(y):B.add(y),B})},[]),f=te.useCallback(y=>{u(x=>{const B=new Set(x);return B.has(y)?B.delete(y):B.add(y),B})},[]);return q.jsxs("div",{style:{position:"relative"},children:[q.jsx(iw,{isSmallScreen:n,style:m>0?{color:"red"}:void 0,onClick:o,children:q.jsxs("div",{children:[m," errors"]})}),e&&m>0&&q.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:C.map(({errorType:y,errors:x},B)=>{const S=c.has(y);return q.jsxs("div",{style:{borderBottom:B<C.length-1?"1px solid #444":"none"},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:D=>{D.currentTarget.style.backgroundColor="#303030"},onMouseLeave:D=>{D.currentTarget.style.backgroundColor="#232323"},onTouchStart:D=>{D.stopPropagation(),D.currentTarget.style.backgroundColor="#303030"},onTouchEnd:D=>{D.stopPropagation(),D.preventDefault(),D.currentTarget.style.backgroundColor="#232323",I(y)},onClick:D=>{D.stopPropagation(),I(y)},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[q.jsx("div",{style:{color:"#888",fontSize:"16px",transform:S?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),q.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:y})]}),q.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:x.length})]}),!S&&x.map(({error:D,index:w,errorId:F})=>{const R=g.has(F),H=D.message??"No error message";return q.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:G=>{G.currentTarget.style.backgroundColor="#333",r(F)},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="#2a2a2a",_(F)||r(null)},onTouchStart:G=>{G.stopPropagation(),G.currentTarget.style.backgroundColor="#333",r(F)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),G.currentTarget.style.backgroundColor="#2a2a2a",d(F)},onClick:G=>{G.stopPropagation(),d(F)},children:[q.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:H}),q.jsx("button",{type:"button","aria-label":R?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:R?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:G=>G.stopPropagation(),onClick:G=>{G.stopPropagation(),f(F)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),f(F)},children:"›"})]}),R&&q.jsxs("div",{"data-error-id":w,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[q.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:G=>G.stopPropagation(),onClick:G=>G.stopPropagation(),children:H}),q.jsx(zko,{errorId:F,errorMessage:H,copiedErrorId:s,onCopy:(G,K)=>{h(G),a(K),setTimeout(()=>a(null),2e3)}})]})]},F)})]},y)})})]})},Jko=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=PK(n);return q.jsxs("div",{className:lT`
5684
+ `,Eko=({children:t,transform:e=vl(),elements:n})=>{const o=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:A}=sd(_=>({isShowingDRCErrors:_.is_showing_drc_errors,hoveredErrorId:_.hovered_error_id,focusedErrorId:_.focused_error_id})),s=A??r;if(!n)return q.jsx("div",{style:{position:"relative"},ref:o,children:t});const a=n.filter(_=>_.type==="pcb_trace_error"&&!_.message?.includes("Multiple components found with name")),c=n.filter(_=>_.type==="pcb_via_clearance_error"),l=n.filter(_=>_.type==="pcb_trace_error"&&_.message?.includes("Multiple components found with name")),g=Q7t(n),u=B7t(n,s),h=_=>{const p=GRo({error:_,indexes:g});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const m=mt(e,p);return Number.isNaN(m.x)||Number.isNaN(m.y)?null:m};let d=null;return u&&(d=h(u)),q.jsxs("div",{style:{position:"relative"},ref:o,children:[t,a.map((_,p)=>{const m=gT(_,p),C=s===m;if(!C&&!i)return null;const I=h(_);if(!I)return null;const f=C3e(I,o);return q.jsxs(te.Fragment,{children:[q.jsx(W7t,{errorCenter:I,isHighlighted:C}),q.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Yl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!C){const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),q.jsx("div",{style:{position:"absolute",zIndex:C?200:100,left:f.left,top:f.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:f.transform},children:q.jsx("div",{className:`error-message ${f3e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},m)}),c.map((_,p)=>{const m=gT(_,p),C=s===m;if(!C&&!i)return null;const I=h(_);if(!I)return null;const f=C3e({x:I.x,y:I.y},o);return q.jsxs(te.Fragment,{children:[q.jsx(W7t,{errorCenter:I,isHighlighted:C}),q.jsx("div",{style:{position:"absolute",left:I.x-15,top:I.y-15,width:30,height:30,zIndex:Yl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:y=>{const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="1")}},onMouseLeave:y=>{if(!C){const x=y.currentTarget.nextElementSibling;if(x){const B=x.querySelector(".error-message");B&&(B.style.opacity="0")}}}}),q.jsx("div",{style:{position:"absolute",zIndex:C?Yl.errorOverlay+10:Yl.errorOverlay+1,left:f.left,top:f.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:f.transform},children:q.jsx("div",{className:`error-message ${f3e}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:_.message})})]},m)}),l.map((_,p)=>{const m=_.component_name||_.message?.match(/name "([^"]+)"/)?.[1];if(!m)return null;const C=n?.filter(y=>y.type==="source_component"&&y.name===m||y.type==="pcb_component"&&n?.find(x=>x.type==="source_component"&&x.source_component_id===y.source_component_id&&x.name===m))||[],I=gT(_,p),f=s===I;return!f&&!i?null:C.map((y,x)=>{let B={x:0,y:0};if(y.type==="pcb_component")B=y.center||{x:0,y:0};else if(y.type==="source_component"){const K=n?.find(J=>J.type==="pcb_component"&&J.source_component_id===y.source_component_id);K&&K.type==="pcb_component"&&(B=K.center||{x:0,y:0})}const S=mt(e,B);if(Number.isNaN(S.x)||Number.isNaN(S.y))return null;const D=Math.abs(e.a),H=Math.max(8,Math.min(30,.5*D)),G=C3e(S,o);return q.jsxs(te.Fragment,{children:[q.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Yl.errorOverlay},width:"100%",height:"100%",children:f?q.jsx("polygon",{points:`${S.x},${S.y-H*1.25} ${S.x+H},${S.y} ${S.x},${S.y+H*1.25} ${S.x-H},${S.y}`,fill:"#ff4444"}):q.jsx("circle",{cx:S.x,cy:S.y,r:H,fill:"none",stroke:f?"#ff4444":"red",strokeWidth:f?Math.max(2,H*.15):Math.max(1,H*.1),opacity:1})}),q.jsx("div",{style:{position:"absolute",left:S.x-(H+10),top:S.y-(H+10),width:(H+10)*2,height:(H+10)*2,zIndex:Yl.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:K=>{const J=K.currentTarget.nextElementSibling;if(J){const W=J.querySelector(".error-message");W&&(W.style.opacity="1")}},onMouseLeave:K=>{if(!f){const J=K.currentTarget.nextElementSibling;if(J){const W=J.querySelector(".error-message");W&&(W.style.opacity="0")}}}}),q.jsx("div",{style:{position:"absolute",zIndex:f?Yl.errorOverlay+20:Yl.errorOverlay+10,left:G.left,top:G.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||f?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:G.transform},children:q.jsx("div",{className:`error-message ${f3e}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:_.message})})]},`${I}_${x}`)})}),d&&q.jsx(yko,{center:d})]})};function xko(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function Bko({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const o=nw(e).source_trace.get(t?.source_trace_id);if(o?.display_name&&(o?.max_length?n+=` / ${o.max_length}mm `:n+=" mm ",n+=`(${o.display_name})`),!n)return null;const i=t.trace_length&&o?.max_length&&t.trace_length>o.max_length;return{text:n,isOverLength:i}}function Qko(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"),A=e.filter(a=>a._element.type!=="pcb_trace"),s=i.filter(a=>r.some(c=>a._element.type==="pcb_trace"&&a._element.source_trace_id===c.source_trace_id&&c.max_length!==void 0));if(!n)return[...A,...s];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[...A,a]}return e}var Sko={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},bko=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=[],A=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)),s=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return A.length>0?s?r.push(...A.map(a=>`${s}.${a}`)):r.push(...A):s&&r.push(s),r.join(", ")}default:return""}},Dko={top:"red",bottom:"aqua"},Mko=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=te.useState(!1),r=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[A,s,a,c]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],l=t.same_space_index??0,g=26,u=Dko[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=Bko({primitiveElement:r,elements:n});if(!p)return null;const m=e.y-35;return q.jsx("div",{style:{zIndex:Yl.elementOverlay,position:"absolute",left:e.x,top:m,color:u,pointerEvents:"none",transform:"translateX(-50%)"},children:q.jsx("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:p.text})})}const d=bko(t);return d.trim().length===0?null:q.jsx("div",{style:{zIndex:Yl.elementOverlay,position:"absolute",left:A-a/2-8,top:s-c/2-8,width:a+16,height:c+16,color:u,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:q.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:q.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})})})},wko=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=sd(s=>[s.is_moving_component,s.is_showing_multiple_traces_length]),r=t.some(s=>s._element.type==="pcb_smtpad")&&t.some(s=>s._element.type==="pcb_trace");let A=t;return r&&(A=A.filter(s=>s._element.type==="pcb_smtpad")),A=Qko({primitives:A,is_showing_multiple_traces_length:i,elements:n}),q.jsx("div",{style:Sko,children:!o&&A.map((s,a)=>q.jsx(Mko,{primitive:s,mousePos:e,elements:n},a))})},ow=t=>t?.type==="pcb_component",j7t=t=>t?.type==="pcb_group",Pko=t=>t?.type==="pcb_panel",y3e=t=>t?.type==="pcb_board",p0={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},R2={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},E3e=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:R2.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:p0.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(A=>{if(!r.has(A.anchor_id)){const s=mt(e,A.anchor);r.set(A.anchor_id,s)}}),q.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:Yl.dimensionOverlay},children:q.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(A=>{const s=A.anchor,a=A.anchor_id,c=A.target,l=r.get(a),g=mt(e,c),u=c.x-s.x,h=c.y-s.y,d=Math.abs(g.x-l.x),_=Math.abs(g.y-l.y),p=g.y<l.y,m=g.x>l.x,C=p?p0.LABEL_OFFSET_ABOVE:p0.LABEL_OFFSET_BELOW,I=m?p0.LABEL_OFFSET_RIGHT:p0.LABEL_OFFSET_LEFT,f=d>p0.MIN_LINE_LENGTH_FOR_LABEL,y=_>p0.MIN_LINE_LENGTH_FOR_LABEL,x=`${A.display_offset_x??u.toFixed(2)}mm`,B=`${A.display_offset_y??h.toFixed(2)}mm`;return q.jsxs("g",{children:[q.jsx("line",{x1:l.x,y1:l.y,x2:g.x,y2:l.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.LINE_STROKE_WIDTH,strokeDasharray:p0.LINE_DASH_PATTERN}),q.jsx("line",{x1:g.x,y1:l.y,x2:g.x,y2:g.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.LINE_STROKE_WIDTH,strokeDasharray:p0.LINE_DASH_PATTERN}),A.type==="component"||A.type==="board"?q.jsx("circle",{cx:g.x,cy:g.y,r:p0.COMPONENT_MARKER_RADIUS,fill:R2.COMPONENT_MARKER_FILL,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1}):q.jsxs(q.Fragment,{children:[q.jsx("line",{x1:g.x-p0.ANCHOR_MARKER_SIZE,y1:g.y,x2:g.x+p0.ANCHOR_MARKER_SIZE,y2:g.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH}),q.jsx("line",{x1:g.x,y1:g.y-p0.ANCHOR_MARKER_SIZE,x2:g.x,y2:g.y+p0.ANCHOR_MARKER_SIZE,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&q.jsx("foreignObject",{x:Math.min(l.x,g.x),y:l.y+C,width:Math.abs(g.x-l.x),height:20,style:{overflow:"visible"},children:q.jsx("div",{style:{...i,textAlign:"center"},children:x})}),y&&q.jsx("foreignObject",{x:g.x+I,y:Math.min(l.y,g.y),width:p0.Y_LABEL_MIN_WIDTH,height:Math.abs(g.y-l.y),style:{overflow:"visible"},children:q.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:m?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:B})})]},A.id)}),Array.from(r.entries()).map(([A,s])=>q.jsxs("g",{children:[q.jsx("line",{x1:s.x-p0.ANCHOR_MARKER_SIZE,y1:s.y,x2:s.x+p0.ANCHOR_MARKER_SIZE,y2:s.y,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH}),q.jsx("line",{x1:s.x,y1:s.y-p0.ANCHOR_MARKER_SIZE,x2:s.x,y2:s.y+p0.ANCHOR_MARKER_SIZE,stroke:R2.OFFSET_LINE,strokeWidth:p0.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${A}`))]})})},vko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(m=>y3e(m)),A=t.filter(m=>ow(m)),s=t.filter(m=>j7t(m)),a=e.map(m=>ow(m._parent_pcb_component)?m._parent_pcb_component.pcb_component_id:ow(m._element)?m._element.pcb_component_id:null).filter(m=>!!m),c=new Set;if(a.forEach(m=>{const C=A.find(I=>I.pcb_component_id===m);C?.pcb_group_id&&c.add(C.pcb_group_id)}),!sd(m=>m.is_showing_group_anchor_offsets)&&a.length===0)return null;const g=A.map(m=>{const C=m.positioned_relative_to_pcb_board_id;if(!C)return null;const I=r.find(f=>f.pcb_board_id===C);return I?{component:m,board:I,type:"component"}:null}).filter(m=>!!m),u=s.map(m=>{const C=m.positioned_relative_to_pcb_board_id;if(!C||!m.center)return null;const I=r.find(f=>f.pcb_board_id===C);return I?{group:m,board:I,type:"group"}:null}).filter(m=>!!m),h=[...g,...u];if(h.length===0)return null;const d=a.length===0,_=h.filter(m=>m.type==="component"?d||a.includes(m.component.pcb_component_id):d||c.has(m.group.pcb_group_id));if(_.length===0)return null;const p=_.map(m=>m.type==="component"?{id:`${m.board.pcb_board_id}-${m.component.pcb_component_id}-${m.type}`,anchor:m.board.center,anchor_id:m.board.pcb_board_id,target:m.component.center,type:"component",display_offset_x:m.component.display_offset_x,display_offset_y:m.component.display_offset_y}:{id:`${m.board.pcb_board_id}-${m.group.pcb_group_id}-${m.type}`,anchor:m.board.center,anchor_id:m.board.pcb_board_id,target:{x:m.group.anchor_position?.x??m.group.center.x,y:m.group.anchor_position?.y??m.group.center.y},type:"group",display_offset_x:m.group.display_offset_x,display_offset_y:m.group.display_offset_y}).filter(m=>!!m);return q.jsx(E3e,{targets:p,transform:n,containerWidth:o,containerHeight:i})},Nko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(m=>j7t(m)),A=t.filter(m=>ow(m)),s=e.map(m=>ow(m._parent_pcb_component)?m._parent_pcb_component.pcb_component_id:ow(m._element)?m._element.pcb_component_id:null).filter(m=>!!m),a=(m,C)=>{if(C.has(m))return;C.add(m);const I=r.find(f=>f.pcb_group_id===m);I?.position_mode==="relative_to_group_anchor"&&I.positioned_relative_to_pcb_group_id&&a(I.positioned_relative_to_pcb_group_id,C)},c=new Set;if(s.forEach(m=>{const C=A.find(I=>I.pcb_component_id===m);C&&(C.position_mode==="relative_to_group_anchor"&&C.positioned_relative_to_pcb_group_id&&a(C.positioned_relative_to_pcb_group_id,c),C.pcb_group_id&&a(C.pcb_group_id,c))}),!sd(m=>m.is_showing_group_anchor_offsets)&&s.length===0)return null;const g=A.map(m=>{if(m.position_mode==="relative_to_group_anchor"&&m.positioned_relative_to_pcb_group_id){const C=r.find(I=>I.pcb_group_id===m.positioned_relative_to_pcb_group_id);return C&&C.anchor_position?{component:m,parentGroup:C,type:"component"}:null}if(m.pcb_group_id){const C=r.find(I=>I.pcb_group_id===m.pcb_group_id);return C&&C.anchor_position?{component:m,parentGroup:C,type:"component"}:null}return null}).filter(m=>!!m),u=r.map(m=>{if(m.position_mode==="relative_to_group_anchor"&&m.positioned_relative_to_pcb_group_id){const C=r.find(I=>I.pcb_group_id===m.positioned_relative_to_pcb_group_id);if(C&&C.anchor_position&&m.anchor_position)return{group:m,parentGroup:C,type:"group"}}return null}).filter(m=>!!m),h=[...g,...u];if(h.length===0)return null;const d=s.length===0,_=h.filter(m=>m.type==="component"?d||s.includes(m.component.pcb_component_id):d||c.has(m.group.pcb_group_id)||c.has(m.parentGroup.pcb_group_id));if(_.length===0)return null;const p=_.map(m=>{const C=m.parentGroup.anchor_position;return C?m.type==="component"?m.component.center?{id:`${m.parentGroup.pcb_group_id}-${m.component.pcb_component_id}-${m.type}`,anchor:C,anchor_id:m.parentGroup.pcb_group_id,target:m.component.center,type:"component",display_offset_x:m.component.display_offset_x,display_offset_y:m.component.display_offset_y}:null:m.group.anchor_position?{id:`${m.parentGroup.pcb_group_id}-${m.group.pcb_group_id}-${m.type}`,anchor:C,anchor_id:m.parentGroup.pcb_group_id,target:m.group.anchor_position,type:"group",display_offset_x:m.group.display_offset_x,display_offset_y:m.group.display_offset_y}:null:null}).filter(m=>!!m);return q.jsx(E3e,{targets:p,transform:n,containerWidth:o,containerHeight:i})},Rko=(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?m3e([t]):m3e(o)},Tko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const s of e)ow(s._parent_pcb_component)&&r.set(s._parent_pcb_component.pcb_component_id,s._parent_pcb_component),ow(s._element)&&r.set(s._element.pcb_component_id,s._element);if(r.size===0)return null;const A=[];for(const s of r.values()){const a=Rko(s,t);if(!a)continue;const c=s.positioned_relative_to_pcb_group_id??s.pcb_group_id,l=c?nw(t).pcb_group.get(c):null;A.push({component:s,bbox:a,group:l})}return A.length===0?null:q.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Yl.dimensionOverlay},children:q.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:A.map(({component:s,bbox:a,group:c})=>{const l=mt(n,{x:a.minX,y:a.maxY}),g=mt(n,{x:a.maxX,y:a.minY}),u={x:Math.min(l.x,g.x),y:Math.min(l.y,g.y),width:Math.abs(g.x-l.x),height:Math.abs(g.y-l.y)},h=s.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},d=mt(n,h);return q.jsxs("g",{children:[q.jsx("rect",{x:u.x,y:u.y,width:u.width,height:u.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),q.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),q.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),q.jsx("circle",{cx:d.x,cy:d.y,r:p0.COMPONENT_MARKER_RADIUS,fill:R2.COMPONENT_MARKER_FILL,stroke:R2.COMPONENT_MARKER_STROKE,strokeWidth:1})]},s.pcb_component_id)})})})},kko=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>Pko(h)),A=t.filter(h=>y3e(h)),s=e.map(h=>y3e(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!sd(h=>h.is_showing_group_anchor_offsets)&&s.length===0)return null;const c=A.map(h=>{const d=h.pcb_panel_id,_=h.position_mode;if(!d||_!=="relative_to_panel_anchor")return null;const p=r.find(m=>m.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(c.length===0)return null;const l=s.length===0,g=c.filter(h=>l||s.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 q.jsx(E3e,{targets:u,transform:n,containerWidth:o,containerHeight:i})},Woe=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}},X7t=(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,A=e[o].y,s=e[i].x,a=e[i].y;A>t.y!=a>t.y&&t.x<(s-r)*(t.y-A)/(a-A||Number.EPSILON)+r&&(n=!n)}return n},Fko=(t,e,n)=>{const o=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const s=Z_({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),a=i.width||.5,c=Math.max(a*25,2)/n.a;s<c&&o.push(i);continue}if(i.pcb_drawing_type==="polygon"){const s=i.points.map(c=>({x:Bn.parse(c.x),y:Bn.parse(c.y)})),a=Woe(s);if(!a||e.x<a.center.x-a.width/2||e.x>a.center.x+a.width/2||e.y<a.center.y-a.height/2||e.y>a.center.y+a.height/2)continue;X7t(e,s)&&o.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const s=i.brep_shape.outer_ring.vertices.map(c=>({x:Bn.parse(c.x),y:Bn.parse(c.y)})),a=Woe(s);if(!a||e.x<a.center.x-a.width/2||e.x>a.center.x+a.width/2||e.y<a.center.y-a.height/2||e.y>a.center.y+a.height/2)continue;X7t(e,s)&&o.push(i);continue}if(!("x"in i&&"y"in i))continue;let r=0,A=0;if("w"in i&&"h"in i)r=i.w,A=i.h;else if("r"in i)r=i.r*2,A=i.r*2;else if("rX"in i&&"rY"in i)r=i.rX*2,A=i.rY*2;else continue;Math.abs(i.x-e.x)<r/2&&Math.abs(i.y-e.y)<A/2&&o.push(i)}return o},Lko=({elements:t,children:e,transform:n,primitives:o,onMouseHoverOverPrimitives:i})=>{const[r,A]=te.useState([]),[s,a]=te.useState({x:0,y:0}),[c,{width:l,height:g}]=MK(),u=te.useMemo(()=>{const d=[];for(const _ of r){if(_._element?.type==="pcb_via"||_._element?.type==="pcb_component"||_?.layer==="drill"||_?.is_hoverable===!1)continue;let p=null,m=0,C=0;if(_.pcb_drawing_type==="polygon"){const x=Woe(_.points);if(!x)continue;p=x.center,m=x.width,C=x.height}else if(_.pcb_drawing_type==="polygon_with_arcs"){const x=_.brep_shape.outer_ring.vertices.map(S=>({x:S.x,y:S.y})),B=Woe(x);if(!B)continue;p=B.center,m=B.width,C=B.height}else"x"in _&&"y"in _&&(p={x:_.x,y:_.y},m="w"in _?_.w:"r"in _?_.r*2:"rX"in _&&"rY"in _?_.rX*2:0,C="h"in _?_.h:"r"in _?_.r*2:"rX"in _&&"rY"in _?_.rY*2:0);if(!p)continue;const I=mt(n,p),f={w:m*n.a,h:C*n.a},y=d.filter(x=>I.x===x.screen_x&&I.y===x.screen_y&&f.w===x.screen_w&&f.h===x.screen_h).length;d.push({..._,x:p.x,y:p.y,w:m,h:C,screen_x:I.x,screen_y:I.y,screen_w:f.w,screen_h:f.h,same_space_index:y})}return d},[r,n]),h=(d,_,p,m)=>{a({x:d,y:_});const C=mt(Wy(p),{x:d,y:_}),I=Fko(m,C,p);xko(new Set(I.map(f=>f._pcb_drawing_object_id)),new Set(r.map(f=>f._pcb_drawing_object_id)))||(A(I),i(I))};return q.jsxs("div",{ref:c,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:d=>{if(n){const _=d.currentTarget.getBoundingClientRect(),p=d.clientX-_.left,m=d.clientY-_.top;h(p,m,n,o)}},onTouchStart:d=>{if(n){const _=d.touches[0],p=d.currentTarget.getBoundingClientRect(),m=_.clientX-p.left,C=_.clientY-p.top;h(m,C,n,o)}},children:[e,q.jsx(wko,{elements:t,mousePos:s,highlightedPrimitives:u}),n&&q.jsxs(q.Fragment,{children:[q.jsx(vko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g}),q.jsx(Nko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g}),q.jsx(Tko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g}),q.jsx(kko,{elements:t,highlightedPrimitives:u,transform:n,containerWidth:l,containerHeight:g})]})]})},$7t=["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)"],Hko=({children:t,transform:e=vl(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:A}]=MK(),s=te.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:c,is_showing_group_anchor_offsets:l}=sd(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=s.current;if(!g||!r||!A)return;g.width=r,g.height=A;const u=g.getContext("2d");if(!u||(u.clearRect(0,0,r,A),!a))return;const h=n.filter(x=>x.type==="pcb_group"),d=n.filter(x=>x.type==="pcb_component"),_=n.filter(x=>x.type==="source_group"),p=new Map(_.map(x=>[x.source_group_id,x])),m=h.filter(x=>{if(x.name?.toLowerCase().includes("subpanel"))return!1;if(c==="all")return!0;if(!x.source_group_id)return!1;const B=p.get(x.source_group_id);return B?B.was_automatically_named!==!0:!1}),C=new Map;_.forEach(x=>{const B=x;if(B.parent_source_group_id){const S=C.get(B.parent_source_group_id)||[];S.push(x.source_group_id),C.set(B.parent_source_group_id,S)}});const I=x=>{const B=[],S=C.get(x)||[];for(const D of S)B.push(D),B.push(...I(D));return B},f=x=>{const B=_.find(S=>S.source_group_id===x);return B?.parent_source_group_id?1+f(B.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 B=x.positioned_relative_to_pcb_group_id??x.pcb_group_id;B&&y.add(B)}m.forEach((x,B)=>{let S=d.filter(Ue=>Ue.pcb_group_id===x.pcb_group_id);if(x.source_group_id){const Ue=I(x.source_group_id),Je=h.filter(He=>He.source_group_id&&Ue.includes(He.source_group_id));for(const He of Je){const Me=d.filter(ve=>ve.pcb_group_id===He.pcb_group_id);S=[...S,...Me]}}let D,w,F,R,H=!1;if(x.center&&x.width&&x.height){H=!0;const Ue=x.width/2,Je=x.height/2;D=x.center.x-Ue,F=x.center.x+Ue,w=x.center.y-Je,R=x.center.y+Je}else if(S.length===0||(D=1/0,w=1/0,F=-1/0,R=-1/0,S.forEach(Ue=>{if(Ue.center&&typeof Ue.width=="number"&&typeof Ue.height=="number"){const Je=Ue.center.x-Ue.width/2,He=Ue.center.x+Ue.width/2,Me=Ue.center.y+Ue.height/2,ve=Ue.center.y-Ue.height/2;D=Math.min(D,Je),F=Math.max(F,He),w=Math.min(w,ve),R=Math.max(R,Me)}}),D===1/0||F===-1/0))return;const G=x.source_group_id?f(x.source_group_id):0,K=x.source_group_id?I(x.source_group_id).length>0:!1;if(!H){const He=1+(K?.5:0);D-=He,F+=He,w-=He,R+=He}const J=mt(e,{x:D,y:R}),W=mt(e,{x:F,y:R}),j=mt(e,{x:D,y:w}),Ae=mt(e,{x:F,y:w}),re=$7t[B%$7t.length];u.strokeStyle=re,u.lineWidth=2;const Z=Math.max(4,Math.min(12,8*Math.abs(e.a))),oe=Math.max(2,Math.min(6,4*Math.abs(e.a))),ce=Z*(K?1.3:1),ge=oe;u.setLineDash([ce,ge]),u.beginPath(),u.moveTo(J.x,J.y),u.lineTo(W.x,W.y),u.lineTo(Ae.x,Ae.y),u.lineTo(j.x,j.y),u.closePath(),u.stroke();const xe=Math.max(8,Math.min(12,10*Math.abs(e.a))),we=G==0||G==1?0:G*.11,De=xe*(1-we),_e=4,Qe=x.name||`Group ${B+1}`;u.font=`${De}px sans-serif`,u.setLineDash([]);const Ye=u.measureText(Qe).width+_e*2,We=De+_e*2,ot=J.x-5,Ce=J.y-5,Ze=3;if(u.fillStyle="rgba(0, 0, 0, 0.8)",u.beginPath(),u.roundRect(ot,Ce-We,Ye,We,Ze),u.fill(),u.fillStyle=re,u.textAlign="left",u.textBaseline="middle",u.fillText(Qe,ot+_e,Ce-We/2),l&&y.has(x.pcb_group_id)&&!!x.anchor_position&&x.anchor_position){const Ue=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},Je=mt(e,Ue);u.strokeStyle="white",u.lineWidth=1.5,u.setLineDash([]);const He=Math.max(4,Math.min(8,6*Math.abs(e.a)));u.beginPath(),u.moveTo(Je.x-He,Je.y),u.lineTo(Je.x+He,Je.y),u.stroke(),u.beginPath(),u.moveTo(Je.x,Je.y-He),u.lineTo(Je.x,Je.y+He),u.stroke()}})},[n,e,r,A,a,c,l,o]),q.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,q.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Yl.pcbGroupOverlay,display:a?"block":"none"}})]})},Gko=({transform:t,soup:e,children:n})=>{const o=sd(s=>s.is_showing_rats_nest),{netMap:i,idToNetMap:r}=te.useMemo(()=>x7t(e||[]),[e]),A=te.useMemo(()=>{if(!e||!o)return[];const s=u=>{const h=nw(e)[u.replace(/_\d+$/,"")].get(u);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},a=(u,h)=>{const d=i[h]||[];let _=null,p=1/0;return d.forEach(m=>{const C=s(m);if(C){const I=Math.sqrt((u.x-C.x)**2+(u.y-C.y)**2);I<p&&I>0&&(p=I,_=C)}}),_},c=nw(e).pcb_port.list(),l=nw(e).source_trace.list(),g=[];return c.forEach((u,h)=>{const d=r[u.pcb_port_id];let _=!1;for(const C of l)C.connected_source_port_ids.includes(u.source_port_id)&&C.connected_source_net_ids.length>0&&(_=!0);if(!d)return;const p={x:u.x,y:u.y},m=a(p,d);m&&g.push({key:`${u.pcb_port_id}-${h}`,startPoint:p,endPoint:m,isInNet:_})}),g},[e,i,r,o]);return!e||!o?n:(t||(t=vl()),q.jsxs("div",{style:{position:"relative"},children:[n,q.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Yl.ratsNestOverlay},children:A.map(({key:s,startPoint:a,endPoint:c,isInNet:l})=>{const g=mt(t,a),u=mt(t,c);return q.jsx("line",{x1:g.x,y1:g.y,x2:u.x,y2:u.y,stroke:"white",strokeWidth:"1",strokeDasharray:l?"6,6":void 0},s)})})]}))},Oko={version:"1.11.378"},IS=(t,e,n)=>{const o=sd(A=>A.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 A=s=>{const a=s.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const c=t.split("+"),l=c.includes("ctrl"),g=c.includes("shift"),u=c.includes("alt"),h=c.includes("meta"),d=c[c.length-1],_=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||_)&&(!l||s.ctrlKey)&&(!g||s.shiftKey)&&(!u||s.altKey)&&(!h||s.metaKey)&&s.key.toLowerCase()===d.toLowerCase()&&(s.preventDefault(),r.current())};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t])},Kko=()=>{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},PK=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),o=te.useCallback(A=>{e.stopPropagation&&A.stopPropagation();const s=Date.now();s-n.current<300||(n.current=s,t?.(A))},[t,e.stopPropagation]),i=te.useCallback(A=>{A.preventDefault(),o(A)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},iw=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=PK(n);return q.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},Uko=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:gT(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},Yko=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=te.useRef(null),r=te.useRef(null),A=te.useRef(null),s=te.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);te.useEffect(()=>s,[s]);const a=te.useCallback(l=>{s(),A.current=l,e(l),n(null),r.current=window.requestAnimationFrame(()=>{n(l),r.current=null}),t(),i.current=window.setTimeout(()=>{A.current=null,e(null),n(null),i.current=null},o)},[s,o,t,n,e]),c=te.useCallback(l=>A.current===l,[]);return{handleErrorSelect:a,isSelectedError:c}},zko=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=PK(()=>o(e,t));return q.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?q.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):q.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:q.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},Vko=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:A})=>{const[s,a]=te.useState(null),[c,l]=te.useState(new Set),[g,u]=te.useState(new Set),[,h]=bRo(),{handleErrorSelect:d,isSelectedError:_}=Yko({onClose:i,setHoveredErrorId:r,setFocusedErrorId:A}),p=te.useMemo(()=>t?.filter(y=>y.type.includes("error"))??[],[t]),m=p.length,C=te.useMemo(()=>Uko(p),[p]),I=te.useCallback(y=>{l(x=>{const B=new Set(x);return B.has(y)?B.delete(y):B.add(y),B})},[]),f=te.useCallback(y=>{u(x=>{const B=new Set(x);return B.has(y)?B.delete(y):B.add(y),B})},[]);return q.jsxs("div",{style:{position:"relative"},children:[q.jsx(iw,{isSmallScreen:n,style:m>0?{color:"red"}:void 0,onClick:o,children:q.jsxs("div",{children:[m," errors"]})}),e&&m>0&&q.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:C.map(({errorType:y,errors:x},B)=>{const S=c.has(y);return q.jsxs("div",{style:{borderBottom:B<C.length-1?"1px solid #444":"none"},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:D=>{D.currentTarget.style.backgroundColor="#303030"},onMouseLeave:D=>{D.currentTarget.style.backgroundColor="#232323"},onTouchStart:D=>{D.stopPropagation(),D.currentTarget.style.backgroundColor="#303030"},onTouchEnd:D=>{D.stopPropagation(),D.preventDefault(),D.currentTarget.style.backgroundColor="#232323",I(y)},onClick:D=>{D.stopPropagation(),I(y)},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[q.jsx("div",{style:{color:"#888",fontSize:"16px",transform:S?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),q.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:y})]}),q.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:x.length})]}),!S&&x.map(({error:D,index:w,errorId:F})=>{const R=g.has(F),H=D.message??"No error message";return q.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[q.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:G=>{G.currentTarget.style.backgroundColor="#333",r(F)},onMouseLeave:G=>{G.currentTarget.style.backgroundColor="#2a2a2a",_(F)||r(null)},onTouchStart:G=>{G.stopPropagation(),G.currentTarget.style.backgroundColor="#333",r(F)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),G.currentTarget.style.backgroundColor="#2a2a2a",d(F)},onClick:G=>{G.stopPropagation(),d(F)},children:[q.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:H}),q.jsx("button",{type:"button","aria-label":R?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:R?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:G=>G.stopPropagation(),onClick:G=>{G.stopPropagation(),f(F)},onTouchEnd:G=>{G.stopPropagation(),G.preventDefault(),f(F)},children:"›"})]}),R&&q.jsxs("div",{"data-error-id":w,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[q.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:G=>G.stopPropagation(),onClick:G=>G.stopPropagation(),children:H}),q.jsx(zko,{errorId:F,errorMessage:H,copiedErrorId:s,onCopy:(G,K)=>{h(G),a(K),setTimeout(()=>a(null),2e3)}})]})]},F)})]},y)})})]})},Jko=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=PK(n);return q.jsxs("div",{className:lT`
5685
5685
  margin-top: 2px;
5686
5686
  padding: 4px;
5687
5687
  padding-left: 8px;
@@ -5752,7 +5752,7 @@ test("${c} should solve problem correctly", () => {
5752
5752
  // Add more specific assertions based on expected output
5753
5753
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5754
5754
  })
5755
- `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}o(!1)};return q.jsxs("div",{className:`relative ${e}`,ref:i,children:[q.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&q.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:[q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:A,children:"Download page.tsx"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download test.ts"})]})]})},rNt=t=>t.activeSubSolver?[t,...rNt(t.activeSubSolver)]:[t],KFo=({solver:t})=>{const e=rNt(t);return q.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>q.jsxs("div",{className:"flex items-center",children:[o>0&&q.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),q.jsx(OFo,{solver:n})]},n.constructor.name))})},UFo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,A]=te.useReducer(_=>!_,!1),s=te.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(s.current&&(clearInterval(s.current),s.current=void 0),A()):(A(),s.current=setInterval(()=>{if(t.solved||t.failed){s.current&&(clearInterval(s.current),s.current=void 0),A(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const p=_.getCurrentPhase();for(;_.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const p=Number(_);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{s.current&&clearInterval(s.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&r&&(s.current&&(clearInterval(s.current),s.current=void 0),A())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return q.jsxs("div",{className:"space-y-2 p-2 border-b",children:[q.jsx("div",{className:"flex items-center",children:q.jsx(KFo,{solver:t})}),q.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[q.jsx("button",{onClick:a,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),q.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),q.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),q.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&q.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),q.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",q.jsx("span",{className:"font-medium",children:d})]}),t.solved&&q.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&q.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&q.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},YFo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},zFo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=YFo(t,e),r=t[o],A=t.firstIterationOfPhase?.[o]??null,s=t.iterations;let a=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&A!==null?a=h-A:A!==null&&(a=s-A)}else i==="In Progress"&&A!==null&&(a=s-A);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:A,iterations:a,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},VFo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return q.jsx("span",{className:`font-medium ${e[t]}`,children:t})},JFo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:q.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),q.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},qFo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),WFo=({stats:t})=>{if(!t||Object.keys(t).length===0)return q.jsx("span",{children:"-"});const e=Object.entries(t),n=qFo(t);return q.jsxs("details",{className:"cursor-pointer",children:[q.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),q.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>q.jsxs("div",{children:[o,": ",String(i)]},o))})]})},B3e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(B3e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=B3e(o));return e},jFo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=B3e(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)}`)}},XFo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((s,a)=>zFo(t,a)),i=s=>{e?.(s)},r=s=>{s.solverInstance&&(n?n(s.solverInstance,s.name):jFo(s.solverInstance,s.name))},A=s=>`${(s/1e3).toFixed(2)}s`;return q.jsxs("div",{className:"border-t border-gray-200",children:[q.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:q.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),q.jsx("div",{className:"overflow-x-auto",children:q.jsxs("table",{className:"w-full text-sm",children:[q.jsx("thead",{children:q.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),q.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",q.jsx("sub",{children:"0"})]}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),q.jsx("tbody",{children:o.map(s=>q.jsxs("tr",{className:`border-b border-gray-100 ${s.status==="In Progress"?"bg-yellow-50":""}`,children:[q.jsx("td",{className:"px-4 py-2",children:q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("span",{className:"text-gray-400 w-6",children:String(s.index+1).padStart(2,"0")}),q.jsx("button",{onClick:()=>i(s.name),disabled:s.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 ${s.name} completes`,children:q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.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"})})}),q.jsx("span",{className:"font-medium text-gray-900",children:s.name})]})}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(VFo,{status:s.status})}),q.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:s.firstIteration!==null?s.firstIteration:""}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:s.iterations}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(JFo,{progress:s.progress})}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:A(s.timeSpent)}),q.jsx("td",{className:"px-4 py-2 text-gray-500",children:q.jsx(WFo,{stats:s.stats})}),q.jsx("td",{className:"px-4 py-2",children:s.solverInstance?q.jsxs("button",{onClick:()=>r(s),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${s.name}`,children:[q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.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"})}),q.jsx("span",{children:"Input"})]}):null})]},s.name))})]})})]})},$Fo=class extends Xr.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function ZFo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let A=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,m)=>{typeof p=="number"&&(p<A&&(A=p),p>a&&(a=p)),typeof m=="number"&&(m<s&&(s=m),m>c&&(c=m))};for(const p of e)l(p.x,p.y);for(const p of n){const m=p.points??[];for(const C of m)l(C.x,C.y)}for(const p of o){const m=p.x??0,C=p.y??0,I=p.width??0,f=p.height??0;l(m,C),l(m+I,C+f)}for(const p of i){const m=p.x??0,C=p.y??0,I=p.radius??1;l(m-I,C-I),l(m+I,C+I)}for(const p of r)l(p.x,p.y);(!isFinite(A)||!isFinite(s)||!isFinite(a)||!isFinite(c))&&(A=-20,s=-20,a=20,c=20);const g=10,u=A-g,h=s-g,d=Math.max(1,a-A+2*g),_=Math.max(1,c-s+2*g);return q.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,m)=>q.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-${m}`)),n.map((p,m)=>q.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(C=>`${C.x??0},${C.y??0}`).join(" ")},`line-${m}`)),i.map((p,m)=>q.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-${m}`)),e.map((p,m)=>q.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${m}`)),r.map((p,m)=>q.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${m}`))]})}var eLo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=te.useReducer(l=>l+1,0),A=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),s=te.useMemo(()=>(A.rects?.length||0)===0&&(A.lines?.length||0)===0&&(A.points?.length||0)===0&&(A.circles?.length||0)===0,[A]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const a=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return q.jsxs("div",{children:[q.jsx(UFo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),s?q.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):q.jsx($Fo,{fallback:q.jsx(ZFo,{graphics:A}),children:q.jsx(GFo,{graphics:A})}),a&&q.jsx(XFo,{solver:t,onStepUntilPhase:c})]})};const tLo=()=>{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)},[])},nLo=1e3,fS=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),A=document.createElement("a");A.href=r,A.download=n,A.target="_blank",A.rel="noopener noreferrer",A.style.display="none",document.body.appendChild(A),A.click(),document.body.removeChild(A),setTimeout(()=>{URL.revokeObjectURL(r)},nLo)},ANt=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"},yS="https://github.com/tscircuit/tscircuit-autorouter/issues/new",sNt="https://github.com/tscircuit/copper-pour-solver/issues/new",aNt="https://github.com/tscircuit/calculate-packing/issues/new",cNt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",oLo={PackSolver2:aNt,AutoroutingPipelineSolver:yS,AssignableAutoroutingPipeline2:yS,AssignableAutoroutingPipeline3:yS,AutoroutingPipeline1_OriginalUnravel:yS,AutoroutingPipelineSolver3_HgPortPointPathing:yS,AutoroutingPipelineSolver4:yS,AutoroutingPipelineSolver5:yS,AutoroutingPipelineSolver7_MultiGraph:yS,AutoroutingPipelineSolver8:yS,CopperPourPipelineSolver:sNt,SchematicTracePipelineSolver:cNt},iLo=t=>t.toLowerCase().includes("pack")?RMo:t.toLowerCase().includes("rout")?OMo:bMo,lNt=t=>{const e=oLo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?yS:n.includes("schematic")&&n.includes("trace")?cNt:n.includes("copperpour")?sNt:n.includes("pack")?aNt:null},rLo=t=>`${ANt(`${t.componentName}-${t.solverName}`)}-solver-input.json`,gNt=t=>{fS(JSON.stringify(t.solverParams,null,2),{fileName:rLo(t),mimeType:"application/json"})},ALo=({solverEvent:t})=>{const e=lNt(t.solverName);return q.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:[q.jsxs(pc,{type:"button",variant:"outline",size:"sm",onClick:()=>gNt(t),children:[q.jsx(rwe,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?q.jsx(pc,{asChild:!0,variant:"outline",size:"sm",children:q.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[q.jsx(Mne,{className:"rf-w-4 rf-h-4"}),"Report"]})}):q.jsxs(pc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[q.jsx(Mne,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},sLo=({solverEvent:t})=>{const e=lNt(t.solverName);return e?q.jsx(pc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:q.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:q.jsx(Mne,{className:"rf-w-4 rf-h-4"})})}):q.jsx(pc,{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:q.jsx(Mne,{className:"rf-w-4 rf-h-4"})})},aLo=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);tLo();const o=te.useMemo(()=>{const s=new Map;for(const a of t){const c=`${a.componentName}-${a.solverName}`;s.set(c,a)}return s},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,A=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const s=zye[r.solverName];if(!s)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(zye).join(", ")}`,classFound:!1};try{const a=r.solverParams,c=a?.input!==void 0?a.input:a;return{instance:new s(c),error:null,classFound:!0}}catch(a){const c=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?q.jsx("div",{className:"rf-p-4",children:q.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:q.jsxs("div",{className:"rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),q.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."})]})})}):q.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[q.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(s=>{const a=o.get(s),c=e===s;return q.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(s),children:(()=>{const l=iLo(a.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),q.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},s)})]}),q.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?A.instance?q.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[q.jsx(ALo,{solverEvent:r}),q.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:q.jsx(aS,{fallback:q.jsx("div",{className:"rf-p-4",children:q.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),q.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:q.jsx(eLo,{solver:A.instance})})})]}):q.jsxs("div",{className:"rf-p-4",children:[q.jsxs("div",{className:"rf-mb-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),q.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),A.error&&q.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${A.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:q.jsx("p",{className:`rf-text-sm ${A.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:A.error})}),q.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[q.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:[q.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(sLo,{solverEvent:r}),q.jsx(pc,{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:()=>gNt(r),children:q.jsx(rwe,{className:"rf-w-4 rf-h-4"})})]})]}),q.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:q.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)})})]})]}):q.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},uNt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{G6.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{G6.captureException(i,{error_type:o.type})}catch{}}},[n])},cLo=t=>{te.useEffect(()=>{try{xKt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},dNt="0.0.2376",lLo={version:dNt},Q3e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},S3e=new Map,Xoe=t=>{const e=S3e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},gLo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=S3e.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return S3e.set(n.name,i),{type:"tracked",store:t,...i}},hNt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:A,store:s,...a}=e;let c;try{c=(r??(Q3e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Q3e?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=gLo(s,c,a);let u=!0;i.setState=(_,p,m)=>{const C=n(_,p);if(!u)return C;const I=m===void 0?{type:A||"anonymous"}:typeof m=="string"?{type:m}:m;return s===void 0?(l?.send(I,o()),C):(l?.send({...I,type:`${s}/${I.type}`},{...Xoe(a.name),[s]:i.getState()}),C)};const h=(..._)=>{const p=u;u=!1,n(..._),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(([_,p])=>[_,_===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const p=i.dispatch;i.dispatch=(...m)=>{(Q3e?"production":void 0)!=="production"&&m[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),p(...m)}}return l.subscribe(_=>{var p;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return b3e(_.payload,m=>{if(m.type==="__setState"){if(s===void 0){h(m.state);return}Object.keys(m.state).length!==1&&console.error(`
5755
+ `,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}o(!1)};return q.jsxs("div",{className:`relative ${e}`,ref:i,children:[q.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&q.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:[q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:A,children:"Download page.tsx"}),q.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download test.ts"})]})]})},rNt=t=>t.activeSubSolver?[t,...rNt(t.activeSubSolver)]:[t],KFo=({solver:t})=>{const e=rNt(t);return q.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>q.jsxs("div",{className:"flex items-center",children:[o>0&&q.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),q.jsx(OFo,{solver:n})]},n.constructor.name))})},UFo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,A]=te.useReducer(_=>!_,!1),s=te.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),e())},c=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},l=()=>{r?(s.current&&(clearInterval(s.current),s.current=void 0),A()):(A(),s.current=setInterval(()=>{if(t.solved||t.failed){s.current&&(clearInterval(s.current),s.current=void 0),A(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},g=()=>{const _=t;if(_.getCurrentPhase&&!t.solved&&!t.failed){const p=_.getCurrentPhase();for(;_.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},u=()=>{if(t.solved||t.failed||r)return;const _=window.prompt("Step until which iteration?",`${t.iterations}`);if(_===null)return;const p=Number(_);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{s.current&&clearInterval(s.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&r&&(s.current&&(clearInterval(s.current),s.current=void 0),A())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return q.jsxs("div",{className:"space-y-2 p-2 border-b",children:[q.jsx("div",{className:"flex items-center",children:q.jsx(KFo,{solver:t})}),q.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[q.jsx("button",{onClick:a,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),q.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),q.jsx("button",{onClick:l,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),q.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&q.jsx("button",{onClick:g,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),q.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&q.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",q.jsx("span",{className:"font-medium",children:d})]}),t.solved&&q.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&q.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&q.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},YFo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},zFo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=YFo(t,e),r=t[o],A=t.firstIterationOfPhase?.[o]??null,s=t.iterations;let a=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfPhase?.[u.solverName]:void 0;h!==void 0&&A!==null?a=h-A:A!==null&&(a=s-A)}else i==="In Progress"&&A!==null&&(a=s-A);const c=t.timeSpentOnPhase?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:A,iterations:a,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},VFo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return q.jsx("span",{className:`font-medium ${e[t]}`,children:t})},JFo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:q.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),q.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},qFo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),WFo=({stats:t})=>{if(!t||Object.keys(t).length===0)return q.jsx("span",{children:"-"});const e=Object.entries(t),n=qFo(t);return q.jsxs("details",{className:"cursor-pointer",children:[q.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),q.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>q.jsxs("div",{children:[o,": ",String(i)]},o))})]})},B3e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(B3e);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=B3e(o));return e},jFo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=B3e(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)}`)}},XFo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((s,a)=>zFo(t,a)),i=s=>{e?.(s)},r=s=>{s.solverInstance&&(n?n(s.solverInstance,s.name):jFo(s.solverInstance,s.name))},A=s=>`${(s/1e3).toFixed(2)}s`;return q.jsxs("div",{className:"border-t border-gray-200",children:[q.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:q.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),q.jsx("div",{className:"overflow-x-auto",children:q.jsxs("table",{className:"w-full text-sm",children:[q.jsx("thead",{children:q.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),q.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",q.jsx("sub",{children:"0"})]}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),q.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),q.jsx("tbody",{children:o.map(s=>q.jsxs("tr",{className:`border-b border-gray-100 ${s.status==="In Progress"?"bg-yellow-50":""}`,children:[q.jsx("td",{className:"px-4 py-2",children:q.jsxs("div",{className:"flex items-center gap-2",children:[q.jsx("span",{className:"text-gray-400 w-6",children:String(s.index+1).padStart(2,"0")}),q.jsx("button",{onClick:()=>i(s.name),disabled:s.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 ${s.name} completes`,children:q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.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"})})}),q.jsx("span",{className:"font-medium text-gray-900",children:s.name})]})}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(VFo,{status:s.status})}),q.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:s.firstIteration!==null?s.firstIteration:""}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:s.iterations}),q.jsx("td",{className:"px-4 py-2",children:q.jsx(JFo,{progress:s.progress})}),q.jsx("td",{className:"px-4 py-2 text-gray-600",children:A(s.timeSpent)}),q.jsx("td",{className:"px-4 py-2 text-gray-500",children:q.jsx(WFo,{stats:s.stats})}),q.jsx("td",{className:"px-4 py-2",children:s.solverInstance?q.jsxs("button",{onClick:()=>r(s),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${s.name}`,children:[q.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:q.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"})}),q.jsx("span",{children:"Input"})]}):null})]},s.name))})]})})]})},$Fo=class extends Xr.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function ZFo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let A=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,m)=>{typeof p=="number"&&(p<A&&(A=p),p>a&&(a=p)),typeof m=="number"&&(m<s&&(s=m),m>c&&(c=m))};for(const p of e)l(p.x,p.y);for(const p of n){const m=p.points??[];for(const C of m)l(C.x,C.y)}for(const p of o){const m=p.x??0,C=p.y??0,I=p.width??0,f=p.height??0;l(m,C),l(m+I,C+f)}for(const p of i){const m=p.x??0,C=p.y??0,I=p.radius??1;l(m-I,C-I),l(m+I,C+I)}for(const p of r)l(p.x,p.y);(!isFinite(A)||!isFinite(s)||!isFinite(a)||!isFinite(c))&&(A=-20,s=-20,a=20,c=20);const g=10,u=A-g,h=s-g,d=Math.max(1,a-A+2*g),_=Math.max(1,c-s+2*g);return q.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${_}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,m)=>q.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-${m}`)),n.map((p,m)=>q.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(C=>`${C.x??0},${C.y??0}`).join(" ")},`line-${m}`)),i.map((p,m)=>q.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-${m}`)),e.map((p,m)=>q.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${m}`)),r.map((p,m)=>q.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${m}`))]})}var eLo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=te.useReducer(l=>l+1,0),A=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(l){return console.error("Visualization error:",l),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),s=te.useMemo(()=>(A.rects?.length||0)===0&&(A.lines?.length||0)===0&&(A.points?.length||0)===0&&(A.circles?.length||0)===0,[A]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(l)}},[]);const a=t.pipelineDef!==void 0,c=l=>{const g=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&g.currentPipelineStepIndex<=g.pipelineDef.findIndex(u=>u.solverName===l);)t.step();r()}};return q.jsxs("div",{children:[q.jsx(UFo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),s?q.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):q.jsx($Fo,{fallback:q.jsx(ZFo,{graphics:A}),children:q.jsx(GFo,{graphics:A})}),a&&q.jsx(XFo,{solver:t,onStepUntilPhase:c})]})};const tLo=()=>{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)},[])},nLo=1e3,fS=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),A=document.createElement("a");A.href=r,A.download=n,A.target="_blank",A.rel="noopener noreferrer",A.style.display="none",document.body.appendChild(A),A.click(),document.body.removeChild(A),setTimeout(()=>{URL.revokeObjectURL(r)},nLo)},ANt=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"},yS="https://github.com/tscircuit/tscircuit-autorouter/issues/new",sNt="https://github.com/tscircuit/copper-pour-solver/issues/new",aNt="https://github.com/tscircuit/calculate-packing/issues/new",cNt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",oLo={PackSolver2:aNt,AutoroutingPipelineSolver:yS,AssignableAutoroutingPipeline2:yS,AssignableAutoroutingPipeline3:yS,AutoroutingPipeline1_OriginalUnravel:yS,AutoroutingPipelineSolver3_HgPortPointPathing:yS,AutoroutingPipelineSolver4:yS,AutoroutingPipelineSolver5:yS,AutoroutingPipelineSolver7_MultiGraph:yS,AutoroutingPipelineSolver8:yS,CopperPourPipelineSolver:sNt,SchematicTracePipelineSolver:cNt},iLo=t=>t.toLowerCase().includes("pack")?RMo:t.toLowerCase().includes("rout")?OMo:bMo,lNt=t=>{const e=oLo[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?yS:n.includes("schematic")&&n.includes("trace")?cNt:n.includes("copperpour")?sNt:n.includes("pack")?aNt:null},rLo=t=>`${ANt(`${t.componentName}-${t.solverName}`)}-solver-input.json`,gNt=t=>{fS(JSON.stringify(t.solverParams,null,2),{fileName:rLo(t),mimeType:"application/json"})},ALo=({solverEvent:t})=>{const e=lNt(t.solverName);return q.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:[q.jsxs(pc,{type:"button",variant:"outline",size:"sm",onClick:()=>gNt(t),children:[q.jsx(rwe,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?q.jsx(pc,{asChild:!0,variant:"outline",size:"sm",children:q.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[q.jsx(Mne,{className:"rf-w-4 rf-h-4"}),"Report"]})}):q.jsxs(pc,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[q.jsx(Mne,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},sLo=({solverEvent:t})=>{const e=lNt(t.solverName);return e?q.jsx(pc,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:q.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:q.jsx(Mne,{className:"rf-w-4 rf-h-4"})})}):q.jsx(pc,{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:q.jsx(Mne,{className:"rf-w-4 rf-h-4"})})},aLo=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);tLo();const o=te.useMemo(()=>{const s=new Map;for(const a of t){const c=`${a.componentName}-${a.solverName}`;s.set(c,a)}return s},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,A=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const s=zye[r.solverName];if(!s)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(zye).join(", ")}`,classFound:!1};try{const a=r.solverParams,c=a?.input!==void 0?a.input:a;return{instance:new s(c),error:null,classFound:!0}}catch(a){const c=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?q.jsx("div",{className:"rf-p-4",children:q.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:q.jsxs("div",{className:"rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),q.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."})]})})}):q.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[q.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[q.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(s=>{const a=o.get(s),c=e===s;return q.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(s),children:(()=>{const l=iLo(a.solverName);return q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[q.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),q.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[q.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),q.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},s)})]}),q.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?A.instance?q.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[q.jsx(ALo,{solverEvent:r}),q.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:q.jsx(aS,{fallback:q.jsx("div",{className:"rf-p-4",children:q.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),q.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:q.jsx(eLo,{solver:A.instance})})})]}):q.jsxs("div",{className:"rf-p-4",children:[q.jsxs("div",{className:"rf-mb-4",children:[q.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),q.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),A.error&&q.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${A.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:q.jsx("p",{className:`rf-text-sm ${A.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:A.error})}),q.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[q.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:[q.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),q.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[q.jsx(sLo,{solverEvent:r}),q.jsx(pc,{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:()=>gNt(r),children:q.jsx(rwe,{className:"rf-w-4 rf-h-4"})})]})]}),q.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:q.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)})})]})]}):q.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:q.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},uNt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{G6.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{G6.captureException(i,{error_type:o.type})}catch{}}},[n])},cLo=t=>{te.useEffect(()=>{try{xKt(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},dNt="0.0.2377",lLo={version:dNt},Q3e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},S3e=new Map,Xoe=t=>{const e=S3e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},gLo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=S3e.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return S3e.set(n.name,i),{type:"tracked",store:t,...i}},hNt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:A,store:s,...a}=e;let c;try{c=(r??(Q3e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Q3e?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=gLo(s,c,a);let u=!0;i.setState=(_,p,m)=>{const C=n(_,p);if(!u)return C;const I=m===void 0?{type:A||"anonymous"}:typeof m=="string"?{type:m}:m;return s===void 0?(l?.send(I,o()),C):(l?.send({...I,type:`${s}/${I.type}`},{...Xoe(a.name),[s]:i.getState()}),C)};const h=(..._)=>{const p=u;u=!1,n(..._),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(([_,p])=>[_,_===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let _=!1;const p=i.dispatch;i.dispatch=(...m)=>{(Q3e?"production":void 0)!=="production"&&m[0].type==="__setState"&&!_&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),_=!0),p(...m)}}return l.subscribe(_=>{var p;switch(_.type){case"ACTION":if(typeof _.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return b3e(_.payload,m=>{if(m.type==="__setState"){if(s===void 0){h(m.state);return}Object.keys(m.state).length!==1&&console.error(`
5756
5756
  [zustand devtools middleware] Unsupported __setState action format.
5757
5757
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5758
5758
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }