@tscircuit/runframe 0.0.1503 → 0.0.1504

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.
@@ -1730,7 +1730,7 @@ var useErrorTelemetry = ({
1730
1730
  };
1731
1731
 
1732
1732
  // package.json
1733
- var version = "0.0.1502";
1733
+ var version = "0.0.1503";
1734
1734
  var package_default = {
1735
1735
  name: "@tscircuit/runframe",
1736
1736
  main: "dist/preview.js",
@@ -1802,7 +1802,7 @@ var package_default = {
1802
1802
  "circuit-json-to-bom-csv": "^0.0.8",
1803
1803
  "circuit-json-to-gerber": "^0.0.46",
1804
1804
  "circuit-json-to-gltf": "^0.0.56",
1805
- "circuit-json-to-kicad": "^0.0.34",
1805
+ "circuit-json-to-kicad": "^0.0.35",
1806
1806
  "circuit-json-to-lbrn": "^0.0.4",
1807
1807
  "circuit-json-to-pnp-csv": "^0.0.7",
1808
1808
  "circuit-json-to-step": "^0.0.13",
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  linkify,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-CWWWNEFE.js";
11
+ } from "./chunk-VUVKIGHG.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  useRunFrameStore,
35
35
  useRunnerStore,
36
36
  useStyles
37
- } from "./chunk-CWWWNEFE.js";
37
+ } from "./chunk-VUVKIGHG.js";
38
38
 
39
39
  // lib/components/RunFrame/RunFrame.tsx
40
40
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5615,7 +5615,7 @@ test("${g} should solve problem correctly", () => {
5615
5615
  // Add more specific assertions based on expected output
5616
5616
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5617
5617
  })
5618
- `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),C=document.createElement("a");C.href=B,C.download=`${g}.test.ts`,C.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return V.jsxs("div",{className:`relative ${A}`,ref:o,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&V.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:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Fee=t=>t.activeSubSolver?[t,...Fee(t.activeSubSolver)]:[t],GYt=({solver:t})=>{const A=Fee(t);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>V.jsxs("div",{className:"flex items-center",children:[i>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(kYt,{solver:e})]},e.constructor.name))})},FYt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=$.useReducer(Q=>!Q,!1),r=$.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};$.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),$.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const C=t.getCurrentPhase!==void 0,l=C?t.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(GYt,{solver:t})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),V.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),V.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),V.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,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"}),C&&V.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),l&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:l})]}),t.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},RYt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},MYt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=RYt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],C=B?t.firstIterationOfPhase?.[B.solverName]:void 0;C!==void 0&&s!==null?a=C-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},NYt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${A[t]}`,children:t})},_Yt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},vYt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),UYt=({stats:t})=>{if(!t||Object.keys(t).length===0)return V.jsx("span",{children:"-"});const A=Object.entries(t),e=vYt(t);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),V.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>V.jsxs("div",{children:[i,": ",String(o)]},i))})]})},thA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(thA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=thA(i));return A},LYt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=thA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},HYt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>MYt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):LYt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:i.map(r=>V.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>o(r.name),disabled:r.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 ${r.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(NYt,{status:r.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(_Yt,{progress:r.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx(UYt,{stats:r.stats})}),V.jsx("td",{className:"px-4 py-2",children:r.solverInstance?V.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})}),V.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},YYt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function JYt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,C=r-c,l=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${C} ${l} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>V.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>V.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>V.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var TYt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=$.useReducer(I=>I+1,0),s=$.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=$.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);$.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return V.jsxs("div",{children:[V.jsx(FYt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(YYt,{fallback:V.jsx(JYt,{graphics:s}),children:V.jsx(xYt,{graphics:s})}),a&&V.jsx(HYt,{solver:t,onStepUntilPhase:g})]})};const KYt=()=>{$.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},qYt=t=>t.toLowerCase().includes("pack")?Twt:t.toLowerCase().includes("rout")?Zwt:Mwt,PYt=({solverEvents:t=[]})=>{const[A,e]=$.useState(null);KYt();const i=$.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=$.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=$.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=ViA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ViA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.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."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=qYt(a.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?V.jsx(Km,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:V.jsx(TYt,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&V.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:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Ree=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{$.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{wT.captureException(i)}catch{}}},[t,A]),$.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{wT.captureException(o,{error_type:i.type})}catch{}}},[e])},Mee="0.0.1502",OYt={version:Mee},ihA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},ohA=new Map,XW=t=>{const A=ohA.get(t);return A?Object.fromEntries(Object.entries(A.stores).map(([e,i])=>[e,i.getState()])):{}},WYt=(t,A,e)=>{if(t===void 0)return{type:"untracked",connection:A.connect(e)};const i=ohA.get(e.name);if(i)return{type:"tracked",store:t,...i};const o={connection:A.connect(e),stores:{}};return ohA.set(e.name,o),{type:"tracked",store:t,...o}},Nee=(t,A={})=>(e,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(ihA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(ihA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(e,i,o);const{connection:I,...c}=WYt(r,g,a);let B=!0;o.setState=(Q,E,h)=>{const u=e(Q,E);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...XW(a.name),[r]:o.getState()}),u)};const C=(...Q)=>{const E=B;B=!1,e(...Q),B=E},l=t(o.setState,i,o);if(c.type==="untracked"?I?.init(l):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([Q,E])=>[Q,Q===c.store?l:E.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let Q=!1;const E=o.dispatch;o.dispatch=(...h)=>{(ihA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),E(...h)}}return I.subscribe(Q=>{var E;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return nhA(Q.payload,h=>{if(h.type==="__setState"){if(r===void 0){C(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5618
+ `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),C=document.createElement("a");C.href=B,C.download=`${g}.test.ts`,C.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return V.jsxs("div",{className:`relative ${A}`,ref:o,children:[V.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&V.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:[V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),V.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Fee=t=>t.activeSubSolver?[t,...Fee(t.activeSubSolver)]:[t],GYt=({solver:t})=>{const A=Fee(t);return V.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>V.jsxs("div",{className:"flex items-center",children:[i>0&&V.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),V.jsx(kYt,{solver:e})]},e.constructor.name))})},FYt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=$.useReducer(Q=>!Q,!1),r=$.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};$.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),$.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const C=t.getCurrentPhase!==void 0,l=C?t.getCurrentPhase():null;return V.jsxs("div",{className:"space-y-2 p-2 border-b",children:[V.jsx("div",{className:"flex items-center",children:V.jsx(GYt,{solver:t})}),V.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[V.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),V.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),V.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),V.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,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"}),C&&V.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),V.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),l&&V.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",V.jsx("span",{className:"font-medium",children:l})]}),t.solved&&V.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&V.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&V.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},RYt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},MYt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=RYt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],C=B?t.firstIterationOfPhase?.[B.solverName]:void 0;C!==void 0&&s!==null?a=C-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},NYt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return V.jsx("span",{className:`font-medium ${A[t]}`,children:t})},_Yt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:V.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),V.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},vYt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),UYt=({stats:t})=>{if(!t||Object.keys(t).length===0)return V.jsx("span",{children:"-"});const A=Object.entries(t),e=vYt(t);return V.jsxs("details",{className:"cursor-pointer",children:[V.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),V.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>V.jsxs("div",{children:[i,": ",String(o)]},i))})]})},thA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(thA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=thA(i));return A},LYt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=thA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},HYt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>MYt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):LYt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return V.jsxs("div",{className:"border-t border-gray-200",children:[V.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:V.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),V.jsx("div",{className:"overflow-x-auto",children:V.jsxs("table",{className:"w-full text-sm",children:[V.jsx("thead",{children:V.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),V.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",V.jsx("sub",{children:"0"})]}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),V.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),V.jsx("tbody",{children:i.map(r=>V.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[V.jsx("td",{className:"px-4 py-2",children:V.jsxs("div",{className:"flex items-center gap-2",children:[V.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),V.jsx("button",{onClick:()=>o(r.name),disabled:r.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 ${r.name} completes`,children:V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})})}),V.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(NYt,{status:r.status})}),V.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),V.jsx("td",{className:"px-4 py-2",children:V.jsx(_Yt,{progress:r.progress})}),V.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),V.jsx("td",{className:"px-4 py-2 text-gray-500",children:V.jsx(UYt,{stats:r.stats})}),V.jsx("td",{className:"px-4 py-2",children:r.solverInstance?V.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[V.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:V.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"})}),V.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},YYt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function JYt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,C=r-c,l=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return V.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${C} ${l} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>V.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>V.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>V.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>V.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var TYt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=$.useReducer(I=>I+1,0),s=$.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=$.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);$.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return V.jsxs("div",{children:[V.jsx(FYt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?V.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):V.jsx(YYt,{fallback:V.jsx(JYt,{graphics:s}),children:V.jsx(xYt,{graphics:s})}),a&&V.jsx(HYt,{solver:t,onStepUntilPhase:g})]})};const KYt=()=>{$.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},qYt=t=>t.toLowerCase().includes("pack")?Twt:t.toLowerCase().includes("rout")?Zwt:Mwt,PYt=({solverEvents:t=[]})=>{const[A,e]=$.useState(null);KYt();const i=$.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=$.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=$.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=ViA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ViA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?V.jsx("div",{className:"rf-p-4",children:V.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:V.jsxs("div",{className:"rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),V.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."})]})})}):V.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[V.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[V.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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return V.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=qYt(a.solverName);return V.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[V.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),V.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[V.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),V.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),V.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?V.jsx(Km,{fallback:V.jsx("div",{className:"rf-p-4",children:V.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),V.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:V.jsx(TYt,{solver:s.instance})}):V.jsxs("div",{className:"rf-p-4",children:[V.jsxs("div",{className:"rf-mb-4",children:[V.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),V.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&V.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:V.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),V.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[V.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:V.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),V.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:V.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):V.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:V.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Ree=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{$.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{wT.captureException(i)}catch{}}},[t,A]),$.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{wT.captureException(o,{error_type:i.type})}catch{}}},[e])},Mee="0.0.1503",OYt={version:Mee},ihA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},ohA=new Map,XW=t=>{const A=ohA.get(t);return A?Object.fromEntries(Object.entries(A.stores).map(([e,i])=>[e,i.getState()])):{}},WYt=(t,A,e)=>{if(t===void 0)return{type:"untracked",connection:A.connect(e)};const i=ohA.get(e.name);if(i)return{type:"tracked",store:t,...i};const o={connection:A.connect(e),stores:{}};return ohA.set(e.name,o),{type:"tracked",store:t,...o}},Nee=(t,A={})=>(e,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(ihA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(ihA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(e,i,o);const{connection:I,...c}=WYt(r,g,a);let B=!0;o.setState=(Q,E,h)=>{const u=e(Q,E);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...XW(a.name),[r]:o.getState()}),u)};const C=(...Q)=>{const E=B;B=!1,e(...Q),B=E},l=t(o.setState,i,o);if(c.type==="untracked"?I?.init(l):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([Q,E])=>[Q,Q===c.store?l:E.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let Q=!1;const E=o.dispatch;o.dispatch=(...h)=>{(ihA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!Q&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),Q=!0),E(...h)}}return I.subscribe(Q=>{var E;switch(Q.type){case"ACTION":if(typeof Q.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return nhA(Q.payload,h=>{if(h.type==="__setState"){if(r===void 0){C(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5619
5619
  [zustand devtools middleware] Unsupported __setState action format.
5620
5620
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5621
5621
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
@@ -5757,7 +5757,7 @@ ${a.join(`
5757
5757
  `)}};NA.register(yre);var eV=class dle extends NA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const e=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):fE(i));return new dle(e)}get names(){return[...this._names]}set names(A){this._names=A.map(e=>String(e))}getString(){return`(layers ${this._names.map(e=>/^[^\s()"]+$/u.test(e)&&!["nil","#t","#f"].includes(e)?e:ro(e)).join(" ")})`}};NA.register(eV);var uY=class extends NA{_value;quoteStringValue=!1;constructor(t){super(),this._value=t}static fromSexprPrimitives(t){const[A]=t,e=this.parsePrimitiveValue(A),i=this;return new i(e)}static parsePrimitiveValue(t){const A=Ei(t);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(t){this._value=t}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?ro(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},NZt=class extends NA{_values;constructor(t){super(),this._values=t}static fromSexprPrimitives(t){const A=t.map(i=>{const o=si(i);if(o===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return o}),e=this;return new e(A)}get values(){return[...this._values]}set values(t){this._values=[...t]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},_Zt=class extends NA{_x;_y;constructor(t,A){super(),this._x=t,this._y=A}static fromSexprPrimitives(t){const[A,e]=t,i=si(A),o=si(e);if(i===void 0||o===void 0)throw new Error(`${this.name} expects two numeric values`);const n=this;return new n(i,o)}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},ur=class extends uY{static parentToken="pcbplotparams"},My=class extends ur{static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},wre=class extends ur{static token="layerselection";token="layerselection"};NA.register(wre);var mre=class extends ur{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};NA.register(mre);var Dre=class extends My{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};NA.register(Dre);var Sre=class extends My{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};NA.register(Sre);var bre=class extends My{static token="svgprecision";token="svgprecision"};NA.register(bre);var xre=class extends My{static token="linewidth";token="linewidth"};NA.register(xre);var kre=class extends My{static token="mode";token="mode"};NA.register(kre);var Gre=class extends My{static token="hpglpennumber";token="hpglpennumber"};NA.register(Gre);var Fre=class extends My{static token="hpglpenspeed";token="hpglpenspeed"};NA.register(Fre);var Rre=class extends My{static token="hpglpendiameter";token="hpglpendiameter"};NA.register(Rre);var Mre=class extends My{static token="hpglpenoverlay";token="hpglpenoverlay"};NA.register(Mre);var Nre=class extends My{static token="outputformat";token="outputformat"};NA.register(Nre);var _re=class extends My{static token="drillshape";token="drillshape"};NA.register(_re);var vre=class extends My{static token="scaleselection";token="scaleselection"};NA.register(vre);var Ure=class extends ur{static token="disableapertmacros";token="disableapertmacros"};NA.register(Ure);var Lre=class extends ur{static token="usegerberextensions";token="usegerberextensions"};NA.register(Lre);var Hre=class extends ur{static token="usegerberattributes";token="usegerberattributes"};NA.register(Hre);var Yre=class extends ur{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};NA.register(Yre);var Jre=class extends ur{static token="creategerberjobfile";token="creategerberjobfile"};NA.register(Jre);var Tre=class extends ur{static token="excludeedgelayer";token="excludeedgelayer"};NA.register(Tre);var Kre=class extends ur{static token="plotframeref";token="plotframeref"};NA.register(Kre);var qre=class extends ur{static token="viasonmask";token="viasonmask"};NA.register(qre);var Pre=class extends ur{static token="useauxorigin";token="useauxorigin"};NA.register(Pre);var Ore=class extends ur{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};NA.register(Ore);var Wre=class extends ur{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};NA.register(Wre);var Zre=class extends ur{static token="pdf_metadata";token="pdf_metadata"};NA.register(Zre);var Vre=class extends ur{static token="pdf_single_document";token="pdf_single_document"};NA.register(Vre);var jre=class extends ur{static token="dxfpolygonmode";token="dxfpolygonmode"};NA.register(jre);var zre=class extends ur{static token="dxfimperialunits";token="dxfimperialunits"};NA.register(zre);var Xre=class extends ur{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};NA.register(Xre);var $re=class extends ur{static token="psnegative";token="psnegative"};NA.register($re);var Aae=class extends ur{static token="psa4output";token="psa4output"};NA.register(Aae);var eae=class extends ur{static token="plotreference";token="plotreference"};NA.register(eae);var tae=class extends ur{static token="plotvalue";token="plotvalue"};NA.register(tae);var iae=class extends ur{static token="plotothertext";token="plotothertext"};NA.register(iae);var oae=class extends ur{static token="plotinvisibletext";token="plotinvisibletext"};NA.register(oae);var nae=class extends ur{static token="padsonsilk";token="padsonsilk"};NA.register(nae);var sae=class extends ur{static token="sketchpadsonfab";token="sketchpadsonfab"};NA.register(sae);var rae=class extends ur{static token="plotpadnumbers";token="plotpadnumbers"};NA.register(rae);var aae=class extends ur{static token="hidednponfab";token="hidednponfab"};NA.register(aae);var gae=class extends ur{static token="sketchdnponfab";token="sketchdnponfab"};NA.register(gae);var Iae=class extends ur{static token="crossoutdnponfab";token="crossoutdnponfab"};NA.register(Iae);var cae=class extends ur{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};NA.register(cae);var Bae=class extends ur{static token="plot_black_and_white";token="plot_black_and_white"};NA.register(Bae);var Cae=class extends ur{static token="mirror";token="mirror"};NA.register(Cae);var lae=class extends ur{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};NA.register(lae);var Qae=class extends ur{static token="plot_on_all_layers";token="plot_on_all_layers"};NA.register(Qae);var Eae=class extends ur{static token="plotinvisible";token="plotinvisible"};NA.register(Eae);var vZt={layerselection:"layerselection",plot_on_all_layers_selection:"plot_on_all_layers_selection",disableapertmacros:"disableapertmacros",usegerberextensions:"usegerberextensions",usegerberattributes:"usegerberattributes",usegerberadvancedattributes:"usegerberadvancedattributes",creategerberjobfile:"creategerberjobfile",excludeedgelayer:"excludeedgelayer",dashed_line_dash_ratio:"dashed_line_dash_ratio",dashed_line_gap_ratio:"dashed_line_gap_ratio",svgprecision:"svgprecision",linewidth:"linewidth",plotframeref:"plotframeref",plotreference:"plotreference",plotvalue:"plotvalue",plotothertext:"plotothertext",plotinvisibletext:"plotinvisibletext",padsonsilk:"padsonsilk",sketchpadsonfab:"sketchpadsonfab",plotpadnumbers:"plotpadnumbers",hidednponfab:"hidednponfab",sketchdnponfab:"sketchdnponfab",crossoutdnponfab:"crossoutdnponfab",subtractmaskfromsilk:"subtractmaskfromsilk",plot_black_and_white:"plot_black_and_white",plot_on_all_layers:"plot_on_all_layers",plotinvisible:"plotinvisible",mode:"mode",useauxorigin:"useauxorigin",viasonmask:"viasonmask",hpglpennumber:"hpglpennumber",hpglpenspeed:"hpglpenspeed",hpglpendiameter:"hpglpendiameter",hpglpenoverlay:"hpglpenoverlay",pdf_front_fp_property_popups:"pdf_front_fp_property_popups",pdf_back_fp_property_popups:"pdf_back_fp_property_popups",pdf_metadata:"pdf_metadata",pdf_single_document:"pdf_single_document",dxfpolygonmode:"dxfpolygonmode",dxfimperialunits:"dxfimperialunits",dxfusepcbnewfont:"dxfusepcbnewfont",psnegative:"psnegative",psa4output:"psa4output",mirror:"mirror",outputformat:"outputformat",drillshape:"drillshape",scaleselection:"scaleselection",outputdirectory:"outputdirectory"},UZt=["layerselection","plot_on_all_layers_selection","disableapertmacros","usegerberextensions","usegerberattributes","usegerberadvancedattributes","creategerberjobfile","excludeedgelayer","dashed_line_dash_ratio","dashed_line_gap_ratio","svgprecision","linewidth","plotframeref","plotreference","plotvalue","plotothertext","mode","useauxorigin","viasonmask","hpglpennumber","hpglpenspeed","hpglpendiameter","hpglpenoverlay","pdf_front_fp_property_popups","pdf_back_fp_property_popups","pdf_metadata","pdf_single_document","dxfpolygonmode","dxfimperialunits","dxfusepcbnewfont","psnegative","psa4output","plot_black_and_white","plot_on_all_layers","plotinvisible","plotinvisibletext","padsonsilk","sketchpadsonfab","plotpadnumbers","hidednponfab","sketchdnponfab","crossoutdnponfab","subtractmaskfromsilk","outputformat","mirror","drillshape","scaleselection","outputdirectory"],zpA=class ple extends NA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const e=new ple,{propertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);for(const[o,n]of Object.entries(i)){const s=vZt[o];if(!s)throw new Error(`Unsupported pcbplotparams token: ${o}`);e._properties[s]=n}return e}getChildren(){const A=[];for(const e of UZt){const i=this._properties[e];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}setNumberProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}setStringOrNumberProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,wre)}get plot_on_all_layers_selection(){return this._properties.plot_on_all_layers_selection?.value}set plot_on_all_layers_selection(A){this.setStringOrNumberProperty("plot_on_all_layers_selection",A,mre)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,Ure)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,Lre)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,Hre)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,Yre)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,Jre)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,Tre)}get dashed_line_dash_ratio(){return this._properties.dashed_line_dash_ratio?.value}set dashed_line_dash_ratio(A){this.setNumberProperty("dashed_line_dash_ratio",A,Dre)}get dashed_line_gap_ratio(){return this._properties.dashed_line_gap_ratio?.value}set dashed_line_gap_ratio(A){this.setNumberProperty("dashed_line_gap_ratio",A,Sre)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,bre)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,xre)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,Kre)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,eae)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,tae)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,iae)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,oae)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,nae)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,rae)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,sae)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,aae)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,gae)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,Iae)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,cae)}get plot_black_and_white(){return this._properties.plot_black_and_white?.value}set plot_black_and_white(A){this.setStringProperty("plot_black_and_white",A,Bae)}get plot_on_all_layers(){return this._properties.plot_on_all_layers?.value}set plot_on_all_layers(A){this.setStringProperty("plot_on_all_layers",A,Qae)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,Eae)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,kre)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,Pre)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,qre)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,Gre)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,Fre)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,Rre)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,Mre)}get pdf_front_fp_property_popups(){return this._properties.pdf_front_fp_property_popups?.value}set pdf_front_fp_property_popups(A){this.setStringProperty("pdf_front_fp_property_popups",A,Ore)}get pdf_back_fp_property_popups(){return this._properties.pdf_back_fp_property_popups?.value}set pdf_back_fp_property_popups(A){this.setStringProperty("pdf_back_fp_property_popups",A,Wre)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,Zre)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,Vre)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,jre)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,zre)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,Xre)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,$re)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,Aae)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,Cae)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,Nre)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,_re)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,vre)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,lae)}};NA.register(zpA);var tV=class extends uY{static parentToken="setup"},XpA=class extends tV{static token="zone_45_only";token="zone_45_only"};NA.register(XpA);var $pA=class extends tV{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};NA.register($pA);var AfA=class extends tV{static token="visible_elements";token="visible_elements"};NA.register(AfA);var efA=class extends tV{static token="uvias_allowed";token="uvias_allowed"};NA.register(efA);var tfA=class fle extends NA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const e=A.map(i=>Ei(i)).filter(i=>i!==void 0);return new fle(e)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(e=>String(e))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};NA.register(tfA);var dY=class extends NZt{static parentToken="setup"},hae=class extends _Zt{static parentToken="setup"},ifA=class extends dY{static token="pcb_text_size";token="pcb_text_size"};NA.register(ifA);var ofA=class extends dY{static token="mod_text_size";token="mod_text_size"};NA.register(ofA);var nfA=class extends dY{static token="pad_size";token="pad_size"};NA.register(nfA);var sfA=class extends dY{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};NA.register(sfA);var rfA=class extends dY{static token="trace_width";token="trace_width"};NA.register(rfA);var afA=class extends hae{static token="aux_axis_origin";token="aux_axis_origin"};NA.register(afA);var gfA=class extends hae{static token="grid_origin";token="grid_origin"};NA.register(gfA);var eC=class extends uY{static parentToken="setup";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},IfA=class extends eC{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};NA.register(IfA);var cfA=class extends eC{static token="solder_mask_min_width";token="solder_mask_min_width"};NA.register(cfA);var BfA=class extends eC{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};NA.register(BfA);var CfA=class extends eC{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};NA.register(CfA);var lfA=class extends eC{static token="last_trace_width";token="last_trace_width"};NA.register(lfA);var QfA=class extends eC{static token="trace_clearance";token="trace_clearance"};NA.register(QfA);var EfA=class extends eC{static token="zone_clearance";token="zone_clearance"};NA.register(EfA);var hfA=class extends eC{static token="trace_min";token="trace_min"};NA.register(hfA);var ufA=class extends eC{static token="segment_width";token="segment_width"};NA.register(ufA);var dfA=class extends eC{static token="edge_width";token="edge_width"};NA.register(dfA);var pfA=class extends eC{static token="via_size";token="via_size"};NA.register(pfA);var ffA=class extends eC{static token="via_drill";token="via_drill"};NA.register(ffA);var yfA=class extends eC{static token="via_min_size";token="via_min_size"};NA.register(yfA);var wfA=class extends eC{static token="via_min_drill";token="via_min_drill"};NA.register(wfA);var mfA=class extends eC{static token="uvia_size";token="uvia_size"};NA.register(mfA);var DfA=class extends eC{static token="uvia_drill";token="uvia_drill"};NA.register(DfA);var SfA=class extends eC{static token="uvia_min_size";token="uvia_min_size"};NA.register(SfA);var bfA=class extends eC{static token="uvia_min_drill";token="uvia_min_drill"};NA.register(bfA);var xfA=class extends eC{static token="pcb_text_width";token="pcb_text_width"};NA.register(xfA);var kfA=class extends eC{static token="mod_edge_width";token="mod_edge_width"};NA.register(kfA);var GfA=class extends eC{static token="mod_text_width";token="mod_text_width"};NA.register(GfA);var FfA=class extends eC{static token="pad_drill";token="pad_drill"};NA.register(FfA);var pY=class extends uY{static parentToken="stackup"},uae=class extends pY{static token="copper_finish";token="copper_finish";quoteStringValue=!0};NA.register(uae);var dae=class extends pY{static token="dielectric_constraints";token="dielectric_constraints"};NA.register(dae);var pae=class extends pY{static token="edge_connector";token="edge_connector"};NA.register(pae);var fae=class extends pY{static token="castellated_pads";token="castellated_pads"};NA.register(fae);var yae=class extends pY{static token="edge_plating";token="edge_plating"};NA.register(yae);var pv=class extends uY{static parentToken="layer"},RfA=class extends pv{static token="type";token="type";quoteStringValue=!0};NA.register(RfA);var MfA=class extends pv{static token="color";token="color";quoteStringValue=!0};NA.register(MfA);var NfA=class extends pv{static token="thickness";token="thickness";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};NA.register(NfA);var _fA=class extends pv{static token="material";token="material";quoteStringValue=!0};NA.register(_fA);var vfA=class extends pv{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};NA.register(vfA);var UfA=class extends pv{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};NA.register(UfA);var wae=class yle extends NA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,e={}){super(),this._name=A,this._number=e.number,this._sxType=e.type,this._sxColor=e.color,this._sxThickness=e.thickness,this._sxMaterial=e.material,this._sxEpsilonR=e.epsilonR,this._sxLossTangent=e.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const e=Ei(A[0]);if(e===void 0)throw new Error("Stackup layer name must be a string");let i=1,o;const n=A[i],s=si(n);s!==void 0&&(o=s,i+=1);const r=A.slice(i),{propertyMap:a}=NA.parsePrimitivesToClassProperties(r,this.token);return new yle(e,{number:o,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const e=Ei(A);if(e===void 0)throw new Error("Stackup layer name must be a string");this._name=e}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const e=si(A);if(e===void 0)throw new Error("Stackup layer number must be numeric");this._number=e}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof RfA?A:new RfA(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof MfA?A:new MfA(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof NfA?A:new NfA(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof _fA?A:new _fA(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof vfA?A:new vfA(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof UfA?A:new UfA(A)}getChildren(){const A=[];return this._sxType&&A.push(this._sxType),this._sxColor&&A.push(this._sxColor),this._sxThickness&&A.push(this._sxThickness),this._sxMaterial&&A.push(this._sxMaterial),this._sxEpsilonR&&A.push(this._sxEpsilonR),this._sxLossTangent&&A.push(this._sxLossTangent),A}getString(){const A=`(layer ${ro(this._name)}${this._number!==void 0?` ${this._number}`:""}`,e=this.getChildren();if(e.length===0)return`${A})`;const i=[A];for(const o of e)i.push(o.getStringIndented());return i.push(")"),i.join(`
5758
5758
  `)}};NA.register(wae);var LfA=class wle extends NA{static token="stackup";static parentToken="setup";token="stackup";_layers=[];_sxCopperFinish;_sxDielectricConstraints;_sxEdgeConnector;_sxCastellatedPads;_sxEdgePlating;constructor(A={}){super(),this.layers=A.layers??[],this._sxCopperFinish=A.copperFinish,this._sxDielectricConstraints=A.dielectricConstraints,this._sxEdgeConnector=A.edgeConnector,this._sxCastellatedPads=A.castellatedPads,this._sxEdgePlating=A.edgePlating}static fromSexprPrimitives(A){const{propertyMap:e,arrayPropertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);return new wle({layers:i.layer??[],copperFinish:e.copper_finish,dielectricConstraints:e.dielectric_constraints,edgeConnector:e.edge_connector,castellatedPads:e.castellated_pads,edgePlating:e.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(e=>{if(!(e instanceof wae))throw new Error("Stackup layers must be StackupLayer instances");return e})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new uae(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new dae(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new pae(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new fae(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new yae(A):void 0}getChildren(){const A=[...this._layers],e=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of e)i&&A.push(i);return A}};NA.register(LfA);var LZt={stackup:"stackup",pcbplotparams:"pcbPlotParams",pad_to_mask_clearance:"padToMaskClearance",solder_mask_min_width:"solderMaskMinWidth",pad_to_paste_clearance:"padToPasteClearance",pad_to_paste_clearance_ratio:"padToPasteClearanceRatio",last_trace_width:"lastTraceWidth",trace_clearance:"traceClearance",zone_clearance:"zoneClearance",zone_45_only:"zone45Only",trace_min:"traceMin",segment_width:"segmentWidth",edge_width:"edgeWidth",via_size:"viaSize",via_drill:"viaDrill",via_min_size:"viaMinSize",via_min_drill:"viaMinDrill",uvias_allowed:"uviasAllowed",uvia_size:"uviaSize",uvia_drill:"uviaDrill",uvia_min_size:"uviaMinSize",uvia_min_drill:"uviaMinDrill",pcb_text_width:"pcbTextWidth",pcb_text_size:"pcbTextSize",mod_edge_width:"modEdgeWidth",mod_text_size:"modTextSize",mod_text_width:"modTextWidth",pad_size:"padSize",pad_drill:"padDrill",allow_soldermask_bridges_in_footprints:"allowSoldermaskBridgesInFootprints",tenting:"tenting",aux_axis_origin:"auxAxisOrigin",grid_origin:"gridOrigin",visible_elements:"visibleElements",pad_to_paste_clearance_values:"padToPasteClearanceValues",trace_width:"traceWidth"},HZt=["stackup","padToMaskClearance","solderMaskMinWidth","padToPasteClearance","padToPasteClearanceRatio","lastTraceWidth","traceClearance","zoneClearance","zone45Only","traceMin","segmentWidth","edgeWidth","viaSize","viaDrill","viaMinSize","viaMinDrill","uviaSize","uviaDrill","uviasAllowed","uviaMinSize","uviaMinDrill","pcbTextWidth","pcbTextSize","modEdgeWidth","modTextSize","modTextWidth","padSize","padDrill","allowSoldermaskBridgesInFootprints","tenting","auxAxisOrigin","gridOrigin","visibleElements","padToPasteClearanceValues","traceWidth","pcbPlotParams"],HfA=class mle extends NA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const e=new mle,{propertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);for(const[o,n]of Object.entries(i)){const s=LZt[o];if(!s)throw new Error(`Unsupported setup property token: ${o}`);e._properties[s]=n}return e}getChildren(){const A=[];for(const e of HZt){const i=this._properties[e];i&&A.push(i)}return A}setProperty(A,e){if(e){this._properties[A]=e;return}delete this._properties[A]}setNumberProperty(A,e,i){if(e===void 0){delete this._properties[A];return}this._properties[A]=new i(e)}getPropertyInstance(A,e){const i=this._properties[A];return i instanceof e?i:void 0}get stackup(){return this.getPropertyInstance("stackup",LfA)}set stackup(A){if(A!==void 0&&!(A instanceof LfA))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",zpA)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof zpA))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",IfA)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,IfA)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",cfA)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,cfA)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",BfA)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,BfA)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",CfA)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,CfA)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",lfA)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,lfA)}get traceClearance(){return this.getPropertyInstance("traceClearance",QfA)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,QfA)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",EfA)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,EfA)}get zone45Only(){return this.getPropertyInstance("zone45Only",XpA)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new XpA(A))}get traceMin(){return this.getPropertyInstance("traceMin",hfA)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,hfA)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",ufA)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,ufA)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",dfA)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,dfA)}get viaSize(){return this.getPropertyInstance("viaSize",pfA)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,pfA)}get viaDrill(){return this.getPropertyInstance("viaDrill",ffA)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,ffA)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",yfA)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,yfA)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",wfA)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,wfA)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",efA)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new efA(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",mfA)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,mfA)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",DfA)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,DfA)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",SfA)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,SfA)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",bfA)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,bfA)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",xfA)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,xfA)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",ifA)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new ifA(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",kfA)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,kfA)}get modTextSize(){return this.getPropertyInstance("modTextSize",ofA)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new ofA(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",GfA)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,GfA)}get padSize(){return this.getPropertyInstance("padSize",nfA)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new nfA(A))}get padDrill(){return this.getPropertyInstance("padDrill",FfA)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,FfA)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",$pA)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new $pA(A))}get tenting(){return this.getPropertyInstance("tenting",tfA)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new tfA(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",afA);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new afA(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",gfA);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new gfA(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",AfA)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new AfA(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",sfA)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new sfA(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",rfA)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new rfA(A))}};NA.register(HfA);var mae=class extends ea{static token="thickness";static parentToken="general";token="thickness"};NA.register(mae);var Dae=class Dle extends NA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const e=Ei(A[0]);if(e===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(e);return new Dle(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};NA.register(Dae);var Sae=new Set(["thickness","legacy_teardrops"]),YfA=class Sle extends NA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const e=new Sle,{propertyMap:i,arrayPropertyMap:o}=NA.parsePrimitivesToClassProperties(A,this.token);for(const n of Object.keys(i))if(!Sae.has(n))throw new Error(`general encountered unsupported child token "${n}"`);for(const[n,s]of Object.entries(o)){if(!Sae.has(n))throw new Error(`general encountered unsupported child token "${n}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${n}"`)}return e._sxThickness=o.thickness?.[0]??i.thickness,e._sxLegacyTeardrops=o.legacy_teardrops?.[0]??i.legacy_teardrops,e}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new mae(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new Dae(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};NA.register(YfA);var tC=class ble extends NA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[e,i,o,n]=A,s=si(e),r=Ei(i),a=Ei(o),g=n===void 0?void 0:Ei(n);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new ble({index:s,name:r,type:a,userName:g})}get index(){return this._index}set index(A){this._index=A}get name(){return this._name}set name(A){this._name=A}get type(){return this._type}set type(A){this._type=A}get userName(){return this._userName}set userName(A){this._userName=A}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const A=[String(this._index),ro(this._name),this._type];return this._userName!==void 0&&A.push(ro(this._userName)),`(${A.join(" ")})`}};NA.register(tC);var JfA=class xle extends NA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const e=new xle;return e._definitions=A.map(i=>tC.fromPrimitive(i)),e}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};NA.register(JfA);var iV=class kle extends NA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const e=si(A[0]),i=Ei(A[1]);if(e===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new kle(e,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return`(net ${this._id} ${ro(this._name)})`}};NA.register(iV);var TfA=class extends ea{static token="version";static parentToken="kicad_pcb";token="version"};NA.register(TfA);var YZt=t=>/^[A-Za-z0-9._-]+$/.test(t),KfA=class extends Fy{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${YZt(this.value)?this.value:ro(this.value)})`}};NA.register(KfA);var JZt=t=>/^[A-Za-z0-9._-]+$/.test(t),qfA=class extends Fy{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${JZt(this.value)?this.value:ro(this.value)})`}};NA.register(qfA);var PfA=class Gle extends NA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const e=si(A[0]);if(e===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?Ei(A[1]):void 0;return new Gle(e,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${ro(this._name)})`:`(net ${this._id})`}};NA.register(PfA);var TZt=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),OfA=class Fle extends NA{static token="via";token="via";_type;_locked=!1;_free=!1;_removeUnusedLayers=!1;_keepEndLayers=!1;_sxAt;_size;_drill;_sxLayers;_sxNet;_sxUuid;_sxTstamp;_sxTeardrops;constructor(A={}){super(),A.type!==void 0&&(this.type=A.type),A.locked!==void 0&&(this.locked=A.locked),A.free!==void 0&&(this.free=A.free),A.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=A.removeUnusedLayers),A.keepEndLayers!==void 0&&(this.keepEndLayers=A.keepEndLayers),A.at!==void 0&&(this.at=A.at),A.size!==void 0&&(this.size=A.size),A.drill!==void 0&&(this.drill=A.drill),A.layers!==void 0&&(this.layers=A.layers),A.net!==void 0&&(this.net=A.net),A.uuid!==void 0&&(this.uuid=A.uuid),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.teardrops!==void 0&&(this.teardrops=A.teardrops)}static fromSexprPrimitives(A){const e=new Fle;for(const i of A){if(typeof i=="string"){e.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[o,...n]=i;if(typeof o!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);e.consumeNode(o,n)}return e}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!TZt.has(A))throw new Error(`via encountered unsupported flag "${A}"`);switch(A){case"locked":this._locked=!0;break;case"free":this._free=!0;break;case"remove_unused_layers":this._removeUnusedLayers=!0;break;case"keep_end_layers":this._keepEndLayers=!0;break}}consumeNode(A,e){switch(A){case"type":{const i=Ei(e[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(e);return;case"free":this._free=this.parseYesNo(e);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(e);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(e);return;case"at":{const i=NA.parsePrimitiveSexpr(["at",...e],{parentToken:this.token});if(!(i instanceof lI))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=si(e[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=si(e[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=eV.fromSexprPrimitives(e);return}case"net":{this._sxNet=PfA.fromSexprPrimitives(e);return}case"teardrops":{this._sxTeardrops=Vse.fromSexprPrimitives(e);return}case"uuid":{const i=Ei(e[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new Ni(i);return}case"tstamp":{const i=Ei(e[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new Og(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const e=Ei(A[0]);if(e===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(e)}get type(){return this._type}set type(A){this._type=A}get locked(){return this._locked}set locked(A){this._locked=A}get free(){return this._free}set free(A){this._free=A}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(A){this._removeUnusedLayers=A}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(A){this._keepEndLayers=A}get at(){return this._sxAt}set at(A){this._sxAt=A!==void 0?lI.from(A):void 0}get size(){return this._size}set size(A){this._size=A}get drill(){return this._drill}set drill(A){this._drill=A}get layers(){return this._sxLayers}set layers(A){if(A===void 0){this._sxLayers=void 0;return}this._sxLayers=A instanceof eV?A:new eV(A)}get net(){return this._sxNet}set net(A){this._sxNet=A}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof Ni?A:new Ni(A)}get teardrops(){return this._sxTeardrops}set teardrops(A){this._sxTeardrops=A}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof Og?A:new Og(A)}getChildren(){const A=[];return this._sxAt&&A.push(this._sxAt),this._sxLayers&&A.push(this._sxLayers),this._sxNet&&A.push(this._sxNet),this._sxUuid&&A.push(this._sxUuid),this._sxTstamp&&A.push(this._sxTstamp),this._sxTeardrops&&A.push(this._sxTeardrops),A}getString(){const A=["(via"];return this._type!==void 0&&A.push(` (type ${this._type})`),this._locked&&A.push(" (locked)"),this._free&&A.push(" (free)"),this._removeUnusedLayers&&A.push(" (remove_unused_layers)"),this._keepEndLayers&&A.push(" (keep_end_layers)"),this._sxAt&&A.push(this._sxAt.getStringIndented()),this._size!==void 0&&A.push(` (size ${this._size})`),this._drill!==void 0&&A.push(` (drill ${this._drill})`),this._sxLayers&&A.push(this._sxLayers.getStringIndented()),this._sxNet&&A.push(this._sxNet.getStringIndented()),this._sxUuid&&A.push(this._sxUuid.getStringIndented()),this._sxTstamp&&A.push(this._sxTstamp.getStringIndented()),this._sxTeardrops&&A.push(this._sxTeardrops.getStringIndented()),A.push(")"),A.join(`
5759
5759
  `)}};NA.register(OfA);var WfA=class Rle extends NA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const e=new Rle;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const o=NA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(o instanceof NA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(o)}return e}consumeChild(A){if(A instanceof TfA){this._sxVersion=A;return}if(A instanceof KfA){this._sxGenerator=A;return}if(A instanceof qfA){this._sxGeneratorVersion=A;return}if(A instanceof YfA){this._sxGeneral=A;return}if(A instanceof TZ){this._sxPaper=A;return}if(A instanceof bne){this._sxTitleBlock=A;return}if(A instanceof JfA){this._sxLayers=A;return}if(A instanceof HfA){this._sxSetup=A;return}if(A instanceof tse){this._properties.push(A);return}if(A instanceof iV){this._nets.push(A);return}if(A instanceof vpA){this._footprints.push(A);return}if(A instanceof kne){this._images.push(A);return}if(A instanceof jpA){this._segments.push(A);return}if(A instanceof $Z){this._grLines.push(A);return}if(A instanceof PpA){this._grTexts.push(A);return}if(A instanceof Ere){this._grPolys.push(A);return}if(A instanceof Cre){this._grRects.push(A);return}if(A instanceof OfA){this._vias.push(A);return}if(A instanceof yre){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new TfA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new KfA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new qfA(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};NA.register(WfA);var bae=t=>NA.parse(t),wh=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(t,A){this.input=t,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},KZt=class extends wh{_step(){const{kicadSch:t,schematicPaperSize:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");t.version=20250114;const e=new TZ;e.size=A?.name??"A4",t.paper=e,t.uuid=new Ni(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function oV(t,A){if(t.manufacturer_part_number)return ZfA(t.manufacturer_part_number);const e=qZt(t.ftype),i=A?.footprinter_string;return ZfA(i?`${e}_${i}`:e)}function qZt(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function ZfA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function PZt(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}function xae(t){return t in lQ}function kae(t,A,e){if(t.type!=="source_component")return A.symbol_name?xae(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return xae(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const i=oV(t,e);return`Device:${PZt(t.name)}_${i}`}var OZt=class extends wh{_step(){const{kicadSch:t,db:A}=this.ctx,e=new Zne,i=[],o=A.schematic_component.list();for(const s of o){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const n=A.schematic_net_label?.list?.()||[];for(const s of n)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const I=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});I&&i.push(I)}}e.symbols=i,t&&(t.libSymbols=e),this.finished=!0}createLibrarySymbolForComponent(t){const{db:A}=this.ctx,e=t.source_component_id?A.source_component.get(t.source_component_id):null;if(!e)return null;const i=A.cad_component?.list()?.find(g=>g.source_component_id===e.source_component_id),o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const n=this.getSymbolData(o,t);if(!n)return null;const s=kae(e,t,i),r=e.ftype==="simple_chip",a=oV(e,i);return this.createLibrarySymbol({libId:s,symbolData:n,isChip:r,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:a?`tscircuit:${a}`:""})}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const o=lQ[i];if(!o)return null;const n=`Custom:${i}`;return this.createLibrarySymbol({libId:n,symbolData:o,isChip:!1,schematicComponent:void 0,description:A?"Power net label":e?"Ground net label":"Net symbol",keywords:A?"power net":e?"ground net":"net",fpFilters:""})}getSymbolData(t,A){return t.startsWith("generic_chip_")?this.createGenericChipSymbolData(A,this.ctx.db):lQ[t]||null}createGenericChipSymbolData(t,A){const e=A.schematic_port.list().filter(r=>r.schematic_component_id===t.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=t.size?.width||1.5,o=t.size?.height||1,n={type:"path",points:[{x:-i/2,y:-o/2},{x:i/2,y:-o/2},{x:i/2,y:o/2},{x:-i/2,y:o/2},{x:-i/2,y:-o/2}]},s=e.map(r=>{const a=r.center.x-t.center.x,g=r.center.y-t.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[n],ports:s,size:{width:i,height:o}}}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:o,keywords:n,fpFilters:s,footprintRef:r=""}){const a=new hv({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),g=new Nne;g.hide=!e,a._sxPinNumbers=g;const I=new _ne;I.offset=e?1.27:0,a._sxPinNames=I,this.addSymbolProperties({symbol:a,libId:t,description:o,keywords:n,fpFilters:s,footprintRef:r});const c=this.createDrawingSubsymbol({libId:t,symbolData:A,isChip:e});a.subSymbols.push(c);const B=this.createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i});return a.subSymbols.push(B),a._sxEmbeddedFonts=new wdA(!1),a}addSymbolProperties({symbol:t,libId:A,description:e,keywords:i,fpFilters:o,footprintRef:n=""}){const s=A.split(":")[1]?.[0]||"U",r=[{key:"Reference",value:s,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:s,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:n,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:e,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:o,id:6,at:[0,0,0],hide:!0}];for(const a of r)t.properties.push(new Ry({key:a.key,value:a.value,id:a.id,at:a.at,effects:this.createTextEffects(1.27,a.hide)}))}getDescription(t){return t?.ftype==="simple_resistor"?"Resistor":t?.ftype==="simple_capacitor"?"Capacitor":t?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(t){return t?.ftype==="simple_resistor"?"R res resistor":t?.ftype==="simple_capacitor"?"C cap capacitor":t?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(t){return t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:t,symbolData:A,isChip:e}){const i=new hv({libraryId:`${t.split(":")[1]}_0_1`}),o=this.ctx.c2kMatSch?.a||15;for(const n of A.primitives||[])if(n.type==="path"&&n.points){const s=e?"background":"none",r=this.createPolylineFromPoints({points:n.points,scale:o,center:A.center,fillType:s});i.polylines.push(r)}return i}createPolylineFromPoints({points:t,scale:A,center:e,fillType:i}){const o=new Fne,n=e?.x??0,s=e?.y??0,r=Bh(A,A),a=t.map(B=>{const C=Tt(r,{x:B.x-n,y:B.y-s});return new yE(C.x,C.y)}),g=new DQ(a);o.points=g;const I=new edA;I.width=.254,I.type="default",o.stroke=I;const c=new Lne;return c.type=i,o.fill=c,o}createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i}){const o=new hv({libraryId:`${t.split(":")[1]}_1_1`});for(let n=0;n<(A.ports?.length||0);n++){const s=A.ports[n],r=new OZ;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:I}=this.calculatePinPosition(s,A.center,A.size,e,n,i);r.at=[a,g,I],r.length=e?6:1.27;const c=new qS;c.size={height:1.27,width:1.27};const B=new KS({font:c}),C=s.labels?.[0]||"~";r._sxName=new xdA({value:C,effects:B});const l=new qS;l.size={height:1.27,width:1.27};const Q=new KS({font:l}),E=s.pinNumber?.toString()||`${n+1}`;r._sxNumber=new Jne({value:E,effects:Q}),o.pins.push(r)}return o}calculatePinPosition(t,A,e,i,o,n){const s=this.ctx.c2kMatSch?.a||15;let r=t.x??0,a=t.y??0,g=!1;if(o!==void 0&&n){const d=this.ctx.db.schematic_port.list().filter(f=>f.schematic_component_id===n.schematic_component_id).sort((f,D)=>(f.pin_number||0)-(D.pin_number||0));if(d[o]){const f=d[o];r=f.center.x-n.center.x,a=f.center.y-n.center.y,g=!0}}let I,c;if(g)I=r,c=a;else{const d=A?.x??0,f=A?.y??0;I=r-d,c=a-f}const B=Bh(s,s),C=Tt(B,{x:I,y:c});let l;if(i&&e){const d=e.width/2,f=e.height/2,D=Math.abs(I)/d,b=Math.abs(c)/f;l=D>b}else l=Math.abs(I)>Math.abs(c);let Q=C.x,E=C.y;const h=6;if(i&&e){const d=e.width/2*s,f=e.height/2*s;l?(Q=I>0?d:-d,E=c*s):(Q=I*s,E=c>0?f:-f)}let u=0;return l?I>0?i?(u=180,Q=Q+h):u=0:i?(u=0,Q=Q-h):u=180:c>0?i?(u=270,E=E+h):u=90:i?(u=90,E=E-h):u=270,{x:Q,y:E,angle:u}}createTextEffects(t,A){const e=new qS;return e.size={height:t,width:t},new KS({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},WZt=class extends wh{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_component.list();if(e.length===0){this.finished=!0;return}const i=[];for(const o of e){const n=o.source_component_id?A.source_component.get(o.source_component_id):null;if(!n||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Tt(this.ctx.c2kMatSch,{x:o.center.x,y:o.center.y}),a=crypto.randomUUID(),g=new hv({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),I=A.cad_component?.list()?.find(_=>_.source_component_id===n.source_component_id),c=kae(n,o,I),B=new DdA(c);g._sxLibId=B;const{reference:C,value:l,description:Q}=this.getComponentMetadata(n),{refTextPos:E,valTextPos:h}=this.getTextPositions(o,{x:s,y:r}),u=new Ry({key:"Reference",value:C,id:0,at:[E.x,E.y,0],effects:this.createTextEffects(1.27,!1)}),d=n.ftype==="simple_chip",f=new Ry({key:"Value",value:l,id:1,at:[h.x,h.y,0],effects:this.createTextEffects(1.27,d)}),D=new Ry({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),b=new Ry({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),m=new Ry({key:"Description",value:Q,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});g.properties.push(u,f,D,b,m);const x=A.schematic_port.list().filter(_=>_.schematic_component_id===o.schematic_component_id).sort((_,Y)=>(_.pin_number||0)-(Y.pin_number||0));for(const _ of x){const Y=new OZ;Y.numberString=`${_.pin_number||1}`,Y.uuid=crypto.randomUUID(),g.pins.push(Y)}const F=new kdA,k=new FdA(""),v=new RdA(`/${t?.uuid?.value||""}`);v.reference=C,v.unit=1,k.paths.push(v),F.projects.push(k),g._sxInstances=F,i.push(g)}t&&(t.symbols=i),this.finished=!0}getTextPositions(t,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(C=>C.schematic_component_id===t.schematic_component_id)||[]).find(C=>C.text&&C.text.length>0);if(i&&this.ctx.c2kMatSch){const C=Tt(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),l={x:A.x,y:A.y+6};return{refTextPos:C,valTextPos:l}}const o=t.symbol_name,n=lQ[o];if(!n)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const C of n.primitives)C.type==="text"&&(C.text==="{REF}"?s=C:C.text==="{VAL}"&&(r=C));const a=n.center||{x:0,y:0},I=o.includes("_down")||o.includes("_up")?.15:0,c=s&&this.ctx.c2kMatSch?Tt(this.ctx.c2kMatSch,{x:t.center.x+(s.x-a.x)+I,y:t.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},B=r&&this.ctx.c2kMatSch?Tt(this.ctx.c2kMatSch,{x:t.center.x+(r.x-a.x)+I,y:t.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:c,valTextPos:B}}getComponentMetadata(t){const A=t.name||"?";return t.ftype==="simple_resistor"?{reference:A,value:t.display_resistance||"R",description:"Resistor"}:t.ftype==="simple_capacitor"?{reference:A,value:t.display_capacitance||"C",description:"Capacitor"}:t.ftype==="simple_inductor"?{reference:A,value:t.display_inductance||"L",description:"Inductor"}:t.ftype==="simple_diode"?{reference:A,value:"D",description:"Diode"}:t.ftype==="simple_chip"?{reference:A,value:A,description:"Integrated Circuit"}:{reference:A,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new qS;i.size={height:t,width:t};const o=e?new YZ({horizontal:e}):void 0;return new KS({font:i,hiddenText:A,justify:o})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},ZZt=class extends wh{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_net_label?.list?.()||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],o=[];for(const n of e){const s=n.text||"",r=n.symbol_name;if(r){const a=this.createSymbolFromNetLabel(n,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(n,s);a&&o.push(a)}}if(t&&i.length>0){const n=t.symbols||[];t.symbols=[...n,...i]}t&&o.length>0&&(t.globalLabels=[...t.globalLabels||[],...o]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:o}=Tt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=crypto.randomUUID(),s=new hv({at:[i,o,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:n,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new DdA(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),I=g?-4:4,c=g?-6:6,B=new Ry({key:"Reference",value:A,id:0,at:[i,o+I,0],effects:this.createTextEffects(1.27,!1)}),C=new Ry({key:"Value",value:A,id:1,at:[i,o+c,0],effects:this.createTextEffects(1.27,!0)}),l=new Ry({key:"Footprint",value:"",id:2,at:[i-1.778,o,90],effects:this.createTextEffects(1.27,!0)}),Q=new Ry({key:"Datasheet",value:"~",id:3,at:[i,o,0],effects:this.createTextEffects(1.27,!0)}),E=new Ry({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,o,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(B,C,l,Q,E);const h=new OZ;h.numberString="1",h.uuid=crypto.randomUUID(),s.pins.push(h);const{kicadSch:u}=this.ctx,d=new kdA,f=new FdA(""),D=new RdA(`/${u?.uuid?.value||""}`);return D.reference=A,D.unit=1,f.paths.push(D),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Tt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[o]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[o]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new YZ(a)),new ose({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new qS;return e.size={height:t,width:t},new KS({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},VZt=class extends wh{_step(){const{kicadSch:t,db:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const e=A.schematic_trace.list();if(e.length===0){this.finished=!0;return}const i=[],o=[];for(const n of e){for(const s of n.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of n.junctions){const r=this.createJunction(s);o.push(r)}}t.wires=i,t.junctions=o,this.finished=!0}createWireFromEdge(t){const A=new jne;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Tt(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Tt(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),o=e.x,n=e.y,s=i.x,r=i.y,a=new DQ([new yE(o,n),new yE(s,r)]);A.points=a;const g=new edA;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(t){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:e}=Tt(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new zne({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},jZt=class extends wh{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new vdA,e=new rse;e.value="/";const i=new ase("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new wdA(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function zZt(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,o=1/0,n=-1/0,s=-1/0;for(const g of A){const I=g.size?.width??0,c=g.size?.height??0;i=Math.min(i,g.center.x-I/2),o=Math.min(o,g.center.y-c/2),n=Math.max(n,g.center.x+I/2),s=Math.max(s,g.center.y+c/2)}for(const g of e)for(const I of g.edges)i=Math.min(i,I.from.x,I.to.x),o=Math.min(o,I.from.y,I.to.y),n=Math.max(n,I.from.x,I.to.x),s=Math.max(s,I.from.y,I.to.y);i===1/0&&(i=0,o=0,n=0,s=0);const r=(i+n)/2,a=(o+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:o,maxX:n,maxY:s}}}var nV=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function XZt(t,A,e=20){const i=t+2*e,o=A+2*e;for(let n=0;n<nV.length;n++){const s=nV[n];if(i<=s.width&&o<=s.height)return s}return nV[nV.length-1]}var Gae=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){const e=pa(t),{center:i,bounds:o}=zZt(e),n=(o.maxX-o.minX)*15,s=(o.maxY-o.minY)*15,r=XZt(n,s),a=r.width/2,g=r.height/2;this.ctx={db:e,circuitJson:t,kicadSch:new LdA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:VB(cr(a,g),Bh(15,-15),cr(-i.x,-i.y))},this.pipeline=[new KZt(t,this.ctx),new OZt(t,this.ctx),new WZt(t,this.ctx),new ZZt(t,this.ctx),new VZt(t,this.ctx),new jZt(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},$Zt=class extends wh{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");t.version=20241229;const A=new TZ;A.size="A4",t.paper=A;const e=new YfA;e.thickness=1.6,t.general=e;const i=new HfA;i.padToMaskClearance=0,t.setup=i;const o=new JfA,n=[new tC({index:0,name:"F.Cu",type:"signal"}),new tC({index:2,name:"B.Cu",type:"signal"}),new tC({index:9,name:"F.Adhes",type:"user"}),new tC({index:11,name:"B.Adhes",type:"user"}),new tC({index:13,name:"F.Paste",type:"user"}),new tC({index:15,name:"B.Paste",type:"user"}),new tC({index:5,name:"F.SilkS",type:"user"}),new tC({index:7,name:"B.SilkS",type:"user"}),new tC({index:1,name:"F.Mask",type:"user"}),new tC({index:3,name:"B.Mask",type:"user"}),new tC({index:20,name:"Dwgs.User",type:"user"}),new tC({index:21,name:"Cmts.User",type:"user"}),new tC({index:22,name:"Eco1.User",type:"user"}),new tC({index:23,name:"Eco2.User",type:"user"}),new tC({index:24,name:"Edge.Cuts",type:"user"}),new tC({index:25,name:"Margin",type:"user"}),new tC({index:17,name:"B.CrtYd",type:"user"}),new tC({index:16,name:"F.CrtYd",type:"user"}),new tC({index:19,name:"B.Fab",type:"user"}),new tC({index:18,name:"F.Fab",type:"user"})];o.definitions=n,t.layers=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},AVt=class extends wh{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,e=this.ctx.db.source_net?.list()??[];for(const r of e){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",I=g&&g.trim().length>0?g:a;A.set(a,I)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const I=this.ctx.db.source_net?.get(g);if(I?.subcircuit_connectivity_map_key&&I.subcircuit_connectivity_map_key.length>0){a=I.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",I=g&&g.trim().length>0?g:a;A.set(a,I)}}const o=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),n=[];n.push(new iV(0,""));let s=1;for(const[r,a]of o){const g=new iV(s,a);n.push(g);const I={id:s,name:a};this.ctx.pcbNetMap.set(r,I),s++}t.nets=n,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function eVt(t){let A=0;for(let i=0;i<t.length;i++){const o=t.charCodeAt(i);A=(A<<5)-A+o,A=A&A}let e="";for(let i=0;i<4;i++){let o=A;for(let n=0;n<t.length;n++)o=(o<<5)-o+t.charCodeAt(n)+i*31,o=o&o;e+=Math.abs(o).toString(16).padStart(8,"0")}return e}function fY(t){const A=eVt(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function tVt({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){let s,r;if("x"in t&&"y"in t)s=t.x,r=t.y;else if("points"in t&&Array.isArray(t.points)){const u=t.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=VB(i!==0?lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},Bh(1,-1),cr(-A.x,-A.y)),g=Tt(a,{x:s,y:r}),c={top:"F.Cu",bottom:"B.Cu"}[t.layer]||"F.Cu";let B,C,l,Q;if(t.shape==="circle")B="circle",C=["radius"in t?t.radius*2:.5,"radius"in t?t.radius*2:.5];else if(t.shape==="polygon"&&"points"in t){const u=t.points,d=VB(Bh(1,-1),cr(-s,-r)),f=u.map(b=>{const m=Tt(d,{x:b.x,y:b.y});return new yE(m.x,m.y)}),D=new spA;D.contours=[new DQ(f)],D.width=0,D.filled=!0,Q=new Use,Q.addGraphic(D),B="custom",l=new pse,l.anchor="circle",C=[.2,.2]}else B="rect",C=["width"in t?t.width:.5,"height"in t?t.height:.5];const E=`pad:${n}:${e}:${g.x},${g.y}`,h=new VZ({number:String(e),padType:"smd",shape:B,at:[g.x,g.y,0],size:C,layers:[`${c}`,`${c==="F.Cu"?"F":"B"}.Paste`,`${c==="F.Cu"?"F":"B"}.Mask`],uuid:fY(E)});return l&&(h.options=l),Q&&(h.primitives=Q),o&&(h.net=new ApA(o.id,o.name)),h}function iVt({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){if(!("x"in t&&"y"in t))return null;const s=t.x-A.x,r=-(t.y-A.y),a=i!==0?lm(i*Math.PI/180):md(),g=Tt(a,{x:s,y:r});let I="circle",c,B,C=0;const l="hole_offset_x"in t||"hole_offset_y"in t;let Q;if(l){const u={x:t.hole_offset_x??0,y:t.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Tt(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(I="circle",c=[t.outer_diameter,t.outer_diameter],B=new CD({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(I="oval",c=[t.outer_width,t.outer_height],B=new CD({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="pill_hole_with_rect_pad"?(I="rect",c=[t.rect_pad_width,t.rect_pad_height],B=new CD({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="circular_hole_with_rect_pad"?(I="rect",c=[t.rect_pad_width,t.rect_pad_height],B=new CD({diameter:t.hole_diameter,offset:Q})):t.shape==="rotated_pill_hole_with_rect_pad"?(I="rect",c=[t.rect_pad_width,t.rect_pad_height],B=new CD({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q}),C=t.rect_ccw_rotation||0):(I="circle",c=[1.6,1.6],B=new CD({diameter:.8,offset:Q}));const E=`thruhole:${n}:${e}:${g.x},${g.y}`,h=new VZ({number:String(e),padType:"thru_hole",shape:I,at:[g.x,g.y,C],size:c,drill:B,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:fY(E)});return o&&(h.net=new ApA(o.id,o.name)),h}function oVt({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,o=-(t.y-A.y),n=e!==0?lm(e*Math.PI/180):md(),s=Tt(n,{x:i,y:o});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const I=t.hole_diameter;a=[I,I],g=new CD({diameter:I})}else if(t.hole_shape==="oval"){r="oval";const I=t.hole_width,c=t.hole_height;a=[I,c],g=new CD({oval:!0,diameter:I,width:c})}else{r="circle";const I="hole_diameter"in t?t.hole_diameter:1;a=[I,I],g=new CD({diameter:I})}return new VZ({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function nVt({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,o=-(t.anchor_position.y-A.y),n=e!==0?lm(e*Math.PI/180):md(),s=Tt(n,{x:i,y:o}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",I=(t.font_size||1)/1.5,c=new qS;c.size={width:I,height:I};const B=new KS({font:c}),C=t.ccw_rotation||0;return new $se({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:C},layer:g,effects:B})}var sVt=class extends wh{componentsProcessed=0;pcbComponents=[];getNetInfoForPcbPort(t){if(!t)return;const A=this.ctx.db.pcb_port?.get(t);if(!A)return;const e=A.source_port_id;if(!e)return;const i=this.ctx.db.source_port?.get(e);if(!i)return;const o=i.subcircuit_connectivity_map_key;if(o)return this.ctx.pcbNetMap?.get(o)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}create3DModelsFromCadComponent(t,A){const e=[],i=t.model_step_url||t.model_wrl_url;if(!i)return e;const o=new MpA(i);if(t.position&&(o.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:t.position.z||0}),t.rotation&&(o.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const n=t.model_unit_to_mm_scale_factor;o.scale={x:n,y:n,z:n}}return e.push(o),e}constructor(t,A){super(t,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const e=this.pcbComponents[this.componentsProcessed],i=e.source_component_id?this.ctx.db.source_component.get(e.source_component_id):null,o=this.getCadComponentForPcbComponent(e.pcb_component_id),n=i?oV(i,o):"Unknown",s=Tt(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new vpA({libraryLink:`tscircuit:${n}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:fY(r)}),g=a.fpTexts,I=this.ctx.db.pcb_silkscreen_text?.list().filter(h=>h.pcb_component_id===e.pcb_component_id)||[];for(const h of I){const u=nVt({textElement:h,componentCenter:e.center,componentRotation:e.rotation||0});u&&g.push(u)}a.fpTexts=g;const c=this.ctx.db.pcb_smtpad?.list().filter(h=>h.pcb_component_id===e.pcb_component_id)||[],B=a.fpPads;let C=1;for(const h of c){const u=this.getNetInfoForPcbPort(h.pcb_port_id),d=tVt({pcbPad:h,componentCenter:e.center,padNumber:C,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});B.push(d),C++}const l=this.ctx.db.pcb_plated_hole?.list().filter(h=>h.pcb_component_id===e.pcb_component_id)||[];for(const h of l){const u=this.getNetInfoForPcbPort(h.pcb_port_id),d=iVt({platedHole:h,componentCenter:e.center,padNumber:C,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});d&&(B.push(d),C++)}const Q=this.ctx.db.pcb_hole?.list().filter(h=>h.subcircuit_id===e.subcircuit_id)||[];for(const h of Q){const u=oVt({pcbHole:h,componentCenter:e.center,componentRotation:e.rotation||0});u&&B.push(u)}if(a.fpPads=B,o){const h=this.create3DModelsFromCadComponent(o,e.center);h.length>0&&(a.models=h)}const E=t.footprints;E.push(a),t.footprints=E,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},rVt=class extends wh{tracesProcessed=0;pcbTraces=[];constructor(t,A){super(t,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}for(let o=0;o<i.route.length-1;o++){const n=i.route[o],s=i.route[o+1],r=Tt(A,{x:n.x,y:n.y}),a=Tt(A,{x:s.x,y:s.y});let g;if(e){let Q=i.subcircuit_connectivity_map_key;if(!Q&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(Q=E.subcircuit_connectivity_map_key,!Q&&E.connected_source_net_ids?.length))for(const h of E.connected_source_net_ids){const u=this.ctx.db.source_net?.get(h);if(u?.subcircuit_connectivity_map_key){Q=u.subcircuit_connectivity_map_key;break}}}if(!Q&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(Q=E.subcircuit_connectivity_map_key)}Q&&(g=e.get(Q))}const c={top:"F.Cu",bottom:"B.Cu"}[n.layer]||n.layer||"F.Cu",B=`segment:${r.x},${r.y}:${a.x},${a.y}:${c}:${g?.id??0}`,C=new jpA({start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},layer:c,width:i.width||.25,net:new AV(g?.id??0),uuid:fY(B)}),l=t.segments;l.push(C),t.segments=l}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},aVt=class extends wh{viasProcessed=0;pcbVias=[];constructor(t,A){super(t,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],o=Tt(A,{x:i.x,y:i.y});let n;if(e){let g=i.subcircuit_connectivity_map_key;if(!g&&i.pcb_trace_id){const I=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(I&&("subcircuit_connectivity_map_key"in I&&(g=I.subcircuit_connectivity_map_key),!g&&I.source_trace_id)){const c=this.ctx.db.source_trace?.get(I.source_trace_id);if(c&&("subcircuit_connectivity_map_key"in c&&(g=c.subcircuit_connectivity_map_key),!g&&c.connected_source_net_ids?.length))for(const B of c.connected_source_net_ids){const C=this.ctx.db.source_net?.get(B);if(C?.subcircuit_connectivity_map_key){g=C.subcircuit_connectivity_map_key;break}}}}if(!g&&i.connection_name){const I=this.ctx.db.source_net?.get(i.connection_name);I?.subcircuit_connectivity_map_key&&(g=I.subcircuit_connectivity_map_key)}g&&(n=e.get(g))}const s=`via:${o.x},${o.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${n?.id??0}`,r=new OfA({at:[o.x,o.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:["F.Cu","B.Cu"],net:new PfA(n?.id??0),uuid:fY(s)}),a=t.vias;a.push(r),t.vias=a,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function gVt({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Tt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),o={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",n=(t.font_size||1)/1.5,s=new qS;s.size={width:n,height:n};const r=new YZ,a=t.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new KS({font:s});a!=="center"&&(g.justify=r);const I=t.ccw_rotation||0,c=new lI([e.x,e.y,I]),B=new PpA({text:t.text,layer:o,effects:g});return B.position=c,B}var IVt=class extends wh{_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const e=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const n of e)if(!(!n.route||n.route.length<2))for(let s=0;s<n.route.length-1;s++){const r=n.route[s],a=n.route[s+1];if(!r||!a)continue;const g=Tt(A,{x:r.x,y:r.y}),I=Tt(A,{x:a.x,y:a.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[n.layer]||n.layer||"F.SilkS",C=new $Z({start:{x:g.x,y:g.y},end:{x:I.x,y:I.y},layer:B,width:n.stroke_width||.15}),l=t.graphicLines;l.push(C),t.graphicLines=l}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(n=>!n.pcb_component_id)||[];for(const n of i){const s=gVt({textElement:n,c2kMatPcb:A});if(s){const r=t.graphicTexts;r.push(s),t.graphicTexts=r}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const n=o[0];if(!n){this.finished=!0;return}let s;if(n.outline&&n.outline.length>0)s=n.outline;else{const a=n.width?n.width/2:0,g=n.height?n.height/2:0;s=[{x:n.center.x-a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y+g},{x:n.center.x-a,y:n.center.y+g}]}const r=s.map(a=>Tt(A,a));for(let a=0;a<r.length;a++){const g=r[a],I=r[(a+1)%r.length];if(!g||!I)continue;const c=new $Z({start:{x:g.x,y:g.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=t.graphicLines;B.push(c),t.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Fae=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){this.ctx={db:pa(t),circuitJson:t,kicadPcb:new WfA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:VB(cr(100,100),Bh(1,-1))},this.pipeline=[new $Zt(t,this.ctx),new AVt(t,this.ctx),new sVt(t,this.ctx),new rVt(t,this.ctx),new aVt(t,this.ctx),new IVt(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}},cVt=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,o=A.pcbFilename??`${e}.kicad_pcb`,n=new Date().toISOString();this.ctx={db:pa(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:n,modified:n},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:o},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
5760
- `}},BVt=class extends wh{_step(){const t=new Gae(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new Fae(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},CVt=class extends wh{isCustomSymbol(t){return t?.startsWith("Custom:")??!1}_step(){const t=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const e=new Map;try{const o=bae(t).find(r=>r instanceof LdA);if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const n=o.libSymbols;if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const s=n.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);e.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),e.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(e.values()),this.finished=!0}updateFootprintProperty(t,A){const e=t.properties??[];for(const i of e)if(i.key==="Footprint"&&i.value){const o=i.value.split(":");o.length>1?i.value=`${A}:${o[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(t){if(!t)return"symbol";const A=t.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}getOutput(){return this.ctx.libraryOutput}};function lVt(t){const A=t.split(/[/\\]/);return A[A.length-1]||t}var QVt=class extends wh{findCustomFootprintNames(){const t=new Set,A=this.ctx.db.cad_component?.list()??[],e=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const o=i.source_component_id?e?.get(i.source_component_id):null;if(o){const n=oV(o,i);t.add(n)}}return t}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const e=this.findCustomFootprintNames(),i=new Map;try{const n=bae(t).find(r=>r instanceof WfA);if(!n){this.ctx.footprintEntries=[],this.finished=!0;return}const s=n.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:e});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e}){const o=(t.libraryLink??"footprint").split(":"),n=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!e.has(n);t.libraryLink=n,t.position=lI.from([0,0,0]),t.locked=!1,t.placed=!1,t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0,t.properties=[];const r=t.fpTexts??[];for(const B of r)B.uuid=void 0,B.type==="reference"?B.text="REF**":B.type==="value"&&B.text.trim().length===0&&(B.text=n);t.fpTexts=r;const a=t.fpPads??[];for(const B of a)B.uuid=void 0,B.net=void 0;t.fpPads=a;const g=t.models??[],I=[],c=[];for(const B of g)if(B.path){const C=lVt(B.path),l=`\${KIPRJMOD}/${A}.3dshapes/${C}`,Q=new MpA(l);B.offset&&(Q.offset=B.offset),B.scale&&(Q.scale=B.scale),B.rotate&&(Q.rotate=B.rotate),I.push(Q),c.push(B.path)}return t.models=I,{footprintName:n,kicadModString:t.getString(),model3dSourcePaths:c,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},EVt=20211014,hVt="circuit-json-to-kicad",uVt=class extends wh{_step(){const t=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(t){return new One({version:EVt,generator:hVt,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},dVt=class extends wh{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],o=new Set;for(const r of e)for(const a of r.model3dSourcePaths)o.add(a);const n=this.generateFpLibTable(A),s=this.generateSymLibTable(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=e,this.ctx.libraryOutput.fpLibTableString=n,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(o),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
5760
+ `}},BVt=class extends wh{_step(){const t=new Gae(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new Fae(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},CVt=class extends wh{isCustomSymbol(t){return t?.startsWith("Custom:")??!1}_step(){const t=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const e=new Map;try{const o=bae(t).find(r=>r instanceof LdA);if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const n=o.libSymbols;if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const s=n.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);e.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),e.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(e.values()),this.finished=!0}updateFootprintProperty(t,A){const e=t.properties??[];for(const i of e)if(i.key==="Footprint"&&i.value){const o=i.value.split(":");o.length>1?i.value=`${A}:${o[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(t){if(!t)return"symbol";const A=t.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}getOutput(){return this.ctx.libraryOutput}};function lVt(t){const A=t.split(/[/\\]/);return A[A.length-1]||t}var QVt=class extends wh{findCustomFootprintNames(){const t=new Set,A=this.ctx.db.cad_component?.list()??[],e=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const o=i.source_component_id?e?.get(i.source_component_id):null;if(o){const n=oV(o,i);t.add(n)}}return t}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const e=this.findCustomFootprintNames(),i=new Map;try{const n=bae(t).find(r=>r instanceof WfA);if(!n){this.ctx.footprintEntries=[],this.finished=!0;return}const s=n.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:e});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e}){const o=(t.libraryLink??"footprint").split(":"),n=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!e.has(n);t.libraryLink=n,t.position=lI.from([0,0,0]),t.locked=!1,t.placed=!1,t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0,t.properties=[];const r=t.fpTexts??[];for(const B of r)B.uuid=void 0,B.type==="reference"?B.text="REF**":B.type==="value"&&B.text.trim().length===0&&(B.text=n);t.fpTexts=r;const a=t.fpPads??[];for(const B of a)B.uuid=void 0,B.net=void 0;t.fpPads=a;const g=t.models??[],I=[],c=[];for(const B of g)if(B.path){const C=lVt(B.path),l=`../../3dmodels/${A}.3dshapes/${C}`,Q=new MpA(l);B.offset&&(Q.offset=B.offset),B.scale&&(Q.scale=B.scale),B.rotate&&(Q.rotate=B.rotate),I.push(Q),c.push(B.path)}return t.models=I,{footprintName:n,kicadModString:t.getString(),model3dSourcePaths:c,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},EVt=20211014,hVt="circuit-json-to-kicad",uVt=class extends wh{_step(){const t=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(t){return new One({version:EVt,generator:hVt,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},dVt=class extends wh{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],o=new Set;for(const r of e)for(const a of r.model3dSourcePaths)o.add(a);const n=this.generateFpLibTable(A),s=this.generateSymLibTable(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=e,this.ctx.libraryOutput.fpLibTableString=n,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(o),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
5761
5761
  (version 7)
5762
5762
  (lib (name "${t}") (type "KiCad") (uri "\${KIPRJMOD}/${t}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
5763
5763
  )
@@ -5619,7 +5619,7 @@ test("${g} should solve problem correctly", () => {
5619
5619
  // Add more specific assertions based on expected output
5620
5620
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5621
5621
  })
5622
- `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return O.jsxs("div",{className:`relative ${A}`,ref:o,children:[O.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&O.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:[O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Xte=t=>t.activeSubSolver?[t,...Xte(t.activeSubSolver)]:[t],SKt=({solver:t})=>{const A=Xte(t);return O.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>O.jsxs("div",{className:"flex items-center",children:[i>0&&O.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),O.jsx(DKt,{solver:e})]},e.constructor.name))})},bKt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=j.useReducer(Q=>!Q,!1),r=j.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};j.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),j.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const l=t.getCurrentPhase!==void 0,C=l?t.getCurrentPhase():null;return O.jsxs("div",{className:"space-y-2 p-2 border-b",children:[O.jsx("div",{className:"flex items-center",children:O.jsx(SKt,{solver:t})}),O.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[O.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),O.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),O.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),O.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,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"}),l&&O.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),O.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",O.jsx("span",{className:"font-medium",children:C})]}),t.solved&&O.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&O.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&O.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},xKt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},kKt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=xKt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],l=B?t.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},GKt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return O.jsx("span",{className:`font-medium ${A[t]}`,children:t})},FKt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:O.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),O.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},RKt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),MKt=({stats:t})=>{if(!t||Object.keys(t).length===0)return O.jsx("span",{children:"-"});const A=Object.entries(t),e=RKt(t);return O.jsxs("details",{className:"cursor-pointer",children:[O.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),O.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>O.jsxs("div",{children:[i,": ",String(o)]},i))})]})},auA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(auA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=auA(i));return A},NKt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=auA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_Kt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>kKt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):NKt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return O.jsxs("div",{className:"border-t border-gray-200",children:[O.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:O.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),O.jsx("div",{className:"overflow-x-auto",children:O.jsxs("table",{className:"w-full text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),O.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",O.jsx("sub",{children:"0"})]}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),O.jsx("tbody",{children:i.map(r=>O.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[O.jsx("td",{className:"px-4 py-2",children:O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),O.jsx("button",{onClick:()=>o(r.name),disabled:r.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 ${r.name} completes`,children:O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})})}),O.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(GKt,{status:r.status})}),O.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(FKt,{progress:r.progress})}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),O.jsx("td",{className:"px-4 py-2 text-gray-500",children:O.jsx(MKt,{stats:r.stats})}),O.jsx("td",{className:"px-4 py-2",children:r.solverInstance?O.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})}),O.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},vKt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function UKt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return O.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>O.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>O.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>O.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var LKt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=j.useReducer(I=>I+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return O.jsxs("div",{children:[O.jsx(bKt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?O.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):O.jsx(vKt,{fallback:O.jsx(UKt,{graphics:s}),children:O.jsx(mKt,{graphics:s})}),a&&O.jsx(_Kt,{solver:t,onStepUntilPhase:g})]})};const HKt=()=>{j.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},YKt=t=>t.toLowerCase().includes("pack")?zSt:t.toLowerCase().includes("rout")?tbt:vSt,JKt=({solverEvents:t=[]})=>{const[A,e]=j.useState(null);HKt();const i=j.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=j.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=j.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=ZeA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZeA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?O.jsx("div",{className:"rf-p-4",children:O.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:O.jsxs("div",{className:"rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),O.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."})]})})}):O.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[O.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[O.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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return O.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=YKt(a.solverName);return O.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[O.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),O.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[O.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),O.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),O.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?O.jsx(ky,{fallback:O.jsx("div",{className:"rf-p-4",children:O.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),O.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:O.jsx(LKt,{solver:s.instance})}):O.jsxs("div",{className:"rf-p-4",children:[O.jsxs("div",{className:"rf-mb-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),O.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&O.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:O.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),O.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[O.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:O.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),O.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:O.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):O.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:O.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},$te=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{j.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{j3.captureException(i)}catch{}}},[t,A]),j.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{j3.captureException(o,{error_type:i.type})}catch{}}},[e])},Aie="0.0.1502",TKt={version:Aie},YZ=m1A()(D1A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),KKt=t=>{const[A,e]=j.useState([]),[i,o]=j.useState(null),[n,s]=j.useState(""),[r,a]=av("eval-version-selection",null),g=YZ(l=>l.setLastRunEvalVersion),I=YZ(l=>l.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(l=>l.json()).then(l=>{if(Array.isArray(l?.versions)){let C=[...l.versions];l.tags?.latest&&(o(l.tags.latest),C=C.filter(Q=>Q!==l.tags.latest)),e(C)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:j.useMemo(()=>A.filter(l=>l.includes(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:I,search:n,setSearch:s,selectVersion:l=>{a(l),s("")}}},qKt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=j.useState(""),[s,r]=j.useState("");if(!i)return null;const a=t.filter(c=>c.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),I=c=>{c.key==="Enter"&&(a.length===1?n(a[0]):g&&n(s))};return O.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:O.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[O.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),O.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:c=>r(c.target.value),onKeyDown:I}),O.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(c=>O.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${o===c?"bg-blue-50":""}`,onClick:()=>n(c),children:c},c)),g&&O.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${o===s?"bg-blue-50":""}`,onClick:()=>n(s),children:['Create new "',s,'"']})]}),O.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},PKt=t=>{const A=j.useRef(null),e=Yc(i=>i.recentEvents);j.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function OKt(t){const A=WKt(t),e=j.forwardRef((i,o)=>{const{children:n,...s}=i,r=j.Children.toArray(n),a=r.find(VKt);if(a){const g=a.props.children,I=r.map(c=>c===a?j.Children.count(g)>1?j.Children.only(null):j.isValidElement(g)?g.props.children:null:c);return O.jsx(A,{...s,ref:o,children:j.isValidElement(g)?j.cloneElement(g,void 0,I):null})}return O.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function WKt(t){const A=j.forwardRef((e,i)=>{const{children:o,...n}=e;if(j.isValidElement(o)){const s=zKt(o),r=jKt(n,o.props);return o.type!==j.Fragment&&(r.ref=i?Vp(i,s):s),j.cloneElement(o,r)}return j.Children.count(o)>1?j.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var ZKt=Symbol("radix.slottable");function VKt(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ZKt}function jKt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function zKt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var JZ="Dialog",[eie,tie]=uw(JZ),[XKt,Pw]=eie(JZ),iie=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=j.useRef(null),a=j.useRef(null),[g,I]=nx({prop:i,defaultProp:o??!1,onChange:n,caller:JZ});return O.jsx(XKt,{scope:A,triggerRef:r,contentRef:a,contentId:Bh(),titleId:Bh(),descriptionId:Bh(),open:g,onOpenChange:I,onOpenToggle:j.useCallback(()=>I(c=>!c),[I]),modal:s,children:e})};iie.displayName=JZ;var oie="DialogTrigger",nie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(oie,e),n=Bc(A,o.triggerRef);return O.jsx(Ha.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":cuA(o.open),...i,ref:n,onClick:vo(t.onClick,o.onOpenToggle)})});nie.displayName=oie;var guA="DialogPortal",[$Kt,sie]=eie(guA,{forceMount:void 0}),rie=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Pw(guA,A);return O.jsx($Kt,{scope:A,forceMount:e,children:j.Children.map(i,s=>O.jsx(s0,{present:e||n.open,children:O.jsx(oW,{asChild:!0,container:o,children:s})}))})};rie.displayName=guA;var TZ="DialogOverlay",aie=j.forwardRef((t,A)=>{const e=sie(TZ,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(TZ,t.__scopeDialog);return n.modal?O.jsx(s0,{present:i||n.open,children:O.jsx(eqt,{...o,ref:A})}):null});aie.displayName=TZ;var Aqt=OKt("DialogOverlay.RemoveScroll"),eqt=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(TZ,e);return O.jsx(BW,{as:Aqt,allowPinchZoom:!0,shards:[o.contentRef],children:O.jsx(Ha.div,{"data-state":cuA(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),ZF="DialogContent",gie=j.forwardRef((t,A)=>{const e=sie(ZF,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(ZF,t.__scopeDialog);return O.jsx(s0,{present:i||n.open,children:n.modal?O.jsx(tqt,{...o,ref:A}):O.jsx(iqt,{...o,ref:A})})});gie.displayName=ZF;var tqt=j.forwardRef((t,A)=>{const e=Pw(ZF,t.__scopeDialog),i=j.useRef(null),o=Bc(A,e.contentRef,i);return j.useEffect(()=>{const n=i.current;if(n)return AEA(n)},[]),O.jsx(Iie,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:vo(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:vo(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:vo(t.onFocusOutside,n=>n.preventDefault())})}),iqt=j.forwardRef((t,A)=>{const e=Pw(ZF,t.__scopeDialog),i=j.useRef(!1),o=j.useRef(!1);return O.jsx(Iie,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),Iie=j.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Pw(ZF,e),a=j.useRef(null),g=Bc(A,a);return _QA(),O.jsxs(O.Fragment,{children:[O.jsx(P8,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:O.jsx(tH,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":cuA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),O.jsxs(O.Fragment,{children:[O.jsx(nqt,{titleId:r.titleId}),O.jsx(rqt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),IuA="DialogTitle",cie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(IuA,e);return O.jsx(Ha.h2,{id:o.titleId,...i,ref:A})});cie.displayName=IuA;var Bie="DialogDescription",lie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(Bie,e);return O.jsx(Ha.p,{id:o.descriptionId,...i,ref:A})});lie.displayName=Bie;var Cie="DialogClose",Qie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(Cie,e);return O.jsx(Ha.button,{type:"button",...i,ref:A,onClick:vo(t.onClick,()=>o.onOpenChange(!1))})});Qie.displayName=Cie;function cuA(t){return t?"open":"closed"}var Eie="DialogTitleWarning",[oqt,hie]=N3e(Eie,{contentName:ZF,titleName:IuA,docsSlug:"dialog"}),nqt=({titleId:t})=>{const A=hie(Eie),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5622
+ `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return O.jsxs("div",{className:`relative ${A}`,ref:o,children:[O.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&O.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:[O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),O.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Xte=t=>t.activeSubSolver?[t,...Xte(t.activeSubSolver)]:[t],SKt=({solver:t})=>{const A=Xte(t);return O.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>O.jsxs("div",{className:"flex items-center",children:[i>0&&O.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),O.jsx(DKt,{solver:e})]},e.constructor.name))})},bKt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=j.useReducer(Q=>!Q,!1),r=j.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),o&&o(t))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},c=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const E=Q.getCurrentPhase();for(;Q.getCurrentPhase()===E&&!t.solved&&!t.failed;)t.step();A()}},B=()=>{if(t.solved||t.failed||n)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const E=Number(Q);if(!Number.isFinite(E)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<E&&!t.solved&&!t.failed;)t.step();A(),t.solved&&o&&o(t)};j.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),j.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);const l=t.getCurrentPhase!==void 0,C=l?t.getCurrentPhase():null;return O.jsxs("div",{className:"space-y-2 p-2 border-b",children:[O.jsx("div",{className:"flex items-center",children:O.jsx(SKt,{solver:t})}),O.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[O.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),O.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),O.jsx("button",{onClick:I,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),O.jsx("button",{onClick:B,disabled:t.solved||t.failed||n,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"}),l&&O.jsx("button",{onClick:c,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),O.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&O.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",O.jsx("span",{className:"font-medium",children:C})]}),t.solved&&O.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&O.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&O.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},xKt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},kKt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=xKt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="Completed"){const B=t.pipelineDef[A+1],l=B?t.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},GKt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return O.jsx("span",{className:`font-medium ${A[t]}`,children:t})},FKt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:O.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),O.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},RKt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),MKt=({stats:t})=>{if(!t||Object.keys(t).length===0)return O.jsx("span",{children:"-"});const A=Object.entries(t),e=RKt(t);return O.jsxs("details",{className:"cursor-pointer",children:[O.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),O.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>O.jsxs("div",{children:[i,": ",String(o)]},i))})]})},auA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(auA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=auA(i));return A},NKt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=auA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},_Kt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>kKt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):NKt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return O.jsxs("div",{className:"border-t border-gray-200",children:[O.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:O.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),O.jsx("div",{className:"overflow-x-auto",children:O.jsxs("table",{className:"w-full text-sm",children:[O.jsx("thead",{children:O.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),O.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",O.jsx("sub",{children:"0"})]}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),O.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),O.jsx("tbody",{children:i.map(r=>O.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[O.jsx("td",{className:"px-4 py-2",children:O.jsxs("div",{className:"flex items-center gap-2",children:[O.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),O.jsx("button",{onClick:()=>o(r.name),disabled:r.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 ${r.name} completes`,children:O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})})}),O.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(GKt,{status:r.status})}),O.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),O.jsx("td",{className:"px-4 py-2",children:O.jsx(FKt,{progress:r.progress})}),O.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),O.jsx("td",{className:"px-4 py-2 text-gray-500",children:O.jsx(MKt,{stats:r.stats})}),O.jsx("td",{className:"px-4 py-2",children:r.solverInstance?O.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[O.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:O.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"})}),O.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},vKt=class extends Xi.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function UKt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(E,h)=>{typeof E=="number"&&(E<s&&(s=E),E>a&&(a=E)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const E of A)I(E.x,E.y);for(const E of e){const h=E.points??[];for(const u of h)I(u.x,u.y)}for(const E of i){const h=E.x??0,u=E.y??0,d=E.width??0,f=E.height??0;I(h,u),I(h+d,u+f)}for(const E of o){const h=E.x??0,u=E.y??0,d=E.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const E of n)I(E.x,E.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),Q=Math.max(1,g-r+2*c);return O.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((E,h)=>O.jsx("rect",{x:E.x??0,y:E.y??0,width:E.width??0,height:E.height??0,fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`rect-${h}`)),e.map((E,h)=>O.jsx("polyline",{fill:"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1,points:(E.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.fillColor??"none",stroke:E.strokeColor??"black",strokeWidth:E.strokeWidth??1},`circle-${h}`)),A.map((E,h)=>O.jsx("circle",{cx:E.x??0,cy:E.y??0,r:E.radius??1.5,fill:E.color??"black"},`point-${h}`)),n.map((E,h)=>O.jsx("text",{x:E.x??0,y:E.y??0,fontSize:E.fontSize??10,fill:E.color??"black",children:E.text??""},`text-${h}`))]})}var LKt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=j.useReducer(I=>I+1,0),s=j.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[t,o]),r=j.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);j.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=t.pipelineDef!==void 0,g=I=>{const c=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)t.step();n()}};return O.jsxs("div",{children:[O.jsx(bKt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?O.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):O.jsx(vKt,{fallback:O.jsx(UKt,{graphics:s}),children:O.jsx(mKt,{graphics:s})}),a&&O.jsx(_Kt,{solver:t,onStepUntilPhase:g})]})};const HKt=()=>{j.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},YKt=t=>t.toLowerCase().includes("pack")?zSt:t.toLowerCase().includes("rout")?tbt:vSt,JKt=({solverEvents:t=[]})=>{const[A,e]=j.useState(null);HKt();const i=j.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),o=j.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=j.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=ZeA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZeA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?O.jsx("div",{className:"rf-p-4",children:O.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:O.jsxs("div",{className:"rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),O.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."})]})})}):O.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[O.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[O.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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return O.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>e(r),children:(()=>{const I=YKt(a.solverName);return O.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[O.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),O.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[O.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),O.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),O.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?O.jsx(ky,{fallback:O.jsx("div",{className:"rf-p-4",children:O.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),O.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:O.jsx(LKt,{solver:s.instance})}):O.jsxs("div",{className:"rf-p-4",children:[O.jsxs("div",{className:"rf-mb-4",children:[O.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),O.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&O.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:O.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),O.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[O.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:O.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),O.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:O.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):O.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:O.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},$te=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{j.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{j3.captureException(i)}catch{}}},[t,A]),j.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{j3.captureException(o,{error_type:i.type})}catch{}}},[e])},Aie="0.0.1503",TKt={version:Aie},YZ=m1A()(D1A(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),KKt=t=>{const[A,e]=j.useState([]),[i,o]=j.useState(null),[n,s]=j.useState(""),[r,a]=av("eval-version-selection",null),g=YZ(l=>l.setLastRunEvalVersion),I=YZ(l=>l.lastRunEvalVersion);return j.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(l=>l.json()).then(l=>{if(Array.isArray(l?.versions)){let C=[...l.versions];l.tags?.latest&&(o(l.tags.latest),C=C.filter(Q=>Q!==l.tags.latest)),e(C)}}).catch(()=>{})},[t]),j.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:j.useMemo(()=>A.filter(l=>l.includes(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:I,search:n,setSearch:s,selectVersion:l=>{a(l),s("")}}},qKt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=j.useState(""),[s,r]=j.useState("");if(!i)return null;const a=t.filter(c=>c.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),I=c=>{c.key==="Enter"&&(a.length===1?n(a[0]):g&&n(s))};return O.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:O.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[O.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),O.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:c=>r(c.target.value),onKeyDown:I}),O.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(c=>O.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${o===c?"bg-blue-50":""}`,onClick:()=>n(c),children:c},c)),g&&O.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${o===s?"bg-blue-50":""}`,onClick:()=>n(s),children:['Create new "',s,'"']})]}),O.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),O.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},PKt=t=>{const A=j.useRef(null),e=Yc(i=>i.recentEvents);j.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function OKt(t){const A=WKt(t),e=j.forwardRef((i,o)=>{const{children:n,...s}=i,r=j.Children.toArray(n),a=r.find(VKt);if(a){const g=a.props.children,I=r.map(c=>c===a?j.Children.count(g)>1?j.Children.only(null):j.isValidElement(g)?g.props.children:null:c);return O.jsx(A,{...s,ref:o,children:j.isValidElement(g)?j.cloneElement(g,void 0,I):null})}return O.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function WKt(t){const A=j.forwardRef((e,i)=>{const{children:o,...n}=e;if(j.isValidElement(o)){const s=zKt(o),r=jKt(n,o.props);return o.type!==j.Fragment&&(r.ref=i?Vp(i,s):s),j.cloneElement(o,r)}return j.Children.count(o)>1?j.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var ZKt=Symbol("radix.slottable");function VKt(t){return j.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ZKt}function jKt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function zKt(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var JZ="Dialog",[eie,tie]=uw(JZ),[XKt,Pw]=eie(JZ),iie=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=j.useRef(null),a=j.useRef(null),[g,I]=nx({prop:i,defaultProp:o??!1,onChange:n,caller:JZ});return O.jsx(XKt,{scope:A,triggerRef:r,contentRef:a,contentId:Bh(),titleId:Bh(),descriptionId:Bh(),open:g,onOpenChange:I,onOpenToggle:j.useCallback(()=>I(c=>!c),[I]),modal:s,children:e})};iie.displayName=JZ;var oie="DialogTrigger",nie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(oie,e),n=Bc(A,o.triggerRef);return O.jsx(Ha.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":cuA(o.open),...i,ref:n,onClick:vo(t.onClick,o.onOpenToggle)})});nie.displayName=oie;var guA="DialogPortal",[$Kt,sie]=eie(guA,{forceMount:void 0}),rie=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Pw(guA,A);return O.jsx($Kt,{scope:A,forceMount:e,children:j.Children.map(i,s=>O.jsx(s0,{present:e||n.open,children:O.jsx(oW,{asChild:!0,container:o,children:s})}))})};rie.displayName=guA;var TZ="DialogOverlay",aie=j.forwardRef((t,A)=>{const e=sie(TZ,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(TZ,t.__scopeDialog);return n.modal?O.jsx(s0,{present:i||n.open,children:O.jsx(eqt,{...o,ref:A})}):null});aie.displayName=TZ;var Aqt=OKt("DialogOverlay.RemoveScroll"),eqt=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(TZ,e);return O.jsx(BW,{as:Aqt,allowPinchZoom:!0,shards:[o.contentRef],children:O.jsx(Ha.div,{"data-state":cuA(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),ZF="DialogContent",gie=j.forwardRef((t,A)=>{const e=sie(ZF,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Pw(ZF,t.__scopeDialog);return O.jsx(s0,{present:i||n.open,children:n.modal?O.jsx(tqt,{...o,ref:A}):O.jsx(iqt,{...o,ref:A})})});gie.displayName=ZF;var tqt=j.forwardRef((t,A)=>{const e=Pw(ZF,t.__scopeDialog),i=j.useRef(null),o=Bc(A,e.contentRef,i);return j.useEffect(()=>{const n=i.current;if(n)return AEA(n)},[]),O.jsx(Iie,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:vo(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:vo(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:vo(t.onFocusOutside,n=>n.preventDefault())})}),iqt=j.forwardRef((t,A)=>{const e=Pw(ZF,t.__scopeDialog),i=j.useRef(!1),o=j.useRef(!1);return O.jsx(Iie,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),Iie=j.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Pw(ZF,e),a=j.useRef(null),g=Bc(A,a);return _QA(),O.jsxs(O.Fragment,{children:[O.jsx(P8,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:O.jsx(tH,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":cuA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),O.jsxs(O.Fragment,{children:[O.jsx(nqt,{titleId:r.titleId}),O.jsx(rqt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),IuA="DialogTitle",cie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(IuA,e);return O.jsx(Ha.h2,{id:o.titleId,...i,ref:A})});cie.displayName=IuA;var Bie="DialogDescription",lie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(Bie,e);return O.jsx(Ha.p,{id:o.descriptionId,...i,ref:A})});lie.displayName=Bie;var Cie="DialogClose",Qie=j.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Pw(Cie,e);return O.jsx(Ha.button,{type:"button",...i,ref:A,onClick:vo(t.onClick,()=>o.onOpenChange(!1))})});Qie.displayName=Cie;function cuA(t){return t?"open":"closed"}var Eie="DialogTitleWarning",[oqt,hie]=N3e(Eie,{contentName:ZF,titleName:IuA,docsSlug:"dialog"}),nqt=({titleId:t})=>{const A=hie(Eie),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
5623
5623
 
5624
5624
  If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
5625
5625
 
@@ -5757,7 +5757,7 @@ ${a.join(`
5757
5757
  `)}};NA.register(Lae);var PV=class ihe extends NA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const e=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):yE(i));return new ihe(e)}get names(){return[...this._names]}set names(A){this._names=A.map(e=>String(e))}getString(){return`(layers ${this._names.map(e=>/^[^\s()"]+$/u.test(e)&&!["nil","#t","#f"].includes(e)?e:go(e)).join(" ")})`}};NA.register(PV);var LY=class extends NA{_value;quoteStringValue=!1;constructor(t){super(),this._value=t}static fromSexprPrimitives(t){const[A]=t,e=this.parsePrimitiveValue(A),i=this;return new i(e)}static parsePrimitiveValue(t){const A=Ei(t);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(t){this._value=t}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?go(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},Djt=class extends NA{_values;constructor(t){super(),this._values=t}static fromSexprPrimitives(t){const A=t.map(i=>{const o=si(i);if(o===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return o}),e=this;return new e(A)}get values(){return[...this._values]}set values(t){this._values=[...t]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},Sjt=class extends NA{_x;_y;constructor(t,A){super(),this._x=t,this._y=A}static fromSexprPrimitives(t){const[A,e]=t,i=si(A),o=si(e);if(i===void 0||o===void 0)throw new Error(`${this.name} expects two numeric values`);const n=this;return new n(i,o)}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},ur=class extends LY{static parentToken="pcbplotparams"},Ky=class extends ur{static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},Hae=class extends ur{static token="layerselection";token="layerselection"};NA.register(Hae);var Yae=class extends ur{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};NA.register(Yae);var Jae=class extends Ky{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};NA.register(Jae);var Tae=class extends Ky{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};NA.register(Tae);var Kae=class extends Ky{static token="svgprecision";token="svgprecision"};NA.register(Kae);var qae=class extends Ky{static token="linewidth";token="linewidth"};NA.register(qae);var Pae=class extends Ky{static token="mode";token="mode"};NA.register(Pae);var Oae=class extends Ky{static token="hpglpennumber";token="hpglpennumber"};NA.register(Oae);var Wae=class extends Ky{static token="hpglpenspeed";token="hpglpenspeed"};NA.register(Wae);var Zae=class extends Ky{static token="hpglpendiameter";token="hpglpendiameter"};NA.register(Zae);var Vae=class extends Ky{static token="hpglpenoverlay";token="hpglpenoverlay"};NA.register(Vae);var jae=class extends Ky{static token="outputformat";token="outputformat"};NA.register(jae);var zae=class extends Ky{static token="drillshape";token="drillshape"};NA.register(zae);var Xae=class extends Ky{static token="scaleselection";token="scaleselection"};NA.register(Xae);var $ae=class extends ur{static token="disableapertmacros";token="disableapertmacros"};NA.register($ae);var Age=class extends ur{static token="usegerberextensions";token="usegerberextensions"};NA.register(Age);var ege=class extends ur{static token="usegerberattributes";token="usegerberattributes"};NA.register(ege);var tge=class extends ur{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};NA.register(tge);var ige=class extends ur{static token="creategerberjobfile";token="creategerberjobfile"};NA.register(ige);var oge=class extends ur{static token="excludeedgelayer";token="excludeedgelayer"};NA.register(oge);var nge=class extends ur{static token="plotframeref";token="plotframeref"};NA.register(nge);var sge=class extends ur{static token="viasonmask";token="viasonmask"};NA.register(sge);var rge=class extends ur{static token="useauxorigin";token="useauxorigin"};NA.register(rge);var age=class extends ur{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};NA.register(age);var gge=class extends ur{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};NA.register(gge);var Ige=class extends ur{static token="pdf_metadata";token="pdf_metadata"};NA.register(Ige);var cge=class extends ur{static token="pdf_single_document";token="pdf_single_document"};NA.register(cge);var Bge=class extends ur{static token="dxfpolygonmode";token="dxfpolygonmode"};NA.register(Bge);var lge=class extends ur{static token="dxfimperialunits";token="dxfimperialunits"};NA.register(lge);var Cge=class extends ur{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};NA.register(Cge);var Qge=class extends ur{static token="psnegative";token="psnegative"};NA.register(Qge);var Ege=class extends ur{static token="psa4output";token="psa4output"};NA.register(Ege);var hge=class extends ur{static token="plotreference";token="plotreference"};NA.register(hge);var uge=class extends ur{static token="plotvalue";token="plotvalue"};NA.register(uge);var dge=class extends ur{static token="plotothertext";token="plotothertext"};NA.register(dge);var pge=class extends ur{static token="plotinvisibletext";token="plotinvisibletext"};NA.register(pge);var fge=class extends ur{static token="padsonsilk";token="padsonsilk"};NA.register(fge);var yge=class extends ur{static token="sketchpadsonfab";token="sketchpadsonfab"};NA.register(yge);var wge=class extends ur{static token="plotpadnumbers";token="plotpadnumbers"};NA.register(wge);var mge=class extends ur{static token="hidednponfab";token="hidednponfab"};NA.register(mge);var Dge=class extends ur{static token="sketchdnponfab";token="sketchdnponfab"};NA.register(Dge);var Sge=class extends ur{static token="crossoutdnponfab";token="crossoutdnponfab"};NA.register(Sge);var bge=class extends ur{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};NA.register(bge);var xge=class extends ur{static token="plot_black_and_white";token="plot_black_and_white"};NA.register(xge);var kge=class extends ur{static token="mirror";token="mirror"};NA.register(kge);var Gge=class extends ur{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};NA.register(Gge);var Fge=class extends ur{static token="plot_on_all_layers";token="plot_on_all_layers"};NA.register(Fge);var Rge=class extends ur{static token="plotinvisible";token="plotinvisible"};NA.register(Rge);var bjt={layerselection:"layerselection",plot_on_all_layers_selection:"plot_on_all_layers_selection",disableapertmacros:"disableapertmacros",usegerberextensions:"usegerberextensions",usegerberattributes:"usegerberattributes",usegerberadvancedattributes:"usegerberadvancedattributes",creategerberjobfile:"creategerberjobfile",excludeedgelayer:"excludeedgelayer",dashed_line_dash_ratio:"dashed_line_dash_ratio",dashed_line_gap_ratio:"dashed_line_gap_ratio",svgprecision:"svgprecision",linewidth:"linewidth",plotframeref:"plotframeref",plotreference:"plotreference",plotvalue:"plotvalue",plotothertext:"plotothertext",plotinvisibletext:"plotinvisibletext",padsonsilk:"padsonsilk",sketchpadsonfab:"sketchpadsonfab",plotpadnumbers:"plotpadnumbers",hidednponfab:"hidednponfab",sketchdnponfab:"sketchdnponfab",crossoutdnponfab:"crossoutdnponfab",subtractmaskfromsilk:"subtractmaskfromsilk",plot_black_and_white:"plot_black_and_white",plot_on_all_layers:"plot_on_all_layers",plotinvisible:"plotinvisible",mode:"mode",useauxorigin:"useauxorigin",viasonmask:"viasonmask",hpglpennumber:"hpglpennumber",hpglpenspeed:"hpglpenspeed",hpglpendiameter:"hpglpendiameter",hpglpenoverlay:"hpglpenoverlay",pdf_front_fp_property_popups:"pdf_front_fp_property_popups",pdf_back_fp_property_popups:"pdf_back_fp_property_popups",pdf_metadata:"pdf_metadata",pdf_single_document:"pdf_single_document",dxfpolygonmode:"dxfpolygonmode",dxfimperialunits:"dxfimperialunits",dxfusepcbnewfont:"dxfusepcbnewfont",psnegative:"psnegative",psa4output:"psa4output",mirror:"mirror",outputformat:"outputformat",drillshape:"drillshape",scaleselection:"scaleselection",outputdirectory:"outputdirectory"},xjt=["layerselection","plot_on_all_layers_selection","disableapertmacros","usegerberextensions","usegerberattributes","usegerberadvancedattributes","creategerberjobfile","excludeedgelayer","dashed_line_dash_ratio","dashed_line_gap_ratio","svgprecision","linewidth","plotframeref","plotreference","plotvalue","plotothertext","mode","useauxorigin","viasonmask","hpglpennumber","hpglpenspeed","hpglpendiameter","hpglpenoverlay","pdf_front_fp_property_popups","pdf_back_fp_property_popups","pdf_metadata","pdf_single_document","dxfpolygonmode","dxfimperialunits","dxfusepcbnewfont","psnegative","psa4output","plot_black_and_white","plot_on_all_layers","plotinvisible","plotinvisibletext","padsonsilk","sketchpadsonfab","plotpadnumbers","hidednponfab","sketchdnponfab","crossoutdnponfab","subtractmaskfromsilk","outputformat","mirror","drillshape","scaleselection","outputdirectory"],XfA=class ohe extends NA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const e=new ohe,{propertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);for(const[o,n]of Object.entries(i)){const s=bjt[o];if(!s)throw new Error(`Unsupported pcbplotparams token: ${o}`);e._properties[s]=n}return e}getChildren(){const A=[];for(const e of xjt){const i=this._properties[e];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}setNumberProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}setStringOrNumberProperty(A,e,i){if(e===void 0){this.clearProperty(A);return}this._properties[A]=new i(e)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,Hae)}get plot_on_all_layers_selection(){return this._properties.plot_on_all_layers_selection?.value}set plot_on_all_layers_selection(A){this.setStringOrNumberProperty("plot_on_all_layers_selection",A,Yae)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,$ae)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,Age)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,ege)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,tge)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,ige)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,oge)}get dashed_line_dash_ratio(){return this._properties.dashed_line_dash_ratio?.value}set dashed_line_dash_ratio(A){this.setNumberProperty("dashed_line_dash_ratio",A,Jae)}get dashed_line_gap_ratio(){return this._properties.dashed_line_gap_ratio?.value}set dashed_line_gap_ratio(A){this.setNumberProperty("dashed_line_gap_ratio",A,Tae)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,Kae)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,qae)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,nge)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,hge)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,uge)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,dge)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,pge)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,fge)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,wge)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,yge)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,mge)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,Dge)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,Sge)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,bge)}get plot_black_and_white(){return this._properties.plot_black_and_white?.value}set plot_black_and_white(A){this.setStringProperty("plot_black_and_white",A,xge)}get plot_on_all_layers(){return this._properties.plot_on_all_layers?.value}set plot_on_all_layers(A){this.setStringProperty("plot_on_all_layers",A,Fge)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,Rge)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,Pae)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,rge)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,sge)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,Oae)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,Wae)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,Zae)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,Vae)}get pdf_front_fp_property_popups(){return this._properties.pdf_front_fp_property_popups?.value}set pdf_front_fp_property_popups(A){this.setStringProperty("pdf_front_fp_property_popups",A,age)}get pdf_back_fp_property_popups(){return this._properties.pdf_back_fp_property_popups?.value}set pdf_back_fp_property_popups(A){this.setStringProperty("pdf_back_fp_property_popups",A,gge)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,Ige)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,cge)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,Bge)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,lge)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,Cge)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,Qge)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,Ege)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,kge)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,jae)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,zae)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,Xae)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,Gge)}};NA.register(XfA);var OV=class extends LY{static parentToken="setup"},$fA=class extends OV{static token="zone_45_only";token="zone_45_only"};NA.register($fA);var A0A=class extends OV{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};NA.register(A0A);var e0A=class extends OV{static token="visible_elements";token="visible_elements"};NA.register(e0A);var t0A=class extends OV{static token="uvias_allowed";token="uvias_allowed"};NA.register(t0A);var i0A=class nhe extends NA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const e=A.map(i=>Ei(i)).filter(i=>i!==void 0);return new nhe(e)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(e=>String(e))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};NA.register(i0A);var HY=class extends Djt{static parentToken="setup"},Mge=class extends Sjt{static parentToken="setup"},o0A=class extends HY{static token="pcb_text_size";token="pcb_text_size"};NA.register(o0A);var n0A=class extends HY{static token="mod_text_size";token="mod_text_size"};NA.register(n0A);var s0A=class extends HY{static token="pad_size";token="pad_size"};NA.register(s0A);var r0A=class extends HY{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};NA.register(r0A);var a0A=class extends HY{static token="trace_width";token="trace_width"};NA.register(a0A);var g0A=class extends Mge{static token="aux_axis_origin";token="aux_axis_origin"};NA.register(g0A);var I0A=class extends Mge{static token="grid_origin";token="grid_origin"};NA.register(I0A);var il=class extends LY{static parentToken="setup";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},c0A=class extends il{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};NA.register(c0A);var B0A=class extends il{static token="solder_mask_min_width";token="solder_mask_min_width"};NA.register(B0A);var l0A=class extends il{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};NA.register(l0A);var C0A=class extends il{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};NA.register(C0A);var Q0A=class extends il{static token="last_trace_width";token="last_trace_width"};NA.register(Q0A);var E0A=class extends il{static token="trace_clearance";token="trace_clearance"};NA.register(E0A);var h0A=class extends il{static token="zone_clearance";token="zone_clearance"};NA.register(h0A);var u0A=class extends il{static token="trace_min";token="trace_min"};NA.register(u0A);var d0A=class extends il{static token="segment_width";token="segment_width"};NA.register(d0A);var p0A=class extends il{static token="edge_width";token="edge_width"};NA.register(p0A);var f0A=class extends il{static token="via_size";token="via_size"};NA.register(f0A);var y0A=class extends il{static token="via_drill";token="via_drill"};NA.register(y0A);var w0A=class extends il{static token="via_min_size";token="via_min_size"};NA.register(w0A);var m0A=class extends il{static token="via_min_drill";token="via_min_drill"};NA.register(m0A);var D0A=class extends il{static token="uvia_size";token="uvia_size"};NA.register(D0A);var S0A=class extends il{static token="uvia_drill";token="uvia_drill"};NA.register(S0A);var b0A=class extends il{static token="uvia_min_size";token="uvia_min_size"};NA.register(b0A);var x0A=class extends il{static token="uvia_min_drill";token="uvia_min_drill"};NA.register(x0A);var k0A=class extends il{static token="pcb_text_width";token="pcb_text_width"};NA.register(k0A);var G0A=class extends il{static token="mod_edge_width";token="mod_edge_width"};NA.register(G0A);var F0A=class extends il{static token="mod_text_width";token="mod_text_width"};NA.register(F0A);var R0A=class extends il{static token="pad_drill";token="pad_drill"};NA.register(R0A);var YY=class extends LY{static parentToken="stackup"},Nge=class extends YY{static token="copper_finish";token="copper_finish";quoteStringValue=!0};NA.register(Nge);var _ge=class extends YY{static token="dielectric_constraints";token="dielectric_constraints"};NA.register(_ge);var vge=class extends YY{static token="edge_connector";token="edge_connector"};NA.register(vge);var Uge=class extends YY{static token="castellated_pads";token="castellated_pads"};NA.register(Uge);var Lge=class extends YY{static token="edge_plating";token="edge_plating"};NA.register(Lge);var vv=class extends LY{static parentToken="layer"},M0A=class extends vv{static token="type";token="type";quoteStringValue=!0};NA.register(M0A);var N0A=class extends vv{static token="color";token="color";quoteStringValue=!0};NA.register(N0A);var _0A=class extends vv{static token="thickness";token="thickness";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};NA.register(_0A);var v0A=class extends vv{static token="material";token="material";quoteStringValue=!0};NA.register(v0A);var U0A=class extends vv{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};NA.register(U0A);var L0A=class extends vv{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(t){const A=si(t);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};NA.register(L0A);var Hge=class she extends NA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,e={}){super(),this._name=A,this._number=e.number,this._sxType=e.type,this._sxColor=e.color,this._sxThickness=e.thickness,this._sxMaterial=e.material,this._sxEpsilonR=e.epsilonR,this._sxLossTangent=e.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const e=Ei(A[0]);if(e===void 0)throw new Error("Stackup layer name must be a string");let i=1,o;const n=A[i],s=si(n);s!==void 0&&(o=s,i+=1);const r=A.slice(i),{propertyMap:a}=NA.parsePrimitivesToClassProperties(r,this.token);return new she(e,{number:o,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const e=Ei(A);if(e===void 0)throw new Error("Stackup layer name must be a string");this._name=e}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const e=si(A);if(e===void 0)throw new Error("Stackup layer number must be numeric");this._number=e}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof M0A?A:new M0A(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof N0A?A:new N0A(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof _0A?A:new _0A(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof v0A?A:new v0A(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof U0A?A:new U0A(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof L0A?A:new L0A(A)}getChildren(){const A=[];return this._sxType&&A.push(this._sxType),this._sxColor&&A.push(this._sxColor),this._sxThickness&&A.push(this._sxThickness),this._sxMaterial&&A.push(this._sxMaterial),this._sxEpsilonR&&A.push(this._sxEpsilonR),this._sxLossTangent&&A.push(this._sxLossTangent),A}getString(){const A=`(layer ${go(this._name)}${this._number!==void 0?` ${this._number}`:""}`,e=this.getChildren();if(e.length===0)return`${A})`;const i=[A];for(const o of e)i.push(o.getStringIndented());return i.push(")"),i.join(`
5758
5758
  `)}};NA.register(Hge);var H0A=class rhe extends NA{static token="stackup";static parentToken="setup";token="stackup";_layers=[];_sxCopperFinish;_sxDielectricConstraints;_sxEdgeConnector;_sxCastellatedPads;_sxEdgePlating;constructor(A={}){super(),this.layers=A.layers??[],this._sxCopperFinish=A.copperFinish,this._sxDielectricConstraints=A.dielectricConstraints,this._sxEdgeConnector=A.edgeConnector,this._sxCastellatedPads=A.castellatedPads,this._sxEdgePlating=A.edgePlating}static fromSexprPrimitives(A){const{propertyMap:e,arrayPropertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);return new rhe({layers:i.layer??[],copperFinish:e.copper_finish,dielectricConstraints:e.dielectric_constraints,edgeConnector:e.edge_connector,castellatedPads:e.castellated_pads,edgePlating:e.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(e=>{if(!(e instanceof Hge))throw new Error("Stackup layers must be StackupLayer instances");return e})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new Nge(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new _ge(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new vge(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new Uge(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new Lge(A):void 0}getChildren(){const A=[...this._layers],e=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of e)i&&A.push(i);return A}};NA.register(H0A);var kjt={stackup:"stackup",pcbplotparams:"pcbPlotParams",pad_to_mask_clearance:"padToMaskClearance",solder_mask_min_width:"solderMaskMinWidth",pad_to_paste_clearance:"padToPasteClearance",pad_to_paste_clearance_ratio:"padToPasteClearanceRatio",last_trace_width:"lastTraceWidth",trace_clearance:"traceClearance",zone_clearance:"zoneClearance",zone_45_only:"zone45Only",trace_min:"traceMin",segment_width:"segmentWidth",edge_width:"edgeWidth",via_size:"viaSize",via_drill:"viaDrill",via_min_size:"viaMinSize",via_min_drill:"viaMinDrill",uvias_allowed:"uviasAllowed",uvia_size:"uviaSize",uvia_drill:"uviaDrill",uvia_min_size:"uviaMinSize",uvia_min_drill:"uviaMinDrill",pcb_text_width:"pcbTextWidth",pcb_text_size:"pcbTextSize",mod_edge_width:"modEdgeWidth",mod_text_size:"modTextSize",mod_text_width:"modTextWidth",pad_size:"padSize",pad_drill:"padDrill",allow_soldermask_bridges_in_footprints:"allowSoldermaskBridgesInFootprints",tenting:"tenting",aux_axis_origin:"auxAxisOrigin",grid_origin:"gridOrigin",visible_elements:"visibleElements",pad_to_paste_clearance_values:"padToPasteClearanceValues",trace_width:"traceWidth"},Gjt=["stackup","padToMaskClearance","solderMaskMinWidth","padToPasteClearance","padToPasteClearanceRatio","lastTraceWidth","traceClearance","zoneClearance","zone45Only","traceMin","segmentWidth","edgeWidth","viaSize","viaDrill","viaMinSize","viaMinDrill","uviaSize","uviaDrill","uviasAllowed","uviaMinSize","uviaMinDrill","pcbTextWidth","pcbTextSize","modEdgeWidth","modTextSize","modTextWidth","padSize","padDrill","allowSoldermaskBridgesInFootprints","tenting","auxAxisOrigin","gridOrigin","visibleElements","padToPasteClearanceValues","traceWidth","pcbPlotParams"],Y0A=class ahe extends NA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const e=new ahe,{propertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);for(const[o,n]of Object.entries(i)){const s=kjt[o];if(!s)throw new Error(`Unsupported setup property token: ${o}`);e._properties[s]=n}return e}getChildren(){const A=[];for(const e of Gjt){const i=this._properties[e];i&&A.push(i)}return A}setProperty(A,e){if(e){this._properties[A]=e;return}delete this._properties[A]}setNumberProperty(A,e,i){if(e===void 0){delete this._properties[A];return}this._properties[A]=new i(e)}getPropertyInstance(A,e){const i=this._properties[A];return i instanceof e?i:void 0}get stackup(){return this.getPropertyInstance("stackup",H0A)}set stackup(A){if(A!==void 0&&!(A instanceof H0A))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",XfA)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof XfA))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",c0A)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,c0A)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",B0A)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,B0A)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",l0A)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,l0A)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",C0A)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,C0A)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",Q0A)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,Q0A)}get traceClearance(){return this.getPropertyInstance("traceClearance",E0A)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,E0A)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",h0A)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,h0A)}get zone45Only(){return this.getPropertyInstance("zone45Only",$fA)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new $fA(A))}get traceMin(){return this.getPropertyInstance("traceMin",u0A)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,u0A)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",d0A)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,d0A)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",p0A)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,p0A)}get viaSize(){return this.getPropertyInstance("viaSize",f0A)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,f0A)}get viaDrill(){return this.getPropertyInstance("viaDrill",y0A)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,y0A)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",w0A)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,w0A)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",m0A)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,m0A)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",t0A)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new t0A(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",D0A)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,D0A)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",S0A)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,S0A)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",b0A)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,b0A)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",x0A)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,x0A)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",k0A)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,k0A)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",o0A)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new o0A(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",G0A)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,G0A)}get modTextSize(){return this.getPropertyInstance("modTextSize",n0A)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new n0A(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",F0A)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,F0A)}get padSize(){return this.getPropertyInstance("padSize",s0A)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new s0A(A))}get padDrill(){return this.getPropertyInstance("padDrill",R0A)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,R0A)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",A0A)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new A0A(A))}get tenting(){return this.getPropertyInstance("tenting",i0A)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new i0A(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",g0A);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new g0A(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",I0A);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new I0A(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",e0A)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new e0A(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",r0A)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new r0A(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",a0A)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new a0A(A))}};NA.register(Y0A);var Yge=class extends ta{static token="thickness";static parentToken="general";token="thickness"};NA.register(Yge);var Jge=class ghe extends NA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const e=Ei(A[0]);if(e===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(e);return new ghe(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};NA.register(Jge);var Tge=new Set(["thickness","legacy_teardrops"]),J0A=class Ihe extends NA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const e=new Ihe,{propertyMap:i,arrayPropertyMap:o}=NA.parsePrimitivesToClassProperties(A,this.token);for(const n of Object.keys(i))if(!Tge.has(n))throw new Error(`general encountered unsupported child token "${n}"`);for(const[n,s]of Object.entries(o)){if(!Tge.has(n))throw new Error(`general encountered unsupported child token "${n}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${n}"`)}return e._sxThickness=o.thickness?.[0]??i.thickness,e._sxLegacyTeardrops=o.legacy_teardrops?.[0]??i.legacy_teardrops,e}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new Yge(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new Jge(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};NA.register(J0A);var ol=class che extends NA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[e,i,o,n]=A,s=si(e),r=Ei(i),a=Ei(o),g=n===void 0?void 0:Ei(n);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new che({index:s,name:r,type:a,userName:g})}get index(){return this._index}set index(A){this._index=A}get name(){return this._name}set name(A){this._name=A}get type(){return this._type}set type(A){this._type=A}get userName(){return this._userName}set userName(A){this._userName=A}getChildren(){return[]}getString(){if(this._index===void 0||this._name===void 0||this._type===void 0)return"()";const A=[String(this._index),go(this._name),this._type];return this._userName!==void 0&&A.push(go(this._userName)),`(${A.join(" ")})`}};NA.register(ol);var T0A=class Bhe extends NA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const e=new Bhe;return e._definitions=A.map(i=>ol.fromPrimitive(i)),e}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};NA.register(T0A);var WV=class lhe extends NA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const e=si(A[0]),i=Ei(A[1]);if(e===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new lhe(e,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return`(net ${this._id} ${go(this._name)})`}};NA.register(WV);var K0A=class extends ta{static token="version";static parentToken="kicad_pcb";token="version"};NA.register(K0A);var Fjt=t=>/^[A-Za-z0-9._-]+$/.test(t),q0A=class extends Jy{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${Fjt(this.value)?this.value:go(this.value)})`}};NA.register(q0A);var Rjt=t=>/^[A-Za-z0-9._-]+$/.test(t),P0A=class extends Jy{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${Rjt(this.value)?this.value:go(this.value)})`}};NA.register(P0A);var O0A=class Che extends NA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const e=si(A[0]);if(e===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?Ei(A[1]):void 0;return new Che(e,i)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A}getChildren(){return[]}getString(){return this._name!==void 0?`(net ${this._id} ${go(this._name)})`:`(net ${this._id})`}};NA.register(O0A);var Mjt=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),W0A=class Qhe extends NA{static token="via";token="via";_type;_locked=!1;_free=!1;_removeUnusedLayers=!1;_keepEndLayers=!1;_sxAt;_size;_drill;_sxLayers;_sxNet;_sxUuid;_sxTstamp;_sxTeardrops;constructor(A={}){super(),A.type!==void 0&&(this.type=A.type),A.locked!==void 0&&(this.locked=A.locked),A.free!==void 0&&(this.free=A.free),A.removeUnusedLayers!==void 0&&(this.removeUnusedLayers=A.removeUnusedLayers),A.keepEndLayers!==void 0&&(this.keepEndLayers=A.keepEndLayers),A.at!==void 0&&(this.at=A.at),A.size!==void 0&&(this.size=A.size),A.drill!==void 0&&(this.drill=A.drill),A.layers!==void 0&&(this.layers=A.layers),A.net!==void 0&&(this.net=A.net),A.uuid!==void 0&&(this.uuid=A.uuid),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.teardrops!==void 0&&(this.teardrops=A.teardrops)}static fromSexprPrimitives(A){const e=new Qhe;for(const i of A){if(typeof i=="string"){e.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[o,...n]=i;if(typeof o!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);e.consumeNode(o,n)}return e}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!Mjt.has(A))throw new Error(`via encountered unsupported flag "${A}"`);switch(A){case"locked":this._locked=!0;break;case"free":this._free=!0;break;case"remove_unused_layers":this._removeUnusedLayers=!0;break;case"keep_end_layers":this._keepEndLayers=!0;break}}consumeNode(A,e){switch(A){case"type":{const i=Ei(e[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(e);return;case"free":this._free=this.parseYesNo(e);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(e);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(e);return;case"at":{const i=NA.parsePrimitiveSexpr(["at",...e],{parentToken:this.token});if(!(i instanceof EI))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=si(e[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=si(e[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=PV.fromSexprPrimitives(e);return}case"net":{this._sxNet=O0A.fromSexprPrimitives(e);return}case"teardrops":{this._sxTeardrops=cae.fromSexprPrimitives(e);return}case"uuid":{const i=Ei(e[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new Ni(i);return}case"tstamp":{const i=Ei(e[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new jg(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const e=Ei(A[0]);if(e===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(e)}get type(){return this._type}set type(A){this._type=A}get locked(){return this._locked}set locked(A){this._locked=A}get free(){return this._free}set free(A){this._free=A}get removeUnusedLayers(){return this._removeUnusedLayers}set removeUnusedLayers(A){this._removeUnusedLayers=A}get keepEndLayers(){return this._keepEndLayers}set keepEndLayers(A){this._keepEndLayers=A}get at(){return this._sxAt}set at(A){this._sxAt=A!==void 0?EI.from(A):void 0}get size(){return this._size}set size(A){this._size=A}get drill(){return this._drill}set drill(A){this._drill=A}get layers(){return this._sxLayers}set layers(A){if(A===void 0){this._sxLayers=void 0;return}this._sxLayers=A instanceof PV?A:new PV(A)}get net(){return this._sxNet}set net(A){this._sxNet=A}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof Ni?A:new Ni(A)}get teardrops(){return this._sxTeardrops}set teardrops(A){this._sxTeardrops=A}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof jg?A:new jg(A)}getChildren(){const A=[];return this._sxAt&&A.push(this._sxAt),this._sxLayers&&A.push(this._sxLayers),this._sxNet&&A.push(this._sxNet),this._sxUuid&&A.push(this._sxUuid),this._sxTstamp&&A.push(this._sxTstamp),this._sxTeardrops&&A.push(this._sxTeardrops),A}getString(){const A=["(via"];return this._type!==void 0&&A.push(` (type ${this._type})`),this._locked&&A.push(" (locked)"),this._free&&A.push(" (free)"),this._removeUnusedLayers&&A.push(" (remove_unused_layers)"),this._keepEndLayers&&A.push(" (keep_end_layers)"),this._sxAt&&A.push(this._sxAt.getStringIndented()),this._size!==void 0&&A.push(` (size ${this._size})`),this._drill!==void 0&&A.push(` (drill ${this._drill})`),this._sxLayers&&A.push(this._sxLayers.getStringIndented()),this._sxNet&&A.push(this._sxNet.getStringIndented()),this._sxUuid&&A.push(this._sxUuid.getStringIndented()),this._sxTstamp&&A.push(this._sxTstamp.getStringIndented()),this._sxTeardrops&&A.push(this._sxTeardrops.getStringIndented()),A.push(")"),A.join(`
5759
5759
  `)}};NA.register(W0A);var Z0A=class Ehe extends NA{static token="kicad_pcb";token="kicad_pcb";_sxVersion;_sxGenerator;_sxGeneratorVersion;_sxGeneral;_sxPaper;_sxTitleBlock;_sxLayers;_sxSetup;_properties=[];_nets=[];_footprints=[];_images=[];_segments=[];_grLines=[];_grTexts=[];_grPolys=[];_grRects=[];_vias=[];_zones=[];_otherChildren=[];constructor(A={}){super(),A.version!==void 0&&(this.version=A.version),A.generator!==void 0&&(this.generator=A.generator),A.generatorVersion!==void 0&&(this.generatorVersion=A.generatorVersion),A.general!==void 0&&(this.general=A.general),A.paper!==void 0&&(this.paper=A.paper),A.titleBlock!==void 0&&(this.titleBlock=A.titleBlock),A.layers!==void 0&&(this.layers=A.layers),A.setup!==void 0&&(this.setup=A.setup),A.properties!==void 0&&(this.properties=A.properties),A.nets!==void 0&&(this.nets=A.nets),A.footprints!==void 0&&(this.footprints=A.footprints),A.images!==void 0&&(this.images=A.images),A.segments!==void 0&&(this.segments=A.segments),A.graphicLines!==void 0&&(this.graphicLines=A.graphicLines),A.graphicTexts!==void 0&&(this.graphicTexts=A.graphicTexts),A.graphicPolys!==void 0&&(this.graphicPolys=A.graphicPolys),A.graphicRects!==void 0&&(this.graphicRects=A.graphicRects),A.vias!==void 0&&(this.vias=A.vias),A.zones!==void 0&&(this.zones=A.zones),A.otherChildren!==void 0&&(this.otherChildren=A.otherChildren)}static fromSexprPrimitives(A){const e=new Ehe;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const o=NA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(o instanceof NA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(o)}return e}consumeChild(A){if(A instanceof K0A){this._sxVersion=A;return}if(A instanceof q0A){this._sxGenerator=A;return}if(A instanceof P0A){this._sxGeneratorVersion=A;return}if(A instanceof J0A){this._sxGeneral=A;return}if(A instanceof RV){this._sxPaper=A;return}if(A instanceof Kse){this._sxTitleBlock=A;return}if(A instanceof T0A){this._sxLayers=A;return}if(A instanceof Y0A){this._sxSetup=A;return}if(A instanceof ure){this._properties.push(A);return}if(A instanceof WV){this._nets.push(A);return}if(A instanceof UfA){this._footprints.push(A);return}if(A instanceof Pse){this._images.push(A);return}if(A instanceof zfA){this._segments.push(A);return}if(A instanceof KV){this._grLines.push(A);return}if(A instanceof OfA){this._grTexts.push(A);return}if(A instanceof Rae){this._grPolys.push(A);return}if(A instanceof kae){this._grRects.push(A);return}if(A instanceof W0A){this._vias.push(A);return}if(A instanceof Lae){this._zones.push(A);return}this._otherChildren.push(A)}get version(){return this._sxVersion?.value}set version(A){this._sxVersion=A===void 0?void 0:new K0A(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new q0A(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new P0A(A)}get general(){return this._sxGeneral}set general(A){this._sxGeneral=A}get paper(){return this._sxPaper}set paper(A){this._sxPaper=A}get titleBlock(){return this._sxTitleBlock}set titleBlock(A){this._sxTitleBlock=A}get layers(){return this._sxLayers}set layers(A){this._sxLayers=A}get setup(){return this._sxSetup}set setup(A){this._sxSetup=A}get properties(){return[...this._properties]}set properties(A){this._properties=[...A]}get nets(){return[...this._nets]}set nets(A){this._nets=[...A]}get footprints(){return[...this._footprints]}set footprints(A){this._footprints=[...A]}get images(){return[...this._images]}set images(A){this._images=[...A]}get segments(){return[...this._segments]}set segments(A){this._segments=[...A]}get graphicLines(){return[...this._grLines]}set graphicLines(A){this._grLines=[...A]}get graphicTexts(){return[...this._grTexts]}set graphicTexts(A){this._grTexts=[...A]}get graphicPolys(){return[...this._grPolys]}set graphicPolys(A){this._grPolys=[...A]}get graphicRects(){return[...this._grRects]}set graphicRects(A){this._grRects=[...A]}get vias(){return[...this._vias]}set vias(A){this._vias=[...A]}get zones(){return[...this._zones]}set zones(A){this._zones=[...A]}get otherChildren(){return[...this._otherChildren]}set otherChildren(A){this._otherChildren=[...A]}getChildren(){const A=[];return this._sxVersion&&A.push(this._sxVersion),this._sxGenerator&&A.push(this._sxGenerator),this._sxGeneratorVersion&&A.push(this._sxGeneratorVersion),this._sxGeneral&&A.push(this._sxGeneral),this._sxPaper&&A.push(this._sxPaper),this._sxTitleBlock&&A.push(this._sxTitleBlock),this._sxLayers&&A.push(this._sxLayers),this._sxSetup&&A.push(this._sxSetup),A.push(...this._properties),A.push(...this._nets),A.push(...this._footprints),A.push(...this._images),A.push(...this._segments),A.push(...this._grLines),A.push(...this._grTexts),A.push(...this._grPolys),A.push(...this._grRects),A.push(...this._vias),A.push(...this._zones),A.push(...this._otherChildren),A}};NA.register(Z0A);var Kge=t=>NA.parse(t),Dh=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(t,A){this.input=t,this.ctx=A}step(){if(this.iteration++,this.iteration>this.MAX_ITERATIONS)throw new Error("Max iterations reached");this._step()}_step(){throw new Error("Not implemented")}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){throw new Error("Not implemented")}},Njt=class extends Dh{_step(){const{kicadSch:t,schematicPaperSize:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");t.version=20250114;const e=new RV;e.size=A?.name??"A4",t.paper=e,t.uuid=new Ni(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function ZV(t,A){if(t.manufacturer_part_number)return V0A(t.manufacturer_part_number);const e=_jt(t.ftype),i=A?.footprinter_string;return V0A(i?`${e}_${i}`:e)}function _jt(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function V0A(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function vjt(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}function qge(t){return t in BQ}function Pge(t,A,e){if(t.type!=="source_component")return A.symbol_name?qge(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return qge(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const i=ZV(t,e);return`Device:${vjt(t.name)}_${i}`}var Ujt=class extends Dh{_step(){const{kicadSch:t,db:A}=this.ctx,e=new Ire,i=[],o=A.schematic_component.list();for(const s of o){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const n=A.schematic_net_label?.list?.()||[];for(const s of n)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const I=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});I&&i.push(I)}}e.symbols=i,t&&(t.libSymbols=e),this.finished=!0}createLibrarySymbolForComponent(t){const{db:A}=this.ctx,e=t.source_component_id?A.source_component.get(t.source_component_id):null;if(!e)return null;const i=A.cad_component?.list()?.find(g=>g.source_component_id===e.source_component_id),o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const n=this.getSymbolData(o,t);if(!n)return null;const s=Pge(e,t,i),r=e.ftype==="simple_chip",a=ZV(e,i);return this.createLibrarySymbol({libId:s,symbolData:n,isChip:r,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:a?`tscircuit:${a}`:""})}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const o=BQ[i];if(!o)return null;const n=`Custom:${i}`;return this.createLibrarySymbol({libId:n,symbolData:o,isChip:!1,schematicComponent:void 0,description:A?"Power net label":e?"Ground net label":"Net symbol",keywords:A?"power net":e?"ground net":"net",fpFilters:""})}getSymbolData(t,A){return t.startsWith("generic_chip_")?this.createGenericChipSymbolData(A,this.ctx.db):BQ[t]||null}createGenericChipSymbolData(t,A){const e=A.schematic_port.list().filter(r=>r.schematic_component_id===t.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=t.size?.width||1.5,o=t.size?.height||1,n={type:"path",points:[{x:-i/2,y:-o/2},{x:i/2,y:-o/2},{x:i/2,y:o/2},{x:-i/2,y:o/2},{x:-i/2,y:-o/2}]},s=e.map(r=>{const a=r.center.x-t.center.x,g=r.center.y-t.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[n],ports:s,size:{width:i,height:o}}}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:o,keywords:n,fpFilters:s,footprintRef:r=""}){const a=new Mv({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),g=new jse;g.hide=!e,a._sxPinNumbers=g;const I=new zse;I.offset=e?1.27:0,a._sxPinNames=I,this.addSymbolProperties({symbol:a,libId:t,description:o,keywords:n,fpFilters:s,footprintRef:r});const c=this.createDrawingSubsymbol({libId:t,symbolData:A,isChip:e});a.subSymbols.push(c);const B=this.createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i});return a.subSymbols.push(B),a._sxEmbeddedFonts=new mpA(!1),a}addSymbolProperties({symbol:t,libId:A,description:e,keywords:i,fpFilters:o,footprintRef:n=""}){const s=A.split(":")[1]?.[0]||"U",r=[{key:"Reference",value:s,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:s,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:n,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:e,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:o,id:6,at:[0,0,0],hide:!0}];for(const a of r)t.properties.push(new Ty({key:a.key,value:a.value,id:a.id,at:a.at,effects:this.createTextEffects(1.27,a.hide)}))}getDescription(t){return t?.ftype==="simple_resistor"?"Resistor":t?.ftype==="simple_capacitor"?"Capacitor":t?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(t){return t?.ftype==="simple_resistor"?"R res resistor":t?.ftype==="simple_capacitor"?"C cap capacitor":t?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(t){return t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:t,symbolData:A,isChip:e}){const i=new Mv({libraryId:`${t.split(":")[1]}_0_1`}),o=this.ctx.c2kMatSch?.a||15;for(const n of A.primitives||[])if(n.type==="path"&&n.points){const s=e?"background":"none",r=this.createPolylineFromPoints({points:n.points,scale:o,center:A.center,fillType:s});i.polylines.push(r)}return i}createPolylineFromPoints({points:t,scale:A,center:e,fillType:i}){const o=new Wse,n=e?.x??0,s=e?.y??0,r=ah(A,A),a=t.map(B=>{const l=Tt(r,{x:B.x-n,y:B.y-s});return new wE(l.x,l.y)}),g=new SQ(a);o.points=g;const I=new tpA;I.width=.254,I.type="default",o.stroke=I;const c=new Are;return c.type=i,o.fill=c,o}createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i}){const o=new Mv({libraryId:`${t.split(":")[1]}_1_1`});for(let n=0;n<(A.ports?.length||0);n++){const s=A.ports[n],r=new vV;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:I}=this.calculatePinPosition(s,A.center,A.size,e,n,i);r.at=[a,g,I],r.length=e?6:1.27;const c=new XS;c.size={height:1.27,width:1.27};const B=new zS({font:c}),l=s.labels?.[0]||"~";r._sxName=new kpA({value:l,effects:B});const C=new XS;C.size={height:1.27,width:1.27};const Q=new zS({font:C}),E=s.pinNumber?.toString()||`${n+1}`;r._sxNumber=new ire({value:E,effects:Q}),o.pins.push(r)}return o}calculatePinPosition(t,A,e,i,o,n){const s=this.ctx.c2kMatSch?.a||15;let r=t.x??0,a=t.y??0,g=!1;if(o!==void 0&&n){const d=this.ctx.db.schematic_port.list().filter(f=>f.schematic_component_id===n.schematic_component_id).sort((f,m)=>(f.pin_number||0)-(m.pin_number||0));if(d[o]){const f=d[o];r=f.center.x-n.center.x,a=f.center.y-n.center.y,g=!0}}let I,c;if(g)I=r,c=a;else{const d=A?.x??0,f=A?.y??0;I=r-d,c=a-f}const B=ah(s,s),l=Tt(B,{x:I,y:c});let C;if(i&&e){const d=e.width/2,f=e.height/2,m=Math.abs(I)/d,S=Math.abs(c)/f;C=m>S}else C=Math.abs(I)>Math.abs(c);let Q=l.x,E=l.y;const h=6;if(i&&e){const d=e.width/2*s,f=e.height/2*s;C?(Q=I>0?d:-d,E=c*s):(Q=I*s,E=c>0?f:-f)}let u=0;return C?I>0?i?(u=180,Q=Q+h):u=0:i?(u=0,Q=Q-h):u=180:c>0?i?(u=270,E=E+h):u=90:i?(u=90,E=E-h):u=270,{x:Q,y:E,angle:u}}createTextEffects(t,A){const e=new XS;return e.size={height:t,width:t},new zS({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Ljt=class extends Dh{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_component.list();if(e.length===0){this.finished=!0;return}const i=[];for(const o of e){const n=o.source_component_id?A.source_component.get(o.source_component_id):null;if(!n||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Tt(this.ctx.c2kMatSch,{x:o.center.x,y:o.center.y}),a=crypto.randomUUID(),g=new Mv({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),I=A.cad_component?.list()?.find(_=>_.source_component_id===n.source_component_id),c=Pge(n,o,I),B=new SpA(c);g._sxLibId=B;const{reference:l,value:C,description:Q}=this.getComponentMetadata(n),{refTextPos:E,valTextPos:h}=this.getTextPositions(o,{x:s,y:r}),u=new Ty({key:"Reference",value:l,id:0,at:[E.x,E.y,0],effects:this.createTextEffects(1.27,!1)}),d=n.ftype==="simple_chip",f=new Ty({key:"Value",value:C,id:1,at:[h.x,h.y,0],effects:this.createTextEffects(1.27,d)}),m=new Ty({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),S=new Ty({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),D=new Ty({key:"Description",value:Q,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});g.properties.push(u,f,m,S,D);const x=A.schematic_port.list().filter(_=>_.schematic_component_id===o.schematic_component_id).sort((_,H)=>(_.pin_number||0)-(H.pin_number||0));for(const _ of x){const H=new vV;H.numberString=`${_.pin_number||1}`,H.uuid=crypto.randomUUID(),g.pins.push(H)}const F=new GpA,k=new RpA(""),v=new MpA(`/${t?.uuid?.value||""}`);v.reference=l,v.unit=1,k.paths.push(v),F.projects.push(k),g._sxInstances=F,i.push(g)}t&&(t.symbols=i),this.finished=!0}getTextPositions(t,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(l=>l.schematic_component_id===t.schematic_component_id)||[]).find(l=>l.text&&l.text.length>0);if(i&&this.ctx.c2kMatSch){const l=Tt(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:l,valTextPos:C}}const o=t.symbol_name,n=BQ[o];if(!n)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const l of n.primitives)l.type==="text"&&(l.text==="{REF}"?s=l:l.text==="{VAL}"&&(r=l));const a=n.center||{x:0,y:0},I=o.includes("_down")||o.includes("_up")?.15:0,c=s&&this.ctx.c2kMatSch?Tt(this.ctx.c2kMatSch,{x:t.center.x+(s.x-a.x)+I,y:t.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},B=r&&this.ctx.c2kMatSch?Tt(this.ctx.c2kMatSch,{x:t.center.x+(r.x-a.x)+I,y:t.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:c,valTextPos:B}}getComponentMetadata(t){const A=t.name||"?";return t.ftype==="simple_resistor"?{reference:A,value:t.display_resistance||"R",description:"Resistor"}:t.ftype==="simple_capacitor"?{reference:A,value:t.display_capacitance||"C",description:"Capacitor"}:t.ftype==="simple_inductor"?{reference:A,value:t.display_inductance||"L",description:"Inductor"}:t.ftype==="simple_diode"?{reference:A,value:"D",description:"Diode"}:t.ftype==="simple_chip"?{reference:A,value:A,description:"Integrated Circuit"}:{reference:A,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new XS;i.size={height:t,width:t};const o=e?new GV({horizontal:e}):void 0;return new zS({font:i,hiddenText:A,justify:o})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Hjt=class extends Dh{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_net_label?.list?.()||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],o=[];for(const n of e){const s=n.text||"",r=n.symbol_name;if(r){const a=this.createSymbolFromNetLabel(n,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(n,s);a&&o.push(a)}}if(t&&i.length>0){const n=t.symbols||[];t.symbols=[...n,...i]}t&&o.length>0&&(t.globalLabels=[...t.globalLabels||[],...o]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:o}=Tt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=crypto.randomUUID(),s=new Mv({at:[i,o,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:n,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new SpA(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),I=g?-4:4,c=g?-6:6,B=new Ty({key:"Reference",value:A,id:0,at:[i,o+I,0],effects:this.createTextEffects(1.27,!1)}),l=new Ty({key:"Value",value:A,id:1,at:[i,o+c,0],effects:this.createTextEffects(1.27,!0)}),C=new Ty({key:"Footprint",value:"",id:2,at:[i-1.778,o,90],effects:this.createTextEffects(1.27,!0)}),Q=new Ty({key:"Datasheet",value:"~",id:3,at:[i,o,0],effects:this.createTextEffects(1.27,!0)}),E=new Ty({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,o,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(B,l,C,Q,E);const h=new vV;h.numberString="1",h.uuid=crypto.randomUUID(),s.pins.push(h);const{kicadSch:u}=this.ctx,d=new GpA,f=new RpA(""),m=new MpA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Tt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[o]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[o]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new GV(a)),new pre({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new XS;return e.size={height:t,width:t},new zS({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Yjt=class extends Dh{_step(){const{kicadSch:t,db:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const e=A.schematic_trace.list();if(e.length===0){this.finished=!0;return}const i=[],o=[];for(const n of e){for(const s of n.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of n.junctions){const r=this.createJunction(s);o.push(r)}}t.wires=i,t.junctions=o,this.finished=!0}createWireFromEdge(t){const A=new Bre;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Tt(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Tt(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),o=e.x,n=e.y,s=i.x,r=i.y,a=new SQ([new wE(o,n),new wE(s,r)]);A.points=a;const g=new tpA;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(t){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:e}=Tt(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new lre({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},Jjt=class extends Dh{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new UpA,e=new wre;e.value="/";const i=new mre("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new mpA(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Tjt(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,o=1/0,n=-1/0,s=-1/0;for(const g of A){const I=g.size?.width??0,c=g.size?.height??0;i=Math.min(i,g.center.x-I/2),o=Math.min(o,g.center.y-c/2),n=Math.max(n,g.center.x+I/2),s=Math.max(s,g.center.y+c/2)}for(const g of e)for(const I of g.edges)i=Math.min(i,I.from.x,I.to.x),o=Math.min(o,I.from.y,I.to.y),n=Math.max(n,I.from.x,I.to.x),s=Math.max(s,I.from.y,I.to.y);i===1/0&&(i=0,o=0,n=0,s=0);const r=(i+n)/2,a=(o+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:o,maxX:n,maxY:s}}}var VV=[{name:"A4",width:297,height:210},{name:"A3",width:420,height:297},{name:"A2",width:594,height:420},{name:"A1",width:841,height:594},{name:"A0",width:1189,height:841}];function Kjt(t,A,e=20){const i=t+2*e,o=A+2*e;for(let n=0;n<VV.length;n++){const s=VV[n];if(i<=s.width&&o<=s.height)return s}return VV[VV.length-1]}var Oge=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){const e=wa(t),{center:i,bounds:o}=Tjt(e),n=(o.maxX-o.minX)*15,s=(o.maxY-o.minY)*15,r=Kjt(n,s),a=r.width/2,g=r.height/2;this.ctx={db:e,circuitJson:t,kicadSch:new HpA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:jB(Ir(a,g),ah(15,-15),Ir(-i.x,-i.y))},this.pipeline=[new Njt(t,this.ctx),new Ujt(t,this.ctx),new Ljt(t,this.ctx),new Hjt(t,this.ctx),new Yjt(t,this.ctx),new Jjt(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadSch}getOutputString(){return this.ctx.kicadSch.getString()}},qjt=class extends Dh{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");t.version=20241229;const A=new RV;A.size="A4",t.paper=A;const e=new J0A;e.thickness=1.6,t.general=e;const i=new Y0A;i.padToMaskClearance=0,t.setup=i;const o=new T0A,n=[new ol({index:0,name:"F.Cu",type:"signal"}),new ol({index:2,name:"B.Cu",type:"signal"}),new ol({index:9,name:"F.Adhes",type:"user"}),new ol({index:11,name:"B.Adhes",type:"user"}),new ol({index:13,name:"F.Paste",type:"user"}),new ol({index:15,name:"B.Paste",type:"user"}),new ol({index:5,name:"F.SilkS",type:"user"}),new ol({index:7,name:"B.SilkS",type:"user"}),new ol({index:1,name:"F.Mask",type:"user"}),new ol({index:3,name:"B.Mask",type:"user"}),new ol({index:20,name:"Dwgs.User",type:"user"}),new ol({index:21,name:"Cmts.User",type:"user"}),new ol({index:22,name:"Eco1.User",type:"user"}),new ol({index:23,name:"Eco2.User",type:"user"}),new ol({index:24,name:"Edge.Cuts",type:"user"}),new ol({index:25,name:"Margin",type:"user"}),new ol({index:17,name:"B.CrtYd",type:"user"}),new ol({index:16,name:"F.CrtYd",type:"user"}),new ol({index:19,name:"B.Fab",type:"user"}),new ol({index:18,name:"F.Fab",type:"user"})];o.definitions=n,t.layers=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Pjt=class extends Dh{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,e=this.ctx.db.source_net?.list()??[];for(const r of e){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",I=g&&g.trim().length>0?g:a;A.set(a,I)}const i=this.ctx.db.source_trace?.list()??[];for(const r of i){let a=r.subcircuit_connectivity_map_key;if(!a&&r.connected_source_net_ids?.length)for(const g of r.connected_source_net_ids){const I=this.ctx.db.source_net?.get(g);if(I?.subcircuit_connectivity_map_key&&I.subcircuit_connectivity_map_key.length>0){a=I.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",I=g&&g.trim().length>0?g:a;A.set(a,I)}}const o=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),n=[];n.push(new WV(0,""));let s=1;for(const[r,a]of o){const g=new WV(s,a);n.push(g);const I={id:s,name:a};this.ctx.pcbNetMap.set(r,I),s++}t.nets=n,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function Ojt(t){let A=0;for(let i=0;i<t.length;i++){const o=t.charCodeAt(i);A=(A<<5)-A+o,A=A&A}let e="";for(let i=0;i<4;i++){let o=A;for(let n=0;n<t.length;n++)o=(o<<5)-o+t.charCodeAt(n)+i*31,o=o&o;e+=Math.abs(o).toString(16).padStart(8,"0")}return e}function JY(t){const A=Ojt(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function Wjt({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){let s,r;if("x"in t&&"y"in t)s=t.x,r=t.y;else if("points"in t&&Array.isArray(t.points)){const u=t.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=jB(i!==0?hm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},ah(1,-1),Ir(-A.x,-A.y)),g=Tt(a,{x:s,y:r}),c={top:"F.Cu",bottom:"B.Cu"}[t.layer]||"F.Cu";let B,l,C,Q;if(t.shape==="circle")B="circle",l=["radius"in t?t.radius*2:.5,"radius"in t?t.radius*2:.5];else if(t.shape==="polygon"&&"points"in t){const u=t.points,d=jB(ah(1,-1),Ir(-s,-r)),f=u.map(S=>{const D=Tt(d,{x:S.x,y:S.y});return new wE(D.x,D.y)}),m=new rfA;m.contours=[new SQ(f)],m.width=0,m.filled=!0,Q=new $re,Q.addGraphic(m),B="custom",C=new vre,C.anchor="circle",l=[.2,.2]}else B="rect",l=["width"in t?t.width:.5,"height"in t?t.height:.5];const E=`pad:${n}:${e}:${g.x},${g.y}`,h=new HV({number:String(e),padType:"smd",shape:B,at:[g.x,g.y,0],size:l,layers:[`${c}`,`${c==="F.Cu"?"F":"B"}.Paste`,`${c==="F.Cu"?"F":"B"}.Mask`],uuid:JY(E)});return C&&(h.options=C),Q&&(h.primitives=Q),o&&(h.net=new efA(o.id,o.name)),h}function Zjt({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){if(!("x"in t&&"y"in t))return null;const s=t.x-A.x,r=-(t.y-A.y),a=i!==0?hm(i*Math.PI/180):yd(),g=Tt(a,{x:s,y:r});let I="circle",c,B,l=0;const C="hole_offset_x"in t||"hole_offset_y"in t;let Q;if(C){const u={x:t.hole_offset_x??0,y:t.hole_offset_y??0};(u.x!==0||u.y!==0)&&(Q=Tt(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(I="circle",c=[t.outer_diameter,t.outer_diameter],B=new wD({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(I="oval",c=[t.outer_width,t.outer_height],B=new wD({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="pill_hole_with_rect_pad"?(I="rect",c=[t.rect_pad_width,t.rect_pad_height],B=new wD({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="circular_hole_with_rect_pad"?(I="rect",c=[t.rect_pad_width,t.rect_pad_height],B=new wD({diameter:t.hole_diameter,offset:Q})):t.shape==="rotated_pill_hole_with_rect_pad"?(I="rect",c=[t.rect_pad_width,t.rect_pad_height],B=new wD({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q}),l=t.rect_ccw_rotation||0):(I="circle",c=[1.6,1.6],B=new wD({diameter:.8,offset:Q}));const E=`thruhole:${n}:${e}:${g.x},${g.y}`,h=new HV({number:String(e),padType:"thru_hole",shape:I,at:[g.x,g.y,l],size:c,drill:B,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:JY(E)});return o&&(h.net=new efA(o.id,o.name)),h}function Vjt({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,o=-(t.y-A.y),n=e!==0?hm(e*Math.PI/180):yd(),s=Tt(n,{x:i,y:o});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const I=t.hole_diameter;a=[I,I],g=new wD({diameter:I})}else if(t.hole_shape==="oval"){r="oval";const I=t.hole_width,c=t.hole_height;a=[I,c],g=new wD({oval:!0,diameter:I,width:c})}else{r="circle";const I="hole_diameter"in t?t.hole_diameter:1;a=[I,I],g=new wD({diameter:I})}return new HV({number:"",padType:"np_thru_hole",shape:r,at:[s.x,s.y,0],size:a,drill:g,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:crypto.randomUUID()})}function jjt({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,o=-(t.anchor_position.y-A.y),n=e!==0?hm(e*Math.PI/180):yd(),s=Tt(n,{x:i,y:o}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",I=(t.font_size||1)/1.5,c=new XS;c.size={width:I,height:I};const B=new zS({font:c}),l=t.ccw_rotation||0;return new Qae({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:l},layer:g,effects:B})}var zjt=class extends Dh{componentsProcessed=0;pcbComponents=[];getNetInfoForPcbPort(t){if(!t)return;const A=this.ctx.db.pcb_port?.get(t);if(!A)return;const e=A.source_port_id;if(!e)return;const i=this.ctx.db.source_port?.get(e);if(!i)return;const o=i.subcircuit_connectivity_map_key;if(o)return this.ctx.pcbNetMap?.get(o)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}create3DModelsFromCadComponent(t,A){const e=[],i=t.model_step_url||t.model_wrl_url;if(!i)return e;const o=new NfA(i);if(t.position&&(o.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:t.position.z||0}),t.rotation&&(o.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const n=t.model_unit_to_mm_scale_factor;o.scale={x:n,y:n,z:n}}return e.push(o),e}constructor(t,A){super(t,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const e=this.pcbComponents[this.componentsProcessed],i=e.source_component_id?this.ctx.db.source_component.get(e.source_component_id):null,o=this.getCadComponentForPcbComponent(e.pcb_component_id),n=i?ZV(i,o):"Unknown",s=Tt(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new UfA({libraryLink:`tscircuit:${n}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:JY(r)}),g=a.fpTexts,I=this.ctx.db.pcb_silkscreen_text?.list().filter(h=>h.pcb_component_id===e.pcb_component_id)||[];for(const h of I){const u=jjt({textElement:h,componentCenter:e.center,componentRotation:e.rotation||0});u&&g.push(u)}a.fpTexts=g;const c=this.ctx.db.pcb_smtpad?.list().filter(h=>h.pcb_component_id===e.pcb_component_id)||[],B=a.fpPads;let l=1;for(const h of c){const u=this.getNetInfoForPcbPort(h.pcb_port_id),d=Wjt({pcbPad:h,componentCenter:e.center,padNumber:l,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});B.push(d),l++}const C=this.ctx.db.pcb_plated_hole?.list().filter(h=>h.pcb_component_id===e.pcb_component_id)||[];for(const h of C){const u=this.getNetInfoForPcbPort(h.pcb_port_id),d=Zjt({platedHole:h,componentCenter:e.center,padNumber:l,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});d&&(B.push(d),l++)}const Q=this.ctx.db.pcb_hole?.list().filter(h=>h.subcircuit_id===e.subcircuit_id)||[];for(const h of Q){const u=Vjt({pcbHole:h,componentCenter:e.center,componentRotation:e.rotation||0});u&&B.push(u)}if(a.fpPads=B,o){const h=this.create3DModelsFromCadComponent(o,e.center);h.length>0&&(a.models=h)}const E=t.footprints;E.push(a),t.footprints=E,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},Xjt=class extends Dh{tracesProcessed=0;pcbTraces=[];constructor(t,A){super(t,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}for(let o=0;o<i.route.length-1;o++){const n=i.route[o],s=i.route[o+1],r=Tt(A,{x:n.x,y:n.y}),a=Tt(A,{x:s.x,y:s.y});let g;if(e){let Q=i.subcircuit_connectivity_map_key;if(!Q&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(Q=E.subcircuit_connectivity_map_key,!Q&&E.connected_source_net_ids?.length))for(const h of E.connected_source_net_ids){const u=this.ctx.db.source_net?.get(h);if(u?.subcircuit_connectivity_map_key){Q=u.subcircuit_connectivity_map_key;break}}}if(!Q&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(Q=E.subcircuit_connectivity_map_key)}Q&&(g=e.get(Q))}const c={top:"F.Cu",bottom:"B.Cu"}[n.layer]||n.layer||"F.Cu",B=`segment:${r.x},${r.y}:${a.x},${a.y}:${c}:${g?.id??0}`,l=new zfA({start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},layer:c,width:i.width||.25,net:new qV(g?.id??0),uuid:JY(B)}),C=t.segments;C.push(l),t.segments=C}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},$jt=class extends Dh{viasProcessed=0;pcbVias=[];constructor(t,A){super(t,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],o=Tt(A,{x:i.x,y:i.y});let n;if(e){let g=i.subcircuit_connectivity_map_key;if(!g&&i.pcb_trace_id){const I=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(I&&("subcircuit_connectivity_map_key"in I&&(g=I.subcircuit_connectivity_map_key),!g&&I.source_trace_id)){const c=this.ctx.db.source_trace?.get(I.source_trace_id);if(c&&("subcircuit_connectivity_map_key"in c&&(g=c.subcircuit_connectivity_map_key),!g&&c.connected_source_net_ids?.length))for(const B of c.connected_source_net_ids){const l=this.ctx.db.source_net?.get(B);if(l?.subcircuit_connectivity_map_key){g=l.subcircuit_connectivity_map_key;break}}}}if(!g&&i.connection_name){const I=this.ctx.db.source_net?.get(i.connection_name);I?.subcircuit_connectivity_map_key&&(g=I.subcircuit_connectivity_map_key)}g&&(n=e.get(g))}const s=`via:${o.x},${o.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${n?.id??0}`,r=new W0A({at:[o.x,o.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:["F.Cu","B.Cu"],net:new O0A(n?.id??0),uuid:JY(s)}),a=t.vias;a.push(r),t.vias=a,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function Azt({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Tt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),o={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",n=(t.font_size||1)/1.5,s=new XS;s.size={width:n,height:n};const r=new GV,a=t.anchor_alignment||"center";switch(a){case"top_left":r.horizontal="left",r.vertical="top";break;case"top_right":r.horizontal="right",r.vertical="top";break;case"bottom_left":r.horizontal="left",r.vertical="bottom";break;case"bottom_right":r.horizontal="right",r.vertical="bottom";break}const g=new zS({font:s});a!=="center"&&(g.justify=r);const I=t.ccw_rotation||0,c=new EI([e.x,e.y,I]),B=new OfA({text:t.text,layer:o,effects:g});return B.position=c,B}var ezt=class extends Dh{_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const e=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const n of e)if(!(!n.route||n.route.length<2))for(let s=0;s<n.route.length-1;s++){const r=n.route[s],a=n.route[s+1];if(!r||!a)continue;const g=Tt(A,{x:r.x,y:r.y}),I=Tt(A,{x:a.x,y:a.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[n.layer]||n.layer||"F.SilkS",l=new KV({start:{x:g.x,y:g.y},end:{x:I.x,y:I.y},layer:B,width:n.stroke_width||.15}),C=t.graphicLines;C.push(l),t.graphicLines=C}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(n=>!n.pcb_component_id)||[];for(const n of i){const s=Azt({textElement:n,c2kMatPcb:A});if(s){const r=t.graphicTexts;r.push(s),t.graphicTexts=r}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const n=o[0];if(!n){this.finished=!0;return}let s;if(n.outline&&n.outline.length>0)s=n.outline;else{const a=n.width?n.width/2:0,g=n.height?n.height/2:0;s=[{x:n.center.x-a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y+g},{x:n.center.x-a,y:n.center.y+g}]}const r=s.map(a=>Tt(A,a));for(let a=0;a<r.length;a++){const g=r[a],I=r[(a+1)%r.length];if(!g||!I)continue;const c=new KV({start:{x:g.x,y:g.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=t.graphicLines;B.push(c),t.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Wge=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){this.ctx={db:wa(t),circuitJson:t,kicadPcb:new Z0A({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:jB(Ir(100,100),ah(1,-1))},this.pipeline=[new qjt(t,this.ctx),new Pjt(t,this.ctx),new zjt(t,this.ctx),new Xjt(t,this.ctx),new $jt(t,this.ctx),new ezt(t,this.ctx)]}step(){if(!this.currentStage){this.finished=!0;return}this.currentStage.step(),this.currentStage.finished&&this.currentStageIndex++}runUntilFinished(){for(;!this.finished;)this.step()}getOutput(){return this.ctx.kicadPcb}getOutputString(){return this.ctx.kicadPcb.getString()}},tzt=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,o=A.pcbFilename??`${e}.kicad_pcb`,n=new Date().toISOString();this.ctx={db:wa(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:n,modified:n},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:o},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
5760
- `}},izt=class extends Dh{_step(){const t=new Oge(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new Wge(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},ozt=class extends Dh{isCustomSymbol(t){return t?.startsWith("Custom:")??!1}_step(){const t=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const e=new Map;try{const o=Kge(t).find(r=>r instanceof HpA);if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const n=o.libSymbols;if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const s=n.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);e.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),e.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(e.values()),this.finished=!0}updateFootprintProperty(t,A){const e=t.properties??[];for(const i of e)if(i.key==="Footprint"&&i.value){const o=i.value.split(":");o.length>1?i.value=`${A}:${o[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(t){if(!t)return"symbol";const A=t.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}getOutput(){return this.ctx.libraryOutput}};function nzt(t){const A=t.split(/[/\\]/);return A[A.length-1]||t}var szt=class extends Dh{findCustomFootprintNames(){const t=new Set,A=this.ctx.db.cad_component?.list()??[],e=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const o=i.source_component_id?e?.get(i.source_component_id):null;if(o){const n=ZV(o,i);t.add(n)}}return t}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const e=this.findCustomFootprintNames(),i=new Map;try{const n=Kge(t).find(r=>r instanceof Z0A);if(!n){this.ctx.footprintEntries=[],this.finished=!0;return}const s=n.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:e});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e}){const o=(t.libraryLink??"footprint").split(":"),n=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!e.has(n);t.libraryLink=n,t.position=EI.from([0,0,0]),t.locked=!1,t.placed=!1,t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0,t.properties=[];const r=t.fpTexts??[];for(const B of r)B.uuid=void 0,B.type==="reference"?B.text="REF**":B.type==="value"&&B.text.trim().length===0&&(B.text=n);t.fpTexts=r;const a=t.fpPads??[];for(const B of a)B.uuid=void 0,B.net=void 0;t.fpPads=a;const g=t.models??[],I=[],c=[];for(const B of g)if(B.path){const l=nzt(B.path),C=`\${KIPRJMOD}/${A}.3dshapes/${l}`,Q=new NfA(C);B.offset&&(Q.offset=B.offset),B.scale&&(Q.scale=B.scale),B.rotate&&(Q.rotate=B.rotate),I.push(Q),c.push(B.path)}return t.models=I,{footprintName:n,kicadModString:t.getString(),model3dSourcePaths:c,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},rzt=20211014,azt="circuit-json-to-kicad",gzt=class extends Dh{_step(){const t=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(t){return new are({version:rzt,generator:azt,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},Izt=class extends Dh{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],o=new Set;for(const r of e)for(const a of r.model3dSourcePaths)o.add(a);const n=this.generateFpLibTable(A),s=this.generateSymLibTable(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=e,this.ctx.libraryOutput.fpLibTableString=n,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(o),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
5760
+ `}},izt=class extends Dh{_step(){const t=new Oge(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new Wge(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},ozt=class extends Dh{isCustomSymbol(t){return t?.startsWith("Custom:")??!1}_step(){const t=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const e=new Map;try{const o=Kge(t).find(r=>r instanceof HpA);if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const n=o.libSymbols;if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const s=n.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);e.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),e.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(e.values()),this.finished=!0}updateFootprintProperty(t,A){const e=t.properties??[];for(const i of e)if(i.key==="Footprint"&&i.value){const o=i.value.split(":");o.length>1?i.value=`${A}:${o[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(t){if(!t)return"symbol";const A=t.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}getOutput(){return this.ctx.libraryOutput}};function nzt(t){const A=t.split(/[/\\]/);return A[A.length-1]||t}var szt=class extends Dh{findCustomFootprintNames(){const t=new Set,A=this.ctx.db.cad_component?.list()??[],e=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const o=i.source_component_id?e?.get(i.source_component_id):null;if(o){const n=ZV(o,i);t.add(n)}}return t}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const e=this.findCustomFootprintNames(),i=new Map;try{const n=Kge(t).find(r=>r instanceof Z0A);if(!n){this.ctx.footprintEntries=[],this.finished=!0;return}const s=n.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:e});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e}){const o=(t.libraryLink??"footprint").split(":"),n=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!e.has(n);t.libraryLink=n,t.position=EI.from([0,0,0]),t.locked=!1,t.placed=!1,t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0,t.properties=[];const r=t.fpTexts??[];for(const B of r)B.uuid=void 0,B.type==="reference"?B.text="REF**":B.type==="value"&&B.text.trim().length===0&&(B.text=n);t.fpTexts=r;const a=t.fpPads??[];for(const B of a)B.uuid=void 0,B.net=void 0;t.fpPads=a;const g=t.models??[],I=[],c=[];for(const B of g)if(B.path){const l=nzt(B.path),C=`../../3dmodels/${A}.3dshapes/${l}`,Q=new NfA(C);B.offset&&(Q.offset=B.offset),B.scale&&(Q.scale=B.scale),B.rotate&&(Q.rotate=B.rotate),I.push(Q),c.push(B.path)}return t.models=I,{footprintName:n,kicadModString:t.getString(),model3dSourcePaths:c,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},rzt=20211014,azt="circuit-json-to-kicad",gzt=class extends Dh{_step(){const t=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(t){return new are({version:rzt,generator:azt,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},Izt=class extends Dh{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],o=new Set;for(const r of e)for(const a of r.model3dSourcePaths)o.add(a);const n=this.generateFpLibTable(A),s=this.generateSymLibTable(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=e,this.ctx.libraryOutput.fpLibTableString=n,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(o),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
5761
5761
  (version 7)
5762
5762
  (lib (name "${t}") (type "KiCad") (uri "\${KIPRJMOD}/${t}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
5763
5763
  )
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/runframe",
3
3
  "main": "dist/preview.js",
4
4
  "type": "module",
5
- "version": "0.0.1503",
5
+ "version": "0.0.1504",
6
6
  "exports": {
7
7
  ".": "./dist/preview.js",
8
8
  "./preview": "./dist/preview.js",
@@ -69,7 +69,7 @@
69
69
  "circuit-json-to-bom-csv": "^0.0.8",
70
70
  "circuit-json-to-gerber": "^0.0.46",
71
71
  "circuit-json-to-gltf": "^0.0.56",
72
- "circuit-json-to-kicad": "^0.0.34",
72
+ "circuit-json-to-kicad": "^0.0.35",
73
73
  "circuit-json-to-lbrn": "^0.0.4",
74
74
  "circuit-json-to-pnp-csv": "^0.0.7",
75
75
  "circuit-json-to-step": "^0.0.13",