@tscircuit/runframe 0.0.2665 → 0.0.2667
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.
|
@@ -2861,7 +2861,7 @@ var usePostHogActivity = (properties) => {
|
|
|
2861
2861
|
};
|
|
2862
2862
|
|
|
2863
2863
|
// package.json
|
|
2864
|
-
var version = "0.0.
|
|
2864
|
+
var version = "0.0.2665";
|
|
2865
2865
|
var package_default = {
|
|
2866
2866
|
name: "@tscircuit/runframe",
|
|
2867
2867
|
main: "dist/preview.js",
|
|
@@ -2984,13 +2984,13 @@ var package_default = {
|
|
|
2984
2984
|
},
|
|
2985
2985
|
dependencies: {
|
|
2986
2986
|
"@tscircuit/core": "^0.0.1847",
|
|
2987
|
-
"@tscircuit/eval": "^0.0.
|
|
2987
|
+
"@tscircuit/eval": "^0.0.1356",
|
|
2988
2988
|
"@tscircuit/solver-utils": "^0.0.16",
|
|
2989
2989
|
debug: "^4.4.0",
|
|
2990
2990
|
"format-si-unit": "^0.0.12"
|
|
2991
2991
|
},
|
|
2992
2992
|
overrides: {
|
|
2993
|
-
"circuit-json": "
|
|
2993
|
+
"circuit-json": "$circuit-json"
|
|
2994
2994
|
}
|
|
2995
2995
|
};
|
|
2996
2996
|
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -5768,7 +5768,7 @@ test("${c} should solve problem correctly", () => {
|
|
|
5768
5768
|
// Add more specific assertions based on expected output
|
|
5769
5769
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5770
5770
|
})
|
|
5771
|
-
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&z.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:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},Dzt=t=>t.activeSubSolver?[t,...Dzt(t.activeSubSolver)]:[t],hci=({solver:t})=>{const e=Dzt(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(dci,{solver:n})]},n.getSolverName()))})},mci=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=Z.useReducer(S=>!S,!1),g=Z.useRef(void 0),u=Z.useRef(null),h="solver-debugger-last-iteration",[d,m]=Z.useState(null),p=Z.useRef(null),_=Z.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),f=()=>{const S=Math.max(1,n),Q=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let P=0;P<Q&&!(t.solved||t.failed);P++)t.step();e()},S)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const S=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(S===null)return;u.current=S,typeof window<"u"&&window.localStorage.setItem(h,S);const Q=Number(S);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<Q&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return Z.useEffect(()=>()=>{I()},[]),Z.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),Z.useEffect(()=>{c&&(I(),f())},[n,c]),Z.useEffect(()=>{if(typeof document>"u")return;const S=Q=>{p.current&&!p.current.contains(Q.target)&&m(null)};return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[]),z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[z.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(S=>z.jsxs("button",{type:"button",onClick:()=>{i(S),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S==="vector"?"Vector":"Canvas",o===S&&z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},S))})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:z.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:_.map(S=>z.jsxs("button",{type:"button",onClick:()=>{r(S.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S.label,z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:S.description}),n===S.value&&z.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},S.value))})]})]}),z.jsx(hci,{solver:t})]})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),z.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},pci=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),_ci=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},fci=(t,e)=>{const o=t.pipelineDef[e].solverName,i=_ci(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},Ici=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Cci=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Mzt=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},yci=t=>Object.entries(t).map(([e,n])=>`${e}: ${Mzt(n)}`).join(", "),xci=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=yci(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",Mzt(i)]},o))})]})},Nke=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Nke);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Nke(o));return e},Eci=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Nke(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},Bci=({expanded:t})=>z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${t?"rotate-90":""}`,children:z.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"})}),wzt=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},Nzt=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=Z.useState(new Set),A=t.pipelineDef.map((p,_)=>fci(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):Eci(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=wzt(t);for(;!t.solved&&!t.failed&&(t.step(),wzt(t)===p););r?.()}},m=i*24;return z.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&z.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),z.jsxs("div",{className:"flex gap-2",children:[z.jsx("button",{onClick:d,disabled:t.solved||t.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),z.jsx("button",{onClick:h,disabled:t.solved||t.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[!o&&z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:A.map(p=>{const _=pci(p.solverInstance),f=s.has(p.name);return z.jsxs(Xr.Fragment,{children:[z.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?z.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:z.jsx(Bci,{expanded:f})}):z.jsx("span",{className:"w-4"}),z.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>l(p.name),disabled:p.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 ${p.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(Ici,{status:p.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(Cci,{progress:p.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(xci,{stats:p.stats})}),z.jsx("td",{className:"px-4 py-2",children:p.solverInstance?z.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})}),z.jsx("span",{children:"Input"})]}):null})]}),_&&f&&z.jsx("tr",{children:z.jsx("td",{colSpan:8,className:"p-0",children:z.jsx(Nzt,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function Sci({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>z.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>z.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>z.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var Qci=class extends Xr.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}},bci=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=Z.useReducer(f=>f+1,0),[a]=Z.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=Z.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=Z.useState(n),u=Z.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=Z.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);Z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),Z.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return z.jsxs("div",{children:[z.jsx(mci,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(Qci,{fallback:z.jsx(Sci,{graphics:u}),children:A==="canvas"?z.jsx(uci,{graphics:u}):z.jsx(cci,{graphics:u})}),d&&z.jsx(Nzt,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const Pci=()=>{Z.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)},[])},vci=1e3,hB=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},vci)},Rke=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},Dci=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},p3="https://github.com/tscircuit/tscircuit-autorouter/issues/new",Rzt="https://github.com/tscircuit/copper-pour-solver/issues/new",Tzt="https://github.com/tscircuit/calculate-packing/issues/new",Mci="https://github.com/tscircuit/matchpack/issues/new",kzt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",wci={PackSolver2:Tzt,LayoutPipelineSolver:Mci,AutoroutingPipelineSolver:p3,AssignableAutoroutingPipeline2:p3,AssignableAutoroutingPipeline3:p3,AutoroutingPipeline1_OriginalUnravel:p3,AutoroutingPipelineSolver3_HgPortPointPathing:p3,AutoroutingPipelineSolver4:p3,AutoroutingPipelineSolver5:p3,AutoroutingPipelineSolver7_MultiGraph:p3,AutoroutingPipelineSolver8:p3,CopperPourPipelineSolver:Rzt,SchematicTracePipelineSolver:kzt},Nci=t=>t.toLowerCase().includes("pack")?lWo:t.toLowerCase().includes("rout")?_Gt:nWo,Fzt=t=>{const e=wci[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?p3:n.includes("schematic")&&n.includes("trace")?kzt:n.includes("copperpour")?Rzt:n.includes("pack")?Tzt:null},Rci=t=>`${Rke(`${t.componentName}-${t.solverName}`)}-solver-input.json`,Lzt=t=>{hB(JSON.stringify(t.solverParams,null,2),{fileName:Rci(t),mimeType:"application/json"})},Tci=({solverEvent:t})=>{const e=Fzt(t.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[z.jsxs(ic,{type:"button",variant:"outline",size:"sm",onClick:()=>Lzt(t),children:[z.jsx(XV,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(ic,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx(rce,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(ic,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx(rce,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},kci=({solverEvent:t})=>{const e=Fzt(t.solverName);return e?z.jsx(ic,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx(rce,{className:"rf-w-4 rf-h-4"})})}):z.jsx(ic,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:z.jsx(rce,{className:"rf-w-4 rf-h-4"})})},Fci=({solverEvents:t=[]})=>{const[e,n]=Z.useState(null);Pci();const o=Z.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=Z.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=Z.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=VPe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(VPe).join(", ")}`,classFound:!1};try{return{instance:new a(...Dci(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.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."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=Nci(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(Tci,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(LS,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(bci,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.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:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(kci,{solverEvent:r}),z.jsx(ic,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>Lzt(r),children:z.jsx(XV,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Lci=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Hci=new Set(["tscircuit","default","auto","auto_local"]);function Gci(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function Oci(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&Lci.get(n);if(o)return o;if(n&&!Hci.has(n))return e;const i=t.solverName?.trim();if(i)return Gci(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const Tke="#fbbf24";function Uci(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function Hzt(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function Yci(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function Gzt(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...Yci(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function Kci(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(Hzt(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of Gzt(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:Tke,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:Tke,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function zci(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const Vci=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function Jci(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!Vci.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:Uci(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=Gzt(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${zci(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const kke=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,Ozt=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",Uzt=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,Wci={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},qci=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=Z.useState(null),[r,s]=Z.useState("output"),[a,A]=Z.useState(!0),[c,l]=Z.useState(!1),g=Z.useRef(null),[u,h]=Z.useState(480),d=o?e.findIndex(L=>L.id===o.id&&Uzt(L)===Uzt(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=Z.useMemo(()=>!p||!x?null:Jci(t??[],p,y),[t,p,x,y]),S=Z.useMemo(()=>p&&y==="output"&&a?Kci(p):{lines:[],circles:[]},[p,y,a]);if(Z.useLayoutEffect(()=>{const L=g.current;if(!L)return;const G=()=>h(Math.max(360,L.clientHeight));G();const O=new ResizeObserver(G);return O.observe(L),()=>O.disconnect()},[!!p]),!p)return z.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[z.jsx(_Gt,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),z.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),z.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const Q=kke(p,m),P=p.status==="running"&&n,w=!f,R=I?.connections.length,F=E?.filter(L=>L.type==="pcb_trace").length??0;return z.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[z.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[z.jsx("span",{children:"Routing phases"}),z.jsx("span",{children:e.length})]}),z.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:e.map((L,G)=>{const O=Hzt(L).length,K=L.endSimpleRouteJson?`${O} ${O===1?"trace":"traces"} routed`:L.status==="error"?"Failed":L.status==="running"&&n?"Routing…":"No output";return z.jsxs("button",{type:"button","aria-pressed":G===m,title:`${Ozt(L)} · ${K}`,onClick:()=>i(L),className:dr("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",G===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[z.jsx("span",{className:dr("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",G===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:G+1}),z.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[z.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:kke(L,G),children:kke(L,G)}),L.status==="complete"?z.jsx(jV,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):L.status==="error"?z.jsx(bRe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?z.jsx(AB,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),z.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[Oci(L)," · ",K]})]})]},L.id)})})]}),z.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[z.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[Q,z.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&z.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),z.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(L=>z.jsx("button",{type:"button","aria-pressed":y===L,disabled:L==="input"?!C:!f,onClick:()=>s(L),className:dr("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===L?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:L==="input"?"Input":"Output"},L))})]}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[z.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:L=>A(L.target.checked),className:"rf-accent-blue-600"}),z.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Tke}}),"Highlight changes (all layers)"]}),z.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",F," traces"]})]}),w&&z.jsx("div",{className:dr("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:P?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),z.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?z.jsx(Qke,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:Wci,debugGraphics:S}):z.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[z.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${Ozt(p)}`]}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[z.jsxs("button",{type:"button",disabled:!x,onClick:()=>hB(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[z.jsx(XV,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),z.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(xL,{className:dr("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&z.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${Q} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},Yzt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Z.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{H8.captureException(o)}catch{}}},[t,e]),Z.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{H8.captureException(i,{error_type:o.type})}catch{}}},[n])},jci=t=>{Z.useEffect(()=>{try{Ftn(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},Kzt="0.0.2661",Xci={version:Kzt},Fke={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Lke=new Map,Nle=t=>{const e=Lke.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},$ci=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Lke.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return Lke.set(n.name,i),{type:"tracked",store:t,...i}},zzt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(Fke?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Fke?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=$ci(a,c,A);let u=!0;i.setState=(m,p,_)=>{const f=n(m,p);if(!u)return f;const I=_===void 0?{type:s||"anonymous"}:typeof _=="string"?{type:_}:_;return a===void 0?(l?.send(I,o()),f):(l?.send({...I,type:`${a}/${I.type}`},{...Nle(A.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=u;u=!1,n(...m),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([m,p])=>[m,m===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(..._)=>{(Fke?"production":void 0)!=="production"&&_[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(..._)}}return l.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Hke(m.payload,_=>{if(_.type==="__setState"){if(a===void 0){h(_.state);return}Object.keys(_.state).length!==1&&console.error(`
|
|
5771
|
+
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return z.jsxs("div",{className:`relative ${e}`,ref:i,children:[z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&z.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:[z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},Dzt=t=>t.activeSubSolver?[t,...Dzt(t.activeSubSolver)]:[t],hci=({solver:t})=>{const e=Dzt(t);return z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>z.jsxs("div",{className:"flex items-center",children:[o>0&&z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),z.jsx(dci,{solver:n})]},n.getSolverName()))})},mci=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=Z.useReducer(S=>!S,!1),g=Z.useRef(void 0),u=Z.useRef(null),h="solver-debugger-last-iteration",[d,m]=Z.useState(null),p=Z.useRef(null),_=Z.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),f=()=>{const S=Math.max(1,n),Q=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let P=0;P<Q&&!(t.solved||t.failed);P++)t.step();e()},S)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const S=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(S===null)return;u.current=S,typeof window<"u"&&window.localStorage.setItem(h,S);const Q=Number(S);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<Q&&!t.solved&&!t.failed;)t.step();e(),t.solved&&A&&A(t)};return Z.useEffect(()=>()=>{I()},[]),Z.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),Z.useEffect(()=>{c&&(I(),f())},[n,c]),Z.useEffect(()=>{if(typeof document>"u")return;const S=Q=>{p.current&&!p.current.contains(Q.target)&&m(null)};return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[]),z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[z.jsx("div",{className:"flex items-center",children:z.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[z.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(S=>z.jsxs("button",{type:"button",onClick:()=>{i(S),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S==="vector"?"Vector":"Canvas",o===S&&z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},S))})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:z.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),z.jsxs("div",{className:"relative",children:[z.jsx("button",{type:"button",onClick:()=>m(d==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&z.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:_.map(S=>z.jsxs("button",{type:"button",onClick:()=>{r(S.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S.label,z.jsx("span",{className:"ml-auto text-xs text-slate-500",children:S.description}),n===S.value&&z.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},S.value))})]})]}),z.jsx(hci,{solver:t})]})}),z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[z.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),z.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),z.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),z.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},pci=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),_ci=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},fci=(t,e)=>{const o=t.pipelineDef[e].solverName,i=_ci(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},Ici=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return z.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Cci=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return z.jsxs("div",{className:"flex items-center gap-2",children:[z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),z.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Mzt=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},yci=t=>Object.entries(t).map(([e,n])=>`${e}: ${Mzt(n)}`).join(", "),xci=({stats:t})=>{if(!t||Object.keys(t).length===0)return z.jsx("span",{children:"-"});const e=Object.entries(t),n=yci(t);return z.jsxs("details",{className:"cursor-pointer",children:[z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),z.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>z.jsxs("div",{children:[o,": ",Mzt(i)]},o))})]})},Nke=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Nke);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Nke(o));return e},Eci=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Nke(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},Bci=({expanded:t})=>z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${t?"rotate-90":""}`,children:z.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"})}),wzt=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},Nzt=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=Z.useState(new Set),A=t.pipelineDef.map((p,_)=>fci(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):Eci(p.solverInstance,p.name))},u=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=wzt(t);for(;!t.solved&&!t.failed&&(t.step(),wzt(t)===p););r?.()}},m=i*24;return z.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&z.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),z.jsxs("div",{className:"flex gap-2",children:[z.jsx("button",{onClick:d,disabled:t.solved||t.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),z.jsx("button",{onClick:h,disabled:t.solved||t.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),z.jsx("div",{className:"overflow-x-auto",children:z.jsxs("table",{className:"w-full text-sm",children:[!o&&z.jsx("thead",{children:z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",z.jsx("sub",{children:"0"})]}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),z.jsx("tbody",{children:A.map(p=>{const _=pci(p.solverInstance),f=s.has(p.name);return z.jsxs(Xr.Fragment,{children:[z.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[z.jsx("td",{className:"px-4 py-2",children:z.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?z.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:z.jsx(Bci,{expanded:f})}):z.jsx("span",{className:"w-4"}),z.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),z.jsx("button",{onClick:()=>l(p.name),disabled:p.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 ${p.name} completes`,children:z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})})}),z.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(Ici,{status:p.status})}),z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),z.jsx("td",{className:"px-4 py-2",children:z.jsx(Cci,{progress:p.progress})}),z.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),z.jsx("td",{className:"px-4 py-2 text-gray-500",children:z.jsx(xci,{stats:p.stats})}),z.jsx("td",{className:"px-4 py-2",children:p.solverInstance?z.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:z.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"})}),z.jsx("span",{children:"Input"})]}):null})]}),_&&f&&z.jsx("tr",{children:z.jsx("td",{colSpan:8,className:"p-0",children:z.jsx(Nzt,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function Sci({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>z.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${_}`)),n.map((p,_)=>z.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${_}`)),e.map((p,_)=>z.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>z.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var Qci=class extends Xr.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}},bci=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=Z.useReducer(f=>f+1,0),[a]=Z.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=Z.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=Z.useState(n),u=Z.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=Z.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);Z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),Z.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},_=f=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return z.jsxs("div",{children:[z.jsx(mci,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):z.jsx(Qci,{fallback:z.jsx(Sci,{graphics:u}),children:A==="canvas"?z.jsx(uci,{graphics:u}):z.jsx(cci,{graphics:u})}),d&&z.jsx(Nzt,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const Pci=()=>{Z.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)},[])},vci=1e3,hB=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},vci)},Rke=t=>{let e=t.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},Dci=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},p3="https://github.com/tscircuit/tscircuit-autorouter/issues/new",Rzt="https://github.com/tscircuit/copper-pour-solver/issues/new",Tzt="https://github.com/tscircuit/calculate-packing/issues/new",Mci="https://github.com/tscircuit/matchpack/issues/new",kzt="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",wci={PackSolver2:Tzt,LayoutPipelineSolver:Mci,AutoroutingPipelineSolver:p3,AssignableAutoroutingPipeline2:p3,AssignableAutoroutingPipeline3:p3,AutoroutingPipeline1_OriginalUnravel:p3,AutoroutingPipelineSolver3_HgPortPointPathing:p3,AutoroutingPipelineSolver4:p3,AutoroutingPipelineSolver5:p3,AutoroutingPipelineSolver7_MultiGraph:p3,AutoroutingPipelineSolver8:p3,CopperPourPipelineSolver:Rzt,SchematicTracePipelineSolver:kzt},Nci=t=>t.toLowerCase().includes("pack")?lWo:t.toLowerCase().includes("rout")?_Gt:nWo,Fzt=t=>{const e=wci[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?p3:n.includes("schematic")&&n.includes("trace")?kzt:n.includes("copperpour")?Rzt:n.includes("pack")?Tzt:null},Rci=t=>`${Rke(`${t.componentName}-${t.solverName}`)}-solver-input.json`,Lzt=t=>{hB(JSON.stringify(t.solverParams,null,2),{fileName:Rci(t),mimeType:"application/json"})},Tci=({solverEvent:t})=>{const e=Fzt(t.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[z.jsxs(ic,{type:"button",variant:"outline",size:"sm",onClick:()=>Lzt(t),children:[z.jsx(XV,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?z.jsx(ic,{asChild:!0,variant:"outline",size:"sm",children:z.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[z.jsx(rce,{className:"rf-w-4 rf-h-4"}),"Report"]})}):z.jsxs(ic,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[z.jsx(rce,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},kci=({solverEvent:t})=>{const e=Fzt(t.solverName);return e?z.jsx(ic,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:z.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:z.jsx(rce,{className:"rf-w-4 rf-h-4"})})}):z.jsx(ic,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:z.jsx(rce,{className:"rf-w-4 rf-h-4"})})},Fci=({solverEvents:t=[]})=>{const[e,n]=Z.useState(null);Pci();const o=Z.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=Z.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=Z.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=VPe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(VPe).join(", ")}`,classFound:!1};try{return{instance:new a(...Dci(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?z.jsx("div",{className:"rf-p-4",children:z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:z.jsxs("div",{className:"rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),z.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."})]})})}):z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const A=o.get(a),c=e===a;return z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=Nci(A.solverName);return z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?z.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[z.jsx(Tci,{solverEvent:r}),z.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:z.jsx(LS,{fallback:z.jsx("div",{className:"rf-p-4",children:z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:z.jsx(bci,{solver:s.instance})})})]}):z.jsxs("div",{className:"rf-p-4",children:[z.jsxs("div",{className:"rf-mb-4",children:[z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&z.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:z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[z.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(kci,{solverEvent:r}),z.jsx(ic,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>Lzt(r),children:z.jsx(XV,{className:"rf-w-4 rf-h-4"})})]})]}),z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Lci=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Hci=new Set(["tscircuit","default","auto","auto_local"]);function Gci(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function Oci(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&Lci.get(n);if(o)return o;if(n&&!Hci.has(n))return e;const i=t.solverName?.trim();if(i)return Gci(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const Tke="#fbbf24";function Uci(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function Hzt(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function Yci(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function Gzt(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...Yci(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function Kci(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(Hzt(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of Gzt(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:Tke,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:Tke,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function zci(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const Vci=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function Jci(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!Vci.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:Uci(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=Gzt(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${zci(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const kke=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,Ozt=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",Uzt=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,Wci={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},qci=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=Z.useState(null),[r,s]=Z.useState("output"),[a,A]=Z.useState(!0),[c,l]=Z.useState(!1),g=Z.useRef(null),[u,h]=Z.useState(480),d=o?e.findIndex(L=>L.id===o.id&&Uzt(L)===Uzt(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=Z.useMemo(()=>!p||!x?null:Jci(t??[],p,y),[t,p,x,y]),S=Z.useMemo(()=>p&&y==="output"&&a?Kci(p):{lines:[],circles:[]},[p,y,a]);if(Z.useLayoutEffect(()=>{const L=g.current;if(!L)return;const G=()=>h(Math.max(360,L.clientHeight));G();const O=new ResizeObserver(G);return O.observe(L),()=>O.disconnect()},[!!p]),!p)return z.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[z.jsx(_Gt,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),z.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),z.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const Q=kke(p,m),P=p.status==="running"&&n,w=!f,R=I?.connections.length,F=E?.filter(L=>L.type==="pcb_trace").length??0;return z.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[z.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[z.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[z.jsx("span",{children:"Routing phases"}),z.jsx("span",{children:e.length})]}),z.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:e.map((L,G)=>{const O=Hzt(L).length,K=L.endSimpleRouteJson?`${O} ${O===1?"trace":"traces"} routed`:L.status==="error"?"Failed":L.status==="running"&&n?"Routing…":"No output";return z.jsxs("button",{type:"button","aria-pressed":G===m,title:`${Ozt(L)} · ${K}`,onClick:()=>i(L),className:dr("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",G===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[z.jsx("span",{className:dr("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",G===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:G+1}),z.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[z.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:kke(L,G),children:kke(L,G)}),L.status==="complete"?z.jsx(jV,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):L.status==="error"?z.jsx(bRe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?z.jsx(AB,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),z.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[Oci(L)," · ",K]})]})]},L.id)})})]}),z.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[z.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[Q,z.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&z.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),z.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(L=>z.jsx("button",{type:"button","aria-pressed":y===L,disabled:L==="input"?!C:!f,onClick:()=>s(L),className:dr("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===L?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:L==="input"?"Input":"Output"},L))})]}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[z.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[z.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:L=>A(L.target.checked),className:"rf-accent-blue-600"}),z.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:Tke}}),"Highlight changes (all layers)"]}),z.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",F," traces"]})]}),w&&z.jsx("div",{className:dr("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:P?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),z.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?z.jsx(Qke,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:Wci,debugGraphics:S}):z.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),z.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[z.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${Ozt(p)}`]}),z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[z.jsxs("button",{type:"button",disabled:!x,onClick:()=>hB(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[z.jsx(XV,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),z.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[z.jsx(xL,{className:dr("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&z.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${Q} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},Yzt=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{Z.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{H8.captureException(o)}catch{}}},[t,e]),Z.useEffect(()=>{if(n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{H8.captureException(i,{error_type:o.type})}catch{}}},[n])},jci=t=>{Z.useEffect(()=>{try{Ftn(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},Kzt="0.0.2665",Xci={version:Kzt},Fke={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Lke=new Map,Nle=t=>{const e=Lke.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,o])=>[n,o.getState()])):{}},$ci=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const o=Lke.get(n.name);if(o)return{type:"tracked",store:t,...o};const i={connection:e.connect(n),stores:{}};return Lke.set(n.name,i),{type:"tracked",store:t,...i}},zzt=(t,e={})=>(n,o,i)=>{const{enabled:r,anonymousActionType:s,store:a,...A}=e;let c;try{c=(r??(Fke?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return(Fke?"production":void 0)!=="production"&&r&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,o,i);const{connection:l,...g}=$ci(a,c,A);let u=!0;i.setState=(m,p,_)=>{const f=n(m,p);if(!u)return f;const I=_===void 0?{type:s||"anonymous"}:typeof _=="string"?{type:_}:_;return a===void 0?(l?.send(I,o()),f):(l?.send({...I,type:`${a}/${I.type}`},{...Nle(A.name),[a]:i.getState()}),f)};const h=(...m)=>{const p=u;u=!1,n(...m),u=p},d=t(i.setState,o,i);if(g.type==="untracked"?l?.init(d):(g.stores[g.store]=i,l?.init(Object.fromEntries(Object.entries(g.stores).map(([m,p])=>[m,m===g.store?d:p.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const p=i.dispatch;i.dispatch=(..._)=>{(Fke?"production":void 0)!=="production"&&_[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),p(..._)}}return l.subscribe(m=>{var p;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Hke(m.payload,_=>{if(_.type==="__setState"){if(a===void 0){h(_.state);return}Object.keys(_.state).length!==1&&console.error(`
|
|
5772
5772
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5773
5773
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5774
5774
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|