@tscircuit/runframe 0.0.1904 → 0.0.1906
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.
|
@@ -1821,7 +1821,7 @@ var useErrorTelemetry = ({
|
|
|
1821
1821
|
};
|
|
1822
1822
|
|
|
1823
1823
|
// package.json
|
|
1824
|
-
var version = "0.0.
|
|
1824
|
+
var version = "0.0.1904";
|
|
1825
1825
|
var package_default = {
|
|
1826
1826
|
name: "@tscircuit/runframe",
|
|
1827
1827
|
main: "dist/preview.js",
|
|
@@ -1877,7 +1877,7 @@ var package_default = {
|
|
|
1877
1877
|
"@tscircuit/file-server": "^0.0.32",
|
|
1878
1878
|
"@tscircuit/internal-dynamic-import": "^0.0.0",
|
|
1879
1879
|
"@tscircuit/pcb-viewer": "1.11.368",
|
|
1880
|
-
"@tscircuit/schematic-viewer": "^2.0.
|
|
1880
|
+
"@tscircuit/schematic-viewer": "^2.0.60",
|
|
1881
1881
|
"@types/bun": "latest",
|
|
1882
1882
|
"@types/debug": "^4.1.12",
|
|
1883
1883
|
"@types/react": "^19.1.10",
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -5375,7 +5375,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
|
|
|
5375
5375
|
50% { opacity: 0.2; }
|
|
5376
5376
|
100% { opacity: 0.6; }
|
|
5377
5377
|
}
|
|
5378
|
-
`,r.appendChild(g)}})}};i();const s=new MutationObserver(i);return s.observe(r,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},Bit=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],vHn=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:r}=t;te.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!r||!n||n.length===0)return;const i=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=Up(n).source_group?.list().filter(g=>!g.is_subcircuit)||[],l=Up(n).schematic_component?.list()||[],u=new Map;c.forEach(g=>{const y=g;if(y.parent_source_group_id){const P=u.get(y.parent_source_group_id)||[];P.push(g.source_group_id),u.set(y.parent_source_group_id,P)}});const _=g=>{const y=[],P=u.get(g)||[];for(const v of P)y.push(v),y.push(..._(v));return y},d=g=>{const y=c.find(P=>P.source_group_id===g);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},m=c.length>0&&c.some(g=>g.name&&g.name.trim()!=="");let h=[];if(m){const g=new Map;for(const y of l){const P=Up(n).source_component.get(y.source_component_id);P?.source_group_id&&(g.has(P.source_group_id)||g.set(P.source_group_id,[]),g.get(P.source_group_id).push(y))}c.forEach((y,P)=>{let v=g.get(y.source_group_id)||[];const S=_(y.source_group_id);for(const M of S){const w=g.get(M)||[];v=[...v,...w]}if(v.length>0){const M=d(y.source_group_id),w=_(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;h.push({id:y.source_group_id,name:y.name||`Group ${P+1}`,components:v,color:Bit[P%Bit.length],depthLevel:M,hasChildren:w,sourceGroupId:y.source_group_id})}})}const p=s.viewBox.baseVal,x=s.getBoundingClientRect(),f=Math.min(x.width/p.width,x.height/p.height)||1;h.sort((g,y)=>g.depthLevel-y.depthLevel),h.forEach(g=>{if(g.components.length===0)return;const y=SHn(g.components,s);if(!y)return;const P=Math.max(8,Math.min(25,15/Math.max(f,.3))),v=g.hasChildren?P*.6:0,S=P+v,M=Math.max(1,2/Math.max(f,.5)),w=g.depthLevel===0?M:M*.7,A=Math.max(4,8/Math.max(f,.5)),D=g.hasChildren?1.3:1,I=A*D,H=I*.5,F=document.createElementNS("http://www.w3.org/2000/svg","rect");F.setAttribute("class","schematic-group-overlay"),F.setAttribute("x",(y.minX-S).toString()),F.setAttribute("y",(y.minY-S).toString()),F.setAttribute("width",(y.maxX-y.minX+S*2).toString()),F.setAttribute("height",(y.maxY-y.minY+S*2).toString()),F.setAttribute("fill","none"),F.setAttribute("stroke",g.color),F.setAttribute("stroke-width",w.toString()),F.setAttribute("stroke-dasharray",`${I},${H}`),F.setAttribute("opacity","0.8"),F.setAttribute("rx","0"),F.setAttribute("ry","0");const B=Math.max(6,Math.min(20,14/Math.max(f,.2))),z=g.depthLevel===0||g.depthLevel===1?0:g.depthLevel*.2,X=B*(1-z),Y=Math.max(1,X*.2),J=g.name,ne=document.createElementNS("http://www.w3.org/2000/svg","text");ne.setAttribute("font-size",X.toString()),ne.setAttribute("font-family","Arial, sans-serif"),ne.textContent=J,s.appendChild(ne);const ce=ne.getBBox();s.removeChild(ne);const Z=ce.width+Y*2,oe=X+Y*2,se=y.minX-S,le=y.minY-S-oe,fe=document.createElementNS("http://www.w3.org/2000/svg","rect");fe.setAttribute("class","schematic-group-overlay"),fe.setAttribute("x",se.toString()),fe.setAttribute("y",(le-oe).toString()),fe.setAttribute("width",Z.toString()),fe.setAttribute("height",oe.toString()),fe.setAttribute("fill","transparent"),fe.setAttribute("rx","0"),fe.setAttribute("ry","0");const Se=document.createElementNS("http://www.w3.org/2000/svg","text");Se.setAttribute("class","schematic-group-overlay"),Se.setAttribute("x",(se+Y).toString()),Se.setAttribute("y",(le+oe-Y).toString()),Se.setAttribute("fill",g.color),Se.setAttribute("font-size",X.toString()),Se.setAttribute("font-family","Arial, sans-serif"),Se.setAttribute("font-weight",g.depthLevel===0?"600":"500"),Se.setAttribute("stroke",g.color),Se.setAttribute("stroke-width",Math.max(.2,X*.02).toString()),Se.textContent=J,s.appendChild(F),s.appendChild(fe),s.appendChild(Se)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(i)},[e,o,r])};function SHn(t,e){let n=1/0,o=1/0,r=-1/0,i=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),r=Math.max(r,l.x+l.width),i=Math.max(i,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:r,maxY:i}}var CHn=zl("schematic-viewer"),MHn=()=>{zl.enable("schematic-viewer*")},THn=CHn,zit=t=>{const[e,n]=te.useState(0),[o,r]=te.useState(0);return te.useEffect(()=>{if(!t.current)return;const i=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),r(a?.height||0)};i();const s=new ResizeObserver(i);return s.observe(t.current),window.addEventListener("resize",i),()=>{s.disconnect(),window.removeEventListener("resize",i)}},[]),{containerWidth:e,containerHeight:o}},wHn=THn.extend("useComponentDragging"),EHn=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:r,realToSvgProjection:i,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=te.useState(null),u=rr(i,r),_=te.useRef(null),d=te.useRef(null),m=te.useRef(new Map);te.useEffect(()=>{e.forEach(M=>{"edit_event_type"in M&&M.edit_event_type==="edit_schematic_component_location"&&!M.in_progress&&m.current.set(M.schematic_component_id,{...M.new_center})})},[e]);const h=te.useCallback((M,w,A)=>{if(!s)return!1;const D=A.closest('[data-circuit-json-type="schematic_component"]');if(!D)return!1;const I=D.getAttribute("data-schematic-component-id");if(!I)return!1;o&&o();const H=Up(n).schematic_component.get(I);if(!H)return!1;_.current={x:M,y:w};let F;const B=m.current.get(I);if(B)F={...B};else{const X=Fit({editEvents:e,schematic_component_id:I});F={x:H.center.x+X.x,y:H.center.y+X.y},m.current.set(I,{...F})}const z={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:I,original_center:F,new_center:{...F},in_progress:!0,created_at:Date.now(),_element:D};return d.current=z,l(z),!0},[o,s,n,e]),p=te.useCallback(M=>{h(M.clientX,M.clientY,M.target)},[h]),x=te.useCallback(M=>{if(M.touches.length!==1)return;const w=M.touches[0];h(w.clientX,w.clientY,M.target)&&M.preventDefault()},[h]),f=te.useCallback((M,w)=>{if(!d.current||!_.current)return;const A={x:M-_.current.x,y:w-_.current.y},D={x:A.x/u.a,y:A.y/u.d};let I={x:d.current.original_center.x+D.x,y:d.current.original_center.y+D.y};if(a){const F=B=>Math.round(B*10)/10;I={x:F(I.x),y:F(I.y)}}const H={...d.current,new_center:I};d.current=H,l(H)},[u,a]),g=te.useCallback(M=>f(M.clientX,M.clientY),[f]),y=te.useCallback(M=>{if(M.touches.length!==1||!d.current)return;M.preventDefault();const w=M.touches[0];f(w.clientX,w.clientY)},[f]),P=te.useCallback(()=>{if(!d.current)return;const M={...d.current,in_progress:!1};m.current.set(M.schematic_component_id,{...M.new_center}),wHn("endDrag calling onEditEvent with new edit event",{newEditEvent:M}),t&&t(M),d.current=null,_.current=null,l(null)},[t]),v=te.useCallback(()=>P(),[P]),S=te.useCallback(()=>P(),[P]);return te.useEffect(()=>(window.addEventListener("mousemove",g),window.addEventListener("mouseup",v),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",v),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",S)}),[g,v,y,S]),{handleMouseDown:p,handleTouchStart:x,isDragging:!!d.current,activeEditEvent:c}},Y6={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},DHn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.schematicEditIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),j.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},AHn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.schematicGridIcon},children:j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:j.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},RHn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.viewMenuIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("circle",{cx:"12",cy:"12",r:"1"}),j.jsx("circle",{cx:"12",cy:"5",r:"1"}),j.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},kHn={version:"2.0.58"},NHn=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:r,onToggleGroups:i,showGrid:s,onToggleGrid:a})=>{const c=te.useMemo(()=>{if(!t||t.length===0)return!1;try{if((Up(t).source_group?.list()||[]).length>0)return!0;const u=Up(t).schematic_component?.list()||[];if(u.length>1){const _=new Set;for(const d of u){const m=Up(t).source_component.get(d.source_component_id);m?.ftype&&_.add(m.ftype)}return _.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?j.jsxs(j.Fragment,{children:[j.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:Y6.viewMenuBackdrop}}),j.jsxs("div",{style:{position:"absolute",top:"56px",right:"16px",backgroundColor:"#ffffff",color:"#000000",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",zIndex:Y6.viewMenu},children:[j.jsxs("div",{onClick:()=>{c&&i(!r)},onTouchEnd:l=>{l.preventDefault(),c&&i(!r)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:r&&"✓"}),"View Schematic Groups"]}),!c&&j.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),j.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),j.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(kHn?.version)]})]})]}):null},HHn=()=>j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:j.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),IHn=({onClick:t})=>j.jsx("div",{onClick:t,title:"Run SPICE simulation",style:{position:"absolute",top:"16px",right:"112px",backgroundColor:"#fff",color:"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.spiceSimulationIcon},children:j.jsx(HHn,{})});xj.register(aHn,uHn,VNn,zNn,qNn,oHn,GNn);var bj=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],Vit=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},LHn=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:r})=>{const i=te.useMemo(()=>{const c=e.some(u=>u.toLowerCase().startsWith("v(")),l=e.some(u=>u.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!r)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return j.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(u=>({x:Number(u.name),y:u[c]})),borderColor:bj[l%bj.length],backgroundColor:bj[l%bj.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return Vit(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>Vit(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:i,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return j.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:j.jsx(yHn,{options:a,data:s})})},OHn=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:r,error:i,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,u]=te.useState(String(s.startTime)),[_,d]=te.useState(String(s.duration));te.useEffect(()=>{u(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const m=()=>{a({...s,startTime:Number(l),duration:Number(_)})},h=o.filter(p=>{const x=p.toLowerCase().startsWith("v("),f=p.toLowerCase().startsWith("i(");return!!(s.showVoltage&&x||s.showCurrent&&f)});return j.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1002,fontFamily:"sans-serif"},children:j.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[j.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),j.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),j.jsx("div",{children:j.jsx(LHn,{plotData:n,nodes:h,isLoading:r,error:i,hasRun:c})}),j.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[j.jsxs("div",{style:{display:"flex",gap:"16px"},children:[j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:p=>a({...s,showVoltage:p.target.checked})}),"Voltage"]}),j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:p=>a({...s,showCurrent:p.target.checked})}),"Current"]})]}),j.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[j.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),j.jsx("input",{id:"startTime",type:"number",value:l,onChange:p=>u(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),j.jsx("input",{id:"duration",type:"number",value:_,onChange:p=>d(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("button",{onClick:m,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),j.jsxs("div",{style:{marginTop:"24px"},children:[j.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),j.jsx("pre",{style:{backgroundColor:"#fafafa",padding:"16px",borderRadius:"6px",maxHeight:"150px",overflowY:"auto",border:"1px solid #eee",color:"#333",fontSize:"13px",fontFamily:"monospace"},children:t})]})]})})},FHn="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",vj=null,BHn=()=>{if(typeof window>"u")return null;if(vj)return vj;try{const t=new Blob([atob(FHn)],{type:"application/javascript"});return vj=URL.createObjectURL(t),vj}catch(t){return console.error("Failed to create blob URL for worker",t),null}},zHn=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],r=Object.keys(e).filter(a=>a!==n),i=r;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return r.forEach(u=>{l[u]=e[u][c]}),l}),nodes:i}},VHn=t=>{const[e,n]=te.useState([]),[o,r]=te.useState([]),[i,s]=te.useState(!0),[a,c]=te.useState(null);return te.useEffect(()=>{if(!t){s(!1),n([]),r([]),c(null);return}s(!0),c(null),n([]),r([]);const l=BHn();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const u=new Worker(l,{type:"module"});return u.onmessage=_=>{if(_.data.type==="result")try{const{plotData:d,nodes:m}=zHn(_.data.result);n(d),r(m)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else _.data.type==="error"&&c(_.data.error);s(!1)},u.onerror=_=>{c(_.message),s(!1)},u.postMessage({spiceString:t}),()=>{u.terminate()}},[t]),{plotData:e,nodes:o,isLoading:i,error:a}},w2e=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},WHn=(t,e)=>{const o=iOe(t).toSpiceString(),i=o.split(`
|
|
5378
|
+
`,r.appendChild(g)}})}};i();const s=new MutationObserver(i);return s.observe(r,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},Bit=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],vHn=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:r}=t;te.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!r||!n||n.length===0)return;const i=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=Up(n).source_group?.list().filter(g=>!g.is_subcircuit)||[],l=Up(n).schematic_component?.list()||[],u=new Map;c.forEach(g=>{const y=g;if(y.parent_source_group_id){const P=u.get(y.parent_source_group_id)||[];P.push(g.source_group_id),u.set(y.parent_source_group_id,P)}});const _=g=>{const y=[],P=u.get(g)||[];for(const v of P)y.push(v),y.push(..._(v));return y},d=g=>{const y=c.find(P=>P.source_group_id===g);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},m=c.length>0&&c.some(g=>g.name&&g.name.trim()!=="");let h=[];if(m){const g=new Map;for(const y of l){const P=Up(n).source_component.get(y.source_component_id);P?.source_group_id&&(g.has(P.source_group_id)||g.set(P.source_group_id,[]),g.get(P.source_group_id).push(y))}c.forEach((y,P)=>{let v=g.get(y.source_group_id)||[];const S=_(y.source_group_id);for(const M of S){const w=g.get(M)||[];v=[...v,...w]}if(v.length>0){const M=d(y.source_group_id),w=_(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;h.push({id:y.source_group_id,name:y.name||`Group ${P+1}`,components:v,color:Bit[P%Bit.length],depthLevel:M,hasChildren:w,sourceGroupId:y.source_group_id})}})}const p=s.viewBox.baseVal,x=s.getBoundingClientRect(),f=Math.min(x.width/p.width,x.height/p.height)||1;h.sort((g,y)=>g.depthLevel-y.depthLevel),h.forEach(g=>{if(g.components.length===0)return;const y=SHn(g.components,s);if(!y)return;const P=Math.max(8,Math.min(25,15/Math.max(f,.3))),v=g.hasChildren?P*.6:0,S=P+v,M=Math.max(1,2/Math.max(f,.5)),w=g.depthLevel===0?M:M*.7,A=Math.max(4,8/Math.max(f,.5)),D=g.hasChildren?1.3:1,I=A*D,H=I*.5,F=document.createElementNS("http://www.w3.org/2000/svg","rect");F.setAttribute("class","schematic-group-overlay"),F.setAttribute("x",(y.minX-S).toString()),F.setAttribute("y",(y.minY-S).toString()),F.setAttribute("width",(y.maxX-y.minX+S*2).toString()),F.setAttribute("height",(y.maxY-y.minY+S*2).toString()),F.setAttribute("fill","none"),F.setAttribute("stroke",g.color),F.setAttribute("stroke-width",w.toString()),F.setAttribute("stroke-dasharray",`${I},${H}`),F.setAttribute("opacity","0.8"),F.setAttribute("rx","0"),F.setAttribute("ry","0");const B=Math.max(6,Math.min(20,14/Math.max(f,.2))),z=g.depthLevel===0||g.depthLevel===1?0:g.depthLevel*.2,X=B*(1-z),Y=Math.max(1,X*.2),J=g.name,ne=document.createElementNS("http://www.w3.org/2000/svg","text");ne.setAttribute("font-size",X.toString()),ne.setAttribute("font-family","Arial, sans-serif"),ne.textContent=J,s.appendChild(ne);const ce=ne.getBBox();s.removeChild(ne);const Z=ce.width+Y*2,oe=X+Y*2,se=y.minX-S,le=y.minY-S-oe,fe=document.createElementNS("http://www.w3.org/2000/svg","rect");fe.setAttribute("class","schematic-group-overlay"),fe.setAttribute("x",se.toString()),fe.setAttribute("y",(le-oe).toString()),fe.setAttribute("width",Z.toString()),fe.setAttribute("height",oe.toString()),fe.setAttribute("fill","transparent"),fe.setAttribute("rx","0"),fe.setAttribute("ry","0");const Se=document.createElementNS("http://www.w3.org/2000/svg","text");Se.setAttribute("class","schematic-group-overlay"),Se.setAttribute("x",(se+Y).toString()),Se.setAttribute("y",(le+oe-Y).toString()),Se.setAttribute("fill",g.color),Se.setAttribute("font-size",X.toString()),Se.setAttribute("font-family","Arial, sans-serif"),Se.setAttribute("font-weight",g.depthLevel===0?"600":"500"),Se.setAttribute("stroke",g.color),Se.setAttribute("stroke-width",Math.max(.2,X*.02).toString()),Se.textContent=J,s.appendChild(F),s.appendChild(fe),s.appendChild(Se)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(i)},[e,o,r])};function SHn(t,e){let n=1/0,o=1/0,r=-1/0,i=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),r=Math.max(r,l.x+l.width),i=Math.max(i,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:r,maxY:i}}var CHn=zl("schematic-viewer"),MHn=()=>{zl.enable("schematic-viewer*")},THn=CHn,zit=t=>{const[e,n]=te.useState(0),[o,r]=te.useState(0);return te.useEffect(()=>{if(!t.current)return;const i=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),r(a?.height||0)};i();const s=new ResizeObserver(i);return s.observe(t.current),window.addEventListener("resize",i),()=>{s.disconnect(),window.removeEventListener("resize",i)}},[]),{containerWidth:e,containerHeight:o}},wHn=THn.extend("useComponentDragging"),EHn=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:r,realToSvgProjection:i,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=te.useState(null),u=rr(i,r),_=te.useRef(null),d=te.useRef(null),m=te.useRef(new Map);te.useEffect(()=>{e.forEach(M=>{"edit_event_type"in M&&M.edit_event_type==="edit_schematic_component_location"&&!M.in_progress&&m.current.set(M.schematic_component_id,{...M.new_center})})},[e]);const h=te.useCallback((M,w,A)=>{if(!s)return!1;const D=A.closest('[data-circuit-json-type="schematic_component"]');if(!D)return!1;const I=D.getAttribute("data-schematic-component-id");if(!I)return!1;o&&o();const H=Up(n).schematic_component.get(I);if(!H)return!1;_.current={x:M,y:w};let F;const B=m.current.get(I);if(B)F={...B};else{const X=Fit({editEvents:e,schematic_component_id:I});F={x:H.center.x+X.x,y:H.center.y+X.y},m.current.set(I,{...F})}const z={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:I,original_center:F,new_center:{...F},in_progress:!0,created_at:Date.now(),_element:D};return d.current=z,l(z),!0},[o,s,n,e]),p=te.useCallback(M=>{h(M.clientX,M.clientY,M.target)},[h]),x=te.useCallback(M=>{if(M.touches.length!==1)return;const w=M.touches[0];h(w.clientX,w.clientY,M.target)&&M.preventDefault()},[h]),f=te.useCallback((M,w)=>{if(!d.current||!_.current)return;const A={x:M-_.current.x,y:w-_.current.y},D={x:A.x/u.a,y:A.y/u.d};let I={x:d.current.original_center.x+D.x,y:d.current.original_center.y+D.y};if(a){const F=B=>Math.round(B*10)/10;I={x:F(I.x),y:F(I.y)}}const H={...d.current,new_center:I};d.current=H,l(H)},[u,a]),g=te.useCallback(M=>f(M.clientX,M.clientY),[f]),y=te.useCallback(M=>{if(M.touches.length!==1||!d.current)return;M.preventDefault();const w=M.touches[0];f(w.clientX,w.clientY)},[f]),P=te.useCallback(()=>{if(!d.current)return;const M={...d.current,in_progress:!1};m.current.set(M.schematic_component_id,{...M.new_center}),wHn("endDrag calling onEditEvent with new edit event",{newEditEvent:M}),t&&t(M),d.current=null,_.current=null,l(null)},[t]),v=te.useCallback(()=>P(),[P]),S=te.useCallback(()=>P(),[P]);return te.useEffect(()=>(window.addEventListener("mousemove",g),window.addEventListener("mouseup",v),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",v),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",S)}),[g,v,y,S]),{handleMouseDown:p,handleTouchStart:x,isDragging:!!d.current,activeEditEvent:c}},Y6={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},DHn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.schematicEditIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),j.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},AHn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.schematicGridIcon},children:j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:j.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},RHn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.viewMenuIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("circle",{cx:"12",cy:"12",r:"1"}),j.jsx("circle",{cx:"12",cy:"5",r:"1"}),j.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},kHn={version:"2.0.59"},NHn=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:r,onToggleGroups:i,showGrid:s,onToggleGrid:a})=>{const c=te.useMemo(()=>{if(!t||t.length===0)return!1;try{if((Up(t).source_group?.list()||[]).length>0)return!0;const u=Up(t).schematic_component?.list()||[];if(u.length>1){const _=new Set;for(const d of u){const m=Up(t).source_component.get(d.source_component_id);m?.ftype&&_.add(m.ftype)}return _.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?j.jsxs(j.Fragment,{children:[j.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:Y6.viewMenuBackdrop}}),j.jsxs("div",{style:{position:"absolute",top:"56px",right:"16px",backgroundColor:"#ffffff",color:"#000000",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",zIndex:Y6.viewMenu},children:[j.jsxs("div",{onClick:()=>{c&&i(!r)},onTouchEnd:l=>{l.preventDefault(),c&&i(!r)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:r&&"✓"}),"View Schematic Groups"]}),!c&&j.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),j.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),j.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(kHn?.version)]})]})]}):null},HHn=()=>j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:j.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),IHn=({onClick:t})=>j.jsx("div",{onClick:t,title:"Run SPICE simulation",style:{position:"absolute",top:"16px",right:"112px",backgroundColor:"#fff",color:"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y6.spiceSimulationIcon},children:j.jsx(HHn,{})});xj.register(aHn,uHn,VNn,zNn,qNn,oHn,GNn);var bj=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],Vit=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},LHn=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:r})=>{const i=te.useMemo(()=>{const c=e.some(u=>u.toLowerCase().startsWith("v(")),l=e.some(u=>u.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!r)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return j.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(u=>({x:Number(u.name),y:u[c]})),borderColor:bj[l%bj.length],backgroundColor:bj[l%bj.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return Vit(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>Vit(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:i,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return j.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:j.jsx(yHn,{options:a,data:s})})},OHn=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:r,error:i,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,u]=te.useState(String(s.startTime)),[_,d]=te.useState(String(s.duration));te.useEffect(()=>{u(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const m=()=>{a({...s,startTime:Number(l),duration:Number(_)})},h=o.filter(p=>{const x=p.toLowerCase().startsWith("v("),f=p.toLowerCase().startsWith("i(");return!!(s.showVoltage&&x||s.showCurrent&&f)});return j.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1002,fontFamily:"sans-serif"},children:j.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[j.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),j.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),j.jsx("div",{children:j.jsx(LHn,{plotData:n,nodes:h,isLoading:r,error:i,hasRun:c})}),j.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[j.jsxs("div",{style:{display:"flex",gap:"16px"},children:[j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:p=>a({...s,showVoltage:p.target.checked})}),"Voltage"]}),j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:p=>a({...s,showCurrent:p.target.checked})}),"Current"]})]}),j.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[j.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),j.jsx("input",{id:"startTime",type:"number",value:l,onChange:p=>u(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),j.jsx("input",{id:"duration",type:"number",value:_,onChange:p=>d(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("button",{onClick:m,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),j.jsxs("div",{style:{marginTop:"24px"},children:[j.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),j.jsx("pre",{style:{backgroundColor:"#fafafa",padding:"16px",borderRadius:"6px",maxHeight:"150px",overflowY:"auto",border:"1px solid #eee",color:"#333",fontSize:"13px",fontFamily:"monospace"},children:t})]})]})})},FHn="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",vj=null,BHn=()=>{if(typeof window>"u")return null;if(vj)return vj;try{const t=new Blob([atob(FHn)],{type:"application/javascript"});return vj=URL.createObjectURL(t),vj}catch(t){return console.error("Failed to create blob URL for worker",t),null}},zHn=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],r=Object.keys(e).filter(a=>a!==n),i=r;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return r.forEach(u=>{l[u]=e[u][c]}),l}),nodes:i}},VHn=t=>{const[e,n]=te.useState([]),[o,r]=te.useState([]),[i,s]=te.useState(!0),[a,c]=te.useState(null);return te.useEffect(()=>{if(!t){s(!1),n([]),r([]),c(null);return}s(!0),c(null),n([]),r([]);const l=BHn();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const u=new Worker(l,{type:"module"});return u.onmessage=_=>{if(_.data.type==="result")try{const{plotData:d,nodes:m}=zHn(_.data.result);n(d),r(m)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else _.data.type==="error"&&c(_.data.error);s(!1)},u.onerror=_=>{c(_.message),s(!1)},u.postMessage({spiceString:t}),()=>{u.terminate()}},[t]),{plotData:e,nodes:o,isLoading:i,error:a}},w2e=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},WHn=(t,e)=>{const o=iOe(t).toSpiceString(),i=o.split(`
|
|
5379
5379
|
`).filter(D=>D.trim()!=="").filter(D=>!D.startsWith("*")&&!D.startsWith(".")&&D.trim()!==""),s=new Set,a=new Set,c=new Set;for(const D of i){const I=D.trim().split(/\s+/);if(I.length<3)continue;const H=I[0],F=H[0].toUpperCase();let B=[];if(["R","C","L","V","I","D"].includes(F))B=I.slice(1,3),F==="V"&&c.add(H);else if(F==="Q"&&I.length>=4)B=I.slice(1,4);else if(F==="M"&&I.length>=5)B=I.slice(1,5);else if(F==="X")B=I.slice(1,-1);else continue;B.forEach(z=>s.add(z)),F==="C"&&B.forEach(z=>a.add(z))}s.delete("0"),a.delete("0");const l=Array.from(a).map(D=>`.ic V(${D})=0`),u=[],_=Array.from(s).map(D=>`V(${D})`);u.push(..._);const d=Array.from(c).map(D=>`I(${D})`);u.push(...d);const m=u.length>0?`.probe ${u.join(" ")}`:"",h=e?.startTime??0,p=e?.duration??20,x=h*.001,f=p*.001,g=x+f,y=f/50,P=`.tran ${w2e(y)} ${w2e(g)} ${w2e(x)} UIC`,v=".end",S=o.split(`
|
|
5380
5380
|
`);let M=-1;for(let D=S.length-1;D>=0;D--)if(S[D].trim().toLowerCase().startsWith(v)){M=D;break}const w=[...l,m,P].filter(Boolean);let A;if(M!==-1){const D=S.slice(0,M),I=S.slice(M);A=[...D,...w,...I]}else A=[...S,...w,v];return A.join(`
|
|
5381
5381
|
`)},$Hn=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},UHn=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},E2e=te.createContext(null),XHn=5,jHn=(t,e)=>!t&&!e?!0:!t||!e?!1:t.minX===e.minX&&t.maxX===e.maxX&&t.minY===e.minY&&t.maxY===e.maxY,GHn=({children:t})=>{if(te.useContext(E2e))return j.jsx(j.Fragment,{children:t});const n=te.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),o=te.useCallback(()=>{for(const _ of n.current.subscribers)_()},[]),r=te.useCallback(()=>{const _=n.current.pointer,d=new Set;if(_)for(const[h,p]of n.current.boundingBoxes){const x=p.bounds;x&&_.x>=x.minX&&_.x<=x.maxX&&_.y>=x.minY&&_.y<=x.maxY&&d.add(h)}const m=n.current.hoveringIds;d.size===m.size&&[...d].every(h=>m.has(h))||(n.current.hoveringIds=d,o())},[o]),i=te.useCallback((_,d)=>{n.current.boundingBoxes.set(_,d),r()},[r]),s=te.useCallback((_,d)=>{const m=n.current.boundingBoxes.get(_);m&&jHn(m.bounds,d.bounds)&&m.onClick===d.onClick||(n.current.boundingBoxes.set(_,d),r())},[r]),a=te.useCallback(_=>{n.current.boundingBoxes.delete(_)&&r()},[r]),c=te.useCallback(_=>(n.current.subscribers.add(_),()=>{n.current.subscribers.delete(_)}),[]),l=te.useCallback(_=>n.current.hoveringIds.has(_),[]);te.useEffect(()=>{const _=p=>{const{clientX:x,clientY:f}=p,g=n.current.pointer;g&&g.x===x&&g.y===f||(n.current.pointer={x,y:f},r())},d=()=>{n.current.pointer!==null&&(n.current.pointer=null,n.current.mouseDownPosition=null,r())},m=p=>{n.current.mouseDownPosition={x:p.clientX,y:p.clientY}},h=p=>{const{clientX:x,clientY:f}=p,g=n.current.mouseDownPosition;if(g&&Math.sqrt(Math.pow(x-g.x,2)+Math.pow(f-g.y,2))>XHn){n.current.mouseDownPosition=null;return}n.current.mouseDownPosition=null;for(const y of n.current.boundingBoxes.values()){const P=y.bounds;P&&x>=P.minX&&x<=P.maxX&&f>=P.minY&&f<=P.maxY&&y.onClick?.(p)}};return window.addEventListener("pointermove",_,{passive:!0}),window.addEventListener("pointerdown",_,{passive:!0}),window.addEventListener("pointerup",_,{passive:!0}),window.addEventListener("pointerleave",d),window.addEventListener("pointercancel",d),window.addEventListener("blur",d),window.addEventListener("mousedown",m,{passive:!0}),window.addEventListener("click",h,{passive:!0}),()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerdown",_),window.removeEventListener("pointerup",_),window.removeEventListener("pointerleave",d),window.removeEventListener("pointercancel",d),window.removeEventListener("blur",d),window.removeEventListener("mousedown",m),window.removeEventListener("click",h)}},[r]);const u=te.useMemo(()=>({registerBoundingBox:i,updateBoundingBox:s,unregisterBoundingBox:a,subscribe:c,isHovering:l}),[i,s,a,c,l]);return j.jsx(E2e.Provider,{value:u,children:t})},Wit=t=>{const e=te.useContext(E2e);if(!e)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const n=te.useId(),o=te.useRef(t);o.current=t;const r=te.useMemo(()=>s=>{o.current.onClick?.(s)},[]);return te.useEffect(()=>(e.registerBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?r:void 0}),()=>{e.unregisterBoundingBox(n)}),[e,r,n]),te.useEffect(()=>{e.updateBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?r:void 0})},[e,r,n,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:te.useSyncExternalStore(e.subscribe,()=>e.isHovering(n),()=>!1)}},YHn=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,qHn=({componentId:t,svgDivRef:e,containerRef:n,onComponentClick:o,onHoverChange:r,showOutline:i,circuitJsonKey:s})=>{const[a,c]=te.useState(null),l=te.useRef(null),u=te.useCallback(()=>{l.current=null;const x=e.current,f=n.current;if(!x||!f){c(S=>S&&null);return}const g=x.querySelector(`[data-schematic-component-id="${t}"]`);if(!g){c(S=>S&&null);return}const y=g.getBoundingClientRect(),P=f.getBoundingClientRect(),v={bounds:{minX:y.left,maxX:y.right,minY:y.top,maxY:y.bottom},rect:{left:y.left-P.left,top:y.top-P.top,width:y.width,height:y.height}};c(S=>YHn(S,v)?S:v)},[t,n,e]),_=te.useCallback(()=>{l.current===null&&(l.current=window.requestAnimationFrame(u))},[u]);te.useEffect(()=>{_()},[_,s]),te.useEffect(()=>{_();const x=e.current,f=n.current;if(!x||!f)return;const g=typeof ResizeObserver<"u"?new ResizeObserver(()=>{_()}):null;g?.observe(f),g?.observe(x);const y=typeof MutationObserver<"u"?new MutationObserver(()=>{_()}):null;return y?.observe(x,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{g?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},[_,e,n]);const d=te.useCallback(x=>{o&&o(t,x)},[t,o]),m=a?.bounds??null,{hovering:h}=Wit({bounds:m,onClick:o?d:void 0});if(te.useEffect(()=>{r&&r(t,h)},[h,t,r]),!a||!h||!i)return null;const p=a.rect;return j.jsx("div",{style:{position:"absolute",left:p.left,top:p.top,width:p.width,height:p.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:Y6.schematicComponentHoverOutline}})},JHn=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,QHn=({portId:t,portLabel:e,svgDivRef:n,containerRef:o,onPortClick:r,onHoverChange:i,showOutline:s,circuitJsonKey:a})=>{const[c,l]=te.useState(null),u=te.useRef(null),_=te.useCallback(()=>{u.current=null;const f=n.current,g=o.current;if(!f||!g){l(w=>w&&null);return}const y=f.querySelector(`[data-schematic-port-id="${t}"]`);if(!y){l(w=>w&&null);return}const P=y.getBoundingClientRect(),v=g.getBoundingClientRect(),S=4,M={bounds:{minX:P.left-S,maxX:P.right+S,minY:P.top-S,maxY:P.bottom+S},rect:{left:P.left-v.left-S,top:P.top-v.top-S,width:P.width+S*2,height:P.height+S*2}};l(w=>JHn(w,M)?w:M)},[t,o,n]),d=te.useCallback(()=>{u.current===null&&(u.current=window.requestAnimationFrame(_))},[_]);te.useEffect(()=>{d()},[d,a]),te.useEffect(()=>{d();const f=n.current,g=o.current;if(!f||!g)return;const y=typeof ResizeObserver<"u"?new ResizeObserver(()=>{d()}):null;y?.observe(g),y?.observe(f);const P=typeof MutationObserver<"u"?new MutationObserver(()=>{d()}):null;return P?.observe(f,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{y?.disconnect(),P?.disconnect(),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),u.current!==null&&(cancelAnimationFrame(u.current),u.current=null)}},[d,n,o]);const m=te.useCallback(f=>{r&&r(t,f)},[t,r]),h=c?.bounds??null,{hovering:p}=Wit({bounds:h,onClick:r?m:void 0});if(te.useEffect(()=>{i&&i(t,p)},[p,t,i]),!c||!s)return null;const x=c.rect;return j.jsxs(j.Fragment,{children:[j.jsx("div",{style:{position:"absolute",left:x.left,top:x.top,width:x.width,height:x.height,border:p?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:p?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:Y6.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),p&&e&&j.jsx("div",{style:{position:"absolute",left:x.left+x.width/2,top:x.top-24,transform:"translateX(-50%)",backgroundColor:"rgba(0, 0, 0, 0.85)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",whiteSpace:"nowrap",pointerEvents:"none",zIndex:Y6.schematicPortHoverOutline+1},children:e})]})},KHn=({circuitJson:t,containerStyle:e,editEvents:n=[],onEditEvent:o,defaultEditMode:r=!1,debugGrid:i=!1,editingEnabled:s=!1,debug:a=!1,clickToInteractEnabled:c=!1,colorOverrides:l,spiceSimulationEnabled:u=!1,disableGroups:_=!1,onSchematicComponentClicked:d,showSchematicPorts:m=!1,onSchematicPortClicked:h})=>{a&&MHn();const[p,x]=te.useState(!1),[f,g]=te.useState({showVoltage:!0,showCurrent:!1,startTime:0,duration:20}),y=ge=>`${ge?.length||0}_${ge?.editCount||0}`,P=te.useMemo(()=>y(t),[t]),v=te.useMemo(()=>{if(!u)return null;try{return WHn(t,f)}catch(ge){return console.error("Failed to generate SPICE string",ge),null}},[P,u,f.startTime,f.duration]),[S,M]=te.useState(!1);te.useEffect(()=>{M(!1)},[P]);const{plotData:w,nodes:A,isLoading:D,error:I}=VHn(S?v:null),[H,F]=te.useState(r),[B,z]=te.useState(!0),[X,Y]=te.useState(!1),J=i||X,[ne,ce]=te.useState(!c),[Z,oe]=te.useState(!1),[se,le]=te.useState(()=>_?!1:$Hn("schematic_viewer_show_groups",!1)),[fe,Se]=te.useState(!1),we=te.useRef(new Set),De=te.useCallback((ge,et)=>{et?we.current.add(ge):we.current.delete(ge),Se(we.current.size>0)},[]),[pe,Me]=te.useState(!1),xe=te.useRef(new Set),Ve=te.useCallback((ge,et)=>{et?xe.current.add(ge):xe.current.delete(ge),Me(xe.current.size>0)},[]),$e=te.useRef(null),qe=te.useRef(null),me=te.useMemo(()=>{try{return Up(t).schematic_component?.list()?.map(ge=>ge.schematic_component_id)??[]}catch(ge){return console.error("Failed to derive schematic component ids",ge),[]}},[P,t]),je=te.useMemo(()=>{if(!m)return[];try{return(Up(t).schematic_port?.list()??[]).map(et=>{const st=Up(t).source_port.get(et.source_port_id),Rt=(st?.source_component_id?Up(t).source_component.get(st.source_component_id):null)?.name??"?",Ft=et.display_pin_label??st?.pin_number??st?.name??"?";return{portId:et.source_port_id,label:`${Rt}.${Ft}`}})}catch(ge){return console.error("Failed to derive schematic port info",ge),[]}},[P,t,m]),Oe=ge=>{const et=ge.touches[0];qe.current={x:et.clientX,y:et.clientY}},ke=ge=>{const et=ge.changedTouches[0],st=qe.current;if(!st)return;const xt=Math.abs(et.clientX-st.x),Rt=Math.abs(et.clientY-st.y);xt<10&&Rt<10&&(ge.preventDefault(),ce(!0)),qe.current=null},[ze,Re]=te.useState([]),ve=te.useRef(t);te.useEffect(()=>{const ge=y(t),et=y(ve.current);ge!==et&&(Re([]),ve.current=t)},[t]);const{ref:Ee,cancelDrag:Te,transform:Fe}=ON({onSetTransform(ge){$e.current&&($e.current.style.transform=J1(ge))},enabled:ne&&!p}),{containerWidth:We,containerHeight:Ke}=zit(Ee),nt=te.useMemo(()=>!We||!Ke?"":GX(t,{width:We,height:Ke||720,grid:J?{cellSize:1,labelCells:!0}:void 0,colorOverrides:l}),[P,We,Ke,J]),it=te.useMemo(()=>nt.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent",[nt]),at=te.useMemo(()=>{if(!nt)return Jc();const ge=nt.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return PO(ge)}catch(et){return console.error(et),Jc()}},[nt]),ft=ge=>{Re(et=>[...et,ge]),o&&o(ge)},St=te.useMemo(()=>[...n,...ze],[n,ze]),{handleMouseDown:It,handleTouchStart:Vt,isDragging:Lt,activeEditEvent:Et}=EHn({onEditEvent:ft,cancelDrag:Te,realToSvgProjection:at,svgToScreenProjection:Fe,circuitJson:t,editEvents:St,enabled:H&&ne&&!p,snapToGrid:B});PHn({svgDivRef:$e,editEvents:St,realToSvgProjection:at,svgToScreenProjection:Fe,activeEditEvent:Et}),bHn({svgDivRef:$e,circuitJson:t,activeEditEvent:Et,editEvents:St}),vHn({svgDivRef:$e,circuitJson:t,circuitJsonKey:P,showGroups:se&&!_});const Wt=te.useRef(Vt);te.useEffect(()=>{Wt.current=Vt},[Vt]);const Sn=te.useMemo(()=>j.jsx("div",{ref:$e,style:{pointerEvents:c?ne?"auto":"none":"auto",transformOrigin:"0 0"},className:d?"schematic-component-clickable":void 0,onTouchStart:ge=>{H&&ne&&!p&&Wt.current(ge)},dangerouslySetInnerHTML:{__html:nt}}),[nt,ne,c,H,p]);return j.jsxs(GHn,{children:[d&&j.jsx("style",{children:".schematic-component-clickable [data-schematic-component-id]:hover { cursor: pointer !important; }"}),h&&j.jsx("style",{children:"[data-schematic-port-id]:hover { cursor: pointer !important; }"}),j.jsxs("div",{ref:Ee,style:{position:"relative",backgroundColor:it,overflow:"hidden",cursor:p?"auto":Lt?"grabbing":c&&!ne||fe&&d||pe&&h?"pointer":"grab",minHeight:"300px",...e},onWheelCapture:ge=>{p&&ge.stopPropagation()},onMouseDown:ge=>{if(c&&!ne){ge.preventDefault(),ge.stopPropagation();return}It(ge)},onMouseDownCapture:ge=>{if(c&&!ne){ge.preventDefault(),ge.stopPropagation();return}},onTouchStart:ge=>{p||Oe(ge)},onTouchEnd:ge=>{p||ke(ge)},children:[!ne&&c&&j.jsx("div",{onClick:ge=>{ge.preventDefault(),ge.stopPropagation(),ce(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:Y6.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"all",touchAction:"pan-x pan-y pinch-zoom"},children:j.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})}),j.jsx(RHn,{active:Z,onClick:()=>oe(!Z)}),s&&j.jsx(DHn,{active:H,onClick:()=>F(!H)}),s&&H&&j.jsx(AHn,{active:B,onClick:()=>z(!B)}),j.jsx(NHn,{circuitJson:t,circuitJsonKey:P,isVisible:Z,onClose:()=>oe(!1),showGroups:se,onToggleGroups:ge=>{_||(le(ge),UHn("schematic_viewer_show_groups",ge))},showGrid:J,onToggleGrid:Y}),u&&j.jsx(IHn,{onClick:()=>x(!0)}),p&&j.jsx(OHn,{spiceString:v,onClose:()=>x(!1),plotData:w,nodes:A,isLoading:D,error:I,simOptions:f,onSimOptionsChange:ge=>{M(!0),g(ge)},hasRun:S}),d&&me.map(ge=>j.jsx(qHn,{componentId:ge,svgDivRef:$e,containerRef:Ee,showOutline:!0,circuitJsonKey:P,onHoverChange:De,onComponentClick:(et,st)=>{d?.({schematicComponentId:et,event:st})}},ge)),Sn,m&&je.map(({portId:ge,label:et})=>j.jsx(QHn,{portId:ge,portLabel:et,svgDivRef:$e,containerRef:Ee,showOutline:!0,circuitJsonKey:P,onHoverChange:Ve,onPortClick:h?(st,xt)=>{h?.({schematicPortId:st,event:xt})}:void 0},ge))]})]})},ZHn=({circuitJson:t,containerStyle:e,colorOverrides:n,width:o,height:r,className:i})=>{const[s,a]=te.useState(null),[c,l]=te.useState(!0),[u,_]=te.useState(null),[d,m]=te.useState(null),h=te.useRef(null),p=te.useRef(null),{containerWidth:x,containerHeight:f}=zit(h),[g,y]=te.useState(!1),{ref:P}=ON({onSetTransform(F){p.current&&(p.current.style.transform=J1(F))}}),v=o||x||1e3,S=r||f||600;te.useEffect(()=>{l(!0),_(null),a(t),l(!1)},[t]);const M=te.useMemo(()=>s&&s.find(B=>B.type==="simulation_experiment")?.simulation_experiment_id||null,[s]),w=te.useMemo(()=>s?s.filter(F=>F.type==="simulation_transient_voltage_graph").map(F=>F.simulation_transient_voltage_graph_id):[],[s]),A=te.useMemo(()=>{if(!s||!v||!S||!M)return"";try{return Not({circuitJson:s,simulation_experiment_id:M,simulation_transient_voltage_graph_ids:w,width:v,height:S,schematicOptions:{colorOverrides:n}})}catch(F){return console.error("Failed to generate fallback schematic SVG:",F),""}},[s,v,S,n,M,w]);te.useEffect(()=>{if(!A){m(null);return}try{const F=new Blob([A],{type:"image/svg+xml"}),B=URL.createObjectURL(F);return m(B),()=>{URL.revokeObjectURL(B)}}catch(F){console.error("Failed to create SVG object URL:",F),m(null)}},[A]);const D=te.useMemo(()=>A?A.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent":"transparent",[A]),I=F=>{y(!0)},H=F=>{y(!0)};return te.useEffect(()=>{const F=()=>{y(!1)},B=()=>{y(!1)};return window.addEventListener("mouseup",F),window.addEventListener("touchend",B),()=>{window.removeEventListener("mouseup",F),window.removeEventListener("touchend",B)}},[]),c?j.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f5f5f5",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#666",...e},className:i,children:"Loading circuit..."}):u?j.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#fef2f2",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#dc2626",...e},className:i,children:j.jsxs("div",{style:{textAlign:"center",padding:"20px"},children:[j.jsx("div",{style:{fontWeight:"bold",marginBottom:"8px"},children:"Circuit Conversion Error"}),j.jsx("div",{style:{fontSize:"14px"},children:u})]})}):A?j.jsx("div",{ref:F=>{h.current=F,P.current=F},style:{position:"relative",backgroundColor:D,overflow:"hidden",minHeight:"300px",cursor:g?"grabbing":"grab",...e},className:i,onMouseDown:I,onTouchStart:H,children:d?j.jsx("img",{ref:p,src:d,alt:"Circuit Simulation",style:{transformOrigin:"0 0",width:"100%",height:"100%",display:"block",objectFit:"contain"}}):j.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",minHeight:"300px",color:"#666",fontFamily:"sans-serif"},children:"Failed to render SVG"})}):j.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"#f8fafc",minHeight:"300px",fontFamily:"sans-serif",gap:"12px",...e},className:i,children:[j.jsx("div",{style:{fontSize:"16px",color:"#475569",fontWeight:500},children:"No Simulation Found"}),j.jsxs("div",{style:{fontSize:"14px",color:"#64748b"},children:["Use"," ",j.jsx("code",{style:{backgroundColor:"#e2e8f0",padding:"2px 6px",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px"},children:"<analogsimulation />"})," ","to create simulations"]})]})},$it=t=>{const[e,n]=te.useState(0),[o,r]=te.useState(0);return te.useEffect(()=>{if(!t.current)return;const i=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),r(a?.height||0)};i();const s=new ResizeObserver(i);return s.observe(t.current),window.addEventListener("resize",i),()=>{s.disconnect(),window.removeEventListener("resize",i)}},[]),{containerWidth:e,containerHeight:o}};zl("assembly-viewer");var Uit=()=>{zl.enable("assembly-viewer*")},eIn=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&Uit();const r=te.useRef(null),{ref:i}=ON({onSetTransform(u){r.current&&(r.current.style.transform=J1(u))}}),{containerWidth:s,containerHeight:a}=$it(i),c=te.useMemo(()=>!s||!a?"":cot(t,{width:s,height:a||720}),[t,s,a]);te.useMemo(()=>{if(!c)return Jc();const u=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return PO(u)}catch(_){return console.error(_),Jc()}},[c]);const l=te.useMemo(()=>j.jsx("div",{ref:r,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return j.jsx("div",{ref:i,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})},tIn=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&Uit();const r=te.useRef(null),{ref:i}=ON({onSetTransform(u){r.current&&(r.current.style.transform=J1(u))}}),{containerWidth:s,containerHeight:a}=$it(i),c=te.useMemo(()=>!s||!a?"":xot(t,{width:s,height:a||720}),[t,s,a]);te.useMemo(()=>{if(!c)return Jc();const u=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return PO(u)}catch(_){return console.error(_),Jc()}},[c]);const l=te.useMemo(()=>j.jsx("div",{ref:r,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return j.jsx("div",{ref:i,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})};const Xit=["Initialize a tscircuit project using [tsci init](https://github.com/tscircuit/cli) before adding components.","Define reusable modules with cached routes using [<subcircuit />](https://docs.tscircuit.com/elements/subcircuit)","Run `tsci dev` on the command line to preview your boards before export",'Use units like mm or mils consistently across your designs (e.g. pcbX="10mm")',"Quickly set footprints with the [footprint prop](https://docs.tscircuit.com/footprints/footprinter-strings)","Check out the guide on [ordering prototypes](https://docs.tscircuit.com/building-electronics/ordering-prototypes)","Use [net labels](https://docs.tscircuit.com/elements/net) and [group elements](https://docs.tscircuit.com/elements/group) to organize complex schematics.","You can manually drag components on the PCB and Schematic using [manual edits](https://docs.tscircuit.com/guides/manual-edits)","Every tscircuit module can export to [Circuit JSON](https://github.com/tscircuit/circuit-json), Gerbers, Pick'n'Place CSV files, Bill of Materials CSV and more","You can import components from [JLCPCB](https://docs.tscircuit.com/guides/importing-modules-and-chips/importing-from-jlcpcb) or [KiCad](https://docs.tscircuit.com/guides/importing-modules-and-chips/importing-from-kicad)","Any module you push to the [registry](https://tscircuit.com/trending) will have [simple image urls](https://docs.tscircuit.com/web-apis/image-generation-api) you can use display images on a website","The default [Parts Engine](https://docs.tscircuit.com/guides/platform-configuration) will automatically find parts from common vendors for your BOM",'[Pin selectors](https://docs.tscircuit.com/guides/using-sel-references) are similar to CSS selectors, ".R1 > .pin1" means "connect to the first pin of the component R1"',"You can use the [sel](https://docs.tscircuit.com/guides/using-sel-references) object to select pins in a type-safe way","Publish modules via the [registry](https://tscircuit.com/trending) for working with a team or sharing your work","[Explore tutorials](https://docs.tscircuit.com/category/tutorials) for real-world circuit design examples.","Upload your Circuit JSON to [circuitjson.com](https://circuitjson.com) for a quick preview.","You can display Circuit JSON in 3D, PCB or Schematic mode with the [<CircuitJsonPreview />](https://docs.tscircuit.com/guides/running-tscircuit/displaying-circuit-json-on-a-webpage#react-display-all-available-previews-with-circuitjsonpreview-) React component","Use a [<group />](https://docs.tscircuit.com/elements/group) element to move multiple components at once in a schematic or PCB layout.","Check out the [GitHub Discussions page](https://github.com/tscircuit/tscircuit/discussions) to upvote features","You can customize the autorouter using the [autorouter prop](https://docs.tscircuit.com/elements/board#setting-the-autorouter)","Use the [<constraint />](https://docs.tscircuit.com/footprints/constraint) element to enforce geometric relationships in PCB designs.","When working on component placement and circuit design, autorouting can slow down your iteration cycle. Use [routingDisabled](https://docs.tscircuit.com/elements/board#disabling-routing-with-routingdisabled) on the <board /> element to disable autorouting temporarily.","Join the [Discord server](https://tscircuit.com/join) to discuss issues and get help directly from the community."],nIn=(()=>{let t=Xit[Math.floor(Math.random()*Xit.length)];return t=t.replace(/</g,"<"),t=t.replace(/>/g,">"),t=t.replace(new RegExp('(?<!href=")(?<!\\()(?<!\\]\\()(https?:\\/\\/[^\\s\\)\\]]+)',"g"),(e,n)=>`<a class="rf-text-blue-500 rf-underline" href="${e}" target="_blank">${e}</a>`),t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/g,'<a class="rf-text-blue-500 rf-underline" href="$2" target="_blank">$1</a>'),t})(),A9=({onRunClicked:t})=>j.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-justify-center rf-h-full rf-bg-gray-50 rf-text-gray-500 rf-p-4",children:[j.jsx(U8n,{className:"rf-size-14 rf-mb-4"}),j.jsxs("p",{className:"rf-text-md rf-break-words rf-max-w-xl rf-text-center",children:["Tip: ",j.jsx("span",{dangerouslySetInnerHTML:{__html:nIn}})]}),t&&j.jsxs(y0,{className:"rf-mt-4 rf-bg-blue-600 rf-hover:bg-blue-500",onClick:t,children:["Run Code",j.jsx(Y8n,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),Sj=({text:t,onClick:e})=>j.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:e,children:t}),Cj=t=>j.jsxs("div",{className:"rf-leading-5",children:[j.jsx("div",{className:"rf-py-2 rf-font-bold",children:t.column.name}),j.jsx("div",{children:t.field?.()??j.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:e=>{t.onTextChange?.(e.target.value)}})})]}),oIn=({open:t,children:e,title:n,onClose:o})=>t?j.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-justify-center rf-items-center rf-z-50",onClick:o,children:j.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:r=>{r.preventDefault(),r.stopPropagation()},children:[j.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:n}),j.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:o,children:"×"}),e]})}):null,rIn=({elements:t})=>{const[e,n]=te.useState({open:!1}),[o,r]=te.useReducer((u,_)=>({...u,..._}),{}),i=[...new Set(t.map(u=>u.type))],s=t.map(u=>{const _=u[`${u.type}_id`],d=Object.fromEntries(Object.entries(u).filter(([h])=>!(h===`${u.type}_id`||!h.endsWith("_id")))),m=Object.fromEntries(Object.entries(u).filter(([h])=>!h.endsWith("_id")));return{primary_id:_,other_ids:d,...m,_og_elm:u}}),a=s.map(u=>{let _="";const d=m=>{const h=Object.keys(m.other_ids).find(f=>f.startsWith("source_"));if(!h)return`.${m.name}`;const p=h.slice(0,-3),x=s.find(f=>f.type===p&&f.primary_id===m.other_ids[h]);return x?"name"in x?`${d(x)} > .${m.name}`:`#${x.primary_id} > .${m.name}`:`??? > .${m.name}`};return"name"in u&&(_=d(u)),{...u,selector_path:_}}),c=[{key:"primary_id",name:"primary_id",renderCell:u=>j.jsxs("div",{className:"rf-flex rf-items-center",children:[j.jsx(Sj,{text:u.primary_id,onClick:()=>r({focused_id:u.primary_id,id_search:void 0,selector_search:void 0})}),j.jsx("span",{className:"rf-flex-grow"}),j.jsx(Sj,{text:"(JSON)",onClick:()=>n({open:!0,element:u._og_elm,title:u.primary_id})})]}),renderHeaderCell:u=>j.jsx(Cj,{column:u,onTextChange:_=>r({id_search:_}),field:o.focused_id?()=>j.jsxs("div",{children:["Focus:"," ",j.jsx("span",{className:"rf-underline",children:o.focused_id}),j.jsx(Sj,{text:"(unfocus)",onClick:()=>r({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:u=>j.jsx(Cj,{column:u,field:()=>j.jsxs("select",{onChange:_=>r({component_type_filter:_.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[j.jsx("option",{value:"any",children:"any"},"any"),j.jsx("option",{value:"source",children:"source"},"source"),j.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),j.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),i.map(_=>j.jsx("option",{value:_,children:_},_))]})})},{key:"name",name:"name",renderHeaderCell:u=>j.jsx(Cj,{column:u,onTextChange:_=>r({name_search:_})})},{key:"selector_path",name:"selector_path",renderHeaderCell:u=>j.jsx(Cj,{column:u,onTextChange:_=>r({selector_search:_})})},{key:"other_ids",name:"other_ids",renderCell:u=>j.jsx("div",{className:"rf-space-x-2",children:Object.entries(u.other_ids).map(([_,d])=>j.jsx(Sj,{text:d,onClick:()=>r({focused_id:d})},d))})}],l=a.filter(u=>o.name_search?u.name?.toLowerCase()?.includes(o.name_search.toLowerCase()):!0).filter(u=>!o.component_type_filter||o.component_type_filter==="any"?!0:o.component_type_filter==="source"?u.type.startsWith("source_"):o.component_type_filter==="source/pcb"?u.type.startsWith("source_")||u.type.startsWith("pcb_"):o.component_type_filter==="source/schematic"?u.type.startsWith("source_")||u.type.startsWith("schematic_"):u.type?.includes(o.component_type_filter)).filter(u=>o.selector_search?o.selector_search.split(" ").filter(d=>d.length>0).every(d=>u.selector_path?.includes(d)):!0).filter(u=>o.id_search?u.primary_id?.includes(o.id_search):!0).filter(u=>!!(!o.focused_id||u.primary_id===o.focused_id||Object.values(u.other_ids).includes(o.focused_id)));return j.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[j.jsx("div",{className:"rf-overflow-x-auto",children:j.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[j.jsx("thead",{children:j.jsx("tr",{children:c.map(u=>j.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:u.renderHeaderCell?u.renderHeaderCell(u):u.name},u.key))})}),j.jsx("tbody",{children:l.map((u,_)=>j.jsx("tr",{className:"rf-hover:bg-gray-100",children:c.map(d=>j.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:d.renderCell?d.renderCell(u):u[d.key]},d.key))},_))})]})}),j.jsx(oIn,{open:e.open,onClose:()=>n({open:!1}),title:e.open?e.title:"",children:j.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:j.jsx("pre",{className:"rf-whitespace-pre-wrap",children:e.open?JSON.stringify(e.element,null,2):""})})})]})};var iH={},D2e={},jit;function iIn(){return jit||(jit=1,(function(t){Object.defineProperty(t,"__esModule",{value:!0});var e=(function(){function i(s,a){var c=[],l=!0,u=!1,_=void 0;try{for(var d=s[Symbol.iterator](),m;!(l=(m=d.next()).done)&&(c.push(m.value),!(a&&c.length===a));l=!0);}catch(h){u=!0,_=h}finally{try{!l&&d.return&&d.return()}finally{if(u)throw _}}return c}return function(s,a){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return i(s,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();t.default=o,t.parseUnitObj=r;var n=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function o(i){var s=parseFloat(i),a=i.match(n)||[],c=a.length>0?i.substr(a[0].length).trim():"";return[s,c]}function r(i){var s=o(i),a=e(s,2),c=a[0],l=a[1];return{val:c,unit:l}}})(D2e)),D2e}var Git;function sIn(){if(Git)return iH;Git=1,Object.defineProperty(iH,"__esModule",{value:!0});var t=(function(){function c(l,u){var _=[],d=!0,m=!1,h=void 0;try{for(var p=l[Symbol.iterator](),x;!(d=(x=p.next()).done)&&(_.push(x.value),!(u&&_.length===u));d=!0);}catch(f){m=!0,h=f}finally{try{!d&&p.return&&p.return()}finally{if(m)throw h}}return _}return function(l,u){if(Array.isArray(l))return l;if(Symbol.iterator in Object(l))return c(l,u);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();iH.formatSI=i,iH.unformatSI=a;function e(c){return c&&c.__esModule?c:{default:c}}var n=iIn(),o=e(n),r={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function i(c){if(c===0)return"0";for(var l=Math.abs(c),u=0;l>=1e3&&u<24;)l/=1e3,u+=3;for(;l<1&&u>-24;)l*=1e3,u-=3;var _=c<0?"-":"";return l>1e3?_+l.toFixed(0)+r[u]:_+parseFloat(l.toPrecision(3))+r[u]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function a(c){if(c==null||c==="")return NaN;var l=(0,o.default)(c),u=t(l,2),_=u[0],d=u[1],m=s[d];return _*m}return iH}var aIn=sIn(),Mj={exports:{}};var cIn=Mj.exports,Yit;function lIn(){return Yit||(Yit=1,(function(t,e){((n,o)=>{t.exports=o()})(cIn,function n(){var o=typeof self<"u"?self:typeof window<"u"?window:o!==void 0?o:{},r,i=!o.document&&!!o.postMessage,s=o.IS_PAPA_WORKER||!1,a={},c=0,l={};function u(w){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(A){var D=v(A);D.chunkSize=parseInt(D.chunkSize),A.step||A.chunk||(D.chunkSize=null),this._handle=new p(D),(this._handle.streamer=this)._config=D}).call(this,w),this.parseChunk=function(A,D){var I=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<I){let F=this._config.newline;F||(H=this._config.quoteChar||'"',F=this._handle.guessLineEndings(A,H)),A=[...A.split(F).slice(I)].join(F)}this.isFirstChunk&&M(this._config.beforeFirstChunk)&&(H=this._config.beforeFirstChunk(A))!==void 0&&(A=H),this.isFirstChunk=!1,this._halted=!1;var I=this._partialLine+A,H=(this._partialLine="",this._handle.parse(I,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(A=H.meta.cursor,I=(this._finished||(this._partialLine=I.substring(A-this._baseIndex),this._baseIndex=A),H&&H.data&&(this._rowCount+=H.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)o.postMessage({results:H,workerId:l.WORKER_ID,finished:I});else if(M(this._config.chunk)&&!D){if(this._config.chunk(H,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=H=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(H.data),this._completeResults.errors=this._completeResults.errors.concat(H.errors),this._completeResults.meta=H.meta),this._completed||!I||!M(this._config.complete)||H&&H.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),I||H&&H.meta.paused||this._nextChunk(),H}this._halted=!0},this._sendError=function(A){M(this._config.error)?this._config.error(A):s&&this._config.error&&o.postMessage({workerId:l.WORKER_ID,error:A,finished:!1})}}function _(w){var A;(w=w||{}).chunkSize||(w.chunkSize=l.RemoteChunkSize),u.call(this,w),this._nextChunk=i?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(D){this._input=D,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(A=new XMLHttpRequest,this._config.withCredentials&&(A.withCredentials=this._config.withCredentials),i||(A.onload=S(this._chunkLoaded,this),A.onerror=S(this._chunkError,this)),A.open(this._config.downloadRequestBody?"POST":"GET",this._input,!i),this._config.downloadRequestHeaders){var D,I=this._config.downloadRequestHeaders;for(D in I)A.setRequestHeader(D,I[D])}var H;this._config.chunkSize&&(H=this._start+this._config.chunkSize-1,A.setRequestHeader("Range","bytes="+this._start+"-"+H));try{A.send(this._config.downloadRequestBody)}catch(F){this._chunkError(F.message)}i&&A.status===0&&this._chunkError()}},this._chunkLoaded=function(){A.readyState===4&&(A.status<200||400<=A.status?this._chunkError():(this._start+=this._config.chunkSize||A.responseText.length,this._finished=!this._config.chunkSize||this._start>=(D=>(D=D.getResponseHeader("Content-Range"))!==null?parseInt(D.substring(D.lastIndexOf("/")+1)):-1)(A),this.parseChunk(A.responseText)))},this._chunkError=function(D){D=A.statusText||D,this._sendError(new Error(D))}}function d(w){(w=w||{}).chunkSize||(w.chunkSize=l.LocalChunkSize),u.call(this,w);var A,D,I=typeof FileReader<"u";this.stream=function(H){this._input=H,D=H.slice||H.webkitSlice||H.mozSlice,I?((A=new FileReader).onload=S(this._chunkLoaded,this),A.onerror=S(this._chunkError,this)):A=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var H=this._input,F=(this._config.chunkSize&&(F=Math.min(this._start+this._config.chunkSize,this._input.size),H=D.call(H,this._start,F)),A.readAsText(H,this._config.encoding));I||this._chunkLoaded({target:{result:F}})},this._chunkLoaded=function(H){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(H.target.result)},this._chunkError=function(){this._sendError(A.error)}}function m(w){var A;u.call(this,w=w||{}),this.stream=function(D){return A=D,this._nextChunk()},this._nextChunk=function(){var D,I;if(!this._finished)return D=this._config.chunkSize,A=D?(I=A.substring(0,D),A.substring(D)):(I=A,""),this._finished=!A,this.parseChunk(I)}}function h(w){u.call(this,w=w||{});var A=[],D=!0,I=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(H){this._input=H,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){I&&A.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),A.length?this.parseChunk(A.shift()):D=!0},this._streamData=S(function(H){try{A.push(typeof H=="string"?H:H.toString(this._config.encoding)),D&&(D=!1,this._checkIsFinished(),this.parseChunk(A.shift()))}catch(F){this._streamError(F)}},this),this._streamError=S(function(H){this._streamCleanUp(),this._sendError(H)},this),this._streamEnd=S(function(){this._streamCleanUp(),I=!0,this._streamData("")},this),this._streamCleanUp=S(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function p(w){var A,D,I,H,F=Math.pow(2,53),B=-F,z=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,X=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,Y=this,J=0,ne=0,ce=!1,Z=!1,oe=[],se={data:[],errors:[],meta:{}};function le(De){return w.skipEmptyLines==="greedy"?De.join("").trim()==="":De.length===1&&De[0].length===0}function fe(){if(se&&I&&(we("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+l.DefaultDelimiter+"'"),I=!1),w.skipEmptyLines&&(se.data=se.data.filter(function(xe){return!le(xe)})),Se()){let xe=function(Ve,$e){M(w.transformHeader)&&(Ve=w.transformHeader(Ve,$e)),oe.push(Ve)};if(se)if(Array.isArray(se.data[0])){for(var De=0;Se()&&De<se.data.length;De++)se.data[De].forEach(xe);se.data.splice(0,1)}else se.data.forEach(xe)}function pe(xe,Ve){for(var $e=w.header?{}:[],qe=0;qe<xe.length;qe++){var me=qe,je=xe[qe],je=((Oe,ke)=>(ze=>(w.dynamicTypingFunction&&w.dynamicTyping[ze]===void 0&&(w.dynamicTyping[ze]=w.dynamicTypingFunction(ze)),(w.dynamicTyping[ze]||w.dynamicTyping)===!0))(Oe)?ke==="true"||ke==="TRUE"||ke!=="false"&&ke!=="FALSE"&&((ze=>{if(z.test(ze)&&(ze=parseFloat(ze),B<ze&&ze<F))return 1})(ke)?parseFloat(ke):X.test(ke)?new Date(ke):ke===""?null:ke):ke)(me=w.header?qe>=oe.length?"__parsed_extra":oe[qe]:me,je=w.transform?w.transform(je,me):je);me==="__parsed_extra"?($e[me]=$e[me]||[],$e[me].push(je)):$e[me]=je}return w.header&&(qe>oe.length?we("FieldMismatch","TooManyFields","Too many fields: expected "+oe.length+" fields but parsed "+qe,ne+Ve):qe<oe.length&&we("FieldMismatch","TooFewFields","Too few fields: expected "+oe.length+" fields but parsed "+qe,ne+Ve)),$e}var Me;se&&(w.header||w.dynamicTyping||w.transform)&&(Me=1,!se.data.length||Array.isArray(se.data[0])?(se.data=se.data.map(pe),Me=se.data.length):se.data=pe(se.data,0),w.header&&se.meta&&(se.meta.fields=oe),ne+=Me)}function Se(){return w.header&&oe.length===0}function we(De,pe,Me,xe){De={type:De,code:pe,message:Me},xe!==void 0&&(De.row=xe),se.errors.push(De)}M(w.step)&&(H=w.step,w.step=function(De){se=De,Se()?fe():(fe(),se.data.length!==0&&(J+=De.data.length,w.preview&&J>w.preview?D.abort():(se.data=se.data[0],H(se,Y))))}),this.parse=function(De,pe,Me){var xe=w.quoteChar||'"',xe=(w.newline||(w.newline=this.guessLineEndings(De,xe)),I=!1,w.delimiter?M(w.delimiter)&&(w.delimiter=w.delimiter(De),se.meta.delimiter=w.delimiter):((xe=((Ve,$e,qe,me,je)=>{var Oe,ke,ze,Re;je=je||[","," ","|",";",l.RECORD_SEP,l.UNIT_SEP];for(var ve=0;ve<je.length;ve++){for(var Ee,Te=je[ve],Fe=0,We=0,Ke=0,nt=(ze=void 0,new f({comments:me,delimiter:Te,newline:$e,preview:10}).parse(Ve)),it=0;it<nt.data.length;it++)qe&&le(nt.data[it])?Ke++:(Ee=nt.data[it].length,We+=Ee,ze===void 0?ze=Ee:0<Ee&&(Fe+=Math.abs(Ee-ze),ze=Ee));0<nt.data.length&&(We/=nt.data.length-Ke),(ke===void 0||Fe<=ke)&&(Re===void 0||Re<We)&&1.99<We&&(ke=Fe,Oe=Te,Re=We)}return{successful:!!(w.delimiter=Oe),bestDelimiter:Oe}})(De,w.newline,w.skipEmptyLines,w.comments,w.delimitersToGuess)).successful?w.delimiter=xe.bestDelimiter:(I=!0,w.delimiter=l.DefaultDelimiter),se.meta.delimiter=w.delimiter),v(w));return w.preview&&w.header&&xe.preview++,A=De,D=new f(xe),se=D.parse(A,pe,Me),fe(),ce?{meta:{paused:!0}}:se||{meta:{paused:!1}}},this.paused=function(){return ce},this.pause=function(){ce=!0,D.abort(),A=M(w.chunk)?"":A.substring(D.getCharIndex())},this.resume=function(){Y.streamer._halted?(ce=!1,Y.streamer.parseChunk(A,!0)):setTimeout(Y.resume,3)},this.aborted=function(){return Z},this.abort=function(){Z=!0,D.abort(),se.meta.aborted=!0,M(w.complete)&&w.complete(se),A=""},this.guessLineEndings=function(Ve,xe){Ve=Ve.substring(0,1048576);var xe=new RegExp(x(xe)+"([^]*?)"+x(xe),"gm"),Me=(Ve=Ve.replace(xe,"")).split("\r"),xe=Ve.split(`
|
|
@@ -5691,7 +5691,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5691
5691
|
// Add more specific assertions based on expected output
|
|
5692
5692
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5693
5693
|
})
|
|
5694
|
-
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:r,children:[j.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&&j.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:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},fct=t=>t.activeSubSolver?[t,...fct(t.activeSubSolver)]:[t],t$n=({solver:t})=>{const e=fct(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(e$n,{solver:n})]},n.constructor.name))})},n$n=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=te.useReducer(p=>!p,!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(),r&&r(t))},u=()=>{i?(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(),r&&t.solved&&r(t);return}t.step(),e()},n))},_=()=>{const p=t;if(p.getCurrentPhase&&!t.solved&&!t.failed){const x=p.getCurrentPhase();for(;p.getCurrentPhase()===x&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||i)return;const p=window.prompt("Step until which iteration?",`${t.iterations}`);if(p===null)return;const x=Number(p);if(!Number.isFinite(x)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<x&&!t.solved&&!t.failed;)t.step();e(),t.solved&&r&&r(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&i&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,i]);const m=t.getCurrentPhase!==void 0,h=m?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(t$n,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:c,disabled:t.solved||t.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),j.jsx("button",{onClick:d,disabled:t.solved||t.failed||i,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"}),m&&j.jsx("button",{onClick:_,disabled:t.solved||t.failed||i,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:h})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},o$n=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},r$n=(t,e)=>{const o=t.pipelineDef[e].solverName,r=o$n(t,e),i=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(r==="Completed"){const d=t.pipelineDef[e+1],m=d?t.firstIterationOfPhase?.[d.solverName]:void 0;m!==void 0&&s!==null?c=m-s:s!==null&&(c=a-s)}else r==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let u=0;r==="Completed"?u=1:r==="In Progress"&&i&&(u=i.progress??0);const _=i?.stats??null;return{index:e,name:o,status:r,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:_&&Object.keys(_).length>0?_:null,solverInstance:i??null}},i$n=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},s$n=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},a$n=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),c$n=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=a$n(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>j.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Txe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Txe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Txe(o));return e},l$n=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Txe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=`${e}_input.json`,i.click(),URL.revokeObjectURL(r)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},u$n=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>r$n(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):l$n(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>r(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:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(i$n,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(s$n,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(c$n,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>i(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},_$n=class extends or.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 d$n({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],r=t.circles??[],i=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(x,f)=>{typeof x=="number"&&(x<s&&(s=x),x>c&&(c=x)),typeof f=="number"&&(f<a&&(a=f),f>l&&(l=f))};for(const x of e)u(x.x,x.y);for(const x of n){const f=x.points??[];for(const g of f)u(g.x,g.y)}for(const x of o){const f=x.x??0,g=x.y??0,y=x.width??0,P=x.height??0;u(f,g),u(f+y,g+P)}for(const x of r){const f=x.x??0,g=x.y??0,y=x.radius??1;u(f-y,g-y),u(f+y,g+y)}for(const x of i)u(x.x,x.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const _=10,d=s-_,m=a-_,h=Math.max(1,c-s+2*_),p=Math.max(1,l-a+2*_);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${m} ${h} ${p}`,role:"img","aria-label":"Graphics fallback",children:[o.map((x,f)=>j.jsx("rect",{x:x.x??0,y:x.y??0,width:x.width??0,height:x.height??0,fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`rect-${f}`)),n.map((x,f)=>j.jsx("polyline",{fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1,points:(x.points??[]).map(g=>`${g.x??0},${g.y??0}`).join(" ")},`line-${f}`)),r.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.fillColor??"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`circle-${f}`)),e.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.color??"black"},`point-${f}`)),i.map((x,f)=>j.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var h$n=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),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 u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const _=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&_.currentPipelineStepIndex<=_.pipelineDef.findIndex(d=>d.solverName===u);)t.step();i()}};return j.jsxs("div",{children:[j.jsx(n$n,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(_$n,{fallback:j.jsx(d$n,{graphics:s}),children:j.jsx(ZWn,{graphics:s})}),c&&j.jsx(u$n,{solver:t,onStepUntilPhase:l})]})};const m$n=()=>{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)},[])},p$n=t=>t.toLowerCase().includes("pack")?$8n:t.toLowerCase().includes("rout")?q8n:H8n,f$n=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);m$n();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]),r=te.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=te.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=yae[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=i.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}}},[i]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.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."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.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:[r.length," ",r.length===1?"Solver":"Solvers"]}),r.map(a=>{const c=o.get(a),l=e===a;return j.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 u=p$n(c.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?j.jsx(F6,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:j.jsx(h$n,{solver:s.instance})}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&j.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:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(i.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},xct=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{nL.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const r=new Error(o.message||"Circuit JSON Error");o.stack&&(r.stack=o.stack);try{nL.captureException(r,{error_type:o.type})}catch{}}},[n])},gct="0.0.1903",x$n={version:gct},wxe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Exe=new Map,cG=t=>{const e=Exe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},g$n=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Exe.get(n.name);if(o)return{type:"tracked",store:t,...o};const r={connection:e.connect(n),stores:{}};return Exe.set(n.name,r),{type:"tracked",store:t,...r}},yct=(t,e={})=>(n,o,r)=>{const{enabled:i,anonymousActionType:s,store:a,...c}=e;let l;try{l=(i??(wxe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(wxe?"production":void 0)!=="production"&&i&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,r);const{connection:u,..._}=g$n(a,l,c);let d=!0;r.setState=(p,x,f)=>{const g=n(p,x);if(!d)return g;const y=f===void 0?{type:s||"anonymous"}:typeof f=="string"?{type:f}:f;return a===void 0?(u?.send(y,o()),g):(u?.send({...y,type:`${a}/${y.type}`},{...cG(c.name),[a]:r.getState()}),g)};const m=(...p)=>{const x=d;d=!1,n(...p),d=x},h=t(r.setState,o,r);if(_.type==="untracked"?u?.init(h):(_.stores[_.store]=r,u?.init(Object.fromEntries(Object.entries(_.stores).map(([p,x])=>[p,p===_.store?h:x.getState()])))),r.dispatchFromDevtools&&typeof r.dispatch=="function"){let p=!1;const x=r.dispatch;r.dispatch=(...f)=>{(wxe?"production":void 0)!=="production"&&f[0].type==="__setState"&&!p&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),p=!0),x(...f)}}return u.subscribe(p=>{var x;switch(p.type){case"ACTION":if(typeof p.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Dxe(p.payload,f=>{if(f.type==="__setState"){if(a===void 0){m(f.state);return}Object.keys(f.state).length!==1&&console.error(`
|
|
5694
|
+
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:r,children:[j.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&&j.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:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},fct=t=>t.activeSubSolver?[t,...fct(t.activeSubSolver)]:[t],t$n=({solver:t})=>{const e=fct(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(e$n,{solver:n})]},n.constructor.name))})},n$n=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=te.useReducer(p=>!p,!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(),r&&r(t))},u=()=>{i?(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(),r&&t.solved&&r(t);return}t.step(),e()},n))},_=()=>{const p=t;if(p.getCurrentPhase&&!t.solved&&!t.failed){const x=p.getCurrentPhase();for(;p.getCurrentPhase()===x&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||i)return;const p=window.prompt("Step until which iteration?",`${t.iterations}`);if(p===null)return;const x=Number(p);if(!Number.isFinite(x)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<x&&!t.solved&&!t.failed;)t.step();e(),t.solved&&r&&r(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&i&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,i]);const m=t.getCurrentPhase!==void 0,h=m?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(t$n,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:c,disabled:t.solved||t.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),j.jsx("button",{onClick:d,disabled:t.solved||t.failed||i,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"}),m&&j.jsx("button",{onClick:_,disabled:t.solved||t.failed||i,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:h})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},o$n=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},r$n=(t,e)=>{const o=t.pipelineDef[e].solverName,r=o$n(t,e),i=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(r==="Completed"){const d=t.pipelineDef[e+1],m=d?t.firstIterationOfPhase?.[d.solverName]:void 0;m!==void 0&&s!==null?c=m-s:s!==null&&(c=a-s)}else r==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let u=0;r==="Completed"?u=1:r==="In Progress"&&i&&(u=i.progress??0);const _=i?.stats??null;return{index:e,name:o,status:r,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:_&&Object.keys(_).length>0?_:null,solverInstance:i??null}},i$n=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},s$n=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},a$n=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),c$n=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=a$n(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>j.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Txe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Txe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Txe(o));return e},l$n=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Txe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=`${e}_input.json`,i.click(),URL.revokeObjectURL(r)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},u$n=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>r$n(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):l$n(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>r(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:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(i$n,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(s$n,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(c$n,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>i(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},_$n=class extends or.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 d$n({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],r=t.circles??[],i=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(x,f)=>{typeof x=="number"&&(x<s&&(s=x),x>c&&(c=x)),typeof f=="number"&&(f<a&&(a=f),f>l&&(l=f))};for(const x of e)u(x.x,x.y);for(const x of n){const f=x.points??[];for(const g of f)u(g.x,g.y)}for(const x of o){const f=x.x??0,g=x.y??0,y=x.width??0,P=x.height??0;u(f,g),u(f+y,g+P)}for(const x of r){const f=x.x??0,g=x.y??0,y=x.radius??1;u(f-y,g-y),u(f+y,g+y)}for(const x of i)u(x.x,x.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const _=10,d=s-_,m=a-_,h=Math.max(1,c-s+2*_),p=Math.max(1,l-a+2*_);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${m} ${h} ${p}`,role:"img","aria-label":"Graphics fallback",children:[o.map((x,f)=>j.jsx("rect",{x:x.x??0,y:x.y??0,width:x.width??0,height:x.height??0,fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`rect-${f}`)),n.map((x,f)=>j.jsx("polyline",{fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1,points:(x.points??[]).map(g=>`${g.x??0},${g.y??0}`).join(" ")},`line-${f}`)),r.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.fillColor??"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`circle-${f}`)),e.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.color??"black"},`point-${f}`)),i.map((x,f)=>j.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var h$n=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),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 u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const _=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&_.currentPipelineStepIndex<=_.pipelineDef.findIndex(d=>d.solverName===u);)t.step();i()}};return j.jsxs("div",{children:[j.jsx(n$n,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(_$n,{fallback:j.jsx(d$n,{graphics:s}),children:j.jsx(ZWn,{graphics:s})}),c&&j.jsx(u$n,{solver:t,onStepUntilPhase:l})]})};const m$n=()=>{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)},[])},p$n=t=>t.toLowerCase().includes("pack")?$8n:t.toLowerCase().includes("rout")?q8n:H8n,f$n=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);m$n();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]),r=te.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=te.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=yae[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=i.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}}},[i]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.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."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.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:[r.length," ",r.length===1?"Solver":"Solvers"]}),r.map(a=>{const c=o.get(a),l=e===a;return j.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 u=p$n(c.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?j.jsx(F6,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:j.jsx(h$n,{solver:s.instance})}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&j.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:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(i.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},xct=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{nL.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const r=new Error(o.message||"Circuit JSON Error");o.stack&&(r.stack=o.stack);try{nL.captureException(r,{error_type:o.type})}catch{}}},[n])},gct="0.0.1904",x$n={version:gct},wxe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Exe=new Map,cG=t=>{const e=Exe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},g$n=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Exe.get(n.name);if(o)return{type:"tracked",store:t,...o};const r={connection:e.connect(n),stores:{}};return Exe.set(n.name,r),{type:"tracked",store:t,...r}},yct=(t,e={})=>(n,o,r)=>{const{enabled:i,anonymousActionType:s,store:a,...c}=e;let l;try{l=(i??(wxe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(wxe?"production":void 0)!=="production"&&i&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,r);const{connection:u,..._}=g$n(a,l,c);let d=!0;r.setState=(p,x,f)=>{const g=n(p,x);if(!d)return g;const y=f===void 0?{type:s||"anonymous"}:typeof f=="string"?{type:f}:f;return a===void 0?(u?.send(y,o()),g):(u?.send({...y,type:`${a}/${y.type}`},{...cG(c.name),[a]:r.getState()}),g)};const m=(...p)=>{const x=d;d=!1,n(...p),d=x},h=t(r.setState,o,r);if(_.type==="untracked"?u?.init(h):(_.stores[_.store]=r,u?.init(Object.fromEntries(Object.entries(_.stores).map(([p,x])=>[p,p===_.store?h:x.getState()])))),r.dispatchFromDevtools&&typeof r.dispatch=="function"){let p=!1;const x=r.dispatch;r.dispatch=(...f)=>{(wxe?"production":void 0)!=="production"&&f[0].type==="__setState"&&!p&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),p=!0),x(...f)}}return u.subscribe(p=>{var x;switch(p.type){case"ACTION":if(typeof p.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Dxe(p.payload,f=>{if(f.type==="__setState"){if(a===void 0){m(f.state);return}Object.keys(f.state).length!==1&&console.error(`
|
|
5695
5695
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5696
5696
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5697
5697
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
package/dist/standalone.min.js
CHANGED
|
@@ -5379,7 +5379,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
|
|
|
5379
5379
|
50% { opacity: 0.2; }
|
|
5380
5380
|
100% { opacity: 0.6; }
|
|
5381
5381
|
}
|
|
5382
|
-
`,r.appendChild(g)}})}};i();const s=new MutationObserver(i);return s.observe(r,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},Sat=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],HOn=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:r}=t;G.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!r||!n||n.length===0)return;const i=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=Bp(n).source_group?.list().filter(g=>!g.is_subcircuit)||[],l=Bp(n).schematic_component?.list()||[],u=new Map;c.forEach(g=>{const y=g;if(y.parent_source_group_id){const P=u.get(y.parent_source_group_id)||[];P.push(g.source_group_id),u.set(y.parent_source_group_id,P)}});const _=g=>{const y=[],P=u.get(g)||[];for(const v of P)y.push(v),y.push(..._(v));return y},d=g=>{const y=c.find(P=>P.source_group_id===g);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},m=c.length>0&&c.some(g=>g.name&&g.name.trim()!=="");let h=[];if(m){const g=new Map;for(const y of l){const P=Bp(n).source_component.get(y.source_component_id);P?.source_group_id&&(g.has(P.source_group_id)||g.set(P.source_group_id,[]),g.get(P.source_group_id).push(y))}c.forEach((y,P)=>{let v=g.get(y.source_group_id)||[];const S=_(y.source_group_id);for(const M of S){const w=g.get(M)||[];v=[...v,...w]}if(v.length>0){const M=d(y.source_group_id),w=_(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;h.push({id:y.source_group_id,name:y.name||`Group ${P+1}`,components:v,color:Sat[P%Sat.length],depthLevel:M,hasChildren:w,sourceGroupId:y.source_group_id})}})}const p=s.viewBox.baseVal,x=s.getBoundingClientRect(),f=Math.min(x.width/p.width,x.height/p.height)||1;h.sort((g,y)=>g.depthLevel-y.depthLevel),h.forEach(g=>{if(g.components.length===0)return;const y=IOn(g.components,s);if(!y)return;const P=Math.max(8,Math.min(25,15/Math.max(f,.3))),v=g.hasChildren?P*.6:0,S=P+v,M=Math.max(1,2/Math.max(f,.5)),w=g.depthLevel===0?M:M*.7,D=Math.max(4,8/Math.max(f,.5)),A=g.hasChildren?1.3:1,I=D*A,H=I*.5,O=document.createElementNS("http://www.w3.org/2000/svg","rect");O.setAttribute("class","schematic-group-overlay"),O.setAttribute("x",(y.minX-S).toString()),O.setAttribute("y",(y.minY-S).toString()),O.setAttribute("width",(y.maxX-y.minX+S*2).toString()),O.setAttribute("height",(y.maxY-y.minY+S*2).toString()),O.setAttribute("fill","none"),O.setAttribute("stroke",g.color),O.setAttribute("stroke-width",w.toString()),O.setAttribute("stroke-dasharray",`${I},${H}`),O.setAttribute("opacity","0.8"),O.setAttribute("rx","0"),O.setAttribute("ry","0");const B=Math.max(6,Math.min(20,14/Math.max(f,.2))),z=g.depthLevel===0||g.depthLevel===1?0:g.depthLevel*.2,X=B*(1-z),q=Math.max(1,X*.2),K=g.name,oe=document.createElementNS("http://www.w3.org/2000/svg","text");oe.setAttribute("font-size",X.toString()),oe.setAttribute("font-family","Arial, sans-serif"),oe.textContent=K,s.appendChild(oe);const ce=oe.getBBox();s.removeChild(oe);const Z=ce.width+q*2,ne=X+q*2,ie=y.minX-S,ae=y.minY-S-ne,he=document.createElementNS("http://www.w3.org/2000/svg","rect");he.setAttribute("class","schematic-group-overlay"),he.setAttribute("x",ie.toString()),he.setAttribute("y",(ae-ne).toString()),he.setAttribute("width",Z.toString()),he.setAttribute("height",ne.toString()),he.setAttribute("fill","transparent"),he.setAttribute("rx","0"),he.setAttribute("ry","0");const Pe=document.createElementNS("http://www.w3.org/2000/svg","text");Pe.setAttribute("class","schematic-group-overlay"),Pe.setAttribute("x",(ie+q).toString()),Pe.setAttribute("y",(ae+ne-q).toString()),Pe.setAttribute("fill",g.color),Pe.setAttribute("font-size",X.toString()),Pe.setAttribute("font-family","Arial, sans-serif"),Pe.setAttribute("font-weight",g.depthLevel===0?"600":"500"),Pe.setAttribute("stroke",g.color),Pe.setAttribute("stroke-width",Math.max(.2,X*.02).toString()),Pe.textContent=K,s.appendChild(O),s.appendChild(he),s.appendChild(Pe)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(i)},[e,o,r])};function IOn(t,e){let n=1/0,o=1/0,r=-1/0,i=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),r=Math.max(r,l.x+l.width),i=Math.max(i,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:r,maxY:i}}var LOn=Ya("schematic-viewer"),OOn=()=>{Ya.enable("schematic-viewer*")},FOn=LOn,Cat=t=>{const[e,n]=G.useState(0),[o,r]=G.useState(0);return G.useEffect(()=>{if(!t.current)return;const i=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),r(a?.height||0)};i();const s=new ResizeObserver(i);return s.observe(t.current),window.addEventListener("resize",i),()=>{s.disconnect(),window.removeEventListener("resize",i)}},[]),{containerWidth:e,containerHeight:o}},BOn=FOn.extend("useComponentDragging"),zOn=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:r,realToSvgProjection:i,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=G.useState(null),u=or(i,r),_=G.useRef(null),d=G.useRef(null),m=G.useRef(new Map);G.useEffect(()=>{e.forEach(M=>{"edit_event_type"in M&&M.edit_event_type==="edit_schematic_component_location"&&!M.in_progress&&m.current.set(M.schematic_component_id,{...M.new_center})})},[e]);const h=G.useCallback((M,w,D)=>{if(!s)return!1;const A=D.closest('[data-circuit-json-type="schematic_component"]');if(!A)return!1;const I=A.getAttribute("data-schematic-component-id");if(!I)return!1;o&&o();const H=Bp(n).schematic_component.get(I);if(!H)return!1;_.current={x:M,y:w};let O;const B=m.current.get(I);if(B)O={...B};else{const X=vat({editEvents:e,schematic_component_id:I});O={x:H.center.x+X.x,y:H.center.y+X.y},m.current.set(I,{...O})}const z={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:I,original_center:O,new_center:{...O},in_progress:!0,created_at:Date.now(),_element:A};return d.current=z,l(z),!0},[o,s,n,e]),p=G.useCallback(M=>{h(M.clientX,M.clientY,M.target)},[h]),x=G.useCallback(M=>{if(M.touches.length!==1)return;const w=M.touches[0];h(w.clientX,w.clientY,M.target)&&M.preventDefault()},[h]),f=G.useCallback((M,w)=>{if(!d.current||!_.current)return;const D={x:M-_.current.x,y:w-_.current.y},A={x:D.x/u.a,y:D.y/u.d};let I={x:d.current.original_center.x+A.x,y:d.current.original_center.y+A.y};if(a){const O=B=>Math.round(B*10)/10;I={x:O(I.x),y:O(I.y)}}const H={...d.current,new_center:I};d.current=H,l(H)},[u,a]),g=G.useCallback(M=>f(M.clientX,M.clientY),[f]),y=G.useCallback(M=>{if(M.touches.length!==1||!d.current)return;M.preventDefault();const w=M.touches[0];f(w.clientX,w.clientY)},[f]),P=G.useCallback(()=>{if(!d.current)return;const M={...d.current,in_progress:!1};m.current.set(M.schematic_component_id,{...M.new_center}),BOn("endDrag calling onEditEvent with new edit event",{newEditEvent:M}),t&&t(M),d.current=null,_.current=null,l(null)},[t]),v=G.useCallback(()=>P(),[P]),S=G.useCallback(()=>P(),[P]);return G.useEffect(()=>(window.addEventListener("mousemove",g),window.addEventListener("mouseup",v),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",v),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",S)}),[g,v,y,S]),{handleMouseDown:p,handleTouchStart:x,isDragging:!!d.current,activeEditEvent:c}},i3={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},VOn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.schematicEditIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),j.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},$On=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.schematicGridIcon},children:j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:j.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},WOn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.viewMenuIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("circle",{cx:"12",cy:"12",r:"1"}),j.jsx("circle",{cx:"12",cy:"5",r:"1"}),j.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},UOn={version:"2.0.58"},XOn=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:r,onToggleGroups:i,showGrid:s,onToggleGrid:a})=>{const c=G.useMemo(()=>{if(!t||t.length===0)return!1;try{if((Bp(t).source_group?.list()||[]).length>0)return!0;const u=Bp(t).schematic_component?.list()||[];if(u.length>1){const _=new Set;for(const d of u){const m=Bp(t).source_component.get(d.source_component_id);m?.ftype&&_.add(m.ftype)}return _.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?j.jsxs(j.Fragment,{children:[j.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:i3.viewMenuBackdrop}}),j.jsxs("div",{style:{position:"absolute",top:"56px",right:"16px",backgroundColor:"#ffffff",color:"#000000",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",zIndex:i3.viewMenu},children:[j.jsxs("div",{onClick:()=>{c&&i(!r)},onTouchEnd:l=>{l.preventDefault(),c&&i(!r)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:r&&"✓"}),"View Schematic Groups"]}),!c&&j.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),j.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),j.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(UOn?.version)]})]})]}):null},jOn=()=>j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:j.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),GOn=({onClick:t})=>j.jsx("div",{onClick:t,title:"Run SPICE simulation",style:{position:"absolute",top:"16px",right:"112px",backgroundColor:"#fff",color:"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.spiceSimulationIcon},children:j.jsx(jOn,{})});sG.register(yOn,vOn,ZLn,QLn,aOn,pOn,iOn);var uG=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],Mat=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},YOn=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:r})=>{const i=G.useMemo(()=>{const c=e.some(u=>u.toLowerCase().startsWith("v(")),l=e.some(u=>u.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!r)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return j.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(u=>({x:Number(u.name),y:u[c]})),borderColor:uG[l%uG.length],backgroundColor:uG[l%uG.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return Mat(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>Mat(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:i,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return j.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:j.jsx(ROn,{options:a,data:s})})},qOn=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:r,error:i,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,u]=G.useState(String(s.startTime)),[_,d]=G.useState(String(s.duration));G.useEffect(()=>{u(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const m=()=>{a({...s,startTime:Number(l),duration:Number(_)})},h=o.filter(p=>{const x=p.toLowerCase().startsWith("v("),f=p.toLowerCase().startsWith("i(");return!!(s.showVoltage&&x||s.showCurrent&&f)});return j.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1002,fontFamily:"sans-serif"},children:j.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[j.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),j.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),j.jsx("div",{children:j.jsx(YOn,{plotData:n,nodes:h,isLoading:r,error:i,hasRun:c})}),j.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[j.jsxs("div",{style:{display:"flex",gap:"16px"},children:[j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:p=>a({...s,showVoltage:p.target.checked})}),"Voltage"]}),j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:p=>a({...s,showCurrent:p.target.checked})}),"Current"]})]}),j.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[j.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),j.jsx("input",{id:"startTime",type:"number",value:l,onChange:p=>u(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),j.jsx("input",{id:"duration",type:"number",value:_,onChange:p=>d(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("button",{onClick:m,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),j.jsxs("div",{style:{marginTop:"24px"},children:[j.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),j.jsx("pre",{style:{backgroundColor:"#fafafa",padding:"16px",borderRadius:"6px",maxHeight:"150px",overflowY:"auto",border:"1px solid #eee",color:"#333",fontSize:"13px",fontFamily:"monospace"},children:t})]})]})})},JOn="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",_G=null,KOn=()=>{if(typeof window>"u")return null;if(_G)return _G;try{const t=new Blob([atob(JOn)],{type:"application/javascript"});return _G=URL.createObjectURL(t),_G}catch(t){return console.error("Failed to create blob URL for worker",t),null}},QOn=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],r=Object.keys(e).filter(a=>a!==n),i=r;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return r.forEach(u=>{l[u]=e[u][c]}),l}),nodes:i}},ZOn=t=>{const[e,n]=G.useState([]),[o,r]=G.useState([]),[i,s]=G.useState(!0),[a,c]=G.useState(null);return G.useEffect(()=>{if(!t){s(!1),n([]),r([]),c(null);return}s(!0),c(null),n([]),r([]);const l=KOn();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const u=new Worker(l,{type:"module"});return u.onmessage=_=>{if(_.data.type==="result")try{const{plotData:d,nodes:m}=QOn(_.data.result);n(d),r(m)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else _.data.type==="error"&&c(_.data.error);s(!1)},u.onerror=_=>{c(_.message),s(!1)},u.postMessage({spiceString:t}),()=>{u.terminate()}},[t]),{plotData:e,nodes:o,isLoading:i,error:a}},Fxe=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},eFn=(t,e)=>{const o=tke(t).toSpiceString(),i=o.split(`
|
|
5382
|
+
`,r.appendChild(g)}})}};i();const s=new MutationObserver(i);return s.observe(r,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},Sat=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],HOn=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:r}=t;G.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!r||!n||n.length===0)return;const i=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=Bp(n).source_group?.list().filter(g=>!g.is_subcircuit)||[],l=Bp(n).schematic_component?.list()||[],u=new Map;c.forEach(g=>{const y=g;if(y.parent_source_group_id){const P=u.get(y.parent_source_group_id)||[];P.push(g.source_group_id),u.set(y.parent_source_group_id,P)}});const _=g=>{const y=[],P=u.get(g)||[];for(const v of P)y.push(v),y.push(..._(v));return y},d=g=>{const y=c.find(P=>P.source_group_id===g);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},m=c.length>0&&c.some(g=>g.name&&g.name.trim()!=="");let h=[];if(m){const g=new Map;for(const y of l){const P=Bp(n).source_component.get(y.source_component_id);P?.source_group_id&&(g.has(P.source_group_id)||g.set(P.source_group_id,[]),g.get(P.source_group_id).push(y))}c.forEach((y,P)=>{let v=g.get(y.source_group_id)||[];const S=_(y.source_group_id);for(const M of S){const w=g.get(M)||[];v=[...v,...w]}if(v.length>0){const M=d(y.source_group_id),w=_(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;h.push({id:y.source_group_id,name:y.name||`Group ${P+1}`,components:v,color:Sat[P%Sat.length],depthLevel:M,hasChildren:w,sourceGroupId:y.source_group_id})}})}const p=s.viewBox.baseVal,x=s.getBoundingClientRect(),f=Math.min(x.width/p.width,x.height/p.height)||1;h.sort((g,y)=>g.depthLevel-y.depthLevel),h.forEach(g=>{if(g.components.length===0)return;const y=IOn(g.components,s);if(!y)return;const P=Math.max(8,Math.min(25,15/Math.max(f,.3))),v=g.hasChildren?P*.6:0,S=P+v,M=Math.max(1,2/Math.max(f,.5)),w=g.depthLevel===0?M:M*.7,D=Math.max(4,8/Math.max(f,.5)),A=g.hasChildren?1.3:1,I=D*A,H=I*.5,O=document.createElementNS("http://www.w3.org/2000/svg","rect");O.setAttribute("class","schematic-group-overlay"),O.setAttribute("x",(y.minX-S).toString()),O.setAttribute("y",(y.minY-S).toString()),O.setAttribute("width",(y.maxX-y.minX+S*2).toString()),O.setAttribute("height",(y.maxY-y.minY+S*2).toString()),O.setAttribute("fill","none"),O.setAttribute("stroke",g.color),O.setAttribute("stroke-width",w.toString()),O.setAttribute("stroke-dasharray",`${I},${H}`),O.setAttribute("opacity","0.8"),O.setAttribute("rx","0"),O.setAttribute("ry","0");const B=Math.max(6,Math.min(20,14/Math.max(f,.2))),z=g.depthLevel===0||g.depthLevel===1?0:g.depthLevel*.2,X=B*(1-z),q=Math.max(1,X*.2),K=g.name,oe=document.createElementNS("http://www.w3.org/2000/svg","text");oe.setAttribute("font-size",X.toString()),oe.setAttribute("font-family","Arial, sans-serif"),oe.textContent=K,s.appendChild(oe);const ce=oe.getBBox();s.removeChild(oe);const Z=ce.width+q*2,ne=X+q*2,ie=y.minX-S,ae=y.minY-S-ne,he=document.createElementNS("http://www.w3.org/2000/svg","rect");he.setAttribute("class","schematic-group-overlay"),he.setAttribute("x",ie.toString()),he.setAttribute("y",(ae-ne).toString()),he.setAttribute("width",Z.toString()),he.setAttribute("height",ne.toString()),he.setAttribute("fill","transparent"),he.setAttribute("rx","0"),he.setAttribute("ry","0");const Pe=document.createElementNS("http://www.w3.org/2000/svg","text");Pe.setAttribute("class","schematic-group-overlay"),Pe.setAttribute("x",(ie+q).toString()),Pe.setAttribute("y",(ae+ne-q).toString()),Pe.setAttribute("fill",g.color),Pe.setAttribute("font-size",X.toString()),Pe.setAttribute("font-family","Arial, sans-serif"),Pe.setAttribute("font-weight",g.depthLevel===0?"600":"500"),Pe.setAttribute("stroke",g.color),Pe.setAttribute("stroke-width",Math.max(.2,X*.02).toString()),Pe.textContent=K,s.appendChild(O),s.appendChild(he),s.appendChild(Pe)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(i)},[e,o,r])};function IOn(t,e){let n=1/0,o=1/0,r=-1/0,i=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),r=Math.max(r,l.x+l.width),i=Math.max(i,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:r,maxY:i}}var LOn=Ya("schematic-viewer"),OOn=()=>{Ya.enable("schematic-viewer*")},FOn=LOn,Cat=t=>{const[e,n]=G.useState(0),[o,r]=G.useState(0);return G.useEffect(()=>{if(!t.current)return;const i=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),r(a?.height||0)};i();const s=new ResizeObserver(i);return s.observe(t.current),window.addEventListener("resize",i),()=>{s.disconnect(),window.removeEventListener("resize",i)}},[]),{containerWidth:e,containerHeight:o}},BOn=FOn.extend("useComponentDragging"),zOn=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:r,realToSvgProjection:i,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=G.useState(null),u=or(i,r),_=G.useRef(null),d=G.useRef(null),m=G.useRef(new Map);G.useEffect(()=>{e.forEach(M=>{"edit_event_type"in M&&M.edit_event_type==="edit_schematic_component_location"&&!M.in_progress&&m.current.set(M.schematic_component_id,{...M.new_center})})},[e]);const h=G.useCallback((M,w,D)=>{if(!s)return!1;const A=D.closest('[data-circuit-json-type="schematic_component"]');if(!A)return!1;const I=A.getAttribute("data-schematic-component-id");if(!I)return!1;o&&o();const H=Bp(n).schematic_component.get(I);if(!H)return!1;_.current={x:M,y:w};let O;const B=m.current.get(I);if(B)O={...B};else{const X=vat({editEvents:e,schematic_component_id:I});O={x:H.center.x+X.x,y:H.center.y+X.y},m.current.set(I,{...O})}const z={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:I,original_center:O,new_center:{...O},in_progress:!0,created_at:Date.now(),_element:A};return d.current=z,l(z),!0},[o,s,n,e]),p=G.useCallback(M=>{h(M.clientX,M.clientY,M.target)},[h]),x=G.useCallback(M=>{if(M.touches.length!==1)return;const w=M.touches[0];h(w.clientX,w.clientY,M.target)&&M.preventDefault()},[h]),f=G.useCallback((M,w)=>{if(!d.current||!_.current)return;const D={x:M-_.current.x,y:w-_.current.y},A={x:D.x/u.a,y:D.y/u.d};let I={x:d.current.original_center.x+A.x,y:d.current.original_center.y+A.y};if(a){const O=B=>Math.round(B*10)/10;I={x:O(I.x),y:O(I.y)}}const H={...d.current,new_center:I};d.current=H,l(H)},[u,a]),g=G.useCallback(M=>f(M.clientX,M.clientY),[f]),y=G.useCallback(M=>{if(M.touches.length!==1||!d.current)return;M.preventDefault();const w=M.touches[0];f(w.clientX,w.clientY)},[f]),P=G.useCallback(()=>{if(!d.current)return;const M={...d.current,in_progress:!1};m.current.set(M.schematic_component_id,{...M.new_center}),BOn("endDrag calling onEditEvent with new edit event",{newEditEvent:M}),t&&t(M),d.current=null,_.current=null,l(null)},[t]),v=G.useCallback(()=>P(),[P]),S=G.useCallback(()=>P(),[P]);return G.useEffect(()=>(window.addEventListener("mousemove",g),window.addEventListener("mouseup",v),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",v),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",S)}),[g,v,y,S]),{handleMouseDown:p,handleTouchStart:x,isDragging:!!d.current,activeEditEvent:c}},i3={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},VOn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.schematicEditIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),j.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},$On=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.schematicGridIcon},children:j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:j.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},WOn=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return j.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.viewMenuIcon},children:j.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[j.jsx("circle",{cx:"12",cy:"12",r:"1"}),j.jsx("circle",{cx:"12",cy:"5",r:"1"}),j.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},UOn={version:"2.0.59"},XOn=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:r,onToggleGroups:i,showGrid:s,onToggleGrid:a})=>{const c=G.useMemo(()=>{if(!t||t.length===0)return!1;try{if((Bp(t).source_group?.list()||[]).length>0)return!0;const u=Bp(t).schematic_component?.list()||[];if(u.length>1){const _=new Set;for(const d of u){const m=Bp(t).source_component.get(d.source_component_id);m?.ftype&&_.add(m.ftype)}return _.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?j.jsxs(j.Fragment,{children:[j.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:i3.viewMenuBackdrop}}),j.jsxs("div",{style:{position:"absolute",top:"56px",right:"16px",backgroundColor:"#ffffff",color:"#000000",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",zIndex:i3.viewMenu},children:[j.jsxs("div",{onClick:()=>{c&&i(!r)},onTouchEnd:l=>{l.preventDefault(),c&&i(!r)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:r&&"✓"}),"View Schematic Groups"]}),!c&&j.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),j.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[j.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),j.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(UOn?.version)]})]})]}):null},jOn=()=>j.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:j.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),GOn=({onClick:t})=>j.jsx("div",{onClick:t,title:"Run SPICE simulation",style:{position:"absolute",top:"16px",right:"112px",backgroundColor:"#fff",color:"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:i3.spiceSimulationIcon},children:j.jsx(jOn,{})});sG.register(yOn,vOn,ZLn,QLn,aOn,pOn,iOn);var uG=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],Mat=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},YOn=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:r})=>{const i=G.useMemo(()=>{const c=e.some(u=>u.toLowerCase().startsWith("v(")),l=e.some(u=>u.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!r)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return j.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return j.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(u=>({x:Number(u.name),y:u[c]})),borderColor:uG[l%uG.length],backgroundColor:uG[l%uG.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return Mat(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>Mat(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:i,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return j.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:j.jsx(ROn,{options:a,data:s})})},qOn=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:r,error:i,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,u]=G.useState(String(s.startTime)),[_,d]=G.useState(String(s.duration));G.useEffect(()=>{u(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const m=()=>{a({...s,startTime:Number(l),duration:Number(_)})},h=o.filter(p=>{const x=p.toLowerCase().startsWith("v("),f=p.toLowerCase().startsWith("i(");return!!(s.showVoltage&&x||s.showCurrent&&f)});return j.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1002,fontFamily:"sans-serif"},children:j.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[j.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[j.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),j.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),j.jsx("div",{children:j.jsx(YOn,{plotData:n,nodes:h,isLoading:r,error:i,hasRun:c})}),j.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[j.jsxs("div",{style:{display:"flex",gap:"16px"},children:[j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:p=>a({...s,showVoltage:p.target.checked})}),"Voltage"]}),j.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[j.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:p=>a({...s,showCurrent:p.target.checked})}),"Current"]})]}),j.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[j.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),j.jsx("input",{id:"startTime",type:"number",value:l,onChange:p=>u(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),j.jsx("input",{id:"duration",type:"number",value:_,onChange:p=>d(p.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),j.jsx("button",{onClick:m,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),j.jsxs("div",{style:{marginTop:"24px"},children:[j.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),j.jsx("pre",{style:{backgroundColor:"#fafafa",padding:"16px",borderRadius:"6px",maxHeight:"150px",overflowY:"auto",border:"1px solid #eee",color:"#333",fontSize:"13px",fontFamily:"monospace"},children:t})]})]})})},JOn="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",_G=null,KOn=()=>{if(typeof window>"u")return null;if(_G)return _G;try{const t=new Blob([atob(JOn)],{type:"application/javascript"});return _G=URL.createObjectURL(t),_G}catch(t){return console.error("Failed to create blob URL for worker",t),null}},QOn=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],r=Object.keys(e).filter(a=>a!==n),i=r;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return r.forEach(u=>{l[u]=e[u][c]}),l}),nodes:i}},ZOn=t=>{const[e,n]=G.useState([]),[o,r]=G.useState([]),[i,s]=G.useState(!0),[a,c]=G.useState(null);return G.useEffect(()=>{if(!t){s(!1),n([]),r([]),c(null);return}s(!0),c(null),n([]),r([]);const l=KOn();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const u=new Worker(l,{type:"module"});return u.onmessage=_=>{if(_.data.type==="result")try{const{plotData:d,nodes:m}=QOn(_.data.result);n(d),r(m)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else _.data.type==="error"&&c(_.data.error);s(!1)},u.onerror=_=>{c(_.message),s(!1)},u.postMessage({spiceString:t}),()=>{u.terminate()}},[t]),{plotData:e,nodes:o,isLoading:i,error:a}},Fxe=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},eFn=(t,e)=>{const o=tke(t).toSpiceString(),i=o.split(`
|
|
5383
5383
|
`).filter(A=>A.trim()!=="").filter(A=>!A.startsWith("*")&&!A.startsWith(".")&&A.trim()!==""),s=new Set,a=new Set,c=new Set;for(const A of i){const I=A.trim().split(/\s+/);if(I.length<3)continue;const H=I[0],O=H[0].toUpperCase();let B=[];if(["R","C","L","V","I","D"].includes(O))B=I.slice(1,3),O==="V"&&c.add(H);else if(O==="Q"&&I.length>=4)B=I.slice(1,4);else if(O==="M"&&I.length>=5)B=I.slice(1,5);else if(O==="X")B=I.slice(1,-1);else continue;B.forEach(z=>s.add(z)),O==="C"&&B.forEach(z=>a.add(z))}s.delete("0"),a.delete("0");const l=Array.from(a).map(A=>`.ic V(${A})=0`),u=[],_=Array.from(s).map(A=>`V(${A})`);u.push(..._);const d=Array.from(c).map(A=>`I(${A})`);u.push(...d);const m=u.length>0?`.probe ${u.join(" ")}`:"",h=e?.startTime??0,p=e?.duration??20,x=h*.001,f=p*.001,g=x+f,y=f/50,P=`.tran ${Fxe(y)} ${Fxe(g)} ${Fxe(x)} UIC`,v=".end",S=o.split(`
|
|
5384
5384
|
`);let M=-1;for(let A=S.length-1;A>=0;A--)if(S[A].trim().toLowerCase().startsWith(v)){M=A;break}const w=[...l,m,P].filter(Boolean);let D;if(M!==-1){const A=S.slice(0,M),I=S.slice(M);D=[...A,...w,...I]}else D=[...S,...w,v];return D.join(`
|
|
5385
5385
|
`)},tFn=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},nFn=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},Bxe=G.createContext(null),oFn=5,rFn=(t,e)=>!t&&!e?!0:!t||!e?!1:t.minX===e.minX&&t.maxX===e.maxX&&t.minY===e.minY&&t.maxY===e.maxY,iFn=({children:t})=>{if(G.useContext(Bxe))return j.jsx(j.Fragment,{children:t});const n=G.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),o=G.useCallback(()=>{for(const _ of n.current.subscribers)_()},[]),r=G.useCallback(()=>{const _=n.current.pointer,d=new Set;if(_)for(const[h,p]of n.current.boundingBoxes){const x=p.bounds;x&&_.x>=x.minX&&_.x<=x.maxX&&_.y>=x.minY&&_.y<=x.maxY&&d.add(h)}const m=n.current.hoveringIds;d.size===m.size&&[...d].every(h=>m.has(h))||(n.current.hoveringIds=d,o())},[o]),i=G.useCallback((_,d)=>{n.current.boundingBoxes.set(_,d),r()},[r]),s=G.useCallback((_,d)=>{const m=n.current.boundingBoxes.get(_);m&&rFn(m.bounds,d.bounds)&&m.onClick===d.onClick||(n.current.boundingBoxes.set(_,d),r())},[r]),a=G.useCallback(_=>{n.current.boundingBoxes.delete(_)&&r()},[r]),c=G.useCallback(_=>(n.current.subscribers.add(_),()=>{n.current.subscribers.delete(_)}),[]),l=G.useCallback(_=>n.current.hoveringIds.has(_),[]);G.useEffect(()=>{const _=p=>{const{clientX:x,clientY:f}=p,g=n.current.pointer;g&&g.x===x&&g.y===f||(n.current.pointer={x,y:f},r())},d=()=>{n.current.pointer!==null&&(n.current.pointer=null,n.current.mouseDownPosition=null,r())},m=p=>{n.current.mouseDownPosition={x:p.clientX,y:p.clientY}},h=p=>{const{clientX:x,clientY:f}=p,g=n.current.mouseDownPosition;if(g&&Math.sqrt(Math.pow(x-g.x,2)+Math.pow(f-g.y,2))>oFn){n.current.mouseDownPosition=null;return}n.current.mouseDownPosition=null;for(const y of n.current.boundingBoxes.values()){const P=y.bounds;P&&x>=P.minX&&x<=P.maxX&&f>=P.minY&&f<=P.maxY&&y.onClick?.(p)}};return window.addEventListener("pointermove",_,{passive:!0}),window.addEventListener("pointerdown",_,{passive:!0}),window.addEventListener("pointerup",_,{passive:!0}),window.addEventListener("pointerleave",d),window.addEventListener("pointercancel",d),window.addEventListener("blur",d),window.addEventListener("mousedown",m,{passive:!0}),window.addEventListener("click",h,{passive:!0}),()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerdown",_),window.removeEventListener("pointerup",_),window.removeEventListener("pointerleave",d),window.removeEventListener("pointercancel",d),window.removeEventListener("blur",d),window.removeEventListener("mousedown",m),window.removeEventListener("click",h)}},[r]);const u=G.useMemo(()=>({registerBoundingBox:i,updateBoundingBox:s,unregisterBoundingBox:a,subscribe:c,isHovering:l}),[i,s,a,c,l]);return j.jsx(Bxe.Provider,{value:u,children:t})},Tat=t=>{const e=G.useContext(Bxe);if(!e)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const n=G.useId(),o=G.useRef(t);o.current=t;const r=G.useMemo(()=>s=>{o.current.onClick?.(s)},[]);return G.useEffect(()=>(e.registerBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?r:void 0}),()=>{e.unregisterBoundingBox(n)}),[e,r,n]),G.useEffect(()=>{e.updateBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?r:void 0})},[e,r,n,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:G.useSyncExternalStore(e.subscribe,()=>e.isHovering(n),()=>!1)}},sFn=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,aFn=({componentId:t,svgDivRef:e,containerRef:n,onComponentClick:o,onHoverChange:r,showOutline:i,circuitJsonKey:s})=>{const[a,c]=G.useState(null),l=G.useRef(null),u=G.useCallback(()=>{l.current=null;const x=e.current,f=n.current;if(!x||!f){c(S=>S&&null);return}const g=x.querySelector(`[data-schematic-component-id="${t}"]`);if(!g){c(S=>S&&null);return}const y=g.getBoundingClientRect(),P=f.getBoundingClientRect(),v={bounds:{minX:y.left,maxX:y.right,minY:y.top,maxY:y.bottom},rect:{left:y.left-P.left,top:y.top-P.top,width:y.width,height:y.height}};c(S=>sFn(S,v)?S:v)},[t,n,e]),_=G.useCallback(()=>{l.current===null&&(l.current=window.requestAnimationFrame(u))},[u]);G.useEffect(()=>{_()},[_,s]),G.useEffect(()=>{_();const x=e.current,f=n.current;if(!x||!f)return;const g=typeof ResizeObserver<"u"?new ResizeObserver(()=>{_()}):null;g?.observe(f),g?.observe(x);const y=typeof MutationObserver<"u"?new MutationObserver(()=>{_()}):null;return y?.observe(x,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{g?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},[_,e,n]);const d=G.useCallback(x=>{o&&o(t,x)},[t,o]),m=a?.bounds??null,{hovering:h}=Tat({bounds:m,onClick:o?d:void 0});if(G.useEffect(()=>{r&&r(t,h)},[h,t,r]),!a||!h||!i)return null;const p=a.rect;return j.jsx("div",{style:{position:"absolute",left:p.left,top:p.top,width:p.width,height:p.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:i3.schematicComponentHoverOutline}})},cFn=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,lFn=({portId:t,portLabel:e,svgDivRef:n,containerRef:o,onPortClick:r,onHoverChange:i,showOutline:s,circuitJsonKey:a})=>{const[c,l]=G.useState(null),u=G.useRef(null),_=G.useCallback(()=>{u.current=null;const f=n.current,g=o.current;if(!f||!g){l(w=>w&&null);return}const y=f.querySelector(`[data-schematic-port-id="${t}"]`);if(!y){l(w=>w&&null);return}const P=y.getBoundingClientRect(),v=g.getBoundingClientRect(),S=4,M={bounds:{minX:P.left-S,maxX:P.right+S,minY:P.top-S,maxY:P.bottom+S},rect:{left:P.left-v.left-S,top:P.top-v.top-S,width:P.width+S*2,height:P.height+S*2}};l(w=>cFn(w,M)?w:M)},[t,o,n]),d=G.useCallback(()=>{u.current===null&&(u.current=window.requestAnimationFrame(_))},[_]);G.useEffect(()=>{d()},[d,a]),G.useEffect(()=>{d();const f=n.current,g=o.current;if(!f||!g)return;const y=typeof ResizeObserver<"u"?new ResizeObserver(()=>{d()}):null;y?.observe(g),y?.observe(f);const P=typeof MutationObserver<"u"?new MutationObserver(()=>{d()}):null;return P?.observe(f,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{y?.disconnect(),P?.disconnect(),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),u.current!==null&&(cancelAnimationFrame(u.current),u.current=null)}},[d,n,o]);const m=G.useCallback(f=>{r&&r(t,f)},[t,r]),h=c?.bounds??null,{hovering:p}=Tat({bounds:h,onClick:r?m:void 0});if(G.useEffect(()=>{i&&i(t,p)},[p,t,i]),!c||!s)return null;const x=c.rect;return j.jsxs(j.Fragment,{children:[j.jsx("div",{style:{position:"absolute",left:x.left,top:x.top,width:x.width,height:x.height,border:p?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:p?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:i3.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),p&&e&&j.jsx("div",{style:{position:"absolute",left:x.left+x.width/2,top:x.top-24,transform:"translateX(-50%)",backgroundColor:"rgba(0, 0, 0, 0.85)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",whiteSpace:"nowrap",pointerEvents:"none",zIndex:i3.schematicPortHoverOutline+1},children:e})]})},uFn=({circuitJson:t,containerStyle:e,editEvents:n=[],onEditEvent:o,defaultEditMode:r=!1,debugGrid:i=!1,editingEnabled:s=!1,debug:a=!1,clickToInteractEnabled:c=!1,colorOverrides:l,spiceSimulationEnabled:u=!1,disableGroups:_=!1,onSchematicComponentClicked:d,showSchematicPorts:m=!1,onSchematicPortClicked:h})=>{a&&OOn();const[p,x]=G.useState(!1),[f,g]=G.useState({showVoltage:!0,showCurrent:!1,startTime:0,duration:20}),y=ge=>`${ge?.length||0}_${ge?.editCount||0}`,P=G.useMemo(()=>y(t),[t]),v=G.useMemo(()=>{if(!u)return null;try{return eFn(t,f)}catch(ge){return console.error("Failed to generate SPICE string",ge),null}},[P,u,f.startTime,f.duration]),[S,M]=G.useState(!1);G.useEffect(()=>{M(!1)},[P]);const{plotData:w,nodes:D,isLoading:A,error:I}=ZOn(S?v:null),[H,O]=G.useState(r),[B,z]=G.useState(!0),[X,q]=G.useState(!1),K=i||X,[oe,ce]=G.useState(!c),[Z,ne]=G.useState(!1),[ie,ae]=G.useState(()=>_?!1:tFn("schematic_viewer_show_groups",!1)),[he,Pe]=G.useState(!1),Ce=G.useRef(new Set),De=G.useCallback((ge,et)=>{et?Ce.current.add(ge):Ce.current.delete(ge),Pe(Ce.current.size>0)},[]),[me,Me]=G.useState(!1),xe=G.useRef(new Set),Ve=G.useCallback((ge,et)=>{et?xe.current.add(ge):xe.current.delete(ge),Me(xe.current.size>0)},[]),We=G.useRef(null),Ge=G.useRef(null),fe=G.useMemo(()=>{try{return Bp(t).schematic_component?.list()?.map(ge=>ge.schematic_component_id)??[]}catch(ge){return console.error("Failed to derive schematic component ids",ge),[]}},[P,t]),Xe=G.useMemo(()=>{if(!m)return[];try{return(Bp(t).schematic_port?.list()??[]).map(et=>{const st=Bp(t).source_port.get(et.source_port_id),Rt=(st?.source_component_id?Bp(t).source_component.get(st.source_component_id):null)?.name??"?",Ft=et.display_pin_label??st?.pin_number??st?.name??"?";return{portId:et.source_port_id,label:`${Rt}.${Ft}`}})}catch(ge){return console.error("Failed to derive schematic port info",ge),[]}},[P,t,m]),Le=ge=>{const et=ge.touches[0];Ge.current={x:et.clientX,y:et.clientY}},ke=ge=>{const et=ge.changedTouches[0],st=Ge.current;if(!st)return;const xt=Math.abs(et.clientX-st.x),Rt=Math.abs(et.clientY-st.y);xt<10&&Rt<10&&(ge.preventDefault(),ce(!0)),Ge.current=null},[Be,Re]=G.useState([]),be=G.useRef(t);G.useEffect(()=>{const ge=y(t),et=y(be.current);ge!==et&&(Re([]),be.current=t)},[t]);const{ref:Ee,cancelDrag:we,transform:Fe}=sH({onSetTransform(ge){We.current&&(We.current.style.transform=Y1(ge))},enabled:oe&&!p}),{containerWidth:$e,containerHeight:Qe}=Cat(Ee),nt=G.useMemo(()=>!$e||!Qe?"":Lj(t,{width:$e,height:Qe||720,grid:K?{cellSize:1,labelCells:!0}:void 0,colorOverrides:l}),[P,$e,Qe,K]),it=G.useMemo(()=>nt.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent",[nt]),at=G.useMemo(()=>{if(!nt)return qc();const ge=nt.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return IL(ge)}catch(et){return console.error(et),qc()}},[nt]),ft=ge=>{Re(et=>[...et,ge]),o&&o(ge)},St=G.useMemo(()=>[...n,...Be],[n,Be]),{handleMouseDown:It,handleTouchStart:Vt,isDragging:Lt,activeEditEvent:Et}=zOn({onEditEvent:ft,cancelDrag:we,realToSvgProjection:at,svgToScreenProjection:Fe,circuitJson:t,editEvents:St,enabled:H&&oe&&!p,snapToGrid:B});kOn({svgDivRef:We,editEvents:St,realToSvgProjection:at,svgToScreenProjection:Fe,activeEditEvent:Et}),NOn({svgDivRef:We,circuitJson:t,activeEditEvent:Et,editEvents:St}),HOn({svgDivRef:We,circuitJson:t,circuitJsonKey:P,showGroups:ie&&!_});const $t=G.useRef(Vt);G.useEffect(()=>{$t.current=Vt},[Vt]);const Sn=G.useMemo(()=>j.jsx("div",{ref:We,style:{pointerEvents:c?oe?"auto":"none":"auto",transformOrigin:"0 0"},className:d?"schematic-component-clickable":void 0,onTouchStart:ge=>{H&&oe&&!p&&$t.current(ge)},dangerouslySetInnerHTML:{__html:nt}}),[nt,oe,c,H,p]);return j.jsxs(iFn,{children:[d&&j.jsx("style",{children:".schematic-component-clickable [data-schematic-component-id]:hover { cursor: pointer !important; }"}),h&&j.jsx("style",{children:"[data-schematic-port-id]:hover { cursor: pointer !important; }"}),j.jsxs("div",{ref:Ee,style:{position:"relative",backgroundColor:it,overflow:"hidden",cursor:p?"auto":Lt?"grabbing":c&&!oe||he&&d||me&&h?"pointer":"grab",minHeight:"300px",...e},onWheelCapture:ge=>{p&&ge.stopPropagation()},onMouseDown:ge=>{if(c&&!oe){ge.preventDefault(),ge.stopPropagation();return}It(ge)},onMouseDownCapture:ge=>{if(c&&!oe){ge.preventDefault(),ge.stopPropagation();return}},onTouchStart:ge=>{p||Le(ge)},onTouchEnd:ge=>{p||ke(ge)},children:[!oe&&c&&j.jsx("div",{onClick:ge=>{ge.preventDefault(),ge.stopPropagation(),ce(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:i3.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"all",touchAction:"pan-x pan-y pinch-zoom"},children:j.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})}),j.jsx(WOn,{active:Z,onClick:()=>ne(!Z)}),s&&j.jsx(VOn,{active:H,onClick:()=>O(!H)}),s&&H&&j.jsx($On,{active:B,onClick:()=>z(!B)}),j.jsx(XOn,{circuitJson:t,circuitJsonKey:P,isVisible:Z,onClose:()=>ne(!1),showGroups:ie,onToggleGroups:ge=>{_||(ae(ge),nFn("schematic_viewer_show_groups",ge))},showGrid:K,onToggleGrid:q}),u&&j.jsx(GOn,{onClick:()=>x(!0)}),p&&j.jsx(qOn,{spiceString:v,onClose:()=>x(!1),plotData:w,nodes:D,isLoading:A,error:I,simOptions:f,onSimOptionsChange:ge=>{M(!0),g(ge)},hasRun:S}),d&&fe.map(ge=>j.jsx(aFn,{componentId:ge,svgDivRef:We,containerRef:Ee,showOutline:!0,circuitJsonKey:P,onHoverChange:De,onComponentClick:(et,st)=>{d?.({schematicComponentId:et,event:st})}},ge)),Sn,m&&Xe.map(({portId:ge,label:et})=>j.jsx(lFn,{portId:ge,portLabel:et,svgDivRef:We,containerRef:Ee,showOutline:!0,circuitJsonKey:P,onHoverChange:Ve,onPortClick:h?(st,xt)=>{h?.({schematicPortId:st,event:xt})}:void 0},ge))]})]})},_Fn=({circuitJson:t,containerStyle:e,colorOverrides:n,width:o,height:r,className:i})=>{const[s,a]=G.useState(null),[c,l]=G.useState(!0),[u,_]=G.useState(null),[d,m]=G.useState(null),h=G.useRef(null),p=G.useRef(null),{containerWidth:x,containerHeight:f}=Cat(h),[g,y]=G.useState(!1),{ref:P}=sH({onSetTransform(O){p.current&&(p.current.style.transform=Y1(O))}}),v=o||x||1e3,S=r||f||600;G.useEffect(()=>{l(!0),_(null),a(t),l(!1)},[t]);const M=G.useMemo(()=>s&&s.find(B=>B.type==="simulation_experiment")?.simulation_experiment_id||null,[s]),w=G.useMemo(()=>s?s.filter(O=>O.type==="simulation_transient_voltage_graph").map(O=>O.simulation_transient_voltage_graph_id):[],[s]),D=G.useMemo(()=>{if(!s||!v||!S||!M)return"";try{return xit({circuitJson:s,simulation_experiment_id:M,simulation_transient_voltage_graph_ids:w,width:v,height:S,schematicOptions:{colorOverrides:n}})}catch(O){return console.error("Failed to generate fallback schematic SVG:",O),""}},[s,v,S,n,M,w]);G.useEffect(()=>{if(!D){m(null);return}try{const O=new Blob([D],{type:"image/svg+xml"}),B=URL.createObjectURL(O);return m(B),()=>{URL.revokeObjectURL(B)}}catch(O){console.error("Failed to create SVG object URL:",O),m(null)}},[D]);const A=G.useMemo(()=>D?D.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent":"transparent",[D]),I=O=>{y(!0)},H=O=>{y(!0)};return G.useEffect(()=>{const O=()=>{y(!1)},B=()=>{y(!1)};return window.addEventListener("mouseup",O),window.addEventListener("touchend",B),()=>{window.removeEventListener("mouseup",O),window.removeEventListener("touchend",B)}},[]),c?j.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f5f5f5",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#666",...e},className:i,children:"Loading circuit..."}):u?j.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#fef2f2",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#dc2626",...e},className:i,children:j.jsxs("div",{style:{textAlign:"center",padding:"20px"},children:[j.jsx("div",{style:{fontWeight:"bold",marginBottom:"8px"},children:"Circuit Conversion Error"}),j.jsx("div",{style:{fontSize:"14px"},children:u})]})}):D?j.jsx("div",{ref:O=>{h.current=O,P.current=O},style:{position:"relative",backgroundColor:A,overflow:"hidden",minHeight:"300px",cursor:g?"grabbing":"grab",...e},className:i,onMouseDown:I,onTouchStart:H,children:d?j.jsx("img",{ref:p,src:d,alt:"Circuit Simulation",style:{transformOrigin:"0 0",width:"100%",height:"100%",display:"block",objectFit:"contain"}}):j.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",minHeight:"300px",color:"#666",fontFamily:"sans-serif"},children:"Failed to render SVG"})}):j.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"#f8fafc",minHeight:"300px",fontFamily:"sans-serif",gap:"12px",...e},className:i,children:[j.jsx("div",{style:{fontSize:"16px",color:"#475569",fontWeight:500},children:"No Simulation Found"}),j.jsxs("div",{style:{fontSize:"14px",color:"#64748b"},children:["Use"," ",j.jsx("code",{style:{backgroundColor:"#e2e8f0",padding:"2px 6px",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px"},children:"<analogsimulation />"})," ","to create simulations"]})]})},wat=t=>{const[e,n]=G.useState(0),[o,r]=G.useState(0);return G.useEffect(()=>{if(!t.current)return;const i=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),r(a?.height||0)};i();const s=new ResizeObserver(i);return s.observe(t.current),window.addEventListener("resize",i),()=>{s.disconnect(),window.removeEventListener("resize",i)}},[]),{containerWidth:e,containerHeight:o}};Ya("assembly-viewer");var Eat=()=>{Ya.enable("assembly-viewer*")},dFn=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&Eat();const r=G.useRef(null),{ref:i}=sH({onSetTransform(u){r.current&&(r.current.style.transform=Y1(u))}}),{containerWidth:s,containerHeight:a}=wat(i),c=G.useMemo(()=>!s||!a?"":jrt(t,{width:s,height:a||720}),[t,s,a]);G.useMemo(()=>{if(!c)return qc();const u=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return IL(u)}catch(_){return console.error(_),qc()}},[c]);const l=G.useMemo(()=>j.jsx("div",{ref:r,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return j.jsx("div",{ref:i,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})},hFn=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&Eat();const r=G.useRef(null),{ref:i}=sH({onSetTransform(u){r.current&&(r.current.style.transform=Y1(u))}}),{containerWidth:s,containerHeight:a}=wat(i),c=G.useMemo(()=>!s||!a?"":tit(t,{width:s,height:a||720}),[t,s,a]);G.useMemo(()=>{if(!c)return qc();const u=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return IL(u)}catch(_){return console.error(_),qc()}},[c]);const l=G.useMemo(()=>j.jsx("div",{ref:r,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return j.jsx("div",{ref:i,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})};const Dat=["Initialize a tscircuit project using [tsci init](https://github.com/tscircuit/cli) before adding components.","Define reusable modules with cached routes using [<subcircuit />](https://docs.tscircuit.com/elements/subcircuit)","Run `tsci dev` on the command line to preview your boards before export",'Use units like mm or mils consistently across your designs (e.g. pcbX="10mm")',"Quickly set footprints with the [footprint prop](https://docs.tscircuit.com/footprints/footprinter-strings)","Check out the guide on [ordering prototypes](https://docs.tscircuit.com/building-electronics/ordering-prototypes)","Use [net labels](https://docs.tscircuit.com/elements/net) and [group elements](https://docs.tscircuit.com/elements/group) to organize complex schematics.","You can manually drag components on the PCB and Schematic using [manual edits](https://docs.tscircuit.com/guides/manual-edits)","Every tscircuit module can export to [Circuit JSON](https://github.com/tscircuit/circuit-json), Gerbers, Pick'n'Place CSV files, Bill of Materials CSV and more","You can import components from [JLCPCB](https://docs.tscircuit.com/guides/importing-modules-and-chips/importing-from-jlcpcb) or [KiCad](https://docs.tscircuit.com/guides/importing-modules-and-chips/importing-from-kicad)","Any module you push to the [registry](https://tscircuit.com/trending) will have [simple image urls](https://docs.tscircuit.com/web-apis/image-generation-api) you can use display images on a website","The default [Parts Engine](https://docs.tscircuit.com/guides/platform-configuration) will automatically find parts from common vendors for your BOM",'[Pin selectors](https://docs.tscircuit.com/guides/using-sel-references) are similar to CSS selectors, ".R1 > .pin1" means "connect to the first pin of the component R1"',"You can use the [sel](https://docs.tscircuit.com/guides/using-sel-references) object to select pins in a type-safe way","Publish modules via the [registry](https://tscircuit.com/trending) for working with a team or sharing your work","[Explore tutorials](https://docs.tscircuit.com/category/tutorials) for real-world circuit design examples.","Upload your Circuit JSON to [circuitjson.com](https://circuitjson.com) for a quick preview.","You can display Circuit JSON in 3D, PCB or Schematic mode with the [<CircuitJsonPreview />](https://docs.tscircuit.com/guides/running-tscircuit/displaying-circuit-json-on-a-webpage#react-display-all-available-previews-with-circuitjsonpreview-) React component","Use a [<group />](https://docs.tscircuit.com/elements/group) element to move multiple components at once in a schematic or PCB layout.","Check out the [GitHub Discussions page](https://github.com/tscircuit/tscircuit/discussions) to upvote features","You can customize the autorouter using the [autorouter prop](https://docs.tscircuit.com/elements/board#setting-the-autorouter)","Use the [<constraint />](https://docs.tscircuit.com/footprints/constraint) element to enforce geometric relationships in PCB designs.","When working on component placement and circuit design, autorouting can slow down your iteration cycle. Use [routingDisabled](https://docs.tscircuit.com/elements/board#disabling-routing-with-routingdisabled) on the <board /> element to disable autorouting temporarily.","Join the [Discord server](https://tscircuit.com/join) to discuss issues and get help directly from the community."],mFn=(()=>{let t=Dat[Math.floor(Math.random()*Dat.length)];return t=t.replace(/</g,"<"),t=t.replace(/>/g,">"),t=t.replace(new RegExp('(?<!href=")(?<!\\()(?<!\\]\\()(https?:\\/\\/[^\\s\\)\\]]+)',"g"),(e,n)=>`<a class="rf-text-blue-500 rf-underline" href="${e}" target="_blank">${e}</a>`),t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/g,'<a class="rf-text-blue-500 rf-underline" href="$2" target="_blank">$1</a>'),t})(),B9=({onRunClicked:t})=>j.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-justify-center rf-h-full rf-bg-gray-50 rf-text-gray-500 rf-p-4",children:[j.jsx(oTn,{className:"rf-size-14 rf-mb-4"}),j.jsxs("p",{className:"rf-text-md rf-break-words rf-max-w-xl rf-text-center",children:["Tip: ",j.jsx("span",{dangerouslySetInnerHTML:{__html:mFn}})]}),t&&j.jsxs(sc,{className:"rf-mt-4 rf-bg-blue-600 rf-hover:bg-blue-500",onClick:t,children:["Run Code",j.jsx(bnt,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),dG=({text:t,onClick:e})=>j.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:e,children:t}),hG=t=>j.jsxs("div",{className:"rf-leading-5",children:[j.jsx("div",{className:"rf-py-2 rf-font-bold",children:t.column.name}),j.jsx("div",{children:t.field?.()??j.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:e=>{t.onTextChange?.(e.target.value)}})})]}),pFn=({open:t,children:e,title:n,onClose:o})=>t?j.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-justify-center rf-items-center rf-z-50",onClick:o,children:j.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:r=>{r.preventDefault(),r.stopPropagation()},children:[j.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:n}),j.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:o,children:"×"}),e]})}):null,fFn=({elements:t})=>{const[e,n]=G.useState({open:!1}),[o,r]=G.useReducer((u,_)=>({...u,..._}),{}),i=[...new Set(t.map(u=>u.type))],s=t.map(u=>{const _=u[`${u.type}_id`],d=Object.fromEntries(Object.entries(u).filter(([h])=>!(h===`${u.type}_id`||!h.endsWith("_id")))),m=Object.fromEntries(Object.entries(u).filter(([h])=>!h.endsWith("_id")));return{primary_id:_,other_ids:d,...m,_og_elm:u}}),a=s.map(u=>{let _="";const d=m=>{const h=Object.keys(m.other_ids).find(f=>f.startsWith("source_"));if(!h)return`.${m.name}`;const p=h.slice(0,-3),x=s.find(f=>f.type===p&&f.primary_id===m.other_ids[h]);return x?"name"in x?`${d(x)} > .${m.name}`:`#${x.primary_id} > .${m.name}`:`??? > .${m.name}`};return"name"in u&&(_=d(u)),{...u,selector_path:_}}),c=[{key:"primary_id",name:"primary_id",renderCell:u=>j.jsxs("div",{className:"rf-flex rf-items-center",children:[j.jsx(dG,{text:u.primary_id,onClick:()=>r({focused_id:u.primary_id,id_search:void 0,selector_search:void 0})}),j.jsx("span",{className:"rf-flex-grow"}),j.jsx(dG,{text:"(JSON)",onClick:()=>n({open:!0,element:u._og_elm,title:u.primary_id})})]}),renderHeaderCell:u=>j.jsx(hG,{column:u,onTextChange:_=>r({id_search:_}),field:o.focused_id?()=>j.jsxs("div",{children:["Focus:"," ",j.jsx("span",{className:"rf-underline",children:o.focused_id}),j.jsx(dG,{text:"(unfocus)",onClick:()=>r({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:u=>j.jsx(hG,{column:u,field:()=>j.jsxs("select",{onChange:_=>r({component_type_filter:_.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[j.jsx("option",{value:"any",children:"any"},"any"),j.jsx("option",{value:"source",children:"source"},"source"),j.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),j.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),i.map(_=>j.jsx("option",{value:_,children:_},_))]})})},{key:"name",name:"name",renderHeaderCell:u=>j.jsx(hG,{column:u,onTextChange:_=>r({name_search:_})})},{key:"selector_path",name:"selector_path",renderHeaderCell:u=>j.jsx(hG,{column:u,onTextChange:_=>r({selector_search:_})})},{key:"other_ids",name:"other_ids",renderCell:u=>j.jsx("div",{className:"rf-space-x-2",children:Object.entries(u.other_ids).map(([_,d])=>j.jsx(dG,{text:d,onClick:()=>r({focused_id:d})},d))})}],l=a.filter(u=>o.name_search?u.name?.toLowerCase()?.includes(o.name_search.toLowerCase()):!0).filter(u=>!o.component_type_filter||o.component_type_filter==="any"?!0:o.component_type_filter==="source"?u.type.startsWith("source_"):o.component_type_filter==="source/pcb"?u.type.startsWith("source_")||u.type.startsWith("pcb_"):o.component_type_filter==="source/schematic"?u.type.startsWith("source_")||u.type.startsWith("schematic_"):u.type?.includes(o.component_type_filter)).filter(u=>o.selector_search?o.selector_search.split(" ").filter(d=>d.length>0).every(d=>u.selector_path?.includes(d)):!0).filter(u=>o.id_search?u.primary_id?.includes(o.id_search):!0).filter(u=>!!(!o.focused_id||u.primary_id===o.focused_id||Object.values(u.other_ids).includes(o.focused_id)));return j.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[j.jsx("div",{className:"rf-overflow-x-auto",children:j.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[j.jsx("thead",{children:j.jsx("tr",{children:c.map(u=>j.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:u.renderHeaderCell?u.renderHeaderCell(u):u.name},u.key))})}),j.jsx("tbody",{children:l.map((u,_)=>j.jsx("tr",{className:"rf-hover:bg-gray-100",children:c.map(d=>j.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:d.renderCell?d.renderCell(u):u[d.key]},d.key))},_))})]})}),j.jsx(pFn,{open:e.open,onClose:()=>n({open:!1}),title:e.open?e.title:"",children:j.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:j.jsx("pre",{className:"rf-whitespace-pre-wrap",children:e.open?JSON.stringify(e.element,null,2):""})})})]})};var EH={},zxe={},Aat;function xFn(){return Aat||(Aat=1,(function(t){Object.defineProperty(t,"__esModule",{value:!0});var e=(function(){function i(s,a){var c=[],l=!0,u=!1,_=void 0;try{for(var d=s[Symbol.iterator](),m;!(l=(m=d.next()).done)&&(c.push(m.value),!(a&&c.length===a));l=!0);}catch(h){u=!0,_=h}finally{try{!l&&d.return&&d.return()}finally{if(u)throw _}}return c}return function(s,a){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return i(s,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();t.default=o,t.parseUnitObj=r;var n=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function o(i){var s=parseFloat(i),a=i.match(n)||[],c=a.length>0?i.substr(a[0].length).trim():"";return[s,c]}function r(i){var s=o(i),a=e(s,2),c=a[0],l=a[1];return{val:c,unit:l}}})(zxe)),zxe}var Rat;function gFn(){if(Rat)return EH;Rat=1,Object.defineProperty(EH,"__esModule",{value:!0});var t=(function(){function c(l,u){var _=[],d=!0,m=!1,h=void 0;try{for(var p=l[Symbol.iterator](),x;!(d=(x=p.next()).done)&&(_.push(x.value),!(u&&_.length===u));d=!0);}catch(f){m=!0,h=f}finally{try{!d&&p.return&&p.return()}finally{if(m)throw h}}return _}return function(l,u){if(Array.isArray(l))return l;if(Symbol.iterator in Object(l))return c(l,u);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();EH.formatSI=i,EH.unformatSI=a;function e(c){return c&&c.__esModule?c:{default:c}}var n=xFn(),o=e(n),r={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function i(c){if(c===0)return"0";for(var l=Math.abs(c),u=0;l>=1e3&&u<24;)l/=1e3,u+=3;for(;l<1&&u>-24;)l*=1e3,u-=3;var _=c<0?"-":"";return l>1e3?_+l.toFixed(0)+r[u]:_+parseFloat(l.toPrecision(3))+r[u]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function a(c){if(c==null||c==="")return NaN;var l=(0,o.default)(c),u=t(l,2),_=u[0],d=u[1],m=s[d];return _*m}return EH}var yFn=gFn(),mG={exports:{}};var PFn=mG.exports,kat;function bFn(){return kat||(kat=1,(function(t,e){((n,o)=>{t.exports=o()})(PFn,function n(){var o=typeof self<"u"?self:typeof window<"u"?window:o!==void 0?o:{},r,i=!o.document&&!!o.postMessage,s=o.IS_PAPA_WORKER||!1,a={},c=0,l={};function u(w){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(D){var A=v(D);A.chunkSize=parseInt(A.chunkSize),D.step||D.chunk||(A.chunkSize=null),this._handle=new p(A),(this._handle.streamer=this)._config=A}).call(this,w),this.parseChunk=function(D,A){var I=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<I){let O=this._config.newline;O||(H=this._config.quoteChar||'"',O=this._handle.guessLineEndings(D,H)),D=[...D.split(O).slice(I)].join(O)}this.isFirstChunk&&M(this._config.beforeFirstChunk)&&(H=this._config.beforeFirstChunk(D))!==void 0&&(D=H),this.isFirstChunk=!1,this._halted=!1;var I=this._partialLine+D,H=(this._partialLine="",this._handle.parse(I,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(D=H.meta.cursor,I=(this._finished||(this._partialLine=I.substring(D-this._baseIndex),this._baseIndex=D),H&&H.data&&(this._rowCount+=H.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)o.postMessage({results:H,workerId:l.WORKER_ID,finished:I});else if(M(this._config.chunk)&&!A){if(this._config.chunk(H,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=H=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(H.data),this._completeResults.errors=this._completeResults.errors.concat(H.errors),this._completeResults.meta=H.meta),this._completed||!I||!M(this._config.complete)||H&&H.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),I||H&&H.meta.paused||this._nextChunk(),H}this._halted=!0},this._sendError=function(D){M(this._config.error)?this._config.error(D):s&&this._config.error&&o.postMessage({workerId:l.WORKER_ID,error:D,finished:!1})}}function _(w){var D;(w=w||{}).chunkSize||(w.chunkSize=l.RemoteChunkSize),u.call(this,w),this._nextChunk=i?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(A){this._input=A,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(D=new XMLHttpRequest,this._config.withCredentials&&(D.withCredentials=this._config.withCredentials),i||(D.onload=S(this._chunkLoaded,this),D.onerror=S(this._chunkError,this)),D.open(this._config.downloadRequestBody?"POST":"GET",this._input,!i),this._config.downloadRequestHeaders){var A,I=this._config.downloadRequestHeaders;for(A in I)D.setRequestHeader(A,I[A])}var H;this._config.chunkSize&&(H=this._start+this._config.chunkSize-1,D.setRequestHeader("Range","bytes="+this._start+"-"+H));try{D.send(this._config.downloadRequestBody)}catch(O){this._chunkError(O.message)}i&&D.status===0&&this._chunkError()}},this._chunkLoaded=function(){D.readyState===4&&(D.status<200||400<=D.status?this._chunkError():(this._start+=this._config.chunkSize||D.responseText.length,this._finished=!this._config.chunkSize||this._start>=(A=>(A=A.getResponseHeader("Content-Range"))!==null?parseInt(A.substring(A.lastIndexOf("/")+1)):-1)(D),this.parseChunk(D.responseText)))},this._chunkError=function(A){A=D.statusText||A,this._sendError(new Error(A))}}function d(w){(w=w||{}).chunkSize||(w.chunkSize=l.LocalChunkSize),u.call(this,w);var D,A,I=typeof FileReader<"u";this.stream=function(H){this._input=H,A=H.slice||H.webkitSlice||H.mozSlice,I?((D=new FileReader).onload=S(this._chunkLoaded,this),D.onerror=S(this._chunkError,this)):D=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var H=this._input,O=(this._config.chunkSize&&(O=Math.min(this._start+this._config.chunkSize,this._input.size),H=A.call(H,this._start,O)),D.readAsText(H,this._config.encoding));I||this._chunkLoaded({target:{result:O}})},this._chunkLoaded=function(H){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(H.target.result)},this._chunkError=function(){this._sendError(D.error)}}function m(w){var D;u.call(this,w=w||{}),this.stream=function(A){return D=A,this._nextChunk()},this._nextChunk=function(){var A,I;if(!this._finished)return A=this._config.chunkSize,D=A?(I=D.substring(0,A),D.substring(A)):(I=D,""),this._finished=!D,this.parseChunk(I)}}function h(w){u.call(this,w=w||{});var D=[],A=!0,I=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(H){this._input=H,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){I&&D.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),D.length?this.parseChunk(D.shift()):A=!0},this._streamData=S(function(H){try{D.push(typeof H=="string"?H:H.toString(this._config.encoding)),A&&(A=!1,this._checkIsFinished(),this.parseChunk(D.shift()))}catch(O){this._streamError(O)}},this),this._streamError=S(function(H){this._streamCleanUp(),this._sendError(H)},this),this._streamEnd=S(function(){this._streamCleanUp(),I=!0,this._streamData("")},this),this._streamCleanUp=S(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function p(w){var D,A,I,H,O=Math.pow(2,53),B=-O,z=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,X=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,q=this,K=0,oe=0,ce=!1,Z=!1,ne=[],ie={data:[],errors:[],meta:{}};function ae(De){return w.skipEmptyLines==="greedy"?De.join("").trim()==="":De.length===1&&De[0].length===0}function he(){if(ie&&I&&(Ce("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+l.DefaultDelimiter+"'"),I=!1),w.skipEmptyLines&&(ie.data=ie.data.filter(function(xe){return!ae(xe)})),Pe()){let xe=function(Ve,We){M(w.transformHeader)&&(Ve=w.transformHeader(Ve,We)),ne.push(Ve)};if(ie)if(Array.isArray(ie.data[0])){for(var De=0;Pe()&&De<ie.data.length;De++)ie.data[De].forEach(xe);ie.data.splice(0,1)}else ie.data.forEach(xe)}function me(xe,Ve){for(var We=w.header?{}:[],Ge=0;Ge<xe.length;Ge++){var fe=Ge,Xe=xe[Ge],Xe=((Le,ke)=>(Be=>(w.dynamicTypingFunction&&w.dynamicTyping[Be]===void 0&&(w.dynamicTyping[Be]=w.dynamicTypingFunction(Be)),(w.dynamicTyping[Be]||w.dynamicTyping)===!0))(Le)?ke==="true"||ke==="TRUE"||ke!=="false"&&ke!=="FALSE"&&((Be=>{if(z.test(Be)&&(Be=parseFloat(Be),B<Be&&Be<O))return 1})(ke)?parseFloat(ke):X.test(ke)?new Date(ke):ke===""?null:ke):ke)(fe=w.header?Ge>=ne.length?"__parsed_extra":ne[Ge]:fe,Xe=w.transform?w.transform(Xe,fe):Xe);fe==="__parsed_extra"?(We[fe]=We[fe]||[],We[fe].push(Xe)):We[fe]=Xe}return w.header&&(Ge>ne.length?Ce("FieldMismatch","TooManyFields","Too many fields: expected "+ne.length+" fields but parsed "+Ge,oe+Ve):Ge<ne.length&&Ce("FieldMismatch","TooFewFields","Too few fields: expected "+ne.length+" fields but parsed "+Ge,oe+Ve)),We}var Me;ie&&(w.header||w.dynamicTyping||w.transform)&&(Me=1,!ie.data.length||Array.isArray(ie.data[0])?(ie.data=ie.data.map(me),Me=ie.data.length):ie.data=me(ie.data,0),w.header&&ie.meta&&(ie.meta.fields=ne),oe+=Me)}function Pe(){return w.header&&ne.length===0}function Ce(De,me,Me,xe){De={type:De,code:me,message:Me},xe!==void 0&&(De.row=xe),ie.errors.push(De)}M(w.step)&&(H=w.step,w.step=function(De){ie=De,Pe()?he():(he(),ie.data.length!==0&&(K+=De.data.length,w.preview&&K>w.preview?A.abort():(ie.data=ie.data[0],H(ie,q))))}),this.parse=function(De,me,Me){var xe=w.quoteChar||'"',xe=(w.newline||(w.newline=this.guessLineEndings(De,xe)),I=!1,w.delimiter?M(w.delimiter)&&(w.delimiter=w.delimiter(De),ie.meta.delimiter=w.delimiter):((xe=((Ve,We,Ge,fe,Xe)=>{var Le,ke,Be,Re;Xe=Xe||[","," ","|",";",l.RECORD_SEP,l.UNIT_SEP];for(var be=0;be<Xe.length;be++){for(var Ee,we=Xe[be],Fe=0,$e=0,Qe=0,nt=(Be=void 0,new f({comments:fe,delimiter:we,newline:We,preview:10}).parse(Ve)),it=0;it<nt.data.length;it++)Ge&&ae(nt.data[it])?Qe++:(Ee=nt.data[it].length,$e+=Ee,Be===void 0?Be=Ee:0<Ee&&(Fe+=Math.abs(Ee-Be),Be=Ee));0<nt.data.length&&($e/=nt.data.length-Qe),(ke===void 0||Fe<=ke)&&(Re===void 0||Re<$e)&&1.99<$e&&(ke=Fe,Le=we,Re=$e)}return{successful:!!(w.delimiter=Le),bestDelimiter:Le}})(De,w.newline,w.skipEmptyLines,w.comments,w.delimitersToGuess)).successful?w.delimiter=xe.bestDelimiter:(I=!0,w.delimiter=l.DefaultDelimiter),ie.meta.delimiter=w.delimiter),v(w));return w.preview&&w.header&&xe.preview++,D=De,A=new f(xe),ie=A.parse(D,me,Me),he(),ce?{meta:{paused:!0}}:ie||{meta:{paused:!1}}},this.paused=function(){return ce},this.pause=function(){ce=!0,A.abort(),D=M(w.chunk)?"":D.substring(A.getCharIndex())},this.resume=function(){q.streamer._halted?(ce=!1,q.streamer.parseChunk(D,!0)):setTimeout(q.resume,3)},this.aborted=function(){return Z},this.abort=function(){Z=!0,A.abort(),ie.meta.aborted=!0,M(w.complete)&&w.complete(ie),D=""},this.guessLineEndings=function(Ve,xe){Ve=Ve.substring(0,1048576);var xe=new RegExp(x(xe)+"([^]*?)"+x(xe),"gm"),Me=(Ve=Ve.replace(xe,"")).split("\r"),xe=Ve.split(`
|
|
@@ -5695,7 +5695,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5695
5695
|
// Add more specific assertions based on expected output
|
|
5696
5696
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5697
5697
|
})
|
|
5698
|
-
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:r,children:[j.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&&j.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:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},Blt=t=>t.activeSubSolver?[t,...Blt(t.activeSubSolver)]:[t],tjn=({solver:t})=>{const e=Blt(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(ejn,{solver:n})]},n.constructor.name))})},njn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=G.useReducer(p=>!p,!1),a=G.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),r&&r(t))},u=()=>{i?(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(),r&&t.solved&&r(t);return}t.step(),e()},n))},_=()=>{const p=t;if(p.getCurrentPhase&&!t.solved&&!t.failed){const x=p.getCurrentPhase();for(;p.getCurrentPhase()===x&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||i)return;const p=window.prompt("Step until which iteration?",`${t.iterations}`);if(p===null)return;const x=Number(p);if(!Number.isFinite(x)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<x&&!t.solved&&!t.failed;)t.step();e(),t.solved&&r&&r(t)};G.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),G.useEffect(()=>{(t.solved||t.failed)&&i&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,i]);const m=t.getCurrentPhase!==void 0,h=m?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(tjn,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:c,disabled:t.solved||t.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),j.jsx("button",{onClick:d,disabled:t.solved||t.failed||i,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"}),m&&j.jsx("button",{onClick:_,disabled:t.solved||t.failed||i,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:h})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},ojn=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},rjn=(t,e)=>{const o=t.pipelineDef[e].solverName,r=ojn(t,e),i=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(r==="Completed"){const d=t.pipelineDef[e+1],m=d?t.firstIterationOfPhase?.[d.solverName]:void 0;m!==void 0&&s!==null?c=m-s:s!==null&&(c=a-s)}else r==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let u=0;r==="Completed"?u=1:r==="In Progress"&&i&&(u=i.progress??0);const _=i?.stats??null;return{index:e,name:o,status:r,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:_&&Object.keys(_).length>0?_:null,solverInstance:i??null}},ijn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},sjn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ajn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),cjn=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=ajn(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>j.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Nge=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Nge);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Nge(o));return e},ljn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Nge(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=`${e}_input.json`,i.click(),URL.revokeObjectURL(r)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},ujn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>rjn(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):ljn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>r(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:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(ijn,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(sjn,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(cjn,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>i(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},_jn=class extends rr.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 djn({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],r=t.circles??[],i=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(x,f)=>{typeof x=="number"&&(x<s&&(s=x),x>c&&(c=x)),typeof f=="number"&&(f<a&&(a=f),f>l&&(l=f))};for(const x of e)u(x.x,x.y);for(const x of n){const f=x.points??[];for(const g of f)u(g.x,g.y)}for(const x of o){const f=x.x??0,g=x.y??0,y=x.width??0,P=x.height??0;u(f,g),u(f+y,g+P)}for(const x of r){const f=x.x??0,g=x.y??0,y=x.radius??1;u(f-y,g-y),u(f+y,g+y)}for(const x of i)u(x.x,x.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const _=10,d=s-_,m=a-_,h=Math.max(1,c-s+2*_),p=Math.max(1,l-a+2*_);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${m} ${h} ${p}`,role:"img","aria-label":"Graphics fallback",children:[o.map((x,f)=>j.jsx("rect",{x:x.x??0,y:x.y??0,width:x.width??0,height:x.height??0,fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`rect-${f}`)),n.map((x,f)=>j.jsx("polyline",{fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1,points:(x.points??[]).map(g=>`${g.x??0},${g.y??0}`).join(" ")},`line-${f}`)),r.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.fillColor??"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`circle-${f}`)),e.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.color??"black"},`point-${f}`)),i.map((x,f)=>j.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var hjn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=G.useReducer(u=>u+1,0),s=G.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),a=G.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);G.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const _=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&_.currentPipelineStepIndex<=_.pipelineDef.findIndex(d=>d.solverName===u);)t.step();i()}};return j.jsxs("div",{children:[j.jsx(njn,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(_jn,{fallback:j.jsx(djn,{graphics:s}),children:j.jsx(ZXn,{graphics:s})}),c&&j.jsx(ujn,{solver:t,onStepUntilPhase:l})]})};const mjn=()=>{G.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)},[])},pjn=t=>t.toLowerCase().includes("pack")?nTn:t.toLowerCase().includes("rout")?aTn:VMn,fjn=({solverEvents:t=[]})=>{const[e,n]=G.useState(null);mjn();const o=G.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),r=G.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=G.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=gie[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(gie).join(", ")}`,classFound:!1};try{const c=i.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}}},[i]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.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."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.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:[r.length," ",r.length===1?"Solver":"Solvers"]}),r.map(a=>{const c=o.get(a),l=e===a;return j.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 u=pjn(c.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?j.jsx(f5,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:j.jsx(hjn,{solver:s.instance})}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&j.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:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(i.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},zlt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{G.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{lW.captureException(o)}catch{}}},[t,e]),G.useEffect(()=>{if(n&&n.length>0)for(const o of n){const r=new Error(o.message||"Circuit JSON Error");o.stack&&(r.stack=o.stack);try{lW.captureException(r,{error_type:o.type})}catch{}}},[n])},Vlt="0.0.1903",xjn={version:Vlt},JG=XHe()(jHe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),gjn=t=>{const[e,n]=G.useState([]),[o,r]=G.useState(null),[i,s]=G.useState(""),[a,c]=gT("eval-version-selection",null),l=JG(m=>m.setLastRunEvalVersion),u=JG(m=>m.lastRunEvalVersion);return G.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(m=>m.json()).then(m=>{if(Array.isArray(m?.versions)){let h=[...m.versions];m.tags?.latest&&(r(m.tags.latest),h=h.filter(p=>p!==m.tags.latest)),n(h)}}).catch(()=>{})},[t]),G.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:G.useMemo(()=>e.filter(m=>m.includes(i)).slice(0,50),[e,i]),latestVersion:o,lastRunEvalVersion:u,search:i,setSearch:s,selectVersion:m=>{c(m),s("")}}},yjn=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[r,i]=G.useState(""),[s,a]=G.useState("");if(!o)return null;const c=t.filter(_=>_.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),u=_=>{_.key==="Enter"&&(c.length===1?i(c[0]):l&&i(s))};return j.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:j.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[j.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),j.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:_=>a(_.target.value),onKeyDown:u}),j.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>j.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${r===_?"bg-blue-50":""}`,onClick:()=>i(_),children:_},_)),l&&j.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${r===s?"bg-blue-50":""}`,onClick:()=>i(s),children:['Create new "',s,'"']})]}),j.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[j.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),j.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:()=>r&&e(r),disabled:!r,children:r===s?`Create "${r}"`:`Save to ${r}`})]})]})})},Pjn=t=>{const e=G.useRef(null),n=j0(o=>o.recentEvents);G.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 bjn(t){const e=vjn(t),n=G.forwardRef((o,r)=>{const{children:i,...s}=o,a=G.Children.toArray(i),c=a.find(Cjn);if(c){const l=c.props.children,u=a.map(_=>_===c?G.Children.count(l)>1?G.Children.only(null):G.isValidElement(l)?l.props.children:null:_);return j.jsx(e,{...s,ref:r,children:G.isValidElement(l)?G.cloneElement(l,void 0,u):null})}return j.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function vjn(t){const e=G.forwardRef((n,o)=>{const{children:r,...i}=n;if(G.isValidElement(r)){const s=Tjn(r),a=Mjn(i,r.props);return r.type!==G.Fragment&&(a.ref=o?Sx(o,s):s),G.cloneElement(r,a)}return G.Children.count(r)>1?G.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var Sjn=Symbol("radix.slottable");function Cjn(t){return G.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Sjn}function Mjn(t,e){const n={...e};for(const o in e){const r=t[o],i=e[o];/^on[A-Z]/.test(o)?r&&i?n[o]=(...a)=>{const c=i(...a);return r(...a),c}:r&&(n[o]=r):o==="style"?n[o]={...r,...i}:o==="className"&&(n[o]=[r,i].filter(Boolean).join(" "))}return{...t,...n}}function Tjn(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 KG="Dialog",[$lt,Wlt]=n4(KG),[wjn,E4]=$lt(KG),Ult=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!0}=t,a=G.useRef(null),c=G.useRef(null),[l,u]=xb({prop:o,defaultProp:r??!1,onChange:i,caller:KG});return j.jsx(wjn,{scope:e,triggerRef:a,contentRef:c,contentId:$p(),titleId:$p(),descriptionId:$p(),open:l,onOpenChange:u,onOpenToggle:G.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};Ult.displayName=KG;var Xlt="DialogTrigger",jlt=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(Xlt,n),i=G0(e,r.triggerRef);return j.jsx(yc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Lge(r.open),...o,ref:i,onClick:Or(t.onClick,r.onOpenToggle)})});jlt.displayName=Xlt;var Hge="DialogPortal",[Ejn,Glt]=$lt(Hge,{forceMount:void 0}),Ylt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=E4(Hge,e);return j.jsx(Ejn,{scope:e,forceMount:n,children:G.Children.map(o,s=>j.jsx(Ag,{present:n||i.open,children:j.jsx(gj,{asChild:!0,container:r,children:s})}))})};Ylt.displayName=Hge;var QG="DialogOverlay",qlt=G.forwardRef((t,e)=>{const n=Glt(QG,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=E4(QG,t.__scopeDialog);return i.modal?j.jsx(Ag,{present:o||i.open,children:j.jsx(Ajn,{...r,ref:e})}):null});qlt.displayName=QG;var Djn=bjn("DialogOverlay.RemoveScroll"),Ajn=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(QG,n);return j.jsx(Tj,{as:Djn,allowPinchZoom:!0,shards:[r.contentRef],children:j.jsx(yc.div,{"data-state":Lge(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),zS="DialogContent",Jlt=G.forwardRef((t,e)=>{const n=Glt(zS,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=E4(zS,t.__scopeDialog);return j.jsx(Ag,{present:o||i.open,children:i.modal?j.jsx(Rjn,{...r,ref:e}):j.jsx(kjn,{...r,ref:e})})});Jlt.displayName=zS;var Rjn=G.forwardRef((t,e)=>{const n=E4(zS,t.__scopeDialog),o=G.useRef(null),r=G0(e,n.contentRef,o);return G.useEffect(()=>{const i=o.current;if(i)return E2e(i)},[]),j.jsx(Klt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Or(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Or(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:Or(t.onFocusOutside,i=>i.preventDefault())})}),kjn=G.forwardRef((t,e)=>{const n=E4(zS,t.__scopeDialog),o=G.useRef(!1),r=G.useRef(!1);return j.jsx(Klt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{t.onCloseAutoFocus?.(i),i.defaultPrevented||(o.current||n.triggerRef.current?.focus(),i.preventDefault()),o.current=!1,r.current=!1},onInteractOutside:i=>{t.onInteractOutside?.(i),i.defaultPrevented||(o.current=!0,i.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const s=i.target;n.triggerRef.current?.contains(s)&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&r.current&&i.preventDefault()}})}),Klt=G.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=E4(zS,n),c=G.useRef(null),l=G0(e,c);return l2e(),j.jsxs(j.Fragment,{children:[j.jsx(ij,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:j.jsx(FN,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Lge(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),j.jsxs(j.Fragment,{children:[j.jsx(Hjn,{titleId:a.titleId}),j.jsx(Ljn,{contentRef:c,descriptionId:a.descriptionId})]})]})}),Ige="DialogTitle",Qlt=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(Ige,n);return j.jsx(yc.h2,{id:r.titleId,...o,ref:e})});Qlt.displayName=Ige;var Zlt="DialogDescription",e0t=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(Zlt,n);return j.jsx(yc.p,{id:r.descriptionId,...o,ref:e})});e0t.displayName=Zlt;var t0t="DialogClose",n0t=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(t0t,n);return j.jsx(yc.button,{type:"button",...o,ref:e,onClick:Or(t.onClick,()=>r.onOpenChange(!1))})});n0t.displayName=t0t;function Lge(t){return t?"open":"closed"}var o0t="DialogTitleWarning",[Njn,r0t]=Iqt(o0t,{contentName:zS,titleName:Ige,docsSlug:"dialog"}),Hjn=({titleId:t})=>{const e=r0t(o0t),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5698
|
+
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:r,children:[j.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&&j.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:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},Blt=t=>t.activeSubSolver?[t,...Blt(t.activeSubSolver)]:[t],tjn=({solver:t})=>{const e=Blt(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(ejn,{solver:n})]},n.constructor.name))})},njn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=G.useReducer(p=>!p,!1),a=G.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),r&&r(t))},u=()=>{i?(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(),r&&t.solved&&r(t);return}t.step(),e()},n))},_=()=>{const p=t;if(p.getCurrentPhase&&!t.solved&&!t.failed){const x=p.getCurrentPhase();for(;p.getCurrentPhase()===x&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||i)return;const p=window.prompt("Step until which iteration?",`${t.iterations}`);if(p===null)return;const x=Number(p);if(!Number.isFinite(x)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<x&&!t.solved&&!t.failed;)t.step();e(),t.solved&&r&&r(t)};G.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),G.useEffect(()=>{(t.solved||t.failed)&&i&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,i]);const m=t.getCurrentPhase!==void 0,h=m?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(tjn,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:c,disabled:t.solved||t.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),j.jsx("button",{onClick:d,disabled:t.solved||t.failed||i,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"}),m&&j.jsx("button",{onClick:_,disabled:t.solved||t.failed||i,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:h})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},ojn=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},rjn=(t,e)=>{const o=t.pipelineDef[e].solverName,r=ojn(t,e),i=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(r==="Completed"){const d=t.pipelineDef[e+1],m=d?t.firstIterationOfPhase?.[d.solverName]:void 0;m!==void 0&&s!==null?c=m-s:s!==null&&(c=a-s)}else r==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let u=0;r==="Completed"?u=1:r==="In Progress"&&i&&(u=i.progress??0);const _=i?.stats??null;return{index:e,name:o,status:r,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:_&&Object.keys(_).length>0?_:null,solverInstance:i??null}},ijn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},sjn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},ajn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),cjn=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=ajn(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>j.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Nge=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Nge);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Nge(o));return e},ljn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Nge(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=`${e}_input.json`,i.click(),URL.revokeObjectURL(r)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},ujn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>rjn(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):ljn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>r(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:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(ijn,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(sjn,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(cjn,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>i(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.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"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},_jn=class extends rr.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 djn({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],r=t.circles??[],i=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(x,f)=>{typeof x=="number"&&(x<s&&(s=x),x>c&&(c=x)),typeof f=="number"&&(f<a&&(a=f),f>l&&(l=f))};for(const x of e)u(x.x,x.y);for(const x of n){const f=x.points??[];for(const g of f)u(g.x,g.y)}for(const x of o){const f=x.x??0,g=x.y??0,y=x.width??0,P=x.height??0;u(f,g),u(f+y,g+P)}for(const x of r){const f=x.x??0,g=x.y??0,y=x.radius??1;u(f-y,g-y),u(f+y,g+y)}for(const x of i)u(x.x,x.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const _=10,d=s-_,m=a-_,h=Math.max(1,c-s+2*_),p=Math.max(1,l-a+2*_);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${m} ${h} ${p}`,role:"img","aria-label":"Graphics fallback",children:[o.map((x,f)=>j.jsx("rect",{x:x.x??0,y:x.y??0,width:x.width??0,height:x.height??0,fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`rect-${f}`)),n.map((x,f)=>j.jsx("polyline",{fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1,points:(x.points??[]).map(g=>`${g.x??0},${g.y??0}`).join(" ")},`line-${f}`)),r.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.fillColor??"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`circle-${f}`)),e.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.color??"black"},`point-${f}`)),i.map((x,f)=>j.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var hjn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=G.useReducer(u=>u+1,0),s=G.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),a=G.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);G.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const _=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&_.currentPipelineStepIndex<=_.pipelineDef.findIndex(d=>d.solverName===u);)t.step();i()}};return j.jsxs("div",{children:[j.jsx(njn,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(_jn,{fallback:j.jsx(djn,{graphics:s}),children:j.jsx(ZXn,{graphics:s})}),c&&j.jsx(ujn,{solver:t,onStepUntilPhase:l})]})};const mjn=()=>{G.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)},[])},pjn=t=>t.toLowerCase().includes("pack")?nTn:t.toLowerCase().includes("rout")?aTn:VMn,fjn=({solverEvents:t=[]})=>{const[e,n]=G.useState(null);mjn();const o=G.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),r=G.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=G.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=gie[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(gie).join(", ")}`,classFound:!1};try{const c=i.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}}},[i]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.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."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.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:[r.length," ",r.length===1?"Solver":"Solvers"]}),r.map(a=>{const c=o.get(a),l=e===a;return j.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 u=pjn(c.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?j.jsx(f5,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:j.jsx(hjn,{solver:s.instance})}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&j.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:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(i.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},zlt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{G.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{lW.captureException(o)}catch{}}},[t,e]),G.useEffect(()=>{if(n&&n.length>0)for(const o of n){const r=new Error(o.message||"Circuit JSON Error");o.stack&&(r.stack=o.stack);try{lW.captureException(r,{error_type:o.type})}catch{}}},[n])},Vlt="0.0.1904",xjn={version:Vlt},JG=XHe()(jHe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),gjn=t=>{const[e,n]=G.useState([]),[o,r]=G.useState(null),[i,s]=G.useState(""),[a,c]=gT("eval-version-selection",null),l=JG(m=>m.setLastRunEvalVersion),u=JG(m=>m.lastRunEvalVersion);return G.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(m=>m.json()).then(m=>{if(Array.isArray(m?.versions)){let h=[...m.versions];m.tags?.latest&&(r(m.tags.latest),h=h.filter(p=>p!==m.tags.latest)),n(h)}}).catch(()=>{})},[t]),G.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:G.useMemo(()=>e.filter(m=>m.includes(i)).slice(0,50),[e,i]),latestVersion:o,lastRunEvalVersion:u,search:i,setSearch:s,selectVersion:m=>{c(m),s("")}}},yjn=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[r,i]=G.useState(""),[s,a]=G.useState("");if(!o)return null;const c=t.filter(_=>_.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),u=_=>{_.key==="Enter"&&(c.length===1?i(c[0]):l&&i(s))};return j.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:j.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[j.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),j.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:_=>a(_.target.value),onKeyDown:u}),j.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>j.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${r===_?"bg-blue-50":""}`,onClick:()=>i(_),children:_},_)),l&&j.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${r===s?"bg-blue-50":""}`,onClick:()=>i(s),children:['Create new "',s,'"']})]}),j.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[j.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),j.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:()=>r&&e(r),disabled:!r,children:r===s?`Create "${r}"`:`Save to ${r}`})]})]})})},Pjn=t=>{const e=G.useRef(null),n=j0(o=>o.recentEvents);G.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 bjn(t){const e=vjn(t),n=G.forwardRef((o,r)=>{const{children:i,...s}=o,a=G.Children.toArray(i),c=a.find(Cjn);if(c){const l=c.props.children,u=a.map(_=>_===c?G.Children.count(l)>1?G.Children.only(null):G.isValidElement(l)?l.props.children:null:_);return j.jsx(e,{...s,ref:r,children:G.isValidElement(l)?G.cloneElement(l,void 0,u):null})}return j.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function vjn(t){const e=G.forwardRef((n,o)=>{const{children:r,...i}=n;if(G.isValidElement(r)){const s=Tjn(r),a=Mjn(i,r.props);return r.type!==G.Fragment&&(a.ref=o?Sx(o,s):s),G.cloneElement(r,a)}return G.Children.count(r)>1?G.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var Sjn=Symbol("radix.slottable");function Cjn(t){return G.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Sjn}function Mjn(t,e){const n={...e};for(const o in e){const r=t[o],i=e[o];/^on[A-Z]/.test(o)?r&&i?n[o]=(...a)=>{const c=i(...a);return r(...a),c}:r&&(n[o]=r):o==="style"?n[o]={...r,...i}:o==="className"&&(n[o]=[r,i].filter(Boolean).join(" "))}return{...t,...n}}function Tjn(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 KG="Dialog",[$lt,Wlt]=n4(KG),[wjn,E4]=$lt(KG),Ult=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!0}=t,a=G.useRef(null),c=G.useRef(null),[l,u]=xb({prop:o,defaultProp:r??!1,onChange:i,caller:KG});return j.jsx(wjn,{scope:e,triggerRef:a,contentRef:c,contentId:$p(),titleId:$p(),descriptionId:$p(),open:l,onOpenChange:u,onOpenToggle:G.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};Ult.displayName=KG;var Xlt="DialogTrigger",jlt=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(Xlt,n),i=G0(e,r.triggerRef);return j.jsx(yc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Lge(r.open),...o,ref:i,onClick:Or(t.onClick,r.onOpenToggle)})});jlt.displayName=Xlt;var Hge="DialogPortal",[Ejn,Glt]=$lt(Hge,{forceMount:void 0}),Ylt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=E4(Hge,e);return j.jsx(Ejn,{scope:e,forceMount:n,children:G.Children.map(o,s=>j.jsx(Ag,{present:n||i.open,children:j.jsx(gj,{asChild:!0,container:r,children:s})}))})};Ylt.displayName=Hge;var QG="DialogOverlay",qlt=G.forwardRef((t,e)=>{const n=Glt(QG,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=E4(QG,t.__scopeDialog);return i.modal?j.jsx(Ag,{present:o||i.open,children:j.jsx(Ajn,{...r,ref:e})}):null});qlt.displayName=QG;var Djn=bjn("DialogOverlay.RemoveScroll"),Ajn=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(QG,n);return j.jsx(Tj,{as:Djn,allowPinchZoom:!0,shards:[r.contentRef],children:j.jsx(yc.div,{"data-state":Lge(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),zS="DialogContent",Jlt=G.forwardRef((t,e)=>{const n=Glt(zS,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=E4(zS,t.__scopeDialog);return j.jsx(Ag,{present:o||i.open,children:i.modal?j.jsx(Rjn,{...r,ref:e}):j.jsx(kjn,{...r,ref:e})})});Jlt.displayName=zS;var Rjn=G.forwardRef((t,e)=>{const n=E4(zS,t.__scopeDialog),o=G.useRef(null),r=G0(e,n.contentRef,o);return G.useEffect(()=>{const i=o.current;if(i)return E2e(i)},[]),j.jsx(Klt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Or(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Or(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:Or(t.onFocusOutside,i=>i.preventDefault())})}),kjn=G.forwardRef((t,e)=>{const n=E4(zS,t.__scopeDialog),o=G.useRef(!1),r=G.useRef(!1);return j.jsx(Klt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{t.onCloseAutoFocus?.(i),i.defaultPrevented||(o.current||n.triggerRef.current?.focus(),i.preventDefault()),o.current=!1,r.current=!1},onInteractOutside:i=>{t.onInteractOutside?.(i),i.defaultPrevented||(o.current=!0,i.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const s=i.target;n.triggerRef.current?.contains(s)&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&r.current&&i.preventDefault()}})}),Klt=G.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=E4(zS,n),c=G.useRef(null),l=G0(e,c);return l2e(),j.jsxs(j.Fragment,{children:[j.jsx(ij,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:j.jsx(FN,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Lge(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),j.jsxs(j.Fragment,{children:[j.jsx(Hjn,{titleId:a.titleId}),j.jsx(Ljn,{contentRef:c,descriptionId:a.descriptionId})]})]})}),Ige="DialogTitle",Qlt=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(Ige,n);return j.jsx(yc.h2,{id:r.titleId,...o,ref:e})});Qlt.displayName=Ige;var Zlt="DialogDescription",e0t=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(Zlt,n);return j.jsx(yc.p,{id:r.descriptionId,...o,ref:e})});e0t.displayName=Zlt;var t0t="DialogClose",n0t=G.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=E4(t0t,n);return j.jsx(yc.button,{type:"button",...o,ref:e,onClick:Or(t.onClick,()=>r.onOpenChange(!1))})});n0t.displayName=t0t;function Lge(t){return t?"open":"closed"}var o0t="DialogTitleWarning",[Njn,r0t]=Iqt(o0t,{contentName:zS,titleName:Ige,docsSlug:"dialog"}),Hjn=({titleId:t})=>{const e=r0t(o0t),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5699
5699
|
|
|
5700
5700
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5701
5701
|
|
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.
|
|
5
|
+
"version": "0.0.1906",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/preview.js",
|
|
8
8
|
"./preview": "./dist/preview.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@tscircuit/file-server": "^0.0.32",
|
|
54
54
|
"@tscircuit/internal-dynamic-import": "^0.0.0",
|
|
55
55
|
"@tscircuit/pcb-viewer": "1.11.368",
|
|
56
|
-
"@tscircuit/schematic-viewer": "^2.0.
|
|
56
|
+
"@tscircuit/schematic-viewer": "^2.0.60",
|
|
57
57
|
"@types/bun": "latest",
|
|
58
58
|
"@types/debug": "^4.1.12",
|
|
59
59
|
"@types/react": "^19.1.10",
|