@tscircuit/runframe 0.0.1680 → 0.0.1681

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.
@@ -1730,7 +1730,7 @@ var useErrorTelemetry = ({
1730
1730
  };
1731
1731
 
1732
1732
  // package.json
1733
- var version = "0.0.1679";
1733
+ var version = "0.0.1680";
1734
1734
  var package_default = {
1735
1735
  name: "@tscircuit/runframe",
1736
1736
  main: "dist/preview.js",
@@ -1787,7 +1787,7 @@ var package_default = {
1787
1787
  "@tscircuit/fake-snippets": "^0.0.163",
1788
1788
  "@tscircuit/file-server": "^0.0.32",
1789
1789
  "@tscircuit/footprinter": "^0.0.236",
1790
- "@tscircuit/pcb-viewer": "1.11.345",
1790
+ "@tscircuit/pcb-viewer": "1.11.346",
1791
1791
  "@tscircuit/props": "^0.0.455",
1792
1792
  "@tscircuit/schematic-trace-solver": "^0.0.40",
1793
1793
  "@tscircuit/schematic-viewer": "^2.0.57",
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  linkify,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-SUHVM4N3.js";
11
+ } from "./chunk-TNWIVBWN.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-SUHVM4N3.js";
37
+ } from "./chunk-TNWIVBWN.js";
38
38
 
39
39
  // lib/components/RunFrame/RunFrame.tsx
40
40
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5462,7 +5462,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Qct(e,A,t){if(!A||!t)retu
5462
5462
  transition: opacity 0.2s;
5463
5463
  margin-bottom: 10px;
5464
5464
  color: red;
5465
- `,RWe=({children:e,transform:A=Mb(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=JC(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=t?Lb(t).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=cn(A,{x:B.x,y:B.y}),d=cn(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=efA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(vWe,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:Vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const b=S.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:S=>{if(!E){const b=S.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:Z.jsx("div",{className:`error-message ${ifA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>cn(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=efA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(MWe,{points:u,errorCenter:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const S=w.currentTarget.nextElementSibling;if(S){const b=S.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:w=>{if(!E){const S=w.currentTarget.nextElementSibling;if(S){const b=S.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?Vc.errorOverlay+10:Vc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${ifA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=t?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&t?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const k=t?.find(x=>x.type==="pcb_component"&&x.source_component_id===Q.source_component_id);k&&k.type==="pcb_component"&&(E=k.center||{x:0,y:0})}const u=cn(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),S=Math.max(8,Math.min(30,.5*d)),b=efA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Vc.errorOverlay},width:"100%",height:"100%",children:C?Z.jsx("polygon",{points:`${u.x},${u.y-S*1.25} ${u.x+S},${u.y} ${u.x},${u.y+S*1.25} ${u.x-S},${u.y}`,fill:"#ff4444"}):Z.jsx("circle",{cx:u.x,cy:u.y,r:S,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,S*.15):Math.max(1,S*.1),opacity:1})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(S+10),top:u.y-(S+10),width:(S+10)*2,height:(S+10)*2,zIndex:Vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?Vc.errorOverlay+20:Vc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:Z.jsx("div",{className:`error-message ${ifA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function NWe(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function LWe({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Lb(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const n=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:n}}function UWe(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,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(!t)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var HWe={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},YWe=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:n}=e;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""}},JWe={top:"red",bottom:"aqua"},TWe=({primitive:e,mousePos:A,elements:t})=>{const[i,n]=AA.useState(!1),o=e._element;AA.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],c=e.same_space_index??0,I=26,l=JWe[e?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in e||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in e)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=LWe({primitiveElement:o,elements:t});if(!h)return null;const E=A.y-35;return Z.jsx("div",{style:{zIndex:Vc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=YWe(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:Vc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:Z.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:Z.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,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(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},KWe=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=JC(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=UWe({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:HWe,children:!i&&s.map((r,a)=>Z.jsx(TWe,{primitive:r,mousePos:A,elements:t},a))})},lk=e=>e?.type==="pcb_component",Kct=e=>e?.type==="pcb_group",PWe=e=>e?.type==="pcb_panel",nfA=e=>e?.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},ty={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},ofA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:ty.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:kI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=cn(A,s.anchor);o.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Vc.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=cn(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?kI.LABEL_OFFSET_ABOVE:kI.LABEL_OFFSET_BELOW,d=E?kI.LABEL_OFFSET_RIGHT:kI.LABEL_OFFSET_LEFT,f=C>kI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>kI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,S=`${s.display_offset_y??B.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.LINE_STROKE_WIDTH,strokeDasharray:kI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.LINE_STROKE_WIDTH,strokeDasharray:kI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:kI.COMPONENT_MARKER_RADIUS,fill:ty.COMPONENT_MARKER_FILL,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-kI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+kI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-kI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+kI.ANCHOR_MARKER_SIZE,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&Z.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:kI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:S})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-kI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+kI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-kI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+kI.ANCHOR_MARKER_SIZE,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},qWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>nfA(E)),s=e.filter(E=>lk(E)),r=e.filter(E=>Kct(E)),a=A.map(E=>lk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:lk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!JC(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return Z.jsx(ofA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},OWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>Kct(E)),s=e.filter(E=>lk(E)),r=A.map(E=>lk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:lk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!JC(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return Z.jsx(ofA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},WWe=(e,A)=>{const t=e.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===t||n.type==="pcb_hole"&&n.pcb_component_id===t);return i.length===0?AfA([e]):AfA(i)},ZWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)lk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),lk(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=WWe(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Lb(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:Vc.dimensionOverlay},children:Z.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 c=cn(t,{x:a.minX,y:a.maxY}),I=cn(t,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=cn(t,B);return Z.jsxs("g",{children:[Z.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:kI.COMPONENT_MARKER_RADIUS,fill:ty.COMPONENT_MARKER_FILL,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},VWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>PWe(B)),s=e.filter(B=>nfA(B)),r=A.map(B=>nfA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!JC(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return Z.jsx(ofA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},DV=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(const o of e)o.x<A&&(A=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(t+n)/2},width:i-A,height:n-t}},Pct=(e,A)=>{if(A.length<3)return!1;let t=!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>e.y!=a>e.y&&e.x<(r-o)*(e.y-s)/(a-s||Number.EPSILON)+o&&(t=!t)}return t},jWe=(e,A,t)=>{const i=[];for(const n of e){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=ru({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)/t.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:_e.parse(g.x),y:_e.parse(g.y)})),a=DV(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;Pct(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:_e.parse(g.x),y:_e.parse(g.y)})),a=DV(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;Pct(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},zWe=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:c,height:I}]=BJ(),l=AA.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=DV(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),S=DV(w);if(!S)continue;h=S.center,E=S.width,u=S.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="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(!h)continue;const d=cn(t,h),f={w:E*t.a,h:u*t.a},m=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[o,t]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=cn(Rb(h),{x:C,y:Q}),d=jWe(E,u,h);NWe(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 Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,t,i)}},onTouchStart:C=>{if(t){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,t,i)}},children:[A,Z.jsx(KWe,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(qWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(OWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(ZWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(VWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},qct=["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)"],XWe=({children:e,transform:A=Mb(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=BJ(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=JC(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=t.filter(w=>w.type==="pcb_group"),C=t.filter(w=>w.type==="pcb_component"),Q=t.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(g==="all")return!0;if(!w.source_group_id)return!1;const S=h.get(w.source_group_id);return S?S.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const S=w;if(S.parent_source_group_id){const b=u.get(S.parent_source_group_id)||[];b.push(w.source_group_id),u.set(S.parent_source_group_id,b)}});const d=w=>{const S=[],b=u.get(w)||[];for(const k of b)S.push(k),S.push(...d(k));return S},f=w=>{const S=Q.find(b=>b.source_group_id===w);return S?.parent_source_group_id?1+f(S.parent_source_group_id):0},m=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const S=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;S&&m.add(S)}E.forEach((w,S)=>{let b=C.filter(KA=>KA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const KA=d(w.source_group_id),WA=B.filter(kA=>kA.source_group_id&&KA.includes(kA.source_group_id));for(const kA of WA){const DA=C.filter(HA=>HA.pcb_group_id===kA.pcb_group_id);b=[...b,...DA]}}let k,x,R,M,U=!1;if(w.center&&w.width&&w.height){U=!0;const KA=w.width/2,WA=w.height/2;k=w.center.x-KA,R=w.center.x+KA,x=w.center.y-WA,M=w.center.y+WA}else if(b.length===0||(k=1/0,x=1/0,R=-1/0,M=-1/0,b.forEach(KA=>{if(KA.center&&typeof KA.width=="number"&&typeof KA.height=="number"){const WA=KA.center.x-KA.width/2,kA=KA.center.x+KA.width/2,DA=KA.center.y+KA.height/2,HA=KA.center.y-KA.height/2;k=Math.min(k,WA),R=Math.max(R,kA),x=Math.min(x,HA),M=Math.max(M,DA)}}),k===1/0||R===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,T=w.source_group_id?d(w.source_group_id).length>0:!1;if(!U){const kA=1+(T?.5:0);k-=kA,R+=kA,x-=kA,M+=kA}const O=cn(A,{x:k,y:M}),W=cn(A,{x:R,y:M}),z=cn(A,{x:k,y:x}),iA=cn(A,{x:R,y:x}),gA=qct[S%qct.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),nA=Math.max(2,Math.min(6,4*Math.abs(A.a))),QA=tA*(T?1.3:1),bA=nA;l.setLineDash([QA,bA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(iA.x,iA.y),l.lineTo(z.x,z.y),l.closePath(),l.stroke();const JA=Math.max(8,Math.min(12,10*Math.abs(A.a))),RA=Y==0||Y==1?0:Y*.11,OA=JA*(1-RA),dA=4,vA=w.name||`Group ${S+1}`;l.font=`${OA}px sans-serif`,l.setLineDash([]);const jA=l.measureText(vA).width+dA*2,$A=OA+dA*2,Qt=O.x-5,wA=O.y-5,st=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(Qt,wA-$A,jA,$A,st),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(vA,Qt+dA,wA-$A/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const KA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},WA=cn(A,KA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-kA,WA.y),l.lineTo(WA.x+kA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-kA),l.lineTo(WA.x,WA.y+kA),l.stroke()}})},[t,A,o,s,a,g,c,i]),Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Vc.pcbGroupOverlay,display:a?"block":"none"}})]})},$We=({transform:e,soup:A,children:t})=>{const i=JC(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>yct(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Lb(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=Lb(A).pcb_port.list(),c=Lb(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?t:(e||(e=Mb()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Vc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=cn(e,a),l=cn(e,g);return Z.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},AZe={version:"1.11.344"},Bk=(e,A,t)=>{const i=JC(s=>s.is_mouse_over_container),n=AA.useRef(i),o=AA.useRef(A);AA.useEffect(()=>{n.current=i},[i]),AA.useEffect(()=>{o.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[e])},tZe=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},QJ=(e,A={stopPropagation:!0})=>{const t=AA.useRef(0),i=AA.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-t.current<300||(t.current=r,e?.(s))},[e,A.stopPropagation]),n=AA.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},eZe=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=QJ(t);return Z.jsxs("div",{className:l1`
5465
+ `,RWe=({children:e,transform:A=Mb(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=JC(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=t?Lb(t).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=cn(A,{x:B.x,y:B.y}),d=cn(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=efA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(vWe,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:Vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:S=>{const b=S.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:S=>{if(!E){const b=S.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:Z.jsx("div",{className:`error-message ${ifA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>cn(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=efA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(MWe,{points:u,errorCenter:f,isHighlighted:E}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:Vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const S=w.currentTarget.nextElementSibling;if(S){const b=S.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:w=>{if(!E){const S=w.currentTarget.nextElementSibling;if(S){const b=S.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:E?Vc.errorOverlay+10:Vc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${ifA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=t?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&t?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const k=t?.find(x=>x.type==="pcb_component"&&x.source_component_id===Q.source_component_id);k&&k.type==="pcb_component"&&(E=k.center||{x:0,y:0})}const u=cn(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),S=Math.max(8,Math.min(30,.5*d)),b=efA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:Vc.errorOverlay},width:"100%",height:"100%",children:C?Z.jsx("polygon",{points:`${u.x},${u.y-S*1.25} ${u.x+S},${u.y} ${u.x},${u.y+S*1.25} ${u.x-S},${u.y}`,fill:"#ff4444"}):Z.jsx("circle",{cx:u.x,cy:u.y,r:S,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,S*.15):Math.max(1,S*.1),opacity:1})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(S+10),top:u.y-(S+10),width:(S+10)*2,height:(S+10)*2,zIndex:Vc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?Vc.errorOverlay+20:Vc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:Z.jsx("div",{className:`error-message ${ifA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function NWe(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function LWe({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Lb(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const n=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:n}}function UWe(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,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(!t)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var HWe={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},YWe=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:n}=e;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""}},JWe={top:"red",bottom:"aqua"},TWe=({primitive:e,mousePos:A,elements:t})=>{const[i,n]=AA.useState(!1),o=e._element;AA.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],c=e.same_space_index??0,I=26,l=JWe[e?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in e||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in e)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=LWe({primitiveElement:o,elements:t});if(!h)return null;const E=A.y-35;return Z.jsx("div",{style:{zIndex:Vc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=YWe(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:Vc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:Z.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:Z.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,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(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},KWe=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,n]=JC(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=UWe({primitives:s,is_showing_multiple_traces_length:n,elements:t}),Z.jsx("div",{style:HWe,children:!i&&s.map((r,a)=>Z.jsx(TWe,{primitive:r,mousePos:A,elements:t},a))})},lk=e=>e?.type==="pcb_component",Kct=e=>e?.type==="pcb_group",PWe=e=>e?.type==="pcb_panel",nfA=e=>e?.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},ty={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},ofA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const n={color:ty.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:kI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return e.forEach(s=>{if(!o.has(s.anchor_id)){const r=cn(A,s.anchor);o.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:Vc.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=cn(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?kI.LABEL_OFFSET_ABOVE:kI.LABEL_OFFSET_BELOW,d=E?kI.LABEL_OFFSET_RIGHT:kI.LABEL_OFFSET_LEFT,f=C>kI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>kI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,S=`${s.display_offset_y??B.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.LINE_STROKE_WIDTH,strokeDasharray:kI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.LINE_STROKE_WIDTH,strokeDasharray:kI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:I.x,cy:I.y,r:kI.COMPONENT_MARKER_RADIUS,fill:ty.COMPONENT_MARKER_FILL,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:I.x-kI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+kI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:I.x,y1:I.y-kI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+kI.ANCHOR_MARKER_SIZE,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&Z.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:kI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:Z.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:S})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-kI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+kI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-kI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+kI.ANCHOR_MARKER_SIZE,stroke:ty.OFFSET_LINE,strokeWidth:kI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},qWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>nfA(E)),s=e.filter(E=>lk(E)),r=e.filter(E=>Kct(E)),a=A.map(E=>lk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:lk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!JC(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return Z.jsx(ofA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},OWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(E=>Kct(E)),s=e.filter(E=>lk(E)),r=A.map(E=>lk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:lk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!JC(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return Z.jsx(ofA,{targets:h,transform:t,containerWidth:i,containerHeight:n})},WWe=(e,A)=>{const t=e.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===t||n.type==="pcb_hole"&&n.pcb_component_id===t);return i.length===0?AfA([e]):AfA(i)},ZWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)lk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),lk(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=WWe(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Lb(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:Vc.dimensionOverlay},children:Z.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 c=cn(t,{x:a.minX,y:a.maxY}),I=cn(t,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=cn(t,B);return Z.jsxs("g",{children:[Z.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:kI.COMPONENT_MARKER_RADIUS,fill:ty.COMPONENT_MARKER_FILL,stroke:ty.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},VWe=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:n})=>{const o=e.filter(B=>PWe(B)),s=e.filter(B=>nfA(B)),r=A.map(B=>nfA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!JC(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return Z.jsx(ofA,{targets:l,transform:t,containerWidth:i,containerHeight:n})},DV=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,n=e[0].y;for(const o of e)o.x<A&&(A=o.x),o.y<t&&(t=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(t+n)/2},width:i-A,height:n-t}},Pct=(e,A)=>{if(A.length<3)return!1;let t=!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>e.y!=a>e.y&&e.x<(r-o)*(e.y-s)/(a-s||Number.EPSILON)+o&&(t=!t)}return t},jWe=(e,A,t)=>{const i=[];for(const n of e){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=ru({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)/t.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:_e.parse(g.x),y:_e.parse(g.y)})),a=DV(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;Pct(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:_e.parse(g.x),y:_e.parse(g.y)})),a=DV(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;Pct(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},zWe=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:c,height:I}]=BJ(),l=AA.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=DV(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),S=DV(w);if(!S)continue;h=S.center,E=S.width,u=S.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="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(!h)continue;const d=cn(t,h),f={w:E*t.a,h:u*t.a},m=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[o,t]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=cn(Rb(h),{x:C,y:Q}),d=jWe(E,u,h);NWe(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 Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,t,i)}},onTouchStart:C=>{if(t){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,t,i)}},children:[A,Z.jsx(KWe,{elements:e,mousePos:r,highlightedPrimitives:l}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(qWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(OWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(ZWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I}),Z.jsx(VWe,{elements:e,highlightedPrimitives:l,transform:t,containerWidth:c,containerHeight:I})]})]})},qct=["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)"],XWe=({children:e,transform:A=Mb(),elements:t=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=BJ(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=JC(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=t.filter(w=>w.type==="pcb_group"),C=t.filter(w=>w.type==="pcb_component"),Q=t.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const S=h.get(w.source_group_id);return S?S.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const S=w;if(S.parent_source_group_id){const b=u.get(S.parent_source_group_id)||[];b.push(w.source_group_id),u.set(S.parent_source_group_id,b)}});const d=w=>{const S=[],b=u.get(w)||[];for(const k of b)S.push(k),S.push(...d(k));return S},f=w=>{const S=Q.find(b=>b.source_group_id===w);return S?.parent_source_group_id?1+f(S.parent_source_group_id):0},m=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const S=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;S&&m.add(S)}E.forEach((w,S)=>{let b=C.filter(KA=>KA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const KA=d(w.source_group_id),WA=B.filter(kA=>kA.source_group_id&&KA.includes(kA.source_group_id));for(const kA of WA){const DA=C.filter(HA=>HA.pcb_group_id===kA.pcb_group_id);b=[...b,...DA]}}let k,x,R,M,U=!1;if(w.center&&w.width&&w.height){U=!0;const KA=w.width/2,WA=w.height/2;k=w.center.x-KA,R=w.center.x+KA,x=w.center.y-WA,M=w.center.y+WA}else if(b.length===0||(k=1/0,x=1/0,R=-1/0,M=-1/0,b.forEach(KA=>{if(KA.center&&typeof KA.width=="number"&&typeof KA.height=="number"){const WA=KA.center.x-KA.width/2,kA=KA.center.x+KA.width/2,DA=KA.center.y+KA.height/2,HA=KA.center.y-KA.height/2;k=Math.min(k,WA),R=Math.max(R,kA),x=Math.min(x,HA),M=Math.max(M,DA)}}),k===1/0||R===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,T=w.source_group_id?d(w.source_group_id).length>0:!1;if(!U){const kA=1+(T?.5:0);k-=kA,R+=kA,x-=kA,M+=kA}const O=cn(A,{x:k,y:M}),W=cn(A,{x:R,y:M}),z=cn(A,{x:k,y:x}),iA=cn(A,{x:R,y:x}),gA=qct[S%qct.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),nA=Math.max(2,Math.min(6,4*Math.abs(A.a))),QA=tA*(T?1.3:1),bA=nA;l.setLineDash([QA,bA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(W.x,W.y),l.lineTo(iA.x,iA.y),l.lineTo(z.x,z.y),l.closePath(),l.stroke();const JA=Math.max(8,Math.min(12,10*Math.abs(A.a))),RA=Y==0||Y==1?0:Y*.11,OA=JA*(1-RA),dA=4,vA=w.name||`Group ${S+1}`;l.font=`${OA}px sans-serif`,l.setLineDash([]);const jA=l.measureText(vA).width+dA*2,$A=OA+dA*2,Qt=O.x-5,wA=O.y-5,st=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(Qt,wA-$A,jA,$A,st),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(vA,Qt+dA,wA-$A/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const KA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},WA=cn(A,KA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(WA.x-kA,WA.y),l.lineTo(WA.x+kA,WA.y),l.stroke(),l.beginPath(),l.moveTo(WA.x,WA.y-kA),l.lineTo(WA.x,WA.y+kA),l.stroke()}})},[t,A,o,s,a,g,c,i]),Z.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:Vc.pcbGroupOverlay,display:a?"block":"none"}})]})},$We=({transform:e,soup:A,children:t})=>{const i=JC(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=AA.useMemo(()=>yct(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Lb(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=Lb(A).pcb_port.list(),c=Lb(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?t:(e||(e=Mb()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:Vc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=cn(e,a),l=cn(e,g);return Z.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},AZe={version:"1.11.345"},Bk=(e,A,t)=>{const i=JC(s=>s.is_mouse_over_container),n=AA.useRef(i),o=AA.useRef(A);AA.useEffect(()=>{n.current=i},[i]),AA.useEffect(()=>{o.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[e])},tZe=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},QJ=(e,A={stopPropagation:!0})=>{const t=AA.useRef(0),i=AA.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-t.current<300||(t.current=r,e?.(s))},[e,A.stopPropagation]),n=AA.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},eZe=({name:e,selected:A,onClick:t})=>{const{style:i,...n}=QJ(t);return Z.jsxs("div",{className:l1`
5466
5466
  margin-top: 2px;
5467
5467
  padding: 4px;
5468
5468
  padding-left: 8px;
@@ -5679,7 +5679,7 @@ test("${g} should solve problem correctly", () => {
5679
5679
  // Add more specific assertions based on expected output
5680
5680
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5681
5681
  })
5682
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},eIt=e=>e.activeSubSolver?[e,...eIt(e.activeSubSolver)]:[e],_9e=({solver:e})=>{const A=eIt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(x9e,{solver:t})]},t.constructor.name))})},k9e=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(_9e,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.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"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.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"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.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"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.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"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.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"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},F9e=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},G9e=(e,A)=>{const i=e.pipelineDef[A].solverName,n=F9e(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},v9e=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},M9e=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},R9e=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),N9e=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=R9e(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},BfA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(BfA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=BfA(i));return A},L9e=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=BfA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,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(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},U9e=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>G9e(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):L9e(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(v9e,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(M9e,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(N9e,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.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:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},H9e=class extends mn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Y9e({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var J9e=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),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 c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(k9e,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(H9e,{fallback:Z.jsx(Y9e,{graphics:s}),children:Z.jsx(b9e,{graphics:s})}),a&&Z.jsx(U9e,{solver:e,onStepUntilPhase:g})]})};const T9e=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},K9e=e=>e.toLowerCase().includes("pack")?Sve:e.toLowerCase().includes("rout")?Gve:Eve,P9e=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);T9e();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=mrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(mrA).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 e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.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:()=>t(r),children:(()=>{const c=K9e(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(vD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(J9e,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},iIt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{tP.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{tP.captureException(n,{error_type:i.type})}catch{}}},[t])},nIt="0.0.1679",q9e={version:nIt},CfA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},QfA=new Map,kV=e=>{const A=QfA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},O9e=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=QfA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return QfA.set(t.name,n),{type:"tracked",store:e,...n}},oIt=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(CfA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(CfA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=O9e(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...kV(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(CfA?"production":void 0)!=="production"&&E[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),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return hfA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
5682
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},eIt=e=>e.activeSubSolver?[e,...eIt(e.activeSubSolver)]:[e],_9e=({solver:e})=>{const A=eIt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(x9e,{solver:t})]},t.constructor.name))})},k9e=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(Q=>!Q,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const Q=e;if(Q.getCurrentPhase&&!e.solved&&!e.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const Q=window.prompt("Step until which iteration?",`${e.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<h&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(_9e,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.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"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.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"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.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"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.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"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.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"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},F9e=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},G9e=(e,A)=>{const i=e.pipelineDef[A].solverName,n=F9e(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},v9e=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},M9e=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},R9e=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),N9e=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=R9e(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},BfA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(BfA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=BfA(i));return A},L9e=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=BfA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,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(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},U9e=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>G9e(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):L9e(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(v9e,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(M9e,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(N9e,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.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:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},H9e=class extends mn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Y9e({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of t){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>Z.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),t.map((h,E)=>Z.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>Z.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>Z.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var J9e=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),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 c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(k9e,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(H9e,{fallback:Z.jsx(Y9e,{graphics:s}),children:Z.jsx(b9e,{graphics:s})}),a&&Z.jsx(U9e,{solver:e,onStepUntilPhase:g})]})};const T9e=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},K9e=e=>e.toLowerCase().includes("pack")?Sve:e.toLowerCase().includes("rout")?Gve:Eve,P9e=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);T9e();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=mrA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(mrA).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 e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.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:()=>t(r),children:(()=>{const c=K9e(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(vD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(J9e,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},iIt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{tP.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{tP.captureException(n,{error_type:i.type})}catch{}}},[t])},nIt="0.0.1680",q9e={version:nIt},CfA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},QfA=new Map,kV=e=>{const A=QfA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},O9e=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=QfA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return QfA.set(t.name,n),{type:"tracked",store:e,...n}},oIt=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(CfA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(CfA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=O9e(r,g,a);let l=!0;n.setState=(Q,h,E)=>{const u=t(Q,h);if(!l)return u;const d=E===void 0?{type:s||"anonymous"}:typeof E=="string"?{type:E}:E;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...kV(a.name),[r]:n.getState()}),u)};const B=(...Q)=>{const h=l;l=!1,t(...Q),l=h},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([Q,h])=>[Q,Q===I.store?C:h.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let Q=!1;const h=n.dispatch;n.dispatch=(...E)=>{(CfA?"production":void 0)!=="production"&&E[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),h(...E)}}return c.subscribe(Q=>{var h;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return hfA(Q.payload,E=>{if(E.type==="__setState"){if(r===void 0){B(E.state);return}Object.keys(E.state).length!==1&&console.error(`
5683
5683
  [zustand devtools middleware] Unsupported __setState action format.
5684
5684
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5685
5685
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
@@ -5466,7 +5466,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function LIe(t,A,e){if(!A||!e)retu
5466
5466
  transition: opacity 0.2s;
5467
5467
  margin-bottom: 10px;
5468
5468
  color: red;
5469
- `,GVt=({children:t,transform:A=Kb(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=TC(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.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)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?Ob(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=cn(A,{x:B.x,y:B.y}),d=cn(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=a0A(m,i);return W.jsxs(V.Fragment,{children:[W.jsx(vVt,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:zc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:D=>{if(!E){const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:W.jsx("div",{className:`error-message ${g0A}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>cn(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=a0A(f,i);return W.jsxs(V.Fragment,{children:[W.jsx(FVt,{points:u,errorCenter:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:zc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?zc.errorOverlay+10:zc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:W.jsx("div",{className:`error-message ${g0A}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const k=e?.find(x=>x.type==="pcb_component"&&x.source_component_id===Q.source_component_id);k&&k.type==="pcb_component"&&(E=k.center||{x:0,y:0})}const u=cn(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),b=a0A(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:zc.errorOverlay},width:"100%",height:"100%",children:C?W.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"}):W.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})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:zc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?zc.errorOverlay+20:zc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:W.jsx("div",{className:`error-message ${g0A}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function MVt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function RVt({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=Ob(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 NVt(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,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var LVt={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},UVt=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""}},HVt={top:"red",bottom:"aqua"},YVt=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=HVt[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=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)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=RVt({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:zc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=UVt(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:zc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,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(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},JVt=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=TC(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=NVt({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:LVt,children:!i&&s.map((r,a)=>W.jsx(YVt,{primitive:r,mousePos:A,elements:e},a))})},dk=t=>t?.type==="pcb_component",Ile=t=>t?.type==="pcb_group",TVt=t=>t?.type==="pcb_panel",c0A=t=>t?.type==="pcb_board",vI={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},Iy={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},I0A=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:Iy.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:vI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=cn(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:zc.dimensionOverlay},children:W.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,c=o.get(a),I=cn(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?vI.LABEL_OFFSET_ABOVE:vI.LABEL_OFFSET_BELOW,d=E?vI.LABEL_OFFSET_RIGHT:vI.LABEL_OFFSET_LEFT,f=C>vI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>vI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.LINE_STROKE_WIDTH,strokeDasharray:vI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.LINE_STROKE_WIDTH,strokeDasharray:vI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:vI.COMPONENT_MARKER_RADIUS,fill:Iy.COMPONENT_MARKER_FILL,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-vI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+vI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-vI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+vI.ANCHOR_MARKER_SIZE,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:vI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-vI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+vI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-vI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+vI.ANCHOR_MARKER_SIZE,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},KVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>c0A(E)),s=t.filter(E=>dk(E)),r=t.filter(E=>Ile(E)),a=A.map(E=>dk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:dk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!TC(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(I0A,{targets:h,transform:e,containerWidth:i,containerHeight:n})},PVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>Ile(E)),s=t.filter(E=>dk(E)),r=A.map(E=>dk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:dk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!TC(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(I0A,{targets:h,transform:e,containerWidth:i,containerHeight:n})},qVt=(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?s0A([t]):s0A(i)},OVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)dk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),dk(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=qVt(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Ob(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:zc.dimensionOverlay},children:W.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 c=cn(e,{x:a.minX,y:a.maxY}),I=cn(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=cn(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:vI.COMPONENT_MARKER_RADIUS,fill:Iy.COMPONENT_MARKER_FILL,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},WVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>TVt(B)),s=t.filter(B=>c0A(B)),r=A.map(B=>c0A(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!TC(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(I0A,{targets:l,transform:e,containerWidth:i,containerHeight:n})},Ij=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}},lle=(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},ZVt=(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=tu({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:_t.parse(g.x),y:_t.parse(g.y)})),a=Ij(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;lle(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:_t.parse(g.x),y:_t.parse(g.y)})),a=Ij(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;lle(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},VVt=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=NJ(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=Ij(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),D=Ij(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="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(!h)continue;const d=cn(e,h),f={w:E*e.a,h:u*e.a},m=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=cn(Pb(h),{x:C,y:Q}),d=ZVt(E,u,h);MVt(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 W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(JVt,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(KVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(PVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(OVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(WVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},Ble=["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)"],jVt=({children:t,transform:A=Kb(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=NJ(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=TC(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const b=u.get(D.parent_source_group_id)||[];b.push(w.source_group_id),u.set(D.parent_source_group_id,b)}});const d=w=>{const D=[],b=u.get(w)||[];for(const k of b)D.push(k),D.push(...d(k));return D},f=w=>{const D=Q.find(b=>b.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},m=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&m.add(D)}E.forEach((w,D)=>{let b=C.filter(KA=>KA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const KA=d(w.source_group_id),VA=B.filter(kA=>kA.source_group_id&&KA.includes(kA.source_group_id));for(const kA of VA){const DA=C.filter(UA=>UA.pcb_group_id===kA.pcb_group_id);b=[...b,...DA]}}let k,x,R,M,L=!1;if(w.center&&w.width&&w.height){L=!0;const KA=w.width/2,VA=w.height/2;k=w.center.x-KA,R=w.center.x+KA,x=w.center.y-VA,M=w.center.y+VA}else if(b.length===0||(k=1/0,x=1/0,R=-1/0,M=-1/0,b.forEach(KA=>{if(KA.center&&typeof KA.width=="number"&&typeof KA.height=="number"){const VA=KA.center.x-KA.width/2,kA=KA.center.x+KA.width/2,DA=KA.center.y+KA.height/2,UA=KA.center.y-KA.height/2;k=Math.min(k,VA),R=Math.max(R,kA),x=Math.min(x,UA),M=Math.max(M,DA)}}),k===1/0||R===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const kA=1+(J?.5:0);k-=kA,R+=kA,x-=kA,M+=kA}const q=cn(A,{x:k,y:M}),Z=cn(A,{x:R,y:M}),X=cn(A,{x:k,y:x}),iA=cn(A,{x:R,y:x}),gA=Ble[D%Ble.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),eA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=tA*(J?1.3:1),pA=eA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(q.x,q.y),l.lineTo(Z.x,Z.y),l.lineTo(iA.x,iA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const NA=Math.max(8,Math.min(12,10*Math.abs(A.a))),FA=Y==0||Y==1?0:Y*.11,PA=NA*(1-FA),hA=4,vA=w.name||`Group ${D+1}`;l.font=`${PA}px sans-serif`,l.setLineDash([]);const WA=l.measureText(vA).width+hA*2,$A=PA+hA*2,Ce=q.x-5,wA=q.y-5,oe=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(Ce,wA-$A,WA,$A,oe),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(vA,Ce+hA,wA-$A/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const KA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},VA=cn(A,KA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(VA.x-kA,VA.y),l.lineTo(VA.x+kA,VA.y),l.stroke(),l.beginPath(),l.moveTo(VA.x,VA.y-kA),l.lineTo(VA.x,VA.y+kA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:zc.pcbGroupOverlay,display:a?"block":"none"}})]})},zVt=({transform:t,soup:A,children:e})=>{const i=TC(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>PIe(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Ob(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=Ob(A).pcb_port.list(),c=Ob(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=Kb()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:zc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=cn(t,a),l=cn(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},XVt={version:"1.11.344"},pk=(t,A,e)=>{const i=TC(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},$Vt=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},UJ=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Ajt=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=UJ(e);return W.jsxs("div",{className:_1`
5469
+ `,GVt=({children:t,transform:A=Kb(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=TC(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.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)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?Ob(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=cn(A,{x:B.x,y:B.y}),d=cn(A,{x:C.x,y:C.y});if(!n)return null;const f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const w=a0A(m,i);return W.jsxs(V.Fragment,{children:[W.jsx(vVt,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:zc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:D=>{if(!E){const b=D.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:w.left,top:w.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:w.transform},children:W.jsx("div",{className:`error-message ${g0A}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.route.map(w=>cn(A,{x:w.x,y:w.y}));if(u.some(w=>isNaN(w.x)||isNaN(w.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=a0A(f,i);return W.jsxs(V.Fragment,{children:[W.jsx(FVt,{points:u,errorCenter:f,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:zc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:w=>{if(!E){const D=w.currentTarget.nextElementSibling;if(D){const b=D.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?zc.errorOverlay+10:zc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:W.jsx("div",{className:`error-message ${g0A}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const k=e?.find(x=>x.type==="pcb_component"&&x.source_component_id===Q.source_component_id);k&&k.type==="pcb_component"&&(E=k.center||{x:0,y:0})}const u=cn(A,E);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),D=Math.max(8,Math.min(30,.5*d)),b=a0A(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:zc.errorOverlay},width:"100%",height:"100%",children:C?W.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"}):W.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})}),W.jsx("div",{style:{position:"absolute",left:u.x-(D+10),top:u.y-(D+10),width:(D+10)*2,height:(D+10)*2,zIndex:zc.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const R=x.querySelector(".error-message");R&&(R.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?zc.errorOverlay+20:zc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:W.jsx("div",{className:`error-message ${g0A}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function MVt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function RVt({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=Ob(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 NVt(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,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var LVt={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},UVt=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""}},HVt={top:"red",bottom:"aqua"},YVt=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=HVt[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=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)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=RVt({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:zc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=UVt(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:zc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,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(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},JVt=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=TC(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=NVt({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:LVt,children:!i&&s.map((r,a)=>W.jsx(YVt,{primitive:r,mousePos:A,elements:e},a))})},dk=t=>t?.type==="pcb_component",Ile=t=>t?.type==="pcb_group",TVt=t=>t?.type==="pcb_panel",c0A=t=>t?.type==="pcb_board",vI={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},Iy={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},I0A=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:Iy.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:vI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=cn(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:zc.dimensionOverlay},children:W.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,c=o.get(a),I=cn(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?vI.LABEL_OFFSET_ABOVE:vI.LABEL_OFFSET_BELOW,d=E?vI.LABEL_OFFSET_RIGHT:vI.LABEL_OFFSET_LEFT,f=C>vI.MIN_LINE_LENGTH_FOR_LABEL,m=Q>vI.MIN_LINE_LENGTH_FOR_LABEL,w=`${s.display_offset_x??l.toFixed(2)}mm`,D=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.LINE_STROKE_WIDTH,strokeDasharray:vI.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.LINE_STROKE_WIDTH,strokeDasharray:vI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:vI.COMPONENT_MARKER_RADIUS,fill:Iy.COMPONENT_MARKER_FILL,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-vI.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+vI.ANCHOR_MARKER_SIZE,y2:I.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-vI.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+vI.ANCHOR_MARKER_SIZE,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:w})}),m&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:vI.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:D})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-vI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+vI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-vI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+vI.ANCHOR_MARKER_SIZE,stroke:Iy.OFFSET_LINE,strokeWidth:vI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},KVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>c0A(E)),s=t.filter(E=>dk(E)),r=t.filter(E=>Ile(E)),a=A.map(E=>dk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:dk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!TC(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(f=>f.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(I0A,{targets:h,transform:e,containerWidth:i,containerHeight:n})},PVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>Ile(E)),s=t.filter(E=>dk(E)),r=A.map(E=>dk(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:dk(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(f=>f.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!TC(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(I0A,{targets:h,transform:e,containerWidth:i,containerHeight:n})},qVt=(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?s0A([t]):s0A(i)},OVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)dk(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),dk(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=qVt(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?Ob(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:zc.dimensionOverlay},children:W.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 c=cn(e,{x:a.minX,y:a.maxY}),I=cn(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=cn(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:vI.COMPONENT_MARKER_RADIUS,fill:Iy.COMPONENT_MARKER_FILL,stroke:Iy.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},WVt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>TVt(B)),s=t.filter(B=>c0A(B)),r=A.map(B=>c0A(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!TC(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(I0A,{targets:l,transform:e,containerWidth:i,containerHeight:n})},Ij=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}},lle=(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},ZVt=(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=tu({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:_t.parse(g.x),y:_t.parse(g.y)})),a=Ij(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;lle(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:_t.parse(g.x),y:_t.parse(g.y)})),a=Ij(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;lle(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},VVt=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=NJ(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const w=Ij(Q.points);if(!w)continue;h=w.center,E=w.width,u=w.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const w=Q.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),D=Ij(w);if(!D)continue;h=D.center,E=D.width,u=D.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="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(!h)continue;const d=cn(e,h),f={w:E*e.a,h:u*e.a},m=C.filter(w=>d.x===w.screen_x&&d.y===w.screen_y&&f.w===w.screen_w&&f.h===w.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=cn(Pb(h),{x:C,y:Q}),d=ZVt(E,u,h);MVt(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 W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(JVt,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx(KVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(PVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(OVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(WVt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},Ble=["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)"],jVt=({children:t,transform:A=Kb(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=NJ(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=TC(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(w=>w.type==="pcb_group"),C=e.filter(w=>w.type==="pcb_component"),Q=e.filter(w=>w.type==="source_group"),h=new Map(Q.map(w=>[w.source_group_id,w])),E=B.filter(w=>{if(w.name?.toLowerCase().includes("subpanel"))return!1;if(g==="all")return!0;if(!w.source_group_id)return!1;const D=h.get(w.source_group_id);return D?D.was_automatically_named!==!0:!1}),u=new Map;Q.forEach(w=>{const D=w;if(D.parent_source_group_id){const b=u.get(D.parent_source_group_id)||[];b.push(w.source_group_id),u.set(D.parent_source_group_id,b)}});const d=w=>{const D=[],b=u.get(w)||[];for(const k of b)D.push(k),D.push(...d(k));return D},f=w=>{const D=Q.find(b=>b.source_group_id===w);return D?.parent_source_group_id?1+f(D.parent_source_group_id):0},m=new Set;if(i.length>0)for(const w of C){if(!i.includes(w.pcb_component_id))continue;const D=w.positioned_relative_to_pcb_group_id??w.pcb_group_id;D&&m.add(D)}E.forEach((w,D)=>{let b=C.filter(KA=>KA.pcb_group_id===w.pcb_group_id);if(w.source_group_id){const KA=d(w.source_group_id),VA=B.filter(kA=>kA.source_group_id&&KA.includes(kA.source_group_id));for(const kA of VA){const DA=C.filter(UA=>UA.pcb_group_id===kA.pcb_group_id);b=[...b,...DA]}}let k,x,R,M,L=!1;if(w.center&&w.width&&w.height){L=!0;const KA=w.width/2,VA=w.height/2;k=w.center.x-KA,R=w.center.x+KA,x=w.center.y-VA,M=w.center.y+VA}else if(b.length===0||(k=1/0,x=1/0,R=-1/0,M=-1/0,b.forEach(KA=>{if(KA.center&&typeof KA.width=="number"&&typeof KA.height=="number"){const VA=KA.center.x-KA.width/2,kA=KA.center.x+KA.width/2,DA=KA.center.y+KA.height/2,UA=KA.center.y-KA.height/2;k=Math.min(k,VA),R=Math.max(R,kA),x=Math.min(x,UA),M=Math.max(M,DA)}}),k===1/0||R===-1/0))return;const Y=w.source_group_id?f(w.source_group_id):0,J=w.source_group_id?d(w.source_group_id).length>0:!1;if(!L){const kA=1+(J?.5:0);k-=kA,R+=kA,x-=kA,M+=kA}const q=cn(A,{x:k,y:M}),Z=cn(A,{x:R,y:M}),X=cn(A,{x:k,y:x}),iA=cn(A,{x:R,y:x}),gA=Ble[D%Ble.length];l.strokeStyle=gA,l.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),eA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=tA*(J?1.3:1),pA=eA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(q.x,q.y),l.lineTo(Z.x,Z.y),l.lineTo(iA.x,iA.y),l.lineTo(X.x,X.y),l.closePath(),l.stroke();const NA=Math.max(8,Math.min(12,10*Math.abs(A.a))),FA=Y==0||Y==1?0:Y*.11,PA=NA*(1-FA),hA=4,vA=w.name||`Group ${D+1}`;l.font=`${PA}px sans-serif`,l.setLineDash([]);const WA=l.measureText(vA).width+hA*2,$A=PA+hA*2,Ce=q.x-5,wA=q.y-5,oe=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(Ce,wA-$A,WA,$A,oe),l.fill(),l.fillStyle=gA,l.textAlign="left",l.textBaseline="middle",l.fillText(vA,Ce+hA,wA-$A/2),c&&m.has(w.pcb_group_id)&&!!w.anchor_position&&w.anchor_position){const KA=Array.isArray(w.anchor_position)?{x:w.anchor_position[0]??0,y:w.anchor_position[1]??0}:{x:w.anchor_position.x,y:w.anchor_position.y},VA=cn(A,KA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(VA.x-kA,VA.y),l.lineTo(VA.x+kA,VA.y),l.stroke(),l.beginPath(),l.moveTo(VA.x,VA.y-kA),l.lineTo(VA.x,VA.y+kA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:zc.pcbGroupOverlay,display:a?"block":"none"}})]})},zVt=({transform:t,soup:A,children:e})=>{const i=TC(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>PIe(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=Ob(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=Ob(A).pcb_port.list(),c=Ob(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=Kb()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:zc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=cn(t,a),l=cn(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},XVt={version:"1.11.345"},pk=(t,A,e)=>{const i=TC(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},$Vt=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},UJ=(t,A={stopPropagation:!0})=>{const e=V.useRef(0),i=V.useCallback(s=>{A.stopPropagation&&s.stopPropagation();const r=Date.now();r-e.current<300||(e.current=r,t?.(s))},[t,A.stopPropagation]),n=V.useCallback(s=>{s.preventDefault(),i(s)},[i]);return{onClick:i,onTouchEnd:n,style:{touchAction:"manipulation"}}},Ajt=({name:t,selected:A,onClick:e})=>{const{style:i,...n}=UJ(e);return W.jsxs("div",{className:_1`
5470
5470
  margin-top: 2px;
5471
5471
  padding: 4px;
5472
5472
  padding-left: 8px;
@@ -5683,7 +5683,7 @@ test("${g} should solve problem correctly", () => {
5683
5683
  // Add more specific assertions based on expected output
5684
5684
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5685
5685
  })
5686
- `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.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&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},yle=t=>t.activeSubSolver?[t,...yle(t.activeSubSolver)]:[t],bzt=({solver:t})=>{const A=yle(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(Szt,{solver:e})]},e.constructor.name))})},xzt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.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))},c=()=>{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))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(bzt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.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"}),W.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"}),W.jsx("button",{onClick:c,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"}),W.jsx("button",{onClick:l,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"}),B&&W.jsx("button",{onClick:I,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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},_zt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},kzt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=_zt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},vzt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Fzt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Gzt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),Mzt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=Gzt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},d0A=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(d0A);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=d0A(i));return A},Rzt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=d0A(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)}`)}},Nzt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>kzt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):Rzt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.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:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(vzt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Fzt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(Mzt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.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:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},Lzt=class extends mn.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 Uzt({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 c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Hzt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(xzt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(Lzt,{fallback:W.jsx(Uzt,{graphics:s}),children:W.jsx(Dzt,{graphics:s})}),a&&W.jsx(Nzt,{solver:t,onStepUntilPhase:g})]})};const Yzt=()=>{V.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)},[])},Jzt=t=>t.toLowerCase().includes("pack")?LNt:t.toLowerCase().includes("rout")?TNt:yNt,Tzt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Yzt();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=foA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(foA).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?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.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 c=Jzt(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(lm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(Hzt,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},mle=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{n8.captureException(i)}catch{}}},[t,A]),V.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{n8.captureException(n,{error_type:i.type})}catch{}}},[e])},wle="0.0.1679",Kzt={version:wle},Ej=rJA()(aJA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Pzt=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=gR("eval-version-selection",null),g=Ej(B=>B.setLastRunEvalVersion),c=Ej(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},qzt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.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:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.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:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.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,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.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}`})]})]})})},Ozt=t=>{const A=V.useRef(null),e=Hl(i=>i.recentEvents);V.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 Wzt(t){const A=Zzt(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(jzt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function Zzt(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=Xzt(n),r=zzt(o,n.props);return n.type!==V.Fragment&&(r.ref=i?Gf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var Vzt=Symbol("radix.slottable");function jzt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Vzt}function zzt(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 Xzt(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 uj="Dialog",[Dle,Sle]=rw(uj),[$zt,vw]=Dle(uj),ble=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=o_({prop:i,defaultProp:n??!1,onChange:o,caller:uj});return W.jsx($zt,{scope:A,triggerRef:r,contentRef:a,contentId:ru(),titleId:ru(),descriptionId:ru(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};ble.displayName=uj;var xle="DialogTrigger",_le=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(xle,e),o=nl(A,n.triggerRef);return W.jsx(mg.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":y0A(n.open),...i,ref:o,onClick:Io(t.onClick,n.onOpenToggle)})});_le.displayName=xle;var p0A="DialogPortal",[AXt,kle]=Dle(p0A,{forceMount:void 0}),vle=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=vw(p0A,A);return W.jsx(AXt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(K0,{present:e||o.open,children:W.jsx(l9,{asChild:!0,container:n,children:s})}))})};vle.displayName=p0A;var dj="DialogOverlay",Fle=V.forwardRef((t,A)=>{const e=kle(dj,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=vw(dj,t.__scopeDialog);return o.modal?W.jsx(K0,{present:i||o.open,children:W.jsx(tXt,{...n,ref:A})}):null});Fle.displayName=dj;var eXt=Wzt("DialogOverlay.RemoveScroll"),tXt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(dj,e);return W.jsx(p9,{as:eXt,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(mg.div,{"data-state":y0A(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),oG="DialogContent",Gle=V.forwardRef((t,A)=>{const e=kle(oG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=vw(oG,t.__scopeDialog);return W.jsx(K0,{present:i||o.open,children:o.modal?W.jsx(iXt,{...n,ref:A}):W.jsx(nXt,{...n,ref:A})})});Gle.displayName=oG;var iXt=V.forwardRef((t,A)=>{const e=vw(oG,t.__scopeDialog),i=V.useRef(null),n=nl(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return ddA(o)},[]),W.jsx(Mle,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Io(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Io(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Io(t.onFocusOutside,o=>o.preventDefault())})}),nXt=V.forwardRef((t,A)=>{const e=vw(oG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(Mle,{...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()}})}),Mle=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=vw(oG,e),a=V.useRef(null),g=nl(A,a);return AdA(),W.jsxs(W.Fragment,{children:[W.jsx($Z,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(mY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":y0A(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(sXt,{titleId:r.titleId}),W.jsx(aXt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),f0A="DialogTitle",Rle=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(f0A,e);return W.jsx(mg.h2,{id:n.titleId,...i,ref:A})});Rle.displayName=f0A;var Nle="DialogDescription",Lle=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(Nle,e);return W.jsx(mg.p,{id:n.descriptionId,...i,ref:A})});Lle.displayName=Nle;var Ule="DialogClose",Hle=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(Ule,e);return W.jsx(mg.button,{type:"button",...i,ref:A,onClick:Io(t.onClick,()=>n.onOpenChange(!1))})});Hle.displayName=Ule;function y0A(t){return t?"open":"closed"}var Yle="DialogTitleWarning",[oXt,Jle]=f7e(Yle,{contentName:oG,titleName:f0A,docsSlug:"dialog"}),sXt=({titleId:t})=>{const A=Jle(Yle),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5686
+ `,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.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&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},yle=t=>t.activeSubSolver?[t,...yle(t.activeSubSolver)]:[t],bzt=({solver:t})=>{const A=yle(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(Szt,{solver:e})]},e.constructor.name))})},xzt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.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))},c=()=>{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))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(bzt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.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"}),W.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"}),W.jsx("button",{onClick:c,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"}),W.jsx("button",{onClick:l,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"}),B&&W.jsx("button",{onClick:I,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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},_zt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},kzt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=_zt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},vzt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Fzt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},Gzt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),Mzt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=Gzt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},d0A=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(d0A);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=d0A(i));return A},Rzt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=d0A(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)}`)}},Nzt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>kzt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):Rzt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.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:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(vzt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Fzt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(Mzt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.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:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},Lzt=class extends mn.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 Uzt({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 c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var Hzt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(xzt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(Lzt,{fallback:W.jsx(Uzt,{graphics:s}),children:W.jsx(Dzt,{graphics:s})}),a&&W.jsx(Nzt,{solver:t,onStepUntilPhase:g})]})};const Yzt=()=>{V.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)},[])},Jzt=t=>t.toLowerCase().includes("pack")?LNt:t.toLowerCase().includes("rout")?TNt:yNt,Tzt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Yzt();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=foA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(foA).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?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.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 c=Jzt(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(lm,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(Hzt,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},mle=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{n8.captureException(i)}catch{}}},[t,A]),V.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{n8.captureException(n,{error_type:i.type})}catch{}}},[e])},wle="0.0.1680",Kzt={version:wle},Ej=rJA()(aJA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),Pzt=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=gR("eval-version-selection",null),g=Ej(B=>B.setLastRunEvalVersion),c=Ej(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},qzt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.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:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.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:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.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,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.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}`})]})]})})},Ozt=t=>{const A=V.useRef(null),e=Hl(i=>i.recentEvents);V.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 Wzt(t){const A=Zzt(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(jzt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function Zzt(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=Xzt(n),r=zzt(o,n.props);return n.type!==V.Fragment&&(r.ref=i?Gf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var Vzt=Symbol("radix.slottable");function jzt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Vzt}function zzt(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 Xzt(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 uj="Dialog",[Dle,Sle]=rw(uj),[$zt,vw]=Dle(uj),ble=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=o_({prop:i,defaultProp:n??!1,onChange:o,caller:uj});return W.jsx($zt,{scope:A,triggerRef:r,contentRef:a,contentId:ru(),titleId:ru(),descriptionId:ru(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};ble.displayName=uj;var xle="DialogTrigger",_le=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(xle,e),o=nl(A,n.triggerRef);return W.jsx(mg.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":y0A(n.open),...i,ref:o,onClick:Io(t.onClick,n.onOpenToggle)})});_le.displayName=xle;var p0A="DialogPortal",[AXt,kle]=Dle(p0A,{forceMount:void 0}),vle=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=vw(p0A,A);return W.jsx(AXt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(K0,{present:e||o.open,children:W.jsx(l9,{asChild:!0,container:n,children:s})}))})};vle.displayName=p0A;var dj="DialogOverlay",Fle=V.forwardRef((t,A)=>{const e=kle(dj,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=vw(dj,t.__scopeDialog);return o.modal?W.jsx(K0,{present:i||o.open,children:W.jsx(tXt,{...n,ref:A})}):null});Fle.displayName=dj;var eXt=Wzt("DialogOverlay.RemoveScroll"),tXt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(dj,e);return W.jsx(p9,{as:eXt,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(mg.div,{"data-state":y0A(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),oG="DialogContent",Gle=V.forwardRef((t,A)=>{const e=kle(oG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=vw(oG,t.__scopeDialog);return W.jsx(K0,{present:i||o.open,children:o.modal?W.jsx(iXt,{...n,ref:A}):W.jsx(nXt,{...n,ref:A})})});Gle.displayName=oG;var iXt=V.forwardRef((t,A)=>{const e=vw(oG,t.__scopeDialog),i=V.useRef(null),n=nl(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return ddA(o)},[]),W.jsx(Mle,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Io(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Io(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Io(t.onFocusOutside,o=>o.preventDefault())})}),nXt=V.forwardRef((t,A)=>{const e=vw(oG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(Mle,{...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()}})}),Mle=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=vw(oG,e),a=V.useRef(null),g=nl(A,a);return AdA(),W.jsxs(W.Fragment,{children:[W.jsx($Z,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(mY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":y0A(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(sXt,{titleId:r.titleId}),W.jsx(aXt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),f0A="DialogTitle",Rle=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(f0A,e);return W.jsx(mg.h2,{id:n.titleId,...i,ref:A})});Rle.displayName=f0A;var Nle="DialogDescription",Lle=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(Nle,e);return W.jsx(mg.p,{id:n.descriptionId,...i,ref:A})});Lle.displayName=Nle;var Ule="DialogClose",Hle=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=vw(Ule,e);return W.jsx(mg.button,{type:"button",...i,ref:A,onClick:Io(t.onClick,()=>n.onOpenChange(!1))})});Hle.displayName=Ule;function y0A(t){return t?"open":"closed"}var Yle="DialogTitleWarning",[oXt,Jle]=f7e(Yle,{contentName:oG,titleName:f0A,docsSlug:"dialog"}),sXt=({titleId:t})=>{const A=Jle(Yle),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5687
5687
 
5688
5688
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5689
5689
 
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.1680",
5
+ "version": "0.0.1681",
6
6
  "exports": {
7
7
  ".": "./dist/preview.js",
8
8
  "./preview": "./dist/preview.js",
@@ -54,7 +54,7 @@
54
54
  "@tscircuit/fake-snippets": "^0.0.163",
55
55
  "@tscircuit/file-server": "^0.0.32",
56
56
  "@tscircuit/footprinter": "^0.0.236",
57
- "@tscircuit/pcb-viewer": "1.11.345",
57
+ "@tscircuit/pcb-viewer": "1.11.346",
58
58
  "@tscircuit/props": "^0.0.455",
59
59
  "@tscircuit/schematic-trace-solver": "^0.0.40",
60
60
  "@tscircuit/schematic-viewer": "^2.0.57",