tscircuit 0.0.1194-libonly → 0.0.1195-libonly

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.
@@ -5307,7 +5307,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
5307
5307
  50% { opacity: 0.2; }
5308
5308
  100% { opacity: 0.6; }
5309
5309
  }
5310
- `,o.appendChild(u)}})}};n();const s=new MutationObserver(n);return s.observe(o,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,e,A,i])},Bee=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],h2t=t=>{const{svgDivRef:A,circuitJson:e,circuitJsonKey:i,showGroups:o}=t;j.useEffect(()=>{if(A.current&&A.current.querySelectorAll(".schematic-group-overlay").forEach(r=>r.remove()),!A.current||!o||!e||e.length===0)return;const n=setTimeout(()=>{if(!A.current)return;const s=A.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove());try{const a=Kp(e).source_group?.list().filter(u=>!u.is_subcircuit)||[],g=Kp(e).schematic_component?.list()||[],I=new Map;a.forEach(u=>{const d=u;if(d.parent_source_group_id){const f=I.get(d.parent_source_group_id)||[];f.push(u.source_group_id),I.set(d.parent_source_group_id,f)}});const c=u=>{const d=[],f=I.get(u)||[];for(const m of f)d.push(m),d.push(...c(m));return d},B=u=>{const d=a.find(f=>f.source_group_id===u);return d?.parent_source_group_id?1+B(d.parent_source_group_id):0},l=a.length>0&&a.some(u=>u.name&&u.name.trim()!=="");let C=[];if(l){const u=new Map;for(const d of g){const f=Kp(e).source_component.get(d.source_component_id);f?.source_group_id&&(u.has(f.source_group_id)||u.set(f.source_group_id,[]),u.get(f.source_group_id).push(d))}a.forEach((d,f)=>{let m=u.get(d.source_group_id)||[];const S=c(d.source_group_id);for(const D of S){const x=u.get(D)||[];m=[...m,...x]}if(m.length>0){const D=B(d.source_group_id),x=c(d.source_group_id).length>0;if(d.name?.startsWith("unnamed_board"))return;C.push({id:d.source_group_id,name:d.name||`Group ${f+1}`,components:m,color:Bee[f%Bee.length],depthLevel:D,hasChildren:x,sourceGroupId:d.source_group_id})}})}const Q=s.viewBox.baseVal,E=s.getBoundingClientRect(),h=Math.min(E.width/Q.width,E.height/Q.height)||1;C.sort((u,d)=>u.depthLevel-d.depthLevel),C.forEach(u=>{if(u.components.length===0)return;const d=u2t(u.components,s);if(!d)return;const f=Math.max(8,Math.min(25,15/Math.max(h,.3))),m=u.hasChildren?f*.6:0,S=f+m,D=Math.max(1,2/Math.max(h,.5)),x=u.depthLevel===0?D:D*.7,F=Math.max(4,8/Math.max(h,.5)),k=u.hasChildren?1.3:1,v=F*k,_=v*.5,H=document.createElementNS("http://www.w3.org/2000/svg","rect");H.setAttribute("class","schematic-group-overlay"),H.setAttribute("x",(d.minX-S).toString()),H.setAttribute("y",(d.minY-S).toString()),H.setAttribute("width",(d.maxX-d.minX+S*2).toString()),H.setAttribute("height",(d.maxY-d.minY+S*2).toString()),H.setAttribute("fill","none"),H.setAttribute("stroke",u.color),H.setAttribute("stroke-width",x.toString()),H.setAttribute("stroke-dasharray",`${v},${_}`),H.setAttribute("opacity","0.8"),H.setAttribute("rx","0"),H.setAttribute("ry","0");const P=Math.max(6,Math.min(20,14/Math.max(h,.2))),J=u.depthLevel===0||u.depthLevel===1?0:u.depthLevel*.2,W=P*(1-J),Z=Math.max(1,W*.2),AA=u.name,nA=document.createElementNS("http://www.w3.org/2000/svg","text");nA.setAttribute("font-size",W.toString()),nA.setAttribute("font-family","Arial, sans-serif"),nA.textContent=AA,s.appendChild(nA);const gA=nA.getBBox();s.removeChild(nA);const tA=gA.width+Z*2,iA=W+Z*2,rA=d.minX-S,CA=d.minY-S-iA,dA=document.createElementNS("http://www.w3.org/2000/svg","rect");dA.setAttribute("class","schematic-group-overlay"),dA.setAttribute("x",rA.toString()),dA.setAttribute("y",(CA-iA).toString()),dA.setAttribute("width",tA.toString()),dA.setAttribute("height",iA.toString()),dA.setAttribute("fill","transparent"),dA.setAttribute("rx","0"),dA.setAttribute("ry","0");const SA=document.createElementNS("http://www.w3.org/2000/svg","text");SA.setAttribute("class","schematic-group-overlay"),SA.setAttribute("x",(rA+Z).toString()),SA.setAttribute("y",(CA+iA-Z).toString()),SA.setAttribute("fill",u.color),SA.setAttribute("font-size",W.toString()),SA.setAttribute("font-family","Arial, sans-serif"),SA.setAttribute("font-weight",u.depthLevel===0?"600":"500"),SA.setAttribute("stroke",u.color),SA.setAttribute("stroke-width",Math.max(.2,W*.02).toString()),SA.textContent=AA,s.appendChild(H),s.appendChild(dA),s.appendChild(SA)})}catch(a){console.error("Error creating group overlays:",a)}},10);return()=>clearTimeout(n)},[A,i,o])};function u2t(t,A){let e=1/0,i=1/0,o=-1/0,n=-1/0;for(const r of t){let a=A.querySelector(`g[data-schematic-component-id="${r.schematic_component_id}"]`);if(a||(a=A.querySelector(`[data-schematic-component-id="${r.schematic_component_id}"]`)),a){const g=a.getBBox();e=Math.min(e,g.x),i=Math.min(i,g.y),o=Math.max(o,g.x+g.width),n=Math.max(n,g.y+g.height)}}return e===1/0?null:{minX:e,minY:i,maxX:o,maxY:n}}var d2t=Ia("schematic-viewer"),p2t=()=>{Ia.enable("schematic-viewer*")},f2t=d2t,lee=t=>{const[A,e]=j.useState(0),[i,o]=j.useState(0);return j.useEffect(()=>{if(!t.current)return;const n=()=>{const r=t.current?.getBoundingClientRect();e(r?.width||0),o(r?.height||0)};n();const s=new ResizeObserver(n);return s.observe(t.current),window.addEventListener("resize",n),()=>{s.disconnect(),window.removeEventListener("resize",n)}},[]),{containerWidth:A,containerHeight:i}},y2t=f2t.extend("useComponentDragging"),w2t=({onEditEvent:t,editEvents:A=[],circuitJson:e,cancelDrag:i,svgToScreenProjection:o,realToSvgProjection:n,enabled:s=!1,snapToGrid:r=!1})=>{const[a,g]=j.useState(null),I=jB(n,o),c=j.useRef(null),B=j.useRef(null),l=j.useRef(new Map);j.useEffect(()=>{A.forEach(D=>{"edit_event_type"in D&&D.edit_event_type==="edit_schematic_component_location"&&!D.in_progress&&l.current.set(D.schematic_component_id,{...D.new_center})})},[A]);const C=j.useCallback((D,x,F)=>{if(!s)return!1;const k=F.closest('[data-circuit-json-type="schematic_component"]');if(!k)return!1;const v=k.getAttribute("data-schematic-component-id");if(!v)return!1;i&&i();const _=Kp(e).schematic_component.get(v);if(!_)return!1;c.current={x:D,y:x};let H;const P=l.current.get(v);if(P)H={...P};else{const W=cee({editEvents:A,schematic_component_id:v});H={x:_.center.x+W.x,y:_.center.y+W.y},l.current.set(v,{...H})}const J={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:v,original_center:H,new_center:{...H},in_progress:!0,created_at:Date.now(),_element:k};return B.current=J,g(J),!0},[i,s,e,A]),Q=j.useCallback(D=>{C(D.clientX,D.clientY,D.target)},[C]),E=j.useCallback(D=>{if(D.touches.length!==1)return;const x=D.touches[0];C(x.clientX,x.clientY,D.target)&&D.preventDefault()},[C]),h=j.useCallback((D,x)=>{if(!B.current||!c.current)return;const F={x:D-c.current.x,y:x-c.current.y},k={x:F.x/I.a,y:F.y/I.d};let v={x:B.current.original_center.x+k.x,y:B.current.original_center.y+k.y};if(r){const H=P=>Math.round(P*10)/10;v={x:H(v.x),y:H(v.y)}}const _={...B.current,new_center:v};B.current=_,g(_)},[I,r]),u=j.useCallback(D=>h(D.clientX,D.clientY),[h]),d=j.useCallback(D=>{if(D.touches.length!==1||!B.current)return;D.preventDefault();const x=D.touches[0];h(x.clientX,x.clientY)},[h]),f=j.useCallback(()=>{if(!B.current)return;const D={...B.current,in_progress:!1};l.current.set(D.schematic_component_id,{...D.new_center}),y2t("endDrag calling onEditEvent with new edit event",{newEditEvent:D}),t&&t(D),B.current=null,c.current=null,g(null)},[t]),m=j.useCallback(()=>f(),[f]),S=j.useCallback(()=>f(),[f]);return j.useEffect(()=>(window.addEventListener("mousemove",u),window.addEventListener("mouseup",m),window.addEventListener("touchmove",d,{passive:!1}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",u),window.removeEventListener("mouseup",m),window.removeEventListener("touchmove",d),window.removeEventListener("touchend",S)}),[u,m,d,S]),{handleMouseDown:Q,handleTouchStart:E,isDragging:!!B.current,activeEditEvent:a}},gk={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47},m2t=({onClick:t,active:A})=>{const e=i=>{i.preventDefault(),t()};return O.jsx("div",{onClick:e,onTouchEnd:e,title:A?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:A?"#4CAF50":"#fff",color:A?"#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:gk.schematicEditIcon},children:O.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[O.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),O.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},D2t=({onClick:t,active:A})=>{const e=i=>{i.preventDefault(),t()};return O.jsx("div",{onClick:e,onTouchEnd:e,title:A?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:A?"#4CAF50":"#fff",color:A?"#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:gk.schematicGridIcon},children:O.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:O.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},S2t=({onClick:t,active:A})=>{const e=i=>{i.preventDefault(),t()};return O.jsx("div",{onClick:e,onTouchEnd:e,title:A?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:A?"#4CAF50":"#fff",color:A?"#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:gk.viewMenuIcon},children:O.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[O.jsx("circle",{cx:"12",cy:"12",r:"1"}),O.jsx("circle",{cx:"12",cy:"5",r:"1"}),O.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},b2t={version:"2.0.51"},x2t=({circuitJson:t,circuitJsonKey:A,isVisible:e,onClose:i,showGroups:o,onToggleGroups:n})=>{const s=j.useMemo(()=>{if(!t||t.length===0)return!1;try{if((Kp(t).source_group?.list()||[]).length>0)return!0;const a=Kp(t).schematic_component?.list()||[];if(a.length>1){const g=new Set;for(const I of a){const c=Kp(t).source_component.get(I.source_component_id);c?.ftype&&g.add(c.ftype)}return g.size>1}return!1}catch(r){return console.error("Error checking for groups:",r),!1}},[A]);return e?O.jsxs(O.Fragment,{children:[O.jsx("div",{onClick:i,onTouchEnd:r=>{r.preventDefault(),i()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:gk.viewMenuBackdrop}}),O.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:gk.viewMenu},children:[O.jsxs("div",{onClick:()=>{s&&n(!o)},onTouchEnd:r=>{r.preventDefault(),s&&n(!o)},style:{padding:"8px 12px",cursor:s?"pointer":"not-allowed",opacity:s?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:r=>{s&&(r.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:r=>{s&&(r.currentTarget.style.backgroundColor="transparent")},children:[O.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:o&&"✓"}),"View Schematic Groups"]}),!s&&O.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),O.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(b2t?.version)]})]})]}):null},k2t=()=>O.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),G2t=({onClick:t})=>O.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:gk.spiceSimulationIcon},children:O.jsx(k2t,{})});VW.register(t2t,n2t,v1t,_1t,q1t,X1t,T1t);var $W=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],Cee=t=>{if(t===0)return"0s";const A=Math.abs(t);let e="s",i=1;return A<1e-12?(e="fs",i=1e15):A<1e-9?(e="ps",i=1e12):A<1e-6?(e="ns",i=1e9):A<.001?(e="us",i=1e6):A<1&&(e="ms",i=1e3),`${parseFloat((t*i).toPrecision(3))}${e}`},F2t=({plotData:t,nodes:A,isLoading:e,error:i,hasRun:o})=>{const n=j.useMemo(()=>{const a=A.some(I=>I.toLowerCase().startsWith("v(")),g=A.some(I=>I.toLowerCase().startsWith("i("));return a&&g?"Value":a?"Voltage (V)":g?"Current (A)":"Value"},[A]);if(e)return O.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!o)return O.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(i)return O.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",i]});if(t.length===0)return O.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:A.map((a,g)=>({label:a,data:t.map(I=>({x:Number(I.name),y:I[a]})),borderColor:$W[g%$W.length],backgroundColor:$W[g%$W.length],fill:!1,tension:.1}))},r={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:a=>{if(a.length>0){const g=a[0];return Cee(g.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:a=>Cee(a),font:{family:"sans-serif"}}},y:{title:{display:!0,text:n,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return O.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:O.jsx(C2t,{options:r,data:s})})},R2t=({spiceString:t,onClose:A,plotData:e,nodes:i,isLoading:o,error:n,simOptions:s,onSimOptionsChange:r,hasRun:a})=>{const[g,I]=j.useState(String(s.startTime)),[c,B]=j.useState(String(s.duration));j.useEffect(()=>{I(String(s.startTime)),B(String(s.duration))},[s.startTime,s.duration]);const l=()=>{r({...s,startTime:Number(g),duration:Number(c)})},C=i.filter(Q=>{const E=Q.toLowerCase().startsWith("v("),h=Q.toLowerCase().startsWith("i(");return!!(s.showVoltage&&E||s.showCurrent&&h)});return O.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:O.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[O.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[O.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),O.jsx("button",{onClick:A,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),O.jsx("div",{children:O.jsx(F2t,{plotData:e,nodes:C,isLoading:o,error:n,hasRun:a})}),O.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[O.jsxs("div",{style:{display:"flex",gap:"16px"},children:[O.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[O.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:Q=>r({...s,showVoltage:Q.target.checked})}),"Voltage"]}),O.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[O.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:Q=>r({...s,showCurrent:Q.target.checked})}),"Current"]})]}),O.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[O.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),O.jsx("input",{id:"startTime",type:"number",value:g,onChange:Q=>I(Q.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),O.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),O.jsx("input",{id:"duration",type:"number",value:c,onChange:Q=>B(Q.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),O.jsx("button",{onClick:l,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:a?"Rerun":"Run"})]})]}),O.jsxs("div",{style:{marginTop:"24px"},children:[O.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),O.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})]})]})})},M2t="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",AZ=null,N2t=()=>{if(typeof window>"u")return null;if(AZ)return AZ;try{const t=new Blob([atob(M2t)],{type:"application/javascript"});return AZ=URL.createObjectURL(t),AZ}catch(t){return console.error("Failed to create blob URL for worker",t),null}},_2t=t=>{const A={};if(t.dataType==="real")t.data.forEach(r=>{A[r.name]=r.values});else if(t.dataType==="complex")t.data.forEach(r=>{A[r.name]=r.values.map(a=>a.real)});else throw new Error("Unsupported data type in simulation result");const e=Object.keys(A).find(r=>r.toLowerCase()==="time"||r.toLowerCase()==="frequency");if(!e)throw new Error("No time or frequency data in simulation result");const i=A[e],o=Object.keys(A).filter(r=>r!==e),n=o;return{plotData:i.map((r,a)=>{const g={name:r.toExponential(2)};return o.forEach(I=>{g[I]=A[I][a]}),g}),nodes:n}},v2t=t=>{const[A,e]=j.useState([]),[i,o]=j.useState([]),[n,s]=j.useState(!0),[r,a]=j.useState(null);return j.useEffect(()=>{if(!t){s(!1),e([]),o([]),a(null);return}s(!0),a(null),e([]),o([]);const g=N2t();if(!g){a("Could not create SPICE simulation worker."),s(!1);return}const I=new Worker(g,{type:"module"});return I.onmessage=c=>{if(c.data.type==="result")try{const{plotData:B,nodes:l}=_2t(c.data.result);e(B),o(l)}catch(B){a(B.message||"Failed to parse simulation result"),console.error(B)}else c.data.type==="error"&&a(c.data.error);s(!1)},I.onerror=c=>{a(c.message),s(!1)},I.postMessage({spiceString:t}),()=>{I.terminate()}},[t]),{plotData:A,nodes:i,isLoading:n,error:r}},QhA=t=>{if(t===0)return"0";const A=Math.abs(t),e=i=>i.toPrecision(4);return A>=1?e(t):A>=.001?`${e(t*1e3)}m`:A>=1e-6?`${e(t*1e6)}u`:A>=1e-9?`${e(t*1e9)}n`:A>=1e-12?`${e(t*1e12)}p`:A>=1e-15?`${e(t*1e15)}f`:t.toExponential(3)},U2t=(t,A)=>{const i=ovA(t).toSpiceString(),n=i.split(`
5310
+ `,o.appendChild(u)}})}};n();const s=new MutationObserver(n);return s.observe(o,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,e,A,i])},Bee=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],h2t=t=>{const{svgDivRef:A,circuitJson:e,circuitJsonKey:i,showGroups:o}=t;j.useEffect(()=>{if(A.current&&A.current.querySelectorAll(".schematic-group-overlay").forEach(r=>r.remove()),!A.current||!o||!e||e.length===0)return;const n=setTimeout(()=>{if(!A.current)return;const s=A.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove());try{const a=Kp(e).source_group?.list().filter(u=>!u.is_subcircuit)||[],g=Kp(e).schematic_component?.list()||[],I=new Map;a.forEach(u=>{const d=u;if(d.parent_source_group_id){const f=I.get(d.parent_source_group_id)||[];f.push(u.source_group_id),I.set(d.parent_source_group_id,f)}});const c=u=>{const d=[],f=I.get(u)||[];for(const m of f)d.push(m),d.push(...c(m));return d},B=u=>{const d=a.find(f=>f.source_group_id===u);return d?.parent_source_group_id?1+B(d.parent_source_group_id):0},l=a.length>0&&a.some(u=>u.name&&u.name.trim()!=="");let C=[];if(l){const u=new Map;for(const d of g){const f=Kp(e).source_component.get(d.source_component_id);f?.source_group_id&&(u.has(f.source_group_id)||u.set(f.source_group_id,[]),u.get(f.source_group_id).push(d))}a.forEach((d,f)=>{let m=u.get(d.source_group_id)||[];const S=c(d.source_group_id);for(const D of S){const x=u.get(D)||[];m=[...m,...x]}if(m.length>0){const D=B(d.source_group_id),x=c(d.source_group_id).length>0;if(d.name?.startsWith("unnamed_board"))return;C.push({id:d.source_group_id,name:d.name||`Group ${f+1}`,components:m,color:Bee[f%Bee.length],depthLevel:D,hasChildren:x,sourceGroupId:d.source_group_id})}})}const Q=s.viewBox.baseVal,E=s.getBoundingClientRect(),h=Math.min(E.width/Q.width,E.height/Q.height)||1;C.sort((u,d)=>u.depthLevel-d.depthLevel),C.forEach(u=>{if(u.components.length===0)return;const d=u2t(u.components,s);if(!d)return;const f=Math.max(8,Math.min(25,15/Math.max(h,.3))),m=u.hasChildren?f*.6:0,S=f+m,D=Math.max(1,2/Math.max(h,.5)),x=u.depthLevel===0?D:D*.7,F=Math.max(4,8/Math.max(h,.5)),k=u.hasChildren?1.3:1,v=F*k,_=v*.5,H=document.createElementNS("http://www.w3.org/2000/svg","rect");H.setAttribute("class","schematic-group-overlay"),H.setAttribute("x",(d.minX-S).toString()),H.setAttribute("y",(d.minY-S).toString()),H.setAttribute("width",(d.maxX-d.minX+S*2).toString()),H.setAttribute("height",(d.maxY-d.minY+S*2).toString()),H.setAttribute("fill","none"),H.setAttribute("stroke",u.color),H.setAttribute("stroke-width",x.toString()),H.setAttribute("stroke-dasharray",`${v},${_}`),H.setAttribute("opacity","0.8"),H.setAttribute("rx","0"),H.setAttribute("ry","0");const P=Math.max(6,Math.min(20,14/Math.max(h,.2))),J=u.depthLevel===0||u.depthLevel===1?0:u.depthLevel*.2,W=P*(1-J),Z=Math.max(1,W*.2),AA=u.name,nA=document.createElementNS("http://www.w3.org/2000/svg","text");nA.setAttribute("font-size",W.toString()),nA.setAttribute("font-family","Arial, sans-serif"),nA.textContent=AA,s.appendChild(nA);const gA=nA.getBBox();s.removeChild(nA);const tA=gA.width+Z*2,iA=W+Z*2,rA=d.minX-S,CA=d.minY-S-iA,dA=document.createElementNS("http://www.w3.org/2000/svg","rect");dA.setAttribute("class","schematic-group-overlay"),dA.setAttribute("x",rA.toString()),dA.setAttribute("y",(CA-iA).toString()),dA.setAttribute("width",tA.toString()),dA.setAttribute("height",iA.toString()),dA.setAttribute("fill","transparent"),dA.setAttribute("rx","0"),dA.setAttribute("ry","0");const SA=document.createElementNS("http://www.w3.org/2000/svg","text");SA.setAttribute("class","schematic-group-overlay"),SA.setAttribute("x",(rA+Z).toString()),SA.setAttribute("y",(CA+iA-Z).toString()),SA.setAttribute("fill",u.color),SA.setAttribute("font-size",W.toString()),SA.setAttribute("font-family","Arial, sans-serif"),SA.setAttribute("font-weight",u.depthLevel===0?"600":"500"),SA.setAttribute("stroke",u.color),SA.setAttribute("stroke-width",Math.max(.2,W*.02).toString()),SA.textContent=AA,s.appendChild(H),s.appendChild(dA),s.appendChild(SA)})}catch(a){console.error("Error creating group overlays:",a)}},10);return()=>clearTimeout(n)},[A,i,o])};function u2t(t,A){let e=1/0,i=1/0,o=-1/0,n=-1/0;for(const r of t){let a=A.querySelector(`g[data-schematic-component-id="${r.schematic_component_id}"]`);if(a||(a=A.querySelector(`[data-schematic-component-id="${r.schematic_component_id}"]`)),a){const g=a.getBBox();e=Math.min(e,g.x),i=Math.min(i,g.y),o=Math.max(o,g.x+g.width),n=Math.max(n,g.y+g.height)}}return e===1/0?null:{minX:e,minY:i,maxX:o,maxY:n}}var d2t=Ia("schematic-viewer"),p2t=()=>{Ia.enable("schematic-viewer*")},f2t=d2t,lee=t=>{const[A,e]=j.useState(0),[i,o]=j.useState(0);return j.useEffect(()=>{if(!t.current)return;const n=()=>{const r=t.current?.getBoundingClientRect();e(r?.width||0),o(r?.height||0)};n();const s=new ResizeObserver(n);return s.observe(t.current),window.addEventListener("resize",n),()=>{s.disconnect(),window.removeEventListener("resize",n)}},[]),{containerWidth:A,containerHeight:i}},y2t=f2t.extend("useComponentDragging"),w2t=({onEditEvent:t,editEvents:A=[],circuitJson:e,cancelDrag:i,svgToScreenProjection:o,realToSvgProjection:n,enabled:s=!1,snapToGrid:r=!1})=>{const[a,g]=j.useState(null),I=jB(n,o),c=j.useRef(null),B=j.useRef(null),l=j.useRef(new Map);j.useEffect(()=>{A.forEach(D=>{"edit_event_type"in D&&D.edit_event_type==="edit_schematic_component_location"&&!D.in_progress&&l.current.set(D.schematic_component_id,{...D.new_center})})},[A]);const C=j.useCallback((D,x,F)=>{if(!s)return!1;const k=F.closest('[data-circuit-json-type="schematic_component"]');if(!k)return!1;const v=k.getAttribute("data-schematic-component-id");if(!v)return!1;i&&i();const _=Kp(e).schematic_component.get(v);if(!_)return!1;c.current={x:D,y:x};let H;const P=l.current.get(v);if(P)H={...P};else{const W=cee({editEvents:A,schematic_component_id:v});H={x:_.center.x+W.x,y:_.center.y+W.y},l.current.set(v,{...H})}const J={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:v,original_center:H,new_center:{...H},in_progress:!0,created_at:Date.now(),_element:k};return B.current=J,g(J),!0},[i,s,e,A]),Q=j.useCallback(D=>{C(D.clientX,D.clientY,D.target)},[C]),E=j.useCallback(D=>{if(D.touches.length!==1)return;const x=D.touches[0];C(x.clientX,x.clientY,D.target)&&D.preventDefault()},[C]),h=j.useCallback((D,x)=>{if(!B.current||!c.current)return;const F={x:D-c.current.x,y:x-c.current.y},k={x:F.x/I.a,y:F.y/I.d};let v={x:B.current.original_center.x+k.x,y:B.current.original_center.y+k.y};if(r){const H=P=>Math.round(P*10)/10;v={x:H(v.x),y:H(v.y)}}const _={...B.current,new_center:v};B.current=_,g(_)},[I,r]),u=j.useCallback(D=>h(D.clientX,D.clientY),[h]),d=j.useCallback(D=>{if(D.touches.length!==1||!B.current)return;D.preventDefault();const x=D.touches[0];h(x.clientX,x.clientY)},[h]),f=j.useCallback(()=>{if(!B.current)return;const D={...B.current,in_progress:!1};l.current.set(D.schematic_component_id,{...D.new_center}),y2t("endDrag calling onEditEvent with new edit event",{newEditEvent:D}),t&&t(D),B.current=null,c.current=null,g(null)},[t]),m=j.useCallback(()=>f(),[f]),S=j.useCallback(()=>f(),[f]);return j.useEffect(()=>(window.addEventListener("mousemove",u),window.addEventListener("mouseup",m),window.addEventListener("touchmove",d,{passive:!1}),window.addEventListener("touchend",S),()=>{window.removeEventListener("mousemove",u),window.removeEventListener("mouseup",m),window.removeEventListener("touchmove",d),window.removeEventListener("touchend",S)}),[u,m,d,S]),{handleMouseDown:Q,handleTouchStart:E,isDragging:!!B.current,activeEditEvent:a}},gk={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47},m2t=({onClick:t,active:A})=>{const e=i=>{i.preventDefault(),t()};return O.jsx("div",{onClick:e,onTouchEnd:e,title:A?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:A?"#4CAF50":"#fff",color:A?"#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:gk.schematicEditIcon},children:O.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[O.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),O.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},D2t=({onClick:t,active:A})=>{const e=i=>{i.preventDefault(),t()};return O.jsx("div",{onClick:e,onTouchEnd:e,title:A?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:A?"#4CAF50":"#fff",color:A?"#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:gk.schematicGridIcon},children:O.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:O.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},S2t=({onClick:t,active:A})=>{const e=i=>{i.preventDefault(),t()};return O.jsx("div",{onClick:e,onTouchEnd:e,title:A?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:A?"#4CAF50":"#fff",color:A?"#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:gk.viewMenuIcon},children:O.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[O.jsx("circle",{cx:"12",cy:"12",r:"1"}),O.jsx("circle",{cx:"12",cy:"5",r:"1"}),O.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},b2t={version:"2.0.52"},x2t=({circuitJson:t,circuitJsonKey:A,isVisible:e,onClose:i,showGroups:o,onToggleGroups:n})=>{const s=j.useMemo(()=>{if(!t||t.length===0)return!1;try{if((Kp(t).source_group?.list()||[]).length>0)return!0;const a=Kp(t).schematic_component?.list()||[];if(a.length>1){const g=new Set;for(const I of a){const c=Kp(t).source_component.get(I.source_component_id);c?.ftype&&g.add(c.ftype)}return g.size>1}return!1}catch(r){return console.error("Error checking for groups:",r),!1}},[A]);return e?O.jsxs(O.Fragment,{children:[O.jsx("div",{onClick:i,onTouchEnd:r=>{r.preventDefault(),i()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:gk.viewMenuBackdrop}}),O.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:gk.viewMenu},children:[O.jsxs("div",{onClick:()=>{s&&n(!o)},onTouchEnd:r=>{r.preventDefault(),s&&n(!o)},style:{padding:"8px 12px",cursor:s?"pointer":"not-allowed",opacity:s?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:r=>{s&&(r.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:r=>{s&&(r.currentTarget.style.backgroundColor="transparent")},children:[O.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:o&&"✓"}),"View Schematic Groups"]}),!s&&O.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),O.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(b2t?.version)]})]})]}):null},k2t=()=>O.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),G2t=({onClick:t})=>O.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:gk.spiceSimulationIcon},children:O.jsx(k2t,{})});VW.register(t2t,n2t,v1t,_1t,q1t,X1t,T1t);var $W=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],Cee=t=>{if(t===0)return"0s";const A=Math.abs(t);let e="s",i=1;return A<1e-12?(e="fs",i=1e15):A<1e-9?(e="ps",i=1e12):A<1e-6?(e="ns",i=1e9):A<.001?(e="us",i=1e6):A<1&&(e="ms",i=1e3),`${parseFloat((t*i).toPrecision(3))}${e}`},F2t=({plotData:t,nodes:A,isLoading:e,error:i,hasRun:o})=>{const n=j.useMemo(()=>{const a=A.some(I=>I.toLowerCase().startsWith("v(")),g=A.some(I=>I.toLowerCase().startsWith("i("));return a&&g?"Value":a?"Voltage (V)":g?"Current (A)":"Value"},[A]);if(e)return O.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!o)return O.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(i)return O.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",i]});if(t.length===0)return O.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:A.map((a,g)=>({label:a,data:t.map(I=>({x:Number(I.name),y:I[a]})),borderColor:$W[g%$W.length],backgroundColor:$W[g%$W.length],fill:!1,tension:.1}))},r={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:a=>{if(a.length>0){const g=a[0];return Cee(g.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:a=>Cee(a),font:{family:"sans-serif"}}},y:{title:{display:!0,text:n,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return O.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:O.jsx(C2t,{options:r,data:s})})},R2t=({spiceString:t,onClose:A,plotData:e,nodes:i,isLoading:o,error:n,simOptions:s,onSimOptionsChange:r,hasRun:a})=>{const[g,I]=j.useState(String(s.startTime)),[c,B]=j.useState(String(s.duration));j.useEffect(()=>{I(String(s.startTime)),B(String(s.duration))},[s.startTime,s.duration]);const l=()=>{r({...s,startTime:Number(g),duration:Number(c)})},C=i.filter(Q=>{const E=Q.toLowerCase().startsWith("v("),h=Q.toLowerCase().startsWith("i(");return!!(s.showVoltage&&E||s.showCurrent&&h)});return O.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:O.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[O.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[O.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),O.jsx("button",{onClick:A,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),O.jsx("div",{children:O.jsx(F2t,{plotData:e,nodes:C,isLoading:o,error:n,hasRun:a})}),O.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[O.jsxs("div",{style:{display:"flex",gap:"16px"},children:[O.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[O.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:Q=>r({...s,showVoltage:Q.target.checked})}),"Voltage"]}),O.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[O.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:Q=>r({...s,showCurrent:Q.target.checked})}),"Current"]})]}),O.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[O.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),O.jsx("input",{id:"startTime",type:"number",value:g,onChange:Q=>I(Q.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),O.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),O.jsx("input",{id:"duration",type:"number",value:c,onChange:Q=>B(Q.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),O.jsx("button",{onClick:l,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:a?"Rerun":"Run"})]})]}),O.jsxs("div",{style:{marginTop:"24px"},children:[O.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),O.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})]})]})})},M2t="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",AZ=null,N2t=()=>{if(typeof window>"u")return null;if(AZ)return AZ;try{const t=new Blob([atob(M2t)],{type:"application/javascript"});return AZ=URL.createObjectURL(t),AZ}catch(t){return console.error("Failed to create blob URL for worker",t),null}},_2t=t=>{const A={};if(t.dataType==="real")t.data.forEach(r=>{A[r.name]=r.values});else if(t.dataType==="complex")t.data.forEach(r=>{A[r.name]=r.values.map(a=>a.real)});else throw new Error("Unsupported data type in simulation result");const e=Object.keys(A).find(r=>r.toLowerCase()==="time"||r.toLowerCase()==="frequency");if(!e)throw new Error("No time or frequency data in simulation result");const i=A[e],o=Object.keys(A).filter(r=>r!==e),n=o;return{plotData:i.map((r,a)=>{const g={name:r.toExponential(2)};return o.forEach(I=>{g[I]=A[I][a]}),g}),nodes:n}},v2t=t=>{const[A,e]=j.useState([]),[i,o]=j.useState([]),[n,s]=j.useState(!0),[r,a]=j.useState(null);return j.useEffect(()=>{if(!t){s(!1),e([]),o([]),a(null);return}s(!0),a(null),e([]),o([]);const g=N2t();if(!g){a("Could not create SPICE simulation worker."),s(!1);return}const I=new Worker(g,{type:"module"});return I.onmessage=c=>{if(c.data.type==="result")try{const{plotData:B,nodes:l}=_2t(c.data.result);e(B),o(l)}catch(B){a(B.message||"Failed to parse simulation result"),console.error(B)}else c.data.type==="error"&&a(c.data.error);s(!1)},I.onerror=c=>{a(c.message),s(!1)},I.postMessage({spiceString:t}),()=>{I.terminate()}},[t]),{plotData:A,nodes:i,isLoading:n,error:r}},QhA=t=>{if(t===0)return"0";const A=Math.abs(t),e=i=>i.toPrecision(4);return A>=1?e(t):A>=.001?`${e(t*1e3)}m`:A>=1e-6?`${e(t*1e6)}u`:A>=1e-9?`${e(t*1e9)}n`:A>=1e-12?`${e(t*1e12)}p`:A>=1e-15?`${e(t*1e15)}f`:t.toExponential(3)},U2t=(t,A)=>{const i=ovA(t).toSpiceString(),n=i.split(`
5311
5311
  `).filter(k=>k.trim()!=="").filter(k=>!k.startsWith("*")&&!k.startsWith(".")&&k.trim()!==""),s=new Set,r=new Set,a=new Set;for(const k of n){const v=k.trim().split(/\s+/);if(v.length<3)continue;const _=v[0],H=_[0].toUpperCase();let P=[];if(["R","C","L","V","I","D"].includes(H))P=v.slice(1,3),H==="V"&&a.add(_);else if(H==="Q"&&v.length>=4)P=v.slice(1,4);else if(H==="M"&&v.length>=5)P=v.slice(1,5);else if(H==="X")P=v.slice(1,-1);else continue;P.forEach(J=>s.add(J)),H==="C"&&P.forEach(J=>r.add(J))}s.delete("0"),r.delete("0");const g=Array.from(r).map(k=>`.ic V(${k})=0`),I=[],c=Array.from(s).map(k=>`V(${k})`);I.push(...c);const B=Array.from(a).map(k=>`I(${k})`);I.push(...B);const l=I.length>0?`.probe ${I.join(" ")}`:"",C=A?.startTime??0,Q=A?.duration??20,E=C*.001,h=Q*.001,u=E+h,d=h/50,f=`.tran ${QhA(d)} ${QhA(u)} ${QhA(E)} UIC`,m=".end",S=i.split(`
5312
5312
  `);let D=-1;for(let k=S.length-1;k>=0;k--)if(S[k].trim().toLowerCase().startsWith(m)){D=k;break}const x=[...g,l,f].filter(Boolean);let F;if(D!==-1){const k=S.slice(0,D),v=S.slice(D);F=[...k,...x,...v]}else F=[...S,...x,m];return F.join(`
5313
5313
  `)},L2t=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},H2t=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},EhA=j.createContext(null),Y2t=5,J2t=(t,A)=>!t&&!A?!0:!t||!A?!1:t.minX===A.minX&&t.maxX===A.maxX&&t.minY===A.minY&&t.maxY===A.maxY,T2t=({children:t})=>{if(j.useContext(EhA))return O.jsx(O.Fragment,{children:t});const e=j.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),i=j.useCallback(()=>{for(const c of e.current.subscribers)c()},[]),o=j.useCallback(()=>{const c=e.current.pointer,B=new Set;if(c)for(const[C,Q]of e.current.boundingBoxes){const E=Q.bounds;E&&c.x>=E.minX&&c.x<=E.maxX&&c.y>=E.minY&&c.y<=E.maxY&&B.add(C)}const l=e.current.hoveringIds;B.size===l.size&&[...B].every(C=>l.has(C))||(e.current.hoveringIds=B,i())},[i]),n=j.useCallback((c,B)=>{e.current.boundingBoxes.set(c,B),o()},[o]),s=j.useCallback((c,B)=>{const l=e.current.boundingBoxes.get(c);l&&J2t(l.bounds,B.bounds)&&l.onClick===B.onClick||(e.current.boundingBoxes.set(c,B),o())},[o]),r=j.useCallback(c=>{e.current.boundingBoxes.delete(c)&&o()},[o]),a=j.useCallback(c=>(e.current.subscribers.add(c),()=>{e.current.subscribers.delete(c)}),[]),g=j.useCallback(c=>e.current.hoveringIds.has(c),[]);j.useEffect(()=>{const c=Q=>{const{clientX:E,clientY:h}=Q,u=e.current.pointer;u&&u.x===E&&u.y===h||(e.current.pointer={x:E,y:h},o())},B=()=>{e.current.pointer!==null&&(e.current.pointer=null,e.current.mouseDownPosition=null,o())},l=Q=>{e.current.mouseDownPosition={x:Q.clientX,y:Q.clientY}},C=Q=>{const{clientX:E,clientY:h}=Q,u=e.current.mouseDownPosition;if(u&&Math.sqrt(Math.pow(E-u.x,2)+Math.pow(h-u.y,2))>Y2t){e.current.mouseDownPosition=null;return}e.current.mouseDownPosition=null;for(const d of e.current.boundingBoxes.values()){const f=d.bounds;f&&E>=f.minX&&E<=f.maxX&&h>=f.minY&&h<=f.maxY&&d.onClick?.(Q)}};return window.addEventListener("pointermove",c,{passive:!0}),window.addEventListener("pointerdown",c,{passive:!0}),window.addEventListener("pointerup",c,{passive:!0}),window.addEventListener("pointerleave",B),window.addEventListener("pointercancel",B),window.addEventListener("blur",B),window.addEventListener("mousedown",l,{passive:!0}),window.addEventListener("click",C,{passive:!0}),()=>{window.removeEventListener("pointermove",c),window.removeEventListener("pointerdown",c),window.removeEventListener("pointerup",c),window.removeEventListener("pointerleave",B),window.removeEventListener("pointercancel",B),window.removeEventListener("blur",B),window.removeEventListener("mousedown",l),window.removeEventListener("click",C)}},[o]);const I=j.useMemo(()=>({registerBoundingBox:n,updateBoundingBox:s,unregisterBoundingBox:r,subscribe:a,isHovering:g}),[n,s,r,a,g]);return O.jsx(EhA.Provider,{value:I,children:t})},K2t=t=>{const A=j.useContext(EhA);if(!A)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const e=j.useId(),i=j.useRef(t);i.current=t;const o=j.useMemo(()=>s=>{i.current.onClick?.(s)},[]);return j.useEffect(()=>(A.registerBoundingBox(e,{bounds:i.current.bounds,onClick:i.current.onClick?o:void 0}),()=>{A.unregisterBoundingBox(e)}),[A,o,e]),j.useEffect(()=>{A.updateBoundingBox(e,{bounds:i.current.bounds,onClick:i.current.onClick?o:void 0})},[A,o,e,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:j.useSyncExternalStore(A.subscribe,()=>A.isHovering(e),()=>!1)}},q2t=(t,A)=>!t&&!A?!0:!t||!A?!1:Math.abs(t.bounds.minX-A.bounds.minX)<.5&&Math.abs(t.bounds.maxX-A.bounds.maxX)<.5&&Math.abs(t.bounds.minY-A.bounds.minY)<.5&&Math.abs(t.bounds.maxY-A.bounds.maxY)<.5&&Math.abs(t.rect.left-A.rect.left)<.5&&Math.abs(t.rect.top-A.rect.top)<.5&&Math.abs(t.rect.width-A.rect.width)<.5&&Math.abs(t.rect.height-A.rect.height)<.5,P2t=({componentId:t,svgDivRef:A,containerRef:e,onComponentClick:i,onHoverChange:o,showOutline:n,circuitJsonKey:s})=>{const[r,a]=j.useState(null),g=j.useRef(null),I=j.useCallback(()=>{g.current=null;const E=A.current,h=e.current;if(!E||!h){a(S=>S&&null);return}const u=E.querySelector(`[data-schematic-component-id="${t}"]`);if(!u){a(S=>S&&null);return}const d=u.getBoundingClientRect(),f=h.getBoundingClientRect(),m={bounds:{minX:d.left,maxX:d.right,minY:d.top,maxY:d.bottom},rect:{left:d.left-f.left,top:d.top-f.top,width:d.width,height:d.height}};a(S=>q2t(S,m)?S:m)},[t,e,A]),c=j.useCallback(()=>{g.current===null&&(g.current=window.requestAnimationFrame(I))},[I]);j.useEffect(()=>{c()},[c,s]),j.useEffect(()=>{c();const E=A.current,h=e.current;if(!E||!h)return;const u=typeof ResizeObserver<"u"?new ResizeObserver(()=>{c()}):null;u?.observe(h),u?.observe(E);const d=typeof MutationObserver<"u"?new MutationObserver(()=>{c()}):null;return d?.observe(E,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{u?.disconnect(),d?.disconnect(),window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)}},[c,A,e]);const B=j.useCallback(E=>{i&&i(t,E)},[t,i]),l=r?.bounds??null,{hovering:C}=K2t({bounds:l,onClick:i?B:void 0});if(j.useEffect(()=>{o&&o(t,C)},[C,t,o]),!r||!C||!n)return null;const Q=r.rect;return O.jsx("div",{style:{position:"absolute",left:Q.left,top:Q.top,width:Q.width,height:Q.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:gk.schematicComponentHoverOutline}})},O2t=({circuitJson:t,containerStyle:A,editEvents:e=[],onEditEvent:i,defaultEditMode:o=!1,debugGrid:n=!1,editingEnabled:s=!1,debug:r=!1,clickToInteractEnabled:a=!1,colorOverrides:g,spiceSimulationEnabled:I=!1,disableGroups:c=!1,onSchematicComponentClicked:B})=>{r&&p2t();const[l,C]=j.useState(!1),[Q,E]=j.useState({showVoltage:!0,showCurrent:!1,startTime:0,duration:20}),h=BA=>`${BA?.length||0}_${BA?.editCount||0}`,u=j.useMemo(()=>h(t),[t]),d=j.useMemo(()=>{if(!I)return null;try{return U2t(t,Q)}catch(BA){return console.error("Failed to generate SPICE string",BA),null}},[u,I,Q.startTime,Q.duration]),[f,m]=j.useState(!1);j.useEffect(()=>{m(!1)},[u]);const{plotData:S,nodes:D,isLoading:x,error:F}=v2t(f?d:null),[k,v]=j.useState(o),[_,H]=j.useState(!0),[P,J]=j.useState(!a),[W,Z]=j.useState(!1),[AA,nA]=j.useState(()=>c?!1:L2t("schematic_viewer_show_groups",!1)),[gA,tA]=j.useState(!1),iA=j.useRef(new Set),rA=j.useCallback((BA,EA)=>{EA?iA.current.add(BA):iA.current.delete(BA),tA(iA.current.size>0)},[]),CA=j.useRef(null),dA=j.useRef(null),SA=j.useMemo(()=>{try{return Kp(t).schematic_component?.list()?.map(BA=>BA.schematic_component_id)??[]}catch(BA){return console.error("Failed to derive schematic component ids",BA),[]}},[u,t]),xA=BA=>{const EA=BA.touches[0];dA.current={x:EA.clientX,y:EA.clientY}},JA=BA=>{const EA=BA.changedTouches[0],vA=dA.current;if(!vA)return;const ne=Math.abs(EA.clientX-vA.x),Qe=Math.abs(EA.clientY-vA.y);ne<10&&Qe<10&&(BA.preventDefault(),J(!0)),dA.current=null},[lA,RA]=j.useState([]),uA=j.useRef(t);j.useEffect(()=>{const BA=h(t),EA=h(uA.current);BA!==EA&&(RA([]),uA.current=t)},[t]);const{ref:KA,cancelDrag:$A,transform:ge}=mH({onSetTransform(BA){CA.current&&(CA.current.style.transform=EG(BA))},enabled:P&&!l}),{containerWidth:yA,containerHeight:qA}=lee(KA),YA=j.useMemo(()=>!yA||!qA?"":DW(t,{width:yA,height:qA||720,grid:n?{cellSize:1,labelCells:!0}:void 0,colorOverrides:g}),[u,yA,qA]),UA=j.useMemo(()=>YA.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent",[YA]),OA=j.useMemo(()=>{if(!YA)return yd();const BA=YA.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return L4(BA)}catch(EA){return console.error(EA),yd()}},[YA]),FA=BA=>{RA(EA=>[...EA,BA]),i&&i(BA)},DA=j.useMemo(()=>[...e,...lA],[e,lA]),{handleMouseDown:TA,handleTouchStart:GA,isDragging:LA,activeEditEvent:PA}=w2t({onEditEvent:FA,cancelDrag:$A,realToSvgProjection:OA,svgToScreenProjection:ge,circuitJson:t,editEvents:DA,enabled:k&&P&&!l,snapToGrid:_});Q2t({svgDivRef:CA,editEvents:DA,realToSvgProjection:OA,svgToScreenProjection:ge,activeEditEvent:PA}),E2t({svgDivRef:CA,circuitJson:t,activeEditEvent:PA,editEvents:DA}),h2t({svgDivRef:CA,circuitJson:t,circuitJsonKey:u,showGroups:AA&&!c});const ie=j.useRef(GA);j.useEffect(()=>{ie.current=GA},[GA]);const mA=j.useMemo(()=>O.jsx("div",{ref:CA,style:{pointerEvents:a?P?"auto":"none":"auto",transformOrigin:"0 0"},className:B?"schematic-component-clickable":void 0,onTouchStart:BA=>{k&&P&&!l&&ie.current(BA)},dangerouslySetInnerHTML:{__html:YA}}),[YA,P,a,k,l]);return O.jsxs(T2t,{children:[B&&O.jsx("style",{children:".schematic-component-clickable [data-schematic-component-id]:hover { cursor: pointer !important; }"}),O.jsxs("div",{ref:KA,style:{position:"relative",backgroundColor:UA,overflow:"hidden",cursor:l?"auto":LA?"grabbing":a&&!P||gA&&B?"pointer":"grab",minHeight:"300px",...A},onWheelCapture:BA=>{l&&BA.stopPropagation()},onMouseDown:BA=>{if(a&&!P){BA.preventDefault(),BA.stopPropagation();return}TA(BA)},onMouseDownCapture:BA=>{if(a&&!P){BA.preventDefault(),BA.stopPropagation();return}},onTouchStart:BA=>{l||xA(BA)},onTouchEnd:BA=>{l||JA(BA)},children:[!P&&a&&O.jsx("div",{onClick:BA=>{BA.preventDefault(),BA.stopPropagation(),J(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:gk.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"all",touchAction:"pan-x pan-y pinch-zoom"},children:O.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"})}),O.jsx(S2t,{active:W,onClick:()=>Z(!W)}),s&&O.jsx(m2t,{active:k,onClick:()=>v(!k)}),s&&k&&O.jsx(D2t,{active:_,onClick:()=>H(!_)}),O.jsx(x2t,{circuitJson:t,circuitJsonKey:u,isVisible:W,onClose:()=>Z(!1),showGroups:AA,onToggleGroups:BA=>{c||(nA(BA),H2t("schematic_viewer_show_groups",BA))}}),I&&O.jsx(G2t,{onClick:()=>C(!0)}),l&&O.jsx(R2t,{spiceString:d,onClose:()=>C(!1),plotData:S,nodes:D,isLoading:x,error:F,simOptions:Q,onSimOptionsChange:BA=>{m(!0),E(BA)},hasRun:f}),B&&SA.map(BA=>O.jsx(P2t,{componentId:BA,svgDivRef:CA,containerRef:KA,showOutline:!0,circuitJsonKey:u,onHoverChange:rA,onComponentClick:(EA,vA)=>{B?.({schematicComponentId:EA,event:vA})}},BA)),mA]})]})},W2t=({circuitJson:t,containerStyle:A,colorOverrides:e,width:i,height:o,className:n})=>{const[s,r]=j.useState(null),[a,g]=j.useState(!0),[I,c]=j.useState(null),[B,l]=j.useState(null),C=j.useRef(null),Q=j.useRef(null),{containerWidth:E,containerHeight:h}=lee(C),[u,d]=j.useState(!1),{ref:f}=mH({onSetTransform(H){Q.current&&(Q.current.style.transform=EG(H))}}),m=i||E||1e3,S=o||h||600;j.useEffect(()=>{g(!0),c(null),r(t),g(!1)},[t]);const D=j.useMemo(()=>s&&s.find(P=>P.type==="simulation_experiment")?.simulation_experiment_id||null,[s]),x=j.useMemo(()=>s?s.filter(H=>H.type==="simulation_transient_voltage_graph").map(H=>H.simulation_transient_voltage_graph_id):[],[s]),F=j.useMemo(()=>{if(!s||!m||!S||!D)return"";try{return s$A({circuitJson:s,simulation_experiment_id:D,simulation_transient_voltage_graph_ids:x,width:m,height:S,schematicOptions:{colorOverrides:e}})}catch(H){return console.error("Failed to generate fallback schematic SVG:",H),""}},[s,m,S,e,D,x]);j.useEffect(()=>{if(!F){l(null);return}try{const H=new Blob([F],{type:"image/svg+xml"}),P=URL.createObjectURL(H);return l(P),()=>{URL.revokeObjectURL(P)}}catch(H){console.error("Failed to create SVG object URL:",H),l(null)}},[F]);const k=j.useMemo(()=>F?F.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent":"transparent",[F]),v=H=>{d(!0)},_=H=>{d(!0)};return j.useEffect(()=>{const H=()=>{d(!1)},P=()=>{d(!1)};return window.addEventListener("mouseup",H),window.addEventListener("touchend",P),()=>{window.removeEventListener("mouseup",H),window.removeEventListener("touchend",P)}},[]),a?O.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f5f5f5",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#666",...A},className:n,children:"Loading circuit..."}):I?O.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#fef2f2",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#dc2626",...A},className:n,children:O.jsxs("div",{style:{textAlign:"center",padding:"20px"},children:[O.jsx("div",{style:{fontWeight:"bold",marginBottom:"8px"},children:"Circuit Conversion Error"}),O.jsx("div",{style:{fontSize:"14px"},children:I})]})}):F?O.jsx("div",{ref:H=>{C.current=H,f.current=H},style:{position:"relative",backgroundColor:k,overflow:"hidden",minHeight:"300px",cursor:u?"grabbing":"grab",...A},className:n,onMouseDown:v,onTouchStart:_,children:B?O.jsx("img",{ref:Q,src:B,alt:"Circuit Simulation",style:{transformOrigin:"0 0",width:"100%",height:"100%",display:"block",objectFit:"contain"}}):O.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",minHeight:"300px",color:"#666",fontFamily:"sans-serif"},children:"Failed to render SVG"})}):O.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"#f8fafc",minHeight:"300px",fontFamily:"sans-serif",gap:"12px",...A},className:n,children:[O.jsx("div",{style:{fontSize:"16px",color:"#475569",fontWeight:500},children:"No Simulation Found"}),O.jsxs("div",{style:{fontSize:"14px",color:"#64748b"},children:["Use"," ",O.jsx("code",{style:{backgroundColor:"#e2e8f0",padding:"2px 6px",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px"},children:"<analogsimulation />"})," ","to create simulations"]})]})},Qee=t=>{const[A,e]=j.useState(0),[i,o]=j.useState(0);return j.useEffect(()=>{if(!t.current)return;const n=()=>{const r=t.current?.getBoundingClientRect();e(r?.width||0),o(r?.height||0)};n();const s=new ResizeObserver(n);return s.observe(t.current),window.addEventListener("resize",n),()=>{s.disconnect(),window.removeEventListener("resize",n)}},[]),{containerWidth:A,containerHeight:i}};Ia("assembly-viewer");var Eee=()=>{Ia.enable("assembly-viewer*")},Z2t=({circuitJson:t,containerStyle:A,debugGrid:e=!1,debug:i=!1})=>{i&&Eee();const o=j.useRef(null),{ref:n}=mH({onSetTransform(I){o.current&&(o.current.style.transform=EG(I))}}),{containerWidth:s,containerHeight:r}=Qee(n),a=j.useMemo(()=>!s||!r?"":v7A(t,{width:s,height:r||720}),[t,s,r]);j.useMemo(()=>{if(!a)return yd();const I=a.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return L4(I)}catch(c){return console.error(c),yd()}},[a]);const g=j.useMemo(()=>O.jsx("div",{ref:o,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:a}}),[a]);return O.jsx("div",{ref:n,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...A},children:g})},V2t=({circuitJson:t,containerStyle:A,debugGrid:e=!1,debug:i=!1})=>{i&&Eee();const o=j.useRef(null),{ref:n}=mH({onSetTransform(I){o.current&&(o.current.style.transform=EG(I))}}),{containerWidth:s,containerHeight:r}=Qee(n),a=j.useMemo(()=>!s||!r?"":MEA(t,{width:s,height:r||720}),[t,s,r]);j.useMemo(()=>{if(!a)return yd();const I=a.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return L4(I)}catch(c){return console.error(c),yd()}},[a]);const g=j.useMemo(()=>O.jsx("div",{ref:o,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:a}}),[a]);return O.jsx("div",{ref:n,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...A},children:g})};const hee=["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."],j2t=(()=>{let t=hee[Math.floor(Math.random()*hee.length)];return t=t.replace(/</g,"&lt;"),t=t.replace(/>/g,"&gt;"),t=t.replace(new RegExp('(?<!href=")(?<!\\()(?<!\\]\\()(https?:\\/\\/[^\\s\\)\\]]+)',"g"),(A,e)=>`<a class="rf-text-blue-500 rf-underline" href="${A}" target="_blank">${A}</a>`),t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/g,'<a class="rf-text-blue-500 rf-underline" href="$2" target="_blank">$1</a>'),t})(),KS=({onRunClicked:t})=>O.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:[O.jsx($St,{className:"rf-size-14 rf-mb-4"}),O.jsxs("p",{className:"rf-text-md rf-break-words rf-max-w-xl rf-text-center",children:["Tip: ",O.jsx("span",{dangerouslySetInnerHTML:{__html:j2t}})]}),t&&O.jsxs(Sa,{className:"rf-mt-4 rf-bg-blue-600 rf-hover:bg-blue-500",onClick:t,children:["Run Code",O.jsx(hXA,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),eZ=({text:t,onClick:A})=>O.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:A,children:t}),tZ=t=>O.jsxs("div",{className:"rf-leading-5",children:[O.jsx("div",{className:"rf-py-2 rf-font-bold",children:t.column.name}),O.jsx("div",{children:t.field?.()??O.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:A=>{t.onTextChange?.(A.target.value)}})})]}),z2t=({open:t,children:A,title:e,onClose:i})=>t?O.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:i,children:O.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:o=>{o.preventDefault(),o.stopPropagation()},children:[O.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:e}),O.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:i,children:"×"}),A]})}):null,X2t=({elements:t})=>{const[A,e]=j.useState({open:!1}),[i,o]=j.useReducer((I,c)=>({...I,...c}),{}),n=[...new Set(t.map(I=>I.type))],s=t.map(I=>{const c=I[`${I.type}_id`],B=Object.fromEntries(Object.entries(I).filter(([C])=>!(C===`${I.type}_id`||!C.endsWith("_id")))),l=Object.fromEntries(Object.entries(I).filter(([C])=>!C.endsWith("_id")));return{primary_id:c,other_ids:B,...l,_og_elm:I}}),r=s.map(I=>{let c="";const B=l=>{const C=Object.keys(l.other_ids).find(h=>h.startsWith("source_"));if(!C)return`.${l.name}`;const Q=C.slice(0,-3),E=s.find(h=>h.type===Q&&h.primary_id===l.other_ids[C]);return E?"name"in E?`${B(E)} > .${l.name}`:`#${E.primary_id} > .${l.name}`:`??? > .${l.name}`};return"name"in I&&(c=B(I)),{...I,selector_path:c}}),a=[{key:"primary_id",name:"primary_id",renderCell:I=>O.jsxs("div",{className:"rf-flex rf-items-center",children:[O.jsx(eZ,{text:I.primary_id,onClick:()=>o({focused_id:I.primary_id,id_search:void 0,selector_search:void 0})}),O.jsx("span",{className:"rf-flex-grow"}),O.jsx(eZ,{text:"(JSON)",onClick:()=>e({open:!0,element:I._og_elm,title:I.primary_id})})]}),renderHeaderCell:I=>O.jsx(tZ,{column:I,onTextChange:c=>o({id_search:c}),field:i.focused_id?()=>O.jsxs("div",{children:["Focus:"," ",O.jsx("span",{className:"rf-underline",children:i.focused_id}),O.jsx(eZ,{text:"(unfocus)",onClick:()=>o({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:I=>O.jsx(tZ,{column:I,field:()=>O.jsxs("select",{onChange:c=>o({component_type_filter:c.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[O.jsx("option",{value:"any",children:"any"},"any"),O.jsx("option",{value:"source",children:"source"},"source"),O.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),O.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),n.map(c=>O.jsx("option",{value:c,children:c},c))]})})},{key:"name",name:"name",renderHeaderCell:I=>O.jsx(tZ,{column:I,onTextChange:c=>o({name_search:c})})},{key:"selector_path",name:"selector_path",renderHeaderCell:I=>O.jsx(tZ,{column:I,onTextChange:c=>o({selector_search:c})})},{key:"other_ids",name:"other_ids",renderCell:I=>O.jsx("div",{className:"rf-space-x-2",children:Object.entries(I.other_ids).map(([c,B])=>O.jsx(eZ,{text:B,onClick:()=>o({focused_id:B})},B))})}],g=r.filter(I=>i.name_search?I.name?.toLowerCase()?.includes(i.name_search.toLowerCase()):!0).filter(I=>!i.component_type_filter||i.component_type_filter==="any"?!0:i.component_type_filter==="source"?I.type.startsWith("source_"):i.component_type_filter==="source/pcb"?I.type.startsWith("source_")||I.type.startsWith("pcb_"):i.component_type_filter==="source/schematic"?I.type.startsWith("source_")||I.type.startsWith("schematic_"):I.type?.includes(i.component_type_filter)).filter(I=>i.selector_search?i.selector_search.split(" ").filter(B=>B.length>0).every(B=>I.selector_path?.includes(B)):!0).filter(I=>i.id_search?I.primary_id?.includes(i.id_search):!0).filter(I=>!!(!i.focused_id||I.primary_id===i.focused_id||Object.values(I.other_ids).includes(i.focused_id)));return O.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[O.jsx("div",{className:"rf-overflow-x-auto",children:O.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[O.jsx("thead",{children:O.jsx("tr",{children:a.map(I=>O.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:I.renderHeaderCell?I.renderHeaderCell(I):I.name},I.key))})}),O.jsx("tbody",{children:g.map((I,c)=>O.jsx("tr",{className:"rf-hover:bg-gray-100",children:a.map(B=>O.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:B.renderCell?B.renderCell(I):I[B.key]},B.key))},c))})]})}),O.jsx(z2t,{open:A.open,onClose:()=>e({open:!1}),title:A.open?A.title:"",children:O.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:O.jsx("pre",{className:"rf-whitespace-pre-wrap",children:A.open?JSON.stringify(A.element,null,2):""})})})]})},$2t=(t,A)=>t==="jlcpcb"?O.jsx("a",{className:"rf-underline rf-text-blue-500",target:"_blank",rel:"noreferrer",href:`https://jlcpcb.com/partdetail/${A}`,children:A}):A,AUt=({circuitJson:t})=>{const A=t.filter(i=>i.type==="source_component"),e=new Set;for(const i of A)if(i.supplier_part_numbers)for(const o of Object.keys(i.supplier_part_numbers))e.add(o);return O.jsx("div",{className:"rf-overflow-x-auto",children:O.jsxs("table",{className:"rf-w-full rf-text-left rf-text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"rf-border-b",children:[O.jsx("th",{className:"rf-p-2",children:"Name"}),Array.from(e).map(i=>O.jsx("th",{className:"rf-p-2 rf-capitalize",children:i},i))]})}),O.jsx("tbody",{children:A.map(i=>O.jsxs("tr",{className:"rf-border-b",children:[O.jsx("td",{className:"rf-p-2",children:i.name}),Array.from(e).map(o=>O.jsx("td",{className:"rf-p-2",children:$2t(o,i.supplier_part_numbers?.[o]?.[0]||"")},o))]},i.source_component_id))})]})})},hhA=j.forwardRef(({className:t,type:A,...e},i)=>O.jsx("input",{type:A,className:no("rf-flex rf-h-9 rf-w-full rf-rounded-md rf-border rf-border-zinc-200 rf-bg-white rf-px-3 rf-py-1 rf-text-sm rf-shadow-sm rf-transition-colors file:rf-border-0 file:rf-bg-transparent file:rf-text-sm file:rf-font-medium placeholder:rf-text-zinc-500 focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 dark:rf-border-zinc-800 dark:rf-bg-zinc-950 dark:rf-placeholder-zinc-400 dark:focus-visible:rf-ring-zinc-300",t),ref:i,...e}));hhA.displayName="Input";function Hi(t,A){return Array.isArray(A)?[t.a*A[0]+t.c*A[1]+t.e,t.b*A[0]+t.d*A[1]+t.f]:{x:t.a*A.x+t.c*A.y+t.e,y:t.b*A.x+t.d*A.y+t.f}}function qS(){return{a:1,c:0,e:0,b:0,d:1,f:0}}function PS(t){const{a:A,b:e,c:i,d:o,e:n,f:s}=t,r=A*o-e*i;return{a:o/r,b:e/-r,c:i/-r,d:A/r,e:(o*n-i*s)/-r,f:(e*n-A*s)/r}}function PH(t){return typeof t>"u"}function el(t,A=0){return{a:1,c:0,e:t,b:0,d:1,f:A}}function iZ(...t){t=Array.isArray(t[0])?t[0]:t;const A=(e,i)=>({a:e.a*i.a+e.c*i.b,c:e.a*i.c+e.c*i.d,e:e.a*i.e+e.c*i.f+e.e,b:e.b*i.a+e.d*i.b,d:e.b*i.c+e.d*i.d,f:e.b*i.e+e.d*i.f+e.f});switch(t.length){case 0:throw new Error("no matrices provided");case 1:return t[0];case 2:return A(t[0],t[1]);default:{const[e,i,...o]=t,n=A(e,i);return iZ(n,...o)}}}function Ly(...t){return iZ(...t)}const{cos:eUt,sin:tUt}=Math;function iUt(t,A,e){const i=eUt(t),o=tUt(t),n={a:i,c:-o,e:0,b:o,d:i,f:0};return PH(A)||PH(e)?n:iZ([el(A,e),n,el(-A,-e)])}function OH(t,A=void 0,e=void 0,i=void 0){PH(A)&&(A=t);const o={a:t,c:0,e:0,b:0,d:A,f:0};return PH(e)||PH(i)?o:iZ([el(e,i),o,el(-e,-i)])}function oUt(t,A){function e(){this.constructor=t}e.prototype=A.prototype,t.prototype=new e}function oZ(t,A,e,i){var o=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(o,oZ.prototype),o.expected=A,o.found=e,o.location=i,o.name="SyntaxError",o}oUt(oZ,Error);function uhA(t,A,e){return e=e||" ",t.length>A?t:(A-=t.length,e+=e.repeat(A),t+e.slice(0,A))}oZ.prototype.format=function(t){var A="Error: "+this.message;if(this.location){var e=null,i;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){e=t[i].text.split(/\r\n|\n|\r/g);break}var o=this.location.start,n=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(o):o,s=this.location.source+":"+n.line+":"+n.column;if(e){var r=this.location.end,a=uhA("",n.line.toString().length," "),g=e[o.line-1],I=o.line===r.line?r.column:g.length+1,c=I-o.column||1;A+=`
@@ -5619,7 +5619,7 @@ test("${g} should solve problem correctly", () => {
5619
5619
  // Add more specific assertions based on expected output
5620
5620
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5621
5621
  })
5622
- `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return O.jsxs("div",{className:`relative ${A}`,ref:o,children:[O.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&O.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},$te=t=>t.activeSubSolver?[t,...$te(t.activeSubSolver)]:[t],bKt=({solver:t})=>{const A=$te(t);return O.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>O.jsxs("div",{className:"flex items-center",children:[i>0&&O.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),O.jsx(SKt,{solver:e})]},e.constructor.name))})},xKt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=j.useReducer(Q=>!Q,!1),r=j.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};j.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),j.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const l=t.getCurrentPhase!==void 0,C=l?t.getCurrentPhase():null;return O.jsxs("div",{className:"space-y-2 p-2 border-b",children:[O.jsx("div",{className:"flex items-center",children:O.jsx(bKt,{solver:t})}),O.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[O.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),O.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),O.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),O.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),l&&O.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),O.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",O.jsx("span",{className:"font-medium",children:C})]}),t.solved&&O.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&O.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&O.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},kKt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},GKt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=kKt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],l=B?t.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},FKt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return O.jsx("span",{className:`font-medium ${A[t]}`,children:t})},RKt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:O.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),O.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},MKt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),NKt=({stats:t})=>{if(!t||Object.keys(t).length===0)return O.jsx("span",{children:"-"});const A=Object.entries(t),e=MKt(t);return O.jsxs("details",{className:"cursor-pointer",children:[O.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),O.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>O.jsxs("div",{children:[i,": ",String(o)]},i))})]})},IuA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(IuA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=IuA(i));return A},_Kt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=IuA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},vKt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>GKt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):_Kt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return O.jsxs("div",{className:"border-t border-gray-200",children:[O.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:O.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),O.jsx("div",{className:"overflow-x-auto",children:O.jsxs("table",{className:"w-full text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),O.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",O.jsx("sub",{children:"0"})]}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),O.jsx("tbody",{children:i.map(r=>O.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[O.jsx("td",{className:"px-4 py-2",children:O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),O.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),O.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(FKt,{status:r.status})}),O.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(RKt,{progress:r.progress})}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),O.jsx("td",{className:"px-4 py-2 text-gray-500",children:O.jsx(NKt,{stats:r.stats})}),O.jsx("td",{className:"px-4 py-2",children:r.solverInstance?O.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),O.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},UKt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function LKt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return O.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>O.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>O.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>O.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var HKt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=j.useReducer(I=>I+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return O.jsxs("div",{children:[O.jsx(xKt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?O.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):O.jsx(UKt,{fallback:O.jsx(LKt,{graphics:s}),children:O.jsx(DKt,{graphics:s})}),a&&O.jsx(vKt,{solver:t,onStepUntilPhase:g})]})};const YKt=()=>{j.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},JKt=t=>t.toLowerCase().includes("pack")?XSt:t.toLowerCase().includes("rout")?ibt:USt,TKt=({solverEvents:t=[]})=>{const[A,e]=j.useState(null);YKt();const i=j.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=j.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=j.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=jeA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(jeA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?O.jsx("div",{className:"rf-p-4",children:O.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:O.jsxs("div",{className:"rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),O.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):O.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[O.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[O.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return O.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=JKt(a.solverName);return O.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[O.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),O.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[O.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),O.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),O.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?O.jsx(ky,{fallback:O.jsx("div",{className:"rf-p-4",children:O.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),O.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:O.jsx(HKt,{solver:s.instance})}):O.jsxs("div",{className:"rf-p-4",children:[O.jsxs("div",{className:"rf-mb-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),O.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&O.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:O.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),O.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[O.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:O.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),O.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:O.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):O.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:O.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Aie=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{j.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{z3.captureException(i)}catch{}}},[t,A]),j.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{z3.captureException(o,{error_type:i.type})}catch{}}},[e])},eie="0.0.1511",KKt={version:eie},JZ=D1A()(S1A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),qKt=t=>{const[A,e]=j.useState([]),[i,o]=j.useState(null),[n,s]=j.useState(""),[r,a]=gv("eval-version-selection",null),g=JZ(l=>l.setLastRunEvalVersion),I=JZ(l=>l.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(l=>l.json()).then(l=>{if(Array.isArray(l?.versions)){let C=[...l.versions];l.tags?.latest&&(o(l.tags.latest),C=C.filter(Q=>Q!==l.tags.latest)),e(C)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:j.useMemo(()=>A.filter(l=>l.includes(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:I,search:n,setSearch:s,selectVersion:l=>{a(l),s("")}}},PKt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=j.useState(""),[s,r]=j.useState("");if(!i)return null;const a=t.filter(c=>c.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),I=c=>{c.key==="Enter"&&(a.length===1?n(a[0]):g&&n(s))};return O.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:O.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[O.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),O.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:c=>r(c.target.value),onKeyDown:I}),O.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(c=>O.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${o===c?"bg-blue-50":""}`,onClick:()=>n(c),children:c},c)),g&&O.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${o===s?"bg-blue-50":""}`,onClick:()=>n(s),children:['Create new "',s,'"']})]}),O.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},OKt=t=>{const A=j.useRef(null),e=Yc(i=>i.recentEvents);j.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function WKt(t){const A=ZKt(t),e=j.forwardRef((i,o)=>{const{children:n,...s}=i,r=j.Children.toArray(n),a=r.find(jKt);if(a){const g=a.props.children,I=r.map(c=>c===a?j.Children.count(g)>1?j.Children.only(null):j.isValidElement(g)?g.props.children:null:c);return O.jsx(A,{...s,ref:o,children:j.isValidElement(g)?j.cloneElement(g,void 0,I):null})}return O.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function ZKt(t){const A=j.forwardRef((e,i)=>{const{children:o,...n}=e;if(j.isValidElement(o)){const s=XKt(o),r=zKt(n,o.props);return o.type!==j.Fragment&&(r.ref=i?Vp(i,s):s),j.cloneElement(o,r)}return j.Children.count(o)>1?j.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var VKt=Symbol("radix.slottable");function jKt(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===VKt}function zKt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function XKt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var TZ="Dialog",[tie,iie]=uw(TZ),[$Kt,Pw]=tie(TZ),oie=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=j.useRef(null),a=j.useRef(null),[g,I]=sx({prop:i,defaultProp:o??!1,onChange:n,caller:TZ});return O.jsx($Kt,{scope:A,triggerRef:r,contentRef:a,contentId:Bh(),titleId:Bh(),descriptionId:Bh(),open:g,onOpenChange:I,onOpenToggle:j.useCallback(()=>I(c=>!c),[I]),modal:s,children:e})};oie.displayName=TZ;var nie="DialogTrigger",sie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(nie,e),n=Bc(A,o.triggerRef);return O.jsx(Ha.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":luA(o.open),...i,ref:n,onClick:vo(t.onClick,o.onOpenToggle)})});sie.displayName=nie;var cuA="DialogPortal",[Aqt,rie]=tie(cuA,{forceMount:void 0}),aie=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Pw(cuA,A);return O.jsx(Aqt,{scope:A,forceMount:e,children:j.Children.map(i,s=>O.jsx(s0,{present:e||n.open,children:O.jsx(nW,{asChild:!0,container:o,children:s})}))})};aie.displayName=cuA;var KZ="DialogOverlay",gie=j.forwardRef((t,A)=>{const e=rie(KZ,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(KZ,t.__scopeDialog);return n.modal?O.jsx(s0,{present:i||n.open,children:O.jsx(tqt,{...o,ref:A})}):null});gie.displayName=KZ;var eqt=WKt("DialogOverlay.RemoveScroll"),tqt=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(KZ,e);return O.jsx(lW,{as:eqt,allowPinchZoom:!0,shards:[o.contentRef],children:O.jsx(Ha.div,{"data-state":luA(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),VF="DialogContent",Iie=j.forwardRef((t,A)=>{const e=rie(VF,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(VF,t.__scopeDialog);return O.jsx(s0,{present:i||n.open,children:n.modal?O.jsx(iqt,{...o,ref:A}):O.jsx(oqt,{...o,ref:A})})});Iie.displayName=VF;var iqt=j.forwardRef((t,A)=>{const e=Pw(VF,t.__scopeDialog),i=j.useRef(null),o=Bc(A,e.contentRef,i);return j.useEffect(()=>{const n=i.current;if(n)return tEA(n)},[]),O.jsx(cie,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:vo(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:vo(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:vo(t.onFocusOutside,n=>n.preventDefault())})}),oqt=j.forwardRef((t,A)=>{const e=Pw(VF,t.__scopeDialog),i=j.useRef(!1),o=j.useRef(!1);return O.jsx(cie,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),cie=j.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Pw(VF,e),a=j.useRef(null),g=Bc(A,a);return UQA(),O.jsxs(O.Fragment,{children:[O.jsx(O8,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:O.jsx(oH,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":luA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),O.jsxs(O.Fragment,{children:[O.jsx(sqt,{titleId:r.titleId}),O.jsx(aqt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),BuA="DialogTitle",Bie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(BuA,e);return O.jsx(Ha.h2,{id:o.titleId,...i,ref:A})});Bie.displayName=BuA;var lie="DialogDescription",Cie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(lie,e);return O.jsx(Ha.p,{id:o.descriptionId,...i,ref:A})});Cie.displayName=lie;var Qie="DialogClose",Eie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(Qie,e);return O.jsx(Ha.button,{type:"button",...i,ref:A,onClick:vo(t.onClick,()=>o.onOpenChange(!1))})});Eie.displayName=Qie;function luA(t){return t?"open":"closed"}var hie="DialogTitleWarning",[nqt,uie]=_3e(hie,{contentName:VF,titleName:BuA,docsSlug:"dialog"}),sqt=({titleId:t})=>{const A=uie(hie),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5622
+ `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return O.jsxs("div",{className:`relative ${A}`,ref:o,children:[O.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&O.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},$te=t=>t.activeSubSolver?[t,...$te(t.activeSubSolver)]:[t],bKt=({solver:t})=>{const A=$te(t);return O.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>O.jsxs("div",{className:"flex items-center",children:[i>0&&O.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),O.jsx(SKt,{solver:e})]},e.constructor.name))})},xKt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=j.useReducer(Q=>!Q,!1),r=j.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};j.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),j.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const l=t.getCurrentPhase!==void 0,C=l?t.getCurrentPhase():null;return O.jsxs("div",{className:"space-y-2 p-2 border-b",children:[O.jsx("div",{className:"flex items-center",children:O.jsx(bKt,{solver:t})}),O.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[O.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),O.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),O.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),O.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),l&&O.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),O.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",O.jsx("span",{className:"font-medium",children:C})]}),t.solved&&O.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&O.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&O.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},kKt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},GKt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=kKt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],l=B?t.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},FKt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return O.jsx("span",{className:`font-medium ${A[t]}`,children:t})},RKt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:O.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),O.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},MKt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),NKt=({stats:t})=>{if(!t||Object.keys(t).length===0)return O.jsx("span",{children:"-"});const A=Object.entries(t),e=MKt(t);return O.jsxs("details",{className:"cursor-pointer",children:[O.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),O.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>O.jsxs("div",{children:[i,": ",String(o)]},i))})]})},IuA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(IuA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=IuA(i));return A},_Kt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=IuA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},vKt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>GKt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):_Kt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return O.jsxs("div",{className:"border-t border-gray-200",children:[O.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:O.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),O.jsx("div",{className:"overflow-x-auto",children:O.jsxs("table",{className:"w-full text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),O.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",O.jsx("sub",{children:"0"})]}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),O.jsx("tbody",{children:i.map(r=>O.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[O.jsx("td",{className:"px-4 py-2",children:O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),O.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),O.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(FKt,{status:r.status})}),O.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(RKt,{progress:r.progress})}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),O.jsx("td",{className:"px-4 py-2 text-gray-500",children:O.jsx(NKt,{stats:r.stats})}),O.jsx("td",{className:"px-4 py-2",children:r.solverInstance?O.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),O.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},UKt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function LKt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return O.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>O.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>O.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>O.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var HKt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=j.useReducer(I=>I+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return O.jsxs("div",{children:[O.jsx(xKt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?O.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):O.jsx(UKt,{fallback:O.jsx(LKt,{graphics:s}),children:O.jsx(DKt,{graphics:s})}),a&&O.jsx(vKt,{solver:t,onStepUntilPhase:g})]})};const YKt=()=>{j.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},JKt=t=>t.toLowerCase().includes("pack")?XSt:t.toLowerCase().includes("rout")?ibt:USt,TKt=({solverEvents:t=[]})=>{const[A,e]=j.useState(null);YKt();const i=j.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=j.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=j.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=jeA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(jeA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?O.jsx("div",{className:"rf-p-4",children:O.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:O.jsxs("div",{className:"rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),O.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):O.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[O.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[O.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return O.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=JKt(a.solverName);return O.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[O.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),O.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[O.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),O.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),O.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?O.jsx(ky,{fallback:O.jsx("div",{className:"rf-p-4",children:O.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),O.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:O.jsx(HKt,{solver:s.instance})}):O.jsxs("div",{className:"rf-p-4",children:[O.jsxs("div",{className:"rf-mb-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),O.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&O.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:O.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),O.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[O.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:O.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),O.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:O.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):O.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:O.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Aie=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{j.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{z3.captureException(i)}catch{}}},[t,A]),j.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{z3.captureException(o,{error_type:i.type})}catch{}}},[e])},eie="0.0.1512",KKt={version:eie},JZ=D1A()(S1A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),qKt=t=>{const[A,e]=j.useState([]),[i,o]=j.useState(null),[n,s]=j.useState(""),[r,a]=gv("eval-version-selection",null),g=JZ(l=>l.setLastRunEvalVersion),I=JZ(l=>l.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(l=>l.json()).then(l=>{if(Array.isArray(l?.versions)){let C=[...l.versions];l.tags?.latest&&(o(l.tags.latest),C=C.filter(Q=>Q!==l.tags.latest)),e(C)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:j.useMemo(()=>A.filter(l=>l.includes(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:I,search:n,setSearch:s,selectVersion:l=>{a(l),s("")}}},PKt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=j.useState(""),[s,r]=j.useState("");if(!i)return null;const a=t.filter(c=>c.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),I=c=>{c.key==="Enter"&&(a.length===1?n(a[0]):g&&n(s))};return O.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:O.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[O.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),O.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:c=>r(c.target.value),onKeyDown:I}),O.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(c=>O.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${o===c?"bg-blue-50":""}`,onClick:()=>n(c),children:c},c)),g&&O.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${o===s?"bg-blue-50":""}`,onClick:()=>n(s),children:['Create new "',s,'"']})]}),O.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},OKt=t=>{const A=j.useRef(null),e=Yc(i=>i.recentEvents);j.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function WKt(t){const A=ZKt(t),e=j.forwardRef((i,o)=>{const{children:n,...s}=i,r=j.Children.toArray(n),a=r.find(jKt);if(a){const g=a.props.children,I=r.map(c=>c===a?j.Children.count(g)>1?j.Children.only(null):j.isValidElement(g)?g.props.children:null:c);return O.jsx(A,{...s,ref:o,children:j.isValidElement(g)?j.cloneElement(g,void 0,I):null})}return O.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function ZKt(t){const A=j.forwardRef((e,i)=>{const{children:o,...n}=e;if(j.isValidElement(o)){const s=XKt(o),r=zKt(n,o.props);return o.type!==j.Fragment&&(r.ref=i?Vp(i,s):s),j.cloneElement(o,r)}return j.Children.count(o)>1?j.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var VKt=Symbol("radix.slottable");function jKt(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===VKt}function zKt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function XKt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var TZ="Dialog",[tie,iie]=uw(TZ),[$Kt,Pw]=tie(TZ),oie=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=j.useRef(null),a=j.useRef(null),[g,I]=sx({prop:i,defaultProp:o??!1,onChange:n,caller:TZ});return O.jsx($Kt,{scope:A,triggerRef:r,contentRef:a,contentId:Bh(),titleId:Bh(),descriptionId:Bh(),open:g,onOpenChange:I,onOpenToggle:j.useCallback(()=>I(c=>!c),[I]),modal:s,children:e})};oie.displayName=TZ;var nie="DialogTrigger",sie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(nie,e),n=Bc(A,o.triggerRef);return O.jsx(Ha.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":luA(o.open),...i,ref:n,onClick:vo(t.onClick,o.onOpenToggle)})});sie.displayName=nie;var cuA="DialogPortal",[Aqt,rie]=tie(cuA,{forceMount:void 0}),aie=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Pw(cuA,A);return O.jsx(Aqt,{scope:A,forceMount:e,children:j.Children.map(i,s=>O.jsx(s0,{present:e||n.open,children:O.jsx(nW,{asChild:!0,container:o,children:s})}))})};aie.displayName=cuA;var KZ="DialogOverlay",gie=j.forwardRef((t,A)=>{const e=rie(KZ,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(KZ,t.__scopeDialog);return n.modal?O.jsx(s0,{present:i||n.open,children:O.jsx(tqt,{...o,ref:A})}):null});gie.displayName=KZ;var eqt=WKt("DialogOverlay.RemoveScroll"),tqt=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(KZ,e);return O.jsx(lW,{as:eqt,allowPinchZoom:!0,shards:[o.contentRef],children:O.jsx(Ha.div,{"data-state":luA(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),VF="DialogContent",Iie=j.forwardRef((t,A)=>{const e=rie(VF,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(VF,t.__scopeDialog);return O.jsx(s0,{present:i||n.open,children:n.modal?O.jsx(iqt,{...o,ref:A}):O.jsx(oqt,{...o,ref:A})})});Iie.displayName=VF;var iqt=j.forwardRef((t,A)=>{const e=Pw(VF,t.__scopeDialog),i=j.useRef(null),o=Bc(A,e.contentRef,i);return j.useEffect(()=>{const n=i.current;if(n)return tEA(n)},[]),O.jsx(cie,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:vo(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:vo(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:vo(t.onFocusOutside,n=>n.preventDefault())})}),oqt=j.forwardRef((t,A)=>{const e=Pw(VF,t.__scopeDialog),i=j.useRef(!1),o=j.useRef(!1);return O.jsx(cie,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),cie=j.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Pw(VF,e),a=j.useRef(null),g=Bc(A,a);return UQA(),O.jsxs(O.Fragment,{children:[O.jsx(O8,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:O.jsx(oH,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":luA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),O.jsxs(O.Fragment,{children:[O.jsx(sqt,{titleId:r.titleId}),O.jsx(aqt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),BuA="DialogTitle",Bie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(BuA,e);return O.jsx(Ha.h2,{id:o.titleId,...i,ref:A})});Bie.displayName=BuA;var lie="DialogDescription",Cie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(lie,e);return O.jsx(Ha.p,{id:o.descriptionId,...i,ref:A})});Cie.displayName=lie;var Qie="DialogClose",Eie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(Qie,e);return O.jsx(Ha.button,{type:"button",...i,ref:A,onClick:vo(t.onClick,()=>o.onOpenChange(!1))})});Eie.displayName=Qie;function luA(t){return t?"open":"closed"}var hie="DialogTitleWarning",[nqt,uie]=_3e(hie,{contentName:VF,titleName:BuA,docsSlug:"dialog"}),sqt=({titleId:t})=>{const A=uie(hie),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5623
5623
 
5624
5624
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5625
5625
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "dist/index.js",
4
4
  "types": "dist/index.d.ts",
5
5
  "type": "module",
6
- "version": "0.0.1194-libonly",
6
+ "version": "0.0.1195-libonly",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/tscircuit/tscircuit"
@@ -59,7 +59,7 @@
59
59
  "@tscircuit/miniflex": "^0.0.4",
60
60
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
61
61
  "@tscircuit/props": "^0.0.448",
62
- "@tscircuit/runframe": "^0.0.1512",
62
+ "@tscircuit/runframe": "^0.0.1513",
63
63
  "@tscircuit/schematic-match-adapt": "^0.0.16",
64
64
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
65
65
  "@tscircuit/simple-3d-svg": "^0.0.41",