tscircuit 0.0.2536-libonly → 0.0.2537-libonly
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.min.js +1 -1
- package/package.json +6 -6
package/dist/browser.min.js
CHANGED
|
@@ -5772,7 +5772,7 @@ test("${c} should solve problem correctly", () => {
|
|
|
5772
5772
|
// Add more specific assertions based on expected output
|
|
5773
5773
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5774
5774
|
})
|
|
5775
|
-
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return Y.jsxs("div",{className:`relative ${e}`,ref:i,children:[Y.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&&Y.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:[Y.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),Y.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Y.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},oin=t=>t.activeSubSolver?[t,...oin(t.activeSubSolver)]:[t],pQi=({solver:t})=>{const e=oin(t);return Y.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>Y.jsxs("div",{className:"flex items-center",children:[o>0&&Y.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Y.jsx(mQi,{solver:n})]},n.getSolverName()))})},_Qi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=$.useReducer(S=>!S,!1),g=$.useRef(void 0),u=$.useRef(null),h="solver-debugger-last-iteration",[d,m]=$.useState(null),p=$.useRef(null),_=$.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"}],[]),f=()=>{const S=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let v=0;v<b&&!(t.solved||t.failed);v++)t.step();e()},S)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const S=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(S===null)return;u.current=S,typeof window<"u"&&window.localStorage.setItem(h,S);const b=Number(S);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&&A&&A(t)};return $.useEffect(()=>()=>{I()},[]),$.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),$.useEffect(()=>{c&&(I(),f())},[n,c]),$.useEffect(()=>{if(typeof document>"u")return;const S=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[]),Y.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Y.jsx("div",{className:"flex items-center",children:Y.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[Y.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[Y.jsxs("div",{className:"relative",children:[Y.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"&&Y.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(S=>Y.jsxs("button",{type:"button",onClick:()=>{i(S),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S==="vector"?"Vector":"Canvas",o===S&&Y.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},S))})]}),Y.jsxs("div",{className:"relative",children:[Y.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"&&Y.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:Y.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"})})]}),Y.jsxs("div",{className:"relative",children:[Y.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"&&Y.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:_.map(S=>Y.jsxs("button",{type:"button",onClick:()=>{r(S.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S.label,Y.jsx("span",{className:"ml-auto text-xs text-slate-500",children:S.description}),n===S.value&&Y.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},S.value))})]})]}),Y.jsx(pQi,{solver:t})]})}),Y.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Y.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Y.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Y.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),Y.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),Y.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&Y.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&Y.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&Y.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&Y.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},fQi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),IQi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},CQi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=IQi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},yQi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Y.jsx("span",{className:`font-medium ${e[t]}`,children:t})},xQi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return Y.jsxs("div",{className:"flex items-center gap-2",children:[Y.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Y.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),Y.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},iin=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)},EQi=t=>Object.entries(t).map(([e,n])=>`${e}: ${iin(n)}`).join(", "),BQi=({stats:t})=>{if(!t||Object.keys(t).length===0)return Y.jsx("span",{children:"-"});const e=Object.entries(t),n=EQi(t);return Y.jsxs("details",{className:"cursor-pointer",children:[Y.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),Y.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>Y.jsxs("div",{children:[o,": ",iin(i)]},o))})]})},TYe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TYe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=TYe(o));return e},SQi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=TYe(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)}`)}},bQi=({expanded:t})=>Y.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:Y.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"})}),rin=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},sin=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=$.useState(new Set),A=t.pipelineDef.map((p,_)=>CQi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):SQi(p.solverInstance,p.name))},u=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=rin(t);for(;!t.solved&&!t.failed&&(t.step(),rin(t)===p););r?.()}},m=i*24;return Y.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&Y.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[Y.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),Y.jsxs("div",{className:"flex gap-2",children:[Y.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"}),Y.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"})]})]}),Y.jsx("div",{className:"overflow-x-auto",children:Y.jsxs("table",{className:"w-full text-sm",children:[!o&&Y.jsx("thead",{children:Y.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Y.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Y.jsx("sub",{children:"0"})]}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Y.jsx("tbody",{children:A.map(p=>{const _=fQi(p.solverInstance),f=s.has(p.name);return Y.jsxs(Cs.Fragment,{children:[Y.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[Y.jsx("td",{className:"px-4 py-2",children:Y.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?Y.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:Y.jsx(bQi,{expanded:f})}):Y.jsx("span",{className:"w-4"}),Y.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),Y.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:Y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Y.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"})})}),Y.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),Y.jsx("td",{className:"px-4 py-2",children:Y.jsx(yQi,{status:p.status})}),Y.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),Y.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),Y.jsx("td",{className:"px-4 py-2",children:Y.jsx(xQi,{progress:p.progress})}),Y.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),Y.jsx("td",{className:"px-4 py-2 text-gray-500",children:Y.jsx(BQi,{stats:p.stats})}),Y.jsx("td",{className:"px-4 py-2",children:p.solverInstance?Y.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[Y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Y.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"})}),Y.jsx("span",{children:"Input"})]}):null})]}),_&&f&&Y.jsx("tr",{children:Y.jsx("td",{colSpan:8,className:"p-0",children:Y.jsx(sin,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function QQi({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,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return Y.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>Y.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-${_}`)),n.map((p,_)=>Y.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>Y.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-${_}`)),e.map((p,_)=>Y.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>Y.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var vQi=class extends Cs.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}},PQi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=$.useReducer(f=>f+1,0),[a]=$.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=$.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=$.useState(n),u=$.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=$.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);$.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),$.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{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=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return Y.jsxs("div",{children:[Y.jsx(_Qi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?Y.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Y.jsx(vQi,{fallback:Y.jsx(QQi,{graphics:u}),children:A==="canvas"?Y.jsx(hQi,{graphics:u}):Y.jsx(gQi,{graphics:u})}),d&&Y.jsx(sin,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const wQi=()=>{$.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)},[])},DQi=1e3,D2=(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)},DQi)},kYe=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"},MQi=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]},Cv="https://github.com/tscircuit/tscircuit-autorouter/issues/new",ain="https://github.com/tscircuit/copper-pour-solver/issues/new",Ain="https://github.com/tscircuit/calculate-packing/issues/new",RQi="https://github.com/tscircuit/matchpack/issues/new",cin="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",NQi={PackSolver2:Ain,LayoutPipelineSolver:RQi,AutoroutingPipelineSolver:Cv,AssignableAutoroutingPipeline2:Cv,AssignableAutoroutingPipeline3:Cv,AutoroutingPipeline1_OriginalUnravel:Cv,AutoroutingPipelineSolver3_HgPortPointPathing:Cv,AutoroutingPipelineSolver4:Cv,AutoroutingPipelineSolver5:Cv,AutoroutingPipelineSolver7_MultiGraph:Cv,AutoroutingPipelineSolver8:Cv,CopperPourPipelineSolver:ain,SchematicTracePipelineSolver:cin},TQi=t=>t.toLowerCase().includes("pack")?nZt:t.toLowerCase().includes("rout")?iZt:a0i,lin=t=>{const e=NQi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?Cv:n.includes("schematic")&&n.includes("trace")?cin:n.includes("copperpour")?ain:n.includes("pack")?Ain:null},kQi=t=>`${kYe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,gin=t=>{D2(JSON.stringify(t.solverParams,null,2),{fileName:kQi(t),mimeType:"application/json"})},FQi=({solverEvent:t})=>{const e=lin(t.solverName);return Y.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:[Y.jsxs(Xa,{type:"button",variant:"outline",size:"sm",onClick:()=>gin(t),children:[Y.jsx(bj,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?Y.jsx(Xa,{asChild:!0,variant:"outline",size:"sm",children:Y.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[Y.jsx(xue,{className:"rf-w-4 rf-h-4"}),"Report"]})}):Y.jsxs(Xa,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[Y.jsx(xue,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},LQi=({solverEvent:t})=>{const e=lin(t.solverName);return e?Y.jsx(Xa,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:Y.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:Y.jsx(xue,{className:"rf-w-4 rf-h-4"})})}):Y.jsx(Xa,{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:Y.jsx(xue,{className:"rf-w-4 rf-h-4"})})},HQi=({solverEvents:t=[]})=>{const[e,n]=$.useState(null);wQi();const o=$.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=$.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=$.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=bDe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(bDe).join(", ")}`,classFound:!1};try{return{instance:new a(...MQi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?Y.jsx("div",{className:"rf-p-4",children:Y.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Y.jsxs("div",{className:"rf-p-4",children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Y.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."})]})})}):Y.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Y.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Y.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 A=o.get(a),c=e===a;return Y.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=TQi(A.solverName);return Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Y.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Y.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Y.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),Y.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),Y.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?Y.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[Y.jsx(FQi,{solverEvent:r}),Y.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:Y.jsx(y2,{fallback:Y.jsx("div",{className:"rf-p-4",children:Y.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Y.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:Y.jsx(PQi,{solver:s.instance})})})]}):Y.jsxs("div",{className:"rf-p-4",children:[Y.jsxs("div",{className:"rf-mb-4",children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),Y.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&Y.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:Y.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Y.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Y.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:[Y.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[Y.jsx(LQi,{solverEvent:r}),Y.jsx(Xa,{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:()=>gin(r),children:Y.jsx(bj,{className:"rf-w-4 rf-h-4"})})]})]}),Y.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Y.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)})})]})]}):Y.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Y.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},OQi=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],GQi=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function UQi(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 A of GQi)if(!(r[A]===void 0||e[A]===void 0)){if(r[A]!==e[A]){a=!0;break}s++}!a&&s>o&&(n=i,o=s)}return n}function YQi(t,e){const n=Object.fromEntries(OQi.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:UQi(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 KQi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),zQi=new Set(["tscircuit","default","auto","auto_local"]);function VQi(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 JQi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&KQi.get(n);if(o)return o;if(n&&!zQi.has(n))return e;const i=t.solverName?.trim();if(i)return VQi(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 FYe="#fbbf24";function WQi(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 uin(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 jQi(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 din(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,...jQi(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 A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function qQi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(uin(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of din(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:FYe,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:FYe,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function XQi(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 $Qi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function ZQi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!$Qi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:WQi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=din(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${XQi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.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:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const LYe=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,hin=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",min=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,e3i={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},t3i=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=$.useState(null),[r,s]=$.useState("output"),[a,A]=$.useState(!0),[c,l]=$.useState(!1),g=$.useRef(null),[u,h]=$.useState(480),d=o?e.findIndex(L=>L.id===o.id&&min(L)===min(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=$.useMemo(()=>!p||!x?null:ZQi(t??[],p,y),[t,p,x,y]),S=$.useMemo(()=>p&&y==="output"&&a?qQi(p):{lines:[],circles:[]},[p,y,a]);if($.useLayoutEffect(()=>{const L=g.current;if(!L)return;const O=()=>h(Math.max(360,L.clientHeight));O();const G=new ResizeObserver(O);return G.observe(L),()=>G.disconnect()},[!!p]),!p)return Y.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:[Y.jsx(iZt,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),Y.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),Y.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=LYe(p,m),v=p.status==="running"&&n,M=!f,N=I?.connections.length,k=E?.filter(L=>L.type==="pcb_trace").length??0;return Y.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:[Y.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:[Y.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:[Y.jsx("span",{children:"Routing phases"}),Y.jsx("span",{children:e.length})]}),Y.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((L,O)=>{const G=uin(L).length,V=L.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:L.status==="error"?"Failed":L.status==="running"&&n?"Routing…":"No output";return Y.jsxs("button",{type:"button","aria-pressed":O===m,title:`${hin(L)} · ${V}`,onClick:()=>i(L),className:Mi("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",O===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[Y.jsx("span",{className:Mi("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",O===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:O+1}),Y.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[Y.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[Y.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:LYe(L,O),children:LYe(L,O)}),L.status==="complete"?Y.jsx(Uw,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):L.status==="error"?Y.jsx(FGe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?Y.jsx(x2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),Y.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[JQi(L)," · ",V]})]})]},L.id)})})]}),Y.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[Y.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:[Y.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,Y.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&Y.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),Y.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(L=>Y.jsx("button",{type:"button","aria-pressed":y===L,disabled:L==="input"?!C:!f,onClick:()=>s(L),className:Mi("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===L?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:L==="input"?"Input":"Output"},L))})]}),Y.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:[Y.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[Y.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:L=>A(L.target.checked),className:"rf-accent-blue-600"}),Y.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:FYe}}),"Highlight changes (all layers)"]}),Y.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),M&&Y.jsx("div",{className:Mi("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."}`:v?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),Y.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?Y.jsx(PYe,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:e3i,debugGraphics:S}):Y.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),Y.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:[Y.jsxs("span",{children:[N===void 0?"Input unavailable":`${N} input connections`,` · ${hin(p)}`]}),Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[Y.jsxs("button",{type:"button",disabled:!x,onClick:()=>D2(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:[Y.jsx(bj,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),Y.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[Y.jsx(sR,{className:Mi("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&Y.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."})]})]})},pin=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{$.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{QL.captureException(o)}catch{}}},[t,e]),$.useEffect(()=>{if(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{QL.captureException(i,{error_type:o.type})}catch{}}},[n])},_in=t=>{$.useEffect(()=>{try{TMo(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},fin="0.0.2715",n3i={version:fin},jde=O4t()(G4t(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),o3i=t=>{const[e,n]=$.useState([]),[o,i]=$.useState(null),[r,s]=$.useState(""),[a,A]=oL("eval-version-selection",null),c=jde(h=>h.setLastRunEvalVersion),l=jde(h=>h.lastRunEvalVersion);return $.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]),$.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:$.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{A(h),s("")}}},i3i=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=$.useState(""),[s,a]=$.useState("");if(!o)return null;const A=t.filter(g=>g.toLowerCase().includes(s.toLowerCase())),c=s&&!t.includes(s),l=g=>{g.key==="Enter"&&(A.length===1?r(A[0]):c&&r(s))};return Y.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:Y.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[Y.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),Y.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:g=>a(g.target.value),onKeyDown:l}),Y.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>Y.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===g?"bg-blue-50":""}`,onClick:()=>r(g),children:g},g)),c&&Y.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,'"']})]}),Y.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[Y.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),Y.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}`})]})]})})},r3i=t=>{const e=$.useRef(null),n=Od(o=>o.recentEvents);$.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 s3i=Object.defineProperty,M2=(t,e)=>s3i(t,"name",{value:e,configurable:!0}),HYe="Dialog",[Iin,Cin]=wx(HYe),[a3i,jb]=Iin(HYe),OYe=M2(t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=$.useRef(null),A=$.useRef(null),[c,l]=Cb({prop:o,defaultProp:i??!1,onChange:r,caller:HYe}),[g,u]=$.useState(0),[h,d]=$.useState(0);return Y.jsx(a3i,{scope:e,triggerRef:a,contentRef:A,contentId:bp(),titleId:bp(),descriptionId:bp(),titlePresent:g>0,descriptionPresent:h>0,setTitleCount:u,setDescriptionCount:d,open:c,onOpenChange:l,onOpenToggle:$.useCallback(()=>l(m=>!m),[l]),modal:s,children:n})},"Dialog"),A3i="DialogTrigger",c3i=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(A3i,o),s=DA(n,r.triggerRef);return Y.jsx(ha.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.open?r.contentId:void 0,"data-state":$de(r.open),...i,ref:s,onClick:or(e.onClick,r.onOpenToggle)})},"DialogTrigger")),yin="DialogPortal",[l3i,xin]=Iin(yin,{forceMount:void 0}),GYe=M2(t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=jb(yin,e);return Y.jsx(l3i,{scope:e,forceMount:n,children:$.Children.map(o,s=>Y.jsx(A2,{present:n||r.open,children:Y.jsx(Hue,{asChild:!0,container:i,children:s})}))})},"DialogPortal"),UYe="DialogOverlay",qde=$.forwardRef(M2(function(e,n){const o=xin(UYe,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=jb(UYe,e.__scopeDialog);return s.modal?Y.jsx(A2,{present:i||s.open,children:Y.jsx(u3i,{...r,ref:n})}):null},"DialogOverlay")),g3i=Ib("DialogOverlay.RemoveScroll"),u3i=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(UYe,o),s=aZt(),a=DA(n,s);return Y.jsx(Dj,{as:g3i,allowPinchZoom:!0,shards:[r.contentRef],children:Y.jsx(ha.div,{"data-state":$de(r.open),...i,ref:a,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),gq="DialogContent",Xde=$.forwardRef(M2(function(e,n){const o=xin(gq,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=jb(gq,e.__scopeDialog);return Y.jsx(A2,{present:i||s.open,children:s.modal?Y.jsx(d3i,{...r,ref:n}):Y.jsx(h3i,{...r,ref:n})})},"DialogContent")),d3i=$.forwardRef(M2(function(e,n){const o=jb(gq,e.__scopeDialog),i=$.useRef(null),r=DA(n,o.contentRef,i);return $.useEffect(()=>{const s=i.current;if(s)return Uue(s)},[]),Y.jsx(Ein,{...e,ref:r,trapFocus:o.open,disableOutsidePointerEvents:o.open,onCloseAutoFocus:or(e.onCloseAutoFocus,s=>{s.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:or(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,A=a.button===0&&a.ctrlKey===!0;(a.button===2||A)&&s.preventDefault()}),onFocusOutside:or(e.onFocusOutside,s=>s.preventDefault())})},"DialogContentModal")),h3i=$.forwardRef(M2(function(e,n){const o=jb(gq,e.__scopeDialog),i=$.useRef(!1),r=$.useRef(!1);return Y.jsx(Ein,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{e.onCloseAutoFocus?.(s),s.defaultPrevented||(i.current||o.triggerRef.current?.focus(),s.preventDefault()),i.current=!1,r.current=!1},onInteractOutside:s=>{e.onInteractOutside?.(s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const a=s.target;o.triggerRef.current?.contains(a)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&r.current&&s.preventDefault()}})},"DialogContentNonModal")),Ein=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,trapFocus:i,onOpenAutoFocus:r,onCloseAutoFocus:s,...a}=e,A=jb(gq,o);return CO(),Y.jsx(Y.Fragment,{children:Y.jsx(Bue,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:r,onUnmountAutoFocus:s,children:Y.jsx(Qj,{role:"dialog",id:A.contentId,"aria-describedby":A.descriptionPresent?A.descriptionId:void 0,"aria-labelledby":A.titlePresent?A.titleId:void 0,"data-state":$de(A.open),...a,ref:n,deferPointerDownOutside:!0,onDismiss:()=>A.onOpenChange(!1)})})})},"DialogContentImpl")),m3i="DialogTitle",YYe=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(m3i,o),{setTitleCount:s}=r;return K0(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),Y.jsx(ha.h2,{id:r.titleId,...i,ref:n})},"DialogTitle")),p3i="DialogDescription",KYe=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(p3i,o),{setDescriptionCount:s}=r;return K0(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),Y.jsx(ha.p,{id:r.descriptionId,...i,ref:n})},"DialogDescription")),_3i="DialogClose",Bin=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(_3i,o);return Y.jsx(ha.button,{type:"button",...i,ref:n,onClick:or(e.onClick,()=>r.onOpenChange(!1))})},"DialogClose"));function $de(t){return t?"open":"closed"}M2($de,"getState");var f3i=Object.defineProperty,Xw=(t,e)=>f3i(t,"name",{value:e,configurable:!0}),I3i="AlertDialog",[C3i,nXi]=wx(I3i,[Cin]),$w=Cin(),y3i=Xw(t=>{const{__scopeAlertDialog:e,...n}=t,o=$w(e);return Y.jsx(OYe,{...o,...n,modal:!0})},"AlertDialog");$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(c3i,{...r,...i,ref:n})},"AlertDialogTrigger"));var x3i=Xw(t=>{const{__scopeAlertDialog:e,...n}=t,o=$w(e);return Y.jsx(GYe,{...o,...n})},"AlertDialogPortal"),E3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(qde,{...r,...i,ref:n})},"AlertDialogOverlay")),B3i="AlertDialogContent",[S3i,b3i]=C3i(B3i),Q3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=$w(o),a=$.useRef(null),A=DA(n,a),c=$.useRef(null);return Y.jsx(S3i,{scope:o,cancelRef:c,children:Y.jsx(Xde,{role:"alertdialog",...s,...r,ref:A,onOpenAutoFocus:or(r.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),v3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(YYe,{...r,...i,ref:n})},"AlertDialogTitle")),P3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(KYe,{...r,...i,ref:n})},"AlertDialogDescription")),w3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(Bin,{...r,...i,ref:n})},"AlertDialogAction")),D3i="AlertDialogCancel",M3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=b3i(D3i,o),s=$w(o),a=DA(n,r);return Y.jsx(Bin,{...s,...i,ref:a})},"AlertDialogCancel")),R3i=y3i,N3i=x3i,Sin=E3i,bin=Q3i,Qin=w3i,vin=M3i,Pin=v3i,win=P3i;const Din=R3i,T3i=N3i,Min=$.forwardRef(({className:t,...e},n)=>Y.jsx(Sin,{className:Mi("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}));Min.displayName=Sin.displayName;const zYe=$.forwardRef(({className:t,...e},n)=>Y.jsxs(T3i,{children:[Y.jsx(Min,{}),Y.jsx(bin,{ref:n,className:Mi("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})]}));zYe.displayName=bin.displayName;const VYe=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});VYe.displayName="AlertDialogHeader";const JYe=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});JYe.displayName="AlertDialogFooter";const WYe=$.forwardRef(({className:t,...e},n)=>Y.jsx(Pin,{ref:n,className:Mi("rf-text-lg rf-font-semibold",t),...e}));WYe.displayName=Pin.displayName;const jYe=$.forwardRef(({className:t,...e},n)=>Y.jsx(win,{ref:n,className:Mi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));jYe.displayName=win.displayName;const k3i=$.forwardRef(({className:t,...e},n)=>Y.jsx(Qin,{ref:n,className:Mi(fO(),t),...e}));k3i.displayName=Qin.displayName;const qYe=$.forwardRef(({className:t,...e},n)=>Y.jsx(vin,{ref:n,className:Mi(fO({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));qYe.displayName=vin.displayName;var F3i=Object.defineProperty,Zw=(t,e)=>F3i(t,"name",{value:e,configurable:!0}),XYe="Checkbox",[L3i,oXi]=wx(XYe),[H3i,$Ye]=L3i(XYe);function Rin(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:A,required:c,value:l="on",internal_do_not_use_render:g}=t,[u,h]=Cb({prop:n,defaultProp:i??!1,onChange:A,caller:XYe}),[d,m]=$.useState(null),[p,_]=$.useState(null),f=$.useRef(!1),[I,C]=$.useReducer(E=>E+1,0),y=d?!!s||!!d.closest("form"):!0,x={checked:u,disabled:r,setChecked:h,control:d,setControl:m,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:f,userInteractionCount:I,onUserInteraction:C,required:c,defaultChecked:eD(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:_};return Y.jsx(H3i,{scope:e,...x,children:Tin(g)?g(x):o})}Zw(Rin,"CheckboxProvider");var O3i="CheckboxTrigger",G3i=$.forwardRef(Zw(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:A,checked:c,required:l,setControl:g,setChecked:u,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:m,bubbleInput:p}=$Ye(O3i,e),_=DA(r,g),f=$.useRef(c);return $.useEffect(()=>{const I=s?.form;if(I){const C=Zw(()=>u(f.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,u]),Y.jsx(ha.button,{type:"button",role:"checkbox","aria-checked":eD(c)?"mixed":c,"aria-required":l,"data-state":ZYe(c),"data-disabled":A?"":void 0,disabled:A,value:a,...i,ref:_,onKeyDown:or(n,I=>{I.key==="Enter"&&I.preventDefault()}),onClick:or(o,I=>{d(),u(C=>eD(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),Nin=$.forwardRef(Zw(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:A,value:c,onCheckedChange:l,form:g,...u}=e;return Y.jsx(Rin,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:A,required:a,onCheckedChange:l,name:i,form:g,value:c,internal_do_not_use_render:({isFormControl:h})=>Y.jsxs(Y.Fragment,{children:[Y.jsx(G3i,{...u,ref:n,__scopeCheckbox:o}),h&&Y.jsx(z3i,{__scopeCheckbox:o})]})})},"Checkbox")),U3i="CheckboxIndicator",Y3i=$.forwardRef(Zw(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=$Ye(U3i,o);return Y.jsx(A2,{present:i||eD(s.checked)||s.checked===!0,children:Y.jsx(ha.span,{"data-state":ZYe(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),K3i="CheckboxBubbleInput",z3i=$.forwardRef(Zw(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:A,defaultChecked:c,required:l,disabled:g,name:u,value:h,form:d,bubbleInput:m,setBubbleInput:p}=$Ye(K3i,e),_=DA(i,p),f=sUe(r),I=$.useRef(!1),C=$.useRef(A),y=$.useRef(a);$.useEffect(()=>{const E=m;if(!E)return;const S=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(S,"checked").set,M=a!==y.current;y.current=a;const N=C.current!==A;C.current=A;const k=!(M&&s.current);if(N&&v){I.current=!M;const L=new Event("click",{bubbles:k});E.indeterminate=eD(A),v.call(E,eD(A)?!1:A),E.dispatchEvent(L),I.current=!1}},[m,A,s,a]);const x=$.useRef(eD(A)?!1:A);return Y.jsx(ha.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??x.current,required:l,disabled:g,name:u,value:h,form:d,...o,tabIndex:-1,ref:_,onClick:or(n,E=>{I.current&&E.stopPropagation()}),style:{...o.style,...f,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function Tin(t){return typeof t=="function"}Zw(Tin,"isFunction");function eD(t){return t==="indeterminate"}Zw(eD,"isIndeterminate");function ZYe(t){return eD(t)?"indeterminate":t?"checked":"unchecked"}Zw(ZYe,"getState");const uq=$.forwardRef(({className:t,...e},n)=>Y.jsx(Nin,{ref:n,className:Mi("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:Y.jsx(Y3i,{className:Mi("rf-flex rf-items-center rf-justify-center rf-text-current"),children:Y.jsx(Uw,{className:"rf-h-4 rf-w-4"})})}));uq.displayName=Nin.displayName;const IR=OYe,V3i=GYe,kin=$.forwardRef(({className:t,...e},n)=>Y.jsx(qde,{className:Mi("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}));kin.displayName=qde.displayName;const J4=$.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>Y.jsxs(V3i,{children:[Y.jsx(kin,{className:Mi(n?"":"rf-hidden")}),Y.jsx(Xde,{ref:i,className:Mi("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})]}));J4.displayName=Xde.displayName;const W4=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});W4.displayName="DialogHeader";const zO=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});zO.displayName="DialogFooter";const j4=$.forwardRef(({className:t,...e},n)=>Y.jsx(YYe,{ref:n,className:Mi("rf-text-lg rf-font-semibold",t),...e}));j4.displayName=YYe.displayName;const CR=$.forwardRef(({className:t,...e},n)=>Y.jsx(KYe,{ref:n,className:Mi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));CR.displayName=KYe.displayName;const Zde={"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"}},J3i="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let eKe=null;const tKe=async()=>(eKe||(eKe=import(J3i)),eKe),W3i=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??FC}/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}})},j3i=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??[]},q3i=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}),Fin=async(t,e)=>{const{fetchEasyEDAComponent:n}=await tKe();return n(t,{fetch:W3i(e),includeModelMetadata:e?.includeModelMetadata})},X3i=async(t,e)=>{const{convertRawEasyToTsx:n}=await tKe(),o=await Fin(t,e);return n({rawEasy:o})},$3i=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await tKe(),i=await Fin(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function q4(t){return Array.isArray?Array.isArray(t):Hin(t)==="[object Array]"}function Z3i(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 nKe(t){return t==null?"":Z3i(t)}function zC(t){return typeof t=="string"}function ehe(t){return typeof t=="number"}function evi(t){return t===!0||t===!1||tvi(t)&&Hin(t)=="[object Boolean]"}function Lin(t){return typeof t=="object"}function tvi(t){return Lin(t)&&t!==null}function R2(t){return t!=null}function the(t){return!t.trim().length}function Hin(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const nvi="Incorrect 'index' type",oKe="Invalid doc index: must be a non-negative integer within the bounds of the docs array",ovi=t=>`Invalid value for key ${t}`,ivi=t=>`Pattern length exceeds max of ${t}.`,rvi=t=>`Missing ${t} property in key`,svi=t=>`Property 'weight' in key '${t}' must be a positive integer`,avi="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.",Oin=Object.prototype.hasOwnProperty;var Avi=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=Gin(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 Gin(t){let e=null,n=null,o=null,i=1,r=null;if(zC(t)||q4(t))o=t,e=Uin(t),n=nhe(t);else{if(!Oin.call(t,"name"))throw new Error(rvi("name"));const s=t.name;if(o=s,Oin.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(svi(nhe(s)));e=Uin(s),n=nhe(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function Uin(t){return q4(t)?t:t.split(".")}function nhe(t){return q4(t)?t.join("."):t}function cvi(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(R2(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!R2(c))return;if(a===s.length-1&&(zC(c)||ehe(c)||evi(c)||typeof c=="bigint"))n.push(A!==void 0?{v:nKe(c),i:A}:nKe(c));else if(q4(c)){o=!0;for(let l=0,g=c.length;l<g;l+=1)i(c[l],s,a+1,l)}else s.length&&i(c,s,a+1,A)}};return i(t,zC(e)?e.split("."):e,0),o?n:n[0]}const ga=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:cvi,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function lvi(t){return t>=9&&t<=13||t===32||t===160}function gvi(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let A=0;A<i.length;A++)lvi(i.charCodeAt(A))?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 iKe=class{constructor({getFn:t=ga.getFn,fieldNormWeight:e=ga.fieldNormWeight}={}){this.norm=gvi(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(oKe);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(oKe);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!R2(t)||the(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(R2(s)){if(q4(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(R2(l)){if(zC(l)){if(!the(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(R2(l.v)){const g=zC(l.v)?l.v:nKe(l.v);if(!the(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(zC(s)&&!the(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 Yin(t,e,{getFn:n=ga.getFn,fieldNormWeight:o=ga.fieldNormWeight}={}){const i=new iKe({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(Gin)),i.setSources(e),i.create(),i}function uvi(t,{getFn:e=ga.getFn,fieldNormWeight:n=ga.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new iKe({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function dvi(t=[],e=ga.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 hvi(t,e,n,{location:o=ga.location,distance:i=ga.distance,threshold:r=ga.threshold,findAllMatches:s=ga.findAllMatches,minMatchCharLength:a=ga.minMatchCharLength,includeMatches:A=ga.includeMatches,ignoreLocation:c=ga.ignoreLocation}={}){if(e.length>32)throw new Error(ivi(32));const l=e.length,g=t.length,u=Math.max(0,Math.min(o,g));let h=r,d=u;const m=(b,v)=>{const M=b/l;if(c)return M;const N=Math.abs(u-v);return i?M+N/i:N?1:M},p=a>1||A,_=p?Array(g):[];let f;for(;(f=t.indexOf(e,d))>-1;){const b=m(0,f);if(h=Math.min(b,h),d=f+l,p){let v=0;for(;v<l;)_[f+v]=1,v+=1}}d=-1;let I=[],C=1,y=0,x=l+g;const E=1<<l-1;for(let b=0;b<l;b+=1){let v=0,M=x;for(;v<M;)m(b,u+M)<=h?v=M:x=M,M=Math.floor((x-v)/2+v);x=M;let N=Math.max(1,u-M+1);const k=s?g:Math.min(u+M,g)+l,L=Array(k+2);L[k+1]=(1<<b)-1;for(let O=k;O>=N;O-=1){const G=O-1,V=n[t[G]];if(L[O]=(L[O+1]<<1|1)&V,b&&(L[O]|=(I[O+1]|I[O])<<1|1|I[O+1]),L[O]&E&&(C=m(b,G),C<=h)){if(h=C,d=G,y=b,d<=u)break;N=Math.max(1,2*u-d)}}if(m(b+1,u)>h)break;I=L}if(p&&d>=0){const b=Math.min(g-1,d+l-1+y);for(let v=d;v<=b;v+=1)n[t[v]]&&(_[v]=1)}const S={isMatch:d>=0,score:Math.max(.001,C)};if(p){const b=dvi(_,a);b.length?A&&(S.indices=b):S.isMatch=!1}return S}function mvi(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 rKe(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 Kin={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},pvi=new RegExp("["+Object.keys(Kin).join("")+"]","g"),dq=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(pvi,e=>Kin[e]):t=>t;var sKe=class{constructor(t,{location:e=ga.location,threshold:n=ga.threshold,distance:o=ga.distance,includeMatches:i=ga.includeMatches,findAllMatches:r=ga.findAllMatches,minMatchCharLength:s=ga.minMatchCharLength,isCaseSensitive:a=ga.isCaseSensitive,ignoreDiacritics:A=ga.ignoreDiacritics,ignoreLocation:c=ga.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:A,ignoreLocation:c},t=a?t:t.toLowerCase(),t=A?dq(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:mvi(u),startIndex:h})},g=this.pattern.length;if(g>32){let u=0;const h=g%32,d=g-h;for(;u<d;)l(this.pattern.substr(u,32),u),u+=32;if(h){const m=g-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?dq(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:A,ignoreLocation:c}=this.options,l=[];let g=0,u=!1;this.chunks.forEach(({pattern:d,alphabet:m,startIndex:p})=>{const{isMatch:_,score:f,indices:I}=hvi(t,d,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,includeMatches:o,ignoreLocation:c});_&&(u=!0),g+=f,_&&I&&l.push(...I)});const h={isMatch:u,score:u?g/this.chunks.length:1};return u&&o&&(h.indices=rKe(l)),h}};const _vi=new Set(["fuzzy","include"]);function fvi(t){return t.startsWith("inverse")}const aKe=[{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 sKe(t,{location:e.location??ga.location,threshold:e.threshold??ga.threshold,distance:e.distance??ga.distance,includeMatches:e.includeMatches??ga.includeMatches,findAllMatches:e.findAllMatches??ga.findAllMatches,minMatchCharLength:e.minMatchCharLength??ga.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??ga.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??ga.ignoreDiacritics,ignoreLocation:e.ignoreLocation??ga.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],zin=aKe.length,Ivi="\0",Cvi="|";function yvi(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 Vin(t,e){const n=t.match(e);return n?n[1]:null}function xvi(t,e={}){return t.replace(/\\\|/g,Ivi).split(Cvi).map(n=>{const o=yvi(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 A=!1,c=-1;for(;!A&&++c<zin;){const l=aKe[c],g=Vin(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<zin;){const l=aKe[c],g=Vin(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var Evi=class{constructor(t,{isCaseSensitive:e=ga.isCaseSensitive,ignoreDiacritics:n=ga.ignoreDiacritics,includeMatches:o=ga.includeMatches,minMatchCharLength:i=ga.minMatchCharLength,ignoreLocation:r=ga.ignoreLocation,findAllMatches:s=ga.findAllMatches,location:a=ga.location,threshold:A=ga.threshold,distance:c=ga.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:A,distance:c},t=e?t:t.toLowerCase(),t=n?dq(t):t,this.pattern=t,this.query=xvi(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?dq(t):t;let r=0;const s=[];let a=0,A=!1;for(let c=0,l=e.length;c<l;c+=1){const g=e[c];s.length=0,r=0,A=!1;for(let u=0,h=g.length;u<h;u+=1){const d=g[u],{isMatch:m,indices:p,score:_}=d.search(t);if(m)r+=1,a+=_,fvi(d.type)&&(A=!0),n&&(_vi.has(d.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,A=!1;break}}if(r){const u={isMatch:!0,score:a/r};return A&&(u.hasInverse=!0),n&&(u.indices=rKe(s)),u}}return{isMatch:!1,score:1}}};const AKe=[];function cKe(...t){AKe.push(...t)}function ohe(t,e){for(let n=0,o=AKe.length;n<o;n+=1){const i=AKe[n];if(i.condition(t,e))return new i(t,e)}return new sKe(t,e)}const ihe={AND:"$and",OR:"$or"},lKe={PATH:"$path",PATTERN:"$val"},gKe=t=>!!(t[ihe.AND]||t[ihe.OR]),Bvi=t=>!!t[lKe.PATH],Svi=t=>!q4(t)&&Lin(t)&&!gKe(t),Jin=t=>({[ihe.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Win(t,e,{auto:n=!0}={}){const o=i=>{if(zC(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=ohe(i,e)),A}const r=Object.keys(i),s=Bvi(i);if(!s&&r.length>1&&!gKe(i))return o(Jin(i));if(Svi(i)){const A=s?i[lKe.PATH]:r[0],c=s?i[lKe.PATTERN]:i[A];if(!zC(c))throw new Error(ovi(A));const l={keyId:nhe(A),pattern:c};return n&&(l.searcher=ohe(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];q4(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return gKe(t)||(t=Jin(t)),o(t)}function uKe(t,{ignoreFieldNorm:e=ga.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 bvi(t,{ignoreFieldNorm:e=ga.ignoreFieldNorm}){t.forEach(n=>{n.score=uKe(n.matches,{ignoreFieldNorm:e})})}var Qvi=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 vvi(t){const e=[];return t.matches.forEach(n=>{if(!R2(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 Pvi(t,e,{includeMatches:n=ga.includeMatches,includeScore:o=ga.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=vvi(i)),o&&(s.score=i.score),s})}const wvi=/[\p{L}\p{M}\p{N}_]+/gu,jin=new WeakSet;function Dvi(t){jin.has(t)||(jin.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 Mvi(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||Dvi(t),e=>e.match(t)||[]):e=>e.match(wvi)||[]}function dKe({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=Mvi(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=dq(i)),o(i)}}}var Rvi=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=dKe({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 sKe(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 c=0;c<this.termSearchers.length;c++){const l=this.termSearchers[c].searchIn(t),g=this.idfWeights[c];o+=g,l.isMatch&&(i++,n+=g*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<c:s.add(c)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,A={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(A.indices=rKe(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function hKe(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 qin(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){hKe(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const A=s[a];if(A)if(Array.isArray(A))for(const c of A)hKe(t,c.v,i,o);else hKe(t,A.v,i,o)}}function Nvi(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)qin(o,i,e,n);return o}function Tvi(t,e,n,o){qin(t,e,n,o)}function kvi(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 Xin(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,A)=>a-A);for(const a of n)kvi(t,a);const o=a=>{let A=0,c=n.length;for(;A<c;){const l=A+c>>>1;n[l]<a?A=l+1:c=l}return a-A},i=n[0],r=new Map;for(const[a,A]of t.docFieldCount)r.set(a>i?o(a):a,A);t.docFieldCount=r;const s=new Map;for(const[a,A]of t.docTermFieldHits)s.set(a>i?o(a):a,A);t.docTermFieldHits=s}var X4=class{constructor(t,e,n){this.options={...ga,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Avi(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=ohe(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 iKe))throw new Error(nvi);if(this._myIndex=e||Yin(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=dKe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Nvi(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!R2(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=dKe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});Tvi(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&&Xin(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(oKe);this._invertedIndex&&Xin(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 u=this._docs.map((h,d)=>({item:h,refIndex:d}));return ehe(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&ehe(n)&&n>0&&zC(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new Qvi(n,l);zC(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=zC(t)?zC(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),bvi(g,{ignoreFieldNorm:a}),r&&g.sort(zC(t)?l:c),ehe(n)&&n>-1&&(g=g.slice(0,n));return Pvi(g,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:A,n:c})=>{if(!R2(a))return;const l=o.searchIn(a);if(l.isMatch){const g={score:l.score,value:a,norm:c,indices:l.indices};i&&(g.matchedMask=l.matchedMask,g.matchedTerms=l.matchedTerms,g.termCount=l.termCount);const u=[g];if(!i||this._coversAllTokens(u)){const h={item:a,idx:A,matches:u};e?(h.score=uKe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=Win(t,this.options),n=this._normalizedKeys(),o=(a,A,c)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let m;return h===null?(m=[],n.forEach((p,_)=>{m.push(...this._findMatches({key:p,value:A[_],searcher:d}))})):m=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(A,h),searcher:d}),m&&m.length?[{idx:c,item:A,matches:m}]:[]}const{children:l,operator:g}=a,u=[];for(let h=0,d=l.length;h<d;h+=1){const m=l[h],p=o(m,A,c);if(p.length)u.push(...p);else if(g===ihe.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(R2(a)){const c=o(e,a,A);c.length&&(r.has(A)||(r.set(A,{idx:A,item:a,matches:[]}),s.push(r.get(A))),c.forEach(({matches:l})=>{r.get(A).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(({$:A,i:c})=>{if(!R2(A))return;const l=[];let g=!1,u=!1;if(s.forEach((h,d)=>{const m=this._findMatches({key:h,value:A[d],searcher:o});m.length?(l.push(...m),m[0].hasInverse&&(u=!0)):g=!0}),!(u&&g)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:c,item:A,matches:l};e?(h.score=uKe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!R2(e))return[];const o=[];if(q4(e))e.forEach(({v:i,i:r,n:s})=>{if(!R2(i))return;const a=n.searchIn(i);if(a.isMatch){const A={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(A.matchedMask=a.matchedMask,A.matchedTerms=a.matchedTerms,A.termCount=a.termCount),o.push(A)}});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}};X4.version="7.5.0",X4.createIndex=Yin,X4.parseIndex=uvi,X4.config=ga,X4.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(avi);return ohe(t,{...ga,...n}).searchIn(e)},X4.parseQuery=Win,cKe(Evi),cKe(Rvi),X4.use=function(...t){t.forEach(e=>cKe(e))};var Fvi=X4;const Lvi="https://kicad-mod-cache.tscircuit.com";let mKe=null,hq=null,pKe=null;const Hvi=async()=>mKe||hq||(hq=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(mKe=t,hq=null,t)),hq),Ovi=async(t,e=20)=>{const n=await Hvi();return pKe||(pKe=new Fvi(n)),pKe.search(t).slice(0,e).map(o=>o.item)},Gvi=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},Uvi=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),Yvi=async t=>{const e=await fetch(`${Lvi}/${Uvi(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await S2("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},$in=t=>t?.source==="jlcpcb"||t?.source==="kicad",Kvi=async(t,e)=>{if(t.source==="jlcpcb")return $3i(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return Yvi(t.footprint.path);throw new Error("Footprint preview is not available for this source")},zvi=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=$.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[Y.jsxs("div",{className:"rf-relative rf-flex-grow",children:[Y.jsx(LGe,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),Y.jsx(UUe,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),Y.jsx(Xa,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):Y.jsxs(Y.Fragment,{children:[Y.jsx(LGe,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),Y.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},Vvi=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Jvi=t=>Vvi.format(t),Zin=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"}},Wvi=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}},jvi=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}},qvi=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}},Xvi=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?Zin(e):null;return Y.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=Zin(r),a=i===s,A=Wvi(r),c=jvi(r),l=qvi(r),g=r.source==="jlcpcb"?r.component.stock:null,u=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return Y.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:[Y.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[Y.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[Y.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:[A,r.source==="jlcpcb"&&h!=null&&Y.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&&Y.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&&Y.jsx(E0i,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?Y.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[g.toLocaleString()," in stock"]}):null]}),Y.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?Y.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),Y.jsxs("div",{children:[r.source==="tscircuit.com"&&o?Y.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:Y.jsx(Xa,{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"&&g!=null?Y.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:[g.toLocaleString()," in stock"]}):null,u!=null&&Y.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:Jvi(u)})]})]},s)})})},$vi=({circuitJson:t,error:e,isLoading:n,height:o})=>Y.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?Y.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:[Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?Y.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:Y.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[Y.jsx(FGe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),Y.jsx("span",{children:e})]})}):t?Y.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:Y.jsx(PYe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):Y.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"})}),ern={importComponentDialog:101,importComponentDetailsDialog:102},Zvi=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:A})=>{const c=t?.package??null,l=c?.latest_pcb_preview_image_url,g=c?.latest_sch_preview_image_url,u=c?.latest_cad_preview_image_url,h=c?.unscoped_name?.split("/").pop()??c?.unscoped_name,d=c?.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 Y.jsx(IR,{open:e,onOpenChange:n,children:Y.jsxs(J4,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:ern.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:[Y.jsx(W4,{className:"rf-pb-4 rf-border-b",children:Y.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:Y.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Y.jsx(j4,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),Y.jsx(CR,{children:c?.description})]})})}),Y.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?Y.jsxs("div",{children:[Y.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),Y.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?Y.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&Y.jsx(Y.Fragment,{children:Y.jsxs("div",{children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),Y.jsxs(p4e,{value:r,onValueChange:_=>s(_),children:[Y.jsxs(sce,{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&&Y.jsx(Y3,{value:"pcb",children:"PCB"}),g&&Y.jsx(Y3,{value:"schematic",children:"Schematic"}),u&&Y.jsx(Y3,{value:"3d",children:"3D"})]}),Y.jsxs("div",{className:"rf-mt-4",children:[Y.jsx(BI,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?Y.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}),Y.jsx(BI,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?Y.jsx("img",{src:g,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),Y.jsx(BI,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?Y.jsx("img",{src:u,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?Y.jsxs("section",{children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),Y.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:Y.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?Y.jsxs("section",{children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),Y.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:Y.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?Y.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),Y.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),Y.jsxs(zO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[Y.jsx("div",{className:"rf-flex-1",children:p?Y.jsxs(Xa,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[Y.jsx(p0i,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),Y.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[Y.jsx(Xa,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),Y.jsx(Xa,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},ePi=()=>{const[t,e]=$.useState(null),[n,o]=$.useState(!1),i=$.useCallback(async(s,a)=>{o(!0);try{const A=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!A.ok)throw new Error(`Failed to load package details: ${A.status}`);const c=await A.json();e(c.package??null)}catch(A){console.error("Failed to fetch package details",A),e(null)}finally{o(!1)}},[]),r=$.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},tPi=(t,e)=>{const[n,o]=$.useState({circuitJson:null,error:null,isLoading:!1});return $.useEffect(()=>{if(!t||!$in(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),Kvi(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},nPi=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??[]},oPi=({sessionToken:t})=>{const[e,n]=$.useState([]),[o,i]=$.useState(!1),[r,s]=$.useState(null),[a,A]=$.useState(!1),c=$.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await nPi(u,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),A(!0)}},[t]),l=$.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},iPi=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}}},trn=(t,e)=>{const n=iPi(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},rPi=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},sPi=()=>{const[t,e]=$.useState([]),[n,o]=$.useState(!1),[i,r]=$.useState(null),[s,a]=$.useState(!1),A=$.useCallback(async l=>{const g=rPi(l);if(!g)return[];o(!0),r(null);try{const u=await j3i(g,10),h=trn(l,u.map(d=>({source:"jlcpcb",component:q3i(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=trn(l,[]);return e(h),r(h.length>0?null:u instanceof Error?u.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),c=$.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},aPi=()=>{const[t,e]=$.useState([]),[n,o]=$.useState(!1),[i,r]=$.useState(null),[s,a]=$.useState(!1),A=$.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await Ovi(g,20)).map(d=>({source:"kicad",footprint:Gvi(d)}));return e(h),h}catch(u){return console.error("Error searching KiCad footprints",u),e([]),r(u instanceof Error?u.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),c=$.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},APi=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},cPi=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{Aq();const A=$.useMemo(()=>APi({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=$.useState(A[0]??"tscircuit.com"),[h,d]=$.useState(""),[m,p]=$.useState(null),{results:_,isSearching:f,error:I,hasSearched:C,search:y,reset:x}=oPi({sessionToken:a}),{results:E,isSearching:S,error:b,hasSearched:v,search:M,reset:N}=sPi(),{results:k,isSearching:L,error:O,hasSearched:G,search:V,reset:K}=aPi(),{details:Z,isLoading:te,fetchDetails:ee,reset:X}=ePi(),[ie,se]=$.useState(null),[Ae,de]=$.useState(!1),[me,ye]=$.useState("pcb"),[le,Ce]=$.useState(null),[_e,Qe]=$.useState(!1),Te=$.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Se,error:he,isLoading:Le}=tPi(m,Te),Me=$in(m);$.useEffect(()=>{Ce(null)},[m]);const Ne=$.useCallback(()=>{x(),N(),K(),p(null)},[N,K,x]);$.useEffect(()=>{t||(Ne(),d(""),de(!1),se(null),Ce(null))},[t,Ne]),$.useEffect(()=>{d(""),p(null),g==="tscircuit.com"?x():g==="jlcpcb"?N():g==="kicad"&&K()},[g,N,K,x]);const Oe=Fe=>{p(Fe),se(Fe),ye("pcb"),de(!0),X();const je=Fe.package.org_owner_tscircuit_handle,it=Fe.package.unscoped_name;if(je&&it){const At=it.split("/").pop()??it;ee(je,At)}},De=async()=>{h.trim()&&(p(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await M(h):g==="kicad"&&await V(h))},Be=async Fe=>{try{if(Ce(null),Qe(!0),Fe.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:Fe,footprint:Fe.footprint.qualifiedName})}else if(Fe.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const je=await X3i(Fe.component.partNumber,{headers:n,apiBase:s});await r({result:Fe,tsx:je})}else if(Fe.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const je=Fe.package.org_owner_tscircuit_handle,it=Fe.package.unscoped_name;if(!je||!it)throw new Error("Missing package metadata");const At=it.split("/").pop()??it,Rt=`@tsci/${je}.${At}`;await i({result:Fe,fullPackageName:Rt})}return!0}catch(je){return console.error("Failed to import component",je),Ce(je instanceof Error?je.message:"Failed to import component"),!1}finally{Qe(!1)}};let ke=[],be=!1,Ye=null,We=!1;g==="tscircuit.com"?(ke=_,be=f,Ye=I,We=C):g==="jlcpcb"?(ke=E,be=S,Ye=b,We=v):g==="kicad"&&(ke=k,be=L,Ye=O,We=G);const tt=async()=>{if(!m)return;await Be(m)&&(e(),Ne(),d(""))},ct=Fe=>{Fe||e()},at=Fe=>{de(Fe),Fe||se(null)};return Y.jsxs(IR,{open:t,onOpenChange:ct,children:[Y.jsxs(J4,{style:{width:"calc(100vw - 2rem)",maxWidth:Me?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:ern.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[Y.jsxs(W4,{children:[Y.jsxs(j4,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Zde[g].label:""," ","Component"]}),Y.jsx(CR,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?Y.jsxs(p4e,{value:g,onValueChange:Fe=>u(Fe),className:"rf-min-w-0 rf-w-full",children:[!l&&Y.jsx(sce,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(Fe=>Y.jsx(Y3,{value:Fe,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Zde[Fe].label},Fe))}),Y.jsxs("div",{className:"rf-min-w-0",style:Me?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[Y.jsxs("div",{className:"rf-min-w-0",children:[Y.jsx(zvi,{query:h,placeholder:Zde[g].placeholder,isSearching:be,onQueryChange:d,onSubmit:De}),Y.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:be?Y.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[Y.jsx(x2,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),Y.jsx("p",{children:"Searching..."})]}):ke.length>0?Y.jsx(Xvi,{results:ke,selected:m,onSelect:p,onShowDetails:g==="tscircuit.com"?Oe:void 0}):Y.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:Ye?`Error: ${Ye}`:We?Zde[g].emptyMessage:"Enter a search term to find components"})})]}),Me?Y.jsx("div",{className:"rf-mt-4",children:Y.jsx($vi,{circuitJson:Se,error:he,isLoading:Le,height:325})}):null]})]}):null,le?Y.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:le}):null,Y.jsxs(zO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[Y.jsx(Xa,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),Y.jsx(Xa,{onClick:tt,disabled:!m||_e,className:"rf-order-1 sm:rf-order-2",children:_e?Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),Y.jsx(Zvi,{packageResult:ie,isOpen:Ae,onOpenChange:at,isLoading:te,details:Z,previewTab:me,onPreviewTabChange:Fe=>ye(Fe),isSubmitting:_e,onImport:()=>{ie&&Be(ie).then(Fe=>{Fe&&(de(!1),e(),Ne(),d(""))})}})]})},lPi=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},nrn=t=>{const e=Od(s=>s.pushEvent),n=Od(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await Js.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${c}"`,success:`Install requested for "${c}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await Js.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 c=`imports/${lPi(a)}.tsx`;await Js.promise(n(c,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${c}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return Y.jsx(cPi,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};nrn.displayName="ImportComponentDialogForCli";const gPi=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>TJi),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},uPi=async({circuitJson:t,projectName:e})=>{await Js.promise((async()=>{const n=await gPi({circuitJson:t,projectName:e});D2(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 _Ke={exports:{}},orn;function dPi(){return orn||(orn=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,g){if(!r[l]){if(!i[l]){var u=typeof uP=="function"&&uP;if(!g&&u)return u(l,!0);if(A)return A(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 A=typeof uP=="function"&&uP,c=0;c<s.length;c++)a(s[c]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(c){for(var l,g,u,h,d,m,p,_=[],f=0,I=c.length,C=I,y=s.getTypeOf(c)!=="string";f<c.length;)C=I-f,u=y?(l=c[f++],g=f<I?c[f++]:0,f<I?c[f++]:0):(l=c.charCodeAt(f++),g=f<I?c.charCodeAt(f++):0,f<I?c.charCodeAt(f++):0),h=l>>2,d=(3&l)<<4|g>>4,m=1<C?(15&g)<<2|u>>6:64,p=2<C?63&u:64,_.push(A.charAt(h)+A.charAt(d)+A.charAt(m)+A.charAt(p));return _.join("")},r.decode=function(c){var l,g,u,h,d,m,p=0,_=0,f="data:";if(c.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var I,C=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===A.charAt(64)&&C--,c.charAt(c.length-2)===A.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<c.length;)l=A.indexOf(c.charAt(p++))<<2|(h=A.indexOf(c.charAt(p++)))>>4,g=(15&h)<<4|(d=A.indexOf(c.charAt(p++)))>>2,u=(3&d)<<6|(m=A.indexOf(c.charAt(p++))),I[_++]=l,d!==64&&(I[_++]=g),m!==64&&(I[_++]=u);return I}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),A=o("./stream/Crc32Probe"),c=o("./stream/DataLengthProbe");function l(g,u,h,d,m){this.compressedSize=g,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=m}l.prototype={getContentWorker:function(){var g=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return g.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),g},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(g,u,h){return g.pipe(new A).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},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 A,c=[],l=0;l<256;l++){A=l;for(var g=0;g<8;g++)A=1&A?3988292384^A>>>1:A>>>1;c[l]=A}return c})();i.exports=function(A,c){return A!==void 0&&A.length?s.getTypeOf(A)!=="string"?(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g[p])];return-1^l})(0|c,A,A.length,0):(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g.charCodeAt(p))];return-1^l})(0|c,A,A.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"),A=o("./utils"),c=o("./stream/GenericWorker"),l=s?"uint8array":"array";function g(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}r.magic="\b\0",A.inherits(g,c),g.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(A.transformTo(l,u.data),!1)},g.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},g.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},g.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},r.compressWorker=function(u){return new g("Deflate",u)},r.uncompressWorker=function(){return new g("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,m){var p,_="";for(p=0;p<m;p++)_+=String.fromCharCode(255&d),d>>>=8;return _}function a(d,m,p,_,f,I){var C,y,x=d.file,E=d.compression,S=I!==l.utf8encode,b=A.transformTo("string",I(x.name)),v=A.transformTo("string",l.utf8encode(x.name)),M=x.comment,N=A.transformTo("string",I(M)),k=A.transformTo("string",l.utf8encode(M)),L=v.length!==x.name.length,O=k.length!==M.length,G="",V="",K="",Z=x.dir,te=x.date,ee={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(ee.crc32=d.crc32,ee.compressedSize=d.compressedSize,ee.uncompressedSize=d.uncompressedSize);var X=0;m&&(X|=8),S||!L&&!O||(X|=2048);var ie=0,se=0;Z&&(ie|=16),f==="UNIX"?(se=798,ie|=(function(de,me){var ye=de;return de||(ye=me?16893:33204),(65535&ye)<<16})(x.unixPermissions,Z)):(se=20,ie|=(function(de){return 63&(de||0)})(x.dosPermissions)),C=te.getUTCHours(),C<<=6,C|=te.getUTCMinutes(),C<<=5,C|=te.getUTCSeconds()/2,y=te.getUTCFullYear()-1980,y<<=4,y|=te.getUTCMonth()+1,y<<=5,y|=te.getUTCDate(),L&&(V=s(1,1)+s(g(b),4)+v,G+="up"+s(V.length,2)+V),O&&(K=s(1,1)+s(g(N),4)+k,G+="uc"+s(K.length,2)+K);var Ae="";return Ae+=`
|
|
5775
|
+
`,g=new Blob([l],{type:"text/plain"}),u=URL.createObjectURL(g),h=document.createElement("a");h.href=u,h.download=`${c}.test.ts`,h.click(),URL.revokeObjectURL(u)}catch(A){alert(`Error generating test.ts for ${t.getSolverName()}: ${A instanceof Error?A.message:String(A)}`)}o(!1)};return Y.jsxs("div",{className:`relative ${e}`,ref:i,children:[Y.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&&Y.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:[Y.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),Y.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Y.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},oin=t=>t.activeSubSolver?[t,...oin(t.activeSubSolver)]:[t],pQi=({solver:t})=>{const e=oin(t);return Y.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>Y.jsxs("div",{className:"flex items-center",children:[o>0&&Y.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Y.jsx(mQi,{solver:n})]},n.getSolverName()))})},_Qi=({solver:t,triggerRender:e,animationSpeed:n=25,renderer:o,onRendererChange:i,onAnimationSpeedChange:r,onDownloadVisualization:s,onSolverStarted:a,onSolverCompleted:A})=>{const[c,l]=$.useReducer(S=>!S,!1),g=$.useRef(void 0),u=$.useRef(null),h="solver-debugger-last-iteration",[d,m]=$.useState(null),p=$.useRef(null),_=$.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"}],[]),f=()=>{const S=Math.max(1,n),b=n<1?Math.round(1/n):1;g.current=setInterval(()=>{if(t.solved||t.failed){g.current&&(clearInterval(g.current),g.current=void 0),l(),e(),A&&t.solved&&A(t);return}for(let v=0;v<b&&!(t.solved||t.failed);v++)t.step();e()},S)},I=()=>{g.current&&(clearInterval(g.current),g.current=void 0)},C=()=>{!t.solved&&!t.failed&&(t.step(),e())},y=()=>{!t.solved&&!t.failed&&(a&&a(t),t.solve(),e(),A&&A(t))},x=()=>{c?(I(),l()):(l(),f())},E=()=>{if(t.solved||t.failed||c)return;u.current===null&&typeof window<"u"&&(u.current=window.localStorage.getItem(h));const S=window.prompt("Step until which iteration?",u.current??`${t.iterations}`);if(S===null)return;u.current=S,typeof window<"u"&&window.localStorage.setItem(h,S);const b=Number(S);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&&A&&A(t)};return $.useEffect(()=>()=>{I()},[]),$.useEffect(()=>{(t.solved||t.failed)&&c&&(I(),l())},[t.solved,t.failed,c]),$.useEffect(()=>{c&&(I(),f())},[n,c]),$.useEffect(()=>{if(typeof document>"u")return;const S=b=>{p.current&&!p.current.contains(b.target)&&m(null)};return document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[]),Y.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Y.jsx("div",{className:"flex items-center",children:Y.jsxs("div",{className:"flex items-center gap-2",ref:p,children:[Y.jsxs("div",{className:"flex h-9 items-center space-x-1 rounded-md border border-slate-200 bg-white p-1 shadow-sm",children:[Y.jsxs("div",{className:"relative",children:[Y.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"&&Y.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(S=>Y.jsxs("button",{type:"button",onClick:()=>{i(S),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S==="vector"?"Vector":"Canvas",o===S&&Y.jsx("span",{className:"ml-auto text-xs text-slate-500",children:"✓"})]},S))})]}),Y.jsxs("div",{className:"relative",children:[Y.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"&&Y.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:Y.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"})})]}),Y.jsxs("div",{className:"relative",children:[Y.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"&&Y.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:_.map(S=>Y.jsxs("button",{type:"button",onClick:()=>{r(S.value),m(null)},className:"flex w-full items-center rounded-sm px-2 py-1.5 text-sm hover:bg-slate-100",children:[S.label,Y.jsx("span",{className:"ml-auto text-xs text-slate-500",children:S.description}),n===S.value&&Y.jsx("span",{className:"ml-2 text-xs text-slate-500",children:"✓"})]},S.value))})]})]}),Y.jsx(pQi,{solver:t})]})}),Y.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Y.jsx("button",{onClick:C,disabled:t.solved||t.failed||c,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Y.jsx("button",{onClick:y,disabled:t.solved||t.failed||c,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Y.jsx("button",{onClick:x,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${c?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:c?"Stop":"Animate"}),Y.jsx("button",{onClick:E,disabled:t.solved||t.failed||c,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"}),Y.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&Y.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),t.solved&&Y.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&Y.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&Y.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},fQi=t=>t!==null&&"pipelineDef"in t&&Array.isArray(t.pipelineDef),IQi=(t,e,n)=>{const o=t.currentPipelineStageIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},CQi=(t,e)=>{const o=t.pipelineDef[e].solverName,i=IQi(t,e),r=t[o],s=t.firstIterationOfStage?.[o]??(e===t.currentPipelineStageIndex?t.iterations:null),a=t.iterations;let A=0;if(i==="Completed"){const u=t.pipelineDef[e+1],h=u?t.firstIterationOfStage?.[u.solverName]:void 0;h!==void 0&&s!==null?A=h-s:s!==null&&(A=a-s)}else i==="In Progress"&&s!==null&&(A=a-s);const c=t.timeSpentOnStage?.[o]??0;let l=0;i==="Completed"?l=1:i==="In Progress"&&r&&(l=r.progress??0);const g=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:A,progress:l,timeSpent:c,stats:g&&Object.keys(g).length>0?g:null,solverInstance:r??null}},yQi=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Y.jsx("span",{className:`font-medium ${e[t]}`,children:t})},xQi=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return Y.jsxs("div",{className:"flex items-center gap-2",children:[Y.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Y.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),Y.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},iin=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)},EQi=t=>Object.entries(t).map(([e,n])=>`${e}: ${iin(n)}`).join(", "),BQi=({stats:t})=>{if(!t||Object.keys(t).length===0)return Y.jsx("span",{children:"-"});const e=Object.entries(t),n=EQi(t);return Y.jsxs("details",{className:"cursor-pointer",children:[Y.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),Y.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>Y.jsxs("div",{children:[o,": ",iin(i)]},o))})]})},TYe=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TYe);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=TYe(o));return e},SQi=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=TYe(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)}`)}},bQi=({expanded:t})=>Y.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:Y.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"})}),rin=t=>{let e=t;for(;e.activeSubSolver;)e=e.activeSubSolver;return e},sin=({solver:t,onStepUntilPhase:e,onDownloadInput:n,isNested:o=!1,indentLevel:i=0,triggerRender:r})=>{const[s,a]=$.useState(new Set),A=t.pipelineDef.map((p,_)=>CQi(t,_)),c=p=>{a(_=>{const f=new Set(_);return f.has(p)?f.delete(p):f.add(p),f})},l=p=>{e?.(p)},g=p=>{p.solverInstance&&(n?n(p.solverInstance,p.name):SQi(p.solverInstance,p.name))},u=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=rin(t);for(;!t.solved&&!t.failed&&(t.step(),rin(t)===p););r?.()}},m=i*24;return Y.jsxs("div",{className:o?"":"border-t border-gray-200",children:[!o&&Y.jsxs("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between",children:[Y.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Stages"}),Y.jsxs("div",{className:"flex gap-2",children:[Y.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"}),Y.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"})]})]}),Y.jsx("div",{className:"overflow-x-auto",children:Y.jsxs("table",{className:"w-full text-sm",children:[!o&&Y.jsx("thead",{children:Y.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stage"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Y.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Y.jsx("sub",{children:"0"})]}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Y.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Y.jsx("tbody",{children:A.map(p=>{const _=fQi(p.solverInstance),f=s.has(p.name);return Y.jsxs(Cs.Fragment,{children:[Y.jsxs("tr",{className:`border-b border-gray-100 ${p.status==="In Progress"?"bg-yellow-50":""}`,children:[Y.jsx("td",{className:"px-4 py-2",children:Y.jsxs("div",{className:"flex items-center gap-2",style:{paddingLeft:m},children:[_?Y.jsx("button",{onClick:()=>c(p.name),className:"text-gray-500 hover:text-gray-700",title:f?"Collapse":"Expand",children:Y.jsx(bQi,{expanded:f})}):Y.jsx("span",{className:"w-4"}),Y.jsx("span",{className:"text-gray-400 w-6",children:String(p.index+1).padStart(2,"0")}),Y.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:Y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Y.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"})})}),Y.jsx("span",{className:"font-medium text-gray-900",children:p.name})]})}),Y.jsx("td",{className:"px-4 py-2",children:Y.jsx(yQi,{status:p.status})}),Y.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:p.firstIteration!==null?p.firstIteration:""}),Y.jsx("td",{className:"px-4 py-2 text-gray-600",children:p.iterations}),Y.jsx("td",{className:"px-4 py-2",children:Y.jsx(xQi,{progress:p.progress})}),Y.jsx("td",{className:"px-4 py-2 text-gray-600",children:u(p.timeSpent)}),Y.jsx("td",{className:"px-4 py-2 text-gray-500",children:Y.jsx(BQi,{stats:p.stats})}),Y.jsx("td",{className:"px-4 py-2",children:p.solverInstance?Y.jsxs("button",{onClick:()=>g(p),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${p.name}`,children:[Y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Y.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"})}),Y.jsx("span",{children:"Input"})]}):null})]}),_&&f&&Y.jsx("tr",{children:Y.jsx("td",{colSpan:8,className:"p-0",children:Y.jsx(sin,{solver:p.solverInstance,onStepUntilPhase:e,onDownloadInput:n,isNested:!0,indentLevel:i+1,triggerRender:r})})})]},p.name)})})]})})]})};function QQi({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,A=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;const l=(p,_)=>{typeof p=="number"&&(p<s&&(s=p),p>A&&(A=p)),typeof _=="number"&&(_<a&&(a=_),_>c&&(c=_))};for(const p of e)l(p.x,p.y);for(const p of n){const _=p.points??[];for(const f of _)l(f.x,f.y)}for(const p of o){const _=p.x??0,f=p.y??0,I=p.width??0,C=p.height??0;l(_,f),l(_+I,f+C)}for(const p of i){const _=p.x??0,f=p.y??0,I=p.radius??1;l(_-I,f-I),l(_+I,f+I)}for(const p of r)l(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(A)||!isFinite(c))&&(s=-20,a=-20,A=20,c=20);const g=10,u=s-g,h=a-g,d=Math.max(1,A-s+2*g),m=Math.max(1,c-a+2*g);return Y.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${u} ${h} ${d} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,_)=>Y.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-${_}`)),n.map((p,_)=>Y.jsx("polyline",{fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1,points:(p.points??[]).map(f=>`${f.x??0},${f.y??0}`).join(" ")},`line-${_}`)),i.map((p,_)=>Y.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-${_}`)),e.map((p,_)=>Y.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${_}`)),r.map((p,_)=>Y.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${_}`))]})}var vQi=class extends Cs.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}},PQi=({solver:t,createSolver:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=$.useReducer(f=>f+1,0),[a]=$.useState(()=>{if(e)return e();if(!t)throw new Error("GenericSolverDebugger requires solver or createSolver");return t}),[A,c]=$.useState(()=>typeof window>"u"?"vector":window.localStorage.getItem("solver-utils-renderer")==="canvas"?"canvas":"vector"),[l,g]=$.useState(n),u=$.useMemo(()=>{try{return a.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(f){return console.error("Visualization error:",f),{points:[],lines:[],rects:[],circles:[]}}},[a,r]),h=$.useMemo(()=>(u.rects?.length||0)===0&&(u.lines?.length||0)===0&&(u.points?.length||0)===0&&(u.circles?.length||0)===0,[u]);$.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const f=document.createElement("script");f.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(f)}},[]),$.useEffect(()=>{g(n)},[n]);const d=a.pipelineDef!==void 0,m=f=>{const I=a;if(!a.solved&&!a.failed){for(;!a.solved&&!a.failed&&I.currentPipelineStageIndex<=I.pipelineDef.findIndex(C=>C.solverName===f);)a.step();s()}},p=()=>{const f=JSON.stringify(u,null,2),I=new Blob([f],{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=>{c(f),typeof window<"u"&&window.localStorage.setItem("solver-utils-renderer",f)};return Y.jsxs("div",{children:[Y.jsx(_Qi,{solver:a,triggerRender:s,animationSpeed:l,renderer:A,onRendererChange:_,onAnimationSpeedChange:g,onDownloadVisualization:p,onSolverStarted:o,onSolverCompleted:i}),h?Y.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Y.jsx(vQi,{fallback:Y.jsx(QQi,{graphics:u}),children:A==="canvas"?Y.jsx(hQi,{graphics:u}):Y.jsx(gQi,{graphics:u})}),d&&Y.jsx(sin,{solver:a,onStepUntilPhase:m,triggerRender:s})]})};const wQi=()=>{$.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)},[])},DQi=1e3,D2=(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)},DQi)},kYe=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"},MQi=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]},Cv="https://github.com/tscircuit/tscircuit-autorouter/issues/new",ain="https://github.com/tscircuit/copper-pour-solver/issues/new",Ain="https://github.com/tscircuit/calculate-packing/issues/new",RQi="https://github.com/tscircuit/matchpack/issues/new",cin="https://github.com/tscircuit/schematic-trace-solver/issues/new?template=json-bug-report.yml",NQi={PackSolver2:Ain,LayoutPipelineSolver:RQi,AutoroutingPipelineSolver:Cv,AssignableAutoroutingPipeline2:Cv,AssignableAutoroutingPipeline3:Cv,AutoroutingPipeline1_OriginalUnravel:Cv,AutoroutingPipelineSolver3_HgPortPointPathing:Cv,AutoroutingPipelineSolver4:Cv,AutoroutingPipelineSolver5:Cv,AutoroutingPipelineSolver7_MultiGraph:Cv,AutoroutingPipelineSolver8:Cv,CopperPourPipelineSolver:ain,SchematicTracePipelineSolver:cin},TQi=t=>t.toLowerCase().includes("pack")?nZt:t.toLowerCase().includes("rout")?iZt:a0i,lin=t=>{const e=NQi[t];if(e)return e;const n=t.toLowerCase();return n.includes("autorout")?Cv:n.includes("schematic")&&n.includes("trace")?cin:n.includes("copperpour")?ain:n.includes("pack")?Ain:null},kQi=t=>`${kYe(`${t.componentName}-${t.solverName}`)}-solver-input.json`,gin=t=>{D2(JSON.stringify(t.solverParams,null,2),{fileName:kQi(t),mimeType:"application/json"})},FQi=({solverEvent:t})=>{const e=lin(t.solverName);return Y.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:[Y.jsxs(Xa,{type:"button",variant:"outline",size:"sm",onClick:()=>gin(t),children:[Y.jsx(bj,{className:"rf-w-4 rf-h-4"}),"Download"]}),e?Y.jsx(Xa,{asChild:!0,variant:"outline",size:"sm",children:Y.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[Y.jsx(xue,{className:"rf-w-4 rf-h-4"}),"Report"]})}):Y.jsxs(Xa,{type:"button",variant:"outline",size:"sm",disabled:!0,title:"No report link configured for this solver",children:[Y.jsx(xue,{className:"rf-w-4 rf-h-4"}),"Report"]})]})},LQi=({solverEvent:t})=>{const e=lin(t.solverName);return e?Y.jsx(Xa,{asChild:!0,variant:"ghost",size:"icon",className:"rf-h-8 rf-w-8",children:Y.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:"Report solver bug","aria-label":"Report solver bug",children:Y.jsx(xue,{className:"rf-w-4 rf-h-4"})})}):Y.jsx(Xa,{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:Y.jsx(xue,{className:"rf-w-4 rf-h-4"})})},HQi=({solverEvents:t=[]})=>{const[e,n]=$.useState(null);wQi();const o=$.useMemo(()=>{const a=new Map;for(const A of t){const c=`${A.componentName}-${A.solverName}`;a.set(c,A)}return a},[t]),i=$.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=$.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=bDe[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(bDe).join(", ")}`,classFound:!1};try{return{instance:new a(...MQi(r)),error:null,classFound:!0}}catch(A){const c=A instanceof Error?A.message:String(A);return console.error("Failed to reconstruct solver:",A),{instance:null,error:`Failed to instantiate solver: ${c}`,classFound:!0}}},[r]);return t.length===0?Y.jsx("div",{className:"rf-p-4",children:Y.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Y.jsxs("div",{className:"rf-p-4",children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Y.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."})]})})}):Y.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Y.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Y.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 A=o.get(a),c=e===a;return Y.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${c?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const l=TQi(A.solverName);return Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Y.jsx(l,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Y.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Y.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:A.componentName}),Y.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:A.solverName})]})]})})()},a)})]}),Y.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?Y.jsxs("div",{className:"rf-flex rf-h-full rf-flex-col rf-overflow-y-auto",children:[Y.jsx(FQi,{solverEvent:r}),Y.jsx("div",{className:"rf-min-h-0 rf-flex-1",children:Y.jsx(y2,{fallback:Y.jsx("div",{className:"rf-p-4",children:Y.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Y.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:Y.jsx(PQi,{solver:s.instance})})})]}):Y.jsxs("div",{className:"rf-p-4",children:[Y.jsxs("div",{className:"rf-mb-4",children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),Y.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&Y.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:Y.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Y.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Y.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:[Y.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"}),Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-1",children:[Y.jsx(LQi,{solverEvent:r}),Y.jsx(Xa,{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:()=>gin(r),children:Y.jsx(bj,{className:"rf-w-4 rf-h-4"})})]})]}),Y.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Y.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)})})]})]}):Y.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Y.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},OQi=["subcircuit_id","componentDisplayName","phaseName","routingPhaseIndex","phaseOrdinal","phaseCount","phaseStageIndex","phaseStageCount","connectionCount","obstacleCount","previousTraceCount","isReroutePhase","autorouterName","autorouterVersion","solverName","effort","cacheStatus"],GQi=["phaseOrdinal","routingPhaseIndex","phaseName","phaseStageIndex"];function UQi(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 A of GQi)if(!(r[A]===void 0||e[A]===void 0)){if(r[A]!==e[A]){a=!0;break}s++}!a&&s>o&&(n=i,o=s)}return n}function YQi(t,e){const n=Object.fromEntries(OQi.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:UQi(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 KQi=new Map([["custom","Custom"],["fanout","Fanout"],["single_layer_fanout","Single layer fanout"],["tscircuit_simplify","Simplify"]]),zQi=new Set(["tscircuit","default","auto","auto_local"]);function VQi(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 JQi(t){const e=t.autorouterName?.trim(),n=e?.replace(/-/g,"_"),o=n&&KQi.get(n);if(o)return o;if(n&&!zQi.has(n))return e;const i=t.solverName?.trim();if(i)return VQi(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 FYe="#fbbf24";function WQi(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 uin(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 jQi(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 din(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,...jQi(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 A=-1,c=Number.POSITIVE_INFINITY;return n.forEach((l,g)=>{if(l.route_type!=="wire")return;const u=Math.hypot(l.x-a.x,l.y-a.y);u<c&&(c=u,A=g)}),A},i=t.route.filter(a=>a.route_type==="jumper").map(a=>[o(a.start),o(a.end)].sort((A,c)=>A-c)).filter(([a,A])=>a>=0&&A>a).sort(([a],[A])=>a-A),r=[];let s=0;for(const[a,A]of i)a>=s&&r.push(n.slice(s,a+1)),s=Math.max(s,A);return s<n.length&&r.push(n.slice(s)),r}function qQi(t){const e=[],n=[],o=t.endSimpleRouteJson;if(!o)return{lines:e,circles:n};const i=new Set(uin(t));for(const r of o.traces??[])if(i.has(r.pcb_trace_id))for(const s of din(r,o)){let a;for(const A of s){if(A.route_type==="through_pad"){a={...A.end,layer:A.end_layer,width:A.width};continue}const c=A.route_type==="wire"?A.layer:A.from_layer;a&&a.layer===c&&(a.x!==A.x||a.y!==A.y)&&e.push({points:[{x:a.x,y:a.y},{x:A.x,y:A.y}],strokeWidth:A.route_type==="wire"?A.width:a.width,strokeColor:FYe,layer:c}),A.route_type==="via"&&n.push({center:{x:A.x,y:A.y},radius:A.outer_diameter/2,stroke:FYe,fill:"transparent"}),a={x:A.x,y:A.y,layer:A.route_type==="wire"?A.layer:A.to_layer,width:A.route_type==="wire"?A.width:a?.width??o.minTraceWidth}}}return{coordinateSystem:"cartesian",lines:e,circles:n}}function XQi(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 $Qi=new Set(["pcb_trace","pcb_via","pcb_copper_pour","pcb_ground_plane","pcb_ground_plane_region","pcb_thermal_spoke","pcb_breakout_point"]);function ZQi(t,e,n){const o=n==="input"?e.startSimpleRouteJson??e.errorSimpleRouteJson:e.endSimpleRouteJson,i=t.filter(c=>!$Qi.has(c.type)&&!c.type.endsWith("_error")&&!c.type.endsWith("_warning"));if(!o)return i;const r=n==="input"?o.traces??[]:WQi(e),s=new Set(t.filter(c=>c.type==="source_trace").map(c=>c.source_trace_id)),a=["top",...Array.from({length:Math.max(0,o.layerCount-2)},(c,l)=>`inner${l+1}`),...o.layerCount>1?["bottom"]:[]],A=[];for(const c of r){const g=o.connections.find(h=>h.name===c.connection_name||h.source_trace_id===c.connection_name)?.source_trace_id??c.connection_name??"",u=din(c,o);for(const[h,d]of u.entries()){const m={type:"pcb_trace",pcb_trace_id:`${e.id}_${n}_${c.pcb_trace_id}_${h}_${XQi(d)}`,subcircuit_id:e.subcircuit_id??void 0,source_trace_id:s.has(g)?g:void 0,route:d};A.push(m);for(const[p,_]of d.entries()){if(_.route_type!=="via")continue;const f=a.indexOf(_.from_layer),I=a.indexOf(_.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:_.x,y:_.y,outer_diameter:_.outer_diameter,hole_diameter:_.hole_diameter,layers:f>=0&&I>=0?a.slice(Math.min(f,I),Math.max(f,I)+1):[_.from_layer,_.to_layer]};A.push(C)}}}return[...i,...A]}const LYe=(t,e)=>t.phaseName||`Phase ${t.phaseOrdinal??e+1}`,hin=t=>t.componentDisplayName?.match(/name="([^"]+)"/)?.[1]?.replace(/^\./,"")||t.componentDisplayName||t.subcircuit_id||"Board",min=t=>t.startSimpleRouteJson??t.endSimpleRouteJson??t.errorSimpleRouteJson,e3i={is_showing_autorouting:!0,is_showing_rats_nest:!1,is_showing_drc_errors:!1,is_showing_drc_warnings:!1,is_showing_pcb_groups:!1},t3i=({circuitJson:t,phases:e=[],isRunning:n=!1})=>{const[o,i]=$.useState(null),[r,s]=$.useState("output"),[a,A]=$.useState(!0),[c,l]=$.useState(!1),g=$.useRef(null),[u,h]=$.useState(480),d=o?e.findIndex(L=>L.id===o.id&&min(L)===min(o)):-1,m=d<0?e.length-1:d,p=e[m],_=d<0,f=!!p?.endSimpleRouteJson,I=p?.startSimpleRouteJson??p?.errorSimpleRouteJson,C=!!I,y=r==="output"&&!f?"input":r==="input"&&!C?"output":r,x=y==="input"?I:p?.endSimpleRouteJson,E=$.useMemo(()=>!p||!x?null:ZQi(t??[],p,y),[t,p,x,y]),S=$.useMemo(()=>p&&y==="output"&&a?qQi(p):{lines:[],circles:[]},[p,y,a]);if($.useLayoutEffect(()=>{const L=g.current;if(!L)return;const O=()=>h(Math.max(360,L.clientHeight));O();const G=new ResizeObserver(O);return G.observe(L),()=>G.disconnect()},[!!p]),!p)return Y.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:[Y.jsx(iZt,{className:"rf-h-7 rf-w-7 rf-text-blue-500"}),Y.jsx("h3",{className:"rf-text-base rf-font-medium",children:n?"Waiting for autorouting":"No autorouting captures"}),Y.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=LYe(p,m),v=p.status==="running"&&n,M=!f,N=I?.connections.length,k=E?.filter(L=>L.type==="pcb_trace").length??0;return Y.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:[Y.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:[Y.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:[Y.jsx("span",{children:"Routing phases"}),Y.jsx("span",{children:e.length})]}),Y.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((L,O)=>{const G=uin(L).length,V=L.endSimpleRouteJson?`${G} ${G===1?"trace":"traces"} routed`:L.status==="error"?"Failed":L.status==="running"&&n?"Routing…":"No output";return Y.jsxs("button",{type:"button","aria-pressed":O===m,title:`${hin(L)} · ${V}`,onClick:()=>i(L),className:Mi("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",O===m?"rf-border-blue-200 rf-bg-blue-50":"rf-border-transparent hover:rf-bg-gray-50"),children:[Y.jsx("span",{className:Mi("rf-flex rf-h-5 rf-w-5 rf-shrink-0 rf-items-center rf-justify-center rf-rounded-full rf-text-[11px]",O===m?"rf-bg-blue-600 rf-text-white":"rf-bg-gray-100 rf-text-gray-500"),children:O+1}),Y.jsxs("span",{className:"rf-min-w-0 rf-flex-1",children:[Y.jsxs("span",{className:"rf-flex rf-items-center rf-gap-1",children:[Y.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:LYe(L,O),children:LYe(L,O)}),L.status==="complete"?Y.jsx(Uw,{"aria-label":"Captured",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-green-600"}):L.status==="error"?Y.jsx(FGe,{"aria-label":"Failed",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-text-red-500"}):n?Y.jsx(x2,{"aria-label":"Routing",className:"rf-h-3 rf-w-3 rf-shrink-0 rf-animate-spin rf-text-blue-500"}):null]}),Y.jsxs("span",{className:"rf-block rf-text-[11px] rf-leading-4 rf-text-gray-500",children:[JQi(L)," · ",V]})]})]},L.id)})})]}),Y.jsxs("div",{className:"rf-flex rf-min-w-0 rf-flex-1 rf-flex-col",children:[Y.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:[Y.jsxs("h3",{className:"rf-mr-auto rf-flex rf-items-center rf-gap-2 rf-text-sm rf-font-medium",children:[b,Y.jsxs("span",{className:"rf-text-xs rf-font-normal rf-text-gray-500",children:[m+1," of ",e.length]})]}),n&&Y.jsx("button",{type:"button",onClick:()=>i(null),disabled:_,className:"rf-text-xs rf-text-blue-600 disabled:rf-text-gray-500",children:_?"Following latest":"Follow latest"}),Y.jsx("div",{className:"rf-flex rf-rounded-md rf-bg-gray-100 rf-p-1","aria-label":"Phase snapshot",children:["input","output"].map(L=>Y.jsx("button",{type:"button","aria-pressed":y===L,disabled:L==="input"?!C:!f,onClick:()=>s(L),className:Mi("rf-rounded rf-px-3 rf-py-1 rf-text-xs disabled:rf-opacity-40",y===L?"rf-bg-white rf-text-gray-900 rf-shadow-sm":"rf-text-gray-500"),children:L==="input"?"Input":"Output"},L))})]}),Y.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:[Y.jsxs("label",{className:"rf-flex rf-items-center rf-gap-2",children:[Y.jsx("input",{type:"checkbox",checked:a,disabled:y!=="output",onChange:L=>A(L.target.checked),className:"rf-accent-blue-600"}),Y.jsx("span",{"aria-hidden":"true",className:"rf-inline-block rf-h-0.5 rf-w-3",style:{backgroundColor:FYe}}),"Highlight changes (all layers)"]}),Y.jsxs("span",{children:[y==="input"?"Before this phase":"After this phase"," ","· ",k," traces"]})]}),M&&Y.jsx("div",{className:Mi("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."}`:v?"Routing in progress. Showing captured input until output is available.":"No output was captured for this phase. Showing the available input."}),Y.jsx("div",{ref:g,className:"rf-relative rf-min-h-[360px] rf-flex-1","data-testid":"autorouting-pcb",children:E?Y.jsx(PYe,{circuitJson:E,height:u,allowEditing:!1,clickToInteractEnabled:!1,initialState:e3i,debugGraphics:S}):Y.jsx("div",{className:"rf-p-6 rf-text-sm rf-text-gray-500",children:"No PCB snapshot available for this capture."})}),Y.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:[Y.jsxs("span",{children:[N===void 0?"Input unavailable":`${N} input connections`,` · ${hin(p)}`]}),Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-4",children:[Y.jsxs("button",{type:"button",disabled:!x,onClick:()=>D2(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:[Y.jsx(bj,{className:"rf-h-3 rf-w-3"}),"Download SRJ"]}),Y.jsxs("button",{type:"button","aria-expanded":c,onClick:()=>l(!c),className:"rf-flex rf-items-center rf-gap-1",children:[Y.jsx(sR,{className:Mi("rf-h-3 rf-w-3",c&&"rf-rotate-90")}),"Inspect SRJ"]})]})]}),c&&Y.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."})]})]})},pin=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{$.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{QL.captureException(o)}catch{}}},[t,e]),$.useEffect(()=>{if(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{QL.captureException(i,{error_type:o.type})}catch{}}},[n])},_in=t=>{$.useEffect(()=>{try{TMo(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},fin="0.0.2716",n3i={version:fin},jde=O4t()(G4t(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),o3i=t=>{const[e,n]=$.useState([]),[o,i]=$.useState(null),[r,s]=$.useState(""),[a,A]=oL("eval-version-selection",null),c=jde(h=>h.setLastRunEvalVersion),l=jde(h=>h.lastRunEvalVersion);return $.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]),$.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,c(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,c(o)))},[t,a,o]),{versions:$.useMemo(()=>e.filter(h=>h.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:l,search:r,setSearch:s,selectVersion:h=>{A(h),s("")}}},i3i=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=$.useState(""),[s,a]=$.useState("");if(!o)return null;const A=t.filter(g=>g.toLowerCase().includes(s.toLowerCase())),c=s&&!t.includes(s),l=g=>{g.key==="Enter"&&(A.length===1?r(A[0]):c&&r(s))};return Y.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:Y.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[Y.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),Y.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:g=>a(g.target.value),onKeyDown:l}),Y.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[A.map(g=>Y.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===g?"bg-blue-50":""}`,onClick:()=>r(g),children:g},g)),c&&Y.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,'"']})]}),Y.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[Y.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),Y.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}`})]})]})})},r3i=t=>{const e=$.useRef(null),n=Od(o=>o.recentEvents);$.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 s3i=Object.defineProperty,M2=(t,e)=>s3i(t,"name",{value:e,configurable:!0}),HYe="Dialog",[Iin,Cin]=wx(HYe),[a3i,jb]=Iin(HYe),OYe=M2(t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=$.useRef(null),A=$.useRef(null),[c,l]=Cb({prop:o,defaultProp:i??!1,onChange:r,caller:HYe}),[g,u]=$.useState(0),[h,d]=$.useState(0);return Y.jsx(a3i,{scope:e,triggerRef:a,contentRef:A,contentId:bp(),titleId:bp(),descriptionId:bp(),titlePresent:g>0,descriptionPresent:h>0,setTitleCount:u,setDescriptionCount:d,open:c,onOpenChange:l,onOpenToggle:$.useCallback(()=>l(m=>!m),[l]),modal:s,children:n})},"Dialog"),A3i="DialogTrigger",c3i=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(A3i,o),s=DA(n,r.triggerRef);return Y.jsx(ha.button,{type:"button","aria-haspopup":"dialog","aria-expanded":r.open,"aria-controls":r.open?r.contentId:void 0,"data-state":$de(r.open),...i,ref:s,onClick:or(e.onClick,r.onOpenToggle)})},"DialogTrigger")),yin="DialogPortal",[l3i,xin]=Iin(yin,{forceMount:void 0}),GYe=M2(t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=jb(yin,e);return Y.jsx(l3i,{scope:e,forceMount:n,children:$.Children.map(o,s=>Y.jsx(A2,{present:n||r.open,children:Y.jsx(Hue,{asChild:!0,container:i,children:s})}))})},"DialogPortal"),UYe="DialogOverlay",qde=$.forwardRef(M2(function(e,n){const o=xin(UYe,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=jb(UYe,e.__scopeDialog);return s.modal?Y.jsx(A2,{present:i||s.open,children:Y.jsx(u3i,{...r,ref:n})}):null},"DialogOverlay")),g3i=Ib("DialogOverlay.RemoveScroll"),u3i=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(UYe,o),s=aZt(),a=DA(n,s);return Y.jsx(Dj,{as:g3i,allowPinchZoom:!0,shards:[r.contentRef],children:Y.jsx(ha.div,{"data-state":$de(r.open),...i,ref:a,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),gq="DialogContent",Xde=$.forwardRef(M2(function(e,n){const o=xin(gq,e.__scopeDialog),{forceMount:i=o.forceMount,...r}=e,s=jb(gq,e.__scopeDialog);return Y.jsx(A2,{present:i||s.open,children:s.modal?Y.jsx(d3i,{...r,ref:n}):Y.jsx(h3i,{...r,ref:n})})},"DialogContent")),d3i=$.forwardRef(M2(function(e,n){const o=jb(gq,e.__scopeDialog),i=$.useRef(null),r=DA(n,o.contentRef,i);return $.useEffect(()=>{const s=i.current;if(s)return Uue(s)},[]),Y.jsx(Ein,{...e,ref:r,trapFocus:o.open,disableOutsidePointerEvents:o.open,onCloseAutoFocus:or(e.onCloseAutoFocus,s=>{s.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:or(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,A=a.button===0&&a.ctrlKey===!0;(a.button===2||A)&&s.preventDefault()}),onFocusOutside:or(e.onFocusOutside,s=>s.preventDefault())})},"DialogContentModal")),h3i=$.forwardRef(M2(function(e,n){const o=jb(gq,e.__scopeDialog),i=$.useRef(!1),r=$.useRef(!1);return Y.jsx(Ein,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{e.onCloseAutoFocus?.(s),s.defaultPrevented||(i.current||o.triggerRef.current?.focus(),s.preventDefault()),i.current=!1,r.current=!1},onInteractOutside:s=>{e.onInteractOutside?.(s),s.defaultPrevented||(i.current=!0,s.detail.originalEvent.type==="pointerdown"&&(r.current=!0));const a=s.target;o.triggerRef.current?.contains(a)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&r.current&&s.preventDefault()}})},"DialogContentNonModal")),Ein=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,trapFocus:i,onOpenAutoFocus:r,onCloseAutoFocus:s,...a}=e,A=jb(gq,o);return CO(),Y.jsx(Y.Fragment,{children:Y.jsx(Bue,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:r,onUnmountAutoFocus:s,children:Y.jsx(Qj,{role:"dialog",id:A.contentId,"aria-describedby":A.descriptionPresent?A.descriptionId:void 0,"aria-labelledby":A.titlePresent?A.titleId:void 0,"data-state":$de(A.open),...a,ref:n,deferPointerDownOutside:!0,onDismiss:()=>A.onOpenChange(!1)})})})},"DialogContentImpl")),m3i="DialogTitle",YYe=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(m3i,o),{setTitleCount:s}=r;return K0(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),Y.jsx(ha.h2,{id:r.titleId,...i,ref:n})},"DialogTitle")),p3i="DialogDescription",KYe=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(p3i,o),{setDescriptionCount:s}=r;return K0(()=>(s(a=>a+1),()=>s(a=>a-1)),[s]),Y.jsx(ha.p,{id:r.descriptionId,...i,ref:n})},"DialogDescription")),_3i="DialogClose",Bin=$.forwardRef(M2(function(e,n){const{__scopeDialog:o,...i}=e,r=jb(_3i,o);return Y.jsx(ha.button,{type:"button",...i,ref:n,onClick:or(e.onClick,()=>r.onOpenChange(!1))})},"DialogClose"));function $de(t){return t?"open":"closed"}M2($de,"getState");var f3i=Object.defineProperty,Xw=(t,e)=>f3i(t,"name",{value:e,configurable:!0}),I3i="AlertDialog",[C3i,nXi]=wx(I3i,[Cin]),$w=Cin(),y3i=Xw(t=>{const{__scopeAlertDialog:e,...n}=t,o=$w(e);return Y.jsx(OYe,{...o,...n,modal:!0})},"AlertDialog");$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(c3i,{...r,...i,ref:n})},"AlertDialogTrigger"));var x3i=Xw(t=>{const{__scopeAlertDialog:e,...n}=t,o=$w(e);return Y.jsx(GYe,{...o,...n})},"AlertDialogPortal"),E3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(qde,{...r,...i,ref:n})},"AlertDialogOverlay")),B3i="AlertDialogContent",[S3i,b3i]=C3i(B3i),Q3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,children:i,...r}=e,s=$w(o),a=$.useRef(null),A=DA(n,a),c=$.useRef(null);return Y.jsx(S3i,{scope:o,cancelRef:c,children:Y.jsx(Xde,{role:"alertdialog",...s,...r,ref:A,onOpenAutoFocus:or(r.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:i})})},"AlertDialogContent")),v3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(YYe,{...r,...i,ref:n})},"AlertDialogTitle")),P3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(KYe,{...r,...i,ref:n})},"AlertDialogDescription")),w3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,r=$w(o);return Y.jsx(Bin,{...r,...i,ref:n})},"AlertDialogAction")),D3i="AlertDialogCancel",M3i=$.forwardRef(Xw(function(e,n){const{__scopeAlertDialog:o,...i}=e,{cancelRef:r}=b3i(D3i,o),s=$w(o),a=DA(n,r);return Y.jsx(Bin,{...s,...i,ref:a})},"AlertDialogCancel")),R3i=y3i,N3i=x3i,Sin=E3i,bin=Q3i,Qin=w3i,vin=M3i,Pin=v3i,win=P3i;const Din=R3i,T3i=N3i,Min=$.forwardRef(({className:t,...e},n)=>Y.jsx(Sin,{className:Mi("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}));Min.displayName=Sin.displayName;const zYe=$.forwardRef(({className:t,...e},n)=>Y.jsxs(T3i,{children:[Y.jsx(Min,{}),Y.jsx(bin,{ref:n,className:Mi("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})]}));zYe.displayName=bin.displayName;const VYe=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});VYe.displayName="AlertDialogHeader";const JYe=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});JYe.displayName="AlertDialogFooter";const WYe=$.forwardRef(({className:t,...e},n)=>Y.jsx(Pin,{ref:n,className:Mi("rf-text-lg rf-font-semibold",t),...e}));WYe.displayName=Pin.displayName;const jYe=$.forwardRef(({className:t,...e},n)=>Y.jsx(win,{ref:n,className:Mi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));jYe.displayName=win.displayName;const k3i=$.forwardRef(({className:t,...e},n)=>Y.jsx(Qin,{ref:n,className:Mi(fO(),t),...e}));k3i.displayName=Qin.displayName;const qYe=$.forwardRef(({className:t,...e},n)=>Y.jsx(vin,{ref:n,className:Mi(fO({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));qYe.displayName=vin.displayName;var F3i=Object.defineProperty,Zw=(t,e)=>F3i(t,"name",{value:e,configurable:!0}),XYe="Checkbox",[L3i,oXi]=wx(XYe),[H3i,$Ye]=L3i(XYe);function Rin(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:A,required:c,value:l="on",internal_do_not_use_render:g}=t,[u,h]=Cb({prop:n,defaultProp:i??!1,onChange:A,caller:XYe}),[d,m]=$.useState(null),[p,_]=$.useState(null),f=$.useRef(!1),[I,C]=$.useReducer(E=>E+1,0),y=d?!!s||!!d.closest("form"):!0,x={checked:u,disabled:r,setChecked:h,control:d,setControl:m,name:a,form:s,value:l,hasConsumerStoppedPropagationRef:f,userInteractionCount:I,onUserInteraction:C,required:c,defaultChecked:eD(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:_};return Y.jsx(H3i,{scope:e,...x,children:Tin(g)?g(x):o})}Zw(Rin,"CheckboxProvider");var O3i="CheckboxTrigger",G3i=$.forwardRef(Zw(function({__scopeCheckbox:e,onKeyDown:n,onClick:o,...i},r){const{control:s,value:a,disabled:A,checked:c,required:l,setControl:g,setChecked:u,hasConsumerStoppedPropagationRef:h,onUserInteraction:d,isFormControl:m,bubbleInput:p}=$Ye(O3i,e),_=DA(r,g),f=$.useRef(c);return $.useEffect(()=>{const I=s?.form;if(I){const C=Zw(()=>u(f.current),"reset");return I.addEventListener("reset",C),()=>I.removeEventListener("reset",C)}},[s,u]),Y.jsx(ha.button,{type:"button",role:"checkbox","aria-checked":eD(c)?"mixed":c,"aria-required":l,"data-state":ZYe(c),"data-disabled":A?"":void 0,disabled:A,value:a,...i,ref:_,onKeyDown:or(n,I=>{I.key==="Enter"&&I.preventDefault()}),onClick:or(o,I=>{d(),u(C=>eD(C)?!0:!C),p&&m&&(h.current=I.isPropagationStopped(),h.current||I.stopPropagation())})})},"CheckboxTrigger")),Nin=$.forwardRef(Zw(function(e,n){const{__scopeCheckbox:o,name:i,checked:r,defaultChecked:s,required:a,disabled:A,value:c,onCheckedChange:l,form:g,...u}=e;return Y.jsx(Rin,{__scopeCheckbox:o,checked:r,defaultChecked:s,disabled:A,required:a,onCheckedChange:l,name:i,form:g,value:c,internal_do_not_use_render:({isFormControl:h})=>Y.jsxs(Y.Fragment,{children:[Y.jsx(G3i,{...u,ref:n,__scopeCheckbox:o}),h&&Y.jsx(z3i,{__scopeCheckbox:o})]})})},"Checkbox")),U3i="CheckboxIndicator",Y3i=$.forwardRef(Zw(function(e,n){const{__scopeCheckbox:o,forceMount:i,...r}=e,s=$Ye(U3i,o);return Y.jsx(A2,{present:i||eD(s.checked)||s.checked===!0,children:Y.jsx(ha.span,{"data-state":ZYe(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:n,style:{pointerEvents:"none",...e.style}})})},"CheckboxIndicator")),K3i="CheckboxBubbleInput",z3i=$.forwardRef(Zw(function({__scopeCheckbox:e,onClick:n,...o},i){const{control:r,hasConsumerStoppedPropagationRef:s,userInteractionCount:a,checked:A,defaultChecked:c,required:l,disabled:g,name:u,value:h,form:d,bubbleInput:m,setBubbleInput:p}=$Ye(K3i,e),_=DA(i,p),f=sUe(r),I=$.useRef(!1),C=$.useRef(A),y=$.useRef(a);$.useEffect(()=>{const E=m;if(!E)return;const S=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(S,"checked").set,M=a!==y.current;y.current=a;const N=C.current!==A;C.current=A;const k=!(M&&s.current);if(N&&v){I.current=!M;const L=new Event("click",{bubbles:k});E.indeterminate=eD(A),v.call(E,eD(A)?!1:A),E.dispatchEvent(L),I.current=!1}},[m,A,s,a]);const x=$.useRef(eD(A)?!1:A);return Y.jsx(ha.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??x.current,required:l,disabled:g,name:u,value:h,form:d,...o,tabIndex:-1,ref:_,onClick:or(n,E=>{I.current&&E.stopPropagation()}),style:{...o.style,...f,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"CheckboxBubbleInput"));function Tin(t){return typeof t=="function"}Zw(Tin,"isFunction");function eD(t){return t==="indeterminate"}Zw(eD,"isIndeterminate");function ZYe(t){return eD(t)?"indeterminate":t?"checked":"unchecked"}Zw(ZYe,"getState");const uq=$.forwardRef(({className:t,...e},n)=>Y.jsx(Nin,{ref:n,className:Mi("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:Y.jsx(Y3i,{className:Mi("rf-flex rf-items-center rf-justify-center rf-text-current"),children:Y.jsx(Uw,{className:"rf-h-4 rf-w-4"})})}));uq.displayName=Nin.displayName;const IR=OYe,V3i=GYe,kin=$.forwardRef(({className:t,...e},n)=>Y.jsx(qde,{className:Mi("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}));kin.displayName=qde.displayName;const J4=$.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>Y.jsxs(V3i,{children:[Y.jsx(kin,{className:Mi(n?"":"rf-hidden")}),Y.jsx(Xde,{ref:i,className:Mi("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})]}));J4.displayName=Xde.displayName;const W4=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});W4.displayName="DialogHeader";const zO=({className:t,...e})=>Y.jsx("div",{className:Mi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});zO.displayName="DialogFooter";const j4=$.forwardRef(({className:t,...e},n)=>Y.jsx(YYe,{ref:n,className:Mi("rf-text-lg rf-font-semibold",t),...e}));j4.displayName=YYe.displayName;const CR=$.forwardRef(({className:t,...e},n)=>Y.jsx(KYe,{ref:n,className:Mi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));CR.displayName=KYe.displayName;const Zde={"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"}},J3i="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let eKe=null;const tKe=async()=>(eKe||(eKe=import(J3i)),eKe),W3i=t=>(e,n)=>{const o=new Headers(n?.headers),i={};return o.forEach((r,s)=>{i[s]=r}),fetch(`${t?.apiBase??FC}/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}})},j3i=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??[]},q3i=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}),Fin=async(t,e)=>{const{fetchEasyEDAComponent:n}=await tKe();return n(t,{fetch:W3i(e),includeModelMetadata:e?.includeModelMetadata})},X3i=async(t,e)=>{const{convertRawEasyToTsx:n}=await tKe(),o=await Fin(t,e);return n({rawEasy:o})},$3i=async(t,e)=>{const{EasyEdaJsonSchema:n,convertEasyEdaJsonToCircuitJson:o}=await tKe(),i=await Fin(t,{...e,includeModelMetadata:!1}),r=n.parse(i);return o(r,{shouldRecenter:!0,showDesignator:!0,useModelCdn:!1})};function q4(t){return Array.isArray?Array.isArray(t):Hin(t)==="[object Array]"}function Z3i(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 nKe(t){return t==null?"":Z3i(t)}function zC(t){return typeof t=="string"}function ehe(t){return typeof t=="number"}function evi(t){return t===!0||t===!1||tvi(t)&&Hin(t)=="[object Boolean]"}function Lin(t){return typeof t=="object"}function tvi(t){return Lin(t)&&t!==null}function R2(t){return t!=null}function the(t){return!t.trim().length}function Hin(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const nvi="Incorrect 'index' type",oKe="Invalid doc index: must be a non-negative integer within the bounds of the docs array",ovi=t=>`Invalid value for key ${t}`,ivi=t=>`Pattern length exceeds max of ${t}.`,rvi=t=>`Missing ${t} property in key`,svi=t=>`Property 'weight' in key '${t}' must be a positive integer`,avi="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.",Oin=Object.prototype.hasOwnProperty;var Avi=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=Gin(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 Gin(t){let e=null,n=null,o=null,i=1,r=null;if(zC(t)||q4(t))o=t,e=Uin(t),n=nhe(t);else{if(!Oin.call(t,"name"))throw new Error(rvi("name"));const s=t.name;if(o=s,Oin.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(svi(nhe(s)));e=Uin(s),n=nhe(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function Uin(t){return q4(t)?t:t.split(".")}function nhe(t){return q4(t)?t.join("."):t}function cvi(t,e){const n=[];let o=!1;const i=(r,s,a,A)=>{if(R2(r))if(!s[a])n.push(A!==void 0?{v:r,i:A}:r);else{const c=r[s[a]];if(!R2(c))return;if(a===s.length-1&&(zC(c)||ehe(c)||evi(c)||typeof c=="bigint"))n.push(A!==void 0?{v:nKe(c),i:A}:nKe(c));else if(q4(c)){o=!0;for(let l=0,g=c.length;l<g;l+=1)i(c[l],s,a+1,l)}else s.length&&i(c,s,a+1,A)}};return i(t,zC(e)?e.split("."):e,0),o?n:n[0]}const ga=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:cvi,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function lvi(t){return t>=9&&t<=13||t===32||t===160}function gvi(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=0,s=!1;for(let A=0;A<i.length;A++)lvi(i.charCodeAt(A))?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 iKe=class{constructor({getFn:t=ga.getFn,fieldNormWeight:e=ga.fieldNormWeight}={}){this.norm=gvi(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(oKe);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(oKe);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!R2(t)||the(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(R2(s)){if(q4(s)){const a=[];for(let A=0,c=s.length;A<c;A+=1){const l=s[A];if(R2(l)){if(zC(l)){if(!the(l)){const g={v:l,i:A,n:this.norm.get(l)};a.push(g)}}else if(R2(l.v)){const g=zC(l.v)?l.v:nKe(l.v);if(!the(g)){const u={v:g,i:l.i,n:this.norm.get(g)};a.push(u)}}}}n.$[o]=a}else if(zC(s)&&!the(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 Yin(t,e,{getFn:n=ga.getFn,fieldNormWeight:o=ga.fieldNormWeight}={}){const i=new iKe({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(Gin)),i.setSources(e),i.create(),i}function uvi(t,{getFn:e=ga.getFn,fieldNormWeight:n=ga.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new iKe({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function dvi(t=[],e=ga.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 hvi(t,e,n,{location:o=ga.location,distance:i=ga.distance,threshold:r=ga.threshold,findAllMatches:s=ga.findAllMatches,minMatchCharLength:a=ga.minMatchCharLength,includeMatches:A=ga.includeMatches,ignoreLocation:c=ga.ignoreLocation}={}){if(e.length>32)throw new Error(ivi(32));const l=e.length,g=t.length,u=Math.max(0,Math.min(o,g));let h=r,d=u;const m=(b,v)=>{const M=b/l;if(c)return M;const N=Math.abs(u-v);return i?M+N/i:N?1:M},p=a>1||A,_=p?Array(g):[];let f;for(;(f=t.indexOf(e,d))>-1;){const b=m(0,f);if(h=Math.min(b,h),d=f+l,p){let v=0;for(;v<l;)_[f+v]=1,v+=1}}d=-1;let I=[],C=1,y=0,x=l+g;const E=1<<l-1;for(let b=0;b<l;b+=1){let v=0,M=x;for(;v<M;)m(b,u+M)<=h?v=M:x=M,M=Math.floor((x-v)/2+v);x=M;let N=Math.max(1,u-M+1);const k=s?g:Math.min(u+M,g)+l,L=Array(k+2);L[k+1]=(1<<b)-1;for(let O=k;O>=N;O-=1){const G=O-1,V=n[t[G]];if(L[O]=(L[O+1]<<1|1)&V,b&&(L[O]|=(I[O+1]|I[O])<<1|1|I[O+1]),L[O]&E&&(C=m(b,G),C<=h)){if(h=C,d=G,y=b,d<=u)break;N=Math.max(1,2*u-d)}}if(m(b+1,u)>h)break;I=L}if(p&&d>=0){const b=Math.min(g-1,d+l-1+y);for(let v=d;v<=b;v+=1)n[t[v]]&&(_[v]=1)}const S={isMatch:d>=0,score:Math.max(.001,C)};if(p){const b=dvi(_,a);b.length?A&&(S.indices=b):S.isMatch=!1}return S}function mvi(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 rKe(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 Kin={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},pvi=new RegExp("["+Object.keys(Kin).join("")+"]","g"),dq=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(pvi,e=>Kin[e]):t=>t;var sKe=class{constructor(t,{location:e=ga.location,threshold:n=ga.threshold,distance:o=ga.distance,includeMatches:i=ga.includeMatches,findAllMatches:r=ga.findAllMatches,minMatchCharLength:s=ga.minMatchCharLength,isCaseSensitive:a=ga.isCaseSensitive,ignoreDiacritics:A=ga.ignoreDiacritics,ignoreLocation:c=ga.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:A,ignoreLocation:c},t=a?t:t.toLowerCase(),t=A?dq(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const l=(u,h)=>{this.chunks.push({pattern:u,alphabet:mvi(u),startIndex:h})},g=this.pattern.length;if(g>32){let u=0;const h=g%32,d=g-h;for(;u<d;)l(this.pattern.substr(u,32),u),u+=32;if(h){const m=g-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?dq(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:A,ignoreLocation:c}=this.options,l=[];let g=0,u=!1;this.chunks.forEach(({pattern:d,alphabet:m,startIndex:p})=>{const{isMatch:_,score:f,indices:I}=hvi(t,d,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:A,includeMatches:o,ignoreLocation:c});_&&(u=!0),g+=f,_&&I&&l.push(...I)});const h={isMatch:u,score:u?g/this.chunks.length:1};return u&&o&&(h.indices=rKe(l)),h}};const _vi=new Set(["fuzzy","include"]);function fvi(t){return t.startsWith("inverse")}const aKe=[{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 sKe(t,{location:e.location??ga.location,threshold:e.threshold??ga.threshold,distance:e.distance??ga.distance,includeMatches:e.includeMatches??ga.includeMatches,findAllMatches:e.findAllMatches??ga.findAllMatches,minMatchCharLength:e.minMatchCharLength??ga.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??ga.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??ga.ignoreDiacritics,ignoreLocation:e.ignoreLocation??ga.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],zin=aKe.length,Ivi="\0",Cvi="|";function yvi(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 Vin(t,e){const n=t.match(e);return n?n[1]:null}function xvi(t,e={}){return t.replace(/\\\|/g,Ivi).split(Cvi).map(n=>{const o=yvi(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 A=!1,c=-1;for(;!A&&++c<zin;){const l=aKe[c],g=Vin(a,l.multiRegex);g&&(i.push(l.create(g,e)),A=!0)}if(!A)for(c=-1;++c<zin;){const l=aKe[c],g=Vin(a,l.singleRegex);if(g){i.push(l.create(g,e));break}}}return i})}var Evi=class{constructor(t,{isCaseSensitive:e=ga.isCaseSensitive,ignoreDiacritics:n=ga.ignoreDiacritics,includeMatches:o=ga.includeMatches,minMatchCharLength:i=ga.minMatchCharLength,ignoreLocation:r=ga.ignoreLocation,findAllMatches:s=ga.findAllMatches,location:a=ga.location,threshold:A=ga.threshold,distance:c=ga.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:A,distance:c},t=e?t:t.toLowerCase(),t=n?dq(t):t,this.pattern=t,this.query=xvi(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?dq(t):t;let r=0;const s=[];let a=0,A=!1;for(let c=0,l=e.length;c<l;c+=1){const g=e[c];s.length=0,r=0,A=!1;for(let u=0,h=g.length;u<h;u+=1){const d=g[u],{isMatch:m,indices:p,score:_}=d.search(t);if(m)r+=1,a+=_,fvi(d.type)&&(A=!0),n&&(_vi.has(d.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,A=!1;break}}if(r){const u={isMatch:!0,score:a/r};return A&&(u.hasInverse=!0),n&&(u.indices=rKe(s)),u}}return{isMatch:!1,score:1}}};const AKe=[];function cKe(...t){AKe.push(...t)}function ohe(t,e){for(let n=0,o=AKe.length;n<o;n+=1){const i=AKe[n];if(i.condition(t,e))return new i(t,e)}return new sKe(t,e)}const ihe={AND:"$and",OR:"$or"},lKe={PATH:"$path",PATTERN:"$val"},gKe=t=>!!(t[ihe.AND]||t[ihe.OR]),Bvi=t=>!!t[lKe.PATH],Svi=t=>!q4(t)&&Lin(t)&&!gKe(t),Jin=t=>({[ihe.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function Win(t,e,{auto:n=!0}={}){const o=i=>{if(zC(i)){const A={keyId:null,pattern:i};return n&&(A.searcher=ohe(i,e)),A}const r=Object.keys(i),s=Bvi(i);if(!s&&r.length>1&&!gKe(i))return o(Jin(i));if(Svi(i)){const A=s?i[lKe.PATH]:r[0],c=s?i[lKe.PATTERN]:i[A];if(!zC(c))throw new Error(ovi(A));const l={keyId:nhe(A),pattern:c};return n&&(l.searcher=ohe(c,e)),l}const a={children:[],operator:r[0]};return r.forEach(A=>{const c=i[A];q4(c)&&c.forEach(l=>{a.children.push(o(l))})}),a};return gKe(t)||(t=Jin(t)),o(t)}function uKe(t,{ignoreFieldNorm:e=ga.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 bvi(t,{ignoreFieldNorm:e=ga.ignoreFieldNorm}){t.forEach(n=>{n.score=uKe(n.matches,{ignoreFieldNorm:e})})}var Qvi=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 vvi(t){const e=[];return t.matches.forEach(n=>{if(!R2(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 Pvi(t,e,{includeMatches:n=ga.includeMatches,includeScore:o=ga.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=vvi(i)),o&&(s.score=i.score),s})}const wvi=/[\p{L}\p{M}\p{N}_]+/gu,jin=new WeakSet;function Dvi(t){jin.has(t)||(jin.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 Mvi(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||Dvi(t),e=>e.match(t)||[]):e=>e.match(wvi)||[]}function dKe({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=Mvi(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=dq(i)),o(i)}}}var Rvi=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=dKe({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 sKe(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 c=0;c<this.termSearchers.length;c++){const l=this.termSearchers[c].searchIn(t),g=this.idfWeights[c];o+=g,l.isMatch&&(i++,n+=g*(1-l.score),l.indices&&e.push(...l.indices),this.combineAll&&(this.useMask?r|=1<<c:s.add(c)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,A={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(A.indices=rKe(e)),this.combineAll&&(this.useMask?A.matchedMask=r:A.matchedTerms=s,A.termCount=this.numTerms),A}};function hKe(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 qin(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){hKe(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const A=s[a];if(A)if(Array.isArray(A))for(const c of A)hKe(t,c.v,i,o);else hKe(t,A.v,i,o)}}function Nvi(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)qin(o,i,e,n);return o}function Tvi(t,e,n,o){qin(t,e,n,o)}function kvi(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 Xin(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,A)=>a-A);for(const a of n)kvi(t,a);const o=a=>{let A=0,c=n.length;for(;A<c;){const l=A+c>>>1;n[l]<a?A=l+1:c=l}return a-A},i=n[0],r=new Map;for(const[a,A]of t.docFieldCount)r.set(a>i?o(a):a,A);t.docFieldCount=r;const s=new Map;for(const[a,A]of t.docTermFieldHits)s.set(a>i?o(a):a,A);t.docTermFieldHits=s}var X4=class{constructor(t,e,n){this.options={...ga,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Avi(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=ohe(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 iKe))throw new Error(nvi);if(this._myIndex=e||Yin(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=dKe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=Nvi(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!R2(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=dKe({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});Tvi(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&&Xin(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(oKe);this._invertedIndex&&Xin(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 u=this._docs.map((h,d)=>({item:h,refIndex:d}));return ehe(n)&&n>-1&&(u=u.slice(0,n)),u}const A=r&&ehe(n)&&n>0&&zC(t),c=s,l=(u,h)=>c(u,h)||u.idx-h.idx;let g;if(A){const u=new Qvi(n,l);zC(this._docs[0])?this._searchStringList(t,{heap:u,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:u,ignoreFieldNorm:a}),g=u.extractSorted()}else g=zC(t)?zC(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),bvi(g,{ignoreFieldNorm:a}),r&&g.sort(zC(t)?l:c),ehe(n)&&n>-1&&(g=g.slice(0,n));return Pvi(g,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:A,n:c})=>{if(!R2(a))return;const l=o.searchIn(a);if(l.isMatch){const g={score:l.score,value:a,norm:c,indices:l.indices};i&&(g.matchedMask=l.matchedMask,g.matchedTerms=l.matchedTerms,g.termCount=l.termCount);const u=[g];if(!i||this._coversAllTokens(u)){const h={item:a,idx:A,matches:u};e?(h.score=uKe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):s.push(h)}}}),s}_searchLogical(t){const e=Win(t,this.options),n=this._normalizedKeys(),o=(a,A,c)=>{if(!("children"in a)){const{keyId:h,searcher:d}=a;let m;return h===null?(m=[],n.forEach((p,_)=>{m.push(...this._findMatches({key:p,value:A[_],searcher:d}))})):m=this._findMatches({key:this._keyStore.get(h),value:this._myIndex.getValueForItemAtKeyId(A,h),searcher:d}),m&&m.length?[{idx:c,item:A,matches:m}]:[]}const{children:l,operator:g}=a,u=[];for(let h=0,d=l.length;h<d;h+=1){const m=l[h],p=o(m,A,c);if(p.length)u.push(...p);else if(g===ihe.AND)return[]}return u},i=this._myIndex.records,r=new Map,s=[];return i.forEach(({$:a,i:A})=>{if(R2(a)){const c=o(e,a,A);c.length&&(r.has(A)||(r.set(A,{idx:A,item:a,matches:[]}),s.push(r.get(A))),c.forEach(({matches:l})=>{r.get(A).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(({$:A,i:c})=>{if(!R2(A))return;const l=[];let g=!1,u=!1;if(s.forEach((h,d)=>{const m=this._findMatches({key:h,value:A[d],searcher:o});m.length?(l.push(...m),m[0].hasInverse&&(u=!0)):g=!0}),!(u&&g)&&l.length&&(!i||this._coversAllTokens(l))){const h={idx:c,item:A,matches:l};e?(h.score=uKe(h.matches,{ignoreFieldNorm:n}),e.insert(h)):a.push(h)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!R2(e))return[];const o=[];if(q4(e))e.forEach(({v:i,i:r,n:s})=>{if(!R2(i))return;const a=n.searchIn(i);if(a.isMatch){const A={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(A.matchedMask=a.matchedMask,A.matchedTerms=a.matchedTerms,A.termCount=a.termCount),o.push(A)}});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}};X4.version="7.5.0",X4.createIndex=Yin,X4.parseIndex=uvi,X4.config=ga,X4.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(avi);return ohe(t,{...ga,...n}).searchIn(e)},X4.parseQuery=Win,cKe(Evi),cKe(Rvi),X4.use=function(...t){t.forEach(e=>cKe(e))};var Fvi=X4;const Lvi="https://kicad-mod-cache.tscircuit.com";let mKe=null,hq=null,pKe=null;const Hvi=async()=>mKe||hq||(hq=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(mKe=t,hq=null,t)),hq),Ovi=async(t,e=20)=>{const n=await Hvi();return pKe||(pKe=new Fvi(n)),pKe.search(t).slice(0,e).map(o=>o.item)},Gvi=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},Uvi=t=>t.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/"),Yvi=async t=>{const e=await fetch(`${Lvi}/${Uvi(t)}`);if(!e.ok)throw new Error(`KiCad footprint fetch failed: ${e.status}`);const n=await e.text(),{KicadFootprintToCircuitJsonConverter:o}=await S2("kicad-to-circuit-json"),i=new o;return i.addFile(t.split("/").pop()??"selected-footprint.kicad_mod",n),i.runUntilFinished(),i.getOutput()},$in=t=>t?.source==="jlcpcb"||t?.source==="kicad",Kvi=async(t,e)=>{if(t.source==="jlcpcb")return $3i(t.component.partNumber,e?.jlcpcb);if(t.source==="kicad")return Yvi(t.footprint.path);throw new Error("Footprint preview is not available for this source")},zvi=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=$.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return Y.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[Y.jsxs("div",{className:"rf-relative rf-flex-grow",children:[Y.jsx(LGe,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),Y.jsx(UUe,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),Y.jsx(Xa,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):Y.jsxs(Y.Fragment,{children:[Y.jsx(LGe,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),Y.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},Vvi=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),Jvi=t=>Vvi.format(t),Zin=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"}},Wvi=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}},jvi=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}},qvi=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}},Xvi=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?Zin(e):null;return Y.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=Zin(r),a=i===s,A=Wvi(r),c=jvi(r),l=qvi(r),g=r.source==="jlcpcb"?r.component.stock:null,u=r.source==="jlcpcb"?r.component.price:null,h=r.source==="jlcpcb"?r.component.isBasic:null,d=r.source==="jlcpcb"?r.component.isDirectLookup:!1;return Y.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:[Y.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[Y.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[Y.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:[A,r.source==="jlcpcb"&&h!=null&&Y.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&&Y.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&&Y.jsx(E0i,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&g!=null?Y.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[g.toLocaleString()," in stock"]}):null]}),Y.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[l?Y.jsx("span",{className:"rf-mr-2",children:l}):null,c]})]}),Y.jsxs("div",{children:[r.source==="tscircuit.com"&&o?Y.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:Y.jsx(Xa,{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"&&g!=null?Y.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:[g.toLocaleString()," in stock"]}):null,u!=null&&Y.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:Jvi(u)})]})]},s)})})},$vi=({circuitJson:t,error:e,isLoading:n,height:o})=>Y.jsx("section",{className:"rf-flex rf-min-w-0 rf-items-center rf-justify-center",style:{height:o},children:n?Y.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:[Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),"Loading preview..."]}):e?Y.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:Y.jsxs("div",{className:"rf-flex rf-max-w-[320px] rf-items-start rf-gap-2 rf-text-sm rf-text-zinc-300",children:[Y.jsx(FGe,{className:"rf-mt-0.5 rf-h-4 rf-w-4 rf-flex-shrink-0"}),Y.jsx("span",{children:e})]})}):t?Y.jsx("div",{className:"rf-w-full rf-min-w-0 rf-overflow-hidden",children:Y.jsx(PYe,{circuitJson:t,height:o,allowEditing:!1,clickToInteractEnabled:!1,focusOnHover:!1,disablePcbGroups:!0})}):Y.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"})}),ern={importComponentDialog:101,importComponentDetailsDialog:102},Zvi=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:A})=>{const c=t?.package??null,l=c?.latest_pcb_preview_image_url,g=c?.latest_sch_preview_image_url,u=c?.latest_cad_preview_image_url,h=c?.unscoped_name?.split("/").pop()??c?.unscoped_name,d=c?.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 Y.jsx(IR,{open:e,onOpenChange:n,children:Y.jsxs(J4,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:ern.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:[Y.jsx(W4,{className:"rf-pb-4 rf-border-b",children:Y.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:Y.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Y.jsx(j4,{className:"rf-text-xl rf-font-semibold rf-truncate",children:h}),Y.jsx(CR,{children:c?.description})]})})}),Y.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[d?Y.jsxs("div",{children:[Y.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),Y.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?Y.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:d}):d})]}):null,(u||l||g)&&Y.jsx(Y.Fragment,{children:Y.jsxs("div",{children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),Y.jsxs(p4e,{value:r,onValueChange:_=>s(_),children:[Y.jsxs(sce,{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&&Y.jsx(Y3,{value:"pcb",children:"PCB"}),g&&Y.jsx(Y3,{value:"schematic",children:"Schematic"}),u&&Y.jsx(Y3,{value:"3d",children:"3D"})]}),Y.jsxs("div",{className:"rf-mt-4",children:[Y.jsx(BI,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:l?Y.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}),Y.jsx(BI,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:g?Y.jsx("img",{src:g,alt:`${h??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),Y.jsx(BI,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?Y.jsx("img",{src:u,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?Y.jsxs("section",{children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),Y.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:Y.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?Y.jsxs("section",{children:[Y.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),Y.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:Y.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?Y.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),Y.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),Y.jsxs(zO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[Y.jsx("div",{className:"rf-flex-1",children:p?Y.jsxs(Xa,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[Y.jsx(p0i,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),Y.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[Y.jsx(Xa,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),Y.jsx(Xa,{onClick:A,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},ePi=()=>{const[t,e]=$.useState(null),[n,o]=$.useState(!1),i=$.useCallback(async(s,a)=>{o(!0);try{const A=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!A.ok)throw new Error(`Failed to load package details: ${A.status}`);const c=await A.json();e(c.package??null)}catch(A){console.error("Failed to fetch package details",A),e(null)}finally{o(!1)}},[]),r=$.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},tPi=(t,e)=>{const[n,o]=$.useState({circuitJson:null,error:null,isLoading:!1});return $.useEffect(()=>{if(!t||!$in(t)){o({circuitJson:null,error:null,isLoading:!1});return}let i=!1;return o({circuitJson:null,error:null,isLoading:!0}),Kvi(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},nPi=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??[]},oPi=({sessionToken:t})=>{const[e,n]=$.useState([]),[o,i]=$.useState(!1),[r,s]=$.useState(null),[a,A]=$.useState(!1),c=$.useCallback(async g=>{const u=g.trim();if(!u)return[];i(!0),s(null);try{const d=(await nPi(u,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),A(!0)}},[t]),l=$.useCallback(()=>{n([]),i(!1),s(null),A(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:c,reset:l}},iPi=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}}},trn=(t,e)=>{const n=iPi(t);return n?e.some(i=>i.component.partNumber.toUpperCase()===n.component.partNumber)?e:[n,...e]:e},rPi=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},sPi=()=>{const[t,e]=$.useState([]),[n,o]=$.useState(!1),[i,r]=$.useState(null),[s,a]=$.useState(!1),A=$.useCallback(async l=>{const g=rPi(l);if(!g)return[];o(!0),r(null);try{const u=await j3i(g,10),h=trn(l,u.map(d=>({source:"jlcpcb",component:q3i(d)})));return e(h),h}catch(u){console.error("Error searching JLCPCB components",u);const h=trn(l,[]);return e(h),r(h.length>0?null:u instanceof Error?u.message:"Failed to search JLCPCB components"),h}finally{o(!1),a(!0)}},[]),c=$.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},aPi=()=>{const[t,e]=$.useState([]),[n,o]=$.useState(!1),[i,r]=$.useState(null),[s,a]=$.useState(!1),A=$.useCallback(async l=>{const g=l.trim();if(!g)return[];o(!0),r(null);try{const h=(await Ovi(g,20)).map(d=>({source:"kicad",footprint:Gvi(d)}));return e(h),h}catch(u){return console.error("Error searching KiCad footprints",u),e([]),r(u instanceof Error?u.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),c=$.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:A,reset:c}},APi=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},cPi=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{Aq();const A=$.useMemo(()=>APi({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),c=A.length>0,l=A.length===1,[g,u]=$.useState(A[0]??"tscircuit.com"),[h,d]=$.useState(""),[m,p]=$.useState(null),{results:_,isSearching:f,error:I,hasSearched:C,search:y,reset:x}=oPi({sessionToken:a}),{results:E,isSearching:S,error:b,hasSearched:v,search:M,reset:N}=sPi(),{results:k,isSearching:L,error:O,hasSearched:G,search:V,reset:K}=aPi(),{details:Z,isLoading:te,fetchDetails:ee,reset:X}=ePi(),[ie,se]=$.useState(null),[Ae,de]=$.useState(!1),[me,ye]=$.useState("pcb"),[le,Ce]=$.useState(null),[_e,Qe]=$.useState(!1),Te=$.useMemo(()=>({jlcpcb:{headers:n,apiBase:s}}),[s,n]),{circuitJson:Se,error:he,isLoading:Le}=tPi(m,Te),Me=$in(m);$.useEffect(()=>{Ce(null)},[m]);const Ne=$.useCallback(()=>{x(),N(),K(),p(null)},[N,K,x]);$.useEffect(()=>{t||(Ne(),d(""),de(!1),se(null),Ce(null))},[t,Ne]),$.useEffect(()=>{d(""),p(null),g==="tscircuit.com"?x():g==="jlcpcb"?N():g==="kicad"&&K()},[g,N,K,x]);const Oe=Fe=>{p(Fe),se(Fe),ye("pcb"),de(!0),X();const je=Fe.package.org_owner_tscircuit_handle,it=Fe.package.unscoped_name;if(je&&it){const At=it.split("/").pop()??it;ee(je,At)}},De=async()=>{h.trim()&&(p(null),g==="tscircuit.com"?await y(h):g==="jlcpcb"?await M(h):g==="kicad"&&await V(h))},Be=async Fe=>{try{if(Ce(null),Qe(!0),Fe.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:Fe,footprint:Fe.footprint.qualifiedName})}else if(Fe.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const je=await X3i(Fe.component.partNumber,{headers:n,apiBase:s});await r({result:Fe,tsx:je})}else if(Fe.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const je=Fe.package.org_owner_tscircuit_handle,it=Fe.package.unscoped_name;if(!je||!it)throw new Error("Missing package metadata");const At=it.split("/").pop()??it,Rt=`@tsci/${je}.${At}`;await i({result:Fe,fullPackageName:Rt})}return!0}catch(je){return console.error("Failed to import component",je),Ce(je instanceof Error?je.message:"Failed to import component"),!1}finally{Qe(!1)}};let ke=[],be=!1,Ye=null,We=!1;g==="tscircuit.com"?(ke=_,be=f,Ye=I,We=C):g==="jlcpcb"?(ke=E,be=S,Ye=b,We=v):g==="kicad"&&(ke=k,be=L,Ye=O,We=G);const tt=async()=>{if(!m)return;await Be(m)&&(e(),Ne(),d(""))},ct=Fe=>{Fe||e()},at=Fe=>{de(Fe),Fe||se(null)};return Y.jsxs(IR,{open:t,onOpenChange:ct,children:[Y.jsxs(J4,{style:{width:"calc(100vw - 2rem)",maxWidth:Me?"min(1120px, calc(100vw - 2rem))":"min(672px, calc(100vw - 2rem))",zIndex:ern.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[Y.jsxs(W4,{children:[Y.jsxs(j4,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",l?Zde[g].label:""," ","Component"]}),Y.jsx(CR,{className:"rf-text-sm",children:c?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),c?Y.jsxs(p4e,{value:g,onValueChange:Fe=>u(Fe),className:"rf-min-w-0 rf-w-full",children:[!l&&Y.jsx(sce,{className:"rf-flex rf-w-full rf-gap-2",children:A.map(Fe=>Y.jsx(Y3,{value:Fe,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Zde[Fe].label},Fe))}),Y.jsxs("div",{className:"rf-min-w-0",style:Me?{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(360px, 0.95fr)",gap:"1.5rem",alignItems:"start"}:void 0,children:[Y.jsxs("div",{className:"rf-min-w-0",children:[Y.jsx(zvi,{query:h,placeholder:Zde[g].placeholder,isSearching:be,onQueryChange:d,onSubmit:De}),Y.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:be?Y.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[Y.jsx(x2,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),Y.jsx("p",{children:"Searching..."})]}):ke.length>0?Y.jsx(Xvi,{results:ke,selected:m,onSelect:p,onShowDetails:g==="tscircuit.com"?Oe:void 0}):Y.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:Ye?`Error: ${Ye}`:We?Zde[g].emptyMessage:"Enter a search term to find components"})})]}),Me?Y.jsx("div",{className:"rf-mt-4",children:Y.jsx($vi,{circuitJson:Se,error:he,isLoading:Le,height:325})}):null]})]}):null,le?Y.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:le}):null,Y.jsxs(zO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[Y.jsx(Xa,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),Y.jsx(Xa,{onClick:tt,disabled:!m||_e,className:"rf-order-1 sm:rf-order-2",children:_e?Y.jsx(x2,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),Y.jsx(Zvi,{packageResult:ie,isOpen:Ae,onOpenChange:at,isLoading:te,details:Z,previewTab:me,onPreviewTabChange:Fe=>ye(Fe),isSubmitting:_e,onImport:()=>{ie&&Be(ie).then(Fe=>{Fe&&(de(!1),e(),Ne(),d(""))})}})]})},lPi=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},nrn=t=>{const e=Od(s=>s.pushEvent),n=Od(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const c=s.package.unscoped_name??s.package.name;await Js.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${c}"`,success:`Install requested for "${c}"`,error:l=>`Failed to request install: ${l instanceof Error?l.message:String(l)}`})},i=async({footprint:s})=>{await Js.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 c=`imports/${lPi(a)}.tsx`;await Js.promise(n(c,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${c}"`,error:l=>`Failed to import component: ${l instanceof Error?l.message:String(l)}`})};return Y.jsx(cPi,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};nrn.displayName="ImportComponentDialogForCli";const gPi=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToAltiumZip:n}=await Promise.resolve().then(()=>TJi),o=await n(t,e);return new Blob([new Uint8Array(o)],{type:"application/zip"})},uPi=async({circuitJson:t,projectName:e})=>{await Js.promise((async()=>{const n=await gPi({circuitJson:t,projectName:e});D2(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 _Ke={exports:{}},orn;function dPi(){return orn||(orn=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(l,g){if(!r[l]){if(!i[l]){var u=typeof uP=="function"&&uP;if(!g&&u)return u(l,!0);if(A)return A(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 A=typeof uP=="function"&&uP,c=0;c<s.length;c++)a(s[c]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(c){for(var l,g,u,h,d,m,p,_=[],f=0,I=c.length,C=I,y=s.getTypeOf(c)!=="string";f<c.length;)C=I-f,u=y?(l=c[f++],g=f<I?c[f++]:0,f<I?c[f++]:0):(l=c.charCodeAt(f++),g=f<I?c.charCodeAt(f++):0,f<I?c.charCodeAt(f++):0),h=l>>2,d=(3&l)<<4|g>>4,m=1<C?(15&g)<<2|u>>6:64,p=2<C?63&u:64,_.push(A.charAt(h)+A.charAt(d)+A.charAt(m)+A.charAt(p));return _.join("")},r.decode=function(c){var l,g,u,h,d,m,p=0,_=0,f="data:";if(c.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var I,C=3*(c=c.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(c.charAt(c.length-1)===A.charAt(64)&&C--,c.charAt(c.length-2)===A.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<c.length;)l=A.indexOf(c.charAt(p++))<<2|(h=A.indexOf(c.charAt(p++)))>>4,g=(15&h)<<4|(d=A.indexOf(c.charAt(p++)))>>2,u=(3&d)<<6|(m=A.indexOf(c.charAt(p++))),I[_++]=l,d!==64&&(I[_++]=g),m!==64&&(I[_++]=u);return I}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),A=o("./stream/Crc32Probe"),c=o("./stream/DataLengthProbe");function l(g,u,h,d,m){this.compressedSize=g,this.uncompressedSize=u,this.crc32=h,this.compression=d,this.compressedContent=m}l.prototype={getContentWorker:function(){var g=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new c("data_length")),u=this;return g.on("end",function(){if(this.streamInfo.data_length!==u.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),g},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(g,u,h){return g.pipe(new A).pipe(new c("uncompressedSize")).pipe(u.compressWorker(h)).pipe(new c("compressedSize")).withStreamInfo("compression",u)},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 A,c=[],l=0;l<256;l++){A=l;for(var g=0;g<8;g++)A=1&A?3988292384^A>>>1:A>>>1;c[l]=A}return c})();i.exports=function(A,c){return A!==void 0&&A.length?s.getTypeOf(A)!=="string"?(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g[p])];return-1^l})(0|c,A,A.length,0):(function(l,g,u,h){var d=a,m=h+u;l^=-1;for(var p=h;p<m;p++)l=l>>>8^d[255&(l^g.charCodeAt(p))];return-1^l})(0|c,A,A.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"),A=o("./utils"),c=o("./stream/GenericWorker"),l=s?"uint8array":"array";function g(u,h){c.call(this,"FlateWorker/"+u),this._pako=null,this._pakoAction=u,this._pakoOptions=h,this.meta={}}r.magic="\b\0",A.inherits(g,c),g.prototype.processChunk=function(u){this.meta=u.meta,this._pako===null&&this._createPako(),this._pako.push(A.transformTo(l,u.data),!1)},g.prototype.flush=function(){c.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},g.prototype.cleanUp=function(){c.prototype.cleanUp.call(this),this._pako=null},g.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var u=this;this._pako.onData=function(h){u.push({data:h,meta:u.meta})}},r.compressWorker=function(u){return new g("Deflate",u)},r.uncompressWorker=function(){return new g("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(d,m){var p,_="";for(p=0;p<m;p++)_+=String.fromCharCode(255&d),d>>>=8;return _}function a(d,m,p,_,f,I){var C,y,x=d.file,E=d.compression,S=I!==l.utf8encode,b=A.transformTo("string",I(x.name)),v=A.transformTo("string",l.utf8encode(x.name)),M=x.comment,N=A.transformTo("string",I(M)),k=A.transformTo("string",l.utf8encode(M)),L=v.length!==x.name.length,O=k.length!==M.length,G="",V="",K="",Z=x.dir,te=x.date,ee={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(ee.crc32=d.crc32,ee.compressedSize=d.compressedSize,ee.uncompressedSize=d.uncompressedSize);var X=0;m&&(X|=8),S||!L&&!O||(X|=2048);var ie=0,se=0;Z&&(ie|=16),f==="UNIX"?(se=798,ie|=(function(de,me){var ye=de;return de||(ye=me?16893:33204),(65535&ye)<<16})(x.unixPermissions,Z)):(se=20,ie|=(function(de){return 63&(de||0)})(x.dosPermissions)),C=te.getUTCHours(),C<<=6,C|=te.getUTCMinutes(),C<<=5,C|=te.getUTCSeconds()/2,y=te.getUTCFullYear()-1980,y<<=4,y|=te.getUTCMonth()+1,y<<=5,y|=te.getUTCDate(),L&&(V=s(1,1)+s(g(b),4)+v,G+="up"+s(V.length,2)+V),O&&(K=s(1,1)+s(g(N),4)+k,G+="uc"+s(K.length,2)+K);var Ae="";return Ae+=`
|
|
5776
5776
|
\0`,Ae+=s(X,2),Ae+=E.magic,Ae+=s(C,2),Ae+=s(y,2),Ae+=s(ee.crc32,4),Ae+=s(ee.compressedSize,4),Ae+=s(ee.uncompressedSize,4),Ae+=s(b.length,2),Ae+=s(G.length,2),{fileRecord:u.LOCAL_FILE_HEADER+Ae+b+G,dirRecord:u.CENTRAL_FILE_HEADER+s(se,2)+Ae+s(N.length,2)+"\0\0\0\0"+s(ie,4)+s(_,4)+b+G+N}}var A=o("../utils"),c=o("../stream/GenericWorker"),l=o("../utf8"),g=o("../crc32"),u=o("../signature");function h(d,m,p,_){c.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=m,this.zipPlatform=p,this.encodeFileName=_,this.streamFiles=d,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}A.inherits(h,c),h.prototype.push=function(d){var m=d.meta.percent||0,p=this.entriesCount,_=this._sources.length;this.accumulate?this.contentBuffer.push(d):(this.bytesWritten+=d.data.length,c.prototype.push.call(this,{data:d.data,meta:{currentFile:this.currentFile,percent:p?(m+100*(p-_-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(_){return u.DATA_DESCRIPTOR+s(_.crc32,4)+s(_.compressedSize,4)+s(_.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,_=(function(f,I,C,y,x){var E=A.transformTo("string",x(y));return u.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(f,2)+s(f,2)+s(I,4)+s(C,4)+s(E.length,2)+E})(this.dirRecords.length,p,d,this.zipComment,this.encodeFileName);this.push({data:_,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!!c.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(!c.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(){c.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(A,c,l){var g=new a(c.streamFiles,l,c.platform,c.encodeFileName),u=0;try{A.forEach(function(h,d){u++;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,c.compression),p=d.options.compressionOptions||c.compressionOptions||{},_=d.dir,f=d.date;d._compressWorker(m,p).withStreamInfo("file",{name:h,dir:_,date:f,comment:d.comment||"",unixPermissions:d.unixPermissions,dosPermissions:d.dosPermissions}).pipe(g)}),g.entriesCount=u}catch(h){g.error(h)}return g}},{"../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 A in this)typeof this[A]!="function"&&(a[A]=this[A]);return a}}(s.prototype=o("./object")).loadAsync=o("./load"),s.support=o("./support"),s.defaults=o("./defaults"),s.version="3.10.1",s.loadAsync=function(a,A){return new s().loadAsync(a,A)},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"),A=o("./utf8"),c=o("./zipEntries"),l=o("./stream/Crc32Probe"),g=o("./nodejsUtils");function u(h){return new a.Promise(function(d,m){var p=h.decompressed.getContentWorker().pipe(new l);p.on("error",function(_){m(_)}).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:A.utf8decode}),g.isNode&&g.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 _=new c(d);return _.load(p),_}).then(function(p){var _=[a.Promise.resolve(p)],f=p.files;if(d.checkCRC32)for(var I=0;I<f.length;I++)_.push(u(f[I]));return a.Promise.all(_)}).then(function(p){for(var _=p.shift(),f=_.files,I=0;I<f.length;I++){var C=f[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 _.zipComment.length&&(m.comment=_.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 A(c,l){a.call(this,"Nodejs stream input adapter for "+c),this._upstreamEnded=!1,this._bindStream(l)}s.inherits(A,a),A.prototype._bindStream=function(c){var l=this;(this._stream=c).pause(),c.on("data",function(g){l.push({data:g,meta:{percent:0}})}).on("error",function(g){l.isPaused?this.generatedError=g:l.error(g)}).on("end",function(){l.isPaused?l._upstreamEnded=!0:l.end()})},A.prototype.pause=function(){return!!a.prototype.pause.call(this)&&(this._stream.pause(),!0)},A.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},i.exports=A},{"../stream/GenericWorker":28,"../utils":32}],13:[function(o,i,r){var s=o("readable-stream").Readable;function a(A,c,l){s.call(this,c),this._helper=A;var g=this;A.on("data",function(u,h){g.push(u)||g._helper.pause(),l&&l(h)}).on("error",function(u){g.emit("error",u)}).on("end",function(){g.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,S){var b,v=A.getTypeOf(E),M=A.extend(S||{},g);M.date=M.date||new Date,M.compression!==null&&(M.compression=M.compression.toUpperCase()),typeof M.unixPermissions=="string"&&(M.unixPermissions=parseInt(M.unixPermissions,8)),M.unixPermissions&&16384&M.unixPermissions&&(M.dir=!0),M.dosPermissions&&16&M.dosPermissions&&(M.dir=!0),M.dir&&(x=f(x)),M.createFolders&&(b=_(x))&&I.call(this,b,!0);var N=v==="string"&&M.binary===!1&&M.base64===!1;S&&S.binary!==void 0||(M.binary=!N),(E instanceof u&&E.uncompressedSize===0||M.dir||!E||E.length===0)&&(M.base64=!1,M.binary=!0,E="",M.compression="STORE",v="string");var k=null;k=E instanceof u||E instanceof c?E:m.isNode&&m.isStream(E)?new p(x,E):A.prepareContent(x,E,M.binary,M.optimizedBinaryString,M.base64);var L=new h(x,k,M);this.files[x]=L}var a=o("./utf8"),A=o("./utils"),c=o("./stream/GenericWorker"),l=o("./stream/StreamHelper"),g=o("./defaults"),u=o("./compressedObject"),h=o("./zipObject"),d=o("./generate"),m=o("./nodejsUtils"),p=o("./nodejs/NodejsStreamInputAdapter"),_=function(x){x.slice(-1)==="/"&&(x=x.substring(0,x.length-1));var E=x.lastIndexOf("/");return 0<E?x.substring(0,E):""},f=function(x){return x.slice(-1)!=="/"&&(x+="/"),x},I=function(x,E){return E=E!==void 0?E:g.createFolders,x=f(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,S,b;for(E in this.files)b=this.files[E],(S=E.slice(this.root.length,E.length))&&E.slice(0,this.root.length)===this.root&&x(S,b)},filter:function(x){var E=[];return this.forEach(function(S,b){x(S,b)&&E.push(b)}),E},file:function(x,E,S){if(arguments.length!==1)return x=this.root+x,s.call(this,x,E,S),this;if(C(x)){var b=x;return this.filter(function(M,N){return!N.dir&&b.test(M)})}var v=this.files[this.root+x];return v&&!v.dir?v:null},folder:function(x){if(!x)return this;if(C(x))return this.filter(function(v,M){return M.dir&&x.test(v)});var E=this.root+x,S=I.call(this,E),b=this.clone();return b.root=S.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 S=this.filter(function(v,M){return M.name.slice(0,x.length)===x}),b=0;b<S.length;b++)delete this.files[S[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,S={};try{if((S=A.extend(x||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:a.utf8encode})).type=S.type.toLowerCase(),S.compression=S.compression.toUpperCase(),S.type==="binarystring"&&(S.type="string"),!S.type)throw new Error("No output type specified.");A.checkSupport(S.type),S.platform!=="darwin"&&S.platform!=="freebsd"&&S.platform!=="linux"&&S.platform!=="sunos"||(S.platform="UNIX"),S.platform==="win32"&&(S.platform="DOS");var b=S.comment||this.comment||"";E=d.generateWorker(this,S,b)}catch(v){(E=new c("error")).error(v)}return new l(E,S.type||"string",S.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(A){s.call(this,A);for(var c=0;c<this.data.length;c++)A[c]=255&A[c]}o("../utils").inherits(a,s),a.prototype.byteAt=function(A){return this.data[this.zero+A]},a.prototype.lastIndexOfSignature=function(A){for(var c=A.charCodeAt(0),l=A.charCodeAt(1),g=A.charCodeAt(2),u=A.charCodeAt(3),h=this.length-4;0<=h;--h)if(this.data[h]===c&&this.data[h+1]===l&&this.data[h+2]===g&&this.data[h+3]===u)return h-this.zero;return-1},a.prototype.readAndCheckSignature=function(A){var c=A.charCodeAt(0),l=A.charCodeAt(1),g=A.charCodeAt(2),u=A.charCodeAt(3),h=this.readData(4);return c===h[0]&&l===h[1]&&g===h[2]&&u===h[3]},a.prototype.readData=function(A){if(this.checkOffset(A),A===0)return[];var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./DataReader":18}],18:[function(o,i,r){var s=o("../utils");function a(A){this.data=A,this.length=A.length,this.index=0,this.zero=0}a.prototype={checkOffset:function(A){this.checkIndex(this.index+A)},checkIndex:function(A){if(this.length<this.zero+A||A<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+A+"). Corrupted zip ?")},setIndex:function(A){this.checkIndex(A),this.index=A},skip:function(A){this.setIndex(this.index+A)},byteAt:function(){},readInt:function(A){var c,l=0;for(this.checkOffset(A),c=this.index+A-1;c>=this.index;c--)l=(l<<8)+this.byteAt(c);return this.index+=A,l},readString:function(A){return s.transformTo("string",this.readData(A))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var A=this.readInt(4);return new Date(Date.UTC(1980+(A>>25&127),(A>>21&15)-1,A>>16&31,A>>11&31,A>>5&63,(31&A)<<1))}},i.exports=a},{"../utils":32}],19:[function(o,i,r){var s=o("./Uint8ArrayReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.readData=function(A){this.checkOffset(A);var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(o,i,r){var s=o("./DataReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.byteAt=function(A){return this.data.charCodeAt(this.zero+A)},a.prototype.lastIndexOfSignature=function(A){return this.data.lastIndexOf(A)-this.zero},a.prototype.readAndCheckSignature=function(A){return A===this.readData(4)},a.prototype.readData=function(A){this.checkOffset(A);var c=this.data.slice(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./DataReader":18}],21:[function(o,i,r){var s=o("./ArrayReader");function a(A){s.call(this,A)}o("../utils").inherits(a,s),a.prototype.readData=function(A){if(this.checkOffset(A),A===0)return new Uint8Array(0);var c=this.data.subarray(this.zero+this.index,this.zero+this.index+A);return this.index+=A,c},i.exports=a},{"../utils":32,"./ArrayReader":17}],22:[function(o,i,r){var s=o("../utils"),a=o("../support"),A=o("./ArrayReader"),c=o("./StringReader"),l=o("./NodeBufferReader"),g=o("./Uint8ArrayReader");i.exports=function(u){var h=s.getTypeOf(u);return s.checkSupport(h),h!=="string"||a.uint8array?h==="nodebuffer"?new l(u):a.uint8array?new g(s.transformTo("uint8array",u)):new A(s.transformTo("array",u)):new c(u)}},{"../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 A(c){s.call(this,"ConvertWorker to "+c),this.destType=c}a.inherits(A,s),A.prototype.processChunk=function(c){this.push({data:a.transformTo(this.destType,c.data),meta:c.meta})},i.exports=A},{"../utils":32,"./GenericWorker":28}],25:[function(o,i,r){var s=o("./GenericWorker"),a=o("../crc32");function A(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}o("../utils").inherits(A,s),A.prototype.processChunk=function(c){this.streamInfo.crc32=a(c.data,this.streamInfo.crc32||0),this.push(c)},i.exports=A},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function A(c){a.call(this,"DataLengthProbe for "+c),this.propName=c,this.withStreamInfo(c,0)}s.inherits(A,a),A.prototype.processChunk=function(c){if(c){var l=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=l+c.data.length}a.prototype.processChunk.call(this,c)},i.exports=A},{"../utils":32,"./GenericWorker":28}],27:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function A(c){a.call(this,"DataWorker");var l=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,c.then(function(g){l.dataIsReady=!0,l.data=g,l.max=g&&g.length||0,l.type=s.getTypeOf(g),l.isPaused||l._tickAndRepeat()},function(g){l.error(g)})}s.inherits(A,a),A.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this.data=null},A.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},A.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},A.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var c=null,l=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":c=this.data.substring(this.index,l);break;case"uint8array":c=this.data.subarray(this.index,l);break;case"array":case"nodebuffer":c=this.data.slice(this.index,l)}return this.index=l,this.push({data:c,meta:{percent:this.max?this.index/this.max*100:0}})},i.exports=A},{"../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,A){return this._listeners[a].push(A),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,A){if(this._listeners[a])for(var c=0;c<this._listeners[a].length;c++)this._listeners[a][c].call(this,A)},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 A=this;return a.on("data",function(c){A.processChunk(c)}),a.on("end",function(){A.end()}),a.on("error",function(c){A.error(c)}),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,A){return this.extraStreamInfo[a]=A,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"),A=o("./GenericWorker"),c=o("../base64"),l=o("../support"),g=o("../external"),u=null;if(l.nodestream)try{u=o("../nodejs/NodejsStreamOutputAdapter")}catch{}function h(m,p){return new g.Promise(function(_,f){var I=[],C=m._internalType,y=m._outputType,x=m._mimeType;m.on("data",function(E,S){I.push(E),p&&p(S)}).on("error",function(E){I=[],f(E)}).on("end",function(){try{var E=(function(S,b,v){switch(S){case"blob":return s.newBlob(s.transformTo("arraybuffer",b),v);case"base64":return c.encode(b);default:return s.transformTo(S,b)}})(y,(function(S,b){var v,M=0,N=null,k=0;for(v=0;v<b.length;v++)k+=b[v].length;switch(S){case"string":return b.join("");case"array":return Array.prototype.concat.apply([],b);case"uint8array":for(N=new Uint8Array(k),v=0;v<b.length;v++)N.set(b[v],M),M+=b[v].length;return N;case"nodebuffer":return Buffer.concat(b);default:throw new Error("concat : unsupported type '"+S+"'")}})(C,I),x);_(E)}catch(S){f(S)}I=[]}).resume()})}function d(m,p,_){var f=p;switch(p){case"blob":case"arraybuffer":f="uint8array";break;case"base64":f="string"}try{this._internalType=f,this._outputType=p,this._mimeType=_,s.checkSupport(f),this._worker=m.pipe(new a(f)),m.lock()}catch(I){this._worker=new A("error"),this._worker.error(I)}}d.prototype={accumulate:function(m){return h(this,m)},on:function(m,p){var _=this;return m==="data"?this._worker.on(m,function(f){p.call(_,f.data,f.meta)}):this._worker.on(m,function(){s.delay(p,arguments,_)}),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 u(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"),A=o("./nodejsUtils"),c=o("./stream/GenericWorker"),l=new Array(256),g=0;g<256;g++)l[g]=252<=g?6:248<=g?5:240<=g?4:224<=g?3:192<=g?2:1;l[254]=l[254]=1;function u(){c.call(this,"utf-8 decode"),this.leftOver=null}function h(){c.call(this,"utf-8 encode")}r.utf8encode=function(d){return a.nodebuffer?A.newBufferFrom(d,"utf-8"):(function(m){var p,_,f,I,C,y=m.length,x=0;for(I=0;I<y;I++)(64512&(_=m.charCodeAt(I)))==55296&&I+1<y&&(64512&(f=m.charCodeAt(I+1)))==56320&&(_=65536+(_-55296<<10)+(f-56320),I++),x+=_<128?1:_<2048?2:_<65536?3:4;for(p=a.uint8array?new Uint8Array(x):new Array(x),I=C=0;C<x;I++)(64512&(_=m.charCodeAt(I)))==55296&&I+1<y&&(64512&(f=m.charCodeAt(I+1)))==56320&&(_=65536+(_-55296<<10)+(f-56320),I++),_<128?p[C++]=_:(_<2048?p[C++]=192|_>>>6:(_<65536?p[C++]=224|_>>>12:(p[C++]=240|_>>>18,p[C++]=128|_>>>12&63),p[C++]=128|_>>>6&63),p[C++]=128|63&_);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=_=0;p<C;)if((f=m[p++])<128)y[_++]=f;else if(4<(I=l[f]))y[_++]=65533,p+=I-1;else{for(f&=I===2?31:I===3?15:7;1<I&&p<C;)f=f<<6|63&m[p++],I--;1<I?y[_++]=65533:f<65536?y[_++]=f:(f-=65536,y[_++]=55296|f>>10&1023,y[_++]=56320|1023&f)}return y.length!==_&&(y.subarray?y=y.subarray(0,_):y.length=_),s.applyFromCharCode(y)})(d=s.transformTo(a.uint8array?"uint8array":"array",d))},s.inherits(u,c),u.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 _=(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),f=m;_!==m.length&&(a.uint8array?(f=m.subarray(0,_),this.leftOver=m.subarray(_,m.length)):(f=m.slice(0,_),this.leftOver=m.slice(_,m.length))),this.push({data:r.utf8decode(f),meta:d.meta})},u.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:r.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},r.Utf8DecodeWorker=u,s.inherits(h,c),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"),A=o("./nodejsUtils"),c=o("./external");function l(p){return p}function g(p,_){for(var f=0;f<p.length;++f)_[f]=255&p.charCodeAt(f);return _}o("setimmediate"),r.newBlob=function(p,_){r.checkSupport("blob");try{return new Blob([p],{type:_})}catch{try{var f=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return f.append(p),f.getBlob(_)}catch{throw new Error("Bug : can't construct the Blob.")}}};var u={stringifyByChunk:function(p,_,f){var I=[],C=0,y=p.length;if(y<=f)return String.fromCharCode.apply(null,p);for(;C<y;)_==="array"||_==="nodebuffer"?I.push(String.fromCharCode.apply(null,p.slice(C,Math.min(C+f,y)))):I.push(String.fromCharCode.apply(null,p.subarray(C,Math.min(C+f,y)))),C+=f;return I.join("")},stringifyByChar:function(p){for(var _="",f=0;f<p.length;f++)_+=String.fromCharCode(p[f]);return _},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,A.allocBuffer(1)).length===1}catch{return!1}})()}};function h(p){var _=65536,f=r.getTypeOf(p),I=!0;if(f==="uint8array"?I=u.applyCanBeUsed.uint8array:f==="nodebuffer"&&(I=u.applyCanBeUsed.nodebuffer),I)for(;1<_;)try{return u.stringifyByChunk(p,f,_)}catch{_=Math.floor(_/2)}return u.stringifyByChar(p)}function d(p,_){for(var f=0;f<p.length;f++)_[f]=p[f];return _}r.applyFromCharCode=h;var m={};m.string={string:l,array:function(p){return g(p,new Array(p.length))},arraybuffer:function(p){return m.string.uint8array(p).buffer},uint8array:function(p){return g(p,new Uint8Array(p.length))},nodebuffer:function(p){return g(p,A.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 A.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 A.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 A.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,_){if(_=_||"",!p)return _;r.checkSupport(p);var f=r.getTypeOf(_);return m[f][p](_)},r.resolve=function(p){for(var _=p.split("/"),f=[],I=0;I<_.length;I++){var C=_[I];C==="."||C===""&&I!==0&&I!==_.length-1||(C===".."?f.pop():f.push(C))}return f.join("/")},r.getTypeOf=function(p){return typeof p=="string"?"string":Object.prototype.toString.call(p)==="[object Array]"?"array":s.nodebuffer&&A.isBuffer(p)?"nodebuffer":s.uint8array&&p instanceof Uint8Array?"uint8array":s.arraybuffer&&p instanceof 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(f=0;f<(p||"").length;f++)I+="\\x"+((_=p.charCodeAt(f))<16?"0":"")+_.toString(16).toUpperCase();return I},r.delay=function(p,_,f){setImmediate(function(){p.apply(f||null,_||[])})},r.inherits=function(p,_){function f(){}f.prototype=_.prototype,p.prototype=new f},r.extend=function(){var p,_,f={};for(p=0;p<arguments.length;p++)for(_ in arguments[p])Object.prototype.hasOwnProperty.call(arguments[p],_)&&f[_]===void 0&&(f[_]=arguments[p][_]);return f},r.prepareContent=function(p,_,f,I,C){return c.Promise.resolve(_).then(function(y){return s.blob&&(y instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(y))!==-1)&&typeof FileReader<"u"?new c.Promise(function(x,E){var S=new FileReader;S.onload=function(b){x(b.target.result)},S.onerror=function(b){E(b.target.error)},S.readAsArrayBuffer(y)}):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):f&&I!==!0&&(y=(function(E){return g(E,s.uint8array?new Uint8Array(E.length):new Array(E.length))})(y))),y):c.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"),A=o("./signature"),c=o("./zipEntry"),l=o("./support");function g(u){this.files=[],this.loadOptions=u}g.prototype={checkSignature:function(u){if(!this.reader.readAndCheckSignature(u)){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(u)+")")}},isSignature:function(u,h){var d=this.reader.index;this.reader.setIndex(u);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 u=this.reader.readData(this.zipCommentLength),h=l.uint8array?"uint8array":"array",d=a.transformTo(h,u);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 u,h,d,m=this.zip64EndOfCentralSize-44;0<m;)u=this.reader.readInt(2),h=this.reader.readInt(4),d=this.reader.readData(h),this.zip64ExtensibleData[u]={id:u,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 u,h;for(u=0;u<this.files.length;u++)h=this.files[u],this.reader.setIndex(h.localHeaderOffset),this.checkSignature(A.LOCAL_FILE_HEADER),h.readLocalPart(this.reader),h.handleUTF8(),h.processAttributes()},readCentralDir:function(){var u;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(A.CENTRAL_FILE_HEADER);)(u=new c({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(u);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 u=this.reader.lastIndexOfSignature(A.CENTRAL_DIRECTORY_END);if(u<0)throw this.isSignature(0,A.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(u);var h=u;if(this.checkSignature(A.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,(u=this.reader.lastIndexOfSignature(A.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(u),this.checkSignature(A.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,A.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(A.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(A.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,A.CENTRAL_FILE_HEADER)||(this.reader.zero=m);else if(m<0)throw new Error("Corrupted zip: missing "+Math.abs(m)+" bytes.")},prepareReader:function(u){this.reader=s(u)},load:function(u){this.prepareReader(u),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},i.exports=g},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),A=o("./compressedObject"),c=o("./crc32"),l=o("./utf8"),g=o("./compressions"),u=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(_){for(var f in g)if(Object.prototype.hasOwnProperty.call(g,f)&&g[f].magic===_)return g[f];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 A(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<f;)m=d.readInt(2),p=d.readInt(2),_=d.readData(p),this.extraFields[m]={id:m,length:p,value:_};d.setIndex(f)},handleUTF8:function(){var d=u.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 _=this.findExtraFieldUnicodeComment();if(_!==null)this.fileCommentStr=_;else{var f=a.transformTo(d,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(f)}}},findExtraFieldUnicodePath:function(){var d=this.extraFields[28789];if(d){var m=s(d.value);return m.readInt(1)!==1||c(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||c(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,_){this.name=m,this.dir=_.dir,this.date=_.date,this.comment=_.comment,this.unixPermissions=_.unixPermissions,this.dosPermissions=_.dosPermissions,this._data=p,this._dataBinary=_.binary,this.options={compression:_.compression,compressionOptions:_.compressionOptions}}var a=o("./stream/StreamHelper"),A=o("./stream/DataWorker"),c=o("./utf8"),l=o("./compressedObject"),g=o("./stream/GenericWorker");s.prototype={internalStream:function(m){var p=null,_="string";try{if(!m)throw new Error("No output type specified.");var f=(_=m.toLowerCase())==="string"||_==="text";_!=="binarystring"&&_!=="text"||(_="string"),p=this._decompressWorker();var I=!this._dataBinary;I&&!f&&(p=p.pipe(new c.Utf8EncodeWorker)),!I&&f&&(p=p.pipe(new c.Utf8DecodeWorker))}catch(C){(p=new g("error")).error(C)}return new a(p,_,"")},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 _=this._decompressWorker();return this._dataBinary||(_=_.pipe(new c.Utf8EncodeWorker)),l.createWorkerFrom(_,m,p)},_decompressWorker:function(){return this._data instanceof l?this._data.getContentWorker():this._data instanceof g?this._data:new A(this._data)}};for(var u=["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<u.length;d++)s.prototype[u[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,A,c=s.MutationObserver||s.WebKitMutationObserver;if(c){var l=0,g=new c(m),u=s.document.createTextNode("");g.observe(u,{characterData:!0}),a=function(){u.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,_;A=!0;for(var f=d.length;f;){for(_=d,d=[],p=-1;++p<f;)_[p]();f=d.length}A=!1}i.exports=function(p){d.push(p)!==1||A||a()}}).call(this,typeof b1<"u"?b1:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(o,i,r){var s=o("immediate");function a(){}var A={},c=["REJECTED"],l=["FULFILLED"],g=["PENDING"];function u(f){if(typeof f!="function")throw new TypeError("resolver must be a function");this.state=g,this.queue=[],this.outcome=void 0,f!==a&&p(this,f)}function h(f,I,C){this.promise=f,typeof I=="function"&&(this.onFulfilled=I,this.callFulfilled=this.otherCallFulfilled),typeof C=="function"&&(this.onRejected=C,this.callRejected=this.otherCallRejected)}function d(f,I,C){s(function(){var y;try{y=I(C)}catch(x){return A.reject(f,x)}y===f?A.reject(f,new TypeError("Cannot resolve promise with itself")):A.resolve(f,y)})}function m(f){var I=f&&f.then;if(f&&(typeof f=="object"||typeof f=="function")&&typeof I=="function")return function(){I.apply(f,arguments)}}function p(f,I){var C=!1;function y(S){C||(C=!0,A.reject(f,S))}function x(S){C||(C=!0,A.resolve(f,S))}var E=_(function(){I(x,y)});E.status==="error"&&y(E.value)}function _(f,I){var C={};try{C.value=f(I),C.status="success"}catch(y){C.status="error",C.value=y}return C}(i.exports=u).prototype.finally=function(f){if(typeof f!="function")return this;var I=this.constructor;return this.then(function(C){return I.resolve(f()).then(function(){return C})},function(C){return I.resolve(f()).then(function(){throw C})})},u.prototype.catch=function(f){return this.then(null,f)},u.prototype.then=function(f,I){if(typeof f!="function"&&this.state===l||typeof I!="function"&&this.state===c)return this;var C=new this.constructor(a);return this.state!==g?d(C,this.state===l?f:I,this.outcome):this.queue.push(new h(C,f,I)),C},h.prototype.callFulfilled=function(f){A.resolve(this.promise,f)},h.prototype.otherCallFulfilled=function(f){d(this.promise,this.onFulfilled,f)},h.prototype.callRejected=function(f){A.reject(this.promise,f)},h.prototype.otherCallRejected=function(f){d(this.promise,this.onRejected,f)},A.resolve=function(f,I){var C=_(m,I);if(C.status==="error")return A.reject(f,C.value);var y=C.value;if(y)p(f,y);else{f.state=l,f.outcome=I;for(var x=-1,E=f.queue.length;++x<E;)f.queue[x].callFulfilled(I)}return f},A.reject=function(f,I){f.state=c,f.outcome=I;for(var C=-1,y=f.queue.length;++C<y;)f.queue[C].callRejected(I);return f},u.resolve=function(f){return f instanceof this?f:A.resolve(new this(a),f)},u.reject=function(f){var I=new this(a);return A.reject(I,f)},u.all=function(f){var I=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=f.length,y=!1;if(!C)return this.resolve([]);for(var x=new Array(C),E=0,S=-1,b=new this(a);++S<C;)v(f[S],S);return b;function v(M,N){I.resolve(M).then(function(k){x[N]=k,++E!==C||y||(y=!0,A.resolve(b,x))},function(k){y||(y=!0,A.reject(b,k))})}},u.race=function(f){var I=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=f.length,y=!1;if(!C)return this.resolve([]);for(var x=-1,E=new this(a);++x<C;)S=f[x],I.resolve(S).then(function(b){y||(y=!0,A.resolve(E,b))},function(b){y||(y=!0,A.reject(E,b))});var S;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"),A=o("./utils/strings"),c=o("./zlib/messages"),l=o("./zlib/zstream"),g=Object.prototype.toString,u=0,h=-1,d=0,m=8;function p(f){if(!(this instanceof p))return new p(f);this.options=a.assign({level:h,method:m,chunkSize:16384,windowBits:15,memLevel:8,strategy:d,to:""},f||{});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!==u)throw new Error(c[C]);if(I.header&&s.deflateSetHeader(this.strm,I.header),I.dictionary){var y;if(y=typeof I.dictionary=="string"?A.string2buf(I.dictionary):g.call(I.dictionary)==="[object ArrayBuffer]"?new Uint8Array(I.dictionary):I.dictionary,(C=s.deflateSetDictionary(this.strm,y))!==u)throw new Error(c[C]);this._dict_set=!0}}function _(f,I){var C=new p(I);if(C.push(f,!0),C.err)throw C.msg||c[C.err];return C.result}p.prototype.push=function(f,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 f=="string"?x.input=A.string2buf(f):g.call(f)==="[object ArrayBuffer]"?x.input=new Uint8Array(f):x.input=f,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!==u)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(A.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===u):y!==2||(this.onEnd(u),!(x.avail_out=0))},p.prototype.onData=function(f){this.chunks.push(f)},p.prototype.onEnd=function(f){f===u&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=a.flattenChunks(this.chunks)),this.chunks=[],this.err=f,this.msg=this.strm.msg},r.Deflate=p,r.deflate=_,r.deflateRaw=function(f,I){return(I=I||{}).raw=!0,_(f,I)},r.gzip=function(f,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"),A=o("./utils/strings"),c=o("./zlib/constants"),l=o("./zlib/messages"),g=o("./zlib/zstream"),u=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 _=this.options;_.raw&&0<=_.windowBits&&_.windowBits<16&&(_.windowBits=-_.windowBits,_.windowBits===0&&(_.windowBits=-15)),!(0<=_.windowBits&&_.windowBits<16)||p&&p.windowBits||(_.windowBits+=32),15<_.windowBits&&_.windowBits<48&&(15&_.windowBits)==0&&(_.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new g,this.strm.avail_out=0;var f=s.inflateInit2(this.strm,_.windowBits);if(f!==c.Z_OK)throw new Error(l[f]);this.header=new u,s.inflateGetHeader(this.strm,this.header)}function m(p,_){var f=new d(_);if(f.push(p,!0),f.err)throw f.msg||l[f.err];return f.result}d.prototype.push=function(p,_){var f,I,C,y,x,E,S=this.strm,b=this.options.chunkSize,v=this.options.dictionary,M=!1;if(this.ended)return!1;I=_===~~_?_:_===!0?c.Z_FINISH:c.Z_NO_FLUSH,typeof p=="string"?S.input=A.binstring2buf(p):h.call(p)==="[object ArrayBuffer]"?S.input=new Uint8Array(p):S.input=p,S.next_in=0,S.avail_in=S.input.length;do{if(S.avail_out===0&&(S.output=new a.Buf8(b),S.next_out=0,S.avail_out=b),(f=s.inflate(S,c.Z_NO_FLUSH))===c.Z_NEED_DICT&&v&&(E=typeof v=="string"?A.string2buf(v):h.call(v)==="[object ArrayBuffer]"?new Uint8Array(v):v,f=s.inflateSetDictionary(this.strm,E)),f===c.Z_BUF_ERROR&&M===!0&&(f=c.Z_OK,M=!1),f!==c.Z_STREAM_END&&f!==c.Z_OK)return this.onEnd(f),!(this.ended=!0);S.next_out&&(S.avail_out!==0&&f!==c.Z_STREAM_END&&(S.avail_in!==0||I!==c.Z_FINISH&&I!==c.Z_SYNC_FLUSH)||(this.options.to==="string"?(C=A.utf8border(S.output,S.next_out),y=S.next_out-C,x=A.buf2string(S.output,C),S.next_out=y,S.avail_out=b-y,y&&a.arraySet(S.output,S.output,C,y,0),this.onData(x)):this.onData(a.shrinkBuf(S.output,S.next_out)))),S.avail_in===0&&S.avail_out===0&&(M=!0)}while((0<S.avail_in||S.avail_out===0)&&f!==c.Z_STREAM_END);return f===c.Z_STREAM_END&&(I=c.Z_FINISH),I===c.Z_FINISH?(f=s.inflateEnd(this.strm),this.onEnd(f),this.ended=!0,f===c.Z_OK):I!==c.Z_SYNC_FLUSH||(this.onEnd(c.Z_OK),!(S.avail_out=0))},d.prototype.onData=function(p){this.chunks.push(p)},d.prototype.onEnd=function(p){p===c.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,_){return(_=_||{}).raw=!0,m(p,_)},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(c){for(var l=Array.prototype.slice.call(arguments,1);l.length;){var g=l.shift();if(g){if(typeof g!="object")throw new TypeError(g+"must be non-object");for(var u in g)g.hasOwnProperty(u)&&(c[u]=g[u])}}return c},r.shrinkBuf=function(c,l){return c.length===l?c:c.subarray?c.subarray(0,l):(c.length=l,c)};var a={arraySet:function(c,l,g,u,h){if(l.subarray&&c.subarray)c.set(l.subarray(g,g+u),h);else for(var d=0;d<u;d++)c[h+d]=l[g+d]},flattenChunks:function(c){var l,g,u,h,d,m;for(l=u=0,g=c.length;l<g;l++)u+=c[l].length;for(m=new Uint8Array(u),l=h=0,g=c.length;l<g;l++)d=c[l],m.set(d,h),h+=d.length;return m}},A={arraySet:function(c,l,g,u,h){for(var d=0;d<u;d++)c[h+d]=l[g+d]},flattenChunks:function(c){return[].concat.apply([],c)}};r.setTyped=function(c){c?(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,A))},r.setTyped(s)},{}],42:[function(o,i,r){var s=o("./common"),a=!0,A=!0;try{String.fromCharCode.apply(null,[0])}catch{a=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{A=!1}for(var c=new s.Buf8(256),l=0;l<256;l++)c[l]=252<=l?6:248<=l?5:240<=l?4:224<=l?3:192<=l?2:1;function g(u,h){if(h<65537&&(u.subarray&&A||!u.subarray&&a))return String.fromCharCode.apply(null,s.shrinkBuf(u,h));for(var d="",m=0;m<h;m++)d+=String.fromCharCode(u[m]);return d}c[254]=c[254]=1,r.string2buf=function(u){var h,d,m,p,_,f=u.length,I=0;for(p=0;p<f;p++)(64512&(d=u.charCodeAt(p)))==55296&&p+1<f&&(64512&(m=u.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=_=0;_<I;p++)(64512&(d=u.charCodeAt(p)))==55296&&p+1<f&&(64512&(m=u.charCodeAt(p+1)))==56320&&(d=65536+(d-55296<<10)+(m-56320),p++),d<128?h[_++]=d:(d<2048?h[_++]=192|d>>>6:(d<65536?h[_++]=224|d>>>12:(h[_++]=240|d>>>18,h[_++]=128|d>>>12&63),h[_++]=128|d>>>6&63),h[_++]=128|63&d);return h},r.buf2binstring=function(u){return g(u,u.length)},r.binstring2buf=function(u){for(var h=new s.Buf8(u.length),d=0,m=h.length;d<m;d++)h[d]=u.charCodeAt(d);return h},r.buf2string=function(u,h){var d,m,p,_,f=h||u.length,I=new Array(2*f);for(d=m=0;d<f;)if((p=u[d++])<128)I[m++]=p;else if(4<(_=c[p]))I[m++]=65533,d+=_-1;else{for(p&=_===2?31:_===3?15:7;1<_&&d<f;)p=p<<6|63&u[d++],_--;1<_?I[m++]=65533:p<65536?I[m++]=p:(p-=65536,I[m++]=55296|p>>10&1023,I[m++]=56320|1023&p)}return g(I,m)},r.utf8border=function(u,h){var d;for((h=h||u.length)>u.length&&(h=u.length),d=h-1;0<=d&&(192&u[d])==128;)d--;return d<0||d===0?h:d+c[u[d]]>h?d:h}},{"./common":41}],43:[function(o,i,r){i.exports=function(s,a,A,c){for(var l=65535&s|0,g=s>>>16&65535|0,u=0;A!==0;){for(A-=u=2e3<A?2e3:A;g=g+(l=l+a[c++]|0)|0,--u;);l%=65521,g%=65521}return l|g<<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,A=[],c=0;c<256;c++){a=c;for(var l=0;l<8;l++)a=1&a?3988292384^a>>>1:a>>>1;A[c]=a}return A})();i.exports=function(a,A,c,l){var g=s,u=l+c;a^=-1;for(var h=l;h<u;h++)a=a>>>8^g[255&(a^A[h])];return-1^a}},{}],46:[function(o,i,r){var s,a=o("../utils/common"),A=o("./trees"),c=o("./adler32"),l=o("./crc32"),g=o("./messages"),u=0,h=4,d=0,m=-2,p=-1,_=4,f=2,I=8,C=9,y=286,x=30,E=19,S=2*y+1,b=15,v=3,M=258,N=M+v+1,k=42,L=113,O=1,G=2,V=3,K=4;function Z(he,Le){return he.msg=g[Le],Le}function te(he){return(he<<1)-(4<he?9:0)}function ee(he){for(var Le=he.length;0<=--Le;)he[Le]=0}function X(he){var Le=he.state,Me=Le.pending;Me>he.avail_out&&(Me=he.avail_out),Me!==0&&(a.arraySet(he.output,Le.pending_buf,Le.pending_out,Me,he.next_out),he.next_out+=Me,Le.pending_out+=Me,he.total_out+=Me,he.avail_out-=Me,Le.pending-=Me,Le.pending===0&&(Le.pending_out=0))}function ie(he,Le){A._tr_flush_block(he,0<=he.block_start?he.block_start:-1,he.strstart-he.block_start,Le),he.block_start=he.strstart,X(he.strm)}function se(he,Le){he.pending_buf[he.pending++]=Le}function Ae(he,Le){he.pending_buf[he.pending++]=Le>>>8&255,he.pending_buf[he.pending++]=255&Le}function de(he,Le){var Me,Ne,Oe=he.max_chain_length,De=he.strstart,Be=he.prev_length,ke=he.nice_match,be=he.strstart>he.w_size-N?he.strstart-(he.w_size-N):0,Ye=he.window,We=he.w_mask,tt=he.prev,ct=he.strstart+M,at=Ye[De+Be-1],Fe=Ye[De+Be];he.prev_length>=he.good_match&&(Oe>>=2),ke>he.lookahead&&(ke=he.lookahead);do if(Ye[(Me=Le)+Be]===Fe&&Ye[Me+Be-1]===at&&Ye[Me]===Ye[De]&&Ye[++Me]===Ye[De+1]){De+=2,Me++;do;while(Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&Ye[++De]===Ye[++Me]&&De<ct);if(Ne=M-(ct-De),De=ct-M,Be<Ne){if(he.match_start=Le,ke<=(Be=Ne))break;at=Ye[De+Be-1],Fe=Ye[De+Be]}}while((Le=tt[Le&We])>be&&--Oe!=0);return Be<=he.lookahead?Be:he.lookahead}function me(he){var Le,Me,Ne,Oe,De,Be,ke,be,Ye,We,tt=he.w_size;do{if(Oe=he.window_size-he.lookahead-he.strstart,he.strstart>=tt+(tt-N)){for(a.arraySet(he.window,he.window,tt,tt,0),he.match_start-=tt,he.strstart-=tt,he.block_start-=tt,Le=Me=he.hash_size;Ne=he.head[--Le],he.head[Le]=tt<=Ne?Ne-tt:0,--Me;);for(Le=Me=tt;Ne=he.prev[--Le],he.prev[Le]=tt<=Ne?Ne-tt:0,--Me;);Oe+=tt}if(he.strm.avail_in===0)break;if(Be=he.strm,ke=he.window,be=he.strstart+he.lookahead,Ye=Oe,We=void 0,We=Be.avail_in,Ye<We&&(We=Ye),Me=We===0?0:(Be.avail_in-=We,a.arraySet(ke,Be.input,Be.next_in,We,be),Be.state.wrap===1?Be.adler=c(Be.adler,ke,We,be):Be.state.wrap===2&&(Be.adler=l(Be.adler,ke,We,be)),Be.next_in+=We,Be.total_in+=We,We),he.lookahead+=Me,he.lookahead+he.insert>=v)for(De=he.strstart-he.insert,he.ins_h=he.window[De],he.ins_h=(he.ins_h<<he.hash_shift^he.window[De+1])&he.hash_mask;he.insert&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[De+v-1])&he.hash_mask,he.prev[De&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=De,De++,he.insert--,!(he.lookahead+he.insert<v)););}while(he.lookahead<N&&he.strm.avail_in!==0)}function ye(he,Le){for(var Me,Ne;;){if(he.lookahead<N){if(me(he),he.lookahead<N&&Le===u)return O;if(he.lookahead===0)break}if(Me=0,he.lookahead>=v&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+v-1])&he.hash_mask,Me=he.prev[he.strstart&he.w_mask]=he.head[he.ins_h],he.head[he.ins_h]=he.strstart),Me!==0&&he.strstart-Me<=he.w_size-N&&(he.match_length=de(he,Me)),he.match_length>=v)if(Ne=A._tr_tally(he,he.strstart-he.match_start,he.match_length-v),he.lookahead-=he.match_length,he.match_length<=he.max_lazy_match&&he.lookahead>=v){for(he.match_length--;he.strstart++,he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+v-1])&he.hash_mask,Me=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 Ne=A._tr_tally(he,0,he.window[he.strstart]),he.lookahead--,he.strstart++;if(Ne&&(ie(he,!1),he.strm.avail_out===0))return O}return he.insert=he.strstart<v-1?he.strstart:v-1,Le===h?(ie(he,!0),he.strm.avail_out===0?V:K):he.last_lit&&(ie(he,!1),he.strm.avail_out===0)?O:G}function le(he,Le){for(var Me,Ne,Oe;;){if(he.lookahead<N){if(me(he),he.lookahead<N&&Le===u)return O;if(he.lookahead===0)break}if(Me=0,he.lookahead>=v&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+v-1])&he.hash_mask,Me=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=v-1,Me!==0&&he.prev_length<he.max_lazy_match&&he.strstart-Me<=he.w_size-N&&(he.match_length=de(he,Me),he.match_length<=5&&(he.strategy===1||he.match_length===v&&4096<he.strstart-he.match_start)&&(he.match_length=v-1)),he.prev_length>=v&&he.match_length<=he.prev_length){for(Oe=he.strstart+he.lookahead-v,Ne=A._tr_tally(he,he.strstart-1-he.prev_match,he.prev_length-v),he.lookahead-=he.prev_length-1,he.prev_length-=2;++he.strstart<=Oe&&(he.ins_h=(he.ins_h<<he.hash_shift^he.window[he.strstart+v-1])&he.hash_mask,Me=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=v-1,he.strstart++,Ne&&(ie(he,!1),he.strm.avail_out===0))return O}else if(he.match_available){if((Ne=A._tr_tally(he,0,he.window[he.strstart-1]))&&ie(he,!1),he.strstart++,he.lookahead--,he.strm.avail_out===0)return O}else he.match_available=1,he.strstart++,he.lookahead--}return he.match_available&&(Ne=A._tr_tally(he,0,he.window[he.strstart-1]),he.match_available=0),he.insert=he.strstart<v-1?he.strstart:v-1,Le===h?(ie(he,!0),he.strm.avail_out===0?V:K):he.last_lit&&(ie(he,!1),he.strm.avail_out===0)?O:G}function Ce(he,Le,Me,Ne,Oe){this.good_length=he,this.max_lazy=Le,this.nice_length=Me,this.max_chain=Ne,this.func=Oe}function _e(){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*S),this.dyn_dtree=new a.Buf16(2*(2*x+1)),this.bl_tree=new a.Buf16(2*(2*E+1)),ee(this.dyn_ltree),ee(this.dyn_dtree),ee(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),ee(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*y+1),ee(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 Qe(he){var Le;return he&&he.state?(he.total_in=he.total_out=0,he.data_type=f,(Le=he.state).pending=0,Le.pending_out=0,Le.wrap<0&&(Le.wrap=-Le.wrap),Le.status=Le.wrap?k:L,he.adler=Le.wrap===2?0:1,Le.last_flush=u,A._tr_init(Le),d):Z(he,m)}function Te(he){var Le=Qe(he);return Le===d&&(function(Me){Me.window_size=2*Me.w_size,ee(Me.head),Me.max_lazy_match=s[Me.level].max_lazy,Me.good_match=s[Me.level].good_length,Me.nice_match=s[Me.level].nice_length,Me.max_chain_length=s[Me.level].max_chain,Me.strstart=0,Me.block_start=0,Me.lookahead=0,Me.insert=0,Me.match_length=Me.prev_length=v-1,Me.match_available=0,Me.ins_h=0})(he.state),Le}function Se(he,Le,Me,Ne,Oe,De){if(!he)return m;var Be=1;if(Le===p&&(Le=6),Ne<0?(Be=0,Ne=-Ne):15<Ne&&(Be=2,Ne-=16),Oe<1||C<Oe||Me!==I||Ne<8||15<Ne||Le<0||9<Le||De<0||_<De)return Z(he,m);Ne===8&&(Ne=9);var ke=new _e;return(he.state=ke).strm=he,ke.wrap=Be,ke.gzhead=null,ke.w_bits=Ne,ke.w_size=1<<ke.w_bits,ke.w_mask=ke.w_size-1,ke.hash_bits=Oe+7,ke.hash_size=1<<ke.hash_bits,ke.hash_mask=ke.hash_size-1,ke.hash_shift=~~((ke.hash_bits+v-1)/v),ke.window=new a.Buf8(2*ke.w_size),ke.head=new a.Buf16(ke.hash_size),ke.prev=new a.Buf16(ke.w_size),ke.lit_bufsize=1<<Oe+6,ke.pending_buf_size=4*ke.lit_bufsize,ke.pending_buf=new a.Buf8(ke.pending_buf_size),ke.d_buf=1*ke.lit_bufsize,ke.l_buf=3*ke.lit_bufsize,ke.level=Le,ke.strategy=De,ke.method=Me,Te(he)}s=[new Ce(0,0,0,0,function(he,Le){var Me=65535;for(Me>he.pending_buf_size-5&&(Me=he.pending_buf_size-5);;){if(he.lookahead<=1){if(me(he),he.lookahead===0&&Le===u)return O;if(he.lookahead===0)break}he.strstart+=he.lookahead,he.lookahead=0;var Ne=he.block_start+Me;if((he.strstart===0||he.strstart>=Ne)&&(he.lookahead=he.strstart-Ne,he.strstart=Ne,ie(he,!1),he.strm.avail_out===0)||he.strstart-he.block_start>=he.w_size-N&&(ie(he,!1),he.strm.avail_out===0))return O}return he.insert=0,Le===h?(ie(he,!0),he.strm.avail_out===0?V:K):(he.strstart>he.block_start&&(ie(he,!1),he.strm.avail_out),O)}),new Ce(4,4,8,4,ye),new Ce(4,5,16,8,ye),new Ce(4,6,32,32,ye),new Ce(4,4,16,16,le),new Ce(8,16,32,32,le),new Ce(8,16,128,128,le),new Ce(8,32,128,256,le),new Ce(32,128,258,1024,le),new Ce(32,258,258,4096,le)],r.deflateInit=function(he,Le){return Se(he,Le,I,15,8,0)},r.deflateInit2=Se,r.deflateReset=Te,r.deflateResetKeep=Qe,r.deflateSetHeader=function(he,Le){return he&&he.state?he.state.wrap!==2?m:(he.state.gzhead=Le,d):m},r.deflate=function(he,Le){var Me,Ne,Oe,De;if(!he||!he.state||5<Le||Le<0)return he?Z(he,m):m;if(Ne=he.state,!he.output||!he.input&&he.avail_in!==0||Ne.status===666&&Le!==h)return Z(he,he.avail_out===0?-5:m);if(Ne.strm=he,Me=Ne.last_flush,Ne.last_flush=Le,Ne.status===k)if(Ne.wrap===2)he.adler=0,se(Ne,31),se(Ne,139),se(Ne,8),Ne.gzhead?(se(Ne,(Ne.gzhead.text?1:0)+(Ne.gzhead.hcrc?2:0)+(Ne.gzhead.extra?4:0)+(Ne.gzhead.name?8:0)+(Ne.gzhead.comment?16:0)),se(Ne,255&Ne.gzhead.time),se(Ne,Ne.gzhead.time>>8&255),se(Ne,Ne.gzhead.time>>16&255),se(Ne,Ne.gzhead.time>>24&255),se(Ne,Ne.level===9?2:2<=Ne.strategy||Ne.level<2?4:0),se(Ne,255&Ne.gzhead.os),Ne.gzhead.extra&&Ne.gzhead.extra.length&&(se(Ne,255&Ne.gzhead.extra.length),se(Ne,Ne.gzhead.extra.length>>8&255)),Ne.gzhead.hcrc&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending,0)),Ne.gzindex=0,Ne.status=69):(se(Ne,0),se(Ne,0),se(Ne,0),se(Ne,0),se(Ne,0),se(Ne,Ne.level===9?2:2<=Ne.strategy||Ne.level<2?4:0),se(Ne,3),Ne.status=L);else{var Be=I+(Ne.w_bits-8<<4)<<8;Be|=(2<=Ne.strategy||Ne.level<2?0:Ne.level<6?1:Ne.level===6?2:3)<<6,Ne.strstart!==0&&(Be|=32),Be+=31-Be%31,Ne.status=L,Ae(Ne,Be),Ne.strstart!==0&&(Ae(Ne,he.adler>>>16),Ae(Ne,65535&he.adler)),he.adler=1}if(Ne.status===69)if(Ne.gzhead.extra){for(Oe=Ne.pending;Ne.gzindex<(65535&Ne.gzhead.extra.length)&&(Ne.pending!==Ne.pending_buf_size||(Ne.gzhead.hcrc&&Ne.pending>Oe&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending-Oe,Oe)),X(he),Oe=Ne.pending,Ne.pending!==Ne.pending_buf_size));)se(Ne,255&Ne.gzhead.extra[Ne.gzindex]),Ne.gzindex++;Ne.gzhead.hcrc&&Ne.pending>Oe&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending-Oe,Oe)),Ne.gzindex===Ne.gzhead.extra.length&&(Ne.gzindex=0,Ne.status=73)}else Ne.status=73;if(Ne.status===73)if(Ne.gzhead.name){Oe=Ne.pending;do{if(Ne.pending===Ne.pending_buf_size&&(Ne.gzhead.hcrc&&Ne.pending>Oe&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending-Oe,Oe)),X(he),Oe=Ne.pending,Ne.pending===Ne.pending_buf_size)){De=1;break}De=Ne.gzindex<Ne.gzhead.name.length?255&Ne.gzhead.name.charCodeAt(Ne.gzindex++):0,se(Ne,De)}while(De!==0);Ne.gzhead.hcrc&&Ne.pending>Oe&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending-Oe,Oe)),De===0&&(Ne.gzindex=0,Ne.status=91)}else Ne.status=91;if(Ne.status===91)if(Ne.gzhead.comment){Oe=Ne.pending;do{if(Ne.pending===Ne.pending_buf_size&&(Ne.gzhead.hcrc&&Ne.pending>Oe&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending-Oe,Oe)),X(he),Oe=Ne.pending,Ne.pending===Ne.pending_buf_size)){De=1;break}De=Ne.gzindex<Ne.gzhead.comment.length?255&Ne.gzhead.comment.charCodeAt(Ne.gzindex++):0,se(Ne,De)}while(De!==0);Ne.gzhead.hcrc&&Ne.pending>Oe&&(he.adler=l(he.adler,Ne.pending_buf,Ne.pending-Oe,Oe)),De===0&&(Ne.status=103)}else Ne.status=103;if(Ne.status===103&&(Ne.gzhead.hcrc?(Ne.pending+2>Ne.pending_buf_size&&X(he),Ne.pending+2<=Ne.pending_buf_size&&(se(Ne,255&he.adler),se(Ne,he.adler>>8&255),he.adler=0,Ne.status=L)):Ne.status=L),Ne.pending!==0){if(X(he),he.avail_out===0)return Ne.last_flush=-1,d}else if(he.avail_in===0&&te(Le)<=te(Me)&&Le!==h)return Z(he,-5);if(Ne.status===666&&he.avail_in!==0)return Z(he,-5);if(he.avail_in!==0||Ne.lookahead!==0||Le!==u&&Ne.status!==666){var ke=Ne.strategy===2?(function(be,Ye){for(var We;;){if(be.lookahead===0&&(me(be),be.lookahead===0)){if(Ye===u)return O;break}if(be.match_length=0,We=A._tr_tally(be,0,be.window[be.strstart]),be.lookahead--,be.strstart++,We&&(ie(be,!1),be.strm.avail_out===0))return O}return be.insert=0,Ye===h?(ie(be,!0),be.strm.avail_out===0?V:K):be.last_lit&&(ie(be,!1),be.strm.avail_out===0)?O:G})(Ne,Le):Ne.strategy===3?(function(be,Ye){for(var We,tt,ct,at,Fe=be.window;;){if(be.lookahead<=M){if(me(be),be.lookahead<=M&&Ye===u)return O;if(be.lookahead===0)break}if(be.match_length=0,be.lookahead>=v&&0<be.strstart&&(tt=Fe[ct=be.strstart-1])===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]){at=be.strstart+M;do;while(tt===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]&&tt===Fe[++ct]&&ct<at);be.match_length=M-(at-ct),be.match_length>be.lookahead&&(be.match_length=be.lookahead)}if(be.match_length>=v?(We=A._tr_tally(be,1,be.match_length-v),be.lookahead-=be.match_length,be.strstart+=be.match_length,be.match_length=0):(We=A._tr_tally(be,0,be.window[be.strstart]),be.lookahead--,be.strstart++),We&&(ie(be,!1),be.strm.avail_out===0))return O}return be.insert=0,Ye===h?(ie(be,!0),be.strm.avail_out===0?V:K):be.last_lit&&(ie(be,!1),be.strm.avail_out===0)?O:G})(Ne,Le):s[Ne.level].func(Ne,Le);if(ke!==V&&ke!==K||(Ne.status=666),ke===O||ke===V)return he.avail_out===0&&(Ne.last_flush=-1),d;if(ke===G&&(Le===1?A._tr_align(Ne):Le!==5&&(A._tr_stored_block(Ne,0,0,!1),Le===3&&(ee(Ne.head),Ne.lookahead===0&&(Ne.strstart=0,Ne.block_start=0,Ne.insert=0))),X(he),he.avail_out===0))return Ne.last_flush=-1,d}return Le!==h?d:Ne.wrap<=0?1:(Ne.wrap===2?(se(Ne,255&he.adler),se(Ne,he.adler>>8&255),se(Ne,he.adler>>16&255),se(Ne,he.adler>>24&255),se(Ne,255&he.total_in),se(Ne,he.total_in>>8&255),se(Ne,he.total_in>>16&255),se(Ne,he.total_in>>24&255)):(Ae(Ne,he.adler>>>16),Ae(Ne,65535&he.adler)),X(he),0<Ne.wrap&&(Ne.wrap=-Ne.wrap),Ne.pending!==0?d:1)},r.deflateEnd=function(he){var Le;return he&&he.state?(Le=he.state.status)!==k&&Le!==69&&Le!==73&&Le!==91&&Le!==103&&Le!==L&&Le!==666?Z(he,m):(he.state=null,Le===L?Z(he,-3):d):m},r.deflateSetDictionary=function(he,Le){var Me,Ne,Oe,De,Be,ke,be,Ye,We=Le.length;if(!he||!he.state||(De=(Me=he.state).wrap)===2||De===1&&Me.status!==k||Me.lookahead)return m;for(De===1&&(he.adler=c(he.adler,Le,We,0)),Me.wrap=0,We>=Me.w_size&&(De===0&&(ee(Me.head),Me.strstart=0,Me.block_start=0,Me.insert=0),Ye=new a.Buf8(Me.w_size),a.arraySet(Ye,Le,We-Me.w_size,Me.w_size,0),Le=Ye,We=Me.w_size),Be=he.avail_in,ke=he.next_in,be=he.input,he.avail_in=We,he.next_in=0,he.input=Le,me(Me);Me.lookahead>=v;){for(Ne=Me.strstart,Oe=Me.lookahead-(v-1);Me.ins_h=(Me.ins_h<<Me.hash_shift^Me.window[Ne+v-1])&Me.hash_mask,Me.prev[Ne&Me.w_mask]=Me.head[Me.ins_h],Me.head[Me.ins_h]=Ne,Ne++,--Oe;);Me.strstart=Ne,Me.lookahead=v-1,me(Me)}return Me.strstart+=Me.lookahead,Me.block_start=Me.strstart,Me.insert=Me.lookahead,Me.lookahead=0,Me.match_length=Me.prev_length=v-1,Me.match_available=0,he.next_in=ke,he.input=be,he.avail_in=Be,Me.wrap=De,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 A,c,l,g,u,h,d,m,p,_,f,I,C,y,x,E,S,b,v,M,N,k,L,O,G;A=s.state,c=s.next_in,O=s.input,l=c+(s.avail_in-5),g=s.next_out,G=s.output,u=g-(a-s.avail_out),h=g+(s.avail_out-257),d=A.dmax,m=A.wsize,p=A.whave,_=A.wnext,f=A.window,I=A.hold,C=A.bits,y=A.lencode,x=A.distcode,E=(1<<A.lenbits)-1,S=(1<<A.distbits)-1;e:do{C<15&&(I+=O[c++]<<C,C+=8,I+=O[c++]<<C,C+=8),b=y[I&E];t:for(;;){if(I>>>=v=b>>>24,C-=v,(v=b>>>16&255)===0)G[g++]=65535&b;else{if(!(16&v)){if((64&v)==0){b=y[(65535&b)+(I&(1<<v)-1)];continue t}if(32&v){A.mode=12;break e}s.msg="invalid literal/length code",A.mode=30;break e}M=65535&b,(v&=15)&&(C<v&&(I+=O[c++]<<C,C+=8),M+=I&(1<<v)-1,I>>>=v,C-=v),C<15&&(I+=O[c++]<<C,C+=8,I+=O[c++]<<C,C+=8),b=x[I&S];n:for(;;){if(I>>>=v=b>>>24,C-=v,!(16&(v=b>>>16&255))){if((64&v)==0){b=x[(65535&b)+(I&(1<<v)-1)];continue n}s.msg="invalid distance code",A.mode=30;break e}if(N=65535&b,C<(v&=15)&&(I+=O[c++]<<C,(C+=8)<v&&(I+=O[c++]<<C,C+=8)),d<(N+=I&(1<<v)-1)){s.msg="invalid distance too far back",A.mode=30;break e}if(I>>>=v,C-=v,(v=g-u)<N){if(p<(v=N-v)&&A.sane){s.msg="invalid distance too far back",A.mode=30;break e}if(L=f,(k=0)===_){if(k+=m-v,v<M){for(M-=v;G[g++]=f[k++],--v;);k=g-N,L=G}}else if(_<v){if(k+=m+_-v,(v-=_)<M){for(M-=v;G[g++]=f[k++],--v;);if(k=0,_<M){for(M-=v=_;G[g++]=f[k++],--v;);k=g-N,L=G}}}else if(k+=_-v,v<M){for(M-=v;G[g++]=f[k++],--v;);k=g-N,L=G}for(;2<M;)G[g++]=L[k++],G[g++]=L[k++],G[g++]=L[k++],M-=3;M&&(G[g++]=L[k++],1<M&&(G[g++]=L[k++]))}else{for(k=g-N;G[g++]=G[k++],G[g++]=G[k++],G[g++]=G[k++],2<(M-=3););M&&(G[g++]=G[k++],1<M&&(G[g++]=G[k++]))}break}}break}}while(c<l&&g<h);c-=M=C>>3,I&=(1<<(C-=M<<3))-1,s.next_in=c,s.next_out=g,s.avail_in=c<l?l-c+5:5-(c-l),s.avail_out=g<h?h-g+257:257-(g-h),A.hold=I,A.bits=C}},{}],49:[function(o,i,r){var s=o("../utils/common"),a=o("./adler32"),A=o("./crc32"),c=o("./inffast"),l=o("./inftrees"),g=1,u=2,h=0,d=-2,m=1,p=852,_=592;function f(k){return(k>>>24&255)+(k>>>8&65280)+((65280&k)<<8)+((255&k)<<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(k){var L;return k&&k.state?(L=k.state,k.total_in=k.total_out=L.total=0,k.msg="",L.wrap&&(k.adler=1&L.wrap),L.mode=m,L.last=0,L.havedict=0,L.dmax=32768,L.head=null,L.hold=0,L.bits=0,L.lencode=L.lendyn=new s.Buf32(p),L.distcode=L.distdyn=new s.Buf32(_),L.sane=1,L.back=-1,h):d}function y(k){var L;return k&&k.state?((L=k.state).wsize=0,L.whave=0,L.wnext=0,C(k)):d}function x(k,L){var O,G;return k&&k.state?(G=k.state,L<0?(O=0,L=-L):(O=1+(L>>4),L<48&&(L&=15)),L&&(L<8||15<L)?d:(G.window!==null&&G.wbits!==L&&(G.window=null),G.wrap=O,G.wbits=L,y(k))):d}function E(k,L){var O,G;return k?(G=new I,(k.state=G).window=null,(O=x(k,L))!==h&&(k.state=null),O):d}var S,b,v=!0;function M(k){if(v){var L;for(S=new s.Buf32(512),b=new s.Buf32(32),L=0;L<144;)k.lens[L++]=8;for(;L<256;)k.lens[L++]=9;for(;L<280;)k.lens[L++]=7;for(;L<288;)k.lens[L++]=8;for(l(g,k.lens,0,288,S,0,k.work,{bits:9}),L=0;L<32;)k.lens[L++]=5;l(u,k.lens,0,32,b,0,k.work,{bits:5}),v=!1}k.lencode=S,k.lenbits=9,k.distcode=b,k.distbits=5}function N(k,L,O,G){var V,K=k.state;return K.window===null&&(K.wsize=1<<K.wbits,K.wnext=0,K.whave=0,K.window=new s.Buf8(K.wsize)),G>=K.wsize?(s.arraySet(K.window,L,O-K.wsize,K.wsize,0),K.wnext=0,K.whave=K.wsize):(G<(V=K.wsize-K.wnext)&&(V=G),s.arraySet(K.window,L,O-G,V,K.wnext),(G-=V)?(s.arraySet(K.window,L,O-G,G,0),K.wnext=G,K.whave=K.wsize):(K.wnext+=V,K.wnext===K.wsize&&(K.wnext=0),K.whave<K.wsize&&(K.whave+=V))),0}r.inflateReset=y,r.inflateReset2=x,r.inflateResetKeep=C,r.inflateInit=function(k){return E(k,15)},r.inflateInit2=E,r.inflate=function(k,L){var O,G,V,K,Z,te,ee,X,ie,se,Ae,de,me,ye,le,Ce,_e,Qe,Te,Se,he,Le,Me,Ne,Oe=0,De=new s.Buf8(4),Be=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!k||!k.state||!k.output||!k.input&&k.avail_in!==0)return d;(O=k.state).mode===12&&(O.mode=13),Z=k.next_out,V=k.output,ee=k.avail_out,K=k.next_in,G=k.input,te=k.avail_in,X=O.hold,ie=O.bits,se=te,Ae=ee,Le=h;e:for(;;)switch(O.mode){case m:if(O.wrap===0){O.mode=13;break}for(;ie<16;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(2&O.wrap&&X===35615){De[O.check=0]=255&X,De[1]=X>>>8&255,O.check=A(O.check,De,2,0),ie=X=0,O.mode=2;break}if(O.flags=0,O.head&&(O.head.done=!1),!(1&O.wrap)||(((255&X)<<8)+(X>>8))%31){k.msg="incorrect header check",O.mode=30;break}if((15&X)!=8){k.msg="unknown compression method",O.mode=30;break}if(ie-=4,he=8+(15&(X>>>=4)),O.wbits===0)O.wbits=he;else if(he>O.wbits){k.msg="invalid window size",O.mode=30;break}O.dmax=1<<he,k.adler=O.check=1,O.mode=512&X?10:12,ie=X=0;break;case 2:for(;ie<16;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(O.flags=X,(255&O.flags)!=8){k.msg="unknown compression method",O.mode=30;break}if(57344&O.flags){k.msg="unknown header flags set",O.mode=30;break}O.head&&(O.head.text=X>>8&1),512&O.flags&&(De[0]=255&X,De[1]=X>>>8&255,O.check=A(O.check,De,2,0)),ie=X=0,O.mode=3;case 3:for(;ie<32;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}O.head&&(O.head.time=X),512&O.flags&&(De[0]=255&X,De[1]=X>>>8&255,De[2]=X>>>16&255,De[3]=X>>>24&255,O.check=A(O.check,De,4,0)),ie=X=0,O.mode=4;case 4:for(;ie<16;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}O.head&&(O.head.xflags=255&X,O.head.os=X>>8),512&O.flags&&(De[0]=255&X,De[1]=X>>>8&255,O.check=A(O.check,De,2,0)),ie=X=0,O.mode=5;case 5:if(1024&O.flags){for(;ie<16;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}O.length=X,O.head&&(O.head.extra_len=X),512&O.flags&&(De[0]=255&X,De[1]=X>>>8&255,O.check=A(O.check,De,2,0)),ie=X=0}else O.head&&(O.head.extra=null);O.mode=6;case 6:if(1024&O.flags&&(te<(de=O.length)&&(de=te),de&&(O.head&&(he=O.head.extra_len-O.length,O.head.extra||(O.head.extra=new Array(O.head.extra_len)),s.arraySet(O.head.extra,G,K,de,he)),512&O.flags&&(O.check=A(O.check,G,de,K)),te-=de,K+=de,O.length-=de),O.length))break e;O.length=0,O.mode=7;case 7:if(2048&O.flags){if(te===0)break e;for(de=0;he=G[K+de++],O.head&&he&&O.length<65536&&(O.head.name+=String.fromCharCode(he)),he&&de<te;);if(512&O.flags&&(O.check=A(O.check,G,de,K)),te-=de,K+=de,he)break e}else O.head&&(O.head.name=null);O.length=0,O.mode=8;case 8:if(4096&O.flags){if(te===0)break e;for(de=0;he=G[K+de++],O.head&&he&&O.length<65536&&(O.head.comment+=String.fromCharCode(he)),he&&de<te;);if(512&O.flags&&(O.check=A(O.check,G,de,K)),te-=de,K+=de,he)break e}else O.head&&(O.head.comment=null);O.mode=9;case 9:if(512&O.flags){for(;ie<16;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(X!==(65535&O.check)){k.msg="header crc mismatch",O.mode=30;break}ie=X=0}O.head&&(O.head.hcrc=O.flags>>9&1,O.head.done=!0),k.adler=O.check=0,O.mode=12;break;case 10:for(;ie<32;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}k.adler=O.check=f(X),ie=X=0,O.mode=11;case 11:if(O.havedict===0)return k.next_out=Z,k.avail_out=ee,k.next_in=K,k.avail_in=te,O.hold=X,O.bits=ie,2;k.adler=O.check=1,O.mode=12;case 12:if(L===5||L===6)break e;case 13:if(O.last){X>>>=7&ie,ie-=7&ie,O.mode=27;break}for(;ie<3;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}switch(O.last=1&X,ie-=1,3&(X>>>=1)){case 0:O.mode=14;break;case 1:if(M(O),O.mode=20,L!==6)break;X>>>=2,ie-=2;break e;case 2:O.mode=17;break;case 3:k.msg="invalid block type",O.mode=30}X>>>=2,ie-=2;break;case 14:for(X>>>=7&ie,ie-=7&ie;ie<32;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if((65535&X)!=(X>>>16^65535)){k.msg="invalid stored block lengths",O.mode=30;break}if(O.length=65535&X,ie=X=0,O.mode=15,L===6)break e;case 15:O.mode=16;case 16:if(de=O.length){if(te<de&&(de=te),ee<de&&(de=ee),de===0)break e;s.arraySet(V,G,K,de,Z),te-=de,K+=de,ee-=de,Z+=de,O.length-=de;break}O.mode=12;break;case 17:for(;ie<14;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(O.nlen=257+(31&X),X>>>=5,ie-=5,O.ndist=1+(31&X),X>>>=5,ie-=5,O.ncode=4+(15&X),X>>>=4,ie-=4,286<O.nlen||30<O.ndist){k.msg="too many length or distance symbols",O.mode=30;break}O.have=0,O.mode=18;case 18:for(;O.have<O.ncode;){for(;ie<3;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}O.lens[Be[O.have++]]=7&X,X>>>=3,ie-=3}for(;O.have<19;)O.lens[Be[O.have++]]=0;if(O.lencode=O.lendyn,O.lenbits=7,Me={bits:O.lenbits},Le=l(0,O.lens,0,19,O.lencode,0,O.work,Me),O.lenbits=Me.bits,Le){k.msg="invalid code lengths set",O.mode=30;break}O.have=0,O.mode=19;case 19:for(;O.have<O.nlen+O.ndist;){for(;Ce=(Oe=O.lencode[X&(1<<O.lenbits)-1])>>>16&255,_e=65535&Oe,!((le=Oe>>>24)<=ie);){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(_e<16)X>>>=le,ie-=le,O.lens[O.have++]=_e;else{if(_e===16){for(Ne=le+2;ie<Ne;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(X>>>=le,ie-=le,O.have===0){k.msg="invalid bit length repeat",O.mode=30;break}he=O.lens[O.have-1],de=3+(3&X),X>>>=2,ie-=2}else if(_e===17){for(Ne=le+3;ie<Ne;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}ie-=le,he=0,de=3+(7&(X>>>=le)),X>>>=3,ie-=3}else{for(Ne=le+7;ie<Ne;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}ie-=le,he=0,de=11+(127&(X>>>=le)),X>>>=7,ie-=7}if(O.have+de>O.nlen+O.ndist){k.msg="invalid bit length repeat",O.mode=30;break}for(;de--;)O.lens[O.have++]=he}}if(O.mode===30)break;if(O.lens[256]===0){k.msg="invalid code -- missing end-of-block",O.mode=30;break}if(O.lenbits=9,Me={bits:O.lenbits},Le=l(g,O.lens,0,O.nlen,O.lencode,0,O.work,Me),O.lenbits=Me.bits,Le){k.msg="invalid literal/lengths set",O.mode=30;break}if(O.distbits=6,O.distcode=O.distdyn,Me={bits:O.distbits},Le=l(u,O.lens,O.nlen,O.ndist,O.distcode,0,O.work,Me),O.distbits=Me.bits,Le){k.msg="invalid distances set",O.mode=30;break}if(O.mode=20,L===6)break e;case 20:O.mode=21;case 21:if(6<=te&&258<=ee){k.next_out=Z,k.avail_out=ee,k.next_in=K,k.avail_in=te,O.hold=X,O.bits=ie,c(k,Ae),Z=k.next_out,V=k.output,ee=k.avail_out,K=k.next_in,G=k.input,te=k.avail_in,X=O.hold,ie=O.bits,O.mode===12&&(O.back=-1);break}for(O.back=0;Ce=(Oe=O.lencode[X&(1<<O.lenbits)-1])>>>16&255,_e=65535&Oe,!((le=Oe>>>24)<=ie);){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(Ce&&(240&Ce)==0){for(Qe=le,Te=Ce,Se=_e;Ce=(Oe=O.lencode[Se+((X&(1<<Qe+Te)-1)>>Qe)])>>>16&255,_e=65535&Oe,!(Qe+(le=Oe>>>24)<=ie);){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}X>>>=Qe,ie-=Qe,O.back+=Qe}if(X>>>=le,ie-=le,O.back+=le,O.length=_e,Ce===0){O.mode=26;break}if(32&Ce){O.back=-1,O.mode=12;break}if(64&Ce){k.msg="invalid literal/length code",O.mode=30;break}O.extra=15&Ce,O.mode=22;case 22:if(O.extra){for(Ne=O.extra;ie<Ne;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}O.length+=X&(1<<O.extra)-1,X>>>=O.extra,ie-=O.extra,O.back+=O.extra}O.was=O.length,O.mode=23;case 23:for(;Ce=(Oe=O.distcode[X&(1<<O.distbits)-1])>>>16&255,_e=65535&Oe,!((le=Oe>>>24)<=ie);){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if((240&Ce)==0){for(Qe=le,Te=Ce,Se=_e;Ce=(Oe=O.distcode[Se+((X&(1<<Qe+Te)-1)>>Qe)])>>>16&255,_e=65535&Oe,!(Qe+(le=Oe>>>24)<=ie);){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}X>>>=Qe,ie-=Qe,O.back+=Qe}if(X>>>=le,ie-=le,O.back+=le,64&Ce){k.msg="invalid distance code",O.mode=30;break}O.offset=_e,O.extra=15&Ce,O.mode=24;case 24:if(O.extra){for(Ne=O.extra;ie<Ne;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}O.offset+=X&(1<<O.extra)-1,X>>>=O.extra,ie-=O.extra,O.back+=O.extra}if(O.offset>O.dmax){k.msg="invalid distance too far back",O.mode=30;break}O.mode=25;case 25:if(ee===0)break e;if(de=Ae-ee,O.offset>de){if((de=O.offset-de)>O.whave&&O.sane){k.msg="invalid distance too far back",O.mode=30;break}me=de>O.wnext?(de-=O.wnext,O.wsize-de):O.wnext-de,de>O.length&&(de=O.length),ye=O.window}else ye=V,me=Z-O.offset,de=O.length;for(ee<de&&(de=ee),ee-=de,O.length-=de;V[Z++]=ye[me++],--de;);O.length===0&&(O.mode=21);break;case 26:if(ee===0)break e;V[Z++]=O.length,ee--,O.mode=21;break;case 27:if(O.wrap){for(;ie<32;){if(te===0)break e;te--,X|=G[K++]<<ie,ie+=8}if(Ae-=ee,k.total_out+=Ae,O.total+=Ae,Ae&&(k.adler=O.check=O.flags?A(O.check,V,Ae,Z-Ae):a(O.check,V,Ae,Z-Ae)),Ae=ee,(O.flags?X:f(X))!==O.check){k.msg="incorrect data check",O.mode=30;break}ie=X=0}O.mode=28;case 28:if(O.wrap&&O.flags){for(;ie<32;){if(te===0)break e;te--,X+=G[K++]<<ie,ie+=8}if(X!==(4294967295&O.total)){k.msg="incorrect length check",O.mode=30;break}ie=X=0}O.mode=29;case 29:Le=1;break e;case 30:Le=-3;break e;case 31:return-4;default:return d}return k.next_out=Z,k.avail_out=ee,k.next_in=K,k.avail_in=te,O.hold=X,O.bits=ie,(O.wsize||Ae!==k.avail_out&&O.mode<30&&(O.mode<27||L!==4))&&N(k,k.output,k.next_out,Ae-k.avail_out)?(O.mode=31,-4):(se-=k.avail_in,Ae-=k.avail_out,k.total_in+=se,k.total_out+=Ae,O.total+=Ae,O.wrap&&Ae&&(k.adler=O.check=O.flags?A(O.check,V,Ae,k.next_out-Ae):a(O.check,V,Ae,k.next_out-Ae)),k.data_type=O.bits+(O.last?64:0)+(O.mode===12?128:0)+(O.mode===20||O.mode===15?256:0),(se==0&&Ae===0||L===4)&&Le===h&&(Le=-5),Le)},r.inflateEnd=function(k){if(!k||!k.state)return d;var L=k.state;return L.window&&(L.window=null),k.state=null,h},r.inflateGetHeader=function(k,L){var O;return k&&k.state?(2&(O=k.state).wrap)==0?d:((O.head=L).done=!1,h):d},r.inflateSetDictionary=function(k,L){var O,G=L.length;return k&&k.state?(O=k.state).wrap!==0&&O.mode!==11?d:O.mode===11&&a(1,L,G,0)!==O.check?-3:N(k,L,G,G)?(O.mode=31,-4):(O.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],A=[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],c=[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(g,u,h,d,m,p,_,f){var I,C,y,x,E,S,b,v,M,N=f.bits,k=0,L=0,O=0,G=0,V=0,K=0,Z=0,te=0,ee=0,X=0,ie=null,se=0,Ae=new s.Buf16(16),de=new s.Buf16(16),me=null,ye=0;for(k=0;k<=15;k++)Ae[k]=0;for(L=0;L<d;L++)Ae[u[h+L]]++;for(V=N,G=15;1<=G&&Ae[G]===0;G--);if(G<V&&(V=G),G===0)return m[p++]=20971520,m[p++]=20971520,f.bits=1,0;for(O=1;O<G&&Ae[O]===0;O++);for(V<O&&(V=O),k=te=1;k<=15;k++)if(te<<=1,(te-=Ae[k])<0)return-1;if(0<te&&(g===0||G!==1))return-1;for(de[1]=0,k=1;k<15;k++)de[k+1]=de[k]+Ae[k];for(L=0;L<d;L++)u[h+L]!==0&&(_[de[u[h+L]]++]=L);if(S=g===0?(ie=me=_,19):g===1?(ie=a,se-=257,me=A,ye-=257,256):(ie=c,me=l,-1),k=O,E=p,Z=L=X=0,y=-1,x=(ee=1<<(K=V))-1,g===1&&852<ee||g===2&&592<ee)return 1;for(;;){for(b=k-Z,M=_[L]<S?(v=0,_[L]):_[L]>S?(v=me[ye+_[L]],ie[se+_[L]]):(v=96,0),I=1<<k-Z,O=C=1<<K;m[E+(X>>Z)+(C-=I)]=b<<24|v<<16|M|0,C!==0;);for(I=1<<k-1;X&I;)I>>=1;if(I!==0?(X&=I-1,X+=I):X=0,L++,--Ae[k]==0){if(k===G)break;k=u[h+_[L]]}if(V<k&&(X&x)!==y){for(Z===0&&(Z=V),E+=O,te=1<<(K=k-Z);K+Z<G&&!((te-=Ae[K+Z])<=0);)K++,te<<=1;if(ee+=1<<K,g===1&&852<ee||g===2&&592<ee)return 1;m[y=X&x]=V<<24|K<<16|E-p|0}}return X!==0&&(m[E+X]=k-Z<<24|64<<16|0),f.bits=V,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,A=1;function c(Oe){for(var De=Oe.length;0<=--De;)Oe[De]=0}var l=0,g=29,u=256,h=u+1+g,d=30,m=19,p=2*h+1,_=15,f=16,I=7,C=256,y=16,x=17,E=18,S=[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],v=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],M=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],N=new Array(2*(h+2));c(N);var k=new Array(2*d);c(k);var L=new Array(512);c(L);var O=new Array(256);c(O);var G=new Array(g);c(G);var V,K,Z,te=new Array(d);function ee(Oe,De,Be,ke,be){this.static_tree=Oe,this.extra_bits=De,this.extra_base=Be,this.elems=ke,this.max_length=be,this.has_stree=Oe&&Oe.length}function X(Oe,De){this.dyn_tree=Oe,this.max_code=0,this.stat_desc=De}function ie(Oe){return Oe<256?L[Oe]:L[256+(Oe>>>7)]}function se(Oe,De){Oe.pending_buf[Oe.pending++]=255&De,Oe.pending_buf[Oe.pending++]=De>>>8&255}function Ae(Oe,De,Be){Oe.bi_valid>f-Be?(Oe.bi_buf|=De<<Oe.bi_valid&65535,se(Oe,Oe.bi_buf),Oe.bi_buf=De>>f-Oe.bi_valid,Oe.bi_valid+=Be-f):(Oe.bi_buf|=De<<Oe.bi_valid&65535,Oe.bi_valid+=Be)}function de(Oe,De,Be){Ae(Oe,Be[2*De],Be[2*De+1])}function me(Oe,De){for(var Be=0;Be|=1&Oe,Oe>>>=1,Be<<=1,0<--De;);return Be>>>1}function ye(Oe,De,Be){var ke,be,Ye=new Array(_+1),We=0;for(ke=1;ke<=_;ke++)Ye[ke]=We=We+Be[ke-1]<<1;for(be=0;be<=De;be++){var tt=Oe[2*be+1];tt!==0&&(Oe[2*be]=me(Ye[tt]++,tt))}}function le(Oe){var De;for(De=0;De<h;De++)Oe.dyn_ltree[2*De]=0;for(De=0;De<d;De++)Oe.dyn_dtree[2*De]=0;for(De=0;De<m;De++)Oe.bl_tree[2*De]=0;Oe.dyn_ltree[2*C]=1,Oe.opt_len=Oe.static_len=0,Oe.last_lit=Oe.matches=0}function Ce(Oe){8<Oe.bi_valid?se(Oe,Oe.bi_buf):0<Oe.bi_valid&&(Oe.pending_buf[Oe.pending++]=Oe.bi_buf),Oe.bi_buf=0,Oe.bi_valid=0}function _e(Oe,De,Be,ke){var be=2*De,Ye=2*Be;return Oe[be]<Oe[Ye]||Oe[be]===Oe[Ye]&&ke[De]<=ke[Be]}function Qe(Oe,De,Be){for(var ke=Oe.heap[Be],be=Be<<1;be<=Oe.heap_len&&(be<Oe.heap_len&&_e(De,Oe.heap[be+1],Oe.heap[be],Oe.depth)&&be++,!_e(De,ke,Oe.heap[be],Oe.depth));)Oe.heap[Be]=Oe.heap[be],Be=be,be<<=1;Oe.heap[Be]=ke}function Te(Oe,De,Be){var ke,be,Ye,We,tt=0;if(Oe.last_lit!==0)for(;ke=Oe.pending_buf[Oe.d_buf+2*tt]<<8|Oe.pending_buf[Oe.d_buf+2*tt+1],be=Oe.pending_buf[Oe.l_buf+tt],tt++,ke===0?de(Oe,be,De):(de(Oe,(Ye=O[be])+u+1,De),(We=S[Ye])!==0&&Ae(Oe,be-=G[Ye],We),de(Oe,Ye=ie(--ke),Be),(We=b[Ye])!==0&&Ae(Oe,ke-=te[Ye],We)),tt<Oe.last_lit;);de(Oe,C,De)}function Se(Oe,De){var Be,ke,be,Ye=De.dyn_tree,We=De.stat_desc.static_tree,tt=De.stat_desc.has_stree,ct=De.stat_desc.elems,at=-1;for(Oe.heap_len=0,Oe.heap_max=p,Be=0;Be<ct;Be++)Ye[2*Be]!==0?(Oe.heap[++Oe.heap_len]=at=Be,Oe.depth[Be]=0):Ye[2*Be+1]=0;for(;Oe.heap_len<2;)Ye[2*(be=Oe.heap[++Oe.heap_len]=at<2?++at:0)]=1,Oe.depth[be]=0,Oe.opt_len--,tt&&(Oe.static_len-=We[2*be+1]);for(De.max_code=at,Be=Oe.heap_len>>1;1<=Be;Be--)Qe(Oe,Ye,Be);for(be=ct;Be=Oe.heap[1],Oe.heap[1]=Oe.heap[Oe.heap_len--],Qe(Oe,Ye,1),ke=Oe.heap[1],Oe.heap[--Oe.heap_max]=Be,Oe.heap[--Oe.heap_max]=ke,Ye[2*be]=Ye[2*Be]+Ye[2*ke],Oe.depth[be]=(Oe.depth[Be]>=Oe.depth[ke]?Oe.depth[Be]:Oe.depth[ke])+1,Ye[2*Be+1]=Ye[2*ke+1]=be,Oe.heap[1]=be++,Qe(Oe,Ye,1),2<=Oe.heap_len;);Oe.heap[--Oe.heap_max]=Oe.heap[1],(function(Fe,je){var it,At,Rt,Ht,ht,yt,Ct=je.dyn_tree,fe=je.max_code,$e=je.stat_desc.static_tree,ut=je.stat_desc.has_stree,Et=je.stat_desc.extra_bits,_t=je.stat_desc.extra_base,Pt=je.stat_desc.max_length,Gt=0;for(Ht=0;Ht<=_;Ht++)Fe.bl_count[Ht]=0;for(Ct[2*Fe.heap[Fe.heap_max]+1]=0,it=Fe.heap_max+1;it<p;it++)Pt<(Ht=Ct[2*Ct[2*(At=Fe.heap[it])+1]+1]+1)&&(Ht=Pt,Gt++),Ct[2*At+1]=Ht,fe<At||(Fe.bl_count[Ht]++,ht=0,_t<=At&&(ht=Et[At-_t]),yt=Ct[2*At],Fe.opt_len+=yt*(Ht+ht),ut&&(Fe.static_len+=yt*($e[2*At+1]+ht)));if(Gt!==0){do{for(Ht=Pt-1;Fe.bl_count[Ht]===0;)Ht--;Fe.bl_count[Ht]--,Fe.bl_count[Ht+1]+=2,Fe.bl_count[Pt]--,Gt-=2}while(0<Gt);for(Ht=Pt;Ht!==0;Ht--)for(At=Fe.bl_count[Ht];At!==0;)fe<(Rt=Fe.heap[--it])||(Ct[2*Rt+1]!==Ht&&(Fe.opt_len+=(Ht-Ct[2*Rt+1])*Ct[2*Rt],Ct[2*Rt+1]=Ht),At--)}})(Oe,De),ye(Ye,at,Oe.bl_count)}function he(Oe,De,Be){var ke,be,Ye=-1,We=De[1],tt=0,ct=7,at=4;for(We===0&&(ct=138,at=3),De[2*(Be+1)+1]=65535,ke=0;ke<=Be;ke++)be=We,We=De[2*(ke+1)+1],++tt<ct&&be===We||(tt<at?Oe.bl_tree[2*be]+=tt:be!==0?(be!==Ye&&Oe.bl_tree[2*be]++,Oe.bl_tree[2*y]++):tt<=10?Oe.bl_tree[2*x]++:Oe.bl_tree[2*E]++,Ye=be,at=(tt=0)===We?(ct=138,3):be===We?(ct=6,3):(ct=7,4))}function Le(Oe,De,Be){var ke,be,Ye=-1,We=De[1],tt=0,ct=7,at=4;for(We===0&&(ct=138,at=3),ke=0;ke<=Be;ke++)if(be=We,We=De[2*(ke+1)+1],!(++tt<ct&&be===We)){if(tt<at)for(;de(Oe,be,Oe.bl_tree),--tt!=0;);else be!==0?(be!==Ye&&(de(Oe,be,Oe.bl_tree),tt--),de(Oe,y,Oe.bl_tree),Ae(Oe,tt-3,2)):tt<=10?(de(Oe,x,Oe.bl_tree),Ae(Oe,tt-3,3)):(de(Oe,E,Oe.bl_tree),Ae(Oe,tt-11,7));Ye=be,at=(tt=0)===We?(ct=138,3):be===We?(ct=6,3):(ct=7,4)}}c(te);var Me=!1;function Ne(Oe,De,Be,ke){Ae(Oe,(l<<1)+(ke?1:0),3),(function(be,Ye,We,tt){Ce(be),se(be,We),se(be,~We),s.arraySet(be.pending_buf,be.window,Ye,We,be.pending),be.pending+=We})(Oe,De,Be)}r._tr_init=function(Oe){Me||((function(){var De,Be,ke,be,Ye,We=new Array(_+1);for(be=ke=0;be<g-1;be++)for(G[be]=ke,De=0;De<1<<S[be];De++)O[ke++]=be;for(O[ke-1]=be,be=Ye=0;be<16;be++)for(te[be]=Ye,De=0;De<1<<b[be];De++)L[Ye++]=be;for(Ye>>=7;be<d;be++)for(te[be]=Ye<<7,De=0;De<1<<b[be]-7;De++)L[256+Ye++]=be;for(Be=0;Be<=_;Be++)We[Be]=0;for(De=0;De<=143;)N[2*De+1]=8,De++,We[8]++;for(;De<=255;)N[2*De+1]=9,De++,We[9]++;for(;De<=279;)N[2*De+1]=7,De++,We[7]++;for(;De<=287;)N[2*De+1]=8,De++,We[8]++;for(ye(N,h+1,We),De=0;De<d;De++)k[2*De+1]=5,k[2*De]=me(De,5);V=new ee(N,S,u+1,h,_),K=new ee(k,b,0,d,_),Z=new ee(new Array(0),v,0,m,I)})(),Me=!0),Oe.l_desc=new X(Oe.dyn_ltree,V),Oe.d_desc=new X(Oe.dyn_dtree,K),Oe.bl_desc=new X(Oe.bl_tree,Z),Oe.bi_buf=0,Oe.bi_valid=0,le(Oe)},r._tr_stored_block=Ne,r._tr_flush_block=function(Oe,De,Be,ke){var be,Ye,We=0;0<Oe.level?(Oe.strm.data_type===2&&(Oe.strm.data_type=(function(tt){var ct,at=4093624447;for(ct=0;ct<=31;ct++,at>>>=1)if(1&at&&tt.dyn_ltree[2*ct]!==0)return a;if(tt.dyn_ltree[18]!==0||tt.dyn_ltree[20]!==0||tt.dyn_ltree[26]!==0)return A;for(ct=32;ct<u;ct++)if(tt.dyn_ltree[2*ct]!==0)return A;return a})(Oe)),Se(Oe,Oe.l_desc),Se(Oe,Oe.d_desc),We=(function(tt){var ct;for(he(tt,tt.dyn_ltree,tt.l_desc.max_code),he(tt,tt.dyn_dtree,tt.d_desc.max_code),Se(tt,tt.bl_desc),ct=m-1;3<=ct&&tt.bl_tree[2*M[ct]+1]===0;ct--);return tt.opt_len+=3*(ct+1)+5+5+4,ct})(Oe),be=Oe.opt_len+3+7>>>3,(Ye=Oe.static_len+3+7>>>3)<=be&&(be=Ye)):be=Ye=Be+5,Be+4<=be&&De!==-1?Ne(Oe,De,Be,ke):Oe.strategy===4||Ye===be?(Ae(Oe,2+(ke?1:0),3),Te(Oe,N,k)):(Ae(Oe,4+(ke?1:0),3),(function(tt,ct,at,Fe){var je;for(Ae(tt,ct-257,5),Ae(tt,at-1,5),Ae(tt,Fe-4,4),je=0;je<Fe;je++)Ae(tt,tt.bl_tree[2*M[je]+1],3);Le(tt,tt.dyn_ltree,ct-1),Le(tt,tt.dyn_dtree,at-1)})(Oe,Oe.l_desc.max_code+1,Oe.d_desc.max_code+1,We+1),Te(Oe,Oe.dyn_ltree,Oe.dyn_dtree)),le(Oe),ke&&Ce(Oe)},r._tr_tally=function(Oe,De,Be){return Oe.pending_buf[Oe.d_buf+2*Oe.last_lit]=De>>>8&255,Oe.pending_buf[Oe.d_buf+2*Oe.last_lit+1]=255&De,Oe.pending_buf[Oe.l_buf+Oe.last_lit]=255&Be,Oe.last_lit++,De===0?Oe.dyn_ltree[2*Be]++:(Oe.matches++,De--,Oe.dyn_ltree[2*(O[Be]+u+1)]++,Oe.dyn_dtree[2*ie(De)]++),Oe.last_lit===Oe.lit_bufsize-1},r._tr_align=function(Oe){Ae(Oe,2,3),de(Oe,C,N),(function(De){De.bi_valid===16?(se(De,De.bi_buf),De.bi_buf=0,De.bi_valid=0):8<=De.bi_valid&&(De.pending_buf[De.pending++]=255&De.bi_buf,De.bi_buf>>=8,De.bi_valid-=8)})(Oe)}},{"../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,A){if(!a.setImmediate){var c,l,g,u,h=1,d={},m=!1,p=a.document,_=Object.getPrototypeOf&&Object.getPrototypeOf(a);_=_&&_.setTimeout?_:a,c={}.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}})()?(u="setImmediate$"+Math.random()+"$",a.addEventListener?a.addEventListener("message",C,!1):a.attachEvent("onmessage",C),function(y){a.postMessage(u+y,"*")}):a.MessageChannel?((g=new MessageChannel).port1.onmessage=function(y){I(y.data)},function(y){g.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)},_.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 S={callback:y,args:x};return d[h]=S,c(h),h++},_.clearImmediate=f}function f(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 S=E.callback,b=E.args;switch(b.length){case 0:S();break;case 1:S(b[0]);break;case 2:S(b[0],b[1]);break;case 3:S(b[0],b[1],b[2]);break;default:S.apply(A,b)}})(x)}finally{f(y),m=!1}}}}function C(y){y.source===a&&typeof y.data=="string"&&y.data.indexOf(u)===0&&I(+y.data.slice(u.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof b1<"u"?b1:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(_Ke)),_Ke.exports}var hPi=dPi();const rhe=Q1(hPi),mPi=async({circuitJson:t,projectName:e})=>{await Js.promise((async()=>{const n=new rhe,[o,{convertCircuitJsonToBomRows:i,convertBomRowsToCsv:r},{convertCircuitJsonToPickAndPlaceCsv:s}]=await Promise.all([S2("circuit-json-to-gerber"),S2("circuit-json-to-bom-csv"),S2("circuit-json-to-pnp-csv")]),a=t.filter(h=>!("error_type"in h)&&!("warning_type"in h)),A=o.convertCircuitJsonToGerberFiles(a,{flip_y_axis:!1});for(const[h,d]of Object.entries(A))n.file(`gerber/${h}`,d);const c=await i({circuitJson:t}),l=await r(c);n.file("bom.csv",l);const g=await s(t,{supplier:"jlcpcb"});n.file("pick_and_place.csv",g);const u=await n.generateAsync({type:"blob"});D2(u,{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)}`})},pPi=async t=>{const{createFdmComponentBox:e,renderFdmComponentBoxPng:n}=await S2("circuit-json-to-fdm-component-box"),[o,i]=await Promise.all([e(t),n(t,{},{width:960,height:640})]);return{...o,previewPng:i}},_Pi=async t=>{const{createFdmComponentBox:e}=await S2("circuit-json-to-fdm-component-box");return e(t)},irn=({generatedBox:t,projectName:e})=>{const n=Uint8Array.from(t.threeMf);D2(new Blob([n.buffer],{type:"model/3mf"}),{fileName:`${kYe(e)}-component-box.3mf`})},fPi=async({circuitJson:t,projectName:e})=>{await Js.promise((async()=>{const n=await _Pi(t);irn({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)}`})},IPi=async({circuitJson:t,projectName:e})=>{let n;try{const{convertCircuitJsonToGltf:o}=await S2("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}D2(n,{fileName:`${e}.glb`})},CPi=async({circuitJson:t,libraryName:e})=>{const{CircuitJsonToKicadLibraryConverter:n}=await S2("circuit-json-to-kicad"),o=new n(t,{libraryName:e,footprintLibraryName:e});o.runUntilFinished();const i=o.getOutput(),r=new rhe;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}
|
|
5777
5777
|
`)}if(i.model3dSourcePaths.length>0){const s=r.folder(`${e}.3dshapes`);if(s)for(const a of i.model3dSourcePaths)try{const A=a.split("/").pop()||a,c=await fetch(a);if(c.ok){const l=await c.arrayBuffer();s.file(A,l)}}catch{}}return r.file("fp-lib-table",i.fpLibTableString),r.file("sym-lib-table",i.symLibTableString),r},yPi=async({circuitJson:t,projectName:e})=>{await Js.promise((async()=>{const o=await(await CPi({circuitJson:t,libraryName:e})).generateAsync({type:"blob"});D2(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)}`})},xPi=async({circuitJson:t,projectName:e})=>{const{CircuitJsonToKicadPcbConverter:n,CircuitJsonToKicadSchConverter:o,CircuitJsonToKicadProConverter:i,resolveAndLoadKicad3dModelFiles:r}=await S2("circuit-json-to-kicad"),s=new o(t);s.runUntilFinished();const a=s.getOutputString(),A=new n(t,{includeBuiltin3dModels:!0,projectName:e});A.runUntilFinished();const c=A.getOutputString(),l=new i(t,{projectName:e,schematicFilename:`${e}.kicad_sch`,pcbFilename:`${e}.kicad_pcb`});l.runUntilFinished();const g=l.getOutputString(),u=new rhe;return u.file(`${e}.kicad_sch`,a),u.file(`${e}.kicad_pcb`,c),u.file(`${e}.kicad_pro`,g),await r({projectName:e,model3dSourcePaths:A.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:h,content:d})=>{u.file(h,d)},onError:({sourcePath:h})=>{console.warn(`Failed to load 3D model from ${h}`)}}),u},EPi=async({circuitJson:t,projectName:e})=>{await Js.promise((async()=>{const o=await(await xPi({circuitJson:t,projectName:e})).generateAsync({type:"blob"});D2(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)}`})},rrn=async({circuitJson:t,projectName:e,options:n={}})=>{try{const{convertCircuitJsonToLbrn:o}=await S2("circuit-json-to-lbrn"),r=(await o(t,{includeSilkscreen:n.includeSilkscreen??!1,includeOxidationCleaningLayer:n.includeOxidationCleaningLayer??!0})).toXml(),s=new Blob([r],{type:"application/lbrn"});D2(s,{fileName:`${e}.lbrn2`})}catch(o){const i=o instanceof Error?o.message:"Unknown error";Js.error(`Failed to export to LBRN format: ${i}`)}},BPi=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToPinoutSvg:n}=await S2("circuit-to-svg"),o=n(t);D2(o,{fileName:`${e}-pinout.svg`,mimeType:"image/svg+xml"})},SPi=async({circuitJson:t,projectName:e})=>{const{circuitJsonToStep:n}=await S2("circuit-json-to-step"),o=t.find(c=>c.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){Js.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(c){const l=c instanceof Error?c.message:"Unknown error";Js.error(`Failed to convert circuit to STEP format: ${l}`);return}const A=new Blob([a],{type:"application/step"});try{D2(A,{fileName:`${e}.step`})}catch(c){const l=c instanceof Error?c.message:"Unknown error";Js.error(`Failed to download STEP file: ${l}`)}},bPi=[{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"}],QPi=async({exportName:t,circuitJson:e,simpleRouteJson:n,projectName:o})=>{const i=kYe(o);if(t==="Fabrication Files"){await mPi({circuitJson:e,projectName:i});return}if(t==="KiCad Project"){await EPi({circuitJson:e,projectName:i});return}if(t==="Altium Project"){await uPi({circuitJson:e,projectName:i});return}if(t==="KiCad Library"){await yPi({circuitJson:e,projectName:i});return}if(t==="Circuit JSON"){D2(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");D2(JSON.stringify(n,null,2),{fileName:`${i}.simple-route.json`,mimeType:"application/json"});return}if(t==="GLB (Binary GLTF)"){await IPi({circuitJson:e,projectName:i});return}if(t==="Pinout SVG"){BPi({circuitJson:e,projectName:i});return}if(t==="STEP"){await SPi({circuitJson:e,projectName:i});return}if(t==="Component Box (3MF)"){await fPi({circuitJson:e,projectName:i});return}if(t==="LightBurn"){await rrn({circuitJson:e,projectName:i});return}throw new Error(`Unsupported export type: "${t}"`)},vPi=({packageName:t,onSelectReview:e})=>{const n=Od(g=>g.fsMap),o=Od(g=>g.circuitJson),[i,r]=$.useState([]),[s,a]=$.useState(!1),[A,c]=$.useState(!1);$.useEffect(()=>{!t||!rce()||(a(!0),wJ.get("ai_reviews/list",{searchParams:{package_name:t}}).json().then(g=>r(g.ai_reviews)).catch(g=>{console.error("Failed to load AI reviews",g),Js.error("Failed to load AI reviews")}).finally(()=>a(!1)))},[t]);const l=async()=>{if(!o){Js.error("Need Circuit JSON to Request AI Review");return}if(!rce()){Js.error("Missing registry token");return}c(!0);try{const{ai_review:g}=await wJ.post("ai_reviews/create",{json:{package_name:t??"unknown",fs_map:Object.fromEntries(n),circuit_json:o}}).json();r(u=>[g,...u]),e(g),Js.success("AI review requested")}catch(g){console.error("Failed to create AI review",g),Js.error("Failed to request AI review")}finally{c(!1)}};return Y.jsxs(Y.Fragment,{children:[Y.jsxs(W4,{children:[Y.jsx(j4,{children:"AI Review"}),Y.jsx(CR,{children:"Select an AI review or request a new one."})]}),Y.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:Y.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?Y.jsx("div",{className:"rf-text-sm",children:"Loading..."}):i.length>0?i.map(g=>Y.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>e(g),children:new Date(g.created_at||"").toLocaleString()},g.ai_review_id)):Y.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),Y.jsx(zO,{className:"rf-mt-4",children:Y.jsx(Xa,{onClick:l,disabled:A,children:A?"Requesting...":"Review my Board"})})]})};function fKe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var yR=fKe();function srn(t){yR=t}var mq={exec:()=>null};function sg(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(gy.caret,"$1"),n=n.replace(i,s),o},getRegex:()=>new RegExp(n,e)};return o}var gy={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")},PPi=/^(?:[ \t]*(?:\n|$))+/,wPi=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,DPi=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,pq=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,MPi=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,IKe=/(?:[*+-]|\d{1,9}[.)])/,arn=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Arn=sg(arn).replace(/bull/g,IKe).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(),RPi=sg(arn).replace(/bull/g,IKe).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(),CKe=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,NPi=/^[^\n]+/,yKe=/(?!\s*\])(?:\\.|[^\[\]\\])+/,TPi=sg(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",yKe).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),kPi=sg(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,IKe).getRegex(),she="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",xKe=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,FPi=sg("^ {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",xKe).replace("tag",she).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),crn=sg(CKe).replace("hr",pq).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",she).getRegex(),LPi=sg(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",crn).getRegex(),EKe={blockquote:LPi,code:wPi,def:TPi,fences:DPi,heading:MPi,hr:pq,html:FPi,lheading:Arn,list:kPi,newline:PPi,paragraph:crn,table:mq,text:NPi},lrn=sg("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",pq).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",she).getRegex(),HPi={...EKe,lheading:RPi,table:lrn,paragraph:sg(CKe).replace("hr",pq).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",lrn).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",she).getRegex()},OPi={...EKe,html:sg(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",xKe).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:mq,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:sg(CKe).replace("hr",pq).replace("heading",` *#{1,6} *[^
|
|
5778
5778
|
]`).replace("lheading",Arn).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},GPi=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,UPi=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,grn=/^( {2,}|\\)\n(?!\s*$)/,YPi=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ahe=/[\p{P}\p{S}]/u,BKe=/[\s\p{P}\p{S}]/u,urn=/[^\s\p{P}\p{S}]/u,KPi=sg(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,BKe).getRegex(),drn=/(?!~)[\p{P}\p{S}]/u,zPi=/(?!~)[\s\p{P}\p{S}]/u,VPi=/(?:[^\s\p{P}\p{S}]|~)/u,JPi=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,hrn=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,WPi=sg(hrn,"u").replace(/punct/g,ahe).getRegex(),jPi=sg(hrn,"u").replace(/punct/g,drn).getRegex(),mrn="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",qPi=sg(mrn,"gu").replace(/notPunctSpace/g,urn).replace(/punctSpace/g,BKe).replace(/punct/g,ahe).getRegex(),XPi=sg(mrn,"gu").replace(/notPunctSpace/g,VPi).replace(/punctSpace/g,zPi).replace(/punct/g,drn).getRegex(),$Pi=sg("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,urn).replace(/punctSpace/g,BKe).replace(/punct/g,ahe).getRegex(),ZPi=sg(/\\(punct)/,"gu").replace(/punct/g,ahe).getRegex(),ewi=sg(/^<(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(),twi=sg(xKe).replace("(?:-->|$)","-->").getRegex(),nwi=sg("^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",twi).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ahe=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,owi=sg(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Ahe).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),prn=sg(/^!?\[(label)\]\[(ref)\]/).replace("label",Ahe).replace("ref",yKe).getRegex(),_rn=sg(/^!?\[(ref)\](?:\[\])?/).replace("ref",yKe).getRegex(),iwi=sg("reflink|nolink(?!\\()","g").replace("reflink",prn).replace("nolink",_rn).getRegex(),SKe={_backpedal:mq,anyPunctuation:ZPi,autolink:ewi,blockSkip:JPi,br:grn,code:UPi,del:mq,emStrongLDelim:WPi,emStrongRDelimAst:qPi,emStrongRDelimUnd:$Pi,escape:GPi,link:owi,nolink:_rn,punctuation:KPi,reflink:prn,reflinkSearch:iwi,tag:nwi,text:YPi,url:mq},rwi={...SKe,link:sg(/^!?\[(label)\]\((.*?)\)/).replace("label",Ahe).getRegex(),reflink:sg(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ahe).getRegex()},bKe={...SKe,emStrongRDelimAst:XPi,emStrongLDelim:jPi,url:sg(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},swi={...bKe,br:sg(grn).replace("{2,}","*").getRegex(),text:sg(bKe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},che={normal:EKe,gfm:HPi,pedantic:OPi},_q={normal:SKe,gfm:bKe,breaks:swi,pedantic:rwi},awi={"&":"&","<":"<",">":">",'"':""","'":"'"},frn=t=>awi[t];function yv(t,e){if(e){if(gy.escapeTest.test(t))return t.replace(gy.escapeReplace,frn)}else if(gy.escapeTestNoEncode.test(t))return t.replace(gy.escapeReplaceNoEncode,frn);return t}function Irn(t){try{t=encodeURI(t).replace(gy.percentDecode,"%")}catch{return null}return t}function Crn(t,e){const n=t.replace(gy.findPipe,(r,s,a)=>{let A=!1,c=s;for(;--c>=0&&a[c]==="\\";)A=!A;return A?"|":" |"}),o=n.split(gy.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(gy.slashPipe,"|");return o}function fq(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 Awi(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 yrn(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 A={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:r,title:s,text:a,tokens:o.inlineTokens(a)};return o.state.inLink=!1,A}function cwi(t,e,n){const o=t.match(n.other.indentCodeCompensation);if(o===null)return e;const i=o[1];return e.split(`
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.2537-libonly",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@tscircuit/checks": "^0.0.189",
|
|
52
52
|
"@tscircuit/circuit-json-util": "^0.0.113",
|
|
53
53
|
"@tscircuit/copper-pour-solver": "^0.0.54",
|
|
54
|
-
"@tscircuit/core": "^0.0.
|
|
54
|
+
"@tscircuit/core": "^0.0.1902",
|
|
55
55
|
"@tscircuit/create-fdm-enclosure": "0.0.4",
|
|
56
56
|
"@tscircuit/eval": "^0.0.1398",
|
|
57
57
|
"@tscircuit/fanout-solver": "0.0.76",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"@tscircuit/math-utils": "^0.0.36",
|
|
66
66
|
"@tscircuit/miniflex": "^0.0.4",
|
|
67
67
|
"@tscircuit/ngspice-spice-engine": "^0.0.20",
|
|
68
|
-
"@tscircuit/props": "^0.0.
|
|
69
|
-
"@tscircuit/runframe": "^0.0.
|
|
68
|
+
"@tscircuit/props": "^0.0.653",
|
|
69
|
+
"@tscircuit/runframe": "^0.0.2717",
|
|
70
70
|
"@tscircuit/schematic-match-adapt": "^0.0.18",
|
|
71
|
-
"@tscircuit/schematic-trace-solver": "^0.0.
|
|
71
|
+
"@tscircuit/schematic-trace-solver": "^0.0.196",
|
|
72
72
|
"@tscircuit/simple-3d-svg": "^0.0.41",
|
|
73
73
|
"@tscircuit/solver-utils": "^0.0.16",
|
|
74
74
|
"@tscircuit/soup-util": "^0.0.41",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"calculate-cell-boundaries": "^0.0.21",
|
|
77
77
|
"calculate-elbow": "^0.0.12",
|
|
78
78
|
"calculate-packing": "^0.0.89",
|
|
79
|
-
"circuit-json": "^0.0.
|
|
79
|
+
"circuit-json": "^0.0.487",
|
|
80
80
|
"circuit-json-to-bpc": "^0.0.13",
|
|
81
81
|
"circuit-json-to-connectivity-map": "^0.0.30",
|
|
82
82
|
"circuit-json-to-gltf": "^0.0.124",
|