@tscircuit/runframe 0.0.1445 → 0.0.1446

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.
@@ -1716,7 +1716,7 @@ var useErrorTelemetry = ({
1716
1716
  };
1717
1717
 
1718
1718
  // package.json
1719
- var version = "0.0.1444";
1719
+ var version = "0.0.1445";
1720
1720
  var package_default = {
1721
1721
  name: "@tscircuit/runframe",
1722
1722
  main: "dist/preview.js",
@@ -1767,11 +1767,11 @@ var package_default = {
1767
1767
  "@tscircuit/3d-viewer": "^0.0.480",
1768
1768
  "@tscircuit/assembly-viewer": "^0.0.5",
1769
1769
  "@tscircuit/create-snippet-url": "^0.0.9",
1770
- "@tscircuit/eval": "^0.0.558",
1770
+ "@tscircuit/eval": "^0.0.559",
1771
1771
  "@tscircuit/fake-snippets": "^0.0.163",
1772
1772
  "@tscircuit/file-server": "^0.0.32",
1773
1773
  "@tscircuit/footprinter": "^0.0.236",
1774
- "@tscircuit/pcb-viewer": "1.11.294",
1774
+ "@tscircuit/pcb-viewer": "1.11.295",
1775
1775
  "@tscircuit/props": "^0.0.429",
1776
1776
  "@tscircuit/schematic-trace-solver": "^0.0.40",
1777
1777
  "@tscircuit/schematic-viewer": "^2.0.51",
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  linkify,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-LFPN2EJP.js";
11
+ } from "./chunk-2S27XVDJ.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  useRunFrameStore,
35
35
  useRunnerStore,
36
36
  useStyles
37
- } from "./chunk-LFPN2EJP.js";
37
+ } from "./chunk-2S27XVDJ.js";
38
38
 
39
39
  // lib/components/RunFrame/RunFrame.tsx
40
40
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5381,7 +5381,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function j$A(t,A,e){if(!A||!e)retu
5381
5381
  transition: opacity 0.2s;
5382
5382
  margin-bottom: 10px;
5383
5383
  color: red;
5384
- `,Xvt=({children:t,transform:A=lg(),elements:e})=>{const i=AA.useRef(null),{isShowingDRCErrors:o,hoveredErrorId:n}=wl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return V.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),V.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,I)=>{const{pcb_port_ids:c,pcb_trace_id:B}=g,C=c?.[0]?a.get(c[0]):void 0,l=c?.[1]?a.get(c[1]):void 0,Q=e?hS(e).pcb_trace.get(B):void 0,E=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,h=n===E;if(C&&l){const u=ae(A,{x:C.x,y:C.y}),d=ae(A,{x:l.x,y:l.y}),f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),D={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(D.x)||isNaN(D.y))return null;const b=PQA(D,i);return V.jsxs(AA.Fragment,{children:[V.jsx(jvt,{screenPort1:u,screenPort2:d,errorCenter:D,canLineBeDrawn:f,isHighlighted:h}),V.jsx("div",{style:{position:"absolute",left:D.x-15,top:D.y-15,width:30,height:30,zIndex:gI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:m=>{const x=m.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="1")}},onMouseLeave:m=>{if(!h){const x=m.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:b.left,top:b.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:V.jsx("div",{className:`error-message ${OQA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}if(Q?.route&&(o||h)){const u=Q.route.map(b=>ae(A,{x:b.x,y:b.y}));if(u.some(b=>isNaN(b.x)||isNaN(b.y)))return null;const d=Math.floor(u.length/2),f=u[d],D=PQA(f,i);return V.jsxs(AA.Fragment,{children:[V.jsx(zvt,{points:u,errorCenter:f,isHighlighted:h}),V.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:gI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:b=>{const m=b.currentTarget.nextElementSibling;if(m){const x=m.querySelector(".error-message");x&&(x.style.opacity="1")}},onMouseLeave:b=>{if(!h){const m=b.currentTarget.nextElementSibling;if(m){const x=m.querySelector(".error-message");x&&(x.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:h?gI.errorOverlay+10:gI.errorOverlay+1,left:D.left,top:D.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:D.transform},children:V.jsx("div",{className:`error-message ${OQA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}return null}),r.map((g,I)=>{const c=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!c)return null;const B=e?.filter(Q=>Q.type==="source_component"&&Q.name===c||Q.type==="pcb_component"&&e?.find(E=>E.type==="source_component"&&E.source_component_id===Q.source_component_id&&E.name===c))||[],C=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,l=n===C;return!l&&!o?null:B.map((Q,E)=>{let h={x:0,y:0};if(Q.type==="pcb_component")h=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const F=e?.find(k=>k.type==="pcb_component"&&k.source_component_id===Q.source_component_id);F&&F.type==="pcb_component"&&(h=F.center||{x:0,y:0})}const u=ae(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),m=Math.max(8,Math.min(30,.5*d)),x=PQA(u,i);return V.jsxs(AA.Fragment,{children:[V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:gI.errorOverlay},width:"100%",height:"100%",children:l?V.jsx("polygon",{points:`${u.x},${u.y-m*1.25} ${u.x+m},${u.y} ${u.x},${u.y+m*1.25} ${u.x-m},${u.y}`,fill:"#ff4444"}):V.jsx("circle",{cx:u.x,cy:u.y,r:m,fill:"none",stroke:l?"#ff4444":"red",strokeWidth:l?Math.max(2,m*.15):Math.max(1,m*.1),opacity:1})}),V.jsx("div",{style:{position:"absolute",left:u.x-(m+10),top:u.y-(m+10),width:(m+10)*2,height:(m+10)*2,zIndex:gI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:F=>{const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="1")}},onMouseLeave:F=>{if(!l){const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:l?gI.errorOverlay+20:gI.errorOverlay+10,left:x.left,top:x.top,color:l?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||l?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:V.jsx("div",{className:`error-message ${OQA}`,style:{opacity:l?1:0,border:`1px solid ${l?"#ff4444":"red"}`},children:g.message})})]},`${C}_${E}`)})})]})};function $vt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function A1t({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=hS(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const o=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:o}}function e1t(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,o=A.filter(a=>a._element.type==="pcb_trace"),n=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=o.filter(a=>n.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(o.length>1){const a=o.reduce((g,I)=>{const c=g._element.trace_length;return I._element.trace_length<c?I:g},o[0]);return[...s,a]}return A}var t1t={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},i1t=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:o}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const n=[],s=Array.from(new Set((A.port_hints??[]).concat(o?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?n.push(...s.map(a=>`${r}.${a}`)):n.push(...s):r&&n.push(r),n.join(", ")}default:return""}},o1t={top:"red",bottom:"aqua"},n1t=({primitive:t,mousePos:A,elements:e})=>{const[i,o]=AA.useState(!1),n=t._element;AA.useEffect(()=>{setTimeout(()=>{o(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],I=t.same_space_index??0,c=26,B=o1t[t?._element?.layer]??"red";let C=0;if(n.type==="pcb_smtpad"&&n?.shape==="rotated_rect"?C=n?.ccw_rotation??0:(n.type==="pcb_smtpad"&&(n?.shape==="pill"||n?.shape==="rotated_pill")&&"ccw_rotation"in t||n.type==="pcb_plated_hole"&&(n?.shape==="pill"||n?.shape==="oval")&&"ccw_rotation"in t)&&(C=n.ccw_rotation??0),n.type==="pcb_trace"){const E=A1t({primitiveElement:n,elements:e});if(!E)return null;const h=A.y-35;return V.jsx("div",{style:{zIndex:gI.elementOverlay,position:"absolute",left:A.x,top:h,color:B,pointerEvents:"none",transform:"translateX(-50%)"},children:V.jsx("div",{style:{backgroundColor:"#f2efcc",color:E.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:E.text})})}const l=i1t(t);return l.trim().length===0?null:V.jsx("div",{style:{zIndex:gI.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:B,transform:`rotate(${-C}deg)`,transformOrigin:"center center"},children:V.jsx("div",{style:{width:i?`calc(100% + ${c*2*I}px)`:"100%",height:i?`calc(100% + ${c*2*I}px)`:"100%",marginLeft:i?`${-c*I}px`:0,marginTop:i?`${-c*I}px`:0,border:`1px solid ${B}`,opacity:i||I===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:V.jsx("div",{style:{position:"absolute",bottom:g+20+c*I,marginRight:i?`${-c*I}px`:0,marginBottom:i?0:-c*I,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(${C}deg)`,minWidth:"45px",textAlign:"center"},children:l})})})},s1t=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,o]=wl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),n=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return n&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=e1t({primitives:s,is_showing_multiple_traces_length:o,elements:e}),V.jsx("div",{style:t1t,children:!i&&s.map((r,a)=>V.jsx(n1t,{primitive:r,mousePos:A,elements:e},a))})},Yx=t=>t?.type==="pcb_component",hAe=t=>t?.type==="pcb_group",r1t=t=>t?.type==="pcb_panel",WQA=t=>t?.type==="pcb_board",JI={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},Xf={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},ZQA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const o={color:Xf.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:JI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},n=new Map;return t.forEach(s=>{if(!n.has(s.anchor_id)){const r=ae(A,s.anchor);n.set(s.anchor_id,r)}}),V.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:gI.dimensionOverlay},children:V.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,I=n.get(a),c=ae(A,g),B=g.x-r.x,C=g.y-r.y,l=Math.abs(c.x-I.x),Q=Math.abs(c.y-I.y),E=c.y<I.y,h=c.x>I.x,u=E?JI.LABEL_OFFSET_ABOVE:JI.LABEL_OFFSET_BELOW,d=h?JI.LABEL_OFFSET_RIGHT:JI.LABEL_OFFSET_LEFT,f=l>JI.MIN_LINE_LENGTH_FOR_LABEL,D=Q>JI.MIN_LINE_LENGTH_FOR_LABEL,b=`${s.display_offset_x??B.toFixed(2)}mm`,m=`${s.display_offset_y??C.toFixed(2)}mm`;return V.jsxs("g",{children:[V.jsx("line",{x1:I.x,y1:I.y,x2:c.x,y2:I.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.LINE_STROKE_WIDTH,strokeDasharray:JI.LINE_DASH_PATTERN}),V.jsx("line",{x1:c.x,y1:I.y,x2:c.x,y2:c.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.LINE_STROKE_WIDTH,strokeDasharray:JI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?V.jsx("circle",{cx:c.x,cy:c.y,r:JI.COMPONENT_MARKER_RADIUS,fill:Xf.COMPONENT_MARKER_FILL,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1}):V.jsxs(V.Fragment,{children:[V.jsx("line",{x1:c.x-JI.ANCHOR_MARKER_SIZE,y1:c.y,x2:c.x+JI.ANCHOR_MARKER_SIZE,y2:c.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:c.x,y1:c.y-JI.ANCHOR_MARKER_SIZE,x2:c.x,y2:c.y+JI.ANCHOR_MARKER_SIZE,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&V.jsx("foreignObject",{x:Math.min(I.x,c.x),y:I.y+u,width:Math.abs(c.x-I.x),height:20,style:{overflow:"visible"},children:V.jsx("div",{style:{...o,textAlign:"center"},children:b})}),D&&V.jsx("foreignObject",{x:c.x+d,y:Math.min(I.y,c.y),width:JI.Y_LABEL_MIN_WIDTH,height:Math.abs(c.y-I.y),style:{overflow:"visible"},children:V.jsx("div",{style:{...o,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:m})})]},s.id)}),Array.from(n.entries()).map(([s,r])=>V.jsxs("g",{children:[V.jsx("line",{x1:r.x-JI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+JI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:r.x,y1:r.y-JI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+JI.ANCHOR_MARKER_SIZE,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},a1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=t.filter(h=>WQA(h)),s=t.filter(h=>Yx(h)),r=t.filter(h=>hAe(h)),a=A.map(h=>Yx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Yx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!wl(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),B=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),C=[...c,...B];if(C.length===0)return null;const l=a.length===0,Q=C.filter(h=>h.type==="component"?l||a.includes(h.component.pcb_component_id):l||g.has(h.group.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return V.jsx(ZQA,{targets:E,transform:e,containerWidth:i,containerHeight:o})},g1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=t.filter(h=>hAe(h)),s=t.filter(h=>Yx(h)),r=A.map(h=>Yx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Yx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=n.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!wl(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const c=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),B=n.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.center)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),C=[...c,...B];if(C.length===0)return null;const l=r.length===0,Q=C.filter(h=>h.type==="component"?l||r.includes(h.component.pcb_component_id):l||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.center?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.center,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return V.jsx(ZQA,{targets:E,transform:e,containerWidth:i,containerHeight:o})},I1t=(t,A)=>{const e=t.pcb_component_id,i=A.filter(o=>(o.type==="pcb_smtpad"||o.type==="pcb_plated_hole")&&o.pcb_component_id===e||o.type==="pcb_hole"&&o.pcb_component_id===e);return i.length===0?qQA([t]):qQA(i)},c1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=new Map;for(const r of A)Yx(r._parent_pcb_component)&&n.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Yx(r._element)&&n.set(r._element.pcb_component_id,r._element);if(n.size===0)return null;const s=[];for(const r of n.values()){const a=I1t(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,I=g?hS(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:I})}return s.length===0?null:V.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:o,overflow:"hidden",pointerEvents:"none",zIndex:gI.dimensionOverlay},children:V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:o,children:s.map(({component:r,bbox:a,group:g})=>{const I=ae(e,{x:a.minX,y:a.maxY}),c=ae(e,{x:a.maxX,y:a.minY}),B={x:Math.min(I.x,c.x),y:Math.min(I.y,c.y),width:Math.abs(c.x-I.x),height:Math.abs(c.y-I.y)},C=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},l=ae(e,C);return V.jsxs("g",{children:[V.jsx("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),V.jsx("line",{x1:l.x-6,y1:l.y,x2:l.x+6,y2:l.y,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("line",{x1:l.x,y1:l.y-6,x2:l.x,y2:l.y+6,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("circle",{cx:l.x,cy:l.y,r:JI.COMPONENT_MARKER_RADIUS,fill:Xf.COMPONENT_MARKER_FILL,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},B1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=t.filter(C=>r1t(C)),s=t.filter(C=>WQA(C)),r=A.map(C=>WQA(C._element)?C._element.pcb_board_id:null).filter(C=>!!C);if(!wl(C=>C.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(C=>{const l=C.pcb_panel_id,Q=C.position_mode;if(!l||Q!=="relative_to_panel_anchor")return null;const E=n.find(h=>h.pcb_panel_id===l);return E?{board:C,panel:E,type:"board"}:null}).filter(C=>!!C);if(g.length===0)return null;const I=r.length===0,c=g.filter(C=>I||r.includes(C.board.pcb_board_id));if(c.length===0)return null;const B=c.map(C=>C.board.center?{id:`${C.panel.pcb_panel_id}-${C.board.pcb_board_id}-${C.type}`,anchor:C.panel.center,anchor_id:C.panel.pcb_panel_id,target:C.board.center,type:"board",display_offset_x:C.board.display_offset_x,display_offset_y:C.board.display_offset_y}:null).filter(C=>!!C);return V.jsx(ZQA,{targets:B,transform:e,containerWidth:i,containerHeight:o})},tW=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,o=t[0].y;for(const n of t)n.x<A&&(A=n.x),n.y<e&&(e=n.y),n.x>i&&(i=n.x),n.y>o&&(o=n.y);return{center:{x:(A+i)/2,y:(e+o)/2},width:i-A,height:o-e}},uAe=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,o=A.length-1;i<A.length;o=i++){const n=A[i].x,s=A[i].y,r=A[o].x,a=A[o].y;s>t.y!=a>t.y&&t.x<(r-n)*(t.y-s)/(a-s||Number.EPSILON)+n&&(e=!e)}return e},C1t=(t,A,e)=>{const i=[];for(const o of t){if(!o._element)continue;if("x1"in o&&o._element?.type==="pcb_trace"){const r=oh({x:A.x,y:A.y},{x:o.x1,y:o.y1},{x:o.x2,y:o.y2}),a=o.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(o);continue}if(o.pcb_drawing_type==="polygon"){const r=o.points.map(g=>({x:ge.parse(g.x),y:ge.parse(g.y)})),a=tW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;uAe(A,r)&&i.push(o);continue}if(o.pcb_drawing_type==="polygon_with_arcs"){const r=o.brep_shape.outer_ring.vertices.map(g=>({x:ge.parse(g.x),y:ge.parse(g.y)})),a=tW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;uAe(A,r)&&i.push(o);continue}if(!("x"in o&&"y"in o))continue;let n=0,s=0;if("w"in o&&"h"in o)n=o.w,s=o.h;else if("r"in o)n=o.r*2,s=o.r*2;else if("rX"in o&&"rY"in o)n=o.rX*2,s=o.rY*2;else continue;Math.abs(o.x-A.x)<n/2&&Math.abs(o.y-A.y)<s/2&&i.push(o)}return i},l1t=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:o})=>{const[n,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:I,height:c}]=jL(),B=AA.useMemo(()=>{const l=[];for(const Q of n){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let E=null,h=0,u=0;if(Q.pcb_drawing_type==="polygon"){const b=tW(Q.points);if(!b)continue;E=b.center,h=b.width,u=b.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const b=Q.brep_shape.outer_ring.vertices.map(x=>({x:x.x,y:x.y})),m=tW(b);if(!m)continue;E=m.center,h=m.width,u=m.height}else"x"in Q&&"y"in Q&&(E={x:Q.x,y:Q.y},h="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!E)continue;const d=ae(e,E),f={w:h*e.a,h:u*e.a},D=l.filter(b=>d.x===b.screen_x&&d.y===b.screen_y&&f.w===b.screen_w&&f.h===b.screen_h).length;l.push({...Q,x:E.x,y:E.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:D})}return l},[n,e]),C=(l,Q,E,h)=>{a({x:l,y:Q});const u=ae(Z0(E),{x:l,y:Q}),d=C1t(h,u,E);$vt(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(n.map(f=>f._pcb_drawing_object_id)))||(s(d),o(d))};return V.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:l=>{if(e){const Q=l.currentTarget.getBoundingClientRect(),E=l.clientX-Q.left,h=l.clientY-Q.top;C(E,h,e,i)}},onTouchStart:l=>{if(e){const Q=l.touches[0],E=l.currentTarget.getBoundingClientRect(),h=Q.clientX-E.left,u=Q.clientY-E.top;C(h,u,e,i)}},children:[A,V.jsx(s1t,{elements:t,mousePos:r,highlightedPrimitives:B}),e&&V.jsxs(V.Fragment,{children:[V.jsx(a1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),V.jsx(g1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),V.jsx(c1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),V.jsx(B1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c})]})]})},dAe=["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)"],Q1t=({children:t,transform:A=lg(),elements:e=[],hoveredComponentIds:i=[]})=>{const[o,{width:n,height:s}]=jL(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:I}=wl(c=>({is_showing_pcb_groups:c.is_showing_pcb_groups,pcb_group_view_mode:c.pcb_group_view_mode,is_showing_group_anchor_offsets:c.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const c=r.current;if(!c||!n||!s)return;c.width=n,c.height=s;const B=c.getContext("2d");if(!B||(B.clearRect(0,0,n,s),!a))return;const C=e.filter(b=>b.type==="pcb_group"),l=e.filter(b=>b.type==="pcb_component"),Q=e.filter(b=>b.type==="source_group"),E=new Map(Q.map(b=>[b.source_group_id,b])),h=C.filter(b=>{if(g==="all")return!0;if(!b.source_group_id)return!1;const m=E.get(b.source_group_id);return m?m.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(b=>{const m=b;if(m.parent_source_group_id){const x=u.get(m.parent_source_group_id)||[];x.push(b.source_group_id),u.set(m.parent_source_group_id,x)}});const d=b=>{const m=[],x=u.get(b)||[];for(const F of x)m.push(F),m.push(...d(F));return m},f=b=>{const m=Q.find(x=>x.source_group_id===b);return m?.parent_source_group_id?1+f(m.parent_source_group_id):0},D=new Set;if(i.length>0)for(const b of l){if(!i.includes(b.pcb_component_id))continue;const m=b.positioned_relative_to_pcb_group_id??b.pcb_group_id;m&&D.add(m)}h.forEach((b,m)=>{let x=l.filter(HA=>HA.pcb_group_id===b.pcb_group_id);if(b.source_group_id){const HA=d(b.source_group_id),VA=C.filter(GA=>GA.source_group_id&&HA.includes(GA.source_group_id));for(const GA of VA){const DA=l.filter(vA=>vA.pcb_group_id===GA.pcb_group_id);x=[...x,...DA]}}let F,k,v,M,H=!1;if(b.center&&b.width&&b.height){H=!0;const HA=b.width/2,VA=b.height/2;F=b.center.x-HA,v=b.center.x+HA,k=b.center.y-VA,M=b.center.y+VA}else if(x.length===0||(F=1/0,k=1/0,v=-1/0,M=-1/0,x.forEach(HA=>{if(HA.center&&typeof HA.width=="number"&&typeof HA.height=="number"){const VA=HA.center.x-HA.width/2,GA=HA.center.x+HA.width/2,DA=HA.center.y+HA.height/2,vA=HA.center.y-HA.height/2;F=Math.min(F,VA),v=Math.max(v,GA),k=Math.min(k,vA),M=Math.max(M,DA)}}),F===1/0||v===-1/0))return;const q=b.source_group_id?f(b.source_group_id):0,K=b.source_group_id?d(b.source_group_id).length>0:!1;if(!H){const GA=1+(K?.5:0);F-=GA,v+=GA,k-=GA,M+=GA}const O=ae(A,{x:F,y:M}),W=ae(A,{x:v,y:M}),$=ae(A,{x:F,y:k}),oA=ae(A,{x:v,y:k}),IA=dAe[m%dAe.length];B.strokeStyle=IA,B.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),sA=Math.max(2,Math.min(6,4*Math.abs(A.a))),dA=tA*(K?1.3:1),SA=sA;B.setLineDash([dA,SA]),B.beginPath(),B.moveTo(O.x,O.y),B.lineTo(W.x,W.y),B.lineTo(oA.x,oA.y),B.lineTo($.x,$.y),B.closePath(),B.stroke();const RA=Math.max(8,Math.min(12,10*Math.abs(A.a))),NA=q==0||q==1?0:q*.11,qA=RA*(1-NA),BA=4,fA=b.name||`Group ${m+1}`;B.font=`${qA}px sans-serif`,B.setLineDash([]);const TA=B.measureText(fA).width+BA*2,ee=qA+BA*2,ce=O.x-5,yA=O.y-5,OA=3;if(B.fillStyle="rgba(0, 0, 0, 0.8)",B.beginPath(),B.roundRect(ce,yA-ee,TA,ee,OA),B.fill(),B.fillStyle=IA,B.textAlign="left",B.textBaseline="middle",B.fillText(fA,ce+BA,yA-ee/2),I&&D.has(b.pcb_group_id)&&!!b.anchor_position&&b.anchor_position){const HA=Array.isArray(b.anchor_position)?{x:b.anchor_position[0]??0,y:b.anchor_position[1]??0}:{x:b.anchor_position.x,y:b.anchor_position.y},VA=ae(A,HA);B.strokeStyle="white",B.lineWidth=1.5,B.setLineDash([]);const GA=Math.max(4,Math.min(8,6*Math.abs(A.a)));B.beginPath(),B.moveTo(VA.x-GA,VA.y),B.lineTo(VA.x+GA,VA.y),B.stroke(),B.beginPath(),B.moveTo(VA.x,VA.y-GA),B.lineTo(VA.x,VA.y+GA),B.stroke()}})},[e,A,n,s,a,g,I,i]),V.jsxs("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:[t,V.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:gI.pcbGroupOverlay,display:a?"block":"none"}})]})},E1t=({transform:t,soup:A,children:e})=>{const i=wl(r=>r.is_showing_rats_nest),{netMap:o,idToNetMap:n}=AA.useMemo(()=>iAe(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=B=>{const C=hS(A)[B.replace(/_\d+$/,"")].get(B);return C&&"x"in C&&"y"in C?{x:C.x,y:C.y}:null},a=(B,C)=>{const l=o[C]||[];let Q=null,E=1/0;return l.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((B.x-u.x)**2+(B.y-u.y)**2);d<E&&d>0&&(E=d,Q=u)}}),Q},g=hS(A).pcb_port.list(),I=hS(A).source_trace.list(),c=[];return g.forEach((B,C)=>{const l=n[B.pcb_port_id];let Q=!1;for(const u of I)u.connected_source_port_ids.includes(B.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!l)return;const E={x:B.x,y:B.y},h=a(E,l);h&&c.push({key:`${B.pcb_port_id}-${C}`,startPoint:E,endPoint:h,isInNet:Q})}),c},[A,o,n,i]);return!A||!i?e:(t||(t=lg()),V.jsxs("div",{style:{position:"relative"},children:[e,V.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:gI.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:I})=>{const c=ae(t,a),B=ae(t,g);return V.jsx("line",{x1:c.x,y1:c.y,x2:B.x,y2:B.y,stroke:"white",strokeWidth:"1",strokeDasharray:I?"6,6":void 0},r)})})]}))},h1t={version:"1.11.293"},Jx=(t,A)=>{const e=wl(i=>i.is_mouse_over_container);AA.useEffect(()=>{if(!t||typeof A!="function")return;const i=o=>{const n=t.split("+"),s=n.includes("ctrl"),r=n.includes("shift"),a=n.includes("alt"),g=n.includes("meta"),I=n[n.length-1];e&&(!s||o.ctrlKey)&&(!r||o.shiftKey)&&(!a||o.altKey)&&(!g||o.metaKey)&&o.key.toLowerCase()===I.toLowerCase()&&(o.preventDefault(),A())};return window.addEventListener("keydown",i),()=>{window.removeEventListener("keydown",i)}},[t,A])},u1t=()=>{const[t,A]=AA.useState(!1);return AA.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},d1t=({name:t,selected:A,onClick:e})=>V.jsxs("div",{className:f_`
5384
+ `,Xvt=({children:t,transform:A=lg(),elements:e})=>{const i=AA.useRef(null),{isShowingDRCErrors:o,hoveredErrorId:n}=wl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return V.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),V.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,I)=>{const{pcb_port_ids:c,pcb_trace_id:B}=g,C=c?.[0]?a.get(c[0]):void 0,l=c?.[1]?a.get(c[1]):void 0,Q=e?hS(e).pcb_trace.get(B):void 0,E=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,h=n===E;if(C&&l){const u=ae(A,{x:C.x,y:C.y}),d=ae(A,{x:l.x,y:l.y}),f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),D={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(D.x)||isNaN(D.y))return null;const b=PQA(D,i);return V.jsxs(AA.Fragment,{children:[V.jsx(jvt,{screenPort1:u,screenPort2:d,errorCenter:D,canLineBeDrawn:f,isHighlighted:h}),V.jsx("div",{style:{position:"absolute",left:D.x-15,top:D.y-15,width:30,height:30,zIndex:gI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:m=>{const x=m.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="1")}},onMouseLeave:m=>{if(!h){const x=m.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:b.left,top:b.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:V.jsx("div",{className:`error-message ${OQA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}if(Q?.route&&(o||h)){const u=Q.route.map(b=>ae(A,{x:b.x,y:b.y}));if(u.some(b=>isNaN(b.x)||isNaN(b.y)))return null;const d=Math.floor(u.length/2),f=u[d],D=PQA(f,i);return V.jsxs(AA.Fragment,{children:[V.jsx(zvt,{points:u,errorCenter:f,isHighlighted:h}),V.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:gI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:b=>{const m=b.currentTarget.nextElementSibling;if(m){const x=m.querySelector(".error-message");x&&(x.style.opacity="1")}},onMouseLeave:b=>{if(!h){const m=b.currentTarget.nextElementSibling;if(m){const x=m.querySelector(".error-message");x&&(x.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:h?gI.errorOverlay+10:gI.errorOverlay+1,left:D.left,top:D.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:D.transform},children:V.jsx("div",{className:`error-message ${OQA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}return null}),r.map((g,I)=>{const c=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!c)return null;const B=e?.filter(Q=>Q.type==="source_component"&&Q.name===c||Q.type==="pcb_component"&&e?.find(E=>E.type==="source_component"&&E.source_component_id===Q.source_component_id&&E.name===c))||[],C=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,l=n===C;return!l&&!o?null:B.map((Q,E)=>{let h={x:0,y:0};if(Q.type==="pcb_component")h=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const F=e?.find(k=>k.type==="pcb_component"&&k.source_component_id===Q.source_component_id);F&&F.type==="pcb_component"&&(h=F.center||{x:0,y:0})}const u=ae(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),m=Math.max(8,Math.min(30,.5*d)),x=PQA(u,i);return V.jsxs(AA.Fragment,{children:[V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:gI.errorOverlay},width:"100%",height:"100%",children:l?V.jsx("polygon",{points:`${u.x},${u.y-m*1.25} ${u.x+m},${u.y} ${u.x},${u.y+m*1.25} ${u.x-m},${u.y}`,fill:"#ff4444"}):V.jsx("circle",{cx:u.x,cy:u.y,r:m,fill:"none",stroke:l?"#ff4444":"red",strokeWidth:l?Math.max(2,m*.15):Math.max(1,m*.1),opacity:1})}),V.jsx("div",{style:{position:"absolute",left:u.x-(m+10),top:u.y-(m+10),width:(m+10)*2,height:(m+10)*2,zIndex:gI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:F=>{const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="1")}},onMouseLeave:F=>{if(!l){const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="0")}}}}),V.jsx("div",{style:{position:"absolute",zIndex:l?gI.errorOverlay+20:gI.errorOverlay+10,left:x.left,top:x.top,color:l?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||l?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:V.jsx("div",{className:`error-message ${OQA}`,style:{opacity:l?1:0,border:`1px solid ${l?"#ff4444":"red"}`},children:g.message})})]},`${C}_${E}`)})})]})};function $vt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function A1t({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=hS(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const o=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:o}}function e1t(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,o=A.filter(a=>a._element.type==="pcb_trace"),n=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=o.filter(a=>n.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(o.length>1){const a=o.reduce((g,I)=>{const c=g._element.trace_length;return I._element.trace_length<c?I:g},o[0]);return[...s,a]}return A}var t1t={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},i1t=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:o}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const n=[],s=Array.from(new Set((A.port_hints??[]).concat(o?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?n.push(...s.map(a=>`${r}.${a}`)):n.push(...s):r&&n.push(r),n.join(", ")}default:return""}},o1t={top:"red",bottom:"aqua"},n1t=({primitive:t,mousePos:A,elements:e})=>{const[i,o]=AA.useState(!1),n=t._element;AA.useEffect(()=>{setTimeout(()=>{o(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],I=t.same_space_index??0,c=26,B=o1t[t?._element?.layer]??"red";let C=0;if(n.type==="pcb_smtpad"&&n?.shape==="rotated_rect"?C=n?.ccw_rotation??0:(n.type==="pcb_smtpad"&&(n?.shape==="pill"||n?.shape==="rotated_pill")&&"ccw_rotation"in t||n.type==="pcb_plated_hole"&&(n?.shape==="pill"||n?.shape==="oval")&&"ccw_rotation"in t)&&(C=n.ccw_rotation??0),n.type==="pcb_trace"){const E=A1t({primitiveElement:n,elements:e});if(!E)return null;const h=A.y-35;return V.jsx("div",{style:{zIndex:gI.elementOverlay,position:"absolute",left:A.x,top:h,color:B,pointerEvents:"none",transform:"translateX(-50%)"},children:V.jsx("div",{style:{backgroundColor:"#f2efcc",color:E.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:E.text})})}const l=i1t(t);return l.trim().length===0?null:V.jsx("div",{style:{zIndex:gI.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:B,transform:`rotate(${-C}deg)`,transformOrigin:"center center"},children:V.jsx("div",{style:{width:i?`calc(100% + ${c*2*I}px)`:"100%",height:i?`calc(100% + ${c*2*I}px)`:"100%",marginLeft:i?`${-c*I}px`:0,marginTop:i?`${-c*I}px`:0,border:`1px solid ${B}`,opacity:i||I===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:V.jsx("div",{style:{position:"absolute",bottom:g+20+c*I,marginRight:i?`${-c*I}px`:0,marginBottom:i?0:-c*I,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(${C}deg)`,minWidth:"45px",textAlign:"center"},children:l})})})},s1t=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,o]=wl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),n=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return n&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=e1t({primitives:s,is_showing_multiple_traces_length:o,elements:e}),V.jsx("div",{style:t1t,children:!i&&s.map((r,a)=>V.jsx(n1t,{primitive:r,mousePos:A,elements:e},a))})},Yx=t=>t?.type==="pcb_component",hAe=t=>t?.type==="pcb_group",r1t=t=>t?.type==="pcb_panel",WQA=t=>t?.type==="pcb_board",JI={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},Xf={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},ZQA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const o={color:Xf.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:JI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},n=new Map;return t.forEach(s=>{if(!n.has(s.anchor_id)){const r=ae(A,s.anchor);n.set(s.anchor_id,r)}}),V.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:gI.dimensionOverlay},children:V.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,I=n.get(a),c=ae(A,g),B=g.x-r.x,C=g.y-r.y,l=Math.abs(c.x-I.x),Q=Math.abs(c.y-I.y),E=c.y<I.y,h=c.x>I.x,u=E?JI.LABEL_OFFSET_ABOVE:JI.LABEL_OFFSET_BELOW,d=h?JI.LABEL_OFFSET_RIGHT:JI.LABEL_OFFSET_LEFT,f=l>JI.MIN_LINE_LENGTH_FOR_LABEL,D=Q>JI.MIN_LINE_LENGTH_FOR_LABEL,b=`${s.display_offset_x??B.toFixed(2)}mm`,m=`${s.display_offset_y??C.toFixed(2)}mm`;return V.jsxs("g",{children:[V.jsx("line",{x1:I.x,y1:I.y,x2:c.x,y2:I.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.LINE_STROKE_WIDTH,strokeDasharray:JI.LINE_DASH_PATTERN}),V.jsx("line",{x1:c.x,y1:I.y,x2:c.x,y2:c.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.LINE_STROKE_WIDTH,strokeDasharray:JI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?V.jsx("circle",{cx:c.x,cy:c.y,r:JI.COMPONENT_MARKER_RADIUS,fill:Xf.COMPONENT_MARKER_FILL,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1}):V.jsxs(V.Fragment,{children:[V.jsx("line",{x1:c.x-JI.ANCHOR_MARKER_SIZE,y1:c.y,x2:c.x+JI.ANCHOR_MARKER_SIZE,y2:c.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:c.x,y1:c.y-JI.ANCHOR_MARKER_SIZE,x2:c.x,y2:c.y+JI.ANCHOR_MARKER_SIZE,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&V.jsx("foreignObject",{x:Math.min(I.x,c.x),y:I.y+u,width:Math.abs(c.x-I.x),height:20,style:{overflow:"visible"},children:V.jsx("div",{style:{...o,textAlign:"center"},children:b})}),D&&V.jsx("foreignObject",{x:c.x+d,y:Math.min(I.y,c.y),width:JI.Y_LABEL_MIN_WIDTH,height:Math.abs(c.y-I.y),style:{overflow:"visible"},children:V.jsx("div",{style:{...o,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:m})})]},s.id)}),Array.from(n.entries()).map(([s,r])=>V.jsxs("g",{children:[V.jsx("line",{x1:r.x-JI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+JI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH}),V.jsx("line",{x1:r.x,y1:r.y-JI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+JI.ANCHOR_MARKER_SIZE,stroke:Xf.OFFSET_LINE,strokeWidth:JI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},a1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=t.filter(h=>WQA(h)),s=t.filter(h=>Yx(h)),r=t.filter(h=>hAe(h)),a=A.map(h=>Yx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Yx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!wl(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),B=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),C=[...c,...B];if(C.length===0)return null;const l=a.length===0,Q=C.filter(h=>h.type==="component"?l||a.includes(h.component.pcb_component_id):l||g.has(h.group.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return V.jsx(ZQA,{targets:E,transform:e,containerWidth:i,containerHeight:o})},g1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=t.filter(h=>hAe(h)),s=t.filter(h=>Yx(h)),r=A.map(h=>Yx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Yx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=n.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!wl(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const c=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),B=n.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.anchor_position)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),C=[...c,...B];if(C.length===0)return null;const l=r.length===0,Q=C.filter(h=>h.type==="component"?l||r.includes(h.component.pcb_component_id):l||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.anchor_position?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.anchor_position,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return V.jsx(ZQA,{targets:E,transform:e,containerWidth:i,containerHeight:o})},I1t=(t,A)=>{const e=t.pcb_component_id,i=A.filter(o=>(o.type==="pcb_smtpad"||o.type==="pcb_plated_hole")&&o.pcb_component_id===e||o.type==="pcb_hole"&&o.pcb_component_id===e);return i.length===0?qQA([t]):qQA(i)},c1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=new Map;for(const r of A)Yx(r._parent_pcb_component)&&n.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Yx(r._element)&&n.set(r._element.pcb_component_id,r._element);if(n.size===0)return null;const s=[];for(const r of n.values()){const a=I1t(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,I=g?hS(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:I})}return s.length===0?null:V.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:o,overflow:"hidden",pointerEvents:"none",zIndex:gI.dimensionOverlay},children:V.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:o,children:s.map(({component:r,bbox:a,group:g})=>{const I=ae(e,{x:a.minX,y:a.maxY}),c=ae(e,{x:a.maxX,y:a.minY}),B={x:Math.min(I.x,c.x),y:Math.min(I.y,c.y),width:Math.abs(c.x-I.x),height:Math.abs(c.y-I.y)},C=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},l=ae(e,C);return V.jsxs("g",{children:[V.jsx("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),V.jsx("line",{x1:l.x-6,y1:l.y,x2:l.x+6,y2:l.y,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("line",{x1:l.x,y1:l.y-6,x2:l.x,y2:l.y+6,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),V.jsx("circle",{cx:l.x,cy:l.y,r:JI.COMPONENT_MARKER_RADIUS,fill:Xf.COMPONENT_MARKER_FILL,stroke:Xf.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},B1t=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:o})=>{const n=t.filter(C=>r1t(C)),s=t.filter(C=>WQA(C)),r=A.map(C=>WQA(C._element)?C._element.pcb_board_id:null).filter(C=>!!C);if(!wl(C=>C.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(C=>{const l=C.pcb_panel_id,Q=C.position_mode;if(!l||Q!=="relative_to_panel_anchor")return null;const E=n.find(h=>h.pcb_panel_id===l);return E?{board:C,panel:E,type:"board"}:null}).filter(C=>!!C);if(g.length===0)return null;const I=r.length===0,c=g.filter(C=>I||r.includes(C.board.pcb_board_id));if(c.length===0)return null;const B=c.map(C=>C.board.center?{id:`${C.panel.pcb_panel_id}-${C.board.pcb_board_id}-${C.type}`,anchor:C.panel.center,anchor_id:C.panel.pcb_panel_id,target:C.board.center,type:"board",display_offset_x:C.board.display_offset_x,display_offset_y:C.board.display_offset_y}:null).filter(C=>!!C);return V.jsx(ZQA,{targets:B,transform:e,containerWidth:i,containerHeight:o})},tW=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,o=t[0].y;for(const n of t)n.x<A&&(A=n.x),n.y<e&&(e=n.y),n.x>i&&(i=n.x),n.y>o&&(o=n.y);return{center:{x:(A+i)/2,y:(e+o)/2},width:i-A,height:o-e}},uAe=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,o=A.length-1;i<A.length;o=i++){const n=A[i].x,s=A[i].y,r=A[o].x,a=A[o].y;s>t.y!=a>t.y&&t.x<(r-n)*(t.y-s)/(a-s||Number.EPSILON)+n&&(e=!e)}return e},C1t=(t,A,e)=>{const i=[];for(const o of t){if(!o._element)continue;if("x1"in o&&o._element?.type==="pcb_trace"){const r=oh({x:A.x,y:A.y},{x:o.x1,y:o.y1},{x:o.x2,y:o.y2}),a=o.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(o);continue}if(o.pcb_drawing_type==="polygon"){const r=o.points.map(g=>({x:ge.parse(g.x),y:ge.parse(g.y)})),a=tW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;uAe(A,r)&&i.push(o);continue}if(o.pcb_drawing_type==="polygon_with_arcs"){const r=o.brep_shape.outer_ring.vertices.map(g=>({x:ge.parse(g.x),y:ge.parse(g.y)})),a=tW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;uAe(A,r)&&i.push(o);continue}if(!("x"in o&&"y"in o))continue;let n=0,s=0;if("w"in o&&"h"in o)n=o.w,s=o.h;else if("r"in o)n=o.r*2,s=o.r*2;else if("rX"in o&&"rY"in o)n=o.rX*2,s=o.rY*2;else continue;Math.abs(o.x-A.x)<n/2&&Math.abs(o.y-A.y)<s/2&&i.push(o)}return i},l1t=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:o})=>{const[n,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:I,height:c}]=jL(),B=AA.useMemo(()=>{const l=[];for(const Q of n){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let E=null,h=0,u=0;if(Q.pcb_drawing_type==="polygon"){const b=tW(Q.points);if(!b)continue;E=b.center,h=b.width,u=b.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const b=Q.brep_shape.outer_ring.vertices.map(x=>({x:x.x,y:x.y})),m=tW(b);if(!m)continue;E=m.center,h=m.width,u=m.height}else"x"in Q&&"y"in Q&&(E={x:Q.x,y:Q.y},h="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!E)continue;const d=ae(e,E),f={w:h*e.a,h:u*e.a},D=l.filter(b=>d.x===b.screen_x&&d.y===b.screen_y&&f.w===b.screen_w&&f.h===b.screen_h).length;l.push({...Q,x:E.x,y:E.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:D})}return l},[n,e]),C=(l,Q,E,h)=>{a({x:l,y:Q});const u=ae(Z0(E),{x:l,y:Q}),d=C1t(h,u,E);$vt(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(n.map(f=>f._pcb_drawing_object_id)))||(s(d),o(d))};return V.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:l=>{if(e){const Q=l.currentTarget.getBoundingClientRect(),E=l.clientX-Q.left,h=l.clientY-Q.top;C(E,h,e,i)}},onTouchStart:l=>{if(e){const Q=l.touches[0],E=l.currentTarget.getBoundingClientRect(),h=Q.clientX-E.left,u=Q.clientY-E.top;C(h,u,e,i)}},children:[A,V.jsx(s1t,{elements:t,mousePos:r,highlightedPrimitives:B}),e&&V.jsxs(V.Fragment,{children:[V.jsx(a1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),V.jsx(g1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),V.jsx(c1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),V.jsx(B1t,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c})]})]})},dAe=["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)"],Q1t=({children:t,transform:A=lg(),elements:e=[],hoveredComponentIds:i=[]})=>{const[o,{width:n,height:s}]=jL(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:I}=wl(c=>({is_showing_pcb_groups:c.is_showing_pcb_groups,pcb_group_view_mode:c.pcb_group_view_mode,is_showing_group_anchor_offsets:c.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const c=r.current;if(!c||!n||!s)return;c.width=n,c.height=s;const B=c.getContext("2d");if(!B||(B.clearRect(0,0,n,s),!a))return;const C=e.filter(b=>b.type==="pcb_group"),l=e.filter(b=>b.type==="pcb_component"),Q=e.filter(b=>b.type==="source_group"),E=new Map(Q.map(b=>[b.source_group_id,b])),h=C.filter(b=>{if(g==="all")return!0;if(!b.source_group_id)return!1;const m=E.get(b.source_group_id);return m?m.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(b=>{const m=b;if(m.parent_source_group_id){const x=u.get(m.parent_source_group_id)||[];x.push(b.source_group_id),u.set(m.parent_source_group_id,x)}});const d=b=>{const m=[],x=u.get(b)||[];for(const F of x)m.push(F),m.push(...d(F));return m},f=b=>{const m=Q.find(x=>x.source_group_id===b);return m?.parent_source_group_id?1+f(m.parent_source_group_id):0},D=new Set;if(i.length>0)for(const b of l){if(!i.includes(b.pcb_component_id))continue;const m=b.positioned_relative_to_pcb_group_id??b.pcb_group_id;m&&D.add(m)}h.forEach((b,m)=>{let x=l.filter(HA=>HA.pcb_group_id===b.pcb_group_id);if(b.source_group_id){const HA=d(b.source_group_id),VA=C.filter(GA=>GA.source_group_id&&HA.includes(GA.source_group_id));for(const GA of VA){const DA=l.filter(vA=>vA.pcb_group_id===GA.pcb_group_id);x=[...x,...DA]}}let F,k,v,M,H=!1;if(b.center&&b.width&&b.height){H=!0;const HA=b.width/2,VA=b.height/2;F=b.center.x-HA,v=b.center.x+HA,k=b.center.y-VA,M=b.center.y+VA}else if(x.length===0||(F=1/0,k=1/0,v=-1/0,M=-1/0,x.forEach(HA=>{if(HA.center&&typeof HA.width=="number"&&typeof HA.height=="number"){const VA=HA.center.x-HA.width/2,GA=HA.center.x+HA.width/2,DA=HA.center.y+HA.height/2,vA=HA.center.y-HA.height/2;F=Math.min(F,VA),v=Math.max(v,GA),k=Math.min(k,vA),M=Math.max(M,DA)}}),F===1/0||v===-1/0))return;const q=b.source_group_id?f(b.source_group_id):0,K=b.source_group_id?d(b.source_group_id).length>0:!1;if(!H){const GA=1+(K?.5:0);F-=GA,v+=GA,k-=GA,M+=GA}const O=ae(A,{x:F,y:M}),W=ae(A,{x:v,y:M}),$=ae(A,{x:F,y:k}),oA=ae(A,{x:v,y:k}),IA=dAe[m%dAe.length];B.strokeStyle=IA,B.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),sA=Math.max(2,Math.min(6,4*Math.abs(A.a))),dA=tA*(K?1.3:1),SA=sA;B.setLineDash([dA,SA]),B.beginPath(),B.moveTo(O.x,O.y),B.lineTo(W.x,W.y),B.lineTo(oA.x,oA.y),B.lineTo($.x,$.y),B.closePath(),B.stroke();const RA=Math.max(8,Math.min(12,10*Math.abs(A.a))),NA=q==0||q==1?0:q*.11,qA=RA*(1-NA),BA=4,fA=b.name||`Group ${m+1}`;B.font=`${qA}px sans-serif`,B.setLineDash([]);const TA=B.measureText(fA).width+BA*2,ee=qA+BA*2,ce=O.x-5,yA=O.y-5,OA=3;if(B.fillStyle="rgba(0, 0, 0, 0.8)",B.beginPath(),B.roundRect(ce,yA-ee,TA,ee,OA),B.fill(),B.fillStyle=IA,B.textAlign="left",B.textBaseline="middle",B.fillText(fA,ce+BA,yA-ee/2),I&&D.has(b.pcb_group_id)&&!!b.anchor_position&&b.anchor_position){const HA=Array.isArray(b.anchor_position)?{x:b.anchor_position[0]??0,y:b.anchor_position[1]??0}:{x:b.anchor_position.x,y:b.anchor_position.y},VA=ae(A,HA);B.strokeStyle="white",B.lineWidth=1.5,B.setLineDash([]);const GA=Math.max(4,Math.min(8,6*Math.abs(A.a)));B.beginPath(),B.moveTo(VA.x-GA,VA.y),B.lineTo(VA.x+GA,VA.y),B.stroke(),B.beginPath(),B.moveTo(VA.x,VA.y-GA),B.lineTo(VA.x,VA.y+GA),B.stroke()}})},[e,A,n,s,a,g,I,i]),V.jsxs("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:[t,V.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:gI.pcbGroupOverlay,display:a?"block":"none"}})]})},E1t=({transform:t,soup:A,children:e})=>{const i=wl(r=>r.is_showing_rats_nest),{netMap:o,idToNetMap:n}=AA.useMemo(()=>iAe(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=B=>{const C=hS(A)[B.replace(/_\d+$/,"")].get(B);return C&&"x"in C&&"y"in C?{x:C.x,y:C.y}:null},a=(B,C)=>{const l=o[C]||[];let Q=null,E=1/0;return l.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((B.x-u.x)**2+(B.y-u.y)**2);d<E&&d>0&&(E=d,Q=u)}}),Q},g=hS(A).pcb_port.list(),I=hS(A).source_trace.list(),c=[];return g.forEach((B,C)=>{const l=n[B.pcb_port_id];let Q=!1;for(const u of I)u.connected_source_port_ids.includes(B.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!l)return;const E={x:B.x,y:B.y},h=a(E,l);h&&c.push({key:`${B.pcb_port_id}-${C}`,startPoint:E,endPoint:h,isInNet:Q})}),c},[A,o,n,i]);return!A||!i?e:(t||(t=lg()),V.jsxs("div",{style:{position:"relative"},children:[e,V.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:gI.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:I})=>{const c=ae(t,a),B=ae(t,g);return V.jsx("line",{x1:c.x,y1:c.y,x2:B.x,y2:B.y,stroke:"white",strokeWidth:"1",strokeDasharray:I?"6,6":void 0},r)})})]}))},h1t={version:"1.11.294"},Jx=(t,A)=>{const e=wl(i=>i.is_mouse_over_container);AA.useEffect(()=>{if(!t||typeof A!="function")return;const i=o=>{const n=t.split("+"),s=n.includes("ctrl"),r=n.includes("shift"),a=n.includes("alt"),g=n.includes("meta"),I=n[n.length-1];e&&(!s||o.ctrlKey)&&(!r||o.shiftKey)&&(!a||o.altKey)&&(!g||o.metaKey)&&o.key.toLowerCase()===I.toLowerCase()&&(o.preventDefault(),A())};return window.addEventListener("keydown",i),()=>{window.removeEventListener("keydown",i)}},[t,A])},u1t=()=>{const[t,A]=AA.useState(!1);return AA.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},d1t=({name:t,selected:A,onClick:e})=>V.jsxs("div",{className:f_`
5385
5385
  margin-top: 2px;
5386
5386
  padding: 4px;
5387
5387
  padding-left: 8px;
@@ -5598,7 +5598,7 @@ test("${g} should solve problem correctly", () => {
5598
5598
  // Add more specific assertions based on expected output
5599
5599
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5600
5600
  })
5601
- `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),C=document.createElement("a");C.href=B,C.download=`${g}.test.ts`,C.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return V.jsxs("div",{className:`relative ${A}`,ref:o,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&V.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:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},FAe=t=>t.activeSubSolver?[t,...FAe(t.activeSubSolver)]:[t],O2t=({solver:t})=>{const A=FAe(t);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>V.jsxs("div",{className:"flex items-center",children:[i>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(P2t,{solver:e})]},e.constructor.name))})},W2t=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const C=t.getCurrentPhase!==void 0,l=C?t.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(O2t,{solver:t})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),V.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),V.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),V.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,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"}),C&&V.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),l&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:l})]}),t.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Z2t=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},V2t=(t,A)=>{const i=t.pipelineDef[A].solverName,o=Z2t(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],C=B?t.firstIterationOfPhase?.[B.solverName]:void 0;C!==void 0&&s!==null?a=C-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},j2t=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${A[t]}`,children:t})},z2t=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},X2t=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),$2t=({stats:t})=>{if(!t||Object.keys(t).length===0)return V.jsx("span",{children:"-"});const A=Object.entries(t),e=X2t(t);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),V.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>V.jsxs("div",{children:[i,": ",String(o)]},i))})]})},tEA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(tEA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=tEA(i));return A},AUt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=tEA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},eUt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>V2t(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):AUt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:i.map(r=>V.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>o(r.name),disabled:r.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 ${r.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(j2t,{status:r.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(z2t,{progress:r.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx($2t,{stats:r.stats})}),V.jsx("td",{className:"px-4 py-2",children:r.solverInstance?V.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})}),V.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},tUt=class extends zi.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 iUt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,C=r-c,l=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${C} ${l} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>V.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>V.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>V.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var oUt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=AA.useReducer(I=>I+1,0),s=AA.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return V.jsxs("div",{children:[V.jsx(W2t,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(tUt,{fallback:V.jsx(iUt,{graphics:s}),children:V.jsx(q2t,{graphics:s})}),a&&V.jsx(eUt,{solver:t,onStepUntilPhase:g})]})};const nUt=()=>{AA.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},sUt=t=>t.toLowerCase().includes("pack")?J0t:t.toLowerCase().includes("rout")?W0t:R0t,rUt=({solverEvents:t=[]})=>{const[A,e]=AA.useState(null);nUt();const i=AA.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=AA.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=AA.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=siA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(siA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.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."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=sUt(a.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?V.jsx(xm,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:V.jsx(oUt,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&V.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},RAe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{AA.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{HJ.captureException(i)}catch{}}},[t,A]),AA.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{HJ.captureException(o,{error_type:i.type})}catch{}}},[e])},NAe="0.0.1444",aUt={version:NAe},iEA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},oEA=new Map,rW=t=>{const A=oEA.get(t);return A?Object.fromEntries(Object.entries(A.stores).map(([e,i])=>[e,i.getState()])):{}},gUt=(t,A,e)=>{if(t===void 0)return{type:"untracked",connection:A.connect(e)};const i=oEA.get(e.name);if(i)return{type:"tracked",store:t,...i};const o={connection:A.connect(e),stores:{}};return oEA.set(e.name,o),{type:"tracked",store:t,...o}},MAe=(t,A={})=>(e,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(iEA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(iEA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(e,i,o);const{connection:I,...c}=gUt(r,g,a);let B=!0;o.setState=(Q,E,h)=>{const u=e(Q,E);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...rW(a.name),[r]:o.getState()}),u)};const C=(...Q)=>{const E=B;B=!1,e(...Q),B=E},l=t(o.setState,i,o);if(c.type==="untracked"?I?.init(l):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([Q,E])=>[Q,Q===c.store?l:E.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let Q=!1;const E=o.dispatch;o.dispatch=(...h)=>{(iEA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),E(...h)}}return I.subscribe(Q=>{var E;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return nEA(Q.payload,h=>{if(h.type==="__setState"){if(r===void 0){C(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5601
+ `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),C=document.createElement("a");C.href=B,C.download=`${g}.test.ts`,C.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return V.jsxs("div",{className:`relative ${A}`,ref:o,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&V.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:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},FAe=t=>t.activeSubSolver?[t,...FAe(t.activeSubSolver)]:[t],O2t=({solver:t})=>{const A=FAe(t);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>V.jsxs("div",{className:"flex items-center",children:[i>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(P2t,{solver:e})]},e.constructor.name))})},W2t=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const C=t.getCurrentPhase!==void 0,l=C?t.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(O2t,{solver:t})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),V.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),V.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),V.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,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"}),C&&V.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),l&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:l})]}),t.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Z2t=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},V2t=(t,A)=>{const i=t.pipelineDef[A].solverName,o=Z2t(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],C=B?t.firstIterationOfPhase?.[B.solverName]:void 0;C!==void 0&&s!==null?a=C-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},j2t=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${A[t]}`,children:t})},z2t=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},X2t=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),$2t=({stats:t})=>{if(!t||Object.keys(t).length===0)return V.jsx("span",{children:"-"});const A=Object.entries(t),e=X2t(t);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),V.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>V.jsxs("div",{children:[i,": ",String(o)]},i))})]})},tEA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(tEA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=tEA(i));return A},AUt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=tEA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},eUt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>V2t(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):AUt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:i.map(r=>V.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>o(r.name),disabled:r.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 ${r.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(j2t,{status:r.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(z2t,{progress:r.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx($2t,{stats:r.stats})}),V.jsx("td",{className:"px-4 py-2",children:r.solverInstance?V.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})}),V.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},tUt=class extends zi.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 iUt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,C=r-c,l=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${C} ${l} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>V.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>V.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>V.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var oUt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=AA.useReducer(I=>I+1,0),s=AA.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return V.jsxs("div",{children:[V.jsx(W2t,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(tUt,{fallback:V.jsx(iUt,{graphics:s}),children:V.jsx(q2t,{graphics:s})}),a&&V.jsx(eUt,{solver:t,onStepUntilPhase:g})]})};const nUt=()=>{AA.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},sUt=t=>t.toLowerCase().includes("pack")?J0t:t.toLowerCase().includes("rout")?W0t:R0t,rUt=({solverEvents:t=[]})=>{const[A,e]=AA.useState(null);nUt();const i=AA.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=AA.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=AA.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=siA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(siA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.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."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=sUt(a.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?V.jsx(xm,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:V.jsx(oUt,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&V.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},RAe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{AA.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{HJ.captureException(i)}catch{}}},[t,A]),AA.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{HJ.captureException(o,{error_type:i.type})}catch{}}},[e])},NAe="0.0.1445",aUt={version:NAe},iEA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},oEA=new Map,rW=t=>{const A=oEA.get(t);return A?Object.fromEntries(Object.entries(A.stores).map(([e,i])=>[e,i.getState()])):{}},gUt=(t,A,e)=>{if(t===void 0)return{type:"untracked",connection:A.connect(e)};const i=oEA.get(e.name);if(i)return{type:"tracked",store:t,...i};const o={connection:A.connect(e),stores:{}};return oEA.set(e.name,o),{type:"tracked",store:t,...o}},MAe=(t,A={})=>(e,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(iEA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(iEA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(e,i,o);const{connection:I,...c}=gUt(r,g,a);let B=!0;o.setState=(Q,E,h)=>{const u=e(Q,E);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...rW(a.name),[r]:o.getState()}),u)};const C=(...Q)=>{const E=B;B=!1,e(...Q),B=E},l=t(o.setState,i,o);if(c.type==="untracked"?I?.init(l):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([Q,E])=>[Q,Q===c.store?l:E.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let Q=!1;const E=o.dispatch;o.dispatch=(...h)=>{(iEA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),E(...h)}}return I.subscribe(Q=>{var E;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return nEA(Q.payload,h=>{if(h.type==="__setState"){if(r===void 0){C(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5602
5602
  [zustand devtools middleware] Unsupported __setState action format.
5603
5603
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5604
5604
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
@@ -5385,7 +5385,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function lee(t,A,e){if(!A||!e)retu
5385
5385
  transition: opacity 0.2s;
5386
5386
  margin-bottom: 10px;
5387
5387
  color: red;
5388
- `,NUt=({children:t,transform:A=Bg(),elements:e})=>{const i=z.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=wC(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return O.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),O.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,I)=>{const{pcb_port_ids:c,pcb_trace_id:B}=g,l=c?.[0]?a.get(c[0]):void 0,C=c?.[1]?a.get(c[1]):void 0,Q=e?SS(e).pcb_trace.get(B):void 0,E=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,h=o===E;if(l&&C){const u=ge(A,{x:l.x,y:l.y}),d=ge(A,{x:C.x,y:C.y}),f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),w={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(w.x)||isNaN(w.y))return null;const S=qEA(w,i);return O.jsxs(z.Fragment,{children:[O.jsx(FUt,{screenPort1:u,screenPort2:d,errorCenter:w,canLineBeDrawn:f,isHighlighted:h}),O.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:cI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const x=D.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="1")}},onMouseLeave:D=>{if(!h){const x=D.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="0")}}}}),O.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:S.left,top:S.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:O.jsx("div",{className:`error-message ${PEA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}if(Q?.route&&(n||h)){const u=Q.route.map(S=>ge(A,{x:S.x,y:S.y}));if(u.some(S=>isNaN(S.x)||isNaN(S.y)))return null;const d=Math.floor(u.length/2),f=u[d],w=qEA(f,i);return O.jsxs(z.Fragment,{children:[O.jsx(RUt,{points:u,errorCenter:f,isHighlighted:h}),O.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:cI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const D=S.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="1")}},onMouseLeave:S=>{if(!h){const D=S.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="0")}}}}),O.jsx("div",{style:{position:"absolute",zIndex:h?cI.errorOverlay+10:cI.errorOverlay+1,left:w.left,top:w.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:O.jsx("div",{className:`error-message ${PEA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}return null}),r.map((g,I)=>{const c=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!c)return null;const B=e?.filter(Q=>Q.type==="source_component"&&Q.name===c||Q.type==="pcb_component"&&e?.find(E=>E.type==="source_component"&&E.source_component_id===Q.source_component_id&&E.name===c))||[],l=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===l;return!C&&!n?null:B.map((Q,E)=>{let h={x:0,y:0};if(Q.type==="pcb_component")h=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const F=e?.find(k=>k.type==="pcb_component"&&k.source_component_id===Q.source_component_id);F&&F.type==="pcb_component"&&(h=F.center||{x:0,y:0})}const u=ge(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),x=qEA(u,i);return O.jsxs(z.Fragment,{children:[O.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:cI.errorOverlay},width:"100%",height:"100%",children:C?O.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):O.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),O.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:cI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:F=>{const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="1")}},onMouseLeave:F=>{if(!C){const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="0")}}}}),O.jsx("div",{style:{position:"absolute",zIndex:C?cI.errorOverlay+20:cI.errorOverlay+10,left:x.left,top:x.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:O.jsx("div",{className:`error-message ${PEA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${l}_${E}`)})})]})};function MUt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function _Ut({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=SS(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function vUt(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,I)=>{const c=g._element.trace_length;return I._element.trace_length<c?I:g},n[0]);return[...s,a]}return A}var UUt={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},LUt=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},HUt={top:"red",bottom:"aqua"},YUt=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=z.useState(!1),o=t._element;z.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],I=t.same_space_index??0,c=26,B=HUt[t?._element?.layer]??"red";let l=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?l=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(l=o.ccw_rotation??0),o.type==="pcb_trace"){const E=_Ut({primitiveElement:o,elements:e});if(!E)return null;const h=A.y-35;return O.jsx("div",{style:{zIndex:cI.elementOverlay,position:"absolute",left:A.x,top:h,color:B,pointerEvents:"none",transform:"translateX(-50%)"},children:O.jsx("div",{style:{backgroundColor:"#f2efcc",color:E.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:E.text})})}const C=LUt(t);return C.trim().length===0?null:O.jsx("div",{style:{zIndex:cI.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:B,transform:`rotate(${-l}deg)`,transformOrigin:"center center"},children:O.jsx("div",{style:{width:i?`calc(100% + ${c*2*I}px)`:"100%",height:i?`calc(100% + ${c*2*I}px)`:"100%",marginLeft:i?`${-c*I}px`:0,marginTop:i?`${-c*I}px`:0,border:`1px solid ${B}`,opacity:i||I===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:O.jsx("div",{style:{position:"absolute",bottom:g+20+c*I,marginRight:i?`${-c*I}px`:0,marginBottom:i?0:-c*I,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(${l}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},JUt=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=wC(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=vUt({primitives:s,is_showing_multiple_traces_length:n,elements:e}),O.jsx("div",{style:UUt,children:!i&&s.map((r,a)=>O.jsx(YUt,{primitive:r,mousePos:A,elements:e},a))})},Wx=t=>t?.type==="pcb_component",Mee=t=>t?.type==="pcb_group",TUt=t=>t?.type==="pcb_panel",OEA=t=>t?.type==="pcb_board",KI={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},r0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},WEA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:r0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:KI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=ge(A,s.anchor);o.set(s.anchor_id,r)}}),O.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:cI.dimensionOverlay},children:O.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,I=o.get(a),c=ge(A,g),B=g.x-r.x,l=g.y-r.y,C=Math.abs(c.x-I.x),Q=Math.abs(c.y-I.y),E=c.y<I.y,h=c.x>I.x,u=E?KI.LABEL_OFFSET_ABOVE:KI.LABEL_OFFSET_BELOW,d=h?KI.LABEL_OFFSET_RIGHT:KI.LABEL_OFFSET_LEFT,f=C>KI.MIN_LINE_LENGTH_FOR_LABEL,w=Q>KI.MIN_LINE_LENGTH_FOR_LABEL,S=`${s.display_offset_x??B.toFixed(2)}mm`,D=`${s.display_offset_y??l.toFixed(2)}mm`;return O.jsxs("g",{children:[O.jsx("line",{x1:I.x,y1:I.y,x2:c.x,y2:I.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.LINE_STROKE_WIDTH,strokeDasharray:KI.LINE_DASH_PATTERN}),O.jsx("line",{x1:c.x,y1:I.y,x2:c.x,y2:c.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.LINE_STROKE_WIDTH,strokeDasharray:KI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?O.jsx("circle",{cx:c.x,cy:c.y,r:KI.COMPONENT_MARKER_RADIUS,fill:r0.COMPONENT_MARKER_FILL,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1}):O.jsxs(O.Fragment,{children:[O.jsx("line",{x1:c.x-KI.ANCHOR_MARKER_SIZE,y1:c.y,x2:c.x+KI.ANCHOR_MARKER_SIZE,y2:c.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH}),O.jsx("line",{x1:c.x,y1:c.y-KI.ANCHOR_MARKER_SIZE,x2:c.x,y2:c.y+KI.ANCHOR_MARKER_SIZE,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&O.jsx("foreignObject",{x:Math.min(I.x,c.x),y:I.y+u,width:Math.abs(c.x-I.x),height:20,style:{overflow:"visible"},children:O.jsx("div",{style:{...n,textAlign:"center"},children:S})}),w&&O.jsx("foreignObject",{x:c.x+d,y:Math.min(I.y,c.y),width:KI.Y_LABEL_MIN_WIDTH,height:Math.abs(c.y-I.y),style:{overflow:"visible"},children:O.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>O.jsxs("g",{children:[O.jsx("line",{x1:r.x-KI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+KI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH}),O.jsx("line",{x1:r.x,y1:r.y-KI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+KI.ANCHOR_MARKER_SIZE,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},KUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(h=>OEA(h)),s=t.filter(h=>Wx(h)),r=t.filter(h=>Mee(h)),a=A.map(h=>Wx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Wx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!wC(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),B=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=a.length===0,Q=l.filter(h=>h.type==="component"?C||a.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return O.jsx(WEA,{targets:E,transform:e,containerWidth:i,containerHeight:n})},qUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(h=>Mee(h)),s=t.filter(h=>Wx(h)),r=A.map(h=>Wx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Wx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=o.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!wC(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const c=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),B=o.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.center)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=r.length===0,Q=l.filter(h=>h.type==="component"?C||r.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.center?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.center,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return O.jsx(WEA,{targets:E,transform:e,containerWidth:i,containerHeight:n})},PUt=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?KEA([t]):KEA(i)},OUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Wx(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Wx(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=PUt(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,I=g?SS(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:I})}return s.length===0?null:O.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:cI.dimensionOverlay},children:O.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const I=ge(e,{x:a.minX,y:a.maxY}),c=ge(e,{x:a.maxX,y:a.minY}),B={x:Math.min(I.x,c.x),y:Math.min(I.y,c.y),width:Math.abs(c.x-I.x),height:Math.abs(c.y-I.y)},l=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=ge(e,l);return O.jsxs("g",{children:[O.jsx("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),O.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),O.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),O.jsx("circle",{cx:C.x,cy:C.y,r:KI.COMPONENT_MARKER_RADIUS,fill:r0.COMPONENT_MARKER_FILL,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},WUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(l=>TUt(l)),s=t.filter(l=>OEA(l)),r=A.map(l=>OEA(l._element)?l._element.pcb_board_id:null).filter(l=>!!l);if(!wC(l=>l.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(l=>{const C=l.pcb_panel_id,Q=l.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const E=o.find(h=>h.pcb_panel_id===C);return E?{board:l,panel:E,type:"board"}:null}).filter(l=>!!l);if(g.length===0)return null;const I=r.length===0,c=g.filter(l=>I||r.includes(l.board.pcb_board_id));if(c.length===0)return null;const B=c.map(l=>l.board.center?{id:`${l.panel.pcb_panel_id}-${l.board.pcb_board_id}-${l.type}`,anchor:l.panel.center,anchor_id:l.panel.pcb_panel_id,target:l.board.center,type:"board",display_offset_x:l.board.display_offset_x,display_offset_y:l.board.display_offset_y}:null).filter(l=>!!l);return O.jsx(WEA,{targets:B,transform:e,containerWidth:i,containerHeight:n})},YW=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},_ee=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},ZUt=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=Ah({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Ie.parse(g.x),y:Ie.parse(g.y)})),a=YW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;_ee(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:Ie.parse(g.x),y:Ie.parse(g.y)})),a=YW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;_ee(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},VUt=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=z.useState([]),[r,a]=z.useState({x:0,y:0}),[g,{width:I,height:c}]=uH(),B=z.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let E=null,h=0,u=0;if(Q.pcb_drawing_type==="polygon"){const S=YW(Q.points);if(!S)continue;E=S.center,h=S.width,u=S.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const S=Q.brep_shape.outer_ring.vertices.map(x=>({x:x.x,y:x.y})),D=YW(S);if(!D)continue;E=D.center,h=D.width,u=D.height}else"x"in Q&&"y"in Q&&(E={x:Q.x,y:Q.y},h="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!E)continue;const d=ge(e,E),f={w:h*e.a,h:u*e.a},w=C.filter(S=>d.x===S.screen_x&&d.y===S.screen_y&&f.w===S.screen_w&&f.h===S.screen_h).length;C.push({...Q,x:E.x,y:E.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:w})}return C},[o,e]),l=(C,Q,E,h)=>{a({x:C,y:Q});const u=ge(X0(E),{x:C,y:Q}),d=ZUt(h,u,E);MUt(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return O.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),E=C.clientX-Q.left,h=C.clientY-Q.top;l(E,h,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],E=C.currentTarget.getBoundingClientRect(),h=Q.clientX-E.left,u=Q.clientY-E.top;l(h,u,e,i)}},children:[A,O.jsx(JUt,{elements:t,mousePos:r,highlightedPrimitives:B}),e&&O.jsxs(O.Fragment,{children:[O.jsx(KUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),O.jsx(qUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),O.jsx(OUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),O.jsx(WUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c})]})]})},vee=["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)"],jUt=({children:t,transform:A=Bg(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=uH(),r=z.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:I}=wC(c=>({is_showing_pcb_groups:c.is_showing_pcb_groups,pcb_group_view_mode:c.pcb_group_view_mode,is_showing_group_anchor_offsets:c.is_showing_group_anchor_offsets}));return z.useEffect(()=>{const c=r.current;if(!c||!o||!s)return;c.width=o,c.height=s;const B=c.getContext("2d");if(!B||(B.clearRect(0,0,o,s),!a))return;const l=e.filter(S=>S.type==="pcb_group"),C=e.filter(S=>S.type==="pcb_component"),Q=e.filter(S=>S.type==="source_group"),E=new Map(Q.map(S=>[S.source_group_id,S])),h=l.filter(S=>{if(g==="all")return!0;if(!S.source_group_id)return!1;const D=E.get(S.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(S=>{const D=S;if(D.parent_source_group_id){const x=u.get(D.parent_source_group_id)||[];x.push(S.source_group_id),u.set(D.parent_source_group_id,x)}});const d=S=>{const D=[],x=u.get(S)||[];for(const F of x)D.push(F),D.push(...d(F));return D},f=S=>{const D=Q.find(x=>x.source_group_id===S);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},w=new Set;if(i.length>0)for(const S of C){if(!i.includes(S.pcb_component_id))continue;const D=S.positioned_relative_to_pcb_group_id??S.pcb_group_id;D&&w.add(D)}h.forEach((S,D)=>{let x=C.filter(LA=>LA.pcb_group_id===S.pcb_group_id);if(S.source_group_id){const LA=d(S.source_group_id),VA=l.filter(RA=>RA.source_group_id&&LA.includes(RA.source_group_id));for(const RA of VA){const SA=C.filter(vA=>vA.pcb_group_id===RA.pcb_group_id);x=[...x,...SA]}}let F,k,v,M,L=!1;if(S.center&&S.width&&S.height){L=!0;const LA=S.width/2,VA=S.height/2;F=S.center.x-LA,v=S.center.x+LA,k=S.center.y-VA,M=S.center.y+VA}else if(x.length===0||(F=1/0,k=1/0,v=-1/0,M=-1/0,x.forEach(LA=>{if(LA.center&&typeof LA.width=="number"&&typeof LA.height=="number"){const VA=LA.center.x-LA.width/2,RA=LA.center.x+LA.width/2,SA=LA.center.y+LA.height/2,vA=LA.center.y-LA.height/2;F=Math.min(F,VA),v=Math.max(v,RA),k=Math.min(k,vA),M=Math.max(M,SA)}}),F===1/0||v===-1/0))return;const K=S.source_group_id?f(S.source_group_id):0,Y=S.source_group_id?d(S.source_group_id).length>0:!1;if(!L){const RA=1+(Y?.5:0);F-=RA,v+=RA,k-=RA,M+=RA}const W=ge(A,{x:F,y:M}),Z=ge(A,{x:v,y:M}),AA=ge(A,{x:F,y:k}),oA=ge(A,{x:v,y:k}),cA=vee[D%vee.length];B.strokeStyle=cA,B.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),CA=tA*(Y?1.3:1),dA=iA;B.setLineDash([CA,dA]),B.beginPath(),B.moveTo(W.x,W.y),B.lineTo(Z.x,Z.y),B.lineTo(oA.x,oA.y),B.lineTo(AA.x,AA.y),B.closePath(),B.stroke();const bA=Math.max(8,Math.min(12,10*Math.abs(A.a))),GA=K==0||K==1?0:K*.11,YA=bA*(1-GA),gA=4,yA=S.name||`Group ${D+1}`;B.font=`${YA}px sans-serif`,B.setLineDash([]);const KA=B.measureText(yA).width+gA*2,Ae=YA+gA*2,ne=W.x-5,mA=W.y-5,PA=3;if(B.fillStyle="rgba(0, 0, 0, 0.8)",B.beginPath(),B.roundRect(ne,mA-Ae,KA,Ae,PA),B.fill(),B.fillStyle=cA,B.textAlign="left",B.textBaseline="middle",B.fillText(yA,ne+gA,mA-Ae/2),I&&w.has(S.pcb_group_id)&&!!S.anchor_position&&S.anchor_position){const LA=Array.isArray(S.anchor_position)?{x:S.anchor_position[0]??0,y:S.anchor_position[1]??0}:{x:S.anchor_position.x,y:S.anchor_position.y},VA=ge(A,LA);B.strokeStyle="white",B.lineWidth=1.5,B.setLineDash([]);const RA=Math.max(4,Math.min(8,6*Math.abs(A.a)));B.beginPath(),B.moveTo(VA.x-RA,VA.y),B.lineTo(VA.x+RA,VA.y),B.stroke(),B.beginPath(),B.moveTo(VA.x,VA.y-RA),B.lineTo(VA.x,VA.y+RA),B.stroke()}})},[e,A,o,s,a,g,I,i]),O.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,O.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:cI.pcbGroupOverlay,display:a?"block":"none"}})]})},zUt=({transform:t,soup:A,children:e})=>{const i=wC(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=z.useMemo(()=>pee(A||[]),[A]),s=z.useMemo(()=>{if(!A||!i)return[];const r=B=>{const l=SS(A)[B.replace(/_\d+$/,"")].get(B);return l&&"x"in l&&"y"in l?{x:l.x,y:l.y}:null},a=(B,l)=>{const C=n[l]||[];let Q=null,E=1/0;return C.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((B.x-u.x)**2+(B.y-u.y)**2);d<E&&d>0&&(E=d,Q=u)}}),Q},g=SS(A).pcb_port.list(),I=SS(A).source_trace.list(),c=[];return g.forEach((B,l)=>{const C=o[B.pcb_port_id];let Q=!1;for(const u of I)u.connected_source_port_ids.includes(B.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const E={x:B.x,y:B.y},h=a(E,C);h&&c.push({key:`${B.pcb_port_id}-${l}`,startPoint:E,endPoint:h,isInNet:Q})}),c},[A,n,o,i]);return!A||!i?e:(t||(t=Bg()),O.jsxs("div",{style:{position:"relative"},children:[e,O.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:cI.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:I})=>{const c=ge(t,a),B=ge(t,g);return O.jsx("line",{x1:c.x,y1:c.y,x2:B.x,y2:B.y,stroke:"white",strokeWidth:"1",strokeDasharray:I?"6,6":void 0},r)})})]}))},XUt={version:"1.11.293"},Zx=(t,A)=>{const e=wC(i=>i.is_mouse_over_container);z.useEffect(()=>{if(!t||typeof A!="function")return;const i=n=>{const o=t.split("+"),s=o.includes("ctrl"),r=o.includes("shift"),a=o.includes("alt"),g=o.includes("meta"),I=o[o.length-1];e&&(!s||n.ctrlKey)&&(!r||n.shiftKey)&&(!a||n.altKey)&&(!g||n.metaKey)&&n.key.toLowerCase()===I.toLowerCase()&&(n.preventDefault(),A())};return window.addEventListener("keydown",i),()=>{window.removeEventListener("keydown",i)}},[t,A])},$Ut=()=>{const[t,A]=z.useState(!1);return z.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},ALt=({name:t,selected:A,onClick:e})=>O.jsxs("div",{className:L_`
5388
+ `,NUt=({children:t,transform:A=Bg(),elements:e})=>{const i=z.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=wC(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return O.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),O.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,I)=>{const{pcb_port_ids:c,pcb_trace_id:B}=g,l=c?.[0]?a.get(c[0]):void 0,C=c?.[1]?a.get(c[1]):void 0,Q=e?SS(e).pcb_trace.get(B):void 0,E=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,h=o===E;if(l&&C){const u=ge(A,{x:l.x,y:l.y}),d=ge(A,{x:C.x,y:C.y}),f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),w={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(w.x)||isNaN(w.y))return null;const S=qEA(w,i);return O.jsxs(z.Fragment,{children:[O.jsx(FUt,{screenPort1:u,screenPort2:d,errorCenter:w,canLineBeDrawn:f,isHighlighted:h}),O.jsx("div",{style:{position:"absolute",left:w.x-15,top:w.y-15,width:30,height:30,zIndex:cI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const x=D.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="1")}},onMouseLeave:D=>{if(!h){const x=D.currentTarget.nextElementSibling;if(x){const F=x.querySelector(".error-message");F&&(F.style.opacity="0")}}}}),O.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:S.left,top:S.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:S.transform},children:O.jsx("div",{className:`error-message ${PEA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}if(Q?.route&&(n||h)){const u=Q.route.map(S=>ge(A,{x:S.x,y:S.y}));if(u.some(S=>isNaN(S.x)||isNaN(S.y)))return null;const d=Math.floor(u.length/2),f=u[d],w=qEA(f,i);return O.jsxs(z.Fragment,{children:[O.jsx(RUt,{points:u,errorCenter:f,isHighlighted:h}),O.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:cI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const D=S.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="1")}},onMouseLeave:S=>{if(!h){const D=S.currentTarget.nextElementSibling;if(D){const x=D.querySelector(".error-message");x&&(x.style.opacity="0")}}}}),O.jsx("div",{style:{position:"absolute",zIndex:h?cI.errorOverlay+10:cI.errorOverlay+1,left:w.left,top:w.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:O.jsx("div",{className:`error-message ${PEA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},E)}return null}),r.map((g,I)=>{const c=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!c)return null;const B=e?.filter(Q=>Q.type==="source_component"&&Q.name===c||Q.type==="pcb_component"&&e?.find(E=>E.type==="source_component"&&E.source_component_id===Q.source_component_id&&E.name===c))||[],l=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===l;return!C&&!n?null:B.map((Q,E)=>{let h={x:0,y:0};if(Q.type==="pcb_component")h=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const F=e?.find(k=>k.type==="pcb_component"&&k.source_component_id===Q.source_component_id);F&&F.type==="pcb_component"&&(h=F.center||{x:0,y:0})}const u=ge(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),x=qEA(u,i);return O.jsxs(z.Fragment,{children:[O.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:cI.errorOverlay},width:"100%",height:"100%",children:C?O.jsx("polygon",{points:`${u.x},${u.y-D*1.25} ${u.x+D},${u.y} ${u.x},${u.y+D*1.25} ${u.x-D},${u.y}`,fill:"#ff4444"}):O.jsx("circle",{cx:u.x,cy:u.y,r:D,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,D*.15):Math.max(1,D*.1),opacity:1})}),O.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:cI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:F=>{const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="1")}},onMouseLeave:F=>{if(!C){const k=F.currentTarget.nextElementSibling;if(k){const v=k.querySelector(".error-message");v&&(v.style.opacity="0")}}}}),O.jsx("div",{style:{position:"absolute",zIndex:C?cI.errorOverlay+20:cI.errorOverlay+10,left:x.left,top:x.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:O.jsx("div",{className:`error-message ${PEA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${l}_${E}`)})})]})};function MUt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function _Ut({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=SS(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function vUt(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,I)=>{const c=g._element.trace_length;return I._element.trace_length<c?I:g},n[0]);return[...s,a]}return A}var UUt={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},LUt=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},HUt={top:"red",bottom:"aqua"},YUt=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=z.useState(!1),o=t._element;z.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],I=t.same_space_index??0,c=26,B=HUt[t?._element?.layer]??"red";let l=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?l=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(l=o.ccw_rotation??0),o.type==="pcb_trace"){const E=_Ut({primitiveElement:o,elements:e});if(!E)return null;const h=A.y-35;return O.jsx("div",{style:{zIndex:cI.elementOverlay,position:"absolute",left:A.x,top:h,color:B,pointerEvents:"none",transform:"translateX(-50%)"},children:O.jsx("div",{style:{backgroundColor:"#f2efcc",color:E.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:E.text})})}const C=LUt(t);return C.trim().length===0?null:O.jsx("div",{style:{zIndex:cI.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:B,transform:`rotate(${-l}deg)`,transformOrigin:"center center"},children:O.jsx("div",{style:{width:i?`calc(100% + ${c*2*I}px)`:"100%",height:i?`calc(100% + ${c*2*I}px)`:"100%",marginLeft:i?`${-c*I}px`:0,marginTop:i?`${-c*I}px`:0,border:`1px solid ${B}`,opacity:i||I===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:O.jsx("div",{style:{position:"absolute",bottom:g+20+c*I,marginRight:i?`${-c*I}px`:0,marginBottom:i?0:-c*I,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(${l}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},JUt=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=wC(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=vUt({primitives:s,is_showing_multiple_traces_length:n,elements:e}),O.jsx("div",{style:UUt,children:!i&&s.map((r,a)=>O.jsx(YUt,{primitive:r,mousePos:A,elements:e},a))})},Wx=t=>t?.type==="pcb_component",Mee=t=>t?.type==="pcb_group",TUt=t=>t?.type==="pcb_panel",OEA=t=>t?.type==="pcb_board",KI={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},r0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},WEA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:r0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:KI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=ge(A,s.anchor);o.set(s.anchor_id,r)}}),O.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:cI.dimensionOverlay},children:O.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,I=o.get(a),c=ge(A,g),B=g.x-r.x,l=g.y-r.y,C=Math.abs(c.x-I.x),Q=Math.abs(c.y-I.y),E=c.y<I.y,h=c.x>I.x,u=E?KI.LABEL_OFFSET_ABOVE:KI.LABEL_OFFSET_BELOW,d=h?KI.LABEL_OFFSET_RIGHT:KI.LABEL_OFFSET_LEFT,f=C>KI.MIN_LINE_LENGTH_FOR_LABEL,w=Q>KI.MIN_LINE_LENGTH_FOR_LABEL,S=`${s.display_offset_x??B.toFixed(2)}mm`,D=`${s.display_offset_y??l.toFixed(2)}mm`;return O.jsxs("g",{children:[O.jsx("line",{x1:I.x,y1:I.y,x2:c.x,y2:I.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.LINE_STROKE_WIDTH,strokeDasharray:KI.LINE_DASH_PATTERN}),O.jsx("line",{x1:c.x,y1:I.y,x2:c.x,y2:c.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.LINE_STROKE_WIDTH,strokeDasharray:KI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?O.jsx("circle",{cx:c.x,cy:c.y,r:KI.COMPONENT_MARKER_RADIUS,fill:r0.COMPONENT_MARKER_FILL,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1}):O.jsxs(O.Fragment,{children:[O.jsx("line",{x1:c.x-KI.ANCHOR_MARKER_SIZE,y1:c.y,x2:c.x+KI.ANCHOR_MARKER_SIZE,y2:c.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH}),O.jsx("line",{x1:c.x,y1:c.y-KI.ANCHOR_MARKER_SIZE,x2:c.x,y2:c.y+KI.ANCHOR_MARKER_SIZE,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&O.jsx("foreignObject",{x:Math.min(I.x,c.x),y:I.y+u,width:Math.abs(c.x-I.x),height:20,style:{overflow:"visible"},children:O.jsx("div",{style:{...n,textAlign:"center"},children:S})}),w&&O.jsx("foreignObject",{x:c.x+d,y:Math.min(I.y,c.y),width:KI.Y_LABEL_MIN_WIDTH,height:Math.abs(c.y-I.y),style:{overflow:"visible"},children:O.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>O.jsxs("g",{children:[O.jsx("line",{x1:r.x-KI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+KI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH}),O.jsx("line",{x1:r.x,y1:r.y-KI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+KI.ANCHOR_MARKER_SIZE,stroke:r0.OFFSET_LINE,strokeWidth:KI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},KUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(h=>OEA(h)),s=t.filter(h=>Wx(h)),r=t.filter(h=>Mee(h)),a=A.map(h=>Wx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Wx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!wC(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),B=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=a.length===0,Q=l.filter(h=>h.type==="component"?C||a.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return O.jsx(WEA,{targets:E,transform:e,containerWidth:i,containerHeight:n})},qUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(h=>Mee(h)),s=t.filter(h=>Wx(h)),r=A.map(h=>Wx(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:Wx(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=o.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!wC(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const c=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),B=o.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.anchor_position)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=r.length===0,Q=l.filter(h=>h.type==="component"?C||r.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(Q.length===0)return null;const E=Q.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.anchor_position?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.anchor_position,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return O.jsx(WEA,{targets:E,transform:e,containerWidth:i,containerHeight:n})},PUt=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?KEA([t]):KEA(i)},OUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Wx(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Wx(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=PUt(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,I=g?SS(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:I})}return s.length===0?null:O.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:cI.dimensionOverlay},children:O.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const I=ge(e,{x:a.minX,y:a.maxY}),c=ge(e,{x:a.maxX,y:a.minY}),B={x:Math.min(I.x,c.x),y:Math.min(I.y,c.y),width:Math.abs(c.x-I.x),height:Math.abs(c.y-I.y)},l=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=ge(e,l);return O.jsxs("g",{children:[O.jsx("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),O.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),O.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),O.jsx("circle",{cx:C.x,cy:C.y,r:KI.COMPONENT_MARKER_RADIUS,fill:r0.COMPONENT_MARKER_FILL,stroke:r0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},WUt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(l=>TUt(l)),s=t.filter(l=>OEA(l)),r=A.map(l=>OEA(l._element)?l._element.pcb_board_id:null).filter(l=>!!l);if(!wC(l=>l.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(l=>{const C=l.pcb_panel_id,Q=l.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const E=o.find(h=>h.pcb_panel_id===C);return E?{board:l,panel:E,type:"board"}:null}).filter(l=>!!l);if(g.length===0)return null;const I=r.length===0,c=g.filter(l=>I||r.includes(l.board.pcb_board_id));if(c.length===0)return null;const B=c.map(l=>l.board.center?{id:`${l.panel.pcb_panel_id}-${l.board.pcb_board_id}-${l.type}`,anchor:l.panel.center,anchor_id:l.panel.pcb_panel_id,target:l.board.center,type:"board",display_offset_x:l.board.display_offset_x,display_offset_y:l.board.display_offset_y}:null).filter(l=>!!l);return O.jsx(WEA,{targets:B,transform:e,containerWidth:i,containerHeight:n})},YW=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},_ee=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},ZUt=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=Ah({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:Ie.parse(g.x),y:Ie.parse(g.y)})),a=YW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;_ee(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:Ie.parse(g.x),y:Ie.parse(g.y)})),a=YW(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;_ee(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},VUt=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=z.useState([]),[r,a]=z.useState({x:0,y:0}),[g,{width:I,height:c}]=uH(),B=z.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let E=null,h=0,u=0;if(Q.pcb_drawing_type==="polygon"){const S=YW(Q.points);if(!S)continue;E=S.center,h=S.width,u=S.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const S=Q.brep_shape.outer_ring.vertices.map(x=>({x:x.x,y:x.y})),D=YW(S);if(!D)continue;E=D.center,h=D.width,u=D.height}else"x"in Q&&"y"in Q&&(E={x:Q.x,y:Q.y},h="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!E)continue;const d=ge(e,E),f={w:h*e.a,h:u*e.a},w=C.filter(S=>d.x===S.screen_x&&d.y===S.screen_y&&f.w===S.screen_w&&f.h===S.screen_h).length;C.push({...Q,x:E.x,y:E.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:w})}return C},[o,e]),l=(C,Q,E,h)=>{a({x:C,y:Q});const u=ge(X0(E),{x:C,y:Q}),d=ZUt(h,u,E);MUt(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(o.map(f=>f._pcb_drawing_object_id)))||(s(d),n(d))};return O.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),E=C.clientX-Q.left,h=C.clientY-Q.top;l(E,h,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],E=C.currentTarget.getBoundingClientRect(),h=Q.clientX-E.left,u=Q.clientY-E.top;l(h,u,e,i)}},children:[A,O.jsx(JUt,{elements:t,mousePos:r,highlightedPrimitives:B}),e&&O.jsxs(O.Fragment,{children:[O.jsx(KUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),O.jsx(qUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),O.jsx(OUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c}),O.jsx(WUt,{elements:t,highlightedPrimitives:B,transform:e,containerWidth:I,containerHeight:c})]})]})},vee=["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)"],jUt=({children:t,transform:A=Bg(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=uH(),r=z.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:I}=wC(c=>({is_showing_pcb_groups:c.is_showing_pcb_groups,pcb_group_view_mode:c.pcb_group_view_mode,is_showing_group_anchor_offsets:c.is_showing_group_anchor_offsets}));return z.useEffect(()=>{const c=r.current;if(!c||!o||!s)return;c.width=o,c.height=s;const B=c.getContext("2d");if(!B||(B.clearRect(0,0,o,s),!a))return;const l=e.filter(S=>S.type==="pcb_group"),C=e.filter(S=>S.type==="pcb_component"),Q=e.filter(S=>S.type==="source_group"),E=new Map(Q.map(S=>[S.source_group_id,S])),h=l.filter(S=>{if(g==="all")return!0;if(!S.source_group_id)return!1;const D=E.get(S.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(S=>{const D=S;if(D.parent_source_group_id){const x=u.get(D.parent_source_group_id)||[];x.push(S.source_group_id),u.set(D.parent_source_group_id,x)}});const d=S=>{const D=[],x=u.get(S)||[];for(const F of x)D.push(F),D.push(...d(F));return D},f=S=>{const D=Q.find(x=>x.source_group_id===S);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},w=new Set;if(i.length>0)for(const S of C){if(!i.includes(S.pcb_component_id))continue;const D=S.positioned_relative_to_pcb_group_id??S.pcb_group_id;D&&w.add(D)}h.forEach((S,D)=>{let x=C.filter(LA=>LA.pcb_group_id===S.pcb_group_id);if(S.source_group_id){const LA=d(S.source_group_id),VA=l.filter(RA=>RA.source_group_id&&LA.includes(RA.source_group_id));for(const RA of VA){const SA=C.filter(vA=>vA.pcb_group_id===RA.pcb_group_id);x=[...x,...SA]}}let F,k,v,M,L=!1;if(S.center&&S.width&&S.height){L=!0;const LA=S.width/2,VA=S.height/2;F=S.center.x-LA,v=S.center.x+LA,k=S.center.y-VA,M=S.center.y+VA}else if(x.length===0||(F=1/0,k=1/0,v=-1/0,M=-1/0,x.forEach(LA=>{if(LA.center&&typeof LA.width=="number"&&typeof LA.height=="number"){const VA=LA.center.x-LA.width/2,RA=LA.center.x+LA.width/2,SA=LA.center.y+LA.height/2,vA=LA.center.y-LA.height/2;F=Math.min(F,VA),v=Math.max(v,RA),k=Math.min(k,vA),M=Math.max(M,SA)}}),F===1/0||v===-1/0))return;const K=S.source_group_id?f(S.source_group_id):0,Y=S.source_group_id?d(S.source_group_id).length>0:!1;if(!L){const RA=1+(Y?.5:0);F-=RA,v+=RA,k-=RA,M+=RA}const W=ge(A,{x:F,y:M}),Z=ge(A,{x:v,y:M}),AA=ge(A,{x:F,y:k}),oA=ge(A,{x:v,y:k}),cA=vee[D%vee.length];B.strokeStyle=cA,B.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),iA=Math.max(2,Math.min(6,4*Math.abs(A.a))),CA=tA*(Y?1.3:1),dA=iA;B.setLineDash([CA,dA]),B.beginPath(),B.moveTo(W.x,W.y),B.lineTo(Z.x,Z.y),B.lineTo(oA.x,oA.y),B.lineTo(AA.x,AA.y),B.closePath(),B.stroke();const bA=Math.max(8,Math.min(12,10*Math.abs(A.a))),GA=K==0||K==1?0:K*.11,YA=bA*(1-GA),gA=4,yA=S.name||`Group ${D+1}`;B.font=`${YA}px sans-serif`,B.setLineDash([]);const KA=B.measureText(yA).width+gA*2,Ae=YA+gA*2,ne=W.x-5,mA=W.y-5,PA=3;if(B.fillStyle="rgba(0, 0, 0, 0.8)",B.beginPath(),B.roundRect(ne,mA-Ae,KA,Ae,PA),B.fill(),B.fillStyle=cA,B.textAlign="left",B.textBaseline="middle",B.fillText(yA,ne+gA,mA-Ae/2),I&&w.has(S.pcb_group_id)&&!!S.anchor_position&&S.anchor_position){const LA=Array.isArray(S.anchor_position)?{x:S.anchor_position[0]??0,y:S.anchor_position[1]??0}:{x:S.anchor_position.x,y:S.anchor_position.y},VA=ge(A,LA);B.strokeStyle="white",B.lineWidth=1.5,B.setLineDash([]);const RA=Math.max(4,Math.min(8,6*Math.abs(A.a)));B.beginPath(),B.moveTo(VA.x-RA,VA.y),B.lineTo(VA.x+RA,VA.y),B.stroke(),B.beginPath(),B.moveTo(VA.x,VA.y-RA),B.lineTo(VA.x,VA.y+RA),B.stroke()}})},[e,A,o,s,a,g,I,i]),O.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,O.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:cI.pcbGroupOverlay,display:a?"block":"none"}})]})},zUt=({transform:t,soup:A,children:e})=>{const i=wC(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=z.useMemo(()=>pee(A||[]),[A]),s=z.useMemo(()=>{if(!A||!i)return[];const r=B=>{const l=SS(A)[B.replace(/_\d+$/,"")].get(B);return l&&"x"in l&&"y"in l?{x:l.x,y:l.y}:null},a=(B,l)=>{const C=n[l]||[];let Q=null,E=1/0;return C.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((B.x-u.x)**2+(B.y-u.y)**2);d<E&&d>0&&(E=d,Q=u)}}),Q},g=SS(A).pcb_port.list(),I=SS(A).source_trace.list(),c=[];return g.forEach((B,l)=>{const C=o[B.pcb_port_id];let Q=!1;for(const u of I)u.connected_source_port_ids.includes(B.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const E={x:B.x,y:B.y},h=a(E,C);h&&c.push({key:`${B.pcb_port_id}-${l}`,startPoint:E,endPoint:h,isInNet:Q})}),c},[A,n,o,i]);return!A||!i?e:(t||(t=Bg()),O.jsxs("div",{style:{position:"relative"},children:[e,O.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:cI.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:I})=>{const c=ge(t,a),B=ge(t,g);return O.jsx("line",{x1:c.x,y1:c.y,x2:B.x,y2:B.y,stroke:"white",strokeWidth:"1",strokeDasharray:I?"6,6":void 0},r)})})]}))},XUt={version:"1.11.294"},Zx=(t,A)=>{const e=wC(i=>i.is_mouse_over_container);z.useEffect(()=>{if(!t||typeof A!="function")return;const i=n=>{const o=t.split("+"),s=o.includes("ctrl"),r=o.includes("shift"),a=o.includes("alt"),g=o.includes("meta"),I=o[o.length-1];e&&(!s||n.ctrlKey)&&(!r||n.shiftKey)&&(!a||n.altKey)&&(!g||n.metaKey)&&n.key.toLowerCase()===I.toLowerCase()&&(n.preventDefault(),A())};return window.addEventListener("keydown",i),()=>{window.removeEventListener("keydown",i)}},[t,A])},$Ut=()=>{const[t,A]=z.useState(!1);return z.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},ALt=({name:t,selected:A,onClick:e})=>O.jsxs("div",{className:L_`
5389
5389
  margin-top: 2px;
5390
5390
  padding: 4px;
5391
5391
  padding-left: 8px;
@@ -5602,7 +5602,7 @@ test("${g} should solve problem correctly", () => {
5602
5602
  // Add more specific assertions based on expected output
5603
5603
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5604
5604
  })
5605
- `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return O.jsxs("div",{className:`relative ${A}`,ref:n,children:[O.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&O.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:[O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Oee=t=>t.activeSubSolver?[t,...Oee(t.activeSubSolver)]:[t],bHt=({solver:t})=>{const A=Oee(t);return O.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>O.jsxs("div",{className:"flex items-center",children:[i>0&&O.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),O.jsx(SHt,{solver:e})]},e.constructor.name))})},xHt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=z.useReducer(Q=>!Q,!1),r=z.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},I=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};z.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),z.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const l=t.getCurrentPhase!==void 0,C=l?t.getCurrentPhase():null;return O.jsxs("div",{className:"space-y-2 p-2 border-b",children:[O.jsx("div",{className:"flex items-center",children:O.jsx(bHt,{solver:t})}),O.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[O.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),O.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),O.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),O.jsx("button",{onClick:B,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),l&&O.jsx("button",{onClick:c,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),O.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",O.jsx("span",{className:"font-medium",children:C})]}),t.solved&&O.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&O.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&O.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},kHt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},GHt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=kHt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const B=t.pipelineDef[A+1],l=B?t.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;n==="Completed"?I=1:n==="In Progress"&&o&&(I=o.progress??0);const c=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:o??null}},FHt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return O.jsx("span",{className:`font-medium ${A[t]}`,children:t})},RHt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:O.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),O.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},NHt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),MHt=({stats:t})=>{if(!t||Object.keys(t).length===0)return O.jsx("span",{children:"-"});const A=Object.entries(t),e=NHt(t);return O.jsxs("details",{className:"cursor-pointer",children:[O.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),O.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>O.jsxs("div",{children:[i,": ",String(n)]},i))})]})},ehA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ehA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=ehA(i));return A},_Ht=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=ehA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},vHt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>GHt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):_Ht(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return O.jsxs("div",{className:"border-t border-gray-200",children:[O.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:O.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),O.jsx("div",{className:"overflow-x-auto",children:O.jsxs("table",{className:"w-full text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),O.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",O.jsx("sub",{children:"0"})]}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),O.jsx("tbody",{children:i.map(r=>O.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[O.jsx("td",{className:"px-4 py-2",children:O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),O.jsx("button",{onClick:()=>n(r.name),disabled:r.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 ${r.name} completes`,children:O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})})}),O.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(FHt,{status:r.status})}),O.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(RHt,{progress:r.progress})}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),O.jsx("td",{className:"px-4 py-2 text-gray-500",children:O.jsx(MHt,{stats:r.stats})}),O.jsx("td",{className:"px-4 py-2",children:r.solverInstance?O.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})}),O.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},UHt=class extends Xi.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 LHt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of n){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of o)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return O.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>O.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>O.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),o.map((E,h)=>O.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var HHt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=z.useReducer(I=>I+1,0),s=z.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();o()}};return O.jsxs("div",{children:[O.jsx(xHt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?O.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):O.jsx(UHt,{fallback:O.jsx(LHt,{graphics:s}),children:O.jsx(DHt,{graphics:s})}),a&&O.jsx(vHt,{solver:t,onStepUntilPhase:g})]})};const YHt=()=>{z.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},JHt=t=>t.toLowerCase().includes("pack")?vwt:t.toLowerCase().includes("rout")?Jwt:dwt,THt=({solverEvents:t=[]})=>{const[A,e]=z.useState(null);YHt();const i=z.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=z.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=z.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=AeA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AeA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return t.length===0?O.jsx("div",{className:"rf-p-4",children:O.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:O.jsxs("div",{className:"rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),O.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."})]})})}):O.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[O.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[O.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:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return O.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=JHt(a.solverName);return O.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[O.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),O.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[O.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),O.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),O.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?O.jsx(uy,{fallback:O.jsx("div",{className:"rf-p-4",children:O.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),O.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:O.jsx(HHt,{solver:s.instance})}):O.jsxs("div",{className:"rf-p-4",children:[O.jsxs("div",{className:"rf-mb-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),O.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&O.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:O.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),O.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[O.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:O.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),O.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:O.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):O.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:O.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Wee=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{z.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{s3.captureException(i)}catch{}}},[t,A]),z.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{s3.captureException(n,{error_type:i.type})}catch{}}},[e])},Zee="0.0.1444",KHt={version:Zee},OW=bvA()(xvA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),qHt=t=>{const[A,e]=z.useState([]),[i,n]=z.useState(null),[o,s]=z.useState(""),[r,a]=H_("eval-version-selection",null),g=OW(l=>l.setLastRunEvalVersion),I=OW(l=>l.lastRunEvalVersion);return z.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(l=>l.json()).then(l=>{if(Array.isArray(l?.versions)){let C=[...l.versions];l.tags?.latest&&(n(l.tags.latest),C=C.filter(Q=>Q!==l.tags.latest)),e(C)}}).catch(()=>{})},[t]),z.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:z.useMemo(()=>A.filter(l=>l.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:I,search:o,setSearch:s,selectVersion:l=>{a(l),s("")}}},PHt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=z.useState(""),[s,r]=z.useState("");if(!i)return null;const a=t.filter(c=>c.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),I=c=>{c.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return O.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:O.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[O.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),O.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:c=>r(c.target.value),onKeyDown:I}),O.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(c=>O.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===c?"bg-blue-50":""}`,onClick:()=>o(c),children:c},c)),g&&O.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),O.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},OHt=t=>{const A=z.useRef(null),e=Uc(i=>i.recentEvents);z.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function WHt(t){const A=ZHt(t),e=z.forwardRef((i,n)=>{const{children:o,...s}=i,r=z.Children.toArray(o),a=r.find(jHt);if(a){const g=a.props.children,I=r.map(c=>c===a?z.Children.count(g)>1?z.Children.only(null):z.isValidElement(g)?g.props.children:null:c);return O.jsx(A,{...s,ref:n,children:z.isValidElement(g)?z.cloneElement(g,void 0,I):null})}return O.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function ZHt(t){const A=z.forwardRef((e,i)=>{const{children:n,...o}=e;if(z.isValidElement(n)){const s=XHt(n),r=zHt(o,n.props);return n.type!==z.Fragment&&(r.ref=i?Lp(i,s):s),z.cloneElement(n,r)}return z.Children.count(n)>1?z.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var VHt=Symbol("radix.slottable");function jHt(t){return z.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===VHt}function zHt(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function XHt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var WW="Dialog",[Vee,jee]=Qw(WW),[$Ht,Fm]=Vee(WW),zee=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=z.useRef(null),a=z.useRef(null),[g,I]=EG({prop:i,defaultProp:n??!1,onChange:o,caller:WW});return O.jsx($Ht,{scope:A,triggerRef:r,contentRef:a,contentId:Eu(),titleId:Eu(),descriptionId:Eu(),open:g,onOpenChange:I,onOpenToggle:z.useCallback(()=>I(c=>!c),[I]),modal:s,children:e})};zee.displayName=WW;var Xee="DialogTrigger",$ee=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(Xee,e),o=dB(A,n.triggerRef);return O.jsx(Cg.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":nhA(n.open),...i,ref:o,onClick:go(t.onClick,n.onOpenToggle)})});$ee.displayName=Xee;var thA="DialogPortal",[AYt,Ate]=Vee(thA,{forceMount:void 0}),ete=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Fm(thA,A);return O.jsx(AYt,{scope:A,forceMount:e,children:z.Children.map(i,s=>O.jsx(oy,{present:e||o.open,children:O.jsx(u8,{asChild:!0,container:n,children:s})}))})};ete.displayName=thA;var ZW="DialogOverlay",tte=z.forwardRef((t,A)=>{const e=Ate(ZW,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Fm(ZW,t.__scopeDialog);return o.modal?O.jsx(oy,{present:i||o.open,children:O.jsx(tYt,{...n,ref:A})}):null});tte.displayName=ZW;var eYt=WHt("DialogOverlay.RemoveScroll"),tYt=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ZW,e);return O.jsx(S8,{as:eYt,allowPinchZoom:!0,shards:[n.contentRef],children:O.jsx(Cg.div,{"data-state":nhA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),wF="DialogContent",ite=z.forwardRef((t,A)=>{const e=Ate(wF,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Fm(wF,t.__scopeDialog);return O.jsx(oy,{present:i||o.open,children:o.modal?O.jsx(iYt,{...n,ref:A}):O.jsx(nYt,{...n,ref:A})})});ite.displayName=wF;var iYt=z.forwardRef((t,A)=>{const e=Fm(wF,t.__scopeDialog),i=z.useRef(null),n=dB(A,e.contentRef,i);return z.useEffect(()=>{const o=i.current;if(o)return tQA(o)},[]),O.jsx(nte,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:go(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:go(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:go(t.onFocusOutside,o=>o.preventDefault())})}),nYt=z.forwardRef((t,A)=>{const e=Fm(wF,t.__scopeDialog),i=z.useRef(!1),n=z.useRef(!1);return O.jsx(nte,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),nte=z.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Fm(wF,e),a=z.useRef(null),g=dB(A,a);return UCA(),O.jsxs(O.Fragment,{children:[O.jsx(s8,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:O.jsx(o8,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":nhA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),O.jsxs(O.Fragment,{children:[O.jsx(sYt,{titleId:r.titleId}),O.jsx(aYt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),ihA="DialogTitle",ote=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ihA,e);return O.jsx(Cg.h2,{id:n.titleId,...i,ref:A})});ote.displayName=ihA;var ste="DialogDescription",rte=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ste,e);return O.jsx(Cg.p,{id:n.descriptionId,...i,ref:A})});rte.displayName=ste;var ate="DialogClose",gte=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ate,e);return O.jsx(Cg.button,{type:"button",...i,ref:A,onClick:go(t.onClick,()=>n.onOpenChange(!1))})});gte.displayName=ate;function nhA(t){return t?"open":"closed"}var Ite="DialogTitleWarning",[oYt,cte]=FPe(Ite,{contentName:wF,titleName:ihA,docsSlug:"dialog"}),sYt=({titleId:t})=>{const A=cte(Ite),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5605
+ `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return O.jsxs("div",{className:`relative ${A}`,ref:n,children:[O.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&O.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:[O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Oee=t=>t.activeSubSolver?[t,...Oee(t.activeSubSolver)]:[t],bHt=({solver:t})=>{const A=Oee(t);return O.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>O.jsxs("div",{className:"flex items-center",children:[i>0&&O.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),O.jsx(SHt,{solver:e})]},e.constructor.name))})},xHt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=z.useReducer(Q=>!Q,!1),r=z.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},I=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};z.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),z.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const l=t.getCurrentPhase!==void 0,C=l?t.getCurrentPhase():null;return O.jsxs("div",{className:"space-y-2 p-2 border-b",children:[O.jsx("div",{className:"flex items-center",children:O.jsx(bHt,{solver:t})}),O.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[O.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),O.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),O.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),O.jsx("button",{onClick:B,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),l&&O.jsx("button",{onClick:c,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),O.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",O.jsx("span",{className:"font-medium",children:C})]}),t.solved&&O.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&O.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&O.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},kHt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},GHt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=kHt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const B=t.pipelineDef[A+1],l=B?t.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;n==="Completed"?I=1:n==="In Progress"&&o&&(I=o.progress??0);const c=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:o??null}},FHt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return O.jsx("span",{className:`font-medium ${A[t]}`,children:t})},RHt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:O.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),O.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},NHt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),MHt=({stats:t})=>{if(!t||Object.keys(t).length===0)return O.jsx("span",{children:"-"});const A=Object.entries(t),e=NHt(t);return O.jsxs("details",{className:"cursor-pointer",children:[O.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),O.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>O.jsxs("div",{children:[i,": ",String(n)]},i))})]})},ehA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ehA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=ehA(i));return A},_Ht=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=ehA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},vHt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>GHt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):_Ht(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return O.jsxs("div",{className:"border-t border-gray-200",children:[O.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:O.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),O.jsx("div",{className:"overflow-x-auto",children:O.jsxs("table",{className:"w-full text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),O.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",O.jsx("sub",{children:"0"})]}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),O.jsx("tbody",{children:i.map(r=>O.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[O.jsx("td",{className:"px-4 py-2",children:O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),O.jsx("button",{onClick:()=>n(r.name),disabled:r.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 ${r.name} completes`,children:O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})})}),O.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(FHt,{status:r.status})}),O.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(RHt,{progress:r.progress})}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),O.jsx("td",{className:"px-4 py-2 text-gray-500",children:O.jsx(MHt,{stats:r.stats})}),O.jsx("td",{className:"px-4 py-2",children:r.solverInstance?O.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})}),O.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},UHt=class extends Xi.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 LHt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of n){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of o)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return O.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>O.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>O.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),o.map((E,h)=>O.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var HHt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=z.useReducer(I=>I+1,0),s=z.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();o()}};return O.jsxs("div",{children:[O.jsx(xHt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?O.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):O.jsx(UHt,{fallback:O.jsx(LHt,{graphics:s}),children:O.jsx(DHt,{graphics:s})}),a&&O.jsx(vHt,{solver:t,onStepUntilPhase:g})]})};const YHt=()=>{z.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},JHt=t=>t.toLowerCase().includes("pack")?vwt:t.toLowerCase().includes("rout")?Jwt:dwt,THt=({solverEvents:t=[]})=>{const[A,e]=z.useState(null);YHt();const i=z.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=z.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=z.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=AeA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(AeA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return t.length===0?O.jsx("div",{className:"rf-p-4",children:O.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:O.jsxs("div",{className:"rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),O.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."})]})})}):O.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[O.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[O.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:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return O.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=JHt(a.solverName);return O.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[O.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),O.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[O.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),O.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),O.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?O.jsx(uy,{fallback:O.jsx("div",{className:"rf-p-4",children:O.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),O.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:O.jsx(HHt,{solver:s.instance})}):O.jsxs("div",{className:"rf-p-4",children:[O.jsxs("div",{className:"rf-mb-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),O.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&O.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:O.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),O.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[O.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:O.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),O.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:O.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):O.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:O.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Wee=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{z.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{s3.captureException(i)}catch{}}},[t,A]),z.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{s3.captureException(n,{error_type:i.type})}catch{}}},[e])},Zee="0.0.1445",KHt={version:Zee},OW=bvA()(xvA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),qHt=t=>{const[A,e]=z.useState([]),[i,n]=z.useState(null),[o,s]=z.useState(""),[r,a]=H_("eval-version-selection",null),g=OW(l=>l.setLastRunEvalVersion),I=OW(l=>l.lastRunEvalVersion);return z.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(l=>l.json()).then(l=>{if(Array.isArray(l?.versions)){let C=[...l.versions];l.tags?.latest&&(n(l.tags.latest),C=C.filter(Q=>Q!==l.tags.latest)),e(C)}}).catch(()=>{})},[t]),z.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:z.useMemo(()=>A.filter(l=>l.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:I,search:o,setSearch:s,selectVersion:l=>{a(l),s("")}}},PHt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=z.useState(""),[s,r]=z.useState("");if(!i)return null;const a=t.filter(c=>c.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),I=c=>{c.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return O.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:O.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[O.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),O.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:c=>r(c.target.value),onKeyDown:I}),O.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(c=>O.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===c?"bg-blue-50":""}`,onClick:()=>o(c),children:c},c)),g&&O.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),O.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},OHt=t=>{const A=z.useRef(null),e=Uc(i=>i.recentEvents);z.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function WHt(t){const A=ZHt(t),e=z.forwardRef((i,n)=>{const{children:o,...s}=i,r=z.Children.toArray(o),a=r.find(jHt);if(a){const g=a.props.children,I=r.map(c=>c===a?z.Children.count(g)>1?z.Children.only(null):z.isValidElement(g)?g.props.children:null:c);return O.jsx(A,{...s,ref:n,children:z.isValidElement(g)?z.cloneElement(g,void 0,I):null})}return O.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function ZHt(t){const A=z.forwardRef((e,i)=>{const{children:n,...o}=e;if(z.isValidElement(n)){const s=XHt(n),r=zHt(o,n.props);return n.type!==z.Fragment&&(r.ref=i?Lp(i,s):s),z.cloneElement(n,r)}return z.Children.count(n)>1?z.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var VHt=Symbol("radix.slottable");function jHt(t){return z.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===VHt}function zHt(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function XHt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var WW="Dialog",[Vee,jee]=Qw(WW),[$Ht,Fm]=Vee(WW),zee=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=z.useRef(null),a=z.useRef(null),[g,I]=EG({prop:i,defaultProp:n??!1,onChange:o,caller:WW});return O.jsx($Ht,{scope:A,triggerRef:r,contentRef:a,contentId:Eu(),titleId:Eu(),descriptionId:Eu(),open:g,onOpenChange:I,onOpenToggle:z.useCallback(()=>I(c=>!c),[I]),modal:s,children:e})};zee.displayName=WW;var Xee="DialogTrigger",$ee=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(Xee,e),o=dB(A,n.triggerRef);return O.jsx(Cg.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":nhA(n.open),...i,ref:o,onClick:go(t.onClick,n.onOpenToggle)})});$ee.displayName=Xee;var thA="DialogPortal",[AYt,Ate]=Vee(thA,{forceMount:void 0}),ete=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Fm(thA,A);return O.jsx(AYt,{scope:A,forceMount:e,children:z.Children.map(i,s=>O.jsx(oy,{present:e||o.open,children:O.jsx(u8,{asChild:!0,container:n,children:s})}))})};ete.displayName=thA;var ZW="DialogOverlay",tte=z.forwardRef((t,A)=>{const e=Ate(ZW,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Fm(ZW,t.__scopeDialog);return o.modal?O.jsx(oy,{present:i||o.open,children:O.jsx(tYt,{...n,ref:A})}):null});tte.displayName=ZW;var eYt=WHt("DialogOverlay.RemoveScroll"),tYt=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ZW,e);return O.jsx(S8,{as:eYt,allowPinchZoom:!0,shards:[n.contentRef],children:O.jsx(Cg.div,{"data-state":nhA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),wF="DialogContent",ite=z.forwardRef((t,A)=>{const e=Ate(wF,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Fm(wF,t.__scopeDialog);return O.jsx(oy,{present:i||o.open,children:o.modal?O.jsx(iYt,{...n,ref:A}):O.jsx(nYt,{...n,ref:A})})});ite.displayName=wF;var iYt=z.forwardRef((t,A)=>{const e=Fm(wF,t.__scopeDialog),i=z.useRef(null),n=dB(A,e.contentRef,i);return z.useEffect(()=>{const o=i.current;if(o)return tQA(o)},[]),O.jsx(nte,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:go(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:go(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:go(t.onFocusOutside,o=>o.preventDefault())})}),nYt=z.forwardRef((t,A)=>{const e=Fm(wF,t.__scopeDialog),i=z.useRef(!1),n=z.useRef(!1);return O.jsx(nte,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),nte=z.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Fm(wF,e),a=z.useRef(null),g=dB(A,a);return UCA(),O.jsxs(O.Fragment,{children:[O.jsx(s8,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:O.jsx(o8,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":nhA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),O.jsxs(O.Fragment,{children:[O.jsx(sYt,{titleId:r.titleId}),O.jsx(aYt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),ihA="DialogTitle",ote=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ihA,e);return O.jsx(Cg.h2,{id:n.titleId,...i,ref:A})});ote.displayName=ihA;var ste="DialogDescription",rte=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ste,e);return O.jsx(Cg.p,{id:n.descriptionId,...i,ref:A})});rte.displayName=ste;var ate="DialogClose",gte=z.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Fm(ate,e);return O.jsx(Cg.button,{type:"button",...i,ref:A,onClick:go(t.onClick,()=>n.onOpenChange(!1))})});gte.displayName=ate;function nhA(t){return t?"open":"closed"}var Ite="DialogTitleWarning",[oYt,cte]=FPe(Ite,{contentName:wF,titleName:ihA,docsSlug:"dialog"}),sYt=({titleId:t})=>{const A=cte(Ite),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5606
5606
 
5607
5607
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5608
5608
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/runframe",
3
3
  "main": "dist/preview.js",
4
4
  "type": "module",
5
- "version": "0.0.1445",
5
+ "version": "0.0.1446",
6
6
  "exports": {
7
7
  ".": "./dist/preview.js",
8
8
  "./preview": "./dist/preview.js",
@@ -48,11 +48,11 @@
48
48
  "@tscircuit/3d-viewer": "^0.0.480",
49
49
  "@tscircuit/assembly-viewer": "^0.0.5",
50
50
  "@tscircuit/create-snippet-url": "^0.0.9",
51
- "@tscircuit/eval": "^0.0.558",
51
+ "@tscircuit/eval": "^0.0.559",
52
52
  "@tscircuit/fake-snippets": "^0.0.163",
53
53
  "@tscircuit/file-server": "^0.0.32",
54
54
  "@tscircuit/footprinter": "^0.0.236",
55
- "@tscircuit/pcb-viewer": "1.11.294",
55
+ "@tscircuit/pcb-viewer": "1.11.295",
56
56
  "@tscircuit/props": "^0.0.429",
57
57
  "@tscircuit/schematic-trace-solver": "^0.0.40",
58
58
  "@tscircuit/schematic-viewer": "^2.0.51",