@tscircuit/runframe 0.0.2958 → 0.0.2959

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.
@@ -5674,7 +5674,7 @@ test("${A} should solve problem correctly", () => {
5674
5674
  // Add more specific assertions based on expected output
5675
5675
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5676
5676
  })
5677
- `,u=new Blob([l],{type:"text/plain"}),g=URL.createObjectURL(u),h=document.createElement("a");h.href=g,h.download=`${A}.test.ts`,h.click(),URL.revokeObjectURL(g)}catch(c){alert(`Error generating test.ts for ${t.getSolverName()}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},M3n=t=>t.activeSubSolver?[t,...M3n(t.activeSubSolver)]:[t],Gor=({solver:t})=>{const e=M3n(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(Oor,{solver:n})]},n.getSolverName()))})},Yor=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:c})=>{const[A,l]=q.useReducer(B=>!B,!1),u=q.useRef(void 0),g=q.useRef(null),h="solver-debugger-last-iteration",[d,m]=q.useState(null),p=q.useRef(null),f=q.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"}],[]),_=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;u.current=setInterval(()=>{if(t.solved||t.failed){u.current&&(clearInterval(u.current),u.current=void 0),l(),e(),c&&t.solved&&c(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{u.current&&(clearInterval(u.current),u.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),c&&c(t))},x=()=>{A?(I(),l()):(l(),_())},E=()=>{if(t.solved||t.failed||A)return;g.current===null&&typeof window<"u"&&(g.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",g.current??`${t.iterations}`);if(B===null)return;g.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&c&&c(t)};return q.useEffect(()=>()=>{I()},[]),q.useEffect(()=>{(t.solved||t.failed)&&A&&(I(),l())},[t.solved,t.failed,A]),q.useEffect(()=>{A&&(I(),_())},[n,A]),q.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[K.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[K.jsxs("div",{className:"relative",children:[K.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&K.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(B=>K.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),K.jsxs("div",{className:"relative",children:[K.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&K.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:K.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),K.jsxs("div",{className:"relative",children:[K.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&K.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:f.map(B=>K.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&K.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),K.jsx(Gor,{solver:t})]})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.jsx("button",{onClick:C,disabled:t.solved||t.failed||A,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),K.jsx("button",{onClick:y,disabled:t.solved||t.failed||A,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),K.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${A?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:A?"Stop":"Animate"}),K.jsx("button",{onClick:E,disabled:t.solved||t.failed||A,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"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Uor=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),Kor=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},zor=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Kor(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let c=0;if(i==="Completed"){const g=t.pipelineDef[e+1],h=g?t.firstIterationOfStage?.[g.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const A=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:l,timeSpent:A,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},Vor=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Jor=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},D3n=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},Wor=t=>Object.entries(t).map(([e,n])=>`${e}: ${D3n(n)}`).join(", "),jor=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=Wor(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",D3n(i)]},o))})]})},Cet=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Cet);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Cet(o));return e},$or=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Cet(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},qor=({expanded:t})=>K.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 ${t?"rotate-90":""}`,children:K.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"})}),N3n=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},R3n=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=q.useState(new Set),c=t.pipelineDef.map((p,f)=>zor(t,f)),A=p=>{a(f=>{const _=new Set(f);return _.has(p)?_.delete(p):_.add(p),_})},l=p=>{e?.(p)},u=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):$or(p.solverInstance,p.name))},g=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=N3n(t);for(;!t.solved&&!t.failed&&(t.step(),N3n(t)===p););r?.()}},m=i*24;return K.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&K.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),K.jsxs("div",{className:"flex gap-2",children:[K.jsx("button",{onClick:d,disabled:t.solved||t.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"}),K.jsx("button",{onClick:h,disabled:t.solved||t.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"})]})]}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[!o&&K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:c.map(p=>{const f=Uor(p.solverInstance),_=s.has(p.name);return K.jsxs(Fs.Fragment,{children:[K.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[f?K.jsx("button",{onClick:()=>A(p.name),className:"text-gray-500 hover:text-gray-700",title:_?"Collapse":"Expand",children:K.jsx(qor,{expanded:_})}):K.jsx("span",{className:"w-4"}),K.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),K.jsx("button",{onClick:()=>l(p.name),disabled:p.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${p.name} completes`,children:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Vor,{status:p.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Jor,{progress:p.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:g(p.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(jor,{stats:p.stats})}),K.jsx("td",{className:"px-4 py-2",children:p.solverInstance?K.jsxs("button",{onClick:()=>u(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]}),f&&_&&K.jsx("tr",{children:K.jsx("td",{colSpan:8,className:"p-0",children:K.jsx(R3n,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function Xor({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,A=Number.NEGATIVE_INFINITY;const l=(p,f)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof f=="number"&&(f<a&&(a=f),f>A&&(A=f))};for(const p of e)l(p.x,p.y);for(const p of n){const f=p.points??[];for(const _ of f)l(_.x,_.y)}for(const p of o){const f=p.x??0,_=p.y??0,I=p.width??0,C=p.height??0;l(f,_),l(f+I,_+C)}for(const p of i){const f=p.x??0,_=p.y??0,I=p.radius??1;l(f-I,_-I),l(f+I,_+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(A))&&(s=-20,a=-20,c=20,A=20);const u=10,g=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,A-a+2*u);return K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${g} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,f)=>K.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${f}`)),n.map((p,f)=>K.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${f}`)),i.map((p,f)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${f}`)),e.map((p,f)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${f}`)),r.map((p,f)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${f}`))]})}var Zor=class extends Fs.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}},eir=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=q.useReducer(_=>_+1,0),[a]=q.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[c,A]=q.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,u]=q.useState(n),g=q.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(_){return console.error("Visualization error:",_),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=q.useMemo(()=>(g.rects?.length||0)===0&&(g.lines?.length||0)===0&&(g.points?.length||0)===0&&(g.circles?.length||0)===0,[g]);q.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const _=document.createElement("script");_.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(_)}},[]),q.useEffect(()=>{u(n)},[n]);const d=a.pipelineDef!==void 0,m=_=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===_);)a.step();s()}},p=()=>{const _=JSON.stringify(g,null,2),I=new Blob([_],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},f=_=>{A(_),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",_)};return K.jsxs("div",{children:[K.jsx(Yor,{solver:a,triggerRender:s,animationSpeed:l,renderer:c,onRendererChange:f,onAnimationSpeedChange:u,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(Zor,{fallback:K.jsx(Xor,{graphics:g}),children:c==="canvas"?K.jsx(Hor,{graphics:g}):K.jsx(kor,{graphics:g})}),d&&K.jsx(R3n,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const tir=()=>{q.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},nir=1e3,o5=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},nir)},yet=t=>{let e=t.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(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},oir=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},kb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",T3n="https://github.com/tscircuit/copper-pour-solver/issues/new",k3n="https://github.com/tscircuit/calculate-packing/issues/new",iir="https://github.com/tscircuit/matchpack/issues/new",F3n="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",rir={PackSolver2:k3n,LayoutPipelineSolver:iir,AutoroutingPipelineSolver:kb,AssignableAutoroutingPipeline2:kb,AssignableAutoroutingPipeline3:kb,AutoroutingPipeline1_OriginalUnravel:kb,AutoroutingPipelineSolver3_HgPortPointPathing:kb,AutoroutingPipelineSolver4:kb,AutoroutingPipelineSolver5:kb,AutoroutingPipelineSolver7_MultiGraph:kb,AutoroutingPipelineSolver8:kb,CopperPourPipelineSolver:T3n,SchematicTracePipelineSolver:F3n},sir=t=>t.toLowerCase().includes("pack")?SCn:t.toLowerCase().includes("rout")?vCn:sVi,L3n=t=>{const e=rir[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?kb:n.includes("schematic")&&n.includes("trace")?F3n:n.includes("copperpour")?T3n:n.includes("pack")?k3n:null},air=t=>`${yet(`${t.componentName}-${t.solverName}`)}-solver-input.json`,H3n=t=>{o5(JSON.stringify(t.solverParams,null,2),{fileName:air(t),mimeType:"application/json"})},cir=({solverEvent:t})=>{const e=L3n(t.solverName);return K.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:[K.jsxs(Ic,{type:"button",variant:"outline",size:"sm",onClick:()=>H3n(t),children:[K.jsx(tte,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?K.jsx(Ic,{asChild:!0,variant:"outline",size:"sm",children:K.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[K.jsx(G_e,{className:"rf-w-4 rf-h-4"}),"Report"]})}):K.jsxs(Ic,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[K.jsx(G_e,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},Air=({solverEvent:t})=>{const e=L3n(t.solverName);return e?K.jsx(Ic,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:K.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:K.jsx(G_e,{className:"rf-w-4 rf-h-4"})})}):K.jsx(Ic,{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:K.jsx(G_e,{className:"rf-w-4 rf-h-4"})})},lir=({solverEvents:t=[]})=>{const[e,n]=q.useState(null);tir();const o=q.useMemo(()=>{const a=new Map;for(const c of t){const A=`${c.componentName}-${c.solverName}`;a.set(A,c)}return a},[t]),i=q.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=q.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=gNe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(gNe).join(", ")}`,classFound:!1};try{return{instance:new a(...oir(r)),error:null,classFound:!0}}catch(c){const A=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${A}`,classFound:!0}}},[r]);return t.length===0?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),A=e===a;return K.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${A?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=sir(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[K.jsx(cir,{solverEvent:r}),K.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:K.jsx(jE,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(eir,{solver:s.instance})})})]}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.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:[K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(Air,{solverEvent:r}),K.jsx(Ic,{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:()=>H3n(r),children:K.jsx(tte,{className:"rf-w-4 rf-h-4"})})]})]}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},uir=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],gir=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function dir(t,e){let n=-1,o=-1;for(let i=t.length-1;i>=0;i--){const r=t[i];if(r.status!=="running"||r.subcircuit_id!==e.subcircuit_id||r.componentDisplayName!==e.componentDisplayName)continue;let s=0,a=!1;for(const c of gir)if(!(r[c]===void 0||e[c]===void 0)){if(r[c]!==e[c]){a=!0;break}s++}!a&&s>o&&(n=i,o=s)}return n}function hir(t,e){const n=Object.fromEntries(uir.filter(s=>e[s]!==void 0).map(s=>[s,e[s]])),o=e.simpleRouteJson?structuredClone(e.simpleRouteJson):void 0,i=e.type==="autorouting:start"?-1:dir(t,e),r={...i===-1?{id:`autorouting_phase_${t.length+1}`}:t[i],...n,status:e.type==="autorouting:start"?"running":e.type==="autorouting:end"?"complete":"error",...e.type==="autorouting:start"?{startSimpleRouteJson:o}:e.type==="autorouting:end"?{endSimpleRouteJson:o}:{errorSimpleRouteJson:o,error:e.error?{...e.error}:void 0}};return i===-1?[...t,r]:t.map((s,a)=>a===i?r:s)}const mir=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),pir=new Set(["tscircuit","default","auto","auto_local"]);function fir(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function _ir(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&mir.get(n);if(o)return o;if(n&&!pir.has(n))return e;const i=t.solverName?.trim();if(i)return fir(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const xet="#fbbf24";function Iir(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function O3n(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function Cir(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function G3n(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...Cir(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let c=-1,A=Number.POSITIVE_INFINITY;return n.forEach((l,u)=>{if(l.route_type!=="wire")return;const g=Math.hypot(l.x-a.x,l.y-a.y);g<A&&(A=g,c=u)}),c},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((c,A)=>c-A)).filter(([a,c])=>a>=0&&c>a).sort(([a],[c])=>a-c),r=[];let s=0;for(const[a,c]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,c);return s<n.length&&r.push(n.slice(s)),r}function yir(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(O3n(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of G3n(r,o)){let a;for(const c of s){if(c.route_type==="through_pad"){a={...c.end,layer:c.end_layer,width:c.width};continue}const A=c.route_type==="wire"?c.layer:c.from_layer;a&&a.layer===A&&(a.x!==c.x||a.y!==c.y)&&e.push({points:[{x:a.x,y:a.y},{x:c.x,y:c.y}],strokeWidth:c.route_type==="wire"?c.width:a.width,strokeColor:xet,layer:A}),c.route_type==="via"&&n.push({center:{x:c.x,y:c.y},radius:c.outer_diameter/2,stroke:xet,fill:"transparent"}),a={x:c.x,y:c.y,layer:c.route_type==="wire"?c.layer:c.to_layer,width:c.route_type==="wire"?c.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function xir(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const Eir=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function Bir(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(A=>!Eir.has(A.type)&&!A.type.endsWith("_error")&&!A.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:Iir(e),s=new Set(t.filter(A=>A.type==="source_trace").map(A=>A.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(A,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],c=[];for(const A of r){const u=o.connections.find(h=>h.name===A.connection_name||h.source_trace_id===A.connection_name)?.source_trace_id??A.connection_name??"",g=G3n(A,o);for(const[h,d]of g.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${A.pcb_trace_id}_${h}_${xir(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(u)?u:void 0,route:d};c.push(m);for(const[p,f]of d.entries()){if(f.route_type!=="via")continue;const _=a.indexOf(f.from_layer),I=a.indexOf(f.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:f.x,y:f.y,outer_diameter:f.outer_diameter,hole_diameter:f.hole_diameter,layers:_>=0&&I>=0?a.slice(Math.min(_,I),Math.max(_,I)+1):[f.from_layer,f.to_layer]};c.push(C)}}}return[...i,...c]}const Eet=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,Y3n=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",U3n=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,bir={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},Sir=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=q.useState(null),[r,s]=q.useState("output"),[a,c]=q.useState(!0),[A,l]=q.useState(!1),u=q.useRef(null),[g,h]=q.useState(480),d=o?e.findIndex(N=>N.id===o.id&&U3n(N)===U3n(o)):-1,m=d<0?e.length-1:d,p=e[m],f=d<0,_=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!_?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=q.useMemo(()=>!p||!x?null:Bir(t??[],p,y),[t,p,x,y]),B=q.useMemo(()=>p&&y==="output"&&a?yir(p):{lines:[],circles:[]},[p,y,a]);if(q.useLayoutEffect(()=>{const N=u.current;if(!N)return;const F=()=>h(Math.max(360,N.clientHeight));F();const O=new ResizeObserver(F);return O.observe(N),()=>O.disconnect()},[!!p]),!p)return K.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:[K.jsx(vCn,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),K.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),K.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"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 b=Eet(p,m),Q=p.status==="running"&&n,w=!_,M=I?.connections.length,T=E?.filter(N=>N.type==="pcb_trace").length??0;return K.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:[K.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:[K.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:[K.jsx("span",{children:"Routing phases"}),K.jsx("span",{children:e.length})]}),K.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:e.map((N,F)=>{const O=O3n(N).length,U=N.endSimpleRouteJson?`${O} ${O===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&n?"Routing…":"No output";return K.jsxs("button",{type:"button","aria-pressed":F===m,title:`${Y3n(N)} · ${U}`,onClick:()=>i(N),className:Li("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",F===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[K.jsx("span",{className:Li("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",F===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:F+1}),K.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[K.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[K.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:Eet(N,F),children:Eet(N,F)}),N.status==="complete"?K.jsx(sQ,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?K.jsx(LXe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?K.jsx($E,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),K.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[_ir(N)," · ",U]})]})]},N.id)})})]}),K.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[K.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:[K.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,K.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&K.jsx("button",{type:"button",onClick:()=>i(null),disabled:f,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:f?"Following latest":"Follow latest"}),K.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>K.jsx("button",{type:"button","aria-pressed":y===N,disabled:N==="input"?!C:!_,onClick:()=>s(N),className:Li("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),K.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:[K.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:N=>c(N.target.checked),className:"rf-accent-blue-600"}),K.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:xet}}),"Highlight changes (all layers)"]}),K.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",T," traces"]})]}),w&&K.jsx("div",{className:Li("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.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:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),K.jsx("div",{ref:u,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?K.jsx(TXe,{circuitJson:E,height:g,allowEditing:!1,clickToInteractEnabled:!1,initialState:bir,debugGraphics:B}):K.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),K.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:[K.jsxs("span",{children:[M===void 0?"Input unavailable":`${M} input connections`,` · ${Y3n(p)}`]}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[K.jsxs("button",{type:"button",disabled:!x,onClick:()=>o5(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[K.jsx(tte,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),K.jsxs("button",{type:"button","aria-expanded":A,onClick:()=>l(!A),className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(hk,{className:Li("rf-h-3 rf-w-3",A&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),A&&K.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":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},K3n=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{q.useEffect(()=>{if(DS("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&t){const o=new Error(t);e&&(o.stack=e);try{ZG.captureException(o)}catch{}}},[t,e]),q.useEffect(()=>{if(DS("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{ZG.captureException(i,{error_type:o.type})}catch{}}},[n])},z3n=t=>{q.useEffect(()=>{try{Tei(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},V3n="0.0.2957",Qir={version:V3n},cIe=mGt()(pGt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),vir=t=>{const[e,n]=q.useState([]),[o,i]=q.useState(null),[r,s]=q.useState(""),[a,c]=xG("eval-version-selection",null),A=cIe(h=>h.setLastRunEvalVersion),l=cIe(h=>h.lastRunEvalVersion);return q.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),q.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,A(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,A(o)))},[t,a,o]),{versions:q.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{c(h),s("")}}},wir=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=q.useState(""),[s,a]=q.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),A=s&&!t.includes(s),l=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):A&&r(s))};return K.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:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:u=>a(u.target.value),onKeyDown:l}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),A&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.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:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},Pir=t=>{const e=q.useRef(null),n=xd(o=>o.recentEvents);q.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};var Mir=Object.defineProperty,mQ=(t,e)=>Mir(t,"name",{value:e,configurable:!0}),Dir="AlertDialog",[Nir,abr]=jx(Dir,[t2n]),pQ=t2n(),Rir=mQ(t=>{const{__scopeAlertDialog:e,...n}=t,o=pQ(e);return K.jsx(B1e,{...o,...n,modal:!0})},"AlertDialog");q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(Mji,{...r,...i,ref:n})},"AlertDialogTrigger"));var Tir=mQ(t=>{const{__scopeAlertDialog:e,...n}=t,o=pQ(e);return K.jsx(b1e,{...o,...n})},"AlertDialogPortal"),J3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(hte,{...r,...i,ref:n})},"AlertDialogOverlay")),kir="AlertDialogContent",[Fir,Lir]=Nir(kir),W3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=pQ(o),a=q.useRef(null),c=Lc(n,a),A=q.useRef(null);return K.jsx(Fir,{scope:o,cancelRef:A,children:K.jsx(pte,{role:"alertdialog",...s,...r,ref:c,onOpenAutoFocus:rr(r.onOpenAutoFocus,l=>{l.preventDefault(),A.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),j3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(S1e,{...r,...i,ref:n})},"AlertDialogTitle")),$3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(Q1e,{...r,...i,ref:n})},"AlertDialogDescription")),q3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(QZe,{...r,...i,ref:n})},"AlertDialogAction")),Hir="AlertDialogCancel",X3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=Lir(Hir,o),s=pQ(o),a=Lc(n,r);return K.jsx(QZe,{...s,...i,ref:a})},"AlertDialogCancel"));const Z3n=Rir,Oir=Tir,eEn=q.forwardRef(({className:t,...e},n)=>K.jsx(J3n,{className:Li("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",t),...e,ref:n}));eEn.displayName=J3n.displayName;const Bet=q.forwardRef(({className:t,...e},n)=>K.jsxs(Oir,{children:[K.jsx(eEn,{}),K.jsx(W3n,{ref:n,className:Li("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",t),...e})]}));Bet.displayName=W3n.displayName;const bet=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});bet.displayName="AlertDialogHeader";const Qet=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});Qet.displayName="AlertDialogFooter";const vet=q.forwardRef(({className:t,...e},n)=>K.jsx(j3n,{ref:n,className:Li("rf-text-lg rf-font-semibold",t),...e}));vet.displayName=j3n.displayName;const wet=q.forwardRef(({className:t,...e},n)=>K.jsx($3n,{ref:n,className:Li("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));wet.displayName=$3n.displayName;const Gir=q.forwardRef(({className:t,...e},n)=>K.jsx(q3n,{ref:n,className:Li(yK(),t),...e}));Gir.displayName=q3n.displayName;const Pet=q.forwardRef(({className:t,...e},n)=>K.jsx(X3n,{ref:n,className:Li(yK({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));Pet.displayName=X3n.displayName;var Yir=Object.defineProperty,fQ=(t,e)=>Yir(t,"name",{value:e,configurable:!0}),Met="Checkbox",[Uir,cbr]=jx(Met),[Kir,Det]=Uir(Met);function tEn(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:c,required:A,value:l="on",internal_do_not_use_render:u}=t,[g,h]=o9({prop:n,defaultProp:i??!1,onChange:c,caller:Met}),[d,m]=q.useState(null),[p,f]=q.useState(null),_=q.useRef(!1),[I,C]=q.useReducer(E=>E+1,0),y=d?!!s||!!d.closest("form"):!0,x={checked:g,disabled:r,setChecked:h,control:d,setControl:m,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:_,userInteractionCount:I,onUserInteraction:C,required:A,defaultChecked:_Q(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:f};return K.jsx(Kir,{scope:e,...x,children:oEn(u)?u(x):o})}fQ(tEn,"CheckboxProvider");var zir="CheckboxTrigger",Vir=q.forwardRef(fQ(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:c,checked:A,required:l,setControl:u,setChecked:g,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:m,bubbleInput:p}=Det(zir,e),f=Lc(r,u),_=q.useRef(A);return q.useEffect(()=>{const I=s?.form;if(I){const C=fQ(()=>g(_.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,g]),K.jsx(Ta.button,{type:"button",role:"checkbox","aria-checked":_Q(A)?"mixed":A,"aria-required":l,"data-state":Net(A),"data-disabled":c?"":void 0,disabled:c,value:a,...i,ref:f,onKeyDown:rr(n,I=>{I.key==="Enter"&&I.preventDefault()}),onClick:rr(o,I=>{d(),g(C=>_Q(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),nEn=q.forwardRef(fQ(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:c,value:A,onCheckedChange:l,form:u,...g}=e;return K.jsx(tEn,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:c,required:a,onCheckedChange:l,name:i,form:u,value:A,internal_do_not_use_render:({isFormControl:h})=>K.jsxs(K.Fragment,{children:[K.jsx(Vir,{...g,ref:n,__scopeCheckbox:o}),h&&K.jsx($ir,{__scopeCheckbox:o})]})})},"Checkbox")),Jir="CheckboxIndicator",Wir=q.forwardRef(fQ(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=Det(Jir,o);return K.jsx(vE,{present:i||_Q(s.checked)||s.checked===!0,children:K.jsx(Ta.span,{"data-state":Net(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),jir="CheckboxBubbleInput",$ir=q.forwardRef(fQ(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:c,defaultChecked:A,required:l,disabled:u,name:g,value:h,form:d,bubbleInput:m,setBubbleInput:p}=Det(jir,e),f=Lc(i,p),_=cZe(r),I=q.useRef(!1),C=q.useRef(c),y=q.useRef(a);q.useEffect(()=>{const E=m;if(!E)return;const B=window.HTMLInputElement.prototype,Q=Object.getOwnPropertyDescriptor(B,"checked").set,w=a!==y.current;y.current=a;const M=C.current!==c;C.current=c;const T=!(w&&s.current);if(M&&Q){I.current=!w;const N=new Event("click",{bubbles:T});E.indeterminate=_Q(c),Q.call(E,_Q(c)?!1:c),E.dispatchEvent(N),I.current=!1}},[m,c,s,a]);const x=q.useRef(_Q(c)?!1:c);return K.jsx(Ta.input,{type:"checkbox","aria-hidden":!0,defaultChecked:A??x.current,required:l,disabled:u,name:g,value:h,form:d,...o,tabIndex:-1,ref:f,onClick:rr(n,E=>{I.current&&E.stopPropagation()}),style:{...o.style,..._,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function oEn(t){return typeof t=="function"}fQ(oEn,"isFunction");function _Q(t){return t==="indeterminate"}fQ(_Q,"isIndeterminate");function Net(t){return _Q(t)?"indeterminate":t?"checked":"unchecked"}fQ(Net,"getState");const Lte=q.forwardRef(({className:t,...e},n)=>K.jsx(nEn,{ref:n,className:Li("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",t),...e,children:K.jsx(Wir,{className:Li("rf-flex rf-items-center rf-justify-center rf-text-current"),children:K.jsx(sQ,{className:"rf-h-4 rf-w-4"})})}));Lte.displayName=nEn.displayName;const Ek=B1e,qir=b1e,iEn=q.forwardRef(({className:t,...e},n)=>K.jsx(hte,{className:Li("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",t),...e,ref:n}));iEn.displayName=hte.displayName;const SM=q.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>K.jsxs(qir,{children:[K.jsx(iEn,{className:Li(n?"":"rf-hidden")}),K.jsx(pte,{ref:i,className:Li("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",t),...o,children:e})]}));SM.displayName=pte.displayName;const QM=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});QM.displayName="DialogHeader";const jK=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});jK.displayName="DialogFooter";const vM=q.forwardRef(({className:t,...e},n)=>K.jsx(S1e,{ref:n,className:Li("rf-text-lg rf-font-semibold",t),...e}));vM.displayName=S1e.displayName;const Bk=q.forwardRef(({className:t,...e},n)=>K.jsx(Q1e,{ref:n,className:Li("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));Bk.displayName=Q1e.displayName;const AIe={"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"}},Xir="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let Ret=null;const Tet=async()=>(Ret||(Ret=import(Xir)),Ret),Zir=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??g2}/proxy`,{...n,headers:{...i,"X-Target-Url":e.toString(),"X-Sender-Origin":i.origin??"","X-Sender-Host":i.host??"https://easyeda.com","X-Sender-Referer":i.referer??"","X-Sender-User-Agent":i["user-agent"]??"","X-Sender-Cookie":i.cookie??"",authority:i.authority??"","content-type":i["content-type"]??"",...t?.headers}})},err=async(t,e=10)=>{const n=encodeURIComponent(t),o=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${n}`);if(!o.ok)throw new Error(`JLCPCB API error: ${o.status}`);return(await o.json()).components??[]},trr=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),rEn=async(t,e)=>{const{fetchEasyEDAComponent:n}=await Tet();return n(t,{fetch:Zir(e),includeModelMetadata:e?.includeModelMetadata})},nrr=async(t,e)=>{const{convertRawEasyToTsx:n}=await Tet(),o=await rEn(t,e);return n({rawEasy:o})},orr=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await Tet(),i=await rEn(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function wM(t){return Array.isArray?Array.isArray(t):aEn(t)==="[object Array]"}function irr(t){if(typeof t=="string")return t;if(typeof t=="bigint")return t.toString();const e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function ket(t){return t==null?"":irr(t)}function ZC(t){return typeof t=="string"}function lIe(t){return typeof t=="number"}function rrr(t){return t===!0||t===!1||srr(t)&&aEn(t)=="[object Boolean]"}function sEn(t){return typeof t=="object"}function srr(t){return sEn(t)&&t!==null}function i5(t){return t!=null}function uIe(t){return!t.trim().length}function aEn(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const arr="Incorrect 'index' type",Fet="Invalid doc index: must be a non-negative integer within the bounds of the docs array",crr=t=>`Invalid value for key ${t}`,Arr=t=>`Pattern length exceeds max of ${t}.`,lrr=t=>`Missing ${t} property in key`,urr=t=>`Property 'weight' in key '${t}' must be a positive integer`,grr="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.",cEn=Object.prototype.hasOwnProperty;var drr=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=AEn(n);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function AEn(t){let e=null,n=null,o=null,i=1,r=null;if(ZC(t)||wM(t))o=t,e=lEn(t),n=gIe(t);else{if(!cEn.call(t,"name"))throw new Error(lrr("name"));const s=t.name;if(o=s,cEn.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(urr(gIe(s)));e=lEn(s),n=gIe(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function lEn(t){return wM(t)?t:t.split(".")}function gIe(t){return wM(t)?t.join("."):t}function hrr(t,e){const n=[];let o=!1;const i=(r,s,a,c)=>{if(i5(r))if(!s[a])n.push(c!==void 0?{v:r,i:c}:r);else{const A=r[s[a]];if(!i5(A))return;if(a===s.length-1&&(ZC(A)||lIe(A)||rrr(A)||typeof A=="bigint"))n.push(c!==void 0?{v:ket(A),i:c}:ket(A));else if(wM(A)){o=!0;for(let l=0,u=A.length;l<u;l+=1)i(A[l],s,a+1,l)}else s.length&&i(A,s,a+1,c)}};return i(t,ZC(e)?e.split("."):e,0),o?n:n[0]}const Pa=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.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:hrr,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function mrr(t){return t>=9&&t<=13||t===32||t===160}function prr(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let c=0;c<i.length;c++)mrr(i.charCodeAt(c))?s=!1:s||(r++,s=!0);if(r===0&&(r=1),n.has(r))return n.get(r);const a=Math.round(o/Math.pow(r,.5*t))/o;return n.set(r,a),a},clear(){n.clear()}}}var Let=class{constructor({getFn:t=Pa.getFn,fieldNormWeight:e=Pa.fieldNormWeight}={}){this.norm=prr(e,3),this.getFn=t,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,n)=>{this._keysMap[e.id]=n})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const t=this.docs.length;this.records=new Array(t);let e=0;if(ZC(this.docs[0]))for(let n=0;n<t;n++){const o=this._createStringRecord(this.docs[n],n);o&&(this.records[e++]=o)}else for(let n=0;n<t;n++)this.records[e++]=this._createObjectRecord(this.docs[n],n);this.records.length=e,this.norm.clear()}add(t,e){if(!Number.isInteger(e)||e<0)throw new Error(Fet);if(ZC(t)){const o=this._createStringRecord(t,e);return o&&this.records.push(o),o}const n=this._createObjectRecord(t,e);return this.records.push(n),n}removeAt(t){if(!Number.isInteger(t)||t<0)throw new Error(Fet);for(let e=0,n=this.records.length;e<n;e+=1)if(this.records[e].i===t){this.records.splice(e,1);break}for(let e=0,n=this.records.length;e<n;e+=1)this.records[e].i>t&&(this.records[e].i-=1)}removeAll(t){const e=new Set;for(const o of t)Number.isInteger(o)&&o>=0&&e.add(o);if(e.size===0)return;this.records=this.records.filter(o=>!e.has(o.i));const n=Array.from(e).sort((o,i)=>o-i);for(const o of this.records){let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s]<o.i?i=s+1:r=s}o.i-=i}}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_createStringRecord(t,e){return!i5(t)||uIe(t)?null:{v:t,i:e,n:this.norm.get(t)}}_createObjectRecord(t,e){const n={i:e,$:{}};for(let o=0,i=this.keys.length;o<i;o++){const r=this.keys[o],s=r.getFn?r.getFn(t):this.getFn(t,r.path);if(i5(s)){if(wM(s)){const a=[];for(let c=0,A=s.length;c<A;c+=1){const l=s[c];if(i5(l)){if(ZC(l)){if(!uIe(l)){const u={v:l,i:c,n:this.norm.get(l)};a.push(u)}}else if(i5(l.v)){const u=ZC(l.v)?l.v:ket(l.v);if(!uIe(u)){const g={v:u,i:l.i,n:this.norm.get(u)};a.push(g)}}}}n.$[o]=a}else if(ZC(s)&&!uIe(s)){const a={v:s,n:this.norm.get(s)};n.$[o]=a}}}return n}toJSON(){return{keys:this.keys.map(({getFn:t,...e})=>e),records:this.records}}};function uEn(t,e,{getFn:n=Pa.getFn,fieldNormWeight:o=Pa.fieldNormWeight}={}){const i=new Let({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(AEn)),i.setSources(e),i.create(),i}function frr(t,{getFn:e=Pa.getFn,fieldNormWeight:n=Pa.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new Let({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function _rr(t=[],e=Pa.minMatchCharLength){const n=[];let o=-1,i=-1,r=0;for(let s=t.length;r<s;r+=1){const a=t[r];a&&o===-1?o=r:!a&&o!==-1&&(i=r-1,i-o+1>=e&&n.push([o,i]),o=-1)}return t[r-1]&&r-o>=e&&n.push([o,r-1]),n}function Irr(t,e,n,{location:o=Pa.location,distance:i=Pa.distance,threshold:r=Pa.threshold,findAllMatches:s=Pa.findAllMatches,minMatchCharLength:a=Pa.minMatchCharLength,includeMatches:c=Pa.includeMatches,ignoreLocation:A=Pa.ignoreLocation}={}){if(e.length>32)throw new Error(Arr(32));const l=e.length,u=t.length,g=Math.max(0,Math.min(o,u));let h=r,d=g;const m=(b,Q)=>{const w=b/l;if(A)return w;const M=Math.abs(g-Q);return i?w+M/i:M?1:w},p=a>1||c,f=p?Array(u):[];let _;for(;(_=t.indexOf(e,d))>-1;){const b=m(0,_);if(h=Math.min(b,h),d=_+l,p){let Q=0;for(;Q<l;)f[_+Q]=1,Q+=1}}d=-1;let I=[],C=1,y=0,x=l+u;const E=1<<l-1;for(let b=0;b<l;b+=1){let Q=0,w=x;for(;Q<w;)m(b,g+w)<=h?Q=w:x=w,w=Math.floor((x-Q)/2+Q);x=w;let M=Math.max(1,g-w+1);const T=s?u:Math.min(g+w,u)+l,N=Array(T+2);N[T+1]=(1<<b)-1;for(let F=T;F>=M;F-=1){const O=F-1,U=n[t[O]];if(N[F]=(N[F+1]<<1|1)&U,b&&(N[F]|=(I[F+1]|I[F])<<1|1|I[F+1]),N[F]&E&&(C=m(b,O),C<=h)){if(h=C,d=O,y=b,d<=g)break;M=Math.max(1,2*g-d)}}if(m(b+1,g)>h)break;I=N}if(p&&d>=0){const b=Math.min(u-1,d+l-1+y);for(let Q=d;Q<=b;Q+=1)n[t[Q]]&&(f[Q]=1)}const B={isMatch:d>=0,score:Math.max(.001,C)};if(p){const b=_rr(f,a);b.length?c&&(B.indices=b):B.isMatch=!1}return B}function Crr(t){const e={};for(let n=0,o=t.length;n<o;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<o-n-1}return e}function Het(t){if(t.length<=1)return t;t.sort((n,o)=>n[0]-o[0]||n[1]-o[1]);const e=[t[0]];for(let n=1,o=t.length;n<o;n+=1){const i=e[e.length-1],r=t[n];r[0]<=i[1]+1?i[1]=Math.max(i[1],r[1]):e.push(r)}return e}const gEn={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},yrr=new RegExp("["+Object.keys(gEn).join("")+"]","g"),Hte=typeof String.prototype.normalize=="function"?t=>t.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(yrr,e=>gEn[e]):t=>t;var Oet=class{constructor(t,{location:e=Pa.location,threshold:n=Pa.threshold,distance:o=Pa.distance,includeMatches:i=Pa.includeMatches,findAllMatches:r=Pa.findAllMatches,minMatchCharLength:s=Pa.minMatchCharLength,isCaseSensitive:a=Pa.isCaseSensitive,ignoreDiacritics:c=Pa.ignoreDiacritics,ignoreLocation:A=Pa.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:c,ignoreLocation:A},t=a?t:t.toLowerCase(),t=c?Hte(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(g,h)=>{this.chunks.push({pattern:g,alphabet:Crr(g),startIndex:h})},u=this.pattern.length;if(u>32){let g=0;const h=u%32,d=u-h;for(;g<d;)l(this.pattern.substr(g,32),g),g+=32;if(h){const m=u-32;l(this.pattern.substr(m),m)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?Hte(t):t,this.pattern===t){if(t.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const d={isMatch:!0,score:0};return o&&(d.indices=[[0,t.length-1]]),d}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,ignoreLocation:A}=this.options,l=[];let u=0,g=!1;this.chunks.forEach(({pattern:d,alphabet:m,startIndex:p})=>{const{isMatch:f,score:_,indices:I}=Irr(t,d,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,includeMatches:o,ignoreLocation:A});f&&(g=!0),u+=_,f&&I&&l.push(...I)});const h={isMatch:g,score:g?u/this.chunks.length:1};return g&&o&&(h.indices=Het(l)),h}};const xrr=new Set(["fuzzy","include"]);function Err(t){return t.startsWith("inverse")}const Get=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:t=>({type:"exact",search(e){const n=e===t;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:t=>({type:"include",search(e){let n=0,o;const i=[],r=t.length;for(;(o=e.indexOf(t,n))>-1;)n=o+r,i.push([o,n-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:t=>({type:"prefix-exact",search(e){const n=e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:t=>({type:"inverse-prefix-exact",search(e){const n=!e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:t=>({type:"inverse-suffix-exact",search(e){const n=!e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:t=>({type:"suffix-exact",search(e){const n=e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[e.length-t.length,e.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:t=>({type:"inverse-exact",search(e){const n=e.indexOf(t)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(t,e={})=>{const n=new Oet(t,{location:e.location??Pa.location,threshold:e.threshold??Pa.threshold,distance:e.distance??Pa.distance,includeMatches:e.includeMatches??Pa.includeMatches,findAllMatches:e.findAllMatches??Pa.findAllMatches,minMatchCharLength:e.minMatchCharLength??Pa.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??Pa.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??Pa.ignoreDiacritics,ignoreLocation:e.ignoreLocation??Pa.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],dEn=Get.length,Brr="\0",brr="|";function Srr(t){const e=[],n=t.length;let o=0;for(;o<n;){for(;o<n&&t[o]===" ";)o++;if(o>=n)break;let i=o;for(;i<n&&t[i]!==" "&&t[i]!=='"';)i++;if(i<n&&t[i]==='"'){for(i++;i<n;){if(t[i]==='"'){const r=i+1;if(r>=n||t[r]===" "){i++;break}if(t[r]==="$"&&(r+1>=n||t[r+1]===" ")){i+=2;break}}i++}e.push(t.substring(o,i)),o=i}else{for(;i<n&&t[i]!==" ";)i++;e.push(t.substring(o,i)),o=i}}return e}function hEn(t,e){const n=t.match(e);return n?n[1]:null}function Qrr(t,e={}){return t.replace(/\\\|/g,Brr).split(brr).map(n=>{const o=Srr(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let c=!1,A=-1;for(;!c&&++A<dEn;){const l=Get[A],u=hEn(a,l.multiRegex);u&&(i.push(l.create(u,e)),c=!0)}if(!c)for(A=-1;++A<dEn;){const l=Get[A],u=hEn(a,l.singleRegex);if(u){i.push(l.create(u,e));break}}}return i})}var vrr=class{constructor(t,{isCaseSensitive:e=Pa.isCaseSensitive,ignoreDiacritics:n=Pa.ignoreDiacritics,includeMatches:o=Pa.includeMatches,minMatchCharLength:i=Pa.minMatchCharLength,ignoreLocation:r=Pa.ignoreLocation,findAllMatches:s=Pa.findAllMatches,location:a=Pa.location,threshold:c=Pa.threshold,distance:A=Pa.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:c,distance:A},t=e?t:t.toLowerCase(),t=n?Hte(t):t,this.pattern=t,this.query=Qrr(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:o,ignoreDiacritics:i}=this.options;t=o?t:t.toLowerCase(),t=i?Hte(t):t;let r=0;const s=[];let a=0,c=!1;for(let A=0,l=e.length;A<l;A+=1){const u=e[A];s.length=0,r=0,c=!1;for(let g=0,h=u.length;g<h;g+=1){const d=u[g],{isMatch:m,indices:p,score:f}=d.search(t);if(m)r+=1,a+=f,Err(d.type)&&(c=!0),n&&(xrr.has(d.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,c=!1;break}}if(r){const g={isMatch:!0,score:a/r};return c&&(g.hasInverse=!0),n&&(g.indices=Het(s)),g}}return{isMatch:!1,score:1}}};const Yet=[];function Uet(...t){Yet.push(...t)}function dIe(t,e){for(let n=0,o=Yet.length;n<o;n+=1){const i=Yet[n];if(i.condition(t,e))return new i(t,e)}return new Oet(t,e)}const hIe={AND:"$and",OR:"$or"},Ket={PATH:"$path",PATTERN:"$val"},zet=t=>!!(t[hIe.AND]||t[hIe.OR]),wrr=t=>!!t[Ket.PATH],Prr=t=>!wM(t)&&sEn(t)&&!zet(t),mEn=t=>({[hIe.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function pEn(t,e,{auto:n=!0}={}){const o=i=>{if(ZC(i)){const c={keyId:null,pattern:i};return n&&(c.searcher=dIe(i,e)),c}const r=Object.keys(i),s=wrr(i);if(!s&&r.length>1&&!zet(i))return o(mEn(i));if(Prr(i)){const c=s?i[Ket.PATH]:r[0],A=s?i[Ket.PATTERN]:i[c];if(!ZC(A))throw new Error(crr(c));const l={keyId:gIe(c),pattern:A};return n&&(l.searcher=dIe(A,e)),l}const a={children:[],operator:r[0]};return r.forEach(c=>{const A=i[c];wM(A)&&A.forEach(l=>{a.children.push(o(l))})}),a};return zet(t)||(t=mEn(t)),o(t)}function Vet(t,{ignoreFieldNorm:e=Pa.ignoreFieldNorm}){let n=1;return t.forEach(({key:o,norm:i,score:r})=>{const s=o?o.weight:null;n*=Math.pow(r===0&&s?Number.EPSILON:r,(s||1)*(e?1:i))}),n}function Mrr(t,{ignoreFieldNorm:e=Pa.ignoreFieldNorm}){t.forEach(n=>{n.score=Vet(n.matches,{ignoreFieldNorm:e})})}var Drr=class{constructor(t,e){this.limit=t,this.heap=[],this.comparator=e}get size(){return this.heap.length}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):this.comparator(t,this.heap[0])<0&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(this.comparator(e[t],e[n])<=0)break;const o=e[t];e[t]=e[n],e[n]=o,t=n}}_sinkDown(t){const e=this.heap,n=e.length;let o=t;do{t=o;const i=2*t+1,r=2*t+2;if(i<n&&this.comparator(e[i],e[o])>0&&(o=i),r<n&&this.comparator(e[r],e[o])>0&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function Nrr(t){const e=[];return t.matches.forEach(n=>{if(!i5(n.indices)||!n.indices.length)return;const o={indices:n.indices,value:n.value};n.key&&(o.key=n.key.id),n.idx>-1&&(o.refIndex=n.idx),e.push(o)}),e}function Rrr(t,e,{includeMatches:n=Pa.includeMatches,includeScore:o=Pa.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=Nrr(i)),o&&(s.score=i.score),s})}const Trr=/[\p{L}\p{M}\p{N}_]+/gu,fEn=new WeakSet;function krr(t){fEn.has(t)||(fEn.add(t),console.warn(`[Fuse] tokenize regex ${t} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Frr(t){if(typeof t=="function"){let e=!1;return n=>{const o=t(n);if(!e&&(e=!0,!Array.isArray(o)||o.some(i=>typeof i!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(o)?"array containing non-strings":typeof o}.`);return o}}return t instanceof RegExp?(t.global||krr(t),e=>e.match(t)||[]):e=>e.match(Trr)||[]}function Jet({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=Frr(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=Hte(i)),o(i)}}}var Lrr=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=Jet({isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,tokenize:e.tokenize});const n=this.analyzer.tokenize(t),{df:o,fieldCount:i}=e._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const r of n){this.termSearchers.push(new Oet(r,{location:e.location,threshold:e.threshold,distance:e.distance,includeMatches:e.includeMatches,findAllMatches:e.findAllMatches,minMatchCharLength:e.minMatchCharLength,isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,ignoreLocation:!0}));const s=o.get(r)||0,a=Math.log(1+(i-s+.5)/(s+.5));this.idfWeights.push(a)}this.combineAll=e.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(t){if(!this.termSearchers.length)return{isMatch:!1,score:1};const e=[];let n=0,o=0,i=0,r=0;const s=this.combineAll&&!this.useMask?new Set:null;for(let A=0;A<this.termSearchers.length;A++){const l=this.termSearchers[A].searchIn(t),u=this.idfWeights[A];o+=u,l.isMatch&&(i++,n+=u*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<A:s.add(A)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,c={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(c.indices=Het(e)),this.combineAll&&(this.useMask?c.matchedMask=r:c.matchedTerms=s,c.termCount=this.numTerms),c}};function Wet(t,e,n,o){const i=o.tokenize(e);if(!i.length)return;t.fieldCount++,t.docFieldCount.set(n,(t.docFieldCount.get(n)||0)+1);const r=new Set(i);let s=t.docTermFieldHits.get(n);s||(s=new Map,t.docTermFieldHits.set(n,s));for(const a of r)s.set(a,(s.get(a)||0)+1),t.df.set(a,(t.df.get(a)||0)+1)}function _En(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){Wet(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const c=s[a];if(c)if(Array.isArray(c))for(const A of c)Wet(t,A.v,i,o);else Wet(t,c.v,i,o)}}function Hrr(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)_En(o,i,e,n);return o}function Orr(t,e,n,o){_En(t,e,n,o)}function Grr(t,e){const n=t.docFieldCount.get(e);if(n===void 0)return;t.fieldCount-=n,t.docFieldCount.delete(e);const o=t.docTermFieldHits.get(e);if(o){for(const[i,r]of o){const s=(t.df.get(i)||0)-r;s<=0?t.df.delete(i):t.df.set(i,s)}t.docTermFieldHits.delete(e)}}function IEn(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,c)=>a-c);for(const a of n)Grr(t,a);const o=a=>{let c=0,A=n.length;for(;c<A;){const l=c+A>>>1;n[l]<a?c=l+1:A=l}return a-c},i=n[0],r=new Map;for(const[a,c]of t.docFieldCount)r.set(a>i?o(a):a,c);t.docFieldCount=r;const s=new Map;for(const[a,c]of t.docTermFieldHits)s.set(a>i?o(a):a,c);t.docTermFieldHits=s}var PM=class{constructor(t,e,n){this.options={...Pa,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new drr(this.options.keys),this._docs=t,this._myIndex=null,this._invertedIndex=null,this.setCollection(t,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(t){if(this._lastQuery===t)return this._lastSearcher;const e=dIe(t,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=t,this._lastSearcher=e,e}setCollection(t,e){if(this._docs=t,e&&!(e instanceof Let))throw new Error(arr);if(this._myIndex=e||uEn(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=Jet({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Hrr(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!i5(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=Jet({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});Orr(this._invertedIndex,e,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}remove(t=()=>!1){const e=[],n=[];for(let o=0,i=this._docs.length;o<i;o+=1)t(this._docs[o],o)&&(e.push(this._docs[o]),n.push(o));if(n.length){this._invertedIndex&&IEn(this._invertedIndex,n);const o=new Set(n);this._docs=this._docs.filter((i,r)=>!o.has(r)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return e}removeAt(t){if(!Number.isInteger(t)||t<0||t>=this._docs.length)throw new Error(Fet);this._invertedIndex&&IEn(this._invertedIndex,[t]);const e=this._docs.splice(t,1)[0];return this._myIndex.removeAt(t),this._invalidateSearcherCache(),e}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(t=>this._keyStore.get(t.id)||t)}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(ZC(t)&&!t.trim()){let g=this._docs.map((h,d)=>({item:h,refIndex:d}));return lIe(n)&&n>-1&&(g=g.slice(0,n)),g}const c=r&&lIe(n)&&n>0&&ZC(t),A=s,l=(g,h)=>A(g,h)||g.idx-h.idx;let u;if(c){const g=new Drr(n,l);ZC(this._docs[0])?this._searchStringList(t,{heap:g,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:g,ignoreFieldNorm:a}),u=g.extractSorted()}else u=ZC(t)?ZC(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),Mrr(u,{ignoreFieldNorm:a}),r&&u.sort(ZC(t)?l:A),lIe(n)&&n>-1&&(u=u.slice(0,n));return Rrr(u,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:c,n:A})=>{if(!i5(a))return;const l=o.searchIn(a);if(l.isMatch){const u={score:l.score,value:a,norm:A,indices:l.indices};i&&(u.matchedMask=l.matchedMask,u.matchedTerms=l.matchedTerms,u.termCount=l.termCount);const g=[u];if(!i||this._coversAllTokens(g)){const h={item:a,idx:c,matches:g};e?(h.score=Vet(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=pEn(t,this.options),n=this._normalizedKeys(),o=(a,c,A)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let m;return h===null?(m=[],n.forEach((p,f)=>{m.push(...this._findMatches({key:p,value:c[f],searcher:d}))})):m=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(c,h),searcher:d}),m&&m.length?[{idx:A,item:c,matches:m}]:[]}const{children:l,operator:u}=a,g=[];for(let h=0,d=l.length;h<d;h+=1){const m=l[h],p=o(m,c,A);if(p.length)g.push(...p);else if(u===hIe.AND)return[]}return g},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:c})=>{if(i5(a)){const A=o(e,a,c);A.length&&(r.has(c)||(r.set(c,{idx:c,item:a,matches:[]}),s.push(r.get(c))),A.forEach(({matches:l})=>{r.get(c).matches.push(...l)}))}}),s}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=this._normalizedKeys(),a=e?null:[];return r.forEach(({$:c,i:A})=>{if(!i5(c))return;const l=[];let u=!1,g=!1;if(s.forEach((h,d)=>{const m=this._findMatches({key:h,value:c[d],searcher:o});m.length?(l.push(...m),m[0].hasInverse&&(g=!0)):u=!0}),!(g&&u)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:A,item:c,matches:l};e?(h.score=Vet(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!i5(e))return[];const o=[];if(wM(e))e.forEach(({v:i,i:r,n:s})=>{if(!i5(i))return;const a=n.searchIn(i);if(a.isMatch){const c={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(c.matchedMask=a.matchedMask,c.matchedTerms=a.matchedTerms,c.termCount=a.termCount),o.push(c)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};PM.version="7.5.0",PM.createIndex=uEn,PM.parseIndex=frr,PM.config=Pa,PM.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(grr);return dIe(t,{...Pa,...n}).searchIn(e)},PM.parseQuery=pEn,Uet(vrr),Uet(Lrr),PM.use=function(...t){t.forEach(e=>Uet(e))};var Yrr=PM;const Urr="https://kicad-mod-cache.tscircuit.com";let jet=null,Ote=null,$et=null;const Krr=async()=>jet||Ote||(Ote=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(jet=t,Ote=null,t)),Ote),zrr=async(t,e=20)=>{const n=await Krr();return $et||($et=new Yrr(n)),$et.search(t).slice(0,e).map(o=>o.item)},Vrr=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},Jrr=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),Wrr=async t=>{const e=await fetch(`${Urr}/${Jrr(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await n5("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},CEn=t=>t?.source==="jlcpcb"||t?.source==="kicad",jrr=async(t,e)=>{if(t.source==="jlcpcb")return orr(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return Wrr(t.footprint.path);throw new Error("Footprint preview is not available for this source")},$rr=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=q.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[K.jsxs("div",{className:"rf-relative rf-flex-grow",children:[K.jsx(HXe,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),K.jsx(het,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),K.jsx(Ic,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):K.jsxs(K.Fragment,{children:[K.jsx(HXe,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),K.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},qrr=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Xrr=t=>qrr.format(t),yEn=t=>{switch(t.source){case"tscircuit.com":{const e=t.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},Zrr=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.isDirectLookup?t.component.partNumber:t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},esr=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},tsr=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.isDirectLookup?void 0:t.component.partNumber;case"kicad":return}},nsr=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?yEn(e):null;return K.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=yEn(r),a=i===s,c=Zrr(r),A=esr(r),l=tsr(r),u=r.source==="jlcpcb"?r.component.stock:null,g=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return K.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 ${a?"rf-bg-zinc-100":""}`,onClick:()=>n(r),children:[K.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[K.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[K.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:[c,r.source==="jlcpcb"&&h!=null&&K.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${h?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:h?"Basic":"Extended"}),d&&K.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"}),r.source==="tscircuit.com"&&r.package.is_private&&K.jsx(xVi,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&u!=null?K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[u.toLocaleString()," in stock"]}):null]}),K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?K.jsx("span",{className:"rf-mr-2",children:l}):null,A]})]}),K.jsxs("div",{children:[r.source==="tscircuit.com"&&o?K.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:K.jsx(Ic,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:m=>{m.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&u!=null?K.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:[u.toLocaleString()," in stock"]}):null,g!=null&&K.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:Xrr(g)})]})]},s)})})},osr=({circuitJson:t,error:e,isLoading:n,height:o})=>K.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?K.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:o},children:[K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?K.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:o},children:K.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[K.jsx(LXe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),K.jsx("span",{children:e})]})}):t?K.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:K.jsx(TXe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):K.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:o},children:"No preview"})}),xEn={importComponentDialog:101,importComponentDetailsDialog:102},isr=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:c})=>{const A=t?.package??null,l=A?.latest_pcb_preview_image_url,u=A?.latest_sch_preview_image_url,g=A?.latest_cad_preview_image_url,h=A?.unscoped_name?.split("/").pop()??A?.unscoped_name,d=A?.org_owner_tscircuit_handle??void 0,m=d?`https://tscircuit.com/${d}`:void 0,p=d&&h?`https://tscircuit.com/${d}/${h}`:void 0;return K.jsx(Ek,{open:e,onOpenChange:n,children:K.jsxs(SM,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:xEn.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:[K.jsx(QM,{className:"rf-pb-4 rf-border-b",children:K.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx(vM,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),K.jsx(Bk,{children:A?.description})]})})}),K.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?K.jsxs("div",{children:[K.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),K.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?K.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(g||l||u)&&K.jsx(K.Fragment,{children:K.jsxs("div",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),K.jsxs(_ke,{value:r,onValueChange:f=>s(f),children:[K.jsxs(hhe,{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:[l&&K.jsx(J7,{value:"pcb",children:"PCB"}),u&&K.jsx(J7,{value:"schematic",children:"Schematic"}),g&&K.jsx(J7,{value:"3d",children:"3D"})]}),K.jsxs("div",{className:"rf-mt-4",children:[K.jsx(SI,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?K.jsx("img",{src:l,alt:`${h??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(SI,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?K.jsx("img",{src:u,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(SI,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?K.jsx("img",{src:g,alt:`${h??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?K.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),K.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),K.jsxs(jK,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[K.jsx("div",{className:"rf-flex-1",children:p?K.jsxs(Ic,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[K.jsx(mVi,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),K.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(Ic,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),K.jsx(Ic,{onClick:c,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},rsr=()=>{const[t,e]=q.useState(null),[n,o]=q.useState(!1),i=q.useCallback(async(s,a)=>{o(!0);try{const c=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!c.ok)throw new Error(`Failed to load package details: ${c.status}`);const A=await c.json();e(A.package??null)}catch(c){console.error("Failed to fetch package details",c),e(null)}finally{o(!1)}},[]),r=q.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},ssr=(t,e)=>{const[n,o]=q.useState({circuitJson:null,error:null,isLoading:!1});return q.useEffect(()=>{if(!t||!CEn(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),jrr(t,e).then(r=>{i||o({circuitJson:r,error:null,isLoading:!1})}).catch(r=>{i||o({circuitJson:null,error:r instanceof Error?r.message:"Failed to load footprint preview",isLoading:!1})}),()=>{i=!0}},[t,e]),n},asr=async(t,e)=>{const n={"Content-Type":"application/json"};e&&(n.Authorization=`Bearer ${e}`);const o=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:n,body:JSON.stringify({query:t})});if(!o.ok)throw new Error(`tscircuit registry error: ${o.status}`);return(await o.json()).packages??[]},csr=({sessionToken:t})=>{const[e,n]=q.useState([]),[o,i]=q.useState(!1),[r,s]=q.useState(null),[a,c]=q.useState(!1),A=q.useCallback(async u=>{const g=u.trim();if(!g)return[];i(!0),s(null);try{const d=(await asr(g,t)).map(m=>({source:"tscircuit.com",package:m}));return n(d),d}catch(h){return console.error("Error searching tscircuit packages",h),n([]),s(h instanceof Error?h.message:"Failed to search tscircuit packages"),[]}finally{i(!1),c(!0)}},[t]),l=q.useCallback(()=>{n([]),i(!1),s(null),c(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:A,reset:l}},Asr=t=>{const e=/^C(\d+)$/i.exec(t.trim());if(!e)return null;const n=Number(e[1]);if(!Number.isSafeInteger(n))return null;const o=`C${e[1]}`;return{source:"jlcpcb",component:{lcscId:n,manufacturer:o,partNumber:o,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},EEn=(t,e)=>{const n=Asr(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},lsr=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},usr=()=>{const[t,e]=q.useState([]),[n,o]=q.useState(!1),[i,r]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async l=>{const u=lsr(l);if(!u)return[];o(!0),r(null);try{const g=await err(u,10),h=EEn(l,g.map(d=>({source:"jlcpcb",component:trr(d)})));return e(h),h}catch(g){console.error("Error searching JLCPCB components",g);const h=EEn(l,[]);return e(h),r(h.length>0?null:g instanceof Error?g.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),A=q.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:A}},gsr=()=>{const[t,e]=q.useState([]),[n,o]=q.useState(!1),[i,r]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async l=>{const u=l.trim();if(!u)return[];o(!0),r(null);try{const h=(await zrr(u,20)).map(d=>({source:"kicad",footprint:Vrr(d)}));return e(h),h}catch(g){return console.error("Error searching KiCad footprints",g),e([]),r(g instanceof Error?g.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),A=q.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:A}},dsr=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},hsr=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{Tte();const c=q.useMemo(()=>dsr({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),A=c.length>0,l=c.length===1,[u,g]=q.useState(c[0]??"tscircuit.com"),[h,d]=q.useState(""),[m,p]=q.useState(null),{results:f,isSearching:_,error:I,hasSearched:C,search:y,reset:x}=csr({sessionToken:a}),{results:E,isSearching:B,error:b,hasSearched:Q,search:w,reset:M}=usr(),{results:T,isSearching:N,error:F,hasSearched:O,search:U,reset:Y}=gsr(),{details:j,isLoading:ee,fetchDetails:J,reset:W}=rsr(),[te,re]=q.useState(null),[ne,le]=q.useState(!1),[ge,fe]=q.useState("pcb"),[Ae,_e]=q.useState(null),[ue,me]=q.useState(!1),we=q.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Me,error:he,isLoading:Pe}=ssr(m,we),Qe=CEn(m);q.useEffect(()=>{_e(null)},[m]);const Se=q.useCallback(()=>{x(),M(),Y(),p(null)},[M,Y,x]);q.useEffect(()=>{t||(Se(),d(""),le(!1),re(null),_e(null))},[t,Se]),q.useEffect(()=>{d(""),p(null),u==="tscircuit.com"?x():u==="jlcpcb"?M():u==="kicad"&&Y()},[u,M,Y,x]);const De=gt=>{p(gt),re(gt),fe("pcb"),le(!0),W();const mt=gt.package.org_owner_tscircuit_handle,St=gt.package.unscoped_name;if(mt&&St){const _t=St.split("/").pop()??St;J(mt,_t)}},Ne=async()=>{h.trim()&&(p(null),u==="tscircuit.com"?await y(h):u==="jlcpcb"?await w(h):u==="kicad"&&await U(h))},Ee=async gt=>{try{if(_e(null),me(!0),gt.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:gt,footprint:gt.footprint.qualifiedName})}else if(gt.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const mt=await nrr(gt.component.partNumber,{headers:n,apiBase:s});await r({result:gt,tsx:mt})}else if(gt.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const mt=gt.package.org_owner_tscircuit_handle,St=gt.package.unscoped_name;if(!mt||!St)throw new Error("Missing package metadata");const _t=St.split("/").pop()??St,Tt=`@tsci/${mt}.${_t}`;await i({result:gt,fullPackageName:Tt})}return!0}catch(mt){return console.error("Failed to import component",mt),_e(mt instanceof Error?mt.message:"Failed to import component"),!1}finally{me(!1)}};let Te=[],Ie=!1,ke=null,Ge=!1;u==="tscircuit.com"?(Te=f,Ie=_,ke=I,Ge=C):u==="jlcpcb"?(Te=E,Ie=B,ke=b,Ge=Q):u==="kicad"&&(Te=T,Ie=N,ke=F,Ge=O);const qe=async()=>{if(!m)return;await Ee(m)&&(e(),Se(),d(""))},rt=gt=>{gt||e()},ct=gt=>{le(gt),gt||re(null)};return K.jsxs(Ek,{open:t,onOpenChange:rt,children:[K.jsxs(SM,{style:{width:"calc(100vw - 2rem)",maxWidth:Qe?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:xEn.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[K.jsxs(QM,{children:[K.jsxs(vM,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?AIe[u].label:""," ","Component"]}),K.jsx(Bk,{className:"rf-text-sm",children:A?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),A?K.jsxs(_ke,{value:u,onValueChange:gt=>g(gt),className:"rf-min-w-0 rf-w-full",children:[!l&&K.jsx(hhe,{className:"rf-flex rf-w-full rf-gap-2",children:c.map(gt=>K.jsx(J7,{value:gt,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:AIe[gt].label},gt))}),K.jsxs("div",{className:"rf-min-w-0",style:Qe?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[K.jsxs("div",{className:"rf-min-w-0",children:[K.jsx($rr,{query:h,placeholder:AIe[u].placeholder,isSearching:Ie,onQueryChange:d,onSubmit:Ne}),K.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:Ie?K.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[K.jsx($E,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),K.jsx("p",{children:"Searching..."})]}):Te.length>0?K.jsx(nsr,{results:Te,selected:m,onSelect:p,onShowDetails:u==="tscircuit.com"?De:void 0}):K.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:ke?`Error: ${ke}`:Ge?AIe[u].emptyMessage:"Enter a search term to find components"})})]}),Qe?K.jsx("div",{className:"rf-mt-4",children:K.jsx(osr,{circuitJson:Me,error:he,isLoading:Pe,height:325})}):null]})]}):null,Ae?K.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:Ae}):null,K.jsxs(jK,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(Ic,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),K.jsx(Ic,{onClick:qe,disabled:!m||ue,className:"rf-order-1 sm:rf-order-2",children:ue?K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),K.jsx(isr,{packageResult:te,isOpen:ne,onOpenChange:ct,isLoading:ee,details:j,previewTab:ge,onPreviewTabChange:gt=>fe(gt),isSubmitting:ue,onImport:()=>{te&&Ee(te).then(gt=>{gt&&(le(!1),e(),Se(),d(""))})}})]})},msr=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},BEn=t=>{const e=xd(s=>s.pushEvent),n=xd(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const A=s.package.unscoped_name??s.package.name;await ua.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${A}"`,success:`Install requested for "${A}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await ua.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:a=>`Failed to copy footprint: ${a instanceof Error?a.message:String(a)}`})},r=async({result:s,tsx:a})=>{const A=`imports/${msr(a)}.tsx`;await ua.promise(n(A,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${A}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return K.jsx(hsr,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};BEn.displayName="ImportComponentDialogForCli";const psr=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>FBr),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},fsr=async({circuitJson:t,projectName:e})=>{await ua.promise((async()=>{const n=await psr({circuitJson:t,projectName:e});o5(n,{fileName:`${e}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:n=>`Failed to generate Altium project: ${n instanceof Error?n.message:String(n)}`})};var qet={exports:{}},bEn;function _sr(){return bEn||(bEn=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,u){if(!r[l]){if(!i[l]){var g=typeof B8=="function"&&B8;if(!u&&g)return g(l,!0);if(c)return c(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[l]={exports:{}};i[l][0].call(d.exports,function(m){var p=i[l][1][m];return a(p||m)},d,d.exports,o,i,r,s)}return r[l].exports}for(var c=typeof B8=="function"&&B8,A=0;A<s.length;A++)a(s[A]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(A){for(var l,u,g,h,d,m,p,f=[],_=0,I=A.length,C=I,y=s.getTypeOf(A)!=="string";_<A.length;)C=I-_,g=y?(l=A[_++],u=_<I?A[_++]:0,_<I?A[_++]:0):(l=A.charCodeAt(_++),u=_<I?A.charCodeAt(_++):0,_<I?A.charCodeAt(_++):0),h=l>>2,d=(3&l)<<4|u>>4,m=1<C?(15&u)<<2|g>>6:64,p=2<C?63&g:64,f.push(c.charAt(h)+c.charAt(d)+c.charAt(m)+c.charAt(p));return f.join("")},r.decode=function(A){var l,u,g,h,d,m,p=0,f=0,_="data:";if(A.substr(0,_.length)===_)throw new Error("Invalid base64 input, it looks like a data url.");var I,C=3*(A=A.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(A.charAt(A.length-1)===c.charAt(64)&&C--,A.charAt(A.length-2)===c.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(I=a.uint8array?new Uint8Array(0|C):new Array(0|C);p<A.length;)l=c.indexOf(A.charAt(p++))<<2|(h=c.indexOf(A.charAt(p++)))>>4,u=(15&h)<<4|(d=c.indexOf(A.charAt(p++)))>>2,g=(3&d)<<6|(m=c.indexOf(A.charAt(p++))),I[f++]=l,d!==64&&(I[f++]=u),m!==64&&(I[f++]=g);return I}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),c=o("./stream/Crc32Probe"),A=o("./stream/DataLengthProbe");function l(u,g,h,d,m){this.compressedSize=u,this.uncompressedSize=g,this.crc32=h,this.compression=d,this.compressedContent=m}l.prototype={getContentWorker:function(){var u=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new A("data_length")),g=this;return u.on("end",function(){if(this.streamInfo.data_length!==g.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),u},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},l.createWorkerFrom=function(u,g,h){return u.pipe(new c).pipe(new A("uncompressedSize")).pipe(g.compressWorker(h)).pipe(new A("compressedSize")).withStreamInfo("compression",g)},i.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var c,A=[],l=0;l<256;l++){c=l;for(var u=0;u<8;u++)c=1&c?3988292384^c>>>1:c>>>1;A[l]=c}return A})();i.exports=function(c,A){return c!==void 0&&c.length?s.getTypeOf(c)!=="string"?(function(l,u,g,h){var d=a,m=h+g;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^u[p])];return-1^l})(0|A,c,c.length,0):(function(l,u,g,h){var d=a,m=h+g;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^u.charCodeAt(p))];return-1^l})(0|A,c,c.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),c=o("./utils"),A=o("./stream/GenericWorker"),l=s?"uint8array":"array";function u(g,h){A.call(this,"FlateWorker/"+g),this._pako=null,this._pakoAction=g,this._pakoOptions=h,this.meta={}}r.magic="\b\0",c.inherits(u,A),u.prototype.processChunk=function(g){this.meta=g.meta,this._pako===null&&this._createPako(),this._pako.push(c.transformTo(l,g.data),!1)},u.prototype.flush=function(){A.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},u.prototype.cleanUp=function(){A.prototype.cleanUp.call(this),this._pako=null},u.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var g=this;this._pako.onData=function(h){g.push({data:h,meta:g.meta})}},r.compressWorker=function(g){return new u("Deflate",g)},r.uncompressWorker=function(){return new u("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,m){var p,f="";for(p=0;p<m;p++)f+=String.fromCharCode(255&d),d>>>=8;return f}function a(d,m,p,f,_,I){var C,y,x=d.file,E=d.compression,B=I!==l.utf8encode,b=c.transformTo("string",I(x.name)),Q=c.transformTo("string",l.utf8encode(x.name)),w=x.comment,M=c.transformTo("string",I(w)),T=c.transformTo("string",l.utf8encode(w)),N=Q.length!==x.name.length,F=T.length!==w.length,O="",U="",Y="",j=x.dir,ee=x.date,J={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(J.crc32=d.crc32,J.compressedSize=d.compressedSize,J.uncompressedSize=d.uncompressedSize);var W=0;m&&(W|=8),B||!N&&!F||(W|=2048);var te=0,re=0;j&&(te|=16),_==="UNIX"?(re=798,te|=(function(le,ge){var fe=le;return le||(fe=ge?16893:33204),(65535&fe)<<16})(x.unixPermissions,j)):(re=20,te|=(function(le){return 63&(le||0)})(x.dosPermissions)),C=ee.getUTCHours(),C<<=6,C|=ee.getUTCMinutes(),C<<=5,C|=ee.getUTCSeconds()/2,y=ee.getUTCFullYear()-1980,y<<=4,y|=ee.getUTCMonth()+1,y<<=5,y|=ee.getUTCDate(),N&&(U=s(1,1)+s(u(b),4)+Q,O+="up"+s(U.length,2)+U),F&&(Y=s(1,1)+s(u(M),4)+T,O+="uc"+s(Y.length,2)+Y);var ne="";return ne+=`
5677
+ `,u=new Blob([l],{type:"text/plain"}),g=URL.createObjectURL(u),h=document.createElement("a");h.href=g,h.download=`${A}.test.ts`,h.click(),URL.revokeObjectURL(g)}catch(c){alert(`Error generating test.ts for ${t.getSolverName()}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.getSolverName()}`,children:t.getSolverName()}),n&&K.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:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},M3n=t=>t.activeSubSolver?[t,...M3n(t.activeSubSolver)]:[t],Gor=({solver:t})=>{const e=M3n(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(Oor,{solver:n})]},n.getSolverName()))})},Yor=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:c})=>{const[A,l]=q.useReducer(B=>!B,!1),u=q.useRef(void 0),g=q.useRef(null),h="solver-debugger-last-iteration",[d,m]=q.useState(null),p=q.useRef(null),f=q.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"}],[]),_=()=>{const B=Math.max(1,n),b=n<1?Math.round(1/n):1;u.current=setInterval(()=>{if(t.solved||t.failed){u.current&&(clearInterval(u.current),u.current=void 0),l(),e(),c&&t.solved&&c(t);return}for(let Q=0;Q<b&&!(t.solved||t.failed);Q++)t.step();e()},B)},I=()=>{u.current&&(clearInterval(u.current),u.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),c&&c(t))},x=()=>{A?(I(),l()):(l(),_())},E=()=>{if(t.solved||t.failed||A)return;g.current===null&&typeof window<"u"&&(g.current=window.localStorage.getItem(h));const B=window.prompt("Step until which iteration?",g.current??`${t.iterations}`);if(B===null)return;g.current=B,typeof window<"u"&&window.localStorage.setItem(h,B);const b=Number(B);if(!Number.isFinite(b)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<b&&!t.solved&&!t.failed;)t.step();e(),t.solved&&c&&c(t)};return q.useEffect(()=>()=>{I()},[]),q.useEffect(()=>{(t.solved||t.failed)&&A&&(I(),l())},[t.solved,t.failed,A]),q.useEffect(()=>{A&&(I(),_())},[n,A]),q.useEffect(()=>{if(typeof document>"u")return;const B=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",B),()=>{document.removeEventListener("mousedown",B)}},[]),K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[K.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[K.jsxs("div",{className:"relative",children:[K.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="renderer"?"open":"closed",children:"Renderer"}),d==="renderer"&&K.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(B=>K.jsxs("button",{type:"button",onClick:()=>{i(B),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B==="vector"?"Vector":"Canvas",o===B&&K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},B))})]}),K.jsxs("div",{className:"relative",children:[K.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="debug"?"open":"closed",children:"Debug"}),d==="debug"&&K.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:K.jsx("button",{type:"button",onClick:()=>{s(),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:"Download Visualization"})})]}),K.jsxs("div",{className:"relative",children:[K.jsx("button",{type:"button",onClick:()=>m(d==="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":d==="animation"?"open":"closed",children:"Animation"}),d==="animation"&&K.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:f.map(B=>K.jsxs("button",{type:"button",onClick:()=>{r(B.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[B.label,K.jsx("span",{className:"ml-auto text-xs text-slate-500",children:B.description}),n===B.value&&K.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},B.value))})]})]}),K.jsx(Gor,{solver:t})]})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.jsx("button",{onClick:C,disabled:t.solved||t.failed||A,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),K.jsx("button",{onClick:y,disabled:t.solved||t.failed||A,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),K.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${A?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:A?"Stop":"Animate"}),K.jsx("button",{onClick:E,disabled:t.solved||t.failed||A,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"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Uor=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),Kor=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},zor=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Kor(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let c=0;if(i==="Completed"){const g=t.pipelineDef[e+1],h=g?t.firstIterationOfStage?.[g.solverName]:void 0;h!==void 0&&s!==null?c=h-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const A=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:l,timeSpent:A,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},Vor=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Jor=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},D3n=t=>{if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"||t==null)return String(t);if(typeof t=="object")try{return JSON.stringify(t)}catch{return String(t)}return String(t)},Wor=t=>Object.entries(t).map(([e,n])=>`${e}: ${D3n(n)}`).join(", "),jor=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=Wor(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",D3n(i)]},o))})]})},Cet=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Cet);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Cet(o));return e},$or=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Cet(t.getConstructorParams()),o=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(o),r=document.createElement("a");r.href=i,r.download=`${e}_input.json`,r.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},qor=({expanded:t})=>K.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 ${t?"rotate-90":""}`,children:K.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"})}),N3n=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},R3n=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=q.useState(new Set),c=t.pipelineDef.map((p,f)=>zor(t,f)),A=p=>{a(f=>{const _=new Set(f);return _.has(p)?_.delete(p):_.add(p),_})},l=p=>{e?.(p)},u=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):$or(p.solverInstance,p.name))},g=p=>`${(p/1e3).toFixed(2)}s`,h=()=>{if(!t.solved&&!t.failed){const p=t.activeSubSolver;for(;!t.solved&&!t.failed&&(t.step(),!(t.activeSubSolver&&t.activeSubSolver!==p)););r?.()}},d=()=>{if(!t.solved&&!t.failed){const p=N3n(t);for(;!t.solved&&!t.failed&&(t.step(),N3n(t)===p););r?.()}},m=i*24;return K.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&K.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),K.jsxs("div",{className:"flex gap-2",children:[K.jsx("button",{onClick:d,disabled:t.solved||t.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"}),K.jsx("button",{onClick:h,disabled:t.solved||t.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"})]})]}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[!o&&K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:c.map(p=>{const f=Uor(p.solverInstance),_=s.has(p.name);return K.jsxs(Fs.Fragment,{children:[K.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[f?K.jsx("button",{onClick:()=>A(p.name),className:"text-gray-500 hover:text-gray-700",title:_?"Collapse":"Expand",children:K.jsx(qor,{expanded:_})}):K.jsx("span",{className:"w-4"}),K.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),K.jsx("button",{onClick:()=>l(p.name),disabled:p.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${p.name} completes`,children:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Vor,{status:p.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Jor,{progress:p.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:g(p.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(jor,{stats:p.stats})}),K.jsx("td",{className:"px-4 py-2",children:p.solverInstance?K.jsxs("button",{onClick:()=>u(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.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"})}),K.jsx("span",{children:"Input"})]}):null})]}),f&&_&&K.jsx("tr",{children:K.jsx("td",{colSpan:8,className:"p-0",children:K.jsx(R3n,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function Xor({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,A=Number.NEGATIVE_INFINITY;const l=(p,f)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof f=="number"&&(f<a&&(a=f),f>A&&(A=f))};for(const p of e)l(p.x,p.y);for(const p of n){const f=p.points??[];for(const _ of f)l(_.x,_.y)}for(const p of o){const f=p.x??0,_=p.y??0,I=p.width??0,C=p.height??0;l(f,_),l(f+I,_+C)}for(const p of i){const f=p.x??0,_=p.y??0,I=p.radius??1;l(f-I,_-I),l(f+I,_+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(A))&&(s=-20,a=-20,c=20,A=20);const u=10,g=s-u,h=a-u,d=Math.max(1,c-s+2*u),m=Math.max(1,A-a+2*u);return K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${g} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,f)=>K.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${f}`)),n.map((p,f)=>K.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${f}`)),i.map((p,f)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${f}`)),e.map((p,f)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${f}`)),r.map((p,f)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${f}`))]})}var Zor=class extends Fs.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}},eir=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=q.useReducer(_=>_+1,0),[a]=q.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[c,A]=q.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,u]=q.useState(n),g=q.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(_){return console.error("Visualization error:",_),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=q.useMemo(()=>(g.rects?.length||0)===0&&(g.lines?.length||0)===0&&(g.points?.length||0)===0&&(g.circles?.length||0)===0,[g]);q.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const _=document.createElement("script");_.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(_)}},[]),q.useEffect(()=>{u(n)},[n]);const d=a.pipelineDef!==void 0,m=_=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===_);)a.step();s()}},p=()=>{const _=JSON.stringify(g,null,2),I=new Blob([_],{type:"application/json"}),C=URL.createObjectURL(I),y=document.createElement("a");y.download="visualization.json",y.href=C,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(C)},f=_=>{A(_),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",_)};return K.jsxs("div",{children:[K.jsx(Yor,{solver:a,triggerRender:s,animationSpeed:l,renderer:c,onRendererChange:f,onAnimationSpeedChange:u,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(Zor,{fallback:K.jsx(Xor,{graphics:g}),children:c==="canvas"?K.jsx(Hor,{graphics:g}):K.jsx(kor,{graphics:g})}),d&&K.jsx(R3n,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const tir=()=>{q.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const o=document.createElement("script");o.id=t,o.src="https://cdn.tailwindcss.com",document.head.appendChild(o)},[])},nir=1e3,o5=(t,e)=>{const{fileName:n,mimeType:o="text/plain"}=e,i=t instanceof Blob?t:new Blob([t],{type:o}),r=URL.createObjectURL(i),s=document.createElement("a");s.href=r,s.download=n,s.target="_blank",s.rel="noopener noreferrer",s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>{URL.revokeObjectURL(r)},nir)},yet=t=>{let e=t.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(e)&&(e=`_${e}`),e=e.slice(0,200),e||"untitled"},oir=t=>{const e=t.solverConstructorArgs??[t.solverParams];if(t.solverName!=="AutoroutingPipelineSolver7_MultiGraph"||e.length!==1)return e;const[{input:n,options:o}]=e;return[n,o]},kb="https://github.com/tscircuit/tscircuit-autorouter/issues/new",T3n="https://github.com/tscircuit/copper-pour-solver/issues/new",k3n="https://github.com/tscircuit/calculate-packing/issues/new",iir="https://github.com/tscircuit/matchpack/issues/new",F3n="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",rir={PackSolver2:k3n,LayoutPipelineSolver:iir,AutoroutingPipelineSolver:kb,AssignableAutoroutingPipeline2:kb,AssignableAutoroutingPipeline3:kb,AutoroutingPipeline1_OriginalUnravel:kb,AutoroutingPipelineSolver3_HgPortPointPathing:kb,AutoroutingPipelineSolver4:kb,AutoroutingPipelineSolver5:kb,AutoroutingPipelineSolver7_MultiGraph:kb,AutoroutingPipelineSolver8:kb,CopperPourPipelineSolver:T3n,SchematicTracePipelineSolver:F3n},sir=t=>t.toLowerCase().includes("pack")?SCn:t.toLowerCase().includes("rout")?vCn:sVi,L3n=t=>{const e=rir[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?kb:n.includes("schematic")&&n.includes("trace")?F3n:n.includes("copperpour")?T3n:n.includes("pack")?k3n:null},air=t=>`${yet(`${t.componentName}-${t.solverName}`)}-solver-input.json`,H3n=t=>{o5(JSON.stringify(t.solverParams,null,2),{fileName:air(t),mimeType:"application/json"})},cir=({solverEvent:t})=>{const e=L3n(t.solverName);return K.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:[K.jsxs(Ic,{type:"button",variant:"outline",size:"sm",onClick:()=>H3n(t),children:[K.jsx(tte,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?K.jsx(Ic,{asChild:!0,variant:"outline",size:"sm",children:K.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[K.jsx(G_e,{className:"rf-w-4 rf-h-4"}),"Report"]})}):K.jsxs(Ic,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[K.jsx(G_e,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},Air=({solverEvent:t})=>{const e=L3n(t.solverName);return e?K.jsx(Ic,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:K.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:K.jsx(G_e,{className:"rf-w-4 rf-h-4"})})}):K.jsx(Ic,{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:K.jsx(G_e,{className:"rf-w-4 rf-h-4"})})},lir=({solverEvents:t=[]})=>{const[e,n]=q.useState(null);tir();const o=q.useMemo(()=>{const a=new Map;for(const c of t){const A=`${c.componentName}-${c.solverName}`;a.set(A,c)}return a},[t]),i=q.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=q.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=gNe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(gNe).join(", ")}`,classFound:!1};try{return{instance:new a(...oir(r)),error:null,classFound:!0}}catch(c){const A=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${A}`,classFound:!0}}},[r]);return t.length===0?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.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."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.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:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),A=e===a;return K.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${A?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=sir(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[K.jsx(cir,{solverEvent:r}),K.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:K.jsx(jE,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(eir,{solver:s.instance})})})]}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.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:[K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(Air,{solverEvent:r}),K.jsx(Ic,{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:()=>H3n(r),children:K.jsx(tte,{className:"rf-w-4 rf-h-4"})})]})]}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},uir=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],gir=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function dir(t,e){let n=-1,o=-1;for(let i=t.length-1;i>=0;i--){const r=t[i];if(r.status!=="running"||r.subcircuit_id!==e.subcircuit_id||r.componentDisplayName!==e.componentDisplayName)continue;let s=0,a=!1;for(const c of gir)if(!(r[c]===void 0||e[c]===void 0)){if(r[c]!==e[c]){a=!0;break}s++}!a&&s>o&&(n=i,o=s)}return n}function hir(t,e){const n=Object.fromEntries(uir.filter(s=>e[s]!==void 0).map(s=>[s,e[s]])),o=e.simpleRouteJson?structuredClone(e.simpleRouteJson):void 0,i=e.type==="autorouting:start"?-1:dir(t,e),r={...i===-1?{id:`autorouting_phase_${t.length+1}`}:t[i],...n,status:e.type==="autorouting:start"?"running":e.type==="autorouting:end"?"complete":"error",...e.type==="autorouting:start"?{startSimpleRouteJson:o}:e.type==="autorouting:end"?{endSimpleRouteJson:o}:{errorSimpleRouteJson:o,error:e.error?{...e.error}:void 0}};return i===-1?[...t,r]:t.map((s,a)=>a===i?r:s)}const mir=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),pir=new Set(["tscircuit","default","auto","auto_local"]);function fir(t){if(t==="FanoutSolver")return"Fanout";if(t==="AutoroutingPipelineSolver11_Simplification")return"Simplify";const e=t.match(/^AutoroutingPipeline(?:Solver)?(\d+)(?:_|$)/);if(e)return`Pipeline${e[1]}`;const n=t.match(/^AssignableAutoroutingPipeline(\d+)$/);return n?`Assignable${n[1]}`:t}function _ir(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&mir.get(n);if(o)return o;if(n&&!pir.has(n))return e;const i=t.solverName?.trim();if(i)return fir(i);const r=t.autorouterVersion?.trim();if(r){const s=r.match(/^beta[_-]pipeline(\d+)$/);return s?`Pipeline${s[1]}`:r==="latest"?"default":r}return e?"default":"Unknown"}const xet="#fbbf24";function Iir(t){const e=t.endSimpleRouteJson?.traces??[],n=new Set(e.flatMap(i=>[i.pcb_trace_id,i.__replaces_pcb_trace_id].filter(r=>r!==void 0)));return[...(t.startSimpleRouteJson?.traces??[]).filter(i=>!n.has(i.pcb_trace_id)),...e]}function O3n(t){const e=new Map((t.startSimpleRouteJson?.traces??[]).map(n=>[n.pcb_trace_id,n]));return(t.endSimpleRouteJson?.traces??[]).filter(n=>{const o=e.get(n.pcb_trace_id);return!o||!!n.__replaces_pcb_trace_id&&n.__replaces_pcb_trace_id!==o.__replaces_pcb_trace_id||JSON.stringify(o.route)!==JSON.stringify(n.route)}).map(n=>n.pcb_trace_id)}function Cir(t,e){return{outer_diameter:t.via_diameter??e.minViaPadDiameter??e.min_via_pad_diameter??e.minViaDiameter??.6,hole_diameter:t.via_hole_diameter??e.minViaHoleDiameter??e.min_via_hole_diameter??.3}}function G3n(t,e){const n=[];for(const a of t.route)a.route_type==="wire"?n.push({...a,layer:a.layer}):a.route_type==="via"?n.push({route_type:"via",x:a.x,y:a.y,from_layer:a.from_layer,to_layer:a.to_layer,...Cir(a,e)}):a.route_type==="through_obstacle"&&n.push({route_type:"through_pad",start:{...a.start},end:{...a.end},width:a.width,start_layer:a.from_layer,end_layer:a.to_layer,pcb_smtpad_id:a.circuitJsonMetadata?.pcb_smtpad_id,pcb_plated_hole_id:a.circuitJsonMetadata?.pcb_plated_hole_id});const o=a=>{let c=-1,A=Number.POSITIVE_INFINITY;return n.forEach((l,u)=>{if(l.route_type!=="wire")return;const g=Math.hypot(l.x-a.x,l.y-a.y);g<A&&(A=g,c=u)}),c},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((c,A)=>c-A)).filter(([a,c])=>a>=0&&c>a).sort(([a],[c])=>a-c),r=[];let s=0;for(const[a,c]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,c);return s<n.length&&r.push(n.slice(s)),r}function yir(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(O3n(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of G3n(r,o)){let a;for(const c of s){if(c.route_type==="through_pad"){a={...c.end,layer:c.end_layer,width:c.width};continue}const A=c.route_type==="wire"?c.layer:c.from_layer;a&&a.layer===A&&(a.x!==c.x||a.y!==c.y)&&e.push({points:[{x:a.x,y:a.y},{x:c.x,y:c.y}],strokeWidth:c.route_type==="wire"?c.width:a.width,strokeColor:xet,layer:A}),c.route_type==="via"&&n.push({center:{x:c.x,y:c.y},radius:c.outer_diameter/2,stroke:xet,fill:"transparent"}),a={x:c.x,y:c.y,layer:c.route_type==="wire"?c.layer:c.to_layer,width:c.route_type==="wire"?c.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function xir(t){const e=JSON.stringify(t);let n=2166136261;for(let o=0;o<e.length;o++)n=Math.imul(n^e.charCodeAt(o),16777619);return(n>>>0).toString(36)}const Eir=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function Bir(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(A=>!Eir.has(A.type)&&!A.type.endsWith("_error")&&!A.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:Iir(e),s=new Set(t.filter(A=>A.type==="source_trace").map(A=>A.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(A,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],c=[];for(const A of r){const u=o.connections.find(h=>h.name===A.connection_name||h.source_trace_id===A.connection_name)?.source_trace_id??A.connection_name??"",g=G3n(A,o);for(const[h,d]of g.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${A.pcb_trace_id}_${h}_${xir(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(u)?u:void 0,route:d};c.push(m);for(const[p,f]of d.entries()){if(f.route_type!=="via")continue;const _=a.indexOf(f.from_layer),I=a.indexOf(f.to_layer),C={type:"pcb_via",pcb_via_id:`${m.pcb_trace_id}_via_${p}`,pcb_trace_id:m.pcb_trace_id,subcircuit_id:e.subcircuit_id??void 0,x:f.x,y:f.y,outer_diameter:f.outer_diameter,hole_diameter:f.hole_diameter,layers:_>=0&&I>=0?a.slice(Math.min(_,I),Math.max(_,I)+1):[f.from_layer,f.to_layer]};c.push(C)}}}return[...i,...c]}const Eet=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,Y3n=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",U3n=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,bir={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},Sir=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=q.useState(null),[r,s]=q.useState("output"),[a,c]=q.useState(!0),[A,l]=q.useState(!1),u=q.useRef(null),[g,h]=q.useState(480),d=o?e.findIndex(N=>N.id===o.id&&U3n(N)===U3n(o)):-1,m=d<0?e.length-1:d,p=e[m],f=d<0,_=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!_?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=q.useMemo(()=>!p||!x?null:Bir(t??[],p,y),[t,p,x,y]),B=q.useMemo(()=>p&&y==="output"&&a?yir(p):{lines:[],circles:[]},[p,y,a]);if(q.useLayoutEffect(()=>{const N=u.current;if(!N)return;const F=()=>h(Math.max(360,N.clientHeight));F();const O=new ResizeObserver(F);return O.observe(N),()=>O.disconnect()},[!!p]),!p)return K.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:[K.jsx(vCn,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),K.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),K.jsx("p",{className:"rf-max-w-md rf-text-sm rf-text-gray-500",children:n?"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 b=Eet(p,m),Q=p.status==="running"&&n,w=!_,M=I?.connections.length,T=E?.filter(N=>N.type==="pcb_trace").length??0;return K.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:[K.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:[K.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:[K.jsx("span",{children:"Routing phases"}),K.jsx("span",{children:e.length})]}),K.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:e.map((N,F)=>{const O=O3n(N).length,U=N.endSimpleRouteJson?`${O} ${O===1?"trace":"traces"} routed`:N.status==="error"?"Failed":N.status==="running"&&n?"Routing…":"No output";return K.jsxs("button",{type:"button","aria-pressed":F===m,title:`${Y3n(N)} · ${U}`,onClick:()=>i(N),className:Li("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",F===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[K.jsx("span",{className:Li("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",F===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:F+1}),K.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[K.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[K.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:Eet(N,F),children:Eet(N,F)}),N.status==="complete"?K.jsx(sQ,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):N.status==="error"?K.jsx(LXe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?K.jsx($E,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),K.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[_ir(N)," · ",U]})]})]},N.id)})})]}),K.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[K.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:[K.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,K.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&K.jsx("button",{type:"button",onClick:()=>i(null),disabled:f,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:f?"Following latest":"Follow latest"}),K.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(N=>K.jsx("button",{type:"button","aria-pressed":y===N,disabled:N==="input"?!C:!_,onClick:()=>s(N),className:Li("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===N?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:N==="input"?"Input":"Output"},N))})]}),K.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:[K.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:N=>c(N.target.checked),className:"rf-accent-blue-600"}),K.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:xet}}),"Highlight changes (all layers)"]}),K.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",T," traces"]})]}),w&&K.jsx("div",{className:Li("rf-border-y rf-px-4 rf-py-2 rf-text-xs",p.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:p.status==="error"?`Routing failed: ${p.error?.message||"No output was captured."}`:Q?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),K.jsx("div",{ref:u,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?K.jsx(TXe,{circuitJson:E,height:g,allowEditing:!1,clickToInteractEnabled:!1,initialState:bir,debugGraphics:B}):K.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),K.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:[K.jsxs("span",{children:[M===void 0?"Input unavailable":`${M} input connections`,` · ${Y3n(p)}`]}),K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[K.jsxs("button",{type:"button",disabled:!x,onClick:()=>o5(JSON.stringify(x,null,2),{fileName:`${p.id}-${y}.srj.json`,mimeType:"application/json"}),className:"rf-flex rf-items-center rf-gap-1 disabled:rf-opacity-40",children:[K.jsx(tte,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),K.jsxs("button",{type:"button","aria-expanded":A,onClick:()=>l(!A),className:"rf-flex rf-items-center rf-gap-1",children:[K.jsx(hk,{className:Li("rf-h-3 rf-w-3",A&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),A&&K.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":`${b} ${y} SRJ`,children:x?JSON.stringify(x,null,2):"No snapshot captured."})]})]})},K3n=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{q.useEffect(()=>{if(DS("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&t){const o=new Error(t);e&&(o.stack=e);try{ZG.captureException(o)}catch{}}},[t,e]),q.useEffect(()=>{if(DS("TSCIRCUIT_TELEMETRY_DISABLED")!==!0&&n&&n.length>0)for(const o of n){const i=new Error(o.message||"Circuit JSON Error");o.stack&&(i.stack=o.stack);try{ZG.captureException(i,{error_type:o.type})}catch{}}},[n])},z3n=t=>{q.useEffect(()=>{try{Tei(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},V3n="0.0.2958",Qir={version:V3n},cIe=mGt()(pGt(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),vir=t=>{const[e,n]=q.useState([]),[o,i]=q.useState(null),[r,s]=q.useState(""),[a,c]=xG("eval-version-selection",null),A=cIe(h=>h.setLastRunEvalVersion),l=cIe(h=>h.lastRunEvalVersion);return q.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(h=>h.json()).then(h=>{if(Array.isArray(h?.versions)){let d=[...h.versions];h.tags?.latest&&(i(h.tags.latest),d=d.filter(m=>m!==h.tags.latest)),n(d)}}).catch(()=>{})},[t]),q.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,A(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,A(o)))},[t,a,o]),{versions:q.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{c(h),s("")}}},wir=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=q.useState(""),[s,a]=q.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),A=s&&!t.includes(s),l=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):A&&r(s))};return K.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:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:u=>a(u.target.value),onKeyDown:l}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),A&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.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:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},Pir=t=>{const e=q.useRef(null),n=xd(o=>o.recentEvents);q.useEffect(()=>{if(n.length===0)return;const o=n[0];o.event_id!==e.current&&(t(o),e.current=o.event_id)},[n,t])};var Mir=Object.defineProperty,mQ=(t,e)=>Mir(t,"name",{value:e,configurable:!0}),Dir="AlertDialog",[Nir,abr]=jx(Dir,[t2n]),pQ=t2n(),Rir=mQ(t=>{const{__scopeAlertDialog:e,...n}=t,o=pQ(e);return K.jsx(B1e,{...o,...n,modal:!0})},"AlertDialog");q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(Mji,{...r,...i,ref:n})},"AlertDialogTrigger"));var Tir=mQ(t=>{const{__scopeAlertDialog:e,...n}=t,o=pQ(e);return K.jsx(b1e,{...o,...n})},"AlertDialogPortal"),J3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(hte,{...r,...i,ref:n})},"AlertDialogOverlay")),kir="AlertDialogContent",[Fir,Lir]=Nir(kir),W3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=pQ(o),a=q.useRef(null),c=Lc(n,a),A=q.useRef(null);return K.jsx(Fir,{scope:o,cancelRef:A,children:K.jsx(pte,{role:"alertdialog",...s,...r,ref:c,onOpenAutoFocus:rr(r.onOpenAutoFocus,l=>{l.preventDefault(),A.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),j3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(S1e,{...r,...i,ref:n})},"AlertDialogTitle")),$3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(Q1e,{...r,...i,ref:n})},"AlertDialogDescription")),q3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=pQ(o);return K.jsx(QZe,{...r,...i,ref:n})},"AlertDialogAction")),Hir="AlertDialogCancel",X3n=q.forwardRef(mQ(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=Lir(Hir,o),s=pQ(o),a=Lc(n,r);return K.jsx(QZe,{...s,...i,ref:a})},"AlertDialogCancel"));const Z3n=Rir,Oir=Tir,eEn=q.forwardRef(({className:t,...e},n)=>K.jsx(J3n,{className:Li("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",t),...e,ref:n}));eEn.displayName=J3n.displayName;const Bet=q.forwardRef(({className:t,...e},n)=>K.jsxs(Oir,{children:[K.jsx(eEn,{}),K.jsx(W3n,{ref:n,className:Li("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",t),...e})]}));Bet.displayName=W3n.displayName;const bet=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});bet.displayName="AlertDialogHeader";const Qet=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});Qet.displayName="AlertDialogFooter";const vet=q.forwardRef(({className:t,...e},n)=>K.jsx(j3n,{ref:n,className:Li("rf-text-lg rf-font-semibold",t),...e}));vet.displayName=j3n.displayName;const wet=q.forwardRef(({className:t,...e},n)=>K.jsx($3n,{ref:n,className:Li("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));wet.displayName=$3n.displayName;const Gir=q.forwardRef(({className:t,...e},n)=>K.jsx(q3n,{ref:n,className:Li(yK(),t),...e}));Gir.displayName=q3n.displayName;const Pet=q.forwardRef(({className:t,...e},n)=>K.jsx(X3n,{ref:n,className:Li(yK({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));Pet.displayName=X3n.displayName;var Yir=Object.defineProperty,fQ=(t,e)=>Yir(t,"name",{value:e,configurable:!0}),Met="Checkbox",[Uir,cbr]=jx(Met),[Kir,Det]=Uir(Met);function tEn(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:c,required:A,value:l="on",internal_do_not_use_render:u}=t,[g,h]=o9({prop:n,defaultProp:i??!1,onChange:c,caller:Met}),[d,m]=q.useState(null),[p,f]=q.useState(null),_=q.useRef(!1),[I,C]=q.useReducer(E=>E+1,0),y=d?!!s||!!d.closest("form"):!0,x={checked:g,disabled:r,setChecked:h,control:d,setControl:m,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:_,userInteractionCount:I,onUserInteraction:C,required:A,defaultChecked:_Q(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:f};return K.jsx(Kir,{scope:e,...x,children:oEn(u)?u(x):o})}fQ(tEn,"CheckboxProvider");var zir="CheckboxTrigger",Vir=q.forwardRef(fQ(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:c,checked:A,required:l,setControl:u,setChecked:g,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:m,bubbleInput:p}=Det(zir,e),f=Lc(r,u),_=q.useRef(A);return q.useEffect(()=>{const I=s?.form;if(I){const C=fQ(()=>g(_.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,g]),K.jsx(Ta.button,{type:"button",role:"checkbox","aria-checked":_Q(A)?"mixed":A,"aria-required":l,"data-state":Net(A),"data-disabled":c?"":void 0,disabled:c,value:a,...i,ref:f,onKeyDown:rr(n,I=>{I.key==="Enter"&&I.preventDefault()}),onClick:rr(o,I=>{d(),g(C=>_Q(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),nEn=q.forwardRef(fQ(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:c,value:A,onCheckedChange:l,form:u,...g}=e;return K.jsx(tEn,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:c,required:a,onCheckedChange:l,name:i,form:u,value:A,internal_do_not_use_render:({isFormControl:h})=>K.jsxs(K.Fragment,{children:[K.jsx(Vir,{...g,ref:n,__scopeCheckbox:o}),h&&K.jsx($ir,{__scopeCheckbox:o})]})})},"Checkbox")),Jir="CheckboxIndicator",Wir=q.forwardRef(fQ(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=Det(Jir,o);return K.jsx(vE,{present:i||_Q(s.checked)||s.checked===!0,children:K.jsx(Ta.span,{"data-state":Net(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),jir="CheckboxBubbleInput",$ir=q.forwardRef(fQ(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:c,defaultChecked:A,required:l,disabled:u,name:g,value:h,form:d,bubbleInput:m,setBubbleInput:p}=Det(jir,e),f=Lc(i,p),_=cZe(r),I=q.useRef(!1),C=q.useRef(c),y=q.useRef(a);q.useEffect(()=>{const E=m;if(!E)return;const B=window.HTMLInputElement.prototype,Q=Object.getOwnPropertyDescriptor(B,"checked").set,w=a!==y.current;y.current=a;const M=C.current!==c;C.current=c;const T=!(w&&s.current);if(M&&Q){I.current=!w;const N=new Event("click",{bubbles:T});E.indeterminate=_Q(c),Q.call(E,_Q(c)?!1:c),E.dispatchEvent(N),I.current=!1}},[m,c,s,a]);const x=q.useRef(_Q(c)?!1:c);return K.jsx(Ta.input,{type:"checkbox","aria-hidden":!0,defaultChecked:A??x.current,required:l,disabled:u,name:g,value:h,form:d,...o,tabIndex:-1,ref:f,onClick:rr(n,E=>{I.current&&E.stopPropagation()}),style:{...o.style,..._,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function oEn(t){return typeof t=="function"}fQ(oEn,"isFunction");function _Q(t){return t==="indeterminate"}fQ(_Q,"isIndeterminate");function Net(t){return _Q(t)?"indeterminate":t?"checked":"unchecked"}fQ(Net,"getState");const Lte=q.forwardRef(({className:t,...e},n)=>K.jsx(nEn,{ref:n,className:Li("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",t),...e,children:K.jsx(Wir,{className:Li("rf-flex rf-items-center rf-justify-center rf-text-current"),children:K.jsx(sQ,{className:"rf-h-4 rf-w-4"})})}));Lte.displayName=nEn.displayName;const Ek=B1e,qir=b1e,iEn=q.forwardRef(({className:t,...e},n)=>K.jsx(hte,{className:Li("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",t),...e,ref:n}));iEn.displayName=hte.displayName;const SM=q.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>K.jsxs(qir,{children:[K.jsx(iEn,{className:Li(n?"":"rf-hidden")}),K.jsx(pte,{ref:i,className:Li("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",t),...o,children:e})]}));SM.displayName=pte.displayName;const QM=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});QM.displayName="DialogHeader";const jK=({className:t,...e})=>K.jsx("div",{className:Li("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});jK.displayName="DialogFooter";const vM=q.forwardRef(({className:t,...e},n)=>K.jsx(S1e,{ref:n,className:Li("rf-text-lg rf-font-semibold",t),...e}));vM.displayName=S1e.displayName;const Bk=q.forwardRef(({className:t,...e},n)=>K.jsx(Q1e,{ref:n,className:Li("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));Bk.displayName=Q1e.displayName;const AIe={"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"}},Xir="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let Ret=null;const Tet=async()=>(Ret||(Ret=import(Xir)),Ret),Zir=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??g2}/proxy`,{...n,headers:{...i,"X-Target-Url":e.toString(),"X-Sender-Origin":i.origin??"","X-Sender-Host":i.host??"https://easyeda.com","X-Sender-Referer":i.referer??"","X-Sender-User-Agent":i["user-agent"]??"","X-Sender-Cookie":i.cookie??"",authority:i.authority??"","content-type":i["content-type"]??"",...t?.headers}})},err=async(t,e=10)=>{const n=encodeURIComponent(t),o=await fetch(`https://jlcsearch.tscircuit.com/api/search?limit=${e}&q=${n}`);if(!o.ok)throw new Error(`JLCPCB API error: ${o.status}`);return(await o.json()).components??[]},trr=t=>({lcscId:t.lcsc,manufacturer:t.mfr,description:t.description,partNumber:`C${t.lcsc}`,package:t.package,price:t.price,stock:t.stock,isBasic:t.is_basic}),rEn=async(t,e)=>{const{fetchEasyEDAComponent:n}=await Tet();return n(t,{fetch:Zir(e),includeModelMetadata:e?.includeModelMetadata})},nrr=async(t,e)=>{const{convertRawEasyToTsx:n}=await Tet(),o=await rEn(t,e);return n({rawEasy:o})},orr=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await Tet(),i=await rEn(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function wM(t){return Array.isArray?Array.isArray(t):aEn(t)==="[object Array]"}function irr(t){if(typeof t=="string")return t;if(typeof t=="bigint")return t.toString();const e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function ket(t){return t==null?"":irr(t)}function ZC(t){return typeof t=="string"}function lIe(t){return typeof t=="number"}function rrr(t){return t===!0||t===!1||srr(t)&&aEn(t)=="[object Boolean]"}function sEn(t){return typeof t=="object"}function srr(t){return sEn(t)&&t!==null}function i5(t){return t!=null}function uIe(t){return!t.trim().length}function aEn(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const arr="Incorrect 'index' type",Fet="Invalid doc index: must be a non-negative integer within the bounds of the docs array",crr=t=>`Invalid value for key ${t}`,Arr=t=>`Pattern length exceeds max of ${t}.`,lrr=t=>`Missing ${t} property in key`,urr=t=>`Property 'weight' in key '${t}' must be a positive integer`,grr="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.",cEn=Object.prototype.hasOwnProperty;var drr=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=AEn(n);this._keys.push(o),this._keyMap[o.id]=o,e+=o.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function AEn(t){let e=null,n=null,o=null,i=1,r=null;if(ZC(t)||wM(t))o=t,e=lEn(t),n=gIe(t);else{if(!cEn.call(t,"name"))throw new Error(lrr("name"));const s=t.name;if(o=s,cEn.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(urr(gIe(s)));e=lEn(s),n=gIe(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function lEn(t){return wM(t)?t:t.split(".")}function gIe(t){return wM(t)?t.join("."):t}function hrr(t,e){const n=[];let o=!1;const i=(r,s,a,c)=>{if(i5(r))if(!s[a])n.push(c!==void 0?{v:r,i:c}:r);else{const A=r[s[a]];if(!i5(A))return;if(a===s.length-1&&(ZC(A)||lIe(A)||rrr(A)||typeof A=="bigint"))n.push(c!==void 0?{v:ket(A),i:c}:ket(A));else if(wM(A)){o=!0;for(let l=0,u=A.length;l<u;l+=1)i(A[l],s,a+1,l)}else s.length&&i(A,s,a+1,c)}};return i(t,ZC(e)?e.split("."):e,0),o?n:n[0]}const Pa=Object.freeze({...{isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.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:hrr,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function mrr(t){return t>=9&&t<=13||t===32||t===160}function prr(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let c=0;c<i.length;c++)mrr(i.charCodeAt(c))?s=!1:s||(r++,s=!0);if(r===0&&(r=1),n.has(r))return n.get(r);const a=Math.round(o/Math.pow(r,.5*t))/o;return n.set(r,a),a},clear(){n.clear()}}}var Let=class{constructor({getFn:t=Pa.getFn,fieldNormWeight:e=Pa.fieldNormWeight}={}){this.norm=prr(e,3),this.getFn=t,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((e,n)=>{this._keysMap[e.id]=n})}create(){if(this.isCreated||!this.docs.length)return;this.isCreated=!0;const t=this.docs.length;this.records=new Array(t);let e=0;if(ZC(this.docs[0]))for(let n=0;n<t;n++){const o=this._createStringRecord(this.docs[n],n);o&&(this.records[e++]=o)}else for(let n=0;n<t;n++)this.records[e++]=this._createObjectRecord(this.docs[n],n);this.records.length=e,this.norm.clear()}add(t,e){if(!Number.isInteger(e)||e<0)throw new Error(Fet);if(ZC(t)){const o=this._createStringRecord(t,e);return o&&this.records.push(o),o}const n=this._createObjectRecord(t,e);return this.records.push(n),n}removeAt(t){if(!Number.isInteger(t)||t<0)throw new Error(Fet);for(let e=0,n=this.records.length;e<n;e+=1)if(this.records[e].i===t){this.records.splice(e,1);break}for(let e=0,n=this.records.length;e<n;e+=1)this.records[e].i>t&&(this.records[e].i-=1)}removeAll(t){const e=new Set;for(const o of t)Number.isInteger(o)&&o>=0&&e.add(o);if(e.size===0)return;this.records=this.records.filter(o=>!e.has(o.i));const n=Array.from(e).sort((o,i)=>o-i);for(const o of this.records){let i=0,r=n.length;for(;i<r;){const s=i+r>>>1;n[s]<o.i?i=s+1:r=s}o.i-=i}}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_createStringRecord(t,e){return!i5(t)||uIe(t)?null:{v:t,i:e,n:this.norm.get(t)}}_createObjectRecord(t,e){const n={i:e,$:{}};for(let o=0,i=this.keys.length;o<i;o++){const r=this.keys[o],s=r.getFn?r.getFn(t):this.getFn(t,r.path);if(i5(s)){if(wM(s)){const a=[];for(let c=0,A=s.length;c<A;c+=1){const l=s[c];if(i5(l)){if(ZC(l)){if(!uIe(l)){const u={v:l,i:c,n:this.norm.get(l)};a.push(u)}}else if(i5(l.v)){const u=ZC(l.v)?l.v:ket(l.v);if(!uIe(u)){const g={v:u,i:l.i,n:this.norm.get(u)};a.push(g)}}}}n.$[o]=a}else if(ZC(s)&&!uIe(s)){const a={v:s,n:this.norm.get(s)};n.$[o]=a}}}return n}toJSON(){return{keys:this.keys.map(({getFn:t,...e})=>e),records:this.records}}};function uEn(t,e,{getFn:n=Pa.getFn,fieldNormWeight:o=Pa.fieldNormWeight}={}){const i=new Let({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(AEn)),i.setSources(e),i.create(),i}function frr(t,{getFn:e=Pa.getFn,fieldNormWeight:n=Pa.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new Let({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function _rr(t=[],e=Pa.minMatchCharLength){const n=[];let o=-1,i=-1,r=0;for(let s=t.length;r<s;r+=1){const a=t[r];a&&o===-1?o=r:!a&&o!==-1&&(i=r-1,i-o+1>=e&&n.push([o,i]),o=-1)}return t[r-1]&&r-o>=e&&n.push([o,r-1]),n}function Irr(t,e,n,{location:o=Pa.location,distance:i=Pa.distance,threshold:r=Pa.threshold,findAllMatches:s=Pa.findAllMatches,minMatchCharLength:a=Pa.minMatchCharLength,includeMatches:c=Pa.includeMatches,ignoreLocation:A=Pa.ignoreLocation}={}){if(e.length>32)throw new Error(Arr(32));const l=e.length,u=t.length,g=Math.max(0,Math.min(o,u));let h=r,d=g;const m=(b,Q)=>{const w=b/l;if(A)return w;const M=Math.abs(g-Q);return i?w+M/i:M?1:w},p=a>1||c,f=p?Array(u):[];let _;for(;(_=t.indexOf(e,d))>-1;){const b=m(0,_);if(h=Math.min(b,h),d=_+l,p){let Q=0;for(;Q<l;)f[_+Q]=1,Q+=1}}d=-1;let I=[],C=1,y=0,x=l+u;const E=1<<l-1;for(let b=0;b<l;b+=1){let Q=0,w=x;for(;Q<w;)m(b,g+w)<=h?Q=w:x=w,w=Math.floor((x-Q)/2+Q);x=w;let M=Math.max(1,g-w+1);const T=s?u:Math.min(g+w,u)+l,N=Array(T+2);N[T+1]=(1<<b)-1;for(let F=T;F>=M;F-=1){const O=F-1,U=n[t[O]];if(N[F]=(N[F+1]<<1|1)&U,b&&(N[F]|=(I[F+1]|I[F])<<1|1|I[F+1]),N[F]&E&&(C=m(b,O),C<=h)){if(h=C,d=O,y=b,d<=g)break;M=Math.max(1,2*g-d)}}if(m(b+1,g)>h)break;I=N}if(p&&d>=0){const b=Math.min(u-1,d+l-1+y);for(let Q=d;Q<=b;Q+=1)n[t[Q]]&&(f[Q]=1)}const B={isMatch:d>=0,score:Math.max(.001,C)};if(p){const b=_rr(f,a);b.length?c&&(B.indices=b):B.isMatch=!1}return B}function Crr(t){const e={};for(let n=0,o=t.length;n<o;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<o-n-1}return e}function Het(t){if(t.length<=1)return t;t.sort((n,o)=>n[0]-o[0]||n[1]-o[1]);const e=[t[0]];for(let n=1,o=t.length;n<o;n+=1){const i=e[e.length-1],r=t[n];r[0]<=i[1]+1?i[1]=Math.max(i[1],r[1]):e.push(r)}return e}const gEn={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},yrr=new RegExp("["+Object.keys(gEn).join("")+"]","g"),Hte=typeof String.prototype.normalize=="function"?t=>t.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(yrr,e=>gEn[e]):t=>t;var Oet=class{constructor(t,{location:e=Pa.location,threshold:n=Pa.threshold,distance:o=Pa.distance,includeMatches:i=Pa.includeMatches,findAllMatches:r=Pa.findAllMatches,minMatchCharLength:s=Pa.minMatchCharLength,isCaseSensitive:a=Pa.isCaseSensitive,ignoreDiacritics:c=Pa.ignoreDiacritics,ignoreLocation:A=Pa.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:c,ignoreLocation:A},t=a?t:t.toLowerCase(),t=c?Hte(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(g,h)=>{this.chunks.push({pattern:g,alphabet:Crr(g),startIndex:h})},u=this.pattern.length;if(u>32){let g=0;const h=u%32,d=u-h;for(;g<d;)l(this.pattern.substr(g,32),g),g+=32;if(h){const m=u-32;l(this.pattern.substr(m),m)}}else l(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?Hte(t):t,this.pattern===t){if(t.length<this.options.minMatchCharLength)return{isMatch:!1,score:1};const d={isMatch:!0,score:0};return o&&(d.indices=[[0,t.length-1]]),d}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,ignoreLocation:A}=this.options,l=[];let u=0,g=!1;this.chunks.forEach(({pattern:d,alphabet:m,startIndex:p})=>{const{isMatch:f,score:_,indices:I}=Irr(t,d,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,includeMatches:o,ignoreLocation:A});f&&(g=!0),u+=_,f&&I&&l.push(...I)});const h={isMatch:g,score:g?u/this.chunks.length:1};return g&&o&&(h.indices=Het(l)),h}};const xrr=new Set(["fuzzy","include"]);function Err(t){return t.startsWith("inverse")}const Get=[{type:"exact",multiRegex:/^="(.*)"$/,singleRegex:/^=(.*)$/,create:t=>({type:"exact",search(e){const n=e===t;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"include",multiRegex:/^'"(.*)"$/,singleRegex:/^'(.*)$/,create:t=>({type:"include",search(e){let n=0,o;const i=[],r=t.length;for(;(o=e.indexOf(t,n))>-1;)n=o+r,i.push([o,n-1]);const s=!!i.length;return{isMatch:s,score:s?0:1,indices:i}}})},{type:"prefix-exact",multiRegex:/^\^"(.*)"$/,singleRegex:/^\^(.*)$/,create:t=>({type:"prefix-exact",search(e){const n=e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}})},{type:"inverse-prefix-exact",multiRegex:/^!\^"(.*)"$/,singleRegex:/^!\^(.*)$/,create:t=>({type:"inverse-prefix-exact",search(e){const n=!e.startsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"inverse-suffix-exact",multiRegex:/^!"(.*)"\$$/,singleRegex:/^!(.*)\$$/,create:t=>({type:"inverse-suffix-exact",search(e){const n=!e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"suffix-exact",multiRegex:/^"(.*)"\$$/,singleRegex:/^(.*)\$$/,create:t=>({type:"suffix-exact",search(e){const n=e.endsWith(t);return{isMatch:n,score:n?0:1,indices:[e.length-t.length,e.length-1]}}})},{type:"inverse-exact",multiRegex:/^!"(.*)"$/,singleRegex:/^!(.*)$/,create:t=>({type:"inverse-exact",search(e){const n=e.indexOf(t)===-1;return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}})},{type:"fuzzy",multiRegex:/^"(.*)"$/,singleRegex:/^(.*)$/,create:(t,e={})=>{const n=new Oet(t,{location:e.location??Pa.location,threshold:e.threshold??Pa.threshold,distance:e.distance??Pa.distance,includeMatches:e.includeMatches??Pa.includeMatches,findAllMatches:e.findAllMatches??Pa.findAllMatches,minMatchCharLength:e.minMatchCharLength??Pa.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??Pa.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??Pa.ignoreDiacritics,ignoreLocation:e.ignoreLocation??Pa.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],dEn=Get.length,Brr="\0",brr="|";function Srr(t){const e=[],n=t.length;let o=0;for(;o<n;){for(;o<n&&t[o]===" ";)o++;if(o>=n)break;let i=o;for(;i<n&&t[i]!==" "&&t[i]!=='"';)i++;if(i<n&&t[i]==='"'){for(i++;i<n;){if(t[i]==='"'){const r=i+1;if(r>=n||t[r]===" "){i++;break}if(t[r]==="$"&&(r+1>=n||t[r+1]===" ")){i+=2;break}}i++}e.push(t.substring(o,i)),o=i}else{for(;i<n&&t[i]!==" ";)i++;e.push(t.substring(o,i)),o=i}}return e}function hEn(t,e){const n=t.match(e);return n?n[1]:null}function Qrr(t,e={}){return t.replace(/\\\|/g,Brr).split(brr).map(n=>{const o=Srr(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let c=!1,A=-1;for(;!c&&++A<dEn;){const l=Get[A],u=hEn(a,l.multiRegex);u&&(i.push(l.create(u,e)),c=!0)}if(!c)for(A=-1;++A<dEn;){const l=Get[A],u=hEn(a,l.singleRegex);if(u){i.push(l.create(u,e));break}}}return i})}var vrr=class{constructor(t,{isCaseSensitive:e=Pa.isCaseSensitive,ignoreDiacritics:n=Pa.ignoreDiacritics,includeMatches:o=Pa.includeMatches,minMatchCharLength:i=Pa.minMatchCharLength,ignoreLocation:r=Pa.ignoreLocation,findAllMatches:s=Pa.findAllMatches,location:a=Pa.location,threshold:c=Pa.threshold,distance:A=Pa.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:c,distance:A},t=e?t:t.toLowerCase(),t=n?Hte(t):t,this.pattern=t,this.query=Qrr(this.pattern,this.options)}static condition(t,e){return e.useExtendedSearch}searchIn(t){const e=this.query;if(!e)return{isMatch:!1,score:1};const{includeMatches:n,isCaseSensitive:o,ignoreDiacritics:i}=this.options;t=o?t:t.toLowerCase(),t=i?Hte(t):t;let r=0;const s=[];let a=0,c=!1;for(let A=0,l=e.length;A<l;A+=1){const u=e[A];s.length=0,r=0,c=!1;for(let g=0,h=u.length;g<h;g+=1){const d=u[g],{isMatch:m,indices:p,score:f}=d.search(t);if(m)r+=1,a+=f,Err(d.type)&&(c=!0),n&&(xrr.has(d.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,c=!1;break}}if(r){const g={isMatch:!0,score:a/r};return c&&(g.hasInverse=!0),n&&(g.indices=Het(s)),g}}return{isMatch:!1,score:1}}};const Yet=[];function Uet(...t){Yet.push(...t)}function dIe(t,e){for(let n=0,o=Yet.length;n<o;n+=1){const i=Yet[n];if(i.condition(t,e))return new i(t,e)}return new Oet(t,e)}const hIe={AND:"$and",OR:"$or"},Ket={PATH:"$path",PATTERN:"$val"},zet=t=>!!(t[hIe.AND]||t[hIe.OR]),wrr=t=>!!t[Ket.PATH],Prr=t=>!wM(t)&&sEn(t)&&!zet(t),mEn=t=>({[hIe.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function pEn(t,e,{auto:n=!0}={}){const o=i=>{if(ZC(i)){const c={keyId:null,pattern:i};return n&&(c.searcher=dIe(i,e)),c}const r=Object.keys(i),s=wrr(i);if(!s&&r.length>1&&!zet(i))return o(mEn(i));if(Prr(i)){const c=s?i[Ket.PATH]:r[0],A=s?i[Ket.PATTERN]:i[c];if(!ZC(A))throw new Error(crr(c));const l={keyId:gIe(c),pattern:A};return n&&(l.searcher=dIe(A,e)),l}const a={children:[],operator:r[0]};return r.forEach(c=>{const A=i[c];wM(A)&&A.forEach(l=>{a.children.push(o(l))})}),a};return zet(t)||(t=mEn(t)),o(t)}function Vet(t,{ignoreFieldNorm:e=Pa.ignoreFieldNorm}){let n=1;return t.forEach(({key:o,norm:i,score:r})=>{const s=o?o.weight:null;n*=Math.pow(r===0&&s?Number.EPSILON:r,(s||1)*(e?1:i))}),n}function Mrr(t,{ignoreFieldNorm:e=Pa.ignoreFieldNorm}){t.forEach(n=>{n.score=Vet(n.matches,{ignoreFieldNorm:e})})}var Drr=class{constructor(t,e){this.limit=t,this.heap=[],this.comparator=e}get size(){return this.heap.length}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):this.comparator(t,this.heap[0])<0&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(){return this.heap.sort(this.comparator)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(this.comparator(e[t],e[n])<=0)break;const o=e[t];e[t]=e[n],e[n]=o,t=n}}_sinkDown(t){const e=this.heap,n=e.length;let o=t;do{t=o;const i=2*t+1,r=2*t+2;if(i<n&&this.comparator(e[i],e[o])>0&&(o=i),r<n&&this.comparator(e[r],e[o])>0&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function Nrr(t){const e=[];return t.matches.forEach(n=>{if(!i5(n.indices)||!n.indices.length)return;const o={indices:n.indices,value:n.value};n.key&&(o.key=n.key.id),n.idx>-1&&(o.refIndex=n.idx),e.push(o)}),e}function Rrr(t,e,{includeMatches:n=Pa.includeMatches,includeScore:o=Pa.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=Nrr(i)),o&&(s.score=i.score),s})}const Trr=/[\p{L}\p{M}\p{N}_]+/gu,fEn=new WeakSet;function krr(t){fEn.has(t)||(fEn.add(t),console.warn(`[Fuse] tokenize regex ${t} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`))}function Frr(t){if(typeof t=="function"){let e=!1;return n=>{const o=t(n);if(!e&&(e=!0,!Array.isArray(o)||o.some(i=>typeof i!="string")))throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(o)?"array containing non-strings":typeof o}.`);return o}}return t instanceof RegExp?(t.global||krr(t),e=>e.match(t)||[]):e=>e.match(Trr)||[]}function Jet({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=Frr(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=Hte(i)),o(i)}}}var Lrr=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=Jet({isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,tokenize:e.tokenize});const n=this.analyzer.tokenize(t),{df:o,fieldCount:i}=e._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(const r of n){this.termSearchers.push(new Oet(r,{location:e.location,threshold:e.threshold,distance:e.distance,includeMatches:e.includeMatches,findAllMatches:e.findAllMatches,minMatchCharLength:e.minMatchCharLength,isCaseSensitive:e.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics,ignoreLocation:!0}));const s=o.get(r)||0,a=Math.log(1+(i-s+.5)/(s+.5));this.idfWeights.push(a)}this.combineAll=e.tokenMatch==="all",this.numTerms=this.termSearchers.length,this.useMask=this.numTerms<=31}searchIn(t){if(!this.termSearchers.length)return{isMatch:!1,score:1};const e=[];let n=0,o=0,i=0,r=0;const s=this.combineAll&&!this.useMask?new Set:null;for(let A=0;A<this.termSearchers.length;A++){const l=this.termSearchers[A].searchIn(t),u=this.idfWeights[A];o+=u,l.isMatch&&(i++,n+=u*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<A:s.add(A)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,c={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(c.indices=Het(e)),this.combineAll&&(this.useMask?c.matchedMask=r:c.matchedTerms=s,c.termCount=this.numTerms),c}};function Wet(t,e,n,o){const i=o.tokenize(e);if(!i.length)return;t.fieldCount++,t.docFieldCount.set(n,(t.docFieldCount.get(n)||0)+1);const r=new Set(i);let s=t.docTermFieldHits.get(n);s||(s=new Map,t.docTermFieldHits.set(n,s));for(const a of r)s.set(a,(s.get(a)||0)+1),t.df.set(a,(t.df.get(a)||0)+1)}function _En(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){Wet(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const c=s[a];if(c)if(Array.isArray(c))for(const A of c)Wet(t,A.v,i,o);else Wet(t,c.v,i,o)}}function Hrr(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)_En(o,i,e,n);return o}function Orr(t,e,n,o){_En(t,e,n,o)}function Grr(t,e){const n=t.docFieldCount.get(e);if(n===void 0)return;t.fieldCount-=n,t.docFieldCount.delete(e);const o=t.docTermFieldHits.get(e);if(o){for(const[i,r]of o){const s=(t.df.get(i)||0)-r;s<=0?t.df.delete(i):t.df.set(i,s)}t.docTermFieldHits.delete(e)}}function IEn(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,c)=>a-c);for(const a of n)Grr(t,a);const o=a=>{let c=0,A=n.length;for(;c<A;){const l=c+A>>>1;n[l]<a?c=l+1:A=l}return a-c},i=n[0],r=new Map;for(const[a,c]of t.docFieldCount)r.set(a>i?o(a):a,c);t.docFieldCount=r;const s=new Map;for(const[a,c]of t.docTermFieldHits)s.set(a>i?o(a):a,c);t.docTermFieldHits=s}var PM=class{constructor(t,e,n){this.options={...Pa,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new drr(this.options.keys),this._docs=t,this._myIndex=null,this._invertedIndex=null,this.setCollection(t,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(t){if(this._lastQuery===t)return this._lastSearcher;const e=dIe(t,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=t,this._lastSearcher=e,e}setCollection(t,e){if(this._docs=t,e&&!(e instanceof Let))throw new Error(arr);if(this._myIndex=e||uEn(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=Jet({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Hrr(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!i5(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=Jet({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});Orr(this._invertedIndex,e,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}remove(t=()=>!1){const e=[],n=[];for(let o=0,i=this._docs.length;o<i;o+=1)t(this._docs[o],o)&&(e.push(this._docs[o]),n.push(o));if(n.length){this._invertedIndex&&IEn(this._invertedIndex,n);const o=new Set(n);this._docs=this._docs.filter((i,r)=>!o.has(r)),this._myIndex.removeAll(n),this._invalidateSearcherCache()}return e}removeAt(t){if(!Number.isInteger(t)||t<0||t>=this._docs.length)throw new Error(Fet);this._invertedIndex&&IEn(this._invertedIndex,[t]);const e=this._docs.splice(t,1)[0];return this._myIndex.removeAt(t),this._invalidateSearcherCache(),e}_invalidateSearcherCache(){this._lastQuery=null,this._lastSearcher=null}getIndex(){return this._myIndex}_normalizedKeys(){return this._myIndex.keys.map(t=>this._keyStore.get(t.id)||t)}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(ZC(t)&&!t.trim()){let g=this._docs.map((h,d)=>({item:h,refIndex:d}));return lIe(n)&&n>-1&&(g=g.slice(0,n)),g}const c=r&&lIe(n)&&n>0&&ZC(t),A=s,l=(g,h)=>A(g,h)||g.idx-h.idx;let u;if(c){const g=new Drr(n,l);ZC(this._docs[0])?this._searchStringList(t,{heap:g,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:g,ignoreFieldNorm:a}),u=g.extractSorted()}else u=ZC(t)?ZC(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),Mrr(u,{ignoreFieldNorm:a}),r&&u.sort(ZC(t)?l:A),lIe(n)&&n>-1&&(u=u.slice(0,n));return Rrr(u,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:c,n:A})=>{if(!i5(a))return;const l=o.searchIn(a);if(l.isMatch){const u={score:l.score,value:a,norm:A,indices:l.indices};i&&(u.matchedMask=l.matchedMask,u.matchedTerms=l.matchedTerms,u.termCount=l.termCount);const g=[u];if(!i||this._coversAllTokens(g)){const h={item:a,idx:c,matches:g};e?(h.score=Vet(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=pEn(t,this.options),n=this._normalizedKeys(),o=(a,c,A)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let m;return h===null?(m=[],n.forEach((p,f)=>{m.push(...this._findMatches({key:p,value:c[f],searcher:d}))})):m=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(c,h),searcher:d}),m&&m.length?[{idx:A,item:c,matches:m}]:[]}const{children:l,operator:u}=a,g=[];for(let h=0,d=l.length;h<d;h+=1){const m=l[h],p=o(m,c,A);if(p.length)g.push(...p);else if(u===hIe.AND)return[]}return g},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:c})=>{if(i5(a)){const A=o(e,a,c);A.length&&(r.has(c)||(r.set(c,{idx:c,item:a,matches:[]}),s.push(r.get(c))),A.forEach(({matches:l})=>{r.get(c).matches.push(...l)}))}}),s}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=this._normalizedKeys(),a=e?null:[];return r.forEach(({$:c,i:A})=>{if(!i5(c))return;const l=[];let u=!1,g=!1;if(s.forEach((h,d)=>{const m=this._findMatches({key:h,value:c[d],searcher:o});m.length?(l.push(...m),m[0].hasInverse&&(g=!0)):u=!0}),!(g&&u)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:A,item:c,matches:l};e?(h.score=Vet(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!i5(e))return[];const o=[];if(wM(e))e.forEach(({v:i,i:r,n:s})=>{if(!i5(i))return;const a=n.searchIn(i);if(a.isMatch){const c={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(c.matchedMask=a.matchedMask,c.matchedTerms=a.matchedTerms,c.termCount=a.termCount),o.push(c)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};PM.version="7.5.0",PM.createIndex=uEn,PM.parseIndex=frr,PM.config=Pa,PM.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(grr);return dIe(t,{...Pa,...n}).searchIn(e)},PM.parseQuery=pEn,Uet(vrr),Uet(Lrr),PM.use=function(...t){t.forEach(e=>Uet(e))};var Yrr=PM;const Urr="https://kicad-mod-cache.tscircuit.com";let jet=null,Ote=null,$et=null;const Krr=async()=>jet||Ote||(Ote=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(jet=t,Ote=null,t)),Ote),zrr=async(t,e=20)=>{const n=await Krr();return $et||($et=new Yrr(n)),$et.search(t).slice(0,e).map(o=>o.item)},Vrr=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},Jrr=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),Wrr=async t=>{const e=await fetch(`${Urr}/${Jrr(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await n5("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},CEn=t=>t?.source==="jlcpcb"||t?.source==="kicad",jrr=async(t,e)=>{if(t.source==="jlcpcb")return orr(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return Wrr(t.footprint.path);throw new Error("Footprint preview is not available for this source")},$rr=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=q.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[K.jsxs("div",{className:"rf-relative rf-flex-grow",children:[K.jsx(HXe,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),K.jsx(het,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),K.jsx(Ic,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):K.jsxs(K.Fragment,{children:[K.jsx(HXe,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),K.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},qrr=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Xrr=t=>qrr.format(t),yEn=t=>{switch(t.source){case"tscircuit.com":{const e=t.package;return`tscircuit-${e.package_id??`${e.org_owner_tscircuit_handle??"unknown"}-${e.unscoped_name??e.name??"package"}`}`}case"jlcpcb":return`jlc-${t.component.lcscId}`;case"kicad":return`kicad-${t.footprint.path}`;default:return"unknown"}},Zrr=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.isDirectLookup?t.component.partNumber:t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},esr=t=>{switch(t.source){case"tscircuit.com":return t.package.description||(t.package.org_owner_tscircuit_handle?`Component by ${t.package.org_owner_tscircuit_handle}`:void 0);case"jlcpcb":return t.component.description;case"kicad":return t.footprint.description}},tsr=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.isDirectLookup?void 0:t.component.partNumber;case"kicad":return}},nsr=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?yEn(e):null;return K.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=yEn(r),a=i===s,c=Zrr(r),A=esr(r),l=tsr(r),u=r.source==="jlcpcb"?r.component.stock:null,g=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return K.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 ${a?"rf-bg-zinc-100":""}`,onClick:()=>n(r),children:[K.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[K.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[K.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:[c,r.source==="jlcpcb"&&h!=null&&K.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${h?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:h?"Basic":"Extended"}),d&&K.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"}),r.source==="tscircuit.com"&&r.package.is_private&&K.jsx(xVi,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&u!=null?K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[u.toLocaleString()," in stock"]}):null]}),K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?K.jsx("span",{className:"rf-mr-2",children:l}):null,A]})]}),K.jsxs("div",{children:[r.source==="tscircuit.com"&&o?K.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:K.jsx(Ic,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:m=>{m.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&u!=null?K.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:[u.toLocaleString()," in stock"]}):null,g!=null&&K.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:Xrr(g)})]})]},s)})})},osr=({circuitJson:t,error:e,isLoading:n,height:o})=>K.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?K.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:o},children:[K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?K.jsx("div",{className:"rf-flex rf-w-full rf-items-center rf-justify-center rf-bg-zinc-950 rf-p-4",style:{height:o},children:K.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[K.jsx(LXe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),K.jsx("span",{children:e})]})}):t?K.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:K.jsx(TXe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):K.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:o},children:"No preview"})}),xEn={importComponentDialog:101,importComponentDetailsDialog:102},isr=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:c})=>{const A=t?.package??null,l=A?.latest_pcb_preview_image_url,u=A?.latest_sch_preview_image_url,g=A?.latest_cad_preview_image_url,h=A?.unscoped_name?.split("/").pop()??A?.unscoped_name,d=A?.org_owner_tscircuit_handle??void 0,m=d?`https://tscircuit.com/${d}`:void 0,p=d&&h?`https://tscircuit.com/${d}/${h}`:void 0;return K.jsx(Ek,{open:e,onOpenChange:n,children:K.jsxs(SM,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:xEn.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:[K.jsx(QM,{className:"rf-pb-4 rf-border-b",children:K.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx(vM,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),K.jsx(Bk,{children:A?.description})]})})}),K.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?K.jsxs("div",{children:[K.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),K.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?K.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(g||l||u)&&K.jsx(K.Fragment,{children:K.jsxs("div",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),K.jsxs(_ke,{value:r,onValueChange:f=>s(f),children:[K.jsxs(hhe,{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:[l&&K.jsx(J7,{value:"pcb",children:"PCB"}),u&&K.jsx(J7,{value:"schematic",children:"Schematic"}),g&&K.jsx(J7,{value:"3d",children:"3D"})]}),K.jsxs("div",{className:"rf-mt-4",children:[K.jsx(SI,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?K.jsx("img",{src:l,alt:`${h??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(SI,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?K.jsx("img",{src:u,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(SI,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?K.jsx("img",{src:g,alt:`${h??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?K.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),K.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),K.jsxs(jK,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[K.jsx("div",{className:"rf-flex-1",children:p?K.jsxs(Ic,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[K.jsx(mVi,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),K.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(Ic,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),K.jsx(Ic,{onClick:c,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},rsr=()=>{const[t,e]=q.useState(null),[n,o]=q.useState(!1),i=q.useCallback(async(s,a)=>{o(!0);try{const c=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!c.ok)throw new Error(`Failed to load package details: ${c.status}`);const A=await c.json();e(A.package??null)}catch(c){console.error("Failed to fetch package details",c),e(null)}finally{o(!1)}},[]),r=q.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},ssr=(t,e)=>{const[n,o]=q.useState({circuitJson:null,error:null,isLoading:!1});return q.useEffect(()=>{if(!t||!CEn(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),jrr(t,e).then(r=>{i||o({circuitJson:r,error:null,isLoading:!1})}).catch(r=>{i||o({circuitJson:null,error:r instanceof Error?r.message:"Failed to load footprint preview",isLoading:!1})}),()=>{i=!0}},[t,e]),n},asr=async(t,e)=>{const n={"Content-Type":"application/json"};e&&(n.Authorization=`Bearer ${e}`);const o=await fetch("https://registry-api.tscircuit.com/packages/search",{method:"POST",headers:n,body:JSON.stringify({query:t})});if(!o.ok)throw new Error(`tscircuit registry error: ${o.status}`);return(await o.json()).packages??[]},csr=({sessionToken:t})=>{const[e,n]=q.useState([]),[o,i]=q.useState(!1),[r,s]=q.useState(null),[a,c]=q.useState(!1),A=q.useCallback(async u=>{const g=u.trim();if(!g)return[];i(!0),s(null);try{const d=(await asr(g,t)).map(m=>({source:"tscircuit.com",package:m}));return n(d),d}catch(h){return console.error("Error searching tscircuit packages",h),n([]),s(h instanceof Error?h.message:"Failed to search tscircuit packages"),[]}finally{i(!1),c(!0)}},[t]),l=q.useCallback(()=>{n([]),i(!1),s(null),c(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:A,reset:l}},Asr=t=>{const e=/^C(\d+)$/i.exec(t.trim());if(!e)return null;const n=Number(e[1]);if(!Number.isSafeInteger(n))return null;const o=`C${e[1]}`;return{source:"jlcpcb",component:{lcscId:n,manufacturer:o,partNumber:o,description:"Import directly from EasyEDA; stock and availability are unknown",package:"",isDirectLookup:!0}}},EEn=(t,e)=>{const n=Asr(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},lsr=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},usr=()=>{const[t,e]=q.useState([]),[n,o]=q.useState(!1),[i,r]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async l=>{const u=lsr(l);if(!u)return[];o(!0),r(null);try{const g=await err(u,10),h=EEn(l,g.map(d=>({source:"jlcpcb",component:trr(d)})));return e(h),h}catch(g){console.error("Error searching JLCPCB components",g);const h=EEn(l,[]);return e(h),r(h.length>0?null:g instanceof Error?g.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),A=q.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:A}},gsr=()=>{const[t,e]=q.useState([]),[n,o]=q.useState(!1),[i,r]=q.useState(null),[s,a]=q.useState(!1),c=q.useCallback(async l=>{const u=l.trim();if(!u)return[];o(!0),r(null);try{const h=(await zrr(u,20)).map(d=>({source:"kicad",footprint:Vrr(d)}));return e(h),h}catch(g){return console.error("Error searching KiCad footprints",g),e([]),r(g instanceof Error?g.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),A=q.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:A}},dsr=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},hsr=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{Tte();const c=q.useMemo(()=>dsr({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),A=c.length>0,l=c.length===1,[u,g]=q.useState(c[0]??"tscircuit.com"),[h,d]=q.useState(""),[m,p]=q.useState(null),{results:f,isSearching:_,error:I,hasSearched:C,search:y,reset:x}=csr({sessionToken:a}),{results:E,isSearching:B,error:b,hasSearched:Q,search:w,reset:M}=usr(),{results:T,isSearching:N,error:F,hasSearched:O,search:U,reset:Y}=gsr(),{details:j,isLoading:ee,fetchDetails:J,reset:W}=rsr(),[te,re]=q.useState(null),[ne,le]=q.useState(!1),[ge,fe]=q.useState("pcb"),[Ae,_e]=q.useState(null),[ue,me]=q.useState(!1),we=q.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Me,error:he,isLoading:Pe}=ssr(m,we),Qe=CEn(m);q.useEffect(()=>{_e(null)},[m]);const Se=q.useCallback(()=>{x(),M(),Y(),p(null)},[M,Y,x]);q.useEffect(()=>{t||(Se(),d(""),le(!1),re(null),_e(null))},[t,Se]),q.useEffect(()=>{d(""),p(null),u==="tscircuit.com"?x():u==="jlcpcb"?M():u==="kicad"&&Y()},[u,M,Y,x]);const De=gt=>{p(gt),re(gt),fe("pcb"),le(!0),W();const mt=gt.package.org_owner_tscircuit_handle,St=gt.package.unscoped_name;if(mt&&St){const _t=St.split("/").pop()??St;J(mt,_t)}},Ne=async()=>{h.trim()&&(p(null),u==="tscircuit.com"?await y(h):u==="jlcpcb"?await w(h):u==="kicad"&&await U(h))},Ee=async gt=>{try{if(_e(null),me(!0),gt.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:gt,footprint:gt.footprint.qualifiedName})}else if(gt.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const mt=await nrr(gt.component.partNumber,{headers:n,apiBase:s});await r({result:gt,tsx:mt})}else if(gt.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const mt=gt.package.org_owner_tscircuit_handle,St=gt.package.unscoped_name;if(!mt||!St)throw new Error("Missing package metadata");const _t=St.split("/").pop()??St,Tt=`@tsci/${mt}.${_t}`;await i({result:gt,fullPackageName:Tt})}return!0}catch(mt){return console.error("Failed to import component",mt),_e(mt instanceof Error?mt.message:"Failed to import component"),!1}finally{me(!1)}};let Te=[],Ie=!1,ke=null,Ge=!1;u==="tscircuit.com"?(Te=f,Ie=_,ke=I,Ge=C):u==="jlcpcb"?(Te=E,Ie=B,ke=b,Ge=Q):u==="kicad"&&(Te=T,Ie=N,ke=F,Ge=O);const qe=async()=>{if(!m)return;await Ee(m)&&(e(),Se(),d(""))},rt=gt=>{gt||e()},ct=gt=>{le(gt),gt||re(null)};return K.jsxs(Ek,{open:t,onOpenChange:rt,children:[K.jsxs(SM,{style:{width:"calc(100vw - 2rem)",maxWidth:Qe?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:xEn.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[K.jsxs(QM,{children:[K.jsxs(vM,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?AIe[u].label:""," ","Component"]}),K.jsx(Bk,{className:"rf-text-sm",children:A?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),A?K.jsxs(_ke,{value:u,onValueChange:gt=>g(gt),className:"rf-min-w-0 rf-w-full",children:[!l&&K.jsx(hhe,{className:"rf-flex rf-w-full rf-gap-2",children:c.map(gt=>K.jsx(J7,{value:gt,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:AIe[gt].label},gt))}),K.jsxs("div",{className:"rf-min-w-0",style:Qe?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[K.jsxs("div",{className:"rf-min-w-0",children:[K.jsx($rr,{query:h,placeholder:AIe[u].placeholder,isSearching:Ie,onQueryChange:d,onSubmit:Ne}),K.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:Ie?K.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[K.jsx($E,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),K.jsx("p",{children:"Searching..."})]}):Te.length>0?K.jsx(nsr,{results:Te,selected:m,onSelect:p,onShowDetails:u==="tscircuit.com"?De:void 0}):K.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:ke?`Error: ${ke}`:Ge?AIe[u].emptyMessage:"Enter a search term to find components"})})]}),Qe?K.jsx("div",{className:"rf-mt-4",children:K.jsx(osr,{circuitJson:Me,error:he,isLoading:Pe,height:325})}):null]})]}):null,Ae?K.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:Ae}):null,K.jsxs(jK,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(Ic,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),K.jsx(Ic,{onClick:qe,disabled:!m||ue,className:"rf-order-1 sm:rf-order-2",children:ue?K.jsx($E,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),K.jsx(isr,{packageResult:te,isOpen:ne,onOpenChange:ct,isLoading:ee,details:j,previewTab:ge,onPreviewTabChange:gt=>fe(gt),isSubmitting:ue,onImport:()=>{te&&Ee(te).then(gt=>{gt&&(le(!1),e(),Se(),d(""))})}})]})},msr=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},BEn=t=>{const e=xd(s=>s.pushEvent),n=xd(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const A=s.package.unscoped_name??s.package.name;await ua.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${A}"`,success:`Install requested for "${A}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await ua.promise(navigator.clipboard.writeText(s),{loading:`Copying "${s}"`,success:`Copied "${s}" to clipboard`,error:a=>`Failed to copy footprint: ${a instanceof Error?a.message:String(a)}`})},r=async({result:s,tsx:a})=>{const A=`imports/${msr(a)}.tsx`;await ua.promise(n(A,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${A}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return K.jsx(hsr,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};BEn.displayName="ImportComponentDialogForCli";const psr=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>FBr),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},fsr=async({circuitJson:t,projectName:e})=>{await ua.promise((async()=>{const n=await psr({circuitJson:t,projectName:e});o5(n,{fileName:`${e}_altium_project.zip`})})(),{loading:"Generating Altium project...",success:"Altium project ZIP ready",error:n=>`Failed to generate Altium project: ${n instanceof Error?n.message:String(n)}`})};var qet={exports:{}},bEn;function _sr(){return bEn||(bEn=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,u){if(!r[l]){if(!i[l]){var g=typeof B8=="function"&&B8;if(!u&&g)return g(l,!0);if(c)return c(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=r[l]={exports:{}};i[l][0].call(d.exports,function(m){var p=i[l][1][m];return a(p||m)},d,d.exports,o,i,r,s)}return r[l].exports}for(var c=typeof B8=="function"&&B8,A=0;A<s.length;A++)a(s[A]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(A){for(var l,u,g,h,d,m,p,f=[],_=0,I=A.length,C=I,y=s.getTypeOf(A)!=="string";_<A.length;)C=I-_,g=y?(l=A[_++],u=_<I?A[_++]:0,_<I?A[_++]:0):(l=A.charCodeAt(_++),u=_<I?A.charCodeAt(_++):0,_<I?A.charCodeAt(_++):0),h=l>>2,d=(3&l)<<4|u>>4,m=1<C?(15&u)<<2|g>>6:64,p=2<C?63&g:64,f.push(c.charAt(h)+c.charAt(d)+c.charAt(m)+c.charAt(p));return f.join("")},r.decode=function(A){var l,u,g,h,d,m,p=0,f=0,_="data:";if(A.substr(0,_.length)===_)throw new Error("Invalid base64 input, it looks like a data url.");var I,C=3*(A=A.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(A.charAt(A.length-1)===c.charAt(64)&&C--,A.charAt(A.length-2)===c.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(I=a.uint8array?new Uint8Array(0|C):new Array(0|C);p<A.length;)l=c.indexOf(A.charAt(p++))<<2|(h=c.indexOf(A.charAt(p++)))>>4,u=(15&h)<<4|(d=c.indexOf(A.charAt(p++)))>>2,g=(3&d)<<6|(m=c.indexOf(A.charAt(p++))),I[f++]=l,d!==64&&(I[f++]=u),m!==64&&(I[f++]=g);return I}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),c=o("./stream/Crc32Probe"),A=o("./stream/DataLengthProbe");function l(u,g,h,d,m){this.compressedSize=u,this.uncompressedSize=g,this.crc32=h,this.compression=d,this.compressedContent=m}l.prototype={getContentWorker:function(){var u=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new A("data_length")),g=this;return u.on("end",function(){if(this.streamInfo.data_length!==g.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),u},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},l.createWorkerFrom=function(u,g,h){return u.pipe(new c).pipe(new A("uncompressedSize")).pipe(g.compressWorker(h)).pipe(new A("compressedSize")).withStreamInfo("compression",g)},i.exports=l},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var c,A=[],l=0;l<256;l++){c=l;for(var u=0;u<8;u++)c=1&c?3988292384^c>>>1:c>>>1;A[l]=c}return A})();i.exports=function(c,A){return c!==void 0&&c.length?s.getTypeOf(c)!=="string"?(function(l,u,g,h){var d=a,m=h+g;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^u[p])];return-1^l})(0|A,c,c.length,0):(function(l,u,g,h){var d=a,m=h+g;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^u.charCodeAt(p))];return-1^l})(0|A,c,c.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),c=o("./utils"),A=o("./stream/GenericWorker"),l=s?"uint8array":"array";function u(g,h){A.call(this,"FlateWorker/"+g),this._pako=null,this._pakoAction=g,this._pakoOptions=h,this.meta={}}r.magic="\b\0",c.inherits(u,A),u.prototype.processChunk=function(g){this.meta=g.meta,this._pako===null&&this._createPako(),this._pako.push(c.transformTo(l,g.data),!1)},u.prototype.flush=function(){A.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},u.prototype.cleanUp=function(){A.prototype.cleanUp.call(this),this._pako=null},u.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var g=this;this._pako.onData=function(h){g.push({data:h,meta:g.meta})}},r.compressWorker=function(g){return new u("Deflate",g)},r.uncompressWorker=function(){return new u("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,m){var p,f="";for(p=0;p<m;p++)f+=String.fromCharCode(255&d),d>>>=8;return f}function a(d,m,p,f,_,I){var C,y,x=d.file,E=d.compression,B=I!==l.utf8encode,b=c.transformTo("string",I(x.name)),Q=c.transformTo("string",l.utf8encode(x.name)),w=x.comment,M=c.transformTo("string",I(w)),T=c.transformTo("string",l.utf8encode(w)),N=Q.length!==x.name.length,F=T.length!==w.length,O="",U="",Y="",j=x.dir,ee=x.date,J={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(J.crc32=d.crc32,J.compressedSize=d.compressedSize,J.uncompressedSize=d.uncompressedSize);var W=0;m&&(W|=8),B||!N&&!F||(W|=2048);var te=0,re=0;j&&(te|=16),_==="UNIX"?(re=798,te|=(function(le,ge){var fe=le;return le||(fe=ge?16893:33204),(65535&fe)<<16})(x.unixPermissions,j)):(re=20,te|=(function(le){return 63&(le||0)})(x.dosPermissions)),C=ee.getUTCHours(),C<<=6,C|=ee.getUTCMinutes(),C<<=5,C|=ee.getUTCSeconds()/2,y=ee.getUTCFullYear()-1980,y<<=4,y|=ee.getUTCMonth()+1,y<<=5,y|=ee.getUTCDate(),N&&(U=s(1,1)+s(u(b),4)+Q,O+="up"+s(U.length,2)+U),F&&(Y=s(1,1)+s(u(M),4)+T,O+="uc"+s(Y.length,2)+Y);var ne="";return ne+=`
5678
5678
  \0`,ne+=s(W,2),ne+=E.magic,ne+=s(C,2),ne+=s(y,2),ne+=s(J.crc32,4),ne+=s(J.compressedSize,4),ne+=s(J.uncompressedSize,4),ne+=s(b.length,2),ne+=s(O.length,2),{fileRecord:g.LOCAL_FILE_HEADER+ne+b+O,dirRecord:g.CENTRAL_FILE_HEADER+s(re,2)+ne+s(M.length,2)+"\0\0\0\0"+s(te,4)+s(f,4)+b+O+M}}var c=o("../utils"),A=o("../stream/GenericWorker"),l=o("../utf8"),u=o("../crc32"),g=o("../signature");function h(d,m,p,f){A.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=m,this.zipPlatform=p,this.encodeFileName=f,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}c.inherits(h,A),h.prototype.push=function(d){var m=d.meta.percent||0,p=this.entriesCount,f=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,A.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:p?(m+100*(p-f-1))/p:100}}))},h.prototype.openedSource=function(d){this.currentSourceOffset=this.bytesWritten,this.currentFile=d.file.name;var m=this.streamFiles&&!d.file.dir;if(m){var p=a(d,m,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:p.fileRecord,meta:{percent:0}})}else this.accumulate=!0},h.prototype.closedSource=function(d){this.accumulate=!1;var m=this.streamFiles&&!d.file.dir,p=a(d,m,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(p.dirRecord),m)this.push({data:(function(f){return g.DATA_DESCRIPTOR+s(f.crc32,4)+s(f.compressedSize,4)+s(f.uncompressedSize,4)})(d),meta:{percent:100}});else for(this.push({data:p.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},h.prototype.flush=function(){for(var d=this.bytesWritten,m=0;m<this.dirRecords.length;m++)this.push({data:this.dirRecords[m],meta:{percent:100}});var p=this.bytesWritten-d,f=(function(_,I,C,y,x){var E=c.transformTo("string",x(y));return g.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(_,2)+s(_,2)+s(I,4)+s(C,4)+s(E.length,2)+E})(this.dirRecords.length,p,d,this.zipComment,this.encodeFileName);this.push({data:f,meta:{percent:100}})},h.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},h.prototype.registerPrevious=function(d){this._sources.push(d);var m=this;return d.on("data",function(p){m.processChunk(p)}),d.on("end",function(){m.closedSource(m.previous.streamInfo),m._sources.length?m.prepareNextSource():m.end()}),d.on("error",function(p){m.error(p)}),this},h.prototype.resume=function(){return!!A.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},h.prototype.error=function(d){var m=this._sources;if(!A.prototype.error.call(this,d))return!1;for(var p=0;p<m.length;p++)try{m[p].error(d)}catch{}return!0},h.prototype.lock=function(){A.prototype.lock.call(this);for(var d=this._sources,m=0;m<d.length;m++)d[m].lock()},i.exports=h},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(o,i,r){var s=o("../compressions"),a=o("./ZipFileWorker");r.generateWorker=function(c,A,l){var u=new a(A.streamFiles,l,A.platform,A.encodeFileName),g=0;try{c.forEach(function(h,d){g++;var m=(function(I,C){var y=I||C,x=s[y];if(!x)throw new Error(y+" is not a valid compression method !");return x})(d.options.compression,A.compression),p=d.options.compressionOptions||A.compressionOptions||{},f=d.dir,_=d.date;d._compressWorker(m,p).withStreamInfo("file",{name:h,dir:f,date:_,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(u)}),u.entriesCount=g}catch(h){u.error(h)}return u}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(o,i,r){function s(){if(!(this instanceof s))return new s;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 a=new s;for(var c in this)typeof this[c]!="function"&&(a[c]=this[c]);return a}}(s.prototype=o("./object")).loadAsync=o("./load"),s.support=o("./support"),s.defaults=o("./defaults"),s.version="3.10.2",s.loadAsync=function(a,c){return new s().loadAsync(a,c)},s.external=o("./external"),i.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(o,i,r){var s=o("./utils"),a=o("./external"),c=o("./utf8"),A=o("./zipEntries"),l=o("./stream/Crc32Probe"),u=o("./nodejsUtils");function g(h){return new a.Promise(function(d,m){var p=h.decompressed.getContentWorker().pipe(new l);p.on("error",function(f){m(f)}).on("end",function(){p.streamInfo.crc32!==h.decompressed.crc32?m(new Error("Corrupted zip : CRC32 mismatch")):d()}).resume()})}i.exports=function(h,d){var m=this;return d=s.extend(d||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:c.utf8decode}),u.isNode&&u.isStream(h)?a.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",h,!0,d.optimizedBinaryString,d.base64).then(function(p){var f=new A(d);return f.load(p),f}).then(function(p){var f=[a.Promise.resolve(p)],_=p.files;if(d.checkCRC32)for(var I=0;I<_.length;I++)f.push(g(_[I]));return a.Promise.all(f)}).then(function(p){for(var f=p.shift(),_=f.files,I=0;I<_.length;I++){var C=_[I],y=C.fileNameStr,x=s.resolve(C.fileNameStr);m.file(x,C.decompressed,{binary:!0,optimizedBinaryString:!0,date:C.date,dir:C.dir,comment:C.fileCommentStr.length?C.fileCommentStr:null,unixPermissions:C.unixPermissions,dosPermissions:C.dosPermissions,createFolders:d.createFolders}),C.dir||(m.file(x).unsafeOriginalName=y)}return f.zipComment.length&&(m.comment=f.zipComment),m})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(o,i,r){var s=o("../utils"),a=o("../stream/GenericWorker");function c(A,l){a.call(this,"Nodejs stream input adapter for "+A),this._upstreamEnded=!1,this._bindStream(l)}s.inherits(c,a),c.prototype._bindStream=function(A){var l=this;(this._stream=A).pause(),A.on("data",function(u){l.push({data:u,meta:{percent:0}})}).on("error",function(u){l.isPaused?this.generatedError=u:l.error(u)}).on("end",function(){l.isPaused?l._upstreamEnded=!0:l.end()})},c.prototype.pause=function(){return!!a.prototype.pause.call(this)&&(this._stream.pause(),!0)},c.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},i.exports=c},{"../stream/GenericWorker":28,"../utils":32}],13:[function(o,i,r){var s=o("readable-stream").Readable;function a(c,A,l){s.call(this,A),this._helper=c;var u=this;c.on("data",function(g,h){u.push(g)||u._helper.pause(),l&&l(h)}).on("error",function(g){u.emit("error",g)}).on("end",function(){u.push(null)})}o("../utils").inherits(a,s),a.prototype._read=function(){this._helper.resume()},i.exports=a},{"../utils":32,"readable-stream":16}],14:[function(o,i,r){i.exports={isNode:typeof Buffer<"u",newBufferFrom:function(s,a){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(s,a);if(typeof s=="number")throw new Error('The "data" argument must not be a number');return new Buffer(s,a)},allocBuffer:function(s){if(Buffer.alloc)return Buffer.alloc(s);var a=new Buffer(s);return a.fill(0),a},isBuffer:function(s){return Buffer.isBuffer(s)},isStream:function(s){return s&&typeof s.on=="function"&&typeof s.pause=="function"&&typeof s.resume=="function"}}},{}],15:[function(o,i,r){function s(x,E,B){var b,Q=c.getTypeOf(E),w=c.extend(B||{},u);w.date=w.date||new Date,w.compression!==null&&(w.compression=w.compression.toUpperCase()),typeof w.unixPermissions=="string"&&(w.unixPermissions=parseInt(w.unixPermissions,8)),w.unixPermissions&&16384&w.unixPermissions&&(w.dir=!0),w.dosPermissions&&16&w.dosPermissions&&(w.dir=!0),w.dir&&(x=_(x)),w.createFolders&&(b=f(x))&&I.call(this,b,!0);var M=Q==="string"&&w.binary===!1&&w.base64===!1;B&&B.binary!==void 0||(w.binary=!M),(E instanceof g&&E.uncompressedSize===0||w.dir||!E||E.length===0)&&(w.base64=!1,w.binary=!0,E="",w.compression="STORE",Q="string");var T=null;T=E instanceof g||E instanceof A?E:m.isNode&&m.isStream(E)?new p(x,E):c.prepareContent(x,E,w.binary,w.optimizedBinaryString,w.base64);var N=new h(x,T,w);this.files[x]=N}var a=o("./utf8"),c=o("./utils"),A=o("./stream/GenericWorker"),l=o("./stream/StreamHelper"),u=o("./defaults"),g=o("./compressedObject"),h=o("./zipObject"),d=o("./generate"),m=o("./nodejsUtils"),p=o("./nodejs/NodejsStreamInputAdapter"),f=function(x){x.slice(-1)==="/"&&(x=x.substring(0,x.length-1));var E=x.lastIndexOf("/");return 0<E?x.substring(0,E):""},_=function(x){return x.slice(-1)!=="/"&&(x+="/"),x},I=function(x,E){return E=E!==void 0?E:u.createFolders,x=_(x),this.files[x]||s.call(this,x,null,{dir:!0,createFolders:E}),this.files[x]};function C(x){return Object.prototype.toString.call(x)==="[object RegExp]"}var y={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(x){var E,B,b;for(E in this.files)b=this.files[E],(B=E.slice(this.root.length,E.length))&&E.slice(0,this.root.length)===this.root&&x(B,b)},filter:function(x){var E=[];return this.forEach(function(B,b){x(B,b)&&E.push(b)}),E},file:function(x,E,B){if(arguments.length!==1)return x=this.root+x,s.call(this,x,E,B),this;if(C(x)){var b=x;return this.filter(function(w,M){return!M.dir&&b.test(w)})}var Q=this.files[this.root+x];return Q&&!Q.dir?Q:null},folder:function(x){if(!x)return this;if(C(x))return this.filter(function(Q,w){return w.dir&&x.test(Q)});var E=this.root+x,B=I.call(this,E),b=this.clone();return b.root=B.name,b},remove:function(x){x=this.root+x;var E=this.files[x];if(E||(x.slice(-1)!=="/"&&(x+="/"),E=this.files[x]),E&&!E.dir)delete this.files[x];else for(var B=this.filter(function(Q,w){return w.name.slice(0,x.length)===x}),b=0;b<B.length;b++)delete this.files[B[b].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(x){var E,B={};try{if((B=c.extend(x||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:a.utf8encode})).type=B.type.toLowerCase(),B.compression=B.compression.toUpperCase(),B.type==="binarystring"&&(B.type="string"),!B.type)throw new Error("No output type specified.");c.checkSupport(B.type),B.platform!=="darwin"&&B.platform!=="freebsd"&&B.platform!=="linux"&&B.platform!=="sunos"||(B.platform="UNIX"),B.platform==="win32"&&(B.platform="DOS");var b=B.comment||this.comment||"";E=d.generateWorker(this,B,b)}catch(Q){(E=new A("error")).error(Q)}return new l(E,B.type||"string",B.mimeType)},generateAsync:function(x,E){return this.generateInternalStream(x).accumulate(E)},generateNodeStream:function(x,E){return(x=x||{}).type||(x.type="nodebuffer"),this.generateInternalStream(x).toNodejsStream(E)}};i.exports=y},{"./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(o,i,r){i.exports=o("stream")},{stream:void 0}],17:[function(o,i,r){var s=o("./DataReader");function a(c){s.call(this,c);for(var A=0;A<this.data.length;A++)c[A]=255&c[A]}o("../utils").inherits(a,s),a.prototype.byteAt=function(c){return this.data[this.zero+c]},a.prototype.lastIndexOfSignature=function(c){for(var A=c.charCodeAt(0),l=c.charCodeAt(1),u=c.charCodeAt(2),g=c.charCodeAt(3),h=this.length-4;0<=h;--h)if(this.data[h]===A&&this.data[h+1]===l&&this.data[h+2]===u&&this.data[h+3]===g)return h-this.zero;return-1},a.prototype.readAndCheckSignature=function(c){var A=c.charCodeAt(0),l=c.charCodeAt(1),u=c.charCodeAt(2),g=c.charCodeAt(3),h=this.readData(4);return A===h[0]&&l===h[1]&&u===h[2]&&g===h[3]},a.prototype.readData=function(c){if(this.checkOffset(c),c===0)return[];var A=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,A},i.exports=a},{"../utils":32,"./DataReader":18}],18:[function(o,i,r){var s=o("../utils");function a(c){this.data=c,this.length=c.length,this.index=0,this.zero=0}a.prototype={checkOffset:function(c){this.checkIndex(this.index+c)},checkIndex:function(c){if(this.length<this.zero+c||c<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+c+"). Corrupted zip ?")},setIndex:function(c){this.checkIndex(c),this.index=c},skip:function(c){this.setIndex(this.index+c)},byteAt:function(){},readInt:function(c){var A,l=0;for(this.checkOffset(c),A=this.index+c-1;A>=this.index;A--)l=(l<<8)+this.byteAt(A);return this.index+=c,l},readString:function(c){return s.transformTo("string",this.readData(c))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var c=this.readInt(4);return new Date(Date.UTC(1980+(c>>25&127),(c>>21&15)-1,c>>16&31,c>>11&31,c>>5&63,(31&c)<<1))}},i.exports=a},{"../utils":32}],19:[function(o,i,r){var s=o("./Uint8ArrayReader");function a(c){s.call(this,c)}o("../utils").inherits(a,s),a.prototype.readData=function(c){this.checkOffset(c);var A=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,A},i.exports=a},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(o,i,r){var s=o("./DataReader");function a(c){s.call(this,c)}o("../utils").inherits(a,s),a.prototype.byteAt=function(c){return this.data.charCodeAt(this.zero+c)},a.prototype.lastIndexOfSignature=function(c){return this.data.lastIndexOf(c)-this.zero},a.prototype.readAndCheckSignature=function(c){return c===this.readData(4)},a.prototype.readData=function(c){this.checkOffset(c);var A=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,A},i.exports=a},{"../utils":32,"./DataReader":18}],21:[function(o,i,r){var s=o("./ArrayReader");function a(c){s.call(this,c)}o("../utils").inherits(a,s),a.prototype.readData=function(c){if(this.checkOffset(c),c===0)return new Uint8Array(0);var A=this.data.subarray(this.zero+this.index,this.zero+this.index+c);return this.index+=c,A},i.exports=a},{"../utils":32,"./ArrayReader":17}],22:[function(o,i,r){var s=o("../utils"),a=o("../support"),c=o("./ArrayReader"),A=o("./StringReader"),l=o("./NodeBufferReader"),u=o("./Uint8ArrayReader");i.exports=function(g){var h=s.getTypeOf(g);return s.checkSupport(h),h!=="string"||a.uint8array?h==="nodebuffer"?new l(g):a.uint8array?new u(s.transformTo("uint8array",g)):new c(s.transformTo("array",g)):new A(g)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(o,i,r){r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(o,i,r){var s=o("./GenericWorker"),a=o("../utils");function c(A){s.call(this,"ConvertWorker to "+A),this.destType=A}a.inherits(c,s),c.prototype.processChunk=function(A){this.push({data:a.transformTo(this.destType,A.data),meta:A.meta})},i.exports=c},{"../utils":32,"./GenericWorker":28}],25:[function(o,i,r){var s=o("./GenericWorker"),a=o("../crc32");function c(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}o("../utils").inherits(c,s),c.prototype.processChunk=function(A){this.streamInfo.crc32=a(A.data,this.streamInfo.crc32||0),this.push(A)},i.exports=c},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function c(A){a.call(this,"DataLengthProbe for "+A),this.propName=A,this.withStreamInfo(A,0)}s.inherits(c,a),c.prototype.processChunk=function(A){if(A){var l=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=l+A.data.length}a.prototype.processChunk.call(this,A)},i.exports=c},{"../utils":32,"./GenericWorker":28}],27:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function c(A){a.call(this,"DataWorker");var l=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,A.then(function(u){l.dataIsReady=!0,l.data=u,l.max=u&&u.length||0,l.type=s.getTypeOf(u),l.isPaused||l._tickAndRepeat()},function(u){l.error(u)})}s.inherits(c,a),c.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this.data=null},c.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},c.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},c.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var A=null,l=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":A=this.data.substring(this.index,l);break;case"uint8array":A=this.data.subarray(this.index,l);break;case"array":case"nodebuffer":A=this.data.slice(this.index,l)}return this.index=l,this.push({data:A,meta:{percent:this.max?this.index/this.max*100:0}})},i.exports=c},{"../utils":32,"./GenericWorker":28}],28:[function(o,i,r){function s(a){this.name=a||"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}s.prototype={push:function(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,c){return this._listeners[a].push(c),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,c){if(this._listeners[a])for(var A=0;A<this._listeners[a].length;A++)this._listeners[a][A].call(this,c)},pipe:function(a){return a.registerPrevious(this)},registerPrevious:function(a){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=a.streamInfo,this.mergeStreamInfo(),this.previous=a;var c=this;return a.on("data",function(A){c.processChunk(A)}),a.on("end",function(){c.end()}),a.on("error",function(A){c.error(A)}),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 a=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),a=!0),this.previous&&this.previous.resume(),!a},flush:function(){},processChunk:function(a){this.push(a)},withStreamInfo:function(a,c){return this.extraStreamInfo[a]=c,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var a in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,a)&&(this.streamInfo[a]=this.extraStreamInfo[a])},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 a="Worker "+this.name;return this.previous?this.previous+" -> "+a:a}},i.exports=s},{}],29:[function(o,i,r){var s=o("../utils"),a=o("./ConvertWorker"),c=o("./GenericWorker"),A=o("../base64"),l=o("../support"),u=o("../external"),g=null;if(l.nodestream)try{g=o("../nodejs/NodejsStreamOutputAdapter")}catch{}function h(m,p){return new u.Promise(function(f,_){var I=[],C=m._internalType,y=m._outputType,x=m._mimeType;m.on("data",function(E,B){I.push(E),p&&p(B)}).on("error",function(E){I=[],_(E)}).on("end",function(){try{var E=(function(B,b,Q){switch(B){case"blob":return s.newBlob(s.transformTo("arraybuffer",b),Q);case"base64":return A.encode(b);default:return s.transformTo(B,b)}})(y,(function(B,b){var Q,w=0,M=null,T=0;for(Q=0;Q<b.length;Q++)T+=b[Q].length;switch(B){case"string":return b.join("");case"array":return Array.prototype.concat.apply([],b);case"uint8array":for(M=new Uint8Array(T),Q=0;Q<b.length;Q++)M.set(b[Q],w),w+=b[Q].length;return M;case"nodebuffer":return Buffer.concat(b);default:throw new Error("concat : unsupported type '"+B+"'")}})(C,I),x);f(E)}catch(B){_(B)}I=[]}).resume()})}function d(m,p,f){var _=p;switch(p){case"blob":case"arraybuffer":_="uint8array";break;case"base64":_="string"}try{this._internalType=_,this._outputType=p,this._mimeType=f,s.checkSupport(_),this._worker=m.pipe(new a(_)),m.lock()}catch(I){this._worker=new c("error"),this._worker.error(I)}}d.prototype={accumulate:function(m){return h(this,m)},on:function(m,p){var f=this;return m==="data"?this._worker.on(m,function(_){p.call(f,_.data,_.meta)}):this._worker.on(m,function(){s.delay(p,arguments,f)}),this},resume:function(){return s.delay(this._worker.resume,[],this._worker),this},pause:function(){return this._worker.pause(),this},toNodejsStream:function(m){if(s.checkSupport("nodestream"),this._outputType!=="nodebuffer")throw new Error(this._outputType+" is not supported by this method");return new g(this,{objectMode:this._outputType!=="nodebuffer"},m)}},i.exports=d},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(o,i,r){if(r.base64=!0,r.array=!0,r.string=!0,r.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",r.nodebuffer=typeof Buffer<"u",r.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")r.blob=!1;else{var s=new ArrayBuffer(0);try{r.blob=new Blob([s],{type:"application/zip"}).size===0}catch{try{var a=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);a.append(s),r.blob=a.getBlob("application/zip").size===0}catch{r.blob=!1}}}try{r.nodestream=!!o("readable-stream").Readable}catch{r.nodestream=!1}},{"readable-stream":16}],31:[function(o,i,r){for(var s=o("./utils"),a=o("./support"),c=o("./nodejsUtils"),A=o("./stream/GenericWorker"),l=new Array(256),u=0;u<256;u++)l[u]=252<=u?6:248<=u?5:240<=u?4:224<=u?3:192<=u?2:1;l[254]=l[254]=1;function g(){A.call(this,"utf-8 decode"),this.leftOver=null}function h(){A.call(this,"utf-8 encode")}r.utf8encode=function(d){return a.nodebuffer?c.newBufferFrom(d,"utf-8"):(function(m){var p,f,_,I,C,y=m.length,x=0;for(I=0;I<y;I++)(64512&(f=m.charCodeAt(I)))==55296&&I+1<y&&(64512&(_=m.charCodeAt(I+1)))==56320&&(f=65536+(f-55296<<10)+(_-56320),I++),x+=f<128?1:f<2048?2:f<65536?3:4;for(p=a.uint8array?new Uint8Array(x):new Array(x),I=C=0;C<x;I++)(64512&(f=m.charCodeAt(I)))==55296&&I+1<y&&(64512&(_=m.charCodeAt(I+1)))==56320&&(f=65536+(f-55296<<10)+(_-56320),I++),f<128?p[C++]=f:(f<2048?p[C++]=192|f>>>6:(f<65536?p[C++]=224|f>>>12:(p[C++]=240|f>>>18,p[C++]=128|f>>>12&63),p[C++]=128|f>>>6&63),p[C++]=128|63&f);return p})(d)},r.utf8decode=function(d){return a.nodebuffer?s.transformTo("nodebuffer",d).toString("utf-8"):(function(m){var p,f,_,I,C=m.length,y=new Array(2*C);for(p=f=0;p<C;)if((_=m[p++])<128)y[f++]=_;else if(4<(I=l[_]))y[f++]=65533,p+=I-1;else{for(_&=I===2?31:I===3?15:7;1<I&&p<C;)_=_<<6|63&m[p++],I--;1<I?y[f++]=65533:_<65536?y[f++]=_:(_-=65536,y[f++]=55296|_>>10&1023,y[f++]=56320|1023&_)}return y.length!==f&&(y.subarray?y=y.subarray(0,f):y.length=f),s.applyFromCharCode(y)})(d=s.transformTo(a.uint8array?"uint8array":"array",d))},s.inherits(g,A),g.prototype.processChunk=function(d){var m=s.transformTo(a.uint8array?"uint8array":"array",d.data);if(this.leftOver&&this.leftOver.length){if(a.uint8array){var p=m;(m=new Uint8Array(p.length+this.leftOver.length)).set(this.leftOver,0),m.set(p,this.leftOver.length)}else m=this.leftOver.concat(m);this.leftOver=null}var f=(function(I,C){var y;for((C=C||I.length)>I.length&&(C=I.length),y=C-1;0<=y&&(192&I[y])==128;)y--;return y<0||y===0?C:y+l[I[y]]>C?y:C})(m),_=m;f!==m.length&&(a.uint8array?(_=m.subarray(0,f),this.leftOver=m.subarray(f,m.length)):(_=m.slice(0,f),this.leftOver=m.slice(f,m.length))),this.push({data:r.utf8decode(_),meta:d.meta})},g.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:r.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},r.Utf8DecodeWorker=g,s.inherits(h,A),h.prototype.processChunk=function(d){this.push({data:r.utf8encode(d.data),meta:d.meta})},r.Utf8EncodeWorker=h},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(o,i,r){var s=o("./support"),a=o("./base64"),c=o("./nodejsUtils"),A=o("./external");function l(p){return p}function u(p,f){for(var _=0;_<p.length;++_)f[_]=255&p.charCodeAt(_);return f}o("setimmediate"),r.newBlob=function(p,f){r.checkSupport("blob");try{return new Blob([p],{type:f})}catch{try{var _=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return _.append(p),_.getBlob(f)}catch{throw new Error("Bug : can't construct the Blob.")}}};var g={stringifyByChunk:function(p,f,_){var I=[],C=0,y=p.length;if(y<=_)return String.fromCharCode.apply(null,p);for(;C<y;)f==="array"||f==="nodebuffer"?I.push(String.fromCharCode.apply(null,p.slice(C,Math.min(C+_,y)))):I.push(String.fromCharCode.apply(null,p.subarray(C,Math.min(C+_,y)))),C+=_;return I.join("")},stringifyByChar:function(p){for(var f="",_=0;_<p.length;_++)f+=String.fromCharCode(p[_]);return f},applyCanBeUsed:{uint8array:(function(){try{return s.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return s.nodebuffer&&String.fromCharCode.apply(null,c.allocBuffer(1)).length===1}catch{return!1}})()}};function h(p){var f=65536,_=r.getTypeOf(p),I=!0;if(_==="uint8array"?I=g.applyCanBeUsed.uint8array:_==="nodebuffer"&&(I=g.applyCanBeUsed.nodebuffer),I)for(;1<f;)try{return g.stringifyByChunk(p,_,f)}catch{f=Math.floor(f/2)}return g.stringifyByChar(p)}function d(p,f){for(var _=0;_<p.length;_++)f[_]=p[_];return f}r.applyFromCharCode=h;var m={};m.string={string:l,array:function(p){return u(p,new Array(p.length))},arraybuffer:function(p){return m.string.uint8array(p).buffer},uint8array:function(p){return u(p,new Uint8Array(p.length))},nodebuffer:function(p){return u(p,c.allocBuffer(p.length))}},m.array={string:h,array:l,arraybuffer:function(p){return new Uint8Array(p).buffer},uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return c.newBufferFrom(p)}},m.arraybuffer={string:function(p){return h(new Uint8Array(p))},array:function(p){return d(new Uint8Array(p),new Array(p.byteLength))},arraybuffer:l,uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return c.newBufferFrom(new Uint8Array(p))}},m.uint8array={string:h,array:function(p){return d(p,new Array(p.length))},arraybuffer:function(p){return p.buffer},uint8array:l,nodebuffer:function(p){return c.newBufferFrom(p)}},m.nodebuffer={string:h,array:function(p){return d(p,new Array(p.length))},arraybuffer:function(p){return m.nodebuffer.uint8array(p).buffer},uint8array:function(p){return d(p,new Uint8Array(p.length))},nodebuffer:l},r.transformTo=function(p,f){if(f=f||"",!p)return f;r.checkSupport(p);var _=r.getTypeOf(f);return m[_][p](f)},r.resolve=function(p){for(var f=p.split("/"),_=[],I=0;I<f.length;I++){var C=f[I];C==="."||C===""&&I!==0&&I!==f.length-1||(C===".."?_.pop():_.push(C))}return _.join("/")},r.getTypeOf=function(p){if(typeof p=="string")return"string";var f=Object.prototype.toString.call(p);return f==="[object Array]"?"array":s.nodebuffer&&c.isBuffer(p)?"nodebuffer":s.uint8array&&f==="[object Uint8Array]"?"uint8array":s.arraybuffer&&f==="[object ArrayBuffer]"?"arraybuffer":void 0},r.checkSupport=function(p){if(!s[p.toLowerCase()])throw new Error(p+" is not supported by this platform")},r.MAX_VALUE_16BITS=65535,r.MAX_VALUE_32BITS=-1,r.pretty=function(p){var f,_,I="";for(_=0;_<(p||"").length;_++)I+="\\x"+((f=p.charCodeAt(_))<16?"0":"")+f.toString(16).toUpperCase();return I},r.delay=function(p,f,_){setImmediate(function(){p.apply(_||null,f||[])})},r.inherits=function(p,f){function _(){}_.prototype=f.prototype,p.prototype=new _},r.extend=function(){var p,f,_={};for(p=0;p<arguments.length;p++)for(f in arguments[p])Object.prototype.hasOwnProperty.call(arguments[p],f)&&_[f]===void 0&&(_[f]=arguments[p][f]);return _},r.prepareContent=function(p,f,_,I,C){return A.Promise.resolve(f).then(function(y){return s.blob&&(y instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(y))!==-1)?Blob.prototype.arrayBuffer!==void 0?y.arrayBuffer():typeof FileReader<"u"?new A.Promise(function(x,E){var B=new FileReader;B.onload=function(b){x(b.target.result)},B.onerror=function(b){E(b.target.error)},B.readAsArrayBuffer(y)}):A.Promise.reject(new Error(p+" is a Blob, but we have no way of reading it.")):y}).then(function(y){var x=r.getTypeOf(y);return x?(x==="arraybuffer"?y=r.transformTo("uint8array",y):x==="string"&&(C?y=a.decode(y):_&&I!==!0&&(y=(function(E){return u(E,s.uint8array?new Uint8Array(E.length):new Array(E.length))})(y))),y):A.Promise.reject(new Error("Can't read the data of '"+p+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),c=o("./signature"),A=o("./zipEntry"),l=o("./support");function u(g){this.files=[],this.loadOptions=g}u.prototype={checkSignature:function(g){if(!this.reader.readAndCheckSignature(g)){this.reader.index-=4;var h=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+a.pretty(h)+", expected "+a.pretty(g)+")")}},isSignature:function(g,h){var d=this.reader.index;this.reader.setIndex(g);var m=this.reader.readString(4)===h;return this.reader.setIndex(d),m},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 g=this.reader.readData(this.zipCommentLength),h=l.uint8array?"uint8array":"array",d=a.transformTo(h,g);this.zipComment=this.loadOptions.decodeFileName(d)},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 g,h,d,m=this.zip64EndOfCentralSize-44;0<m;)g=this.reader.readInt(2),h=this.reader.readInt(4),d=this.reader.readData(h),this.zip64ExtensibleData[g]={id:g,length:h,value:d}},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 g,h;for(g=0;g<this.files.length;g++)h=this.files[g],this.reader.setIndex(h.localHeaderOffset),this.checkSignature(c.LOCAL_FILE_HEADER),h.readLocalPart(this.reader),h.handleUTF8(),h.processAttributes()},readCentralDir:function(){var g;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(c.CENTRAL_FILE_HEADER);)(g=new A({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(g);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 g=this.reader.lastIndexOfSignature(c.CENTRAL_DIRECTORY_END);if(g<0)throw this.isSignature(0,c.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(g);var h=g;if(this.checkSignature(c.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===a.MAX_VALUE_16BITS||this.diskWithCentralDirStart===a.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===a.MAX_VALUE_16BITS||this.centralDirRecords===a.MAX_VALUE_16BITS||this.centralDirSize===a.MAX_VALUE_32BITS||this.centralDirOffset===a.MAX_VALUE_32BITS){if(this.zip64=!0,(g=this.reader.lastIndexOfSignature(c.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(g),this.checkSignature(c.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,c.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(c.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(c.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var d=this.centralDirOffset+this.centralDirSize;this.zip64&&(d+=20,d+=12+this.zip64EndOfCentralSize);var m=h-d;if(0<m)this.isSignature(h,c.CENTRAL_FILE_HEADER)||(this.reader.zero=m);else if(m<0)throw new Error("Corrupted zip: missing "+Math.abs(m)+" bytes.")},prepareReader:function(g){this.reader=s(g)},load:function(g){this.prepareReader(g),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},i.exports=u},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),c=o("./compressedObject"),A=o("./crc32"),l=o("./utf8"),u=o("./compressions"),g=o("./support");function h(d,m){this.options=d,this.loadOptions=m}h.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(d){var m,p;if(d.skip(22),this.fileNameLength=d.readInt(2),p=d.readInt(2),this.fileName=d.readData(this.fileNameLength),d.skip(p),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((m=(function(f){for(var _ in u)if(Object.prototype.hasOwnProperty.call(u,_)&&u[_].magic===f)return u[_];return null})(this.compressionMethod))===null)throw new Error("Corrupted zip : compression "+a.pretty(this.compressionMethod)+" unknown (inner file : "+a.transformTo("string",this.fileName)+")");this.decompressed=new c(this.compressedSize,this.uncompressedSize,this.crc32,m,d.readData(this.compressedSize))},readCentralPart:function(d){this.versionMadeBy=d.readInt(2),d.skip(2),this.bitFlag=d.readInt(2),this.compressionMethod=d.readString(2),this.date=d.readDate(),this.crc32=d.readInt(4),this.compressedSize=d.readInt(4),this.uncompressedSize=d.readInt(4);var m=d.readInt(2);if(this.extraFieldsLength=d.readInt(2),this.fileCommentLength=d.readInt(2),this.diskNumberStart=d.readInt(2),this.internalFileAttributes=d.readInt(2),this.externalFileAttributes=d.readInt(4),this.localHeaderOffset=d.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");d.skip(m),this.readExtraFields(d),this.parseZIP64ExtraField(d),this.fileComment=d.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var d=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),d==0&&(this.dosPermissions=63&this.externalFileAttributes),d==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var d=s(this.extraFields[1].value);this.uncompressedSize===a.MAX_VALUE_32BITS&&(this.uncompressedSize=d.readInt(8)),this.compressedSize===a.MAX_VALUE_32BITS&&(this.compressedSize=d.readInt(8)),this.localHeaderOffset===a.MAX_VALUE_32BITS&&(this.localHeaderOffset=d.readInt(8)),this.diskNumberStart===a.MAX_VALUE_32BITS&&(this.diskNumberStart=d.readInt(4))}},readExtraFields:function(d){var m,p,f,_=d.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});d.index+4<_;)m=d.readInt(2),p=d.readInt(2),f=d.readData(p),this.extraFields[m]={id:m,length:p,value:f};d.setIndex(_)},handleUTF8:function(){var d=g.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=l.utf8decode(this.fileName),this.fileCommentStr=l.utf8decode(this.fileComment);else{var m=this.findExtraFieldUnicodePath();if(m!==null)this.fileNameStr=m;else{var p=a.transformTo(d,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(p)}var f=this.findExtraFieldUnicodeComment();if(f!==null)this.fileCommentStr=f;else{var _=a.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(_)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var m=s(d.value);return m.readInt(1)!==1||A(this.fileName)!==m.readInt(4)?null:l.utf8decode(m.readData(d.length-5))}return null},findExtraFieldUnicodeComment:function(){var d=this.extraFields[25461];if(d){var m=s(d.value);return m.readInt(1)!==1||A(this.fileComment)!==m.readInt(4)?null:l.utf8decode(m.readData(d.length-5))}return null}},i.exports=h},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(o,i,r){function s(m,p,f){this.name=m,this.dir=f.dir,this.date=f.date,this.comment=f.comment,this.unixPermissions=f.unixPermissions,this.dosPermissions=f.dosPermissions,this._data=p,this._dataBinary=f.binary,this.options={compression:f.compression,compressionOptions:f.compressionOptions}}var a=o("./stream/StreamHelper"),c=o("./stream/DataWorker"),A=o("./utf8"),l=o("./compressedObject"),u=o("./stream/GenericWorker");s.prototype={internalStream:function(m){var p=null,f="string";try{if(!m)throw new Error("No output type specified.");var _=(f=m.toLowerCase())==="string"||f==="text";f!=="binarystring"&&f!=="text"||(f="string"),p=this._decompressWorker();var I=!this._dataBinary;I&&!_&&(p=p.pipe(new A.Utf8EncodeWorker)),!I&&_&&(p=p.pipe(new A.Utf8DecodeWorker))}catch(C){(p=new u("error")).error(C)}return new a(p,f,"")},async:function(m,p){return this.internalStream(m).accumulate(p)},nodeStream:function(m,p){return this.internalStream(m||"nodebuffer").toNodejsStream(p)},_compressWorker:function(m,p){if(this._data instanceof l&&this._data.compression.magic===m.magic)return this._data.getCompressedWorker();var f=this._decompressWorker();return this._dataBinary||(f=f.pipe(new A.Utf8EncodeWorker)),l.createWorkerFrom(f,m,p)},_decompressWorker:function(){return this._data instanceof l?this._data.getContentWorker():this._data instanceof u?this._data:new c(this._data)}};for(var g=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],h=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},d=0;d<g.length;d++)s.prototype[g[d]]=h;i.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(o,i,r){(function(s){var a,c,A=s.MutationObserver||s.WebKitMutationObserver;if(A){var l=0,u=new A(m),g=s.document.createTextNode("");u.observe(g,{characterData:!0}),a=function(){g.data=l=++l%2}}else if(s.setImmediate||s.MessageChannel===void 0)a="document"in s&&"onreadystatechange"in s.document.createElement("script")?function(){var p=s.document.createElement("script");p.onreadystatechange=function(){m(),p.onreadystatechange=null,p.parentNode.removeChild(p),p=null},s.document.documentElement.appendChild(p)}:function(){setTimeout(m,0)};else{var h=new s.MessageChannel;h.port1.onmessage=m,a=function(){h.port2.postMessage(0)}}var d=[];function m(){var p,f;c=!0;for(var _=d.length;_;){for(f=d,d=[],p=-1;++p<_;)f[p]();_=d.length}c=!1}i.exports=function(p){d.push(p)!==1||c||a()}}).call(this,typeof Ry<"u"?Ry:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(o,i,r){var s=o("immediate");function a(){}var c={},A=["REJECTED"],l=["FULFILLED"],u=["PENDING"];function g(_){if(typeof _!="function")throw new TypeError("resolver must be a function");this.state=u,this.queue=[],this.outcome=void 0,_!==a&&p(this,_)}function h(_,I,C){this.promise=_,typeof I=="function"&&(this.onFulfilled=I,this.callFulfilled=this.otherCallFulfilled),typeof C=="function"&&(this.onRejected=C,this.callRejected=this.otherCallRejected)}function d(_,I,C){s(function(){var y;try{y=I(C)}catch(x){return c.reject(_,x)}y===_?c.reject(_,new TypeError("Cannot resolve promise with itself")):c.resolve(_,y)})}function m(_){var I=_&&_.then;if(_&&(typeof _=="object"||typeof _=="function")&&typeof I=="function")return function(){I.apply(_,arguments)}}function p(_,I){var C=!1;function y(B){C||(C=!0,c.reject(_,B))}function x(B){C||(C=!0,c.resolve(_,B))}var E=f(function(){I(x,y)});E.status==="error"&&y(E.value)}function f(_,I){var C={};try{C.value=_(I),C.status="success"}catch(y){C.status="error",C.value=y}return C}(i.exports=g).prototype.finally=function(_){if(typeof _!="function")return this;var I=this.constructor;return this.then(function(C){return I.resolve(_()).then(function(){return C})},function(C){return I.resolve(_()).then(function(){throw C})})},g.prototype.catch=function(_){return this.then(null,_)},g.prototype.then=function(_,I){if(typeof _!="function"&&this.state===l||typeof I!="function"&&this.state===A)return this;var C=new this.constructor(a);return this.state!==u?d(C,this.state===l?_:I,this.outcome):this.queue.push(new h(C,_,I)),C},h.prototype.callFulfilled=function(_){c.resolve(this.promise,_)},h.prototype.otherCallFulfilled=function(_){d(this.promise,this.onFulfilled,_)},h.prototype.callRejected=function(_){c.reject(this.promise,_)},h.prototype.otherCallRejected=function(_){d(this.promise,this.onRejected,_)},c.resolve=function(_,I){var C=f(m,I);if(C.status==="error")return c.reject(_,C.value);var y=C.value;if(y)p(_,y);else{_.state=l,_.outcome=I;for(var x=-1,E=_.queue.length;++x<E;)_.queue[x].callFulfilled(I)}return _},c.reject=function(_,I){_.state=A,_.outcome=I;for(var C=-1,y=_.queue.length;++C<y;)_.queue[C].callRejected(I);return _},g.resolve=function(_){return _ instanceof this?_:c.resolve(new this(a),_)},g.reject=function(_){var I=new this(a);return c.reject(I,_)},g.all=function(_){var I=this;if(Object.prototype.toString.call(_)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=_.length,y=!1;if(!C)return this.resolve([]);for(var x=new Array(C),E=0,B=-1,b=new this(a);++B<C;)Q(_[B],B);return b;function Q(w,M){I.resolve(w).then(function(T){x[M]=T,++E!==C||y||(y=!0,c.resolve(b,x))},function(T){y||(y=!0,c.reject(b,T))})}},g.race=function(_){var I=this;if(Object.prototype.toString.call(_)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=_.length,y=!1;if(!C)return this.resolve([]);for(var x=-1,E=new this(a);++x<C;)B=_[x],I.resolve(B).then(function(b){y||(y=!0,c.resolve(E,b))},function(b){y||(y=!0,c.reject(E,b))});var B;return E}},{immediate:36}],38:[function(o,i,r){var s={};(0,o("./lib/utils/common").assign)(s,o("./lib/deflate"),o("./lib/inflate"),o("./lib/zlib/constants")),i.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(o,i,r){var s=o("./zlib/deflate"),a=o("./utils/common"),c=o("./utils/strings"),A=o("./zlib/messages"),l=o("./zlib/zstream"),u=Object.prototype.toString,g=0,h=-1,d=0,m=8;function p(_){if(!(this instanceof p))return new p(_);this.options=a.assign({level:h,method:m,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},_||{});var I=this.options;I.raw&&0<I.windowBits?I.windowBits=-I.windowBits:I.gzip&&0<I.windowBits&&I.windowBits<16&&(I.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new l,this.strm.avail_out=0;var C=s.deflateInit2(this.strm,I.level,I.method,I.windowBits,I.memLevel,I.strategy);if(C!==g)throw new Error(A[C]);if(I.header&&s.deflateSetHeader(this.strm,I.header),I.dictionary){var y;if(y=typeof I.dictionary=="string"?c.string2buf(I.dictionary):u.call(I.dictionary)==="[object ArrayBuffer]"?new Uint8Array(I.dictionary):I.dictionary,(C=s.deflateSetDictionary(this.strm,y))!==g)throw new Error(A[C]);this._dict_set=!0}}function f(_,I){var C=new p(I);if(C.push(_,!0),C.err)throw C.msg||A[C.err];return C.result}p.prototype.push=function(_,I){var C,y,x=this.strm,E=this.options.chunkSize;if(this.ended)return!1;y=I===~~I?I:I===!0?4:0,typeof _=="string"?x.input=c.string2buf(_):u.call(_)==="[object ArrayBuffer]"?x.input=new Uint8Array(_):x.input=_,x.next_in=0,x.avail_in=x.input.length;do{if(x.avail_out===0&&(x.output=new a.Buf8(E),x.next_out=0,x.avail_out=E),(C=s.deflate(x,y))!==1&&C!==g)return this.onEnd(C),!(this.ended=!0);x.avail_out!==0&&(x.avail_in!==0||y!==4&&y!==2)||(this.options.to==="string"?this.onData(c.buf2binstring(a.shrinkBuf(x.output,x.next_out))):this.onData(a.shrinkBuf(x.output,x.next_out)))}while((0<x.avail_in||x.avail_out===0)&&C!==1);return y===4?(C=s.deflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===g):y!==2||(this.onEnd(g),!(x.avail_out=0))},p.prototype.onData=function(_){this.chunks.push(_)},p.prototype.onEnd=function(_){_===g&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=_,this.msg=this.strm.msg},r.Deflate=p,r.deflate=f,r.deflateRaw=function(_,I){return(I=I||{}).raw=!0,f(_,I)},r.gzip=function(_,I){return(I=I||{}).gzip=!0,f(_,I)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(o,i,r){var s=o("./zlib/inflate"),a=o("./utils/common"),c=o("./utils/strings"),A=o("./zlib/constants"),l=o("./zlib/messages"),u=o("./zlib/zstream"),g=o("./zlib/gzheader"),h=Object.prototype.toString;function d(p){if(!(this instanceof d))return new d(p);this.options=a.assign({chunkSize:16384,windowBits:0,to:""},p||{});var f=this.options;f.raw&&0<=f.windowBits&&f.windowBits<16&&(f.windowBits=-f.windowBits,f.windowBits===0&&(f.windowBits=-15)),!(0<=f.windowBits&&f.windowBits<16)||p&&p.windowBits||(f.windowBits+=32),15<f.windowBits&&f.windowBits<48&&(15&f.windowBits)==0&&(f.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new u,this.strm.avail_out=0;var _=s.inflateInit2(this.strm,f.windowBits);if(_!==A.Z_OK)throw new Error(l[_]);this.header=new g,s.inflateGetHeader(this.strm,this.header)}function m(p,f){var _=new d(f);if(_.push(p,!0),_.err)throw _.msg||l[_.err];return _.result}d.prototype.push=function(p,f){var _,I,C,y,x,E,B=this.strm,b=this.options.chunkSize,Q=this.options.dictionary,w=!1;if(this.ended)return!1;I=f===~~f?f:f===!0?A.Z_FINISH:A.Z_NO_FLUSH,typeof p=="string"?B.input=c.binstring2buf(p):h.call(p)==="[object ArrayBuffer]"?B.input=new Uint8Array(p):B.input=p,B.next_in=0,B.avail_in=B.input.length;do{if(B.avail_out===0&&(B.output=new a.Buf8(b),B.next_out=0,B.avail_out=b),(_=s.inflate(B,A.Z_NO_FLUSH))===A.Z_NEED_DICT&&Q&&(E=typeof Q=="string"?c.string2buf(Q):h.call(Q)==="[object ArrayBuffer]"?new Uint8Array(Q):Q,_=s.inflateSetDictionary(this.strm,E)),_===A.Z_BUF_ERROR&&w===!0&&(_=A.Z_OK,w=!1),_!==A.Z_STREAM_END&&_!==A.Z_OK)return this.onEnd(_),!(this.ended=!0);B.next_out&&(B.avail_out!==0&&_!==A.Z_STREAM_END&&(B.avail_in!==0||I!==A.Z_FINISH&&I!==A.Z_SYNC_FLUSH)||(this.options.to==="string"?(C=c.utf8border(B.output,B.next_out),y=B.next_out-C,x=c.buf2string(B.output,C),B.next_out=y,B.avail_out=b-y,y&&a.arraySet(B.output,B.output,C,y,0),this.onData(x)):this.onData(a.shrinkBuf(B.output,B.next_out)))),B.avail_in===0&&B.avail_out===0&&(w=!0)}while((0<B.avail_in||B.avail_out===0)&&_!==A.Z_STREAM_END);return _===A.Z_STREAM_END&&(I=A.Z_FINISH),I===A.Z_FINISH?(_=s.inflateEnd(this.strm),this.onEnd(_),this.ended=!0,_===A.Z_OK):I!==A.Z_SYNC_FLUSH||(this.onEnd(A.Z_OK),!(B.avail_out=0))},d.prototype.onData=function(p){this.chunks.push(p)},d.prototype.onEnd=function(p){p===A.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=p,this.msg=this.strm.msg},r.Inflate=d,r.inflate=m,r.inflateRaw=function(p,f){return(f=f||{}).raw=!0,m(p,f)},r.ungzip=m},{"./utils/common":41,"./utils/strings":42,"./zlib/constants":44,"./zlib/gzheader":47,"./zlib/inflate":49,"./zlib/messages":51,"./zlib/zstream":53}],41:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";r.assign=function(A){for(var l=Array.prototype.slice.call(arguments,1);l.length;){var u=l.shift();if(u){if(typeof u!="object")throw new TypeError(u+"must be non-object");for(var g in u)u.hasOwnProperty(g)&&(A[g]=u[g])}}return A},r.shrinkBuf=function(A,l){return A.length===l?A:A.subarray?A.subarray(0,l):(A.length=l,A)};var a={arraySet:function(A,l,u,g,h){if(l.subarray&&A.subarray)A.set(l.subarray(u,u+g),h);else for(var d=0;d<g;d++)A[h+d]=l[u+d]},flattenChunks:function(A){var l,u,g,h,d,m;for(l=g=0,u=A.length;l<u;l++)g+=A[l].length;for(m=new Uint8Array(g),l=h=0,u=A.length;l<u;l++)d=A[l],m.set(d,h),h+=d.length;return m}},c={arraySet:function(A,l,u,g,h){for(var d=0;d<g;d++)A[h+d]=l[u+d]},flattenChunks:function(A){return[].concat.apply([],A)}};r.setTyped=function(A){A?(r.Buf8=Uint8Array,r.Buf16=Uint16Array,r.Buf32=Int32Array,r.assign(r,a)):(r.Buf8=Array,r.Buf16=Array,r.Buf32=Array,r.assign(r,c))},r.setTyped(s)},{}],42:[function(o,i,r){var s=o("./common"),a=!0,c=!0;try{String.fromCharCode.apply(null,[0])}catch{a=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{c=!1}for(var A=new s.Buf8(256),l=0;l<256;l++)A[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function u(g,h){if(h<65537&&(g.subarray&&c||!g.subarray&&a))return String.fromCharCode.apply(null,s.shrinkBuf(g,h));for(var d="",m=0;m<h;m++)d+=String.fromCharCode(g[m]);return d}A[254]=A[254]=1,r.string2buf=function(g){var h,d,m,p,f,_=g.length,I=0;for(p=0;p<_;p++)(64512&(d=g.charCodeAt(p)))==55296&&p+1<_&&(64512&(m=g.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(m-56320),p++),I+=d<128?1:d<2048?2:d<65536?3:4;for(h=new s.Buf8(I),p=f=0;f<I;p++)(64512&(d=g.charCodeAt(p)))==55296&&p+1<_&&(64512&(m=g.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(m-56320),p++),d<128?h[f++]=d:(d<2048?h[f++]=192|d>>>6:(d<65536?h[f++]=224|d>>>12:(h[f++]=240|d>>>18,h[f++]=128|d>>>12&63),h[f++]=128|d>>>6&63),h[f++]=128|63&d);return h},r.buf2binstring=function(g){return u(g,g.length)},r.binstring2buf=function(g){for(var h=new s.Buf8(g.length),d=0,m=h.length;d<m;d++)h[d]=g.charCodeAt(d);return h},r.buf2string=function(g,h){var d,m,p,f,_=h||g.length,I=new Array(2*_);for(d=m=0;d<_;)if((p=g[d++])<128)I[m++]=p;else if(4<(f=A[p]))I[m++]=65533,d+=f-1;else{for(p&=f===2?31:f===3?15:7;1<f&&d<_;)p=p<<6|63&g[d++],f--;1<f?I[m++]=65533:p<65536?I[m++]=p:(p-=65536,I[m++]=55296|p>>10&1023,I[m++]=56320|1023&p)}return u(I,m)},r.utf8border=function(g,h){var d;for((h=h||g.length)>g.length&&(h=g.length),d=h-1;0<=d&&(192&g[d])==128;)d--;return d<0||d===0?h:d+A[g[d]]>h?d:h}},{"./common":41}],43:[function(o,i,r){i.exports=function(s,a,c,A){for(var l=65535&s|0,u=s>>>16&65535|0,g=0;c!==0;){for(c-=g=2e3<c?2e3:c;u=u+(l=l+a[A++]|0)|0,--g;);l%=65521,u%=65521}return l|u<<16|0}},{}],44:[function(o,i,r){i.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(o,i,r){var s=(function(){for(var a,c=[],A=0;A<256;A++){a=A;for(var l=0;l<8;l++)a=1&a?3988292384^a>>>1:a>>>1;c[A]=a}return c})();i.exports=function(a,c,A,l){var u=s,g=l+A;a^=-1;for(var h=l;h<g;h++)a=a>>>8^u[255&(a^c[h])];return-1^a}},{}],46:[function(o,i,r){var s,a=o("../utils/common"),c=o("./trees"),A=o("./adler32"),l=o("./crc32"),u=o("./messages"),g=0,h=4,d=0,m=-2,p=-1,f=4,_=2,I=8,C=9,y=286,x=30,E=19,B=2*y+1,b=15,Q=3,w=258,M=w+Q+1,T=42,N=113,F=1,O=2,U=3,Y=4;function j(he,Pe){return he.msg=u[Pe],Pe}function ee(he){return(he<<1)-(4<he?9:0)}function J(he){for(var Pe=he.length;0<=--Pe;)he[Pe]=0}function W(he){var Pe=he.state,Qe=Pe.pending;Qe>he.avail_out&&(Qe=he.avail_out),Qe!==0&&(a.arraySet(he.output,Pe.pending_buf,Pe.pending_out,Qe,he.next_out),he.next_out+=Qe,Pe.pending_out+=Qe,he.total_out+=Qe,he.avail_out-=Qe,Pe.pending-=Qe,Pe.pending===0&&(Pe.pending_out=0))}function te(he,Pe){c._tr_flush_block(he,0<=he.block_start?he.block_start:-1,he.strstart-he.block_start,Pe),he.block_start=he.strstart,W(he.strm)}function re(he,Pe){he.pending_buf[he.pending++]=Pe}function ne(he,Pe){he.pending_buf[he.pending++]=Pe>>>8&255,he.pending_buf[he.pending++]=255&Pe}function le(he,Pe){var Qe,Se,De=he.max_chain_length,Ne=he.strstart,Ee=he.prev_length,Te=he.nice_match,Ie=he.strstart>he.w_size-M?he.strstart-(he.w_size-M):0,ke=he.window,Ge=he.w_mask,qe=he.prev,rt=he.strstart+w,ct=ke[Ne+Ee-1],gt=ke[Ne+Ee];he.prev_length>=he.good_match&&(De>>=2),Te>he.lookahead&&(Te=he.lookahead);do if(ke[(Qe=Pe)+Ee]===gt&&ke[Qe+Ee-1]===ct&&ke[Qe]===ke[Ne]&&ke[++Qe]===ke[Ne+1]){Ne+=2,Qe++;do;while(ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&ke[++Ne]===ke[++Qe]&&Ne<rt);if(Se=w-(rt-Ne),Ne=rt-w,Ee<Se){if(he.match_start=Pe,Te<=(Ee=Se))break;ct=ke[Ne+Ee-1],gt=ke[Ne+Ee]}}while((Pe=qe[Pe&Ge])>Ie&&--De!=0);return Ee<=he.lookahead?Ee:he.lookahead}function ge(he){var Pe,Qe,Se,De,Ne,Ee,Te,Ie,ke,Ge,qe=he.w_size;do{if(De=he.window_size-he.lookahead-he.strstart,he.strstart>=qe+(qe-M)){for(a.arraySet(he.window,he.window,qe,qe,0),he.match_start-=qe,he.strstart-=qe,he.block_start-=qe,Pe=Qe=he.hash_size;Se=he.head[--Pe],he.head[Pe]=qe<=Se?Se-qe:0,--Qe;);for(Pe=Qe=qe;Se=he.prev[--Pe],he.prev[Pe]=qe<=Se?Se-qe:0,--Qe;);De+=qe}if(he.strm.avail_in===0)break;if(Ee=he.strm,Te=he.window,Ie=he.strstart+he.lookahead,ke=De,Ge=void 0,Ge=Ee.avail_in,ke<Ge&&(Ge=ke),Qe=Ge===0?0:(Ee.avail_in-=Ge,a.arraySet(Te,Ee.input,Ee.next_in,Ge,Ie),Ee.state.wrap===1?Ee.adler=A(Ee.adler,Te,Ge,Ie):Ee.state.wrap===2&&(Ee.adler=l(Ee.adler,Te,Ge,Ie)),Ee.next_in+=Ge,Ee.total_in+=Ge,Ge),he.lookahead+=Qe,he.lookahead+he.insert>=Q)for(Ne=he.strstart-he.insert,he.ins_h=he.window[Ne],he.ins_h=(he.ins_h<<he.hash_shift^he.window[Ne+1])&he.hash_mask;he.insert&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[Ne+Q-1])&he.hash_mask,he.prev[Ne&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=Ne,Ne++,he.insert--,!(he.lookahead+he.insert<Q)););}while(he.lookahead<M&&he.strm.avail_in!==0)}function fe(he,Pe){for(var Qe,Se;;){if(he.lookahead<M){if(ge(he),he.lookahead<M&&Pe===g)return F;if(he.lookahead===0)break}if(Qe=0,he.lookahead>=Q&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+Q-1])&he.hash_mask,Qe=he.prev[he.strstart&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=he.strstart),Qe!==0&&he.strstart-Qe<=he.w_size-M&&(he.match_length=le(he,Qe)),he.match_length>=Q)if(Se=c._tr_tally(he,he.strstart-he.match_start,he.match_length-Q),he.lookahead-=he.match_length,he.match_length<=he.max_lazy_match&&he.lookahead>=Q){for(he.match_length--;he.strstart++,he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+Q-1])&he.hash_mask,Qe=he.prev[he.strstart&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=he.strstart,--he.match_length!=0;);he.strstart++}else he.strstart+=he.match_length,he.match_length=0,he.ins_h=he.window[he.strstart],he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+1])&he.hash_mask;else Se=c._tr_tally(he,0,he.window[he.strstart]),he.lookahead--,he.strstart++;if(Se&&(te(he,!1),he.strm.avail_out===0))return F}return he.insert=he.strstart<Q-1?he.strstart:Q-1,Pe===h?(te(he,!0),he.strm.avail_out===0?U:Y):he.last_lit&&(te(he,!1),he.strm.avail_out===0)?F:O}function Ae(he,Pe){for(var Qe,Se,De;;){if(he.lookahead<M){if(ge(he),he.lookahead<M&&Pe===g)return F;if(he.lookahead===0)break}if(Qe=0,he.lookahead>=Q&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+Q-1])&he.hash_mask,Qe=he.prev[he.strstart&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=he.strstart),he.prev_length=he.match_length,he.prev_match=he.match_start,he.match_length=Q-1,Qe!==0&&he.prev_length<he.max_lazy_match&&he.strstart-Qe<=he.w_size-M&&(he.match_length=le(he,Qe),he.match_length<=5&&(he.strategy===1||he.match_length===Q&&4096<he.strstart-he.match_start)&&(he.match_length=Q-1)),he.prev_length>=Q&&he.match_length<=he.prev_length){for(De=he.strstart+he.lookahead-Q,Se=c._tr_tally(he,he.strstart-1-he.prev_match,he.prev_length-Q),he.lookahead-=he.prev_length-1,he.prev_length-=2;++he.strstart<=De&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+Q-1])&he.hash_mask,Qe=he.prev[he.strstart&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=he.strstart),--he.prev_length!=0;);if(he.match_available=0,he.match_length=Q-1,he.strstart++,Se&&(te(he,!1),he.strm.avail_out===0))return F}else if(he.match_available){if((Se=c._tr_tally(he,0,he.window[he.strstart-1]))&&te(he,!1),he.strstart++,he.lookahead--,he.strm.avail_out===0)return F}else he.match_available=1,he.strstart++,he.lookahead--}return he.match_available&&(Se=c._tr_tally(he,0,he.window[he.strstart-1]),he.match_available=0),he.insert=he.strstart<Q-1?he.strstart:Q-1,Pe===h?(te(he,!0),he.strm.avail_out===0?U:Y):he.last_lit&&(te(he,!1),he.strm.avail_out===0)?F:O}function _e(he,Pe,Qe,Se,De){this.good_length=he,this.max_lazy=Pe,this.nice_length=Qe,this.max_chain=Se,this.func=De}function ue(){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=I,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 a.Buf16(2*B),this.dyn_dtree=new a.Buf16(2*(2*x+1)),this.bl_tree=new a.Buf16(2*(2*E+1)),J(this.dyn_ltree),J(this.dyn_dtree),J(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new a.Buf16(b+1),this.heap=new a.Buf16(2*y+1),J(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*y+1),J(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 me(he){var Pe;return he&&he.state?(he.total_in=he.total_out=0,he.data_type=_,(Pe=he.state).pending=0,Pe.pending_out=0,Pe.wrap<0&&(Pe.wrap=-Pe.wrap),Pe.status=Pe.wrap?T:N,he.adler=Pe.wrap===2?0:1,Pe.last_flush=g,c._tr_init(Pe),d):j(he,m)}function we(he){var Pe=me(he);return Pe===d&&(function(Qe){Qe.window_size=2*Qe.w_size,J(Qe.head),Qe.max_lazy_match=s[Qe.level].max_lazy,Qe.good_match=s[Qe.level].good_length,Qe.nice_match=s[Qe.level].nice_length,Qe.max_chain_length=s[Qe.level].max_chain,Qe.strstart=0,Qe.block_start=0,Qe.lookahead=0,Qe.insert=0,Qe.match_length=Qe.prev_length=Q-1,Qe.match_available=0,Qe.ins_h=0})(he.state),Pe}function Me(he,Pe,Qe,Se,De,Ne){if(!he)return m;var Ee=1;if(Pe===p&&(Pe=6),Se<0?(Ee=0,Se=-Se):15<Se&&(Ee=2,Se-=16),De<1||C<De||Qe!==I||Se<8||15<Se||Pe<0||9<Pe||Ne<0||f<Ne)return j(he,m);Se===8&&(Se=9);var Te=new ue;return(he.state=Te).strm=he,Te.wrap=Ee,Te.gzhead=null,Te.w_bits=Se,Te.w_size=1<<Te.w_bits,Te.w_mask=Te.w_size-1,Te.hash_bits=De+7,Te.hash_size=1<<Te.hash_bits,Te.hash_mask=Te.hash_size-1,Te.hash_shift=~~((Te.hash_bits+Q-1)/Q),Te.window=new a.Buf8(2*Te.w_size),Te.head=new a.Buf16(Te.hash_size),Te.prev=new a.Buf16(Te.w_size),Te.lit_bufsize=1<<De+6,Te.pending_buf_size=4*Te.lit_bufsize,Te.pending_buf=new a.Buf8(Te.pending_buf_size),Te.d_buf=1*Te.lit_bufsize,Te.l_buf=3*Te.lit_bufsize,Te.level=Pe,Te.strategy=Ne,Te.method=Qe,we(he)}s=[new _e(0,0,0,0,function(he,Pe){var Qe=65535;for(Qe>he.pending_buf_size-5&&(Qe=he.pending_buf_size-5);;){if(he.lookahead<=1){if(ge(he),he.lookahead===0&&Pe===g)return F;if(he.lookahead===0)break}he.strstart+=he.lookahead,he.lookahead=0;var Se=he.block_start+Qe;if((he.strstart===0||he.strstart>=Se)&&(he.lookahead=he.strstart-Se,he.strstart=Se,te(he,!1),he.strm.avail_out===0)||he.strstart-he.block_start>=he.w_size-M&&(te(he,!1),he.strm.avail_out===0))return F}return he.insert=0,Pe===h?(te(he,!0),he.strm.avail_out===0?U:Y):(he.strstart>he.block_start&&(te(he,!1),he.strm.avail_out),F)}),new _e(4,4,8,4,fe),new _e(4,5,16,8,fe),new _e(4,6,32,32,fe),new _e(4,4,16,16,Ae),new _e(8,16,32,32,Ae),new _e(8,16,128,128,Ae),new _e(8,32,128,256,Ae),new _e(32,128,258,1024,Ae),new _e(32,258,258,4096,Ae)],r.deflateInit=function(he,Pe){return Me(he,Pe,I,15,8,0)},r.deflateInit2=Me,r.deflateReset=we,r.deflateResetKeep=me,r.deflateSetHeader=function(he,Pe){return he&&he.state?he.state.wrap!==2?m:(he.state.gzhead=Pe,d):m},r.deflate=function(he,Pe){var Qe,Se,De,Ne;if(!he||!he.state||5<Pe||Pe<0)return he?j(he,m):m;if(Se=he.state,!he.output||!he.input&&he.avail_in!==0||Se.status===666&&Pe!==h)return j(he,he.avail_out===0?-5:m);if(Se.strm=he,Qe=Se.last_flush,Se.last_flush=Pe,Se.status===T)if(Se.wrap===2)he.adler=0,re(Se,31),re(Se,139),re(Se,8),Se.gzhead?(re(Se,(Se.gzhead.text?1:0)+(Se.gzhead.hcrc?2:0)+(Se.gzhead.extra?4:0)+(Se.gzhead.name?8:0)+(Se.gzhead.comment?16:0)),re(Se,255&Se.gzhead.time),re(Se,Se.gzhead.time>>8&255),re(Se,Se.gzhead.time>>16&255),re(Se,Se.gzhead.time>>24&255),re(Se,Se.level===9?2:2<=Se.strategy||Se.level<2?4:0),re(Se,255&Se.gzhead.os),Se.gzhead.extra&&Se.gzhead.extra.length&&(re(Se,255&Se.gzhead.extra.length),re(Se,Se.gzhead.extra.length>>8&255)),Se.gzhead.hcrc&&(he.adler=l(he.adler,Se.pending_buf,Se.pending,0)),Se.gzindex=0,Se.status=69):(re(Se,0),re(Se,0),re(Se,0),re(Se,0),re(Se,0),re(Se,Se.level===9?2:2<=Se.strategy||Se.level<2?4:0),re(Se,3),Se.status=N);else{var Ee=I+(Se.w_bits-8<<4)<<8;Ee|=(2<=Se.strategy||Se.level<2?0:Se.level<6?1:Se.level===6?2:3)<<6,Se.strstart!==0&&(Ee|=32),Ee+=31-Ee%31,Se.status=N,ne(Se,Ee),Se.strstart!==0&&(ne(Se,he.adler>>>16),ne(Se,65535&he.adler)),he.adler=1}if(Se.status===69)if(Se.gzhead.extra){for(De=Se.pending;Se.gzindex<(65535&Se.gzhead.extra.length)&&(Se.pending!==Se.pending_buf_size||(Se.gzhead.hcrc&&Se.pending>De&&(he.adler=l(he.adler,Se.pending_buf,Se.pending-De,De)),W(he),De=Se.pending,Se.pending!==Se.pending_buf_size));)re(Se,255&Se.gzhead.extra[Se.gzindex]),Se.gzindex++;Se.gzhead.hcrc&&Se.pending>De&&(he.adler=l(he.adler,Se.pending_buf,Se.pending-De,De)),Se.gzindex===Se.gzhead.extra.length&&(Se.gzindex=0,Se.status=73)}else Se.status=73;if(Se.status===73)if(Se.gzhead.name){De=Se.pending;do{if(Se.pending===Se.pending_buf_size&&(Se.gzhead.hcrc&&Se.pending>De&&(he.adler=l(he.adler,Se.pending_buf,Se.pending-De,De)),W(he),De=Se.pending,Se.pending===Se.pending_buf_size)){Ne=1;break}Ne=Se.gzindex<Se.gzhead.name.length?255&Se.gzhead.name.charCodeAt(Se.gzindex++):0,re(Se,Ne)}while(Ne!==0);Se.gzhead.hcrc&&Se.pending>De&&(he.adler=l(he.adler,Se.pending_buf,Se.pending-De,De)),Ne===0&&(Se.gzindex=0,Se.status=91)}else Se.status=91;if(Se.status===91)if(Se.gzhead.comment){De=Se.pending;do{if(Se.pending===Se.pending_buf_size&&(Se.gzhead.hcrc&&Se.pending>De&&(he.adler=l(he.adler,Se.pending_buf,Se.pending-De,De)),W(he),De=Se.pending,Se.pending===Se.pending_buf_size)){Ne=1;break}Ne=Se.gzindex<Se.gzhead.comment.length?255&Se.gzhead.comment.charCodeAt(Se.gzindex++):0,re(Se,Ne)}while(Ne!==0);Se.gzhead.hcrc&&Se.pending>De&&(he.adler=l(he.adler,Se.pending_buf,Se.pending-De,De)),Ne===0&&(Se.status=103)}else Se.status=103;if(Se.status===103&&(Se.gzhead.hcrc?(Se.pending+2>Se.pending_buf_size&&W(he),Se.pending+2<=Se.pending_buf_size&&(re(Se,255&he.adler),re(Se,he.adler>>8&255),he.adler=0,Se.status=N)):Se.status=N),Se.pending!==0){if(W(he),he.avail_out===0)return Se.last_flush=-1,d}else if(he.avail_in===0&&ee(Pe)<=ee(Qe)&&Pe!==h)return j(he,-5);if(Se.status===666&&he.avail_in!==0)return j(he,-5);if(he.avail_in!==0||Se.lookahead!==0||Pe!==g&&Se.status!==666){var Te=Se.strategy===2?(function(Ie,ke){for(var Ge;;){if(Ie.lookahead===0&&(ge(Ie),Ie.lookahead===0)){if(ke===g)return F;break}if(Ie.match_length=0,Ge=c._tr_tally(Ie,0,Ie.window[Ie.strstart]),Ie.lookahead--,Ie.strstart++,Ge&&(te(Ie,!1),Ie.strm.avail_out===0))return F}return Ie.insert=0,ke===h?(te(Ie,!0),Ie.strm.avail_out===0?U:Y):Ie.last_lit&&(te(Ie,!1),Ie.strm.avail_out===0)?F:O})(Se,Pe):Se.strategy===3?(function(Ie,ke){for(var Ge,qe,rt,ct,gt=Ie.window;;){if(Ie.lookahead<=w){if(ge(Ie),Ie.lookahead<=w&&ke===g)return F;if(Ie.lookahead===0)break}if(Ie.match_length=0,Ie.lookahead>=Q&&0<Ie.strstart&&(qe=gt[rt=Ie.strstart-1])===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]){ct=Ie.strstart+w;do;while(qe===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]&&qe===gt[++rt]&&rt<ct);Ie.match_length=w-(ct-rt),Ie.match_length>Ie.lookahead&&(Ie.match_length=Ie.lookahead)}if(Ie.match_length>=Q?(Ge=c._tr_tally(Ie,1,Ie.match_length-Q),Ie.lookahead-=Ie.match_length,Ie.strstart+=Ie.match_length,Ie.match_length=0):(Ge=c._tr_tally(Ie,0,Ie.window[Ie.strstart]),Ie.lookahead--,Ie.strstart++),Ge&&(te(Ie,!1),Ie.strm.avail_out===0))return F}return Ie.insert=0,ke===h?(te(Ie,!0),Ie.strm.avail_out===0?U:Y):Ie.last_lit&&(te(Ie,!1),Ie.strm.avail_out===0)?F:O})(Se,Pe):s[Se.level].func(Se,Pe);if(Te!==U&&Te!==Y||(Se.status=666),Te===F||Te===U)return he.avail_out===0&&(Se.last_flush=-1),d;if(Te===O&&(Pe===1?c._tr_align(Se):Pe!==5&&(c._tr_stored_block(Se,0,0,!1),Pe===3&&(J(Se.head),Se.lookahead===0&&(Se.strstart=0,Se.block_start=0,Se.insert=0))),W(he),he.avail_out===0))return Se.last_flush=-1,d}return Pe!==h?d:Se.wrap<=0?1:(Se.wrap===2?(re(Se,255&he.adler),re(Se,he.adler>>8&255),re(Se,he.adler>>16&255),re(Se,he.adler>>24&255),re(Se,255&he.total_in),re(Se,he.total_in>>8&255),re(Se,he.total_in>>16&255),re(Se,he.total_in>>24&255)):(ne(Se,he.adler>>>16),ne(Se,65535&he.adler)),W(he),0<Se.wrap&&(Se.wrap=-Se.wrap),Se.pending!==0?d:1)},r.deflateEnd=function(he){var Pe;return he&&he.state?(Pe=he.state.status)!==T&&Pe!==69&&Pe!==73&&Pe!==91&&Pe!==103&&Pe!==N&&Pe!==666?j(he,m):(he.state=null,Pe===N?j(he,-3):d):m},r.deflateSetDictionary=function(he,Pe){var Qe,Se,De,Ne,Ee,Te,Ie,ke,Ge=Pe.length;if(!he||!he.state||(Ne=(Qe=he.state).wrap)===2||Ne===1&&Qe.status!==T||Qe.lookahead)return m;for(Ne===1&&(he.adler=A(he.adler,Pe,Ge,0)),Qe.wrap=0,Ge>=Qe.w_size&&(Ne===0&&(J(Qe.head),Qe.strstart=0,Qe.block_start=0,Qe.insert=0),ke=new a.Buf8(Qe.w_size),a.arraySet(ke,Pe,Ge-Qe.w_size,Qe.w_size,0),Pe=ke,Ge=Qe.w_size),Ee=he.avail_in,Te=he.next_in,Ie=he.input,he.avail_in=Ge,he.next_in=0,he.input=Pe,ge(Qe);Qe.lookahead>=Q;){for(Se=Qe.strstart,De=Qe.lookahead-(Q-1);Qe.ins_h=(Qe.ins_h<<Qe.hash_shift^Qe.window[Se+Q-1])&Qe.hash_mask,Qe.prev[Se&Qe.w_mask]=Qe.head[Qe.ins_h],Qe.head[Qe.ins_h]=Se,Se++,--De;);Qe.strstart=Se,Qe.lookahead=Q-1,ge(Qe)}return Qe.strstart+=Qe.lookahead,Qe.block_start=Qe.strstart,Qe.insert=Qe.lookahead,Qe.lookahead=0,Qe.match_length=Qe.prev_length=Q-1,Qe.match_available=0,he.next_in=Te,he.input=Ie,he.avail_in=Ee,Qe.wrap=Ne,d},r.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(o,i,r){i.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(o,i,r){i.exports=function(s,a){var c,A,l,u,g,h,d,m,p,f,_,I,C,y,x,E,B,b,Q,w,M,T,N,F,O;c=s.state,A=s.next_in,F=s.input,l=A+(s.avail_in-5),u=s.next_out,O=s.output,g=u-(a-s.avail_out),h=u+(s.avail_out-257),d=c.dmax,m=c.wsize,p=c.whave,f=c.wnext,_=c.window,I=c.hold,C=c.bits,y=c.lencode,x=c.distcode,E=(1<<c.lenbits)-1,B=(1<<c.distbits)-1;e:do{C<15&&(I+=F[A++]<<C,C+=8,I+=F[A++]<<C,C+=8),b=y[I&E];t:for(;;){if(I>>>=Q=b>>>24,C-=Q,(Q=b>>>16&255)===0)O[u++]=65535&b;else{if(!(16&Q)){if((64&Q)==0){b=y[(65535&b)+(I&(1<<Q)-1)];continue t}if(32&Q){c.mode=12;break e}s.msg="invalid literal/length code",c.mode=30;break e}w=65535&b,(Q&=15)&&(C<Q&&(I+=F[A++]<<C,C+=8),w+=I&(1<<Q)-1,I>>>=Q,C-=Q),C<15&&(I+=F[A++]<<C,C+=8,I+=F[A++]<<C,C+=8),b=x[I&B];n:for(;;){if(I>>>=Q=b>>>24,C-=Q,!(16&(Q=b>>>16&255))){if((64&Q)==0){b=x[(65535&b)+(I&(1<<Q)-1)];continue n}s.msg="invalid distance code",c.mode=30;break e}if(M=65535&b,C<(Q&=15)&&(I+=F[A++]<<C,(C+=8)<Q&&(I+=F[A++]<<C,C+=8)),d<(M+=I&(1<<Q)-1)){s.msg="invalid distance too far back",c.mode=30;break e}if(I>>>=Q,C-=Q,(Q=u-g)<M){if(p<(Q=M-Q)&&c.sane){s.msg="invalid distance too far back",c.mode=30;break e}if(N=_,(T=0)===f){if(T+=m-Q,Q<w){for(w-=Q;O[u++]=_[T++],--Q;);T=u-M,N=O}}else if(f<Q){if(T+=m+f-Q,(Q-=f)<w){for(w-=Q;O[u++]=_[T++],--Q;);if(T=0,f<w){for(w-=Q=f;O[u++]=_[T++],--Q;);T=u-M,N=O}}}else if(T+=f-Q,Q<w){for(w-=Q;O[u++]=_[T++],--Q;);T=u-M,N=O}for(;2<w;)O[u++]=N[T++],O[u++]=N[T++],O[u++]=N[T++],w-=3;w&&(O[u++]=N[T++],1<w&&(O[u++]=N[T++]))}else{for(T=u-M;O[u++]=O[T++],O[u++]=O[T++],O[u++]=O[T++],2<(w-=3););w&&(O[u++]=O[T++],1<w&&(O[u++]=O[T++]))}break}}break}}while(A<l&&u<h);A-=w=C>>3,I&=(1<<(C-=w<<3))-1,s.next_in=A,s.next_out=u,s.avail_in=A<l?l-A+5:5-(A-l),s.avail_out=u<h?h-u+257:257-(u-h),c.hold=I,c.bits=C}},{}],49:[function(o,i,r){var s=o("../utils/common"),a=o("./adler32"),c=o("./crc32"),A=o("./inffast"),l=o("./inftrees"),u=1,g=2,h=0,d=-2,m=1,p=852,f=592;function _(T){return(T>>>24&255)+(T>>>8&65280)+((65280&T)<<8)+((255&T)<<24)}function I(){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 s.Buf16(320),this.work=new s.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function C(T){var N;return T&&T.state?(N=T.state,T.total_in=T.total_out=N.total=0,T.msg="",N.wrap&&(T.adler=1&N.wrap),N.mode=m,N.last=0,N.havedict=0,N.dmax=32768,N.head=null,N.hold=0,N.bits=0,N.lencode=N.lendyn=new s.Buf32(p),N.distcode=N.distdyn=new s.Buf32(f),N.sane=1,N.back=-1,h):d}function y(T){var N;return T&&T.state?((N=T.state).wsize=0,N.whave=0,N.wnext=0,C(T)):d}function x(T,N){var F,O;return T&&T.state?(O=T.state,N<0?(F=0,N=-N):(F=1+(N>>4),N<48&&(N&=15)),N&&(N<8||15<N)?d:(O.window!==null&&O.wbits!==N&&(O.window=null),O.wrap=F,O.wbits=N,y(T))):d}function E(T,N){var F,O;return T?(O=new I,(T.state=O).window=null,(F=x(T,N))!==h&&(T.state=null),F):d}var B,b,Q=!0;function w(T){if(Q){var N;for(B=new s.Buf32(512),b=new s.Buf32(32),N=0;N<144;)T.lens[N++]=8;for(;N<256;)T.lens[N++]=9;for(;N<280;)T.lens[N++]=7;for(;N<288;)T.lens[N++]=8;for(l(u,T.lens,0,288,B,0,T.work,{bits:9}),N=0;N<32;)T.lens[N++]=5;l(g,T.lens,0,32,b,0,T.work,{bits:5}),Q=!1}T.lencode=B,T.lenbits=9,T.distcode=b,T.distbits=5}function M(T,N,F,O){var U,Y=T.state;return Y.window===null&&(Y.wsize=1<<Y.wbits,Y.wnext=0,Y.whave=0,Y.window=new s.Buf8(Y.wsize)),O>=Y.wsize?(s.arraySet(Y.window,N,F-Y.wsize,Y.wsize,0),Y.wnext=0,Y.whave=Y.wsize):(O<(U=Y.wsize-Y.wnext)&&(U=O),s.arraySet(Y.window,N,F-O,U,Y.wnext),(O-=U)?(s.arraySet(Y.window,N,F-O,O,0),Y.wnext=O,Y.whave=Y.wsize):(Y.wnext+=U,Y.wnext===Y.wsize&&(Y.wnext=0),Y.whave<Y.wsize&&(Y.whave+=U))),0}r.inflateReset=y,r.inflateReset2=x,r.inflateResetKeep=C,r.inflateInit=function(T){return E(T,15)},r.inflateInit2=E,r.inflate=function(T,N){var F,O,U,Y,j,ee,J,W,te,re,ne,le,ge,fe,Ae,_e,ue,me,we,Me,he,Pe,Qe,Se,De=0,Ne=new s.Buf8(4),Ee=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!T||!T.state||!T.output||!T.input&&T.avail_in!==0)return d;(F=T.state).mode===12&&(F.mode=13),j=T.next_out,U=T.output,J=T.avail_out,Y=T.next_in,O=T.input,ee=T.avail_in,W=F.hold,te=F.bits,re=ee,ne=J,Pe=h;e:for(;;)switch(F.mode){case m:if(F.wrap===0){F.mode=13;break}for(;te<16;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(2&F.wrap&&W===35615){Ne[F.check=0]=255&W,Ne[1]=W>>>8&255,F.check=c(F.check,Ne,2,0),te=W=0,F.mode=2;break}if(F.flags=0,F.head&&(F.head.done=!1),!(1&F.wrap)||(((255&W)<<8)+(W>>8))%31){T.msg="incorrect header check",F.mode=30;break}if((15&W)!=8){T.msg="unknown compression method",F.mode=30;break}if(te-=4,he=8+(15&(W>>>=4)),F.wbits===0)F.wbits=he;else if(he>F.wbits){T.msg="invalid window size",F.mode=30;break}F.dmax=1<<he,T.adler=F.check=1,F.mode=512&W?10:12,te=W=0;break;case 2:for(;te<16;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(F.flags=W,(255&F.flags)!=8){T.msg="unknown compression method",F.mode=30;break}if(57344&F.flags){T.msg="unknown header flags set",F.mode=30;break}F.head&&(F.head.text=W>>8&1),512&F.flags&&(Ne[0]=255&W,Ne[1]=W>>>8&255,F.check=c(F.check,Ne,2,0)),te=W=0,F.mode=3;case 3:for(;te<32;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}F.head&&(F.head.time=W),512&F.flags&&(Ne[0]=255&W,Ne[1]=W>>>8&255,Ne[2]=W>>>16&255,Ne[3]=W>>>24&255,F.check=c(F.check,Ne,4,0)),te=W=0,F.mode=4;case 4:for(;te<16;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}F.head&&(F.head.xflags=255&W,F.head.os=W>>8),512&F.flags&&(Ne[0]=255&W,Ne[1]=W>>>8&255,F.check=c(F.check,Ne,2,0)),te=W=0,F.mode=5;case 5:if(1024&F.flags){for(;te<16;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}F.length=W,F.head&&(F.head.extra_len=W),512&F.flags&&(Ne[0]=255&W,Ne[1]=W>>>8&255,F.check=c(F.check,Ne,2,0)),te=W=0}else F.head&&(F.head.extra=null);F.mode=6;case 6:if(1024&F.flags&&(ee<(le=F.length)&&(le=ee),le&&(F.head&&(he=F.head.extra_len-F.length,F.head.extra||(F.head.extra=new Array(F.head.extra_len)),s.arraySet(F.head.extra,O,Y,le,he)),512&F.flags&&(F.check=c(F.check,O,le,Y)),ee-=le,Y+=le,F.length-=le),F.length))break e;F.length=0,F.mode=7;case 7:if(2048&F.flags){if(ee===0)break e;for(le=0;he=O[Y+le++],F.head&&he&&F.length<65536&&(F.head.name+=String.fromCharCode(he)),he&&le<ee;);if(512&F.flags&&(F.check=c(F.check,O,le,Y)),ee-=le,Y+=le,he)break e}else F.head&&(F.head.name=null);F.length=0,F.mode=8;case 8:if(4096&F.flags){if(ee===0)break e;for(le=0;he=O[Y+le++],F.head&&he&&F.length<65536&&(F.head.comment+=String.fromCharCode(he)),he&&le<ee;);if(512&F.flags&&(F.check=c(F.check,O,le,Y)),ee-=le,Y+=le,he)break e}else F.head&&(F.head.comment=null);F.mode=9;case 9:if(512&F.flags){for(;te<16;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(W!==(65535&F.check)){T.msg="header crc mismatch",F.mode=30;break}te=W=0}F.head&&(F.head.hcrc=F.flags>>9&1,F.head.done=!0),T.adler=F.check=0,F.mode=12;break;case 10:for(;te<32;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}T.adler=F.check=_(W),te=W=0,F.mode=11;case 11:if(F.havedict===0)return T.next_out=j,T.avail_out=J,T.next_in=Y,T.avail_in=ee,F.hold=W,F.bits=te,2;T.adler=F.check=1,F.mode=12;case 12:if(N===5||N===6)break e;case 13:if(F.last){W>>>=7&te,te-=7&te,F.mode=27;break}for(;te<3;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}switch(F.last=1&W,te-=1,3&(W>>>=1)){case 0:F.mode=14;break;case 1:if(w(F),F.mode=20,N!==6)break;W>>>=2,te-=2;break e;case 2:F.mode=17;break;case 3:T.msg="invalid block type",F.mode=30}W>>>=2,te-=2;break;case 14:for(W>>>=7&te,te-=7&te;te<32;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if((65535&W)!=(W>>>16^65535)){T.msg="invalid stored block lengths",F.mode=30;break}if(F.length=65535&W,te=W=0,F.mode=15,N===6)break e;case 15:F.mode=16;case 16:if(le=F.length){if(ee<le&&(le=ee),J<le&&(le=J),le===0)break e;s.arraySet(U,O,Y,le,j),ee-=le,Y+=le,J-=le,j+=le,F.length-=le;break}F.mode=12;break;case 17:for(;te<14;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(F.nlen=257+(31&W),W>>>=5,te-=5,F.ndist=1+(31&W),W>>>=5,te-=5,F.ncode=4+(15&W),W>>>=4,te-=4,286<F.nlen||30<F.ndist){T.msg="too many length or distance symbols",F.mode=30;break}F.have=0,F.mode=18;case 18:for(;F.have<F.ncode;){for(;te<3;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}F.lens[Ee[F.have++]]=7&W,W>>>=3,te-=3}for(;F.have<19;)F.lens[Ee[F.have++]]=0;if(F.lencode=F.lendyn,F.lenbits=7,Qe={bits:F.lenbits},Pe=l(0,F.lens,0,19,F.lencode,0,F.work,Qe),F.lenbits=Qe.bits,Pe){T.msg="invalid code lengths set",F.mode=30;break}F.have=0,F.mode=19;case 19:for(;F.have<F.nlen+F.ndist;){for(;_e=(De=F.lencode[W&(1<<F.lenbits)-1])>>>16&255,ue=65535&De,!((Ae=De>>>24)<=te);){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(ue<16)W>>>=Ae,te-=Ae,F.lens[F.have++]=ue;else{if(ue===16){for(Se=Ae+2;te<Se;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(W>>>=Ae,te-=Ae,F.have===0){T.msg="invalid bit length repeat",F.mode=30;break}he=F.lens[F.have-1],le=3+(3&W),W>>>=2,te-=2}else if(ue===17){for(Se=Ae+3;te<Se;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}te-=Ae,he=0,le=3+(7&(W>>>=Ae)),W>>>=3,te-=3}else{for(Se=Ae+7;te<Se;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}te-=Ae,he=0,le=11+(127&(W>>>=Ae)),W>>>=7,te-=7}if(F.have+le>F.nlen+F.ndist){T.msg="invalid bit length repeat",F.mode=30;break}for(;le--;)F.lens[F.have++]=he}}if(F.mode===30)break;if(F.lens[256]===0){T.msg="invalid code -- missing end-of-block",F.mode=30;break}if(F.lenbits=9,Qe={bits:F.lenbits},Pe=l(u,F.lens,0,F.nlen,F.lencode,0,F.work,Qe),F.lenbits=Qe.bits,Pe){T.msg="invalid literal/lengths set",F.mode=30;break}if(F.distbits=6,F.distcode=F.distdyn,Qe={bits:F.distbits},Pe=l(g,F.lens,F.nlen,F.ndist,F.distcode,0,F.work,Qe),F.distbits=Qe.bits,Pe){T.msg="invalid distances set",F.mode=30;break}if(F.mode=20,N===6)break e;case 20:F.mode=21;case 21:if(6<=ee&&258<=J){T.next_out=j,T.avail_out=J,T.next_in=Y,T.avail_in=ee,F.hold=W,F.bits=te,A(T,ne),j=T.next_out,U=T.output,J=T.avail_out,Y=T.next_in,O=T.input,ee=T.avail_in,W=F.hold,te=F.bits,F.mode===12&&(F.back=-1);break}for(F.back=0;_e=(De=F.lencode[W&(1<<F.lenbits)-1])>>>16&255,ue=65535&De,!((Ae=De>>>24)<=te);){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(_e&&(240&_e)==0){for(me=Ae,we=_e,Me=ue;_e=(De=F.lencode[Me+((W&(1<<me+we)-1)>>me)])>>>16&255,ue=65535&De,!(me+(Ae=De>>>24)<=te);){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}W>>>=me,te-=me,F.back+=me}if(W>>>=Ae,te-=Ae,F.back+=Ae,F.length=ue,_e===0){F.mode=26;break}if(32&_e){F.back=-1,F.mode=12;break}if(64&_e){T.msg="invalid literal/length code",F.mode=30;break}F.extra=15&_e,F.mode=22;case 22:if(F.extra){for(Se=F.extra;te<Se;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}F.length+=W&(1<<F.extra)-1,W>>>=F.extra,te-=F.extra,F.back+=F.extra}F.was=F.length,F.mode=23;case 23:for(;_e=(De=F.distcode[W&(1<<F.distbits)-1])>>>16&255,ue=65535&De,!((Ae=De>>>24)<=te);){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if((240&_e)==0){for(me=Ae,we=_e,Me=ue;_e=(De=F.distcode[Me+((W&(1<<me+we)-1)>>me)])>>>16&255,ue=65535&De,!(me+(Ae=De>>>24)<=te);){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}W>>>=me,te-=me,F.back+=me}if(W>>>=Ae,te-=Ae,F.back+=Ae,64&_e){T.msg="invalid distance code",F.mode=30;break}F.offset=ue,F.extra=15&_e,F.mode=24;case 24:if(F.extra){for(Se=F.extra;te<Se;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}F.offset+=W&(1<<F.extra)-1,W>>>=F.extra,te-=F.extra,F.back+=F.extra}if(F.offset>F.dmax){T.msg="invalid distance too far back",F.mode=30;break}F.mode=25;case 25:if(J===0)break e;if(le=ne-J,F.offset>le){if((le=F.offset-le)>F.whave&&F.sane){T.msg="invalid distance too far back",F.mode=30;break}ge=le>F.wnext?(le-=F.wnext,F.wsize-le):F.wnext-le,le>F.length&&(le=F.length),fe=F.window}else fe=U,ge=j-F.offset,le=F.length;for(J<le&&(le=J),J-=le,F.length-=le;U[j++]=fe[ge++],--le;);F.length===0&&(F.mode=21);break;case 26:if(J===0)break e;U[j++]=F.length,J--,F.mode=21;break;case 27:if(F.wrap){for(;te<32;){if(ee===0)break e;ee--,W|=O[Y++]<<te,te+=8}if(ne-=J,T.total_out+=ne,F.total+=ne,ne&&(T.adler=F.check=F.flags?c(F.check,U,ne,j-ne):a(F.check,U,ne,j-ne)),ne=J,(F.flags?W:_(W))!==F.check){T.msg="incorrect data check",F.mode=30;break}te=W=0}F.mode=28;case 28:if(F.wrap&&F.flags){for(;te<32;){if(ee===0)break e;ee--,W+=O[Y++]<<te,te+=8}if(W!==(4294967295&F.total)){T.msg="incorrect length check",F.mode=30;break}te=W=0}F.mode=29;case 29:Pe=1;break e;case 30:Pe=-3;break e;case 31:return-4;default:return d}return T.next_out=j,T.avail_out=J,T.next_in=Y,T.avail_in=ee,F.hold=W,F.bits=te,(F.wsize||ne!==T.avail_out&&F.mode<30&&(F.mode<27||N!==4))&&M(T,T.output,T.next_out,ne-T.avail_out)?(F.mode=31,-4):(re-=T.avail_in,ne-=T.avail_out,T.total_in+=re,T.total_out+=ne,F.total+=ne,F.wrap&&ne&&(T.adler=F.check=F.flags?c(F.check,U,ne,T.next_out-ne):a(F.check,U,ne,T.next_out-ne)),T.data_type=F.bits+(F.last?64:0)+(F.mode===12?128:0)+(F.mode===20||F.mode===15?256:0),(re==0&&ne===0||N===4)&&Pe===h&&(Pe=-5),Pe)},r.inflateEnd=function(T){if(!T||!T.state)return d;var N=T.state;return N.window&&(N.window=null),T.state=null,h},r.inflateGetHeader=function(T,N){var F;return T&&T.state?(2&(F=T.state).wrap)==0?d:((F.head=N).done=!1,h):d},r.inflateSetDictionary=function(T,N){var F,O=N.length;return T&&T.state?(F=T.state).wrap!==0&&F.mode!==11?d:F.mode===11&&a(1,N,O,0)!==F.check?-3:M(T,N,O,O)?(F.mode=31,-4):(F.havedict=1,h):d},r.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(o,i,r){var s=o("../utils/common"),a=[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],c=[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],A=[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],l=[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];i.exports=function(u,g,h,d,m,p,f,_){var I,C,y,x,E,B,b,Q,w,M=_.bits,T=0,N=0,F=0,O=0,U=0,Y=0,j=0,ee=0,J=0,W=0,te=null,re=0,ne=new s.Buf16(16),le=new s.Buf16(16),ge=null,fe=0;for(T=0;T<=15;T++)ne[T]=0;for(N=0;N<d;N++)ne[g[h+N]]++;for(U=M,O=15;1<=O&&ne[O]===0;O--);if(O<U&&(U=O),O===0)return m[p++]=20971520,m[p++]=20971520,_.bits=1,0;for(F=1;F<O&&ne[F]===0;F++);for(U<F&&(U=F),T=ee=1;T<=15;T++)if(ee<<=1,(ee-=ne[T])<0)return-1;if(0<ee&&(u===0||O!==1))return-1;for(le[1]=0,T=1;T<15;T++)le[T+1]=le[T]+ne[T];for(N=0;N<d;N++)g[h+N]!==0&&(f[le[g[h+N]]++]=N);if(B=u===0?(te=ge=f,19):u===1?(te=a,re-=257,ge=c,fe-=257,256):(te=A,ge=l,-1),T=F,E=p,j=N=W=0,y=-1,x=(J=1<<(Y=U))-1,u===1&&852<J||u===2&&592<J)return 1;for(;;){for(b=T-j,w=f[N]<B?(Q=0,f[N]):f[N]>B?(Q=ge[fe+f[N]],te[re+f[N]]):(Q=96,0),I=1<<T-j,F=C=1<<Y;m[E+(W>>j)+(C-=I)]=b<<24|Q<<16|w|0,C!==0;);for(I=1<<T-1;W&I;)I>>=1;if(I!==0?(W&=I-1,W+=I):W=0,N++,--ne[T]==0){if(T===O)break;T=g[h+f[N]]}if(U<T&&(W&x)!==y){for(j===0&&(j=U),E+=F,ee=1<<(Y=T-j);Y+j<O&&!((ee-=ne[Y+j])<=0);)Y++,ee<<=1;if(J+=1<<Y,u===1&&852<J||u===2&&592<J)return 1;m[y=W&x]=U<<24|Y<<16|E-p|0}}return W!==0&&(m[E+W]=T-j<<24|64<<16|0),_.bits=U,0}},{"../utils/common":41}],51:[function(o,i,r){i.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(o,i,r){var s=o("../utils/common"),a=0,c=1;function A(De){for(var Ne=De.length;0<=--Ne;)De[Ne]=0}var l=0,u=29,g=256,h=g+1+u,d=30,m=19,p=2*h+1,f=15,_=16,I=7,C=256,y=16,x=17,E=18,B=[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],b=[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],Q=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],w=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],M=new Array(2*(h+2));A(M);var T=new Array(2*d);A(T);var N=new Array(512);A(N);var F=new Array(256);A(F);var O=new Array(u);A(O);var U,Y,j,ee=new Array(d);function J(De,Ne,Ee,Te,Ie){this.static_tree=De,this.extra_bits=Ne,this.extra_base=Ee,this.elems=Te,this.max_length=Ie,this.has_stree=De&&De.length}function W(De,Ne){this.dyn_tree=De,this.max_code=0,this.stat_desc=Ne}function te(De){return De<256?N[De]:N[256+(De>>>7)]}function re(De,Ne){De.pending_buf[De.pending++]=255&Ne,De.pending_buf[De.pending++]=Ne>>>8&255}function ne(De,Ne,Ee){De.bi_valid>_-Ee?(De.bi_buf|=Ne<<De.bi_valid&65535,re(De,De.bi_buf),De.bi_buf=Ne>>_-De.bi_valid,De.bi_valid+=Ee-_):(De.bi_buf|=Ne<<De.bi_valid&65535,De.bi_valid+=Ee)}function le(De,Ne,Ee){ne(De,Ee[2*Ne],Ee[2*Ne+1])}function ge(De,Ne){for(var Ee=0;Ee|=1&De,De>>>=1,Ee<<=1,0<--Ne;);return Ee>>>1}function fe(De,Ne,Ee){var Te,Ie,ke=new Array(f+1),Ge=0;for(Te=1;Te<=f;Te++)ke[Te]=Ge=Ge+Ee[Te-1]<<1;for(Ie=0;Ie<=Ne;Ie++){var qe=De[2*Ie+1];qe!==0&&(De[2*Ie]=ge(ke[qe]++,qe))}}function Ae(De){var Ne;for(Ne=0;Ne<h;Ne++)De.dyn_ltree[2*Ne]=0;for(Ne=0;Ne<d;Ne++)De.dyn_dtree[2*Ne]=0;for(Ne=0;Ne<m;Ne++)De.bl_tree[2*Ne]=0;De.dyn_ltree[2*C]=1,De.opt_len=De.static_len=0,De.last_lit=De.matches=0}function _e(De){8<De.bi_valid?re(De,De.bi_buf):0<De.bi_valid&&(De.pending_buf[De.pending++]=De.bi_buf),De.bi_buf=0,De.bi_valid=0}function ue(De,Ne,Ee,Te){var Ie=2*Ne,ke=2*Ee;return De[Ie]<De[ke]||De[Ie]===De[ke]&&Te[Ne]<=Te[Ee]}function me(De,Ne,Ee){for(var Te=De.heap[Ee],Ie=Ee<<1;Ie<=De.heap_len&&(Ie<De.heap_len&&ue(Ne,De.heap[Ie+1],De.heap[Ie],De.depth)&&Ie++,!ue(Ne,Te,De.heap[Ie],De.depth));)De.heap[Ee]=De.heap[Ie],Ee=Ie,Ie<<=1;De.heap[Ee]=Te}function we(De,Ne,Ee){var Te,Ie,ke,Ge,qe=0;if(De.last_lit!==0)for(;Te=De.pending_buf[De.d_buf+2*qe]<<8|De.pending_buf[De.d_buf+2*qe+1],Ie=De.pending_buf[De.l_buf+qe],qe++,Te===0?le(De,Ie,Ne):(le(De,(ke=F[Ie])+g+1,Ne),(Ge=B[ke])!==0&&ne(De,Ie-=O[ke],Ge),le(De,ke=te(--Te),Ee),(Ge=b[ke])!==0&&ne(De,Te-=ee[ke],Ge)),qe<De.last_lit;);le(De,C,Ne)}function Me(De,Ne){var Ee,Te,Ie,ke=Ne.dyn_tree,Ge=Ne.stat_desc.static_tree,qe=Ne.stat_desc.has_stree,rt=Ne.stat_desc.elems,ct=-1;for(De.heap_len=0,De.heap_max=p,Ee=0;Ee<rt;Ee++)ke[2*Ee]!==0?(De.heap[++De.heap_len]=ct=Ee,De.depth[Ee]=0):ke[2*Ee+1]=0;for(;De.heap_len<2;)ke[2*(Ie=De.heap[++De.heap_len]=ct<2?++ct:0)]=1,De.depth[Ie]=0,De.opt_len--,qe&&(De.static_len-=Ge[2*Ie+1]);for(Ne.max_code=ct,Ee=De.heap_len>>1;1<=Ee;Ee--)me(De,ke,Ee);for(Ie=rt;Ee=De.heap[1],De.heap[1]=De.heap[De.heap_len--],me(De,ke,1),Te=De.heap[1],De.heap[--De.heap_max]=Ee,De.heap[--De.heap_max]=Te,ke[2*Ie]=ke[2*Ee]+ke[2*Te],De.depth[Ie]=(De.depth[Ee]>=De.depth[Te]?De.depth[Ee]:De.depth[Te])+1,ke[2*Ee+1]=ke[2*Te+1]=Ie,De.heap[1]=Ie++,me(De,ke,1),2<=De.heap_len;);De.heap[--De.heap_max]=De.heap[1],(function(gt,mt){var St,_t,Tt,Dt,Xe,Gt,un=mt.dyn_tree,xe=mt.max_code,et=mt.stat_desc.static_tree,It=mt.stat_desc.has_stree,Bt=mt.stat_desc.extra_bits,pt=mt.stat_desc.extra_base,xt=mt.stat_desc.max_length,Qt=0;for(Dt=0;Dt<=f;Dt++)gt.bl_count[Dt]=0;for(un[2*gt.heap[gt.heap_max]+1]=0,St=gt.heap_max+1;St<p;St++)xt<(Dt=un[2*un[2*(_t=gt.heap[St])+1]+1]+1)&&(Dt=xt,Qt++),un[2*_t+1]=Dt,xe<_t||(gt.bl_count[Dt]++,Xe=0,pt<=_t&&(Xe=Bt[_t-pt]),Gt=un[2*_t],gt.opt_len+=Gt*(Dt+Xe),It&&(gt.static_len+=Gt*(et[2*_t+1]+Xe)));if(Qt!==0){do{for(Dt=xt-1;gt.bl_count[Dt]===0;)Dt--;gt.bl_count[Dt]--,gt.bl_count[Dt+1]+=2,gt.bl_count[xt]--,Qt-=2}while(0<Qt);for(Dt=xt;Dt!==0;Dt--)for(_t=gt.bl_count[Dt];_t!==0;)xe<(Tt=gt.heap[--St])||(un[2*Tt+1]!==Dt&&(gt.opt_len+=(Dt-un[2*Tt+1])*un[2*Tt],un[2*Tt+1]=Dt),_t--)}})(De,Ne),fe(ke,ct,De.bl_count)}function he(De,Ne,Ee){var Te,Ie,ke=-1,Ge=Ne[1],qe=0,rt=7,ct=4;for(Ge===0&&(rt=138,ct=3),Ne[2*(Ee+1)+1]=65535,Te=0;Te<=Ee;Te++)Ie=Ge,Ge=Ne[2*(Te+1)+1],++qe<rt&&Ie===Ge||(qe<ct?De.bl_tree[2*Ie]+=qe:Ie!==0?(Ie!==ke&&De.bl_tree[2*Ie]++,De.bl_tree[2*y]++):qe<=10?De.bl_tree[2*x]++:De.bl_tree[2*E]++,ke=Ie,ct=(qe=0)===Ge?(rt=138,3):Ie===Ge?(rt=6,3):(rt=7,4))}function Pe(De,Ne,Ee){var Te,Ie,ke=-1,Ge=Ne[1],qe=0,rt=7,ct=4;for(Ge===0&&(rt=138,ct=3),Te=0;Te<=Ee;Te++)if(Ie=Ge,Ge=Ne[2*(Te+1)+1],!(++qe<rt&&Ie===Ge)){if(qe<ct)for(;le(De,Ie,De.bl_tree),--qe!=0;);else Ie!==0?(Ie!==ke&&(le(De,Ie,De.bl_tree),qe--),le(De,y,De.bl_tree),ne(De,qe-3,2)):qe<=10?(le(De,x,De.bl_tree),ne(De,qe-3,3)):(le(De,E,De.bl_tree),ne(De,qe-11,7));ke=Ie,ct=(qe=0)===Ge?(rt=138,3):Ie===Ge?(rt=6,3):(rt=7,4)}}A(ee);var Qe=!1;function Se(De,Ne,Ee,Te){ne(De,(l<<1)+(Te?1:0),3),(function(Ie,ke,Ge,qe){_e(Ie),re(Ie,Ge),re(Ie,~Ge),s.arraySet(Ie.pending_buf,Ie.window,ke,Ge,Ie.pending),Ie.pending+=Ge})(De,Ne,Ee)}r._tr_init=function(De){Qe||((function(){var Ne,Ee,Te,Ie,ke,Ge=new Array(f+1);for(Ie=Te=0;Ie<u-1;Ie++)for(O[Ie]=Te,Ne=0;Ne<1<<B[Ie];Ne++)F[Te++]=Ie;for(F[Te-1]=Ie,Ie=ke=0;Ie<16;Ie++)for(ee[Ie]=ke,Ne=0;Ne<1<<b[Ie];Ne++)N[ke++]=Ie;for(ke>>=7;Ie<d;Ie++)for(ee[Ie]=ke<<7,Ne=0;Ne<1<<b[Ie]-7;Ne++)N[256+ke++]=Ie;for(Ee=0;Ee<=f;Ee++)Ge[Ee]=0;for(Ne=0;Ne<=143;)M[2*Ne+1]=8,Ne++,Ge[8]++;for(;Ne<=255;)M[2*Ne+1]=9,Ne++,Ge[9]++;for(;Ne<=279;)M[2*Ne+1]=7,Ne++,Ge[7]++;for(;Ne<=287;)M[2*Ne+1]=8,Ne++,Ge[8]++;for(fe(M,h+1,Ge),Ne=0;Ne<d;Ne++)T[2*Ne+1]=5,T[2*Ne]=ge(Ne,5);U=new J(M,B,g+1,h,f),Y=new J(T,b,0,d,f),j=new J(new Array(0),Q,0,m,I)})(),Qe=!0),De.l_desc=new W(De.dyn_ltree,U),De.d_desc=new W(De.dyn_dtree,Y),De.bl_desc=new W(De.bl_tree,j),De.bi_buf=0,De.bi_valid=0,Ae(De)},r._tr_stored_block=Se,r._tr_flush_block=function(De,Ne,Ee,Te){var Ie,ke,Ge=0;0<De.level?(De.strm.data_type===2&&(De.strm.data_type=(function(qe){var rt,ct=4093624447;for(rt=0;rt<=31;rt++,ct>>>=1)if(1&ct&&qe.dyn_ltree[2*rt]!==0)return a;if(qe.dyn_ltree[18]!==0||qe.dyn_ltree[20]!==0||qe.dyn_ltree[26]!==0)return c;for(rt=32;rt<g;rt++)if(qe.dyn_ltree[2*rt]!==0)return c;return a})(De)),Me(De,De.l_desc),Me(De,De.d_desc),Ge=(function(qe){var rt;for(he(qe,qe.dyn_ltree,qe.l_desc.max_code),he(qe,qe.dyn_dtree,qe.d_desc.max_code),Me(qe,qe.bl_desc),rt=m-1;3<=rt&&qe.bl_tree[2*w[rt]+1]===0;rt--);return qe.opt_len+=3*(rt+1)+5+5+4,rt})(De),Ie=De.opt_len+3+7>>>3,(ke=De.static_len+3+7>>>3)<=Ie&&(Ie=ke)):Ie=ke=Ee+5,Ee+4<=Ie&&Ne!==-1?Se(De,Ne,Ee,Te):De.strategy===4||ke===Ie?(ne(De,2+(Te?1:0),3),we(De,M,T)):(ne(De,4+(Te?1:0),3),(function(qe,rt,ct,gt){var mt;for(ne(qe,rt-257,5),ne(qe,ct-1,5),ne(qe,gt-4,4),mt=0;mt<gt;mt++)ne(qe,qe.bl_tree[2*w[mt]+1],3);Pe(qe,qe.dyn_ltree,rt-1),Pe(qe,qe.dyn_dtree,ct-1)})(De,De.l_desc.max_code+1,De.d_desc.max_code+1,Ge+1),we(De,De.dyn_ltree,De.dyn_dtree)),Ae(De),Te&&_e(De)},r._tr_tally=function(De,Ne,Ee){return De.pending_buf[De.d_buf+2*De.last_lit]=Ne>>>8&255,De.pending_buf[De.d_buf+2*De.last_lit+1]=255&Ne,De.pending_buf[De.l_buf+De.last_lit]=255&Ee,De.last_lit++,Ne===0?De.dyn_ltree[2*Ee]++:(De.matches++,Ne--,De.dyn_ltree[2*(F[Ee]+g+1)]++,De.dyn_dtree[2*te(Ne)]++),De.last_lit===De.lit_bufsize-1},r._tr_align=function(De){ne(De,2,3),le(De,C,M),(function(Ne){Ne.bi_valid===16?(re(Ne,Ne.bi_buf),Ne.bi_buf=0,Ne.bi_valid=0):8<=Ne.bi_valid&&(Ne.pending_buf[Ne.pending++]=255&Ne.bi_buf,Ne.bi_buf>>=8,Ne.bi_valid-=8)})(De)}},{"../utils/common":41}],53:[function(o,i,r){i.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(o,i,r){(function(s){(function(a,c){if(!a.setImmediate){var A,l,u,g,h=1,d={},m=!1,p=a.document,f=Object.getPrototypeOf&&Object.getPrototypeOf(a);f=f&&f.setTimeout?f:a,A={}.toString.call(a.process)==="[object process]"?function(y){n.nextTick(function(){I(y)})}:(function(){if(a.postMessage&&!a.importScripts){var y=!0,x=a.onmessage;return a.onmessage=function(){y=!1},a.postMessage("","*"),a.onmessage=x,y}})()?(g="setImmediate$"+Math.random()+"$",a.addEventListener?a.addEventListener("message",C,!1):a.attachEvent("onmessage",C),function(y){a.postMessage(g+y,"*")}):a.MessageChannel?((u=new MessageChannel).port1.onmessage=function(y){I(y.data)},function(y){u.port2.postMessage(y)}):p&&"onreadystatechange"in p.createElement("script")?(l=p.documentElement,function(y){var x=p.createElement("script");x.onreadystatechange=function(){I(y),x.onreadystatechange=null,l.removeChild(x),x=null},l.appendChild(x)}):function(y){setTimeout(I,0,y)},f.setImmediate=function(y){typeof y!="function"&&(y=new Function(""+y));for(var x=new Array(arguments.length-1),E=0;E<x.length;E++)x[E]=arguments[E+1];var B={callback:y,args:x};return d[h]=B,A(h),h++},f.clearImmediate=_}function _(y){delete d[y]}function I(y){if(m)setTimeout(I,0,y);else{var x=d[y];if(x){m=!0;try{(function(E){var B=E.callback,b=E.args;switch(b.length){case 0:B();break;case 1:B(b[0]);break;case 2:B(b[0],b[1]);break;case 3:B(b[0],b[1],b[2]);break;default:B.apply(c,b)}})(x)}finally{_(y),m=!1}}}}function C(y){y.source===a&&typeof y.data=="string"&&y.data.indexOf(g)===0&&I(+y.data.slice(g.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof Ry<"u"?Ry:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(qet)),qet.exports}var Isr=_sr();const mIe=vC(Isr),Csr=async({circuitJson:t,projectName:e})=>{await ua.promise((async()=>{const n=new mIe,[o,{convertCircuitJsonToBomRows:i,convertBomRowsToCsv:r},{convertCircuitJsonToPickAndPlaceCsv:s}]=await Promise.all([n5("circuit-json-to-gerber"),n5("circuit-json-to-bom-csv"),n5("circuit-json-to-pnp-csv")]),a=t.filter(h=>!("error_type"in h)&&!("warning_type"in h)),c=o.convertCircuitJsonToGerberFiles(a,{flip_y_axis:!1});for(const[h,d]of Object.entries(c))n.file(`gerber/${h}`,d);const A=await i({circuitJson:t}),l=await r(A);n.file("bom.csv",l);const u=await s(t,{supplier:"jlcpcb"});n.file("pick_and_place.csv",u);const g=await n.generateAsync({type:"blob"});o5(g,{fileName:`${e}_fabrication_files.zip`})})(),{loading:"Generating fabrication files...",success:"Fabrication ZIP ready",error:n=>`Failed to generate fabrication files: ${n instanceof Error?n.message:String(n)}`})},ysr=async t=>{const{createFdmComponentBox:e,renderFdmComponentBoxPng:n}=await n5("circuit-json-to-fdm-component-box"),[o,i]=await Promise.all([e(t),n(t,{},{width:960,height:640})]);return{...o,previewPng:i}},xsr=async t=>{const{createFdmComponentBox:e}=await n5("circuit-json-to-fdm-component-box");return e(t)},SEn=({generatedBox:t,projectName:e})=>{const n=Uint8Array.from(t.threeMf);o5(new Blob([n.buffer],{type:"model/3mf"}),{fileName:`${yet(e)}-component-box.3mf`})},Esr=async({circuitJson:t,projectName:e})=>{await ua.promise((async()=>{const n=await xsr(t);SEn({generatedBox:n,projectName:e})})(),{loading:"Generating component box...",success:"Component box 3MF ready",error:n=>`Failed to generate component box: ${n instanceof Error?n.message:String(n)}`})},Bsr=async({circuitJson:t,projectName:e})=>{let n;try{const{convertCircuitJsonToGltf:o}=await n5("circuit-json-to-gltf");console.log("convertCircuitJsonToGltf",o);const i=await o(t,{format:"glb",boardTextureResolution:1024});if(!i||!(i instanceof ArrayBuffer))throw new Error("Invalid GLB data returned from converter");n=new Blob([i],{type:"model/gltf-binary"})}catch(o){console.error("GLB Export Error:",o);return}o5(n,{fileName:`${e}.glb`})},bsr=async({circuitJson:t,libraryName:e})=>{const{CircuitJsonToKicadLibraryConverter:n}=await n5("circuit-json-to-kicad"),o=new n(t,{libraryName:e,footprintLibraryName:e});o.runUntilFinished();const i=o.getOutput(),r=new mIe;r.file(`${e}.kicad_sym`,i.kicadSymString);for(const s of i.footprints){const a=r.folder(`${e}.pretty`);a&&a.file(`${s.footprintName}.kicad_mod`,`${s.kicadModString}
5679
5679
  `)}if(i.model3dSourcePaths.length>0){const s=r.folder(`${e}.3dshapes`);if(s)for(const a of i.model3dSourcePaths)try{const c=a.split("/").pop()||a,A=await fetch(a);if(A.ok){const l=await A.arrayBuffer();s.file(c,l)}}catch{}}return r.file("fp-lib-table",i.fpLibTableString),r.file("sym-lib-table",i.symLibTableString),r},Ssr=async({circuitJson:t,projectName:e})=>{await ua.promise((async()=>{const o=await(await bsr({circuitJson:t,libraryName:e})).generateAsync({type:"blob"});o5(o,{fileName:`${e}_kicad_library.zip`})})(),{loading:"Generating KiCad library...",success:"KiCad library ZIP ready",error:n=>`Failed to generate KiCad library: ${n instanceof Error?n.message:String(n)}`})},Qsr=async({circuitJson:t,projectName:e})=>{const{CircuitJsonToKicadPcbConverter:n,CircuitJsonToKicadSchConverter:o,CircuitJsonToKicadProConverter:i,resolveAndLoadKicad3dModelFiles:r}=await n5("circuit-json-to-kicad"),s=new o(t);s.runUntilFinished();const a=s.getOutputString(),c=new n(t,{includeBuiltin3dModels:!0,projectName:e});c.runUntilFinished();const A=c.getOutputString(),l=new i(t,{projectName:e,schematicFilename:`${e}.kicad_sch`,pcbFilename:`${e}.kicad_pcb`});l.runUntilFinished();const u=l.getOutputString(),g=new mIe;return g.file(`${e}.kicad_sch`,a),g.file(`${e}.kicad_pcb`,A),g.file(`${e}.kicad_pro`,u),await r({projectName:e,model3dSourcePaths:c.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:h,content:d})=>{g.file(h,d)},onError:({sourcePath:h})=>{console.warn(`Failed to load 3D model from ${h}`)}}),g},vsr=async({circuitJson:t,projectName:e})=>{await ua.promise((async()=>{const o=await(await Qsr({circuitJson:t,projectName:e})).generateAsync({type:"blob"});o5(o,{fileName:`${e}_kicad_project.zip`})})(),{loading:"Generating KiCad project...",success:"KiCad project ZIP ready",error:n=>`Failed to generate KiCad project: ${n instanceof Error?n.message:String(n)}`})},QEn=async({circuitJson:t,projectName:e,options:n={}})=>{try{const{convertCircuitJsonToLbrn:o}=await n5("circuit-json-to-lbrn"),r=(await o(t,{includeSilkscreen:n.includeSilkscreen??!1,includeOxidationCleaningLayer:n.includeOxidationCleaningLayer??!0})).toXml(),s=new Blob([r],{type:"application/lbrn"});o5(s,{fileName:`${e}.lbrn2`})}catch(o){const i=o instanceof Error?o.message:"Unknown error";ua.error(`Failed to export to LBRN format: ${i}`)}},wsr=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToPinoutSvg:n}=await n5("circuit-to-svg"),o=n(t);o5(o,{fileName:`${e}-pinout.svg`,mimeType:"image/svg+xml"})},Psr=async({circuitJson:t,projectName:e})=>{const{circuitJsonToStep:n}=await n5("circuit-json-to-step"),o=t.find(A=>A.type==="pcb_board"),i=o&&"width"in o?o.width:void 0,r=o&&"height"in o?o.height:void 0,s=o&&"thickness"in o?o.thickness:void 0;if(i===void 0||r===void 0||s===void 0){ua.error("Board dimensions not found. Please add a pcb_board with width, height, and thickness to your circuit.");return}let a;try{a=await n(t,{boardWidth:i,boardHeight:r,boardThickness:s,productName:e,includeComponents:!0,includeExternalMeshes:!0})}catch(A){const l=A instanceof Error?A.message:"Unknown error";ua.error(`Failed to convert circuit to STEP format: ${l}`);return}const c=new Blob([a],{type:"application/step"});try{o5(c,{fileName:`${e}.step`})}catch(A){const l=A instanceof Error?A.message:"Unknown error";ua.error(`Failed to download STEP file: ${l}`)}},Msr=[{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:"lbrn2",name:"LightBurn"}],Dsr=async({exportName:t,circuitJson:e,simpleRouteJson:n,projectName:o})=>{const i=yet(o);if(t==="Fabrication Files"){await Csr({circuitJson:e,projectName:i});return}if(t==="KiCad Project"){await vsr({circuitJson:e,projectName:i});return}if(t==="Altium Project"){await fsr({circuitJson:e,projectName:i});return}if(t==="KiCad Library"){await Ssr({circuitJson:e,projectName:i});return}if(t==="Circuit JSON"){o5(JSON.stringify(e,null,2),{fileName:`${i}.circuit.json`,mimeType:"application/json"});return}if(t==="Simple Route JSON"){if(!n)throw new Error("No Simple Route JSON available to export");o5(JSON.stringify(n,null,2),{fileName:`${i}.simple-route.json`,mimeType:"application/json"});return}if(t==="GLB (Binary GLTF)"){await Bsr({circuitJson:e,projectName:i});return}if(t==="Pinout SVG"){wsr({circuitJson:e,projectName:i});return}if(t==="STEP"){await Psr({circuitJson:e,projectName:i});return}if(t==="Component Box (3MF)"){await Esr({circuitJson:e,projectName:i});return}if(t==="LightBurn"){await QEn({circuitJson:e,projectName:i});return}throw new Error(`Unsupported export type: "${t}"`)},Nsr=({packageName:t,onSelectReview:e})=>{const n=xd(u=>u.fsMap),o=xd(u=>u.circuitJson),[i,r]=q.useState([]),[s,a]=q.useState(!1),[c,A]=q.useState(!1);q.useEffect(()=>{!t||!dhe()||(a(!0),lX.get("ai_reviews/list",{searchParams:{package_name:t}}).json().then(u=>r(u.ai_reviews)).catch(u=>{console.error("Failed to load AI reviews",u),ua.error("Failed to load AI reviews")}).finally(()=>a(!1)))},[t]);const l=async()=>{if(!o){ua.error("Need Circuit JSON to Request AI Review");return}if(!dhe()){ua.error("Missing registry token");return}A(!0);try{const{ai_review:u}=await lX.post("ai_reviews/create",{json:{package_name:t??"unknown",fs_map:Object.fromEntries(n),circuit_json:o}}).json();r(g=>[u,...g]),e(u),ua.success("AI review requested")}catch(u){console.error("Failed to create AI review",u),ua.error("Failed to request AI review")}finally{A(!1)}};return K.jsxs(K.Fragment,{children:[K.jsxs(QM,{children:[K.jsx(vM,{children:"AI Review"}),K.jsx(Bk,{children:"Select an AI review or request a new one."})]}),K.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:K.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:s?K.jsx("div",{className:"rf-text-sm",children:"Loading..."}):i.length>0?i.map(u=>K.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>e(u),children:new Date(u.created_at||"").toLocaleString()},u.ai_review_id)):K.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),K.jsx(jK,{className:"rf-mt-4",children:K.jsx(Ic,{onClick:l,disabled:c,children:c?"Requesting...":"Review my Board"})})]})};function Xet(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var bk=Xet();function vEn(t){bk=t}var Gte={exec:()=>null};function H0(t,e=""){let n=typeof t=="string"?t:t.source;const o={replace:(i,r)=>{let s=typeof r=="string"?r:r.source;return s=s.replace(v2.caret,"$1"),n=n.replace(i,s),o},getRegex:()=>new RegExp(n,e)};return o}var v2={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:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Rsr=/^(?:[ \t]*(?:\n|$))+/,Tsr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ksr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Yte=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Fsr=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Zet=/(?:[*+-]|\d{1,9}[.)])/,wEn=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,PEn=H0(wEn).replace(/bull/g,Zet).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(),Lsr=H0(wEn).replace(/bull/g,Zet).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(),ett=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Hsr=/^[^\n]+/,ttt=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Osr=H0(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ttt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Gsr=H0(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Zet).getRegex(),pIe="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",ntt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Ysr=H0("^ {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",ntt).replace("tag",pIe).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),MEn=H0(ett).replace("hr",Yte).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",pIe).getRegex(),Usr=H0(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",MEn).getRegex(),ott={blockquote:Usr,code:Tsr,def:Osr,fences:ksr,heading:Fsr,hr:Yte,html:Ysr,lheading:PEn,list:Gsr,newline:Rsr,paragraph:MEn,table:Gte,text:Hsr},DEn=H0("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Yte).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",pIe).getRegex(),Ksr={...ott,lheading:Lsr,table:DEn,paragraph:H0(ett).replace("hr",Yte).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",DEn).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",pIe).getRegex()},zsr={...ott,html:H0(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ntt).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:Gte,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:H0(ett).replace("hr",Yte).replace("heading",` *#{1,6} *[^
5680
5680
  ]`).replace("lheading",PEn).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Vsr=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Jsr=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,NEn=/^( {2,}|\\)\n(?!\s*$)/,Wsr=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,fIe=/[\p{P}\p{S}]/u,itt=/[\s\p{P}\p{S}]/u,REn=/[^\s\p{P}\p{S}]/u,jsr=H0(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,itt).getRegex(),TEn=/(?!~)[\p{P}\p{S}]/u,$sr=/(?!~)[\s\p{P}\p{S}]/u,qsr=/(?:[^\s\p{P}\p{S}]|~)/u,Xsr=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,kEn=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Zsr=H0(kEn,"u").replace(/punct/g,fIe).getRegex(),ear=H0(kEn,"u").replace(/punct/g,TEn).getRegex(),FEn="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",tar=H0(FEn,"gu").replace(/notPunctSpace/g,REn).replace(/punctSpace/g,itt).replace(/punct/g,fIe).getRegex(),nar=H0(FEn,"gu").replace(/notPunctSpace/g,qsr).replace(/punctSpace/g,$sr).replace(/punct/g,TEn).getRegex(),oar=H0("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,REn).replace(/punctSpace/g,itt).replace(/punct/g,fIe).getRegex(),iar=H0(/\\(punct)/,"gu").replace(/punct/g,fIe).getRegex(),rar=H0(/^<(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(),sar=H0(ntt).replace("(?:-->|$)","-->").getRegex(),aar=H0("^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",sar).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),_Ie=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,car=H0(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",_Ie).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),LEn=H0(/^!?\[(label)\]\[(ref)\]/).replace("label",_Ie).replace("ref",ttt).getRegex(),HEn=H0(/^!?\[(ref)\](?:\[\])?/).replace("ref",ttt).getRegex(),Aar=H0("reflink|nolink(?!\\()","g").replace("reflink",LEn).replace("nolink",HEn).getRegex(),rtt={_backpedal:Gte,anyPunctuation:iar,autolink:rar,blockSkip:Xsr,br:NEn,code:Jsr,del:Gte,emStrongLDelim:Zsr,emStrongRDelimAst:tar,emStrongRDelimUnd:oar,escape:Vsr,link:car,nolink:HEn,punctuation:jsr,reflink:LEn,reflinkSearch:Aar,tag:aar,text:Wsr,url:Gte},lar={...rtt,link:H0(/^!?\[(label)\]\((.*?)\)/).replace("label",_Ie).getRegex(),reflink:H0(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",_Ie).getRegex()},stt={...rtt,emStrongRDelimAst:nar,emStrongLDelim:ear,url:H0(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},uar={...stt,br:H0(NEn).replace("{2,}","*").getRegex(),text:H0(stt.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},IIe={normal:ott,gfm:Ksr,pedantic:zsr},Ute={normal:rtt,gfm:stt,breaks:uar,pedantic:lar},gar={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},OEn=t=>gar[t];function Fb(t,e){if(e){if(v2.escapeTest.test(t))return t.replace(v2.escapeReplace,OEn)}else if(v2.escapeTestNoEncode.test(t))return t.replace(v2.escapeReplaceNoEncode,OEn);return t}function GEn(t){try{t=encodeURI(t).replace(v2.percentDecode,"%")}catch{return null}return t}function YEn(t,e){const n=t.replace(v2.findPipe,(r,s,a)=>{let c=!1,A=s;for(;--A>=0&&a[A]==="\\";)c=!c;return c?"|":" |"}),o=n.split(v2.splitPipe);let i=0;if(o[0].trim()||o.shift(),o.length>0&&!o.at(-1)?.trim()&&o.pop(),e)if(o.length>e)o.splice(e);else for(;o.length<e;)o.push("");for(;i<o.length;i++)o[i]=o[i].trim().replace(v2.slashPipe,"|");return o}function Kte(t,e,n){const o=t.length;if(o===0)return"";let i=0;for(;i<o&&t.charAt(o-i-1)===e;)i++;return t.slice(0,o-i)}function dar(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let o=0;o<t.length;o++)if(t[o]==="\\")o++;else if(t[o]===e[0])n++;else if(t[o]===e[1]&&(n--,n<0))return o;return n>0?-2:-1}function UEn(t,e,n,o,i){const r=e.href,s=e.title||null,a=t[1].replace(i.other.outputLinkReplace,"$1");o.state.inLink=!0;const c={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:r,title:s,text:a,tokens:o.inlineTokens(a)};return o.state.inLink=!1,c}function har(t,e,n){const o=t.match(n.other.indentCodeCompensation);if(o===null)return e;const i=o[1];return e.split(`