@tscircuit/runframe 0.0.3061 → 0.0.3063

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.
@@ -5667,7 +5667,7 @@ test("${i} should solve problem correctly", () => {
5667
5667
  // Add more specific assertions based on expected output
5668
5668
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5669
5669
  })
5670
- `,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return T.jsxs("div",{className:`relative ${A}`,ref:t,children:[T.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&T.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:[T.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),T.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download page.tsx"}),T.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},CPI=g=>g.activeSubSolver?[g,...CPI(g.activeSubSolver)]:[g],xpo=({solver:g})=>{const A=CPI(g);return T.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>T.jsxs("div",{className:"flex items-center",children:[e>0&&T.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),T.jsx(Npo,{solver:I})]},I.getSolverName()))})},Fpo=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:o,onDownloadVisualization:B,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=z.useReducer(m=>!m,!1),n=z.useRef(void 0),s=z.useRef(null),r="solver-debugger-last-iteration",[a,c]=z.useState(null),h=z.useRef(null),l=z.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return z.useEffect(()=>()=>{d()},[]),z.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),z.useEffect(()=>{i&&(d(),D())},[I,i]),z.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),T.jsxs("div",{className:"space-y-2 p-2 border-b",children:[T.jsx("div",{className:"flex items-center",children:T.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[T.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[T.jsxs("div",{className:"relative",children:[T.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&T.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>T.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&T.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),T.jsxs("div",{className:"relative",children:[T.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&T.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:T.jsx("button",{type:"button",onClick:()=>{B(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),T.jsxs("div",{className:"relative",children:[T.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&T.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>T.jsxs("button",{type:"button",onClick:()=>{o(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,T.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&T.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),T.jsx(xpo,{solver:g})]})}),T.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[T.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),T.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),T.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),T.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),T.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&T.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&T.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&T.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&T.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},Upo=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),Jpo=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Ppo=(g,A)=>{const e=g.pipelineDef[A].solverName,t=Jpo(g,A),o=g[e],B=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&B!==null?Q=r-B:B!==null&&(Q=C-B)}else t==="In Progress"&&B!==null&&(Q=C-B);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&o&&(E=o.progress??0);const n=o?.stats??null;return{index:A,name:e,status:t,firstIteration:B,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:o??null}},Kpo=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return T.jsx("span",{className:`font-medium ${A[g]}`,children:g})},Lpo=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return T.jsxs("div",{className:"flex items-center gap-2",children:[T.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:T.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),T.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},QPI=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},Ypo=g=>Object.entries(g).map(([A,I])=>`${A}: ${QPI(I)}`).join(", "),_po=({stats:g})=>{if(!g||Object.keys(g).length===0)return T.jsx("span",{children:"-"});const A=Object.entries(g),I=Ypo(g);return T.jsxs("details",{className:"cursor-pointer",children:[T.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),T.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>T.jsxs("div",{children:[e,": ",QPI(t)]},e))})]})},uCg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(uCg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=uCg(e));return A},bpo=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=uCg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},Hpo=({expanded:g})=>T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:T.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"})}),iPI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},EPI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:o})=>{const[B,C]=z.useState(new Set),Q=g.pipelineDef.map((h,l)=>Ppo(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):bpo(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););o?.()}},a=()=>{if(!g.solved&&!g.failed){const h=iPI(g);for(;!g.solved&&!g.failed&&(g.step(),iPI(g)===h););o?.()}},c=t*24;return T.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&T.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[T.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),T.jsxs("div",{className:"flex gap-2",children:[T.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),T.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),T.jsx("div",{className:"overflow-x-auto",children:T.jsxs("table",{className:"w-full text-sm",children:[!e&&T.jsx("thead",{children:T.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),T.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",T.jsx("sub",{children:"0"})]}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),T.jsx("tbody",{children:Q.map(h=>{const l=Upo(h.solverInstance),D=B.has(h.name);return T.jsxs(rC.Fragment,{children:[T.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[T.jsx("td",{className:"px-4 py-2",children:T.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?T.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:T.jsx(Hpo,{expanded:D})}):T.jsx("span",{className:"w-4"}),T.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),T.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:T.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"})})}),T.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),T.jsx("td",{className:"px-4 py-2",children:T.jsx(Kpo,{status:h.status})}),T.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),T.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),T.jsx("td",{className:"px-4 py-2",children:T.jsx(Lpo,{progress:h.progress})}),T.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),T.jsx("td",{className:"px-4 py-2 text-gray-500",children:T.jsx(_po,{stats:h.stats})}),T.jsx("td",{className:"px-4 py-2",children:h.solverInstance?T.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:T.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"})}),T.jsx("span",{children:"Input"})]}):null})]}),l&&D&&T.jsx("tr",{children:T.jsx("td",{colSpan:8,className:"p-0",children:T.jsx(EPI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:o})})})]},h.name)})})]})})]})};function vpo({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],o=g.texts??[];let B=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<B&&(B=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of o)E(h.x,h.y);(!isFinite(B)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(B=-20,C=-20,Q=20,i=20);const n=10,s=B-n,r=C-n,a=Math.max(1,Q-B+2*n),c=Math.max(1,i-C+2*n);return T.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>T.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>T.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>T.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>T.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),o.map((h,l)=>T.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var Tpo=class extends rC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},qpo=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[o,B]=z.useReducer(D=>D+1,0),[C]=z.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=z.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=z.useState(I),s=z.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,o]),r=z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),z.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();B()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return T.jsxs("div",{children:[T.jsx(Fpo,{solver:C,triggerRender:B,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?T.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):T.jsx(Tpo,{fallback:T.jsx(vpo,{graphics:s}),children:Q==="canvas"?T.jsx(Rpo,{graphics:s}):T.jsx(Mpo,{graphics:s})}),a&&T.jsx(EPI,{solver:C,onStepUntilPhase:c,triggerRender:B})]})};const Zpo=()=>{z.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},Opo=1e3,_k=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),o=URL.createObjectURL(t),B=document.createElement("a");B.href=o,B.download=I,B.target="_blank",B.rel="noopener noreferrer",B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),setTimeout(()=>{URL.revokeObjectURL(o)},Opo)},GCg=g=>{let A=g.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},Wpo=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},yF="https://github.com/tscircuit/tscircuit-autorouter/issues/new",nPI="https://github.com/tscircuit/copper-pour-solver/issues/new",sPI="https://github.com/tscircuit/calculate-packing/issues/new",Vpo="https://github.com/tscircuit/matchpack/issues/new",aPI="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",jpo={PackSolver2:sPI,LayoutPipelineSolver:Vpo,AutoroutingPipelineSolver:yF,AssignableAutoroutingPipeline2:yF,AssignableAutoroutingPipeline3:yF,AutoroutingPipeline1_OriginalUnravel:yF,AutoroutingPipelineSolver3_HgPortPointPathing:yF,AutoroutingPipelineSolver4:yF,AutoroutingPipelineSolver5:yF,AutoroutingPipelineSolver7_MultiGraph:yF,AutoroutingPipelineSolver8:yF,CopperPourPipelineSolver:nPI,SchematicTracePipelineSolver:aPI},zpo=g=>g.toLowerCase().includes("pack")?$1I:g.toLowerCase().includes("rout")?gxI:Vro,rPI=g=>{const A=jpo[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?yF:I.includes("schematic")&&I.includes("trace")?aPI:I.includes("copperpour")?nPI:I.includes("pack")?sPI:null},Xpo=g=>`${GCg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,cPI=g=>{_k(JSON.stringify(g.solverParams,null,2),{fileName:Xpo(g),mimeType:"application/json"})},$po=({solverEvent:g})=>{const A=rPI(g.solverName);return T.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[T.jsxs(si,{type:"button",variant:"outline",size:"sm",onClick:()=>cPI(g),children:[T.jsx(ktA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?T.jsx(si,{asChild:!0,variant:"outline",size:"sm",children:T.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[T.jsx(LGA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):T.jsxs(si,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[T.jsx(LGA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},Ako=({solverEvent:g})=>{const A=rPI(g.solverName);return A?T.jsx(si,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:T.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:T.jsx(LGA,{className:"rf-w-4 rf-h-4"})})}):T.jsx(si,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:T.jsx(LGA,{className:"rf-w-4 rf-h-4"})})},gko=({solverEvents:g=[]})=>{const[A,I]=z.useState(null);Zpo();const e=z.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=z.useMemo(()=>Array.from(e.keys()),[e]),o=A?e.get(A):null,B=z.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const C=b9A[o.solverName];if(!C)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(b9A).join(", ")}`,classFound:!1};try{return{instance:new C(...Wpo(o)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[o]);return g.length===0?T.jsx("div",{className:"rf-p-4",children:T.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:T.jsxs("div",{className:"rf-p-4",children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),T.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."})]})})}):T.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[T.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[T.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return T.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=zpo(Q.solverName);return T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[T.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),T.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[T.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),T.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),T.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?B.instance?T.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[T.jsx($po,{solverEvent:o}),T.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:T.jsx(pS,{fallback:T.jsx("div",{className:"rf-p-4",children:T.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),T.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:T.jsx(qpo,{solver:B.instance})})})]}):T.jsxs("div",{className:"rf-p-4",children:[T.jsxs("div",{className:"rf-mb-4",children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),T.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),B.error&&T.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${B.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:T.jsx("p",{className:`rf-text-sm ${B.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:B.error})}),T.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[T.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[T.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[T.jsx(Ako,{solverEvent:o}),T.jsx(si,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>cPI(o),children:T.jsx(ktA,{className:"rf-w-4 rf-h-4"})})]})]}),T.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:T.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)})})]})]}):T.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:T.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Iko=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],eko=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function tko(g,A){let I=-1,e=-1;for(let t=g.length-1;t>=0;t--){const o=g[t];if(o.status!=="running"||o.subcircuit_id!==A.subcircuit_id||o.componentDisplayName!==A.componentDisplayName)continue;let B=0,C=!1;for(const Q of eko)if(!(o[Q]===void 0||A[Q]===void 0)){if(o[Q]!==A[Q]){C=!0;break}B++}!C&&B>e&&(I=t,e=B)}return I}function oko(g,A){const I=Object.fromEntries(Iko.filter(B=>A[B]!==void 0).map(B=>[B,A[B]])),e=A.simpleRouteJson?structuredClone(A.simpleRouteJson):void 0,t=A.type==="autorouting:start"?-1:tko(g,A),o={...t===-1?{id:`autorouting_phase_${g.length+1}`}:g[t],...I,status:A.type==="autorouting:start"?"running":A.type==="autorouting:end"?"complete":"error",...A.type==="autorouting:start"?{startSimpleRouteJson:e}:A.type==="autorouting:end"?{endSimpleRouteJson:e}:{errorSimpleRouteJson:e,error:A.error?{...A.error}:void 0}};return t===-1?[...g,o]:g.map((B,C)=>C===t?o:B)}const Bko=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Cko=new Set(["tscircuit","default","auto","auto_local"]);function Qko(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function iko(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&Bko.get(I);if(e)return e;if(I&&!Cko.has(I))return A;const t=g.solverName?.trim();if(t)return Qko(t);const o=g.autorouterVersion?.trim();if(o){const B=o.match(/^beta[_-]pipeline(\d+)$/);return B?`Pipeline${B[1]}`:o==="latest"?"default":o}return A?"default":"Unknown"}const mCg="#fbbf24";function Eko(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(o=>o!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function hPI(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function nko(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function lPI(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...nko(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),o=[];let B=0;for(const[C,Q]of t)C>=B&&o.push(I.slice(B,C+1)),B=Math.max(B,Q);return B<I.length&&o.push(I.slice(B)),o}function sko(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(hPI(g));for(const o of e.traces??[])if(t.has(o.pcb_trace_id))for(const B of lPI(o,e)){let C;for(const Q of B){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:mCg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:mCg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function ako(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const rko=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function cko(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!rko.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const o=I==="input"?e.traces??[]:Eko(A),B=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of o){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=lPI(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${ako(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:B.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const pCg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,DPI=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",dPI=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,hko={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},lko=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=z.useState(null),[o,B]=z.useState("output"),[C,Q]=z.useState(!0),[i,E]=z.useState(!1),n=z.useRef(null),[s,r]=z.useState(480),a=e?A.findIndex(N=>N.id===e.id&&dPI(N)===dPI(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=o==="output"&&!D?"input":o==="input"&&!y?"output":o,u=w==="input"?d:h?.endSimpleRouteJson,G=z.useMemo(()=>!h||!u?null:cko(g??[],h,w),[g,h,u,w]),m=z.useMemo(()=>h&&w==="output"&&C?sko(h):{lines:[],circles:[]},[h,w,C]);if(z.useLayoutEffect(()=>{const N=n.current;if(!N)return;const U=()=>r(Math.max(360,N.clientHeight));U();const K=new ResizeObserver(U);return K.observe(N),()=>K.disconnect()},[!!h]),!h)return T.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[T.jsx(gxI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),T.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),T.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=pCg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return T.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[T.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[T.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[T.jsx("span",{children:"Routing phases"}),T.jsx("span",{children:A.length})]}),T.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,U)=>{const K=hPI(N).length,Y=N.endSimpleRouteJson?`${K} ${K===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return T.jsxs("button",{type:"button","aria-pressed":U===c,title:`${DPI(N)} · ${Y}`,onClick:()=>t(N),className:Bo("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",U===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[T.jsx("span",{className:Bo("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",U===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:U+1}),T.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[T.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[T.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:pCg(N,U),children:pCg(N,U)}),N.status==="complete"?T.jsx(aF,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?T.jsx(Hog,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?T.jsx(kS,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),T.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[iko(N)," · ",Y]})]})]},N.id)})})]}),T.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[T.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[T.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,T.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&T.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),T.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>T.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>B(N),className:Bo("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),T.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[T.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[T.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),T.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:mCg}}),"Highlight changes (all layers)"]}),T.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&T.jsx("div",{className:Bo("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),T.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?T.jsx(Yog,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:hko,debugGraphics:m}):T.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),T.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[T.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${DPI(h)}`]}),T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[T.jsxs("button",{type:"button",disabled:!u,onClick:()=>_k(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[T.jsx(ktA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),T.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[T.jsx(Rb,{className:Bo("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&T.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},yPI=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{z.useEffect(()=>{if(uJ("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{Rq.captureException(e)}catch{}}},[g,A]),z.useEffect(()=>{if(uJ("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{Rq.captureException(t,{error_type:e.type})}catch{}}},[I])},wPI=g=>{z.useEffect(()=>{try{sdt(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},uPI="0.0.3060",Dko={version:uPI},BpA=cXg()(hXg(g=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{g({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),dko=g=>{const[A,I]=z.useState([]),[e,t]=z.useState(null),[o,B]=z.useState(""),[C,Q]=XT("eval-version-selection",null),i=BpA(r=>r.setLastRunEvalVersion),E=BpA(r=>r.lastRunEvalVersion);return z.useEffect(()=>{g&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(r=>r.json()).then(r=>{if(Array.isArray(r?.versions)){let a=[...r.versions];r.tags?.latest&&(t(r.tags.latest),a=a.filter(c=>c!==r.tags.latest)),I(a)}}).catch(()=>{})},[g]),z.useEffect(()=>{g&&(C?(window.TSCIRCUIT_LATEST_EVAL_VERSION=C,i(C)):e&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=e,i(e)))},[g,C,e]),{versions:z.useMemo(()=>A.filter(r=>r.includes(o)).slice(0,50),[A,o]),latestVersion:e,lastRunEvalVersion:E,search:o,setSearch:B,selectVersion:r=>{Q(r),B("")}}},yko=({snippetNames:g,onSelect:A,onCancel:I,isOpen:e})=>{const[t,o]=z.useState(""),[B,C]=z.useState("");if(!e)return null;const Q=g.filter(n=>n.toLowerCase().includes(B.toLowerCase())),i=B&&!g.includes(B),E=n=>{n.key==="Enter"&&(Q.length===1?o(Q[0]):i&&o(B))};return T.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:T.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[T.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),T.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:B,onChange:n=>C(n.target.value),onKeyDown:E}),T.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[Q.map(n=>T.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${t===n?"bg-blue-50":""}`,onClick:()=>o(n),children:n},n)),i&&T.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${t===B?"bg-blue-50":""}`,onClick:()=>o(B),children:['Create new "',B,'"']})]}),T.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[T.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:I,children:"Cancel"}),T.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>t&&A(t),disabled:!t,children:t===B?`Create "${t}"`:`Save to ${t}`})]})]})})},wko=g=>{const A=z.useRef(null),I=Jc(e=>e.recentEvents);z.useEffect(()=>{if(I.length===0)return;const e=I[0];e.event_id!==A.current&&(g(e),A.current=e.event_id)},[I,g])};var uko=Object.defineProperty,iP=(g,A)=>uko(g,"name",{value:A,configurable:!0}),Gko="AlertDialog",[mko,SCB]=rk(Gko,[SFI]),EP=SFI(),pko=iP(g=>{const{__scopeAlertDialog:A,...I}=g,e=EP(A);return T.jsx(umA,{...e,...I,modal:!0})},"AlertDialog");z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(ylo,{...o,...t,ref:I})},"AlertDialogTrigger"));var kko=iP(g=>{const{__scopeAlertDialog:A,...I}=g,e=EP(A);return T.jsx(GmA,{...e,...I})},"AlertDialogPortal"),GPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(YtA,{...o,...t,ref:I})},"AlertDialogOverlay")),Mko="AlertDialogContent",[Sko,fko]=mko(Mko),mPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,children:t,...o}=A,B=EP(e),C=z.useRef(null),Q=Gi(I,C),i=z.useRef(null);return T.jsx(Sko,{scope:e,cancelRef:i,children:T.jsx(btA,{role:"alertdialog",...B,...o,ref:Q,onOpenAutoFocus:fo(o.onOpenAutoFocus,E=>{E.preventDefault(),i.current?.focus({preventScroll:!0})}),onPointerDownOutside:E=>E.preventDefault(),onInteractOutside:E=>E.preventDefault(),children:t})})},"AlertDialogContent")),pPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(mmA,{...o,...t,ref:I})},"AlertDialogTitle")),kPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(pmA,{...o,...t,ref:I})},"AlertDialogDescription")),MPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(NBg,{...o,...t,ref:I})},"AlertDialogAction")),Rko="AlertDialogCancel",SPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,{cancelRef:o}=fko(Rko,e),B=EP(e),C=Gi(I,o);return T.jsx(NBg,{...B,...t,ref:C})},"AlertDialogCancel"));const fPI=pko,Nko=kko,RPI=z.forwardRef(({className:g,...A},I)=>T.jsx(GPI,{className:Bo("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));RPI.displayName=GPI.displayName;const kCg=z.forwardRef(({className:g,...A},I)=>T.jsxs(Nko,{children:[T.jsx(RPI,{}),T.jsx(mPI,{ref:I,className:Bo("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...A})]}));kCg.displayName=mPI.displayName;const MCg=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});MCg.displayName="AlertDialogHeader";const SCg=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});SCg.displayName="AlertDialogFooter";const fCg=z.forwardRef(({className:g,...A},I)=>T.jsx(pPI,{ref:I,className:Bo("rf-text-lg rf-font-semibold",g),...A}));fCg.displayName=pPI.displayName;const RCg=z.forwardRef(({className:g,...A},I)=>T.jsx(kPI,{ref:I,className:Bo("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));RCg.displayName=kPI.displayName;const xko=z.forwardRef(({className:g,...A},I)=>T.jsx(MPI,{ref:I,className:Bo(nO(),g),...A}));xko.displayName=MPI.displayName;const NCg=z.forwardRef(({className:g,...A},I)=>T.jsx(SPI,{ref:I,className:Bo(nO({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",g),...A}));NCg.displayName=SPI.displayName;var Fko=Object.defineProperty,nP=(g,A)=>Fko(g,"name",{value:A,configurable:!0}),xCg="Checkbox",[Uko,fCB]=rk(xCg),[Jko,FCg]=Uko(xCg);function NPI(g){const{__scopeCheckbox:A,checked:I,children:e,defaultChecked:t,disabled:o,form:B,name:C,onCheckedChange:Q,required:i,value:E="on",internal_do_not_use_render:n}=g,[s,r]=NR({prop:I,defaultProp:t??!1,onChange:Q,caller:xCg}),[a,c]=z.useState(null),[h,l]=z.useState(null),[D,d]=z.useState(null),y=a?!!B||!!a.closest("form"):!0,w={checked:s,disabled:o,setChecked:r,control:a,setControl:c,name:C,form:B,value:E,userClick:D,onUserClick:d,required:i,defaultChecked:wf(t)?!1:t,isFormControl:y,bubbleInput:h,setBubbleInput:l};return T.jsx(Jko,{scope:A,...w,children:FPI(n)?n(w):e})}nP(NPI,"CheckboxProvider");var Pko="CheckboxTrigger",Kko=z.forwardRef(nP(function({__scopeCheckbox:A,onKeyDown:I,onClick:e,...t},o){const{control:B,value:C,disabled:Q,checked:i,required:E,setControl:n,setChecked:s,onUserClick:r,isFormControl:a,bubbleInput:c}=FCg(Pko,A),h=Gi(o,n),l=z.useRef(i);return z.useEffect(()=>{const D=B?.form;if(D){const d=nP(()=>s(l.current),"reset");return D.addEventListener("reset",d),()=>D.removeEventListener("reset",d)}},[B,s]),T.jsx(yQ.button,{type:"button",role:"checkbox","aria-checked":wf(i)?"mixed":i,"aria-required":E,"data-state":UCg(i),"data-disabled":Q?"":void 0,disabled:Q,value:C,...t,ref:h,onKeyDown:fo(I,D=>{D.key==="Enter"&&D.preventDefault()}),onClick:fo(e,D=>{const d=D.isPropagationStopped();r({requestedChecked:wf(i)?!0:!i,hasConsumerStoppedPropagation:d}),s(y=>wf(y)?!0:!y),c&&a&&(d||D.stopPropagation())})})},"CheckboxTrigger")),xPI=z.forwardRef(nP(function(A,I){const{__scopeCheckbox:e,name:t,checked:o,defaultChecked:B,required:C,disabled:Q,value:i,onCheckedChange:E,form:n,...s}=A;return T.jsx(NPI,{__scopeCheckbox:e,checked:o,defaultChecked:B,disabled:Q,required:C,onCheckedChange:E,name:t,form:n,value:i,internal_do_not_use_render:({isFormControl:r})=>T.jsxs(T.Fragment,{children:[T.jsx(Kko,{...s,ref:I,__scopeCheckbox:e}),r&&T.jsx(bko,{__scopeCheckbox:e})]})})},"Checkbox")),Lko="CheckboxIndicator",Yko=z.forwardRef(nP(function(A,I){const{__scopeCheckbox:e,forceMount:t,...o}=A,B=FCg(Lko,e);return T.jsx($M,{present:t||wf(B.checked)||B.checked===!0,children:T.jsx(yQ.span,{"data-state":UCg(B.checked),"data-disabled":B.disabled?"":void 0,...o,ref:I,style:{pointerEvents:"none",...A.style}})})},"CheckboxIndicator")),_ko="CheckboxBubbleInput",bko=z.forwardRef(nP(function({__scopeCheckbox:A,onClick:I,...e},t){const{control:o,userClick:B,checked:C,defaultChecked:Q,required:i,disabled:E,name:n,value:s,form:r,bubbleInput:a,setBubbleInput:c}=FCg(_ko,A),h=Gi(t,c),l=sBg(o),D=z.useRef(!1),d=z.useRef(C),y=z.useRef(B),w=z.useRef(null);z.useEffect(()=>{const G=a;if(!G)return;const m=window.HTMLInputElement.prototype,k=Object.getOwnPropertyDescriptor(m,"checked").set;if(!k)return;const S=d.current!==C;d.current=C;const R=B!==null&&B!==y.current;if(y.current=B,R)w.current=S?null:B,S&&(G.indeterminate=wf(C),k.call(G,wf(C)?!1:C)),G.dispatchEvent(new Event("click",{bubbles:!B.hasConsumerStoppedPropagation}));else if(S){const x=w.current;w.current=null;const N=x?.requestedChecked===C;D.current=!0,G.indeterminate=wf(C),k.call(G,wf(C)?!1:C),G.dispatchEvent(new Event("click",{bubbles:!(N&&x.hasConsumerStoppedPropagation)})),D.current=!1}},[a,C,B]);const u=z.useRef(wf(C)?!1:C);return T.jsx(yQ.input,{type:"checkbox","aria-hidden":!0,defaultChecked:Q??u.current,required:i,disabled:E,name:n,value:s,form:r,...e,tabIndex:-1,ref:h,onClick:fo(I,G=>{D.current&&G.stopPropagation()}),style:{...e.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function FPI(g){return typeof g=="function"}nP(FPI,"isFunction");function wf(g){return g==="indeterminate"}nP(wf,"isIndeterminate");function UCg(g){return wf(g)?"indeterminate":g?"checked":"unchecked"}nP(UCg,"getState");const ioA=z.forwardRef(({className:g,...A},I)=>T.jsx(xPI,{ref:I,className:Bo("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",g),...A,children:T.jsx(Yko,{className:Bo("rf-flex rf-items-center rf-justify-center rf-text-current"),children:T.jsx(aF,{className:"rf-h-4 rf-w-4"})})}));ioA.displayName=xPI.displayName;const Yb=umA,Hko=GmA,UPI=z.forwardRef(({className:g,...A},I)=>T.jsx(YtA,{className:Bo("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));UPI.displayName=YtA.displayName;const NL=z.forwardRef(({className:g,children:A,showOverlay:I=!0,...e},t)=>T.jsxs(Hko,{children:[T.jsx(UPI,{className:Bo(I?"":"rf-hidden")}),T.jsx(btA,{ref:t,className:Bo("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...e,children:A})]}));NL.displayName=btA.displayName;const xL=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});xL.displayName="DialogHeader";const YO=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});YO.displayName="DialogFooter";const FL=z.forwardRef(({className:g,...A},I)=>T.jsx(mmA,{ref:I,className:Bo("rf-text-lg rf-font-semibold",g),...A}));FL.displayName=mmA.displayName;const _b=z.forwardRef(({className:g,...A},I)=>T.jsx(pmA,{ref:I,className:Bo("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));_b.displayName=pmA.displayName;const CpA={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},vko="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let JCg=null;const PCg=async()=>(JCg||(JCg=import(vko)),JCg),Tko=g=>(A,I)=>{const e=new Headers(I?.headers),t={};return e.forEach((o,B)=>{t[B]=o}),fetch(`${g?.apiBase??Fm}/proxy`,{...I,headers:{...t,"X-Target-Url":A.toString(),"X-Sender-Origin":t.origin??"","X-Sender-Host":t.host??"https://easyeda.com","X-Sender-Referer":t.referer??"","X-Sender-User-Agent":t["user-agent"]??"","X-Sender-Cookie":t.cookie??"",authority:t.authority??"","content-type":t["content-type"]??"",...g?.headers}})},qko=async(g,A=10)=>{const I=encodeURIComponent(g),e=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${A}&q=${I}`);if(!e.ok)throw new Error(`JLCPCB API error: ${e.status}`);return(await e.json()).components??[]},Zko=g=>({lcscId:g.lcsc,manufacturer:g.mfr,description:g.description,partNumber:`C${g.lcsc}`,package:g.package,price:g.price,stock:g.stock,isBasic:g.is_basic}),JPI=async(g,A)=>{const{fetchEasyEDAComponent:I}=await PCg();return I(g,{fetch:Tko(A),includeModelMetadata:A?.includeModelMetadata})},Oko=async(g,A)=>{const{convertRawEasyToTsx:I}=await PCg(),e=await JPI(g,A);return I({rawEasy:e})},Wko=async(g,A)=>{const{EasyEdaJsonSchema:I,convertEasyEdaJsonToCircuitJson:e}=await PCg(),t=await JPI(g,{...A,includeModelMetadata:!1}),o=I.parse(t);return e(o,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function UL(g){return Array.isArray?Array.isArray(g):KPI(g)==="[object Array]"}function Vko(g){if(typeof g=="string")return g;if(typeof g=="bigint")return g.toString();const A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function KCg(g){return g==null?"":Vko(g)}function wG(g){return typeof g=="string"}function QpA(g){return typeof g=="number"}function jko(g){return g===!0||g===!1||zko(g)&&KPI(g)=="[object Boolean]"}function PPI(g){return typeof g=="object"}function zko(g){return PPI(g)&&g!==null}function FS(g){return g!=null}function ipA(g){return!g.trim().length}function KPI(g){return g==null?g===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(g)}const Xko="Incorrect 'index' type",LCg="Invalid doc index: must be a non-negative integer within the bounds of the docs array",$ko=g=>`Invalid value for key ${g}`,AMo=g=>`Pattern length exceeds max of ${g}.`,gMo=g=>`Missing ${g} property in key`,IMo=g=>`Property 'weight' in key '${g}' must be a positive integer`,eMo="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",LPI=Object.prototype.hasOwnProperty;var tMo=class{constructor(g){this._keys=[],this._keyMap={};let A=0;g.forEach(I=>{const e=YPI(I);this._keys.push(e),this._keyMap[e.id]=e,A+=e.weight}),this._keys.forEach(I=>{I.weight/=A})}get(g){return this._keyMap[g]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function YPI(g){let A=null,I=null,e=null,t=1,o=null;if(wG(g)||UL(g))e=g,A=_PI(g),I=EpA(g);else{if(!LPI.call(g,"name"))throw new Error(gMo("name"));const B=g.name;if(e=B,LPI.call(g,"weight")&&g.weight!==void 0&&(t=g.weight,t<=0))throw new Error(IMo(EpA(B)));A=_PI(B),I=EpA(B),o=g.getFn??null}return{path:A,id:I,weight:t,src:e,getFn:o}}function _PI(g){return UL(g)?g:g.split(".")}function EpA(g){return UL(g)?g.join("."):g}function oMo(g,A){const I=[];let e=!1;const t=(o,B,C,Q)=>{if(FS(o))if(!B[C])I.push(Q!==void 0?{v:o,i:Q}:o);else{const i=o[B[C]];if(!FS(i))return;if(C===B.length-1&&(wG(i)||QpA(i)||jko(i)||typeof i=="bigint"))I.push(Q!==void 0?{v:KCg(i),i:Q}:KCg(i));else if(UL(i)){e=!0;for(let E=0,n=i.length;E<n;E+=1)t(i[E],B,C+1,E)}else B.length&&t(i,B,C+1,Q)}};return t(g,wG(A)?A.split("."):A,0),e?I:I[0]}const cQ=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(g,A)=>g.score===A.score?g.idx<A.idx?-1:1:g.score<A.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:oMo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function BMo(g){return g>=9&&g<=13||g===32||g===160}function CMo(g=1,A=3){const I=new Map,e=Math.pow(10,A);return{get(t){let o=0,B=!1;for(let Q=0;Q<t.length;Q++)BMo(t.charCodeAt(Q))?B=!1:B||(o++,B=!0);if(o===0&&(o=1),I.has(o))return I.get(o);const C=Math.round(e/Math.pow(o,.5*g))/e;return I.set(o,C),C},clear(){I.clear()}}}var YCg=class{constructor({getFn:g=cQ.getFn,fieldNormWeight:A=cQ.fieldNormWeight}={}){this.norm=CMo(A,3),this.getFn=g,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(g=[]){this.docs=g}setIndexRecords(g=[]){this.records=g}setKeys(g=[]){this.keys=g,this._keysMap={},g.forEach((A,I)=>{this._keysMap[A.id]=I})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const g=this.docs.length;this.records=new Array(g);let A=0;if(wG(this.docs[0]))for(let I=0;I<g;I++){const e=this._createStringRecord(this.docs[I],I);e&&(this.records[A++]=e)}else for(let I=0;I<g;I++)this.records[A++]=this._createObjectRecord(this.docs[I],I);this.records.length=A,this.norm.clear()}add(g,A){if(!Number.isInteger(A)||A<0)throw new Error(LCg);if(wG(g)){const e=this._createStringRecord(g,A);return e&&this.records.push(e),e}const I=this._createObjectRecord(g,A);return this.records.push(I),I}removeAt(g){if(!Number.isInteger(g)||g<0)throw new Error(LCg);for(let A=0,I=this.records.length;A<I;A+=1)if(this.records[A].i===g){this.records.splice(A,1);break}for(let A=0,I=this.records.length;A<I;A+=1)this.records[A].i>g&&(this.records[A].i-=1)}removeAll(g){const A=new Set;for(const e of g)Number.isInteger(e)&&e>=0&&A.add(e);if(A.size===0)return;this.records=this.records.filter(e=>!A.has(e.i));const I=Array.from(A).sort((e,t)=>e-t);for(const e of this.records){let t=0,o=I.length;for(;t<o;){const B=t+o>>>1;I[B]<e.i?t=B+1:o=B}e.i-=t}}getValueForItemAtKeyId(g,A){return g[this._keysMap[A]]}size(){return this.records.length}_createStringRecord(g,A){return!FS(g)||ipA(g)?null:{v:g,i:A,n:this.norm.get(g)}}_createObjectRecord(g,A){const I={i:A,$:{}};for(let e=0,t=this.keys.length;e<t;e++){const o=this.keys[e],B=o.getFn?o.getFn(g):this.getFn(g,o.path);if(FS(B)){if(UL(B)){const C=[];for(let Q=0,i=B.length;Q<i;Q+=1){const E=B[Q];if(FS(E)){if(wG(E)){if(!ipA(E)){const n={v:E,i:Q,n:this.norm.get(E)};C.push(n)}}else if(FS(E.v)){const n=wG(E.v)?E.v:KCg(E.v);if(!ipA(n)){const s={v:n,i:E.i,n:this.norm.get(n)};C.push(s)}}}}I.$[e]=C}else if(wG(B)&&!ipA(B)){const C={v:B,n:this.norm.get(B)};I.$[e]=C}}}return I}toJSON(){return{keys:this.keys.map(({getFn:g,...A})=>A),records:this.records}}};function bPI(g,A,{getFn:I=cQ.getFn,fieldNormWeight:e=cQ.fieldNormWeight}={}){const t=new YCg({getFn:I,fieldNormWeight:e});return t.setKeys(g.map(YPI)),t.setSources(A),t.create(),t}function QMo(g,{getFn:A=cQ.getFn,fieldNormWeight:I=cQ.fieldNormWeight}={}){const{keys:e,records:t}=g,o=new YCg({getFn:A,fieldNormWeight:I});return o.setKeys(e),o.setIndexRecords(t),o}function iMo(g=[],A=cQ.minMatchCharLength){const I=[];let e=-1,t=-1,o=0;for(let B=g.length;o<B;o+=1){const C=g[o];C&&e===-1?e=o:!C&&e!==-1&&(t=o-1,t-e+1>=A&&I.push([e,t]),e=-1)}return g[o-1]&&o-e>=A&&I.push([e,o-1]),I}function EMo(g,A,I,{location:e=cQ.location,distance:t=cQ.distance,threshold:o=cQ.threshold,findAllMatches:B=cQ.findAllMatches,minMatchCharLength:C=cQ.minMatchCharLength,includeMatches:Q=cQ.includeMatches,ignoreLocation:i=cQ.ignoreLocation}={}){if(A.length>32)throw new Error(AMo(32));const E=A.length,n=g.length,s=Math.max(0,Math.min(e,n));let r=o,a=s;const c=(p,k)=>{const S=p/E;if(i)return S;const R=Math.abs(s-k);return t?S+R/t:R?1:S},h=C>1||Q,l=h?Array(n):[];let D;for(;(D=g.indexOf(A,a))>-1;){const p=c(0,D);if(r=Math.min(p,r),a=D+E,h){let k=0;for(;k<E;)l[D+k]=1,k+=1}}a=-1;let d=[],y=1,w=0,u=E+n;const G=1<<E-1;for(let p=0;p<E;p+=1){let k=0,S=u;for(;k<S;)c(p,s+S)<=r?k=S:u=S,S=Math.floor((u-k)/2+k);u=S;let R=Math.max(1,s-S+1);const x=B?n:Math.min(s+S,n)+E,N=Array(x+2);N[x+1]=(1<<p)-1;for(let U=x;U>=R;U-=1){const K=U-1,Y=I[g[K]];if(N[U]=(N[U+1]<<1|1)&Y,p&&(N[U]|=(d[U+1]|d[U])<<1|1|d[U+1]),N[U]&G&&(y=c(p,K),y<=r)){if(r=y,a=K,w=p,a<=s)break;R=Math.max(1,2*s-a)}}if(c(p+1,s)>r)break;d=N}if(h&&a>=0){const p=Math.min(n-1,a+E-1+w);for(let k=a;k<=p;k+=1)I[g[k]]&&(l[k]=1)}const m={isMatch:a>=0,score:Math.max(.001,y)};if(h){const p=iMo(l,C);p.length?Q&&(m.indices=p):m.isMatch=!1}return m}function nMo(g){const A={};for(let I=0,e=g.length;I<e;I+=1){const t=g.charAt(I);A[t]=(A[t]||0)|1<<e-I-1}return A}function _Cg(g){if(g.length<=1)return g;g.sort((I,e)=>I[0]-e[0]||I[1]-e[1]);const A=[g[0]];for(let I=1,e=g.length;I<e;I+=1){const t=A[A.length-1],o=g[I];o[0]<=t[1]+1?t[1]=Math.max(t[1],o[1]):A.push(o)}return A}const HPI={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},sMo=new RegExp("["+Object.keys(HPI).join("")+"]","g"),EoA=typeof String.prototype.normalize=="function"?g=>g.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(sMo,A=>HPI[A]):g=>g;var bCg=class{constructor(g,{location:A=cQ.location,threshold:I=cQ.threshold,distance:e=cQ.distance,includeMatches:t=cQ.includeMatches,findAllMatches:o=cQ.findAllMatches,minMatchCharLength:B=cQ.minMatchCharLength,isCaseSensitive:C=cQ.isCaseSensitive,ignoreDiacritics:Q=cQ.ignoreDiacritics,ignoreLocation:i=cQ.ignoreLocation}={}){if(this.options={location:A,threshold:I,distance:e,includeMatches:t,findAllMatches:o,minMatchCharLength:B,isCaseSensitive:C,ignoreDiacritics:Q,ignoreLocation:i},g=C?g:g.toLowerCase(),g=Q?EoA(g):g,this.pattern=g,this.chunks=[],!this.pattern.length)return;const E=(s,r)=>{this.chunks.push({pattern:s,alphabet:nMo(s),startIndex:r})},n=this.pattern.length;if(n>32){let s=0;const r=n%32,a=n-r;for(;s<a;)E(this.pattern.substr(s,32),s),s+=32;if(r){const c=n-32;E(this.pattern.substr(c),c)}}else E(this.pattern,0)}searchIn(g){const{isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e}=this.options;if(g=A?g:g.toLowerCase(),g=I?EoA(g):g,this.pattern===g){if(g.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const a={isMatch:!0,score:0};return e&&(a.indices=[[0,g.length-1]]),a}const{location:t,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,ignoreLocation:i}=this.options,E=[];let n=0,s=!1;this.chunks.forEach(({pattern:a,alphabet:c,startIndex:h})=>{const{isMatch:l,score:D,indices:d}=EMo(g,a,c,{location:t+h,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,includeMatches:e,ignoreLocation:i});l&&(s=!0),n+=D,l&&d&&E.push(...d)});const r={isMatch:s,score:s?n/this.chunks.length:1};return s&&e&&(r.indices=_Cg(E)),r}};const aMo=new Set(["fuzzy","include"]);function rMo(g){return g.startsWith("inverse")}const HCg=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:g=>({type:"exact",search(A){const I=A===g;return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:g=>({type:"include",search(A){let I=0,e;const t=[],o=g.length;for(;(e=A.indexOf(g,I))>-1;)I=e+o,t.push([e,I-1]);const B=!!t.length;return{isMatch:B,score:B?0:1,indices:t}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:g=>({type:"prefix-exact",search(A){const I=A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:g=>({type:"inverse-prefix-exact",search(A){const I=!A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:g=>({type:"inverse-suffix-exact",search(A){const I=!A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:g=>({type:"suffix-exact",search(A){const I=A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[A.length-g.length,A.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:g=>({type:"inverse-exact",search(A){const I=A.indexOf(g)===-1;return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(g,A={})=>{const I=new bCg(g,{location:A.location??cQ.location,threshold:A.threshold??cQ.threshold,distance:A.distance??cQ.distance,includeMatches:A.includeMatches??cQ.includeMatches,findAllMatches:A.findAllMatches??cQ.findAllMatches,minMatchCharLength:A.minMatchCharLength??cQ.minMatchCharLength,isCaseSensitive:A.isCaseSensitive??cQ.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics??cQ.ignoreDiacritics,ignoreLocation:A.ignoreLocation??cQ.ignoreLocation});return{type:"fuzzy",search(e){return I.searchIn(e)}}}}],vPI=HCg.length,cMo="\0",hMo="|";function lMo(g){const A=[],I=g.length;let e=0;for(;e<I;){for(;e<I&&g[e]===" ";)e++;if(e>=I)break;let t=e;for(;t<I&&g[t]!==" "&&g[t]!=='"';)t++;if(t<I&&g[t]==='"'){for(t++;t<I;){if(g[t]==='"'){const o=t+1;if(o>=I||g[o]===" "){t++;break}if(g[o]==="$"&&(o+1>=I||g[o+1]===" ")){t+=2;break}}t++}A.push(g.substring(e,t)),e=t}else{for(;t<I&&g[t]!==" ";)t++;A.push(g.substring(e,t)),e=t}}return A}function TPI(g,A){const I=g.match(A);return I?I[1]:null}function DMo(g,A={}){return g.replace(/\\\|/g,cMo).split(hMo).map(I=>{const e=lMo(I.replace(/\u0000/g,"|").trim()).filter(o=>o&&!!o.trim()),t=[];for(let o=0,B=e.length;o<B;o+=1){const C=e[o];let Q=!1,i=-1;for(;!Q&&++i<vPI;){const E=HCg[i],n=TPI(C,E.multiRegex);n&&(t.push(E.create(n,A)),Q=!0)}if(!Q)for(i=-1;++i<vPI;){const E=HCg[i],n=TPI(C,E.singleRegex);if(n){t.push(E.create(n,A));break}}}return t})}var dMo=class{constructor(g,{isCaseSensitive:A=cQ.isCaseSensitive,ignoreDiacritics:I=cQ.ignoreDiacritics,includeMatches:e=cQ.includeMatches,minMatchCharLength:t=cQ.minMatchCharLength,ignoreLocation:o=cQ.ignoreLocation,findAllMatches:B=cQ.findAllMatches,location:C=cQ.location,threshold:Q=cQ.threshold,distance:i=cQ.distance}={}){this.query=null,this.options={isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e,minMatchCharLength:t,findAllMatches:B,ignoreLocation:o,location:C,threshold:Q,distance:i},g=A?g:g.toLowerCase(),g=I?EoA(g):g,this.pattern=g,this.query=DMo(this.pattern,this.options)}static condition(g,A){return A.useExtendedSearch}searchIn(g){const A=this.query;if(!A)return{isMatch:!1,score:1};const{includeMatches:I,isCaseSensitive:e,ignoreDiacritics:t}=this.options;g=e?g:g.toLowerCase(),g=t?EoA(g):g;let o=0;const B=[];let C=0,Q=!1;for(let i=0,E=A.length;i<E;i+=1){const n=A[i];B.length=0,o=0,Q=!1;for(let s=0,r=n.length;s<r;s+=1){const a=n[s],{isMatch:c,indices:h,score:l}=a.search(g);if(c)o+=1,C+=l,rMo(a.type)&&(Q=!0),I&&(aMo.has(a.type)?B.push(...h):B.push(h));else{C=0,o=0,B.length=0,Q=!1;break}}if(o){const s={isMatch:!0,score:C/o};return Q&&(s.hasInverse=!0),I&&(s.indices=_Cg(B)),s}}return{isMatch:!1,score:1}}};const vCg=[];function TCg(...g){vCg.push(...g)}function npA(g,A){for(let I=0,e=vCg.length;I<e;I+=1){const t=vCg[I];if(t.condition(g,A))return new t(g,A)}return new bCg(g,A)}const spA={AND:"$and",OR:"$or"},qCg={PATH:"$path",PATTERN:"$val"},ZCg=g=>!!(g[spA.AND]||g[spA.OR]),yMo=g=>!!g[qCg.PATH],wMo=g=>!UL(g)&&PPI(g)&&!ZCg(g),qPI=g=>({[spA.AND]:Object.keys(g).map(A=>({[A]:g[A]}))});function ZPI(g,A,{auto:I=!0}={}){const e=t=>{if(wG(t)){const Q={keyId:null,pattern:t};return I&&(Q.searcher=npA(t,A)),Q}const o=Object.keys(t),B=yMo(t);if(!B&&o.length>1&&!ZCg(t))return e(qPI(t));if(wMo(t)){const Q=B?t[qCg.PATH]:o[0],i=B?t[qCg.PATTERN]:t[Q];if(!wG(i))throw new Error($ko(Q));const E={keyId:EpA(Q),pattern:i};return I&&(E.searcher=npA(i,A)),E}const C={children:[],operator:o[0]};return o.forEach(Q=>{const i=t[Q];UL(i)&&i.forEach(E=>{C.children.push(e(E))})}),C};return ZCg(g)||(g=qPI(g)),e(g)}function OCg(g,{ignoreFieldNorm:A=cQ.ignoreFieldNorm}){let I=1;return g.forEach(({key:e,norm:t,score:o})=>{const B=e?e.weight:null;I*=Math.pow(o===0&&B?Number.EPSILON:o,(B||1)*(A?1:t))}),I}function uMo(g,{ignoreFieldNorm:A=cQ.ignoreFieldNorm}){g.forEach(I=>{I.score=OCg(I.matches,{ignoreFieldNorm:A})})}var GMo=class{constructor(g,A){this.limit=g,this.heap=[],this.comparator=A}get size(){return this.heap.length}insert(g){this.size<this.limit?(this.heap.push(g),this._bubbleUp(this.size-1)):this.comparator(g,this.heap[0])<0&&(this.heap[0]=g,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(g){const A=this.heap;for(;g>0;){const I=g-1>>1;if(this.comparator(A[g],A[I])<=0)break;const e=A[g];A[g]=A[I],A[I]=e,g=I}}_sinkDown(g){const A=this.heap,I=A.length;let e=g;do{g=e;const t=2*g+1,o=2*g+2;if(t<I&&this.comparator(A[t],A[e])>0&&(e=t),o<I&&this.comparator(A[o],A[e])>0&&(e=o),e!==g){const B=A[g];A[g]=A[e],A[e]=B}}while(e!==g)}};function mMo(g){const A=[];return g.matches.forEach(I=>{if(!FS(I.indices)||!I.indices.length)return;const e={indices:I.indices,value:I.value};I.key&&(e.key=I.key.id),I.idx>-1&&(e.refIndex=I.idx),A.push(e)}),A}function pMo(g,A,{includeMatches:I=cQ.includeMatches,includeScore:e=cQ.includeScore}={}){return g.map(t=>{const{idx:o}=t,B={item:A[o],refIndex:o};return I&&(B.matches=mMo(t)),e&&(B.score=t.score),B})}const kMo=/[\p{L}\p{M}\p{N}_]+/gu,OPI=new WeakSet;function MMo(g){OPI.has(g)||(OPI.add(g),console.warn(`[Fuse] tokenize regex ${g} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function SMo(g){if(typeof g=="function"){let A=!1;return I=>{const e=g(I);if(!A&&(A=!0,!Array.isArray(e)||e.some(t=>typeof t!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(e)?"array containing non-strings":typeof e}.`);return e}}return g instanceof RegExp?(g.global||MMo(g),A=>A.match(g)||[]):A=>A.match(kMo)||[]}function WCg({isCaseSensitive:g=!1,ignoreDiacritics:A=!1,tokenize:I}={}){const e=SMo(I);return{tokenize(t){return g||(t=t.toLowerCase()),A&&(t=EoA(t)),e(t)}}}var fMo=class{static condition(g,A){return A.useTokenSearch}constructor(g,A){this.options=A,this.analyzer=WCg({isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,tokenize:A.tokenize});const I=this.analyzer.tokenize(g),{df:e,fieldCount:t}=A._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const o of I){this.termSearchers.push(new bCg(o,{location:A.location,threshold:A.threshold,distance:A.distance,includeMatches:A.includeMatches,findAllMatches:A.findAllMatches,minMatchCharLength:A.minMatchCharLength,isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,ignoreLocation:!0}));const B=e.get(o)||0,C=Math.log(1+(t-B+.5)/(B+.5));this.idfWeights.push(C)}this.combineAll=A.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(g){if(!this.termSearchers.length)return{isMatch:!1,score:1};const A=[];let I=0,e=0,t=0,o=0;const B=this.combineAll&&!this.useMask?new Set:null;for(let i=0;i<this.termSearchers.length;i++){const E=this.termSearchers[i].searchIn(g),n=this.idfWeights[i];e+=n,E.isMatch&&(t++,I+=n*(1-E.score),E.indices&&A.push(...E.indices),this.combineAll&&(this.useMask?o|=1<<i:B.add(i)))}if(t===0)return{isMatch:!1,score:1};const C=e>0?1-I/e:0,Q={isMatch:!0,score:Math.max(.001,C)};return this.options.includeMatches&&A.length&&(Q.indices=_Cg(A)),this.combineAll&&(this.useMask?Q.matchedMask=o:Q.matchedTerms=B,Q.termCount=this.numTerms),Q}};function VCg(g,A,I,e){const t=e.tokenize(A);if(!t.length)return;g.fieldCount++,g.docFieldCount.set(I,(g.docFieldCount.get(I)||0)+1);const o=new Set(t);let B=g.docTermFieldHits.get(I);B||(B=new Map,g.docTermFieldHits.set(I,B));for(const C of o)B.set(C,(B.get(C)||0)+1),g.df.set(C,(g.df.get(C)||0)+1)}function WPI(g,A,I,e){const{i:t,v:o,$:B}=A;if(o!==void 0){VCg(g,o,t,e);return}if(B)for(let C=0;C<I;C++){const Q=B[C];if(Q)if(Array.isArray(Q))for(const i of Q)VCg(g,i.v,t,e);else VCg(g,Q.v,t,e)}}function RMo(g,A,I){const e={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const t of g)WPI(e,t,A,I);return e}function NMo(g,A,I,e){WPI(g,A,I,e)}function xMo(g,A){const I=g.docFieldCount.get(A);if(I===void 0)return;g.fieldCount-=I,g.docFieldCount.delete(A);const e=g.docTermFieldHits.get(A);if(e){for(const[t,o]of e){const B=(g.df.get(t)||0)-o;B<=0?g.df.delete(t):g.df.set(t,B)}g.docTermFieldHits.delete(A)}}function VPI(g,A){if(A.length===0)return;const I=Array.from(new Set(A)).sort((C,Q)=>C-Q);for(const C of I)xMo(g,C);const e=C=>{let Q=0,i=I.length;for(;Q<i;){const E=Q+i>>>1;I[E]<C?Q=E+1:i=E}return C-Q},t=I[0],o=new Map;for(const[C,Q]of g.docFieldCount)o.set(C>t?e(C):C,Q);g.docFieldCount=o;const B=new Map;for(const[C,Q]of g.docTermFieldHits)B.set(C>t?e(C):C,Q);g.docTermFieldHits=B}var JL=class{constructor(g,A,I){this.options={...cQ,...A},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new tMo(this.options.keys),this._docs=g,this._myIndex=null,this._invertedIndex=null,this.setCollection(g,I),this._lastQuery=null,this._lastSearcher=null}_getSearcher(g){if(this._lastQuery===g)return this._lastSearcher;const A=npA(g,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=g,this._lastSearcher=A,A}setCollection(g,A){if(this._docs=g,A&&!(A instanceof YCg))throw new Error(Xko);if(this._myIndex=A||bPI(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const I=WCg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=RMo(this._myIndex.records,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}add(g){if(!FS(g))return;this._docs.push(g);const A=this._myIndex.add(g,this._docs.length-1);if(this._invertedIndex&&A){const I=WCg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});NMo(this._invertedIndex,A,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}remove(g=()=>!1){const A=[],I=[];for(let e=0,t=this._docs.length;e<t;e+=1)g(this._docs[e],e)&&(A.push(this._docs[e]),I.push(e));if(I.length){this._invertedIndex&&VPI(this._invertedIndex,I);const e=new Set(I);this._docs=this._docs.filter((t,o)=>!e.has(o)),this._myIndex.removeAll(I),this._invalidateSearcherCache()}return A}removeAt(g){if(!Number.isInteger(g)||g<0||g>=this._docs.length)throw new Error(LCg);this._invertedIndex&&VPI(this._invertedIndex,[g]);const A=this._docs.splice(g,1)[0];return this._myIndex.removeAt(g),this._invalidateSearcherCache(),A}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(g=>this._keyStore.get(g.id)||g)}search(g,A){const{limit:I=-1}=A||{},{includeMatches:e,includeScore:t,shouldSort:o,sortFn:B,ignoreFieldNorm:C}=this.options;if(wG(g)&&!g.trim()){let s=this._docs.map((r,a)=>({item:r,refIndex:a}));return QpA(I)&&I>-1&&(s=s.slice(0,I)),s}const Q=o&&QpA(I)&&I>0&&wG(g),i=B,E=(s,r)=>i(s,r)||s.idx-r.idx;let n;if(Q){const s=new GMo(I,E);wG(this._docs[0])?this._searchStringList(g,{heap:s,ignoreFieldNorm:C}):this._searchObjectList(g,{heap:s,ignoreFieldNorm:C}),n=s.extractSorted()}else n=wG(g)?wG(this._docs[0])?this._searchStringList(g):this._searchObjectList(g):this._searchLogical(g),uMo(n,{ignoreFieldNorm:C}),o&&n.sort(wG(g)?E:i),QpA(I)&&I>-1&&(n=n.slice(0,I));return pMo(n,this._docs,{includeMatches:e,includeScore:t})}_searchStringList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=A?null:[];return o.forEach(({v:C,i:Q,n:i})=>{if(!FS(C))return;const E=e.searchIn(C);if(E.isMatch){const n={score:E.score,value:C,norm:i,indices:E.indices};t&&(n.matchedMask=E.matchedMask,n.matchedTerms=E.matchedTerms,n.termCount=E.termCount);const s=[n];if(!t||this._coversAllTokens(s)){const r={item:C,idx:Q,matches:s};A?(r.score=OCg(r.matches,{ignoreFieldNorm:I}),A.insert(r)):B.push(r)}}}),B}_searchLogical(g){const A=ZPI(g,this.options),I=this._normalizedKeys(),e=(C,Q,i)=>{if(!("children"in C)){const{keyId:r,searcher:a}=C;let c;return r===null?(c=[],I.forEach((h,l)=>{c.push(...this._findMatches({key:h,value:Q[l],searcher:a}))})):c=this._findMatches({key:this._keyStore.get(r),value:this._myIndex.getValueForItemAtKeyId(Q,r),searcher:a}),c&&c.length?[{idx:i,item:Q,matches:c}]:[]}const{children:E,operator:n}=C,s=[];for(let r=0,a=E.length;r<a;r+=1){const c=E[r],h=e(c,Q,i);if(h.length)s.push(...h);else if(n===spA.AND)return[]}return s},t=this._myIndex.records,o=new Map,B=[];return t.forEach(({$:C,i:Q})=>{if(FS(C)){const i=e(A,C,Q);i.length&&(o.has(Q)||(o.set(Q,{idx:Q,item:C,matches:[]}),B.push(o.get(Q))),i.forEach(({matches:E})=>{o.get(Q).matches.push(...E)}))}}),B}_searchObjectList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=this._normalizedKeys(),C=A?null:[];return o.forEach(({$:Q,i})=>{if(!FS(Q))return;const E=[];let n=!1,s=!1;if(B.forEach((r,a)=>{const c=this._findMatches({key:r,value:Q[a],searcher:e});c.length?(E.push(...c),c[0].hasInverse&&(s=!0)):n=!0}),!(s&&n)&&E.length&&(!t||this._coversAllTokens(E))){const r={idx:i,item:Q,matches:E};A?(r.score=OCg(r.matches,{ignoreFieldNorm:I}),A.insert(r)):C.push(r)}}),C}_findMatches({key:g,value:A,searcher:I}){if(!FS(A))return[];const e=[];if(UL(A))A.forEach(({v:t,i:o,n:B})=>{if(!FS(t))return;const C=I.searchIn(t);if(C.isMatch){const Q={score:C.score,key:g,value:t,idx:o,norm:B,indices:C.indices,hasInverse:C.hasInverse};C.termCount!==void 0&&(Q.matchedMask=C.matchedMask,Q.matchedTerms=C.matchedTerms,Q.termCount=C.termCount),e.push(Q)}});else{const{v:t,n:o}=A,B=I.searchIn(t);if(B.isMatch){const C={score:B.score,key:g,value:t,norm:o,indices:B.indices,hasInverse:B.hasInverse};B.termCount!==void 0&&(C.matchedMask=B.matchedMask,C.matchedTerms=B.matchedTerms,C.termCount=B.termCount),e.push(C)}}return e}_coversAllTokens(g){const A=g.length?g[0].termCount:void 0;if(A===void 0)return!0;if(A<=31){let e=0;for(let t=0;t<g.length;t++)e|=g[t].matchedMask||0;return e===2**A-1}const I=new Set;for(let e=0;e<g.length;e++){const t=g[e].matchedTerms;if(t)for(const o of t)I.add(o)}return I.size===A}};JL.version="7.5.0",JL.createIndex=bPI,JL.parseIndex=QMo,JL.config=cQ,JL.match=function(g,A,I){if(I&&I.useTokenSearch)throw new Error(eMo);return npA(g,{...cQ,...I}).searchIn(A)},JL.parseQuery=ZPI,TCg(dMo),TCg(fMo),JL.use=function(...g){g.forEach(A=>TCg(A))};var FMo=JL;const UMo="https://kicad-mod-cache.tscircuit.com";let jCg=null,noA=null,zCg=null;const JMo=async()=>jCg||noA||(noA=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(g=>g.json()).then(g=>(jCg=g,noA=null,g)),noA),PMo=async(g,A=20)=>{const I=await JMo();return zCg||(zCg=new FMo(I)),zCg.search(g).slice(0,A).map(e=>e.item)},KMo=g=>{const A=g.replace(".pretty/","/").replace(".kicad_mod",""),I=`kicad:${A}`;return{path:g,qualifiedName:I,description:A}},LMo=g=>g.replace(/^\/+/,"").split("/").map(A=>encodeURIComponent(A)).join("/"),YMo=async g=>{const A=await fetch(`${UMo}/${LMo(g)}`);if(!A.ok)throw new Error(`KiCad footprint fetch failed: ${A.status}`);const I=await A.text(),{KicadFootprintToCircuitJsonConverter:e}=await xS("kicad-to-circuit-json"),t=new e;return t.addFile(g.split("/").pop()??"selected-footprint.kicad_mod",I),t.runUntilFinished(),t.getOutput()},jPI=g=>g?.source==="jlcpcb"||g?.source==="kicad",_Mo=async(g,A)=>{if(g.source==="jlcpcb")return Wko(g.component.partNumber,A?.jlcpcb);if(g.source==="kicad")return YMo(g.footprint.path);throw new Error("Footprint preview is not available for this source")},bMo=({query:g,placeholder:A,isSearching:I,onQueryChange:e,onSubmit:t})=>{const o=z.useCallback(B=>{B.key==="Enter"&&(B.preventDefault(),t())},[t]);return T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[T.jsxs("div",{className:"rf-relative rf-flex-grow",children:[T.jsx(Tog,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),T.jsx(hCg,{placeholder:A,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:g,onChange:B=>e(B.target.value),onKeyDown:o})]}),T.jsx(si,{onClick:t,disabled:I||g.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:I?T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):T.jsxs(T.Fragment,{children:[T.jsx(Tog,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),T.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},HMo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),vMo=g=>HMo.format(g),zPI=g=>{switch(g.source){case"tscircuit.com":{const A=g.package;return`tscircuit-${A.package_id??`${A.org_owner_tscircuit_handle??"unknown"}-${A.unscoped_name??A.name??"package"}`}`}case"jlcpcb":return`jlc-${g.component.lcscId}`;case"kicad":return`kicad-${g.footprint.path}`;default:return"unknown"}},TMo=g=>{switch(g.source){case"tscircuit.com":return g.package.unscoped_name;case"jlcpcb":return g.component.isDirectLookup?g.component.partNumber:g.component.manufacturer;case"kicad":return g.footprint.qualifiedName}},qMo=g=>{switch(g.source){case"tscircuit.com":return g.package.description||(g.package.org_owner_tscircuit_handle?`Component by ${g.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return g.component.description;case"kicad":return g.footprint.description}},ZMo=g=>{switch(g.source){case"tscircuit.com":return g.package.name;case"jlcpcb":return g.component.isDirectLookup?void 0:g.component.partNumber;case"kicad":return}},OMo=({results:g,selected:A,onSelect:I,onShowDetails:e})=>{const t=A?zPI(A):null;return T.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:g.map(o=>{const B=zPI(o),C=t===B,Q=TMo(o),i=qMo(o),E=ZMo(o),n=o.source==="jlcpcb"?o.component.stock:null,s=o.source==="jlcpcb"?o.component.price:null,r=o.source==="jlcpcb"?o.component.isBasic:null,a=o.source==="jlcpcb"?o.component.isDirectLookup:!1;return T.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${C?"rf-bg-zinc-100":""}`,onClick:()=>I(o),children:[T.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[T.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[T.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[Q,o.source==="jlcpcb"&&r!=null&&T.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${r?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:r?"Basic":"Extended"}),a&&T.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),o.source==="tscircuit.com"&&o.package.is_private&&T.jsx(nco,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&n!=null?T.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[n.toLocaleString()," in stock"]}):null]}),T.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[E?T.jsx("span",{className:"rf-mr-2",children:E}):null,i]})]}),T.jsxs("div",{children:[o.source==="tscircuit.com"&&e?T.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:T.jsx(si,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:c=>{c.stopPropagation(),e(o)},children:"See Details"})}):o.source==="jlcpcb"&&n!=null?T.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[n.toLocaleString()," in stock"]}):null,s!=null&&T.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:vMo(s)})]})]},B)})})},WMo=({circuitJson:g,error:A,isLoading:I,height:e})=>T.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:e},children:I?T.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:[T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):A?T.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:e},children:T.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[T.jsx(Hog,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),T.jsx("span",{children:A})]})}):g?T.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:T.jsx(Yog,{circuitJson:g,height:e,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):T.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:"No preview"})}),XPI={importComponentDialog:101,importComponentDetailsDialog:102},VMo=({packageResult:g,isOpen:A,onOpenChange:I,isLoading:e,details:t,previewTab:o,onPreviewTabChange:B,isSubmitting:C,onImport:Q})=>{const i=g?.package??null,E=i?.latest_pcb_preview_image_url,n=i?.latest_sch_preview_image_url,s=i?.latest_cad_preview_image_url,r=i?.unscoped_name?.split("/").pop()??i?.unscoped_name,a=i?.org_owner_tscircuit_handle??void 0,c=a?`https://tscircuit.com/${a}`:void 0,h=a&&r?`https://tscircuit.com/${a}/${r}`:void 0;return T.jsx(Yb,{open:A,onOpenChange:I,children:T.jsxs(NL,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:XPI.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[T.jsx(xL,{className:"rf-pb-4 rf-border-b",children:T.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:T.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[T.jsx(FL,{className:"rf-text-xl rf-font-semibold rf-truncate",children:r}),T.jsx(_b,{children:i?.description})]})})}),T.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[a?T.jsxs("div",{children:[T.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),T.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:c?T.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:a}):a})]}):null,(s||E||n)&&T.jsx(T.Fragment,{children:T.jsxs("div",{children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),T.jsxs(OvA,{value:o,onValueChange:l=>B(l),children:[T.jsxs(PDA,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[E&&T.jsx(mx,{value:"pcb",children:"PCB"}),n&&T.jsx(mx,{value:"schematic",children:"Schematic"}),s&&T.jsx(mx,{value:"3d",children:"3D"})]}),T.jsxs("div",{className:"rf-mt-4",children:[T.jsx(xy,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:E?T.jsx("img",{src:E,alt:`${r??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),T.jsx(xy,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:n?T.jsx("img",{src:n,alt:`${r??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),T.jsx(xy,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:s?T.jsx("img",{src:s,alt:`${r??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),t?.ai_description?T.jsxs("section",{children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),T.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:T.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:t.ai_description})})]}):null,t?.ai_usage_instructions?T.jsxs("section",{children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),T.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:T.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:t.ai_usage_instructions})})]}):null,e?T.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),T.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),T.jsxs(YO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[T.jsx("div",{className:"rf-flex-1",children:h?T.jsxs(si,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(h,"_blank"),children:[T.jsx(tco,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),T.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[T.jsx(si,{variant:"outline",onClick:()=>I(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),T.jsx(si,{onClick:Q,disabled:C,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:C?T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},jMo=()=>{const[g,A]=z.useState(null),[I,e]=z.useState(!1),t=z.useCallback(async(B,C)=>{e(!0);try{const Q=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${B}/${C}`)}`);if(!Q.ok)throw new Error(`Failed to load package details: ${Q.status}`);const i=await Q.json();A(i.package??null)}catch(Q){console.error("Failed to fetch package details",Q),A(null)}finally{e(!1)}},[]),o=z.useCallback(()=>{A(null),e(!1)},[]);return{details:g,isLoading:I,fetchDetails:t,reset:o}},zMo=(g,A)=>{const[I,e]=z.useState({circuitJson:null,error:null,isLoading:!1});return z.useEffect(()=>{if(!g||!jPI(g)){e({circuitJson:null,error:null,isLoading:!1});return}let t=!1;return e({circuitJson:null,error:null,isLoading:!0}),_Mo(g,A).then(o=>{t||e({circuitJson:o,error:null,isLoading:!1})}).catch(o=>{t||e({circuitJson:null,error:o instanceof Error?o.message:"Failed to load footprint preview",isLoading:!1})}),()=>{t=!0}},[g,A]),I},XMo=async(g,A)=>{const I={"Content-Type":"application/json"};A&&(I.Authorization=`Bearer ${A}`);const e=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:I,body:JSON.stringify({query:g})});if(!e.ok)throw new Error(`tscircuit registry error: ${e.status}`);return(await e.json()).packages??[]},$Mo=({sessionToken:g})=>{const[A,I]=z.useState([]),[e,t]=z.useState(!1),[o,B]=z.useState(null),[C,Q]=z.useState(!1),i=z.useCallback(async n=>{const s=n.trim();if(!s)return[];t(!0),B(null);try{const a=(await XMo(s,g)).map(c=>({source:"tscircuit.com",package:c}));return I(a),a}catch(r){return console.error("Error searching tscircuit packages",r),I([]),B(r instanceof Error?r.message:"Failed to search tscircuit packages"),[]}finally{t(!1),Q(!0)}},[g]),E=z.useCallback(()=>{I([]),t(!1),B(null),Q(!1)},[]);return{results:A,isSearching:e,error:o,hasSearched:C,search:i,reset:E}},ASo=g=>{const A=/^C(\d+)$/i.exec(g.trim());if(!A)return null;const I=Number(A[1]);if(!Number.isSafeInteger(I))return null;const e=`C${A[1]}`;return{source:"jlcpcb",component:{lcscId:I,manufacturer:e,partNumber:e,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},$PI=(g,A)=>{const I=ASo(g);return I?A.some(t=>t.component.partNumber.toUpperCase()===I.component.partNumber)?A:[I,...A]:A},gSo=g=>{const A=g.trim();return/^C\d+/i.test(A)?A.replace(/^C/i,""):A},ISo=()=>{const[g,A]=z.useState([]),[I,e]=z.useState(!1),[t,o]=z.useState(null),[B,C]=z.useState(!1),Q=z.useCallback(async E=>{const n=gSo(E);if(!n)return[];e(!0),o(null);try{const s=await qko(n,10),r=$PI(E,s.map(a=>({source:"jlcpcb",component:Zko(a)})));return A(r),r}catch(s){console.error("Error searching JLCPCB components",s);const r=$PI(E,[]);return A(r),o(r.length>0?null:s instanceof Error?s.message:"Failed to search JLCPCB components"),r}finally{e(!1),C(!0)}},[]),i=z.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},eSo=()=>{const[g,A]=z.useState([]),[I,e]=z.useState(!1),[t,o]=z.useState(null),[B,C]=z.useState(!1),Q=z.useCallback(async E=>{const n=E.trim();if(!n)return[];e(!0),o(null);try{const r=(await PMo(n,20)).map(a=>({source:"kicad",footprint:KMo(a)}));return A(r),r}catch(s){return console.error("Error searching KiCad footprints",s),A([]),o(s instanceof Error?s.message:"Failed to search KiCad footprints"),[]}finally{e(!1),C(!0)}},[]),i=z.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},tSo=({onTscircuitPackageSelected:g,onJlcpcbComponentTsxLoaded:A,onKicadStringSelected:I})=>{const e=[];return g&&e.push("tscircuit.com"),A&&e.push("jlcpcb"),I&&e.push("kicad"),e},oSo=({isOpen:g,onClose:A,jlcpcbProxyRequestHeaders:I,onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:B,tscircuitSessionToken:C})=>{BoA();const Q=z.useMemo(()=>tSo({onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o}),[e,t,o]),i=Q.length>0,E=Q.length===1,[n,s]=z.useState(Q[0]??"tscircuit.com"),[r,a]=z.useState(""),[c,h]=z.useState(null),{results:l,isSearching:D,error:d,hasSearched:y,search:w,reset:u}=$Mo({sessionToken:C}),{results:G,isSearching:m,error:p,hasSearched:k,search:S,reset:R}=ISo(),{results:x,isSearching:N,error:U,hasSearched:K,search:Y,reset:_}=eSo(),{details:q,isLoading:j,fetchDetails:W,reset:Z}=jMo(),[$,eA]=z.useState(null),[IA,QA]=z.useState(!1),[sA,lA]=z.useState("pcb"),[BA,hA]=z.useState(null),[nA,aA]=z.useState(!1),SA=z.useMemo(()=>({jlcpcb:{headers:I,apiBase:B}}),[B,I]),{circuitJson:FA,error:rA,isLoading:xA}=zMo(c,SA),NA=jPI(c);z.useEffect(()=>{hA(null)},[c]);const RA=z.useCallback(()=>{u(),R(),_(),h(null)},[R,_,u]);z.useEffect(()=>{g||(RA(),a(""),QA(!1),eA(null),hA(null))},[g,RA]),z.useEffect(()=>{a(""),h(null),n==="tscircuit.com"?u():n==="jlcpcb"?R():n==="kicad"&&_()},[n,R,_,u]);const HA=kA=>{h(kA),eA(kA),lA("pcb"),QA(!0),Z();const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(OA&&$A){const og=$A.split("/").pop()??$A;W(OA,og)}},KA=async()=>{r.trim()&&(h(null),n==="tscircuit.com"?await w(r):n==="jlcpcb"?await S(r):n==="kicad"&&await Y(r))},mA=async kA=>{try{if(hA(null),aA(!0),kA.source==="kicad"){if(!e)throw new Error("KiCad handler not provided");await e({result:kA,footprint:kA.footprint.qualifiedName})}else if(kA.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const OA=await Oko(kA.component.partNumber,{headers:I,apiBase:B});await o({result:kA,tsx:OA})}else if(kA.source==="tscircuit.com"){if(!t)throw new Error("tscircuit package handler not provided");const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(!OA||!$A)throw new Error("Missing package metadata");const og=$A.split("/").pop()??$A,dg=`@tsci/${OA}.${og}`;await t({result:kA,fullPackageName:dg})}return!0}catch(OA){return console.error("Failed to import component",OA),hA(OA instanceof Error?OA.message:"Failed to import component"),!1}finally{aA(!1)}};let JA=[],dA=!1,bA=null,WA=!1;n==="tscircuit.com"?(JA=l,dA=D,bA=d,WA=y):n==="jlcpcb"?(JA=G,dA=m,bA=p,WA=k):n==="kicad"&&(JA=x,dA=N,bA=U,WA=K);const Qg=async()=>{if(!c)return;await mA(c)&&(A(),RA(),a(""))},YA=kA=>{kA||A()},uA=kA=>{QA(kA),kA||eA(null)};return T.jsxs(Yb,{open:g,onOpenChange:YA,children:[T.jsxs(NL,{style:{width:"calc(100vw - 2rem)",maxWidth:NA?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:XPI.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[T.jsxs(xL,{children:[T.jsxs(FL,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",E?CpA[n].label:""," ","Component"]}),T.jsx(_b,{className:"rf-text-sm",children:i?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),i?T.jsxs(OvA,{value:n,onValueChange:kA=>s(kA),className:"rf-min-w-0 rf-w-full",children:[!E&&T.jsx(PDA,{className:"rf-flex rf-w-full rf-gap-2",children:Q.map(kA=>T.jsx(mx,{value:kA,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:CpA[kA].label},kA))}),T.jsxs("div",{className:"rf-min-w-0",style:NA?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[T.jsxs("div",{className:"rf-min-w-0",children:[T.jsx(bMo,{query:r,placeholder:CpA[n].placeholder,isSearching:dA,onQueryChange:a,onSubmit:KA}),T.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:dA?T.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[T.jsx(kS,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),T.jsx("p",{children:"Searching..."})]}):JA.length>0?T.jsx(OMo,{results:JA,selected:c,onSelect:h,onShowDetails:n==="tscircuit.com"?HA:void 0}):T.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:bA?`Error: ${bA}`:WA?CpA[n].emptyMessage:"Enter a search term to find components"})})]}),NA?T.jsx("div",{className:"rf-mt-4",children:T.jsx(WMo,{circuitJson:FA,error:rA,isLoading:xA,height:325})}):null]})]}):null,BA?T.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:BA}):null,T.jsxs(YO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[T.jsx(si,{variant:"outline",onClick:A,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),T.jsx(si,{onClick:Qg,disabled:!c||nA,className:"rf-order-1 sm:rf-order-2",children:nA?T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),T.jsx(VMo,{packageResult:$,isOpen:IA,onOpenChange:uA,isLoading:j,details:q,previewTab:sA,onPreviewTabChange:kA=>lA(kA),isSubmitting:nA,onImport:()=>{$&&mA($).then(kA=>{kA&&(QA(!1),A(),RA(),a(""))})}})]})},BSo=g=>{const A=g.match(/export const (\w+) =/);if(!A)throw new Error("Could not determine component name from TSX contents");return A[1]},A4I=g=>{const A=Jc(B=>B.pushEvent),I=Jc(B=>B.upsertFile),e=async({result:B,fullPackageName:C})=>{const i=B.package.unscoped_name??B.package.name;await KC.promise(A({event_type:"INSTALL_PACKAGE",full_package_name:C}),{loading:`Requesting install for "${i}"`,success:`Install requested for "${i}"`,error:E=>`Failed to request install: ${E instanceof Error?E.message:String(E)}`})},t=async({footprint:B})=>{await KC.promise(navigator.clipboard.writeText(B),{loading:`Copying "${B}"`,success:`Copied "${B}" to clipboard`,error:C=>`Failed to copy footprint: ${C instanceof Error?C.message:String(C)}`})},o=async({result:B,tsx:C})=>{const i=`imports/${BSo(C)}.tsx`;await KC.promise(I(i,C),{loading:`Importing ${B.component.partNumber}`,success:`Imported to "${i}"`,error:E=>`Failed to import component: ${E instanceof Error?E.message:String(E)}`})};return T.jsx(oSo,{...g,onTscircuitPackageSelected:e,onKicadStringSelected:t,onJlcpcbComponentTsxLoaded:o})};A4I.displayName="ImportComponentDialogForCli";const CSo=async({circuitJson:g,projectName:A})=>{const{convertCircuitJsonToAltiumZip:I}=await Promise.resolve().then(()=>MTo),e=await I(g,A);return new Blob([new Uint8Array(e)],{type:"application/zip"})},QSo=async({circuitJson:g,projectName:A})=>{await KC.promise((async()=>{const I=await CSo({circuitJson:g,projectName:A});_k(I,{fileName:`${A}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:I=>`Failed to generate Altium project: ${I instanceof Error?I.message:String(I)}`})};var XCg={exports:{}},g4I;function iSo(){return g4I||(g4I=1,(function(g,A){var I={env:{},version:""};(function(e){g.exports=e()})(function(){return(function e(t,o,B){function C(E,n){if(!o[E]){if(!t[E]){var s=typeof rU=="function"&&rU;if(!n&&s)return s(E,!0);if(Q)return Q(E,!0);var r=new Error("Cannot find module '"+E+"'");throw r.code="MODULE_NOT_FOUND",r}var a=o[E]={exports:{}};t[E][0].call(a.exports,function(c){var h=t[E][1][c];return C(h||c)},a,a.exports,e,t,o,B)}return o[E].exports}for(var Q=typeof rU=="function"&&rU,i=0;i<B.length;i++)C(B[i]);return C})({1:[function(e,t,o){var B=e("./utils"),C=e("./support"),Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(i){for(var E,n,s,r,a,c,h,l=[],D=0,d=i.length,y=d,w=B.getTypeOf(i)!=="string";D<i.length;)y=d-D,s=w?(E=i[D++],n=D<d?i[D++]:0,D<d?i[D++]:0):(E=i.charCodeAt(D++),n=D<d?i.charCodeAt(D++):0,D<d?i.charCodeAt(D++):0),r=E>>2,a=(3&E)<<4|n>>4,c=1<y?(15&n)<<2|s>>6:64,h=2<y?63&s:64,l.push(Q.charAt(r)+Q.charAt(a)+Q.charAt(c)+Q.charAt(h));return l.join("")},o.decode=function(i){var E,n,s,r,a,c,h=0,l=0,D="data:";if(i.substr(0,D.length)===D)throw new Error("Invalid base64 input, it looks like a data url.");var d,y=3*(i=i.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(i.charAt(i.length-1)===Q.charAt(64)&&y--,i.charAt(i.length-2)===Q.charAt(64)&&y--,y%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=C.uint8array?new Uint8Array(0|y):new Array(0|y);h<i.length;)E=Q.indexOf(i.charAt(h++))<<2|(r=Q.indexOf(i.charAt(h++)))>>4,n=(15&r)<<4|(a=Q.indexOf(i.charAt(h++)))>>2,s=(3&a)<<6|(c=Q.indexOf(i.charAt(h++))),d[l++]=E,a!==64&&(d[l++]=n),c!==64&&(d[l++]=s);return d}},{"./support":30,"./utils":32}],2:[function(e,t,o){var B=e("./external"),C=e("./stream/DataWorker"),Q=e("./stream/Crc32Probe"),i=e("./stream/DataLengthProbe");function E(n,s,r,a,c){this.compressedSize=n,this.uncompressedSize=s,this.crc32=r,this.compression=a,this.compressedContent=c}E.prototype={getContentWorker:function(){var n=new C(B.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new i("data_length")),s=this;return n.on("end",function(){if(this.streamInfo.data_length!==s.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),n},getCompressedWorker:function(){return new C(B.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},E.createWorkerFrom=function(n,s,r){return n.pipe(new Q).pipe(new i("uncompressedSize")).pipe(s.compressWorker(r)).pipe(new i("compressedSize")).withStreamInfo("compression",s)},t.exports=E},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,o){var B=e("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new B("STORE compression")},uncompressWorker:function(){return new B("STORE decompression")}},o.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,o){var B=e("./utils"),C=(function(){for(var Q,i=[],E=0;E<256;E++){Q=E;for(var n=0;n<8;n++)Q=1&Q?3988292384^Q>>>1:Q>>>1;i[E]=Q}return i})();t.exports=function(Q,i){return Q!==void 0&&Q.length?B.getTypeOf(Q)!=="string"?(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n[h])];return-1^E})(0|i,Q,Q.length,0):(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n.charCodeAt(h))];return-1^E})(0|i,Q,Q.length,0):0}},{"./utils":32}],5:[function(e,t,o){o.base64=!1,o.binary=!1,o.dir=!1,o.createFolders=!0,o.date=null,o.compression=null,o.compressionOptions=null,o.comment=null,o.unixPermissions=null,o.dosPermissions=null},{}],6:[function(e,t,o){var B=null;B=typeof Promise<"u"?Promise:e("lie"),t.exports={Promise:B}},{lie:37}],7:[function(e,t,o){var B=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",C=e("pako"),Q=e("./utils"),i=e("./stream/GenericWorker"),E=B?"uint8array":"array";function n(s,r){i.call(this,"FlateWorker/"+s),this._pako=null,this._pakoAction=s,this._pakoOptions=r,this.meta={}}o.magic="\b\0",Q.inherits(n,i),n.prototype.processChunk=function(s){this.meta=s.meta,this._pako===null&&this._createPako(),this._pako.push(Q.transformTo(E,s.data),!1)},n.prototype.flush=function(){i.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},n.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this._pako=null},n.prototype._createPako=function(){this._pako=new C[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var s=this;this._pako.onData=function(r){s.push({data:r,meta:s.meta})}},o.compressWorker=function(s){return new n("Deflate",s)},o.uncompressWorker=function(){return new n("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,o){function B(a,c){var h,l="";for(h=0;h<c;h++)l+=String.fromCharCode(255&a),a>>>=8;return l}function C(a,c,h,l,D,d){var y,w,u=a.file,G=a.compression,m=d!==E.utf8encode,p=Q.transformTo("string",d(u.name)),k=Q.transformTo("string",E.utf8encode(u.name)),S=u.comment,R=Q.transformTo("string",d(S)),x=Q.transformTo("string",E.utf8encode(S)),N=k.length!==u.name.length,U=x.length!==S.length,K="",Y="",_="",q=u.dir,j=u.date,W={crc32:0,compressedSize:0,uncompressedSize:0};c&&!h||(W.crc32=a.crc32,W.compressedSize=a.compressedSize,W.uncompressedSize=a.uncompressedSize);var Z=0;c&&(Z|=8),m||!N&&!U||(Z|=2048);var $=0,eA=0;q&&($|=16),D==="UNIX"?(eA=798,$|=(function(QA,sA){var lA=QA;return QA||(lA=sA?16893:33204),(65535&lA)<<16})(u.unixPermissions,q)):(eA=20,$|=(function(QA){return 63&(QA||0)})(u.dosPermissions)),y=j.getUTCHours(),y<<=6,y|=j.getUTCMinutes(),y<<=5,y|=j.getUTCSeconds()/2,w=j.getUTCFullYear()-1980,w<<=4,w|=j.getUTCMonth()+1,w<<=5,w|=j.getUTCDate(),N&&(Y=B(1,1)+B(n(p),4)+k,K+="up"+B(Y.length,2)+Y),U&&(_=B(1,1)+B(n(R),4)+x,K+="uc"+B(_.length,2)+_);var IA="";return IA+=`
5670
+ `,n=new Blob([E],{type:"text/plain"}),s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=`${i}.test.ts`,r.click(),URL.revokeObjectURL(s)}catch(Q){alert(`Error generating test.ts for ${g.getSolverName()}: ${Q instanceof Error?Q.message:String(Q)}`)}e(!1)};return T.jsxs("div",{className:`relative ${A}`,ref:t,children:[T.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>e(!I),title:`Download options for ${g.getSolverName()}`,children:g.getSolverName()}),I&&T.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:[T.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),T.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:B,children:"Download page.tsx"}),T.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:C,children:"Download test.ts"})]})]})},CPI=g=>g.activeSubSolver?[g,...CPI(g.activeSubSolver)]:[g],xpo=({solver:g})=>{const A=CPI(g);return T.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((I,e)=>T.jsxs("div",{className:"flex items-center",children:[e>0&&T.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),T.jsx(Npo,{solver:I})]},I.getSolverName()))})},Fpo=({solver:g,triggerRender:A,animationSpeed:I=25,renderer:e,onRendererChange:t,onAnimationSpeedChange:o,onDownloadVisualization:B,onSolverStarted:C,onSolverCompleted:Q})=>{const[i,E]=z.useReducer(m=>!m,!1),n=z.useRef(void 0),s=z.useRef(null),r="solver-debugger-last-iteration",[a,c]=z.useState(null),h=z.useRef(null),l=z.useMemo(()=>[{label:"Slow",value:250,description:"250ms"},{label:"Normal",value:100,description:"100ms"},{label:"Fast",value:10,description:"10ms"},{label:"Fast (2x)",value:5,description:"5ms"},{label:"Fast (10x)",value:1,description:"1ms"},{label:"Fast 20x",value:.5,description:"2 steps / 1ms"},{label:"Fast 100x",value:.1,description:"10 steps / 1ms"}],[]),D=()=>{const m=Math.max(1,I),p=I<1?Math.round(1/I):1;n.current=setInterval(()=>{if(g.solved||g.failed){n.current&&(clearInterval(n.current),n.current=void 0),E(),A(),Q&&g.solved&&Q(g);return}for(let k=0;k<p&&!(g.solved||g.failed);k++)g.step();A()},m)},d=()=>{n.current&&(clearInterval(n.current),n.current=void 0)},y=()=>{!g.solved&&!g.failed&&(g.step(),A())},w=()=>{!g.solved&&!g.failed&&(C&&C(g),g.solve(),A(),Q&&Q(g))},u=()=>{i?(d(),E()):(E(),D())},G=()=>{if(g.solved||g.failed||i)return;s.current===null&&typeof window<"u"&&(s.current=window.localStorage.getItem(r));const m=window.prompt("Step until which iteration?",s.current??`${g.iterations}`);if(m===null)return;s.current=m,typeof window<"u"&&window.localStorage.setItem(r,m);const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;g.iterations<p&&!g.solved&&!g.failed;)g.step();A(),g.solved&&Q&&Q(g)};return z.useEffect(()=>()=>{d()},[]),z.useEffect(()=>{(g.solved||g.failed)&&i&&(d(),E())},[g.solved,g.failed,i]),z.useEffect(()=>{i&&(d(),D())},[I,i]),z.useEffect(()=>{if(typeof document>"u")return;const m=p=>{h.current&&!h.current.contains(p.target)&&c(null)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),T.jsxs("div",{className:"space-y-2 p-2 border-b",children:[T.jsx("div",{className:"flex items-center",children:T.jsxs("div",{className:"flex items-center gap-2",ref:h,children:[T.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[T.jsxs("div",{className:"relative",children:[T.jsx("button",{type:"button",onClick:()=>c(a==="renderer"?null:"renderer"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="renderer"?"open":"closed",children:"Renderer"}),a==="renderer"&&T.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[10rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:["vector","canvas"].map(m=>T.jsxs("button",{type:"button",onClick:()=>{t(m),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m==="vector"?"Vector":"Canvas",e===m&&T.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},m))})]}),T.jsxs("div",{className:"relative",children:[T.jsx("button",{type:"button",onClick:()=>c(a==="debug"?null:"debug"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="debug"?"open":"closed",children:"Debug"}),a==="debug"&&T.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:T.jsx("button",{type:"button",onClick:()=>{B(),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),T.jsxs("div",{className:"relative",children:[T.jsx("button",{type:"button",onClick:()=>c(a==="animation"?null:"animation"),className:"flex select-none items-center rounded-sm px-3 py-1 text-sm font-medium outline-none focus:bg-slate-100 data-[state=open]:bg-slate-100","data-state":a==="animation"?"open":"closed",children:"Animation"}),a==="animation"&&T.jsx("div",{className:"absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-slate-200 bg-white p-1 text-slate-950 shadow-md",children:l.map(m=>T.jsxs("button",{type:"button",onClick:()=>{o(m.value),c(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[m.label,T.jsx("span",{className:"ml-auto text-xs text-slate-500",children:m.description}),I===m.value&&T.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},m.value))})]})]}),T.jsx(xpo,{solver:g})]})}),T.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[T.jsx("button",{onClick:y,disabled:g.solved||g.failed||i,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),T.jsx("button",{onClick:w,disabled:g.solved||g.failed||i,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),T.jsx("button",{onClick:u,disabled:g.solved||g.failed,className:`px-3 py-1 rounded text-white text-sm ${i?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:i?"Stop":"Animate"}),T.jsx("button",{onClick:G,disabled:g.solved||g.failed||i,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),T.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",g.iterations]}),g.timeToSolve!==void 0&&T.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(g.timeToSolve/1e3).toFixed(3),"s"]}),g.solved&&T.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),g.failed&&T.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),g.error&&T.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",g.error]})]})},Upo=g=>g!==null&&"pipelineDef"in g&&Array.isArray(g.pipelineDef),Jpo=(g,A,I)=>{const e=g.currentPipelineStageIndex;return A<e?"Completed":A===e&&g.activeSubSolver?g.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Ppo=(g,A)=>{const e=g.pipelineDef[A].solverName,t=Jpo(g,A),o=g[e],B=g.firstIterationOfStage?.[e]??(A===g.currentPipelineStageIndex?g.iterations:null),C=g.iterations;let Q=0;if(t==="Completed"){const s=g.pipelineDef[A+1],r=s?g.firstIterationOfStage?.[s.solverName]:void 0;r!==void 0&&B!==null?Q=r-B:B!==null&&(Q=C-B)}else t==="In Progress"&&B!==null&&(Q=C-B);const i=g.timeSpentOnStage?.[e]??0;let E=0;t==="Completed"?E=1:t==="In Progress"&&o&&(E=o.progress??0);const n=o?.stats??null;return{index:A,name:e,status:t,firstIteration:B,iterations:Q,progress:E,timeSpent:i,stats:n&&Object.keys(n).length>0?n:null,solverInstance:o??null}},Kpo=({status:g})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return T.jsx("span",{className:`font-medium ${A[g]}`,children:g})},Lpo=({progress:g})=>{if(g===0)return null;const A=Math.round(g*100);return T.jsxs("div",{className:"flex items-center gap-2",children:[T.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:T.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),T.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},QPI=g=>{if(typeof g=="string")return g;if(typeof g=="number"||typeof g=="boolean"||typeof g=="bigint"||g==null)return String(g);if(typeof g=="object")try{return JSON.stringify(g)}catch{return String(g)}return String(g)},Ypo=g=>Object.entries(g).map(([A,I])=>`${A}: ${QPI(I)}`).join(", "),_po=({stats:g})=>{if(!g||Object.keys(g).length===0)return T.jsx("span",{children:"-"});const A=Object.entries(g),I=Ypo(g);return T.jsxs("details",{className:"cursor-pointer",children:[T.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:I}),T.jsx("div",{className:"mt-1 text-xs",children:A.map(([e,t])=>T.jsxs("div",{children:[e,": ",QPI(t)]},e))})]})},uCg=g=>{if(g===null||typeof g!="object")return g;if(Array.isArray(g))return g.map(uCg);const A={};for(const[I,e]of Object.entries(g))I.startsWith("_")||(A[I]=uCg(e));return A},bpo=(g,A)=>{try{if(typeof g.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const I=uCg(g.getConstructorParams()),e=new Blob([JSON.stringify(I,null,2)],{type:"application/json"}),t=URL.createObjectURL(e),o=document.createElement("a");o.href=t,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(t)}catch(I){alert(`Error downloading input for ${A}: ${I instanceof Error?I.message:String(I)}`)}},Hpo=({expanded:g})=>T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:`w-4 h-4 transition-transform duration-200 ${g?"rotate-90":""}`,children:T.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"})}),iPI=g=>{let A=g;for(;A.activeSubSolver;)A=A.activeSubSolver;return A},EPI=({solver:g,onStepUntilPhase:A,onDownloadInput:I,isNested:e=!1,indentLevel:t=0,triggerRender:o})=>{const[B,C]=z.useState(new Set),Q=g.pipelineDef.map((h,l)=>Ppo(g,l)),i=h=>{C(l=>{const D=new Set(l);return D.has(h)?D.delete(h):D.add(h),D})},E=h=>{A?.(h)},n=h=>{h.solverInstance&&(I?I(h.solverInstance,h.name):bpo(h.solverInstance,h.name))},s=h=>`${(h/1e3).toFixed(2)}s`,r=()=>{if(!g.solved&&!g.failed){const h=g.activeSubSolver;for(;!g.solved&&!g.failed&&(g.step(),!(g.activeSubSolver&&g.activeSubSolver!==h)););o?.()}},a=()=>{if(!g.solved&&!g.failed){const h=iPI(g);for(;!g.solved&&!g.failed&&(g.step(),iPI(g)===h););o?.()}},c=t*24;return T.jsxs("div",{className:e?"":"border-t border-gray-200",children:[!e&&T.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[T.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),T.jsxs("div",{className:"flex gap-2",children:[T.jsx("button",{onClick:a,disabled:g.solved||g.failed,className:"bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Solver"}),T.jsx("button",{onClick:r,disabled:g.solved||g.failed,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 disabled:cursor-not-allowed cursor-pointer text-white px-3 py-1 rounded text-sm",children:"Next Stage"})]})]}),T.jsx("div",{className:"overflow-x-auto",children:T.jsxs("table",{className:"w-full text-sm",children:[!e&&T.jsx("thead",{children:T.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),T.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",T.jsx("sub",{children:"0"})]}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),T.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),T.jsx("tbody",{children:Q.map(h=>{const l=Upo(h.solverInstance),D=B.has(h.name);return T.jsxs(rC.Fragment,{children:[T.jsxs("tr",{className:`border-b border-gray-100 ${h.status==="In Progress"?"bg-yellow-50":""}`,children:[T.jsx("td",{className:"px-4 py-2",children:T.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:c},children:[l?T.jsx("button",{onClick:()=>i(h.name),className:"text-gray-500 hover:text-gray-700",title:D?"Collapse":"Expand",children:T.jsx(Hpo,{expanded:D})}):T.jsx("span",{className:"w-4"}),T.jsx("span",{className:"text-gray-400 w-6",children:String(h.index+1).padStart(2,"0")}),T.jsx("button",{onClick:()=>E(h.name),disabled:h.status==="Completed"||g.solved||g.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${h.name} completes`,children:T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:T.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"})})}),T.jsx("span",{className:"font-medium text-gray-900",children:h.name})]})}),T.jsx("td",{className:"px-4 py-2",children:T.jsx(Kpo,{status:h.status})}),T.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:h.firstIteration!==null?h.firstIteration:""}),T.jsx("td",{className:"px-4 py-2 text-gray-600",children:h.iterations}),T.jsx("td",{className:"px-4 py-2",children:T.jsx(Lpo,{progress:h.progress})}),T.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(h.timeSpent)}),T.jsx("td",{className:"px-4 py-2 text-gray-500",children:T.jsx(_po,{stats:h.stats})}),T.jsx("td",{className:"px-4 py-2",children:h.solverInstance?T.jsxs("button",{onClick:()=>n(h),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${h.name}`,children:[T.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:T.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"})}),T.jsx("span",{children:"Input"})]}):null})]}),l&&D&&T.jsx("tr",{children:T.jsx("td",{colSpan:8,className:"p-0",children:T.jsx(EPI,{solver:h.solverInstance,onStepUntilPhase:A,onDownloadInput:I,isNested:!0,indentLevel:t+1,triggerRender:o})})})]},h.name)})})]})})]})};function vpo({graphics:g}){const A=g.points??[],I=g.lines??[],e=g.rects??[],t=g.circles??[],o=g.texts??[];let B=Number.POSITIVE_INFINITY,C=Number.POSITIVE_INFINITY,Q=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;const E=(h,l)=>{typeof h=="number"&&(h<B&&(B=h),h>Q&&(Q=h)),typeof l=="number"&&(l<C&&(C=l),l>i&&(i=l))};for(const h of A)E(h.x,h.y);for(const h of I){const l=h.points??[];for(const D of l)E(D.x,D.y)}for(const h of e){const l=h.x??0,D=h.y??0,d=h.width??0,y=h.height??0;E(l,D),E(l+d,D+y)}for(const h of t){const l=h.x??0,D=h.y??0,d=h.radius??1;E(l-d,D-d),E(l+d,D+d)}for(const h of o)E(h.x,h.y);(!isFinite(B)||!isFinite(C)||!isFinite(Q)||!isFinite(i))&&(B=-20,C=-20,Q=20,i=20);const n=10,s=B-n,r=C-n,a=Math.max(1,Q-B+2*n),c=Math.max(1,i-C+2*n);return T.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${s} ${r} ${a} ${c}`,role:"img","aria-label":"Graphics fallback",children:[e.map((h,l)=>T.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${l}`)),I.map((h,l)=>T.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(D=>`${D.x??0},${D.y??0}`).join(" ")},`line-${l}`)),t.map((h,l)=>T.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${l}`)),A.map((h,l)=>T.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${l}`)),o.map((h,l)=>T.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${l}`))]})}var Tpo=class extends rC.Component{constructor(g){super(g),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(g){console.error("InteractiveGraphics render error:",g)}render(){return this.state.hasError?this.props.fallback:this.props.children}},qpo=({solver:g,createSolver:A,animationSpeed:I=25,onSolverStarted:e,onSolverCompleted:t})=>{const[o,B]=z.useReducer(D=>D+1,0),[C]=z.useState(()=>{if(A)return A();if(!g)throw new Error("GenericSolverDebugger requires solver or createSolver");return g}),[Q,i]=z.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[E,n]=z.useState(I),s=z.useMemo(()=>{try{return C.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(D){return console.error("Visualization error:",D),{points:[],lines:[],rects:[],circles:[]}}},[C,o]),r=z.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);z.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const D=document.createElement("script");D.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(D)}},[]),z.useEffect(()=>{n(I)},[I]);const a=C.pipelineDef!==void 0,c=D=>{const d=C;if(!C.solved&&!C.failed){for(;!C.solved&&!C.failed&&d.currentPipelineStageIndex<=d.pipelineDef.findIndex(y=>y.solverName===D);)C.step();B()}},h=()=>{const D=JSON.stringify(s,null,2),d=new Blob([D],{type:"application/json"}),y=URL.createObjectURL(d),w=document.createElement("a");w.download="visualization.json",w.href=y,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(y)},l=D=>{i(D),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",D)};return T.jsxs("div",{children:[T.jsx(Fpo,{solver:C,triggerRender:B,animationSpeed:E,renderer:Q,onRendererChange:l,onAnimationSpeedChange:n,onDownloadVisualization:h,onSolverStarted:e,onSolverCompleted:t}),r?T.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):T.jsx(Tpo,{fallback:T.jsx(vpo,{graphics:s}),children:Q==="canvas"?T.jsx(Rpo,{graphics:s}):T.jsx(Mpo,{graphics:s})}),a&&T.jsx(EPI,{solver:C,onStepUntilPhase:c,triggerRender:B})]})};const Zpo=()=>{z.useEffect(()=>{const g="tailwind-cdn-script";if(document.getElementById(g)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const I=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),I)return;const e=document.createElement("script");e.id=g,e.src="https://cdn.tailwindcss.com",document.head.appendChild(e)},[])},Opo=1e3,_k=(g,A)=>{const{fileName:I,mimeType:e="text/plain"}=A,t=g instanceof Blob?g:new Blob([g],{type:e}),o=URL.createObjectURL(t),B=document.createElement("a");B.href=o,B.download=I,B.target="_blank",B.rel="noopener noreferrer",B.style.display="none",document.body.appendChild(B),B.click(),document.body.removeChild(B),setTimeout(()=>{URL.revokeObjectURL(o)},Opo)},GCg=g=>{let A=g.trim().replace(/[\\/:*?"<>|]/g,"_").replace(/[\x00-\x1f]/g,"").replace(/^\.+/,"").replace(/\.+$/,"").replace(/\s+/g," ").replace(/_+/g,"_");return/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/i.test(A)&&(A=`_${A}`),A=A.slice(0,200),A||"untitled"},Wpo=g=>{const A=g.solverConstructorArgs??[g.solverParams];if(g.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||A.length!==1)return A;const[{input:I,options:e}]=A;return[I,e]},yF="https://github.com/tscircuit/tscircuit-autorouter/issues/new",nPI="https://github.com/tscircuit/copper-pour-solver/issues/new",sPI="https://github.com/tscircuit/calculate-packing/issues/new",Vpo="https://github.com/tscircuit/matchpack/issues/new",aPI="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",jpo={PackSolver2:sPI,LayoutPipelineSolver:Vpo,AutoroutingPipelineSolver:yF,AssignableAutoroutingPipeline2:yF,AssignableAutoroutingPipeline3:yF,AutoroutingPipeline1_OriginalUnravel:yF,AutoroutingPipelineSolver3_HgPortPointPathing:yF,AutoroutingPipelineSolver4:yF,AutoroutingPipelineSolver5:yF,AutoroutingPipelineSolver7_MultiGraph:yF,AutoroutingPipelineSolver8:yF,CopperPourPipelineSolver:nPI,SchematicTracePipelineSolver:aPI},zpo=g=>g.toLowerCase().includes("pack")?$1I:g.toLowerCase().includes("rout")?gxI:Vro,rPI=g=>{const A=jpo[g];if(A)return A;const I=g.toLowerCase();return I.includes("autorout")?yF:I.includes("schematic")&&I.includes("trace")?aPI:I.includes("copperpour")?nPI:I.includes("pack")?sPI:null},Xpo=g=>`${GCg(`${g.componentName}-${g.solverName}`)}-solver-input.json`,cPI=g=>{_k(JSON.stringify(g.solverParams,null,2),{fileName:Xpo(g),mimeType:"application/json"})},$po=({solverEvent:g})=>{const A=rPI(g.solverName);return T.jsxs("div",{className:"rf-flex rf-items-center rf-justify-end rf-gap-2 rf-border-b rf-border-gray-200 rf-bg-gray-50 rf-px-4 rf-py-2",children:[T.jsxs(si,{type:"button",variant:"outline",size:"sm",onClick:()=>cPI(g),children:[T.jsx(ktA,{className:"rf-w-4 rf-h-4"}),"Download"]}),A?T.jsx(si,{asChild:!0,variant:"outline",size:"sm",children:T.jsxs("a",{href:A,target:"_blank",rel:"noopener noreferrer",children:[T.jsx(LGA,{className:"rf-w-4 rf-h-4"}),"Report"]})}):T.jsxs(si,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[T.jsx(LGA,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},Ako=({solverEvent:g})=>{const A=rPI(g.solverName);return A?T.jsx(si,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:T.jsx("a",{href:A,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:T.jsx(LGA,{className:"rf-w-4 rf-h-4"})})}):T.jsx(si,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",disabled:!0,title:"No report link configured for this solver","aria-label":"Report solver bug",children:T.jsx(LGA,{className:"rf-w-4 rf-h-4"})})},gko=({solverEvents:g=[]})=>{const[A,I]=z.useState(null);Zpo();const e=z.useMemo(()=>{const C=new Map;for(const Q of g){const i=`${Q.componentName}-${Q.solverName}`;C.set(i,Q)}return C},[g]),t=z.useMemo(()=>Array.from(e.keys()),[e]),o=A?e.get(A):null,B=z.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const C=b9A[o.solverName];if(!C)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(b9A).join(", ")}`,classFound:!1};try{return{instance:new C(...Wpo(o)),error:null,classFound:!0}}catch(Q){const i=Q instanceof Error?Q.message:String(Q);return console.error("Failed to reconstruct solver:",Q),{instance:null,error:`Failed to instantiate solver: ${i}`,classFound:!0}}},[o]);return g.length===0?T.jsx("div",{className:"rf-p-4",children:T.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:T.jsxs("div",{className:"rf-p-4",children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),T.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."})]})})}):T.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[T.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[T.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[t.length," ",t.length===1?"Solver":"Solvers"]}),t.map(C=>{const Q=e.get(C),i=A===C;return T.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${i?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>I(C),children:(()=>{const E=zpo(Q.solverName);return T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[T.jsx(E,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),T.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[T.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:Q.componentName}),T.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:Q.solverName})]})]})})()},C)})]}),T.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?B.instance?T.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[T.jsx($po,{solverEvent:o}),T.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:T.jsx(pS,{fallback:T.jsx("div",{className:"rf-p-4",children:T.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),T.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:T.jsx(qpo,{solver:B.instance})})})]}):T.jsxs("div",{className:"rf-p-4",children:[T.jsxs("div",{className:"rf-mb-4",children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),T.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),B.error&&T.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${B.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:T.jsx("p",{className:`rf-text-sm ${B.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:B.error})}),T.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[T.jsxs("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50 rf-flex rf-items-center rf-justify-between rf-gap-2",children:[T.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[T.jsx(Ako,{solverEvent:o}),T.jsx(si,{type:"button",variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8","aria-label":"Download solver input JSON",title:"Download solver input JSON",onClick:()=>cPI(o),children:T.jsx(ktA,{className:"rf-w-4 rf-h-4"})})]})]}),T.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:T.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)})})]})]}):T.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:T.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Iko=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],eko=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function tko(g,A){let I=-1,e=-1;for(let t=g.length-1;t>=0;t--){const o=g[t];if(o.status!=="running"||o.subcircuit_id!==A.subcircuit_id||o.componentDisplayName!==A.componentDisplayName)continue;let B=0,C=!1;for(const Q of eko)if(!(o[Q]===void 0||A[Q]===void 0)){if(o[Q]!==A[Q]){C=!0;break}B++}!C&&B>e&&(I=t,e=B)}return I}function oko(g,A){const I=Object.fromEntries(Iko.filter(B=>A[B]!==void 0).map(B=>[B,A[B]])),e=A.simpleRouteJson?structuredClone(A.simpleRouteJson):void 0,t=A.type==="autorouting:start"?-1:tko(g,A),o={...t===-1?{id:`autorouting_phase_${g.length+1}`}:g[t],...I,status:A.type==="autorouting:start"?"running":A.type==="autorouting:end"?"complete":"error",...A.type==="autorouting:start"?{startSimpleRouteJson:e}:A.type==="autorouting:end"?{endSimpleRouteJson:e}:{errorSimpleRouteJson:e,error:A.error?{...A.error}:void 0}};return t===-1?[...g,o]:g.map((B,C)=>C===t?o:B)}const Bko=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),Cko=new Set(["tscircuit","default","auto","auto_local"]);function Qko(g){if(g==="FanoutSolver")return"Fanout";if(g==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const A=g.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(A)return`Pipeline${A[1]}`;const I=g.match(/^AssignableAutoroutingPipeline(\d+)$/);return I?`Assignable${I[1]}`:g}function iko(g){const A=g.autorouterName?.trim(),I=A?.replace(/-/g,"_"),e=I&&Bko.get(I);if(e)return e;if(I&&!Cko.has(I))return A;const t=g.solverName?.trim();if(t)return Qko(t);const o=g.autorouterVersion?.trim();if(o){const B=o.match(/^beta[_-]pipeline(\d+)$/);return B?`Pipeline${B[1]}`:o==="latest"?"default":o}return A?"default":"Unknown"}const mCg="#fbbf24";function Eko(g){const A=g.endSimpleRouteJson?.traces??[],I=new Set(A.flatMap(t=>[t.pcb_trace_id,t.__replaces_pcb_trace_id].filter(o=>o!==void 0)));return[...(g.startSimpleRouteJson?.traces??[]).filter(t=>!I.has(t.pcb_trace_id)),...A]}function hPI(g){const A=new Map((g.startSimpleRouteJson?.traces??[]).map(I=>[I.pcb_trace_id,I]));return(g.endSimpleRouteJson?.traces??[]).filter(I=>{const e=A.get(I.pcb_trace_id);return!e||!!I.__replaces_pcb_trace_id&&I.__replaces_pcb_trace_id!==e.__replaces_pcb_trace_id||JSON.stringify(e.route)!==JSON.stringify(I.route)}).map(I=>I.pcb_trace_id)}function nko(g,A){return{outer_diameter:g.via_diameter??A.minViaPadDiameter??A.min_via_pad_diameter??A.minViaDiameter??.6,hole_diameter:g.via_hole_diameter??A.minViaHoleDiameter??A.min_via_hole_diameter??.3}}function lPI(g,A){const I=[];for(const C of g.route)C.route_type==="wire"?I.push({...C,layer:C.layer}):C.route_type==="via"?I.push({route_type:"via",x:C.x,y:C.y,from_layer:C.from_layer,to_layer:C.to_layer,...nko(C,A)}):C.route_type==="through_obstacle"&&I.push({route_type:"through_pad",start:{...C.start},end:{...C.end},width:C.width,start_layer:C.from_layer,end_layer:C.to_layer,pcb_smtpad_id:C.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:C.circuitJsonMetadata?.pcb_plated_hole_id});const e=C=>{let Q=-1,i=Number.POSITIVE_INFINITY;return I.forEach((E,n)=>{if(E.route_type!=="wire")return;const s=Math.hypot(E.x-C.x,E.y-C.y);s<i&&(i=s,Q=n)}),Q},t=g.route.filter(C=>C.route_type==="jumper").map(C=>[e(C.start),e(C.end)].sort((Q,i)=>Q-i)).filter(([C,Q])=>C>=0&&Q>C).sort(([C],[Q])=>C-Q),o=[];let B=0;for(const[C,Q]of t)C>=B&&o.push(I.slice(B,C+1)),B=Math.max(B,Q);return B<I.length&&o.push(I.slice(B)),o}function sko(g){const A=[],I=[],e=g.endSimpleRouteJson;if(!e)return{lines:A,circles:I};const t=new Set(hPI(g));for(const o of e.traces??[])if(t.has(o.pcb_trace_id))for(const B of lPI(o,e)){let C;for(const Q of B){if(Q.route_type==="through_pad"){C={...Q.end,layer:Q.end_layer,width:Q.width};continue}const i=Q.route_type==="wire"?Q.layer:Q.from_layer;C&&C.layer===i&&(C.x!==Q.x||C.y!==Q.y)&&A.push({points:[{x:C.x,y:C.y},{x:Q.x,y:Q.y}],strokeWidth:Q.route_type==="wire"?Q.width:C.width,strokeColor:mCg,layer:i}),Q.route_type==="via"&&I.push({center:{x:Q.x,y:Q.y},radius:Q.outer_diameter/2,stroke:mCg,fill:"transparent"}),C={x:Q.x,y:Q.y,layer:Q.route_type==="wire"?Q.layer:Q.to_layer,width:Q.route_type==="wire"?Q.width:C?.width??e.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:A,circles:I}}function ako(g){const A=JSON.stringify(g);let I=2166136261;for(let e=0;e<A.length;e++)I=Math.imul(I^A.charCodeAt(e),16777619);return(I>>>0).toString(36)}const rko=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function cko(g,A,I){const e=I==="input"?A.startSimpleRouteJson??A.errorSimpleRouteJson:A.endSimpleRouteJson,t=g.filter(i=>!rko.has(i.type)&&!i.type.endsWith("_error")&&!i.type.endsWith("_warning"));if(!e)return t;const o=I==="input"?e.traces??[]:Eko(A),B=new Set(g.filter(i=>i.type==="source_trace").map(i=>i.source_trace_id)),C=["top",...Array.from({length:Math.max(0,e.layerCount-2)},(i,E)=>`inner${E+1}`),...e.layerCount>1?["bottom"]:[]],Q=[];for(const i of o){const n=e.connections.find(r=>r.name===i.connection_name||r.source_trace_id===i.connection_name)?.source_trace_id??i.connection_name??"",s=lPI(i,e);for(const[r,a]of s.entries()){const c={type:"pcb_trace",pcb_trace_id:`${A.id}_${I}_${i.pcb_trace_id}_${r}_${ako(a)}`,subcircuit_id:A.subcircuit_id??void 0,source_trace_id:B.has(n)?n:void 0,route:a};Q.push(c);for(const[h,l]of a.entries()){if(l.route_type!=="via")continue;const D=C.indexOf(l.from_layer),d=C.indexOf(l.to_layer),y={type:"pcb_via",pcb_via_id:`${c.pcb_trace_id}_via_${h}`,pcb_trace_id:c.pcb_trace_id,subcircuit_id:A.subcircuit_id??void 0,x:l.x,y:l.y,outer_diameter:l.outer_diameter,hole_diameter:l.hole_diameter,layers:D>=0&&d>=0?C.slice(Math.min(D,d),Math.max(D,d)+1):[l.from_layer,l.to_layer]};Q.push(y)}}}return[...t,...Q]}const pCg=(g,A)=>g.phaseName||`Phase ${g.phaseOrdinal??A+1}`,DPI=g=>g.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||g.componentDisplayName||g.subcircuit_id||"Board",dPI=g=>g.startSimpleRouteJson??g.endSimpleRouteJson??g.errorSimpleRouteJson,hko={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},lko=({circuitJson:g,phases:A=[],isRunning:I=!1})=>{const[e,t]=z.useState(null),[o,B]=z.useState("output"),[C,Q]=z.useState(!0),[i,E]=z.useState(!1),n=z.useRef(null),[s,r]=z.useState(480),a=e?A.findIndex(N=>N.id===e.id&&dPI(N)===dPI(e)):-1,c=a<0?A.length-1:a,h=A[c],l=a<0,D=!!h?.endSimpleRouteJson,d=h?.startSimpleRouteJson??h?.errorSimpleRouteJson,y=!!d,w=o==="output"&&!D?"input":o==="input"&&!y?"output":o,u=w==="input"?d:h?.endSimpleRouteJson,G=z.useMemo(()=>!h||!u?null:cko(g??[],h,w),[g,h,u,w]),m=z.useMemo(()=>h&&w==="output"&&C?sko(h):{lines:[],circles:[]},[h,w,C]);if(z.useLayoutEffect(()=>{const N=n.current;if(!N)return;const U=()=>r(Math.max(360,N.clientHeight));U();const K=new ResizeObserver(U);return K.observe(N),()=>K.disconnect()},[!!h]),!h)return T.jsxs("div",{className:"rf-flex rf-min-h-[400px] rf-flex-col rf-items-center rf-justify-center rf-gap-3 rf-p-8 rf-text-center",children:[T.jsx(gxI,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),T.jsx("h3",{className:"rf-text-base rf-font-medium",children:I?"Waiting for autorouting":"No autorouting captures"}),T.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:I?"Phases appear as the circuit routes. Each capture includes its input and output on the PCB.":"Run a circuit with autorouting enabled to inspect its phases. A circuit JSON file alone does not include routing history."})]});const p=pCg(h,c),k=h.status==="running"&&I,S=!D,R=d?.connections.length,x=G?.filter(N=>N.type==="pcb_trace").length??0;return T.jsxs("div",{className:"rf-flex rf-h-full rf-min-h-[620px] rf-flex-col rf-bg-white md:rf-flex-row","data-testid":"autorouting-explorer",children:[T.jsxs("aside",{className:"rf-flex rf-shrink-0 rf-flex-col rf-border-b rf-border-gray-200 md:rf-w-52 md:rf-border-b-0 md:rf-border-r","aria-label":"Routing phases",children:[T.jsxs("div",{className:"rf-flex rf-items-center rf-justify-between rf-px-3 rf-py-2 rf-text-xs rf-text-gray-500",children:[T.jsx("span",{children:"Routing phases"}),T.jsx("span",{children:A.length})]}),T.jsx("div",{className:"rf-flex rf-gap-1 rf-overflow-x-auto rf-px-1.5 rf-pb-1.5 md:rf-flex-col md:rf-overflow-x-hidden md:rf-overflow-y-auto",children:A.map((N,U)=>{const K=hPI(N).length,Y=N.endSimpleRouteJson?`${K} ${K===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&I?"Routing…":"No output";return T.jsxs("button",{type:"button","aria-pressed":U===c,title:`${DPI(N)} · ${Y}`,onClick:()=>t(N),className:Bo("rf-flex rf-min-w-[192px] rf-items-start rf-gap-2 rf-rounded-md rf-border rf-px-2 rf-py-2 rf-text-left md:rf-min-w-0",U===c?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[T.jsx("span",{className:Bo("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",U===c?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:U+1}),T.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[T.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[T.jsx("span",{className:"rf-min-w-0 rf-flex-1 rf-truncate rf-text-xs rf-font-medium rf-leading-5 rf-text-gray-800",title:pCg(N,U),children:pCg(N,U)}),N.status==="complete"?T.jsx(aF,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?T.jsx(Hog,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):I?T.jsx(kS,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),T.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[iko(N)," · ",Y]})]})]},N.id)})})]}),T.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[T.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-gap-3 rf-border-b rf-border-gray-200 rf-px-4 rf-py-3",children:[T.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[p,T.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[c+1," of ",A.length]})]}),I&&T.jsx("button",{type:"button",onClick:()=>t(null),disabled:l,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:l?"Following latest":"Follow latest"}),T.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>T.jsx("button",{type:"button","aria-pressed":w===N,disabled:N==="input"?!y:!D,onClick:()=>B(N),className:Bo("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",w===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),T.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-px-4 rf-py-2 rf-text-xs rf-text-gray-600",children:[T.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[T.jsx("input",{type:"checkbox",checked:C,disabled:w!=="output",onChange:N=>Q(N.target.checked),className:"rf-accent-blue-600"}),T.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:mCg}}),"Highlight changes (all layers)"]}),T.jsxs("span",{children:[w==="input"?"Before this phase":"After this phase"," ","· ",x," traces"]})]}),S&&T.jsx("div",{className:Bo("rf-border-y rf-px-4 rf-py-2 rf-text-xs",h.status==="error"?"rf-border-red-100 rf-bg-red-50 rf-text-red-700":"rf-border-blue-100 rf-bg-blue-50 rf-text-blue-700"),role:"status",children:h.status==="error"?`Routing failed: ${h.error?.message||"No output was captured."}`:k?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),T.jsx("div",{ref:n,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:G?T.jsx(Yog,{circuitJson:G,height:s,allowEditing:!1,clickToInteractEnabled:!1,initialState:hko,debugGraphics:m}):T.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),T.jsxs("div",{className:"rf-flex rf-flex-wrap rf-items-center rf-justify-between rf-gap-2 rf-border-t rf-border-gray-200 rf-px-4 rf-py-3 rf-text-xs rf-text-gray-500",children:[T.jsxs("span",{children:[R===void 0?"Input unavailable":`${R} input connections`,` · ${DPI(h)}`]}),T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[T.jsxs("button",{type:"button",disabled:!u,onClick:()=>_k(JSON.stringify(u,null,2),{fileName:`${h.id}-${w}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[T.jsx(ktA,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),T.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>E(!i),className:"rf-flex rf-items-center rf-gap-1",children:[T.jsx(Rb,{className:Bo("rf-h-3 rf-w-3",i&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),i&&T.jsx("pre",{className:"rf-m-0 rf-max-h-64 rf-overflow-auto rf-border-t rf-border-gray-200 rf-bg-gray-50 rf-p-4 rf-text-xs","aria-label":`${p} ${w} SRJ`,children:u?JSON.stringify(u,null,2):"No snapshot captured."})]})]})},yPI=({errorMessage:g,errorStack:A,circuitJsonErrors:I})=>{z.useEffect(()=>{if(uJ("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&g){const e=new Error(g);A&&(e.stack=A);try{Rq.captureException(e)}catch{}}},[g,A]),z.useEffect(()=>{if(uJ("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&I&&I.length>0)for(const e of I){const t=new Error(e.message||"Circuit JSON Error");e.stack&&(t.stack=e.stack);try{Rq.captureException(t,{error_type:e.type})}catch{}}},[I])},wPI=g=>{z.useEffect(()=>{try{sdt(g)}catch{}},[g.source,g.component,g.isWebEmbedded,g.activeTab])},uPI="0.0.3062",Dko={version:uPI},BpA=cXg()(hXg(g=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{g({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),dko=g=>{const[A,I]=z.useState([]),[e,t]=z.useState(null),[o,B]=z.useState(""),[C,Q]=XT("eval-version-selection",null),i=BpA(r=>r.setLastRunEvalVersion),E=BpA(r=>r.lastRunEvalVersion);return z.useEffect(()=>{g&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(r=>r.json()).then(r=>{if(Array.isArray(r?.versions)){let a=[...r.versions];r.tags?.latest&&(t(r.tags.latest),a=a.filter(c=>c!==r.tags.latest)),I(a)}}).catch(()=>{})},[g]),z.useEffect(()=>{g&&(C?(window.TSCIRCUIT_LATEST_EVAL_VERSION=C,i(C)):e&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=e,i(e)))},[g,C,e]),{versions:z.useMemo(()=>A.filter(r=>r.includes(o)).slice(0,50),[A,o]),latestVersion:e,lastRunEvalVersion:E,search:o,setSearch:B,selectVersion:r=>{Q(r),B("")}}},yko=({snippetNames:g,onSelect:A,onCancel:I,isOpen:e})=>{const[t,o]=z.useState(""),[B,C]=z.useState("");if(!e)return null;const Q=g.filter(n=>n.toLowerCase().includes(B.toLowerCase())),i=B&&!g.includes(B),E=n=>{n.key==="Enter"&&(Q.length===1?o(Q[0]):i&&o(B))};return T.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:T.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[T.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),T.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:B,onChange:n=>C(n.target.value),onKeyDown:E}),T.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[Q.map(n=>T.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${t===n?"bg-blue-50":""}`,onClick:()=>o(n),children:n},n)),i&&T.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${t===B?"bg-blue-50":""}`,onClick:()=>o(B),children:['Create new "',B,'"']})]}),T.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[T.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:I,children:"Cancel"}),T.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>t&&A(t),disabled:!t,children:t===B?`Create "${t}"`:`Save to ${t}`})]})]})})},wko=g=>{const A=z.useRef(null),I=Jc(e=>e.recentEvents);z.useEffect(()=>{if(I.length===0)return;const e=I[0];e.event_id!==A.current&&(g(e),A.current=e.event_id)},[I,g])};var uko=Object.defineProperty,iP=(g,A)=>uko(g,"name",{value:A,configurable:!0}),Gko="AlertDialog",[mko,SCB]=rk(Gko,[SFI]),EP=SFI(),pko=iP(g=>{const{__scopeAlertDialog:A,...I}=g,e=EP(A);return T.jsx(umA,{...e,...I,modal:!0})},"AlertDialog");z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(ylo,{...o,...t,ref:I})},"AlertDialogTrigger"));var kko=iP(g=>{const{__scopeAlertDialog:A,...I}=g,e=EP(A);return T.jsx(GmA,{...e,...I})},"AlertDialogPortal"),GPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(YtA,{...o,...t,ref:I})},"AlertDialogOverlay")),Mko="AlertDialogContent",[Sko,fko]=mko(Mko),mPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,children:t,...o}=A,B=EP(e),C=z.useRef(null),Q=Gi(I,C),i=z.useRef(null);return T.jsx(Sko,{scope:e,cancelRef:i,children:T.jsx(btA,{role:"alertdialog",...B,...o,ref:Q,onOpenAutoFocus:fo(o.onOpenAutoFocus,E=>{E.preventDefault(),i.current?.focus({preventScroll:!0})}),onPointerDownOutside:E=>E.preventDefault(),onInteractOutside:E=>E.preventDefault(),children:t})})},"AlertDialogContent")),pPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(mmA,{...o,...t,ref:I})},"AlertDialogTitle")),kPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(pmA,{...o,...t,ref:I})},"AlertDialogDescription")),MPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,o=EP(e);return T.jsx(NBg,{...o,...t,ref:I})},"AlertDialogAction")),Rko="AlertDialogCancel",SPI=z.forwardRef(iP(function(A,I){const{__scopeAlertDialog:e,...t}=A,{cancelRef:o}=fko(Rko,e),B=EP(e),C=Gi(I,o);return T.jsx(NBg,{...B,...t,ref:C})},"AlertDialogCancel"));const fPI=pko,Nko=kko,RPI=z.forwardRef(({className:g,...A},I)=>T.jsx(GPI,{className:Bo("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));RPI.displayName=GPI.displayName;const kCg=z.forwardRef(({className:g,...A},I)=>T.jsxs(Nko,{children:[T.jsx(RPI,{}),T.jsx(mPI,{ref:I,className:Bo("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...A})]}));kCg.displayName=mPI.displayName;const MCg=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});MCg.displayName="AlertDialogHeader";const SCg=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});SCg.displayName="AlertDialogFooter";const fCg=z.forwardRef(({className:g,...A},I)=>T.jsx(pPI,{ref:I,className:Bo("rf-text-lg rf-font-semibold",g),...A}));fCg.displayName=pPI.displayName;const RCg=z.forwardRef(({className:g,...A},I)=>T.jsx(kPI,{ref:I,className:Bo("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));RCg.displayName=kPI.displayName;const xko=z.forwardRef(({className:g,...A},I)=>T.jsx(MPI,{ref:I,className:Bo(nO(),g),...A}));xko.displayName=MPI.displayName;const NCg=z.forwardRef(({className:g,...A},I)=>T.jsx(SPI,{ref:I,className:Bo(nO({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",g),...A}));NCg.displayName=SPI.displayName;var Fko=Object.defineProperty,nP=(g,A)=>Fko(g,"name",{value:A,configurable:!0}),xCg="Checkbox",[Uko,fCB]=rk(xCg),[Jko,FCg]=Uko(xCg);function NPI(g){const{__scopeCheckbox:A,checked:I,children:e,defaultChecked:t,disabled:o,form:B,name:C,onCheckedChange:Q,required:i,value:E="on",internal_do_not_use_render:n}=g,[s,r]=NR({prop:I,defaultProp:t??!1,onChange:Q,caller:xCg}),[a,c]=z.useState(null),[h,l]=z.useState(null),[D,d]=z.useState(null),y=a?!!B||!!a.closest("form"):!0,w={checked:s,disabled:o,setChecked:r,control:a,setControl:c,name:C,form:B,value:E,userClick:D,onUserClick:d,required:i,defaultChecked:wf(t)?!1:t,isFormControl:y,bubbleInput:h,setBubbleInput:l};return T.jsx(Jko,{scope:A,...w,children:FPI(n)?n(w):e})}nP(NPI,"CheckboxProvider");var Pko="CheckboxTrigger",Kko=z.forwardRef(nP(function({__scopeCheckbox:A,onKeyDown:I,onClick:e,...t},o){const{control:B,value:C,disabled:Q,checked:i,required:E,setControl:n,setChecked:s,onUserClick:r,isFormControl:a,bubbleInput:c}=FCg(Pko,A),h=Gi(o,n),l=z.useRef(i);return z.useEffect(()=>{const D=B?.form;if(D){const d=nP(()=>s(l.current),"reset");return D.addEventListener("reset",d),()=>D.removeEventListener("reset",d)}},[B,s]),T.jsx(yQ.button,{type:"button",role:"checkbox","aria-checked":wf(i)?"mixed":i,"aria-required":E,"data-state":UCg(i),"data-disabled":Q?"":void 0,disabled:Q,value:C,...t,ref:h,onKeyDown:fo(I,D=>{D.key==="Enter"&&D.preventDefault()}),onClick:fo(e,D=>{const d=D.isPropagationStopped();r({requestedChecked:wf(i)?!0:!i,hasConsumerStoppedPropagation:d}),s(y=>wf(y)?!0:!y),c&&a&&(d||D.stopPropagation())})})},"CheckboxTrigger")),xPI=z.forwardRef(nP(function(A,I){const{__scopeCheckbox:e,name:t,checked:o,defaultChecked:B,required:C,disabled:Q,value:i,onCheckedChange:E,form:n,...s}=A;return T.jsx(NPI,{__scopeCheckbox:e,checked:o,defaultChecked:B,disabled:Q,required:C,onCheckedChange:E,name:t,form:n,value:i,internal_do_not_use_render:({isFormControl:r})=>T.jsxs(T.Fragment,{children:[T.jsx(Kko,{...s,ref:I,__scopeCheckbox:e}),r&&T.jsx(bko,{__scopeCheckbox:e})]})})},"Checkbox")),Lko="CheckboxIndicator",Yko=z.forwardRef(nP(function(A,I){const{__scopeCheckbox:e,forceMount:t,...o}=A,B=FCg(Lko,e);return T.jsx($M,{present:t||wf(B.checked)||B.checked===!0,children:T.jsx(yQ.span,{"data-state":UCg(B.checked),"data-disabled":B.disabled?"":void 0,...o,ref:I,style:{pointerEvents:"none",...A.style}})})},"CheckboxIndicator")),_ko="CheckboxBubbleInput",bko=z.forwardRef(nP(function({__scopeCheckbox:A,onClick:I,...e},t){const{control:o,userClick:B,checked:C,defaultChecked:Q,required:i,disabled:E,name:n,value:s,form:r,bubbleInput:a,setBubbleInput:c}=FCg(_ko,A),h=Gi(t,c),l=sBg(o),D=z.useRef(!1),d=z.useRef(C),y=z.useRef(B),w=z.useRef(null);z.useEffect(()=>{const G=a;if(!G)return;const m=window.HTMLInputElement.prototype,k=Object.getOwnPropertyDescriptor(m,"checked").set;if(!k)return;const S=d.current!==C;d.current=C;const R=B!==null&&B!==y.current;if(y.current=B,R)w.current=S?null:B,S&&(G.indeterminate=wf(C),k.call(G,wf(C)?!1:C)),G.dispatchEvent(new Event("click",{bubbles:!B.hasConsumerStoppedPropagation}));else if(S){const x=w.current;w.current=null;const N=x?.requestedChecked===C;D.current=!0,G.indeterminate=wf(C),k.call(G,wf(C)?!1:C),G.dispatchEvent(new Event("click",{bubbles:!(N&&x.hasConsumerStoppedPropagation)})),D.current=!1}},[a,C,B]);const u=z.useRef(wf(C)?!1:C);return T.jsx(yQ.input,{type:"checkbox","aria-hidden":!0,defaultChecked:Q??u.current,required:i,disabled:E,name:n,value:s,form:r,...e,tabIndex:-1,ref:h,onClick:fo(I,G=>{D.current&&G.stopPropagation()}),style:{...e.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function FPI(g){return typeof g=="function"}nP(FPI,"isFunction");function wf(g){return g==="indeterminate"}nP(wf,"isIndeterminate");function UCg(g){return wf(g)?"indeterminate":g?"checked":"unchecked"}nP(UCg,"getState");const ioA=z.forwardRef(({className:g,...A},I)=>T.jsx(xPI,{ref:I,className:Bo("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",g),...A,children:T.jsx(Yko,{className:Bo("rf-flex rf-items-center rf-justify-center rf-text-current"),children:T.jsx(aF,{className:"rf-h-4 rf-w-4"})})}));ioA.displayName=xPI.displayName;const Yb=umA,Hko=GmA,UPI=z.forwardRef(({className:g,...A},I)=>T.jsx(YtA,{className:Bo("rf-fixed rf-inset-0 rf-z-50 rf-bg-black/80 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0",g),...A,ref:I}));UPI.displayName=YtA.displayName;const NL=z.forwardRef(({className:g,children:A,showOverlay:I=!0,...e},t)=>T.jsxs(Hko,{children:[T.jsx(UPI,{className:Bo(I?"":"rf-hidden")}),T.jsx(btA,{ref:t,className:Bo("rf-fixed rf-left-[50%] rf-top-[50%] rf-z-50 rf-grid rf-w-full rf-max-w-lg rf-translate-x-[-50%] rf-translate-y-[-50%] rf-gap-4 rf-border rf-border-zinc-200 rf-bg-white rf-p-6 rf-shadow-lg rf-duration-200 data-[state=open]:rf-animate-in data-[state=closed]:rf-animate-out data-[state=closed]:rf-fade-out-0 data-[state=open]:rf-fade-in-0 data-[state=closed]:rf-zoom-out-95 data-[state=open]:rf-zoom-in-95 data-[state=closed]:rf-slide-out-to-left-1/2 data-[state=closed]:rf-slide-out-to-top-[48%] data-[state=open]:rf-slide-in-from-left-1/2 data-[state=open]:rf-slide-in-from-top-[48%] sm:rf-rounded-lg dark:rf-border-zinc-800 dark:rf-bg-zinc-950",g),...e,children:A})]}));NL.displayName=btA.displayName;const xL=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",g),...A});xL.displayName="DialogHeader";const YO=({className:g,...A})=>T.jsx("div",{className:Bo("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",g),...A});YO.displayName="DialogFooter";const FL=z.forwardRef(({className:g,...A},I)=>T.jsx(mmA,{ref:I,className:Bo("rf-text-lg rf-font-semibold",g),...A}));FL.displayName=mmA.displayName;const _b=z.forwardRef(({className:g,...A},I)=>T.jsx(pmA,{ref:I,className:Bo("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",g),...A}));_b.displayName=pmA.displayName;const CpA={"tscircuit.com":{label:"tscircuit.com",placeholder:"Search tscircuit packages...",emptyMessage:"No packages found"},jlcpcb:{label:"JLCPCB Parts",placeholder:"Search JLCPCB parts (e.g. C14663)...",emptyMessage:"No parts found"},kicad:{label:"KiCad Footprints",placeholder:"Search KiCad footprints...",emptyMessage:"No footprints found"}},vko="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let JCg=null;const PCg=async()=>(JCg||(JCg=import(vko)),JCg),Tko=g=>(A,I)=>{const e=new Headers(I?.headers),t={};return e.forEach((o,B)=>{t[B]=o}),fetch(`${g?.apiBase??Fm}/proxy`,{...I,headers:{...t,"X-Target-Url":A.toString(),"X-Sender-Origin":t.origin??"","X-Sender-Host":t.host??"https://easyeda.com","X-Sender-Referer":t.referer??"","X-Sender-User-Agent":t["user-agent"]??"","X-Sender-Cookie":t.cookie??"",authority:t.authority??"","content-type":t["content-type"]??"",...g?.headers}})},qko=async(g,A=10)=>{const I=encodeURIComponent(g),e=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${A}&q=${I}`);if(!e.ok)throw new Error(`JLCPCB API error: ${e.status}`);return(await e.json()).components??[]},Zko=g=>({lcscId:g.lcsc,manufacturer:g.mfr,description:g.description,partNumber:`C${g.lcsc}`,package:g.package,price:g.price,stock:g.stock,isBasic:g.is_basic}),JPI=async(g,A)=>{const{fetchEasyEDAComponent:I}=await PCg();return I(g,{fetch:Tko(A),includeModelMetadata:A?.includeModelMetadata})},Oko=async(g,A)=>{const{convertRawEasyToTsx:I}=await PCg(),e=await JPI(g,A);return I({rawEasy:e})},Wko=async(g,A)=>{const{EasyEdaJsonSchema:I,convertEasyEdaJsonToCircuitJson:e}=await PCg(),t=await JPI(g,{...A,includeModelMetadata:!1}),o=I.parse(t);return e(o,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function UL(g){return Array.isArray?Array.isArray(g):KPI(g)==="[object Array]"}function Vko(g){if(typeof g=="string")return g;if(typeof g=="bigint")return g.toString();const A=g+"";return A=="0"&&1/g==-1/0?"-0":A}function KCg(g){return g==null?"":Vko(g)}function wG(g){return typeof g=="string"}function QpA(g){return typeof g=="number"}function jko(g){return g===!0||g===!1||zko(g)&&KPI(g)=="[object Boolean]"}function PPI(g){return typeof g=="object"}function zko(g){return PPI(g)&&g!==null}function FS(g){return g!=null}function ipA(g){return!g.trim().length}function KPI(g){return g==null?g===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(g)}const Xko="Incorrect 'index' type",LCg="Invalid doc index: must be a non-negative integer within the bounds of the docs array",$ko=g=>`Invalid value for key ${g}`,AMo=g=>`Pattern length exceeds max of ${g}.`,gMo=g=>`Missing ${g} property in key`,IMo=g=>`Property 'weight' in key '${g}' must be a positive integer`,eMo="Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.",LPI=Object.prototype.hasOwnProperty;var tMo=class{constructor(g){this._keys=[],this._keyMap={};let A=0;g.forEach(I=>{const e=YPI(I);this._keys.push(e),this._keyMap[e.id]=e,A+=e.weight}),this._keys.forEach(I=>{I.weight/=A})}get(g){return this._keyMap[g]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function YPI(g){let A=null,I=null,e=null,t=1,o=null;if(wG(g)||UL(g))e=g,A=_PI(g),I=EpA(g);else{if(!LPI.call(g,"name"))throw new Error(gMo("name"));const B=g.name;if(e=B,LPI.call(g,"weight")&&g.weight!==void 0&&(t=g.weight,t<=0))throw new Error(IMo(EpA(B)));A=_PI(B),I=EpA(B),o=g.getFn??null}return{path:A,id:I,weight:t,src:e,getFn:o}}function _PI(g){return UL(g)?g:g.split(".")}function EpA(g){return UL(g)?g.join("."):g}function oMo(g,A){const I=[];let e=!1;const t=(o,B,C,Q)=>{if(FS(o))if(!B[C])I.push(Q!==void 0?{v:o,i:Q}:o);else{const i=o[B[C]];if(!FS(i))return;if(C===B.length-1&&(wG(i)||QpA(i)||jko(i)||typeof i=="bigint"))I.push(Q!==void 0?{v:KCg(i),i:Q}:KCg(i));else if(UL(i)){e=!0;for(let E=0,n=i.length;E<n;E+=1)t(i[E],B,C+1,E)}else B.length&&t(i,B,C+1,Q)}};return t(g,wG(A)?A.split("."):A,0),e?I:I[0]}const cQ=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(g,A)=>g.score===A.score?g.idx<A.idx?-1:1:g.score<A.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,useTokenSearch:!1,tokenize:void 0,tokenMatch:"any",getFn:oMo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function BMo(g){return g>=9&&g<=13||g===32||g===160}function CMo(g=1,A=3){const I=new Map,e=Math.pow(10,A);return{get(t){let o=0,B=!1;for(let Q=0;Q<t.length;Q++)BMo(t.charCodeAt(Q))?B=!1:B||(o++,B=!0);if(o===0&&(o=1),I.has(o))return I.get(o);const C=Math.round(e/Math.pow(o,.5*g))/e;return I.set(o,C),C},clear(){I.clear()}}}var YCg=class{constructor({getFn:g=cQ.getFn,fieldNormWeight:A=cQ.fieldNormWeight}={}){this.norm=CMo(A,3),this.getFn=g,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(g=[]){this.docs=g}setIndexRecords(g=[]){this.records=g}setKeys(g=[]){this.keys=g,this._keysMap={},g.forEach((A,I)=>{this._keysMap[A.id]=I})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const g=this.docs.length;this.records=new Array(g);let A=0;if(wG(this.docs[0]))for(let I=0;I<g;I++){const e=this._createStringRecord(this.docs[I],I);e&&(this.records[A++]=e)}else for(let I=0;I<g;I++)this.records[A++]=this._createObjectRecord(this.docs[I],I);this.records.length=A,this.norm.clear()}add(g,A){if(!Number.isInteger(A)||A<0)throw new Error(LCg);if(wG(g)){const e=this._createStringRecord(g,A);return e&&this.records.push(e),e}const I=this._createObjectRecord(g,A);return this.records.push(I),I}removeAt(g){if(!Number.isInteger(g)||g<0)throw new Error(LCg);for(let A=0,I=this.records.length;A<I;A+=1)if(this.records[A].i===g){this.records.splice(A,1);break}for(let A=0,I=this.records.length;A<I;A+=1)this.records[A].i>g&&(this.records[A].i-=1)}removeAll(g){const A=new Set;for(const e of g)Number.isInteger(e)&&e>=0&&A.add(e);if(A.size===0)return;this.records=this.records.filter(e=>!A.has(e.i));const I=Array.from(A).sort((e,t)=>e-t);for(const e of this.records){let t=0,o=I.length;for(;t<o;){const B=t+o>>>1;I[B]<e.i?t=B+1:o=B}e.i-=t}}getValueForItemAtKeyId(g,A){return g[this._keysMap[A]]}size(){return this.records.length}_createStringRecord(g,A){return!FS(g)||ipA(g)?null:{v:g,i:A,n:this.norm.get(g)}}_createObjectRecord(g,A){const I={i:A,$:{}};for(let e=0,t=this.keys.length;e<t;e++){const o=this.keys[e],B=o.getFn?o.getFn(g):this.getFn(g,o.path);if(FS(B)){if(UL(B)){const C=[];for(let Q=0,i=B.length;Q<i;Q+=1){const E=B[Q];if(FS(E)){if(wG(E)){if(!ipA(E)){const n={v:E,i:Q,n:this.norm.get(E)};C.push(n)}}else if(FS(E.v)){const n=wG(E.v)?E.v:KCg(E.v);if(!ipA(n)){const s={v:n,i:E.i,n:this.norm.get(n)};C.push(s)}}}}I.$[e]=C}else if(wG(B)&&!ipA(B)){const C={v:B,n:this.norm.get(B)};I.$[e]=C}}}return I}toJSON(){return{keys:this.keys.map(({getFn:g,...A})=>A),records:this.records}}};function bPI(g,A,{getFn:I=cQ.getFn,fieldNormWeight:e=cQ.fieldNormWeight}={}){const t=new YCg({getFn:I,fieldNormWeight:e});return t.setKeys(g.map(YPI)),t.setSources(A),t.create(),t}function QMo(g,{getFn:A=cQ.getFn,fieldNormWeight:I=cQ.fieldNormWeight}={}){const{keys:e,records:t}=g,o=new YCg({getFn:A,fieldNormWeight:I});return o.setKeys(e),o.setIndexRecords(t),o}function iMo(g=[],A=cQ.minMatchCharLength){const I=[];let e=-1,t=-1,o=0;for(let B=g.length;o<B;o+=1){const C=g[o];C&&e===-1?e=o:!C&&e!==-1&&(t=o-1,t-e+1>=A&&I.push([e,t]),e=-1)}return g[o-1]&&o-e>=A&&I.push([e,o-1]),I}function EMo(g,A,I,{location:e=cQ.location,distance:t=cQ.distance,threshold:o=cQ.threshold,findAllMatches:B=cQ.findAllMatches,minMatchCharLength:C=cQ.minMatchCharLength,includeMatches:Q=cQ.includeMatches,ignoreLocation:i=cQ.ignoreLocation}={}){if(A.length>32)throw new Error(AMo(32));const E=A.length,n=g.length,s=Math.max(0,Math.min(e,n));let r=o,a=s;const c=(p,k)=>{const S=p/E;if(i)return S;const R=Math.abs(s-k);return t?S+R/t:R?1:S},h=C>1||Q,l=h?Array(n):[];let D;for(;(D=g.indexOf(A,a))>-1;){const p=c(0,D);if(r=Math.min(p,r),a=D+E,h){let k=0;for(;k<E;)l[D+k]=1,k+=1}}a=-1;let d=[],y=1,w=0,u=E+n;const G=1<<E-1;for(let p=0;p<E;p+=1){let k=0,S=u;for(;k<S;)c(p,s+S)<=r?k=S:u=S,S=Math.floor((u-k)/2+k);u=S;let R=Math.max(1,s-S+1);const x=B?n:Math.min(s+S,n)+E,N=Array(x+2);N[x+1]=(1<<p)-1;for(let U=x;U>=R;U-=1){const K=U-1,Y=I[g[K]];if(N[U]=(N[U+1]<<1|1)&Y,p&&(N[U]|=(d[U+1]|d[U])<<1|1|d[U+1]),N[U]&G&&(y=c(p,K),y<=r)){if(r=y,a=K,w=p,a<=s)break;R=Math.max(1,2*s-a)}}if(c(p+1,s)>r)break;d=N}if(h&&a>=0){const p=Math.min(n-1,a+E-1+w);for(let k=a;k<=p;k+=1)I[g[k]]&&(l[k]=1)}const m={isMatch:a>=0,score:Math.max(.001,y)};if(h){const p=iMo(l,C);p.length?Q&&(m.indices=p):m.isMatch=!1}return m}function nMo(g){const A={};for(let I=0,e=g.length;I<e;I+=1){const t=g.charAt(I);A[t]=(A[t]||0)|1<<e-I-1}return A}function _Cg(g){if(g.length<=1)return g;g.sort((I,e)=>I[0]-e[0]||I[1]-e[1]);const A=[g[0]];for(let I=1,e=g.length;I<e;I+=1){const t=A[A.length-1],o=g[I];o[0]<=t[1]+1?t[1]=Math.max(t[1],o[1]):A.push(o)}return A}const HPI={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},sMo=new RegExp("["+Object.keys(HPI).join("")+"]","g"),EoA=typeof String.prototype.normalize=="function"?g=>g.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"").replace(sMo,A=>HPI[A]):g=>g;var bCg=class{constructor(g,{location:A=cQ.location,threshold:I=cQ.threshold,distance:e=cQ.distance,includeMatches:t=cQ.includeMatches,findAllMatches:o=cQ.findAllMatches,minMatchCharLength:B=cQ.minMatchCharLength,isCaseSensitive:C=cQ.isCaseSensitive,ignoreDiacritics:Q=cQ.ignoreDiacritics,ignoreLocation:i=cQ.ignoreLocation}={}){if(this.options={location:A,threshold:I,distance:e,includeMatches:t,findAllMatches:o,minMatchCharLength:B,isCaseSensitive:C,ignoreDiacritics:Q,ignoreLocation:i},g=C?g:g.toLowerCase(),g=Q?EoA(g):g,this.pattern=g,this.chunks=[],!this.pattern.length)return;const E=(s,r)=>{this.chunks.push({pattern:s,alphabet:nMo(s),startIndex:r})},n=this.pattern.length;if(n>32){let s=0;const r=n%32,a=n-r;for(;s<a;)E(this.pattern.substr(s,32),s),s+=32;if(r){const c=n-32;E(this.pattern.substr(c),c)}}else E(this.pattern,0)}searchIn(g){const{isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e}=this.options;if(g=A?g:g.toLowerCase(),g=I?EoA(g):g,this.pattern===g){if(g.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const a={isMatch:!0,score:0};return e&&(a.indices=[[0,g.length-1]]),a}const{location:t,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,ignoreLocation:i}=this.options,E=[];let n=0,s=!1;this.chunks.forEach(({pattern:a,alphabet:c,startIndex:h})=>{const{isMatch:l,score:D,indices:d}=EMo(g,a,c,{location:t+h,distance:o,threshold:B,findAllMatches:C,minMatchCharLength:Q,includeMatches:e,ignoreLocation:i});l&&(s=!0),n+=D,l&&d&&E.push(...d)});const r={isMatch:s,score:s?n/this.chunks.length:1};return s&&e&&(r.indices=_Cg(E)),r}};const aMo=new Set(["fuzzy","include"]);function rMo(g){return g.startsWith("inverse")}const HCg=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:g=>({type:"exact",search(A){const I=A===g;return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:g=>({type:"include",search(A){let I=0,e;const t=[],o=g.length;for(;(e=A.indexOf(g,I))>-1;)I=e+o,t.push([e,I-1]);const B=!!t.length;return{isMatch:B,score:B?0:1,indices:t}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:g=>({type:"prefix-exact",search(A){const I=A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,g.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:g=>({type:"inverse-prefix-exact",search(A){const I=!A.startsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:g=>({type:"inverse-suffix-exact",search(A){const I=!A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:g=>({type:"suffix-exact",search(A){const I=A.endsWith(g);return{isMatch:I,score:I?0:1,indices:[A.length-g.length,A.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:g=>({type:"inverse-exact",search(A){const I=A.indexOf(g)===-1;return{isMatch:I,score:I?0:1,indices:[0,A.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(g,A={})=>{const I=new bCg(g,{location:A.location??cQ.location,threshold:A.threshold??cQ.threshold,distance:A.distance??cQ.distance,includeMatches:A.includeMatches??cQ.includeMatches,findAllMatches:A.findAllMatches??cQ.findAllMatches,minMatchCharLength:A.minMatchCharLength??cQ.minMatchCharLength,isCaseSensitive:A.isCaseSensitive??cQ.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics??cQ.ignoreDiacritics,ignoreLocation:A.ignoreLocation??cQ.ignoreLocation});return{type:"fuzzy",search(e){return I.searchIn(e)}}}}],vPI=HCg.length,cMo="\0",hMo="|";function lMo(g){const A=[],I=g.length;let e=0;for(;e<I;){for(;e<I&&g[e]===" ";)e++;if(e>=I)break;let t=e;for(;t<I&&g[t]!==" "&&g[t]!=='"';)t++;if(t<I&&g[t]==='"'){for(t++;t<I;){if(g[t]==='"'){const o=t+1;if(o>=I||g[o]===" "){t++;break}if(g[o]==="$"&&(o+1>=I||g[o+1]===" ")){t+=2;break}}t++}A.push(g.substring(e,t)),e=t}else{for(;t<I&&g[t]!==" ";)t++;A.push(g.substring(e,t)),e=t}}return A}function TPI(g,A){const I=g.match(A);return I?I[1]:null}function DMo(g,A={}){return g.replace(/\\\|/g,cMo).split(hMo).map(I=>{const e=lMo(I.replace(/\u0000/g,"|").trim()).filter(o=>o&&!!o.trim()),t=[];for(let o=0,B=e.length;o<B;o+=1){const C=e[o];let Q=!1,i=-1;for(;!Q&&++i<vPI;){const E=HCg[i],n=TPI(C,E.multiRegex);n&&(t.push(E.create(n,A)),Q=!0)}if(!Q)for(i=-1;++i<vPI;){const E=HCg[i],n=TPI(C,E.singleRegex);if(n){t.push(E.create(n,A));break}}}return t})}var dMo=class{constructor(g,{isCaseSensitive:A=cQ.isCaseSensitive,ignoreDiacritics:I=cQ.ignoreDiacritics,includeMatches:e=cQ.includeMatches,minMatchCharLength:t=cQ.minMatchCharLength,ignoreLocation:o=cQ.ignoreLocation,findAllMatches:B=cQ.findAllMatches,location:C=cQ.location,threshold:Q=cQ.threshold,distance:i=cQ.distance}={}){this.query=null,this.options={isCaseSensitive:A,ignoreDiacritics:I,includeMatches:e,minMatchCharLength:t,findAllMatches:B,ignoreLocation:o,location:C,threshold:Q,distance:i},g=A?g:g.toLowerCase(),g=I?EoA(g):g,this.pattern=g,this.query=DMo(this.pattern,this.options)}static condition(g,A){return A.useExtendedSearch}searchIn(g){const A=this.query;if(!A)return{isMatch:!1,score:1};const{includeMatches:I,isCaseSensitive:e,ignoreDiacritics:t}=this.options;g=e?g:g.toLowerCase(),g=t?EoA(g):g;let o=0;const B=[];let C=0,Q=!1;for(let i=0,E=A.length;i<E;i+=1){const n=A[i];B.length=0,o=0,Q=!1;for(let s=0,r=n.length;s<r;s+=1){const a=n[s],{isMatch:c,indices:h,score:l}=a.search(g);if(c)o+=1,C+=l,rMo(a.type)&&(Q=!0),I&&(aMo.has(a.type)?B.push(...h):B.push(h));else{C=0,o=0,B.length=0,Q=!1;break}}if(o){const s={isMatch:!0,score:C/o};return Q&&(s.hasInverse=!0),I&&(s.indices=_Cg(B)),s}}return{isMatch:!1,score:1}}};const vCg=[];function TCg(...g){vCg.push(...g)}function npA(g,A){for(let I=0,e=vCg.length;I<e;I+=1){const t=vCg[I];if(t.condition(g,A))return new t(g,A)}return new bCg(g,A)}const spA={AND:"$and",OR:"$or"},qCg={PATH:"$path",PATTERN:"$val"},ZCg=g=>!!(g[spA.AND]||g[spA.OR]),yMo=g=>!!g[qCg.PATH],wMo=g=>!UL(g)&&PPI(g)&&!ZCg(g),qPI=g=>({[spA.AND]:Object.keys(g).map(A=>({[A]:g[A]}))});function ZPI(g,A,{auto:I=!0}={}){const e=t=>{if(wG(t)){const Q={keyId:null,pattern:t};return I&&(Q.searcher=npA(t,A)),Q}const o=Object.keys(t),B=yMo(t);if(!B&&o.length>1&&!ZCg(t))return e(qPI(t));if(wMo(t)){const Q=B?t[qCg.PATH]:o[0],i=B?t[qCg.PATTERN]:t[Q];if(!wG(i))throw new Error($ko(Q));const E={keyId:EpA(Q),pattern:i};return I&&(E.searcher=npA(i,A)),E}const C={children:[],operator:o[0]};return o.forEach(Q=>{const i=t[Q];UL(i)&&i.forEach(E=>{C.children.push(e(E))})}),C};return ZCg(g)||(g=qPI(g)),e(g)}function OCg(g,{ignoreFieldNorm:A=cQ.ignoreFieldNorm}){let I=1;return g.forEach(({key:e,norm:t,score:o})=>{const B=e?e.weight:null;I*=Math.pow(o===0&&B?Number.EPSILON:o,(B||1)*(A?1:t))}),I}function uMo(g,{ignoreFieldNorm:A=cQ.ignoreFieldNorm}){g.forEach(I=>{I.score=OCg(I.matches,{ignoreFieldNorm:A})})}var GMo=class{constructor(g,A){this.limit=g,this.heap=[],this.comparator=A}get size(){return this.heap.length}insert(g){this.size<this.limit?(this.heap.push(g),this._bubbleUp(this.size-1)):this.comparator(g,this.heap[0])<0&&(this.heap[0]=g,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(g){const A=this.heap;for(;g>0;){const I=g-1>>1;if(this.comparator(A[g],A[I])<=0)break;const e=A[g];A[g]=A[I],A[I]=e,g=I}}_sinkDown(g){const A=this.heap,I=A.length;let e=g;do{g=e;const t=2*g+1,o=2*g+2;if(t<I&&this.comparator(A[t],A[e])>0&&(e=t),o<I&&this.comparator(A[o],A[e])>0&&(e=o),e!==g){const B=A[g];A[g]=A[e],A[e]=B}}while(e!==g)}};function mMo(g){const A=[];return g.matches.forEach(I=>{if(!FS(I.indices)||!I.indices.length)return;const e={indices:I.indices,value:I.value};I.key&&(e.key=I.key.id),I.idx>-1&&(e.refIndex=I.idx),A.push(e)}),A}function pMo(g,A,{includeMatches:I=cQ.includeMatches,includeScore:e=cQ.includeScore}={}){return g.map(t=>{const{idx:o}=t,B={item:A[o],refIndex:o};return I&&(B.matches=mMo(t)),e&&(B.score=t.score),B})}const kMo=/[\p{L}\p{M}\p{N}_]+/gu,OPI=new WeakSet;function MMo(g){OPI.has(g)||(OPI.add(g),console.warn(`[Fuse] tokenize regex ${g} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function SMo(g){if(typeof g=="function"){let A=!1;return I=>{const e=g(I);if(!A&&(A=!0,!Array.isArray(e)||e.some(t=>typeof t!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(e)?"array containing non-strings":typeof e}.`);return e}}return g instanceof RegExp?(g.global||MMo(g),A=>A.match(g)||[]):A=>A.match(kMo)||[]}function WCg({isCaseSensitive:g=!1,ignoreDiacritics:A=!1,tokenize:I}={}){const e=SMo(I);return{tokenize(t){return g||(t=t.toLowerCase()),A&&(t=EoA(t)),e(t)}}}var fMo=class{static condition(g,A){return A.useTokenSearch}constructor(g,A){this.options=A,this.analyzer=WCg({isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,tokenize:A.tokenize});const I=this.analyzer.tokenize(g),{df:e,fieldCount:t}=A._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const o of I){this.termSearchers.push(new bCg(o,{location:A.location,threshold:A.threshold,distance:A.distance,includeMatches:A.includeMatches,findAllMatches:A.findAllMatches,minMatchCharLength:A.minMatchCharLength,isCaseSensitive:A.isCaseSensitive,ignoreDiacritics:A.ignoreDiacritics,ignoreLocation:!0}));const B=e.get(o)||0,C=Math.log(1+(t-B+.5)/(B+.5));this.idfWeights.push(C)}this.combineAll=A.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(g){if(!this.termSearchers.length)return{isMatch:!1,score:1};const A=[];let I=0,e=0,t=0,o=0;const B=this.combineAll&&!this.useMask?new Set:null;for(let i=0;i<this.termSearchers.length;i++){const E=this.termSearchers[i].searchIn(g),n=this.idfWeights[i];e+=n,E.isMatch&&(t++,I+=n*(1-E.score),E.indices&&A.push(...E.indices),this.combineAll&&(this.useMask?o|=1<<i:B.add(i)))}if(t===0)return{isMatch:!1,score:1};const C=e>0?1-I/e:0,Q={isMatch:!0,score:Math.max(.001,C)};return this.options.includeMatches&&A.length&&(Q.indices=_Cg(A)),this.combineAll&&(this.useMask?Q.matchedMask=o:Q.matchedTerms=B,Q.termCount=this.numTerms),Q}};function VCg(g,A,I,e){const t=e.tokenize(A);if(!t.length)return;g.fieldCount++,g.docFieldCount.set(I,(g.docFieldCount.get(I)||0)+1);const o=new Set(t);let B=g.docTermFieldHits.get(I);B||(B=new Map,g.docTermFieldHits.set(I,B));for(const C of o)B.set(C,(B.get(C)||0)+1),g.df.set(C,(g.df.get(C)||0)+1)}function WPI(g,A,I,e){const{i:t,v:o,$:B}=A;if(o!==void 0){VCg(g,o,t,e);return}if(B)for(let C=0;C<I;C++){const Q=B[C];if(Q)if(Array.isArray(Q))for(const i of Q)VCg(g,i.v,t,e);else VCg(g,Q.v,t,e)}}function RMo(g,A,I){const e={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const t of g)WPI(e,t,A,I);return e}function NMo(g,A,I,e){WPI(g,A,I,e)}function xMo(g,A){const I=g.docFieldCount.get(A);if(I===void 0)return;g.fieldCount-=I,g.docFieldCount.delete(A);const e=g.docTermFieldHits.get(A);if(e){for(const[t,o]of e){const B=(g.df.get(t)||0)-o;B<=0?g.df.delete(t):g.df.set(t,B)}g.docTermFieldHits.delete(A)}}function VPI(g,A){if(A.length===0)return;const I=Array.from(new Set(A)).sort((C,Q)=>C-Q);for(const C of I)xMo(g,C);const e=C=>{let Q=0,i=I.length;for(;Q<i;){const E=Q+i>>>1;I[E]<C?Q=E+1:i=E}return C-Q},t=I[0],o=new Map;for(const[C,Q]of g.docFieldCount)o.set(C>t?e(C):C,Q);g.docFieldCount=o;const B=new Map;for(const[C,Q]of g.docTermFieldHits)B.set(C>t?e(C):C,Q);g.docTermFieldHits=B}var JL=class{constructor(g,A,I){this.options={...cQ,...A},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new tMo(this.options.keys),this._docs=g,this._myIndex=null,this._invertedIndex=null,this.setCollection(g,I),this._lastQuery=null,this._lastSearcher=null}_getSearcher(g){if(this._lastQuery===g)return this._lastSearcher;const A=npA(g,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=g,this._lastSearcher=A,A}setCollection(g,A){if(this._docs=g,A&&!(A instanceof YCg))throw new Error(Xko);if(this._myIndex=A||bPI(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const I=WCg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=RMo(this._myIndex.records,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}add(g){if(!FS(g))return;this._docs.push(g);const A=this._myIndex.add(g,this._docs.length-1);if(this._invertedIndex&&A){const I=WCg({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});NMo(this._invertedIndex,A,this._myIndex.keys.length,I)}this._invalidateSearcherCache()}remove(g=()=>!1){const A=[],I=[];for(let e=0,t=this._docs.length;e<t;e+=1)g(this._docs[e],e)&&(A.push(this._docs[e]),I.push(e));if(I.length){this._invertedIndex&&VPI(this._invertedIndex,I);const e=new Set(I);this._docs=this._docs.filter((t,o)=>!e.has(o)),this._myIndex.removeAll(I),this._invalidateSearcherCache()}return A}removeAt(g){if(!Number.isInteger(g)||g<0||g>=this._docs.length)throw new Error(LCg);this._invertedIndex&&VPI(this._invertedIndex,[g]);const A=this._docs.splice(g,1)[0];return this._myIndex.removeAt(g),this._invalidateSearcherCache(),A}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(g=>this._keyStore.get(g.id)||g)}search(g,A){const{limit:I=-1}=A||{},{includeMatches:e,includeScore:t,shouldSort:o,sortFn:B,ignoreFieldNorm:C}=this.options;if(wG(g)&&!g.trim()){let s=this._docs.map((r,a)=>({item:r,refIndex:a}));return QpA(I)&&I>-1&&(s=s.slice(0,I)),s}const Q=o&&QpA(I)&&I>0&&wG(g),i=B,E=(s,r)=>i(s,r)||s.idx-r.idx;let n;if(Q){const s=new GMo(I,E);wG(this._docs[0])?this._searchStringList(g,{heap:s,ignoreFieldNorm:C}):this._searchObjectList(g,{heap:s,ignoreFieldNorm:C}),n=s.extractSorted()}else n=wG(g)?wG(this._docs[0])?this._searchStringList(g):this._searchObjectList(g):this._searchLogical(g),uMo(n,{ignoreFieldNorm:C}),o&&n.sort(wG(g)?E:i),QpA(I)&&I>-1&&(n=n.slice(0,I));return pMo(n,this._docs,{includeMatches:e,includeScore:t})}_searchStringList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=A?null:[];return o.forEach(({v:C,i:Q,n:i})=>{if(!FS(C))return;const E=e.searchIn(C);if(E.isMatch){const n={score:E.score,value:C,norm:i,indices:E.indices};t&&(n.matchedMask=E.matchedMask,n.matchedTerms=E.matchedTerms,n.termCount=E.termCount);const s=[n];if(!t||this._coversAllTokens(s)){const r={item:C,idx:Q,matches:s};A?(r.score=OCg(r.matches,{ignoreFieldNorm:I}),A.insert(r)):B.push(r)}}}),B}_searchLogical(g){const A=ZPI(g,this.options),I=this._normalizedKeys(),e=(C,Q,i)=>{if(!("children"in C)){const{keyId:r,searcher:a}=C;let c;return r===null?(c=[],I.forEach((h,l)=>{c.push(...this._findMatches({key:h,value:Q[l],searcher:a}))})):c=this._findMatches({key:this._keyStore.get(r),value:this._myIndex.getValueForItemAtKeyId(Q,r),searcher:a}),c&&c.length?[{idx:i,item:Q,matches:c}]:[]}const{children:E,operator:n}=C,s=[];for(let r=0,a=E.length;r<a;r+=1){const c=E[r],h=e(c,Q,i);if(h.length)s.push(...h);else if(n===spA.AND)return[]}return s},t=this._myIndex.records,o=new Map,B=[];return t.forEach(({$:C,i:Q})=>{if(FS(C)){const i=e(A,C,Q);i.length&&(o.has(Q)||(o.set(Q,{idx:Q,item:C,matches:[]}),B.push(o.get(Q))),i.forEach(({matches:E})=>{o.get(Q).matches.push(...E)}))}}),B}_searchObjectList(g,{heap:A,ignoreFieldNorm:I}={}){const e=this._getSearcher(g),t=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:o}=this._myIndex,B=this._normalizedKeys(),C=A?null:[];return o.forEach(({$:Q,i})=>{if(!FS(Q))return;const E=[];let n=!1,s=!1;if(B.forEach((r,a)=>{const c=this._findMatches({key:r,value:Q[a],searcher:e});c.length?(E.push(...c),c[0].hasInverse&&(s=!0)):n=!0}),!(s&&n)&&E.length&&(!t||this._coversAllTokens(E))){const r={idx:i,item:Q,matches:E};A?(r.score=OCg(r.matches,{ignoreFieldNorm:I}),A.insert(r)):C.push(r)}}),C}_findMatches({key:g,value:A,searcher:I}){if(!FS(A))return[];const e=[];if(UL(A))A.forEach(({v:t,i:o,n:B})=>{if(!FS(t))return;const C=I.searchIn(t);if(C.isMatch){const Q={score:C.score,key:g,value:t,idx:o,norm:B,indices:C.indices,hasInverse:C.hasInverse};C.termCount!==void 0&&(Q.matchedMask=C.matchedMask,Q.matchedTerms=C.matchedTerms,Q.termCount=C.termCount),e.push(Q)}});else{const{v:t,n:o}=A,B=I.searchIn(t);if(B.isMatch){const C={score:B.score,key:g,value:t,norm:o,indices:B.indices,hasInverse:B.hasInverse};B.termCount!==void 0&&(C.matchedMask=B.matchedMask,C.matchedTerms=B.matchedTerms,C.termCount=B.termCount),e.push(C)}}return e}_coversAllTokens(g){const A=g.length?g[0].termCount:void 0;if(A===void 0)return!0;if(A<=31){let e=0;for(let t=0;t<g.length;t++)e|=g[t].matchedMask||0;return e===2**A-1}const I=new Set;for(let e=0;e<g.length;e++){const t=g[e].matchedTerms;if(t)for(const o of t)I.add(o)}return I.size===A}};JL.version="7.5.0",JL.createIndex=bPI,JL.parseIndex=QMo,JL.config=cQ,JL.match=function(g,A,I){if(I&&I.useTokenSearch)throw new Error(eMo);return npA(g,{...cQ,...I}).searchIn(A)},JL.parseQuery=ZPI,TCg(dMo),TCg(fMo),JL.use=function(...g){g.forEach(A=>TCg(A))};var FMo=JL;const UMo="https://kicad-mod-cache.tscircuit.com";let jCg=null,noA=null,zCg=null;const JMo=async()=>jCg||noA||(noA=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(g=>g.json()).then(g=>(jCg=g,noA=null,g)),noA),PMo=async(g,A=20)=>{const I=await JMo();return zCg||(zCg=new FMo(I)),zCg.search(g).slice(0,A).map(e=>e.item)},KMo=g=>{const A=g.replace(".pretty/","/").replace(".kicad_mod",""),I=`kicad:${A}`;return{path:g,qualifiedName:I,description:A}},LMo=g=>g.replace(/^\/+/,"").split("/").map(A=>encodeURIComponent(A)).join("/"),YMo=async g=>{const A=await fetch(`${UMo}/${LMo(g)}`);if(!A.ok)throw new Error(`KiCad footprint fetch failed: ${A.status}`);const I=await A.text(),{KicadFootprintToCircuitJsonConverter:e}=await xS("kicad-to-circuit-json"),t=new e;return t.addFile(g.split("/").pop()??"selected-footprint.kicad_mod",I),t.runUntilFinished(),t.getOutput()},jPI=g=>g?.source==="jlcpcb"||g?.source==="kicad",_Mo=async(g,A)=>{if(g.source==="jlcpcb")return Wko(g.component.partNumber,A?.jlcpcb);if(g.source==="kicad")return YMo(g.footprint.path);throw new Error("Footprint preview is not available for this source")},bMo=({query:g,placeholder:A,isSearching:I,onQueryChange:e,onSubmit:t})=>{const o=z.useCallback(B=>{B.key==="Enter"&&(B.preventDefault(),t())},[t]);return T.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[T.jsxs("div",{className:"rf-relative rf-flex-grow",children:[T.jsx(Tog,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),T.jsx(hCg,{placeholder:A,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:g,onChange:B=>e(B.target.value),onKeyDown:o})]}),T.jsx(si,{onClick:t,disabled:I||g.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:I?T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):T.jsxs(T.Fragment,{children:[T.jsx(Tog,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),T.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},HMo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),vMo=g=>HMo.format(g),zPI=g=>{switch(g.source){case"tscircuit.com":{const A=g.package;return`tscircuit-${A.package_id??`${A.org_owner_tscircuit_handle??"unknown"}-${A.unscoped_name??A.name??"package"}`}`}case"jlcpcb":return`jlc-${g.component.lcscId}`;case"kicad":return`kicad-${g.footprint.path}`;default:return"unknown"}},TMo=g=>{switch(g.source){case"tscircuit.com":return g.package.unscoped_name;case"jlcpcb":return g.component.isDirectLookup?g.component.partNumber:g.component.manufacturer;case"kicad":return g.footprint.qualifiedName}},qMo=g=>{switch(g.source){case"tscircuit.com":return g.package.description||(g.package.org_owner_tscircuit_handle?`Component by ${g.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return g.component.description;case"kicad":return g.footprint.description}},ZMo=g=>{switch(g.source){case"tscircuit.com":return g.package.name;case"jlcpcb":return g.component.isDirectLookup?void 0:g.component.partNumber;case"kicad":return}},OMo=({results:g,selected:A,onSelect:I,onShowDetails:e})=>{const t=A?zPI(A):null;return T.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:g.map(o=>{const B=zPI(o),C=t===B,Q=TMo(o),i=qMo(o),E=ZMo(o),n=o.source==="jlcpcb"?o.component.stock:null,s=o.source==="jlcpcb"?o.component.price:null,r=o.source==="jlcpcb"?o.component.isBasic:null,a=o.source==="jlcpcb"?o.component.isDirectLookup:!1;return T.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${C?"rf-bg-zinc-100":""}`,onClick:()=>I(o),children:[T.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[T.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[T.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[Q,o.source==="jlcpcb"&&r!=null&&T.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${r?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:r?"Basic":"Extended"}),a&&T.jsx("span",{className:"rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 rf-bg-blue-100 rf-text-blue-700",children:"Direct lookup"}),o.source==="tscircuit.com"&&o.package.is_private&&T.jsx(nco,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),o.source==="jlcpcb"&&n!=null?T.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[n.toLocaleString()," in stock"]}):null]}),T.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[E?T.jsx("span",{className:"rf-mr-2",children:E}):null,i]})]}),T.jsxs("div",{children:[o.source==="tscircuit.com"&&e?T.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:T.jsx(si,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:c=>{c.stopPropagation(),e(o)},children:"See Details"})}):o.source==="jlcpcb"&&n!=null?T.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[n.toLocaleString()," in stock"]}):null,s!=null&&T.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:vMo(s)})]})]},B)})})},WMo=({circuitJson:g,error:A,isLoading:I,height:e})=>T.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:e},children:I?T.jsxs("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-gap-2 rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:[T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):A?T.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:e},children:T.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[T.jsx(Hog,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),T.jsx("span",{children:A})]})}):g?T.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:T.jsx(Yog,{circuitJson:g,height:e,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):T.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-text-sm rf-text-zinc-300",style:{height:e},children:"No preview"})}),XPI={importComponentDialog:101,importComponentDetailsDialog:102},VMo=({packageResult:g,isOpen:A,onOpenChange:I,isLoading:e,details:t,previewTab:o,onPreviewTabChange:B,isSubmitting:C,onImport:Q})=>{const i=g?.package??null,E=i?.latest_pcb_preview_image_url,n=i?.latest_sch_preview_image_url,s=i?.latest_cad_preview_image_url,r=i?.unscoped_name?.split("/").pop()??i?.unscoped_name,a=i?.org_owner_tscircuit_handle??void 0,c=a?`https://tscircuit.com/${a}`:void 0,h=a&&r?`https://tscircuit.com/${a}/${r}`:void 0;return T.jsx(Yb,{open:A,onOpenChange:I,children:T.jsxs(NL,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:XPI.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[T.jsx(xL,{className:"rf-pb-4 rf-border-b",children:T.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:T.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[T.jsx(FL,{className:"rf-text-xl rf-font-semibold rf-truncate",children:r}),T.jsx(_b,{children:i?.description})]})})}),T.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[a?T.jsxs("div",{children:[T.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),T.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:c?T.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:a}):a})]}):null,(s||E||n)&&T.jsx(T.Fragment,{children:T.jsxs("div",{children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),T.jsxs(OvA,{value:o,onValueChange:l=>B(l),children:[T.jsxs(PDA,{className:"rf-inline-flex rf-h-9 rf-items-center rf-justify-center rf-rounded-lg rf-bg-zinc-100 rf-p-1 rf-text-zinc-500 dark:rf-bg-zinc-800 dark:rf-text-zinc-400",children:[E&&T.jsx(mx,{value:"pcb",children:"PCB"}),n&&T.jsx(mx,{value:"schematic",children:"Schematic"}),s&&T.jsx(mx,{value:"3d",children:"3D"})]}),T.jsxs("div",{className:"rf-mt-4",children:[T.jsx(xy,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:E?T.jsx("img",{src:E,alt:`${r??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),T.jsx(xy,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:n?T.jsx("img",{src:n,alt:`${r??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),T.jsx(xy,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:s?T.jsx("img",{src:s,alt:`${r??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),t?.ai_description?T.jsxs("section",{children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),T.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:T.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:t.ai_description})})]}):null,t?.ai_usage_instructions?T.jsxs("section",{children:[T.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),T.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:T.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:t.ai_usage_instructions})})]}):null,e?T.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),T.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),T.jsxs(YO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[T.jsx("div",{className:"rf-flex-1",children:h?T.jsxs(si,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(h,"_blank"),children:[T.jsx(tco,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),T.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[T.jsx(si,{variant:"outline",onClick:()=>I(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),T.jsx(si,{onClick:Q,disabled:C,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:C?T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},jMo=()=>{const[g,A]=z.useState(null),[I,e]=z.useState(!1),t=z.useCallback(async(B,C)=>{e(!0);try{const Q=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${B}/${C}`)}`);if(!Q.ok)throw new Error(`Failed to load package details: ${Q.status}`);const i=await Q.json();A(i.package??null)}catch(Q){console.error("Failed to fetch package details",Q),A(null)}finally{e(!1)}},[]),o=z.useCallback(()=>{A(null),e(!1)},[]);return{details:g,isLoading:I,fetchDetails:t,reset:o}},zMo=(g,A)=>{const[I,e]=z.useState({circuitJson:null,error:null,isLoading:!1});return z.useEffect(()=>{if(!g||!jPI(g)){e({circuitJson:null,error:null,isLoading:!1});return}let t=!1;return e({circuitJson:null,error:null,isLoading:!0}),_Mo(g,A).then(o=>{t||e({circuitJson:o,error:null,isLoading:!1})}).catch(o=>{t||e({circuitJson:null,error:o instanceof Error?o.message:"Failed to load footprint preview",isLoading:!1})}),()=>{t=!0}},[g,A]),I},XMo=async(g,A)=>{const I={"Content-Type":"application/json"};A&&(I.Authorization=`Bearer ${A}`);const e=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:I,body:JSON.stringify({query:g})});if(!e.ok)throw new Error(`tscircuit registry error: ${e.status}`);return(await e.json()).packages??[]},$Mo=({sessionToken:g})=>{const[A,I]=z.useState([]),[e,t]=z.useState(!1),[o,B]=z.useState(null),[C,Q]=z.useState(!1),i=z.useCallback(async n=>{const s=n.trim();if(!s)return[];t(!0),B(null);try{const a=(await XMo(s,g)).map(c=>({source:"tscircuit.com",package:c}));return I(a),a}catch(r){return console.error("Error searching tscircuit packages",r),I([]),B(r instanceof Error?r.message:"Failed to search tscircuit packages"),[]}finally{t(!1),Q(!0)}},[g]),E=z.useCallback(()=>{I([]),t(!1),B(null),Q(!1)},[]);return{results:A,isSearching:e,error:o,hasSearched:C,search:i,reset:E}},ASo=g=>{const A=/^C(\d+)$/i.exec(g.trim());if(!A)return null;const I=Number(A[1]);if(!Number.isSafeInteger(I))return null;const e=`C${A[1]}`;return{source:"jlcpcb",component:{lcscId:I,manufacturer:e,partNumber:e,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},$PI=(g,A)=>{const I=ASo(g);return I?A.some(t=>t.component.partNumber.toUpperCase()===I.component.partNumber)?A:[I,...A]:A},gSo=g=>{const A=g.trim();return/^C\d+/i.test(A)?A.replace(/^C/i,""):A},ISo=()=>{const[g,A]=z.useState([]),[I,e]=z.useState(!1),[t,o]=z.useState(null),[B,C]=z.useState(!1),Q=z.useCallback(async E=>{const n=gSo(E);if(!n)return[];e(!0),o(null);try{const s=await qko(n,10),r=$PI(E,s.map(a=>({source:"jlcpcb",component:Zko(a)})));return A(r),r}catch(s){console.error("Error searching JLCPCB components",s);const r=$PI(E,[]);return A(r),o(r.length>0?null:s instanceof Error?s.message:"Failed to search JLCPCB components"),r}finally{e(!1),C(!0)}},[]),i=z.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},eSo=()=>{const[g,A]=z.useState([]),[I,e]=z.useState(!1),[t,o]=z.useState(null),[B,C]=z.useState(!1),Q=z.useCallback(async E=>{const n=E.trim();if(!n)return[];e(!0),o(null);try{const r=(await PMo(n,20)).map(a=>({source:"kicad",footprint:KMo(a)}));return A(r),r}catch(s){return console.error("Error searching KiCad footprints",s),A([]),o(s instanceof Error?s.message:"Failed to search KiCad footprints"),[]}finally{e(!1),C(!0)}},[]),i=z.useCallback(()=>{A([]),e(!1),o(null),C(!1)},[]);return{results:g,isSearching:I,error:t,hasSearched:B,search:Q,reset:i}},tSo=({onTscircuitPackageSelected:g,onJlcpcbComponentTsxLoaded:A,onKicadStringSelected:I})=>{const e=[];return g&&e.push("tscircuit.com"),A&&e.push("jlcpcb"),I&&e.push("kicad"),e},oSo=({isOpen:g,onClose:A,jlcpcbProxyRequestHeaders:I,onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o,jlcpcbProxyApiBase:B,tscircuitSessionToken:C})=>{BoA();const Q=z.useMemo(()=>tSo({onKicadStringSelected:e,onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:o}),[e,t,o]),i=Q.length>0,E=Q.length===1,[n,s]=z.useState(Q[0]??"tscircuit.com"),[r,a]=z.useState(""),[c,h]=z.useState(null),{results:l,isSearching:D,error:d,hasSearched:y,search:w,reset:u}=$Mo({sessionToken:C}),{results:G,isSearching:m,error:p,hasSearched:k,search:S,reset:R}=ISo(),{results:x,isSearching:N,error:U,hasSearched:K,search:Y,reset:_}=eSo(),{details:q,isLoading:j,fetchDetails:W,reset:Z}=jMo(),[$,eA]=z.useState(null),[IA,QA]=z.useState(!1),[sA,lA]=z.useState("pcb"),[BA,hA]=z.useState(null),[nA,aA]=z.useState(!1),SA=z.useMemo(()=>({jlcpcb:{headers:I,apiBase:B}}),[B,I]),{circuitJson:FA,error:rA,isLoading:xA}=zMo(c,SA),NA=jPI(c);z.useEffect(()=>{hA(null)},[c]);const RA=z.useCallback(()=>{u(),R(),_(),h(null)},[R,_,u]);z.useEffect(()=>{g||(RA(),a(""),QA(!1),eA(null),hA(null))},[g,RA]),z.useEffect(()=>{a(""),h(null),n==="tscircuit.com"?u():n==="jlcpcb"?R():n==="kicad"&&_()},[n,R,_,u]);const HA=kA=>{h(kA),eA(kA),lA("pcb"),QA(!0),Z();const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(OA&&$A){const og=$A.split("/").pop()??$A;W(OA,og)}},KA=async()=>{r.trim()&&(h(null),n==="tscircuit.com"?await w(r):n==="jlcpcb"?await S(r):n==="kicad"&&await Y(r))},mA=async kA=>{try{if(hA(null),aA(!0),kA.source==="kicad"){if(!e)throw new Error("KiCad handler not provided");await e({result:kA,footprint:kA.footprint.qualifiedName})}else if(kA.source==="jlcpcb"){if(!o)throw new Error("JLCPCB handler not provided");const OA=await Oko(kA.component.partNumber,{headers:I,apiBase:B});await o({result:kA,tsx:OA})}else if(kA.source==="tscircuit.com"){if(!t)throw new Error("tscircuit package handler not provided");const OA=kA.package.org_owner_tscircuit_handle,$A=kA.package.unscoped_name;if(!OA||!$A)throw new Error("Missing package metadata");const og=$A.split("/").pop()??$A,dg=`@tsci/${OA}.${og}`;await t({result:kA,fullPackageName:dg})}return!0}catch(OA){return console.error("Failed to import component",OA),hA(OA instanceof Error?OA.message:"Failed to import component"),!1}finally{aA(!1)}};let JA=[],dA=!1,bA=null,WA=!1;n==="tscircuit.com"?(JA=l,dA=D,bA=d,WA=y):n==="jlcpcb"?(JA=G,dA=m,bA=p,WA=k):n==="kicad"&&(JA=x,dA=N,bA=U,WA=K);const Qg=async()=>{if(!c)return;await mA(c)&&(A(),RA(),a(""))},YA=kA=>{kA||A()},uA=kA=>{QA(kA),kA||eA(null)};return T.jsxs(Yb,{open:g,onOpenChange:YA,children:[T.jsxs(NL,{style:{width:"calc(100vw - 2rem)",maxWidth:NA?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:XPI.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[T.jsxs(xL,{children:[T.jsxs(FL,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",E?CpA[n].label:""," ","Component"]}),T.jsx(_b,{className:"rf-text-sm",children:i?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),i?T.jsxs(OvA,{value:n,onValueChange:kA=>s(kA),className:"rf-min-w-0 rf-w-full",children:[!E&&T.jsx(PDA,{className:"rf-flex rf-w-full rf-gap-2",children:Q.map(kA=>T.jsx(mx,{value:kA,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:CpA[kA].label},kA))}),T.jsxs("div",{className:"rf-min-w-0",style:NA?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[T.jsxs("div",{className:"rf-min-w-0",children:[T.jsx(bMo,{query:r,placeholder:CpA[n].placeholder,isSearching:dA,onQueryChange:a,onSubmit:KA}),T.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:dA?T.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[T.jsx(kS,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),T.jsx("p",{children:"Searching..."})]}):JA.length>0?T.jsx(OMo,{results:JA,selected:c,onSelect:h,onShowDetails:n==="tscircuit.com"?HA:void 0}):T.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:bA?`Error: ${bA}`:WA?CpA[n].emptyMessage:"Enter a search term to find components"})})]}),NA?T.jsx("div",{className:"rf-mt-4",children:T.jsx(WMo,{circuitJson:FA,error:rA,isLoading:xA,height:325})}):null]})]}):null,BA?T.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:BA}):null,T.jsxs(YO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[T.jsx(si,{variant:"outline",onClick:A,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),T.jsx(si,{onClick:Qg,disabled:!c||nA,className:"rf-order-1 sm:rf-order-2",children:nA?T.jsx(kS,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),T.jsx(VMo,{packageResult:$,isOpen:IA,onOpenChange:uA,isLoading:j,details:q,previewTab:sA,onPreviewTabChange:kA=>lA(kA),isSubmitting:nA,onImport:()=>{$&&mA($).then(kA=>{kA&&(QA(!1),A(),RA(),a(""))})}})]})},BSo=g=>{const A=g.match(/export const (\w+) =/);if(!A)throw new Error("Could not determine component name from TSX contents");return A[1]},A4I=g=>{const A=Jc(B=>B.pushEvent),I=Jc(B=>B.upsertFile),e=async({result:B,fullPackageName:C})=>{const i=B.package.unscoped_name??B.package.name;await KC.promise(A({event_type:"INSTALL_PACKAGE",full_package_name:C}),{loading:`Requesting install for "${i}"`,success:`Install requested for "${i}"`,error:E=>`Failed to request install: ${E instanceof Error?E.message:String(E)}`})},t=async({footprint:B})=>{await KC.promise(navigator.clipboard.writeText(B),{loading:`Copying "${B}"`,success:`Copied "${B}" to clipboard`,error:C=>`Failed to copy footprint: ${C instanceof Error?C.message:String(C)}`})},o=async({result:B,tsx:C})=>{const i=`imports/${BSo(C)}.tsx`;await KC.promise(I(i,C),{loading:`Importing ${B.component.partNumber}`,success:`Imported to "${i}"`,error:E=>`Failed to import component: ${E instanceof Error?E.message:String(E)}`})};return T.jsx(oSo,{...g,onTscircuitPackageSelected:e,onKicadStringSelected:t,onJlcpcbComponentTsxLoaded:o})};A4I.displayName="ImportComponentDialogForCli";const CSo=async({circuitJson:g,projectName:A})=>{const{convertCircuitJsonToAltiumZip:I}=await Promise.resolve().then(()=>MTo),e=await I(g,A);return new Blob([new Uint8Array(e)],{type:"application/zip"})},QSo=async({circuitJson:g,projectName:A})=>{await KC.promise((async()=>{const I=await CSo({circuitJson:g,projectName:A});_k(I,{fileName:`${A}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:I=>`Failed to generate Altium project: ${I instanceof Error?I.message:String(I)}`})};var XCg={exports:{}},g4I;function iSo(){return g4I||(g4I=1,(function(g,A){var I={env:{},version:""};(function(e){g.exports=e()})(function(){return(function e(t,o,B){function C(E,n){if(!o[E]){if(!t[E]){var s=typeof rU=="function"&&rU;if(!n&&s)return s(E,!0);if(Q)return Q(E,!0);var r=new Error("Cannot find module '"+E+"'");throw r.code="MODULE_NOT_FOUND",r}var a=o[E]={exports:{}};t[E][0].call(a.exports,function(c){var h=t[E][1][c];return C(h||c)},a,a.exports,e,t,o,B)}return o[E].exports}for(var Q=typeof rU=="function"&&rU,i=0;i<B.length;i++)C(B[i]);return C})({1:[function(e,t,o){var B=e("./utils"),C=e("./support"),Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";o.encode=function(i){for(var E,n,s,r,a,c,h,l=[],D=0,d=i.length,y=d,w=B.getTypeOf(i)!=="string";D<i.length;)y=d-D,s=w?(E=i[D++],n=D<d?i[D++]:0,D<d?i[D++]:0):(E=i.charCodeAt(D++),n=D<d?i.charCodeAt(D++):0,D<d?i.charCodeAt(D++):0),r=E>>2,a=(3&E)<<4|n>>4,c=1<y?(15&n)<<2|s>>6:64,h=2<y?63&s:64,l.push(Q.charAt(r)+Q.charAt(a)+Q.charAt(c)+Q.charAt(h));return l.join("")},o.decode=function(i){var E,n,s,r,a,c,h=0,l=0,D="data:";if(i.substr(0,D.length)===D)throw new Error("Invalid base64 input, it looks like a data url.");var d,y=3*(i=i.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(i.charAt(i.length-1)===Q.charAt(64)&&y--,i.charAt(i.length-2)===Q.charAt(64)&&y--,y%1!=0)throw new Error("Invalid base64 input, bad content length.");for(d=C.uint8array?new Uint8Array(0|y):new Array(0|y);h<i.length;)E=Q.indexOf(i.charAt(h++))<<2|(r=Q.indexOf(i.charAt(h++)))>>4,n=(15&r)<<4|(a=Q.indexOf(i.charAt(h++)))>>2,s=(3&a)<<6|(c=Q.indexOf(i.charAt(h++))),d[l++]=E,a!==64&&(d[l++]=n),c!==64&&(d[l++]=s);return d}},{"./support":30,"./utils":32}],2:[function(e,t,o){var B=e("./external"),C=e("./stream/DataWorker"),Q=e("./stream/Crc32Probe"),i=e("./stream/DataLengthProbe");function E(n,s,r,a,c){this.compressedSize=n,this.uncompressedSize=s,this.crc32=r,this.compression=a,this.compressedContent=c}E.prototype={getContentWorker:function(){var n=new C(B.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new i("data_length")),s=this;return n.on("end",function(){if(this.streamInfo.data_length!==s.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),n},getCompressedWorker:function(){return new C(B.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},E.createWorkerFrom=function(n,s,r){return n.pipe(new Q).pipe(new i("uncompressedSize")).pipe(s.compressWorker(r)).pipe(new i("compressedSize")).withStreamInfo("compression",s)},t.exports=E},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(e,t,o){var B=e("./stream/GenericWorker");o.STORE={magic:"\0\0",compressWorker:function(){return new B("STORE compression")},uncompressWorker:function(){return new B("STORE decompression")}},o.DEFLATE=e("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(e,t,o){var B=e("./utils"),C=(function(){for(var Q,i=[],E=0;E<256;E++){Q=E;for(var n=0;n<8;n++)Q=1&Q?3988292384^Q>>>1:Q>>>1;i[E]=Q}return i})();t.exports=function(Q,i){return Q!==void 0&&Q.length?B.getTypeOf(Q)!=="string"?(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n[h])];return-1^E})(0|i,Q,Q.length,0):(function(E,n,s,r){var a=C,c=r+s;E^=-1;for(var h=r;h<c;h++)E=E>>>8^a[255&(E^n.charCodeAt(h))];return-1^E})(0|i,Q,Q.length,0):0}},{"./utils":32}],5:[function(e,t,o){o.base64=!1,o.binary=!1,o.dir=!1,o.createFolders=!0,o.date=null,o.compression=null,o.compressionOptions=null,o.comment=null,o.unixPermissions=null,o.dosPermissions=null},{}],6:[function(e,t,o){var B=null;B=typeof Promise<"u"?Promise:e("lie"),t.exports={Promise:B}},{lie:37}],7:[function(e,t,o){var B=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",C=e("pako"),Q=e("./utils"),i=e("./stream/GenericWorker"),E=B?"uint8array":"array";function n(s,r){i.call(this,"FlateWorker/"+s),this._pako=null,this._pakoAction=s,this._pakoOptions=r,this.meta={}}o.magic="\b\0",Q.inherits(n,i),n.prototype.processChunk=function(s){this.meta=s.meta,this._pako===null&&this._createPako(),this._pako.push(Q.transformTo(E,s.data),!1)},n.prototype.flush=function(){i.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},n.prototype.cleanUp=function(){i.prototype.cleanUp.call(this),this._pako=null},n.prototype._createPako=function(){this._pako=new C[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var s=this;this._pako.onData=function(r){s.push({data:r,meta:s.meta})}},o.compressWorker=function(s){return new n("Deflate",s)},o.uncompressWorker=function(){return new n("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(e,t,o){function B(a,c){var h,l="";for(h=0;h<c;h++)l+=String.fromCharCode(255&a),a>>>=8;return l}function C(a,c,h,l,D,d){var y,w,u=a.file,G=a.compression,m=d!==E.utf8encode,p=Q.transformTo("string",d(u.name)),k=Q.transformTo("string",E.utf8encode(u.name)),S=u.comment,R=Q.transformTo("string",d(S)),x=Q.transformTo("string",E.utf8encode(S)),N=k.length!==u.name.length,U=x.length!==S.length,K="",Y="",_="",q=u.dir,j=u.date,W={crc32:0,compressedSize:0,uncompressedSize:0};c&&!h||(W.crc32=a.crc32,W.compressedSize=a.compressedSize,W.uncompressedSize=a.uncompressedSize);var Z=0;c&&(Z|=8),m||!N&&!U||(Z|=2048);var $=0,eA=0;q&&($|=16),D==="UNIX"?(eA=798,$|=(function(QA,sA){var lA=QA;return QA||(lA=sA?16893:33204),(65535&lA)<<16})(u.unixPermissions,q)):(eA=20,$|=(function(QA){return 63&(QA||0)})(u.dosPermissions)),y=j.getUTCHours(),y<<=6,y|=j.getUTCMinutes(),y<<=5,y|=j.getUTCSeconds()/2,w=j.getUTCFullYear()-1980,w<<=4,w|=j.getUTCMonth()+1,w<<=5,w|=j.getUTCDate(),N&&(Y=B(1,1)+B(n(p),4)+k,K+="up"+B(Y.length,2)+Y),U&&(_=B(1,1)+B(n(R),4)+x,K+="uc"+B(_.length,2)+_);var IA="";return IA+=`
5671
5671
  \0`,IA+=B(Z,2),IA+=G.magic,IA+=B(y,2),IA+=B(w,2),IA+=B(W.crc32,4),IA+=B(W.compressedSize,4),IA+=B(W.uncompressedSize,4),IA+=B(p.length,2),IA+=B(K.length,2),{fileRecord:s.LOCAL_FILE_HEADER+IA+p+K,dirRecord:s.CENTRAL_FILE_HEADER+B(eA,2)+IA+B(R.length,2)+"\0\0\0\0"+B($,4)+B(l,4)+p+K+R}}var Q=e("../utils"),i=e("../stream/GenericWorker"),E=e("../utf8"),n=e("../crc32"),s=e("../signature");function r(a,c,h,l){i.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=c,this.zipPlatform=h,this.encodeFileName=l,this.streamFiles=a,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}Q.inherits(r,i),r.prototype.push=function(a){var c=a.meta.percent||0,h=this.entriesCount,l=this._sources.length;this.accumulate?this.contentBuffer.push(a):(this.bytesWritten+=a.data.length,i.prototype.push.call(this,{data:a.data,meta:{currentFile:this.currentFile,percent:h?(c+100*(h-l-1))/h:100}}))},r.prototype.openedSource=function(a){this.currentSourceOffset=this.bytesWritten,this.currentFile=a.file.name;var c=this.streamFiles&&!a.file.dir;if(c){var h=C(a,c,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:h.fileRecord,meta:{percent:0}})}else this.accumulate=!0},r.prototype.closedSource=function(a){this.accumulate=!1;var c=this.streamFiles&&!a.file.dir,h=C(a,c,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(h.dirRecord),c)this.push({data:(function(l){return s.DATA_DESCRIPTOR+B(l.crc32,4)+B(l.compressedSize,4)+B(l.uncompressedSize,4)})(a),meta:{percent:100}});else for(this.push({data:h.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},r.prototype.flush=function(){for(var a=this.bytesWritten,c=0;c<this.dirRecords.length;c++)this.push({data:this.dirRecords[c],meta:{percent:100}});var h=this.bytesWritten-a,l=(function(D,d,y,w,u){var G=Q.transformTo("string",u(w));return s.CENTRAL_DIRECTORY_END+"\0\0\0\0"+B(D,2)+B(D,2)+B(d,4)+B(y,4)+B(G.length,2)+G})(this.dirRecords.length,h,a,this.zipComment,this.encodeFileName);this.push({data:l,meta:{percent:100}})},r.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},r.prototype.registerPrevious=function(a){this._sources.push(a);var c=this;return a.on("data",function(h){c.processChunk(h)}),a.on("end",function(){c.closedSource(c.previous.streamInfo),c._sources.length?c.prepareNextSource():c.end()}),a.on("error",function(h){c.error(h)}),this},r.prototype.resume=function(){return!!i.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},r.prototype.error=function(a){var c=this._sources;if(!i.prototype.error.call(this,a))return!1;for(var h=0;h<c.length;h++)try{c[h].error(a)}catch{}return!0},r.prototype.lock=function(){i.prototype.lock.call(this);for(var a=this._sources,c=0;c<a.length;c++)a[c].lock()},t.exports=r},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(e,t,o){var B=e("../compressions"),C=e("./ZipFileWorker");o.generateWorker=function(Q,i,E){var n=new C(i.streamFiles,E,i.platform,i.encodeFileName),s=0;try{Q.forEach(function(r,a){s++;var c=(function(d,y){var w=d||y,u=B[w];if(!u)throw new Error(w+" is not a valid compression method !");return u})(a.options.compression,i.compression),h=a.options.compressionOptions||i.compressionOptions||{},l=a.dir,D=a.date;a._compressWorker(c,h).withStreamInfo("file",{name:r,dir:l,date:D,comment:a.comment||"",unixPermissions:a.unixPermissions,dosPermissions:a.dosPermissions}).pipe(n)}),n.entriesCount=s}catch(r){n.error(r)}return n}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(e,t,o){function B(){if(!(this instanceof B))return new B;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var C=new B;for(var Q in this)typeof this[Q]!="function"&&(C[Q]=this[Q]);return C}}(B.prototype=e("./object")).loadAsync=e("./load"),B.support=e("./support"),B.defaults=e("./defaults"),B.version="3.10.2",B.loadAsync=function(C,Q){return new B().loadAsync(C,Q)},B.external=e("./external"),t.exports=B},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(e,t,o){var B=e("./utils"),C=e("./external"),Q=e("./utf8"),i=e("./zipEntries"),E=e("./stream/Crc32Probe"),n=e("./nodejsUtils");function s(r){return new C.Promise(function(a,c){var h=r.decompressed.getContentWorker().pipe(new E);h.on("error",function(l){c(l)}).on("end",function(){h.streamInfo.crc32!==r.decompressed.crc32?c(new Error("Corrupted zip : CRC32 mismatch")):a()}).resume()})}t.exports=function(r,a){var c=this;return a=B.extend(a||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:Q.utf8decode}),n.isNode&&n.isStream(r)?C.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):B.prepareContent("the loaded zip file",r,!0,a.optimizedBinaryString,a.base64).then(function(h){var l=new i(a);return l.load(h),l}).then(function(h){var l=[C.Promise.resolve(h)],D=h.files;if(a.checkCRC32)for(var d=0;d<D.length;d++)l.push(s(D[d]));return C.Promise.all(l)}).then(function(h){for(var l=h.shift(),D=l.files,d=0;d<D.length;d++){var y=D[d],w=y.fileNameStr,u=B.resolve(y.fileNameStr);c.file(u,y.decompressed,{binary:!0,optimizedBinaryString:!0,date:y.date,dir:y.dir,comment:y.fileCommentStr.length?y.fileCommentStr:null,unixPermissions:y.unixPermissions,dosPermissions:y.dosPermissions,createFolders:a.createFolders}),y.dir||(c.file(u).unsafeOriginalName=w)}return l.zipComment.length&&(c.comment=l.zipComment),c})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(e,t,o){var B=e("../utils"),C=e("../stream/GenericWorker");function Q(i,E){C.call(this,"Nodejs stream input adapter for "+i),this._upstreamEnded=!1,this._bindStream(E)}B.inherits(Q,C),Q.prototype._bindStream=function(i){var E=this;(this._stream=i).pause(),i.on("data",function(n){E.push({data:n,meta:{percent:0}})}).on("error",function(n){E.isPaused?this.generatedError=n:E.error(n)}).on("end",function(){E.isPaused?E._upstreamEnded=!0:E.end()})},Q.prototype.pause=function(){return!!C.prototype.pause.call(this)&&(this._stream.pause(),!0)},Q.prototype.resume=function(){return!!C.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},t.exports=Q},{"../stream/GenericWorker":28,"../utils":32}],13:[function(e,t,o){var B=e("readable-stream").Readable;function C(Q,i,E){B.call(this,i),this._helper=Q;var n=this;Q.on("data",function(s,r){n.push(s)||n._helper.pause(),E&&E(r)}).on("error",function(s){n.emit("error",s)}).on("end",function(){n.push(null)})}e("../utils").inherits(C,B),C.prototype._read=function(){this._helper.resume()},t.exports=C},{"../utils":32,"readable-stream":16}],14:[function(e,t,o){t.exports={isNode:typeof Buffer<"u",newBufferFrom:function(B,C){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(B,C);if(typeof B=="number")throw new Error('The "data" argument must not be a number');return new Buffer(B,C)},allocBuffer:function(B){if(Buffer.alloc)return Buffer.alloc(B);var C=new Buffer(B);return C.fill(0),C},isBuffer:function(B){return Buffer.isBuffer(B)},isStream:function(B){return B&&typeof B.on=="function"&&typeof B.pause=="function"&&typeof B.resume=="function"}}},{}],15:[function(e,t,o){function B(u,G,m){var p,k=Q.getTypeOf(G),S=Q.extend(m||{},n);S.date=S.date||new Date,S.compression!==null&&(S.compression=S.compression.toUpperCase()),typeof S.unixPermissions=="string"&&(S.unixPermissions=parseInt(S.unixPermissions,8)),S.unixPermissions&&16384&S.unixPermissions&&(S.dir=!0),S.dosPermissions&&16&S.dosPermissions&&(S.dir=!0),S.dir&&(u=D(u)),S.createFolders&&(p=l(u))&&d.call(this,p,!0);var R=k==="string"&&S.binary===!1&&S.base64===!1;m&&m.binary!==void 0||(S.binary=!R),(G instanceof s&&G.uncompressedSize===0||S.dir||!G||G.length===0)&&(S.base64=!1,S.binary=!0,G="",S.compression="STORE",k="string");var x=null;x=G instanceof s||G instanceof i?G:c.isNode&&c.isStream(G)?new h(u,G):Q.prepareContent(u,G,S.binary,S.optimizedBinaryString,S.base64);var N=new r(u,x,S);this.files[u]=N}var C=e("./utf8"),Q=e("./utils"),i=e("./stream/GenericWorker"),E=e("./stream/StreamHelper"),n=e("./defaults"),s=e("./compressedObject"),r=e("./zipObject"),a=e("./generate"),c=e("./nodejsUtils"),h=e("./nodejs/NodejsStreamInputAdapter"),l=function(u){u.slice(-1)==="/"&&(u=u.substring(0,u.length-1));var G=u.lastIndexOf("/");return 0<G?u.substring(0,G):""},D=function(u){return u.slice(-1)!=="/"&&(u+="/"),u},d=function(u,G){return G=G!==void 0?G:n.createFolders,u=D(u),this.files[u]||B.call(this,u,null,{dir:!0,createFolders:G}),this.files[u]};function y(u){return Object.prototype.toString.call(u)==="[object RegExp]"}var w={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(u){var G,m,p;for(G in this.files)p=this.files[G],(m=G.slice(this.root.length,G.length))&&G.slice(0,this.root.length)===this.root&&u(m,p)},filter:function(u){var G=[];return this.forEach(function(m,p){u(m,p)&&G.push(p)}),G},file:function(u,G,m){if(arguments.length!==1)return u=this.root+u,B.call(this,u,G,m),this;if(y(u)){var p=u;return this.filter(function(S,R){return!R.dir&&p.test(S)})}var k=this.files[this.root+u];return k&&!k.dir?k:null},folder:function(u){if(!u)return this;if(y(u))return this.filter(function(k,S){return S.dir&&u.test(k)});var G=this.root+u,m=d.call(this,G),p=this.clone();return p.root=m.name,p},remove:function(u){u=this.root+u;var G=this.files[u];if(G||(u.slice(-1)!=="/"&&(u+="/"),G=this.files[u]),G&&!G.dir)delete this.files[u];else for(var m=this.filter(function(k,S){return S.name.slice(0,u.length)===u}),p=0;p<m.length;p++)delete this.files[m[p].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(u){var G,m={};try{if((m=Q.extend(u||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:C.utf8encode})).type=m.type.toLowerCase(),m.compression=m.compression.toUpperCase(),m.type==="binarystring"&&(m.type="string"),!m.type)throw new Error("No output type specified.");Q.checkSupport(m.type),m.platform!=="darwin"&&m.platform!=="freebsd"&&m.platform!=="linux"&&m.platform!=="sunos"||(m.platform="UNIX"),m.platform==="win32"&&(m.platform="DOS");var p=m.comment||this.comment||"";G=a.generateWorker(this,m,p)}catch(k){(G=new i("error")).error(k)}return new E(G,m.type||"string",m.mimeType)},generateAsync:function(u,G){return this.generateInternalStream(u).accumulate(G)},generateNodeStream:function(u,G){return(u=u||{}).type||(u.type="nodebuffer"),this.generateInternalStream(u).toNodejsStream(G)}};t.exports=w},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(e,t,o){t.exports=e("stream")},{stream:void 0}],17:[function(e,t,o){var B=e("./DataReader");function C(Q){B.call(this,Q);for(var i=0;i<this.data.length;i++)Q[i]=255&Q[i]}e("../utils").inherits(C,B),C.prototype.byteAt=function(Q){return this.data[this.zero+Q]},C.prototype.lastIndexOfSignature=function(Q){for(var i=Q.charCodeAt(0),E=Q.charCodeAt(1),n=Q.charCodeAt(2),s=Q.charCodeAt(3),r=this.length-4;0<=r;--r)if(this.data[r]===i&&this.data[r+1]===E&&this.data[r+2]===n&&this.data[r+3]===s)return r-this.zero;return-1},C.prototype.readAndCheckSignature=function(Q){var i=Q.charCodeAt(0),E=Q.charCodeAt(1),n=Q.charCodeAt(2),s=Q.charCodeAt(3),r=this.readData(4);return i===r[0]&&E===r[1]&&n===r[2]&&s===r[3]},C.prototype.readData=function(Q){if(this.checkOffset(Q),Q===0)return[];var i=this.data.slice(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./DataReader":18}],18:[function(e,t,o){var B=e("../utils");function C(Q){this.data=Q,this.length=Q.length,this.index=0,this.zero=0}C.prototype={checkOffset:function(Q){this.checkIndex(this.index+Q)},checkIndex:function(Q){if(this.length<this.zero+Q||Q<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+Q+"). Corrupted zip ?")},setIndex:function(Q){this.checkIndex(Q),this.index=Q},skip:function(Q){this.setIndex(this.index+Q)},byteAt:function(){},readInt:function(Q){var i,E=0;for(this.checkOffset(Q),i=this.index+Q-1;i>=this.index;i--)E=(E<<8)+this.byteAt(i);return this.index+=Q,E},readString:function(Q){return B.transformTo("string",this.readData(Q))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var Q=this.readInt(4);return new Date(Date.UTC(1980+(Q>>25&127),(Q>>21&15)-1,Q>>16&31,Q>>11&31,Q>>5&63,(31&Q)<<1))}},t.exports=C},{"../utils":32}],19:[function(e,t,o){var B=e("./Uint8ArrayReader");function C(Q){B.call(this,Q)}e("../utils").inherits(C,B),C.prototype.readData=function(Q){this.checkOffset(Q);var i=this.data.slice(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(e,t,o){var B=e("./DataReader");function C(Q){B.call(this,Q)}e("../utils").inherits(C,B),C.prototype.byteAt=function(Q){return this.data.charCodeAt(this.zero+Q)},C.prototype.lastIndexOfSignature=function(Q){return this.data.lastIndexOf(Q)-this.zero},C.prototype.readAndCheckSignature=function(Q){return Q===this.readData(4)},C.prototype.readData=function(Q){this.checkOffset(Q);var i=this.data.slice(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./DataReader":18}],21:[function(e,t,o){var B=e("./ArrayReader");function C(Q){B.call(this,Q)}e("../utils").inherits(C,B),C.prototype.readData=function(Q){if(this.checkOffset(Q),Q===0)return new Uint8Array(0);var i=this.data.subarray(this.zero+this.index,this.zero+this.index+Q);return this.index+=Q,i},t.exports=C},{"../utils":32,"./ArrayReader":17}],22:[function(e,t,o){var B=e("../utils"),C=e("../support"),Q=e("./ArrayReader"),i=e("./StringReader"),E=e("./NodeBufferReader"),n=e("./Uint8ArrayReader");t.exports=function(s){var r=B.getTypeOf(s);return B.checkSupport(r),r!=="string"||C.uint8array?r==="nodebuffer"?new E(s):C.uint8array?new n(B.transformTo("uint8array",s)):new Q(B.transformTo("array",s)):new i(s)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(e,t,o){o.LOCAL_FILE_HEADER="PK",o.CENTRAL_FILE_HEADER="PK",o.CENTRAL_DIRECTORY_END="PK",o.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",o.ZIP64_CENTRAL_DIRECTORY_END="PK",o.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(e,t,o){var B=e("./GenericWorker"),C=e("../utils");function Q(i){B.call(this,"ConvertWorker to "+i),this.destType=i}C.inherits(Q,B),Q.prototype.processChunk=function(i){this.push({data:C.transformTo(this.destType,i.data),meta:i.meta})},t.exports=Q},{"../utils":32,"./GenericWorker":28}],25:[function(e,t,o){var B=e("./GenericWorker"),C=e("../crc32");function Q(){B.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}e("../utils").inherits(Q,B),Q.prototype.processChunk=function(i){this.streamInfo.crc32=C(i.data,this.streamInfo.crc32||0),this.push(i)},t.exports=Q},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(e,t,o){var B=e("../utils"),C=e("./GenericWorker");function Q(i){C.call(this,"DataLengthProbe for "+i),this.propName=i,this.withStreamInfo(i,0)}B.inherits(Q,C),Q.prototype.processChunk=function(i){if(i){var E=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=E+i.data.length}C.prototype.processChunk.call(this,i)},t.exports=Q},{"../utils":32,"./GenericWorker":28}],27:[function(e,t,o){var B=e("../utils"),C=e("./GenericWorker");function Q(i){C.call(this,"DataWorker");var E=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,i.then(function(n){E.dataIsReady=!0,E.data=n,E.max=n&&n.length||0,E.type=B.getTypeOf(n),E.isPaused||E._tickAndRepeat()},function(n){E.error(n)})}B.inherits(Q,C),Q.prototype.cleanUp=function(){C.prototype.cleanUp.call(this),this.data=null},Q.prototype.resume=function(){return!!C.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,B.delay(this._tickAndRepeat,[],this)),!0)},Q.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(B.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},Q.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var i=null,E=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":i=this.data.substring(this.index,E);break;case"uint8array":i=this.data.subarray(this.index,E);break;case"array":case"nodebuffer":i=this.data.slice(this.index,E)}return this.index=E,this.push({data:i,meta:{percent:this.max?this.index/this.max*100:0}})},t.exports=Q},{"../utils":32,"./GenericWorker":28}],28:[function(e,t,o){function B(C){this.name=C||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}B.prototype={push:function(C){this.emit("data",C)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(C){this.emit("error",C)}return!0},error:function(C){return!this.isFinished&&(this.isPaused?this.generatedError=C:(this.isFinished=!0,this.emit("error",C),this.previous&&this.previous.error(C),this.cleanUp()),!0)},on:function(C,Q){return this._listeners[C].push(Q),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(C,Q){if(this._listeners[C])for(var i=0;i<this._listeners[C].length;i++)this._listeners[C][i].call(this,Q)},pipe:function(C){return C.registerPrevious(this)},registerPrevious:function(C){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=C.streamInfo,this.mergeStreamInfo(),this.previous=C;var Q=this;return C.on("data",function(i){Q.processChunk(i)}),C.on("end",function(){Q.end()}),C.on("error",function(i){Q.error(i)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var C=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),C=!0),this.previous&&this.previous.resume(),!C},flush:function(){},processChunk:function(C){this.push(C)},withStreamInfo:function(C,Q){return this.extraStreamInfo[C]=Q,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var C in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,C)&&(this.streamInfo[C]=this.extraStreamInfo[C])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var C="Worker "+this.name;return this.previous?this.previous+" -> "+C:C}},t.exports=B},{}],29:[function(e,t,o){var B=e("../utils"),C=e("./ConvertWorker"),Q=e("./GenericWorker"),i=e("../base64"),E=e("../support"),n=e("../external"),s=null;if(E.nodestream)try{s=e("../nodejs/NodejsStreamOutputAdapter")}catch{}function r(c,h){return new n.Promise(function(l,D){var d=[],y=c._internalType,w=c._outputType,u=c._mimeType;c.on("data",function(G,m){d.push(G),h&&h(m)}).on("error",function(G){d=[],D(G)}).on("end",function(){try{var G=(function(m,p,k){switch(m){case"blob":return B.newBlob(B.transformTo("arraybuffer",p),k);case"base64":return i.encode(p);default:return B.transformTo(m,p)}})(w,(function(m,p){var k,S=0,R=null,x=0;for(k=0;k<p.length;k++)x+=p[k].length;switch(m){case"string":return p.join("");case"array":return Array.prototype.concat.apply([],p);case"uint8array":for(R=new Uint8Array(x),k=0;k<p.length;k++)R.set(p[k],S),S+=p[k].length;return R;case"nodebuffer":return Buffer.concat(p);default:throw new Error("concat : unsupported type '"+m+"'")}})(y,d),u);l(G)}catch(m){D(m)}d=[]}).resume()})}function a(c,h,l){var D=h;switch(h){case"blob":case"arraybuffer":D="uint8array";break;case"base64":D="string"}try{this._internalType=D,this._outputType=h,this._mimeType=l,B.checkSupport(D),this._worker=c.pipe(new C(D)),c.lock()}catch(d){this._worker=new Q("error"),this._worker.error(d)}}a.prototype={accumulate:function(c){return r(this,c)},on:function(c,h){var l=this;return c==="data"?this._worker.on(c,function(D){h.call(l,D.data,D.meta)}):this._worker.on(c,function(){B.delay(h,arguments,l)}),this},resume:function(){return B.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(c){if(B.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new s(this,{objectMode:this._outputType!=="nodebuffer"},c)}},t.exports=a},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(e,t,o){if(o.base64=!0,o.array=!0,o.string=!0,o.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",o.nodebuffer=typeof Buffer<"u",o.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")o.blob=!1;else{var B=new ArrayBuffer(0);try{o.blob=new Blob([B],{type:"application/zip"}).size===0}catch{try{var C=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);C.append(B),o.blob=C.getBlob("application/zip").size===0}catch{o.blob=!1}}}try{o.nodestream=!!e("readable-stream").Readable}catch{o.nodestream=!1}},{"readable-stream":16}],31:[function(e,t,o){for(var B=e("./utils"),C=e("./support"),Q=e("./nodejsUtils"),i=e("./stream/GenericWorker"),E=new Array(256),n=0;n<256;n++)E[n]=252<=n?6:248<=n?5:240<=n?4:224<=n?3:192<=n?2:1;E[254]=E[254]=1;function s(){i.call(this,"utf-8 decode"),this.leftOver=null}function r(){i.call(this,"utf-8 encode")}o.utf8encode=function(a){return C.nodebuffer?Q.newBufferFrom(a,"utf-8"):(function(c){var h,l,D,d,y,w=c.length,u=0;for(d=0;d<w;d++)(64512&(l=c.charCodeAt(d)))==55296&&d+1<w&&(64512&(D=c.charCodeAt(d+1)))==56320&&(l=65536+(l-55296<<10)+(D-56320),d++),u+=l<128?1:l<2048?2:l<65536?3:4;for(h=C.uint8array?new Uint8Array(u):new Array(u),d=y=0;y<u;d++)(64512&(l=c.charCodeAt(d)))==55296&&d+1<w&&(64512&(D=c.charCodeAt(d+1)))==56320&&(l=65536+(l-55296<<10)+(D-56320),d++),l<128?h[y++]=l:(l<2048?h[y++]=192|l>>>6:(l<65536?h[y++]=224|l>>>12:(h[y++]=240|l>>>18,h[y++]=128|l>>>12&63),h[y++]=128|l>>>6&63),h[y++]=128|63&l);return h})(a)},o.utf8decode=function(a){return C.nodebuffer?B.transformTo("nodebuffer",a).toString("utf-8"):(function(c){var h,l,D,d,y=c.length,w=new Array(2*y);for(h=l=0;h<y;)if((D=c[h++])<128)w[l++]=D;else if(4<(d=E[D]))w[l++]=65533,h+=d-1;else{for(D&=d===2?31:d===3?15:7;1<d&&h<y;)D=D<<6|63&c[h++],d--;1<d?w[l++]=65533:D<65536?w[l++]=D:(D-=65536,w[l++]=55296|D>>10&1023,w[l++]=56320|1023&D)}return w.length!==l&&(w.subarray?w=w.subarray(0,l):w.length=l),B.applyFromCharCode(w)})(a=B.transformTo(C.uint8array?"uint8array":"array",a))},B.inherits(s,i),s.prototype.processChunk=function(a){var c=B.transformTo(C.uint8array?"uint8array":"array",a.data);if(this.leftOver&&this.leftOver.length){if(C.uint8array){var h=c;(c=new Uint8Array(h.length+this.leftOver.length)).set(this.leftOver,0),c.set(h,this.leftOver.length)}else c=this.leftOver.concat(c);this.leftOver=null}var l=(function(d,y){var w;for((y=y||d.length)>d.length&&(y=d.length),w=y-1;0<=w&&(192&d[w])==128;)w--;return w<0||w===0?y:w+E[d[w]]>y?w:y})(c),D=c;l!==c.length&&(C.uint8array?(D=c.subarray(0,l),this.leftOver=c.subarray(l,c.length)):(D=c.slice(0,l),this.leftOver=c.slice(l,c.length))),this.push({data:o.utf8decode(D),meta:a.meta})},s.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:o.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},o.Utf8DecodeWorker=s,B.inherits(r,i),r.prototype.processChunk=function(a){this.push({data:o.utf8encode(a.data),meta:a.meta})},o.Utf8EncodeWorker=r},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(e,t,o){var B=e("./support"),C=e("./base64"),Q=e("./nodejsUtils"),i=e("./external");function E(h){return h}function n(h,l){for(var D=0;D<h.length;++D)l[D]=255&h.charCodeAt(D);return l}e("setimmediate"),o.newBlob=function(h,l){o.checkSupport("blob");try{return new Blob([h],{type:l})}catch{try{var D=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return D.append(h),D.getBlob(l)}catch{throw new Error("Bug : can't construct the Blob.")}}};var s={stringifyByChunk:function(h,l,D){var d=[],y=0,w=h.length;if(w<=D)return String.fromCharCode.apply(null,h);for(;y<w;)l==="array"||l==="nodebuffer"?d.push(String.fromCharCode.apply(null,h.slice(y,Math.min(y+D,w)))):d.push(String.fromCharCode.apply(null,h.subarray(y,Math.min(y+D,w)))),y+=D;return d.join("")},stringifyByChar:function(h){for(var l="",D=0;D<h.length;D++)l+=String.fromCharCode(h[D]);return l},applyCanBeUsed:{uint8array:(function(){try{return B.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return B.nodebuffer&&String.fromCharCode.apply(null,Q.allocBuffer(1)).length===1}catch{return!1}})()}};function r(h){var l=65536,D=o.getTypeOf(h),d=!0;if(D==="uint8array"?d=s.applyCanBeUsed.uint8array:D==="nodebuffer"&&(d=s.applyCanBeUsed.nodebuffer),d)for(;1<l;)try{return s.stringifyByChunk(h,D,l)}catch{l=Math.floor(l/2)}return s.stringifyByChar(h)}function a(h,l){for(var D=0;D<h.length;D++)l[D]=h[D];return l}o.applyFromCharCode=r;var c={};c.string={string:E,array:function(h){return n(h,new Array(h.length))},arraybuffer:function(h){return c.string.uint8array(h).buffer},uint8array:function(h){return n(h,new Uint8Array(h.length))},nodebuffer:function(h){return n(h,Q.allocBuffer(h.length))}},c.array={string:r,array:E,arraybuffer:function(h){return new Uint8Array(h).buffer},uint8array:function(h){return new Uint8Array(h)},nodebuffer:function(h){return Q.newBufferFrom(h)}},c.arraybuffer={string:function(h){return r(new Uint8Array(h))},array:function(h){return a(new Uint8Array(h),new Array(h.byteLength))},arraybuffer:E,uint8array:function(h){return new Uint8Array(h)},nodebuffer:function(h){return Q.newBufferFrom(new Uint8Array(h))}},c.uint8array={string:r,array:function(h){return a(h,new Array(h.length))},arraybuffer:function(h){return h.buffer},uint8array:E,nodebuffer:function(h){return Q.newBufferFrom(h)}},c.nodebuffer={string:r,array:function(h){return a(h,new Array(h.length))},arraybuffer:function(h){return c.nodebuffer.uint8array(h).buffer},uint8array:function(h){return a(h,new Uint8Array(h.length))},nodebuffer:E},o.transformTo=function(h,l){if(l=l||"",!h)return l;o.checkSupport(h);var D=o.getTypeOf(l);return c[D][h](l)},o.resolve=function(h){for(var l=h.split("/"),D=[],d=0;d<l.length;d++){var y=l[d];y==="."||y===""&&d!==0&&d!==l.length-1||(y===".."?D.pop():D.push(y))}return D.join("/")},o.getTypeOf=function(h){if(typeof h=="string")return"string";var l=Object.prototype.toString.call(h);return l==="[object Array]"?"array":B.nodebuffer&&Q.isBuffer(h)?"nodebuffer":B.uint8array&&l==="[object Uint8Array]"?"uint8array":B.arraybuffer&&l==="[object ArrayBuffer]"?"arraybuffer":void 0},o.checkSupport=function(h){if(!B[h.toLowerCase()])throw new Error(h+" is not supported by this platform")},o.MAX_VALUE_16BITS=65535,o.MAX_VALUE_32BITS=-1,o.pretty=function(h){var l,D,d="";for(D=0;D<(h||"").length;D++)d+="\\x"+((l=h.charCodeAt(D))<16?"0":"")+l.toString(16).toUpperCase();return d},o.delay=function(h,l,D){setImmediate(function(){h.apply(D||null,l||[])})},o.inherits=function(h,l){function D(){}D.prototype=l.prototype,h.prototype=new D},o.extend=function(){var h,l,D={};for(h=0;h<arguments.length;h++)for(l in arguments[h])Object.prototype.hasOwnProperty.call(arguments[h],l)&&D[l]===void 0&&(D[l]=arguments[h][l]);return D},o.prepareContent=function(h,l,D,d,y){return i.Promise.resolve(l).then(function(w){return B.blob&&(w instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(w))!==-1)?Blob.prototype.arrayBuffer!==void 0?w.arrayBuffer():typeof FileReader<"u"?new i.Promise(function(u,G){var m=new FileReader;m.onload=function(p){u(p.target.result)},m.onerror=function(p){G(p.target.error)},m.readAsArrayBuffer(w)}):i.Promise.reject(new Error(h+" is a Blob, but we have no way of reading it.")):w}).then(function(w){var u=o.getTypeOf(w);return u?(u==="arraybuffer"?w=o.transformTo("uint8array",w):u==="string"&&(y?w=C.decode(w):D&&d!==!0&&(w=(function(G){return n(G,B.uint8array?new Uint8Array(G.length):new Array(G.length))})(w))),w):i.Promise.reject(new Error("Can't read the data of '"+h+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(e,t,o){var B=e("./reader/readerFor"),C=e("./utils"),Q=e("./signature"),i=e("./zipEntry"),E=e("./support");function n(s){this.files=[],this.loadOptions=s}n.prototype={checkSignature:function(s){if(!this.reader.readAndCheckSignature(s)){this.reader.index-=4;var r=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+C.pretty(r)+", expected "+C.pretty(s)+")")}},isSignature:function(s,r){var a=this.reader.index;this.reader.setIndex(s);var c=this.reader.readString(4)===r;return this.reader.setIndex(a),c},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var s=this.reader.readData(this.zipCommentLength),r=E.uint8array?"uint8array":"array",a=C.transformTo(r,s);this.zipComment=this.loadOptions.decodeFileName(a)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var s,r,a,c=this.zip64EndOfCentralSize-44;0<c;)s=this.reader.readInt(2),r=this.reader.readInt(4),a=this.reader.readData(r),this.zip64ExtensibleData[s]={id:s,length:r,value:a}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),1<this.disksCount)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var s,r;for(s=0;s<this.files.length;s++)r=this.files[s],this.reader.setIndex(r.localHeaderOffset),this.checkSignature(Q.LOCAL_FILE_HEADER),r.readLocalPart(this.reader),r.handleUTF8(),r.processAttributes()},readCentralDir:function(){var s;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(Q.CENTRAL_FILE_HEADER);)(s=new i({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(s);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var s=this.reader.lastIndexOfSignature(Q.CENTRAL_DIRECTORY_END);if(s<0)throw this.isSignature(0,Q.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(s);var r=s;if(this.checkSignature(Q.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===C.MAX_VALUE_16BITS||this.diskWithCentralDirStart===C.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===C.MAX_VALUE_16BITS||this.centralDirRecords===C.MAX_VALUE_16BITS||this.centralDirSize===C.MAX_VALUE_32BITS||this.centralDirOffset===C.MAX_VALUE_32BITS){if(this.zip64=!0,(s=this.reader.lastIndexOfSignature(Q.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(s),this.checkSignature(Q.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,Q.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(Q.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(Q.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var a=this.centralDirOffset+this.centralDirSize;this.zip64&&(a+=20,a+=12+this.zip64EndOfCentralSize);var c=r-a;if(0<c)this.isSignature(r,Q.CENTRAL_FILE_HEADER)||(this.reader.zero=c);else if(c<0)throw new Error("Corrupted zip: missing "+Math.abs(c)+" bytes.")},prepareReader:function(s){this.reader=B(s)},load:function(s){this.prepareReader(s),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},t.exports=n},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(e,t,o){var B=e("./reader/readerFor"),C=e("./utils"),Q=e("./compressedObject"),i=e("./crc32"),E=e("./utf8"),n=e("./compressions"),s=e("./support");function r(a,c){this.options=a,this.loadOptions=c}r.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(a){var c,h;if(a.skip(22),this.fileNameLength=a.readInt(2),h=a.readInt(2),this.fileName=a.readData(this.fileNameLength),a.skip(h),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if((c=(function(l){for(var D in n)if(Object.prototype.hasOwnProperty.call(n,D)&&n[D].magic===l)return n[D];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+C.pretty(this.compressionMethod)+" unknown (inner file : "+C.transformTo("string",this.fileName)+")");this.decompressed=new Q(this.compressedSize,this.uncompressedSize,this.crc32,c,a.readData(this.compressedSize))},readCentralPart:function(a){this.versionMadeBy=a.readInt(2),a.skip(2),this.bitFlag=a.readInt(2),this.compressionMethod=a.readString(2),this.date=a.readDate(),this.crc32=a.readInt(4),this.compressedSize=a.readInt(4),this.uncompressedSize=a.readInt(4);var c=a.readInt(2);if(this.extraFieldsLength=a.readInt(2),this.fileCommentLength=a.readInt(2),this.diskNumberStart=a.readInt(2),this.internalFileAttributes=a.readInt(2),this.externalFileAttributes=a.readInt(4),this.localHeaderOffset=a.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");a.skip(c),this.readExtraFields(a),this.parseZIP64ExtraField(a),this.fileComment=a.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var a=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),a==0&&(this.dosPermissions=63&this.externalFileAttributes),a==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var a=B(this.extraFields[1].value);this.uncompressedSize===C.MAX_VALUE_32BITS&&(this.uncompressedSize=a.readInt(8)),this.compressedSize===C.MAX_VALUE_32BITS&&(this.compressedSize=a.readInt(8)),this.localHeaderOffset===C.MAX_VALUE_32BITS&&(this.localHeaderOffset=a.readInt(8)),this.diskNumberStart===C.MAX_VALUE_32BITS&&(this.diskNumberStart=a.readInt(4))}},readExtraFields:function(a){var c,h,l,D=a.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});a.index+4<D;)c=a.readInt(2),h=a.readInt(2),l=a.readData(h),this.extraFields[c]={id:c,length:h,value:l};a.setIndex(D)},handleUTF8:function(){var a=s.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=E.utf8decode(this.fileName),this.fileCommentStr=E.utf8decode(this.fileComment);else{var c=this.findExtraFieldUnicodePath();if(c!==null)this.fileNameStr=c;else{var h=C.transformTo(a,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(h)}var l=this.findExtraFieldUnicodeComment();if(l!==null)this.fileCommentStr=l;else{var D=C.transformTo(a,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(D)}}},findExtraFieldUnicodePath:function(){var a=this.extraFields[28789];if(a){var c=B(a.value);return c.readInt(1)!==1||i(this.fileName)!==c.readInt(4)?null:E.utf8decode(c.readData(a.length-5))}return null},findExtraFieldUnicodeComment:function(){var a=this.extraFields[25461];if(a){var c=B(a.value);return c.readInt(1)!==1||i(this.fileComment)!==c.readInt(4)?null:E.utf8decode(c.readData(a.length-5))}return null}},t.exports=r},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(e,t,o){function B(c,h,l){this.name=c,this.dir=l.dir,this.date=l.date,this.comment=l.comment,this.unixPermissions=l.unixPermissions,this.dosPermissions=l.dosPermissions,this._data=h,this._dataBinary=l.binary,this.options={compression:l.compression,compressionOptions:l.compressionOptions}}var C=e("./stream/StreamHelper"),Q=e("./stream/DataWorker"),i=e("./utf8"),E=e("./compressedObject"),n=e("./stream/GenericWorker");B.prototype={internalStream:function(c){var h=null,l="string";try{if(!c)throw new Error("No output type specified.");var D=(l=c.toLowerCase())==="string"||l==="text";l!=="binarystring"&&l!=="text"||(l="string"),h=this._decompressWorker();var d=!this._dataBinary;d&&!D&&(h=h.pipe(new i.Utf8EncodeWorker)),!d&&D&&(h=h.pipe(new i.Utf8DecodeWorker))}catch(y){(h=new n("error")).error(y)}return new C(h,l,"")},async:function(c,h){return this.internalStream(c).accumulate(h)},nodeStream:function(c,h){return this.internalStream(c||"nodebuffer").toNodejsStream(h)},_compressWorker:function(c,h){if(this._data instanceof E&&this._data.compression.magic===c.magic)return this._data.getCompressedWorker();var l=this._decompressWorker();return this._dataBinary||(l=l.pipe(new i.Utf8EncodeWorker)),E.createWorkerFrom(l,c,h)},_decompressWorker:function(){return this._data instanceof E?this._data.getContentWorker():this._data instanceof n?this._data:new Q(this._data)}};for(var s=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],r=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},a=0;a<s.length;a++)B.prototype[s[a]]=r;t.exports=B},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(e,t,o){(function(B){var C,Q,i=B.MutationObserver||B.WebKitMutationObserver;if(i){var E=0,n=new i(c),s=B.document.createTextNode("");n.observe(s,{characterData:!0}),C=function(){s.data=E=++E%2}}else if(B.setImmediate||B.MessageChannel===void 0)C="document"in B&&"onreadystatechange"in B.document.createElement("script")?function(){var h=B.document.createElement("script");h.onreadystatechange=function(){c(),h.onreadystatechange=null,h.parentNode.removeChild(h),h=null},B.document.documentElement.appendChild(h)}:function(){setTimeout(c,0)};else{var r=new B.MessageChannel;r.port1.onmessage=c,C=function(){r.port2.postMessage(0)}}var a=[];function c(){var h,l;Q=!0;for(var D=a.length;D;){for(l=a,a=[],h=-1;++h<D;)l[h]();D=a.length}Q=!1}t.exports=function(h){a.push(h)!==1||Q||C()}}).call(this,typeof UY<"u"?UY:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(e,t,o){var B=e("immediate");function C(){}var Q={},i=["REJECTED"],E=["FULFILLED"],n=["PENDING"];function s(D){if(typeof D!="function")throw new TypeError("resolver must be a function");this.state=n,this.queue=[],this.outcome=void 0,D!==C&&h(this,D)}function r(D,d,y){this.promise=D,typeof d=="function"&&(this.onFulfilled=d,this.callFulfilled=this.otherCallFulfilled),typeof y=="function"&&(this.onRejected=y,this.callRejected=this.otherCallRejected)}function a(D,d,y){B(function(){var w;try{w=d(y)}catch(u){return Q.reject(D,u)}w===D?Q.reject(D,new TypeError("Cannot resolve promise with itself")):Q.resolve(D,w)})}function c(D){var d=D&&D.then;if(D&&(typeof D=="object"||typeof D=="function")&&typeof d=="function")return function(){d.apply(D,arguments)}}function h(D,d){var y=!1;function w(m){y||(y=!0,Q.reject(D,m))}function u(m){y||(y=!0,Q.resolve(D,m))}var G=l(function(){d(u,w)});G.status==="error"&&w(G.value)}function l(D,d){var y={};try{y.value=D(d),y.status="success"}catch(w){y.status="error",y.value=w}return y}(t.exports=s).prototype.finally=function(D){if(typeof D!="function")return this;var d=this.constructor;return this.then(function(y){return d.resolve(D()).then(function(){return y})},function(y){return d.resolve(D()).then(function(){throw y})})},s.prototype.catch=function(D){return this.then(null,D)},s.prototype.then=function(D,d){if(typeof D!="function"&&this.state===E||typeof d!="function"&&this.state===i)return this;var y=new this.constructor(C);return this.state!==n?a(y,this.state===E?D:d,this.outcome):this.queue.push(new r(y,D,d)),y},r.prototype.callFulfilled=function(D){Q.resolve(this.promise,D)},r.prototype.otherCallFulfilled=function(D){a(this.promise,this.onFulfilled,D)},r.prototype.callRejected=function(D){Q.reject(this.promise,D)},r.prototype.otherCallRejected=function(D){a(this.promise,this.onRejected,D)},Q.resolve=function(D,d){var y=l(c,d);if(y.status==="error")return Q.reject(D,y.value);var w=y.value;if(w)h(D,w);else{D.state=E,D.outcome=d;for(var u=-1,G=D.queue.length;++u<G;)D.queue[u].callFulfilled(d)}return D},Q.reject=function(D,d){D.state=i,D.outcome=d;for(var y=-1,w=D.queue.length;++y<w;)D.queue[y].callRejected(d);return D},s.resolve=function(D){return D instanceof this?D:Q.resolve(new this(C),D)},s.reject=function(D){var d=new this(C);return Q.reject(d,D)},s.all=function(D){var d=this;if(Object.prototype.toString.call(D)!=="[object Array]")return this.reject(new TypeError("must be an array"));var y=D.length,w=!1;if(!y)return this.resolve([]);for(var u=new Array(y),G=0,m=-1,p=new this(C);++m<y;)k(D[m],m);return p;function k(S,R){d.resolve(S).then(function(x){u[R]=x,++G!==y||w||(w=!0,Q.resolve(p,u))},function(x){w||(w=!0,Q.reject(p,x))})}},s.race=function(D){var d=this;if(Object.prototype.toString.call(D)!=="[object Array]")return this.reject(new TypeError("must be an array"));var y=D.length,w=!1;if(!y)return this.resolve([]);for(var u=-1,G=new this(C);++u<y;)m=D[u],d.resolve(m).then(function(p){w||(w=!0,Q.resolve(G,p))},function(p){w||(w=!0,Q.reject(G,p))});var m;return G}},{immediate:36}],38:[function(e,t,o){var B={};(0,e("./lib/utils/common").assign)(B,e("./lib/deflate"),e("./lib/inflate"),e("./lib/zlib/constants")),t.exports=B},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(e,t,o){var B=e("./zlib/deflate"),C=e("./utils/common"),Q=e("./utils/strings"),i=e("./zlib/messages"),E=e("./zlib/zstream"),n=Object.prototype.toString,s=0,r=-1,a=0,c=8;function h(D){if(!(this instanceof h))return new h(D);this.options=C.assign({level:r,method:c,chunkSize:16384,windowBits:15,memLevel:8,strategy:a,to:""},D||{});var d=this.options;d.raw&&0<d.windowBits?d.windowBits=-d.windowBits:d.gzip&&0<d.windowBits&&d.windowBits<16&&(d.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new E,this.strm.avail_out=0;var y=B.deflateInit2(this.strm,d.level,d.method,d.windowBits,d.memLevel,d.strategy);if(y!==s)throw new Error(i[y]);if(d.header&&B.deflateSetHeader(this.strm,d.header),d.dictionary){var w;if(w=typeof d.dictionary=="string"?Q.string2buf(d.dictionary):n.call(d.dictionary)==="[object ArrayBuffer]"?new Uint8Array(d.dictionary):d.dictionary,(y=B.deflateSetDictionary(this.strm,w))!==s)throw new Error(i[y]);this._dict_set=!0}}function l(D,d){var y=new h(d);if(y.push(D,!0),y.err)throw y.msg||i[y.err];return y.result}h.prototype.push=function(D,d){var y,w,u=this.strm,G=this.options.chunkSize;if(this.ended)return!1;w=d===~~d?d:d===!0?4:0,typeof D=="string"?u.input=Q.string2buf(D):n.call(D)==="[object ArrayBuffer]"?u.input=new Uint8Array(D):u.input=D,u.next_in=0,u.avail_in=u.input.length;do{if(u.avail_out===0&&(u.output=new C.Buf8(G),u.next_out=0,u.avail_out=G),(y=B.deflate(u,w))!==1&&y!==s)return this.onEnd(y),!(this.ended=!0);u.avail_out!==0&&(u.avail_in!==0||w!==4&&w!==2)||(this.options.to==="string"?this.onData(Q.buf2binstring(C.shrinkBuf(u.output,u.next_out))):this.onData(C.shrinkBuf(u.output,u.next_out)))}while((0<u.avail_in||u.avail_out===0)&&y!==1);return w===4?(y=B.deflateEnd(this.strm),this.onEnd(y),this.ended=!0,y===s):w!==2||(this.onEnd(s),!(u.avail_out=0))},h.prototype.onData=function(D){this.chunks.push(D)},h.prototype.onEnd=function(D){D===s&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=C.flattenChunks(this.chunks)),this.chunks=[],this.err=D,this.msg=this.strm.msg},o.Deflate=h,o.deflate=l,o.deflateRaw=function(D,d){return(d=d||{}).raw=!0,l(D,d)},o.gzip=function(D,d){return(d=d||{}).gzip=!0,l(D,d)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(e,t,o){var B=e("./zlib/inflate"),C=e("./utils/common"),Q=e("./utils/strings"),i=e("./zlib/constants"),E=e("./zlib/messages"),n=e("./zlib/zstream"),s=e("./zlib/gzheader"),r=Object.prototype.toString;function a(h){if(!(this instanceof a))return new a(h);this.options=C.assign({chunkSize:16384,windowBits:0,to:""},h||{});var l=this.options;l.raw&&0<=l.windowBits&&l.windowBits<16&&(l.windowBits=-l.windowBits,l.windowBits===0&&(l.windowBits=-15)),!(0<=l.windowBits&&l.windowBits<16)||h&&h.windowBits||(l.windowBits+=32),15<l.windowBits&&l.windowBits<48&&(15&l.windowBits)==0&&(l.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new n,this.strm.avail_out=0;var D=B.inflateInit2(this.strm,l.windowBits);if(D!==i.Z_OK)throw new Error(E[D]);this.header=new s,B.inflateGetHeader(this.strm,this.header)}function c(h,l){var D=new a(l);if(D.push(h,!0),D.err)throw D.msg||E[D.err];return D.result}a.prototype.push=function(h,l){var D,d,y,w,u,G,m=this.strm,p=this.options.chunkSize,k=this.options.dictionary,S=!1;if(this.ended)return!1;d=l===~~l?l:l===!0?i.Z_FINISH:i.Z_NO_FLUSH,typeof h=="string"?m.input=Q.binstring2buf(h):r.call(h)==="[object ArrayBuffer]"?m.input=new Uint8Array(h):m.input=h,m.next_in=0,m.avail_in=m.input.length;do{if(m.avail_out===0&&(m.output=new C.Buf8(p),m.next_out=0,m.avail_out=p),(D=B.inflate(m,i.Z_NO_FLUSH))===i.Z_NEED_DICT&&k&&(G=typeof k=="string"?Q.string2buf(k):r.call(k)==="[object ArrayBuffer]"?new Uint8Array(k):k,D=B.inflateSetDictionary(this.strm,G)),D===i.Z_BUF_ERROR&&S===!0&&(D=i.Z_OK,S=!1),D!==i.Z_STREAM_END&&D!==i.Z_OK)return this.onEnd(D),!(this.ended=!0);m.next_out&&(m.avail_out!==0&&D!==i.Z_STREAM_END&&(m.avail_in!==0||d!==i.Z_FINISH&&d!==i.Z_SYNC_FLUSH)||(this.options.to==="string"?(y=Q.utf8border(m.output,m.next_out),w=m.next_out-y,u=Q.buf2string(m.output,y),m.next_out=w,m.avail_out=p-w,w&&C.arraySet(m.output,m.output,y,w,0),this.onData(u)):this.onData(C.shrinkBuf(m.output,m.next_out)))),m.avail_in===0&&m.avail_out===0&&(S=!0)}while((0<m.avail_in||m.avail_out===0)&&D!==i.Z_STREAM_END);return D===i.Z_STREAM_END&&(d=i.Z_FINISH),d===i.Z_FINISH?(D=B.inflateEnd(this.strm),this.onEnd(D),this.ended=!0,D===i.Z_OK):d!==i.Z_SYNC_FLUSH||(this.onEnd(i.Z_OK),!(m.avail_out=0))},a.prototype.onData=function(h){this.chunks.push(h)},a.prototype.onEnd=function(h){h===i.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=C.flattenChunks(this.chunks)),this.chunks=[],this.err=h,this.msg=this.strm.msg},o.Inflate=a,o.inflate=c,o.inflateRaw=function(h,l){return(l=l||{}).raw=!0,c(h,l)},o.ungzip=c},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(e,t,o){var B=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";o.assign=function(i){for(var E=Array.prototype.slice.call(arguments,1);E.length;){var n=E.shift();if(n){if(typeof n!="object")throw new TypeError(n+"must be non-object");for(var s in n)n.hasOwnProperty(s)&&(i[s]=n[s])}}return i},o.shrinkBuf=function(i,E){return i.length===E?i:i.subarray?i.subarray(0,E):(i.length=E,i)};var C={arraySet:function(i,E,n,s,r){if(E.subarray&&i.subarray)i.set(E.subarray(n,n+s),r);else for(var a=0;a<s;a++)i[r+a]=E[n+a]},flattenChunks:function(i){var E,n,s,r,a,c;for(E=s=0,n=i.length;E<n;E++)s+=i[E].length;for(c=new Uint8Array(s),E=r=0,n=i.length;E<n;E++)a=i[E],c.set(a,r),r+=a.length;return c}},Q={arraySet:function(i,E,n,s,r){for(var a=0;a<s;a++)i[r+a]=E[n+a]},flattenChunks:function(i){return[].concat.apply([],i)}};o.setTyped=function(i){i?(o.Buf8=Uint8Array,o.Buf16=Uint16Array,o.Buf32=Int32Array,o.assign(o,C)):(o.Buf8=Array,o.Buf16=Array,o.Buf32=Array,o.assign(o,Q))},o.setTyped(B)},{}],42:[function(e,t,o){var B=e("./common"),C=!0,Q=!0;try{String.fromCharCode.apply(null,[0])}catch{C=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{Q=!1}for(var i=new B.Buf8(256),E=0;E<256;E++)i[E]=252<=E?6:248<=E?5:240<=E?4:224<=E?3:192<=E?2:1;function n(s,r){if(r<65537&&(s.subarray&&Q||!s.subarray&&C))return String.fromCharCode.apply(null,B.shrinkBuf(s,r));for(var a="",c=0;c<r;c++)a+=String.fromCharCode(s[c]);return a}i[254]=i[254]=1,o.string2buf=function(s){var r,a,c,h,l,D=s.length,d=0;for(h=0;h<D;h++)(64512&(a=s.charCodeAt(h)))==55296&&h+1<D&&(64512&(c=s.charCodeAt(h+1)))==56320&&(a=65536+(a-55296<<10)+(c-56320),h++),d+=a<128?1:a<2048?2:a<65536?3:4;for(r=new B.Buf8(d),h=l=0;l<d;h++)(64512&(a=s.charCodeAt(h)))==55296&&h+1<D&&(64512&(c=s.charCodeAt(h+1)))==56320&&(a=65536+(a-55296<<10)+(c-56320),h++),a<128?r[l++]=a:(a<2048?r[l++]=192|a>>>6:(a<65536?r[l++]=224|a>>>12:(r[l++]=240|a>>>18,r[l++]=128|a>>>12&63),r[l++]=128|a>>>6&63),r[l++]=128|63&a);return r},o.buf2binstring=function(s){return n(s,s.length)},o.binstring2buf=function(s){for(var r=new B.Buf8(s.length),a=0,c=r.length;a<c;a++)r[a]=s.charCodeAt(a);return r},o.buf2string=function(s,r){var a,c,h,l,D=r||s.length,d=new Array(2*D);for(a=c=0;a<D;)if((h=s[a++])<128)d[c++]=h;else if(4<(l=i[h]))d[c++]=65533,a+=l-1;else{for(h&=l===2?31:l===3?15:7;1<l&&a<D;)h=h<<6|63&s[a++],l--;1<l?d[c++]=65533:h<65536?d[c++]=h:(h-=65536,d[c++]=55296|h>>10&1023,d[c++]=56320|1023&h)}return n(d,c)},o.utf8border=function(s,r){var a;for((r=r||s.length)>s.length&&(r=s.length),a=r-1;0<=a&&(192&s[a])==128;)a--;return a<0||a===0?r:a+i[s[a]]>r?a:r}},{"./common":41}],43:[function(e,t,o){t.exports=function(B,C,Q,i){for(var E=65535&B|0,n=B>>>16&65535|0,s=0;Q!==0;){for(Q-=s=2e3<Q?2e3:Q;n=n+(E=E+C[i++]|0)|0,--s;);E%=65521,n%=65521}return E|n<<16|0}},{}],44:[function(e,t,o){t.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(e,t,o){var B=(function(){for(var C,Q=[],i=0;i<256;i++){C=i;for(var E=0;E<8;E++)C=1&C?3988292384^C>>>1:C>>>1;Q[i]=C}return Q})();t.exports=function(C,Q,i,E){var n=B,s=E+i;C^=-1;for(var r=E;r<s;r++)C=C>>>8^n[255&(C^Q[r])];return-1^C}},{}],46:[function(e,t,o){var B,C=e("../utils/common"),Q=e("./trees"),i=e("./adler32"),E=e("./crc32"),n=e("./messages"),s=0,r=4,a=0,c=-2,h=-1,l=4,D=2,d=8,y=9,w=286,u=30,G=19,m=2*w+1,p=15,k=3,S=258,R=S+k+1,x=42,N=113,U=1,K=2,Y=3,_=4;function q(rA,xA){return rA.msg=n[xA],xA}function j(rA){return(rA<<1)-(4<rA?9:0)}function W(rA){for(var xA=rA.length;0<=--xA;)rA[xA]=0}function Z(rA){var xA=rA.state,NA=xA.pending;NA>rA.avail_out&&(NA=rA.avail_out),NA!==0&&(C.arraySet(rA.output,xA.pending_buf,xA.pending_out,NA,rA.next_out),rA.next_out+=NA,xA.pending_out+=NA,rA.total_out+=NA,rA.avail_out-=NA,xA.pending-=NA,xA.pending===0&&(xA.pending_out=0))}function $(rA,xA){Q._tr_flush_block(rA,0<=rA.block_start?rA.block_start:-1,rA.strstart-rA.block_start,xA),rA.block_start=rA.strstart,Z(rA.strm)}function eA(rA,xA){rA.pending_buf[rA.pending++]=xA}function IA(rA,xA){rA.pending_buf[rA.pending++]=xA>>>8&255,rA.pending_buf[rA.pending++]=255&xA}function QA(rA,xA){var NA,RA,HA=rA.max_chain_length,KA=rA.strstart,mA=rA.prev_length,JA=rA.nice_match,dA=rA.strstart>rA.w_size-R?rA.strstart-(rA.w_size-R):0,bA=rA.window,WA=rA.w_mask,Qg=rA.prev,YA=rA.strstart+S,uA=bA[KA+mA-1],kA=bA[KA+mA];rA.prev_length>=rA.good_match&&(HA>>=2),JA>rA.lookahead&&(JA=rA.lookahead);do if(bA[(NA=xA)+mA]===kA&&bA[NA+mA-1]===uA&&bA[NA]===bA[KA]&&bA[++NA]===bA[KA+1]){KA+=2,NA++;do;while(bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&bA[++KA]===bA[++NA]&&KA<YA);if(RA=S-(YA-KA),KA=YA-S,mA<RA){if(rA.match_start=xA,JA<=(mA=RA))break;uA=bA[KA+mA-1],kA=bA[KA+mA]}}while((xA=Qg[xA&WA])>dA&&--HA!=0);return mA<=rA.lookahead?mA:rA.lookahead}function sA(rA){var xA,NA,RA,HA,KA,mA,JA,dA,bA,WA,Qg=rA.w_size;do{if(HA=rA.window_size-rA.lookahead-rA.strstart,rA.strstart>=Qg+(Qg-R)){for(C.arraySet(rA.window,rA.window,Qg,Qg,0),rA.match_start-=Qg,rA.strstart-=Qg,rA.block_start-=Qg,xA=NA=rA.hash_size;RA=rA.head[--xA],rA.head[xA]=Qg<=RA?RA-Qg:0,--NA;);for(xA=NA=Qg;RA=rA.prev[--xA],rA.prev[xA]=Qg<=RA?RA-Qg:0,--NA;);HA+=Qg}if(rA.strm.avail_in===0)break;if(mA=rA.strm,JA=rA.window,dA=rA.strstart+rA.lookahead,bA=HA,WA=void 0,WA=mA.avail_in,bA<WA&&(WA=bA),NA=WA===0?0:(mA.avail_in-=WA,C.arraySet(JA,mA.input,mA.next_in,WA,dA),mA.state.wrap===1?mA.adler=i(mA.adler,JA,WA,dA):mA.state.wrap===2&&(mA.adler=E(mA.adler,JA,WA,dA)),mA.next_in+=WA,mA.total_in+=WA,WA),rA.lookahead+=NA,rA.lookahead+rA.insert>=k)for(KA=rA.strstart-rA.insert,rA.ins_h=rA.window[KA],rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[KA+1])&rA.hash_mask;rA.insert&&(rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[KA+k-1])&rA.hash_mask,rA.prev[KA&rA.w_mask]=rA.head[rA.ins_h],rA.head[rA.ins_h]=KA,KA++,rA.insert--,!(rA.lookahead+rA.insert<k)););}while(rA.lookahead<R&&rA.strm.avail_in!==0)}function lA(rA,xA){for(var NA,RA;;){if(rA.lookahead<R){if(sA(rA),rA.lookahead<R&&xA===s)return U;if(rA.lookahead===0)break}if(NA=0,rA.lookahead>=k&&(rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[rA.strstart+k-1])&rA.hash_mask,NA=rA.prev[rA.strstart&rA.w_mask]=rA.head[rA.ins_h],rA.head[rA.ins_h]=rA.strstart),NA!==0&&rA.strstart-NA<=rA.w_size-R&&(rA.match_length=QA(rA,NA)),rA.match_length>=k)if(RA=Q._tr_tally(rA,rA.strstart-rA.match_start,rA.match_length-k),rA.lookahead-=rA.match_length,rA.match_length<=rA.max_lazy_match&&rA.lookahead>=k){for(rA.match_length--;rA.strstart++,rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[rA.strstart+k-1])&rA.hash_mask,NA=rA.prev[rA.strstart&rA.w_mask]=rA.head[rA.ins_h],rA.head[rA.ins_h]=rA.strstart,--rA.match_length!=0;);rA.strstart++}else rA.strstart+=rA.match_length,rA.match_length=0,rA.ins_h=rA.window[rA.strstart],rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[rA.strstart+1])&rA.hash_mask;else RA=Q._tr_tally(rA,0,rA.window[rA.strstart]),rA.lookahead--,rA.strstart++;if(RA&&($(rA,!1),rA.strm.avail_out===0))return U}return rA.insert=rA.strstart<k-1?rA.strstart:k-1,xA===r?($(rA,!0),rA.strm.avail_out===0?Y:_):rA.last_lit&&($(rA,!1),rA.strm.avail_out===0)?U:K}function BA(rA,xA){for(var NA,RA,HA;;){if(rA.lookahead<R){if(sA(rA),rA.lookahead<R&&xA===s)return U;if(rA.lookahead===0)break}if(NA=0,rA.lookahead>=k&&(rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[rA.strstart+k-1])&rA.hash_mask,NA=rA.prev[rA.strstart&rA.w_mask]=rA.head[rA.ins_h],rA.head[rA.ins_h]=rA.strstart),rA.prev_length=rA.match_length,rA.prev_match=rA.match_start,rA.match_length=k-1,NA!==0&&rA.prev_length<rA.max_lazy_match&&rA.strstart-NA<=rA.w_size-R&&(rA.match_length=QA(rA,NA),rA.match_length<=5&&(rA.strategy===1||rA.match_length===k&&4096<rA.strstart-rA.match_start)&&(rA.match_length=k-1)),rA.prev_length>=k&&rA.match_length<=rA.prev_length){for(HA=rA.strstart+rA.lookahead-k,RA=Q._tr_tally(rA,rA.strstart-1-rA.prev_match,rA.prev_length-k),rA.lookahead-=rA.prev_length-1,rA.prev_length-=2;++rA.strstart<=HA&&(rA.ins_h=(rA.ins_h<<rA.hash_shift^rA.window[rA.strstart+k-1])&rA.hash_mask,NA=rA.prev[rA.strstart&rA.w_mask]=rA.head[rA.ins_h],rA.head[rA.ins_h]=rA.strstart),--rA.prev_length!=0;);if(rA.match_available=0,rA.match_length=k-1,rA.strstart++,RA&&($(rA,!1),rA.strm.avail_out===0))return U}else if(rA.match_available){if((RA=Q._tr_tally(rA,0,rA.window[rA.strstart-1]))&&$(rA,!1),rA.strstart++,rA.lookahead--,rA.strm.avail_out===0)return U}else rA.match_available=1,rA.strstart++,rA.lookahead--}return rA.match_available&&(RA=Q._tr_tally(rA,0,rA.window[rA.strstart-1]),rA.match_available=0),rA.insert=rA.strstart<k-1?rA.strstart:k-1,xA===r?($(rA,!0),rA.strm.avail_out===0?Y:_):rA.last_lit&&($(rA,!1),rA.strm.avail_out===0)?U:K}function hA(rA,xA,NA,RA,HA){this.good_length=rA,this.max_lazy=xA,this.nice_length=NA,this.max_chain=RA,this.func=HA}function nA(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=d,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new C.Buf16(2*m),this.dyn_dtree=new C.Buf16(2*(2*u+1)),this.bl_tree=new C.Buf16(2*(2*G+1)),W(this.dyn_ltree),W(this.dyn_dtree),W(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new C.Buf16(p+1),this.heap=new C.Buf16(2*w+1),W(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new C.Buf16(2*w+1),W(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function aA(rA){var xA;return rA&&rA.state?(rA.total_in=rA.total_out=0,rA.data_type=D,(xA=rA.state).pending=0,xA.pending_out=0,xA.wrap<0&&(xA.wrap=-xA.wrap),xA.status=xA.wrap?x:N,rA.adler=xA.wrap===2?0:1,xA.last_flush=s,Q._tr_init(xA),a):q(rA,c)}function SA(rA){var xA=aA(rA);return xA===a&&(function(NA){NA.window_size=2*NA.w_size,W(NA.head),NA.max_lazy_match=B[NA.level].max_lazy,NA.good_match=B[NA.level].good_length,NA.nice_match=B[NA.level].nice_length,NA.max_chain_length=B[NA.level].max_chain,NA.strstart=0,NA.block_start=0,NA.lookahead=0,NA.insert=0,NA.match_length=NA.prev_length=k-1,NA.match_available=0,NA.ins_h=0})(rA.state),xA}function FA(rA,xA,NA,RA,HA,KA){if(!rA)return c;var mA=1;if(xA===h&&(xA=6),RA<0?(mA=0,RA=-RA):15<RA&&(mA=2,RA-=16),HA<1||y<HA||NA!==d||RA<8||15<RA||xA<0||9<xA||KA<0||l<KA)return q(rA,c);RA===8&&(RA=9);var JA=new nA;return(rA.state=JA).strm=rA,JA.wrap=mA,JA.gzhead=null,JA.w_bits=RA,JA.w_size=1<<JA.w_bits,JA.w_mask=JA.w_size-1,JA.hash_bits=HA+7,JA.hash_size=1<<JA.hash_bits,JA.hash_mask=JA.hash_size-1,JA.hash_shift=~~((JA.hash_bits+k-1)/k),JA.window=new C.Buf8(2*JA.w_size),JA.head=new C.Buf16(JA.hash_size),JA.prev=new C.Buf16(JA.w_size),JA.lit_bufsize=1<<HA+6,JA.pending_buf_size=4*JA.lit_bufsize,JA.pending_buf=new C.Buf8(JA.pending_buf_size),JA.d_buf=1*JA.lit_bufsize,JA.l_buf=3*JA.lit_bufsize,JA.level=xA,JA.strategy=KA,JA.method=NA,SA(rA)}B=[new hA(0,0,0,0,function(rA,xA){var NA=65535;for(NA>rA.pending_buf_size-5&&(NA=rA.pending_buf_size-5);;){if(rA.lookahead<=1){if(sA(rA),rA.lookahead===0&&xA===s)return U;if(rA.lookahead===0)break}rA.strstart+=rA.lookahead,rA.lookahead=0;var RA=rA.block_start+NA;if((rA.strstart===0||rA.strstart>=RA)&&(rA.lookahead=rA.strstart-RA,rA.strstart=RA,$(rA,!1),rA.strm.avail_out===0)||rA.strstart-rA.block_start>=rA.w_size-R&&($(rA,!1),rA.strm.avail_out===0))return U}return rA.insert=0,xA===r?($(rA,!0),rA.strm.avail_out===0?Y:_):(rA.strstart>rA.block_start&&($(rA,!1),rA.strm.avail_out),U)}),new hA(4,4,8,4,lA),new hA(4,5,16,8,lA),new hA(4,6,32,32,lA),new hA(4,4,16,16,BA),new hA(8,16,32,32,BA),new hA(8,16,128,128,BA),new hA(8,32,128,256,BA),new hA(32,128,258,1024,BA),new hA(32,258,258,4096,BA)],o.deflateInit=function(rA,xA){return FA(rA,xA,d,15,8,0)},o.deflateInit2=FA,o.deflateReset=SA,o.deflateResetKeep=aA,o.deflateSetHeader=function(rA,xA){return rA&&rA.state?rA.state.wrap!==2?c:(rA.state.gzhead=xA,a):c},o.deflate=function(rA,xA){var NA,RA,HA,KA;if(!rA||!rA.state||5<xA||xA<0)return rA?q(rA,c):c;if(RA=rA.state,!rA.output||!rA.input&&rA.avail_in!==0||RA.status===666&&xA!==r)return q(rA,rA.avail_out===0?-5:c);if(RA.strm=rA,NA=RA.last_flush,RA.last_flush=xA,RA.status===x)if(RA.wrap===2)rA.adler=0,eA(RA,31),eA(RA,139),eA(RA,8),RA.gzhead?(eA(RA,(RA.gzhead.text?1:0)+(RA.gzhead.hcrc?2:0)+(RA.gzhead.extra?4:0)+(RA.gzhead.name?8:0)+(RA.gzhead.comment?16:0)),eA(RA,255&RA.gzhead.time),eA(RA,RA.gzhead.time>>8&255),eA(RA,RA.gzhead.time>>16&255),eA(RA,RA.gzhead.time>>24&255),eA(RA,RA.level===9?2:2<=RA.strategy||RA.level<2?4:0),eA(RA,255&RA.gzhead.os),RA.gzhead.extra&&RA.gzhead.extra.length&&(eA(RA,255&RA.gzhead.extra.length),eA(RA,RA.gzhead.extra.length>>8&255)),RA.gzhead.hcrc&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending,0)),RA.gzindex=0,RA.status=69):(eA(RA,0),eA(RA,0),eA(RA,0),eA(RA,0),eA(RA,0),eA(RA,RA.level===9?2:2<=RA.strategy||RA.level<2?4:0),eA(RA,3),RA.status=N);else{var mA=d+(RA.w_bits-8<<4)<<8;mA|=(2<=RA.strategy||RA.level<2?0:RA.level<6?1:RA.level===6?2:3)<<6,RA.strstart!==0&&(mA|=32),mA+=31-mA%31,RA.status=N,IA(RA,mA),RA.strstart!==0&&(IA(RA,rA.adler>>>16),IA(RA,65535&rA.adler)),rA.adler=1}if(RA.status===69)if(RA.gzhead.extra){for(HA=RA.pending;RA.gzindex<(65535&RA.gzhead.extra.length)&&(RA.pending!==RA.pending_buf_size||(RA.gzhead.hcrc&&RA.pending>HA&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending-HA,HA)),Z(rA),HA=RA.pending,RA.pending!==RA.pending_buf_size));)eA(RA,255&RA.gzhead.extra[RA.gzindex]),RA.gzindex++;RA.gzhead.hcrc&&RA.pending>HA&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending-HA,HA)),RA.gzindex===RA.gzhead.extra.length&&(RA.gzindex=0,RA.status=73)}else RA.status=73;if(RA.status===73)if(RA.gzhead.name){HA=RA.pending;do{if(RA.pending===RA.pending_buf_size&&(RA.gzhead.hcrc&&RA.pending>HA&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending-HA,HA)),Z(rA),HA=RA.pending,RA.pending===RA.pending_buf_size)){KA=1;break}KA=RA.gzindex<RA.gzhead.name.length?255&RA.gzhead.name.charCodeAt(RA.gzindex++):0,eA(RA,KA)}while(KA!==0);RA.gzhead.hcrc&&RA.pending>HA&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending-HA,HA)),KA===0&&(RA.gzindex=0,RA.status=91)}else RA.status=91;if(RA.status===91)if(RA.gzhead.comment){HA=RA.pending;do{if(RA.pending===RA.pending_buf_size&&(RA.gzhead.hcrc&&RA.pending>HA&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending-HA,HA)),Z(rA),HA=RA.pending,RA.pending===RA.pending_buf_size)){KA=1;break}KA=RA.gzindex<RA.gzhead.comment.length?255&RA.gzhead.comment.charCodeAt(RA.gzindex++):0,eA(RA,KA)}while(KA!==0);RA.gzhead.hcrc&&RA.pending>HA&&(rA.adler=E(rA.adler,RA.pending_buf,RA.pending-HA,HA)),KA===0&&(RA.status=103)}else RA.status=103;if(RA.status===103&&(RA.gzhead.hcrc?(RA.pending+2>RA.pending_buf_size&&Z(rA),RA.pending+2<=RA.pending_buf_size&&(eA(RA,255&rA.adler),eA(RA,rA.adler>>8&255),rA.adler=0,RA.status=N)):RA.status=N),RA.pending!==0){if(Z(rA),rA.avail_out===0)return RA.last_flush=-1,a}else if(rA.avail_in===0&&j(xA)<=j(NA)&&xA!==r)return q(rA,-5);if(RA.status===666&&rA.avail_in!==0)return q(rA,-5);if(rA.avail_in!==0||RA.lookahead!==0||xA!==s&&RA.status!==666){var JA=RA.strategy===2?(function(dA,bA){for(var WA;;){if(dA.lookahead===0&&(sA(dA),dA.lookahead===0)){if(bA===s)return U;break}if(dA.match_length=0,WA=Q._tr_tally(dA,0,dA.window[dA.strstart]),dA.lookahead--,dA.strstart++,WA&&($(dA,!1),dA.strm.avail_out===0))return U}return dA.insert=0,bA===r?($(dA,!0),dA.strm.avail_out===0?Y:_):dA.last_lit&&($(dA,!1),dA.strm.avail_out===0)?U:K})(RA,xA):RA.strategy===3?(function(dA,bA){for(var WA,Qg,YA,uA,kA=dA.window;;){if(dA.lookahead<=S){if(sA(dA),dA.lookahead<=S&&bA===s)return U;if(dA.lookahead===0)break}if(dA.match_length=0,dA.lookahead>=k&&0<dA.strstart&&(Qg=kA[YA=dA.strstart-1])===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]){uA=dA.strstart+S;do;while(Qg===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]&&Qg===kA[++YA]&&YA<uA);dA.match_length=S-(uA-YA),dA.match_length>dA.lookahead&&(dA.match_length=dA.lookahead)}if(dA.match_length>=k?(WA=Q._tr_tally(dA,1,dA.match_length-k),dA.lookahead-=dA.match_length,dA.strstart+=dA.match_length,dA.match_length=0):(WA=Q._tr_tally(dA,0,dA.window[dA.strstart]),dA.lookahead--,dA.strstart++),WA&&($(dA,!1),dA.strm.avail_out===0))return U}return dA.insert=0,bA===r?($(dA,!0),dA.strm.avail_out===0?Y:_):dA.last_lit&&($(dA,!1),dA.strm.avail_out===0)?U:K})(RA,xA):B[RA.level].func(RA,xA);if(JA!==Y&&JA!==_||(RA.status=666),JA===U||JA===Y)return rA.avail_out===0&&(RA.last_flush=-1),a;if(JA===K&&(xA===1?Q._tr_align(RA):xA!==5&&(Q._tr_stored_block(RA,0,0,!1),xA===3&&(W(RA.head),RA.lookahead===0&&(RA.strstart=0,RA.block_start=0,RA.insert=0))),Z(rA),rA.avail_out===0))return RA.last_flush=-1,a}return xA!==r?a:RA.wrap<=0?1:(RA.wrap===2?(eA(RA,255&rA.adler),eA(RA,rA.adler>>8&255),eA(RA,rA.adler>>16&255),eA(RA,rA.adler>>24&255),eA(RA,255&rA.total_in),eA(RA,rA.total_in>>8&255),eA(RA,rA.total_in>>16&255),eA(RA,rA.total_in>>24&255)):(IA(RA,rA.adler>>>16),IA(RA,65535&rA.adler)),Z(rA),0<RA.wrap&&(RA.wrap=-RA.wrap),RA.pending!==0?a:1)},o.deflateEnd=function(rA){var xA;return rA&&rA.state?(xA=rA.state.status)!==x&&xA!==69&&xA!==73&&xA!==91&&xA!==103&&xA!==N&&xA!==666?q(rA,c):(rA.state=null,xA===N?q(rA,-3):a):c},o.deflateSetDictionary=function(rA,xA){var NA,RA,HA,KA,mA,JA,dA,bA,WA=xA.length;if(!rA||!rA.state||(KA=(NA=rA.state).wrap)===2||KA===1&&NA.status!==x||NA.lookahead)return c;for(KA===1&&(rA.adler=i(rA.adler,xA,WA,0)),NA.wrap=0,WA>=NA.w_size&&(KA===0&&(W(NA.head),NA.strstart=0,NA.block_start=0,NA.insert=0),bA=new C.Buf8(NA.w_size),C.arraySet(bA,xA,WA-NA.w_size,NA.w_size,0),xA=bA,WA=NA.w_size),mA=rA.avail_in,JA=rA.next_in,dA=rA.input,rA.avail_in=WA,rA.next_in=0,rA.input=xA,sA(NA);NA.lookahead>=k;){for(RA=NA.strstart,HA=NA.lookahead-(k-1);NA.ins_h=(NA.ins_h<<NA.hash_shift^NA.window[RA+k-1])&NA.hash_mask,NA.prev[RA&NA.w_mask]=NA.head[NA.ins_h],NA.head[NA.ins_h]=RA,RA++,--HA;);NA.strstart=RA,NA.lookahead=k-1,sA(NA)}return NA.strstart+=NA.lookahead,NA.block_start=NA.strstart,NA.insert=NA.lookahead,NA.lookahead=0,NA.match_length=NA.prev_length=k-1,NA.match_available=0,rA.next_in=JA,rA.input=dA,rA.avail_in=mA,NA.wrap=KA,a},o.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(e,t,o){t.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(e,t,o){t.exports=function(B,C){var Q,i,E,n,s,r,a,c,h,l,D,d,y,w,u,G,m,p,k,S,R,x,N,U,K;Q=B.state,i=B.next_in,U=B.input,E=i+(B.avail_in-5),n=B.next_out,K=B.output,s=n-(C-B.avail_out),r=n+(B.avail_out-257),a=Q.dmax,c=Q.wsize,h=Q.whave,l=Q.wnext,D=Q.window,d=Q.hold,y=Q.bits,w=Q.lencode,u=Q.distcode,G=(1<<Q.lenbits)-1,m=(1<<Q.distbits)-1;A:do{y<15&&(d+=U[i++]<<y,y+=8,d+=U[i++]<<y,y+=8),p=w[d&G];g:for(;;){if(d>>>=k=p>>>24,y-=k,(k=p>>>16&255)===0)K[n++]=65535&p;else{if(!(16&k)){if((64&k)==0){p=w[(65535&p)+(d&(1<<k)-1)];continue g}if(32&k){Q.mode=12;break A}B.msg="invalid literal/length code",Q.mode=30;break A}S=65535&p,(k&=15)&&(y<k&&(d+=U[i++]<<y,y+=8),S+=d&(1<<k)-1,d>>>=k,y-=k),y<15&&(d+=U[i++]<<y,y+=8,d+=U[i++]<<y,y+=8),p=u[d&m];I:for(;;){if(d>>>=k=p>>>24,y-=k,!(16&(k=p>>>16&255))){if((64&k)==0){p=u[(65535&p)+(d&(1<<k)-1)];continue I}B.msg="invalid distance code",Q.mode=30;break A}if(R=65535&p,y<(k&=15)&&(d+=U[i++]<<y,(y+=8)<k&&(d+=U[i++]<<y,y+=8)),a<(R+=d&(1<<k)-1)){B.msg="invalid distance too far back",Q.mode=30;break A}if(d>>>=k,y-=k,(k=n-s)<R){if(h<(k=R-k)&&Q.sane){B.msg="invalid distance too far back",Q.mode=30;break A}if(N=D,(x=0)===l){if(x+=c-k,k<S){for(S-=k;K[n++]=D[x++],--k;);x=n-R,N=K}}else if(l<k){if(x+=c+l-k,(k-=l)<S){for(S-=k;K[n++]=D[x++],--k;);if(x=0,l<S){for(S-=k=l;K[n++]=D[x++],--k;);x=n-R,N=K}}}else if(x+=l-k,k<S){for(S-=k;K[n++]=D[x++],--k;);x=n-R,N=K}for(;2<S;)K[n++]=N[x++],K[n++]=N[x++],K[n++]=N[x++],S-=3;S&&(K[n++]=N[x++],1<S&&(K[n++]=N[x++]))}else{for(x=n-R;K[n++]=K[x++],K[n++]=K[x++],K[n++]=K[x++],2<(S-=3););S&&(K[n++]=K[x++],1<S&&(K[n++]=K[x++]))}break}}break}}while(i<E&&n<r);i-=S=y>>3,d&=(1<<(y-=S<<3))-1,B.next_in=i,B.next_out=n,B.avail_in=i<E?E-i+5:5-(i-E),B.avail_out=n<r?r-n+257:257-(n-r),Q.hold=d,Q.bits=y}},{}],49:[function(e,t,o){var B=e("../utils/common"),C=e("./adler32"),Q=e("./crc32"),i=e("./inffast"),E=e("./inftrees"),n=1,s=2,r=0,a=-2,c=1,h=852,l=592;function D(x){return(x>>>24&255)+(x>>>8&65280)+((65280&x)<<8)+((255&x)<<24)}function d(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new B.Buf16(320),this.work=new B.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function y(x){var N;return x&&x.state?(N=x.state,x.total_in=x.total_out=N.total=0,x.msg="",N.wrap&&(x.adler=1&N.wrap),N.mode=c,N.last=0,N.havedict=0,N.dmax=32768,N.head=null,N.hold=0,N.bits=0,N.lencode=N.lendyn=new B.Buf32(h),N.distcode=N.distdyn=new B.Buf32(l),N.sane=1,N.back=-1,r):a}function w(x){var N;return x&&x.state?((N=x.state).wsize=0,N.whave=0,N.wnext=0,y(x)):a}function u(x,N){var U,K;return x&&x.state?(K=x.state,N<0?(U=0,N=-N):(U=1+(N>>4),N<48&&(N&=15)),N&&(N<8||15<N)?a:(K.window!==null&&K.wbits!==N&&(K.window=null),K.wrap=U,K.wbits=N,w(x))):a}function G(x,N){var U,K;return x?(K=new d,(x.state=K).window=null,(U=u(x,N))!==r&&(x.state=null),U):a}var m,p,k=!0;function S(x){if(k){var N;for(m=new B.Buf32(512),p=new B.Buf32(32),N=0;N<144;)x.lens[N++]=8;for(;N<256;)x.lens[N++]=9;for(;N<280;)x.lens[N++]=7;for(;N<288;)x.lens[N++]=8;for(E(n,x.lens,0,288,m,0,x.work,{bits:9}),N=0;N<32;)x.lens[N++]=5;E(s,x.lens,0,32,p,0,x.work,{bits:5}),k=!1}x.lencode=m,x.lenbits=9,x.distcode=p,x.distbits=5}function R(x,N,U,K){var Y,_=x.state;return _.window===null&&(_.wsize=1<<_.wbits,_.wnext=0,_.whave=0,_.window=new B.Buf8(_.wsize)),K>=_.wsize?(B.arraySet(_.window,N,U-_.wsize,_.wsize,0),_.wnext=0,_.whave=_.wsize):(K<(Y=_.wsize-_.wnext)&&(Y=K),B.arraySet(_.window,N,U-K,Y,_.wnext),(K-=Y)?(B.arraySet(_.window,N,U-K,K,0),_.wnext=K,_.whave=_.wsize):(_.wnext+=Y,_.wnext===_.wsize&&(_.wnext=0),_.whave<_.wsize&&(_.whave+=Y))),0}o.inflateReset=w,o.inflateReset2=u,o.inflateResetKeep=y,o.inflateInit=function(x){return G(x,15)},o.inflateInit2=G,o.inflate=function(x,N){var U,K,Y,_,q,j,W,Z,$,eA,IA,QA,sA,lA,BA,hA,nA,aA,SA,FA,rA,xA,NA,RA,HA=0,KA=new B.Buf8(4),mA=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!x||!x.state||!x.output||!x.input&&x.avail_in!==0)return a;(U=x.state).mode===12&&(U.mode=13),q=x.next_out,Y=x.output,W=x.avail_out,_=x.next_in,K=x.input,j=x.avail_in,Z=U.hold,$=U.bits,eA=j,IA=W,xA=r;A:for(;;)switch(U.mode){case c:if(U.wrap===0){U.mode=13;break}for(;$<16;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(2&U.wrap&&Z===35615){KA[U.check=0]=255&Z,KA[1]=Z>>>8&255,U.check=Q(U.check,KA,2,0),$=Z=0,U.mode=2;break}if(U.flags=0,U.head&&(U.head.done=!1),!(1&U.wrap)||(((255&Z)<<8)+(Z>>8))%31){x.msg="incorrect header check",U.mode=30;break}if((15&Z)!=8){x.msg="unknown compression method",U.mode=30;break}if($-=4,rA=8+(15&(Z>>>=4)),U.wbits===0)U.wbits=rA;else if(rA>U.wbits){x.msg="invalid window size",U.mode=30;break}U.dmax=1<<rA,x.adler=U.check=1,U.mode=512&Z?10:12,$=Z=0;break;case 2:for(;$<16;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(U.flags=Z,(255&U.flags)!=8){x.msg="unknown compression method",U.mode=30;break}if(57344&U.flags){x.msg="unknown header flags set",U.mode=30;break}U.head&&(U.head.text=Z>>8&1),512&U.flags&&(KA[0]=255&Z,KA[1]=Z>>>8&255,U.check=Q(U.check,KA,2,0)),$=Z=0,U.mode=3;case 3:for(;$<32;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}U.head&&(U.head.time=Z),512&U.flags&&(KA[0]=255&Z,KA[1]=Z>>>8&255,KA[2]=Z>>>16&255,KA[3]=Z>>>24&255,U.check=Q(U.check,KA,4,0)),$=Z=0,U.mode=4;case 4:for(;$<16;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}U.head&&(U.head.xflags=255&Z,U.head.os=Z>>8),512&U.flags&&(KA[0]=255&Z,KA[1]=Z>>>8&255,U.check=Q(U.check,KA,2,0)),$=Z=0,U.mode=5;case 5:if(1024&U.flags){for(;$<16;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}U.length=Z,U.head&&(U.head.extra_len=Z),512&U.flags&&(KA[0]=255&Z,KA[1]=Z>>>8&255,U.check=Q(U.check,KA,2,0)),$=Z=0}else U.head&&(U.head.extra=null);U.mode=6;case 6:if(1024&U.flags&&(j<(QA=U.length)&&(QA=j),QA&&(U.head&&(rA=U.head.extra_len-U.length,U.head.extra||(U.head.extra=new Array(U.head.extra_len)),B.arraySet(U.head.extra,K,_,QA,rA)),512&U.flags&&(U.check=Q(U.check,K,QA,_)),j-=QA,_+=QA,U.length-=QA),U.length))break A;U.length=0,U.mode=7;case 7:if(2048&U.flags){if(j===0)break A;for(QA=0;rA=K[_+QA++],U.head&&rA&&U.length<65536&&(U.head.name+=String.fromCharCode(rA)),rA&&QA<j;);if(512&U.flags&&(U.check=Q(U.check,K,QA,_)),j-=QA,_+=QA,rA)break A}else U.head&&(U.head.name=null);U.length=0,U.mode=8;case 8:if(4096&U.flags){if(j===0)break A;for(QA=0;rA=K[_+QA++],U.head&&rA&&U.length<65536&&(U.head.comment+=String.fromCharCode(rA)),rA&&QA<j;);if(512&U.flags&&(U.check=Q(U.check,K,QA,_)),j-=QA,_+=QA,rA)break A}else U.head&&(U.head.comment=null);U.mode=9;case 9:if(512&U.flags){for(;$<16;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(Z!==(65535&U.check)){x.msg="header crc mismatch",U.mode=30;break}$=Z=0}U.head&&(U.head.hcrc=U.flags>>9&1,U.head.done=!0),x.adler=U.check=0,U.mode=12;break;case 10:for(;$<32;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}x.adler=U.check=D(Z),$=Z=0,U.mode=11;case 11:if(U.havedict===0)return x.next_out=q,x.avail_out=W,x.next_in=_,x.avail_in=j,U.hold=Z,U.bits=$,2;x.adler=U.check=1,U.mode=12;case 12:if(N===5||N===6)break A;case 13:if(U.last){Z>>>=7&$,$-=7&$,U.mode=27;break}for(;$<3;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}switch(U.last=1&Z,$-=1,3&(Z>>>=1)){case 0:U.mode=14;break;case 1:if(S(U),U.mode=20,N!==6)break;Z>>>=2,$-=2;break A;case 2:U.mode=17;break;case 3:x.msg="invalid block type",U.mode=30}Z>>>=2,$-=2;break;case 14:for(Z>>>=7&$,$-=7&$;$<32;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if((65535&Z)!=(Z>>>16^65535)){x.msg="invalid stored block lengths",U.mode=30;break}if(U.length=65535&Z,$=Z=0,U.mode=15,N===6)break A;case 15:U.mode=16;case 16:if(QA=U.length){if(j<QA&&(QA=j),W<QA&&(QA=W),QA===0)break A;B.arraySet(Y,K,_,QA,q),j-=QA,_+=QA,W-=QA,q+=QA,U.length-=QA;break}U.mode=12;break;case 17:for(;$<14;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(U.nlen=257+(31&Z),Z>>>=5,$-=5,U.ndist=1+(31&Z),Z>>>=5,$-=5,U.ncode=4+(15&Z),Z>>>=4,$-=4,286<U.nlen||30<U.ndist){x.msg="too many length or distance symbols",U.mode=30;break}U.have=0,U.mode=18;case 18:for(;U.have<U.ncode;){for(;$<3;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}U.lens[mA[U.have++]]=7&Z,Z>>>=3,$-=3}for(;U.have<19;)U.lens[mA[U.have++]]=0;if(U.lencode=U.lendyn,U.lenbits=7,NA={bits:U.lenbits},xA=E(0,U.lens,0,19,U.lencode,0,U.work,NA),U.lenbits=NA.bits,xA){x.msg="invalid code lengths set",U.mode=30;break}U.have=0,U.mode=19;case 19:for(;U.have<U.nlen+U.ndist;){for(;hA=(HA=U.lencode[Z&(1<<U.lenbits)-1])>>>16&255,nA=65535&HA,!((BA=HA>>>24)<=$);){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(nA<16)Z>>>=BA,$-=BA,U.lens[U.have++]=nA;else{if(nA===16){for(RA=BA+2;$<RA;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(Z>>>=BA,$-=BA,U.have===0){x.msg="invalid bit length repeat",U.mode=30;break}rA=U.lens[U.have-1],QA=3+(3&Z),Z>>>=2,$-=2}else if(nA===17){for(RA=BA+3;$<RA;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}$-=BA,rA=0,QA=3+(7&(Z>>>=BA)),Z>>>=3,$-=3}else{for(RA=BA+7;$<RA;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}$-=BA,rA=0,QA=11+(127&(Z>>>=BA)),Z>>>=7,$-=7}if(U.have+QA>U.nlen+U.ndist){x.msg="invalid bit length repeat",U.mode=30;break}for(;QA--;)U.lens[U.have++]=rA}}if(U.mode===30)break;if(U.lens[256]===0){x.msg="invalid code -- missing end-of-block",U.mode=30;break}if(U.lenbits=9,NA={bits:U.lenbits},xA=E(n,U.lens,0,U.nlen,U.lencode,0,U.work,NA),U.lenbits=NA.bits,xA){x.msg="invalid literal/lengths set",U.mode=30;break}if(U.distbits=6,U.distcode=U.distdyn,NA={bits:U.distbits},xA=E(s,U.lens,U.nlen,U.ndist,U.distcode,0,U.work,NA),U.distbits=NA.bits,xA){x.msg="invalid distances set",U.mode=30;break}if(U.mode=20,N===6)break A;case 20:U.mode=21;case 21:if(6<=j&&258<=W){x.next_out=q,x.avail_out=W,x.next_in=_,x.avail_in=j,U.hold=Z,U.bits=$,i(x,IA),q=x.next_out,Y=x.output,W=x.avail_out,_=x.next_in,K=x.input,j=x.avail_in,Z=U.hold,$=U.bits,U.mode===12&&(U.back=-1);break}for(U.back=0;hA=(HA=U.lencode[Z&(1<<U.lenbits)-1])>>>16&255,nA=65535&HA,!((BA=HA>>>24)<=$);){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(hA&&(240&hA)==0){for(aA=BA,SA=hA,FA=nA;hA=(HA=U.lencode[FA+((Z&(1<<aA+SA)-1)>>aA)])>>>16&255,nA=65535&HA,!(aA+(BA=HA>>>24)<=$);){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}Z>>>=aA,$-=aA,U.back+=aA}if(Z>>>=BA,$-=BA,U.back+=BA,U.length=nA,hA===0){U.mode=26;break}if(32&hA){U.back=-1,U.mode=12;break}if(64&hA){x.msg="invalid literal/length code",U.mode=30;break}U.extra=15&hA,U.mode=22;case 22:if(U.extra){for(RA=U.extra;$<RA;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}U.length+=Z&(1<<U.extra)-1,Z>>>=U.extra,$-=U.extra,U.back+=U.extra}U.was=U.length,U.mode=23;case 23:for(;hA=(HA=U.distcode[Z&(1<<U.distbits)-1])>>>16&255,nA=65535&HA,!((BA=HA>>>24)<=$);){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if((240&hA)==0){for(aA=BA,SA=hA,FA=nA;hA=(HA=U.distcode[FA+((Z&(1<<aA+SA)-1)>>aA)])>>>16&255,nA=65535&HA,!(aA+(BA=HA>>>24)<=$);){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}Z>>>=aA,$-=aA,U.back+=aA}if(Z>>>=BA,$-=BA,U.back+=BA,64&hA){x.msg="invalid distance code",U.mode=30;break}U.offset=nA,U.extra=15&hA,U.mode=24;case 24:if(U.extra){for(RA=U.extra;$<RA;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}U.offset+=Z&(1<<U.extra)-1,Z>>>=U.extra,$-=U.extra,U.back+=U.extra}if(U.offset>U.dmax){x.msg="invalid distance too far back",U.mode=30;break}U.mode=25;case 25:if(W===0)break A;if(QA=IA-W,U.offset>QA){if((QA=U.offset-QA)>U.whave&&U.sane){x.msg="invalid distance too far back",U.mode=30;break}sA=QA>U.wnext?(QA-=U.wnext,U.wsize-QA):U.wnext-QA,QA>U.length&&(QA=U.length),lA=U.window}else lA=Y,sA=q-U.offset,QA=U.length;for(W<QA&&(QA=W),W-=QA,U.length-=QA;Y[q++]=lA[sA++],--QA;);U.length===0&&(U.mode=21);break;case 26:if(W===0)break A;Y[q++]=U.length,W--,U.mode=21;break;case 27:if(U.wrap){for(;$<32;){if(j===0)break A;j--,Z|=K[_++]<<$,$+=8}if(IA-=W,x.total_out+=IA,U.total+=IA,IA&&(x.adler=U.check=U.flags?Q(U.check,Y,IA,q-IA):C(U.check,Y,IA,q-IA)),IA=W,(U.flags?Z:D(Z))!==U.check){x.msg="incorrect data check",U.mode=30;break}$=Z=0}U.mode=28;case 28:if(U.wrap&&U.flags){for(;$<32;){if(j===0)break A;j--,Z+=K[_++]<<$,$+=8}if(Z!==(4294967295&U.total)){x.msg="incorrect length check",U.mode=30;break}$=Z=0}U.mode=29;case 29:xA=1;break A;case 30:xA=-3;break A;case 31:return-4;default:return a}return x.next_out=q,x.avail_out=W,x.next_in=_,x.avail_in=j,U.hold=Z,U.bits=$,(U.wsize||IA!==x.avail_out&&U.mode<30&&(U.mode<27||N!==4))&&R(x,x.output,x.next_out,IA-x.avail_out)?(U.mode=31,-4):(eA-=x.avail_in,IA-=x.avail_out,x.total_in+=eA,x.total_out+=IA,U.total+=IA,U.wrap&&IA&&(x.adler=U.check=U.flags?Q(U.check,Y,IA,x.next_out-IA):C(U.check,Y,IA,x.next_out-IA)),x.data_type=U.bits+(U.last?64:0)+(U.mode===12?128:0)+(U.mode===20||U.mode===15?256:0),(eA==0&&IA===0||N===4)&&xA===r&&(xA=-5),xA)},o.inflateEnd=function(x){if(!x||!x.state)return a;var N=x.state;return N.window&&(N.window=null),x.state=null,r},o.inflateGetHeader=function(x,N){var U;return x&&x.state?(2&(U=x.state).wrap)==0?a:((U.head=N).done=!1,r):a},o.inflateSetDictionary=function(x,N){var U,K=N.length;return x&&x.state?(U=x.state).wrap!==0&&U.mode!==11?a:U.mode===11&&C(1,N,K,0)!==U.check?-3:R(x,N,K,K)?(U.mode=31,-4):(U.havedict=1,r):a},o.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(e,t,o){var B=e("../utils/common"),C=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Q=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],i=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],E=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];t.exports=function(n,s,r,a,c,h,l,D){var d,y,w,u,G,m,p,k,S,R=D.bits,x=0,N=0,U=0,K=0,Y=0,_=0,q=0,j=0,W=0,Z=0,$=null,eA=0,IA=new B.Buf16(16),QA=new B.Buf16(16),sA=null,lA=0;for(x=0;x<=15;x++)IA[x]=0;for(N=0;N<a;N++)IA[s[r+N]]++;for(Y=R,K=15;1<=K&&IA[K]===0;K--);if(K<Y&&(Y=K),K===0)return c[h++]=20971520,c[h++]=20971520,D.bits=1,0;for(U=1;U<K&&IA[U]===0;U++);for(Y<U&&(Y=U),x=j=1;x<=15;x++)if(j<<=1,(j-=IA[x])<0)return-1;if(0<j&&(n===0||K!==1))return-1;for(QA[1]=0,x=1;x<15;x++)QA[x+1]=QA[x]+IA[x];for(N=0;N<a;N++)s[r+N]!==0&&(l[QA[s[r+N]]++]=N);if(m=n===0?($=sA=l,19):n===1?($=C,eA-=257,sA=Q,lA-=257,256):($=i,sA=E,-1),x=U,G=h,q=N=Z=0,w=-1,u=(W=1<<(_=Y))-1,n===1&&852<W||n===2&&592<W)return 1;for(;;){for(p=x-q,S=l[N]<m?(k=0,l[N]):l[N]>m?(k=sA[lA+l[N]],$[eA+l[N]]):(k=96,0),d=1<<x-q,U=y=1<<_;c[G+(Z>>q)+(y-=d)]=p<<24|k<<16|S|0,y!==0;);for(d=1<<x-1;Z&d;)d>>=1;if(d!==0?(Z&=d-1,Z+=d):Z=0,N++,--IA[x]==0){if(x===K)break;x=s[r+l[N]]}if(Y<x&&(Z&u)!==w){for(q===0&&(q=Y),G+=U,j=1<<(_=x-q);_+q<K&&!((j-=IA[_+q])<=0);)_++,j<<=1;if(W+=1<<_,n===1&&852<W||n===2&&592<W)return 1;c[w=Z&u]=Y<<24|_<<16|G-h|0}}return Z!==0&&(c[G+Z]=x-q<<24|64<<16|0),D.bits=Y,0}},{"../utils/common":41}],51:[function(e,t,o){t.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(e,t,o){var B=e("../utils/common"),C=0,Q=1;function i(HA){for(var KA=HA.length;0<=--KA;)HA[KA]=0}var E=0,n=29,s=256,r=s+1+n,a=30,c=19,h=2*r+1,l=15,D=16,d=7,y=256,w=16,u=17,G=18,m=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],p=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],k=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],S=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],R=new Array(2*(r+2));i(R);var x=new Array(2*a);i(x);var N=new Array(512);i(N);var U=new Array(256);i(U);var K=new Array(n);i(K);var Y,_,q,j=new Array(a);function W(HA,KA,mA,JA,dA){this.static_tree=HA,this.extra_bits=KA,this.extra_base=mA,this.elems=JA,this.max_length=dA,this.has_stree=HA&&HA.length}function Z(HA,KA){this.dyn_tree=HA,this.max_code=0,this.stat_desc=KA}function $(HA){return HA<256?N[HA]:N[256+(HA>>>7)]}function eA(HA,KA){HA.pending_buf[HA.pending++]=255&KA,HA.pending_buf[HA.pending++]=KA>>>8&255}function IA(HA,KA,mA){HA.bi_valid>D-mA?(HA.bi_buf|=KA<<HA.bi_valid&65535,eA(HA,HA.bi_buf),HA.bi_buf=KA>>D-HA.bi_valid,HA.bi_valid+=mA-D):(HA.bi_buf|=KA<<HA.bi_valid&65535,HA.bi_valid+=mA)}function QA(HA,KA,mA){IA(HA,mA[2*KA],mA[2*KA+1])}function sA(HA,KA){for(var mA=0;mA|=1&HA,HA>>>=1,mA<<=1,0<--KA;);return mA>>>1}function lA(HA,KA,mA){var JA,dA,bA=new Array(l+1),WA=0;for(JA=1;JA<=l;JA++)bA[JA]=WA=WA+mA[JA-1]<<1;for(dA=0;dA<=KA;dA++){var Qg=HA[2*dA+1];Qg!==0&&(HA[2*dA]=sA(bA[Qg]++,Qg))}}function BA(HA){var KA;for(KA=0;KA<r;KA++)HA.dyn_ltree[2*KA]=0;for(KA=0;KA<a;KA++)HA.dyn_dtree[2*KA]=0;for(KA=0;KA<c;KA++)HA.bl_tree[2*KA]=0;HA.dyn_ltree[2*y]=1,HA.opt_len=HA.static_len=0,HA.last_lit=HA.matches=0}function hA(HA){8<HA.bi_valid?eA(HA,HA.bi_buf):0<HA.bi_valid&&(HA.pending_buf[HA.pending++]=HA.bi_buf),HA.bi_buf=0,HA.bi_valid=0}function nA(HA,KA,mA,JA){var dA=2*KA,bA=2*mA;return HA[dA]<HA[bA]||HA[dA]===HA[bA]&&JA[KA]<=JA[mA]}function aA(HA,KA,mA){for(var JA=HA.heap[mA],dA=mA<<1;dA<=HA.heap_len&&(dA<HA.heap_len&&nA(KA,HA.heap[dA+1],HA.heap[dA],HA.depth)&&dA++,!nA(KA,JA,HA.heap[dA],HA.depth));)HA.heap[mA]=HA.heap[dA],mA=dA,dA<<=1;HA.heap[mA]=JA}function SA(HA,KA,mA){var JA,dA,bA,WA,Qg=0;if(HA.last_lit!==0)for(;JA=HA.pending_buf[HA.d_buf+2*Qg]<<8|HA.pending_buf[HA.d_buf+2*Qg+1],dA=HA.pending_buf[HA.l_buf+Qg],Qg++,JA===0?QA(HA,dA,KA):(QA(HA,(bA=U[dA])+s+1,KA),(WA=m[bA])!==0&&IA(HA,dA-=K[bA],WA),QA(HA,bA=$(--JA),mA),(WA=p[bA])!==0&&IA(HA,JA-=j[bA],WA)),Qg<HA.last_lit;);QA(HA,y,KA)}function FA(HA,KA){var mA,JA,dA,bA=KA.dyn_tree,WA=KA.stat_desc.static_tree,Qg=KA.stat_desc.has_stree,YA=KA.stat_desc.elems,uA=-1;for(HA.heap_len=0,HA.heap_max=h,mA=0;mA<YA;mA++)bA[2*mA]!==0?(HA.heap[++HA.heap_len]=uA=mA,HA.depth[mA]=0):bA[2*mA+1]=0;for(;HA.heap_len<2;)bA[2*(dA=HA.heap[++HA.heap_len]=uA<2?++uA:0)]=1,HA.depth[dA]=0,HA.opt_len--,Qg&&(HA.static_len-=WA[2*dA+1]);for(KA.max_code=uA,mA=HA.heap_len>>1;1<=mA;mA--)aA(HA,bA,mA);for(dA=YA;mA=HA.heap[1],HA.heap[1]=HA.heap[HA.heap_len--],aA(HA,bA,1),JA=HA.heap[1],HA.heap[--HA.heap_max]=mA,HA.heap[--HA.heap_max]=JA,bA[2*dA]=bA[2*mA]+bA[2*JA],HA.depth[dA]=(HA.depth[mA]>=HA.depth[JA]?HA.depth[mA]:HA.depth[JA])+1,bA[2*mA+1]=bA[2*JA+1]=dA,HA.heap[1]=dA++,aA(HA,bA,1),2<=HA.heap_len;);HA.heap[--HA.heap_max]=HA.heap[1],(function(kA,OA){var $A,og,dg,Sg,Bg,Yg,iI=OA.dyn_tree,GA=OA.max_code,ng=OA.stat_desc.static_tree,pg=OA.stat_desc.has_stree,Ug=OA.stat_desc.extra_bits,mg=OA.stat_desc.extra_base,Rg=OA.stat_desc.max_length,Jg=0;for(Sg=0;Sg<=l;Sg++)kA.bl_count[Sg]=0;for(iI[2*kA.heap[kA.heap_max]+1]=0,$A=kA.heap_max+1;$A<h;$A++)Rg<(Sg=iI[2*iI[2*(og=kA.heap[$A])+1]+1]+1)&&(Sg=Rg,Jg++),iI[2*og+1]=Sg,GA<og||(kA.bl_count[Sg]++,Bg=0,mg<=og&&(Bg=Ug[og-mg]),Yg=iI[2*og],kA.opt_len+=Yg*(Sg+Bg),pg&&(kA.static_len+=Yg*(ng[2*og+1]+Bg)));if(Jg!==0){do{for(Sg=Rg-1;kA.bl_count[Sg]===0;)Sg--;kA.bl_count[Sg]--,kA.bl_count[Sg+1]+=2,kA.bl_count[Rg]--,Jg-=2}while(0<Jg);for(Sg=Rg;Sg!==0;Sg--)for(og=kA.bl_count[Sg];og!==0;)GA<(dg=kA.heap[--$A])||(iI[2*dg+1]!==Sg&&(kA.opt_len+=(Sg-iI[2*dg+1])*iI[2*dg],iI[2*dg+1]=Sg),og--)}})(HA,KA),lA(bA,uA,HA.bl_count)}function rA(HA,KA,mA){var JA,dA,bA=-1,WA=KA[1],Qg=0,YA=7,uA=4;for(WA===0&&(YA=138,uA=3),KA[2*(mA+1)+1]=65535,JA=0;JA<=mA;JA++)dA=WA,WA=KA[2*(JA+1)+1],++Qg<YA&&dA===WA||(Qg<uA?HA.bl_tree[2*dA]+=Qg:dA!==0?(dA!==bA&&HA.bl_tree[2*dA]++,HA.bl_tree[2*w]++):Qg<=10?HA.bl_tree[2*u]++:HA.bl_tree[2*G]++,bA=dA,uA=(Qg=0)===WA?(YA=138,3):dA===WA?(YA=6,3):(YA=7,4))}function xA(HA,KA,mA){var JA,dA,bA=-1,WA=KA[1],Qg=0,YA=7,uA=4;for(WA===0&&(YA=138,uA=3),JA=0;JA<=mA;JA++)if(dA=WA,WA=KA[2*(JA+1)+1],!(++Qg<YA&&dA===WA)){if(Qg<uA)for(;QA(HA,dA,HA.bl_tree),--Qg!=0;);else dA!==0?(dA!==bA&&(QA(HA,dA,HA.bl_tree),Qg--),QA(HA,w,HA.bl_tree),IA(HA,Qg-3,2)):Qg<=10?(QA(HA,u,HA.bl_tree),IA(HA,Qg-3,3)):(QA(HA,G,HA.bl_tree),IA(HA,Qg-11,7));bA=dA,uA=(Qg=0)===WA?(YA=138,3):dA===WA?(YA=6,3):(YA=7,4)}}i(j);var NA=!1;function RA(HA,KA,mA,JA){IA(HA,(E<<1)+(JA?1:0),3),(function(dA,bA,WA,Qg){hA(dA),eA(dA,WA),eA(dA,~WA),B.arraySet(dA.pending_buf,dA.window,bA,WA,dA.pending),dA.pending+=WA})(HA,KA,mA)}o._tr_init=function(HA){NA||((function(){var KA,mA,JA,dA,bA,WA=new Array(l+1);for(dA=JA=0;dA<n-1;dA++)for(K[dA]=JA,KA=0;KA<1<<m[dA];KA++)U[JA++]=dA;for(U[JA-1]=dA,dA=bA=0;dA<16;dA++)for(j[dA]=bA,KA=0;KA<1<<p[dA];KA++)N[bA++]=dA;for(bA>>=7;dA<a;dA++)for(j[dA]=bA<<7,KA=0;KA<1<<p[dA]-7;KA++)N[256+bA++]=dA;for(mA=0;mA<=l;mA++)WA[mA]=0;for(KA=0;KA<=143;)R[2*KA+1]=8,KA++,WA[8]++;for(;KA<=255;)R[2*KA+1]=9,KA++,WA[9]++;for(;KA<=279;)R[2*KA+1]=7,KA++,WA[7]++;for(;KA<=287;)R[2*KA+1]=8,KA++,WA[8]++;for(lA(R,r+1,WA),KA=0;KA<a;KA++)x[2*KA+1]=5,x[2*KA]=sA(KA,5);Y=new W(R,m,s+1,r,l),_=new W(x,p,0,a,l),q=new W(new Array(0),k,0,c,d)})(),NA=!0),HA.l_desc=new Z(HA.dyn_ltree,Y),HA.d_desc=new Z(HA.dyn_dtree,_),HA.bl_desc=new Z(HA.bl_tree,q),HA.bi_buf=0,HA.bi_valid=0,BA(HA)},o._tr_stored_block=RA,o._tr_flush_block=function(HA,KA,mA,JA){var dA,bA,WA=0;0<HA.level?(HA.strm.data_type===2&&(HA.strm.data_type=(function(Qg){var YA,uA=4093624447;for(YA=0;YA<=31;YA++,uA>>>=1)if(1&uA&&Qg.dyn_ltree[2*YA]!==0)return C;if(Qg.dyn_ltree[18]!==0||Qg.dyn_ltree[20]!==0||Qg.dyn_ltree[26]!==0)return Q;for(YA=32;YA<s;YA++)if(Qg.dyn_ltree[2*YA]!==0)return Q;return C})(HA)),FA(HA,HA.l_desc),FA(HA,HA.d_desc),WA=(function(Qg){var YA;for(rA(Qg,Qg.dyn_ltree,Qg.l_desc.max_code),rA(Qg,Qg.dyn_dtree,Qg.d_desc.max_code),FA(Qg,Qg.bl_desc),YA=c-1;3<=YA&&Qg.bl_tree[2*S[YA]+1]===0;YA--);return Qg.opt_len+=3*(YA+1)+5+5+4,YA})(HA),dA=HA.opt_len+3+7>>>3,(bA=HA.static_len+3+7>>>3)<=dA&&(dA=bA)):dA=bA=mA+5,mA+4<=dA&&KA!==-1?RA(HA,KA,mA,JA):HA.strategy===4||bA===dA?(IA(HA,2+(JA?1:0),3),SA(HA,R,x)):(IA(HA,4+(JA?1:0),3),(function(Qg,YA,uA,kA){var OA;for(IA(Qg,YA-257,5),IA(Qg,uA-1,5),IA(Qg,kA-4,4),OA=0;OA<kA;OA++)IA(Qg,Qg.bl_tree[2*S[OA]+1],3);xA(Qg,Qg.dyn_ltree,YA-1),xA(Qg,Qg.dyn_dtree,uA-1)})(HA,HA.l_desc.max_code+1,HA.d_desc.max_code+1,WA+1),SA(HA,HA.dyn_ltree,HA.dyn_dtree)),BA(HA),JA&&hA(HA)},o._tr_tally=function(HA,KA,mA){return HA.pending_buf[HA.d_buf+2*HA.last_lit]=KA>>>8&255,HA.pending_buf[HA.d_buf+2*HA.last_lit+1]=255&KA,HA.pending_buf[HA.l_buf+HA.last_lit]=255&mA,HA.last_lit++,KA===0?HA.dyn_ltree[2*mA]++:(HA.matches++,KA--,HA.dyn_ltree[2*(U[mA]+s+1)]++,HA.dyn_dtree[2*$(KA)]++),HA.last_lit===HA.lit_bufsize-1},o._tr_align=function(HA){IA(HA,2,3),QA(HA,y,R),(function(KA){KA.bi_valid===16?(eA(KA,KA.bi_buf),KA.bi_buf=0,KA.bi_valid=0):8<=KA.bi_valid&&(KA.pending_buf[KA.pending++]=255&KA.bi_buf,KA.bi_buf>>=8,KA.bi_valid-=8)})(HA)}},{"../utils/common":41}],53:[function(e,t,o){t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,o){(function(B){(function(C,Q){if(!C.setImmediate){var i,E,n,s,r=1,a={},c=!1,h=C.document,l=Object.getPrototypeOf&&Object.getPrototypeOf(C);l=l&&l.setTimeout?l:C,i={}.toString.call(C.process)==="[object process]"?function(w){I.nextTick(function(){d(w)})}:(function(){if(C.postMessage&&!C.importScripts){var w=!0,u=C.onmessage;return C.onmessage=function(){w=!1},C.postMessage("","*"),C.onmessage=u,w}})()?(s="setImmediate$"+Math.random()+"$",C.addEventListener?C.addEventListener("message",y,!1):C.attachEvent("onmessage",y),function(w){C.postMessage(s+w,"*")}):C.MessageChannel?((n=new MessageChannel).port1.onmessage=function(w){d(w.data)},function(w){n.port2.postMessage(w)}):h&&"onreadystatechange"in h.createElement("script")?(E=h.documentElement,function(w){var u=h.createElement("script");u.onreadystatechange=function(){d(w),u.onreadystatechange=null,E.removeChild(u),u=null},E.appendChild(u)}):function(w){setTimeout(d,0,w)},l.setImmediate=function(w){typeof w!="function"&&(w=new Function(""+w));for(var u=new Array(arguments.length-1),G=0;G<u.length;G++)u[G]=arguments[G+1];var m={callback:w,args:u};return a[r]=m,i(r),r++},l.clearImmediate=D}function D(w){delete a[w]}function d(w){if(c)setTimeout(d,0,w);else{var u=a[w];if(u){c=!0;try{(function(G){var m=G.callback,p=G.args;switch(p.length){case 0:m();break;case 1:m(p[0]);break;case 2:m(p[0],p[1]);break;case 3:m(p[0],p[1],p[2]);break;default:m.apply(Q,p)}})(u)}finally{D(w),c=!1}}}}function y(w){w.source===C&&typeof w.data=="string"&&w.data.indexOf(s)===0&&d(+w.data.slice(s.length))}})(typeof self>"u"?B===void 0?this:B:self)}).call(this,typeof UY<"u"?UY:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(XCg)),XCg.exports}var ESo=iSo();const soA=bp(ESo),nSo=async()=>await Promise.resolve().then(()=>SVo),sSo=async({circuitJson:g,projectName:A})=>{try{const{circuitJsonToStep:I}=await nSo(),e=await I(g,{exportMode:"assembly"}),t=new soA;for(const[o,B]of Object.entries(e))t.file(o,B);_k(await t.generateAsync({type:"blob"}),{fileName:`${A}-assembly.zip`})}catch(I){KC.error(`Failed to export assembly STEP: ${I instanceof Error?I.message:String(I)}`)}},aSo=async({circuitJson:g,projectName:A})=>{await KC.promise((async()=>{const I=new soA,[e,{convertCircuitJsonToBomRows:t,convertBomRowsToCsv:o},{convertCircuitJsonToPickAndPlaceCsv:B}]=await Promise.all([xS("circuit-json-to-gerber"),xS("circuit-json-to-bom-csv"),xS("circuit-json-to-pnp-csv")]),C=g.filter(r=>!("error_type"in r)&&!("warning_type"in r)),Q=e.convertCircuitJsonToGerberFiles(C,{flip_y_axis:!1});for(const[r,a]of Object.entries(Q))I.file(`gerber/${r}`,a);const i=await t({circuitJson:g}),E=await o(i);I.file("bom.csv",E);const n=await B(g,{supplier:"jlcpcb"});I.file("pick_and_place.csv",n);const s=await I.generateAsync({type:"blob"});_k(s,{fileName:`${A}_fabrication_files.zip`})})(),{loading:"Generating fabrication files...",success:"Fabrication ZIP ready",error:I=>`Failed to generate fabrication files: ${I instanceof Error?I.message:String(I)}`})},rSo=async g=>{const{createFdmComponentBox:A,renderFdmComponentBoxPng:I}=await xS("circuit-json-to-fdm-component-box"),[e,t]=await Promise.all([A(g),I(g,{},{width:960,height:640})]);return{...e,previewPng:t}},cSo=async g=>{const{createFdmComponentBox:A}=await xS("circuit-json-to-fdm-component-box");return A(g)},I4I=({generatedBox:g,projectName:A})=>{const I=Uint8Array.from(g.threeMf);_k(new Blob([I.buffer],{type:"model/3mf"}),{fileName:`${GCg(A)}-component-box.3mf`})},hSo=async({circuitJson:g,projectName:A})=>{await KC.promise((async()=>{const I=await cSo(g);I4I({generatedBox:I,projectName:A})})(),{loading:"Generating component box...",success:"Component box 3MF ready",error:I=>`Failed to generate component box: ${I instanceof Error?I.message:String(I)}`})},lSo=async({circuitJson:g,projectName:A})=>{let I;try{const{convertCircuitJsonToGltf:e}=await xS("circuit-json-to-gltf");console.log("convertCircuitJsonToGltf",e);const t=await e(g,{format:"glb",boardTextureResolution:1024});if(!t||!(t instanceof ArrayBuffer))throw new Error("Invalid GLB data returned from converter");I=new Blob([t],{type:"model/gltf-binary"})}catch(e){console.error("GLB Export Error:",e);return}_k(I,{fileName:`${A}.glb`})},DSo=async({circuitJson:g,libraryName:A})=>{const{CircuitJsonToKicadLibraryConverter:I}=await xS("circuit-json-to-kicad"),e=new I(g,{libraryName:A,footprintLibraryName:A});e.runUntilFinished();const t=e.getOutput(),o=new soA;o.file(`${A}.kicad_sym`,t.kicadSymString);for(const B of t.footprints){const C=o.folder(`${A}.pretty`);C&&C.file(`${B.footprintName}.kicad_mod`,`${B.kicadModString}
5672
5672
  `)}if(t.model3dSourcePaths.length>0){const B=o.folder(`${A}.3dshapes`);if(B)for(const C of t.model3dSourcePaths)try{const Q=C.split("/").pop()||C,i=await fetch(C);if(i.ok){const E=await i.arrayBuffer();B.file(Q,E)}}catch{}}return o.file("fp-lib-table",t.fpLibTableString),o.file("sym-lib-table",t.symLibTableString),o},dSo=async({circuitJson:g,projectName:A})=>{await KC.promise((async()=>{const e=await(await DSo({circuitJson:g,libraryName:A})).generateAsync({type:"blob"});_k(e,{fileName:`${A}_kicad_library.zip`})})(),{loading:"Generating KiCad library...",success:"KiCad library ZIP ready",error:I=>`Failed to generate KiCad library: ${I instanceof Error?I.message:String(I)}`})},ySo=async({circuitJson:g,projectName:A})=>{const{CircuitJsonToKicadPcbConverter:I,CircuitJsonToKicadSchConverter:e,CircuitJsonToKicadProConverter:t,resolveAndLoadKicad3dModelFiles:o}=await xS("circuit-json-to-kicad"),B=new e(g);B.runUntilFinished();const C=B.getOutputString(),Q=new I(g,{includeBuiltin3dModels:!0,projectName:A});Q.runUntilFinished();const i=Q.getOutputString(),E=new t(g,{projectName:A,schematicFilename:`${A}.kicad_sch`,pcbFilename:`${A}.kicad_pcb`});E.runUntilFinished();const n=E.getOutputString(),s=new soA;return s.file(`${A}.kicad_sch`,C),s.file(`${A}.kicad_pcb`,i),s.file(`${A}.kicad_pro`,n),await o({projectName:A,model3dSourcePaths:Q.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:r,content:a})=>{s.file(r,a)},onError:({sourcePath:r})=>{console.warn(`Failed to load 3D model from ${r}`)}}),s},wSo=async({circuitJson:g,projectName:A})=>{await KC.promise((async()=>{const e=await(await ySo({circuitJson:g,projectName:A})).generateAsync({type:"blob"});_k(e,{fileName:`${A}_kicad_project.zip`})})(),{loading:"Generating KiCad project...",success:"KiCad project ZIP ready",error:I=>`Failed to generate KiCad project: ${I instanceof Error?I.message:String(I)}`})},e4I=async({circuitJson:g,projectName:A,options:I={}})=>{try{const{convertCircuitJsonToLbrn:e}=await xS("circuit-json-to-lbrn"),o=(await e(g,{includeSilkscreen:I.includeSilkscreen??!1,includeOxidationCleaningLayer:I.includeOxidationCleaningLayer??!0})).toXml(),B=new Blob([o],{type:"application/lbrn"});_k(B,{fileName:`${A}.lbrn2`})}catch(e){const t=e instanceof Error?e.message:"Unknown error";KC.error(`Failed to export to LBRN format: ${t}`)}},uSo=async({circuitJson:g,projectName:A})=>{const{convertCircuitJsonToPinoutSvg:I}=await xS("circuit-to-svg"),e=I(g);_k(e,{fileName:`${A}-pinout.svg`,mimeType:"image/svg+xml"})},GSo=async({circuitJson:g,projectName:A})=>{const{circuitJsonToStep:I}=await xS("circuit-json-to-step"),e=g.find(i=>i.type==="pcb_board"),t=e&&"width"in e?e.width:void 0,o=e&&"height"in e?e.height:void 0,B=e&&"thickness"in e?e.thickness:void 0;if(t===void 0||o===void 0||B===void 0){KC.error("Board dimensions not found. Please add a pcb_board with width, height, and thickness to your circuit.");return}let C;try{C=await I(g,{boardWidth:t,boardHeight:o,boardThickness:B,productName:A,includeComponents:!0,includeExternalMeshes:!0})}catch(i){const E=i instanceof Error?i.message:"Unknown error";KC.error(`Failed to convert circuit to STEP format: ${E}`);return}const Q=new Blob([C],{type:"application/step"});try{_k(Q,{fileName:`${A}.step`})}catch(i){const E=i instanceof Error?i.message:"Unknown error";KC.error(`Failed to download STEP file: ${E}`)}},mSo=[{extension:"json",name:"Circuit JSON"},{extension:"json",name:"Simple Route JSON"},{extension:"zip",name:"Fabrication Files"},{extension:"zip",name:"KiCad Project"},{extension:"zip",name:"Altium Project"},{extension:"zip",name:"KiCad Library"},{extension:"glb",name:"GLB (Binary GLTF)"},{extension:"svg",name:"Pinout SVG"},{extension:"step",name:"STEP"},{extension:"zip",name:"Assembly STEP"},{extension:"lbrn2",name:"LightBurn"}],pSo=async({exportName:g,circuitJson:A,simpleRouteJson:I,projectName:e})=>{const t=GCg(e);if(g==="Fabrication Files"){await aSo({circuitJson:A,projectName:t});return}if(g==="KiCad Project"){await wSo({circuitJson:A,projectName:t});return}if(g==="Altium Project"){await QSo({circuitJson:A,projectName:t});return}if(g==="KiCad Library"){await dSo({circuitJson:A,projectName:t});return}if(g==="Circuit JSON"){_k(JSON.stringify(A,null,2),{fileName:`${t}.circuit.json`,mimeType:"application/json"});return}if(g==="Simple Route JSON"){if(!I)throw new Error("No Simple Route JSON available to export");_k(JSON.stringify(I,null,2),{fileName:`${t}.simple-route.json`,mimeType:"application/json"});return}if(g==="GLB (Binary GLTF)"){await lSo({circuitJson:A,projectName:t});return}if(g==="Pinout SVG"){uSo({circuitJson:A,projectName:t});return}if(g==="STEP"){await GSo({circuitJson:A,projectName:t});return}if(g==="Assembly STEP"){await sSo({circuitJson:A,projectName:t});return}if(g==="Component Box (3MF)"){await hSo({circuitJson:A,projectName:t});return}if(g==="LightBurn"){await e4I({circuitJson:A,projectName:t});return}throw new Error(`Unsupported export type: "${g}"`)},kSo=({packageName:g,onSelectReview:A})=>{const I=Jc(n=>n.fsMap),e=Jc(n=>n.circuitJson),[t,o]=z.useState([]),[B,C]=z.useState(!1),[Q,i]=z.useState(!1);z.useEffect(()=>{!g||!JDA()||(C(!0),kgA.get("ai_reviews/list",{searchParams:{package_name:g}}).json().then(n=>o(n.ai_reviews)).catch(n=>{console.error("Failed to load AI reviews",n),KC.error("Failed to load AI reviews")}).finally(()=>C(!1)))},[g]);const E=async()=>{if(!e){KC.error("Need Circuit JSON to Request AI Review");return}if(!JDA()){KC.error("Missing registry token");return}i(!0);try{const{ai_review:n}=await kgA.post("ai_reviews/create",{json:{package_name:g??"unknown",fs_map:Object.fromEntries(I),circuit_json:e}}).json();o(s=>[n,...s]),A(n),KC.success("AI review requested")}catch(n){console.error("Failed to create AI review",n),KC.error("Failed to request AI review")}finally{i(!1)}};return T.jsxs(T.Fragment,{children:[T.jsxs(xL,{children:[T.jsx(FL,{children:"AI Review"}),T.jsx(_b,{children:"Select an AI review or request a new one."})]}),T.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:T.jsx("div",{className:"rf-w-48 rf-h-64 rf-overflow-y-auto rf-border rf-rounded rf-p-2 rf-flex-shrink-0",children:B?T.jsx("div",{className:"rf-text-sm",children:"Loading..."}):t.length>0?t.map(n=>T.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>A(n),children:new Date(n.created_at||"").toLocaleString()},n.ai_review_id)):T.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),T.jsx(YO,{className:"rf-mt-4",children:T.jsx(si,{onClick:E,disabled:Q,children:Q?"Requesting...":"Review my Board"})})]})};function $Cg(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var bb=$Cg();function t4I(g){bb=g}var aoA={exec:()=>null};function Zs(g,A=""){let I=typeof g=="string"?g:g.source;const e={replace:(t,o)=>{let B=typeof o=="string"?o:o.source;return B=B.replace(Wm.caret,"$1"),I=I.replace(t,B),e},getRegex:()=>new RegExp(I,A)};return e}var Wm={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:g=>new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}#`),htmlBeginRegex:g=>new RegExp(`^ {0,${Math.min(3,g-1)}}<(?:[a-z].*>|!--)`,"i")},MSo=/^(?:[ \t]*(?:\n|$))+/,SSo=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,fSo=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,roA=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,RSo=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,AQg=/(?:[*+-]|\d{1,9}[.)])/,o4I=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,B4I=Zs(o4I).replace(/bull/g,AQg).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),NSo=Zs(o4I).replace(/bull/g,AQg).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),gQg=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,xSo=/^[^\n]+/,IQg=/(?!\s*\])(?:\\.|[^\[\]\\])+/,FSo=Zs(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",IQg).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),USo=Zs(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,AQg).getRegex(),apA="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",eQg=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,JSo=Zs("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",eQg).replace("tag",apA).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),C4I=Zs(gQg).replace("hr",roA).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",apA).getRegex(),PSo=Zs(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",C4I).getRegex(),tQg={blockquote:PSo,code:SSo,def:FSo,fences:fSo,heading:RSo,hr:roA,html:JSo,lheading:B4I,list:USo,newline:MSo,paragraph:C4I,table:aoA,text:xSo},Q4I=Zs("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",roA).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",apA).getRegex(),KSo={...tQg,lheading:NSo,table:Q4I,paragraph:Zs(gQg).replace("hr",roA).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Q4I).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",apA).getRegex()},LSo={...tQg,html:Zs(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",eQg).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:aoA,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Zs(gQg).replace("hr",roA).replace("heading",` *#{1,6} *[^
5673
5673
  ]`).replace("lheading",B4I).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},YSo=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,_So=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,i4I=/^( {2,}|\\)\n(?!\s*$)/,bSo=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,rpA=/[\p{P}\p{S}]/u,oQg=/[\s\p{P}\p{S}]/u,E4I=/[^\s\p{P}\p{S}]/u,HSo=Zs(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,oQg).getRegex(),n4I=/(?!~)[\p{P}\p{S}]/u,vSo=/(?!~)[\s\p{P}\p{S}]/u,TSo=/(?:[^\s\p{P}\p{S}]|~)/u,qSo=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,s4I=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,ZSo=Zs(s4I,"u").replace(/punct/g,rpA).getRegex(),OSo=Zs(s4I,"u").replace(/punct/g,n4I).getRegex(),a4I="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",WSo=Zs(a4I,"gu").replace(/notPunctSpace/g,E4I).replace(/punctSpace/g,oQg).replace(/punct/g,rpA).getRegex(),VSo=Zs(a4I,"gu").replace(/notPunctSpace/g,TSo).replace(/punctSpace/g,vSo).replace(/punct/g,n4I).getRegex(),jSo=Zs("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,E4I).replace(/punctSpace/g,oQg).replace(/punct/g,rpA).getRegex(),zSo=Zs(/\\(punct)/,"gu").replace(/punct/g,rpA).getRegex(),XSo=Zs(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),$So=Zs(eQg).replace("(?:-->|$)","-->").getRegex(),A2o=Zs("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",$So).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),cpA=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,g2o=Zs(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",cpA).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),r4I=Zs(/^!?\[(label)\]\[(ref)\]/).replace("label",cpA).replace("ref",IQg).getRegex(),c4I=Zs(/^!?\[(ref)\](?:\[\])?/).replace("ref",IQg).getRegex(),I2o=Zs("reflink|nolink(?!\\()","g").replace("reflink",r4I).replace("nolink",c4I).getRegex(),BQg={_backpedal:aoA,anyPunctuation:zSo,autolink:XSo,blockSkip:qSo,br:i4I,code:_So,del:aoA,emStrongLDelim:ZSo,emStrongRDelimAst:WSo,emStrongRDelimUnd:jSo,escape:YSo,link:g2o,nolink:c4I,punctuation:HSo,reflink:r4I,reflinkSearch:I2o,tag:A2o,text:bSo,url:aoA},e2o={...BQg,link:Zs(/^!?\[(label)\]\((.*?)\)/).replace("label",cpA).getRegex(),reflink:Zs(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",cpA).getRegex()},CQg={...BQg,emStrongRDelimAst:VSo,emStrongLDelim:OSo,url:Zs(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},t2o={...CQg,br:Zs(i4I).replace("{2,}","*").getRegex(),text:Zs(CQg.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},hpA={normal:tQg,gfm:KSo,pedantic:LSo},coA={normal:BQg,gfm:CQg,breaks:t2o,pedantic:e2o},o2o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},h4I=g=>o2o[g];function wF(g,A){if(A){if(Wm.escapeTest.test(g))return g.replace(Wm.escapeReplace,h4I)}else if(Wm.escapeTestNoEncode.test(g))return g.replace(Wm.escapeReplaceNoEncode,h4I);return g}function l4I(g){try{g=encodeURI(g).replace(Wm.percentDecode,"%")}catch{return null}return g}function D4I(g,A){const I=g.replace(Wm.findPipe,(o,B,C)=>{let Q=!1,i=B;for(;--i>=0&&C[i]==="\\";)Q=!Q;return Q?"|":" |"}),e=I.split(Wm.splitPipe);let t=0;if(e[0].trim()||e.shift(),e.length>0&&!e.at(-1)?.trim()&&e.pop(),A)if(e.length>A)e.splice(A);else for(;e.length<A;)e.push("");for(;t<e.length;t++)e[t]=e[t].trim().replace(Wm.slashPipe,"|");return e}function hoA(g,A,I){const e=g.length;if(e===0)return"";let t=0;for(;t<e&&g.charAt(e-t-1)===A;)t++;return g.slice(0,e-t)}function B2o(g,A){if(g.indexOf(A[1])===-1)return-1;let I=0;for(let e=0;e<g.length;e++)if(g[e]==="\\")e++;else if(g[e]===A[0])I++;else if(g[e]===A[1]&&(I--,I<0))return e;return I>0?-2:-1}function d4I(g,A,I,e,t){const o=A.href,B=A.title||null,C=g[1].replace(t.other.outputLinkReplace,"$1");e.state.inLink=!0;const Q={type:g[0].charAt(0)==="!"?"image":"link",raw:I,href:o,title:B,text:C,tokens:e.inlineTokens(C)};return e.state.inLink=!1,Q}function C2o(g,A,I){const e=g.match(I.other.indentCodeCompensation);if(e===null)return A;const t=e[1];return A.split(`