tscircuit 0.0.1231 → 0.0.1232-libonly
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.min.js +2 -2
- package/package.json +3 -9
- package/cli.mjs +0 -14
package/dist/browser.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:o,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:n,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"})]})]})},YIe=t=>t.activeSubSolver?[t,...YIe(t.activeSubSolver)]:[t],mXt=({solver:t})=>{const A=YIe(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(yXt,{solver:e})]},e.constructor.name))})},wXt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,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(),o&&o(t))},c=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},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||n)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&&o&&o(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);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(mXt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),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]})]})},DXt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},SXt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=DXt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="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 o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;o==="Completed"?c=1:o==="In Progress"&&n&&(c=n.progress??0);const I=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:n??null}},bXt=({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})},_Xt=({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,"%"]})]})},xXt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),kXt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=xXt(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,o])=>W.jsxs("div",{children:[i,": ",String(o)]},i))})]})},s0A=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(s0A);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=s0A(i));return A},FXt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=s0A(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},GXt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>SXt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):FXt(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:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children: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(bXt,{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(_Xt,{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(kXt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[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))})]})})]})},RXt=class extends no.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 vXt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const 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,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of o){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 n)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}`)),o.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}`)),n.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 MXt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=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,o]),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();n()}};return W.jsxs("div",{children:[W.jsx(wXt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(RXt,{fallback:W.jsx(vXt,{graphics:s}),children:W.jsx(fXt,{graphics:s})}),a&&W.jsx(GXt,{solver:t,onStepUntilPhase:g})]})};const NXt=()=>{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)},[])},LXt=t=>t.toLowerCase().includes("pack")?j1t:t.toLowerCase().includes("rout")?e2t:M1t,UXt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);NXt();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]),o=V.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=V.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=enA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(enA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.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=LXt(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:n?s.instance?W.jsx(Oy,{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"," ",n.solverName]})]})}),children:W.jsx(MXt,{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:n.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.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(n.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"})})})]})},JIe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{q5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{q5.captureException(o,{error_type:i.type})}catch{}}},[e])},TIe="0.0.1547",HXt={version:TIe},ij=LYA()(UYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),YXt=t=>{const[A,e]=V.useState([]),[i,o]=V.useState(null),[n,s]=V.useState(""),[r,a]=I1("eval-version-selection",null),g=ij(B=>B.setLastRunEvalVersion),c=ij(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&&(o(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(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:c,search:n,setSearch:s,selectVersion:B=>{a(B),s("")}}},JXt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=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?n(a[0]):g&&n(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 ${o===I?"bg-blue-50":""}`,onClick:()=>n(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 ${o===s?"bg-blue-50":""}`,onClick:()=>n(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:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},TXt=t=>{const A=V.useRef(null),e=jI(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 KXt(t){const A=PXt(t),e=V.forwardRef((i,o)=>{const{children:n,...s}=i,r=V.Children.toArray(n),a=r.find(OXt);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:o,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function PXt(t){const A=V.forwardRef((e,i)=>{const{children:o,...n}=e;if(V.isValidElement(o)){const s=ZXt(o),r=WXt(n,o.props);return o.type!==V.Fragment&&(r.ref=i?cf(i,s):s),V.cloneElement(o,r)}return V.Children.count(o)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var qXt=Symbol("radix.slottable");function OXt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===qXt}function WXt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function ZXt(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 oj="Dialog",[KIe,PIe]=Km(oj),[VXt,Ew]=KIe(oj),qIe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=q_({prop:i,defaultProp:o??!1,onChange:n,caller:oj});return W.jsx(VXt,{scope:A,triggerRef:r,contentRef:a,contentId:_E(),titleId:_E(),descriptionId:_E(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};qIe.displayName=oj;var OIe="DialogTrigger",WIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(OIe,e),n=yI(A,o.triggerRef);return W.jsx(ja.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":g0A(o.open),...i,ref:n,onClick:To(t.onClick,o.onOpenToggle)})});WIe.displayName=OIe;var r0A="DialogPortal",[jXt,ZIe]=KIe(r0A,{forceMount:void 0}),VIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Ew(r0A,A);return W.jsx(jXt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(f0,{present:e||n.open,children:W.jsx(AV,{asChild:!0,container:o,children:s})}))})};VIe.displayName=r0A;var nj="DialogOverlay",jIe=V.forwardRef((t,A)=>{const e=ZIe(nj,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(nj,t.__scopeDialog);return n.modal?W.jsx(f0,{present:i||n.open,children:W.jsx(XXt,{...o,ref:A})}):null});jIe.displayName=nj;var zXt=KXt("DialogOverlay.RemoveScroll"),XXt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(nj,e);return W.jsx(aV,{as:zXt,allowPinchZoom:!0,shards:[o.contentRef],children:W.jsx(ja.div,{"data-state":g0A(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),JG="DialogContent",zIe=V.forwardRef((t,A)=>{const e=ZIe(JG,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(JG,t.__scopeDialog);return W.jsx(f0,{present:i||n.open,children:n.modal?W.jsx($Xt,{...o,ref:A}):W.jsx(A6t,{...o,ref:A})})});zIe.displayName=JG;var $Xt=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(null),o=yI(A,e.contentRef,i);return V.useEffect(()=>{const n=i.current;if(n)return rdA(n)},[]),W.jsx(XIe,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:To(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:To(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:To(t.onFocusOutside,n=>n.preventDefault())})}),A6t=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(!1),o=V.useRef(!1);return W.jsx(XIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),XIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Ew(JG,e),a=V.useRef(null),g=yI(A,a);return TuA(),W.jsxs(W.Fragment,{children:[W.jsx(JZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:W.jsx(aY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":g0A(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(t6t,{titleId:r.titleId}),W.jsx(o6t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),a0A="DialogTitle",$Ie=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(a0A,e);return W.jsx(ja.h2,{id:o.titleId,...i,ref:A})});$Ie.displayName=a0A;var Ale="DialogDescription",ele=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(Ale,e);return W.jsx(ja.p,{id:o.descriptionId,...i,ref:A})});ele.displayName=Ale;var tle="DialogClose",ile=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(tle,e);return W.jsx(ja.button,{type:"button",...i,ref:A,onClick:To(t.onClick,()=>o.onOpenChange(!1))})});ile.displayName=tle;function g0A(t){return t?"open":"closed"}var ole="DialogTitleWarning",[e6t,nle]=R6e(ole,{contentName:JG,titleName:a0A,docsSlug:"dialog"}),t6t=({titleId:t})=>{const A=nle(ole),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:o,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:n,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"})]})]})},YIe=t=>t.activeSubSolver?[t,...YIe(t.activeSubSolver)]:[t],mXt=({solver:t})=>{const A=YIe(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(yXt,{solver:e})]},e.constructor.name))})},wXt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,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(),o&&o(t))},c=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&t.solved&&o(t);return}t.step(),A()},e))},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||n)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&&o&&o(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,n]);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(mXt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),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]})]})},DXt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},SXt=(t,A)=>{const i=t.pipelineDef[A].solverName,o=DXt(t,A),n=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(o==="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 o==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;o==="Completed"?c=1:o==="In Progress"&&n&&(c=n.progress??0);const I=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:n??null}},bXt=({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})},_Xt=({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,"%"]})]})},xXt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),kXt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=xXt(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,o])=>W.jsxs("div",{children:[i,": ",String(o)]},i))})]})},s0A=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(s0A);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=s0A(i));return A},FXt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=s0A(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},GXt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>SXt(t,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):FXt(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:()=>o(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children: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(bXt,{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(_Xt,{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(kXt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[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))})]})})]})},RXt=class extends no.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 vXt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],o=t.circles??[],n=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const 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,f=h.height??0;c(E,u),c(E+d,u+f)}for(const h of o){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 n)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}`)),o.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}`)),n.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 MXt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[o,n]=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,o]),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();n()}};return W.jsxs("div",{children:[W.jsx(wXt,{solver:t,triggerRender:n,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(RXt,{fallback:W.jsx(vXt,{graphics:s}),children:W.jsx(fXt,{graphics:s})}),a&&W.jsx(GXt,{solver:t,onStepUntilPhase:g})]})};const NXt=()=>{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)},[])},LXt=t=>t.toLowerCase().includes("pack")?j1t:t.toLowerCase().includes("rout")?e2t:M1t,UXt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);NXt();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]),o=V.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=V.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=enA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(enA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return t.length===0?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:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.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=LXt(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:n?s.instance?W.jsx(Oy,{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"," ",n.solverName]})]})}),children:W.jsx(MXt,{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:n.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.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(n.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"})})})]})},JIe=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{q5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{q5.captureException(o,{error_type:i.type})}catch{}}},[e])},TIe="0.0.1548",HXt={version:TIe},ij=LYA()(UYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),YXt=t=>{const[A,e]=V.useState([]),[i,o]=V.useState(null),[n,s]=V.useState(""),[r,a]=I1("eval-version-selection",null),g=ij(B=>B.setLastRunEvalVersion),c=ij(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&&(o(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(n)).slice(0,50),[A,n]),latestVersion:i,lastRunEvalVersion:c,search:n,setSearch:s,selectVersion:B=>{a(B),s("")}}},JXt=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[o,n]=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?n(a[0]):g&&n(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 ${o===I?"bg-blue-50":""}`,onClick:()=>n(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 ${o===s?"bg-blue-50":""}`,onClick:()=>n(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:()=>o&&A(o),disabled:!o,children:o===s?`Create "${o}"`:`Save to ${o}`})]})]})})},TXt=t=>{const A=V.useRef(null),e=jI(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 KXt(t){const A=PXt(t),e=V.forwardRef((i,o)=>{const{children:n,...s}=i,r=V.Children.toArray(n),a=r.find(OXt);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:o,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:o,children:n})});return e.displayName=`${t}.Slot`,e}function PXt(t){const A=V.forwardRef((e,i)=>{const{children:o,...n}=e;if(V.isValidElement(o)){const s=ZXt(o),r=WXt(n,o.props);return o.type!==V.Fragment&&(r.ref=i?cf(i,s):s),V.cloneElement(o,r)}return V.Children.count(o)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var qXt=Symbol("radix.slottable");function OXt(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===qXt}function WXt(t,A){const e={...A};for(const i in A){const o=t[i],n=A[i];/^on[A-Z]/.test(i)?o&&n?e[i]=(...r)=>{const a=n(...r);return o(...r),a}:o&&(e[i]=o):i==="style"?e[i]={...o,...n}:i==="className"&&(e[i]=[o,n].filter(Boolean).join(" "))}return{...t,...e}}function ZXt(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 oj="Dialog",[KIe,PIe]=Km(oj),[VXt,Ew]=KIe(oj),qIe=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:o,onOpenChange:n,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=q_({prop:i,defaultProp:o??!1,onChange:n,caller:oj});return W.jsx(VXt,{scope:A,triggerRef:r,contentRef:a,contentId:_E(),titleId:_E(),descriptionId:_E(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};qIe.displayName=oj;var OIe="DialogTrigger",WIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(OIe,e),n=yI(A,o.triggerRef);return W.jsx(ja.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":g0A(o.open),...i,ref:n,onClick:To(t.onClick,o.onOpenToggle)})});WIe.displayName=OIe;var r0A="DialogPortal",[jXt,ZIe]=KIe(r0A,{forceMount:void 0}),VIe=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:o}=t,n=Ew(r0A,A);return W.jsx(jXt,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(f0,{present:e||n.open,children:W.jsx(AV,{asChild:!0,container:o,children:s})}))})};VIe.displayName=r0A;var nj="DialogOverlay",jIe=V.forwardRef((t,A)=>{const e=ZIe(nj,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(nj,t.__scopeDialog);return n.modal?W.jsx(f0,{present:i||n.open,children:W.jsx(XXt,{...o,ref:A})}):null});jIe.displayName=nj;var zXt=KXt("DialogOverlay.RemoveScroll"),XXt=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(nj,e);return W.jsx(aV,{as:zXt,allowPinchZoom:!0,shards:[o.contentRef],children:W.jsx(ja.div,{"data-state":g0A(o.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),JG="DialogContent",zIe=V.forwardRef((t,A)=>{const e=ZIe(JG,t.__scopeDialog),{forceMount:i=e.forceMount,...o}=t,n=Ew(JG,t.__scopeDialog);return W.jsx(f0,{present:i||n.open,children:n.modal?W.jsx($Xt,{...o,ref:A}):W.jsx(A6t,{...o,ref:A})})});zIe.displayName=JG;var $Xt=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(null),o=yI(A,e.contentRef,i);return V.useEffect(()=>{const n=i.current;if(n)return rdA(n)},[]),W.jsx(XIe,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:To(t.onCloseAutoFocus,n=>{n.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:To(t.onPointerDownOutside,n=>{const s=n.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&n.preventDefault()}),onFocusOutside:To(t.onFocusOutside,n=>n.preventDefault())})}),A6t=V.forwardRef((t,A)=>{const e=Ew(JG,t.__scopeDialog),i=V.useRef(!1),o=V.useRef(!1);return W.jsx(XIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{t.onCloseAutoFocus?.(n),n.defaultPrevented||(i.current||e.triggerRef.current?.focus(),n.preventDefault()),i.current=!1,o.current=!1},onInteractOutside:n=>{t.onInteractOutside?.(n),n.defaultPrevented||(i.current=!0,n.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=n.target;e.triggerRef.current?.contains(s)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&o.current&&n.preventDefault()}})}),XIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:o,onCloseAutoFocus:n,...s}=t,r=Ew(JG,e),a=V.useRef(null),g=yI(A,a);return TuA(),W.jsxs(W.Fragment,{children:[W.jsx(JZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:o,onUnmountAutoFocus:n,children:W.jsx(aY,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":g0A(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(t6t,{titleId:r.titleId}),W.jsx(o6t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),a0A="DialogTitle",$Ie=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(a0A,e);return W.jsx(ja.h2,{id:o.titleId,...i,ref:A})});$Ie.displayName=a0A;var Ale="DialogDescription",ele=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(Ale,e);return W.jsx(ja.p,{id:o.descriptionId,...i,ref:A})});ele.displayName=Ale;var tle="DialogClose",ile=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,o=Ew(tle,e);return W.jsx(ja.button,{type:"button",...i,ref:A,onClick:To(t.onClick,()=>o.onOpenChange(!1))})});ile.displayName=tle;function g0A(t){return t?"open":"closed"}var ole="DialogTitleWarning",[e6t,nle]=R6e(ole,{contentName:JG,titleName:a0A,docsSlug:"dialog"}),t6t=({titleId:t})=>{const A=nle(ole),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
|
`)}};LA.register(Qai);var SEe=class YbA extends LA{static token="locked";static parentToken="group";token="locked";value;constructor(A){super(),this.value=A}static fromSexprPrimitives(A){if(A.length===0)return new YbA(!0);const e=mi(A[0]);return new YbA(e==="yes")}getString(){return this.value?"(locked yes)":"(locked no)"}};LA.register(SEe);var bEe=class Owe extends LA{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 o=mi(i);o&&e.push(o)}return new Owe(e)}getString(){return this.members.length===0?"(members)":`(members ${this.members.map(e=>`"${e}"`).join(" ")})`}};LA.register(bEe);var qwA=class Wwe extends LA{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,o=Ii(e),n=Ii(i);if(o===void 0||n===void 0)throw new Error("end expects two numeric arguments");return new Wwe(o,n)}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})`}};LA.register(qwA);var hai=new Set(["true","yes","1"]),_Ee=class qX 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 qX(e):typeof e=="string"?new qX(hai.has(e.toLowerCase())):new qX(!1)}getString(){return`(locked ${this.value?"yes":"no"})`}};LA.register(_Ee);var gz=class Zwe extends LA{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,o=Ii(e);if(o===void 0)throw new Error("net expects a numeric identifier");const n=i===void 0?void 0:mi(i);return new Zwe(o,n??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?` ${ho(this._name)}`:"";return`(net ${this._id}${A})`}};LA.register(gz);var OwA=class Vwe extends LA{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,o=Ii(e),n=Ii(i);if(o===void 0||n===void 0)throw new Error("start expects two numeric arguments");return new Vwe(o,n)}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})`}};LA.register(OwA);var xEe=new Set(["start","end","width","layer","net","tstamp","uuid","locked"]),WwA=class jwe extends LA{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 jwe,{propertyMap:i,arrayPropertyMap:o}=LA.parsePrimitivesToClassProperties(A,this.token),n=Object.keys(i).filter(r=>!xEe.has(r));if(n.length>0)throw new Error(`Unsupported child tokens inside segment expression: ${n.join(", ")}`);for(const[r,a]of Object.entries(o)){if(!xEe.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=o.start?.[0]??i.start,e._sxEnd=o.end?.[0]??i.end,e._sxWidth=o.width?.[0]??i.width,e._sxLayer=o.layer?.[0]??i.layer,e._sxNet=o.net?.[0]??i.net;const s=o.locked?.[0]??i.locked;return e._sxLocked=s&&s.value?s:void 0,e._sxTstamp=o.tstamp?.[0]??i.tstamp,e._sxUuid=o.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 Nr?A:new Nr(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 Sr){this._sxLayer=A;return}const e=Array.isArray(A)?A:[A];this._sxLayer=new Sr(e)}get net(){return this._sxNet}set net(A){if(A===void 0){this._sxNet=void 0;return}if(A instanceof gz){this._sxNet=A;return}this._sxNet=new gz(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 ic?A:new ic(A)}get uuid(){return this._sxUuid}set uuid(A){if(A===void 0){this._sxUuid=void 0;return}this._sxUuid=A instanceof Yi?A:new Yi(A)}get locked(){return this._sxLocked?.value??!1}set locked(A){this._sxLocked=A?new _Ee(!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 OwA?A:new OwA(A.x,A.y)}normalizeEnd(A){if(A!==void 0)return A instanceof qwA?A:new qwA(A.x,A.y)}};LA.register(WwA);var kEe=class zwe extends LA{static token="zone";token="zone";_rawChildren=[];static fromSexprPrimitives(A){const e=new zwe;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(` ${Mh(e)}`);return A.push(")"),A.join(`
|
|
5824
5824
|
`)}};LA.register(kEe);var cz=class Xwe extends LA{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):Mh(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:ho(e)).join(" ")})`}};LA.register(cz);var rT=class extends LA{_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=mi(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?ho(this._value):this._value:`${this._value}`}getString(){return`(${this.token} ${this.formatValue()})`}},Eai=class extends LA{_values;constructor(t){super(),this._values=t}static fromSexprPrimitives(t){const A=t.map(i=>{const o=Ii(i);if(o===void 0)throw new Error(`${this.name} expects numeric primitives but received ${i}`);return o}),e=this;return new e(A)}get values(){return[...this._values]}set values(t){this._values=[...t]}getChildren(){return[]}getString(){return`(${this.token} ${this._values.join(" ")})`}},uai=class extends LA{_x;_y;constructor(t,A){super(),this._x=t,this._y=A}static fromSexprPrimitives(t){const[A,e]=t,i=Ii(A),o=Ii(e);if(i===void 0||o===void 0)throw new Error(`${this.name} expects two numeric values`);const n=this;return new n(i,o)}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}getChildren(){return[]}getString(){return`(${this.token} ${this._x} ${this._y})`}},br=class extends rT{static parentToken="pcbplotparams"},am=class extends br{static parsePrimitiveValue(t){const A=Ii(t);if(A===void 0)throw new Error(`pcbplotparams ${this.token} expects a numeric value`);return A}},FEe=class extends br{static token="layerselection";token="layerselection"};LA.register(FEe);var GEe=class extends br{static token="plot_on_all_layers_selection";token="plot_on_all_layers_selection"};LA.register(GEe);var REe=class extends am{static token="dashed_line_dash_ratio";token="dashed_line_dash_ratio"};LA.register(REe);var vEe=class extends am{static token="dashed_line_gap_ratio";token="dashed_line_gap_ratio"};LA.register(vEe);var MEe=class extends am{static token="svgprecision";token="svgprecision"};LA.register(MEe);var NEe=class extends am{static token="linewidth";token="linewidth"};LA.register(NEe);var LEe=class extends am{static token="mode";token="mode"};LA.register(LEe);var UEe=class extends am{static token="hpglpennumber";token="hpglpennumber"};LA.register(UEe);var HEe=class extends am{static token="hpglpenspeed";token="hpglpenspeed"};LA.register(HEe);var YEe=class extends am{static token="hpglpendiameter";token="hpglpendiameter"};LA.register(YEe);var JEe=class extends am{static token="hpglpenoverlay";token="hpglpenoverlay"};LA.register(JEe);var TEe=class extends am{static token="outputformat";token="outputformat"};LA.register(TEe);var KEe=class extends am{static token="drillshape";token="drillshape"};LA.register(KEe);var PEe=class extends am{static token="scaleselection";token="scaleselection"};LA.register(PEe);var qEe=class extends br{static token="disableapertmacros";token="disableapertmacros"};LA.register(qEe);var OEe=class extends br{static token="usegerberextensions";token="usegerberextensions"};LA.register(OEe);var WEe=class extends br{static token="usegerberattributes";token="usegerberattributes"};LA.register(WEe);var ZEe=class extends br{static token="usegerberadvancedattributes";token="usegerberadvancedattributes"};LA.register(ZEe);var VEe=class extends br{static token="creategerberjobfile";token="creategerberjobfile"};LA.register(VEe);var jEe=class extends br{static token="excludeedgelayer";token="excludeedgelayer"};LA.register(jEe);var zEe=class extends br{static token="plotframeref";token="plotframeref"};LA.register(zEe);var XEe=class extends br{static token="viasonmask";token="viasonmask"};LA.register(XEe);var $Ee=class extends br{static token="useauxorigin";token="useauxorigin"};LA.register($Ee);var Aue=class extends br{static token="pdf_front_fp_property_popups";token="pdf_front_fp_property_popups"};LA.register(Aue);var eue=class extends br{static token="pdf_back_fp_property_popups";token="pdf_back_fp_property_popups"};LA.register(eue);var tue=class extends br{static token="pdf_metadata";token="pdf_metadata"};LA.register(tue);var iue=class extends br{static token="pdf_single_document";token="pdf_single_document"};LA.register(iue);var oue=class extends br{static token="dxfpolygonmode";token="dxfpolygonmode"};LA.register(oue);var nue=class extends br{static token="dxfimperialunits";token="dxfimperialunits"};LA.register(nue);var sue=class extends br{static token="dxfusepcbnewfont";token="dxfusepcbnewfont"};LA.register(sue);var rue=class extends br{static token="psnegative";token="psnegative"};LA.register(rue);var aue=class extends br{static token="psa4output";token="psa4output"};LA.register(aue);var gue=class extends br{static token="plotreference";token="plotreference"};LA.register(gue);var cue=class extends br{static token="plotvalue";token="plotvalue"};LA.register(cue);var Iue=class extends br{static token="plotothertext";token="plotothertext"};LA.register(Iue);var lue=class extends br{static token="plotinvisibletext";token="plotinvisibletext"};LA.register(lue);var Bue=class extends br{static token="padsonsilk";token="padsonsilk"};LA.register(Bue);var Cue=class extends br{static token="sketchpadsonfab";token="sketchpadsonfab"};LA.register(Cue);var Que=class extends br{static token="plotpadnumbers";token="plotpadnumbers"};LA.register(Que);var hue=class extends br{static token="hidednponfab";token="hidednponfab"};LA.register(hue);var Eue=class extends br{static token="sketchdnponfab";token="sketchdnponfab"};LA.register(Eue);var uue=class extends br{static token="crossoutdnponfab";token="crossoutdnponfab"};LA.register(uue);var due=class extends br{static token="subtractmaskfromsilk";token="subtractmaskfromsilk"};LA.register(due);var pue=class extends br{static token="plot_black_and_white";token="plot_black_and_white"};LA.register(pue);var fue=class extends br{static token="mirror";token="mirror"};LA.register(fue);var yue=class extends br{static token="outputdirectory";token="outputdirectory";quoteStringValue=!0};LA.register(yue);var mue=class extends br{static token="plot_on_all_layers";token="plot_on_all_layers"};LA.register(mue);var wue=class extends br{static token="plotinvisible";token="plotinvisible"};LA.register(wue);var dai={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"},pai=["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"],ZwA=class $we extends LA{static token="pcbplotparams";static parentToken="setup";token="pcbplotparams";_properties={};static fromSexprPrimitives(A){const e=new $we,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[o,n]of Object.entries(i)){const s=dai[o];if(!s)throw new Error(`Unsupported pcbplotparams token: ${o}`);e._properties[s]=n}return e}getChildren(){const A=[];for(const e of pai){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,FEe)}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,GEe)}get disableapertmacros(){return this._properties.disableapertmacros?.value}set disableapertmacros(A){this.setStringProperty("disableapertmacros",A,qEe)}get usegerberextensions(){return this._properties.usegerberextensions?.value}set usegerberextensions(A){this.setStringProperty("usegerberextensions",A,OEe)}get usegerberattributes(){return this._properties.usegerberattributes?.value}set usegerberattributes(A){this.setStringProperty("usegerberattributes",A,WEe)}get usegerberadvancedattributes(){return this._properties.usegerberadvancedattributes?.value}set usegerberadvancedattributes(A){this.setStringProperty("usegerberadvancedattributes",A,ZEe)}get creategerberjobfile(){return this._properties.creategerberjobfile?.value}set creategerberjobfile(A){this.setStringProperty("creategerberjobfile",A,VEe)}get excludeedgelayer(){return this._properties.excludeedgelayer?.value}set excludeedgelayer(A){this.setStringProperty("excludeedgelayer",A,jEe)}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,REe)}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,vEe)}get svgprecision(){return this._properties.svgprecision?.value}set svgprecision(A){this.setNumberProperty("svgprecision",A,MEe)}get linewidth(){return this._properties.linewidth?.value}set linewidth(A){this.setNumberProperty("linewidth",A,NEe)}get plotframeref(){return this._properties.plotframeref?.value}set plotframeref(A){this.setStringProperty("plotframeref",A,zEe)}get plotreference(){return this._properties.plotreference?.value}set plotreference(A){this.setStringProperty("plotreference",A,gue)}get plotvalue(){return this._properties.plotvalue?.value}set plotvalue(A){this.setStringProperty("plotvalue",A,cue)}get plotothertext(){return this._properties.plotothertext?.value}set plotothertext(A){this.setStringProperty("plotothertext",A,Iue)}get plotinvisibletext(){return this._properties.plotinvisibletext?.value}set plotinvisibletext(A){this.setStringProperty("plotinvisibletext",A,lue)}get padsonsilk(){return this._properties.padsonsilk?.value}set padsonsilk(A){this.setStringProperty("padsonsilk",A,Bue)}get plotpadnumbers(){return this._properties.plotpadnumbers?.value}set plotpadnumbers(A){this.setStringProperty("plotpadnumbers",A,Que)}get sketchpadsonfab(){return this._properties.sketchpadsonfab?.value}set sketchpadsonfab(A){this.setStringProperty("sketchpadsonfab",A,Cue)}get hidednponfab(){return this._properties.hidednponfab?.value}set hidednponfab(A){this.setStringProperty("hidednponfab",A,hue)}get sketchdnponfab(){return this._properties.sketchdnponfab?.value}set sketchdnponfab(A){this.setStringProperty("sketchdnponfab",A,Eue)}get crossoutdnponfab(){return this._properties.crossoutdnponfab?.value}set crossoutdnponfab(A){this.setStringProperty("crossoutdnponfab",A,uue)}get subtractmaskfromsilk(){return this._properties.subtractmaskfromsilk?.value}set subtractmaskfromsilk(A){this.setStringProperty("subtractmaskfromsilk",A,due)}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,pue)}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,mue)}get plotinvisible(){return this._properties.plotinvisible?.value}set plotinvisible(A){this.setStringProperty("plotinvisible",A,wue)}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,$Ee)}get viasonmask(){return this._properties.viasonmask?.value}set viasonmask(A){this.setStringProperty("viasonmask",A,XEe)}get hpglpennumber(){return this._properties.hpglpennumber?.value}set hpglpennumber(A){this.setNumberProperty("hpglpennumber",A,UEe)}get hpglpenspeed(){return this._properties.hpglpenspeed?.value}set hpglpenspeed(A){this.setNumberProperty("hpglpenspeed",A,HEe)}get hpglpendiameter(){return this._properties.hpglpendiameter?.value}set hpglpendiameter(A){this.setNumberProperty("hpglpendiameter",A,YEe)}get hpglpenoverlay(){return this._properties.hpglpenoverlay?.value}set hpglpenoverlay(A){this.setNumberProperty("hpglpenoverlay",A,JEe)}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,Aue)}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,eue)}get pdf_metadata(){return this._properties.pdf_metadata?.value}set pdf_metadata(A){this.setStringProperty("pdf_metadata",A,tue)}get pdf_single_document(){return this._properties.pdf_single_document?.value}set pdf_single_document(A){this.setStringProperty("pdf_single_document",A,iue)}get dxfpolygonmode(){return this._properties.dxfpolygonmode?.value}set dxfpolygonmode(A){this.setStringProperty("dxfpolygonmode",A,oue)}get dxfimperialunits(){return this._properties.dxfimperialunits?.value}set dxfimperialunits(A){this.setStringProperty("dxfimperialunits",A,nue)}get dxfusepcbnewfont(){return this._properties.dxfusepcbnewfont?.value}set dxfusepcbnewfont(A){this.setStringProperty("dxfusepcbnewfont",A,sue)}get psnegative(){return this._properties.psnegative?.value}set psnegative(A){this.setStringProperty("psnegative",A,rue)}get psa4output(){return this._properties.psa4output?.value}set psa4output(A){this.setStringProperty("psa4output",A,aue)}get mirror(){return this._properties.mirror?.value}set mirror(A){this.setStringProperty("mirror",A,fue)}get outputformat(){return this._properties.outputformat?.value}set outputformat(A){this.setNumberProperty("outputformat",A,TEe)}get drillshape(){return this._properties.drillshape?.value}set drillshape(A){this.setNumberProperty("drillshape",A,KEe)}get scaleselection(){return this._properties.scaleselection?.value}set scaleselection(A){this.setNumberProperty("scaleselection",A,PEe)}get outputdirectory(){return this._properties.outputdirectory?.value}set outputdirectory(A){this.setStringProperty("outputdirectory",A,yue)}};LA.register(ZwA);var Iz=class extends rT{static parentToken="setup"},VwA=class extends Iz{static token="zone_45_only";token="zone_45_only"};LA.register(VwA);var jwA=class extends Iz{static token="allow_soldermask_bridges_in_footprints";token="allow_soldermask_bridges_in_footprints"};LA.register(jwA);var zwA=class extends Iz{static token="visible_elements";token="visible_elements"};LA.register(zwA);var XwA=class extends Iz{static token="uvias_allowed";token="uvias_allowed"};LA.register(XwA);var $wA=class ADe extends LA{static token="tenting";static parentToken="setup";token="tenting";_sides=[];constructor(A=[]){super(),this.sides=A}static fromSexprPrimitives(A){const e=A.map(i=>mi(i)).filter(i=>i!==void 0);return new ADe(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(" ")})`}};LA.register($wA);var aT=class extends Eai{static parentToken="setup"},Due=class extends uai{static parentToken="setup"},ADA=class extends aT{static token="pcb_text_size";token="pcb_text_size"};LA.register(ADA);var eDA=class extends aT{static token="mod_text_size";token="mod_text_size"};LA.register(eDA);var tDA=class extends aT{static token="pad_size";token="pad_size"};LA.register(tDA);var iDA=class extends aT{static token="pad_to_paste_clearance_values";token="pad_to_paste_clearance_values"};LA.register(iDA);var oDA=class extends aT{static token="trace_width";token="trace_width"};LA.register(oDA);var nDA=class extends Due{static token="aux_axis_origin";token="aux_axis_origin"};LA.register(nDA);var sDA=class extends Due{static token="grid_origin";token="grid_origin"};LA.register(sDA);var BB=class extends rT{static parentToken="setup";static parsePrimitiveValue(t){const A=Ii(t);if(A===void 0)throw new Error(`${this.name} expects a numeric value`);return A}},rDA=class extends BB{static token="pad_to_mask_clearance";token="pad_to_mask_clearance"};LA.register(rDA);var aDA=class extends BB{static token="solder_mask_min_width";token="solder_mask_min_width"};LA.register(aDA);var gDA=class extends BB{static token="pad_to_paste_clearance";token="pad_to_paste_clearance"};LA.register(gDA);var cDA=class extends BB{static token="pad_to_paste_clearance_ratio";token="pad_to_paste_clearance_ratio"};LA.register(cDA);var IDA=class extends BB{static token="last_trace_width";token="last_trace_width"};LA.register(IDA);var lDA=class extends BB{static token="trace_clearance";token="trace_clearance"};LA.register(lDA);var BDA=class extends BB{static token="zone_clearance";token="zone_clearance"};LA.register(BDA);var CDA=class extends BB{static token="trace_min";token="trace_min"};LA.register(CDA);var QDA=class extends BB{static token="segment_width";token="segment_width"};LA.register(QDA);var hDA=class extends BB{static token="edge_width";token="edge_width"};LA.register(hDA);var EDA=class extends BB{static token="via_size";token="via_size"};LA.register(EDA);var uDA=class extends BB{static token="via_drill";token="via_drill"};LA.register(uDA);var dDA=class extends BB{static token="via_min_size";token="via_min_size"};LA.register(dDA);var pDA=class extends BB{static token="via_min_drill";token="via_min_drill"};LA.register(pDA);var fDA=class extends BB{static token="uvia_size";token="uvia_size"};LA.register(fDA);var yDA=class extends BB{static token="uvia_drill";token="uvia_drill"};LA.register(yDA);var mDA=class extends BB{static token="uvia_min_size";token="uvia_min_size"};LA.register(mDA);var wDA=class extends BB{static token="uvia_min_drill";token="uvia_min_drill"};LA.register(wDA);var DDA=class extends BB{static token="pcb_text_width";token="pcb_text_width"};LA.register(DDA);var SDA=class extends BB{static token="mod_edge_width";token="mod_edge_width"};LA.register(SDA);var bDA=class extends BB{static token="mod_text_width";token="mod_text_width"};LA.register(bDA);var _DA=class extends BB{static token="pad_drill";token="pad_drill"};LA.register(_DA);var gT=class extends rT{static parentToken="stackup"},Sue=class extends gT{static token="copper_finish";token="copper_finish";quoteStringValue=!0};LA.register(Sue);var bue=class extends gT{static token="dielectric_constraints";token="dielectric_constraints"};LA.register(bue);var _ue=class extends gT{static token="edge_connector";token="edge_connector"};LA.register(_ue);var xue=class extends gT{static token="castellated_pads";token="castellated_pads"};LA.register(xue);var kue=class extends gT{static token="edge_plating";token="edge_plating"};LA.register(kue);var Y1=class extends rT{static parentToken="layer"},xDA=class extends Y1{static token="type";token="type";quoteStringValue=!0};LA.register(xDA);var kDA=class extends Y1{static token="color";token="color";quoteStringValue=!0};LA.register(kDA);var FDA=class extends Y1{static token="thickness";token="thickness";static parsePrimitiveValue(t){const A=Ii(t);if(A===void 0)throw new Error("Stackup layer thickness expects a numeric value");return A}};LA.register(FDA);var GDA=class extends Y1{static token="material";token="material";quoteStringValue=!0};LA.register(GDA);var RDA=class extends Y1{static token="epsilon_r";token="epsilon_r";static parsePrimitiveValue(t){const A=Ii(t);if(A===void 0)throw new Error("Stackup layer epsilon_r expects a numeric value");return A}};LA.register(RDA);var vDA=class extends Y1{static token="loss_tangent";token="loss_tangent";static parsePrimitiveValue(t){const A=Ii(t);if(A===void 0)throw new Error("Stackup layer loss_tangent expects a numeric value");return A}};LA.register(vDA);var Fue=class eDe extends LA{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=mi(A[0]);if(e===void 0)throw new Error("Stackup layer name must be a string");let i=1,o;const n=A[i],s=Ii(n);s!==void 0&&(o=s,i+=1);const r=A.slice(i),{propertyMap:a}=LA.parsePrimitivesToClassProperties(r,this.token);return new eDe(e,{number:o,type:a.type,color:a.color,thickness:a.thickness,material:a.material,epsilonR:a.epsilon_r,lossTangent:a.loss_tangent})}get name(){return this._name}set name(A){const e=mi(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=Ii(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 xDA?A:new xDA(A)}get color(){return this._sxColor?.value}set color(A){if(A===void 0){this._sxColor=void 0;return}this._sxColor=A instanceof kDA?A:new kDA(A)}get thickness(){return this._sxThickness?.value}set thickness(A){if(A===void 0){this._sxThickness=void 0;return}this._sxThickness=A instanceof FDA?A:new FDA(A)}get material(){return this._sxMaterial?.value}set material(A){if(A===void 0){this._sxMaterial=void 0;return}this._sxMaterial=A instanceof GDA?A:new GDA(A)}get epsilonR(){return this._sxEpsilonR?.value}set epsilonR(A){if(A===void 0){this._sxEpsilonR=void 0;return}this._sxEpsilonR=A instanceof RDA?A:new RDA(A)}get lossTangent(){return this._sxLossTangent?.value}set lossTangent(A){if(A===void 0){this._sxLossTangent=void 0;return}this._sxLossTangent=A instanceof vDA?A:new vDA(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 ${ho(this._name)}${this._number!==void 0?` ${this._number}`:""}`,e=this.getChildren();if(e.length===0)return`${A})`;const i=[A];for(const o of e)i.push(o.getStringIndented());return i.push(")"),i.join(`
|
|
5825
5825
|
`)}};LA.register(Fue);var MDA=class tDe extends LA{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}=LA.parsePrimitivesToClassProperties(A,this.token);return new tDe({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 Fue))throw new Error("Stackup layers must be StackupLayer instances");return e})}get copperFinish(){return this._sxCopperFinish?.value}set copperFinish(A){this._sxCopperFinish=A?new Sue(A):void 0}get dielectricConstraints(){return this._sxDielectricConstraints?.value}set dielectricConstraints(A){this._sxDielectricConstraints=A?new bue(A):void 0}get edgeConnector(){return this._sxEdgeConnector?.value}set edgeConnector(A){this._sxEdgeConnector=A?new _ue(A):void 0}get castellatedPads(){return this._sxCastellatedPads?.value}set castellatedPads(A){this._sxCastellatedPads=A?new xue(A):void 0}get edgePlating(){return this._sxEdgePlating?.value}set edgePlating(A){this._sxEdgePlating=A?new kue(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}};LA.register(MDA);var fai={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"},yai=["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"],NDA=class iDe extends LA{static token="setup";token="setup";_properties={};static fromSexprPrimitives(A){const e=new iDe,{propertyMap:i}=LA.parsePrimitivesToClassProperties(A,this.token);for(const[o,n]of Object.entries(i)){const s=fai[o];if(!s)throw new Error(`Unsupported setup property token: ${o}`);e._properties[s]=n}return e}getChildren(){const A=[];for(const e of yai){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",MDA)}set stackup(A){if(A!==void 0&&!(A instanceof MDA))throw new Error("stackup must be a Stackup instance");this.setProperty("stackup",A)}get pcbPlotParams(){return this.getPropertyInstance("pcbPlotParams",ZwA)}set pcbPlotParams(A){if(A!==void 0&&!(A instanceof ZwA))throw new Error("pcbPlotParams must be a PcbPlotParams instance");this.setProperty("pcbPlotParams",A)}get padToMaskClearance(){return this.getPropertyInstance("padToMaskClearance",rDA)?.value}set padToMaskClearance(A){this.setNumberProperty("padToMaskClearance",A,rDA)}get solderMaskMinWidth(){return this.getPropertyInstance("solderMaskMinWidth",aDA)?.value}set solderMaskMinWidth(A){this.setNumberProperty("solderMaskMinWidth",A,aDA)}get padToPasteClearance(){return this.getPropertyInstance("padToPasteClearance",gDA)?.value}set padToPasteClearance(A){this.setNumberProperty("padToPasteClearance",A,gDA)}get padToPasteClearanceRatio(){return this.getPropertyInstance("padToPasteClearanceRatio",cDA)?.value}set padToPasteClearanceRatio(A){this.setNumberProperty("padToPasteClearanceRatio",A,cDA)}get lastTraceWidth(){return this.getPropertyInstance("lastTraceWidth",IDA)?.value}set lastTraceWidth(A){this.setNumberProperty("lastTraceWidth",A,IDA)}get traceClearance(){return this.getPropertyInstance("traceClearance",lDA)?.value}set traceClearance(A){this.setNumberProperty("traceClearance",A,lDA)}get zoneClearance(){return this.getPropertyInstance("zoneClearance",BDA)?.value}set zoneClearance(A){this.setNumberProperty("zoneClearance",A,BDA)}get zone45Only(){return this.getPropertyInstance("zone45Only",VwA)?.value}set zone45Only(A){this.setProperty("zone45Only",A===void 0?void 0:new VwA(A))}get traceMin(){return this.getPropertyInstance("traceMin",CDA)?.value}set traceMin(A){this.setNumberProperty("traceMin",A,CDA)}get segmentWidth(){return this.getPropertyInstance("segmentWidth",QDA)?.value}set segmentWidth(A){this.setNumberProperty("segmentWidth",A,QDA)}get edgeWidth(){return this.getPropertyInstance("edgeWidth",hDA)?.value}set edgeWidth(A){this.setNumberProperty("edgeWidth",A,hDA)}get viaSize(){return this.getPropertyInstance("viaSize",EDA)?.value}set viaSize(A){this.setNumberProperty("viaSize",A,EDA)}get viaDrill(){return this.getPropertyInstance("viaDrill",uDA)?.value}set viaDrill(A){this.setNumberProperty("viaDrill",A,uDA)}get viaMinSize(){return this.getPropertyInstance("viaMinSize",dDA)?.value}set viaMinSize(A){this.setNumberProperty("viaMinSize",A,dDA)}get viaMinDrill(){return this.getPropertyInstance("viaMinDrill",pDA)?.value}set viaMinDrill(A){this.setNumberProperty("viaMinDrill",A,pDA)}get uviasAllowed(){return this.getPropertyInstance("uviasAllowed",XwA)?.value}set uviasAllowed(A){this.setProperty("uviasAllowed",A===void 0?void 0:new XwA(A))}get uviaSize(){return this.getPropertyInstance("uviaSize",fDA)?.value}set uviaSize(A){this.setNumberProperty("uviaSize",A,fDA)}get uviaDrill(){return this.getPropertyInstance("uviaDrill",yDA)?.value}set uviaDrill(A){this.setNumberProperty("uviaDrill",A,yDA)}get uviaMinSize(){return this.getPropertyInstance("uviaMinSize",mDA)?.value}set uviaMinSize(A){this.setNumberProperty("uviaMinSize",A,mDA)}get uviaMinDrill(){return this.getPropertyInstance("uviaMinDrill",wDA)?.value}set uviaMinDrill(A){this.setNumberProperty("uviaMinDrill",A,wDA)}get pcbTextWidth(){return this.getPropertyInstance("pcbTextWidth",DDA)?.value}set pcbTextWidth(A){this.setNumberProperty("pcbTextWidth",A,DDA)}get pcbTextSize(){return this.getPropertyInstance("pcbTextSize",ADA)?.values}set pcbTextSize(A){if(A===void 0){delete this._properties.pcbTextSize;return}this.setProperty("pcbTextSize",new ADA(A))}get modEdgeWidth(){return this.getPropertyInstance("modEdgeWidth",SDA)?.value}set modEdgeWidth(A){this.setNumberProperty("modEdgeWidth",A,SDA)}get modTextSize(){return this.getPropertyInstance("modTextSize",eDA)?.values}set modTextSize(A){if(A===void 0){delete this._properties.modTextSize;return}this.setProperty("modTextSize",new eDA(A))}get modTextWidth(){return this.getPropertyInstance("modTextWidth",bDA)?.value}set modTextWidth(A){this.setNumberProperty("modTextWidth",A,bDA)}get padSize(){return this.getPropertyInstance("padSize",tDA)?.values}set padSize(A){if(A===void 0){delete this._properties.padSize;return}this.setProperty("padSize",new tDA(A))}get padDrill(){return this.getPropertyInstance("padDrill",_DA)?.value}set padDrill(A){this.setNumberProperty("padDrill",A,_DA)}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",$wA)?.sides}set tenting(A){if(A===void 0){delete this._properties.tenting;return}this.setProperty("tenting",new $wA(A))}get auxAxisOrigin(){const A=this.getPropertyInstance("auxAxisOrigin",nDA);if(A)return{x:A.x,y:A.y}}set auxAxisOrigin(A){if(!A){delete this._properties.auxAxisOrigin;return}this.setProperty("auxAxisOrigin",new nDA(A.x,A.y))}get gridOrigin(){const A=this.getPropertyInstance("gridOrigin",sDA);if(A)return{x:A.x,y:A.y}}set gridOrigin(A){if(!A){delete this._properties.gridOrigin;return}this.setProperty("gridOrigin",new sDA(A.x,A.y))}get visibleElements(){return this.getPropertyInstance("visibleElements",zwA)?.value}set visibleElements(A){this.setProperty("visibleElements",A===void 0?void 0:new zwA(A))}get padToPasteClearanceValues(){return this.getPropertyInstance("padToPasteClearanceValues",iDA)?.values}set padToPasteClearanceValues(A){if(A===void 0){delete this._properties.padToPasteClearanceValues;return}this.setProperty("padToPasteClearanceValues",new iDA(A))}get traceWidth(){return this.getPropertyInstance("traceWidth",oDA)?.values}set traceWidth(A){if(A===void 0){delete this._properties.traceWidth;return}this.setProperty("traceWidth",new oDA(A))}};LA.register(NDA);var Gue=class extends Ba{static token="thickness";static parentToken="general";token="thickness"};LA.register(Gue);var Rue=class oDe extends LA{static token="legacy_teardrops";static parentToken="general";token="legacy_teardrops";_enabled;constructor(A){super(),this._enabled=A}static fromSexprPrimitives(A){const e=mi(A[0]);if(e===void 0)throw new Error("legacy_teardrops expects a string value");const i=/^(yes|true)$/iu.test(e);return new oDe(i)}get enabled(){return this._enabled}set enabled(A){this._enabled=A}getChildren(){return[]}getString(){return`(legacy_teardrops ${this._enabled?"yes":"no"})`}};LA.register(Rue);var vue=new Set(["thickness","legacy_teardrops"]),LDA=class nDe extends LA{static token="general";static parentToken="kicad_pcb";token="general";_sxThickness;_sxLegacyTeardrops;static fromSexprPrimitives(A){const e=new nDe,{propertyMap:i,arrayPropertyMap:o}=LA.parsePrimitivesToClassProperties(A,this.token);for(const n of Object.keys(i))if(!vue.has(n))throw new Error(`general encountered unsupported child token "${n}"`);for(const[n,s]of Object.entries(o)){if(!vue.has(n))throw new Error(`general encountered unsupported child token "${n}"`);if(s.length>1)throw new Error(`general encountered repeated child token "${n}"`)}return e._sxThickness=o.thickness?.[0]??i.thickness,e._sxLegacyTeardrops=o.legacy_teardrops?.[0]??i.legacy_teardrops,e}get thickness(){return this._sxThickness?.value}set thickness(A){this._sxThickness=A===void 0?void 0:new Gue(A)}get legacyTeardrops(){return this._sxLegacyTeardrops?.enabled}set legacyTeardrops(A){if(A===void 0){this._sxLegacyTeardrops=void 0;return}this._sxLegacyTeardrops=new Rue(A)}getChildren(){const A=[];return this._sxThickness&&A.push(this._sxThickness),this._sxLegacyTeardrops&&A.push(this._sxLegacyTeardrops),A}};LA.register(LDA);var CB=class sDe extends LA{static token="__pcb_layer_definition__";static parentToken="layers";token="__pcb_layer_definition__";_index;_name;_type;_userName;constructor(A){super(),this._index=A.index,this._name=A.name,this._type=A.type,this._userName=A.userName}static fromPrimitive(A){if(!Array.isArray(A)||A.length<3)throw new Error(`layers entry must be an array with at least index, name, and type: ${JSON.stringify(A)}`);const[e,i,o,n]=A,s=Ii(e),r=mi(i),a=mi(o),g=n===void 0?void 0:mi(n);if(s===void 0||r===void 0||a===void 0)throw new Error(`layers entry is missing required values: ${JSON.stringify(A)}`);return new sDe({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),ho(this._name),this._type];return this._userName!==void 0&&A.push(ho(this._userName)),`(${A.join(" ")})`}};LA.register(CB);var UDA=class rDe extends LA{static token="layers";static parentToken="kicad_pcb";token="layers";_definitions=[];static fromSexprPrimitives(A){const e=new rDe;return e._definitions=A.map(i=>CB.fromPrimitive(i)),e}get definitions(){return[...this._definitions]}set definitions(A){this._definitions=[...A]}getChildren(){return[...this._definitions]}};LA.register(UDA);var lz=class aDe extends LA{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=Ii(A[0]),i=mi(A[1]);if(e===void 0||i===void 0)throw new Error("net requires numeric id and string name");return new aDe(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} ${ho(this._name)})`}};LA.register(lz);var HDA=class extends Ba{static token="version";static parentToken="kicad_pcb";token="version"};LA.register(HDA);var mai=t=>/^[A-Za-z0-9._-]+$/.test(t),YDA=class extends sm{static token="generator";static parentToken="kicad_pcb";token="generator";getString(){return`(generator ${mai(this.value)?this.value:ho(this.value)})`}};LA.register(YDA);var wai=t=>/^[A-Za-z0-9._-]+$/.test(t),JDA=class extends sm{static token="generator_version";static parentToken="kicad_pcb";token="generator_version";getString(){return`(generator_version ${wai(this.value)?this.value:ho(this.value)})`}};LA.register(JDA);var TDA=class gDe extends LA{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=Ii(A[0]);if(e===void 0)throw new Error("via net requires a numeric id");const i=A.length>1?mi(A[1]):void 0;return new gDe(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} ${ho(this._name)})`:`(net ${this._id})`}};LA.register(TDA);var Dai=new Set(["locked","free","remove_unused_layers","keep_end_layers"]),KDA=class cDe extends LA{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 cDe;for(const i of A){if(typeof i=="string"){e.consumeBareToken(i);continue}if(!Array.isArray(i)||i.length===0)throw new Error(`via encountered unsupported primitive child: ${JSON.stringify(i)}`);const[o,...n]=i;if(typeof o!="string")throw new Error(`via encountered child with non-string token: ${JSON.stringify(i)}`);e.consumeNode(o,n)}return e}consumeBareToken(A){if(A==="blind"||A==="micro"){this._type=A;return}if(!Dai.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=mi(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=LA.parsePrimitiveSexpr(["at",...e],{parentToken:this.token});if(!(i instanceof Dc))throw new Error("via failed to parse at child");this._sxAt=i;return}case"size":{const i=Ii(e[0]);if(i===void 0)throw new Error("via size expects a numeric value");this._size=i;return}case"drill":{const i=Ii(e[0]);if(i===void 0)throw new Error("via drill expects a numeric value");this._drill=i;return}case"layers":{this._sxLayers=cz.fromSexprPrimitives(e);return}case"net":{this._sxNet=TDA.fromSexprPrimitives(e);return}case"teardrops":{this._sxTeardrops=iEe.fromSexprPrimitives(e);return}case"uuid":{const i=mi(e[0]);if(i===void 0)throw new Error("via uuid expects a string value");this._sxUuid=new Yi(i);return}case"tstamp":{const i=mi(e[0]);if(i===void 0)throw new Error("via tstamp expects a string value");this._sxTstamp=new ic(i);return}default:throw new Error(`via encountered unsupported child token "${A}"`)}}parseYesNo(A){if(A.length===0)return!0;const e=mi(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?Dc.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 cz?A:new cz(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 Yi?A:new Yi(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 ic?A:new ic(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
|
-
`)}};LA.register(KDA);var PDA=class IDe extends LA{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 IDe;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const o=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(o instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(o)}return e}consumeChild(A){if(A instanceof HDA){this._sxVersion=A;return}if(A instanceof YDA){this._sxGenerator=A;return}if(A instanceof JDA){this._sxGeneratorVersion=A;return}if(A instanceof LDA){this._sxGeneral=A;return}if(A instanceof jj){this._sxPaper=A;return}if(A instanceof FQe){this._sxTitleBlock=A;return}if(A instanceof UDA){this._sxLayers=A;return}if(A instanceof NDA){this._sxSetup=A;return}if(A instanceof L1){this._properties.push(A);return}if(A instanceof lz){this._nets.push(A);return}if(A instanceof RwA){this._footprints.push(A);return}if(A instanceof RQe){this._images.push(A);return}if(A instanceof WwA){this._segments.push(A);return}if(A instanceof az){this._grLines.push(A);return}if(A instanceof TwA){this._grTexts.push(A);return}if(A instanceof wEe){this._grPolys.push(A);return}if(A instanceof fEe){this._grRects.push(A);return}if(A instanceof KDA){this._vias.push(A);return}if(A instanceof kEe){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 HDA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new YDA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new JDA(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}};LA.register(PDA);var Mue=t=>LA.parse(t),JE=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")}},Sai=class extends JE{_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 jj;e.size=A?.name??"A4",t.paper=e,t.uuid=new Yi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Bz(t,A){if(t.manufacturer_part_number)return qDA(t.manufacturer_part_number);const e=bai(t.ftype),i=A?.footprinter_string;return qDA(i?`${e}_${i}`:e)}function bai(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function qDA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Nue(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Lue={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"},_ai=/^[A-Za-z]+\d+$/;function Uue(t){return t?_ai.test(t.trim()):!1}function ODA(t){const A=t?.name;if(Uue(A))return Nue(A);const e=t?.ftype;return e&&Lue[e]?Lue[e]:Nue(A)}function xai(t){const A=t?.name;return Uue(A)?A.trim():`${ODA(t)}?`}function Hue(t){return t in mQ}function Yue(t,A,e){if(t.type!=="source_component")return A.symbol_name?Hue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Hue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const i=Bz(t,e);return`Device:${ODA(t)}_${i}`}var kai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx,e=new the,i=[],o=A.schematic_component.list();for(const s of o){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const n=A.schematic_net_label?.list?.()||[];for(const s of n)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const 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(g=>g.source_component_id===e.source_component_id),o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const n=this.getSymbolData(o,t);if(!n)return null;const s=Yue(e,t,i),r=e.ftype==="simple_chip",a=Bz(e,i);return this.createLibrarySymbol({libId:s,symbolData:n,isChip:r,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:a?`tscircuit:${a}`:"",referencePrefix:ODA(e)})}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const o=mQ[i];if(!o)return null;const n=`Custom:${i}`;return this.createLibrarySymbol({libId:n,symbolData:o,isChip:!1,schematicComponent:void 0,description:A?"Power net label":e?"Ground net label":"Net symbol",keywords:A?"power net":e?"ground net":"net",fpFilters:"",referencePrefix:n.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,o=t.size?.height||1,n={type:"path",points:[{x:-i/2,y:-o/2},{x:i/2,y:-o/2},{x:i/2,y:o/2},{x:-i/2,y:o/2},{x:-i/2,y:-o/2}]},s=e.map(r=>{const a=r.center.x-t.center.x,g=r.center.y-t.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[n],ports:s,size:{width:i,height:o}}}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:o,keywords:n,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new N1({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new UQe;c.hide=!e,g._sxPinNumbers=c;const I=new HQe;I.offset=e?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:t,description:o,keywords:n,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 Xj(!1),g}addSymbolProperties({symbol:t,libId:A,description:e,keywords:i,fpFilters:o,footprintRef:n="",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:n,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:e,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:o,id:6,at:[0,0,0],hide:!0}];for(const g of a)t.properties.push(new rm({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){return t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:t,symbolData:A,isChip:e}){const i=new N1({libraryId:`${t.split(":")[1]}_0_1`}),o=this.ctx.c2kMatSch?.a||15;for(const n of A.primitives||[])if(n.type==="path"&&n.points){const s=e?"background":"none",r=this.createPolylineFromPoints({points:n.points,scale:o,center:A.center,fillType:s});i.polylines.push(r)}else if(n.type==="circle"){const s=this.createCircleFromPrimitive({primitive:n,scale:o,center:A.center});i.circles.push(s)}return i}createPolylineFromPoints({points:t,scale:A,center:e,fillType:i}){const o=new MQe,n=e?.x??0,s=e?.y??0,r=yh(A,A),a=t.map(l=>{const B=Zt(r,{x:l.x-n,y:l.y-s});return new Nh(B.x,B.y)}),g=new JQ(a);o.points=g;const c=new Wj;c.width=.254,c.type="default",o.stroke=c;const I=new PQe;return I.type=i,o.fill=I,o}createCircleFromPrimitive({primitive:t,scale:A,center:e}){const i=new WQe,o=e?.x??0,n=e?.y??0,s=yh(A,A),r=Zt(s,{x:t.x-o,y:t.y-n}),a=i;a._sxCenter=new TQe(r.x,r.y),a._sxRadius=new KQe(t.radius*A);const g=new Wj;g.width=.254,g.type="default",a._sxStroke=g;const c=new qQe;return c.type=t.fill?"outline":"none",a._sxFill=c,i}createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i}){const o=new N1({libraryId:`${t.split(":")[1]}_1_1`});for(let n=0;n<(A.ports?.length||0);n++){const s=A.ports[n],r=new ez;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,e,n,i);r.at=[a,g,c],r.length=e?6:1.27;const I=new $D;I.size={height:1.27,width:1.27};const l=new XD({font:I}),B=s.labels?.[0]||"~";r._sxName=new DmA({value:B,effects:l});const C=new $D;C.size={height:1.27,width:1.27};const Q=new XD({font:C}),h=s.pinNumber?.toString()||`${n+1}`;r._sxNumber=new VQe({value:h,effects:Q}),o.pins.push(r)}return o}calculatePinPosition(t,A,e,i,o,n){const s=this.ctx.c2kMatSch?.a||15;let r=t.x??0,a=t.y??0,g=!1;if(o!==void 0&&n){const d=this.ctx.db.schematic_port.list().filter(f=>f.schematic_component_id===n.schematic_component_id).sort((f,m)=>(f.pin_number||0)-(m.pin_number||0));if(d[o]){const f=d[o];r=f.center.x-n.center.x,a=f.center.y-n.center.y,g=!0}}let c,I;if(g)c=r,I=a;else{const d=A?.x??0,f=A?.y??0;c=r-d,I=a-f}const l=yh(s,s),B=Zt(l,{x:c,y:I});let C;if(i&&e){const d=e.width/2,f=e.height/2,m=Math.abs(c)/d,D=Math.abs(I)/f;C=m>D}else C=Math.abs(c)>Math.abs(I);let Q=B.x,h=B.y;const E=6;if(i&&e){const d=e.width/2*s,f=e.height/2*s;C?(Q=c>0?d:-d,h=I*s):(Q=c*s,h=I>0?f:-f)}let u=0;return C?c>0?i?(u=180,Q=Q+E):u=0:i?(u=0,Q=Q-E):u=180:I>0?i?(u=270,h=h+E):u=90:i?(u=90,h=h-E):u=270,{x:Q,y:h,angle:u}}createTextEffects(t,A){const e=new $D;return e.size={height:t,width:t},new XD({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Fai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_component.list();if(e.length===0){this.finished=!0;return}const i=[];for(const o of e){const n=o.source_component_id?A.source_component.get(o.source_component_id):null;if(!n||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Zt(this.ctx.c2kMatSch,{x:o.center.x,y:o.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(v=>v.source_component_id===n.source_component_id),I=Yue(n,o,c),l=new ymA(I);g._sxLibId=l;const{reference:B,value:C,description:Q}=this.getComponentMetadata(n),{refTextPos:h,valTextPos:E}=this.getTextPositions(o,{x:s,y:r}),u=new rm({key:"Reference",value:B,id:0,at:[h.x,h.y,0],effects:this.createTextEffects(1.27,!1)}),d=n.ftype==="simple_chip",f=new rm({key:"Value",value:C,id:1,at:[E.x,E.y,0],effects:this.createTextEffects(1.27,d)}),m=new rm({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),D=new rm({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),w=new rm({key:"Description",value:Q,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});g.properties.push(u,f,m,D,w);const b=A.schematic_port.list().filter(v=>v.schematic_component_id===o.schematic_component_id).sort((v,U)=>(v.pin_number||0)-(U.pin_number||0));for(const v of b){const U=new ez;U.numberString=`${v.pin_number||1}`,U.uuid=crypto.randomUUID(),g.pins.push(U)}const k=new SmA,_=new _mA(""),M=new xmA(`/${t?.uuid?.value||""}`);M.reference=B,M.unit=1,_.paths.push(M),k.projects.push(_),g._sxInstances=k,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=Zt(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 o=t.symbol_name,n=mQ[o];if(!n)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of n.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=n.center||{x:0,y:0},c=o.includes("_down")||o.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Zt(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?Zt(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=xai(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"}:{reference:e,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new $D;i.size={height:t,width:t};const o=e?new Zj({horizontal:e}):void 0;return new XD({font:i,hiddenText:A,justify:o})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Gai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_net_label?.list?.()||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],o=[];for(const n of e){const s=n.text||"",r=n.symbol_name;if(r){const a=this.createSymbolFromNetLabel(n,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(n,s);a&&o.push(a)}}if(t&&i.length>0){const n=t.symbols||[];t.symbols=[...n,...i]}t&&o.length>0&&(t.globalLabels=[...t.globalLabels||[],...o]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:o}=Zt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=crypto.randomUUID(),s=new N1({at:[i,o,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:n,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new ymA(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new rm({key:"Reference",value:A,id:0,at:[i,o+c,0],effects:this.createTextEffects(1.27,!1)}),B=new rm({key:"Value",value:A,id:1,at:[i,o+I,0],effects:this.createTextEffects(1.27,!0)}),C=new rm({key:"Footprint",value:"",id:2,at:[i-1.778,o,90],effects:this.createTextEffects(1.27,!0)}),Q=new rm({key:"Datasheet",value:"~",id:3,at:[i,o,0],effects:this.createTextEffects(1.27,!0)}),h=new rm({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,o,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new ez;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new SmA,f=new _mA(""),m=new xmA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Zt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[o]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[o]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new Zj(a)),new Ihe({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new $D;return e.size={height:t,width:t},new XD({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Rai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const e=A.schematic_trace.list();if(e.length===0){this.finished=!0;return}const i=[],o=[];for(const n of e){for(const s of n.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of n.junctions){const r=this.createJunction(s);o.push(r)}}t.wires=i,t.junctions=o,this.finished=!0}createWireFromEdge(t){const A=new ohe;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Zt(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Zt(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),o=e.x,n=e.y,s=i.x,r=i.y,a=new JQ([new Nh(o,n),new Nh(s,r)]);A.points=a;const g=new Wj;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}=Zt(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new nhe({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},vai=class extends JE{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new RmA,e=new Che;e.value="/";const i=new Qhe("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new Xj(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Mai(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,o=1/0,n=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),o=Math.min(o,g.center.y-I/2),n=Math.max(n,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),o=Math.min(o,c.from.y,c.to.y),n=Math.max(n,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,o=0,n=0,s=0);const r=(i+n)/2,a=(o+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:o,maxX:n,maxY:s}}}var Cz=[{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 Nai(t,A,e=20){const i=t+2*e,o=A+2*e;for(let n=0;n<Cz.length;n++){const s=Cz[n];if(i<=s.width&&o<=s.height)return s}return Cz[Cz.length-1]}var Jue=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){const e=va(t),{center:i,bounds:o}=Mai(e),n=(o.maxX-o.minX)*15,s=(o.maxY-o.minY)*15,r=Nai(n,s),a=r.width/2,g=r.height/2;this.ctx={db:e,circuitJson:t,kicadSch:new MmA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:sB(dr(a,g),yh(15,-15),dr(-i.x,-i.y))},this.pipeline=[new Sai(t,this.ctx),new kai(t,this.ctx),new Fai(t,this.ctx),new Gai(t,this.ctx),new Rai(t,this.ctx),new vai(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()}},Lai=class extends JE{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");t.version=20241229;const A=new jj;A.size="A4",t.paper=A;const e=new LDA;e.thickness=1.6,t.general=e;const i=new NDA;i.padToMaskClearance=0,t.setup=i;const o=new UDA,n=[new CB({index:0,name:"F.Cu",type:"signal"}),new CB({index:2,name:"B.Cu",type:"signal"}),new CB({index:9,name:"F.Adhes",type:"user"}),new CB({index:11,name:"B.Adhes",type:"user"}),new CB({index:13,name:"F.Paste",type:"user"}),new CB({index:15,name:"B.Paste",type:"user"}),new CB({index:5,name:"F.SilkS",type:"user"}),new CB({index:7,name:"B.SilkS",type:"user"}),new CB({index:1,name:"F.Mask",type:"user"}),new CB({index:3,name:"B.Mask",type:"user"}),new CB({index:20,name:"Dwgs.User",type:"user"}),new CB({index:21,name:"Cmts.User",type:"user"}),new CB({index:22,name:"Eco1.User",type:"user"}),new CB({index:23,name:"Eco2.User",type:"user"}),new CB({index:24,name:"Edge.Cuts",type:"user"}),new CB({index:25,name:"Margin",type:"user"}),new CB({index:17,name:"B.CrtYd",type:"user"}),new CB({index:16,name:"F.CrtYd",type:"user"}),new CB({index:19,name:"B.Fab",type:"user"}),new CB({index:18,name:"F.Fab",type:"user"})];o.definitions=n,t.layers=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Uai=class extends JE{_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 o=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),n=[];n.push(new lz(0,""));let s=1;for(const[r,a]of o){const g=new lz(s,a);n.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}t.nets=n,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function Hai(t){let A=0;for(let i=0;i<t.length;i++){const o=t.charCodeAt(i);A=(A<<5)-A+o,A=A&A}let e="";for(let i=0;i<4;i++){let o=A;for(let n=0;n<t.length;n++)o=(o<<5)-o+t.charCodeAt(n)+i*31,o=o&o;e+=Math.abs(o).toString(16).padStart(8,"0")}return e}function eS(t){const A=Hai(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function Yai({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){let s,r;if("x"in t&&"y"in t)s=t.x,r=t.y;else if("points"in t&&Array.isArray(t.points)){const u=t.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=sB(i!==0?Tw(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},yh(1,-1),dr(-A.x,-A.y)),g=Zt(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(yh(1,-1),dr(-s,-r)),f=u.map(D=>{const w=Zt(d,{x:D.x,y:D.y});return new Nh(w.x,w.y)}),m=new iwA;m.contours=[new JQ(f)],m.width=0,m.filled=!0,Q=new qhe,Q.addGraphic(m),l="custom",C=new _he,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:${n}:${e}:${g.x},${g.y}`,E=new oz({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:eS(h)});return C&&(E.options=C),Q&&(E.primitives=Q),o&&(E.net=new zmA(o.id,o.name)),E}function Jai({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){if(!("x"in t&&"y"in t))return null;const s=t.x-A.x,r=-(t.y-A.y),a=i!==0?Tw(i*Math.PI/180):Ld(),g=Zt(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=Zt(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(c="circle",I=[t.outer_diameter,t.outer_diameter],l=new AS({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(c="oval",I=[t.outer_width,t.outer_height],l=new AS({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 AS({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 AS({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 AS({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 AS({diameter:.8,offset:Q}));const h=`thruhole:${n}:${e}:${g.x},${g.y}`,E=new oz({number:String(e),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:eS(h)});return o&&(E.net=new zmA(o.id,o.name)),E}function Tai({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,o=-(t.y-A.y),n=e!==0?Tw(e*Math.PI/180):Ld(),s=Zt(n,{x:i,y:o});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const c=t.hole_diameter;a=[c,c],g=new AS({diameter:c})}else if(t.hole_shape==="oval"){r="oval";const c=t.hole_width,I=t.hole_height;a=[c,I],g=new AS({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in t?t.hole_diameter:1;a=[c,c],g=new AS({diameter:c})}return new oz({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 Kai({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,o=-(t.anchor_position.y-A.y),n=e!==0?Tw(e*Math.PI/180):Ld(),s=Zt(n,{x:i,y:o}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",c=(t.font_size||1)/1.5,I=new $D;I.size={width:c,height:c};const l=new XD({font:I}),B=t.ccw_rotation||0;return new rEe({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}var Pai=class extends JE{componentsProcessed=0;pcbComponents=[];getNetInfoForPcbPort(t){if(!t)return;const A=this.ctx.db.pcb_port?.get(t);if(!A)return;const e=A.source_port_id;if(!e)return;const i=this.ctx.db.source_port?.get(e);if(!i)return;const o=i.subcircuit_connectivity_map_key;if(o)return this.ctx.pcbNetMap?.get(o)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}create3DModelsFromCadComponent(t,A){const e=[],i=t.model_step_url||t.model_wrl_url;if(!i)return e;const o=new kwA(i);if(t.position&&(o.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:t.position.z||0}),t.rotation&&(o.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const n=t.model_unit_to_mm_scale_factor;o.scale={x:n,y:n,z:n}}return e.push(o),e}constructor(t,A){super(t,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const e=this.pcbComponents[this.componentsProcessed],i=e.source_component_id?this.ctx.db.source_component.get(e.source_component_id):null,o=this.getCadComponentForPcbComponent(e.pcb_component_id),n=i?Bz(i,o):"Unknown",s=Zt(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new RwA({libraryLink:`tscircuit:${n}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:eS(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(E=>E.pcb_component_id===e.pcb_component_id)||[];for(const E of c){const u=Kai({textElement:E,componentCenter:e.center,componentRotation:e.rotation||0});u&&(i?.name&&E.text===i.name&&(u.type="reference"),g.push(u))}a.fpTexts=g;const I=this.ctx.db.pcb_smtpad?.list().filter(E=>E.pcb_component_id===e.pcb_component_id)||[],l=a.fpPads;let B=1;for(const E of I){const u=this.getNetInfoForPcbPort(E.pcb_port_id),d=Yai({pcbPad:E,componentCenter:e.center,padNumber:B,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});l.push(d),B++}const C=this.ctx.db.pcb_plated_hole?.list().filter(E=>E.pcb_component_id===e.pcb_component_id)||[];for(const E of C){const u=this.getNetInfoForPcbPort(E.pcb_port_id),d=Jai({platedHole:E,componentCenter:e.center,padNumber:B,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});d&&(l.push(d),B++)}const Q=this.ctx.db.pcb_hole?.list().filter(E=>E.subcircuit_id===e.subcircuit_id)||[];for(const E of Q){const u=Tai({pcbHole:E,componentCenter:e.center,componentRotation:e.rotation||0});u&&l.push(u)}if(a.fpPads=l,o){const E=this.create3DModelsFromCadComponent(o,e.center);E.length>0&&(a.models=E)}const h=t.footprints;h.push(a),t.footprints=h,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},qai=class extends JE{tracesProcessed=0;pcbTraces=[];constructor(t,A){super(t,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}for(let o=0;o<i.route.length-1;o++){const n=i.route[o],s=i.route[o+1],r=Zt(A,{x:n.x,y:n.y}),a=Zt(A,{x:s.x,y:s.y});let g;if(e){let Q=i.subcircuit_connectivity_map_key;if(!Q&&i.source_trace_id){const 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 E of h.connected_source_net_ids){const u=this.ctx.db.source_net?.get(E);if(u?.subcircuit_connectivity_map_key){Q=u.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&&(g=e.get(Q))}const I={top:"F.Cu",bottom:"B.Cu"}[n.layer]||n.layer||"F.Cu",l=`segment:${r.x},${r.y}:${a.x},${a.y}:${I}:${g?.id??0}`,B=new WwA({start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},layer:I,width:i.width||.25,net:new gz(g?.id??0),uuid:eS(l)}),C=t.segments;C.push(B),t.segments=C}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},Oai=class extends JE{viasProcessed=0;pcbVias=[];constructor(t,A){super(t,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],o=Zt(A,{x:i.x,y:i.y});let n;if(e){let g=i.subcircuit_connectivity_map_key;if(!g&&i.pcb_trace_id){const c=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(c&&("subcircuit_connectivity_map_key"in c&&(g=c.subcircuit_connectivity_map_key),!g&&c.source_trace_id)){const I=this.ctx.db.source_trace?.get(c.source_trace_id);if(I&&("subcircuit_connectivity_map_key"in I&&(g=I.subcircuit_connectivity_map_key),!g&&I.connected_source_net_ids?.length))for(const l of I.connected_source_net_ids){const B=this.ctx.db.source_net?.get(l);if(B?.subcircuit_connectivity_map_key){g=B.subcircuit_connectivity_map_key;break}}}}if(!g&&i.connection_name){const c=this.ctx.db.source_net?.get(i.connection_name);c?.subcircuit_connectivity_map_key&&(g=c.subcircuit_connectivity_map_key)}g&&(n=e.get(g))}const s=`via:${o.x},${o.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${n?.id??0}`,r=new KDA({at:[o.x,o.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:["F.Cu","B.Cu"],net:new TDA(n?.id??0),uuid:eS(s)}),a=t.vias;a.push(r),t.vias=a,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function Wai({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Zt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),o={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",n=(t.font_size||1)/1.5,s=new $D;s.size={width:n,height:n};const r=new Zj,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 XD({font:s});a!=="center"&&(g.justify=r);const c=t.ccw_rotation||0,I=new Dc([e.x,e.y,c]),l=new TwA({text:t.text,layer:o,effects:g});return l.position=I,l}var Zai=class extends JE{_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const e=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const n of e)if(!(!n.route||n.route.length<2))for(let s=0;s<n.route.length-1;s++){const r=n.route[s],a=n.route[s+1];if(!r||!a)continue;const g=Zt(A,{x:r.x,y:r.y}),c=Zt(A,{x:a.x,y:a.y}),l={top:"F.SilkS",bottom:"B.SilkS"}[n.layer]||n.layer||"F.SilkS",B=new az({start:{x:g.x,y:g.y},end:{x:c.x,y:c.y},layer:l,width:n.stroke_width||.15}),C=t.graphicLines;C.push(B),t.graphicLines=C}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(n=>!n.pcb_component_id)||[];for(const n of i){const s=Wai({textElement:n,c2kMatPcb:A});if(s){const r=t.graphicTexts;r.push(s),t.graphicTexts=r}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const n=o[0];if(!n){this.finished=!0;return}let s;if(n.outline&&n.outline.length>0)s=n.outline;else{const a=n.width?n.width/2:0,g=n.height?n.height/2:0;s=[{x:n.center.x-a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y+g},{x:n.center.x-a,y:n.center.y+g}]}const r=s.map(a=>Zt(A,a));for(let a=0;a<r.length;a++){const g=r[a],c=r[(a+1)%r.length];if(!g||!c)continue;const I=new az({start:{x:g.x,y:g.y},end:{x:c.x,y:c.y},layer:"Edge.Cuts",width:.1}),l=t.graphicLines;l.push(I),t.graphicLines=l}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Tue=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){this.ctx={db:va(t),circuitJson:t,kicadPcb:new PDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:sB(dr(100,100),yh(1,-1))},this.pipeline=[new Lai(t,this.ctx),new Uai(t,this.ctx),new Pai(t,this.ctx),new qai(t,this.ctx),new Oai(t,this.ctx),new Zai(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()}},Vai=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,o=A.pcbFilename??`${e}.kicad_pcb`,n=new Date().toISOString();this.ctx={db:va(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:n,modified:n},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:o},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5826
|
+
`)}};LA.register(KDA);var PDA=class IDe extends LA{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 IDe;for(const i of A){if(!Array.isArray(i)||i.length===0)throw new Error(`kicad_pcb encountered unsupported primitive child: ${JSON.stringify(i)}`);const o=LA.parsePrimitiveSexpr(i,{parentToken:this.token});if(!(o instanceof LA))throw new Error(`kicad_pcb expected SxClass child, received ${JSON.stringify(i)}`);e.consumeChild(o)}return e}consumeChild(A){if(A instanceof HDA){this._sxVersion=A;return}if(A instanceof YDA){this._sxGenerator=A;return}if(A instanceof JDA){this._sxGeneratorVersion=A;return}if(A instanceof LDA){this._sxGeneral=A;return}if(A instanceof jj){this._sxPaper=A;return}if(A instanceof FQe){this._sxTitleBlock=A;return}if(A instanceof UDA){this._sxLayers=A;return}if(A instanceof NDA){this._sxSetup=A;return}if(A instanceof L1){this._properties.push(A);return}if(A instanceof lz){this._nets.push(A);return}if(A instanceof RwA){this._footprints.push(A);return}if(A instanceof RQe){this._images.push(A);return}if(A instanceof WwA){this._segments.push(A);return}if(A instanceof az){this._grLines.push(A);return}if(A instanceof TwA){this._grTexts.push(A);return}if(A instanceof wEe){this._grPolys.push(A);return}if(A instanceof fEe){this._grRects.push(A);return}if(A instanceof KDA){this._vias.push(A);return}if(A instanceof kEe){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 HDA(A)}get generator(){return this._sxGenerator?.value}set generator(A){this._sxGenerator=A===void 0?void 0:new YDA(A)}get generatorVersion(){return this._sxGeneratorVersion?.value}set generatorVersion(A){this._sxGeneratorVersion=A===void 0?void 0:new JDA(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}};LA.register(PDA);var Mue=t=>LA.parse(t),JE=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")}},Sai=class extends JE{_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 jj;e.size=A?.name??"A4",t.paper=e,t.uuid=new Yi(crypto.randomUUID()),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Bz(t,A){if(t.manufacturer_part_number)return qDA(t.manufacturer_part_number);const e=bai(t.ftype),i=A?.footprinter_string;return qDA(i?`${e}_${i}`:e)}function bai(t){if(!t)return"component";let A=t.replace(/^simple_/,"");return A||"component"}function qDA(t){return t.replace(/[\\\/:\s]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"").trim()||"component"}function Nue(t){return t?t.match(/^([A-Za-z]+)/)?.[1]?.toUpperCase()??"U":"U"}var Lue={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"},_ai=/^[A-Za-z]+\d+$/;function Uue(t){return t?_ai.test(t.trim()):!1}function ODA(t){const A=t?.ftype;if(A&&Lue[A])return Lue[A];const e=t?.name;return Uue(e),Nue(e)}function xai(t){const A=t?.name;return Uue(A)?A.trim():`${ODA(t)}?`}function Hue(t){return t in mQ}function Yue(t,A,e){if(t.type!=="source_component")return A.symbol_name?Hue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`:"Device:Component";if(A.symbol_name)return Hue(A.symbol_name)?`Device:${A.symbol_name}`:`Custom:${A.symbol_name}`;const i=Bz(t,e);return`Device:${ODA(t)}_${i}`}var kai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx,e=new the,i=[],o=A.schematic_component.list();for(const s of o){const r=this.createLibrarySymbolForComponent(s);r&&i.push(r)}const n=A.schematic_net_label?.list?.()||[];for(const s of n)if(s.symbol_name){const r=s.source_net_id?A.source_net.get(s.source_net_id)?.is_power:!1,a=s.source_net_id?A.source_net.get(s.source_net_id)?.is_ground:!1;if(r||a){const 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(g=>g.source_component_id===e.source_component_id),o=t.symbol_name||(e.ftype==="simple_chip"?`generic_chip_${t.source_component_id}`:null);if(!o)return null;const n=this.getSymbolData(o,t);if(!n)return null;const s=Yue(e,t,i),r=e.ftype==="simple_chip",a=Bz(e,i);return this.createLibrarySymbol({libId:s,symbolData:n,isChip:r,schematicComponent:t,description:this.getDescription(e),keywords:this.getKeywords(e),fpFilters:this.getFpFilters(e),footprintRef:a?`tscircuit:${a}`:"",referencePrefix:ODA(e)})}createLibrarySymbolForNetLabel({netLabel:t,isPower:A,isGround:e}){const i=t.symbol_name;if(!i)return null;const o=mQ[i];if(!o)return null;const n=`Custom:${i}`;return this.createLibrarySymbol({libId:n,symbolData:o,isChip:!1,schematicComponent:void 0,description:A?"Power net label":e?"Ground net label":"Net symbol",keywords:A?"power net":e?"ground net":"net",fpFilters:"",referencePrefix:n.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,o=t.size?.height||1,n={type:"path",points:[{x:-i/2,y:-o/2},{x:i/2,y:-o/2},{x:i/2,y:o/2},{x:-i/2,y:o/2},{x:-i/2,y:-o/2}]},s=e.map(r=>{const a=r.center.x-t.center.x,g=r.center.y-t.center.y;return{x:a,y:g,labels:[r.display_pin_label||`${r.pin_number||1}`],pinNumber:r.pin_number||1}});return{center:{x:0,y:0},primitives:[n],ports:s,size:{width:i,height:o}}}createLibrarySymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i,description:o,keywords:n,fpFilters:s,footprintRef:r="",referencePrefix:a}){const g=new N1({libraryId:t,excludeFromSim:!1,inBom:!0,onBoard:!0}),c=new UQe;c.hide=!e,g._sxPinNumbers=c;const I=new HQe;I.offset=e?1.27:0,g._sxPinNames=I,this.addSymbolProperties({symbol:g,libId:t,description:o,keywords:n,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 Xj(!1),g}addSymbolProperties({symbol:t,libId:A,description:e,keywords:i,fpFilters:o,footprintRef:n="",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:n,id:2,at:[-1.778,0,90],hide:!0},{key:"Datasheet",value:"~",id:3,at:[0,0,0],hide:!0},{key:"Description",value:e,id:4,at:[0,0,0],hide:!0},{key:"ki_keywords",value:i,id:5,at:[0,0,0],hide:!0},{key:"ki_fp_filters",value:o,id:6,at:[0,0,0],hide:!0}];for(const g of a)t.properties.push(new rm({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){return t?.ftype==="simple_resistor"?"R_*":t?.ftype==="simple_capacitor"?"C_*":(t?.ftype==="simple_chip","*")}createDrawingSubsymbol({libId:t,symbolData:A,isChip:e}){const i=new N1({libraryId:`${t.split(":")[1]}_0_1`}),o=this.ctx.c2kMatSch?.a||15;for(const n of A.primitives||[])if(n.type==="path"&&n.points){const s=e?"background":"none",r=this.createPolylineFromPoints({points:n.points,scale:o,center:A.center,fillType:s});i.polylines.push(r)}else if(n.type==="circle"){const s=this.createCircleFromPrimitive({primitive:n,scale:o,center:A.center});i.circles.push(s)}return i}createPolylineFromPoints({points:t,scale:A,center:e,fillType:i}){const o=new MQe,n=e?.x??0,s=e?.y??0,r=yh(A,A),a=t.map(l=>{const B=Zt(r,{x:l.x-n,y:l.y-s});return new Nh(B.x,B.y)}),g=new JQ(a);o.points=g;const c=new Wj;c.width=.254,c.type="default",o.stroke=c;const I=new PQe;return I.type=i,o.fill=I,o}createCircleFromPrimitive({primitive:t,scale:A,center:e}){const i=new WQe,o=e?.x??0,n=e?.y??0,s=yh(A,A),r=Zt(s,{x:t.x-o,y:t.y-n}),a=i;a._sxCenter=new TQe(r.x,r.y),a._sxRadius=new KQe(t.radius*A);const g=new Wj;g.width=.254,g.type="default",a._sxStroke=g;const c=new qQe;return c.type=t.fill?"outline":"none",a._sxFill=c,i}createPinSubsymbol({libId:t,symbolData:A,isChip:e,schematicComponent:i}){const o=new N1({libraryId:`${t.split(":")[1]}_1_1`});for(let n=0;n<(A.ports?.length||0);n++){const s=A.ports[n],r=new ez;r.pinElectricalType="passive",r.pinGraphicStyle="line";const{x:a,y:g,angle:c}=this.calculatePinPosition(s,A.center,A.size,e,n,i);r.at=[a,g,c],r.length=e?6:1.27;const I=new $D;I.size={height:1.27,width:1.27};const l=new XD({font:I}),B=s.labels?.[0]||"~";r._sxName=new DmA({value:B,effects:l});const C=new $D;C.size={height:1.27,width:1.27};const Q=new XD({font:C}),h=s.pinNumber?.toString()||`${n+1}`;r._sxNumber=new VQe({value:h,effects:Q}),o.pins.push(r)}return o}calculatePinPosition(t,A,e,i,o,n){const s=this.ctx.c2kMatSch?.a||15;let r=t.x??0,a=t.y??0,g=!1;if(o!==void 0&&n){const d=this.ctx.db.schematic_port.list().filter(f=>f.schematic_component_id===n.schematic_component_id).sort((f,m)=>(f.pin_number||0)-(m.pin_number||0));if(d[o]){const f=d[o];r=f.center.x-n.center.x,a=f.center.y-n.center.y,g=!0}}let c,I;if(g)c=r,I=a;else{const d=A?.x??0,f=A?.y??0;c=r-d,I=a-f}const l=yh(s,s),B=Zt(l,{x:c,y:I});let C;if(i&&e){const d=e.width/2,f=e.height/2,m=Math.abs(c)/d,D=Math.abs(I)/f;C=m>D}else C=Math.abs(c)>Math.abs(I);let Q=B.x,h=B.y;const E=6;if(i&&e){const d=e.width/2*s,f=e.height/2*s;C?(Q=c>0?d:-d,h=I*s):(Q=c*s,h=I>0?f:-f)}let u=0;return C?c>0?i?(u=180,Q=Q+E):u=0:i?(u=0,Q=Q-E):u=180:I>0?i?(u=270,h=h+E):u=90:i?(u=90,h=h-E):u=270,{x:Q,y:h,angle:u}}createTextEffects(t,A){const e=new $D;return e.size={height:t,width:t},new XD({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Fai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_component.list();if(e.length===0){this.finished=!0;return}const i=[];for(const o of e){const n=o.source_component_id?A.source_component.get(o.source_component_id):null;if(!n||!this.ctx.c2kMatSch)continue;const{x:s,y:r}=Zt(this.ctx.c2kMatSch,{x:o.center.x,y:o.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(v=>v.source_component_id===n.source_component_id),I=Yue(n,o,c),l=new ymA(I);g._sxLibId=l;const{reference:B,value:C,description:Q}=this.getComponentMetadata(n),{refTextPos:h,valTextPos:E}=this.getTextPositions(o,{x:s,y:r}),u=new rm({key:"Reference",value:B,id:0,at:[h.x,h.y,0],effects:this.createTextEffects(1.27,!1)}),d=n.ftype==="simple_chip",f=new rm({key:"Value",value:C,id:1,at:[E.x,E.y,0],effects:this.createTextEffects(1.27,d)}),m=new rm({key:"Footprint",value:"",id:2,at:[s-1.778,r,90],effects:this.createTextEffects(1.27,!0)}),D=new rm({key:"Datasheet",value:"~",id:3,at:[s,r,0],effects:this.createTextEffects(1.27,!0)}),w=new rm({key:"Description",value:Q,id:4,at:[s,r,0],effects:this.createTextEffects(1.27,!0)});g.properties.push(u,f,m,D,w);const b=A.schematic_port.list().filter(v=>v.schematic_component_id===o.schematic_component_id).sort((v,U)=>(v.pin_number||0)-(U.pin_number||0));for(const v of b){const U=new ez;U.numberString=`${v.pin_number||1}`,U.uuid=crypto.randomUUID(),g.pins.push(U)}const k=new SmA,_=new _mA(""),M=new xmA(`/${t?.uuid?.value||""}`);M.reference=B,M.unit=1,_.paths.push(M),k.projects.push(_),g._sxInstances=k,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=Zt(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 o=t.symbol_name,n=mQ[o];if(!n)return{refTextPos:{x:A.x,y:A.y-6},valTextPos:{x:A.x,y:A.y+6}};let s=null,r=null;for(const B of n.primitives)B.type==="text"&&(B.text==="{REF}"?s=B:B.text==="{VAL}"&&(r=B));const a=n.center||{x:0,y:0},c=o.includes("_down")||o.includes("_up")?.15:0,I=s&&this.ctx.c2kMatSch?Zt(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?Zt(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=xai(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"}:{reference:e,value:A,description:"Component"}}createTextEffects(t,A=!1,e){const i=new $D;i.size={height:t,width:t};const o=e?new Zj({horizontal:e}):void 0;return new XD({font:i,hiddenText:A,justify:o})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Gai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx,e=A.schematic_net_label?.list?.()||[];if(e.length===0){this.finished=!0;return}if(!this.ctx.c2kMatSch){this.finished=!0;return}const i=[],o=[];for(const n of e){const s=n.text||"",r=n.symbol_name;if(r){const a=this.createSymbolFromNetLabel(n,s,r);a&&i.push(a)}else{const a=this.createGlobalLabel(n,s);a&&o.push(a)}}if(t&&i.length>0){const n=t.symbols||[];t.symbols=[...n,...i]}t&&o.length>0&&(t.globalLabels=[...t.globalLabels||[],...o]),this.finished=!0}createSymbolFromNetLabel(t,A,e){if(!this.ctx.c2kMatSch)return null;const{x:i,y:o}=Zt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),n=crypto.randomUUID(),s=new N1({at:[i,o,0],unit:1,excludeFromSim:!1,inBom:!0,onBoard:!0,dnp:!1,uuid:n,fieldsAutoplaced:!0}),r=`Custom:${e}`,a=new ymA(r);s._sxLibId=a;const g=e.includes("_up")||e.toLowerCase().includes("vcc"),c=g?-4:4,I=g?-6:6,l=new rm({key:"Reference",value:A,id:0,at:[i,o+c,0],effects:this.createTextEffects(1.27,!1)}),B=new rm({key:"Value",value:A,id:1,at:[i,o+I,0],effects:this.createTextEffects(1.27,!0)}),C=new rm({key:"Footprint",value:"",id:2,at:[i-1.778,o,90],effects:this.createTextEffects(1.27,!0)}),Q=new rm({key:"Datasheet",value:"~",id:3,at:[i,o,0],effects:this.createTextEffects(1.27,!0)}),h=new rm({key:"Description",value:`Power/Net symbol: ${A}`,id:4,at:[i,o,0],effects:this.createTextEffects(1.27,!0)});s.properties.push(l,B,C,Q,h);const E=new ez;E.numberString="1",E.uuid=crypto.randomUUID(),s.pins.push(E);const{kicadSch:u}=this.ctx,d=new SmA,f=new _mA(""),m=new xmA(`/${u?.uuid?.value||""}`);return m.reference=A,m.unit=1,f.paths.push(m),d.projects.push(f),s._sxInstances=d,s}createGlobalLabel(t,A){if(!this.ctx.c2kMatSch||!this.ctx.kicadSch)return null;const{x:e,y:i}=Zt(this.ctx.c2kMatSch,{x:t.anchor_position?.x??t.center?.x??0,y:t.anchor_position?.y??t.center?.y??0}),o=t.anchor_side||"left",s={left:0,right:180,top:270,bottom:90}[o]||0,a={left:{horizontal:"left"},right:{horizontal:"right"},top:{vertical:"top"},bottom:{vertical:"bottom"}}[o]||{},g=this.createTextEffects(1.27,!1);return Object.keys(a).length>0&&(g.justify=new Zj(a)),new Ihe({value:A,at:[e,i,s],effects:g,uuid:crypto.randomUUID(),fieldsAutoplaced:!0})}createTextEffects(t,A=!1){const e=new $D;return e.size={height:t,width:t},new XD({font:e,hiddenText:A})}getOutput(){if(!this.ctx.kicadSch)throw new Error("kicadSch is not initialized");return this.ctx.kicadSch}},Rai=class extends JE{_step(){const{kicadSch:t,db:A}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const e=A.schematic_trace.list();if(e.length===0){this.finished=!0;return}const i=[],o=[];for(const n of e){for(const s of n.edges){const r=this.createWireFromEdge(s);i.push(r)}for(const s of n.junctions){const r=this.createJunction(s);o.push(r)}}t.wires=i,t.junctions=o,this.finished=!0}createWireFromEdge(t){const A=new ohe;if(!this.ctx.c2kMatSch)throw new Error("Schematic transformation matrix not initialized in context");const e=Zt(this.ctx.c2kMatSch,{x:t.from.x,y:t.from.y}),i=Zt(this.ctx.c2kMatSch,{x:t.to.x,y:t.to.y}),o=e.x,n=e.y,s=i.x,r=i.y,a=new JQ([new Nh(o,n),new Nh(s,r)]);A.points=a;const g=new Wj;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}=Zt(this.ctx.c2kMatSch,{x:t.x,y:t.y}),i=new nhe({at:[A,e],diameter:0});return i.uuid=crypto.randomUUID(),i}getOutput(){return this.ctx.kicadSch}},vai=class extends JE{_step(){const{kicadSch:t}=this.ctx;if(!t)throw new Error("KicadSch instance not initialized in context");const A=new RmA,e=new Che;e.value="/";const i=new Qhe("1");e.pages=[i],A.paths=[e],t.sheetInstances=A,t.embeddedFonts=new Xj(!1),this.finished=!0}getOutput(){return this.ctx.kicadSch}};function Mai(t){const A=t.schematic_component.list(),e=t.schematic_trace.list();let i=1/0,o=1/0,n=-1/0,s=-1/0;for(const g of A){const c=g.size?.width??0,I=g.size?.height??0;i=Math.min(i,g.center.x-c/2),o=Math.min(o,g.center.y-I/2),n=Math.max(n,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),o=Math.min(o,c.from.y,c.to.y),n=Math.max(n,c.from.x,c.to.x),s=Math.max(s,c.from.y,c.to.y);i===1/0&&(i=0,o=0,n=0,s=0);const r=(i+n)/2,a=(o+s)/2;return{center:{x:r,y:a},bounds:{minX:i,minY:o,maxX:n,maxY:s}}}var Cz=[{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 Nai(t,A,e=20){const i=t+2*e,o=A+2*e;for(let n=0;n<Cz.length;n++){const s=Cz[n];if(i<=s.width&&o<=s.height)return s}return Cz[Cz.length-1]}var Jue=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){const e=va(t),{center:i,bounds:o}=Mai(e),n=(o.maxX-o.minX)*15,s=(o.maxY-o.minY)*15,r=Nai(n,s),a=r.width/2,g=r.height/2;this.ctx={db:e,circuitJson:t,kicadSch:new MmA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),schematicPaperSize:r,c2kMatSch:sB(dr(a,g),yh(15,-15),dr(-i.x,-i.y))},this.pipeline=[new Sai(t,this.ctx),new kai(t,this.ctx),new Fai(t,this.ctx),new Gai(t,this.ctx),new Rai(t,this.ctx),new vai(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()}},Lai=class extends JE{_step(){const{kicadPcb:t}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");t.version=20241229;const A=new jj;A.size="A4",t.paper=A;const e=new LDA;e.thickness=1.6,t.general=e;const i=new NDA;i.padToMaskClearance=0,t.setup=i;const o=new UDA,n=[new CB({index:0,name:"F.Cu",type:"signal"}),new CB({index:2,name:"B.Cu",type:"signal"}),new CB({index:9,name:"F.Adhes",type:"user"}),new CB({index:11,name:"B.Adhes",type:"user"}),new CB({index:13,name:"F.Paste",type:"user"}),new CB({index:15,name:"B.Paste",type:"user"}),new CB({index:5,name:"F.SilkS",type:"user"}),new CB({index:7,name:"B.SilkS",type:"user"}),new CB({index:1,name:"F.Mask",type:"user"}),new CB({index:3,name:"B.Mask",type:"user"}),new CB({index:20,name:"Dwgs.User",type:"user"}),new CB({index:21,name:"Cmts.User",type:"user"}),new CB({index:22,name:"Eco1.User",type:"user"}),new CB({index:23,name:"Eco2.User",type:"user"}),new CB({index:24,name:"Edge.Cuts",type:"user"}),new CB({index:25,name:"Margin",type:"user"}),new CB({index:17,name:"B.CrtYd",type:"user"}),new CB({index:16,name:"F.CrtYd",type:"user"}),new CB({index:19,name:"B.Fab",type:"user"}),new CB({index:18,name:"F.Fab",type:"user"})];o.definitions=n,t.layers=o,this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Uai=class extends JE{_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 o=Array.from(A.entries()).sort((r,a)=>r[0].localeCompare(a[0])),n=[];n.push(new lz(0,""));let s=1;for(const[r,a]of o){const g=new lz(s,a);n.push(g);const c={id:s,name:a};this.ctx.pcbNetMap.set(r,c),s++}t.nets=n,this.finished=!0}getOutput(){return this.ctx.kicadPcb}};function Hai(t){let A=0;for(let i=0;i<t.length;i++){const o=t.charCodeAt(i);A=(A<<5)-A+o,A=A&A}let e="";for(let i=0;i<4;i++){let o=A;for(let n=0;n<t.length;n++)o=(o<<5)-o+t.charCodeAt(n)+i*31,o=o&o;e+=Math.abs(o).toString(16).padStart(8,"0")}return e}function eS(t){const A=Hai(t);return`${A.slice(0,8)}-${A.slice(8,12)}-${A.slice(12,16)}-${A.slice(16,20)}-${A.slice(20,32)}`}function Yai({pcbPad:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){let s,r;if("x"in t&&"y"in t)s=t.x,r=t.y;else if("points"in t&&Array.isArray(t.points)){const u=t.points;s=u.reduce((d,f)=>d+f.x,0)/u.length,r=u.reduce((d,f)=>d+f.y,0)/u.length}else throw new Error("Pad must have either x/y coordinates or points array");const a=sB(i!==0?Tw(i*Math.PI/180):{a:1,b:0,c:0,d:1,e:0,f:0},yh(1,-1),dr(-A.x,-A.y)),g=Zt(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(yh(1,-1),dr(-s,-r)),f=u.map(D=>{const w=Zt(d,{x:D.x,y:D.y});return new Nh(w.x,w.y)}),m=new iwA;m.contours=[new JQ(f)],m.width=0,m.filled=!0,Q=new qhe,Q.addGraphic(m),l="custom",C=new _he,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:${n}:${e}:${g.x},${g.y}`,E=new oz({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:eS(h)});return C&&(E.options=C),Q&&(E.primitives=Q),o&&(E.net=new zmA(o.id,o.name)),E}function Jai({platedHole:t,componentCenter:A,padNumber:e,componentRotation:i=0,netInfo:o,componentId:n}){if(!("x"in t&&"y"in t))return null;const s=t.x-A.x,r=-(t.y-A.y),a=i!==0?Tw(i*Math.PI/180):Ld(),g=Zt(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=Zt(a,{x:-u.x,y:u.y}))}t.shape==="circle"?(c="circle",I=[t.outer_diameter,t.outer_diameter],l=new AS({diameter:t.hole_diameter,offset:Q})):t.shape==="pill"||t.shape==="oval"?(c="oval",I=[t.outer_width,t.outer_height],l=new AS({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 AS({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 AS({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 AS({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 AS({diameter:.8,offset:Q}));const h=`thruhole:${n}:${e}:${g.x},${g.y}`,E=new oz({number:String(e),padType:"thru_hole",shape:c,at:[g.x,g.y,B],size:I,drill:l,layers:["*.Cu","*.Mask"],removeUnusedLayers:!1,uuid:eS(h)});return o&&(E.net=new zmA(o.id,o.name)),E}function Tai({pcbHole:t,componentCenter:A,componentRotation:e=0}){if(!("x"in t&&"y"in t))return null;const i=t.x-A.x,o=-(t.y-A.y),n=e!==0?Tw(e*Math.PI/180):Ld(),s=Zt(n,{x:i,y:o});let r="circle",a,g;if(t.hole_shape==="circle"){r="circle";const c=t.hole_diameter;a=[c,c],g=new AS({diameter:c})}else if(t.hole_shape==="oval"){r="oval";const c=t.hole_width,I=t.hole_height;a=[c,I],g=new AS({oval:!0,diameter:c,width:I})}else{r="circle";const c="hole_diameter"in t?t.hole_diameter:1;a=[c,c],g=new AS({diameter:c})}return new oz({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 Kai({textElement:t,componentCenter:A,componentRotation:e=0}){if(!t.text||!t.anchor_position)return null;const i=t.anchor_position.x-A.x,o=-(t.anchor_position.y-A.y),n=e!==0?Tw(e*Math.PI/180):Ld(),s=Zt(n,{x:i,y:o}),r={x:s.x,y:s.y},g={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",c=(t.font_size||1)/1.5,I=new $D;I.size={width:c,height:c};const l=new XD({font:I}),B=t.ccw_rotation||0;return new rEe({type:"user",text:t.text,position:{x:r.x,y:r.y,angle:B},layer:g,effects:l})}var Pai=class extends JE{componentsProcessed=0;pcbComponents=[];getNetInfoForPcbPort(t){if(!t)return;const A=this.ctx.db.pcb_port?.get(t);if(!A)return;const e=A.source_port_id;if(!e)return;const i=this.ctx.db.source_port?.get(e);if(!i)return;const o=i.subcircuit_connectivity_map_key;if(o)return this.ctx.pcbNetMap?.get(o)}getCadComponentForPcbComponent(t){return(this.ctx.db.cad_component?.list()||[]).find(e=>e.pcb_component_id===t)}create3DModelsFromCadComponent(t,A){const e=[],i=t.model_step_url||t.model_wrl_url;if(!i)return e;const o=new kwA(i);if(t.position&&(o.offset={x:(t.position.x||0)-A.x,y:-((t.position.y||0)-A.y),z:t.position.z||0}),t.rotation&&(o.rotate={x:t.rotation.x||0,y:t.rotation.y||0,z:t.rotation.z||0}),t.model_unit_to_mm_scale_factor){const n=t.model_unit_to_mm_scale_factor;o.scale={x:n,y:n,z:n}}return e.push(o),e}constructor(t,A){super(t,A),this.pcbComponents=this.ctx.db.pcb_component.list()}_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.componentsProcessed>=this.pcbComponents.length){this.finished=!0;return}const e=this.pcbComponents[this.componentsProcessed],i=e.source_component_id?this.ctx.db.source_component.get(e.source_component_id):null,o=this.getCadComponentForPcbComponent(e.pcb_component_id),n=i?Bz(i,o):"Unknown",s=Zt(A,{x:e.center.x,y:e.center.y}),r=`footprint:${e.pcb_component_id}:${s.x},${s.y}`,a=new RwA({libraryLink:`tscircuit:${n}`,layer:"F.Cu",at:[s.x,s.y,e.rotation||0],uuid:eS(r)}),g=a.fpTexts,c=this.ctx.db.pcb_silkscreen_text?.list().filter(E=>E.pcb_component_id===e.pcb_component_id)||[];for(const E of c){const u=Kai({textElement:E,componentCenter:e.center,componentRotation:e.rotation||0});u&&(i?.name&&E.text===i.name&&(u.type="reference"),g.push(u))}a.fpTexts=g;const I=this.ctx.db.pcb_smtpad?.list().filter(E=>E.pcb_component_id===e.pcb_component_id)||[],l=a.fpPads;let B=1;for(const E of I){const u=this.getNetInfoForPcbPort(E.pcb_port_id),d=Yai({pcbPad:E,componentCenter:e.center,padNumber:B,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});l.push(d),B++}const C=this.ctx.db.pcb_plated_hole?.list().filter(E=>E.pcb_component_id===e.pcb_component_id)||[];for(const E of C){const u=this.getNetInfoForPcbPort(E.pcb_port_id),d=Jai({platedHole:E,componentCenter:e.center,padNumber:B,componentRotation:e.rotation||0,netInfo:u,componentId:e.pcb_component_id});d&&(l.push(d),B++)}const Q=this.ctx.db.pcb_hole?.list().filter(E=>E.subcircuit_id===e.subcircuit_id)||[];for(const E of Q){const u=Tai({pcbHole:E,componentCenter:e.center,componentRotation:e.rotation||0});u&&l.push(u)}if(a.fpPads=l,o){const E=this.create3DModelsFromCadComponent(o,e.center);E.length>0&&(a.models=E)}const h=t.footprints;h.push(a),t.footprints=h,this.componentsProcessed++}getOutput(){return this.ctx.kicadPcb}},qai=class extends JE{tracesProcessed=0;pcbTraces=[];constructor(t,A){super(t,A),this.pcbTraces=this.ctx.db.pcb_trace.list()}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.tracesProcessed>=this.pcbTraces.length){this.finished=!0;return}const i=this.pcbTraces[this.tracesProcessed];if(!i.route||i.route.length<2){this.tracesProcessed++;return}for(let o=0;o<i.route.length-1;o++){const n=i.route[o],s=i.route[o+1],r=Zt(A,{x:n.x,y:n.y}),a=Zt(A,{x:s.x,y:s.y});let g;if(e){let Q=i.subcircuit_connectivity_map_key;if(!Q&&i.source_trace_id){const 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 E of h.connected_source_net_ids){const u=this.ctx.db.source_net?.get(E);if(u?.subcircuit_connectivity_map_key){Q=u.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&&(g=e.get(Q))}const I={top:"F.Cu",bottom:"B.Cu"}[n.layer]||n.layer||"F.Cu",l=`segment:${r.x},${r.y}:${a.x},${a.y}:${I}:${g?.id??0}`,B=new WwA({start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},layer:I,width:i.width||.25,net:new gz(g?.id??0),uuid:eS(l)}),C=t.segments;C.push(B),t.segments=C}this.tracesProcessed++}getOutput(){return this.ctx.kicadPcb}},Oai=class extends JE{viasProcessed=0;pcbVias=[];constructor(t,A){super(t,A),this.pcbVias=this.ctx.db.pcb_via?.list()||[]}_step(){const{kicadPcb:t,c2kMatPcb:A,pcbNetMap:e}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");if(this.viasProcessed>=this.pcbVias.length){this.finished=!0;return}const i=this.pcbVias[this.viasProcessed],o=Zt(A,{x:i.x,y:i.y});let n;if(e){let g=i.subcircuit_connectivity_map_key;if(!g&&i.pcb_trace_id){const c=this.ctx.db.pcb_trace?.get(i.pcb_trace_id);if(c&&("subcircuit_connectivity_map_key"in c&&(g=c.subcircuit_connectivity_map_key),!g&&c.source_trace_id)){const I=this.ctx.db.source_trace?.get(c.source_trace_id);if(I&&("subcircuit_connectivity_map_key"in I&&(g=I.subcircuit_connectivity_map_key),!g&&I.connected_source_net_ids?.length))for(const l of I.connected_source_net_ids){const B=this.ctx.db.source_net?.get(l);if(B?.subcircuit_connectivity_map_key){g=B.subcircuit_connectivity_map_key;break}}}}if(!g&&i.connection_name){const c=this.ctx.db.source_net?.get(i.connection_name);c?.subcircuit_connectivity_map_key&&(g=c.subcircuit_connectivity_map_key)}g&&(n=e.get(g))}const s=`via:${o.x},${o.y}:${i.outer_diameter||.8}:${i.hole_diameter||.4}:${n?.id??0}`,r=new KDA({at:[o.x,o.y],size:i.outer_diameter||.8,drill:i.hole_diameter||.4,layers:["F.Cu","B.Cu"],net:new TDA(n?.id??0),uuid:eS(s)}),a=t.vias;a.push(r),t.vias=a,this.viasProcessed++}getOutput(){return this.ctx.kicadPcb}};function Wai({textElement:t,c2kMatPcb:A}){if(!t.text||!t.anchor_position)return null;const e=Zt(A,{x:t.anchor_position.x,y:t.anchor_position.y}),o={top:"F.SilkS",bottom:"B.SilkS"}[t.layer]||t.layer||"F.SilkS",n=(t.font_size||1)/1.5,s=new $D;s.size={width:n,height:n};const r=new Zj,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 XD({font:s});a!=="center"&&(g.justify=r);const c=t.ccw_rotation||0,I=new Dc([e.x,e.y,c]),l=new TwA({text:t.text,layer:o,effects:g});return l.position=I,l}var Zai=class extends JE{_step(){const{kicadPcb:t,c2kMatPcb:A}=this.ctx;if(!t)throw new Error("KicadPcb instance not initialized in context");if(!A)throw new Error("PCB transformation matrix not initialized in context");const e=this.ctx.db.pcb_silkscreen_path?.list()||[];for(const n of e)if(!(!n.route||n.route.length<2))for(let s=0;s<n.route.length-1;s++){const r=n.route[s],a=n.route[s+1];if(!r||!a)continue;const g=Zt(A,{x:r.x,y:r.y}),c=Zt(A,{x:a.x,y:a.y}),l={top:"F.SilkS",bottom:"B.SilkS"}[n.layer]||n.layer||"F.SilkS",B=new az({start:{x:g.x,y:g.y},end:{x:c.x,y:c.y},layer:l,width:n.stroke_width||.15}),C=t.graphicLines;C.push(B),t.graphicLines=C}const i=this.ctx.db.pcb_silkscreen_text?.list().filter(n=>!n.pcb_component_id)||[];for(const n of i){const s=Wai({textElement:n,c2kMatPcb:A});if(s){const r=t.graphicTexts;r.push(s),t.graphicTexts=r}}const o=this.ctx.db.pcb_board?.list()||[];if(o.length>0){const n=o[0];if(!n){this.finished=!0;return}let s;if(n.outline&&n.outline.length>0)s=n.outline;else{const a=n.width?n.width/2:0,g=n.height?n.height/2:0;s=[{x:n.center.x-a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y-g},{x:n.center.x+a,y:n.center.y+g},{x:n.center.x-a,y:n.center.y+g}]}const r=s.map(a=>Zt(A,a));for(let a=0;a<r.length;a++){const g=r[a],c=r[(a+1)%r.length];if(!g||!c)continue;const I=new az({start:{x:g.x,y:g.y},end:{x:c.x,y:c.y},layer:"Edge.Cuts",width:.1}),l=t.graphicLines;l.push(I),t.graphicLines=l}}this.finished=!0}getOutput(){return this.ctx.kicadPcb}},Tue=class{ctx;pipeline;currentStageIndex=0;finished=!1;get currentStage(){return this.pipeline[this.currentStageIndex]}constructor(t){this.ctx={db:va(t),circuitJson:t,kicadPcb:new PDA({generator:"circuit-json-to-kicad",generatorVersion:"0.0.1"}),c2kMatPcb:sB(dr(100,100),yh(1,-1))},this.pipeline=[new Lai(t,this.ctx),new Uai(t,this.ctx),new Pai(t,this.ctx),new qai(t,this.ctx),new Oai(t,this.ctx),new Zai(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()}},Vai=class{ctx;project;constructor(t,A={}){const e=A.projectName??t?.project?.name??"circuit-json-project",i=A.schematicFilename??`${e}.kicad_sch`,o=A.pcbFilename??`${e}.kicad_pcb`,n=new Date().toISOString();this.ctx={db:va(t),circuitJson:t},this.project={version:1,head:{generator:"circuit-json-to-kicad",generator_version:"0.0.1",project_name:e,created:n,modified:n},meta:{version:1},text_variables:{},libraries:{pinned_symbol_libs:[],pinned_footprint_libs:[]},boards:[],cvpcb:{meta:{version:0}},erc:{meta:{version:0},erc_exclusions:[]},net_settings:{meta:{version:1},last_net_id:0,classes:[]},pcbnew:{page_layout_descr_file:"",last_paths:{}},schematic:{meta:{version:1},page_layout_descr_file:"",last_opened_files:[i]},board:{meta:{version:1},last_opened_board:o},sheets:[[Math.random().toString(36).substring(2,15),"Root"]]}}runUntilFinished(){}getOutput(){return this.project}getOutputString(){return`${JSON.stringify(this.project,null,2)}
|
|
5827
5827
|
`}},jai=class extends JE{_step(){const t=new Jue(this.ctx.circuitJson);t.runUntilFinished(),this.ctx.kicadSchString=t.getOutputString();const A=new Tue(this.ctx.circuitJson);A.runUntilFinished(),this.ctx.kicadPcbString=A.getOutputString(),this.finished=!0}getOutput(){return this.ctx.libraryOutput}},zai=class extends JE{isCustomSymbol(t){return t?.startsWith("Custom:")??!1}_step(){const t=this.ctx.kicadSchString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("Schematic content not available. Run GenerateKicadSchAndPcbStage first.");const e=new Map;try{const o=Mue(t).find(r=>r instanceof MmA);if(!o){this.ctx.symbolEntries=[],this.finished=!0;return}const n=o.libSymbols;if(!n){this.ctx.symbolEntries=[],this.finished=!0;return}const s=n.symbols??[];for(const r of s){const a=this.isCustomSymbol(r.libraryId),g=this.sanitizeSymbolName(r.libraryId);e.has(g)||(r.libraryId=g,this.updateFootprintProperty(r,A),e.set(g,{symbolName:g,symbol:r,isBuiltin:!a}))}}catch(i){console.warn("Failed to parse schematic for symbol extraction:",i)}this.ctx.symbolEntries=Array.from(e.values()),this.finished=!0}updateFootprintProperty(t,A){const e=t.properties??[];for(const i of e)if(i.key==="Footprint"&&i.value){const o=i.value.split(":");o.length>1?i.value=`${A}:${o[1]}`:i.value.trim()&&(i.value=`${A}:${i.value}`)}}sanitizeSymbolName(t){if(!t)return"symbol";const A=t.split(":");return(A.length>1?A[1]:A[0])?.replace(/[\\\/]/g,"-").trim()||"symbol"}getOutput(){return this.ctx.libraryOutput}};function Xai(t){const A=t.split(/[/\\]/);return A[A.length-1]||t}var $ai=class extends JE{findCustomFootprintNames(){const t=new Set,A=this.ctx.db.cad_component?.list()??[],e=this.ctx.db.source_component;for(const i of A)if(!i.footprinter_string){const o=i.source_component_id?e?.get(i.source_component_id):null;if(o){const n=Bz(o,i);t.add(n)}}return t}_step(){const t=this.ctx.kicadPcbString,A=this.ctx.fpLibraryName??"tscircuit";if(!t)throw new Error("PCB content not available. Run GenerateKicadSchAndPcbStage first.");const e=this.findCustomFootprintNames(),i=new Map;try{const n=Mue(t).find(r=>r instanceof PDA);if(!n){this.ctx.footprintEntries=[],this.finished=!0;return}const s=n.footprints??[];for(const r of s){const a=this.sanitizeFootprint({footprint:r,fpLibraryName:A,customFootprintNames:e});i.has(a.footprintName)||i.set(a.footprintName,a)}}catch(o){console.warn("Failed to parse PCB for footprint extraction:",o)}this.ctx.footprintEntries=Array.from(i.values()),this.finished=!0}sanitizeFootprint({footprint:t,fpLibraryName:A,customFootprintNames:e}){const o=(t.libraryLink??"footprint").split(":"),n=(o.length>1?o[1]:o[0])?.replace(/[\\\/]/g,"-").trim()||"footprint",s=!e.has(n);if(t.libraryLink=n,t.position=Dc.from([0,0,0]),t.locked=!1,t.placed=!1,t.descr||(t.descr=""),t.tags||(t.tags=""),t.embeddedFonts||(t.embeddedFonts=new Xj(!1)),!t.attr){const C=new fhe,Q=(t.fpPads??[]).map(h=>h.padType);Q.some(h=>h.includes("thru_hole"))?C.type="through_hole":Q.some(h=>h.includes("smd"))&&(C.type="smd"),t.attr=C}t.uuid=void 0,t.path=void 0,t.sheetfile=void 0,t.sheetname=void 0;const r=new $D;r.size={width:1.27,height:1.27},r.thickness=.15;const a=new XD({font:r});t.properties=[new L1({key:"Reference",value:"Ref**",position:[0,0,0],layer:"F.SilkS",uuid:eS(`${n}-property-Reference`),effects:a}),new L1({key:"Value",value:"Val**",position:[0,0,0],layer:"F.Fab",uuid:eS(`${n}-property-Value`),effects:a}),new L1({key:"Datasheet",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:eS(`${n}-property-Datasheet`),effects:a}),new L1({key:"Description",value:"",position:[0,0,0],layer:"F.Fab",hidden:!0,uuid:eS(`${n}-property-Description`),effects:a})];const g=t.fpTexts??[];for(const C of g)C.uuid=void 0,C.type==="reference"?C.text="REF**":C.type==="value"&&C.text.trim().length===0&&(C.text=n);t.fpTexts=g;const c=t.fpPads??[];for(let C=0;C<c.length;C++){const Q=c[C];Q&&(Q.uuid=eS(`${n}-pad-${Q.number??C}`),Q.net=void 0)}t.fpPads=c;const I=t.models??[],l=[],B=[];for(const C of I)if(C.path){const Q=Xai(C.path),h=`../../3dmodels/${A}.3dshapes/${Q}`,E=new kwA(h);C.offset&&(E.offset=C.offset),C.scale&&(E.scale=C.scale),C.rotate&&(E.rotate=C.rotate),l.push(E),B.push(C.path)}return t.models=l,{footprintName:n,kicadModString:t.getString(),model3dSourcePaths:B,isBuiltin:s}}getOutput(){return this.ctx.libraryOutput}},Agi=20211014,egi="circuit-json-to-kicad",tgi=class extends JE{_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 Ahe({version:Agi,generator:egi,symbols:t.map(e=>e.symbol)}).getString()}getOutput(){return this.ctx.libraryOutput}},igi=class extends JE{_step(){const t=this.ctx.libraryName??"tscircuit",A=this.ctx.fpLibraryName??"tscircuit",e=this.ctx.footprintEntries??[],i=this.ctx.symbolEntries??[],o=new Set;for(const r of e)for(const a of r.model3dSourcePaths)o.add(a);const n=this.generateFpLibTable(A),s=this.generateSymLibTable(t);this.ctx.libraryOutput||(this.ctx.libraryOutput={kicadSymString:"",symbols:[],footprints:[],fpLibTableString:"",symLibTableString:"",model3dSourcePaths:[]}),this.ctx.libraryOutput.symbols=i,this.ctx.libraryOutput.footprints=e,this.ctx.libraryOutput.fpLibTableString=n,this.ctx.libraryOutput.symLibTableString=s,this.ctx.libraryOutput.model3dSourcePaths=Array.from(o),this.finished=!0}generateFpLibTable(t){return`(fp_lib_table
|
|
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
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.1232-libonly",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/tscircuit/tscircuit"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
-
"cli.mjs",
|
|
14
13
|
"globals.d.ts"
|
|
15
14
|
],
|
|
16
15
|
"scripts": {
|
|
@@ -29,10 +28,6 @@
|
|
|
29
28
|
},
|
|
30
29
|
"./browser": "./dist/browser.min.js"
|
|
31
30
|
},
|
|
32
|
-
"bin": {
|
|
33
|
-
"tsci": "cli.mjs",
|
|
34
|
-
"tscircuit": "cli.mjs"
|
|
35
|
-
},
|
|
36
31
|
"devDependencies": {
|
|
37
32
|
"@types/bun": "^1.2.16",
|
|
38
33
|
"esbuild": "^0.20.2",
|
|
@@ -54,7 +49,6 @@
|
|
|
54
49
|
"@tscircuit/checks": "^0.0.87",
|
|
55
50
|
"@tscircuit/circuit-json-flex": "^0.0.3",
|
|
56
51
|
"@tscircuit/circuit-json-util": "^0.0.77",
|
|
57
|
-
"@tscircuit/cli": "^0.1.844",
|
|
58
52
|
"@tscircuit/copper-pour-solver": "^0.0.14",
|
|
59
53
|
"@tscircuit/core": "^0.0.1000",
|
|
60
54
|
"@tscircuit/eval": "^0.0.617",
|
|
@@ -65,7 +59,7 @@
|
|
|
65
59
|
"@tscircuit/miniflex": "^0.0.4",
|
|
66
60
|
"@tscircuit/ngspice-spice-engine": "^0.0.8",
|
|
67
61
|
"@tscircuit/props": "^0.0.457",
|
|
68
|
-
"@tscircuit/runframe": "^0.0.
|
|
62
|
+
"@tscircuit/runframe": "^0.0.1549",
|
|
69
63
|
"@tscircuit/schematic-match-adapt": "^0.0.16",
|
|
70
64
|
"@tscircuit/schematic-trace-solver": "^v0.0.45",
|
|
71
65
|
"@tscircuit/simple-3d-svg": "^0.0.41",
|
|
@@ -108,4 +102,4 @@
|
|
|
108
102
|
"tslib": "^2.8.1",
|
|
109
103
|
"zod": "^3.25.67"
|
|
110
104
|
}
|
|
111
|
-
}
|
|
105
|
+
}
|
package/cli.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
|
|
6
|
-
// Use require to import package.json
|
|
7
|
-
const packageJson = require("./package.json");
|
|
8
|
-
global.TSCIRCUIT_VERSION = packageJson.version;
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
await import("@tscircuit/cli");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
main();
|