autoglm-gui 0.4.12__py3-none-any.whl → 0.4.13__py3-none-any.whl

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.
@@ -0,0 +1,149 @@
1
+ import{c as ee,j as a,u as lt,r as l,B as ie,a as Ze,S as en,g as In,s as Zr,b as tn,d as nn,e as es,f as oe,i as ts,h as ns,k as rs,R as Fn,l as ss,m as is,n as ke,o as os,P as as,p as cs,q as ls,t as us,v as ds,w as fs}from"./index-wu8Wjf12.js";const hs=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],ps=ee("arrow-up-down",hs);const ms=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],Un=ee("chevron-left",ms);const _s=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Gn=ee("chevron-right",_s);const gs=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],Ie=ee("circle-alert",gs);const xs=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Ge=ee("circle-check",xs);const vs=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],bs=ee("eye-off",vs);const ys=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],ws=ee("eye",ys);const Es=[["path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4",key:"1nerag"}],["path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88",key:"o46ks0"}],["path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02",key:"ptglia"}],["path",{d:"M2 12a10 10 0 0 1 18-6",key:"ydlgp0"}],["path",{d:"M2 16h.01",key:"1gqxmh"}],["path",{d:"M21.8 16c.2-2 .131-5.354 0-6",key:"drycrb"}],["path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2",key:"1tidbn"}],["path",{d:"M8.65 22c.21-.66.45-1.32.57-2",key:"13wd9y"}],["path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2",key:"1fr1j5"}]],Ts=ee("fingerprint-pattern",Es);const Ss=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],rn=ee("image",Ss);const Cs=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],We=ee("loader-circle",Cs);const ks=[["path",{d:"M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z",key:"vbtd3f"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",key:"x3v2xh"}]],Ns=ee("monitor-play",ks);const Rs=[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]],Ps=ee("plug",Rs);const As=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],Ds=ee("rotate-ccw",As);const Ls=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],js=ee("send",Ls);const Os=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],Bs=ee("server",Os);const Ms=[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Wn=ee("settings",Ms);const Is=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],qn=ee("smartphone",Is);const Fs=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],_t=ee("sparkles",Fs);const Us=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Gs=ee("video",Us);const Ws=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],qs=ee("wifi-off",Ws);const Hs=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],Xs=ee("wifi",Hs);const zs=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],$s=ee("x",zs);function sn({isOpen:t,title:e,content:n,onConfirm:r,onCancel:i,confirmText:s="确认",cancelText:c="取消"}){return t?a.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm animate-in fade-in duration-200",children:a.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-xl max-w-md w-full overflow-hidden transform transition-all animate-in zoom-in-95 duration-200",onClick:o=>o.stopPropagation(),children:[a.jsxs("div",{className:"p-6",children:[a.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100 mb-2",children:e}),a.jsx("p",{className:"text-gray-500 dark:text-gray-400 text-sm leading-relaxed whitespace-pre-wrap",children:n})]}),a.jsxs("div",{className:"bg-gray-50 dark:bg-gray-700/50 px-6 py-4 flex justify-end gap-3",children:[a.jsx("button",{onClick:o=>{o.stopPropagation(),i()},className:"px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 transition-colors",children:c}),a.jsx("button",{onClick:o=>{o.stopPropagation(),r()},className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors",children:s})]})]})}):null}function Vs({id:t,model:e,status:n,connectionType:r,isInitialized:i,isActive:s,onClick:c,onConnectWifi:o,onDisconnectWifi:u}){const d=lt(),f=n==="device",h=r==="usb",_=r==="remote",[m,x]=l.useState(!1),[p,v]=l.useState(!1),[E,C]=l.useState(!1),g=y=>{y.stopPropagation(),!(m||!o)&&v(!0)},b=y=>{y.stopPropagation(),!(m||!u)&&C(!0)},S=async()=>{v(!1),x(!0);try{o&&await o()}finally{x(!1)}},k=async()=>{C(!1),x(!0);try{u&&await u()}finally{x(!1)}};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{onClick:c,role:"button",tabIndex:0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&c()},className:`
2
+ group relative w-full text-left p-4 rounded-xl transition-all duration-200 cursor-pointer
3
+ border-2
4
+ ${s?"bg-slate-50 border-[#1d9bf0] dark:bg-slate-800/50 dark:border-[#1d9bf0]":"bg-white border-transparent hover:border-slate-200 dark:bg-slate-900 dark:hover:border-slate-700"}
5
+ `,children:[s&&a.jsx("div",{className:"absolute left-0 top-2 bottom-2 w-1 bg-[#1d9bf0] rounded-r"}),a.jsxs("div",{className:"flex items-center gap-3 pl-2",children:[a.jsx("div",{className:`relative flex-shrink-0 ${f?"status-online":"status-offline"} w-3 h-3 rounded-full transition-all ${s?"scale-110":""}`}),a.jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center gap-0.5",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(qn,{className:`w-4 h-4 ${s?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),a.jsx("span",{className:`font-semibold text-sm truncate ${s?"text-slate-900 dark:text-slate-100":"text-slate-700 dark:text-slate-300"}`,children:e||d.deviceCard.unknownDevice})]}),a.jsx("span",{className:`text-xs font-mono truncate ${s?"text-slate-500 dark:text-slate-400":"text-slate-400 dark:text-slate-500"}`,children:t})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[h&&o&&a.jsx(ie,{variant:"ghost",size:"icon",onClick:g,disabled:m,className:`h-8 w-8 rounded-full ${s?"bg-[#1d9bf0]/10 text-[#1d9bf0] hover:bg-[#1d9bf0]/20":"text-slate-400 dark:text-slate-500 hover:text-[#1d9bf0] dark:hover:text-[#1d9bf0] hover:bg-slate-100 dark:hover:bg-slate-800"}`,title:d.deviceCard.connectViaWifi,children:m?a.jsx(We,{className:"w-4 h-4 animate-spin"}):a.jsx(Xs,{className:"w-4 h-4"})}),_&&u&&a.jsx(ie,{variant:"ghost",size:"icon",onClick:b,disabled:m,className:`h-8 w-8 rounded-full ${s?"bg-red-500/10 text-red-500 hover:bg-red-500/20":"text-slate-400 dark:text-slate-500 hover:text-red-500 dark:hover:text-red-500 hover:bg-slate-100 dark:hover:bg-slate-800"}`,title:d.deviceCard.disconnectWifi,children:m?a.jsx(We,{className:"w-4 h-4 animate-spin"}):a.jsx(qs,{className:"w-4 h-4"})}),i&&a.jsxs(Ze,{variant:"success",className:`text-xs ${s?"bg-green-500/10 text-green-600 dark:text-green-400":""}`,children:[a.jsx(Ge,{className:"w-3 h-3 mr-1"}),d.deviceCard.ready]})]})]})]}),a.jsx(sn,{isOpen:p,title:d.deviceCard.connectWifiTitle,content:d.deviceCard.connectWifiContent,onConfirm:S,onCancel:()=>v(!1)}),a.jsx(sn,{isOpen:E,title:d.deviceCard.disconnectWifiTitle,content:d.deviceCard.disconnectWifiContent,onConfirm:k,onCancel:()=>C(!1)})]})}const Ys=()=>{try{const t=localStorage.getItem("sidebar-collapsed");return t!==null?JSON.parse(t):!1}catch(t){return console.warn("Failed to load sidebar collapsed state:",t),!1}};function Ks({devices:t,currentDeviceId:e,onSelectDevice:n,onOpenConfig:r,onConnectWifi:i,onDisconnectWifi:s}){const c=lt(),[o,u]=l.useState(Ys);l.useEffect(()=>{localStorage.setItem("sidebar-collapsed",JSON.stringify(o))},[o]),l.useEffect(()=>{const f=h=>{(h.metaKey||h.ctrlKey)&&h.key==="b"&&(h.preventDefault(),u(!o))};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[o]);const d=()=>{u(!o)};return a.jsxs(a.Fragment,{children:[o&&a.jsx(ie,{variant:"outline",size:"icon",onClick:d,className:"fixed left-0 top-20 z-50 h-16 w-8 rounded-r-lg rounded-l-none border-l-0 bg-slate-100 hover:bg-slate-200 dark:bg-slate-800 dark:hover:bg-slate-700",title:"Expand sidebar",style:{left:0},children:a.jsx(Gn,{className:"h-4 w-4"})}),a.jsxs("div",{className:`
6
+ ${o?"w-0 -ml-4 opacity-0":"w-80 opacity-100"}
7
+ transition-all duration-300 ease-in-out
8
+ h-full min-h-0
9
+ bg-white dark:bg-slate-950
10
+ border-r border-slate-200 dark:border-slate-800
11
+ flex flex-col
12
+ overflow-hidden
13
+ `,children:[a.jsxs("div",{className:"flex items-center justify-between p-4",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:a.jsx(qn,{className:"h-5 w-5 text-[#1d9bf0]"})}),a.jsxs("div",{children:[a.jsx("h2",{className:"text-base font-bold text-slate-900 dark:text-slate-100",children:"AutoGLM"}),a.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:[t.length," ",(t.length===1,c.deviceSidebar.devices)]})]})]}),a.jsx(ie,{variant:"ghost",size:"icon",onClick:d,className:"h-8 w-8 rounded-full text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300",title:"Collapse sidebar",children:a.jsx(Un,{className:"h-4 w-4"})})]}),a.jsx(en,{className:"mx-4"}),a.jsx("div",{className:"flex-1 overflow-y-auto p-3 space-y-2 min-h-0",children:t.length===0?a.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[a.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800",children:a.jsx(Ps,{className:"h-8 w-8 text-slate-400"})}),a.jsx("p",{className:"mt-4 font-medium text-slate-900 dark:text-slate-100",children:c.deviceSidebar.noDevicesConnected}),a.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:c.deviceSidebar.clickToRefresh})]}):t.map(f=>a.jsx(Vs,{id:f.id,model:f.model,status:f.status,connectionType:f.connection_type,isInitialized:f.is_initialized,isActive:e===f.id,onClick:()=>n(f.id),onConnectWifi:async()=>{await i(f.id)},onDisconnectWifi:async()=>{await s(f.id)}},f.id))}),a.jsx(en,{className:"mx-4"}),a.jsx("div",{className:"p-3",children:a.jsxs(ie,{variant:"outline",onClick:r,className:"w-full justify-start gap-2 rounded-full border-slate-200 dark:border-slate-700",children:[a.jsx(Wn,{className:"h-4 w-4"}),c.deviceSidebar.settings]})})]})]})}const xe=Object.create(null);xe.open="0";xe.close="1";xe.ping="2";xe.pong="3";xe.message="4";xe.upgrade="5";xe.noop="6";const et=Object.create(null);Object.keys(xe).forEach(t=>{et[xe[t]]=t});const Bt={type:"error",data:"parser error"},Hn=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",Xn=typeof ArrayBuffer=="function",zn=t=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,Xt=({type:t,data:e},n,r)=>Hn&&e instanceof Blob?n?r(e):on(e,r):Xn&&(e instanceof ArrayBuffer||zn(e))?n?r(e):on(new Blob([e]),r):r(xe[t]+(e||"")),on=(t,e)=>{const n=new FileReader;return n.onload=function(){const r=n.result.split(",")[1];e("b"+(r||""))},n.readAsDataURL(t)};function an(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let gt;function Js(t,e){if(Hn&&t.data instanceof Blob)return t.data.arrayBuffer().then(an).then(e);if(Xn&&(t.data instanceof ArrayBuffer||zn(t.data)))return e(an(t.data));Xt(t,!1,n=>{gt||(gt=new TextEncoder),e(gt.encode(n))})}const cn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Fe=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let t=0;t<cn.length;t++)Fe[cn.charCodeAt(t)]=t;const Qs=t=>{let e=t.length*.75,n=t.length,r,i=0,s,c,o,u;t[t.length-1]==="="&&(e--,t[t.length-2]==="="&&e--);const d=new ArrayBuffer(e),f=new Uint8Array(d);for(r=0;r<n;r+=4)s=Fe[t.charCodeAt(r)],c=Fe[t.charCodeAt(r+1)],o=Fe[t.charCodeAt(r+2)],u=Fe[t.charCodeAt(r+3)],f[i++]=s<<2|c>>4,f[i++]=(c&15)<<4|o>>2,f[i++]=(o&3)<<6|u&63;return d},Zs=typeof ArrayBuffer=="function",zt=(t,e)=>{if(typeof t!="string")return{type:"message",data:$n(t,e)};const n=t.charAt(0);return n==="b"?{type:"message",data:ei(t.substring(1),e)}:et[n]?t.length>1?{type:et[n],data:t.substring(1)}:{type:et[n]}:Bt},ei=(t,e)=>{if(Zs){const n=Qs(t);return $n(n,e)}else return{base64:!0,data:t}},$n=(t,e)=>{switch(e){case"blob":return t instanceof Blob?t:new Blob([t]);case"arraybuffer":default:return t instanceof ArrayBuffer?t:t.buffer}},Vn="",ti=(t,e)=>{const n=t.length,r=new Array(n);let i=0;t.forEach((s,c)=>{Xt(s,!1,o=>{r[c]=o,++i===n&&e(r.join(Vn))})})},ni=(t,e)=>{const n=t.split(Vn),r=[];for(let i=0;i<n.length;i++){const s=zt(n[i],e);if(r.push(s),s.type==="error")break}return r};function ri(){return new TransformStream({transform(t,e){Js(t,n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const s=new DataView(i.buffer);s.setUint8(0,126),s.setUint16(1,r)}else{i=new Uint8Array(9);const s=new DataView(i.buffer);s.setUint8(0,127),s.setBigUint64(1,BigInt(r))}t.data&&typeof t.data!="string"&&(i[0]|=128),e.enqueue(i),e.enqueue(n)})}})}let xt;function ze(t){return t.reduce((e,n)=>e+n.length,0)}function $e(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let r=0;for(let i=0;i<e;i++)n[i]=t[0][r++],r===t[0].length&&(t.shift(),r=0);return t.length&&r<t[0].length&&(t[0]=t[0].slice(r)),n}function si(t,e){xt||(xt=new TextDecoder);const n=[];let r=0,i=-1,s=!1;return new TransformStream({transform(c,o){for(n.push(c);;){if(r===0){if(ze(n)<1)break;const u=$e(n,1);s=(u[0]&128)===128,i=u[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(ze(n)<2)break;const u=$e(n,2);i=new DataView(u.buffer,u.byteOffset,u.length).getUint16(0),r=3}else if(r===2){if(ze(n)<8)break;const u=$e(n,8),d=new DataView(u.buffer,u.byteOffset,u.length),f=d.getUint32(0);if(f>Math.pow(2,21)-1){o.enqueue(Bt);break}i=f*Math.pow(2,32)+d.getUint32(4),r=3}else{if(ze(n)<i)break;const u=$e(n,i);o.enqueue(zt(s?u:xt.decode(u),e)),r=0}if(i===0||i>t){o.enqueue(Bt);break}}}})}const Yn=4;function te(t){if(t)return ii(t)}function ii(t){for(var e in te.prototype)t[e]=te.prototype[e];return t}te.prototype.on=te.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this};te.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this};te.prototype.off=te.prototype.removeListener=te.prototype.removeAllListeners=te.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+t];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+t],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===e||r.fn===e){n.splice(i,1);break}return n.length===0&&delete this._callbacks["$"+t],this};te.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,e)}return this};te.prototype.emitReserved=te.prototype.emit;te.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]};te.prototype.hasListeners=function(t){return!!this.listeners(t).length};const ut=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,n)=>n(e,0),de=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),oi="arraybuffer";function Kn(t,...e){return e.reduce((n,r)=>(t.hasOwnProperty(r)&&(n[r]=t[r]),n),{})}const ai=de.setTimeout,ci=de.clearTimeout;function dt(t,e){e.useNativeTimers?(t.setTimeoutFn=ai.bind(de),t.clearTimeoutFn=ci.bind(de)):(t.setTimeoutFn=de.setTimeout.bind(de),t.clearTimeoutFn=de.clearTimeout.bind(de))}const li=1.33;function ui(t){return typeof t=="string"?di(t):Math.ceil((t.byteLength||t.size)*li)}function di(t){let e=0,n=0;for(let r=0,i=t.length;r<i;r++)e=t.charCodeAt(r),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(r++,n+=4);return n}function Jn(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function fi(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}function hi(t){let e={},n=t.split("&");for(let r=0,i=n.length;r<i;r++){let s=n[r].split("=");e[decodeURIComponent(s[0])]=decodeURIComponent(s[1])}return e}class pi extends Error{constructor(e,n,r){super(e),this.description=n,this.context=r,this.type="TransportError"}}class $t extends te{constructor(e){super(),this.writable=!1,dt(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,n,r){return super.emitReserved("error",new pi(e,n,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const n=zt(e,this.socket.binaryType);this.onPacket(n)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,n={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(n)}_hostname(){const e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){const n=fi(e);return n.length?"?"+n:""}}class mi extends $t{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";const n=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){const n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};ni(e,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){const e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,ti(e,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=Jn()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(e,n)}}let Qn=!1;try{Qn=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const _i=Qn;function gi(){}class xi extends mi{constructor(e){if(super(e),typeof location<"u"){const n=location.protocol==="https:";let r=location.port;r||(r=n?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||r!==e.port}}doWrite(e,n){const r=this.request({method:"POST",data:e});r.on("success",n),r.on("error",(i,s)=>{this.onError("xhr post error",i,s)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=e}}class ge extends te{constructor(e,n,r){super(),this.createRequest=e,dt(this,r),this._opts=r,this._method=r.method||"GET",this._uri=n,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var e;const n=Kn(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this._opts.xd;const r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this._opts.extraHeaders[i])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this._opts.cookieJar)===null||i===void 0||i.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},r.send(this._data)}catch(i){this.setTimeoutFn(()=>{this._onError(i)},0);return}typeof document<"u"&&(this._index=ge.requestsCount++,ge.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=gi,e)try{this._xhr.abort()}catch{}typeof document<"u"&&delete ge.requests[this._index],this._xhr=null}}_onLoad(){const e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}ge.requestsCount=0;ge.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",ln);else if(typeof addEventListener=="function"){const t="onpagehide"in de?"pagehide":"unload";addEventListener(t,ln,!1)}}function ln(){for(let t in ge.requests)ge.requests.hasOwnProperty(t)&&ge.requests[t].abort()}const vi=(function(){const t=Zn({xdomain:!1});return t&&t.responseType!==null})();class bi extends xi{constructor(e){super(e);const n=e&&e.forceBase64;this.supportsBinary=vi&&!n}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new ge(Zn,this.uri(),e)}}function Zn(t){const e=t.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||_i))return new XMLHttpRequest}catch{}if(!e)try{return new de[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}const er=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class yi extends $t{get name(){return"websocket"}doOpen(){const e=this.uri(),n=this.opts.protocols,r=er?{}:Kn(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let n=0;n<e.length;n++){const r=e[n],i=n===e.length-1;Xt(r,this.supportsBinary,s=>{try{this.doWrite(r,s)}catch{}i&&ut(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=Jn()),this.supportsBinary||(n.b64=1),this.createUri(e,n)}}const vt=de.WebSocket||de.MozWebSocket;class wi extends yi{createSocket(e,n,r){return er?new vt(e,n,r):n?new vt(e,n):new vt(e)}doWrite(e,n){this.ws.send(n)}}class Ei extends $t{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{const n=si(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(n).getReader(),i=ri();i.readable.pipeTo(e.writable),this._writer=i.writable.getWriter();const s=()=>{r.read().then(({done:o,value:u})=>{o||(this.onPacket(u),s())}).catch(o=>{})};s();const c={type:"open"};this.query.sid&&(c.data=`{"sid":"${this.query.sid}"}`),this._writer.write(c).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let n=0;n<e.length;n++){const r=e[n],i=n===e.length-1;this._writer.write(r).then(()=>{i&&ut(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}}const Ti={websocket:wi,webtransport:Ei,polling:bi},Si=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Ci=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Mt(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),r=t.indexOf("]");n!=-1&&r!=-1&&(t=t.substring(0,n)+t.substring(n,r).replace(/:/g,";")+t.substring(r,t.length));let i=Si.exec(t||""),s={},c=14;for(;c--;)s[Ci[c]]=i[c]||"";return n!=-1&&r!=-1&&(s.source=e,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=ki(s,s.path),s.queryKey=Ni(s,s.query),s}function ki(t,e){const n=/\/{2,9}/g,r=e.replace(n,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&r.splice(0,1),e.slice(-1)=="/"&&r.splice(r.length-1,1),r}function Ni(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,s){i&&(n[i]=s)}),n}const It=typeof addEventListener=="function"&&typeof removeEventListener=="function",tt=[];It&&addEventListener("offline",()=>{tt.forEach(t=>t())},!1);class Te extends te{constructor(e,n){if(super(),this.binaryType=oi,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(n=e,e=null),e){const r=Mt(e);n.hostname=r.host,n.secure=r.protocol==="https"||r.protocol==="wss",n.port=r.port,r.query&&(n.query=r.query)}else n.host&&(n.hostname=Mt(n.host).host);dt(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},n.transports.forEach(r=>{const i=r.prototype.name;this.transports.push(i),this._transportsByName[i]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=hi(this.opts.query)),It&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},tt.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){const n=Object.assign({},this.opts.query);n.EIO=Yn,n.transport=e,this.id&&(n.sid=this.id);const r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const e=this.opts.rememberUpgrade&&Te.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const n=this.createTransport(e);n.open(),this.setTransport(n)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",n=>this._onClose("transport close",n))}onOpen(){this.readyState="open",Te.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const n=new Error("server error");n.code=e.data,this._onError(n);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r<this.writeBuffer.length;r++){const i=this.writeBuffer[r].data;if(i&&(n+=ui(i)),r>0&&n>this._maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,ut(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,n,r){return this._sendPacket("message",e,n,r),this}send(e,n,r){return this._sendPacket("message",e,n,r),this}_sendPacket(e,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const s={type:e,data:n,options:r};this.emitReserved("packetCreate",s),this.writeBuffer.push(s),i&&this.once("flush",i),this.flush()}close(){const e=()=>{this._onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),e()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():e()}):this.upgrading?r():e()),this}_onError(e){if(Te.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),It&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const r=tt.indexOf(this._offlineEventListener);r!==-1&&tt.splice(r,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,n),this.writeBuffer=[],this._prevBufferLen=0}}}Te.protocol=Yn;class Ri extends Te{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let n=this.createTransport(e),r=!1;Te.priorWebsocketSuccess=!1;const i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",h=>{if(!r)if(h.type==="pong"&&h.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;Te.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(f(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{const _=new Error("probe error");_.transport=n.name,this.emitReserved("upgradeError",_)}}))};function s(){r||(r=!0,f(),n.close(),n=null)}const c=h=>{const _=new Error("probe error: "+h);_.transport=n.name,s(),this.emitReserved("upgradeError",_)};function o(){c("transport closed")}function u(){c("socket closed")}function d(h){n&&h.name!==n.name&&s()}const f=()=>{n.removeListener("open",i),n.removeListener("error",c),n.removeListener("close",o),this.off("close",u),this.off("upgrading",d)};n.once("open",i),n.once("error",c),n.once("close",o),this.once("close",u),this.once("upgrading",d),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){const n=[];for(let r=0;r<e.length;r++)~this.transports.indexOf(e[r])&&n.push(e[r]);return n}}let Pi=class extends Ri{constructor(e,n={}){const r=typeof e=="object"?e:n;(!r.transports||r.transports&&typeof r.transports[0]=="string")&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map(i=>Ti[i]).filter(i=>!!i)),super(e,r)}};function Ai(t,e="",n){let r=t;n=n||typeof location<"u"&&location,t==null&&(t=n.protocol+"//"+n.host),typeof t=="string"&&(t.charAt(0)==="/"&&(t.charAt(1)==="/"?t=n.protocol+t:t=n.host+t),/^(https?|wss?):\/\//.test(t)||(typeof n<"u"?t=n.protocol+"//"+t:t="https://"+t),r=Mt(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";const s=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+s+":"+r.port+e,r.href=r.protocol+"://"+s+(n&&n.port===r.port?"":":"+r.port),r}const Di=typeof ArrayBuffer=="function",Li=t=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer,tr=Object.prototype.toString,ji=typeof Blob=="function"||typeof Blob<"u"&&tr.call(Blob)==="[object BlobConstructor]",Oi=typeof File=="function"||typeof File<"u"&&tr.call(File)==="[object FileConstructor]";function Vt(t){return Di&&(t instanceof ArrayBuffer||Li(t))||ji&&t instanceof Blob||Oi&&t instanceof File}function nt(t,e){if(!t||typeof t!="object")return!1;if(Array.isArray(t)){for(let n=0,r=t.length;n<r;n++)if(nt(t[n]))return!0;return!1}if(Vt(t))return!0;if(t.toJSON&&typeof t.toJSON=="function"&&arguments.length===1)return nt(t.toJSON(),!0);for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&nt(t[n]))return!0;return!1}function Bi(t){const e=[],n=t.data,r=t;return r.data=Ft(n,e),r.attachments=e.length,{packet:r,buffers:e}}function Ft(t,e){if(!t)return t;if(Vt(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}else if(Array.isArray(t)){const n=new Array(t.length);for(let r=0;r<t.length;r++)n[r]=Ft(t[r],e);return n}else if(typeof t=="object"&&!(t instanceof Date)){const n={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=Ft(t[r],e));return n}return t}function Mi(t,e){return t.data=Ut(t.data,e),delete t.attachments,t}function Ut(t,e){if(!t)return t;if(t&&t._placeholder===!0){if(typeof t.num=="number"&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}else if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=Ut(t[n],e);else if(typeof t=="object")for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=Ut(t[n],e));return t}const Ii=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Fi=5;var U;(function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"})(U||(U={}));class Ui{constructor(e){this.replacer=e}encode(e){return(e.type===U.EVENT||e.type===U.ACK)&&nt(e)?this.encodeAsBinary({type:e.type===U.EVENT?U.BINARY_EVENT:U.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let n=""+e.type;return(e.type===U.BINARY_EVENT||e.type===U.BINARY_ACK)&&(n+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(n+=e.nsp+","),e.id!=null&&(n+=e.id),e.data!=null&&(n+=JSON.stringify(e.data,this.replacer)),n}encodeAsBinary(e){const n=Bi(e),r=this.encodeAsString(n.packet),i=n.buffers;return i.unshift(r),i}}function un(t){return Object.prototype.toString.call(t)==="[object Object]"}class Yt extends te{constructor(e){super(),this.reviver=e}add(e){let n;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");n=this.decodeString(e);const r=n.type===U.BINARY_EVENT;r||n.type===U.BINARY_ACK?(n.type=r?U.EVENT:U.ACK,this.reconstructor=new Gi(n),n.attachments===0&&super.emitReserved("decoded",n)):super.emitReserved("decoded",n)}else if(Vt(e)||e.base64)if(this.reconstructor)n=this.reconstructor.takeBinaryData(e),n&&(this.reconstructor=null,super.emitReserved("decoded",n));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let n=0;const r={type:Number(e.charAt(0))};if(U[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===U.BINARY_EVENT||r.type===U.BINARY_ACK){const s=n+1;for(;e.charAt(++n)!=="-"&&n!=e.length;);const c=e.substring(s,n);if(c!=Number(c)||e.charAt(n)!=="-")throw new Error("Illegal attachments");r.attachments=Number(c)}if(e.charAt(n+1)==="/"){const s=n+1;for(;++n&&!(e.charAt(n)===","||n===e.length););r.nsp=e.substring(s,n)}else r.nsp="/";const i=e.charAt(n+1);if(i!==""&&Number(i)==i){const s=n+1;for(;++n;){const c=e.charAt(n);if(c==null||Number(c)!=c){--n;break}if(n===e.length)break}r.id=Number(e.substring(s,n+1))}if(e.charAt(++n)){const s=this.tryParse(e.substr(n));if(Yt.isPayloadValid(r.type,s))r.data=s;else throw new Error("invalid payload")}return r}tryParse(e){try{return JSON.parse(e,this.reviver)}catch{return!1}}static isPayloadValid(e,n){switch(e){case U.CONNECT:return un(n);case U.DISCONNECT:return n===void 0;case U.CONNECT_ERROR:return typeof n=="string"||un(n);case U.EVENT:case U.BINARY_EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&Ii.indexOf(n[0])===-1);case U.ACK:case U.BINARY_ACK:return Array.isArray(n)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Gi{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const n=Mi(this.reconPack,this.buffers);return this.finishedReconstruction(),n}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Wi=Object.freeze(Object.defineProperty({__proto__:null,Decoder:Yt,Encoder:Ui,get PacketType(){return U},protocol:Fi},Symbol.toStringTag,{value:"Module"}));function fe(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const qi=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class nr extends te{constructor(e,n,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=n,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[fe(e,"open",this.onopen.bind(this)),fe(e,"packet",this.onpacket.bind(this)),fe(e,"error",this.onerror.bind(this)),fe(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...n){var r,i,s;if(qi.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(n.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(n),this;const c={type:U.EVENT,data:n};if(c.options={},c.options.compress=this.flags.compress!==!1,typeof n[n.length-1]=="function"){const f=this.ids++,h=n.pop();this._registerAckCallback(f,h),c.id=f}const o=(i=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||i===void 0?void 0:i.writable,u=this.connected&&!(!((s=this.io.engine)===null||s===void 0)&&s._hasPingExpired());return this.flags.volatile&&!o||(u?(this.notifyOutgoingListeners(c),this.packet(c)):this.sendBuffer.push(c)),this.flags={},this}_registerAckCallback(e,n){var r;const i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[e]=n;return}const s=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let o=0;o<this.sendBuffer.length;o++)this.sendBuffer[o].id===e&&this.sendBuffer.splice(o,1);n.call(this,new Error("operation has timed out"))},i),c=(...o)=>{this.io.clearTimeoutFn(s),n.apply(this,o)};c.withError=!0,this.acks[e]=c}emitWithAck(e,...n){return new Promise((r,i)=>{const s=(c,o)=>c?i(c):r(o);s.withError=!0,n.push(s),this.emit(e,...n)})}_addToQueue(e){let n;typeof e[e.length-1]=="function"&&(n=e.pop());const r={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((i,...s)=>r!==this._queue[0]?void 0:(i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...s)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;const n=this._queue[0];n.pending&&!e||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:U.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,n),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(r=>String(r.id)===e)){const r=this.acks[e];delete this.acks[e],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case U.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case U.EVENT:case U.BINARY_EVENT:this.onevent(e);break;case U.ACK:case U.BINARY_ACK:this.onack(e);break;case U.DISCONNECT:this.ondisconnect();break;case U.CONNECT_ERROR:this.destroy();const r=new Error(e.data.message);r.data=e.data.data,this.emitReserved("connect_error",r);break}}onevent(e){const n=e.data||[];e.id!=null&&n.push(this.ack(e.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const n=this._anyListeners.slice();for(const r of n)r.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){const n=this;let r=!1;return function(...i){r||(r=!0,n.packet({type:U.ACK,id:e,data:i}))}}onack(e){const n=this.acks[e.id];typeof n=="function"&&(delete this.acks[e.id],n.withError&&e.data.unshift(null),n.apply(this,e.data))}onconnect(e,n){this.id=e,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:U.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const n=this._anyListeners;for(let r=0;r<n.length;r++)if(e===n[r])return n.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const n=this._anyOutgoingListeners;for(let r=0;r<n.length;r++)if(e===n[r])return n.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const n=this._anyOutgoingListeners.slice();for(const r of n)r.apply(this,e.data)}}}function je(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}je.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=(Math.floor(e*10)&1)==0?t-n:t+n}return Math.min(t,this.max)|0};je.prototype.reset=function(){this.attempts=0};je.prototype.setMin=function(t){this.ms=t};je.prototype.setMax=function(t){this.max=t};je.prototype.setJitter=function(t){this.jitter=t};class Gt extends te{constructor(e,n){var r;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(n=e,e=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,dt(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new je({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=e;const i=n.parser||Wi;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var n;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(n=this.backoff)===null||n===void 0||n.setMin(e),this)}randomizationFactor(e){var n;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(n=this.backoff)===null||n===void 0||n.setJitter(e),this)}reconnectionDelayMax(e){var n;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(n=this.backoff)===null||n===void 0||n.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new Pi(this.uri,this.opts);const n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;const i=fe(n,"open",function(){r.onopen(),e&&e()}),s=o=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",o),e?e(o):this.maybeReconnectOnOpen()},c=fe(n,"error",s);if(this._timeout!==!1){const o=this._timeout,u=this.setTimeoutFn(()=>{i(),s(new Error("timeout")),n.close()},o);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(c),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(fe(e,"ping",this.onping.bind(this)),fe(e,"data",this.ondata.bind(this)),fe(e,"error",this.onerror.bind(this)),fe(e,"close",this.onclose.bind(this)),fe(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(n){this.onclose("parse error",n)}}ondecoded(e){ut(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,n){let r=this.nsps[e];return r?this._autoConnect&&!r.active&&r.connect():(r=new nr(this,e,n),this.nsps[e]=r),r}_destroy(e){const n=Object.keys(this.nsps);for(const r of n)if(this.nsps[r].active)return;this._close()}_packet(e){const n=this.encoder.encode(e);for(let r=0;r<n.length;r++)this.engine.write(n[r],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,n){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const n=this.backoff.duration();this._reconnecting=!0;const r=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(i=>{i?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",i)):e.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const Be={};function rt(t,e){typeof t=="object"&&(e=t,t=void 0),e=e||{};const n=Ai(t,e.path||"/socket.io"),r=n.source,i=n.id,s=n.path,c=Be[i]&&s in Be[i].nsps,o=e.forceNew||e["force new connection"]||e.multiplex===!1||c;let u;return o?u=new Gt(r,e):(Be[i]||(Be[i]=new Gt(r,e)),u=Be[i]),n.query&&!e.query&&(e.query=n.queryKey),u.socket(n.path,e)}Object.assign(rt,{Manager:Gt,Socket:nr,io:rt,connect:rt});function Hi(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0}const st={H264:1748121140,H265:1748121141,AV1:6387249},{WritableStream:Xi}=globalThis;class zi{#e;#t;#n=0;#r=7;get byteAligned(){return this.#r===7}get ended(){return this.#n>=this.#e.length}constructor(e){this.#e=e,this.#t=e[0]}f1(){const e=this.#t>>this.#r;return this.#r-=1,this.#r<0&&(this.#n+=1,this.#r=7,this.#t=this.#e[this.#n]),e&1}f(e){let n=0;for(;e>0;e-=1)n<<=1,n|=this.f1();return n}skip(e){if(e<=this.#r+1){this.#n+=1,this.#r=7,this.#t=this.#e[this.#n];return}e-=this.#r+1,this.#n+=1;const n=e/8|0;n>0&&(this.#n+=n,e-=n*8),this.#r=7-e,this.#t=this.#e[this.#n]}readBytes(e){if(!this.byteAligned)throw new Error("Bytes must be byte-aligned");const n=this.#e.subarray(this.#n,this.#n+e);return this.#n+=e,this.#t=this.#e[this.#n],n}getPosition(){return[this.#n,this.#r]}setPosition([e,n]){this.#n=e,this.#r=n,this.#t=this.#e[e]}}const $i={SequenceHeader:1,TemporalDelimiter:2,FrameHeader:3,TileGroup:4,Metadata:5,Frame:6,RedundantFrameHeader:7,TileList:8,Padding:15},Vi={Bt709:1,Unspecified:2,Bt470M:4,Bt470BG:5,Bt601:6,Smpte240:7,GenericFilm:8,Bt2020:9,Xyz:10,Smpte431:11,Smpte432:12,Ebu3213:22},Yi={Bt709:1,Unspecified:2,Bt470M:4,Bt470BG:5,Bt601:6,Smpte240:7,Linear:8,Log100:9,Log100Sqrt10:10,Iec61966:11,Bt1361:12,Srgb:13,Bt2020Ten:14,Bt2020Twelve:15,Smpte2084:16,Smpte428:17,Hlg:18},Ki={Identity:0,Bt709:1,Unspecified:2,Fcc:4,Bt470BG:5,Bt601:6,Smpte240:7,YCgCo:8,Bt2020Ncl:9,Bt2020Cl:10,Smpte2085:11,ChromatNcl:12,ChromatCl:13,ICtCp:14};class se extends zi{static ObuType=$i;static ColorPrimaries=Vi;static TransferCharacteristics=Yi;static MatrixCoefficients=Ki;#e=0;uvlc(){let e=0;for(;!this.f1();)e+=1;return e>=32?2**32-1:this.f(e)+(1<<e>>>0)-1}leb128(){if(!this.byteAligned)throw new Error("LEB128 must be byte-aligned");let e=0n;this.#e=0;for(let n=0n;n<8n;n+=1n){const r=this.f(8);if(e|=BigInt(r&127)<<7n*n,this.#e+=1,(r&128)==0)break}return e}*annexBBitstream(){for(;!this.ended;){const e=this.leb128();yield*this.temporalUnit(e)}}*temporalUnit(e){for(;e>0;){const n=this.leb128();e-=BigInt(this.#e),yield*this.frameUnit(n),e-=n}}*frameUnit(e){for(;e>0;){const n=this.leb128();e-=BigInt(this.#e);const r=this.openBitstreamUnit(n);r&&(yield r),e-=n}}#t=0;openBitstreamUnit(e){const n=this.obuHeader();let r;if(n.obu_has_size_field)r=this.leb128();else if(e!==void 0)r=e-1n-(n.obu_extension_flag?1n:0n);else throw new Error("obu_has_size_field must be true");const i=this.getPosition();if(n.obu_type!==se.ObuType.SequenceHeader&&n.obu_type!==se.ObuType.TemporalDelimiter&&this.#t!==0&&n.obu_extension_header){const u=!!(this.#t&1<<n.obu_extension_header.temporal_id),d=!!(this.#t&1<<n.obu_extension_header.spatial_id+8);if(!u||!d){this.skip(Number(r));return}}let s;switch(n.obu_type){case se.ObuType.SequenceHeader:s=this.sequenceHeaderObu();break}const c=this.getPosition(),o=(c[0]-i[0])*8+(i[1]-c[1]);return r>0&&this.skip(Number(r)*8-o),{obu_header:n,obu_size:r,sequence_header_obu:s}}obuHeader(){if(!!this.f1())throw new Error("Invalid data");const n=this.f(4),r=!!this.f1(),i=!!this.f1();this.f1();let s;return r&&(s=this.obuExtensionHeader()),{obu_type:n,obu_extension_flag:r,obu_has_size_field:i,obu_extension_header:s}}obuExtensionHeader(){const e=this.f(3),n=this.f(2);return this.skip(3),{temporal_id:e,spatial_id:n}}static SelectScreenContentTools=2;static SelectIntegerMv=2;sequenceHeaderObu(){const e=this.f(3),n=!!this.f1(),r=!!this.f1();let i=!1,s,c=!1,o,u=!1,d=0;const f=[],h=[],_=[],m=[],x=[];let p,v;if(r)f[0]=0,h[0]=this.f(5),_[0]=0,m[0]=!1,x[0]=!1;else{i=!!this.f1(),i&&(s=this.timingInfo(),c=!!this.f1(),c&&(o=this.decoderModelInfo(),p=[])),u=!!this.f1(),u&&(v=[]),d=this.f(5);for(let J=0;J<=d;J+=1)f[J]=this.f(12),h[J]=this.f(5),h[J]>7?_[J]=this.f1():_[J]=0,c?(m[J]=!!this.f1(),m[J]&&(p[J]=this.operatingParametersInfo(o))):m[J]=!1,u&&(x[J]=!!this.f1(),x[J]&&(v[J]=this.f(4)))}const E=this.chooseOperatingPoint();this.#t=f[E];const C=this.f(4),g=this.f(4),b=this.f(C+1),S=this.f(g+1);let k=!1,y,A;r||(k=!!this.f1(),k&&(y=this.f(4),A=this.f(3)));const w=!!this.f1(),D=!!this.f1(),T=!!this.f1();let W=!1,Y=!1,N=!1,P=!1,L=!1,I=!1,G=!1,z=!1,$=se.SelectScreenContentTools,q=!1,K=se.SelectIntegerMv,Q;r||(W=!!this.f1(),Y=!!this.f1(),N=!!this.f1(),P=!!this.f1(),L=!!this.f1(),L&&(I=!!this.f1(),G=!!this.f1()),z=!!this.f1(),z||($=this.f1()),$>0&&(q=!!this.f1(),q||(K=this.f1())),L&&(Q=this.f(3)));const Z=!!this.f1(),re=!!this.f1(),ae=!!this.f1(),ce=this.colorConfig(e),le=!!this.f1();return{seq_profile:e,still_picture:n,reduced_still_picture_header:r,timing_info_present_flag:i,timing_info:s,decoder_model_info_present_flag:c,decoder_model_info:o,initial_display_delay_present_flag:u,initial_display_delay_minus_1:v,operating_points_cnt_minus_1:d,operating_point_idc:f,seq_level_idx:h,seq_tier:_,decoder_model_present_for_this_op:m,operating_parameters_info:p,initial_display_delay_present_for_this_op:x,frame_width_bits_minus_1:C,frame_height_bits_minus_1:g,max_frame_width_minus_1:b,max_frame_height_minus_1:S,frame_id_numbers_present_flag:k,delta_frame_id_length_minus_2:y,additional_frame_id_length_minus_1:A,use_128x128_superblock:w,enable_filter_intra:D,enable_intra_edge_filter:T,enable_interintra_compound:W,enable_masked_compound:Y,enable_warped_motion:N,enable_dual_filter:P,enable_order_hint:L,enable_jnt_comp:I,enable_ref_frame_mvs:G,seq_choose_screen_content_tools:z,seq_force_screen_content_tools:$,seq_choose_integer_mv:q,seq_force_integer_mv:K,order_hint_bits_minus_1:Q,enable_superres:Z,enable_cdef:re,enable_restoration:ae,color_config:ce,film_grain_params_present:le}}searchSequenceHeaderObu(){for(;!this.ended;){const e=this.openBitstreamUnit();if(e&&e.sequence_header_obu)return e.sequence_header_obu}}timingInfo(){const e=this.f(32),n=this.f(32),r=!!this.f1();let i;return r&&(i=this.uvlc()),{num_units_in_display_tick:e,time_scale:n,equal_picture_interval:r,num_ticks_per_picture_minus_1:i}}decoderModelInfo(){const e=this.f(5),n=this.f(32),r=this.f(5),i=this.f(5);return{buffer_delay_length_minus_1:e,num_units_in_decoding_tick:n,buffer_removal_time_length_minus_1:r,frame_presentation_time_length_minus_1:i}}operatingParametersInfo(e){const n=e.buffer_delay_length_minus_1+1,r=this.f(n),i=this.f(n),s=!!this.f1();return{decoder_buffer_delay:r,encoder_buffer_delay:i,low_delay_mode_flag:s}}chooseOperatingPoint(){return 0}colorConfig(e){const n=!!this.f1();let r=!1,i=8;e===2&&n?(r=!!this.f1(),i=r?12:10):e<=2&&(i=n?10:8);let s=!1;e===1&&(s=!!this.f1());const c=!!this.f1();let o=se.ColorPrimaries.Unspecified,u=se.TransferCharacteristics.Unspecified,d=se.MatrixCoefficients.Unspecified;c&&(o=this.f(8),u=this.f(8),d=this.f(8));let f=!1,h,_,m=0,x=!1;if(s)f=!!this.f1(),h=!0,_=!0;else{if(o===se.ColorPrimaries.Bt709&&u===se.TransferCharacteristics.Srgb&&d===se.MatrixCoefficients.Identity)f=!0,h=!1,_=!1;else{switch(f=!!this.f1(),e){case 0:h=!0,_=!0;break;case 1:h=!1,_=!1;break;default:i==12?(h=!!this.f1(),h?_=!!this.f1():_=!1):(h=!0,_=!1);break}h&&_&&(m=this.f(2))}x=!!this.f1()}return{high_bitdepth:n,twelve_bit:r,BitDepth:i,mono_chrome:s,color_description_present_flag:c,color_primaries:o,transfer_characteristics:u,matrix_coefficients:d,color_range:f,subsampling_x:h,subsampling_y:_,chroma_sample_position:m,separate_uv_delta_q:x}}}function*rr(t){let e=-1,n=0,r=!1;for(let i=0;i<t.length;i+=1){const s=t[i];if(r){if(s>3)throw new Error("Invalid data");r=!1;continue}if(s===0){n+=1;continue}const c=n;if(n=0,e===-1){if(c>=2&&s===1){e=i+1;continue}throw new Error("Invalid data")}if(!(c<2)){if(s===1){yield t.subarray(e,i-c),e=i+1;continue}if(c>2)throw new Error("Invalid data");switch(s){case 2:throw new Error("Invalid data");case 3:r=!0;break}}}if(r)throw new Error("Invalid data");yield t.subarray(e,t.length)}class ft{#e;#t;#n;#r=0;#i=0;#s=7;#o=0;get byteLength(){return this.#t}get stopBitIndex(){return this.#n}get bytePosition(){return this.#i}get bitPosition(){return this.#s}get ended(){return this.#i>=this.#t&&this.#s<=this.#n}constructor(e){this.#e=e;for(let n=e.length-1;n>=0;n-=1){if(this.#e[n]===0)continue;const r=e[n];for(let i=0;i<8;i+=1)if((r>>i&1)===1){this.#t=n,this.#n=i,this.#c();return}}throw new Error("Stop bit not found")}#c(){if(this.#o=this.#e[this.#i],this.#r===2&&this.#o===3){this.#r=0,this.#i+=1,this.#c();return}this.#o===0?this.#r+=1:this.#r=0}next(){if(this.ended)throw new Error("Bit index out of bounds");const e=this.#o>>this.#s&1;return this.#s-=1,this.#s<0&&(this.#i+=1,this.#s=7,this.#c()),e}read(e){if(e>32)throw new Error("Read length too large");let n=0;for(let r=0;r<e;r+=1)n=n<<1|this.next();return n}#l(){if(this.#i>=this.#t&&this.#s<this.#n)throw new Error("Bit index out of bounds")}skip(e){if(e<=this.#s+1){this.#s-=e,this.#l();return}for(e-=this.#s+1,this.#i+=1,this.#s=7,this.#c(),this.#l();e>=8;e-=8)this.#i+=1,this.#c(),this.#l();this.#s=7-e,this.#l()}decodeExponentialGolombNumber(){let e=0;for(;this.next()===0;)e+=1;return e===0?0:(1<<e|this.read(e))-1}#d(){return{zeroCount:this.#r,bytePosition:this.#i,bitPosition:this.#s,byte:this.#o}}#a(e){this.#r=e.zeroCount,this.#i=e.bytePosition,this.#s=e.bitPosition,this.#o=e.byte}peek(e){const n=this.#d(),r=this.read(e);return this.#a(n),r}readBytes(e){const n=new Uint8Array(e);for(let r=0;r<e;r+=1)n[r]=this.read(8);return n}peekBytes(e){const n=this.#d(),r=this.readBytes(e);return this.#a(n),r}}function Ji(t){const e=new ft(t);if(e.next()!==0)throw new Error("Invalid data");const n=e.read(2);if(e.read(5)!==7)throw new Error("Invalid data");if(n===0)throw new Error("Invalid data");const i=e.read(8),s=e.peek(8),c=!!e.next(),o=!!e.next(),u=!!e.next(),d=!!e.next(),f=!!e.next(),h=!!e.next();if(e.read(2)!==0)throw new Error("Invalid data");const _=e.read(8),m=e.decodeExponentialGolombNumber();if(i===100||i===110||i===122||i===244||i===44||i===83||i===86||i===118||i===128||i===138||i===139||i===134){const y=e.decodeExponentialGolombNumber();if(y===3&&e.next(),e.decodeExponentialGolombNumber(),e.decodeExponentialGolombNumber(),e.next(),!!e.next())for(let w=0;w<(y!==3?8:12);w+=1)e.next()}e.decodeExponentialGolombNumber();const x=e.decodeExponentialGolombNumber();if(x===0)e.decodeExponentialGolombNumber();else if(x===1){e.next(),e.decodeExponentialGolombNumber(),e.decodeExponentialGolombNumber();const y=e.decodeExponentialGolombNumber();for(let A=0;A<y;A+=1)e.decodeExponentialGolombNumber()}e.decodeExponentialGolombNumber(),e.next();const p=e.decodeExponentialGolombNumber(),v=e.decodeExponentialGolombNumber(),E=e.next();E||e.next(),e.next();const C=!!e.next();let g,b,S,k;return C?(g=e.decodeExponentialGolombNumber(),b=e.decodeExponentialGolombNumber(),S=e.decodeExponentialGolombNumber(),k=e.decodeExponentialGolombNumber()):(g=0,b=0,S=0,k=0),e.next(),{profile_idc:i,constraint_set:s,constraint_set0_flag:c,constraint_set1_flag:o,constraint_set2_flag:u,constraint_set3_flag:d,constraint_set4_flag:f,constraint_set5_flag:h,level_idc:_,seq_parameter_set_id:m,pic_width_in_mbs_minus1:p,pic_height_in_map_units_minus1:v,frame_mbs_only_flag:E,frame_cropping_flag:C,frame_crop_left_offset:g,frame_crop_right_offset:b,frame_crop_top_offset:S,frame_crop_bottom_offset:k}}function Qi(t){let e,n;for(const r of rr(t))switch(r[0]&31){case 7:if(e=r,n)return{sequenceParameterSet:e,pictureParameterSet:n};break;case 8:if(n=r,e)return{sequenceParameterSet:e,pictureParameterSet:n};break}throw new Error("Invalid data")}function Zi(t){const{sequenceParameterSet:e,pictureParameterSet:n}=Qi(t),{profile_idc:r,constraint_set:i,level_idc:s,pic_width_in_mbs_minus1:c,pic_height_in_map_units_minus1:o,frame_mbs_only_flag:u,frame_crop_left_offset:d,frame_crop_right_offset:f,frame_crop_top_offset:h,frame_crop_bottom_offset:_}=Ji(e),m=(c+1)*16,x=(o+1)*(2-u)*16,p=d*2,v=f*2,E=h*2,C=_*2,g=m-p-v,b=x-E-C;return{pictureParameterSet:n,sequenceParameterSet:e,profileIndex:r,constraintSet:i,levelIndex:s,encodedWidth:m,encodedHeight:x,cropLeft:p,cropRight:v,cropTop:E,cropBottom:C,croppedWidth:g,croppedHeight:b}}function eo(t){switch(t){case 0:case 3:return 1;case 1:case 2:return 2;default:throw new Error("Invalid chroma_format_idc")}}function to(t){switch(t){case 0:case 2:case 3:return 1;case 1:return 2;default:throw new Error("Invalid chroma_format_idc")}}function no(t){const e=new ft(t);if(e.next()!==0)throw new Error("Invalid NALU header");const n=e.read(6),r=e.read(6),i=e.read(3);return{nal_unit_type:n,nuh_layer_id:r,nuh_temporal_id_plus1:i}}function ro(t){const e=new ft(t),n=e.read(4),r=!!e.next(),i=!!e.next(),s=e.read(6),c=e.read(3),o=!!e.next();e.skip(16);const u=sr(e,!0,c),d=!!e.next(),f=[],h=[],_=[];for(let D=d?0:c;D<=c;D+=1)f[D]=e.decodeExponentialGolombNumber(),h[D]=e.decodeExponentialGolombNumber(),_[D]=e.decodeExponentialGolombNumber();const m=e.read(6),x=e.decodeExponentialGolombNumber(),p=[];for(let D=1;D<=x;D+=1){p[D]=[];for(let T=0;T<=m;T+=1)p[D][T]=!!e.next()}const v=!!e.next();let E,C,g,b,S,k,y,A;if(v){E=e.read(32),C=e.read(32),g=!!e.next(),g&&(b=e.decodeExponentialGolombNumber()),S=e.decodeExponentialGolombNumber(),k=[],y=[!0],A=[];for(let D=0;D<S;D+=1)k[D]=e.decodeExponentialGolombNumber(),D>0&&(y[D]=!!e.next()),A[D]=ir(e,y[D],c)}const w=!!e.next();return{vps_video_parameter_set_id:n,vps_base_layer_internal_flag:r,vps_base_layer_available_flag:i,vps_max_layers_minus1:s,vps_max_sub_layers_minus1:c,vps_temporal_id_nesting_flag:o,profileTierLevel:u,vps_sub_layer_ordering_info_present_flag:d,vps_max_dec_pic_buffering_minus1:f,vps_max_num_reorder_pics:h,vps_max_latency_increase_plus1:_,vps_max_layer_id:m,vps_num_layer_sets_minus1:x,layer_id_included_flag:p,vps_timing_info_present_flag:v,vps_num_units_in_tick:E,vps_time_scale:C,vps_poc_proportional_to_timing_flag:g,vps_num_ticks_poc_diff_one_minus1:b,vps_num_hrd_parameters:S,hrd_layer_set_idx:k,cprms_present_flag:y,hrdParameters:A,vps_extension_flag:w}}function so(t){const e=new ft(t),n=e.read(4),r=e.read(3),i=!!e.next(),s=sr(e,!0,r),c=e.decodeExponentialGolombNumber(),o=e.decodeExponentialGolombNumber();let u;o===3&&(u=!!e.next());const d=e.decodeExponentialGolombNumber(),f=e.decodeExponentialGolombNumber(),h=!!e.next();let _,m,x,p;h&&(_=e.decodeExponentialGolombNumber(),m=e.decodeExponentialGolombNumber(),x=e.decodeExponentialGolombNumber(),p=e.decodeExponentialGolombNumber());const v=e.decodeExponentialGolombNumber(),E=e.decodeExponentialGolombNumber(),C=e.decodeExponentialGolombNumber(),g=[],b=[],S=[],k=!!e.next();for(let B=k?0:r;B<=r;B+=1)g[B]=e.decodeExponentialGolombNumber(),b[B]=e.decodeExponentialGolombNumber(),S[B]=e.decodeExponentialGolombNumber();const y=e.decodeExponentialGolombNumber(),A=e.decodeExponentialGolombNumber(),w=e.decodeExponentialGolombNumber(),D=e.decodeExponentialGolombNumber(),T=e.decodeExponentialGolombNumber(),W=e.decodeExponentialGolombNumber(),Y=!!e.next();let N,P;Y&&(N=!!e.next(),N&&(P=io(e)));const L=!!e.next(),I=!!e.next(),G=!!e.next();let z,$,q,K,Q;G&&(z=e.read(4),$=e.read(4),q=e.read(4),K=e.read(4),Q=!!e.next());const Z=e.decodeExponentialGolombNumber(),re=[];for(let B=0;B<Z;B+=1)re[B]=oo(e,B,Z,re);const ae=!!e.next();let ce,le,J;if(ae){ce=e.decodeExponentialGolombNumber(),le=[],J=[];for(let B=0;B<ce;B+=1)le[B]=e.read(C+4),J[B]=!!e.next()}const pe=!!e.next(),Oe=!!e.next(),Ne=!!e.next();let be;Ne&&(be=ao(e,r));const O=!!e.next();let ne,R,j,M,H;if(O&&(ne=!!e.next(),R=!!e.next(),j=!!e.next(),M=!!e.next(),H=e.read(4)),ne)throw new Error("Not implemented");let V;R&&(V=lo(e));let F;if(j&&(F=uo(e)),M)throw new Error("Not implemented");let X;if(H){X=[];let B=0;for(;!e.ended;)X[B]=!!e.next(),B+=1}return{sps_video_parameter_set_id:n,sps_max_sub_layers_minus1:r,sps_temporal_id_nesting_flag:i,profileTierLevel:s,sps_seq_parameter_set_id:c,chroma_format_idc:o,separate_colour_plane_flag:u,pic_width_in_luma_samples:d,pic_height_in_luma_samples:f,conformance_window_flag:h,conf_win_left_offset:_,conf_win_right_offset:m,conf_win_top_offset:x,conf_win_bottom_offset:p,bit_depth_luma_minus8:v,bit_depth_chroma_minus8:E,log2_max_pic_order_cnt_lsb_minus4:C,sps_sub_layer_ordering_info_present_flag:k,sps_max_dec_pic_buffering_minus1:g,sps_max_num_reorder_pics:b,sps_max_latency_increase_plus1:S,log2_min_luma_coding_block_size_minus3:y,log2_diff_max_min_luma_coding_block_size:A,log2_min_luma_transform_block_size_minus2:w,log2_diff_max_min_luma_transform_block_size:D,max_transform_hierarchy_depth_inter:T,max_transform_hierarchy_depth_intra:W,scaling_list_enabled_flag:Y,sps_scaling_list_data_present_flag:N,scalingListData:P,amp_enabled_flag:L,sample_adaptive_offset_enabled_flag:I,pcm_enabled_flag:G,pcm_sample_bit_depth_luma_minus1:z,pcm_sample_bit_depth_chroma_minus1:$,log2_min_pcm_luma_coding_block_size_minus3:q,log2_diff_max_min_pcm_luma_coding_block_size:K,pcm_loop_filter_disabled_flag:Q,num_short_term_ref_pic_sets:Z,shortTermRefPicSets:re,long_term_ref_pics_present_flag:ae,num_long_term_ref_pics_sps:ce,lt_ref_pic_poc_lsb_sps:le,used_by_curr_pic_lt_sps_flag:J,sps_temporal_mvp_enabled_flag:pe,strong_intra_smoothing_enabled_flag:Oe,vui_parameters_present_flag:Ne,vuiParameters:be,sps_extension_present_flag:O,sps_range_extension_flag:ne,sps_multilayer_extension_flag:R,sps_3d_extension_flag:j,sps_scc_extension_flag:M,sps_extension_4bits:H,spsMultilayerExtension:V,sps3dExtension:F,sps_extension_data_flag:X}}function dn(t){const e=t.read(2),n=!!t.next(),r=t.read(5),i=t.peekBytes(4),s=[];for(let k=0;k<32;k+=1)s[k]=!!t.next();const c=t.peekBytes(6),o=!!t.next(),u=!!t.next(),d=!!t.next(),f=!!t.next();let h,_,m,x,p,v,E,C,g,b;r===4||s[4]||r===5||s[5]||r===6||s[6]||r===7||s[7]||r===8||s[8]||r===9||s[9]||r===10||s[10]||r===11||s[11]?(h=!!t.next(),_=!!t.next(),m=!!t.next(),x=!!t.next(),p=!!t.next(),v=!!t.next(),E=!!t.next(),C=!!t.next(),g=!!t.next(),r===5||s[5]||r===9||s[9]||r===10||s[10]||r===11||s[11]?(b=!!t.next(),t.skip(33)):t.skip(34)):r===2||s[2]?(t.skip(7),C=!!t.next(),t.skip(35)):t.skip(43);let S;return r===1||s[1]||r===2||s[2]||r===3||s[3]||r===4||s[4]||r===5||s[5]||r===9||s[9]||r===11||s[11]?S=!!t.next():t.skip(1),{profile_space:e,tier_flag:n,profile_idc:r,profileCompatibilitySet:i,profile_compatibility_flag:s,constraintSet:c,progressive_source_flag:o,interlaced_source_flag:u,non_packed_constraint_flag:d,frame_only_constraint_flag:f,max_12bit_constraint_flag:h,max_10bit_constraint_flag:_,max_8bit_constraint_flag:m,max_422chroma_constraint_flag:x,max_420chroma_constraint_flag:p,max_monochrome_constraint_flag:v,intra_constraint_flag:E,one_picture_only_constraint_flag:C,lower_bit_rate_constraint_flag:g,max_14bit_constraint_flag:b,inbld_flag:S}}function sr(t,e,n){let r;r=dn(t);const i=t.read(8),s=[],c=[];for(let d=0;d<n;d+=1)s[d]=!!t.next(),c[d]=!!t.next();if(n>0)for(let d=n;d<8;d+=1)t.read(2);const o=[],u=[];for(let d=0;d<n;d+=1)s[d]&&(o[d]=dn(t)),c[d]&&(u[d]=t.read(8));return{generalProfileTier:r,general_level_idc:i,sub_layer_profile_present_flag:s,sub_layer_level_present_flag:c,subLayerProfileTier:o,sub_layer_level_idc:u}}function io(t){const e=[];for(let n=0;n<4;n+=1){e[n]=[];for(let r=0;r<6;r+=n===3?3:1)if(!!!t.next())t.decodeExponentialGolombNumber();else{let s=8;const c=Math.min(64,1<<4+(n<<1));n>1&&(s=t.decodeExponentialGolombNumber()+8),e[n][r]=[];for(let o=0;o<c;o+=1){const u=t.decodeExponentialGolombNumber();s=(s+u+256)%256,e[n][r][o]=s}}}return e}function oo(t,e,n,r){let i=!1;e!==0&&(i=!!t.next());let s=0,c=!1,o=0;const u=[],d=[];let f=0,h=0;const _=[],m=[],x=[],p=[];if(i){e===n&&(s=t.decodeExponentialGolombNumber()),c=!!t.next(),o=t.decodeExponentialGolombNumber();const v=e-(s+1),E=r[v],C=E.num_negative_pics+E.num_positive_pics;for(let T=0;T<=C;T+=1)u[T]=!!t.next(),u[T]?d[T]=!0:d[T]=!!t.next();const g=(1-2*Number(c))*(o+1),b=[],S=[],k=[],y=[];let A=0;for(let T=0;T<E.num_negative_pics;T+=1)A-=E.delta_poc_s0_minus1[T]+1,b[T]=A;A=0;for(let T=0;T<E.num_positive_pics;T+=1)A+=E.delta_poc_s1_minus1[T]+1,S[T]=A;let w=0;if(E.num_positive_pics>0)for(let T=E.num_positive_pics-1;T>=0;T-=1)A=S[T]+g,A<0&&d[E.num_negative_pics+T]&&(k[w]=A,m[w]=u[E.num_negative_pics+T],w+=1);g<0&&d[C]&&(k[w]=g,m[w]=u[C],w+=1);for(let T=0;T<E.num_negative_pics;T+=1)A=b[T]+g,A<0&&d[T]&&(k[w]=A,m[w]=u[T],w+=1);f=w;let D=0;for(w=0;w<f;w+=1){const T=k[w];_[w]=-(T-D-1),D=T}if(w=0,E.num_negative_pics>0)for(let T=E.num_negative_pics-1;T>=0;T-=1)A=b[T]+g,A>0&&d[T]&&(y[w]=A,p[w]=u[T],w+=1);g>0&&d[C]&&(y[w]=g,p[w]=u[C],w+=1);for(let T=0;T<E.num_positive_pics;T+=1)A=S[T]+g,A>0&&d[E.num_negative_pics+T]&&(y[w]=A,p[w]=u[E.num_negative_pics+T],w+=1);for(h=w,D=0,w=0;w<h;w+=1){const T=y[w];x[w]=T-D-1,D=T}}else{f=t.decodeExponentialGolombNumber(),h=t.decodeExponentialGolombNumber();for(let v=0;v<f;v+=1)_[v]=t.decodeExponentialGolombNumber(),m[v]=!!t.next();for(let v=0;v<h;v+=1)x[v]=t.decodeExponentialGolombNumber(),p[v]=!!t.next()}return{stRpsIdx:e,num_short_term_ref_pic_sets:n,inter_ref_pic_set_prediction_flag:i,delta_idx_minus1:s,delta_rps_sign:c,abs_delta_rps_minus1:o,used_by_curr_pic_flag:u,use_delta_flag:d,num_negative_pics:f,num_positive_pics:h,delta_poc_s0_minus1:_,used_by_curr_pic_s0_flag:m,delta_poc_s1_minus1:x,used_by_curr_pic_s1_flag:p}}function ao(t,e){const n=!!t.next();let r,i,s;n&&(r=t.read(8),r===255&&(i=t.read(16),s=t.read(16)));const c=!!t.next();let o;c&&(o=!!t.next());const u=!!t.next();let d,f,h,_,m,x;u&&(d=t.read(3),f=!!t.next(),h=!!t.next(),h&&(_=t.read(8),m=t.read(8),x=t.read(8)));const p=!!t.next();let v,E;p&&(v=t.decodeExponentialGolombNumber(),E=t.decodeExponentialGolombNumber());const C=!!t.next(),g=!!t.next(),b=!!t.next(),S=!!t.next();let k,y,A,w;S&&(k=t.decodeExponentialGolombNumber(),y=t.decodeExponentialGolombNumber(),A=t.decodeExponentialGolombNumber(),w=t.decodeExponentialGolombNumber());const D=!!t.next();let T,W,Y,N,P,L;D&&(T=t.read(32),W=t.read(32),Y=!!t.next(),Y&&(N=t.decodeExponentialGolombNumber()),P=!!t.next(),P&&(L=ir(t,!0,e)));const I=!!t.next();let G,z,$,q,K,Q,Z,re;return I&&(G=!!t.next(),z=!!t.next(),$=!!t.next(),q=t.decodeExponentialGolombNumber(),K=t.decodeExponentialGolombNumber(),Q=t.decodeExponentialGolombNumber(),Z=t.decodeExponentialGolombNumber(),re=t.decodeExponentialGolombNumber()),{aspect_ratio_info_present_flag:n,aspect_ratio_idc:r,sar_width:i,sar_height:s,overscan_info_present_flag:c,overscan_appropriate_flag:o,video_signal_type_present_flag:u,video_format:d,video_full_range_flag:f,colour_description_present_flag:h,colour_primaries:_,transfer_characteristics:m,matrix_coeffs:x,chroma_loc_info_present_flag:p,chroma_sample_loc_type_top_field:v,chroma_sample_loc_type_bottom_field:E,neutral_chroma_indication_flag:C,field_seq_flag:g,frame_field_info_present_flag:b,default_display_window_flag:S,def_disp_win_left_offset:k,def_disp_win_right_offset:y,def_disp_win_top_offset:A,def_disp_win_bottom_offset:w,vui_timing_info_present_flag:D,vui_num_units_in_tick:T,vui_time_scale:W,vui_poc_proportional_to_timing_flag:Y,vui_num_ticks_poc_diff_one_minus1:N,vui_hrd_parameters_present_flag:P,vui_hrd_parameters:L,bitstream_restriction_flag:I,tiles_fixed_structure_flag:G,motion_vectors_over_pic_boundaries_flag:z,restricted_ref_pic_lists_flag:$,min_spatial_segmentation_idc:q,max_bytes_per_pic_denom:K,max_bits_per_min_cu_denom:Q,log2_max_mv_length_horizontal:Z,log2_max_mv_length_vertical:re}}function ir(t,e,n){let r,i,s,c,o,u,d,f,h,_,m,x,p;e&&(r=!!t.next(),i=!!t.next(),(r||i)&&(s=!!t.next(),s&&(c=t.read(8),o=t.read(5),u=!!t.next(),d=t.read(5)),f=t.read(4),h=t.read(4),s&&(_=t.read(4)),m=t.read(5),x=t.read(5),p=t.read(5)));const v=[],E=[],C=[],g=[],b=[],S=[],k=[];for(let y=0;y<=n;y+=1)v[y]=!!t.next(),v[y]||(E[y]=!!t.next()),E[y]?C[y]=t.decodeExponentialGolombNumber():g[y]=!!t.next(),g[y]||(b[y]=t.decodeExponentialGolombNumber()),r&&(S[y]=fn(t,y,hn(b[y]))),i&&(k[y]=fn(t,y,hn(b[y])));return{nal_hrd_parameters_present_flag:r,vcl_hrd_parameters_present_flag:i,sub_pic_hrd_params_present_flag:s,tick_divisor_minus2:c,du_cpb_removal_delay_increment_length_minus1:o,sub_pic_cpb_params_in_pic_timing_sei_flag:u,dpb_output_delay_du_length_minus1:d,bit_rate_scale:f,cpb_size_scale:h,cpb_size_du_scale:_,initial_cpb_removal_delay_length_minus1:m,au_cpb_removal_delay_length_minus1:x,dpb_output_delay_length_minus1:p,fixed_pic_rate_general_flag:v,fixed_pic_rate_within_cvs_flag:E,elemental_duration_in_tc_minus1:C,low_delay_hrd_flag:g,cpb_cnt_minus1:b,nalHrdParameters:S,vclHrdParameters:k}}function fn(t,e,n){const r=[],i=[],s=[],c=[],o=[];for(let u=0;u<n;u+=1)r[u]=t.decodeExponentialGolombNumber(),i[u]=t.decodeExponentialGolombNumber(),e>0&&(o[u]=!!t.next());return{bit_rate_value_minus1:r,cpb_size_value_minus1:i,cpb_size_du_value_minus1:s,bit_rate_du_value_minus1:c,cbr_flag:o}}function hn(t){return t+1}function co(t){let e,n,r,i=0;for(const s of rr(t)){const c=no(s),o={...c,data:s,rbsp:s.subarray(2)};switch(c.nal_unit_type){case 32:e=o;break;case 33:n=o;break;case 34:r=o;break;default:continue}if(i+=1,i===3)return{videoParameterSet:e,sequenceParameterSet:n,pictureParameterSet:r}}throw new Error("Invalid data")}function lo(t){return{inter_view_mv_vert_constraint_flag:!!t.next()}}function uo(t){const e=[],n=[];e[0]=!!t.next(),n[0]=!!t.next();const r=t.decodeExponentialGolombNumber(),i=!!t.next(),s=!!t.next(),c=!!t.next(),o=!!t.next();e[1]=!!t.next(),n[1]=!!t.next();const u=!!t.next(),d=t.decodeExponentialGolombNumber(),f=!!t.next(),h=!!t.next(),_=!!t.next(),m=!!t.next(),x=!!t.next();return{iv_di_mc_enabled_flag:e,iv_mv_scal_enabled_flag:n,log2_ivmc_sub_pb_size_minus3:r,iv_res_pred_enabled_flag:i,depth_ref_enabled_flag:s,vsp_mc_enabled_flag:c,dbbp_enabled_flag:o,tex_mc_enabled_flag:u,log2_texmc_sub_pb_size_minus3:d,intra_contour_enabled_flag:f,intra_dc_only_wedge_enabled_flag:h,cqt_cu_part_pred_enabled_flag:_,inter_dc_only_enabled_flag:m,skip_intra_enabled_flag:x}}function fo(t){const{videoParameterSet:e,sequenceParameterSet:n,pictureParameterSet:r}=co(t),{profileTierLevel:{generalProfileTier:{profile_space:i,tier_flag:s,profile_idc:c,profileCompatibilitySet:o,constraintSet:u},general_level_idc:d}}=ro(e.rbsp),{chroma_format_idc:f,pic_width_in_luma_samples:h,pic_height_in_luma_samples:_,conf_win_left_offset:m=0,conf_win_right_offset:x=0,conf_win_top_offset:p=0,conf_win_bottom_offset:v=0}=so(n.rbsp),E=eo(f),C=to(f),g=h-E*(m+x),b=_-C*(p+v);return{videoParameterSet:e,sequenceParameterSet:n,pictureParameterSet:r,generalProfileSpace:i,generalProfileIndex:c,generalProfileCompatibilitySet:o,generalTierFlag:s,generalLevelIndex:d,generalConstraintSet:u,encodedWidth:h,encodedHeight:_,cropLeft:m,cropRight:x,cropTop:p,cropBottom:v,croppedWidth:g,croppedHeight:b}}function pn(t){return t.toString(16).toUpperCase()}function bt(t){return t.toString(16).toUpperCase().padStart(2,"0")}function Me(t){return t.toString(10).padStart(2,"0")}class ho{#e;#t;constructor(e,n){this.#e=e,this.#t=n}#n(e){const r=new se(e).searchSequenceHeaderObu();if(!r)return;const{seq_profile:i,seq_level_idx:[s=0],max_frame_width_minus_1:c,max_frame_height_minus_1:o,color_config:{BitDepth:u,mono_chrome:d,subsampling_x:f,subsampling_y:h,chroma_sample_position:_,color_description_present_flag:m}}=r;let x,p,v,E;m?{color_primaries:x,transfer_characteristics:p,matrix_coefficients:v,color_range:E}=r.color_config:(x=se.ColorPrimaries.Bt709,p=se.TransferCharacteristics.Bt709,v=se.MatrixCoefficients.Bt709,E=!1);const C=c+1,g=o+1;this.#t(C,g);const b=["av01",i.toString(16),Me(s)+(r.seq_tier[0]?"H":"M"),Me(u),d?"1":"0",(f?"1":"0")+(h?"1":"0")+_.toString(),Me(x),Me(p),Me(v),E?"1":"0"].join(".");this.#e.configure({codec:b,optimizeForLatency:!0})}decode(e){e.type!=="configuration"&&(this.#n(e.data),this.#e.decode(new EncodedVideoChunk({type:e.keyframe===!1?"delta":"key",timestamp:0,data:e.data})))}}class or{#e;#t;constructor(e){this.#t=e}decode(e){if(e.type==="configuration"){this.#e=e.data,this.configure(e.data);return}let n;this.#e!==void 0?(n=new Uint8Array(this.#e.length+e.data.length),n.set(this.#e,0),n.set(e.data,this.#e.length),this.#e=void 0):n=e.data,this.#t.decode(new EncodedVideoChunk({type:e.keyframe===!1?"delta":"key",timestamp:0,data:n}))}}class po extends or{#e;#t;constructor(e,n){super(e),this.#e=e,this.#t=n}configure(e){const{profileIndex:n,constraintSet:r,levelIndex:i,croppedWidth:s,croppedHeight:c}=Zi(e);this.#t(s,c);const o="avc1."+bt(n)+bt(r)+bt(i);this.#e.configure({codec:o,optimizeForLatency:!0})}}class mo extends or{#e;#t;constructor(e,n){super(e),this.#e=e,this.#t=n}configure(e){const{generalProfileSpace:n,generalProfileIndex:r,generalProfileCompatibilitySet:i,generalTierFlag:s,generalLevelIndex:c,generalConstraintSet:o,croppedWidth:u,croppedHeight:d}=fo(e);this.#t(u,d);const f=["hev1",["","A","B","C"][n]+r.toString(),pn(Hi(i,0)),(s?"H":"L")+c.toString(),...Array.from(o,pn)].join(".");this.#e.configure({codec:f,codedWidth:u,codedHeight:d,optimizeForLatency:!0})}}class _o{listeners=[];constructor(){this.event=this.event.bind(this)}addEventListener(e){this.listeners.push(e);const n=()=>{const r=this.listeners.indexOf(e);r!==-1&&this.listeners.splice(r,1)};return n.dispose=n,n}event=(e,n,...r)=>{const i={listener:e,thisArg:n,args:r};return this.addEventListener(i)};fire(e){for(const n of this.listeners.slice())n.listener.apply(n.thisArg,[e,...n.args])}dispose(){this.listeners.length=0}}class go{#e;#t=new ReadableStream({start:e=>{this.#e=e},pull:e=>{e.enqueue(this.#r())}},{highWaterMark:0});#n=this.#t.getReader();#r;#i=0;#s;constructor(e,n){this.#r=e,this.#s=n}async borrow(){return(await this.#n.read()).value}return(e){this.#i<this.#s&&(this.#e.enqueue(e),this.#i+=1)}}class xo{#e;#t;constructor(){typeof OffscreenCanvas<"u"?this.#e=new OffscreenCanvas(1,1):(this.#e=document.createElement("canvas"),this.#e.width=1,this.#e.height=1),this.#t=this.#e.getContext("bitmaprenderer",{alpha:!1})}async capture(e){this.#e.width=e.displayWidth,this.#e.height=e.displayHeight;const n=await createImageBitmap(e);return this.#t.transferFromImageBitmap(n),this.#e instanceof OffscreenCanvas?await this.#e.convertToBlob({type:"image/png"}):new Promise((r,i)=>{this.#e.toBlob(s=>{s?r(s):i(new Error("Failed to convert canvas to blob"))},"image/png")})}}const mn=new go(()=>new xo,4);class _n{static get isSupported(){return typeof globalThis.VideoDecoder<"u"}static capabilities={h264:{},h265:{},av1:{}};#e;get codec(){return this.#e}#t;#n;get writable(){return this.#n}#r;#i;#s;get renderer(){return this.#s}#o=0;#c=0;get framesRendered(){return this.#c}#l=0;get framesSkipped(){return this.#l}#d=new _o;get sizeChanged(){return this.#d.event}#a;#p=!1;#u;#f;#m=0;constructor({codec:e,renderer:n}){switch(this.#e=e,this.#s=n,this.#a=new VideoDecoder({output:r=>{if(this.#f?.close(),this.#f=r.clone(),this.#p){this.#u&&(this.#u.close(),this.#l+=1),this.#u=r;return}this.#g(r)},error:r=>{this.#_(r)}}),this.#e){case st.H264:this.#t=new po(this.#a,this.#h);break;case st.H265:this.#t=new mo(this.#a,this.#h);break;case st.AV1:this.#t=new ho(this.#a,this.#h);break;default:throw new Error(`Unsupported codec: ${this.#e}`)}this.#n=new Xi({start:r=>{this.#r?r.error(this.#r):this.#i=r},write:r=>{this.#t.decode(r)}}),this.#x()}#_(e){if(this.#i)try{this.#i.error(e)}catch{}else this.#r=e}async#g(e){try{if(this.#p=!0,this.#h(e.displayWidth,e.displayHeight),await this.#s.draw(e),this.#o+=1,e.close(),this.#u){const n=this.#u;this.#u=void 0,await this.#g(n)}this.#p=!1}catch(n){this.#_(n)}}#h=(e,n)=>{this.#s.setSize(e,n),this.#d.fire({width:e,height:n})};#x=()=>{this.#o>0&&(this.#c+=1,this.#l+=this.#o-1,this.#o=0),this.#m=requestAnimationFrame(this.#x)};async snapshot(){const e=this.#f;if(!e)return;const n=await mn.borrow(),r=await n.capture(e);return mn.return(n),r}dispose(){cancelAnimationFrame(this.#m),this.#a.state!=="closed"&&this.#a.close(),this.#u?.close(),this.#f?.close()}}var yt={exports:{}},wt={exports:{}},gn;function Kt(){return gn||(gn=1,(function(){function t(e,n){throw new Error("abstract")}t.prototype.drawFrame=function(e){throw new Error("abstract")},t.prototype.clear=function(){throw new Error("abstract")},wt.exports=t})()),wt.exports}var Et={exports:{}},Tt={exports:{}},St={exports:{}},xn;function vo(){return xn||(xn=1,(function(){function t(e){for(var n=0,r=e>>1;r!=0;)r=r>>1,n++;if(e!==1<<n)throw"chroma plane dimensions must be power of 2 ratio to luma plane dimensions; got "+e;return n}St.exports=t})()),St.exports}var vn;function bo(){return vn||(vn=1,(function(){var t=vo();function e(n,r){var i=n.format.width|0,s=n.format.height|0,c=t(n.format.width/n.format.chromaWidth)|0,o=t(n.format.height/n.format.chromaHeight)|0,u=n.y.bytes,d=n.u.bytes,f=n.v.bytes,h=n.y.stride|0,_=n.u.stride|0,m=n.v.stride|0,x=i<<2,p=0,v=0,E=0,C=0,g=0,b=0,S=0,k=0,y=0,A=0,w=0,D=0,T=0,W=0,Y=0,N=0,P=0,L=0;if(c==1&&o==1)for(S=0,k=x,L=0,N=0;N<s;N+=2){for(v=N*h|0,E=v+h|0,C=L*_|0,g=L*m|0,Y=0;Y<i;Y+=2)y=d[C++]|0,A=f[g++]|0,D=(409*A|0)-57088|0,T=(100*y|0)+(208*A|0)-34816|0,W=(516*y|0)-70912|0,w=298*u[v++]|0,r[S]=w+D>>8,r[S+1]=w-T>>8,r[S+2]=w+W>>8,S+=4,w=298*u[v++]|0,r[S]=w+D>>8,r[S+1]=w-T>>8,r[S+2]=w+W>>8,S+=4,w=298*u[E++]|0,r[k]=w+D>>8,r[k+1]=w-T>>8,r[k+2]=w+W>>8,k+=4,w=298*u[E++]|0,r[k]=w+D>>8,r[k+1]=w-T>>8,r[k+2]=w+W>>8,k+=4;S+=x,k+=x,L++}else for(b=0,N=0;N<s;N++)for(P=0,L=N>>o,p=N*h|0,C=L*_|0,g=L*m|0,Y=0;Y<i;Y++)P=Y>>c,y=d[C+P]|0,A=f[g+P]|0,D=(409*A|0)-57088|0,T=(100*y|0)+(208*A|0)-34816|0,W=(516*y|0)-70912|0,w=298*u[p++]|0,r[b]=w+D>>8,r[b+1]=w-T>>8,r[b+2]=w+W>>8,b+=4}Tt.exports={convertYCbCr:e}})()),Tt.exports}var bn;function yo(){return bn||(bn=1,(function(){var t=Kt(),e=bo();function n(r){var i=this,s=r.getContext("2d"),c=null,o=null,u=null;function d(h,_){c=s.createImageData(h,_);for(var m=c.data,x=h*_*4,p=0;p<x;p+=4)m[p+3]=255}function f(h,_){o=document.createElement("canvas"),o.width=h,o.height=_,u=o.getContext("2d")}return i.drawFrame=function(_){var m=_.format;(r.width!==m.displayWidth||r.height!==m.displayHeight)&&(r.width=m.displayWidth,r.height=m.displayHeight),(c===null||c.width!=m.width||c.height!=m.height)&&d(m.width,m.height),e.convertYCbCr(_,c.data);var x=m.cropWidth!=m.displayWidth||m.cropHeight!=m.displayHeight,p;x?(o||f(m.cropWidth,m.cropHeight),p=u):p=s,p.putImageData(c,-m.cropLeft,-m.cropTop,m.cropLeft,m.cropTop,m.cropWidth,m.cropHeight),x&&s.drawImage(o,0,0,m.displayWidth,m.displayHeight)},i.clear=function(){s.clearRect(0,0,r.width,r.height)},i}n.prototype=Object.create(t.prototype),Et.exports=n})()),Et.exports}var Ct={exports:{}},kt,yn;function wo(){return yn||(yn=1,kt={vertex:`precision mediump float;
14
+
15
+ attribute vec2 aPosition;
16
+ attribute vec2 aLumaPosition;
17
+ attribute vec2 aChromaPosition;
18
+ varying vec2 vLumaPosition;
19
+ varying vec2 vChromaPosition;
20
+ void main() {
21
+ gl_Position = vec4(aPosition, 0, 1);
22
+ vLumaPosition = aLumaPosition;
23
+ vChromaPosition = aChromaPosition;
24
+ }
25
+ `,fragment:`// inspired by https://github.com/mbebenita/Broadway/blob/master/Player/canvas.js
26
+
27
+ precision mediump float;
28
+
29
+ uniform sampler2D uTextureY;
30
+ uniform sampler2D uTextureCb;
31
+ uniform sampler2D uTextureCr;
32
+ varying vec2 vLumaPosition;
33
+ varying vec2 vChromaPosition;
34
+ void main() {
35
+ // Y, Cb, and Cr planes are uploaded as ALPHA textures.
36
+ float fY = texture2D(uTextureY, vLumaPosition).w;
37
+ float fCb = texture2D(uTextureCb, vChromaPosition).w;
38
+ float fCr = texture2D(uTextureCr, vChromaPosition).w;
39
+
40
+ // Premultipy the Y...
41
+ float fYmul = fY * 1.1643828125;
42
+
43
+ // And convert that to RGB!
44
+ gl_FragColor = vec4(
45
+ fYmul + 1.59602734375 * fCr - 0.87078515625,
46
+ fYmul - 0.39176171875 * fCb - 0.81296875 * fCr + 0.52959375,
47
+ fYmul + 2.017234375 * fCb - 1.081390625,
48
+ 1
49
+ );
50
+ }
51
+ `,vertexStripe:`precision mediump float;
52
+
53
+ attribute vec2 aPosition;
54
+ attribute vec2 aTexturePosition;
55
+ varying vec2 vTexturePosition;
56
+
57
+ void main() {
58
+ gl_Position = vec4(aPosition, 0, 1);
59
+ vTexturePosition = aTexturePosition;
60
+ }
61
+ `,fragmentStripe:`// extra 'stripe' texture fiddling to work around IE 11's poor performance on gl.LUMINANCE and gl.ALPHA textures
62
+
63
+ precision mediump float;
64
+
65
+ uniform sampler2D uStripe;
66
+ uniform sampler2D uTexture;
67
+ varying vec2 vTexturePosition;
68
+ void main() {
69
+ // Y, Cb, and Cr planes are mapped into a pseudo-RGBA texture
70
+ // so we can upload them without expanding the bytes on IE 11
71
+ // which doesn't allow LUMINANCE or ALPHA textures
72
+ // The stripe textures mark which channel to keep for each pixel.
73
+ // Each texture extraction will contain the relevant value in one
74
+ // channel only.
75
+
76
+ float fLuminance = dot(
77
+ texture2D(uStripe, vTexturePosition),
78
+ texture2D(uTexture, vTexturePosition)
79
+ );
80
+
81
+ gl_FragColor = vec4(0, 0, 0, fLuminance);
82
+ }
83
+ `}),kt}var wn;function Eo(){return wn||(wn=1,(function(){var t=Kt(),e=wo();function n(r){var i=this,s=n.contextForCanvas(r);if(s===null)throw new Error("WebGL unavailable");function c(N,P){var L=s.createShader(N);if(s.shaderSource(L,P),s.compileShader(L),!s.getShaderParameter(L,s.COMPILE_STATUS)){var I=s.getShaderInfoLog(L);throw s.deleteShader(L),new Error("GL shader compilation for "+N+" failed: "+I)}return L}var o,u,d=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),f={},h={},_={},m,x,p,v,E,C,g,b,S,k;function y(N,P){return(!f[N]||P)&&(f[N]=s.createTexture()),f[N]}function A(N,P,L,I,G){var z=!f[N]||P,$=y(N,P);if(s.activeTexture(s.TEXTURE0),n.stripe){var q=!f[N+"_temp"]||P,K=y(N+"_temp",P);s.bindTexture(s.TEXTURE_2D,K),q?(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,L/4,I,0,s.RGBA,s.UNSIGNED_BYTE,G)):s.texSubImage2D(s.TEXTURE_2D,0,0,0,L/4,I,s.RGBA,s.UNSIGNED_BYTE,G);var Q=f[N+"_stripe"],Z=!Q||P;Z&&(Q=y(N+"_stripe",P)),s.bindTexture(s.TEXTURE_2D,Q),Z&&(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,L,1,0,s.RGBA,s.UNSIGNED_BYTE,T(L)))}else s.bindTexture(s.TEXTURE_2D,$),z?(s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texImage2D(s.TEXTURE_2D,0,s.ALPHA,L,I,0,s.ALPHA,s.UNSIGNED_BYTE,G)):s.texSubImage2D(s.TEXTURE_2D,0,0,0,L,I,s.ALPHA,s.UNSIGNED_BYTE,G)}function w(N,P,L,I){var G=f[N];s.useProgram(u);var z=h[N];(!z||P)&&(s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,G),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,L,I,0,s.RGBA,s.UNSIGNED_BYTE,null),z=h[N]=s.createFramebuffer()),s.bindFramebuffer(s.FRAMEBUFFER,z),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,G,0);var $=f[N+"_temp"];s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,$),s.uniform1i(C,1);var q=f[N+"_stripe"];s.activeTexture(s.TEXTURE2),s.bindTexture(s.TEXTURE_2D,q),s.uniform1i(E,2),s.bindBuffer(s.ARRAY_BUFFER,m),s.enableVertexAttribArray(x),s.vertexAttribPointer(x,2,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,p),s.enableVertexAttribArray(v),s.vertexAttribPointer(v,2,s.FLOAT,!1,0,0),s.viewport(0,0,L,I),s.drawArrays(s.TRIANGLES,0,d.length/2),s.bindFramebuffer(s.FRAMEBUFFER,null)}function D(N,P,L){s.activeTexture(P),s.bindTexture(s.TEXTURE_2D,f[N]),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.uniform1i(s.getUniformLocation(o,N),L)}function T(N){if(_[N])return _[N];for(var P=N,L=new Uint32Array(P),I=0;I<P;I+=4)L[I]=255,L[I+1]=65280,L[I+2]=16711680,L[I+3]=4278190080;return _[N]=new Uint8Array(L.buffer)}function W(N,P){var L=c(s.VERTEX_SHADER,N),I=c(s.FRAGMENT_SHADER,P),G=s.createProgram();if(s.attachShader(G,L),s.attachShader(G,I),s.linkProgram(G),!s.getProgramParameter(G,s.LINK_STATUS)){var z=s.getProgramInfoLog(G);throw s.deleteProgram(G),new Error("GL program linking failed: "+z)}return G}function Y(){if(n.stripe){u=W(e.vertexStripe,e.fragmentStripe),s.getAttribLocation(u,"aPosition"),p=s.createBuffer();var N=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]);s.bindBuffer(s.ARRAY_BUFFER,p),s.bufferData(s.ARRAY_BUFFER,N,s.STATIC_DRAW),v=s.getAttribLocation(u,"aTexturePosition"),E=s.getUniformLocation(u,"uStripe"),C=s.getUniformLocation(u,"uTexture")}o=W(e.vertex,e.fragment),m=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,m),s.bufferData(s.ARRAY_BUFFER,d,s.STATIC_DRAW),x=s.getAttribLocation(o,"aPosition"),g=s.createBuffer(),b=s.getAttribLocation(o,"aLumaPosition"),S=s.createBuffer(),k=s.getAttribLocation(o,"aChromaPosition")}return i.drawFrame=function(N){var P=N.format,L=!o||r.width!==P.displayWidth||r.height!==P.displayHeight;if(L&&(r.width=P.displayWidth,r.height=P.displayHeight,i.clear()),o||Y(),L){var I=function(G,z,$){var q=P.cropLeft/$,K=(P.cropLeft+P.cropWidth)/$,Q=(P.cropTop+P.cropHeight)/P.height,Z=P.cropTop/P.height,re=new Float32Array([q,Q,K,Q,q,Z,q,Z,K,Q,K,Z]);s.bindBuffer(s.ARRAY_BUFFER,G),s.bufferData(s.ARRAY_BUFFER,re,s.STATIC_DRAW)};I(g,b,N.y.stride),I(S,k,N.u.stride*P.width/P.chromaWidth)}A("uTextureY",L,N.y.stride,P.height,N.y.bytes),A("uTextureCb",L,N.u.stride,P.chromaHeight,N.u.bytes),A("uTextureCr",L,N.v.stride,P.chromaHeight,N.v.bytes),n.stripe&&(w("uTextureY",L,N.y.stride,P.height),w("uTextureCb",L,N.u.stride,P.chromaHeight),w("uTextureCr",L,N.v.stride,P.chromaHeight)),s.useProgram(o),s.viewport(0,0,r.width,r.height),D("uTextureY",s.TEXTURE0,0),D("uTextureCb",s.TEXTURE1,1),D("uTextureCr",s.TEXTURE2,2),s.bindBuffer(s.ARRAY_BUFFER,m),s.enableVertexAttribArray(x),s.vertexAttribPointer(x,2,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,g),s.enableVertexAttribArray(b),s.vertexAttribPointer(b,2,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,S),s.enableVertexAttribArray(k),s.vertexAttribPointer(k,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLES,0,d.length/2)},i.clear=function(){s.viewport(0,0,r.width,r.height),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT)},i.clear(),i}n.stripe=!1,n.contextForCanvas=function(r){var i={preferLowPowerToHighPerformance:!0,powerPreference:"low-power",failIfMajorPerformanceCaveat:!0,preserveDrawingBuffer:!0};return r.getContext("webgl",i)||r.getContext("experimental-webgl",i)},n.isAvailable=function(){var r=document.createElement("canvas"),i;r.width=1,r.height=1;try{i=n.contextForCanvas(r)}catch{return!1}if(i){var s=i.TEXTURE0,c=4,o=4,u=i.createTexture(),d=new Uint8Array(c*o),f=n.stripe?c/4:c,h=n.stripe?i.RGBA:i.ALPHA,_=n.stripe?i.NEAREST:i.LINEAR;i.activeTexture(s),i.bindTexture(i.TEXTURE_2D,u),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,_),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,_),i.texImage2D(i.TEXTURE_2D,0,h,f,o,0,h,i.UNSIGNED_BYTE,d);var m=i.getError();return!m}else return!1},n.prototype=Object.create(t.prototype),Ct.exports=n})()),Ct.exports}var En;function To(){return En||(En=1,(function(){var t=Kt(),e=yo(),n=Eo(),r={FrameSink:t,SoftwareFrameSink:e,WebGLFrameSink:n,attach:function(i,s){s=s||{};var c="webGL"in s?s.webGL:n.isAvailable();return c?new n(i,s):new e(i,s)}};yt.exports=r})()),yt.exports}To();function ar(){if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("no canvas input found nor any canvas can be created")}class cr{#e;get canvas(){return this.#e}constructor(e){e?this.#e=e:this.#e=ar()}setSize(e,n){(this.#e.width!==e||this.#e.height!==n)&&(this.#e.width=e,this.#e.height=n)}}class So extends cr{#e;constructor(e){super(e),this.#e=this.canvas.getContext("bitmaprenderer",{alpha:!1})}async draw(e){const n=await createImageBitmap(e);this.#e.transferFromImageBitmap(n)}}const Co=Promise.resolve();function Tn(t,e){const n={powerPreference:"low-power",alpha:!1,failIfMajorPerformanceCaveat:!0,preserveDrawingBuffer:!!e};return t.getContext("webgl2",n)||t.getContext("webgl",n)}class qe extends cr{static vertexShaderSource=`
84
+ attribute vec2 xy;
85
+
86
+ varying highp vec2 uv;
87
+
88
+ void main(void) {
89
+ gl_Position = vec4(xy, 0.0, 1.0);
90
+ // Map vertex coordinates (-1 to +1) to UV coordinates (0 to 1).
91
+ // UV coordinates are Y-flipped relative to vertex coordinates.
92
+ uv = vec2((1.0 + xy.x) / 2.0, (1.0 - xy.y) / 2.0);
93
+ }
94
+ `;static fragmentShaderSource=`
95
+ varying highp vec2 uv;
96
+
97
+ uniform sampler2D texture;
98
+
99
+ void main(void) {
100
+ gl_FragColor = texture2D(texture, uv);
101
+ }
102
+ `;static get isSupported(){const e=ar();return!!Tn(e)}#e;constructor(e,n){super(e);const r=Tn(this.canvas,n);if(!r)throw new Error("WebGL not supported");this.#e=r;const i=r.createShader(r.VERTEX_SHADER);if(r.shaderSource(i,qe.vertexShaderSource),r.compileShader(i),!r.getShaderParameter(i,r.COMPILE_STATUS))throw new Error(r.getShaderInfoLog(i));const s=r.createShader(r.FRAGMENT_SHADER);if(r.shaderSource(s,qe.fragmentShaderSource),r.compileShader(s),!r.getShaderParameter(s,r.COMPILE_STATUS))throw new Error(r.getShaderInfoLog(s));const c=r.createProgram();if(r.attachShader(c,i),r.attachShader(c,s),r.linkProgram(c),!r.getProgramParameter(c,r.LINK_STATUS))throw new Error(r.getProgramInfoLog(c));r.useProgram(c);const o=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,1,1,-1]),r.STATIC_DRAW);const u=r.getAttribLocation(c,"xy");r.vertexAttribPointer(u,2,r.FLOAT,!1,0,0),r.enableVertexAttribArray(u);const d=r.createTexture();r.bindTexture(r.TEXTURE_2D,d),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)}draw(e){const n=this.#e;return n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.drawArrays(n.TRIANGLE_FAN,0,4),Co}}const Sn=50,ko=300;function No({deviceId:t,className:e,onFallback:n,fallbackTimeout:r=5e3,enableControl:i=!1,onTapSuccess:s,onTapError:c,onSwipeSuccess:o,onSwipeError:u,onStreamReady:d}){const f=l.useRef(null),h=l.useRef(null),_=l.useRef(null),m=l.useRef(null),x=l.useRef(null),p=l.useRef(null),v=l.useRef(null),E=l.useRef(!1),C=l.useRef(!1),g=l.useRef(n),b=l.useRef(r),S=l.useRef(d),[k,y]=l.useState("connecting"),[A,w]=l.useState(null),[D,T]=l.useState(null),[W,Y]=l.useState(null),N=l.useRef(!1),P=l.useRef(null),L=l.useRef(!1),I=l.useRef(0),G=l.useRef(null),z=l.useRef(null),$=l.useRef(null),q=l.useRef(null);l.useEffect(()=>{g.current=n,b.current=r,S.current=d},[n,r,d]),l.useEffect(()=>{(async()=>{try{const j=await In(t);j.success&&Y({width:j.width,height:j.height})}catch(j){console.error("[ScrcpyPlayer] Failed to fetch device resolution:",j)}})()},[t]);const K=l.useCallback(()=>{const R=m.current,j=_.current;if(!R||!j||!D)return;const M=j.clientWidth,H=j.clientHeight,{width:V,height:F}=D,X=V/F;let B=M,ue=M/X;ue>H&&(ue=H,B=H*X),R.width=V,R.height=F,R.style.width=`${B}px`,R.style.height=`${ue}px`},[D]);l.useEffect(()=>{const R=()=>K();return window.addEventListener("resize",R),()=>window.removeEventListener("resize",R)},[K]),l.useEffect(()=>{K()},[D,K]);const Q=l.useCallback(async()=>{if(qe.isSupported){const j=new qe;return{renderer:j,element:j.canvas}}const R=new So;return{renderer:R,element:R.canvas}},[]),Z=l.useCallback(async R=>{if(!_n.isSupported)throw new Error("Current browser does not support WebCodecs API. Please use the latest Chrome/Edge.");const{renderer:j,element:M}=await Q();return m.current=M,_.current&&!M.parentElement&&_.current.appendChild(M),new _n({codec:R,renderer:j})},[Q]),re=l.useCallback(()=>{E.current||(E.current=!0,x.current&&(clearTimeout(x.current),x.current=null))},[]),ae=l.useCallback(R=>{let j=!1,M=[];const H=new TransformStream({transform(F,X){if(F.type==="configuration"){X.enqueue(F),j=!0,M.length>0&&(M.forEach(B=>X.enqueue(B)),M=[]);return}if(F.type==="data"&&!j){M.push(F);return}X.enqueue(F)}});return new ReadableStream({start(F){let X=!1;const B=me=>{if(!X)try{re();const we={...me,data:me.data instanceof Uint8Array?me.data:new Uint8Array(me.data)};F.enqueue(we)}catch(we){console.error("[ScrcpyPlayer] Video enqueue error:",we),X=!0,ye()}},ue=me=>{X||(F.error(new Error(me?.message||"Socket error")),X=!0,ye())},Re=()=>{X||(F.close(),X=!0,ye())},ye=()=>{f.current?.off("video-data",B),f.current?.off("error",ue),f.current?.off("disconnect",Re)};return f.current?.on("video-data",B),f.current?.on("error",ue),f.current?.on("disconnect",Re),()=>{X=!0,ye()}}}).pipeThrough(H)},[re]),ce=l.useCallback((R=!1)=>{if(R&&(C.current=!0),h.current){try{h.current.dispose()}catch(j){console.error("[ScrcpyPlayer] Failed to dispose decoder:",j)}h.current=null}m.current=null,f.current&&(f.current.disconnect(),f.current=null),S.current?.(null),p.current&&(clearTimeout(p.current),p.current=null),x.current&&(clearTimeout(x.current),x.current=null),y("disconnected"),T(null),w(null)},[]),le=l.useCallback(()=>{ce(!0),E.current=!1,y("connecting"),w(null);const R=rt({path:"/socket.io",transports:["websocket"],timeout:1e4});f.current=R,R.on("connect",()=>{R.emit("connect-device",{device_id:t,maxSize:1280,bitRate:4e6}),x.current=setTimeout(()=>{E.current||(y("error"),w("Video stream timeout"),C.current=!0,R.close(),g.current?.())},b.current)}),R.on("video-metadata",async j=>{try{h.current&&(h.current.dispose(),h.current=null);const M=j?.codec?j.codec:st.H264;h.current=await Z(M),h.current.sizeChanged(({width:V,height:F})=>{T({width:V,height:F})}),ae(j).pipeTo(h.current.writable).catch(V=>{console.error("[ScrcpyPlayer] Video stream error:",V)}),y("connected"),S.current?.({close:()=>R.close()})}catch(M){console.error("[ScrcpyPlayer] Decoder initialization failed:",M),y("error"),w("Decoder initialization failed"),C.current=!0,R.close(),g.current?.()}}),R.on("error",j=>{console.error("[ScrcpyPlayer] Socket error:",j),y("error"),w(j?.message||"Socket error")}),R.on("disconnect",()=>{if(C.current){C.current=!1;return}y("disconnected"),S.current?.(null),p.current||(p.current=setTimeout(()=>{p.current=null,v.current?.()},3e3))})},[t,ce,Z,ae]);l.useEffect(()=>{v.current=le},[le]),l.useEffect(()=>(queueMicrotask(()=>{le()}),()=>{z.current&&(clearTimeout(z.current),z.current=null),$.current&&(clearTimeout($.current),$.current=null),ce(!0)}),[le,ce]);const J=()=>{if(D)return{width:D.width,height:D.height};const R=m.current;return R?{width:R.width,height:R.height}:null},pe=(R,j)=>{const M=m.current,H=J();if(!M||!H)return null;const V=M.getBoundingClientRect();if(R<V.left||R>V.right||j<V.top||j>V.bottom)return null;const F=R-V.left,X=j-V.top,B=Math.round(F/V.width*H.width),ue=Math.round(X/V.height*H.height),Re=W?W.width/H.width:1,ye=W?W.height/H.height:1;return{x:Math.round(B*Re),y:Math.round(ue*ye)}},Oe=async R=>{if(!i||k!=="connected")return;const j=pe(R.clientX,R.clientY);if(j){N.current=!0,L.current=!1,P.current={x:R.clientX,y:R.clientY};try{await es(j.x,j.y,t)}catch(M){console.error("[ScrcpyPlayer] Touch down failed:",M)}}},Ne=R=>{if(!N.current||k!=="connected")return;const j=Date.now(),M=pe(R.clientX,R.clientY);if(M){if(P.current){const H=R.clientX-P.current.x,V=R.clientY-P.current.y;Math.hypot(H,V)>4&&(L.current=!0)}if(G.current=M,j-I.current<Sn){z.current||(z.current=setTimeout(()=>{z.current=null,G.current&&(nn(G.current.x,G.current.y,t).catch(H=>{console.error("[ScrcpyPlayer] Touch move failed:",H)}),G.current=null,I.current=Date.now())},Sn));return}I.current=j,nn(M.x,M.y,t).catch(H=>{console.error("[ScrcpyPlayer] Touch move failed:",H)})}},be=async R=>{if(!N.current||k!=="connected")return;const j=pe(R.clientX,R.clientY);if(N.current=!1,P.current=null,!!j)try{await tn(j.x,j.y,t),L.current?o?.():s?.()}catch(M){const H=String(M);L.current?u?.(H):c?.(H)}},O=async R=>{if(!N.current||k!=="connected")return;const j=pe(R.clientX,R.clientY);if(N.current=!1,P.current=null,!!j)try{await tn(j.x,j.y,t)}catch(M){console.error("[ScrcpyPlayer] Touch cancel failed:",M)}},ne=R=>{if(!i||k!=="connected")return;R.preventDefault();const j=R.deltaY;q.current||(q.current={deltaY:0}),q.current.deltaY+=j,$.current&&clearTimeout($.current),$.current=setTimeout(async()=>{const M=q.current;if(q.current=null,!M)return;const H=m.current,V=J();if(!H||!V)return;const F=H.getBoundingClientRect(),X=F.left+F.width/2,B=F.top+F.height/2,ue=pe(X,B);if(!ue)return;const Re=Math.max(Math.min(M.deltaY,600),-600),ye=B+Re,me=pe(X,ye);if(me)try{const we=await Zr(ue.x,ue.y,me.x,me.y,300,t);we.success?o?.():u?.(we.error||"Scroll failed")}catch(we){u?.(String(we))}},ko)};return a.jsx("div",{className:`relative w-full h-full flex items-center justify-center ${e||""}`,children:a.jsx("div",{ref:_,className:"relative w-full h-full flex items-center justify-center bg-slate-50 dark:bg-slate-900",onMouseDown:Oe,onMouseMove:Ne,onMouseUp:be,onMouseLeave:O,onWheel:ne,children:k!=="connected"&&a.jsxs("div",{className:"absolute inset-0 flex items-center justify-center text-slate-400",children:[k==="connecting"&&"Connecting...",k==="error"&&(A||"Connection error"),k==="disconnected"&&"Disconnected"]})})})}const lr=l.forwardRef(({className:t,...e},n)=>a.jsx("textarea",{className:oe("flex min-h-[40px] w-full rounded-full border border-slate-200 bg-white px-3 py-2 text-sm ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1d9bf0] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-100 dark:ring-offset-slate-950 dark:placeholder:text-slate-400 dark:focus-visible:ring-[#1d9bf0] resize-none",t),ref:n,...e}));lr.displayName="Textarea";const Wt=l.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:oe("rounded-2xl border border-slate-200 bg-white text-slate-950 shadow-sm dark:border-slate-800 dark:bg-slate-950 dark:text-slate-50",t),...e}));Wt.displayName="Card";const Ro=l.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:oe("flex flex-col space-y-1.5 p-6",t),...e}));Ro.displayName="CardHeader";const Po=l.forwardRef(({className:t,...e},n)=>a.jsx("h3",{ref:n,className:oe("text-xl font-semibold leading-none tracking-tight",t),...e}));Po.displayName="CardTitle";const Ao=l.forwardRef(({className:t,...e},n)=>a.jsx("p",{ref:n,className:oe("text-sm text-slate-500 dark:text-slate-400",t),...e}));Ao.displayName="CardDescription";const Do=l.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:oe("p-6 pt-0",t),...e}));Do.displayName="CardContent";const Lo=l.forwardRef(({className:t,...e},n)=>a.jsx("div",{ref:n,className:oe("flex items-center p-6 pt-0",t),...e}));Lo.displayName="CardFooter";function jo({deviceId:t,deviceName:e,config:n,isConfigured:r}){const i=lt(),[s,c]=l.useState([]),[o,u]=l.useState(""),[d,f]=l.useState(!1),[h,_]=l.useState(null),[m,x]=l.useState(!1),[p,v]=l.useState(null),[E,C]=l.useState(!0),[g,b]=l.useState(!1),[S,k]=l.useState("auto"),[y,A]=l.useState(null),[w,D]=l.useState("success"),T=l.useRef(null),W=(O,ne=2e3,R="success")=>{T.current&&clearTimeout(T.current),D(R),A(O),T.current=setTimeout(()=>{A(null)},ne)};l.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const[Y,N]=l.useState(!1),[P,L]=l.useState(!1),I=l.useRef(null),G=()=>{I.current&&clearTimeout(I.current),N(!0)},z=()=>{I.current=setTimeout(()=>{N(!1)},500)};l.useEffect(()=>()=>{I.current&&clearTimeout(I.current)},[]);const $=()=>{L(O=>!O)},q=l.useRef(null),K=l.useRef(null),Q=l.useRef(null),Z=l.useRef(!1),re=l.useRef(!1),ae=l.useCallback(async()=>{if(n)try{await ts({model_config:{base_url:n.base_url||void 0,api_key:n.api_key||void 0,model_name:n.model_name||void 0},agent_config:{device_id:t}}),x(!0),_(null)}catch(O){const ne=O instanceof Error?O.message:"Initialization failed";_(ne)}},[t,n]);l.useEffect(()=>{r&&n&&!m&&!re.current&&(re.current=!0,ae())},[r,n,m,ae]);const ce=l.useCallback(async()=>{const O=o.trim();if(!O||d)return;m||await ae();const ne={id:Date.now().toString(),role:"user",content:O,timestamp:new Date};c(F=>[...F,ne]),u(""),f(!0),_(null);const R=[],j=[],M=(Date.now()+1).toString(),H={id:M,role:"agent",content:"",timestamp:new Date,thinking:[],actions:[],isStreaming:!0};c(F=>[...F,H]);const V=ns(ne.content,t,F=>{R.push(F.thinking),j.push(F.action),c(X=>X.map(B=>B.id===M?{...B,thinking:[...R],actions:[...j],steps:F.step}:B))},F=>{c(X=>X.map(B=>B.id===M?{...B,content:F.message,success:F.success,isStreaming:!1}:B)),f(!1),q.current=null},F=>{c(X=>X.map(B=>B.id===M?{...B,content:`Error: ${F.message}`,success:!1,isStreaming:!1}:B)),f(!1),_(F.message),q.current=null});q.current=V},[o,d,m,t,ae]),le=l.useCallback(async()=>{q.current&&q.current.close(),c([]),f(!1),_(null),q.current=null,await rs(t)},[t]),J=()=>{Q.current?.scrollIntoView({behavior:"smooth"})};l.useEffect(()=>{J()},[s]),l.useEffect(()=>()=>{q.current&&q.current.close(),K.current&&K.current.close()},[t]),l.useEffect(()=>{if(!t||!(S==="screenshot"||S==="auto"&&g))return;const ne=async()=>{if(!Z.current){Z.current=!0;try{const j=await In(t);j.success&&v(j)}catch(j){console.error("Failed to fetch screenshot:",j)}finally{Z.current=!1}}};ne();const R=setInterval(ne,500);return()=>clearInterval(R)},[t,g,S]);const pe=O=>{(O.metaKey||O.ctrlKey)&&O.key==="Enter"&&(O.preventDefault(),ce())},Oe=l.useCallback(O=>{K.current=O},[]),Ne=l.useCallback(()=>{b(!0),C(!1)},[]),be=O=>{k(O)};return a.jsxs("div",{className:"flex-1 flex gap-4 p-4 items-stretch justify-center min-h-0",children:[a.jsxs(Wt,{className:"flex-1 flex flex-col min-h-0 max-w-2xl",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-slate-200 dark:border-slate-800",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:a.jsx(_t,{className:"h-5 w-5 text-[#1d9bf0]"})}),a.jsxs("div",{children:[a.jsx("h2",{className:"font-bold text-slate-900 dark:text-slate-100",children:e}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 font-mono",children:t})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[r?m?a.jsxs(Ze,{variant:"success",children:[a.jsx(Ge,{className:"w-3 h-3 mr-1"}),i.devicePanel.ready]}):a.jsx(ie,{onClick:ae,disabled:!r||!n,size:"sm",variant:"twitter",children:i.devicePanel.initializing}):a.jsxs(Ze,{variant:"warning",children:[a.jsx(Ie,{className:"w-3 h-3 mr-1"}),i.devicePanel.noConfig]}),a.jsx(ie,{variant:"ghost",size:"icon",onClick:le,className:"h-8 w-8 rounded-full text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300",title:"Reset chat",children:a.jsx(Ds,{className:"h-4 w-4"})})]})]}),h&&a.jsxs("div",{className:"mx-4 mt-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl text-sm text-red-600 dark:text-red-400 flex items-center gap-2",children:[a.jsx(Ie,{className:"w-4 h-4 flex-shrink-0"}),h]}),a.jsxs("div",{className:"flex-1 overflow-y-auto p-4 min-h-0",children:[s.length===0?a.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center min-h-[calc(100%-1rem)]",children:[a.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800 mb-4",children:a.jsx(_t,{className:"h-8 w-8 text-slate-400"})}),a.jsx("p",{className:"font-medium text-slate-900 dark:text-slate-100",children:i.devicePanel.readyToHelp}),a.jsx("p",{className:"mt-1 text-sm text-slate-500 dark:text-slate-400",children:i.devicePanel.describeTask})]}):s.map(O=>a.jsx("div",{className:`flex ${O.role==="user"?"justify-end":"justify-start"}`,children:O.role==="agent"?a.jsxs("div",{className:"max-w-[85%] space-y-3",children:[O.thinking?.map((ne,R)=>a.jsxs("div",{className:"bg-slate-100 dark:bg-slate-800 rounded-2xl rounded-tl-sm px-4 py-3",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[a.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full bg-[#1d9bf0]/10",children:a.jsx(_t,{className:"h-3 w-3 text-[#1d9bf0]"})}),a.jsxs("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:["Step ",R+1]})]}),a.jsx("p",{className:"text-sm whitespace-pre-wrap text-slate-700 dark:text-slate-300",children:ne}),O.actions?.[R]&&a.jsxs("details",{className:"mt-2 text-xs",children:[a.jsx("summary",{className:"cursor-pointer text-[#1d9bf0] hover:text-[#1a8cd8]",children:"View action"}),a.jsx("pre",{className:"mt-2 p-2 bg-slate-900 text-slate-200 rounded-lg overflow-x-auto text-xs",children:JSON.stringify(O.actions[R],null,2)})]})]},R)),O.content&&a.jsxs("div",{className:`
103
+ rounded-2xl px-4 py-3 flex items-start gap-2
104
+ ${O.success===!1?"bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-400":"bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300"}
105
+ `,children:[a.jsx(Ge,{className:`w-5 h-5 flex-shrink-0 mt-0.5 ${O.success===!1?"text-red-500":"text-green-500"}`}),a.jsxs("div",{children:[a.jsx("p",{className:"whitespace-pre-wrap",children:O.content}),O.steps!==void 0&&a.jsxs("p",{className:"text-xs mt-2 opacity-60 text-slate-500 dark:text-slate-400",children:[O.steps," steps completed"]})]})]}),O.isStreaming&&a.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500 dark:text-slate-400",children:[a.jsx(We,{className:"w-4 h-4 animate-spin"}),"Processing..."]})]}):a.jsxs("div",{className:"max-w-[75%]",children:[a.jsx("div",{className:"chat-bubble-user px-4 py-3",children:a.jsx("p",{className:"whitespace-pre-wrap text-white dark:text-white",children:O.content})}),a.jsx("p",{className:"text-xs text-slate-400 dark:text-slate-500 mt-1 text-right",children:O.timestamp.toLocaleTimeString()})]})},O.id)),a.jsx("div",{ref:Q})]}),a.jsx("div",{className:"p-4 border-t border-slate-200 dark:border-slate-800",children:a.jsxs("div",{className:"flex items-end gap-3",children:[a.jsx(lr,{value:o,onChange:O=>u(O.target.value),onKeyDown:pe,placeholder:r?m?i.devicePanel.whatToDo:i.devicePanel.initDeviceFirst:i.devicePanel.configureFirst,disabled:d,className:"flex-1 min-h-[40px] max-h-[120px] resize-none",rows:1}),a.jsx(ie,{onClick:ce,disabled:d||!o.trim(),size:"icon",variant:"twitter",className:"h-10 w-10 rounded-full flex-shrink-0",children:d?a.jsx(We,{className:"h-4 w-4 animate-spin"}):a.jsx(js,{className:"h-4 w-4"})})]})})]}),a.jsxs(Wt,{className:"w-[320px] flex-shrink-0 relative min-h-0 overflow-hidden bg-background",onMouseEnter:G,onMouseLeave:z,children:[a.jsx("div",{className:`absolute top-4 right-4 z-10 transition-opacity duration-200 ${Y?"opacity-100":"opacity-0 pointer-events-none"}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:`flex items-center gap-1 bg-popover/90 backdrop-blur rounded-xl p-1 shadow-lg border border-border transition-all duration-300 ${P?"opacity-100 translate-x-0":"opacity-0 translate-x-4 pointer-events-none"}`,children:[a.jsx(ie,{variant:"ghost",size:"sm",onClick:()=>be("auto"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${S==="auto"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:i.devicePanel.auto}),a.jsxs(ie,{variant:"ghost",size:"sm",onClick:()=>be("video"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${S==="video"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[a.jsx(Gs,{className:"w-3 h-3 mr-1"}),i.devicePanel.video]}),a.jsxs(ie,{variant:"ghost",size:"sm",onClick:()=>be("screenshot"),className:`h-7 px-3 text-xs rounded-lg transition-colors ${S==="screenshot"?"bg-primary text-primary-foreground":"text-foreground hover:bg-accent hover:text-accent-foreground"}`,children:[a.jsx(rn,{className:"w-3 h-3 mr-1"}),i.devicePanel.image]})]}),a.jsx(ie,{variant:"ghost",size:"icon",onClick:$,className:"h-8 w-8 rounded-full bg-popover/90 backdrop-blur border border-border shadow-lg hover:bg-accent",title:P?"Hide controls":"Show controls",children:P?a.jsx(Gn,{className:"w-4 h-4"}):a.jsx(Un,{className:"w-4 h-4"})})]})}),a.jsx("div",{className:"absolute bottom-4 left-4 z-10",children:a.jsxs(Ze,{variant:"secondary",className:"bg-white/90 text-slate-700 border border-slate-200 dark:bg-slate-900/90 dark:text-slate-300 dark:border-slate-700",children:[S==="auto"&&i.devicePanel.auto,S==="video"&&a.jsxs(a.Fragment,{children:[a.jsx(Ns,{className:"w-3 h-3 mr-1"}),i.devicePanel.video]}),S==="screenshot"&&a.jsxs(a.Fragment,{children:[a.jsx(rn,{className:"w-3 h-3 mr-1"}),i.devicePanel.imageRefresh]})]})}),y&&a.jsxs("div",{className:"absolute bottom-4 right-4 z-20 flex items-center gap-2 px-3 py-2 bg-[#1d9bf0] text-white text-sm rounded-xl shadow-lg",children:[w==="error"&&a.jsx(Ie,{className:"w-4 h-4"}),w==="tap"&&a.jsx(Ts,{className:"w-4 h-4"}),w==="swipe"&&a.jsx(ps,{className:"w-4 h-4"}),w==="success"&&a.jsx(Ge,{className:"w-4 h-4"}),a.jsx("span",{children:y})]}),S==="video"||S==="auto"&&E&&!g?a.jsx(No,{deviceId:t,className:"w-full h-full",enableControl:!0,onFallback:Ne,onTapSuccess:()=>W(i.devicePanel.tapped,2e3,"tap"),onTapError:O=>W(i.devicePanel.tapError.replace("{error}",O),3e3,"error"),onSwipeSuccess:()=>W(i.devicePanel.swiped,2e3,"swipe"),onSwipeError:O=>W(i.devicePanel.swipeError.replace("{error}",O),3e3,"error"),onStreamReady:Oe,fallbackTimeout:1e5}):a.jsx("div",{className:"w-full h-full flex items-center justify-center bg-muted/30 min-h-0",children:p&&p.success?a.jsxs("div",{className:"relative w-full h-full flex items-center justify-center min-h-0",children:[a.jsx("img",{src:`data:image/png;base64,${p.image}`,alt:"Device Screenshot",className:"max-w-full max-h-full object-contain",style:{width:p.width>p.height?"100%":"auto",height:p.width>p.height?"auto":"100%"}}),p.is_sensitive&&a.jsx("div",{className:"absolute top-12 right-2 px-2 py-1 bg-yellow-500 text-white text-xs rounded-lg",children:i.devicePanel.sensitiveContent})]}):p?.error?a.jsxs("div",{className:"text-center text-destructive",children:[a.jsx(Ie,{className:"w-8 h-8 mx-auto mb-2"}),a.jsx("p",{className:"font-medium",children:i.devicePanel.screenshotFailed}),a.jsx("p",{className:"text-xs mt-1 opacity-60",children:p.error})]}):a.jsxs("div",{className:"text-center text-muted-foreground",children:[a.jsx(We,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),a.jsx("p",{className:"text-sm",children:i.devicePanel.loading})]})})]})]})}function Oo({message:t,type:e="info",onClose:n,duration:r=3e3}){l.useEffect(()=>{const c=setTimeout(()=>{n()},r);return()=>clearTimeout(c)},[r,n]);const i={success:"bg-green-500",error:"bg-red-500",info:"bg-blue-500"},s={success:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M5 13l4 4L19 7"})}),error:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})}),info:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})};return a.jsx("div",{className:"fixed top-4 left-1/2 transform -translate-x-1/2 z-50 animate-fade-in-down",children:a.jsxs("div",{className:`${i[e]} text-white px-4 py-3 rounded-lg shadow-lg flex items-center gap-3 min-w-[300px]`,children:[s[e],a.jsx("span",{className:"font-medium",children:t}),a.jsx("button",{onClick:n,className:"ml-auto hover:bg-white/20 rounded-full p-1 transition-colors",children:a.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})})}const it=l.forwardRef(({className:t,type:e,...n},r)=>a.jsx("input",{type:e,className:oe("flex h-10 w-full rounded-full border border-slate-200 bg-white px-3 py-2 text-sm ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1d9bf0] focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-100 dark:ring-offset-slate-950 dark:placeholder:text-slate-400 dark:focus-visible:ring-[#1d9bf0]",t),ref:r,...n}));it.displayName="Input";function Se(t,e,{checkForDefaultPrevented:n=!0}={}){return function(i){if(t?.(i),n===!1||!i.defaultPrevented)return e?.(i)}}function Bo(t,e){const n=l.createContext(e),r=s=>{const{children:c,...o}=s,u=l.useMemo(()=>o,Object.values(o));return a.jsx(n.Provider,{value:u,children:c})};r.displayName=t+"Provider";function i(s){const c=l.useContext(n);if(c)return c;if(e!==void 0)return e;throw new Error(`\`${s}\` must be used within \`${t}\``)}return[r,i]}function Mo(t,e=[]){let n=[];function r(s,c){const o=l.createContext(c),u=n.length;n=[...n,c];const d=h=>{const{scope:_,children:m,...x}=h,p=_?.[t]?.[u]||o,v=l.useMemo(()=>x,Object.values(x));return a.jsx(p.Provider,{value:v,children:m})};d.displayName=s+"Provider";function f(h,_){const m=_?.[t]?.[u]||o,x=l.useContext(m);if(x)return x;if(c!==void 0)return c;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[d,f]}const i=()=>{const s=n.map(c=>l.createContext(c));return function(o){const u=o?.[t]||s;return l.useMemo(()=>({[`__scope${t}`]:{...o,[t]:u}}),[o,u])}};return i.scopeName=t,[r,Io(i,...e)]}function Io(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(s){const c=r.reduce((o,{useScope:u,scopeName:d})=>{const h=u(s)[`__scope${d}`];return{...o,...h}},{});return l.useMemo(()=>({[`__scope${e.scopeName}`]:c}),[c])}};return n.scopeName=e.scopeName,n}var He=globalThis?.document?l.useLayoutEffect:()=>{},Fo=Fn[" useId ".trim().toString()]||(()=>{}),Uo=0;function Nt(t){const[e,n]=l.useState(Fo());return He(()=>{n(r=>r??String(Uo++))},[t]),t||(e?`radix-${e}`:"")}var Go=Fn[" useInsertionEffect ".trim().toString()]||He;function Wo({prop:t,defaultProp:e,onChange:n=()=>{},caller:r}){const[i,s,c]=qo({defaultProp:e,onChange:n}),o=t!==void 0,u=o?t:i;{const f=l.useRef(t!==void 0);l.useEffect(()=>{const h=f.current;h!==o&&console.warn(`${r} is changing from ${h?"controlled":"uncontrolled"} to ${o?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),f.current=o},[o,r])}const d=l.useCallback(f=>{if(o){const h=Ho(f)?f(t):f;h!==t&&c.current?.(h)}else s(f)},[o,t,s,c]);return[u,d]}function qo({defaultProp:t,onChange:e}){const[n,r]=l.useState(t),i=l.useRef(n),s=l.useRef(e);return Go(()=>{s.current=e},[e]),l.useEffect(()=>{i.current!==n&&(s.current?.(n),i.current=n)},[n,i]),[n,r,s]}function Ho(t){return typeof t=="function"}function ur(t){const e=Xo(t),n=l.forwardRef((r,i)=>{const{children:s,...c}=r,o=l.Children.toArray(s),u=o.find($o);if(u){const d=u.props.children,f=o.map(h=>h===u?l.Children.count(d)>1?l.Children.only(null):l.isValidElement(d)?d.props.children:null:h);return a.jsx(e,{...c,ref:i,children:l.isValidElement(d)?l.cloneElement(d,void 0,f):null})}return a.jsx(e,{...c,ref:i,children:s})});return n.displayName=`${t}.Slot`,n}function Xo(t){const e=l.forwardRef((n,r)=>{const{children:i,...s}=n;if(l.isValidElement(i)){const c=Yo(i),o=Vo(s,i.props);return i.type!==l.Fragment&&(o.ref=r?ss(r,c):c),l.cloneElement(i,o)}return l.Children.count(i)>1?l.Children.only(null):null});return e.displayName=`${t}.SlotClone`,e}var zo=Symbol("radix.slottable");function $o(t){return l.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===zo}function Vo(t,e){const n={...e};for(const r in e){const i=t[r],s=e[r];/^on[A-Z]/.test(r)?i&&s?n[r]=(...o)=>{const u=s(...o);return i(...o),u}:i&&(n[r]=i):r==="style"?n[r]={...i,...s}:r==="className"&&(n[r]=[i,s].filter(Boolean).join(" "))}return{...t,...n}}function Yo(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var Ko=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],ve=Ko.reduce((t,e)=>{const n=ur(`Primitive.${e}`),r=l.forwardRef((i,s)=>{const{asChild:c,...o}=i,u=c?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(u,{...o,ref:s})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function Jo(t,e){t&&is.flushSync(()=>t.dispatchEvent(e))}function Xe(t){const e=l.useRef(t);return l.useEffect(()=>{e.current=t}),l.useMemo(()=>(...n)=>e.current?.(...n),[])}function Qo(t,e=globalThis?.document){const n=Xe(t);l.useEffect(()=>{const r=i=>{i.key==="Escape"&&n(i)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var Zo="DismissableLayer",qt="dismissableLayer.update",ea="dismissableLayer.pointerDownOutside",ta="dismissableLayer.focusOutside",Cn,dr=l.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),fr=l.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:s,onInteractOutside:c,onDismiss:o,...u}=t,d=l.useContext(dr),[f,h]=l.useState(null),_=f?.ownerDocument??globalThis?.document,[,m]=l.useState({}),x=ke(e,y=>h(y)),p=Array.from(d.layers),[v]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),E=p.indexOf(v),C=f?p.indexOf(f):-1,g=d.layersWithOutsidePointerEventsDisabled.size>0,b=C>=E,S=sa(y=>{const A=y.target,w=[...d.branches].some(D=>D.contains(A));!b||w||(i?.(y),c?.(y),y.defaultPrevented||o?.())},_),k=ia(y=>{const A=y.target;[...d.branches].some(D=>D.contains(A))||(s?.(y),c?.(y),y.defaultPrevented||o?.())},_);return Qo(y=>{C===d.layers.size-1&&(r?.(y),!y.defaultPrevented&&o&&(y.preventDefault(),o()))},_),l.useEffect(()=>{if(f)return n&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(Cn=_.body.style.pointerEvents,_.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(f)),d.layers.add(f),kn(),()=>{n&&d.layersWithOutsidePointerEventsDisabled.size===1&&(_.body.style.pointerEvents=Cn)}},[f,_,n,d]),l.useEffect(()=>()=>{f&&(d.layers.delete(f),d.layersWithOutsidePointerEventsDisabled.delete(f),kn())},[f,d]),l.useEffect(()=>{const y=()=>m({});return document.addEventListener(qt,y),()=>document.removeEventListener(qt,y)},[]),a.jsx(ve.div,{...u,ref:x,style:{pointerEvents:g?b?"auto":"none":void 0,...t.style},onFocusCapture:Se(t.onFocusCapture,k.onFocusCapture),onBlurCapture:Se(t.onBlurCapture,k.onBlurCapture),onPointerDownCapture:Se(t.onPointerDownCapture,S.onPointerDownCapture)})});fr.displayName=Zo;var na="DismissableLayerBranch",ra=l.forwardRef((t,e)=>{const n=l.useContext(dr),r=l.useRef(null),i=ke(e,r);return l.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),a.jsx(ve.div,{...t,ref:i})});ra.displayName=na;function sa(t,e=globalThis?.document){const n=Xe(t),r=l.useRef(!1),i=l.useRef(()=>{});return l.useEffect(()=>{const s=o=>{if(o.target&&!r.current){let u=function(){hr(ea,n,d,{discrete:!0})};const d={originalEvent:o};o.pointerType==="touch"?(e.removeEventListener("click",i.current),i.current=u,e.addEventListener("click",i.current,{once:!0})):u()}else e.removeEventListener("click",i.current);r.current=!1},c=window.setTimeout(()=>{e.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(c),e.removeEventListener("pointerdown",s),e.removeEventListener("click",i.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function ia(t,e=globalThis?.document){const n=Xe(t),r=l.useRef(!1);return l.useEffect(()=>{const i=s=>{s.target&&!r.current&&hr(ta,n,{originalEvent:s},{discrete:!1})};return e.addEventListener("focusin",i),()=>e.removeEventListener("focusin",i)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function kn(){const t=new CustomEvent(qt);document.dispatchEvent(t)}function hr(t,e,n,{discrete:r}){const i=n.originalEvent.target,s=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&i.addEventListener(t,e,{once:!0}),r?Jo(i,s):i.dispatchEvent(s)}var Rt="focusScope.autoFocusOnMount",Pt="focusScope.autoFocusOnUnmount",Nn={bubbles:!1,cancelable:!0},oa="FocusScope",pr=l.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:s,...c}=t,[o,u]=l.useState(null),d=Xe(i),f=Xe(s),h=l.useRef(null),_=ke(e,p=>u(p)),m=l.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;l.useEffect(()=>{if(r){let p=function(g){if(m.paused||!o)return;const b=g.target;o.contains(b)?h.current=b:Ee(h.current,{select:!0})},v=function(g){if(m.paused||!o)return;const b=g.relatedTarget;b!==null&&(o.contains(b)||Ee(h.current,{select:!0}))},E=function(g){if(document.activeElement===document.body)for(const S of g)S.removedNodes.length>0&&Ee(o)};document.addEventListener("focusin",p),document.addEventListener("focusout",v);const C=new MutationObserver(E);return o&&C.observe(o,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",v),C.disconnect()}}},[r,o,m.paused]),l.useEffect(()=>{if(o){Pn.add(m);const p=document.activeElement;if(!o.contains(p)){const E=new CustomEvent(Rt,Nn);o.addEventListener(Rt,d),o.dispatchEvent(E),E.defaultPrevented||(aa(fa(mr(o)),{select:!0}),document.activeElement===p&&Ee(o))}return()=>{o.removeEventListener(Rt,d),setTimeout(()=>{const E=new CustomEvent(Pt,Nn);o.addEventListener(Pt,f),o.dispatchEvent(E),E.defaultPrevented||Ee(p??document.body,{select:!0}),o.removeEventListener(Pt,f),Pn.remove(m)},0)}}},[o,d,f,m]);const x=l.useCallback(p=>{if(!n&&!r||m.paused)return;const v=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,E=document.activeElement;if(v&&E){const C=p.currentTarget,[g,b]=ca(C);g&&b?!p.shiftKey&&E===b?(p.preventDefault(),n&&Ee(g,{select:!0})):p.shiftKey&&E===g&&(p.preventDefault(),n&&Ee(b,{select:!0})):E===C&&p.preventDefault()}},[n,r,m.paused]);return a.jsx(ve.div,{tabIndex:-1,...c,ref:_,onKeyDown:x})});pr.displayName=oa;function aa(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Ee(r,{select:e}),document.activeElement!==n)return}function ca(t){const e=mr(t),n=Rn(e,t),r=Rn(e.reverse(),t);return[n,r]}function mr(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function Rn(t,e){for(const n of t)if(!la(n,{upTo:e}))return n}function la(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function ua(t){return t instanceof HTMLInputElement&&"select"in t}function Ee(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&ua(t)&&e&&t.select()}}var Pn=da();function da(){let t=[];return{add(e){const n=t[0];e!==n&&n?.pause(),t=An(t,e),t.unshift(e)},remove(e){t=An(t,e),t[0]?.resume()}}}function An(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function fa(t){return t.filter(e=>e.tagName!=="A")}var ha="Portal",_r=l.forwardRef((t,e)=>{const{container:n,...r}=t,[i,s]=l.useState(!1);He(()=>s(!0),[]);const c=n||i&&globalThis?.document?.body;return c?os.createPortal(a.jsx(ve.div,{...r,ref:e}),c):null});_r.displayName=ha;function pa(t,e){return l.useReducer((n,r)=>e[n][r]??n,t)}var ht=t=>{const{present:e,children:n}=t,r=ma(e),i=typeof n=="function"?n({present:r.isPresent}):l.Children.only(n),s=ke(r.ref,_a(i));return typeof n=="function"||r.isPresent?l.cloneElement(i,{ref:s}):null};ht.displayName="Presence";function ma(t){const[e,n]=l.useState(),r=l.useRef(null),i=l.useRef(t),s=l.useRef("none"),c=t?"mounted":"unmounted",[o,u]=pa(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{const d=Ve(r.current);s.current=o==="mounted"?d:"none"},[o]),He(()=>{const d=r.current,f=i.current;if(f!==t){const _=s.current,m=Ve(d);t?u("MOUNT"):m==="none"||d?.display==="none"?u("UNMOUNT"):u(f&&_!==m?"ANIMATION_OUT":"UNMOUNT"),i.current=t}},[t,u]),He(()=>{if(e){let d;const f=e.ownerDocument.defaultView??window,h=m=>{const p=Ve(r.current).includes(CSS.escape(m.animationName));if(m.target===e&&p&&(u("ANIMATION_END"),!i.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",d=f.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},_=m=>{m.target===e&&(s.current=Ve(r.current))};return e.addEventListener("animationstart",_),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{f.clearTimeout(d),e.removeEventListener("animationstart",_),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else u("ANIMATION_END")},[e,u]),{isPresent:["mounted","unmountSuspended"].includes(o),ref:l.useCallback(d=>{r.current=d?getComputedStyle(d):null,n(d)},[])}}function Ve(t){return t?.animationName||"none"}function _a(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var At=0;function ga(){l.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??Dn()),document.body.insertAdjacentElement("beforeend",t[1]??Dn()),At++,()=>{At===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),At--}},[])}function Dn(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var _e=function(){return _e=Object.assign||function(e){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},_e.apply(this,arguments)};function gr(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}function xa(t,e,n){if(n||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))}var ot="right-scroll-bar-position",at="width-before-scroll-bar",va="with-scroll-bars-hidden",ba="--removed-body-scroll-bar-size";function Dt(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function ya(t,e){var n=l.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var i=n.value;i!==r&&(n.value=r,n.callback(r,i))}}}})[0];return n.callback=e,n.facade}var wa=typeof window<"u"?l.useLayoutEffect:l.useEffect,Ln=new WeakMap;function Ea(t,e){var n=ya(null,function(r){return t.forEach(function(i){return Dt(i,r)})});return wa(function(){var r=Ln.get(n);if(r){var i=new Set(r),s=new Set(t),c=n.current;i.forEach(function(o){s.has(o)||Dt(o,null)}),s.forEach(function(o){i.has(o)||Dt(o,c)})}Ln.set(n,t)},[t]),n}function Ta(t){return t}function Sa(t,e){e===void 0&&(e=Ta);var n=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:t},useMedium:function(s){var c=e(s,r);return n.push(c),function(){n=n.filter(function(o){return o!==c})}},assignSyncMedium:function(s){for(r=!0;n.length;){var c=n;n=[],c.forEach(s)}n={push:function(o){return s(o)},filter:function(){return n}}},assignMedium:function(s){r=!0;var c=[];if(n.length){var o=n;n=[],o.forEach(s),c=n}var u=function(){var f=c;c=[],f.forEach(s)},d=function(){return Promise.resolve().then(u)};d(),n={push:function(f){c.push(f),d()},filter:function(f){return c=c.filter(f),n}}}};return i}function Ca(t){t===void 0&&(t={});var e=Sa(null);return e.options=_e({async:!0,ssr:!1},t),e}var xr=function(t){var e=t.sideCar,n=gr(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return l.createElement(r,_e({},n))};xr.isSideCarExport=!0;function ka(t,e){return t.useMedium(e),xr}var vr=Ca(),Lt=function(){},pt=l.forwardRef(function(t,e){var n=l.useRef(null),r=l.useState({onScrollCapture:Lt,onWheelCapture:Lt,onTouchMoveCapture:Lt}),i=r[0],s=r[1],c=t.forwardProps,o=t.children,u=t.className,d=t.removeScrollBar,f=t.enabled,h=t.shards,_=t.sideCar,m=t.noRelative,x=t.noIsolation,p=t.inert,v=t.allowPinchZoom,E=t.as,C=E===void 0?"div":E,g=t.gapMode,b=gr(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=_,k=Ea([n,e]),y=_e(_e({},b),i);return l.createElement(l.Fragment,null,f&&l.createElement(S,{sideCar:vr,removeScrollBar:d,shards:h,noRelative:m,noIsolation:x,inert:p,setCallbacks:s,allowPinchZoom:!!v,lockRef:n,gapMode:g}),c?l.cloneElement(l.Children.only(o),_e(_e({},y),{ref:k})):l.createElement(C,_e({},y,{className:u,ref:k}),o))});pt.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};pt.classNames={fullWidth:at,zeroRight:ot};var Na=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ra(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=Na();return e&&t.setAttribute("nonce",e),t}function Pa(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Aa(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var Da=function(){var t=0,e=null;return{add:function(n){t==0&&(e=Ra())&&(Pa(e,n),Aa(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},La=function(){var t=Da();return function(e,n){l.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},br=function(){var t=La(),e=function(n){var r=n.styles,i=n.dynamic;return t(r,i),null};return e},ja={left:0,top:0,right:0,gap:0},jt=function(t){return parseInt(t||"",10)||0},Oa=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],i=e[t==="padding"?"paddingRight":"marginRight"];return[jt(n),jt(r),jt(i)]},Ba=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return ja;var e=Oa(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},Ma=br(),Le="data-scroll-locked",Ia=function(t,e,n,r){var i=t.left,s=t.top,c=t.right,o=t.gap;return n===void 0&&(n="margin"),`
106
+ .`.concat(va,` {
107
+ overflow: hidden `).concat(r,`;
108
+ padding-right: `).concat(o,"px ").concat(r,`;
109
+ }
110
+ body[`).concat(Le,`] {
111
+ overflow: hidden `).concat(r,`;
112
+ overscroll-behavior: contain;
113
+ `).concat([e&&"position: relative ".concat(r,";"),n==="margin"&&`
114
+ padding-left: `.concat(i,`px;
115
+ padding-top: `).concat(s,`px;
116
+ padding-right: `).concat(c,`px;
117
+ margin-left:0;
118
+ margin-top:0;
119
+ margin-right: `).concat(o,"px ").concat(r,`;
120
+ `),n==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
121
+ }
122
+
123
+ .`).concat(ot,` {
124
+ right: `).concat(o,"px ").concat(r,`;
125
+ }
126
+
127
+ .`).concat(at,` {
128
+ margin-right: `).concat(o,"px ").concat(r,`;
129
+ }
130
+
131
+ .`).concat(ot," .").concat(ot,` {
132
+ right: 0 `).concat(r,`;
133
+ }
134
+
135
+ .`).concat(at," .").concat(at,` {
136
+ margin-right: 0 `).concat(r,`;
137
+ }
138
+
139
+ body[`).concat(Le,`] {
140
+ `).concat(ba,": ").concat(o,`px;
141
+ }
142
+ `)},jn=function(){var t=parseInt(document.body.getAttribute(Le)||"0",10);return isFinite(t)?t:0},Fa=function(){l.useEffect(function(){return document.body.setAttribute(Le,(jn()+1).toString()),function(){var t=jn()-1;t<=0?document.body.removeAttribute(Le):document.body.setAttribute(Le,t.toString())}},[])},Ua=function(t){var e=t.noRelative,n=t.noImportant,r=t.gapMode,i=r===void 0?"margin":r;Fa();var s=l.useMemo(function(){return Ba(i)},[i]);return l.createElement(Ma,{styles:Ia(s,!e,i,n?"":"!important")})},Ht=!1;if(typeof window<"u")try{var Ye=Object.defineProperty({},"passive",{get:function(){return Ht=!0,!0}});window.addEventListener("test",Ye,Ye),window.removeEventListener("test",Ye,Ye)}catch{Ht=!1}var Pe=Ht?{passive:!1}:!1,Ga=function(t){return t.tagName==="TEXTAREA"},yr=function(t,e){if(!(t instanceof Element))return!1;var n=window.getComputedStyle(t);return n[e]!=="hidden"&&!(n.overflowY===n.overflowX&&!Ga(t)&&n[e]==="visible")},Wa=function(t){return yr(t,"overflowY")},qa=function(t){return yr(t,"overflowX")},On=function(t,e){var n=e.ownerDocument,r=e;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=wr(t,r);if(i){var s=Er(t,r),c=s[1],o=s[2];if(c>o)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ha=function(t){var e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;return[e,n,r]},Xa=function(t){var e=t.scrollLeft,n=t.scrollWidth,r=t.clientWidth;return[e,n,r]},wr=function(t,e){return t==="v"?Wa(e):qa(e)},Er=function(t,e){return t==="v"?Ha(e):Xa(e)},za=function(t,e){return t==="h"&&e==="rtl"?-1:1},$a=function(t,e,n,r,i){var s=za(t,window.getComputedStyle(e).direction),c=s*r,o=n.target,u=e.contains(o),d=!1,f=c>0,h=0,_=0;do{if(!o)break;var m=Er(t,o),x=m[0],p=m[1],v=m[2],E=p-v-s*x;(x||E)&&wr(t,o)&&(h+=E,_+=x);var C=o.parentNode;o=C&&C.nodeType===Node.DOCUMENT_FRAGMENT_NODE?C.host:C}while(!u&&o!==document.body||u&&(e.contains(o)||e===o));return(f&&Math.abs(h)<1||!f&&Math.abs(_)<1)&&(d=!0),d},Ke=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},Bn=function(t){return[t.deltaX,t.deltaY]},Mn=function(t){return t&&"current"in t?t.current:t},Va=function(t,e){return t[0]===e[0]&&t[1]===e[1]},Ya=function(t){return`
143
+ .block-interactivity-`.concat(t,` {pointer-events: none;}
144
+ .allow-interactivity-`).concat(t,` {pointer-events: all;}
145
+ `)},Ka=0,Ae=[];function Ja(t){var e=l.useRef([]),n=l.useRef([0,0]),r=l.useRef(),i=l.useState(Ka++)[0],s=l.useState(br)[0],c=l.useRef(t);l.useEffect(function(){c.current=t},[t]),l.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(i));var p=xa([t.lockRef.current],(t.shards||[]).map(Mn),!0).filter(Boolean);return p.forEach(function(v){return v.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),p.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(i))})}}},[t.inert,t.lockRef.current,t.shards]);var o=l.useCallback(function(p,v){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!c.current.allowPinchZoom;var E=Ke(p),C=n.current,g="deltaX"in p?p.deltaX:C[0]-E[0],b="deltaY"in p?p.deltaY:C[1]-E[1],S,k=p.target,y=Math.abs(g)>Math.abs(b)?"h":"v";if("touches"in p&&y==="h"&&k.type==="range")return!1;var A=window.getSelection(),w=A&&A.anchorNode,D=w?w===k||w.contains(k):!1;if(D)return!1;var T=On(y,k);if(!T)return!0;if(T?S=y:(S=y==="v"?"h":"v",T=On(y,k)),!T)return!1;if(!r.current&&"changedTouches"in p&&(g||b)&&(r.current=S),!S)return!0;var W=r.current||S;return $a(W,v,p,W==="h"?g:b)},[]),u=l.useCallback(function(p){var v=p;if(!(!Ae.length||Ae[Ae.length-1]!==s)){var E="deltaY"in v?Bn(v):Ke(v),C=e.current.filter(function(S){return S.name===v.type&&(S.target===v.target||v.target===S.shadowParent)&&Va(S.delta,E)})[0];if(C&&C.should){v.cancelable&&v.preventDefault();return}if(!C){var g=(c.current.shards||[]).map(Mn).filter(Boolean).filter(function(S){return S.contains(v.target)}),b=g.length>0?o(v,g[0]):!c.current.noIsolation;b&&v.cancelable&&v.preventDefault()}}},[]),d=l.useCallback(function(p,v,E,C){var g={name:p,delta:v,target:E,should:C,shadowParent:Qa(E)};e.current.push(g),setTimeout(function(){e.current=e.current.filter(function(b){return b!==g})},1)},[]),f=l.useCallback(function(p){n.current=Ke(p),r.current=void 0},[]),h=l.useCallback(function(p){d(p.type,Bn(p),p.target,o(p,t.lockRef.current))},[]),_=l.useCallback(function(p){d(p.type,Ke(p),p.target,o(p,t.lockRef.current))},[]);l.useEffect(function(){return Ae.push(s),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:_}),document.addEventListener("wheel",u,Pe),document.addEventListener("touchmove",u,Pe),document.addEventListener("touchstart",f,Pe),function(){Ae=Ae.filter(function(p){return p!==s}),document.removeEventListener("wheel",u,Pe),document.removeEventListener("touchmove",u,Pe),document.removeEventListener("touchstart",f,Pe)}},[]);var m=t.removeScrollBar,x=t.inert;return l.createElement(l.Fragment,null,x?l.createElement(s,{styles:Ya(i)}):null,m?l.createElement(Ua,{noRelative:t.noRelative,gapMode:t.gapMode}):null)}function Qa(t){for(var e=null;t!==null;)t instanceof ShadowRoot&&(e=t.host,t=t.host),t=t.parentNode;return e}const Za=ka(vr,Ja);var Tr=l.forwardRef(function(t,e){return l.createElement(pt,_e({},t,{ref:e,sideCar:Za}))});Tr.classNames=pt.classNames;var ec=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},De=new WeakMap,Je=new WeakMap,Qe={},Ot=0,Sr=function(t){return t&&(t.host||Sr(t.parentNode))},tc=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=Sr(n);return r&&t.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",t,". Doing nothing"),null)}).filter(function(n){return!!n})},nc=function(t,e,n,r){var i=tc(e,Array.isArray(t)?t:[t]);Qe[n]||(Qe[n]=new WeakMap);var s=Qe[n],c=[],o=new Set,u=new Set(i),d=function(h){!h||o.has(h)||(o.add(h),d(h.parentNode))};i.forEach(d);var f=function(h){!h||u.has(h)||Array.prototype.forEach.call(h.children,function(_){if(o.has(_))f(_);else try{var m=_.getAttribute(r),x=m!==null&&m!=="false",p=(De.get(_)||0)+1,v=(s.get(_)||0)+1;De.set(_,p),s.set(_,v),c.push(_),p===1&&x&&Je.set(_,!0),v===1&&_.setAttribute(n,"true"),x||_.setAttribute(r,"true")}catch(E){console.error("aria-hidden: cannot operate on ",_,E)}})};return f(e),o.clear(),Ot++,function(){c.forEach(function(h){var _=De.get(h)-1,m=s.get(h)-1;De.set(h,_),s.set(h,m),_||(Je.has(h)||h.removeAttribute(r),Je.delete(h)),m||h.removeAttribute(n)}),Ot--,Ot||(De=new WeakMap,De=new WeakMap,Je=new WeakMap,Qe={})}},rc=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),i=ec(t);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),nc(r,i,n,"aria-hidden")):function(){return null}},mt="Dialog",[Cr]=Mo(mt),[sc,he]=Cr(mt),kr=t=>{const{__scopeDialog:e,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:c=!0}=t,o=l.useRef(null),u=l.useRef(null),[d,f]=Wo({prop:r,defaultProp:i??!1,onChange:s,caller:mt});return a.jsx(sc,{scope:e,triggerRef:o,contentRef:u,contentId:Nt(),titleId:Nt(),descriptionId:Nt(),open:d,onOpenChange:f,onOpenToggle:l.useCallback(()=>f(h=>!h),[f]),modal:c,children:n})};kr.displayName=mt;var Nr="DialogTrigger",ic=l.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,i=he(Nr,n),s=ke(e,i.triggerRef);return a.jsx(ve.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Zt(i.open),...r,ref:s,onClick:Se(t.onClick,i.onOpenToggle)})});ic.displayName=Nr;var Jt="DialogPortal",[oc,Rr]=Cr(Jt,{forceMount:void 0}),Pr=t=>{const{__scopeDialog:e,forceMount:n,children:r,container:i}=t,s=he(Jt,e);return a.jsx(oc,{scope:e,forceMount:n,children:l.Children.map(r,c=>a.jsx(ht,{present:n||s.open,children:a.jsx(_r,{asChild:!0,container:i,children:c})}))})};Pr.displayName=Jt;var ct="DialogOverlay",Ar=l.forwardRef((t,e)=>{const n=Rr(ct,t.__scopeDialog),{forceMount:r=n.forceMount,...i}=t,s=he(ct,t.__scopeDialog);return s.modal?a.jsx(ht,{present:r||s.open,children:a.jsx(cc,{...i,ref:e})}):null});Ar.displayName=ct;var ac=ur("DialogOverlay.RemoveScroll"),cc=l.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,i=he(ct,n);return a.jsx(Tr,{as:ac,allowPinchZoom:!0,shards:[i.contentRef],children:a.jsx(ve.div,{"data-state":Zt(i.open),...r,ref:e,style:{pointerEvents:"auto",...r.style}})})}),Ce="DialogContent",Dr=l.forwardRef((t,e)=>{const n=Rr(Ce,t.__scopeDialog),{forceMount:r=n.forceMount,...i}=t,s=he(Ce,t.__scopeDialog);return a.jsx(ht,{present:r||s.open,children:s.modal?a.jsx(lc,{...i,ref:e}):a.jsx(uc,{...i,ref:e})})});Dr.displayName=Ce;var lc=l.forwardRef((t,e)=>{const n=he(Ce,t.__scopeDialog),r=l.useRef(null),i=ke(e,n.contentRef,r);return l.useEffect(()=>{const s=r.current;if(s)return rc(s)},[]),a.jsx(Lr,{...t,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Se(t.onCloseAutoFocus,s=>{s.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:Se(t.onPointerDownOutside,s=>{const c=s.detail.originalEvent,o=c.button===0&&c.ctrlKey===!0;(c.button===2||o)&&s.preventDefault()}),onFocusOutside:Se(t.onFocusOutside,s=>s.preventDefault())})}),uc=l.forwardRef((t,e)=>{const n=he(Ce,t.__scopeDialog),r=l.useRef(!1),i=l.useRef(!1);return a.jsx(Lr,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{t.onCloseAutoFocus?.(s),s.defaultPrevented||(r.current||n.triggerRef.current?.focus(),s.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:s=>{t.onInteractOutside?.(s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const c=s.target;n.triggerRef.current?.contains(c)&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&i.current&&s.preventDefault()}})}),Lr=l.forwardRef((t,e)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,...c}=t,o=he(Ce,n),u=l.useRef(null),d=ke(e,u);return ga(),a.jsxs(a.Fragment,{children:[a.jsx(pr,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:a.jsx(fr,{role:"dialog",id:o.contentId,"aria-describedby":o.descriptionId,"aria-labelledby":o.titleId,"data-state":Zt(o.open),...c,ref:d,onDismiss:()=>o.onOpenChange(!1)})}),a.jsxs(a.Fragment,{children:[a.jsx(dc,{titleId:o.titleId}),a.jsx(hc,{contentRef:u,descriptionId:o.descriptionId})]})]})}),Qt="DialogTitle",jr=l.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,i=he(Qt,n);return a.jsx(ve.h2,{id:i.titleId,...r,ref:e})});jr.displayName=Qt;var Or="DialogDescription",Br=l.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,i=he(Or,n);return a.jsx(ve.p,{id:i.descriptionId,...r,ref:e})});Br.displayName=Or;var Mr="DialogClose",Ir=l.forwardRef((t,e)=>{const{__scopeDialog:n,...r}=t,i=he(Mr,n);return a.jsx(ve.button,{type:"button",...r,ref:e,onClick:Se(t.onClick,()=>i.onOpenChange(!1))})});Ir.displayName=Mr;function Zt(t){return t?"open":"closed"}var Fr="DialogTitleWarning",[Ec,Ur]=Bo(Fr,{contentName:Ce,titleName:Qt,docsSlug:"dialog"}),dc=({titleId:t})=>{const e=Ur(Fr),n=`\`${e.contentName}\` requires a \`${e.titleName}\` for the component to be accessible for screen reader users.
146
+
147
+ If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
148
+
149
+ For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return l.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},fc="DialogDescriptionWarning",hc=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Ur(fc).contentName}}.`;return l.useEffect(()=>{const i=t.current?.getAttribute("aria-describedby");e&&i&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},pc=kr,mc=Pr,Gr=Ar,Wr=Dr,qr=jr,Hr=Br,_c=Ir;const gc=pc,xc=mc,Xr=l.forwardRef(({className:t,...e},n)=>a.jsx(Gr,{ref:n,className:oe("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));Xr.displayName=Gr.displayName;const zr=l.forwardRef(({className:t,children:e,...n},r)=>a.jsxs(xc,{children:[a.jsx(Xr,{}),a.jsxs(Wr,{ref:r,className:oe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-slate-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-2xl dark:border-slate-800 dark:bg-slate-950 dark:text-slate-50",t),...n,children:[e,a.jsxs(_c,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-[#1d9bf0] focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-slate-100 data-[state=open]:text-slate-500 dark:ring-offset-slate-950 dark:focus:ring-[#1d9bf0] dark:data-[state=open]:bg-slate-800 dark:data-[state=open]:text-slate-400",children:[a.jsx($s,{className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));zr.displayName=Wr.displayName;const $r=({className:t,...e})=>a.jsx("div",{className:oe("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});$r.displayName="DialogHeader";const Vr=({className:t,...e})=>a.jsx("div",{className:oe("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});Vr.displayName="DialogFooter";const Yr=l.forwardRef(({className:t,...e},n)=>a.jsx(qr,{ref:n,className:oe("text-lg font-semibold leading-none tracking-tight",t),...e}));Yr.displayName=qr.displayName;const Kr=l.forwardRef(({className:t,...e},n)=>a.jsx(Hr,{ref:n,className:oe("text-sm text-slate-500 dark:text-slate-400",t),...e}));Kr.displayName=Hr.displayName;var vc="Label",Jr=l.forwardRef((t,e)=>a.jsx(as.label,{...t,ref:e,onMouseDown:n=>{n.target.closest("button, input, select, textarea")||(t.onMouseDown?.(n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Jr.displayName=vc;var Qr=Jr;const Ue=l.forwardRef(({className:t,...e},n)=>a.jsx(Qr,{ref:n,className:oe("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-slate-900 dark:text-slate-100",t),...e}));Ue.displayName=Qr.displayName;const bc=[{name:"bigmodel",config:{base_url:"https://open.bigmodel.cn/api/paas/v4",model_name:"autoglm-phone",api_key:""}},{name:"modelscope",config:{base_url:"https://api-inference.modelscope.cn/v1",model_name:"ZhipuAI/AutoGLM-Phone-9B",api_key:""}},{name:"custom",config:{base_url:"",model_name:"autoglm-phone-9b",api_key:""}}];function Tc(){const t=lt(),[e,n]=l.useState([]),[r,i]=l.useState(""),[s,c]=l.useState({message:"",type:"info",visible:!1}),o=(g,b="info")=>{c({message:g,type:b,visible:!0})},[u,d]=l.useState(null),[f,h]=l.useState(!1),[_,m]=l.useState(!1),[x,p]=l.useState({base_url:"",model_name:"",api_key:""});l.useEffect(()=>{(async()=>{try{const b=await cs();d({base_url:b.base_url,model_name:b.model_name,api_key:b.api_key||void 0}),p({base_url:b.base_url,model_name:b.model_name,api_key:b.api_key||""}),b.base_url||h(!0)}catch(b){console.error("Failed to load config:",b),h(!0)}})()},[]),l.useEffect(()=>{const g=async()=>{try{const S=await ls(),k=new Map,y=new Map;for(const w of S.devices)if(w.serial){const D=y.get(w.serial)||[];D.push(w),y.set(w.serial,D)}else k.set(w.id,w);Array.from(y.values()).forEach(w=>{const T=w.find(W=>W.connection_type==="remote")||w[0];k.set(T.id,T)});const A=Array.from(k.values());n(A),A.length>0&&!r&&i(A[0].id),r&&!A.find(w=>w.id===r)&&i(A[0]?.id||"")}catch(S){console.error("Failed to load devices:",S)}};g();const b=setInterval(g,3e3);return()=>clearInterval(b)},[r]);const v=async()=>{if(!x.base_url){o(t.chat.baseUrlRequired,"error");return}try{await us({base_url:x.base_url,model_name:x.model_name||"autoglm-phone-9b",api_key:x.api_key||void 0}),d({base_url:x.base_url,model_name:x.model_name,api_key:x.api_key||void 0}),h(!1),o(t.toasts.configSaved,"success")}catch(g){console.error("Failed to save config:",g),o(`Failed to save: ${g instanceof Error?g.message:"Unknown error"}`,"error")}},E=async g=>{try{const b=await fs({device_id:g});b.success&&b.device_id?(i(b.device_id),o(t.toasts.wifiConnected,"success")):b.success||o(b.message||b.error||t.toasts.connectionFailed,"error")}catch(b){o(t.toasts.wifiConnectionError,"error"),console.error("Connect WiFi error:",b)}},C=async g=>{try{const b=await ds(g);b.success?o(t.toasts.wifiDisconnected,"success"):o(b.message||b.error||t.toasts.disconnectFailed,"error")}catch(b){o(t.toasts.wifiDisconnectError,"error"),console.error("Disconnect WiFi error:",b)}};return a.jsxs("div",{className:"h-full flex relative min-h-0",children:[s.visible&&a.jsx(Oo,{message:s.message,type:s.type,onClose:()=>c(g=>({...g,visible:!1}))}),a.jsx(gc,{open:f,onOpenChange:h,children:a.jsxs(zr,{className:"sm:max-w-md",children:[a.jsxs($r,{children:[a.jsxs(Yr,{className:"flex items-center gap-2",children:[a.jsx(Wn,{className:"w-5 h-5 text-[#1d9bf0]"}),t.chat.configuration]}),a.jsx(Kr,{children:t.chat.configureApi})]}),a.jsxs("div",{className:"space-y-4 py-4",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ue,{className:"text-sm font-medium",children:t.chat.selectPreset}),a.jsx("div",{className:"grid grid-cols-1 gap-2",children:bc.map(g=>a.jsxs("button",{type:"button",onClick:()=>p({base_url:g.config.base_url,model_name:g.config.model_name,api_key:g.config.api_key}),className:`text-left p-3 rounded-lg border transition-all ${x.base_url===g.config.base_url&&(g.name!=="custom"||g.name==="custom"&&x.base_url==="")?"border-[#1d9bf0] bg-[#1d9bf0]/5":"border-slate-200 dark:border-slate-700 hover:border-[#1d9bf0]/50 hover:bg-slate-50 dark:hover:bg-slate-800/50"}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Bs,{className:`w-4 h-4 ${x.base_url===g.config.base_url&&(g.name!=="custom"||g.name==="custom"&&x.base_url==="")?"text-[#1d9bf0]":"text-slate-400 dark:text-slate-500"}`}),a.jsx("span",{className:"font-medium text-sm text-slate-900 dark:text-slate-100",children:t.presetConfigs[g.name].name})]}),a.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-1 ml-6",children:t.presetConfigs[g.name].description})]},g.name))})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs(Ue,{htmlFor:"base_url",children:[t.chat.baseUrl," *"]}),a.jsx(it,{id:"base_url",value:x.base_url,onChange:g=>p({...x,base_url:g.target.value}),placeholder:"http://localhost:8080/v1"}),!x.base_url&&a.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[a.jsx(Ie,{className:"w-3 h-3"}),t.chat.baseUrlRequired]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ue,{htmlFor:"api_key",children:t.chat.apiKey}),a.jsxs("div",{className:"relative",children:[a.jsx(it,{id:"api_key",type:_?"text":"password",value:x.api_key,onChange:g=>p({...x,api_key:g.target.value}),placeholder:"Leave empty if not required",className:"pr-10"}),a.jsx(ie,{type:"button",variant:"ghost",size:"icon",onClick:()=>m(!_),className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",children:_?a.jsx(bs,{className:"w-4 h-4 text-slate-400"}):a.jsx(ws,{className:"w-4 h-4 text-slate-400"})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx(Ue,{htmlFor:"model_name",children:t.chat.modelName}),a.jsx(it,{id:"model_name",value:x.model_name,onChange:g=>p({...x,model_name:g.target.value}),placeholder:"autoglm-phone-9b"})]})]}),a.jsxs(Vr,{className:"sm:justify-between gap-2",children:[a.jsx(ie,{variant:"outline",onClick:()=>{h(!1),u&&p({base_url:u.base_url,model_name:u.model_name,api_key:u.api_key||""})},children:t.chat.cancel}),a.jsxs(ie,{onClick:v,variant:"twitter",children:[a.jsx(Ge,{className:"w-4 h-4 mr-2"}),t.chat.saveConfig]})]})]})}),a.jsx(Ks,{devices:e,currentDeviceId:r,onSelectDevice:i,onOpenConfig:()=>h(!0),onConnectWifi:E,onDisconnectWifi:C}),a.jsx("div",{className:"flex-1 flex items-stretch justify-center min-h-0 px-4 py-4",children:e.length===0?a.jsx("div",{className:"flex-1 flex items-center justify-center bg-slate-50 dark:bg-slate-950",children:a.jsxs("div",{className:"text-center",children:[a.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-800 mx-auto mb-4",children:a.jsx("svg",{className:"w-10 h-10 text-slate-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),a.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-100 mb-2",children:t.chat.welcomeTitle}),a.jsx("p",{className:"text-slate-500 dark:text-slate-400",children:t.chat.connectDevice})]})}):e.map(g=>a.jsx("div",{className:`w-full max-w-7xl flex items-stretch justify-center min-h-0 ${g.id===r?"":"hidden"}`,children:a.jsx(jo,{deviceId:g.id,deviceName:g.model,config:u,isVisible:g.id===r,isConfigured:!!u?.base_url})},g.id))})]})}export{Tc as component};