tscircuit 0.0.1941 → 0.0.1942

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.
@@ -5622,7 +5622,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
5622
5622
  50% { opacity: 0.2; }
5623
5623
  100% { opacity: 0.6; }
5624
5624
  }
5625
- `,i.appendChild(f)}})}};r();const s=new MutationObserver(r);return s.observe(i,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},sSt=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],Cxo=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:i}=t;X.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!i||!n||n.length===0)return;const r=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=lp(n).source_group?.list().filter(f=>!f.is_subcircuit)||[],l=lp(n).schematic_component?.list()||[],A=new Map;c.forEach(f=>{const y=f;if(y.parent_source_group_id){const C=A.get(y.parent_source_group_id)||[];C.push(f.source_group_id),A.set(y.parent_source_group_id,C)}});const u=f=>{const y=[],C=A.get(f)||[];for(const I of C)y.push(I),y.push(...u(I));return y},d=f=>{const y=c.find(C=>C.source_group_id===f);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},_=c.length>0&&c.some(f=>f.name&&f.name.trim()!=="");let h=[];if(_){const f=new Map;for(const y of l){const C=lp(n).source_component.get(y.source_component_id);C?.source_group_id&&(f.has(C.source_group_id)||f.set(C.source_group_id,[]),f.get(C.source_group_id).push(y))}c.forEach((y,C)=>{let I=f.get(y.source_group_id)||[];const E=u(y.source_group_id);for(const b of E){const P=f.get(b)||[];I=[...I,...P]}if(I.length>0){const b=d(y.source_group_id),P=u(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;h.push({id:y.source_group_id,name:y.name||`Group ${C+1}`,components:I,color:sSt[C%sSt.length],depthLevel:b,hasChildren:P,sourceGroupId:y.source_group_id})}})}const m=s.viewBox.baseVal,p=s.getBoundingClientRect(),g=Math.min(p.width/m.width,p.height/m.height)||1;h.sort((f,y)=>f.depthLevel-y.depthLevel),h.forEach(f=>{if(f.components.length===0)return;const y=xxo(f.components,s);if(!y)return;const C=Math.max(8,Math.min(25,15/Math.max(g,.3))),I=f.hasChildren?C*.6:0,E=C+I,b=Math.max(1,2/Math.max(g,.5)),P=f.depthLevel===0?b:b*.7,B=Math.max(4,8/Math.max(g,.5)),M=f.hasChildren?1.3:1,R=B*M,k=R*.5,H=document.createElementNS("http://www.w3.org/2000/svg","rect");H.setAttribute("class","schematic-group-overlay"),H.setAttribute("x",(y.minX-E).toString()),H.setAttribute("y",(y.minY-E).toString()),H.setAttribute("width",(y.maxX-y.minX+E*2).toString()),H.setAttribute("height",(y.maxY-y.minY+E*2).toString()),H.setAttribute("fill","none"),H.setAttribute("stroke",f.color),H.setAttribute("stroke-width",P.toString()),H.setAttribute("stroke-dasharray",`${R},${k}`),H.setAttribute("opacity","0.8"),H.setAttribute("rx","0"),H.setAttribute("ry","0");const F=Math.max(6,Math.min(20,14/Math.max(g,.2))),G=f.depthLevel===0||f.depthLevel===1?0:f.depthLevel*.2,W=F*(1-G),J=Math.max(1,W*.2),q=f.name,oe=document.createElementNS("http://www.w3.org/2000/svg","text");oe.setAttribute("font-size",W.toString()),oe.setAttribute("font-family","Arial, sans-serif"),oe.textContent=q,s.appendChild(oe);const le=oe.getBBox();s.removeChild(oe);const ee=le.width+J*2,re=W+J*2,ae=y.minX-E,ie=y.minY-E-re,de=document.createElementNS("http://www.w3.org/2000/svg","rect");de.setAttribute("class","schematic-group-overlay"),de.setAttribute("x",ae.toString()),de.setAttribute("y",(ie-re).toString()),de.setAttribute("width",ee.toString()),de.setAttribute("height",re.toString()),de.setAttribute("fill","transparent"),de.setAttribute("rx","0"),de.setAttribute("ry","0");const ye=document.createElementNS("http://www.w3.org/2000/svg","text");ye.setAttribute("class","schematic-group-overlay"),ye.setAttribute("x",(ae+J).toString()),ye.setAttribute("y",(ie+re-J).toString()),ye.setAttribute("fill",f.color),ye.setAttribute("font-size",W.toString()),ye.setAttribute("font-family","Arial, sans-serif"),ye.setAttribute("font-weight",f.depthLevel===0?"600":"500"),ye.setAttribute("stroke",f.color),ye.setAttribute("stroke-width",Math.max(.2,W*.02).toString()),ye.textContent=q,s.appendChild(H),s.appendChild(de),s.appendChild(ye)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(r)},[e,o,i])};function xxo(t,e){let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),i=Math.max(i,l.x+l.width),r=Math.max(r,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:i,maxY:r}}var Ixo=bc("schematic-viewer"),Exo=()=>{bc.enable("schematic-viewer*")},bxo=Ixo,aSt=t=>{const[e,n]=X.useState(0),[o,i]=X.useState(0);return X.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}},Sxo=bxo.extend("useComponentDragging"),Pxo=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:i,realToSvgProjection:r,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=X.useState(null),A=Ti(r,i),u=X.useRef(null),d=X.useRef(null),_=X.useRef(new Map);X.useEffect(()=>{e.forEach(b=>{"edit_event_type"in b&&b.edit_event_type==="edit_schematic_component_location"&&!b.in_progress&&_.current.set(b.schematic_component_id,{...b.new_center})})},[e]);const h=X.useCallback((b,P,B)=>{if(!s)return!1;const M=B.closest('[data-circuit-json-type="schematic_component"]');if(!M)return!1;const R=M.getAttribute("data-schematic-component-id");if(!R)return!1;o&&o();const k=lp(n).schematic_component.get(R);if(!k)return!1;u.current={x:b,y:P};let H;const F=_.current.get(R);if(F)H={...F};else{const W=rSt({editEvents:e,schematic_component_id:R});H={x:k.center.x+W.x,y:k.center.y+W.y},_.current.set(R,{...H})}const G={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:R,original_center:H,new_center:{...H},in_progress:!0,created_at:Date.now(),_element:M};return d.current=G,l(G),!0},[o,s,n,e]),m=X.useCallback(b=>{h(b.clientX,b.clientY,b.target)},[h]),p=X.useCallback(b=>{if(b.touches.length!==1)return;const P=b.touches[0];h(P.clientX,P.clientY,b.target)&&b.preventDefault()},[h]),g=X.useCallback((b,P)=>{if(!d.current||!u.current)return;const B={x:b-u.current.x,y:P-u.current.y},M={x:B.x/A.a,y:B.y/A.d};let R={x:d.current.original_center.x+M.x,y:d.current.original_center.y+M.y};if(a){const H=F=>Math.round(F*10)/10;R={x:H(R.x),y:H(R.y)}}const k={...d.current,new_center:R};d.current=k,l(k)},[A,a]),f=X.useCallback(b=>g(b.clientX,b.clientY),[g]),y=X.useCallback(b=>{if(b.touches.length!==1||!d.current)return;b.preventDefault();const P=b.touches[0];g(P.clientX,P.clientY)},[g]),C=X.useCallback(()=>{if(!d.current)return;const b={...d.current,in_progress:!1};_.current.set(b.schematic_component_id,{...b.new_center}),Sxo("endDrag calling onEditEvent with new edit event",{newEditEvent:b}),t&&t(b),d.current=null,u.current=null,l(null)},[t]),I=X.useCallback(()=>C(),[C]),E=X.useCallback(()=>C(),[C]);return X.useEffect(()=>(window.addEventListener("mousemove",f),window.addEventListener("mouseup",I),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",E),()=>{window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",I),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",E)}),[f,I,y,E]),{handleMouseDown:m,handleTouchStart:p,isDragging:!!d.current,activeEditEvent:c}},oE={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},vxo=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return K.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.schematicEditIcon},children:K.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[K.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),K.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},Bxo=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return K.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.schematicGridIcon},children:K.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:K.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},Mxo=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return K.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.viewMenuIcon},children:K.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[K.jsx("circle",{cx:"12",cy:"12",r:"1"}),K.jsx("circle",{cx:"12",cy:"5",r:"1"}),K.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},wxo={version:"2.0.65"},Dxo=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:i,onToggleGroups:r,showGrid:s,onToggleGrid:a})=>{const c=X.useMemo(()=>{if(!t||t.length===0)return!1;try{if((lp(t).source_group?.list()||[]).length>0)return!0;const A=lp(t).schematic_component?.list()||[];if(A.length>1){const u=new Set;for(const d of A){const _=lp(t).source_component.get(d.source_component_id);_?.ftype&&u.add(_.ftype)}return u.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?K.jsxs(K.Fragment,{children:[K.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:oE.viewMenuBackdrop}}),K.jsxs("div",{style:{position:"absolute",top:"56px",right:"16px",backgroundColor:"#ffffff",color:"#000000",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",zIndex:oE.viewMenu},children:[K.jsxs("div",{onClick:()=>{c&&r(!i)},onTouchEnd:l=>{l.preventDefault(),c&&r(!i)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[K.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:i&&"✓"}),"View Schematic Groups"]}),!c&&K.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),K.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[K.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),K.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(wxo?.version)]})]})]}):null},Qxo=()=>K.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:K.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),Txo=({onClick:t})=>K.jsx("div",{onClick:t,title:"Run SPICE simulation",style:{position:"absolute",top:"16px",right:"112px",backgroundColor:"#fff",color:"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.spiceSimulationIcon},children:K.jsx(Qxo,{})});Yee.register(rxo,cxo,FCo,HCo,WCo,txo,YCo);var Xee=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],cSt=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},Rxo=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:i})=>{const r=X.useMemo(()=>{const c=e.some(A=>A.toLowerCase().startsWith("v(")),l=e.some(A=>A.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return K.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!i)return K.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return K.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return K.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(A=>({x:Number(A.name),y:A[c]})),borderColor:Xee[l%Xee.length],backgroundColor:Xee[l%Xee.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return cSt(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>cSt(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:r,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return K.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:K.jsx(pxo,{options:a,data:s})})},Nxo=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:i,error:r,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,A]=X.useState(String(s.startTime)),[u,d]=X.useState(String(s.duration));X.useEffect(()=>{A(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const _=()=>{a({...s,startTime:Number(l),duration:Number(u)})},h=o.filter(m=>{const p=m.toLowerCase().startsWith("v("),g=m.toLowerCase().startsWith("i(");return!!(s.showVoltage&&p||s.showCurrent&&g)});return K.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1002,fontFamily:"sans-serif"},children:K.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[K.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[K.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),K.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),K.jsx("div",{children:K.jsx(Rxo,{plotData:n,nodes:h,isLoading:i,error:r,hasRun:c})}),K.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[K.jsxs("div",{style:{display:"flex",gap:"16px"},children:[K.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[K.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:m=>a({...s,showVoltage:m.target.checked})}),"Voltage"]}),K.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[K.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:m=>a({...s,showCurrent:m.target.checked})}),"Current"]})]}),K.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[K.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),K.jsx("input",{id:"startTime",type:"number",value:l,onChange:m=>A(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),K.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),K.jsx("input",{id:"duration",type:"number",value:u,onChange:m=>d(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),K.jsx("button",{onClick:_,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),K.jsxs("div",{style:{marginTop:"24px"},children:[K.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),K.jsx("pre",{style:{backgroundColor:"#fafafa",padding:"16px",borderRadius:"6px",maxHeight:"150px",overflowY:"auto",border:"1px solid #eee",color:"#333",fontSize:"13px",fontFamily:"monospace"},children:t})]})]})})},kxo="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",Jee=null,Lxo=()=>{if(typeof window>"u")return null;if(Jee)return Jee;try{const t=new Blob([atob(kxo)],{type:"application/javascript"});return Jee=URL.createObjectURL(t),Jee}catch(t){return console.error("Failed to create blob URL for worker",t),null}},Hxo=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],i=Object.keys(e).filter(a=>a!==n),r=i;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return i.forEach(A=>{l[A]=e[A][c]}),l}),nodes:r}},Fxo=t=>{const[e,n]=X.useState([]),[o,i]=X.useState([]),[r,s]=X.useState(!0),[a,c]=X.useState(null);return X.useEffect(()=>{if(!t){s(!1),n([]),i([]),c(null);return}s(!0),c(null),n([]),i([]);const l=Lxo();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const A=new Worker(l,{type:"module"});return A.onmessage=u=>{if(u.data.type==="result")try{const{plotData:d,nodes:_}=Hxo(u.data.result);n(d),i(_)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else u.data.type==="error"&&c(u.data.error);s(!1)},A.onerror=u=>{c(u.message),s(!1)},A.postMessage({spiceString:t}),()=>{A.terminate()}},[t]),{plotData:e,nodes:o,isLoading:r,error:a}},GPe=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},Oxo=(t,e)=>{const o=rZe(t).toSpiceString(),r=o.split(`
5625
+ `,i.appendChild(f)}})}};r();const s=new MutationObserver(r);return s.observe(i,{childList:!0,subtree:!1,characterData:!1}),()=>{s.disconnect()}},[t,n,e,o])},sSt=["#8B0000","#2F4F4F","#191970","#006400","#FF4500","#800080","#2E8B57","#B8860B","#C71585","#008B8B"],Cxo=t=>{const{svgDivRef:e,circuitJson:n,circuitJsonKey:o,showGroups:i}=t;X.useEffect(()=>{if(e.current&&e.current.querySelectorAll(".schematic-group-overlay").forEach(a=>a.remove()),!e.current||!i||!n||n.length===0)return;const r=setTimeout(()=>{if(!e.current)return;const s=e.current.querySelector("svg");if(!s)return;s.querySelectorAll(".schematic-group-overlay").forEach(c=>c.remove());try{const c=lp(n).source_group?.list().filter(f=>!f.is_subcircuit)||[],l=lp(n).schematic_component?.list()||[],A=new Map;c.forEach(f=>{const y=f;if(y.parent_source_group_id){const C=A.get(y.parent_source_group_id)||[];C.push(f.source_group_id),A.set(y.parent_source_group_id,C)}});const u=f=>{const y=[],C=A.get(f)||[];for(const I of C)y.push(I),y.push(...u(I));return y},d=f=>{const y=c.find(C=>C.source_group_id===f);return y?.parent_source_group_id?1+d(y.parent_source_group_id):0},_=c.length>0&&c.some(f=>f.name&&f.name.trim()!=="");let h=[];if(_){const f=new Map;for(const y of l){const C=lp(n).source_component.get(y.source_component_id);C?.source_group_id&&(f.has(C.source_group_id)||f.set(C.source_group_id,[]),f.get(C.source_group_id).push(y))}c.forEach((y,C)=>{let I=f.get(y.source_group_id)||[];const E=u(y.source_group_id);for(const b of E){const P=f.get(b)||[];I=[...I,...P]}if(I.length>0){const b=d(y.source_group_id),P=u(y.source_group_id).length>0;if(y.name?.startsWith("unnamed_board"))return;h.push({id:y.source_group_id,name:y.name||`Group ${C+1}`,components:I,color:sSt[C%sSt.length],depthLevel:b,hasChildren:P,sourceGroupId:y.source_group_id})}})}const m=s.viewBox.baseVal,p=s.getBoundingClientRect(),g=Math.min(p.width/m.width,p.height/m.height)||1;h.sort((f,y)=>f.depthLevel-y.depthLevel),h.forEach(f=>{if(f.components.length===0)return;const y=xxo(f.components,s);if(!y)return;const C=Math.max(8,Math.min(25,15/Math.max(g,.3))),I=f.hasChildren?C*.6:0,E=C+I,b=Math.max(1,2/Math.max(g,.5)),P=f.depthLevel===0?b:b*.7,B=Math.max(4,8/Math.max(g,.5)),M=f.hasChildren?1.3:1,R=B*M,k=R*.5,H=document.createElementNS("http://www.w3.org/2000/svg","rect");H.setAttribute("class","schematic-group-overlay"),H.setAttribute("x",(y.minX-E).toString()),H.setAttribute("y",(y.minY-E).toString()),H.setAttribute("width",(y.maxX-y.minX+E*2).toString()),H.setAttribute("height",(y.maxY-y.minY+E*2).toString()),H.setAttribute("fill","none"),H.setAttribute("stroke",f.color),H.setAttribute("stroke-width",P.toString()),H.setAttribute("stroke-dasharray",`${R},${k}`),H.setAttribute("opacity","0.8"),H.setAttribute("rx","0"),H.setAttribute("ry","0");const F=Math.max(6,Math.min(20,14/Math.max(g,.2))),G=f.depthLevel===0||f.depthLevel===1?0:f.depthLevel*.2,W=F*(1-G),J=Math.max(1,W*.2),q=f.name,oe=document.createElementNS("http://www.w3.org/2000/svg","text");oe.setAttribute("font-size",W.toString()),oe.setAttribute("font-family","Arial, sans-serif"),oe.textContent=q,s.appendChild(oe);const le=oe.getBBox();s.removeChild(oe);const ee=le.width+J*2,re=W+J*2,ae=y.minX-E,ie=y.minY-E-re,de=document.createElementNS("http://www.w3.org/2000/svg","rect");de.setAttribute("class","schematic-group-overlay"),de.setAttribute("x",ae.toString()),de.setAttribute("y",(ie-re).toString()),de.setAttribute("width",ee.toString()),de.setAttribute("height",re.toString()),de.setAttribute("fill","transparent"),de.setAttribute("rx","0"),de.setAttribute("ry","0");const ye=document.createElementNS("http://www.w3.org/2000/svg","text");ye.setAttribute("class","schematic-group-overlay"),ye.setAttribute("x",(ae+J).toString()),ye.setAttribute("y",(ie+re-J).toString()),ye.setAttribute("fill",f.color),ye.setAttribute("font-size",W.toString()),ye.setAttribute("font-family","Arial, sans-serif"),ye.setAttribute("font-weight",f.depthLevel===0?"600":"500"),ye.setAttribute("stroke",f.color),ye.setAttribute("stroke-width",Math.max(.2,W*.02).toString()),ye.textContent=q,s.appendChild(H),s.appendChild(de),s.appendChild(ye)})}catch(c){console.error("Error creating group overlays:",c)}},10);return()=>clearTimeout(r)},[e,o,i])};function xxo(t,e){let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const a of t){let c=e.querySelector(`g[data-schematic-component-id="${a.schematic_component_id}"]`);if(c||(c=e.querySelector(`[data-schematic-component-id="${a.schematic_component_id}"]`)),c){const l=c.getBBox();n=Math.min(n,l.x),o=Math.min(o,l.y),i=Math.max(i,l.x+l.width),r=Math.max(r,l.y+l.height)}}return n===1/0?null:{minX:n,minY:o,maxX:i,maxY:r}}var Ixo=bc("schematic-viewer"),Exo=()=>{bc.enable("schematic-viewer*")},bxo=Ixo,aSt=t=>{const[e,n]=X.useState(0),[o,i]=X.useState(0);return X.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}},Sxo=bxo.extend("useComponentDragging"),Pxo=({onEditEvent:t,editEvents:e=[],circuitJson:n,cancelDrag:o,svgToScreenProjection:i,realToSvgProjection:r,enabled:s=!1,snapToGrid:a=!1})=>{const[c,l]=X.useState(null),A=Ti(r,i),u=X.useRef(null),d=X.useRef(null),_=X.useRef(new Map);X.useEffect(()=>{e.forEach(b=>{"edit_event_type"in b&&b.edit_event_type==="edit_schematic_component_location"&&!b.in_progress&&_.current.set(b.schematic_component_id,{...b.new_center})})},[e]);const h=X.useCallback((b,P,B)=>{if(!s)return!1;const M=B.closest('[data-circuit-json-type="schematic_component"]');if(!M)return!1;const R=M.getAttribute("data-schematic-component-id");if(!R)return!1;o&&o();const k=lp(n).schematic_component.get(R);if(!k)return!1;u.current={x:b,y:P};let H;const F=_.current.get(R);if(F)H={...F};else{const W=rSt({editEvents:e,schematic_component_id:R});H={x:k.center.x+W.x,y:k.center.y+W.y},_.current.set(R,{...H})}const G={edit_event_id:Math.random().toString(36).substr(2,9),edit_event_type:"edit_schematic_component_location",schematic_component_id:R,original_center:H,new_center:{...H},in_progress:!0,created_at:Date.now(),_element:M};return d.current=G,l(G),!0},[o,s,n,e]),m=X.useCallback(b=>{h(b.clientX,b.clientY,b.target)},[h]),p=X.useCallback(b=>{if(b.touches.length!==1)return;const P=b.touches[0];h(P.clientX,P.clientY,b.target)&&b.preventDefault()},[h]),g=X.useCallback((b,P)=>{if(!d.current||!u.current)return;const B={x:b-u.current.x,y:P-u.current.y},M={x:B.x/A.a,y:B.y/A.d};let R={x:d.current.original_center.x+M.x,y:d.current.original_center.y+M.y};if(a){const H=F=>Math.round(F*10)/10;R={x:H(R.x),y:H(R.y)}}const k={...d.current,new_center:R};d.current=k,l(k)},[A,a]),f=X.useCallback(b=>g(b.clientX,b.clientY),[g]),y=X.useCallback(b=>{if(b.touches.length!==1||!d.current)return;b.preventDefault();const P=b.touches[0];g(P.clientX,P.clientY)},[g]),C=X.useCallback(()=>{if(!d.current)return;const b={...d.current,in_progress:!1};_.current.set(b.schematic_component_id,{...b.new_center}),Sxo("endDrag calling onEditEvent with new edit event",{newEditEvent:b}),t&&t(b),d.current=null,u.current=null,l(null)},[t]),I=X.useCallback(()=>C(),[C]),E=X.useCallback(()=>C(),[C]);return X.useEffect(()=>(window.addEventListener("mousemove",f),window.addEventListener("mouseup",I),window.addEventListener("touchmove",y,{passive:!1}),window.addEventListener("touchend",E),()=>{window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",I),window.removeEventListener("touchmove",y),window.removeEventListener("touchend",E)}),[f,I,y,E]),{handleMouseDown:m,handleTouchStart:p,isDragging:!!d.current,activeEditEvent:c}},oE={schematicEditIcon:50,schematicGridIcon:49,spiceSimulationIcon:50,viewMenuIcon:48,viewMenu:55,viewMenuBackdrop:54,clickToInteractOverlay:100,schematicComponentHoverOutline:47,schematicPortHoverOutline:48},vxo=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return K.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Disable edit mode":"Enable edit mode",style:{position:"absolute",top:"16px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.schematicEditIcon},children:K.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[K.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),K.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})},Bxo=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return K.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide grid":"Show grid",style:{position:"absolute",top:"56px",right:"64px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.schematicGridIcon},children:K.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:K.jsx("path",{d:"M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z"})})})},Mxo=({onClick:t,active:e})=>{const n=o=>{o.preventDefault(),t()};return K.jsx("div",{onClick:n,onTouchEnd:n,title:e?"Hide view menu":"Show view menu",style:{position:"absolute",top:"16px",right:"16px",backgroundColor:e?"#4CAF50":"#fff",color:e?"#fff":"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.viewMenuIcon},children:K.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[K.jsx("circle",{cx:"12",cy:"12",r:"1"}),K.jsx("circle",{cx:"12",cy:"5",r:"1"}),K.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})},wxo={version:"2.0.66"},Dxo=({circuitJson:t,circuitJsonKey:e,isVisible:n,onClose:o,showGroups:i,onToggleGroups:r,showGrid:s,onToggleGrid:a})=>{const c=X.useMemo(()=>{if(!t||t.length===0)return!1;try{if((lp(t).source_group?.list()||[]).length>0)return!0;const A=lp(t).schematic_component?.list()||[];if(A.length>1){const u=new Set;for(const d of A){const _=lp(t).source_component.get(d.source_component_id);_?.ftype&&u.add(_.ftype)}return u.size>1}return!1}catch(l){return console.error("Error checking for groups:",l),!1}},[e]);return n?K.jsxs(K.Fragment,{children:[K.jsx("div",{onClick:o,onTouchEnd:l=>{l.preventDefault(),o()},style:{position:"absolute",inset:0,backgroundColor:"transparent",zIndex:oE.viewMenuBackdrop}}),K.jsxs("div",{style:{position:"absolute",top:"56px",right:"16px",backgroundColor:"#ffffff",color:"#000000",border:"1px solid #ccc",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",minWidth:"200px",zIndex:oE.viewMenu},children:[K.jsxs("div",{onClick:()=>{c&&r(!i)},onTouchEnd:l=>{l.preventDefault(),c&&r(!i)},style:{padding:"8px 12px",cursor:c?"pointer":"not-allowed",opacity:c?1:.5,fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{c&&(l.currentTarget.style.backgroundColor="#f0f0f0")},onMouseLeave:l=>{c&&(l.currentTarget.style.backgroundColor="transparent")},children:[K.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:i&&"✓"}),"View Schematic Groups"]}),!c&&K.jsx("div",{style:{padding:"8px 12px",fontSize:"11px",color:"#666",fontStyle:"italic"},children:"No groups found in this schematic"}),K.jsxs("div",{onClick:()=>a(!s),onTouchEnd:l=>{l.preventDefault(),a(!s)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"#000000",fontFamily:"sans-serif",display:"flex",alignItems:"center",gap:"8px"},onMouseEnter:l=>{l.currentTarget.style.backgroundColor="#f0f0f0"},onMouseLeave:l=>{l.currentTarget.style.backgroundColor="transparent"},children:[K.jsx("div",{style:{width:"16px",height:"16px",border:"2px solid #000",borderRadius:"2px",backgroundColor:"transparent",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:"bold"},children:s&&"✓"}),"Show Grid"]}),K.jsxs("div",{style:{padding:"4px 8px",fontSize:"12px",color:"#999",borderTop:"1px solid #eee",textAlign:"center"},children:["v",String(wxo?.version)]})]})]}):null},Qxo=()=>K.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:K.jsx("path",{d:"M3 12h2.5l2.5-9 4 18 4-9h5.5"})}),Txo=({onClick:t})=>K.jsx("div",{onClick:t,title:"Run SPICE simulation",style:{position:"absolute",top:"16px",right:"112px",backgroundColor:"#fff",color:"#000",padding:"8px",borderRadius:"4px",cursor:"pointer",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",display:"flex",alignItems:"center",gap:"4px",zIndex:oE.spiceSimulationIcon},children:K.jsx(Qxo,{})});Yee.register(rxo,cxo,FCo,HCo,WCo,txo,YCo);var Xee=["#8884d8","#82ca9d","#ffc658","#ff7300","#387908"],cSt=t=>{if(t===0)return"0s";const e=Math.abs(t);let n="s",o=1;return e<1e-12?(n="fs",o=1e15):e<1e-9?(n="ps",o=1e12):e<1e-6?(n="ns",o=1e9):e<.001?(n="us",o=1e6):e<1&&(n="ms",o=1e3),`${parseFloat((t*o).toPrecision(3))}${n}`},Rxo=({plotData:t,nodes:e,isLoading:n,error:o,hasRun:i})=>{const r=X.useMemo(()=>{const c=e.some(A=>A.toLowerCase().startsWith("v(")),l=e.some(A=>A.toLowerCase().startsWith("i("));return c&&l?"Value":c?"Voltage (V)":l?"Current (A)":"Value"},[e]);if(n)return K.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"Running simulation..."});if(!i)return K.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:'Click "Run" to start the simulation.'});if(o)return K.jsxs("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"red"},children:["Error: ",o]});if(t.length===0)return K.jsx("div",{style:{height:"300px",width:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:"No data to plot. Check simulation output or SPICE netlist."});const s={datasets:e.map((c,l)=>({label:c,data:t.map(A=>({x:Number(A.name),y:A[c]})),borderColor:Xee[l%Xee.length],backgroundColor:Xee[l%Xee.length],fill:!1,tension:.1}))},a={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{font:{family:"sans-serif"}}},title:{display:!1},tooltip:{callbacks:{title:c=>{if(c.length>0){const l=c[0];return cSt(l.parsed.x)}return""}}}},scales:{x:{type:"linear",title:{display:!0,text:"Time",font:{family:"sans-serif"}},ticks:{callback:c=>cSt(c),font:{family:"sans-serif"}}},y:{title:{display:!0,text:r,font:{family:"sans-serif"}},ticks:{font:{family:"sans-serif"}}}}};return K.jsx("div",{style:{position:"relative",height:"300px",width:"100%"},children:K.jsx(pxo,{options:a,data:s})})},Nxo=({spiceString:t,onClose:e,plotData:n,nodes:o,isLoading:i,error:r,simOptions:s,onSimOptionsChange:a,hasRun:c})=>{const[l,A]=X.useState(String(s.startTime)),[u,d]=X.useState(String(s.duration));X.useEffect(()=>{A(String(s.startTime)),d(String(s.duration))},[s.startTime,s.duration]);const _=()=>{a({...s,startTime:Number(l),duration:Number(u)})},h=o.filter(m=>{const p=m.toLowerCase().startsWith("v("),g=m.toLowerCase().startsWith("i(");return!!(s.showVoltage&&p||s.showCurrent&&g)});return K.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1002,fontFamily:"sans-serif"},children:K.jsxs("div",{style:{backgroundColor:"white",padding:"24px",borderRadius:"12px",width:"90%",maxWidth:"900px",boxShadow:"0 4px 20px rgba(0, 0, 0, 0.15)"},children:[K.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid #eee",paddingBottom:"16px"},children:[K.jsx("h2",{style:{margin:0,fontSize:"22px",fontWeight:600,color:"#333"},children:"SPICE Simulation"}),K.jsx("button",{onClick:e,style:{background:"none",border:"none",fontSize:"28px",cursor:"pointer",color:"#888",padding:0,lineHeight:1},children:"×"})]}),K.jsx("div",{children:K.jsx(Rxo,{plotData:n,nodes:h,isLoading:i,error:r,hasRun:c})}),K.jsxs("div",{style:{marginTop:"16px",padding:"12px",backgroundColor:"#f7f7f7",borderRadius:"6px",display:"flex",flexWrap:"wrap",gap:"24px",alignItems:"center",fontSize:"14px"},children:[K.jsxs("div",{style:{display:"flex",gap:"16px"},children:[K.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[K.jsx("input",{type:"checkbox",checked:s.showVoltage,onChange:m=>a({...s,showVoltage:m.target.checked})}),"Voltage"]}),K.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[K.jsx("input",{type:"checkbox",checked:s.showCurrent,onChange:m=>a({...s,showCurrent:m.target.checked})}),"Current"]})]}),K.jsxs("div",{style:{display:"flex",gap:"16px",alignItems:"center"},children:[K.jsx("label",{htmlFor:"startTime",children:"Start Time (ms):"}),K.jsx("input",{id:"startTime",type:"number",value:l,onChange:m=>A(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),K.jsx("label",{htmlFor:"duration",children:"Duration (ms):"}),K.jsx("input",{id:"duration",type:"number",value:u,onChange:m=>d(m.target.value),style:{width:"80px",padding:"4px 8px",borderRadius:"4px",border:"1px solid #ccc"}}),K.jsx("button",{onClick:_,style:{padding:"4px 12px",borderRadius:"4px",border:"1px solid #ccc",backgroundColor:"#f0f0f0",cursor:"pointer"},children:c?"Rerun":"Run"})]})]}),K.jsxs("div",{style:{marginTop:"24px"},children:[K.jsx("h3",{style:{marginTop:0,marginBottom:"12px",fontSize:"18px",fontWeight:600,color:"#333"},children:"SPICE Netlist"}),K.jsx("pre",{style:{backgroundColor:"#fafafa",padding:"16px",borderRadius:"6px",maxHeight:"150px",overflowY:"auto",border:"1px solid #eee",color:"#333",fontSize:"13px",fontFamily:"monospace"},children:t})]})]})})},kxo="dmFyIGU9bnVsbCxzPWFzeW5jKCk9Pihhd2FpdCBpbXBvcnQoImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vZWVjaXJjdWl0LWVuZ2luZUAxLjUuMi8rZXNtIikpLlNpbXVsYXRpb24sYz1hc3luYygpPT57aWYoZSYmZS5pc0luaXRpYWxpemVkKCkpcmV0dXJuO2xldCBpPWF3YWl0IHMoKTtlPW5ldyBpLGF3YWl0IGUuc3RhcnQoKX07c2VsZi5vbm1lc3NhZ2U9YXN5bmMgaT0+e3RyeXtpZihhd2FpdCBjKCksIWUpdGhyb3cgbmV3IEVycm9yKCJTaW11bGF0aW9uIG5vdCBpbml0aWFsaXplZCIpO2xldCB0PWkuZGF0YS5zcGljZVN0cmluZyxhPXQubWF0Y2goL3dyZGF0YVxzKyhcUyspXHMrKC4qKS9pKTtpZihhKXtsZXQgbz1gLnByb2JlICR7YVsyXS50cmltKCkuc3BsaXQoL1xzKy8pLmpvaW4oIiAiKX1gO3Q9dC5yZXBsYWNlKC93cmRhdGEuKi9pLG8pfWVsc2UgaWYoIXQubWF0Y2goL1wucHJvYmUvaSkpdGhyb3cgdC5tYXRjaCgvcGxvdFxzKyguKikvaSk/bmV3IEVycm9yKCJUaGUgJ3Bsb3QnIGNvbW1hbmQgaXMgbm90IHN1cHBvcnRlZCBmb3IgZGF0YSBleHRyYWN0aW9uLiBQbGVhc2UgdXNlICd3cmRhdGEgPGZpbGVuYW1lPiA8dmFyMT4gLi4uJyBvciAnLnByb2JlIDx2YXIxPiAuLi4nIGluc3RlYWQuIik6bmV3IEVycm9yKCJObyAnLnByb2JlJyBvciAnd3JkYXRhJyBjb21tYW5kIGZvdW5kIGluIFNQSUNFIGZpbGUuIFVzZSAnd3JkYXRhIDxmaWxlbmFtZT4gPHZhcjE+IC4uLicgdG8gc3BlY2lmeSBvdXRwdXQuIik7ZS5zZXROZXRMaXN0KHQpO2xldCBuPWF3YWl0IGUucnVuU2ltKCk7c2VsZi5wb3N0TWVzc2FnZSh7dHlwZToicmVzdWx0IixyZXN1bHQ6bn0pfWNhdGNoKHQpe3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6ImVycm9yIixlcnJvcjp0Lm1lc3NhZ2V9KX19Owo=",Jee=null,Lxo=()=>{if(typeof window>"u")return null;if(Jee)return Jee;try{const t=new Blob([atob(kxo)],{type:"application/javascript"});return Jee=URL.createObjectURL(t),Jee}catch(t){return console.error("Failed to create blob URL for worker",t),null}},Hxo=t=>{const e={};if(t.dataType==="real")t.data.forEach(a=>{e[a.name]=a.values});else if(t.dataType==="complex")t.data.forEach(a=>{e[a.name]=a.values.map(c=>c.real)});else throw new Error("Unsupported data type in simulation result");const n=Object.keys(e).find(a=>a.toLowerCase()==="time"||a.toLowerCase()==="frequency");if(!n)throw new Error("No time or frequency data in simulation result");const o=e[n],i=Object.keys(e).filter(a=>a!==n),r=i;return{plotData:o.map((a,c)=>{const l={name:a.toExponential(2)};return i.forEach(A=>{l[A]=e[A][c]}),l}),nodes:r}},Fxo=t=>{const[e,n]=X.useState([]),[o,i]=X.useState([]),[r,s]=X.useState(!0),[a,c]=X.useState(null);return X.useEffect(()=>{if(!t){s(!1),n([]),i([]),c(null);return}s(!0),c(null),n([]),i([]);const l=Lxo();if(!l){c("Could not create SPICE simulation worker."),s(!1);return}const A=new Worker(l,{type:"module"});return A.onmessage=u=>{if(u.data.type==="result")try{const{plotData:d,nodes:_}=Hxo(u.data.result);n(d),i(_)}catch(d){c(d.message||"Failed to parse simulation result"),console.error(d)}else u.data.type==="error"&&c(u.data.error);s(!1)},A.onerror=u=>{c(u.message),s(!1)},A.postMessage({spiceString:t}),()=>{A.terminate()}},[t]),{plotData:e,nodes:o,isLoading:r,error:a}},GPe=t=>{if(t===0)return"0";const e=Math.abs(t),n=o=>o.toPrecision(4);return e>=1?n(t):e>=.001?`${n(t*1e3)}m`:e>=1e-6?`${n(t*1e6)}u`:e>=1e-9?`${n(t*1e9)}n`:e>=1e-12?`${n(t*1e12)}p`:e>=1e-15?`${n(t*1e15)}f`:t.toExponential(3)},Oxo=(t,e)=>{const o=rZe(t).toSpiceString(),r=o.split(`
5626
5626
  `).filter(M=>M.trim()!=="").filter(M=>!M.startsWith("*")&&!M.startsWith(".")&&M.trim()!==""),s=new Set,a=new Set,c=new Set;for(const M of r){const R=M.trim().split(/\s+/);if(R.length<3)continue;const k=R[0],H=k[0].toUpperCase();let F=[];if(["R","C","L","V","I","D"].includes(H))F=R.slice(1,3),H==="V"&&c.add(k);else if(H==="Q"&&R.length>=4)F=R.slice(1,4);else if(H==="M"&&R.length>=5)F=R.slice(1,5);else if(H==="X")F=R.slice(1,-1);else continue;F.forEach(G=>s.add(G)),H==="C"&&F.forEach(G=>a.add(G))}s.delete("0"),a.delete("0");const l=Array.from(a).map(M=>`.ic V(${M})=0`),A=[],u=Array.from(s).map(M=>`V(${M})`);A.push(...u);const d=Array.from(c).map(M=>`I(${M})`);A.push(...d);const _=A.length>0?`.probe ${A.join(" ")}`:"",h=e?.startTime??0,m=e?.duration??20,p=h*.001,g=m*.001,f=p+g,y=g/50,C=`.tran ${GPe(y)} ${GPe(f)} ${GPe(p)} UIC`,I=".end",E=o.split(`
5627
5627
  `);let b=-1;for(let M=E.length-1;M>=0;M--)if(E[M].trim().toLowerCase().startsWith(I)){b=M;break}const P=[...l,_,C].filter(Boolean);let B;if(b!==-1){const M=E.slice(0,b),R=E.slice(b);B=[...M,...P,...R]}else B=[...E,...P,I];return B.join(`
5628
5628
  `)},Gxo=(t,e)=>{if(typeof window>"u")return e;try{const n=localStorage.getItem(t);return n!==null?JSON.parse(n):e}catch{return e}},Uxo=(t,e)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(e))}catch{}},UPe=X.createContext(null),zxo=5,Vxo=(t,e)=>!t&&!e?!0:!t||!e?!1:t.minX===e.minX&&t.maxX===e.maxX&&t.minY===e.minY&&t.maxY===e.maxY,Yxo=({children:t})=>{if(X.useContext(UPe))return K.jsx(K.Fragment,{children:t});const n=X.useRef({pointer:null,boundingBoxes:new Map,hoveringIds:new Set,subscribers:new Set,mouseDownPosition:null}),o=X.useCallback(()=>{for(const u of n.current.subscribers)u()},[]),i=X.useCallback(()=>{const u=n.current.pointer,d=new Set;if(u)for(const[h,m]of n.current.boundingBoxes){const p=m.bounds;p&&u.x>=p.minX&&u.x<=p.maxX&&u.y>=p.minY&&u.y<=p.maxY&&d.add(h)}const _=n.current.hoveringIds;d.size===_.size&&[...d].every(h=>_.has(h))||(n.current.hoveringIds=d,o())},[o]),r=X.useCallback((u,d)=>{n.current.boundingBoxes.set(u,d),i()},[i]),s=X.useCallback((u,d)=>{const _=n.current.boundingBoxes.get(u);_&&Vxo(_.bounds,d.bounds)&&_.onClick===d.onClick||(n.current.boundingBoxes.set(u,d),i())},[i]),a=X.useCallback(u=>{n.current.boundingBoxes.delete(u)&&i()},[i]),c=X.useCallback(u=>(n.current.subscribers.add(u),()=>{n.current.subscribers.delete(u)}),[]),l=X.useCallback(u=>n.current.hoveringIds.has(u),[]);X.useEffect(()=>{const u=m=>{const{clientX:p,clientY:g}=m,f=n.current.pointer;f&&f.x===p&&f.y===g||(n.current.pointer={x:p,y:g},i())},d=()=>{n.current.pointer!==null&&(n.current.pointer=null,n.current.mouseDownPosition=null,i())},_=m=>{n.current.mouseDownPosition={x:m.clientX,y:m.clientY}},h=m=>{const{clientX:p,clientY:g}=m,f=n.current.mouseDownPosition;if(f&&Math.sqrt(Math.pow(p-f.x,2)+Math.pow(g-f.y,2))>zxo){n.current.mouseDownPosition=null;return}n.current.mouseDownPosition=null;for(const y of n.current.boundingBoxes.values()){const C=y.bounds;C&&p>=C.minX&&p<=C.maxX&&g>=C.minY&&g<=C.maxY&&y.onClick?.(m)}};return window.addEventListener("pointermove",u,{passive:!0}),window.addEventListener("pointerdown",u,{passive:!0}),window.addEventListener("pointerup",u,{passive:!0}),window.addEventListener("pointerleave",d),window.addEventListener("pointercancel",d),window.addEventListener("blur",d),window.addEventListener("mousedown",_,{passive:!0}),window.addEventListener("click",h,{passive:!0}),()=>{window.removeEventListener("pointermove",u),window.removeEventListener("pointerdown",u),window.removeEventListener("pointerup",u),window.removeEventListener("pointerleave",d),window.removeEventListener("pointercancel",d),window.removeEventListener("blur",d),window.removeEventListener("mousedown",_),window.removeEventListener("click",h)}},[i]);const A=X.useMemo(()=>({registerBoundingBox:r,updateBoundingBox:s,unregisterBoundingBox:a,subscribe:c,isHovering:l}),[r,s,a,c,l]);return K.jsx(UPe.Provider,{value:A,children:t})},lSt=t=>{const e=X.useContext(UPe);if(!e)throw new Error("useMouseEventsOverBoundingBox must be used within a MouseTracker");const n=X.useId(),o=X.useRef(t);o.current=t;const i=X.useMemo(()=>s=>{o.current.onClick?.(s)},[]);return X.useEffect(()=>(e.registerBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0}),()=>{e.unregisterBoundingBox(n)}),[e,i,n]),X.useEffect(()=>{e.updateBoundingBox(n,{bounds:o.current.bounds,onClick:o.current.onClick?i:void 0})},[e,i,n,t.bounds?.minX,t.bounds?.maxX,t.bounds?.minY,t.bounds?.maxY,t.onClick]),{hovering:X.useSyncExternalStore(e.subscribe,()=>e.isHovering(n),()=>!1)}},Kxo=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,Wxo=({componentId:t,svgDivRef:e,containerRef:n,onComponentClick:o,onHoverChange:i,showOutline:r,circuitJsonKey:s})=>{const[a,c]=X.useState(null),l=X.useRef(null),A=X.useCallback(()=>{l.current=null;const p=e.current,g=n.current;if(!p||!g){c(E=>E&&null);return}const f=p.querySelector(`[data-schematic-component-id="${t}"]`);if(!f){c(E=>E&&null);return}const y=f.getBoundingClientRect(),C=g.getBoundingClientRect(),I={bounds:{minX:y.left,maxX:y.right,minY:y.top,maxY:y.bottom},rect:{left:y.left-C.left,top:y.top-C.top,width:y.width,height:y.height}};c(E=>Kxo(E,I)?E:I)},[t,n,e]),u=X.useCallback(()=>{l.current===null&&(l.current=window.requestAnimationFrame(A))},[A]);X.useEffect(()=>{u()},[u,s]),X.useEffect(()=>{u();const p=e.current,g=n.current;if(!p||!g)return;const f=typeof ResizeObserver<"u"?new ResizeObserver(()=>{u()}):null;f?.observe(g),f?.observe(p);const y=typeof MutationObserver<"u"?new MutationObserver(()=>{u()}):null;return y?.observe(p,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{f?.disconnect(),y?.disconnect(),window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)}},[u,e,n]);const d=X.useCallback(p=>{o&&o(t,p)},[t,o]),_=a?.bounds??null,{hovering:h}=lSt({bounds:_,onClick:o?d:void 0});if(X.useEffect(()=>{i&&i(t,h)},[h,t,i]),!a||!h||!r)return null;const m=a.rect;return K.jsx("div",{style:{position:"absolute",left:m.left,top:m.top,width:m.width,height:m.height,border:"1.5px solid rgba(51, 153, 255, 0.9)",pointerEvents:"none",zIndex:oE.schematicComponentHoverOutline}})},jxo=(t,e)=>!t&&!e?!0:!t||!e?!1:Math.abs(t.bounds.minX-e.bounds.minX)<.5&&Math.abs(t.bounds.maxX-e.bounds.maxX)<.5&&Math.abs(t.bounds.minY-e.bounds.minY)<.5&&Math.abs(t.bounds.maxY-e.bounds.maxY)<.5&&Math.abs(t.rect.left-e.rect.left)<.5&&Math.abs(t.rect.top-e.rect.top)<.5&&Math.abs(t.rect.width-e.rect.width)<.5&&Math.abs(t.rect.height-e.rect.height)<.5,Xxo=({portId:t,portLabel:e,svgDivRef:n,containerRef:o,onPortClick:i,onHoverChange:r,showOutline:s,circuitJsonKey:a})=>{const[c,l]=X.useState(null),A=X.useRef(null),u=X.useCallback(()=>{A.current=null;const g=n.current,f=o.current;if(!g||!f){l(P=>P&&null);return}const y=g.querySelector(`[data-schematic-port-id="${t}"]`);if(!y){l(P=>P&&null);return}const C=y.getBoundingClientRect(),I=f.getBoundingClientRect(),E=4,b={bounds:{minX:C.left-E,maxX:C.right+E,minY:C.top-E,maxY:C.bottom+E},rect:{left:C.left-I.left-E,top:C.top-I.top-E,width:C.width+E*2,height:C.height+E*2}};l(P=>jxo(P,b)?P:b)},[t,o,n]),d=X.useCallback(()=>{A.current===null&&(A.current=window.requestAnimationFrame(u))},[u]);X.useEffect(()=>{d()},[d,a]),X.useEffect(()=>{d();const g=n.current,f=o.current;if(!g||!f)return;const y=typeof ResizeObserver<"u"?new ResizeObserver(()=>{d()}):null;y?.observe(f),y?.observe(g);const C=typeof MutationObserver<"u"?new MutationObserver(()=>{d()}):null;return C?.observe(g,{attributes:!0,attributeFilter:["style","transform"],subtree:!0,childList:!0}),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{y?.disconnect(),C?.disconnect(),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d),A.current!==null&&(cancelAnimationFrame(A.current),A.current=null)}},[d,n,o]);const _=X.useCallback(g=>{i&&i(t,g)},[t,i]),h=c?.bounds??null,{hovering:m}=lSt({bounds:h,onClick:i?_:void 0});if(X.useEffect(()=>{r&&r(t,m)},[m,t,r]),!c||!s)return null;const p=c.rect;return K.jsxs(K.Fragment,{children:[K.jsx("div",{style:{position:"absolute",left:p.left,top:p.top,width:p.width,height:p.height,border:m?"1.5px solid rgba(255, 153, 51, 0.9)":"1.5px solid rgba(255, 153, 51, 0.3)",backgroundColor:m?"rgba(255, 153, 51, 0.15)":"rgba(255, 153, 51, 0.05)",borderRadius:"50%",pointerEvents:"none",zIndex:oE.schematicPortHoverOutline,transition:"border-color 0.15s, background-color 0.15s"}}),m&&e&&K.jsx("div",{style:{position:"absolute",left:p.left+p.width/2,top:p.top-24,transform:"translateX(-50%)",backgroundColor:"rgba(0, 0, 0, 0.85)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",whiteSpace:"nowrap",pointerEvents:"none",zIndex:oE.schematicPortHoverOutline+1},children:e})]})},Jxo=({circuitJson:t,containerStyle:e,editEvents:n=[],onEditEvent:o,defaultEditMode:i=!1,debugGrid:r=!1,editingEnabled:s=!1,debug:a=!1,clickToInteractEnabled:c=!1,colorOverrides:l,spiceSimulationEnabled:A=!1,disableGroups:u=!1,onSchematicComponentClicked:d,showSchematicPorts:_=!1,onSchematicPortClicked:h,css:m,className:p})=>{a&&Exo();const[g,f]=X.useState(!1),[y,C]=X.useState({showVoltage:!0,showCurrent:!1,startTime:0,duration:20}),I=rt=>`${rt?.length||0}_${rt?.editCount||0}`,E=X.useMemo(()=>I(t),[t]),b=X.useMemo(()=>{if(!A)return null;try{return Oxo(t,y)}catch(rt){return console.error("Failed to generate SPICE string",rt),null}},[E,A,y.startTime,y.duration]),[P,B]=X.useState(!1);X.useEffect(()=>{B(!1)},[E]);const{plotData:M,nodes:R,isLoading:k,error:H}=Fxo(P?b:null),[F,G]=X.useState(i),[W,J]=X.useState(!0),[q,oe]=X.useState(!1),le=r||q,[ee,re]=X.useState(!c),[ae,ie]=X.useState(!1),[de,ye]=X.useState(()=>u?!1:Gxo("schematic_viewer_show_groups",!1)),[Ie,ve]=X.useState(!1),ue=X.useRef(new Set),Se=X.useCallback((rt,ft)=>{ft?ue.current.add(rt):ue.current.delete(rt),ve(ue.current.size>0)},[]),[he,De]=X.useState(!1),Ge=X.useRef(new Set),Ye=X.useCallback((rt,ft)=>{ft?Ge.current.add(rt):Ge.current.delete(rt),De(Ge.current.size>0)},[]),fe=X.useRef(null),qe=X.useRef(null),Le=X.useMemo(()=>{try{return lp(t).schematic_component?.list()?.map(rt=>rt.schematic_component_id)??[]}catch(rt){return console.error("Failed to derive schematic component ids",rt),[]}},[E,t]),Qe=X.useMemo(()=>{if(!_)return[];try{return(lp(t).schematic_port?.list()??[]).map(ft=>{const kt=lp(t).source_port.get(ft.source_port_id),sn=(kt?.source_component_id?lp(t).source_component.get(kt.source_component_id):null)?.name??"?",qn=ft.display_pin_label??kt?.pin_number??kt?.name??"?";return{portId:ft.source_port_id,label:`${sn}.${qn}`}})}catch(rt){return console.error("Failed to derive schematic port info",rt),[]}},[E,t,_]),Ue=rt=>{const ft=rt.touches[0];qe.current={x:ft.clientX,y:ft.clientY}},we=rt=>{const ft=rt.changedTouches[0],kt=qe.current;if(!kt)return;const Ot=Math.abs(ft.clientX-kt.x),sn=Math.abs(ft.clientY-kt.y);Ot<10&&sn<10&&(rt.preventDefault(),re(!0)),qe.current=null},[Ee,Fe]=X.useState([]),Me=X.useRef(t);X.useEffect(()=>{const rt=I(t),ft=I(Me.current);rt!==ft&&(Fe([]),Me.current=t)},[t]);const{ref:ze,cancelDrag:je,transform:it}=qF({onSetTransform(rt){fe.current&&(fe.current.style.transform=p1(rt))},enabled:ee&&!g}),{containerWidth:at,containerHeight:At}=aSt(ze),lt=X.useMemo(()=>!at||!At?"":gee(t,{width:at,height:At||720,drawPorts:_,grid:le?{cellSize:1,labelCells:!0}:void 0,colorOverrides:l,css:m,className:p}),[E,at,At,le,_]),xt=X.useMemo(()=>lt.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent",[lt]),Bt=X.useMemo(()=>{if(!lt)return hA();const rt=lt.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return EU(rt)}catch(ft){return console.error(ft),hA()}},[lt]),pt=rt=>{Fe(ft=>[...ft,rt]),o&&o(rt)},Mt=X.useMemo(()=>[...n,...Ee],[n,Ee]),{handleMouseDown:Lt,handleTouchStart:an,isDragging:cn,activeEditEvent:wn}=Pxo({onEditEvent:pt,cancelDrag:je,realToSvgProjection:Bt,svgToScreenProjection:it,circuitJson:t,editEvents:Mt,enabled:F&&ee&&!g,snapToGrid:W});fxo({svgDivRef:fe,editEvents:Mt,realToSvgProjection:Bt,svgToScreenProjection:it,activeEditEvent:wn}),yxo({svgDivRef:fe,circuitJson:t,activeEditEvent:wn,editEvents:Mt}),Cxo({svgDivRef:fe,circuitJson:t,circuitJsonKey:E,showGroups:de&&!u});const xe=X.useRef(an);X.useEffect(()=>{xe.current=an},[an]);const et=X.useMemo(()=>K.jsx("div",{ref:fe,style:{pointerEvents:c?ee?"auto":"none":"auto",transformOrigin:"0 0"},className:d?"schematic-component-clickable":void 0,onTouchStart:rt=>{F&&ee&&!g&&xe.current(rt)},dangerouslySetInnerHTML:{__html:lt}}),[lt,ee,c,F,g]);return K.jsxs(Yxo,{children:[d&&K.jsx("style",{children:".schematic-component-clickable [data-schematic-component-id]:hover { cursor: pointer !important; }"}),h&&K.jsx("style",{children:"[data-schematic-port-id]:hover { cursor: pointer !important; }"}),K.jsxs("div",{ref:ze,style:{position:"relative",backgroundColor:xt,overflow:"hidden",cursor:g?"auto":cn?"grabbing":c&&!ee||Ie&&d||he&&h?"pointer":"grab",minHeight:"300px",...e},onWheelCapture:rt=>{g&&rt.stopPropagation()},onMouseDown:rt=>{if(c&&!ee){rt.preventDefault(),rt.stopPropagation();return}Lt(rt)},onMouseDownCapture:rt=>{if(c&&!ee){rt.preventDefault(),rt.stopPropagation();return}},onTouchStart:rt=>{g||Ue(rt)},onTouchEnd:rt=>{g||we(rt)},children:[!ee&&c&&K.jsx("div",{onClick:rt=>{rt.preventDefault(),rt.stopPropagation(),re(!0)},style:{position:"absolute",inset:0,cursor:"pointer",zIndex:oE.clickToInteractOverlay,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"all",touchAction:"pan-x pan-y pinch-zoom"},children:K.jsx("div",{style:{backgroundColor:"rgba(0, 0, 0, 0.8)",color:"white",padding:"12px 24px",borderRadius:"8px",fontSize:"16px",fontFamily:"sans-serif",pointerEvents:"none"},children:typeof window<"u"&&("ontouchstart"in window||navigator.maxTouchPoints>0)?"Touch to Interact":"Click to Interact"})}),K.jsx(Mxo,{active:ae,onClick:()=>ie(!ae)}),s&&K.jsx(vxo,{active:F,onClick:()=>G(!F)}),s&&F&&K.jsx(Bxo,{active:W,onClick:()=>J(!W)}),K.jsx(Dxo,{circuitJson:t,circuitJsonKey:E,isVisible:ae,onClose:()=>ie(!1),showGroups:de,onToggleGroups:rt=>{u||(ye(rt),Uxo("schematic_viewer_show_groups",rt))},showGrid:le,onToggleGrid:oe}),A&&K.jsx(Txo,{onClick:()=>f(!0)}),g&&K.jsx(Nxo,{spiceString:b,onClose:()=>f(!1),plotData:M,nodes:R,isLoading:k,error:H,simOptions:y,onSimOptionsChange:rt=>{B(!0),C(rt)},hasRun:P}),d&&Le.map(rt=>K.jsx(Wxo,{componentId:rt,svgDivRef:fe,containerRef:ze,showOutline:!0,circuitJsonKey:E,onHoverChange:Se,onComponentClick:(ft,kt)=>{d?.({schematicComponentId:ft,event:kt})}},rt)),et,_&&Qe.map(({portId:rt,label:ft})=>K.jsx(Xxo,{portId:rt,portLabel:ft,svgDivRef:fe,containerRef:ze,showOutline:!0,circuitJsonKey:E,onHoverChange:Ye,onPortClick:h?(kt,Ot)=>{h?.({schematicPortId:kt,event:Ot})}:void 0},rt))]})]})},qxo=1200,$xo=1,Zxo=({circuitJson:t,containerStyle:e,colorOverrides:n,width:o,height:i,className:r})=>{const[s,a]=X.useState(null),[c,l]=X.useState(!0),[A,u]=X.useState(null),[d,_]=X.useState(null),h=X.useRef(null),m=X.useRef(null),{containerWidth:p}=aSt(h),[g,f]=X.useState(!1),{ref:y}=qF({onSetTransform(F){m.current&&(m.current.style.transform=p1(F))}}),C=o&&i?o/i:$xo,I=o||(i?i*C:p)||qxo,E=i||I/C;X.useEffect(()=>{l(!0),u(null),a(t),l(!1)},[t]);const b=X.useMemo(()=>s&&s.find(G=>G.type==="simulation_experiment")?.simulation_experiment_id||null,[s]),P=X.useMemo(()=>s?s.filter(F=>F.type==="simulation_transient_voltage_graph").map(F=>F.simulation_transient_voltage_graph_id):[],[s]),B=X.useMemo(()=>s?s.filter(F=>F.type==="simulation_transient_current_graph").map(F=>F.simulation_transient_current_graph_id):[],[s]),M=X.useMemo(()=>{if(!s||!I||!E||!b)return"";try{return eEt({circuitJson:s,simulation_experiment_id:b,simulation_transient_current_graph_ids:B,simulation_transient_voltage_graph_ids:P,width:I,height:E,schematicOptions:{colorOverrides:n}})}catch(F){return console.error("Failed to generate fallback schematic SVG:",F),""}},[s,I,E,n,b,B,P]);X.useEffect(()=>{if(!M){_(null);return}try{const F=new Blob([M],{type:"image/svg+xml"}),G=URL.createObjectURL(F);return _(G),()=>{URL.revokeObjectURL(G)}}catch(F){console.error("Failed to create SVG object URL:",F),_(null)}},[M]);const R=X.useMemo(()=>M?M.match(/<svg[^>]*style="[^"]*background-color:\s*([^;\"]+)/i)?.[1]??"transparent":"transparent",[M]),k=F=>{f(!0)},H=F=>{f(!0)};return X.useEffect(()=>{const F=()=>{f(!1)},G=()=>{f(!1)};return window.addEventListener("mouseup",F),window.addEventListener("touchend",G),()=>{window.removeEventListener("mouseup",F),window.removeEventListener("touchend",G)}},[]),c?K.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f5f5f5",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#666",...e},className:r,children:"Loading circuit..."}):A?K.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#fef2f2",minHeight:"300px",fontFamily:"sans-serif",fontSize:"16px",color:"#dc2626",...e},className:r,children:K.jsxs("div",{style:{textAlign:"center",padding:"20px"},children:[K.jsx("div",{style:{fontWeight:"bold",marginBottom:"8px"},children:"Circuit Conversion Error"}),K.jsx("div",{style:{fontSize:"14px"},children:A})]})}):M?K.jsx("div",{ref:F=>{h.current=F,y.current=F},style:{position:"relative",backgroundColor:R,overflow:"hidden",minHeight:"300px",cursor:g?"grabbing":"grab",...e},className:r,onMouseDown:k,onTouchStart:H,children:d?K.jsx("img",{ref:m,src:d,alt:"Circuit Simulation",style:{transformOrigin:"0 0",width:"100%",height:"100%",display:"block",objectFit:"contain"}}):K.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",minHeight:"300px",color:"#666",fontFamily:"sans-serif"},children:"Failed to render SVG"})}):K.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"#f8fafc",minHeight:"300px",fontFamily:"sans-serif",gap:"12px",...e},className:r,children:[K.jsx("div",{style:{fontSize:"16px",color:"#475569",fontWeight:500},children:"No Simulation Found"}),K.jsxs("div",{style:{fontSize:"14px",color:"#64748b"},children:["Use"," ",K.jsx("code",{style:{backgroundColor:"#e2e8f0",padding:"2px 6px",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px"},children:"<analogsimulation />"})," ","to create simulations"]})]})},ASt=t=>{const[e,n]=X.useState(0),[o,i]=X.useState(0);return X.useEffect(()=>{if(!t.current)return;const r=()=>{const a=t.current?.getBoundingClientRect();n(a?.width||0),i(a?.height||0)};r();const s=new ResizeObserver(r);return s.observe(t.current),window.addEventListener("resize",r),()=>{s.disconnect(),window.removeEventListener("resize",r)}},[]),{containerWidth:e,containerHeight:o}};bc("assembly-viewer");var uSt=()=>{bc.enable("assembly-viewer*")},e2o=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&uSt();const i=X.useRef(null),{ref:r}=qF({onSetTransform(A){i.current&&(i.current.style.transform=p1(A))}}),{containerWidth:s,containerHeight:a}=ASt(r),c=X.useMemo(()=>!s||!a?"":h4t(t,{width:s,height:a||720}),[t,s,a]);X.useMemo(()=>{if(!c)return hA();const A=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return EU(A)}catch(u){return console.error(u),hA()}},[c]);const l=X.useMemo(()=>K.jsx("div",{ref:i,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return K.jsx("div",{ref:r,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})},t2o=({circuitJson:t,containerStyle:e,debugGrid:n=!1,debug:o=!1})=>{o&&uSt();const i=X.useRef(null),{ref:r}=qF({onSetTransform(A){i.current&&(i.current.style.transform=p1(A))}}),{containerWidth:s,containerHeight:a}=ASt(r),c=X.useMemo(()=>!s||!a?"":I4t(t,{width:s,height:a||720}),[t,s,a]);X.useMemo(()=>{if(!c)return hA();const A=c.match(/data-real-to-screen-transform="([^"]+)"/)?.[1];try{return EU(A)}catch(u){return console.error(u),hA()}},[c]);const l=X.useMemo(()=>K.jsx("div",{ref:i,style:{pointerEvents:"auto",transformOrigin:"0 0"},dangerouslySetInnerHTML:{__html:c}}),[c]);return K.jsx("div",{ref:r,style:{position:"relative",backgroundColor:"#FFFFFF",overflow:"hidden",minHeight:"300px",...e},children:l})};const dSt=["Initialize a tscircuit project using [tsci init](https://github.com/tscircuit/cli) before adding components.","Define reusable modules with cached routes using [<subcircuit />](https://docs.tscircuit.com/elements/subcircuit)","Run `tsci dev` on the command line to preview your boards before export",'Use units like mm or mils consistently across your designs (e.g. pcbX="10mm")',"Quickly set footprints with the [footprint prop](https://docs.tscircuit.com/footprints/footprinter-strings)","Check out the guide on [ordering prototypes](https://docs.tscircuit.com/building-electronics/ordering-prototypes)","Use [net labels](https://docs.tscircuit.com/elements/net) and [group elements](https://docs.tscircuit.com/elements/group) to organize complex schematics.","You can manually drag components on the PCB and Schematic using [manual edits](https://docs.tscircuit.com/guides/manual-edits)","Every tscircuit module can export to [Circuit JSON](https://github.com/tscircuit/circuit-json), Gerbers, Pick'n'Place CSV files, Bill of Materials CSV and more","You can import components from [JLCPCB](https://docs.tscircuit.com/guides/importing-modules-and-chips/importing-from-jlcpcb) or [KiCad](https://docs.tscircuit.com/guides/importing-modules-and-chips/importing-from-kicad)","Any module you push to the [registry](https://tscircuit.com/trending) will have [simple image urls](https://docs.tscircuit.com/web-apis/image-generation-api) you can use display images on a website","The default [Parts Engine](https://docs.tscircuit.com/guides/platform-configuration) will automatically find parts from common vendors for your BOM",'[Pin selectors](https://docs.tscircuit.com/guides/using-sel-references) are similar to CSS selectors, ".R1 > .pin1" means "connect to the first pin of the component R1"',"You can use the [sel](https://docs.tscircuit.com/guides/using-sel-references) object to select pins in a type-safe way","Publish modules via the [registry](https://tscircuit.com/trending) for working with a team or sharing your work","[Explore tutorials](https://docs.tscircuit.com/category/tutorials) for real-world circuit design examples.","Upload your Circuit JSON to [circuitjson.com](https://circuitjson.com) for a quick preview.","You can display Circuit JSON in 3D, PCB or Schematic mode with the [<CircuitJsonPreview />](https://docs.tscircuit.com/guides/running-tscircuit/displaying-circuit-json-on-a-webpage#react-display-all-available-previews-with-circuitjsonpreview-) React component","Use a [<group />](https://docs.tscircuit.com/elements/group) element to move multiple components at once in a schematic or PCB layout.","Check out the [GitHub Discussions page](https://github.com/tscircuit/tscircuit/discussions) to upvote features","You can customize the autorouter using the [autorouter prop](https://docs.tscircuit.com/elements/board#setting-the-autorouter)","Use the [<constraint />](https://docs.tscircuit.com/footprints/constraint) element to enforce geometric relationships in PCB designs.","When working on component placement and circuit design, autorouting can slow down your iteration cycle. Use [routingDisabled](https://docs.tscircuit.com/elements/board#disabling-routing-with-routingdisabled) on the <board /> element to disable autorouting temporarily.","Join the [Discord server](https://tscircuit.com/join) to discuss issues and get help directly from the community."],n2o=(()=>{let t=dSt[Math.floor(Math.random()*dSt.length)];return t=t.replace(/</g,"&lt;"),t=t.replace(/>/g,"&gt;"),t=t.replace(new RegExp('(?<!href=")(?<!\\()(?<!\\]\\()(https?:\\/\\/[^\\s\\)\\]]+)',"g"),(e,n)=>`<a class="rf-text-blue-500 rf-underline" href="${e}" target="_blank">${e}</a>`),t=t.replace(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/g,'<a class="rf-text-blue-500 rf-underline" href="$2" target="_blank">$1</a>'),t})(),Wb=({onRunClicked:t})=>K.jsxs("div",{className:"rf-flex rf-flex-col rf-items-center rf-justify-center rf-h-full rf-bg-gray-50 rf-text-gray-500 rf-p-4",children:[K.jsx(guo,{className:"rf-size-14 rf-mb-4"}),K.jsxs("p",{className:"rf-text-md rf-break-words rf-max-w-xl rf-text-center",children:["Tip: ",K.jsx("span",{dangerouslySetInnerHTML:{__html:n2o}})]}),t&&K.jsxs(_l,{className:"rf-mt-4 rf-bg-blue-600 rf-hover:bg-blue-500",onClick:t,children:["Run Code",K.jsx(G2t,{className:"rf-w-3 rf-h-3 rf-ml-2"})]})]}),qee=({text:t,onClick:e})=>K.jsx("span",{className:"rf-cursor-pointer rf-underline rf-text-blue-600 rf-mx-2",onClick:e,children:t}),$ee=t=>K.jsxs("div",{className:"rf-leading-5",children:[K.jsx("div",{className:"rf-py-2 rf-font-bold",children:t.column.name}),K.jsx("div",{children:t.field?.()??K.jsx("input",{type:"text",className:"rf-border rf-rounded rf-p-1 rf-w-full",onChange:e=>{t.onTextChange?.(e.target.value)}})})]}),o2o=({open:t,children:e,title:n,onClose:o})=>t?K.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-justify-center rf-items-center rf-z-50",onClick:o,children:K.jsxs("div",{className:"rf-bg-white rf-p-5 rf-rounded-lg rf-relative rf-w-11/12 rf-max-w-2xl",onClick:i=>{i.preventDefault(),i.stopPropagation()},children:[K.jsx("h2",{className:"rf-mt-0 rf-text-md rf-pb-4",children:n}),K.jsx("button",{type:"button",className:"rf-absolute rf-top-2 rf-right-4 rf-text-2xl rf-font-bold",onClick:o,children:"×"}),e]})}):null,i2o=({elements:t})=>{const[e,n]=X.useState({open:!1}),[o,i]=X.useReducer((A,u)=>({...A,...u}),{}),r=[...new Set(t.map(A=>A.type))],s=t.map(A=>{const u=A[`${A.type}_id`],d=Object.fromEntries(Object.entries(A).filter(([h])=>!(h===`${A.type}_id`||!h.endsWith("_id")))),_=Object.fromEntries(Object.entries(A).filter(([h])=>!h.endsWith("_id")));return{primary_id:u,other_ids:d,..._,_og_elm:A}}),a=s.map(A=>{let u="";const d=_=>{const h=Object.keys(_.other_ids).find(g=>g.startsWith("source_"));if(!h)return`.${_.name}`;const m=h.slice(0,-3),p=s.find(g=>g.type===m&&g.primary_id===_.other_ids[h]);return p?"name"in p?`${d(p)} > .${_.name}`:`#${p.primary_id} > .${_.name}`:`??? > .${_.name}`};return"name"in A&&(u=d(A)),{...A,selector_path:u}}),c=[{key:"primary_id",name:"primary_id",renderCell:A=>K.jsxs("div",{className:"rf-flex rf-items-center",children:[K.jsx(qee,{text:A.primary_id,onClick:()=>i({focused_id:A.primary_id,id_search:void 0,selector_search:void 0})}),K.jsx("span",{className:"rf-flex-grow"}),K.jsx(qee,{text:"(JSON)",onClick:()=>n({open:!0,element:A._og_elm,title:A.primary_id})})]}),renderHeaderCell:A=>K.jsx($ee,{column:A,onTextChange:u=>i({id_search:u}),field:o.focused_id?()=>K.jsxs("div",{children:["Focus:"," ",K.jsx("span",{className:"rf-underline",children:o.focused_id}),K.jsx(qee,{text:"(unfocus)",onClick:()=>i({focused_id:void 0})})]}):void 0})},{key:"type",name:"type",renderHeaderCell:A=>K.jsx($ee,{column:A,field:()=>K.jsxs("select",{onChange:u=>i({component_type_filter:u.target.value}),className:"rf-border rf-rounded rf-p-1 rf-w-full",children:[K.jsx("option",{value:"any",children:"any"},"any"),K.jsx("option",{value:"source",children:"source"},"source"),K.jsx("option",{value:"source/pcb",children:"source/pcb"},"source/pcb"),K.jsx("option",{value:"source/schematic",children:"source/schematic"},"source/schematic"),r.map(u=>K.jsx("option",{value:u,children:u},u))]})})},{key:"name",name:"name",renderHeaderCell:A=>K.jsx($ee,{column:A,onTextChange:u=>i({name_search:u})})},{key:"selector_path",name:"selector_path",renderHeaderCell:A=>K.jsx($ee,{column:A,onTextChange:u=>i({selector_search:u})})},{key:"other_ids",name:"other_ids",renderCell:A=>K.jsx("div",{className:"rf-space-x-2",children:Object.entries(A.other_ids).map(([u,d])=>K.jsx(qee,{text:d,onClick:()=>i({focused_id:d})},d))})}],l=a.filter(A=>o.name_search?A.name?.toLowerCase()?.includes(o.name_search.toLowerCase()):!0).filter(A=>!o.component_type_filter||o.component_type_filter==="any"?!0:o.component_type_filter==="source"?A.type.startsWith("source_"):o.component_type_filter==="source/pcb"?A.type.startsWith("source_")||A.type.startsWith("pcb_"):o.component_type_filter==="source/schematic"?A.type.startsWith("source_")||A.type.startsWith("schematic_"):A.type?.includes(o.component_type_filter)).filter(A=>o.selector_search?o.selector_search.split(" ").filter(d=>d.length>0).every(d=>A.selector_path?.includes(d)):!0).filter(A=>o.id_search?A.primary_id?.includes(o.id_search):!0).filter(A=>!!(!o.focused_id||A.primary_id===o.focused_id||Object.values(A.other_ids).includes(o.focused_id)));return K.jsxs("div",{className:"rf-font-mono rf-text-xs rf-bg-white",children:[K.jsx("div",{className:"rf-overflow-x-auto",children:K.jsxs("table",{className:"rf-table-auto rf-w-full rf-text-left",children:[K.jsx("thead",{children:K.jsx("tr",{children:c.map(A=>K.jsx("th",{className:"rf-px-4 rf-py-2 rf-border-b",children:A.renderHeaderCell?A.renderHeaderCell(A):A.name},A.key))})}),K.jsx("tbody",{children:l.map((A,u)=>K.jsx("tr",{className:"rf-hover:bg-gray-100",children:c.map(d=>K.jsx("td",{className:"rf-px-4 rf-py-2 rf-border-b",children:d.renderCell?d.renderCell(A):A[d.key]},d.key))},u))})]})}),K.jsx(o2o,{open:e.open,onClose:()=>n({open:!1}),title:e.open?e.title:"",children:K.jsx("div",{className:"rf-bg-gray-800 rf-p-3 rf-text-white rf-rounded",children:K.jsx("pre",{className:"rf-whitespace-pre-wrap",children:e.open?JSON.stringify(e.element,null,2):""})})})]})};var yO={},zPe={},hSt;function r2o(){return hSt||(hSt=1,(function(t){Object.defineProperty(t,"__esModule",{value:!0});var e=(function(){function r(s,a){var c=[],l=!0,A=!1,u=void 0;try{for(var d=s[Symbol.iterator](),_;!(l=(_=d.next()).done)&&(c.push(_.value),!(a&&c.length===a));l=!0);}catch(h){A=!0,u=h}finally{try{!l&&d.return&&d.return()}finally{if(A)throw u}}return c}return function(s,a){if(Array.isArray(s))return s;if(Symbol.iterator in Object(s))return r(s,a);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();t.default=o,t.parseUnitObj=i;var n=/-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/;function o(r){var s=parseFloat(r),a=r.match(n)||[],c=a.length>0?r.substr(a[0].length).trim():"";return[s,c]}function i(r){var s=o(r),a=e(s,2),c=a[0],l=a[1];return{val:c,unit:l}}})(zPe)),zPe}var _St;function s2o(){if(_St)return yO;_St=1,Object.defineProperty(yO,"__esModule",{value:!0});var t=(function(){function c(l,A){var u=[],d=!0,_=!1,h=void 0;try{for(var m=l[Symbol.iterator](),p;!(d=(p=m.next()).done)&&(u.push(p.value),!(A&&u.length===A));d=!0);}catch(g){_=!0,h=g}finally{try{!d&&m.return&&m.return()}finally{if(_)throw h}}return u}return function(l,A){if(Array.isArray(l))return l;if(Symbol.iterator in Object(l))return c(l,A);throw new TypeError("Invalid attempt to destructure non-iterable instance")}})();yO.formatSI=r,yO.unformatSI=a;function e(c){return c&&c.__esModule?c:{default:c}}var n=r2o(),o=e(n),i={24:"Y",21:"Z",18:"E",15:"P",12:"T",9:"G",6:"M",3:"k",0:"","-3":"m","-6":"µ","-9":"n","-12":"p","-15":"f","-18":"a","-21":"z","-24":"y"};function r(c){if(c===0)return"0";for(var l=Math.abs(c),A=0;l>=1e3&&A<24;)l/=1e3,A+=3;for(;l<1&&A>-24;)l*=1e3,A-=3;var u=c<0?"-":"";return l>1e3?u+l.toFixed(0)+i[A]:u+parseFloat(l.toPrecision(3))+i[A]}var s={Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,"":1,m:.001,µ:1e-6,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24};function a(c){if(c==null||c==="")return NaN;var l=(0,o.default)(c),A=t(l,2),u=A[0],d=A[1],_=s[d];return u*_}return yO}var a2o=s2o(),Zee={exports:{}};var c2o=Zee.exports,mSt;function l2o(){return mSt||(mSt=1,(function(t,e){((n,o)=>{t.exports=o()})(c2o,function n(){var o=typeof self<"u"?self:typeof window<"u"?window:o!==void 0?o:{},i,r=!o.document&&!!o.postMessage,s=o.IS_PAPA_WORKER||!1,a={},c=0,l={};function A(B){return B.charCodeAt(0)===65279?B.slice(1):B}function u(B){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(M){var R=E(M);R.chunkSize=parseInt(R.chunkSize),M.step||M.chunk||(R.chunkSize=null),this._handle=new p(R),(this._handle.streamer=this)._config=R}).call(this,B),this.parseChunk=function(M,R){var k=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<k){let F=this._config.newline;F||(H=this._config.quoteChar||'"',F=this._handle.guessLineEndings(M,H)),M=[...M.split(F).slice(k)].join(F)}this.isFirstChunk&&P(this._config.beforeFirstChunk)&&(H=this._config.beforeFirstChunk(M))!==void 0&&(M=H),this.isFirstChunk=!1,this._halted=!1;var k=this._partialLine+M,H=(this._partialLine="",this._handle.parse(k,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(M=H.meta.cursor,k=(this._finished||(this._partialLine=k.substring(M-this._baseIndex),this._baseIndex=M),H&&H.data&&(this._rowCount+=H.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),s)o.postMessage({results:H,workerId:l.WORKER_ID,finished:k});else if(P(this._config.chunk)&&!R){if(this._config.chunk(H,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=H=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(H.data),this._completeResults.errors=this._completeResults.errors.concat(H.errors),this._completeResults.meta=H.meta),this._completed||!k||!P(this._config.complete)||H&&H.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),k||H&&H.meta.paused||this._nextChunk(),H}this._halted=!0},this._sendError=function(M){P(this._config.error)?this._config.error(M):s&&this._config.error&&o.postMessage({workerId:l.WORKER_ID,error:M,finished:!1})}}function d(B){var M;(B=B||{}).chunkSize||(B.chunkSize=l.RemoteChunkSize),u.call(this,B),this._nextChunk=r?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(R){this._input=R,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(M=new XMLHttpRequest,this._config.withCredentials&&(M.withCredentials=this._config.withCredentials),r||(M.onload=b(this._chunkLoaded,this),M.onerror=b(this._chunkError,this)),M.open(this._config.downloadRequestBody?"POST":"GET",this._input,!r),this._config.downloadRequestHeaders){var R,k=this._config.downloadRequestHeaders;for(R in k)M.setRequestHeader(R,k[R])}var H;this._config.chunkSize&&(H=this._start+this._config.chunkSize-1,M.setRequestHeader("Range","bytes="+this._start+"-"+H));try{M.send(this._config.downloadRequestBody)}catch(F){this._chunkError(F.message)}r&&M.status===0&&this._chunkError()}},this._chunkLoaded=function(){M.readyState===4&&(M.status<200||400<=M.status?this._chunkError():(this._start+=this._config.chunkSize||M.responseText.length,this._finished=!this._config.chunkSize||this._start>=(R=>(R=R.getResponseHeader("Content-Range"))!==null?parseInt(R.substring(R.lastIndexOf("/")+1)):-1)(M),this.parseChunk(M.responseText)))},this._chunkError=function(R){R=M.statusText||R,this._sendError(new Error(R))}}function _(B){(B=B||{}).chunkSize||(B.chunkSize=l.LocalChunkSize),u.call(this,B);var M,R,k=typeof FileReader<"u";this.stream=function(H){this._input=H,R=H.slice||H.webkitSlice||H.mozSlice,k?((M=new FileReader).onload=b(this._chunkLoaded,this),M.onerror=b(this._chunkError,this)):M=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var H=this._input,F=(this._config.chunkSize&&(F=Math.min(this._start+this._config.chunkSize,this._input.size),H=R.call(H,this._start,F)),M.readAsText(H,this._config.encoding));k||this._chunkLoaded({target:{result:F}})},this._chunkLoaded=function(H){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(H.target.result)},this._chunkError=function(){this._sendError(M.error)}}function h(B){var M;u.call(this,B=B||{}),this.stream=function(R){return M=R,this._nextChunk()},this._nextChunk=function(){var R,k;if(!this._finished)return R=this._config.chunkSize,M=R?(k=M.substring(0,R),M.substring(R)):(k=M,""),this._finished=!M,this.parseChunk(k)}}function m(B){u.call(this,B=B||{});var M=[],R=!0,k=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(H){this._input=H,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){k&&M.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),M.length?this.parseChunk(M.shift()):R=!0},this._streamData=b(function(H){try{M.push(typeof H=="string"?H:H.toString(this._config.encoding)),R&&(R=!1,this._checkIsFinished(),this.parseChunk(M.shift()))}catch(F){this._streamError(F)}},this),this._streamError=b(function(H){this._streamCleanUp(),this._sendError(H)},this),this._streamEnd=b(function(){this._streamCleanUp(),k=!0,this._streamData("")},this),this._streamCleanUp=b(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function p(B){var M,R,k,H,F=Math.pow(2,53),G=-F,W=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,J=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,q=this,oe=0,le=0,ee=!1,re=!1,ae=[],ie={data:[],errors:[],meta:{}};function de(ue){return B.skipEmptyLines==="greedy"?ue.join("").trim()==="":ue.length===1&&ue[0].length===0}function ye(){if(ie&&k&&(ve("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+l.DefaultDelimiter+"'"),k=!1),B.skipEmptyLines&&(ie.data=ie.data.filter(function(De){return!de(De)})),Ie()){let De=function(Ge,Ye){Ge=A(Ge),P(B.transformHeader)&&(Ge=B.transformHeader(Ge,Ye)),ae.push(Ge)};if(ie)if(Array.isArray(ie.data[0])){for(var ue=0;Ie()&&ue<ie.data.length;ue++)ie.data[ue].forEach(De);ie.data.splice(0,1)}else ie.data.forEach(De)}function Se(De,Ge){for(var Ye=B.header?{}:[],fe=0;fe<De.length;fe++){var qe=fe,Le=De[fe],Le=((Qe,Ue)=>(we=>(B.dynamicTypingFunction&&B.dynamicTyping[we]===void 0&&(B.dynamicTyping[we]=B.dynamicTypingFunction(we)),(B.dynamicTyping[we]||B.dynamicTyping)===!0))(Qe)?Ue==="true"||Ue==="TRUE"||Ue!=="false"&&Ue!=="FALSE"&&((we=>{if(W.test(we)&&(we=parseFloat(we),G<we&&we<F))return 1})(Ue)?parseFloat(Ue):J.test(Ue)?new Date(Ue):Ue===""?null:Ue):Ue)(qe=B.header?fe>=ae.length?"__parsed_extra":ae[fe]:qe,Le=B.transform?B.transform(Le,qe):Le);qe==="__parsed_extra"?(Ye[qe]=Ye[qe]||[],Ye[qe].push(Le)):Ye[qe]=Le}return B.header&&(fe>ae.length?ve("FieldMismatch","TooManyFields","Too many fields: expected "+ae.length+" fields but parsed "+fe,le+Ge):fe<ae.length&&ve("FieldMismatch","TooFewFields","Too few fields: expected "+ae.length+" fields but parsed "+fe,le+Ge)),Ye}var he;ie&&(B.header||B.dynamicTyping||B.transform)&&(he=1,!ie.data.length||Array.isArray(ie.data[0])?(ie.data=ie.data.map(Se),he=ie.data.length):ie.data=Se(ie.data,0),B.header&&ie.meta&&(ie.meta.fields=ae),le+=he)}function Ie(){return B.header&&ae.length===0}function ve(ue,Se,he,De){ue={type:ue,code:Se,message:he},De!==void 0&&(ue.row=De),ie.errors.push(ue)}P(B.step)&&(H=B.step,B.step=function(ue){ie=ue,Ie()?ye():(ye(),ie.data.length!==0&&(oe+=ue.data.length,B.preview&&oe>B.preview?R.abort():(ie.data=ie.data[0],H(ie,q))))}),this.parse=function(ue,Se,he){var De=B.quoteChar||'"',De=(B.newline||(B.newline=this.guessLineEndings(ue,De)),k=!1,B.delimiter?P(B.delimiter)&&(B.delimiter=B.delimiter(ue),ie.meta.delimiter=B.delimiter):((De=((Ge,Ye,fe,qe,Le)=>{var Qe,Ue,we,Ee;Le=Le||[","," ","|",";",l.RECORD_SEP,l.UNIT_SEP];for(var Fe=0;Fe<Le.length;Fe++){for(var Me,ze=Le[Fe],je=0,it=0,at=0,At=(we=void 0,new f({comments:qe,delimiter:ze,newline:Ye,preview:10}).parse(Ge)),lt=0;lt<At.data.length;lt++)fe&&de(At.data[lt])?at++:(Me=At.data[lt].length,it+=Me,we===void 0?we=Me:0<Me&&(je+=Math.abs(Me-we),we=Me));0<At.data.length&&(it/=At.data.length-at),(Ue===void 0||je<=Ue)&&(Ee===void 0||Ee<it)&&1.99<it&&(Ue=je,Qe=ze,Ee=it)}return{successful:!!(B.delimiter=Qe),bestDelimiter:Qe}})(ue,B.newline,B.skipEmptyLines,B.comments,B.delimitersToGuess)).successful?B.delimiter=De.bestDelimiter:(k=!0,B.delimiter=l.DefaultDelimiter),ie.meta.delimiter=B.delimiter),E(B));return B.preview&&B.header&&De.preview++,M=ue,R=new f(De),ie=R.parse(M,Se,he),ye(),ee?{meta:{paused:!0}}:ie||{meta:{paused:!1}}},this.paused=function(){return ee},this.pause=function(){ee=!0,R.abort(),M=P(B.chunk)?"":M.substring(R.getCharIndex())},this.resume=function(){q.streamer._halted?(ee=!1,q.streamer.parseChunk(M,!0)):setTimeout(q.resume,3)},this.aborted=function(){return re},this.abort=function(){re=!0,R.abort(),ie.meta.aborted=!0,P(B.complete)&&B.complete(ie),M=""},this.guessLineEndings=function(Ge,De){Ge=Ge.substring(0,1048576);var De=new RegExp(g(De)+"([^]*?)"+g(De),"gm"),he=(Ge=Ge.replace(De,"")).split("\r"),De=Ge.split(`
@@ -5790,7 +5790,7 @@ test("${l} should solve problem correctly", () => {
5790
5790
  // Add more specific assertions based on expected output
5791
5791
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5792
5792
  })
5793
- `,u=new Blob([A],{type:"text/plain"}),d=URL.createObjectURL(u),_=document.createElement("a");_.href=d,_.download=`${l}.test.ts`,_.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&K.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},q3t=t=>t.activeSubSolver?[t,...q3t(t.activeSubSolver)]:[t],Mbo=({solver:t})=>{const e=q3t(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(Bbo,{solver:n})]},n.constructor.name))})},wbo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=X.useReducer(m=>!m,!1),a=X.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};X.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),X.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const _=t.getCurrentPhase!==void 0,h=_?t.getCurrentPhase():null;return K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsx(Mbo,{solver:t})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),K.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),K.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),K.jsx("button",{onClick:d,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),_&&K.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",K.jsx("span",{className:"font-medium",children:h})]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Dbo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Qbo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Dbo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const d=t.pipelineDef[e+1],_=d?t.firstIterationOfPhase?.[d.solverName]:void 0;_!==void 0&&s!==null?c=_-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},Tbo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Rbo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Nbo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),kbo=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=Nbo(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",String(i)]},o))})]})},Eve=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Eve);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Eve(o));return e},Lbo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Eve(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)}`)}},Hbo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>Qbo(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):Lbo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return K.jsxs("div",{className:"border-t border-gray-200",children:[K.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:o.map(a=>K.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),K.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.name} completes`,children:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Tbo,{status:a.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Rbo,{progress:a.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(kbo,{stats:a.stats})}),K.jsx("td",{className:"px-4 py-2",children:a.solverInstance?K.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),K.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Fbo=class extends Ur.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Obo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,C=p.height??0;A(g,f),A(g+y,f+C)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,d=s-u,_=a-u,h=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${_} ${h} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>K.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>K.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-${g}`)),i.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var Gbo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=X.useReducer(A=>A+1,0),s=X.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=X.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);X.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(d=>d.solverName===A);)t.step();r()}};return K.jsxs("div",{children:[K.jsx(wbo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(Fbo,{fallback:K.jsx(Obo,{graphics:s}),children:K.jsx(vbo,{graphics:s})}),c&&K.jsx(Hbo,{solver:t,onStepUntilPhase:l})]})};const Ubo=()=>{X.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)},[])},zbo=t=>t.toLowerCase().includes("pack")?muo:t.toLowerCase().includes("rout")?Cuo:euo,Vbo=({solverEvents:t=[]})=>{const[e,n]=X.useState(null);Ubo();const o=X.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=X.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=X.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=Sme[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Sme).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return K.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=zbo(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsx(J2,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(Gbo,{solver:s.instance})}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},$3t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{X.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{eD.captureException(o)}catch{}}},[t,e]),X.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{eD.captureException(i,{error_type:o.type})}catch{}}},[n])},Z3t=t=>{X.useEffect(()=>{try{l9n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},ePt="0.0.2116",Ybo={version:ePt},vte=tot()(not(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),Kbo=t=>{const[e,n]=X.useState([]),[o,i]=X.useState(null),[r,s]=X.useState(""),[a,c]=Tw("eval-version-selection",null),l=vte(_=>_.setLastRunEvalVersion),A=vte(_=>_.lastRunEvalVersion);return X.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(_=>_.json()).then(_=>{if(Array.isArray(_?.versions)){let h=[..._.versions];_.tags?.latest&&(i(_.tags.latest),h=h.filter(m=>m!==_.tags.latest)),n(h)}}).catch(()=>{})},[t]),X.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:X.useMemo(()=>e.filter(_=>_.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:A,search:r,setSearch:s,selectVersion:_=>{c(_),s("")}}},Wbo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=X.useState(""),[s,a]=X.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),A=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):l&&r(s))};return K.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:u=>a(u.target.value),onKeyDown:A}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),l&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},jbo=t=>{const e=X.useRef(null),n=x0(o=>o.recentEvents);X.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 Bte="Dialog",[tPt,nPt]=zI(Bte),[Xbo,m5]=tPt(Bte),Mte=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=X.useRef(null),c=X.useRef(null),[l,A]=uP({prop:o,defaultProp:i??!1,onChange:r,caller:Bte});return K.jsx(Xbo,{scope:e,triggerRef:a,contentRef:c,contentId:hp(),titleId:hp(),descriptionId:hp(),open:l,onOpenChange:A,onOpenToggle:X.useCallback(()=>A(u=>!u),[A]),modal:s,children:n})};Mte.displayName=Bte;var oPt="DialogTrigger",iPt=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(oPt,n),r=I0(e,i.triggerRef);return K.jsx(Na.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":Pve(i.open),...o,ref:r,onClick:br(t.onClick,i.onOpenToggle)})});iPt.displayName=oPt;var bve="DialogPortal",[Jbo,rPt]=tPt(bve,{forceMount:void 0}),wte=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=m5(bve,e);return K.jsx(Jbo,{scope:e,forceMount:n,children:X.Children.map(o,s=>K.jsx(ux,{present:n||r.open,children:K.jsx(XZ,{asChild:!0,container:i,children:s})}))})};wte.displayName=bve;var Dte="DialogOverlay",DO=X.forwardRef((t,e)=>{const n=rPt(Dte,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=m5(Dte,t.__scopeDialog);return r.modal?K.jsx(ux,{present:o||r.open,children:K.jsx($bo,{...i,ref:e})}):null});DO.displayName=Dte;var qbo=w6("DialogOverlay.RemoveScroll"),$bo=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(Dte,n),r=kuo(),s=I0(e,r);return K.jsx(oee,{as:qbo,allowPinchZoom:!0,shards:[i.contentRef],children:K.jsx(Na.div,{"data-state":Pve(i.open),...o,ref:s,style:{pointerEvents:"auto",...o.style}})})}),iT="DialogContent",QO=X.forwardRef((t,e)=>{const n=rPt(iT,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=m5(iT,t.__scopeDialog);return K.jsx(ux,{present:o||r.open,children:r.modal?K.jsx(Zbo,{...i,ref:e}):K.jsx(eSo,{...i,ref:e})})});QO.displayName=iT;var Zbo=X.forwardRef((t,e)=>{const n=m5(iT,t.__scopeDialog),o=X.useRef(null),i=I0(e,n.contentRef,o);return X.useEffect(()=>{const r=o.current;if(r)return b3e(r)},[]),K.jsx(sPt,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:br(t.onCloseAutoFocus,r=>{r.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:br(t.onPointerDownOutside,r=>{const s=r.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&r.preventDefault()}),onFocusOutside:br(t.onFocusOutside,r=>r.preventDefault())})}),eSo=X.forwardRef((t,e)=>{const n=m5(iT,t.__scopeDialog),o=X.useRef(!1),i=X.useRef(!1);return K.jsx(sPt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:r=>{t.onCloseAutoFocus?.(r),r.defaultPrevented||(o.current||n.triggerRef.current?.focus(),r.preventDefault()),o.current=!1,i.current=!1},onInteractOutside:r=>{t.onInteractOutside?.(r),r.defaultPrevented||(o.current=!0,r.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=r.target;n.triggerRef.current?.contains(s)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&i.current&&r.preventDefault()}})}),sPt=X.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:r,...s}=t,a=m5(iT,n);return o3e(),K.jsx(K.Fragment,{children:K.jsx(kZ,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:i,onUnmountAutoFocus:r,children:K.jsx(vF,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Pve(a.open),...s,ref:e,deferPointerDownOutside:!0,onDismiss:()=>a.onOpenChange(!1)})})})}),aPt="DialogTitle",Qte=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(aPt,n);return K.jsx(Na.h2,{id:i.titleId,...o,ref:e})});Qte.displayName=aPt;var cPt="DialogDescription",Tte=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(cPt,n);return K.jsx(Na.p,{id:i.descriptionId,...o,ref:e})});Tte.displayName=cPt;var lPt="DialogClose",Sve=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(lPt,n);return K.jsx(Na.button,{type:"button",...o,ref:e,onClick:br(t.onClick,()=>i.onOpenChange(!1))})});Sve.displayName=lPt;function Pve(t){return t?"open":"closed"}var APt="AlertDialog",[tSo]=zI(APt,[nPt]),jb=nPt(),uPt=t=>{const{__scopeAlertDialog:e,...n}=t,o=jb(e);return K.jsx(Mte,{...o,...n,modal:!0})};uPt.displayName=APt;var nSo="AlertDialogTrigger",oSo=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(iPt,{...i,...o,ref:e})});oSo.displayName=nSo;var iSo="AlertDialogPortal",dPt=t=>{const{__scopeAlertDialog:e,...n}=t,o=jb(e);return K.jsx(wte,{...o,...n})};dPt.displayName=iSo;var rSo="AlertDialogOverlay",hPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(DO,{...i,...o,ref:e})});hPt.displayName=rSo;var _Pt="AlertDialogContent",[sSo,aSo]=tSo(_Pt),mPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,children:o,...i}=t,r=jb(n),s=X.useRef(null),a=I0(e,s),c=X.useRef(null);return K.jsx(sSo,{scope:n,cancelRef:c,children:K.jsx(QO,{role:"alertdialog",...r,...i,ref:a,onOpenAutoFocus:br(i.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:o})})});mPt.displayName=_Pt;var cSo="AlertDialogTitle",gPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(Qte,{...i,...o,ref:e})});gPt.displayName=cSo;var lSo="AlertDialogDescription",pPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(Tte,{...i,...o,ref:e})});pPt.displayName=lSo;var ASo="AlertDialogAction",fPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(Sve,{...i,...o,ref:e})});fPt.displayName=ASo;var yPt="AlertDialogCancel",CPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,{cancelRef:i}=aSo(yPt,n),r=jb(n),s=I0(e,i);return K.jsx(Sve,{...r,...o,ref:s})});CPt.displayName=yPt;var uSo=uPt,dSo=dPt,xPt=hPt,IPt=mPt,EPt=fPt,bPt=CPt,SPt=gPt,PPt=pPt;const vPt=uSo,hSo=dSo,BPt=X.forwardRef(({className:t,...e},n)=>K.jsx(xPt,{className:Hi("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}));BPt.displayName=xPt.displayName;const vve=X.forwardRef(({className:t,...e},n)=>K.jsxs(hSo,{children:[K.jsx(BPt,{}),K.jsx(IPt,{ref:n,className:Hi("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})]}));vve.displayName=IPt.displayName;const Bve=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});Bve.displayName="AlertDialogHeader";const Mve=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});Mve.displayName="AlertDialogFooter";const wve=X.forwardRef(({className:t,...e},n)=>K.jsx(SPt,{ref:n,className:Hi("rf-text-lg rf-font-semibold",t),...e}));wve.displayName=SPt.displayName;const Dve=X.forwardRef(({className:t,...e},n)=>K.jsx(PPt,{ref:n,className:Hi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));Dve.displayName=PPt.displayName;const _So=X.forwardRef(({className:t,...e},n)=>K.jsx(EPt,{ref:n,className:Hi(bQ(),t),...e}));_So.displayName=EPt.displayName;const Qve=X.forwardRef(({className:t,...e},n)=>K.jsx(bPt,{ref:n,className:Hi(bQ({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));Qve.displayName=bPt.displayName;function mSo(t){const e=X.useRef({value:t,previous:t});return X.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var Rte="Checkbox",[gSo]=zI(Rte),[pSo,Tve]=gSo(Rte);function fSo(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:c,required:l,value:A="on",internal_do_not_use_render:u}=t,[d,_]=uP({prop:n,defaultProp:i??!1,onChange:c,caller:Rte}),[h,m]=X.useState(null),[p,g]=X.useState(null),f=X.useRef(!1),y=h?!!s||!!h.closest("form"):!0,C={checked:d,disabled:r,setChecked:_,control:h,setControl:m,name:a,form:s,value:A,hasConsumerStoppedPropagationRef:f,required:l,defaultChecked:gv(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:g};return K.jsx(pSo,{scope:e,...C,children:ySo(u)?u(C):o})}var MPt="CheckboxTrigger",wPt=X.forwardRef(({__scopeCheckbox:t,onKeyDown:e,onClick:n,...o},i)=>{const{control:r,value:s,disabled:a,checked:c,required:l,setControl:A,setChecked:u,hasConsumerStoppedPropagationRef:d,isFormControl:_,bubbleInput:h}=Tve(MPt,t),m=I0(i,A),p=X.useRef(c);return X.useEffect(()=>{const g=r?.form;if(g){const f=()=>u(p.current);return g.addEventListener("reset",f),()=>g.removeEventListener("reset",f)}},[r,u]),K.jsx(Na.button,{type:"button",role:"checkbox","aria-checked":gv(c)?"mixed":c,"aria-required":l,"data-state":NPt(c),"data-disabled":a?"":void 0,disabled:a,value:s,...o,ref:m,onKeyDown:br(e,g=>{g.key==="Enter"&&g.preventDefault()}),onClick:br(n,g=>{u(f=>gv(f)?!0:!f),h&&_&&(d.current=g.isPropagationStopped(),d.current||g.stopPropagation())})})});wPt.displayName=MPt;var Rve=X.forwardRef((t,e)=>{const{__scopeCheckbox:n,name:o,checked:i,defaultChecked:r,required:s,disabled:a,value:c,onCheckedChange:l,form:A,...u}=t;return K.jsx(fSo,{__scopeCheckbox:n,checked:i,defaultChecked:r,disabled:a,required:s,onCheckedChange:l,name:o,form:A,value:c,internal_do_not_use_render:({isFormControl:d})=>K.jsxs(K.Fragment,{children:[K.jsx(wPt,{...u,ref:e,__scopeCheckbox:n}),d&&K.jsx(RPt,{__scopeCheckbox:n})]})})});Rve.displayName=Rte;var DPt="CheckboxIndicator",QPt=X.forwardRef((t,e)=>{const{__scopeCheckbox:n,forceMount:o,...i}=t,r=Tve(DPt,n);return K.jsx(ux,{present:o||gv(r.checked)||r.checked===!0,children:K.jsx(Na.span,{"data-state":NPt(r.checked),"data-disabled":r.disabled?"":void 0,...i,ref:e,style:{pointerEvents:"none",...t.style}})})});QPt.displayName=DPt;var TPt="CheckboxBubbleInput",RPt=X.forwardRef(({__scopeCheckbox:t,...e},n)=>{const{control:o,hasConsumerStoppedPropagationRef:i,checked:r,defaultChecked:s,required:a,disabled:c,name:l,value:A,form:u,bubbleInput:d,setBubbleInput:_}=Tve(TPt,t),h=I0(n,_),m=mSo(r),p=CIt(o);X.useEffect(()=>{const f=d;if(!f)return;const y=window.HTMLInputElement.prototype,I=Object.getOwnPropertyDescriptor(y,"checked").set,E=!i.current;if(m!==r&&I){const b=new Event("click",{bubbles:E});f.indeterminate=gv(r),I.call(f,gv(r)?!1:r),f.dispatchEvent(b)}},[d,m,r,i]);const g=X.useRef(gv(r)?!1:r);return K.jsx(Na.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??g.current,required:a,disabled:c,name:l,value:A,form:u,...e,tabIndex:-1,ref:h,style:{...e.style,...p,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});RPt.displayName=TPt;function ySo(t){return typeof t=="function"}function gv(t){return t==="indeterminate"}function NPt(t){return gv(t)?"indeterminate":t?"checked":"unchecked"}const TO=X.forwardRef(({className:t,...e},n)=>K.jsx(Rve,{ref:n,className:Hi("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...e,children:K.jsx(QPt,{className:Hi("rf-flex rf-items-center rf-justify-center rf-text-current"),children:K.jsx(Q8,{className:"rf-h-4 rf-w-4"})})}));TO.displayName=Rve.displayName;const rT=Mte,CSo=wte,kPt=X.forwardRef(({className:t,...e},n)=>K.jsx(DO,{className:Hi("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}));kPt.displayName=DO.displayName;const eM=X.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>K.jsxs(CSo,{children:[K.jsx(kPt,{className:Hi(n?"":"rf-hidden")}),K.jsx(QO,{ref:i,className:Hi("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})]}));eM.displayName=QO.displayName;const tM=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});tM.displayName="DialogHeader";const RO=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});RO.displayName="DialogFooter";const nM=X.forwardRef(({className:t,...e},n)=>K.jsx(Qte,{ref:n,className:Hi("rf-text-lg rf-font-semibold",t),...e}));nM.displayName=Qte.displayName;const sT=X.forwardRef(({className:t,...e},n)=>K.jsx(Tte,{ref:n,className:Hi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));sT.displayName=Tte.displayName;const Nte={"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"}},xSo="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let Nve=null;const ISo=async()=>(Nve||(Nve=import(xSo)),Nve),ESo=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??[]},bSo=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}),SSo=async(t,e)=>{const{fetchEasyEDAComponent:n,convertRawEasyToTsx:o}=await ISo(),i=await n(t,{fetch:(r,s)=>fetch(`${e?.apiBase??M1}/proxy`,{...s,headers:{...s?.headers,"X-Target-Url":r.toString(),"X-Sender-Origin":s?.headers?.origin??"","X-Sender-Host":s?.headers?.host??"https://easyeda.com","X-Sender-Referer":s?.headers?.referer??"","X-Sender-User-Agent":s?.headers?.userAgent??"","X-Sender-Cookie":s?.headers?.cookie??"",authority:s?.headers?.authority??"","content-type":s?.headers?.["content-type"]??"",...e?.headers}})});return o({rawEasy:i})},PSo=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=X.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[K.jsxs("div",{className:"rf-relative rf-flex-grow",children:[K.jsx(e3e,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),K.jsx(VPe,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),K.jsx(_l,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):K.jsxs(K.Fragment,{children:[K.jsx(e3e,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),K.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},vSo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),BSo=t=>vSo.format(t),LPt=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"}},MSo=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},wSo=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}},DSo=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.partNumber;case"kicad":return}},QSo=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?LPt(e):null;return K.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=LPt(r),a=i===s,c=MSo(r),l=wSo(r),A=DSo(r),u=r.source==="jlcpcb"?r.component.stock:null,d=r.source==="jlcpcb"?r.component.price:null,_=r.source==="jlcpcb"?r.component.isBasic:null;return K.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${a?"rf-bg-zinc-100":""}`,onClick:()=>n(r),children:[K.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[K.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[K.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[c,r.source==="jlcpcb"&&_!=null&&K.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${_?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:_?"Basic":"Extended"}),r.source==="tscircuit.com"&&r.package.is_private&&K.jsx(puo,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&u!=null?K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[u.toLocaleString()," in stock"]}):null]}),K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[A?K.jsx("span",{className:"rf-mr-2",children:A}):null,l]})]}),K.jsxs("div",{children:[r.source==="tscircuit.com"&&o?K.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:K.jsx(_l,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:h=>{h.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&u!=null?K.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[u.toLocaleString()," in stock"]}):null,d!=null&&K.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:BSo(d)})]})]},s)})})},HPt={importComponentDialog:101,importComponentDetailsDialog:102},TSo=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:c})=>{const l=t?.package??null,A=l?.latest_pcb_preview_image_url,u=l?.latest_sch_preview_image_url,d=l?.latest_cad_preview_image_url,_=l?.unscoped_name?.split("/").pop()??l?.unscoped_name,h=l?.org_owner_tscircuit_handle??void 0,m=h?`https://tscircuit.com/${h}`:void 0,p=h&&_?`https://tscircuit.com/${h}/${_}`:void 0;return K.jsx(rT,{open:e,onOpenChange:n,children:K.jsxs(eM,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:HPt.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[K.jsx(tM,{className:"rf-pb-4 rf-border-b",children:K.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx(nM,{className:"rf-text-xl rf-font-semibold rf-truncate",children:_}),K.jsx(sT,{children:l?.description})]})})}),K.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[h?K.jsxs("div",{children:[K.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),K.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?K.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:h}):h})]}):null,(d||A||u)&&K.jsx(K.Fragment,{children:K.jsxs("div",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),K.jsxs(Lpe,{value:r,onValueChange:g=>s(g),children:[K.jsxs(UJ,{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:[A&&K.jsx(B4,{value:"pcb",children:"PCB"}),u&&K.jsx(B4,{value:"schematic",children:"Schematic"}),d&&K.jsx(B4,{value:"3d",children:"3D"})]}),K.jsxs("div",{className:"rf-mt-4",children:[K.jsx(bf,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:A?K.jsx("img",{src:A,alt:`${_??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(bf,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?K.jsx("img",{src:u,alt:`${_??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(bf,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:d?K.jsx("img",{src:d,alt:`${_??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?K.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),K.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),K.jsxs(RO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[K.jsx("div",{className:"rf-flex-1",children:p?K.jsxs(_l,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[K.jsx(Auo,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),K.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(_l,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),K.jsx(_l,{onClick:c,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},RSo=()=>{const[t,e]=X.useState(null),[n,o]=X.useState(!1),i=X.useCallback(async(s,a)=>{o(!0);try{const c=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!c.ok)throw new Error(`Failed to load package details: ${c.status}`);const l=await c.json();e(l.package??null)}catch(c){console.error("Failed to fetch package details",c),e(null)}finally{o(!1)}},[]),r=X.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},NSo=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??[]},kSo=({sessionToken:t})=>{const[e,n]=X.useState([]),[o,i]=X.useState(!1),[r,s]=X.useState(null),[a,c]=X.useState(!1),l=X.useCallback(async u=>{const d=u.trim();if(!d)return[];i(!0),s(null);try{const h=(await NSo(d,t)).map(m=>({source:"tscircuit.com",package:m}));return n(h),h}catch(_){return console.error("Error searching tscircuit packages",_),n([]),s(_ instanceof Error?_.message:"Failed to search tscircuit packages"),[]}finally{i(!1),c(!0)}},[t]),A=X.useCallback(()=>{n([]),i(!1),s(null),c(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:l,reset:A}},LSo=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},HSo=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),c=X.useCallback(async A=>{const u=LSo(A);if(!u)return[];o(!0),r(null);try{const _=(await ESo(u,10)).map(h=>({source:"jlcpcb",component:bSo(h)}));return e(_),_}catch(d){return console.error("Error searching JLCPCB components",d),e([]),r(d instanceof Error?d.message:"Failed to search JLCPCB components"),[]}finally{o(!1),a(!0)}},[]),l=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:l}};function pv(t){return Array.isArray?Array.isArray(t):OPt(t)==="[object Array]"}function FSo(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 kve(t){return t==null?"":FSo(t)}function U1(t){return typeof t=="string"}function kte(t){return typeof t=="number"}function OSo(t){return t===!0||t===!1||GSo(t)&&OPt(t)=="[object Boolean]"}function FPt(t){return typeof t=="object"}function GSo(t){return FPt(t)&&t!==null}function Tx(t){return t!=null}function Lte(t){return!t.trim().length}function OPt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const USo="Incorrect 'index' type",Lve="Invalid doc index: must be a non-negative integer within the bounds of the docs array",zSo=t=>`Invalid value for key ${t}`,VSo=t=>`Pattern length exceeds max of ${t}.`,YSo=t=>`Missing ${t} property in key`,KSo=t=>`Property 'weight' in key '${t}' must be a positive integer`,WSo="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.",GPt=Object.prototype.hasOwnProperty;var jSo=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=UPt(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 UPt(t){let e=null,n=null,o=null,i=1,r=null;if(U1(t)||pv(t))o=t,e=zPt(t),n=Hte(t);else{if(!GPt.call(t,"name"))throw new Error(YSo("name"));const s=t.name;if(o=s,GPt.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(KSo(Hte(s)));e=zPt(s),n=Hte(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function zPt(t){return pv(t)?t:t.split(".")}function Hte(t){return pv(t)?t.join("."):t}function XSo(t,e){const n=[];let o=!1;const i=(r,s,a,c)=>{if(Tx(r))if(!s[a])n.push(c!==void 0?{v:r,i:c}:r);else{const l=r[s[a]];if(!Tx(l))return;if(a===s.length-1&&(U1(l)||kte(l)||OSo(l)||typeof l=="bigint"))n.push(c!==void 0?{v:kve(l),i:c}:kve(l));else if(pv(l)){o=!0;for(let A=0,u=l.length;A<u;A+=1)i(l[A],s,a+1,A)}else s.length&&i(l,s,a+1,c)}};return i(t,U1(e)?e.split("."):e,0),o?n:n[0]}const bs=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:XSo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function JSo(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=1,s=!1;for(let c=0;c<i.length;c++)i.charCodeAt(c)===32?s||(r++,s=!0):s=!1;if(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 Hve=class{constructor({getFn:t=bs.getFn,fieldNormWeight:e=bs.fieldNormWeight}={}){this.norm=JSo(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(U1(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(Lve);if(U1(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(Lve);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!Tx(t)||Lte(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(Tx(s)){if(pv(s)){const a=[];for(let c=0,l=s.length;c<l;c+=1){const A=s[c];if(Tx(A)){if(U1(A)){if(!Lte(A)){const u={v:A,i:c,n:this.norm.get(A)};a.push(u)}}else if(Tx(A.v)){const u=U1(A.v)?A.v:kve(A.v);if(!Lte(u)){const d={v:u,i:A.i,n:this.norm.get(u)};a.push(d)}}}}n.$[o]=a}else if(U1(s)&&!Lte(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 VPt(t,e,{getFn:n=bs.getFn,fieldNormWeight:o=bs.fieldNormWeight}={}){const i=new Hve({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(UPt)),i.setSources(e),i.create(),i}function qSo(t,{getFn:e=bs.getFn,fieldNormWeight:n=bs.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new Hve({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function $So(t=[],e=bs.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 ZSo(t,e,n,{location:o=bs.location,distance:i=bs.distance,threshold:r=bs.threshold,findAllMatches:s=bs.findAllMatches,minMatchCharLength:a=bs.minMatchCharLength,includeMatches:c=bs.includeMatches,ignoreLocation:l=bs.ignoreLocation}={}){if(e.length>32)throw new Error(VSo(32));const A=e.length,u=t.length,d=Math.max(0,Math.min(o,u));let _=r,h=d;const m=(B,M)=>{const R=B/A;if(l)return R;const k=Math.abs(d-M);return i?R+k/i:k?1:R},p=a>1||c,g=p?Array(u):[];let f;for(;(f=t.indexOf(e,h))>-1;){const B=m(0,f);if(_=Math.min(B,_),h=f+A,p){let M=0;for(;M<A;)g[f+M]=1,M+=1}}h=-1;let y=[],C=1,I=0,E=A+u;const b=1<<A-1;for(let B=0;B<A;B+=1){let M=0,R=E;for(;M<R;)m(B,d+R)<=_?M=R:E=R,R=Math.floor((E-M)/2+M);E=R;let k=Math.max(1,d-R+1);const H=s?u:Math.min(d+R,u)+A,F=Array(H+2);F[H+1]=(1<<B)-1;for(let G=H;G>=k;G-=1){const W=G-1,J=n[t[W]];if(F[G]=(F[G+1]<<1|1)&J,B&&(F[G]|=(y[G+1]|y[G])<<1|1|y[G+1]),F[G]&b&&(C=m(B,W),C<=_)){if(_=C,h=W,I=B,h<=d)break;k=Math.max(1,2*d-h)}}if(m(B+1,d)>_)break;y=F}if(p&&h>=0){const B=Math.min(u-1,h+A-1+I);for(let M=h;M<=B;M+=1)n[t[M]]&&(g[M]=1)}const P={isMatch:h>=0,score:Math.max(.001,C)};if(p){const B=$So(g,a);B.length?c&&(P.indices=B):P.isMatch=!1}return P}function e3o(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 Fve(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 YPt={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},t3o=new RegExp("["+Object.keys(YPt).join("")+"]","g"),NO=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(t3o,e=>YPt[e]):t=>t;var Ove=class{constructor(t,{location:e=bs.location,threshold:n=bs.threshold,distance:o=bs.distance,includeMatches:i=bs.includeMatches,findAllMatches:r=bs.findAllMatches,minMatchCharLength:s=bs.minMatchCharLength,isCaseSensitive:a=bs.isCaseSensitive,ignoreDiacritics:c=bs.ignoreDiacritics,ignoreLocation:l=bs.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:c,ignoreLocation:l},t=a?t:t.toLowerCase(),t=c?NO(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const A=(d,_)=>{this.chunks.push({pattern:d,alphabet:e3o(d),startIndex:_})},u=this.pattern.length;if(u>32){let d=0;const _=u%32,h=u-_;for(;d<h;)A(this.pattern.substr(d,32),d),d+=32;if(_){const m=u-32;A(this.pattern.substr(m),m)}}else A(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?NO(t):t,this.pattern===t){const h={isMatch:!0,score:0};return o&&(h.indices=[[0,t.length-1]]),h}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,ignoreLocation:l}=this.options,A=[];let u=0,d=!1;this.chunks.forEach(({pattern:h,alphabet:m,startIndex:p})=>{const{isMatch:g,score:f,indices:y}=ZSo(t,h,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,includeMatches:o,ignoreLocation:l});g&&(d=!0),u+=f,g&&y&&A.push(...y)});const _={isMatch:d,score:d?u/this.chunks.length:1};return d&&o&&(_.indices=Fve(A)),_}};const n3o=new Set(["fuzzy","include"]);function o3o(t){return t.startsWith("inverse")}const Gve=[{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 Ove(t,{location:e.location??bs.location,threshold:e.threshold??bs.threshold,distance:e.distance??bs.distance,includeMatches:e.includeMatches??bs.includeMatches,findAllMatches:e.findAllMatches??bs.findAllMatches,minMatchCharLength:e.minMatchCharLength??bs.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??bs.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??bs.ignoreDiacritics,ignoreLocation:e.ignoreLocation??bs.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],KPt=Gve.length,i3o="\0",r3o="|";function s3o(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 WPt(t,e){const n=t.match(e);return n?n[1]:null}function a3o(t,e={}){return t.replace(/\\\|/g,i3o).split(r3o).map(n=>{const o=s3o(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let c=!1,l=-1;for(;!c&&++l<KPt;){const A=Gve[l],u=WPt(a,A.multiRegex);u&&(i.push(A.create(u,e)),c=!0)}if(!c)for(l=-1;++l<KPt;){const A=Gve[l],u=WPt(a,A.singleRegex);if(u){i.push(A.create(u,e));break}}}return i})}var c3o=class{constructor(t,{isCaseSensitive:e=bs.isCaseSensitive,ignoreDiacritics:n=bs.ignoreDiacritics,includeMatches:o=bs.includeMatches,minMatchCharLength:i=bs.minMatchCharLength,ignoreLocation:r=bs.ignoreLocation,findAllMatches:s=bs.findAllMatches,location:a=bs.location,threshold:c=bs.threshold,distance:l=bs.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:c,distance:l},t=e?t:t.toLowerCase(),t=n?NO(t):t,this.pattern=t,this.query=a3o(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?NO(t):t;let r=0;const s=[];let a=0,c=!1;for(let l=0,A=e.length;l<A;l+=1){const u=e[l];s.length=0,r=0,c=!1;for(let d=0,_=u.length;d<_;d+=1){const h=u[d],{isMatch:m,indices:p,score:g}=h.search(t);if(m)r+=1,a+=g,o3o(h.type)&&(c=!0),n&&(n3o.has(h.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,c=!1;break}}if(r){const d={isMatch:!0,score:a/r};return c&&(d.hasInverse=!0),n&&(d.indices=Fve(s)),d}}return{isMatch:!1,score:1}}};const Uve=[];function zve(...t){Uve.push(...t)}function Fte(t,e){for(let n=0,o=Uve.length;n<o;n+=1){const i=Uve[n];if(i.condition(t,e))return new i(t,e)}return new Ove(t,e)}const Ote={AND:"$and",OR:"$or"},Vve={PATH:"$path",PATTERN:"$val"},Yve=t=>!!(t[Ote.AND]||t[Ote.OR]),l3o=t=>!!t[Vve.PATH],A3o=t=>!pv(t)&&FPt(t)&&!Yve(t),jPt=t=>({[Ote.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function XPt(t,e,{auto:n=!0}={}){const o=i=>{if(U1(i)){const c={keyId:null,pattern:i};return n&&(c.searcher=Fte(i,e)),c}const r=Object.keys(i),s=l3o(i);if(!s&&r.length>1&&!Yve(i))return o(jPt(i));if(A3o(i)){const c=s?i[Vve.PATH]:r[0],l=s?i[Vve.PATTERN]:i[c];if(!U1(l))throw new Error(zSo(c));const A={keyId:Hte(c),pattern:l};return n&&(A.searcher=Fte(l,e)),A}const a={children:[],operator:r[0]};return r.forEach(c=>{const l=i[c];pv(l)&&l.forEach(A=>{a.children.push(o(A))})}),a};return Yve(t)||(t=jPt(t)),o(t)}function Kve(t,{ignoreFieldNorm:e=bs.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 u3o(t,{ignoreFieldNorm:e=bs.ignoreFieldNorm}){t.forEach(n=>{n.score=Kve(n.matches,{ignoreFieldNorm:e})})}var d3o=class{constructor(t){this.limit=t,this.heap=[]}get size(){return this.heap.length}shouldInsert(t){return this.size<this.limit||t<this.heap[0].score}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):t.score<this.heap[0].score&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(t){return this.heap.sort(t)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(e[t].score<=e[n].score)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&&e[i].score>e[o].score&&(o=i),r<n&&e[r].score>e[o].score&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function h3o(t){const e=[];return t.matches.forEach(n=>{if(!Tx(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 _3o(t,e,{includeMatches:n=bs.includeMatches,includeScore:o=bs.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=h3o(i)),o&&(s.score=i.score),s})}const m3o=/[\p{L}\p{M}\p{N}_]+/gu,JPt=new WeakSet;function g3o(t){JPt.has(t)||(JPt.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 p3o(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||g3o(t),e=>e.match(t)||[]):e=>e.match(m3o)||[]}function Wve({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=p3o(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=NO(i)),o(i)}}}var f3o=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=Wve({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 Ove(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 l=0;l<this.termSearchers.length;l++){const A=this.termSearchers[l].searchIn(t),u=this.idfWeights[l];o+=u,A.isMatch&&(i++,n+=u*(1-A.score),A.indices&&e.push(...A.indices),this.combineAll&&(this.useMask?r|=1<<l:s.add(l)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,c={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(c.indices=Fve(e)),this.combineAll&&(this.useMask?c.matchedMask=r:c.matchedTerms=s,c.termCount=this.numTerms),c}};function jve(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 qPt(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){jve(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const c=s[a];if(c)if(Array.isArray(c))for(const l of c)jve(t,l.v,i,o);else jve(t,c.v,i,o)}}function y3o(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)qPt(o,i,e,n);return o}function C3o(t,e,n,o){qPt(t,e,n,o)}function x3o(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 $Pt(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,c)=>a-c);for(const a of n)x3o(t,a);const o=a=>{let c=0,l=n.length;for(;c<l;){const A=c+l>>>1;n[A]<a?c=A+1:l=A}return a-c},i=n[0],r=new Map;for(const[a,c]of t.docFieldCount)r.set(a>i?o(a):a,c);t.docFieldCount=r;const s=new Map;for(const[a,c]of t.docTermFieldHits)s.set(a>i?o(a):a,c);t.docTermFieldHits=s}var fv=class{constructor(t,e,n){this.options={...bs,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new jSo(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=Fte(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 Hve))throw new Error(USo);if(this._myIndex=e||VPt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=Wve({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=y3o(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!Tx(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=Wve({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});C3o(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&&$Pt(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(Lve);this._invertedIndex&&$Pt(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}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(U1(t)&&!t.trim()){let A=this._docs.map((u,d)=>({item:u,refIndex:d}));return kte(n)&&n>-1&&(A=A.slice(0,n)),A}const c=kte(n)&&n>0&&U1(t);let l;if(c){const A=new d3o(n);U1(this._docs[0])?this._searchStringList(t,{heap:A,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:A,ignoreFieldNorm:a}),l=A.extractSorted(s)}else l=U1(t)?U1(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),u3o(l,{ignoreFieldNorm:a}),r&&l.sort(s),kte(n)&&n>-1&&(l=l.slice(0,n));return _3o(l,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:c,n:l})=>{if(!Tx(a))return;const A=o.searchIn(a);if(A.isMatch){const u={score:A.score,value:a,norm:l,indices:A.indices};i&&(u.matchedMask=A.matchedMask,u.matchedTerms=A.matchedTerms,u.termCount=A.termCount);const d=[u];if(!i||this._coversAllTokens(d)){const _={item:a,idx:c,matches:d};e?(_.score=Kve(_.matches,{ignoreFieldNorm:n}),e.shouldInsert(_.score)&&e.insert(_)):s.push(_)}}}),s}_searchLogical(t){const e=XPt(t,this.options),n=(s,a,c)=>{if(!("children"in s)){const{keyId:d,searcher:_}=s;let h;return d===null?(h=[],this._myIndex.keys.forEach((m,p)=>{h.push(...this._findMatches({key:m,value:a[p],searcher:_}))})):h=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(a,d),searcher:_}),h&&h.length?[{idx:c,item:a,matches:h}]:[]}const{children:l,operator:A}=s,u=[];for(let d=0,_=l.length;d<_;d+=1){const h=l[d],m=n(h,a,c);if(m.length)u.push(...m);else if(A===Ote.AND)return[]}return u},o=this._myIndex.records,i=new Map,r=[];return o.forEach(({$:s,i:a})=>{if(Tx(s)){const c=n(e,s,a);c.length&&(i.has(a)||(i.set(a,{idx:a,item:s,matches:[]}),r.push(i.get(a))),c.forEach(({matches:l})=>{i.get(a).matches.push(...l)}))}}),r}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{keys:r,records:s}=this._myIndex,a=e?null:[];return s.forEach(({$:c,i:l})=>{if(!Tx(c))return;const A=[];let u=!1,d=!1;if(r.forEach((_,h)=>{const m=this._findMatches({key:_,value:c[h],searcher:o});m.length?(A.push(...m),m[0].hasInverse&&(d=!0)):u=!0}),!(d&&u)&&A.length&&(!i||this._coversAllTokens(A))){const _={idx:l,item:c,matches:A};e?(_.score=Kve(_.matches,{ignoreFieldNorm:n}),e.shouldInsert(_.score)&&e.insert(_)):a.push(_)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!Tx(e))return[];const o=[];if(pv(e))e.forEach(({v:i,i:r,n:s})=>{if(!Tx(i))return;const a=n.searchIn(i);if(a.isMatch){const c={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(c.matchedMask=a.matchedMask,c.matchedTerms=a.matchedTerms,c.termCount=a.termCount),o.push(c)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};fv.version="7.4.2",fv.createIndex=VPt,fv.parseIndex=qSo,fv.config=bs,fv.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(WSo);return Fte(t,{...bs,...n}).searchIn(e)},fv.parseQuery=XPt,zve(c3o),zve(f3o),fv.use=function(...t){t.forEach(e=>zve(e))};var I3o=fv;let Xve=null,kO=null,Jve=null;const E3o=async()=>Xve||kO||(kO=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(Xve=t,kO=null,t)),kO),b3o=async(t,e=20)=>{const n=await E3o();return Jve||(Jve=new I3o(n)),Jve.search(t).slice(0,e).map(o=>o.item)},S3o=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},P3o=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),c=X.useCallback(async A=>{const u=A.trim();if(!u)return[];o(!0),r(null);try{const _=(await b3o(u,20)).map(h=>({source:"kicad",footprint:S3o(h)}));return e(_),_}catch(d){return console.error("Error searching KiCad footprints",d),e([]),r(d instanceof Error?d.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),l=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:l}},v3o=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},B3o=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{Pte();const c=X.useMemo(()=>v3o({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),l=c.length>0,A=c.length===1,[u,d]=X.useState(c[0]??"tscircuit.com"),[_,h]=X.useState(""),[m,p]=X.useState(null),{results:g,isSearching:f,error:y,hasSearched:C,search:I,reset:E}=kSo({sessionToken:a}),{results:b,isSearching:P,error:B,hasSearched:M,search:R,reset:k}=HSo(),{results:H,isSearching:F,error:G,hasSearched:W,search:J,reset:q}=P3o(),{details:oe,isLoading:le,fetchDetails:ee,reset:re}=RSo(),[ae,ie]=X.useState(null),[de,ye]=X.useState(!1),[Ie,ve]=X.useState("pcb"),[ue,Se]=X.useState(null),[he,De]=X.useState(!1);X.useEffect(()=>{Se(null)},[m]);const Ge=X.useCallback(()=>{E(),k(),q(),p(null)},[k,q,E]);X.useEffect(()=>{t||(Ge(),h(""),ye(!1),ie(null),Se(null))},[t,Ge]),X.useEffect(()=>{h(""),p(null),u==="tscircuit.com"?E():u==="jlcpcb"?k():u==="kicad"&&q()},[u,k,q,E]);const Ye=ze=>{p(ze),ie(ze),ve("pcb"),ye(!0),re();const je=ze.package.org_owner_tscircuit_handle,it=ze.package.unscoped_name;if(je&&it){const at=it.split("/").pop()??it;ee(je,at)}},fe=async()=>{_.trim()&&(p(null),u==="tscircuit.com"?await I(_):u==="jlcpcb"?await R(_):u==="kicad"&&await J(_))},qe=async ze=>{try{if(Se(null),De(!0),ze.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:ze,footprint:ze.footprint.qualifiedName})}else if(ze.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const je=await SSo(ze.component.partNumber,{headers:n,apiBase:s});await r({result:ze,tsx:je})}else if(ze.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const je=ze.package.org_owner_tscircuit_handle,it=ze.package.unscoped_name;if(!je||!it)throw new Error("Missing package metadata");const at=it.split("/").pop()??it,At=`@tsci/${je}.${at}`;await i({result:ze,fullPackageName:At})}return!0}catch(je){return console.error("Failed to import component",je),Se(je instanceof Error?je.message:"Failed to import component"),!1}finally{De(!1)}};let Le=[],Qe=!1,Ue=null,we=!1;u==="tscircuit.com"?(Le=g,Qe=f,Ue=y,we=C):u==="jlcpcb"?(Le=b,Qe=P,Ue=B,we=M):u==="kicad"&&(Le=H,Qe=F,Ue=G,we=W);const Ee=async()=>{if(!m)return;await qe(m)&&(e(),Ge(),h(""))},Fe=ze=>{ze||e()},Me=ze=>{ye(ze),ze||ie(null)};return K.jsxs(rT,{open:t,onOpenChange:Fe,children:[K.jsxs(eM,{style:{width:"calc(100vw - 2rem)",zIndex:HPt.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[K.jsxs(tM,{children:[K.jsxs(nM,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",A?Nte[u].label:""," ","Component"]}),K.jsx(sT,{className:"rf-text-sm",children:l?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),l?K.jsxs(Lpe,{value:u,onValueChange:ze=>d(ze),className:"rf-min-w-0 rf-w-full",children:[!A&&K.jsx(UJ,{className:"rf-flex rf-w-full rf-gap-2",children:c.map(ze=>K.jsx(B4,{value:ze,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Nte[ze].label},ze))}),K.jsx(PSo,{query:_,placeholder:Nte[u].placeholder,isSearching:Qe,onQueryChange:h,onSubmit:fe}),K.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:Qe?K.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[K.jsx(W4,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),K.jsx("p",{children:"Searching..."})]}):Le.length>0?K.jsx(QSo,{results:Le,selected:m,onSelect:p,onShowDetails:u==="tscircuit.com"?Ye:void 0}):K.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:Ue?`Error: ${Ue}`:we?Nte[u].emptyMessage:"Enter a search term to find components"})})]}):null,ue?K.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:ue}):null,K.jsxs(RO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(_l,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),K.jsx(_l,{onClick:Ee,disabled:!m||he,className:"rf-order-1 sm:rf-order-2",children:he?K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),K.jsx(TSo,{packageResult:ae,isOpen:de,onOpenChange:Me,isLoading:le,details:oe,previewTab:Ie,onPreviewTabChange:ze=>ve(ze),isSubmitting:he,onImport:()=>{ae&&qe(ae).then(ze=>{ze&&(ye(!1),e(),Ge(),h(""))})}})]})},M3o=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},ZPt=t=>{const e=x0(s=>s.pushEvent),n=x0(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const l=s.package.unscoped_name??s.package.name;await na.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${l}"`,success:`Install requested for "${l}"`,error:A=>`Failed to request install: ${A instanceof Error?A.message:String(A)}`})},i=async({footprint:s})=>{await na.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 l=`imports/${M3o(a)}.tsx`;await na.promise(n(l,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${l}"`,error:A=>`Failed to import component: ${A instanceof Error?A.message:String(A)}`})};return K.jsx(B3o,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};ZPt.displayName="ImportComponentDialogForCli";var qve={exports:{}},evt;function w3o(){return evt||(evt=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(A,u){if(!r[A]){if(!i[A]){var d=typeof WS=="function"&&WS;if(!u&&d)return d(A,!0);if(c)return c(A,!0);var _=new Error("Cannot find module '"+A+"'");throw _.code="MODULE_NOT_FOUND",_}var h=r[A]={exports:{}};i[A][0].call(h.exports,function(m){var p=i[A][1][m];return a(p||m)},h,h.exports,o,i,r,s)}return r[A].exports}for(var c=typeof WS=="function"&&WS,l=0;l<s.length;l++)a(s[l]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(l){for(var A,u,d,_,h,m,p,g=[],f=0,y=l.length,C=y,I=s.getTypeOf(l)!=="string";f<l.length;)C=y-f,d=I?(A=l[f++],u=f<y?l[f++]:0,f<y?l[f++]:0):(A=l.charCodeAt(f++),u=f<y?l.charCodeAt(f++):0,f<y?l.charCodeAt(f++):0),_=A>>2,h=(3&A)<<4|u>>4,m=1<C?(15&u)<<2|d>>6:64,p=2<C?63&d:64,g.push(c.charAt(_)+c.charAt(h)+c.charAt(m)+c.charAt(p));return g.join("")},r.decode=function(l){var A,u,d,_,h,m,p=0,g=0,f="data:";if(l.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var y,C=3*(l=l.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(l.charAt(l.length-1)===c.charAt(64)&&C--,l.charAt(l.length-2)===c.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(y=a.uint8array?new Uint8Array(0|C):new Array(0|C);p<l.length;)A=c.indexOf(l.charAt(p++))<<2|(_=c.indexOf(l.charAt(p++)))>>4,u=(15&_)<<4|(h=c.indexOf(l.charAt(p++)))>>2,d=(3&h)<<6|(m=c.indexOf(l.charAt(p++))),y[g++]=A,h!==64&&(y[g++]=u),m!==64&&(y[g++]=d);return y}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),c=o("./stream/Crc32Probe"),l=o("./stream/DataLengthProbe");function A(u,d,_,h,m){this.compressedSize=u,this.uncompressedSize=d,this.crc32=_,this.compression=h,this.compressedContent=m}A.prototype={getContentWorker:function(){var u=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new l("data_length")),d=this;return u.on("end",function(){if(this.streamInfo.data_length!==d.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),u},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},A.createWorkerFrom=function(u,d,_){return u.pipe(new c).pipe(new l("uncompressedSize")).pipe(d.compressWorker(_)).pipe(new l("compressedSize")).withStreamInfo("compression",d)},i.exports=A},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var c,l=[],A=0;A<256;A++){c=A;for(var u=0;u<8;u++)c=1&c?3988292384^c>>>1:c>>>1;l[A]=c}return l})();i.exports=function(c,l){return c!==void 0&&c.length?s.getTypeOf(c)!=="string"?(function(A,u,d,_){var h=a,m=_+d;A^=-1;for(var p=_;p<m;p++)A=A>>>8^h[255&(A^u[p])];return-1^A})(0|l,c,c.length,0):(function(A,u,d,_){var h=a,m=_+d;A^=-1;for(var p=_;p<m;p++)A=A>>>8^h[255&(A^u.charCodeAt(p))];return-1^A})(0|l,c,c.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),c=o("./utils"),l=o("./stream/GenericWorker"),A=s?"uint8array":"array";function u(d,_){l.call(this,"FlateWorker/"+d),this._pako=null,this._pakoAction=d,this._pakoOptions=_,this.meta={}}r.magic="\b\0",c.inherits(u,l),u.prototype.processChunk=function(d){this.meta=d.meta,this._pako===null&&this._createPako(),this._pako.push(c.transformTo(A,d.data),!1)},u.prototype.flush=function(){l.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},u.prototype.cleanUp=function(){l.prototype.cleanUp.call(this),this._pako=null},u.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var d=this;this._pako.onData=function(_){d.push({data:_,meta:d.meta})}},r.compressWorker=function(d){return new u("Deflate",d)},r.uncompressWorker=function(){return new u("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(h,m){var p,g="";for(p=0;p<m;p++)g+=String.fromCharCode(255&h),h>>>=8;return g}function a(h,m,p,g,f,y){var C,I,E=h.file,b=h.compression,P=y!==A.utf8encode,B=c.transformTo("string",y(E.name)),M=c.transformTo("string",A.utf8encode(E.name)),R=E.comment,k=c.transformTo("string",y(R)),H=c.transformTo("string",A.utf8encode(R)),F=M.length!==E.name.length,G=H.length!==R.length,W="",J="",q="",oe=E.dir,le=E.date,ee={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(ee.crc32=h.crc32,ee.compressedSize=h.compressedSize,ee.uncompressedSize=h.uncompressedSize);var re=0;m&&(re|=8),P||!F&&!G||(re|=2048);var ae=0,ie=0;oe&&(ae|=16),f==="UNIX"?(ie=798,ae|=(function(ye,Ie){var ve=ye;return ye||(ve=Ie?16893:33204),(65535&ve)<<16})(E.unixPermissions,oe)):(ie=20,ae|=(function(ye){return 63&(ye||0)})(E.dosPermissions)),C=le.getUTCHours(),C<<=6,C|=le.getUTCMinutes(),C<<=5,C|=le.getUTCSeconds()/2,I=le.getUTCFullYear()-1980,I<<=4,I|=le.getUTCMonth()+1,I<<=5,I|=le.getUTCDate(),F&&(J=s(1,1)+s(u(B),4)+M,W+="up"+s(J.length,2)+J),G&&(q=s(1,1)+s(u(k),4)+H,W+="uc"+s(q.length,2)+q);var de="";return de+=`
5793
+ `,u=new Blob([A],{type:"text/plain"}),d=URL.createObjectURL(u),_=document.createElement("a");_.href=d,_.download=`${l}.test.ts`,_.click(),URL.revokeObjectURL(d)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}o(!1)};return K.jsxs("div",{className:`relative ${e}`,ref:i,children:[K.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>o(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&K.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download JSON"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),K.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},q3t=t=>t.activeSubSolver?[t,...q3t(t.activeSubSolver)]:[t],Mbo=({solver:t})=>{const e=q3t(t);return K.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,o)=>K.jsxs("div",{className:"flex items-center",children:[o>0&&K.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),K.jsx(Bbo,{solver:n})]},n.constructor.name))})},wbo=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:o,onSolverCompleted:i})=>{const[r,s]=X.useReducer(m=>!m,!1),a=X.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(o&&o(t),t.solve(),e(),i&&i(t))},A=()=>{r?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},u=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const p=m.getCurrentPhase();for(;m.getCurrentPhase()===p&&!t.solved&&!t.failed;)t.step();e()}},d=()=>{if(t.solved||t.failed||r)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const p=Number(m);if(!Number.isFinite(p)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<p&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};X.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),X.useEffect(()=>{(t.solved||t.failed)&&r&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,r]);const _=t.getCurrentPhase!==void 0,h=_?t.getCurrentPhase():null;return K.jsxs("div",{className:"space-y-2 p-2 border-b",children:[K.jsx("div",{className:"flex items-center",children:K.jsx(Mbo,{solver:t})}),K.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[K.jsx("button",{onClick:c,disabled:t.solved||t.failed||r,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),K.jsx("button",{onClick:l,disabled:t.solved||t.failed||r,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),K.jsx("button",{onClick:A,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${r?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:r?"Stop":"Animate"}),K.jsx("button",{onClick:d,disabled:t.solved||t.failed||r,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),_&&K.jsx("button",{onClick:u,disabled:t.solved||t.failed||r,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),K.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),h&&K.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",K.jsx("span",{className:"font-medium",children:h})]}),t.solved&&K.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&K.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&K.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},Dbo=(t,e,n)=>{const o=t.currentPipelineStepIndex;return e<o?"Completed":e===o&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},Qbo=(t,e)=>{const o=t.pipelineDef[e].solverName,i=Dbo(t,e),r=t[o],s=t.firstIterationOfPhase?.[o]??null,a=t.iterations;let c=0;if(i==="Completed"){const d=t.pipelineDef[e+1],_=d?t.firstIterationOfPhase?.[d.solverName]:void 0;_!==void 0&&s!==null?c=_-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[o]??0;let A=0;i==="Completed"?A=1:i==="In Progress"&&r&&(A=r.progress??0);const u=r?.stats??null;return{index:e,name:o,status:i,firstIteration:s,iterations:c,progress:A,timeSpent:l,stats:u&&Object.keys(u).length>0?u:null,solverInstance:r??null}},Tbo=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return K.jsx("span",{className:`font-medium ${e[t]}`,children:t})},Rbo=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:K.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),K.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},Nbo=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),kbo=({stats:t})=>{if(!t||Object.keys(t).length===0)return K.jsx("span",{children:"-"});const e=Object.entries(t),n=Nbo(t);return K.jsxs("details",{className:"cursor-pointer",children:[K.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),K.jsx("div",{className:"mt-1 text-xs",children:e.map(([o,i])=>K.jsxs("div",{children:[o,": ",String(i)]},o))})]})},Eve=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Eve);const e={};for(const[n,o]of Object.entries(t))n.startsWith("_")||(e[n]=Eve(o));return e},Lbo=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Eve(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)}`)}},Hbo=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const o=t.pipelineDef.map((a,c)=>Qbo(t,c)),i=a=>{e?.(a)},r=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):Lbo(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return K.jsxs("div",{className:"border-t border-gray-200",children:[K.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:K.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),K.jsx("div",{className:"overflow-x-auto",children:K.jsxs("table",{className:"w-full text-sm",children:[K.jsx("thead",{children:K.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),K.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",K.jsx("sub",{children:"0"})]}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),K.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),K.jsx("tbody",{children:o.map(a=>K.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[K.jsx("td",{className:"px-4 py-2",children:K.jsxs("div",{className:"flex items-center gap-2",children:[K.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),K.jsx("button",{onClick:()=>i(a.name),disabled:a.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 ${a.name} completes`,children:K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),K.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Tbo,{status:a.status})}),K.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),K.jsx("td",{className:"px-4 py-2",children:K.jsx(Rbo,{progress:a.progress})}),K.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),K.jsx("td",{className:"px-4 py-2 text-gray-500",children:K.jsx(kbo,{stats:a.stats})}),K.jsx("td",{className:"px-4 py-2",children:a.solverInstance?K.jsxs("button",{onClick:()=>r(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[K.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:K.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),K.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},Fbo=class extends Ur.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function Obo({graphics:t}){const e=t.points??[],n=t.lines??[],o=t.rects??[],i=t.circles??[],r=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const A=(p,g)=>{typeof p=="number"&&(p<s&&(s=p),p>c&&(c=p)),typeof g=="number"&&(g<a&&(a=g),g>l&&(l=g))};for(const p of e)A(p.x,p.y);for(const p of n){const g=p.points??[];for(const f of g)A(f.x,f.y)}for(const p of o){const g=p.x??0,f=p.y??0,y=p.width??0,C=p.height??0;A(g,f),A(g+y,f+C)}for(const p of i){const g=p.x??0,f=p.y??0,y=p.radius??1;A(g-y,f-y),A(g+y,f+y)}for(const p of r)A(p.x,p.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const u=10,d=s-u,_=a-u,h=Math.max(1,c-s+2*u),m=Math.max(1,l-a+2*u);return K.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${d} ${_} ${h} ${m}`,role:"img","aria-label":"Graphics fallback",children:[o.map((p,g)=>K.jsx("rect",{x:p.x??0,y:p.y??0,width:p.width??0,height:p.height??0,fill:"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`rect-${g}`)),n.map((p,g)=>K.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-${g}`)),i.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.fillColor??"none",stroke:p.strokeColor??"black",strokeWidth:p.strokeWidth??1},`circle-${g}`)),e.map((p,g)=>K.jsx("circle",{cx:p.x??0,cy:p.y??0,r:p.radius??1.5,fill:p.color??"black"},`point-${g}`)),r.map((p,g)=>K.jsx("text",{x:p.x??0,y:p.y??0,fontSize:p.fontSize??10,fill:p.color??"black",children:p.text??""},`text-${g}`))]})}var Gbo=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:o})=>{const[i,r]=X.useReducer(A=>A+1,0),s=X.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(A){return console.error("Visualization error:",A),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=X.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);X.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const A=document.createElement("script");A.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(A)}},[]);const c=t.pipelineDef!==void 0,l=A=>{const u=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&u.currentPipelineStepIndex<=u.pipelineDef.findIndex(d=>d.solverName===A);)t.step();r()}};return K.jsxs("div",{children:[K.jsx(wbo,{solver:t,triggerRender:r,animationSpeed:e,onSolverStarted:n,onSolverCompleted:o}),a?K.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):K.jsx(Fbo,{fallback:K.jsx(Obo,{graphics:s}),children:K.jsx(vbo,{graphics:s})}),c&&K.jsx(Hbo,{solver:t,onStepUntilPhase:l})]})};const Ubo=()=>{X.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)},[])},zbo=t=>t.toLowerCase().includes("pack")?muo:t.toLowerCase().includes("rout")?Cuo:euo,Vbo=({solverEvents:t=[]})=>{const[e,n]=X.useState(null);Ubo();const o=X.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=X.useMemo(()=>Array.from(o.keys()),[o]),r=e?o.get(e):null,s=X.useMemo(()=>{if(!r)return{instance:null,error:null,classFound:!1};const a=Sme[r.solverName];if(!a)return{instance:null,error:`Solver class "${r.solverName}" not found in SOLVERS registry. Available: ${Object.keys(Sme).join(", ")}`,classFound:!1};try{const c=r.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[r]);return t.length===0?K.jsx("div",{className:"rf-p-4",children:K.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:K.jsxs("div",{className:"rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),K.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):K.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[K.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[K.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=o.get(a),l=e===a;return K.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const A=zbo(c.solverName);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[K.jsx(A,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),K.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),K.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:r?s.instance?K.jsx(J2,{fallback:K.jsx("div",{className:"rf-p-4",children:K.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),K.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",r.solverName]})]})}),children:K.jsx(Gbo,{solver:s.instance})}):K.jsxs("div",{className:"rf-p-4",children:[K.jsxs("div",{className:"rf-mb-4",children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:r.solverName}),K.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",r.componentName]})]}),s.error&&K.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:K.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),K.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[K.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:K.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),K.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:K.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(r.solverParams,null,2)})})]})]}):K.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},$3t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{X.useEffect(()=>{if(t){const o=new Error(t);e&&(o.stack=e);try{eD.captureException(o)}catch{}}},[t,e]),X.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{eD.captureException(i,{error_type:o.type})}catch{}}},[n])},Z3t=t=>{X.useEffect(()=>{try{l9n(t)}catch{}},[t.source,t.component,t.isWebEmbedded,t.activeTab])},ePt="0.0.2117",Ybo={version:ePt},vte=tot()(not(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:e=>{t({lastRunEvalVersion:e})}}),{name:"runframe-runner-store"})),Kbo=t=>{const[e,n]=X.useState([]),[o,i]=X.useState(null),[r,s]=X.useState(""),[a,c]=Tw("eval-version-selection",null),l=vte(_=>_.setLastRunEvalVersion),A=vte(_=>_.lastRunEvalVersion);return X.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(_=>_.json()).then(_=>{if(Array.isArray(_?.versions)){let h=[..._.versions];_.tags?.latest&&(i(_.tags.latest),h=h.filter(m=>m!==_.tags.latest)),n(h)}}).catch(()=>{})},[t]),X.useEffect(()=>{t&&(a?(window.TSCIRCUIT_LATEST_EVAL_VERSION=a,l(a)):o&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=o,l(o)))},[t,a,o]),{versions:X.useMemo(()=>e.filter(_=>_.includes(r)).slice(0,50),[e,r]),latestVersion:o,lastRunEvalVersion:A,search:r,setSearch:s,selectVersion:_=>{c(_),s("")}}},Wbo=({snippetNames:t,onSelect:e,onCancel:n,isOpen:o})=>{const[i,r]=X.useState(""),[s,a]=X.useState("");if(!o)return null;const c=t.filter(u=>u.toLowerCase().includes(s.toLowerCase())),l=s&&!t.includes(s),A=u=>{u.key==="Enter"&&(c.length===1?r(c[0]):l&&r(s))};return K.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:K.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[K.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),K.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:u=>a(u.target.value),onKeyDown:A}),K.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[c.map(u=>K.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${i===u?"bg-blue-50":""}`,onClick:()=>r(u),children:u},u)),l&&K.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${i===s?"bg-blue-50":""}`,onClick:()=>r(s),children:['Create new "',s,'"']})]}),K.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:n,children:"Cancel"}),K.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>i&&e(i),disabled:!i,children:i===s?`Create "${i}"`:`Save to ${i}`})]})]})})},jbo=t=>{const e=X.useRef(null),n=x0(o=>o.recentEvents);X.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 Bte="Dialog",[tPt,nPt]=zI(Bte),[Xbo,m5]=tPt(Bte),Mte=t=>{const{__scopeDialog:e,children:n,open:o,defaultOpen:i,onOpenChange:r,modal:s=!0}=t,a=X.useRef(null),c=X.useRef(null),[l,A]=uP({prop:o,defaultProp:i??!1,onChange:r,caller:Bte});return K.jsx(Xbo,{scope:e,triggerRef:a,contentRef:c,contentId:hp(),titleId:hp(),descriptionId:hp(),open:l,onOpenChange:A,onOpenToggle:X.useCallback(()=>A(u=>!u),[A]),modal:s,children:n})};Mte.displayName=Bte;var oPt="DialogTrigger",iPt=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(oPt,n),r=I0(e,i.triggerRef);return K.jsx(Na.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":Pve(i.open),...o,ref:r,onClick:br(t.onClick,i.onOpenToggle)})});iPt.displayName=oPt;var bve="DialogPortal",[Jbo,rPt]=tPt(bve,{forceMount:void 0}),wte=t=>{const{__scopeDialog:e,forceMount:n,children:o,container:i}=t,r=m5(bve,e);return K.jsx(Jbo,{scope:e,forceMount:n,children:X.Children.map(o,s=>K.jsx(ux,{present:n||r.open,children:K.jsx(XZ,{asChild:!0,container:i,children:s})}))})};wte.displayName=bve;var Dte="DialogOverlay",DO=X.forwardRef((t,e)=>{const n=rPt(Dte,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=m5(Dte,t.__scopeDialog);return r.modal?K.jsx(ux,{present:o||r.open,children:K.jsx($bo,{...i,ref:e})}):null});DO.displayName=Dte;var qbo=w6("DialogOverlay.RemoveScroll"),$bo=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(Dte,n),r=kuo(),s=I0(e,r);return K.jsx(oee,{as:qbo,allowPinchZoom:!0,shards:[i.contentRef],children:K.jsx(Na.div,{"data-state":Pve(i.open),...o,ref:s,style:{pointerEvents:"auto",...o.style}})})}),iT="DialogContent",QO=X.forwardRef((t,e)=>{const n=rPt(iT,t.__scopeDialog),{forceMount:o=n.forceMount,...i}=t,r=m5(iT,t.__scopeDialog);return K.jsx(ux,{present:o||r.open,children:r.modal?K.jsx(Zbo,{...i,ref:e}):K.jsx(eSo,{...i,ref:e})})});QO.displayName=iT;var Zbo=X.forwardRef((t,e)=>{const n=m5(iT,t.__scopeDialog),o=X.useRef(null),i=I0(e,n.contentRef,o);return X.useEffect(()=>{const r=o.current;if(r)return b3e(r)},[]),K.jsx(sPt,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:br(t.onCloseAutoFocus,r=>{r.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:br(t.onPointerDownOutside,r=>{const s=r.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&r.preventDefault()}),onFocusOutside:br(t.onFocusOutside,r=>r.preventDefault())})}),eSo=X.forwardRef((t,e)=>{const n=m5(iT,t.__scopeDialog),o=X.useRef(!1),i=X.useRef(!1);return K.jsx(sPt,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:r=>{t.onCloseAutoFocus?.(r),r.defaultPrevented||(o.current||n.triggerRef.current?.focus(),r.preventDefault()),o.current=!1,i.current=!1},onInteractOutside:r=>{t.onInteractOutside?.(r),r.defaultPrevented||(o.current=!0,r.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=r.target;n.triggerRef.current?.contains(s)&&r.preventDefault(),r.detail.originalEvent.type==="focusin"&&i.current&&r.preventDefault()}})}),sPt=X.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:r,...s}=t,a=m5(iT,n);return o3e(),K.jsx(K.Fragment,{children:K.jsx(kZ,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:i,onUnmountAutoFocus:r,children:K.jsx(vF,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Pve(a.open),...s,ref:e,deferPointerDownOutside:!0,onDismiss:()=>a.onOpenChange(!1)})})})}),aPt="DialogTitle",Qte=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(aPt,n);return K.jsx(Na.h2,{id:i.titleId,...o,ref:e})});Qte.displayName=aPt;var cPt="DialogDescription",Tte=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(cPt,n);return K.jsx(Na.p,{id:i.descriptionId,...o,ref:e})});Tte.displayName=cPt;var lPt="DialogClose",Sve=X.forwardRef((t,e)=>{const{__scopeDialog:n,...o}=t,i=m5(lPt,n);return K.jsx(Na.button,{type:"button",...o,ref:e,onClick:br(t.onClick,()=>i.onOpenChange(!1))})});Sve.displayName=lPt;function Pve(t){return t?"open":"closed"}var APt="AlertDialog",[tSo]=zI(APt,[nPt]),jb=nPt(),uPt=t=>{const{__scopeAlertDialog:e,...n}=t,o=jb(e);return K.jsx(Mte,{...o,...n,modal:!0})};uPt.displayName=APt;var nSo="AlertDialogTrigger",oSo=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(iPt,{...i,...o,ref:e})});oSo.displayName=nSo;var iSo="AlertDialogPortal",dPt=t=>{const{__scopeAlertDialog:e,...n}=t,o=jb(e);return K.jsx(wte,{...o,...n})};dPt.displayName=iSo;var rSo="AlertDialogOverlay",hPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(DO,{...i,...o,ref:e})});hPt.displayName=rSo;var _Pt="AlertDialogContent",[sSo,aSo]=tSo(_Pt),mPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,children:o,...i}=t,r=jb(n),s=X.useRef(null),a=I0(e,s),c=X.useRef(null);return K.jsx(sSo,{scope:n,cancelRef:c,children:K.jsx(QO,{role:"alertdialog",...r,...i,ref:a,onOpenAutoFocus:br(i.onOpenAutoFocus,l=>{l.preventDefault(),c.current?.focus({preventScroll:!0})}),onPointerDownOutside:l=>l.preventDefault(),onInteractOutside:l=>l.preventDefault(),children:o})})});mPt.displayName=_Pt;var cSo="AlertDialogTitle",gPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(Qte,{...i,...o,ref:e})});gPt.displayName=cSo;var lSo="AlertDialogDescription",pPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(Tte,{...i,...o,ref:e})});pPt.displayName=lSo;var ASo="AlertDialogAction",fPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,i=jb(n);return K.jsx(Sve,{...i,...o,ref:e})});fPt.displayName=ASo;var yPt="AlertDialogCancel",CPt=X.forwardRef((t,e)=>{const{__scopeAlertDialog:n,...o}=t,{cancelRef:i}=aSo(yPt,n),r=jb(n),s=I0(e,i);return K.jsx(Sve,{...r,...o,ref:s})});CPt.displayName=yPt;var uSo=uPt,dSo=dPt,xPt=hPt,IPt=mPt,EPt=fPt,bPt=CPt,SPt=gPt,PPt=pPt;const vPt=uSo,hSo=dSo,BPt=X.forwardRef(({className:t,...e},n)=>K.jsx(xPt,{className:Hi("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}));BPt.displayName=xPt.displayName;const vve=X.forwardRef(({className:t,...e},n)=>K.jsxs(hSo,{children:[K.jsx(BPt,{}),K.jsx(IPt,{ref:n,className:Hi("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})]}));vve.displayName=IPt.displayName;const Bve=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});Bve.displayName="AlertDialogHeader";const Mve=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});Mve.displayName="AlertDialogFooter";const wve=X.forwardRef(({className:t,...e},n)=>K.jsx(SPt,{ref:n,className:Hi("rf-text-lg rf-font-semibold",t),...e}));wve.displayName=SPt.displayName;const Dve=X.forwardRef(({className:t,...e},n)=>K.jsx(PPt,{ref:n,className:Hi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));Dve.displayName=PPt.displayName;const _So=X.forwardRef(({className:t,...e},n)=>K.jsx(EPt,{ref:n,className:Hi(bQ(),t),...e}));_So.displayName=EPt.displayName;const Qve=X.forwardRef(({className:t,...e},n)=>K.jsx(bPt,{ref:n,className:Hi(bQ({variant:"outline"}),"rf-mt-2 sm:rf-mt-0",t),...e}));Qve.displayName=bPt.displayName;function mSo(t){const e=X.useRef({value:t,previous:t});return X.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var Rte="Checkbox",[gSo]=zI(Rte),[pSo,Tve]=gSo(Rte);function fSo(t){const{__scopeCheckbox:e,checked:n,children:o,defaultChecked:i,disabled:r,form:s,name:a,onCheckedChange:c,required:l,value:A="on",internal_do_not_use_render:u}=t,[d,_]=uP({prop:n,defaultProp:i??!1,onChange:c,caller:Rte}),[h,m]=X.useState(null),[p,g]=X.useState(null),f=X.useRef(!1),y=h?!!s||!!h.closest("form"):!0,C={checked:d,disabled:r,setChecked:_,control:h,setControl:m,name:a,form:s,value:A,hasConsumerStoppedPropagationRef:f,required:l,defaultChecked:gv(i)?!1:i,isFormControl:y,bubbleInput:p,setBubbleInput:g};return K.jsx(pSo,{scope:e,...C,children:ySo(u)?u(C):o})}var MPt="CheckboxTrigger",wPt=X.forwardRef(({__scopeCheckbox:t,onKeyDown:e,onClick:n,...o},i)=>{const{control:r,value:s,disabled:a,checked:c,required:l,setControl:A,setChecked:u,hasConsumerStoppedPropagationRef:d,isFormControl:_,bubbleInput:h}=Tve(MPt,t),m=I0(i,A),p=X.useRef(c);return X.useEffect(()=>{const g=r?.form;if(g){const f=()=>u(p.current);return g.addEventListener("reset",f),()=>g.removeEventListener("reset",f)}},[r,u]),K.jsx(Na.button,{type:"button",role:"checkbox","aria-checked":gv(c)?"mixed":c,"aria-required":l,"data-state":NPt(c),"data-disabled":a?"":void 0,disabled:a,value:s,...o,ref:m,onKeyDown:br(e,g=>{g.key==="Enter"&&g.preventDefault()}),onClick:br(n,g=>{u(f=>gv(f)?!0:!f),h&&_&&(d.current=g.isPropagationStopped(),d.current||g.stopPropagation())})})});wPt.displayName=MPt;var Rve=X.forwardRef((t,e)=>{const{__scopeCheckbox:n,name:o,checked:i,defaultChecked:r,required:s,disabled:a,value:c,onCheckedChange:l,form:A,...u}=t;return K.jsx(fSo,{__scopeCheckbox:n,checked:i,defaultChecked:r,disabled:a,required:s,onCheckedChange:l,name:o,form:A,value:c,internal_do_not_use_render:({isFormControl:d})=>K.jsxs(K.Fragment,{children:[K.jsx(wPt,{...u,ref:e,__scopeCheckbox:n}),d&&K.jsx(RPt,{__scopeCheckbox:n})]})})});Rve.displayName=Rte;var DPt="CheckboxIndicator",QPt=X.forwardRef((t,e)=>{const{__scopeCheckbox:n,forceMount:o,...i}=t,r=Tve(DPt,n);return K.jsx(ux,{present:o||gv(r.checked)||r.checked===!0,children:K.jsx(Na.span,{"data-state":NPt(r.checked),"data-disabled":r.disabled?"":void 0,...i,ref:e,style:{pointerEvents:"none",...t.style}})})});QPt.displayName=DPt;var TPt="CheckboxBubbleInput",RPt=X.forwardRef(({__scopeCheckbox:t,...e},n)=>{const{control:o,hasConsumerStoppedPropagationRef:i,checked:r,defaultChecked:s,required:a,disabled:c,name:l,value:A,form:u,bubbleInput:d,setBubbleInput:_}=Tve(TPt,t),h=I0(n,_),m=mSo(r),p=CIt(o);X.useEffect(()=>{const f=d;if(!f)return;const y=window.HTMLInputElement.prototype,I=Object.getOwnPropertyDescriptor(y,"checked").set,E=!i.current;if(m!==r&&I){const b=new Event("click",{bubbles:E});f.indeterminate=gv(r),I.call(f,gv(r)?!1:r),f.dispatchEvent(b)}},[d,m,r,i]);const g=X.useRef(gv(r)?!1:r);return K.jsx(Na.input,{type:"checkbox","aria-hidden":!0,defaultChecked:s??g.current,required:a,disabled:c,name:l,value:A,form:u,...e,tabIndex:-1,ref:h,style:{...e.style,...p,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});RPt.displayName=TPt;function ySo(t){return typeof t=="function"}function gv(t){return t==="indeterminate"}function NPt(t){return gv(t)?"indeterminate":t?"checked":"unchecked"}const TO=X.forwardRef(({className:t,...e},n)=>K.jsx(Rve,{ref:n,className:Hi("rf-peer rf-h-4 rf-w-4 rf-shrink-0 rf-rounded-sm rf-border rf-border-zinc-200 rf-border-zinc-900 rf-shadow focus-visible:rf-outline-none focus-visible:rf-ring-1 focus-visible:rf-ring-zinc-950 disabled:rf-cursor-not-allowed disabled:rf-opacity-50 data-[state=checked]:rf-bg-zinc-900 data-[state=checked]:rf-text-zinc-50 dark:rf-border-zinc-800 dark:rf-border-zinc-50 dark:focus-visible:rf-ring-zinc-300 dark:data-[state=checked]:rf-bg-zinc-50 dark:data-[state=checked]:rf-text-zinc-900",t),...e,children:K.jsx(QPt,{className:Hi("rf-flex rf-items-center rf-justify-center rf-text-current"),children:K.jsx(Q8,{className:"rf-h-4 rf-w-4"})})}));TO.displayName=Rve.displayName;const rT=Mte,CSo=wte,kPt=X.forwardRef(({className:t,...e},n)=>K.jsx(DO,{className:Hi("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}));kPt.displayName=DO.displayName;const eM=X.forwardRef(({className:t,children:e,showOverlay:n=!0,...o},i)=>K.jsxs(CSo,{children:[K.jsx(kPt,{className:Hi(n?"":"rf-hidden")}),K.jsx(QO,{ref:i,className:Hi("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})]}));eM.displayName=QO.displayName;const tM=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col rf-space-y-2 rf-text-center sm:rf-text-left",t),...e});tM.displayName="DialogHeader";const RO=({className:t,...e})=>K.jsx("div",{className:Hi("rf-flex rf-flex-col-reverse sm:rf-flex-row sm:rf-justify-end sm:rf-space-x-2",t),...e});RO.displayName="DialogFooter";const nM=X.forwardRef(({className:t,...e},n)=>K.jsx(Qte,{ref:n,className:Hi("rf-text-lg rf-font-semibold",t),...e}));nM.displayName=Qte.displayName;const sT=X.forwardRef(({className:t,...e},n)=>K.jsx(Tte,{ref:n,className:Hi("rf-text-sm rf-text-zinc-500 dark:rf-text-zinc-400",t),...e}));sT.displayName=Tte.displayName;const Nte={"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"}},xSo="https://cdn.jsdelivr.net/npm/easyeda@latest/dist/browser/index.js";let Nve=null;const ISo=async()=>(Nve||(Nve=import(xSo)),Nve),ESo=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??[]},bSo=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}),SSo=async(t,e)=>{const{fetchEasyEDAComponent:n,convertRawEasyToTsx:o}=await ISo(),i=await n(t,{fetch:(r,s)=>fetch(`${e?.apiBase??M1}/proxy`,{...s,headers:{...s?.headers,"X-Target-Url":r.toString(),"X-Sender-Origin":s?.headers?.origin??"","X-Sender-Host":s?.headers?.host??"https://easyeda.com","X-Sender-Referer":s?.headers?.referer??"","X-Sender-User-Agent":s?.headers?.userAgent??"","X-Sender-Cookie":s?.headers?.cookie??"",authority:s?.headers?.authority??"","content-type":s?.headers?.["content-type"]??"",...e?.headers}})});return o({rawEasy:i})},PSo=({query:t,placeholder:e,isSearching:n,onQueryChange:o,onSubmit:i})=>{const r=X.useCallback(s=>{s.key==="Enter"&&(s.preventDefault(),i())},[i]);return K.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2 rf-mt-4",children:[K.jsxs("div",{className:"rf-relative rf-flex-grow",children:[K.jsx(e3e,{className:"rf-absolute rf-left-2 rf-top-2.5 rf-h-4 rf-w-4 rf-text-muted-foreground"}),K.jsx(VPe,{placeholder:e,className:"rf-pl-8",spellCheck:!1,autoComplete:"off",value:t,onChange:s=>o(s.target.value),onKeyDown:r})]}),K.jsx(_l,{onClick:i,disabled:n||t.trim().length<1,className:"sm:rf-px-4 rf-px-3",children:n?K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):K.jsxs(K.Fragment,{children:[K.jsx(e3e,{className:"rf-h-4 rf-w-4 sm:rf-hidden"}),K.jsx("span",{className:"rf-hidden sm:rf-inline",children:"Search"})]})})]})},vSo=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),BSo=t=>vSo.format(t),LPt=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"}},MSo=t=>{switch(t.source){case"tscircuit.com":return t.package.unscoped_name;case"jlcpcb":return t.component.manufacturer;case"kicad":return t.footprint.qualifiedName}},wSo=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}},DSo=t=>{switch(t.source){case"tscircuit.com":return t.package.name;case"jlcpcb":return t.component.partNumber;case"kicad":return}},QSo=({results:t,selected:e,onSelect:n,onShowDetails:o})=>{const i=e?LPt(e):null;return K.jsx("div",{className:"rf-divide-y rf-w-full rf-overflow-hidden",children:t.map(r=>{const s=LPt(r),a=i===s,c=MSo(r),l=wSo(r),A=DSo(r),u=r.source==="jlcpcb"?r.component.stock:null,d=r.source==="jlcpcb"?r.component.price:null,_=r.source==="jlcpcb"?r.component.isBasic:null;return K.jsxs("div",{className:`rf-p-3 rf-flex rf-flex-col sm:rf-grid sm:rf-grid-cols-[minmax(0,1fr)_auto] rf-items-start sm:rf-items-center rf-cursor-pointer hover:rf-bg-zinc-100 rf-gap-2 rf-overflow-hidden ${a?"rf-bg-zinc-100":""}`,onClick:()=>n(r),children:[K.jsxs("div",{className:"rf-min-w-0 rf-overflow-hidden rf-w-full",children:[K.jsxs("div",{className:"rf-flex rf-items-start rf-gap-2 rf-min-w-0",children:[K.jsxs("div",{className:"rf-font-medium rf-text-sm rf-truncate rf-flex-1 rf-min-w-0 rf-flex rf-items-center rf-gap-1.5",children:[c,r.source==="jlcpcb"&&_!=null&&K.jsx("span",{className:`rf-text-xs rf-px-1.5 rf-py-0.5 rf-rounded rf-font-medium rf-flex-shrink-0 ${_?"rf-bg-green-100 rf-text-green-700":"rf-bg-orange-100 rf-text-orange-700"}`,children:_?"Basic":"Extended"}),r.source==="tscircuit.com"&&r.package.is_private&&K.jsx(puo,{className:"rf-ml-1 rf-h-3 rf-w-3 rf-text-zinc-400 rf-flex-shrink-0"})]}),r.source==="jlcpcb"&&u!=null?K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 sm:rf-hidden",children:[u.toLocaleString()," in stock"]}):null]}),K.jsxs("div",{className:"rf-text-xs rf-text-zinc-500 rf-truncate rf-w-full",children:[A?K.jsx("span",{className:"rf-mr-2",children:A}):null,l]})]}),K.jsxs("div",{children:[r.source==="tscircuit.com"&&o?K.jsx("div",{className:"rf-flex-shrink-0 rf-w-full sm:rf-w-auto",children:K.jsx(_l,{variant:"outline",size:"sm",className:"rf-text-xs rf-w-full sm:rf-w-auto",onClick:h=>{h.stopPropagation(),o(r)},children:"See Details"})}):r.source==="jlcpcb"&&u!=null?K.jsxs("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0",children:[u.toLocaleString()," in stock"]}):null,d!=null&&K.jsx("div",{className:"rf-hidden sm:rf-block rf-text-xs rf-text-zinc-500 rf-font-medium rf-whitespace-nowrap rf-flex-shrink-0 rf-text-right",children:BSo(d)})]})]},s)})})},HPt={importComponentDialog:101,importComponentDetailsDialog:102},TSo=({packageResult:t,isOpen:e,onOpenChange:n,isLoading:o,details:i,previewTab:r,onPreviewTabChange:s,isSubmitting:a,onImport:c})=>{const l=t?.package??null,A=l?.latest_pcb_preview_image_url,u=l?.latest_sch_preview_image_url,d=l?.latest_cad_preview_image_url,_=l?.unscoped_name?.split("/").pop()??l?.unscoped_name,h=l?.org_owner_tscircuit_handle??void 0,m=h?`https://tscircuit.com/${h}`:void 0,p=h&&_?`https://tscircuit.com/${h}/${_}`:void 0;return K.jsx(rT,{open:e,onOpenChange:n,children:K.jsxs(eM,{showOverlay:!1,style:{width:"calc(100vw - 2rem)",zIndex:HPt.importComponentDetailsDialog},className:"rf-max-w-5xl no-scrollbar !rf-overflow-y-auto rf-max-h-[90vh] rf-overflow-hidden rf-flex rf-flex-col rf-rounded-sm",children:[K.jsx(tM,{className:"rf-pb-4 rf-border-b",children:K.jsx("div",{className:"rf-flex rf-items-start rf-justify-between rf-gap-4",children:K.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[K.jsx(nM,{className:"rf-text-xl rf-font-semibold rf-truncate",children:_}),K.jsx(sT,{children:l?.description})]})})}),K.jsxs("div",{className:"rf-flex-1 rf-overflow-y-auto rf-py-4 rf-space-y-6",children:[h?K.jsxs("div",{children:[K.jsx("span",{className:"rf-text-xs rf-font-medium rf-text-gray-500 rf-uppercase rf-tracking-wide",children:"Created by"}),K.jsx("div",{className:"rf-mt-1 rf-text-sm rf-font-medium",children:m?K.jsx("a",{href:m,target:"_blank",rel:"noopener noreferrer",className:"rf-text-black hover:rf-underline",children:h}):h})]}):null,(d||A||u)&&K.jsx(K.Fragment,{children:K.jsxs("div",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Preview"}),K.jsxs(Lpe,{value:r,onValueChange:g=>s(g),children:[K.jsxs(UJ,{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:[A&&K.jsx(B4,{value:"pcb",children:"PCB"}),u&&K.jsx(B4,{value:"schematic",children:"Schematic"}),d&&K.jsx(B4,{value:"3d",children:"3D"})]}),K.jsxs("div",{className:"rf-mt-4",children:[K.jsx(bf,{value:"pcb",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:A?K.jsx("img",{src:A,alt:`${_??"package"} PCB preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(bf,{value:"schematic",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:u?K.jsx("img",{src:u,alt:`${_??"package"} schematic preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null}),K.jsx(bf,{value:"3d",className:"rf-border rf-rounded-lg rf-overflow-hidden rf-bg-gray-50",children:d?K.jsx("img",{src:d,alt:`${_??"package"} 3D preview`,className:"rf-w-full rf-h-full rf-object-contain rf-bg-white rf-p-4"}):null})]})]})]})}),i?.ai_description?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"AI Description"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed",children:i.ai_description})})]}):null,i?.ai_usage_instructions?K.jsxs("section",{children:[K.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-mb-3",children:"Usage Instructions"}),K.jsx("div",{className:"rf-bg-gray-50 rf-border rf-border-gray-200 rf-rounded-lg rf-p-4",children:K.jsx("p",{className:"rf-text-sm rf-text-gray-700 rf-leading-relaxed rf-whitespace-pre-wrap",children:i.ai_usage_instructions})})]}):null,o?K.jsxs("div",{className:"rf-flex rf-justify-center rf-items-center rf-gap-2 rf-text-gray-500",children:[K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}),K.jsx("span",{className:"rf-text-sm",children:"Loading package details..."})]}):null]}),K.jsxs(RO,{className:"rf-pt-4 rf-border-t rf-flex rf-flex-col sm:rf-flex-row rf-justify-between rf-gap-2",children:[K.jsx("div",{className:"rf-flex-1",children:p?K.jsxs(_l,{variant:"outline",size:"sm",className:"rf-gap-2 rf-w-full sm:rf-w-auto",onClick:()=>window.open(p,"_blank"),children:[K.jsx(Auo,{className:"rf-h-4 rf-w-4"}),"View on tscircuit.com"]}):null}),K.jsxs("div",{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(_l,{variant:"outline",onClick:()=>n(!1),className:"rf-order-2 sm:rf-order-1",children:"Close"}),K.jsx(_l,{onClick:c,disabled:a,className:"rf-bg-blue-600 hover:rf-bg-blue-700",children:a?K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import Component"})]})]})]})})},RSo=()=>{const[t,e]=X.useState(null),[n,o]=X.useState(!1),i=X.useCallback(async(s,a)=>{o(!0);try{const c=await fetch(`https://api.tscircuit.com/packages/get?name=${encodeURIComponent(`${s}/${a}`)}`);if(!c.ok)throw new Error(`Failed to load package details: ${c.status}`);const l=await c.json();e(l.package??null)}catch(c){console.error("Failed to fetch package details",c),e(null)}finally{o(!1)}},[]),r=X.useCallback(()=>{e(null),o(!1)},[]);return{details:t,isLoading:n,fetchDetails:i,reset:r}},NSo=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??[]},kSo=({sessionToken:t})=>{const[e,n]=X.useState([]),[o,i]=X.useState(!1),[r,s]=X.useState(null),[a,c]=X.useState(!1),l=X.useCallback(async u=>{const d=u.trim();if(!d)return[];i(!0),s(null);try{const h=(await NSo(d,t)).map(m=>({source:"tscircuit.com",package:m}));return n(h),h}catch(_){return console.error("Error searching tscircuit packages",_),n([]),s(_ instanceof Error?_.message:"Failed to search tscircuit packages"),[]}finally{i(!1),c(!0)}},[t]),A=X.useCallback(()=>{n([]),i(!1),s(null),c(!1)},[]);return{results:e,isSearching:o,error:r,hasSearched:a,search:l,reset:A}},LSo=t=>{const e=t.trim();return/^C\d+/i.test(e)?e.replace(/^C/i,""):e},HSo=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),c=X.useCallback(async A=>{const u=LSo(A);if(!u)return[];o(!0),r(null);try{const _=(await ESo(u,10)).map(h=>({source:"jlcpcb",component:bSo(h)}));return e(_),_}catch(d){return console.error("Error searching JLCPCB components",d),e([]),r(d instanceof Error?d.message:"Failed to search JLCPCB components"),[]}finally{o(!1),a(!0)}},[]),l=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:l}};function pv(t){return Array.isArray?Array.isArray(t):OPt(t)==="[object Array]"}function FSo(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 kve(t){return t==null?"":FSo(t)}function U1(t){return typeof t=="string"}function kte(t){return typeof t=="number"}function OSo(t){return t===!0||t===!1||GSo(t)&&OPt(t)=="[object Boolean]"}function FPt(t){return typeof t=="object"}function GSo(t){return FPt(t)&&t!==null}function Tx(t){return t!=null}function Lte(t){return!t.trim().length}function OPt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const USo="Incorrect 'index' type",Lve="Invalid doc index: must be a non-negative integer within the bounds of the docs array",zSo=t=>`Invalid value for key ${t}`,VSo=t=>`Pattern length exceeds max of ${t}.`,YSo=t=>`Missing ${t} property in key`,KSo=t=>`Property 'weight' in key '${t}' must be a positive integer`,WSo="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.",GPt=Object.prototype.hasOwnProperty;var jSo=class{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{const o=UPt(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 UPt(t){let e=null,n=null,o=null,i=1,r=null;if(U1(t)||pv(t))o=t,e=zPt(t),n=Hte(t);else{if(!GPt.call(t,"name"))throw new Error(YSo("name"));const s=t.name;if(o=s,GPt.call(t,"weight")&&t.weight!==void 0&&(i=t.weight,i<=0))throw new Error(KSo(Hte(s)));e=zPt(s),n=Hte(s),r=t.getFn??null}return{path:e,id:n,weight:i,src:o,getFn:r}}function zPt(t){return pv(t)?t:t.split(".")}function Hte(t){return pv(t)?t.join("."):t}function XSo(t,e){const n=[];let o=!1;const i=(r,s,a,c)=>{if(Tx(r))if(!s[a])n.push(c!==void 0?{v:r,i:c}:r);else{const l=r[s[a]];if(!Tx(l))return;if(a===s.length-1&&(U1(l)||kte(l)||OSo(l)||typeof l=="bigint"))n.push(c!==void 0?{v:kve(l),i:c}:kve(l));else if(pv(l)){o=!0;for(let A=0,u=l.length;A<u;A+=1)i(l[A],s,a+1,A)}else s.length&&i(l,s,a+1,c)}};return i(t,U1(e)?e.split("."):e,0),o?n:n[0]}const bs=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:XSo,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}});function JSo(t=1,e=3){const n=new Map,o=Math.pow(10,e);return{get(i){let r=1,s=!1;for(let c=0;c<i.length;c++)i.charCodeAt(c)===32?s||(r++,s=!0):s=!1;if(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 Hve=class{constructor({getFn:t=bs.getFn,fieldNormWeight:e=bs.fieldNormWeight}={}){this.norm=JSo(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(U1(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(Lve);if(U1(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(Lve);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!Tx(t)||Lte(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(Tx(s)){if(pv(s)){const a=[];for(let c=0,l=s.length;c<l;c+=1){const A=s[c];if(Tx(A)){if(U1(A)){if(!Lte(A)){const u={v:A,i:c,n:this.norm.get(A)};a.push(u)}}else if(Tx(A.v)){const u=U1(A.v)?A.v:kve(A.v);if(!Lte(u)){const d={v:u,i:A.i,n:this.norm.get(u)};a.push(d)}}}}n.$[o]=a}else if(U1(s)&&!Lte(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 VPt(t,e,{getFn:n=bs.getFn,fieldNormWeight:o=bs.fieldNormWeight}={}){const i=new Hve({getFn:n,fieldNormWeight:o});return i.setKeys(t.map(UPt)),i.setSources(e),i.create(),i}function qSo(t,{getFn:e=bs.getFn,fieldNormWeight:n=bs.fieldNormWeight}={}){const{keys:o,records:i}=t,r=new Hve({getFn:e,fieldNormWeight:n});return r.setKeys(o),r.setIndexRecords(i),r}function $So(t=[],e=bs.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 ZSo(t,e,n,{location:o=bs.location,distance:i=bs.distance,threshold:r=bs.threshold,findAllMatches:s=bs.findAllMatches,minMatchCharLength:a=bs.minMatchCharLength,includeMatches:c=bs.includeMatches,ignoreLocation:l=bs.ignoreLocation}={}){if(e.length>32)throw new Error(VSo(32));const A=e.length,u=t.length,d=Math.max(0,Math.min(o,u));let _=r,h=d;const m=(B,M)=>{const R=B/A;if(l)return R;const k=Math.abs(d-M);return i?R+k/i:k?1:R},p=a>1||c,g=p?Array(u):[];let f;for(;(f=t.indexOf(e,h))>-1;){const B=m(0,f);if(_=Math.min(B,_),h=f+A,p){let M=0;for(;M<A;)g[f+M]=1,M+=1}}h=-1;let y=[],C=1,I=0,E=A+u;const b=1<<A-1;for(let B=0;B<A;B+=1){let M=0,R=E;for(;M<R;)m(B,d+R)<=_?M=R:E=R,R=Math.floor((E-M)/2+M);E=R;let k=Math.max(1,d-R+1);const H=s?u:Math.min(d+R,u)+A,F=Array(H+2);F[H+1]=(1<<B)-1;for(let G=H;G>=k;G-=1){const W=G-1,J=n[t[W]];if(F[G]=(F[G+1]<<1|1)&J,B&&(F[G]|=(y[G+1]|y[G])<<1|1|y[G+1]),F[G]&b&&(C=m(B,W),C<=_)){if(_=C,h=W,I=B,h<=d)break;k=Math.max(1,2*d-h)}}if(m(B+1,d)>_)break;y=F}if(p&&h>=0){const B=Math.min(u-1,h+A-1+I);for(let M=h;M<=B;M+=1)n[t[M]]&&(g[M]=1)}const P={isMatch:h>=0,score:Math.max(.001,C)};if(p){const B=$So(g,a);B.length?c&&(P.indices=B):P.isMatch=!1}return P}function e3o(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 Fve(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 YPt={ł:"l",Ł:"L",đ:"d",Đ:"D",ø:"o",Ø:"O",ħ:"h",Ħ:"H",ŧ:"t",Ŧ:"T",ı:"i",ß:"ss"},t3o=new RegExp("["+Object.keys(YPt).join("")+"]","g"),NO=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(t3o,e=>YPt[e]):t=>t;var Ove=class{constructor(t,{location:e=bs.location,threshold:n=bs.threshold,distance:o=bs.distance,includeMatches:i=bs.includeMatches,findAllMatches:r=bs.findAllMatches,minMatchCharLength:s=bs.minMatchCharLength,isCaseSensitive:a=bs.isCaseSensitive,ignoreDiacritics:c=bs.ignoreDiacritics,ignoreLocation:l=bs.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:o,includeMatches:i,findAllMatches:r,minMatchCharLength:s,isCaseSensitive:a,ignoreDiacritics:c,ignoreLocation:l},t=a?t:t.toLowerCase(),t=c?NO(t):t,this.pattern=t,this.chunks=[],!this.pattern.length)return;const A=(d,_)=>{this.chunks.push({pattern:d,alphabet:e3o(d),startIndex:_})},u=this.pattern.length;if(u>32){let d=0;const _=u%32,h=u-_;for(;d<h;)A(this.pattern.substr(d,32),d),d+=32;if(_){const m=u-32;A(this.pattern.substr(m),m)}}else A(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o}=this.options;if(t=e?t:t.toLowerCase(),t=n?NO(t):t,this.pattern===t){const h={isMatch:!0,score:0};return o&&(h.indices=[[0,t.length-1]]),h}const{location:i,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,ignoreLocation:l}=this.options,A=[];let u=0,d=!1;this.chunks.forEach(({pattern:h,alphabet:m,startIndex:p})=>{const{isMatch:g,score:f,indices:y}=ZSo(t,h,m,{location:i+p,distance:r,threshold:s,findAllMatches:a,minMatchCharLength:c,includeMatches:o,ignoreLocation:l});g&&(d=!0),u+=f,g&&y&&A.push(...y)});const _={isMatch:d,score:d?u/this.chunks.length:1};return d&&o&&(_.indices=Fve(A)),_}};const n3o=new Set(["fuzzy","include"]);function o3o(t){return t.startsWith("inverse")}const Gve=[{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 Ove(t,{location:e.location??bs.location,threshold:e.threshold??bs.threshold,distance:e.distance??bs.distance,includeMatches:e.includeMatches??bs.includeMatches,findAllMatches:e.findAllMatches??bs.findAllMatches,minMatchCharLength:e.minMatchCharLength??bs.minMatchCharLength,isCaseSensitive:e.isCaseSensitive??bs.isCaseSensitive,ignoreDiacritics:e.ignoreDiacritics??bs.ignoreDiacritics,ignoreLocation:e.ignoreLocation??bs.ignoreLocation});return{type:"fuzzy",search(o){return n.searchIn(o)}}}}],KPt=Gve.length,i3o="\0",r3o="|";function s3o(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 WPt(t,e){const n=t.match(e);return n?n[1]:null}function a3o(t,e={}){return t.replace(/\\\|/g,i3o).split(r3o).map(n=>{const o=s3o(n.replace(/\u0000/g,"|").trim()).filter(r=>r&&!!r.trim()),i=[];for(let r=0,s=o.length;r<s;r+=1){const a=o[r];let c=!1,l=-1;for(;!c&&++l<KPt;){const A=Gve[l],u=WPt(a,A.multiRegex);u&&(i.push(A.create(u,e)),c=!0)}if(!c)for(l=-1;++l<KPt;){const A=Gve[l],u=WPt(a,A.singleRegex);if(u){i.push(A.create(u,e));break}}}return i})}var c3o=class{constructor(t,{isCaseSensitive:e=bs.isCaseSensitive,ignoreDiacritics:n=bs.ignoreDiacritics,includeMatches:o=bs.includeMatches,minMatchCharLength:i=bs.minMatchCharLength,ignoreLocation:r=bs.ignoreLocation,findAllMatches:s=bs.findAllMatches,location:a=bs.location,threshold:c=bs.threshold,distance:l=bs.distance}={}){this.query=null,this.options={isCaseSensitive:e,ignoreDiacritics:n,includeMatches:o,minMatchCharLength:i,findAllMatches:s,ignoreLocation:r,location:a,threshold:c,distance:l},t=e?t:t.toLowerCase(),t=n?NO(t):t,this.pattern=t,this.query=a3o(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?NO(t):t;let r=0;const s=[];let a=0,c=!1;for(let l=0,A=e.length;l<A;l+=1){const u=e[l];s.length=0,r=0,c=!1;for(let d=0,_=u.length;d<_;d+=1){const h=u[d],{isMatch:m,indices:p,score:g}=h.search(t);if(m)r+=1,a+=g,o3o(h.type)&&(c=!0),n&&(n3o.has(h.type)?s.push(...p):s.push(p));else{a=0,r=0,s.length=0,c=!1;break}}if(r){const d={isMatch:!0,score:a/r};return c&&(d.hasInverse=!0),n&&(d.indices=Fve(s)),d}}return{isMatch:!1,score:1}}};const Uve=[];function zve(...t){Uve.push(...t)}function Fte(t,e){for(let n=0,o=Uve.length;n<o;n+=1){const i=Uve[n];if(i.condition(t,e))return new i(t,e)}return new Ove(t,e)}const Ote={AND:"$and",OR:"$or"},Vve={PATH:"$path",PATTERN:"$val"},Yve=t=>!!(t[Ote.AND]||t[Ote.OR]),l3o=t=>!!t[Vve.PATH],A3o=t=>!pv(t)&&FPt(t)&&!Yve(t),jPt=t=>({[Ote.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function XPt(t,e,{auto:n=!0}={}){const o=i=>{if(U1(i)){const c={keyId:null,pattern:i};return n&&(c.searcher=Fte(i,e)),c}const r=Object.keys(i),s=l3o(i);if(!s&&r.length>1&&!Yve(i))return o(jPt(i));if(A3o(i)){const c=s?i[Vve.PATH]:r[0],l=s?i[Vve.PATTERN]:i[c];if(!U1(l))throw new Error(zSo(c));const A={keyId:Hte(c),pattern:l};return n&&(A.searcher=Fte(l,e)),A}const a={children:[],operator:r[0]};return r.forEach(c=>{const l=i[c];pv(l)&&l.forEach(A=>{a.children.push(o(A))})}),a};return Yve(t)||(t=jPt(t)),o(t)}function Kve(t,{ignoreFieldNorm:e=bs.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 u3o(t,{ignoreFieldNorm:e=bs.ignoreFieldNorm}){t.forEach(n=>{n.score=Kve(n.matches,{ignoreFieldNorm:e})})}var d3o=class{constructor(t){this.limit=t,this.heap=[]}get size(){return this.heap.length}shouldInsert(t){return this.size<this.limit||t<this.heap[0].score}insert(t){this.size<this.limit?(this.heap.push(t),this._bubbleUp(this.size-1)):t.score<this.heap[0].score&&(this.heap[0]=t,this._sinkDown(0))}extractSorted(t){return this.heap.sort(t)}_bubbleUp(t){const e=this.heap;for(;t>0;){const n=t-1>>1;if(e[t].score<=e[n].score)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&&e[i].score>e[o].score&&(o=i),r<n&&e[r].score>e[o].score&&(o=r),o!==t){const s=e[t];e[t]=e[o],e[o]=s}}while(o!==t)}};function h3o(t){const e=[];return t.matches.forEach(n=>{if(!Tx(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 _3o(t,e,{includeMatches:n=bs.includeMatches,includeScore:o=bs.includeScore}={}){return t.map(i=>{const{idx:r}=i,s={item:e[r],refIndex:r};return n&&(s.matches=h3o(i)),o&&(s.score=i.score),s})}const m3o=/[\p{L}\p{M}\p{N}_]+/gu,JPt=new WeakSet;function g3o(t){JPt.has(t)||(JPt.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 p3o(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||g3o(t),e=>e.match(t)||[]):e=>e.match(m3o)||[]}function Wve({isCaseSensitive:t=!1,ignoreDiacritics:e=!1,tokenize:n}={}){const o=p3o(n);return{tokenize(i){return t||(i=i.toLowerCase()),e&&(i=NO(i)),o(i)}}}var f3o=class{static condition(t,e){return e.useTokenSearch}constructor(t,e){this.options=e,this.analyzer=Wve({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 Ove(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 l=0;l<this.termSearchers.length;l++){const A=this.termSearchers[l].searchIn(t),u=this.idfWeights[l];o+=u,A.isMatch&&(i++,n+=u*(1-A.score),A.indices&&e.push(...A.indices),this.combineAll&&(this.useMask?r|=1<<l:s.add(l)))}if(i===0)return{isMatch:!1,score:1};const a=o>0?1-n/o:0,c={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&e.length&&(c.indices=Fve(e)),this.combineAll&&(this.useMask?c.matchedMask=r:c.matchedTerms=s,c.termCount=this.numTerms),c}};function jve(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 qPt(t,e,n,o){const{i,v:r,$:s}=e;if(r!==void 0){jve(t,r,i,o);return}if(s)for(let a=0;a<n;a++){const c=s[a];if(c)if(Array.isArray(c))for(const l of c)jve(t,l.v,i,o);else jve(t,c.v,i,o)}}function y3o(t,e,n){const o={fieldCount:0,df:new Map,docFieldCount:new Map,docTermFieldHits:new Map};for(const i of t)qPt(o,i,e,n);return o}function C3o(t,e,n,o){qPt(t,e,n,o)}function x3o(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 $Pt(t,e){if(e.length===0)return;const n=Array.from(new Set(e)).sort((a,c)=>a-c);for(const a of n)x3o(t,a);const o=a=>{let c=0,l=n.length;for(;c<l;){const A=c+l>>>1;n[A]<a?c=A+1:l=A}return a-c},i=n[0],r=new Map;for(const[a,c]of t.docFieldCount)r.set(a>i?o(a):a,c);t.docFieldCount=r;const s=new Map;for(const[a,c]of t.docTermFieldHits)s.set(a>i?o(a):a,c);t.docTermFieldHits=s}var fv=class{constructor(t,e,n){this.options={...bs,...e},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new jSo(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=Fte(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 Hve))throw new Error(USo);if(this._myIndex=e||VPt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){const n=Wve({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});this._invertedIndex=y3o(this._myIndex.records,this._myIndex.keys.length,n)}this._invalidateSearcherCache()}add(t){if(!Tx(t))return;this._docs.push(t);const e=this._myIndex.add(t,this._docs.length-1);if(this._invertedIndex&&e){const n=Wve({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics,tokenize:this.options.tokenize});C3o(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&&$Pt(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(Lve);this._invertedIndex&&$Pt(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}search(t,e){const{limit:n=-1}=e||{},{includeMatches:o,includeScore:i,shouldSort:r,sortFn:s,ignoreFieldNorm:a}=this.options;if(U1(t)&&!t.trim()){let A=this._docs.map((u,d)=>({item:u,refIndex:d}));return kte(n)&&n>-1&&(A=A.slice(0,n)),A}const c=kte(n)&&n>0&&U1(t);let l;if(c){const A=new d3o(n);U1(this._docs[0])?this._searchStringList(t,{heap:A,ignoreFieldNorm:a}):this._searchObjectList(t,{heap:A,ignoreFieldNorm:a}),l=A.extractSorted(s)}else l=U1(t)?U1(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t),u3o(l,{ignoreFieldNorm:a}),r&&l.sort(s),kte(n)&&n>-1&&(l=l.slice(0,n));return _3o(l,this._docs,{includeMatches:o,includeScore:i})}_searchStringList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{records:r}=this._myIndex,s=e?null:[];return r.forEach(({v:a,i:c,n:l})=>{if(!Tx(a))return;const A=o.searchIn(a);if(A.isMatch){const u={score:A.score,value:a,norm:l,indices:A.indices};i&&(u.matchedMask=A.matchedMask,u.matchedTerms=A.matchedTerms,u.termCount=A.termCount);const d=[u];if(!i||this._coversAllTokens(d)){const _={item:a,idx:c,matches:d};e?(_.score=Kve(_.matches,{ignoreFieldNorm:n}),e.shouldInsert(_.score)&&e.insert(_)):s.push(_)}}}),s}_searchLogical(t){const e=XPt(t,this.options),n=(s,a,c)=>{if(!("children"in s)){const{keyId:d,searcher:_}=s;let h;return d===null?(h=[],this._myIndex.keys.forEach((m,p)=>{h.push(...this._findMatches({key:m,value:a[p],searcher:_}))})):h=this._findMatches({key:this._keyStore.get(d),value:this._myIndex.getValueForItemAtKeyId(a,d),searcher:_}),h&&h.length?[{idx:c,item:a,matches:h}]:[]}const{children:l,operator:A}=s,u=[];for(let d=0,_=l.length;d<_;d+=1){const h=l[d],m=n(h,a,c);if(m.length)u.push(...m);else if(A===Ote.AND)return[]}return u},o=this._myIndex.records,i=new Map,r=[];return o.forEach(({$:s,i:a})=>{if(Tx(s)){const c=n(e,s,a);c.length&&(i.has(a)||(i.set(a,{idx:a,item:s,matches:[]}),r.push(i.get(a))),c.forEach(({matches:l})=>{i.get(a).matches.push(...l)}))}}),r}_searchObjectList(t,{heap:e,ignoreFieldNorm:n}={}){const o=this._getSearcher(t),i=this.options.useTokenSearch&&this.options.tokenMatch==="all",{keys:r,records:s}=this._myIndex,a=e?null:[];return s.forEach(({$:c,i:l})=>{if(!Tx(c))return;const A=[];let u=!1,d=!1;if(r.forEach((_,h)=>{const m=this._findMatches({key:_,value:c[h],searcher:o});m.length?(A.push(...m),m[0].hasInverse&&(d=!0)):u=!0}),!(d&&u)&&A.length&&(!i||this._coversAllTokens(A))){const _={idx:l,item:c,matches:A};e?(_.score=Kve(_.matches,{ignoreFieldNorm:n}),e.shouldInsert(_.score)&&e.insert(_)):a.push(_)}}),a}_findMatches({key:t,value:e,searcher:n}){if(!Tx(e))return[];const o=[];if(pv(e))e.forEach(({v:i,i:r,n:s})=>{if(!Tx(i))return;const a=n.searchIn(i);if(a.isMatch){const c={score:a.score,key:t,value:i,idx:r,norm:s,indices:a.indices,hasInverse:a.hasInverse};a.termCount!==void 0&&(c.matchedMask=a.matchedMask,c.matchedTerms=a.matchedTerms,c.termCount=a.termCount),o.push(c)}});else{const{v:i,n:r}=e,s=n.searchIn(i);if(s.isMatch){const a={score:s.score,key:t,value:i,norm:r,indices:s.indices,hasInverse:s.hasInverse};s.termCount!==void 0&&(a.matchedMask=s.matchedMask,a.matchedTerms=s.matchedTerms,a.termCount=s.termCount),o.push(a)}}return o}_coversAllTokens(t){const e=t.length?t[0].termCount:void 0;if(e===void 0)return!0;if(e<=31){let o=0;for(let i=0;i<t.length;i++)o|=t[i].matchedMask||0;return o===2**e-1}const n=new Set;for(let o=0;o<t.length;o++){const i=t[o].matchedTerms;if(i)for(const r of i)n.add(r)}return n.size===e}};fv.version="7.4.2",fv.createIndex=VPt,fv.parseIndex=qSo,fv.config=bs,fv.match=function(t,e,n){if(n&&n.useTokenSearch)throw new Error(WSo);return Fte(t,{...bs,...n}).searchIn(e)},fv.parseQuery=XPt,zve(c3o),zve(f3o),fv.use=function(...t){t.forEach(e=>zve(e))};var I3o=fv;let Xve=null,kO=null,Jve=null;const E3o=async()=>Xve||kO||(kO=fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then(t=>t.json()).then(t=>(Xve=t,kO=null,t)),kO),b3o=async(t,e=20)=>{const n=await E3o();return Jve||(Jve=new I3o(n)),Jve.search(t).slice(0,e).map(o=>o.item)},S3o=t=>{const e=t.replace(".pretty/","/").replace(".kicad_mod",""),n=`kicad:${e}`;return{path:t,qualifiedName:n,description:e}},P3o=()=>{const[t,e]=X.useState([]),[n,o]=X.useState(!1),[i,r]=X.useState(null),[s,a]=X.useState(!1),c=X.useCallback(async A=>{const u=A.trim();if(!u)return[];o(!0),r(null);try{const _=(await b3o(u,20)).map(h=>({source:"kicad",footprint:S3o(h)}));return e(_),_}catch(d){return console.error("Error searching KiCad footprints",d),e([]),r(d instanceof Error?d.message:"Failed to search KiCad footprints"),[]}finally{o(!1),a(!0)}},[]),l=X.useCallback(()=>{e([]),o(!1),r(null),a(!1)},[]);return{results:t,isSearching:n,error:i,hasSearched:s,search:c,reset:l}},v3o=({onTscircuitPackageSelected:t,onJlcpcbComponentTsxLoaded:e,onKicadStringSelected:n})=>{const o=[];return t&&o.push("tscircuit.com"),e&&o.push("jlcpcb"),n&&o.push("kicad"),o},B3o=({isOpen:t,onClose:e,jlcpcbProxyRequestHeaders:n,onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r,jlcpcbProxyApiBase:s,tscircuitSessionToken:a})=>{Pte();const c=X.useMemo(()=>v3o({onKicadStringSelected:o,onTscircuitPackageSelected:i,onJlcpcbComponentTsxLoaded:r}),[o,i,r]),l=c.length>0,A=c.length===1,[u,d]=X.useState(c[0]??"tscircuit.com"),[_,h]=X.useState(""),[m,p]=X.useState(null),{results:g,isSearching:f,error:y,hasSearched:C,search:I,reset:E}=kSo({sessionToken:a}),{results:b,isSearching:P,error:B,hasSearched:M,search:R,reset:k}=HSo(),{results:H,isSearching:F,error:G,hasSearched:W,search:J,reset:q}=P3o(),{details:oe,isLoading:le,fetchDetails:ee,reset:re}=RSo(),[ae,ie]=X.useState(null),[de,ye]=X.useState(!1),[Ie,ve]=X.useState("pcb"),[ue,Se]=X.useState(null),[he,De]=X.useState(!1);X.useEffect(()=>{Se(null)},[m]);const Ge=X.useCallback(()=>{E(),k(),q(),p(null)},[k,q,E]);X.useEffect(()=>{t||(Ge(),h(""),ye(!1),ie(null),Se(null))},[t,Ge]),X.useEffect(()=>{h(""),p(null),u==="tscircuit.com"?E():u==="jlcpcb"?k():u==="kicad"&&q()},[u,k,q,E]);const Ye=ze=>{p(ze),ie(ze),ve("pcb"),ye(!0),re();const je=ze.package.org_owner_tscircuit_handle,it=ze.package.unscoped_name;if(je&&it){const at=it.split("/").pop()??it;ee(je,at)}},fe=async()=>{_.trim()&&(p(null),u==="tscircuit.com"?await I(_):u==="jlcpcb"?await R(_):u==="kicad"&&await J(_))},qe=async ze=>{try{if(Se(null),De(!0),ze.source==="kicad"){if(!o)throw new Error("KiCad handler not provided");await o({result:ze,footprint:ze.footprint.qualifiedName})}else if(ze.source==="jlcpcb"){if(!r)throw new Error("JLCPCB handler not provided");const je=await SSo(ze.component.partNumber,{headers:n,apiBase:s});await r({result:ze,tsx:je})}else if(ze.source==="tscircuit.com"){if(!i)throw new Error("tscircuit package handler not provided");const je=ze.package.org_owner_tscircuit_handle,it=ze.package.unscoped_name;if(!je||!it)throw new Error("Missing package metadata");const at=it.split("/").pop()??it,At=`@tsci/${je}.${at}`;await i({result:ze,fullPackageName:At})}return!0}catch(je){return console.error("Failed to import component",je),Se(je instanceof Error?je.message:"Failed to import component"),!1}finally{De(!1)}};let Le=[],Qe=!1,Ue=null,we=!1;u==="tscircuit.com"?(Le=g,Qe=f,Ue=y,we=C):u==="jlcpcb"?(Le=b,Qe=P,Ue=B,we=M):u==="kicad"&&(Le=H,Qe=F,Ue=G,we=W);const Ee=async()=>{if(!m)return;await qe(m)&&(e(),Ge(),h(""))},Fe=ze=>{ze||e()},Me=ze=>{ye(ze),ze||ie(null)};return K.jsxs(rT,{open:t,onOpenChange:Fe,children:[K.jsxs(eM,{style:{width:"calc(100vw - 2rem)",zIndex:HPt.importComponentDialog},className:"rf-rounded-sm rf-max-h-[90vh] rf-overflow-y-auto rf-overflow-x-hidden rf-flex rf-flex-col",children:[K.jsxs(tM,{children:[K.jsxs(nM,{className:"rf-text-lg sm:rf-text-xl",children:["Import ",A?Nte[u].label:""," ","Component"]}),K.jsx(sT,{className:"rf-text-sm",children:l?"Search for components from available sources.":"Import options are disabled because no handlers were provided."})]}),l?K.jsxs(Lpe,{value:u,onValueChange:ze=>d(ze),className:"rf-min-w-0 rf-w-full",children:[!A&&K.jsx(UJ,{className:"rf-flex rf-w-full rf-gap-2",children:c.map(ze=>K.jsx(B4,{value:ze,className:"rf-flex-1 rf-text-xs sm:rf-text-sm",children:Nte[ze].label},ze))}),K.jsx(PSo,{query:_,placeholder:Nte[u].placeholder,isSearching:Qe,onQueryChange:h,onSubmit:fe}),K.jsx("div",{className:"no-scrollbar rf-mt-4 rf-flex-1 rf-min-h-[200px] !rf-max-h-[40vh] !rf-overflow-y-auto rf-overflow-x-hidden rf-border rf-rounded-md rf-min-w-0",children:Qe?K.jsxs("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:[K.jsx(W4,{className:"rf-h-8 rf-w-8 rf-animate-spin rf-mx-auto rf-mb-2"}),K.jsx("p",{children:"Searching..."})]}):Le.length>0?K.jsx(QSo,{results:Le,selected:m,onSelect:p,onShowDetails:u==="tscircuit.com"?Ye:void 0}):K.jsx("div",{className:"rf-p-8 rf-text-center rf-text-zinc-500",children:Ue?`Error: ${Ue}`:we?Nte[u].emptyMessage:"Enter a search term to find components"})})]}):null,ue?K.jsx("div",{className:"rf-text-sm rf-text-red-600 rf-mt-2",children:ue}):null,K.jsxs(RO,{className:"rf-flex rf-flex-col sm:rf-flex-row rf-gap-2",children:[K.jsx(_l,{variant:"outline",onClick:e,className:"rf-order-2 sm:rf-order-1",children:"Cancel"}),K.jsx(_l,{onClick:Ee,disabled:!m||he,className:"rf-order-1 sm:rf-order-2",children:he?K.jsx(W4,{className:"rf-h-4 rf-w-4 rf-animate-spin"}):"Import"})]})]}),K.jsx(TSo,{packageResult:ae,isOpen:de,onOpenChange:Me,isLoading:le,details:oe,previewTab:Ie,onPreviewTabChange:ze=>ve(ze),isSubmitting:he,onImport:()=>{ae&&qe(ae).then(ze=>{ze&&(ye(!1),e(),Ge(),h(""))})}})]})},M3o=t=>{const e=t.match(/export const (\w+) =/);if(!e)throw new Error("Could not determine component name from TSX contents");return e[1]},ZPt=t=>{const e=x0(s=>s.pushEvent),n=x0(s=>s.upsertFile),o=async({result:s,fullPackageName:a})=>{const l=s.package.unscoped_name??s.package.name;await na.promise(e({event_type:"INSTALL_PACKAGE",full_package_name:a}),{loading:`Requesting install for "${l}"`,success:`Install requested for "${l}"`,error:A=>`Failed to request install: ${A instanceof Error?A.message:String(A)}`})},i=async({footprint:s})=>{await na.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 l=`imports/${M3o(a)}.tsx`;await na.promise(n(l,a),{loading:`Importing ${s.component.partNumber}`,success:`Imported to "${l}"`,error:A=>`Failed to import component: ${A instanceof Error?A.message:String(A)}`})};return K.jsx(B3o,{...t,onTscircuitPackageSelected:o,onKicadStringSelected:i,onJlcpcbComponentTsxLoaded:r})};ZPt.displayName="ImportComponentDialogForCli";var qve={exports:{}},evt;function w3o(){return evt||(evt=1,(function(t,e){var n={env:{},version:""};(function(o){t.exports=o()})(function(){return(function o(i,r,s){function a(A,u){if(!r[A]){if(!i[A]){var d=typeof WS=="function"&&WS;if(!u&&d)return d(A,!0);if(c)return c(A,!0);var _=new Error("Cannot find module '"+A+"'");throw _.code="MODULE_NOT_FOUND",_}var h=r[A]={exports:{}};i[A][0].call(h.exports,function(m){var p=i[A][1][m];return a(p||m)},h,h.exports,o,i,r,s)}return r[A].exports}for(var c=typeof WS=="function"&&WS,l=0;l<s.length;l++)a(s[l]);return a})({1:[function(o,i,r){var s=o("./utils"),a=o("./support"),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.encode=function(l){for(var A,u,d,_,h,m,p,g=[],f=0,y=l.length,C=y,I=s.getTypeOf(l)!=="string";f<l.length;)C=y-f,d=I?(A=l[f++],u=f<y?l[f++]:0,f<y?l[f++]:0):(A=l.charCodeAt(f++),u=f<y?l.charCodeAt(f++):0,f<y?l.charCodeAt(f++):0),_=A>>2,h=(3&A)<<4|u>>4,m=1<C?(15&u)<<2|d>>6:64,p=2<C?63&d:64,g.push(c.charAt(_)+c.charAt(h)+c.charAt(m)+c.charAt(p));return g.join("")},r.decode=function(l){var A,u,d,_,h,m,p=0,g=0,f="data:";if(l.substr(0,f.length)===f)throw new Error("Invalid base64 input, it looks like a data url.");var y,C=3*(l=l.replace(/[^A-Za-z0-9+/=]/g,"")).length/4;if(l.charAt(l.length-1)===c.charAt(64)&&C--,l.charAt(l.length-2)===c.charAt(64)&&C--,C%1!=0)throw new Error("Invalid base64 input, bad content length.");for(y=a.uint8array?new Uint8Array(0|C):new Array(0|C);p<l.length;)A=c.indexOf(l.charAt(p++))<<2|(_=c.indexOf(l.charAt(p++)))>>4,u=(15&_)<<4|(h=c.indexOf(l.charAt(p++)))>>2,d=(3&h)<<6|(m=c.indexOf(l.charAt(p++))),y[g++]=A,h!==64&&(y[g++]=u),m!==64&&(y[g++]=d);return y}},{"./support":30,"./utils":32}],2:[function(o,i,r){var s=o("./external"),a=o("./stream/DataWorker"),c=o("./stream/Crc32Probe"),l=o("./stream/DataLengthProbe");function A(u,d,_,h,m){this.compressedSize=u,this.uncompressedSize=d,this.crc32=_,this.compression=h,this.compressedContent=m}A.prototype={getContentWorker:function(){var u=new a(s.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new l("data_length")),d=this;return u.on("end",function(){if(this.streamInfo.data_length!==d.uncompressedSize)throw new Error("Bug : uncompressed data size mismatch")}),u},getCompressedWorker:function(){return new a(s.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize",this.compressedSize).withStreamInfo("uncompressedSize",this.uncompressedSize).withStreamInfo("crc32",this.crc32).withStreamInfo("compression",this.compression)}},A.createWorkerFrom=function(u,d,_){return u.pipe(new c).pipe(new l("uncompressedSize")).pipe(d.compressWorker(_)).pipe(new l("compressedSize")).withStreamInfo("compression",d)},i.exports=A},{"./external":6,"./stream/Crc32Probe":25,"./stream/DataLengthProbe":26,"./stream/DataWorker":27}],3:[function(o,i,r){var s=o("./stream/GenericWorker");r.STORE={magic:"\0\0",compressWorker:function(){return new s("STORE compression")},uncompressWorker:function(){return new s("STORE decompression")}},r.DEFLATE=o("./flate")},{"./flate":7,"./stream/GenericWorker":28}],4:[function(o,i,r){var s=o("./utils"),a=(function(){for(var c,l=[],A=0;A<256;A++){c=A;for(var u=0;u<8;u++)c=1&c?3988292384^c>>>1:c>>>1;l[A]=c}return l})();i.exports=function(c,l){return c!==void 0&&c.length?s.getTypeOf(c)!=="string"?(function(A,u,d,_){var h=a,m=_+d;A^=-1;for(var p=_;p<m;p++)A=A>>>8^h[255&(A^u[p])];return-1^A})(0|l,c,c.length,0):(function(A,u,d,_){var h=a,m=_+d;A^=-1;for(var p=_;p<m;p++)A=A>>>8^h[255&(A^u.charCodeAt(p))];return-1^A})(0|l,c,c.length,0):0}},{"./utils":32}],5:[function(o,i,r){r.base64=!1,r.binary=!1,r.dir=!1,r.createFolders=!0,r.date=null,r.compression=null,r.compressionOptions=null,r.comment=null,r.unixPermissions=null,r.dosPermissions=null},{}],6:[function(o,i,r){var s=null;s=typeof Promise<"u"?Promise:o("lie"),i.exports={Promise:s}},{lie:37}],7:[function(o,i,r){var s=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Uint32Array<"u",a=o("pako"),c=o("./utils"),l=o("./stream/GenericWorker"),A=s?"uint8array":"array";function u(d,_){l.call(this,"FlateWorker/"+d),this._pako=null,this._pakoAction=d,this._pakoOptions=_,this.meta={}}r.magic="\b\0",c.inherits(u,l),u.prototype.processChunk=function(d){this.meta=d.meta,this._pako===null&&this._createPako(),this._pako.push(c.transformTo(A,d.data),!1)},u.prototype.flush=function(){l.prototype.flush.call(this),this._pako===null&&this._createPako(),this._pako.push([],!0)},u.prototype.cleanUp=function(){l.prototype.cleanUp.call(this),this._pako=null},u.prototype._createPako=function(){this._pako=new a[this._pakoAction]({raw:!0,level:this._pakoOptions.level||-1});var d=this;this._pako.onData=function(_){d.push({data:_,meta:d.meta})}},r.compressWorker=function(d){return new u("Deflate",d)},r.uncompressWorker=function(){return new u("Inflate",{})}},{"./stream/GenericWorker":28,"./utils":32,pako:38}],8:[function(o,i,r){function s(h,m){var p,g="";for(p=0;p<m;p++)g+=String.fromCharCode(255&h),h>>>=8;return g}function a(h,m,p,g,f,y){var C,I,E=h.file,b=h.compression,P=y!==A.utf8encode,B=c.transformTo("string",y(E.name)),M=c.transformTo("string",A.utf8encode(E.name)),R=E.comment,k=c.transformTo("string",y(R)),H=c.transformTo("string",A.utf8encode(R)),F=M.length!==E.name.length,G=H.length!==R.length,W="",J="",q="",oe=E.dir,le=E.date,ee={crc32:0,compressedSize:0,uncompressedSize:0};m&&!p||(ee.crc32=h.crc32,ee.compressedSize=h.compressedSize,ee.uncompressedSize=h.uncompressedSize);var re=0;m&&(re|=8),P||!F&&!G||(re|=2048);var ae=0,ie=0;oe&&(ae|=16),f==="UNIX"?(ie=798,ae|=(function(ye,Ie){var ve=ye;return ye||(ve=Ie?16893:33204),(65535&ve)<<16})(E.unixPermissions,oe)):(ie=20,ae|=(function(ye){return 63&(ye||0)})(E.dosPermissions)),C=le.getUTCHours(),C<<=6,C|=le.getUTCMinutes(),C<<=5,C|=le.getUTCSeconds()/2,I=le.getUTCFullYear()-1980,I<<=4,I|=le.getUTCMonth()+1,I<<=5,I|=le.getUTCDate(),F&&(J=s(1,1)+s(u(B),4)+M,W+="up"+s(J.length,2)+J),G&&(q=s(1,1)+s(u(k),4)+H,W+="uc"+s(q.length,2)+q);var de="";return de+=`
5794
5794
  \0`,de+=s(re,2),de+=b.magic,de+=s(C,2),de+=s(I,2),de+=s(ee.crc32,4),de+=s(ee.compressedSize,4),de+=s(ee.uncompressedSize,4),de+=s(B.length,2),de+=s(W.length,2),{fileRecord:d.LOCAL_FILE_HEADER+de+B+W,dirRecord:d.CENTRAL_FILE_HEADER+s(ie,2)+de+s(k.length,2)+"\0\0\0\0"+s(ae,4)+s(g,4)+B+W+k}}var c=o("../utils"),l=o("../stream/GenericWorker"),A=o("../utf8"),u=o("../crc32"),d=o("../signature");function _(h,m,p,g){l.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=m,this.zipPlatform=p,this.encodeFileName=g,this.streamFiles=h,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}c.inherits(_,l),_.prototype.push=function(h){var m=h.meta.percent||0,p=this.entriesCount,g=this._sources.length;this.accumulate?this.contentBuffer.push(h):(this.bytesWritten+=h.data.length,l.prototype.push.call(this,{data:h.data,meta:{currentFile:this.currentFile,percent:p?(m+100*(p-g-1))/p:100}}))},_.prototype.openedSource=function(h){this.currentSourceOffset=this.bytesWritten,this.currentFile=h.file.name;var m=this.streamFiles&&!h.file.dir;if(m){var p=a(h,m,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:p.fileRecord,meta:{percent:0}})}else this.accumulate=!0},_.prototype.closedSource=function(h){this.accumulate=!1;var m=this.streamFiles&&!h.file.dir,p=a(h,m,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(p.dirRecord),m)this.push({data:(function(g){return d.DATA_DESCRIPTOR+s(g.crc32,4)+s(g.compressedSize,4)+s(g.uncompressedSize,4)})(h),meta:{percent:100}});else for(this.push({data:p.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null},_.prototype.flush=function(){for(var h=this.bytesWritten,m=0;m<this.dirRecords.length;m++)this.push({data:this.dirRecords[m],meta:{percent:100}});var p=this.bytesWritten-h,g=(function(f,y,C,I,E){var b=c.transformTo("string",E(I));return d.CENTRAL_DIRECTORY_END+"\0\0\0\0"+s(f,2)+s(f,2)+s(y,4)+s(C,4)+s(b.length,2)+b})(this.dirRecords.length,p,h,this.zipComment,this.encodeFileName);this.push({data:g,meta:{percent:100}})},_.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()},_.prototype.registerPrevious=function(h){this._sources.push(h);var m=this;return h.on("data",function(p){m.processChunk(p)}),h.on("end",function(){m.closedSource(m.previous.streamInfo),m._sources.length?m.prepareNextSource():m.end()}),h.on("error",function(p){m.error(p)}),this},_.prototype.resume=function(){return!!l.prototype.resume.call(this)&&(!this.previous&&this._sources.length?(this.prepareNextSource(),!0):this.previous||this._sources.length||this.generatedError?void 0:(this.end(),!0))},_.prototype.error=function(h){var m=this._sources;if(!l.prototype.error.call(this,h))return!1;for(var p=0;p<m.length;p++)try{m[p].error(h)}catch{}return!0},_.prototype.lock=function(){l.prototype.lock.call(this);for(var h=this._sources,m=0;m<h.length;m++)h[m].lock()},i.exports=_},{"../crc32":4,"../signature":23,"../stream/GenericWorker":28,"../utf8":31,"../utils":32}],9:[function(o,i,r){var s=o("../compressions"),a=o("./ZipFileWorker");r.generateWorker=function(c,l,A){var u=new a(l.streamFiles,A,l.platform,l.encodeFileName),d=0;try{c.forEach(function(_,h){d++;var m=(function(y,C){var I=y||C,E=s[I];if(!E)throw new Error(I+" is not a valid compression method !");return E})(h.options.compression,l.compression),p=h.options.compressionOptions||l.compressionOptions||{},g=h.dir,f=h.date;h._compressWorker(m,p).withStreamInfo("file",{name:_,dir:g,date:f,comment:h.comment||"",unixPermissions:h.unixPermissions,dosPermissions:h.dosPermissions}).pipe(u)}),u.entriesCount=d}catch(_){u.error(_)}return u}},{"../compressions":3,"./ZipFileWorker":8}],10:[function(o,i,r){function s(){if(!(this instanceof s))return new s;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var a=new s;for(var c in this)typeof this[c]!="function"&&(a[c]=this[c]);return a}}(s.prototype=o("./object")).loadAsync=o("./load"),s.support=o("./support"),s.defaults=o("./defaults"),s.version="3.10.1",s.loadAsync=function(a,c){return new s().loadAsync(a,c)},s.external=o("./external"),i.exports=s},{"./defaults":5,"./external":6,"./load":11,"./object":15,"./support":30}],11:[function(o,i,r){var s=o("./utils"),a=o("./external"),c=o("./utf8"),l=o("./zipEntries"),A=o("./stream/Crc32Probe"),u=o("./nodejsUtils");function d(_){return new a.Promise(function(h,m){var p=_.decompressed.getContentWorker().pipe(new A);p.on("error",function(g){m(g)}).on("end",function(){p.streamInfo.crc32!==_.decompressed.crc32?m(new Error("Corrupted zip : CRC32 mismatch")):h()}).resume()})}i.exports=function(_,h){var m=this;return h=s.extend(h||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:c.utf8decode}),u.isNode&&u.isStream(_)?a.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):s.prepareContent("the loaded zip file",_,!0,h.optimizedBinaryString,h.base64).then(function(p){var g=new l(h);return g.load(p),g}).then(function(p){var g=[a.Promise.resolve(p)],f=p.files;if(h.checkCRC32)for(var y=0;y<f.length;y++)g.push(d(f[y]));return a.Promise.all(g)}).then(function(p){for(var g=p.shift(),f=g.files,y=0;y<f.length;y++){var C=f[y],I=C.fileNameStr,E=s.resolve(C.fileNameStr);m.file(E,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:h.createFolders}),C.dir||(m.file(E).unsafeOriginalName=I)}return g.zipComment.length&&(m.comment=g.zipComment),m})}},{"./external":6,"./nodejsUtils":14,"./stream/Crc32Probe":25,"./utf8":31,"./utils":32,"./zipEntries":33}],12:[function(o,i,r){var s=o("../utils"),a=o("../stream/GenericWorker");function c(l,A){a.call(this,"Nodejs stream input adapter for "+l),this._upstreamEnded=!1,this._bindStream(A)}s.inherits(c,a),c.prototype._bindStream=function(l){var A=this;(this._stream=l).pause(),l.on("data",function(u){A.push({data:u,meta:{percent:0}})}).on("error",function(u){A.isPaused?this.generatedError=u:A.error(u)}).on("end",function(){A.isPaused?A._upstreamEnded=!0:A.end()})},c.prototype.pause=function(){return!!a.prototype.pause.call(this)&&(this._stream.pause(),!0)},c.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(this._upstreamEnded?this.end():this._stream.resume(),!0)},i.exports=c},{"../stream/GenericWorker":28,"../utils":32}],13:[function(o,i,r){var s=o("readable-stream").Readable;function a(c,l,A){s.call(this,l),this._helper=c;var u=this;c.on("data",function(d,_){u.push(d)||u._helper.pause(),A&&A(_)}).on("error",function(d){u.emit("error",d)}).on("end",function(){u.push(null)})}o("../utils").inherits(a,s),a.prototype._read=function(){this._helper.resume()},i.exports=a},{"../utils":32,"readable-stream":16}],14:[function(o,i,r){i.exports={isNode:typeof Buffer<"u",newBufferFrom:function(s,a){if(Buffer.from&&Buffer.from!==Uint8Array.from)return Buffer.from(s,a);if(typeof s=="number")throw new Error('The "data" argument must not be a number');return new Buffer(s,a)},allocBuffer:function(s){if(Buffer.alloc)return Buffer.alloc(s);var a=new Buffer(s);return a.fill(0),a},isBuffer:function(s){return Buffer.isBuffer(s)},isStream:function(s){return s&&typeof s.on=="function"&&typeof s.pause=="function"&&typeof s.resume=="function"}}},{}],15:[function(o,i,r){function s(E,b,P){var B,M=c.getTypeOf(b),R=c.extend(P||{},u);R.date=R.date||new Date,R.compression!==null&&(R.compression=R.compression.toUpperCase()),typeof R.unixPermissions=="string"&&(R.unixPermissions=parseInt(R.unixPermissions,8)),R.unixPermissions&&16384&R.unixPermissions&&(R.dir=!0),R.dosPermissions&&16&R.dosPermissions&&(R.dir=!0),R.dir&&(E=f(E)),R.createFolders&&(B=g(E))&&y.call(this,B,!0);var k=M==="string"&&R.binary===!1&&R.base64===!1;P&&P.binary!==void 0||(R.binary=!k),(b instanceof d&&b.uncompressedSize===0||R.dir||!b||b.length===0)&&(R.base64=!1,R.binary=!0,b="",R.compression="STORE",M="string");var H=null;H=b instanceof d||b instanceof l?b:m.isNode&&m.isStream(b)?new p(E,b):c.prepareContent(E,b,R.binary,R.optimizedBinaryString,R.base64);var F=new _(E,H,R);this.files[E]=F}var a=o("./utf8"),c=o("./utils"),l=o("./stream/GenericWorker"),A=o("./stream/StreamHelper"),u=o("./defaults"),d=o("./compressedObject"),_=o("./zipObject"),h=o("./generate"),m=o("./nodejsUtils"),p=o("./nodejs/NodejsStreamInputAdapter"),g=function(E){E.slice(-1)==="/"&&(E=E.substring(0,E.length-1));var b=E.lastIndexOf("/");return 0<b?E.substring(0,b):""},f=function(E){return E.slice(-1)!=="/"&&(E+="/"),E},y=function(E,b){return b=b!==void 0?b:u.createFolders,E=f(E),this.files[E]||s.call(this,E,null,{dir:!0,createFolders:b}),this.files[E]};function C(E){return Object.prototype.toString.call(E)==="[object RegExp]"}var I={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(E){var b,P,B;for(b in this.files)B=this.files[b],(P=b.slice(this.root.length,b.length))&&b.slice(0,this.root.length)===this.root&&E(P,B)},filter:function(E){var b=[];return this.forEach(function(P,B){E(P,B)&&b.push(B)}),b},file:function(E,b,P){if(arguments.length!==1)return E=this.root+E,s.call(this,E,b,P),this;if(C(E)){var B=E;return this.filter(function(R,k){return!k.dir&&B.test(R)})}var M=this.files[this.root+E];return M&&!M.dir?M:null},folder:function(E){if(!E)return this;if(C(E))return this.filter(function(M,R){return R.dir&&E.test(M)});var b=this.root+E,P=y.call(this,b),B=this.clone();return B.root=P.name,B},remove:function(E){E=this.root+E;var b=this.files[E];if(b||(E.slice(-1)!=="/"&&(E+="/"),b=this.files[E]),b&&!b.dir)delete this.files[E];else for(var P=this.filter(function(M,R){return R.name.slice(0,E.length)===E}),B=0;B<P.length;B++)delete this.files[P[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(E){var b,P={};try{if((P=c.extend(E||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:a.utf8encode})).type=P.type.toLowerCase(),P.compression=P.compression.toUpperCase(),P.type==="binarystring"&&(P.type="string"),!P.type)throw new Error("No output type specified.");c.checkSupport(P.type),P.platform!=="darwin"&&P.platform!=="freebsd"&&P.platform!=="linux"&&P.platform!=="sunos"||(P.platform="UNIX"),P.platform==="win32"&&(P.platform="DOS");var B=P.comment||this.comment||"";b=h.generateWorker(this,P,B)}catch(M){(b=new l("error")).error(M)}return new A(b,P.type||"string",P.mimeType)},generateAsync:function(E,b){return this.generateInternalStream(E).accumulate(b)},generateNodeStream:function(E,b){return(E=E||{}).type||(E.type="nodebuffer"),this.generateInternalStream(E).toNodejsStream(b)}};i.exports=I},{"./compressedObject":2,"./defaults":5,"./generate":9,"./nodejs/NodejsStreamInputAdapter":12,"./nodejsUtils":14,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31,"./utils":32,"./zipObject":35}],16:[function(o,i,r){i.exports=o("stream")},{stream:void 0}],17:[function(o,i,r){var s=o("./DataReader");function a(c){s.call(this,c);for(var l=0;l<this.data.length;l++)c[l]=255&c[l]}o("../utils").inherits(a,s),a.prototype.byteAt=function(c){return this.data[this.zero+c]},a.prototype.lastIndexOfSignature=function(c){for(var l=c.charCodeAt(0),A=c.charCodeAt(1),u=c.charCodeAt(2),d=c.charCodeAt(3),_=this.length-4;0<=_;--_)if(this.data[_]===l&&this.data[_+1]===A&&this.data[_+2]===u&&this.data[_+3]===d)return _-this.zero;return-1},a.prototype.readAndCheckSignature=function(c){var l=c.charCodeAt(0),A=c.charCodeAt(1),u=c.charCodeAt(2),d=c.charCodeAt(3),_=this.readData(4);return l===_[0]&&A===_[1]&&u===_[2]&&d===_[3]},a.prototype.readData=function(c){if(this.checkOffset(c),c===0)return[];var l=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./DataReader":18}],18:[function(o,i,r){var s=o("../utils");function a(c){this.data=c,this.length=c.length,this.index=0,this.zero=0}a.prototype={checkOffset:function(c){this.checkIndex(this.index+c)},checkIndex:function(c){if(this.length<this.zero+c||c<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+c+"). Corrupted zip ?")},setIndex:function(c){this.checkIndex(c),this.index=c},skip:function(c){this.setIndex(this.index+c)},byteAt:function(){},readInt:function(c){var l,A=0;for(this.checkOffset(c),l=this.index+c-1;l>=this.index;l--)A=(A<<8)+this.byteAt(l);return this.index+=c,A},readString:function(c){return s.transformTo("string",this.readData(c))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var c=this.readInt(4);return new Date(Date.UTC(1980+(c>>25&127),(c>>21&15)-1,c>>16&31,c>>11&31,c>>5&63,(31&c)<<1))}},i.exports=a},{"../utils":32}],19:[function(o,i,r){var s=o("./Uint8ArrayReader");function a(c){s.call(this,c)}o("../utils").inherits(a,s),a.prototype.readData=function(c){this.checkOffset(c);var l=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./Uint8ArrayReader":21}],20:[function(o,i,r){var s=o("./DataReader");function a(c){s.call(this,c)}o("../utils").inherits(a,s),a.prototype.byteAt=function(c){return this.data.charCodeAt(this.zero+c)},a.prototype.lastIndexOfSignature=function(c){return this.data.lastIndexOf(c)-this.zero},a.prototype.readAndCheckSignature=function(c){return c===this.readData(4)},a.prototype.readData=function(c){this.checkOffset(c);var l=this.data.slice(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./DataReader":18}],21:[function(o,i,r){var s=o("./ArrayReader");function a(c){s.call(this,c)}o("../utils").inherits(a,s),a.prototype.readData=function(c){if(this.checkOffset(c),c===0)return new Uint8Array(0);var l=this.data.subarray(this.zero+this.index,this.zero+this.index+c);return this.index+=c,l},i.exports=a},{"../utils":32,"./ArrayReader":17}],22:[function(o,i,r){var s=o("../utils"),a=o("../support"),c=o("./ArrayReader"),l=o("./StringReader"),A=o("./NodeBufferReader"),u=o("./Uint8ArrayReader");i.exports=function(d){var _=s.getTypeOf(d);return s.checkSupport(_),_!=="string"||a.uint8array?_==="nodebuffer"?new A(d):a.uint8array?new u(s.transformTo("uint8array",d)):new c(s.transformTo("array",d)):new l(d)}},{"../support":30,"../utils":32,"./ArrayReader":17,"./NodeBufferReader":19,"./StringReader":20,"./Uint8ArrayReader":21}],23:[function(o,i,r){r.LOCAL_FILE_HEADER="PK",r.CENTRAL_FILE_HEADER="PK",r.CENTRAL_DIRECTORY_END="PK",r.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK\x07",r.ZIP64_CENTRAL_DIRECTORY_END="PK",r.DATA_DESCRIPTOR="PK\x07\b"},{}],24:[function(o,i,r){var s=o("./GenericWorker"),a=o("../utils");function c(l){s.call(this,"ConvertWorker to "+l),this.destType=l}a.inherits(c,s),c.prototype.processChunk=function(l){this.push({data:a.transformTo(this.destType,l.data),meta:l.meta})},i.exports=c},{"../utils":32,"./GenericWorker":28}],25:[function(o,i,r){var s=o("./GenericWorker"),a=o("../crc32");function c(){s.call(this,"Crc32Probe"),this.withStreamInfo("crc32",0)}o("../utils").inherits(c,s),c.prototype.processChunk=function(l){this.streamInfo.crc32=a(l.data,this.streamInfo.crc32||0),this.push(l)},i.exports=c},{"../crc32":4,"../utils":32,"./GenericWorker":28}],26:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function c(l){a.call(this,"DataLengthProbe for "+l),this.propName=l,this.withStreamInfo(l,0)}s.inherits(c,a),c.prototype.processChunk=function(l){if(l){var A=this.streamInfo[this.propName]||0;this.streamInfo[this.propName]=A+l.data.length}a.prototype.processChunk.call(this,l)},i.exports=c},{"../utils":32,"./GenericWorker":28}],27:[function(o,i,r){var s=o("../utils"),a=o("./GenericWorker");function c(l){a.call(this,"DataWorker");var A=this;this.dataIsReady=!1,this.index=0,this.max=0,this.data=null,this.type="",this._tickScheduled=!1,l.then(function(u){A.dataIsReady=!0,A.data=u,A.max=u&&u.length||0,A.type=s.getTypeOf(u),A.isPaused||A._tickAndRepeat()},function(u){A.error(u)})}s.inherits(c,a),c.prototype.cleanUp=function(){a.prototype.cleanUp.call(this),this.data=null},c.prototype.resume=function(){return!!a.prototype.resume.call(this)&&(!this._tickScheduled&&this.dataIsReady&&(this._tickScheduled=!0,s.delay(this._tickAndRepeat,[],this)),!0)},c.prototype._tickAndRepeat=function(){this._tickScheduled=!1,this.isPaused||this.isFinished||(this._tick(),this.isFinished||(s.delay(this._tickAndRepeat,[],this),this._tickScheduled=!0))},c.prototype._tick=function(){if(this.isPaused||this.isFinished)return!1;var l=null,A=Math.min(this.max,this.index+16384);if(this.index>=this.max)return this.end();switch(this.type){case"string":l=this.data.substring(this.index,A);break;case"uint8array":l=this.data.subarray(this.index,A);break;case"array":case"nodebuffer":l=this.data.slice(this.index,A)}return this.index=A,this.push({data:l,meta:{percent:this.max?this.index/this.max*100:0}})},i.exports=c},{"../utils":32,"./GenericWorker":28}],28:[function(o,i,r){function s(a){this.name=a||"default",this.streamInfo={},this.generatedError=null,this.extraStreamInfo={},this.isPaused=!0,this.isFinished=!1,this.isLocked=!1,this._listeners={data:[],end:[],error:[]},this.previous=null}s.prototype={push:function(a){this.emit("data",a)},end:function(){if(this.isFinished)return!1;this.flush();try{this.emit("end"),this.cleanUp(),this.isFinished=!0}catch(a){this.emit("error",a)}return!0},error:function(a){return!this.isFinished&&(this.isPaused?this.generatedError=a:(this.isFinished=!0,this.emit("error",a),this.previous&&this.previous.error(a),this.cleanUp()),!0)},on:function(a,c){return this._listeners[a].push(c),this},cleanUp:function(){this.streamInfo=this.generatedError=this.extraStreamInfo=null,this._listeners=[]},emit:function(a,c){if(this._listeners[a])for(var l=0;l<this._listeners[a].length;l++)this._listeners[a][l].call(this,c)},pipe:function(a){return a.registerPrevious(this)},registerPrevious:function(a){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.streamInfo=a.streamInfo,this.mergeStreamInfo(),this.previous=a;var c=this;return a.on("data",function(l){c.processChunk(l)}),a.on("end",function(){c.end()}),a.on("error",function(l){c.error(l)}),this},pause:function(){return!this.isPaused&&!this.isFinished&&(this.isPaused=!0,this.previous&&this.previous.pause(),!0)},resume:function(){if(!this.isPaused||this.isFinished)return!1;var a=this.isPaused=!1;return this.generatedError&&(this.error(this.generatedError),a=!0),this.previous&&this.previous.resume(),!a},flush:function(){},processChunk:function(a){this.push(a)},withStreamInfo:function(a,c){return this.extraStreamInfo[a]=c,this.mergeStreamInfo(),this},mergeStreamInfo:function(){for(var a in this.extraStreamInfo)Object.prototype.hasOwnProperty.call(this.extraStreamInfo,a)&&(this.streamInfo[a]=this.extraStreamInfo[a])},lock:function(){if(this.isLocked)throw new Error("The stream '"+this+"' has already been used.");this.isLocked=!0,this.previous&&this.previous.lock()},toString:function(){var a="Worker "+this.name;return this.previous?this.previous+" -> "+a:a}},i.exports=s},{}],29:[function(o,i,r){var s=o("../utils"),a=o("./ConvertWorker"),c=o("./GenericWorker"),l=o("../base64"),A=o("../support"),u=o("../external"),d=null;if(A.nodestream)try{d=o("../nodejs/NodejsStreamOutputAdapter")}catch{}function _(m,p){return new u.Promise(function(g,f){var y=[],C=m._internalType,I=m._outputType,E=m._mimeType;m.on("data",function(b,P){y.push(b),p&&p(P)}).on("error",function(b){y=[],f(b)}).on("end",function(){try{var b=(function(P,B,M){switch(P){case"blob":return s.newBlob(s.transformTo("arraybuffer",B),M);case"base64":return l.encode(B);default:return s.transformTo(P,B)}})(I,(function(P,B){var M,R=0,k=null,H=0;for(M=0;M<B.length;M++)H+=B[M].length;switch(P){case"string":return B.join("");case"array":return Array.prototype.concat.apply([],B);case"uint8array":for(k=new Uint8Array(H),M=0;M<B.length;M++)k.set(B[M],R),R+=B[M].length;return k;case"nodebuffer":return Buffer.concat(B);default:throw new Error("concat : unsupported type '"+P+"'")}})(C,y),E);g(b)}catch(P){f(P)}y=[]}).resume()})}function h(m,p,g){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=g,s.checkSupport(f),this._worker=m.pipe(new a(f)),m.lock()}catch(y){this._worker=new c("error"),this._worker.error(y)}}h.prototype={accumulate:function(m){return _(this,m)},on:function(m,p){var g=this;return m==="data"?this._worker.on(m,function(f){p.call(g,f.data,f.meta)}):this._worker.on(m,function(){s.delay(p,arguments,g)}),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 d(this,{objectMode:this._outputType!=="nodebuffer"},m)}},i.exports=h},{"../base64":1,"../external":6,"../nodejs/NodejsStreamOutputAdapter":13,"../support":30,"../utils":32,"./ConvertWorker":24,"./GenericWorker":28}],30:[function(o,i,r){if(r.base64=!0,r.array=!0,r.string=!0,r.arraybuffer=typeof ArrayBuffer<"u"&&typeof Uint8Array<"u",r.nodebuffer=typeof Buffer<"u",r.uint8array=typeof Uint8Array<"u",typeof ArrayBuffer>"u")r.blob=!1;else{var s=new ArrayBuffer(0);try{r.blob=new Blob([s],{type:"application/zip"}).size===0}catch{try{var a=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);a.append(s),r.blob=a.getBlob("application/zip").size===0}catch{r.blob=!1}}}try{r.nodestream=!!o("readable-stream").Readable}catch{r.nodestream=!1}},{"readable-stream":16}],31:[function(o,i,r){for(var s=o("./utils"),a=o("./support"),c=o("./nodejsUtils"),l=o("./stream/GenericWorker"),A=new Array(256),u=0;u<256;u++)A[u]=252<=u?6:248<=u?5:240<=u?4:224<=u?3:192<=u?2:1;A[254]=A[254]=1;function d(){l.call(this,"utf-8 decode"),this.leftOver=null}function _(){l.call(this,"utf-8 encode")}r.utf8encode=function(h){return a.nodebuffer?c.newBufferFrom(h,"utf-8"):(function(m){var p,g,f,y,C,I=m.length,E=0;for(y=0;y<I;y++)(64512&(g=m.charCodeAt(y)))==55296&&y+1<I&&(64512&(f=m.charCodeAt(y+1)))==56320&&(g=65536+(g-55296<<10)+(f-56320),y++),E+=g<128?1:g<2048?2:g<65536?3:4;for(p=a.uint8array?new Uint8Array(E):new Array(E),y=C=0;C<E;y++)(64512&(g=m.charCodeAt(y)))==55296&&y+1<I&&(64512&(f=m.charCodeAt(y+1)))==56320&&(g=65536+(g-55296<<10)+(f-56320),y++),g<128?p[C++]=g:(g<2048?p[C++]=192|g>>>6:(g<65536?p[C++]=224|g>>>12:(p[C++]=240|g>>>18,p[C++]=128|g>>>12&63),p[C++]=128|g>>>6&63),p[C++]=128|63&g);return p})(h)},r.utf8decode=function(h){return a.nodebuffer?s.transformTo("nodebuffer",h).toString("utf-8"):(function(m){var p,g,f,y,C=m.length,I=new Array(2*C);for(p=g=0;p<C;)if((f=m[p++])<128)I[g++]=f;else if(4<(y=A[f]))I[g++]=65533,p+=y-1;else{for(f&=y===2?31:y===3?15:7;1<y&&p<C;)f=f<<6|63&m[p++],y--;1<y?I[g++]=65533:f<65536?I[g++]=f:(f-=65536,I[g++]=55296|f>>10&1023,I[g++]=56320|1023&f)}return I.length!==g&&(I.subarray?I=I.subarray(0,g):I.length=g),s.applyFromCharCode(I)})(h=s.transformTo(a.uint8array?"uint8array":"array",h))},s.inherits(d,l),d.prototype.processChunk=function(h){var m=s.transformTo(a.uint8array?"uint8array":"array",h.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 g=(function(y,C){var I;for((C=C||y.length)>y.length&&(C=y.length),I=C-1;0<=I&&(192&y[I])==128;)I--;return I<0||I===0?C:I+A[y[I]]>C?I:C})(m),f=m;g!==m.length&&(a.uint8array?(f=m.subarray(0,g),this.leftOver=m.subarray(g,m.length)):(f=m.slice(0,g),this.leftOver=m.slice(g,m.length))),this.push({data:r.utf8decode(f),meta:h.meta})},d.prototype.flush=function(){this.leftOver&&this.leftOver.length&&(this.push({data:r.utf8decode(this.leftOver),meta:{}}),this.leftOver=null)},r.Utf8DecodeWorker=d,s.inherits(_,l),_.prototype.processChunk=function(h){this.push({data:r.utf8encode(h.data),meta:h.meta})},r.Utf8EncodeWorker=_},{"./nodejsUtils":14,"./stream/GenericWorker":28,"./support":30,"./utils":32}],32:[function(o,i,r){var s=o("./support"),a=o("./base64"),c=o("./nodejsUtils"),l=o("./external");function A(p){return p}function u(p,g){for(var f=0;f<p.length;++f)g[f]=255&p.charCodeAt(f);return g}o("setimmediate"),r.newBlob=function(p,g){r.checkSupport("blob");try{return new Blob([p],{type:g})}catch{try{var f=new(self.BlobBuilder||self.WebKitBlobBuilder||self.MozBlobBuilder||self.MSBlobBuilder);return f.append(p),f.getBlob(g)}catch{throw new Error("Bug : can't construct the Blob.")}}};var d={stringifyByChunk:function(p,g,f){var y=[],C=0,I=p.length;if(I<=f)return String.fromCharCode.apply(null,p);for(;C<I;)g==="array"||g==="nodebuffer"?y.push(String.fromCharCode.apply(null,p.slice(C,Math.min(C+f,I)))):y.push(String.fromCharCode.apply(null,p.subarray(C,Math.min(C+f,I)))),C+=f;return y.join("")},stringifyByChar:function(p){for(var g="",f=0;f<p.length;f++)g+=String.fromCharCode(p[f]);return g},applyCanBeUsed:{uint8array:(function(){try{return s.uint8array&&String.fromCharCode.apply(null,new Uint8Array(1)).length===1}catch{return!1}})(),nodebuffer:(function(){try{return s.nodebuffer&&String.fromCharCode.apply(null,c.allocBuffer(1)).length===1}catch{return!1}})()}};function _(p){var g=65536,f=r.getTypeOf(p),y=!0;if(f==="uint8array"?y=d.applyCanBeUsed.uint8array:f==="nodebuffer"&&(y=d.applyCanBeUsed.nodebuffer),y)for(;1<g;)try{return d.stringifyByChunk(p,f,g)}catch{g=Math.floor(g/2)}return d.stringifyByChar(p)}function h(p,g){for(var f=0;f<p.length;f++)g[f]=p[f];return g}r.applyFromCharCode=_;var m={};m.string={string:A,array:function(p){return u(p,new Array(p.length))},arraybuffer:function(p){return m.string.uint8array(p).buffer},uint8array:function(p){return u(p,new Uint8Array(p.length))},nodebuffer:function(p){return u(p,c.allocBuffer(p.length))}},m.array={string:_,array:A,arraybuffer:function(p){return new Uint8Array(p).buffer},uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return c.newBufferFrom(p)}},m.arraybuffer={string:function(p){return _(new Uint8Array(p))},array:function(p){return h(new Uint8Array(p),new Array(p.byteLength))},arraybuffer:A,uint8array:function(p){return new Uint8Array(p)},nodebuffer:function(p){return c.newBufferFrom(new Uint8Array(p))}},m.uint8array={string:_,array:function(p){return h(p,new Array(p.length))},arraybuffer:function(p){return p.buffer},uint8array:A,nodebuffer:function(p){return c.newBufferFrom(p)}},m.nodebuffer={string:_,array:function(p){return h(p,new Array(p.length))},arraybuffer:function(p){return m.nodebuffer.uint8array(p).buffer},uint8array:function(p){return h(p,new Uint8Array(p.length))},nodebuffer:A},r.transformTo=function(p,g){if(g=g||"",!p)return g;r.checkSupport(p);var f=r.getTypeOf(g);return m[f][p](g)},r.resolve=function(p){for(var g=p.split("/"),f=[],y=0;y<g.length;y++){var C=g[y];C==="."||C===""&&y!==0&&y!==g.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&&c.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 g,f,y="";for(f=0;f<(p||"").length;f++)y+="\\x"+((g=p.charCodeAt(f))<16?"0":"")+g.toString(16).toUpperCase();return y},r.delay=function(p,g,f){setImmediate(function(){p.apply(f||null,g||[])})},r.inherits=function(p,g){function f(){}f.prototype=g.prototype,p.prototype=new f},r.extend=function(){var p,g,f={};for(p=0;p<arguments.length;p++)for(g in arguments[p])Object.prototype.hasOwnProperty.call(arguments[p],g)&&f[g]===void 0&&(f[g]=arguments[p][g]);return f},r.prepareContent=function(p,g,f,y,C){return l.Promise.resolve(g).then(function(I){return s.blob&&(I instanceof Blob||["[object File]","[object Blob]"].indexOf(Object.prototype.toString.call(I))!==-1)&&typeof FileReader<"u"?new l.Promise(function(E,b){var P=new FileReader;P.onload=function(B){E(B.target.result)},P.onerror=function(B){b(B.target.error)},P.readAsArrayBuffer(I)}):I}).then(function(I){var E=r.getTypeOf(I);return E?(E==="arraybuffer"?I=r.transformTo("uint8array",I):E==="string"&&(C?I=a.decode(I):f&&y!==!0&&(I=(function(b){return u(b,s.uint8array?new Uint8Array(b.length):new Array(b.length))})(I))),I):l.Promise.reject(new Error("Can't read the data of '"+p+"'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"))})}},{"./base64":1,"./external":6,"./nodejsUtils":14,"./support":30,setimmediate:54}],33:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),c=o("./signature"),l=o("./zipEntry"),A=o("./support");function u(d){this.files=[],this.loadOptions=d}u.prototype={checkSignature:function(d){if(!this.reader.readAndCheckSignature(d)){this.reader.index-=4;var _=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+a.pretty(_)+", expected "+a.pretty(d)+")")}},isSignature:function(d,_){var h=this.reader.index;this.reader.setIndex(d);var m=this.reader.readString(4)===_;return this.reader.setIndex(h),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 d=this.reader.readData(this.zipCommentLength),_=A.uint8array?"uint8array":"array",h=a.transformTo(_,d);this.zipComment=this.loadOptions.decodeFileName(h)},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 d,_,h,m=this.zip64EndOfCentralSize-44;0<m;)d=this.reader.readInt(2),_=this.reader.readInt(4),h=this.reader.readData(_),this.zip64ExtensibleData[d]={id:d,length:_,value:h}},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 d,_;for(d=0;d<this.files.length;d++)_=this.files[d],this.reader.setIndex(_.localHeaderOffset),this.checkSignature(c.LOCAL_FILE_HEADER),_.readLocalPart(this.reader),_.handleUTF8(),_.processAttributes()},readCentralDir:function(){var d;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(c.CENTRAL_FILE_HEADER);)(d=new l({zip64:this.zip64},this.loadOptions)).readCentralPart(this.reader),this.files.push(d);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 d=this.reader.lastIndexOfSignature(c.CENTRAL_DIRECTORY_END);if(d<0)throw this.isSignature(0,c.LOCAL_FILE_HEADER)?new Error("Corrupted zip: can't find end of central directory"):new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");this.reader.setIndex(d);var _=d;if(this.checkSignature(c.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===a.MAX_VALUE_16BITS||this.diskWithCentralDirStart===a.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===a.MAX_VALUE_16BITS||this.centralDirRecords===a.MAX_VALUE_16BITS||this.centralDirSize===a.MAX_VALUE_32BITS||this.centralDirOffset===a.MAX_VALUE_32BITS){if(this.zip64=!0,(d=this.reader.lastIndexOfSignature(c.ZIP64_CENTRAL_DIRECTORY_LOCATOR))<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(d),this.checkSignature(c.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,c.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(c.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(c.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var h=this.centralDirOffset+this.centralDirSize;this.zip64&&(h+=20,h+=12+this.zip64EndOfCentralSize);var m=_-h;if(0<m)this.isSignature(_,c.CENTRAL_FILE_HEADER)||(this.reader.zero=m);else if(m<0)throw new Error("Corrupted zip: missing "+Math.abs(m)+" bytes.")},prepareReader:function(d){this.reader=s(d)},load:function(d){this.prepareReader(d),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},i.exports=u},{"./reader/readerFor":22,"./signature":23,"./support":30,"./utils":32,"./zipEntry":34}],34:[function(o,i,r){var s=o("./reader/readerFor"),a=o("./utils"),c=o("./compressedObject"),l=o("./crc32"),A=o("./utf8"),u=o("./compressions"),d=o("./support");function _(h,m){this.options=h,this.loadOptions=m}_.prototype={isEncrypted:function(){return(1&this.bitFlag)==1},useUTF8:function(){return(2048&this.bitFlag)==2048},readLocalPart:function(h){var m,p;if(h.skip(22),this.fileNameLength=h.readInt(2),p=h.readInt(2),this.fileName=h.readData(this.fileNameLength),h.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(g){for(var f in u)if(Object.prototype.hasOwnProperty.call(u,f)&&u[f].magic===g)return u[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 c(this.compressedSize,this.uncompressedSize,this.crc32,m,h.readData(this.compressedSize))},readCentralPart:function(h){this.versionMadeBy=h.readInt(2),h.skip(2),this.bitFlag=h.readInt(2),this.compressionMethod=h.readString(2),this.date=h.readDate(),this.crc32=h.readInt(4),this.compressedSize=h.readInt(4),this.uncompressedSize=h.readInt(4);var m=h.readInt(2);if(this.extraFieldsLength=h.readInt(2),this.fileCommentLength=h.readInt(2),this.diskNumberStart=h.readInt(2),this.internalFileAttributes=h.readInt(2),this.externalFileAttributes=h.readInt(4),this.localHeaderOffset=h.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");h.skip(m),this.readExtraFields(h),this.parseZIP64ExtraField(h),this.fileComment=h.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var h=this.versionMadeBy>>8;this.dir=!!(16&this.externalFileAttributes),h==0&&(this.dosPermissions=63&this.externalFileAttributes),h==3&&(this.unixPermissions=this.externalFileAttributes>>16&65535),this.dir||this.fileNameStr.slice(-1)!=="/"||(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var h=s(this.extraFields[1].value);this.uncompressedSize===a.MAX_VALUE_32BITS&&(this.uncompressedSize=h.readInt(8)),this.compressedSize===a.MAX_VALUE_32BITS&&(this.compressedSize=h.readInt(8)),this.localHeaderOffset===a.MAX_VALUE_32BITS&&(this.localHeaderOffset=h.readInt(8)),this.diskNumberStart===a.MAX_VALUE_32BITS&&(this.diskNumberStart=h.readInt(4))}},readExtraFields:function(h){var m,p,g,f=h.index+this.extraFieldsLength;for(this.extraFields||(this.extraFields={});h.index+4<f;)m=h.readInt(2),p=h.readInt(2),g=h.readData(p),this.extraFields[m]={id:m,length:p,value:g};h.setIndex(f)},handleUTF8:function(){var h=d.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=A.utf8decode(this.fileName),this.fileCommentStr=A.utf8decode(this.fileComment);else{var m=this.findExtraFieldUnicodePath();if(m!==null)this.fileNameStr=m;else{var p=a.transformTo(h,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(p)}var g=this.findExtraFieldUnicodeComment();if(g!==null)this.fileCommentStr=g;else{var f=a.transformTo(h,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(f)}}},findExtraFieldUnicodePath:function(){var h=this.extraFields[28789];if(h){var m=s(h.value);return m.readInt(1)!==1||l(this.fileName)!==m.readInt(4)?null:A.utf8decode(m.readData(h.length-5))}return null},findExtraFieldUnicodeComment:function(){var h=this.extraFields[25461];if(h){var m=s(h.value);return m.readInt(1)!==1||l(this.fileComment)!==m.readInt(4)?null:A.utf8decode(m.readData(h.length-5))}return null}},i.exports=_},{"./compressedObject":2,"./compressions":3,"./crc32":4,"./reader/readerFor":22,"./support":30,"./utf8":31,"./utils":32}],35:[function(o,i,r){function s(m,p,g){this.name=m,this.dir=g.dir,this.date=g.date,this.comment=g.comment,this.unixPermissions=g.unixPermissions,this.dosPermissions=g.dosPermissions,this._data=p,this._dataBinary=g.binary,this.options={compression:g.compression,compressionOptions:g.compressionOptions}}var a=o("./stream/StreamHelper"),c=o("./stream/DataWorker"),l=o("./utf8"),A=o("./compressedObject"),u=o("./stream/GenericWorker");s.prototype={internalStream:function(m){var p=null,g="string";try{if(!m)throw new Error("No output type specified.");var f=(g=m.toLowerCase())==="string"||g==="text";g!=="binarystring"&&g!=="text"||(g="string"),p=this._decompressWorker();var y=!this._dataBinary;y&&!f&&(p=p.pipe(new l.Utf8EncodeWorker)),!y&&f&&(p=p.pipe(new l.Utf8DecodeWorker))}catch(C){(p=new u("error")).error(C)}return new a(p,g,"")},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 A&&this._data.compression.magic===m.magic)return this._data.getCompressedWorker();var g=this._decompressWorker();return this._dataBinary||(g=g.pipe(new l.Utf8EncodeWorker)),A.createWorkerFrom(g,m,p)},_decompressWorker:function(){return this._data instanceof A?this._data.getContentWorker():this._data instanceof u?this._data:new c(this._data)}};for(var d=["asText","asBinary","asNodeBuffer","asUint8Array","asArrayBuffer"],_=function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},h=0;h<d.length;h++)s.prototype[d[h]]=_;i.exports=s},{"./compressedObject":2,"./stream/DataWorker":27,"./stream/GenericWorker":28,"./stream/StreamHelper":29,"./utf8":31}],36:[function(o,i,r){(function(s){var a,c,l=s.MutationObserver||s.WebKitMutationObserver;if(l){var A=0,u=new l(m),d=s.document.createTextNode("");u.observe(d,{characterData:!0}),a=function(){d.data=A=++A%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 _=new s.MessageChannel;_.port1.onmessage=m,a=function(){_.port2.postMessage(0)}}var h=[];function m(){var p,g;c=!0;for(var f=h.length;f;){for(g=h,h=[],p=-1;++p<f;)g[p]();f=h.length}c=!1}i.exports=function(p){h.push(p)!==1||c||a()}}).call(this,typeof GG<"u"?GG:typeof self<"u"?self:typeof window<"u"?window:{})},{}],37:[function(o,i,r){var s=o("immediate");function a(){}var c={},l=["REJECTED"],A=["FULFILLED"],u=["PENDING"];function d(f){if(typeof f!="function")throw new TypeError("resolver must be a function");this.state=u,this.queue=[],this.outcome=void 0,f!==a&&p(this,f)}function _(f,y,C){this.promise=f,typeof y=="function"&&(this.onFulfilled=y,this.callFulfilled=this.otherCallFulfilled),typeof C=="function"&&(this.onRejected=C,this.callRejected=this.otherCallRejected)}function h(f,y,C){s(function(){var I;try{I=y(C)}catch(E){return c.reject(f,E)}I===f?c.reject(f,new TypeError("Cannot resolve promise with itself")):c.resolve(f,I)})}function m(f){var y=f&&f.then;if(f&&(typeof f=="object"||typeof f=="function")&&typeof y=="function")return function(){y.apply(f,arguments)}}function p(f,y){var C=!1;function I(P){C||(C=!0,c.reject(f,P))}function E(P){C||(C=!0,c.resolve(f,P))}var b=g(function(){y(E,I)});b.status==="error"&&I(b.value)}function g(f,y){var C={};try{C.value=f(y),C.status="success"}catch(I){C.status="error",C.value=I}return C}(i.exports=d).prototype.finally=function(f){if(typeof f!="function")return this;var y=this.constructor;return this.then(function(C){return y.resolve(f()).then(function(){return C})},function(C){return y.resolve(f()).then(function(){throw C})})},d.prototype.catch=function(f){return this.then(null,f)},d.prototype.then=function(f,y){if(typeof f!="function"&&this.state===A||typeof y!="function"&&this.state===l)return this;var C=new this.constructor(a);return this.state!==u?h(C,this.state===A?f:y,this.outcome):this.queue.push(new _(C,f,y)),C},_.prototype.callFulfilled=function(f){c.resolve(this.promise,f)},_.prototype.otherCallFulfilled=function(f){h(this.promise,this.onFulfilled,f)},_.prototype.callRejected=function(f){c.reject(this.promise,f)},_.prototype.otherCallRejected=function(f){h(this.promise,this.onRejected,f)},c.resolve=function(f,y){var C=g(m,y);if(C.status==="error")return c.reject(f,C.value);var I=C.value;if(I)p(f,I);else{f.state=A,f.outcome=y;for(var E=-1,b=f.queue.length;++E<b;)f.queue[E].callFulfilled(y)}return f},c.reject=function(f,y){f.state=l,f.outcome=y;for(var C=-1,I=f.queue.length;++C<I;)f.queue[C].callRejected(y);return f},d.resolve=function(f){return f instanceof this?f:c.resolve(new this(a),f)},d.reject=function(f){var y=new this(a);return c.reject(y,f)},d.all=function(f){var y=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=f.length,I=!1;if(!C)return this.resolve([]);for(var E=new Array(C),b=0,P=-1,B=new this(a);++P<C;)M(f[P],P);return B;function M(R,k){y.resolve(R).then(function(H){E[k]=H,++b!==C||I||(I=!0,c.resolve(B,E))},function(H){I||(I=!0,c.reject(B,H))})}},d.race=function(f){var y=this;if(Object.prototype.toString.call(f)!=="[object Array]")return this.reject(new TypeError("must be an array"));var C=f.length,I=!1;if(!C)return this.resolve([]);for(var E=-1,b=new this(a);++E<C;)P=f[E],y.resolve(P).then(function(B){I||(I=!0,c.resolve(b,B))},function(B){I||(I=!0,c.reject(b,B))});var P;return b}},{immediate:36}],38:[function(o,i,r){var s={};(0,o("./lib/utils/common").assign)(s,o("./lib/deflate"),o("./lib/inflate"),o("./lib/zlib/constants")),i.exports=s},{"./lib/deflate":39,"./lib/inflate":40,"./lib/utils/common":41,"./lib/zlib/constants":44}],39:[function(o,i,r){var s=o("./zlib/deflate"),a=o("./utils/common"),c=o("./utils/strings"),l=o("./zlib/messages"),A=o("./zlib/zstream"),u=Object.prototype.toString,d=0,_=-1,h=0,m=8;function p(f){if(!(this instanceof p))return new p(f);this.options=a.assign({level:_,method:m,chunkSize:16384,windowBits:15,memLevel:8,strategy:h,to:""},f||{});var y=this.options;y.raw&&0<y.windowBits?y.windowBits=-y.windowBits:y.gzip&&0<y.windowBits&&y.windowBits<16&&(y.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new A,this.strm.avail_out=0;var C=s.deflateInit2(this.strm,y.level,y.method,y.windowBits,y.memLevel,y.strategy);if(C!==d)throw new Error(l[C]);if(y.header&&s.deflateSetHeader(this.strm,y.header),y.dictionary){var I;if(I=typeof y.dictionary=="string"?c.string2buf(y.dictionary):u.call(y.dictionary)==="[object ArrayBuffer]"?new Uint8Array(y.dictionary):y.dictionary,(C=s.deflateSetDictionary(this.strm,I))!==d)throw new Error(l[C]);this._dict_set=!0}}function g(f,y){var C=new p(y);if(C.push(f,!0),C.err)throw C.msg||l[C.err];return C.result}p.prototype.push=function(f,y){var C,I,E=this.strm,b=this.options.chunkSize;if(this.ended)return!1;I=y===~~y?y:y===!0?4:0,typeof f=="string"?E.input=c.string2buf(f):u.call(f)==="[object ArrayBuffer]"?E.input=new Uint8Array(f):E.input=f,E.next_in=0,E.avail_in=E.input.length;do{if(E.avail_out===0&&(E.output=new a.Buf8(b),E.next_out=0,E.avail_out=b),(C=s.deflate(E,I))!==1&&C!==d)return this.onEnd(C),!(this.ended=!0);E.avail_out!==0&&(E.avail_in!==0||I!==4&&I!==2)||(this.options.to==="string"?this.onData(c.buf2binstring(a.shrinkBuf(E.output,E.next_out))):this.onData(a.shrinkBuf(E.output,E.next_out)))}while((0<E.avail_in||E.avail_out===0)&&C!==1);return I===4?(C=s.deflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===d):I!==2||(this.onEnd(d),!(E.avail_out=0))},p.prototype.onData=function(f){this.chunks.push(f)},p.prototype.onEnd=function(f){f===d&&(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=g,r.deflateRaw=function(f,y){return(y=y||{}).raw=!0,g(f,y)},r.gzip=function(f,y){return(y=y||{}).gzip=!0,g(f,y)}},{"./utils/common":41,"./utils/strings":42,"./zlib/deflate":46,"./zlib/messages":51,"./zlib/zstream":53}],40:[function(o,i,r){var s=o("./zlib/inflate"),a=o("./utils/common"),c=o("./utils/strings"),l=o("./zlib/constants"),A=o("./zlib/messages"),u=o("./zlib/zstream"),d=o("./zlib/gzheader"),_=Object.prototype.toString;function h(p){if(!(this instanceof h))return new h(p);this.options=a.assign({chunkSize:16384,windowBits:0,to:""},p||{});var g=this.options;g.raw&&0<=g.windowBits&&g.windowBits<16&&(g.windowBits=-g.windowBits,g.windowBits===0&&(g.windowBits=-15)),!(0<=g.windowBits&&g.windowBits<16)||p&&p.windowBits||(g.windowBits+=32),15<g.windowBits&&g.windowBits<48&&(15&g.windowBits)==0&&(g.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new u,this.strm.avail_out=0;var f=s.inflateInit2(this.strm,g.windowBits);if(f!==l.Z_OK)throw new Error(A[f]);this.header=new d,s.inflateGetHeader(this.strm,this.header)}function m(p,g){var f=new h(g);if(f.push(p,!0),f.err)throw f.msg||A[f.err];return f.result}h.prototype.push=function(p,g){var f,y,C,I,E,b,P=this.strm,B=this.options.chunkSize,M=this.options.dictionary,R=!1;if(this.ended)return!1;y=g===~~g?g:g===!0?l.Z_FINISH:l.Z_NO_FLUSH,typeof p=="string"?P.input=c.binstring2buf(p):_.call(p)==="[object ArrayBuffer]"?P.input=new Uint8Array(p):P.input=p,P.next_in=0,P.avail_in=P.input.length;do{if(P.avail_out===0&&(P.output=new a.Buf8(B),P.next_out=0,P.avail_out=B),(f=s.inflate(P,l.Z_NO_FLUSH))===l.Z_NEED_DICT&&M&&(b=typeof M=="string"?c.string2buf(M):_.call(M)==="[object ArrayBuffer]"?new Uint8Array(M):M,f=s.inflateSetDictionary(this.strm,b)),f===l.Z_BUF_ERROR&&R===!0&&(f=l.Z_OK,R=!1),f!==l.Z_STREAM_END&&f!==l.Z_OK)return this.onEnd(f),!(this.ended=!0);P.next_out&&(P.avail_out!==0&&f!==l.Z_STREAM_END&&(P.avail_in!==0||y!==l.Z_FINISH&&y!==l.Z_SYNC_FLUSH)||(this.options.to==="string"?(C=c.utf8border(P.output,P.next_out),I=P.next_out-C,E=c.buf2string(P.output,C),P.next_out=I,P.avail_out=B-I,I&&a.arraySet(P.output,P.output,C,I,0),this.onData(E)):this.onData(a.shrinkBuf(P.output,P.next_out)))),P.avail_in===0&&P.avail_out===0&&(R=!0)}while((0<P.avail_in||P.avail_out===0)&&f!==l.Z_STREAM_END);return f===l.Z_STREAM_END&&(y=l.Z_FINISH),y===l.Z_FINISH?(f=s.inflateEnd(this.strm),this.onEnd(f),this.ended=!0,f===l.Z_OK):y!==l.Z_SYNC_FLUSH||(this.onEnd(l.Z_OK),!(P.avail_out=0))},h.prototype.onData=function(p){this.chunks.push(p)},h.prototype.onEnd=function(p){p===l.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=h,r.inflate=m,r.inflateRaw=function(p,g){return(g=g||{}).raw=!0,m(p,g)},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(l){for(var A=Array.prototype.slice.call(arguments,1);A.length;){var u=A.shift();if(u){if(typeof u!="object")throw new TypeError(u+"must be non-object");for(var d in u)u.hasOwnProperty(d)&&(l[d]=u[d])}}return l},r.shrinkBuf=function(l,A){return l.length===A?l:l.subarray?l.subarray(0,A):(l.length=A,l)};var a={arraySet:function(l,A,u,d,_){if(A.subarray&&l.subarray)l.set(A.subarray(u,u+d),_);else for(var h=0;h<d;h++)l[_+h]=A[u+h]},flattenChunks:function(l){var A,u,d,_,h,m;for(A=d=0,u=l.length;A<u;A++)d+=l[A].length;for(m=new Uint8Array(d),A=_=0,u=l.length;A<u;A++)h=l[A],m.set(h,_),_+=h.length;return m}},c={arraySet:function(l,A,u,d,_){for(var h=0;h<d;h++)l[_+h]=A[u+h]},flattenChunks:function(l){return[].concat.apply([],l)}};r.setTyped=function(l){l?(r.Buf8=Uint8Array,r.Buf16=Uint16Array,r.Buf32=Int32Array,r.assign(r,a)):(r.Buf8=Array,r.Buf16=Array,r.Buf32=Array,r.assign(r,c))},r.setTyped(s)},{}],42:[function(o,i,r){var s=o("./common"),a=!0,c=!0;try{String.fromCharCode.apply(null,[0])}catch{a=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{c=!1}for(var l=new s.Buf8(256),A=0;A<256;A++)l[A]=252<=A?6:248<=A?5:240<=A?4:224<=A?3:192<=A?2:1;function u(d,_){if(_<65537&&(d.subarray&&c||!d.subarray&&a))return String.fromCharCode.apply(null,s.shrinkBuf(d,_));for(var h="",m=0;m<_;m++)h+=String.fromCharCode(d[m]);return h}l[254]=l[254]=1,r.string2buf=function(d){var _,h,m,p,g,f=d.length,y=0;for(p=0;p<f;p++)(64512&(h=d.charCodeAt(p)))==55296&&p+1<f&&(64512&(m=d.charCodeAt(p+1)))==56320&&(h=65536+(h-55296<<10)+(m-56320),p++),y+=h<128?1:h<2048?2:h<65536?3:4;for(_=new s.Buf8(y),p=g=0;g<y;p++)(64512&(h=d.charCodeAt(p)))==55296&&p+1<f&&(64512&(m=d.charCodeAt(p+1)))==56320&&(h=65536+(h-55296<<10)+(m-56320),p++),h<128?_[g++]=h:(h<2048?_[g++]=192|h>>>6:(h<65536?_[g++]=224|h>>>12:(_[g++]=240|h>>>18,_[g++]=128|h>>>12&63),_[g++]=128|h>>>6&63),_[g++]=128|63&h);return _},r.buf2binstring=function(d){return u(d,d.length)},r.binstring2buf=function(d){for(var _=new s.Buf8(d.length),h=0,m=_.length;h<m;h++)_[h]=d.charCodeAt(h);return _},r.buf2string=function(d,_){var h,m,p,g,f=_||d.length,y=new Array(2*f);for(h=m=0;h<f;)if((p=d[h++])<128)y[m++]=p;else if(4<(g=l[p]))y[m++]=65533,h+=g-1;else{for(p&=g===2?31:g===3?15:7;1<g&&h<f;)p=p<<6|63&d[h++],g--;1<g?y[m++]=65533:p<65536?y[m++]=p:(p-=65536,y[m++]=55296|p>>10&1023,y[m++]=56320|1023&p)}return u(y,m)},r.utf8border=function(d,_){var h;for((_=_||d.length)>d.length&&(_=d.length),h=_-1;0<=h&&(192&d[h])==128;)h--;return h<0||h===0?_:h+l[d[h]]>_?h:_}},{"./common":41}],43:[function(o,i,r){i.exports=function(s,a,c,l){for(var A=65535&s|0,u=s>>>16&65535|0,d=0;c!==0;){for(c-=d=2e3<c?2e3:c;u=u+(A=A+a[l++]|0)|0,--d;);A%=65521,u%=65521}return A|u<<16|0}},{}],44:[function(o,i,r){i.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],45:[function(o,i,r){var s=(function(){for(var a,c=[],l=0;l<256;l++){a=l;for(var A=0;A<8;A++)a=1&a?3988292384^a>>>1:a>>>1;c[l]=a}return c})();i.exports=function(a,c,l,A){var u=s,d=A+l;a^=-1;for(var _=A;_<d;_++)a=a>>>8^u[255&(a^c[_])];return-1^a}},{}],46:[function(o,i,r){var s,a=o("../utils/common"),c=o("./trees"),l=o("./adler32"),A=o("./crc32"),u=o("./messages"),d=0,_=4,h=0,m=-2,p=-1,g=4,f=2,y=8,C=9,I=286,E=30,b=19,P=2*I+1,B=15,M=3,R=258,k=R+M+1,H=42,F=113,G=1,W=2,J=3,q=4;function oe(fe,qe){return fe.msg=u[qe],qe}function le(fe){return(fe<<1)-(4<fe?9:0)}function ee(fe){for(var qe=fe.length;0<=--qe;)fe[qe]=0}function re(fe){var qe=fe.state,Le=qe.pending;Le>fe.avail_out&&(Le=fe.avail_out),Le!==0&&(a.arraySet(fe.output,qe.pending_buf,qe.pending_out,Le,fe.next_out),fe.next_out+=Le,qe.pending_out+=Le,fe.total_out+=Le,fe.avail_out-=Le,qe.pending-=Le,qe.pending===0&&(qe.pending_out=0))}function ae(fe,qe){c._tr_flush_block(fe,0<=fe.block_start?fe.block_start:-1,fe.strstart-fe.block_start,qe),fe.block_start=fe.strstart,re(fe.strm)}function ie(fe,qe){fe.pending_buf[fe.pending++]=qe}function de(fe,qe){fe.pending_buf[fe.pending++]=qe>>>8&255,fe.pending_buf[fe.pending++]=255&qe}function ye(fe,qe){var Le,Qe,Ue=fe.max_chain_length,we=fe.strstart,Ee=fe.prev_length,Fe=fe.nice_match,Me=fe.strstart>fe.w_size-k?fe.strstart-(fe.w_size-k):0,ze=fe.window,je=fe.w_mask,it=fe.prev,at=fe.strstart+R,At=ze[we+Ee-1],lt=ze[we+Ee];fe.prev_length>=fe.good_match&&(Ue>>=2),Fe>fe.lookahead&&(Fe=fe.lookahead);do if(ze[(Le=qe)+Ee]===lt&&ze[Le+Ee-1]===At&&ze[Le]===ze[we]&&ze[++Le]===ze[we+1]){we+=2,Le++;do;while(ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&ze[++we]===ze[++Le]&&we<at);if(Qe=R-(at-we),we=at-R,Ee<Qe){if(fe.match_start=qe,Fe<=(Ee=Qe))break;At=ze[we+Ee-1],lt=ze[we+Ee]}}while((qe=it[qe&je])>Me&&--Ue!=0);return Ee<=fe.lookahead?Ee:fe.lookahead}function Ie(fe){var qe,Le,Qe,Ue,we,Ee,Fe,Me,ze,je,it=fe.w_size;do{if(Ue=fe.window_size-fe.lookahead-fe.strstart,fe.strstart>=it+(it-k)){for(a.arraySet(fe.window,fe.window,it,it,0),fe.match_start-=it,fe.strstart-=it,fe.block_start-=it,qe=Le=fe.hash_size;Qe=fe.head[--qe],fe.head[qe]=it<=Qe?Qe-it:0,--Le;);for(qe=Le=it;Qe=fe.prev[--qe],fe.prev[qe]=it<=Qe?Qe-it:0,--Le;);Ue+=it}if(fe.strm.avail_in===0)break;if(Ee=fe.strm,Fe=fe.window,Me=fe.strstart+fe.lookahead,ze=Ue,je=void 0,je=Ee.avail_in,ze<je&&(je=ze),Le=je===0?0:(Ee.avail_in-=je,a.arraySet(Fe,Ee.input,Ee.next_in,je,Me),Ee.state.wrap===1?Ee.adler=l(Ee.adler,Fe,je,Me):Ee.state.wrap===2&&(Ee.adler=A(Ee.adler,Fe,je,Me)),Ee.next_in+=je,Ee.total_in+=je,je),fe.lookahead+=Le,fe.lookahead+fe.insert>=M)for(we=fe.strstart-fe.insert,fe.ins_h=fe.window[we],fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[we+1])&fe.hash_mask;fe.insert&&(fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[we+M-1])&fe.hash_mask,fe.prev[we&fe.w_mask]=fe.head[fe.ins_h],fe.head[fe.ins_h]=we,we++,fe.insert--,!(fe.lookahead+fe.insert<M)););}while(fe.lookahead<k&&fe.strm.avail_in!==0)}function ve(fe,qe){for(var Le,Qe;;){if(fe.lookahead<k){if(Ie(fe),fe.lookahead<k&&qe===d)return G;if(fe.lookahead===0)break}if(Le=0,fe.lookahead>=M&&(fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[fe.strstart+M-1])&fe.hash_mask,Le=fe.prev[fe.strstart&fe.w_mask]=fe.head[fe.ins_h],fe.head[fe.ins_h]=fe.strstart),Le!==0&&fe.strstart-Le<=fe.w_size-k&&(fe.match_length=ye(fe,Le)),fe.match_length>=M)if(Qe=c._tr_tally(fe,fe.strstart-fe.match_start,fe.match_length-M),fe.lookahead-=fe.match_length,fe.match_length<=fe.max_lazy_match&&fe.lookahead>=M){for(fe.match_length--;fe.strstart++,fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[fe.strstart+M-1])&fe.hash_mask,Le=fe.prev[fe.strstart&fe.w_mask]=fe.head[fe.ins_h],fe.head[fe.ins_h]=fe.strstart,--fe.match_length!=0;);fe.strstart++}else fe.strstart+=fe.match_length,fe.match_length=0,fe.ins_h=fe.window[fe.strstart],fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[fe.strstart+1])&fe.hash_mask;else Qe=c._tr_tally(fe,0,fe.window[fe.strstart]),fe.lookahead--,fe.strstart++;if(Qe&&(ae(fe,!1),fe.strm.avail_out===0))return G}return fe.insert=fe.strstart<M-1?fe.strstart:M-1,qe===_?(ae(fe,!0),fe.strm.avail_out===0?J:q):fe.last_lit&&(ae(fe,!1),fe.strm.avail_out===0)?G:W}function ue(fe,qe){for(var Le,Qe,Ue;;){if(fe.lookahead<k){if(Ie(fe),fe.lookahead<k&&qe===d)return G;if(fe.lookahead===0)break}if(Le=0,fe.lookahead>=M&&(fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[fe.strstart+M-1])&fe.hash_mask,Le=fe.prev[fe.strstart&fe.w_mask]=fe.head[fe.ins_h],fe.head[fe.ins_h]=fe.strstart),fe.prev_length=fe.match_length,fe.prev_match=fe.match_start,fe.match_length=M-1,Le!==0&&fe.prev_length<fe.max_lazy_match&&fe.strstart-Le<=fe.w_size-k&&(fe.match_length=ye(fe,Le),fe.match_length<=5&&(fe.strategy===1||fe.match_length===M&&4096<fe.strstart-fe.match_start)&&(fe.match_length=M-1)),fe.prev_length>=M&&fe.match_length<=fe.prev_length){for(Ue=fe.strstart+fe.lookahead-M,Qe=c._tr_tally(fe,fe.strstart-1-fe.prev_match,fe.prev_length-M),fe.lookahead-=fe.prev_length-1,fe.prev_length-=2;++fe.strstart<=Ue&&(fe.ins_h=(fe.ins_h<<fe.hash_shift^fe.window[fe.strstart+M-1])&fe.hash_mask,Le=fe.prev[fe.strstart&fe.w_mask]=fe.head[fe.ins_h],fe.head[fe.ins_h]=fe.strstart),--fe.prev_length!=0;);if(fe.match_available=0,fe.match_length=M-1,fe.strstart++,Qe&&(ae(fe,!1),fe.strm.avail_out===0))return G}else if(fe.match_available){if((Qe=c._tr_tally(fe,0,fe.window[fe.strstart-1]))&&ae(fe,!1),fe.strstart++,fe.lookahead--,fe.strm.avail_out===0)return G}else fe.match_available=1,fe.strstart++,fe.lookahead--}return fe.match_available&&(Qe=c._tr_tally(fe,0,fe.window[fe.strstart-1]),fe.match_available=0),fe.insert=fe.strstart<M-1?fe.strstart:M-1,qe===_?(ae(fe,!0),fe.strm.avail_out===0?J:q):fe.last_lit&&(ae(fe,!1),fe.strm.avail_out===0)?G:W}function Se(fe,qe,Le,Qe,Ue){this.good_length=fe,this.max_lazy=qe,this.nice_length=Le,this.max_chain=Qe,this.func=Ue}function he(){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=y,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*P),this.dyn_dtree=new a.Buf16(2*(2*E+1)),this.bl_tree=new a.Buf16(2*(2*b+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*I+1),ee(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new a.Buf16(2*I+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 De(fe){var qe;return fe&&fe.state?(fe.total_in=fe.total_out=0,fe.data_type=f,(qe=fe.state).pending=0,qe.pending_out=0,qe.wrap<0&&(qe.wrap=-qe.wrap),qe.status=qe.wrap?H:F,fe.adler=qe.wrap===2?0:1,qe.last_flush=d,c._tr_init(qe),h):oe(fe,m)}function Ge(fe){var qe=De(fe);return qe===h&&(function(Le){Le.window_size=2*Le.w_size,ee(Le.head),Le.max_lazy_match=s[Le.level].max_lazy,Le.good_match=s[Le.level].good_length,Le.nice_match=s[Le.level].nice_length,Le.max_chain_length=s[Le.level].max_chain,Le.strstart=0,Le.block_start=0,Le.lookahead=0,Le.insert=0,Le.match_length=Le.prev_length=M-1,Le.match_available=0,Le.ins_h=0})(fe.state),qe}function Ye(fe,qe,Le,Qe,Ue,we){if(!fe)return m;var Ee=1;if(qe===p&&(qe=6),Qe<0?(Ee=0,Qe=-Qe):15<Qe&&(Ee=2,Qe-=16),Ue<1||C<Ue||Le!==y||Qe<8||15<Qe||qe<0||9<qe||we<0||g<we)return oe(fe,m);Qe===8&&(Qe=9);var Fe=new he;return(fe.state=Fe).strm=fe,Fe.wrap=Ee,Fe.gzhead=null,Fe.w_bits=Qe,Fe.w_size=1<<Fe.w_bits,Fe.w_mask=Fe.w_size-1,Fe.hash_bits=Ue+7,Fe.hash_size=1<<Fe.hash_bits,Fe.hash_mask=Fe.hash_size-1,Fe.hash_shift=~~((Fe.hash_bits+M-1)/M),Fe.window=new a.Buf8(2*Fe.w_size),Fe.head=new a.Buf16(Fe.hash_size),Fe.prev=new a.Buf16(Fe.w_size),Fe.lit_bufsize=1<<Ue+6,Fe.pending_buf_size=4*Fe.lit_bufsize,Fe.pending_buf=new a.Buf8(Fe.pending_buf_size),Fe.d_buf=1*Fe.lit_bufsize,Fe.l_buf=3*Fe.lit_bufsize,Fe.level=qe,Fe.strategy=we,Fe.method=Le,Ge(fe)}s=[new Se(0,0,0,0,function(fe,qe){var Le=65535;for(Le>fe.pending_buf_size-5&&(Le=fe.pending_buf_size-5);;){if(fe.lookahead<=1){if(Ie(fe),fe.lookahead===0&&qe===d)return G;if(fe.lookahead===0)break}fe.strstart+=fe.lookahead,fe.lookahead=0;var Qe=fe.block_start+Le;if((fe.strstart===0||fe.strstart>=Qe)&&(fe.lookahead=fe.strstart-Qe,fe.strstart=Qe,ae(fe,!1),fe.strm.avail_out===0)||fe.strstart-fe.block_start>=fe.w_size-k&&(ae(fe,!1),fe.strm.avail_out===0))return G}return fe.insert=0,qe===_?(ae(fe,!0),fe.strm.avail_out===0?J:q):(fe.strstart>fe.block_start&&(ae(fe,!1),fe.strm.avail_out),G)}),new Se(4,4,8,4,ve),new Se(4,5,16,8,ve),new Se(4,6,32,32,ve),new Se(4,4,16,16,ue),new Se(8,16,32,32,ue),new Se(8,16,128,128,ue),new Se(8,32,128,256,ue),new Se(32,128,258,1024,ue),new Se(32,258,258,4096,ue)],r.deflateInit=function(fe,qe){return Ye(fe,qe,y,15,8,0)},r.deflateInit2=Ye,r.deflateReset=Ge,r.deflateResetKeep=De,r.deflateSetHeader=function(fe,qe){return fe&&fe.state?fe.state.wrap!==2?m:(fe.state.gzhead=qe,h):m},r.deflate=function(fe,qe){var Le,Qe,Ue,we;if(!fe||!fe.state||5<qe||qe<0)return fe?oe(fe,m):m;if(Qe=fe.state,!fe.output||!fe.input&&fe.avail_in!==0||Qe.status===666&&qe!==_)return oe(fe,fe.avail_out===0?-5:m);if(Qe.strm=fe,Le=Qe.last_flush,Qe.last_flush=qe,Qe.status===H)if(Qe.wrap===2)fe.adler=0,ie(Qe,31),ie(Qe,139),ie(Qe,8),Qe.gzhead?(ie(Qe,(Qe.gzhead.text?1:0)+(Qe.gzhead.hcrc?2:0)+(Qe.gzhead.extra?4:0)+(Qe.gzhead.name?8:0)+(Qe.gzhead.comment?16:0)),ie(Qe,255&Qe.gzhead.time),ie(Qe,Qe.gzhead.time>>8&255),ie(Qe,Qe.gzhead.time>>16&255),ie(Qe,Qe.gzhead.time>>24&255),ie(Qe,Qe.level===9?2:2<=Qe.strategy||Qe.level<2?4:0),ie(Qe,255&Qe.gzhead.os),Qe.gzhead.extra&&Qe.gzhead.extra.length&&(ie(Qe,255&Qe.gzhead.extra.length),ie(Qe,Qe.gzhead.extra.length>>8&255)),Qe.gzhead.hcrc&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending,0)),Qe.gzindex=0,Qe.status=69):(ie(Qe,0),ie(Qe,0),ie(Qe,0),ie(Qe,0),ie(Qe,0),ie(Qe,Qe.level===9?2:2<=Qe.strategy||Qe.level<2?4:0),ie(Qe,3),Qe.status=F);else{var Ee=y+(Qe.w_bits-8<<4)<<8;Ee|=(2<=Qe.strategy||Qe.level<2?0:Qe.level<6?1:Qe.level===6?2:3)<<6,Qe.strstart!==0&&(Ee|=32),Ee+=31-Ee%31,Qe.status=F,de(Qe,Ee),Qe.strstart!==0&&(de(Qe,fe.adler>>>16),de(Qe,65535&fe.adler)),fe.adler=1}if(Qe.status===69)if(Qe.gzhead.extra){for(Ue=Qe.pending;Qe.gzindex<(65535&Qe.gzhead.extra.length)&&(Qe.pending!==Qe.pending_buf_size||(Qe.gzhead.hcrc&&Qe.pending>Ue&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending-Ue,Ue)),re(fe),Ue=Qe.pending,Qe.pending!==Qe.pending_buf_size));)ie(Qe,255&Qe.gzhead.extra[Qe.gzindex]),Qe.gzindex++;Qe.gzhead.hcrc&&Qe.pending>Ue&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending-Ue,Ue)),Qe.gzindex===Qe.gzhead.extra.length&&(Qe.gzindex=0,Qe.status=73)}else Qe.status=73;if(Qe.status===73)if(Qe.gzhead.name){Ue=Qe.pending;do{if(Qe.pending===Qe.pending_buf_size&&(Qe.gzhead.hcrc&&Qe.pending>Ue&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending-Ue,Ue)),re(fe),Ue=Qe.pending,Qe.pending===Qe.pending_buf_size)){we=1;break}we=Qe.gzindex<Qe.gzhead.name.length?255&Qe.gzhead.name.charCodeAt(Qe.gzindex++):0,ie(Qe,we)}while(we!==0);Qe.gzhead.hcrc&&Qe.pending>Ue&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending-Ue,Ue)),we===0&&(Qe.gzindex=0,Qe.status=91)}else Qe.status=91;if(Qe.status===91)if(Qe.gzhead.comment){Ue=Qe.pending;do{if(Qe.pending===Qe.pending_buf_size&&(Qe.gzhead.hcrc&&Qe.pending>Ue&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending-Ue,Ue)),re(fe),Ue=Qe.pending,Qe.pending===Qe.pending_buf_size)){we=1;break}we=Qe.gzindex<Qe.gzhead.comment.length?255&Qe.gzhead.comment.charCodeAt(Qe.gzindex++):0,ie(Qe,we)}while(we!==0);Qe.gzhead.hcrc&&Qe.pending>Ue&&(fe.adler=A(fe.adler,Qe.pending_buf,Qe.pending-Ue,Ue)),we===0&&(Qe.status=103)}else Qe.status=103;if(Qe.status===103&&(Qe.gzhead.hcrc?(Qe.pending+2>Qe.pending_buf_size&&re(fe),Qe.pending+2<=Qe.pending_buf_size&&(ie(Qe,255&fe.adler),ie(Qe,fe.adler>>8&255),fe.adler=0,Qe.status=F)):Qe.status=F),Qe.pending!==0){if(re(fe),fe.avail_out===0)return Qe.last_flush=-1,h}else if(fe.avail_in===0&&le(qe)<=le(Le)&&qe!==_)return oe(fe,-5);if(Qe.status===666&&fe.avail_in!==0)return oe(fe,-5);if(fe.avail_in!==0||Qe.lookahead!==0||qe!==d&&Qe.status!==666){var Fe=Qe.strategy===2?(function(Me,ze){for(var je;;){if(Me.lookahead===0&&(Ie(Me),Me.lookahead===0)){if(ze===d)return G;break}if(Me.match_length=0,je=c._tr_tally(Me,0,Me.window[Me.strstart]),Me.lookahead--,Me.strstart++,je&&(ae(Me,!1),Me.strm.avail_out===0))return G}return Me.insert=0,ze===_?(ae(Me,!0),Me.strm.avail_out===0?J:q):Me.last_lit&&(ae(Me,!1),Me.strm.avail_out===0)?G:W})(Qe,qe):Qe.strategy===3?(function(Me,ze){for(var je,it,at,At,lt=Me.window;;){if(Me.lookahead<=R){if(Ie(Me),Me.lookahead<=R&&ze===d)return G;if(Me.lookahead===0)break}if(Me.match_length=0,Me.lookahead>=M&&0<Me.strstart&&(it=lt[at=Me.strstart-1])===lt[++at]&&it===lt[++at]&&it===lt[++at]){At=Me.strstart+R;do;while(it===lt[++at]&&it===lt[++at]&&it===lt[++at]&&it===lt[++at]&&it===lt[++at]&&it===lt[++at]&&it===lt[++at]&&it===lt[++at]&&at<At);Me.match_length=R-(At-at),Me.match_length>Me.lookahead&&(Me.match_length=Me.lookahead)}if(Me.match_length>=M?(je=c._tr_tally(Me,1,Me.match_length-M),Me.lookahead-=Me.match_length,Me.strstart+=Me.match_length,Me.match_length=0):(je=c._tr_tally(Me,0,Me.window[Me.strstart]),Me.lookahead--,Me.strstart++),je&&(ae(Me,!1),Me.strm.avail_out===0))return G}return Me.insert=0,ze===_?(ae(Me,!0),Me.strm.avail_out===0?J:q):Me.last_lit&&(ae(Me,!1),Me.strm.avail_out===0)?G:W})(Qe,qe):s[Qe.level].func(Qe,qe);if(Fe!==J&&Fe!==q||(Qe.status=666),Fe===G||Fe===J)return fe.avail_out===0&&(Qe.last_flush=-1),h;if(Fe===W&&(qe===1?c._tr_align(Qe):qe!==5&&(c._tr_stored_block(Qe,0,0,!1),qe===3&&(ee(Qe.head),Qe.lookahead===0&&(Qe.strstart=0,Qe.block_start=0,Qe.insert=0))),re(fe),fe.avail_out===0))return Qe.last_flush=-1,h}return qe!==_?h:Qe.wrap<=0?1:(Qe.wrap===2?(ie(Qe,255&fe.adler),ie(Qe,fe.adler>>8&255),ie(Qe,fe.adler>>16&255),ie(Qe,fe.adler>>24&255),ie(Qe,255&fe.total_in),ie(Qe,fe.total_in>>8&255),ie(Qe,fe.total_in>>16&255),ie(Qe,fe.total_in>>24&255)):(de(Qe,fe.adler>>>16),de(Qe,65535&fe.adler)),re(fe),0<Qe.wrap&&(Qe.wrap=-Qe.wrap),Qe.pending!==0?h:1)},r.deflateEnd=function(fe){var qe;return fe&&fe.state?(qe=fe.state.status)!==H&&qe!==69&&qe!==73&&qe!==91&&qe!==103&&qe!==F&&qe!==666?oe(fe,m):(fe.state=null,qe===F?oe(fe,-3):h):m},r.deflateSetDictionary=function(fe,qe){var Le,Qe,Ue,we,Ee,Fe,Me,ze,je=qe.length;if(!fe||!fe.state||(we=(Le=fe.state).wrap)===2||we===1&&Le.status!==H||Le.lookahead)return m;for(we===1&&(fe.adler=l(fe.adler,qe,je,0)),Le.wrap=0,je>=Le.w_size&&(we===0&&(ee(Le.head),Le.strstart=0,Le.block_start=0,Le.insert=0),ze=new a.Buf8(Le.w_size),a.arraySet(ze,qe,je-Le.w_size,Le.w_size,0),qe=ze,je=Le.w_size),Ee=fe.avail_in,Fe=fe.next_in,Me=fe.input,fe.avail_in=je,fe.next_in=0,fe.input=qe,Ie(Le);Le.lookahead>=M;){for(Qe=Le.strstart,Ue=Le.lookahead-(M-1);Le.ins_h=(Le.ins_h<<Le.hash_shift^Le.window[Qe+M-1])&Le.hash_mask,Le.prev[Qe&Le.w_mask]=Le.head[Le.ins_h],Le.head[Le.ins_h]=Qe,Qe++,--Ue;);Le.strstart=Qe,Le.lookahead=M-1,Ie(Le)}return Le.strstart+=Le.lookahead,Le.block_start=Le.strstart,Le.insert=Le.lookahead,Le.lookahead=0,Le.match_length=Le.prev_length=M-1,Le.match_available=0,fe.next_in=Fe,fe.input=Me,fe.avail_in=Ee,Le.wrap=we,h},r.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./messages":51,"./trees":52}],47:[function(o,i,r){i.exports=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}},{}],48:[function(o,i,r){i.exports=function(s,a){var c,l,A,u,d,_,h,m,p,g,f,y,C,I,E,b,P,B,M,R,k,H,F,G,W;c=s.state,l=s.next_in,G=s.input,A=l+(s.avail_in-5),u=s.next_out,W=s.output,d=u-(a-s.avail_out),_=u+(s.avail_out-257),h=c.dmax,m=c.wsize,p=c.whave,g=c.wnext,f=c.window,y=c.hold,C=c.bits,I=c.lencode,E=c.distcode,b=(1<<c.lenbits)-1,P=(1<<c.distbits)-1;e:do{C<15&&(y+=G[l++]<<C,C+=8,y+=G[l++]<<C,C+=8),B=I[y&b];t:for(;;){if(y>>>=M=B>>>24,C-=M,(M=B>>>16&255)===0)W[u++]=65535&B;else{if(!(16&M)){if((64&M)==0){B=I[(65535&B)+(y&(1<<M)-1)];continue t}if(32&M){c.mode=12;break e}s.msg="invalid literal/length code",c.mode=30;break e}R=65535&B,(M&=15)&&(C<M&&(y+=G[l++]<<C,C+=8),R+=y&(1<<M)-1,y>>>=M,C-=M),C<15&&(y+=G[l++]<<C,C+=8,y+=G[l++]<<C,C+=8),B=E[y&P];n:for(;;){if(y>>>=M=B>>>24,C-=M,!(16&(M=B>>>16&255))){if((64&M)==0){B=E[(65535&B)+(y&(1<<M)-1)];continue n}s.msg="invalid distance code",c.mode=30;break e}if(k=65535&B,C<(M&=15)&&(y+=G[l++]<<C,(C+=8)<M&&(y+=G[l++]<<C,C+=8)),h<(k+=y&(1<<M)-1)){s.msg="invalid distance too far back",c.mode=30;break e}if(y>>>=M,C-=M,(M=u-d)<k){if(p<(M=k-M)&&c.sane){s.msg="invalid distance too far back",c.mode=30;break e}if(F=f,(H=0)===g){if(H+=m-M,M<R){for(R-=M;W[u++]=f[H++],--M;);H=u-k,F=W}}else if(g<M){if(H+=m+g-M,(M-=g)<R){for(R-=M;W[u++]=f[H++],--M;);if(H=0,g<R){for(R-=M=g;W[u++]=f[H++],--M;);H=u-k,F=W}}}else if(H+=g-M,M<R){for(R-=M;W[u++]=f[H++],--M;);H=u-k,F=W}for(;2<R;)W[u++]=F[H++],W[u++]=F[H++],W[u++]=F[H++],R-=3;R&&(W[u++]=F[H++],1<R&&(W[u++]=F[H++]))}else{for(H=u-k;W[u++]=W[H++],W[u++]=W[H++],W[u++]=W[H++],2<(R-=3););R&&(W[u++]=W[H++],1<R&&(W[u++]=W[H++]))}break}}break}}while(l<A&&u<_);l-=R=C>>3,y&=(1<<(C-=R<<3))-1,s.next_in=l,s.next_out=u,s.avail_in=l<A?A-l+5:5-(l-A),s.avail_out=u<_?_-u+257:257-(u-_),c.hold=y,c.bits=C}},{}],49:[function(o,i,r){var s=o("../utils/common"),a=o("./adler32"),c=o("./crc32"),l=o("./inffast"),A=o("./inftrees"),u=1,d=2,_=0,h=-2,m=1,p=852,g=592;function f(H){return(H>>>24&255)+(H>>>8&65280)+((65280&H)<<8)+((255&H)<<24)}function y(){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(H){var F;return H&&H.state?(F=H.state,H.total_in=H.total_out=F.total=0,H.msg="",F.wrap&&(H.adler=1&F.wrap),F.mode=m,F.last=0,F.havedict=0,F.dmax=32768,F.head=null,F.hold=0,F.bits=0,F.lencode=F.lendyn=new s.Buf32(p),F.distcode=F.distdyn=new s.Buf32(g),F.sane=1,F.back=-1,_):h}function I(H){var F;return H&&H.state?((F=H.state).wsize=0,F.whave=0,F.wnext=0,C(H)):h}function E(H,F){var G,W;return H&&H.state?(W=H.state,F<0?(G=0,F=-F):(G=1+(F>>4),F<48&&(F&=15)),F&&(F<8||15<F)?h:(W.window!==null&&W.wbits!==F&&(W.window=null),W.wrap=G,W.wbits=F,I(H))):h}function b(H,F){var G,W;return H?(W=new y,(H.state=W).window=null,(G=E(H,F))!==_&&(H.state=null),G):h}var P,B,M=!0;function R(H){if(M){var F;for(P=new s.Buf32(512),B=new s.Buf32(32),F=0;F<144;)H.lens[F++]=8;for(;F<256;)H.lens[F++]=9;for(;F<280;)H.lens[F++]=7;for(;F<288;)H.lens[F++]=8;for(A(u,H.lens,0,288,P,0,H.work,{bits:9}),F=0;F<32;)H.lens[F++]=5;A(d,H.lens,0,32,B,0,H.work,{bits:5}),M=!1}H.lencode=P,H.lenbits=9,H.distcode=B,H.distbits=5}function k(H,F,G,W){var J,q=H.state;return q.window===null&&(q.wsize=1<<q.wbits,q.wnext=0,q.whave=0,q.window=new s.Buf8(q.wsize)),W>=q.wsize?(s.arraySet(q.window,F,G-q.wsize,q.wsize,0),q.wnext=0,q.whave=q.wsize):(W<(J=q.wsize-q.wnext)&&(J=W),s.arraySet(q.window,F,G-W,J,q.wnext),(W-=J)?(s.arraySet(q.window,F,G-W,W,0),q.wnext=W,q.whave=q.wsize):(q.wnext+=J,q.wnext===q.wsize&&(q.wnext=0),q.whave<q.wsize&&(q.whave+=J))),0}r.inflateReset=I,r.inflateReset2=E,r.inflateResetKeep=C,r.inflateInit=function(H){return b(H,15)},r.inflateInit2=b,r.inflate=function(H,F){var G,W,J,q,oe,le,ee,re,ae,ie,de,ye,Ie,ve,ue,Se,he,De,Ge,Ye,fe,qe,Le,Qe,Ue=0,we=new s.Buf8(4),Ee=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!H||!H.state||!H.output||!H.input&&H.avail_in!==0)return h;(G=H.state).mode===12&&(G.mode=13),oe=H.next_out,J=H.output,ee=H.avail_out,q=H.next_in,W=H.input,le=H.avail_in,re=G.hold,ae=G.bits,ie=le,de=ee,qe=_;e:for(;;)switch(G.mode){case m:if(G.wrap===0){G.mode=13;break}for(;ae<16;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(2&G.wrap&&re===35615){we[G.check=0]=255&re,we[1]=re>>>8&255,G.check=c(G.check,we,2,0),ae=re=0,G.mode=2;break}if(G.flags=0,G.head&&(G.head.done=!1),!(1&G.wrap)||(((255&re)<<8)+(re>>8))%31){H.msg="incorrect header check",G.mode=30;break}if((15&re)!=8){H.msg="unknown compression method",G.mode=30;break}if(ae-=4,fe=8+(15&(re>>>=4)),G.wbits===0)G.wbits=fe;else if(fe>G.wbits){H.msg="invalid window size",G.mode=30;break}G.dmax=1<<fe,H.adler=G.check=1,G.mode=512&re?10:12,ae=re=0;break;case 2:for(;ae<16;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(G.flags=re,(255&G.flags)!=8){H.msg="unknown compression method",G.mode=30;break}if(57344&G.flags){H.msg="unknown header flags set",G.mode=30;break}G.head&&(G.head.text=re>>8&1),512&G.flags&&(we[0]=255&re,we[1]=re>>>8&255,G.check=c(G.check,we,2,0)),ae=re=0,G.mode=3;case 3:for(;ae<32;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}G.head&&(G.head.time=re),512&G.flags&&(we[0]=255&re,we[1]=re>>>8&255,we[2]=re>>>16&255,we[3]=re>>>24&255,G.check=c(G.check,we,4,0)),ae=re=0,G.mode=4;case 4:for(;ae<16;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}G.head&&(G.head.xflags=255&re,G.head.os=re>>8),512&G.flags&&(we[0]=255&re,we[1]=re>>>8&255,G.check=c(G.check,we,2,0)),ae=re=0,G.mode=5;case 5:if(1024&G.flags){for(;ae<16;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}G.length=re,G.head&&(G.head.extra_len=re),512&G.flags&&(we[0]=255&re,we[1]=re>>>8&255,G.check=c(G.check,we,2,0)),ae=re=0}else G.head&&(G.head.extra=null);G.mode=6;case 6:if(1024&G.flags&&(le<(ye=G.length)&&(ye=le),ye&&(G.head&&(fe=G.head.extra_len-G.length,G.head.extra||(G.head.extra=new Array(G.head.extra_len)),s.arraySet(G.head.extra,W,q,ye,fe)),512&G.flags&&(G.check=c(G.check,W,ye,q)),le-=ye,q+=ye,G.length-=ye),G.length))break e;G.length=0,G.mode=7;case 7:if(2048&G.flags){if(le===0)break e;for(ye=0;fe=W[q+ye++],G.head&&fe&&G.length<65536&&(G.head.name+=String.fromCharCode(fe)),fe&&ye<le;);if(512&G.flags&&(G.check=c(G.check,W,ye,q)),le-=ye,q+=ye,fe)break e}else G.head&&(G.head.name=null);G.length=0,G.mode=8;case 8:if(4096&G.flags){if(le===0)break e;for(ye=0;fe=W[q+ye++],G.head&&fe&&G.length<65536&&(G.head.comment+=String.fromCharCode(fe)),fe&&ye<le;);if(512&G.flags&&(G.check=c(G.check,W,ye,q)),le-=ye,q+=ye,fe)break e}else G.head&&(G.head.comment=null);G.mode=9;case 9:if(512&G.flags){for(;ae<16;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(re!==(65535&G.check)){H.msg="header crc mismatch",G.mode=30;break}ae=re=0}G.head&&(G.head.hcrc=G.flags>>9&1,G.head.done=!0),H.adler=G.check=0,G.mode=12;break;case 10:for(;ae<32;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}H.adler=G.check=f(re),ae=re=0,G.mode=11;case 11:if(G.havedict===0)return H.next_out=oe,H.avail_out=ee,H.next_in=q,H.avail_in=le,G.hold=re,G.bits=ae,2;H.adler=G.check=1,G.mode=12;case 12:if(F===5||F===6)break e;case 13:if(G.last){re>>>=7&ae,ae-=7&ae,G.mode=27;break}for(;ae<3;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}switch(G.last=1&re,ae-=1,3&(re>>>=1)){case 0:G.mode=14;break;case 1:if(R(G),G.mode=20,F!==6)break;re>>>=2,ae-=2;break e;case 2:G.mode=17;break;case 3:H.msg="invalid block type",G.mode=30}re>>>=2,ae-=2;break;case 14:for(re>>>=7&ae,ae-=7&ae;ae<32;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if((65535&re)!=(re>>>16^65535)){H.msg="invalid stored block lengths",G.mode=30;break}if(G.length=65535&re,ae=re=0,G.mode=15,F===6)break e;case 15:G.mode=16;case 16:if(ye=G.length){if(le<ye&&(ye=le),ee<ye&&(ye=ee),ye===0)break e;s.arraySet(J,W,q,ye,oe),le-=ye,q+=ye,ee-=ye,oe+=ye,G.length-=ye;break}G.mode=12;break;case 17:for(;ae<14;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(G.nlen=257+(31&re),re>>>=5,ae-=5,G.ndist=1+(31&re),re>>>=5,ae-=5,G.ncode=4+(15&re),re>>>=4,ae-=4,286<G.nlen||30<G.ndist){H.msg="too many length or distance symbols",G.mode=30;break}G.have=0,G.mode=18;case 18:for(;G.have<G.ncode;){for(;ae<3;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}G.lens[Ee[G.have++]]=7&re,re>>>=3,ae-=3}for(;G.have<19;)G.lens[Ee[G.have++]]=0;if(G.lencode=G.lendyn,G.lenbits=7,Le={bits:G.lenbits},qe=A(0,G.lens,0,19,G.lencode,0,G.work,Le),G.lenbits=Le.bits,qe){H.msg="invalid code lengths set",G.mode=30;break}G.have=0,G.mode=19;case 19:for(;G.have<G.nlen+G.ndist;){for(;Se=(Ue=G.lencode[re&(1<<G.lenbits)-1])>>>16&255,he=65535&Ue,!((ue=Ue>>>24)<=ae);){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(he<16)re>>>=ue,ae-=ue,G.lens[G.have++]=he;else{if(he===16){for(Qe=ue+2;ae<Qe;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(re>>>=ue,ae-=ue,G.have===0){H.msg="invalid bit length repeat",G.mode=30;break}fe=G.lens[G.have-1],ye=3+(3&re),re>>>=2,ae-=2}else if(he===17){for(Qe=ue+3;ae<Qe;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}ae-=ue,fe=0,ye=3+(7&(re>>>=ue)),re>>>=3,ae-=3}else{for(Qe=ue+7;ae<Qe;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}ae-=ue,fe=0,ye=11+(127&(re>>>=ue)),re>>>=7,ae-=7}if(G.have+ye>G.nlen+G.ndist){H.msg="invalid bit length repeat",G.mode=30;break}for(;ye--;)G.lens[G.have++]=fe}}if(G.mode===30)break;if(G.lens[256]===0){H.msg="invalid code -- missing end-of-block",G.mode=30;break}if(G.lenbits=9,Le={bits:G.lenbits},qe=A(u,G.lens,0,G.nlen,G.lencode,0,G.work,Le),G.lenbits=Le.bits,qe){H.msg="invalid literal/lengths set",G.mode=30;break}if(G.distbits=6,G.distcode=G.distdyn,Le={bits:G.distbits},qe=A(d,G.lens,G.nlen,G.ndist,G.distcode,0,G.work,Le),G.distbits=Le.bits,qe){H.msg="invalid distances set",G.mode=30;break}if(G.mode=20,F===6)break e;case 20:G.mode=21;case 21:if(6<=le&&258<=ee){H.next_out=oe,H.avail_out=ee,H.next_in=q,H.avail_in=le,G.hold=re,G.bits=ae,l(H,de),oe=H.next_out,J=H.output,ee=H.avail_out,q=H.next_in,W=H.input,le=H.avail_in,re=G.hold,ae=G.bits,G.mode===12&&(G.back=-1);break}for(G.back=0;Se=(Ue=G.lencode[re&(1<<G.lenbits)-1])>>>16&255,he=65535&Ue,!((ue=Ue>>>24)<=ae);){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(Se&&(240&Se)==0){for(De=ue,Ge=Se,Ye=he;Se=(Ue=G.lencode[Ye+((re&(1<<De+Ge)-1)>>De)])>>>16&255,he=65535&Ue,!(De+(ue=Ue>>>24)<=ae);){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}re>>>=De,ae-=De,G.back+=De}if(re>>>=ue,ae-=ue,G.back+=ue,G.length=he,Se===0){G.mode=26;break}if(32&Se){G.back=-1,G.mode=12;break}if(64&Se){H.msg="invalid literal/length code",G.mode=30;break}G.extra=15&Se,G.mode=22;case 22:if(G.extra){for(Qe=G.extra;ae<Qe;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}G.length+=re&(1<<G.extra)-1,re>>>=G.extra,ae-=G.extra,G.back+=G.extra}G.was=G.length,G.mode=23;case 23:for(;Se=(Ue=G.distcode[re&(1<<G.distbits)-1])>>>16&255,he=65535&Ue,!((ue=Ue>>>24)<=ae);){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if((240&Se)==0){for(De=ue,Ge=Se,Ye=he;Se=(Ue=G.distcode[Ye+((re&(1<<De+Ge)-1)>>De)])>>>16&255,he=65535&Ue,!(De+(ue=Ue>>>24)<=ae);){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}re>>>=De,ae-=De,G.back+=De}if(re>>>=ue,ae-=ue,G.back+=ue,64&Se){H.msg="invalid distance code",G.mode=30;break}G.offset=he,G.extra=15&Se,G.mode=24;case 24:if(G.extra){for(Qe=G.extra;ae<Qe;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}G.offset+=re&(1<<G.extra)-1,re>>>=G.extra,ae-=G.extra,G.back+=G.extra}if(G.offset>G.dmax){H.msg="invalid distance too far back",G.mode=30;break}G.mode=25;case 25:if(ee===0)break e;if(ye=de-ee,G.offset>ye){if((ye=G.offset-ye)>G.whave&&G.sane){H.msg="invalid distance too far back",G.mode=30;break}Ie=ye>G.wnext?(ye-=G.wnext,G.wsize-ye):G.wnext-ye,ye>G.length&&(ye=G.length),ve=G.window}else ve=J,Ie=oe-G.offset,ye=G.length;for(ee<ye&&(ye=ee),ee-=ye,G.length-=ye;J[oe++]=ve[Ie++],--ye;);G.length===0&&(G.mode=21);break;case 26:if(ee===0)break e;J[oe++]=G.length,ee--,G.mode=21;break;case 27:if(G.wrap){for(;ae<32;){if(le===0)break e;le--,re|=W[q++]<<ae,ae+=8}if(de-=ee,H.total_out+=de,G.total+=de,de&&(H.adler=G.check=G.flags?c(G.check,J,de,oe-de):a(G.check,J,de,oe-de)),de=ee,(G.flags?re:f(re))!==G.check){H.msg="incorrect data check",G.mode=30;break}ae=re=0}G.mode=28;case 28:if(G.wrap&&G.flags){for(;ae<32;){if(le===0)break e;le--,re+=W[q++]<<ae,ae+=8}if(re!==(4294967295&G.total)){H.msg="incorrect length check",G.mode=30;break}ae=re=0}G.mode=29;case 29:qe=1;break e;case 30:qe=-3;break e;case 31:return-4;default:return h}return H.next_out=oe,H.avail_out=ee,H.next_in=q,H.avail_in=le,G.hold=re,G.bits=ae,(G.wsize||de!==H.avail_out&&G.mode<30&&(G.mode<27||F!==4))&&k(H,H.output,H.next_out,de-H.avail_out)?(G.mode=31,-4):(ie-=H.avail_in,de-=H.avail_out,H.total_in+=ie,H.total_out+=de,G.total+=de,G.wrap&&de&&(H.adler=G.check=G.flags?c(G.check,J,de,H.next_out-de):a(G.check,J,de,H.next_out-de)),H.data_type=G.bits+(G.last?64:0)+(G.mode===12?128:0)+(G.mode===20||G.mode===15?256:0),(ie==0&&de===0||F===4)&&qe===_&&(qe=-5),qe)},r.inflateEnd=function(H){if(!H||!H.state)return h;var F=H.state;return F.window&&(F.window=null),H.state=null,_},r.inflateGetHeader=function(H,F){var G;return H&&H.state?(2&(G=H.state).wrap)==0?h:((G.head=F).done=!1,_):h},r.inflateSetDictionary=function(H,F){var G,W=F.length;return H&&H.state?(G=H.state).wrap!==0&&G.mode!==11?h:G.mode===11&&a(1,F,W,0)!==G.check?-3:k(H,F,W,W)?(G.mode=31,-4):(G.havedict=1,_):h},r.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":41,"./adler32":43,"./crc32":45,"./inffast":48,"./inftrees":50}],50:[function(o,i,r){var s=o("../utils/common"),a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],c=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],l=[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],A=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];i.exports=function(u,d,_,h,m,p,g,f){var y,C,I,E,b,P,B,M,R,k=f.bits,H=0,F=0,G=0,W=0,J=0,q=0,oe=0,le=0,ee=0,re=0,ae=null,ie=0,de=new s.Buf16(16),ye=new s.Buf16(16),Ie=null,ve=0;for(H=0;H<=15;H++)de[H]=0;for(F=0;F<h;F++)de[d[_+F]]++;for(J=k,W=15;1<=W&&de[W]===0;W--);if(W<J&&(J=W),W===0)return m[p++]=20971520,m[p++]=20971520,f.bits=1,0;for(G=1;G<W&&de[G]===0;G++);for(J<G&&(J=G),H=le=1;H<=15;H++)if(le<<=1,(le-=de[H])<0)return-1;if(0<le&&(u===0||W!==1))return-1;for(ye[1]=0,H=1;H<15;H++)ye[H+1]=ye[H]+de[H];for(F=0;F<h;F++)d[_+F]!==0&&(g[ye[d[_+F]]++]=F);if(P=u===0?(ae=Ie=g,19):u===1?(ae=a,ie-=257,Ie=c,ve-=257,256):(ae=l,Ie=A,-1),H=G,b=p,oe=F=re=0,I=-1,E=(ee=1<<(q=J))-1,u===1&&852<ee||u===2&&592<ee)return 1;for(;;){for(B=H-oe,R=g[F]<P?(M=0,g[F]):g[F]>P?(M=Ie[ve+g[F]],ae[ie+g[F]]):(M=96,0),y=1<<H-oe,G=C=1<<q;m[b+(re>>oe)+(C-=y)]=B<<24|M<<16|R|0,C!==0;);for(y=1<<H-1;re&y;)y>>=1;if(y!==0?(re&=y-1,re+=y):re=0,F++,--de[H]==0){if(H===W)break;H=d[_+g[F]]}if(J<H&&(re&E)!==I){for(oe===0&&(oe=J),b+=G,le=1<<(q=H-oe);q+oe<W&&!((le-=de[q+oe])<=0);)q++,le<<=1;if(ee+=1<<q,u===1&&852<ee||u===2&&592<ee)return 1;m[I=re&E]=J<<24|q<<16|b-p|0}}return re!==0&&(m[b+re]=H-oe<<24|64<<16|0),f.bits=J,0}},{"../utils/common":41}],51:[function(o,i,r){i.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],52:[function(o,i,r){var s=o("../utils/common"),a=0,c=1;function l(Ue){for(var we=Ue.length;0<=--we;)Ue[we]=0}var A=0,u=29,d=256,_=d+1+u,h=30,m=19,p=2*_+1,g=15,f=16,y=7,C=256,I=16,E=17,b=18,P=[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],M=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],R=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],k=new Array(2*(_+2));l(k);var H=new Array(2*h);l(H);var F=new Array(512);l(F);var G=new Array(256);l(G);var W=new Array(u);l(W);var J,q,oe,le=new Array(h);function ee(Ue,we,Ee,Fe,Me){this.static_tree=Ue,this.extra_bits=we,this.extra_base=Ee,this.elems=Fe,this.max_length=Me,this.has_stree=Ue&&Ue.length}function re(Ue,we){this.dyn_tree=Ue,this.max_code=0,this.stat_desc=we}function ae(Ue){return Ue<256?F[Ue]:F[256+(Ue>>>7)]}function ie(Ue,we){Ue.pending_buf[Ue.pending++]=255&we,Ue.pending_buf[Ue.pending++]=we>>>8&255}function de(Ue,we,Ee){Ue.bi_valid>f-Ee?(Ue.bi_buf|=we<<Ue.bi_valid&65535,ie(Ue,Ue.bi_buf),Ue.bi_buf=we>>f-Ue.bi_valid,Ue.bi_valid+=Ee-f):(Ue.bi_buf|=we<<Ue.bi_valid&65535,Ue.bi_valid+=Ee)}function ye(Ue,we,Ee){de(Ue,Ee[2*we],Ee[2*we+1])}function Ie(Ue,we){for(var Ee=0;Ee|=1&Ue,Ue>>>=1,Ee<<=1,0<--we;);return Ee>>>1}function ve(Ue,we,Ee){var Fe,Me,ze=new Array(g+1),je=0;for(Fe=1;Fe<=g;Fe++)ze[Fe]=je=je+Ee[Fe-1]<<1;for(Me=0;Me<=we;Me++){var it=Ue[2*Me+1];it!==0&&(Ue[2*Me]=Ie(ze[it]++,it))}}function ue(Ue){var we;for(we=0;we<_;we++)Ue.dyn_ltree[2*we]=0;for(we=0;we<h;we++)Ue.dyn_dtree[2*we]=0;for(we=0;we<m;we++)Ue.bl_tree[2*we]=0;Ue.dyn_ltree[2*C]=1,Ue.opt_len=Ue.static_len=0,Ue.last_lit=Ue.matches=0}function Se(Ue){8<Ue.bi_valid?ie(Ue,Ue.bi_buf):0<Ue.bi_valid&&(Ue.pending_buf[Ue.pending++]=Ue.bi_buf),Ue.bi_buf=0,Ue.bi_valid=0}function he(Ue,we,Ee,Fe){var Me=2*we,ze=2*Ee;return Ue[Me]<Ue[ze]||Ue[Me]===Ue[ze]&&Fe[we]<=Fe[Ee]}function De(Ue,we,Ee){for(var Fe=Ue.heap[Ee],Me=Ee<<1;Me<=Ue.heap_len&&(Me<Ue.heap_len&&he(we,Ue.heap[Me+1],Ue.heap[Me],Ue.depth)&&Me++,!he(we,Fe,Ue.heap[Me],Ue.depth));)Ue.heap[Ee]=Ue.heap[Me],Ee=Me,Me<<=1;Ue.heap[Ee]=Fe}function Ge(Ue,we,Ee){var Fe,Me,ze,je,it=0;if(Ue.last_lit!==0)for(;Fe=Ue.pending_buf[Ue.d_buf+2*it]<<8|Ue.pending_buf[Ue.d_buf+2*it+1],Me=Ue.pending_buf[Ue.l_buf+it],it++,Fe===0?ye(Ue,Me,we):(ye(Ue,(ze=G[Me])+d+1,we),(je=P[ze])!==0&&de(Ue,Me-=W[ze],je),ye(Ue,ze=ae(--Fe),Ee),(je=B[ze])!==0&&de(Ue,Fe-=le[ze],je)),it<Ue.last_lit;);ye(Ue,C,we)}function Ye(Ue,we){var Ee,Fe,Me,ze=we.dyn_tree,je=we.stat_desc.static_tree,it=we.stat_desc.has_stree,at=we.stat_desc.elems,At=-1;for(Ue.heap_len=0,Ue.heap_max=p,Ee=0;Ee<at;Ee++)ze[2*Ee]!==0?(Ue.heap[++Ue.heap_len]=At=Ee,Ue.depth[Ee]=0):ze[2*Ee+1]=0;for(;Ue.heap_len<2;)ze[2*(Me=Ue.heap[++Ue.heap_len]=At<2?++At:0)]=1,Ue.depth[Me]=0,Ue.opt_len--,it&&(Ue.static_len-=je[2*Me+1]);for(we.max_code=At,Ee=Ue.heap_len>>1;1<=Ee;Ee--)De(Ue,ze,Ee);for(Me=at;Ee=Ue.heap[1],Ue.heap[1]=Ue.heap[Ue.heap_len--],De(Ue,ze,1),Fe=Ue.heap[1],Ue.heap[--Ue.heap_max]=Ee,Ue.heap[--Ue.heap_max]=Fe,ze[2*Me]=ze[2*Ee]+ze[2*Fe],Ue.depth[Me]=(Ue.depth[Ee]>=Ue.depth[Fe]?Ue.depth[Ee]:Ue.depth[Fe])+1,ze[2*Ee+1]=ze[2*Fe+1]=Me,Ue.heap[1]=Me++,De(Ue,ze,1),2<=Ue.heap_len;);Ue.heap[--Ue.heap_max]=Ue.heap[1],(function(lt,xt){var Bt,pt,Mt,Lt,an,cn,wn=xt.dyn_tree,xe=xt.max_code,et=xt.stat_desc.static_tree,rt=xt.stat_desc.has_stree,ft=xt.stat_desc.extra_bits,kt=xt.stat_desc.extra_base,Ot=xt.stat_desc.max_length,sn=0;for(Lt=0;Lt<=g;Lt++)lt.bl_count[Lt]=0;for(wn[2*lt.heap[lt.heap_max]+1]=0,Bt=lt.heap_max+1;Bt<p;Bt++)Ot<(Lt=wn[2*wn[2*(pt=lt.heap[Bt])+1]+1]+1)&&(Lt=Ot,sn++),wn[2*pt+1]=Lt,xe<pt||(lt.bl_count[Lt]++,an=0,kt<=pt&&(an=ft[pt-kt]),cn=wn[2*pt],lt.opt_len+=cn*(Lt+an),rt&&(lt.static_len+=cn*(et[2*pt+1]+an)));if(sn!==0){do{for(Lt=Ot-1;lt.bl_count[Lt]===0;)Lt--;lt.bl_count[Lt]--,lt.bl_count[Lt+1]+=2,lt.bl_count[Ot]--,sn-=2}while(0<sn);for(Lt=Ot;Lt!==0;Lt--)for(pt=lt.bl_count[Lt];pt!==0;)xe<(Mt=lt.heap[--Bt])||(wn[2*Mt+1]!==Lt&&(lt.opt_len+=(Lt-wn[2*Mt+1])*wn[2*Mt],wn[2*Mt+1]=Lt),pt--)}})(Ue,we),ve(ze,At,Ue.bl_count)}function fe(Ue,we,Ee){var Fe,Me,ze=-1,je=we[1],it=0,at=7,At=4;for(je===0&&(at=138,At=3),we[2*(Ee+1)+1]=65535,Fe=0;Fe<=Ee;Fe++)Me=je,je=we[2*(Fe+1)+1],++it<at&&Me===je||(it<At?Ue.bl_tree[2*Me]+=it:Me!==0?(Me!==ze&&Ue.bl_tree[2*Me]++,Ue.bl_tree[2*I]++):it<=10?Ue.bl_tree[2*E]++:Ue.bl_tree[2*b]++,ze=Me,At=(it=0)===je?(at=138,3):Me===je?(at=6,3):(at=7,4))}function qe(Ue,we,Ee){var Fe,Me,ze=-1,je=we[1],it=0,at=7,At=4;for(je===0&&(at=138,At=3),Fe=0;Fe<=Ee;Fe++)if(Me=je,je=we[2*(Fe+1)+1],!(++it<at&&Me===je)){if(it<At)for(;ye(Ue,Me,Ue.bl_tree),--it!=0;);else Me!==0?(Me!==ze&&(ye(Ue,Me,Ue.bl_tree),it--),ye(Ue,I,Ue.bl_tree),de(Ue,it-3,2)):it<=10?(ye(Ue,E,Ue.bl_tree),de(Ue,it-3,3)):(ye(Ue,b,Ue.bl_tree),de(Ue,it-11,7));ze=Me,At=(it=0)===je?(at=138,3):Me===je?(at=6,3):(at=7,4)}}l(le);var Le=!1;function Qe(Ue,we,Ee,Fe){de(Ue,(A<<1)+(Fe?1:0),3),(function(Me,ze,je,it){Se(Me),ie(Me,je),ie(Me,~je),s.arraySet(Me.pending_buf,Me.window,ze,je,Me.pending),Me.pending+=je})(Ue,we,Ee)}r._tr_init=function(Ue){Le||((function(){var we,Ee,Fe,Me,ze,je=new Array(g+1);for(Me=Fe=0;Me<u-1;Me++)for(W[Me]=Fe,we=0;we<1<<P[Me];we++)G[Fe++]=Me;for(G[Fe-1]=Me,Me=ze=0;Me<16;Me++)for(le[Me]=ze,we=0;we<1<<B[Me];we++)F[ze++]=Me;for(ze>>=7;Me<h;Me++)for(le[Me]=ze<<7,we=0;we<1<<B[Me]-7;we++)F[256+ze++]=Me;for(Ee=0;Ee<=g;Ee++)je[Ee]=0;for(we=0;we<=143;)k[2*we+1]=8,we++,je[8]++;for(;we<=255;)k[2*we+1]=9,we++,je[9]++;for(;we<=279;)k[2*we+1]=7,we++,je[7]++;for(;we<=287;)k[2*we+1]=8,we++,je[8]++;for(ve(k,_+1,je),we=0;we<h;we++)H[2*we+1]=5,H[2*we]=Ie(we,5);J=new ee(k,P,d+1,_,g),q=new ee(H,B,0,h,g),oe=new ee(new Array(0),M,0,m,y)})(),Le=!0),Ue.l_desc=new re(Ue.dyn_ltree,J),Ue.d_desc=new re(Ue.dyn_dtree,q),Ue.bl_desc=new re(Ue.bl_tree,oe),Ue.bi_buf=0,Ue.bi_valid=0,ue(Ue)},r._tr_stored_block=Qe,r._tr_flush_block=function(Ue,we,Ee,Fe){var Me,ze,je=0;0<Ue.level?(Ue.strm.data_type===2&&(Ue.strm.data_type=(function(it){var at,At=4093624447;for(at=0;at<=31;at++,At>>>=1)if(1&At&&it.dyn_ltree[2*at]!==0)return a;if(it.dyn_ltree[18]!==0||it.dyn_ltree[20]!==0||it.dyn_ltree[26]!==0)return c;for(at=32;at<d;at++)if(it.dyn_ltree[2*at]!==0)return c;return a})(Ue)),Ye(Ue,Ue.l_desc),Ye(Ue,Ue.d_desc),je=(function(it){var at;for(fe(it,it.dyn_ltree,it.l_desc.max_code),fe(it,it.dyn_dtree,it.d_desc.max_code),Ye(it,it.bl_desc),at=m-1;3<=at&&it.bl_tree[2*R[at]+1]===0;at--);return it.opt_len+=3*(at+1)+5+5+4,at})(Ue),Me=Ue.opt_len+3+7>>>3,(ze=Ue.static_len+3+7>>>3)<=Me&&(Me=ze)):Me=ze=Ee+5,Ee+4<=Me&&we!==-1?Qe(Ue,we,Ee,Fe):Ue.strategy===4||ze===Me?(de(Ue,2+(Fe?1:0),3),Ge(Ue,k,H)):(de(Ue,4+(Fe?1:0),3),(function(it,at,At,lt){var xt;for(de(it,at-257,5),de(it,At-1,5),de(it,lt-4,4),xt=0;xt<lt;xt++)de(it,it.bl_tree[2*R[xt]+1],3);qe(it,it.dyn_ltree,at-1),qe(it,it.dyn_dtree,At-1)})(Ue,Ue.l_desc.max_code+1,Ue.d_desc.max_code+1,je+1),Ge(Ue,Ue.dyn_ltree,Ue.dyn_dtree)),ue(Ue),Fe&&Se(Ue)},r._tr_tally=function(Ue,we,Ee){return Ue.pending_buf[Ue.d_buf+2*Ue.last_lit]=we>>>8&255,Ue.pending_buf[Ue.d_buf+2*Ue.last_lit+1]=255&we,Ue.pending_buf[Ue.l_buf+Ue.last_lit]=255&Ee,Ue.last_lit++,we===0?Ue.dyn_ltree[2*Ee]++:(Ue.matches++,we--,Ue.dyn_ltree[2*(G[Ee]+d+1)]++,Ue.dyn_dtree[2*ae(we)]++),Ue.last_lit===Ue.lit_bufsize-1},r._tr_align=function(Ue){de(Ue,2,3),ye(Ue,C,k),(function(we){we.bi_valid===16?(ie(we,we.bi_buf),we.bi_buf=0,we.bi_valid=0):8<=we.bi_valid&&(we.pending_buf[we.pending++]=255&we.bi_buf,we.bi_buf>>=8,we.bi_valid-=8)})(Ue)}},{"../utils/common":41}],53:[function(o,i,r){i.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(o,i,r){(function(s){(function(a,c){if(!a.setImmediate){var l,A,u,d,_=1,h={},m=!1,p=a.document,g=Object.getPrototypeOf&&Object.getPrototypeOf(a);g=g&&g.setTimeout?g:a,l={}.toString.call(a.process)==="[object process]"?function(I){n.nextTick(function(){y(I)})}:(function(){if(a.postMessage&&!a.importScripts){var I=!0,E=a.onmessage;return a.onmessage=function(){I=!1},a.postMessage("","*"),a.onmessage=E,I}})()?(d="setImmediate$"+Math.random()+"$",a.addEventListener?a.addEventListener("message",C,!1):a.attachEvent("onmessage",C),function(I){a.postMessage(d+I,"*")}):a.MessageChannel?((u=new MessageChannel).port1.onmessage=function(I){y(I.data)},function(I){u.port2.postMessage(I)}):p&&"onreadystatechange"in p.createElement("script")?(A=p.documentElement,function(I){var E=p.createElement("script");E.onreadystatechange=function(){y(I),E.onreadystatechange=null,A.removeChild(E),E=null},A.appendChild(E)}):function(I){setTimeout(y,0,I)},g.setImmediate=function(I){typeof I!="function"&&(I=new Function(""+I));for(var E=new Array(arguments.length-1),b=0;b<E.length;b++)E[b]=arguments[b+1];var P={callback:I,args:E};return h[_]=P,l(_),_++},g.clearImmediate=f}function f(I){delete h[I]}function y(I){if(m)setTimeout(y,0,I);else{var E=h[I];if(E){m=!0;try{(function(b){var P=b.callback,B=b.args;switch(B.length){case 0:P();break;case 1:P(B[0]);break;case 2:P(B[0],B[1]);break;case 3:P(B[0],B[1],B[2]);break;default:P.apply(c,B)}})(E)}finally{f(I),m=!1}}}}function C(I){I.source===a&&typeof I.data=="string"&&I.data.indexOf(d)===0&&y(+I.data.slice(d.length))}})(typeof self>"u"?s===void 0?this:s:self)}).call(this,typeof GG<"u"?GG:typeof self<"u"?self:typeof window<"u"?window:{})},{}]},{},[10])(10)})})(qve)),qve.exports}var D3o=w3o();const $ve=g2(D3o);var Q3o=()=>{if(globalThis.tscircuitDynamicModules)return globalThis.tscircuitDynamicModules;const t={};return globalThis.tscircuitDynamicModules=t,t};function T3o(t,e){return Q3o()[t]=e,e}var R3o=["circuit-json-to-bom-csv","circuit-json-to-bpc","circuit-json-to-connectivity-map","circuit-json-to-gerber","circuit-json-to-gltf","circuit-json-to-kicad","circuit-json-to-lbrn","circuit-json-to-pnp-csv","circuit-json-to-readable-netlist","circuit-json-to-simple-3d","circuit-json-to-spice","circuit-json-to-step","circuit-json-to-tscircuit","circuit-to-canvas","circuit-to-svg"],Zve=t=>{const e=t.indexOf("@");return e===-1?t:t.slice(0,e)},N3o=new Set(R3o),k3o=t=>(H3o(t),[L3o(t),`https://esm.run/${t}`]);function L3o(t){const e=Zve(t),n=t.length===e.length?"latest":t.slice(e.length+1);return`https://jscdn.tscircuit.com/${e}/${n}/+esm`}function H3o(t){const e=Zve(t);if(!N3o.has(e))throw new Error(`Unsupported module: ${t}`)}async function F3o(t){let e;for(const n of k3o(t))try{const o=await import(n);return T3o(Zve(t),o)}catch(o){e=o}throw e}var oM=F3o,tvt=3,O3o=(t,e={})=>{e.flip_y_axis??=!1;const n=[];for(const o of t)if(o.type==="pcb_component"){const i=lp(t).source_component.get(o.source_component_id);n.push({designator:i?.name??o.pcb_component_id,mid_x:o.center.x,mid_y:o.center.y*(e.flip_y_axis?-1:1),layer:o.layer,rotation:o.rotation})}return n},G3o=t=>gSt.unparse(O3o(t).map(e=>({Designator:e.designator,"Mid X":e.mid_x.toFixed(tvt),"Mid Y":e.mid_y.toFixed(tvt),Layer:e.layer,Rotation:e.rotation})));const Xb=(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,document.body.appendChild(s),s.click(),setTimeout(()=>{document.body.removeChild(s),URL.revokeObjectURL(r)},0)},U3o=async({circuitJson:t,projectName:e})=>{const n=new $ve,{stringifyGerberCommandLayers:o,convertSoupToGerberCommands:i,convertSoupToExcellonDrillCommands:r,stringifyExcellonDrill:s}=await oM("circuit-json-to-gerber"),a=t.filter(p=>!("error_type"in p)&&!("warning_type"in p)),c=i(a,{flip_y_axis:!1}),l=o(c);for(const[p,g]of Object.entries(l))n.file(`gerber/${p}.gbr`,g);const A=r({circuitJson:a,is_plated:!0,flip_y_axis:!1}),u=s(A);n.file("gerber/drill.drl",u);const d=await pSt({circuitJson:t}),_=await d2o(d);n.file("bom.csv",_);const h=await G3o(t);n.file("pick_and_place.csv",h);const m=await n.generateAsync({type:"blob"});Xb(m,{fileName:`${e}_fabrication_files.zip`})},z3o=async({circuitJson:t,projectName:e})=>{let n;try{const{convertCircuitJsonToGltf:o}=await oM("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}Xb(n,{fileName:`${e}.glb`})},V3o=async({circuitJson:t,projectName:e})=>{const{convertCircuitJsonToPinoutSvg:n}=await oM("circuit-to-svg"),o=n(t);Xb(o,{fileName:`${e}-pinout.svg`,mimeType:"image/svg+xml"})},Y3o=async({circuitJson:t,projectName:e})=>{const{CircuitJsonToKicadPcbConverter:n,CircuitJsonToKicadSchConverter:o,CircuitJsonToKicadProConverter:i,resolveAndLoadKicad3dModelFiles:r}=await oM("circuit-json-to-kicad"),s=new o(t);s.runUntilFinished();const a=s.getOutputString(),c=new n(t,{includeBuiltin3dModels:!0,projectName:e});c.runUntilFinished();const l=c.getOutputString(),A=new i(t,{projectName:e,schematicFilename:`${e}.kicad_sch`,pcbFilename:`${e}.kicad_pcb`});A.runUntilFinished();const u=A.getOutputString(),d=new $ve;return d.file(`${e}.kicad_sch`,a),d.file(`${e}.kicad_pcb`,l),d.file(`${e}.kicad_pro`,u),await r({projectName:e,model3dSourcePaths:c.getModel3dSourcePaths(),fetch,onModelFile:({outputPath:_,content:h})=>{d.file(_,h)},onError:({sourcePath:_})=>{console.warn(`Failed to load 3D model from ${_}`)}}),d},K3o=async({circuitJson:t,projectName:e})=>{const o=await(await Y3o({circuitJson:t,projectName:e})).generateAsync({type:"blob"});Xb(o,{fileName:`${e}_kicad_project.zip`})},W3o=async({circuitJson:t,libraryName:e})=>{const{CircuitJsonToKicadLibraryConverter:n}=await oM("circuit-json-to-kicad"),o=new n(t,{libraryName:e,footprintLibraryName:e});o.runUntilFinished();const i=o.getOutput(),r=new $ve;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}
5795
5795
  `)}if(i.model3dSourcePaths.length>0){const s=r.folder(`${e}.3dshapes`);if(s)for(const a of i.model3dSourcePaths)try{const c=a.split("/").pop()||a,l=await fetch(a);if(l.ok){const A=await l.arrayBuffer();s.file(c,A)}}catch{}}return r.file("fp-lib-table",i.fpLibTableString),r.file("sym-lib-table",i.symLibTableString),r},j3o=async({circuitJson:t,projectName:e})=>{const o=await(await W3o({circuitJson:t,libraryName:e})).generateAsync({type:"blob"});Xb(o,{fileName:`${e}_kicad_library.zip`})},X3o=async({circuitJson:t,projectName:e})=>{const{circuitJsonToStep:n}=await oM("circuit-json-to-step"),o=t.find(l=>l.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){na.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(l){const A=l instanceof Error?l.message:"Unknown error";na.error(`Failed to convert circuit to STEP format: ${A}`);return}const c=new Blob([a],{type:"application/step"});try{Xb(c,{fileName:`${e}.step`})}catch(l){const A=l instanceof Error?l.message:"Unknown error";na.error(`Failed to download STEP file: ${A}`)}},nvt=async({circuitJson:t,projectName:e,options:n={}})=>{try{const{convertCircuitJsonToLbrn:o}=await oM("circuit-json-to-lbrn"),r=(await o(t,{includeSilkscreen:n.includeSilkscreen??!1,includeOxidationCleaningLayer:n.includeOxidationCleaningLayer??!0})).toXml(),s=new Blob([r],{type:"application/lbrn"});Xb(s,{fileName:`${e}.lbrn2`})}catch(o){const i=o instanceof Error?o.message:"Unknown error";na.error(`Failed to export to LBRN format: ${i}`)}},J3o=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"},q3o=[{extension:"json",name:"Circuit JSON"},{extension:"json",name:"Simple Route JSON"},{extension:"zip",name:"Fabrication Files"},{extension:"zip",name:"KiCad 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"}],$3o=async({exportName:t,circuitJson:e,simpleRouteJson:n,projectName:o})=>{const i=J3o(o);if(t==="Fabrication Files"){U3o({circuitJson:e,projectName:i});return}if(t==="KiCad Project"){await K3o({circuitJson:e,projectName:i});return}if(t==="KiCad Library"){await j3o({circuitJson:e,projectName:i});return}if(t==="Circuit JSON"){Xb(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");Xb(JSON.stringify(n,null,2),{fileName:`${i}.simple-route.json`,mimeType:"application/json"});return}if(t==="GLB (Binary GLTF)"){await z3o({circuitJson:e,projectName:i});return}if(t==="Pinout SVG"){V3o({circuitJson:e,projectName:i});return}if(t==="STEP"){await X3o({circuitJson:e,projectName:i});return}if(t==="LightBurn"){await nvt({circuitJson:e,projectName:i});return}throw new Error(`Unsupported export type: "${t}"`)},Z3o=({packageName:t,onSelectReview:e})=>{const n=x0(u=>u.fsMap),o=x0(u=>u.circuitJson),[i,r]=X.useState([]),[s,a]=X.useState(!1),[c,l]=X.useState(!1);X.useEffect(()=>{!t||!GJ()||(a(!0),UL.get("ai_reviews/list",{searchParams:{package_name:t}}).json().then(u=>r(u.ai_reviews)).catch(u=>{console.error("Failed to load AI reviews",u),na.error("Failed to load AI reviews")}).finally(()=>a(!1)))},[t]);const A=async()=>{if(!o){na.error("Need Circuit JSON to Request AI Review");return}if(!GJ()){na.error("Missing registry token");return}l(!0);try{const{ai_review:u}=await UL.post("ai_reviews/create",{json:{package_name:t??"unknown",fs_map:Object.fromEntries(n),circuit_json:o}}).json();r(d=>[u,...d]),e(u),na.success("AI review requested")}catch(u){console.error("Failed to create AI review",u),na.error("Failed to request AI review")}finally{l(!1)}};return K.jsxs(K.Fragment,{children:[K.jsxs(tM,{children:[K.jsx(nM,{children:"AI Review"}),K.jsx(sT,{children:"Select an AI review or request a new one."})]}),K.jsx("div",{className:"rf-flex rf-gap-4 rf-mt-4",children:K.jsx("div",{className:"rf-w-48 rf-h-64 rf-overflow-y-auto rf-border rf-rounded rf-p-2 rf-flex-shrink-0",children:s?K.jsx("div",{className:"rf-text-sm",children:"Loading..."}):i.length>0?i.map(u=>K.jsx("div",{className:"rf-text-sm rf-p-2 rf-cursor-pointer rf-rounded hover:rf-bg-zinc-100",onClick:()=>e(u),children:new Date(u.created_at||"").toLocaleString()},u.ai_review_id)):K.jsx("div",{className:"rf-text-sm rf-text-muted-foreground",children:"No AI reviews found."})})}),K.jsx(RO,{className:"rf-mt-4",children:K.jsx(_l,{onClick:A,disabled:c,children:c?"Requesting...":"Review my Board"})})]})};function eBe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var iM=eBe();function ovt(t){iM=t}var LO={exec:()=>null};function ql(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(z1.caret,"$1"),n=n.replace(i,s),o},getRegex:()=>new RegExp(n,e)};return o}var z1={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")},ePo=/^(?:[ \t]*(?:\n|$))+/,tPo=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,nPo=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,HO=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,oPo=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,tBe=/(?:[*+-]|\d{1,9}[.)])/,ivt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,rvt=ql(ivt).replace(/bull/g,tBe).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(),iPo=ql(ivt).replace(/bull/g,tBe).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(),nBe=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,rPo=/^[^\n]+/,oBe=/(?!\s*\])(?:\\.|[^\[\]\\])+/,sPo=ql(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",oBe).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),aPo=ql(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,tBe).getRegex(),Gte="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",iBe=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,cPo=ql("^ {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",iBe).replace("tag",Gte).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),svt=ql(nBe).replace("hr",HO).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",Gte).getRegex(),lPo=ql(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",svt).getRegex(),rBe={blockquote:lPo,code:tPo,def:sPo,fences:nPo,heading:oPo,hr:HO,html:cPo,lheading:rvt,list:aPo,newline:ePo,paragraph:svt,table:LO,text:rPo},avt=ql("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",HO).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",Gte).getRegex(),APo={...rBe,lheading:iPo,table:avt,paragraph:ql(nBe).replace("hr",HO).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",avt).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",Gte).getRegex()},uPo={...rBe,html:ql(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",iBe).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:LO,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ql(nBe).replace("hr",HO).replace("heading",` *#{1,6} *[^
5796
5796
  ]`).replace("lheading",rvt).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},dPo=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,hPo=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,cvt=/^( {2,}|\\)\n(?!\s*$)/,_Po=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ute=/[\p{P}\p{S}]/u,sBe=/[\s\p{P}\p{S}]/u,lvt=/[^\s\p{P}\p{S}]/u,mPo=ql(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,sBe).getRegex(),Avt=/(?!~)[\p{P}\p{S}]/u,gPo=/(?!~)[\s\p{P}\p{S}]/u,pPo=/(?:[^\s\p{P}\p{S}]|~)/u,fPo=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,uvt=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,yPo=ql(uvt,"u").replace(/punct/g,Ute).getRegex(),CPo=ql(uvt,"u").replace(/punct/g,Avt).getRegex(),dvt="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",xPo=ql(dvt,"gu").replace(/notPunctSpace/g,lvt).replace(/punctSpace/g,sBe).replace(/punct/g,Ute).getRegex(),IPo=ql(dvt,"gu").replace(/notPunctSpace/g,pPo).replace(/punctSpace/g,gPo).replace(/punct/g,Avt).getRegex(),EPo=ql("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,lvt).replace(/punctSpace/g,sBe).replace(/punct/g,Ute).getRegex(),bPo=ql(/\\(punct)/,"gu").replace(/punct/g,Ute).getRegex(),SPo=ql(/^<(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(),PPo=ql(iBe).replace("(?:-->|$)","-->").getRegex(),vPo=ql("^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",PPo).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),zte=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,BPo=ql(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",zte).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),hvt=ql(/^!?\[(label)\]\[(ref)\]/).replace("label",zte).replace("ref",oBe).getRegex(),_vt=ql(/^!?\[(ref)\](?:\[\])?/).replace("ref",oBe).getRegex(),MPo=ql("reflink|nolink(?!\\()","g").replace("reflink",hvt).replace("nolink",_vt).getRegex(),aBe={_backpedal:LO,anyPunctuation:bPo,autolink:SPo,blockSkip:fPo,br:cvt,code:hPo,del:LO,emStrongLDelim:yPo,emStrongRDelimAst:xPo,emStrongRDelimUnd:EPo,escape:dPo,link:BPo,nolink:_vt,punctuation:mPo,reflink:hvt,reflinkSearch:MPo,tag:vPo,text:_Po,url:LO},wPo={...aBe,link:ql(/^!?\[(label)\]\((.*?)\)/).replace("label",zte).getRegex(),reflink:ql(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",zte).getRegex()},cBe={...aBe,emStrongRDelimAst:IPo,emStrongLDelim:CPo,url:ql(/^((?: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.!#$%&'*+\/=?_`{\|}~-]+@)))/},DPo={...cBe,br:ql(cvt).replace("{2,}","*").getRegex(),text:ql(cBe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Vte={normal:rBe,gfm:APo,pedantic:uPo},FO={normal:aBe,gfm:cBe,breaks:DPo,pedantic:wPo},QPo={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},mvt=t=>QPo[t];function cE(t,e){if(e){if(z1.escapeTest.test(t))return t.replace(z1.escapeReplace,mvt)}else if(z1.escapeTestNoEncode.test(t))return t.replace(z1.escapeReplaceNoEncode,mvt);return t}function gvt(t){try{t=encodeURI(t).replace(z1.percentDecode,"%")}catch{return null}return t}function pvt(t,e){const n=t.replace(z1.findPipe,(r,s,a)=>{let c=!1,l=s;for(;--l>=0&&a[l]==="\\";)c=!c;return c?"|":" |"}),o=n.split(z1.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(z1.slashPipe,"|");return o}function OO(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 TPo(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 fvt(t,e,n,o,i){const r=e.href,s=e.title||null,a=t[1].replace(i.other.outputLinkReplace,"$1");o.state.inLink=!0;const c={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:r,title:s,text:a,tokens:o.inlineTokens(a)};return o.state.inLink=!1,c}function RPo(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.1941",
6
+ "version": "0.0.1942",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
@@ -55,7 +55,7 @@
55
55
  "@tscircuit/capacity-autorouter": "^0.0.583",
56
56
  "@tscircuit/checks": "0.0.138",
57
57
  "@tscircuit/circuit-json-util": "^0.0.96",
58
- "@tscircuit/cli": "^0.1.1550",
58
+ "@tscircuit/cli": "^0.1.1551",
59
59
  "@tscircuit/copper-pour-solver": "^0.0.29",
60
60
  "@tscircuit/core": "^0.0.1353",
61
61
  "@tscircuit/eval": "^0.0.948",
@@ -70,7 +70,7 @@
70
70
  "@tscircuit/miniflex": "^0.0.4",
71
71
  "@tscircuit/ngspice-spice-engine": "^0.0.18",
72
72
  "@tscircuit/props": "^0.0.553",
73
- "@tscircuit/runframe": "^0.0.2117",
73
+ "@tscircuit/runframe": "^0.0.2118",
74
74
  "@tscircuit/schematic-match-adapt": "^0.0.18",
75
75
  "@tscircuit/schematic-trace-solver": "^0.0.72",
76
76
  "@tscircuit/simple-3d-svg": "^0.0.41",