@tscircuit/runframe 0.0.1591 → 0.0.1593

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1730,7 +1730,7 @@ var useErrorTelemetry = ({
1730
1730
  };
1731
1731
 
1732
1732
  // package.json
1733
- var version = "0.0.1590";
1733
+ var version = "0.0.1592";
1734
1734
  var package_default = {
1735
1735
  name: "@tscircuit/runframe",
1736
1736
  main: "dist/preview.js",
@@ -1782,7 +1782,7 @@ var package_default = {
1782
1782
  "@tscircuit/3d-viewer": "^0.0.512",
1783
1783
  "@tscircuit/assembly-viewer": "^0.0.5",
1784
1784
  "@tscircuit/create-snippet-url": "^0.0.9",
1785
- "@tscircuit/eval": "^0.0.625",
1785
+ "@tscircuit/eval": "^0.0.627",
1786
1786
  "@tscircuit/circuit-json-util": "^0.0.75",
1787
1787
  "@tscircuit/fake-snippets": "^0.0.163",
1788
1788
  "@tscircuit/file-server": "^0.0.32",
@@ -1800,7 +1800,7 @@ var package_default = {
1800
1800
  autoprefixer: "^10.4.20",
1801
1801
  "chokidar-cli": "^3.0.0",
1802
1802
  "circuit-json-to-bom-csv": "^0.0.8",
1803
- "circuit-json-to-gerber": "^0.0.46",
1803
+ "circuit-json-to-gerber": "^0.0.47",
1804
1804
  "circuit-json-to-gltf": "^0.0.56",
1805
1805
  "circuit-json-to-kicad": "^0.0.71",
1806
1806
  "circuit-json-to-lbrn": "^0.0.4",
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  linkify,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-MK7BHAXD.js";
11
+ } from "./chunk-YWNRR7IA.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  useRunFrameStore,
35
35
  useRunnerStore,
36
36
  useStyles
37
- } from "./chunk-MK7BHAXD.js";
37
+ } from "./chunk-YWNRR7IA.js";
38
38
 
39
39
  // lib/components/RunFrame/RunFrame.tsx
40
40
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -5682,7 +5682,7 @@ test("${g} should solve problem correctly", () => {
5682
5682
  // Add more specific assertions based on expected output
5683
5683
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5684
5684
  })
5685
- `,c=new Blob([I],{type:"text/plain"}),l=URL.createObjectURL(c),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},qgt=e=>e.activeSubSolver?[e,...qgt(e.activeSubSolver)]:[e],BWe=({solver:e})=>{const A=qgt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(lWe,{solver:t})]},t.constructor.name))})},CWe=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},I=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},c=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(BWe,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:I,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:c,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},QWe=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},EWe=(e,A)=>{const i=e.pipelineDef[A].solverName,n=QWe(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let I=0;n==="Completed"?I=1:n==="In Progress"&&o&&(I=o.progress??0);const c=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:o??null}},hWe=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},uWe=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},dWe=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),pWe=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=dWe(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},qpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=qpA(i));return A},fWe=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=qpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},yWe=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>EWe(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):fWe(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(hWe,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(uWe,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(pWe,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},mWe=class extends en.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function wWe({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)I(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)I(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;I(h,u),I(h+d,u+f)}for(const Q of n){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const Q of o)I(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,l=s-c,B=r-c,C=Math.max(1,a-s+2*c),E=Math.max(1,g-r+2*c);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),o.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var DWe=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(I=>I+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=e.pipelineDef!==void 0,g=I=>{const c=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(l=>l.solverName===I);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(CWe,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(mWe,{fallback:Z.jsx(wWe,{graphics:s}),children:Z.jsx(cWe,{graphics:s})}),a&&Z.jsx(yWe,{solver:e,onStepUntilPhase:g})]})};const SWe=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},bWe=e=>e.toLowerCase().includes("pack")?DGe:e.toLowerCase().includes("rout")?GGe:EGe,xWe=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);SWe();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=irA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(irA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const I=bWe(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(dD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(DWe,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Ogt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{UK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{UK.captureException(n,{error_type:i.type})}catch{}}},[t])},Wgt="0.0.1590",_We={version:Wgt},OpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},WpA=new Map,I9=e=>{const A=WpA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},kWe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=WpA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return WpA.set(t.name,n),{type:"tracked",store:e,...n}},Zgt=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(OpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(OpA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:I,...c}=kWe(r,g,a);let l=!0;n.setState=(E,Q,h)=>{const u=t(E,Q);if(!l)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...I9(a.name),[r]:n.getState()}),u)};const B=(...E)=>{const Q=l;l=!1,t(...E),l=Q},C=e(n.setState,i,n);if(c.type==="untracked"?I?.init(C):(c.stores[c.store]=n,I?.init(Object.fromEntries(Object.entries(c.stores).map(([E,Q])=>[E,E===c.store?C:Q.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let E=!1;const Q=n.dispatch;n.dispatch=(...h)=>{(OpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return I.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ZpA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){B(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5685
+ `,c=new Blob([I],{type:"text/plain"}),l=URL.createObjectURL(c),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:n,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},qgt=e=>e.activeSubSolver?[e,...qgt(e.activeSubSolver)]:[e],BWe=({solver:e})=>{const A=qgt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(lWe,{solver:t})]},t.constructor.name))})},CWe=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),n&&n(e))},I=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&e.solved&&n(e);return}e.step(),A()},t))},c=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},l=()=>{if(e.solved||e.failed||o)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&n&&n(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,o]);const B=e.getCurrentPhase!==void 0,C=B?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(BWe,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:I,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),Z.jsx("button",{onClick:l,disabled:e.solved||e.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),B&&Z.jsx("button",{onClick:c,disabled:e.solved||e.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},QWe=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},EWe=(e,A)=>{const i=e.pipelineDef[A].solverName,n=QWe(e,A),o=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(n==="Completed"){const l=e.pipelineDef[A+1],B=l?e.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let I=0;n==="Completed"?I=1:n==="In Progress"&&o&&(I=o.progress??0);const c=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:o??null}},hWe=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},uWe=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},dWe=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),pWe=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=dWe(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>Z.jsxs("div",{children:[i,": ",String(n)]},i))})]})},qpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=qpA(i));return A},fWe=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=qpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},yWe=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>EWe(e,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):fWe(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(hWe,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(uWe,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(pWe,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},mWe=class extends en.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function wWe({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],n=e.circles??[],o=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)I(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)I(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;I(h,u),I(h+d,u+f)}for(const Q of n){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const Q of o)I(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,l=s-c,B=r-c,C=Math.max(1,a-s+2*c),E=Math.max(1,g-r+2*c);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),n.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),o.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var DWe=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[n,o]=AA.useReducer(I=>I+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[e,n]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=e.pipelineDef!==void 0,g=I=>{const c=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(l=>l.solverName===I);)e.step();o()}};return Z.jsxs("div",{children:[Z.jsx(CWe,{solver:e,triggerRender:o,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(mWe,{fallback:Z.jsx(wWe,{graphics:s}),children:Z.jsx(cWe,{graphics:s})}),a&&Z.jsx(yWe,{solver:e,onStepUntilPhase:g})]})};const SWe=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},bWe=e=>e.toLowerCase().includes("pack")?DGe:e.toLowerCase().includes("rout")?GGe:EGe,xWe=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);SWe();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),n=AA.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=AA.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=irA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(irA).join(", ")}`,classFound:!1};try{const a=o.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[o]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const I=bWe(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?Z.jsx(dD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:Z.jsx(DWe,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Ogt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{UK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{UK.captureException(n,{error_type:i.type})}catch{}}},[t])},Wgt="0.0.1592",_We={version:Wgt},OpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},WpA=new Map,I9=e=>{const A=WpA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},kWe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=WpA.get(t.name);if(i)return{type:"tracked",store:e,...i};const n={connection:A.connect(t),stores:{}};return WpA.set(t.name,n),{type:"tracked",store:e,...n}},Zgt=(e,A={})=>(t,i,n)=>{const{enabled:o,anonymousActionType:s,store:r,...a}=A;let g;try{g=(o??(OpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(OpA?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,n);const{connection:I,...c}=kWe(r,g,a);let l=!0;n.setState=(E,Q,h)=>{const u=t(E,Q);if(!l)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...I9(a.name),[r]:n.getState()}),u)};const B=(...E)=>{const Q=l;l=!1,t(...E),l=Q},C=e(n.setState,i,n);if(c.type==="untracked"?I?.init(C):(c.stores[c.store]=n,I?.init(Object.fromEntries(Object.entries(c.stores).map(([E,Q])=>[E,E===c.store?C:Q.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let E=!1;const Q=n.dispatch;n.dispatch=(...h)=>{(OpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return I.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return ZpA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){B(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5686
5686
  [zustand devtools middleware] Unsupported __setState action format.
5687
5687
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5688
5688
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
@@ -5739,7 +5739,7 @@ ${A}%`}}),l9e=Vc({command_code:"TD",schema:jA({command_code:bA("TD").default("TD
5739
5739
  20,1,$1+$1,$4,$5,$6,$7,0*
5740
5740
  20,1,$1+$1,$6,$7,$8,$9,0*
5741
5741
  20,1,$1+$1,$8,$9,$2,$3,0*
5742
- `.trim()}).add("comment",{comment:"APERTURE MACROS END"}).build())};function K9e(e){const A=e.filter(i=>i.type==="pcb_trace"),t={};for(const i of A)for(const n of i.route)n.route_type==="wire"&&(t[n.layer]=t[n.layer]||new Set,t[n.layer].add(n.width));return{top:Array.from(t.top||[]),bottom:Array.from(t.bottom||[])}}function P9e({glayer:e,soup:A,glayer_name:t}){const i=()=>{const s=e.reduce((r,a)=>a.command_code==="ADD"?Math.max(r,a.aperture_number):r,0);return s===0?10:s+1};e.push(...zI().add("comment",{comment:"aperture START LIST"}).build());const n=K9e(A);for(const s of n[t.startsWith("F_")?"top":"bottom"])e.push(...zI().add("define_aperture_template",{aperture_number:i(),standard_template_code:"C",diameter:s}).build());const o=q9e(A,t.startsWith("F_")?"top":"bottom");for(const s of o)e.push(...zI().add("define_aperture_template",{aperture_number:i(),...s}).build());e.push(...zI().add("delete_attribute",{}).add("comment",{comment:"aperture END LIST"}).build())}var Bct=e=>{if(e.shape==="rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};if(e.shape==="circle")return{standard_template_code:"C",diameter:e.radius*2};if(e.shape==="rotated_rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};throw e.shape==="polygon"?new Error("Polygon SMT pads are drawn as regions, not apertures"):new Error(`Unsupported shape ${e.shape}`)},Cct=e=>{if("stroke_width"in e)return{standard_template_code:"C",diameter:e.stroke_width};throw new Error(`Provide stroke_width for: ${e}`)},Qct=e=>{if("font_size"in e)return{standard_template_code:"C",diameter:e.font_size/8};throw new Error(`Provide font_size for: ${e}`)},Ect=e=>{if("font_size"in e)return{standard_template_code:"C",diameter:e.font_size/8};throw new Error(`Provide font_size for: ${e}`)},hct=e=>{if(e.shape==="rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};if(e.shape==="rotated_rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};if(e.shape==="circle")return{standard_template_code:"C",diameter:e.radius*2};if(e.shape==="pill"){if(!("width"in e&&"height"in e))throw new Error("Invalid pill shape in getApertureConfigFromPcbPlatedHole: missing dimensions");return e.width>=e.height?{macro_name:"HORZPILL",x_size:e.width,y_size:e.height,circle_diameter:Math.min(e.width,e.height),circle_center_offset:e.width/2}:{macro_name:"VERTPILL",x_size:e.width,y_size:e.height,circle_diameter:Math.min(e.width,e.height),circle_center_offset:e.height/2}}throw new Error(`Unsupported shape ${e.shape}`)},uct=e=>{if(e.shape==="circle"){if(!("outer_diameter"in e&&"hole_diameter"in e))throw new Error("Invalid circle shape in getApertureConfigFromPcbPlatedHole: missing diameters");return{standard_template_code:"C",diameter:e.outer_diameter}}if(e.shape==="pill"){if(!("outer_width"in e&&"outer_height"in e))throw new Error("Invalid pill shape in getApertureConfigFromPcbPlatedHole: missing dimensions");return e.outer_width>e.outer_height?{macro_name:"HORZPILL",x_size:e.outer_width,y_size:e.outer_height,circle_diameter:Math.min(e.outer_width,e.outer_height),circle_center_offset:e.outer_width/2}:{macro_name:"VERTPILL",x_size:e.outer_width,y_size:e.outer_height,circle_diameter:Math.min(e.outer_width,e.outer_height),circle_center_offset:e.outer_height/2}}const A=e.shape;if(A==="circular_hole_with_rect_pad"||A==="pill_hole_with_rect_pad"||A==="rotated_pill_hole_with_rect_pad"){if(!("rect_pad_width"in e&&"rect_pad_height"in e))throw new Error(`Invalid ${A} shape in getApertureConfigFromPcbPlatedHole: missing dimensions`);return{standard_template_code:"R",x_size:e.rect_pad_width,y_size:e.rect_pad_height}}throw new Error(`Unsupported shape in getApertureConfigFromPcbPlatedHole: ${e.shape}`)},dct=e=>{if(!("hole_diameter"in e))throw new Error(`Invalid shape called in getApertureConfigFromCirclePcbHole: ${e.hole_shape}`);return{standard_template_code:"C",diameter:e.hole_diameter}},pct=e=>{if(!("outer_diameter"in e))throw new Error("outer_diameter not specified in getApertureConfigFromPcbVia");return{standard_template_code:"C",diameter:e.outer_diameter}};function q9e(e,A){const t=[],i=new Set,n=o=>{const s=RVe(o);i.has(s)||(t.push(o),i.add(s))};for(const o of e)o.type==="pcb_smtpad"?o.layer===A&&o.shape!=="polygon"&&n(Bct(o)):o.type==="pcb_solder_paste"?o.layer===A&&n(hct(o)):o.type==="pcb_plated_hole"?o.layers.includes(A)&&n(uct(o)):o.type==="pcb_hole"?o.hole_shape==="circle"?n(dct(o)):console.warn("NOT IMPLEMENTED: drawing gerber for non circle holes"):o.type==="pcb_via"?n(pct(o)):o.type==="pcb_silkscreen_path"?n(Cct(o)):o.type==="pcb_silkscreen_text"?n(Qct(o)):o.type==="pcb_copper_text"&&o.layer===A&&n(Ect(o));return t}var HD=(e,A)=>{let t;if("trace_width"in A){const i=A.trace_width;t=e.find(n=>"standard_template_code"in n&&n.command_code==="ADD"&&n.standard_template_code==="C"&&n.diameter===i)}else("standard_template_code"in A||"macro_name"in A)&&(t=e.find(i=>i.command_code==="ADD"&&Object.keys(A).every(n=>i[n]===A[n])));if(!t)throw new Error(`Aperture not found for search params ${JSON.stringify(A)}`);return t.aperture_number},O9e={version:"0.0.45"},W9e={"top-copper":"Copper,L1,Top","bottom-copper":"Copper,L2,Bot","top-soldermask":"Soldermask,Top","bottom-soldermask":"Soldermask,Bot","top-silkscreen":"Legend,Top","bottom-silkscreen":"Legend,Bot","top-paste":"Paste,Top","bottom-paste":"Paste,Bot",edgecut:"Profile,NP"},bb=e=>{const A=W9e[e.layer_type?`${e.layer}-${e.layer_type}`:e.layer];return zI().add("add_attribute_on_file",{attribute_name:"GenerationSoftware",attribute_value:`tscircuit,circuit-json-to-gerber,${O9e.version}`}).add("add_attribute_on_file",{attribute_name:"CreationDate",attribute_value:new Date().toISOString()}).add("add_attribute_on_file",{attribute_name:"SameCoordinates",attribute_value:"Original"}).add("add_attribute_on_file",{attribute_name:"FileFunction",attribute_value:A}).$if(e.layer!=="edgecut",t=>t.add("add_attribute_on_file",{attribute_name:"FilePolarity",attribute_value:e.layer_type==="soldermask"?"Negative":"Positive"})).add("format_specification",{}).add("set_unit",{unit:"MM"}).add("comment",{comment:"Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)"}).add("comment",{comment:`Created by tscircuit (builder) date ${new Date().toISOString()}`}).add("set_movement_mode_to_linear",{}).add("set_layer_polarity",{polarity:"D"}).add("create_arc",{}).build()},Z9e={top:"F_",bottom:"B_"},V9e={copper:"Cu",silkscreen:"SilkScreen",soldermask:"Mask",mask:"Mask",paste:"Paste"},wf=(e,A)=>e==="edgecut"?"Edge_Cuts":`${Z9e[e]}${V9e[A]}`,j9e=(e,A={})=>{A.flip_y_axis??=!1;const t={F_Cu:bb({layer:"top",layer_type:"copper"}),F_SilkScreen:bb({layer:"top",layer_type:"silkscreen"}),F_Mask:bb({layer:"top",layer_type:"soldermask"}),F_Paste:bb({layer:"top",layer_type:"paste"}),B_Cu:bb({layer:"bottom",layer_type:"copper"}),B_SilkScreen:bb({layer:"bottom",layer_type:"silkscreen"}),B_Mask:bb({layer:"bottom",layer_type:"soldermask"}),B_Paste:bb({layer:"bottom",layer_type:"paste"}),Edge_Cuts:bb({layer:"edgecut"})};for(const s of["F_Cu","B_Cu","F_Mask","B_Mask","F_Paste","B_Paste","F_SilkScreen","B_SilkScreen"]){const r=t[s];T9e(r),P9e({soup:e,glayer:r,glayer_name:s})}t.Edge_Cuts.push(...zI().add("define_aperture_template",{aperture_number:10,standard_template_code:"C",diameter:.05}).build());const i=s=>A.flip_y_axis?-s:s,n=new Map;for(const s of e)if(s.type==="pcb_plated_hole"&&"x"in s&&typeof s.x=="number"&&"y"in s&&typeof s.y=="number"){const r="ccw_rotation"in s&&typeof s.ccw_rotation=="number"?s.ccw_rotation:0;n.set(`${s.x}:${s.y}`,r)}const o=(s,r,a,g)=>{if(s.layer!==r)return;const I=.7,c=t[wf(r,a)],l=g(s),B=zI().add("select_aperture",{aperture_number:HD(c,l)});let C=s.anchor_position.x,E=s.anchor_position.y;const Q=s.font_size*I,h=Q*.4,u=Q*.5,d=s.text.split("").reduce((H,O)=>O===" "?H+u+h:H+Q+h,0)-h,f=Q;switch(s.anchor_alignment||(()=>{const H=s.anchor_side;if(H)switch(H){case"top":return"top_center";case"bottom":return"bottom_center";case"left":return"center_left";case"right":return"center_right"}})()||"center"){case"top_left":break;case"top_center":C-=d/2;break;case"top_right":C-=d;break;case"center_right":E-=f/2;break;case"center_left":C-=d,E-=f/2;break;case"bottom_left":E-=f;break;case"bottom_center":C-=d/2,E-=f;break;case"bottom_right":C-=d,E-=f;break;default:C-=d/2,E-=f/2;break}let w=C;const D=E;let b=s.ccw_rotation||0;const k=w+d/2,x=D+f/2,N=[];if((s.is_mirrored!==void 0?s.is_mirrored:s.layer==="bottom")&&(N.push(hr(k,x),{a:-1,b:0,c:0,d:1,e:0,f:0},hr(-k,-x)),b=-b),b){const H=b*Math.PI/180;N.push(hr(k,x),Lm(H),hr(-k,-x))}const U=N.length>0?rB(...N):void 0,Y=H=>U?Pe(U,H):H;if(a==="copper"&&s.is_knockout){const H=s.knockout_padding??{left:.2,right:.2,top:.2,bottom:.2},O=[{x:C-H.left,y:E-H.top},{x:C+d+H.right,y:E-H.top},{x:C+d+H.right,y:E+f+H.bottom},{x:C-H.left,y:E+f+H.bottom}].map(Y);c.push(...zI().add("select_aperture",{aperture_number:HD(c,l)}).add("start_region_statement",{}).add("move_operation",{x:O[0].x,y:i(O[0].y)}).add("plot_operation",{x:O[1].x,y:i(O[1].y)}).add("plot_operation",{x:O[2].x,y:i(O[2].y)}).add("plot_operation",{x:O[3].x,y:i(O[3].y)}).add("plot_operation",{x:O[0].x,y:i(O[0].y)}).add("end_region_statement",{}).build()),c.push(...zI().add("set_layer_polarity",{polarity:"C"}).build())}for(const H of s.text.toUpperCase()){if(H===" "){w+=u+h;continue}const O=SfA[H]||[];for(const W of O){const $=w+W.x1*Q,iA=D+W.y1*Q,rA=w+W.x2*Q,tA=D+W.y2*Q,oA=Y({x:$,y:iA}),aA=Y({x:rA,y:tA});B.add("move_operation",{x:oA.x,y:i(oA.y)}),B.add("plot_operation",{x:aA.x,y:i(aA.y)})}w+=Q+h}c.push(...B.build()),a==="copper"&&s.is_knockout&&c.push(...zI().add("set_layer_polarity",{polarity:"D"}).build())};for(const s of["top","bottom","edgecut"])for(const r of e)if(r.type==="pcb_trace"){const{route:a}=r;for(const[g,I]of J9e(a))if(g.route_type==="wire"&&g.layer===s){const c=t[wf(s,"copper")];c.push(...zI().add("select_aperture",{aperture_number:HD(c,{trace_width:g.width})}).add("move_operation",{x:g.x,y:i(g.y)}).add("plot_operation",{x:I.x,y:i(I.y)}).build())}}else if(r.type==="pcb_silkscreen_path"){if(r.layer===s){const a=t[wf(s,"silkscreen")],g=Cct(r),I=zI().add("select_aperture",{aperture_number:HD(a,g)});r.route.length>0&&I.add("move_operation",{x:r.route[0].x,y:i(r.route[0].y)});for(let c=1;c<r.route.length;c++)I.add("plot_operation",{x:r.route[c].x,y:i(r.route[c].y)});a.push(...I.build())}}else if(r.type==="pcb_silkscreen_text"&&s!=="edgecut")o(r,s,"silkscreen",Qct);else if(r.type==="pcb_copper_text"&&s!=="edgecut")o(r,s,"copper",Ect);else if(r.type==="pcb_smtpad"&&r.shape!=="polygon"){if(r.layer===s)for(const a of[t[wf(s,"copper")],t[wf(s,"soldermask")]]){const g=Bct(r),I=HD(a,g),c=zI().add("select_aperture",{aperture_number:I});r.shape==="rotated_rect"&&r.ccw_rotation&&c.add("load_rotation",{rotation_degrees:r.ccw_rotation}),c.add("flash_operation",{x:r.x,y:i(r.y)}),r.shape==="rotated_rect"&&r.ccw_rotation&&c.add("load_rotation",{rotation_degrees:0}),a.push(...c.build())}}else if(r.type==="pcb_smtpad"&&r.shape==="polygon"){if(r.layer===s){const a=[t[wf(s,"copper")]];(!("is_covered_with_solder_mask"in r)||r.is_covered_with_solder_mask!==!1)&&a.push(t[wf(s,"soldermask")]);for(const g of a){const I=zI().add("select_aperture",{aperture_number:10}).add("start_region_statement",{}),{points:c}=r;if(c&&c.length>0){I.add("move_operation",{x:c[0].x,y:i(c[0].y)});for(let l=1;l<c.length;l++)I.add("plot_operation",{x:c[l].x,y:i(c[l].y)});I.add("plot_operation",{x:c[0].x,y:i(c[0].y)})}I.add("end_region_statement",{}),g.push(...I.build())}}}else if(r.type==="pcb_solder_paste"){if(r.layer===s){const a=t[wf(s,"paste")],g=HD(a,hct(r)),I="ccw_rotation"in r&&typeof r.ccw_rotation=="number"?r.ccw_rotation:n.get(`${r.x}:${r.y}`)??0,c=zI().add("select_aperture",{aperture_number:g});I&&c.add("load_rotation",{rotation_degrees:I}),c.add("flash_operation",{x:r.x,y:i(r.y)}),I&&c.add("load_rotation",{rotation_degrees:0}),a.push(...c.build())}}else if(r.type==="pcb_plated_hole"){if(r.layers.includes(s))for(const a of[t[wf(s,"copper")],t[wf(s,"soldermask")]]){const g="hole_width"in r&&typeof r.hole_width=="number"?r.hole_width:0,I="hole_height"in r&&typeof r.hole_height=="number"?r.hole_height:0,c=[g];"outer_width"in r&&typeof r.outer_width=="number"&&c.push(r.outer_width),"rect_pad_width"in r&&typeof r.rect_pad_width=="number"&&c.push(r.rect_pad_width);const l=Math.max(...c),B=[I];"outer_height"in r&&typeof r.outer_height=="number"&&B.push(r.outer_height),"rect_pad_height"in r&&typeof r.rect_pad_height=="number"&&B.push(r.rect_pad_height);const C=Math.max(...B);if(r.shape==="pill"){const E={standard_template_code:"C",diameter:Math.min(l,C)};let Q;try{Q=HD(a,E)}catch{Q=Math.max(...a.filter(b=>"aperture_number"in b).map(b=>b.aperture_number),9)+1,a.push(...zI().add("define_aperture_template",{aperture_number:Q,...E}).build())}const h=zI().add("select_aperture",{aperture_number:Q}),u=(r.ccw_rotation??0)*Math.PI/180,d=Math.cos(u),f=Math.sin(u),m=(b,k)=>{const x=b*d-k*f,N=b*f+k*d;return{x:r.x+x,y:r.y+N}},w=l>=C,D=w?(l-C)/2:(C-l)/2;if(D<=0){const b=m(0,0);h.add("flash_operation",{x:b.x,y:i(b.y)})}else{const b=w?{x:-D,y:0}:{x:0,y:-D},k=w?{x:D,y:0}:{x:0,y:D},x=m(b.x,b.y),N=m(k.x,k.y);h.add("flash_operation",{x:x.x,y:i(x.y)}).add("move_operation",{x:x.x,y:i(x.y)}).add("plot_operation",{x:N.x,y:i(N.y)}).add("flash_operation",{x:N.x,y:i(N.y)})}a.push(...h.build())}else{const E=uct({...r,...r.shape!=="circle"?{outer_width:l,outer_height:C}:{}}),Q="rect_ccw_rotation"in r&&typeof r.rect_ccw_rotation=="number"?r.rect_ccw_rotation:void 0,h=zI().add("select_aperture",{aperture_number:HD(a,E)});Q&&h.add("load_rotation",{rotation_degrees:Q}),h.add("flash_operation",{x:r.x,y:i(r.y)}),Q&&h.add("load_rotation",{rotation_degrees:0}),a.push(...h.build())}}}else if(r.type==="pcb_hole"){if(s!=="edgecut")for(const a of[t[wf(s,"soldermask")]]){if(r.hole_shape!=="circle"){console.warn("NOT IMPLEMENTED: drawing gerber for non-round holes");continue}a.push(...zI().add("select_aperture",{aperture_number:HD(a,dct(r))}).add("flash_operation",{x:r.x,y:i(r.y)}).build())}}else if(r.type==="pcb_via"){if(r.layers.includes(s))for(const a of[t[wf(s,"copper")]])a.push(...zI().add("select_aperture",{aperture_number:HD(a,pct(r))}).add("flash_operation",{x:r.x,y:i(r.y)}).build())}else if(r.type==="pcb_board"&&s==="edgecut"){if(r.pcb_panel_id)continue;const g=t.Edge_Cuts,{width:I,height:c,center:l,outline:B}=r,C=zI().add("select_aperture",{aperture_number:10});if(B&&B.length>2){const E=B.map(u=>({x:u.x,y:i(u.y)})),Q=E[0];C.add("move_operation",Q);for(let u=1;u<E.length;u++)C.add("plot_operation",E[u]);const h=E[E.length-1];(h.x!==Q.x||h.y!==Q.y)&&C.add("plot_operation",Q)}else C.add("move_operation",{x:l.x-I/2,y:i(l.y-c/2)}).add("plot_operation",{x:l.x+I/2,y:i(l.y-c/2)}).add("plot_operation",{x:l.x+I/2,y:i(l.y+c/2)}).add("plot_operation",{x:l.x-I/2,y:i(l.y+c/2)}).add("plot_operation",{x:l.x-I/2,y:i(l.y-c/2)});g.push(...C.build())}else if(r.type==="pcb_panel"&&s==="edgecut"){const a=t.Edge_Cuts,g=r,{width:I,height:c,center:l}=g,B=zI().add("select_aperture",{aperture_number:10}).add("move_operation",{x:l.x-I/2,y:i(l.y-c/2)}).add("plot_operation",{x:l.x+I/2,y:i(l.y-c/2)}).add("plot_operation",{x:l.x+I/2,y:i(l.y+c/2)}).add("plot_operation",{x:l.x-I/2,y:i(l.y+c/2)}).add("plot_operation",{x:l.x-I/2,y:i(l.y-c/2)});a.push(...B.build())}else if(r.type==="pcb_cutout"){if(s==="edgecut"){const a=t.Edge_Cuts,g=zI().add("select_aperture",{aperture_number:10}),I=r;if(I.shape==="rect"){const{center:c,width:l,height:B,rotation:C,corner_radius:E}=I,Q=l/2,h=B/2,u=Math.max(0,Math.min(E??0,Math.abs(Q),Math.abs(h))),f=(()=>{let m=Hu();if(C){const w=C*Math.PI/180;m=Lm(w)}return rB(hr(c.x,c.y),m)})();if(u>0){const m={x:-Q+u,y:h};let w=Pe(f,m);g.add("move_operation",{x:w.x,y:i(w.y)});const D=k=>{const x=Pe(f,k);g.add("plot_operation",{x:x.x,y:i(x.y)}),w=x},b=k=>{const x=Pe(f,k.point),N=Pe(f,k.center);g.add("set_movement_mode_to_clockwise_circular",{}).add("plot_operation",{x:x.x,y:i(x.y),i:N.x-w.x,j:i(N.y)-i(w.y)}).add("set_movement_mode_to_linear",{}),w=x};D({x:Q-u,y:h}),b({point:{x:Q,y:h-u},center:{x:Q-u,y:h-u}}),D({x:Q,y:-h+u}),b({point:{x:Q-u,y:-h},center:{x:Q-u,y:-h+u}}),D({x:-Q+u,y:-h}),b({point:{x:-Q,y:-h+u},center:{x:-Q+u,y:-h+u}}),D({x:-Q,y:h-u}),b({point:{x:-Q+u,y:h},center:{x:-Q+u,y:h-u}})}else{const w=[{x:-Q,y:h},{x:Q,y:h},{x:Q,y:-h},{x:-Q,y:-h}].map(D=>Pe(f,D));g.add("move_operation",{x:w[0].x,y:i(w[0].y)});for(let D=1;D<w.length;D++)g.add("plot_operation",{x:w[D].x,y:i(w[D].y)});g.add("plot_operation",{x:w[0].x,y:i(w[0].y)})}}else if(I.shape==="circle"){const{center:c,radius:l}=I,B={x:c.x+l,y:c.y},C={x:c.x-l,y:c.y};g.add("move_operation",{x:B.x,y:i(B.y)}).add("set_movement_mode_to_counterclockwise_circular",{}).add("plot_operation",{x:C.x,y:i(C.y),i:-l,j:0}).add("plot_operation",{x:B.x,y:i(B.y),i:l,j:0}).add("set_movement_mode_to_linear",{})}else if(I.shape==="polygon"){const{points:c}=I;if(c.length>0){g.add("move_operation",{x:c[0].x,y:i(c[0].y)});for(let l=1;l<c.length;l++)g.add("plot_operation",{x:c[l].x,y:i(c[l].y)});g.add("plot_operation",{x:c[0].x,y:i(c[0].y)})}}a.push(...g.build())}}else if(r.type==="pcb_copper_pour"&&s===r.layer){const a=t[wf(s,"copper")],g=zI().add("select_aperture",{aperture_number:10}).add("start_region_statement",{});if(r.shape==="brep"){const{brep_shape:c}=r;if(!c)continue;const{outer_ring:l,inner_rings:B}=c,C=Q=>{if(!Q||Q.vertices.length===0)return;g.add("move_operation",{x:Q.vertices[0].x,y:i(Q.vertices[0].y)});const h=[...Q.vertices,Q.vertices[0]];for(let u=0;u<h.length-1;u++){const d=h[u],f=h[u+1];if(d.bulge&&Math.abs(d.bulge)>1e-9){const m=(A.flip_y_axis?-1:1)*d.bulge;m>0?g.add("set_movement_mode_to_counterclockwise_circular",{}):g.add("set_movement_mode_to_clockwise_circular",{});const w={x:d.x,y:d.y},D={x:f.x,y:f.y},b=D.x-w.x,k=D.y-w.y,x=Math.sqrt(b*b+k*k);if(x<1e-9){g.add("set_movement_mode_to_linear",{}),g.add("plot_operation",{x:f.x,y:i(f.y)});continue}const N=Math.abs(m),R=4*Math.atan(N);if(Math.abs(Math.sin(R/2))<1e-9){g.add("set_movement_mode_to_linear",{}),g.add("plot_operation",{x:f.x,y:i(f.y)});continue}const U=x/(2*Math.sin(R/2)),Y=(Math.PI-R)/2,H=Math.atan2(k,b),O=m>0?Y:-Y,W=H+O,$=w.x+U*Math.cos(W),iA=w.y+U*Math.sin(W),rA=$-w.x,tA=iA-w.y;g.add("plot_operation",{x:f.x,y:i(f.y),i:rA,j:A.flip_y_axis?-tA:tA})}else g.add("set_movement_mode_to_linear",{}),g.add("plot_operation",{x:f.x,y:i(f.y)})}},E=Q=>{const{vertices:h}=Q;if(!h||h.length===0)return{vertices:[]};const u=h.length;return{vertices:[...h].reverse().map((m,w)=>{const D=(u-2-w+u)%u,b=h[D].bulge;return{...m,bulge:b?-b:void 0}})}};if(C(E(l)),B)for(const Q of B)C(E(Q))}else if(r.shape==="rect"){const{center:c,width:l,height:B,rotation:C}=r,E=l/2,Q=B/2,h=[{x:-E,y:Q},{x:E,y:Q},{x:E,y:-Q},{x:-E,y:-Q}];let u=Hu();if(C){const f=C*Math.PI/180;u=Lm(f)}u=rB(hr(c.x,c.y),u);const d=h.map(f=>Pe(u,f));g.add("move_operation",{x:d[0].x,y:i(d[0].y)});for(let f=1;f<d.length;f++)g.add("plot_operation",{x:d[f].x,y:i(d[f].y)});g.add("plot_operation",{x:d[0].x,y:i(d[0].y)})}else if(r.shape==="polygon"){const{points:c}=r;if(c.length>0){g.add("move_operation",{x:c[0].x,y:i(c[0].y)});for(let l=1;l<c.length;l++)g.add("plot_operation",{x:c[l].x,y:i(c[l].y)});g.add("plot_operation",{x:c[0].x,y:i(c[0].y)})}}g.add("end_region_statement",{});const I=g.build();a.push(...I),r.covered_with_solder_mask===!1&&t[wf(s,"soldermask")].push(...I)}for(const s of Object.keys(t))t[s].push(...zI().add("end_of_file",{}).build());return t},IJ={},bfA={},fct;function z9e(){return fct||(fct=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0});var A=(function(){function o(s,r){var a=[],g=!0,I=!1,c=void 0;try{for(var l=s[Symbol.iterator](),B;!(g=(B=l.next()).done)&&(a.push(B.value),!(r&&a.length===r));g=!0);}catch(C){I=!0,c=C}finally{try{!g&&l.return&&l.return()}finally{if(I)throw c}}return a}return function(s,r){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return o(s,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();e.default=i,e.parseUnitObj=n;var t=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function i(o){var s=parseFloat(o),r=o.match(t)||[],a=r.length>0?o.substr(r[0].length).trim():"";return[s,a]}function n(o){var s=i(o),r=A(s,2),a=r[0],g=r[1];return{val:a,unit:g}}})(bfA)),bfA}var yct;function X9e(){if(yct)return IJ;yct=1,Object.defineProperty(IJ,"__esModule",{value:!0});var e=(function(){function a(g,I){var c=[],l=!0,B=!1,C=void 0;try{for(var E=g[Symbol.iterator](),Q;!(l=(Q=E.next()).done)&&(c.push(Q.value),!(I&&c.length===I));l=!0);}catch(h){B=!0,C=h}finally{try{!l&&E.return&&E.return()}finally{if(B)throw C}}return c}return function(g,I){if(Array.isArray(g))return g;if(Symbol.iterator in Object(g))return a(g,I);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();IJ.formatSI=o,IJ.unformatSI=r;function A(a){return a&&a.__esModule?a:{default:a}}var t=z9e(),i=A(t),n={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function o(a){if(a===0)return"0";for(var g=Math.abs(a),I=0;g>=1e3&&I<24;)g/=1e3,I+=3;for(;g<1&&I>-24;)g*=1e3,I-=3;var c=a<0?"-":"";return g>1e3?c+g.toFixed(0)+n[I]:c+parseFloat(g.toPrecision(3))+n[I]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function r(a){if(a==null||a==="")return NaN;var g=(0,i.default)(a),I=e(g,2),c=I[0],l=I[1],B=s[l];return c*B}return IJ}var $9e=X9e(),u9={exports:{}};var Aje=u9.exports,mct;function tje(){return mct||(mct=1,(function(e,A){((t,i)=>{e.exports=i()})(Aje,function t(){var i=typeof self<"u"?self:typeof window<"u"?window:i!==void 0?i:{},n,o=!i.document&&!!i.postMessage,s=i.IS_PAPA_WORKER||!1,r={},a=0,g={};function I(b){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(k){var x=m(k);x.chunkSize=parseInt(x.chunkSize),k.step||k.chunk||(x.chunkSize=null),this._handle=new E(x),(this._handle.streamer=this)._config=x}).call(this,b),this.parseChunk=function(k,x){var N=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<N){let U=this._config.newline;U||(R=this._config.quoteChar||'"',U=this._handle.guessLineEndings(k,R)),k=[...k.split(U).slice(N)].join(U)}this.isFirstChunk&&D(this._config.beforeFirstChunk)&&(R=this._config.beforeFirstChunk(k))!==void 0&&(k=R),this.isFirstChunk=!1,this._halted=!1;var N=this._partialLine+k,R=(this._partialLine="",this._handle.parse(N,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(k=R.meta.cursor,N=(this._finished||(this._partialLine=N.substring(k-this._baseIndex),this._baseIndex=k),R&&R.data&&(this._rowCount+=R.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)i.postMessage({results:R,workerId:g.WORKER_ID,finished:N});else if(D(this._config.chunk)&&!x){if(this._config.chunk(R,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=R=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(R.data),this._completeResults.errors=this._completeResults.errors.concat(R.errors),this._completeResults.meta=R.meta),this._completed||!N||!D(this._config.complete)||R&&R.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),N||R&&R.meta.paused||this._nextChunk(),R}this._halted=!0},this._sendError=function(k){D(this._config.error)?this._config.error(k):s&&this._config.error&&i.postMessage({workerId:g.WORKER_ID,error:k,finished:!1})}}function c(b){var k;(b=b||{}).chunkSize||(b.chunkSize=g.RemoteChunkSize),I.call(this,b),this._nextChunk=o?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(x){this._input=x,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(k=new XMLHttpRequest,this._config.withCredentials&&(k.withCredentials=this._config.withCredentials),o||(k.onload=w(this._chunkLoaded,this),k.onerror=w(this._chunkError,this)),k.open(this._config.downloadRequestBody?"POST":"GET",this._input,!o),this._config.downloadRequestHeaders){var x,N=this._config.downloadRequestHeaders;for(x in N)k.setRequestHeader(x,N[x])}var R;this._config.chunkSize&&(R=this._start+this._config.chunkSize-1,k.setRequestHeader("Range","bytes="+this._start+"-"+R));try{k.send(this._config.downloadRequestBody)}catch(U){this._chunkError(U.message)}o&&k.status===0&&this._chunkError()}},this._chunkLoaded=function(){k.readyState===4&&(k.status<200||400<=k.status?this._chunkError():(this._start+=this._config.chunkSize||k.responseText.length,this._finished=!this._config.chunkSize||this._start>=(x=>(x=x.getResponseHeader("Content-Range"))!==null?parseInt(x.substring(x.lastIndexOf("/")+1)):-1)(k),this.parseChunk(k.responseText)))},this._chunkError=function(x){x=k.statusText||x,this._sendError(new Error(x))}}function l(b){(b=b||{}).chunkSize||(b.chunkSize=g.LocalChunkSize),I.call(this,b);var k,x,N=typeof FileReader<"u";this.stream=function(R){this._input=R,x=R.slice||R.webkitSlice||R.mozSlice,N?((k=new FileReader).onload=w(this._chunkLoaded,this),k.onerror=w(this._chunkError,this)):k=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var R=this._input,U=(this._config.chunkSize&&(U=Math.min(this._start+this._config.chunkSize,this._input.size),R=x.call(R,this._start,U)),k.readAsText(R,this._config.encoding));N||this._chunkLoaded({target:{result:U}})},this._chunkLoaded=function(R){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(R.target.result)},this._chunkError=function(){this._sendError(k.error)}}function B(b){var k;I.call(this,b=b||{}),this.stream=function(x){return k=x,this._nextChunk()},this._nextChunk=function(){var x,N;if(!this._finished)return x=this._config.chunkSize,k=x?(N=k.substring(0,x),k.substring(x)):(N=k,""),this._finished=!k,this.parseChunk(N)}}function C(b){I.call(this,b=b||{});var k=[],x=!0,N=!1;this.pause=function(){I.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){I.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(R){this._input=R,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){N&&k.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),k.length?this.parseChunk(k.shift()):x=!0},this._streamData=w(function(R){try{k.push(typeof R=="string"?R:R.toString(this._config.encoding)),x&&(x=!1,this._checkIsFinished(),this.parseChunk(k.shift()))}catch(U){this._streamError(U)}},this),this._streamError=w(function(R){this._streamCleanUp(),this._sendError(R)},this),this._streamEnd=w(function(){this._streamCleanUp(),N=!0,this._streamData("")},this),this._streamCleanUp=w(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function E(b){var k,x,N,R,U=Math.pow(2,53),Y=-U,H=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,O=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,W=this,$=0,iA=0,rA=!1,tA=!1,oA=[],aA={data:[],errors:[],meta:{}};function QA(KA){return b.skipEmptyLines==="greedy"?KA.join("").trim()==="":KA.length===1&&KA[0].length===0}function SA(){if(aA&&N&&(MA("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+g.DefaultDelimiter+"'"),N=!1),b.skipEmptyLines&&(aA.data=aA.data.filter(function(dA){return!QA(dA)})),FA()){let dA=function(PA,JA){D(b.transformHeader)&&(PA=b.transformHeader(PA,JA)),oA.push(PA)};if(aA)if(Array.isArray(aA.data[0])){for(var KA=0;FA()&&KA<aA.data.length;KA++)aA.data[KA].forEach(dA);aA.data.splice(0,1)}else aA.data.forEach(dA)}function hA(dA,PA){for(var JA=b.header?{}:[],it=0;it<dA.length;it++){var fA=it,tt=dA[it],tt=((OA,HA)=>(ZA=>(b.dynamicTypingFunction&&b.dynamicTyping[ZA]===void 0&&(b.dynamicTyping[ZA]=b.dynamicTypingFunction(ZA)),(b.dynamicTyping[ZA]||b.dynamicTyping)===!0))(OA)?HA==="true"||HA==="TRUE"||HA!=="false"&&HA!=="FALSE"&&((ZA=>{if(H.test(ZA)&&(ZA=parseFloat(ZA),Y<ZA&&ZA<U))return 1})(HA)?parseFloat(HA):O.test(HA)?new Date(HA):HA===""?null:HA):HA)(fA=b.header?it>=oA.length?"__parsed_extra":oA[it]:fA,tt=b.transform?b.transform(tt,fA):tt);fA==="__parsed_extra"?(JA[fA]=JA[fA]||[],JA[fA].push(tt)):JA[fA]=tt}return b.header&&(it>oA.length?MA("FieldMismatch","TooManyFields","Too many fields: expected "+oA.length+" fields but parsed "+it,iA+PA):it<oA.length&&MA("FieldMismatch","TooFewFields","Too few fields: expected "+oA.length+" fields but parsed "+it,iA+PA)),JA}var GA;aA&&(b.header||b.dynamicTyping||b.transform)&&(GA=1,!aA.data.length||Array.isArray(aA.data[0])?(aA.data=aA.data.map(hA),GA=aA.data.length):aA.data=hA(aA.data,0),b.header&&aA.meta&&(aA.meta.fields=oA),iA+=GA)}function FA(){return b.header&&oA.length===0}function MA(KA,hA,GA,dA){KA={type:KA,code:hA,message:GA},dA!==void 0&&(KA.row=dA),aA.errors.push(KA)}D(b.step)&&(R=b.step,b.step=function(KA){aA=KA,FA()?SA():(SA(),aA.data.length!==0&&($+=KA.data.length,b.preview&&$>b.preview?x.abort():(aA.data=aA.data[0],R(aA,W))))}),this.parse=function(KA,hA,GA){var dA=b.quoteChar||'"',dA=(b.newline||(b.newline=this.guessLineEndings(KA,dA)),N=!1,b.delimiter?D(b.delimiter)&&(b.delimiter=b.delimiter(KA),aA.meta.delimiter=b.delimiter):((dA=((PA,JA,it,fA,tt)=>{var OA,HA,ZA,xA;tt=tt||[","," ","|",";",g.RECORD_SEP,g.UNIT_SEP];for(var wA=0;wA<tt.length;wA++){for(var UA,kA=tt[wA],TA=0,qA=0,At=0,DA=(ZA=void 0,new h({comments:fA,delimiter:kA,newline:JA,preview:10}).parse(PA)),lA=0;lA<DA.data.length;lA++)it&&QA(DA.data[lA])?At++:(UA=DA.data[lA].length,qA+=UA,ZA===void 0?ZA=UA:0<UA&&(TA+=Math.abs(UA-ZA),ZA=UA));0<DA.data.length&&(qA/=DA.data.length-At),(HA===void 0||TA<=HA)&&(xA===void 0||xA<qA)&&1.99<qA&&(HA=TA,OA=kA,xA=qA)}return{successful:!!(b.delimiter=OA),bestDelimiter:OA}})(KA,b.newline,b.skipEmptyLines,b.comments,b.delimitersToGuess)).successful?b.delimiter=dA.bestDelimiter:(N=!0,b.delimiter=g.DefaultDelimiter),aA.meta.delimiter=b.delimiter),m(b));return b.preview&&b.header&&dA.preview++,k=KA,x=new h(dA),aA=x.parse(k,hA,GA),SA(),rA?{meta:{paused:!0}}:aA||{meta:{paused:!1}}},this.paused=function(){return rA},this.pause=function(){rA=!0,x.abort(),k=D(b.chunk)?"":k.substring(x.getCharIndex())},this.resume=function(){W.streamer._halted?(rA=!1,W.streamer.parseChunk(k,!0)):setTimeout(W.resume,3)},this.aborted=function(){return tA},this.abort=function(){tA=!0,x.abort(),aA.meta.aborted=!0,D(b.complete)&&b.complete(aA),k=""},this.guessLineEndings=function(PA,dA){PA=PA.substring(0,1048576);var dA=new RegExp(Q(dA)+"([^]*?)"+Q(dA),"gm"),GA=(PA=PA.replace(dA,"")).split("\r"),dA=PA.split(`
5742
+ `.trim()}).add("comment",{comment:"APERTURE MACROS END"}).build())};function K9e(e){const A=e.filter(i=>i.type==="pcb_trace"),t={};for(const i of A)for(const n of i.route)n.route_type==="wire"&&(t[n.layer]=t[n.layer]||new Set,t[n.layer].add(n.width));return{top:Array.from(t.top||[]),bottom:Array.from(t.bottom||[])}}function P9e({glayer:e,soup:A,glayer_name:t}){const i=()=>{const s=e.reduce((r,a)=>a.command_code==="ADD"?Math.max(r,a.aperture_number):r,0);return s===0?10:s+1};e.push(...zI().add("comment",{comment:"aperture START LIST"}).build());const n=K9e(A);for(const s of n[t.startsWith("F_")?"top":"bottom"])e.push(...zI().add("define_aperture_template",{aperture_number:i(),standard_template_code:"C",diameter:s}).build());const o=q9e(A,t.startsWith("F_")?"top":"bottom");for(const s of o)e.push(...zI().add("define_aperture_template",{aperture_number:i(),...s}).build());e.push(...zI().add("delete_attribute",{}).add("comment",{comment:"aperture END LIST"}).build())}var Bct=e=>{if(e.shape==="rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};if(e.shape==="circle")return{standard_template_code:"C",diameter:e.radius*2};if(e.shape==="rotated_rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};throw e.shape==="polygon"?new Error("Polygon SMT pads are drawn as regions, not apertures"):new Error(`Unsupported shape ${e.shape}`)},Cct=e=>{if("stroke_width"in e)return{standard_template_code:"C",diameter:e.stroke_width};throw new Error(`Provide stroke_width for: ${e}`)},Qct=e=>{if("font_size"in e)return{standard_template_code:"C",diameter:e.font_size/8};throw new Error(`Provide font_size for: ${e}`)},Ect=e=>{if("font_size"in e)return{standard_template_code:"C",diameter:e.font_size/8};throw new Error(`Provide font_size for: ${e}`)},hct=e=>{if(e.shape==="rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};if(e.shape==="rotated_rect")return{standard_template_code:"R",x_size:e.width,y_size:e.height};if(e.shape==="circle")return{standard_template_code:"C",diameter:e.radius*2};if(e.shape==="pill"){if(!("width"in e&&"height"in e))throw new Error("Invalid pill shape in getApertureConfigFromPcbPlatedHole: missing dimensions");return e.width>=e.height?{macro_name:"HORZPILL",x_size:e.width,y_size:e.height,circle_diameter:Math.min(e.width,e.height),circle_center_offset:e.width/2}:{macro_name:"VERTPILL",x_size:e.width,y_size:e.height,circle_diameter:Math.min(e.width,e.height),circle_center_offset:e.height/2}}throw new Error(`Unsupported shape ${e.shape}`)},uct=e=>{if(e.shape==="circle"){if(!("outer_diameter"in e&&"hole_diameter"in e))throw new Error("Invalid circle shape in getApertureConfigFromPcbPlatedHole: missing diameters");return{standard_template_code:"C",diameter:e.outer_diameter}}if(e.shape==="pill"){if(!("outer_width"in e&&"outer_height"in e))throw new Error("Invalid pill shape in getApertureConfigFromPcbPlatedHole: missing dimensions");return e.outer_width>e.outer_height?{macro_name:"HORZPILL",x_size:e.outer_width,y_size:e.outer_height,circle_diameter:Math.min(e.outer_width,e.outer_height),circle_center_offset:e.outer_width/2}:{macro_name:"VERTPILL",x_size:e.outer_width,y_size:e.outer_height,circle_diameter:Math.min(e.outer_width,e.outer_height),circle_center_offset:e.outer_height/2}}const A=e.shape;if(A==="circular_hole_with_rect_pad"||A==="pill_hole_with_rect_pad"||A==="rotated_pill_hole_with_rect_pad"){if(!("rect_pad_width"in e&&"rect_pad_height"in e))throw new Error(`Invalid ${A} shape in getApertureConfigFromPcbPlatedHole: missing dimensions`);return{standard_template_code:"R",x_size:e.rect_pad_width,y_size:e.rect_pad_height}}throw new Error(`Unsupported shape in getApertureConfigFromPcbPlatedHole: ${e.shape}`)},dct=e=>{if(!("hole_diameter"in e))throw new Error(`Invalid shape called in getApertureConfigFromCirclePcbHole: ${e.hole_shape}`);return{standard_template_code:"C",diameter:e.hole_diameter}},pct=e=>{if(!("outer_diameter"in e))throw new Error("outer_diameter not specified in getApertureConfigFromPcbVia");return{standard_template_code:"C",diameter:e.outer_diameter}};function q9e(e,A){const t=[],i=new Set,n=o=>{const s=RVe(o);i.has(s)||(t.push(o),i.add(s))};for(const o of e)o.type==="pcb_smtpad"?o.layer===A&&o.shape!=="polygon"&&n(Bct(o)):o.type==="pcb_solder_paste"?o.layer===A&&n(hct(o)):o.type==="pcb_plated_hole"?o.layers.includes(A)&&n(uct(o)):o.type==="pcb_hole"?o.hole_shape==="circle"?n(dct(o)):console.warn("NOT IMPLEMENTED: drawing gerber for non circle holes"):o.type==="pcb_via"?n(pct(o)):o.type==="pcb_silkscreen_path"?n(Cct(o)):o.type==="pcb_silkscreen_text"?n(Qct(o)):o.type==="pcb_copper_text"&&o.layer===A&&n(Ect(o));return t}var HD=(e,A)=>{let t;if("trace_width"in A){const i=A.trace_width;t=e.find(n=>"standard_template_code"in n&&n.command_code==="ADD"&&n.standard_template_code==="C"&&n.diameter===i)}else("standard_template_code"in A||"macro_name"in A)&&(t=e.find(i=>i.command_code==="ADD"&&Object.keys(A).every(n=>i[n]===A[n])));if(!t)throw new Error(`Aperture not found for search params ${JSON.stringify(A)}`);return t.aperture_number},O9e={version:"0.0.46"},W9e={"top-copper":"Copper,L1,Top","bottom-copper":"Copper,L2,Bot","top-soldermask":"Soldermask,Top","bottom-soldermask":"Soldermask,Bot","top-silkscreen":"Legend,Top","bottom-silkscreen":"Legend,Bot","top-paste":"Paste,Top","bottom-paste":"Paste,Bot",edgecut:"Profile,NP"},bb=e=>{const A=W9e[e.layer_type?`${e.layer}-${e.layer_type}`:e.layer];return zI().add("add_attribute_on_file",{attribute_name:"GenerationSoftware",attribute_value:`tscircuit,circuit-json-to-gerber,${O9e.version}`}).add("add_attribute_on_file",{attribute_name:"CreationDate",attribute_value:new Date().toISOString()}).add("add_attribute_on_file",{attribute_name:"SameCoordinates",attribute_value:"Original"}).add("add_attribute_on_file",{attribute_name:"FileFunction",attribute_value:A}).$if(e.layer!=="edgecut",t=>t.add("add_attribute_on_file",{attribute_name:"FilePolarity",attribute_value:e.layer_type==="soldermask"?"Negative":"Positive"})).add("format_specification",{}).add("set_unit",{unit:"MM"}).add("comment",{comment:"Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)"}).add("comment",{comment:`Created by tscircuit (builder) date ${new Date().toISOString()}`}).add("set_movement_mode_to_linear",{}).add("set_layer_polarity",{polarity:"D"}).add("create_arc",{}).build()},Z9e={top:"F_",bottom:"B_"},V9e={copper:"Cu",silkscreen:"SilkScreen",soldermask:"Mask",mask:"Mask",paste:"Paste"},wf=(e,A)=>e==="edgecut"?"Edge_Cuts":`${Z9e[e]}${V9e[A]}`,j9e=(e,A={})=>{A.flip_y_axis??=!1;const t=e.some(r=>r.type==="pcb_panel"),i={F_Cu:bb({layer:"top",layer_type:"copper"}),F_SilkScreen:bb({layer:"top",layer_type:"silkscreen"}),F_Mask:bb({layer:"top",layer_type:"soldermask"}),F_Paste:bb({layer:"top",layer_type:"paste"}),B_Cu:bb({layer:"bottom",layer_type:"copper"}),B_SilkScreen:bb({layer:"bottom",layer_type:"silkscreen"}),B_Mask:bb({layer:"bottom",layer_type:"soldermask"}),B_Paste:bb({layer:"bottom",layer_type:"paste"}),Edge_Cuts:bb({layer:"edgecut"})};for(const r of["F_Cu","B_Cu","F_Mask","B_Mask","F_Paste","B_Paste","F_SilkScreen","B_SilkScreen"]){const a=i[r];T9e(a),P9e({soup:e,glayer:a,glayer_name:r})}i.Edge_Cuts.push(...zI().add("define_aperture_template",{aperture_number:10,standard_template_code:"C",diameter:.05}).build());const n=r=>A.flip_y_axis?-r:r,o=new Map;for(const r of e)if(r.type==="pcb_plated_hole"&&"x"in r&&typeof r.x=="number"&&"y"in r&&typeof r.y=="number"){const a="ccw_rotation"in r&&typeof r.ccw_rotation=="number"?r.ccw_rotation:0;o.set(`${r.x}:${r.y}`,a)}const s=(r,a,g,I)=>{if(r.layer!==a)return;const c=.7,l=i[wf(a,g)],B=I(r),C=zI().add("select_aperture",{aperture_number:HD(l,B)});let E=r.anchor_position.x,Q=r.anchor_position.y;const h=r.font_size*c,u=h*.4,d=h*.5,f=r.text.split("").reduce((O,W)=>W===" "?O+d+u:O+h+u,0)-u,m=h;switch(r.anchor_alignment||(()=>{const O=r.anchor_side;if(O)switch(O){case"top":return"top_center";case"bottom":return"bottom_center";case"left":return"center_left";case"right":return"center_right"}})()||"center"){case"top_left":break;case"top_center":E-=f/2;break;case"top_right":E-=f;break;case"center_right":Q-=m/2;break;case"center_left":E-=f,Q-=m/2;break;case"bottom_left":Q-=m;break;case"bottom_center":E-=f/2,Q-=m;break;case"bottom_right":E-=f,Q-=m;break;default:E-=f/2,Q-=m/2;break}let D=E;const b=Q;let k=r.ccw_rotation||0;const x=D+f/2,N=b+m/2,R=[];if((r.is_mirrored!==void 0?r.is_mirrored:r.layer==="bottom")&&(R.push(hr(x,N),{a:-1,b:0,c:0,d:1,e:0,f:0},hr(-x,-N)),k=-k),k){const O=k*Math.PI/180;R.push(hr(x,N),Lm(O),hr(-x,-N))}const Y=R.length>0?rB(...R):void 0,H=O=>Y?Pe(Y,O):O;if(g==="copper"&&r.is_knockout){const O=r.knockout_padding??{left:.2,right:.2,top:.2,bottom:.2},W=[{x:E-O.left,y:Q-O.top},{x:E+f+O.right,y:Q-O.top},{x:E+f+O.right,y:Q+m+O.bottom},{x:E-O.left,y:Q+m+O.bottom}].map(H);l.push(...zI().add("select_aperture",{aperture_number:HD(l,B)}).add("start_region_statement",{}).add("move_operation",{x:W[0].x,y:n(W[0].y)}).add("plot_operation",{x:W[1].x,y:n(W[1].y)}).add("plot_operation",{x:W[2].x,y:n(W[2].y)}).add("plot_operation",{x:W[3].x,y:n(W[3].y)}).add("plot_operation",{x:W[0].x,y:n(W[0].y)}).add("end_region_statement",{}).build()),l.push(...zI().add("set_layer_polarity",{polarity:"C"}).build())}for(const O of r.text.toUpperCase()){if(O===" "){D+=d+u;continue}const W=SfA[O]||[];for(const $ of W){const iA=D+$.x1*h,rA=b+$.y1*h,tA=D+$.x2*h,oA=b+$.y2*h,aA=H({x:iA,y:rA}),QA=H({x:tA,y:oA});C.add("move_operation",{x:aA.x,y:n(aA.y)}),C.add("plot_operation",{x:QA.x,y:n(QA.y)})}D+=h+u}l.push(...C.build()),g==="copper"&&r.is_knockout&&l.push(...zI().add("set_layer_polarity",{polarity:"D"}).build())};for(const r of["top","bottom","edgecut"])for(const a of e)if(a.type==="pcb_trace"){const{route:g}=a;for(const[I,c]of J9e(g))if(I.route_type==="wire"&&I.layer===r){const l=i[wf(r,"copper")];l.push(...zI().add("select_aperture",{aperture_number:HD(l,{trace_width:I.width})}).add("move_operation",{x:I.x,y:n(I.y)}).add("plot_operation",{x:c.x,y:n(c.y)}).build())}}else if(a.type==="pcb_silkscreen_path"){if(a.layer===r){const g=i[wf(r,"silkscreen")],I=Cct(a),c=zI().add("select_aperture",{aperture_number:HD(g,I)});a.route.length>0&&c.add("move_operation",{x:a.route[0].x,y:n(a.route[0].y)});for(let l=1;l<a.route.length;l++)c.add("plot_operation",{x:a.route[l].x,y:n(a.route[l].y)});g.push(...c.build())}}else if(a.type==="pcb_silkscreen_text"&&r!=="edgecut")s(a,r,"silkscreen",Qct);else if(a.type==="pcb_copper_text"&&r!=="edgecut")s(a,r,"copper",Ect);else if(a.type==="pcb_smtpad"&&a.shape!=="polygon"){if(a.layer===r)for(const g of[i[wf(r,"copper")],i[wf(r,"soldermask")]]){const I=Bct(a),c=HD(g,I),l=zI().add("select_aperture",{aperture_number:c});a.shape==="rotated_rect"&&a.ccw_rotation&&l.add("load_rotation",{rotation_degrees:a.ccw_rotation}),l.add("flash_operation",{x:a.x,y:n(a.y)}),a.shape==="rotated_rect"&&a.ccw_rotation&&l.add("load_rotation",{rotation_degrees:0}),g.push(...l.build())}}else if(a.type==="pcb_smtpad"&&a.shape==="polygon"){if(a.layer===r){const g=[i[wf(r,"copper")]];(!("is_covered_with_solder_mask"in a)||a.is_covered_with_solder_mask!==!1)&&g.push(i[wf(r,"soldermask")]);for(const I of g){const c=zI().add("select_aperture",{aperture_number:10}).add("start_region_statement",{}),{points:l}=a;if(l&&l.length>0){c.add("move_operation",{x:l[0].x,y:n(l[0].y)});for(let B=1;B<l.length;B++)c.add("plot_operation",{x:l[B].x,y:n(l[B].y)});c.add("plot_operation",{x:l[0].x,y:n(l[0].y)})}c.add("end_region_statement",{}),I.push(...c.build())}}}else if(a.type==="pcb_solder_paste"){if(a.layer===r){const g=i[wf(r,"paste")],I=HD(g,hct(a)),c="ccw_rotation"in a&&typeof a.ccw_rotation=="number"?a.ccw_rotation:o.get(`${a.x}:${a.y}`)??0,l=zI().add("select_aperture",{aperture_number:I});c&&l.add("load_rotation",{rotation_degrees:c}),l.add("flash_operation",{x:a.x,y:n(a.y)}),c&&l.add("load_rotation",{rotation_degrees:0}),g.push(...l.build())}}else if(a.type==="pcb_plated_hole"){if(a.layers.includes(r))for(const g of[i[wf(r,"copper")],i[wf(r,"soldermask")]]){const I="hole_width"in a&&typeof a.hole_width=="number"?a.hole_width:0,c="hole_height"in a&&typeof a.hole_height=="number"?a.hole_height:0,l=[I];"outer_width"in a&&typeof a.outer_width=="number"&&l.push(a.outer_width),"rect_pad_width"in a&&typeof a.rect_pad_width=="number"&&l.push(a.rect_pad_width);const B=Math.max(...l),C=[c];"outer_height"in a&&typeof a.outer_height=="number"&&C.push(a.outer_height),"rect_pad_height"in a&&typeof a.rect_pad_height=="number"&&C.push(a.rect_pad_height);const E=Math.max(...C);if(a.shape==="pill"){const Q={standard_template_code:"C",diameter:Math.min(B,E)};let h;try{h=HD(g,Q)}catch{h=Math.max(...g.filter(k=>"aperture_number"in k).map(k=>k.aperture_number),9)+1,g.push(...zI().add("define_aperture_template",{aperture_number:h,...Q}).build())}const u=zI().add("select_aperture",{aperture_number:h}),d=(a.ccw_rotation??0)*Math.PI/180,f=Math.cos(d),m=Math.sin(d),w=(k,x)=>{const N=k*f-x*m,R=k*m+x*f;return{x:a.x+N,y:a.y+R}},D=B>=E,b=D?(B-E)/2:(E-B)/2;if(b<=0){const k=w(0,0);u.add("flash_operation",{x:k.x,y:n(k.y)})}else{const k=D?{x:-b,y:0}:{x:0,y:-b},x=D?{x:b,y:0}:{x:0,y:b},N=w(k.x,k.y),R=w(x.x,x.y);u.add("flash_operation",{x:N.x,y:n(N.y)}).add("move_operation",{x:N.x,y:n(N.y)}).add("plot_operation",{x:R.x,y:n(R.y)}).add("flash_operation",{x:R.x,y:n(R.y)})}g.push(...u.build())}else{const Q=uct({...a,...a.shape!=="circle"?{outer_width:B,outer_height:E}:{}}),h="rect_ccw_rotation"in a&&typeof a.rect_ccw_rotation=="number"?a.rect_ccw_rotation:void 0,u=zI().add("select_aperture",{aperture_number:HD(g,Q)});h&&u.add("load_rotation",{rotation_degrees:h}),u.add("flash_operation",{x:a.x,y:n(a.y)}),h&&u.add("load_rotation",{rotation_degrees:0}),g.push(...u.build())}}}else if(a.type==="pcb_hole"){if(r!=="edgecut")for(const g of[i[wf(r,"soldermask")]]){if(a.hole_shape!=="circle"){console.warn("NOT IMPLEMENTED: drawing gerber for non-round holes");continue}g.push(...zI().add("select_aperture",{aperture_number:HD(g,dct(a))}).add("flash_operation",{x:a.x,y:n(a.y)}).build())}}else if(a.type==="pcb_via"){if(a.layers.includes(r))for(const g of[i[wf(r,"copper")]])g.push(...zI().add("select_aperture",{aperture_number:HD(g,pct(a))}).add("flash_operation",{x:a.x,y:n(a.y)}).build())}else if(a.type==="pcb_board"&&r==="edgecut"){if(t)continue;const g=i.Edge_Cuts,{width:I,height:c,center:l,outline:B}=a,C=zI().add("select_aperture",{aperture_number:10});if(B&&B.length>2){const E=B.map(u=>({x:u.x,y:n(u.y)})),Q=E[0];C.add("move_operation",Q);for(let u=1;u<E.length;u++)C.add("plot_operation",E[u]);const h=E[E.length-1];(h.x!==Q.x||h.y!==Q.y)&&C.add("plot_operation",Q)}else C.add("move_operation",{x:l.x-I/2,y:n(l.y-c/2)}).add("plot_operation",{x:l.x+I/2,y:n(l.y-c/2)}).add("plot_operation",{x:l.x+I/2,y:n(l.y+c/2)}).add("plot_operation",{x:l.x-I/2,y:n(l.y+c/2)}).add("plot_operation",{x:l.x-I/2,y:n(l.y-c/2)});g.push(...C.build())}else if(a.type==="pcb_panel"&&r==="edgecut"){const g=i.Edge_Cuts,I=a,{width:c,height:l,center:B}=I,C=zI().add("select_aperture",{aperture_number:10}).add("move_operation",{x:B.x-c/2,y:n(B.y-l/2)}).add("plot_operation",{x:B.x+c/2,y:n(B.y-l/2)}).add("plot_operation",{x:B.x+c/2,y:n(B.y+l/2)}).add("plot_operation",{x:B.x-c/2,y:n(B.y+l/2)}).add("plot_operation",{x:B.x-c/2,y:n(B.y-l/2)});g.push(...C.build())}else if(a.type==="pcb_cutout"){if(r==="edgecut"){const g=i.Edge_Cuts,I=zI().add("select_aperture",{aperture_number:10}),c=a;if(c.shape==="rect"){const{center:l,width:B,height:C,rotation:E,corner_radius:Q}=c,h=B/2,u=C/2,d=Math.max(0,Math.min(Q??0,Math.abs(h),Math.abs(u))),m=(()=>{let w=Hu();if(E){const D=E*Math.PI/180;w=Lm(D)}return rB(hr(l.x,l.y),w)})();if(d>0){const w={x:-h+d,y:u};let D=Pe(m,w);I.add("move_operation",{x:D.x,y:n(D.y)});const b=x=>{const N=Pe(m,x);I.add("plot_operation",{x:N.x,y:n(N.y)}),D=N},k=x=>{const N=Pe(m,x.point),R=Pe(m,x.center);I.add("set_movement_mode_to_clockwise_circular",{}).add("plot_operation",{x:N.x,y:n(N.y),i:R.x-D.x,j:n(R.y)-n(D.y)}).add("set_movement_mode_to_linear",{}),D=N};b({x:h-d,y:u}),k({point:{x:h,y:u-d},center:{x:h-d,y:u-d}}),b({x:h,y:-u+d}),k({point:{x:h-d,y:-u},center:{x:h-d,y:-u+d}}),b({x:-h+d,y:-u}),k({point:{x:-h,y:-u+d},center:{x:-h+d,y:-u+d}}),b({x:-h,y:u-d}),k({point:{x:-h+d,y:u},center:{x:-h+d,y:u-d}})}else{const D=[{x:-h,y:u},{x:h,y:u},{x:h,y:-u},{x:-h,y:-u}].map(b=>Pe(m,b));I.add("move_operation",{x:D[0].x,y:n(D[0].y)});for(let b=1;b<D.length;b++)I.add("plot_operation",{x:D[b].x,y:n(D[b].y)});I.add("plot_operation",{x:D[0].x,y:n(D[0].y)})}}else if(c.shape==="circle"){const{center:l,radius:B}=c,C={x:l.x+B,y:l.y},E={x:l.x-B,y:l.y};I.add("move_operation",{x:C.x,y:n(C.y)}).add("set_movement_mode_to_counterclockwise_circular",{}).add("plot_operation",{x:E.x,y:n(E.y),i:-B,j:0}).add("plot_operation",{x:C.x,y:n(C.y),i:B,j:0}).add("set_movement_mode_to_linear",{})}else if(c.shape==="polygon"){const{points:l}=c;if(l.length>0){I.add("move_operation",{x:l[0].x,y:n(l[0].y)});for(let B=1;B<l.length;B++)I.add("plot_operation",{x:l[B].x,y:n(l[B].y)});I.add("plot_operation",{x:l[0].x,y:n(l[0].y)})}}g.push(...I.build())}}else if(a.type==="pcb_copper_pour"&&r===a.layer){const g=i[wf(r,"copper")],I=zI().add("select_aperture",{aperture_number:10}).add("start_region_statement",{});if(a.shape==="brep"){const{brep_shape:l}=a;if(!l)continue;const{outer_ring:B,inner_rings:C}=l,E=h=>{if(!h||h.vertices.length===0)return;I.add("move_operation",{x:h.vertices[0].x,y:n(h.vertices[0].y)});const u=[...h.vertices,h.vertices[0]];for(let d=0;d<u.length-1;d++){const f=u[d],m=u[d+1];if(f.bulge&&Math.abs(f.bulge)>1e-9){const w=(A.flip_y_axis?-1:1)*f.bulge;w>0?I.add("set_movement_mode_to_counterclockwise_circular",{}):I.add("set_movement_mode_to_clockwise_circular",{});const D={x:f.x,y:f.y},b={x:m.x,y:m.y},k=b.x-D.x,x=b.y-D.y,N=Math.sqrt(k*k+x*x);if(N<1e-9){I.add("set_movement_mode_to_linear",{}),I.add("plot_operation",{x:m.x,y:n(m.y)});continue}const R=Math.abs(w),U=4*Math.atan(R);if(Math.abs(Math.sin(U/2))<1e-9){I.add("set_movement_mode_to_linear",{}),I.add("plot_operation",{x:m.x,y:n(m.y)});continue}const Y=N/(2*Math.sin(U/2)),H=(Math.PI-U)/2,O=Math.atan2(x,k),W=w>0?H:-H,$=O+W,iA=D.x+Y*Math.cos($),rA=D.y+Y*Math.sin($),tA=iA-D.x,oA=rA-D.y;I.add("plot_operation",{x:m.x,y:n(m.y),i:tA,j:A.flip_y_axis?-oA:oA})}else I.add("set_movement_mode_to_linear",{}),I.add("plot_operation",{x:m.x,y:n(m.y)})}},Q=h=>{const{vertices:u}=h;if(!u||u.length===0)return{vertices:[]};const d=u.length;return{vertices:[...u].reverse().map((w,D)=>{const b=(d-2-D+d)%d,k=u[b].bulge;return{...w,bulge:k?-k:void 0}})}};if(E(Q(B)),C)for(const h of C)E(Q(h))}else if(a.shape==="rect"){const{center:l,width:B,height:C,rotation:E}=a,Q=B/2,h=C/2,u=[{x:-Q,y:h},{x:Q,y:h},{x:Q,y:-h},{x:-Q,y:-h}];let d=Hu();if(E){const m=E*Math.PI/180;d=Lm(m)}d=rB(hr(l.x,l.y),d);const f=u.map(m=>Pe(d,m));I.add("move_operation",{x:f[0].x,y:n(f[0].y)});for(let m=1;m<f.length;m++)I.add("plot_operation",{x:f[m].x,y:n(f[m].y)});I.add("plot_operation",{x:f[0].x,y:n(f[0].y)})}else if(a.shape==="polygon"){const{points:l}=a;if(l.length>0){I.add("move_operation",{x:l[0].x,y:n(l[0].y)});for(let B=1;B<l.length;B++)I.add("plot_operation",{x:l[B].x,y:n(l[B].y)});I.add("plot_operation",{x:l[0].x,y:n(l[0].y)})}}I.add("end_region_statement",{});const c=I.build();g.push(...c),a.covered_with_solder_mask===!1&&i[wf(r,"soldermask")].push(...c)}for(const r of Object.keys(i))i[r].push(...zI().add("end_of_file",{}).build());return i},IJ={},bfA={},fct;function z9e(){return fct||(fct=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0});var A=(function(){function o(s,r){var a=[],g=!0,I=!1,c=void 0;try{for(var l=s[Symbol.iterator](),B;!(g=(B=l.next()).done)&&(a.push(B.value),!(r&&a.length===r));g=!0);}catch(C){I=!0,c=C}finally{try{!g&&l.return&&l.return()}finally{if(I)throw c}}return a}return function(s,r){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return o(s,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();e.default=i,e.parseUnitObj=n;var t=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function i(o){var s=parseFloat(o),r=o.match(t)||[],a=r.length>0?o.substr(r[0].length).trim():"";return[s,a]}function n(o){var s=i(o),r=A(s,2),a=r[0],g=r[1];return{val:a,unit:g}}})(bfA)),bfA}var yct;function X9e(){if(yct)return IJ;yct=1,Object.defineProperty(IJ,"__esModule",{value:!0});var e=(function(){function a(g,I){var c=[],l=!0,B=!1,C=void 0;try{for(var E=g[Symbol.iterator](),Q;!(l=(Q=E.next()).done)&&(c.push(Q.value),!(I&&c.length===I));l=!0);}catch(h){B=!0,C=h}finally{try{!l&&E.return&&E.return()}finally{if(B)throw C}}return c}return function(g,I){if(Array.isArray(g))return g;if(Symbol.iterator in Object(g))return a(g,I);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();IJ.formatSI=o,IJ.unformatSI=r;function A(a){return a&&a.__esModule?a:{default:a}}var t=z9e(),i=A(t),n={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function o(a){if(a===0)return"0";for(var g=Math.abs(a),I=0;g>=1e3&&I<24;)g/=1e3,I+=3;for(;g<1&&I>-24;)g*=1e3,I-=3;var c=a<0?"-":"";return g>1e3?c+g.toFixed(0)+n[I]:c+parseFloat(g.toPrecision(3))+n[I]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function r(a){if(a==null||a==="")return NaN;var g=(0,i.default)(a),I=e(g,2),c=I[0],l=I[1],B=s[l];return c*B}return IJ}var $9e=X9e(),u9={exports:{}};var Aje=u9.exports,mct;function tje(){return mct||(mct=1,(function(e,A){((t,i)=>{e.exports=i()})(Aje,function t(){var i=typeof self<"u"?self:typeof window<"u"?window:i!==void 0?i:{},n,o=!i.document&&!!i.postMessage,s=i.IS_PAPA_WORKER||!1,r={},a=0,g={};function I(b){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(k){var x=m(k);x.chunkSize=parseInt(x.chunkSize),k.step||k.chunk||(x.chunkSize=null),this._handle=new E(x),(this._handle.streamer=this)._config=x}).call(this,b),this.parseChunk=function(k,x){var N=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<N){let U=this._config.newline;U||(R=this._config.quoteChar||'"',U=this._handle.guessLineEndings(k,R)),k=[...k.split(U).slice(N)].join(U)}this.isFirstChunk&&D(this._config.beforeFirstChunk)&&(R=this._config.beforeFirstChunk(k))!==void 0&&(k=R),this.isFirstChunk=!1,this._halted=!1;var N=this._partialLine+k,R=(this._partialLine="",this._handle.parse(N,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(k=R.meta.cursor,N=(this._finished||(this._partialLine=N.substring(k-this._baseIndex),this._baseIndex=k),R&&R.data&&(this._rowCount+=R.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)i.postMessage({results:R,workerId:g.WORKER_ID,finished:N});else if(D(this._config.chunk)&&!x){if(this._config.chunk(R,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=R=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(R.data),this._completeResults.errors=this._completeResults.errors.concat(R.errors),this._completeResults.meta=R.meta),this._completed||!N||!D(this._config.complete)||R&&R.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),N||R&&R.meta.paused||this._nextChunk(),R}this._halted=!0},this._sendError=function(k){D(this._config.error)?this._config.error(k):s&&this._config.error&&i.postMessage({workerId:g.WORKER_ID,error:k,finished:!1})}}function c(b){var k;(b=b||{}).chunkSize||(b.chunkSize=g.RemoteChunkSize),I.call(this,b),this._nextChunk=o?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(x){this._input=x,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(k=new XMLHttpRequest,this._config.withCredentials&&(k.withCredentials=this._config.withCredentials),o||(k.onload=w(this._chunkLoaded,this),k.onerror=w(this._chunkError,this)),k.open(this._config.downloadRequestBody?"POST":"GET",this._input,!o),this._config.downloadRequestHeaders){var x,N=this._config.downloadRequestHeaders;for(x in N)k.setRequestHeader(x,N[x])}var R;this._config.chunkSize&&(R=this._start+this._config.chunkSize-1,k.setRequestHeader("Range","bytes="+this._start+"-"+R));try{k.send(this._config.downloadRequestBody)}catch(U){this._chunkError(U.message)}o&&k.status===0&&this._chunkError()}},this._chunkLoaded=function(){k.readyState===4&&(k.status<200||400<=k.status?this._chunkError():(this._start+=this._config.chunkSize||k.responseText.length,this._finished=!this._config.chunkSize||this._start>=(x=>(x=x.getResponseHeader("Content-Range"))!==null?parseInt(x.substring(x.lastIndexOf("/")+1)):-1)(k),this.parseChunk(k.responseText)))},this._chunkError=function(x){x=k.statusText||x,this._sendError(new Error(x))}}function l(b){(b=b||{}).chunkSize||(b.chunkSize=g.LocalChunkSize),I.call(this,b);var k,x,N=typeof FileReader<"u";this.stream=function(R){this._input=R,x=R.slice||R.webkitSlice||R.mozSlice,N?((k=new FileReader).onload=w(this._chunkLoaded,this),k.onerror=w(this._chunkError,this)):k=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var R=this._input,U=(this._config.chunkSize&&(U=Math.min(this._start+this._config.chunkSize,this._input.size),R=x.call(R,this._start,U)),k.readAsText(R,this._config.encoding));N||this._chunkLoaded({target:{result:U}})},this._chunkLoaded=function(R){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(R.target.result)},this._chunkError=function(){this._sendError(k.error)}}function B(b){var k;I.call(this,b=b||{}),this.stream=function(x){return k=x,this._nextChunk()},this._nextChunk=function(){var x,N;if(!this._finished)return x=this._config.chunkSize,k=x?(N=k.substring(0,x),k.substring(x)):(N=k,""),this._finished=!k,this.parseChunk(N)}}function C(b){I.call(this,b=b||{});var k=[],x=!0,N=!1;this.pause=function(){I.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){I.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(R){this._input=R,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){N&&k.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),k.length?this.parseChunk(k.shift()):x=!0},this._streamData=w(function(R){try{k.push(typeof R=="string"?R:R.toString(this._config.encoding)),x&&(x=!1,this._checkIsFinished(),this.parseChunk(k.shift()))}catch(U){this._streamError(U)}},this),this._streamError=w(function(R){this._streamCleanUp(),this._sendError(R)},this),this._streamEnd=w(function(){this._streamCleanUp(),N=!0,this._streamData("")},this),this._streamCleanUp=w(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function E(b){var k,x,N,R,U=Math.pow(2,53),Y=-U,H=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,O=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,W=this,$=0,iA=0,rA=!1,tA=!1,oA=[],aA={data:[],errors:[],meta:{}};function QA(KA){return b.skipEmptyLines==="greedy"?KA.join("").trim()==="":KA.length===1&&KA[0].length===0}function SA(){if(aA&&N&&(MA("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+g.DefaultDelimiter+"'"),N=!1),b.skipEmptyLines&&(aA.data=aA.data.filter(function(dA){return!QA(dA)})),FA()){let dA=function(PA,JA){D(b.transformHeader)&&(PA=b.transformHeader(PA,JA)),oA.push(PA)};if(aA)if(Array.isArray(aA.data[0])){for(var KA=0;FA()&&KA<aA.data.length;KA++)aA.data[KA].forEach(dA);aA.data.splice(0,1)}else aA.data.forEach(dA)}function hA(dA,PA){for(var JA=b.header?{}:[],it=0;it<dA.length;it++){var fA=it,tt=dA[it],tt=((OA,HA)=>(ZA=>(b.dynamicTypingFunction&&b.dynamicTyping[ZA]===void 0&&(b.dynamicTyping[ZA]=b.dynamicTypingFunction(ZA)),(b.dynamicTyping[ZA]||b.dynamicTyping)===!0))(OA)?HA==="true"||HA==="TRUE"||HA!=="false"&&HA!=="FALSE"&&((ZA=>{if(H.test(ZA)&&(ZA=parseFloat(ZA),Y<ZA&&ZA<U))return 1})(HA)?parseFloat(HA):O.test(HA)?new Date(HA):HA===""?null:HA):HA)(fA=b.header?it>=oA.length?"__parsed_extra":oA[it]:fA,tt=b.transform?b.transform(tt,fA):tt);fA==="__parsed_extra"?(JA[fA]=JA[fA]||[],JA[fA].push(tt)):JA[fA]=tt}return b.header&&(it>oA.length?MA("FieldMismatch","TooManyFields","Too many fields: expected "+oA.length+" fields but parsed "+it,iA+PA):it<oA.length&&MA("FieldMismatch","TooFewFields","Too few fields: expected "+oA.length+" fields but parsed "+it,iA+PA)),JA}var GA;aA&&(b.header||b.dynamicTyping||b.transform)&&(GA=1,!aA.data.length||Array.isArray(aA.data[0])?(aA.data=aA.data.map(hA),GA=aA.data.length):aA.data=hA(aA.data,0),b.header&&aA.meta&&(aA.meta.fields=oA),iA+=GA)}function FA(){return b.header&&oA.length===0}function MA(KA,hA,GA,dA){KA={type:KA,code:hA,message:GA},dA!==void 0&&(KA.row=dA),aA.errors.push(KA)}D(b.step)&&(R=b.step,b.step=function(KA){aA=KA,FA()?SA():(SA(),aA.data.length!==0&&($+=KA.data.length,b.preview&&$>b.preview?x.abort():(aA.data=aA.data[0],R(aA,W))))}),this.parse=function(KA,hA,GA){var dA=b.quoteChar||'"',dA=(b.newline||(b.newline=this.guessLineEndings(KA,dA)),N=!1,b.delimiter?D(b.delimiter)&&(b.delimiter=b.delimiter(KA),aA.meta.delimiter=b.delimiter):((dA=((PA,JA,it,fA,tt)=>{var OA,HA,ZA,xA;tt=tt||[","," ","|",";",g.RECORD_SEP,g.UNIT_SEP];for(var wA=0;wA<tt.length;wA++){for(var UA,kA=tt[wA],TA=0,qA=0,At=0,DA=(ZA=void 0,new h({comments:fA,delimiter:kA,newline:JA,preview:10}).parse(PA)),lA=0;lA<DA.data.length;lA++)it&&QA(DA.data[lA])?At++:(UA=DA.data[lA].length,qA+=UA,ZA===void 0?ZA=UA:0<UA&&(TA+=Math.abs(UA-ZA),ZA=UA));0<DA.data.length&&(qA/=DA.data.length-At),(HA===void 0||TA<=HA)&&(xA===void 0||xA<qA)&&1.99<qA&&(HA=TA,OA=kA,xA=qA)}return{successful:!!(b.delimiter=OA),bestDelimiter:OA}})(KA,b.newline,b.skipEmptyLines,b.comments,b.delimitersToGuess)).successful?b.delimiter=dA.bestDelimiter:(N=!0,b.delimiter=g.DefaultDelimiter),aA.meta.delimiter=b.delimiter),m(b));return b.preview&&b.header&&dA.preview++,k=KA,x=new h(dA),aA=x.parse(k,hA,GA),SA(),rA?{meta:{paused:!0}}:aA||{meta:{paused:!1}}},this.paused=function(){return rA},this.pause=function(){rA=!0,x.abort(),k=D(b.chunk)?"":k.substring(x.getCharIndex())},this.resume=function(){W.streamer._halted?(rA=!1,W.streamer.parseChunk(k,!0)):setTimeout(W.resume,3)},this.aborted=function(){return tA},this.abort=function(){tA=!0,x.abort(),aA.meta.aborted=!0,D(b.complete)&&b.complete(aA),k=""},this.guessLineEndings=function(PA,dA){PA=PA.substring(0,1048576);var dA=new RegExp(Q(dA)+"([^]*?)"+Q(dA),"gm"),GA=(PA=PA.replace(dA,"")).split("\r"),dA=PA.split(`
5743
5743
  `),PA=1<dA.length&&dA[0].length<GA[0].length;if(GA.length===1||PA)return`
5744
5744
  `;for(var JA=0,it=0;it<GA.length;it++)GA[it][0]===`
5745
5745
  `&&JA++;return JA>=GA.length/2?`\r