@tscircuit/runframe 0.0.1627 → 0.0.1628
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.
|
|
1733
|
+
var version = "0.0.1627";
|
|
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.47",
|
|
1804
1804
|
"circuit-json-to-gltf": "^0.0.56",
|
|
1805
|
-
"circuit-json-to-kicad": "^0.0.
|
|
1805
|
+
"circuit-json-to-kicad": "^0.0.74",
|
|
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.18",
|
package/dist/preview.js
CHANGED
package/dist/runner.js
CHANGED
|
@@ -5682,7 +5682,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5682
5682
|
// Add more specific assertions based on expected output
|
|
5683
5683
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5684
5684
|
})
|
|
5685
|
-
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},$gt=e=>e.activeSubSolver?[e,...$gt(e.activeSubSolver)]:[e],UWe=({solver:e})=>{const A=$gt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(LWe,{solver:t})]},t.constructor.name))})},HWe=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(UWe,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,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"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},YWe=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},JWe=(e,A)=>{const i=e.pipelineDef[A].solverName,n=YWe(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},TWe=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},KWe=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},PWe=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),qWe=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=PWe(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},qpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=qpA(i));return A},OWe=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=qpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},WWe=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>JWe(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):OWe(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(TWe,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(KWe,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(qWe,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},ZWe=class extends nn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function VWe({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)c(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)c(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;c(h,u),c(h+d,u+f)}for(const Q of n){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;c(h-d,u-d),c(h+d,u+d)}for(const Q of o)c(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),E=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),o.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var jWe=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(HWe,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(ZWe,{fallback:Z.jsx(VWe,{graphics:s}),children:Z.jsx(vWe,{graphics:s})}),a&&Z.jsx(WWe,{solver:e,onStepUntilPhase:g})]})};const zWe=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},XWe=e=>e.toLowerCase().includes("pack")?vFe:e.toLowerCase().includes("rout")?TFe:bFe,$We=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);zWe();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=ArA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ArA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.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:()=>t(r),children:(()=>{const c=XWe(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(pD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(jWe,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Act=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{NK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{NK.captureException(n,{error_type:i.type})}catch{}}},[t])},tct="0.0.1626",AZe={version:tct},OpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},WpA=new Map,o9=e=>{const A=WpA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},tZe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=WpA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return WpA.set(t.name,n),{type:"tracked",store:e,...n}},ect=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(OpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(OpA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=tZe(r,g,a);let l=!0;n.setState=(E,Q,h)=>{const u=t(E,Q);if(!l)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...o9(a.name),[r]:n.getState()}),u)};const B=(...E)=>{const Q=l;l=!1,t(...E),l=Q},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([E,Q])=>[E,E===I.store?C:Q.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let E=!1;const Q=n.dispatch;n.dispatch=(...h)=>{(OpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return c.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ZpA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){B(h.state);return}Object.keys(h.state).length!==1&&console.error(`
|
|
5685
|
+
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},$gt=e=>e.activeSubSolver?[e,...$gt(e.activeSubSolver)]:[e],UWe=({solver:e})=>{const A=$gt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(LWe,{solver:t})]},t.constructor.name))})},HWe=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},I=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(UWe,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:c,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,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"}),B&&Z.jsx("button",{onClick:I,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},YWe=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},JWe=(e,A)=>{const i=e.pipelineDef[A].solverName,n=YWe(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},TWe=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},KWe=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},PWe=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),qWe=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=PWe(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},qpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=qpA(i));return A},OWe=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=qpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},WWe=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>JWe(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):OWe(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(TWe,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(KWe,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(qWe,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},ZWe=class extends nn.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function VWe({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)c(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)c(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;c(h,u),c(h+d,u+f)}for(const Q of n){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;c(h-d,u-d),c(h+d,u+d)}for(const Q of o)c(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),E=Math.max(1,g-r+2*I);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),o.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var jWe=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(c=>c+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=e.pipelineDef!==void 0,g=c=>{const I=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(HWe,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(ZWe,{fallback:Z.jsx(VWe,{graphics:s}),children:Z.jsx(vWe,{graphics:s})}),a&&Z.jsx(WWe,{solver:e,onStepUntilPhase:g})]})};const zWe=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},XWe=e=>e.toLowerCase().includes("pack")?vFe:e.toLowerCase().includes("rout")?TFe:bFe,$We=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);zWe();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=ArA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ArA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.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:()=>t(r),children:(()=>{const c=XWe(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(pD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(jWe,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Act=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{NK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{NK.captureException(n,{error_type:i.type})}catch{}}},[t])},tct="0.0.1627",AZe={version:tct},OpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},WpA=new Map,o9=e=>{const A=WpA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},tZe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=WpA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return WpA.set(t.name,n),{type:"tracked",store:e,...n}},ect=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(OpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(OpA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:c,...I}=tZe(r,g,a);let l=!0;n.setState=(E,Q,h)=>{const u=t(E,Q);if(!l)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(c?.send(d,i()),u):(c?.send({...d,type:`${r}/${d.type}`},{...o9(a.name),[r]:n.getState()}),u)};const B=(...E)=>{const Q=l;l=!1,t(...E),l=Q},C=e(n.setState,i,n);if(I.type==="untracked"?c?.init(C):(I.stores[I.store]=n,c?.init(Object.fromEntries(Object.entries(I.stores).map(([E,Q])=>[E,E===I.store?C:Q.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let E=!1;const Q=n.dispatch;n.dispatch=(...h)=>{(OpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return c.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ZpA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){B(h.state);return}Object.keys(h.state).length!==1&&console.error(`
|
|
5686
5686
|
[zustand devtools middleware] Unsupported __setState action format.
|
|
5687
5687
|
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
5688
5688
|
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
@@ -5823,7 +5823,7 @@ ${a.join(`
|
|
|
5823
5823
|
`)}};NA.register(Rei);var JQt=class rSA extends NA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new rSA(!0);const t=pi(A[0]);return new rSA(t==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};NA.register(JQt);var TQt=class Y0t extends NA{static token="members";static parentToken="group";token="members";members;constructor(A){super(),this.members=A}static fromSexprPrimitives(A){const t=[];for(const i of A){const n=pi(i);n&&t.push(n)}return new Y0t(t)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(t=>`"${t}"`).join(" ")})`}};NA.register(TQt);var vmA=class J0t extends NA{static token="end";static parentToken="segment";token="end";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=ai(t),o=ai(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new J0t(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}};NA.register(vmA);var Nei=new Set(["true","yes","1"]),KQt=class Jz extends Ml{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[t]=A;return typeof t=="boolean"?new Jz(t):typeof t=="string"?new Jz(Nei.has(t.toLowerCase())):new Jz(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};NA.register(KQt);var cj=class T0t extends NA{static token="net";static parentToken="segment";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const[t,i]=A,n=ai(t);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:pi(i);return new T0t(n,o??void 0)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A===""?void 0:A}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const A=this._name?` ${Bn(this._name)}`:"";return`(net ${this._id}${A})`}};NA.register(cj);var LmA=class K0t extends NA{static token="start";static parentToken="segment";token="start";_x;_y;constructor(A,t){super(),this._x=A,this._y=t}static fromSexprPrimitives(A){const[t,i]=A,n=ai(t),o=ai(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new K0t(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}};NA.register(LmA);var PQt=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),UmA=class P0t extends NA{static token="segment";token="segment";_sxStart;_sxEnd;_sxWidth;_sxLayer;_sxNet;_sxTstamp;_sxUuid;_sxLocked;constructor(A={}){super(),A.start!==void 0&&(this.start=A.start),A.end!==void 0&&(this.end=A.end),A.width!==void 0&&(this.width=A.width),A.layer!==void 0&&(this.layer=A.layer),A.net!==void 0&&(this.net=A.net),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.uuid!==void 0&&(this.uuid=A.uuid),A.locked!==void 0&&(this.locked=A.locked)}static fromSexprPrimitives(A){const t=new P0t,{propertyMap:i,arrayPropertyMap:n}=NA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!PQt.has(r));if(o.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${o.join(", ")}`);for(const[r,a]of Object.entries(n)){if(!PQt.has(r))throw new Error(`Unsupported child tokens inside segment expression: ${r}`);if(a.length>1)throw new Error(`Segment does not support repeated child tokens: ${r}`)}t._sxStart=n.start?.[0]??i.start,t._sxEnd=n.end?.[0]??i.end,t._sxWidth=n.width?.[0]??i.width,t._sxLayer=n.layer?.[0]??i.layer,t._sxNet=n.net?.[0]??i.net;const s=n.locked?.[0]??i.locked;return t._sxLocked=s&&s.value?s:void 0,t._sxTstamp=n.tstamp?.[0]??i.tstamp,t._sxUuid=n.uuid?.[0]??i.uuid,t}get start(){return this._sxStart}set start(A){this._sxStart=this.normalizeStart(A)}get end(){return this._sxEnd}set end(A){this._sxEnd=this.normalizeEnd(A)}get startPoint(){return this._sxStart?.toObject()}get endPoint(){return this._sxEnd?.toObject()}get width(){return this._sxWidth?.value}set width(A){if(A===void 0){this._sxWidth=void 0;return}this._sxWidth=A instanceof Gr?A:new Gr(A)}get widthClass(){return this._sxWidth}set widthClass(A){this._sxWidth=A}get layer(){return this._sxLayer}set layer(A){if(A===void 0){this._sxLayer=void 0;return}if(A instanceof yr){this._sxLayer=A;return}const t=Array.isArray(A)?A:[A];this._sxLayer=new yr(t)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof cj){this._sxNet=A;return}this._sxNet=new cj(A.id,A.name)}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof Zg?A:new Zg(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof Ui?A:new Ui(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new KQt(!0):void 0}getChildren(){const A=[];return this._sxStart&&A.push(this._sxStart),this._sxEnd&&A.push(this._sxEnd),this._sxWidth&&A.push(this._sxWidth),this._sxLayer&&A.push(this._sxLayer),this._sxNet&&A.push(this._sxNet),this._sxLocked&&A.push(this._sxLocked),this._sxTstamp&&A.push(this._sxTstamp),this._sxUuid&&A.push(this._sxUuid),A}normalizeStart(A){if(A!==void 0)return A instanceof LmA?A:new LmA(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof vmA?A:new vmA(A.x,A.y)}};NA.register(UmA);var qQt=class q0t extends NA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const t=new q0t;return t._rawChildren=[...A],t}get rawChildren(){return[...this._rawChildren]}set rawChildren(A){this._rawChildren=[...A]}getChildren(){return[]}getString(){const A=["(zone"];for(const t of this._rawChildren)A.push(` ${RE(t)}`);return A.push(")"),A.join(`
|
|
5824
5824
|
`)}};NA.register(qQt);var Ij=class O0t extends NA{static token="layers";token="layers";_names=[];constructor(A=[]){super(),this.names=A}static fromSexprPrimitives(A){const t=A.map(i=>typeof i=="string"||typeof i=="number"?String(i):RE(i));return new O0t(t)}get names(){return[...this._names]}set names(A){this._names=A.map(t=>String(t))}getString(){return`(layers ${this._names.map(t=>/^[^\s()"]+$/u.test(t)&&!["nil","#t","#f"].includes(t)?t:Bn(t)).join(" ")})`}};NA.register(Ij);var NJ=class extends NA{_value;quoteStringValue=!1;constructor(e){super(),this._value=e}static fromSexprPrimitives(e){const[A]=e,t=this.parsePrimitiveValue(A),i=this;return new i(t)}static parsePrimitiveValue(e){const A=pi(e);if(A===void 0)throw new Error(`${this.name} expects a primitive value`);return A}get value(){return this._value}set value(e){this._value=e}getChildren(){return[]}formatValue(){return typeof this._value=="string"?this.quoteStringValue?Bn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},vei=class extends NA{_values;constructor(e){super(),this._values=e}static fromSexprPrimitives(e){const A=e.map(i=>{const n=ai(i);if(n===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return n}),t=this;return new t(A)}get values(){return[...this._values]}set values(e){this._values=[...e]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},Lei=class extends NA{_x;_y;constructor(e,A){super(),this._x=e,this._y=A}static fromSexprPrimitives(e){const[A,t]=e,i=ai(A),n=ai(t);if(i===void 0||n===void 0)throw new Error(`${this.name} expects two numeric values`);const o=this;return new o(i,n)}get x(){return this._x}set x(e){this._x=e}get y(){return this._y}set y(e){this._y=e}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},mr=class extends NJ{static parentToken="pcbplotparams"},$y=class extends mr{static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},OQt=class extends mr{static token="layerselection";token="layerselection"};NA.register(OQt);var WQt=class extends mr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};NA.register(WQt);var ZQt=class extends $y{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};NA.register(ZQt);var VQt=class extends $y{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};NA.register(VQt);var jQt=class extends $y{static token="svgprecision";token="svgprecision"};NA.register(jQt);var zQt=class extends $y{static token="linewidth";token="linewidth"};NA.register(zQt);var XQt=class extends $y{static token="mode";token="mode"};NA.register(XQt);var $Qt=class extends $y{static token="hpglpennumber";token="hpglpennumber"};NA.register($Qt);var AEt=class extends $y{static token="hpglpenspeed";token="hpglpenspeed"};NA.register(AEt);var tEt=class extends $y{static token="hpglpendiameter";token="hpglpendiameter"};NA.register(tEt);var eEt=class extends $y{static token="hpglpenoverlay";token="hpglpenoverlay"};NA.register(eEt);var iEt=class extends $y{static token="outputformat";token="outputformat"};NA.register(iEt);var nEt=class extends $y{static token="drillshape";token="drillshape"};NA.register(nEt);var oEt=class extends $y{static token="scaleselection";token="scaleselection"};NA.register(oEt);var sEt=class extends mr{static token="disableapertmacros";token="disableapertmacros"};NA.register(sEt);var rEt=class extends mr{static token="usegerberextensions";token="usegerberextensions"};NA.register(rEt);var aEt=class extends mr{static token="usegerberattributes";token="usegerberattributes"};NA.register(aEt);var gEt=class extends mr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};NA.register(gEt);var cEt=class extends mr{static token="creategerberjobfile";token="creategerberjobfile"};NA.register(cEt);var IEt=class extends mr{static token="excludeedgelayer";token="excludeedgelayer"};NA.register(IEt);var lEt=class extends mr{static token="plotframeref";token="plotframeref"};NA.register(lEt);var BEt=class extends mr{static token="viasonmask";token="viasonmask"};NA.register(BEt);var CEt=class extends mr{static token="useauxorigin";token="useauxorigin"};NA.register(CEt);var QEt=class extends mr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};NA.register(QEt);var EEt=class extends mr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};NA.register(EEt);var hEt=class extends mr{static token="pdf_metadata";token="pdf_metadata"};NA.register(hEt);var uEt=class extends mr{static token="pdf_single_document";token="pdf_single_document"};NA.register(uEt);var dEt=class extends mr{static token="dxfpolygonmode";token="dxfpolygonmode"};NA.register(dEt);var pEt=class extends mr{static token="dxfimperialunits";token="dxfimperialunits"};NA.register(pEt);var fEt=class extends mr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};NA.register(fEt);var yEt=class extends mr{static token="psnegative";token="psnegative"};NA.register(yEt);var mEt=class extends mr{static token="psa4output";token="psa4output"};NA.register(mEt);var wEt=class extends mr{static token="plotreference";token="plotreference"};NA.register(wEt);var DEt=class extends mr{static token="plotvalue";token="plotvalue"};NA.register(DEt);var SEt=class extends mr{static token="plotothertext";token="plotothertext"};NA.register(SEt);var bEt=class extends mr{static token="plotinvisibletext";token="plotinvisibletext"};NA.register(bEt);var xEt=class extends mr{static token="padsonsilk";token="padsonsilk"};NA.register(xEt);var _Et=class extends mr{static token="sketchpadsonfab";token="sketchpadsonfab"};NA.register(_Et);var kEt=class extends mr{static token="plotpadnumbers";token="plotpadnumbers"};NA.register(kEt);var FEt=class extends mr{static token="hidednponfab";token="hidednponfab"};NA.register(FEt);var GEt=class extends mr{static token="sketchdnponfab";token="sketchdnponfab"};NA.register(GEt);var MEt=class extends mr{static token="crossoutdnponfab";token="crossoutdnponfab"};NA.register(MEt);var REt=class extends mr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};NA.register(REt);var NEt=class extends mr{static token="plot_black_and_white";token="plot_black_and_white"};NA.register(NEt);var vEt=class extends mr{static token="mirror";token="mirror"};NA.register(vEt);var LEt=class extends mr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};NA.register(LEt);var UEt=class extends mr{static token="plot_on_all_layers";token="plot_on_all_layers"};NA.register(UEt);var HEt=class extends mr{static token="plotinvisible";token="plotinvisible"};NA.register(HEt);var Uei={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"},Hei=["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"],HmA=class W0t extends NA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const t=new W0t,{propertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=Uei[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of Hei){const i=this._properties[t];i&&A.push(i)}return A}clearProperty(A){delete this._properties[A]}setStringProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}setStringOrNumberProperty(A,t,i){if(t===void 0){this.clearProperty(A);return}this._properties[A]=new i(t)}get layerselection(){return this._properties.layerselection?.value}set layerselection(A){this.setStringOrNumberProperty("layerselection",A,OQt)}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,WQt)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,sEt)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,rEt)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,aEt)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,gEt)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,cEt)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,IEt)}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,ZQt)}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,VQt)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,jQt)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,zQt)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,lEt)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,wEt)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,DEt)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,SEt)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,bEt)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,xEt)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,kEt)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,_Et)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,FEt)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,GEt)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,MEt)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,REt)}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,NEt)}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,UEt)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,HEt)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,XQt)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,CEt)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,BEt)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,$Qt)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,AEt)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,tEt)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,eEt)}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,QEt)}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,EEt)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,hEt)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,uEt)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,dEt)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,pEt)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,fEt)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,yEt)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,mEt)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,vEt)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,iEt)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,nEt)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,oEt)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,LEt)}};NA.register(HmA);var lj=class extends NJ{static parentToken="setup"},YmA=class extends lj{static token="zone_45_only";token="zone_45_only"};NA.register(YmA);var JmA=class extends lj{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};NA.register(JmA);var TmA=class extends lj{static token="visible_elements";token="visible_elements"};NA.register(TmA);var KmA=class extends lj{static token="uvias_allowed";token="uvias_allowed"};NA.register(KmA);var PmA=class Z0t extends NA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const t=A.map(i=>pi(i)).filter(i=>i!==void 0);return new Z0t(t)}get sides(){return[...this._sides]}set sides(A){this._sides=A.map(t=>String(t))}getChildren(){return[]}getString(){return this._sides.length===0?"(tenting)":`(tenting ${this._sides.join(" ")})`}};NA.register(PmA);var vJ=class extends vei{static parentToken="setup"},YEt=class extends Lei{static parentToken="setup"},qmA=class extends vJ{static token="pcb_text_size";token="pcb_text_size"};NA.register(qmA);var OmA=class extends vJ{static token="mod_text_size";token="mod_text_size"};NA.register(OmA);var WmA=class extends vJ{static token="pad_size";token="pad_size"};NA.register(WmA);var ZmA=class extends vJ{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};NA.register(ZmA);var VmA=class extends vJ{static token="trace_width";token="trace_width"};NA.register(VmA);var jmA=class extends YEt{static token="aux_axis_origin";token="aux_axis_origin"};NA.register(jmA);var zmA=class extends YEt{static token="grid_origin";token="grid_origin"};NA.register(zmA);var cB=class extends NJ{static parentToken="setup";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},XmA=class extends cB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};NA.register(XmA);var $mA=class extends cB{static token="solder_mask_min_width";token="solder_mask_min_width"};NA.register($mA);var AwA=class extends cB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};NA.register(AwA);var twA=class extends cB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};NA.register(twA);var ewA=class extends cB{static token="last_trace_width";token="last_trace_width"};NA.register(ewA);var iwA=class extends cB{static token="trace_clearance";token="trace_clearance"};NA.register(iwA);var nwA=class extends cB{static token="zone_clearance";token="zone_clearance"};NA.register(nwA);var owA=class extends cB{static token="trace_min";token="trace_min"};NA.register(owA);var swA=class extends cB{static token="segment_width";token="segment_width"};NA.register(swA);var rwA=class extends cB{static token="edge_width";token="edge_width"};NA.register(rwA);var awA=class extends cB{static token="via_size";token="via_size"};NA.register(awA);var gwA=class extends cB{static token="via_drill";token="via_drill"};NA.register(gwA);var cwA=class extends cB{static token="via_min_size";token="via_min_size"};NA.register(cwA);var IwA=class extends cB{static token="via_min_drill";token="via_min_drill"};NA.register(IwA);var lwA=class extends cB{static token="uvia_size";token="uvia_size"};NA.register(lwA);var BwA=class extends cB{static token="uvia_drill";token="uvia_drill"};NA.register(BwA);var CwA=class extends cB{static token="uvia_min_size";token="uvia_min_size"};NA.register(CwA);var QwA=class extends cB{static token="uvia_min_drill";token="uvia_min_drill"};NA.register(QwA);var EwA=class extends cB{static token="pcb_text_width";token="pcb_text_width"};NA.register(EwA);var hwA=class extends cB{static token="mod_edge_width";token="mod_edge_width"};NA.register(hwA);var uwA=class extends cB{static token="mod_text_width";token="mod_text_width"};NA.register(uwA);var dwA=class extends cB{static token="pad_drill";token="pad_drill"};NA.register(dwA);var LJ=class extends NJ{static parentToken="stackup"},JEt=class extends LJ{static token="copper_finish";token="copper_finish";quoteStringValue=!0};NA.register(JEt);var TEt=class extends LJ{static token="dielectric_constraints";token="dielectric_constraints"};NA.register(TEt);var KEt=class extends LJ{static token="edge_connector";token="edge_connector"};NA.register(KEt);var PEt=class extends LJ{static token="castellated_pads";token="castellated_pads"};NA.register(PEt);var qEt=class extends LJ{static token="edge_plating";token="edge_plating"};NA.register(qEt);var y1=class extends NJ{static parentToken="layer"},pwA=class extends y1{static token="type";token="type";quoteStringValue=!0};NA.register(pwA);var fwA=class extends y1{static token="color";token="color";quoteStringValue=!0};NA.register(fwA);var ywA=class extends y1{static token="thickness";token="thickness";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};NA.register(ywA);var mwA=class extends y1{static token="material";token="material";quoteStringValue=!0};NA.register(mwA);var wwA=class extends y1{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};NA.register(wwA);var DwA=class extends y1{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(e){const A=ai(e);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};NA.register(DwA);var OEt=class V0t extends NA{static token="layer";static parentToken="stackup";token="layer";_name;_number;_sxType;_sxColor;_sxThickness;_sxMaterial;_sxEpsilonR;_sxLossTangent;constructor(A,t={}){super(),this._name=A,this._number=t.number,this._sxType=t.type,this._sxColor=t.color,this._sxThickness=t.thickness,this._sxMaterial=t.material,this._sxEpsilonR=t.epsilonR,this._sxLossTangent=t.lossTangent}static fromSexprPrimitives(A){if(A.length===0)throw new Error("Stackup layer requires at least a name");const t=pi(A[0]);if(t===void 0)throw new Error("Stackup layer name must be a string");let i=1,n;const o=A[i],s=ai(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=NA.parsePrimitivesToClassProperties(r,this.token);return new V0t(t,{number:n,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 t=pi(A);if(t===void 0)throw new Error("Stackup layer name must be a string");this._name=t}get number(){return this._number}set number(A){if(A===void 0){this._number=void 0;return}const t=ai(A);if(t===void 0)throw new Error("Stackup layer number must be numeric");this._number=t}get type(){return this._sxType?.value}set type(A){if(A===void 0){this._sxType=void 0;return}this._sxType=A instanceof pwA?A:new pwA(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof fwA?A:new fwA(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof ywA?A:new ywA(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof mwA?A:new mwA(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof wwA?A:new wwA(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof DwA?A:new DwA(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 ${Bn(this._name)}${this._number!==void 0?` ${this._number}`:""}`,t=this.getChildren();if(t.length===0)return`${A})`;const i=[A];for(const n of t)i.push(n.getStringIndented());return i.push(")"),i.join(`
|
|
5825
5825
|
`)}};NA.register(OEt);var SwA=class j0t 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:t,arrayPropertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);return new j0t({layers:i.layer??[],copperFinish:t.copper_finish,dielectricConstraints:t.dielectric_constraints,edgeConnector:t.edge_connector,castellatedPads:t.castellated_pads,edgePlating:t.edge_plating})}get layers(){return[...this._layers]}set layers(A){this._layers=A.map(t=>{if(!(t instanceof OEt))throw new Error("Stackup layers must be StackupLayer instances");return t})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new JEt(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new TEt(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new KEt(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new PEt(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new qEt(A):void 0}getChildren(){const A=[...this._layers],t=[this._sxCopperFinish,this._sxDielectricConstraints,this._sxEdgeConnector,this._sxCastellatedPads,this._sxEdgePlating];for(const i of t)i&&A.push(i);return A}};NA.register(SwA);var Yei={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"},Jei=["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"],bwA=class z0t extends NA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const t=new z0t,{propertyMap:i}=NA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=Yei[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);t._properties[s]=o}return t}getChildren(){const A=[];for(const t of Jei){const i=this._properties[t];i&&A.push(i)}return A}setProperty(A,t){if(t){this._properties[A]=t;return}delete this._properties[A]}setNumberProperty(A,t,i){if(t===void 0){delete this._properties[A];return}this._properties[A]=new i(t)}getPropertyInstance(A,t){const i=this._properties[A];return i instanceof t?i:void 0}get stackup(){return this.getPropertyInstance("stackup",SwA)}set stackup(A){if(A!==void 0&&!(A instanceof SwA))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",HmA)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof HmA))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",XmA)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,XmA)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",$mA)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,$mA)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",AwA)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,AwA)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",twA)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,twA)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",ewA)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,ewA)}get traceClearance(){return this.getPropertyInstance("traceClearance",iwA)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,iwA)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",nwA)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,nwA)}get zone45Only(){return this.getPropertyInstance("zone45Only",YmA)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new YmA(A))}get traceMin(){return this.getPropertyInstance("traceMin",owA)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,owA)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",swA)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,swA)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",rwA)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,rwA)}get viaSize(){return this.getPropertyInstance("viaSize",awA)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,awA)}get viaDrill(){return this.getPropertyInstance("viaDrill",gwA)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,gwA)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",cwA)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,cwA)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",IwA)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,IwA)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",KmA)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new KmA(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",lwA)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,lwA)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",BwA)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,BwA)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",CwA)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,CwA)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",QwA)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,QwA)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",EwA)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,EwA)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",qmA)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new qmA(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",hwA)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,hwA)}get modTextSize(){return this.getPropertyInstance("modTextSize",OmA)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new OmA(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",uwA)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,uwA)}get padSize(){return this.getPropertyInstance("padSize",WmA)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new WmA(A))}get padDrill(){return this.getPropertyInstance("padDrill",dwA)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,dwA)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",JmA)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new JmA(A))}get tenting(){return this.getPropertyInstance("tenting",PmA)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new PmA(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",jmA);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new jmA(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",zmA);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new zmA(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",TmA)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new TmA(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",ZmA)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new ZmA(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",VmA)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new VmA(A))}};NA.register(bwA);var WEt=class extends ga{static token="thickness";static parentToken="general";token="thickness"};NA.register(WEt);var ZEt=class X0t extends NA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const t=pi(A[0]);if(t===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(t);return new X0t(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};NA.register(ZEt);var VEt=new Set(["thickness","legacy_teardrops"]),xwA=class $0t extends NA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const t=new $0t,{propertyMap:i,arrayPropertyMap:n}=NA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!VEt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!VEt.has(o))throw new Error(`general encountered unsupported child token "${o}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${o}"`)}return t._sxThickness=n.thickness?.[0]??i.thickness,t._sxLegacyTeardrops=n.legacy_teardrops?.[0]??i.legacy_teardrops,t}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new WEt(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new ZEt(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};NA.register(xwA);var Rl=class Ayt 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[t,i,n,o]=A,s=ai(t),r=pi(i),a=pi(n),g=o===void 0?void 0:pi(o);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new Ayt({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),Bn(this._name),this._type];return this._userName!==void 0&&A.push(Bn(this._userName)),`(${A.join(" ")})`}};NA.register(Rl);var _wA=class tyt extends NA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const t=new tyt;return t._definitions=A.map(i=>Rl.fromPrimitive(i)),t}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};NA.register(_wA);var Bj=class eyt extends NA{static token="net";static parentToken="kicad_pcb";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=ai(A[0]),i=pi(A[1]);if(t===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new eyt(t,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} ${Bn(this._name)})`}};NA.register(Bj);var kwA=class extends ga{static token="version";static parentToken="kicad_pcb";token="version"};NA.register(kwA);var Tei=e=>/^[A-Za-z0-9._-]+$/.test(e),FwA=class extends Xy{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${Tei(this.value)?this.value:Bn(this.value)})`}};NA.register(FwA);var Kei=e=>/^[A-Za-z0-9._-]+$/.test(e),GwA=class extends Xy{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${Kei(this.value)?this.value:Bn(this.value)})`}};NA.register(GwA);var MwA=class iyt extends NA{static token="net";static parentToken="via";token="net";_id;_name;constructor(A,t){super(),this._id=A,this._name=t}static fromSexprPrimitives(A){const t=ai(A[0]);if(t===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?pi(A[1]):void 0;return new iyt(t,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} ${Bn(this._name)})`:`(net ${this._id})`}};NA.register(MwA);var Pei=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),RwA=class nyt 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 t=new nyt;for(const i of A){if(typeof i=="string"){t.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[n,...o]=i;if(typeof n!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);t.consumeNode(n,o)}return t}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!Pei.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,t){switch(A){case"type":{const i=pi(t[0]);if(i===void 0)throw new Error("via type expects a string value");this._type=i;return}case"locked":this._locked=this.parseYesNo(t);return;case"free":this._free=this.parseYesNo(t);return;case"remove_unused_layers":this._removeUnusedLayers=this.parseYesNo(t);return;case"keep_end_layers":this._keepEndLayers=this.parseYesNo(t);return;case"at":{const i=NA.parsePrimitiveSexpr(["at",...t],{parentToken:this.token});if(!(i instanceof Wg))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=ai(t[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=ai(t[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=Ij.fromSexprPrimitives(t);return}case"net":{this._sxNet=MwA.fromSexprPrimitives(t);return}case"teardrops":{this._sxTeardrops=uQt.fromSexprPrimitives(t);return}case"uuid":{const i=pi(t[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new Ui(i);return}case"tstamp":{const i=pi(t[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new Zg(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const t=pi(A[0]);if(t===void 0)throw new Error("Expected string when parsing via boolean child");return/^(yes|true)$/iu.test(t)}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?Wg.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 Ij?A:new Ij(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 Ui?A:new Ui(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 Zg?A:new Zg(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(`
|
|
5826
|
-
`)}};NA.register(RwA);var NwA=class oyt 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 t=new oyt;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 n=NA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof NA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof kwA){this._sxVersion=A;return}if(A instanceof FwA){this._sxGenerator=A;return}if(A instanceof GwA){this._sxGeneratorVersion=A;return}if(A instanceof xwA){this._sxGeneral=A;return}if(A instanceof V9){this._sxPaper=A;return}if(A instanceof VBt){this._sxTitleBlock=A;return}if(A instanceof _wA){this._sxLayers=A;return}if(A instanceof bwA){this._sxSetup=A;return}if(A instanceof WD){this._properties.push(A);return}if(A instanceof Bj){this._nets.push(A);return}if(A instanceof DmA){this._footprints.push(A);return}if(A instanceof zBt){this._images.push(A);return}if(A instanceof UmA){this._segments.push(A);return}if(A instanceof aj){this._grLines.push(A);return}if(A instanceof gj){this._grTexts.push(A);return}if(A instanceof HQt){this._grPolys.push(A);return}if(A instanceof vQt){this._grRects.push(A);return}if(A instanceof RwA){this._vias.push(A);return}if(A instanceof qQt){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 kwA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new FwA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new GwA(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(NwA);var jEt=e=>NA.parse(e),Uh=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,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")}},qei=class extends Uh{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new V9;t.size=A?.name??"A4",e.paper=t,e.uuid=new Ui(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function MG(e,A){if(e.manufacturer_part_number)return vwA(e.manufacturer_part_number);const t=Oei(e.ftype),i=A?.footprinter_string;return vwA(i?`${t}_${i}`:t)}function Oei(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function vwA(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Cj(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var zEt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},Wei=/^[A-Za-z]+\d+$/;function XEt(e){return e?Wei.test(e.trim()):!1}function Qj(e){const A=e?.ftype;if(A&&zEt[A])return zEt[A];const t=e?.name;return XEt(t),Cj(t)}function Zei(e){const A=e?.name;return XEt(A)?A.trim():`${Qj(e)}?`}function $Et(e){return e in SQ}function Aht(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?$Et(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return $Et(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=MG(e,t);return`Device:${Qj(e)}_${n}`}var Vei=class extends Uh{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new uCt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)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 c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Aht(t,e,i),a=t.ftype==="simple_chip",g=MG(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Qj(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=MG(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=this.buildSymbolDataFromSchematicPrimitives(i,o,e.schematic_component_id),g=MG(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Qj(A)})}buildSymbolDataFromSchematicPrimitives(e,A,t){const{circuitJson:i}=this.ctx,n=i.filter(c=>c.type==="schematic_circle"&&c.schematic_symbol_id===e),o=i.filter(c=>c.type==="schematic_line"&&c.schematic_symbol_id===e),s=i.filter(c=>c.type==="schematic_path"&&c.schematic_symbol_id===e);let r=i.filter(c=>c.type==="schematic_port"&&"schematic_symbol_id"in c&&c.schematic_symbol_id===e);if(r.length===0&&t&&(r=i.filter(c=>c.type==="schematic_port"&&c.schematic_component_id===t&&c.display_pin_label!==void 0),r.length===0)){const c=i.filter(l=>l.type==="schematic_port"&&l.schematic_component_id===t),I=new Set;r=c.filter(l=>{const B=l.pin_number;if(B!==void 0){if(I.has(B))return!1;I.add(B)}return!0})}const a=[];for(const c of n)a.push({type:"circle",x:c.center?.x??0,y:c.center?.y??0,radius:c.radius??.5,fill:c.is_filled??!1,fillColor:c.fill_color});for(const c of o)a.push({type:"path",points:[{x:c.x1??0,y:c.y1??0},{x:c.x2??0,y:c.y2??0}]});for(const c of s)c.points&&c.points.length>0&&a.push({type:"path",points:c.points,fill:c.is_filled??!1,fillColor:c.fill_color});const g=r.map((c,I)=>({x:c.center?.x??0,y:c.center?.y??0,labels:[c.display_pin_label||`${c.pin_number||I+1}`],pinNumber:c.pin_number||I+1,facingDirection:c.facing_direction}));return g.sort((c,I)=>c.pinNumber-I.pinNumber),{center:A.center||{x:0,y:0},size:A.size||{width:1,height:1},primitives:a,ports:g}}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=SQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?this.createGenericChipSymbolData(A,this.ctx.db):SQ[e]||null}createGenericChipSymbolData(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.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:[o],ports:s,size:{width:i,height:n}}}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new d1({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new lyA;c.hide=!t,g._sxPinNumbers=c;const I=new CyA;I.offset=t?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const l=this.createDrawingSubsymbol({libId:e,symbolData:A,isChip:t});g.subSymbols.push(l);const B=this.createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i});return g.subSymbols.push(B),g._sxEmbeddedFonts=new h1(!1),g}addSymbolProperties({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,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:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new mf({key:g.key,value:g.value,id:g.id,at:g.at,effects:this.createTextEffects(1.27,g.hide)}))}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:e,symbolData:A,isChip:t}){const i=new d1({libraryId:`${e.split(":")[1]}_0_1`}),n=15.24,o=this.ctx.c2kMatSch?.a||15,s=t?o:n;for(const r of A.primitives||[])if(r.type==="path"&&r.points){const a=t||r.fill?"background":"none",g=this.createPolylineFromPoints({points:r.points,scale:s,center:A.center,fillType:a});i.polylines.push(g)}else if(r.type==="circle"){const a=this.createCircleFromPrimitive({primitive:r,scale:s,center:A.center});i.circles.push(a)}return i}createPolylineFromPoints({points:e,scale:A,center:t,fillType:i}){const n=new $Bt,o=t?.x??0,s=t?.y??0,r=mE(A,A),a=e.map(l=>{const B=Pe(r,{x:l.x-o,y:l.y-s});return new YQ(B.x,B.y)}),g=new TC(a);n.points=g;const c=new OD;c.width=.254,c.type="default",n.stroke=c;const I=new sCt;return I.type=i,n.fill=I,n}createCircleFromPrimitive({primitive:e,scale:A,center:t}){const i=new gCt,n=t?.x??0,o=t?.y??0,s=mE(A,A),r=Pe(s,{x:e.x-n,y:e.y-o}),a=i;a._sxCenter=new nCt(r.x,r.y),a._sxRadius=new oCt(e.radius*A);const g=new OD;g.width=.254,g.type="default",a._sxStroke=g;const c=new rCt;return c.type=e.fill?"background":"none",a._sxFill=c,i}createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i}){const n=new d1({libraryId:`${e.split(":")[1]}_1_1`});for(let o=0;o<(A.ports?.length||0);o++){const s=A.ports[o],r=new $9;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,t,o,i);r.at=[a,g,c];const I=6,l=2.54;r.length=t?I:l;const B=new L0;B.size={height:1.27,width:1.27};const C=new v0({font:B}),E=s.labels?.[0]||"~";r._sxName=new QyA({value:E,effects:C});const Q=new L0;Q.size={height:1.27,width:1.27};const h=new v0({font:Q}),u=s.pinNumber?.toString()||`${o+1}`;r._sxNumber=new ICt({value:u,effects:h}),n.pins.push(r)}return n}calculatePinPosition(e,A,t,i,n,o){const r=this.ctx.c2kMatSch?.a||15,a=i?r:15.24;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=this.ctx.db.schematic_port.list().filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=mE(a,a),E=Pe(C,{x:l,y:B});let Q;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,b=Math.abs(B)/w;Q=D>b}else Q=Math.abs(l)>Math.abs(B);let h=E.x,u=E.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;Q?(h=l>0?m:-m,u=B*a):(h=l*a,u=B>0?w:-w)}let f=0;return Q?l>0?(f=180,i&&(h=h+d)):(f=0,i&&(h=h-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:h,y:u,angle:f}}createTextEffects(e,A){const t=new L0;return t.size={height:e,width:e},new v0({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},jei=class extends Uh{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Pe(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new d1({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=MG(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Aht(o,n,c,I),C=new cyA(B);g._sxLibId=C;const{reference:E,value:Q,description:h}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(this.ctx.symbolMetadataMap&&o.name){const oA=Cj(o.name);f=this.ctx.symbolMetadataMap.get(oA)}const m=f?.properties?.Reference,w=new mf({key:"Reference",value:m?.value??E,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",b=f?.properties?.Value,k=new mf({key:"Value",value:b?.value??Q,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(b?.effects?.font?.size?.x??1.27),b?.effects?.hide??D)}),x=f?.properties?.Footprint,N=new mf({key:"Footprint",value:x?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,x?.effects?.hide??!0)}),R=f?.properties?.Datasheet,U=new mf({key:"Datasheet",value:R?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,R?.effects?.hide??!0)}),J=f?.properties?.Description,H=new mf({key:"Description",value:J?.value??h,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,J?.effects?.hide??!0)});g.properties.push(w,k,N,U,H);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new mf({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new mf({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new CyA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new lyA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new h1(f.embeddedFonts))}let X=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=X.filter(rA=>rA.display_pin_label);oA.length>0&&(X=oA)}X.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<X.length;oA++){const rA=X[oA];if(!rA)continue;const CA=new $9;CA.numberString=`${rA.pin_number||oA+1}`,CA.uuid=crypto.randomUUID(),g.pins.push(CA)}const iA=new EyA,aA=new uyA(""),tA=new dyA(`/${e?.uuid?.value||""}`);tA.reference=E,tA.unit=1,aA.paths.push(tA),iA.projects.push(aA),g._sxInstances=iA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Pe(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=SQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Pe(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Pe(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=Zei(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new L0;i.size={height:e,width:e};const n=t?new kJ({horizontal:t}):void 0;return new v0({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},zei=class extends Uh{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Pe(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new d1({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new cyA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new mf({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new mf({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new mf({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),E=new mf({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),Q=new mf({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,E,Q);const h=new $9;h.numberString="1",h.uuid=crypto.randomUUID(),s.pins.push(h);const{kicadSch:u}=this.ctx,d=new EyA,f=new uyA(""),m=new dyA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Pe(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new kJ(a)),new bCt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new L0;return t.size={height:e,width:e},new v0({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Xei=class extends Uh{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new pCt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Pe(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Pe(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new TC([new YQ(n,o),new YQ(s,r)]);A.points=a;const g=new OD;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Pe(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new fCt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},$ei=class extends Uh{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new myA,t=new kCt;t.value="/";const i=new FCt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new h1(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Aii(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var Ej=[{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 tii(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<Ej.length;o++){const s=Ej[o];if(i<=s.width&&n<=s.height)return s}return Ej[Ej.length-1]}var tht=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){const i=_a(e),{center:n,bounds:o}=Aii(i),s=(o.maxX-o.minX)*15,r=(o.maxY-o.minY)*15,a=tii(s,r),g=a.width/2,c=a.height/2;this.ctx={db:i,circuitJson:e,kicadSch:new DyA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:a,c2kMatSch:oB(Er(g,c),mE(15,-15),Er(-n.x,-n.y)),symbolMetadataMap:A?.symbolMetadataMap},this.pipeline=[new qei(e,this.ctx),new Vei(e,this.ctx),new jei(e,this.ctx),new zei(e,this.ctx),new Xei(e,this.ctx),new $ei(e,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()}},eii=class extends Uh{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new V9;n.size="A4",e.paper=n;const o=new xwA;o.thickness=1.6,e.general=o;const s=new bwA;s.padToMaskClearance=0,e.setup=s;const r=new _wA,a=[new Rl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Rl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Rl({index:31,name:"B.Cu",type:"signal"})),a.push(new Rl({index:32,name:"B.Adhes",type:"user"}),new Rl({index:33,name:"F.Adhes",type:"user"}),new Rl({index:34,name:"B.Paste",type:"user"}),new Rl({index:35,name:"F.Paste",type:"user"}),new Rl({index:36,name:"B.SilkS",type:"user"}),new Rl({index:37,name:"F.SilkS",type:"user"}),new Rl({index:38,name:"B.Mask",type:"user"}),new Rl({index:39,name:"F.Mask",type:"user"}),new Rl({index:40,name:"Dwgs.User",type:"user"}),new Rl({index:41,name:"Cmts.User",type:"user"}),new Rl({index:42,name:"Eco1.User",type:"user"}),new Rl({index:43,name:"Eco2.User",type:"user"}),new Rl({index:44,name:"Edge.Cuts",type:"user"}),new Rl({index:45,name:"Margin",type:"user"}),new Rl({index:46,name:"B.CrtYd",type:"user"}),new Rl({index:47,name:"F.CrtYd",type:"user"}),new Rl({index:48,name:"B.Fab",type:"user"}),new Rl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},iii=class extends Uh{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}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 c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new Bj(0,""));let s=1;for(const[r,a]of n){const g=new Bj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function nii(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function wf(e){const A=nii(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function hj(e){const A=new L0;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new v0({font:A})}function oii(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new WD({key:"Reference",value:n?.value??"REF**",position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:wf(`${t}-property-Reference`),effects:hj(n?.effects),hidden:n?.hide}));const o=A.properties.Value;i.push(new WD({key:"Value",value:o?.value??t,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:wf(`${t}-property-Value`),effects:hj(o?.effects),hidden:o?.hide}));const s=A.properties.Datasheet;i.push(new WD({key:"Datasheet",value:s?.value??"",position:s?.at?[Number(s.at.x),Number(s.at.y),Number(s.at.rotation??0)]:[0,0,0],layer:s?.layer??"F.Fab",uuid:wf(`${t}-property-Datasheet`),effects:hj(s?.effects),hidden:s?.hide??!0}));const r=A.properties.Description;i.push(new WD({key:"Description",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:wf(`${t}-property-Description`),effects:hj(r?.effects),hidden:r?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new SyA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new h1(A.embeddedFonts)),A.model){const i=new oj(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function sii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new gmA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new OD,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function rii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new gmA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new OD,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function aii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new ij({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new OD,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function gii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new ij({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new OD,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function cii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new ij({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new OD,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function Iii(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new YQ(c,I)}),r=new mQt;r.points=new TC(s),r.layer=o,r.fill=!1;const a=new OD;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function lii({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Lm(t*Math.PI/180):Lu(),s=Pe(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new L0;I.size={width:c,height:c};const l=new v0({font:I}),B=e.ccw_rotation||0;return new $yA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function Bii(e,A,t,i){const n=[];for(const o of e){const s=lii({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function Cii(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Lm(t*Math.PI/180):Lu(),a=Pe(r,{x:o,y:s}),g=n.font_size||1,c=new L0;c.size={width:g,height:g};const I=new v0({font:c}),l=new $yA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function Qii(e,A){const t=[],i=e.model_step_url||e.model_wrl_url;if(!i)return t;const n=new oj(i);if(e.position&&(n.offset={x:(e.position.x||0)-A.x,y:-((e.position.y||0)-A.y),z:e.position.z||0}),e.rotation&&(n.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const o=e.model_unit_to_mm_scale_factor;n.scale={x:o,y:o,z:o}}return t.push(n),t}function Eii({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.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=oB(i!==0?Lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},mE(1,-1),Er(-A.x,-A.y)),g=Pe(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,E;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=oB(mE(1,-1),Er(-s,-r)),f=u.map(w=>{const D=Pe(d,{x:w.x,y:w.y});return new YQ(D.x,D.y)}),m=new ZyA;m.contours=[new TC(f)],m.width=0,m.filled=!0,E=new sQt,E.addGraphic(m),l="custom",C=new KCt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const Q=`pad:${o}:${t}:${g.x},${g.y}`,h=new ej({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:wf(Q)});return C&&(h.options=C),E&&(h.primitives=E),n&&(h.net=new TyA(n.id,n.name)),h}function hii(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=Eii({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function uii({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Lm(i*Math.PI/180):Lu(),g=Pe(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let E;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(E=Pe(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new ZD({diameter:e.hole_diameter,offset:E})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new ZD({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:E})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new ZD({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:E})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new ZD({diameter:e.hole_diameter,offset:E})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new ZD({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:E}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new ZD({diameter:.8,offset:E}));const Q=`thruhole:${o}:${t}:${g.x},${g.y}`,h=new ej({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:wf(Q)});return n&&(h.net=new TyA(n.id,n.name)),h}function dii(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=uii({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function pii({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Lm(t*Math.PI/180):Lu(),s=Pe(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new ZD({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new ZD({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new ZD({diameter:c})}return new ej({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 fii(e,A,t){const i=[];for(const n of e){const o=pii({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var yii=class extends Uh{componentsProcessed=0;pcbComponents=[];getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)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 t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?MG(i,n):"Unknown",s=Pe(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new DmA({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:wf(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Bii(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Cii(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=H=>this.getNetInfoForPcbPort(H),C=this.ctx.db.pcb_smtpad?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:E,nextPadNumber:Q}=hii(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...E);const h=this.ctx.db.pcb_plated_hole?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:u}=dii(h,t.center,t.rotation||0,t.pcb_component_id,Q,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(H=>H.subcircuit_id===t.subcircuit_id)||[],f=fii(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...sii(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];w.push(...rii(D,t.center)),a.fpCircles=w;const b=this.ctx.db.pcb_fabrication_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],k=a.fpRects??[];k.push(...aii(b,t.center));const x=this.ctx.db.pcb_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(...gii(x,t.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(...cii(N,t.center)),a.fpRects=k;const R=this.ctx.db.pcb_courtyard_outline?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],U=Iii(R,t.center);if(U.length>0&&(a.fpPolys=U),n){const H=Qii(n,t.center);H.length>0&&(a.models=H)}if(this.ctx.footprintMetadataMap&&i?.name){const H=Cj(i.name),O=this.ctx.footprintMetadataMap.get(H);O&&oii(a,O,i.name)}const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},mii={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function wii(e){return e&&(mii[e]||e)||"F.Cu"}function Dii(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var Sii=class extends Uh{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)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}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Pe(A,{x:s.x,y:s.y}),g=Pe(A,{x:r.x,y:r.y});let c;if(t){let Q=i.subcircuit_connectivity_map_key;if(!Q&&i.source_trace_id){const h=this.ctx.db.source_trace?.get(i.source_trace_id);if(h&&(Q=h.subcircuit_connectivity_map_key,!Q&&h.connected_source_net_ids?.length))for(const u of h.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){Q=d.subcircuit_connectivity_map_key;break}}}if(!Q&&typeof i.connection_name=="string"){const h=this.ctx.db.source_net?.get(i.connection_name);h?.subcircuit_connectivity_map_key&&(Q=h.subcircuit_connectivity_map_key)}Q&&(c=t.get(Q))}const I=s.layer??r.layer??n,l=wii(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new UmA({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new cj(c?.id??0),uuid:wf(B)}),E=e.segments;E.push(C),e.segments=E,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},bii=class extends Uh{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)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],n=Pe(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const E=this.ctx.db.source_net?.get(C);if(E?.subcircuit_connectivity_map_key){I=E.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):Dii(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new RwA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new MwA(o?.id??0),uuid:wf(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function xii({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new L0;s.size={width:o,height:o};const r=new kJ,a=e.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 v0({font:s});a!=="center"&&(g.justify=r);const c=new Wg([t.x,t.y,0]),I=new gj({text:e.text,layer:n,effects:g});return I.position=c,I}function _ii({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new L0;s.size={width:o,height:o};const r=new kJ,a=e.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 v0({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new Wg([t.x,t.y,c]),l=new gj({text:e.text,layer:n,effects:g});return l.position=I,l}var kii=class extends Uh{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Pe(A,{x:a.x,y:a.y}),I=Pe(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new aj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),E=e.graphicLines;E.push(C),e.graphicLines=E}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=_ii({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=xii({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Pe(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new aj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},eht=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:_a(e),circuitJson:e,kicadPcb:new NwA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:oB(Er(100,100),mE(1,-1)),footprintMetadataMap:A?.footprintMetadataMap},this.pipeline=[new eii(e,this.ctx),new iii(e,this.ctx),new yii(e,this.ctx),new Sii(e,this.ctx),new bii(e,this.ctx),new kii(e,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()}},Fii=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:_a(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},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:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5826
|
+
`)}};NA.register(RwA);var NwA=class oyt 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 t=new oyt;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 n=NA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof NA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);t.consumeChild(n)}return t}consumeChild(A){if(A instanceof kwA){this._sxVersion=A;return}if(A instanceof FwA){this._sxGenerator=A;return}if(A instanceof GwA){this._sxGeneratorVersion=A;return}if(A instanceof xwA){this._sxGeneral=A;return}if(A instanceof V9){this._sxPaper=A;return}if(A instanceof VBt){this._sxTitleBlock=A;return}if(A instanceof _wA){this._sxLayers=A;return}if(A instanceof bwA){this._sxSetup=A;return}if(A instanceof WD){this._properties.push(A);return}if(A instanceof Bj){this._nets.push(A);return}if(A instanceof DmA){this._footprints.push(A);return}if(A instanceof zBt){this._images.push(A);return}if(A instanceof UmA){this._segments.push(A);return}if(A instanceof aj){this._grLines.push(A);return}if(A instanceof gj){this._grTexts.push(A);return}if(A instanceof HQt){this._grPolys.push(A);return}if(A instanceof vQt){this._grRects.push(A);return}if(A instanceof RwA){this._vias.push(A);return}if(A instanceof qQt){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 kwA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new FwA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new GwA(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(NwA);var jEt=e=>NA.parse(e),Uh=class{MAX_ITERATIONS=1e3;iteration=0;finished=!1;input;ctx;constructor(e,A){this.input=e,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")}},qei=class extends Uh{_step(){const{kicadSch:e,schematicPaperSize:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");e.version=20250114;const t=new V9;t.size=A?.name??"A4",e.paper=t,e.uuid=new Ui(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function MG(e,A){if(e.manufacturer_part_number)return vwA(e.manufacturer_part_number);const t=Oei(e.ftype),i=A?.footprinter_string;return vwA(i?`${t}_${i}`:t)}function Oei(e){if(!e)return"component";let A=e.replace(/^simple_/,"");return A||"component"}function vwA(e){return e.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Cj(e){return e?e.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var zEt={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},Wei=/^[A-Za-z]+\d+$/;function XEt(e){return e?Wei.test(e.trim()):!1}function Qj(e){const A=e?.ftype;if(A&&zEt[A])return zEt[A];const t=e?.name;return XEt(t),Cj(t)}function Zei(e){const A=e?.name;return XEt(A)?A.trim():`${Qj(e)}?`}function $Et(e){return e in SQ}function Aht(e,A,t,i){if(i)return`Custom:${i}`;if(e.type!=="source_component")return A.symbol_name?$Et(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return $Et(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=MG(e,t);return`Device:${Qj(e)}_${n}`}var Vei=class extends Uh{processedSymbolNames=new Set;_step(){const{kicadSch:e,db:A}=this.ctx,t=new uCt,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)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 c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}t.symbols=i,e&&(e.libSymbols=t),this.finished=!0}createLibrarySymbolForComponent(e){const{db:A}=this.ctx,t=e.source_component_id?A.source_component.get(e.source_component_id):null;if(!t)return null;const i=A.cad_component?.list()?.find(c=>c.source_component_id===t.source_component_id);let n=e.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===e.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(e,t,i,n);const o=e.symbol_name||(t.ftype==="simple_chip"?`generic_chip_${e.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,e);if(!s)return null;const r=Aht(t,e,i),a=t.ftype==="simple_chip",g=MG(t,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:e,description:this.getDescription(t),keywords:this.getKeywords(t),fpFilters:this.getFpFilters(t),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Qj(t)})}createLibrarySymbolFromSchematicSymbol(e,A,t,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=MG(A,t);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=this.buildSymbolDataFromSchematicPrimitives(i,o,e.schematic_component_id),g=MG(A,t);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:e,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:Qj(A)})}buildSymbolDataFromSchematicPrimitives(e,A,t){const{circuitJson:i}=this.ctx,n=i.filter(c=>c.type==="schematic_circle"&&c.schematic_symbol_id===e),o=i.filter(c=>c.type==="schematic_line"&&c.schematic_symbol_id===e),s=i.filter(c=>c.type==="schematic_path"&&c.schematic_symbol_id===e);let r=i.filter(c=>c.type==="schematic_port"&&"schematic_symbol_id"in c&&c.schematic_symbol_id===e);if(r.length===0&&t&&(r=i.filter(c=>c.type==="schematic_port"&&c.schematic_component_id===t&&c.display_pin_label!==void 0),r.length===0)){const c=i.filter(l=>l.type==="schematic_port"&&l.schematic_component_id===t),I=new Set;r=c.filter(l=>{const B=l.pin_number;if(B!==void 0){if(I.has(B))return!1;I.add(B)}return!0})}const a=[];for(const c of n)a.push({type:"circle",x:c.center?.x??0,y:c.center?.y??0,radius:c.radius??.5,fill:c.is_filled??!1,fillColor:c.fill_color});for(const c of o)a.push({type:"path",points:[{x:c.x1??0,y:c.y1??0},{x:c.x2??0,y:c.y2??0}]});for(const c of s)c.points&&c.points.length>0&&a.push({type:"path",points:c.points,fill:c.is_filled??!1,fillColor:c.fill_color});const g=r.map((c,I)=>({x:c.center?.x??0,y:c.center?.y??0,labels:[c.display_pin_label||`${c.pin_number||I+1}`],pinNumber:c.pin_number||I+1,facingDirection:c.facing_direction}));return g.sort((c,I)=>c.pinNumber-I.pinNumber),{center:A.center||{x:0,y:0},size:A.size||{width:1,height:1},primitives:a,ports:g}}createLibrarySymbolForNetLabel({netLabel:e,isPower:A,isGround:t}){const i=e.symbol_name;if(!i)return null;const n=SQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,isChip:!1,schematicComponent:void 0,description:A?"Power net label":t?"Ground net label":"Net symbol",keywords:A?"power net":t?"ground net":"net",fpFilters:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(e,A){return e.startsWith("generic_chip_")?this.createGenericChipSymbolData(A,this.ctx.db):SQ[e]||null}createGenericChipSymbolData(e,A){const t=A.schematic_port.list().filter(r=>r.schematic_component_id===e.schematic_component_id).sort((r,a)=>(r.pin_number||0)-(a.pin_number||0)),i=e.size?.width||1.5,n=e.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/2}]},s=t.map(r=>{const a=r.center.x-e.center.x,g=r.center.y-e.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:[o],ports:s,size:{width:i,height:n}}}createLibrarySymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new d1({libraryId:e,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new lyA;c.hide=!t,g._sxPinNumbers=c;const I=new CyA;I.offset=t?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:e,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const l=this.createDrawingSubsymbol({libId:e,symbolData:A,isChip:t});g.subSymbols.push(l);const B=this.createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i});return g.subSymbols.push(B),g._sxEmbeddedFonts=new h1(!1),g}addSymbolProperties({symbol:e,libId:A,description:t,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:t,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:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)e.properties.push(new mf({key:g.key,value:g.value,id:g.id,at:g.at,effects:this.createTextEffects(1.27,g.hide)}))}getDescription(e){return e?.ftype==="simple_resistor"?"Resistor":e?.ftype==="simple_capacitor"?"Capacitor":e?.ftype==="simple_chip"?"Integrated Circuit":"Component"}getKeywords(e){return e?.ftype==="simple_resistor"?"R res resistor":e?.ftype==="simple_capacitor"?"C cap capacitor":e?.ftype==="simple_chip"?"U IC chip":""}getFpFilters(e,A){return A?`${A}*`:e?.ftype==="simple_resistor"?"R_*":e?.ftype==="simple_capacitor"?"C_*":(e?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:e,symbolData:A,isChip:t}){const i=new d1({libraryId:`${e.split(":")[1]}_0_1`}),n=15.24,o=this.ctx.c2kMatSch?.a||15,s=t?o:n;for(const r of A.primitives||[])if(r.type==="path"&&r.points){const a=t||r.fill?"background":"none",g=this.createPolylineFromPoints({points:r.points,scale:s,center:A.center,fillType:a});i.polylines.push(g)}else if(r.type==="circle"){const a=this.createCircleFromPrimitive({primitive:r,scale:s,center:A.center});i.circles.push(a)}return i}createPolylineFromPoints({points:e,scale:A,center:t,fillType:i}){const n=new $Bt,o=t?.x??0,s=t?.y??0,r=mE(A,A),a=e.map(l=>{const B=Pe(r,{x:l.x-o,y:l.y-s});return new YQ(B.x,B.y)}),g=new TC(a);n.points=g;const c=new OD;c.width=.254,c.type="default",n.stroke=c;const I=new sCt;return I.type=i,n.fill=I,n}createCircleFromPrimitive({primitive:e,scale:A,center:t}){const i=new gCt,n=t?.x??0,o=t?.y??0,s=mE(A,A),r=Pe(s,{x:e.x-n,y:e.y-o}),a=i;a._sxCenter=new nCt(r.x,r.y),a._sxRadius=new oCt(e.radius*A);const g=new OD;g.width=.254,g.type="default",a._sxStroke=g;const c=new rCt;return c.type=e.fill?"background":"none",a._sxFill=c,i}createPinSubsymbol({libId:e,symbolData:A,isChip:t,schematicComponent:i}){const n=new d1({libraryId:`${e.split(":")[1]}_1_1`});for(let o=0;o<(A.ports?.length||0);o++){const s=A.ports[o],r=new $9;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,t,o,i);r.at=[a,g,c];const I=6,l=2.54;r.length=t?I:l;const B=new L0;B.size={height:1.27,width:1.27};const C=new v0({font:B}),E=s.labels?.[0]||"~";r._sxName=new QyA({value:E,effects:C});const Q=new L0;Q.size={height:1.27,width:1.27};const h=new v0({font:Q}),u=s.pinNumber?.toString()||`${o+1}`;r._sxNumber=new ICt({value:u,effects:h}),n.pins.push(r)}return n}calculatePinPosition(e,A,t,i,n,o){const r=this.ctx.c2kMatSch?.a||15,a=i?r:15.24;let g=e.x??0,c=e.y??0,I=!1;if(i&&n!==void 0&&o){const m=this.ctx.db.schematic_port.list().filter(w=>w.schematic_component_id===o.schematic_component_id).sort((w,D)=>(w.pin_number||0)-(D.pin_number||0));if(m[n]){const w=m[n];g=w.center.x-o.center.x,c=w.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,w=A?.y??0;l=g-m,B=c-w}const C=mE(a,a),E=Pe(C,{x:l,y:B});let Q;if(i&&t){const m=t.width/2,w=t.height/2,D=Math.abs(l)/m,b=Math.abs(B)/w;Q=D>b}else Q=Math.abs(l)>Math.abs(B);let h=E.x,u=E.y;const d=6;if(i&&t){const m=t.width/2*a,w=t.height/2*a;Q?(h=l>0?m:-m,u=B*a):(h=l*a,u=B>0?w:-w)}let f=0;return Q?l>0?(f=180,i&&(h=h+d)):(f=0,i&&(h=h-d)):B>0?(f=270,i&&(u=u+d)):(f=90,i&&(u=u-d)),{x:h,y:u,angle:f}}createTextEffects(e,A){const t=new L0;return t.size={height:e,width:e},new v0({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},jei=class extends Uh{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_component.list();if(t.length===0){this.finished=!0;return}const i=[];for(const n of t){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Pe(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new d1({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(oA=>oA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const oA=this.ctx.circuitJson.find(rA=>(rA.type==="schematic_line"||rA.type==="schematic_circle"||rA.type==="schematic_path")&&rA.schematic_component_id===n.schematic_component_id&&rA.schematic_symbol_id);oA&&(l=oA.schematic_symbol_id)}if(l){const oA=this.ctx.circuitJson.find(rA=>rA.type==="schematic_symbol"&&rA.schematic_symbol_id===l);if(oA?.name)I=oA.name;else{const rA=MG(o,c);rA?I=rA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Aht(o,n,c,I),C=new cyA(B);g._sxLibId=C;const{reference:E,value:Q,description:h}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let f;if(this.ctx.symbolMetadataMap&&o.name){const oA=Cj(o.name);f=this.ctx.symbolMetadataMap.get(oA)}const m=f?.properties?.Reference,w=new mf({key:"Reference",value:m?.value??E,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),D=o.ftype==="simple_chip",b=f?.properties?.Value,k=new mf({key:"Value",value:b?.value??Q,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(b?.effects?.font?.size?.x??1.27),b?.effects?.hide??D)}),x=f?.properties?.Footprint,N=new mf({key:"Footprint",value:x?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,x?.effects?.hide??!0)}),R=f?.properties?.Datasheet,U=new mf({key:"Datasheet",value:R?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,R?.effects?.hide??!0)}),J=f?.properties?.Description,H=new mf({key:"Description",value:J?.value??h,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,J?.effects?.hide??!0)});g.properties.push(w,k,N,U,H);const O=f?.properties?.ki_keywords;if(O?.value){const oA=new mf({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(oA)}const W=f?.properties?.ki_fp_filters;if(W?.value){const oA=new mf({key:"ki_fp_filters",value:W.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,W.effects?.hide??!0)});g.properties.push(oA)}if(f){if(f.inBom!==void 0&&(g.inBom=f.inBom),f.onBoard!==void 0&&(g.onBoard=f.onBoard),f.excludeFromSim!==void 0&&(g.excludeFromSim=f.excludeFromSim),f.pinNames){const oA=new CyA;f.pinNames.offset!==void 0&&(oA.offset=Number(f.pinNames.offset)),f.pinNames.hide!==void 0&&(oA.hide=f.pinNames.hide),g.pinNames=oA}if(f.pinNumbers){const oA=new lyA;f.pinNumbers.hide!==void 0&&(oA.hide=f.pinNumbers.hide),g.pinNumbers=oA}f.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new h1(f.embeddedFonts))}let X=A.schematic_port.list().filter(oA=>oA.schematic_component_id===n.schematic_component_id);if(l){const oA=X.filter(rA=>rA.display_pin_label);oA.length>0&&(X=oA)}X.sort((oA,rA)=>(oA.pin_number||0)-(rA.pin_number||0));for(let oA=0;oA<X.length;oA++){const rA=X[oA];if(!rA)continue;const CA=new $9;CA.numberString=`${rA.pin_number||oA+1}`,CA.uuid=crypto.randomUUID(),g.pins.push(CA)}const iA=new EyA,aA=new uyA(""),tA=new dyA(`/${e?.uuid?.value||""}`);tA.reference=E,tA.unit=1,aA.paths.push(tA),iA.projects.push(aA),g._sxInstances=iA,i.push(g)}e&&(e.symbols=i),this.finished=!0}getTextPositions(e,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===e.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Pe(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=e.symbol_name,o=SQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Pe(this.ctx.c2kMatSch,{x:e.center.x+(s.x-a.x)+c,y:e.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Pe(this.ctx.c2kMatSch,{x:e.center.x+(r.x-a.x)+c,y:e.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(e){const A=e.name||"?",t=Zei(e);return e.ftype==="simple_resistor"?{reference:t,value:e.display_resistance||"R",description:"Resistor"}:e.ftype==="simple_capacitor"?{reference:t,value:e.display_capacitance||"C",description:"Capacitor"}:e.ftype==="simple_inductor"?{reference:t,value:e.display_inductance||"L",description:"Inductor"}:e.ftype==="simple_diode"?{reference:t,value:"D",description:"Diode"}:e.ftype==="simple_chip"?{reference:t,value:A,description:"Integrated Circuit"}:e.ftype==="simple_led"?{reference:t,value:e.manufacturer_part_number||"",description:"LED"}:e.ftype==="simple_switch"?{reference:t,value:e.manufacturer_part_number||"",description:"Switch"}:e.ftype==="simple_potentiometer"?{reference:t,value:e.display_max_resistance||"",description:"Potentiometer"}:{reference:t,value:A,description:"Component"}}createTextEffects(e,A=!1,t){const i=new L0;i.size={height:e,width:e};const n=t?new kJ({horizontal:t}):void 0;return new v0({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},zei=class extends Uh{_step(){const{kicadSch:e,db:A}=this.ctx,t=A.schematic_net_label?.list?.()||[];if(t.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],n=[];for(const o of t){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(e&&i.length>0){const o=e.symbols||[];e.symbols=[...o,...i]}e&&n.length>0&&(e.globalLabels=[...e.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(e,A,t){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Pe(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),o=crypto.randomUUID(),s=new d1({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${t}`,a=new cyA(r);s._sxLibId=a;const g=t.includes("_up")||t.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new mf({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new mf({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new mf({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),E=new mf({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),Q=new mf({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,E,Q);const h=new $9;h.numberString="1",h.uuid=crypto.randomUUID(),s.pins.push(h);const{kicadSch:u}=this.ctx,d=new EyA,f=new uyA(""),m=new dyA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(e,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:t,y:i}=Pe(this.ctx.c2kMatSch,{x:e.anchor_position?.x??e.center?.x??0,y:e.anchor_position?.y??e.center?.y??0}),n=e.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new kJ(a)),new bCt({value:A,at:[t,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(e,A=!1){const t=new L0;return t.size={height:e,width:e},new v0({font:t,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Xei=class extends Uh{_step(){const{kicadSch:e,db:A}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const t=A.schematic_trace.list();if(t.length===0){this.finished=!0;return}const i=[],n=[];for(const o of t){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}e.wires=i,e.junctions=n,this.finished=!0}createWireFromEdge(e){const A=new pCt;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const t=Pe(this.ctx.c2kMatSch,{x:e.from.x,y:e.from.y}),i=Pe(this.ctx.c2kMatSch,{x:e.to.x,y:e.to.y}),n=t.x,o=t.y,s=i.x,r=i.y,a=new TC([new YQ(n,o),new YQ(s,r)]);A.points=a;const g=new OD;return g.width=0,g.type="default",A.stroke=g,A.uuid=crypto.randomUUID(),A}createJunction(e){if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const{x:A,y:t}=Pe(this.ctx.c2kMatSch,{x:e.x,y:e.y}),i=new fCt({at:[A,t],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},$ei=class extends Uh{_step(){const{kicadSch:e}=this.ctx;if(!e)throw new Error("KicadSch instance not initialized in context");const A=new myA,t=new kCt;t.value="/";const i=new FCt("1");t.pages=[i],A.paths=[t],e.sheetInstances=A,e.embeddedFonts=new h1(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Aii(e){const A=e.schematic_component.list(),t=e.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of t)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var Ej=[{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 tii(e,A,t=20){const i=e+2*t,n=A+2*t;for(let o=0;o<Ej.length;o++){const s=Ej[o];if(i<=s.width&&n<=s.height)return s}return Ej[Ej.length-1]}var tht=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){const i=_a(e),{center:n,bounds:o}=Aii(i),s=(o.maxX-o.minX)*15,r=(o.maxY-o.minY)*15,a=tii(s,r),g=a.width/2,c=a.height/2;this.ctx={db:i,circuitJson:e,kicadSch:new DyA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:a,c2kMatSch:oB(Er(g,c),mE(15,-15),Er(-n.x,-n.y)),symbolMetadataMap:A?.symbolMetadataMap},this.pipeline=[new qei(e,this.ctx),new Vei(e,this.ctx),new jei(e,this.ctx),new zei(e,this.ctx),new Xei(e,this.ctx),new $ei(e,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()}},eii=class extends Uh{_step(){const{kicadPcb:e,db:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,e.version=20241229;const n=new V9;n.size="A4",e.paper=n;const o=new xwA;o.thickness=1.6,e.general=o;const s=new bwA;s.padToMaskClearance=0,e.setup=s;const r=new _wA,a=[new Rl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new Rl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new Rl({index:31,name:"B.Cu",type:"signal"})),a.push(new Rl({index:32,name:"B.Adhes",type:"user"}),new Rl({index:33,name:"F.Adhes",type:"user"}),new Rl({index:34,name:"B.Paste",type:"user"}),new Rl({index:35,name:"F.Paste",type:"user"}),new Rl({index:36,name:"B.SilkS",type:"user"}),new Rl({index:37,name:"F.SilkS",type:"user"}),new Rl({index:38,name:"B.Mask",type:"user"}),new Rl({index:39,name:"F.Mask",type:"user"}),new Rl({index:40,name:"Dwgs.User",type:"user"}),new Rl({index:41,name:"Cmts.User",type:"user"}),new Rl({index:42,name:"Eco1.User",type:"user"}),new Rl({index:43,name:"Eco2.User",type:"user"}),new Rl({index:44,name:"Edge.Cuts",type:"user"}),new Rl({index:45,name:"Margin",type:"user"}),new Rl({index:46,name:"B.CrtYd",type:"user"}),new Rl({index:47,name:"F.CrtYd",type:"user"}),new Rl({index:48,name:"B.Fab",type:"user"}),new Rl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,e.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},iii=class extends Uh{_step(){const{kicadPcb:e}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");this.ctx.pcbNetMap=new Map;const A=new Map,t=this.ctx.db.source_net?.list()??[];for(const r of t){const a=r.subcircuit_connectivity_map_key||r.source_net_id;if(!a)continue;const g=r.name||r.source_net_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}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 c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new Bj(0,""));let s=1;for(const[r,a]of n){const g=new Bj(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}e.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function nii(e){let A=0;for(let i=0;i<e.length;i++){const n=e.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let t="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<e.length;o++)n=(n<<5)-n+e.charCodeAt(o)+i*31,n=n&n;t+=Math.abs(n).toString(16).padStart(8,"0")}return t}function wf(e){const A=nii(e);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function hj(e){const A=new L0;return e?.font?.size?A.size={width:Number(e.font.size.x),height:Number(e.font.size.y)}:A.size={width:1.27,height:1.27},e?.font?.thickness!==void 0?A.thickness=Number(e.font.thickness):A.thickness=.15,new v0({font:A})}function oii(e,A,t){if(A.properties){const i=[],n=A.properties.Reference;i.push(new WD({key:"Reference",value:t,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:wf(`${t}-property-Reference`),effects:hj(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new WD({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:wf(`${t}-property-Value`),effects:hj(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new WD({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:wf(`${t}-property-Datasheet`),effects:hj(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new WD({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:wf(`${t}-property-Description`),effects:hj(a?.effects),hidden:a?.hide??!0})),e.properties=i}if(A.attributes&&(e.attr||(e.attr=new SyA),A.attributes.through_hole?e.attr.type="through_hole":A.attributes.smd&&(e.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(e.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(e.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(e.libraryLink=A.footprintName),A.layer&&(e.layer=A.layer),A.embeddedFonts!==void 0&&(e.embeddedFonts=new h1(A.embeddedFonts)),A.model){const i=new oj(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=e.models||[];e.models=[i,...n]}}function sii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new gmA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new OD,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),t.push(a)}return t}function rii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new gmA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new OD,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),t.push(a)}return t}function aii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new ij({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new OD,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),t.push(c)}return t}function gii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new ij({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new OD,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),t.push(g)}return t}function cii(e,A){const t=[];for(const i of e){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new ij({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new OD,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),t.push(c)}return t}function Iii(e,A){const t=[];for(const i of e){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new YQ(c,I)}),r=new mQt;r.points=new TC(s),r.layer=o,r.fill=!1;const a=new OD;a.width=.05,a.type="default",r.stroke=a,t.push(r)}return t}function lii({textElement:e,componentCenter:A,componentRotation:t=0}){if(!e.text||!e.anchor_position)return null;const i=e.anchor_position.x-A.x,n=-(e.anchor_position.y-A.y),o=t!==0?Lm(t*Math.PI/180):Lu(),s=Pe(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",c=(e.font_size||1)/1.5,I=new L0;I.size={width:c,height:c};const l=new v0({font:I}),B=e.ccw_rotation||0;return new $yA({type:"user",text:e.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function Bii(e,A,t,i){const n=[];for(const o of e){const s=lii({textElement:o,componentCenter:A,componentRotation:t});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function Cii(e,A,t){const i=[];for(const n of e){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=t!==0?Lm(t*Math.PI/180):Lu(),a=Pe(r,{x:o,y:s}),g=n.font_size||1,c=new L0;c.size={width:g,height:g};const I=new v0({font:c}),l=new $yA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function Qii(e,A){const t=[],i=e.model_step_url||e.model_wrl_url;if(!i)return t;const n=new oj(i);if(e.position&&(n.offset={x:(e.position.x||0)-A.x,y:-((e.position.y||0)-A.y),z:e.position.z||0}),e.rotation&&(n.rotate={x:e.rotation.x||0,y:e.rotation.y||0,z:e.rotation.z||0}),e.model_unit_to_mm_scale_factor){const o=e.model_unit_to_mm_scale_factor;n.scale={x:o,y:o,z:o}}return t.push(n),t}function Eii({pcbPad:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){let s,r;if("x"in e&&"y"in e)s=e.x,r=e.y;else if("points"in e&&Array.isArray(e.points)){const u=e.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=oB(i!==0?Lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},mE(1,-1),Er(-A.x,-A.y)),g=Pe(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[e.layer]||"F.Cu";let l,B,C,E;if(e.shape==="circle")l="circle",B=["radius"in e?e.radius*2:.5,"radius"in e?e.radius*2:.5];else if(e.shape==="polygon"&&"points"in e){const u=e.points,d=oB(mE(1,-1),Er(-s,-r)),f=u.map(w=>{const D=Pe(d,{x:w.x,y:w.y});return new YQ(D.x,D.y)}),m=new ZyA;m.contours=[new TC(f)],m.width=0,m.filled=!0,E=new sQt,E.addGraphic(m),l="custom",C=new KCt,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in e?e.width:.5,"height"in e?e.height:.5];const Q=`pad:${o}:${t}:${g.x},${g.y}`,h=new ej({number:String(t),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:wf(Q)});return C&&(h.options=C),E&&(h.primitives=E),n&&(h.net=new TyA(n.id,n.name)),h}function hii(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=Eii({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function uii({platedHole:e,componentCenter:A,padNumber:t,componentRotation:i=0,netInfo:n,componentId:o}){if(!("x"in e&&"y"in e))return null;const s=e.x-A.x,r=-(e.y-A.y),a=i!==0?Lm(i*Math.PI/180):Lu(),g=Pe(a,{x:s,y:r});let c="circle",I,l,B=0;const C="hole_offset_x"in e||"hole_offset_y"in e;let E;if(C){const u={x:e.hole_offset_x??0,y:e.hole_offset_y??0};(u.x!==0||u.y!==0)&&(E=Pe(a,{x:-u.x,y:u.y}))}e.shape==="circle"?(c="circle",I=[e.outer_diameter,e.outer_diameter],l=new ZD({diameter:e.hole_diameter,offset:E})):e.shape==="pill"||e.shape==="oval"?(c="oval",I=[e.outer_width,e.outer_height],l=new ZD({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:E})):e.shape==="pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new ZD({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:E})):e.shape==="circular_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new ZD({diameter:e.hole_diameter,offset:E})):e.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[e.rect_pad_width,e.rect_pad_height],l=new ZD({oval:!0,diameter:e.hole_width,width:e.hole_height,offset:E}),B=e.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new ZD({diameter:.8,offset:E}));const Q=`thruhole:${o}:${t}:${g.x},${g.y}`,h=new ej({number:String(t),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:wf(Q)});return n&&(h.net=new TyA(n.id,n.name)),h}function dii(e,A,t,i,n,o){const s=[];let r=n;for(const a of e){const g=o(a.pcb_port_id),c=uii({platedHole:a,componentCenter:A,padNumber:r,componentRotation:t,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function pii({pcbHole:e,componentCenter:A,componentRotation:t=0}){if(!("x"in e&&"y"in e))return null;const i=e.x-A.x,n=-(e.y-A.y),o=t!==0?Lm(t*Math.PI/180):Lu(),s=Pe(o,{x:i,y:n});let r="circle",a,g;if(e.hole_shape==="circle"){r="circle";const c=e.hole_diameter;a=[c,c],g=new ZD({diameter:c})}else if(e.hole_shape==="oval"){r="oval";const c=e.hole_width,I=e.hole_height;a=[c,I],g=new ZD({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in e?e.hole_diameter:1;a=[c,c],g=new ZD({diameter:c})}return new ej({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 fii(e,A,t){const i=[];for(const n of e){const o=pii({pcbHole:n,componentCenter:A,componentRotation:t});o&&i.push(o)}return i}var yii=class extends Uh{componentsProcessed=0;pcbComponents=[];getNetInfoForPcbPort(e){if(!e)return;const A=this.ctx.db.pcb_port?.get(e);if(!A)return;const t=A.source_port_id;if(!t)return;const i=this.ctx.db.source_port?.get(t);if(!i)return;const n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(e){return(this.ctx.db.cad_component?.list()||[]).find(t=>t.pcb_component_id===e)}constructor(e,A){super(e,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)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 t=this.pcbComponents[this.componentsProcessed],i=t.source_component_id?this.ctx.db.source_component.get(t.source_component_id):null,n=this.getCadComponentForPcbComponent(t.pcb_component_id),o=i?MG(i,n):"Unknown",s=Pe(A,{x:t.center.x,y:t.center.y}),r=`footprint:${t.pcb_component_id}:${s.x},${s.y}`,a=new DmA({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,t.rotation||0],uuid:wf(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Bii(c,t.center,t.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];g.push(...Cii(I,t.center,t.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=H=>this.getNetInfoForPcbPort(H),C=this.ctx.db.pcb_smtpad?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:E,nextPadNumber:Q}=hii(C,t.center,t.rotation||0,t.pcb_component_id,1,B);l.push(...E);const h=this.ctx.db.pcb_plated_hole?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],{pads:u}=dii(h,t.center,t.rotation||0,t.pcb_component_id,Q,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(H=>H.subcircuit_id===t.subcircuit_id)||[],f=fii(d,t.center,t.rotation||0);l.push(...f),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],w=a.fpCircles??[];w.push(...sii(m,t.center));const D=this.ctx.db.pcb_courtyard_circle?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];w.push(...rii(D,t.center)),a.fpCircles=w;const b=this.ctx.db.pcb_fabrication_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],k=a.fpRects??[];k.push(...aii(b,t.center));const x=this.ctx.db.pcb_note_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(...gii(x,t.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[];k.push(...cii(N,t.center)),a.fpRects=k;const R=this.ctx.db.pcb_courtyard_outline?.list().filter(H=>H.pcb_component_id===t.pcb_component_id)||[],U=Iii(R,t.center);if(U.length>0&&(a.fpPolys=U),n){const H=Qii(n,t.center);H.length>0&&(a.models=H)}if(this.ctx.footprintMetadataMap&&i?.name){const H=Cj(i.name),O=this.ctx.footprintMetadataMap.get(H);O&&oii(a,O,i.name)}const J=e.footprints;J.push(a),e.footprints=J,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},mii={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function wii(e){return e&&(mii[e]||e)||"F.Cu"}function Dii(e){const A=["F.Cu"];for(let t=1;t<e-1;t++)A.push(`In${t}.Cu`);return A.push("B.Cu"),A}var Sii=class extends Uh{tracesProcessed=0;pcbTraces=[];constructor(e,A){super(e,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)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}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Pe(A,{x:s.x,y:s.y}),g=Pe(A,{x:r.x,y:r.y});let c;if(t){let Q=i.subcircuit_connectivity_map_key;if(!Q&&i.source_trace_id){const h=this.ctx.db.source_trace?.get(i.source_trace_id);if(h&&(Q=h.subcircuit_connectivity_map_key,!Q&&h.connected_source_net_ids?.length))for(const u of h.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){Q=d.subcircuit_connectivity_map_key;break}}}if(!Q&&typeof i.connection_name=="string"){const h=this.ctx.db.source_net?.get(i.connection_name);h?.subcircuit_connectivity_map_key&&(Q=h.subcircuit_connectivity_map_key)}Q&&(c=t.get(Q))}const I=s.layer??r.layer??n,l=wii(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new UmA({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new cj(c?.id??0),uuid:wf(B)}),E=e.segments;E.push(C),e.segments=E,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},bii=class extends Uh{viasProcessed=0;pcbVias=[];constructor(e,A){super(e,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:e,c2kMatPcb:A,pcbNetMap:t}=this.ctx;if(!e)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],n=Pe(A,{x:i.x,y:i.y});let o;if(t){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const E=this.ctx.db.source_net?.get(C);if(E?.subcircuit_connectivity_map_key){I=E.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=t.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):Dii(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new RwA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new MwA(o?.id??0),uuid:wf(a)}),c=e.vias;c.push(g),e.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function xii({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[e.layer]||e.layer||"F.Fab",o=(e.font_size||1)/1.5,s=new L0;s.size={width:o,height:o};const r=new kJ,a=e.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 v0({font:s});a!=="center"&&(g.justify=r);const c=new Wg([t.x,t.y,0]),I=new gj({text:e.text,layer:n,effects:g});return I.position=c,I}function _ii({textElement:e,c2kMatPcb:A}){if(!e.text||!e.anchor_position)return null;const t=Pe(A,{x:e.anchor_position.x,y:e.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[e.layer]||e.layer||"F.SilkS",o=(e.font_size||1)/1.5,s=new L0;s.size={width:o,height:o};const r=new kJ,a=e.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 v0({font:s});a!=="center"&&(g.justify=r);const c=e.ccw_rotation||0,I=new Wg([t.x,t.y,c]),l=new gj({text:e.text,layer:n,effects:g});return l.position=I,l}var kii=class extends Uh{_step(){const{kicadPcb:e,c2kMatPcb:A}=this.ctx;if(!e)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const t=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const s of t)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Pe(A,{x:a.x,y:a.y}),I=Pe(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new aj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),E=e.graphicLines;E.push(C),e.graphicLines=E}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=_ii({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=xii({textElement:s,c2kMatPcb:A});if(r){const a=e.graphicTexts;a.push(r),e.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Pe(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new aj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=e.graphicLines;B.push(l),e.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},eht=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(e,A){this.ctx={db:_a(e),circuitJson:e,kicadPcb:new NwA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:oB(Er(100,100),mE(1,-1)),footprintMetadataMap:A?.footprintMetadataMap},this.pipeline=[new eii(e,this.ctx),new iii(e,this.ctx),new yii(e,this.ctx),new Sii(e,this.ctx),new bii(e,this.ctx),new kii(e,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()}},Fii=class{ctx;project;constructor(e,A={}){const t=A.projectName??e?.project?.name??"circuit-json-project",i=A.schematicFilename??`${t}.kicad_sch`,n=A.pcbFilename??`${t}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:_a(e),circuitJson:e},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:t,created:o,modified:o},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:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5827
5827
|
`}},Gii=class extends Uh{_step(){const e=new tht(this.ctx.circuitJson);e.runUntilFinished(),this.ctx.kicadSchString=e.getOutputString();const A=new eht(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},Mii=class extends Uh{isCustomSymbol(e){return e?.startsWith("Custom:")??!1}_step(){const e=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const t=new Map;try{const n=jEt(e).find(r=>r instanceof DyA);if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const o=n.libSymbols;if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const s=o.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);t.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),a||this.snapPinPositionsToGrid(r),t.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(t.values()),this.finished=!0}updateFootprintProperty(e,A){const t=e.properties??[];for(const i of t)if(i.key==="Footprint"&&i.value){const n=i.value.split(":");n.length>1?i.value=`${A}:${n[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(e){if(!e)return"symbol";const A=e.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}snapPinPositionsToGrid(e){for(const t of e.subSymbols??[]){for(const i of t.pins??[])i.at&&(i.at.x=Math.round(i.at.x/1.27)*1.27,i.at.y=Math.round(i.at.y/1.27)*1.27);for(const i of t.polylines??[])if(i.points?.points)for(const n of i.points.points)"x"in n&&"y"in n&&(n.x=Math.round(n.x/1.27)*1.27,n.y=Math.round(n.y/1.27)*1.27)}}getOutput(){return this.ctx.libraryOutput}},Rii=20240108,Nii="pcbnew",vii="8.0";function Lii(e){const A=e.split(/[/\\]/);return A[A.length-1]||e}var Uii=class extends Uh{findCustomFootprintNames(){const e=new Set,A=this.ctx.db.cad_component?.list()??[],t=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const n=i.source_component_id?t?.get(i.source_component_id):null;if(n){const o=MG(n,i);e.add(o)}}return e}_step(){const e=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!e)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const t=this.findCustomFootprintNames(),i=new Map;try{const o=jEt(e).find(r=>r instanceof NwA);if(!o){this.ctx.footprintEntries=[],this.finished=!0;return}const s=o.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:t});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(n){console.warn("Failed to parse PCB for footprint extraction:",n)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:e,fpLibraryName:A,customFootprintNames:t}){const n=(e.libraryLink??"footprint").split(":"),o=(n.length>1?n[1]:n[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!t.has(o);if(e.libraryLink=o,e.position=Wg.from([0,0,0]),e.locked=!1,e.placed=!1,e.version=Rii,e.generator=Nii,e.generatorVersion=vii,e.descr||(e.descr=""),e.tags||(e.tags=""),e.embeddedFonts||(e.embeddedFonts=new h1(!1)),!e.attr){const d=new SyA,f=(e.fpPads??[]).map(m=>m.padType);f.some(m=>m.includes("thru_hole"))?d.type="through_hole":f.some(m=>m.includes("smd"))&&(d.type="smd"),e.attr=d}e.uuid=void 0,e.path=void 0,e.sheetfile=void 0,e.sheetname=void 0;const r=new L0;r.size={width:1.27,height:1.27},r.thickness=.15;const a=new v0({font:r}),g=e.fpPads??[];let c=0,I=0;for(const d of g){const f=d.at,m=d.size;if(f&&m){const w=f.y??0,D=m.height??0,b=w-D/2,k=w+D/2;c=Math.min(c,b),I=Math.max(I,k)}}const l=c-.5,B=I+.5;e.properties=[new WD({key:"Reference",value:"REF**",position:[0,l,0],layer:"F.SilkS",uuid:wf(`${o}-property-Reference`),effects:a}),new WD({key:"Value",value:"Val**",position:[0,B,0],layer:"F.Fab",uuid:wf(`${o}-property-Value`),effects:a}),new WD({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:wf(`${o}-property-Datasheet`),effects:a}),new WD({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:wf(`${o}-property-Description`),effects:a})];const C=e.fpTexts??[];for(const d of C)d.uuid=void 0,d.type==="reference"?d.text="REF**":d.type==="value"&&d.text.trim().length===0&&(d.text=o);e.fpTexts=C;const E=e.fpPads??[];for(let d=0;d<E.length;d++){const f=E[d];f&&(f.uuid=wf(`${o}-pad-${f.number??d}`),f.net=void 0)}e.fpPads=E;const Q=e.models??[],h=[],u=[];for(const d of Q)if(d.path){const f=Lii(d.path),m=`../../3dmodels/${A}.3dshapes/${f}`,w=new oj(m);d.offset&&(w.offset=d.offset),d.scale&&(w.scale=d.scale),d.rotate&&(w.rotate=d.rotate),h.push(w),u.push(d.path)}return e.models=h,{footprintName:o,kicadModString:e.getString(),model3dSourcePaths:u,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},Hii=20211014,Yii="circuit-json-to-kicad",Jii=class extends Uh{_step(){const e=this.ctx.symbolEntries??[],A=this.generateSymbolLibrary(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.kicadSymString=A,this.finished=!0}generateSymbolLibrary(e){return new ECt({version:Hii,generator:Yii,symbols:e.map(t=>t.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},Tii=class extends Uh{_step(){const e=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",t=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],n=new Set;for(const r of t)for(const a of r.model3dSourcePaths)n.add(a);const o=this.generateFpLibTable(A),s=this.generateSymLibTable(e);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=t,this.ctx.libraryOutput.fpLibTableString=o,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(n),this.finished=!0}generateFpLibTable(e){return`(fp_lib_table
|
|
5828
5828
|
(version 7)
|
|
5829
5829
|
(lib (name "${e}") (type "KiCad") (uri "\${KIPRJMOD}/${e}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
|
package/dist/standalone.min.js
CHANGED
|
@@ -5686,7 +5686,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5686
5686
|
// Add more specific assertions based on expected output
|
|
5687
5687
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5688
5688
|
})
|
|
5689
|
-
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.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&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},uIe=t=>t.activeSubSolver?[t,...uIe(t.activeSubSolver)]:[t],N9t=({solver:t})=>{const A=uIe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(M9t,{solver:e})]},e.constructor.name))})},v9t=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(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(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(N9t,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,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"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},L9t=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},U9t=(t,A)=>{const i=t.pipelineDef[A].solverName,n=L9t(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},H9t=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Y9t=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},J9t=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),T9t=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=J9t(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},jfA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(jfA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=jfA(i));return A},K9t=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=jfA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},P9t=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>U9t(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):K9t(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(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:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(H9t,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Y9t,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(T9t,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},q9t=class extends nn.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 O9t({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,p=h.height??0;c(E,u),c(E+d,u+p)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var W9t=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(v9t,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(q9t,{fallback:W.jsx(O9t,{graphics:s}),children:W.jsx(R9t,{graphics:s})}),a&&W.jsx(P9t,{solver:t,onStepUntilPhase:g})]})};const Z9t=()=>{V.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)},[])},V9t=t=>t.toLowerCase().includes("pack")?OMt:t.toLowerCase().includes("rout")?zMt:FMt,j9t=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Z9t();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=znA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(znA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.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 c=V9t(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Zy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(W9t,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},dIe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{U5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{U5.captureException(n,{error_type:i.type})}catch{}}},[e])},pIe="0.0.1626",z9t={version:pIe},O9=kYA()(FYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),X9t=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=g1("eval-version-selection",null),g=O9(B=>B.setLastRunEvalVersion),c=O9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},$9t=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.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:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.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:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.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:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},Ajt=t=>{const A=V.useRef(null),e=ZI(i=>i.recentEvents);V.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 ejt(t){const A=tjt(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(njt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function tjt(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=sjt(n),r=ojt(o,n.props);return n.type!==V.Fragment&&(r.ref=i?gf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var ijt=Symbol("radix.slottable");function njt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ijt}function ojt(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function sjt(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 W9="Dialog",[fIe,yIe]=Om(W9),[rjt,dw]=fIe(W9),mIe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=Wx({prop:i,defaultProp:n??!1,onChange:o,caller:W9});return W.jsx(rjt,{scope:A,triggerRef:r,contentRef:a,contentId:xE(),titleId:xE(),descriptionId:xE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};mIe.displayName=W9;var wIe="DialogTrigger",DIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(wIe,e),o=pI(A,n.triggerRef);return W.jsx(Wa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":$fA(n.open),...i,ref:o,onClick:Hn(t.onClick,n.onOpenToggle)})});DIe.displayName=wIe;var zfA="DialogPortal",[ajt,SIe]=fIe(zfA,{forceMount:void 0}),bIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=dw(zfA,A);return W.jsx(ajt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(m0,{present:e||o.open,children:W.jsx(TZ,{asChild:!0,container:n,children:s})}))})};bIe.displayName=zfA;var Z9="DialogOverlay",xIe=V.forwardRef((t,A)=>{const e=SIe(Z9,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=dw(Z9,t.__scopeDialog);return o.modal?W.jsx(m0,{present:i||o.open,children:W.jsx(cjt,{...n,ref:A})}):null});xIe.displayName=Z9;var gjt=ejt("DialogOverlay.RemoveScroll"),cjt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(Z9,e);return W.jsx(jZ,{as:gjt,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Wa.div,{"data-state":$fA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),YG="DialogContent",_Ie=V.forwardRef((t,A)=>{const e=SIe(YG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=dw(YG,t.__scopeDialog);return W.jsx(m0,{present:i||o.open,children:o.modal?W.jsx(Ijt,{...n,ref:A}):W.jsx(ljt,{...n,ref:A})})});_Ie.displayName=YG;var Ijt=V.forwardRef((t,A)=>{const e=dw(YG,t.__scopeDialog),i=V.useRef(null),n=pI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return VuA(o)},[]),W.jsx(kIe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Hn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(t.onFocusOutside,o=>o.preventDefault())})}),ljt=V.forwardRef((t,A)=>{const e=dw(YG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(kIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),kIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=dw(YG,e),a=V.useRef(null),g=pI(A,a);return kuA(),W.jsxs(W.Fragment,{children:[W.jsx(_Z,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(oY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":$fA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(Cjt,{titleId:r.titleId}),W.jsx(hjt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),XfA="DialogTitle",FIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(XfA,e);return W.jsx(Wa.h2,{id:n.titleId,...i,ref:A})});FIe.displayName=XfA;var GIe="DialogDescription",RIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(GIe,e);return W.jsx(Wa.p,{id:n.descriptionId,...i,ref:A})});RIe.displayName=GIe;var MIe="DialogClose",NIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(MIe,e);return W.jsx(Wa.button,{type:"button",...i,ref:A,onClick:Hn(t.onClick,()=>n.onOpenChange(!1))})});NIe.displayName=MIe;function $fA(t){return t?"open":"closed"}var vIe="DialogTitleWarning",[Bjt,LIe]=g6e(vIe,{contentName:YG,titleName:XfA,docsSlug:"dialog"}),Cjt=({titleId:t})=>{const A=LIe(vIe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5689
|
+
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.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&&W.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},uIe=t=>t.activeSubSolver?[t,...uIe(t.activeSubSolver)]:[t],N9t=({solver:t})=>{const A=uIe(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(M9t,{solver:e})]},e.constructor.name))})},v9t=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(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(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(N9t,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,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"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},L9t=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},U9t=(t,A)=>{const i=t.pipelineDef[A].solverName,n=L9t(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},H9t=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},Y9t=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},J9t=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),T9t=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=J9t(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},jfA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(jfA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=jfA(i));return A},K9t=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=jfA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},P9t=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>U9t(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):K9t(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(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:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(H9t,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(Y9t,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(T9t,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},q9t=class extends nn.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 O9t({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,p=h.height??0;c(E,u),c(E+d,u+p)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var W9t=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(v9t,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(q9t,{fallback:W.jsx(O9t,{graphics:s}),children:W.jsx(R9t,{graphics:s})}),a&&W.jsx(P9t,{solver:t,onStepUntilPhase:g})]})};const Z9t=()=>{V.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)},[])},V9t=t=>t.toLowerCase().includes("pack")?OMt:t.toLowerCase().includes("rout")?zMt:FMt,j9t=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);Z9t();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=znA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(znA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.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 c=V9t(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Zy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(W9t,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},dIe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{U5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{U5.captureException(n,{error_type:i.type})}catch{}}},[e])},pIe="0.0.1627",z9t={version:pIe},O9=kYA()(FYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),X9t=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=g1("eval-version-selection",null),g=O9(B=>B.setLastRunEvalVersion),c=O9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},$9t=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.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:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.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:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.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:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},Ajt=t=>{const A=V.useRef(null),e=ZI(i=>i.recentEvents);V.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 ejt(t){const A=tjt(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(njt);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function tjt(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=sjt(n),r=ojt(o,n.props);return n.type!==V.Fragment&&(r.ref=i?gf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var ijt=Symbol("radix.slottable");function njt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===ijt}function ojt(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function sjt(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 W9="Dialog",[fIe,yIe]=Om(W9),[rjt,dw]=fIe(W9),mIe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=Wx({prop:i,defaultProp:n??!1,onChange:o,caller:W9});return W.jsx(rjt,{scope:A,triggerRef:r,contentRef:a,contentId:xE(),titleId:xE(),descriptionId:xE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};mIe.displayName=W9;var wIe="DialogTrigger",DIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(wIe,e),o=pI(A,n.triggerRef);return W.jsx(Wa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":$fA(n.open),...i,ref:o,onClick:Hn(t.onClick,n.onOpenToggle)})});DIe.displayName=wIe;var zfA="DialogPortal",[ajt,SIe]=fIe(zfA,{forceMount:void 0}),bIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=dw(zfA,A);return W.jsx(ajt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(m0,{present:e||o.open,children:W.jsx(TZ,{asChild:!0,container:n,children:s})}))})};bIe.displayName=zfA;var Z9="DialogOverlay",xIe=V.forwardRef((t,A)=>{const e=SIe(Z9,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=dw(Z9,t.__scopeDialog);return o.modal?W.jsx(m0,{present:i||o.open,children:W.jsx(cjt,{...n,ref:A})}):null});xIe.displayName=Z9;var gjt=ejt("DialogOverlay.RemoveScroll"),cjt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(Z9,e);return W.jsx(jZ,{as:gjt,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(Wa.div,{"data-state":$fA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),YG="DialogContent",_Ie=V.forwardRef((t,A)=>{const e=SIe(YG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=dw(YG,t.__scopeDialog);return W.jsx(m0,{present:i||o.open,children:o.modal?W.jsx(Ijt,{...n,ref:A}):W.jsx(ljt,{...n,ref:A})})});_Ie.displayName=YG;var Ijt=V.forwardRef((t,A)=>{const e=dw(YG,t.__scopeDialog),i=V.useRef(null),n=pI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return VuA(o)},[]),W.jsx(kIe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Hn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(t.onFocusOutside,o=>o.preventDefault())})}),ljt=V.forwardRef((t,A)=>{const e=dw(YG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(kIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),kIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=dw(YG,e),a=V.useRef(null),g=pI(A,a);return kuA(),W.jsxs(W.Fragment,{children:[W.jsx(_Z,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(oY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":$fA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(Cjt,{titleId:r.titleId}),W.jsx(hjt,{contentRef:a,descriptionId:r.descriptionId})]})]})}),XfA="DialogTitle",FIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(XfA,e);return W.jsx(Wa.h2,{id:n.titleId,...i,ref:A})});FIe.displayName=XfA;var GIe="DialogDescription",RIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(GIe,e);return W.jsx(Wa.p,{id:n.descriptionId,...i,ref:A})});RIe.displayName=GIe;var MIe="DialogClose",NIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=dw(MIe,e);return W.jsx(Wa.button,{type:"button",...i,ref:A,onClick:Hn(t.onClick,()=>n.onOpenChange(!1))})});NIe.displayName=MIe;function $fA(t){return t?"open":"closed"}var vIe="DialogTitleWarning",[Bjt,LIe]=g6e(vIe,{contentName:YG,titleName:XfA,docsSlug:"dialog"}),Cjt=({titleId:t})=>{const A=LIe(vIe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5690
5690
|
|
|
5691
5691
|
If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5692
5692
|
|
|
@@ -5823,7 +5823,7 @@ ${a.join(`
|
|
|
5823
5823
|
`)}};vA.register(Soi);var eEe=class kbA extends vA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new kbA(!0);const e=pi(A[0]);return new kbA(e==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};vA.register(eEe);var tEe=class ywe extends vA{static token="members";static parentToken="group";token="members";members;constructor(A){super(),this.members=A}static fromSexprPrimitives(A){const e=[];for(const i of A){const n=pi(i);n&&e.push(n)}return new ywe(e)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(e=>`"${e}"`).join(" ")})`}};vA.register(tEe);var vwA=class mwe extends vA{static token="end";static parentToken="segment";token="end";_x;_y;constructor(A,e){super(),this._x=A,this._y=e}static fromSexprPrimitives(A){const[e,i]=A,n=ai(e),o=ai(i);if(n===void 0||o===void 0)throw new Error("end expects two numeric arguments");return new mwe(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(end ${this._x} ${this._y})`}};vA.register(vwA);var boi=new Set(["true","yes","1"]),iEe=class JX extends Nl{static token="locked";static parentToken="segment";token="locked";constructor(A){super(A)}static fromSexprPrimitives(A){const[e]=A;return typeof e=="boolean"?new JX(e):typeof e=="string"?new JX(boi.has(e.toLowerCase())):new JX(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};vA.register(iEe);var $j=class wwe extends vA{static token="net";static parentToken="segment";token="net";_id;_name;constructor(A,e){super(),this._id=A,this._name=e}static fromSexprPrimitives(A){const[e,i]=A,n=ai(e);if(n===void 0)throw new Error("net expects a numeric identifier");const o=i===void 0?void 0:pi(i);return new wwe(n,o??void 0)}get id(){return this._id}set id(A){this._id=A}get name(){return this._name}set name(A){this._name=A===""?void 0:A}toObject(){return this._name===void 0?{id:this._id}:{id:this._id,name:this._name}}getChildren(){return[]}getString(){const A=this._name?` ${Qn(this._name)}`:"";return`(net ${this._id}${A})`}};vA.register($j);var LwA=class Dwe extends vA{static token="start";static parentToken="segment";token="start";_x;_y;constructor(A,e){super(),this._x=A,this._y=e}static fromSexprPrimitives(A){const[e,i]=A,n=ai(e),o=ai(i);if(n===void 0||o===void 0)throw new Error("start expects two numeric arguments");return new Dwe(n,o)}get x(){return this._x}set x(A){this._x=A}get y(){return this._y}set y(A){this._y=A}toObject(){return{x:this._x,y:this._y}}getChildren(){return[]}getString(){return`(start ${this._x} ${this._y})`}};vA.register(LwA);var nEe=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),UwA=class Swe extends vA{static token="segment";token="segment";_sxStart;_sxEnd;_sxWidth;_sxLayer;_sxNet;_sxTstamp;_sxUuid;_sxLocked;constructor(A={}){super(),A.start!==void 0&&(this.start=A.start),A.end!==void 0&&(this.end=A.end),A.width!==void 0&&(this.width=A.width),A.layer!==void 0&&(this.layer=A.layer),A.net!==void 0&&(this.net=A.net),A.tstamp!==void 0&&(this.tstamp=A.tstamp),A.uuid!==void 0&&(this.uuid=A.uuid),A.locked!==void 0&&(this.locked=A.locked)}static fromSexprPrimitives(A){const e=new Swe,{propertyMap:i,arrayPropertyMap:n}=vA.parsePrimitivesToClassProperties(A,this.token),o=Object.keys(i).filter(r=>!nEe.has(r));if(o.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${o.join(", ")}`);for(const[r,a]of Object.entries(n)){if(!nEe.has(r))throw new Error(`Unsupported child tokens inside segment expression: ${r}`);if(a.length>1)throw new Error(`Segment does not support repeated child tokens: ${r}`)}e._sxStart=n.start?.[0]??i.start,e._sxEnd=n.end?.[0]??i.end,e._sxWidth=n.width?.[0]??i.width,e._sxLayer=n.layer?.[0]??i.layer,e._sxNet=n.net?.[0]??i.net;const s=n.locked?.[0]??i.locked;return e._sxLocked=s&&s.value?s:void 0,e._sxTstamp=n.tstamp?.[0]??i.tstamp,e._sxUuid=n.uuid?.[0]??i.uuid,e}get start(){return this._sxStart}set start(A){this._sxStart=this.normalizeStart(A)}get end(){return this._sxEnd}set end(A){this._sxEnd=this.normalizeEnd(A)}get startPoint(){return this._sxStart?.toObject()}get endPoint(){return this._sxEnd?.toObject()}get width(){return this._sxWidth?.value}set width(A){if(A===void 0){this._sxWidth=void 0;return}this._sxWidth=A instanceof Gr?A:new Gr(A)}get widthClass(){return this._sxWidth}set widthClass(A){this._sxWidth=A}get layer(){return this._sxLayer}set layer(A){if(A===void 0){this._sxLayer=void 0;return}if(A instanceof yr){this._sxLayer=A;return}const e=Array.isArray(A)?A:[A];this._sxLayer=new yr(e)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof $j){this._sxNet=A;return}this._sxNet=new $j(A.id,A.name)}get tstamp(){return this._sxTstamp}set tstamp(A){if(A===void 0){this._sxTstamp=void 0;return}this._sxTstamp=A instanceof Xg?A:new Xg(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof Ui?A:new Ui(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new iEe(!0):void 0}getChildren(){const A=[];return this._sxStart&&A.push(this._sxStart),this._sxEnd&&A.push(this._sxEnd),this._sxWidth&&A.push(this._sxWidth),this._sxLayer&&A.push(this._sxLayer),this._sxNet&&A.push(this._sxNet),this._sxLocked&&A.push(this._sxLocked),this._sxTstamp&&A.push(this._sxTstamp),this._sxUuid&&A.push(this._sxUuid),A}normalizeStart(A){if(A!==void 0)return A instanceof LwA?A:new LwA(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof vwA?A:new vwA(A.x,A.y)}};vA.register(UwA);var oEe=class bwe extends vA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const e=new bwe;return e._rawChildren=[...A],e}get rawChildren(){return[...this._rawChildren]}set rawChildren(A){this._rawChildren=[...A]}getChildren(){return[]}getString(){const A=["(zone"];for(const e of this._rawChildren)A.push(` ${Nh(e)}`);return A.push(")"),A.join(`
|
|
5824
5824
|
`)}};vA.register(oEe);var Az=class xwe extends vA{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):Nh(i));return new xwe(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:Qn(e)).join(" ")})`}};vA.register(Az);var eT=class extends vA{_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=pi(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?Qn(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},xoi=class extends vA{_values;constructor(t){super(),this._values=t}static fromSexprPrimitives(t){const A=t.map(i=>{const n=ai(i);if(n===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return n}),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(" ")})`}},_oi=class extends vA{_x;_y;constructor(t,A){super(),this._x=t,this._y=A}static fromSexprPrimitives(t){const[A,e]=t,i=ai(A),n=ai(e);if(i===void 0||n===void 0)throw new Error(`${this.name} expects two numeric values`);const o=this;return new o(i,n)}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})`}},mr=class extends eT{static parentToken="pcbplotparams"},cm=class extends mr{static parsePrimitiveValue(t){const A=ai(t);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},sEe=class extends mr{static token="layerselection";token="layerselection"};vA.register(sEe);var rEe=class extends mr{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};vA.register(rEe);var aEe=class extends cm{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};vA.register(aEe);var gEe=class extends cm{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};vA.register(gEe);var cEe=class extends cm{static token="svgprecision";token="svgprecision"};vA.register(cEe);var IEe=class extends cm{static token="linewidth";token="linewidth"};vA.register(IEe);var lEe=class extends cm{static token="mode";token="mode"};vA.register(lEe);var BEe=class extends cm{static token="hpglpennumber";token="hpglpennumber"};vA.register(BEe);var CEe=class extends cm{static token="hpglpenspeed";token="hpglpenspeed"};vA.register(CEe);var QEe=class extends cm{static token="hpglpendiameter";token="hpglpendiameter"};vA.register(QEe);var hEe=class extends cm{static token="hpglpenoverlay";token="hpglpenoverlay"};vA.register(hEe);var EEe=class extends cm{static token="outputformat";token="outputformat"};vA.register(EEe);var uEe=class extends cm{static token="drillshape";token="drillshape"};vA.register(uEe);var dEe=class extends cm{static token="scaleselection";token="scaleselection"};vA.register(dEe);var pEe=class extends mr{static token="disableapertmacros";token="disableapertmacros"};vA.register(pEe);var fEe=class extends mr{static token="usegerberextensions";token="usegerberextensions"};vA.register(fEe);var yEe=class extends mr{static token="usegerberattributes";token="usegerberattributes"};vA.register(yEe);var mEe=class extends mr{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};vA.register(mEe);var wEe=class extends mr{static token="creategerberjobfile";token="creategerberjobfile"};vA.register(wEe);var DEe=class extends mr{static token="excludeedgelayer";token="excludeedgelayer"};vA.register(DEe);var SEe=class extends mr{static token="plotframeref";token="plotframeref"};vA.register(SEe);var bEe=class extends mr{static token="viasonmask";token="viasonmask"};vA.register(bEe);var xEe=class extends mr{static token="useauxorigin";token="useauxorigin"};vA.register(xEe);var _Ee=class extends mr{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};vA.register(_Ee);var kEe=class extends mr{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};vA.register(kEe);var FEe=class extends mr{static token="pdf_metadata";token="pdf_metadata"};vA.register(FEe);var GEe=class extends mr{static token="pdf_single_document";token="pdf_single_document"};vA.register(GEe);var REe=class extends mr{static token="dxfpolygonmode";token="dxfpolygonmode"};vA.register(REe);var MEe=class extends mr{static token="dxfimperialunits";token="dxfimperialunits"};vA.register(MEe);var NEe=class extends mr{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};vA.register(NEe);var vEe=class extends mr{static token="psnegative";token="psnegative"};vA.register(vEe);var LEe=class extends mr{static token="psa4output";token="psa4output"};vA.register(LEe);var UEe=class extends mr{static token="plotreference";token="plotreference"};vA.register(UEe);var HEe=class extends mr{static token="plotvalue";token="plotvalue"};vA.register(HEe);var YEe=class extends mr{static token="plotothertext";token="plotothertext"};vA.register(YEe);var JEe=class extends mr{static token="plotinvisibletext";token="plotinvisibletext"};vA.register(JEe);var TEe=class extends mr{static token="padsonsilk";token="padsonsilk"};vA.register(TEe);var KEe=class extends mr{static token="sketchpadsonfab";token="sketchpadsonfab"};vA.register(KEe);var PEe=class extends mr{static token="plotpadnumbers";token="plotpadnumbers"};vA.register(PEe);var qEe=class extends mr{static token="hidednponfab";token="hidednponfab"};vA.register(qEe);var OEe=class extends mr{static token="sketchdnponfab";token="sketchdnponfab"};vA.register(OEe);var WEe=class extends mr{static token="crossoutdnponfab";token="crossoutdnponfab"};vA.register(WEe);var ZEe=class extends mr{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};vA.register(ZEe);var VEe=class extends mr{static token="plot_black_and_white";token="plot_black_and_white"};vA.register(VEe);var jEe=class extends mr{static token="mirror";token="mirror"};vA.register(jEe);var zEe=class extends mr{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};vA.register(zEe);var XEe=class extends mr{static token="plot_on_all_layers";token="plot_on_all_layers"};vA.register(XEe);var $Ee=class extends mr{static token="plotinvisible";token="plotinvisible"};vA.register($Ee);var koi={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"},Foi=["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"],HwA=class _we extends vA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const e=new _we,{propertyMap:i}=vA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=koi[n];if(!s)throw new Error(`Unsupported pcbplotparams token: ${n}`);e._properties[s]=o}return e}getChildren(){const A=[];for(const e of Foi){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,sEe)}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,rEe)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,pEe)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,fEe)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,yEe)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,mEe)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,wEe)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,DEe)}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,aEe)}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,gEe)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,cEe)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,IEe)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,SEe)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,UEe)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,HEe)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,YEe)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,JEe)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,TEe)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,PEe)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,KEe)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,qEe)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,OEe)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,WEe)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,ZEe)}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,VEe)}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,XEe)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,$Ee)}get mode(){return this._properties.mode?.value}set mode(A){this.setNumberProperty("mode",A,lEe)}get useauxorigin(){return this._properties.useauxorigin?.value}set useauxorigin(A){this.setStringProperty("useauxorigin",A,xEe)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,bEe)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,BEe)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,CEe)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,QEe)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,hEe)}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,_Ee)}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,kEe)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,FEe)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,GEe)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,REe)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,MEe)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,NEe)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,vEe)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,LEe)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,jEe)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,EEe)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,uEe)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,dEe)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,zEe)}};vA.register(HwA);var ez=class extends eT{static parentToken="setup"},YwA=class extends ez{static token="zone_45_only";token="zone_45_only"};vA.register(YwA);var JwA=class extends ez{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};vA.register(JwA);var TwA=class extends ez{static token="visible_elements";token="visible_elements"};vA.register(TwA);var KwA=class extends ez{static token="uvias_allowed";token="uvias_allowed"};vA.register(KwA);var PwA=class kwe extends vA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const e=A.map(i=>pi(i)).filter(i=>i!==void 0);return new kwe(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(" ")})`}};vA.register(PwA);var tT=class extends xoi{static parentToken="setup"},Aue=class extends _oi{static parentToken="setup"},qwA=class extends tT{static token="pcb_text_size";token="pcb_text_size"};vA.register(qwA);var OwA=class extends tT{static token="mod_text_size";token="mod_text_size"};vA.register(OwA);var WwA=class extends tT{static token="pad_size";token="pad_size"};vA.register(WwA);var ZwA=class extends tT{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};vA.register(ZwA);var VwA=class extends tT{static token="trace_width";token="trace_width"};vA.register(VwA);var jwA=class extends Aue{static token="aux_axis_origin";token="aux_axis_origin"};vA.register(jwA);var zwA=class extends Aue{static token="grid_origin";token="grid_origin"};vA.register(zwA);var lB=class extends eT{static parentToken="setup";static parsePrimitiveValue(t){const A=ai(t);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},XwA=class extends lB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};vA.register(XwA);var $wA=class extends lB{static token="solder_mask_min_width";token="solder_mask_min_width"};vA.register($wA);var ADA=class extends lB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};vA.register(ADA);var eDA=class extends lB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};vA.register(eDA);var tDA=class extends lB{static token="last_trace_width";token="last_trace_width"};vA.register(tDA);var iDA=class extends lB{static token="trace_clearance";token="trace_clearance"};vA.register(iDA);var nDA=class extends lB{static token="zone_clearance";token="zone_clearance"};vA.register(nDA);var oDA=class extends lB{static token="trace_min";token="trace_min"};vA.register(oDA);var sDA=class extends lB{static token="segment_width";token="segment_width"};vA.register(sDA);var rDA=class extends lB{static token="edge_width";token="edge_width"};vA.register(rDA);var aDA=class extends lB{static token="via_size";token="via_size"};vA.register(aDA);var gDA=class extends lB{static token="via_drill";token="via_drill"};vA.register(gDA);var cDA=class extends lB{static token="via_min_size";token="via_min_size"};vA.register(cDA);var IDA=class extends lB{static token="via_min_drill";token="via_min_drill"};vA.register(IDA);var lDA=class extends lB{static token="uvia_size";token="uvia_size"};vA.register(lDA);var BDA=class extends lB{static token="uvia_drill";token="uvia_drill"};vA.register(BDA);var CDA=class extends lB{static token="uvia_min_size";token="uvia_min_size"};vA.register(CDA);var QDA=class extends lB{static token="uvia_min_drill";token="uvia_min_drill"};vA.register(QDA);var hDA=class extends lB{static token="pcb_text_width";token="pcb_text_width"};vA.register(hDA);var EDA=class extends lB{static token="mod_edge_width";token="mod_edge_width"};vA.register(EDA);var uDA=class extends lB{static token="mod_text_width";token="mod_text_width"};vA.register(uDA);var dDA=class extends lB{static token="pad_drill";token="pad_drill"};vA.register(dDA);var iT=class extends eT{static parentToken="stackup"},eue=class extends iT{static token="copper_finish";token="copper_finish";quoteStringValue=!0};vA.register(eue);var tue=class extends iT{static token="dielectric_constraints";token="dielectric_constraints"};vA.register(tue);var iue=class extends iT{static token="edge_connector";token="edge_connector"};vA.register(iue);var nue=class extends iT{static token="castellated_pads";token="castellated_pads"};vA.register(nue);var oue=class extends iT{static token="edge_plating";token="edge_plating"};vA.register(oue);var U1=class extends eT{static parentToken="layer"},pDA=class extends U1{static token="type";token="type";quoteStringValue=!0};vA.register(pDA);var fDA=class extends U1{static token="color";token="color";quoteStringValue=!0};vA.register(fDA);var yDA=class extends U1{static token="thickness";token="thickness";static parsePrimitiveValue(t){const A=ai(t);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};vA.register(yDA);var mDA=class extends U1{static token="material";token="material";quoteStringValue=!0};vA.register(mDA);var wDA=class extends U1{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(t){const A=ai(t);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};vA.register(wDA);var DDA=class extends U1{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(t){const A=ai(t);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};vA.register(DDA);var sue=class Fwe extends vA{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=pi(A[0]);if(e===void 0)throw new Error("Stackup layer name must be a string");let i=1,n;const o=A[i],s=ai(o);s!==void 0&&(n=s,i+=1);const r=A.slice(i),{propertyMap:a}=vA.parsePrimitivesToClassProperties(r,this.token);return new Fwe(e,{number:n,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=pi(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=ai(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 pDA?A:new pDA(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof fDA?A:new fDA(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof yDA?A:new yDA(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof mDA?A:new mDA(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof wDA?A:new wDA(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof DDA?A:new DDA(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 ${Qn(this._name)}${this._number!==void 0?` ${this._number}`:""}`,e=this.getChildren();if(e.length===0)return`${A})`;const i=[A];for(const n of e)i.push(n.getStringIndented());return i.push(")"),i.join(`
|
|
5825
5825
|
`)}};vA.register(sue);var SDA=class Gwe extends vA{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}=vA.parsePrimitivesToClassProperties(A,this.token);return new Gwe({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 sue))throw new Error("Stackup layers must be StackupLayer instances");return e})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new eue(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new tue(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new iue(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new nue(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new oue(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}};vA.register(SDA);var Goi={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"},Roi=["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"],bDA=class Rwe extends vA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const e=new Rwe,{propertyMap:i}=vA.parsePrimitivesToClassProperties(A,this.token);for(const[n,o]of Object.entries(i)){const s=Goi[n];if(!s)throw new Error(`Unsupported setup property token: ${n}`);e._properties[s]=o}return e}getChildren(){const A=[];for(const e of Roi){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",SDA)}set stackup(A){if(A!==void 0&&!(A instanceof SDA))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",HwA)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof HwA))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",XwA)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,XwA)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",$wA)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,$wA)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",ADA)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,ADA)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",eDA)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,eDA)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",tDA)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,tDA)}get traceClearance(){return this.getPropertyInstance("traceClearance",iDA)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,iDA)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",nDA)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,nDA)}get zone45Only(){return this.getPropertyInstance("zone45Only",YwA)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new YwA(A))}get traceMin(){return this.getPropertyInstance("traceMin",oDA)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,oDA)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",sDA)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,sDA)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",rDA)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,rDA)}get viaSize(){return this.getPropertyInstance("viaSize",aDA)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,aDA)}get viaDrill(){return this.getPropertyInstance("viaDrill",gDA)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,gDA)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",cDA)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,cDA)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",IDA)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,IDA)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",KwA)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new KwA(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",lDA)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,lDA)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",BDA)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,BDA)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",CDA)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,CDA)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",QDA)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,QDA)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",hDA)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,hDA)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",qwA)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new qwA(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",EDA)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,EDA)}get modTextSize(){return this.getPropertyInstance("modTextSize",OwA)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new OwA(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",uDA)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,uDA)}get padSize(){return this.getPropertyInstance("padSize",WwA)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new WwA(A))}get padDrill(){return this.getPropertyInstance("padDrill",dDA)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,dDA)}get allowSoldermaskBridgesInFootprints(){return this.getPropertyInstance("allowSoldermaskBridgesInFootprints",JwA)?.value}set allowSoldermaskBridgesInFootprints(A){this.setProperty("allowSoldermaskBridgesInFootprints",A===void 0?void 0:new JwA(A))}get tenting(){return this.getPropertyInstance("tenting",PwA)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new PwA(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",jwA);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new jwA(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",zwA);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new zwA(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",TwA)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new TwA(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",ZwA)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new ZwA(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",VwA)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new VwA(A))}};vA.register(bDA);var rue=class extends ca{static token="thickness";static parentToken="general";token="thickness"};vA.register(rue);var aue=class Mwe extends vA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const e=pi(A[0]);if(e===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(e);return new Mwe(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};vA.register(aue);var gue=new Set(["thickness","legacy_teardrops"]),xDA=class Nwe extends vA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const e=new Nwe,{propertyMap:i,arrayPropertyMap:n}=vA.parsePrimitivesToClassProperties(A,this.token);for(const o of Object.keys(i))if(!gue.has(o))throw new Error(`general encountered unsupported child token "${o}"`);for(const[o,s]of Object.entries(n)){if(!gue.has(o))throw new Error(`general encountered unsupported child token "${o}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${o}"`)}return e._sxThickness=n.thickness?.[0]??i.thickness,e._sxLegacyTeardrops=n.legacy_teardrops?.[0]??i.legacy_teardrops,e}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new rue(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new aue(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};vA.register(xDA);var vl=class vwe extends vA{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,n,o]=A,s=ai(e),r=pi(i),a=pi(n),g=o===void 0?void 0:pi(o);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new vwe({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),Qn(this._name),this._type];return this._userName!==void 0&&A.push(Qn(this._userName)),`(${A.join(" ")})`}};vA.register(vl);var _DA=class Lwe extends vA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const e=new Lwe;return e._definitions=A.map(i=>vl.fromPrimitive(i)),e}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};vA.register(_DA);var tz=class Uwe extends vA{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=ai(A[0]),i=pi(A[1]);if(e===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new Uwe(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} ${Qn(this._name)})`}};vA.register(tz);var kDA=class extends ca{static token="version";static parentToken="kicad_pcb";token="version"};vA.register(kDA);var Moi=t=>/^[A-Za-z0-9._-]+$/.test(t),FDA=class extends gm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${Moi(this.value)?this.value:Qn(this.value)})`}};vA.register(FDA);var Noi=t=>/^[A-Za-z0-9._-]+$/.test(t),GDA=class extends gm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${Noi(this.value)?this.value:Qn(this.value)})`}};vA.register(GDA);var RDA=class Hwe extends vA{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=ai(A[0]);if(e===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?pi(A[1]):void 0;return new Hwe(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} ${Qn(this._name)})`:`(net ${this._id})`}};vA.register(RDA);var voi=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),MDA=class Ywe extends vA{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 Ywe;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[n,...o]=i;if(typeof n!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);e.consumeNode(n,o)}return e}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!voi.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=pi(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=vA.parsePrimitiveSexpr(["at",...e],{parentToken:this.token});if(!(i instanceof zg))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=ai(e[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=ai(e[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=Az.fromSexprPrimitives(e);return}case"net":{this._sxNet=RDA.fromSexprPrimitives(e);return}case"teardrops":{this._sxTeardrops=Ghe.fromSexprPrimitives(e);return}case"uuid":{const i=pi(e[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new Ui(i);return}case"tstamp":{const i=pi(e[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new Xg(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const e=pi(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?zg.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 Az?A:new Az(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 Ui?A:new Ui(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 Xg?A:new Xg(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(`
|
|
5826
|
-
`)}};vA.register(MDA);var NDA=class Jwe extends vA{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 Jwe;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 n=vA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof vA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(n)}return e}consumeChild(A){if(A instanceof kDA){this._sxVersion=A;return}if(A instanceof FDA){this._sxGenerator=A;return}if(A instanceof GDA){this._sxGeneratorVersion=A;return}if(A instanceof xDA){this._sxGeneral=A;return}if(A instanceof Uj){this._sxPaper=A;return}if(A instanceof gQe){this._sxTitleBlock=A;return}if(A instanceof _DA){this._sxLayers=A;return}if(A instanceof bDA){this._sxSetup=A;return}if(A instanceof iS){this._properties.push(A);return}if(A instanceof tz){this._nets.push(A);return}if(A instanceof DwA){this._footprints.push(A);return}if(A instanceof IQe){this._images.push(A);return}if(A instanceof UwA){this._segments.push(A);return}if(A instanceof zj){this._grLines.push(A);return}if(A instanceof Xj){this._grTexts.push(A);return}if(A instanceof $he){this._grPolys.push(A);return}if(A instanceof jhe){this._grRects.push(A);return}if(A instanceof MDA){this._vias.push(A);return}if(A instanceof oEe){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 kDA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new FDA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new GDA(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}};vA.register(NDA);var cue=t=>vA.parse(t),YE=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")}},Loi=class extends YE{_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 Uj;e.size=A?.name??"A4",t.paper=e,t.uuid=new Ui(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function VG(t,A){if(t.manufacturer_part_number)return vDA(t.manufacturer_part_number);const e=Uoi(t.ftype),i=A?.footprinter_string;return vDA(i?`${e}_${i}`:e)}function Uoi(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function vDA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function iz(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Iue={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},Hoi=/^[A-Za-z]+\d+$/;function lue(t){return t?Hoi.test(t.trim()):!1}function nz(t){const A=t?.ftype;if(A&&Iue[A])return Iue[A];const e=t?.name;return lue(e),iz(e)}function Yoi(t){const A=t?.name;return lue(A)?A.trim():`${nz(t)}?`}function Bue(t){return t in mQ}function Cue(t,A,e,i){if(i)return`Custom:${i}`;if(t.type!=="source_component")return A.symbol_name?Bue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Bue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=VG(t,e);return`Device:${nz(t)}_${n}`}var Joi=class extends YE{processedSymbolNames=new Set;_step(){const{kicadSch:t,db:A}=this.ctx,e=new GQe,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)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 c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}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(c=>c.source_component_id===e.source_component_id);let n=t.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===t.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(t,e,i,n);const o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,t);if(!s)return null;const r=Cue(e,t,i),a=e.ftype==="simple_chip",g=VG(e,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:nz(e)})}createLibrarySymbolFromSchematicSymbol(t,A,e,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=VG(A,e);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=this.buildSymbolDataFromSchematicPrimitives(i,o,t.schematic_component_id),g=VG(A,e);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:t,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:nz(A)})}buildSymbolDataFromSchematicPrimitives(t,A,e){const{circuitJson:i}=this.ctx,n=i.filter(c=>c.type==="schematic_circle"&&c.schematic_symbol_id===t),o=i.filter(c=>c.type==="schematic_line"&&c.schematic_symbol_id===t),s=i.filter(c=>c.type==="schematic_path"&&c.schematic_symbol_id===t);let r=i.filter(c=>c.type==="schematic_port"&&"schematic_symbol_id"in c&&c.schematic_symbol_id===t);if(r.length===0&&e&&(r=i.filter(c=>c.type==="schematic_port"&&c.schematic_component_id===e&&c.display_pin_label!==void 0),r.length===0)){const c=i.filter(l=>l.type==="schematic_port"&&l.schematic_component_id===e),I=new Set;r=c.filter(l=>{const B=l.pin_number;if(B!==void 0){if(I.has(B))return!1;I.add(B)}return!0})}const a=[];for(const c of n)a.push({type:"circle",x:c.center?.x??0,y:c.center?.y??0,radius:c.radius??.5,fill:c.is_filled??!1,fillColor:c.fill_color});for(const c of o)a.push({type:"path",points:[{x:c.x1??0,y:c.y1??0},{x:c.x2??0,y:c.y2??0}]});for(const c of s)c.points&&c.points.length>0&&a.push({type:"path",points:c.points,fill:c.is_filled??!1,fillColor:c.fill_color});const g=r.map((c,I)=>({x:c.center?.x??0,y:c.center?.y??0,labels:[c.display_pin_label||`${c.pin_number||I+1}`],pinNumber:c.pin_number||I+1,facingDirection:c.facing_direction}));return g.sort((c,I)=>c.pinNumber-I.pinNumber),{center:A.center||{x:0,y:0},size:A.size||{width:1,height:1},primitives:a,ports:g}}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const n=mQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,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:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(t,A){return t.startsWith("generic_chip_")?this.createGenericChipSymbolData(A,this.ctx.db):mQ[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,n=t.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/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:[o],ports:s,size:{width:i,height:n}}}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new N1({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new lmA;c.hide=!e,g._sxPinNumbers=c;const I=new CmA;I.offset=e?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:t,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const l=this.createDrawingSubsymbol({libId:t,symbolData:A,isChip:e});g.subSymbols.push(l);const B=this.createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i});return g.subSymbols.push(B),g._sxEmbeddedFonts=new R1(!1),g}addSymbolProperties({symbol:t,libId:A,description:e,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,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:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)t.properties.push(new _f({key:g.key,value:g.value,id:g.id,at:g.at,effects:this.createTextEffects(1.27,g.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,A){return A?`${A}*`:t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:t,symbolData:A,isChip:e}){const i=new N1({libraryId:`${t.split(":")[1]}_0_1`}),n=15.24,o=this.ctx.c2kMatSch?.a||15,s=e?o:n;for(const r of A.primitives||[])if(r.type==="path"&&r.points){const a=e||r.fill?"background":"none",g=this.createPolylineFromPoints({points:r.points,scale:s,center:A.center,fillType:a});i.polylines.push(g)}else if(r.type==="circle"){const a=this.createCircleFromPrimitive({primitive:r,scale:s,center:A.center});i.circles.push(a)}return i}createPolylineFromPoints({points:t,scale:A,center:e,fillType:i}){const n=new BQe,o=e?.x??0,s=e?.y??0,r=fh(A,A),a=t.map(l=>{const B=Pt(r,{x:l.x-o,y:l.y-s});return new JQ(B.x,B.y)}),g=new KC(a);n.points=g;const c=new tS;c.width=.254,c.type="default",n.stroke=c;const I=new pQe;return I.type=i,n.fill=I,n}createCircleFromPrimitive({primitive:t,scale:A,center:e}){const i=new mQe,n=e?.x??0,o=e?.y??0,s=fh(A,A),r=Pt(s,{x:t.x-n,y:t.y-o}),a=i;a._sxCenter=new uQe(r.x,r.y),a._sxRadius=new dQe(t.radius*A);const g=new tS;g.width=.254,g.type="default",a._sxStroke=g;const c=new fQe;return c.type=t.fill?"background":"none",a._sxFill=c,i}createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i}){const n=new N1({libraryId:`${t.split(":")[1]}_1_1`});for(let o=0;o<(A.ports?.length||0);o++){const s=A.ports[o],r=new Tj;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,e,o,i);r.at=[a,g,c];const I=6,l=2.54;r.length=e?I:l;const B=new W0;B.size={height:1.27,width:1.27};const C=new O0({font:B}),Q=s.labels?.[0]||"~";r._sxName=new QmA({value:Q,effects:C});const h=new W0;h.size={height:1.27,width:1.27};const E=new O0({font:h}),u=s.pinNumber?.toString()||`${o+1}`;r._sxNumber=new DQe({value:u,effects:E}),n.pins.push(r)}return n}calculatePinPosition(t,A,e,i,n,o){const r=this.ctx.c2kMatSch?.a||15,a=i?r:15.24;let g=t.x??0,c=t.y??0,I=!1;if(i&&n!==void 0&&o){const m=this.ctx.db.schematic_port.list().filter(D=>D.schematic_component_id===o.schematic_component_id).sort((D,w)=>(D.pin_number||0)-(w.pin_number||0));if(m[n]){const D=m[n];g=D.center.x-o.center.x,c=D.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,D=A?.y??0;l=g-m,B=c-D}const C=fh(a,a),Q=Pt(C,{x:l,y:B});let h;if(i&&e){const m=e.width/2,D=e.height/2,w=Math.abs(l)/m,S=Math.abs(B)/D;h=w>S}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&e){const m=e.width/2*a,D=e.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?D:-D)}let p=0;return h?l>0?(p=180,i&&(E=E+d)):(p=0,i&&(E=E-d)):B>0?(p=270,i&&(u=u+d)):(p=90,i&&(u=u-d)),{x:E,y:u,angle:p}}createTextEffects(t,A){const e=new W0;return e.size={height:t,width:t},new O0({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Toi=class extends YE{_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 n of e){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Pt(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new N1({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(tA=>tA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const tA=this.ctx.circuitJson.find(sA=>(sA.type==="schematic_line"||sA.type==="schematic_circle"||sA.type==="schematic_path")&&sA.schematic_component_id===n.schematic_component_id&&sA.schematic_symbol_id);tA&&(l=tA.schematic_symbol_id)}if(l){const tA=this.ctx.circuitJson.find(sA=>sA.type==="schematic_symbol"&&sA.schematic_symbol_id===l);if(tA?.name)I=tA.name;else{const sA=VG(o,c);sA?I=sA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Cue(o,n,c,I),C=new cmA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let p;if(this.ctx.symbolMetadataMap&&o.name){const tA=iz(o.name);p=this.ctx.symbolMetadataMap.get(tA)}const m=p?.properties?.Reference,D=new _f({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),w=o.ftype==="simple_chip",S=p?.properties?.Value,k=new _f({key:"Value",value:S?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(S?.effects?.font?.size?.x??1.27),S?.effects?.hide??w)}),x=p?.properties?.Footprint,N=new _f({key:"Footprint",value:x?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,x?.effects?.hide??!0)}),M=p?.properties?.Datasheet,L=new _f({key:"Datasheet",value:M?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,M?.effects?.hide??!0)}),Y=p?.properties?.Description,H=new _f({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(D,k,N,L,H);const O=p?.properties?.ki_keywords;if(O?.value){const tA=new _f({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(tA)}const Z=p?.properties?.ki_fp_filters;if(Z?.value){const tA=new _f({key:"ki_fp_filters",value:Z.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,Z.effects?.hide??!0)});g.properties.push(tA)}if(p){if(p.inBom!==void 0&&(g.inBom=p.inBom),p.onBoard!==void 0&&(g.onBoard=p.onBoard),p.excludeFromSim!==void 0&&(g.excludeFromSim=p.excludeFromSim),p.pinNames){const tA=new CmA;p.pinNames.offset!==void 0&&(tA.offset=Number(p.pinNames.offset)),p.pinNames.hide!==void 0&&(tA.hide=p.pinNames.hide),g.pinNames=tA}if(p.pinNumbers){const tA=new lmA;p.pinNumbers.hide!==void 0&&(tA.hide=p.pinNumbers.hide),g.pinNumbers=tA}p.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new R1(p.embeddedFonts))}let X=A.schematic_port.list().filter(tA=>tA.schematic_component_id===n.schematic_component_id);if(l){const tA=X.filter(sA=>sA.display_pin_label);tA.length>0&&(X=tA)}X.sort((tA,sA)=>(tA.pin_number||0)-(sA.pin_number||0));for(let tA=0;tA<X.length;tA++){const sA=X[tA];if(!sA)continue;const IA=new Tj;IA.numberString=`${sA.pin_number||tA+1}`,IA.uuid=crypto.randomUUID(),g.pins.push(IA)}const iA=new hmA,aA=new umA(""),eA=new dmA(`/${t?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),iA.projects.push(aA),g._sxInstances=iA,i.push(g)}t&&(t.symbols=i),this.finished=!0}getTextPositions(t,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===t.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Pt(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=t.symbol_name,o=mQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Pt(this.ctx.c2kMatSch,{x:t.center.x+(s.x-a.x)+c,y:t.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Pt(this.ctx.c2kMatSch,{x:t.center.x+(r.x-a.x)+c,y:t.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(t){const A=t.name||"?",e=Yoi(t);return t.ftype==="simple_resistor"?{reference:e,value:t.display_resistance||"R",description:"Resistor"}:t.ftype==="simple_capacitor"?{reference:e,value:t.display_capacitance||"C",description:"Capacitor"}:t.ftype==="simple_inductor"?{reference:e,value:t.display_inductance||"L",description:"Inductor"}:t.ftype==="simple_diode"?{reference:e,value:"D",description:"Diode"}:t.ftype==="simple_chip"?{reference:e,value:A,description:"Integrated Circuit"}:t.ftype==="simple_led"?{reference:e,value:t.manufacturer_part_number||"",description:"LED"}:t.ftype==="simple_switch"?{reference:e,value:t.manufacturer_part_number||"",description:"Switch"}:t.ftype==="simple_potentiometer"?{reference:e,value:t.display_max_resistance||"",description:"Potentiometer"}:{reference:e,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new W0;i.size={height:t,width:t};const n=e?new jJ({horizontal:e}):void 0;return new O0({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Koi=class extends YE{_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=[],n=[];for(const o of e){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(t&&i.length>0){const o=t.symbols||[];t.symbols=[...o,...i]}t&&n.length>0&&(t.globalLabels=[...t.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Pt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=crypto.randomUUID(),s=new N1({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new cmA(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new _f({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new _f({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new _f({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new _f({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new _f({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new Tj;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new hmA,p=new umA(""),m=new dmA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,p.paths.push(m),d.projects.push(p),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Pt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new jJ(a)),new JQe({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new W0;return e.size={height:t,width:t},new O0({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Poi=class extends YE{_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=[],n=[];for(const o of e){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}t.wires=i,t.junctions=n,this.finished=!0}createWireFromEdge(t){const A=new MQe;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Pt(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Pt(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),n=e.x,o=e.y,s=i.x,r=i.y,a=new KC([new JQ(n,o),new JQ(s,r)]);A.points=a;const g=new tS;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}=Pt(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new NQe({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},qoi=class extends YE{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new mmA,e=new PQe;e.value="/";const i=new qQe("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new R1(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Ooi(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of e)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var oz=[{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 Woi(t,A,e=20){const i=t+2*e,n=A+2*e;for(let o=0;o<oz.length;o++){const s=oz[o];if(i<=s.width&&n<=s.height)return s}return oz[oz.length-1]}var Que=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t,A){const i=Ga(t),{center:n,bounds:o}=Ooi(i),s=(o.maxX-o.minX)*15,r=(o.maxY-o.minY)*15,a=Woi(s,r),g=a.width/2,c=a.height/2;this.ctx={db:i,circuitJson:t,kicadSch:new DmA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:a,c2kMatSch:sB(Qr(g,c),fh(15,-15),Qr(-n.x,-n.y)),symbolMetadataMap:A?.symbolMetadataMap},this.pipeline=[new Loi(t,this.ctx),new Joi(t,this.ctx),new Toi(t,this.ctx),new Koi(t,this.ctx),new Poi(t,this.ctx),new qoi(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()}},Zoi=class extends YE{_step(){const{kicadPcb:t,db:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,t.version=20241229;const n=new Uj;n.size="A4",t.paper=n;const o=new xDA;o.thickness=1.6,t.general=o;const s=new bDA;s.padToMaskClearance=0,t.setup=s;const r=new _DA,a=[new vl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new vl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new vl({index:31,name:"B.Cu",type:"signal"})),a.push(new vl({index:32,name:"B.Adhes",type:"user"}),new vl({index:33,name:"F.Adhes",type:"user"}),new vl({index:34,name:"B.Paste",type:"user"}),new vl({index:35,name:"F.Paste",type:"user"}),new vl({index:36,name:"B.SilkS",type:"user"}),new vl({index:37,name:"F.SilkS",type:"user"}),new vl({index:38,name:"B.Mask",type:"user"}),new vl({index:39,name:"F.Mask",type:"user"}),new vl({index:40,name:"Dwgs.User",type:"user"}),new vl({index:41,name:"Cmts.User",type:"user"}),new vl({index:42,name:"Eco1.User",type:"user"}),new vl({index:43,name:"Eco2.User",type:"user"}),new vl({index:44,name:"Edge.Cuts",type:"user"}),new vl({index:45,name:"Margin",type:"user"}),new vl({index:46,name:"B.CrtYd",type:"user"}),new vl({index:47,name:"F.CrtYd",type:"user"}),new vl({index:48,name:"B.Fab",type:"user"}),new vl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,t.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Voi=class extends YE{_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||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}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 c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new tz(0,""));let s=1;for(const[r,a]of n){const g=new tz(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}t.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function joi(t){let A=0;for(let i=0;i<t.length;i++){const n=t.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let e="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<t.length;o++)n=(n<<5)-n+t.charCodeAt(o)+i*31,n=n&n;e+=Math.abs(n).toString(16).padStart(8,"0")}return e}function kf(t){const A=joi(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function sz(t){const A=new W0;return t?.font?.size?A.size={width:Number(t.font.size.x),height:Number(t.font.size.y)}:A.size={width:1.27,height:1.27},t?.font?.thickness!==void 0?A.thickness=Number(t.font.thickness):A.thickness=.15,new O0({font:A})}function zoi(t,A,e){if(A.properties){const i=[],n=A.properties.Reference;i.push(new iS({key:"Reference",value:n?.value??"REF**",position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:kf(`${e}-property-Reference`),effects:sz(n?.effects),hidden:n?.hide}));const o=A.properties.Value;i.push(new iS({key:"Value",value:o?.value??e,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:kf(`${e}-property-Value`),effects:sz(o?.effects),hidden:o?.hide}));const s=A.properties.Datasheet;i.push(new iS({key:"Datasheet",value:s?.value??"",position:s?.at?[Number(s.at.x),Number(s.at.y),Number(s.at.rotation??0)]:[0,0,0],layer:s?.layer??"F.Fab",uuid:kf(`${e}-property-Datasheet`),effects:sz(s?.effects),hidden:s?.hide??!0}));const r=A.properties.Description;i.push(new iS({key:"Description",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:kf(`${e}-property-Description`),effects:sz(r?.effects),hidden:r?.hide??!0})),t.properties=i}if(A.attributes&&(t.attr||(t.attr=new SmA),A.attributes.through_hole?t.attr.type="through_hole":A.attributes.smd&&(t.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(t.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(t.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(t.libraryLink=A.footprintName),A.layer&&(t.layer=A.layer),A.embeddedFonts!==void 0&&(t.embeddedFonts=new R1(A.embeddedFonts)),A.model){const i=new Zj(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=t.models||[];t.models=[i,...n]}}function Xoi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new gwA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new tS,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),e.push(a)}return e}function $oi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new gwA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new tS,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),e.push(a)}return e}function Asi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Oj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new tS,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),e.push(c)}return e}function esi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Oj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new tS,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),e.push(g)}return e}function tsi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Oj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new tS,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),e.push(c)}return e}function isi(t,A){const e=[];for(const i of t){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new JQ(c,I)}),r=new Lhe;r.points=new KC(s),r.layer=o,r.fill=!1;const a=new tS;a.width=.05,a.type="default",r.stroke=a,e.push(r)}return e}function nsi({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,n=-(t.anchor_position.y-A.y),o=e!==0?Lm(e*Math.PI/180):Nu(),s=Pt(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",c=(t.font_size||1)/1.5,I=new W0;I.size={width:c,height:c};const l=new O0({font:I}),B=t.ccw_rotation||0;return new $mA({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function osi(t,A,e,i){const n=[];for(const o of t){const s=nsi({textElement:o,componentCenter:A,componentRotation:e});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function ssi(t,A,e){const i=[];for(const n of t){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=e!==0?Lm(e*Math.PI/180):Nu(),a=Pt(r,{x:o,y:s}),g=n.font_size||1,c=new W0;c.size={width:g,height:g};const I=new O0({font:c}),l=new $mA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function rsi(t,A){const e=[],i=t.model_step_url||t.model_wrl_url;if(!i)return e;const n=new Zj(i);if(t.position&&(n.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:t.position.z||0}),t.rotation&&(n.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const o=t.model_unit_to_mm_scale_factor;n.scale={x:o,y:o,z:o}}return e.push(n),e}function asi({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){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,p)=>d+p.x,0)/u.length,r=u.reduce((d,p)=>d+p.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=sB(i!==0?Lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},fh(1,-1),Qr(-A.x,-A.y)),g=Pt(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[t.layer]||"F.Cu";let l,B,C,Q;if(t.shape==="circle")l="circle",B=["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=sB(fh(1,-1),Qr(-s,-r)),p=u.map(D=>{const w=Pt(d,{x:D.x,y:D.y});return new JQ(w.x,w.y)}),m=new ZmA;m.contours=[new KC(p)],m.width=0,m.filled=!0,Q=new phe,Q.addGraphic(m),l="custom",C=new ihe,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in t?t.width:.5,"height"in t?t.height:.5];const h=`pad:${o}:${e}:${g.x},${g.y}`,E=new qj({number:String(e),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:kf(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new TmA(n.id,n.name)),E}function gsi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=asi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function csi({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){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):Nu(),g=Pt(a,{x:s,y:r});let c="circle",I,l,B=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=Pt(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(c="circle",I=[t.outer_diameter,t.outer_diameter],l=new nS({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(c="oval",I=[t.outer_width,t.outer_height],l=new nS({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new nS({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="circular_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new nS({diameter:t.hole_diameter,offset:Q})):t.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new nS({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q}),B=t.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new nS({diameter:.8,offset:Q}));const h=`thruhole:${o}:${e}:${g.x},${g.y}`,E=new qj({number:String(e),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:kf(h)});return n&&(E.net=new TmA(n.id,n.name)),E}function Isi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=csi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function lsi({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,n=-(t.y-A.y),o=e!==0?Lm(e*Math.PI/180):Nu(),s=Pt(o,{x:i,y:n});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const c=t.hole_diameter;a=[c,c],g=new nS({diameter:c})}else if(t.hole_shape==="oval"){r="oval";const c=t.hole_width,I=t.hole_height;a=[c,I],g=new nS({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in t?t.hole_diameter:1;a=[c,c],g=new nS({diameter:c})}return new qj({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 Bsi(t,A,e){const i=[];for(const n of t){const o=lsi({pcbHole:n,componentCenter:A,componentRotation:e});o&&i.push(o)}return i}var Csi=class extends YE{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 n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}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,n=this.getCadComponentForPcbComponent(e.pcb_component_id),o=i?VG(i,n):"Unknown",s=Pt(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new DwA({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:kf(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];g.push(...osi(c,e.center,e.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];g.push(...ssi(I,e.center,e.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=H=>this.getNetInfoForPcbPort(H),C=this.ctx.db.pcb_smtpad?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=gsi(C,e.center,e.rotation||0,e.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],{pads:u}=Isi(E,e.center,e.rotation||0,e.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(H=>H.subcircuit_id===e.subcircuit_id)||[],p=Bsi(d,e.center,e.rotation||0);l.push(...p),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],D=a.fpCircles??[];D.push(...Xoi(m,e.center));const w=this.ctx.db.pcb_courtyard_circle?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];D.push(...$oi(w,e.center)),a.fpCircles=D;const S=this.ctx.db.pcb_fabrication_note_rect?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],k=a.fpRects??[];k.push(...Asi(S,e.center));const x=this.ctx.db.pcb_note_rect?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];k.push(...esi(x,e.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];k.push(...tsi(N,e.center)),a.fpRects=k;const M=this.ctx.db.pcb_courtyard_outline?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],L=isi(M,e.center);if(L.length>0&&(a.fpPolys=L),n){const H=rsi(n,e.center);H.length>0&&(a.models=H)}if(this.ctx.footprintMetadataMap&&i?.name){const H=iz(i.name),O=this.ctx.footprintMetadataMap.get(H);O&&zoi(a,O,i.name)}const Y=t.footprints;Y.push(a),t.footprints=Y,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},Qsi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function hsi(t){return t&&(Qsi[t]||t)||"F.Cu"}function Esi(t){const A=["F.Cu"];for(let e=1;e<t-1;e++)A.push(`In${e}.Cu`);return A.push("B.Cu"),A}var usi=class extends YE{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}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Pt(A,{x:s.x,y:s.y}),g=Pt(A,{x:r.x,y:r.y});let c;if(e){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=e.get(h))}const I=s.layer??r.layer??n,l=hsi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new UwA({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new $j(c?.id??0),uuid:kf(B)}),Q=t.segments;Q.push(C),t.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},dsi=class extends YE{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],n=Pt(A,{x:i.x,y:i.y});let o;if(e){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=e.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):Esi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new MDA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new RDA(o?.id??0),uuid:kf(a)}),c=t.vias;c.push(g),t.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function psi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Pt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[t.layer]||t.layer||"F.Fab",o=(t.font_size||1)/1.5,s=new W0;s.size={width:o,height:o};const r=new jJ,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 O0({font:s});a!=="center"&&(g.justify=r);const c=new zg([e.x,e.y,0]),I=new Xj({text:t.text,layer:n,effects:g});return I.position=c,I}function fsi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Pt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",o=(t.font_size||1)/1.5,s=new W0;s.size={width:o,height:o};const r=new jJ,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 O0({font:s});a!=="center"&&(g.justify=r);const c=t.ccw_rotation||0,I=new zg([e.x,e.y,c]),l=new Xj({text:t.text,layer:n,effects:g});return l.position=I,l}var ysi=class extends YE{_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 s of e)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Pt(A,{x:a.x,y:a.y}),I=Pt(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new zj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=t.graphicLines;Q.push(C),t.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=fsi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=psi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Pt(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new zj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=t.graphicLines;B.push(l),t.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},hue=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t,A){this.ctx={db:Ga(t),circuitJson:t,kicadPcb:new NDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:sB(Qr(100,100),fh(1,-1)),footprintMetadataMap:A?.footprintMetadataMap},this.pipeline=[new Zoi(t,this.ctx),new Voi(t,this.ctx),new Csi(t,this.ctx),new usi(t,this.ctx),new dsi(t,this.ctx),new ysi(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()}},msi=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,n=A.pcbFilename??`${e}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Ga(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:o,modified:o},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:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5826
|
+
`)}};vA.register(MDA);var NDA=class Jwe extends vA{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 Jwe;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 n=vA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(n instanceof vA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(n)}return e}consumeChild(A){if(A instanceof kDA){this._sxVersion=A;return}if(A instanceof FDA){this._sxGenerator=A;return}if(A instanceof GDA){this._sxGeneratorVersion=A;return}if(A instanceof xDA){this._sxGeneral=A;return}if(A instanceof Uj){this._sxPaper=A;return}if(A instanceof gQe){this._sxTitleBlock=A;return}if(A instanceof _DA){this._sxLayers=A;return}if(A instanceof bDA){this._sxSetup=A;return}if(A instanceof iS){this._properties.push(A);return}if(A instanceof tz){this._nets.push(A);return}if(A instanceof DwA){this._footprints.push(A);return}if(A instanceof IQe){this._images.push(A);return}if(A instanceof UwA){this._segments.push(A);return}if(A instanceof zj){this._grLines.push(A);return}if(A instanceof Xj){this._grTexts.push(A);return}if(A instanceof $he){this._grPolys.push(A);return}if(A instanceof jhe){this._grRects.push(A);return}if(A instanceof MDA){this._vias.push(A);return}if(A instanceof oEe){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 kDA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new FDA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new GDA(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}};vA.register(NDA);var cue=t=>vA.parse(t),YE=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")}},Loi=class extends YE{_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 Uj;e.size=A?.name??"A4",t.paper=e,t.uuid=new Ui(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function VG(t,A){if(t.manufacturer_part_number)return vDA(t.manufacturer_part_number);const e=Uoi(t.ftype),i=A?.footprinter_string;return vDA(i?`${e}_${i}`:e)}function Uoi(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function vDA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function iz(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Iue={simple_resistor:"R",simple_capacitor:"C",simple_inductor:"L",simple_diode:"D",simple_led:"D",simple_chip:"U",simple_transistor:"Q",simple_mosfet:"Q",simple_fuse:"F",simple_switch:"SW",simple_push_button:"SW",simple_potentiometer:"RV",simple_crystal:"Y",simple_resonator:"Y",simple_pin_header:"J",simple_pinout:"J",simple_test_point:"TP",simple_battery:"BT"},Hoi=/^[A-Za-z]+\d+$/;function lue(t){return t?Hoi.test(t.trim()):!1}function nz(t){const A=t?.ftype;if(A&&Iue[A])return Iue[A];const e=t?.name;return lue(e),iz(e)}function Yoi(t){const A=t?.name;return lue(A)?A.trim():`${nz(t)}?`}function Bue(t){return t in mQ}function Cue(t,A,e,i){if(i)return`Custom:${i}`;if(t.type!=="source_component")return A.symbol_name?Bue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Bue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const n=VG(t,e);return`Device:${nz(t)}_${n}`}var Joi=class extends YE{processedSymbolNames=new Set;_step(){const{kicadSch:t,db:A}=this.ctx,e=new GQe,i=[];this.processedSymbolNames=new Set;const n=A.schematic_component.list();for(const s of n){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const o=A.schematic_net_label?.list?.()||[];for(const s of o)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 c=this.createLibrarySymbolForNetLabel({netLabel:s,isPower:r??!1,isGround:a??!1});c&&i.push(c)}}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(c=>c.source_component_id===e.source_component_id);let n=t.schematic_symbol_id;if(!n){const c=this.ctx.circuitJson.find(I=>(I.type==="schematic_line"||I.type==="schematic_circle"||I.type==="schematic_path")&&I.schematic_component_id===t.schematic_component_id&&I.schematic_symbol_id);c&&(n=c.schematic_symbol_id)}if(n)return this.createLibrarySymbolFromSchematicSymbol(t,e,i,n);const o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const s=this.getSymbolData(o,t);if(!s)return null;const r=Cue(e,t,i),a=e.ftype==="simple_chip",g=VG(e,i);return this.createLibrarySymbol({libId:r,symbolData:s,isChip:a,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:nz(e)})}createLibrarySymbolFromSchematicSymbol(t,A,e,i){const{db:n}=this.ctx,o=this.ctx.circuitJson.find(c=>c.type==="schematic_symbol"&&c.schematic_symbol_id===i);if(!o)return null;let s;if(o.name)s=o.name;else{const c=VG(A,e);c?s=c:s=`custom_${A.ftype||"component"}_${i}`}const r=`Custom:${s}`;if(this.processedSymbolNames.has(r))return null;this.processedSymbolNames.add(r);const a=this.buildSymbolDataFromSchematicPrimitives(i,o,t.schematic_component_id),g=VG(A,e);return this.createLibrarySymbol({libId:r,symbolData:a,isChip:!1,schematicComponent:t,description:this.getDescription(A),keywords:this.getKeywords(A),fpFilters:this.getFpFilters(A,o.name),footprintRef:g?`tscircuit:${g}`:"",referencePrefix:nz(A)})}buildSymbolDataFromSchematicPrimitives(t,A,e){const{circuitJson:i}=this.ctx,n=i.filter(c=>c.type==="schematic_circle"&&c.schematic_symbol_id===t),o=i.filter(c=>c.type==="schematic_line"&&c.schematic_symbol_id===t),s=i.filter(c=>c.type==="schematic_path"&&c.schematic_symbol_id===t);let r=i.filter(c=>c.type==="schematic_port"&&"schematic_symbol_id"in c&&c.schematic_symbol_id===t);if(r.length===0&&e&&(r=i.filter(c=>c.type==="schematic_port"&&c.schematic_component_id===e&&c.display_pin_label!==void 0),r.length===0)){const c=i.filter(l=>l.type==="schematic_port"&&l.schematic_component_id===e),I=new Set;r=c.filter(l=>{const B=l.pin_number;if(B!==void 0){if(I.has(B))return!1;I.add(B)}return!0})}const a=[];for(const c of n)a.push({type:"circle",x:c.center?.x??0,y:c.center?.y??0,radius:c.radius??.5,fill:c.is_filled??!1,fillColor:c.fill_color});for(const c of o)a.push({type:"path",points:[{x:c.x1??0,y:c.y1??0},{x:c.x2??0,y:c.y2??0}]});for(const c of s)c.points&&c.points.length>0&&a.push({type:"path",points:c.points,fill:c.is_filled??!1,fillColor:c.fill_color});const g=r.map((c,I)=>({x:c.center?.x??0,y:c.center?.y??0,labels:[c.display_pin_label||`${c.pin_number||I+1}`],pinNumber:c.pin_number||I+1,facingDirection:c.facing_direction}));return g.sort((c,I)=>c.pinNumber-I.pinNumber),{center:A.center||{x:0,y:0},size:A.size||{width:1,height:1},primitives:a,ports:g}}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const n=mQ[i];if(!n)return null;const o=`Custom:${i}`;return this.createLibrarySymbol({libId:o,symbolData:n,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:"",referencePrefix:o.split(":")[1]?.[0]||"U"})}getSymbolData(t,A){return t.startsWith("generic_chip_")?this.createGenericChipSymbolData(A,this.ctx.db):mQ[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,n=t.size?.height||1,o={type:"path",points:[{x:-i/2,y:-n/2},{x:i/2,y:-n/2},{x:i/2,y:n/2},{x:-i/2,y:n/2},{x:-i/2,y:-n/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:[o],ports:s,size:{width:i,height:n}}}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:n,keywords:o,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new N1({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new lmA;c.hide=!e,g._sxPinNumbers=c;const I=new CmA;I.offset=e?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:t,description:n,keywords:o,fpFilters:s,footprintRef:r,referencePrefix:a});const l=this.createDrawingSubsymbol({libId:t,symbolData:A,isChip:e});g.subSymbols.push(l);const B=this.createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i});return g.subSymbols.push(B),g._sxEmbeddedFonts=new R1(!1),g}addSymbolProperties({symbol:t,libId:A,description:e,keywords:i,fpFilters:n,footprintRef:o="",referencePrefix:s}){const r=s||A.split(":")[1]?.[0]||"U",a=[{key:"Reference",value:r,id:0,at:[2.032,0,90],hide:!1},{key:"Value",value:r,id:1,at:[0,0,90],hide:!1},{key:"Footprint",value:o,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:n,id:6,at:[0,0,0],hide:!0}];for(const g of a)t.properties.push(new _f({key:g.key,value:g.value,id:g.id,at:g.at,effects:this.createTextEffects(1.27,g.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,A){return A?`${A}*`:t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:t,symbolData:A,isChip:e}){const i=new N1({libraryId:`${t.split(":")[1]}_0_1`}),n=15.24,o=this.ctx.c2kMatSch?.a||15,s=e?o:n;for(const r of A.primitives||[])if(r.type==="path"&&r.points){const a=e||r.fill?"background":"none",g=this.createPolylineFromPoints({points:r.points,scale:s,center:A.center,fillType:a});i.polylines.push(g)}else if(r.type==="circle"){const a=this.createCircleFromPrimitive({primitive:r,scale:s,center:A.center});i.circles.push(a)}return i}createPolylineFromPoints({points:t,scale:A,center:e,fillType:i}){const n=new BQe,o=e?.x??0,s=e?.y??0,r=fh(A,A),a=t.map(l=>{const B=Pt(r,{x:l.x-o,y:l.y-s});return new JQ(B.x,B.y)}),g=new KC(a);n.points=g;const c=new tS;c.width=.254,c.type="default",n.stroke=c;const I=new pQe;return I.type=i,n.fill=I,n}createCircleFromPrimitive({primitive:t,scale:A,center:e}){const i=new mQe,n=e?.x??0,o=e?.y??0,s=fh(A,A),r=Pt(s,{x:t.x-n,y:t.y-o}),a=i;a._sxCenter=new uQe(r.x,r.y),a._sxRadius=new dQe(t.radius*A);const g=new tS;g.width=.254,g.type="default",a._sxStroke=g;const c=new fQe;return c.type=t.fill?"background":"none",a._sxFill=c,i}createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i}){const n=new N1({libraryId:`${t.split(":")[1]}_1_1`});for(let o=0;o<(A.ports?.length||0);o++){const s=A.ports[o],r=new Tj;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,e,o,i);r.at=[a,g,c];const I=6,l=2.54;r.length=e?I:l;const B=new W0;B.size={height:1.27,width:1.27};const C=new O0({font:B}),Q=s.labels?.[0]||"~";r._sxName=new QmA({value:Q,effects:C});const h=new W0;h.size={height:1.27,width:1.27};const E=new O0({font:h}),u=s.pinNumber?.toString()||`${o+1}`;r._sxNumber=new DQe({value:u,effects:E}),n.pins.push(r)}return n}calculatePinPosition(t,A,e,i,n,o){const r=this.ctx.c2kMatSch?.a||15,a=i?r:15.24;let g=t.x??0,c=t.y??0,I=!1;if(i&&n!==void 0&&o){const m=this.ctx.db.schematic_port.list().filter(D=>D.schematic_component_id===o.schematic_component_id).sort((D,w)=>(D.pin_number||0)-(w.pin_number||0));if(m[n]){const D=m[n];g=D.center.x-o.center.x,c=D.center.y-o.center.y,I=!0}}let l,B;if(I)l=g,B=c;else{const m=A?.x??0,D=A?.y??0;l=g-m,B=c-D}const C=fh(a,a),Q=Pt(C,{x:l,y:B});let h;if(i&&e){const m=e.width/2,D=e.height/2,w=Math.abs(l)/m,S=Math.abs(B)/D;h=w>S}else h=Math.abs(l)>Math.abs(B);let E=Q.x,u=Q.y;const d=6;if(i&&e){const m=e.width/2*a,D=e.height/2*a;h?(E=l>0?m:-m,u=B*a):(E=l*a,u=B>0?D:-D)}let p=0;return h?l>0?(p=180,i&&(E=E+d)):(p=0,i&&(E=E-d)):B>0?(p=270,i&&(u=u+d)):(p=90,i&&(u=u-d)),{x:E,y:u,angle:p}}createTextEffects(t,A){const e=new W0;return e.size={height:t,width:t},new O0({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Toi=class extends YE{_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 n of e){const o=n.source_component_id?A.source_component.get(n.source_component_id):null;if(!o||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Pt(this.ctx.c2kMatSch,{x:n.center.x,y:n.center.y}),a=crypto.randomUUID(),g=new N1({at:[s,r,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:a,fieldsAutoplaced:!0}),c=A.cad_component?.list()?.find(tA=>tA.source_component_id===o.source_component_id);let I,l=n.schematic_symbol_id;if(!l){const tA=this.ctx.circuitJson.find(sA=>(sA.type==="schematic_line"||sA.type==="schematic_circle"||sA.type==="schematic_path")&&sA.schematic_component_id===n.schematic_component_id&&sA.schematic_symbol_id);tA&&(l=tA.schematic_symbol_id)}if(l){const tA=this.ctx.circuitJson.find(sA=>sA.type==="schematic_symbol"&&sA.schematic_symbol_id===l);if(tA?.name)I=tA.name;else{const sA=VG(o,c);sA?I=sA:I=`custom_${o.ftype||"component"}_${l}`}}const B=Cue(o,n,c,I),C=new cmA(B);g._sxLibId=C;const{reference:Q,value:h,description:E}=this.getComponentMetadata(o),{refTextPos:u,valTextPos:d}=this.getTextPositions(n,{x:s,y:r});let p;if(this.ctx.symbolMetadataMap&&o.name){const tA=iz(o.name);p=this.ctx.symbolMetadataMap.get(tA)}const m=p?.properties?.Reference,D=new _f({key:"Reference",value:m?.value??Q,id:0,at:[u.x,u.y,0],effects:this.createTextEffects(Number(m?.effects?.font?.size?.x??1.27),m?.effects?.hide??!1)}),w=o.ftype==="simple_chip",S=p?.properties?.Value,k=new _f({key:"Value",value:S?.value??h,id:1,at:[d.x,d.y,0],effects:this.createTextEffects(Number(S?.effects?.font?.size?.x??1.27),S?.effects?.hide??w)}),x=p?.properties?.Footprint,N=new _f({key:"Footprint",value:x?.value??"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,x?.effects?.hide??!0)}),M=p?.properties?.Datasheet,L=new _f({key:"Datasheet",value:M?.value??"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,M?.effects?.hide??!0)}),Y=p?.properties?.Description,H=new _f({key:"Description",value:Y?.value??E,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,Y?.effects?.hide??!0)});g.properties.push(D,k,N,L,H);const O=p?.properties?.ki_keywords;if(O?.value){const tA=new _f({key:"ki_keywords",value:O.value,id:5,at:[s,r,0],effects:this.createTextEffects(1.27,O.effects?.hide??!0)});g.properties.push(tA)}const Z=p?.properties?.ki_fp_filters;if(Z?.value){const tA=new _f({key:"ki_fp_filters",value:Z.value,id:6,at:[s,r,0],effects:this.createTextEffects(1.27,Z.effects?.hide??!0)});g.properties.push(tA)}if(p){if(p.inBom!==void 0&&(g.inBom=p.inBom),p.onBoard!==void 0&&(g.onBoard=p.onBoard),p.excludeFromSim!==void 0&&(g.excludeFromSim=p.excludeFromSim),p.pinNames){const tA=new CmA;p.pinNames.offset!==void 0&&(tA.offset=Number(p.pinNames.offset)),p.pinNames.hide!==void 0&&(tA.hide=p.pinNames.hide),g.pinNames=tA}if(p.pinNumbers){const tA=new lmA;p.pinNumbers.hide!==void 0&&(tA.hide=p.pinNumbers.hide),g.pinNumbers=tA}p.embeddedFonts!==void 0&&(g._sxEmbeddedFonts=new R1(p.embeddedFonts))}let X=A.schematic_port.list().filter(tA=>tA.schematic_component_id===n.schematic_component_id);if(l){const tA=X.filter(sA=>sA.display_pin_label);tA.length>0&&(X=tA)}X.sort((tA,sA)=>(tA.pin_number||0)-(sA.pin_number||0));for(let tA=0;tA<X.length;tA++){const sA=X[tA];if(!sA)continue;const IA=new Tj;IA.numberString=`${sA.pin_number||tA+1}`,IA.uuid=crypto.randomUUID(),g.pins.push(IA)}const iA=new hmA,aA=new umA(""),eA=new dmA(`/${t?.uuid?.value||""}`);eA.reference=Q,eA.unit=1,aA.paths.push(eA),iA.projects.push(aA),g._sxInstances=iA,i.push(g)}t&&(t.symbols=i),this.finished=!0}getTextPositions(t,A){const i=(this.ctx.db.schematic_text?.list?.()?.filter(B=>B.schematic_component_id===t.schematic_component_id)||[]).find(B=>B.text&&B.text.length>0);if(i&&this.ctx.c2kMatSch){const B=Pt(this.ctx.c2kMatSch,{x:i.position.x,y:i.position.y}),C={x:A.x,y:A.y+6};return{refTextPos:B,valTextPos:C}}const n=t.symbol_name,o=mQ[n];if(!o)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of o.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=o.center||{x:0,y:0},c=n.includes("_down")||n.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Pt(this.ctx.c2kMatSch,{x:t.center.x+(s.x-a.x)+c,y:t.center.y+(s.y-a.y)}):{x:A.x,y:A.y-6},l=r&&this.ctx.c2kMatSch?Pt(this.ctx.c2kMatSch,{x:t.center.x+(r.x-a.x)+c,y:t.center.y+(r.y-a.y)}):{x:A.x,y:A.y+6};return{refTextPos:I,valTextPos:l}}getComponentMetadata(t){const A=t.name||"?",e=Yoi(t);return t.ftype==="simple_resistor"?{reference:e,value:t.display_resistance||"R",description:"Resistor"}:t.ftype==="simple_capacitor"?{reference:e,value:t.display_capacitance||"C",description:"Capacitor"}:t.ftype==="simple_inductor"?{reference:e,value:t.display_inductance||"L",description:"Inductor"}:t.ftype==="simple_diode"?{reference:e,value:"D",description:"Diode"}:t.ftype==="simple_chip"?{reference:e,value:A,description:"Integrated Circuit"}:t.ftype==="simple_led"?{reference:e,value:t.manufacturer_part_number||"",description:"LED"}:t.ftype==="simple_switch"?{reference:e,value:t.manufacturer_part_number||"",description:"Switch"}:t.ftype==="simple_potentiometer"?{reference:e,value:t.display_max_resistance||"",description:"Potentiometer"}:{reference:e,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new W0;i.size={height:t,width:t};const n=e?new jJ({horizontal:e}):void 0;return new O0({font:i,hiddenText:A,justify:n})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Koi=class extends YE{_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=[],n=[];for(const o of e){const s=o.text||"",r=o.symbol_name;if(r){const a=this.createSymbolFromNetLabel(o,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(o,s);a&&n.push(a)}}if(t&&i.length>0){const o=t.symbols||[];t.symbols=[...o,...i]}t&&n.length>0&&(t.globalLabels=[...t.globalLabels||[],...n]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:n}=Pt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=crypto.randomUUID(),s=new N1({at:[i,n,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:o,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new cmA(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new _f({key:"Reference",value:A,id:0,at:[i,n+c,0],effects:this.createTextEffects(1.27,!1)}),B=new _f({key:"Value",value:A,id:1,at:[i,n+I,0],effects:this.createTextEffects(1.27,!0)}),C=new _f({key:"Footprint",value:"",id:2,at:[i-1.778,n,90],effects:this.createTextEffects(1.27,!0)}),Q=new _f({key:"Datasheet",value:"~",id:3,at:[i,n,0],effects:this.createTextEffects(1.27,!0)}),h=new _f({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,n,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new Tj;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new hmA,p=new umA(""),m=new dmA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,p.paths.push(m),d.projects.push(p),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Pt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[n]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[n]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new jJ(a)),new JQe({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new W0;return e.size={height:t,width:t},new O0({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Poi=class extends YE{_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=[],n=[];for(const o of e){for(const s of o.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of o.junctions){const r=this.createJunction(s);n.push(r)}}t.wires=i,t.junctions=n,this.finished=!0}createWireFromEdge(t){const A=new MQe;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Pt(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Pt(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),n=e.x,o=e.y,s=i.x,r=i.y,a=new KC([new JQ(n,o),new JQ(s,r)]);A.points=a;const g=new tS;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}=Pt(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new NQe({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},qoi=class extends YE{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new mmA,e=new PQe;e.value="/";const i=new qQe("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new R1(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Ooi(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,n=1/0,o=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),n=Math.min(n,g.center.y-I/2),o=Math.max(o,g.center.x+c/2),s=Math.max(s,g.center.y+I/2)}for(const g of e)for(const c of g.edges)i=Math.min(i,c.from.x,c.to.x),n=Math.min(n,c.from.y,c.to.y),o=Math.max(o,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,n=0,o=0,s=0);const r=(i+o)/2,a=(n+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:n,maxX:o,maxY:s}}}var oz=[{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 Woi(t,A,e=20){const i=t+2*e,n=A+2*e;for(let o=0;o<oz.length;o++){const s=oz[o];if(i<=s.width&&n<=s.height)return s}return oz[oz.length-1]}var Que=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t,A){const i=Ga(t),{center:n,bounds:o}=Ooi(i),s=(o.maxX-o.minX)*15,r=(o.maxY-o.minY)*15,a=Woi(s,r),g=a.width/2,c=a.height/2;this.ctx={db:i,circuitJson:t,kicadSch:new DmA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:a,c2kMatSch:sB(Qr(g,c),fh(15,-15),Qr(-n.x,-n.y)),symbolMetadataMap:A?.symbolMetadataMap},this.pipeline=[new Loi(t,this.ctx),new Joi(t,this.ctx),new Toi(t,this.ctx),new Koi(t,this.ctx),new Poi(t,this.ctx),new qoi(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()}},Zoi=class extends YE{_step(){const{kicadPcb:t,db:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");const i=A.pcb_board?.list()?.[0]?.num_layers??2;this.ctx.numLayers=i,t.version=20241229;const n=new Uj;n.size="A4",t.paper=n;const o=new xDA;o.thickness=1.6,t.general=o;const s=new bDA;s.padToMaskClearance=0,t.setup=s;const r=new _DA,a=[new vl({index:0,name:"F.Cu",type:"signal"})];for(let g=1;g<i-1;g++)a.push(new vl({index:g,name:`In${g}.Cu`,type:"signal"}));a.push(new vl({index:31,name:"B.Cu",type:"signal"})),a.push(new vl({index:32,name:"B.Adhes",type:"user"}),new vl({index:33,name:"F.Adhes",type:"user"}),new vl({index:34,name:"B.Paste",type:"user"}),new vl({index:35,name:"F.Paste",type:"user"}),new vl({index:36,name:"B.SilkS",type:"user"}),new vl({index:37,name:"F.SilkS",type:"user"}),new vl({index:38,name:"B.Mask",type:"user"}),new vl({index:39,name:"F.Mask",type:"user"}),new vl({index:40,name:"Dwgs.User",type:"user"}),new vl({index:41,name:"Cmts.User",type:"user"}),new vl({index:42,name:"Eco1.User",type:"user"}),new vl({index:43,name:"Eco2.User",type:"user"}),new vl({index:44,name:"Edge.Cuts",type:"user"}),new vl({index:45,name:"Margin",type:"user"}),new vl({index:46,name:"B.CrtYd",type:"user"}),new vl({index:47,name:"F.CrtYd",type:"user"}),new vl({index:48,name:"B.Fab",type:"user"}),new vl({index:49,name:"F.Fab",type:"user"})),r.definitions=a,t.layers=r,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Voi=class extends YE{_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||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}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 c=this.ctx.db.source_net?.get(g);if(c?.subcircuit_connectivity_map_key&&c.subcircuit_connectivity_map_key.length>0){a=c.subcircuit_connectivity_map_key;break}}if(a&&!A.has(a)){const g=r.display_name||r.source_trace_id||"",c=g&&g.trim().length>0?g:a;A.set(a,c)}}const n=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),o=[];o.push(new tz(0,""));let s=1;for(const[r,a]of n){const g=new tz(s,a);o.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}t.nets=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function joi(t){let A=0;for(let i=0;i<t.length;i++){const n=t.charCodeAt(i);A=(A<<5)-A+n,A=A&A}let e="";for(let i=0;i<4;i++){let n=A;for(let o=0;o<t.length;o++)n=(n<<5)-n+t.charCodeAt(o)+i*31,n=n&n;e+=Math.abs(n).toString(16).padStart(8,"0")}return e}function kf(t){const A=joi(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function sz(t){const A=new W0;return t?.font?.size?A.size={width:Number(t.font.size.x),height:Number(t.font.size.y)}:A.size={width:1.27,height:1.27},t?.font?.thickness!==void 0?A.thickness=Number(t.font.thickness):A.thickness=.15,new O0({font:A})}function zoi(t,A,e){if(A.properties){const i=[],n=A.properties.Reference;i.push(new iS({key:"Reference",value:e,position:n?.at?[Number(n.at.x),Number(n.at.y),Number(n.at.rotation??0)]:[0,-3,0],layer:n?.layer??"F.SilkS",uuid:kf(`${e}-property-Reference`),effects:sz(n?.effects),hidden:n?.hide}));const o=A.properties.Value,s=o?.value??A.footprintName??"";i.push(new iS({key:"Value",value:s,position:o?.at?[Number(o.at.x),Number(o.at.y),Number(o.at.rotation??0)]:[0,3,0],layer:o?.layer??"F.Fab",uuid:kf(`${e}-property-Value`),effects:sz(o?.effects),hidden:o?.hide}));const r=A.properties.Datasheet;i.push(new iS({key:"Datasheet",value:r?.value??"",position:r?.at?[Number(r.at.x),Number(r.at.y),Number(r.at.rotation??0)]:[0,0,0],layer:r?.layer??"F.Fab",uuid:kf(`${e}-property-Datasheet`),effects:sz(r?.effects),hidden:r?.hide??!0}));const a=A.properties.Description;i.push(new iS({key:"Description",value:a?.value??"",position:a?.at?[Number(a.at.x),Number(a.at.y),Number(a.at.rotation??0)]:[0,0,0],layer:a?.layer??"F.Fab",uuid:kf(`${e}-property-Description`),effects:sz(a?.effects),hidden:a?.hide??!0})),t.properties=i}if(A.attributes&&(t.attr||(t.attr=new SmA),A.attributes.through_hole?t.attr.type="through_hole":A.attributes.smd&&(t.attr.type="smd"),A.attributes.exclude_from_pos_files!==void 0&&(t.attr.excludeFromPosFiles=A.attributes.exclude_from_pos_files),A.attributes.exclude_from_bom!==void 0&&(t.attr.excludeFromBom=A.attributes.exclude_from_bom)),A.footprintName&&(t.libraryLink=A.footprintName),A.layer&&(t.layer=A.layer),A.embeddedFonts!==void 0&&(t.embeddedFonts=new R1(A.embeddedFonts)),A.model){const i=new Zj(A.model.path);A.model.offset&&(i.offset={x:Number(A.model.offset.x),y:Number(A.model.offset.y),z:Number(A.model.offset.z)}),A.model.scale&&(i.scale={x:Number(A.model.scale.x),y:Number(A.model.scale.y),z:Number(A.model.scale.z)}),A.model.rotate&&(i.rotate={x:Number(A.model.rotate.x),y:Number(A.model.rotate.y),z:Number(A.model.rotate.z)});const n=t.models||[];t.models=[i,...n]}}function Xoi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.SilkS",bottom:"B.SilkS"}[i.layer]||i.layer||"F.SilkS",a=new gwA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new tS,fill:!1});a.stroke&&(a.stroke.width=i.stroke_width||.05,a.stroke.type="default"),e.push(a)}return e}function $oi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),r={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",a=new gwA({center:{x:n,y:o},end:{x:n+i.radius,y:o},layer:r,stroke:new tS,fill:!1});a.stroke&&(a.stroke.width=.05,a.stroke.type="default"),e.push(a)}return e}function Asi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.Fab",bottom:"B.Fab"}[i.layer]||i.layer||"F.Fab",c=new Oj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new tS,fill:!1});c.stroke&&(c.stroke.width=i.stroke_width||.1,c.stroke.type="default"),e.push(c)}return e}function esi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,a="F.Fab",g=new Oj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:a,stroke:new tS,fill:!1});g.stroke&&(g.stroke.width=i.stroke_width||.1,g.stroke.type="default"),e.push(g)}return e}function tsi(t,A){const e=[];for(const i of t){const n=i.center.x-A.x,o=-(i.center.y-A.y),s=i.width/2,r=i.height/2,g={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",c=new Oj({start:{x:n-s,y:o-r},end:{x:n+s,y:o+r},layer:g,stroke:new tS,fill:!1});c.stroke&&(c.stroke.width=.05,c.stroke.type="default"),e.push(c)}return e}function isi(t,A){const e=[];for(const i of t){if(!i.outline||i.outline.length<2)continue;const o={top:"F.CrtYd",bottom:"B.CrtYd"}[i.layer]||"F.CrtYd",s=i.outline.map(g=>{const c=g.x-A.x,I=-(g.y-A.y);return new JQ(c,I)}),r=new Lhe;r.points=new KC(s),r.layer=o,r.fill=!1;const a=new tS;a.width=.05,a.type="default",r.stroke=a,e.push(r)}return e}function nsi({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,n=-(t.anchor_position.y-A.y),o=e!==0?Lm(e*Math.PI/180):Nu(),s=Pt(o,{x:i,y:n}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",c=(t.font_size||1)/1.5,I=new W0;I.size={width:c,height:c};const l=new O0({font:I}),B=t.ccw_rotation||0;return new $mA({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}function osi(t,A,e,i){const n=[];for(const o of t){const s=nsi({textElement:o,componentCenter:A,componentRotation:e});s&&(i&&o.text===i&&(s.type="reference"),n.push(s))}return n}function ssi(t,A,e){const i=[];for(const n of t){const o=n.anchor_position.x-A.x,s=-(n.anchor_position.y-A.y),r=e!==0?Lm(e*Math.PI/180):Nu(),a=Pt(r,{x:o,y:s}),g=n.font_size||1,c=new W0;c.size={width:g,height:g};const I=new O0({font:c}),l=new $mA({type:"user",text:n.text,position:{x:a.x,y:a.y,angle:0},layer:"F.Fab",effects:I});i.push(l)}return i}function rsi(t,A){const e=[],i=t.model_step_url||t.model_wrl_url;if(!i)return e;const n=new Zj(i);if(t.position&&(n.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:t.position.z||0}),t.rotation&&(n.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const o=t.model_unit_to_mm_scale_factor;n.scale={x:o,y:o,z:o}}return e.push(n),e}function asi({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){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,p)=>d+p.x,0)/u.length,r=u.reduce((d,p)=>d+p.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=sB(i!==0?Lm(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},fh(1,-1),Qr(-A.x,-A.y)),g=Pt(a,{x:s,y:r}),I={top:"F.Cu",bottom:"B.Cu"}[t.layer]||"F.Cu";let l,B,C,Q;if(t.shape==="circle")l="circle",B=["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=sB(fh(1,-1),Qr(-s,-r)),p=u.map(D=>{const w=Pt(d,{x:D.x,y:D.y});return new JQ(w.x,w.y)}),m=new ZmA;m.contours=[new KC(p)],m.width=0,m.filled=!0,Q=new phe,Q.addGraphic(m),l="custom",C=new ihe,C.anchor="circle",B=[.2,.2]}else l="rect",B=["width"in t?t.width:.5,"height"in t?t.height:.5];const h=`pad:${o}:${e}:${g.x},${g.y}`,E=new qj({number:String(e),padType:"smd",shape:l,at:[g.x,g.y,0],size:B,layers:[`${I}`,`${I==="F.Cu"?"F":"B"}.Paste`,`${I==="F.Cu"?"F":"B"}.Mask`],uuid:kf(h)});return C&&(E.options=C),Q&&(E.primitives=Q),n&&(E.net=new TmA(n.id,n.name)),E}function gsi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=asi({pcbPad:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});s.push(c),r++}return{pads:s,nextPadNumber:r}}function csi({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:n,componentId:o}){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):Nu(),g=Pt(a,{x:s,y:r});let c="circle",I,l,B=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=Pt(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(c="circle",I=[t.outer_diameter,t.outer_diameter],l=new nS({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(c="oval",I=[t.outer_width,t.outer_height],l=new nS({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new nS({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q})):t.shape==="circular_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new nS({diameter:t.hole_diameter,offset:Q})):t.shape==="rotated_pill_hole_with_rect_pad"?(c="rect",I=[t.rect_pad_width,t.rect_pad_height],l=new nS({oval:!0,diameter:t.hole_width,width:t.hole_height,offset:Q}),B=t.rect_ccw_rotation||0):(c="circle",I=[1.6,1.6],l=new nS({diameter:.8,offset:Q}));const h=`thruhole:${o}:${e}:${g.x},${g.y}`,E=new qj({number:String(e),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:kf(h)});return n&&(E.net=new TmA(n.id,n.name)),E}function Isi(t,A,e,i,n,o){const s=[];let r=n;for(const a of t){const g=o(a.pcb_port_id),c=csi({platedHole:a,componentCenter:A,padNumber:r,componentRotation:e,netInfo:g,componentId:i});c&&(s.push(c),r++)}return{pads:s,nextPadNumber:r}}function lsi({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,n=-(t.y-A.y),o=e!==0?Lm(e*Math.PI/180):Nu(),s=Pt(o,{x:i,y:n});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const c=t.hole_diameter;a=[c,c],g=new nS({diameter:c})}else if(t.hole_shape==="oval"){r="oval";const c=t.hole_width,I=t.hole_height;a=[c,I],g=new nS({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in t?t.hole_diameter:1;a=[c,c],g=new nS({diameter:c})}return new qj({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 Bsi(t,A,e){const i=[];for(const n of t){const o=lsi({pcbHole:n,componentCenter:A,componentRotation:e});o&&i.push(o)}return i}var Csi=class extends YE{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 n=i.subcircuit_connectivity_map_key;if(n)return this.ctx.pcbNetMap?.get(n)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}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,n=this.getCadComponentForPcbComponent(e.pcb_component_id),o=i?VG(i,n):"Unknown",s=Pt(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new DwA({libraryLink:`tscircuit:${o}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:kf(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];g.push(...osi(c,e.center,e.rotation||0,i?.name));const I=this.ctx.db.pcb_note_text?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];g.push(...ssi(I,e.center,e.rotation||0)),a.fpTexts=g;const l=a.fpPads,B=H=>this.getNetInfoForPcbPort(H),C=this.ctx.db.pcb_smtpad?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],{pads:Q,nextPadNumber:h}=gsi(C,e.center,e.rotation||0,e.pcb_component_id,1,B);l.push(...Q);const E=this.ctx.db.pcb_plated_hole?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],{pads:u}=Isi(E,e.center,e.rotation||0,e.pcb_component_id,h,B);l.push(...u);const d=this.ctx.db.pcb_hole?.list().filter(H=>H.subcircuit_id===e.subcircuit_id)||[],p=Bsi(d,e.center,e.rotation||0);l.push(...p),a.fpPads=l;const m=this.ctx.db.pcb_silkscreen_circle?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],D=a.fpCircles??[];D.push(...Xoi(m,e.center));const w=this.ctx.db.pcb_courtyard_circle?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];D.push(...$oi(w,e.center)),a.fpCircles=D;const S=this.ctx.db.pcb_fabrication_note_rect?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],k=a.fpRects??[];k.push(...Asi(S,e.center));const x=this.ctx.db.pcb_note_rect?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];k.push(...esi(x,e.center));const N=this.ctx.db.pcb_courtyard_rect?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[];k.push(...tsi(N,e.center)),a.fpRects=k;const M=this.ctx.db.pcb_courtyard_outline?.list().filter(H=>H.pcb_component_id===e.pcb_component_id)||[],L=isi(M,e.center);if(L.length>0&&(a.fpPolys=L),n){const H=rsi(n,e.center);H.length>0&&(a.models=H)}if(this.ctx.footprintMetadataMap&&i?.name){const H=iz(i.name),O=this.ctx.footprintMetadataMap.get(H);O&&zoi(a,O,i.name)}const Y=t.footprints;Y.push(a),t.footprints=Y,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},Qsi={top:"F.Cu",bottom:"B.Cu",inner1:"In1.Cu",inner2:"In2.Cu",inner3:"In3.Cu",inner4:"In4.Cu",inner5:"In5.Cu",inner6:"In6.Cu"};function hsi(t){return t&&(Qsi[t]||t)||"F.Cu"}function Esi(t){const A=["F.Cu"];for(let e=1;e<t-1;e++)A.push(`In${e}.Cu`);return A.push("B.Cu"),A}var usi=class extends YE{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}let n=i.route[0]?.layer;for(let o=0;o<i.route.length-1;o++){const s=i.route[o],r=i.route[o+1],a=Pt(A,{x:s.x,y:s.y}),g=Pt(A,{x:r.x,y:r.y});let c;if(e){let h=i.subcircuit_connectivity_map_key;if(!h&&i.source_trace_id){const E=this.ctx.db.source_trace?.get(i.source_trace_id);if(E&&(h=E.subcircuit_connectivity_map_key,!h&&E.connected_source_net_ids?.length))for(const u of E.connected_source_net_ids){const d=this.ctx.db.source_net?.get(u);if(d?.subcircuit_connectivity_map_key){h=d.subcircuit_connectivity_map_key;break}}}if(!h&&typeof i.connection_name=="string"){const E=this.ctx.db.source_net?.get(i.connection_name);E?.subcircuit_connectivity_map_key&&(h=E.subcircuit_connectivity_map_key)}h&&(c=e.get(h))}const I=s.layer??r.layer??n,l=hsi(I),B=`segment:${a.x},${a.y}:${g.x},${g.y}:${l}:${c?.id??0}`,C=new UwA({start:{x:a.x,y:a.y},end:{x:g.x,y:g.y},layer:l,width:i.width||.25,net:new $j(c?.id??0),uuid:kf(B)}),Q=t.segments;Q.push(C),t.segments=Q,s.layer&&(n=s.layer),r.layer&&(n=r.layer)}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},dsi=class extends YE{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],n=Pt(A,{x:i.x,y:i.y});let o;if(e){let I=i.subcircuit_connectivity_map_key;if(!I&&i.pcb_trace_id){const l=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(l&&("subcircuit_connectivity_map_key"in l&&(I=l.subcircuit_connectivity_map_key),!I&&l.source_trace_id)){const B=this.ctx.db.source_trace?.get(l.source_trace_id);if(B&&("subcircuit_connectivity_map_key"in B&&(I=B.subcircuit_connectivity_map_key),!I&&B.connected_source_net_ids?.length))for(const C of B.connected_source_net_ids){const Q=this.ctx.db.source_net?.get(C);if(Q?.subcircuit_connectivity_map_key){I=Q.subcircuit_connectivity_map_key;break}}}}if(!I&&i.connection_name){const l=this.ctx.db.source_net?.get(i.connection_name);l?.subcircuit_connectivity_map_key&&(I=l.subcircuit_connectivity_map_key)}I&&(o=e.get(I))}const s=this.ctx.numLayers??2,r=i.layers?i.layers.map(I=>I==="top"?"F.Cu":I==="bottom"?"B.Cu":`In${I.replace("inner","")}.Cu`):Esi(s),a=`via:${n.x},${n.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${o?.id??0}`,g=new MDA({at:[n.x,n.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:r,net:new RDA(o?.id??0),uuid:kf(a)}),c=t.vias;c.push(g),t.vias=c,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function psi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Pt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.Fab",bottom:"B.Fab"}[t.layer]||t.layer||"F.Fab",o=(t.font_size||1)/1.5,s=new W0;s.size={width:o,height:o};const r=new jJ,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 O0({font:s});a!=="center"&&(g.justify=r);const c=new zg([e.x,e.y,0]),I=new Xj({text:t.text,layer:n,effects:g});return I.position=c,I}function fsi({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Pt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),n={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",o=(t.font_size||1)/1.5,s=new W0;s.size={width:o,height:o};const r=new jJ,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 O0({font:s});a!=="center"&&(g.justify=r);const c=t.ccw_rotation||0,I=new zg([e.x,e.y,c]),l=new Xj({text:t.text,layer:n,effects:g});return l.position=I,l}var ysi=class extends YE{_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 s of e)if(!(!s.route||s.route.length<2))for(let r=0;r<s.route.length-1;r++){const a=s.route[r],g=s.route[r+1];if(!a||!g)continue;const c=Pt(A,{x:a.x,y:a.y}),I=Pt(A,{x:g.x,y:g.y}),B={top:"F.SilkS",bottom:"B.SilkS"}[s.layer]||s.layer||"F.SilkS",C=new zj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:B,width:s.stroke_width||.15}),Q=t.graphicLines;Q.push(C),t.graphicLines=Q}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(s=>!s.pcb_component_id)||[];for(const s of i){const r=fsi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const n=this.ctx.db.pcb_fabrication_note_text?.list()||[];for(const s of n){const r=psi({textElement:s,c2kMatPcb:A});if(r){const a=t.graphicTexts;a.push(r),t.graphicTexts=a}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const s=o[0];if(!s){this.finished=!0;return}let r;if(s.outline&&s.outline.length>0)r=s.outline;else{const g=s.width?s.width/2:0,c=s.height?s.height/2:0;r=[{x:s.center.x-g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y-c},{x:s.center.x+g,y:s.center.y+c},{x:s.center.x-g,y:s.center.y+c}]}const a=r.map(g=>Pt(A,g));for(let g=0;g<a.length;g++){const c=a[g],I=a[(g+1)%a.length];if(!c||!I)continue;const l=new zj({start:{x:c.x,y:c.y},end:{x:I.x,y:I.y},layer:"Edge.Cuts",width:.1}),B=t.graphicLines;B.push(l),t.graphicLines=B}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},hue=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t,A){this.ctx={db:Ga(t),circuitJson:t,kicadPcb:new NDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:sB(Qr(100,100),fh(1,-1)),footprintMetadataMap:A?.footprintMetadataMap},this.pipeline=[new Zoi(t,this.ctx),new Voi(t,this.ctx),new Csi(t,this.ctx),new usi(t,this.ctx),new dsi(t,this.ctx),new ysi(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()}},msi=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,n=A.pcbFilename??`${e}.kicad_pcb`,o=new Date().toISOString();this.ctx={db:Ga(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:o,modified:o},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:n},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5827
5827
|
`}},wsi=class extends YE{_step(){const t=new Que(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new hue(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},Dsi=class extends YE{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 n=cue(t).find(r=>r instanceof DmA);if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const o=n.libSymbols;if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const s=o.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),a||this.snapPinPositionsToGrid(r),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 n=i.value.split(":");n.length>1?i.value=`${A}:${n[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"}snapPinPositionsToGrid(t){for(const e of t.subSymbols??[]){for(const i of e.pins??[])i.at&&(i.at.x=Math.round(i.at.x/1.27)*1.27,i.at.y=Math.round(i.at.y/1.27)*1.27);for(const i of e.polylines??[])if(i.points?.points)for(const n of i.points.points)"x"in n&&"y"in n&&(n.x=Math.round(n.x/1.27)*1.27,n.y=Math.round(n.y/1.27)*1.27)}}getOutput(){return this.ctx.libraryOutput}},Ssi=20240108,bsi="pcbnew",xsi="8.0";function _si(t){const A=t.split(/[/\\]/);return A[A.length-1]||t}var ksi=class extends YE{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 n=i.source_component_id?e?.get(i.source_component_id):null;if(n){const o=VG(n,i);t.add(o)}}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 o=cue(t).find(r=>r instanceof NDA);if(!o){this.ctx.footprintEntries=[],this.finished=!0;return}const s=o.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(n){console.warn("Failed to parse PCB for footprint extraction:",n)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e}){const n=(t.libraryLink??"footprint").split(":"),o=(n.length>1?n[1]:n[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!e.has(o);if(t.libraryLink=o,t.position=zg.from([0,0,0]),t.locked=!1,t.placed=!1,t.version=Ssi,t.generator=bsi,t.generatorVersion=xsi,t.descr||(t.descr=""),t.tags||(t.tags=""),t.embeddedFonts||(t.embeddedFonts=new R1(!1)),!t.attr){const d=new SmA,p=(t.fpPads??[]).map(m=>m.padType);p.some(m=>m.includes("thru_hole"))?d.type="through_hole":p.some(m=>m.includes("smd"))&&(d.type="smd"),t.attr=d}t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0;const r=new W0;r.size={width:1.27,height:1.27},r.thickness=.15;const a=new O0({font:r}),g=t.fpPads??[];let c=0,I=0;for(const d of g){const p=d.at,m=d.size;if(p&&m){const D=p.y??0,w=m.height??0,S=D-w/2,k=D+w/2;c=Math.min(c,S),I=Math.max(I,k)}}const l=c-.5,B=I+.5;t.properties=[new iS({key:"Reference",value:"REF**",position:[0,l,0],layer:"F.SilkS",uuid:kf(`${o}-property-Reference`),effects:a}),new iS({key:"Value",value:"Val**",position:[0,B,0],layer:"F.Fab",uuid:kf(`${o}-property-Value`),effects:a}),new iS({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:kf(`${o}-property-Datasheet`),effects:a}),new iS({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:kf(`${o}-property-Description`),effects:a})];const C=t.fpTexts??[];for(const d of C)d.uuid=void 0,d.type==="reference"?d.text="REF**":d.type==="value"&&d.text.trim().length===0&&(d.text=o);t.fpTexts=C;const Q=t.fpPads??[];for(let d=0;d<Q.length;d++){const p=Q[d];p&&(p.uuid=kf(`${o}-pad-${p.number??d}`),p.net=void 0)}t.fpPads=Q;const h=t.models??[],E=[],u=[];for(const d of h)if(d.path){const p=_si(d.path),m=`../../3dmodels/${A}.3dshapes/${p}`,D=new Zj(m);d.offset&&(D.offset=d.offset),d.scale&&(D.scale=d.scale),d.rotate&&(D.rotate=d.rotate),E.push(D),u.push(d.path)}return t.models=E,{footprintName:o,kicadModString:t.getString(),model3dSourcePaths:u,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},Fsi=20211014,Gsi="circuit-json-to-kicad",Rsi=class extends YE{_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 kQe({version:Fsi,generator:Gsi,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},Msi=class extends YE{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],n=new Set;for(const r of e)for(const a of r.model3dSourcePaths)n.add(a);const o=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=o,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(n),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
|
|
5828
5828
|
(version 7)
|
|
5829
5829
|
(lib (name "${t}") (type "KiCad") (uri "\${KIPRJMOD}/${t}.pretty") (options "") (descr "Generated by circuit-json-to-kicad"))
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tscircuit/runframe",
|
|
3
3
|
"main": "dist/preview.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.1628",
|
|
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.47",
|
|
71
71
|
"circuit-json-to-gltf": "^0.0.56",
|
|
72
|
-
"circuit-json-to-kicad": "^0.0.
|
|
72
|
+
"circuit-json-to-kicad": "^0.0.74",
|
|
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.18",
|