@tscircuit/runframe 0.0.1889 → 0.0.1891
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1821,7 +1821,7 @@ var useErrorTelemetry = ({
|
|
|
1821
1821
|
};
|
|
1822
1822
|
|
|
1823
1823
|
// package.json
|
|
1824
|
-
var version = "0.0.
|
|
1824
|
+
var version = "0.0.1890";
|
|
1825
1825
|
var package_default = {
|
|
1826
1826
|
name: "@tscircuit/runframe",
|
|
1827
1827
|
main: "dist/preview.js",
|
|
@@ -1888,7 +1888,7 @@ var package_default = {
|
|
|
1888
1888
|
"chokidar-cli": "^3.0.0",
|
|
1889
1889
|
"circuit-json-to-bom-csv": "^0.0.8",
|
|
1890
1890
|
"circuit-json-to-gerber": "^0.0.49",
|
|
1891
|
-
"circuit-json-to-kicad": "^0.0.
|
|
1891
|
+
"circuit-json-to-kicad": "^0.0.124",
|
|
1892
1892
|
"circuit-json-to-lbrn": "^0.0.74",
|
|
1893
1893
|
"circuit-json-to-pnp-csv": "^0.0.7",
|
|
1894
1894
|
"circuit-json-to-step": "^0.0.18",
|
|
@@ -1937,7 +1937,7 @@ var package_default = {
|
|
|
1937
1937
|
yargs: "^17.7.2"
|
|
1938
1938
|
},
|
|
1939
1939
|
dependencies: {
|
|
1940
|
-
"@tscircuit/eval": "^0.0.
|
|
1940
|
+
"@tscircuit/eval": "^0.0.798",
|
|
1941
1941
|
"@tscircuit/solver-utils": "^0.0.7"
|
|
1942
1942
|
}
|
|
1943
1943
|
};
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -5691,7 +5691,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5691
5691
|
// Add more specific assertions based on expected output
|
|
5692
5692
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5693
5693
|
})
|
|
5694
|
-
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:r,children:[G.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&&G.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:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},d_t=t=>t.activeSubSolver?[t,...d_t(t.activeSubSolver)]:[t],vGn=({solver:t})=>{const e=d_t(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>G.jsxs("div",{className:"flex items-center",children:[o>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(PGn,{solver:n})]},n.constructor.name))})},SGn=({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 G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(vGn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.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"}),G.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"}),G.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"}),G.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&&G.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"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:h})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},CGn=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},MGn=(t,e)=>{const o=t.pipelineDef[e].solverName,r=CGn(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}},TGn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},wGn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},EGn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),DGn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=EGn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>G.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Sge=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Sge);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Sge(o));return e},AGn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Sge(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)}`)}},RGn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>MGn(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):AGn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:o.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.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:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(TGn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(wGn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(DGn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.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:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},kGn=class extends ar.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 NGn({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,b=x.height??0;u(f,g),u(f+y,g+b)}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 G.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)=>G.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)=>G.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)=>G.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)=>G.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)=>G.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var HGn=({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 G.jsxs("div",{children:[G.jsx(SGn,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(kGn,{fallback:G.jsx(NGn,{graphics:s}),children:G.jsx(bGn,{graphics:s})}),c&&G.jsx(RGn,{solver:t,onStepUntilPhase:l})]})};const IGn=()=>{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)},[])},LGn=t=>t.toLowerCase().includes("pack")?ETn:t.toLowerCase().includes("rout")?HTn:yTn,OGn=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);IGn();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=Vae[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Vae).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?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.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."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.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 G.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=LGn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?G.jsx(q6,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:G.jsx(HGn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&G.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:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.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)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},h_t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{yL.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{yL.captureException(r,{error_type:o.type})}catch{}}},[n])},m_t="0.0.1888",FGn={version:m_t},Cge={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Mge=new Map,kG=t=>{const e=Mge.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},BGn=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Mge.get(n.name);if(o)return{type:"tracked",store:t,...o};const r={connection:e.connect(n),stores:{}};return Mge.set(n.name,r),{type:"tracked",store:t,...r}},p_t=(t,e={})=>(n,o,r)=>{const{enabled:i,anonymousActionType:s,store:a,...c}=e;let l;try{l=(i??(Cge?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(Cge?"production":void 0)!=="production"&&i&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,r);const{connection:u,..._}=BGn(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}`},{...kG(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)=>{(Cge?"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 Tge(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 G.jsxs("div",{className:`relative ${e}`,ref:r,children:[G.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&&G.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:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},d_t=t=>t.activeSubSolver?[t,...d_t(t.activeSubSolver)]:[t],vGn=({solver:t})=>{const e=d_t(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>G.jsxs("div",{className:"flex items-center",children:[o>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(PGn,{solver:n})]},n.constructor.name))})},SGn=({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 G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(vGn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.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"}),G.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"}),G.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"}),G.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&&G.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"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:h})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},CGn=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},MGn=(t,e)=>{const o=t.pipelineDef[e].solverName,r=CGn(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}},TGn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},wGn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},EGn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),DGn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=EGn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>G.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Sge=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Sge);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Sge(o));return e},AGn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Sge(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)}`)}},RGn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>MGn(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):AGn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:o.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.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:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(TGn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(wGn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(DGn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.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:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},kGn=class extends ar.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 NGn({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,b=x.height??0;u(f,g),u(f+y,g+b)}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 G.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)=>G.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)=>G.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)=>G.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)=>G.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)=>G.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var HGn=({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 G.jsxs("div",{children:[G.jsx(SGn,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(kGn,{fallback:G.jsx(NGn,{graphics:s}),children:G.jsx(bGn,{graphics:s})}),c&&G.jsx(RGn,{solver:t,onStepUntilPhase:l})]})};const IGn=()=>{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)},[])},LGn=t=>t.toLowerCase().includes("pack")?ETn:t.toLowerCase().includes("rout")?HTn:yTn,OGn=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);IGn();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=Vae[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Vae).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?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.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."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.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 G.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=LGn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?G.jsx(q6,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:G.jsx(HGn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&G.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:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.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)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},h_t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{yL.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{yL.captureException(r,{error_type:o.type})}catch{}}},[n])},m_t="0.0.1890",FGn={version:m_t},Cge={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Mge=new Map,kG=t=>{const e=Mge.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},BGn=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Mge.get(n.name);if(o)return{type:"tracked",store:t,...o};const r={connection:e.connect(n),stores:{}};return Mge.set(n.name,r),{type:"tracked",store:t,...r}},p_t=(t,e={})=>(n,o,r)=>{const{enabled:i,anonymousActionType:s,store:a,...c}=e;let l;try{l=(i??(Cge?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(Cge?"production":void 0)!=="production"&&i&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,r);const{connection:u,..._}=BGn(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}`},{...kG(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)=>{(Cge?"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 Tge(p.payload,f=>{if(f.type==="__setState"){if(a===void 0){m(f.state);return}Object.keys(f.state).length!==1&&console.error(`
|
|
5695
5695
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5696
5696
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5697
5697
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
package/dist/standalone.min.js
CHANGED
|
@@ -5695,7 +5695,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5695
5695
|
// Add more specific assertions based on expected output
|
|
5696
5696
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5697
5697
|
})
|
|
5698
|
-
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:r,children:[G.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&&G.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:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},Idt=t=>t.activeSubSolver?[t,...Idt(t.activeSubSolver)]:[t],vJn=({solver:t})=>{const e=Idt(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>G.jsxs("div",{className:"flex items-center",children:[o>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(PJn,{solver:n})]},n.constructor.name))})},SJn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=Y.useReducer(p=>!p,!1),a=Y.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)};Y.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),Y.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 G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(vJn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.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"}),G.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"}),G.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"}),G.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&&G.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"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:h})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},CJn=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},MJn=(t,e)=>{const o=t.pipelineDef[e].solverName,r=CJn(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}},TJn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},wJn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},EJn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),DJn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=EJn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>G.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Aye=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Aye);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Aye(o));return e},AJn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Aye(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)}`)}},RJn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>MJn(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):AJn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:o.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.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:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(TJn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(wJn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(DJn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.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:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},kJn=class extends cr.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 NJn({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,b=x.height??0;u(f,g),u(f+y,g+b)}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 G.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)=>G.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)=>G.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)=>G.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)=>G.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)=>G.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var HJn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=Y.useReducer(u=>u+1,0),s=Y.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),a=Y.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);Y.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 G.jsxs("div",{children:[G.jsx(SJn,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(kJn,{fallback:G.jsx(NJn,{graphics:s}),children:G.jsx(bJn,{graphics:s})}),c&&G.jsx(RJn,{solver:t,onStepUntilPhase:l})]})};const IJn=()=>{Y.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)},[])},LJn=t=>t.toLowerCase().includes("pack")?VDn:t.toLowerCase().includes("rout")?jDn:TDn,OJn=({solverEvents:t=[]})=>{const[e,n]=Y.useState(null);IJn();const o=Y.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),r=Y.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=Y.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=zie[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(zie).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?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.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."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.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 G.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=LJn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?G.jsx(M5,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:G.jsx(HJn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&G.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:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.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)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Ldt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Y.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{EW.captureException(o)}catch{}}},[t,e]),Y.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{EW.captureException(r,{error_type:o.type})}catch{}}},[n])},Odt="0.0.1888",FJn={version:Odt},bY=OIe()(FIe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),BJn=t=>{const[e,n]=Y.useState([]),[o,r]=Y.useState(null),[i,s]=Y.useState(""),[a,c]=RT("eval-version-selection",null),l=bY(m=>m.setLastRunEvalVersion),u=bY(m=>m.lastRunEvalVersion);return Y.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]),Y.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:Y.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("")}}},zJn=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[r,i]=Y.useState(""),[s,a]=Y.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 G.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:G.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[G.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),G.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}),G.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>G.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&&G.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,'"']})]}),G.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[G.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),G.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}`})]})]})})},VJn=t=>{const e=Y.useRef(null),n=eu(o=>o.recentEvents);Y.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 $Jn(t){const e=WJn(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(XJn);if(c){const l=c.props.children,u=a.map(_=>_===c?Y.Children.count(l)>1?Y.Children.only(null):Y.isValidElement(l)?l.props.children:null:_);return G.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return G.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function WJn(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=GJn(r),a=jJn(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?Rx(o,s):s),Y.cloneElement(r,a)}return Y.Children.count(r)>1?Y.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var UJn=Symbol("radix.slottable");function XJn(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===UJn}function jJn(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 GJn(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 PY="Dialog",[Fdt,Bdt]=d4(PY),[YJn,B4]=Fdt(PY),zdt=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!0}=t,a=Y.useRef(null),c=Y.useRef(null),[l,u]=DP({prop:o,defaultProp:r??!1,onChange:i,caller:PY});return G.jsx(YJn,{scope:e,triggerRef:a,contentRef:c,contentId:Jp(),titleId:Jp(),descriptionId:Jp(),open:l,onOpenChange:u,onOpenToggle:Y.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};zdt.displayName=PY;var Vdt="DialogTrigger",$dt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(Vdt,n),i=tu(e,r.triggerRef);return G.jsx(Cc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Nye(r.open),...o,ref:i,onClick:Vr(t.onClick,r.onOpenToggle)})});$dt.displayName=Vdt;var Rye="DialogPortal",[qJn,Wdt]=Fdt(Rye,{forceMount:void 0}),Udt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=B4(Rye,e);return G.jsx(qJn,{scope:e,forceMount:n,children:Y.Children.map(o,s=>G.jsx(Fg,{present:n||i.open,children:G.jsx(Lj,{asChild:!0,container:r,children:s})}))})};Udt.displayName=Rye;var vY="DialogOverlay",Xdt=Y.forwardRef((t,e)=>{const n=Wdt(vY,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=B4(vY,t.__scopeDialog);return i.modal?G.jsx(Fg,{present:o||i.open,children:G.jsx(KJn,{...r,ref:e})}):null});Xdt.displayName=vY;var JJn=$Jn("DialogOverlay.RemoveScroll"),KJn=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(vY,n);return G.jsx(Uj,{as:JJn,allowPinchZoom:!0,shards:[r.contentRef],children:G.jsx(Cc.div,{"data-state":Nye(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),Z8="DialogContent",jdt=Y.forwardRef((t,e)=>{const n=Wdt(Z8,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=B4(Z8,t.__scopeDialog);return G.jsx(Fg,{present:o||i.open,children:i.modal?G.jsx(QJn,{...r,ref:e}):G.jsx(ZJn,{...r,ref:e})})});jdt.displayName=Z8;var QJn=Y.forwardRef((t,e)=>{const n=B4(Z8,t.__scopeDialog),o=Y.useRef(null),r=tu(e,n.contentRef,o);return Y.useEffect(()=>{const i=o.current;if(i)return Y2e(i)},[]),G.jsx(Gdt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vr(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Vr(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:Vr(t.onFocusOutside,i=>i.preventDefault())})}),ZJn=Y.forwardRef((t,e)=>{const n=B4(Z8,t.__scopeDialog),o=Y.useRef(!1),r=Y.useRef(!1);return G.jsx(Gdt,{...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()}})}),Gdt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=B4(Z8,n),c=Y.useRef(null),l=tu(e,c);return D2e(),G.jsxs(G.Fragment,{children:[G.jsx(Sj,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:G.jsx(ZN,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Nye(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),G.jsxs(G.Fragment,{children:[G.jsx(tKn,{titleId:a.titleId}),G.jsx(oKn,{contentRef:c,descriptionId:a.descriptionId})]})]})}),kye="DialogTitle",Ydt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(kye,n);return G.jsx(Cc.h2,{id:r.titleId,...o,ref:e})});Ydt.displayName=kye;var qdt="DialogDescription",Jdt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(qdt,n);return G.jsx(Cc.p,{id:r.descriptionId,...o,ref:e})});Jdt.displayName=qdt;var Kdt="DialogClose",Qdt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(Kdt,n);return G.jsx(Cc.button,{type:"button",...o,ref:e,onClick:Vr(t.onClick,()=>r.onOpenChange(!1))})});Qdt.displayName=Kdt;function Nye(t){return t?"open":"closed"}var Zdt="DialogTitleWarning",[eKn,eht]=AZt(Zdt,{contentName:Z8,titleName:kye,docsSlug:"dialog"}),tKn=({titleId:t})=>{const e=eht(Zdt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5698
|
+
`,_=new Blob([u],{type:"text/plain"}),d=URL.createObjectURL(_),m=document.createElement("a");m.href=d,m.download=`${l}.test.ts`,m.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:r,children:[G.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&&G.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:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},Idt=t=>t.activeSubSolver?[t,...Idt(t.activeSubSolver)]:[t],vJn=({solver:t})=>{const e=Idt(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>G.jsxs("div",{className:"flex items-center",children:[o>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(PJn,{solver:n})]},n.constructor.name))})},SJn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:r})=>{const[i,s]=Y.useReducer(p=>!p,!1),a=Y.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)};Y.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),Y.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 G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(vJn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.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"}),G.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"}),G.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"}),G.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&&G.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"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:h})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},CJn=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},MJn=(t,e)=>{const o=t.pipelineDef[e].solverName,r=CJn(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}},TJn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},wJn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},EJn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),DJn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=EJn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>G.jsxs("div",{children:[o,": ",String(r)]},o))})]})},Aye=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Aye);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Aye(o));return e},AJn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Aye(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)}`)}},RJn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>MJn(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):AJn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:o.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.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:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(TJn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(wJn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(DJn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.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:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.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"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},kJn=class extends cr.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 NJn({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,b=x.height??0;u(f,g),u(f+y,g+b)}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 G.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)=>G.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)=>G.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)=>G.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)=>G.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)=>G.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var HJn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[r,i]=Y.useReducer(u=>u+1,0),s=Y.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,r]),a=Y.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);Y.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 G.jsxs("div",{children:[G.jsx(SJn,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(kJn,{fallback:G.jsx(NJn,{graphics:s}),children:G.jsx(bJn,{graphics:s})}),c&&G.jsx(RJn,{solver:t,onStepUntilPhase:l})]})};const IJn=()=>{Y.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)},[])},LJn=t=>t.toLowerCase().includes("pack")?VDn:t.toLowerCase().includes("rout")?jDn:TDn,OJn=({solverEvents:t=[]})=>{const[e,n]=Y.useState(null);IJn();const o=Y.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),r=Y.useMemo(()=>Array.from(o.keys()),[o]),i=e?o.get(e):null,s=Y.useMemo(()=>{if(!i)return{instance:null,error:null,classFound:!1};const a=zie[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(zie).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?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.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."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.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 G.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=LJn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?G.jsx(M5,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:G.jsx(HJn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&G.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:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.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)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Ldt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Y.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{EW.captureException(o)}catch{}}},[t,e]),Y.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{EW.captureException(r,{error_type:o.type})}catch{}}},[n])},Odt="0.0.1890",FJn={version:Odt},bY=OIe()(FIe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),BJn=t=>{const[e,n]=Y.useState([]),[o,r]=Y.useState(null),[i,s]=Y.useState(""),[a,c]=RT("eval-version-selection",null),l=bY(m=>m.setLastRunEvalVersion),u=bY(m=>m.lastRunEvalVersion);return Y.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]),Y.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:Y.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("")}}},zJn=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[r,i]=Y.useState(""),[s,a]=Y.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 G.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:G.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[G.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),G.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}),G.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>G.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&&G.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,'"']})]}),G.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[G.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),G.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}`})]})]})})},VJn=t=>{const e=Y.useRef(null),n=eu(o=>o.recentEvents);Y.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 $Jn(t){const e=WJn(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(XJn);if(c){const l=c.props.children,u=a.map(_=>_===c?Y.Children.count(l)>1?Y.Children.only(null):Y.isValidElement(l)?l.props.children:null:_);return G.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return G.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function WJn(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=GJn(r),a=jJn(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?Rx(o,s):s),Y.cloneElement(r,a)}return Y.Children.count(r)>1?Y.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var UJn=Symbol("radix.slottable");function XJn(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===UJn}function jJn(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 GJn(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 PY="Dialog",[Fdt,Bdt]=d4(PY),[YJn,B4]=Fdt(PY),zdt=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!0}=t,a=Y.useRef(null),c=Y.useRef(null),[l,u]=DP({prop:o,defaultProp:r??!1,onChange:i,caller:PY});return G.jsx(YJn,{scope:e,triggerRef:a,contentRef:c,contentId:Jp(),titleId:Jp(),descriptionId:Jp(),open:l,onOpenChange:u,onOpenToggle:Y.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};zdt.displayName=PY;var Vdt="DialogTrigger",$dt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(Vdt,n),i=tu(e,r.triggerRef);return G.jsx(Cc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Nye(r.open),...o,ref:i,onClick:Vr(t.onClick,r.onOpenToggle)})});$dt.displayName=Vdt;var Rye="DialogPortal",[qJn,Wdt]=Fdt(Rye,{forceMount:void 0}),Udt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=B4(Rye,e);return G.jsx(qJn,{scope:e,forceMount:n,children:Y.Children.map(o,s=>G.jsx(Fg,{present:n||i.open,children:G.jsx(Lj,{asChild:!0,container:r,children:s})}))})};Udt.displayName=Rye;var vY="DialogOverlay",Xdt=Y.forwardRef((t,e)=>{const n=Wdt(vY,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=B4(vY,t.__scopeDialog);return i.modal?G.jsx(Fg,{present:o||i.open,children:G.jsx(KJn,{...r,ref:e})}):null});Xdt.displayName=vY;var JJn=$Jn("DialogOverlay.RemoveScroll"),KJn=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(vY,n);return G.jsx(Uj,{as:JJn,allowPinchZoom:!0,shards:[r.contentRef],children:G.jsx(Cc.div,{"data-state":Nye(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),Z8="DialogContent",jdt=Y.forwardRef((t,e)=>{const n=Wdt(Z8,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=B4(Z8,t.__scopeDialog);return G.jsx(Fg,{present:o||i.open,children:i.modal?G.jsx(QJn,{...r,ref:e}):G.jsx(ZJn,{...r,ref:e})})});jdt.displayName=Z8;var QJn=Y.forwardRef((t,e)=>{const n=B4(Z8,t.__scopeDialog),o=Y.useRef(null),r=tu(e,n.contentRef,o);return Y.useEffect(()=>{const i=o.current;if(i)return Y2e(i)},[]),G.jsx(Gdt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vr(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Vr(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:Vr(t.onFocusOutside,i=>i.preventDefault())})}),ZJn=Y.forwardRef((t,e)=>{const n=B4(Z8,t.__scopeDialog),o=Y.useRef(!1),r=Y.useRef(!1);return G.jsx(Gdt,{...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()}})}),Gdt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=B4(Z8,n),c=Y.useRef(null),l=tu(e,c);return D2e(),G.jsxs(G.Fragment,{children:[G.jsx(Sj,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:G.jsx(ZN,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Nye(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),G.jsxs(G.Fragment,{children:[G.jsx(tKn,{titleId:a.titleId}),G.jsx(oKn,{contentRef:c,descriptionId:a.descriptionId})]})]})}),kye="DialogTitle",Ydt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(kye,n);return G.jsx(Cc.h2,{id:r.titleId,...o,ref:e})});Ydt.displayName=kye;var qdt="DialogDescription",Jdt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(qdt,n);return G.jsx(Cc.p,{id:r.descriptionId,...o,ref:e})});Jdt.displayName=qdt;var Kdt="DialogClose",Qdt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=B4(Kdt,n);return G.jsx(Cc.button,{type:"button",...o,ref:e,onClick:Vr(t.onClick,()=>r.onOpenChange(!1))})});Qdt.displayName=Kdt;function Nye(t){return t?"open":"closed"}var Zdt="DialogTitleWarning",[eKn,eht]=AZt(Zdt,{contentName:Z8,titleName:kye,docsSlug:"dialog"}),tKn=({titleId:t})=>{const e=eht(Zdt),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
|
|
|
@@ -5782,6 +5782,6 @@ Please report this to https://github.com/markedjs/marked.`,t){const o="<p>An err
|
|
|
5782
5782
|
rf-max-h-[90vh] rf-overflow-y-auto
|
|
5783
5783
|
`,children:G.jsx("div",{className:"rf-relative rf-w-full",children:n==="initial"&&G.jsx(Weo,{onCancel:e,packageReleaseId:i??"",signIn:s??(()=>{}),isLoggedIn:a})})})})}),qeo=({isOpen:t,onClose:e,stage:n,setStage:o,signIn:r,isLoggedIn:i})=>{const s=eu(a=>a.circuitJson);return G.jsx(Yeo,{signIn:r,isOpen:t,onClose:e,stage:n,setStage:o,circuitJson:s,isLoggedIn:i??!1})},Jeo=()=>{const[t,e]=Y.useState(!1),[n,o]=Y.useState("initial");return{isOpen:t,stage:n,open:()=>e(!0),close:()=>{e(!1),o("initial")},setStage:o,OrderDialog:qeo}};async function zmt(){const t=await fetch(`${Ax}/files/list`),{file_list:e}=await t.json(),n=new Map;for(const o of e){const i=await(await fetch(`${Ax}/files/get?file_path=${encodeURIComponent(o.file_path)}`)).json();(i.file?.text_content||i.file?.binary_content_b64)&&n.set(o.file_path,{text_content:i.file.text_content,binary_content_b64:i.file.binary_content_b64})}return n}const Keo="https://api.tscircuit.com/bug_reports/view?bug_report_id=",Qeo=t=>`${Keo}${t}`,Zeo=t=>{const[e,n]=Y.useState(!1),[o,r]=Y.useState(!1),[i,s]=Y.useState(null),[a,c]=Y.useState(null),[l,u]=Y.useState([]),_=Y.useRef(null),[d,m]=Y.useState(null),[h,p]=Y.useState(0),x=t?.onLoginRequired,f=Y.useMemo(()=>NY()?!0:typeof document>"u"?!1:document.cookie.split(";").some(S=>S.trim().startsWith("session=")),[e]);Y.useEffect(()=>{if(e&&!d&&_.current){const S=typeof window<"u"?window.__TSCIRCUIT_LAST_EXECUTION_ERROR:void 0;S&&(_.current.value=`I'm getting this execution error:
|
|
5784
5784
|
|
|
5785
|
-
${S}`)}},[e,d]),Y.useEffect(()=>{e&&!d&&zmt().then(S=>{p(S.size)}).catch(S=>{console.error("Failed to fetch file count",S),p(0)})},[e,d]);const g=Y.useCallback(()=>{s(null),m(null),c(null),u([]),_.current&&(_.current.value=""),n(!0)},[]),y=Y.useCallback(()=>{n(!1)},[]),b=Y.useCallback(async()=>{r(!0),s(null),c(null),u([]);const S=Xv(),M=_.current?.value||"";try{const w=await zmt();if(w.size===0){ds.error("No project files available to include in the bug report"),r(!1);return}const D=new Date(Date.now()+1440*60*1e3).toISOString(),I=(await S.post("bug_reports/create",{json:{text:M.trim()||void 0,is_auto_deleted:!0,delete_at:D}}).json()).bug_report.bug_report_id,H=Array.from(w.entries()),O=[];for(let V=0;V<H.length;V++){const[j,q]=H[V];c({current:V+1,total:H.length,currentFile:j});try{const K={bug_report_id:I,file_path:j};q.text_content&&(K.content_text=q.text_content),q.binary_content_b64&&(K.content_base64=q.binary_content_b64),await S.post("bug_reports/upload_file",{json:K})}catch(K){const ne=K instanceof Uv?`HTTP ${K.response.status}`:K instanceof Error?K.message:"Upload failed";O.push({filePath:j,message:ne}),u([...O])}}c(null);const z=Qeo(I);m({bugReportUrl:z})}catch(w){if(console.error("Failed to submit bug report",w),w instanceof Uv)if(w.response.status===401)if(f){const D="Your session has expired. Please sign in again to continue.";s(D),ds.error(D),x&&(y(),x())}else{const D="You must be logged in to report a bug. Please sign in via cli and try again.";s(D),ds.error(D),setTimeout(()=>{x&&(y(),x())},1e3)}else{const D=`Failed to submit bug report (${w.response.status})`;s(D),ds.error(D)}else if(w instanceof Error)s(w.message),ds.error(w.message);else{const D="Failed to submit bug report";s(D),ds.error(D)}}finally{r(!1)}},[f,x]);return{BugReportDialog:Y.useMemo(()=>{const S=a?Math.round(a.current/a.total*100):0;return G.jsx(bht,{open:e,onOpenChange:M=>{M?(s(null),m(null),c(null),u([]),n(!0)):o||y()},children:G.jsxs(Fye,{children:[G.jsxs(Bye,{children:[G.jsx(Vye,{children:d?"Bug Report Created":"Report Bug"}),G.jsx($ye,{asChild:!0,children:d?G.jsxs("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:[G.jsx("p",{children:"Bug report created successfully."}),l.length>0&&G.jsxs("div",{className:"rf-bg-red-50 rf-border rf-border-red-200 rf-rounded rf-p-2 rf-max-h-28 rf-overflow-y-auto rf-overflow-x-hidden",children:[G.jsxs("p",{className:"rf-text-red-700 rf-font-medium rf-text-xs rf-mb-1",children:[l.length," file(s) failed:"]}),l.map((M,w)=>G.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[G.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),G.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},w))]}),G.jsx("div",{children:G.jsx("a",{className:"rf-text-blue-600 hover:rf-underline",href:d.bugReportUrl,target:"_blank",rel:"noreferrer",children:"View bug report"})}),G.jsxs("p",{children:["Please share this link privately with tscircuit staff so we can help debug. Join the",G.jsx("a",{className:"rf-ml-1 rf-text-blue-600 hover:rf-underline",href:"https://tscircuit.com/join",target:"_blank",rel:"noreferrer",children:"tscircuit Discord"}),"."]})]}):G.jsx("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:a?G.jsxs("div",{className:"rf-space-y-2 rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-flex rf-justify-between rf-text-xs",children:[G.jsx("span",{children:"Uploading files..."}),G.jsxs("span",{children:[a.current,"/",a.total]})]}),G.jsx("div",{className:"rf-w-full rf-h-2 rf-bg-gray-200 rf-rounded-full rf-overflow-hidden",children:G.jsx("div",{className:"rf-h-full rf-bg-blue-500 rf-transition-all rf-duration-150",style:{width:`${S}%`}})}),G.jsx("p",{className:"rf-text-xs rf-text-gray-500 rf-break-all rf-truncate rf-w-full rf-max-w-full",children:`${a.currentFile.slice(0,60)}${a.currentFile.length>60?"...":""}`}),l.length>0&&G.jsx("div",{className:"rf-bg-red-50 rf-border rf-border-red-200 rf-rounded rf-p-2 rf-max-h-20 rf-overflow-y-auto rf-overflow-x-hidden",children:l.map((M,w)=>G.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[G.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),G.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},w))})]}):G.jsxs(G.Fragment,{children:[G.jsxs("p",{children:["Reporting a bug will upload your entire project",h>0?` (${h} file${h===1?"":"s"})`:""," ","to tscircuit support."]}),G.jsxs("div",{className:"rf-space-y-2",children:[G.jsx("label",{htmlFor:"bug-description",className:"rf-block rf-font-medium",children:"Description (optional)"}),G.jsx("textarea",{ref:_,id:"bug-description",className:"rf-w-full rf-min-h-[100px] rf-px-3 rf-py-2 rf-text-sm rf-border rf-border-gray-300 rf-rounded-md focus:rf-outline-none focus:rf-ring-2 focus:rf-ring-blue-500",placeholder:"Describe the issue you're experiencing...",disabled:o})]}),G.jsxs("p",{children:["Share the generated bug report link privately with tscircuit staff so we can help debug your issue. You can also reach out on our",G.jsx("a",{className:"rf-ml-1 rf-text-blue-600 hover:rf-underline",href:"https://tscircuit.com/join",target:"_blank",rel:"noreferrer",children:"Discord community"}),"."]}),!f&&G.jsx("p",{className:"rf-text-red-600",children:"You appear to be logged out. Please log in before reporting a bug or the upload will fail."}),i&&G.jsx("p",{className:"rf-text-red-600",children:i})]})})})]}),G.jsx(zye,{children:d?G.jsx("button",{type:"button",className:fE(),onClick:()=>{y()},children:"Close"}):G.jsxs(G.Fragment,{children:[G.jsx(Wye,{disabled:o,onClick:()=>{o||y()},children:"Cancel"}),!f&&x?G.jsx("button",{type:"button",className:fE(),onClick:M=>{M.preventDefault(),y(),x()},children:"Sign In"}):G.jsx("button",{type:"button",className:h4(fE(),o&&"rf-opacity-70 rf-cursor-not-allowed"),disabled:o,onClick:M=>{M.preventDefault(),b()},children:o?"Reporting...":"Upload & Report"})]})})]})},"bug-report-dialog")},[e,o,y,i,d,h,f,b,x,a,l]),openBugReportDialog:g}};function eto({open:t,onOpenChange:e,onExport:n}){const[o,r]=Y.useState(!1),i=()=>{n({includeSilkscreen:o}),e(!1)},s=()=>{e(!1)};return G.jsx(QE,{open:t,onOpenChange:e,children:G.jsxs(eC,{children:[G.jsxs(tC,{children:[G.jsx(nC,{children:"LightBurn Export Options"}),G.jsx(ZE,{children:"Configure export settings for PCB laser ablation with LightBurn"})]}),G.jsx("div",{className:"rf-flex rf-flex-col rf-gap-4 rf-py-4",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-space-x-2",children:[G.jsx(lI,{id:"includeSilkscreen",checked:o,onCheckedChange:a=>r(a===!0)}),G.jsx("label",{htmlFor:"includeSilkscreen",className:"rf-text-xs rf-font-medium rf-leading-none peer-disabled:rf-cursor-not-allowed peer-disabled:rf-opacity-70",children:"Include silkscreen layer"})]})}),G.jsxs(uI,{children:[G.jsx(dc,{variant:"outline",onClick:s,children:"Cancel"}),G.jsx(dc,{onClick:i,children:"Export"})]})]})})}const tto=/#(\d+)/,nto=t=>{const e=t.match(tto);if(!e)return null;const n=Number.parseInt(e[1],10);return Number.isFinite(n)?n:null},oto=t=>{if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"){const e=new Date(t).getTime();return Number.isFinite(e)?e:null}return null},rto=t=>{if(!t)return null;let e=null,n=-1,o=-1;for(const[r,i]of Object.entries(t)){const s=nto(r),a=oto(i.createdAt);if(s!==null){s>n&&(n=s,e={key:r,value:i});continue}if(n===-1){if(a!==null&&a>o){o=a,e={key:r,value:i};continue}e||(e={key:r,value:i})}}return e},bI=t=>{const e=bY(De=>De.lastRunEvalVersion),n=eu(De=>De.currentMainComponentPath),[o,r]=Y.useState(null),[i,s]=Y.useState(!1),[a,c]=Y.useState(!0),[l,u]=Y.useState(!1),[_,d]=Y.useState(null),[m,h]=Y.useState(null),[p,x]=Y.useState(!1),[f,g]=Y.useState(null),[y,b]=Y.useState(null),[v,S]=Y.useState(!1),[M,w]=Y.useState(!1),[D,A]=Y.useState(!1),[I,H]=Y.useState(null),O=Jeo(),z=eu(De=>De.pushEvent),V=eu(De=>De.recentEvents),j=Y.useMemo(()=>Date.now(),[]);VJn(De=>{if(!(new Date(De.created_at).valueOf()<j+500)){if(De.event_type==="FILE_UPDATED"){s(!0);return}if(De.event_type==="SNIPPET_SAVED"){s(!1),c(!1),g("Snippet saved successfully."),S(!1);return}De.event_type==="REQUEST_EXPORT"&&(w(!0),g("Export processing..."),S(!1)),De.event_type==="EXPORT_CREATED"&&(g(`Export created: ${De.exportFilePath}`),S(!1),w(!1))}}),Y.useEffect(()=>{if(!l||_===null)return;const De=V.filter(xe=>new Date(xe.created_at).valueOf()>_),pe=De.find(xe=>xe.event_type==="FAILED_TO_SAVE_SNIPPET"),Me=De.find(xe=>xe.event_type==="SNIPPET_SAVED");pe&&(u(!1),d(null),b(pe.message??"Failed to save snippet. See console for error."),console.error(pe.message),S(!0),pe.error_code==="SNIPPET_UNSET"&&pe.available_snippet_names&&(h(pe.available_snippet_names),x(!0))),Me&&(u(!1),d(null),g("Snippet saved successfully."),S(!1))},[V,l]);const q=async()=>{u(!0),d(Date.now()),g(null),S(!1),await z({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:o})},ne=eu(De=>De.circuitJson)??t.circuitJson,[ce,ee]=Y.useState(!1),[oe,ie]=Y.useState(!1),{BugReportDialog:ae,openBugReportDialog:de}=Zeo({onLoginRequired:t.onLoginRequired}),be=async De=>{I&&(await qht({circuitJson:I.circuitJson,projectName:I.projectName,options:De}),H(null))},Ce=Y.useMemo(()=>rto(t.autoroutingLog),[t.autoroutingLog]);return G.jsxs(G.Fragment,{children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1 rf-flex-shrink-0",children:[G.jsxs(qj,{children:[G.jsx(Jj,{asChild:!0,children:G.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"File"})}),G.jsxs(uH,{className:"rf-z-[101]",children:[!t.isWebEmbedded&&G.jsxs(G.Fragment,{children:[G.jsx(Md,{className:"rf-text-xs",onSelect:q,disabled:l,children:l?"Saving...":"Push"}),parseInt(window.location.port)>5e3&&G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{O.open()},children:"Order"}),G.jsx(Md,{className:"rf-text-xs",onSelect:()=>ee(!0),disabled:l,children:"Import"}),G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{if(!NY()){ds.error("Requires tscircuit token");return}ie(!0)},children:"AI Review"})]}),!t.isWebEmbedded&&t.onLoginRequired&&G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{t.onLoginRequired?.()},children:"Sign In"}),!t.isWebEmbedded&&G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",children:"Report Bug"}),G.jsx(cH,{children:G.jsxs(EE,{children:[G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{de()},children:"Report Entire Circuit"}),G.jsx(Md,{className:"rf-text-xs",disabled:!Ce||!t.onReportAutoroutingLog,onSelect:()=>{!Ce||!t.onReportAutoroutingLog||t.onReportAutoroutingLog(Ce.key,{simpleRouteJson:Ce.value.simpleRouteJson})},children:"Report Autorouter Bug"})]})})]}),G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",disabled:M,children:M?"Exporting...":"Export"}),G.jsx(cH,{children:G.jsx(EE,{children:KQn.map((De,pe)=>G.jsx(Md,{onSelect:()=>{if(!ne){ds.error("No Circuit JSON to export");return}let Me="Untitled";if(n){const We=n.split("/").pop();We&&(Me=We.replace(/\.[^.]+$/,""))}const xe=t.projectName??o??Me;if(De.name==="LightBurn"){H({circuitJson:ne,projectName:xe}),A(!0);return}QQn({exportName:De.name,circuitJson:ne,projectName:xe?.replace(/\.(board|circuit)$/,"")})},disabled:M,children:G.jsx("span",{className:"rf-text-xs",children:De.name})},pe))})})]}),!t.isWebEmbedded&&G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",children:"Advanced"}),G.jsx(cH,{children:G.jsxs(EE,{children:[G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(lI,{id:"load-latest-eval",checked:t.shouldLoadLatestEval,onCheckedChange:De=>{t.onChangeShouldLoadLatestEval?.(De===!0)}}),G.jsx("label",{htmlFor:"load-latest-eval",className:"rf-text-xs rf-cursor-pointer",children:"Force Latest @tscircuit/eval"})]})}),e&&G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",children:G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:G.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/eval@",e]})})}),G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",children:G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:G.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/runframe@",FJn.version]})})}),G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",onClick:()=>{window.open("/api/admin","_blank")},children:G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:G.jsx("span",{className:"rf-text-xs",children:"CLI Admin Panel"})})})]})})]})]}),G.jsx(bht,{open:v,onOpenChange:S,children:G.jsxs(Fye,{children:[G.jsxs(Bye,{children:[G.jsx(Vye,{children:"Error Saving Snippet"}),G.jsx($ye,{children:y})]}),G.jsx(zye,{children:G.jsx(Wye,{onClick:()=>S(!1),children:"Dismiss"})})]})}),G.jsx(zJn,{snippetNames:m??[],onSelect:async De=>{u(!0),d(Date.now()),r(De),await z({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:De}),x(!1)},onCancel:()=>x(!1),isOpen:p})]}),G.jsxs(qj,{children:[G.jsx(Jj,{asChild:!0,children:G.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"View"})}),G.jsx(uH,{className:"rf-z-[104]",children:G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",children:"Schematic"}),G.jsx(cH,{children:G.jsxs(EE,{children:[G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",onSelect:De=>De.preventDefault(),children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(lI,{id:"show-schematic-ports",checked:t.showSchematicPorts,onCheckedChange:De=>{t.onChangeShowSchematicPorts?.(De===!0)}}),G.jsx("label",{htmlFor:"show-schematic-ports",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Ports"})]})}),G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",onSelect:De=>De.preventDefault(),children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(lI,{id:"show-schematic-grid",checked:t.showSchematicDebugGrid,onCheckedChange:De=>{t.onChangeShowSchematicDebugGrid?.(De===!0)}}),G.jsx("label",{htmlFor:"show-schematic-grid",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Grid"})]})})]})})]})})]})]}),ae,G.jsx(eto,{open:D,onOpenChange:A,onExport:be}),G.jsx(jht,{isOpen:ce,onClose:()=>ee(!1)}),G.jsx(seo,{isOpen:oe,onClose:()=>ie(!1),packageName:o}),G.jsx(QKe,{position:"top-center",reverseOrder:!1,containerStyle:{zIndex:1e5},toastOptions:{className:"rf-break-all",style:{zIndex:1e5}}}),G.jsx(O.OrderDialog,{isOpen:O.isOpen,onClose:O.close,stage:O.stage,setStage:O.setStage})]})},ito=["assembly","pinout","analog_simulation","bom","circuit_json","errors","render_log","solvers"],Vmt=({code:t,fsMap:e,onRunClicked:n=void 0,errorMessage:o,errorStack:r,circuitJson:i,autoroutingGraphics:s,showRightHeaderContent:a=!0,showCodeTab:c=!1,codeTabContent:l,showJsonTab:u=!0,showRenderLogTab:_=!0,onActiveTabChange:d,renderLog:m,showImportAndFormatButtons:h=!0,className:p,headerClassName:x,leftHeaderContent:f,readOnly:g,isStreaming:y,autoroutingLog:b,onReportAutoroutingLog:v,isRunningCode:S,hasCodeChangedSinceLastRun:M,onEditEvent:w,editEvents:D,defaultActiveTab:A,defaultTab:I,availableTabs:H,autoRotate3dViewerDisabled:O,showSchematicDebugGrid:z=!1,showSchematicPorts:V=!1,onChangeShowSchematicDebugGrid:j,onChangeShowSchematicPorts:q,showToggleFullScreen:K=!0,defaultToFullScreen:ne=!1,activeEffectName:ce,allowSelectingVersion:ee=!0,showFileMenu:oe=!1,isWebEmbedded:ie=!1,projectName:ae,onRerunWithDebug:de,solverEvents:be})=>{xY();const{versions:Ce,latestVersion:De,lastRunEvalVersion:pe,search:Me,setSearch:xe,selectVersion:We}=BJn(ee),Xe=Y.useMemo(()=>i?i.filter(Dt=>Dt&&"error_type"in Dt||Dt.type.includes("error")):null,[i]),Je=Y.useMemo(()=>i?i.filter(Dt=>Dt&&"warning_type"in Dt||Dt.type.includes("warning")):null,[i]),fe=Y.useMemo(()=>i?i.some(Dt=>Dt.type==="schematic_group"):!0,[i]),Ye=Y.useMemo(()=>i?.some(Dt=>Dt.type==="pcb_panel"),[i]);Ldt({errorMessage:o,errorStack:r,circuitJsonErrors:Xe});const Oe=I??H?.[0]??"pcb",[Ne,Ve]=RT("runframe-active-tab",A??Oe,A),[Re,Pe]=Y.useState(null),[Ee,we]=Y.useState(ne),[ze,Ue]=Y.useState(z),[et,ot]=Y.useState(V),at=j?z:ze,lt=q?V:et,xt=j??Ue,Ct=q??ot;ZYn(Ee);const Lt=Y.useCallback(Dt=>{Ve(Dt),d?.(Dt)},[d,Ve]),$t=()=>{we(!Ee)};Y.useEffect(()=>{o&&(Ne!=="errors"&&Pe(Ne),Lt("errors"))},[o]),Y.useEffect(()=>{(Ne==="code"||Ne==="errors")&&i&&!o&&Lt(Re??A??I??H?.[0]??"pcb")},[i]);const Ot=Y.useCallback(Dt=>{window.TSCIRCUIT_3D_OBJECT_REF=Dt===null?void 0:Dt},[]);return G.jsx("div",{className:lr("flex flex-col relative rf-overflow-x-hidden rf-h-full",p),children:G.jsx("div",{className:lr("rf-md:sticky rf-md:top-2 rf-h-full",Ee&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-h-full rf-bg-white rf-overflow-hidden"),children:G.jsxs(gae,{value:Ne,onValueChange:Lt,className:"rf-flex-grow rf-flex rf-flex-col rf-h-full",children:[G.jsxs("div",{className:lr("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",x),children:[f,oe&&!f&&G.jsx(bI,{isWebEmbedded:ie,circuitJson:i,projectName:ae,showSchematicDebugGrid:at,onChangeShowSchematicDebugGrid:xt,showSchematicPorts:lt,onChangeShowSchematicPorts:Ct}),(f||oe)&&G.jsx("div",{className:"rf-flex-grow"}),!f&&!oe&&S&&G.jsx($9,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!f&&!oe&&G.jsx("div",{className:"rf-flex-grow"}),m&&m.progress!==1&&!o&&G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-min-w-0 rf-max-w-xs",children:[ce?G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:ce,children:ce}):m.lastRenderEvent&&G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:m.lastRenderEvent?.phase??"",children:m.lastRenderEvent?.phase??""}),G.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white rf-flex-shrink-0",children:G.jsx($9,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),G.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums rf-flex-shrink-0",children:[((m.progress??0)*100).toFixed(1),"%"]})]}),a&&G.jsxs(AW,{children:[c&&G.jsx(z6,{value:"code",children:"Code"}),!H||H.includes("pcb")?G.jsxs(z6,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&G.jsx("span",{className:lr("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",M?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}):null,!H||H.includes("schematic")?G.jsxs(z6,{value:"schematic",className:lr("rf-whitespace-nowrap",i&&!fe&&"rf-opacity-50"),disabled:i?!fe||Ye:!1,children:[i&&G.jsx("span",{className:lr("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",M?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}):null,!H||H.includes("cad")?G.jsxs(z6,{value:"cad",children:[i&&G.jsx("span",{className:lr("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",M?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}):null,!["pcb","cad","schematic"].includes(Ne)&&G.jsx(z6,{value:Ne,children:VFe(Ne)}),G.jsxs(qj,{children:[G.jsx(Jj,{asChild:!0,children:G.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[G.jsx(IDn,{className:"rf-w-4 rf-h-4"}),(Xe&&Xe.length>0||o)&&G.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),G.jsxs(uH,{className:"rf-*:text-xs rf-z-[101]",children:[ito.filter(Dt=>!H||H.includes(Dt)).map(Dt=>G.jsxs(Md,{onSelect:()=>Lt(Dt),children:[Ne!==Dt&&G.jsx(sot,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Ne===Dt&&G.jsx(T8,{className:"rf-w-3 rf-h-3"}),G.jsx("div",{className:"rf-pr-2",children:VFe(Dt)}),Dt==="errors"&&(Xe&&Xe.length>0||o)&&G.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:o?1:Xe?.length}),Dt==="solvers"&&be&&be.length>0&&G.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-min-w-[12px] rf-h-3 rf-px-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-blue-500 rf-rounded-full",children:be.length})]},Dt)),G.jsx(Md,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:G.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",Odt.split(".").map((Dt,Wt)=>Wt===2?parseInt(Dt)+1:Dt).join(".")]})}),ee?G.jsxs(lH,{onOpenChange:Dt=>!Dt&&xe(""),children:[G.jsx(wE,{className:"rf-text-xs rf-opacity-60",children:G.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",pe??De??"latest"]})}),G.jsx(cH,{children:G.jsxs(EE,{className:"rf-*:text-xs rf-w-40 rf-max-h-[200px] rf-overflow-y-auto",children:[G.jsx("div",{className:"rf-p-1",children:G.jsx(age,{value:Me,onChange:Dt=>xe(Dt.target.value),placeholder:"Search...",className:"rf-h-7 rf-text-xs"})}),G.jsx(ait,{}),G.jsx(Md,{onSelect:()=>We(null),children:De?`${De} (latest)`:"latest"}),Ce.map(Dt=>G.jsx(Md,{onSelect:()=>We(Dt),children:Dt},Dt))]})})]}):pe&&G.jsx(Md,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:G.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",pe]})})]})]})]}),K&&G.jsx(dc,{onClick:$t,variant:"ghost",children:Ee?G.jsx(UDn,{size:16}):G.jsx(zDn,{size:16})})]}),c&&G.jsx(a1,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:G.jsx("div",{className:"rf-h-full",children:l})}),(!H||H.includes("pcb"))&&G.jsx(a1,{value:"pcb",children:G.jsx("div",{className:lr("rf-overflow-hidden",Ee?"rf-h-[calc(100vh-52px)]":"rf-h-full"),children:G.jsx(M5,{fallbackRender:({error:Dt})=>G.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:Dt?.message||"An unknown error occurred"})]})}),children:i?G.jsx(KYn,{focusOnHover:!1,circuitJson:i,debugGraphics:s,containerClassName:lr("rf-h-full rf-w-full",Ee?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Dt=>{if(w)for(const Wt of Dt)w(Wt)}}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("assembly"))&&G.jsx(a1,{value:"assembly",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Assembly"}),children:i?G.jsx(KVn,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("pinout"))&&G.jsx(a1,{value:"pinout",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Pinout Viewer"}),children:i?G.jsx(QVn,{circuitJson:i,containerStyle:{height:"100%"}}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("schematic"))&&G.jsx(a1,{value:"schematic",children:G.jsx("div",{className:lr("rf-overflow-auto rf-bg-white",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallbackRender:({error:Dt})=>G.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:Dt?.message||"An unknown error occurred"})]})}),children:i?G.jsx(qVn,{spiceSimulationEnabled:!0,circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Dt=>{w?.(Dt)},debugGrid:at,showSchematicPorts:lt}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("cad"))&&G.jsx(a1,{value:"cad",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallbackRender:({error:Dt,resetErrorBoundary:Wt})=>G.jsx(fDn,{error:Dt,resetErrorBoundary:Wt}),children:i?G.jsx(sDn,{ref:Ot,circuitJson:i,autoRotateDisabled:O},`cad-${Ee}`):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("analog_simulation"))&&G.jsx(a1,{value:"analog_simulation",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Analog Simulation"}),children:i?G.jsx(JVn,{circuitJson:i,containerStyle:{height:"100%"}}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("bom"))&&G.jsx(a1,{value:"bom",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallbackRender:({error:Dt})=>G.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:Dt?.message||"An unknown error occurred"})]})}),children:i?G.jsx(m$n,{circuitJson:i}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("circuit_json"))&&G.jsx(a1,{value:"circuit_json",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading JSON viewer"}),children:i?G.jsx(t$n,{elements:i}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("errors"))&&G.jsx(a1,{value:"errors",className:"rf-h-full",children:G.jsx("div",{className:lr("rf-overflow-hidden",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:o||Xe&&Xe.length>0||i?G.jsx(VNn,{code:t,fsMap:e,circuitJsonErrors:Xe,circuitJsonWarnings:Je,errorMessage:o,errorStack:r,circuitJson:i,evalVersion:pe,autoroutingLog:b,onReportAutoroutingLog:v}):G.jsx(J9,{onRunClicked:n})})}),_&&(!H||H.includes("render_log"))&&G.jsx(a1,{value:"render_log",children:G.jsx(nqn,{renderLog:m,onRerunWithDebug:de})}),(!H||H.includes("solvers"))&&G.jsx(a1,{value:"solvers",children:G.jsx("div",{className:lr("rf-overflow-hidden",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Solvers view"}),children:G.jsx(OJn,{solverEvents:be})})})})]})})})};const $mt=Symbol("Comlink.proxy"),sto=Symbol("Comlink.endpoint"),Wmt=Symbol("Comlink.releaseProxy"),T5e=Symbol("Comlink.finalizer"),JY=Symbol("Comlink.thrown"),Umt=t=>typeof t=="object"&&t!==null||typeof t=="function",ato={canHandle:t=>Umt(t)&&t[$mt],serialize(t){const{port1:e,port2:n}=new MessageChannel;return jmt(t,e),[n,[n]]},deserialize(t){return t.start(),Ymt(t)}},cto={canHandle:t=>Umt(t)&&JY in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},Xmt=new Map([["proxy",ato],["throw",cto]]);function lto(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function jmt(t,e=globalThis,n=["*"]){e.addEventListener("message",function o(r){if(!r||!r.data)return;if(!lto(n,r.origin)){console.warn(`Invalid origin '${r.origin}' for comlink proxy`);return}const{id:i,type:s,path:a}=Object.assign({path:[]},r.data),c=(r.data.argumentList||[]).map(lC);let l;try{const u=a.slice(0,-1).reduce((d,m)=>d[m],t),_=a.reduce((d,m)=>d[m],t);switch(s){case"GET":l=_;break;case"SET":u[a.slice(-1)[0]]=lC(r.data.value),l=!0;break;case"APPLY":l=_.apply(u,c);break;case"CONSTRUCT":{const d=new _(...c);l=E5e(d)}break;case"ENDPOINT":{const{port1:d,port2:m}=new MessageChannel;jmt(t,m),l=mto(d,[d])}break;case"RELEASE":l=void 0;break;default:return}}catch(u){l={value:u,[JY]:0}}Promise.resolve(l).catch(u=>({value:u,[JY]:0})).then(u=>{const[_,d]=eq(u);e.postMessage(Object.assign(Object.assign({},_),{id:i}),d),s==="RELEASE"&&(e.removeEventListener("message",o),Gmt(e),T5e in t&&typeof t[T5e]=="function"&&t[T5e]())}).catch(u=>{const[_,d]=eq({value:new TypeError("Unserializable return value"),[JY]:0});e.postMessage(Object.assign(Object.assign({},_),{id:i}),d)})}),e.start&&e.start()}function uto(t){return t.constructor.name==="MessagePort"}function Gmt(t){uto(t)&&t.close()}function Ymt(t,e){const n=new Map;return t.addEventListener("message",function(r){const{data:i}=r;if(!i||!i.id)return;const s=n.get(i.id);if(s)try{s(i)}finally{n.delete(i.id)}}),w5e(t,n,[],e)}function KY(t){if(t)throw new Error("Proxy has been released and is not useable")}function qmt(t){return nD(t,new Map,{type:"RELEASE"}).then(()=>{Gmt(t)})}const QY=new WeakMap,ZY="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(QY.get(t)||0)-1;QY.set(t,e),e===0&&qmt(t)});function _to(t,e){const n=(QY.get(e)||0)+1;QY.set(e,n),ZY&&ZY.register(t,e,t)}function dto(t){ZY&&ZY.unregister(t)}function w5e(t,e,n=[],o=function(){}){let r=!1;const i=new Proxy(o,{get(s,a){if(KY(r),a===Wmt)return()=>{dto(i),qmt(t),e.clear(),r=!0};if(a==="then"){if(n.length===0)return{then:()=>i};const c=nD(t,e,{type:"GET",path:n.map(l=>l.toString())}).then(lC);return c.then.bind(c)}return w5e(t,e,[...n,a])},set(s,a,c){KY(r);const[l,u]=eq(c);return nD(t,e,{type:"SET",path:[...n,a].map(_=>_.toString()),value:l},u).then(lC)},apply(s,a,c){KY(r);const l=n[n.length-1];if(l===sto)return nD(t,e,{type:"ENDPOINT"}).then(lC);if(l==="bind")return w5e(t,e,n.slice(0,-1));const[u,_]=Jmt(c);return nD(t,e,{type:"APPLY",path:n.map(d=>d.toString()),argumentList:u},_).then(lC)},construct(s,a){KY(r);const[c,l]=Jmt(a);return nD(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:c},l).then(lC)}});return _to(i,t),i}function hto(t){return Array.prototype.concat.apply([],t)}function Jmt(t){const e=t.map(eq);return[e.map(n=>n[0]),hto(e.map(n=>n[1]))]}const Kmt=new WeakMap;function mto(t,e){return Kmt.set(t,e),t}function E5e(t){return Object.assign(t,{[$mt]:!0})}function eq(t){for(const[e,n]of Xmt)if(n.canHandle(t)){const[o,r]=n.serialize(t);return[{type:"HANDLER",name:e,value:o},r]}return[{type:"RAW",value:t},Kmt.get(t)||[]]}function lC(t){switch(t.type){case"HANDLER":return Xmt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function nD(t,e,n,o){return new Promise(r=>{const i=pto();e.set(i,r),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),o)})}function pto(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function D5e(t,e=""){const n=[];for(const o in t){if(!Object.prototype.hasOwnProperty.call(t,o))continue;const r=t[o],i=e?`${e}.${o}`:o;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){const s=D5e(r,i);n.push(...s)}else n.push(i)}return n}function Qmt(t,e){const n=e.split(".");let o=t;for(const r of n)o=o[r];return o}var Zmt=async t=>{const e=globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER;if(e&&typeof e.kill=="function"){t.verbose&&console.log("[Worker] Killing previous global worker instance...");try{await e.kill()}catch(d){t.verbose&&console.warn("[Worker] Error killing previous global worker instance:",d),globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER===e&&(globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER=void 0)}}t.verbose&&console.log("[Worker] Creating circuit web worker with config:",t);let n=t.webWorkerBlobUrl??t.webWorkerUrl;if(!n){const d=`https://cdn.jsdelivr.net/npm/@tscircuit/eval@${t.evalVersion??"latest"}/dist/webworker/entrypoint.js`,m=await globalThis.fetch(d).then(h=>h.blob());n=URL.createObjectURL(m)}const o=new Worker(n,{type:"module"});let r;o.addEventListener("error",d=>{console.error("[Worker] Error in worker",d),r=d}),o.addEventListener("unhandledrejection",d=>{console.error("[Worker] Unhandled rejection in worker",d)}),o.addEventListener("messageerror",d=>{console.error("[Worker] Message error in worker",d)});const i=d=>{console.log("[Worker] Message in worker",d)};if(o.addEventListener("message",i),o.addEventListener("message",async d=>{const m=d.data;if(m?.type==="worker_fetch")try{const h=await globalThis.fetch(m.input,m.init),p=await h.text();o.postMessage({type:"worker_fetch_result",requestId:m.requestId,success:!0,response:{body:p,status:h.status,statusText:h.statusText,headers:(()=>{const x={};return h.headers.forEach((f,g)=>{x[g]=f}),x})()}})}catch(h){o.postMessage({type:"worker_fetch_result",requestId:m.requestId,success:!1,error:{name:h.name,message:h.message,stack:h.stack}})}}),r)throw r;const s=Ymt(o);o.removeEventListener("message",i);function a(d){return!d||typeof d!="object"?d:d.type&&d.props!==void 0?{__isSerializedReactElement:!0,type:d.type,props:c(d.props),key:d.key}:d}function c(d){if(!d||typeof d!="object")return d;const m={};for(const[h,p]of Object.entries(d))h==="children"?Array.isArray(p)?m.children=p.map(a):m.children=a(p):m[h]=p;return m}t.enableFetchProxy&&o.postMessage({type:"override_global_fetch"}),t.disableCdnLoading&&await s.setDisableCdnLoading(!0),t.snippetsApiBaseUrl&&await s.setSnippetsApiBaseUrl(t.snippetsApiBaseUrl),t.tscircuitSessionToken&&await s.setTscircuitSessionToken(t.tscircuitSessionToken);const l=d=>typeof d=="function"?E5e(d):d;if(t.platform)for(const d of D5e(t.platform))await s.setPlatformConfigProperty(d,l(Qmt(t.platform,d))).catch(m=>{throw new Error(`Error setting platform config property ${d}: ${m instanceof Error?m.message:String(m)}`)});if(t.projectConfig)for(const d of D5e(t.projectConfig))await s.setProjectConfigProperty(d,l(Qmt(t.projectConfig,d))).catch(m=>{throw new Error(`Error setting project config property ${d}: ${m instanceof Error?m.message:String(m)}`)});let u=!1;const _={clearEventListeners:s.clearEventListeners.bind(s),enableDebug:async(...d)=>{if(u)throw new Error("CircuitWebWorker was terminated, can't enableDebug");return s.enableDebug.bind(s)(...d)},version:s.version.bind(s),execute:async(...d)=>{if(u)throw new Error("CircuitWebWorker was terminated, can't execute");return s.execute.bind(s)(...d)},executeComponent:async d=>{if(u)throw new Error("CircuitWebWorker was terminated, can't executeComponent");if(typeof d=="function")return s.executeComponent.bind(s)(d);if(d&&typeof d=="object"&&d.type){const m=a(d);return s.executeComponent.bind(s)(m)}return s.executeComponent.bind(s)(d)},executeWithFsMap:async(...d)=>{if(u)throw new Error("CircuitWebWorker was terminated, can't executeWithFsMap");return s.executeWithFsMap.bind(s)(...d)},renderUntilSettled:s.renderUntilSettled.bind(s),getCircuitJson:s.getCircuitJson.bind(s),on:(d,m)=>{const h=E5e(m);s.on(d,h)},kill:async()=>{s[Wmt](),o.terminate(),u=!0,globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER===_&&(globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER=void 0)}};return _.__rawWorker=o,globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER=_,_};const fto=({error:t,resetErrorBoundary:e})=>G.jsx("section",{className:"rf-h-full rf-w-full rf-grid rf-place-items-center",children:G.jsx("div",{className:"rf-min-h-full rf-flex rf-items-center rf-justify-center rf-px-4",children:G.jsxs("div",{className:"rf-max-w-lg rf-w-full rf-text-center",children:[G.jsxs("div",{className:"rf-mb-8",children:[G.jsx("div",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-20 rf-h-20 rf-bg-red-100 rf-rounded-full rf-mb-6",children:G.jsx(qDn,{className:"rf-w-10 rf-h-10 rf-text-red-600"})}),G.jsx("h1",{className:"rf-text-2xl rf-font-bold rf-text-gray-900 rf-mb-3",children:"Oops! Something went wrong"}),G.jsx("p",{className:"rf-text-gray-600 rf-mb-4",children:"RunFrame encountered an unexpected error."}),G.jsx("pre",{className:"rf-text-xs no-scrollbar rf-font-mono rf-text-left rf-whitespace-pre-wrap rf-text-red-600 rf-bg-red-50 rf-border rf-border-red-200 rf-p-3 rf-rounded-lg rf-mb-4 rf-overflow-auto rf-max-h-[120px]",children:t.message}),t.stack&&G.jsxs("details",{className:"rf-text-center rf-mb-6",children:[G.jsx("summary",{className:"rf-text-xs rf-text-gray-500 rf-cursor-pointer hover:rf-text-gray-700",children:"View stack trace"}),G.jsx("pre",{className:"rf-text-xs rf-font-mono no-scrollbar rf-whitespace-pre-wrap rf-text-gray-500 rf-bg-gray-100 rf-p-3 rf-rounded-lg rf-mt-2 rf-overflow-auto rf-text-left rf-max-h-[150px]",children:t.stack})]})]}),G.jsxs("div",{className:"rf-flex rf-flex-col rf-gap-2 rf-justify-center",children:[G.jsx(dc,{variant:"destructive",size:"lg",onClick:()=>window.location.reload(),children:"Refresh Dev Server"}),G.jsx(dc,{variant:"outline",size:"lg",onClick:e,children:"Try Again"})]})]})})}),ept=t=>{const e={};if(!t)return e;for(const o of Og)e[o]=0;const n=new Map;for(const o of t){const[,,r,i]=o.type.split(":");if(i==="start"){n.set(`${r}:${o.renderId}`,o);continue}if(i==="end"){const s=n.get(`${r}:${o.renderId}`);if(s){const a=o.createdAt-s.createdAt;e[r]=(e[r]||0)+a}}}return e},xto=(t,e)=>{const n={};for(const[o,r]of t.entries()){const i=e.get(o);i!==r&&(n[o]={old:r,new:i})}for(const[o,r]of e.entries())t.has(o)||(n[o]={old:void 0,new:r});return n};function gto(){const t=Y.useRef(Promise.resolve()),e=Y.useRef(!1),n=Y.useRef(null),o=Y.useCallback(async s=>{await t.current;const a={cancelled:!1};n.current=a;let c;const l=new Promise(u=>{c=u});try{return t.current=l,e.current=!0,await s()}catch(u){if(!a.cancelled)throw u}finally{e.current=!1,n.current=null,c()}},[]),r=Y.useCallback(()=>{n.current&&(n.current.cancelled=!0),t.current=Promise.resolve(),e.current=!1},[]),i=Y.useCallback(()=>e.current,[]);return{runWithMutex:o,isLocked:i,cancel:r}}const yto=({message:t="Loading files..."})=>G.jsxs("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full",children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4 rf-p-2 rf-border-b",children:[G.jsx("div",{className:"rf-w-20 rf-h-9 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded-md rf-animate-pulse"}),G.jsx("div",{className:"rf-flex rf-gap-6 rf-ml-auto",children:["PCB","Schematic","3D"].map((e,n)=>G.jsx("div",{className:"rf-h-6 rf-w-20 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded rf-animate-pulse"},n))})]}),G.jsx("div",{className:"rf-flex-1 rf-p-4",children:G.jsx("div",{className:"rf-w-full rf-h-full rf-rounded-lg rf-bg-gray-100 dark:rf-bg-gray-800 rf-animate-pulse rf-flex rf-items-center rf-justify-center",children:G.jsx("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4",children:G.jsx("div",{className:"rf-text-sm rf-text-gray-400 dark:rf-text-gray-500",children:t})})})})]}),tq=t=>{const e=t.toLowerCase(),n=e.split("/").pop();return e.endsWith(".circuit.json")||n==="circuit.json"},bto=t=>t.endsWith(".tsx")||tq(t)||t.endsWith(".jsx"),Pto=({mainComponentPath:t,fsMap:e})=>Y.useMemo(()=>{if(!(t!=null&&tq(t)))return{isStaticCircuitJson:!1,circuitJson:null,error:null};const o=e.get(t);if(!o)return{isStaticCircuitJson:!0,circuitJson:null,error:`Circuit JSON file not found: ${t}`};try{return{isStaticCircuitJson:!0,circuitJson:JSON.parse(o),error:null}}catch(r){return{isStaticCircuitJson:!0,circuitJson:null,error:`Failed to parse circuit.json: ${r instanceof Error?r.message:String(r)}`}}},[t,e]),vto=t=>!t||typeof t!="object"?!1:!!("error_type"in t||typeof t.type=="string"&&t.type.includes("error")),Sto=t=>t instanceof Error?{name:t.name,message:t.message,stack:t.stack}:typeof t=="string"?{message:t}:t&&typeof t=="object"?t:{message:String(t)},Cto=t=>Array.isArray(t)?t.filter(vto):[],A5e=({circuitJson:t,executionError:e})=>{const n=[];e&&n.push(Sto(e));const o=Cto(t);return n.push(...o),{hasExecutionError:!!e,...n.length>0?{errors:n}:{}}};var Mto=Symbol("radix.slottable");function Tto(t){const e=({children:n})=>G.jsx(G.Fragment,{children:n});return e.displayName=`${t}.Slottable`,e.__radixId=Mto,e}var wto=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Eto="VisuallyHidden",tpt=Y.forwardRef((t,e)=>G.jsx(Cc.span,{...t,ref:e,style:{...wto,...t.style}}));tpt.displayName=Eto;var Dto=tpt,[nq]=d4("Tooltip",[vE]),oq=vE(),npt="TooltipProvider",Ato=700,R5e="tooltip.open",[Rto,k5e]=nq(npt),opt=t=>{const{__scopeTooltip:e,delayDuration:n=Ato,skipDelayDuration:o=300,disableHoverableContent:r=!1,children:i}=t,s=Y.useRef(!0),a=Y.useRef(!1),c=Y.useRef(0);return Y.useEffect(()=>{const l=c.current;return()=>window.clearTimeout(l)},[]),G.jsx(Rto,{scope:e,isOpenDelayedRef:s,delayDuration:n,onOpen:Y.useCallback(()=>{window.clearTimeout(c.current),s.current=!1},[]),onClose:Y.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>s.current=!0,o)},[o]),isPointerInTransitRef:a,onPointerInTransitChange:Y.useCallback(l=>{a.current=l},[]),disableHoverableContent:r,children:i})};opt.displayName=npt;var PI="Tooltip",[kto,rq]=nq(PI),rpt=t=>{const{__scopeTooltip:e,children:n,open:o,defaultOpen:r,onOpenChange:i,disableHoverableContent:s,delayDuration:a}=t,c=k5e(PI,t.__scopeTooltip),l=oq(e),[u,_]=Y.useState(null),d=Jp(),m=Y.useRef(0),h=s??c.disableHoverableContent,p=a??c.delayDuration,x=Y.useRef(!1),[f,g]=DP({prop:o,defaultProp:r??!1,onChange:M=>{M?(c.onOpen(),document.dispatchEvent(new CustomEvent(R5e))):c.onClose(),i?.(M)},caller:PI}),y=Y.useMemo(()=>f?x.current?"delayed-open":"instant-open":"closed",[f]),b=Y.useCallback(()=>{window.clearTimeout(m.current),m.current=0,x.current=!1,g(!0)},[g]),v=Y.useCallback(()=>{window.clearTimeout(m.current),m.current=0,g(!1)},[g]),S=Y.useCallback(()=>{window.clearTimeout(m.current),m.current=window.setTimeout(()=>{x.current=!0,g(!0),m.current=0},p)},[p,g]);return Y.useEffect(()=>()=>{m.current&&(window.clearTimeout(m.current),m.current=0)},[]),G.jsx(Hj,{...l,children:G.jsx(kto,{scope:e,contentId:d,open:f,stateAttribute:y,trigger:u,onTriggerChange:_,onTriggerEnter:Y.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:Y.useCallback(()=>{h?v():(window.clearTimeout(m.current),m.current=0)},[v,h]),onOpen:b,onClose:v,disableHoverableContent:h,children:n})})};rpt.displayName=PI;var N5e="TooltipTrigger",ipt=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=rq(N5e,n),i=k5e(N5e,n),s=oq(n),a=Y.useRef(null),c=tu(e,a,r.onTriggerChange),l=Y.useRef(!1),u=Y.useRef(!1),_=Y.useCallback(()=>l.current=!1,[]);return Y.useEffect(()=>()=>document.removeEventListener("pointerup",_),[_]),G.jsx(Ij,{asChild:!0,...s,children:G.jsx(Cc.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...o,ref:c,onPointerMove:Vr(t.onPointerMove,d=>{d.pointerType!=="touch"&&!u.current&&!i.isPointerInTransitRef.current&&(r.onTriggerEnter(),u.current=!0)}),onPointerLeave:Vr(t.onPointerLeave,()=>{r.onTriggerLeave(),u.current=!1}),onPointerDown:Vr(t.onPointerDown,()=>{r.open&&r.onClose(),l.current=!0,document.addEventListener("pointerup",_,{once:!0})}),onFocus:Vr(t.onFocus,()=>{l.current||r.onOpen()}),onBlur:Vr(t.onBlur,r.onClose),onClick:Vr(t.onClick,r.onClose)})})});ipt.displayName=N5e;var Nto="TooltipPortal",[Rao,Hto]=nq(Nto,{forceMount:void 0}),oD="TooltipContent",spt=Y.forwardRef((t,e)=>{const n=Hto(oD,t.__scopeTooltip),{forceMount:o=n.forceMount,side:r="top",...i}=t,s=rq(oD,t.__scopeTooltip);return G.jsx(Fg,{present:o||s.open,children:s.disableHoverableContent?G.jsx(apt,{side:r,...i,ref:e}):G.jsx(Ito,{side:r,...i,ref:e})})}),Ito=Y.forwardRef((t,e)=>{const n=rq(oD,t.__scopeTooltip),o=k5e(oD,t.__scopeTooltip),r=Y.useRef(null),i=tu(e,r),[s,a]=Y.useState(null),{trigger:c,onClose:l}=n,u=r.current,{onPointerInTransitChange:_}=o,d=Y.useCallback(()=>{a(null),_(!1)},[_]),m=Y.useCallback((h,p)=>{const x=h.currentTarget,f={x:h.clientX,y:h.clientY},g=zto(f,x.getBoundingClientRect()),y=Vto(f,g),b=$to(p.getBoundingClientRect()),v=Uto([...y,...b]);a(v),_(!0)},[_]);return Y.useEffect(()=>()=>d(),[d]),Y.useEffect(()=>{if(c&&u){const h=x=>m(x,u),p=x=>m(x,c);return c.addEventListener("pointerleave",h),u.addEventListener("pointerleave",p),()=>{c.removeEventListener("pointerleave",h),u.removeEventListener("pointerleave",p)}}},[c,u,m,d]),Y.useEffect(()=>{if(s){const h=p=>{const x=p.target,f={x:p.clientX,y:p.clientY},g=c?.contains(x)||u?.contains(x),y=!Wto(f,s);g?d():y&&(d(),l())};return document.addEventListener("pointermove",h),()=>document.removeEventListener("pointermove",h)}},[c,u,s,l,d]),G.jsx(apt,{...t,ref:i})}),[Lto,Oto]=nq(PI,{isInside:!1}),Fto=Tto("TooltipContent"),apt=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,children:o,"aria-label":r,onEscapeKeyDown:i,onPointerDownOutside:s,...a}=t,c=rq(oD,n),l=oq(n),{onClose:u}=c;return Y.useEffect(()=>(document.addEventListener(R5e,u),()=>document.removeEventListener(R5e,u)),[u]),Y.useEffect(()=>{if(c.trigger){const _=d=>{d.target?.contains(c.trigger)&&u()};return window.addEventListener("scroll",_,{capture:!0}),()=>window.removeEventListener("scroll",_,{capture:!0})}},[c.trigger,u]),G.jsx(ZN,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:s,onFocusOutside:_=>_.preventDefault(),onDismiss:u,children:G.jsxs(X2e,{"data-state":c.stateAttribute,...l,...a,ref:e,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[G.jsx(Fto,{children:o}),G.jsx(Lto,{scope:n,isInside:!0,children:G.jsx(Dto,{id:c.contentId,role:"tooltip",children:r||o})})]})})});spt.displayName=oD;var cpt="TooltipArrow",Bto=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=oq(n);return Oto(cpt,n).isInside?null:G.jsx(j2e,{...r,...o,ref:e})});Bto.displayName=cpt;function zto(t,e){const n=Math.abs(e.top-t.y),o=Math.abs(e.bottom-t.y),r=Math.abs(e.right-t.x),i=Math.abs(e.left-t.x);switch(Math.min(n,o,r,i)){case i:return"left";case r:return"right";case n:return"top";case o:return"bottom";default:throw new Error("unreachable")}}function Vto(t,e,n=5){const o=[];switch(e){case"top":o.push({x:t.x-n,y:t.y+n},{x:t.x+n,y:t.y+n});break;case"bottom":o.push({x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y-n});break;case"left":o.push({x:t.x+n,y:t.y-n},{x:t.x+n,y:t.y+n});break;case"right":o.push({x:t.x-n,y:t.y-n},{x:t.x-n,y:t.y+n});break}return o}function $to(t){const{top:e,right:n,bottom:o,left:r}=t;return[{x:r,y:e},{x:n,y:e},{x:n,y:o},{x:r,y:o}]}function Wto(t,e){const{x:n,y:o}=t;let r=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const a=e[i],c=e[s],l=a.x,u=a.y,_=c.x,d=c.y;u>o!=d>o&&n<(_-l)*(o-u)/(d-u)+l&&(r=!r)}return r}function Uto(t){const e=t.slice();return e.sort((n,o)=>n.x<o.x?-1:n.x>o.x?1:n.y<o.y?-1:n.y>o.y?1:0),Xto(e)}function Xto(t){if(t.length<=1)return t.slice();const e=[];for(let o=0;o<t.length;o++){const r=t[o];for(;e.length>=2;){const i=e[e.length-1],s=e[e.length-2];if((i.x-s.x)*(r.y-s.y)>=(i.y-s.y)*(r.x-s.x))e.pop();else break}e.push(r)}e.pop();const n=[];for(let o=t.length-1;o>=0;o--){const r=t[o];for(;n.length>=2;){const i=n[n.length-1],s=n[n.length-2];if((i.x-s.x)*(r.y-s.y)>=(i.y-s.y)*(r.x-s.x))n.pop();else break}n.push(r)}return n.pop(),e.length===1&&n.length===1&&e[0].x===n[0].x&&e[0].y===n[0].y?e:e.concat(n)}var jto=opt,Gto=rpt,Yto=ipt,lpt=spt;const upt=jto,_pt=Gto,dpt=Yto,H5e=Y.forwardRef(({className:t,sideOffset:e=4,...n},o)=>G.jsx(lpt,{ref:o,sideOffset:e,className:lr("z-50 overflow-hidden rounded-md bg-slate-900 px-3 py-1.5 text-xs text-slate-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-slate-50 dark:text-slate-900",t),...n}));H5e.displayName=lpt.displayName;const qto=26,Ux=Za("run-frame:RunFrame"),Jto=async()=>{try{const t=await fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval");if(t.ok)return(await t.json()).tags?.latest}catch(t){console.error("Failed to fetch latest eval version",t)}},hpt=async(t,e)=>{if(t)return t;if(e||!window.TSCIRCUIT_LATEST_EVAL_VERSION){const n=await Jto();if(n)return window.TSCIRCUIT_LATEST_EVAL_VERSION=n,n}return window.TSCIRCUIT_LATEST_EVAL_VERSION?window.TSCIRCUIT_LATEST_EVAL_VERSION:"latest"},mpt=t=>{xY();const e=eu(pe=>pe.circuitJson),n=eu(pe=>pe.setCircuitJson),[o,r]=Y.useState(null),i=Y.useRef(null),[s,a]=Y.useState(null),[c,l]=Y.useReducer((pe,Me)=>pe+1,0),u=bY(pe=>pe.setLastRunEvalVersion),_=Y.useRef(0),d=gto(),[m,h]=Y.useState(!1),[p,x]=Y.useState(!1),[f,g]=Y.useState({}),[y,b]=Y.useState(""),[v,S]=Y.useState(!1),[M,w]=Y.useState(!1),D=Object.values(f).sort((pe,Me)=>pe.startTime-Me.startTime)[0]?.effectName,A=pe=>{t.onRunCompleted?.(pe)};Y.useEffect(()=>{const pe=Me=>{(Me.ctrlKey||Me.metaKey)&&Me.key==="Enter"&&!m&&l(1)};return window.addEventListener("keydown",pe),()=>window.removeEventListener("keydown",pe)},[m]),Y.useEffect(()=>{let pe=!1;return(async()=>{try{if(!globalThis.runFrameWorker){const xe=await hpt(t.evalVersion,t.forceLatestEvalVersion),We=await Zmt({evalVersion:xe,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${Ax}/files/static`},...t.platformConfig&&{platformConfig:t.platformConfig},verbose:!0,...t.enableFetchProxy&&{enableFetchProxy:t.enableFetchProxy},...window.TSCIRCUIT_USE_RUNFRAME_FOR_CLI&&{disableCdnLoading:!0},...t.tscircuitSessionToken&&{tscircuitSessionToken:t.tscircuitSessionToken}});if(pe)return;globalThis.runFrameWorker=We,u(xe)}pe||x(!0)}catch(xe){console.error("Failed to preload eval worker",xe)}})(),()=>{pe=!0}},[t.evalVersion,t.evalWebWorkerBlobUrl,t.forceLatestEvalVersion,t.tscircuitSessionToken]);const[I,H]=Y.useState(null),[O,z]=Y.useState({}),[V,j]=Y.useState([]),[q,K]=Y.useState(t.defaultActiveTab??t.defaultTab??"pcb");Y.useEffect(()=>{t.debug&&Za.enable("run-frame*")},[t.debug]);const ne=t.fsMap instanceof Map?t.fsMap:Object.entries(t.fsMap??{}).reduce((pe,[Me,xe])=>pe.set(Me,xe),new Map),ce=Y.useRef(null),ee=Y.useRef(null),{isStaticCircuitJson:oe,circuitJson:ie,error:ae}=Pto({mainComponentPath:t.mainComponentPath,fsMap:ne});Y.useEffect(()=>{oe&&(ie?(n(ie),r(null)):ae&&r({error:ae,stack:""}))},[oe,ie,ae]),Y.useEffect(()=>{if(t.isLoadingFiles||oe)return;const pe=ne instanceof Map?Object.fromEntries(ne.entries()):ne;if(!pe||Object.keys(pe).length===0){r({error:"No files provided. Please provide at least one file with code to execute.",stack:""}),h(!1);return}const Me=c!==_.current;if(ce.current&&e){const We=xto(ce.current,ne);if(Object.keys(We).length>0)Ux("code changes detected");else if(ee.current!==t.entrypoint)Ux("render triggered by entrypoint change");else if(!Me){Ux("render triggered without changes to fsMap, skipping");return}}if(t.showRunButton&&c===_.current)return;ce.current=ne,ee.current=t.entrypoint??null,_.current=c,h(!0);const xe=async()=>{Ux("running render worker"),r(null),H(null),g({}),j([]);const We={progress:0,debugOutputs:[]};let Xe=!1;i.current=()=>{Xe=!0};const Je=await hpt(t.evalVersion,!globalThis.runFrameWorker&&t.forceLatestEvalVersion);Ux("resolvedEvalVersion",Je);const fe=globalThis.runFrameWorker??await Zmt({evalVersion:Je,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,verbose:!0,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${Ax}/files/static`},...t.platformConfig&&{platformConfig:t.platformConfig},...t.enableFetchProxy&&{enableFetchProxy:t.enableFetchProxy},...window.TSCIRCUIT_USE_RUNFRAME_FOR_CLI&&{disableCdnLoading:!0},...t.tscircuitSessionToken&&{tscircuitSessionToken:t.tscircuitSessionToken}});globalThis.runFrameWorker=fe,u(Je),y?.trim()&&fe.enableDebug(y.replace("DEBUG=","")),Ux("Starting render..."),t.onRenderStarted?.();const Ye=ne instanceof Map?Object.fromEntries(ne.entries()):ne;let Oe=Date.now();fe.on("asyncEffect:start",Pe=>{const Ee=`${Pe.phase}|${Pe.componentDisplayName??""}|${Pe.effectName}`;g(we=>({...we,[Ee]:{...Pe,startTime:Date.now()}}))}),fe.on("asyncEffect:end",Pe=>{const Ee=`${Pe.phase}|${Pe.componentDisplayName??""}|${Pe.effectName}`;g(we=>{const{[Ee]:ze,...Ue}=we;return Ue})}),fe.on("autorouting:start",Pe=>{z({...O,[Pe.componentDisplayName]:{simpleRouteJson:Pe.simpleRouteJson,createdAt:Date.now()}})}),fe.on("solver:started",Pe=>{Ux("solver:started",Pe),j(Ee=>{const we=`${Pe.componentName}-${Pe.solverName}`;return Ee.some(Ue=>`${Ue.componentName}-${Ue.solverName}`===we)?Ee:[...Ee,Pe]})}),fe.on("board:renderPhaseStarted",Pe=>{We.lastRenderEvent=Pe,We.eventsProcessed=(We.eventsProcessed??0)+1;const Ee=Og.indexOf(Pe.phase)/qto*.75+We.eventsProcessed/1e3*.25,we=1-Math.exp(-Ee*3);We.progress=we,Xe||H({...We})}),q==="render_log"&&fe.on("renderable:renderLifecycle:anyEvent",Pe=>{We.renderEvents=We.renderEvents??[],Pe.createdAt=Date.now(),We.renderEvents.push(Pe),Date.now()-Oe>500&&(We.phaseTimings=ept(We.renderEvents??[]),Oe=Date.now()),Xe||H({...We})}),fe.on("autorouting:progress",Pe=>{a(Pe.debugGraphics)}),fe.on("debug:logOutput",Pe=>{We.debugOutputs=We.debugOutputs??[],We.debugOutputs.push({type:"debug",name:Pe.name,content:Pe.content}),Xe||H({...We})}),Ux("Executing fsMap...");const Ne=await fe.executeWithFsMap({entrypoint:t.entrypoint,fsMap:Ye,...t.mainComponentPath?{mainComponentPath:t.mainComponentPath}:{}}).then(()=>({success:!0})).catch(Pe=>{const Ee=Pe.message.replace("Error: ","");return Ux(`eval error: ${Ee}`),t.onError?.(Pe),A(A5e({executionError:Pe})),r({error:Ee,stack:Pe.stack}),H(null),console.error(Pe),{success:!1}});if(Ux("worker call started"),!Ne.success){h(!1),g({});return}const Ve=fe.renderUntilSettled();Ux("waiting for initial circuit json...");let Re=await fe.getCircuitJson().catch(Pe=>(Ux("error getting initial circuit json",Pe),t.onError?.(Pe),A(A5e({executionError:Pe})),r({error:Pe.message,stack:Pe.stack}),H(null),h(!1),g({}),null));Re&&(Ux("got initial circuit json"),n(Re),t.onCircuitJsonChange?.(Re),t.onInitialRender?.({circuitJson:Re}),await Ve,Ux("getting final circuit json"),Re=await fe.getCircuitJson(),t.onCircuitJsonChange?.(Re),n(Re),A(A5e({circuitJson:Re})),t.onRenderFinished?.({circuitJson:Re}),a({}),q==="render_log"&&(We.phaseTimings=ept(We.renderEvents??[])),We.progress=1,Xe||H({...We}),h(!1),g({}),b(""),i.current=null)};d.runWithMutex(xe)},[t.fsMap,t.entrypoint,c,t.evalVersion,t.mainComponentPath,t.isLoadingFiles,y,oe]);const de=Y.useRef(null),be=Y.useRef(null),Ce=pe=>{if(!pe||pe===null){console.warn("[RunFrame] handleEditEvent received null or undefined event.");return}pe.in_progress?(de.current=pe,be.current&&(clearTimeout(be.current),be.current=null)):(be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{const Me=pe||de.current;t.onEditEvent?.(Me),de.current=null,be.current=null},100))},De=async(pe,Me)=>{let xe="";const We=Array.isArray(e)&&e.find(fe=>fe.type==="software_project_metadata"),Xe=t.projectUrl??We?.project_url;if(Xe)try{xe=new URL(Xe).pathname}catch{xe=Xe}const Je=xe?`${xe} - ${pe}`:pe;await hI.post("autorouting/bug_reports/create",{json:{title:Je,simple_route_json:Me.simpleRouteJson}}).json().then(({autorouting_bug_report:fe})=>{window.open(`https://api.tscircuit.com/autorouting/bug_reports/view?autorouting_bug_report_id=${fe.autorouting_bug_report_id}`,"_blank")}).catch(fe=>{if(console.error("Failed to report autorouting bug",fe),fe instanceof Uv&&fe.response?.status===401){t.onLoginRequired?t.onLoginRequired():alert("You must be logged in to report autorouting bugs");return}const Oe=fe instanceof Error?fe.message:"Failed to report autorouting bug";alert(`Failed to report autorouting bug: ${Oe}`)})};return t.isLoadingFiles?G.jsx(yto,{}):G.jsx(M5,{FallbackComponent:fto,children:G.jsx(Vmt,{code:ne.get(t.entrypoint??t.mainComponentPath),fsMap:ne,defaultActiveTab:t.defaultActiveTab??t.defaultTab,defaultTab:t.defaultTab,availableTabs:t.availableTabs,showToggleFullScreen:t.showToggleFullScreen,autoroutingGraphics:s,autoroutingLog:O,onReportAutoroutingLog:t.onReportAutoroutingLog||De,leftHeaderContent:G.jsxs(G.Fragment,{children:[t.showRunButton&&G.jsx(upt,{children:G.jsxs(_pt,{children:[G.jsx(dpt,{asChild:!0,children:G.jsxs("div",{className:"rf-relative rf-inline-flex",children:[G.jsxs("button",{type:"button",onClick:()=>{l(1)},className:"rf-flex rf-items-center rf-gap-2 rf-px-4 rf-py-2 rf-bg-blue-600 hover:rf-bg-blue-700 rf-text-white rf-rounded-md disabled:rf-opacity-50 transition-colors duration-200",disabled:m||!p,children:["Run"," ",m||!p?G.jsx($9,{className:"rf-w-3 rf-h-3 rf-animate-spin"}):G.jsx(aot,{className:"rf-w-3 rf-h-3"})]}),m&&G.jsx("div",{className:"rf-flex rf-items-center rf-ml-1",children:G.jsx(dc,{onClick:pe=>{pe.stopPropagation(),h(!1),H(null),r(null),i.current&&(i.current(),i.current=null),d.cancel(),g({}),globalThis.runFrameWorker&&(globalThis.runFrameWorker.kill(),globalThis.runFrameWorker=null)},variant:"ghost",size:"icon",className:"rf-text-red-300 hover:rf-text-red-400 hover:!rf-bg-transparent [&>svg]:rf-text-red-300 [&>svg]:hover:rf-text-red-400 rf-flex rf-items-center rf-justify-center",children:G.jsx(YDn,{className:"!rf-h-2.5 !rf-w-2.5",fill:"currentColor",stroke:"currentColor"})})})]})}),G.jsx(H5e,{sideOffset:8,className:"rf-p-0 rf-bg-transparent rf-border-none rf-shadow-none rf-pointer-events-none",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-px-2.5 rf-py-1.5 rf-bg-slate-900 rf-rounded-md rf-shadow-xl rf-border rf-border-slate-800/60",children:[G.jsx("kbd",{className:"rf-bg-slate-800 rf-px-1.5 rf-py-0.5 rf-rounded rf-text-[10px] rf-font-sans rf-font-medium rf-border rf-border-slate-700 rf-text-slate-200 rf-leading-none",children:"Ctrl"}),G.jsx("span",{className:"rf-text-slate-500 rf-text-[11px] rf-font-medium rf-leading-none",children:"+"}),G.jsx("kbd",{className:"rf-bg-slate-800 rf-px-1.5 rf-py-0.5 rf-rounded rf-text-[10px] rf-font-sans rf-font-medium rf-border rf-border-slate-700 rf-text-slate-200 rf-leading-none",children:"Enter"})]})})]})}),t.showFileMenu!==!1&&G.jsx(bI,{isWebEmbedded:t.isWebEmbedded,onLoginRequired:t.onLoginRequired,showSchematicDebugGrid:v,onChangeShowSchematicDebugGrid:S,showSchematicPorts:M,onChangeShowSchematicPorts:w,autoroutingLog:O,onReportAutoroutingLog:t.onReportAutoroutingLog||De}),t.leftHeaderContent]}),onActiveTabChange:K,circuitJson:e,renderLog:I,activeEffectName:D,isRunningCode:m,errorMessage:o?.error,errorStack:o?.stack,onEditEvent:Ce,editEvents:t.editEvents,defaultToFullScreen:t.defaultToFullScreen,onRerunWithDebug:pe=>{b(pe||""),l(1)},solverEvents:V,showSchematicDebugGrid:v,showSchematicPorts:M,onChangeShowSchematicDebugGrid:S,onChangeShowSchematicPorts:w})})},Kto=t=>new Promise(e=>setTimeout(e,t)),Qto=({isOpen:t,onClose:e,onLoginSuccess:n})=>{const[o,r]=Y.useState("idle"),[i,s]=Y.useState(null),[a,c]=Y.useState(null),l=eu(p=>p.pushEvent),u=Y.useRef(null);Y.useEffect(()=>()=>{u.current&&u.current.abort()},[]);const _=Y.useCallback(async()=>{r("creating"),c(null),u.current=new AbortController;try{const p=Xv(),{login_page:x}=await p.post("sessions/login_page/create",{json:{},signal:u.current?.signal}).json();s(x.url),r("waiting");const f=new URL(x.url);for(f.searchParams.set("autoclose","true"),window.open(f.toString(),"_blank");!u.current?.signal.aborted;){const{login_page:y}=await p.post("sessions/login_page/get",{json:{login_page_id:x.login_page_id},headers:{Authorization:`Bearer ${x.login_page_auth_token}`},signal:u.current?.signal}).json();if(y.was_login_successful){r("exchanging");break}if(y.is_expired)throw new Error("Login page expired. Please try again.");await Kto(1e3)}if(u.current?.signal.aborted){r("idle");return}const{session:g}=await p.post("sessions/login_page/exchange_for_cli_session",{json:{login_page_id:x.login_page_id},headers:{Authorization:`Bearer ${x.login_page_auth_token}`},signal:u.current?.signal}).json();typeof window<"u"&&(window.TSCIRCUIT_REGISTRY_TOKEN=g.token),await l({event_type:"TOKEN_UPDATED",registry_token:g.token}),r("success"),ds.success("Successfully logged in!"),n?.(),setTimeout(()=>{e(),r("idle"),s(null)},1e3)}catch(p){if(p instanceof DOMException&&p.name==="AbortError"){r("idle");return}console.error("Login error:",p);const x=p instanceof Error?p.message:"Failed to complete login";c(x),r("error"),ds.error(x)}},[l,n,e]),d=Y.useCallback(()=>{u.current&&u.current.abort(),r("idle"),s(null),c(null),e()},[e]),m=o==="creating"||o==="waiting"||o==="exchanging",h=()=>{switch(o){case"creating":return"Creating login page...";case"waiting":return"Waiting for you to complete login in the browser...";case"exchanging":return"Generating token...";case"success":return"Successfully logged in!";case"error":return a||"An error occurred";default:return null}};return G.jsx(QE,{open:t,onOpenChange:p=>!p&&!m&&d(),children:G.jsxs(eC,{className:"rf-max-w-md",children:[G.jsxs(tC,{children:[G.jsx(nC,{children:"Sign In Required"}),G.jsx(ZE,{children:o==="idle"||o==="error"?"Sign in to continue. A new browser window will open for authentication.":"Complete the login process in the opened browser window."})]}),G.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4 rf-py-4",children:[o==="idle"||o==="error"?G.jsx(dc,{onClick:_,className:"rf-w-full",children:"Sign In"}):G.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-3 rf-w-full",children:[o!=="success"&&G.jsx("div",{className:"rf-animate-spin rf-w-6 rf-h-6 rf-border-2 rf-border-gray-300 rf-border-t-blue-600 rf-rounded-full"}),G.jsx("p",{className:"rf-text-sm rf-text-gray-600 rf-text-center",children:h()}),i&&o==="waiting"&&G.jsx("a",{href:i,target:"_blank",rel:"noreferrer",className:"rf-text-xs rf-text-blue-600 hover:rf-underline",children:"Click here if the window didn't open"})]}),a&&o==="error"&&G.jsx("p",{className:"rf-text-sm rf-text-red-600 rf-text-center",children:a}),m&&G.jsx(dc,{variant:"outline",onClick:d,className:"rf-w-full",children:"Cancel"})]})]})})},Zto=()=>{const[t,e]=Y.useState(!1),n=Y.useCallback(()=>{e(!0)},[]),o=Y.useCallback(()=>{e(!1)},[]),r=Y.useCallback(()=>{e(!1)},[]);return{LoginDialog:G.jsx(Qto,{isOpen:t,onClose:o,onLoginSuccess:r}),openLoginDialog:n}},eno=t=>{const[e,n]=RT("load-latest-eval",!0),[o]=Y.useState(()=>typeof window>"u"?void 0:new URLSearchParams(window.location.hash.slice(1)).get("main_component")??void 0),r=Y.useCallback(a=>{if(typeof window>"u")return;const c=new URLSearchParams(window.location.hash.slice(1));if(c.get("main_component")===a)return;c.set("main_component",a);const l=c.toString(),u=`${window.location.pathname}${window.location.search}`+(l.length>0?`#${l}`:"");window.history.replaceState(null,"",u)},[]),{LoginDialog:i,openLoginDialog:s}=Zto();return G.jsxs(G.Fragment,{children:[i,G.jsx(uft,{debug:t.debug,forceLatestEvalVersion:!t.workerBlobUrl&&e,defaultToFullScreen:!0,showToggleFullScreen:!1,workerBlobUrl:t.workerBlobUrl,showFilesSwitch:!0,showFileMenu:!1,enableFetchProxy:t.enableFetchProxy,initialMainComponentPath:o,onLoginRequired:s,onMainComponentPathChange:r,leftHeaderContent:G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between",children:[G.jsx(bI,{isWebEmbedded:!1,shouldLoadLatestEval:!t.workerBlobUrl&&e,onChangeShouldLoadLatestEval:a=>{n(a),globalThis.runFrameWorker=null},onLoginRequired:s}),t.scenarioSelectorContent]})})]})};Za("run-frame:ImportComponentDialog");var ppt=1,tno=.9,nno=.8,ono=.17,I5e=.1,L5e=.999,rno=.9999,ino=.99,sno=/[\\\/_+.#"@\[\(\{&]/,ano=/[\\\/_+.#"@\[\(\{&]/g,cno=/[\s-]/,fpt=/[\s-]/g;function O5e(t,e,n,o,r,i,s){if(i===e.length)return r===t.length?ppt:ino;var a=`${r},${i}`;if(s[a]!==void 0)return s[a];for(var c=o.charAt(i),l=n.indexOf(c,r),u=0,_,d,m,h;l>=0;)_=O5e(t,e,n,o,l+1,i+1,s),_>u&&(l===r?_*=ppt:sno.test(t.charAt(l-1))?(_*=nno,m=t.slice(r,l-1).match(ano),m&&r>0&&(_*=Math.pow(L5e,m.length))):cno.test(t.charAt(l-1))?(_*=tno,h=t.slice(r,l-1).match(fpt),h&&r>0&&(_*=Math.pow(L5e,h.length))):(_*=ono,r>0&&(_*=Math.pow(L5e,l-r))),t.charAt(l)!==e.charAt(i)&&(_*=rno)),(_<I5e&&n.charAt(l-1)===o.charAt(i+1)||o.charAt(i+1)===o.charAt(i)&&n.charAt(l-1)!==o.charAt(i))&&(d=O5e(t,e,n,o,l+1,i+2,s),d*I5e>_&&(_=d*I5e)),_>u&&(u=_),l=n.indexOf(c,l+1);return s[a]=u,u}function xpt(t){return t.toLowerCase().replace(fpt," ")}function lno(t,e,n){return t=n&&n.length>0?`${t+" "+n.join(" ")}`:t,O5e(t,e,xpt(t),xpt(e),0,0,{})}var uno=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Gv=uno.reduce((t,e)=>{const n=tot(`Primitive.${e}`),o=Y.forwardRef((r,i)=>{const{asChild:s,...a}=r,c=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),G.jsx(c,{...a,ref:i})});return o.displayName=`Primitive.${e}`,{...t,[e]:o}},{}),vI='[cmdk-group=""]',F5e='[cmdk-group-items=""]',_no='[cmdk-group-heading=""]',gpt='[cmdk-item=""]',ypt=`${gpt}:not([aria-disabled="true"])`,B5e="cmdk-item-select",rD="data-value",dno=(t,e,n)=>lno(t,e,n),bpt=Y.createContext(void 0),SI=()=>Y.useContext(bpt),Ppt=Y.createContext(void 0),z5e=()=>Y.useContext(Ppt),vpt=Y.createContext(void 0),Spt=Y.forwardRef((t,e)=>{let n=iD(()=>{var oe,ie;return{search:"",value:(ie=(oe=t.value)!=null?oe:t.defaultValue)!=null?ie:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),o=iD(()=>new Set),r=iD(()=>new Map),i=iD(()=>new Map),s=iD(()=>new Set),a=Cpt(t),{label:c,children:l,value:u,onValueChange:_,filter:d,shouldFilter:m,loop:h,disablePointerSelection:p=!1,vimBindings:x=!0,...f}=t,g=Jp(),y=Jp(),b=Jp(),v=Y.useRef(null),S=Sno();uC(()=>{if(u!==void 0){let oe=u.trim();n.current.value=oe,M.emit()}},[u]),uC(()=>{S(6,O)},[]);let M=Y.useMemo(()=>({subscribe:oe=>(s.current.add(oe),()=>s.current.delete(oe)),snapshot:()=>n.current,setState:(oe,ie,ae)=>{var de,be,Ce,De;if(!Object.is(n.current[oe],ie)){if(n.current[oe]=ie,oe==="search")H(),A(),S(1,I);else if(oe==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let pe=document.getElementById(b);pe?pe.focus():(de=document.getElementById(g))==null||de.focus()}if(S(7,()=>{var pe;n.current.selectedItemId=(pe=z())==null?void 0:pe.id,M.emit()}),ae||S(5,O),((be=a.current)==null?void 0:be.value)!==void 0){let pe=ie??"";(De=(Ce=a.current).onValueChange)==null||De.call(Ce,pe);return}}M.emit()}},emit:()=>{s.current.forEach(oe=>oe())}}),[]),w=Y.useMemo(()=>({value:(oe,ie,ae)=>{var de;ie!==((de=i.current.get(oe))==null?void 0:de.value)&&(i.current.set(oe,{value:ie,keywords:ae}),n.current.filtered.items.set(oe,D(ie,ae)),S(2,()=>{A(),M.emit()}))},item:(oe,ie)=>(o.current.add(oe),ie&&(r.current.has(ie)?r.current.get(ie).add(oe):r.current.set(ie,new Set([oe]))),S(3,()=>{H(),A(),n.current.value||I(),M.emit()}),()=>{i.current.delete(oe),o.current.delete(oe),n.current.filtered.items.delete(oe);let ae=z();S(4,()=>{H(),ae?.getAttribute("id")===oe&&I(),M.emit()})}),group:oe=>(r.current.has(oe)||r.current.set(oe,new Set),()=>{i.current.delete(oe),r.current.delete(oe)}),filter:()=>a.current.shouldFilter,label:c||t["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:g,inputId:b,labelId:y,listInnerRef:v}),[]);function D(oe,ie){var ae,de;let be=(de=(ae=a.current)==null?void 0:ae.filter)!=null?de:dno;return oe?be(oe,n.current.search,ie):0}function A(){if(!n.current.search||a.current.shouldFilter===!1)return;let oe=n.current.filtered.items,ie=[];n.current.filtered.groups.forEach(de=>{let be=r.current.get(de),Ce=0;be.forEach(De=>{let pe=oe.get(De);Ce=Math.max(pe,Ce)}),ie.push([de,Ce])});let ae=v.current;V().sort((de,be)=>{var Ce,De;let pe=de.getAttribute("id"),Me=be.getAttribute("id");return((Ce=oe.get(Me))!=null?Ce:0)-((De=oe.get(pe))!=null?De:0)}).forEach(de=>{let be=de.closest(F5e);be?be.appendChild(de.parentElement===be?de:de.closest(`${F5e} > *`)):ae.appendChild(de.parentElement===ae?de:de.closest(`${F5e} > *`))}),ie.sort((de,be)=>be[1]-de[1]).forEach(de=>{var be;let Ce=(be=v.current)==null?void 0:be.querySelector(`${vI}[${rD}="${encodeURIComponent(de[0])}"]`);Ce?.parentElement.appendChild(Ce)})}function I(){let oe=V().find(ae=>ae.getAttribute("aria-disabled")!=="true"),ie=oe?.getAttribute(rD);M.setState("value",ie||void 0)}function H(){var oe,ie,ae,de;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=o.current.size;return}n.current.filtered.groups=new Set;let be=0;for(let Ce of o.current){let De=(ie=(oe=i.current.get(Ce))==null?void 0:oe.value)!=null?ie:"",pe=(de=(ae=i.current.get(Ce))==null?void 0:ae.keywords)!=null?de:[],Me=D(De,pe);n.current.filtered.items.set(Ce,Me),Me>0&&be++}for(let[Ce,De]of r.current)for(let pe of De)if(n.current.filtered.items.get(pe)>0){n.current.filtered.groups.add(Ce);break}n.current.filtered.count=be}function O(){var oe,ie,ae;let de=z();de&&(((oe=de.parentElement)==null?void 0:oe.firstChild)===de&&((ae=(ie=de.closest(vI))==null?void 0:ie.querySelector(_no))==null||ae.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function z(){var oe;return(oe=v.current)==null?void 0:oe.querySelector(`${gpt}[aria-selected="true"]`)}function V(){var oe;return Array.from(((oe=v.current)==null?void 0:oe.querySelectorAll(ypt))||[])}function j(oe){let ie=V()[oe];ie&&M.setState("value",ie.getAttribute(rD))}function q(oe){var ie;let ae=z(),de=V(),be=de.findIndex(De=>De===ae),Ce=de[be+oe];(ie=a.current)!=null&&ie.loop&&(Ce=be+oe<0?de[de.length-1]:be+oe===de.length?de[0]:de[be+oe]),Ce&&M.setState("value",Ce.getAttribute(rD))}function K(oe){let ie=z(),ae=ie?.closest(vI),de;for(;ae&&!de;)ae=oe>0?Pno(ae,vI):vno(ae,vI),de=ae?.querySelector(ypt);de?M.setState("value",de.getAttribute(rD)):q(oe)}let ne=()=>j(V().length-1),ce=oe=>{oe.preventDefault(),oe.metaKey?ne():oe.altKey?K(1):q(1)},ee=oe=>{oe.preventDefault(),oe.metaKey?j(0):oe.altKey?K(-1):q(-1)};return Y.createElement(Gv.div,{ref:e,tabIndex:-1,...f,"cmdk-root":"",onKeyDown:oe=>{var ie;(ie=f.onKeyDown)==null||ie.call(f,oe);let ae=oe.nativeEvent.isComposing||oe.keyCode===229;if(!(oe.defaultPrevented||ae))switch(oe.key){case"n":case"j":{x&&oe.ctrlKey&&ce(oe);break}case"ArrowDown":{ce(oe);break}case"p":case"k":{x&&oe.ctrlKey&&ee(oe);break}case"ArrowUp":{ee(oe);break}case"Home":{oe.preventDefault(),j(0);break}case"End":{oe.preventDefault(),ne();break}case"Enter":{oe.preventDefault();let de=z();if(de){let be=new Event(B5e);de.dispatchEvent(be)}}}}},Y.createElement("label",{"cmdk-label":"",htmlFor:w.inputId,id:w.labelId,style:Mno},c),iq(t,oe=>Y.createElement(Ppt.Provider,{value:M},Y.createElement(bpt.Provider,{value:w},oe))))}),hno=Y.forwardRef((t,e)=>{var n,o;let r=Jp(),i=Y.useRef(null),s=Y.useContext(vpt),a=SI(),c=Cpt(t),l=(o=(n=c.current)==null?void 0:n.forceMount)!=null?o:s?.forceMount;uC(()=>{if(!l)return a.item(r,s?.id)},[l]);let u=Mpt(r,i,[t.value,t.children,i],t.keywords),_=z5e(),d=Yv(S=>S.value&&S.value===u.current),m=Yv(S=>l||a.filter()===!1?!0:S.search?S.filtered.items.get(r)>0:!0);Y.useEffect(()=>{let S=i.current;if(!(!S||t.disabled))return S.addEventListener(B5e,h),()=>S.removeEventListener(B5e,h)},[m,t.onSelect,t.disabled]);function h(){var S,M;p(),(M=(S=c.current).onSelect)==null||M.call(S,u.current)}function p(){_.setState("value",u.current,!0)}if(!m)return null;let{disabled:x,value:f,onSelect:g,forceMount:y,keywords:b,...v}=t;return Y.createElement(Gv.div,{ref:Rx(i,e),...v,id:r,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!d,"data-disabled":!!x,"data-selected":!!d,onPointerMove:x||a.getDisablePointerSelection()?void 0:p,onClick:x?void 0:h},t.children)}),mno=Y.forwardRef((t,e)=>{let{heading:n,children:o,forceMount:r,...i}=t,s=Jp(),a=Y.useRef(null),c=Y.useRef(null),l=Jp(),u=SI(),_=Yv(m=>r||u.filter()===!1?!0:m.search?m.filtered.groups.has(s):!0);uC(()=>u.group(s),[]),Mpt(s,a,[t.value,t.heading,c]);let d=Y.useMemo(()=>({id:s,forceMount:r}),[r]);return Y.createElement(Gv.div,{ref:Rx(a,e),...i,"cmdk-group":"",role:"presentation",hidden:_?void 0:!0},n&&Y.createElement("div",{ref:c,"cmdk-group-heading":"","aria-hidden":!0,id:l},n),iq(t,m=>Y.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?l:void 0},Y.createElement(vpt.Provider,{value:d},m))))}),pno=Y.forwardRef((t,e)=>{let{alwaysRender:n,...o}=t,r=Y.useRef(null),i=Yv(s=>!s.search);return!n&&!i?null:Y.createElement(Gv.div,{ref:Rx(r,e),...o,"cmdk-separator":"",role:"separator"})}),fno=Y.forwardRef((t,e)=>{let{onValueChange:n,...o}=t,r=t.value!=null,i=z5e(),s=Yv(l=>l.search),a=Yv(l=>l.selectedItemId),c=SI();return Y.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),Y.createElement(Gv.input,{ref:e,...o,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":a,id:c.inputId,type:"text",value:r?t.value:s,onChange:l=>{r||i.setState("search",l.target.value),n?.(l.target.value)}})}),xno=Y.forwardRef((t,e)=>{let{children:n,label:o="Suggestions",...r}=t,i=Y.useRef(null),s=Y.useRef(null),a=Yv(l=>l.selectedItemId),c=SI();return Y.useEffect(()=>{if(s.current&&i.current){let l=s.current,u=i.current,_,d=new ResizeObserver(()=>{_=requestAnimationFrame(()=>{let m=l.offsetHeight;u.style.setProperty("--cmdk-list-height",m.toFixed(1)+"px")})});return d.observe(l),()=>{cancelAnimationFrame(_),d.unobserve(l)}}},[]),Y.createElement(Gv.div,{ref:Rx(i,e),...r,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":o,id:c.listId},iq(t,l=>Y.createElement("div",{ref:Rx(s,c.listInnerRef),"cmdk-list-sizer":""},l)))}),gno=Y.forwardRef((t,e)=>{let{open:n,onOpenChange:o,overlayClassName:r,contentClassName:i,container:s,...a}=t;return Y.createElement(Hye,{open:n,onOpenChange:o},Y.createElement(Iye,{container:s},Y.createElement(SY,{"cmdk-overlay":"",className:r}),Y.createElement(CY,{"aria-label":t.label,"cmdk-dialog":"",className:i},Y.createElement(Spt,{ref:e,...a}))))}),yno=Y.forwardRef((t,e)=>Yv(n=>n.filtered.count===0)?Y.createElement(Gv.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),bno=Y.forwardRef((t,e)=>{let{progress:n,children:o,label:r="Loading...",...i}=t;return Y.createElement(Gv.div,{ref:e,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r},iq(t,s=>Y.createElement("div",{"aria-hidden":!0},s)))}),Xx=Object.assign(Spt,{List:xno,Item:hno,Input:fno,Group:mno,Separator:pno,Dialog:gno,Empty:yno,Loading:bno});function Pno(t,e){let n=t.nextElementSibling;for(;n;){if(n.matches(e))return n;n=n.nextElementSibling}}function vno(t,e){let n=t.previousElementSibling;for(;n;){if(n.matches(e))return n;n=n.previousElementSibling}}function Cpt(t){let e=Y.useRef(t);return uC(()=>{e.current=t}),e}var uC=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;function iD(t){let e=Y.useRef();return e.current===void 0&&(e.current=t()),e}function Yv(t){let e=z5e(),n=()=>t(e.snapshot());return Y.useSyncExternalStore(e.subscribe,n,n)}function Mpt(t,e,n,o=[]){let r=Y.useRef(),i=SI();return uC(()=>{var s;let a=(()=>{var l;for(let u of n){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(l=u.current.textContent)==null?void 0:l.trim():r.current}})(),c=o.map(l=>l.trim());i.value(t,a,c),(s=e.current)==null||s.setAttribute(rD,a),r.current=a}),r}var Sno=()=>{let[t,e]=Y.useState(),n=iD(()=>new Map);return uC(()=>{n.current.forEach(o=>o()),n.current=new Map},[t]),(o,r)=>{n.current.set(o,r),e({})}};function Cno(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function iq({asChild:t,children:e},n){return t&&Y.isValidElement(e)?Y.cloneElement(Cno(e),{ref:e.ref},n(e.props.children)):n(e)}var Mno={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Tpt=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx,{ref:n,className:lr("rf-flex rf-h-full rf-w-full rf-flex-col rf-overflow-hidden rf-rounded-md rf-bg-white rf-text-zinc-950 dark:rf-bg-zinc-950 dark:rf-text-zinc-50",t),...e}));Tpt.displayName=Xx.displayName;const wpt=Y.forwardRef(({className:t,...e},n)=>G.jsxs("div",{className:"rf-flex rf-items-center rf-border-b rf-px-3","cmdk-input-wrapper":"",children:[G.jsx(T2e,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-shrink-0 rf-opacity-50"}),G.jsx(Xx.Input,{ref:n,className:lr("rf-flex rf-h-10 rf-w-full rf-rounded-md rf-bg-transparent rf-py-3 rf-text-sm rf-outline-none placeholder:rf-text-zinc-500 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 dark:placeholder:rf-text-zinc-400",t),...e})]}));wpt.displayName=Xx.Input.displayName;const Ept=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.List,{ref:n,className:lr("rf-max-h-[300px] rf-overflow-y-auto rf-overflow-x-hidden rf-py-1",t),...e}));Ept.displayName=Xx.List.displayName;const V5e=Y.forwardRef((t,e)=>G.jsx(Xx.Empty,{ref:e,className:"rf-py-6 rf-text-center rf-text-sm",...t}));V5e.displayName=Xx.Empty.displayName;const CI=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.Group,{ref:n,className:lr("rf-overflow-hidden rf-px-1 rf-py-0 rf-text-zinc-950 [&_[cmdk-group-heading]]:rf-px-2 [&_[cmdk-group-heading]]:rf-py-1.5 [&_[cmdk-group-heading]]:rf-text-xs [&_[cmdk-group-heading]]:rf-font-medium [&_[cmdk-group-heading]]:rf-text-zinc-500 dark:rf-text-zinc-50 dark:[&_[cmdk-group-heading]]:rf-text-zinc-400",t),...e}));CI.displayName=Xx.Group.displayName;const Tno=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.Separator,{ref:n,className:lr("rf--mx-1 rf-h-px rf-bg-zinc-200 dark:rf-bg-zinc-800",t),...e}));Tno.displayName=Xx.Separator.displayName;const MI=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.Item,{ref:n,className:lr("rf-relative rf-flex rf-cursor-default rf-gap-2 rf-select-none rf-items-center rf-rounded-sm rf-px-2 rf-py-1.5 rf-text-sm rf-outline-none data-[disabled=true]:rf-pointer-events-none data-[selected=true]:rf-bg-zinc-100 data-[selected=true]:rf-text-zinc-900 data-[disabled=true]:rf-opacity-50 [&_svg]:rf-pointer-events-none [&_svg]:rf-size-4 [&_svg]:rf-shrink-0 dark:data-[selected=true]:rf-bg-zinc-800 dark:data-[selected=true]:rf-text-zinc-50",t),...e}));MI.displayName=Xx.Item.displayName;function wno(t){const e=Eno(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(Ano);if(c){const l=c.props.children,u=a.map(_=>_===c?Y.Children.count(l)>1?Y.Children.only(null):Y.isValidElement(l)?l.props.children:null:_);return G.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return G.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function Eno(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=kno(r),a=Rno(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?Rx(o,s):s),Y.cloneElement(r,a)}return Y.Children.count(r)>1?Y.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var Dno=Symbol("radix.slottable");function Ano(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Dno}function Rno(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 kno(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 sq="Popover",[Dpt]=d4(sq,[vE]),TI=vE(),[Nno,qv]=Dpt(sq),Apt=t=>{const{__scopePopover:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!1}=t,a=TI(e),c=Y.useRef(null),[l,u]=Y.useState(!1),[_,d]=DP({prop:o,defaultProp:r??!1,onChange:i,caller:sq});return G.jsx(Hj,{...a,children:G.jsx(Nno,{scope:e,contentId:Jp(),triggerRef:c,open:_,onOpenChange:d,onOpenToggle:Y.useCallback(()=>d(m=>!m),[d]),hasCustomAnchor:l,onCustomAnchorAdd:Y.useCallback(()=>u(!0),[]),onCustomAnchorRemove:Y.useCallback(()=>u(!1),[]),modal:s,children:n})})};Apt.displayName=sq;var Rpt="PopoverAnchor",Hno=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=qv(Rpt,n),i=TI(n),{onCustomAnchorAdd:s,onCustomAnchorRemove:a}=r;return Y.useEffect(()=>(s(),()=>a()),[s,a]),G.jsx(Ij,{...i,...o,ref:e})});Hno.displayName=Rpt;var kpt="PopoverTrigger",Npt=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=qv(kpt,n),i=TI(n),s=tu(e,r.triggerRef),a=G.jsx(Cc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Fpt(r.open),...o,ref:s,onClick:Vr(t.onClick,r.onOpenToggle)});return r.hasCustomAnchor?a:G.jsx(Ij,{asChild:!0,...i,children:a})});Npt.displayName=kpt;var $5e="PopoverPortal",[Ino,Lno]=Dpt($5e,{forceMount:void 0}),Hpt=t=>{const{__scopePopover:e,forceMount:n,children:o,container:r}=t,i=qv($5e,e);return G.jsx(Ino,{scope:e,forceMount:n,children:G.jsx(Fg,{present:n||i.open,children:G.jsx(Lj,{asChild:!0,container:r,children:o})})})};Hpt.displayName=$5e;var sD="PopoverContent",Ipt=Y.forwardRef((t,e)=>{const n=Lno(sD,t.__scopePopover),{forceMount:o=n.forceMount,...r}=t,i=qv(sD,t.__scopePopover);return G.jsx(Fg,{present:o||i.open,children:i.modal?G.jsx(Fno,{...r,ref:e}):G.jsx(Bno,{...r,ref:e})})});Ipt.displayName=sD;var Ono=wno("PopoverContent.RemoveScroll"),Fno=Y.forwardRef((t,e)=>{const n=qv(sD,t.__scopePopover),o=Y.useRef(null),r=tu(e,o),i=Y.useRef(!1);return Y.useEffect(()=>{const s=o.current;if(s)return Y2e(s)},[]),G.jsx(Uj,{as:Ono,allowPinchZoom:!0,children:G.jsx(Lpt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vr(t.onCloseAutoFocus,s=>{s.preventDefault(),i.current||n.triggerRef.current?.focus()}),onPointerDownOutside:Vr(t.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,l=a.button===2||c;i.current=l},{checkForDefaultPrevented:!1}),onFocusOutside:Vr(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1})})})}),Bno=Y.forwardRef((t,e)=>{const n=qv(sD,t.__scopePopover),o=Y.useRef(!1),r=Y.useRef(!1);return G.jsx(Lpt,{...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()}})}),Lpt=Y.forwardRef((t,e)=>{const{__scopePopover:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,disableOutsidePointerEvents:s,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,..._}=t,d=qv(sD,n),m=TI(n);return D2e(),G.jsx(Sj,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:G.jsx(ZN,{asChild:!0,disableOutsidePointerEvents:s,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>d.onOpenChange(!1),children:G.jsx(X2e,{"data-state":Fpt(d.open),role:"dialog",id:d.contentId,...m,..._,ref:e,style:{..._.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Opt="PopoverClose",zno=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=qv(Opt,n);return G.jsx(Cc.button,{type:"button",...o,ref:e,onClick:Vr(t.onClick,()=>r.onOpenChange(!1))})});zno.displayName=Opt;var Vno="PopoverArrow",$no=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=TI(n);return G.jsx(j2e,{...r,...o,ref:e})});$no.displayName=Vno;function Fpt(t){return t?"open":"closed"}var Wno=Apt,Uno=Npt,Xno=Hpt,Bpt=Ipt;const jno=Wno,Gno=Uno,zpt=Y.forwardRef(({className:t,align:e="center",sideOffset:n=4,...o},r)=>G.jsx(Xno,{children:G.jsx(Bpt,{ref:r,align:e,sideOffset:n,className:lr("rf-z-50 rf-w-72 rf-rounded-md rf-border rf-border-zinc-200 rf-bg-white rf-p-4 rf-text-zinc-950 rf-shadow-md rf-outline-none data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[side=bottom]:rf-slide-in-from-top-2 data-[side=left]:rf-slide-in-from-right-2 data-[side=right]:rf-slide-in-from-left-2 data-[side=top]:rf-slide-in-from-bottom-2 rf-origin-[--radix-popover-content-transform-origin] dark:rf-border-zinc-800 dark:rf-bg-zinc-950 dark:rf-text-zinc-50",t),...o})}));zpt.displayName=Bpt.displayName;function Vpt(t,e){const n=t.lastIndexOf("."),o=e.lastIndexOf("."),r=n>0?t.substring(0,n):t,i=o>0?e.substring(0,o):e;if(r!==i&&t.substring(n)===e.substring(o)){if(r.startsWith(i))return 1;if(i.startsWith(r))return-1}return t.localeCompare(e,void 0,{numeric:!0,sensitivity:"base"})}function Yno(t){const e=[],n=new Map;n.set("",{name:"",path:"",type:"folder",children:e});for(const o of t){const r=o.split("/");let i="";for(let s=0;s<r.length;s++){const a=r[s],c=i;if(i=i?`${i}/${a}`:a,!n.has(i)){const l=s===r.length-1,u={name:a,path:i,type:l?"file":"folder",children:l?void 0:[]};n.set(i,u);const _=n.get(c);_&&_.children&&_.children.push(u)}}}return e}function $pt(t,e){for(const n of t){if(n.path===e)return n;if(n.children){const o=$pt(n.children,e);if(o)return o}}return null}function qno(t,e){let n;if(e?n=$pt(t,e):n={name:"",path:"",type:"folder",children:t},!n||!n.children)return{files:[],folders:[]};const o=n.children.filter(i=>i.type==="file"),r=n.children.filter(i=>i.type==="folder");return o.sort((i,s)=>Vpt(i.name,s.name)),r.sort((i,s)=>Vpt(i.name,s.name)),{files:o,folders:r}}const Jno=t=>{const e=t.split("/").pop()||"";return e.endsWith(".py.tsx")?e.slice(0,-4):e};function W5e(t){const e=t.lastIndexOf("/");return e===-1?"/":t.substring(0,e)}function Kno({currentFile:t,files:e}){const[n,o]=Y.useState(!1),[r,i]=Y.useState(()=>{if(typeof window<"u"){const c=new URLSearchParams(window.location.search),l=new URLSearchParams(window.location.hash.slice(1)),u=c.get("file")??l.get("file");if(u&&e.includes(u)){const _=W5e(u);return _==="/"?null:_}}if(t&&e.includes(t)){const c=W5e(t);return c==="/"?null:c}return null});return Y.useEffect(()=>{if(t&&!n&&e.includes(t)){const c=W5e(t);i(c==="/"?null:c)}},[t,n,e]),{currentFolder:r,navigateToFolder:c=>{i(c),o(!0)},resetManualNavigation:()=>{o(!1)}}}const U5e=t=>t.endsWith(".tsx")||t.endsWith(".jsx")?G.jsx(NDn,{className:"rf-h-4 rf-w-4 rf-text-blue-500"}):t.endsWith(".md")||t.endsWith(".txt")?G.jsx(ODn,{className:"rf-h-4 rf-w-4 rf-text-gray-600"}):G.jsx(FDn,{className:"rf-h-4 rf-w-4 rf-text-gray-500"}),Qno=t=>t.endsWith(".tsx")||tq(t)||t.endsWith(".jsx"),Zno=t=>Jno(t),Wpt=t=>t.substring(0,t.lastIndexOf("/"))||"/",Upt=({files:t,onFileChange:e,currentFile:n,fileFilter:o=Qno,getDisplayName:r=Zno,placeholder:i="Select file",searchPlaceholder:s="Search for file",emptyMessage:a="No files found in this directory.",pinnedFiles:c=[],onToggleFavorite:l,recentlySavedFiles:u=[]})=>{const[_,d]=Y.useState(!1),[m,h]=Y.useState(n),{currentFolder:p,navigateToFolder:x,resetManualNavigation:f}=Kno({currentFile:m,files:t}),[g,y]=Y.useState(0),[b,v]=Y.useState(""),[S,M]=RT("runframe:recentlyViewed",[]),[w,D]=RT("runframe:showRecents",!1);Y.useEffect(()=>{const ae=de=>{(de.metaKey||de.ctrlKey)&&de.key==="k"&&(de.preventDefault(),d(be=>!be))};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[]);const A=t.filter(o),I=Y.useRef(null);Y.useEffect(()=>{const ae=()=>{I.current&&(clearTimeout(I.current),I.current=null)};return h(n),n&&A.includes(n)&&(ae(),I.current=setTimeout(()=>{M(de=>{if(de[0]===n)return de;const be=de.filter(Ce=>Ce!==n);return[n,...be].slice(0,10)})},500)),ae},[n,A,M]);const H=Yno(A),{files:O,folders:z}=qno(H,p||""),j=(()=>{if(!b.trim())return{currentDirResults:[],globalResults:[]};const ae=b.toLowerCase(),be=A.map(pe=>{const Me=pe.split("/").pop()||"";return{path:pe,fileName:Me}}).filter(pe=>pe.fileName.toLowerCase().includes(ae)||pe.path.toLowerCase().includes(ae)),Ce=be.filter(pe=>p?pe.path.substring(0,pe.path.lastIndexOf("/"))===p:!pe.path.includes("/")),De=be.filter(pe=>p?pe.path.substring(0,pe.path.lastIndexOf("/"))!==p:pe.path.includes("/"));return{currentDirResults:Ce,globalResults:De}})(),q=b.trim().length>0,K=ae=>{x(ae),y(0)},ne=Y.useCallback(()=>{if(!p)return;const ae=p.lastIndexOf("/"),de=ae===-1?null:p.substring(0,ae);K(de)},[p,K]);Y.useEffect(()=>{if(!_)return;const ae=de=>{(de.metaKey||de.ctrlKey)&&de.key==="ArrowUp"&&(de.preventDefault(),ne())};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[_,ne]);const ce=Y.useCallback((ae,de,be=!1)=>{if(h(ae),y(de),d(!1),e(ae),be){const Ce=ae.lastIndexOf("/"),De=Ce===-1?null:ae.substring(0,Ce);K(De)}},[e,K]);Y.useEffect(()=>{const ae=de=>{if((de.metaKey||de.ctrlKey)&&(de.key==="ArrowLeft"||de.key==="ArrowRight")){if(de.preventDefault(),!n||O.length===0)return;const be=O.findIndex(pe=>pe.path===n);if(be===-1)return;let Ce;de.key==="ArrowLeft"?Ce=be===0?O.length-1:be-1:Ce=be===O.length-1?0:be+1;const De=O[Ce];De&&ce(De.path,Ce)}};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[n,O,ce]),Y.useEffect(()=>{if(O.length>0){const ae=O.findIndex(de=>de.path===n);ae>=0&&y(ae)}},[O,n]);const ee=Y.useMemo(()=>{const ae=u.filter(Ce=>A.includes(Ce)),de=S.filter(Ce=>A.includes(Ce)),be=[];ae.length>0&&be.push({path:ae[0],type:"saved"});for(const Ce of de){if(be.length>=3)break;be.some(De=>De.path===Ce)||be.push({path:Ce,type:"viewed"})}return be},[u,S,A]),oe=p??"/";oe.length>25&&""+oe.slice(-22);const ie=()=>`rf-w-full rf-min-w-[600px] ${q?"rf-max-w-[600px]":"rf-max-w-[1000px]"}`;return G.jsx("div",{className:"rf-flex rf-items-center rf-gap-1",children:G.jsxs(jno,{open:_,onOpenChange:ae=>{d(ae),ae||(v(""),f())},children:[G.jsx(Gno,{asChild:!0,children:G.jsxs(dc,{variant:"outline",role:"combobox","aria-expanded":_,className:"rf-w-fit rf-min-w-32 rf-max-w-100 rf-justify-center rf-items-center rf-gap-1 !rf-font-normal",children:[G.jsx("span",{className:"rf-truncate rf-text-left",children:m?r(m):i}),G.jsx(wDn,{className:"rf-opacity-50 rf-flex-shrink-0"})]})}),G.jsx(zpt,{className:lr("!rf-p-0 !rf-overflow-y-auto !rf-max-h-[80vh] !rf-z-[200]",ie()),children:G.jsxs(Tpt,{shouldFilter:!1,children:[G.jsx(wpt,{placeholder:s,className:"rf-h-9 rf-w-full",value:b,onValueChange:v}),ee.length>0&&G.jsxs("div",{className:"rf-border-b rf-border-gray-200",children:[G.jsxs("button",{onClick:()=>D(!w),className:"rf-w-full rf-px-3 rf-py-2 rf-flex rf-items-center rf-justify-between rf-text-xs rf-text-slate-600 hover:rf-bg-slate-50 rf-bg-transparent rf-border-none rf-cursor-pointer",children:[G.jsx("span",{className:"rf-font-medium",children:"Recent Files"}),G.jsx(M2e,{className:lr("rf-h-4 rf-w-4 rf-transition-transform",!w&&"-rf-rotate-90")})]}),w&&G.jsx("div",{className:"rf-pb-1",children:ee.map((ae,de)=>G.jsxs("div",{onClick:()=>ce(ae.path,de,!0),className:lr("rf-flex rf-items-center rf-px-3 rf-py-1.5 rf-cursor-pointer hover:rf-bg-slate-100",ae.path===n&&"rf-font-medium"),children:[ae.type==="saved"?G.jsx("span",{title:"Recently saved",children:G.jsx(GDn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-green-500"})}):G.jsx("span",{title:"Recently viewed",children:G.jsx(kDn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-500"})}),G.jsx("span",{className:"rf-text-sm",children:r(ae.path.split("/").pop()||"")}),G.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Wpt(ae.path)}),G.jsx(T8,{className:lr("rf-ml-auto rf-h-4 rf-w-4",ae.path===n?"rf-opacity-100":"rf-opacity-0")})]},ae.path))})]}),G.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-slate-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[G.jsx("div",{className:"rf-flex rf-items-center rf-text-xs rf-text-slate-600 rf-min-w-0 rf-flex-1",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-min-w-0",children:[G.jsx("button",{onClick:()=>K(null),className:"rf-text-blue-600 hover:rf-text-blue-800 rf-underline rf-cursor-pointer rf-bg-transparent rf-border-none rf-p-0 rf-flex-shrink-0",children:"root"}),p?.split("/").filter(Boolean).map((ae,de,be)=>{const Ce=be.slice(0,de+1).join("/");return G.jsxs("span",{className:"rf-flex rf-items-center rf-min-w-0",children:[G.jsx("span",{className:"rf-mx-1 rf-flex-shrink-0",children:"/"}),de===be.length-1?G.jsx("span",{className:"rf-text-slate-800 rf-truncate rf-max-w-[200px]",title:ae,children:ae}):G.jsx("button",{onClick:()=>K(Ce),className:"rf-text-blue-600 hover:rf-text-blue-800 rf-underline rf-cursor-pointer rf-bg-transparent rf-border-none rf-p-0 rf-truncate rf-max-w-[150px]",title:ae,children:ae})]},Ce)})]})}),G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2 rf-flex-shrink-0",children:p&&G.jsxs("button",{onClick:ne,className:"rf-flex rf-items-center rf-gap-1 rf-text-slate-600 hover:rf-text-slate-800 rf-bg-transparent rf-border-none rf-p-1 rf-rounded hover:rf-bg-slate-200 rf-transition-colors",title:"Go up one level",children:[G.jsx(MDn,{className:"rf-h-3 rf-w-3"}),G.jsx("span",{className:"rf-text-xs rf-font-medium",children:"Up"})]})})]}),G.jsx(Ept,{className:"rf-overflow-visible rf-max-h-none",children:q?G.jsx(G.Fragment,{children:j.currentDirResults.length===0&&j.globalResults.length===0?G.jsxs(V5e,{children:['No files found matching "',b,'".']}):G.jsxs(G.Fragment,{children:[j.currentDirResults.length>0&&G.jsx(CI,{children:j.currentDirResults.map((ae,de)=>G.jsxs(MI,{value:`search-current:${ae.path}`,onSelect:()=>{h(ae.path),d(!1),e(ae.path)},className:lr(ae.path===n&&"rf-font-medium","rf-group"),children:[G.jsx("span",{className:"rf-mr-2",children:U5e(ae.fileName)}),G.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[G.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ae.fileName)}),G.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:p||"/"}),ae.path===n&&G.jsx(T8,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ae.path))}),j.globalResults.length>0&&G.jsx(CI,{children:j.globalResults.map(ae=>G.jsxs(MI,{value:`search-global:${ae.path}`,onSelect:()=>{h(ae.path),d(!1),e(ae.path)},className:lr(ae.path===n&&"rf-font-medium","rf-group"),children:[G.jsx("span",{className:"rf-mr-2",children:U5e(ae.fileName)}),G.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[G.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ae.fileName)}),G.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Wpt(ae.path)}),ae.path===n&&G.jsx(T8,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ae.path))})]})}):G.jsxs(G.Fragment,{children:[G.jsx(V5e,{children:a}),O.length>0&&G.jsx(CI,{children:O.map((ae,de)=>G.jsxs(MI,{value:`current:${ae.path}`,onSelect:()=>ce(ae.path,de),className:lr(ae.path===n&&"rf-font-medium","rf-group"),children:[G.jsx("span",{className:"rf-mr-2",children:U5e(ae.name)}),r(ae.name),G.jsx("div",{className:"rf-ml-auto rf-flex rf-items-center rf-gap-1",children:G.jsx(T8,{className:lr("rf-h-4 rf-w-4",ae.path===n?"rf-opacity-100":"rf-opacity-0")})})]},ae.path))}),z.length>0&&G.jsx(CI,{children:z.map(ae=>G.jsxs(MI,{value:`folder-${ae.path}`,onSelect:()=>K(ae.path),className:"rf-text-slate-600 hover:rf-text-slate-900",children:[G.jsx(BDn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-600"}),ae.name,G.jsx(xE,{className:"rf-ml-auto rf-h-4 rf-w-4"})]},ae.path))}),O.length===0&&z.length===0&&G.jsx("div",{className:"rf-p-4 rf-text-center rf-text-slate-500 rf-text-sm",children:"No files or folders in this directory"})]})})]})})]})})},Xpt=({files:t,onFileChange:e,currentFile:n})=>G.jsx(Upt,{files:t,onFileChange:e,currentFile:n,fileFilter:()=>!0,placeholder:"Select circuit",searchPlaceholder:"Search for circuit file",emptyMessage:"No circuit files found in this directory."}),eoo=t=>{xY();const[e,n]=Y.useState(()=>t.initialCircuitPath??""),[o,r]=Y.useState(null),[i,s]=Y.useState(!1),[a,c]=Y.useState({}),[l,u]=Y.useState(new Set),[_,d]=Y.useState(new Set),m=t.files,h=m.map(b=>b.filePath),p=Y.useCallback(async b=>{if(!b.fileStaticAssetUrl)throw new Error(`No fileStaticAssetUrl provided for ${b.filePath}`);const v=await fetch(b.fileStaticAssetUrl);if(!v.ok)throw new Error(`Failed to fetch ${b.filePath}: ${v.statusText}`);return await v.json()},[]),x=Y.useCallback(async b=>{if(a[b]){r(a[b]),t.onCircuitJsonPathChange?.(b);return}if(_.has(b)){console.warn(`Skipping failed file: ${b}`),r(null);return}if(!l.has(b)){u(v=>new Set(v).add(b)),s(!0),r(null);try{const v=m.find(w=>w.filePath===b);if(!v)throw new Error(`File reference not found for ${b}`);const M=await(t.onFetchFile||p)(v);c(w=>({...w,[b]:M})),r(M),t.onCircuitJsonPathChange?.(b),d(w=>{const D=new Set(w);return D.delete(b),D})}catch(v){console.error(`Failed to load circuit JSON file ${b}:`,v),d(S=>new Set(S).add(b)),r(null)}finally{u(v=>{const S=new Set(v);return S.delete(b),S}),s(!1)}}},[m,a,l,_,t.onFetchFile,t.onCircuitJsonPathChange,p]);Y.useEffect(()=>{if(h.length===0)return;let b=e;(!b||!h.includes(b))&&(b=lft(h)??h[0],n(b)),b&&h.includes(b)&&x(b)},[e]);const f=Y.useCallback(b=>{n(b)},[]),g=Y.useCallback(b=>{d(v=>{const S=new Set(v);return S.delete(b),S}),x(b)},[x]);if(h.length===0)return G.jsx("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full rf-items-center rf-justify-center",children:G.jsxs("div",{className:"rf-text-center rf-p-8",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-2",children:"No Circuit JSON Files Found"}),G.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Please provide circuit JSON files to view."})]})});const y=_.has(e);return G.jsx(M5,{fallbackRender:({error:b})=>G.jsx("div",{className:"rf-mt-4 rf-mx-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Circuit JSON Preview"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:b.message})]})}),children:y?G.jsxs("div",{className:"rf-w-full rf-h-full rf-flex rf-flex-col",children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full rf-p-4 rf-border-b rf-border-gray-200",children:[(t.showFileMenu??!0)&&G.jsx(bI,{isWebEmbedded:!0,circuitJson:null,projectName:t.projectName}),h.length>1&&G.jsx("div",{className:"rf-absolute rf-left-1/2 rf-transform rf--translate-x-1/2 rf-flex rf-items-center rf-gap-2",children:G.jsx(Xpt,{currentFile:e,files:h,onFileChange:f})})]}),G.jsx("div",{className:"rf-flex-1 rf-flex rf-items-center rf-justify-center",children:G.jsxs("div",{className:"rf-text-center rf-p-8",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-600 rf-mb-2",children:"Failed to Load Circuit File"}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-600 rf-mb-4",children:["Could not load: ",e]}),G.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-2",children:[G.jsx("button",{onClick:()=>g(e),className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600",children:"Retry"}),h.length>1&&G.jsx("p",{className:"rf-text-xs rf-text-gray-500",children:"Or select a different file from the dropdown above"})]})]})})]}):G.jsx(Vmt,{circuitJson:o,defaultToFullScreen:t.defaultToFullScreen,showToggleFullScreen:t.showToggleFullScreen,showFileMenu:!1,isWebEmbedded:!1,projectName:t.projectName,defaultActiveTab:t.tabSelected,leftHeaderContent:G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full",children:[(t.showFileMenu??!0)&&G.jsx(bI,{isWebEmbedded:!0,circuitJson:o,projectName:t.projectName}),h.length>1&&G.jsx("div",{className:`rf-absolute rf-left-1/2 rf-transform rf--translate-x-1/2 rf-flex rf-items-center rf-gap-2 ${i?"rf-opacity-50":""}`,children:G.jsx(Xpt,{currentFile:e,files:h,onFileChange:f})})]})})})},too=()=>{const t=eu(e=>e.fsMap);Y.useEffect(()=>{if(!document||!t)return;const e=Array.from(t.keys()),n=lft(e),o=t.get("package.json");try{if(o){const r=JSON.parse(o);if(r?.name){document.title=r.name;return}}}catch{}n&&(document.title=n)},[t])},jpt=(t,e,n)=>{const o=t instanceof RegExp?Gpt(t,n):t,r=e instanceof RegExp?Gpt(e,n):e,i=o!==null&&r!=null&&noo(o,r,n);return i&&{start:i[0],end:i[1],pre:n.slice(0,i[0]),body:n.slice(i[0]+o.length,i[1]),post:n.slice(i[1]+r.length)}},Gpt=(t,e)=>{const n=e.match(t);return n?n[0]:null},noo=(t,e,n)=>{let o,r,i,s,a,c=n.indexOf(t),l=n.indexOf(e,c+1),u=c;if(c>=0&&l>0){if(t===e)return[c,l];for(o=[],i=n.length;u>=0&&!a;){if(u===c)o.push(u),c=n.indexOf(t,u+1);else if(o.length===1){const _=o.pop();_!==void 0&&(a=[_,l])}else r=o.pop(),r!==void 0&&r<i&&(i=r,s=l),l=n.indexOf(e,u+1);u=c<l&&c>=0?c:l}o.length&&s!==void 0&&(a=[i,s])}return a},Ypt="\0SLASH"+Math.random()+"\0",qpt="\0OPEN"+Math.random()+"\0",X5e="\0CLOSE"+Math.random()+"\0",Jpt="\0COMMA"+Math.random()+"\0",Kpt="\0PERIOD"+Math.random()+"\0",ooo=new RegExp(Ypt,"g"),roo=new RegExp(qpt,"g"),ioo=new RegExp(X5e,"g"),soo=new RegExp(Jpt,"g"),aoo=new RegExp(Kpt,"g"),coo=/\\\\/g,loo=/\\{/g,uoo=/\\}/g,_oo=/\\,/g,doo=/\\./g;function j5e(t){return isNaN(t)?t.charCodeAt(0):parseInt(t,10)}function hoo(t){return t.replace(coo,Ypt).replace(loo,qpt).replace(uoo,X5e).replace(_oo,Jpt).replace(doo,Kpt)}function moo(t){return t.replace(ooo,"\\").replace(roo,"{").replace(ioo,"}").replace(soo,",").replace(aoo,".")}function Qpt(t){if(!t)return[""];const e=[],n=jpt("{","}",t);if(!n)return t.split(",");const{pre:o,body:r,post:i}=n,s=o.split(",");s[s.length-1]+="{"+r+"}";const a=Qpt(i);return i.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),e.push.apply(e,s),e}function poo(t){return t?(t.slice(0,2)==="{}"&&(t="\\{\\}"+t.slice(2)),wI(hoo(t),!0).map(moo)):[]}function foo(t){return"{"+t+"}"}function xoo(t){return/^-?0\d/.test(t)}function goo(t,e){return t<=e}function yoo(t,e){return t>=e}function wI(t,e){const n=[],o=jpt("{","}",t);if(!o)return[t];const r=o.pre,i=o.post.length?wI(o.post,!1):[""];if(/\$$/.test(o.pre))for(let s=0;s<i.length;s++){const a=r+"{"+o.body+"}"+i[s];n.push(a)}else{const s=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(o.body),a=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(o.body),c=s||a,l=o.body.indexOf(",")>=0;if(!c&&!l)return o.post.match(/,(?!,).*\}/)?(t=o.pre+"{"+o.body+X5e+o.post,wI(t)):[t];let u;if(c)u=o.body.split(/\.\./);else if(u=Qpt(o.body),u.length===1&&u[0]!==void 0&&(u=wI(u[0],!1).map(foo),u.length===1))return i.map(d=>o.pre+u[0]+d);let _;if(c&&u[0]!==void 0&&u[1]!==void 0){const d=j5e(u[0]),m=j5e(u[1]),h=Math.max(u[0].length,u[1].length);let p=u.length===3&&u[2]!==void 0?Math.abs(j5e(u[2])):1,x=goo;m<d&&(p*=-1,x=yoo);const g=u.some(xoo);_=[];for(let y=d;x(y,m);y+=p){let b;if(a)b=String.fromCharCode(y),b==="\\"&&(b="");else if(b=String(y),g){const v=h-b.length;if(v>0){const S=new Array(v+1).join("0");y<0?b="-"+S+b.slice(1):b=S+b}}_.push(b)}}else{_=[];for(let d=0;d<u.length;d++)_.push.apply(_,wI(u[d],!1))}for(let d=0;d<_.length;d++)for(let m=0;m<i.length;m++){const h=r+_[d]+i[m];(!e||c||h)&&n.push(h)}}return n}const boo=1024*64,aq=t=>{if(typeof t!="string")throw new TypeError("invalid pattern");if(t.length>boo)throw new TypeError("pattern is too long")},Poo={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},EI=t=>t.replace(/[[\]\\-]/g,"\\$&"),voo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Zpt=t=>t.join(""),Soo=(t,e)=>{const n=e;if(t.charAt(n)!=="[")throw new Error("not in a brace expression");const o=[],r=[];let i=n+1,s=!1,a=!1,c=!1,l=!1,u=n,_="";e:for(;i<t.length;){const p=t.charAt(i);if((p==="!"||p==="^")&&i===n+1){l=!0,i++;continue}if(p==="]"&&s&&!c){u=i+1;break}if(s=!0,p==="\\"&&!c){c=!0,i++;continue}if(p==="["&&!c){for(const[x,[f,g,y]]of Object.entries(Poo))if(t.startsWith(x,i)){if(_)return["$.",!1,t.length-n,!0];i+=x.length,y?r.push(f):o.push(f),a=a||g;continue e}}if(c=!1,_){p>_?o.push(EI(_)+"-"+EI(p)):p===_&&o.push(EI(p)),_="",i++;continue}if(t.startsWith("-]",i+1)){o.push(EI(p+"-")),i+=2;continue}if(t.startsWith("-",i+1)){_=p,i+=2;continue}o.push(EI(p)),i++}if(u<i)return["",!1,0,!1];if(!o.length&&!r.length)return["$.",!1,t.length-n,!0];if(r.length===0&&o.length===1&&/^\\?.$/.test(o[0])&&!l){const p=o[0].length===2?o[0].slice(-1):o[0];return[voo(p),!1,u-n,!1]}const d="["+(l?"^":"")+Zpt(o)+"]",m="["+(l?"":"^")+Zpt(r)+"]";return[o.length&&r.length?"("+d+"|"+m+")":o.length?d:m,a,u-n,!0]},DI=(t,{windowsPathsNoEscape:e=!1,magicalBraces:n=!0}={})=>n?e?t.replace(/\[([^\/\\])\]/g,"$1"):t.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):e?t.replace(/\[([^\/\\{}])\]/g,"$1"):t.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),Coo=new Set(["!","?","+","*","@"]),eft=t=>Coo.has(t),Moo="(?!(?:^|/)\\.\\.?(?:$|/))",cq="(?!\\.)",Too=new Set(["[","."]),woo=new Set(["..","."]),Eoo=new Set("().*{}+?[]^$\\!"),Doo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),G5e="[^/]",tft=G5e+"*?",nft=G5e+"+?";class x2{type;#o;#n;#r=!1;#t=[];#e;#s;#i;#l=!1;#a;#u;#_=!1;constructor(e,n,o={}){this.type=e,e&&(this.#n=!0),this.#e=n,this.#o=this.#e?this.#e.#o:this,this.#a=this.#o===this?o:this.#o.#a,this.#i=this.#o===this?[]:this.#o.#i,e==="!"&&!this.#o.#l&&this.#i.push(this),this.#s=this.#e?this.#e.#t.length:0}get hasMagic(){if(this.#n!==void 0)return this.#n;for(const e of this.#t)if(typeof e!="string"&&(e.type||e.hasMagic))return this.#n=!0;return this.#n}toString(){return this.#u!==void 0?this.#u:this.type?this.#u=this.type+"("+this.#t.map(e=>String(e)).join("|")+")":this.#u=this.#t.map(e=>String(e)).join("")}#d(){if(this!==this.#o)throw new Error("should only call on root");if(this.#l)return this;this.toString(),this.#l=!0;let e;for(;e=this.#i.pop();){if(e.type!=="!")continue;let n=e,o=n.#e;for(;o;){for(let r=n.#s+1;!o.type&&r<o.#t.length;r++)for(const i of e.#t){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(o.#t[r])}n=o,o=n.#e}}return this}push(...e){for(const n of e)if(n!==""){if(typeof n!="string"&&!(n instanceof x2&&n.#e===this))throw new Error("invalid part: "+n);this.#t.push(n)}}toJSON(){const e=this.type===null?this.#t.slice().map(n=>typeof n=="string"?n:n.toJSON()):[this.type,...this.#t.map(n=>n.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#o||this.#o.#l&&this.#e?.type==="!")&&e.push({}),e}isStart(){if(this.#o===this)return!0;if(!this.#e?.isStart())return!1;if(this.#s===0)return!0;const e=this.#e;for(let n=0;n<this.#s;n++){const o=e.#t[n];if(!(o instanceof x2&&o.type==="!"))return!1}return!0}isEnd(){if(this.#o===this||this.#e?.type==="!")return!0;if(!this.#e?.isEnd())return!1;if(!this.type)return this.#e?.isEnd();const e=this.#e?this.#e.#t.length:0;return this.#s===e-1}copyIn(e){typeof e=="string"?this.push(e):this.push(e.clone(this))}clone(e){const n=new x2(this.type,e);for(const o of this.#t)n.copyIn(o);return n}static#c(e,n,o,r){let i=!1,s=!1,a=-1,c=!1;if(n.type===null){let m=o,h="";for(;m<e.length;){const p=e.charAt(m++);if(i||p==="\\"){i=!i,h+=p;continue}if(s){m===a+1?(p==="^"||p==="!")&&(c=!0):p==="]"&&!(m===a+2&&c)&&(s=!1),h+=p;continue}else if(p==="["){s=!0,a=m,c=!1,h+=p;continue}if(!r.noext&&eft(p)&&e.charAt(m)==="("){n.push(h),h="";const x=new x2(p,n);m=x2.#c(e,x,m,r),n.push(x);continue}h+=p}return n.push(h),m}let l=o+1,u=new x2(null,n);const _=[];let d="";for(;l<e.length;){const m=e.charAt(l++);if(i||m==="\\"){i=!i,d+=m;continue}if(s){l===a+1?(m==="^"||m==="!")&&(c=!0):m==="]"&&!(l===a+2&&c)&&(s=!1),d+=m;continue}else if(m==="["){s=!0,a=l,c=!1,d+=m;continue}if(eft(m)&&e.charAt(l)==="("){u.push(d),d="";const h=new x2(m,u);u.push(h),l=x2.#c(e,h,l,r);continue}if(m==="|"){u.push(d),d="",_.push(u),u=new x2(null,n);continue}if(m===")")return d===""&&n.#t.length===0&&(n.#_=!0),u.push(d),d="",n.push(..._,u),l;d+=m}return n.type=null,n.#n=void 0,n.#t=[e.substring(o-1)],l}static fromGlob(e,n={}){const o=new x2(null,void 0,n);return x2.#c(e,o,0,n),o}toMMPattern(){if(this!==this.#o)return this.#o.toMMPattern();const e=this.toString(),[n,o,r,i]=this.toRegExpSource();if(!(r||this.#n||this.#a.nocase&&!this.#a.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return o;const a=(this.#a.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${n}$`,a),{_src:n,_glob:e})}get options(){return this.#a}toRegExpSource(e){const n=e??!!this.#a.dot;if(this.#o===this&&this.#d(),!this.type){const c=this.isStart()&&this.isEnd()&&!this.#t.some(m=>typeof m!="string"),l=this.#t.map(m=>{const[h,p,x,f]=typeof m=="string"?x2.#p(m,this.#n,c):m.toRegExpSource(e);return this.#n=this.#n||x,this.#r=this.#r||f,h}).join("");let u="";if(this.isStart()&&typeof this.#t[0]=="string"&&!(this.#t.length===1&&woo.has(this.#t[0]))){const h=Too,p=n&&h.has(l.charAt(0))||l.startsWith("\\.")&&h.has(l.charAt(2))||l.startsWith("\\.\\.")&&h.has(l.charAt(4)),x=!n&&!e&&h.has(l.charAt(0));u=p?Moo:x?cq:""}let _="";return this.isEnd()&&this.#o.#l&&this.#e?.type==="!"&&(_="(?:$|\\/)"),[u+l+_,DI(l),this.#n=!!this.#n,this.#r]}const o=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:";let i=this.#h(n);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){const c=this.toString();return this.#t=[c],this.type=null,this.#n=void 0,[c,DI(this.toString()),!1,!1]}let s=!o||e||n||!cq?"":this.#h(!0);s===i&&(s=""),s&&(i=`(?:${i})(?:${s})*?`);let a="";if(this.type==="!"&&this.#_)a=(this.isStart()&&!n?cq:"")+nft;else{const c=this.type==="!"?"))"+(this.isStart()&&!n&&!e?cq:"")+tft+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=r+i+c}return[a,DI(i),this.#n=!!this.#n,this.#r]}#h(e){return this.#t.map(n=>{if(typeof n=="string")throw new Error("string type in extglob ast??");const[o,r,i,s]=n.toRegExpSource(e);return this.#r=this.#r||s,o}).filter(n=>!(this.isStart()&&this.isEnd())||!!n).join("|")}static#p(e,n,o=!1){let r=!1,i="",s=!1;for(let a=0;a<e.length;a++){const c=e.charAt(a);if(r){r=!1,i+=(Eoo.has(c)?"\\":"")+c;continue}if(c==="\\"){a===e.length-1?i+="\\\\":r=!0;continue}if(c==="["){const[l,u,_,d]=Soo(e,a);if(_){i+=l,s=s||u,a+=_-1,n=n||d;continue}}if(c==="*"){i+=o&&e==="*"?nft:tft,n=!0;continue}if(c==="?"){i+=G5e,n=!0;continue}i+=Doo(c)}return[i,DI(e),!!n,s]}}const Aoo=(t,{windowsPathsNoEscape:e=!1,magicalBraces:n=!1}={})=>n?e?t.replace(/[?*()[\]{}]/g,"[$&]"):t.replace(/[?*()[\]\\{}]/g,"\\$&"):e?t.replace(/[?*()[\]]/g,"[$&]"):t.replace(/[?*()[\]\\]/g,"\\$&");var aD={env:{}};const g2=(t,e,n={})=>(aq(e),!n.nocomment&&e.charAt(0)==="#"?!1:new AI(e,n).match(t)),Roo=/^\*+([^+@!?\*\[\(]*)$/,koo=t=>e=>!e.startsWith(".")&&e.endsWith(t),Noo=t=>e=>e.endsWith(t),Hoo=t=>(t=t.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(t)),Ioo=t=>(t=t.toLowerCase(),e=>e.toLowerCase().endsWith(t)),Loo=/^\*+\.\*+$/,Ooo=t=>!t.startsWith(".")&&t.includes("."),Foo=t=>t!=="."&&t!==".."&&t.includes("."),Boo=/^\.\*+$/,zoo=t=>t!=="."&&t!==".."&&t.startsWith("."),Voo=/^\*+$/,$oo=t=>t.length!==0&&!t.startsWith("."),Woo=t=>t.length!==0&&t!=="."&&t!=="..",Uoo=/^\?+([^+@!?\*\[\(]*)?$/,Xoo=([t,e=""])=>{const n=oft([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},joo=([t,e=""])=>{const n=rft([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},Goo=([t,e=""])=>{const n=rft([t]);return e?o=>n(o)&&o.endsWith(e):n},Yoo=([t,e=""])=>{const n=oft([t]);return e?o=>n(o)&&o.endsWith(e):n},oft=([t])=>{const e=t.length;return n=>n.length===e&&!n.startsWith(".")},rft=([t])=>{const e=t.length;return n=>n.length===e&&n!=="."&&n!==".."},ift=typeof aD=="object"&&aD?typeof aD.env=="object"&&aD.env&&aD.env.__MINIMATCH_TESTING_PLATFORM__||aD.platform:"posix",sft={win32:{sep:"\\"},posix:{sep:"/"}},qoo=ift==="win32"?sft.win32.sep:sft.posix.sep;g2.sep=qoo;const O5=Symbol("globstar **");g2.GLOBSTAR=O5;const Joo="[^/]"+"*?",Koo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Qoo="(?:(?!(?:\\/|^)\\.).)*?",Zoo=(t,e={})=>n=>g2(n,t,e);g2.filter=Zoo;const F5=(t,e={})=>Object.assign({},t,e),ero=t=>{if(!t||typeof t!="object"||!Object.keys(t).length)return g2;const e=g2;return Object.assign((o,r,i={})=>e(o,r,F5(t,i)),{Minimatch:class extends e.Minimatch{constructor(r,i={}){super(r,F5(t,i))}static defaults(r){return e.defaults(F5(t,r)).Minimatch}},AST:class extends e.AST{constructor(r,i,s={}){super(r,i,F5(t,s))}static fromGlob(r,i={}){return e.AST.fromGlob(r,F5(t,i))}},unescape:(o,r={})=>e.unescape(o,F5(t,r)),escape:(o,r={})=>e.escape(o,F5(t,r)),filter:(o,r={})=>e.filter(o,F5(t,r)),defaults:o=>e.defaults(F5(t,o)),makeRe:(o,r={})=>e.makeRe(o,F5(t,r)),braceExpand:(o,r={})=>e.braceExpand(o,F5(t,r)),match:(o,r,i={})=>e.match(o,r,F5(t,i)),sep:e.sep,GLOBSTAR:O5})};g2.defaults=ero;const aft=(t,e={})=>(aq(t),e.nobrace||!/\{(?:(?!\{).)*\}/.test(t)?[t]:poo(t));g2.braceExpand=aft;const tro=(t,e={})=>new AI(t,e).makeRe();g2.makeRe=tro;const nro=(t,e,n={})=>{const o=new AI(e,n);return t=t.filter(r=>o.match(r)),o.options.nonull&&!t.length&&t.push(e),t};g2.match=nro;const cft=/[?*]|[+@!]\(.*?\)|\[|\]/,oro=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");class AI{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(e,n={}){aq(e),n=n||{},this.options=n,this.pattern=e,this.platform=n.platform||ift,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!n.windowsPathsNoEscape||n.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!n.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!n.nonegate,this.comment=!1,this.empty=!1,this.partial=!!n.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=n.windowsNoMagicRoot!==void 0?n.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(const e of this.set)for(const n of e)if(typeof n!="string")return!0;return!1}debug(...e){}make(){const e=this.pattern,n=this.options;if(!n.nocomment&&e.charAt(0)==="#"){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],n.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);const o=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(o),this.debug(this.pattern,this.globParts);let r=this.globParts.map((i,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){const c=i[0]===""&&i[1]===""&&(i[2]==="?"||!cft.test(i[2]))&&!cft.test(i[3]),l=/^[a-z]:/i.test(i[0]);if(c)return[...i.slice(0,4),...i.slice(4).map(u=>this.parse(u))];if(l)return[i[0],...i.slice(1).map(u=>this.parse(u))]}return i.map(c=>this.parse(c))});if(this.debug(this.pattern,r),this.set=r.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){const s=this.set[i];s[0]===""&&s[1]===""&&this.globParts[i][2]==="?"&&typeof s[3]=="string"&&/^[a-z]:$/i.test(s[3])&&(s[2]="?")}this.debug(this.pattern,this.set)}preprocess(e){if(this.options.noglobstar)for(let o=0;o<e.length;o++)for(let r=0;r<e[o].length;r++)e[o][r]==="**"&&(e[o][r]="*");const{optimizationLevel:n=1}=this.options;return n>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):n>=1?e=this.levelOneOptimize(e):e=this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(n=>{let o=-1;for(;(o=n.indexOf("**",o+1))!==-1;){let r=o;for(;n[r+1]==="**";)r++;r!==o&&n.splice(o,r-o)}return n})}levelOneOptimize(e){return e.map(n=>(n=n.reduce((o,r)=>{const i=o[o.length-1];return r==="**"&&i==="**"?o:r===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(o.pop(),o):(o.push(r),o)},[]),n.length===0?[""]:n))}levelTwoFileOptimize(e){Array.isArray(e)||(e=this.slashSplit(e));let n=!1;do{if(n=!1,!this.preserveMultipleSlashes){for(let r=1;r<e.length-1;r++){const i=e[r];r===1&&i===""&&e[0]===""||(i==="."||i==="")&&(n=!0,e.splice(r,1),r--)}e[0]==="."&&e.length===2&&(e[1]==="."||e[1]==="")&&(n=!0,e.pop())}let o=0;for(;(o=e.indexOf("..",o+1))!==-1;){const r=e[o-1];r&&r!=="."&&r!==".."&&r!=="**"&&(n=!0,e.splice(o-1,2),o-=2)}}while(n);return e.length===0?[""]:e}firstPhasePreProcess(e){let n=!1;do{n=!1;for(let o of e){let r=-1;for(;(r=o.indexOf("**",r+1))!==-1;){let s=r;for(;o[s+1]==="**";)s++;s>r&&o.splice(r+1,s-r);let a=o[r+1];const c=o[r+2],l=o[r+3];if(a!==".."||!c||c==="."||c===".."||!l||l==="."||l==="..")continue;n=!0,o.splice(r,1);const u=o.slice(0);u[r]="**",e.push(u),r--}if(!this.preserveMultipleSlashes){for(let s=1;s<o.length-1;s++){const a=o[s];s===1&&a===""&&o[0]===""||(a==="."||a==="")&&(n=!0,o.splice(s,1),s--)}o[0]==="."&&o.length===2&&(o[1]==="."||o[1]==="")&&(n=!0,o.pop())}let i=0;for(;(i=o.indexOf("..",i+1))!==-1;){const s=o[i-1];if(s&&s!=="."&&s!==".."&&s!=="**"){n=!0;const c=i===1&&o[i+1]==="**"?["."]:[];o.splice(i-1,2,...c),o.length===0&&o.push(""),i-=2}}}}while(n);return e}secondPhasePreProcess(e){for(let n=0;n<e.length-1;n++)for(let o=n+1;o<e.length;o++){const r=this.partsMatch(e[n],e[o],!this.preserveMultipleSlashes);if(r){e[n]=[],e[o]=r;break}}return e.filter(n=>n.length)}partsMatch(e,n,o=!1){let r=0,i=0,s=[],a="";for(;r<e.length&&i<n.length;)if(e[r]===n[i])s.push(a==="b"?n[i]:e[r]),r++,i++;else if(o&&e[r]==="**"&&n[i]===e[r+1])s.push(e[r]),r++;else if(o&&n[i]==="**"&&e[r]===n[i+1])s.push(n[i]),i++;else if(e[r]==="*"&&n[i]&&(this.options.dot||!n[i].startsWith("."))&&n[i]!=="**"){if(a==="b")return!1;a="a",s.push(e[r]),r++,i++}else if(n[i]==="*"&&e[r]&&(this.options.dot||!e[r].startsWith("."))&&e[r]!=="**"){if(a==="a")return!1;a="b",s.push(n[i]),r++,i++}else return!1;return e.length===n.length&&s}parseNegate(){if(this.nonegate)return;const e=this.pattern;let n=!1,o=0;for(let r=0;r<e.length&&e.charAt(r)==="!";r++)n=!n,o++;o&&(this.pattern=e.slice(o)),this.negate=n}matchOne(e,n,o=!1){const r=this.options;if(this.isWindows){const p=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),x=!p&&e[0]===""&&e[1]===""&&e[2]==="?"&&/^[a-z]:$/i.test(e[3]),f=typeof n[0]=="string"&&/^[a-z]:$/i.test(n[0]),g=!f&&n[0]===""&&n[1]===""&&n[2]==="?"&&typeof n[3]=="string"&&/^[a-z]:$/i.test(n[3]),y=x?3:p?0:void 0,b=g?3:f?0:void 0;if(typeof y=="number"&&typeof b=="number"){const[v,S]=[e[y],n[b]];v.toLowerCase()===S.toLowerCase()&&(n[b]=v,b>y?n=n.slice(b):y>b&&(e=e.slice(y)))}}const{optimizationLevel:i=1}=this.options;i>=2&&(e=this.levelTwoFileOptimize(e)),this.debug("matchOne",this,{file:e,pattern:n}),this.debug("matchOne",e.length,n.length);for(var s=0,a=0,c=e.length,l=n.length;s<c&&a<l;s++,a++){this.debug("matchOne loop");var u=n[a],_=e[s];if(this.debug(n,u,_),u===!1)return!1;if(u===O5){this.debug("GLOBSTAR",[n,u,_]);var d=s,m=a+1;if(m===l){for(this.debug("** at the end");s<c;s++)if(e[s]==="."||e[s]===".."||!r.dot&&e[s].charAt(0)===".")return!1;return!0}for(;d<c;){var h=e[d];if(this.debug(`
|
|
5785
|
+
${S}`)}},[e,d]),Y.useEffect(()=>{e&&!d&&zmt().then(S=>{p(S.size)}).catch(S=>{console.error("Failed to fetch file count",S),p(0)})},[e,d]);const g=Y.useCallback(()=>{s(null),m(null),c(null),u([]),_.current&&(_.current.value=""),n(!0)},[]),y=Y.useCallback(()=>{n(!1)},[]),b=Y.useCallback(async()=>{r(!0),s(null),c(null),u([]);const S=Xv(),M=_.current?.value||"";try{const w=await zmt();if(w.size===0){ds.error("No project files available to include in the bug report"),r(!1);return}const D=new Date(Date.now()+1440*60*1e3).toISOString(),I=(await S.post("bug_reports/create",{json:{text:M.trim()||void 0,is_auto_deleted:!0,delete_at:D}}).json()).bug_report.bug_report_id,H=Array.from(w.entries()),O=[];for(let V=0;V<H.length;V++){const[j,q]=H[V];c({current:V+1,total:H.length,currentFile:j});try{const K={bug_report_id:I,file_path:j};q.text_content&&(K.content_text=q.text_content),q.binary_content_b64&&(K.content_base64=q.binary_content_b64),await S.post("bug_reports/upload_file",{json:K})}catch(K){const ne=K instanceof Uv?`HTTP ${K.response.status}`:K instanceof Error?K.message:"Upload failed";O.push({filePath:j,message:ne}),u([...O])}}c(null);const z=Qeo(I);m({bugReportUrl:z})}catch(w){if(console.error("Failed to submit bug report",w),w instanceof Uv)if(w.response.status===401)if(f){const D="Your session has expired. Please sign in again to continue.";s(D),ds.error(D),x&&(y(),x())}else{const D="You must be logged in to report a bug. Please sign in via cli and try again.";s(D),ds.error(D),setTimeout(()=>{x&&(y(),x())},1e3)}else{const D=`Failed to submit bug report (${w.response.status})`;s(D),ds.error(D)}else if(w instanceof Error)s(w.message),ds.error(w.message);else{const D="Failed to submit bug report";s(D),ds.error(D)}}finally{r(!1)}},[f,x]);return{BugReportDialog:Y.useMemo(()=>{const S=a?Math.round(a.current/a.total*100):0;return G.jsx(bht,{open:e,onOpenChange:M=>{M?(s(null),m(null),c(null),u([]),n(!0)):o||y()},children:G.jsxs(Fye,{children:[G.jsxs(Bye,{children:[G.jsx(Vye,{children:d?"Bug Report Created":"Report Bug"}),G.jsx($ye,{asChild:!0,children:d?G.jsxs("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:[G.jsx("p",{children:"Bug report created successfully."}),l.length>0&&G.jsxs("div",{className:"rf-bg-red-50 rf-border rf-border-red-200 rf-rounded rf-p-2 rf-max-h-28 rf-overflow-y-auto rf-overflow-x-hidden",children:[G.jsxs("p",{className:"rf-text-red-700 rf-font-medium rf-text-xs rf-mb-1",children:[l.length," file(s) failed:"]}),l.map((M,w)=>G.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[G.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),G.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},w))]}),G.jsx("div",{children:G.jsx("a",{className:"rf-text-blue-600 hover:rf-underline",href:d.bugReportUrl,target:"_blank",rel:"noreferrer",children:"View bug report"})}),G.jsxs("p",{children:["Please share this link privately with tscircuit staff so we can help debug. Join the",G.jsx("a",{className:"rf-ml-1 rf-text-blue-600 hover:rf-underline",href:"https://tscircuit.com/join",target:"_blank",rel:"noreferrer",children:"tscircuit Discord"}),"."]})]}):G.jsx("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:a?G.jsxs("div",{className:"rf-space-y-2 rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-flex rf-justify-between rf-text-xs",children:[G.jsx("span",{children:"Uploading files..."}),G.jsxs("span",{children:[a.current,"/",a.total]})]}),G.jsx("div",{className:"rf-w-full rf-h-2 rf-bg-gray-200 rf-rounded-full rf-overflow-hidden",children:G.jsx("div",{className:"rf-h-full rf-bg-blue-500 rf-transition-all rf-duration-150",style:{width:`${S}%`}})}),G.jsx("p",{className:"rf-text-xs rf-text-gray-500 rf-break-all rf-truncate rf-w-full rf-max-w-full",children:`${a.currentFile.slice(0,60)}${a.currentFile.length>60?"...":""}`}),l.length>0&&G.jsx("div",{className:"rf-bg-red-50 rf-border rf-border-red-200 rf-rounded rf-p-2 rf-max-h-20 rf-overflow-y-auto rf-overflow-x-hidden",children:l.map((M,w)=>G.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[G.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),G.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},w))})]}):G.jsxs(G.Fragment,{children:[G.jsxs("p",{children:["Reporting a bug will upload your entire project",h>0?` (${h} file${h===1?"":"s"})`:""," ","to tscircuit support."]}),G.jsxs("div",{className:"rf-space-y-2",children:[G.jsx("label",{htmlFor:"bug-description",className:"rf-block rf-font-medium",children:"Description (optional)"}),G.jsx("textarea",{ref:_,id:"bug-description",className:"rf-w-full rf-min-h-[100px] rf-px-3 rf-py-2 rf-text-sm rf-border rf-border-gray-300 rf-rounded-md focus:rf-outline-none focus:rf-ring-2 focus:rf-ring-blue-500",placeholder:"Describe the issue you're experiencing...",disabled:o})]}),G.jsxs("p",{children:["Share the generated bug report link privately with tscircuit staff so we can help debug your issue. You can also reach out on our",G.jsx("a",{className:"rf-ml-1 rf-text-blue-600 hover:rf-underline",href:"https://tscircuit.com/join",target:"_blank",rel:"noreferrer",children:"Discord community"}),"."]}),!f&&G.jsx("p",{className:"rf-text-red-600",children:"You appear to be logged out. Please log in before reporting a bug or the upload will fail."}),i&&G.jsx("p",{className:"rf-text-red-600",children:i})]})})})]}),G.jsx(zye,{children:d?G.jsx("button",{type:"button",className:fE(),onClick:()=>{y()},children:"Close"}):G.jsxs(G.Fragment,{children:[G.jsx(Wye,{disabled:o,onClick:()=>{o||y()},children:"Cancel"}),!f&&x?G.jsx("button",{type:"button",className:fE(),onClick:M=>{M.preventDefault(),y(),x()},children:"Sign In"}):G.jsx("button",{type:"button",className:h4(fE(),o&&"rf-opacity-70 rf-cursor-not-allowed"),disabled:o,onClick:M=>{M.preventDefault(),b()},children:o?"Reporting...":"Upload & Report"})]})})]})},"bug-report-dialog")},[e,o,y,i,d,h,f,b,x,a,l]),openBugReportDialog:g}};function eto({open:t,onOpenChange:e,onExport:n}){const[o,r]=Y.useState(!1),i=()=>{n({includeSilkscreen:o}),e(!1)},s=()=>{e(!1)};return G.jsx(QE,{open:t,onOpenChange:e,children:G.jsxs(eC,{children:[G.jsxs(tC,{children:[G.jsx(nC,{children:"LightBurn Export Options"}),G.jsx(ZE,{children:"Configure export settings for PCB laser ablation with LightBurn"})]}),G.jsx("div",{className:"rf-flex rf-flex-col rf-gap-4 rf-py-4",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-space-x-2",children:[G.jsx(lI,{id:"includeSilkscreen",checked:o,onCheckedChange:a=>r(a===!0)}),G.jsx("label",{htmlFor:"includeSilkscreen",className:"rf-text-xs rf-font-medium rf-leading-none peer-disabled:rf-cursor-not-allowed peer-disabled:rf-opacity-70",children:"Include silkscreen layer"})]})}),G.jsxs(uI,{children:[G.jsx(dc,{variant:"outline",onClick:s,children:"Cancel"}),G.jsx(dc,{onClick:i,children:"Export"})]})]})})}const tto=/#(\d+)/,nto=t=>{const e=t.match(tto);if(!e)return null;const n=Number.parseInt(e[1],10);return Number.isFinite(n)?n:null},oto=t=>{if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"){const e=new Date(t).getTime();return Number.isFinite(e)?e:null}return null},rto=t=>{if(!t)return null;let e=null,n=-1,o=-1;for(const[r,i]of Object.entries(t)){const s=nto(r),a=oto(i.createdAt);if(s!==null){s>n&&(n=s,e={key:r,value:i});continue}if(n===-1){if(a!==null&&a>o){o=a,e={key:r,value:i};continue}e||(e={key:r,value:i})}}return e},bI=t=>{const e=bY(De=>De.lastRunEvalVersion),n=eu(De=>De.currentMainComponentPath),[o,r]=Y.useState(null),[i,s]=Y.useState(!1),[a,c]=Y.useState(!0),[l,u]=Y.useState(!1),[_,d]=Y.useState(null),[m,h]=Y.useState(null),[p,x]=Y.useState(!1),[f,g]=Y.useState(null),[y,b]=Y.useState(null),[v,S]=Y.useState(!1),[M,w]=Y.useState(!1),[D,A]=Y.useState(!1),[I,H]=Y.useState(null),O=Jeo(),z=eu(De=>De.pushEvent),V=eu(De=>De.recentEvents),j=Y.useMemo(()=>Date.now(),[]);VJn(De=>{if(!(new Date(De.created_at).valueOf()<j+500)){if(De.event_type==="FILE_UPDATED"){s(!0);return}if(De.event_type==="SNIPPET_SAVED"){s(!1),c(!1),g("Snippet saved successfully."),S(!1);return}De.event_type==="REQUEST_EXPORT"&&(w(!0),g("Export processing..."),S(!1)),De.event_type==="EXPORT_CREATED"&&(g(`Export created: ${De.exportFilePath}`),S(!1),w(!1))}}),Y.useEffect(()=>{if(!l||_===null)return;const De=V.filter(xe=>new Date(xe.created_at).valueOf()>_),pe=De.find(xe=>xe.event_type==="FAILED_TO_SAVE_SNIPPET"),Me=De.find(xe=>xe.event_type==="SNIPPET_SAVED");pe&&(u(!1),d(null),b(pe.message??"Failed to save snippet. See console for error."),console.error(pe.message),S(!0),pe.error_code==="SNIPPET_UNSET"&&pe.available_snippet_names&&(h(pe.available_snippet_names),x(!0))),Me&&(u(!1),d(null),g("Snippet saved successfully."),S(!1))},[V,l]);const q=async()=>{u(!0),d(Date.now()),g(null),S(!1),await z({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:o})},ne=eu(De=>De.circuitJson)??t.circuitJson,[ce,ee]=Y.useState(!1),[oe,ie]=Y.useState(!1),{BugReportDialog:ae,openBugReportDialog:de}=Zeo({onLoginRequired:t.onLoginRequired}),be=async De=>{I&&(await qht({circuitJson:I.circuitJson,projectName:I.projectName,options:De}),H(null))},Ce=Y.useMemo(()=>rto(t.autoroutingLog),[t.autoroutingLog]);return G.jsxs(G.Fragment,{children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1 rf-flex-shrink-0",children:[G.jsxs(qj,{children:[G.jsx(Jj,{asChild:!0,children:G.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"File"})}),G.jsxs(uH,{className:"rf-z-[101]",children:[!t.isWebEmbedded&&G.jsxs(G.Fragment,{children:[G.jsx(Md,{className:"rf-text-xs",onSelect:q,disabled:l,children:l?"Saving...":"Push"}),parseInt(window.location.port)>5e3&&G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{O.open()},children:"Order"}),G.jsx(Md,{className:"rf-text-xs",onSelect:()=>ee(!0),disabled:l,children:"Import"}),G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{if(!NY()){ds.error("Requires tscircuit token");return}ie(!0)},children:"AI Review"})]}),!t.isWebEmbedded&&t.onLoginRequired&&G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{t.onLoginRequired?.()},children:"Sign In"}),!t.isWebEmbedded&&G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",children:"Report Bug"}),G.jsx(cH,{children:G.jsxs(EE,{children:[G.jsx(Md,{className:"rf-text-xs",onSelect:()=>{de()},children:"Report Entire Circuit"}),G.jsx(Md,{className:"rf-text-xs",disabled:!Ce||!t.onReportAutoroutingLog,onSelect:()=>{!Ce||!t.onReportAutoroutingLog||t.onReportAutoroutingLog(Ce.key,{simpleRouteJson:Ce.value.simpleRouteJson})},children:"Report Autorouter Bug"})]})})]}),G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",disabled:M,children:M?"Exporting...":"Export"}),G.jsx(cH,{children:G.jsx(EE,{children:KQn.map((De,pe)=>G.jsx(Md,{onSelect:()=>{if(!ne){ds.error("No Circuit JSON to export");return}let Me="Untitled";if(n){const We=n.split("/").pop();We&&(Me=We.replace(/\.[^.]+$/,""))}const xe=t.projectName??o??Me;if(De.name==="LightBurn"){H({circuitJson:ne,projectName:xe}),A(!0);return}QQn({exportName:De.name,circuitJson:ne,projectName:xe?.replace(/\.(board|circuit)$/,"")})},disabled:M,children:G.jsx("span",{className:"rf-text-xs",children:De.name})},pe))})})]}),!t.isWebEmbedded&&G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",children:"Advanced"}),G.jsx(cH,{children:G.jsxs(EE,{children:[G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(lI,{id:"load-latest-eval",checked:t.shouldLoadLatestEval,onCheckedChange:De=>{t.onChangeShouldLoadLatestEval?.(De===!0)}}),G.jsx("label",{htmlFor:"load-latest-eval",className:"rf-text-xs rf-cursor-pointer",children:"Force Latest @tscircuit/eval"})]})}),e&&G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",children:G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:G.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/eval@",e]})})}),G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",children:G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:G.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/runframe@",FJn.version]})})}),G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",onClick:()=>{window.open("/api/admin","_blank")},children:G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:G.jsx("span",{className:"rf-text-xs",children:"CLI Admin Panel"})})})]})})]})]}),G.jsx(bht,{open:v,onOpenChange:S,children:G.jsxs(Fye,{children:[G.jsxs(Bye,{children:[G.jsx(Vye,{children:"Error Saving Snippet"}),G.jsx($ye,{children:y})]}),G.jsx(zye,{children:G.jsx(Wye,{onClick:()=>S(!1),children:"Dismiss"})})]})}),G.jsx(zJn,{snippetNames:m??[],onSelect:async De=>{u(!0),d(Date.now()),r(De),await z({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:De}),x(!1)},onCancel:()=>x(!1),isOpen:p})]}),G.jsxs(qj,{children:[G.jsx(Jj,{asChild:!0,children:G.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"View"})}),G.jsx(uH,{className:"rf-z-[104]",children:G.jsxs(lH,{children:[G.jsx(wE,{className:"rf-text-xs",children:"Schematic"}),G.jsx(cH,{children:G.jsxs(EE,{children:[G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",onSelect:De=>De.preventDefault(),children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(lI,{id:"show-schematic-ports",checked:t.showSchematicPorts,onCheckedChange:De=>{t.onChangeShowSchematicPorts?.(De===!0)}}),G.jsx("label",{htmlFor:"show-schematic-ports",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Ports"})]})}),G.jsx(Md,{className:"rf-flex rf-items-center rf-gap-2",onSelect:De=>De.preventDefault(),children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(lI,{id:"show-schematic-grid",checked:t.showSchematicDebugGrid,onCheckedChange:De=>{t.onChangeShowSchematicDebugGrid?.(De===!0)}}),G.jsx("label",{htmlFor:"show-schematic-grid",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Grid"})]})})]})})]})})]})]}),ae,G.jsx(eto,{open:D,onOpenChange:A,onExport:be}),G.jsx(jht,{isOpen:ce,onClose:()=>ee(!1)}),G.jsx(seo,{isOpen:oe,onClose:()=>ie(!1),packageName:o}),G.jsx(QKe,{position:"top-center",reverseOrder:!1,containerStyle:{zIndex:1e5},toastOptions:{className:"rf-break-all",style:{zIndex:1e5}}}),G.jsx(O.OrderDialog,{isOpen:O.isOpen,onClose:O.close,stage:O.stage,setStage:O.setStage})]})},ito=["assembly","pinout","analog_simulation","bom","circuit_json","errors","render_log","solvers"],Vmt=({code:t,fsMap:e,onRunClicked:n=void 0,errorMessage:o,errorStack:r,circuitJson:i,autoroutingGraphics:s,showRightHeaderContent:a=!0,showCodeTab:c=!1,codeTabContent:l,showJsonTab:u=!0,showRenderLogTab:_=!0,onActiveTabChange:d,renderLog:m,showImportAndFormatButtons:h=!0,className:p,headerClassName:x,leftHeaderContent:f,readOnly:g,isStreaming:y,autoroutingLog:b,onReportAutoroutingLog:v,isRunningCode:S,hasCodeChangedSinceLastRun:M,onEditEvent:w,editEvents:D,defaultActiveTab:A,defaultTab:I,availableTabs:H,autoRotate3dViewerDisabled:O,showSchematicDebugGrid:z=!1,showSchematicPorts:V=!1,onChangeShowSchematicDebugGrid:j,onChangeShowSchematicPorts:q,showToggleFullScreen:K=!0,defaultToFullScreen:ne=!1,activeEffectName:ce,allowSelectingVersion:ee=!0,showFileMenu:oe=!1,isWebEmbedded:ie=!1,projectName:ae,onRerunWithDebug:de,solverEvents:be})=>{xY();const{versions:Ce,latestVersion:De,lastRunEvalVersion:pe,search:Me,setSearch:xe,selectVersion:We}=BJn(ee),Xe=Y.useMemo(()=>i?i.filter(Dt=>Dt&&"error_type"in Dt||Dt.type.includes("error")):null,[i]),Je=Y.useMemo(()=>i?i.filter(Dt=>Dt&&"warning_type"in Dt||Dt.type.includes("warning")):null,[i]),fe=Y.useMemo(()=>i?i.some(Dt=>Dt.type==="schematic_group"):!0,[i]),Ye=Y.useMemo(()=>i?.some(Dt=>Dt.type==="pcb_panel"),[i]);Ldt({errorMessage:o,errorStack:r,circuitJsonErrors:Xe});const Oe=I??H?.[0]??"pcb",[Ne,Ve]=RT("runframe-active-tab",A??Oe,A),[Re,Pe]=Y.useState(null),[Ee,we]=Y.useState(ne),[ze,Ue]=Y.useState(z),[et,ot]=Y.useState(V),at=j?z:ze,lt=q?V:et,xt=j??Ue,Ct=q??ot;ZYn(Ee);const Lt=Y.useCallback(Dt=>{Ve(Dt),d?.(Dt)},[d,Ve]),$t=()=>{we(!Ee)};Y.useEffect(()=>{o&&(Ne!=="errors"&&Pe(Ne),Lt("errors"))},[o]),Y.useEffect(()=>{(Ne==="code"||Ne==="errors")&&i&&!o&&Lt(Re??A??I??H?.[0]??"pcb")},[i]);const Ot=Y.useCallback(Dt=>{window.TSCIRCUIT_3D_OBJECT_REF=Dt===null?void 0:Dt},[]);return G.jsx("div",{className:lr("flex flex-col relative rf-overflow-x-hidden rf-h-full",p),children:G.jsx("div",{className:lr("rf-md:sticky rf-md:top-2 rf-h-full",Ee&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-h-full rf-bg-white rf-overflow-hidden"),children:G.jsxs(gae,{value:Ne,onValueChange:Lt,className:"rf-flex-grow rf-flex rf-flex-col rf-h-full",children:[G.jsxs("div",{className:lr("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",x),children:[f,oe&&!f&&G.jsx(bI,{isWebEmbedded:ie,circuitJson:i,projectName:ae,showSchematicDebugGrid:at,onChangeShowSchematicDebugGrid:xt,showSchematicPorts:lt,onChangeShowSchematicPorts:Ct}),(f||oe)&&G.jsx("div",{className:"rf-flex-grow"}),!f&&!oe&&S&&G.jsx($9,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!f&&!oe&&G.jsx("div",{className:"rf-flex-grow"}),m&&m.progress!==1&&!o&&G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-min-w-0 rf-max-w-xs",children:[ce?G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:ce,children:ce}):m.lastRenderEvent&&G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:m.lastRenderEvent?.phase??"",children:m.lastRenderEvent?.phase??""}),G.jsx("div",{className:"rf-w-4 rf-h-4 rf-bg-blue-500 rf-opacity-50 rf-rounded-full rf-text-white rf-flex-shrink-0",children:G.jsx($9,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),G.jsxs("div",{className:"rf-text-xs rf-font-bold rf-text-gray-700 rf-tabular-nums rf-flex-shrink-0",children:[((m.progress??0)*100).toFixed(1),"%"]})]}),a&&G.jsxs(AW,{children:[c&&G.jsx(z6,{value:"code",children:"Code"}),!H||H.includes("pcb")?G.jsxs(z6,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&G.jsx("span",{className:lr("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",M?"rf-bg-gray-500":"rf-bg-blue-500")}),"PCB"]}):null,!H||H.includes("schematic")?G.jsxs(z6,{value:"schematic",className:lr("rf-whitespace-nowrap",i&&!fe&&"rf-opacity-50"),disabled:i?!fe||Ye:!1,children:[i&&G.jsx("span",{className:lr("rf-inline-flex rf-items-center rf-justify-center rf-w-2 rf-h-2 rf-mr-1 rf-text-xs rf-font-bold rf-text-white rf-rounded-full",M?"rf-bg-gray-500":"rf-bg-blue-500")}),"Schematic"]}):null,!H||H.includes("cad")?G.jsxs(z6,{value:"cad",children:[i&&G.jsx("span",{className:lr("inline-flex items-center justify-center w-2 h-2 mr-1 text-xs font-bold text-white rounded-full",M?"rf-bg-gray-500":"rf-bg-blue-500")}),"3D"]}):null,!["pcb","cad","schematic"].includes(Ne)&&G.jsx(z6,{value:Ne,children:VFe(Ne)}),G.jsxs(qj,{children:[G.jsx(Jj,{asChild:!0,children:G.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[G.jsx(IDn,{className:"rf-w-4 rf-h-4"}),(Xe&&Xe.length>0||o)&&G.jsx("span",{className:"rf-inline-flex rf-absolute rf-top-[6px] rf-right-[4px] rf-items-center rf-justify-center rf-w-1 rf-h-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full"})]})}),G.jsxs(uH,{className:"rf-*:text-xs rf-z-[101]",children:[ito.filter(Dt=>!H||H.includes(Dt)).map(Dt=>G.jsxs(Md,{onSelect:()=>Lt(Dt),children:[Ne!==Dt&&G.jsx(sot,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Ne===Dt&&G.jsx(T8,{className:"rf-w-3 rf-h-3"}),G.jsx("div",{className:"rf-pr-2",children:VFe(Dt)}),Dt==="errors"&&(Xe&&Xe.length>0||o)&&G.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-3 rf-h-3 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-red-500 rf-rounded-full",children:o?1:Xe?.length}),Dt==="solvers"&&be&&be.length>0&&G.jsx("span",{className:"rf-inline-flex rf-items-center rf-justify-center rf-min-w-[12px] rf-h-3 rf-px-1 rf-ml-2 rf-text-[8px] rf-font-bold rf-text-white rf-bg-blue-500 rf-rounded-full",children:be.length})]},Dt)),G.jsx(Md,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:G.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",Odt.split(".").map((Dt,Wt)=>Wt===2?parseInt(Dt)+1:Dt).join(".")]})}),ee?G.jsxs(lH,{onOpenChange:Dt=>!Dt&&xe(""),children:[G.jsx(wE,{className:"rf-text-xs rf-opacity-60",children:G.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",pe??De??"latest"]})}),G.jsx(cH,{children:G.jsxs(EE,{className:"rf-*:text-xs rf-w-40 rf-max-h-[200px] rf-overflow-y-auto",children:[G.jsx("div",{className:"rf-p-1",children:G.jsx(age,{value:Me,onChange:Dt=>xe(Dt.target.value),placeholder:"Search...",className:"rf-h-7 rf-text-xs"})}),G.jsx(ait,{}),G.jsx(Md,{onSelect:()=>We(null),children:De?`${De} (latest)`:"latest"}),Ce.map(Dt=>G.jsx(Md,{onSelect:()=>We(Dt),children:Dt},Dt))]})})]}):pe&&G.jsx(Md,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:G.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",pe]})})]})]})]}),K&&G.jsx(dc,{onClick:$t,variant:"ghost",children:Ee?G.jsx(UDn,{size:16}):G.jsx(zDn,{size:16})})]}),c&&G.jsx(a1,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:G.jsx("div",{className:"rf-h-full",children:l})}),(!H||H.includes("pcb"))&&G.jsx(a1,{value:"pcb",children:G.jsx("div",{className:lr("rf-overflow-hidden",Ee?"rf-h-[calc(100vh-52px)]":"rf-h-full"),children:G.jsx(M5,{fallbackRender:({error:Dt})=>G.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:Dt?.message||"An unknown error occurred"})]})}),children:i?G.jsx(KYn,{focusOnHover:!1,circuitJson:i,debugGraphics:s,containerClassName:lr("rf-h-full rf-w-full",Ee?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:Dt=>{if(w)for(const Wt of Dt)w(Wt)}}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("assembly"))&&G.jsx(a1,{value:"assembly",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Assembly"}),children:i?G.jsx(KVn,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("pinout"))&&G.jsx(a1,{value:"pinout",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Pinout Viewer"}),children:i?G.jsx(QVn,{circuitJson:i,containerStyle:{height:"100%"}}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("schematic"))&&G.jsx(a1,{value:"schematic",children:G.jsx("div",{className:lr("rf-overflow-auto rf-bg-white",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallbackRender:({error:Dt})=>G.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:Dt?.message||"An unknown error occurred"})]})}),children:i?G.jsx(qVn,{spiceSimulationEnabled:!0,circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:Dt=>{w?.(Dt)},debugGrid:at,showSchematicPorts:lt}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("cad"))&&G.jsx(a1,{value:"cad",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallbackRender:({error:Dt,resetErrorBoundary:Wt})=>G.jsx(fDn,{error:Dt,resetErrorBoundary:Wt}),children:i?G.jsx(sDn,{ref:Ot,circuitJson:i,autoRotateDisabled:O},`cad-${Ee}`):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("analog_simulation"))&&G.jsx(a1,{value:"analog_simulation",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Analog Simulation"}),children:i?G.jsx(JVn,{circuitJson:i,containerStyle:{height:"100%"}}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("bom"))&&G.jsx(a1,{value:"bom",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallbackRender:({error:Dt})=>G.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:Dt?.message||"An unknown error occurred"})]})}),children:i?G.jsx(m$n,{circuitJson:i}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("circuit_json"))&&G.jsx(a1,{value:"circuit_json",children:G.jsx("div",{className:lr("rf-overflow-auto",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading JSON viewer"}),children:i?G.jsx(t$n,{elements:i}):G.jsx(J9,{onRunClicked:n})})})}),(!H||H.includes("errors"))&&G.jsx(a1,{value:"errors",className:"rf-h-full",children:G.jsx("div",{className:lr("rf-overflow-hidden",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:o||Xe&&Xe.length>0||i?G.jsx(VNn,{code:t,fsMap:e,circuitJsonErrors:Xe,circuitJsonWarnings:Je,errorMessage:o,errorStack:r,circuitJson:i,evalVersion:pe,autoroutingLog:b,onReportAutoroutingLog:v}):G.jsx(J9,{onRunClicked:n})})}),_&&(!H||H.includes("render_log"))&&G.jsx(a1,{value:"render_log",children:G.jsx(nqn,{renderLog:m,onRerunWithDebug:de})}),(!H||H.includes("solvers"))&&G.jsx(a1,{value:"solvers",children:G.jsx("div",{className:lr("rf-overflow-hidden",Ee?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:G.jsx(M5,{fallback:G.jsx("div",{children:"Error loading Solvers view"}),children:G.jsx(OJn,{solverEvents:be})})})})]})})})};const $mt=Symbol("Comlink.proxy"),sto=Symbol("Comlink.endpoint"),Wmt=Symbol("Comlink.releaseProxy"),T5e=Symbol("Comlink.finalizer"),JY=Symbol("Comlink.thrown"),Umt=t=>typeof t=="object"&&t!==null||typeof t=="function",ato={canHandle:t=>Umt(t)&&t[$mt],serialize(t){const{port1:e,port2:n}=new MessageChannel;return jmt(t,e),[n,[n]]},deserialize(t){return t.start(),Ymt(t)}},cto={canHandle:t=>Umt(t)&&JY in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},Xmt=new Map([["proxy",ato],["throw",cto]]);function lto(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function jmt(t,e=globalThis,n=["*"]){e.addEventListener("message",function o(r){if(!r||!r.data)return;if(!lto(n,r.origin)){console.warn(`Invalid origin '${r.origin}' for comlink proxy`);return}const{id:i,type:s,path:a}=Object.assign({path:[]},r.data),c=(r.data.argumentList||[]).map(lC);let l;try{const u=a.slice(0,-1).reduce((d,m)=>d[m],t),_=a.reduce((d,m)=>d[m],t);switch(s){case"GET":l=_;break;case"SET":u[a.slice(-1)[0]]=lC(r.data.value),l=!0;break;case"APPLY":l=_.apply(u,c);break;case"CONSTRUCT":{const d=new _(...c);l=E5e(d)}break;case"ENDPOINT":{const{port1:d,port2:m}=new MessageChannel;jmt(t,m),l=mto(d,[d])}break;case"RELEASE":l=void 0;break;default:return}}catch(u){l={value:u,[JY]:0}}Promise.resolve(l).catch(u=>({value:u,[JY]:0})).then(u=>{const[_,d]=eq(u);e.postMessage(Object.assign(Object.assign({},_),{id:i}),d),s==="RELEASE"&&(e.removeEventListener("message",o),Gmt(e),T5e in t&&typeof t[T5e]=="function"&&t[T5e]())}).catch(u=>{const[_,d]=eq({value:new TypeError("Unserializable return value"),[JY]:0});e.postMessage(Object.assign(Object.assign({},_),{id:i}),d)})}),e.start&&e.start()}function uto(t){return t.constructor.name==="MessagePort"}function Gmt(t){uto(t)&&t.close()}function Ymt(t,e){const n=new Map;return t.addEventListener("message",function(r){const{data:i}=r;if(!i||!i.id)return;const s=n.get(i.id);if(s)try{s(i)}finally{n.delete(i.id)}}),w5e(t,n,[],e)}function KY(t){if(t)throw new Error("Proxy has been released and is not useable")}function qmt(t){return nD(t,new Map,{type:"RELEASE"}).then(()=>{Gmt(t)})}const QY=new WeakMap,ZY="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(QY.get(t)||0)-1;QY.set(t,e),e===0&&qmt(t)});function _to(t,e){const n=(QY.get(e)||0)+1;QY.set(e,n),ZY&&ZY.register(t,e,t)}function dto(t){ZY&&ZY.unregister(t)}function w5e(t,e,n=[],o=function(){}){let r=!1;const i=new Proxy(o,{get(s,a){if(KY(r),a===Wmt)return()=>{dto(i),qmt(t),e.clear(),r=!0};if(a==="then"){if(n.length===0)return{then:()=>i};const c=nD(t,e,{type:"GET",path:n.map(l=>l.toString())}).then(lC);return c.then.bind(c)}return w5e(t,e,[...n,a])},set(s,a,c){KY(r);const[l,u]=eq(c);return nD(t,e,{type:"SET",path:[...n,a].map(_=>_.toString()),value:l},u).then(lC)},apply(s,a,c){KY(r);const l=n[n.length-1];if(l===sto)return nD(t,e,{type:"ENDPOINT"}).then(lC);if(l==="bind")return w5e(t,e,n.slice(0,-1));const[u,_]=Jmt(c);return nD(t,e,{type:"APPLY",path:n.map(d=>d.toString()),argumentList:u},_).then(lC)},construct(s,a){KY(r);const[c,l]=Jmt(a);return nD(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:c},l).then(lC)}});return _to(i,t),i}function hto(t){return Array.prototype.concat.apply([],t)}function Jmt(t){const e=t.map(eq);return[e.map(n=>n[0]),hto(e.map(n=>n[1]))]}const Kmt=new WeakMap;function mto(t,e){return Kmt.set(t,e),t}function E5e(t){return Object.assign(t,{[$mt]:!0})}function eq(t){for(const[e,n]of Xmt)if(n.canHandle(t)){const[o,r]=n.serialize(t);return[{type:"HANDLER",name:e,value:o},r]}return[{type:"RAW",value:t},Kmt.get(t)||[]]}function lC(t){switch(t.type){case"HANDLER":return Xmt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function nD(t,e,n,o){return new Promise(r=>{const i=pto();e.set(i,r),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),o)})}function pto(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function D5e(t,e=""){const n=[];for(const o in t){if(!Object.prototype.hasOwnProperty.call(t,o))continue;const r=t[o],i=e?`${e}.${o}`:o;if(r!==null&&typeof r=="object"&&!Array.isArray(r)){const s=D5e(r,i);n.push(...s)}else n.push(i)}return n}function Qmt(t,e){const n=e.split(".");let o=t;for(const r of n)o=o[r];return o}var Zmt=async t=>{const e=globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER;if(e&&typeof e.kill=="function"){t.verbose&&console.log("[Worker] Killing previous global worker instance...");try{await e.kill()}catch(d){t.verbose&&console.warn("[Worker] Error killing previous global worker instance:",d),globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER===e&&(globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER=void 0)}}t.verbose&&console.log("[Worker] Creating circuit web worker with config:",t);let n=t.webWorkerBlobUrl??t.webWorkerUrl;if(!n){const d=`https://cdn.jsdelivr.net/npm/@tscircuit/eval@${t.evalVersion??"latest"}/dist/webworker/entrypoint.js`,m=await globalThis.fetch(d).then(h=>h.blob());n=URL.createObjectURL(m)}const o=new Worker(n,{type:"module"});let r;o.addEventListener("error",d=>{console.error("[Worker] Error in worker",d),r=d}),o.addEventListener("unhandledrejection",d=>{console.error("[Worker] Unhandled rejection in worker",d)}),o.addEventListener("messageerror",d=>{console.error("[Worker] Message error in worker",d)});const i=d=>{console.log("[Worker] Message in worker",d)};if(o.addEventListener("message",i),o.addEventListener("message",async d=>{const m=d.data;if(m?.type==="worker_fetch")try{const h=await globalThis.fetch(m.input,m.init),p=await h.text();o.postMessage({type:"worker_fetch_result",requestId:m.requestId,success:!0,response:{body:p,status:h.status,statusText:h.statusText,headers:(()=>{const x={};return h.headers.forEach((f,g)=>{x[g]=f}),x})()}})}catch(h){o.postMessage({type:"worker_fetch_result",requestId:m.requestId,success:!1,error:{name:h.name,message:h.message,stack:h.stack}})}}),r)throw r;const s=Ymt(o);o.removeEventListener("message",i);function a(d){return!d||typeof d!="object"?d:d.type&&d.props!==void 0?{__isSerializedReactElement:!0,type:d.type,props:c(d.props),key:d.key}:d}function c(d){if(!d||typeof d!="object")return d;const m={};for(const[h,p]of Object.entries(d))h==="children"?Array.isArray(p)?m.children=p.map(a):m.children=a(p):m[h]=p;return m}t.enableFetchProxy&&o.postMessage({type:"override_global_fetch"}),t.disableCdnLoading&&await s.setDisableCdnLoading(!0),t.snippetsApiBaseUrl&&await s.setSnippetsApiBaseUrl(t.snippetsApiBaseUrl),t.tscircuitSessionToken&&await s.setTscircuitSessionToken(t.tscircuitSessionToken),t.easyEdaProxyConfig&&await s.setEasyEdaProxyConfig(t.easyEdaProxyConfig);const l=d=>typeof d=="function"?E5e(d):d;if(t.platform)for(const d of D5e(t.platform))await s.setPlatformConfigProperty(d,l(Qmt(t.platform,d))).catch(m=>{throw new Error(`Error setting platform config property ${d}: ${m instanceof Error?m.message:String(m)}`)});if(t.projectConfig)for(const d of D5e(t.projectConfig))await s.setProjectConfigProperty(d,l(Qmt(t.projectConfig,d))).catch(m=>{throw new Error(`Error setting project config property ${d}: ${m instanceof Error?m.message:String(m)}`)});let u=!1;const _={clearEventListeners:s.clearEventListeners.bind(s),enableDebug:async(...d)=>{if(u)throw new Error("CircuitWebWorker was terminated, can't enableDebug");return s.enableDebug.bind(s)(...d)},version:s.version.bind(s),execute:async(...d)=>{if(u)throw new Error("CircuitWebWorker was terminated, can't execute");return s.execute.bind(s)(...d)},executeComponent:async d=>{if(u)throw new Error("CircuitWebWorker was terminated, can't executeComponent");if(typeof d=="function")return s.executeComponent.bind(s)(d);if(d&&typeof d=="object"&&d.type){const m=a(d);return s.executeComponent.bind(s)(m)}return s.executeComponent.bind(s)(d)},executeWithFsMap:async(...d)=>{if(u)throw new Error("CircuitWebWorker was terminated, can't executeWithFsMap");return s.executeWithFsMap.bind(s)(...d)},renderUntilSettled:s.renderUntilSettled.bind(s),getCircuitJson:s.getCircuitJson.bind(s),on:(d,m)=>{const h=E5e(m);s.on(d,h)},kill:async()=>{s[Wmt](),o.terminate(),u=!0,globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER===_&&(globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER=void 0)}};return _.__rawWorker=o,globalThis.TSCIRCUIT_GLOBAL_CIRCUIT_WORKER=_,_};const fto=({error:t,resetErrorBoundary:e})=>G.jsx("section",{className:"rf-h-full rf-w-full rf-grid rf-place-items-center",children:G.jsx("div",{className:"rf-min-h-full rf-flex rf-items-center rf-justify-center rf-px-4",children:G.jsxs("div",{className:"rf-max-w-lg rf-w-full rf-text-center",children:[G.jsxs("div",{className:"rf-mb-8",children:[G.jsx("div",{className:"rf-inline-flex rf-items-center rf-justify-center rf-w-20 rf-h-20 rf-bg-red-100 rf-rounded-full rf-mb-6",children:G.jsx(qDn,{className:"rf-w-10 rf-h-10 rf-text-red-600"})}),G.jsx("h1",{className:"rf-text-2xl rf-font-bold rf-text-gray-900 rf-mb-3",children:"Oops! Something went wrong"}),G.jsx("p",{className:"rf-text-gray-600 rf-mb-4",children:"RunFrame encountered an unexpected error."}),G.jsx("pre",{className:"rf-text-xs no-scrollbar rf-font-mono rf-text-left rf-whitespace-pre-wrap rf-text-red-600 rf-bg-red-50 rf-border rf-border-red-200 rf-p-3 rf-rounded-lg rf-mb-4 rf-overflow-auto rf-max-h-[120px]",children:t.message}),t.stack&&G.jsxs("details",{className:"rf-text-center rf-mb-6",children:[G.jsx("summary",{className:"rf-text-xs rf-text-gray-500 rf-cursor-pointer hover:rf-text-gray-700",children:"View stack trace"}),G.jsx("pre",{className:"rf-text-xs rf-font-mono no-scrollbar rf-whitespace-pre-wrap rf-text-gray-500 rf-bg-gray-100 rf-p-3 rf-rounded-lg rf-mt-2 rf-overflow-auto rf-text-left rf-max-h-[150px]",children:t.stack})]})]}),G.jsxs("div",{className:"rf-flex rf-flex-col rf-gap-2 rf-justify-center",children:[G.jsx(dc,{variant:"destructive",size:"lg",onClick:()=>window.location.reload(),children:"Refresh Dev Server"}),G.jsx(dc,{variant:"outline",size:"lg",onClick:e,children:"Try Again"})]})]})})}),ept=t=>{const e={};if(!t)return e;for(const o of Og)e[o]=0;const n=new Map;for(const o of t){const[,,r,i]=o.type.split(":");if(i==="start"){n.set(`${r}:${o.renderId}`,o);continue}if(i==="end"){const s=n.get(`${r}:${o.renderId}`);if(s){const a=o.createdAt-s.createdAt;e[r]=(e[r]||0)+a}}}return e},xto=(t,e)=>{const n={};for(const[o,r]of t.entries()){const i=e.get(o);i!==r&&(n[o]={old:r,new:i})}for(const[o,r]of e.entries())t.has(o)||(n[o]={old:void 0,new:r});return n};function gto(){const t=Y.useRef(Promise.resolve()),e=Y.useRef(!1),n=Y.useRef(null),o=Y.useCallback(async s=>{await t.current;const a={cancelled:!1};n.current=a;let c;const l=new Promise(u=>{c=u});try{return t.current=l,e.current=!0,await s()}catch(u){if(!a.cancelled)throw u}finally{e.current=!1,n.current=null,c()}},[]),r=Y.useCallback(()=>{n.current&&(n.current.cancelled=!0),t.current=Promise.resolve(),e.current=!1},[]),i=Y.useCallback(()=>e.current,[]);return{runWithMutex:o,isLocked:i,cancel:r}}const yto=({message:t="Loading files..."})=>G.jsxs("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full",children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4 rf-p-2 rf-border-b",children:[G.jsx("div",{className:"rf-w-20 rf-h-9 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded-md rf-animate-pulse"}),G.jsx("div",{className:"rf-flex rf-gap-6 rf-ml-auto",children:["PCB","Schematic","3D"].map((e,n)=>G.jsx("div",{className:"rf-h-6 rf-w-20 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded rf-animate-pulse"},n))})]}),G.jsx("div",{className:"rf-flex-1 rf-p-4",children:G.jsx("div",{className:"rf-w-full rf-h-full rf-rounded-lg rf-bg-gray-100 dark:rf-bg-gray-800 rf-animate-pulse rf-flex rf-items-center rf-justify-center",children:G.jsx("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4",children:G.jsx("div",{className:"rf-text-sm rf-text-gray-400 dark:rf-text-gray-500",children:t})})})})]}),tq=t=>{const e=t.toLowerCase(),n=e.split("/").pop();return e.endsWith(".circuit.json")||n==="circuit.json"},bto=t=>t.endsWith(".tsx")||tq(t)||t.endsWith(".jsx"),Pto=({mainComponentPath:t,fsMap:e})=>Y.useMemo(()=>{if(!(t!=null&&tq(t)))return{isStaticCircuitJson:!1,circuitJson:null,error:null};const o=e.get(t);if(!o)return{isStaticCircuitJson:!0,circuitJson:null,error:`Circuit JSON file not found: ${t}`};try{return{isStaticCircuitJson:!0,circuitJson:JSON.parse(o),error:null}}catch(r){return{isStaticCircuitJson:!0,circuitJson:null,error:`Failed to parse circuit.json: ${r instanceof Error?r.message:String(r)}`}}},[t,e]),vto=t=>!t||typeof t!="object"?!1:!!("error_type"in t||typeof t.type=="string"&&t.type.includes("error")),Sto=t=>t instanceof Error?{name:t.name,message:t.message,stack:t.stack}:typeof t=="string"?{message:t}:t&&typeof t=="object"?t:{message:String(t)},Cto=t=>Array.isArray(t)?t.filter(vto):[],A5e=({circuitJson:t,executionError:e})=>{const n=[];e&&n.push(Sto(e));const o=Cto(t);return n.push(...o),{hasExecutionError:!!e,...n.length>0?{errors:n}:{}}};var Mto=Symbol("radix.slottable");function Tto(t){const e=({children:n})=>G.jsx(G.Fragment,{children:n});return e.displayName=`${t}.Slottable`,e.__radixId=Mto,e}var wto=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Eto="VisuallyHidden",tpt=Y.forwardRef((t,e)=>G.jsx(Cc.span,{...t,ref:e,style:{...wto,...t.style}}));tpt.displayName=Eto;var Dto=tpt,[nq]=d4("Tooltip",[vE]),oq=vE(),npt="TooltipProvider",Ato=700,R5e="tooltip.open",[Rto,k5e]=nq(npt),opt=t=>{const{__scopeTooltip:e,delayDuration:n=Ato,skipDelayDuration:o=300,disableHoverableContent:r=!1,children:i}=t,s=Y.useRef(!0),a=Y.useRef(!1),c=Y.useRef(0);return Y.useEffect(()=>{const l=c.current;return()=>window.clearTimeout(l)},[]),G.jsx(Rto,{scope:e,isOpenDelayedRef:s,delayDuration:n,onOpen:Y.useCallback(()=>{window.clearTimeout(c.current),s.current=!1},[]),onClose:Y.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>s.current=!0,o)},[o]),isPointerInTransitRef:a,onPointerInTransitChange:Y.useCallback(l=>{a.current=l},[]),disableHoverableContent:r,children:i})};opt.displayName=npt;var PI="Tooltip",[kto,rq]=nq(PI),rpt=t=>{const{__scopeTooltip:e,children:n,open:o,defaultOpen:r,onOpenChange:i,disableHoverableContent:s,delayDuration:a}=t,c=k5e(PI,t.__scopeTooltip),l=oq(e),[u,_]=Y.useState(null),d=Jp(),m=Y.useRef(0),h=s??c.disableHoverableContent,p=a??c.delayDuration,x=Y.useRef(!1),[f,g]=DP({prop:o,defaultProp:r??!1,onChange:M=>{M?(c.onOpen(),document.dispatchEvent(new CustomEvent(R5e))):c.onClose(),i?.(M)},caller:PI}),y=Y.useMemo(()=>f?x.current?"delayed-open":"instant-open":"closed",[f]),b=Y.useCallback(()=>{window.clearTimeout(m.current),m.current=0,x.current=!1,g(!0)},[g]),v=Y.useCallback(()=>{window.clearTimeout(m.current),m.current=0,g(!1)},[g]),S=Y.useCallback(()=>{window.clearTimeout(m.current),m.current=window.setTimeout(()=>{x.current=!0,g(!0),m.current=0},p)},[p,g]);return Y.useEffect(()=>()=>{m.current&&(window.clearTimeout(m.current),m.current=0)},[]),G.jsx(Hj,{...l,children:G.jsx(kto,{scope:e,contentId:d,open:f,stateAttribute:y,trigger:u,onTriggerChange:_,onTriggerEnter:Y.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:Y.useCallback(()=>{h?v():(window.clearTimeout(m.current),m.current=0)},[v,h]),onOpen:b,onClose:v,disableHoverableContent:h,children:n})})};rpt.displayName=PI;var N5e="TooltipTrigger",ipt=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=rq(N5e,n),i=k5e(N5e,n),s=oq(n),a=Y.useRef(null),c=tu(e,a,r.onTriggerChange),l=Y.useRef(!1),u=Y.useRef(!1),_=Y.useCallback(()=>l.current=!1,[]);return Y.useEffect(()=>()=>document.removeEventListener("pointerup",_),[_]),G.jsx(Ij,{asChild:!0,...s,children:G.jsx(Cc.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...o,ref:c,onPointerMove:Vr(t.onPointerMove,d=>{d.pointerType!=="touch"&&!u.current&&!i.isPointerInTransitRef.current&&(r.onTriggerEnter(),u.current=!0)}),onPointerLeave:Vr(t.onPointerLeave,()=>{r.onTriggerLeave(),u.current=!1}),onPointerDown:Vr(t.onPointerDown,()=>{r.open&&r.onClose(),l.current=!0,document.addEventListener("pointerup",_,{once:!0})}),onFocus:Vr(t.onFocus,()=>{l.current||r.onOpen()}),onBlur:Vr(t.onBlur,r.onClose),onClick:Vr(t.onClick,r.onClose)})})});ipt.displayName=N5e;var Nto="TooltipPortal",[Rao,Hto]=nq(Nto,{forceMount:void 0}),oD="TooltipContent",spt=Y.forwardRef((t,e)=>{const n=Hto(oD,t.__scopeTooltip),{forceMount:o=n.forceMount,side:r="top",...i}=t,s=rq(oD,t.__scopeTooltip);return G.jsx(Fg,{present:o||s.open,children:s.disableHoverableContent?G.jsx(apt,{side:r,...i,ref:e}):G.jsx(Ito,{side:r,...i,ref:e})})}),Ito=Y.forwardRef((t,e)=>{const n=rq(oD,t.__scopeTooltip),o=k5e(oD,t.__scopeTooltip),r=Y.useRef(null),i=tu(e,r),[s,a]=Y.useState(null),{trigger:c,onClose:l}=n,u=r.current,{onPointerInTransitChange:_}=o,d=Y.useCallback(()=>{a(null),_(!1)},[_]),m=Y.useCallback((h,p)=>{const x=h.currentTarget,f={x:h.clientX,y:h.clientY},g=zto(f,x.getBoundingClientRect()),y=Vto(f,g),b=$to(p.getBoundingClientRect()),v=Uto([...y,...b]);a(v),_(!0)},[_]);return Y.useEffect(()=>()=>d(),[d]),Y.useEffect(()=>{if(c&&u){const h=x=>m(x,u),p=x=>m(x,c);return c.addEventListener("pointerleave",h),u.addEventListener("pointerleave",p),()=>{c.removeEventListener("pointerleave",h),u.removeEventListener("pointerleave",p)}}},[c,u,m,d]),Y.useEffect(()=>{if(s){const h=p=>{const x=p.target,f={x:p.clientX,y:p.clientY},g=c?.contains(x)||u?.contains(x),y=!Wto(f,s);g?d():y&&(d(),l())};return document.addEventListener("pointermove",h),()=>document.removeEventListener("pointermove",h)}},[c,u,s,l,d]),G.jsx(apt,{...t,ref:i})}),[Lto,Oto]=nq(PI,{isInside:!1}),Fto=Tto("TooltipContent"),apt=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,children:o,"aria-label":r,onEscapeKeyDown:i,onPointerDownOutside:s,...a}=t,c=rq(oD,n),l=oq(n),{onClose:u}=c;return Y.useEffect(()=>(document.addEventListener(R5e,u),()=>document.removeEventListener(R5e,u)),[u]),Y.useEffect(()=>{if(c.trigger){const _=d=>{d.target?.contains(c.trigger)&&u()};return window.addEventListener("scroll",_,{capture:!0}),()=>window.removeEventListener("scroll",_,{capture:!0})}},[c.trigger,u]),G.jsx(ZN,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:s,onFocusOutside:_=>_.preventDefault(),onDismiss:u,children:G.jsxs(X2e,{"data-state":c.stateAttribute,...l,...a,ref:e,style:{...a.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[G.jsx(Fto,{children:o}),G.jsx(Lto,{scope:n,isInside:!0,children:G.jsx(Dto,{id:c.contentId,role:"tooltip",children:r||o})})]})})});spt.displayName=oD;var cpt="TooltipArrow",Bto=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=oq(n);return Oto(cpt,n).isInside?null:G.jsx(j2e,{...r,...o,ref:e})});Bto.displayName=cpt;function zto(t,e){const n=Math.abs(e.top-t.y),o=Math.abs(e.bottom-t.y),r=Math.abs(e.right-t.x),i=Math.abs(e.left-t.x);switch(Math.min(n,o,r,i)){case i:return"left";case r:return"right";case n:return"top";case o:return"bottom";default:throw new Error("unreachable")}}function Vto(t,e,n=5){const o=[];switch(e){case"top":o.push({x:t.x-n,y:t.y+n},{x:t.x+n,y:t.y+n});break;case"bottom":o.push({x:t.x-n,y:t.y-n},{x:t.x+n,y:t.y-n});break;case"left":o.push({x:t.x+n,y:t.y-n},{x:t.x+n,y:t.y+n});break;case"right":o.push({x:t.x-n,y:t.y-n},{x:t.x-n,y:t.y+n});break}return o}function $to(t){const{top:e,right:n,bottom:o,left:r}=t;return[{x:r,y:e},{x:n,y:e},{x:n,y:o},{x:r,y:o}]}function Wto(t,e){const{x:n,y:o}=t;let r=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const a=e[i],c=e[s],l=a.x,u=a.y,_=c.x,d=c.y;u>o!=d>o&&n<(_-l)*(o-u)/(d-u)+l&&(r=!r)}return r}function Uto(t){const e=t.slice();return e.sort((n,o)=>n.x<o.x?-1:n.x>o.x?1:n.y<o.y?-1:n.y>o.y?1:0),Xto(e)}function Xto(t){if(t.length<=1)return t.slice();const e=[];for(let o=0;o<t.length;o++){const r=t[o];for(;e.length>=2;){const i=e[e.length-1],s=e[e.length-2];if((i.x-s.x)*(r.y-s.y)>=(i.y-s.y)*(r.x-s.x))e.pop();else break}e.push(r)}e.pop();const n=[];for(let o=t.length-1;o>=0;o--){const r=t[o];for(;n.length>=2;){const i=n[n.length-1],s=n[n.length-2];if((i.x-s.x)*(r.y-s.y)>=(i.y-s.y)*(r.x-s.x))n.pop();else break}n.push(r)}return n.pop(),e.length===1&&n.length===1&&e[0].x===n[0].x&&e[0].y===n[0].y?e:e.concat(n)}var jto=opt,Gto=rpt,Yto=ipt,lpt=spt;const upt=jto,_pt=Gto,dpt=Yto,H5e=Y.forwardRef(({className:t,sideOffset:e=4,...n},o)=>G.jsx(lpt,{ref:o,sideOffset:e,className:lr("z-50 overflow-hidden rounded-md bg-slate-900 px-3 py-1.5 text-xs text-slate-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-slate-50 dark:text-slate-900",t),...n}));H5e.displayName=lpt.displayName;const qto=26,Ux=Za("run-frame:RunFrame"),Jto=async()=>{try{const t=await fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval");if(t.ok)return(await t.json()).tags?.latest}catch(t){console.error("Failed to fetch latest eval version",t)}},hpt=async(t,e)=>{if(t)return t;if(e||!window.TSCIRCUIT_LATEST_EVAL_VERSION){const n=await Jto();if(n)return window.TSCIRCUIT_LATEST_EVAL_VERSION=n,n}return window.TSCIRCUIT_LATEST_EVAL_VERSION?window.TSCIRCUIT_LATEST_EVAL_VERSION:"latest"},mpt=t=>{xY();const e=eu(pe=>pe.circuitJson),n=eu(pe=>pe.setCircuitJson),[o,r]=Y.useState(null),i=Y.useRef(null),[s,a]=Y.useState(null),[c,l]=Y.useReducer((pe,Me)=>pe+1,0),u=bY(pe=>pe.setLastRunEvalVersion),_=Y.useRef(0),d=gto(),[m,h]=Y.useState(!1),[p,x]=Y.useState(!1),[f,g]=Y.useState({}),[y,b]=Y.useState(""),[v,S]=Y.useState(!1),[M,w]=Y.useState(!1),D=Object.values(f).sort((pe,Me)=>pe.startTime-Me.startTime)[0]?.effectName,A=pe=>{t.onRunCompleted?.(pe)};Y.useEffect(()=>{const pe=Me=>{(Me.ctrlKey||Me.metaKey)&&Me.key==="Enter"&&!m&&l(1)};return window.addEventListener("keydown",pe),()=>window.removeEventListener("keydown",pe)},[m]),Y.useEffect(()=>{let pe=!1;return(async()=>{try{if(!globalThis.runFrameWorker){const xe=await hpt(t.evalVersion,t.forceLatestEvalVersion),We=await Zmt({evalVersion:xe,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${Ax}/files/static`},...t.platformConfig&&{platformConfig:t.platformConfig},verbose:!0,...t.enableFetchProxy&&{enableFetchProxy:t.enableFetchProxy},...window.TSCIRCUIT_USE_RUNFRAME_FOR_CLI&&{disableCdnLoading:!0},...t.tscircuitSessionToken&&{tscircuitSessionToken:t.tscircuitSessionToken}});if(pe)return;globalThis.runFrameWorker=We,u(xe)}pe||x(!0)}catch(xe){console.error("Failed to preload eval worker",xe)}})(),()=>{pe=!0}},[t.evalVersion,t.evalWebWorkerBlobUrl,t.forceLatestEvalVersion,t.tscircuitSessionToken]);const[I,H]=Y.useState(null),[O,z]=Y.useState({}),[V,j]=Y.useState([]),[q,K]=Y.useState(t.defaultActiveTab??t.defaultTab??"pcb");Y.useEffect(()=>{t.debug&&Za.enable("run-frame*")},[t.debug]);const ne=t.fsMap instanceof Map?t.fsMap:Object.entries(t.fsMap??{}).reduce((pe,[Me,xe])=>pe.set(Me,xe),new Map),ce=Y.useRef(null),ee=Y.useRef(null),{isStaticCircuitJson:oe,circuitJson:ie,error:ae}=Pto({mainComponentPath:t.mainComponentPath,fsMap:ne});Y.useEffect(()=>{oe&&(ie?(n(ie),r(null)):ae&&r({error:ae,stack:""}))},[oe,ie,ae]),Y.useEffect(()=>{if(t.isLoadingFiles||oe)return;const pe=ne instanceof Map?Object.fromEntries(ne.entries()):ne;if(!pe||Object.keys(pe).length===0){r({error:"No files provided. Please provide at least one file with code to execute.",stack:""}),h(!1);return}const Me=c!==_.current;if(ce.current&&e){const We=xto(ce.current,ne);if(Object.keys(We).length>0)Ux("code changes detected");else if(ee.current!==t.entrypoint)Ux("render triggered by entrypoint change");else if(!Me){Ux("render triggered without changes to fsMap, skipping");return}}if(t.showRunButton&&c===_.current)return;ce.current=ne,ee.current=t.entrypoint??null,_.current=c,h(!0);const xe=async()=>{Ux("running render worker"),r(null),H(null),g({}),j([]);const We={progress:0,debugOutputs:[]};let Xe=!1;i.current=()=>{Xe=!0};const Je=await hpt(t.evalVersion,!globalThis.runFrameWorker&&t.forceLatestEvalVersion);Ux("resolvedEvalVersion",Je);const fe=globalThis.runFrameWorker??await Zmt({evalVersion:Je,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,verbose:!0,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${Ax}/files/static`},...t.platformConfig&&{platformConfig:t.platformConfig},...t.enableFetchProxy&&{enableFetchProxy:t.enableFetchProxy},...window.TSCIRCUIT_USE_RUNFRAME_FOR_CLI&&{disableCdnLoading:!0},...t.tscircuitSessionToken&&{tscircuitSessionToken:t.tscircuitSessionToken}});globalThis.runFrameWorker=fe,u(Je),y?.trim()&&fe.enableDebug(y.replace("DEBUG=","")),Ux("Starting render..."),t.onRenderStarted?.();const Ye=ne instanceof Map?Object.fromEntries(ne.entries()):ne;let Oe=Date.now();fe.on("asyncEffect:start",Pe=>{const Ee=`${Pe.phase}|${Pe.componentDisplayName??""}|${Pe.effectName}`;g(we=>({...we,[Ee]:{...Pe,startTime:Date.now()}}))}),fe.on("asyncEffect:end",Pe=>{const Ee=`${Pe.phase}|${Pe.componentDisplayName??""}|${Pe.effectName}`;g(we=>{const{[Ee]:ze,...Ue}=we;return Ue})}),fe.on("autorouting:start",Pe=>{z({...O,[Pe.componentDisplayName]:{simpleRouteJson:Pe.simpleRouteJson,createdAt:Date.now()}})}),fe.on("solver:started",Pe=>{Ux("solver:started",Pe),j(Ee=>{const we=`${Pe.componentName}-${Pe.solverName}`;return Ee.some(Ue=>`${Ue.componentName}-${Ue.solverName}`===we)?Ee:[...Ee,Pe]})}),fe.on("board:renderPhaseStarted",Pe=>{We.lastRenderEvent=Pe,We.eventsProcessed=(We.eventsProcessed??0)+1;const Ee=Og.indexOf(Pe.phase)/qto*.75+We.eventsProcessed/1e3*.25,we=1-Math.exp(-Ee*3);We.progress=we,Xe||H({...We})}),q==="render_log"&&fe.on("renderable:renderLifecycle:anyEvent",Pe=>{We.renderEvents=We.renderEvents??[],Pe.createdAt=Date.now(),We.renderEvents.push(Pe),Date.now()-Oe>500&&(We.phaseTimings=ept(We.renderEvents??[]),Oe=Date.now()),Xe||H({...We})}),fe.on("autorouting:progress",Pe=>{a(Pe.debugGraphics)}),fe.on("debug:logOutput",Pe=>{We.debugOutputs=We.debugOutputs??[],We.debugOutputs.push({type:"debug",name:Pe.name,content:Pe.content}),Xe||H({...We})}),Ux("Executing fsMap...");const Ne=await fe.executeWithFsMap({entrypoint:t.entrypoint,fsMap:Ye,...t.mainComponentPath?{mainComponentPath:t.mainComponentPath}:{}}).then(()=>({success:!0})).catch(Pe=>{const Ee=Pe.message.replace("Error: ","");return Ux(`eval error: ${Ee}`),t.onError?.(Pe),A(A5e({executionError:Pe})),r({error:Ee,stack:Pe.stack}),H(null),console.error(Pe),{success:!1}});if(Ux("worker call started"),!Ne.success){h(!1),g({});return}const Ve=fe.renderUntilSettled();Ux("waiting for initial circuit json...");let Re=await fe.getCircuitJson().catch(Pe=>(Ux("error getting initial circuit json",Pe),t.onError?.(Pe),A(A5e({executionError:Pe})),r({error:Pe.message,stack:Pe.stack}),H(null),h(!1),g({}),null));Re&&(Ux("got initial circuit json"),n(Re),t.onCircuitJsonChange?.(Re),t.onInitialRender?.({circuitJson:Re}),await Ve,Ux("getting final circuit json"),Re=await fe.getCircuitJson(),t.onCircuitJsonChange?.(Re),n(Re),A(A5e({circuitJson:Re})),t.onRenderFinished?.({circuitJson:Re}),a({}),q==="render_log"&&(We.phaseTimings=ept(We.renderEvents??[])),We.progress=1,Xe||H({...We}),h(!1),g({}),b(""),i.current=null)};d.runWithMutex(xe)},[t.fsMap,t.entrypoint,c,t.evalVersion,t.mainComponentPath,t.isLoadingFiles,y,oe]);const de=Y.useRef(null),be=Y.useRef(null),Ce=pe=>{if(!pe||pe===null){console.warn("[RunFrame] handleEditEvent received null or undefined event.");return}pe.in_progress?(de.current=pe,be.current&&(clearTimeout(be.current),be.current=null)):(be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{const Me=pe||de.current;t.onEditEvent?.(Me),de.current=null,be.current=null},100))},De=async(pe,Me)=>{let xe="";const We=Array.isArray(e)&&e.find(fe=>fe.type==="software_project_metadata"),Xe=t.projectUrl??We?.project_url;if(Xe)try{xe=new URL(Xe).pathname}catch{xe=Xe}const Je=xe?`${xe} - ${pe}`:pe;await hI.post("autorouting/bug_reports/create",{json:{title:Je,simple_route_json:Me.simpleRouteJson}}).json().then(({autorouting_bug_report:fe})=>{window.open(`https://api.tscircuit.com/autorouting/bug_reports/view?autorouting_bug_report_id=${fe.autorouting_bug_report_id}`,"_blank")}).catch(fe=>{if(console.error("Failed to report autorouting bug",fe),fe instanceof Uv&&fe.response?.status===401){t.onLoginRequired?t.onLoginRequired():alert("You must be logged in to report autorouting bugs");return}const Oe=fe instanceof Error?fe.message:"Failed to report autorouting bug";alert(`Failed to report autorouting bug: ${Oe}`)})};return t.isLoadingFiles?G.jsx(yto,{}):G.jsx(M5,{FallbackComponent:fto,children:G.jsx(Vmt,{code:ne.get(t.entrypoint??t.mainComponentPath),fsMap:ne,defaultActiveTab:t.defaultActiveTab??t.defaultTab,defaultTab:t.defaultTab,availableTabs:t.availableTabs,showToggleFullScreen:t.showToggleFullScreen,autoroutingGraphics:s,autoroutingLog:O,onReportAutoroutingLog:t.onReportAutoroutingLog||De,leftHeaderContent:G.jsxs(G.Fragment,{children:[t.showRunButton&&G.jsx(upt,{children:G.jsxs(_pt,{children:[G.jsx(dpt,{asChild:!0,children:G.jsxs("div",{className:"rf-relative rf-inline-flex",children:[G.jsxs("button",{type:"button",onClick:()=>{l(1)},className:"rf-flex rf-items-center rf-gap-2 rf-px-4 rf-py-2 rf-bg-blue-600 hover:rf-bg-blue-700 rf-text-white rf-rounded-md disabled:rf-opacity-50 transition-colors duration-200",disabled:m||!p,children:["Run"," ",m||!p?G.jsx($9,{className:"rf-w-3 rf-h-3 rf-animate-spin"}):G.jsx(aot,{className:"rf-w-3 rf-h-3"})]}),m&&G.jsx("div",{className:"rf-flex rf-items-center rf-ml-1",children:G.jsx(dc,{onClick:pe=>{pe.stopPropagation(),h(!1),H(null),r(null),i.current&&(i.current(),i.current=null),d.cancel(),g({}),globalThis.runFrameWorker&&(globalThis.runFrameWorker.kill(),globalThis.runFrameWorker=null)},variant:"ghost",size:"icon",className:"rf-text-red-300 hover:rf-text-red-400 hover:!rf-bg-transparent [&>svg]:rf-text-red-300 [&>svg]:hover:rf-text-red-400 rf-flex rf-items-center rf-justify-center",children:G.jsx(YDn,{className:"!rf-h-2.5 !rf-w-2.5",fill:"currentColor",stroke:"currentColor"})})})]})}),G.jsx(H5e,{sideOffset:8,className:"rf-p-0 rf-bg-transparent rf-border-none rf-shadow-none rf-pointer-events-none",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-px-2.5 rf-py-1.5 rf-bg-slate-900 rf-rounded-md rf-shadow-xl rf-border rf-border-slate-800/60",children:[G.jsx("kbd",{className:"rf-bg-slate-800 rf-px-1.5 rf-py-0.5 rf-rounded rf-text-[10px] rf-font-sans rf-font-medium rf-border rf-border-slate-700 rf-text-slate-200 rf-leading-none",children:"Ctrl"}),G.jsx("span",{className:"rf-text-slate-500 rf-text-[11px] rf-font-medium rf-leading-none",children:"+"}),G.jsx("kbd",{className:"rf-bg-slate-800 rf-px-1.5 rf-py-0.5 rf-rounded rf-text-[10px] rf-font-sans rf-font-medium rf-border rf-border-slate-700 rf-text-slate-200 rf-leading-none",children:"Enter"})]})})]})}),t.showFileMenu!==!1&&G.jsx(bI,{isWebEmbedded:t.isWebEmbedded,onLoginRequired:t.onLoginRequired,showSchematicDebugGrid:v,onChangeShowSchematicDebugGrid:S,showSchematicPorts:M,onChangeShowSchematicPorts:w,autoroutingLog:O,onReportAutoroutingLog:t.onReportAutoroutingLog||De}),t.leftHeaderContent]}),onActiveTabChange:K,circuitJson:e,renderLog:I,activeEffectName:D,isRunningCode:m,errorMessage:o?.error,errorStack:o?.stack,onEditEvent:Ce,editEvents:t.editEvents,defaultToFullScreen:t.defaultToFullScreen,onRerunWithDebug:pe=>{b(pe||""),l(1)},solverEvents:V,showSchematicDebugGrid:v,showSchematicPorts:M,onChangeShowSchematicDebugGrid:S,onChangeShowSchematicPorts:w})})},Kto=t=>new Promise(e=>setTimeout(e,t)),Qto=({isOpen:t,onClose:e,onLoginSuccess:n})=>{const[o,r]=Y.useState("idle"),[i,s]=Y.useState(null),[a,c]=Y.useState(null),l=eu(p=>p.pushEvent),u=Y.useRef(null);Y.useEffect(()=>()=>{u.current&&u.current.abort()},[]);const _=Y.useCallback(async()=>{r("creating"),c(null),u.current=new AbortController;try{const p=Xv(),{login_page:x}=await p.post("sessions/login_page/create",{json:{},signal:u.current?.signal}).json();s(x.url),r("waiting");const f=new URL(x.url);for(f.searchParams.set("autoclose","true"),window.open(f.toString(),"_blank");!u.current?.signal.aborted;){const{login_page:y}=await p.post("sessions/login_page/get",{json:{login_page_id:x.login_page_id},headers:{Authorization:`Bearer ${x.login_page_auth_token}`},signal:u.current?.signal}).json();if(y.was_login_successful){r("exchanging");break}if(y.is_expired)throw new Error("Login page expired. Please try again.");await Kto(1e3)}if(u.current?.signal.aborted){r("idle");return}const{session:g}=await p.post("sessions/login_page/exchange_for_cli_session",{json:{login_page_id:x.login_page_id},headers:{Authorization:`Bearer ${x.login_page_auth_token}`},signal:u.current?.signal}).json();typeof window<"u"&&(window.TSCIRCUIT_REGISTRY_TOKEN=g.token),await l({event_type:"TOKEN_UPDATED",registry_token:g.token}),r("success"),ds.success("Successfully logged in!"),n?.(),setTimeout(()=>{e(),r("idle"),s(null)},1e3)}catch(p){if(p instanceof DOMException&&p.name==="AbortError"){r("idle");return}console.error("Login error:",p);const x=p instanceof Error?p.message:"Failed to complete login";c(x),r("error"),ds.error(x)}},[l,n,e]),d=Y.useCallback(()=>{u.current&&u.current.abort(),r("idle"),s(null),c(null),e()},[e]),m=o==="creating"||o==="waiting"||o==="exchanging",h=()=>{switch(o){case"creating":return"Creating login page...";case"waiting":return"Waiting for you to complete login in the browser...";case"exchanging":return"Generating token...";case"success":return"Successfully logged in!";case"error":return a||"An error occurred";default:return null}};return G.jsx(QE,{open:t,onOpenChange:p=>!p&&!m&&d(),children:G.jsxs(eC,{className:"rf-max-w-md",children:[G.jsxs(tC,{children:[G.jsx(nC,{children:"Sign In Required"}),G.jsx(ZE,{children:o==="idle"||o==="error"?"Sign in to continue. A new browser window will open for authentication.":"Complete the login process in the opened browser window."})]}),G.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4 rf-py-4",children:[o==="idle"||o==="error"?G.jsx(dc,{onClick:_,className:"rf-w-full",children:"Sign In"}):G.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-3 rf-w-full",children:[o!=="success"&&G.jsx("div",{className:"rf-animate-spin rf-w-6 rf-h-6 rf-border-2 rf-border-gray-300 rf-border-t-blue-600 rf-rounded-full"}),G.jsx("p",{className:"rf-text-sm rf-text-gray-600 rf-text-center",children:h()}),i&&o==="waiting"&&G.jsx("a",{href:i,target:"_blank",rel:"noreferrer",className:"rf-text-xs rf-text-blue-600 hover:rf-underline",children:"Click here if the window didn't open"})]}),a&&o==="error"&&G.jsx("p",{className:"rf-text-sm rf-text-red-600 rf-text-center",children:a}),m&&G.jsx(dc,{variant:"outline",onClick:d,className:"rf-w-full",children:"Cancel"})]})]})})},Zto=()=>{const[t,e]=Y.useState(!1),n=Y.useCallback(()=>{e(!0)},[]),o=Y.useCallback(()=>{e(!1)},[]),r=Y.useCallback(()=>{e(!1)},[]);return{LoginDialog:G.jsx(Qto,{isOpen:t,onClose:o,onLoginSuccess:r}),openLoginDialog:n}},eno=t=>{const[e,n]=RT("load-latest-eval",!0),[o]=Y.useState(()=>typeof window>"u"?void 0:new URLSearchParams(window.location.hash.slice(1)).get("main_component")??void 0),r=Y.useCallback(a=>{if(typeof window>"u")return;const c=new URLSearchParams(window.location.hash.slice(1));if(c.get("main_component")===a)return;c.set("main_component",a);const l=c.toString(),u=`${window.location.pathname}${window.location.search}`+(l.length>0?`#${l}`:"");window.history.replaceState(null,"",u)},[]),{LoginDialog:i,openLoginDialog:s}=Zto();return G.jsxs(G.Fragment,{children:[i,G.jsx(uft,{debug:t.debug,forceLatestEvalVersion:!t.workerBlobUrl&&e,defaultToFullScreen:!0,showToggleFullScreen:!1,workerBlobUrl:t.workerBlobUrl,showFilesSwitch:!0,showFileMenu:!1,enableFetchProxy:t.enableFetchProxy,initialMainComponentPath:o,onLoginRequired:s,onMainComponentPathChange:r,leftHeaderContent:G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between",children:[G.jsx(bI,{isWebEmbedded:!1,shouldLoadLatestEval:!t.workerBlobUrl&&e,onChangeShouldLoadLatestEval:a=>{n(a),globalThis.runFrameWorker=null},onLoginRequired:s}),t.scenarioSelectorContent]})})]})};Za("run-frame:ImportComponentDialog");var ppt=1,tno=.9,nno=.8,ono=.17,I5e=.1,L5e=.999,rno=.9999,ino=.99,sno=/[\\\/_+.#"@\[\(\{&]/,ano=/[\\\/_+.#"@\[\(\{&]/g,cno=/[\s-]/,fpt=/[\s-]/g;function O5e(t,e,n,o,r,i,s){if(i===e.length)return r===t.length?ppt:ino;var a=`${r},${i}`;if(s[a]!==void 0)return s[a];for(var c=o.charAt(i),l=n.indexOf(c,r),u=0,_,d,m,h;l>=0;)_=O5e(t,e,n,o,l+1,i+1,s),_>u&&(l===r?_*=ppt:sno.test(t.charAt(l-1))?(_*=nno,m=t.slice(r,l-1).match(ano),m&&r>0&&(_*=Math.pow(L5e,m.length))):cno.test(t.charAt(l-1))?(_*=tno,h=t.slice(r,l-1).match(fpt),h&&r>0&&(_*=Math.pow(L5e,h.length))):(_*=ono,r>0&&(_*=Math.pow(L5e,l-r))),t.charAt(l)!==e.charAt(i)&&(_*=rno)),(_<I5e&&n.charAt(l-1)===o.charAt(i+1)||o.charAt(i+1)===o.charAt(i)&&n.charAt(l-1)!==o.charAt(i))&&(d=O5e(t,e,n,o,l+1,i+2,s),d*I5e>_&&(_=d*I5e)),_>u&&(u=_),l=n.indexOf(c,l+1);return s[a]=u,u}function xpt(t){return t.toLowerCase().replace(fpt," ")}function lno(t,e,n){return t=n&&n.length>0?`${t+" "+n.join(" ")}`:t,O5e(t,e,xpt(t),xpt(e),0,0,{})}var uno=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Gv=uno.reduce((t,e)=>{const n=tot(`Primitive.${e}`),o=Y.forwardRef((r,i)=>{const{asChild:s,...a}=r,c=s?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),G.jsx(c,{...a,ref:i})});return o.displayName=`Primitive.${e}`,{...t,[e]:o}},{}),vI='[cmdk-group=""]',F5e='[cmdk-group-items=""]',_no='[cmdk-group-heading=""]',gpt='[cmdk-item=""]',ypt=`${gpt}:not([aria-disabled="true"])`,B5e="cmdk-item-select",rD="data-value",dno=(t,e,n)=>lno(t,e,n),bpt=Y.createContext(void 0),SI=()=>Y.useContext(bpt),Ppt=Y.createContext(void 0),z5e=()=>Y.useContext(Ppt),vpt=Y.createContext(void 0),Spt=Y.forwardRef((t,e)=>{let n=iD(()=>{var oe,ie;return{search:"",value:(ie=(oe=t.value)!=null?oe:t.defaultValue)!=null?ie:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),o=iD(()=>new Set),r=iD(()=>new Map),i=iD(()=>new Map),s=iD(()=>new Set),a=Cpt(t),{label:c,children:l,value:u,onValueChange:_,filter:d,shouldFilter:m,loop:h,disablePointerSelection:p=!1,vimBindings:x=!0,...f}=t,g=Jp(),y=Jp(),b=Jp(),v=Y.useRef(null),S=Sno();uC(()=>{if(u!==void 0){let oe=u.trim();n.current.value=oe,M.emit()}},[u]),uC(()=>{S(6,O)},[]);let M=Y.useMemo(()=>({subscribe:oe=>(s.current.add(oe),()=>s.current.delete(oe)),snapshot:()=>n.current,setState:(oe,ie,ae)=>{var de,be,Ce,De;if(!Object.is(n.current[oe],ie)){if(n.current[oe]=ie,oe==="search")H(),A(),S(1,I);else if(oe==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let pe=document.getElementById(b);pe?pe.focus():(de=document.getElementById(g))==null||de.focus()}if(S(7,()=>{var pe;n.current.selectedItemId=(pe=z())==null?void 0:pe.id,M.emit()}),ae||S(5,O),((be=a.current)==null?void 0:be.value)!==void 0){let pe=ie??"";(De=(Ce=a.current).onValueChange)==null||De.call(Ce,pe);return}}M.emit()}},emit:()=>{s.current.forEach(oe=>oe())}}),[]),w=Y.useMemo(()=>({value:(oe,ie,ae)=>{var de;ie!==((de=i.current.get(oe))==null?void 0:de.value)&&(i.current.set(oe,{value:ie,keywords:ae}),n.current.filtered.items.set(oe,D(ie,ae)),S(2,()=>{A(),M.emit()}))},item:(oe,ie)=>(o.current.add(oe),ie&&(r.current.has(ie)?r.current.get(ie).add(oe):r.current.set(ie,new Set([oe]))),S(3,()=>{H(),A(),n.current.value||I(),M.emit()}),()=>{i.current.delete(oe),o.current.delete(oe),n.current.filtered.items.delete(oe);let ae=z();S(4,()=>{H(),ae?.getAttribute("id")===oe&&I(),M.emit()})}),group:oe=>(r.current.has(oe)||r.current.set(oe,new Set),()=>{i.current.delete(oe),r.current.delete(oe)}),filter:()=>a.current.shouldFilter,label:c||t["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:g,inputId:b,labelId:y,listInnerRef:v}),[]);function D(oe,ie){var ae,de;let be=(de=(ae=a.current)==null?void 0:ae.filter)!=null?de:dno;return oe?be(oe,n.current.search,ie):0}function A(){if(!n.current.search||a.current.shouldFilter===!1)return;let oe=n.current.filtered.items,ie=[];n.current.filtered.groups.forEach(de=>{let be=r.current.get(de),Ce=0;be.forEach(De=>{let pe=oe.get(De);Ce=Math.max(pe,Ce)}),ie.push([de,Ce])});let ae=v.current;V().sort((de,be)=>{var Ce,De;let pe=de.getAttribute("id"),Me=be.getAttribute("id");return((Ce=oe.get(Me))!=null?Ce:0)-((De=oe.get(pe))!=null?De:0)}).forEach(de=>{let be=de.closest(F5e);be?be.appendChild(de.parentElement===be?de:de.closest(`${F5e} > *`)):ae.appendChild(de.parentElement===ae?de:de.closest(`${F5e} > *`))}),ie.sort((de,be)=>be[1]-de[1]).forEach(de=>{var be;let Ce=(be=v.current)==null?void 0:be.querySelector(`${vI}[${rD}="${encodeURIComponent(de[0])}"]`);Ce?.parentElement.appendChild(Ce)})}function I(){let oe=V().find(ae=>ae.getAttribute("aria-disabled")!=="true"),ie=oe?.getAttribute(rD);M.setState("value",ie||void 0)}function H(){var oe,ie,ae,de;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=o.current.size;return}n.current.filtered.groups=new Set;let be=0;for(let Ce of o.current){let De=(ie=(oe=i.current.get(Ce))==null?void 0:oe.value)!=null?ie:"",pe=(de=(ae=i.current.get(Ce))==null?void 0:ae.keywords)!=null?de:[],Me=D(De,pe);n.current.filtered.items.set(Ce,Me),Me>0&&be++}for(let[Ce,De]of r.current)for(let pe of De)if(n.current.filtered.items.get(pe)>0){n.current.filtered.groups.add(Ce);break}n.current.filtered.count=be}function O(){var oe,ie,ae;let de=z();de&&(((oe=de.parentElement)==null?void 0:oe.firstChild)===de&&((ae=(ie=de.closest(vI))==null?void 0:ie.querySelector(_no))==null||ae.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function z(){var oe;return(oe=v.current)==null?void 0:oe.querySelector(`${gpt}[aria-selected="true"]`)}function V(){var oe;return Array.from(((oe=v.current)==null?void 0:oe.querySelectorAll(ypt))||[])}function j(oe){let ie=V()[oe];ie&&M.setState("value",ie.getAttribute(rD))}function q(oe){var ie;let ae=z(),de=V(),be=de.findIndex(De=>De===ae),Ce=de[be+oe];(ie=a.current)!=null&&ie.loop&&(Ce=be+oe<0?de[de.length-1]:be+oe===de.length?de[0]:de[be+oe]),Ce&&M.setState("value",Ce.getAttribute(rD))}function K(oe){let ie=z(),ae=ie?.closest(vI),de;for(;ae&&!de;)ae=oe>0?Pno(ae,vI):vno(ae,vI),de=ae?.querySelector(ypt);de?M.setState("value",de.getAttribute(rD)):q(oe)}let ne=()=>j(V().length-1),ce=oe=>{oe.preventDefault(),oe.metaKey?ne():oe.altKey?K(1):q(1)},ee=oe=>{oe.preventDefault(),oe.metaKey?j(0):oe.altKey?K(-1):q(-1)};return Y.createElement(Gv.div,{ref:e,tabIndex:-1,...f,"cmdk-root":"",onKeyDown:oe=>{var ie;(ie=f.onKeyDown)==null||ie.call(f,oe);let ae=oe.nativeEvent.isComposing||oe.keyCode===229;if(!(oe.defaultPrevented||ae))switch(oe.key){case"n":case"j":{x&&oe.ctrlKey&&ce(oe);break}case"ArrowDown":{ce(oe);break}case"p":case"k":{x&&oe.ctrlKey&&ee(oe);break}case"ArrowUp":{ee(oe);break}case"Home":{oe.preventDefault(),j(0);break}case"End":{oe.preventDefault(),ne();break}case"Enter":{oe.preventDefault();let de=z();if(de){let be=new Event(B5e);de.dispatchEvent(be)}}}}},Y.createElement("label",{"cmdk-label":"",htmlFor:w.inputId,id:w.labelId,style:Mno},c),iq(t,oe=>Y.createElement(Ppt.Provider,{value:M},Y.createElement(bpt.Provider,{value:w},oe))))}),hno=Y.forwardRef((t,e)=>{var n,o;let r=Jp(),i=Y.useRef(null),s=Y.useContext(vpt),a=SI(),c=Cpt(t),l=(o=(n=c.current)==null?void 0:n.forceMount)!=null?o:s?.forceMount;uC(()=>{if(!l)return a.item(r,s?.id)},[l]);let u=Mpt(r,i,[t.value,t.children,i],t.keywords),_=z5e(),d=Yv(S=>S.value&&S.value===u.current),m=Yv(S=>l||a.filter()===!1?!0:S.search?S.filtered.items.get(r)>0:!0);Y.useEffect(()=>{let S=i.current;if(!(!S||t.disabled))return S.addEventListener(B5e,h),()=>S.removeEventListener(B5e,h)},[m,t.onSelect,t.disabled]);function h(){var S,M;p(),(M=(S=c.current).onSelect)==null||M.call(S,u.current)}function p(){_.setState("value",u.current,!0)}if(!m)return null;let{disabled:x,value:f,onSelect:g,forceMount:y,keywords:b,...v}=t;return Y.createElement(Gv.div,{ref:Rx(i,e),...v,id:r,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!d,"data-disabled":!!x,"data-selected":!!d,onPointerMove:x||a.getDisablePointerSelection()?void 0:p,onClick:x?void 0:h},t.children)}),mno=Y.forwardRef((t,e)=>{let{heading:n,children:o,forceMount:r,...i}=t,s=Jp(),a=Y.useRef(null),c=Y.useRef(null),l=Jp(),u=SI(),_=Yv(m=>r||u.filter()===!1?!0:m.search?m.filtered.groups.has(s):!0);uC(()=>u.group(s),[]),Mpt(s,a,[t.value,t.heading,c]);let d=Y.useMemo(()=>({id:s,forceMount:r}),[r]);return Y.createElement(Gv.div,{ref:Rx(a,e),...i,"cmdk-group":"",role:"presentation",hidden:_?void 0:!0},n&&Y.createElement("div",{ref:c,"cmdk-group-heading":"","aria-hidden":!0,id:l},n),iq(t,m=>Y.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?l:void 0},Y.createElement(vpt.Provider,{value:d},m))))}),pno=Y.forwardRef((t,e)=>{let{alwaysRender:n,...o}=t,r=Y.useRef(null),i=Yv(s=>!s.search);return!n&&!i?null:Y.createElement(Gv.div,{ref:Rx(r,e),...o,"cmdk-separator":"",role:"separator"})}),fno=Y.forwardRef((t,e)=>{let{onValueChange:n,...o}=t,r=t.value!=null,i=z5e(),s=Yv(l=>l.search),a=Yv(l=>l.selectedItemId),c=SI();return Y.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),Y.createElement(Gv.input,{ref:e,...o,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":a,id:c.inputId,type:"text",value:r?t.value:s,onChange:l=>{r||i.setState("search",l.target.value),n?.(l.target.value)}})}),xno=Y.forwardRef((t,e)=>{let{children:n,label:o="Suggestions",...r}=t,i=Y.useRef(null),s=Y.useRef(null),a=Yv(l=>l.selectedItemId),c=SI();return Y.useEffect(()=>{if(s.current&&i.current){let l=s.current,u=i.current,_,d=new ResizeObserver(()=>{_=requestAnimationFrame(()=>{let m=l.offsetHeight;u.style.setProperty("--cmdk-list-height",m.toFixed(1)+"px")})});return d.observe(l),()=>{cancelAnimationFrame(_),d.unobserve(l)}}},[]),Y.createElement(Gv.div,{ref:Rx(i,e),...r,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":o,id:c.listId},iq(t,l=>Y.createElement("div",{ref:Rx(s,c.listInnerRef),"cmdk-list-sizer":""},l)))}),gno=Y.forwardRef((t,e)=>{let{open:n,onOpenChange:o,overlayClassName:r,contentClassName:i,container:s,...a}=t;return Y.createElement(Hye,{open:n,onOpenChange:o},Y.createElement(Iye,{container:s},Y.createElement(SY,{"cmdk-overlay":"",className:r}),Y.createElement(CY,{"aria-label":t.label,"cmdk-dialog":"",className:i},Y.createElement(Spt,{ref:e,...a}))))}),yno=Y.forwardRef((t,e)=>Yv(n=>n.filtered.count===0)?Y.createElement(Gv.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),bno=Y.forwardRef((t,e)=>{let{progress:n,children:o,label:r="Loading...",...i}=t;return Y.createElement(Gv.div,{ref:e,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r},iq(t,s=>Y.createElement("div",{"aria-hidden":!0},s)))}),Xx=Object.assign(Spt,{List:xno,Item:hno,Input:fno,Group:mno,Separator:pno,Dialog:gno,Empty:yno,Loading:bno});function Pno(t,e){let n=t.nextElementSibling;for(;n;){if(n.matches(e))return n;n=n.nextElementSibling}}function vno(t,e){let n=t.previousElementSibling;for(;n;){if(n.matches(e))return n;n=n.previousElementSibling}}function Cpt(t){let e=Y.useRef(t);return uC(()=>{e.current=t}),e}var uC=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;function iD(t){let e=Y.useRef();return e.current===void 0&&(e.current=t()),e}function Yv(t){let e=z5e(),n=()=>t(e.snapshot());return Y.useSyncExternalStore(e.subscribe,n,n)}function Mpt(t,e,n,o=[]){let r=Y.useRef(),i=SI();return uC(()=>{var s;let a=(()=>{var l;for(let u of n){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(l=u.current.textContent)==null?void 0:l.trim():r.current}})(),c=o.map(l=>l.trim());i.value(t,a,c),(s=e.current)==null||s.setAttribute(rD,a),r.current=a}),r}var Sno=()=>{let[t,e]=Y.useState(),n=iD(()=>new Map);return uC(()=>{n.current.forEach(o=>o()),n.current=new Map},[t]),(o,r)=>{n.current.set(o,r),e({})}};function Cno(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function iq({asChild:t,children:e},n){return t&&Y.isValidElement(e)?Y.cloneElement(Cno(e),{ref:e.ref},n(e.props.children)):n(e)}var Mno={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Tpt=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx,{ref:n,className:lr("rf-flex rf-h-full rf-w-full rf-flex-col rf-overflow-hidden rf-rounded-md rf-bg-white rf-text-zinc-950 dark:rf-bg-zinc-950 dark:rf-text-zinc-50",t),...e}));Tpt.displayName=Xx.displayName;const wpt=Y.forwardRef(({className:t,...e},n)=>G.jsxs("div",{className:"rf-flex rf-items-center rf-border-b rf-px-3","cmdk-input-wrapper":"",children:[G.jsx(T2e,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-shrink-0 rf-opacity-50"}),G.jsx(Xx.Input,{ref:n,className:lr("rf-flex rf-h-10 rf-w-full rf-rounded-md rf-bg-transparent rf-py-3 rf-text-sm rf-outline-none placeholder:rf-text-zinc-500 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 dark:placeholder:rf-text-zinc-400",t),...e})]}));wpt.displayName=Xx.Input.displayName;const Ept=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.List,{ref:n,className:lr("rf-max-h-[300px] rf-overflow-y-auto rf-overflow-x-hidden rf-py-1",t),...e}));Ept.displayName=Xx.List.displayName;const V5e=Y.forwardRef((t,e)=>G.jsx(Xx.Empty,{ref:e,className:"rf-py-6 rf-text-center rf-text-sm",...t}));V5e.displayName=Xx.Empty.displayName;const CI=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.Group,{ref:n,className:lr("rf-overflow-hidden rf-px-1 rf-py-0 rf-text-zinc-950 [&_[cmdk-group-heading]]:rf-px-2 [&_[cmdk-group-heading]]:rf-py-1.5 [&_[cmdk-group-heading]]:rf-text-xs [&_[cmdk-group-heading]]:rf-font-medium [&_[cmdk-group-heading]]:rf-text-zinc-500 dark:rf-text-zinc-50 dark:[&_[cmdk-group-heading]]:rf-text-zinc-400",t),...e}));CI.displayName=Xx.Group.displayName;const Tno=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.Separator,{ref:n,className:lr("rf--mx-1 rf-h-px rf-bg-zinc-200 dark:rf-bg-zinc-800",t),...e}));Tno.displayName=Xx.Separator.displayName;const MI=Y.forwardRef(({className:t,...e},n)=>G.jsx(Xx.Item,{ref:n,className:lr("rf-relative rf-flex rf-cursor-default rf-gap-2 rf-select-none rf-items-center rf-rounded-sm rf-px-2 rf-py-1.5 rf-text-sm rf-outline-none data-[disabled=true]:rf-pointer-events-none data-[selected=true]:rf-bg-zinc-100 data-[selected=true]:rf-text-zinc-900 data-[disabled=true]:rf-opacity-50 [&_svg]:rf-pointer-events-none [&_svg]:rf-size-4 [&_svg]:rf-shrink-0 dark:data-[selected=true]:rf-bg-zinc-800 dark:data-[selected=true]:rf-text-zinc-50",t),...e}));MI.displayName=Xx.Item.displayName;function wno(t){const e=Eno(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(Ano);if(c){const l=c.props.children,u=a.map(_=>_===c?Y.Children.count(l)>1?Y.Children.only(null):Y.isValidElement(l)?l.props.children:null:_);return G.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return G.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function Eno(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=kno(r),a=Rno(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?Rx(o,s):s),Y.cloneElement(r,a)}return Y.Children.count(r)>1?Y.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var Dno=Symbol("radix.slottable");function Ano(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Dno}function Rno(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 kno(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 sq="Popover",[Dpt]=d4(sq,[vE]),TI=vE(),[Nno,qv]=Dpt(sq),Apt=t=>{const{__scopePopover:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!1}=t,a=TI(e),c=Y.useRef(null),[l,u]=Y.useState(!1),[_,d]=DP({prop:o,defaultProp:r??!1,onChange:i,caller:sq});return G.jsx(Hj,{...a,children:G.jsx(Nno,{scope:e,contentId:Jp(),triggerRef:c,open:_,onOpenChange:d,onOpenToggle:Y.useCallback(()=>d(m=>!m),[d]),hasCustomAnchor:l,onCustomAnchorAdd:Y.useCallback(()=>u(!0),[]),onCustomAnchorRemove:Y.useCallback(()=>u(!1),[]),modal:s,children:n})})};Apt.displayName=sq;var Rpt="PopoverAnchor",Hno=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=qv(Rpt,n),i=TI(n),{onCustomAnchorAdd:s,onCustomAnchorRemove:a}=r;return Y.useEffect(()=>(s(),()=>a()),[s,a]),G.jsx(Ij,{...i,...o,ref:e})});Hno.displayName=Rpt;var kpt="PopoverTrigger",Npt=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=qv(kpt,n),i=TI(n),s=tu(e,r.triggerRef),a=G.jsx(Cc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":Fpt(r.open),...o,ref:s,onClick:Vr(t.onClick,r.onOpenToggle)});return r.hasCustomAnchor?a:G.jsx(Ij,{asChild:!0,...i,children:a})});Npt.displayName=kpt;var $5e="PopoverPortal",[Ino,Lno]=Dpt($5e,{forceMount:void 0}),Hpt=t=>{const{__scopePopover:e,forceMount:n,children:o,container:r}=t,i=qv($5e,e);return G.jsx(Ino,{scope:e,forceMount:n,children:G.jsx(Fg,{present:n||i.open,children:G.jsx(Lj,{asChild:!0,container:r,children:o})})})};Hpt.displayName=$5e;var sD="PopoverContent",Ipt=Y.forwardRef((t,e)=>{const n=Lno(sD,t.__scopePopover),{forceMount:o=n.forceMount,...r}=t,i=qv(sD,t.__scopePopover);return G.jsx(Fg,{present:o||i.open,children:i.modal?G.jsx(Fno,{...r,ref:e}):G.jsx(Bno,{...r,ref:e})})});Ipt.displayName=sD;var Ono=wno("PopoverContent.RemoveScroll"),Fno=Y.forwardRef((t,e)=>{const n=qv(sD,t.__scopePopover),o=Y.useRef(null),r=tu(e,o),i=Y.useRef(!1);return Y.useEffect(()=>{const s=o.current;if(s)return Y2e(s)},[]),G.jsx(Uj,{as:Ono,allowPinchZoom:!0,children:G.jsx(Lpt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Vr(t.onCloseAutoFocus,s=>{s.preventDefault(),i.current||n.triggerRef.current?.focus()}),onPointerDownOutside:Vr(t.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,l=a.button===2||c;i.current=l},{checkForDefaultPrevented:!1}),onFocusOutside:Vr(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1})})})}),Bno=Y.forwardRef((t,e)=>{const n=qv(sD,t.__scopePopover),o=Y.useRef(!1),r=Y.useRef(!1);return G.jsx(Lpt,{...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()}})}),Lpt=Y.forwardRef((t,e)=>{const{__scopePopover:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,disableOutsidePointerEvents:s,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,..._}=t,d=qv(sD,n),m=TI(n);return D2e(),G.jsx(Sj,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:G.jsx(ZN,{asChild:!0,disableOutsidePointerEvents:s,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>d.onOpenChange(!1),children:G.jsx(X2e,{"data-state":Fpt(d.open),role:"dialog",id:d.contentId,...m,..._,ref:e,style:{..._.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Opt="PopoverClose",zno=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=qv(Opt,n);return G.jsx(Cc.button,{type:"button",...o,ref:e,onClick:Vr(t.onClick,()=>r.onOpenChange(!1))})});zno.displayName=Opt;var Vno="PopoverArrow",$no=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=TI(n);return G.jsx(j2e,{...r,...o,ref:e})});$no.displayName=Vno;function Fpt(t){return t?"open":"closed"}var Wno=Apt,Uno=Npt,Xno=Hpt,Bpt=Ipt;const jno=Wno,Gno=Uno,zpt=Y.forwardRef(({className:t,align:e="center",sideOffset:n=4,...o},r)=>G.jsx(Xno,{children:G.jsx(Bpt,{ref:r,align:e,sideOffset:n,className:lr("rf-z-50 rf-w-72 rf-rounded-md rf-border rf-border-zinc-200 rf-bg-white rf-p-4 rf-text-zinc-950 rf-shadow-md rf-outline-none data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[side=bottom]:rf-slide-in-from-top-2 data-[side=left]:rf-slide-in-from-right-2 data-[side=right]:rf-slide-in-from-left-2 data-[side=top]:rf-slide-in-from-bottom-2 rf-origin-[--radix-popover-content-transform-origin] dark:rf-border-zinc-800 dark:rf-bg-zinc-950 dark:rf-text-zinc-50",t),...o})}));zpt.displayName=Bpt.displayName;function Vpt(t,e){const n=t.lastIndexOf("."),o=e.lastIndexOf("."),r=n>0?t.substring(0,n):t,i=o>0?e.substring(0,o):e;if(r!==i&&t.substring(n)===e.substring(o)){if(r.startsWith(i))return 1;if(i.startsWith(r))return-1}return t.localeCompare(e,void 0,{numeric:!0,sensitivity:"base"})}function Yno(t){const e=[],n=new Map;n.set("",{name:"",path:"",type:"folder",children:e});for(const o of t){const r=o.split("/");let i="";for(let s=0;s<r.length;s++){const a=r[s],c=i;if(i=i?`${i}/${a}`:a,!n.has(i)){const l=s===r.length-1,u={name:a,path:i,type:l?"file":"folder",children:l?void 0:[]};n.set(i,u);const _=n.get(c);_&&_.children&&_.children.push(u)}}}return e}function $pt(t,e){for(const n of t){if(n.path===e)return n;if(n.children){const o=$pt(n.children,e);if(o)return o}}return null}function qno(t,e){let n;if(e?n=$pt(t,e):n={name:"",path:"",type:"folder",children:t},!n||!n.children)return{files:[],folders:[]};const o=n.children.filter(i=>i.type==="file"),r=n.children.filter(i=>i.type==="folder");return o.sort((i,s)=>Vpt(i.name,s.name)),r.sort((i,s)=>Vpt(i.name,s.name)),{files:o,folders:r}}const Jno=t=>{const e=t.split("/").pop()||"";return e.endsWith(".py.tsx")?e.slice(0,-4):e};function W5e(t){const e=t.lastIndexOf("/");return e===-1?"/":t.substring(0,e)}function Kno({currentFile:t,files:e}){const[n,o]=Y.useState(!1),[r,i]=Y.useState(()=>{if(typeof window<"u"){const c=new URLSearchParams(window.location.search),l=new URLSearchParams(window.location.hash.slice(1)),u=c.get("file")??l.get("file");if(u&&e.includes(u)){const _=W5e(u);return _==="/"?null:_}}if(t&&e.includes(t)){const c=W5e(t);return c==="/"?null:c}return null});return Y.useEffect(()=>{if(t&&!n&&e.includes(t)){const c=W5e(t);i(c==="/"?null:c)}},[t,n,e]),{currentFolder:r,navigateToFolder:c=>{i(c),o(!0)},resetManualNavigation:()=>{o(!1)}}}const U5e=t=>t.endsWith(".tsx")||t.endsWith(".jsx")?G.jsx(NDn,{className:"rf-h-4 rf-w-4 rf-text-blue-500"}):t.endsWith(".md")||t.endsWith(".txt")?G.jsx(ODn,{className:"rf-h-4 rf-w-4 rf-text-gray-600"}):G.jsx(FDn,{className:"rf-h-4 rf-w-4 rf-text-gray-500"}),Qno=t=>t.endsWith(".tsx")||tq(t)||t.endsWith(".jsx"),Zno=t=>Jno(t),Wpt=t=>t.substring(0,t.lastIndexOf("/"))||"/",Upt=({files:t,onFileChange:e,currentFile:n,fileFilter:o=Qno,getDisplayName:r=Zno,placeholder:i="Select file",searchPlaceholder:s="Search for file",emptyMessage:a="No files found in this directory.",pinnedFiles:c=[],onToggleFavorite:l,recentlySavedFiles:u=[]})=>{const[_,d]=Y.useState(!1),[m,h]=Y.useState(n),{currentFolder:p,navigateToFolder:x,resetManualNavigation:f}=Kno({currentFile:m,files:t}),[g,y]=Y.useState(0),[b,v]=Y.useState(""),[S,M]=RT("runframe:recentlyViewed",[]),[w,D]=RT("runframe:showRecents",!1);Y.useEffect(()=>{const ae=de=>{(de.metaKey||de.ctrlKey)&&de.key==="k"&&(de.preventDefault(),d(be=>!be))};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[]);const A=t.filter(o),I=Y.useRef(null);Y.useEffect(()=>{const ae=()=>{I.current&&(clearTimeout(I.current),I.current=null)};return h(n),n&&A.includes(n)&&(ae(),I.current=setTimeout(()=>{M(de=>{if(de[0]===n)return de;const be=de.filter(Ce=>Ce!==n);return[n,...be].slice(0,10)})},500)),ae},[n,A,M]);const H=Yno(A),{files:O,folders:z}=qno(H,p||""),j=(()=>{if(!b.trim())return{currentDirResults:[],globalResults:[]};const ae=b.toLowerCase(),be=A.map(pe=>{const Me=pe.split("/").pop()||"";return{path:pe,fileName:Me}}).filter(pe=>pe.fileName.toLowerCase().includes(ae)||pe.path.toLowerCase().includes(ae)),Ce=be.filter(pe=>p?pe.path.substring(0,pe.path.lastIndexOf("/"))===p:!pe.path.includes("/")),De=be.filter(pe=>p?pe.path.substring(0,pe.path.lastIndexOf("/"))!==p:pe.path.includes("/"));return{currentDirResults:Ce,globalResults:De}})(),q=b.trim().length>0,K=ae=>{x(ae),y(0)},ne=Y.useCallback(()=>{if(!p)return;const ae=p.lastIndexOf("/"),de=ae===-1?null:p.substring(0,ae);K(de)},[p,K]);Y.useEffect(()=>{if(!_)return;const ae=de=>{(de.metaKey||de.ctrlKey)&&de.key==="ArrowUp"&&(de.preventDefault(),ne())};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[_,ne]);const ce=Y.useCallback((ae,de,be=!1)=>{if(h(ae),y(de),d(!1),e(ae),be){const Ce=ae.lastIndexOf("/"),De=Ce===-1?null:ae.substring(0,Ce);K(De)}},[e,K]);Y.useEffect(()=>{const ae=de=>{if((de.metaKey||de.ctrlKey)&&(de.key==="ArrowLeft"||de.key==="ArrowRight")){if(de.preventDefault(),!n||O.length===0)return;const be=O.findIndex(pe=>pe.path===n);if(be===-1)return;let Ce;de.key==="ArrowLeft"?Ce=be===0?O.length-1:be-1:Ce=be===O.length-1?0:be+1;const De=O[Ce];De&&ce(De.path,Ce)}};return window.addEventListener("keydown",ae),()=>window.removeEventListener("keydown",ae)},[n,O,ce]),Y.useEffect(()=>{if(O.length>0){const ae=O.findIndex(de=>de.path===n);ae>=0&&y(ae)}},[O,n]);const ee=Y.useMemo(()=>{const ae=u.filter(Ce=>A.includes(Ce)),de=S.filter(Ce=>A.includes(Ce)),be=[];ae.length>0&&be.push({path:ae[0],type:"saved"});for(const Ce of de){if(be.length>=3)break;be.some(De=>De.path===Ce)||be.push({path:Ce,type:"viewed"})}return be},[u,S,A]),oe=p??"/";oe.length>25&&""+oe.slice(-22);const ie=()=>`rf-w-full rf-min-w-[600px] ${q?"rf-max-w-[600px]":"rf-max-w-[1000px]"}`;return G.jsx("div",{className:"rf-flex rf-items-center rf-gap-1",children:G.jsxs(jno,{open:_,onOpenChange:ae=>{d(ae),ae||(v(""),f())},children:[G.jsx(Gno,{asChild:!0,children:G.jsxs(dc,{variant:"outline",role:"combobox","aria-expanded":_,className:"rf-w-fit rf-min-w-32 rf-max-w-100 rf-justify-center rf-items-center rf-gap-1 !rf-font-normal",children:[G.jsx("span",{className:"rf-truncate rf-text-left",children:m?r(m):i}),G.jsx(wDn,{className:"rf-opacity-50 rf-flex-shrink-0"})]})}),G.jsx(zpt,{className:lr("!rf-p-0 !rf-overflow-y-auto !rf-max-h-[80vh] !rf-z-[200]",ie()),children:G.jsxs(Tpt,{shouldFilter:!1,children:[G.jsx(wpt,{placeholder:s,className:"rf-h-9 rf-w-full",value:b,onValueChange:v}),ee.length>0&&G.jsxs("div",{className:"rf-border-b rf-border-gray-200",children:[G.jsxs("button",{onClick:()=>D(!w),className:"rf-w-full rf-px-3 rf-py-2 rf-flex rf-items-center rf-justify-between rf-text-xs rf-text-slate-600 hover:rf-bg-slate-50 rf-bg-transparent rf-border-none rf-cursor-pointer",children:[G.jsx("span",{className:"rf-font-medium",children:"Recent Files"}),G.jsx(M2e,{className:lr("rf-h-4 rf-w-4 rf-transition-transform",!w&&"-rf-rotate-90")})]}),w&&G.jsx("div",{className:"rf-pb-1",children:ee.map((ae,de)=>G.jsxs("div",{onClick:()=>ce(ae.path,de,!0),className:lr("rf-flex rf-items-center rf-px-3 rf-py-1.5 rf-cursor-pointer hover:rf-bg-slate-100",ae.path===n&&"rf-font-medium"),children:[ae.type==="saved"?G.jsx("span",{title:"Recently saved",children:G.jsx(GDn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-green-500"})}):G.jsx("span",{title:"Recently viewed",children:G.jsx(kDn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-500"})}),G.jsx("span",{className:"rf-text-sm",children:r(ae.path.split("/").pop()||"")}),G.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Wpt(ae.path)}),G.jsx(T8,{className:lr("rf-ml-auto rf-h-4 rf-w-4",ae.path===n?"rf-opacity-100":"rf-opacity-0")})]},ae.path))})]}),G.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-slate-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[G.jsx("div",{className:"rf-flex rf-items-center rf-text-xs rf-text-slate-600 rf-min-w-0 rf-flex-1",children:G.jsxs("div",{className:"rf-flex rf-items-center rf-min-w-0",children:[G.jsx("button",{onClick:()=>K(null),className:"rf-text-blue-600 hover:rf-text-blue-800 rf-underline rf-cursor-pointer rf-bg-transparent rf-border-none rf-p-0 rf-flex-shrink-0",children:"root"}),p?.split("/").filter(Boolean).map((ae,de,be)=>{const Ce=be.slice(0,de+1).join("/");return G.jsxs("span",{className:"rf-flex rf-items-center rf-min-w-0",children:[G.jsx("span",{className:"rf-mx-1 rf-flex-shrink-0",children:"/"}),de===be.length-1?G.jsx("span",{className:"rf-text-slate-800 rf-truncate rf-max-w-[200px]",title:ae,children:ae}):G.jsx("button",{onClick:()=>K(Ce),className:"rf-text-blue-600 hover:rf-text-blue-800 rf-underline rf-cursor-pointer rf-bg-transparent rf-border-none rf-p-0 rf-truncate rf-max-w-[150px]",title:ae,children:ae})]},Ce)})]})}),G.jsx("div",{className:"rf-flex rf-items-center rf-gap-2 rf-flex-shrink-0",children:p&&G.jsxs("button",{onClick:ne,className:"rf-flex rf-items-center rf-gap-1 rf-text-slate-600 hover:rf-text-slate-800 rf-bg-transparent rf-border-none rf-p-1 rf-rounded hover:rf-bg-slate-200 rf-transition-colors",title:"Go up one level",children:[G.jsx(MDn,{className:"rf-h-3 rf-w-3"}),G.jsx("span",{className:"rf-text-xs rf-font-medium",children:"Up"})]})})]}),G.jsx(Ept,{className:"rf-overflow-visible rf-max-h-none",children:q?G.jsx(G.Fragment,{children:j.currentDirResults.length===0&&j.globalResults.length===0?G.jsxs(V5e,{children:['No files found matching "',b,'".']}):G.jsxs(G.Fragment,{children:[j.currentDirResults.length>0&&G.jsx(CI,{children:j.currentDirResults.map((ae,de)=>G.jsxs(MI,{value:`search-current:${ae.path}`,onSelect:()=>{h(ae.path),d(!1),e(ae.path)},className:lr(ae.path===n&&"rf-font-medium","rf-group"),children:[G.jsx("span",{className:"rf-mr-2",children:U5e(ae.fileName)}),G.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[G.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ae.fileName)}),G.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:p||"/"}),ae.path===n&&G.jsx(T8,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ae.path))}),j.globalResults.length>0&&G.jsx(CI,{children:j.globalResults.map(ae=>G.jsxs(MI,{value:`search-global:${ae.path}`,onSelect:()=>{h(ae.path),d(!1),e(ae.path)},className:lr(ae.path===n&&"rf-font-medium","rf-group"),children:[G.jsx("span",{className:"rf-mr-2",children:U5e(ae.fileName)}),G.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[G.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ae.fileName)}),G.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Wpt(ae.path)}),ae.path===n&&G.jsx(T8,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ae.path))})]})}):G.jsxs(G.Fragment,{children:[G.jsx(V5e,{children:a}),O.length>0&&G.jsx(CI,{children:O.map((ae,de)=>G.jsxs(MI,{value:`current:${ae.path}`,onSelect:()=>ce(ae.path,de),className:lr(ae.path===n&&"rf-font-medium","rf-group"),children:[G.jsx("span",{className:"rf-mr-2",children:U5e(ae.name)}),r(ae.name),G.jsx("div",{className:"rf-ml-auto rf-flex rf-items-center rf-gap-1",children:G.jsx(T8,{className:lr("rf-h-4 rf-w-4",ae.path===n?"rf-opacity-100":"rf-opacity-0")})})]},ae.path))}),z.length>0&&G.jsx(CI,{children:z.map(ae=>G.jsxs(MI,{value:`folder-${ae.path}`,onSelect:()=>K(ae.path),className:"rf-text-slate-600 hover:rf-text-slate-900",children:[G.jsx(BDn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-600"}),ae.name,G.jsx(xE,{className:"rf-ml-auto rf-h-4 rf-w-4"})]},ae.path))}),O.length===0&&z.length===0&&G.jsx("div",{className:"rf-p-4 rf-text-center rf-text-slate-500 rf-text-sm",children:"No files or folders in this directory"})]})})]})})]})})},Xpt=({files:t,onFileChange:e,currentFile:n})=>G.jsx(Upt,{files:t,onFileChange:e,currentFile:n,fileFilter:()=>!0,placeholder:"Select circuit",searchPlaceholder:"Search for circuit file",emptyMessage:"No circuit files found in this directory."}),eoo=t=>{xY();const[e,n]=Y.useState(()=>t.initialCircuitPath??""),[o,r]=Y.useState(null),[i,s]=Y.useState(!1),[a,c]=Y.useState({}),[l,u]=Y.useState(new Set),[_,d]=Y.useState(new Set),m=t.files,h=m.map(b=>b.filePath),p=Y.useCallback(async b=>{if(!b.fileStaticAssetUrl)throw new Error(`No fileStaticAssetUrl provided for ${b.filePath}`);const v=await fetch(b.fileStaticAssetUrl);if(!v.ok)throw new Error(`Failed to fetch ${b.filePath}: ${v.statusText}`);return await v.json()},[]),x=Y.useCallback(async b=>{if(a[b]){r(a[b]),t.onCircuitJsonPathChange?.(b);return}if(_.has(b)){console.warn(`Skipping failed file: ${b}`),r(null);return}if(!l.has(b)){u(v=>new Set(v).add(b)),s(!0),r(null);try{const v=m.find(w=>w.filePath===b);if(!v)throw new Error(`File reference not found for ${b}`);const M=await(t.onFetchFile||p)(v);c(w=>({...w,[b]:M})),r(M),t.onCircuitJsonPathChange?.(b),d(w=>{const D=new Set(w);return D.delete(b),D})}catch(v){console.error(`Failed to load circuit JSON file ${b}:`,v),d(S=>new Set(S).add(b)),r(null)}finally{u(v=>{const S=new Set(v);return S.delete(b),S}),s(!1)}}},[m,a,l,_,t.onFetchFile,t.onCircuitJsonPathChange,p]);Y.useEffect(()=>{if(h.length===0)return;let b=e;(!b||!h.includes(b))&&(b=lft(h)??h[0],n(b)),b&&h.includes(b)&&x(b)},[e]);const f=Y.useCallback(b=>{n(b)},[]),g=Y.useCallback(b=>{d(v=>{const S=new Set(v);return S.delete(b),S}),x(b)},[x]);if(h.length===0)return G.jsx("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full rf-items-center rf-justify-center",children:G.jsxs("div",{className:"rf-text-center rf-p-8",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-2",children:"No Circuit JSON Files Found"}),G.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Please provide circuit JSON files to view."})]})});const y=_.has(e);return G.jsx(M5,{fallbackRender:({error:b})=>G.jsx("div",{className:"rf-mt-4 rf-mx-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Circuit JSON Preview"}),G.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:b.message})]})}),children:y?G.jsxs("div",{className:"rf-w-full rf-h-full rf-flex rf-flex-col",children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full rf-p-4 rf-border-b rf-border-gray-200",children:[(t.showFileMenu??!0)&&G.jsx(bI,{isWebEmbedded:!0,circuitJson:null,projectName:t.projectName}),h.length>1&&G.jsx("div",{className:"rf-absolute rf-left-1/2 rf-transform rf--translate-x-1/2 rf-flex rf-items-center rf-gap-2",children:G.jsx(Xpt,{currentFile:e,files:h,onFileChange:f})})]}),G.jsx("div",{className:"rf-flex-1 rf-flex rf-items-center rf-justify-center",children:G.jsxs("div",{className:"rf-text-center rf-p-8",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-600 rf-mb-2",children:"Failed to Load Circuit File"}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-600 rf-mb-4",children:["Could not load: ",e]}),G.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-2",children:[G.jsx("button",{onClick:()=>g(e),className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600",children:"Retry"}),h.length>1&&G.jsx("p",{className:"rf-text-xs rf-text-gray-500",children:"Or select a different file from the dropdown above"})]})]})})]}):G.jsx(Vmt,{circuitJson:o,defaultToFullScreen:t.defaultToFullScreen,showToggleFullScreen:t.showToggleFullScreen,showFileMenu:!1,isWebEmbedded:!1,projectName:t.projectName,defaultActiveTab:t.tabSelected,leftHeaderContent:G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full",children:[(t.showFileMenu??!0)&&G.jsx(bI,{isWebEmbedded:!0,circuitJson:o,projectName:t.projectName}),h.length>1&&G.jsx("div",{className:`rf-absolute rf-left-1/2 rf-transform rf--translate-x-1/2 rf-flex rf-items-center rf-gap-2 ${i?"rf-opacity-50":""}`,children:G.jsx(Xpt,{currentFile:e,files:h,onFileChange:f})})]})})})},too=()=>{const t=eu(e=>e.fsMap);Y.useEffect(()=>{if(!document||!t)return;const e=Array.from(t.keys()),n=lft(e),o=t.get("package.json");try{if(o){const r=JSON.parse(o);if(r?.name){document.title=r.name;return}}}catch{}n&&(document.title=n)},[t])},jpt=(t,e,n)=>{const o=t instanceof RegExp?Gpt(t,n):t,r=e instanceof RegExp?Gpt(e,n):e,i=o!==null&&r!=null&&noo(o,r,n);return i&&{start:i[0],end:i[1],pre:n.slice(0,i[0]),body:n.slice(i[0]+o.length,i[1]),post:n.slice(i[1]+r.length)}},Gpt=(t,e)=>{const n=e.match(t);return n?n[0]:null},noo=(t,e,n)=>{let o,r,i,s,a,c=n.indexOf(t),l=n.indexOf(e,c+1),u=c;if(c>=0&&l>0){if(t===e)return[c,l];for(o=[],i=n.length;u>=0&&!a;){if(u===c)o.push(u),c=n.indexOf(t,u+1);else if(o.length===1){const _=o.pop();_!==void 0&&(a=[_,l])}else r=o.pop(),r!==void 0&&r<i&&(i=r,s=l),l=n.indexOf(e,u+1);u=c<l&&c>=0?c:l}o.length&&s!==void 0&&(a=[i,s])}return a},Ypt="\0SLASH"+Math.random()+"\0",qpt="\0OPEN"+Math.random()+"\0",X5e="\0CLOSE"+Math.random()+"\0",Jpt="\0COMMA"+Math.random()+"\0",Kpt="\0PERIOD"+Math.random()+"\0",ooo=new RegExp(Ypt,"g"),roo=new RegExp(qpt,"g"),ioo=new RegExp(X5e,"g"),soo=new RegExp(Jpt,"g"),aoo=new RegExp(Kpt,"g"),coo=/\\\\/g,loo=/\\{/g,uoo=/\\}/g,_oo=/\\,/g,doo=/\\./g;function j5e(t){return isNaN(t)?t.charCodeAt(0):parseInt(t,10)}function hoo(t){return t.replace(coo,Ypt).replace(loo,qpt).replace(uoo,X5e).replace(_oo,Jpt).replace(doo,Kpt)}function moo(t){return t.replace(ooo,"\\").replace(roo,"{").replace(ioo,"}").replace(soo,",").replace(aoo,".")}function Qpt(t){if(!t)return[""];const e=[],n=jpt("{","}",t);if(!n)return t.split(",");const{pre:o,body:r,post:i}=n,s=o.split(",");s[s.length-1]+="{"+r+"}";const a=Qpt(i);return i.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),e.push.apply(e,s),e}function poo(t){return t?(t.slice(0,2)==="{}"&&(t="\\{\\}"+t.slice(2)),wI(hoo(t),!0).map(moo)):[]}function foo(t){return"{"+t+"}"}function xoo(t){return/^-?0\d/.test(t)}function goo(t,e){return t<=e}function yoo(t,e){return t>=e}function wI(t,e){const n=[],o=jpt("{","}",t);if(!o)return[t];const r=o.pre,i=o.post.length?wI(o.post,!1):[""];if(/\$$/.test(o.pre))for(let s=0;s<i.length;s++){const a=r+"{"+o.body+"}"+i[s];n.push(a)}else{const s=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(o.body),a=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(o.body),c=s||a,l=o.body.indexOf(",")>=0;if(!c&&!l)return o.post.match(/,(?!,).*\}/)?(t=o.pre+"{"+o.body+X5e+o.post,wI(t)):[t];let u;if(c)u=o.body.split(/\.\./);else if(u=Qpt(o.body),u.length===1&&u[0]!==void 0&&(u=wI(u[0],!1).map(foo),u.length===1))return i.map(d=>o.pre+u[0]+d);let _;if(c&&u[0]!==void 0&&u[1]!==void 0){const d=j5e(u[0]),m=j5e(u[1]),h=Math.max(u[0].length,u[1].length);let p=u.length===3&&u[2]!==void 0?Math.abs(j5e(u[2])):1,x=goo;m<d&&(p*=-1,x=yoo);const g=u.some(xoo);_=[];for(let y=d;x(y,m);y+=p){let b;if(a)b=String.fromCharCode(y),b==="\\"&&(b="");else if(b=String(y),g){const v=h-b.length;if(v>0){const S=new Array(v+1).join("0");y<0?b="-"+S+b.slice(1):b=S+b}}_.push(b)}}else{_=[];for(let d=0;d<u.length;d++)_.push.apply(_,wI(u[d],!1))}for(let d=0;d<_.length;d++)for(let m=0;m<i.length;m++){const h=r+_[d]+i[m];(!e||c||h)&&n.push(h)}}return n}const boo=1024*64,aq=t=>{if(typeof t!="string")throw new TypeError("invalid pattern");if(t.length>boo)throw new TypeError("pattern is too long")},Poo={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},EI=t=>t.replace(/[[\]\\-]/g,"\\$&"),voo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Zpt=t=>t.join(""),Soo=(t,e)=>{const n=e;if(t.charAt(n)!=="[")throw new Error("not in a brace expression");const o=[],r=[];let i=n+1,s=!1,a=!1,c=!1,l=!1,u=n,_="";e:for(;i<t.length;){const p=t.charAt(i);if((p==="!"||p==="^")&&i===n+1){l=!0,i++;continue}if(p==="]"&&s&&!c){u=i+1;break}if(s=!0,p==="\\"&&!c){c=!0,i++;continue}if(p==="["&&!c){for(const[x,[f,g,y]]of Object.entries(Poo))if(t.startsWith(x,i)){if(_)return["$.",!1,t.length-n,!0];i+=x.length,y?r.push(f):o.push(f),a=a||g;continue e}}if(c=!1,_){p>_?o.push(EI(_)+"-"+EI(p)):p===_&&o.push(EI(p)),_="",i++;continue}if(t.startsWith("-]",i+1)){o.push(EI(p+"-")),i+=2;continue}if(t.startsWith("-",i+1)){_=p,i+=2;continue}o.push(EI(p)),i++}if(u<i)return["",!1,0,!1];if(!o.length&&!r.length)return["$.",!1,t.length-n,!0];if(r.length===0&&o.length===1&&/^\\?.$/.test(o[0])&&!l){const p=o[0].length===2?o[0].slice(-1):o[0];return[voo(p),!1,u-n,!1]}const d="["+(l?"^":"")+Zpt(o)+"]",m="["+(l?"":"^")+Zpt(r)+"]";return[o.length&&r.length?"("+d+"|"+m+")":o.length?d:m,a,u-n,!0]},DI=(t,{windowsPathsNoEscape:e=!1,magicalBraces:n=!0}={})=>n?e?t.replace(/\[([^\/\\])\]/g,"$1"):t.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1"):e?t.replace(/\[([^\/\\{}])\]/g,"$1"):t.replace(/((?!\\).|^)\[([^\/\\{}])\]/g,"$1$2").replace(/\\([^\/{}])/g,"$1"),Coo=new Set(["!","?","+","*","@"]),eft=t=>Coo.has(t),Moo="(?!(?:^|/)\\.\\.?(?:$|/))",cq="(?!\\.)",Too=new Set(["[","."]),woo=new Set(["..","."]),Eoo=new Set("().*{}+?[]^$\\!"),Doo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),G5e="[^/]",tft=G5e+"*?",nft=G5e+"+?";class x2{type;#o;#n;#r=!1;#t=[];#e;#s;#i;#l=!1;#a;#u;#_=!1;constructor(e,n,o={}){this.type=e,e&&(this.#n=!0),this.#e=n,this.#o=this.#e?this.#e.#o:this,this.#a=this.#o===this?o:this.#o.#a,this.#i=this.#o===this?[]:this.#o.#i,e==="!"&&!this.#o.#l&&this.#i.push(this),this.#s=this.#e?this.#e.#t.length:0}get hasMagic(){if(this.#n!==void 0)return this.#n;for(const e of this.#t)if(typeof e!="string"&&(e.type||e.hasMagic))return this.#n=!0;return this.#n}toString(){return this.#u!==void 0?this.#u:this.type?this.#u=this.type+"("+this.#t.map(e=>String(e)).join("|")+")":this.#u=this.#t.map(e=>String(e)).join("")}#d(){if(this!==this.#o)throw new Error("should only call on root");if(this.#l)return this;this.toString(),this.#l=!0;let e;for(;e=this.#i.pop();){if(e.type!=="!")continue;let n=e,o=n.#e;for(;o;){for(let r=n.#s+1;!o.type&&r<o.#t.length;r++)for(const i of e.#t){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(o.#t[r])}n=o,o=n.#e}}return this}push(...e){for(const n of e)if(n!==""){if(typeof n!="string"&&!(n instanceof x2&&n.#e===this))throw new Error("invalid part: "+n);this.#t.push(n)}}toJSON(){const e=this.type===null?this.#t.slice().map(n=>typeof n=="string"?n:n.toJSON()):[this.type,...this.#t.map(n=>n.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#o||this.#o.#l&&this.#e?.type==="!")&&e.push({}),e}isStart(){if(this.#o===this)return!0;if(!this.#e?.isStart())return!1;if(this.#s===0)return!0;const e=this.#e;for(let n=0;n<this.#s;n++){const o=e.#t[n];if(!(o instanceof x2&&o.type==="!"))return!1}return!0}isEnd(){if(this.#o===this||this.#e?.type==="!")return!0;if(!this.#e?.isEnd())return!1;if(!this.type)return this.#e?.isEnd();const e=this.#e?this.#e.#t.length:0;return this.#s===e-1}copyIn(e){typeof e=="string"?this.push(e):this.push(e.clone(this))}clone(e){const n=new x2(this.type,e);for(const o of this.#t)n.copyIn(o);return n}static#c(e,n,o,r){let i=!1,s=!1,a=-1,c=!1;if(n.type===null){let m=o,h="";for(;m<e.length;){const p=e.charAt(m++);if(i||p==="\\"){i=!i,h+=p;continue}if(s){m===a+1?(p==="^"||p==="!")&&(c=!0):p==="]"&&!(m===a+2&&c)&&(s=!1),h+=p;continue}else if(p==="["){s=!0,a=m,c=!1,h+=p;continue}if(!r.noext&&eft(p)&&e.charAt(m)==="("){n.push(h),h="";const x=new x2(p,n);m=x2.#c(e,x,m,r),n.push(x);continue}h+=p}return n.push(h),m}let l=o+1,u=new x2(null,n);const _=[];let d="";for(;l<e.length;){const m=e.charAt(l++);if(i||m==="\\"){i=!i,d+=m;continue}if(s){l===a+1?(m==="^"||m==="!")&&(c=!0):m==="]"&&!(l===a+2&&c)&&(s=!1),d+=m;continue}else if(m==="["){s=!0,a=l,c=!1,d+=m;continue}if(eft(m)&&e.charAt(l)==="("){u.push(d),d="";const h=new x2(m,u);u.push(h),l=x2.#c(e,h,l,r);continue}if(m==="|"){u.push(d),d="",_.push(u),u=new x2(null,n);continue}if(m===")")return d===""&&n.#t.length===0&&(n.#_=!0),u.push(d),d="",n.push(..._,u),l;d+=m}return n.type=null,n.#n=void 0,n.#t=[e.substring(o-1)],l}static fromGlob(e,n={}){const o=new x2(null,void 0,n);return x2.#c(e,o,0,n),o}toMMPattern(){if(this!==this.#o)return this.#o.toMMPattern();const e=this.toString(),[n,o,r,i]=this.toRegExpSource();if(!(r||this.#n||this.#a.nocase&&!this.#a.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return o;const a=(this.#a.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${n}$`,a),{_src:n,_glob:e})}get options(){return this.#a}toRegExpSource(e){const n=e??!!this.#a.dot;if(this.#o===this&&this.#d(),!this.type){const c=this.isStart()&&this.isEnd()&&!this.#t.some(m=>typeof m!="string"),l=this.#t.map(m=>{const[h,p,x,f]=typeof m=="string"?x2.#p(m,this.#n,c):m.toRegExpSource(e);return this.#n=this.#n||x,this.#r=this.#r||f,h}).join("");let u="";if(this.isStart()&&typeof this.#t[0]=="string"&&!(this.#t.length===1&&woo.has(this.#t[0]))){const h=Too,p=n&&h.has(l.charAt(0))||l.startsWith("\\.")&&h.has(l.charAt(2))||l.startsWith("\\.\\.")&&h.has(l.charAt(4)),x=!n&&!e&&h.has(l.charAt(0));u=p?Moo:x?cq:""}let _="";return this.isEnd()&&this.#o.#l&&this.#e?.type==="!"&&(_="(?:$|\\/)"),[u+l+_,DI(l),this.#n=!!this.#n,this.#r]}const o=this.type==="*"||this.type==="+",r=this.type==="!"?"(?:(?!(?:":"(?:";let i=this.#h(n);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){const c=this.toString();return this.#t=[c],this.type=null,this.#n=void 0,[c,DI(this.toString()),!1,!1]}let s=!o||e||n||!cq?"":this.#h(!0);s===i&&(s=""),s&&(i=`(?:${i})(?:${s})*?`);let a="";if(this.type==="!"&&this.#_)a=(this.isStart()&&!n?cq:"")+nft;else{const c=this.type==="!"?"))"+(this.isStart()&&!n&&!e?cq:"")+tft+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=r+i+c}return[a,DI(i),this.#n=!!this.#n,this.#r]}#h(e){return this.#t.map(n=>{if(typeof n=="string")throw new Error("string type in extglob ast??");const[o,r,i,s]=n.toRegExpSource(e);return this.#r=this.#r||s,o}).filter(n=>!(this.isStart()&&this.isEnd())||!!n).join("|")}static#p(e,n,o=!1){let r=!1,i="",s=!1;for(let a=0;a<e.length;a++){const c=e.charAt(a);if(r){r=!1,i+=(Eoo.has(c)?"\\":"")+c;continue}if(c==="\\"){a===e.length-1?i+="\\\\":r=!0;continue}if(c==="["){const[l,u,_,d]=Soo(e,a);if(_){i+=l,s=s||u,a+=_-1,n=n||d;continue}}if(c==="*"){i+=o&&e==="*"?nft:tft,n=!0;continue}if(c==="?"){i+=G5e,n=!0;continue}i+=Doo(c)}return[i,DI(e),!!n,s]}}const Aoo=(t,{windowsPathsNoEscape:e=!1,magicalBraces:n=!1}={})=>n?e?t.replace(/[?*()[\]{}]/g,"[$&]"):t.replace(/[?*()[\]\\{}]/g,"\\$&"):e?t.replace(/[?*()[\]]/g,"[$&]"):t.replace(/[?*()[\]\\]/g,"\\$&");var aD={env:{}};const g2=(t,e,n={})=>(aq(e),!n.nocomment&&e.charAt(0)==="#"?!1:new AI(e,n).match(t)),Roo=/^\*+([^+@!?\*\[\(]*)$/,koo=t=>e=>!e.startsWith(".")&&e.endsWith(t),Noo=t=>e=>e.endsWith(t),Hoo=t=>(t=t.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(t)),Ioo=t=>(t=t.toLowerCase(),e=>e.toLowerCase().endsWith(t)),Loo=/^\*+\.\*+$/,Ooo=t=>!t.startsWith(".")&&t.includes("."),Foo=t=>t!=="."&&t!==".."&&t.includes("."),Boo=/^\.\*+$/,zoo=t=>t!=="."&&t!==".."&&t.startsWith("."),Voo=/^\*+$/,$oo=t=>t.length!==0&&!t.startsWith("."),Woo=t=>t.length!==0&&t!=="."&&t!=="..",Uoo=/^\?+([^+@!?\*\[\(]*)?$/,Xoo=([t,e=""])=>{const n=oft([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},joo=([t,e=""])=>{const n=rft([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},Goo=([t,e=""])=>{const n=rft([t]);return e?o=>n(o)&&o.endsWith(e):n},Yoo=([t,e=""])=>{const n=oft([t]);return e?o=>n(o)&&o.endsWith(e):n},oft=([t])=>{const e=t.length;return n=>n.length===e&&!n.startsWith(".")},rft=([t])=>{const e=t.length;return n=>n.length===e&&n!=="."&&n!==".."},ift=typeof aD=="object"&&aD?typeof aD.env=="object"&&aD.env&&aD.env.__MINIMATCH_TESTING_PLATFORM__||aD.platform:"posix",sft={win32:{sep:"\\"},posix:{sep:"/"}},qoo=ift==="win32"?sft.win32.sep:sft.posix.sep;g2.sep=qoo;const O5=Symbol("globstar **");g2.GLOBSTAR=O5;const Joo="[^/]"+"*?",Koo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Qoo="(?:(?!(?:\\/|^)\\.).)*?",Zoo=(t,e={})=>n=>g2(n,t,e);g2.filter=Zoo;const F5=(t,e={})=>Object.assign({},t,e),ero=t=>{if(!t||typeof t!="object"||!Object.keys(t).length)return g2;const e=g2;return Object.assign((o,r,i={})=>e(o,r,F5(t,i)),{Minimatch:class extends e.Minimatch{constructor(r,i={}){super(r,F5(t,i))}static defaults(r){return e.defaults(F5(t,r)).Minimatch}},AST:class extends e.AST{constructor(r,i,s={}){super(r,i,F5(t,s))}static fromGlob(r,i={}){return e.AST.fromGlob(r,F5(t,i))}},unescape:(o,r={})=>e.unescape(o,F5(t,r)),escape:(o,r={})=>e.escape(o,F5(t,r)),filter:(o,r={})=>e.filter(o,F5(t,r)),defaults:o=>e.defaults(F5(t,o)),makeRe:(o,r={})=>e.makeRe(o,F5(t,r)),braceExpand:(o,r={})=>e.braceExpand(o,F5(t,r)),match:(o,r,i={})=>e.match(o,r,F5(t,i)),sep:e.sep,GLOBSTAR:O5})};g2.defaults=ero;const aft=(t,e={})=>(aq(t),e.nobrace||!/\{(?:(?!\{).)*\}/.test(t)?[t]:poo(t));g2.braceExpand=aft;const tro=(t,e={})=>new AI(t,e).makeRe();g2.makeRe=tro;const nro=(t,e,n={})=>{const o=new AI(e,n);return t=t.filter(r=>o.match(r)),o.options.nonull&&!t.length&&t.push(e),t};g2.match=nro;const cft=/[?*]|[+@!]\(.*?\)|\[|\]/,oro=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");class AI{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(e,n={}){aq(e),n=n||{},this.options=n,this.pattern=e,this.platform=n.platform||ift,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!n.windowsPathsNoEscape||n.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!n.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!n.nonegate,this.comment=!1,this.empty=!1,this.partial=!!n.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=n.windowsNoMagicRoot!==void 0?n.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(const e of this.set)for(const n of e)if(typeof n!="string")return!0;return!1}debug(...e){}make(){const e=this.pattern,n=this.options;if(!n.nocomment&&e.charAt(0)==="#"){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],n.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);const o=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(o),this.debug(this.pattern,this.globParts);let r=this.globParts.map((i,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){const c=i[0]===""&&i[1]===""&&(i[2]==="?"||!cft.test(i[2]))&&!cft.test(i[3]),l=/^[a-z]:/i.test(i[0]);if(c)return[...i.slice(0,4),...i.slice(4).map(u=>this.parse(u))];if(l)return[i[0],...i.slice(1).map(u=>this.parse(u))]}return i.map(c=>this.parse(c))});if(this.debug(this.pattern,r),this.set=r.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){const s=this.set[i];s[0]===""&&s[1]===""&&this.globParts[i][2]==="?"&&typeof s[3]=="string"&&/^[a-z]:$/i.test(s[3])&&(s[2]="?")}this.debug(this.pattern,this.set)}preprocess(e){if(this.options.noglobstar)for(let o=0;o<e.length;o++)for(let r=0;r<e[o].length;r++)e[o][r]==="**"&&(e[o][r]="*");const{optimizationLevel:n=1}=this.options;return n>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):n>=1?e=this.levelOneOptimize(e):e=this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(n=>{let o=-1;for(;(o=n.indexOf("**",o+1))!==-1;){let r=o;for(;n[r+1]==="**";)r++;r!==o&&n.splice(o,r-o)}return n})}levelOneOptimize(e){return e.map(n=>(n=n.reduce((o,r)=>{const i=o[o.length-1];return r==="**"&&i==="**"?o:r===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(o.pop(),o):(o.push(r),o)},[]),n.length===0?[""]:n))}levelTwoFileOptimize(e){Array.isArray(e)||(e=this.slashSplit(e));let n=!1;do{if(n=!1,!this.preserveMultipleSlashes){for(let r=1;r<e.length-1;r++){const i=e[r];r===1&&i===""&&e[0]===""||(i==="."||i==="")&&(n=!0,e.splice(r,1),r--)}e[0]==="."&&e.length===2&&(e[1]==="."||e[1]==="")&&(n=!0,e.pop())}let o=0;for(;(o=e.indexOf("..",o+1))!==-1;){const r=e[o-1];r&&r!=="."&&r!==".."&&r!=="**"&&(n=!0,e.splice(o-1,2),o-=2)}}while(n);return e.length===0?[""]:e}firstPhasePreProcess(e){let n=!1;do{n=!1;for(let o of e){let r=-1;for(;(r=o.indexOf("**",r+1))!==-1;){let s=r;for(;o[s+1]==="**";)s++;s>r&&o.splice(r+1,s-r);let a=o[r+1];const c=o[r+2],l=o[r+3];if(a!==".."||!c||c==="."||c===".."||!l||l==="."||l==="..")continue;n=!0,o.splice(r,1);const u=o.slice(0);u[r]="**",e.push(u),r--}if(!this.preserveMultipleSlashes){for(let s=1;s<o.length-1;s++){const a=o[s];s===1&&a===""&&o[0]===""||(a==="."||a==="")&&(n=!0,o.splice(s,1),s--)}o[0]==="."&&o.length===2&&(o[1]==="."||o[1]==="")&&(n=!0,o.pop())}let i=0;for(;(i=o.indexOf("..",i+1))!==-1;){const s=o[i-1];if(s&&s!=="."&&s!==".."&&s!=="**"){n=!0;const c=i===1&&o[i+1]==="**"?["."]:[];o.splice(i-1,2,...c),o.length===0&&o.push(""),i-=2}}}}while(n);return e}secondPhasePreProcess(e){for(let n=0;n<e.length-1;n++)for(let o=n+1;o<e.length;o++){const r=this.partsMatch(e[n],e[o],!this.preserveMultipleSlashes);if(r){e[n]=[],e[o]=r;break}}return e.filter(n=>n.length)}partsMatch(e,n,o=!1){let r=0,i=0,s=[],a="";for(;r<e.length&&i<n.length;)if(e[r]===n[i])s.push(a==="b"?n[i]:e[r]),r++,i++;else if(o&&e[r]==="**"&&n[i]===e[r+1])s.push(e[r]),r++;else if(o&&n[i]==="**"&&e[r]===n[i+1])s.push(n[i]),i++;else if(e[r]==="*"&&n[i]&&(this.options.dot||!n[i].startsWith("."))&&n[i]!=="**"){if(a==="b")return!1;a="a",s.push(e[r]),r++,i++}else if(n[i]==="*"&&e[r]&&(this.options.dot||!e[r].startsWith("."))&&e[r]!=="**"){if(a==="a")return!1;a="b",s.push(n[i]),r++,i++}else return!1;return e.length===n.length&&s}parseNegate(){if(this.nonegate)return;const e=this.pattern;let n=!1,o=0;for(let r=0;r<e.length&&e.charAt(r)==="!";r++)n=!n,o++;o&&(this.pattern=e.slice(o)),this.negate=n}matchOne(e,n,o=!1){const r=this.options;if(this.isWindows){const p=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),x=!p&&e[0]===""&&e[1]===""&&e[2]==="?"&&/^[a-z]:$/i.test(e[3]),f=typeof n[0]=="string"&&/^[a-z]:$/i.test(n[0]),g=!f&&n[0]===""&&n[1]===""&&n[2]==="?"&&typeof n[3]=="string"&&/^[a-z]:$/i.test(n[3]),y=x?3:p?0:void 0,b=g?3:f?0:void 0;if(typeof y=="number"&&typeof b=="number"){const[v,S]=[e[y],n[b]];v.toLowerCase()===S.toLowerCase()&&(n[b]=v,b>y?n=n.slice(b):y>b&&(e=e.slice(y)))}}const{optimizationLevel:i=1}=this.options;i>=2&&(e=this.levelTwoFileOptimize(e)),this.debug("matchOne",this,{file:e,pattern:n}),this.debug("matchOne",e.length,n.length);for(var s=0,a=0,c=e.length,l=n.length;s<c&&a<l;s++,a++){this.debug("matchOne loop");var u=n[a],_=e[s];if(this.debug(n,u,_),u===!1)return!1;if(u===O5){this.debug("GLOBSTAR",[n,u,_]);var d=s,m=a+1;if(m===l){for(this.debug("** at the end");s<c;s++)if(e[s]==="."||e[s]===".."||!r.dot&&e[s].charAt(0)===".")return!1;return!0}for(;d<c;){var h=e[d];if(this.debug(`
|
|
5786
5786
|
globstar while`,e,d,n,m,h),this.matchOne(e.slice(d),n.slice(m),o))return this.debug("globstar found match!",d,c,h),!0;if(h==="."||h===".."||!r.dot&&h.charAt(0)==="."){this.debug("dot detected!",e,d,n,m);break}this.debug("globstar swallow a segment, and continue"),d++}return!!(o&&(this.debug(`
|
|
5787
5787
|
>>> no match, partial?`,e,d,n,m),d===c))}let p;if(typeof u=="string"?(p=_===u,this.debug("string match",u,_,p)):(p=u.test(_),this.debug("pattern match",u,_,p)),!p)return!1}if(s===c&&a===l)return!0;if(s===c)return o;if(a===l)return s===c-1&&e[s]==="";throw new Error("wtf?")}braceExpand(){return aft(this.pattern,this.options)}parse(e){aq(e);const n=this.options;if(e==="**")return O5;if(e==="")return"";let o,r=null;(o=e.match(Voo))?r=n.dot?Woo:$oo:(o=e.match(Roo))?r=(n.nocase?n.dot?Ioo:Hoo:n.dot?Noo:koo)(o[1]):(o=e.match(Uoo))?r=(n.nocase?n.dot?joo:Xoo:n.dot?Goo:Yoo)(o):(o=e.match(Loo))?r=n.dot?Foo:Ooo:(o=e.match(Boo))&&(r=zoo);const i=x2.fromGlob(e,this.options).toMMPattern();return r&&typeof i=="object"&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;const e=this.set;if(!e.length)return this.regexp=!1,this.regexp;const n=this.options,o=n.noglobstar?Joo:n.dot?Koo:Qoo,r=new Set(n.nocase?["i"]:[]);let i=e.map(c=>{const l=c.map(_=>{if(_ instanceof RegExp)for(const d of _.flags.split(""))r.add(d);return typeof _=="string"?oro(_):_===O5?O5:_._src});l.forEach((_,d)=>{const m=l[d+1],h=l[d-1];_!==O5||h===O5||(h===void 0?m!==void 0&&m!==O5?l[d+1]="(?:\\/|"+o+"\\/)?"+m:l[d]=o:m===void 0?l[d-1]=h+"(?:\\/|\\/"+o+")?":m!==O5&&(l[d-1]=h+"(?:\\/|\\/"+o+"\\/)"+m,l[d+1]=O5))});const u=l.filter(_=>_!==O5);if(this.partial&&u.length>=1){const _=[];for(let d=1;d<=u.length;d++)_.push(u.slice(0,d).join("/"));return"(?:"+_.join("|")+")"}return u.join("/")}).join("|");const[s,a]=e.length>1?["(?:",")"]:["",""];i="^"+s+i+a+"$",this.partial&&(i="^(?:\\/|"+s+i.slice(1,-1)+a+")$"),this.negate&&(i="^(?!"+i+").+$");try{this.regexp=new RegExp(i,[...r].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(e){return this.preserveMultipleSlashes?e.split("/"):this.isWindows&&/^\/\/[^\/]+/.test(e)?["",...e.split(/\/+/)]:e.split(/\/+/)}match(e,n=this.partial){if(this.debug("match",e,this.pattern),this.comment)return!1;if(this.empty)return e==="";if(e==="/"&&n)return!0;const o=this.options;this.isWindows&&(e=e.split("\\").join("/"));const r=this.slashSplit(e);this.debug(this.pattern,"split",r);const i=this.set;this.debug(this.pattern,"set",i);let s=r[r.length-1];if(!s)for(let a=r.length-2;!s&&a>=0;a--)s=r[a];for(let a=0;a<i.length;a++){const c=i[a];let l=r;if(o.matchBase&&c.length===1&&(l=[s]),this.matchOne(l,c,n))return o.flipNegate?!0:!this.negate}return o.flipNegate?!1:this.negate}static defaults(e){return g2.defaults(e).Minimatch}}g2.AST=x2,g2.Minimatch=AI,g2.escape=Aoo,g2.unescape=DI;const rro=t=>(t.endsWith(".tsx")||t.endsWith(".ts")||t.endsWith(".jsx")||t.endsWith(".js")||tq(t))&&!t.endsWith(".d.ts"),iro=t=>{if(!t)return null;try{const e=JSON.parse(t);return jPt.parse(e)}catch(e){return console.warn("Failed to parse tscircuit.config.json",e),null}},sro=(t,e)=>{const o=iro(e)?.includeBoardFiles?.filter(Boolean);if(o&&o.length>0){const r=o.map(i=>new AI(i,{dot:!0}));return t.filter(i=>r.some(s=>s.match(i)))}return t.filter(rro)},Y5e=Za("run-frame:RunFrameWithApi"),aro=()=>{const e=!!eu(o=>o.error),n=e?"Dev server disconnected":"Dev server connected";return G.jsx(upt,{children:G.jsxs(_pt,{children:[G.jsx(dpt,{asChild:!0,children:G.jsx("button",{type:"button","aria-label":n,className:"rf-inline-flex rf-items-center rf-justify-center rf-p-2 rf-rounded-full rf-outline-none",children:G.jsx("span",{className:lr("rf-inline-flex rf-size-2 rf-rounded-full rf-flex-shrink-0",e?"rf-bg-red-600":"rf-bg-green-600 rf-opacity-50"),"aria-hidden":"true"})})}),G.jsx(H5e,{side:"right",children:n})]})})},lft=t=>t.find(e=>e.includes("entrypoint."))??t.find(e=>e.includes("index."))??t.find(e=>e.includes("main."))??t.find(e=>e.endsWith(".tsx")),cro=t=>t.find(e=>e.includes("manual-edits."))??t.find(e=>e.includes("manual-edit."))??t.find(e=>e.endsWith(".json")),uft=t=>{const{apiBaseUrl:e,leftHeaderContent:n}=t;Y.useEffect(()=>{t.debug&&Za.enable("run-frame*")},[t.debug]);const o=eu(O=>O.startPolling),r=eu(O=>O.stopPolling),i=eu(O=>O.setCurrentMainComponentPath),s=eu(O=>O.pushEvent),a=DZt(),c=eu(O=>O.fsMap),l=eu(O=>O.recentlySavedFiles),u=Y.useMemo(()=>Array.from(c.keys()),[c]),_=Y.useMemo(()=>{const O=c.get("tscircuit.config.json");return typeof O=="string"?O:void 0},[c]),d=Y.useMemo(()=>sro(u,_),[u,_]),m=eu(O=>O.circuitJson),[h,p]=Y.useState(()=>typeof window>"u"?t.initialMainComponentPath??"":new URLSearchParams(window.location.hash.slice(1)).get("file")??t.initialMainComponentPath??""),[x,f]=RT("runframe:favorites",[]),g=!a,y=Y.useCallback(O=>{f(z=>z.includes(O)?z.filter(V=>V!==O):[...z,O])},[f]),b=t.fileFilter??bto,v=Y.useMemo(()=>d.filter(b),[d,b]);Y.useEffect(()=>{if(h&&(v.includes(h)||d.includes(h)))return;if(h){const q=h.includes("/")?h.substring(0,h.lastIndexOf("/")):"",K=v.find(ne=>(ne.includes("/")?ne.substring(0,ne.lastIndexOf("/")):"")===q);if(K){p(K);return}}const O=window?.TSCIRCUIT_DEFAULT_MAIN_COMPONENT_PATH,z=[t.initialMainComponentPath,O].filter(q=>!!q);for(const q of z)if(v.includes(q)){p(q);return}const j=(v.length>0?v:d)[0];j&&p(j)},[v,d,t.initialMainComponentPath,h]);const S=Y.useCallback(O=>{if(typeof window>"u")return;const z=new URLSearchParams(window.location.hash.slice(1));if(z.get("file")===O)return;z.set("file",O);const V=z.toString(),j=`${window.location.pathname}${window.location.search}${V.length>0?`#${V}`:""}`;window.history.replaceState(null,"",j)},[]);Y.useEffect(()=>{h&&(S(h),t.onMainComponentPathChange?.(h),i(h))},[h,t.onMainComponentPathChange,S,i]),too();const{editEventsForRender:M,pushEditEvent:w,markRenderStarted:D,markRenderComplete:A}=EZt();Y.useEffect(()=>{e&&(window.TSCIRCUIT_FILESERVER_API_BASE_URL=e)},[e]),Y.useEffect(()=>(o(),()=>r()),[o,r]);const I=Y.useMemo(()=>String(h).length>0?{mainComponentPath:h}:{},[h]),H=Y.useCallback(async O=>{try{await s({event_type:"RUN_COMPLETED",initiator:"runframe",...O})}catch(z){Y5e("Failed to push RUN_COMPLETED event",z)}},[s]);return G.jsx(mpt,{fsMap:c,showFileMenu:t.showFileMenu,isLoadingFiles:g,evalVersion:t.evalVersion,forceLatestEvalVersion:t.forceLatestEvalVersion,evalWebWorkerBlobUrl:t.evalWebWorkerBlobUrl??t.workerBlobUrl,enableFetchProxy:t.enableFetchProxy,leftHeaderContent:G.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full",children:[G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[t.leftHeaderContent,G.jsx(aro,{})]}),t.showFilesSwitch&&G.jsx("div",{className:"rf-absolute rf-left-1/2 rf-transform rf--translate-x-1/2",children:G.jsx(Upt,{currentFile:h,files:v,onFileChange:O=>{typeof c.get(O)=="string"&&p(O)},pinnedFiles:x,onToggleFavorite:y,fileFilter:b,recentlySavedFiles:l})})]}),defaultToFullScreen:t.defaultToFullScreen,showToggleFullScreen:t.showToggleFullScreen,onInitialRender:()=>{Y5e("onInitialRender / markRenderStarted"),D()},onRenderFinished:()=>{Y5e("onRenderFinished / markRenderComplete"),A()},onRunCompleted:H,editEvents:M,onEditEvent:O=>{w(O),fetch(`${Ax}/events/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event_type:"USER_CREATED_MANUAL_EDIT",...O})});const z=cro(Array.from(c.keys()))??"manual-edits.json",V=c.get(z),j=JSON.parse(V??"{}");BHe({circuitJson:m,editEvents:[O],manualEditsFile:j}),fetch(`${Ax}/files/upsert`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:z,text_content:JSON.stringify(j),initiator:"runframe"})})},onLoginRequired:t.onLoginRequired,...I})},lro=()=>new Promise(t=>{document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>t()):t()}),uro=()=>{const t=window.location.hash.slice(1),n=new URLSearchParams(t).get("tab")?.toLowerCase()?.trim();return n&&["pcb","schematic","cad"].includes(n)?n:"pcb"},_ro=()=>{const t=document.getElementById("root");if(t)return t;const e=document.createElement("div");return e.id="root",e.style.height="100vh",document.body.appendChild(e),e},dro=async()=>{const t=Array.from(document.querySelectorAll("script[type='tscircuit-tsx']")),e=new Map;return await Promise.all(t.map(async(n,o)=>{const r=n.dataset.path||n.getAttribute("data-file-path")||`script${o?o+1:""}.tsx`;if(n.src){const s=await(await fetch(n.src)).text();e.set(r,s)}else e.set(r,n.textContent||"")})),{fsMap:e}},_ft="<--INJECT_TSCIRCUIT_EVAL_WEB_WORKER_BLOB_URL-->",q5e={evalWebWorkerBlobUrl:_ft.includes("<--")?void 0:_ft,enableFetchProxy:"<--INJECT_ENABLE_FETCH_PROXY-->".includes("<--")?void 0:!0};(async()=>{await lro();const t=c2t.createRoot(_ro()),e=window.TSCIRCUIT_RUNFRAME_STATIC_FILE_LIST,n=window.TSCIRCUIT_DEFAULT_MAIN_COMPONENT_PATH,o=window.TSCIRCUIT_PACKAGE_NAME;if(Array.isArray(e)){const r=uro();t.render(G.jsx(eoo,{files:e,initialCircuitPath:n,tabSelected:r,projectName:o}))}else if(window.TSCIRCUIT_USE_RUNFRAME_FOR_CLI)t.render(G.jsx(eno,{...q5e}));else{const{fsMap:r}=await dro();r.size>0?t.render(G.jsx(mpt,{...q5e,fsMap:r})):t.render(G.jsx(uft,{...q5e}))}})()}));
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tscircuit/runframe",
|
|
3
3
|
"main": "dist/preview.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.1891",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/preview.js",
|
|
8
8
|
"./preview": "./dist/preview.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"chokidar-cli": "^3.0.0",
|
|
65
65
|
"circuit-json-to-bom-csv": "^0.0.8",
|
|
66
66
|
"circuit-json-to-gerber": "^0.0.49",
|
|
67
|
-
"circuit-json-to-kicad": "^0.0.
|
|
67
|
+
"circuit-json-to-kicad": "^0.0.124",
|
|
68
68
|
"circuit-json-to-lbrn": "^0.0.74",
|
|
69
69
|
"circuit-json-to-pnp-csv": "^0.0.7",
|
|
70
70
|
"circuit-json-to-step": "^0.0.18",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"yargs": "^17.7.2"
|
|
114
114
|
},
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"@tscircuit/eval": "^0.0.
|
|
116
|
+
"@tscircuit/eval": "^0.0.798",
|
|
117
117
|
"@tscircuit/solver-utils": "^0.0.7"
|
|
118
118
|
}
|
|
119
119
|
}
|