@tscircuit/runframe 0.0.2069 → 0.0.2070

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.
@@ -2004,7 +2004,7 @@ var usePostHogActivity = (properties) => {
2004
2004
  };
2005
2005
 
2006
2006
  // package.json
2007
- var version = "0.0.2068";
2007
+ var version = "0.0.2069";
2008
2008
  var package_default = {
2009
2009
  name: "@tscircuit/runframe",
2010
2010
  main: "dist/preview.js",
@@ -2059,7 +2059,7 @@ var package_default = {
2059
2059
  "@tscircuit/fake-snippets": "^0.0.163",
2060
2060
  "@tscircuit/file-server": "^0.0.32",
2061
2061
  "@tscircuit/internal-dynamic-import": "^0.0.7",
2062
- "@tscircuit/pcb-viewer": "1.11.371",
2062
+ "@tscircuit/pcb-viewer": "1.11.372",
2063
2063
  "@tscircuit/schematic-viewer": "^2.0.62",
2064
2064
  "@types/bun": "latest",
2065
2065
  "@types/debug": "^4.1.12",
package/dist/preview.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  SchematicViewer,
8
8
  useOrderDialog,
9
9
  useOrderDialogCli
10
- } from "./chunk-5RMEE6IC.js";
10
+ } from "./chunk-23AD7FSR.js";
11
11
  export {
12
12
  BomTable,
13
13
  CadViewer,
package/dist/runner.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  useRunFrameStore,
35
35
  useRunnerStore,
36
36
  useStyles
37
- } from "./chunk-5RMEE6IC.js";
37
+ } from "./chunk-23AD7FSR.js";
38
38
 
39
39
  // lib/components/RunFrame/RunFrame.tsx
40
40
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5524,7 +5524,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function tCt(t,e,n){if(!e||!n)retu
5524
5524
  transition: opacity 0.2s;
5525
5525
  margin-bottom: 10px;
5526
5526
  color: red;
5527
- `,U_o=({children:t,transform:e=rA(),elements:n})=>{const o=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=x_(m=>({isShowingDRCErrors:m.is_showing_drc_errors,hoveredErrorId:m.hovered_error_id,focusedErrorId:m.focused_error_id})),a=s??r;if(!n)return W.jsx("div",{style:{position:"relative"},ref:o,children:t});const c=n.filter(m=>m.type==="pcb_trace_error"&&!m.message?.includes("Multiple components found with name")),l=n.filter(m=>m.type==="pcb_via_clearance_error"),A=n.filter(m=>m.type==="pcb_trace_error"&&m.message?.includes("Multiple components found with name")),u=uCt(n),_=ACt(n,a),h=m=>{const p=Auo({error:m,indexes:u});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const g=dt(e,p);return Number.isNaN(g.x)||Number.isNaN(g.y)?null:g};let d=null;return _&&(d=h(_)),W.jsxs("div",{style:{position:"relative"},ref:o,children:[t,c.map((m,p)=>{const g=vD(m,p),y=a===g;if(!y&&!i)return null;const f=h(m);if(!f)return null;const x=ebe(f,o);return W.jsxs(te.Fragment,{children:[W.jsx(kCt,{errorCenter:f,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:_A.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!y){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:x.left,top:x.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:W.jsx("div",{className:`error-message ${tbe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:m.message})})]},g)}),l.map((m,p)=>{const g=vD(m,p),y=a===g;if(!y&&!i)return null;const f=h(m);if(!f)return null;const x=ebe({x:f.x,y:f.y},o);return W.jsxs(te.Fragment,{children:[W.jsx(kCt,{errorCenter:f,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:_A.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!y){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?_A.errorOverlay+10:_A.errorOverlay+1,left:x.left,top:x.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:W.jsx("div",{className:`error-message ${tbe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:m.message})})]},g)}),A.map((m,p)=>{const g=m.component_name||m.message?.match(/name "([^"]+)"/)?.[1];if(!g)return null;const y=n?.filter(I=>I.type==="source_component"&&I.name===g||I.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===I.source_component_id&&E.name===g))||[],f=vD(m,p),x=a===f;return!x&&!i?null:y.map((I,E)=>{let b={x:0,y:0};if(I.type==="pcb_component")b=I.center||{x:0,y:0};else if(I.type==="source_component"){const G=n?.find(K=>K.type==="pcb_component"&&K.source_component_id===I.source_component_id);G&&G.type==="pcb_component"&&(b=G.center||{x:0,y:0})}const P=dt(e,b);if(Number.isNaN(P.x)||Number.isNaN(P.y))return null;const B=Math.abs(e.a),F=Math.max(8,Math.min(30,.5*B)),O=ebe(P,o);return W.jsxs(te.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:_A.errorOverlay},width:"100%",height:"100%",children:x?W.jsx("polygon",{points:`${P.x},${P.y-F*1.25} ${P.x+F},${P.y} ${P.x},${P.y+F*1.25} ${P.x-F},${P.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:P.x,cy:P.y,r:F,fill:"none",stroke:x?"#ff4444":"red",strokeWidth:x?Math.max(2,F*.15):Math.max(1,F*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:P.x-(F+10),top:P.y-(F+10),width:(F+10)*2,height:(F+10)*2,zIndex:_A.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const K=G.currentTarget.nextElementSibling;if(K){const X=K.querySelector(".error-message");X&&(X.style.opacity="1")}},onMouseLeave:G=>{if(!x){const K=G.currentTarget.nextElementSibling;if(K){const X=K.querySelector(".error-message");X&&(X.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:x?_A.errorOverlay+20:_A.errorOverlay+10,left:O.left,top:O.top,color:x?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||x?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:O.transform},children:W.jsx("div",{className:`error-message ${tbe}`,style:{opacity:x?1:0,border:`1px solid ${x?"#ff4444":"red"}`},children:m.message})})]},`${f}_${E}`)})}),d&&W.jsx(z_o,{center:d})]})};function V_o(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function Y_o({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const o=uP(e).source_trace.get(t?.source_trace_id);if(o?.display_name&&(o?.max_length?n+=` / ${o.max_length}mm `:n+=" mm ",n+=`(${o.display_name})`),!n)return null;const i=t.trace_length&&o?.max_length&&t.trace_length>o.max_length;return{text:n,isOverLength:i}}function K_o(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(c=>c._element.type==="pcb_trace"),r=o.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>r.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!n)return[...s,...a];if(i.length>1){const c=i.reduce((l,A)=>{const u=l._element.trace_length;return A._element.trace_length<u?A:l},i[0]);return[...s,c]}return e}var W_o={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},j_o=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(c=>`${a}.${c}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},X_o={top:"red",bottom:"aqua"},J_o=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=te.useState(!1),r=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],A=t.same_space_index??0,u=26,_=X_o[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const p=Y_o({primitiveElement:r,elements:n});if(!p)return null;const g=e.y-35;return W.jsx("div",{style:{zIndex:_A.elementOverlay,position:"absolute",left:e.x,top:g,color:_,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:p.text})})}const d=j_o(t);return d.trim().length===0?null:W.jsx("div",{style:{zIndex:_A.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:_,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:o?`calc(100% + ${u*2*A}px)`:"100%",height:o?`calc(100% + ${u*2*A}px)`:"100%",marginLeft:o?`${-u*A}px`:0,marginTop:o?`${-u*A}px`:0,border:`1px solid ${_}`,opacity:o||A===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:l+20+u*A,marginRight:o?`${-u*A}px`:0,marginBottom:o?0:-u*A,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},q_o=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=x_(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=K_o({primitives:s,is_showing_multiple_traces_length:i,elements:n}),W.jsx("div",{style:W_o,children:!o&&s.map((a,c)=>W.jsx(J_o,{primitive:a,mousePos:e,elements:n},c))})},_P=t=>t?.type==="pcb_component",HCt=t=>t?.type==="pcb_group",$_o=t=>t?.type==="pcb_panel",nbe=t=>t?.type==="pcb_board",D0={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},ox={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},obe=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:ox.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:D0.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=dt(e,s.anchor);r.set(s.anchor_id,a)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:_A.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,A=r.get(c),u=dt(e,l),_=l.x-a.x,h=l.y-a.y,d=Math.abs(u.x-A.x),m=Math.abs(u.y-A.y),p=u.y<A.y,g=u.x>A.x,y=p?D0.LABEL_OFFSET_ABOVE:D0.LABEL_OFFSET_BELOW,f=g?D0.LABEL_OFFSET_RIGHT:D0.LABEL_OFFSET_LEFT,x=d>D0.MIN_LINE_LENGTH_FOR_LABEL,I=m>D0.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??_.toFixed(2)}mm`,b=`${s.display_offset_y??h.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:A.x,y1:A.y,x2:u.x,y2:A.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.LINE_STROKE_WIDTH,strokeDasharray:D0.LINE_DASH_PATTERN}),W.jsx("line",{x1:u.x,y1:A.y,x2:u.x,y2:u.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.LINE_STROKE_WIDTH,strokeDasharray:D0.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:u.x,cy:u.y,r:D0.COMPONENT_MARKER_RADIUS,fill:ox.COMPONENT_MARKER_FILL,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:u.x-D0.ANCHOR_MARKER_SIZE,y1:u.y,x2:u.x+D0.ANCHOR_MARKER_SIZE,y2:u.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:u.x,y1:u.y-D0.ANCHOR_MARKER_SIZE,x2:u.x,y2:u.y+D0.ANCHOR_MARKER_SIZE,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH})]}),x&&W.jsx("foreignObject",{x:Math.min(A.x,u.x),y:A.y+y,width:Math.abs(u.x-A.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...i,textAlign:"center"},children:E})}),I&&W.jsx("foreignObject",{x:u.x+f,y:Math.min(A.y,u.y),width:D0.Y_LABEL_MIN_WIDTH,height:Math.abs(u.y-A.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:g?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:b})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>W.jsxs("g",{children:[W.jsx("line",{x1:a.x-D0.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+D0.ANCHOR_MARKER_SIZE,y2:a.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:a.x,y1:a.y-D0.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+D0.ANCHOR_MARKER_SIZE,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},Z_o=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>nbe(g)),s=t.filter(g=>_P(g)),a=t.filter(g=>HCt(g)),c=e.map(g=>_P(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:_P(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),l=new Set;if(c.forEach(g=>{const y=s.find(f=>f.pcb_component_id===g);y?.pcb_group_id&&l.add(y.pcb_group_id)}),!x_(g=>g.is_showing_group_anchor_offsets)&&c.length===0)return null;const u=s.map(g=>{const y=g.positioned_relative_to_pcb_board_id;if(!y)return null;const f=r.find(x=>x.pcb_board_id===y);return f?{component:g,board:f,type:"component"}:null}).filter(g=>!!g),_=a.map(g=>{const y=g.positioned_relative_to_pcb_board_id;if(!y||!g.center)return null;const f=r.find(x=>x.pcb_board_id===y);return f?{group:g,board:f,type:"group"}:null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=c.length===0,m=h.filter(g=>g.type==="component"?d||c.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>g.type==="component"?{id:`${g.board.pcb_board_id}-${g.component.pcb_component_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:{id:`${g.board.pcb_board_id}-${g.group.pcb_group_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:{x:g.group.anchor_position?.x??g.group.center.x,y:g.group.anchor_position?.y??g.group.center.y},type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}).filter(g=>!!g);return W.jsx(obe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},edo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>HCt(g)),s=t.filter(g=>_P(g)),a=e.map(g=>_P(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:_P(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),c=(g,y)=>{if(y.has(g))return;y.add(g);const f=r.find(x=>x.pcb_group_id===g);f?.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&c(f.positioned_relative_to_pcb_group_id,y)},l=new Set;if(a.forEach(g=>{const y=s.find(f=>f.pcb_component_id===g);y&&(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id&&c(y.positioned_relative_to_pcb_group_id,l),y.pcb_group_id&&c(y.pcb_group_id,l))}),!x_(g=>g.is_showing_group_anchor_offsets)&&a.length===0)return null;const u=s.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const y=r.find(f=>f.pcb_group_id===g.positioned_relative_to_pcb_group_id);return y&&y.anchor_position?{component:g,parentGroup:y,type:"component"}:null}if(g.pcb_group_id){const y=r.find(f=>f.pcb_group_id===g.pcb_group_id);return y&&y.anchor_position?{component:g,parentGroup:y,type:"component"}:null}return null}).filter(g=>!!g),_=r.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const y=r.find(f=>f.pcb_group_id===g.positioned_relative_to_pcb_group_id);if(y&&y.anchor_position&&g.anchor_position)return{group:g,parentGroup:y,type:"group"}}return null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=a.length===0,m=h.filter(g=>g.type==="component"?d||a.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id)||l.has(g.parentGroup.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>{const y=g.parentGroup.anchor_position;return y?g.type==="component"?g.component.center?{id:`${g.parentGroup.pcb_group_id}-${g.component.pcb_component_id}-${g.type}`,anchor:y,anchor_id:g.parentGroup.pcb_group_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:null:g.group.anchor_position?{id:`${g.parentGroup.pcb_group_id}-${g.group.pcb_group_id}-${g.type}`,anchor:y,anchor_id:g.parentGroup.pcb_group_id,target:g.group.anchor_position,type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}:null:null}).filter(g=>!!g);return W.jsx(obe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},tdo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?$Ee([t]):$Ee(o)},ndo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)_P(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),_P(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const c=tdo(a,t);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,A=l?uP(t).pcb_group.get(l):null;s.push({component:a,bbox:c,group:A})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:_A.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const A=dt(n,{x:c.minX,y:c.maxY}),u=dt(n,{x:c.maxX,y:c.minY}),_={x:Math.min(A.x,u.x),y:Math.min(A.y,u.y),width:Math.abs(u.x-A.x),height:Math.abs(u.y-A.y)},h=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},d=dt(n,h);return W.jsxs("g",{children:[W.jsx("rect",{x:_.x,y:_.y,width:_.width,height:_.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:d.x,cy:d.y,r:D0.COMPONENT_MARKER_RADIUS,fill:ox.COMPONENT_MARKER_FILL,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},odo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>$_o(h)),s=t.filter(h=>nbe(h)),a=e.map(h=>nbe(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!x_(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(h=>{const d=h.pcb_panel_id,m=h.position_mode;if(!d||m!=="relative_to_panel_anchor")return null;const p=r.find(g=>g.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(l.length===0)return null;const A=a.length===0,u=l.filter(h=>A||a.includes(h.board.pcb_board_id));if(u.length===0)return null;const _=u.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return W.jsx(obe,{targets:_,transform:n,containerWidth:o,containerHeight:i})},p$=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},LCt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,c=e[i].y;s>t.y!=c>t.y&&t.x<(a-r)*(t.y-s)/(c-s||Number.EPSILON)+r&&(n=!n)}return n},ido=(t,e,n)=>{const o=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=$g({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/n.a;a<l&&o.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=p$(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;LCt(e,a)&&o.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=p$(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;LCt(e,a)&&o.push(i);continue}if(!("x"in i&&"y"in i))continue;let r=0,s=0;if("w"in i&&"h"in i)r=i.w,s=i.h;else if("r"in i)r=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)r=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<r/2&&Math.abs(i.y-e.y)<s/2&&o.push(i)}return o},rdo=({elements:t,children:e,transform:n,primitives:o,onMouseHoverOverPrimitives:i})=>{const[r,s]=te.useState([]),[a,c]=te.useState({x:0,y:0}),[l,{width:A,height:u}]=EL(),_=te.useMemo(()=>{const d=[];for(const m of r){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,g=0,y=0;if(m.pcb_drawing_type==="polygon"){const E=p$(m.points);if(!E)continue;p=E.center,g=E.width,y=E.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const E=m.brep_shape.outer_ring.vertices.map(P=>({x:P.x,y:P.y})),b=p$(E);if(!b)continue;p=b.center,g=b.width,y=b.height}else"x"in m&&"y"in m&&(p={x:m.x,y:m.y},g="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,y="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const f=dt(n,p),x={w:g*n.a,h:y*n.a},I=d.filter(E=>f.x===E.screen_x&&f.y===E.screen_y&&x.w===E.screen_w&&x.h===E.screen_h).length;d.push({...m,x:p.x,y:p.y,w:g,h:y,screen_x:f.x,screen_y:f.y,screen_w:x.w,screen_h:x.h,same_space_index:I})}return d},[r,n]),h=(d,m,p,g)=>{c({x:d,y:m});const y=dt(Ry(p),{x:d,y:m}),f=ido(g,y,p);V_o(new Set(f.map(x=>x._pcb_drawing_object_id)),new Set(r.map(x=>x._pcb_drawing_object_id)))||(s(f),i(f))};return W.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:d=>{if(n){const m=d.currentTarget.getBoundingClientRect(),p=d.clientX-m.left,g=d.clientY-m.top;h(p,g,n,o)}},onTouchStart:d=>{if(n){const m=d.touches[0],p=d.currentTarget.getBoundingClientRect(),g=m.clientX-p.left,y=m.clientY-p.top;h(g,y,n,o)}},children:[e,W.jsx(q_o,{elements:t,mousePos:a,highlightedPrimitives:_}),n&&W.jsxs(W.Fragment,{children:[W.jsx(Z_o,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),W.jsx(edo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),W.jsx(ndo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),W.jsx(odo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u})]})]})},FCt=["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)"],sdo=({children:t,transform:e=rA(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=EL(),a=te.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:A}=x_(u=>({is_showing_pcb_groups:u.is_showing_pcb_groups,pcb_group_view_mode:u.pcb_group_view_mode,is_showing_group_anchor_offsets:u.is_showing_group_anchor_offsets}));return te.useEffect(()=>{const u=a.current;if(!u||!r||!s)return;u.width=r,u.height=s;const _=u.getContext("2d");if(!_||(_.clearRect(0,0,r,s),!c))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),m=n.filter(E=>E.type==="source_group"),p=new Map(m.map(E=>[E.source_group_id,E])),g=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!E.source_group_id)return!1;const b=p.get(E.source_group_id);return b?b.was_automatically_named!==!0:!1}),y=new Map;m.forEach(E=>{const b=E;if(b.parent_source_group_id){const P=y.get(b.parent_source_group_id)||[];P.push(E.source_group_id),y.set(b.parent_source_group_id,P)}});const f=E=>{const b=[],P=y.get(E)||[];for(const B of P)b.push(B),b.push(...f(B));return b},x=E=>{const b=m.find(P=>P.source_group_id===E);return b?.parent_source_group_id?1+x(b.parent_source_group_id):0},I=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const b=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;b&&I.add(b)}g.forEach((E,b)=>{let P=d.filter(De=>De.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const De=f(E.source_group_id),ze=h.filter(Re=>Re.source_group_id&&De.includes(Re.source_group_id));for(const Re of ze){const Se=d.filter(we=>we.pcb_group_id===Re.pcb_group_id);P=[...P,...Se]}}let B,w,k,N,F=!1;if(E.center&&E.width&&E.height){F=!0;const De=E.width/2,ze=E.height/2;B=E.center.x-De,k=E.center.x+De,w=E.center.y-ze,N=E.center.y+ze}else if(P.length===0||(B=1/0,w=1/0,k=-1/0,N=-1/0,P.forEach(De=>{if(De.center&&typeof De.width=="number"&&typeof De.height=="number"){const ze=De.center.x-De.width/2,Re=De.center.x+De.width/2,Se=De.center.y+De.height/2,we=De.center.y-De.height/2;B=Math.min(B,ze),k=Math.max(k,Re),w=Math.min(w,we),N=Math.max(N,Se)}}),B===1/0||k===-1/0))return;const O=E.source_group_id?x(E.source_group_id):0,G=E.source_group_id?f(E.source_group_id).length>0:!1;if(!F){const Re=1+(G?.5:0);B-=Re,k+=Re,w-=Re,N+=Re}const K=dt(e,{x:B,y:N}),X=dt(e,{x:k,y:N}),$=dt(e,{x:B,y:w}),oe=dt(e,{x:k,y:w}),Ae=FCt[b%FCt.length];_.strokeStyle=Ae,_.lineWidth=2;const Z=Math.max(4,Math.min(12,8*Math.abs(e.a))),se=Math.max(2,Math.min(6,4*Math.abs(e.a))),ce=Z*(G?1.3:1),ge=se;_.setLineDash([ce,ge]),_.beginPath(),_.moveTo(K.x,K.y),_.lineTo(X.x,X.y),_.lineTo(oe.x,oe.y),_.lineTo($.x,$.y),_.closePath(),_.stroke();const be=Math.max(8,Math.min(12,10*Math.abs(e.a))),ve=O==0||O==1?0:O*.11,Be=be*(1-ve),ue=4,Ie=E.name||`Group ${b+1}`;_.font=`${Be}px sans-serif`,_.setLineDash([]);const Le=_.measureText(Ie).width+ue*2,Ue=Be+ue*2,je=K.x-5,ye=K.y-5,$e=3;if(_.fillStyle="rgba(0, 0, 0, 0.8)",_.beginPath(),_.roundRect(je,ye-Ue,Le,Ue,$e),_.fill(),_.fillStyle=Ae,_.textAlign="left",_.textBaseline="middle",_.fillText(Ie,je+ue,ye-Ue/2),A&&I.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const De=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},ze=dt(e,De);_.strokeStyle="white",_.lineWidth=1.5,_.setLineDash([]);const Re=Math.max(4,Math.min(8,6*Math.abs(e.a)));_.beginPath(),_.moveTo(ze.x-Re,ze.y),_.lineTo(ze.x+Re,ze.y),_.stroke(),_.beginPath(),_.moveTo(ze.x,ze.y-Re),_.lineTo(ze.x,ze.y+Re),_.stroke()}})},[n,e,r,s,c,l,A,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:_A.pcbGroupOverlay,display:c?"block":"none"}})]})},ado=({transform:t,soup:e,children:n})=>{const o=x_(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=te.useMemo(()=>lCt(e||[]),[e]),s=te.useMemo(()=>{if(!e||!o)return[];const a=_=>{const h=uP(e)[_.replace(/_\d+$/,"")].get(_);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},c=(_,h)=>{const d=i[h]||[];let m=null,p=1/0;return d.forEach(g=>{const y=a(g);if(y){const f=Math.sqrt((_.x-y.x)**2+(_.y-y.y)**2);f<p&&f>0&&(p=f,m=y)}}),m},l=uP(e).pcb_port.list(),A=uP(e).source_trace.list(),u=[];return l.forEach((_,h)=>{const d=r[_.pcb_port_id];let m=!1;for(const y of A)y.connected_source_port_ids.includes(_.source_port_id)&&y.connected_source_net_ids.length>0&&(m=!0);if(!d)return;const p={x:_.x,y:_.y},g=c(p,d);g&&u.push({key:`${_.pcb_port_id}-${h}`,startPoint:p,endPoint:g,isInNet:m})}),u},[e,i,r,o]);return!e||!o?n:(t||(t=rA()),W.jsxs("div",{style:{position:"relative"},children:[n,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:_A.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:A})=>{const u=dt(t,c),_=dt(t,l);return W.jsx("line",{x1:u.x,y1:u.y,x2:_.x,y2:_.y,stroke:"white",strokeWidth:"1",strokeDasharray:A?"6,6":void 0},a)})})]}))},cdo={version:"1.11.370"},dP=(t,e,n)=>{const o=x_(s=>s.is_mouse_over_container),i=te.useRef(o),r=te.useRef(e);te.useEffect(()=>{i.current=o},[o]),te.useEffect(()=>{r.current=e},[e]),te.useEffect(()=>{if(!t)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=t.split("+"),A=l.includes("ctrl"),u=l.includes("shift"),_=l.includes("alt"),h=l.includes("meta"),d=l[l.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!A||a.ctrlKey)&&(!u||a.shiftKey)&&(!_||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},ldo=()=>{const[t,e]=te.useState(!1);return te.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},SL=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),o=te.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=te.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},hP=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=SL(n);return W.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},Ado=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:vD(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},udo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=te.useRef(null),r=te.useRef(null),s=te.useRef(null),a=te.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);te.useEffect(()=>a,[a]);const c=te.useCallback(A=>{a(),s.current=A,e(A),n(null),r.current=window.requestAnimationFrame(()=>{n(A),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),l=te.useCallback(A=>s.current===A,[]);return{handleErrorSelect:c,isSelectedError:l}},_do=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=SL(()=>o(e,t));return W.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?W.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:W.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},ddo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,c]=te.useState(null),[l,A]=te.useState(new Set),[u,_]=te.useState(new Set),[,h]=q0o(),{handleErrorSelect:d,isSelectedError:m}=udo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),p=te.useMemo(()=>t?.filter(I=>I.type.includes("error"))??[],[t]),g=p.length,y=te.useMemo(()=>Ado(p),[p]),f=te.useCallback(I=>{A(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]),x=te.useCallback(I=>{_(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]);return W.jsxs("div",{style:{position:"relative"},children:[W.jsx(hP,{isSmallScreen:n,style:g>0?{color:"red"}:void 0,onClick:o,children:W.jsxs("div",{children:[g," errors"]})}),e&&g>0&&W.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:y.map(({errorType:I,errors:E},b)=>{const P=l.has(I);return W.jsxs("div",{style:{borderBottom:b<y.length-1?"1px solid #444":"none"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:B=>{B.currentTarget.style.backgroundColor="#303030"},onMouseLeave:B=>{B.currentTarget.style.backgroundColor="#232323"},onTouchStart:B=>{B.stopPropagation(),B.currentTarget.style.backgroundColor="#303030"},onTouchEnd:B=>{B.stopPropagation(),B.preventDefault(),B.currentTarget.style.backgroundColor="#232323",f(I)},onClick:B=>{B.stopPropagation(),f(I)},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[W.jsx("div",{style:{color:"#888",fontSize:"16px",transform:P?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),W.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:I})]}),W.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!P&&E.map(({error:B,index:w,errorId:k})=>{const N=u.has(k),F=B.message??"No error message";return W.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:O=>{O.currentTarget.style.backgroundColor="#333",r(k)},onMouseLeave:O=>{O.currentTarget.style.backgroundColor="#2a2a2a",m(k)||r(null)},onTouchStart:O=>{O.stopPropagation(),O.currentTarget.style.backgroundColor="#333",r(k)},onTouchEnd:O=>{O.stopPropagation(),O.preventDefault(),O.currentTarget.style.backgroundColor="#2a2a2a",d(k)},onClick:O=>{O.stopPropagation(),d(k)},children:[W.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:F}),W.jsx("button",{type:"button","aria-label":N?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:N?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:O=>O.stopPropagation(),onClick:O=>{O.stopPropagation(),x(k)},onTouchEnd:O=>{O.stopPropagation(),O.preventDefault(),x(k)},children:"›"})]}),N&&W.jsxs("div",{"data-error-id":w,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[W.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:O=>O.stopPropagation(),onClick:O=>O.stopPropagation(),children:F}),W.jsx(_do,{errorId:k,errorMessage:F,copiedErrorId:a,onCopy:(O,G)=>{h(O),c(G),setTimeout(()=>c(null),2e3)}})]})]},k)})]},I)})})]})},hdo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=SL(n);return W.jsxs("div",{className:PD`
5527
+ `,U_o=({children:t,transform:e=rA(),elements:n})=>{const o=te.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=x_(m=>({isShowingDRCErrors:m.is_showing_drc_errors,hoveredErrorId:m.hovered_error_id,focusedErrorId:m.focused_error_id})),a=s??r;if(!n)return W.jsx("div",{style:{position:"relative"},ref:o,children:t});const c=n.filter(m=>m.type==="pcb_trace_error"&&!m.message?.includes("Multiple components found with name")),l=n.filter(m=>m.type==="pcb_via_clearance_error"),A=n.filter(m=>m.type==="pcb_trace_error"&&m.message?.includes("Multiple components found with name")),u=uCt(n),_=ACt(n,a),h=m=>{const p=Auo({error:m,indexes:u});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const g=dt(e,p);return Number.isNaN(g.x)||Number.isNaN(g.y)?null:g};let d=null;return _&&(d=h(_)),W.jsxs("div",{style:{position:"relative"},ref:o,children:[t,c.map((m,p)=>{const g=vD(m,p),y=a===g;if(!y&&!i)return null;const f=h(m);if(!f)return null;const x=ebe(f,o);return W.jsxs(te.Fragment,{children:[W.jsx(kCt,{errorCenter:f,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:_A.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!y){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?200:100,left:x.left,top:x.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||y?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:W.jsx("div",{className:`error-message ${tbe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:m.message})})]},g)}),l.map((m,p)=>{const g=vD(m,p),y=a===g;if(!y&&!i)return null;const f=h(m);if(!f)return null;const x=ebe({x:f.x,y:f.y},o);return W.jsxs(te.Fragment,{children:[W.jsx(kCt,{errorCenter:f,isHighlighted:y}),W.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:_A.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!y){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:y?_A.errorOverlay+10:_A.errorOverlay+1,left:x.left,top:x.top,color:y?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:W.jsx("div",{className:`error-message ${tbe}`,style:{opacity:y?1:0,border:`1px solid ${y?"#ff4444":"red"}`},children:m.message})})]},g)}),A.map((m,p)=>{const g=m.component_name||m.message?.match(/name "([^"]+)"/)?.[1];if(!g)return null;const y=n?.filter(I=>I.type==="source_component"&&I.name===g||I.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===I.source_component_id&&E.name===g))||[],f=vD(m,p),x=a===f;return!x&&!i?null:y.map((I,E)=>{let b={x:0,y:0};if(I.type==="pcb_component")b=I.center||{x:0,y:0};else if(I.type==="source_component"){const G=n?.find(K=>K.type==="pcb_component"&&K.source_component_id===I.source_component_id);G&&G.type==="pcb_component"&&(b=G.center||{x:0,y:0})}const P=dt(e,b);if(Number.isNaN(P.x)||Number.isNaN(P.y))return null;const B=Math.abs(e.a),F=Math.max(8,Math.min(30,.5*B)),O=ebe(P,o);return W.jsxs(te.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:_A.errorOverlay},width:"100%",height:"100%",children:x?W.jsx("polygon",{points:`${P.x},${P.y-F*1.25} ${P.x+F},${P.y} ${P.x},${P.y+F*1.25} ${P.x-F},${P.y}`,fill:"#ff4444"}):W.jsx("circle",{cx:P.x,cy:P.y,r:F,fill:"none",stroke:x?"#ff4444":"red",strokeWidth:x?Math.max(2,F*.15):Math.max(1,F*.1),opacity:1})}),W.jsx("div",{style:{position:"absolute",left:P.x-(F+10),top:P.y-(F+10),width:(F+10)*2,height:(F+10)*2,zIndex:_A.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const K=G.currentTarget.nextElementSibling;if(K){const X=K.querySelector(".error-message");X&&(X.style.opacity="1")}},onMouseLeave:G=>{if(!x){const K=G.currentTarget.nextElementSibling;if(K){const X=K.querySelector(".error-message");X&&(X.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:x?_A.errorOverlay+20:_A.errorOverlay+10,left:O.left,top:O.top,color:x?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||x?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:O.transform},children:W.jsx("div",{className:`error-message ${tbe}`,style:{opacity:x?1:0,border:`1px solid ${x?"#ff4444":"red"}`},children:m.message})})]},`${f}_${E}`)})}),d&&W.jsx(z_o,{center:d})]})};function V_o(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function Y_o({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const o=uP(e).source_trace.get(t?.source_trace_id);if(o?.display_name&&(o?.max_length?n+=` / ${o.max_length}mm `:n+=" mm ",n+=`(${o.display_name})`),!n)return null;const i=t.trace_length&&o?.max_length&&t.trace_length>o.max_length;return{text:n,isOverLength:i}}function K_o(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(c=>c._element.type==="pcb_trace"),r=o.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>r.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!n)return[...s,...a];if(i.length>1){const c=i.reduce((l,A)=>{const u=l._element.trace_length;return A._element.trace_length<u?A:l},i[0]);return[...s,c]}return e}var W_o={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},j_o=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(c=>`${a}.${c}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},X_o={top:"red",bottom:"aqua"},J_o=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=te.useState(!1),r=t._element;te.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],A=t.same_space_index??0,u=26,_=X_o[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const p=Y_o({primitiveElement:r,elements:n});if(!p)return null;const g=e.y-35;return W.jsx("div",{style:{zIndex:_A.elementOverlay,position:"absolute",left:e.x,top:g,color:_,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:p.text})})}const d=j_o(t);return d.trim().length===0?null:W.jsx("div",{style:{zIndex:_A.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:_,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:o?`calc(100% + ${u*2*A}px)`:"100%",height:o?`calc(100% + ${u*2*A}px)`:"100%",marginLeft:o?`${-u*A}px`:0,marginTop:o?`${-u*A}px`:0,border:`1px solid ${_}`,opacity:o||A===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:l+20+u*A,marginRight:o?`${-u*A}px`:0,marginBottom:o?0:-u*A,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},q_o=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=x_(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=K_o({primitives:s,is_showing_multiple_traces_length:i,elements:n}),W.jsx("div",{style:W_o,children:!o&&s.map((a,c)=>W.jsx(J_o,{primitive:a,mousePos:e,elements:n},c))})},_P=t=>t?.type==="pcb_component",HCt=t=>t?.type==="pcb_group",$_o=t=>t?.type==="pcb_panel",nbe=t=>t?.type==="pcb_board",D0={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},ox={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},obe=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:ox.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:D0.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=dt(e,s.anchor);r.set(s.anchor_id,a)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:_A.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,A=r.get(c),u=dt(e,l),_=l.x-a.x,h=l.y-a.y,d=Math.abs(u.x-A.x),m=Math.abs(u.y-A.y),p=u.y<A.y,g=u.x>A.x,y=p?D0.LABEL_OFFSET_ABOVE:D0.LABEL_OFFSET_BELOW,f=g?D0.LABEL_OFFSET_RIGHT:D0.LABEL_OFFSET_LEFT,x=d>D0.MIN_LINE_LENGTH_FOR_LABEL,I=m>D0.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??_.toFixed(2)}mm`,b=`${s.display_offset_y??h.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:A.x,y1:A.y,x2:u.x,y2:A.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.LINE_STROKE_WIDTH,strokeDasharray:D0.LINE_DASH_PATTERN}),W.jsx("line",{x1:u.x,y1:A.y,x2:u.x,y2:u.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.LINE_STROKE_WIDTH,strokeDasharray:D0.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:u.x,cy:u.y,r:D0.COMPONENT_MARKER_RADIUS,fill:ox.COMPONENT_MARKER_FILL,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:u.x-D0.ANCHOR_MARKER_SIZE,y1:u.y,x2:u.x+D0.ANCHOR_MARKER_SIZE,y2:u.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:u.x,y1:u.y-D0.ANCHOR_MARKER_SIZE,x2:u.x,y2:u.y+D0.ANCHOR_MARKER_SIZE,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH})]}),x&&W.jsx("foreignObject",{x:Math.min(A.x,u.x),y:A.y+y,width:Math.abs(u.x-A.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...i,textAlign:"center"},children:E})}),I&&W.jsx("foreignObject",{x:u.x+f,y:Math.min(A.y,u.y),width:D0.Y_LABEL_MIN_WIDTH,height:Math.abs(u.y-A.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:g?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:b})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>W.jsxs("g",{children:[W.jsx("line",{x1:a.x-D0.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+D0.ANCHOR_MARKER_SIZE,y2:a.y,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:a.x,y1:a.y-D0.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+D0.ANCHOR_MARKER_SIZE,stroke:ox.OFFSET_LINE,strokeWidth:D0.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},Z_o=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>nbe(g)),s=t.filter(g=>_P(g)),a=t.filter(g=>HCt(g)),c=e.map(g=>_P(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:_P(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),l=new Set;if(c.forEach(g=>{const y=s.find(f=>f.pcb_component_id===g);y?.pcb_group_id&&l.add(y.pcb_group_id)}),!x_(g=>g.is_showing_group_anchor_offsets)&&c.length===0)return null;const u=s.map(g=>{const y=g.positioned_relative_to_pcb_board_id;if(!y)return null;const f=r.find(x=>x.pcb_board_id===y);return f?{component:g,board:f,type:"component"}:null}).filter(g=>!!g),_=a.map(g=>{const y=g.positioned_relative_to_pcb_board_id;if(!y||!g.center)return null;const f=r.find(x=>x.pcb_board_id===y);return f?{group:g,board:f,type:"group"}:null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=c.length===0,m=h.filter(g=>g.type==="component"?d||c.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>g.type==="component"?{id:`${g.board.pcb_board_id}-${g.component.pcb_component_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:{id:`${g.board.pcb_board_id}-${g.group.pcb_group_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:{x:g.group.anchor_position?.x??g.group.center.x,y:g.group.anchor_position?.y??g.group.center.y},type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}).filter(g=>!!g);return W.jsx(obe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},edo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>HCt(g)),s=t.filter(g=>_P(g)),a=e.map(g=>_P(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:_P(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),c=(g,y)=>{if(y.has(g))return;y.add(g);const f=r.find(x=>x.pcb_group_id===g);f?.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&c(f.positioned_relative_to_pcb_group_id,y)},l=new Set;if(a.forEach(g=>{const y=s.find(f=>f.pcb_component_id===g);y&&(y.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id&&c(y.positioned_relative_to_pcb_group_id,l),y.pcb_group_id&&c(y.pcb_group_id,l))}),!x_(g=>g.is_showing_group_anchor_offsets)&&a.length===0)return null;const u=s.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const y=r.find(f=>f.pcb_group_id===g.positioned_relative_to_pcb_group_id);return y&&y.anchor_position?{component:g,parentGroup:y,type:"component"}:null}if(g.pcb_group_id){const y=r.find(f=>f.pcb_group_id===g.pcb_group_id);return y&&y.anchor_position?{component:g,parentGroup:y,type:"component"}:null}return null}).filter(g=>!!g),_=r.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const y=r.find(f=>f.pcb_group_id===g.positioned_relative_to_pcb_group_id);if(y&&y.anchor_position&&g.anchor_position)return{group:g,parentGroup:y,type:"group"}}return null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=a.length===0,m=h.filter(g=>g.type==="component"?d||a.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id)||l.has(g.parentGroup.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>{const y=g.parentGroup.anchor_position;return y?g.type==="component"?g.component.center?{id:`${g.parentGroup.pcb_group_id}-${g.component.pcb_component_id}-${g.type}`,anchor:y,anchor_id:g.parentGroup.pcb_group_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:null:g.group.anchor_position?{id:`${g.parentGroup.pcb_group_id}-${g.group.pcb_group_id}-${g.type}`,anchor:y,anchor_id:g.parentGroup.pcb_group_id,target:g.group.anchor_position,type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}:null:null}).filter(g=>!!g);return W.jsx(obe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},tdo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?$Ee([t]):$Ee(o)},ndo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)_P(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),_P(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const c=tdo(a,t);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,A=l?uP(t).pcb_group.get(l):null;s.push({component:a,bbox:c,group:A})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:_A.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const A=dt(n,{x:c.minX,y:c.maxY}),u=dt(n,{x:c.maxX,y:c.minY}),_={x:Math.min(A.x,u.x),y:Math.min(A.y,u.y),width:Math.abs(u.x-A.x),height:Math.abs(u.y-A.y)},h=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},d=dt(n,h);return W.jsxs("g",{children:[W.jsx("rect",{x:_.x,y:_.y,width:_.width,height:_.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:d.x,cy:d.y,r:D0.COMPONENT_MARKER_RADIUS,fill:ox.COMPONENT_MARKER_FILL,stroke:ox.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},odo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>$_o(h)),s=t.filter(h=>nbe(h)),a=e.map(h=>nbe(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!x_(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(h=>{const d=h.pcb_panel_id,m=h.position_mode;if(!d||m!=="relative_to_panel_anchor")return null;const p=r.find(g=>g.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(l.length===0)return null;const A=a.length===0,u=l.filter(h=>A||a.includes(h.board.pcb_board_id));if(u.length===0)return null;const _=u.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return W.jsx(obe,{targets:_,transform:n,containerWidth:o,containerHeight:i})},p$=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},LCt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,c=e[i].y;s>t.y!=c>t.y&&t.x<(a-r)*(t.y-s)/(c-s||Number.EPSILON)+r&&(n=!n)}return n},ido=(t,e,n)=>{const o=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=$g({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/n.a;a<l&&o.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=p$(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;LCt(e,a)&&o.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=p$(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;LCt(e,a)&&o.push(i);continue}if(!("x"in i&&"y"in i))continue;let r=0,s=0;if("w"in i&&"h"in i)r=i.w,s=i.h;else if("r"in i)r=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)r=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<r/2&&Math.abs(i.y-e.y)<s/2&&o.push(i)}return o},rdo=({elements:t,children:e,transform:n,primitives:o,onMouseHoverOverPrimitives:i})=>{const[r,s]=te.useState([]),[a,c]=te.useState({x:0,y:0}),[l,{width:A,height:u}]=EL(),_=te.useMemo(()=>{const d=[];for(const m of r){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,g=0,y=0;if(m.pcb_drawing_type==="polygon"){const E=p$(m.points);if(!E)continue;p=E.center,g=E.width,y=E.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const E=m.brep_shape.outer_ring.vertices.map(P=>({x:P.x,y:P.y})),b=p$(E);if(!b)continue;p=b.center,g=b.width,y=b.height}else"x"in m&&"y"in m&&(p={x:m.x,y:m.y},g="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,y="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const f=dt(n,p),x={w:g*n.a,h:y*n.a},I=d.filter(E=>f.x===E.screen_x&&f.y===E.screen_y&&x.w===E.screen_w&&x.h===E.screen_h).length;d.push({...m,x:p.x,y:p.y,w:g,h:y,screen_x:f.x,screen_y:f.y,screen_w:x.w,screen_h:x.h,same_space_index:I})}return d},[r,n]),h=(d,m,p,g)=>{c({x:d,y:m});const y=dt(Ry(p),{x:d,y:m}),f=ido(g,y,p);V_o(new Set(f.map(x=>x._pcb_drawing_object_id)),new Set(r.map(x=>x._pcb_drawing_object_id)))||(s(f),i(f))};return W.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:d=>{if(n){const m=d.currentTarget.getBoundingClientRect(),p=d.clientX-m.left,g=d.clientY-m.top;h(p,g,n,o)}},onTouchStart:d=>{if(n){const m=d.touches[0],p=d.currentTarget.getBoundingClientRect(),g=m.clientX-p.left,y=m.clientY-p.top;h(g,y,n,o)}},children:[e,W.jsx(q_o,{elements:t,mousePos:a,highlightedPrimitives:_}),n&&W.jsxs(W.Fragment,{children:[W.jsx(Z_o,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),W.jsx(edo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),W.jsx(ndo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),W.jsx(odo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u})]})]})},FCt=["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)"],sdo=({children:t,transform:e=rA(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=EL(),a=te.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:A}=x_(u=>({is_showing_pcb_groups:u.is_showing_pcb_groups,pcb_group_view_mode:u.pcb_group_view_mode,is_showing_group_anchor_offsets:u.is_showing_group_anchor_offsets}));return te.useEffect(()=>{const u=a.current;if(!u||!r||!s)return;u.width=r,u.height=s;const _=u.getContext("2d");if(!_||(_.clearRect(0,0,r,s),!c))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),m=n.filter(E=>E.type==="source_group"),p=new Map(m.map(E=>[E.source_group_id,E])),g=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!E.source_group_id)return!1;const b=p.get(E.source_group_id);return b?b.was_automatically_named!==!0:!1}),y=new Map;m.forEach(E=>{const b=E;if(b.parent_source_group_id){const P=y.get(b.parent_source_group_id)||[];P.push(E.source_group_id),y.set(b.parent_source_group_id,P)}});const f=E=>{const b=[],P=y.get(E)||[];for(const B of P)b.push(B),b.push(...f(B));return b},x=E=>{const b=m.find(P=>P.source_group_id===E);return b?.parent_source_group_id?1+x(b.parent_source_group_id):0},I=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const b=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;b&&I.add(b)}g.forEach((E,b)=>{let P=d.filter(De=>De.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const De=f(E.source_group_id),ze=h.filter(Re=>Re.source_group_id&&De.includes(Re.source_group_id));for(const Re of ze){const Se=d.filter(we=>we.pcb_group_id===Re.pcb_group_id);P=[...P,...Se]}}let B,w,k,N,F=!1;if(E.center&&E.width&&E.height){F=!0;const De=E.width/2,ze=E.height/2;B=E.center.x-De,k=E.center.x+De,w=E.center.y-ze,N=E.center.y+ze}else if(P.length===0||(B=1/0,w=1/0,k=-1/0,N=-1/0,P.forEach(De=>{if(De.center&&typeof De.width=="number"&&typeof De.height=="number"){const ze=De.center.x-De.width/2,Re=De.center.x+De.width/2,Se=De.center.y+De.height/2,we=De.center.y-De.height/2;B=Math.min(B,ze),k=Math.max(k,Re),w=Math.min(w,we),N=Math.max(N,Se)}}),B===1/0||k===-1/0))return;const O=E.source_group_id?x(E.source_group_id):0,G=E.source_group_id?f(E.source_group_id).length>0:!1;if(!F){const Re=1+(G?.5:0);B-=Re,k+=Re,w-=Re,N+=Re}const K=dt(e,{x:B,y:N}),X=dt(e,{x:k,y:N}),$=dt(e,{x:B,y:w}),oe=dt(e,{x:k,y:w}),Ae=FCt[b%FCt.length];_.strokeStyle=Ae,_.lineWidth=2;const Z=Math.max(4,Math.min(12,8*Math.abs(e.a))),se=Math.max(2,Math.min(6,4*Math.abs(e.a))),ce=Z*(G?1.3:1),ge=se;_.setLineDash([ce,ge]),_.beginPath(),_.moveTo(K.x,K.y),_.lineTo(X.x,X.y),_.lineTo(oe.x,oe.y),_.lineTo($.x,$.y),_.closePath(),_.stroke();const be=Math.max(8,Math.min(12,10*Math.abs(e.a))),ve=O==0||O==1?0:O*.11,Be=be*(1-ve),ue=4,Ie=E.name||`Group ${b+1}`;_.font=`${Be}px sans-serif`,_.setLineDash([]);const Le=_.measureText(Ie).width+ue*2,Ue=Be+ue*2,je=K.x-5,ye=K.y-5,$e=3;if(_.fillStyle="rgba(0, 0, 0, 0.8)",_.beginPath(),_.roundRect(je,ye-Ue,Le,Ue,$e),_.fill(),_.fillStyle=Ae,_.textAlign="left",_.textBaseline="middle",_.fillText(Ie,je+ue,ye-Ue/2),A&&I.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const De=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},ze=dt(e,De);_.strokeStyle="white",_.lineWidth=1.5,_.setLineDash([]);const Re=Math.max(4,Math.min(8,6*Math.abs(e.a)));_.beginPath(),_.moveTo(ze.x-Re,ze.y),_.lineTo(ze.x+Re,ze.y),_.stroke(),_.beginPath(),_.moveTo(ze.x,ze.y-Re),_.lineTo(ze.x,ze.y+Re),_.stroke()}})},[n,e,r,s,c,l,A,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:_A.pcbGroupOverlay,display:c?"block":"none"}})]})},ado=({transform:t,soup:e,children:n})=>{const o=x_(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=te.useMemo(()=>lCt(e||[]),[e]),s=te.useMemo(()=>{if(!e||!o)return[];const a=_=>{const h=uP(e)[_.replace(/_\d+$/,"")].get(_);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},c=(_,h)=>{const d=i[h]||[];let m=null,p=1/0;return d.forEach(g=>{const y=a(g);if(y){const f=Math.sqrt((_.x-y.x)**2+(_.y-y.y)**2);f<p&&f>0&&(p=f,m=y)}}),m},l=uP(e).pcb_port.list(),A=uP(e).source_trace.list(),u=[];return l.forEach((_,h)=>{const d=r[_.pcb_port_id];let m=!1;for(const y of A)y.connected_source_port_ids.includes(_.source_port_id)&&y.connected_source_net_ids.length>0&&(m=!0);if(!d)return;const p={x:_.x,y:_.y},g=c(p,d);g&&u.push({key:`${_.pcb_port_id}-${h}`,startPoint:p,endPoint:g,isInNet:m})}),u},[e,i,r,o]);return!e||!o?n:(t||(t=rA()),W.jsxs("div",{style:{position:"relative"},children:[n,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:_A.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:A})=>{const u=dt(t,c),_=dt(t,l);return W.jsx("line",{x1:u.x,y1:u.y,x2:_.x,y2:_.y,stroke:"white",strokeWidth:"1",strokeDasharray:A?"6,6":void 0},a)})})]}))},cdo={version:"1.11.371"},dP=(t,e,n)=>{const o=x_(s=>s.is_mouse_over_container),i=te.useRef(o),r=te.useRef(e);te.useEffect(()=>{i.current=o},[o]),te.useEffect(()=>{r.current=e},[e]),te.useEffect(()=>{if(!t)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=t.split("+"),A=l.includes("ctrl"),u=l.includes("shift"),_=l.includes("alt"),h=l.includes("meta"),d=l[l.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!A||a.ctrlKey)&&(!u||a.shiftKey)&&(!_||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},ldo=()=>{const[t,e]=te.useState(!1);return te.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},SL=(t,e={stopPropagation:!0})=>{const n=te.useRef(0),o=te.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=te.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},hP=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=SL(n);return W.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},Ado=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:vD(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},udo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=te.useRef(null),r=te.useRef(null),s=te.useRef(null),a=te.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);te.useEffect(()=>a,[a]);const c=te.useCallback(A=>{a(),s.current=A,e(A),n(null),r.current=window.requestAnimationFrame(()=>{n(A),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),l=te.useCallback(A=>s.current===A,[]);return{handleErrorSelect:c,isSelectedError:l}},_do=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=SL(()=>o(e,t));return W.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?W.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:W.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},ddo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,c]=te.useState(null),[l,A]=te.useState(new Set),[u,_]=te.useState(new Set),[,h]=q0o(),{handleErrorSelect:d,isSelectedError:m}=udo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),p=te.useMemo(()=>t?.filter(I=>I.type.includes("error"))??[],[t]),g=p.length,y=te.useMemo(()=>Ado(p),[p]),f=te.useCallback(I=>{A(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]),x=te.useCallback(I=>{_(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]);return W.jsxs("div",{style:{position:"relative"},children:[W.jsx(hP,{isSmallScreen:n,style:g>0?{color:"red"}:void 0,onClick:o,children:W.jsxs("div",{children:[g," errors"]})}),e&&g>0&&W.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:y.map(({errorType:I,errors:E},b)=>{const P=l.has(I);return W.jsxs("div",{style:{borderBottom:b<y.length-1?"1px solid #444":"none"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:B=>{B.currentTarget.style.backgroundColor="#303030"},onMouseLeave:B=>{B.currentTarget.style.backgroundColor="#232323"},onTouchStart:B=>{B.stopPropagation(),B.currentTarget.style.backgroundColor="#303030"},onTouchEnd:B=>{B.stopPropagation(),B.preventDefault(),B.currentTarget.style.backgroundColor="#232323",f(I)},onClick:B=>{B.stopPropagation(),f(I)},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[W.jsx("div",{style:{color:"#888",fontSize:"16px",transform:P?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),W.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:I})]}),W.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!P&&E.map(({error:B,index:w,errorId:k})=>{const N=u.has(k),F=B.message??"No error message";return W.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[W.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:O=>{O.currentTarget.style.backgroundColor="#333",r(k)},onMouseLeave:O=>{O.currentTarget.style.backgroundColor="#2a2a2a",m(k)||r(null)},onTouchStart:O=>{O.stopPropagation(),O.currentTarget.style.backgroundColor="#333",r(k)},onTouchEnd:O=>{O.stopPropagation(),O.preventDefault(),O.currentTarget.style.backgroundColor="#2a2a2a",d(k)},onClick:O=>{O.stopPropagation(),d(k)},children:[W.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:F}),W.jsx("button",{type:"button","aria-label":N?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:N?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:O=>O.stopPropagation(),onClick:O=>{O.stopPropagation(),x(k)},onTouchEnd:O=>{O.stopPropagation(),O.preventDefault(),x(k)},children:"›"})]}),N&&W.jsxs("div",{"data-error-id":w,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[W.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:O=>O.stopPropagation(),onClick:O=>O.stopPropagation(),children:F}),W.jsx(_do,{errorId:k,errorMessage:F,copiedErrorId:a,onCopy:(O,G)=>{h(O),c(G),setTimeout(()=>c(null),2e3)}})]})]},k)})]},I)})})]})},hdo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=SL(n);return W.jsxs("div",{className:PD`
5528
5528
  margin-top: 2px;
5529
5529
  padding: 4px;
5530
5530
  padding-left: 8px;
@@ -5741,7 +5741,7 @@ test("${l} should solve problem correctly", () => {
5741
5741
  // Add more specific assertions based on expected output
5742
5742
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5743
5743
  })
5744
- `,u=new Blob([A],{type:"text/plain"}),_=URL.createObjectURL(u),h=document.createElement("a");h.href=_,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(_)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&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:r,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:a,children:"Download test.ts"})]})]})},qCt=t=>t.activeSubSolver?[t,...qCt(t.activeSubSolver)]:[t],Who=({solver:t})=>{const e=qCt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(Kho,{solver:n})]},n.constructor.name))})},jho=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(m=>!m,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},_=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?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(Who,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:_,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),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"]}),d&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:d})]}),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]})]})},Xho=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Jho=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Xho(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const _=t.pipelineDef[e+1],h=_?t.firstIterationOfPhase?.[_.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},qho=({status:t})=>{const e={"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 ${e[t]}`,children:t})},$ho=({progress:t})=>{if(t===0)return null;const e=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:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Zho=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),emo=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=Zho(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},ube=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ube);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=ube(o));return e},tmo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=ube(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},nmo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>Jho(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):tmo(a.solverInstance,a.name))},s=a=>`${(a/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:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.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(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.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:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(qho,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx($ho,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(emo,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.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})]},a.name))})]})})]})},omo=class extends Qi.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 imo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const y of g)A(y.x,y.y)}for(const p of o){const g=p.x??0,y=p.y??0,f=p.width??0,x=p.height??0;A(g,y),A(g+f,y+x)}for(const p of i){const g=p.x??0,y=p.y??0,f=p.radius??1;A(g-f,y-f),A(g+f,y+f)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,_=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>W.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>W.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(y=>`${y.x??0},${y.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>W.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var rmo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=te.useReducer(A=>A+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(_=>_.solverName===A);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(jho,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(omo,{fallback:W.jsx(imo,{graphics:s}),children:W.jsx(Yho,{graphics:s})}),c&&W.jsx(nmo,{solver:t,onStepUntilPhase:l})]})};const smo=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},amo=t=>t.toLowerCase().includes("pack")?TXn:t.toLowerCase().includes("rout")?LXn:EXn,cmo=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);smo();const o=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=jhe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(jhe).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=amo(c.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(A,{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:c.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsx(_3,{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"," ",r.solverName]})]})}),children:W.jsx(rmo,{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:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.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(r.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"})})})]})},$Ct=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{X9.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{X9.captureException(i,{error_type:o.type})}catch{}}},[n])},lmo=t=>{te.useEffect(()=>{try{s6t(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},ZCt="0.0.2068",Amo={version:ZCt},_be={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},dbe=new Map,C$=t=>{const e=dbe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},umo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=dbe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return dbe.set(n.name,i),{type:"tracked",store:t,...i}},e5t=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...c}=e;let l;try{l=(r??(_be?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(_be?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:A,...u}=umo(a,l,c);let _=!0;i.setState=(m,p,g)=>{const y=n(m,p);if(!_)return y;const f=g===void 0?{type:s||"anonymous"}:typeof g=="string"?{type:g}:g;return a===void 0?(A?.send(f,o()),y):(A?.send({...f,type:`${a}/${f.type}`},{...C$(c.name),[a]:i.getState()}),y)};const h=(...m)=>{const p=_;_=!1,n(...m),_=p},d=t(i.setState,o,i);if(u.type==="untracked"?A?.init(d):(u.stores[u.store]=i,A?.init(Object.fromEntries(Object.entries(u.stores).map(([m,p])=>[m,m===u.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(...g)=>{(_be?"production":void 0)!=="production"&&g[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(...g)}}return A.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return hbe(m.payload,g=>{if(g.type==="__setState"){if(a===void 0){h(g.state);return}Object.keys(g.state).length!==1&&console.error(`
5744
+ `,u=new Blob([A],{type:"text/plain"}),_=URL.createObjectURL(u),h=document.createElement("a");h.href=_,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(_)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&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:r,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:a,children:"Download test.ts"})]})]})},qCt=t=>t.activeSubSolver?[t,...qCt(t.activeSubSolver)]:[t],Who=({solver:t})=>{const e=qCt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(Kho,{solver:n})]},n.constructor.name))})},jho=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=te.useReducer(m=>!m,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},_=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?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(Who,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:_,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),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"]}),d&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:d})]}),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]})]})},Xho=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Jho=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Xho(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const _=t.pipelineDef[e+1],h=_?t.firstIterationOfPhase?.[_.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},qho=({status:t})=>{const e={"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 ${e[t]}`,children:t})},$ho=({progress:t})=>{if(t===0)return null;const e=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:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Zho=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),emo=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=Zho(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},ube=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ube);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=ube(o));return e},tmo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=ube(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},nmo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>Jho(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):tmo(a.solverInstance,a.name))},s=a=>`${(a/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:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.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(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.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:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(qho,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx($ho,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(emo,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.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})]},a.name))})]})})]})},omo=class extends Qi.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 imo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const y of g)A(y.x,y.y)}for(const p of o){const g=p.x??0,y=p.y??0,f=p.width??0,x=p.height??0;A(g,y),A(g+f,y+x)}for(const p of i){const g=p.x??0,y=p.y??0,f=p.radius??1;A(g-f,y-f),A(g+f,y+f)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,_=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>W.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>W.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(y=>`${y.x??0},${y.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>W.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var rmo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=te.useReducer(A=>A+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(_=>_.solverName===A);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(jho,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(omo,{fallback:W.jsx(imo,{graphics:s}),children:W.jsx(Yho,{graphics:s})}),c&&W.jsx(nmo,{solver:t,onStepUntilPhase:l})]})};const smo=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},amo=t=>t.toLowerCase().includes("pack")?TXn:t.toLowerCase().includes("rout")?LXn:EXn,cmo=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);smo();const o=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=te.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=te.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=jhe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(jhe).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=amo(c.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(A,{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:c.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsx(_3,{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"," ",r.solverName]})]})}),children:W.jsx(rmo,{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:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.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(r.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"})})})]})},$Ct=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{X9.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{X9.captureException(i,{error_type:o.type})}catch{}}},[n])},lmo=t=>{te.useEffect(()=>{try{s6t(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},ZCt="0.0.2069",Amo={version:ZCt},_be={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},dbe=new Map,C$=t=>{const e=dbe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},umo=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=dbe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return dbe.set(n.name,i),{type:"tracked",store:t,...i}},e5t=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...c}=e;let l;try{l=(r??(_be?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(_be?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:A,...u}=umo(a,l,c);let _=!0;i.setState=(m,p,g)=>{const y=n(m,p);if(!_)return y;const f=g===void 0?{type:s||"anonymous"}:typeof g=="string"?{type:g}:g;return a===void 0?(A?.send(f,o()),y):(A?.send({...f,type:`${a}/${f.type}`},{...C$(c.name),[a]:i.getState()}),y)};const h=(...m)=>{const p=_;_=!1,n(...m),_=p},d=t(i.setState,o,i);if(u.type==="untracked"?A?.init(d):(u.stores[u.store]=i,A?.init(Object.fromEntries(Object.entries(u.stores).map(([m,p])=>[m,m===u.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(...g)=>{(_be?"production":void 0)!=="production"&&g[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(...g)}}return A.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return hbe(m.payload,g=>{if(g.type==="__setState"){if(a===void 0){h(g.state);return}Object.keys(g.state).length!==1&&console.error(`
5745
5745
  [zustand devtools middleware] Unsupported __setState action format.
5746
5746
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5747
5747
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
@@ -5528,7 +5528,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function P5t(t,e,n){if(!e||!n)retu
5528
5528
  transition: opacity 0.2s;
5529
5529
  margin-bottom: 10px;
5530
5530
  color: red;
5531
- `,jmo=({children:t,transform:e=iA(),elements:n})=>{const o=j.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=I_(m=>({isShowingDRCErrors:m.is_showing_drc_errors,hoveredErrorId:m.hovered_error_id,focusedErrorId:m.focused_error_id})),a=s??r;if(!n)return K.jsx("div",{style:{position:"relative"},ref:o,children:t});const c=n.filter(m=>m.type==="pcb_trace_error"&&!m.message?.includes("Multiple components found with name")),l=n.filter(m=>m.type==="pcb_via_clearance_error"),A=n.filter(m=>m.type==="pcb_trace_error"&&m.message?.includes("Multiple components found with name")),u=k5t(n),_=N5t(n,a),h=m=>{const p=mho({error:m,indexes:u});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const g=dt(e,p);return Number.isNaN(g.x)||Number.isNaN(g.y)?null:g};let d=null;return _&&(d=h(_)),K.jsxs("div",{style:{position:"relative"},ref:o,children:[t,c.map((m,p)=>{const g=V7(m,p),f=a===g;if(!f&&!i)return null;const y=h(m);if(!y)return null;const x=cSe(y,o);return K.jsxs(j.Fragment,{children:[K.jsx(aIt,{errorCenter:y,isHighlighted:f}),K.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:gA.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!f){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),K.jsx("div",{style:{position:"absolute",zIndex:f?200:100,left:x.left,top:x.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||f?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:K.jsx("div",{className:`error-message ${lSe}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},g)}),l.map((m,p)=>{const g=V7(m,p),f=a===g;if(!f&&!i)return null;const y=h(m);if(!y)return null;const x=cSe({x:y.x,y:y.y},o);return K.jsxs(j.Fragment,{children:[K.jsx(aIt,{errorCenter:y,isHighlighted:f}),K.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:gA.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!f){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),K.jsx("div",{style:{position:"absolute",zIndex:f?gA.errorOverlay+10:gA.errorOverlay+1,left:x.left,top:x.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:K.jsx("div",{className:`error-message ${lSe}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},g)}),A.map((m,p)=>{const g=m.component_name||m.message?.match(/name "([^"]+)"/)?.[1];if(!g)return null;const f=n?.filter(I=>I.type==="source_component"&&I.name===g||I.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===I.source_component_id&&E.name===g))||[],y=V7(m,p),x=a===y;return!x&&!i?null:f.map((I,E)=>{let b={x:0,y:0};if(I.type==="pcb_component")b=I.center||{x:0,y:0};else if(I.type==="source_component"){const G=n?.find(W=>W.type==="pcb_component"&&W.source_component_id===I.source_component_id);G&&G.type==="pcb_component"&&(b=G.center||{x:0,y:0})}const P=dt(e,b);if(Number.isNaN(P.x)||Number.isNaN(P.y))return null;const B=Math.abs(e.a),L=Math.max(8,Math.min(30,.5*B)),F=cSe(P,o);return K.jsxs(j.Fragment,{children:[K.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:gA.errorOverlay},width:"100%",height:"100%",children:x?K.jsx("polygon",{points:`${P.x},${P.y-L*1.25} ${P.x+L},${P.y} ${P.x},${P.y+L*1.25} ${P.x-L},${P.y}`,fill:"#ff4444"}):K.jsx("circle",{cx:P.x,cy:P.y,r:L,fill:"none",stroke:x?"#ff4444":"red",strokeWidth:x?Math.max(2,L*.15):Math.max(1,L*.1),opacity:1})}),K.jsx("div",{style:{position:"absolute",left:P.x-(L+10),top:P.y-(L+10),width:(L+10)*2,height:(L+10)*2,zIndex:gA.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const W=G.currentTarget.nextElementSibling;if(W){const J=W.querySelector(".error-message");J&&(J.style.opacity="1")}},onMouseLeave:G=>{if(!x){const W=G.currentTarget.nextElementSibling;if(W){const J=W.querySelector(".error-message");J&&(J.style.opacity="0")}}}}),K.jsx("div",{style:{position:"absolute",zIndex:x?gA.errorOverlay+20:gA.errorOverlay+10,left:F.left,top:F.top,color:x?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||x?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:F.transform},children:K.jsx("div",{className:`error-message ${lSe}`,style:{opacity:x?1:0,border:`1px solid ${x?"#ff4444":"red"}`},children:m.message})})]},`${y}_${E}`)})}),d&&K.jsx(Wmo,{center:d})]})};function Xmo(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function Jmo({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const o=xP(e).source_trace.get(t?.source_trace_id);if(o?.display_name&&(o?.max_length?n+=` / ${o.max_length}mm `:n+=" mm ",n+=`(${o.display_name})`),!n)return null;const i=t.trace_length&&o?.max_length&&t.trace_length>o.max_length;return{text:n,isOverLength:i}}function qmo(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(c=>c._element.type==="pcb_trace"),r=o.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>r.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!n)return[...s,...a];if(i.length>1){const c=i.reduce((l,A)=>{const u=l._element.trace_length;return A._element.trace_length<u?A:l},i[0]);return[...s,c]}return e}var $mo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},Zmo=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(c=>`${a}.${c}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},ego={top:"red",bottom:"aqua"},tgo=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=j.useState(!1),r=t._element;j.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],A=t.same_space_index??0,u=26,_=ego[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const p=Jmo({primitiveElement:r,elements:n});if(!p)return null;const g=e.y-35;return K.jsx("div",{style:{zIndex:gA.elementOverlay,position:"absolute",left:e.x,top:g,color:_,pointerEvents:"none",transform:"translateX(-50%)"},children:K.jsx("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:p.text})})}const d=Zmo(t);return d.trim().length===0?null:K.jsx("div",{style:{zIndex:gA.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:_,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:K.jsx("div",{style:{width:o?`calc(100% + ${u*2*A}px)`:"100%",height:o?`calc(100% + ${u*2*A}px)`:"100%",marginLeft:o?`${-u*A}px`:0,marginTop:o?`${-u*A}px`:0,border:`1px solid ${_}`,opacity:o||A===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:K.jsx("div",{style:{position:"absolute",bottom:l+20+u*A,marginRight:o?`${-u*A}px`:0,marginBottom:o?0:-u*A,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},ngo=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=I_(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=qmo({primitives:s,is_showing_multiple_traces_length:i,elements:n}),K.jsx("div",{style:$mo,children:!o&&s.map((a,c)=>K.jsx(tgo,{primitive:a,mousePos:e,elements:n},c))})},CP=t=>t?.type==="pcb_component",cIt=t=>t?.type==="pcb_group",ogo=t=>t?.type==="pcb_panel",ASe=t=>t?.type==="pcb_board",Tu={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},hx={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},uSe=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:hx.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Tu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=dt(e,s.anchor);r.set(s.anchor_id,a)}}),K.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:gA.dimensionOverlay},children:K.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,A=r.get(c),u=dt(e,l),_=l.x-a.x,h=l.y-a.y,d=Math.abs(u.x-A.x),m=Math.abs(u.y-A.y),p=u.y<A.y,g=u.x>A.x,f=p?Tu.LABEL_OFFSET_ABOVE:Tu.LABEL_OFFSET_BELOW,y=g?Tu.LABEL_OFFSET_RIGHT:Tu.LABEL_OFFSET_LEFT,x=d>Tu.MIN_LINE_LENGTH_FOR_LABEL,I=m>Tu.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??_.toFixed(2)}mm`,b=`${s.display_offset_y??h.toFixed(2)}mm`;return K.jsxs("g",{children:[K.jsx("line",{x1:A.x,y1:A.y,x2:u.x,y2:A.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.LINE_STROKE_WIDTH,strokeDasharray:Tu.LINE_DASH_PATTERN}),K.jsx("line",{x1:u.x,y1:A.y,x2:u.x,y2:u.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.LINE_STROKE_WIDTH,strokeDasharray:Tu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?K.jsx("circle",{cx:u.x,cy:u.y,r:Tu.COMPONENT_MARKER_RADIUS,fill:hx.COMPONENT_MARKER_FILL,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1}):K.jsxs(K.Fragment,{children:[K.jsx("line",{x1:u.x-Tu.ANCHOR_MARKER_SIZE,y1:u.y,x2:u.x+Tu.ANCHOR_MARKER_SIZE,y2:u.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH}),K.jsx("line",{x1:u.x,y1:u.y-Tu.ANCHOR_MARKER_SIZE,x2:u.x,y2:u.y+Tu.ANCHOR_MARKER_SIZE,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH})]}),x&&K.jsx("foreignObject",{x:Math.min(A.x,u.x),y:A.y+f,width:Math.abs(u.x-A.x),height:20,style:{overflow:"visible"},children:K.jsx("div",{style:{...i,textAlign:"center"},children:E})}),I&&K.jsx("foreignObject",{x:u.x+y,y:Math.min(A.y,u.y),width:Tu.Y_LABEL_MIN_WIDTH,height:Math.abs(u.y-A.y),style:{overflow:"visible"},children:K.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:g?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:b})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>K.jsxs("g",{children:[K.jsx("line",{x1:a.x-Tu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+Tu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH}),K.jsx("line",{x1:a.x,y1:a.y-Tu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+Tu.ANCHOR_MARKER_SIZE,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},igo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>ASe(g)),s=t.filter(g=>CP(g)),a=t.filter(g=>cIt(g)),c=e.map(g=>CP(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:CP(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),l=new Set;if(c.forEach(g=>{const f=s.find(y=>y.pcb_component_id===g);f?.pcb_group_id&&l.add(f.pcb_group_id)}),!I_(g=>g.is_showing_group_anchor_offsets)&&c.length===0)return null;const u=s.map(g=>{const f=g.positioned_relative_to_pcb_board_id;if(!f)return null;const y=r.find(x=>x.pcb_board_id===f);return y?{component:g,board:y,type:"component"}:null}).filter(g=>!!g),_=a.map(g=>{const f=g.positioned_relative_to_pcb_board_id;if(!f||!g.center)return null;const y=r.find(x=>x.pcb_board_id===f);return y?{group:g,board:y,type:"group"}:null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=c.length===0,m=h.filter(g=>g.type==="component"?d||c.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>g.type==="component"?{id:`${g.board.pcb_board_id}-${g.component.pcb_component_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:{id:`${g.board.pcb_board_id}-${g.group.pcb_group_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:{x:g.group.anchor_position?.x??g.group.center.x,y:g.group.anchor_position?.y??g.group.center.y},type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}).filter(g=>!!g);return K.jsx(uSe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},rgo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>cIt(g)),s=t.filter(g=>CP(g)),a=e.map(g=>CP(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:CP(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),c=(g,f)=>{if(f.has(g))return;f.add(g);const y=r.find(x=>x.pcb_group_id===g);y?.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id&&c(y.positioned_relative_to_pcb_group_id,f)},l=new Set;if(a.forEach(g=>{const f=s.find(y=>y.pcb_component_id===g);f&&(f.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&c(f.positioned_relative_to_pcb_group_id,l),f.pcb_group_id&&c(f.pcb_group_id,l))}),!I_(g=>g.is_showing_group_anchor_offsets)&&a.length===0)return null;const u=s.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const f=r.find(y=>y.pcb_group_id===g.positioned_relative_to_pcb_group_id);return f&&f.anchor_position?{component:g,parentGroup:f,type:"component"}:null}if(g.pcb_group_id){const f=r.find(y=>y.pcb_group_id===g.pcb_group_id);return f&&f.anchor_position?{component:g,parentGroup:f,type:"component"}:null}return null}).filter(g=>!!g),_=r.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const f=r.find(y=>y.pcb_group_id===g.positioned_relative_to_pcb_group_id);if(f&&f.anchor_position&&g.anchor_position)return{group:g,parentGroup:f,type:"group"}}return null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=a.length===0,m=h.filter(g=>g.type==="component"?d||a.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id)||l.has(g.parentGroup.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>{const f=g.parentGroup.anchor_position;return f?g.type==="component"?g.component.center?{id:`${g.parentGroup.pcb_group_id}-${g.component.pcb_component_id}-${g.type}`,anchor:f,anchor_id:g.parentGroup.pcb_group_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:null:g.group.anchor_position?{id:`${g.parentGroup.pcb_group_id}-${g.group.pcb_group_id}-${g.type}`,anchor:f,anchor_id:g.parentGroup.pcb_group_id,target:g.group.anchor_position,type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}:null:null}).filter(g=>!!g);return K.jsx(uSe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},sgo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?sSe([t]):sSe(o)},ago=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)CP(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),CP(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const c=sgo(a,t);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,A=l?xP(t).pcb_group.get(l):null;s.push({component:a,bbox:c,group:A})}return s.length===0?null:K.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:gA.dimensionOverlay},children:K.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const A=dt(n,{x:c.minX,y:c.maxY}),u=dt(n,{x:c.maxX,y:c.minY}),_={x:Math.min(A.x,u.x),y:Math.min(A.y,u.y),width:Math.abs(u.x-A.x),height:Math.abs(u.y-A.y)},h=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},d=dt(n,h);return K.jsxs("g",{children:[K.jsx("rect",{x:_.x,y:_.y,width:_.width,height:_.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),K.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),K.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),K.jsx("circle",{cx:d.x,cy:d.y,r:Tu.COMPONENT_MARKER_RADIUS,fill:hx.COMPONENT_MARKER_FILL,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},cgo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>ogo(h)),s=t.filter(h=>ASe(h)),a=e.map(h=>ASe(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!I_(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(h=>{const d=h.pcb_panel_id,m=h.position_mode;if(!d||m!=="relative_to_panel_anchor")return null;const p=r.find(g=>g.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(l.length===0)return null;const A=a.length===0,u=l.filter(h=>A||a.includes(h.board.pcb_board_id));if(u.length===0)return null;const _=u.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return K.jsx(uSe,{targets:_,transform:n,containerWidth:o,containerHeight:i})},oZ=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},lIt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,c=e[i].y;s>t.y!=c>t.y&&t.x<(a-r)*(t.y-s)/(c-s||Number.EPSILON)+r&&(n=!n)}return n},lgo=(t,e,n)=>{const o=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=Kg({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/n.a;a<l&&o.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=oZ(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;lIt(e,a)&&o.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=oZ(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;lIt(e,a)&&o.push(i);continue}if(!("x"in i&&"y"in i))continue;let r=0,s=0;if("w"in i&&"h"in i)r=i.w,s=i.h;else if("r"in i)r=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)r=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<r/2&&Math.abs(i.y-e.y)<s/2&&o.push(i)}return o},Ago=({elements:t,children:e,transform:n,primitives:o,onMouseHoverOverPrimitives:i})=>{const[r,s]=j.useState([]),[a,c]=j.useState({x:0,y:0}),[l,{width:A,height:u}]=jL(),_=j.useMemo(()=>{const d=[];for(const m of r){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,g=0,f=0;if(m.pcb_drawing_type==="polygon"){const E=oZ(m.points);if(!E)continue;p=E.center,g=E.width,f=E.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const E=m.brep_shape.outer_ring.vertices.map(P=>({x:P.x,y:P.y})),b=oZ(E);if(!b)continue;p=b.center,g=b.width,f=b.height}else"x"in m&&"y"in m&&(p={x:m.x,y:m.y},g="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,f="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const y=dt(n,p),x={w:g*n.a,h:f*n.a},I=d.filter(E=>y.x===E.screen_x&&y.y===E.screen_y&&x.w===E.screen_w&&x.h===E.screen_h).length;d.push({...m,x:p.x,y:p.y,w:g,h:f,screen_x:y.x,screen_y:y.y,screen_w:x.w,screen_h:x.h,same_space_index:I})}return d},[r,n]),h=(d,m,p,g)=>{c({x:d,y:m});const f=dt(Ry(p),{x:d,y:m}),y=lgo(g,f,p);Xmo(new Set(y.map(x=>x._pcb_drawing_object_id)),new Set(r.map(x=>x._pcb_drawing_object_id)))||(s(y),i(y))};return K.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:d=>{if(n){const m=d.currentTarget.getBoundingClientRect(),p=d.clientX-m.left,g=d.clientY-m.top;h(p,g,n,o)}},onTouchStart:d=>{if(n){const m=d.touches[0],p=d.currentTarget.getBoundingClientRect(),g=m.clientX-p.left,f=m.clientY-p.top;h(g,f,n,o)}},children:[e,K.jsx(ngo,{elements:t,mousePos:a,highlightedPrimitives:_}),n&&K.jsxs(K.Fragment,{children:[K.jsx(igo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),K.jsx(rgo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),K.jsx(ago,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),K.jsx(cgo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u})]})]})},AIt=["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)"],ugo=({children:t,transform:e=iA(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=jL(),a=j.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:A}=I_(u=>({is_showing_pcb_groups:u.is_showing_pcb_groups,pcb_group_view_mode:u.pcb_group_view_mode,is_showing_group_anchor_offsets:u.is_showing_group_anchor_offsets}));return j.useEffect(()=>{const u=a.current;if(!u||!r||!s)return;u.width=r,u.height=s;const _=u.getContext("2d");if(!_||(_.clearRect(0,0,r,s),!c))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),m=n.filter(E=>E.type==="source_group"),p=new Map(m.map(E=>[E.source_group_id,E])),g=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!E.source_group_id)return!1;const b=p.get(E.source_group_id);return b?b.was_automatically_named!==!0:!1}),f=new Map;m.forEach(E=>{const b=E;if(b.parent_source_group_id){const P=f.get(b.parent_source_group_id)||[];P.push(E.source_group_id),f.set(b.parent_source_group_id,P)}});const y=E=>{const b=[],P=f.get(E)||[];for(const B of P)b.push(B),b.push(...y(B));return b},x=E=>{const b=m.find(P=>P.source_group_id===E);return b?.parent_source_group_id?1+x(b.parent_source_group_id):0},I=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const b=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;b&&I.add(b)}g.forEach((E,b)=>{let P=d.filter(De=>De.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const De=y(E.source_group_id),ze=h.filter(Qe=>Qe.source_group_id&&De.includes(Qe.source_group_id));for(const Qe of ze){const be=d.filter(we=>we.pcb_group_id===Qe.pcb_group_id);P=[...P,...be]}}let B,w,k,N,L=!1;if(E.center&&E.width&&E.height){L=!0;const De=E.width/2,ze=E.height/2;B=E.center.x-De,k=E.center.x+De,w=E.center.y-ze,N=E.center.y+ze}else if(P.length===0||(B=1/0,w=1/0,k=-1/0,N=-1/0,P.forEach(De=>{if(De.center&&typeof De.width=="number"&&typeof De.height=="number"){const ze=De.center.x-De.width/2,Qe=De.center.x+De.width/2,be=De.center.y+De.height/2,we=De.center.y-De.height/2;B=Math.min(B,ze),k=Math.max(k,Qe),w=Math.min(w,we),N=Math.max(N,be)}}),B===1/0||k===-1/0))return;const F=E.source_group_id?x(E.source_group_id):0,G=E.source_group_id?y(E.source_group_id).length>0:!1;if(!L){const Qe=1+(G?.5:0);B-=Qe,k+=Qe,w-=Qe,N+=Qe}const W=dt(e,{x:B,y:N}),J=dt(e,{x:k,y:N}),$=dt(e,{x:B,y:w}),oe=dt(e,{x:k,y:w}),Ae=AIt[b%AIt.length];_.strokeStyle=Ae,_.lineWidth=2;const ee=Math.max(4,Math.min(12,8*Math.abs(e.a))),ie=Math.max(2,Math.min(6,4*Math.abs(e.a))),re=ee*(G?1.3:1),_e=ie;_.setLineDash([re,_e]),_.beginPath(),_.moveTo(W.x,W.y),_.lineTo(J.x,J.y),_.lineTo(oe.x,oe.y),_.lineTo($.x,$.y),_.closePath(),_.stroke();const xe=Math.max(8,Math.min(12,10*Math.abs(e.a))),Se=F==0||F==1?0:F*.11,ve=xe*(1-Se),le=4,Ie=E.name||`Group ${b+1}`;_.font=`${ve}px sans-serif`,_.setLineDash([]);const ke=_.measureText(Ie).width+le*2,Ue=ve+le*2,je=W.x-5,fe=W.y-5,qe=3;if(_.fillStyle="rgba(0, 0, 0, 0.8)",_.beginPath(),_.roundRect(je,fe-Ue,ke,Ue,qe),_.fill(),_.fillStyle=Ae,_.textAlign="left",_.textBaseline="middle",_.fillText(Ie,je+le,fe-Ue/2),A&&I.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const De=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},ze=dt(e,De);_.strokeStyle="white",_.lineWidth=1.5,_.setLineDash([]);const Qe=Math.max(4,Math.min(8,6*Math.abs(e.a)));_.beginPath(),_.moveTo(ze.x-Qe,ze.y),_.lineTo(ze.x+Qe,ze.y),_.stroke(),_.beginPath(),_.moveTo(ze.x,ze.y-Qe),_.lineTo(ze.x,ze.y+Qe),_.stroke()}})},[n,e,r,s,c,l,A,o]),K.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,K.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:gA.pcbGroupOverlay,display:c?"block":"none"}})]})},_go=({transform:t,soup:e,children:n})=>{const o=I_(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=j.useMemo(()=>R5t(e||[]),[e]),s=j.useMemo(()=>{if(!e||!o)return[];const a=_=>{const h=xP(e)[_.replace(/_\d+$/,"")].get(_);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},c=(_,h)=>{const d=i[h]||[];let m=null,p=1/0;return d.forEach(g=>{const f=a(g);if(f){const y=Math.sqrt((_.x-f.x)**2+(_.y-f.y)**2);y<p&&y>0&&(p=y,m=f)}}),m},l=xP(e).pcb_port.list(),A=xP(e).source_trace.list(),u=[];return l.forEach((_,h)=>{const d=r[_.pcb_port_id];let m=!1;for(const f of A)f.connected_source_port_ids.includes(_.source_port_id)&&f.connected_source_net_ids.length>0&&(m=!0);if(!d)return;const p={x:_.x,y:_.y},g=c(p,d);g&&u.push({key:`${_.pcb_port_id}-${h}`,startPoint:p,endPoint:g,isInNet:m})}),u},[e,i,r,o]);return!e||!o?n:(t||(t=iA()),K.jsxs("div",{style:{position:"relative"},children:[n,K.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:gA.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:A})=>{const u=dt(t,c),_=dt(t,l);return K.jsx("line",{x1:u.x,y1:u.y,x2:_.x,y2:_.y,stroke:"white",strokeWidth:"1",strokeDasharray:A?"6,6":void 0},a)})})]}))},dgo={version:"1.11.370"},IP=(t,e,n)=>{const o=I_(s=>s.is_mouse_over_container),i=j.useRef(o),r=j.useRef(e);j.useEffect(()=>{i.current=o},[o]),j.useEffect(()=>{r.current=e},[e]),j.useEffect(()=>{if(!t)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=t.split("+"),A=l.includes("ctrl"),u=l.includes("shift"),_=l.includes("alt"),h=l.includes("meta"),d=l[l.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!A||a.ctrlKey)&&(!u||a.shiftKey)&&(!_||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},hgo=()=>{const[t,e]=j.useState(!1);return j.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},JL=(t,e={stopPropagation:!0})=>{const n=j.useRef(0),o=j.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=j.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},EP=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=JL(n);return K.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},mgo=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:V7(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},ggo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=j.useRef(null),r=j.useRef(null),s=j.useRef(null),a=j.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);j.useEffect(()=>a,[a]);const c=j.useCallback(A=>{a(),s.current=A,e(A),n(null),r.current=window.requestAnimationFrame(()=>{n(A),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),l=j.useCallback(A=>s.current===A,[]);return{handleErrorSelect:c,isSelectedError:l}},pgo=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=JL(()=>o(e,t));return K.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?K.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):K.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:K.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},fgo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,c]=j.useState(null),[l,A]=j.useState(new Set),[u,_]=j.useState(new Set),[,h]=nho(),{handleErrorSelect:d,isSelectedError:m}=ggo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),p=j.useMemo(()=>t?.filter(I=>I.type.includes("error"))??[],[t]),g=p.length,f=j.useMemo(()=>mgo(p),[p]),y=j.useCallback(I=>{A(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]),x=j.useCallback(I=>{_(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]);return K.jsxs("div",{style:{position:"relative"},children:[K.jsx(EP,{isSmallScreen:n,style:g>0?{color:"red"}:void 0,onClick:o,children:K.jsxs("div",{children:[g," errors"]})}),e&&g>0&&K.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:f.map(({errorType:I,errors:E},b)=>{const P=l.has(I);return K.jsxs("div",{style:{borderBottom:b<f.length-1?"1px solid #444":"none"},children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:B=>{B.currentTarget.style.backgroundColor="#303030"},onMouseLeave:B=>{B.currentTarget.style.backgroundColor="#232323"},onTouchStart:B=>{B.stopPropagation(),B.currentTarget.style.backgroundColor="#303030"},onTouchEnd:B=>{B.stopPropagation(),B.preventDefault(),B.currentTarget.style.backgroundColor="#232323",y(I)},onClick:B=>{B.stopPropagation(),y(I)},children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[K.jsx("div",{style:{color:"#888",fontSize:"16px",transform:P?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),K.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:I})]}),K.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!P&&E.map(({error:B,index:w,errorId:k})=>{const N=u.has(k),L=B.message??"No error message";return K.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:F=>{F.currentTarget.style.backgroundColor="#333",r(k)},onMouseLeave:F=>{F.currentTarget.style.backgroundColor="#2a2a2a",m(k)||r(null)},onTouchStart:F=>{F.stopPropagation(),F.currentTarget.style.backgroundColor="#333",r(k)},onTouchEnd:F=>{F.stopPropagation(),F.preventDefault(),F.currentTarget.style.backgroundColor="#2a2a2a",d(k)},onClick:F=>{F.stopPropagation(),d(k)},children:[K.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:L}),K.jsx("button",{type:"button","aria-label":N?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:N?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:F=>F.stopPropagation(),onClick:F=>{F.stopPropagation(),x(k)},onTouchEnd:F=>{F.stopPropagation(),F.preventDefault(),x(k)},children:"›"})]}),N&&K.jsxs("div",{"data-error-id":w,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[K.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:F=>F.stopPropagation(),onClick:F=>F.stopPropagation(),children:L}),K.jsx(pgo,{errorId:k,errorMessage:L,copiedErrorId:a,onCopy:(F,G)=>{h(F),c(G),setTimeout(()=>c(null),2e3)}})]})]},k)})]},I)})})]})},ygo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=JL(n);return K.jsxs("div",{className:U7`
5531
+ `,jmo=({children:t,transform:e=iA(),elements:n})=>{const o=j.useRef(null),{isShowingDRCErrors:i,hoveredErrorId:r,focusedErrorId:s}=I_(m=>({isShowingDRCErrors:m.is_showing_drc_errors,hoveredErrorId:m.hovered_error_id,focusedErrorId:m.focused_error_id})),a=s??r;if(!n)return K.jsx("div",{style:{position:"relative"},ref:o,children:t});const c=n.filter(m=>m.type==="pcb_trace_error"&&!m.message?.includes("Multiple components found with name")),l=n.filter(m=>m.type==="pcb_via_clearance_error"),A=n.filter(m=>m.type==="pcb_trace_error"&&m.message?.includes("Multiple components found with name")),u=k5t(n),_=N5t(n,a),h=m=>{const p=mho({error:m,indexes:u});if(!p||typeof p.x!="number"||typeof p.y!="number")return null;const g=dt(e,p);return Number.isNaN(g.x)||Number.isNaN(g.y)?null:g};let d=null;return _&&(d=h(_)),K.jsxs("div",{style:{position:"relative"},ref:o,children:[t,c.map((m,p)=>{const g=V7(m,p),f=a===g;if(!f&&!i)return null;const y=h(m);if(!y)return null;const x=cSe(y,o);return K.jsxs(j.Fragment,{children:[K.jsx(aIt,{errorCenter:y,isHighlighted:f}),K.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:gA.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!f){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),K.jsx("div",{style:{position:"absolute",zIndex:f?200:100,left:x.left,top:x.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||f?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:K.jsx("div",{className:`error-message ${lSe}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},g)}),l.map((m,p)=>{const g=V7(m,p),f=a===g;if(!f&&!i)return null;const y=h(m);if(!y)return null;const x=cSe({x:y.x,y:y.y},o);return K.jsxs(j.Fragment,{children:[K.jsx(aIt,{errorCenter:y,isHighlighted:f}),K.jsx("div",{style:{position:"absolute",left:y.x-15,top:y.y-15,width:30,height:30,zIndex:gA.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:I=>{const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:I=>{if(!f){const E=I.currentTarget.nextElementSibling;if(E){const b=E.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),K.jsx("div",{style:{position:"absolute",zIndex:f?gA.errorOverlay+10:gA.errorOverlay+1,left:x.left,top:x.top,color:f?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:x.transform},children:K.jsx("div",{className:`error-message ${lSe}`,style:{opacity:f?1:0,border:`1px solid ${f?"#ff4444":"red"}`},children:m.message})})]},g)}),A.map((m,p)=>{const g=m.component_name||m.message?.match(/name "([^"]+)"/)?.[1];if(!g)return null;const f=n?.filter(I=>I.type==="source_component"&&I.name===g||I.type==="pcb_component"&&n?.find(E=>E.type==="source_component"&&E.source_component_id===I.source_component_id&&E.name===g))||[],y=V7(m,p),x=a===y;return!x&&!i?null:f.map((I,E)=>{let b={x:0,y:0};if(I.type==="pcb_component")b=I.center||{x:0,y:0};else if(I.type==="source_component"){const G=n?.find(W=>W.type==="pcb_component"&&W.source_component_id===I.source_component_id);G&&G.type==="pcb_component"&&(b=G.center||{x:0,y:0})}const P=dt(e,b);if(Number.isNaN(P.x)||Number.isNaN(P.y))return null;const B=Math.abs(e.a),L=Math.max(8,Math.min(30,.5*B)),F=cSe(P,o);return K.jsxs(j.Fragment,{children:[K.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:gA.errorOverlay},width:"100%",height:"100%",children:x?K.jsx("polygon",{points:`${P.x},${P.y-L*1.25} ${P.x+L},${P.y} ${P.x},${P.y+L*1.25} ${P.x-L},${P.y}`,fill:"#ff4444"}):K.jsx("circle",{cx:P.x,cy:P.y,r:L,fill:"none",stroke:x?"#ff4444":"red",strokeWidth:x?Math.max(2,L*.15):Math.max(1,L*.1),opacity:1})}),K.jsx("div",{style:{position:"absolute",left:P.x-(L+10),top:P.y-(L+10),width:(L+10)*2,height:(L+10)*2,zIndex:gA.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:G=>{const W=G.currentTarget.nextElementSibling;if(W){const J=W.querySelector(".error-message");J&&(J.style.opacity="1")}},onMouseLeave:G=>{if(!x){const W=G.currentTarget.nextElementSibling;if(W){const J=W.querySelector(".error-message");J&&(J.style.opacity="0")}}}}),K.jsx("div",{style:{position:"absolute",zIndex:x?gA.errorOverlay+20:gA.errorOverlay+10,left:F.left,top:F.top,color:x?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:i||x?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:F.transform},children:K.jsx("div",{className:`error-message ${lSe}`,style:{opacity:x?1:0,border:`1px solid ${x?"#ff4444":"red"}`},children:m.message})})]},`${y}_${E}`)})}),d&&K.jsx(Wmo,{center:d})]})};function Xmo(t,e){return t.size!==e.size?!1:Array.from(t).every(n=>e.has(n))}function Jmo({primitiveElement:t,elements:e}){let n=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const o=xP(e).source_trace.get(t?.source_trace_id);if(o?.display_name&&(o?.max_length?n+=` / ${o.max_length}mm `:n+=" mm ",n+=`(${o.display_name})`),!n)return null;const i=t.trace_length&&o?.max_length&&t.trace_length>o.max_length;return{text:n,isOverLength:i}}function qmo(t){const{primitives:e,is_showing_multiple_traces_length:n,elements:o}=t,i=e.filter(c=>c._element.type==="pcb_trace"),r=o.filter(c=>c.type==="source_trace"),s=e.filter(c=>c._element.type!=="pcb_trace"),a=i.filter(c=>r.some(l=>c._element.type==="pcb_trace"&&c._element.source_trace_id===l.source_trace_id&&l.max_length!==void 0));if(!n)return[...s,...a];if(i.length>1){const c=i.reduce((l,A)=>{const u=l._element.trace_length;return A._element.trace_length<u?A:l},i[0]);return[...s,c]}return e}var $mo={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},Zmo=t=>{const{_element:e,_parent_pcb_component:n,_parent_source_component:o,_source_port:i}=t;switch(e.type){case"pcb_trace":return e.trace_length?`${e.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const r=[],s=Array.from(new Set((e.port_hints??[]).concat(i?.port_hints??[]))).filter(c=>!/^[0-9]+$/.test(c)).filter(c=>!c.includes("unnamed_")).sort((c,l)=>l.localeCompare(c)),a=o&&"name"in o&&o.name&&!o.name.includes("unnamed_")?o.name:null;return s.length>0?a?r.push(...s.map(c=>`${a}.${c}`)):r.push(...s):a&&r.push(a),r.join(", ")}default:return""}},ego={top:"red",bottom:"aqua"},tgo=({primitive:t,mousePos:e,elements:n})=>{const[o,i]=j.useState(!1),r=t._element;j.useEffect(()=>{setTimeout(()=>{i(!0)},100)},[]);const[s,a,c,l]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],A=t.same_space_index??0,u=26,_=ego[t?._element?.layer]??"red";let h=0;if(r.type==="pcb_smtpad"&&r?.shape==="rotated_rect"?h=r?.ccw_rotation??0:(r.type==="pcb_smtpad"&&(r?.shape==="pill"||r?.shape==="rotated_pill")&&"ccw_rotation"in t||r.type==="pcb_plated_hole"&&(r?.shape==="pill"||r?.shape==="oval")&&"ccw_rotation"in t)&&(h=r.ccw_rotation??0),r.type==="pcb_trace"){const p=Jmo({primitiveElement:r,elements:n});if(!p)return null;const g=e.y-35;return K.jsx("div",{style:{zIndex:gA.elementOverlay,position:"absolute",left:e.x,top:g,color:_,pointerEvents:"none",transform:"translateX(-50%)"},children:K.jsx("div",{style:{backgroundColor:"#f2efcc",color:p.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:p.text})})}const d=Zmo(t);return d.trim().length===0?null:K.jsx("div",{style:{zIndex:gA.elementOverlay,position:"absolute",left:s-c/2-8,top:a-l/2-8,width:c+16,height:l+16,color:_,transform:`rotate(${-h}deg)`,transformOrigin:"center center"},children:K.jsx("div",{style:{width:o?`calc(100% + ${u*2*A}px)`:"100%",height:o?`calc(100% + ${u*2*A}px)`:"100%",marginLeft:o?`${-u*A}px`:0,marginTop:o?`${-u*A}px`:0,border:`1px solid ${_}`,opacity:o||A===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:K.jsx("div",{style:{position:"absolute",bottom:l+20+u*A,marginRight:o?`${-u*A}px`:0,marginBottom:o?0:-u*A,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${h}deg)`,minWidth:"45px",textAlign:"center"},children:d})})})},ngo=({highlightedPrimitives:t,mousePos:e,elements:n})=>{const[o,i]=I_(a=>[a.is_moving_component,a.is_showing_multiple_traces_length]),r=t.some(a=>a._element.type==="pcb_smtpad")&&t.some(a=>a._element.type==="pcb_trace");let s=t;return r&&(s=s.filter(a=>a._element.type==="pcb_smtpad")),s=qmo({primitives:s,is_showing_multiple_traces_length:i,elements:n}),K.jsx("div",{style:$mo,children:!o&&s.map((a,c)=>K.jsx(tgo,{primitive:a,mousePos:e,elements:n},c))})},CP=t=>t?.type==="pcb_component",cIt=t=>t?.type==="pcb_group",ogo=t=>t?.type==="pcb_panel",ASe=t=>t?.type==="pcb_board",Tu={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},hx={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},uSe=({targets:t,transform:e,containerWidth:n,containerHeight:o})=>{if(t.length===0)return null;const i={color:hx.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Tu.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},r=new Map;return t.forEach(s=>{if(!r.has(s.anchor_id)){const a=dt(e,s.anchor);r.set(s.anchor_id,a)}}),K.jsx("div",{style:{position:"absolute",left:0,top:0,width:n,height:o,overflow:"hidden",pointerEvents:"none",zIndex:gA.dimensionOverlay},children:K.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:n,height:o,children:[t.map(s=>{const a=s.anchor,c=s.anchor_id,l=s.target,A=r.get(c),u=dt(e,l),_=l.x-a.x,h=l.y-a.y,d=Math.abs(u.x-A.x),m=Math.abs(u.y-A.y),p=u.y<A.y,g=u.x>A.x,f=p?Tu.LABEL_OFFSET_ABOVE:Tu.LABEL_OFFSET_BELOW,y=g?Tu.LABEL_OFFSET_RIGHT:Tu.LABEL_OFFSET_LEFT,x=d>Tu.MIN_LINE_LENGTH_FOR_LABEL,I=m>Tu.MIN_LINE_LENGTH_FOR_LABEL,E=`${s.display_offset_x??_.toFixed(2)}mm`,b=`${s.display_offset_y??h.toFixed(2)}mm`;return K.jsxs("g",{children:[K.jsx("line",{x1:A.x,y1:A.y,x2:u.x,y2:A.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.LINE_STROKE_WIDTH,strokeDasharray:Tu.LINE_DASH_PATTERN}),K.jsx("line",{x1:u.x,y1:A.y,x2:u.x,y2:u.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.LINE_STROKE_WIDTH,strokeDasharray:Tu.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?K.jsx("circle",{cx:u.x,cy:u.y,r:Tu.COMPONENT_MARKER_RADIUS,fill:hx.COMPONENT_MARKER_FILL,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1}):K.jsxs(K.Fragment,{children:[K.jsx("line",{x1:u.x-Tu.ANCHOR_MARKER_SIZE,y1:u.y,x2:u.x+Tu.ANCHOR_MARKER_SIZE,y2:u.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH}),K.jsx("line",{x1:u.x,y1:u.y-Tu.ANCHOR_MARKER_SIZE,x2:u.x,y2:u.y+Tu.ANCHOR_MARKER_SIZE,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH})]}),x&&K.jsx("foreignObject",{x:Math.min(A.x,u.x),y:A.y+f,width:Math.abs(u.x-A.x),height:20,style:{overflow:"visible"},children:K.jsx("div",{style:{...i,textAlign:"center"},children:E})}),I&&K.jsx("foreignObject",{x:u.x+y,y:Math.min(A.y,u.y),width:Tu.Y_LABEL_MIN_WIDTH,height:Math.abs(u.y-A.y),style:{overflow:"visible"},children:K.jsx("div",{style:{...i,display:"flex",alignItems:"center",justifyContent:g?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:b})})]},s.id)}),Array.from(r.entries()).map(([s,a])=>K.jsxs("g",{children:[K.jsx("line",{x1:a.x-Tu.ANCHOR_MARKER_SIZE,y1:a.y,x2:a.x+Tu.ANCHOR_MARKER_SIZE,y2:a.y,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH}),K.jsx("line",{x1:a.x,y1:a.y-Tu.ANCHOR_MARKER_SIZE,x2:a.x,y2:a.y+Tu.ANCHOR_MARKER_SIZE,stroke:hx.OFFSET_LINE,strokeWidth:Tu.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},igo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>ASe(g)),s=t.filter(g=>CP(g)),a=t.filter(g=>cIt(g)),c=e.map(g=>CP(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:CP(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),l=new Set;if(c.forEach(g=>{const f=s.find(y=>y.pcb_component_id===g);f?.pcb_group_id&&l.add(f.pcb_group_id)}),!I_(g=>g.is_showing_group_anchor_offsets)&&c.length===0)return null;const u=s.map(g=>{const f=g.positioned_relative_to_pcb_board_id;if(!f)return null;const y=r.find(x=>x.pcb_board_id===f);return y?{component:g,board:y,type:"component"}:null}).filter(g=>!!g),_=a.map(g=>{const f=g.positioned_relative_to_pcb_board_id;if(!f||!g.center)return null;const y=r.find(x=>x.pcb_board_id===f);return y?{group:g,board:y,type:"group"}:null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=c.length===0,m=h.filter(g=>g.type==="component"?d||c.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>g.type==="component"?{id:`${g.board.pcb_board_id}-${g.component.pcb_component_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:{id:`${g.board.pcb_board_id}-${g.group.pcb_group_id}-${g.type}`,anchor:g.board.center,anchor_id:g.board.pcb_board_id,target:{x:g.group.anchor_position?.x??g.group.center.x,y:g.group.anchor_position?.y??g.group.center.y},type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}).filter(g=>!!g);return K.jsx(uSe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},rgo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(g=>cIt(g)),s=t.filter(g=>CP(g)),a=e.map(g=>CP(g._parent_pcb_component)?g._parent_pcb_component.pcb_component_id:CP(g._element)?g._element.pcb_component_id:null).filter(g=>!!g),c=(g,f)=>{if(f.has(g))return;f.add(g);const y=r.find(x=>x.pcb_group_id===g);y?.position_mode==="relative_to_group_anchor"&&y.positioned_relative_to_pcb_group_id&&c(y.positioned_relative_to_pcb_group_id,f)},l=new Set;if(a.forEach(g=>{const f=s.find(y=>y.pcb_component_id===g);f&&(f.position_mode==="relative_to_group_anchor"&&f.positioned_relative_to_pcb_group_id&&c(f.positioned_relative_to_pcb_group_id,l),f.pcb_group_id&&c(f.pcb_group_id,l))}),!I_(g=>g.is_showing_group_anchor_offsets)&&a.length===0)return null;const u=s.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const f=r.find(y=>y.pcb_group_id===g.positioned_relative_to_pcb_group_id);return f&&f.anchor_position?{component:g,parentGroup:f,type:"component"}:null}if(g.pcb_group_id){const f=r.find(y=>y.pcb_group_id===g.pcb_group_id);return f&&f.anchor_position?{component:g,parentGroup:f,type:"component"}:null}return null}).filter(g=>!!g),_=r.map(g=>{if(g.position_mode==="relative_to_group_anchor"&&g.positioned_relative_to_pcb_group_id){const f=r.find(y=>y.pcb_group_id===g.positioned_relative_to_pcb_group_id);if(f&&f.anchor_position&&g.anchor_position)return{group:g,parentGroup:f,type:"group"}}return null}).filter(g=>!!g),h=[...u,..._];if(h.length===0)return null;const d=a.length===0,m=h.filter(g=>g.type==="component"?d||a.includes(g.component.pcb_component_id):d||l.has(g.group.pcb_group_id)||l.has(g.parentGroup.pcb_group_id));if(m.length===0)return null;const p=m.map(g=>{const f=g.parentGroup.anchor_position;return f?g.type==="component"?g.component.center?{id:`${g.parentGroup.pcb_group_id}-${g.component.pcb_component_id}-${g.type}`,anchor:f,anchor_id:g.parentGroup.pcb_group_id,target:g.component.center,type:"component",display_offset_x:g.component.display_offset_x,display_offset_y:g.component.display_offset_y}:null:g.group.anchor_position?{id:`${g.parentGroup.pcb_group_id}-${g.group.pcb_group_id}-${g.type}`,anchor:f,anchor_id:g.parentGroup.pcb_group_id,target:g.group.anchor_position,type:"group",display_offset_x:g.group.display_offset_x,display_offset_y:g.group.display_offset_y}:null:null}).filter(g=>!!g);return K.jsx(uSe,{targets:p,transform:n,containerWidth:o,containerHeight:i})},sgo=(t,e)=>{const n=t.pcb_component_id,o=e.filter(i=>(i.type==="pcb_smtpad"||i.type==="pcb_plated_hole")&&i.pcb_component_id===n||i.type==="pcb_hole"&&i.pcb_component_id===n);return o.length===0?sSe([t]):sSe(o)},ago=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=new Map;for(const a of e)CP(a._parent_pcb_component)&&r.set(a._parent_pcb_component.pcb_component_id,a._parent_pcb_component),CP(a._element)&&r.set(a._element.pcb_component_id,a._element);if(r.size===0)return null;const s=[];for(const a of r.values()){const c=sgo(a,t);if(!c)continue;const l=a.positioned_relative_to_pcb_group_id??a.pcb_group_id,A=l?xP(t).pcb_group.get(l):null;s.push({component:a,bbox:c,group:A})}return s.length===0?null:K.jsx("div",{style:{position:"absolute",left:0,top:0,width:o,height:i,overflow:"hidden",pointerEvents:"none",zIndex:gA.dimensionOverlay},children:K.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:o,height:i,children:s.map(({component:a,bbox:c,group:l})=>{const A=dt(n,{x:c.minX,y:c.maxY}),u=dt(n,{x:c.maxX,y:c.minY}),_={x:Math.min(A.x,u.x),y:Math.min(A.y,u.y),width:Math.abs(u.x-A.x),height:Math.abs(u.y-A.y)},h=a.center??{x:(c.minX+c.maxX)/2,y:(c.minY+c.maxY)/2},d=dt(n,h);return K.jsxs("g",{children:[K.jsx("rect",{x:_.x,y:_.y,width:_.width,height:_.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),K.jsx("line",{x1:d.x-6,y1:d.y,x2:d.x+6,y2:d.y,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),K.jsx("line",{x1:d.x,y1:d.y-6,x2:d.x,y2:d.y+6,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),K.jsx("circle",{cx:d.x,cy:d.y,r:Tu.COMPONENT_MARKER_RADIUS,fill:hx.COMPONENT_MARKER_FILL,stroke:hx.COMPONENT_MARKER_STROKE,strokeWidth:1})]},a.pcb_component_id)})})})},cgo=({elements:t,highlightedPrimitives:e,transform:n,containerWidth:o,containerHeight:i})=>{const r=t.filter(h=>ogo(h)),s=t.filter(h=>ASe(h)),a=e.map(h=>ASe(h._element)?h._element.pcb_board_id:null).filter(h=>!!h);if(!I_(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const l=s.map(h=>{const d=h.pcb_panel_id,m=h.position_mode;if(!d||m!=="relative_to_panel_anchor")return null;const p=r.find(g=>g.pcb_panel_id===d);return p?{board:h,panel:p,type:"board"}:null}).filter(h=>!!h);if(l.length===0)return null;const A=a.length===0,u=l.filter(h=>A||a.includes(h.board.pcb_board_id));if(u.length===0)return null;const _=u.map(h=>h.board.center?{id:`${h.panel.pcb_panel_id}-${h.board.pcb_board_id}-${h.type}`,anchor:h.panel.center,anchor_id:h.panel.pcb_panel_id,target:h.board.center,type:"board",display_offset_x:h.board.display_offset_x,display_offset_y:h.board.display_offset_y}:null).filter(h=>!!h);return K.jsx(uSe,{targets:_,transform:n,containerWidth:o,containerHeight:i})},oZ=t=>{if(t.length===0)return null;let e=t[0].x,n=t[0].y,o=t[0].x,i=t[0].y;for(const r of t)r.x<e&&(e=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>i&&(i=r.y);return{center:{x:(e+o)/2,y:(n+i)/2},width:o-e,height:i-n}},lIt=(t,e)=>{if(e.length<3)return!1;let n=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const r=e[o].x,s=e[o].y,a=e[i].x,c=e[i].y;s>t.y!=c>t.y&&t.x<(a-r)*(t.y-s)/(c-s||Number.EPSILON)+r&&(n=!n)}return n},lgo=(t,e,n)=>{const o=[];for(const i of t){if(!i._element)continue;if("x1"in i&&i._element?.type==="pcb_trace"){const a=Kg({x:e.x,y:e.y},{x:i.x1,y:i.y1},{x:i.x2,y:i.y2}),c=i.width||.5,l=Math.max(c*25,2)/n.a;a<l&&o.push(i);continue}if(i.pcb_drawing_type==="polygon"){const a=i.points.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=oZ(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;lIt(e,a)&&o.push(i);continue}if(i.pcb_drawing_type==="polygon_with_arcs"){const a=i.brep_shape.outer_ring.vertices.map(l=>({x:nt.parse(l.x),y:nt.parse(l.y)})),c=oZ(a);if(!c||e.x<c.center.x-c.width/2||e.x>c.center.x+c.width/2||e.y<c.center.y-c.height/2||e.y>c.center.y+c.height/2)continue;lIt(e,a)&&o.push(i);continue}if(!("x"in i&&"y"in i))continue;let r=0,s=0;if("w"in i&&"h"in i)r=i.w,s=i.h;else if("r"in i)r=i.r*2,s=i.r*2;else if("rX"in i&&"rY"in i)r=i.rX*2,s=i.rY*2;else continue;Math.abs(i.x-e.x)<r/2&&Math.abs(i.y-e.y)<s/2&&o.push(i)}return o},Ago=({elements:t,children:e,transform:n,primitives:o,onMouseHoverOverPrimitives:i})=>{const[r,s]=j.useState([]),[a,c]=j.useState({x:0,y:0}),[l,{width:A,height:u}]=jL(),_=j.useMemo(()=>{const d=[];for(const m of r){if(m._element?.type==="pcb_via"||m._element?.type==="pcb_component"||m?.layer==="drill"||m?.is_hoverable===!1)continue;let p=null,g=0,f=0;if(m.pcb_drawing_type==="polygon"){const E=oZ(m.points);if(!E)continue;p=E.center,g=E.width,f=E.height}else if(m.pcb_drawing_type==="polygon_with_arcs"){const E=m.brep_shape.outer_ring.vertices.map(P=>({x:P.x,y:P.y})),b=oZ(E);if(!b)continue;p=b.center,g=b.width,f=b.height}else"x"in m&&"y"in m&&(p={x:m.x,y:m.y},g="w"in m?m.w:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rX*2:0,f="h"in m?m.h:"r"in m?m.r*2:"rX"in m&&"rY"in m?m.rY*2:0);if(!p)continue;const y=dt(n,p),x={w:g*n.a,h:f*n.a},I=d.filter(E=>y.x===E.screen_x&&y.y===E.screen_y&&x.w===E.screen_w&&x.h===E.screen_h).length;d.push({...m,x:p.x,y:p.y,w:g,h:f,screen_x:y.x,screen_y:y.y,screen_w:x.w,screen_h:x.h,same_space_index:I})}return d},[r,n]),h=(d,m,p,g)=>{c({x:d,y:m});const f=dt(Ry(p),{x:d,y:m}),y=lgo(g,f,p);Xmo(new Set(y.map(x=>x._pcb_drawing_object_id)),new Set(r.map(x=>x._pcb_drawing_object_id)))||(s(y),i(y))};return K.jsxs("div",{ref:l,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:d=>{if(n){const m=d.currentTarget.getBoundingClientRect(),p=d.clientX-m.left,g=d.clientY-m.top;h(p,g,n,o)}},onTouchStart:d=>{if(n){const m=d.touches[0],p=d.currentTarget.getBoundingClientRect(),g=m.clientX-p.left,f=m.clientY-p.top;h(g,f,n,o)}},children:[e,K.jsx(ngo,{elements:t,mousePos:a,highlightedPrimitives:_}),n&&K.jsxs(K.Fragment,{children:[K.jsx(igo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),K.jsx(rgo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),K.jsx(ago,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u}),K.jsx(cgo,{elements:t,highlightedPrimitives:_,transform:n,containerWidth:A,containerHeight:u})]})]})},AIt=["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)"],ugo=({children:t,transform:e=iA(),elements:n=[],hoveredComponentIds:o=[]})=>{const[i,{width:r,height:s}]=jL(),a=j.useRef(null),{is_showing_pcb_groups:c,pcb_group_view_mode:l,is_showing_group_anchor_offsets:A}=I_(u=>({is_showing_pcb_groups:u.is_showing_pcb_groups,pcb_group_view_mode:u.pcb_group_view_mode,is_showing_group_anchor_offsets:u.is_showing_group_anchor_offsets}));return j.useEffect(()=>{const u=a.current;if(!u||!r||!s)return;u.width=r,u.height=s;const _=u.getContext("2d");if(!_||(_.clearRect(0,0,r,s),!c))return;const h=n.filter(E=>E.type==="pcb_group"),d=n.filter(E=>E.type==="pcb_component"),m=n.filter(E=>E.type==="source_group"),p=new Map(m.map(E=>[E.source_group_id,E])),g=h.filter(E=>{if(E.name?.toLowerCase().includes("subpanel"))return!1;if(l==="all")return!0;if(!E.source_group_id)return!1;const b=p.get(E.source_group_id);return b?b.was_automatically_named!==!0:!1}),f=new Map;m.forEach(E=>{const b=E;if(b.parent_source_group_id){const P=f.get(b.parent_source_group_id)||[];P.push(E.source_group_id),f.set(b.parent_source_group_id,P)}});const y=E=>{const b=[],P=f.get(E)||[];for(const B of P)b.push(B),b.push(...y(B));return b},x=E=>{const b=m.find(P=>P.source_group_id===E);return b?.parent_source_group_id?1+x(b.parent_source_group_id):0},I=new Set;if(o.length>0)for(const E of d){if(!o.includes(E.pcb_component_id))continue;const b=E.positioned_relative_to_pcb_group_id??E.pcb_group_id;b&&I.add(b)}g.forEach((E,b)=>{let P=d.filter(De=>De.pcb_group_id===E.pcb_group_id);if(E.source_group_id){const De=y(E.source_group_id),ze=h.filter(Qe=>Qe.source_group_id&&De.includes(Qe.source_group_id));for(const Qe of ze){const be=d.filter(we=>we.pcb_group_id===Qe.pcb_group_id);P=[...P,...be]}}let B,w,k,N,L=!1;if(E.center&&E.width&&E.height){L=!0;const De=E.width/2,ze=E.height/2;B=E.center.x-De,k=E.center.x+De,w=E.center.y-ze,N=E.center.y+ze}else if(P.length===0||(B=1/0,w=1/0,k=-1/0,N=-1/0,P.forEach(De=>{if(De.center&&typeof De.width=="number"&&typeof De.height=="number"){const ze=De.center.x-De.width/2,Qe=De.center.x+De.width/2,be=De.center.y+De.height/2,we=De.center.y-De.height/2;B=Math.min(B,ze),k=Math.max(k,Qe),w=Math.min(w,we),N=Math.max(N,be)}}),B===1/0||k===-1/0))return;const F=E.source_group_id?x(E.source_group_id):0,G=E.source_group_id?y(E.source_group_id).length>0:!1;if(!L){const Qe=1+(G?.5:0);B-=Qe,k+=Qe,w-=Qe,N+=Qe}const W=dt(e,{x:B,y:N}),J=dt(e,{x:k,y:N}),$=dt(e,{x:B,y:w}),oe=dt(e,{x:k,y:w}),Ae=AIt[b%AIt.length];_.strokeStyle=Ae,_.lineWidth=2;const ee=Math.max(4,Math.min(12,8*Math.abs(e.a))),ie=Math.max(2,Math.min(6,4*Math.abs(e.a))),re=ee*(G?1.3:1),_e=ie;_.setLineDash([re,_e]),_.beginPath(),_.moveTo(W.x,W.y),_.lineTo(J.x,J.y),_.lineTo(oe.x,oe.y),_.lineTo($.x,$.y),_.closePath(),_.stroke();const xe=Math.max(8,Math.min(12,10*Math.abs(e.a))),Se=F==0||F==1?0:F*.11,ve=xe*(1-Se),le=4,Ie=E.name||`Group ${b+1}`;_.font=`${ve}px sans-serif`,_.setLineDash([]);const ke=_.measureText(Ie).width+le*2,Ue=ve+le*2,je=W.x-5,fe=W.y-5,qe=3;if(_.fillStyle="rgba(0, 0, 0, 0.8)",_.beginPath(),_.roundRect(je,fe-Ue,ke,Ue,qe),_.fill(),_.fillStyle=Ae,_.textAlign="left",_.textBaseline="middle",_.fillText(Ie,je+le,fe-Ue/2),A&&I.has(E.pcb_group_id)&&!!E.anchor_position&&E.anchor_position){const De=Array.isArray(E.anchor_position)?{x:E.anchor_position[0]??0,y:E.anchor_position[1]??0}:{x:E.anchor_position.x,y:E.anchor_position.y},ze=dt(e,De);_.strokeStyle="white",_.lineWidth=1.5,_.setLineDash([]);const Qe=Math.max(4,Math.min(8,6*Math.abs(e.a)));_.beginPath(),_.moveTo(ze.x-Qe,ze.y),_.lineTo(ze.x+Qe,ze.y),_.stroke(),_.beginPath(),_.moveTo(ze.x,ze.y-Qe),_.lineTo(ze.x,ze.y+Qe),_.stroke()}})},[n,e,r,s,c,l,A,o]),K.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,K.jsx("canvas",{ref:a,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:gA.pcbGroupOverlay,display:c?"block":"none"}})]})},_go=({transform:t,soup:e,children:n})=>{const o=I_(a=>a.is_showing_rats_nest),{netMap:i,idToNetMap:r}=j.useMemo(()=>R5t(e||[]),[e]),s=j.useMemo(()=>{if(!e||!o)return[];const a=_=>{const h=xP(e)[_.replace(/_\d+$/,"")].get(_);return h&&"x"in h&&"y"in h?{x:h.x,y:h.y}:null},c=(_,h)=>{const d=i[h]||[];let m=null,p=1/0;return d.forEach(g=>{const f=a(g);if(f){const y=Math.sqrt((_.x-f.x)**2+(_.y-f.y)**2);y<p&&y>0&&(p=y,m=f)}}),m},l=xP(e).pcb_port.list(),A=xP(e).source_trace.list(),u=[];return l.forEach((_,h)=>{const d=r[_.pcb_port_id];let m=!1;for(const f of A)f.connected_source_port_ids.includes(_.source_port_id)&&f.connected_source_net_ids.length>0&&(m=!0);if(!d)return;const p={x:_.x,y:_.y},g=c(p,d);g&&u.push({key:`${_.pcb_port_id}-${h}`,startPoint:p,endPoint:g,isInNet:m})}),u},[e,i,r,o]);return!e||!o?n:(t||(t=iA()),K.jsxs("div",{style:{position:"relative"},children:[n,K.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:gA.ratsNestOverlay},children:s.map(({key:a,startPoint:c,endPoint:l,isInNet:A})=>{const u=dt(t,c),_=dt(t,l);return K.jsx("line",{x1:u.x,y1:u.y,x2:_.x,y2:_.y,stroke:"white",strokeWidth:"1",strokeDasharray:A?"6,6":void 0},a)})})]}))},dgo={version:"1.11.371"},IP=(t,e,n)=>{const o=I_(s=>s.is_mouse_over_container),i=j.useRef(o),r=j.useRef(e);j.useEffect(()=>{i.current=o},[o]),j.useEffect(()=>{r.current=e},[e]),j.useEffect(()=>{if(!t)return;const s=a=>{const c=a.target;if(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)return;const l=t.split("+"),A=l.includes("ctrl"),u=l.includes("shift"),_=l.includes("alt"),h=l.includes("meta"),d=l[l.length-1],m=n?.current?n.current.contains(document.activeElement)||document.activeElement===n.current:!1;(i.current||m)&&(!A||a.ctrlKey)&&(!u||a.shiftKey)&&(!_||a.altKey)&&(!h||a.metaKey)&&a.key.toLowerCase()===d.toLowerCase()&&(a.preventDefault(),r.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},hgo=()=>{const[t,e]=j.useState(!1);return j.useEffect(()=>{const n=()=>{e(window.innerWidth<=768)};return n(),window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t},JL=(t,e={stopPropagation:!0})=>{const n=j.useRef(0),o=j.useCallback(s=>{e.stopPropagation&&s.stopPropagation();const a=Date.now();a-n.current<300||(n.current=a,t?.(s))},[t,e.stopPropagation]),i=j.useCallback(s=>{s.preventDefault(),o(s)},[o]);return{onClick:o,onTouchEnd:i,style:{touchAction:"manipulation"}}},EP=({children:t,isSmallScreen:e,onClick:n,...o})=>{const{style:i,...r}=JL(n);return K.jsx("div",{...o,...r,style:{backgroundColor:"#1F1F1F",border:"1px solid #666",margin:0,padding:4,paddingLeft:e?8:6,paddingRight:e?8:6,borderRadius:2,color:"#eee",cursor:"pointer",fontSize:12,height:"fit-content",userSelect:"none",whiteSpace:"nowrap",...i,...o.style},children:t})},mgo=t=>{const e=new Map;return t.forEach((n,o)=>{const i=n.error_type||"unknown_error",r=e.get(i)||[];r.push({error:n,index:o,errorId:V7(n,o)}),e.set(i,r)}),Array.from(e.entries()).map(([n,o])=>({errorType:n,errors:o}))},ggo=({onClose:t,setHoveredErrorId:e,setFocusedErrorId:n,highlightDurationMs:o=3e3})=>{const i=j.useRef(null),r=j.useRef(null),s=j.useRef(null),a=j.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),r.current!==null&&(window.cancelAnimationFrame(r.current),r.current=null)},[]);j.useEffect(()=>a,[a]);const c=j.useCallback(A=>{a(),s.current=A,e(A),n(null),r.current=window.requestAnimationFrame(()=>{n(A),r.current=null}),t(),i.current=window.setTimeout(()=>{s.current=null,e(null),n(null),i.current=null},o)},[a,o,t,n,e]),l=j.useCallback(A=>s.current===A,[]);return{handleErrorSelect:c,isSelectedError:l}},pgo=({errorId:t,errorMessage:e,copiedErrorId:n,onCopy:o})=>{const{style:i,...r}=JL(()=>o(e,t));return K.jsx("button",{type:"button","aria-label":n===t?"Error message copied":"Copy error message",style:{position:"absolute",top:12,right:16,cursor:"pointer",color:"#888",fontSize:16,background:"none",border:"none",padding:0,display:"flex",alignItems:"center",...i},...r,children:n===t?K.jsx("span",{style:{color:"#4caf50",fontSize:12},children:"Copied!"}):K.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:K.jsx("path",{d:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"})})})},fgo=({elements:t,isOpen:e,isSmallScreen:n,onToggle:o,onClose:i,setHoveredErrorId:r,setFocusedErrorId:s})=>{const[a,c]=j.useState(null),[l,A]=j.useState(new Set),[u,_]=j.useState(new Set),[,h]=nho(),{handleErrorSelect:d,isSelectedError:m}=ggo({onClose:i,setHoveredErrorId:r,setFocusedErrorId:s}),p=j.useMemo(()=>t?.filter(I=>I.type.includes("error"))??[],[t]),g=p.length,f=j.useMemo(()=>mgo(p),[p]),y=j.useCallback(I=>{A(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]),x=j.useCallback(I=>{_(E=>{const b=new Set(E);return b.has(I)?b.delete(I):b.add(I),b})},[]);return K.jsxs("div",{style:{position:"relative"},children:[K.jsx(EP,{isSmallScreen:n,style:g>0?{color:"red"}:void 0,onClick:o,children:K.jsxs("div",{children:[g," errors"]})}),e&&g>0&&K.jsx("div",{style:{position:"absolute",top:"100%",left:0,backgroundColor:"#2a2a2a",border:"1px solid #666",borderRadius:4,marginTop:4,zIndex:1e3,minWidth:n?"280px":"400px",maxWidth:n?"90vw":"600px",maxHeight:"400px",overflow:"auto",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.3)"},children:f.map(({errorType:I,errors:E},b)=>{const P=l.has(I);return K.jsxs("div",{style:{borderBottom:b<f.length-1?"1px solid #444":"none"},children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",cursor:"pointer",backgroundColor:"#232323",transition:"background-color 0.2s ease",touchAction:"manipulation",position:"sticky",top:0,zIndex:1},onMouseEnter:B=>{B.currentTarget.style.backgroundColor="#303030"},onMouseLeave:B=>{B.currentTarget.style.backgroundColor="#232323"},onTouchStart:B=>{B.stopPropagation(),B.currentTarget.style.backgroundColor="#303030"},onTouchEnd:B=>{B.stopPropagation(),B.preventDefault(),B.currentTarget.style.backgroundColor="#232323",y(I)},onClick:B=>{B.stopPropagation(),y(I)},children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#ff6b6b"},children:[K.jsx("div",{style:{color:"#888",fontSize:"16px",transform:P?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease",flexShrink:0},children:"›"}),K.jsx("div",{style:{fontWeight:"bold",fontSize:n?"12px":"13px"},children:I})]}),K.jsx("div",{style:{fontSize:n?"12px":"13px",color:"#aaa",whiteSpace:"nowrap",marginLeft:12},children:E.length})]}),!P&&E.map(({error:B,index:w,errorId:k})=>{const N=u.has(k),L=B.message??"No error message";return K.jsxs("div",{style:{borderTop:"1px solid #3a3a3a"},children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px 12px 24px",cursor:"pointer",backgroundColor:"#2a2a2a",transition:"background-color 0.2s ease",touchAction:"manipulation"},onMouseEnter:F=>{F.currentTarget.style.backgroundColor="#333",r(k)},onMouseLeave:F=>{F.currentTarget.style.backgroundColor="#2a2a2a",m(k)||r(null)},onTouchStart:F=>{F.stopPropagation(),F.currentTarget.style.backgroundColor="#333",r(k)},onTouchEnd:F=>{F.stopPropagation(),F.preventDefault(),F.currentTarget.style.backgroundColor="#2a2a2a",d(k)},onClick:F=>{F.stopPropagation(),d(k)},children:[K.jsx("div",{style:{flex:1,fontSize:n?"12px":"13px",color:"#ddd",lineHeight:1.4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",userSelect:"text"},children:L}),K.jsx("button",{type:"button","aria-label":N?"Collapse error details":"Expand error details",style:{color:"#888",fontSize:"16px",transform:N?"rotate(0deg)":"rotate(90deg)",transition:"transform 0.2s ease",flexShrink:0,background:"none",border:"none",padding:0,cursor:"pointer"},onMouseDown:F=>F.stopPropagation(),onClick:F=>{F.stopPropagation(),x(k)},onTouchEnd:F=>{F.stopPropagation(),F.preventDefault(),x(k)},children:"›"})]}),N&&K.jsxs("div",{"data-error-id":w,style:{display:"block",padding:"12px 16px 12px 24px",backgroundColor:"#1a1a1a",borderTop:"1px solid #444",position:"relative"},children:[K.jsx("div",{style:{fontSize:n?"11px":"12px",color:"#ccc",lineHeight:1.5,wordWrap:"break-word",overflowWrap:"break-word",hyphens:"auto",userSelect:"text",paddingRight:30},onMouseDown:F=>F.stopPropagation(),onClick:F=>F.stopPropagation(),children:L}),K.jsx(pgo,{errorId:k,errorMessage:L,copiedErrorId:a,onCopy:(F,G)=>{h(F),c(G),setTimeout(()=>c(null),2e3)}})]})]},k)})]},I)})})]})},ygo=({name:t,selected:e,onClick:n})=>{const{style:o,...i}=JL(n);return K.jsxs("div",{className:U7`
5532
5532
  margin-top: 2px;
5533
5533
  padding: 4px;
5534
5534
  padding-left: 8px;
@@ -5745,7 +5745,7 @@ test("${l} should solve problem correctly", () => {
5745
5745
  // Add more specific assertions based on expected output
5746
5746
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5747
5747
  })
5748
- `,u=new Blob([A],{type:"text/plain"}),_=URL.createObjectURL(u),h=document.createElement("a");h.href=_,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(_)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},xIt=t=>t.activeSubSolver?[t,...xIt(t.activeSubSolver)]:[t],$po=({solver:t})=>{const e=xIt(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(qpo,{solver:n})]},n.constructor.name))})},Zpo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=j.useReducer(m=>!m,!1),a=j.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},_=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};j.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),j.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsx($po,{solver:t})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),K.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),K.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),K.jsx("button",{onClick:_,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&K.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",K.jsx("span",{className:"font-medium",children:d})]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},efo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},tfo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=efo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const _=t.pipelineDef[e+1],h=_?t.firstIterationOfPhase?.[_.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},nfo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},ofo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ifo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),rfo=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=ifo(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",String(i)]},o))})]})},ySe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ySe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=ySe(o));return e},sfo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=ySe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},afo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>tfo(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):sfo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return K.jsxs("div",{className:"border-t border-gray-200",children:[K.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:o.map(a=>K.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),K.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.name} completes`,children:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(nfo,{status:a.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(ofo,{progress:a.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(rfo,{stats:a.stats})}),K.jsx("td",{className:"px-4 py-2",children:a.solverInstance?K.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},cfo=class extends Ri.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 lfo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,x=p.height??0;A(g,f),A(g+y,f+x)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,_=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>K.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>K.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var Afo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=j.useReducer(A=>A+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(_=>_.solverName===A);)t.step();r()}};return K.jsxs("div",{children:[K.jsx(Zpo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(cfo,{fallback:K.jsx(lfo,{graphics:s}),children:K.jsx(Jpo,{graphics:s})}),c&&K.jsx(afo,{solver:t,onStepUntilPhase:l})]})};const ufo=()=>{j.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},_fo=t=>t.toLowerCase().includes("pack")?J$n:t.toLowerCase().includes("rout")?tZn:N$n,dfo=({solverEvents:t=[]})=>{const[e,n]=j.useState(null);ufo();const o=j.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=j.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=j.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=y_e[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(y_e).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return K.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=_fo(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsx(PC,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(Afo,{solver:s.instance})}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.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:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},CIt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{j.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{Uw.captureException(o)}catch{}}},[t,e]),j.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{Uw.captureException(i,{error_type:o.type})}catch{}}},[n])},IIt=t=>{j.useEffect(()=>{try{X5n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},EIt="0.0.2068",hfo={version:EIt},cZ=$Je()(ZJe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),mfo=t=>{const[e,n]=j.useState([]),[o,i]=j.useState(null),[r,s]=j.useState(""),[a,c]=Cw("eval-version-selection",null),l=cZ(h=>h.setLastRunEvalVersion),A=cZ(h=>h.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:j.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:A,search:r,setSearch:s,selectVersion:h=>{c(h),s("")}}},gfo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=j.useState(""),[s,a]=j.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),A=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):l&&r(s))};return K.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:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.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:u=>a(u.target.value),onKeyDown:A}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),l&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.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:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},pfo=t=>{const e=j.useRef(null),n=i0(o=>o.recentEvents);j.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};function ffo(t){const e=yfo(t),n=j.forwardRef((o,i)=>{const{children:r,...s}=o,a=j.Children.toArray(r),c=a.find(Cfo);if(c){const l=c.props.children,A=a.map(u=>u===c?j.Children.count(l)>1?j.Children.only(null):j.isValidElement(l)?l.props.children:null:u);return K.jsx(e,{...s,ref:i,children:j.isValidElement(l)?j.cloneElement(l,void 0,A):null})}return K.jsx(e,{...s,ref:i,children:r})});return n.displayName=`${t}.Slot`,n}function yfo(t){const e=j.forwardRef((n,o)=>{const{children:i,...r}=n;if(j.isValidElement(i)){const s=Efo(i),a=Ifo(r,i.props);return i.type!==j.Fragment&&(a.ref=o?F2(o,s):s),j.cloneElement(i,a)}return j.Children.count(i)>1?j.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var xfo=Symbol("radix.slottable");function Cfo(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===xfo}function Ifo(t,e){const n={...e};for(const o in e){const i=t[o],r=e[o];/^on[A-Z]/.test(o)?i&&r?n[o]=(...a)=>{const c=r(...a);return i(...a),c}:i&&(n[o]=i):o==="style"?n[o]={...i,...r}:o==="className"&&(n[o]=[i,r].filter(Boolean).join(" "))}return{...t,...n}}function Efo(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lZ="Dialog",[bIt,SIt]=C5(lZ),[bfo,j5]=bIt(lZ),PIt=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=j.useRef(null),c=j.useRef(null),[l,A]=m4({prop:o,defaultProp:i??!1,onChange:r,caller:lZ});return K.jsx(bfo,{scope:e,triggerRef:a,contentRef:c,contentId:qg(),titleId:qg(),descriptionId:qg(),open:l,onOpenChange:A,onOpenToggle:j.useCallback(()=>A(u=>!u),[A]),modal:s,children:n})};PIt.displayName=lZ;var vIt="DialogTrigger",BIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(vIt,n),r=r0(e,i.triggerRef);return K.jsx(El.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":ISe(i.open),...o,ref:r,onClick:Ir(t.onClick,i.onOpenToggle)})});BIt.displayName=vIt;var xSe="DialogPortal",[Sfo,MIt]=bIt(xSe,{forceMount:void 0}),wIt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=j5(xSe,e);return K.jsx(Sfo,{scope:e,forceMount:n,children:j.Children.map(o,s=>K.jsx(Vy,{present:n||r.open,children:K.jsx(Mq,{asChild:!0,container:i,children:s})}))})};wIt.displayName=xSe;var AZ="DialogOverlay",DIt=j.forwardRef((t,e)=>{const n=MIt(AZ,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(AZ,t.__scopeDialog);return r.modal?K.jsx(Vy,{present:o||r.open,children:K.jsx(vfo,{...i,ref:e})}):null});DIt.displayName=AZ;var Pfo=ffo("DialogOverlay.RemoveScroll"),vfo=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(AZ,n);return K.jsx(Hq,{as:Pfo,allowPinchZoom:!0,shards:[i.contentRef],children:K.jsx(El.div,{"data-state":ISe(i.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),a9="DialogContent",TIt=j.forwardRef((t,e)=>{const n=MIt(a9,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(a9,t.__scopeDialog);return K.jsx(Vy,{present:o||r.open,children:r.modal?K.jsx(Bfo,{...i,ref:e}):K.jsx(Mfo,{...i,ref:e})})});TIt.displayName=a9;var Bfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(null),i=r0(e,n.contentRef,o);return j.useEffect(()=>{const r=o.current;if(r)return hEe(r)},[]),K.jsx(QIt,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ir(t.onCloseAutoFocus,r=>{r.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Ir(t.onPointerDownOutside,r=>{const s=r.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&r.preventDefault()}),onFocusOutside:Ir(t.onFocusOutside,r=>r.preventDefault())})}),Mfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(!1),i=j.useRef(!1);return K.jsx(QIt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:r=>{t.onCloseAutoFocus?.(r),r.defaultPrevented||(o.current||n.triggerRef.current?.focus(),r.preventDefault()),o.current=!1,i.current=!1},onInteractOutside:r=>{t.onInteractOutside?.(r),r.defaultPrevented||(o.current=!0,r.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=r.target;n.triggerRef.current?.contains(s)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&i.current&&r.preventDefault()}})}),QIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:r,...s}=t,a=j5(a9,n),c=j.useRef(null),l=r0(e,c);return j3e(),K.jsxs(K.Fragment,{children:[K.jsx(gq,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:i,onUnmountAutoFocus:r,children:K.jsx(WH,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ISe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),K.jsxs(K.Fragment,{children:[K.jsx(Dfo,{titleId:a.titleId}),K.jsx(Qfo,{contentRef:c,descriptionId:a.descriptionId})]})]})}),CSe="DialogTitle",RIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(CSe,n);return K.jsx(El.h2,{id:i.titleId,...o,ref:e})});RIt.displayName=CSe;var NIt="DialogDescription",kIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(NIt,n);return K.jsx(El.p,{id:i.descriptionId,...o,ref:e})});kIt.displayName=NIt;var HIt="DialogClose",LIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(HIt,n);return K.jsx(El.button,{type:"button",...o,ref:e,onClick:Ir(t.onClick,()=>i.onOpenChange(!1))})});LIt.displayName=HIt;function ISe(t){return t?"open":"closed"}var FIt="DialogTitleWarning",[wfo,OIt]=X2n(FIt,{contentName:a9,titleName:CSe,docsSlug:"dialog"}),Dfo=({titleId:t})=>{const e=OIt(FIt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
5748
+ `,u=new Blob([A],{type:"text/plain"}),_=URL.createObjectURL(u),h=document.createElement("a");h.href=_,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(_)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},xIt=t=>t.activeSubSolver?[t,...xIt(t.activeSubSolver)]:[t],$po=({solver:t})=>{const e=xIt(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(qpo,{solver:n})]},n.constructor.name))})},Zpo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=j.useReducer(m=>!m,!1),a=j.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},_=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};j.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),j.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,d=h?t.getCurrentPhase():null;return K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsx($po,{solver:t})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),K.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),K.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),K.jsx("button",{onClick:_,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&K.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),d&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",K.jsx("span",{className:"font-medium",children:d})]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},efo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},tfo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=efo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const _=t.pipelineDef[e+1],h=_?t.firstIterationOfPhase?.[_.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},nfo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},ofo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ifo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),rfo=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=ifo(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",String(i)]},o))})]})},ySe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(ySe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=ySe(o));return e},sfo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=ySe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},afo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>tfo(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):sfo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return K.jsxs("div",{className:"border-t border-gray-200",children:[K.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:o.map(a=>K.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),K.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.name} completes`,children:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(nfo,{status:a.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(ofo,{progress:a.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(rfo,{stats:a.stats})}),K.jsx("td",{className:"px-4 py-2",children:a.solverInstance?K.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},cfo=class extends Ri.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 lfo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,x=p.height??0;A(g,f),A(g+y,f+x)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,_=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${_} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>K.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>K.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var Afo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=j.useReducer(A=>A+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(_=>_.solverName===A);)t.step();r()}};return K.jsxs("div",{children:[K.jsx(Zpo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(cfo,{fallback:K.jsx(lfo,{graphics:s}),children:K.jsx(Jpo,{graphics:s})}),c&&K.jsx(afo,{solver:t,onStepUntilPhase:l})]})};const ufo=()=>{j.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},_fo=t=>t.toLowerCase().includes("pack")?J$n:t.toLowerCase().includes("rout")?tZn:N$n,dfo=({solverEvents:t=[]})=>{const[e,n]=j.useState(null);ufo();const o=j.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=j.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=j.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=y_e[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(y_e).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return K.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=_fo(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsx(PC,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(Afo,{solver:s.instance})}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.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:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},CIt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{j.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{Uw.captureException(o)}catch{}}},[t,e]),j.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{Uw.captureException(i,{error_type:o.type})}catch{}}},[n])},IIt=t=>{j.useEffect(()=>{try{X5n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},EIt="0.0.2069",hfo={version:EIt},cZ=$Je()(ZJe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),mfo=t=>{const[e,n]=j.useState([]),[o,i]=j.useState(null),[r,s]=j.useState(""),[a,c]=Cw("eval-version-selection",null),l=cZ(h=>h.setLastRunEvalVersion),A=cZ(h=>h.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:j.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:A,search:r,setSearch:s,selectVersion:h=>{c(h),s("")}}},gfo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=j.useState(""),[s,a]=j.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),A=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):l&&r(s))};return K.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:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.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:u=>a(u.target.value),onKeyDown:A}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),l&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.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:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},pfo=t=>{const e=j.useRef(null),n=i0(o=>o.recentEvents);j.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};function ffo(t){const e=yfo(t),n=j.forwardRef((o,i)=>{const{children:r,...s}=o,a=j.Children.toArray(r),c=a.find(Cfo);if(c){const l=c.props.children,A=a.map(u=>u===c?j.Children.count(l)>1?j.Children.only(null):j.isValidElement(l)?l.props.children:null:u);return K.jsx(e,{...s,ref:i,children:j.isValidElement(l)?j.cloneElement(l,void 0,A):null})}return K.jsx(e,{...s,ref:i,children:r})});return n.displayName=`${t}.Slot`,n}function yfo(t){const e=j.forwardRef((n,o)=>{const{children:i,...r}=n;if(j.isValidElement(i)){const s=Efo(i),a=Ifo(r,i.props);return i.type!==j.Fragment&&(a.ref=o?F2(o,s):s),j.cloneElement(i,a)}return j.Children.count(i)>1?j.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var xfo=Symbol("radix.slottable");function Cfo(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===xfo}function Ifo(t,e){const n={...e};for(const o in e){const i=t[o],r=e[o];/^on[A-Z]/.test(o)?i&&r?n[o]=(...a)=>{const c=r(...a);return i(...a),c}:i&&(n[o]=i):o==="style"?n[o]={...i,...r}:o==="className"&&(n[o]=[i,r].filter(Boolean).join(" "))}return{...t,...n}}function Efo(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lZ="Dialog",[bIt,SIt]=C5(lZ),[bfo,j5]=bIt(lZ),PIt=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=j.useRef(null),c=j.useRef(null),[l,A]=m4({prop:o,defaultProp:i??!1,onChange:r,caller:lZ});return K.jsx(bfo,{scope:e,triggerRef:a,contentRef:c,contentId:qg(),titleId:qg(),descriptionId:qg(),open:l,onOpenChange:A,onOpenToggle:j.useCallback(()=>A(u=>!u),[A]),modal:s,children:n})};PIt.displayName=lZ;var vIt="DialogTrigger",BIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(vIt,n),r=r0(e,i.triggerRef);return K.jsx(El.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":ISe(i.open),...o,ref:r,onClick:Ir(t.onClick,i.onOpenToggle)})});BIt.displayName=vIt;var xSe="DialogPortal",[Sfo,MIt]=bIt(xSe,{forceMount:void 0}),wIt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=j5(xSe,e);return K.jsx(Sfo,{scope:e,forceMount:n,children:j.Children.map(o,s=>K.jsx(Vy,{present:n||r.open,children:K.jsx(Mq,{asChild:!0,container:i,children:s})}))})};wIt.displayName=xSe;var AZ="DialogOverlay",DIt=j.forwardRef((t,e)=>{const n=MIt(AZ,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(AZ,t.__scopeDialog);return r.modal?K.jsx(Vy,{present:o||r.open,children:K.jsx(vfo,{...i,ref:e})}):null});DIt.displayName=AZ;var Pfo=ffo("DialogOverlay.RemoveScroll"),vfo=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(AZ,n);return K.jsx(Hq,{as:Pfo,allowPinchZoom:!0,shards:[i.contentRef],children:K.jsx(El.div,{"data-state":ISe(i.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),a9="DialogContent",TIt=j.forwardRef((t,e)=>{const n=MIt(a9,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=j5(a9,t.__scopeDialog);return K.jsx(Vy,{present:o||r.open,children:r.modal?K.jsx(Bfo,{...i,ref:e}):K.jsx(Mfo,{...i,ref:e})})});TIt.displayName=a9;var Bfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(null),i=r0(e,n.contentRef,o);return j.useEffect(()=>{const r=o.current;if(r)return hEe(r)},[]),K.jsx(QIt,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ir(t.onCloseAutoFocus,r=>{r.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Ir(t.onPointerDownOutside,r=>{const s=r.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&r.preventDefault()}),onFocusOutside:Ir(t.onFocusOutside,r=>r.preventDefault())})}),Mfo=j.forwardRef((t,e)=>{const n=j5(a9,t.__scopeDialog),o=j.useRef(!1),i=j.useRef(!1);return K.jsx(QIt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:r=>{t.onCloseAutoFocus?.(r),r.defaultPrevented||(o.current||n.triggerRef.current?.focus(),r.preventDefault()),o.current=!1,i.current=!1},onInteractOutside:r=>{t.onInteractOutside?.(r),r.defaultPrevented||(o.current=!0,r.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=r.target;n.triggerRef.current?.contains(s)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&i.current&&r.preventDefault()}})}),QIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:r,...s}=t,a=j5(a9,n),c=j.useRef(null),l=r0(e,c);return j3e(),K.jsxs(K.Fragment,{children:[K.jsx(gq,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:i,onUnmountAutoFocus:r,children:K.jsx(WH,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ISe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),K.jsxs(K.Fragment,{children:[K.jsx(Dfo,{titleId:a.titleId}),K.jsx(Qfo,{contentRef:c,descriptionId:a.descriptionId})]})]})}),CSe="DialogTitle",RIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(CSe,n);return K.jsx(El.h2,{id:i.titleId,...o,ref:e})});RIt.displayName=CSe;var NIt="DialogDescription",kIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(NIt,n);return K.jsx(El.p,{id:i.descriptionId,...o,ref:e})});kIt.displayName=NIt;var HIt="DialogClose",LIt=j.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=j5(HIt,n);return K.jsx(El.button,{type:"button",...o,ref:e,onClick:Ir(t.onClick,()=>i.onOpenChange(!1))})});LIt.displayName=HIt;function ISe(t){return t?"open":"closed"}var FIt="DialogTitleWarning",[wfo,OIt]=X2n(FIt,{contentName:a9,titleName:CSe,docsSlug:"dialog"}),Dfo=({titleId:t})=>{const e=OIt(FIt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
5749
5749
 
5750
5750
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
5751
5751
 
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.2069",
5
+ "version": "0.0.2070",
6
6
  "exports": {
7
7
  ".": "./dist/preview.js",
8
8
  "./preview": "./dist/preview.js",
@@ -52,7 +52,7 @@
52
52
  "@tscircuit/fake-snippets": "^0.0.163",
53
53
  "@tscircuit/file-server": "^0.0.32",
54
54
  "@tscircuit/internal-dynamic-import": "^0.0.7",
55
- "@tscircuit/pcb-viewer": "1.11.371",
55
+ "@tscircuit/pcb-viewer": "1.11.372",
56
56
  "@tscircuit/schematic-viewer": "^2.0.62",
57
57
  "@types/bun": "latest",
58
58
  "@types/debug": "^4.1.12",