@tscircuit/runframe 0.0.1971 → 0.0.1973
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.
package/dist/standalone.min.js
CHANGED
|
@@ -5734,7 +5734,7 @@ test("${l} should solve problem correctly", () => {
|
|
|
5734
5734
|
// Add more specific assertions based on expected output
|
|
5735
5735
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5736
5736
|
})
|
|
5737
|
-
`,_=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 X.jsxs("div",{className:`relative ${e}`,ref:r,children:[X.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&&X.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:[X.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),X.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),X.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},xyt=t=>t.activeSubSolver?[t,...xyt(t.activeSubSolver)]:[t],Qdo=({solver:t})=>{const e=xyt(t);return X.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>X.jsxs("div",{className:"flex items-center",children:[o>0&&X.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),X.jsx(Jdo,{solver:n})]},n.constructor.name))})},Zdo=({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 X.jsxs("div",{className:"space-y-2 p-2 border-b",children:[X.jsx("div",{className:"flex items-center",children:X.jsx(Qdo,{solver:t})}),X.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[X.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"}),X.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"}),X.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"}),X.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&&X.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"}),X.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&X.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&X.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",X.jsx("span",{className:"font-medium",children:h})]}),t.solved&&X.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&X.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&X.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},eho=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},tho=(t,e)=>{const o=t.pipelineDef[e].solverName,r=eho(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}},nho=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return X.jsx("span",{className:`font-medium ${e[t]}`,children:t})},oho=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return X.jsxs("div",{className:"flex items-center gap-2",children:[X.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:X.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),X.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},rho=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),iho=({stats:t})=>{if(!t||Object.keys(t).length===0)return X.jsx("span",{children:"-"});const e=Object.entries(t),n=rho(t);return X.jsxs("details",{className:"cursor-pointer",children:[X.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),X.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>X.jsxs("div",{children:[o,": ",String(r)]},o))})]})},RPe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(RPe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=RPe(o));return e},sho=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=RPe(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)}`)}},aho=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>tho(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):sho(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return X.jsxs("div",{className:"border-t border-gray-200",children:[X.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:X.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),X.jsx("div",{className:"overflow-x-auto",children:X.jsxs("table",{className:"w-full text-sm",children:[X.jsx("thead",{children:X.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),X.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",X.jsx("sub",{children:"0"})]}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),X.jsx("tbody",{children:o.map(a=>X.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[X.jsx("td",{className:"px-4 py-2",children:X.jsxs("div",{className:"flex items-center gap-2",children:[X.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),X.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:X.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:X.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"})})}),X.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),X.jsx("td",{className:"px-4 py-2",children:X.jsx(nho,{status:a.status})}),X.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),X.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),X.jsx("td",{className:"px-4 py-2",children:X.jsx(oho,{progress:a.progress})}),X.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),X.jsx("td",{className:"px-4 py-2 text-gray-500",children:X.jsx(iho,{stats:a.stats})}),X.jsx("td",{className:"px-4 py-2",children:a.solverInstance?X.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:[X.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:X.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"})}),X.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},cho=class extends fr.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 lho({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 X.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)=>X.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)=>X.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)=>X.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)=>X.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)=>X.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var uho=({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 X.jsxs("div",{children:[X.jsx(Zdo,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?X.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):X.jsx(cho,{fallback:X.jsx(lho,{graphics:s}),children:X.jsx(Kdo,{graphics:s})}),c&&X.jsx(aho,{solver:t,onStepUntilPhase:l})]})};const _ho=()=>{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)},[])},dho=t=>t.toLowerCase().includes("pack")?ZGn:t.toLowerCase().includes("rout")?rYn:FGn,hho=({solverEvents:t=[]})=>{const[e,n]=Y.useState(null);_ho();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=x0e[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(x0e).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?X.jsx("div",{className:"rf-p-4",children:X.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),X.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."})]})})}):X.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[X.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[X.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 X.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=dho(c.solverName);return X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),X.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[X.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),X.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),X.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?X.jsx(x3,{fallback:X.jsx("div",{className:"rf-p-4",children:X.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),X.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:X.jsx(uho,{solver:s.instance})}):X.jsxs("div",{className:"rf-p-4",children:[X.jsxs("div",{className:"rf-mb-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),X.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&X.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:X.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),X.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[X.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:X.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),X.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:X.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)})})]})]}):X.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:X.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},gyt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Y.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{CG.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{CG.captureException(r,{error_type:o.type})}catch{}}},[n])},yyt="0.0.1970",mho={version:yyt},_Q=SGe()(CGe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),pho=t=>{const[e,n]=Y.useState([]),[o,r]=Y.useState(null),[i,s]=Y.useState(""),[a,c]=qE("eval-version-selection",null),l=_Q(m=>m.setLastRunEvalVersion),u=_Q(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("")}}},fho=({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 X.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:X.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[X.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),X.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}),X.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>X.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&&X.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,'"']})]}),X.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[X.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),X.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}`})]})]})})},xho=t=>{const e=Y.useRef(null),n=v0(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 gho(t){const e=yho(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(Pho);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 X.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return X.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function yho(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=Sho(r),a=vho(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?vg(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 bho=Symbol("radix.slottable");function Pho(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===bho}function vho(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 Sho(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 dQ="Dialog",[byt,Pyt]=_b(dQ),[Cho,Ob]=byt(dQ),vyt=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]=ZS({prop:o,defaultProp:r??!1,onChange:i,caller:dQ});return X.jsx(Cho,{scope:e,triggerRef:a,contentRef:c,contentId:Df(),titleId:Df(),descriptionId:Df(),open:l,onOpenChange:u,onOpenToggle:Y.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};vyt.displayName=dQ;var Syt="DialogTrigger",Cyt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(Syt,n),i=S0(e,r.triggerRef);return X.jsx(Uc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":HPe(r.open),...o,ref:i,onClick:Qr(t.onClick,r.onOpenToggle)})});Cyt.displayName=Syt;var NPe="DialogPortal",[Mho,Myt]=byt(NPe,{forceMount:void 0}),Tyt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=Ob(NPe,e);return X.jsx(Mho,{scope:e,forceMount:n,children:Y.Children.map(o,s=>X.jsx(Dy,{present:n||i.open,children:X.jsx(NK,{asChild:!0,container:r,children:s})}))})};Tyt.displayName=NPe;var hQ="DialogOverlay",wyt=Y.forwardRef((t,e)=>{const n=Myt(hQ,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=Ob(hQ,t.__scopeDialog);return i.modal?X.jsx(Dy,{present:o||i.open,children:X.jsx(who,{...r,ref:e})}):null});wyt.displayName=hQ;var Tho=gho("DialogOverlay.RemoveScroll"),who=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(hQ,n);return X.jsx(VK,{as:Tho,allowPinchZoom:!0,shards:[r.contentRef],children:X.jsx(Uc.div,{"data-state":HPe(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),$M="DialogContent",Eyt=Y.forwardRef((t,e)=>{const n=Myt($M,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=Ob($M,t.__scopeDialog);return X.jsx(Dy,{present:o||i.open,children:i.modal?X.jsx(Eho,{...r,ref:e}):X.jsx(Dho,{...r,ref:e})})});Eyt.displayName=$M;var Eho=Y.forwardRef((t,e)=>{const n=Ob($M,t.__scopeDialog),o=Y.useRef(null),r=S0(e,n.contentRef,o);return Y.useEffect(()=>{const i=o.current;if(i)return wbe(i)},[]),X.jsx(Dyt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Qr(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Qr(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:Qr(t.onFocusOutside,i=>i.preventDefault())})}),Dho=Y.forwardRef((t,e)=>{const n=Ob($M,t.__scopeDialog),o=Y.useRef(!1),r=Y.useRef(!1);return X.jsx(Dyt,{...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()}})}),Dyt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=Ob($M,n),c=Y.useRef(null),l=S0(e,c);return cbe(),X.jsxs(X.Fragment,{children:[X.jsx(bK,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:X.jsx(oO,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":HPe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),X.jsxs(X.Fragment,{children:[X.jsx(kho,{titleId:a.titleId}),X.jsx(Nho,{contentRef:c,descriptionId:a.descriptionId})]})]})}),IPe="DialogTitle",Ayt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(IPe,n);return X.jsx(Uc.h2,{id:r.titleId,...o,ref:e})});Ayt.displayName=IPe;var kyt="DialogDescription",Ryt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(kyt,n);return X.jsx(Uc.p,{id:r.descriptionId,...o,ref:e})});Ryt.displayName=kyt;var Nyt="DialogClose",Iyt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(Nyt,n);return X.jsx(Uc.button,{type:"button",...o,ref:e,onClick:Qr(t.onClick,()=>r.onOpenChange(!1))})});Iyt.displayName=Nyt;function HPe(t){return t?"open":"closed"}var Hyt="DialogTitleWarning",[Aho,Lyt]=Rfn(Hyt,{contentName:$M,titleName:IPe,docsSlug:"dialog"}),kho=({titleId:t})=>{const e=Lyt(Hyt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5737
|
+
`,_=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 X.jsxs("div",{className:`relative ${e}`,ref:r,children:[X.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&&X.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:[X.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:i,children:"Download JSON"}),X.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),X.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},xyt=t=>t.activeSubSolver?[t,...xyt(t.activeSubSolver)]:[t],Qdo=({solver:t})=>{const e=xyt(t);return X.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>X.jsxs("div",{className:"flex items-center",children:[o>0&&X.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),X.jsx(Jdo,{solver:n})]},n.constructor.name))})},Zdo=({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 X.jsxs("div",{className:"space-y-2 p-2 border-b",children:[X.jsx("div",{className:"flex items-center",children:X.jsx(Qdo,{solver:t})}),X.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[X.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"}),X.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"}),X.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"}),X.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&&X.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"}),X.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&X.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&X.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",X.jsx("span",{className:"font-medium",children:h})]}),t.solved&&X.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&X.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&X.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},eho=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},tho=(t,e)=>{const o=t.pipelineDef[e].solverName,r=eho(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}},nho=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return X.jsx("span",{className:`font-medium ${e[t]}`,children:t})},oho=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return X.jsxs("div",{className:"flex items-center gap-2",children:[X.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:X.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),X.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},rho=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),iho=({stats:t})=>{if(!t||Object.keys(t).length===0)return X.jsx("span",{children:"-"});const e=Object.entries(t),n=rho(t);return X.jsxs("details",{className:"cursor-pointer",children:[X.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),X.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,r])=>X.jsxs("div",{children:[o,": ",String(r)]},o))})]})},RPe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(RPe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=RPe(o));return e},sho=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=RPe(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)}`)}},aho=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>tho(t,c)),r=a=>{e?.(a)},i=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):sho(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return X.jsxs("div",{className:"border-t border-gray-200",children:[X.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:X.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),X.jsx("div",{className:"overflow-x-auto",children:X.jsxs("table",{className:"w-full text-sm",children:[X.jsx("thead",{children:X.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),X.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",X.jsx("sub",{children:"0"})]}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),X.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),X.jsx("tbody",{children:o.map(a=>X.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[X.jsx("td",{className:"px-4 py-2",children:X.jsxs("div",{className:"flex items-center gap-2",children:[X.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),X.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:X.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:X.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"})})}),X.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),X.jsx("td",{className:"px-4 py-2",children:X.jsx(nho,{status:a.status})}),X.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),X.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),X.jsx("td",{className:"px-4 py-2",children:X.jsx(oho,{progress:a.progress})}),X.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),X.jsx("td",{className:"px-4 py-2 text-gray-500",children:X.jsx(iho,{stats:a.stats})}),X.jsx("td",{className:"px-4 py-2",children:a.solverInstance?X.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:[X.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:X.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"})}),X.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},cho=class extends fr.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 lho({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 X.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)=>X.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)=>X.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)=>X.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)=>X.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)=>X.jsx("text",{x:x.x??0,y:x.y??0,fontSize:x.fontSize??10,fill:x.color??"black",children:x.text??""},`text-${f}`))]})}var uho=({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 X.jsxs("div",{children:[X.jsx(Zdo,{solver:t,triggerRender:i,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?X.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):X.jsx(cho,{fallback:X.jsx(lho,{graphics:s}),children:X.jsx(Kdo,{graphics:s})}),c&&X.jsx(aho,{solver:t,onStepUntilPhase:l})]})};const _ho=()=>{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)},[])},dho=t=>t.toLowerCase().includes("pack")?ZGn:t.toLowerCase().includes("rout")?rYn:FGn,hho=({solverEvents:t=[]})=>{const[e,n]=Y.useState(null);_ho();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=x0e[i.solverName];if(!a)return{instance:null,error:`Solver class "${i.solverName}" not found in SOLVERS registry. Available: ${Object.keys(x0e).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?X.jsx("div",{className:"rf-p-4",children:X.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),X.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."})]})})}):X.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[X.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[X.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 X.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=dho(c.solverName);return X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),X.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[X.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),X.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),X.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:i?s.instance?X.jsx(x3,{fallback:X.jsx("div",{className:"rf-p-4",children:X.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),X.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",i.solverName]})]})}),children:X.jsx(uho,{solver:s.instance})}):X.jsxs("div",{className:"rf-p-4",children:[X.jsxs("div",{className:"rf-mb-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:i.solverName}),X.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",i.componentName]})]}),s.error&&X.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:X.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),X.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[X.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:X.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),X.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:X.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)})})]})]}):X.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:X.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},gyt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Y.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{CG.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{CG.captureException(r,{error_type:o.type})}catch{}}},[n])},yyt="0.0.1972",mho={version:yyt},_Q=SGe()(CGe(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),pho=t=>{const[e,n]=Y.useState([]),[o,r]=Y.useState(null),[i,s]=Y.useState(""),[a,c]=qE("eval-version-selection",null),l=_Q(m=>m.setLastRunEvalVersion),u=_Q(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("")}}},fho=({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 X.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:X.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[X.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),X.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}),X.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(_=>X.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&&X.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,'"']})]}),X.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[X.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),X.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}`})]})]})})},xho=t=>{const e=Y.useRef(null),n=v0(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 gho(t){const e=yho(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(Pho);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 X.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return X.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function yho(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=Sho(r),a=vho(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?vg(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 bho=Symbol("radix.slottable");function Pho(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===bho}function vho(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 Sho(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 dQ="Dialog",[byt,Pyt]=_b(dQ),[Cho,Ob]=byt(dQ),vyt=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]=ZS({prop:o,defaultProp:r??!1,onChange:i,caller:dQ});return X.jsx(Cho,{scope:e,triggerRef:a,contentRef:c,contentId:Df(),titleId:Df(),descriptionId:Df(),open:l,onOpenChange:u,onOpenToggle:Y.useCallback(()=>u(_=>!_),[u]),modal:s,children:n})};vyt.displayName=dQ;var Syt="DialogTrigger",Cyt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(Syt,n),i=S0(e,r.triggerRef);return X.jsx(Uc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":HPe(r.open),...o,ref:i,onClick:Qr(t.onClick,r.onOpenToggle)})});Cyt.displayName=Syt;var NPe="DialogPortal",[Mho,Myt]=byt(NPe,{forceMount:void 0}),Tyt=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:r}=t,i=Ob(NPe,e);return X.jsx(Mho,{scope:e,forceMount:n,children:Y.Children.map(o,s=>X.jsx(Dy,{present:n||i.open,children:X.jsx(NK,{asChild:!0,container:r,children:s})}))})};Tyt.displayName=NPe;var hQ="DialogOverlay",wyt=Y.forwardRef((t,e)=>{const n=Myt(hQ,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=Ob(hQ,t.__scopeDialog);return i.modal?X.jsx(Dy,{present:o||i.open,children:X.jsx(who,{...r,ref:e})}):null});wyt.displayName=hQ;var Tho=gho("DialogOverlay.RemoveScroll"),who=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(hQ,n);return X.jsx(VK,{as:Tho,allowPinchZoom:!0,shards:[r.contentRef],children:X.jsx(Uc.div,{"data-state":HPe(r.open),...o,ref:e,style:{pointerEvents:"auto",...o.style}})})}),$M="DialogContent",Eyt=Y.forwardRef((t,e)=>{const n=Myt($M,t.__scopeDialog),{forceMount:o=n.forceMount,...r}=t,i=Ob($M,t.__scopeDialog);return X.jsx(Dy,{present:o||i.open,children:i.modal?X.jsx(Eho,{...r,ref:e}):X.jsx(Dho,{...r,ref:e})})});Eyt.displayName=$M;var Eho=Y.forwardRef((t,e)=>{const n=Ob($M,t.__scopeDialog),o=Y.useRef(null),r=S0(e,n.contentRef,o);return Y.useEffect(()=>{const i=o.current;if(i)return wbe(i)},[]),X.jsx(Dyt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Qr(t.onCloseAutoFocus,i=>{i.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Qr(t.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:Qr(t.onFocusOutside,i=>i.preventDefault())})}),Dho=Y.forwardRef((t,e)=>{const n=Ob($M,t.__scopeDialog),o=Y.useRef(!1),r=Y.useRef(!1);return X.jsx(Dyt,{...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()}})}),Dyt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:r,onCloseAutoFocus:i,...s}=t,a=Ob($M,n),c=Y.useRef(null),l=S0(e,c);return cbe(),X.jsxs(X.Fragment,{children:[X.jsx(bK,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:X.jsx(oO,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":HPe(a.open),...s,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),X.jsxs(X.Fragment,{children:[X.jsx(kho,{titleId:a.titleId}),X.jsx(Nho,{contentRef:c,descriptionId:a.descriptionId})]})]})}),IPe="DialogTitle",Ayt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(IPe,n);return X.jsx(Uc.h2,{id:r.titleId,...o,ref:e})});Ayt.displayName=IPe;var kyt="DialogDescription",Ryt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(kyt,n);return X.jsx(Uc.p,{id:r.descriptionId,...o,ref:e})});Ryt.displayName=kyt;var Nyt="DialogClose",Iyt=Y.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,r=Ob(Nyt,n);return X.jsx(Uc.button,{type:"button",...o,ref:e,onClick:Qr(t.onClick,()=>r.onOpenChange(!1))})});Iyt.displayName=Nyt;function HPe(t){return t?"open":"closed"}var Hyt="DialogTitleWarning",[Aho,Lyt]=Rfn(Hyt,{contentName:$M,titleName:IPe,docsSlug:"dialog"}),kho=({titleId:t})=>{const e=Lyt(Hyt),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
|
|
5738
5738
|
|
|
5739
5739
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5740
5740
|
|
|
@@ -5821,6 +5821,6 @@ Please report this to https://github.com/markedjs/marked.`,t){const o="<p>An err
|
|
|
5821
5821
|
rf-max-h-[90vh] rf-overflow-y-auto
|
|
5822
5822
|
`,children:X.jsx("div",{className:"rf-relative rf-w-full",children:n==="initial"&&X.jsx(v1o,{onCancel:e,packageReleaseId:i??"",signIn:s??(()=>{}),isLoggedIn:a})})})})}),E1o=({isOpen:t,onClose:e,stage:n,setStage:o,signIn:r,isLoggedIn:i})=>{const s=v0(a=>a.circuitJson);return X.jsx(w1o,{signIn:r,isOpen:t,onClose:e,stage:n,setStage:o,circuitJson:s,isLoggedIn:i??!1})},D1o=()=>{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:E1o}};async function v3t(){const t=await fetch(`${X2}/files/list`),{file_list:e}=await t.json(),n=new Map;for(const o of e){const i=await(await fetch(`${X2}/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 A1o="https://api.tscircuit.com/bug_reports/view?bug_report_id=",k1o=t=>`${A1o}${t}`,R1o=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(()=>CQ()?!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:
|
|
5823
5823
|
|
|
5824
|
-
${S}`)}},[e,d]),Y.useEffect(()=>{e&&!d&&v3t().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=f8(),M=_.current?.value||"";try{const T=await v3t();if(T.size===0){Ss.error("No project files available to include in the bug report"),r(!1);return}const D=new Date(Date.now()+1440*60*1e3).toISOString(),L=(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(T.entries()),F=[];for(let V=0;V<H.length;V++){const[G,K]=H[V];c({current:V+1,total:H.length,currentFile:G});try{const Q={bug_report_id:L,file_path:G};K.text_content&&(Q.content_text=K.text_content),K.binary_content_b64&&(Q.content_base64=K.binary_content_b64),await S.post("bug_reports/upload_file",{json:Q})}catch(Q){const oe=Q instanceof p8?`HTTP ${Q.response.status}`:Q instanceof Error?Q.message:"Upload failed";F.push({filePath:G,message:oe}),u([...F])}}c(null);const B=k1o(L);m({bugReportUrl:B})}catch(T){if(console.error("Failed to submit bug report",T),T instanceof p8)if(T.response.status===401)if(f){const D="Your session has expired. Please sign in again to continue.";s(D),Ss.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),Ss.error(D),setTimeout(()=>{x&&(y(),x())},1e3)}else{const D=`Failed to submit bug report (${T.response.status})`;s(D),Ss.error(D)}else if(T instanceof Error)s(T.message),Ss.error(T.message);else{const D="Failed to submit bug report";s(D),Ss.error(D)}}finally{r(!1)}},[f,x]);return{BugReportDialog:Y.useMemo(()=>{const S=a?Math.round(a.current/a.total*100):0;return X.jsx(n5t,{open:e,onOpenChange:M=>{M?(s(null),m(null),c(null),u([]),n(!0)):o||y()},children:X.jsxs(zPe,{children:[X.jsxs(VPe,{children:[X.jsx(WPe,{children:d?"Bug Report Created":"Report Bug"}),X.jsx(jPe,{asChild:!0,children:d?X.jsxs("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:[X.jsx("p",{children:"Bug report created successfully."}),l.length>0&&X.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:[X.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,T)=>X.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[X.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),X.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},T))]}),X.jsx("div",{children:X.jsx("a",{className:"rf-text-blue-600 hover:rf-underline",href:d.bugReportUrl,target:"_blank",rel:"noreferrer",children:"View bug report"})}),X.jsxs("p",{children:["Please share this link privately with tscircuit staff so we can help debug. Join the",X.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"}),"."]})]}):X.jsx("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:a?X.jsxs("div",{className:"rf-space-y-2 rf-overflow-hidden",children:[X.jsxs("div",{className:"rf-flex rf-justify-between rf-text-xs",children:[X.jsx("span",{children:"Uploading files..."}),X.jsxs("span",{children:[a.current,"/",a.total]})]}),X.jsx("div",{className:"rf-w-full rf-h-2 rf-bg-gray-200 rf-rounded-full rf-overflow-hidden",children:X.jsx("div",{className:"rf-h-full rf-bg-blue-500 rf-transition-all rf-duration-150",style:{width:`${S}%`}})}),X.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&&X.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,T)=>X.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[X.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),X.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},T))})]}):X.jsxs(X.Fragment,{children:[X.jsxs("p",{children:["Reporting a bug will upload your entire project",h>0?` (${h} file${h===1?"":"s"})`:""," ","to tscircuit support."]}),X.jsxs("div",{className:"rf-space-y-2",children:[X.jsx("label",{htmlFor:"bug-description",className:"rf-block rf-font-medium",children:"Description (optional)"}),X.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})]}),X.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",X.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&&X.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&&X.jsx("p",{className:"rf-text-red-600",children:i})]})})})]}),X.jsx($Pe,{children:d?X.jsx("button",{type:"button",className:IA(),onClick:()=>{y()},children:"Close"}):X.jsxs(X.Fragment,{children:[X.jsx(UPe,{disabled:o,onClick:()=>{o||y()},children:"Cancel"}),!f&&x?X.jsx("button",{type:"button",className:IA(),onClick:M=>{M.preventDefault(),y(),x()},children:"Sign In"}):X.jsx("button",{type:"button",className:db(IA(),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 N1o({open:t,onOpenChange:e,onExport:n}){const[o,r]=Y.useState(!1),i=()=>{n({includeSilkscreen:o}),e(!1)},s=()=>{e(!1)};return X.jsx(pk,{open:t,onOpenChange:e,children:X.jsxs(WM,{children:[X.jsxs(jM,{children:[X.jsx(UM,{children:"LightBurn Export Options"}),X.jsx(fk,{children:"Configure export settings for PCB laser ablation with LightBurn"})]}),X.jsx("div",{className:"rf-flex rf-flex-col rf-gap-4 rf-py-4",children:X.jsxs("div",{className:"rf-flex rf-items-center rf-space-x-2",children:[X.jsx(_F,{id:"includeSilkscreen",checked:o,onCheckedChange:a=>r(a===!0)}),X.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"})]})}),X.jsxs(dF,{children:[X.jsx(kc,{variant:"outline",onClick:s,children:"Cancel"}),X.jsx(kc,{onClick:i,children:"Export"})]})]})})}const I1o=/#(\d+)/,H1o=t=>{const e=t.match(I1o);if(!e)return null;const n=Number.parseInt(e[1],10);return Number.isFinite(n)?n:null},L1o=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},O1o=t=>{if(!t)return null;let e=null,n=-1,o=-1;for(const[r,i]of Object.entries(t)){const s=H1o(r),a=L1o(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},vF=t=>{const e=_Q(Ee=>Ee.lastRunEvalVersion),n=v0(Ee=>Ee.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,T]=Y.useState(!1),[D,A]=Y.useState(!1),[L,H]=Y.useState(null),F=D1o(),B=v0(Ee=>Ee.pushEvent),V=v0(Ee=>Ee.recentEvents),G=Y.useMemo(()=>Date.now(),[]);xho(Ee=>{if(!(new Date(Ee.created_at).valueOf()<G+500)){if(Ee.event_type==="FILE_UPDATED"){s(!0);return}if(Ee.event_type==="SNIPPET_SAVED"){s(!1),c(!1),g("Snippet saved successfully."),S(!1);return}Ee.event_type==="REQUEST_EXPORT"&&(T(!0),g("Export processing..."),S(!1)),Ee.event_type==="EXPORT_CREATED"&&(g(`Export created: ${Ee.exportFilePath}`),S(!1),T(!1))}}),Y.useEffect(()=>{if(!l||_===null)return;const Ee=V.filter(xe=>new Date(xe.created_at).valueOf()>_),_e=Ee.find(xe=>xe.event_type==="FAILED_TO_SAVE_SNIPPET"),Ce=Ee.find(xe=>xe.event_type==="SNIPPET_SAVED");_e&&(u(!1),d(null),b(_e.message??"Failed to save snippet. See console for error."),console.error(_e.message),S(!0),_e.error_code==="SNIPPET_UNSET"&&_e.available_snippet_names&&(h(_e.available_snippet_names),x(!0))),Ce&&(u(!1),d(null),g("Snippet saved successfully."),S(!1))},[V,l]);const K=async()=>{u(!0),d(Date.now()),g(null),S(!1),await B({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:o})},oe=v0(Ee=>Ee.circuitJson)??t.circuitJson,[ue,ne]=Y.useState(!1),[re,ae]=Y.useState(!1),{BugReportDialog:ie,openBugReportDialog:de}=R1o({onLoginRequired:t.onLoginRequired}),be=async Ee=>{L&&(await k5t({circuitJson:L.circuitJson,projectName:L.projectName,options:Ee}),H(null))},Me=Y.useMemo(()=>O1o(t.autoroutingLog),[t.autoroutingLog]);return X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1 rf-flex-shrink-0",children:[X.jsxs(XK,{children:[X.jsx(GK,{asChild:!0,children:X.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"File"})}),X.jsxs(mO,{className:"rf-z-[101]",children:[!t.isWebEmbedded&&X.jsxs(X.Fragment,{children:[X.jsx(Qd,{className:"rf-text-xs",onSelect:K,disabled:l,children:l?"Saving...":"Push"}),parseInt(window.location.port)>5e3&&X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{F.open()},children:"Order"}),X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>ne(!0),disabled:l,children:"Import"}),X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{if(!CQ()){Ss.error("Requires tscircuit token");return}ae(!0)},children:"AI Review"})]}),!t.isWebEmbedded&&t.onLoginRequired&&X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{t.onLoginRequired?.()},children:"Sign In"}),!t.isWebEmbedded&&X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",children:"Report Bug"}),X.jsx(dO,{children:X.jsxs(XA,{children:[X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{de()},children:"Report Entire Circuit"}),X.jsx(Qd,{className:"rf-text-xs",disabled:!Me||!t.onReportAutoroutingLog,onSelect:()=>{!Me||!t.onReportAutoroutingLog||t.onReportAutoroutingLog(Me.key,{simpleRouteJson:Me.value.simpleRouteJson})},children:"Report Autorouter Bug"})]})})]}),X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",disabled:M,children:M?"Exporting...":"Export"}),X.jsx(dO,{children:X.jsx(XA,{children:Apo.map((Ee,_e)=>X.jsx(Qd,{onSelect:()=>{if(!oe){Ss.error("No Circuit JSON to export");return}let Ce="Untitled";if(n){const Fe=n.split("/").pop();Fe&&(Ce=Fe.replace(/\.[^.]+$/,""))}const xe=t.projectName??o??Ce;if(Ee.name==="LightBurn"){H({circuitJson:oe,projectName:xe}),A(!0);return}kpo({exportName:Ee.name,circuitJson:oe,projectName:xe?.replace(/\.(board|circuit)$/,"")})},disabled:M,children:X.jsx("span",{className:"rf-text-xs",children:Ee.name})},_e))})})]}),!t.isWebEmbedded&&X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",children:"Advanced"}),X.jsx(dO,{children:X.jsxs(XA,{children:[X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",children:X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(_F,{id:"load-latest-eval",checked:t.shouldLoadLatestEval,onCheckedChange:Ee=>{t.onChangeShouldLoadLatestEval?.(Ee===!0)}}),X.jsx("label",{htmlFor:"load-latest-eval",className:"rf-text-xs rf-cursor-pointer",children:"Force Latest @tscircuit/eval"})]})}),e&&X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",children:X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:X.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/eval@",e]})})}),X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",children:X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:X.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/runframe@",mho.version]})})}),X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",onClick:()=>{window.open("/api/admin","_blank")},children:X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:X.jsx("span",{className:"rf-text-xs",children:"CLI Admin Panel"})})})]})})]})]}),X.jsx(n5t,{open:v,onOpenChange:S,children:X.jsxs(zPe,{children:[X.jsxs(VPe,{children:[X.jsx(WPe,{children:"Error Saving Snippet"}),X.jsx(jPe,{children:y})]}),X.jsx($Pe,{children:X.jsx(UPe,{onClick:()=>S(!1),children:"Dismiss"})})]})}),X.jsx(fho,{snippetNames:m??[],onSelect:async Ee=>{u(!0),d(Date.now()),r(Ee),await B({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:Ee}),x(!1)},onCancel:()=>x(!1),isOpen:p})]}),X.jsxs(XK,{children:[X.jsx(GK,{asChild:!0,children:X.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"View"})}),X.jsx(mO,{className:"rf-z-[104]",children:X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",children:"Schematic"}),X.jsx(dO,{children:X.jsxs(XA,{children:[X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",onSelect:Ee=>Ee.preventDefault(),children:X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(_F,{id:"show-schematic-ports",checked:t.showSchematicPorts,onCheckedChange:Ee=>{t.onChangeShowSchematicPorts?.(Ee===!0)}}),X.jsx("label",{htmlFor:"show-schematic-ports",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Ports"})]})}),X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",onSelect:Ee=>Ee.preventDefault(),children:X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(_F,{id:"show-schematic-grid",checked:t.showSchematicDebugGrid,onCheckedChange:Ee=>{t.onChangeShowSchematicDebugGrid?.(Ee===!0)}}),X.jsx("label",{htmlFor:"show-schematic-grid",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Grid"})]})})]})})]})})]})]}),ie,X.jsx(N1o,{open:D,onOpenChange:A,onExport:be}),X.jsx(E5t,{isOpen:ue,onClose:()=>ne(!1)}),X.jsx(Bfo,{isOpen:re,onClose:()=>ae(!1),packageName:o}),X.jsx(Xlt,{position:"top-center",reverseOrder:!1,containerStyle:{zIndex:1e5},toastOptions:{className:"rf-break-all",style:{zIndex:1e5}}}),X.jsx(F.OrderDialog,{isOpen:F.isOpen,onClose:F.close,stage:F.stage,setStage:F.setStage})]})},F1o=["assembly","pinout","analog_simulation","bom","circuit_json","errors","render_log","solvers"],S3t=({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:T,editEvents:D,defaultActiveTab:A,defaultTab:L,availableTabs:H,autoRotate3dViewerDisabled:F,showSchematicDebugGrid:B=!1,showSchematicPorts:V=!1,onChangeShowSchematicDebugGrid:G,onChangeShowSchematicPorts:K,showToggleFullScreen:Q=!0,defaultToFullScreen:oe=!1,activeEffectName:ue,allowSelectingVersion:ne=!0,showFileMenu:re=!1,isWebEmbedded:ae=!1,projectName:ie,onRerunWithDebug:de,solverEvents:be,onPcbBoundsSelected:Me})=>{cQ();const{versions:Ee,latestVersion:_e,lastRunEvalVersion:Ce,search:xe,setSearch:Fe,selectVersion:We}=pho(ne),Xe=Y.useMemo(()=>i?i.filter(kt=>kt&&"error_type"in kt||kt.type.includes("error")):null,[i]),ye=Y.useMemo(()=>i?i.filter(kt=>kt&&"warning_type"in kt||kt.type.includes("warning")):null,[i]),Je=Y.useMemo(()=>i?i.some(kt=>kt.type==="schematic_group"):!0,[i]),Be=Y.useMemo(()=>i?.some(kt=>kt.type==="pcb_panel"),[i]);gyt({errorMessage:o,errorStack:r,circuitJsonErrors:Xe});const ke=L??H?.[0]??"pcb",[Ve,Ie]=qE("runframe-active-tab",A??ke,A),[Te,Ae]=Y.useState(null),[De,$e]=Y.useState(oe),[je,nt]=Y.useState(B),[rt,st]=Y.useState(V),ut=G?B:je,xt=K?V:rt,Et=G??nt,Bt=K??st;D_o(De);const Gt=Y.useCallback(kt=>{Ie(kt),d?.(kt)},[d,Ie]),Ft=()=>{$e(!De)};Y.useEffect(()=>{o&&(Ve!=="errors"&&Ae(Ve),Gt("errors"))},[o]),Y.useEffect(()=>{(Ve==="code"||Ve==="errors")&&i&&!o&&Gt(Te??A??L??H?.[0]??"pcb")},[i]);const ln=Y.useCallback(kt=>{window.TSCIRCUIT_3D_OBJECT_REF=kt===null?void 0:kt},[]);return X.jsx("div",{className:yr("flex flex-col relative rf-overflow-x-hidden rf-h-full",p),children:X.jsx("div",{className:yr("rf-md:sticky rf-md:top-2 rf-h-full",De&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-h-full rf-bg-white rf-overflow-hidden"),children:X.jsxs(q_e,{value:Ve,onValueChange:Gt,className:"rf-flex-grow rf-flex rf-flex-col rf-h-full",children:[X.jsxs("div",{className:yr("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",x),children:[f,re&&!f&&X.jsx(vF,{isWebEmbedded:ae,circuitJson:i,projectName:ie,showSchematicDebugGrid:ut,onChangeShowSchematicDebugGrid:Et,showSchematicPorts:xt,onChangeShowSchematicPorts:Bt}),(f||re)&&X.jsx("div",{className:"rf-flex-grow"}),!f&&!re&&S&&X.jsx(Qv,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!f&&!re&&X.jsx("div",{className:"rf-flex-grow"}),m&&m.progress!==1&&!o&&X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-min-w-0 rf-max-w-xs",children:[ue?X.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:ue,children:ue}):m.lastRenderEvent&&X.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:m.lastRenderEvent?.phase??"",children:m.lastRenderEvent?.phase??""}),X.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:X.jsx(Qv,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),X.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&&X.jsxs(TG,{children:[c&&X.jsx(W4,{value:"code",children:"Code"}),!H||H.includes("pcb")?X.jsxs(W4,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&X.jsx("span",{className:yr("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")?X.jsxs(W4,{value:"schematic",className:yr("rf-whitespace-nowrap",i&&!Je&&"rf-opacity-50"),disabled:i?!Je||Be:!1,children:[i&&X.jsx("span",{className:yr("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")?X.jsxs(W4,{value:"cad",children:[i&&X.jsx("span",{className:yr("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(Ve)&&X.jsx(W4,{value:Ve,children:wKe(Ve)}),X.jsxs(XK,{children:[X.jsx(GK,{asChild:!0,children:X.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[X.jsx(GGn,{className:"rf-w-4 rf-h-4"}),(Xe&&Xe.length>0||o)&&X.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"})]})}),X.jsxs(mO,{className:"rf-*:text-xs rf-z-[101]",children:[F1o.filter(kt=>!H||H.includes(kt)).map(kt=>X.jsxs(Qd,{onSelect:()=>Gt(kt),children:[Ve!==kt&&X.jsx(Qht,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Ve===kt&&X.jsx(gM,{className:"rf-w-3 rf-h-3"}),X.jsx("div",{className:"rf-pr-2",children:wKe(kt)}),kt==="errors"&&(Xe&&Xe.length>0||o)&&X.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}),kt==="solvers"&&be&&be.length>0&&X.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})]},kt)),X.jsx(Qd,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:X.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",yyt.split(".").map((kt,bn)=>bn===2?parseInt(kt)+1:kt).join(".")]})}),ne?X.jsxs(hO,{onOpenChange:kt=>!kt&&Fe(""),children:[X.jsx(UA,{className:"rf-text-xs rf-opacity-60",children:X.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",Ce??_e??"latest"]})}),X.jsx(dO,{children:X.jsxs(XA,{className:"rf-*:text-xs rf-w-40 rf-max-h-[200px] rf-overflow-y-auto",children:[X.jsx("div",{className:"rf-p-1",children:X.jsx(z4e,{value:xe,onChange:kt=>Fe(kt.target.value),placeholder:"Search...",className:"rf-h-7 rf-text-xs"})}),X.jsx(Zpt,{}),X.jsx(Qd,{onSelect:()=>We(null),children:_e?`${_e} (latest)`:"latest"}),Ee.map(kt=>X.jsx(Qd,{onSelect:()=>We(kt),children:kt},kt))]})})]}):Ce&&X.jsx(Qd,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:X.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",Ce]})})]})]})]}),Q&&X.jsx(kc,{onClick:Ft,variant:"ghost",children:De?X.jsx(nYn,{size:16}):X.jsx(QGn,{size:16})})]}),c&&X.jsx(j1,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:X.jsx("div",{className:"rf-h-full",children:l})}),(!H||H.includes("pcb"))&&X.jsx(j1,{value:"pcb",children:X.jsx("div",{className:yr("rf-overflow-hidden",De?"rf-h-[calc(100vh-52px)]":"rf-h-full"),children:X.jsx(x3,{fallbackRender:({error:kt})=>X.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),X.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:kt?.message||"An unknown error occurred"})]})}),children:i?X.jsx(w_o,{focusOnHover:!1,circuitJson:i,debugGraphics:s,onBoundsSelected:Me,containerClassName:yr("rf-h-full rf-w-full",De?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:kt=>{if(T)for(const bn of kt)T(bn)}}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("assembly"))&&X.jsx(j1,{value:"assembly",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Assembly"}),children:i?X.jsx(lso,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("pinout"))&&X.jsx(j1,{value:"pinout",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Pinout Viewer"}),children:i?X.jsx(uso,{circuitJson:i,containerStyle:{height:"100%"}}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("schematic"))&&X.jsx(j1,{value:"schematic",children:X.jsx("div",{className:yr("rf-overflow-auto rf-bg-white",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallbackRender:({error:kt})=>X.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),X.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:kt?.message||"An unknown error occurred"})]})}),children:i?X.jsx(aso,{spiceSimulationEnabled:!0,circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:kt=>{T?.(kt)},debugGrid:ut,showSchematicPorts:xt}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("cad"))&&X.jsx(j1,{value:"cad",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallbackRender:({error:kt,resetErrorBoundary:bn})=>X.jsx(EGn,{error:kt,resetErrorBoundary:bn}),children:i?X.jsx(gGn,{ref:ln,circuitJson:i,autoRotateDisabled:F},`cad-${De}`):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("analog_simulation"))&&X.jsx(j1,{value:"analog_simulation",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Analog Simulation"}),children:i?X.jsx(cso,{circuitJson:i,containerStyle:{height:"100%"}}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("bom"))&&X.jsx(j1,{value:"bom",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallbackRender:({error:kt})=>X.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),X.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:kt?.message||"An unknown error occurred"})]})}),children:i?X.jsx(Tso,{circuitJson:i}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("circuit_json"))&&X.jsx(j1,{value:"circuit_json",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading JSON viewer"}),children:i?X.jsx(hso,{elements:i}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("errors"))&&X.jsx(j1,{value:"errors",className:"rf-h-full",children:X.jsx("div",{className:yr("rf-overflow-hidden",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:o||Xe&&Xe.length>0||i?X.jsx(ZJn,{code:t,fsMap:e,circuitJsonErrors:Xe,circuitJsonWarnings:ye,errorMessage:o,errorStack:r,circuitJson:i,evalVersion:Ce,autoroutingLog:b,onReportAutoroutingLog:v}):X.jsx(s6,{onRunClicked:n})})}),_&&(!H||H.includes("render_log"))&&X.jsx(j1,{value:"render_log",children:X.jsx(R_o,{renderLog:m,onRerunWithDebug:de})}),(!H||H.includes("solvers"))&&X.jsx(j1,{value:"solvers",children:X.jsx("div",{className:yr("rf-overflow-hidden",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Solvers view"}),children:X.jsx(hho,{solverEvents:be})})})})]})})})};const C3t=Symbol("Comlink.proxy"),B1o=Symbol("Comlink.endpoint"),M3t=Symbol("Comlink.releaseProxy"),Dve=Symbol("Comlink.finalizer"),VQ=Symbol("Comlink.thrown"),T3t=t=>typeof t=="object"&&t!==null||typeof t=="function",z1o={canHandle:t=>T3t(t)&&t[C3t],serialize(t){const{port1:e,port2:n}=new MessageChannel;return E3t(t,e),[n,[n]]},deserialize(t){return t.start(),A3t(t)}},V1o={canHandle:t=>T3t(t)&&VQ 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}},w3t=new Map([["proxy",z1o],["throw",V1o]]);function $1o(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function E3t(t,e=globalThis,n=["*"]){e.addEventListener("message",function o(r){if(!r||!r.data)return;if(!$1o(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(QM);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]]=QM(r.data.value),l=!0;break;case"APPLY":l=_.apply(u,c);break;case"CONSTRUCT":{const d=new _(...c);l=kve(d)}break;case"ENDPOINT":{const{port1:d,port2:m}=new MessageChannel;E3t(t,m),l=G1o(d,[d])}break;case"RELEASE":l=void 0;break;default:return}}catch(u){l={value:u,[VQ]:0}}Promise.resolve(l).catch(u=>({value:u,[VQ]:0})).then(u=>{const[_,d]=UQ(u);e.postMessage(Object.assign(Object.assign({},_),{id:i}),d),s==="RELEASE"&&(e.removeEventListener("message",o),D3t(e),Dve in t&&typeof t[Dve]=="function"&&t[Dve]())}).catch(u=>{const[_,d]=UQ({value:new TypeError("Unserializable return value"),[VQ]:0});e.postMessage(Object.assign(Object.assign({},_),{id:i}),d)})}),e.start&&e.start()}function W1o(t){return t.constructor.name==="MessagePort"}function D3t(t){W1o(t)&&t.close()}function A3t(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)}}),Ave(t,n,[],e)}function $Q(t){if(t)throw new Error("Proxy has been released and is not useable")}function k3t(t){return yk(t,new Map,{type:"RELEASE"}).then(()=>{D3t(t)})}const WQ=new WeakMap,jQ="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(WQ.get(t)||0)-1;WQ.set(t,e),e===0&&k3t(t)});function j1o(t,e){const n=(WQ.get(e)||0)+1;WQ.set(e,n),jQ&&jQ.register(t,e,t)}function U1o(t){jQ&&jQ.unregister(t)}function Ave(t,e,n=[],o=function(){}){let r=!1;const i=new Proxy(o,{get(s,a){if($Q(r),a===M3t)return()=>{U1o(i),k3t(t),e.clear(),r=!0};if(a==="then"){if(n.length===0)return{then:()=>i};const c=yk(t,e,{type:"GET",path:n.map(l=>l.toString())}).then(QM);return c.then.bind(c)}return Ave(t,e,[...n,a])},set(s,a,c){$Q(r);const[l,u]=UQ(c);return yk(t,e,{type:"SET",path:[...n,a].map(_=>_.toString()),value:l},u).then(QM)},apply(s,a,c){$Q(r);const l=n[n.length-1];if(l===B1o)return yk(t,e,{type:"ENDPOINT"}).then(QM);if(l==="bind")return Ave(t,e,n.slice(0,-1));const[u,_]=R3t(c);return yk(t,e,{type:"APPLY",path:n.map(d=>d.toString()),argumentList:u},_).then(QM)},construct(s,a){$Q(r);const[c,l]=R3t(a);return yk(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:c},l).then(QM)}});return j1o(i,t),i}function X1o(t){return Array.prototype.concat.apply([],t)}function R3t(t){const e=t.map(UQ);return[e.map(n=>n[0]),X1o(e.map(n=>n[1]))]}const N3t=new WeakMap;function G1o(t,e){return N3t.set(t,e),t}function kve(t){return Object.assign(t,{[C3t]:!0})}function UQ(t){for(const[e,n]of w3t)if(n.canHandle(t)){const[o,r]=n.serialize(t);return[{type:"HANDLER",name:e,value:o},r]}return[{type:"RAW",value:t},N3t.get(t)||[]]}function QM(t){switch(t.type){case"HANDLER":return w3t.get(t.name).deserialize(t.value);case"RAW":return t.value}}function yk(t,e,n,o){return new Promise(r=>{const i=Y1o();e.set(i,r),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),o)})}function Y1o(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Rve(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=Rve(r,i);n.push(...s)}else n.push(i)}return n}function I3t(t,e){const n=e.split(".");let o=t;for(const r of n)o=o[r];return o}var q1o=(t="latest")=>[`https://jscdn.tscircuit.com/@tscircuit/eval/${t}/dist/webworker/entrypoint.js`,`https://cdn.jsdelivr.net/npm/@tscircuit/eval@${t}/dist/webworker/entrypoint.js`,`https://unpkg.com/@tscircuit/eval@${t}/dist/webworker/entrypoint.js`],K1o=async(t="latest",e=!1)=>{let n;for(const o of q1o(t))try{const r=await globalThis.fetch(o);if(!r.ok)throw new Error(`Failed to fetch webworker entrypoint from ${o}: ${r.status} ${r.statusText}`);return await r.blob()}catch(r){n=r,e&&console.warn(`[Worker] Failed to fetch webworker entrypoint from ${o}, trying next CDN fallback if available`,r)}throw n instanceof Error?n:new Error("Failed to fetch webworker entrypoint from CDN fallbacks")},H3t=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=await K1o(t.evalVersion??"latest",t.verbose);n=URL.createObjectURL(d)}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=A3t(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"?kve(d):d;if(t.platform)for(const d of Rve(t.platform))await s.setPlatformConfigProperty(d,l(I3t(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 Rve(t.projectConfig))await s.setProjectConfigProperty(d,l(I3t(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=kve(m);s.on(d,h)},kill:async()=>{s[M3t](),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 J1o=({error:t,resetErrorBoundary:e})=>X.jsx("section",{className:"rf-h-full rf-w-full rf-grid rf-place-items-center",children:X.jsx("div",{className:"rf-min-h-full rf-flex rf-items-center rf-justify-center rf-px-4",children:X.jsxs("div",{className:"rf-max-w-lg rf-w-full rf-text-center",children:[X.jsxs("div",{className:"rf-mb-8",children:[X.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:X.jsx(aYn,{className:"rf-w-10 rf-h-10 rf-text-red-600"})}),X.jsx("h1",{className:"rf-text-2xl rf-font-bold rf-text-gray-900 rf-mb-3",children:"Oops! Something went wrong"}),X.jsx("p",{className:"rf-text-gray-600 rf-mb-4",children:"RunFrame encountered an unexpected error."}),X.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&&X.jsxs("details",{className:"rf-text-center rf-mb-6",children:[X.jsx("summary",{className:"rf-text-xs rf-text-gray-500 rf-cursor-pointer hover:rf-text-gray-700",children:"View stack trace"}),X.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})]})]}),X.jsxs("div",{className:"rf-flex rf-flex-col rf-gap-2 rf-justify-center",children:[X.jsx(kc,{variant:"destructive",size:"lg",onClick:()=>window.location.reload(),children:"Refresh Dev Server"}),X.jsx(kc,{variant:"outline",size:"lg",onClick:e,children:"Try Again"})]})]})})}),L3t=t=>{const e={};if(!t)return e;for(const o of Ey)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},Q1o=(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 Z1o(){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 e2o=({message:t="Loading files..."})=>X.jsxs("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full",children:[X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4 rf-p-2 rf-border-b",children:[X.jsx("div",{className:"rf-w-20 rf-h-9 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded-md rf-animate-pulse"}),X.jsx("div",{className:"rf-flex rf-gap-6 rf-ml-auto",children:["PCB","Schematic","3D"].map((e,n)=>X.jsx("div",{className:"rf-h-6 rf-w-20 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded rf-animate-pulse"},n))})]}),X.jsx("div",{className:"rf-flex-1 rf-p-4",children:X.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:X.jsx("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4",children:X.jsx("div",{className:"rf-text-sm rf-text-gray-400 dark:rf-text-gray-500",children:t})})})})]}),XQ=t=>{const e=t.toLowerCase(),n=e.split("/").pop();return e.endsWith(".circuit.json")||n==="circuit.json"},t2o=t=>t.endsWith(".tsx")||XQ(t)||t.endsWith(".jsx"),n2o=({mainComponentPath:t,fsMap:e})=>Y.useMemo(()=>{if(!(t!=null&&XQ(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]),o2o=t=>!t||typeof t!="object"?!1:!!("error_type"in t||typeof t.type=="string"&&t.type.includes("error")),r2o=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)},i2o=t=>Array.isArray(t)?t.filter(o2o):[],Nve=({circuitJson:t,executionError:e})=>{const n=[];e&&n.push(r2o(e));const o=i2o(t);return n.push(...o),{hasExecutionError:!!e,...n.length>0?{errors:n}:{}}};var s2o=Symbol("radix.slottable");function a2o(t){const e=({children:n})=>X.jsx(X.Fragment,{children:n});return e.displayName=`${t}.Slottable`,e.__radixId=s2o,e}var c2o=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"}),l2o="VisuallyHidden",O3t=Y.forwardRef((t,e)=>X.jsx(Uc.span,{...t,ref:e,style:{...c2o,...t.style}}));O3t.displayName=l2o;var u2o=O3t,[GQ]=_b("Tooltip",[zA]),YQ=zA(),F3t="TooltipProvider",_2o=700,Ive="tooltip.open",[d2o,Hve]=GQ(F3t),B3t=t=>{const{__scopeTooltip:e,delayDuration:n=_2o,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)},[]),X.jsx(d2o,{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})};B3t.displayName=F3t;var SF="Tooltip",[h2o,qQ]=GQ(SF),z3t=t=>{const{__scopeTooltip:e,children:n,open:o,defaultOpen:r,onOpenChange:i,disableHoverableContent:s,delayDuration:a}=t,c=Hve(SF,t.__scopeTooltip),l=YQ(e),[u,_]=Y.useState(null),d=Df(),m=Y.useRef(0),h=s??c.disableHoverableContent,p=a??c.delayDuration,x=Y.useRef(!1),[f,g]=ZS({prop:o,defaultProp:r??!1,onChange:M=>{M?(c.onOpen(),document.dispatchEvent(new CustomEvent(Ive))):c.onClose(),i?.(M)},caller:SF}),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)},[]),X.jsx(kK,{...l,children:X.jsx(h2o,{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})})};z3t.displayName=SF;var Lve="TooltipTrigger",V3t=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=qQ(Lve,n),i=Hve(Lve,n),s=YQ(n),a=Y.useRef(null),c=S0(e,a,r.onTriggerChange),l=Y.useRef(!1),u=Y.useRef(!1),_=Y.useCallback(()=>l.current=!1,[]);return Y.useEffect(()=>()=>document.removeEventListener("pointerup",_),[_]),X.jsx(RK,{asChild:!0,...s,children:X.jsx(Uc.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...o,ref:c,onPointerMove:Qr(t.onPointerMove,d=>{d.pointerType!=="touch"&&!u.current&&!i.isPointerInTransitRef.current&&(r.onTriggerEnter(),u.current=!0)}),onPointerLeave:Qr(t.onPointerLeave,()=>{r.onTriggerLeave(),u.current=!1}),onPointerDown:Qr(t.onPointerDown,()=>{r.open&&r.onClose(),l.current=!0,document.addEventListener("pointerup",_,{once:!0})}),onFocus:Qr(t.onFocus,()=>{l.current||r.onOpen()}),onBlur:Qr(t.onBlur,r.onClose),onClick:Qr(t.onClick,r.onClose)})})});V3t.displayName=Lve;var m2o="TooltipPortal",[dbo,p2o]=GQ(m2o,{forceMount:void 0}),bk="TooltipContent",$3t=Y.forwardRef((t,e)=>{const n=p2o(bk,t.__scopeTooltip),{forceMount:o=n.forceMount,side:r="top",...i}=t,s=qQ(bk,t.__scopeTooltip);return X.jsx(Dy,{present:o||s.open,children:s.disableHoverableContent?X.jsx(W3t,{side:r,...i,ref:e}):X.jsx(f2o,{side:r,...i,ref:e})})}),f2o=Y.forwardRef((t,e)=>{const n=qQ(bk,t.__scopeTooltip),o=Hve(bk,t.__scopeTooltip),r=Y.useRef(null),i=S0(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=P2o(f,x.getBoundingClientRect()),y=v2o(f,g),b=S2o(p.getBoundingClientRect()),v=M2o([...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=!C2o(f,s);g?d():y&&(d(),l())};return document.addEventListener("pointermove",h),()=>document.removeEventListener("pointermove",h)}},[c,u,s,l,d]),X.jsx(W3t,{...t,ref:i})}),[x2o,g2o]=GQ(SF,{isInside:!1}),y2o=a2o("TooltipContent"),W3t=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,children:o,"aria-label":r,onEscapeKeyDown:i,onPointerDownOutside:s,...a}=t,c=qQ(bk,n),l=YQ(n),{onClose:u}=c;return Y.useEffect(()=>(document.addEventListener(Ive,u),()=>document.removeEventListener(Ive,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]),X.jsx(oO,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:s,onFocusOutside:_=>_.preventDefault(),onDismiss:u,children:X.jsxs(Cbe,{"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:[X.jsx(y2o,{children:o}),X.jsx(x2o,{scope:n,isInside:!0,children:X.jsx(u2o,{id:c.contentId,role:"tooltip",children:r||o})})]})})});$3t.displayName=bk;var j3t="TooltipArrow",b2o=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=YQ(n);return g2o(j3t,n).isInside?null:X.jsx(Mbe,{...r,...o,ref:e})});b2o.displayName=j3t;function P2o(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 v2o(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 S2o(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 C2o(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 M2o(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),T2o(e)}function T2o(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 w2o=B3t,E2o=z3t,D2o=V3t,U3t=$3t;const X3t=w2o,G3t=E2o,Y3t=D2o,Ove=Y.forwardRef(({className:t,sideOffset:e=4,...n},o)=>X.jsx(U3t,{ref:o,sideOffset:e,className:yr("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}));Ove.displayName=U3t.displayName;const A2o=26,Hg=fc("run-frame:RunFrame"),k2o=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)}},q3t=async(t,e)=>{if(t)return t;if(e||!window.TSCIRCUIT_LATEST_EVAL_VERSION){const n=await k2o();if(n)return window.TSCIRCUIT_LATEST_EVAL_VERSION=n,n}return window.TSCIRCUIT_LATEST_EVAL_VERSION?window.TSCIRCUIT_LATEST_EVAL_VERSION:"latest"},K3t=t=>{cQ();const e=v0(_e=>_e.circuitJson),n=v0(_e=>_e.setCircuitJson),[o,r]=Y.useState(null),i=Y.useRef(null),[s,a]=Y.useState(null),[c,l]=Y.useReducer((_e,Ce)=>_e+1,0),u=_Q(_e=>_e.setLastRunEvalVersion),_=Y.useRef(0),d=Z1o(),[m,h]=Y.useState(!1),[p,x]=Y.useState(!1),[f,g]=Y.useState({}),[y,b]=Y.useState(""),[v,S]=Y.useState(!1),[M,T]=Y.useState(!1),D=Object.values(f).sort((_e,Ce)=>_e.startTime-Ce.startTime)[0]?.effectName,A=_e=>{t.onRunCompleted?.(_e)};Y.useEffect(()=>{const _e=Ce=>{(Ce.ctrlKey||Ce.metaKey)&&Ce.key==="Enter"&&!m&&l(1)};return window.addEventListener("keydown",_e),()=>window.removeEventListener("keydown",_e)},[m]),Y.useEffect(()=>{let _e=!1;return(async()=>{try{if(!globalThis.runFrameWorker){const xe=await q3t(t.evalVersion,t.forceLatestEvalVersion),Fe=await H3t({evalVersion:xe,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${X2}/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},...t.easyEdaProxyConfig&&{easyEdaProxyConfig:t.easyEdaProxyConfig}});if(_e)return;globalThis.runFrameWorker=Fe,u(xe)}_e||x(!0)}catch(xe){console.error("Failed to preload eval worker",xe)}})(),()=>{_e=!0}},[t.evalVersion,t.evalWebWorkerBlobUrl,t.forceLatestEvalVersion,t.tscircuitSessionToken]);const[L,H]=Y.useState(null),[F,B]=Y.useState({}),[V,G]=Y.useState([]),[K,Q]=Y.useState(t.defaultActiveTab??t.defaultTab??"pcb");Y.useEffect(()=>{t.debug&&fc.enable("run-frame*")},[t.debug]);const oe=t.fsMap instanceof Map?t.fsMap:Object.entries(t.fsMap??{}).reduce((_e,[Ce,xe])=>_e.set(Ce,xe),new Map),ue=Y.useRef(null),ne=Y.useRef(null),{isStaticCircuitJson:re,circuitJson:ae,error:ie}=n2o({mainComponentPath:t.mainComponentPath,fsMap:oe});Y.useEffect(()=>{re&&(ae?(n(ae),r(null)):ie&&r({error:ie,stack:""}))},[re,ae,ie]),Y.useEffect(()=>{if(t.isLoadingFiles||re)return;const _e=oe instanceof Map?Object.fromEntries(oe.entries()):oe;if(!_e||Object.keys(_e).length===0){r({error:"No files provided. Please provide at least one file with code to execute.",stack:""}),h(!1);return}const Ce=c!==_.current;if(ue.current&&e){const Fe=Q1o(ue.current,oe);if(Object.keys(Fe).length>0)Hg("code changes detected");else if(ne.current!==t.entrypoint)Hg("render triggered by entrypoint change");else if(!Ce){Hg("render triggered without changes to fsMap, skipping");return}}if(t.showRunButton&&c===_.current)return;ue.current=oe,ne.current=t.entrypoint??null,_.current=c,h(!0);const xe=async()=>{Hg("running render worker"),r(null),H(null),g({}),G([]);const Fe={progress:0,debugOutputs:[]};let We=!1;i.current=()=>{We=!0};const Xe=await q3t(t.evalVersion,!globalThis.runFrameWorker&&t.forceLatestEvalVersion);Hg("resolvedEvalVersion",Xe);const ye=globalThis.runFrameWorker??await H3t({evalVersion:Xe,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,verbose:!0,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${X2}/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},...t.easyEdaProxyConfig&&{easyEdaProxyConfig:t.easyEdaProxyConfig}});globalThis.runFrameWorker=ye,u(Xe),y?.trim()&&ye.enableDebug(y.replace("DEBUG=","")),Hg("Starting render..."),t.onRenderStarted?.();const Je=oe instanceof Map?Object.fromEntries(oe.entries()):oe;let Be=Date.now();ye.on("asyncEffect:start",Te=>{const Ae=`${Te.phase}|${Te.componentDisplayName??""}|${Te.effectName}`;g(De=>({...De,[Ae]:{...Te,startTime:Date.now()}}))}),ye.on("asyncEffect:end",Te=>{const Ae=`${Te.phase}|${Te.componentDisplayName??""}|${Te.effectName}`;g(De=>{const{[Ae]:$e,...je}=De;return je})}),ye.on("autorouting:start",Te=>{B({...F,[Te.componentDisplayName]:{simpleRouteJson:Te.simpleRouteJson,createdAt:Date.now()}})}),ye.on("solver:started",Te=>{Hg("solver:started",Te),G(Ae=>{const De=`${Te.componentName}-${Te.solverName}`;return Ae.some(je=>`${je.componentName}-${je.solverName}`===De)?Ae:[...Ae,Te]})}),ye.on("board:renderPhaseStarted",Te=>{Fe.lastRenderEvent=Te,Fe.eventsProcessed=(Fe.eventsProcessed??0)+1;const Ae=Ey.indexOf(Te.phase)/A2o*.75+Fe.eventsProcessed/1e3*.25,De=1-Math.exp(-Ae*3);Fe.progress=De,We||H({...Fe})}),K==="render_log"&&ye.on("renderable:renderLifecycle:anyEvent",Te=>{Fe.renderEvents=Fe.renderEvents??[],Te.createdAt=Date.now(),Fe.renderEvents.push(Te),Date.now()-Be>500&&(Fe.phaseTimings=L3t(Fe.renderEvents??[]),Be=Date.now()),We||H({...Fe})}),ye.on("autorouting:progress",Te=>{a(Te.debugGraphics)}),ye.on("debug:logOutput",Te=>{Fe.debugOutputs=Fe.debugOutputs??[],Fe.debugOutputs.push({type:"debug",name:Te.name,content:Te.content}),We||H({...Fe})}),Hg("Executing fsMap...");const ke=await ye.executeWithFsMap({entrypoint:t.entrypoint,fsMap:Je,...t.mainComponentPath?{mainComponentPath:t.mainComponentPath}:{}}).then(()=>({success:!0})).catch(Te=>{const Ae=Te.message.replace("Error: ","");return Hg(`eval error: ${Ae}`),t.onError?.(Te),A(Nve({executionError:Te})),r({error:Ae,stack:Te.stack}),H(null),console.error(Te),{success:!1}});if(Hg("worker call started"),!ke.success){h(!1),g({});return}const Ve=ye.renderUntilSettled();Hg("waiting for initial circuit json...");let Ie=await ye.getCircuitJson().catch(Te=>(Hg("error getting initial circuit json",Te),t.onError?.(Te),A(Nve({executionError:Te})),r({error:Te.message,stack:Te.stack}),H(null),h(!1),g({}),null));Ie&&(Hg("got initial circuit json"),n(Ie),t.onCircuitJsonChange?.(Ie),t.onInitialRender?.({circuitJson:Ie}),await Ve,Hg("getting final circuit json"),Ie=await ye.getCircuitJson(),t.onCircuitJsonChange?.(Ie),n(Ie),A(Nve({circuitJson:Ie})),t.onRenderFinished?.({circuitJson:Ie}),a({}),K==="render_log"&&(Fe.phaseTimings=L3t(Fe.renderEvents??[])),Fe.progress=1,We||H({...Fe}),h(!1),g({}),b(""),i.current=null)};d.runWithMutex(xe)},[t.fsMap,t.entrypoint,c,t.evalVersion,t.mainComponentPath,t.isLoadingFiles,y,re]);const de=Y.useRef(null),be=Y.useRef(null),Me=_e=>{if(!_e||_e===null){console.warn("[RunFrame] handleEditEvent received null or undefined event.");return}_e.in_progress?(de.current=_e,be.current&&(clearTimeout(be.current),be.current=null)):(be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{const Ce=_e||de.current;t.onEditEvent?.(Ce),de.current=null,be.current=null},100))},Ee=async(_e,Ce)=>{let xe="";const Fe=Array.isArray(e)&&e.find(ye=>ye.type==="software_project_metadata"),We=t.projectUrl??Fe?.project_url;if(We)try{xe=new URL(We).pathname}catch{xe=We}const Xe=xe?`${xe} - ${_e}`:_e;await pF.post("autorouting/bug_reports/create",{json:{title:Xe,simple_route_json:Ce.simpleRouteJson}}).json().then(({autorouting_bug_report:ye})=>{window.open(`https://api.tscircuit.com/autorouting/bug_reports/view?autorouting_bug_report_id=${ye.autorouting_bug_report_id}`,"_blank")}).catch(ye=>{if(console.error("Failed to report autorouting bug",ye),ye instanceof p8&&ye.response?.status===401){t.onLoginRequired?t.onLoginRequired():alert("You must be logged in to report autorouting bugs");return}const Be=ye instanceof Error?ye.message:"Failed to report autorouting bug";alert(`Failed to report autorouting bug: ${Be}`)})};return t.isLoadingFiles?X.jsx(e2o,{}):X.jsx(x3,{FallbackComponent:J1o,children:X.jsx(S3t,{code:oe.get(t.entrypoint??t.mainComponentPath),fsMap:oe,defaultActiveTab:t.defaultActiveTab??t.defaultTab,defaultTab:t.defaultTab,availableTabs:t.availableTabs,showToggleFullScreen:t.showToggleFullScreen,autoroutingGraphics:s,autoroutingLog:F,onReportAutoroutingLog:t.onReportAutoroutingLog||Ee,leftHeaderContent:X.jsxs(X.Fragment,{children:[t.showRunButton&&X.jsx(X3t,{children:X.jsxs(G3t,{children:[X.jsx(Y3t,{asChild:!0,children:X.jsxs("div",{className:"rf-relative rf-inline-flex",children:[X.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?X.jsx(Qv,{className:"rf-w-3 rf-h-3 rf-animate-spin"}):X.jsx(Zht,{className:"rf-w-3 rf-h-3"})]}),m&&X.jsx("div",{className:"rf-flex rf-items-center rf-ml-1",children:X.jsx(kc,{onClick:_e=>{_e.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:X.jsx(sYn,{className:"!rf-h-2.5 !rf-w-2.5",fill:"currentColor",stroke:"currentColor"})})})]})}),X.jsx(Ove,{sideOffset:8,className:"rf-p-0 rf-bg-transparent rf-border-none rf-shadow-none rf-pointer-events-none",children:X.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:[X.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"}),X.jsx("span",{className:"rf-text-slate-500 rf-text-[11px] rf-font-medium rf-leading-none",children:"+"}),X.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&&X.jsx(vF,{isWebEmbedded:t.isWebEmbedded,onLoginRequired:t.onLoginRequired,showSchematicDebugGrid:v,onChangeShowSchematicDebugGrid:S,showSchematicPorts:M,onChangeShowSchematicPorts:T,autoroutingLog:F,onReportAutoroutingLog:t.onReportAutoroutingLog||Ee}),t.leftHeaderContent]}),onActiveTabChange:Q,circuitJson:e,renderLog:L,activeEffectName:D,isRunningCode:m,errorMessage:o?.error,errorStack:o?.stack,onEditEvent:Me,editEvents:t.editEvents,onPcbBoundsSelected:t.onPcbBoundsSelected,defaultToFullScreen:t.defaultToFullScreen,onRerunWithDebug:_e=>{b(_e||""),l(1)},solverEvents:V,showSchematicDebugGrid:v,showSchematicPorts:M,onChangeShowSchematicDebugGrid:S,onChangeShowSchematicPorts:T})})},R2o=t=>new Promise(e=>setTimeout(e,t)),N2o=({isOpen:t,onClose:e,onLoginSuccess:n})=>{const[o,r]=Y.useState("idle"),[i,s]=Y.useState(null),[a,c]=Y.useState(null),l=v0(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=f8(),{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 R2o(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"),Ss.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"),Ss.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 X.jsx(pk,{open:t,onOpenChange:p=>!p&&!m&&d(),children:X.jsxs(WM,{className:"rf-max-w-md",children:[X.jsxs(jM,{children:[X.jsx(UM,{children:"Sign In Required"}),X.jsx(fk,{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."})]}),X.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4 rf-py-4",children:[o==="idle"||o==="error"?X.jsx(kc,{onClick:_,className:"rf-w-full",children:"Sign In"}):X.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-3 rf-w-full",children:[o!=="success"&&X.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"}),X.jsx("p",{className:"rf-text-sm rf-text-gray-600 rf-text-center",children:h()}),i&&o==="waiting"&&X.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"&&X.jsx("p",{className:"rf-text-sm rf-text-red-600 rf-text-center",children:a}),m&&X.jsx(kc,{variant:"outline",onClick:d,className:"rf-w-full",children:"Cancel"})]})]})})},I2o=()=>{const[t,e]=Y.useState(!1),n=Y.useCallback(()=>{e(!0)},[]),o=Y.useCallback(()=>{e(!1)},[]),r=Y.useCallback(()=>{e(!1)},[]);return{LoginDialog:X.jsx(N2o,{isOpen:t,onClose:o,onLoginSuccess:r}),openLoginDialog:n}},H2o=t=>{const[e,n]=qE("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}=I2o();return X.jsxs(X.Fragment,{children:[i,X.jsx(Xbt,{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:X.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between",children:[X.jsx(vF,{isWebEmbedded:!1,shouldLoadLatestEval:!t.workerBlobUrl&&e,onChangeShouldLoadLatestEval:a=>{n(a),globalThis.runFrameWorker=null},onLoginRequired:s}),t.scenarioSelectorContent]})})]})};fc("run-frame:ImportComponentDialog");var J3t=1,L2o=.9,O2o=.8,F2o=.17,Fve=.1,Bve=.999,B2o=.9999,z2o=.99,V2o=/[\\\/_+.#"@\[\(\{&]/,$2o=/[\\\/_+.#"@\[\(\{&]/g,W2o=/[\s-]/,Q3t=/[\s-]/g;function zve(t,e,n,o,r,i,s){if(i===e.length)return r===t.length?J3t:z2o;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;)_=zve(t,e,n,o,l+1,i+1,s),_>u&&(l===r?_*=J3t:V2o.test(t.charAt(l-1))?(_*=O2o,m=t.slice(r,l-1).match($2o),m&&r>0&&(_*=Math.pow(Bve,m.length))):W2o.test(t.charAt(l-1))?(_*=L2o,h=t.slice(r,l-1).match(Q3t),h&&r>0&&(_*=Math.pow(Bve,h.length))):(_*=F2o,r>0&&(_*=Math.pow(Bve,l-r))),t.charAt(l)!==e.charAt(i)&&(_*=B2o)),(_<Fve&&n.charAt(l-1)===o.charAt(i+1)||o.charAt(i+1)===o.charAt(i)&&n.charAt(l-1)!==o.charAt(i))&&(d=zve(t,e,n,o,l+1,i+2,s),d*Fve>_&&(_=d*Fve)),_>u&&(u=_),l=n.indexOf(c,l+1);return s[a]=u,u}function Z3t(t){return t.toLowerCase().replace(Q3t," ")}function j2o(t,e,n){return t=n&&n.length>0?`${t+" "+n.join(" ")}`:t,zve(t,e,Z3t(t),Z3t(e),0,0,{})}var U2o=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],g8=U2o.reduce((t,e)=>{const n=Ght(`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),X.jsx(c,{...a,ref:i})});return o.displayName=`Primitive.${e}`,{...t,[e]:o}},{}),CF='[cmdk-group=""]',Vve='[cmdk-group-items=""]',X2o='[cmdk-group-heading=""]',ebt='[cmdk-item=""]',tbt=`${ebt}:not([aria-disabled="true"])`,$ve="cmdk-item-select",Pk="data-value",G2o=(t,e,n)=>j2o(t,e,n),nbt=Y.createContext(void 0),MF=()=>Y.useContext(nbt),obt=Y.createContext(void 0),Wve=()=>Y.useContext(obt),rbt=Y.createContext(void 0),ibt=Y.forwardRef((t,e)=>{let n=vk(()=>{var re,ae;return{search:"",value:(ae=(re=t.value)!=null?re:t.defaultValue)!=null?ae:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),o=vk(()=>new Set),r=vk(()=>new Map),i=vk(()=>new Map),s=vk(()=>new Set),a=sbt(t),{label:c,children:l,value:u,onValueChange:_,filter:d,shouldFilter:m,loop:h,disablePointerSelection:p=!1,vimBindings:x=!0,...f}=t,g=Df(),y=Df(),b=Df(),v=Y.useRef(null),S=rxo();ZM(()=>{if(u!==void 0){let re=u.trim();n.current.value=re,M.emit()}},[u]),ZM(()=>{S(6,F)},[]);let M=Y.useMemo(()=>({subscribe:re=>(s.current.add(re),()=>s.current.delete(re)),snapshot:()=>n.current,setState:(re,ae,ie)=>{var de,be,Me,Ee;if(!Object.is(n.current[re],ae)){if(n.current[re]=ae,re==="search")H(),A(),S(1,L);else if(re==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let _e=document.getElementById(b);_e?_e.focus():(de=document.getElementById(g))==null||de.focus()}if(S(7,()=>{var _e;n.current.selectedItemId=(_e=B())==null?void 0:_e.id,M.emit()}),ie||S(5,F),((be=a.current)==null?void 0:be.value)!==void 0){let _e=ae??"";(Ee=(Me=a.current).onValueChange)==null||Ee.call(Me,_e);return}}M.emit()}},emit:()=>{s.current.forEach(re=>re())}}),[]),T=Y.useMemo(()=>({value:(re,ae,ie)=>{var de;ae!==((de=i.current.get(re))==null?void 0:de.value)&&(i.current.set(re,{value:ae,keywords:ie}),n.current.filtered.items.set(re,D(ae,ie)),S(2,()=>{A(),M.emit()}))},item:(re,ae)=>(o.current.add(re),ae&&(r.current.has(ae)?r.current.get(ae).add(re):r.current.set(ae,new Set([re]))),S(3,()=>{H(),A(),n.current.value||L(),M.emit()}),()=>{i.current.delete(re),o.current.delete(re),n.current.filtered.items.delete(re);let ie=B();S(4,()=>{H(),ie?.getAttribute("id")===re&&L(),M.emit()})}),group:re=>(r.current.has(re)||r.current.set(re,new Set),()=>{i.current.delete(re),r.current.delete(re)}),filter:()=>a.current.shouldFilter,label:c||t["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:g,inputId:b,labelId:y,listInnerRef:v}),[]);function D(re,ae){var ie,de;let be=(de=(ie=a.current)==null?void 0:ie.filter)!=null?de:G2o;return re?be(re,n.current.search,ae):0}function A(){if(!n.current.search||a.current.shouldFilter===!1)return;let re=n.current.filtered.items,ae=[];n.current.filtered.groups.forEach(de=>{let be=r.current.get(de),Me=0;be.forEach(Ee=>{let _e=re.get(Ee);Me=Math.max(_e,Me)}),ae.push([de,Me])});let ie=v.current;V().sort((de,be)=>{var Me,Ee;let _e=de.getAttribute("id"),Ce=be.getAttribute("id");return((Me=re.get(Ce))!=null?Me:0)-((Ee=re.get(_e))!=null?Ee:0)}).forEach(de=>{let be=de.closest(Vve);be?be.appendChild(de.parentElement===be?de:de.closest(`${Vve} > *`)):ie.appendChild(de.parentElement===ie?de:de.closest(`${Vve} > *`))}),ae.sort((de,be)=>be[1]-de[1]).forEach(de=>{var be;let Me=(be=v.current)==null?void 0:be.querySelector(`${CF}[${Pk}="${encodeURIComponent(de[0])}"]`);Me?.parentElement.appendChild(Me)})}function L(){let re=V().find(ie=>ie.getAttribute("aria-disabled")!=="true"),ae=re?.getAttribute(Pk);M.setState("value",ae||void 0)}function H(){var re,ae,ie,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 Me of o.current){let Ee=(ae=(re=i.current.get(Me))==null?void 0:re.value)!=null?ae:"",_e=(de=(ie=i.current.get(Me))==null?void 0:ie.keywords)!=null?de:[],Ce=D(Ee,_e);n.current.filtered.items.set(Me,Ce),Ce>0&&be++}for(let[Me,Ee]of r.current)for(let _e of Ee)if(n.current.filtered.items.get(_e)>0){n.current.filtered.groups.add(Me);break}n.current.filtered.count=be}function F(){var re,ae,ie;let de=B();de&&(((re=de.parentElement)==null?void 0:re.firstChild)===de&&((ie=(ae=de.closest(CF))==null?void 0:ae.querySelector(X2o))==null||ie.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function B(){var re;return(re=v.current)==null?void 0:re.querySelector(`${ebt}[aria-selected="true"]`)}function V(){var re;return Array.from(((re=v.current)==null?void 0:re.querySelectorAll(tbt))||[])}function G(re){let ae=V()[re];ae&&M.setState("value",ae.getAttribute(Pk))}function K(re){var ae;let ie=B(),de=V(),be=de.findIndex(Ee=>Ee===ie),Me=de[be+re];(ae=a.current)!=null&&ae.loop&&(Me=be+re<0?de[de.length-1]:be+re===de.length?de[0]:de[be+re]),Me&&M.setState("value",Me.getAttribute(Pk))}function Q(re){let ae=B(),ie=ae?.closest(CF),de;for(;ie&&!de;)ie=re>0?nxo(ie,CF):oxo(ie,CF),de=ie?.querySelector(tbt);de?M.setState("value",de.getAttribute(Pk)):K(re)}let oe=()=>G(V().length-1),ue=re=>{re.preventDefault(),re.metaKey?oe():re.altKey?Q(1):K(1)},ne=re=>{re.preventDefault(),re.metaKey?G(0):re.altKey?Q(-1):K(-1)};return Y.createElement(g8.div,{ref:e,tabIndex:-1,...f,"cmdk-root":"",onKeyDown:re=>{var ae;(ae=f.onKeyDown)==null||ae.call(f,re);let ie=re.nativeEvent.isComposing||re.keyCode===229;if(!(re.defaultPrevented||ie))switch(re.key){case"n":case"j":{x&&re.ctrlKey&&ue(re);break}case"ArrowDown":{ue(re);break}case"p":case"k":{x&&re.ctrlKey&&ne(re);break}case"ArrowUp":{ne(re);break}case"Home":{re.preventDefault(),G(0);break}case"End":{re.preventDefault(),oe();break}case"Enter":{re.preventDefault();let de=B();if(de){let be=new Event($ve);de.dispatchEvent(be)}}}}},Y.createElement("label",{"cmdk-label":"",htmlFor:T.inputId,id:T.labelId,style:sxo},c),KQ(t,re=>Y.createElement(obt.Provider,{value:M},Y.createElement(nbt.Provider,{value:T},re))))}),Y2o=Y.forwardRef((t,e)=>{var n,o;let r=Df(),i=Y.useRef(null),s=Y.useContext(rbt),a=MF(),c=sbt(t),l=(o=(n=c.current)==null?void 0:n.forceMount)!=null?o:s?.forceMount;ZM(()=>{if(!l)return a.item(r,s?.id)},[l]);let u=abt(r,i,[t.value,t.children,i],t.keywords),_=Wve(),d=y8(S=>S.value&&S.value===u.current),m=y8(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($ve,h),()=>S.removeEventListener($ve,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(g8.div,{ref:vg(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)}),q2o=Y.forwardRef((t,e)=>{let{heading:n,children:o,forceMount:r,...i}=t,s=Df(),a=Y.useRef(null),c=Y.useRef(null),l=Df(),u=MF(),_=y8(m=>r||u.filter()===!1?!0:m.search?m.filtered.groups.has(s):!0);ZM(()=>u.group(s),[]),abt(s,a,[t.value,t.heading,c]);let d=Y.useMemo(()=>({id:s,forceMount:r}),[r]);return Y.createElement(g8.div,{ref:vg(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),KQ(t,m=>Y.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?l:void 0},Y.createElement(rbt.Provider,{value:d},m))))}),K2o=Y.forwardRef((t,e)=>{let{alwaysRender:n,...o}=t,r=Y.useRef(null),i=y8(s=>!s.search);return!n&&!i?null:Y.createElement(g8.div,{ref:vg(r,e),...o,"cmdk-separator":"",role:"separator"})}),J2o=Y.forwardRef((t,e)=>{let{onValueChange:n,...o}=t,r=t.value!=null,i=Wve(),s=y8(l=>l.search),a=y8(l=>l.selectedItemId),c=MF();return Y.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),Y.createElement(g8.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)}})}),Q2o=Y.forwardRef((t,e)=>{let{children:n,label:o="Suggestions",...r}=t,i=Y.useRef(null),s=Y.useRef(null),a=y8(l=>l.selectedItemId),c=MF();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(g8.div,{ref:vg(i,e),...r,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":o,id:c.listId},KQ(t,l=>Y.createElement("div",{ref:vg(s,c.listInnerRef),"cmdk-list-sizer":""},l)))}),Z2o=Y.forwardRef((t,e)=>{let{open:n,onOpenChange:o,overlayClassName:r,contentClassName:i,container:s,...a}=t;return Y.createElement(LPe,{open:n,onOpenChange:o},Y.createElement(OPe,{container:s},Y.createElement(mQ,{"cmdk-overlay":"",className:r}),Y.createElement(pQ,{"aria-label":t.label,"cmdk-dialog":"",className:i},Y.createElement(ibt,{ref:e,...a}))))}),exo=Y.forwardRef((t,e)=>y8(n=>n.filtered.count===0)?Y.createElement(g8.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),txo=Y.forwardRef((t,e)=>{let{progress:n,children:o,label:r="Loading...",...i}=t;return Y.createElement(g8.div,{ref:e,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r},KQ(t,s=>Y.createElement("div",{"aria-hidden":!0},s)))}),Lg=Object.assign(ibt,{List:Q2o,Item:Y2o,Input:J2o,Group:q2o,Separator:K2o,Dialog:Z2o,Empty:exo,Loading:txo});function nxo(t,e){let n=t.nextElementSibling;for(;n;){if(n.matches(e))return n;n=n.nextElementSibling}}function oxo(t,e){let n=t.previousElementSibling;for(;n;){if(n.matches(e))return n;n=n.previousElementSibling}}function sbt(t){let e=Y.useRef(t);return ZM(()=>{e.current=t}),e}var ZM=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;function vk(t){let e=Y.useRef();return e.current===void 0&&(e.current=t()),e}function y8(t){let e=Wve(),n=()=>t(e.snapshot());return Y.useSyncExternalStore(e.subscribe,n,n)}function abt(t,e,n,o=[]){let r=Y.useRef(),i=MF();return ZM(()=>{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(Pk,a),r.current=a}),r}var rxo=()=>{let[t,e]=Y.useState(),n=vk(()=>new Map);return ZM(()=>{n.current.forEach(o=>o()),n.current=new Map},[t]),(o,r)=>{n.current.set(o,r),e({})}};function ixo(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function KQ({asChild:t,children:e},n){return t&&Y.isValidElement(e)?Y.cloneElement(ixo(e),{ref:e.ref},n(e.props.children)):n(e)}var sxo={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const cbt=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg,{ref:n,className:yr("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}));cbt.displayName=Lg.displayName;const lbt=Y.forwardRef(({className:t,...e},n)=>X.jsxs("div",{className:"rf-flex rf-items-center rf-border-b rf-px-3","cmdk-input-wrapper":"",children:[X.jsx(ibe,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-shrink-0 rf-opacity-50"}),X.jsx(Lg.Input,{ref:n,className:yr("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})]}));lbt.displayName=Lg.Input.displayName;const ubt=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.List,{ref:n,className:yr("rf-max-h-[300px] rf-overflow-y-auto rf-overflow-x-hidden rf-py-1",t),...e}));ubt.displayName=Lg.List.displayName;const jve=Y.forwardRef((t,e)=>X.jsx(Lg.Empty,{ref:e,className:"rf-py-6 rf-text-center rf-text-sm",...t}));jve.displayName=Lg.Empty.displayName;const TF=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.Group,{ref:n,className:yr("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}));TF.displayName=Lg.Group.displayName;const axo=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.Separator,{ref:n,className:yr("rf--mx-1 rf-h-px rf-bg-zinc-200 dark:rf-bg-zinc-800",t),...e}));axo.displayName=Lg.Separator.displayName;const wF=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.Item,{ref:n,className:yr("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}));wF.displayName=Lg.Item.displayName;function cxo(t){const e=lxo(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(_xo);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 X.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return X.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function lxo(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=hxo(r),a=dxo(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?vg(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 uxo=Symbol("radix.slottable");function _xo(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===uxo}function dxo(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 hxo(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 JQ="Popover",[_bt]=_b(JQ,[zA]),EF=zA(),[mxo,b8]=_bt(JQ),dbt=t=>{const{__scopePopover:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!1}=t,a=EF(e),c=Y.useRef(null),[l,u]=Y.useState(!1),[_,d]=ZS({prop:o,defaultProp:r??!1,onChange:i,caller:JQ});return X.jsx(kK,{...a,children:X.jsx(mxo,{scope:e,contentId:Df(),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})})};dbt.displayName=JQ;var hbt="PopoverAnchor",pxo=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=b8(hbt,n),i=EF(n),{onCustomAnchorAdd:s,onCustomAnchorRemove:a}=r;return Y.useEffect(()=>(s(),()=>a()),[s,a]),X.jsx(RK,{...i,...o,ref:e})});pxo.displayName=hbt;var mbt="PopoverTrigger",pbt=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=b8(mbt,n),i=EF(n),s=S0(e,r.triggerRef),a=X.jsx(Uc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":bbt(r.open),...o,ref:s,onClick:Qr(t.onClick,r.onOpenToggle)});return r.hasCustomAnchor?a:X.jsx(RK,{asChild:!0,...i,children:a})});pbt.displayName=mbt;var Uve="PopoverPortal",[fxo,xxo]=_bt(Uve,{forceMount:void 0}),fbt=t=>{const{__scopePopover:e,forceMount:n,children:o,container:r}=t,i=b8(Uve,e);return X.jsx(fxo,{scope:e,forceMount:n,children:X.jsx(Dy,{present:n||i.open,children:X.jsx(NK,{asChild:!0,container:r,children:o})})})};fbt.displayName=Uve;var Sk="PopoverContent",xbt=Y.forwardRef((t,e)=>{const n=xxo(Sk,t.__scopePopover),{forceMount:o=n.forceMount,...r}=t,i=b8(Sk,t.__scopePopover);return X.jsx(Dy,{present:o||i.open,children:i.modal?X.jsx(yxo,{...r,ref:e}):X.jsx(bxo,{...r,ref:e})})});xbt.displayName=Sk;var gxo=cxo("PopoverContent.RemoveScroll"),yxo=Y.forwardRef((t,e)=>{const n=b8(Sk,t.__scopePopover),o=Y.useRef(null),r=S0(e,o),i=Y.useRef(!1);return Y.useEffect(()=>{const s=o.current;if(s)return wbe(s)},[]),X.jsx(VK,{as:gxo,allowPinchZoom:!0,children:X.jsx(gbt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Qr(t.onCloseAutoFocus,s=>{s.preventDefault(),i.current||n.triggerRef.current?.focus()}),onPointerDownOutside:Qr(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:Qr(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1})})})}),bxo=Y.forwardRef((t,e)=>{const n=b8(Sk,t.__scopePopover),o=Y.useRef(!1),r=Y.useRef(!1);return X.jsx(gbt,{...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()}})}),gbt=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=b8(Sk,n),m=EF(n);return cbe(),X.jsx(bK,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:X.jsx(oO,{asChild:!0,disableOutsidePointerEvents:s,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>d.onOpenChange(!1),children:X.jsx(Cbe,{"data-state":bbt(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)"}})})})}),ybt="PopoverClose",Pxo=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=b8(ybt,n);return X.jsx(Uc.button,{type:"button",...o,ref:e,onClick:Qr(t.onClick,()=>r.onOpenChange(!1))})});Pxo.displayName=ybt;var vxo="PopoverArrow",Sxo=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=EF(n);return X.jsx(Mbe,{...r,...o,ref:e})});Sxo.displayName=vxo;function bbt(t){return t?"open":"closed"}var Cxo=dbt,Mxo=pbt,Txo=fbt,Pbt=xbt;const wxo=Cxo,Exo=Mxo,vbt=Y.forwardRef(({className:t,align:e="center",sideOffset:n=4,...o},r)=>X.jsx(Txo,{children:X.jsx(Pbt,{ref:r,align:e,sideOffset:n,className:yr("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})}));vbt.displayName=Pbt.displayName;function Sbt(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 Dxo(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 Cbt(t,e){for(const n of t){if(n.path===e)return n;if(n.children){const o=Cbt(n.children,e);if(o)return o}}return null}function Axo(t,e){let n;if(e?n=Cbt(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)=>Sbt(i.name,s.name)),r.sort((i,s)=>Sbt(i.name,s.name)),{files:o,folders:r}}const kxo=t=>{const e=t.split("/").pop()||"";return e.endsWith(".py.tsx")?e.slice(0,-4):e};function Xve(t){const e=t.lastIndexOf("/");return e===-1?"/":t.substring(0,e)}function Rxo({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 _=Xve(u);return _==="/"?null:_}}if(t&&e.includes(t)){const c=Xve(t);return c==="/"?null:c}return null});return Y.useEffect(()=>{if(t&&!n&&e.includes(t)){const c=Xve(t);i(c==="/"?null:c)}},[t,n,e]),{currentFolder:r,navigateToFolder:c=>{i(c),o(!0)},resetManualNavigation:()=>{o(!1)}}}const Gve=t=>t.endsWith(".tsx")||t.endsWith(".jsx")?X.jsx(UGn,{className:"rf-h-4 rf-w-4 rf-text-blue-500"}):t.endsWith(".md")||t.endsWith(".txt")?X.jsx(qGn,{className:"rf-h-4 rf-w-4 rf-text-gray-600"}):X.jsx(KGn,{className:"rf-h-4 rf-w-4 rf-text-gray-500"}),Nxo=t=>t.endsWith(".tsx")||XQ(t)||t.endsWith(".jsx"),Ixo=t=>kxo(t),Mbt=t=>t.substring(0,t.lastIndexOf("/"))||"/",Tbt=({files:t,onFileChange:e,currentFile:n,fileFilter:o=Nxo,getDisplayName:r=Ixo,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}=Rxo({currentFile:m,files:t}),[g,y]=Y.useState(0),[b,v]=Y.useState(""),[S,M]=qE("runframe:recentlyViewed",[]),[T,D]=qE("runframe:showRecents",!1);Y.useEffect(()=>{const ie=de=>{(de.metaKey||de.ctrlKey)&&de.key==="k"&&(de.preventDefault(),d(be=>!be))};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[]);const A=t.filter(o),L=Y.useRef(null);Y.useEffect(()=>{const ie=()=>{L.current&&(clearTimeout(L.current),L.current=null)};return h(n),n&&A.includes(n)&&(ie(),L.current=setTimeout(()=>{M(de=>{if(de[0]===n)return de;const be=de.filter(Me=>Me!==n);return[n,...be].slice(0,10)})},500)),ie},[n,A,M]);const H=Dxo(A),{files:F,folders:B}=Axo(H,p||""),G=(()=>{if(!b.trim())return{currentDirResults:[],globalResults:[]};const ie=b.toLowerCase(),be=A.map(_e=>{const Ce=_e.split("/").pop()||"";return{path:_e,fileName:Ce}}).filter(_e=>_e.fileName.toLowerCase().includes(ie)||_e.path.toLowerCase().includes(ie)),Me=be.filter(_e=>p?_e.path.substring(0,_e.path.lastIndexOf("/"))===p:!_e.path.includes("/")),Ee=be.filter(_e=>p?_e.path.substring(0,_e.path.lastIndexOf("/"))!==p:_e.path.includes("/"));return{currentDirResults:Me,globalResults:Ee}})(),K=b.trim().length>0,Q=ie=>{x(ie),y(0)},oe=Y.useCallback(()=>{if(!p)return;const ie=p.lastIndexOf("/"),de=ie===-1?null:p.substring(0,ie);Q(de)},[p,Q]);Y.useEffect(()=>{if(!_)return;const ie=de=>{(de.metaKey||de.ctrlKey)&&de.key==="ArrowUp"&&(de.preventDefault(),oe())};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[_,oe]);const ue=Y.useCallback((ie,de,be=!1)=>{if(h(ie),y(de),d(!1),e(ie),be){const Me=ie.lastIndexOf("/"),Ee=Me===-1?null:ie.substring(0,Me);Q(Ee)}},[e,Q]);Y.useEffect(()=>{const ie=de=>{if((de.metaKey||de.ctrlKey)&&(de.key==="ArrowLeft"||de.key==="ArrowRight")){if(de.preventDefault(),!n||F.length===0)return;const be=F.findIndex(_e=>_e.path===n);if(be===-1)return;let Me;de.key==="ArrowLeft"?Me=be===0?F.length-1:be-1:Me=be===F.length-1?0:be+1;const Ee=F[Me];Ee&&ue(Ee.path,Me)}};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[n,F,ue]),Y.useEffect(()=>{if(F.length>0){const ie=F.findIndex(de=>de.path===n);ie>=0&&y(ie)}},[F,n]);const ne=Y.useMemo(()=>{const ie=u.filter(Me=>A.includes(Me)),de=S.filter(Me=>A.includes(Me)),be=[];ie.length>0&&be.push({path:ie[0],type:"saved"});for(const Me of de){if(be.length>=3)break;be.some(Ee=>Ee.path===Me)||be.push({path:Me,type:"viewed"})}return be},[u,S,A]),re=p??"/";re.length>25&&""+re.slice(-22);const ae=()=>`rf-w-full rf-min-w-[600px] ${K?"rf-max-w-[600px]":"rf-max-w-[1000px]"}`;return X.jsx("div",{className:"rf-flex rf-items-center rf-gap-1",children:X.jsxs(wxo,{open:_,onOpenChange:ie=>{d(ie),ie||(v(""),f())},children:[X.jsx(Exo,{asChild:!0,children:X.jsxs(kc,{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:[X.jsx("span",{className:"rf-truncate rf-text-left",children:m?r(m):i}),X.jsx(BGn,{className:"rf-opacity-50 rf-flex-shrink-0"})]})}),X.jsx(vbt,{className:yr("!rf-p-0 !rf-overflow-y-auto !rf-max-h-[80vh] !rf-z-[200]",ae()),children:X.jsxs(cbt,{shouldFilter:!1,children:[X.jsx(lbt,{placeholder:s,className:"rf-h-9 rf-w-full",value:b,onValueChange:v}),ne.length>0&&X.jsxs("div",{className:"rf-border-b rf-border-gray-200",children:[X.jsxs("button",{onClick:()=>D(!T),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:[X.jsx("span",{className:"rf-font-medium",children:"Recent Files"}),X.jsx(rbe,{className:yr("rf-h-4 rf-w-4 rf-transition-transform",!T&&"-rf-rotate-90")})]}),T&&X.jsx("div",{className:"rf-pb-1",children:ne.map((ie,de)=>X.jsxs("div",{onClick:()=>ue(ie.path,de,!0),className:yr("rf-flex rf-items-center rf-px-3 rf-py-1.5 rf-cursor-pointer hover:rf-bg-slate-100",ie.path===n&&"rf-font-medium"),children:[ie.type==="saved"?X.jsx("span",{title:"Recently saved",children:X.jsx(iYn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-green-500"})}):X.jsx("span",{title:"Recently viewed",children:X.jsx(jGn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-500"})}),X.jsx("span",{className:"rf-text-sm",children:r(ie.path.split("/").pop()||"")}),X.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Mbt(ie.path)}),X.jsx(gM,{className:yr("rf-ml-auto rf-h-4 rf-w-4",ie.path===n?"rf-opacity-100":"rf-opacity-0")})]},ie.path))})]}),X.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:[X.jsx("div",{className:"rf-flex rf-items-center rf-text-xs rf-text-slate-600 rf-min-w-0 rf-flex-1",children:X.jsxs("div",{className:"rf-flex rf-items-center rf-min-w-0",children:[X.jsx("button",{onClick:()=>Q(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((ie,de,be)=>{const Me=be.slice(0,de+1).join("/");return X.jsxs("span",{className:"rf-flex rf-items-center rf-min-w-0",children:[X.jsx("span",{className:"rf-mx-1 rf-flex-shrink-0",children:"/"}),de===be.length-1?X.jsx("span",{className:"rf-text-slate-800 rf-truncate rf-max-w-[200px]",title:ie,children:ie}):X.jsx("button",{onClick:()=>Q(Me),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:ie,children:ie})]},Me)})]})}),X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2 rf-flex-shrink-0",children:p&&X.jsxs("button",{onClick:oe,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:[X.jsx(OGn,{className:"rf-h-3 rf-w-3"}),X.jsx("span",{className:"rf-text-xs rf-font-medium",children:"Up"})]})})]}),X.jsx(ubt,{className:"rf-overflow-visible rf-max-h-none",children:K?X.jsx(X.Fragment,{children:G.currentDirResults.length===0&&G.globalResults.length===0?X.jsxs(jve,{children:['No files found matching "',b,'".']}):X.jsxs(X.Fragment,{children:[G.currentDirResults.length>0&&X.jsx(TF,{children:G.currentDirResults.map((ie,de)=>X.jsxs(wF,{value:`search-current:${ie.path}`,onSelect:()=>{h(ie.path),d(!1),e(ie.path)},className:yr(ie.path===n&&"rf-font-medium","rf-group"),children:[X.jsx("span",{className:"rf-mr-2",children:Gve(ie.fileName)}),X.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[X.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ie.fileName)}),X.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:p||"/"}),ie.path===n&&X.jsx(gM,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ie.path))}),G.globalResults.length>0&&X.jsx(TF,{children:G.globalResults.map(ie=>X.jsxs(wF,{value:`search-global:${ie.path}`,onSelect:()=>{h(ie.path),d(!1),e(ie.path)},className:yr(ie.path===n&&"rf-font-medium","rf-group"),children:[X.jsx("span",{className:"rf-mr-2",children:Gve(ie.fileName)}),X.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[X.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ie.fileName)}),X.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Mbt(ie.path)}),ie.path===n&&X.jsx(gM,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ie.path))})]})}):X.jsxs(X.Fragment,{children:[X.jsx(jve,{children:a}),F.length>0&&X.jsx(TF,{children:F.map((ie,de)=>X.jsxs(wF,{value:`current:${ie.path}`,onSelect:()=>ue(ie.path,de),className:yr(ie.path===n&&"rf-font-medium","rf-group"),children:[X.jsx("span",{className:"rf-mr-2",children:Gve(ie.name)}),r(ie.name),X.jsx("div",{className:"rf-ml-auto rf-flex rf-items-center rf-gap-1",children:X.jsx(gM,{className:yr("rf-h-4 rf-w-4",ie.path===n?"rf-opacity-100":"rf-opacity-0")})})]},ie.path))}),B.length>0&&X.jsx(TF,{children:B.map(ie=>X.jsxs(wF,{value:`folder-${ie.path}`,onSelect:()=>Q(ie.path),className:"rf-text-slate-600 hover:rf-text-slate-900",children:[X.jsx(JGn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-600"}),ie.name,X.jsx(HA,{className:"rf-ml-auto rf-h-4 rf-w-4"})]},ie.path))}),F.length===0&&B.length===0&&X.jsx("div",{className:"rf-p-4 rf-text-center rf-text-slate-500 rf-text-sm",children:"No files or folders in this directory"})]})})]})})]})})},wbt=({files:t,onFileChange:e,currentFile:n})=>X.jsx(Tbt,{files:t,onFileChange:e,currentFile:n,fileFilter:()=>!0,placeholder:"Select circuit",searchPlaceholder:"Search for circuit file",emptyMessage:"No circuit files found in this directory."}),Hxo=t=>{cQ();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(T=>T.filePath===b);if(!v)throw new Error(`File reference not found for ${b}`);const M=await(t.onFetchFile||p)(v);c(T=>({...T,[b]:M})),r(M),t.onCircuitJsonPathChange?.(b),d(T=>{const D=new Set(T);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=Ubt(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 X.jsx("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full rf-items-center rf-justify-center",children:X.jsxs("div",{className:"rf-text-center rf-p-8",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-2",children:"No Circuit JSON Files Found"}),X.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Please provide circuit JSON files to view."})]})});const y=_.has(e);return X.jsx(x3,{fallbackRender:({error:b})=>X.jsx("div",{className:"rf-mt-4 rf-mx-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Circuit JSON Preview"}),X.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?X.jsxs("div",{className:"rf-w-full rf-h-full rf-flex rf-flex-col",children:[X.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)&&X.jsx(vF,{isWebEmbedded:!0,circuitJson:null,projectName:t.projectName}),h.length>1&&X.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:X.jsx(wbt,{currentFile:e,files:h,onFileChange:f})})]}),X.jsx("div",{className:"rf-flex-1 rf-flex rf-items-center rf-justify-center",children:X.jsxs("div",{className:"rf-text-center rf-p-8",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-600 rf-mb-2",children:"Failed to Load Circuit File"}),X.jsxs("p",{className:"rf-text-sm rf-text-gray-600 rf-mb-4",children:["Could not load: ",e]}),X.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-2",children:[X.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&&X.jsx("p",{className:"rf-text-xs rf-text-gray-500",children:"Or select a different file from the dropdown above"})]})]})})]}):X.jsx(S3t,{circuitJson:o,defaultToFullScreen:t.defaultToFullScreen,showToggleFullScreen:t.showToggleFullScreen,showFileMenu:!1,isWebEmbedded:!1,projectName:t.projectName,defaultActiveTab:t.tabSelected,leftHeaderContent:X.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full",children:[(t.showFileMenu??!0)&&X.jsx(vF,{isWebEmbedded:!0,circuitJson:o,projectName:t.projectName}),h.length>1&&X.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:X.jsx(wbt,{currentFile:e,files:h,onFileChange:f})})]})})})},Lxo=()=>{const t=v0(e=>e.fsMap);Y.useEffect(()=>{if(!document||!t)return;const e=Array.from(t.keys()),n=Ubt(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])},Ebt=(t,e,n)=>{const o=t instanceof RegExp?Dbt(t,n):t,r=e instanceof RegExp?Dbt(e,n):e,i=o!==null&&r!=null&&Oxo(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)}},Dbt=(t,e)=>{const n=e.match(t);return n?n[0]:null},Oxo=(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},Abt="\0SLASH"+Math.random()+"\0",kbt="\0OPEN"+Math.random()+"\0",Yve="\0CLOSE"+Math.random()+"\0",Rbt="\0COMMA"+Math.random()+"\0",Nbt="\0PERIOD"+Math.random()+"\0",Fxo=new RegExp(Abt,"g"),Bxo=new RegExp(kbt,"g"),zxo=new RegExp(Yve,"g"),Vxo=new RegExp(Rbt,"g"),$xo=new RegExp(Nbt,"g"),Wxo=/\\\\/g,jxo=/\\{/g,Uxo=/\\}/g,Xxo=/\\,/g,Gxo=/\\./g;function qve(t){return isNaN(t)?t.charCodeAt(0):parseInt(t,10)}function Yxo(t){return t.replace(Wxo,Abt).replace(jxo,kbt).replace(Uxo,Yve).replace(Xxo,Rbt).replace(Gxo,Nbt)}function qxo(t){return t.replace(Fxo,"\\").replace(Bxo,"{").replace(zxo,"}").replace(Vxo,",").replace($xo,".")}function Ibt(t){if(!t)return[""];const e=[],n=Ebt("{","}",t);if(!n)return t.split(",");const{pre:o,body:r,post:i}=n,s=o.split(",");s[s.length-1]+="{"+r+"}";const a=Ibt(i);return i.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),e.push.apply(e,s),e}function Kxo(t){return t?(t.slice(0,2)==="{}"&&(t="\\{\\}"+t.slice(2)),DF(Yxo(t),!0).map(qxo)):[]}function Jxo(t){return"{"+t+"}"}function Qxo(t){return/^-?0\d/.test(t)}function Zxo(t,e){return t<=e}function ego(t,e){return t>=e}function DF(t,e){const n=[],o=Ebt("{","}",t);if(!o)return[t];const r=o.pre,i=o.post.length?DF(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+Yve+o.post,DF(t)):[t];let u;if(c)u=o.body.split(/\.\./);else if(u=Ibt(o.body),u.length===1&&u[0]!==void 0&&(u=DF(u[0],!1).map(Jxo),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=qve(u[0]),m=qve(u[1]),h=Math.max(u[0].length,u[1].length);let p=u.length===3&&u[2]!==void 0?Math.abs(qve(u[2])):1,x=Zxo;m<d&&(p*=-1,x=ego);const g=u.some(Qxo);_=[];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(_,DF(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 tgo=1024*64,QQ=t=>{if(typeof t!="string")throw new TypeError("invalid pattern");if(t.length>tgo)throw new TypeError("pattern is too long")},ngo={"[: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]},AF=t=>t.replace(/[[\]\\-]/g,"\\$&"),ogo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Hbt=t=>t.join(""),rgo=(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(ngo))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(AF(_)+"-"+AF(p)):p===_&&o.push(AF(p)),_="",i++;continue}if(t.startsWith("-]",i+1)){o.push(AF(p+"-")),i+=2;continue}if(t.startsWith("-",i+1)){_=p,i+=2;continue}o.push(AF(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[ogo(p),!1,u-n,!1]}const d="["+(l?"^":"")+Hbt(o)+"]",m="["+(l?"":"^")+Hbt(r)+"]";return[o.length&&r.length?"("+d+"|"+m+")":o.length?d:m,a,u-n,!0]},kF=(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"),igo=new Set(["!","?","+","*","@"]),Lbt=t=>igo.has(t),sgo="(?!(?:^|/)\\.\\.?(?:$|/))",ZQ="(?!\\.)",ago=new Set(["[","."]),cgo=new Set(["..","."]),lgo=new Set("().*{}+?[]^$\\!"),ugo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Kve="[^/]",Obt=Kve+"*?",Fbt=Kve+"+?";class ix{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 ix&&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 ix&&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 ix(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&&Lbt(p)&&e.charAt(m)==="("){n.push(h),h="";const x=new ix(p,n);m=ix.#c(e,x,m,r),n.push(x);continue}h+=p}return n.push(h),m}let l=o+1,u=new ix(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(Lbt(m)&&e.charAt(l)==="("){u.push(d),d="";const h=new ix(m,u);u.push(h),l=ix.#c(e,h,l,r);continue}if(m==="|"){u.push(d),d="",_.push(u),u=new ix(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 ix(null,void 0,n);return ix.#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"?ix.#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&&cgo.has(this.#t[0]))){const h=ago,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?sgo:x?ZQ:""}let _="";return this.isEnd()&&this.#o.#l&&this.#e?.type==="!"&&(_="(?:$|\\/)"),[u+l+_,kF(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,kF(this.toString()),!1,!1]}let s=!o||e||n||!ZQ?"":this.#h(!0);s===i&&(s=""),s&&(i=`(?:${i})(?:${s})*?`);let a="";if(this.type==="!"&&this.#_)a=(this.isStart()&&!n?ZQ:"")+Fbt;else{const c=this.type==="!"?"))"+(this.isStart()&&!n&&!e?ZQ:"")+Obt+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=r+i+c}return[a,kF(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+=(lgo.has(c)?"\\":"")+c;continue}if(c==="\\"){a===e.length-1?i+="\\\\":r=!0;continue}if(c==="["){const[l,u,_,d]=rgo(e,a);if(_){i+=l,s=s||u,a+=_-1,n=n||d;continue}}if(c==="*"){i+=o&&e==="*"?Fbt:Obt,n=!0;continue}if(c==="?"){i+=Kve,n=!0;continue}i+=ugo(c)}return[i,kF(e),!!n,s]}}const _go=(t,{windowsPathsNoEscape:e=!1,magicalBraces:n=!1}={})=>n?e?t.replace(/[?*()[\]{}]/g,"[$&]"):t.replace(/[?*()[\]\\{}]/g,"\\$&"):e?t.replace(/[?*()[\]]/g,"[$&]"):t.replace(/[?*()[\]\\]/g,"\\$&");var Ck={env:{}};const sx=(t,e,n={})=>(QQ(e),!n.nocomment&&e.charAt(0)==="#"?!1:new RF(e,n).match(t)),dgo=/^\*+([^+@!?\*\[\(]*)$/,hgo=t=>e=>!e.startsWith(".")&&e.endsWith(t),mgo=t=>e=>e.endsWith(t),pgo=t=>(t=t.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(t)),fgo=t=>(t=t.toLowerCase(),e=>e.toLowerCase().endsWith(t)),xgo=/^\*+\.\*+$/,ggo=t=>!t.startsWith(".")&&t.includes("."),ygo=t=>t!=="."&&t!==".."&&t.includes("."),bgo=/^\.\*+$/,Pgo=t=>t!=="."&&t!==".."&&t.startsWith("."),vgo=/^\*+$/,Sgo=t=>t.length!==0&&!t.startsWith("."),Cgo=t=>t.length!==0&&t!=="."&&t!=="..",Mgo=/^\?+([^+@!?\*\[\(]*)?$/,Tgo=([t,e=""])=>{const n=Bbt([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},wgo=([t,e=""])=>{const n=zbt([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},Ego=([t,e=""])=>{const n=zbt([t]);return e?o=>n(o)&&o.endsWith(e):n},Dgo=([t,e=""])=>{const n=Bbt([t]);return e?o=>n(o)&&o.endsWith(e):n},Bbt=([t])=>{const e=t.length;return n=>n.length===e&&!n.startsWith(".")},zbt=([t])=>{const e=t.length;return n=>n.length===e&&n!=="."&&n!==".."},Vbt=typeof Ck=="object"&&Ck?typeof Ck.env=="object"&&Ck.env&&Ck.env.__MINIMATCH_TESTING_PLATFORM__||Ck.platform:"posix",$bt={win32:{sep:"\\"},posix:{sep:"/"}},Ago=Vbt==="win32"?$bt.win32.sep:$bt.posix.sep;sx.sep=Ago;const E3=Symbol("globstar **");sx.GLOBSTAR=E3;const kgo="[^/]"+"*?",Rgo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Ngo="(?:(?!(?:\\/|^)\\.).)*?",Igo=(t,e={})=>n=>sx(n,t,e);sx.filter=Igo;const D3=(t,e={})=>Object.assign({},t,e),Hgo=t=>{if(!t||typeof t!="object"||!Object.keys(t).length)return sx;const e=sx;return Object.assign((o,r,i={})=>e(o,r,D3(t,i)),{Minimatch:class extends e.Minimatch{constructor(r,i={}){super(r,D3(t,i))}static defaults(r){return e.defaults(D3(t,r)).Minimatch}},AST:class extends e.AST{constructor(r,i,s={}){super(r,i,D3(t,s))}static fromGlob(r,i={}){return e.AST.fromGlob(r,D3(t,i))}},unescape:(o,r={})=>e.unescape(o,D3(t,r)),escape:(o,r={})=>e.escape(o,D3(t,r)),filter:(o,r={})=>e.filter(o,D3(t,r)),defaults:o=>e.defaults(D3(t,o)),makeRe:(o,r={})=>e.makeRe(o,D3(t,r)),braceExpand:(o,r={})=>e.braceExpand(o,D3(t,r)),match:(o,r,i={})=>e.match(o,r,D3(t,i)),sep:e.sep,GLOBSTAR:E3})};sx.defaults=Hgo;const Wbt=(t,e={})=>(QQ(t),e.nobrace||!/\{(?:(?!\{).)*\}/.test(t)?[t]:Kxo(t));sx.braceExpand=Wbt;const Lgo=(t,e={})=>new RF(t,e).makeRe();sx.makeRe=Lgo;const Ogo=(t,e,n={})=>{const o=new RF(e,n);return t=t.filter(r=>o.match(r)),o.options.nonull&&!t.length&&t.push(e),t};sx.match=Ogo;const jbt=/[?*]|[+@!]\(.*?\)|\[|\]/,Fgo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");class RF{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(e,n={}){QQ(e),n=n||{},this.options=n,this.pattern=e,this.platform=n.platform||Vbt,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]==="?"||!jbt.test(i[2]))&&!jbt.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===E3){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(`
|
|
5824
|
+
${S}`)}},[e,d]),Y.useEffect(()=>{e&&!d&&v3t().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=f8(),M=_.current?.value||"";try{const T=await v3t();if(T.size===0){Ss.error("No project files available to include in the bug report"),r(!1);return}const D=new Date(Date.now()+1440*60*1e3).toISOString(),L=(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(T.entries()),F=[];for(let V=0;V<H.length;V++){const[G,K]=H[V];c({current:V+1,total:H.length,currentFile:G});try{const Q={bug_report_id:L,file_path:G};K.text_content&&(Q.content_text=K.text_content),K.binary_content_b64&&(Q.content_base64=K.binary_content_b64),await S.post("bug_reports/upload_file",{json:Q})}catch(Q){const oe=Q instanceof p8?`HTTP ${Q.response.status}`:Q instanceof Error?Q.message:"Upload failed";F.push({filePath:G,message:oe}),u([...F])}}c(null);const B=k1o(L);m({bugReportUrl:B})}catch(T){if(console.error("Failed to submit bug report",T),T instanceof p8)if(T.response.status===401)if(f){const D="Your session has expired. Please sign in again to continue.";s(D),Ss.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),Ss.error(D),setTimeout(()=>{x&&(y(),x())},1e3)}else{const D=`Failed to submit bug report (${T.response.status})`;s(D),Ss.error(D)}else if(T instanceof Error)s(T.message),Ss.error(T.message);else{const D="Failed to submit bug report";s(D),Ss.error(D)}}finally{r(!1)}},[f,x]);return{BugReportDialog:Y.useMemo(()=>{const S=a?Math.round(a.current/a.total*100):0;return X.jsx(n5t,{open:e,onOpenChange:M=>{M?(s(null),m(null),c(null),u([]),n(!0)):o||y()},children:X.jsxs(zPe,{children:[X.jsxs(VPe,{children:[X.jsx(WPe,{children:d?"Bug Report Created":"Report Bug"}),X.jsx(jPe,{asChild:!0,children:d?X.jsxs("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:[X.jsx("p",{children:"Bug report created successfully."}),l.length>0&&X.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:[X.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,T)=>X.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[X.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),X.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},T))]}),X.jsx("div",{children:X.jsx("a",{className:"rf-text-blue-600 hover:rf-underline",href:d.bugReportUrl,target:"_blank",rel:"noreferrer",children:"View bug report"})}),X.jsxs("p",{children:["Please share this link privately with tscircuit staff so we can help debug. Join the",X.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"}),"."]})]}):X.jsx("div",{className:"rf-text-left rf-space-y-3 rf-text-sm",children:a?X.jsxs("div",{className:"rf-space-y-2 rf-overflow-hidden",children:[X.jsxs("div",{className:"rf-flex rf-justify-between rf-text-xs",children:[X.jsx("span",{children:"Uploading files..."}),X.jsxs("span",{children:[a.current,"/",a.total]})]}),X.jsx("div",{className:"rf-w-full rf-h-2 rf-bg-gray-200 rf-rounded-full rf-overflow-hidden",children:X.jsx("div",{className:"rf-h-full rf-bg-blue-500 rf-transition-all rf-duration-150",style:{width:`${S}%`}})}),X.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&&X.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,T)=>X.jsxs("div",{className:"rf-text-red-600 rf-text-xs rf-mb-0.5",title:`${M.filePath}: ${M.message}`,children:[X.jsx("span",{className:"rf-font-medium rf-break-all",children:M.filePath.split("/").pop()}),X.jsx("span",{className:"rf-text-red-500 rf-block rf-truncate",children:M.message})]},T))})]}):X.jsxs(X.Fragment,{children:[X.jsxs("p",{children:["Reporting a bug will upload your entire project",h>0?` (${h} file${h===1?"":"s"})`:""," ","to tscircuit support."]}),X.jsxs("div",{className:"rf-space-y-2",children:[X.jsx("label",{htmlFor:"bug-description",className:"rf-block rf-font-medium",children:"Description (optional)"}),X.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})]}),X.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",X.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&&X.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&&X.jsx("p",{className:"rf-text-red-600",children:i})]})})})]}),X.jsx($Pe,{children:d?X.jsx("button",{type:"button",className:IA(),onClick:()=>{y()},children:"Close"}):X.jsxs(X.Fragment,{children:[X.jsx(UPe,{disabled:o,onClick:()=>{o||y()},children:"Cancel"}),!f&&x?X.jsx("button",{type:"button",className:IA(),onClick:M=>{M.preventDefault(),y(),x()},children:"Sign In"}):X.jsx("button",{type:"button",className:db(IA(),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 N1o({open:t,onOpenChange:e,onExport:n}){const[o,r]=Y.useState(!1),i=()=>{n({includeSilkscreen:o}),e(!1)},s=()=>{e(!1)};return X.jsx(pk,{open:t,onOpenChange:e,children:X.jsxs(WM,{children:[X.jsxs(jM,{children:[X.jsx(UM,{children:"LightBurn Export Options"}),X.jsx(fk,{children:"Configure export settings for PCB laser ablation with LightBurn"})]}),X.jsx("div",{className:"rf-flex rf-flex-col rf-gap-4 rf-py-4",children:X.jsxs("div",{className:"rf-flex rf-items-center rf-space-x-2",children:[X.jsx(_F,{id:"includeSilkscreen",checked:o,onCheckedChange:a=>r(a===!0)}),X.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"})]})}),X.jsxs(dF,{children:[X.jsx(kc,{variant:"outline",onClick:s,children:"Cancel"}),X.jsx(kc,{onClick:i,children:"Export"})]})]})})}const I1o=/#(\d+)/,H1o=t=>{const e=t.match(I1o);if(!e)return null;const n=Number.parseInt(e[1],10);return Number.isFinite(n)?n:null},L1o=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},O1o=t=>{if(!t)return null;let e=null,n=-1,o=-1;for(const[r,i]of Object.entries(t)){const s=H1o(r),a=L1o(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},vF=t=>{const e=_Q(Ee=>Ee.lastRunEvalVersion),n=v0(Ee=>Ee.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,T]=Y.useState(!1),[D,A]=Y.useState(!1),[L,H]=Y.useState(null),F=D1o(),B=v0(Ee=>Ee.pushEvent),V=v0(Ee=>Ee.recentEvents),G=Y.useMemo(()=>Date.now(),[]);xho(Ee=>{if(!(new Date(Ee.created_at).valueOf()<G+500)){if(Ee.event_type==="FILE_UPDATED"){s(!0);return}if(Ee.event_type==="SNIPPET_SAVED"){s(!1),c(!1),g("Snippet saved successfully."),S(!1);return}Ee.event_type==="REQUEST_EXPORT"&&(T(!0),g("Export processing..."),S(!1)),Ee.event_type==="EXPORT_CREATED"&&(g(`Export created: ${Ee.exportFilePath}`),S(!1),T(!1))}}),Y.useEffect(()=>{if(!l||_===null)return;const Ee=V.filter(xe=>new Date(xe.created_at).valueOf()>_),_e=Ee.find(xe=>xe.event_type==="FAILED_TO_SAVE_SNIPPET"),Ce=Ee.find(xe=>xe.event_type==="SNIPPET_SAVED");_e&&(u(!1),d(null),b(_e.message??"Failed to save snippet. See console for error."),console.error(_e.message),S(!0),_e.error_code==="SNIPPET_UNSET"&&_e.available_snippet_names&&(h(_e.available_snippet_names),x(!0))),Ce&&(u(!1),d(null),g("Snippet saved successfully."),S(!1))},[V,l]);const K=async()=>{u(!0),d(Date.now()),g(null),S(!1),await B({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:o})},oe=v0(Ee=>Ee.circuitJson)??t.circuitJson,[ue,ne]=Y.useState(!1),[re,ae]=Y.useState(!1),{BugReportDialog:ie,openBugReportDialog:de}=R1o({onLoginRequired:t.onLoginRequired}),be=async Ee=>{L&&(await k5t({circuitJson:L.circuitJson,projectName:L.projectName,options:Ee}),H(null))},Me=Y.useMemo(()=>O1o(t.autoroutingLog),[t.autoroutingLog]);return X.jsxs(X.Fragment,{children:[X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1 rf-flex-shrink-0",children:[X.jsxs(XK,{children:[X.jsx(GK,{asChild:!0,children:X.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"File"})}),X.jsxs(mO,{className:"rf-z-[101]",children:[!t.isWebEmbedded&&X.jsxs(X.Fragment,{children:[X.jsx(Qd,{className:"rf-text-xs",onSelect:K,disabled:l,children:l?"Saving...":"Push"}),parseInt(window.location.port)>5e3&&X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{F.open()},children:"Order"}),X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>ne(!0),disabled:l,children:"Import"}),X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{if(!CQ()){Ss.error("Requires tscircuit token");return}ae(!0)},children:"AI Review"})]}),!t.isWebEmbedded&&t.onLoginRequired&&X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{t.onLoginRequired?.()},children:"Sign In"}),!t.isWebEmbedded&&X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",children:"Report Bug"}),X.jsx(dO,{children:X.jsxs(XA,{children:[X.jsx(Qd,{className:"rf-text-xs",onSelect:()=>{de()},children:"Report Entire Circuit"}),X.jsx(Qd,{className:"rf-text-xs",disabled:!Me||!t.onReportAutoroutingLog,onSelect:()=>{!Me||!t.onReportAutoroutingLog||t.onReportAutoroutingLog(Me.key,{simpleRouteJson:Me.value.simpleRouteJson})},children:"Report Autorouter Bug"})]})})]}),X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",disabled:M,children:M?"Exporting...":"Export"}),X.jsx(dO,{children:X.jsx(XA,{children:Apo.map((Ee,_e)=>X.jsx(Qd,{onSelect:()=>{if(!oe){Ss.error("No Circuit JSON to export");return}let Ce="Untitled";if(n){const Fe=n.split("/").pop();Fe&&(Ce=Fe.replace(/\.[^.]+$/,""))}const xe=t.projectName??o??Ce;if(Ee.name==="LightBurn"){H({circuitJson:oe,projectName:xe}),A(!0);return}kpo({exportName:Ee.name,circuitJson:oe,projectName:xe?.replace(/\.(board|circuit)$/,"")})},disabled:M,children:X.jsx("span",{className:"rf-text-xs",children:Ee.name})},_e))})})]}),!t.isWebEmbedded&&X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",children:"Advanced"}),X.jsx(dO,{children:X.jsxs(XA,{children:[X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",children:X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(_F,{id:"load-latest-eval",checked:t.shouldLoadLatestEval,onCheckedChange:Ee=>{t.onChangeShouldLoadLatestEval?.(Ee===!0)}}),X.jsx("label",{htmlFor:"load-latest-eval",className:"rf-text-xs rf-cursor-pointer",children:"Force Latest @tscircuit/eval"})]})}),e&&X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",children:X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:X.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/eval@",e]})})}),X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",children:X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:X.jsxs("span",{className:"rf-text-xs",children:["@tscircuit/runframe@",mho.version]})})}),X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",onClick:()=>{window.open("/api/admin","_blank")},children:X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2",children:X.jsx("span",{className:"rf-text-xs",children:"CLI Admin Panel"})})})]})})]})]}),X.jsx(n5t,{open:v,onOpenChange:S,children:X.jsxs(zPe,{children:[X.jsxs(VPe,{children:[X.jsx(WPe,{children:"Error Saving Snippet"}),X.jsx(jPe,{children:y})]}),X.jsx($Pe,{children:X.jsx(UPe,{onClick:()=>S(!1),children:"Dismiss"})})]})}),X.jsx(fho,{snippetNames:m??[],onSelect:async Ee=>{u(!0),d(Date.now()),r(Ee),await B({event_type:"REQUEST_TO_SAVE_SNIPPET",snippet_name:Ee}),x(!1)},onCancel:()=>x(!1),isOpen:p})]}),X.jsxs(XK,{children:[X.jsx(GK,{asChild:!0,children:X.jsx("div",{className:"rf-whitespace-nowrap rf-text-xs font-medium rf-p-2 rf-mx-1 rf-cursor-pointer rf-relative",children:"View"})}),X.jsx(mO,{className:"rf-z-[104]",children:X.jsxs(hO,{children:[X.jsx(UA,{className:"rf-text-xs",children:"Schematic"}),X.jsx(dO,{children:X.jsxs(XA,{children:[X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",onSelect:Ee=>Ee.preventDefault(),children:X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(_F,{id:"show-schematic-ports",checked:t.showSchematicPorts,onCheckedChange:Ee=>{t.onChangeShowSchematicPorts?.(Ee===!0)}}),X.jsx("label",{htmlFor:"show-schematic-ports",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Ports"})]})}),X.jsx(Qd,{className:"rf-flex rf-items-center rf-gap-2",onSelect:Ee=>Ee.preventDefault(),children:X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[X.jsx(_F,{id:"show-schematic-grid",checked:t.showSchematicDebugGrid,onCheckedChange:Ee=>{t.onChangeShowSchematicDebugGrid?.(Ee===!0)}}),X.jsx("label",{htmlFor:"show-schematic-grid",className:"rf-text-xs rf-cursor-pointer",children:"Show Schematic Grid"})]})})]})})]})})]})]}),ie,X.jsx(N1o,{open:D,onOpenChange:A,onExport:be}),X.jsx(E5t,{isOpen:ue,onClose:()=>ne(!1)}),X.jsx(Bfo,{isOpen:re,onClose:()=>ae(!1),packageName:o}),X.jsx(Xlt,{position:"top-center",reverseOrder:!1,containerStyle:{zIndex:1e5},toastOptions:{className:"rf-break-all",style:{zIndex:1e5}}}),X.jsx(F.OrderDialog,{isOpen:F.isOpen,onClose:F.close,stage:F.stage,setStage:F.setStage})]})},F1o=["assembly","pinout","analog_simulation","bom","circuit_json","errors","render_log","solvers"],S3t=({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:T,editEvents:D,defaultActiveTab:A,defaultTab:L,availableTabs:H,autoRotate3dViewerDisabled:F,showSchematicDebugGrid:B=!1,showSchematicPorts:V=!1,onChangeShowSchematicDebugGrid:G,onChangeShowSchematicPorts:K,showToggleFullScreen:Q=!0,defaultToFullScreen:oe=!1,activeEffectName:ue,allowSelectingVersion:ne=!0,showFileMenu:re=!1,isWebEmbedded:ae=!1,projectName:ie,onRerunWithDebug:de,solverEvents:be,onPcbBoundsSelected:Me})=>{cQ();const{versions:Ee,latestVersion:_e,lastRunEvalVersion:Ce,search:xe,setSearch:Fe,selectVersion:We}=pho(ne),Xe=Y.useMemo(()=>i?i.filter(kt=>kt&&"error_type"in kt||kt.type.includes("error")):null,[i]),ye=Y.useMemo(()=>i?i.filter(kt=>kt&&"warning_type"in kt||kt.type.includes("warning")):null,[i]),Je=Y.useMemo(()=>i?i.some(kt=>kt.type==="schematic_group"):!0,[i]),Be=Y.useMemo(()=>i?.some(kt=>kt.type==="pcb_panel"),[i]);gyt({errorMessage:o,errorStack:r,circuitJsonErrors:Xe});const ke=L??H?.[0]??"pcb",[Ve,Ie]=qE("runframe-active-tab",A??ke,A),[Te,Ae]=Y.useState(null),[De,$e]=Y.useState(oe),[je,nt]=Y.useState(B),[rt,st]=Y.useState(V),ut=G?B:je,xt=K?V:rt,Et=G??nt,Bt=K??st;D_o(De);const Gt=Y.useCallback(kt=>{Ie(kt),d?.(kt)},[d,Ie]),Ft=()=>{$e(!De)};Y.useEffect(()=>{o&&(Ve!=="errors"&&Ae(Ve),Gt("errors"))},[o]),Y.useEffect(()=>{(Ve==="code"||Ve==="errors")&&i&&!o&&Gt(Te??A??L??H?.[0]??"pcb")},[i]);const ln=Y.useCallback(kt=>{window.TSCIRCUIT_3D_OBJECT_REF=kt===null?void 0:kt},[]);return X.jsx("div",{className:yr("flex flex-col relative rf-overflow-x-hidden rf-h-full",p),children:X.jsx("div",{className:yr("rf-md:sticky rf-md:top-2 rf-h-full",De&&"rf-fixed rf-top-0 rf-left-0 rf-w-full rf-h-full rf-bg-white rf-overflow-hidden"),children:X.jsxs(q_e,{value:Ve,onValueChange:Gt,className:"rf-flex-grow rf-flex rf-flex-col rf-h-full",children:[X.jsxs("div",{className:yr("rf-flex rf-items-center rf-gap-2 rf-p-2 rf-pb-0",x),children:[f,re&&!f&&X.jsx(vF,{isWebEmbedded:ae,circuitJson:i,projectName:ie,autoroutingLog:b,onReportAutoroutingLog:v,showSchematicDebugGrid:ut,onChangeShowSchematicDebugGrid:Et,showSchematicPorts:xt,onChangeShowSchematicPorts:Bt}),(f||re)&&X.jsx("div",{className:"rf-flex-grow"}),!f&&!re&&S&&X.jsx(Qv,{className:"rf-w-4 rf-h-4 rf-animate-spin"}),!f&&!re&&X.jsx("div",{className:"rf-flex-grow"}),m&&m.progress!==1&&!o&&X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-min-w-0 rf-max-w-xs",children:[ue?X.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:ue,children:ue}):m.lastRenderEvent&&X.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate rf-min-w-0",title:m.lastRenderEvent?.phase??"",children:m.lastRenderEvent?.phase??""}),X.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:X.jsx(Qv,{className:"rf-w-4 rf-h-4 rf-animate-spin"})}),X.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&&X.jsxs(TG,{children:[c&&X.jsx(W4,{value:"code",children:"Code"}),!H||H.includes("pcb")?X.jsxs(W4,{value:"pcb",className:"rf-whitespace-nowrap",children:[i&&X.jsx("span",{className:yr("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")?X.jsxs(W4,{value:"schematic",className:yr("rf-whitespace-nowrap",i&&!Je&&"rf-opacity-50"),disabled:i?!Je||Be:!1,children:[i&&X.jsx("span",{className:yr("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")?X.jsxs(W4,{value:"cad",children:[i&&X.jsx("span",{className:yr("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(Ve)&&X.jsx(W4,{value:Ve,children:wKe(Ve)}),X.jsxs(XK,{children:[X.jsx(GK,{asChild:!0,children:X.jsxs("div",{className:"rf-whitespace-nowrap rf-p-2 rf-mr-1 rf-cursor-pointer rf-relative",children:[X.jsx(GGn,{className:"rf-w-4 rf-h-4"}),(Xe&&Xe.length>0||o)&&X.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"})]})}),X.jsxs(mO,{className:"rf-*:text-xs rf-z-[101]",children:[F1o.filter(kt=>!H||H.includes(kt)).map(kt=>X.jsxs(Qd,{onSelect:()=>Gt(kt),children:[Ve!==kt&&X.jsx(Qht,{className:"rf-w-3 rf-h-3 rf-opacity-30"}),Ve===kt&&X.jsx(gM,{className:"rf-w-3 rf-h-3"}),X.jsx("div",{className:"rf-pr-2",children:wKe(kt)}),kt==="errors"&&(Xe&&Xe.length>0||o)&&X.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}),kt==="solvers"&&be&&be.length>0&&X.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})]},kt)),X.jsx(Qd,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:X.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/runframe@",yyt.split(".").map((kt,bn)=>bn===2?parseInt(kt)+1:kt).join(".")]})}),ne?X.jsxs(hO,{onOpenChange:kt=>!kt&&Fe(""),children:[X.jsx(UA,{className:"rf-text-xs rf-opacity-60",children:X.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",Ce??_e??"latest"]})}),X.jsx(dO,{children:X.jsxs(XA,{className:"rf-*:text-xs rf-w-40 rf-max-h-[200px] rf-overflow-y-auto",children:[X.jsx("div",{className:"rf-p-1",children:X.jsx(z4e,{value:xe,onChange:kt=>Fe(kt.target.value),placeholder:"Search...",className:"rf-h-7 rf-text-xs"})}),X.jsx(Zpt,{}),X.jsx(Qd,{onSelect:()=>We(null),children:_e?`${_e} (latest)`:"latest"}),Ee.map(kt=>X.jsx(Qd,{onSelect:()=>We(kt),children:kt},kt))]})})]}):Ce&&X.jsx(Qd,{disabled:!0,className:"rf-opacity-60 rf-cursor-default rf-select-none",children:X.jsxs("div",{className:"rf-pr-2 rf-text-xs rf-text-gray-500",children:["@tscircuit/eval@",Ce]})})]})]})]}),Q&&X.jsx(kc,{onClick:Ft,variant:"ghost",children:De?X.jsx(nYn,{size:16}):X.jsx(QGn,{size:16})})]}),c&&X.jsx(j1,{value:"code",className:"rf-flex-grow rf-overflow-hidden",children:X.jsx("div",{className:"rf-h-full",children:l})}),(!H||H.includes("pcb"))&&X.jsx(j1,{value:"pcb",children:X.jsx("div",{className:yr("rf-overflow-hidden",De?"rf-h-[calc(100vh-52px)]":"rf-h-full"),children:X.jsx(x3,{fallbackRender:({error:kt})=>X.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading PCB viewer"}),X.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:kt?.message||"An unknown error occurred"})]})}),children:i?X.jsx(w_o,{focusOnHover:!1,circuitJson:i,debugGraphics:s,onBoundsSelected:Me,containerClassName:yr("rf-h-full rf-w-full",De?"rf-min-h-[calc(100vh-240px)]":"rf-min-h-[620px]"),onEditEventsChanged:kt=>{if(T)for(const bn of kt)T(bn)}}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("assembly"))&&X.jsx(j1,{value:"assembly",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Assembly"}),children:i?X.jsx(lso,{circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,debugGrid:!0}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("pinout"))&&X.jsx(j1,{value:"pinout",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Pinout Viewer"}),children:i?X.jsx(uso,{circuitJson:i,containerStyle:{height:"100%"}}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("schematic"))&&X.jsx(j1,{value:"schematic",children:X.jsx("div",{className:yr("rf-overflow-auto rf-bg-white",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallbackRender:({error:kt})=>X.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Schematic"}),X.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:kt?.message||"An unknown error occurred"})]})}),children:i?X.jsx(aso,{spiceSimulationEnabled:!0,circuitJson:i,containerStyle:{height:"100%"},editingEnabled:!0,onEditEvent:kt=>{T?.(kt)},debugGrid:ut,showSchematicPorts:xt}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("cad"))&&X.jsx(j1,{value:"cad",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallbackRender:({error:kt,resetErrorBoundary:bn})=>X.jsx(EGn,{error:kt,resetErrorBoundary:bn}),children:i?X.jsx(gGn,{ref:ln,circuitJson:i,autoRotateDisabled:F},`cad-${De}`):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("analog_simulation"))&&X.jsx(j1,{value:"analog_simulation",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Analog Simulation"}),children:i?X.jsx(cso,{circuitJson:i,containerStyle:{height:"100%"}}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("bom"))&&X.jsx(j1,{value:"bom",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallbackRender:({error:kt})=>X.jsx("div",{className:"rf-mt-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Bill of Materials"}),X.jsx("p",{className:"rf-text-xs rf-font-mono rf-whitespace-pre-wrap rf-text-red-600 rf-mt-2",children:kt?.message||"An unknown error occurred"})]})}),children:i?X.jsx(Tso,{circuitJson:i}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("circuit_json"))&&X.jsx(j1,{value:"circuit_json",children:X.jsx("div",{className:yr("rf-overflow-auto",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading JSON viewer"}),children:i?X.jsx(hso,{elements:i}):X.jsx(s6,{onRunClicked:n})})})}),(!H||H.includes("errors"))&&X.jsx(j1,{value:"errors",className:"rf-h-full",children:X.jsx("div",{className:yr("rf-overflow-hidden",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:o||Xe&&Xe.length>0||i?X.jsx(ZJn,{code:t,fsMap:e,circuitJsonErrors:Xe,circuitJsonWarnings:ye,errorMessage:o,errorStack:r,circuitJson:i,evalVersion:Ce,autoroutingLog:b,onReportAutoroutingLog:v}):X.jsx(s6,{onRunClicked:n})})}),_&&(!H||H.includes("render_log"))&&X.jsx(j1,{value:"render_log",children:X.jsx(R_o,{renderLog:m,onRerunWithDebug:de})}),(!H||H.includes("solvers"))&&X.jsx(j1,{value:"solvers",children:X.jsx("div",{className:yr("rf-overflow-hidden",De?"rf-h-[calc(100vh-60px)]":"rf-h-full rf-min-h-[620px]"),children:X.jsx(x3,{fallback:X.jsx("div",{children:"Error loading Solvers view"}),children:X.jsx(hho,{solverEvents:be})})})})]})})})};const C3t=Symbol("Comlink.proxy"),B1o=Symbol("Comlink.endpoint"),M3t=Symbol("Comlink.releaseProxy"),Dve=Symbol("Comlink.finalizer"),VQ=Symbol("Comlink.thrown"),T3t=t=>typeof t=="object"&&t!==null||typeof t=="function",z1o={canHandle:t=>T3t(t)&&t[C3t],serialize(t){const{port1:e,port2:n}=new MessageChannel;return E3t(t,e),[n,[n]]},deserialize(t){return t.start(),A3t(t)}},V1o={canHandle:t=>T3t(t)&&VQ 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}},w3t=new Map([["proxy",z1o],["throw",V1o]]);function $1o(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function E3t(t,e=globalThis,n=["*"]){e.addEventListener("message",function o(r){if(!r||!r.data)return;if(!$1o(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(QM);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]]=QM(r.data.value),l=!0;break;case"APPLY":l=_.apply(u,c);break;case"CONSTRUCT":{const d=new _(...c);l=kve(d)}break;case"ENDPOINT":{const{port1:d,port2:m}=new MessageChannel;E3t(t,m),l=G1o(d,[d])}break;case"RELEASE":l=void 0;break;default:return}}catch(u){l={value:u,[VQ]:0}}Promise.resolve(l).catch(u=>({value:u,[VQ]:0})).then(u=>{const[_,d]=UQ(u);e.postMessage(Object.assign(Object.assign({},_),{id:i}),d),s==="RELEASE"&&(e.removeEventListener("message",o),D3t(e),Dve in t&&typeof t[Dve]=="function"&&t[Dve]())}).catch(u=>{const[_,d]=UQ({value:new TypeError("Unserializable return value"),[VQ]:0});e.postMessage(Object.assign(Object.assign({},_),{id:i}),d)})}),e.start&&e.start()}function W1o(t){return t.constructor.name==="MessagePort"}function D3t(t){W1o(t)&&t.close()}function A3t(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)}}),Ave(t,n,[],e)}function $Q(t){if(t)throw new Error("Proxy has been released and is not useable")}function k3t(t){return yk(t,new Map,{type:"RELEASE"}).then(()=>{D3t(t)})}const WQ=new WeakMap,jQ="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(WQ.get(t)||0)-1;WQ.set(t,e),e===0&&k3t(t)});function j1o(t,e){const n=(WQ.get(e)||0)+1;WQ.set(e,n),jQ&&jQ.register(t,e,t)}function U1o(t){jQ&&jQ.unregister(t)}function Ave(t,e,n=[],o=function(){}){let r=!1;const i=new Proxy(o,{get(s,a){if($Q(r),a===M3t)return()=>{U1o(i),k3t(t),e.clear(),r=!0};if(a==="then"){if(n.length===0)return{then:()=>i};const c=yk(t,e,{type:"GET",path:n.map(l=>l.toString())}).then(QM);return c.then.bind(c)}return Ave(t,e,[...n,a])},set(s,a,c){$Q(r);const[l,u]=UQ(c);return yk(t,e,{type:"SET",path:[...n,a].map(_=>_.toString()),value:l},u).then(QM)},apply(s,a,c){$Q(r);const l=n[n.length-1];if(l===B1o)return yk(t,e,{type:"ENDPOINT"}).then(QM);if(l==="bind")return Ave(t,e,n.slice(0,-1));const[u,_]=R3t(c);return yk(t,e,{type:"APPLY",path:n.map(d=>d.toString()),argumentList:u},_).then(QM)},construct(s,a){$Q(r);const[c,l]=R3t(a);return yk(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:c},l).then(QM)}});return j1o(i,t),i}function X1o(t){return Array.prototype.concat.apply([],t)}function R3t(t){const e=t.map(UQ);return[e.map(n=>n[0]),X1o(e.map(n=>n[1]))]}const N3t=new WeakMap;function G1o(t,e){return N3t.set(t,e),t}function kve(t){return Object.assign(t,{[C3t]:!0})}function UQ(t){for(const[e,n]of w3t)if(n.canHandle(t)){const[o,r]=n.serialize(t);return[{type:"HANDLER",name:e,value:o},r]}return[{type:"RAW",value:t},N3t.get(t)||[]]}function QM(t){switch(t.type){case"HANDLER":return w3t.get(t.name).deserialize(t.value);case"RAW":return t.value}}function yk(t,e,n,o){return new Promise(r=>{const i=Y1o();e.set(i,r),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),o)})}function Y1o(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Rve(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=Rve(r,i);n.push(...s)}else n.push(i)}return n}function I3t(t,e){const n=e.split(".");let o=t;for(const r of n)o=o[r];return o}var q1o=(t="latest")=>[`https://jscdn.tscircuit.com/@tscircuit/eval/${t}/dist/webworker/entrypoint.js`,`https://cdn.jsdelivr.net/npm/@tscircuit/eval@${t}/dist/webworker/entrypoint.js`,`https://unpkg.com/@tscircuit/eval@${t}/dist/webworker/entrypoint.js`],K1o=async(t="latest",e=!1)=>{let n;for(const o of q1o(t))try{const r=await globalThis.fetch(o);if(!r.ok)throw new Error(`Failed to fetch webworker entrypoint from ${o}: ${r.status} ${r.statusText}`);return await r.blob()}catch(r){n=r,e&&console.warn(`[Worker] Failed to fetch webworker entrypoint from ${o}, trying next CDN fallback if available`,r)}throw n instanceof Error?n:new Error("Failed to fetch webworker entrypoint from CDN fallbacks")},H3t=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=await K1o(t.evalVersion??"latest",t.verbose);n=URL.createObjectURL(d)}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=A3t(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"?kve(d):d;if(t.platform)for(const d of Rve(t.platform))await s.setPlatformConfigProperty(d,l(I3t(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 Rve(t.projectConfig))await s.setProjectConfigProperty(d,l(I3t(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=kve(m);s.on(d,h)},kill:async()=>{s[M3t](),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 J1o=({error:t,resetErrorBoundary:e})=>X.jsx("section",{className:"rf-h-full rf-w-full rf-grid rf-place-items-center",children:X.jsx("div",{className:"rf-min-h-full rf-flex rf-items-center rf-justify-center rf-px-4",children:X.jsxs("div",{className:"rf-max-w-lg rf-w-full rf-text-center",children:[X.jsxs("div",{className:"rf-mb-8",children:[X.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:X.jsx(aYn,{className:"rf-w-10 rf-h-10 rf-text-red-600"})}),X.jsx("h1",{className:"rf-text-2xl rf-font-bold rf-text-gray-900 rf-mb-3",children:"Oops! Something went wrong"}),X.jsx("p",{className:"rf-text-gray-600 rf-mb-4",children:"RunFrame encountered an unexpected error."}),X.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&&X.jsxs("details",{className:"rf-text-center rf-mb-6",children:[X.jsx("summary",{className:"rf-text-xs rf-text-gray-500 rf-cursor-pointer hover:rf-text-gray-700",children:"View stack trace"}),X.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})]})]}),X.jsxs("div",{className:"rf-flex rf-flex-col rf-gap-2 rf-justify-center",children:[X.jsx(kc,{variant:"destructive",size:"lg",onClick:()=>window.location.reload(),children:"Refresh Dev Server"}),X.jsx(kc,{variant:"outline",size:"lg",onClick:e,children:"Try Again"})]})]})})}),L3t=t=>{const e={};if(!t)return e;for(const o of Ey)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},Q1o=(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 Z1o(){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 e2o=({message:t="Loading files..."})=>X.jsxs("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full",children:[X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4 rf-p-2 rf-border-b",children:[X.jsx("div",{className:"rf-w-20 rf-h-9 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded-md rf-animate-pulse"}),X.jsx("div",{className:"rf-flex rf-gap-6 rf-ml-auto",children:["PCB","Schematic","3D"].map((e,n)=>X.jsx("div",{className:"rf-h-6 rf-w-20 rf-bg-gray-200 dark:rf-bg-gray-700 rf-rounded rf-animate-pulse"},n))})]}),X.jsx("div",{className:"rf-flex-1 rf-p-4",children:X.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:X.jsx("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4",children:X.jsx("div",{className:"rf-text-sm rf-text-gray-400 dark:rf-text-gray-500",children:t})})})})]}),XQ=t=>{const e=t.toLowerCase(),n=e.split("/").pop();return e.endsWith(".circuit.json")||n==="circuit.json"},t2o=t=>t.endsWith(".tsx")||XQ(t)||t.endsWith(".jsx"),n2o=({mainComponentPath:t,fsMap:e})=>Y.useMemo(()=>{if(!(t!=null&&XQ(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]),o2o=t=>!t||typeof t!="object"?!1:!!("error_type"in t||typeof t.type=="string"&&t.type.includes("error")),r2o=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)},i2o=t=>Array.isArray(t)?t.filter(o2o):[],Nve=({circuitJson:t,executionError:e})=>{const n=[];e&&n.push(r2o(e));const o=i2o(t);return n.push(...o),{hasExecutionError:!!e,...n.length>0?{errors:n}:{}}};var s2o=Symbol("radix.slottable");function a2o(t){const e=({children:n})=>X.jsx(X.Fragment,{children:n});return e.displayName=`${t}.Slottable`,e.__radixId=s2o,e}var c2o=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"}),l2o="VisuallyHidden",O3t=Y.forwardRef((t,e)=>X.jsx(Uc.span,{...t,ref:e,style:{...c2o,...t.style}}));O3t.displayName=l2o;var u2o=O3t,[GQ]=_b("Tooltip",[zA]),YQ=zA(),F3t="TooltipProvider",_2o=700,Ive="tooltip.open",[d2o,Hve]=GQ(F3t),B3t=t=>{const{__scopeTooltip:e,delayDuration:n=_2o,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)},[]),X.jsx(d2o,{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})};B3t.displayName=F3t;var SF="Tooltip",[h2o,qQ]=GQ(SF),z3t=t=>{const{__scopeTooltip:e,children:n,open:o,defaultOpen:r,onOpenChange:i,disableHoverableContent:s,delayDuration:a}=t,c=Hve(SF,t.__scopeTooltip),l=YQ(e),[u,_]=Y.useState(null),d=Df(),m=Y.useRef(0),h=s??c.disableHoverableContent,p=a??c.delayDuration,x=Y.useRef(!1),[f,g]=ZS({prop:o,defaultProp:r??!1,onChange:M=>{M?(c.onOpen(),document.dispatchEvent(new CustomEvent(Ive))):c.onClose(),i?.(M)},caller:SF}),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)},[]),X.jsx(kK,{...l,children:X.jsx(h2o,{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})})};z3t.displayName=SF;var Lve="TooltipTrigger",V3t=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=qQ(Lve,n),i=Hve(Lve,n),s=YQ(n),a=Y.useRef(null),c=S0(e,a,r.onTriggerChange),l=Y.useRef(!1),u=Y.useRef(!1),_=Y.useCallback(()=>l.current=!1,[]);return Y.useEffect(()=>()=>document.removeEventListener("pointerup",_),[_]),X.jsx(RK,{asChild:!0,...s,children:X.jsx(Uc.button,{"aria-describedby":r.open?r.contentId:void 0,"data-state":r.stateAttribute,...o,ref:c,onPointerMove:Qr(t.onPointerMove,d=>{d.pointerType!=="touch"&&!u.current&&!i.isPointerInTransitRef.current&&(r.onTriggerEnter(),u.current=!0)}),onPointerLeave:Qr(t.onPointerLeave,()=>{r.onTriggerLeave(),u.current=!1}),onPointerDown:Qr(t.onPointerDown,()=>{r.open&&r.onClose(),l.current=!0,document.addEventListener("pointerup",_,{once:!0})}),onFocus:Qr(t.onFocus,()=>{l.current||r.onOpen()}),onBlur:Qr(t.onBlur,r.onClose),onClick:Qr(t.onClick,r.onClose)})})});V3t.displayName=Lve;var m2o="TooltipPortal",[dbo,p2o]=GQ(m2o,{forceMount:void 0}),bk="TooltipContent",$3t=Y.forwardRef((t,e)=>{const n=p2o(bk,t.__scopeTooltip),{forceMount:o=n.forceMount,side:r="top",...i}=t,s=qQ(bk,t.__scopeTooltip);return X.jsx(Dy,{present:o||s.open,children:s.disableHoverableContent?X.jsx(W3t,{side:r,...i,ref:e}):X.jsx(f2o,{side:r,...i,ref:e})})}),f2o=Y.forwardRef((t,e)=>{const n=qQ(bk,t.__scopeTooltip),o=Hve(bk,t.__scopeTooltip),r=Y.useRef(null),i=S0(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=P2o(f,x.getBoundingClientRect()),y=v2o(f,g),b=S2o(p.getBoundingClientRect()),v=M2o([...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=!C2o(f,s);g?d():y&&(d(),l())};return document.addEventListener("pointermove",h),()=>document.removeEventListener("pointermove",h)}},[c,u,s,l,d]),X.jsx(W3t,{...t,ref:i})}),[x2o,g2o]=GQ(SF,{isInside:!1}),y2o=a2o("TooltipContent"),W3t=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,children:o,"aria-label":r,onEscapeKeyDown:i,onPointerDownOutside:s,...a}=t,c=qQ(bk,n),l=YQ(n),{onClose:u}=c;return Y.useEffect(()=>(document.addEventListener(Ive,u),()=>document.removeEventListener(Ive,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]),X.jsx(oO,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:s,onFocusOutside:_=>_.preventDefault(),onDismiss:u,children:X.jsxs(Cbe,{"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:[X.jsx(y2o,{children:o}),X.jsx(x2o,{scope:n,isInside:!0,children:X.jsx(u2o,{id:c.contentId,role:"tooltip",children:r||o})})]})})});$3t.displayName=bk;var j3t="TooltipArrow",b2o=Y.forwardRef((t,e)=>{const{__scopeTooltip:n,...o}=t,r=YQ(n);return g2o(j3t,n).isInside?null:X.jsx(Mbe,{...r,...o,ref:e})});b2o.displayName=j3t;function P2o(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 v2o(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 S2o(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 C2o(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 M2o(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),T2o(e)}function T2o(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 w2o=B3t,E2o=z3t,D2o=V3t,U3t=$3t;const X3t=w2o,G3t=E2o,Y3t=D2o,Ove=Y.forwardRef(({className:t,sideOffset:e=4,...n},o)=>X.jsx(U3t,{ref:o,sideOffset:e,className:yr("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}));Ove.displayName=U3t.displayName;const A2o=26,Hg=fc("run-frame:RunFrame"),k2o=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)}},q3t=async(t,e)=>{if(t)return t;if(e||!window.TSCIRCUIT_LATEST_EVAL_VERSION){const n=await k2o();if(n)return window.TSCIRCUIT_LATEST_EVAL_VERSION=n,n}return window.TSCIRCUIT_LATEST_EVAL_VERSION?window.TSCIRCUIT_LATEST_EVAL_VERSION:"latest"},K3t=t=>{cQ();const e=v0(_e=>_e.circuitJson),n=v0(_e=>_e.setCircuitJson),[o,r]=Y.useState(null),i=Y.useRef(null),[s,a]=Y.useState(null),[c,l]=Y.useReducer((_e,Ce)=>_e+1,0),u=_Q(_e=>_e.setLastRunEvalVersion),_=Y.useRef(0),d=Z1o(),[m,h]=Y.useState(!1),[p,x]=Y.useState(!1),[f,g]=Y.useState({}),[y,b]=Y.useState(""),[v,S]=Y.useState(!1),[M,T]=Y.useState(!1),D=Object.values(f).sort((_e,Ce)=>_e.startTime-Ce.startTime)[0]?.effectName,A=_e=>{t.onRunCompleted?.(_e)};Y.useEffect(()=>{const _e=Ce=>{(Ce.ctrlKey||Ce.metaKey)&&Ce.key==="Enter"&&!m&&l(1)};return window.addEventListener("keydown",_e),()=>window.removeEventListener("keydown",_e)},[m]),Y.useEffect(()=>{let _e=!1;return(async()=>{try{if(!globalThis.runFrameWorker){const xe=await q3t(t.evalVersion,t.forceLatestEvalVersion),Fe=await H3t({evalVersion:xe,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${X2}/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},...t.easyEdaProxyConfig&&{easyEdaProxyConfig:t.easyEdaProxyConfig}});if(_e)return;globalThis.runFrameWorker=Fe,u(xe)}_e||x(!0)}catch(xe){console.error("Failed to preload eval worker",xe)}})(),()=>{_e=!0}},[t.evalVersion,t.evalWebWorkerBlobUrl,t.forceLatestEvalVersion,t.tscircuitSessionToken]);const[L,H]=Y.useState(null),[F,B]=Y.useState({}),[V,G]=Y.useState([]),[K,Q]=Y.useState(t.defaultActiveTab??t.defaultTab??"pcb");Y.useEffect(()=>{t.debug&&fc.enable("run-frame*")},[t.debug]);const oe=t.fsMap instanceof Map?t.fsMap:Object.entries(t.fsMap??{}).reduce((_e,[Ce,xe])=>_e.set(Ce,xe),new Map),ue=Y.useRef(null),ne=Y.useRef(null),{isStaticCircuitJson:re,circuitJson:ae,error:ie}=n2o({mainComponentPath:t.mainComponentPath,fsMap:oe});Y.useEffect(()=>{re&&(ae?(n(ae),r(null)):ie&&r({error:ie,stack:""}))},[re,ae,ie]),Y.useEffect(()=>{if(t.isLoadingFiles||re)return;const _e=oe instanceof Map?Object.fromEntries(oe.entries()):oe;if(!_e||Object.keys(_e).length===0){r({error:"No files provided. Please provide at least one file with code to execute.",stack:""}),h(!1);return}const Ce=c!==_.current;if(ue.current&&e){const Fe=Q1o(ue.current,oe);if(Object.keys(Fe).length>0)Hg("code changes detected");else if(ne.current!==t.entrypoint)Hg("render triggered by entrypoint change");else if(!Ce){Hg("render triggered without changes to fsMap, skipping");return}}if(t.showRunButton&&c===_.current)return;ue.current=oe,ne.current=t.entrypoint??null,_.current=c,h(!0);const xe=async()=>{Hg("running render worker"),r(null),H(null),g({}),G([]);const Fe={progress:0,debugOutputs:[]};let We=!1;i.current=()=>{We=!0};const Xe=await q3t(t.evalVersion,!globalThis.runFrameWorker&&t.forceLatestEvalVersion);Hg("resolvedEvalVersion",Xe);const ye=globalThis.runFrameWorker??await H3t({evalVersion:Xe,webWorkerBlobUrl:t.evalWebWorkerBlobUrl,verbose:!0,projectConfig:{projectBaseUrl:t.projectBaseUrl||`${X2}/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},...t.easyEdaProxyConfig&&{easyEdaProxyConfig:t.easyEdaProxyConfig}});globalThis.runFrameWorker=ye,u(Xe),y?.trim()&&ye.enableDebug(y.replace("DEBUG=","")),Hg("Starting render..."),t.onRenderStarted?.();const Je=oe instanceof Map?Object.fromEntries(oe.entries()):oe;let Be=Date.now();ye.on("asyncEffect:start",Te=>{const Ae=`${Te.phase}|${Te.componentDisplayName??""}|${Te.effectName}`;g(De=>({...De,[Ae]:{...Te,startTime:Date.now()}}))}),ye.on("asyncEffect:end",Te=>{const Ae=`${Te.phase}|${Te.componentDisplayName??""}|${Te.effectName}`;g(De=>{const{[Ae]:$e,...je}=De;return je})}),ye.on("autorouting:start",Te=>{B({...F,[Te.componentDisplayName]:{simpleRouteJson:Te.simpleRouteJson,createdAt:Date.now()}})}),ye.on("solver:started",Te=>{Hg("solver:started",Te),G(Ae=>{const De=`${Te.componentName}-${Te.solverName}`;return Ae.some(je=>`${je.componentName}-${je.solverName}`===De)?Ae:[...Ae,Te]})}),ye.on("board:renderPhaseStarted",Te=>{Fe.lastRenderEvent=Te,Fe.eventsProcessed=(Fe.eventsProcessed??0)+1;const Ae=Ey.indexOf(Te.phase)/A2o*.75+Fe.eventsProcessed/1e3*.25,De=1-Math.exp(-Ae*3);Fe.progress=De,We||H({...Fe})}),K==="render_log"&&ye.on("renderable:renderLifecycle:anyEvent",Te=>{Fe.renderEvents=Fe.renderEvents??[],Te.createdAt=Date.now(),Fe.renderEvents.push(Te),Date.now()-Be>500&&(Fe.phaseTimings=L3t(Fe.renderEvents??[]),Be=Date.now()),We||H({...Fe})}),ye.on("autorouting:progress",Te=>{a(Te.debugGraphics)}),ye.on("debug:logOutput",Te=>{Fe.debugOutputs=Fe.debugOutputs??[],Fe.debugOutputs.push({type:"debug",name:Te.name,content:Te.content}),We||H({...Fe})}),Hg("Executing fsMap...");const ke=await ye.executeWithFsMap({entrypoint:t.entrypoint,fsMap:Je,...t.mainComponentPath?{mainComponentPath:t.mainComponentPath}:{}}).then(()=>({success:!0})).catch(Te=>{const Ae=Te.message.replace("Error: ","");return Hg(`eval error: ${Ae}`),t.onError?.(Te),A(Nve({executionError:Te})),r({error:Ae,stack:Te.stack}),H(null),console.error(Te),{success:!1}});if(Hg("worker call started"),!ke.success){h(!1),g({});return}const Ve=ye.renderUntilSettled();Hg("waiting for initial circuit json...");let Ie=await ye.getCircuitJson().catch(Te=>(Hg("error getting initial circuit json",Te),t.onError?.(Te),A(Nve({executionError:Te})),r({error:Te.message,stack:Te.stack}),H(null),h(!1),g({}),null));Ie&&(Hg("got initial circuit json"),n(Ie),t.onCircuitJsonChange?.(Ie),t.onInitialRender?.({circuitJson:Ie}),await Ve,Hg("getting final circuit json"),Ie=await ye.getCircuitJson(),t.onCircuitJsonChange?.(Ie),n(Ie),A(Nve({circuitJson:Ie})),t.onRenderFinished?.({circuitJson:Ie}),a({}),K==="render_log"&&(Fe.phaseTimings=L3t(Fe.renderEvents??[])),Fe.progress=1,We||H({...Fe}),h(!1),g({}),b(""),i.current=null)};d.runWithMutex(xe)},[t.fsMap,t.entrypoint,c,t.evalVersion,t.mainComponentPath,t.isLoadingFiles,y,re]);const de=Y.useRef(null),be=Y.useRef(null),Me=_e=>{if(!_e||_e===null){console.warn("[RunFrame] handleEditEvent received null or undefined event.");return}_e.in_progress?(de.current=_e,be.current&&(clearTimeout(be.current),be.current=null)):(be.current&&clearTimeout(be.current),be.current=setTimeout(()=>{const Ce=_e||de.current;t.onEditEvent?.(Ce),de.current=null,be.current=null},100))},Ee=async(_e,Ce)=>{let xe="";const Fe=Array.isArray(e)&&e.find(ye=>ye.type==="software_project_metadata"),We=t.projectUrl??Fe?.project_url;if(We)try{xe=new URL(We).pathname}catch{xe=We}const Xe=xe?`${xe} - ${_e}`:_e;await pF.post("autorouting/bug_reports/create",{json:{title:Xe,simple_route_json:Ce.simpleRouteJson}}).json().then(({autorouting_bug_report:ye})=>{window.open(`https://api.tscircuit.com/autorouting/bug_reports/view?autorouting_bug_report_id=${ye.autorouting_bug_report_id}`,"_blank")}).catch(ye=>{if(console.error("Failed to report autorouting bug",ye),ye instanceof p8&&ye.response?.status===401){t.onLoginRequired?t.onLoginRequired():alert("You must be logged in to report autorouting bugs");return}const Be=ye instanceof Error?ye.message:"Failed to report autorouting bug";alert(`Failed to report autorouting bug: ${Be}`)})};return t.isLoadingFiles?X.jsx(e2o,{}):X.jsx(x3,{FallbackComponent:J1o,children:X.jsx(S3t,{code:oe.get(t.entrypoint??t.mainComponentPath),fsMap:oe,defaultActiveTab:t.defaultActiveTab??t.defaultTab,defaultTab:t.defaultTab,availableTabs:t.availableTabs,showToggleFullScreen:t.showToggleFullScreen,autoroutingGraphics:s,autoroutingLog:F,onReportAutoroutingLog:t.onReportAutoroutingLog||Ee,leftHeaderContent:X.jsxs(X.Fragment,{children:[t.showRunButton&&X.jsx(X3t,{children:X.jsxs(G3t,{children:[X.jsx(Y3t,{asChild:!0,children:X.jsxs("div",{className:"rf-relative rf-inline-flex",children:[X.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?X.jsx(Qv,{className:"rf-w-3 rf-h-3 rf-animate-spin"}):X.jsx(Zht,{className:"rf-w-3 rf-h-3"})]}),m&&X.jsx("div",{className:"rf-flex rf-items-center rf-ml-1",children:X.jsx(kc,{onClick:_e=>{_e.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:X.jsx(sYn,{className:"!rf-h-2.5 !rf-w-2.5",fill:"currentColor",stroke:"currentColor"})})})]})}),X.jsx(Ove,{sideOffset:8,className:"rf-p-0 rf-bg-transparent rf-border-none rf-shadow-none rf-pointer-events-none",children:X.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:[X.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"}),X.jsx("span",{className:"rf-text-slate-500 rf-text-[11px] rf-font-medium rf-leading-none",children:"+"}),X.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&&X.jsx(vF,{isWebEmbedded:t.isWebEmbedded,onLoginRequired:t.onLoginRequired,showSchematicDebugGrid:v,onChangeShowSchematicDebugGrid:S,showSchematicPorts:M,onChangeShowSchematicPorts:T,autoroutingLog:F,onReportAutoroutingLog:t.onReportAutoroutingLog||Ee}),t.leftHeaderContent]}),onActiveTabChange:Q,circuitJson:e,renderLog:L,activeEffectName:D,isRunningCode:m,errorMessage:o?.error,errorStack:o?.stack,onEditEvent:Me,editEvents:t.editEvents,onPcbBoundsSelected:t.onPcbBoundsSelected,defaultToFullScreen:t.defaultToFullScreen,onRerunWithDebug:_e=>{b(_e||""),l(1)},solverEvents:V,showSchematicDebugGrid:v,showSchematicPorts:M,onChangeShowSchematicDebugGrid:S,onChangeShowSchematicPorts:T})})},R2o=t=>new Promise(e=>setTimeout(e,t)),N2o=({isOpen:t,onClose:e,onLoginSuccess:n})=>{const[o,r]=Y.useState("idle"),[i,s]=Y.useState(null),[a,c]=Y.useState(null),l=v0(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=f8(),{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 R2o(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"),Ss.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"),Ss.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 X.jsx(pk,{open:t,onOpenChange:p=>!p&&!m&&d(),children:X.jsxs(WM,{className:"rf-max-w-md",children:[X.jsxs(jM,{children:[X.jsx(UM,{children:"Sign In Required"}),X.jsx(fk,{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."})]}),X.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-4 rf-py-4",children:[o==="idle"||o==="error"?X.jsx(kc,{onClick:_,className:"rf-w-full",children:"Sign In"}):X.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-3 rf-w-full",children:[o!=="success"&&X.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"}),X.jsx("p",{className:"rf-text-sm rf-text-gray-600 rf-text-center",children:h()}),i&&o==="waiting"&&X.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"&&X.jsx("p",{className:"rf-text-sm rf-text-red-600 rf-text-center",children:a}),m&&X.jsx(kc,{variant:"outline",onClick:d,className:"rf-w-full",children:"Cancel"})]})]})})},I2o=()=>{const[t,e]=Y.useState(!1),n=Y.useCallback(()=>{e(!0)},[]),o=Y.useCallback(()=>{e(!1)},[]),r=Y.useCallback(()=>{e(!1)},[]);return{LoginDialog:X.jsx(N2o,{isOpen:t,onClose:o,onLoginSuccess:r}),openLoginDialog:n}},H2o=t=>{const[e,n]=qE("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}=I2o();return X.jsxs(X.Fragment,{children:[i,X.jsx(Xbt,{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:X.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between",children:[X.jsx(vF,{isWebEmbedded:!1,shouldLoadLatestEval:!t.workerBlobUrl&&e,onChangeShouldLoadLatestEval:a=>{n(a),globalThis.runFrameWorker=null},onLoginRequired:s}),t.scenarioSelectorContent]})})]})};fc("run-frame:ImportComponentDialog");var J3t=1,L2o=.9,O2o=.8,F2o=.17,Fve=.1,Bve=.999,B2o=.9999,z2o=.99,V2o=/[\\\/_+.#"@\[\(\{&]/,$2o=/[\\\/_+.#"@\[\(\{&]/g,W2o=/[\s-]/,Q3t=/[\s-]/g;function zve(t,e,n,o,r,i,s){if(i===e.length)return r===t.length?J3t:z2o;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;)_=zve(t,e,n,o,l+1,i+1,s),_>u&&(l===r?_*=J3t:V2o.test(t.charAt(l-1))?(_*=O2o,m=t.slice(r,l-1).match($2o),m&&r>0&&(_*=Math.pow(Bve,m.length))):W2o.test(t.charAt(l-1))?(_*=L2o,h=t.slice(r,l-1).match(Q3t),h&&r>0&&(_*=Math.pow(Bve,h.length))):(_*=F2o,r>0&&(_*=Math.pow(Bve,l-r))),t.charAt(l)!==e.charAt(i)&&(_*=B2o)),(_<Fve&&n.charAt(l-1)===o.charAt(i+1)||o.charAt(i+1)===o.charAt(i)&&n.charAt(l-1)!==o.charAt(i))&&(d=zve(t,e,n,o,l+1,i+2,s),d*Fve>_&&(_=d*Fve)),_>u&&(u=_),l=n.indexOf(c,l+1);return s[a]=u,u}function Z3t(t){return t.toLowerCase().replace(Q3t," ")}function j2o(t,e,n){return t=n&&n.length>0?`${t+" "+n.join(" ")}`:t,zve(t,e,Z3t(t),Z3t(e),0,0,{})}var U2o=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],g8=U2o.reduce((t,e)=>{const n=Ght(`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),X.jsx(c,{...a,ref:i})});return o.displayName=`Primitive.${e}`,{...t,[e]:o}},{}),CF='[cmdk-group=""]',Vve='[cmdk-group-items=""]',X2o='[cmdk-group-heading=""]',ebt='[cmdk-item=""]',tbt=`${ebt}:not([aria-disabled="true"])`,$ve="cmdk-item-select",Pk="data-value",G2o=(t,e,n)=>j2o(t,e,n),nbt=Y.createContext(void 0),MF=()=>Y.useContext(nbt),obt=Y.createContext(void 0),Wve=()=>Y.useContext(obt),rbt=Y.createContext(void 0),ibt=Y.forwardRef((t,e)=>{let n=vk(()=>{var re,ae;return{search:"",value:(ae=(re=t.value)!=null?re:t.defaultValue)!=null?ae:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),o=vk(()=>new Set),r=vk(()=>new Map),i=vk(()=>new Map),s=vk(()=>new Set),a=sbt(t),{label:c,children:l,value:u,onValueChange:_,filter:d,shouldFilter:m,loop:h,disablePointerSelection:p=!1,vimBindings:x=!0,...f}=t,g=Df(),y=Df(),b=Df(),v=Y.useRef(null),S=rxo();ZM(()=>{if(u!==void 0){let re=u.trim();n.current.value=re,M.emit()}},[u]),ZM(()=>{S(6,F)},[]);let M=Y.useMemo(()=>({subscribe:re=>(s.current.add(re),()=>s.current.delete(re)),snapshot:()=>n.current,setState:(re,ae,ie)=>{var de,be,Me,Ee;if(!Object.is(n.current[re],ae)){if(n.current[re]=ae,re==="search")H(),A(),S(1,L);else if(re==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let _e=document.getElementById(b);_e?_e.focus():(de=document.getElementById(g))==null||de.focus()}if(S(7,()=>{var _e;n.current.selectedItemId=(_e=B())==null?void 0:_e.id,M.emit()}),ie||S(5,F),((be=a.current)==null?void 0:be.value)!==void 0){let _e=ae??"";(Ee=(Me=a.current).onValueChange)==null||Ee.call(Me,_e);return}}M.emit()}},emit:()=>{s.current.forEach(re=>re())}}),[]),T=Y.useMemo(()=>({value:(re,ae,ie)=>{var de;ae!==((de=i.current.get(re))==null?void 0:de.value)&&(i.current.set(re,{value:ae,keywords:ie}),n.current.filtered.items.set(re,D(ae,ie)),S(2,()=>{A(),M.emit()}))},item:(re,ae)=>(o.current.add(re),ae&&(r.current.has(ae)?r.current.get(ae).add(re):r.current.set(ae,new Set([re]))),S(3,()=>{H(),A(),n.current.value||L(),M.emit()}),()=>{i.current.delete(re),o.current.delete(re),n.current.filtered.items.delete(re);let ie=B();S(4,()=>{H(),ie?.getAttribute("id")===re&&L(),M.emit()})}),group:re=>(r.current.has(re)||r.current.set(re,new Set),()=>{i.current.delete(re),r.current.delete(re)}),filter:()=>a.current.shouldFilter,label:c||t["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:g,inputId:b,labelId:y,listInnerRef:v}),[]);function D(re,ae){var ie,de;let be=(de=(ie=a.current)==null?void 0:ie.filter)!=null?de:G2o;return re?be(re,n.current.search,ae):0}function A(){if(!n.current.search||a.current.shouldFilter===!1)return;let re=n.current.filtered.items,ae=[];n.current.filtered.groups.forEach(de=>{let be=r.current.get(de),Me=0;be.forEach(Ee=>{let _e=re.get(Ee);Me=Math.max(_e,Me)}),ae.push([de,Me])});let ie=v.current;V().sort((de,be)=>{var Me,Ee;let _e=de.getAttribute("id"),Ce=be.getAttribute("id");return((Me=re.get(Ce))!=null?Me:0)-((Ee=re.get(_e))!=null?Ee:0)}).forEach(de=>{let be=de.closest(Vve);be?be.appendChild(de.parentElement===be?de:de.closest(`${Vve} > *`)):ie.appendChild(de.parentElement===ie?de:de.closest(`${Vve} > *`))}),ae.sort((de,be)=>be[1]-de[1]).forEach(de=>{var be;let Me=(be=v.current)==null?void 0:be.querySelector(`${CF}[${Pk}="${encodeURIComponent(de[0])}"]`);Me?.parentElement.appendChild(Me)})}function L(){let re=V().find(ie=>ie.getAttribute("aria-disabled")!=="true"),ae=re?.getAttribute(Pk);M.setState("value",ae||void 0)}function H(){var re,ae,ie,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 Me of o.current){let Ee=(ae=(re=i.current.get(Me))==null?void 0:re.value)!=null?ae:"",_e=(de=(ie=i.current.get(Me))==null?void 0:ie.keywords)!=null?de:[],Ce=D(Ee,_e);n.current.filtered.items.set(Me,Ce),Ce>0&&be++}for(let[Me,Ee]of r.current)for(let _e of Ee)if(n.current.filtered.items.get(_e)>0){n.current.filtered.groups.add(Me);break}n.current.filtered.count=be}function F(){var re,ae,ie;let de=B();de&&(((re=de.parentElement)==null?void 0:re.firstChild)===de&&((ie=(ae=de.closest(CF))==null?void 0:ae.querySelector(X2o))==null||ie.scrollIntoView({block:"nearest"})),de.scrollIntoView({block:"nearest"}))}function B(){var re;return(re=v.current)==null?void 0:re.querySelector(`${ebt}[aria-selected="true"]`)}function V(){var re;return Array.from(((re=v.current)==null?void 0:re.querySelectorAll(tbt))||[])}function G(re){let ae=V()[re];ae&&M.setState("value",ae.getAttribute(Pk))}function K(re){var ae;let ie=B(),de=V(),be=de.findIndex(Ee=>Ee===ie),Me=de[be+re];(ae=a.current)!=null&&ae.loop&&(Me=be+re<0?de[de.length-1]:be+re===de.length?de[0]:de[be+re]),Me&&M.setState("value",Me.getAttribute(Pk))}function Q(re){let ae=B(),ie=ae?.closest(CF),de;for(;ie&&!de;)ie=re>0?nxo(ie,CF):oxo(ie,CF),de=ie?.querySelector(tbt);de?M.setState("value",de.getAttribute(Pk)):K(re)}let oe=()=>G(V().length-1),ue=re=>{re.preventDefault(),re.metaKey?oe():re.altKey?Q(1):K(1)},ne=re=>{re.preventDefault(),re.metaKey?G(0):re.altKey?Q(-1):K(-1)};return Y.createElement(g8.div,{ref:e,tabIndex:-1,...f,"cmdk-root":"",onKeyDown:re=>{var ae;(ae=f.onKeyDown)==null||ae.call(f,re);let ie=re.nativeEvent.isComposing||re.keyCode===229;if(!(re.defaultPrevented||ie))switch(re.key){case"n":case"j":{x&&re.ctrlKey&&ue(re);break}case"ArrowDown":{ue(re);break}case"p":case"k":{x&&re.ctrlKey&&ne(re);break}case"ArrowUp":{ne(re);break}case"Home":{re.preventDefault(),G(0);break}case"End":{re.preventDefault(),oe();break}case"Enter":{re.preventDefault();let de=B();if(de){let be=new Event($ve);de.dispatchEvent(be)}}}}},Y.createElement("label",{"cmdk-label":"",htmlFor:T.inputId,id:T.labelId,style:sxo},c),KQ(t,re=>Y.createElement(obt.Provider,{value:M},Y.createElement(nbt.Provider,{value:T},re))))}),Y2o=Y.forwardRef((t,e)=>{var n,o;let r=Df(),i=Y.useRef(null),s=Y.useContext(rbt),a=MF(),c=sbt(t),l=(o=(n=c.current)==null?void 0:n.forceMount)!=null?o:s?.forceMount;ZM(()=>{if(!l)return a.item(r,s?.id)},[l]);let u=abt(r,i,[t.value,t.children,i],t.keywords),_=Wve(),d=y8(S=>S.value&&S.value===u.current),m=y8(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($ve,h),()=>S.removeEventListener($ve,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(g8.div,{ref:vg(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)}),q2o=Y.forwardRef((t,e)=>{let{heading:n,children:o,forceMount:r,...i}=t,s=Df(),a=Y.useRef(null),c=Y.useRef(null),l=Df(),u=MF(),_=y8(m=>r||u.filter()===!1?!0:m.search?m.filtered.groups.has(s):!0);ZM(()=>u.group(s),[]),abt(s,a,[t.value,t.heading,c]);let d=Y.useMemo(()=>({id:s,forceMount:r}),[r]);return Y.createElement(g8.div,{ref:vg(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),KQ(t,m=>Y.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?l:void 0},Y.createElement(rbt.Provider,{value:d},m))))}),K2o=Y.forwardRef((t,e)=>{let{alwaysRender:n,...o}=t,r=Y.useRef(null),i=y8(s=>!s.search);return!n&&!i?null:Y.createElement(g8.div,{ref:vg(r,e),...o,"cmdk-separator":"",role:"separator"})}),J2o=Y.forwardRef((t,e)=>{let{onValueChange:n,...o}=t,r=t.value!=null,i=Wve(),s=y8(l=>l.search),a=y8(l=>l.selectedItemId),c=MF();return Y.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),Y.createElement(g8.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)}})}),Q2o=Y.forwardRef((t,e)=>{let{children:n,label:o="Suggestions",...r}=t,i=Y.useRef(null),s=Y.useRef(null),a=y8(l=>l.selectedItemId),c=MF();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(g8.div,{ref:vg(i,e),...r,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":o,id:c.listId},KQ(t,l=>Y.createElement("div",{ref:vg(s,c.listInnerRef),"cmdk-list-sizer":""},l)))}),Z2o=Y.forwardRef((t,e)=>{let{open:n,onOpenChange:o,overlayClassName:r,contentClassName:i,container:s,...a}=t;return Y.createElement(LPe,{open:n,onOpenChange:o},Y.createElement(OPe,{container:s},Y.createElement(mQ,{"cmdk-overlay":"",className:r}),Y.createElement(pQ,{"aria-label":t.label,"cmdk-dialog":"",className:i},Y.createElement(ibt,{ref:e,...a}))))}),exo=Y.forwardRef((t,e)=>y8(n=>n.filtered.count===0)?Y.createElement(g8.div,{ref:e,...t,"cmdk-empty":"",role:"presentation"}):null),txo=Y.forwardRef((t,e)=>{let{progress:n,children:o,label:r="Loading...",...i}=t;return Y.createElement(g8.div,{ref:e,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r},KQ(t,s=>Y.createElement("div",{"aria-hidden":!0},s)))}),Lg=Object.assign(ibt,{List:Q2o,Item:Y2o,Input:J2o,Group:q2o,Separator:K2o,Dialog:Z2o,Empty:exo,Loading:txo});function nxo(t,e){let n=t.nextElementSibling;for(;n;){if(n.matches(e))return n;n=n.nextElementSibling}}function oxo(t,e){let n=t.previousElementSibling;for(;n;){if(n.matches(e))return n;n=n.previousElementSibling}}function sbt(t){let e=Y.useRef(t);return ZM(()=>{e.current=t}),e}var ZM=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;function vk(t){let e=Y.useRef();return e.current===void 0&&(e.current=t()),e}function y8(t){let e=Wve(),n=()=>t(e.snapshot());return Y.useSyncExternalStore(e.subscribe,n,n)}function abt(t,e,n,o=[]){let r=Y.useRef(),i=MF();return ZM(()=>{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(Pk,a),r.current=a}),r}var rxo=()=>{let[t,e]=Y.useState(),n=vk(()=>new Map);return ZM(()=>{n.current.forEach(o=>o()),n.current=new Map},[t]),(o,r)=>{n.current.set(o,r),e({})}};function ixo(t){let e=t.type;return typeof e=="function"?e(t.props):"render"in e?e.render(t.props):t}function KQ({asChild:t,children:e},n){return t&&Y.isValidElement(e)?Y.cloneElement(ixo(e),{ref:e.ref},n(e.props.children)):n(e)}var sxo={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const cbt=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg,{ref:n,className:yr("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}));cbt.displayName=Lg.displayName;const lbt=Y.forwardRef(({className:t,...e},n)=>X.jsxs("div",{className:"rf-flex rf-items-center rf-border-b rf-px-3","cmdk-input-wrapper":"",children:[X.jsx(ibe,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-shrink-0 rf-opacity-50"}),X.jsx(Lg.Input,{ref:n,className:yr("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})]}));lbt.displayName=Lg.Input.displayName;const ubt=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.List,{ref:n,className:yr("rf-max-h-[300px] rf-overflow-y-auto rf-overflow-x-hidden rf-py-1",t),...e}));ubt.displayName=Lg.List.displayName;const jve=Y.forwardRef((t,e)=>X.jsx(Lg.Empty,{ref:e,className:"rf-py-6 rf-text-center rf-text-sm",...t}));jve.displayName=Lg.Empty.displayName;const TF=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.Group,{ref:n,className:yr("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}));TF.displayName=Lg.Group.displayName;const axo=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.Separator,{ref:n,className:yr("rf--mx-1 rf-h-px rf-bg-zinc-200 dark:rf-bg-zinc-800",t),...e}));axo.displayName=Lg.Separator.displayName;const wF=Y.forwardRef(({className:t,...e},n)=>X.jsx(Lg.Item,{ref:n,className:yr("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}));wF.displayName=Lg.Item.displayName;function cxo(t){const e=lxo(t),n=Y.forwardRef((o,r)=>{const{children:i,...s}=o,a=Y.Children.toArray(i),c=a.find(_xo);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 X.jsx(e,{...s,ref:r,children:Y.isValidElement(l)?Y.cloneElement(l,void 0,u):null})}return X.jsx(e,{...s,ref:r,children:i})});return n.displayName=`${t}.Slot`,n}function lxo(t){const e=Y.forwardRef((n,o)=>{const{children:r,...i}=n;if(Y.isValidElement(r)){const s=hxo(r),a=dxo(i,r.props);return r.type!==Y.Fragment&&(a.ref=o?vg(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 uxo=Symbol("radix.slottable");function _xo(t){return Y.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===uxo}function dxo(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 hxo(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 JQ="Popover",[_bt]=_b(JQ,[zA]),EF=zA(),[mxo,b8]=_bt(JQ),dbt=t=>{const{__scopePopover:e,children:n,open:o,defaultOpen:r,onOpenChange:i,modal:s=!1}=t,a=EF(e),c=Y.useRef(null),[l,u]=Y.useState(!1),[_,d]=ZS({prop:o,defaultProp:r??!1,onChange:i,caller:JQ});return X.jsx(kK,{...a,children:X.jsx(mxo,{scope:e,contentId:Df(),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})})};dbt.displayName=JQ;var hbt="PopoverAnchor",pxo=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=b8(hbt,n),i=EF(n),{onCustomAnchorAdd:s,onCustomAnchorRemove:a}=r;return Y.useEffect(()=>(s(),()=>a()),[s,a]),X.jsx(RK,{...i,...o,ref:e})});pxo.displayName=hbt;var mbt="PopoverTrigger",pbt=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=b8(mbt,n),i=EF(n),s=S0(e,r.triggerRef),a=X.jsx(Uc.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.contentId,"data-state":bbt(r.open),...o,ref:s,onClick:Qr(t.onClick,r.onOpenToggle)});return r.hasCustomAnchor?a:X.jsx(RK,{asChild:!0,...i,children:a})});pbt.displayName=mbt;var Uve="PopoverPortal",[fxo,xxo]=_bt(Uve,{forceMount:void 0}),fbt=t=>{const{__scopePopover:e,forceMount:n,children:o,container:r}=t,i=b8(Uve,e);return X.jsx(fxo,{scope:e,forceMount:n,children:X.jsx(Dy,{present:n||i.open,children:X.jsx(NK,{asChild:!0,container:r,children:o})})})};fbt.displayName=Uve;var Sk="PopoverContent",xbt=Y.forwardRef((t,e)=>{const n=xxo(Sk,t.__scopePopover),{forceMount:o=n.forceMount,...r}=t,i=b8(Sk,t.__scopePopover);return X.jsx(Dy,{present:o||i.open,children:i.modal?X.jsx(yxo,{...r,ref:e}):X.jsx(bxo,{...r,ref:e})})});xbt.displayName=Sk;var gxo=cxo("PopoverContent.RemoveScroll"),yxo=Y.forwardRef((t,e)=>{const n=b8(Sk,t.__scopePopover),o=Y.useRef(null),r=S0(e,o),i=Y.useRef(!1);return Y.useEffect(()=>{const s=o.current;if(s)return wbe(s)},[]),X.jsx(VK,{as:gxo,allowPinchZoom:!0,children:X.jsx(gbt,{...t,ref:r,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Qr(t.onCloseAutoFocus,s=>{s.preventDefault(),i.current||n.triggerRef.current?.focus()}),onPointerDownOutside:Qr(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:Qr(t.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1})})})}),bxo=Y.forwardRef((t,e)=>{const n=b8(Sk,t.__scopePopover),o=Y.useRef(!1),r=Y.useRef(!1);return X.jsx(gbt,{...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()}})}),gbt=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=b8(Sk,n),m=EF(n);return cbe(),X.jsx(bK,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:r,onUnmountAutoFocus:i,children:X.jsx(oO,{asChild:!0,disableOutsidePointerEvents:s,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>d.onOpenChange(!1),children:X.jsx(Cbe,{"data-state":bbt(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)"}})})})}),ybt="PopoverClose",Pxo=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=b8(ybt,n);return X.jsx(Uc.button,{type:"button",...o,ref:e,onClick:Qr(t.onClick,()=>r.onOpenChange(!1))})});Pxo.displayName=ybt;var vxo="PopoverArrow",Sxo=Y.forwardRef((t,e)=>{const{__scopePopover:n,...o}=t,r=EF(n);return X.jsx(Mbe,{...r,...o,ref:e})});Sxo.displayName=vxo;function bbt(t){return t?"open":"closed"}var Cxo=dbt,Mxo=pbt,Txo=fbt,Pbt=xbt;const wxo=Cxo,Exo=Mxo,vbt=Y.forwardRef(({className:t,align:e="center",sideOffset:n=4,...o},r)=>X.jsx(Txo,{children:X.jsx(Pbt,{ref:r,align:e,sideOffset:n,className:yr("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})}));vbt.displayName=Pbt.displayName;function Sbt(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 Dxo(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 Cbt(t,e){for(const n of t){if(n.path===e)return n;if(n.children){const o=Cbt(n.children,e);if(o)return o}}return null}function Axo(t,e){let n;if(e?n=Cbt(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)=>Sbt(i.name,s.name)),r.sort((i,s)=>Sbt(i.name,s.name)),{files:o,folders:r}}const kxo=t=>{const e=t.split("/").pop()||"";return e.endsWith(".py.tsx")?e.slice(0,-4):e};function Xve(t){const e=t.lastIndexOf("/");return e===-1?"/":t.substring(0,e)}function Rxo({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 _=Xve(u);return _==="/"?null:_}}if(t&&e.includes(t)){const c=Xve(t);return c==="/"?null:c}return null});return Y.useEffect(()=>{if(t&&!n&&e.includes(t)){const c=Xve(t);i(c==="/"?null:c)}},[t,n,e]),{currentFolder:r,navigateToFolder:c=>{i(c),o(!0)},resetManualNavigation:()=>{o(!1)}}}const Gve=t=>t.endsWith(".tsx")||t.endsWith(".jsx")?X.jsx(UGn,{className:"rf-h-4 rf-w-4 rf-text-blue-500"}):t.endsWith(".md")||t.endsWith(".txt")?X.jsx(qGn,{className:"rf-h-4 rf-w-4 rf-text-gray-600"}):X.jsx(KGn,{className:"rf-h-4 rf-w-4 rf-text-gray-500"}),Nxo=t=>t.endsWith(".tsx")||XQ(t)||t.endsWith(".jsx"),Ixo=t=>kxo(t),Mbt=t=>t.substring(0,t.lastIndexOf("/"))||"/",Tbt=({files:t,onFileChange:e,currentFile:n,fileFilter:o=Nxo,getDisplayName:r=Ixo,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}=Rxo({currentFile:m,files:t}),[g,y]=Y.useState(0),[b,v]=Y.useState(""),[S,M]=qE("runframe:recentlyViewed",[]),[T,D]=qE("runframe:showRecents",!1);Y.useEffect(()=>{const ie=de=>{(de.metaKey||de.ctrlKey)&&de.key==="k"&&(de.preventDefault(),d(be=>!be))};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[]);const A=t.filter(o),L=Y.useRef(null);Y.useEffect(()=>{const ie=()=>{L.current&&(clearTimeout(L.current),L.current=null)};return h(n),n&&A.includes(n)&&(ie(),L.current=setTimeout(()=>{M(de=>{if(de[0]===n)return de;const be=de.filter(Me=>Me!==n);return[n,...be].slice(0,10)})},500)),ie},[n,A,M]);const H=Dxo(A),{files:F,folders:B}=Axo(H,p||""),G=(()=>{if(!b.trim())return{currentDirResults:[],globalResults:[]};const ie=b.toLowerCase(),be=A.map(_e=>{const Ce=_e.split("/").pop()||"";return{path:_e,fileName:Ce}}).filter(_e=>_e.fileName.toLowerCase().includes(ie)||_e.path.toLowerCase().includes(ie)),Me=be.filter(_e=>p?_e.path.substring(0,_e.path.lastIndexOf("/"))===p:!_e.path.includes("/")),Ee=be.filter(_e=>p?_e.path.substring(0,_e.path.lastIndexOf("/"))!==p:_e.path.includes("/"));return{currentDirResults:Me,globalResults:Ee}})(),K=b.trim().length>0,Q=ie=>{x(ie),y(0)},oe=Y.useCallback(()=>{if(!p)return;const ie=p.lastIndexOf("/"),de=ie===-1?null:p.substring(0,ie);Q(de)},[p,Q]);Y.useEffect(()=>{if(!_)return;const ie=de=>{(de.metaKey||de.ctrlKey)&&de.key==="ArrowUp"&&(de.preventDefault(),oe())};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[_,oe]);const ue=Y.useCallback((ie,de,be=!1)=>{if(h(ie),y(de),d(!1),e(ie),be){const Me=ie.lastIndexOf("/"),Ee=Me===-1?null:ie.substring(0,Me);Q(Ee)}},[e,Q]);Y.useEffect(()=>{const ie=de=>{if((de.metaKey||de.ctrlKey)&&(de.key==="ArrowLeft"||de.key==="ArrowRight")){if(de.preventDefault(),!n||F.length===0)return;const be=F.findIndex(_e=>_e.path===n);if(be===-1)return;let Me;de.key==="ArrowLeft"?Me=be===0?F.length-1:be-1:Me=be===F.length-1?0:be+1;const Ee=F[Me];Ee&&ue(Ee.path,Me)}};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[n,F,ue]),Y.useEffect(()=>{if(F.length>0){const ie=F.findIndex(de=>de.path===n);ie>=0&&y(ie)}},[F,n]);const ne=Y.useMemo(()=>{const ie=u.filter(Me=>A.includes(Me)),de=S.filter(Me=>A.includes(Me)),be=[];ie.length>0&&be.push({path:ie[0],type:"saved"});for(const Me of de){if(be.length>=3)break;be.some(Ee=>Ee.path===Me)||be.push({path:Me,type:"viewed"})}return be},[u,S,A]),re=p??"/";re.length>25&&""+re.slice(-22);const ae=()=>`rf-w-full rf-min-w-[600px] ${K?"rf-max-w-[600px]":"rf-max-w-[1000px]"}`;return X.jsx("div",{className:"rf-flex rf-items-center rf-gap-1",children:X.jsxs(wxo,{open:_,onOpenChange:ie=>{d(ie),ie||(v(""),f())},children:[X.jsx(Exo,{asChild:!0,children:X.jsxs(kc,{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:[X.jsx("span",{className:"rf-truncate rf-text-left",children:m?r(m):i}),X.jsx(BGn,{className:"rf-opacity-50 rf-flex-shrink-0"})]})}),X.jsx(vbt,{className:yr("!rf-p-0 !rf-overflow-y-auto !rf-max-h-[80vh] !rf-z-[200]",ae()),children:X.jsxs(cbt,{shouldFilter:!1,children:[X.jsx(lbt,{placeholder:s,className:"rf-h-9 rf-w-full",value:b,onValueChange:v}),ne.length>0&&X.jsxs("div",{className:"rf-border-b rf-border-gray-200",children:[X.jsxs("button",{onClick:()=>D(!T),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:[X.jsx("span",{className:"rf-font-medium",children:"Recent Files"}),X.jsx(rbe,{className:yr("rf-h-4 rf-w-4 rf-transition-transform",!T&&"-rf-rotate-90")})]}),T&&X.jsx("div",{className:"rf-pb-1",children:ne.map((ie,de)=>X.jsxs("div",{onClick:()=>ue(ie.path,de,!0),className:yr("rf-flex rf-items-center rf-px-3 rf-py-1.5 rf-cursor-pointer hover:rf-bg-slate-100",ie.path===n&&"rf-font-medium"),children:[ie.type==="saved"?X.jsx("span",{title:"Recently saved",children:X.jsx(iYn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-green-500"})}):X.jsx("span",{title:"Recently viewed",children:X.jsx(jGn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-500"})}),X.jsx("span",{className:"rf-text-sm",children:r(ie.path.split("/").pop()||"")}),X.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Mbt(ie.path)}),X.jsx(gM,{className:yr("rf-ml-auto rf-h-4 rf-w-4",ie.path===n?"rf-opacity-100":"rf-opacity-0")})]},ie.path))})]}),X.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:[X.jsx("div",{className:"rf-flex rf-items-center rf-text-xs rf-text-slate-600 rf-min-w-0 rf-flex-1",children:X.jsxs("div",{className:"rf-flex rf-items-center rf-min-w-0",children:[X.jsx("button",{onClick:()=>Q(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((ie,de,be)=>{const Me=be.slice(0,de+1).join("/");return X.jsxs("span",{className:"rf-flex rf-items-center rf-min-w-0",children:[X.jsx("span",{className:"rf-mx-1 rf-flex-shrink-0",children:"/"}),de===be.length-1?X.jsx("span",{className:"rf-text-slate-800 rf-truncate rf-max-w-[200px]",title:ie,children:ie}):X.jsx("button",{onClick:()=>Q(Me),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:ie,children:ie})]},Me)})]})}),X.jsx("div",{className:"rf-flex rf-items-center rf-gap-2 rf-flex-shrink-0",children:p&&X.jsxs("button",{onClick:oe,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:[X.jsx(OGn,{className:"rf-h-3 rf-w-3"}),X.jsx("span",{className:"rf-text-xs rf-font-medium",children:"Up"})]})})]}),X.jsx(ubt,{className:"rf-overflow-visible rf-max-h-none",children:K?X.jsx(X.Fragment,{children:G.currentDirResults.length===0&&G.globalResults.length===0?X.jsxs(jve,{children:['No files found matching "',b,'".']}):X.jsxs(X.Fragment,{children:[G.currentDirResults.length>0&&X.jsx(TF,{children:G.currentDirResults.map((ie,de)=>X.jsxs(wF,{value:`search-current:${ie.path}`,onSelect:()=>{h(ie.path),d(!1),e(ie.path)},className:yr(ie.path===n&&"rf-font-medium","rf-group"),children:[X.jsx("span",{className:"rf-mr-2",children:Gve(ie.fileName)}),X.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[X.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ie.fileName)}),X.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:p||"/"}),ie.path===n&&X.jsx(gM,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ie.path))}),G.globalResults.length>0&&X.jsx(TF,{children:G.globalResults.map(ie=>X.jsxs(wF,{value:`search-global:${ie.path}`,onSelect:()=>{h(ie.path),d(!1),e(ie.path)},className:yr(ie.path===n&&"rf-font-medium","rf-group"),children:[X.jsx("span",{className:"rf-mr-2",children:Gve(ie.fileName)}),X.jsxs("div",{className:"rf-flex rf-items-center rf-w-full rf-min-w-0",children:[X.jsx("span",{className:"rf-truncate rf-flex-1",children:r(ie.fileName)}),X.jsx("span",{className:"rf-text-xs rf-text-muted-foreground rf-ml-2 rf-truncate rf-max-w-[40%]",children:Mbt(ie.path)}),ie.path===n&&X.jsx(gM,{className:"rf-ml-2 rf-h-4 rf-w-4 rf-flex-shrink-0"})]})]},ie.path))})]})}):X.jsxs(X.Fragment,{children:[X.jsx(jve,{children:a}),F.length>0&&X.jsx(TF,{children:F.map((ie,de)=>X.jsxs(wF,{value:`current:${ie.path}`,onSelect:()=>ue(ie.path,de),className:yr(ie.path===n&&"rf-font-medium","rf-group"),children:[X.jsx("span",{className:"rf-mr-2",children:Gve(ie.name)}),r(ie.name),X.jsx("div",{className:"rf-ml-auto rf-flex rf-items-center rf-gap-1",children:X.jsx(gM,{className:yr("rf-h-4 rf-w-4",ie.path===n?"rf-opacity-100":"rf-opacity-0")})})]},ie.path))}),B.length>0&&X.jsx(TF,{children:B.map(ie=>X.jsxs(wF,{value:`folder-${ie.path}`,onSelect:()=>Q(ie.path),className:"rf-text-slate-600 hover:rf-text-slate-900",children:[X.jsx(JGn,{className:"rf-mr-2 rf-h-4 rf-w-4 rf-text-blue-600"}),ie.name,X.jsx(HA,{className:"rf-ml-auto rf-h-4 rf-w-4"})]},ie.path))}),F.length===0&&B.length===0&&X.jsx("div",{className:"rf-p-4 rf-text-center rf-text-slate-500 rf-text-sm",children:"No files or folders in this directory"})]})})]})})]})})},wbt=({files:t,onFileChange:e,currentFile:n})=>X.jsx(Tbt,{files:t,onFileChange:e,currentFile:n,fileFilter:()=>!0,placeholder:"Select circuit",searchPlaceholder:"Search for circuit file",emptyMessage:"No circuit files found in this directory."}),Hxo=t=>{cQ();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(T=>T.filePath===b);if(!v)throw new Error(`File reference not found for ${b}`);const M=await(t.onFetchFile||p)(v);c(T=>({...T,[b]:M})),r(M),t.onCircuitJsonPathChange?.(b),d(T=>{const D=new Set(T);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=Ubt(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 X.jsx("div",{className:"rf-flex rf-flex-col rf-w-full rf-h-full rf-items-center rf-justify-center",children:X.jsxs("div",{className:"rf-text-center rf-p-8",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-2",children:"No Circuit JSON Files Found"}),X.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Please provide circuit JSON files to view."})]})});const y=_.has(e);return X.jsx(x3,{fallbackRender:({error:b})=>X.jsx("div",{className:"rf-mt-4 rf-mx-4 rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200",children:X.jsxs("div",{className:"rf-p-4",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-3",children:"Error loading Circuit JSON Preview"}),X.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?X.jsxs("div",{className:"rf-w-full rf-h-full rf-flex rf-flex-col",children:[X.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)&&X.jsx(vF,{isWebEmbedded:!0,circuitJson:null,projectName:t.projectName}),h.length>1&&X.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:X.jsx(wbt,{currentFile:e,files:h,onFileChange:f})})]}),X.jsx("div",{className:"rf-flex-1 rf-flex rf-items-center rf-justify-center",children:X.jsxs("div",{className:"rf-text-center rf-p-8",children:[X.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-600 rf-mb-2",children:"Failed to Load Circuit File"}),X.jsxs("p",{className:"rf-text-sm rf-text-gray-600 rf-mb-4",children:["Could not load: ",e]}),X.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-gap-2",children:[X.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&&X.jsx("p",{className:"rf-text-xs rf-text-gray-500",children:"Or select a different file from the dropdown above"})]})]})})]}):X.jsx(S3t,{circuitJson:o,defaultToFullScreen:t.defaultToFullScreen,showToggleFullScreen:t.showToggleFullScreen,showFileMenu:!1,isWebEmbedded:!1,projectName:t.projectName,defaultActiveTab:t.tabSelected,leftHeaderContent:X.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full",children:[(t.showFileMenu??!0)&&X.jsx(vF,{isWebEmbedded:!0,circuitJson:o,projectName:t.projectName}),h.length>1&&X.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:X.jsx(wbt,{currentFile:e,files:h,onFileChange:f})})]})})})},Lxo=()=>{const t=v0(e=>e.fsMap);Y.useEffect(()=>{if(!document||!t)return;const e=Array.from(t.keys()),n=Ubt(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])},Ebt=(t,e,n)=>{const o=t instanceof RegExp?Dbt(t,n):t,r=e instanceof RegExp?Dbt(e,n):e,i=o!==null&&r!=null&&Oxo(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)}},Dbt=(t,e)=>{const n=e.match(t);return n?n[0]:null},Oxo=(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},Abt="\0SLASH"+Math.random()+"\0",kbt="\0OPEN"+Math.random()+"\0",Yve="\0CLOSE"+Math.random()+"\0",Rbt="\0COMMA"+Math.random()+"\0",Nbt="\0PERIOD"+Math.random()+"\0",Fxo=new RegExp(Abt,"g"),Bxo=new RegExp(kbt,"g"),zxo=new RegExp(Yve,"g"),Vxo=new RegExp(Rbt,"g"),$xo=new RegExp(Nbt,"g"),Wxo=/\\\\/g,jxo=/\\{/g,Uxo=/\\}/g,Xxo=/\\,/g,Gxo=/\\./g;function qve(t){return isNaN(t)?t.charCodeAt(0):parseInt(t,10)}function Yxo(t){return t.replace(Wxo,Abt).replace(jxo,kbt).replace(Uxo,Yve).replace(Xxo,Rbt).replace(Gxo,Nbt)}function qxo(t){return t.replace(Fxo,"\\").replace(Bxo,"{").replace(zxo,"}").replace(Vxo,",").replace($xo,".")}function Ibt(t){if(!t)return[""];const e=[],n=Ebt("{","}",t);if(!n)return t.split(",");const{pre:o,body:r,post:i}=n,s=o.split(",");s[s.length-1]+="{"+r+"}";const a=Ibt(i);return i.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),e.push.apply(e,s),e}function Kxo(t){return t?(t.slice(0,2)==="{}"&&(t="\\{\\}"+t.slice(2)),DF(Yxo(t),!0).map(qxo)):[]}function Jxo(t){return"{"+t+"}"}function Qxo(t){return/^-?0\d/.test(t)}function Zxo(t,e){return t<=e}function ego(t,e){return t>=e}function DF(t,e){const n=[],o=Ebt("{","}",t);if(!o)return[t];const r=o.pre,i=o.post.length?DF(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+Yve+o.post,DF(t)):[t];let u;if(c)u=o.body.split(/\.\./);else if(u=Ibt(o.body),u.length===1&&u[0]!==void 0&&(u=DF(u[0],!1).map(Jxo),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=qve(u[0]),m=qve(u[1]),h=Math.max(u[0].length,u[1].length);let p=u.length===3&&u[2]!==void 0?Math.abs(qve(u[2])):1,x=Zxo;m<d&&(p*=-1,x=ego);const g=u.some(Qxo);_=[];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(_,DF(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 tgo=1024*64,QQ=t=>{if(typeof t!="string")throw new TypeError("invalid pattern");if(t.length>tgo)throw new TypeError("pattern is too long")},ngo={"[: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]},AF=t=>t.replace(/[[\]\\-]/g,"\\$&"),ogo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Hbt=t=>t.join(""),rgo=(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(ngo))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(AF(_)+"-"+AF(p)):p===_&&o.push(AF(p)),_="",i++;continue}if(t.startsWith("-]",i+1)){o.push(AF(p+"-")),i+=2;continue}if(t.startsWith("-",i+1)){_=p,i+=2;continue}o.push(AF(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[ogo(p),!1,u-n,!1]}const d="["+(l?"^":"")+Hbt(o)+"]",m="["+(l?"":"^")+Hbt(r)+"]";return[o.length&&r.length?"("+d+"|"+m+")":o.length?d:m,a,u-n,!0]},kF=(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"),igo=new Set(["!","?","+","*","@"]),Lbt=t=>igo.has(t),sgo="(?!(?:^|/)\\.\\.?(?:$|/))",ZQ="(?!\\.)",ago=new Set(["[","."]),cgo=new Set(["..","."]),lgo=new Set("().*{}+?[]^$\\!"),ugo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Kve="[^/]",Obt=Kve+"*?",Fbt=Kve+"+?";class ix{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 ix&&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 ix&&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 ix(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&&Lbt(p)&&e.charAt(m)==="("){n.push(h),h="";const x=new ix(p,n);m=ix.#c(e,x,m,r),n.push(x);continue}h+=p}return n.push(h),m}let l=o+1,u=new ix(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(Lbt(m)&&e.charAt(l)==="("){u.push(d),d="";const h=new ix(m,u);u.push(h),l=ix.#c(e,h,l,r);continue}if(m==="|"){u.push(d),d="",_.push(u),u=new ix(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 ix(null,void 0,n);return ix.#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"?ix.#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&&cgo.has(this.#t[0]))){const h=ago,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?sgo:x?ZQ:""}let _="";return this.isEnd()&&this.#o.#l&&this.#e?.type==="!"&&(_="(?:$|\\/)"),[u+l+_,kF(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,kF(this.toString()),!1,!1]}let s=!o||e||n||!ZQ?"":this.#h(!0);s===i&&(s=""),s&&(i=`(?:${i})(?:${s})*?`);let a="";if(this.type==="!"&&this.#_)a=(this.isStart()&&!n?ZQ:"")+Fbt;else{const c=this.type==="!"?"))"+(this.isStart()&&!n&&!e?ZQ:"")+Obt+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=r+i+c}return[a,kF(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+=(lgo.has(c)?"\\":"")+c;continue}if(c==="\\"){a===e.length-1?i+="\\\\":r=!0;continue}if(c==="["){const[l,u,_,d]=rgo(e,a);if(_){i+=l,s=s||u,a+=_-1,n=n||d;continue}}if(c==="*"){i+=o&&e==="*"?Fbt:Obt,n=!0;continue}if(c==="?"){i+=Kve,n=!0;continue}i+=ugo(c)}return[i,kF(e),!!n,s]}}const _go=(t,{windowsPathsNoEscape:e=!1,magicalBraces:n=!1}={})=>n?e?t.replace(/[?*()[\]{}]/g,"[$&]"):t.replace(/[?*()[\]\\{}]/g,"\\$&"):e?t.replace(/[?*()[\]]/g,"[$&]"):t.replace(/[?*()[\]\\]/g,"\\$&");var Ck={env:{}};const sx=(t,e,n={})=>(QQ(e),!n.nocomment&&e.charAt(0)==="#"?!1:new RF(e,n).match(t)),dgo=/^\*+([^+@!?\*\[\(]*)$/,hgo=t=>e=>!e.startsWith(".")&&e.endsWith(t),mgo=t=>e=>e.endsWith(t),pgo=t=>(t=t.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(t)),fgo=t=>(t=t.toLowerCase(),e=>e.toLowerCase().endsWith(t)),xgo=/^\*+\.\*+$/,ggo=t=>!t.startsWith(".")&&t.includes("."),ygo=t=>t!=="."&&t!==".."&&t.includes("."),bgo=/^\.\*+$/,Pgo=t=>t!=="."&&t!==".."&&t.startsWith("."),vgo=/^\*+$/,Sgo=t=>t.length!==0&&!t.startsWith("."),Cgo=t=>t.length!==0&&t!=="."&&t!=="..",Mgo=/^\?+([^+@!?\*\[\(]*)?$/,Tgo=([t,e=""])=>{const n=Bbt([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},wgo=([t,e=""])=>{const n=zbt([t]);return e?(e=e.toLowerCase(),o=>n(o)&&o.toLowerCase().endsWith(e)):n},Ego=([t,e=""])=>{const n=zbt([t]);return e?o=>n(o)&&o.endsWith(e):n},Dgo=([t,e=""])=>{const n=Bbt([t]);return e?o=>n(o)&&o.endsWith(e):n},Bbt=([t])=>{const e=t.length;return n=>n.length===e&&!n.startsWith(".")},zbt=([t])=>{const e=t.length;return n=>n.length===e&&n!=="."&&n!==".."},Vbt=typeof Ck=="object"&&Ck?typeof Ck.env=="object"&&Ck.env&&Ck.env.__MINIMATCH_TESTING_PLATFORM__||Ck.platform:"posix",$bt={win32:{sep:"\\"},posix:{sep:"/"}},Ago=Vbt==="win32"?$bt.win32.sep:$bt.posix.sep;sx.sep=Ago;const E3=Symbol("globstar **");sx.GLOBSTAR=E3;const kgo="[^/]"+"*?",Rgo="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Ngo="(?:(?!(?:\\/|^)\\.).)*?",Igo=(t,e={})=>n=>sx(n,t,e);sx.filter=Igo;const D3=(t,e={})=>Object.assign({},t,e),Hgo=t=>{if(!t||typeof t!="object"||!Object.keys(t).length)return sx;const e=sx;return Object.assign((o,r,i={})=>e(o,r,D3(t,i)),{Minimatch:class extends e.Minimatch{constructor(r,i={}){super(r,D3(t,i))}static defaults(r){return e.defaults(D3(t,r)).Minimatch}},AST:class extends e.AST{constructor(r,i,s={}){super(r,i,D3(t,s))}static fromGlob(r,i={}){return e.AST.fromGlob(r,D3(t,i))}},unescape:(o,r={})=>e.unescape(o,D3(t,r)),escape:(o,r={})=>e.escape(o,D3(t,r)),filter:(o,r={})=>e.filter(o,D3(t,r)),defaults:o=>e.defaults(D3(t,o)),makeRe:(o,r={})=>e.makeRe(o,D3(t,r)),braceExpand:(o,r={})=>e.braceExpand(o,D3(t,r)),match:(o,r,i={})=>e.match(o,r,D3(t,i)),sep:e.sep,GLOBSTAR:E3})};sx.defaults=Hgo;const Wbt=(t,e={})=>(QQ(t),e.nobrace||!/\{(?:(?!\{).)*\}/.test(t)?[t]:Kxo(t));sx.braceExpand=Wbt;const Lgo=(t,e={})=>new RF(t,e).makeRe();sx.makeRe=Lgo;const Ogo=(t,e,n={})=>{const o=new RF(e,n);return t=t.filter(r=>o.match(r)),o.options.nonull&&!t.length&&t.push(e),t};sx.match=Ogo;const jbt=/[?*]|[+@!]\(.*?\)|\[|\]/,Fgo=t=>t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");class RF{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(e,n={}){QQ(e),n=n||{},this.options=n,this.pattern=e,this.platform=n.platform||Vbt,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]==="?"||!jbt.test(i[2]))&&!jbt.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===E3){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(`
|
|
5825
5825
|
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(`
|
|
5826
5826
|
>>> 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 Wbt(this.pattern,this.options)}parse(e){QQ(e);const n=this.options;if(e==="**")return E3;if(e==="")return"";let o,r=null;(o=e.match(vgo))?r=n.dot?Cgo:Sgo:(o=e.match(dgo))?r=(n.nocase?n.dot?fgo:pgo:n.dot?mgo:hgo)(o[1]):(o=e.match(Mgo))?r=(n.nocase?n.dot?wgo:Tgo:n.dot?Ego:Dgo)(o):(o=e.match(xgo))?r=n.dot?ygo:ggo:(o=e.match(bgo))&&(r=Pgo);const i=ix.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?kgo:n.dot?Rgo:Ngo,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"?Fgo(_):_===E3?E3:_._src});l.forEach((_,d)=>{const m=l[d+1],h=l[d-1];_!==E3||h===E3||(h===void 0?m!==void 0&&m!==E3?l[d+1]="(?:\\/|"+o+"\\/)?"+m:l[d]=o:m===void 0?l[d-1]=h+"(?:\\/|\\/"+o+")?":m!==E3&&(l[d-1]=h+"(?:\\/|\\/"+o+"\\/)"+m,l[d+1]=E3))});const u=l.filter(_=>_!==E3);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 sx.defaults(e).Minimatch}}sx.AST=ix,sx.Minimatch=RF,sx.escape=_go,sx.unescape=kF;const Bgo=t=>(t.endsWith(".tsx")||t.endsWith(".ts")||t.endsWith(".jsx")||t.endsWith(".js")||XQ(t))&&!t.endsWith(".d.ts"),zgo=t=>{if(!t)return null;try{const e=JSON.parse(t);return OEt.parse(e)}catch(e){return console.warn("Failed to parse tscircuit.config.json",e),null}},Vgo=(t,e)=>{const o=zgo(e)?.includeBoardFiles?.filter(Boolean);if(o&&o.length>0){const r=o.map(i=>new RF(i,{dot:!0}));return t.filter(i=>r.some(s=>s.match(i)))}return t.filter(Bgo)},Jve=fc("run-frame:RunFrameWithApi"),$go=()=>{const e=!!v0(o=>o.error),n=e?"Dev server disconnected":"Dev server connected";return X.jsx(X3t,{children:X.jsxs(G3t,{children:[X.jsx(Y3t,{asChild:!0,children:X.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:X.jsx("span",{className:yr("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"})})}),X.jsx(Ove,{side:"right",children:n})]})})},Ubt=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")),Wgo=t=>t.find(e=>e.includes("manual-edits."))??t.find(e=>e.includes("manual-edit."))??t.find(e=>e.endsWith(".json")),Xbt=t=>{const{apiBaseUrl:e,leftHeaderContent:n}=t;Y.useEffect(()=>{t.debug&&fc.enable("run-frame*")},[t.debug]);const o=v0(F=>F.startPolling),r=v0(F=>F.stopPolling),i=v0(F=>F.setCurrentMainComponentPath),s=v0(F=>F.pushEvent),a=kfn(),c=v0(F=>F.fsMap),l=v0(F=>F.recentlySavedFiles),u=Y.useMemo(()=>Array.from(c.keys()),[c]),_=Y.useMemo(()=>{const F=c.get("tscircuit.config.json");return typeof F=="string"?F:void 0},[c]),d=Y.useMemo(()=>Vgo(u,_),[u,_]),m=v0(F=>F.circuitJson),[h,p]=Y.useState(()=>typeof window>"u"?t.initialMainComponentPath??"":new URLSearchParams(window.location.hash.slice(1)).get("file")??t.initialMainComponentPath??""),[x,f]=qE("runframe:favorites",[]),g=!a,y=Y.useCallback(F=>{f(B=>B.includes(F)?B.filter(V=>V!==F):[...B,F])},[f]),b=t.fileFilter??t2o,v=Y.useMemo(()=>d.filter(b),[d,b]);Y.useEffect(()=>{if(h&&(v.includes(h)||d.includes(h)))return;if(h){const K=h.includes("/")?h.substring(0,h.lastIndexOf("/")):"",Q=v.find(oe=>(oe.includes("/")?oe.substring(0,oe.lastIndexOf("/")):"")===K);if(Q){p(Q);return}}const F=window?.TSCIRCUIT_DEFAULT_MAIN_COMPONENT_PATH,B=[t.initialMainComponentPath,F].filter(K=>!!K);for(const K of B)if(v.includes(K)){p(K);return}const G=(v.length>0?v:d)[0];G&&p(G)},[v,d,t.initialMainComponentPath,h]);const S=Y.useCallback(F=>{if(typeof window>"u")return;const B=new URLSearchParams(window.location.hash.slice(1));if(B.get("file")===F)return;B.set("file",F);const V=B.toString(),G=`${window.location.pathname}${window.location.search}${V.length>0?`#${V}`:""}`;window.history.replaceState(null,"",G)},[]);Y.useEffect(()=>{h&&(S(h),t.onMainComponentPathChange?.(h),i(h))},[h,t.onMainComponentPathChange,S,i]),Lxo();const{editEventsForRender:M,pushEditEvent:T,markRenderStarted:D,markRenderComplete:A}=Afn();Y.useEffect(()=>{e&&(window.TSCIRCUIT_FILESERVER_API_BASE_URL=e)},[e]),Y.useEffect(()=>(o(),()=>r()),[o,r]);const L=Y.useMemo(()=>String(h).length>0?{mainComponentPath:h}:{},[h]),H=Y.useCallback(async F=>{try{await s({event_type:"RUN_COMPLETED",initiator:"runframe",...F})}catch(B){Jve("Failed to push RUN_COMPLETED event",B)}},[s]);return X.jsx(K3t,{fsMap:c,showFileMenu:t.showFileMenu,isLoadingFiles:g,evalVersion:t.evalVersion,forceLatestEvalVersion:t.forceLatestEvalVersion,evalWebWorkerBlobUrl:t.evalWebWorkerBlobUrl??t.workerBlobUrl,enableFetchProxy:t.enableFetchProxy,leftHeaderContent:X.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-w-full",children:[X.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[t.leftHeaderContent,X.jsx($go,{})]}),t.showFilesSwitch&&X.jsx("div",{className:"rf-absolute rf-left-1/2 rf-transform rf--translate-x-1/2",children:X.jsx(Tbt,{currentFile:h,files:v,onFileChange:F=>{typeof c.get(F)=="string"&&p(F)},pinnedFiles:x,onToggleFavorite:y,fileFilter:b,recentlySavedFiles:l})})]}),defaultToFullScreen:t.defaultToFullScreen,showToggleFullScreen:t.showToggleFullScreen,onInitialRender:()=>{Jve("onInitialRender / markRenderStarted"),D()},onRenderFinished:()=>{Jve("onRenderFinished / markRenderComplete"),A()},onRunCompleted:H,editEvents:M,onEditEvent:F=>{T(F),fetch(`${X2}/events/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event_type:"USER_CREATED_MANUAL_EDIT",...F})});const B=Wgo(Array.from(c.keys()))??"manual-edits.json",V=c.get(B),G=JSON.parse(V??"{}");MXe({circuitJson:m,editEvents:[F],manualEditsFile:G}),fetch(`${X2}/files/upsert`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_path:B,text_content:JSON.stringify(G),initiator:"runframe"})})},onLoginRequired:t.onLoginRequired,easyEdaProxyConfig:{proxyEndpointUrl:`${X2}/proxy`},...L})},jgo=()=>new Promise(t=>{document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>t()):t()}),Ugo=()=>{const t=window.location.hash.slice(1),n=new URLSearchParams(t).get("tab")?.toLowerCase()?.trim();return n&&["pcb","schematic","cad"].includes(n)?n:"pcb"},Xgo=()=>{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},Ggo=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}},Gbt="<--INJECT_TSCIRCUIT_EVAL_WEB_WORKER_BLOB_URL-->",Qve={evalWebWorkerBlobUrl:Gbt.includes("<--")?void 0:Gbt,enableFetchProxy:"<--INJECT_ENABLE_FETCH_PROXY-->".includes("<--")?void 0:!0};(async()=>{await jgo();const t=QPt.createRoot(Xgo()),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=Ugo();t.render(X.jsx(Hxo,{files:e,initialCircuitPath:n,tabSelected:r,projectName:o}))}else if(window.TSCIRCUIT_USE_RUNFRAME_FOR_CLI)t.render(X.jsx(H2o,{...Qve}));else{const{fsMap:r}=await Ggo();r.size>0?t.render(X.jsx(K3t,{...Qve,fsMap:r})):t.render(X.jsx(Xbt,{...Qve}))}})()}));
|