@tscircuit/runframe 0.0.1937 → 0.0.1938

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1821,7 +1821,7 @@ var useErrorTelemetry = ({
1821
1821
  };
1822
1822
 
1823
1823
  // package.json
1824
- var version = "0.0.1936";
1824
+ var version = "0.0.1937";
1825
1825
  var package_default = {
1826
1826
  name: "@tscircuit/runframe",
1827
1827
  main: "dist/preview.js",
@@ -2055,7 +2055,17 @@ async function getEvents(since) {
2055
2055
  const data = await response.json();
2056
2056
  return data.event_list;
2057
2057
  }
2058
- var DYNAMIC_FILE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".json"];
2058
+ var DYNAMIC_FILE_EXTENSIONS = [
2059
+ ".tsx",
2060
+ ".ts",
2061
+ ".jsx",
2062
+ ".js",
2063
+ ".json",
2064
+ ".kicad_pcb",
2065
+ ".kicad_sch",
2066
+ ".kicad_prl",
2067
+ ".kicad_pro"
2068
+ ];
2059
2069
  async function getInitialFilesFromApi() {
2060
2070
  const response = await fetch(`${API_BASE}/files/list`);
2061
2071
  const { file_list } = await response.json();
package/dist/preview.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  SchematicViewer,
8
8
  useOrderDialog,
9
9
  useOrderDialogCli
10
- } from "./chunk-ENHPE6YV.js";
10
+ } from "./chunk-QCA2MAUV.js";
11
11
  export {
12
12
  BomTable,
13
13
  CadViewer,
package/dist/runner.js CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  useRunFrameStore,
34
34
  useRunnerStore,
35
35
  useStyles
36
- } from "./chunk-ENHPE6YV.js";
36
+ } from "./chunk-QCA2MAUV.js";
37
37
 
38
38
  // lib/components/RunFrame/RunFrame.tsx
39
39
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5691,11 +5691,11 @@ test("${l} should solve problem correctly", () => {
5691
5691
  // Add more specific assertions based on expected output
5692
5692
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5693
5693
  })
5694
- `,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:r,children:[j.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&j.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},fct=t=>t.activeSubSolver?[t,...fct(t.activeSubSolver)]:[t],t$n=({solver:t})=>{const e=fct(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(e$n,{solver:n})]},n.constructor.name))})},n$n=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=te.useReducer(p=>!p,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),r&&r(t))},u=()=>{i?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),r&&t.solved&&r(t);return}t.step(),e()},n))},_=()=>{const p=t;if(p.getCurrentPhase&&!t.solved&&!t.failed){const x=p.getCurrentPhase();for(;p.getCurrentPhase()===x&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||i)return;const p=window.prompt("Step until which iteration?",`${t.iterations}`);if(p===null)return;const x=Number(p);if(!Number.isFinite(x)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<x&&!t.solved&&!t.failed;)t.step();e(),t.solved&&r&&r(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&i&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,i]);const m=t.getCurrentPhase!==void 0,h=m?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(t$n,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:c,disabled:t.solved||t.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),j.jsx("button",{onClick:d,disabled:t.solved||t.failed||i,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),m&&j.jsx("button",{onClick:_,disabled:t.solved||t.failed||i,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:h})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},o$n=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},r$n=(t,e)=>{const o=t.pipelineDef[e].solverName,r=o$n(t,e),i=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(r==="Completed"){const d=t.pipelineDef[e+1],m=d?t.firstIterationOfPhase?.[d.solverName]:void 0;m!==void 0&&s!==null?c=m-s:s!==null&&(c=a-s)}else r==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let u=0;r==="Completed"?u=1:r==="In Progress"&&i&&(u=i.progress??0);const _=i?.stats??null;return{index:e,name:o,status:r,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:_&&Object.keys(_).length>0?_:null,solverInstance:i??null}},i$n=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},s$n=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},a$n=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),c$n=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=a$n(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>j.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Txe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Txe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Txe(o));return e},l$n=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Txe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=`${e}_input.json`,i.click(),URL.revokeObjectURL(r)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},u$n=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>r$n(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):l$n(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>r(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(i$n,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(s$n,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(c$n,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>i(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},_$n=class extends or.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function d$n({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],r=t.circles??[],i=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(x,f)=>{typeof x=="number"&&(x<s&&(s=x),x>c&&(c=x)),typeof f=="number"&&(f<a&&(a=f),f>l&&(l=f))};for(const x of e)u(x.x,x.y);for(const x of n){const f=x.points??[];for(const g of f)u(g.x,g.y)}for(const x of o){const f=x.x??0,g=x.y??0,y=x.width??0,P=x.height??0;u(f,g),u(f+y,g+P)}for(const x of r){const f=x.x??0,g=x.y??0,y=x.radius??1;u(f-y,g-y),u(f+y,g+y)}for(const x of i)u(x.x,x.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const _=10,d=s-_,m=a-_,h=Math.max(1,c-s+2*_),p=Math.max(1,l-a+2*_);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${m} ${h} ${p}`,role:"img","aria-label":"Graphics fallback",children:[o.map((x,f)=>j.jsx("rect",{x:x.x??0,y:x.y??0,width:x.width??0,height:x.height??0,fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`rect-${f}`)),n.map((x,f)=>j.jsx("polyline",{fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1,points:(x.points??[]).map(g=>`${g.x??0},${g.y??0}`).join(" ")},`line-${f}`)),r.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.fillColor??"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`circle-${f}`)),e.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.color??"black"},`point-${f}`)),i.map((x,f)=>j.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var h$n=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const _=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&_.currentPipelineStepIndex<=_.pipelineDef.findIndex(d=>d.solverName===u);)t.step();i()}};return j.jsxs("div",{children:[j.jsx(n$n,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(_$n,{fallback:j.jsx(d$n,{graphics:s}),children:j.jsx(ZWn,{graphics:s})}),c&&j.jsx(u$n,{solver:t,onStepUntilPhase:l})]})};const m$n=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},p$n=t=>t.toLowerCase().includes("pack")?$8n:t.toLowerCase().includes("rout")?q8n:H8n,f$n=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);m$n();const o=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),r=te.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=te.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=yae[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=i.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[i]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[r.length," ",r.length===1?"Solver":"Solvers"]}),r.map(a=>{const c=o.get(a),l=e===a;return j.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const u=p$n(c.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?j.jsx(F6,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:j.jsx(h$n,{solver:s.instance})}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&j.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(i.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},xct=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{nL.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const r=new Error(o.message||"Circuit JSON Error");o.stack&&(r.stack=o.stack);try{nL.captureException(r,{error_type:o.type})}catch{}}},[n])},gct="0.0.1936",x$n={version:gct},wxe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Exe=new Map,cG=t=>{const e=Exe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},g$n=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Exe.get(n.name);if(o)return{type:"tracked",store:t,...o};const r={connection:e.connect(n),stores:{}};return Exe.set(n.name,r),{type:"tracked",store:t,...r}},yct=(t,e={})=>(n,o,r)=>{const{enabled:i,anonymousActionType:s,store:a,...c}=e;let l;try{l=(i??(wxe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(wxe?"production":void 0)!=="production"&&i&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,r);const{connection:u,..._}=g$n(a,l,c);let d=!0;r.setState=(p,x,f)=>{const g=n(p,x);if(!d)return g;const y=f===void 0?{type:s||"anonymous"}:typeof f=="string"?{type:f}:f;return a===void 0?(u?.send(y,o()),g):(u?.send({...y,type:`${a}/${y.type}`},{...cG(c.name),[a]:r.getState()}),g)};const m=(...p)=>{const x=d;d=!1,n(...p),d=x},h=t(r.setState,o,r);if(_.type==="untracked"?u?.init(h):(_.stores[_.store]=r,u?.init(Object.fromEntries(Object.entries(_.stores).map(([p,x])=>[p,p===_.store?h:x.getState()])))),r.dispatchFromDevtools&&typeof r.dispatch=="function"){let p=!1;const x=r.dispatch;r.dispatch=(...f)=>{(wxe?"production":void 0)!=="production"&&f[0].type==="__setState"&&!p&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),p=!0),x(...f)}}return u.subscribe(p=>{var x;switch(p.type){case"ACTION":if(typeof p.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Dxe(p.payload,f=>{if(f.type==="__setState"){if(a===void 0){m(f.state);return}Object.keys(f.state).length!==1&&console.error(`
5694
+ `,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return j.jsxs("div",{className:`relative ${e}`,ref:r,children:[j.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&j.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),j.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},fct=t=>t.activeSubSolver?[t,...fct(t.activeSubSolver)]:[t],t$n=({solver:t})=>{const e=fct(t);return j.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>j.jsxs("div",{className:"flex items-center",children:[o>0&&j.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),j.jsx(e$n,{solver:n})]},n.constructor.name))})},n$n=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=te.useReducer(p=>!p,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),r&&r(t))},u=()=>{i?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),r&&t.solved&&r(t);return}t.step(),e()},n))},_=()=>{const p=t;if(p.getCurrentPhase&&!t.solved&&!t.failed){const x=p.getCurrentPhase();for(;p.getCurrentPhase()===x&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||i)return;const p=window.prompt("Step until which iteration?",`${t.iterations}`);if(p===null)return;const x=Number(p);if(!Number.isFinite(x)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<x&&!t.solved&&!t.failed;)t.step();e(),t.solved&&r&&r(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&i&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,i]);const m=t.getCurrentPhase!==void 0,h=m?t.getCurrentPhase():null;return j.jsxs("div",{className:"space-y-2 p-2 border-b",children:[j.jsx("div",{className:"flex items-center",children:j.jsx(t$n,{solver:t})}),j.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[j.jsx("button",{onClick:c,disabled:t.solved||t.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),j.jsx("button",{onClick:l,disabled:t.solved||t.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),j.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),j.jsx("button",{onClick:d,disabled:t.solved||t.failed||i,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),m&&j.jsx("button",{onClick:_,disabled:t.solved||t.failed||i,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),j.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&j.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",j.jsx("span",{className:"font-medium",children:h})]}),t.solved&&j.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&j.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&j.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},o$n=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},r$n=(t,e)=>{const o=t.pipelineDef[e].solverName,r=o$n(t,e),i=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(r==="Completed"){const d=t.pipelineDef[e+1],m=d?t.firstIterationOfPhase?.[d.solverName]:void 0;m!==void 0&&s!==null?c=m-s:s!==null&&(c=a-s)}else r==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let u=0;r==="Completed"?u=1:r==="In Progress"&&i&&(u=i.progress??0);const _=i?.stats??null;return{index:e,name:o,status:r,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:_&&Object.keys(_).length>0?_:null,solverInstance:i??null}},i$n=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return j.jsx("span",{className:`font-medium ${e[t]}`,children:t})},s$n=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:j.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),j.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},a$n=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),c$n=({stats:t})=>{if(!t||Object.keys(t).length===0)return j.jsx("span",{children:"-"});const e=Object.entries(t),n=a$n(t);return j.jsxs("details",{className:"cursor-pointer",children:[j.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),j.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>j.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Txe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Txe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Txe(o));return e},l$n=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Txe(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=`${e}_input.json`,i.click(),URL.revokeObjectURL(r)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},u$n=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>r$n(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):l$n(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return j.jsxs("div",{className:"border-t border-gray-200",children:[j.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:j.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),j.jsx("div",{className:"overflow-x-auto",children:j.jsxs("table",{className:"w-full text-sm",children:[j.jsx("thead",{children:j.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),j.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",j.jsx("sub",{children:"0"})]}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),j.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),j.jsx("tbody",{children:o.map(a=>j.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[j.jsx("td",{className:"px-4 py-2",children:j.jsxs("div",{className:"flex items-center gap-2",children:[j.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),j.jsx("button",{onClick:()=>r(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),j.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(i$n,{status:a.status})}),j.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),j.jsx("td",{className:"px-4 py-2",children:j.jsx(s$n,{progress:a.progress})}),j.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),j.jsx("td",{className:"px-4 py-2 text-gray-500",children:j.jsx(c$n,{stats:a.stats})}),j.jsx("td",{className:"px-4 py-2",children:a.solverInstance?j.jsxs("button",{onClick:()=>i(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[j.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:j.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),j.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},_$n=class extends or.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function d$n({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],r=t.circles??[],i=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(x,f)=>{typeof x=="number"&&(x<s&&(s=x),x>c&&(c=x)),typeof f=="number"&&(f<a&&(a=f),f>l&&(l=f))};for(const x of e)u(x.x,x.y);for(const x of n){const f=x.points??[];for(const g of f)u(g.x,g.y)}for(const x of o){const f=x.x??0,g=x.y??0,y=x.width??0,P=x.height??0;u(f,g),u(f+y,g+P)}for(const x of r){const f=x.x??0,g=x.y??0,y=x.radius??1;u(f-y,g-y),u(f+y,g+y)}for(const x of i)u(x.x,x.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const _=10,d=s-_,m=a-_,h=Math.max(1,c-s+2*_),p=Math.max(1,l-a+2*_);return j.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${m} ${h} ${p}`,role:"img","aria-label":"Graphics fallback",children:[o.map((x,f)=>j.jsx("rect",{x:x.x??0,y:x.y??0,width:x.width??0,height:x.height??0,fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`rect-${f}`)),n.map((x,f)=>j.jsx("polyline",{fill:"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1,points:(x.points??[]).map(g=>`${g.x??0},${g.y??0}`).join(" ")},`line-${f}`)),r.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.fillColor??"none",stroke:x.strokeColor??"black",strokeWidth:x.strokeWidth??1},`circle-${f}`)),e.map((x,f)=>j.jsx("circle",{cx:x.x??0,cy:x.y??0,r:x.radius??1.5,fill:x.color??"black"},`point-${f}`)),i.map((x,f)=>j.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var h$n=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const _=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&_.currentPipelineStepIndex<=_.pipelineDef.findIndex(d=>d.solverName===u);)t.step();i()}};return j.jsxs("div",{children:[j.jsx(n$n,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?j.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):j.jsx(_$n,{fallback:j.jsx(d$n,{graphics:s}),children:j.jsx(ZWn,{graphics:s})}),c&&j.jsx(u$n,{solver:t,onStepUntilPhase:l})]})};const m$n=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},p$n=t=>t.toLowerCase().includes("pack")?$8n:t.toLowerCase().includes("rout")?q8n:H8n,f$n=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);m$n();const o=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),r=te.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=te.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=yae[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=i.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[i]);return t.length===0?j.jsx("div",{className:"rf-p-4",children:j.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:j.jsxs("div",{className:"rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),j.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):j.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[j.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[j.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[r.length," ",r.length===1?"Solver":"Solvers"]}),r.map(a=>{const c=o.get(a),l=e===a;return j.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const u=p$n(c.solverName);return j.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[j.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),j.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[j.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),j.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),j.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?j.jsx(F6,{fallback:j.jsx("div",{className:"rf-p-4",children:j.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),j.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:j.jsx(h$n,{solver:s.instance})}):j.jsxs("div",{className:"rf-p-4",children:[j.jsxs("div",{className:"rf-mb-4",children:[j.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),j.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&j.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:j.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),j.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[j.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:j.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),j.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:j.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(i.solverParams,null,2)})})]})]}):j.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:j.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},xct=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{nL.captureException(o)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const o of n){const r=new Error(o.message||"Circuit JSON Error");o.stack&&(r.stack=o.stack);try{nL.captureException(r,{error_type:o.type})}catch{}}},[n])},gct="0.0.1937",x$n={version:gct},wxe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Exe=new Map,cG=t=>{const e=Exe.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},g$n=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Exe.get(n.name);if(o)return{type:"tracked",store:t,...o};const r={connection:e.connect(n),stores:{}};return Exe.set(n.name,r),{type:"tracked",store:t,...r}},yct=(t,e={})=>(n,o,r)=>{const{enabled:i,anonymousActionType:s,store:a,...c}=e;let l;try{l=(i??(wxe?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(wxe?"production":void 0)!=="production"&&i&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,r);const{connection:u,..._}=g$n(a,l,c);let d=!0;r.setState=(p,x,f)=>{const g=n(p,x);if(!d)return g;const y=f===void 0?{type:s||"anonymous"}:typeof f=="string"?{type:f}:f;return a===void 0?(u?.send(y,o()),g):(u?.send({...y,type:`${a}/${y.type}`},{...cG(c.name),[a]:r.getState()}),g)};const m=(...p)=>{const x=d;d=!1,n(...p),d=x},h=t(r.setState,o,r);if(_.type==="untracked"?u?.init(h):(_.stores[_.store]=r,u?.init(Object.fromEntries(Object.entries(_.stores).map(([p,x])=>[p,p===_.store?h:x.getState()])))),r.dispatchFromDevtools&&typeof r.dispatch=="function"){let p=!1;const x=r.dispatch;r.dispatch=(...f)=>{(wxe?"production":void 0)!=="production"&&f[0].type==="__setState"&&!p&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),p=!0),x(...f)}}return u.subscribe(p=>{var x;switch(p.type){case"ACTION":if(typeof p.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Dxe(p.payload,f=>{if(f.type==="__setState"){if(a===void 0){m(f.state);return}Object.keys(f.state).length!==1&&console.error(`
5695
5695
  [zustand devtools middleware] Unsupported __setState action format.
5696
5696
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5697
5697
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
5698
- `);const g=f.state[a];if(g==null)return;JSON.stringify(r.getState())!==JSON.stringify(g)&&m(g);return}r.dispatchFromDevtools&&typeof r.dispatch=="function"&&r.dispatch(f)});case"DISPATCH":switch(p.payload.type){case"RESET":return m(h),a===void 0?u?.init(r.getState()):u?.init(cG(c.name));case"COMMIT":if(a===void 0){u?.init(r.getState());return}return u?.init(cG(c.name));case"ROLLBACK":return Dxe(p.state,f=>{if(a===void 0){m(f),u?.init(r.getState());return}m(f[a]),u?.init(cG(c.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return Dxe(p.state,f=>{if(a===void 0){m(f);return}JSON.stringify(r.getState())!==JSON.stringify(f[a])&&m(f[a])});case"IMPORT_STATE":{const{nextLiftedState:f}=p.payload,g=(x=f.computedStates.slice(-1)[0])==null?void 0:x.state;if(!g)return;m(a===void 0?g:g[a]),u?.send(null,f);return}case"PAUSE_RECORDING":return d=!d}return}}),h},Dxe=(t,e)=>{let n;try{n=JSON.parse(t)}catch(o){console.error("[zustand devtools middleware] Could not parse the received json",o)}n!==void 0&&e(n)},Axe=ust()(yct(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),y$n=t=>{const[e,n]=te.useState([]),[o,r]=te.useState(null),[i,s]=te.useState(""),[a,c]=act("eval-version-selection",null),l=Axe(m=>m.setLastRunEvalVersion),u=Axe(m=>m.lastRunEvalVersion);return te.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(m=>m.json()).then(m=>{if(Array.isArray(m?.versions)){let h=[...m.versions];m.tags?.latest&&(r(m.tags.latest),h=h.filter(p=>p!==m.tags.latest)),n(h)}}).catch(()=>{})},[t]),te.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:te.useMemo(()=>e.filter(m=>m.includes(i)).slice(0,50),[e,i]),latestVersion:o,lastRunEvalVersion:u,search:i,setSearch:s,selectVersion:m=>{c(m),s("")}}},P$n=zl("run-frame"),k9=window.TSCIRCUIT_FILESERVER_API_BASE_URL??"/api",SH=P$n.extend("store");async function Pct(t,e){return(await(await fetch(`${k9}/files/upsert`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:t,text_content:e})})).json()).file}async function Rxe(t){return(await(await fetch(`${k9}/files/get?file_path=${encodeURIComponent(t)}`)).json()).file}async function b$n(t){const e=t?`${k9}/events/list?since=${encodeURIComponent(t)}`:`${k9}/events/list`;return(await(await fetch(e)).json()).event_list}const bct=[".tsx",".ts",".jsx",".js",".json"];async function v$n(){const t=await fetch(`${k9}/files/list`),{file_list:e}=await t.json(),n=new Map;for(const o of e){if(bct.some(r=>o.file_path.endsWith(r))){const r=await Rxe(o.file_path);n.set(o.file_path,r.text_content);continue}n.set(o.file_path,"__STATIC_ASSET__")}return n}const S$n=["manual-edits.json","manual_edits.json"],o3=ust()(yct((t,e)=>({fsMap:new Map,lastEventTime:new Date().toISOString(),isPolling:!1,error:null,circuitJson:null,lastManualEditsChangeSentAt:0,recentEvents:[],simulateScenarioOrder:void 0,currentMainComponentPath:null,recentlySavedFiles:[],loadInitialFiles:async()=>{const n=await v$n();SH("loaded initial files",{fsMap:n}),t({fsMap:n})},upsertFile:async(n,o)=>{try{const r=await Pct(n,o);t(i=>({fsMap:new Map(i.fsMap).set(r.file_path,r.text_content)}))}catch(r){t({error:r})}},getFile:async n=>{try{const o=await Rxe(n);t(r=>({fsMap:new Map(r.fsMap).set(o.file_path,o.text_content)}))}catch(o){t({error:o})}},setCircuitJson:n=>{n!==e().circuitJson&&t({circuitJson:n})},addRecentlySavedFile:n=>{t(o=>{if(S$n.includes(n)||!bct.some(i=>n.endsWith(i)))return o;const r=o.recentlySavedFiles.filter(i=>i!==n);return{recentlySavedFiles:[n,...r].slice(0,10)}})},startPolling:()=>{const n=async()=>{const o=e();if(o.isPolling){try{const r=await b$n(o.lastEventTime);if(r.length>0){const i=r[r.length-1].created_at;SH("received events",r.map(c=>c.event_type)),t(c=>({recentEvents:[...c.recentEvents,...r].slice(0,100),lastEventTime:i}));let s=0;const a=new Map(o.fsMap);for(const c of r)if(c.event_type==="FILE_UPDATED"){s++;const l=await Rxe(c.file_path);if(c.file_path==="manual_edits.json"&&Date.now()-o.lastManualEditsChangeSentAt<1e3)continue;l.text_content?a.set(l.file_path,l.text_content):a.set(l.file_path,"__STATIC_ASSET__"),e().addRecentlySavedFile(c.file_path)}else c.event_type==="FILE_DELETED"&&(s++,a.delete(c.file_path));s>0&&(SH("updating fsMap, fsUpdateCount:",s),t({fsMap:a}))}}catch(r){t({error:r})}setTimeout(n,1e3)}};t({isPolling:!0}),n()},stopPolling:()=>{t({isPolling:!1})},pushEvent:async n=>{await fetch(`${k9}/events/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})},applyEditEventsAndUpdateManualEditsJson:async n=>{SH("applyEditEventsAndUpdateManualEditsJson",{editEvents:n});const o=e();if(!o.circuitJson)return;const r=o.fsMap.get("manual-edits.json"),i=r?JSON.parse(r):{},s=Vnn({circuitJson:o.circuitJson,editEvents:n,manualEditsFile:i});SH("updatedManualEditsFileContent",s),t(a=>({lastManualEditsChangeSentAt:Date.now(),fsMap:new Map(a.fsMap).set("manual-edits.json",JSON.stringify(s))})),await Pct("manual-edits.json",JSON.stringify(s,null,2))},setSimulateScenarioOrder:n=>t({simulateScenarioOrder:n}),setCurrentMainComponentPath:n=>t({currentMainComponentPath:n})}),{name:"run-frame-store"})),C$n=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[r,i]=te.useState(""),[s,a]=te.useState("");if(!o)return null;const c=t.filter(_=>_.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),u=_=>{_.key==="Enter"&&(c.length===1?i(c[0]):l&&i(s))};return j.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:j.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[j.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),j.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:_=>a(_.target.value),onKeyDown:u}),j.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>j.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${r===_?"bg-blue-50":""}`,onClick:()=>i(_),children:_},_)),l&&j.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${r===s?"bg-blue-50":""}`,onClick:()=>i(s),children:['Create new "',s,'"']})]}),j.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[j.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),j.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>r&&e(r),disabled:!r,children:r===s?`Create "${r}"`:`Save to ${r}`})]})]})})},M$n=t=>{const e=te.useRef(null),n=o3(o=>o.recentEvents);te.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};function T$n(t){const e=w$n(t),n=te.forwardRef((o,r)=>{const{children:i,...s}=o,a=te.Children.toArray(i),c=a.find(D$n);if(c){const l=c.props.children,u=a.map(_=>_===c?te.Children.count(l)>1?te.Children.only(null):te.isValidElement(l)?l.props.children:null:_);return j.jsx(e,{...s,ref:r,children:te.isValidElement(l)?te.cloneElement(l,void 0,u):null})}return j.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function w$n(t){const e=te.forwardRef((n,o)=>{const{children:r,...i}=n;if(te.isValidElement(r)){const s=R$n(r),a=A$n(i,r.props);return r.type!==te.Fragment&&(a.ref=o?iP(o,s):s),te.cloneElement(r,a)}return te.Children.count(r)>1?te.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var E$n=Symbol("radix.slottable");function D$n(t){return te.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===E$n}function A$n(t,e){const n={...e};for(const o in e){const r=t[o],i=e[o];/^on[A-Z]/.test(o)?r&&i?n[o]=(...a)=>{const c=i(...a);return r(...a),c}:r&&(n[o]=r):o==="style"?n[o]={...r,...i}:o==="className"&&(n[o]=[r,i].filter(Boolean).join(" "))}return{...t,...n}}function R$n(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lG="Dialog",[vct,Sct]=P3(lG),[k$n,p4]=vct(lG),Cct=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!0}=t,a=te.useRef(null),c=te.useRef(null),[l,u]=sC({prop:o,defaultProp:r??!1,onChange:i,caller:lG});return j.jsx(k$n,{scope:e,triggerRef:a,contentRef:c,contentId:b3(),titleId:b3(),descriptionId:b3(),open:l,onOpenChange:u,onOpenToggle:te.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};Cct.displayName=lG;var Mct="DialogTrigger",Tct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Mct,n),i=hd(e,r.triggerRef);return j.jsx(Ll.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Hxe(r.open),...o,ref:i,onClick:qi(t.onClick,r.onOpenToggle)})});Tct.displayName=Mct;var kxe="DialogPortal",[N$n,wct]=vct(kxe,{forceMount:void 0}),Ect=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=p4(kxe,e);return j.jsx(N$n,{scope:e,forceMount:n,children:te.Children.map(o,s=>j.jsx(I4,{present:n||i.open,children:j.jsx(p1e,{asChild:!0,container:r,children:s})}))})};Ect.displayName=kxe;var uG="DialogOverlay",Dct=te.forwardRef((t,e)=>{const n=wct(uG,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=p4(uG,t.__scopeDialog);return i.modal?j.jsx(I4,{present:o||i.open,children:j.jsx(I$n,{...r,ref:e})}):null});Dct.displayName=uG;var H$n=T$n("DialogOverlay.RemoveScroll"),I$n=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(uG,n);return j.jsx(b1e,{as:H$n,allowPinchZoom:!0,shards:[r.contentRef],children:j.jsx(Ll.div,{"data-state":Hxe(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),wS="DialogContent",Act=te.forwardRef((t,e)=>{const n=wct(wS,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=p4(wS,t.__scopeDialog);return j.jsx(I4,{present:o||i.open,children:i.modal?j.jsx(L$n,{...r,ref:e}):j.jsx(O$n,{...r,ref:e})})});Act.displayName=wS;var L$n=te.forwardRef((t,e)=>{const n=p4(wS,t.__scopeDialog),o=te.useRef(null),r=hd(e,n.contentRef,o);return te.useEffect(()=>{const i=o.current;if(i)return wtt(i)},[]),j.jsx(Rct,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:qi(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:qi(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:qi(t.onFocusOutside,i=>i.preventDefault())})}),O$n=te.forwardRef((t,e)=>{const n=p4(wS,t.__scopeDialog),o=te.useRef(!1),r=te.useRef(!1);return j.jsx(Rct,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{t.onCloseAutoFocus?.(i),i.defaultPrevented||(o.current||n.triggerRef.current?.focus(),i.preventDefault()),o.current=!1,r.current=!1},onInteractOutside:i=>{t.onInteractOutside?.(i),i.defaultPrevented||(o.current=!0,i.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const s=i.target;n.triggerRef.current?.contains(s)&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&r.current&&i.preventDefault()}})}),Rct=te.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=p4(wS,n),c=te.useRef(null),l=hd(e,c);return Fet(),j.jsxs(j.Fragment,{children:[j.jsx(t1e,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:j.jsx(Qfe,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Hxe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),j.jsxs(j.Fragment,{children:[j.jsx(B$n,{titleId:a.titleId}),j.jsx(V$n,{contentRef:c,descriptionId:a.descriptionId})]})]})}),Nxe="DialogTitle",kct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Nxe,n);return j.jsx(Ll.h2,{id:r.titleId,...o,ref:e})});kct.displayName=Nxe;var Nct="DialogDescription",Hct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Nct,n);return j.jsx(Ll.p,{id:r.descriptionId,...o,ref:e})});Hct.displayName=Nct;var Ict="DialogClose",Lct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Ict,n);return j.jsx(Ll.button,{type:"button",...o,ref:e,onClick:qi(t.onClick,()=>r.onOpenChange(!1))})});Lct.displayName=Ict;function Hxe(t){return t?"open":"closed"}var Oct="DialogTitleWarning",[F$n,Fct]=M_t(Oct,{contentName:wS,titleName:Nxe,docsSlug:"dialog"}),B$n=({titleId:t})=>{const e=Fct(Oct),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
5698
+ `);const g=f.state[a];if(g==null)return;JSON.stringify(r.getState())!==JSON.stringify(g)&&m(g);return}r.dispatchFromDevtools&&typeof r.dispatch=="function"&&r.dispatch(f)});case"DISPATCH":switch(p.payload.type){case"RESET":return m(h),a===void 0?u?.init(r.getState()):u?.init(cG(c.name));case"COMMIT":if(a===void 0){u?.init(r.getState());return}return u?.init(cG(c.name));case"ROLLBACK":return Dxe(p.state,f=>{if(a===void 0){m(f),u?.init(r.getState());return}m(f[a]),u?.init(cG(c.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return Dxe(p.state,f=>{if(a===void 0){m(f);return}JSON.stringify(r.getState())!==JSON.stringify(f[a])&&m(f[a])});case"IMPORT_STATE":{const{nextLiftedState:f}=p.payload,g=(x=f.computedStates.slice(-1)[0])==null?void 0:x.state;if(!g)return;m(a===void 0?g:g[a]),u?.send(null,f);return}case"PAUSE_RECORDING":return d=!d}return}}),h},Dxe=(t,e)=>{let n;try{n=JSON.parse(t)}catch(o){console.error("[zustand devtools middleware] Could not parse the received json",o)}n!==void 0&&e(n)},Axe=ust()(yct(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),y$n=t=>{const[e,n]=te.useState([]),[o,r]=te.useState(null),[i,s]=te.useState(""),[a,c]=act("eval-version-selection",null),l=Axe(m=>m.setLastRunEvalVersion),u=Axe(m=>m.lastRunEvalVersion);return te.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(m=>m.json()).then(m=>{if(Array.isArray(m?.versions)){let h=[...m.versions];m.tags?.latest&&(r(m.tags.latest),h=h.filter(p=>p!==m.tags.latest)),n(h)}}).catch(()=>{})},[t]),te.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:te.useMemo(()=>e.filter(m=>m.includes(i)).slice(0,50),[e,i]),latestVersion:o,lastRunEvalVersion:u,search:i,setSearch:s,selectVersion:m=>{c(m),s("")}}},P$n=zl("run-frame"),k9=window.TSCIRCUIT_FILESERVER_API_BASE_URL??"/api",SH=P$n.extend("store");async function Pct(t,e){return(await(await fetch(`${k9}/files/upsert`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:t,text_content:e})})).json()).file}async function Rxe(t){return(await(await fetch(`${k9}/files/get?file_path=${encodeURIComponent(t)}`)).json()).file}async function b$n(t){const e=t?`${k9}/events/list?since=${encodeURIComponent(t)}`:`${k9}/events/list`;return(await(await fetch(e)).json()).event_list}const bct=[".tsx",".ts",".jsx",".js",".json",".kicad_pcb",".kicad_sch",".kicad_prl",".kicad_pro"];async function v$n(){const t=await fetch(`${k9}/files/list`),{file_list:e}=await t.json(),n=new Map;for(const o of e){if(bct.some(r=>o.file_path.endsWith(r))){const r=await Rxe(o.file_path);n.set(o.file_path,r.text_content);continue}n.set(o.file_path,"__STATIC_ASSET__")}return n}const S$n=["manual-edits.json","manual_edits.json"],o3=ust()(yct((t,e)=>({fsMap:new Map,lastEventTime:new Date().toISOString(),isPolling:!1,error:null,circuitJson:null,lastManualEditsChangeSentAt:0,recentEvents:[],simulateScenarioOrder:void 0,currentMainComponentPath:null,recentlySavedFiles:[],loadInitialFiles:async()=>{const n=await v$n();SH("loaded initial files",{fsMap:n}),t({fsMap:n})},upsertFile:async(n,o)=>{try{const r=await Pct(n,o);t(i=>({fsMap:new Map(i.fsMap).set(r.file_path,r.text_content)}))}catch(r){t({error:r})}},getFile:async n=>{try{const o=await Rxe(n);t(r=>({fsMap:new Map(r.fsMap).set(o.file_path,o.text_content)}))}catch(o){t({error:o})}},setCircuitJson:n=>{n!==e().circuitJson&&t({circuitJson:n})},addRecentlySavedFile:n=>{t(o=>{if(S$n.includes(n)||!bct.some(i=>n.endsWith(i)))return o;const r=o.recentlySavedFiles.filter(i=>i!==n);return{recentlySavedFiles:[n,...r].slice(0,10)}})},startPolling:()=>{const n=async()=>{const o=e();if(o.isPolling){try{const r=await b$n(o.lastEventTime);if(r.length>0){const i=r[r.length-1].created_at;SH("received events",r.map(c=>c.event_type)),t(c=>({recentEvents:[...c.recentEvents,...r].slice(0,100),lastEventTime:i}));let s=0;const a=new Map(o.fsMap);for(const c of r)if(c.event_type==="FILE_UPDATED"){s++;const l=await Rxe(c.file_path);if(c.file_path==="manual_edits.json"&&Date.now()-o.lastManualEditsChangeSentAt<1e3)continue;l.text_content?a.set(l.file_path,l.text_content):a.set(l.file_path,"__STATIC_ASSET__"),e().addRecentlySavedFile(c.file_path)}else c.event_type==="FILE_DELETED"&&(s++,a.delete(c.file_path));s>0&&(SH("updating fsMap, fsUpdateCount:",s),t({fsMap:a}))}}catch(r){t({error:r})}setTimeout(n,1e3)}};t({isPolling:!0}),n()},stopPolling:()=>{t({isPolling:!1})},pushEvent:async n=>{await fetch(`${k9}/events/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})},applyEditEventsAndUpdateManualEditsJson:async n=>{SH("applyEditEventsAndUpdateManualEditsJson",{editEvents:n});const o=e();if(!o.circuitJson)return;const r=o.fsMap.get("manual-edits.json"),i=r?JSON.parse(r):{},s=Vnn({circuitJson:o.circuitJson,editEvents:n,manualEditsFile:i});SH("updatedManualEditsFileContent",s),t(a=>({lastManualEditsChangeSentAt:Date.now(),fsMap:new Map(a.fsMap).set("manual-edits.json",JSON.stringify(s))})),await Pct("manual-edits.json",JSON.stringify(s,null,2))},setSimulateScenarioOrder:n=>t({simulateScenarioOrder:n}),setCurrentMainComponentPath:n=>t({currentMainComponentPath:n})}),{name:"run-frame-store"})),C$n=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[r,i]=te.useState(""),[s,a]=te.useState("");if(!o)return null;const c=t.filter(_=>_.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),u=_=>{_.key==="Enter"&&(c.length===1?i(c[0]):l&&i(s))};return j.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:j.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[j.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),j.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:_=>a(_.target.value),onKeyDown:u}),j.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>j.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${r===_?"bg-blue-50":""}`,onClick:()=>i(_),children:_},_)),l&&j.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${r===s?"bg-blue-50":""}`,onClick:()=>i(s),children:['Create new "',s,'"']})]}),j.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[j.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),j.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>r&&e(r),disabled:!r,children:r===s?`Create "${r}"`:`Save to ${r}`})]})]})})},M$n=t=>{const e=te.useRef(null),n=o3(o=>o.recentEvents);te.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};function T$n(t){const e=w$n(t),n=te.forwardRef((o,r)=>{const{children:i,...s}=o,a=te.Children.toArray(i),c=a.find(D$n);if(c){const l=c.props.children,u=a.map(_=>_===c?te.Children.count(l)>1?te.Children.only(null):te.isValidElement(l)?l.props.children:null:_);return j.jsx(e,{...s,ref:r,children:te.isValidElement(l)?te.cloneElement(l,void 0,u):null})}return j.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function w$n(t){const e=te.forwardRef((n,o)=>{const{children:r,...i}=n;if(te.isValidElement(r)){const s=R$n(r),a=A$n(i,r.props);return r.type!==te.Fragment&&(a.ref=o?iP(o,s):s),te.cloneElement(r,a)}return te.Children.count(r)>1?te.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var E$n=Symbol("radix.slottable");function D$n(t){return te.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===E$n}function A$n(t,e){const n={...e};for(const o in e){const r=t[o],i=e[o];/^on[A-Z]/.test(o)?r&&i?n[o]=(...a)=>{const c=i(...a);return r(...a),c}:r&&(n[o]=r):o==="style"?n[o]={...r,...i}:o==="className"&&(n[o]=[r,i].filter(Boolean).join(" "))}return{...t,...n}}function R$n(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var lG="Dialog",[vct,Sct]=P3(lG),[k$n,p4]=vct(lG),Cct=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!0}=t,a=te.useRef(null),c=te.useRef(null),[l,u]=sC({prop:o,defaultProp:r??!1,onChange:i,caller:lG});return j.jsx(k$n,{scope:e,triggerRef:a,contentRef:c,contentId:b3(),titleId:b3(),descriptionId:b3(),open:l,onOpenChange:u,onOpenToggle:te.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};Cct.displayName=lG;var Mct="DialogTrigger",Tct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Mct,n),i=hd(e,r.triggerRef);return j.jsx(Ll.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Hxe(r.open),...o,ref:i,onClick:qi(t.onClick,r.onOpenToggle)})});Tct.displayName=Mct;var kxe="DialogPortal",[N$n,wct]=vct(kxe,{forceMount:void 0}),Ect=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=p4(kxe,e);return j.jsx(N$n,{scope:e,forceMount:n,children:te.Children.map(o,s=>j.jsx(I4,{present:n||i.open,children:j.jsx(p1e,{asChild:!0,container:r,children:s})}))})};Ect.displayName=kxe;var uG="DialogOverlay",Dct=te.forwardRef((t,e)=>{const n=wct(uG,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=p4(uG,t.__scopeDialog);return i.modal?j.jsx(I4,{present:o||i.open,children:j.jsx(I$n,{...r,ref:e})}):null});Dct.displayName=uG;var H$n=T$n("DialogOverlay.RemoveScroll"),I$n=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(uG,n);return j.jsx(b1e,{as:H$n,allowPinchZoom:!0,shards:[r.contentRef],children:j.jsx(Ll.div,{"data-state":Hxe(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),wS="DialogContent",Act=te.forwardRef((t,e)=>{const n=wct(wS,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=p4(wS,t.__scopeDialog);return j.jsx(I4,{present:o||i.open,children:i.modal?j.jsx(L$n,{...r,ref:e}):j.jsx(O$n,{...r,ref:e})})});Act.displayName=wS;var L$n=te.forwardRef((t,e)=>{const n=p4(wS,t.__scopeDialog),o=te.useRef(null),r=hd(e,n.contentRef,o);return te.useEffect(()=>{const i=o.current;if(i)return wtt(i)},[]),j.jsx(Rct,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:qi(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:qi(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:qi(t.onFocusOutside,i=>i.preventDefault())})}),O$n=te.forwardRef((t,e)=>{const n=p4(wS,t.__scopeDialog),o=te.useRef(!1),r=te.useRef(!1);return j.jsx(Rct,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{t.onCloseAutoFocus?.(i),i.defaultPrevented||(o.current||n.triggerRef.current?.focus(),i.preventDefault()),o.current=!1,r.current=!1},onInteractOutside:i=>{t.onInteractOutside?.(i),i.defaultPrevented||(o.current=!0,i.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const s=i.target;n.triggerRef.current?.contains(s)&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&r.current&&i.preventDefault()}})}),Rct=te.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=p4(wS,n),c=te.useRef(null),l=hd(e,c);return Fet(),j.jsxs(j.Fragment,{children:[j.jsx(t1e,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:j.jsx(Qfe,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Hxe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),j.jsxs(j.Fragment,{children:[j.jsx(B$n,{titleId:a.titleId}),j.jsx(V$n,{contentRef:c,descriptionId:a.descriptionId})]})]})}),Nxe="DialogTitle",kct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Nxe,n);return j.jsx(Ll.h2,{id:r.titleId,...o,ref:e})});kct.displayName=Nxe;var Nct="DialogDescription",Hct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Nct,n);return j.jsx(Ll.p,{id:r.descriptionId,...o,ref:e})});Hct.displayName=Nct;var Ict="DialogClose",Lct=te.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=p4(Ict,n);return j.jsx(Ll.button,{type:"button",...o,ref:e,onClick:qi(t.onClick,()=>r.onOpenChange(!1))})});Lct.displayName=Ict;function Hxe(t){return t?"open":"closed"}var Oct="DialogTitleWarning",[F$n,Fct]=M_t(Oct,{contentName:wS,titleName:Nxe,docsSlug:"dialog"}),B$n=({titleId:t})=>{const e=Fct(Oct),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
5699
5699
 
5700
5700
  If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
5701
5701