@tscircuit/runframe 0.0.2114 → 0.0.2115
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.
|
@@ -2009,7 +2009,7 @@ var usePostHogActivity = (properties) => {
|
|
|
2009
2009
|
};
|
|
2010
2010
|
|
|
2011
2011
|
// package.json
|
|
2012
|
-
var version = "0.0.
|
|
2012
|
+
var version = "0.0.2114";
|
|
2013
2013
|
var package_default = {
|
|
2014
2014
|
name: "@tscircuit/runframe",
|
|
2015
2015
|
main: "dist/preview.js",
|
|
@@ -2065,7 +2065,7 @@ var package_default = {
|
|
|
2065
2065
|
"@tscircuit/file-server": "^0.0.32",
|
|
2066
2066
|
"@tscircuit/internal-dynamic-import": "^0.0.7",
|
|
2067
2067
|
"@tscircuit/pcb-viewer": "1.11.374",
|
|
2068
|
-
"@tscircuit/schematic-viewer": "^2.0.
|
|
2068
|
+
"@tscircuit/schematic-viewer": "^2.0.66",
|
|
2069
2069
|
"@types/bun": "latest",
|
|
2070
2070
|
"@types/debug": "^4.1.12",
|
|
2071
2071
|
"@types/react": "^19.1.10",
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -5618,7 +5618,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
|
|
|
5618
5618
|
50% { opacity: 0.2; }
|
|
5619
5619
|
100% { opacity: 0.6; }
|
|
5620
5620
|
}
|
|
5621
|
-
`,i.appendChild(f)}})}};r();const s=new MutationObserver(r);return s.observe(i,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},SEt=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],t1o=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:i}=t;ne.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!i||!n||n.length===0)return;const r=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=mp(n).source_group?.list().filter(f=>!f.is_subcircuit)||[],l=mp(n).schematic_component?.list()||[],A=new Map;c.forEach(f=>{const y=f;if(y.parent_source_group_id){const C=A.get(y.parent_source_group_id)||[];C.push(f.source_group_id),A.set(y.parent_source_group_id,C)}});const u=f=>{const y=[],C=A.get(f)||[];for(const I of C)y.push(I),y.push(...u(I));return y},d=f=>{const y=c.find(C=>C.source_group_id===f);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},h=c.length>0&&c.some(f=>f.name&&f.name.trim()!=="");let _=[];if(h){const f=new Map;for(const y of l){const C=mp(n).source_component.get(y.source_component_id);C?.source_group_id&&(f.has(C.source_group_id)||f.set(C.source_group_id,[]),f.get(C.source_group_id).push(y))}c.forEach((y,C)=>{let I=f.get(y.source_group_id)||[];const E=u(y.source_group_id);for(const b of E){const P=f.get(b)||[];I=[...I,...P]}if(I.length>0){const b=d(y.source_group_id),P=u(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;_.push({id:y.source_group_id,name:y.name||`Group ${C+1}`,components:I,color:SEt[C%SEt.length],depthLevel:b,hasChildren:P,sourceGroupId:y.source_group_id})}})}const m=s.viewBox.baseVal,p=s.getBoundingClientRect(),g=Math.min(p.width/m.width,p.height/m.height)||1;_.sort((f,y)=>f.depthLevel-y.depthLevel),_.forEach(f=>{if(f.components.length===0)return;const y=n1o(f.components,s);if(!y)return;const C=Math.max(8,Math.min(25,15/Math.max(g,.3))),I=f.hasChildren?C*.6:0,E=C+I,b=Math.max(1,2/Math.max(g,.5)),P=f.depthLevel===0?b:b*.7,B=Math.max(4,8/Math.max(g,.5)),M=f.hasChildren?1.3:1,R=B*M,k=R*.5,L=document.createElementNS("http://www.w3.org/2000/svg","rect");L.setAttribute("class","schematic-group-overlay"),L.setAttribute("x",(y.minX-E).toString()),L.setAttribute("y",(y.minY-E).toString()),L.setAttribute("width",(y.maxX-y.minX+E*2).toString()),L.setAttribute("height",(y.maxY-y.minY+E*2).toString()),L.setAttribute("fill","none"),L.setAttribute("stroke",f.color),L.setAttribute("stroke-width",P.toString()),L.setAttribute("stroke-dasharray",`${R},${k}`),L.setAttribute("opacity","0.8"),L.setAttribute("rx","0"),L.setAttribute("ry","0");const O=Math.max(6,Math.min(20,14/Math.max(g,.2))),G=f.depthLevel===0||f.depthLevel===1?0:f.depthLevel*.2,K=O*(1-G),X=Math.max(1,K*.2),q=f.name,oe=document.createElementNS("http://www.w3.org/2000/svg","text");oe.setAttribute("font-size",K.toString()),oe.setAttribute("font-family","Arial, sans-serif"),oe.textContent=q,s.appendChild(oe);const le=oe.getBBox();s.removeChild(oe);const Z=le.width+X*2,re=K+X*2,ce=y.minX-E,ae=y.minY-E-re,pe=document.createElementNS("http://www.w3.org/2000/svg","rect");pe.setAttribute("class","schematic-group-overlay"),pe.setAttribute("x",ce.toString()),pe.setAttribute("y",(ae-re).toString()),pe.setAttribute("width",Z.toString()),pe.setAttribute("height",re.toString()),pe.setAttribute("fill","transparent"),pe.setAttribute("rx","0"),pe.setAttribute("ry","0");const Ie=document.createElementNS("http://www.w3.org/2000/svg","text");Ie.setAttribute("class","schematic-group-overlay"),Ie.setAttribute("x",(ce+X).toString()),Ie.setAttribute("y",(ae+re-X).toString()),Ie.setAttribute("fill",f.color),Ie.setAttribute("font-size",K.toString()),Ie.setAttribute("font-family","Arial, sans-serif"),Ie.setAttribute("font-weight",f.depthLevel===0?"600":"500"),Ie.setAttribute("stroke",f.color),Ie.setAttribute("stroke-width",Math.max(.2,K*.02).toString()),Ie.textContent=q,s.appendChild(L),s.appendChild(pe),s.appendChild(Ie)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(r)},[e,o,i])};function n1o(t,e){let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),i=Math.max(i,l.x+l.width),r=Math.max(r,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:i,maxY:r}}var o1o=gA("schematic-viewer"),i1o=()=>{gA.enable("schematic-viewer*")},r1o=o1o,PEt=t=>{const[e,n]=ne.useState(0),[o,i]=ne.useState(0);return ne.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}},s1o=r1o.extend("useComponentDragging"),a1o=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:i,realToSvgProjection:r,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=ne.useState(null),A=Ti(r,i),u=ne.useRef(null),d=ne.useRef(null),h=ne.useRef(new Map);ne.useEffect(()=>{e.forEach(b=>{"edit_event_type"in b&&b.edit_event_type==="edit_schematic_component_location"&&!b.in_progress&&h.current.set(b.schematic_component_id,{...b.new_center})})},[e]);const _=ne.useCallback((b,P,B)=>{if(!s)return!1;const M=B.closest('[data-circuit-json-type="schematic_component"]');if(!M)return!1;const R=M.getAttribute("data-schematic-component-id");if(!R)return!1;o&&o();const k=mp(n).schematic_component.get(R);if(!k)return!1;u.current={x:b,y:P};let L;const O=h.current.get(R);if(O)L={...O};else{const K=bEt({editEvents:e,schematic_component_id:R});L={x:k.center.x+K.x,y:k.center.y+K.y},h.current.set(R,{...L})}const G={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:R,original_center:L,new_center:{...L},in_progress:!0,created_at:Date.now(),_element:M};return d.current=G,l(G),!0},[o,s,n,e]),m=ne.useCallback(b=>{_(b.clientX,b.clientY,b.target)},[_]),p=ne.useCallback(b=>{if(b.touches.length!==1)return;const P=b.touches[0];_(P.clientX,P.clientY,b.target)&&b.preventDefault()},[_]),g=ne.useCallback((b,P)=>{if(!d.current||!u.current)return;const B={x:b-u.current.x,y:P-u.current.y},M={x:B.x/A.a,y:B.y/A.d};let R={x:d.current.original_center.x+M.x,y:d.current.original_center.y+M.y};if(a){const L=O=>Math.round(O*10)/10;R={x:L(R.x),y:L(R.y)}}const k={...d.current,new_center:R};d.current=k,l(k)},[A,a]),f=ne.useCallback(b=>g(b.clientX,b.clientY),[g]),y=ne.useCallback(b=>{if(b.touches.length!==1||!d.current)return;b.preventDefault();const P=b.touches[0];g(P.clientX,P.clientY)},[g]),C=ne.useCallback(()=>{if(!d.current)return;const b={...d.current,in_progress:!1};h.current.set(b.schematic_component_id,{...b.new_center}),s1o("endDrag calling onEditEvent with new edit event",{newEditEvent:b}),t&&t(b),d.current=null,u.current=null,l(null)},[t]),I=ne.useCallback(()=>C(),[C]),E=ne.useCallback(()=>C(),[C]);return ne.useEffect(()=>(window.addEventListener("mousemove",f),window.addEventListener("mouseup",I),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",E),()=>{window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",I),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",E)}),[f,I,y,E]),{handleMouseDown:m,handleTouchStart:p,isDragging:!!d.current,activeEditEvent:c}},Y4={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},c1o=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return W.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y4.schematicEditIcon},children:W.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[W.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),W.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},l1o=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return W.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y4.schematicGridIcon},children:W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:W.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},A1o=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return W.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y4.viewMenuIcon},children:W.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[W.jsx("circle",{cx:"12",cy:"12",r:"1"}),W.jsx("circle",{cx:"12",cy:"5",r:"1"}),W.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},u1o={version:"2.0.64"},d1o=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:i,onToggleGroups:r,showGrid:s,onToggleGrid:a})=>{const c=ne.useMemo(()=>{if(!t||t.length===0)return!1;try{if((mp(t).source_group?.list()||[]).length>0)return!0;const A=mp(t).schematic_component?.list()||[];if(A.length>1){const u=new Set;for(const d of A){const h=mp(t).source_component.get(d.source_component_id);h?.ftype&&u.add(h.ftype)}return u.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?W.jsxs(W.Fragment,{children:[W.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:Y4.viewMenuBackdrop}}),W.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:Y4.viewMenu},children:[W.jsxs("div",{onClick:()=>{c&&r(!i)},onTouchEnd:l=>{l.preventDefault(),c&&r(!i)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[W.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:i&&"✓"}),"View Schematic Groups"]}),!c&&W.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),W.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[W.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),W.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(u1o?.version)]})]})]}):null},_1o=()=>W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:W.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),h1o=({onClick:t})=>W.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:Y4.spiceSimulationIcon},children:W.jsx(_1o,{})});nee.register(Ofo,zfo,Cfo,yfo,Bfo,kfo,Pfo);var see=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],vEt=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},m1o=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:i})=>{const r=ne.useMemo(()=>{const c=e.some(A=>A.toLowerCase().startsWith("v(")),l=e.some(A=>A.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return W.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!i)return W.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return W.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return W.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(A=>({x:Number(A.name),y:A[c]})),borderColor:see[l%see.length],backgroundColor:see[l%see.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return vEt(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>vEt(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:r,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return W.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:W.jsx($fo,{options:a,data:s})})},g1o=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:i,error:r,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,A]=ne.useState(String(s.startTime)),[u,d]=ne.useState(String(s.duration));ne.useEffect(()=>{A(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const h=()=>{a({...s,startTime:Number(l),duration:Number(u)})},_=o.filter(m=>{const p=m.toLowerCase().startsWith("v("),g=m.toLowerCase().startsWith("i(");return!!(s.showVoltage&&p||s.showCurrent&&g)});return W.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:W.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[W.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[W.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),W.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),W.jsx("div",{children:W.jsx(m1o,{plotData:n,nodes:_,isLoading:i,error:r,hasRun:c})}),W.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[W.jsxs("div",{style:{display:"flex",gap:"16px"},children:[W.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[W.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:m=>a({...s,showVoltage:m.target.checked})}),"Voltage"]}),W.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[W.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:m=>a({...s,showCurrent:m.target.checked})}),"Current"]})]}),W.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[W.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),W.jsx("input",{id:"startTime",type:"number",value:l,onChange:m=>A(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),W.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),W.jsx("input",{id:"duration",type:"number",value:u,onChange:m=>d(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),W.jsx("button",{onClick:h,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),W.jsxs("div",{style:{marginTop:"24px"},children:[W.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),W.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})]})]})})},p1o="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",aee=null,f1o=()=>{if(typeof window>"u")return null;if(aee)return aee;try{const t=new Blob([atob(p1o)],{type:"application/javascript"});return aee=URL.createObjectURL(t),aee}catch(t){return console.error("Failed to create blob URL for worker",t),null}},y1o=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],i=Object.keys(e).filter(a=>a!==n),r=i;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return i.forEach(A=>{l[A]=e[A][c]}),l}),nodes:r}},C1o=t=>{const[e,n]=ne.useState([]),[o,i]=ne.useState([]),[r,s]=ne.useState(!0),[a,c]=ne.useState(null);return ne.useEffect(()=>{if(!t){s(!1),n([]),i([]),c(null);return}s(!0),c(null),n([]),i([]);const l=f1o();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const A=new Worker(l,{type:"module"});return A.onmessage=u=>{if(u.data.type==="result")try{const{plotData:d,nodes:h}=y1o(u.data.result);n(d),i(h)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else u.data.type==="error"&&c(u.data.error);s(!1)},A.onerror=u=>{c(u.message),s(!1)},A.postMessage({spiceString:t}),()=>{A.terminate()}},[t]),{plotData:e,nodes:o,isLoading:r,error:a}},D3e=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},x1o=(t,e)=>{const o=Bit(t).toSpiceString(),r=o.split(`
|
|
5621
|
+
`,i.appendChild(f)}})}};r();const s=new MutationObserver(r);return s.observe(i,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},SEt=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],t1o=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:i}=t;ne.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!i||!n||n.length===0)return;const r=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=mp(n).source_group?.list().filter(f=>!f.is_subcircuit)||[],l=mp(n).schematic_component?.list()||[],A=new Map;c.forEach(f=>{const y=f;if(y.parent_source_group_id){const C=A.get(y.parent_source_group_id)||[];C.push(f.source_group_id),A.set(y.parent_source_group_id,C)}});const u=f=>{const y=[],C=A.get(f)||[];for(const I of C)y.push(I),y.push(...u(I));return y},d=f=>{const y=c.find(C=>C.source_group_id===f);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},h=c.length>0&&c.some(f=>f.name&&f.name.trim()!=="");let _=[];if(h){const f=new Map;for(const y of l){const C=mp(n).source_component.get(y.source_component_id);C?.source_group_id&&(f.has(C.source_group_id)||f.set(C.source_group_id,[]),f.get(C.source_group_id).push(y))}c.forEach((y,C)=>{let I=f.get(y.source_group_id)||[];const E=u(y.source_group_id);for(const b of E){const P=f.get(b)||[];I=[...I,...P]}if(I.length>0){const b=d(y.source_group_id),P=u(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;_.push({id:y.source_group_id,name:y.name||`Group ${C+1}`,components:I,color:SEt[C%SEt.length],depthLevel:b,hasChildren:P,sourceGroupId:y.source_group_id})}})}const m=s.viewBox.baseVal,p=s.getBoundingClientRect(),g=Math.min(p.width/m.width,p.height/m.height)||1;_.sort((f,y)=>f.depthLevel-y.depthLevel),_.forEach(f=>{if(f.components.length===0)return;const y=n1o(f.components,s);if(!y)return;const C=Math.max(8,Math.min(25,15/Math.max(g,.3))),I=f.hasChildren?C*.6:0,E=C+I,b=Math.max(1,2/Math.max(g,.5)),P=f.depthLevel===0?b:b*.7,B=Math.max(4,8/Math.max(g,.5)),M=f.hasChildren?1.3:1,R=B*M,k=R*.5,L=document.createElementNS("http://www.w3.org/2000/svg","rect");L.setAttribute("class","schematic-group-overlay"),L.setAttribute("x",(y.minX-E).toString()),L.setAttribute("y",(y.minY-E).toString()),L.setAttribute("width",(y.maxX-y.minX+E*2).toString()),L.setAttribute("height",(y.maxY-y.minY+E*2).toString()),L.setAttribute("fill","none"),L.setAttribute("stroke",f.color),L.setAttribute("stroke-width",P.toString()),L.setAttribute("stroke-dasharray",`${R},${k}`),L.setAttribute("opacity","0.8"),L.setAttribute("rx","0"),L.setAttribute("ry","0");const O=Math.max(6,Math.min(20,14/Math.max(g,.2))),G=f.depthLevel===0||f.depthLevel===1?0:f.depthLevel*.2,K=O*(1-G),X=Math.max(1,K*.2),q=f.name,oe=document.createElementNS("http://www.w3.org/2000/svg","text");oe.setAttribute("font-size",K.toString()),oe.setAttribute("font-family","Arial, sans-serif"),oe.textContent=q,s.appendChild(oe);const le=oe.getBBox();s.removeChild(oe);const Z=le.width+X*2,re=K+X*2,ce=y.minX-E,ae=y.minY-E-re,pe=document.createElementNS("http://www.w3.org/2000/svg","rect");pe.setAttribute("class","schematic-group-overlay"),pe.setAttribute("x",ce.toString()),pe.setAttribute("y",(ae-re).toString()),pe.setAttribute("width",Z.toString()),pe.setAttribute("height",re.toString()),pe.setAttribute("fill","transparent"),pe.setAttribute("rx","0"),pe.setAttribute("ry","0");const Ie=document.createElementNS("http://www.w3.org/2000/svg","text");Ie.setAttribute("class","schematic-group-overlay"),Ie.setAttribute("x",(ce+X).toString()),Ie.setAttribute("y",(ae+re-X).toString()),Ie.setAttribute("fill",f.color),Ie.setAttribute("font-size",K.toString()),Ie.setAttribute("font-family","Arial, sans-serif"),Ie.setAttribute("font-weight",f.depthLevel===0?"600":"500"),Ie.setAttribute("stroke",f.color),Ie.setAttribute("stroke-width",Math.max(.2,K*.02).toString()),Ie.textContent=q,s.appendChild(L),s.appendChild(pe),s.appendChild(Ie)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(r)},[e,o,i])};function n1o(t,e){let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),i=Math.max(i,l.x+l.width),r=Math.max(r,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:i,maxY:r}}var o1o=gA("schematic-viewer"),i1o=()=>{gA.enable("schematic-viewer*")},r1o=o1o,PEt=t=>{const[e,n]=ne.useState(0),[o,i]=ne.useState(0);return ne.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}},s1o=r1o.extend("useComponentDragging"),a1o=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:i,realToSvgProjection:r,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=ne.useState(null),A=Ti(r,i),u=ne.useRef(null),d=ne.useRef(null),h=ne.useRef(new Map);ne.useEffect(()=>{e.forEach(b=>{"edit_event_type"in b&&b.edit_event_type==="edit_schematic_component_location"&&!b.in_progress&&h.current.set(b.schematic_component_id,{...b.new_center})})},[e]);const _=ne.useCallback((b,P,B)=>{if(!s)return!1;const M=B.closest('[data-circuit-json-type="schematic_component"]');if(!M)return!1;const R=M.getAttribute("data-schematic-component-id");if(!R)return!1;o&&o();const k=mp(n).schematic_component.get(R);if(!k)return!1;u.current={x:b,y:P};let L;const O=h.current.get(R);if(O)L={...O};else{const K=bEt({editEvents:e,schematic_component_id:R});L={x:k.center.x+K.x,y:k.center.y+K.y},h.current.set(R,{...L})}const G={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:R,original_center:L,new_center:{...L},in_progress:!0,created_at:Date.now(),_element:M};return d.current=G,l(G),!0},[o,s,n,e]),m=ne.useCallback(b=>{_(b.clientX,b.clientY,b.target)},[_]),p=ne.useCallback(b=>{if(b.touches.length!==1)return;const P=b.touches[0];_(P.clientX,P.clientY,b.target)&&b.preventDefault()},[_]),g=ne.useCallback((b,P)=>{if(!d.current||!u.current)return;const B={x:b-u.current.x,y:P-u.current.y},M={x:B.x/A.a,y:B.y/A.d};let R={x:d.current.original_center.x+M.x,y:d.current.original_center.y+M.y};if(a){const L=O=>Math.round(O*10)/10;R={x:L(R.x),y:L(R.y)}}const k={...d.current,new_center:R};d.current=k,l(k)},[A,a]),f=ne.useCallback(b=>g(b.clientX,b.clientY),[g]),y=ne.useCallback(b=>{if(b.touches.length!==1||!d.current)return;b.preventDefault();const P=b.touches[0];g(P.clientX,P.clientY)},[g]),C=ne.useCallback(()=>{if(!d.current)return;const b={...d.current,in_progress:!1};h.current.set(b.schematic_component_id,{...b.new_center}),s1o("endDrag calling onEditEvent with new edit event",{newEditEvent:b}),t&&t(b),d.current=null,u.current=null,l(null)},[t]),I=ne.useCallback(()=>C(),[C]),E=ne.useCallback(()=>C(),[C]);return ne.useEffect(()=>(window.addEventListener("mousemove",f),window.addEventListener("mouseup",I),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",E),()=>{window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",I),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",E)}),[f,I,y,E]),{handleMouseDown:m,handleTouchStart:p,isDragging:!!d.current,activeEditEvent:c}},Y4={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},c1o=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return W.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y4.schematicEditIcon},children:W.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[W.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),W.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},l1o=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return W.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y4.schematicGridIcon},children:W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:W.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},A1o=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return W.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:Y4.viewMenuIcon},children:W.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[W.jsx("circle",{cx:"12",cy:"12",r:"1"}),W.jsx("circle",{cx:"12",cy:"5",r:"1"}),W.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},u1o={version:"2.0.65"},d1o=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:i,onToggleGroups:r,showGrid:s,onToggleGrid:a})=>{const c=ne.useMemo(()=>{if(!t||t.length===0)return!1;try{if((mp(t).source_group?.list()||[]).length>0)return!0;const A=mp(t).schematic_component?.list()||[];if(A.length>1){const u=new Set;for(const d of A){const h=mp(t).source_component.get(d.source_component_id);h?.ftype&&u.add(h.ftype)}return u.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?W.jsxs(W.Fragment,{children:[W.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:Y4.viewMenuBackdrop}}),W.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:Y4.viewMenu},children:[W.jsxs("div",{onClick:()=>{c&&r(!i)},onTouchEnd:l=>{l.preventDefault(),c&&r(!i)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[W.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:i&&"✓"}),"View Schematic Groups"]}),!c&&W.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),W.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[W.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),W.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(u1o?.version)]})]})]}):null},_1o=()=>W.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:W.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),h1o=({onClick:t})=>W.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:Y4.spiceSimulationIcon},children:W.jsx(_1o,{})});nee.register(Ofo,zfo,Cfo,yfo,Bfo,kfo,Pfo);var see=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],vEt=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},m1o=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:i})=>{const r=ne.useMemo(()=>{const c=e.some(A=>A.toLowerCase().startsWith("v(")),l=e.some(A=>A.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return W.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!i)return W.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return W.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return W.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(A=>({x:Number(A.name),y:A[c]})),borderColor:see[l%see.length],backgroundColor:see[l%see.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return vEt(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>vEt(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:r,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return W.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:W.jsx($fo,{options:a,data:s})})},g1o=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:i,error:r,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,A]=ne.useState(String(s.startTime)),[u,d]=ne.useState(String(s.duration));ne.useEffect(()=>{A(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const h=()=>{a({...s,startTime:Number(l),duration:Number(u)})},_=o.filter(m=>{const p=m.toLowerCase().startsWith("v("),g=m.toLowerCase().startsWith("i(");return!!(s.showVoltage&&p||s.showCurrent&&g)});return W.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:W.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[W.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[W.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),W.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),W.jsx("div",{children:W.jsx(m1o,{plotData:n,nodes:_,isLoading:i,error:r,hasRun:c})}),W.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[W.jsxs("div",{style:{display:"flex",gap:"16px"},children:[W.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[W.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:m=>a({...s,showVoltage:m.target.checked})}),"Voltage"]}),W.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[W.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:m=>a({...s,showCurrent:m.target.checked})}),"Current"]})]}),W.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[W.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),W.jsx("input",{id:"startTime",type:"number",value:l,onChange:m=>A(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),W.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),W.jsx("input",{id:"duration",type:"number",value:u,onChange:m=>d(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),W.jsx("button",{onClick:h,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),W.jsxs("div",{style:{marginTop:"24px"},children:[W.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),W.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})]})]})})},p1o="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",aee=null,f1o=()=>{if(typeof window>"u")return null;if(aee)return aee;try{const t=new Blob([atob(p1o)],{type:"application/javascript"});return aee=URL.createObjectURL(t),aee}catch(t){return console.error("Failed to create blob URL for worker",t),null}},y1o=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],i=Object.keys(e).filter(a=>a!==n),r=i;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return i.forEach(A=>{l[A]=e[A][c]}),l}),nodes:r}},C1o=t=>{const[e,n]=ne.useState([]),[o,i]=ne.useState([]),[r,s]=ne.useState(!0),[a,c]=ne.useState(null);return ne.useEffect(()=>{if(!t){s(!1),n([]),i([]),c(null);return}s(!0),c(null),n([]),i([]);const l=f1o();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const A=new Worker(l,{type:"module"});return A.onmessage=u=>{if(u.data.type==="result")try{const{plotData:d,nodes:h}=y1o(u.data.result);n(d),i(h)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else u.data.type==="error"&&c(u.data.error);s(!1)},A.onerror=u=>{c(u.message),s(!1)},A.postMessage({spiceString:t}),()=>{A.terminate()}},[t]),{plotData:e,nodes:o,isLoading:r,error:a}},D3e=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},x1o=(t,e)=>{const o=Bit(t).toSpiceString(),r=o.split(`
|
|
5622
5622
|
`).filter(M=>M.trim()!=="").filter(M=>!M.startsWith("*")&&!M.startsWith(".")&&M.trim()!==""),s=new Set,a=new Set,c=new Set;for(const M of r){const R=M.trim().split(/\s+/);if(R.length<3)continue;const k=R[0],L=k[0].toUpperCase();let O=[];if(["R","C","L","V","I","D"].includes(L))O=R.slice(1,3),L==="V"&&c.add(k);else if(L==="Q"&&R.length>=4)O=R.slice(1,4);else if(L==="M"&&R.length>=5)O=R.slice(1,5);else if(L==="X")O=R.slice(1,-1);else continue;O.forEach(G=>s.add(G)),L==="C"&&O.forEach(G=>a.add(G))}s.delete("0"),a.delete("0");const l=Array.from(a).map(M=>`.ic V(${M})=0`),A=[],u=Array.from(s).map(M=>`V(${M})`);A.push(...u);const d=Array.from(c).map(M=>`I(${M})`);A.push(...d);const h=A.length>0?`.probe ${A.join(" ")}`:"",_=e?.startTime??0,m=e?.duration??20,p=_*.001,g=m*.001,f=p+g,y=g/50,C=`.tran ${D3e(y)} ${D3e(f)} ${D3e(p)} UIC`,I=".end",E=o.split(`
|
|
5623
5623
|
`);let b=-1;for(let M=E.length-1;M>=0;M--)if(E[M].trim().toLowerCase().startsWith(I)){b=M;break}const P=[...l,h,C].filter(Boolean);let B;if(b!==-1){const M=E.slice(0,b),R=E.slice(b);B=[...M,...P,...R]}else B=[...E,...P,I];return B.join(`
|
|
5624
5624
|
`)},I1o=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},E1o=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},Q3e=ne.createContext(null),b1o=5,S1o=(t,e)=>!t&&!e?!0:!t||!e?!1:t.minX===e.minX&&t.maxX===e.maxX&&t.minY===e.minY&&t.maxY===e.maxY,P1o=({children:t})=>{if(ne.useContext(Q3e))return W.jsx(W.Fragment,{children:t});const n=ne.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),o=ne.useCallback(()=>{for(const u of n.current.subscribers)u()},[]),i=ne.useCallback(()=>{const u=n.current.pointer,d=new Set;if(u)for(const[_,m]of n.current.boundingBoxes){const p=m.bounds;p&&u.x>=p.minX&&u.x<=p.maxX&&u.y>=p.minY&&u.y<=p.maxY&&d.add(_)}const h=n.current.hoveringIds;d.size===h.size&&[...d].every(_=>h.has(_))||(n.current.hoveringIds=d,o())},[o]),r=ne.useCallback((u,d)=>{n.current.boundingBoxes.set(u,d),i()},[i]),s=ne.useCallback((u,d)=>{const h=n.current.boundingBoxes.get(u);h&&S1o(h.bounds,d.bounds)&&h.onClick===d.onClick||(n.current.boundingBoxes.set(u,d),i())},[i]),a=ne.useCallback(u=>{n.current.boundingBoxes.delete(u)&&i()},[i]),c=ne.useCallback(u=>(n.current.subscribers.add(u),()=>{n.current.subscribers.delete(u)}),[]),l=ne.useCallback(u=>n.current.hoveringIds.has(u),[]);ne.useEffect(()=>{const u=m=>{const{clientX:p,clientY:g}=m,f=n.current.pointer;f&&f.x===p&&f.y===g||(n.current.pointer={x:p,y:g},i())},d=()=>{n.current.pointer!==null&&(n.current.pointer=null,n.current.mouseDownPosition=null,i())},h=m=>{n.current.mouseDownPosition={x:m.clientX,y:m.clientY}},_=m=>{const{clientX:p,clientY:g}=m,f=n.current.mouseDownPosition;if(f&&Math.sqrt(Math.pow(p-f.x,2)+Math.pow(g-f.y,2))>b1o){n.current.mouseDownPosition=null;return}n.current.mouseDownPosition=null;for(const y of n.current.boundingBoxes.values()){const C=y.bounds;C&&p>=C.minX&&p<=C.maxX&&g>=C.minY&&g<=C.maxY&&y.onClick?.(m)}};return window.addEventListener("pointermove",u,{passive:!0}),window.addEventListener("pointerdown",u,{passive:!0}),window.addEventListener("pointerup",u,{passive:!0}),window.addEventListener("pointerleave",d),window.addEventListener("pointercancel",d),window.addEventListener("blur",d),window.addEventListener("mousedown",h,{passive:!0}),window.addEventListener("click",_,{passive:!0}),()=>{window.removeEventListener("pointermove",u),window.removeEventListener("pointerdown",u),window.removeEventListener("pointerup",u),window.removeEventListener("pointerleave",d),window.removeEventListener("pointercancel",d),window.removeEventListener("blur",d),window.removeEventListener("mousedown",h),window.removeEventListener("click",_)}},[i]);const A=ne.useMemo(()=>({registerBoundingBox:r,updateBoundingBox:s,unregisterBoundingBox:a,subscribe:c,isHovering:l}),[r,s,a,c,l]);return W.jsx(Q3e.Provider,{value:A,children:t})},BEt=t=>{const e=ne.useContext(Q3e);if(!e)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const n=ne.useId(),o=ne.useRef(t);o.current=t;const i=ne.useMemo(()=>s=>{o.current.onClick?.(s)},[]);return ne.useEffect(()=>(e.registerBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0}),()=>{e.unregisterBoundingBox(n)}),[e,i,n]),ne.useEffect(()=>{e.updateBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0})},[e,i,n,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:ne.useSyncExternalStore(e.subscribe,()=>e.isHovering(n),()=>!1)}},v1o=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,B1o=({componentId:t,svgDivRef:e,containerRef:n,onComponentClick:o,onHoverChange:i,showOutline:r,circuitJsonKey:s})=>{const[a,c]=ne.useState(null),l=ne.useRef(null),A=ne.useCallback(()=>{l.current=null;const p=e.current,g=n.current;if(!p||!g){c(E=>E&&null);return}const f=p.querySelector(`[data-schematic-component-id="${t}"]`);if(!f){c(E=>E&&null);return}const y=f.getBoundingClientRect(),C=g.getBoundingClientRect(),I={bounds:{minX:y.left,maxX:y.right,minY:y.top,maxY:y.bottom},rect:{left:y.left-C.left,top:y.top-C.top,width:y.width,height:y.height}};c(E=>v1o(E,I)?E:I)},[t,n,e]),u=ne.useCallback(()=>{l.current===null&&(l.current=window.requestAnimationFrame(A))},[A]);ne.useEffect(()=>{u()},[u,s]),ne.useEffect(()=>{u();const p=e.current,g=n.current;if(!p||!g)return;const f=typeof ResizeObserver<"u"?new ResizeObserver(()=>{u()}):null;f?.observe(g),f?.observe(p);const y=typeof MutationObserver<"u"?new MutationObserver(()=>{u()}):null;return y?.observe(p,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{f?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},[u,e,n]);const d=ne.useCallback(p=>{o&&o(t,p)},[t,o]),h=a?.bounds??null,{hovering:_}=BEt({bounds:h,onClick:o?d:void 0});if(ne.useEffect(()=>{i&&i(t,_)},[_,t,i]),!a||!_||!r)return null;const m=a.rect;return W.jsx("div",{style:{position:"absolute",left:m.left,top:m.top,width:m.width,height:m.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:Y4.schematicComponentHoverOutline}})},M1o=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,w1o=({portId:t,portLabel:e,svgDivRef:n,containerRef:o,onPortClick:i,onHoverChange:r,showOutline:s,circuitJsonKey:a})=>{const[c,l]=ne.useState(null),A=ne.useRef(null),u=ne.useCallback(()=>{A.current=null;const g=n.current,f=o.current;if(!g||!f){l(P=>P&&null);return}const y=g.querySelector(`[data-schematic-port-id="${t}"]`);if(!y){l(P=>P&&null);return}const C=y.getBoundingClientRect(),I=f.getBoundingClientRect(),E=4,b={bounds:{minX:C.left-E,maxX:C.right+E,minY:C.top-E,maxY:C.bottom+E},rect:{left:C.left-I.left-E,top:C.top-I.top-E,width:C.width+E*2,height:C.height+E*2}};l(P=>M1o(P,b)?P:b)},[t,o,n]),d=ne.useCallback(()=>{A.current===null&&(A.current=window.requestAnimationFrame(u))},[u]);ne.useEffect(()=>{d()},[d,a]),ne.useEffect(()=>{d();const g=n.current,f=o.current;if(!g||!f)return;const y=typeof ResizeObserver<"u"?new ResizeObserver(()=>{d()}):null;y?.observe(f),y?.observe(g);const C=typeof MutationObserver<"u"?new MutationObserver(()=>{d()}):null;return C?.observe(g,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{y?.disconnect(),C?.disconnect(),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),A.current!==null&&(cancelAnimationFrame(A.current),A.current=null)}},[d,n,o]);const h=ne.useCallback(g=>{i&&i(t,g)},[t,i]),_=c?.bounds??null,{hovering:m}=BEt({bounds:_,onClick:i?h:void 0});if(ne.useEffect(()=>{r&&r(t,m)},[m,t,r]),!c||!s)return null;const p=c.rect;return W.jsxs(W.Fragment,{children:[W.jsx("div",{style:{position:"absolute",left:p.left,top:p.top,width:p.width,height:p.height,border:m?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:m?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:Y4.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),m&&e&&W.jsx("div",{style:{position:"absolute",left:p.left+p.width/2,top:p.top-24,transform:"translateX(-50%)",backgroundColor:"rgba(0, 0, 0, 0.85)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",whiteSpace:"nowrap",pointerEvents:"none",zIndex:Y4.schematicPortHoverOutline+1},children:e})]})},D1o=({circuitJson:t,containerStyle:e,editEvents:n=[],onEditEvent:o,defaultEditMode:i=!1,debugGrid:r=!1,editingEnabled:s=!1,debug:a=!1,clickToInteractEnabled:c=!1,colorOverrides:l,spiceSimulationEnabled:A=!1,disableGroups:u=!1,onSchematicComponentClicked:d,showSchematicPorts:h=!1,onSchematicPortClicked:_,css:m,className:p})=>{a&&i1o();const[g,f]=ne.useState(!1),[y,C]=ne.useState({showVoltage:!0,showCurrent:!1,startTime:0,duration:20}),I=rt=>`${rt?.length||0}_${rt?.editCount||0}`,E=ne.useMemo(()=>I(t),[t]),b=ne.useMemo(()=>{if(!A)return null;try{return x1o(t,y)}catch(rt){return console.error("Failed to generate SPICE string",rt),null}},[E,A,y.startTime,y.duration]),[P,B]=ne.useState(!1);ne.useEffect(()=>{B(!1)},[E]);const{plotData:M,nodes:R,isLoading:k,error:L}=C1o(P?b:null),[O,G]=ne.useState(i),[K,X]=ne.useState(!0),[q,oe]=ne.useState(!1),le=r||q,[Z,re]=ne.useState(!c),[ce,ae]=ne.useState(!1),[pe,Ie]=ne.useState(()=>u?!1:I1o("schematic_viewer_show_groups",!1)),[Pe,Be]=ne.useState(!1),me=ne.useRef(new Set),be=ne.useCallback((rt,ft)=>{ft?me.current.add(rt):me.current.delete(rt),Be(me.current.size>0)},[]),[_e,Ne]=ne.useState(!1),Ue=ne.useRef(new Set),We=ne.useCallback((rt,ft)=>{ft?Ue.current.add(rt):Ue.current.delete(rt),Ne(Ue.current.size>0)},[]),fe=ne.useRef(null),qe=ne.useRef(null),He=ne.useMemo(()=>{try{return mp(t).schematic_component?.list()?.map(rt=>rt.schematic_component_id)??[]}catch(rt){return console.error("Failed to derive schematic component ids",rt),[]}},[E,t]),De=ne.useMemo(()=>{if(!h)return[];try{return(mp(t).schematic_port?.list()??[]).map(ft=>{const kt=mp(t).source_port.get(ft.source_port_id),sn=(kt?.source_component_id?mp(t).source_component.get(kt.source_component_id):null)?.name??"?",qn=ft.display_pin_label??kt?.pin_number??kt?.name??"?";return{portId:ft.source_port_id,label:`${sn}.${qn}`}})}catch(rt){return console.error("Failed to derive schematic port info",rt),[]}},[E,t,h]),Ge=rt=>{const ft=rt.touches[0];qe.current={x:ft.clientX,y:ft.clientY}},we=rt=>{const ft=rt.changedTouches[0],kt=qe.current;if(!kt)return;const Ot=Math.abs(ft.clientX-kt.x),sn=Math.abs(ft.clientY-kt.y);Ot<10&&sn<10&&(rt.preventDefault(),re(!0)),qe.current=null},[Se,Fe]=ne.useState([]),Me=ne.useRef(t);ne.useEffect(()=>{const rt=I(t),ft=I(Me.current);rt!==ft&&(Fe([]),Me.current=t)},[t]);const{ref:ze,cancelDrag:je,transform:it}=vF({onSetTransform(rt){fe.current&&(fe.current.style.transform=y1(rt))},enabled:Z&&!g}),{containerWidth:at,containerHeight:At}=PEt(ze),lt=ne.useMemo(()=>!at||!At?"":vZ(t,{width:at,height:At||720,drawPorts:h,grid:le?{cellSize:1,labelCells:!0}:void 0,colorOverrides:l,css:m,className:p}),[E,at,At,le,h]),xt=ne.useMemo(()=>lt.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent",[lt]),Bt=ne.useMemo(()=>{if(!lt)return mA();const rt=lt.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return Iz(rt)}catch(ft){return console.error(ft),mA()}},[lt]),pt=rt=>{Fe(ft=>[...ft,rt]),o&&o(rt)},Mt=ne.useMemo(()=>[...n,...Se],[n,Se]),{handleMouseDown:Ht,handleTouchStart:an,isDragging:cn,activeEditEvent:wn}=a1o({onEditEvent:pt,cancelDrag:je,realToSvgProjection:Bt,svgToScreenProjection:it,circuitJson:t,editEvents:Mt,enabled:O&&Z&&!g,snapToGrid:K});Zfo({svgDivRef:fe,editEvents:Mt,realToSvgProjection:Bt,svgToScreenProjection:it,activeEditEvent:wn}),e1o({svgDivRef:fe,circuitJson:t,activeEditEvent:wn,editEvents:Mt}),t1o({svgDivRef:fe,circuitJson:t,circuitJsonKey:E,showGroups:pe&&!u});const Ce=ne.useRef(an);ne.useEffect(()=>{Ce.current=an},[an]);const et=ne.useMemo(()=>W.jsx("div",{ref:fe,style:{pointerEvents:c?Z?"auto":"none":"auto",transformOrigin:"0 0"},className:d?"schematic-component-clickable":void 0,onTouchStart:rt=>{O&&Z&&!g&&Ce.current(rt)},dangerouslySetInnerHTML:{__html:lt}}),[lt,Z,c,O,g]);return W.jsxs(P1o,{children:[d&&W.jsx("style",{children:".schematic-component-clickable [data-schematic-component-id]:hover { cursor: pointer !important; }"}),_&&W.jsx("style",{children:"[data-schematic-port-id]:hover { cursor: pointer !important; }"}),W.jsxs("div",{ref:ze,style:{position:"relative",backgroundColor:xt,overflow:"hidden",cursor:g?"auto":cn?"grabbing":c&&!Z||Pe&&d||_e&&_?"pointer":"grab",minHeight:"300px",...e},onWheelCapture:rt=>{g&&rt.stopPropagation()},onMouseDown:rt=>{if(c&&!Z){rt.preventDefault(),rt.stopPropagation();return}Ht(rt)},onMouseDownCapture:rt=>{if(c&&!Z){rt.preventDefault(),rt.stopPropagation();return}},onTouchStart:rt=>{g||Ge(rt)},onTouchEnd:rt=>{g||we(rt)},children:[!Z&&c&&W.jsx("div",{onClick:rt=>{rt.preventDefault(),rt.stopPropagation(),re(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:Y4.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"all",touchAction:"pan-x pan-y pinch-zoom"},children:W.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"})}),W.jsx(A1o,{active:ce,onClick:()=>ae(!ce)}),s&&W.jsx(c1o,{active:O,onClick:()=>G(!O)}),s&&O&&W.jsx(l1o,{active:K,onClick:()=>X(!K)}),W.jsx(d1o,{circuitJson:t,circuitJsonKey:E,isVisible:ce,onClose:()=>ae(!1),showGroups:pe,onToggleGroups:rt=>{u||(Ie(rt),E1o("schematic_viewer_show_groups",rt))},showGrid:le,onToggleGrid:oe}),A&&W.jsx(h1o,{onClick:()=>f(!0)}),g&&W.jsx(g1o,{spiceString:b,onClose:()=>f(!1),plotData:M,nodes:R,isLoading:k,error:L,simOptions:y,onSimOptionsChange:rt=>{B(!0),C(rt)},hasRun:P}),d&&He.map(rt=>W.jsx(B1o,{componentId:rt,svgDivRef:fe,containerRef:ze,showOutline:!0,circuitJsonKey:E,onHoverChange:be,onComponentClick:(ft,kt)=>{d?.({schematicComponentId:ft,event:kt})}},rt)),et,h&&De.map(({portId:rt,label:ft})=>W.jsx(w1o,{portId:rt,portLabel:ft,svgDivRef:fe,containerRef:ze,showOutline:!0,circuitJsonKey:E,onHoverChange:We,onPortClick:_?(kt,Ot)=>{_?.({schematicPortId:kt,event:Ot})}:void 0},rt))]})]})},Q1o=1200,T1o=1,R1o=({circuitJson:t,containerStyle:e,colorOverrides:n,width:o,height:i,className:r})=>{const[s,a]=ne.useState(null),[c,l]=ne.useState(!0),[A,u]=ne.useState(null),[d,h]=ne.useState(null),_=ne.useRef(null),m=ne.useRef(null),{containerWidth:p}=PEt(_),[g,f]=ne.useState(!1),{ref:y}=vF({onSetTransform(O){m.current&&(m.current.style.transform=y1(O))}}),C=o&&i?o/i:T1o,I=o||(i?i*C:p)||Q1o,E=i||I/C;ne.useEffect(()=>{l(!0),u(null),a(t),l(!1)},[t]);const b=ne.useMemo(()=>s&&s.find(G=>G.type==="simulation_experiment")?.simulation_experiment_id||null,[s]),P=ne.useMemo(()=>s?s.filter(O=>O.type==="simulation_transient_voltage_graph").map(O=>O.simulation_transient_voltage_graph_id):[],[s]),B=ne.useMemo(()=>s?s.filter(O=>O.type==="simulation_transient_current_graph").map(O=>O.simulation_transient_current_graph_id):[],[s]),M=ne.useMemo(()=>{if(!s||!I||!E||!b)return"";try{return y5t({circuitJson:s,simulation_experiment_id:b,simulation_transient_current_graph_ids:B,simulation_transient_voltage_graph_ids:P,width:I,height:E,schematicOptions:{colorOverrides:n}})}catch(O){return console.error("Failed to generate fallback schematic SVG:",O),""}},[s,I,E,n,b,B,P]);ne.useEffect(()=>{if(!M){h(null);return}try{const O=new Blob([M],{type:"image/svg+xml"}),G=URL.createObjectURL(O);return h(G),()=>{URL.revokeObjectURL(G)}}catch(O){console.error("Failed to create SVG object URL:",O),h(null)}},[M]);const R=ne.useMemo(()=>M?M.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent":"transparent",[M]),k=O=>{f(!0)},L=O=>{f(!0)};return ne.useEffect(()=>{const O=()=>{f(!1)},G=()=>{f(!1)};return window.addEventListener("mouseup",O),window.addEventListener("touchend",G),()=>{window.removeEventListener("mouseup",O),window.removeEventListener("touchend",G)}},[]),c?W.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f5f5f5",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#666",...e},className:r,children:"Loading circuit..."}):A?W.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#fef2f2",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#dc2626",...e},className:r,children:W.jsxs("div",{style:{textAlign:"center",padding:"20px"},children:[W.jsx("div",{style:{fontWeight:"bold",marginBottom:"8px"},children:"Circuit Conversion Error"}),W.jsx("div",{style:{fontSize:"14px"},children:A})]})}):M?W.jsx("div",{ref:O=>{_.current=O,y.current=O},style:{position:"relative",backgroundColor:R,overflow:"hidden",minHeight:"300px",cursor:g?"grabbing":"grab",...e},className:r,onMouseDown:k,onTouchStart:L,children:d?W.jsx("img",{ref:m,src:d,alt:"Circuit Simulation",style:{transformOrigin:"0 0",width:"100%",height:"100%",display:"block",objectFit:"contain"}}):W.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",minHeight:"300px",color:"#666",fontFamily:"sans-serif"},children:"Failed to render SVG"})}):W.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"#f8fafc",minHeight:"300px",fontFamily:"sans-serif",gap:"12px",...e},className:r,children:[W.jsx("div",{style:{fontSize:"16px",color:"#475569",fontWeight:500},children:"No Simulation Found"}),W.jsxs("div",{style:{fontSize:"14px",color:"#64748b"},children:["Use"," ",W.jsx("code",{style:{backgroundColor:"#e2e8f0",padding:"2px 6px",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px"},children:"<analogsimulation />"})," ","to create simulations"]})]})},MEt=t=>{const[e,n]=ne.useState(0),[o,i]=ne.useState(0);return ne.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}};gA("assembly-viewer");var wEt=()=>{gA.enable("assembly-viewer*")},N1o=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&wEt();const i=ne.useRef(null),{ref:r}=vF({onSetTransform(A){i.current&&(i.current.style.transform=y1(A))}}),{containerWidth:s,containerHeight:a}=MEt(r),c=ne.useMemo(()=>!s||!a?"":QIt(t,{width:s,height:a||720}),[t,s,a]);ne.useMemo(()=>{if(!c)return mA();const A=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return Iz(A)}catch(u){return console.error(u),mA()}},[c]);const l=ne.useMemo(()=>W.jsx("div",{ref:i,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return W.jsx("div",{ref:r,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})},k1o=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&wEt();const i=ne.useRef(null),{ref:r}=vF({onSetTransform(A){i.current&&(i.current.style.transform=y1(A))}}),{containerWidth:s,containerHeight:a}=MEt(r),c=ne.useMemo(()=>!s||!a?"":GIt(t,{width:s,height:a||720}),[t,s,a]);ne.useMemo(()=>{if(!c)return mA();const A=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return Iz(A)}catch(u){return console.error(u),mA()}},[c]);const l=ne.useMemo(()=>W.jsx("div",{ref:i,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return W.jsx("div",{ref:r,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})};const DEt=["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."],H1o=(()=>{let t=DEt[Math.floor(Math.random()*DEt.length)];return t=t.replace(/</g,"<"),t=t.replace(/>/g,">"),t=t.replace(new RegExp('(?<!href=")(?<!\\()(?<!\\]\\()(https?:\\/\\/[^\\s\\)\\]]+)',"g"),(e,n)=>`<a class="rf-text-blue-500 rf-underline" href="${e}" target="_blank">${e}</a>`),t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/g,'<a class="rf-text-blue-500 rf-underline" href="$2" target="_blank">$1</a>'),t})(),Fb=({onRunClicked:t})=>W.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:[W.jsx(Jao,{className:"rf-size-14 rf-mb-4"}),W.jsxs("p",{className:"rf-text-md rf-break-words rf-max-w-xl rf-text-center",children:["Tip: ",W.jsx("span",{dangerouslySetInnerHTML:{__html:H1o}})]}),t&&W.jsxs(zu,{className:"rf-mt-4 rf-bg-blue-600 rf-hover:bg-blue-500",onClick:t,children:["Run Code",W.jsx(eco,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),cee=({text:t,onClick:e})=>W.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:e,children:t}),lee=t=>W.jsxs("div",{className:"rf-leading-5",children:[W.jsx("div",{className:"rf-py-2 rf-font-bold",children:t.column.name}),W.jsx("div",{children:t.field?.()??W.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:e=>{t.onTextChange?.(e.target.value)}})})]}),L1o=({open:t,children:e,title:n,onClose:o})=>t?W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-justify-center rf-items-center rf-z-50",onClick:o,children:W.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:i=>{i.preventDefault(),i.stopPropagation()},children:[W.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:n}),W.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:o,children:"×"}),e]})}):null,F1o=({elements:t})=>{const[e,n]=ne.useState({open:!1}),[o,i]=ne.useReducer((A,u)=>({...A,...u}),{}),r=[...new Set(t.map(A=>A.type))],s=t.map(A=>{const u=A[`${A.type}_id`],d=Object.fromEntries(Object.entries(A).filter(([_])=>!(_===`${A.type}_id`||!_.endsWith("_id")))),h=Object.fromEntries(Object.entries(A).filter(([_])=>!_.endsWith("_id")));return{primary_id:u,other_ids:d,...h,_og_elm:A}}),a=s.map(A=>{let u="";const d=h=>{const _=Object.keys(h.other_ids).find(g=>g.startsWith("source_"));if(!_)return`.${h.name}`;const m=_.slice(0,-3),p=s.find(g=>g.type===m&&g.primary_id===h.other_ids[_]);return p?"name"in p?`${d(p)} > .${h.name}`:`#${p.primary_id} > .${h.name}`:`??? > .${h.name}`};return"name"in A&&(u=d(A)),{...A,selector_path:u}}),c=[{key:"primary_id",name:"primary_id",renderCell:A=>W.jsxs("div",{className:"rf-flex rf-items-center",children:[W.jsx(cee,{text:A.primary_id,onClick:()=>i({focused_id:A.primary_id,id_search:void 0,selector_search:void 0})}),W.jsx("span",{className:"rf-flex-grow"}),W.jsx(cee,{text:"(JSON)",onClick:()=>n({open:!0,element:A._og_elm,title:A.primary_id})})]}),renderHeaderCell:A=>W.jsx(lee,{column:A,onTextChange:u=>i({id_search:u}),field:o.focused_id?()=>W.jsxs("div",{children:["Focus:"," ",W.jsx("span",{className:"rf-underline",children:o.focused_id}),W.jsx(cee,{text:"(unfocus)",onClick:()=>i({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:A=>W.jsx(lee,{column:A,field:()=>W.jsxs("select",{onChange:u=>i({component_type_filter:u.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[W.jsx("option",{value:"any",children:"any"},"any"),W.jsx("option",{value:"source",children:"source"},"source"),W.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),W.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),r.map(u=>W.jsx("option",{value:u,children:u},u))]})})},{key:"name",name:"name",renderHeaderCell:A=>W.jsx(lee,{column:A,onTextChange:u=>i({name_search:u})})},{key:"selector_path",name:"selector_path",renderHeaderCell:A=>W.jsx(lee,{column:A,onTextChange:u=>i({selector_search:u})})},{key:"other_ids",name:"other_ids",renderCell:A=>W.jsx("div",{className:"rf-space-x-2",children:Object.entries(A.other_ids).map(([u,d])=>W.jsx(cee,{text:d,onClick:()=>i({focused_id:d})},d))})}],l=a.filter(A=>o.name_search?A.name?.toLowerCase()?.includes(o.name_search.toLowerCase()):!0).filter(A=>!o.component_type_filter||o.component_type_filter==="any"?!0:o.component_type_filter==="source"?A.type.startsWith("source_"):o.component_type_filter==="source/pcb"?A.type.startsWith("source_")||A.type.startsWith("pcb_"):o.component_type_filter==="source/schematic"?A.type.startsWith("source_")||A.type.startsWith("schematic_"):A.type?.includes(o.component_type_filter)).filter(A=>o.selector_search?o.selector_search.split(" ").filter(d=>d.length>0).every(d=>A.selector_path?.includes(d)):!0).filter(A=>o.id_search?A.primary_id?.includes(o.id_search):!0).filter(A=>!!(!o.focused_id||A.primary_id===o.focused_id||Object.values(A.other_ids).includes(o.focused_id)));return W.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[W.jsx("div",{className:"rf-overflow-x-auto",children:W.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[W.jsx("thead",{children:W.jsx("tr",{children:c.map(A=>W.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:A.renderHeaderCell?A.renderHeaderCell(A):A.name},A.key))})}),W.jsx("tbody",{children:l.map((A,u)=>W.jsx("tr",{className:"rf-hover:bg-gray-100",children:c.map(d=>W.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:d.renderCell?d.renderCell(A):A[d.key]},d.key))},u))})]})}),W.jsx(L1o,{open:e.open,onClose:()=>n({open:!1}),title:e.open?e.title:"",children:W.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:W.jsx("pre",{className:"rf-whitespace-pre-wrap",children:e.open?JSON.stringify(e.element,null,2):""})})})]})};var XF={},T3e={},QEt;function O1o(){return QEt||(QEt=1,(function(t){Object.defineProperty(t,"__esModule",{value:!0});var e=(function(){function r(s,a){var c=[],l=!0,A=!1,u=void 0;try{for(var d=s[Symbol.iterator](),h;!(l=(h=d.next()).done)&&(c.push(h.value),!(a&&c.length===a));l=!0);}catch(_){A=!0,u=_}finally{try{!l&&d.return&&d.return()}finally{if(A)throw u}}return c}return function(s,a){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return r(s,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();t.default=o,t.parseUnitObj=i;var n=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function o(r){var s=parseFloat(r),a=r.match(n)||[],c=a.length>0?r.substr(a[0].length).trim():"";return[s,c]}function i(r){var s=o(r),a=e(s,2),c=a[0],l=a[1];return{val:c,unit:l}}})(T3e)),T3e}var TEt;function G1o(){if(TEt)return XF;TEt=1,Object.defineProperty(XF,"__esModule",{value:!0});var t=(function(){function c(l,A){var u=[],d=!0,h=!1,_=void 0;try{for(var m=l[Symbol.iterator](),p;!(d=(p=m.next()).done)&&(u.push(p.value),!(A&&u.length===A));d=!0);}catch(g){h=!0,_=g}finally{try{!d&&m.return&&m.return()}finally{if(h)throw _}}return u}return function(l,A){if(Array.isArray(l))return l;if(Symbol.iterator in Object(l))return c(l,A);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();XF.formatSI=r,XF.unformatSI=a;function e(c){return c&&c.__esModule?c:{default:c}}var n=O1o(),o=e(n),i={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function r(c){if(c===0)return"0";for(var l=Math.abs(c),A=0;l>=1e3&&A<24;)l/=1e3,A+=3;for(;l<1&&A>-24;)l*=1e3,A-=3;var u=c<0?"-":"";return l>1e3?u+l.toFixed(0)+i[A]:u+parseFloat(l.toPrecision(3))+i[A]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function a(c){if(c==null||c==="")return NaN;var l=(0,o.default)(c),A=t(l,2),u=A[0],d=A[1],h=s[d];return u*h}return XF}var U1o=G1o(),Aee={exports:{}};var z1o=Aee.exports,REt;function V1o(){return REt||(REt=1,(function(t,e){((n,o)=>{t.exports=o()})(z1o,function n(){var o=typeof self<"u"?self:typeof window<"u"?window:o!==void 0?o:{},i,r=!o.document&&!!o.postMessage,s=o.IS_PAPA_WORKER||!1,a={},c=0,l={};function A(B){return B.charCodeAt(0)===65279?B.slice(1):B}function u(B){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(M){var R=E(M);R.chunkSize=parseInt(R.chunkSize),M.step||M.chunk||(R.chunkSize=null),this._handle=new p(R),(this._handle.streamer=this)._config=R}).call(this,B),this.parseChunk=function(M,R){var k=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<k){let O=this._config.newline;O||(L=this._config.quoteChar||'"',O=this._handle.guessLineEndings(M,L)),M=[...M.split(O).slice(k)].join(O)}this.isFirstChunk&&P(this._config.beforeFirstChunk)&&(L=this._config.beforeFirstChunk(M))!==void 0&&(M=L),this.isFirstChunk=!1,this._halted=!1;var k=this._partialLine+M,L=(this._partialLine="",this._handle.parse(k,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(M=L.meta.cursor,k=(this._finished||(this._partialLine=k.substring(M-this._baseIndex),this._baseIndex=M),L&&L.data&&(this._rowCount+=L.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)o.postMessage({results:L,workerId:l.WORKER_ID,finished:k});else if(P(this._config.chunk)&&!R){if(this._config.chunk(L,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=L=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(L.data),this._completeResults.errors=this._completeResults.errors.concat(L.errors),this._completeResults.meta=L.meta),this._completed||!k||!P(this._config.complete)||L&&L.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),k||L&&L.meta.paused||this._nextChunk(),L}this._halted=!0},this._sendError=function(M){P(this._config.error)?this._config.error(M):s&&this._config.error&&o.postMessage({workerId:l.WORKER_ID,error:M,finished:!1})}}function d(B){var M;(B=B||{}).chunkSize||(B.chunkSize=l.RemoteChunkSize),u.call(this,B),this._nextChunk=r?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(R){this._input=R,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(M=new XMLHttpRequest,this._config.withCredentials&&(M.withCredentials=this._config.withCredentials),r||(M.onload=b(this._chunkLoaded,this),M.onerror=b(this._chunkError,this)),M.open(this._config.downloadRequestBody?"POST":"GET",this._input,!r),this._config.downloadRequestHeaders){var R,k=this._config.downloadRequestHeaders;for(R in k)M.setRequestHeader(R,k[R])}var L;this._config.chunkSize&&(L=this._start+this._config.chunkSize-1,M.setRequestHeader("Range","bytes="+this._start+"-"+L));try{M.send(this._config.downloadRequestBody)}catch(O){this._chunkError(O.message)}r&&M.status===0&&this._chunkError()}},this._chunkLoaded=function(){M.readyState===4&&(M.status<200||400<=M.status?this._chunkError():(this._start+=this._config.chunkSize||M.responseText.length,this._finished=!this._config.chunkSize||this._start>=(R=>(R=R.getResponseHeader("Content-Range"))!==null?parseInt(R.substring(R.lastIndexOf("/")+1)):-1)(M),this.parseChunk(M.responseText)))},this._chunkError=function(R){R=M.statusText||R,this._sendError(new Error(R))}}function h(B){(B=B||{}).chunkSize||(B.chunkSize=l.LocalChunkSize),u.call(this,B);var M,R,k=typeof FileReader<"u";this.stream=function(L){this._input=L,R=L.slice||L.webkitSlice||L.mozSlice,k?((M=new FileReader).onload=b(this._chunkLoaded,this),M.onerror=b(this._chunkError,this)):M=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var L=this._input,O=(this._config.chunkSize&&(O=Math.min(this._start+this._config.chunkSize,this._input.size),L=R.call(L,this._start,O)),M.readAsText(L,this._config.encoding));k||this._chunkLoaded({target:{result:O}})},this._chunkLoaded=function(L){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(L.target.result)},this._chunkError=function(){this._sendError(M.error)}}function _(B){var M;u.call(this,B=B||{}),this.stream=function(R){return M=R,this._nextChunk()},this._nextChunk=function(){var R,k;if(!this._finished)return R=this._config.chunkSize,M=R?(k=M.substring(0,R),M.substring(R)):(k=M,""),this._finished=!M,this.parseChunk(k)}}function m(B){u.call(this,B=B||{});var M=[],R=!0,k=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(L){this._input=L,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){k&&M.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),M.length?this.parseChunk(M.shift()):R=!0},this._streamData=b(function(L){try{M.push(typeof L=="string"?L:L.toString(this._config.encoding)),R&&(R=!1,this._checkIsFinished(),this.parseChunk(M.shift()))}catch(O){this._streamError(O)}},this),this._streamError=b(function(L){this._streamCleanUp(),this._sendError(L)},this),this._streamEnd=b(function(){this._streamCleanUp(),k=!0,this._streamData("")},this),this._streamCleanUp=b(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function p(B){var M,R,k,L,O=Math.pow(2,53),G=-O,K=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,X=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,q=this,oe=0,le=0,Z=!1,re=!1,ce=[],ae={data:[],errors:[],meta:{}};function pe(me){return B.skipEmptyLines==="greedy"?me.join("").trim()==="":me.length===1&&me[0].length===0}function Ie(){if(ae&&k&&(Be("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+l.DefaultDelimiter+"'"),k=!1),B.skipEmptyLines&&(ae.data=ae.data.filter(function(Ne){return!pe(Ne)})),Pe()){let Ne=function(Ue,We){Ue=A(Ue),P(B.transformHeader)&&(Ue=B.transformHeader(Ue,We)),ce.push(Ue)};if(ae)if(Array.isArray(ae.data[0])){for(var me=0;Pe()&&me<ae.data.length;me++)ae.data[me].forEach(Ne);ae.data.splice(0,1)}else ae.data.forEach(Ne)}function be(Ne,Ue){for(var We=B.header?{}:[],fe=0;fe<Ne.length;fe++){var qe=fe,He=Ne[fe],He=((De,Ge)=>(we=>(B.dynamicTypingFunction&&B.dynamicTyping[we]===void 0&&(B.dynamicTyping[we]=B.dynamicTypingFunction(we)),(B.dynamicTyping[we]||B.dynamicTyping)===!0))(De)?Ge==="true"||Ge==="TRUE"||Ge!=="false"&&Ge!=="FALSE"&&((we=>{if(K.test(we)&&(we=parseFloat(we),G<we&&we<O))return 1})(Ge)?parseFloat(Ge):X.test(Ge)?new Date(Ge):Ge===""?null:Ge):Ge)(qe=B.header?fe>=ce.length?"__parsed_extra":ce[fe]:qe,He=B.transform?B.transform(He,qe):He);qe==="__parsed_extra"?(We[qe]=We[qe]||[],We[qe].push(He)):We[qe]=He}return B.header&&(fe>ce.length?Be("FieldMismatch","TooManyFields","Too many fields: expected "+ce.length+" fields but parsed "+fe,le+Ue):fe<ce.length&&Be("FieldMismatch","TooFewFields","Too few fields: expected "+ce.length+" fields but parsed "+fe,le+Ue)),We}var _e;ae&&(B.header||B.dynamicTyping||B.transform)&&(_e=1,!ae.data.length||Array.isArray(ae.data[0])?(ae.data=ae.data.map(be),_e=ae.data.length):ae.data=be(ae.data,0),B.header&&ae.meta&&(ae.meta.fields=ce),le+=_e)}function Pe(){return B.header&&ce.length===0}function Be(me,be,_e,Ne){me={type:me,code:be,message:_e},Ne!==void 0&&(me.row=Ne),ae.errors.push(me)}P(B.step)&&(L=B.step,B.step=function(me){ae=me,Pe()?Ie():(Ie(),ae.data.length!==0&&(oe+=me.data.length,B.preview&&oe>B.preview?R.abort():(ae.data=ae.data[0],L(ae,q))))}),this.parse=function(me,be,_e){var Ne=B.quoteChar||'"',Ne=(B.newline||(B.newline=this.guessLineEndings(me,Ne)),k=!1,B.delimiter?P(B.delimiter)&&(B.delimiter=B.delimiter(me),ae.meta.delimiter=B.delimiter):((Ne=((Ue,We,fe,qe,He)=>{var De,Ge,we,Se;He=He||[","," ","|",";",l.RECORD_SEP,l.UNIT_SEP];for(var Fe=0;Fe<He.length;Fe++){for(var Me,ze=He[Fe],je=0,it=0,at=0,At=(we=void 0,new f({comments:qe,delimiter:ze,newline:We,preview:10}).parse(Ue)),lt=0;lt<At.data.length;lt++)fe&&pe(At.data[lt])?at++:(Me=At.data[lt].length,it+=Me,we===void 0?we=Me:0<Me&&(je+=Math.abs(Me-we),we=Me));0<At.data.length&&(it/=At.data.length-at),(Ge===void 0||je<=Ge)&&(Se===void 0||Se<it)&&1.99<it&&(Ge=je,De=ze,Se=it)}return{successful:!!(B.delimiter=De),bestDelimiter:De}})(me,B.newline,B.skipEmptyLines,B.comments,B.delimitersToGuess)).successful?B.delimiter=Ne.bestDelimiter:(k=!0,B.delimiter=l.DefaultDelimiter),ae.meta.delimiter=B.delimiter),E(B));return B.preview&&B.header&&Ne.preview++,M=me,R=new f(Ne),ae=R.parse(M,be,_e),Ie(),Z?{meta:{paused:!0}}:ae||{meta:{paused:!1}}},this.paused=function(){return Z},this.pause=function(){Z=!0,R.abort(),M=P(B.chunk)?"":M.substring(R.getCharIndex())},this.resume=function(){q.streamer._halted?(Z=!1,q.streamer.parseChunk(M,!0)):setTimeout(q.resume,3)},this.aborted=function(){return re},this.abort=function(){re=!0,R.abort(),ae.meta.aborted=!0,P(B.complete)&&B.complete(ae),M=""},this.guessLineEndings=function(Ue,Ne){Ue=Ue.substring(0,1048576);var Ne=new RegExp(g(Ne)+"([^]*?)"+g(Ne),"gm"),_e=(Ue=Ue.replace(Ne,"")).split("\r"),Ne=Ue.split(`
|
|
@@ -5786,7 +5786,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5786
5786
|
// Add more specific assertions based on expected output
|
|
5787
5787
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5788
5788
|
})
|
|
5789
|
-
`,u=new Blob([A],{type:"text/plain"}),d=URL.createObjectURL(u),h=document.createElement("a");h.href=d,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},DSt=t=>t.activeSubSolver?[t,...DSt(t.activeSubSolver)]:[t],I5o=({solver:t})=>{const e=DSt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(x5o,{solver:n})]},n.constructor.name))})},E5o=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ne.useReducer(m=>!m,!1),a=ne.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};ne.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),ne.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,_=h?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(I5o,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:d,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),_&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:_})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},b5o=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},S5o=(t,e)=>{const o=t.pipelineDef[e].solverName,i=b5o(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const d=t.pipelineDef[e+1],h=d?t.firstIterationOfPhase?.[d.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},P5o=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${e[t]}`,children:t})},v5o=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},B5o=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),M5o=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=B5o(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},pPe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(pPe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=pPe(o));return e},w5o=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=pPe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},D5o=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>S5o(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):w5o(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(P5o,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(v5o,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(M5o,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Q5o=class extends Or.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function T5o({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,C=p.height??0;A(g,f),A(g+y,f+C)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,d=s-u,h=a-u,_=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${h} ${_} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>W.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>W.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>W.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var R5o=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=ne.useReducer(A=>A+1,0),s=ne.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=ne.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);ne.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(d=>d.solverName===A);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(E5o,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(Q5o,{fallback:W.jsx(T5o,{graphics:s}),children:W.jsx(C5o,{graphics:s})}),c&&W.jsx(D5o,{solver:t,onStepUntilPhase:l})]})};const N5o=()=>{ne.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},k5o=t=>t.toLowerCase().includes("pack")?Xao:t.toLowerCase().includes("rout")?tco:Oao,H5o=({solverEvents:t=[]})=>{const[e,n]=ne.useState(null);N5o();const o=ne.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=ne.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ne.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=efe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(efe).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=k5o(c.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsx(N4,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:W.jsx(R5o,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},QSt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ne.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{F9.captureException(o)}catch{}}},[t,e]),ne.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{F9.captureException(i,{error_type:o.type})}catch{}}},[n])},L5o=t=>{ne.useEffect(()=>{try{I7t(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},TSt="0.0.2113",F5o={version:TSt},fPe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},yPe=new Map,Fee=t=>{const e=yPe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},O5o=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=yPe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return yPe.set(n.name,i),{type:"tracked",store:t,...i}},RSt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...c}=e;let l;try{l=(r??(fPe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(fPe?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:A,...u}=O5o(a,l,c);let d=!0;i.setState=(m,p,g)=>{const f=n(m,p);if(!d)return f;const y=g===void 0?{type:s||"anonymous"}:typeof g=="string"?{type:g}:g;return a===void 0?(A?.send(y,o()),f):(A?.send({...y,type:`${a}/${y.type}`},{...Fee(c.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=d;d=!1,n(...m),d=p},_=t(i.setState,o,i);if(u.type==="untracked"?A?.init(_):(u.stores[u.store]=i,A?.init(Object.fromEntries(Object.entries(u.stores).map(([m,p])=>[m,m===u.store?_:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(...g)=>{(fPe?"production":void 0)!=="production"&&g[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(...g)}}return A.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return CPe(m.payload,g=>{if(g.type==="__setState"){if(a===void 0){h(g.state);return}Object.keys(g.state).length!==1&&console.error(`
|
|
5789
|
+
`,u=new Blob([A],{type:"text/plain"}),d=URL.createObjectURL(u),h=document.createElement("a");h.href=d,h.download=`${l}.test.ts`,h.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return W.jsxs("div",{className:`relative ${e}`,ref:i,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},DSt=t=>t.activeSubSolver?[t,...DSt(t.activeSubSolver)]:[t],I5o=({solver:t})=>{const e=DSt(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>W.jsxs("div",{className:"flex items-center",children:[o>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(x5o,{solver:n})]},n.constructor.name))})},E5o=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=ne.useReducer(m=>!m,!1),a=ne.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};ne.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),ne.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const h=t.getCurrentPhase!==void 0,_=h?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(I5o,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),W.jsx("button",{onClick:d,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),h&&W.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),_&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:_})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},b5o=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},S5o=(t,e)=>{const o=t.pipelineDef[e].solverName,i=b5o(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const d=t.pipelineDef[e+1],h=d?t.firstIterationOfPhase?.[d.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},P5o=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${e[t]}`,children:t})},v5o=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},B5o=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),M5o=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const e=Object.entries(t),n=B5o(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),W.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>W.jsxs("div",{children:[o,": ",String(i)]},o))})]})},pPe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(pPe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=pPe(o));return e},w5o=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=pPe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},D5o=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>S5o(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):w5o(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:o.map(a=>W.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(P5o,{status:a.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(v5o,{progress:a.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(M5o,{stats:a.stats})}),W.jsx("td",{className:"px-4 py-2",children:a.solverInstance?W.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Q5o=class extends Or.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function T5o({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,C=p.height??0;A(g,f),A(g+y,f+C)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,d=s-u,h=a-u,_=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${h} ${_} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>W.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>W.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${g}`)),i.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>W.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>W.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var R5o=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=ne.useReducer(A=>A+1,0),s=ne.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=ne.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);ne.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(d=>d.solverName===A);)t.step();r()}};return W.jsxs("div",{children:[W.jsx(E5o,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(Q5o,{fallback:W.jsx(T5o,{graphics:s}),children:W.jsx(C5o,{graphics:s})}),c&&W.jsx(D5o,{solver:t,onStepUntilPhase:l})]})};const N5o=()=>{ne.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},k5o=t=>t.toLowerCase().includes("pack")?Xao:t.toLowerCase().includes("rout")?tco:Oao,H5o=({solverEvents:t=[]})=>{const[e,n]=ne.useState(null);N5o();const o=ne.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=ne.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=ne.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=efe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(efe).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=k5o(c.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?W.jsx(N4,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:W.jsx(R5o,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},QSt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{ne.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{F9.captureException(o)}catch{}}},[t,e]),ne.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{F9.captureException(i,{error_type:o.type})}catch{}}},[n])},L5o=t=>{ne.useEffect(()=>{try{I7t(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},TSt="0.0.2114",F5o={version:TSt},fPe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},yPe=new Map,Fee=t=>{const e=yPe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},O5o=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=yPe.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return yPe.set(n.name,i),{type:"tracked",store:t,...i}},RSt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...c}=e;let l;try{l=(r??(fPe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(fPe?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:A,...u}=O5o(a,l,c);let d=!0;i.setState=(m,p,g)=>{const f=n(m,p);if(!d)return f;const y=g===void 0?{type:s||"anonymous"}:typeof g=="string"?{type:g}:g;return a===void 0?(A?.send(y,o()),f):(A?.send({...y,type:`${a}/${y.type}`},{...Fee(c.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=d;d=!1,n(...m),d=p},_=t(i.setState,o,i);if(u.type==="untracked"?A?.init(_):(u.stores[u.store]=i,A?.init(Object.fromEntries(Object.entries(u.stores).map(([m,p])=>[m,m===u.store?_:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(...g)=>{(fPe?"production":void 0)!=="production"&&g[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(...g)}}return A.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return CPe(m.payload,g=>{if(g.type==="__setState"){if(a===void 0){h(g.state);return}Object.keys(g.state).length!==1&&console.error(`
|
|
5790
5790
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5791
5791
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5792
5792
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|