@tscircuit/runframe 0.0.2994 → 0.0.2995

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.
@@ -2868,7 +2868,7 @@ var usePostHogActivity = (properties) => {
2868
2868
  };
2869
2869
 
2870
2870
  // package.json
2871
- var version = "0.0.2993";
2871
+ var version = "0.0.2994";
2872
2872
  var package_default = {
2873
2873
  name: "@tscircuit/runframe",
2874
2874
  main: "dist/preview.js",
@@ -2996,7 +2996,7 @@ var package_default = {
2996
2996
  },
2997
2997
  dependencies: {
2998
2998
  "@tscircuit/core": "^0.0.1911",
2999
- "@tscircuit/eval": "0.0.1618",
2999
+ "@tscircuit/eval": "0.0.1619",
3000
3000
  "@tscircuit/solver-utils": "^0.0.16",
3001
3001
  debug: "^4.4.0",
3002
3002
  "format-si-unit": "^0.0.12"
package/dist/preview.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  useOrderDialogCli,
11
11
  usePcbViewerController,
12
12
  useSchematicViewerController
13
- } from "./chunk-IQKVUBRN.js";
13
+ } from "./chunk-RHCSLXWV.js";
14
14
  export {
15
15
  BomTable,
16
16
  CadViewer,
package/dist/runner.d.ts CHANGED
@@ -174,6 +174,8 @@ declare global {
174
174
  var runFrameWorker: any;
175
175
  interface Window {
176
176
  TSCIRCUIT_USE_RUNFRAME_FOR_CLI?: boolean;
177
+ TSCIRCUIT_JLCSEARCH_BASE_URL?: string;
178
+ TSCIRCUIT_DATASHEET_API_BASE_URL?: string;
177
179
  }
178
180
  }
179
181
 
package/dist/runner.js CHANGED
@@ -43,7 +43,7 @@ import {
43
43
  useRunnerStore,
44
44
  useSchematicViewerController,
45
45
  useStyles
46
- } from "./chunk-IQKVUBRN.js";
46
+ } from "./chunk-RHCSLXWV.js";
47
47
 
48
48
  // lib/components/RunFrame/RunFrame.tsx
49
49
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -381,6 +381,11 @@ var RunFrame = (props) => {
381
381
  props.evalVersion,
382
382
  !globalThis.runFrameWorker && props.forceLatestEvalVersion
383
383
  );
384
+ const partsEngineOptions = {
385
+ jlcSearchBaseUrl: window.TSCIRCUIT_JLCSEARCH_BASE_URL,
386
+ datasheetApiBaseUrl: window.TSCIRCUIT_DATASHEET_API_BASE_URL
387
+ };
388
+ const hasPartsEngineBaseUrls = partsEngineOptions.jlcSearchBaseUrl !== void 0 || partsEngineOptions.datasheetApiBaseUrl !== void 0;
384
389
  const worker = globalThis.runFrameWorker ?? await createCircuitWebWorker({
385
390
  evalVersion,
386
391
  webWorkerBlobUrl: props.evalWebWorkerBlobUrl,
@@ -401,7 +406,8 @@ var RunFrame = (props) => {
401
406
  },
402
407
  ...props.easyEdaProxyConfig && {
403
408
  easyEdaProxyConfig: props.easyEdaProxyConfig
404
- }
409
+ },
410
+ ...hasPartsEngineBaseUrls && { partsEngineOptions }
405
411
  });
406
412
  return { worker, evalVersion };
407
413
  })();
@@ -5670,7 +5670,7 @@ test("${i} should solve problem correctly", () => {
5670
5670
  // Add more specific assertions based on expected output
5671
5671
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5672
5672
  })
5673
- `,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},jNI=g=>g.activeSubSolver?[g,...jNI(g.activeSubSolver)]:[g],LhB=({solver:g})=>{const A=jNI(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(PhB,{solver:I})]},I.getSolverName()))})},YhB=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:B,onDownloadVisualization:o,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.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"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="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":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.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(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="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":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.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:W.jsx("button",{type:"button",onClick:()=>{o(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="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":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.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:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{B(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(LhB,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.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"}),W.jsx("button",{onClick:w,disabled:g.solved||g.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"}),W.jsx("button",{onClick:u,disabled:g.solved||g.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"}),W.jsx("button",{onClick:G,disabled:g.solved||g.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},_hB=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),bhB=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},HhB=(g,A)=>{const e=g.pipelineDef[A].solverName,t=bhB(g,A),B=g[e],o=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&o!==null?Q=r-o:o!==null&&(Q=C-o)}else t==="In Progress"&&o!==null&&(Q=C-o);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&B&&(E=B.progress??0);const n=B?.stats??null;return{index:A,name:e,status:t,firstIteration:o,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:B??null}},vhB=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},qhB=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},zNI=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},ThB=g=>Object.entries(g).map(([A,I])=>`${A}: ${zNI(I)}`).join(", "),ZhB=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=ThB(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",zNI(t)]},e))})]})},Itg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(Itg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=Itg(e));return A},OhB=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=Itg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),B=document.createElement("a");B.href=t,B.download=`${A}_input.json`,B.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},WhB=({expanded:g})=>W.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 ${g?"rotate-90":""}`,children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),XNI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},$NI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:B})=>{const[o,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>HhB(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):OhB(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););B?.()}},a=()=>{if(!g.solved&&!g.failed){const h=XNI(g);for(;!g.solved&&!g.failed&&(g.step(),XNI(g)===h););B?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.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"}),W.jsx("button",{onClick:r,disabled:g.solved||g.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"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=_hB(h.solverInstance),D=o.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(WhB,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(vhB,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(qhB,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(ZhB,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx($NI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:B})})})]},h.name)})})]})})]})};function VhB({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],B=g.texts??[];let o=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<o&&(o=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of B)E(h.x,h.y);(!isFinite(o)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(o=-20,C=-20,Q=20,i=20);const n=10,s=o-n,r=C-n,a=Math.max(1,Q-o+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),B.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var jhB=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},zhB=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[B,o]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,B]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();o()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(YhB,{solver:C,triggerRender:o,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(jhB,{fallback:W.jsx(VhB,{graphics:s}),children:Q==="canvas"?W.jsx(KhB,{graphics:s}):W.jsx(xhB,{graphics:s})}),a&&W.jsx($NI,{solver:C,onStepUntilPhase:c,triggerRender:o})]})};const XhB=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},$hB=1e3,dk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),B=URL.createObjectURL(t),o=document.createElement("a");o.href=B,o.download=I,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(B)},$hB)},etg=g=>{let A=g.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(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},A0B=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},KF="https://github.com/tscircuit/tscircuit-autorouter/issues/new",A1I="https://github.com/tscircuit/copper-pour-solver/issues/new",g1I="https://github.com/tscircuit/calculate-packing/issues/new",g0B="https://github.com/tscircuit/matchpack/issues/new",I1I="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",I0B={PackSolver2:g1I,LayoutPipelineSolver:g0B,AutoroutingPipelineSolver:KF,AssignableAutoroutingPipeline2:KF,AssignableAutoroutingPipeline3:KF,AutoroutingPipeline1_OriginalUnravel:KF,AutoroutingPipelineSolver3_HgPortPointPathing:KF,AutoroutingPipelineSolver4:KF,AutoroutingPipelineSolver5:KF,AutoroutingPipelineSolver7_MultiGraph:KF,AutoroutingPipelineSolver8:KF,CopperPourPipelineSolver:A1I,SchematicTracePipelineSolver:I1I},e0B=g=>g.toLowerCase().includes("pack")?lBB:g.toLowerCase().includes("rout")?HSI:iBB,e1I=g=>{const A=I0B[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?KF:I.includes("schematic")&&I.includes("trace")?I1I:I.includes("copperpour")?A1I:I.includes("pack")?g1I:null},t0B=g=>`${etg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,t1I=g=>{dk(JSON.stringify(g.solverParams,null,2),{fileName:t0B(g),mimeType:"application/json"})},B0B=({solverEvent:g})=>{const A=e1I(g.solverName);return W.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:[W.jsxs(XE,{type:"button",variant:"outline",size:"sm",onClick:()=>t1I(g),children:[W.jsx(vIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(XE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(EwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(XE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(EwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},o0B=({solverEvent:g})=>{const A=e1I(g.solverName);return A?W.jsx(XE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(EwA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(XE,{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:W.jsx(EwA,{className:"rf-w-4 rf-h-4"})})},C0B=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);XhB();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),B=A?e.get(A):null,o=gA.useMemo(()=>{if(!B)return{instance:null,error:null,classFound:!1};const C=w6A[B.solverName];if(!C)return{instance:null,error:`Solver class "${B.solverName}" not found in SOLVERS registry. Available: ${Object.keys(w6A).join(", ")}`,classFound:!1};try{return{instance:new C(...A0B(B)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[B]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=e0B(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:B?o.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(B0B,{solverEvent:B}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",B.solverName]})]})}),children:W.jsx(zhB,{solver:o.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:B.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",B.componentName]})]}),o.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${o.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${o.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:o.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.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:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(o0B,{solverEvent:B}),W.jsx(XE,{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:()=>t1I(B),children:W.jsx(vIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(B.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Q0B=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),i0B=new Set(["tscircuit","default","auto","auto_local"]);function E0B(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function n0B(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&Q0B.get(I);if(e)return e;if(I&&!i0B.has(I))return A;const t=g.solverName?.trim();if(t)return E0B(t);const B=g.autorouterVersion?.trim();if(B){const o=B.match(/^beta[_-]pipeline(\d+)$/);return o?`Pipeline${o[1]}`:B==="latest"?"default":B}return A?"default":"Unknown"}const ttg="#fbbf24";function s0B(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(B=>B!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function B1I(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function a0B(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function o1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...a0B(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),B=[];let o=0;for(const[C,Q]of t)C>=o&&B.push(I.slice(o,C+1)),o=Math.max(o,Q);return o<I.length&&B.push(I.slice(o)),B}function r0B(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(B1I(g));for(const B of e.traces??[])if(t.has(B.pcb_trace_id))for(const o of o1I(B,e)){let C;for(const Q of o){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:ttg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:ttg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function c0B(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const h0B=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function l0B(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!h0B.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const B=I==="input"?e.traces??[]:s0B(A),o=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of B){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=o1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${c0B(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:o.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const Btg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,C1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",Q1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,D0B={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},d0B=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[B,o]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&Q1I(N)===Q1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=B==="output"&&!D?"input":B==="input"&&!y?"output":B,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:l0B(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?r0B(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const J=()=>r(Math.max(360,N.clientHeight));J();const P=new ResizeObserver(J);return P.observe(N),()=>P.disconnect()},[!!h]),!h)return W.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:[W.jsx(HSI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"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 p=Btg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return W.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:[W.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:[W.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:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.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:A.map((N,J)=>{const P=B1I(N).length,b=N.endSimpleRouteJson?`${P} ${P===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":J===c,title:`${C1I(N)} · ${b}`,onClick:()=>t(N),className:no("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",J===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:no("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",J===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:J+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.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:Btg(N,J),children:Btg(N,J)}),N.status==="complete"?W.jsx(HIA,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(aIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(b2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[n0B(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.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:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>o(N),className:no("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.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:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:ttg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&W.jsx("div",{className:no("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.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:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(EIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:D0B,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.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:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${C1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>dk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(vIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(vT,{className:no("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.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":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},i1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{n9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{n9.captureException(t,{error_type:e.type})}catch{}}},[I])},y0B=g=>{gA.useEffect(()=>{try{dVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},E1I="0.0.2993",w0B={version:E1I},otg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Ctg=new Map,SuA=g=>{const A=Ctg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},u0B=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=Ctg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return Ctg.set(I.name,t),{type:"tracked",store:g,...t}},n1I=(g,A={})=>(I,e,t)=>{const{enabled:B,anonymousActionType:o,store:C,...Q}=A;let i;try{i=(B??(otg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(otg?"production":void 0)!=="production"&&B&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=u0B(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:o||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...SuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(otg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Qtg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
5673
+ `,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:t,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},jNI=g=>g.activeSubSolver?[g,...jNI(g.activeSubSolver)]:[g],LhB=({solver:g})=>{const A=jNI(g);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>W.jsxs("div",{className:"flex items-center",children:[e>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(PhB,{solver:I})]},I.getSolverName()))})},YhB=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:B,onDownloadVisualization:o,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=gA.useReducer(m=>!m,!1),n=gA.useRef(void 0),s=gA.useRef(null),r="solver-debugger-last-iteration",[a,c]=gA.useState(null),h=gA.useRef(null),l=gA.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"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return gA.useEffect(()=>()=>{d()},[]),gA.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),gA.useEffect(()=>{i&&(d(),D())},[I,i]),gA.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[W.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="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":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&W.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(m=>W.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="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":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&W.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:W.jsx("button",{type:"button",onClick:()=>{o(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),W.jsxs("div",{className:"relative",children:[W.jsx("button",{type:"button",onClick:()=>c(a==="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":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&W.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:l.map(m=>W.jsxs("button",{type:"button",onClick:()=>{B(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,W.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&W.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),W.jsx(LhB,{solver:g})]})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:y,disabled:g.solved||g.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"}),W.jsx("button",{onClick:w,disabled:g.solved||g.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"}),W.jsx("button",{onClick:u,disabled:g.solved||g.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"}),W.jsx("button",{onClick:G,disabled:g.solved||g.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"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},_hB=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),bhB=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},HhB=(g,A)=>{const e=g.pipelineDef[A].solverName,t=bhB(g,A),B=g[e],o=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&o!==null?Q=r-o:o!==null&&(Q=C-o)}else t==="In Progress"&&o!==null&&(Q=C-o);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&B&&(E=B.progress??0);const n=B?.stats??null;return{index:A,name:e,status:t,firstIteration:o,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:B??null}},vhB=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[g]}`,children:g})},qhB=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},zNI=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},ThB=g=>Object.entries(g).map(([A,I])=>`${A}: ${zNI(I)}`).join(", "),ZhB=({stats:g})=>{if(!g||Object.keys(g).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(g),I=ThB(g);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>W.jsxs("div",{children:[e,": ",zNI(t)]},e))})]})},Itg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(Itg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=Itg(e));return A},OhB=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=Itg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),B=document.createElement("a");B.href=t,B.download=`${A}_input.json`,B.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},WhB=({expanded:g})=>W.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 ${g?"rotate-90":""}`,children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})}),XNI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},$NI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:B})=>{const[o,C]=gA.useState(new Set),Q=g.pipelineDef.map((h,l)=>HhB(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):OhB(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););B?.()}},a=()=>{if(!g.solved&&!g.failed){const h=XNI(g);for(;!g.solved&&!g.failed&&(g.step(),XNI(g)===h););B?.()}},c=t*24;return W.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&W.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),W.jsxs("div",{className:"flex gap-2",children:[W.jsx("button",{onClick:a,disabled:g.solved||g.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"}),W.jsx("button",{onClick:r,disabled:g.solved||g.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"})]})]}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[!e&&W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:Q.map(h=>{const l=_hB(h.solverInstance),D=o.has(h.name);return W.jsxs(nC.Fragment,{children:[W.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?W.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:W.jsx(WhB,{expanded:D})}):W.jsx("span",{className:"w-4"}),W.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(vhB,{status:h.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(qhB,{progress:h.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(ZhB,{stats:h.stats})}),W.jsx("td",{className:"px-4 py-2",children:h.solverInstance?W.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]}),l&&D&&W.jsx("tr",{children:W.jsx("td",{colSpan:8,className:"p-0",children:W.jsx($NI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:B})})})]},h.name)})})]})})]})};function VhB({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],B=g.texts??[];let o=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<o&&(o=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of B)E(h.x,h.y);(!isFinite(o)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(o=-20,C=-20,Q=20,i=20);const n=10,s=o-n,r=C-n,a=Math.max(1,Q-o+2*n),c=Math.max(1,i-C+2*n);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),B.map((h,l)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var jhB=class extends nC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},zhB=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[B,o]=gA.useReducer(D=>D+1,0),[C]=gA.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=gA.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=gA.useState(I),s=gA.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,B]),r=gA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);gA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),gA.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();o()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return W.jsxs("div",{children:[W.jsx(YhB,{solver:C,triggerRender:o,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(jhB,{fallback:W.jsx(VhB,{graphics:s}),children:Q==="canvas"?W.jsx(KhB,{graphics:s}):W.jsx(xhB,{graphics:s})}),a&&W.jsx($NI,{solver:C,onStepUntilPhase:c,triggerRender:o})]})};const XhB=()=>{gA.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},$hB=1e3,dk=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),B=URL.createObjectURL(t),o=document.createElement("a");o.href=B,o.download=I,o.target="_blank",o.rel="noopener noreferrer",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),setTimeout(()=>{URL.revokeObjectURL(B)},$hB)},etg=g=>{let A=g.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(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},A0B=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},KF="https://github.com/tscircuit/tscircuit-autorouter/issues/new",A1I="https://github.com/tscircuit/copper-pour-solver/issues/new",g1I="https://github.com/tscircuit/calculate-packing/issues/new",g0B="https://github.com/tscircuit/matchpack/issues/new",I1I="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",I0B={PackSolver2:g1I,LayoutPipelineSolver:g0B,AutoroutingPipelineSolver:KF,AssignableAutoroutingPipeline2:KF,AssignableAutoroutingPipeline3:KF,AutoroutingPipeline1_OriginalUnravel:KF,AutoroutingPipelineSolver3_HgPortPointPathing:KF,AutoroutingPipelineSolver4:KF,AutoroutingPipelineSolver5:KF,AutoroutingPipelineSolver7_MultiGraph:KF,AutoroutingPipelineSolver8:KF,CopperPourPipelineSolver:A1I,SchematicTracePipelineSolver:I1I},e0B=g=>g.toLowerCase().includes("pack")?lBB:g.toLowerCase().includes("rout")?HSI:iBB,e1I=g=>{const A=I0B[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?KF:I.includes("schematic")&&I.includes("trace")?I1I:I.includes("copperpour")?A1I:I.includes("pack")?g1I:null},t0B=g=>`${etg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,t1I=g=>{dk(JSON.stringify(g.solverParams,null,2),{fileName:t0B(g),mimeType:"application/json"})},B0B=({solverEvent:g})=>{const A=e1I(g.solverName);return W.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:[W.jsxs(XE,{type:"button",variant:"outline",size:"sm",onClick:()=>t1I(g),children:[W.jsx(vIA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?W.jsx(XE,{asChild:!0,variant:"outline",size:"sm",children:W.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[W.jsx(EwA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):W.jsxs(XE,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[W.jsx(EwA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},o0B=({solverEvent:g})=>{const A=e1I(g.solverName);return A?W.jsx(XE,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:W.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:W.jsx(EwA,{className:"rf-w-4 rf-h-4"})})}):W.jsx(XE,{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:W.jsx(EwA,{className:"rf-w-4 rf-h-4"})})},C0B=({solverEvents:g=[]})=>{const[A,I]=gA.useState(null);XhB();const e=gA.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=gA.useMemo(()=>Array.from(e.keys()),[e]),B=A?e.get(A):null,o=gA.useMemo(()=>{if(!B)return{instance:null,error:null,classFound:!1};const C=w6A[B.solverName];if(!C)return{instance:null,error:`Solver class "${B.solverName}" not found in SOLVERS registry. Available: ${Object.keys(w6A).join(", ")}`,classFound:!1};try{return{instance:new C(...A0B(B)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[B]);return g.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return W.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=e0B(Q.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:B?o.instance?W.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[W.jsx(B0B,{solverEvent:B}),W.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:W.jsx(SR,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",B.solverName]})]})}),children:W.jsx(zhB,{solver:o.instance})})})]}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:B.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",B.componentName]})]}),o.error&&W.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${o.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:W.jsx("p",{className:`rf-text-sm ${o.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:o.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.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:[W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(o0B,{solverEvent:B}),W.jsx(XE,{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:()=>t1I(B),children:W.jsx(vIA,{className:"rf-w-4 rf-h-4"})})]})]}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(B.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Q0B=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),i0B=new Set(["tscircuit","default","auto","auto_local"]);function E0B(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function n0B(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&Q0B.get(I);if(e)return e;if(I&&!i0B.has(I))return A;const t=g.solverName?.trim();if(t)return E0B(t);const B=g.autorouterVersion?.trim();if(B){const o=B.match(/^beta[_-]pipeline(\d+)$/);return o?`Pipeline${o[1]}`:B==="latest"?"default":B}return A?"default":"Unknown"}const ttg="#fbbf24";function s0B(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(B=>B!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function B1I(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function a0B(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function o1I(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...a0B(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),B=[];let o=0;for(const[C,Q]of t)C>=o&&B.push(I.slice(o,C+1)),o=Math.max(o,Q);return o<I.length&&B.push(I.slice(o)),B}function r0B(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(B1I(g));for(const B of e.traces??[])if(t.has(B.pcb_trace_id))for(const o of o1I(B,e)){let C;for(const Q of o){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:ttg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:ttg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function c0B(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const h0B=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function l0B(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!h0B.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const B=I==="input"?e.traces??[]:s0B(A),o=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of B){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=o1I(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${c0B(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:o.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const Btg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,C1I=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",Q1I=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,D0B={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},d0B=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=gA.useState(null),[B,o]=gA.useState("output"),[C,Q]=gA.useState(!0),[i,E]=gA.useState(!1),n=gA.useRef(null),[s,r]=gA.useState(480),a=e?A.findIndex(N=>N.id===e.id&&Q1I(N)===Q1I(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=B==="output"&&!D?"input":B==="input"&&!y?"output":B,u=w==="input"?d:h?.endSimpleRouteJson,G=gA.useMemo(()=>!h||!u?null:l0B(g??[],h,w),[g,h,u,w]),m=gA.useMemo(()=>h&&w==="output"&&C?r0B(h):{lines:[],circles:[]},[h,w,C]);if(gA.useLayoutEffect(()=>{const N=n.current;if(!N)return;const J=()=>r(Math.max(360,N.clientHeight));J();const P=new ResizeObserver(J);return P.observe(N),()=>P.disconnect()},[!!h]),!h)return W.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:[W.jsx(HSI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),W.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),W.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"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 p=Btg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return W.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:[W.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:[W.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:[W.jsx("span",{children:"Routing phases"}),W.jsx("span",{children:A.length})]}),W.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:A.map((N,J)=>{const P=B1I(N).length,b=N.endSimpleRouteJson?`${P} ${P===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return W.jsxs("button",{type:"button","aria-pressed":J===c,title:`${C1I(N)} · ${b}`,onClick:()=>t(N),className:no("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",J===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[W.jsx("span",{className:no("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",J===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:J+1}),W.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[W.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[W.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:Btg(N,J),children:Btg(N,J)}),N.status==="complete"?W.jsx(HIA,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?W.jsx(aIg,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?W.jsx(b2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),W.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[n0B(N)," · ",b]})]})]},N.id)})})]}),W.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[W.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:[W.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,W.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&W.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),W.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>W.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>o(N),className:no("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),W.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:[W.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),W.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:ttg}}),"Highlight changes (all layers)"]}),W.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&W.jsx("div",{className:no("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.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:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),W.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?W.jsx(EIg,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:D0B,debugGraphics:m}):W.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),W.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:[W.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${C1I(h)}`]}),W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[W.jsxs("button",{type:"button",disabled:!u,onClick:()=>dk(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[W.jsx(vIA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),W.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[W.jsx(vT,{className:no("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&W.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":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},i1I=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{n9.captureException(e)}catch{}}},[g,A]),gA.useEffect(()=>{if(wx("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{n9.captureException(t,{error_type:e.type})}catch{}}},[I])},y0B=g=>{gA.useEffect(()=>{try{dVI(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},E1I="0.0.2994",w0B={version:E1I},otg={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Ctg=new Map,SuA=g=>{const A=Ctg.get(g);return A?Object.fromEntries(Object.entries(A.stores).map(([I,e])=>[I,e.getState()])):{}},u0B=(g,A,I)=>{if(g===void 0)return{type:"untracked",connection:A.connect(I)};const e=Ctg.get(I.name);if(e)return{type:"tracked",store:g,...e};const t={connection:A.connect(I),stores:{}};return Ctg.set(I.name,t),{type:"tracked",store:g,...t}},n1I=(g,A={})=>(I,e,t)=>{const{enabled:B,anonymousActionType:o,store:C,...Q}=A;let i;try{i=(B??(otg?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return(otg?"production":void 0)!=="production"&&B&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),g(I,e,t);const{connection:E,...n}=u0B(C,i,Q);let s=!0;t.setState=(c,h,l)=>{const D=I(c,h);if(!s)return D;const d=l===void 0?{type:o||"anonymous"}:typeof l=="string"?{type:l}:l;return C===void 0?(E?.send(d,e()),D):(E?.send({...d,type:`${C}/${d.type}`},{...SuA(Q.name),[C]:t.getState()}),D)};const r=(...c)=>{const h=s;s=!1,I(...c),s=h},a=g(t.setState,e,t);if(n.type==="untracked"?E?.init(a):(n.stores[n.store]=t,E?.init(Object.fromEntries(Object.entries(n.stores).map(([c,h])=>[c,c===n.store?a:h.getState()])))),t.dispatchFromDevtools&&typeof t.dispatch=="function"){let c=!1;const h=t.dispatch;t.dispatch=(...l)=>{(otg?"production":void 0)!=="production"&&l[0].type==="__setState"&&!c&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),c=!0),h(...l)}}return E.subscribe(c=>{var h;switch(c.type){case"ACTION":if(typeof c.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Qtg(c.payload,l=>{if(l.type==="__setState"){if(C===void 0){r(l.state);return}Object.keys(l.state).length!==1&&console.error(`
5674
5674
  [zustand devtools middleware] Unsupported __setState action format.
5675
5675
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5676
5676
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }