diff --git a/server/public/assets/index-D7L_pr9D.js b/server/public/assets/index-De2C8XFV.js similarity index 98% rename from server/public/assets/index-D7L_pr9D.js rename to server/public/assets/index-De2C8XFV.js index a4b79ecf..b98d3ac2 100644 --- a/server/public/assets/index-D7L_pr9D.js +++ b/server/public/assets/index-De2C8XFV.js @@ -123,4 +123,4 @@ wok yeast yogurt shrimp -fling`;function qX(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""}function DX(){const t=String(TX).split(/\r?\n/).map(l=>l.trim()).filter(Boolean);return t.length?(t[Math.floor(Math.random()*t.length)]||"").trim():""}function $8(){const{setNickname:t}=$2(),{value:a,status:l,save:o}=N1("profile",{nickname:""}),u=m.useRef(!1);m.useEffect(()=>{if(l!=="ready"||u.current||(a.nickname||"").trim())return;u.current=!0;const p=qX(DX()).slice(0,32);if(!p)return;(async()=>{try{await t(p)}catch{}finally{o({nickname:p})}})()},[o,t,l,a.nickname])}function G8(){const t=q2(),a=h1(B=>B.connected),{identifySession:l}=$2(),{value:o,status:u,save:d}=N1("identity",{cookieUserId:""}),{value:p,status:v}=N1("profile",{nickname:""}),{value:g,status:x}=N1("overseerPreference",{enabled:!1}),z=m.useRef(!1),M=m.useRef(null),y=m.useRef(null),H=u==="ready"&&v==="ready"&&x==="ready",S=(o?.cookieUserId||"").trim(),w=(p?.nickname||"").trim(),C=!!g?.enabled,V=m.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null)},[]),A=m.useCallback(async()=>{if(!(!H||!a||!t?.id||z.current)){z.current=!0;try{const k=((await l({cookieUserId:S,nickname:w,overseerEnabled:C}))?.cookieUserId||"").trim();k&&k!==S&&d(D=>({...D||{},cookieUserId:k})),M.current=t.id,V()}catch{V(),y.current=setTimeout(()=>{A()},2e3)}finally{z.current=!1}}},[V,a,S,l,w,C,H,d,t?.id]);m.useEffect(()=>{!H||!a||!t?.id||M.current!==t.id&&A()},[a,H,A,t?.id]),m.useEffect(()=>{!H||!a||!t?.id||A()},[H,a,t?.id,S,w,C,A]),m.useEffect(()=>{const B=()=>{t?.connected&&A()},k=()=>{typeof document>"u"||document.visibilityState!=="visible"||t?.connected&&A()};return window.addEventListener("online",B),document.addEventListener("visibilitychange",k),()=>{window.removeEventListener("online",B),document.removeEventListener("visibilitychange",k)}},[A,t?.connected]),m.useEffect(()=>{if(!H||!t?.connected)return;const B=setInterval(()=>{t?.connected&&A()},6e4);return()=>clearInterval(B)},[H,A,t?.connected]),m.useEffect(()=>()=>V(),[V])}const ec=1e4,cc=28,OX=14;function _X(t){const a=String(t||"").trim(),l=a.startsWith("#")?a.slice(1):a;if(!/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/.test(l))return null;const o=l.length===3?l.split("").map(u=>u+u).join(""):l;return{r:Number.parseInt(o.slice(0,2),16),g:Number.parseInt(o.slice(2,4),16),b:Number.parseInt(o.slice(4,6),16)}}function Rs(t,a){return`rgba(${t.r}, ${t.g}, ${t.b}, ${a})`}function I7({layout:t="desktop",className:a="",dismissable:l=!0}){const o=h1(k=>{const D=k.session?.globalObjective?.text;return D?String(D).trim():""}),u=h1(k=>{const D=String(k.session?.assignment?.roverId||"").trim();return D&&(Array.isArray(k.session?.roster)?k.session.roster:[]).find(E=>String(E?.id)===D)?.color||null}),d=t==="mobile-portrait"||t==="mobile-landscape"||t==="mobile",[p,v]=m.useState(!1),[g,x]=m.useState(cc),[z,M]=m.useState(0),y=m.useRef(null),H=m.useRef(null),S=m.useRef(null);m.useEffect(()=>{if(!o){v(!1);return}if(v(!0),!d||!l)return;const k=Date.now();M(ec);const D=setTimeout(()=>v(!1),ec),N=setInterval(()=>{const j=Date.now()-k;M(Math.max(0,ec-j))},250);return()=>{clearTimeout(D),clearInterval(N)}},[o,d]),m.useEffect(()=>{if(!o)return;x(cc);let k=0;const D=()=>{const j=S.current,E=H.current;if(!j||!E)return;const Z=j.clientWidth;if(!Z)return;const q=E.scrollWidth;if(!q)return;const T=Math.min(1,Z/q),P=Math.max(OX,Math.floor(cc*T));x(P)};k=window.requestAnimationFrame(D);const N=new ResizeObserver(()=>{window.cancelAnimationFrame(k),k=window.requestAnimationFrame(D)});return y.current&&N.observe(y.current),()=>{window.cancelAnimationFrame(k),N.disconnect()}},[o]);const w=m.useMemo(()=>["panel-section flex w-full items-center justify-center border border-neutral-500/60 shadow-[0_1px_0_rgba(255,255,255,0.05)_inset,0_10px_24px_rgba(0,0,0,0.28)]",d?"rounded-none":"rounded","px-1 py-1 text-center font-semibold tracking-tight",a].filter(Boolean).join(" "),[a,d]),C=_X(u),V=C?{borderColor:Rs(C,.35),backgroundImage:`linear-gradient(90deg, rgba(23,23,23,0.96) 0%, rgba(38,38,38,0.94) 58%, ${Rs(C,.18)} 100%)`}:void 0;if(!o||!p)return null;const A=d?Math.ceil(z/1e3):null,B=l?{onClick:()=>v(!1),role:"button",tabIndex:0}:{};return r.jsx("div",{ref:y,className:w,style:{...V||{},fontSize:`${g}px`,lineHeight:1.1},...B,children:r.jsxs("span",{className:"flex w-full items-stretch gap-0.5 whitespace-nowrap rounded-md",children:[r.jsxs("span",{className:"flex flex-col justify-center border-r border-slate-700/60 px-0.5 text-[0.55em] font-semibold leading-tight text-slate-400",children:[r.jsx("span",{children:"Global"}),r.jsx("span",{children:"Objective"})]}),r.jsx("span",{ref:S,className:"flex-1 overflow-hidden text-slate-100",children:r.jsx("span",{ref:H,className:"block",children:o})}),d?r.jsxs("span",{className:"flex items-center border-l border-slate-700/60 px-0.5 text-[0.55em] font-semibold uppercase tracking-wide text-slate-400",children:[A,"s"]}):null]})})}const UX=3200;function ZX(t={}){const a=typeof t.rewardName=="string"&&t.rewardName.trim()?t.rewardName.trim():"Unknown Event",l=Number.isFinite(Number(t.goal))?Math.max(1,Math.floor(Number(t.goal))):0,o=Number.isFinite(Number(t.count))?Math.max(0,Math.floor(Number(t.count))):l;return{rewardName:a,goal:l,count:o,ts:Date.now()}}function oa(){const t=q2(),{value:a}=N1("audio",p2),l=Number.isFinite(a?.masterVolume)?a.masterVolume:p2.masterVolume,o=Number.isFinite(a?.alertVolume)?a.alertVolume:p2.alertVolume,u=Math.max(0,Math.min(1,l*o)),[d,p]=m.useState(null),v=m.useRef(null);return m.useEffect(()=>{v.current=new Audio("/tada.mp3"),v.current.volume=u,v.current.load()},[u]),m.useEffect(()=>{let g=null;function x(){const y=v.current;y&&(y.volume=u,y.currentTime=0,y.play().catch(()=>{}))}function z(y={}){const H=ZX(y);p(H),x(),g&&clearTimeout(g),g=setTimeout(()=>{p(null)},UX)}function M(y){z(y?.detail||{})}return t.on("buttonBox:rewardRun",z),window.addEventListener("buttonBox:rewardRunLocalTest",M),()=>{g&&clearTimeout(g),t.off("buttonBox:rewardRun",z),window.removeEventListener("buttonBox:rewardRunLocalTest",M)}},[u,t]),d?r.jsx("div",{className:"pointer-events-none fixed inset-0 z-[120] flex items-center justify-center bg-black/75 px-1 py-1",children:r.jsx("div",{className:"pointer-events-auto w-full max-w-2xl",children:r.jsx("div",{className:"surface rounded-none border-2 border-cyan-300 bg-amber-100/95 px-1 py-1 text-center text-black shadow-2xl",children:r.jsxs("div",{className:"flex items-center justify-center gap-1 border-2 border-blue-600 bg-yellow-100 px-0.5 py-1",children:[r.jsx("img",{src:"/party1.gif",alt:"",className:"hidden shrink-0 sm:block"}),r.jsxs("div",{children:[r.jsxs("p",{className:"font-mono text-2xl font-bold text-red-700 sm:text-3xl",children:["Running event: ",d.rewardName,"!"]}),r.jsxs("p",{className:"font-mono text-xl font-bold text-blue-800 sm:text-2xl",children:[d.count,"/",d.goal]})]}),r.jsx("img",{src:"/party2.gif",alt:"",className:"hidden shrink-0 sm:block"})]})})})}):null}const $X=4e3;function Es(...t){return t.filter(Boolean).join(" ")}function Ou(){const t=q2(),[a,l]=m.useState(!!t?.connected),[o,u]=m.useState(""),[d,p]=m.useState(!0),[v,g]=m.useState(!1),x=m.useRef(null);m.useEffect(()=>{const S=()=>{x.current&&(clearTimeout(x.current),x.current=null)},w=()=>{S(),p(!0),g(!1)},C=()=>{S(),x.current=setTimeout(()=>{g(!0)},$X)},V=()=>{l(!0),u(""),w(),C()},A=D=>{l(!1),u(typeof D=="string"?D:"disconnected"),w()},B=D=>{l(!1),u(D?.message||"connect error"),w()},k=()=>{l(!1),w()};return t.on("connect",V),t.on("disconnect",A),t.on("connect_error",B),t.io.on("reconnect_attempt",k),t.connected&&C(),()=>{S(),t.off("connect",V),t.off("disconnect",A),t.off("connect_error",B),t.io.off("reconnect_attempt",k)}},[t]);const z=typeof navigator<"u"?navigator.onLine===!1:!1,M=a?"Connected to socket.io":z?"Offline":"Reconnecting...",y=a?"":o,H=a?"bg-emerald-700 text-emerald-100":z?"bg-red-800 text-red-100":"bg-amber-800 text-amber-100";return r.jsx("div",{className:Es("fixed bottom-2 left-2 z-[120] transition-opacity duration-500",!d&&"hidden",v?"opacity-0 pointer-events-none":"opacity-100"),"aria-live":"polite",children:r.jsxs("div",{className:Es("rounded-sm px-2 py-1 text-xs",H),children:[r.jsx("span",{className:"font-semibold",children:M}),y?r.jsxs("span",{className:"ml-1 opacity-85",children:["(",y,")"]}):null]})})}function GX(){const[t,a]=m.useState(()=>typeof window>"u"||window.innerWidth>=1024?"desktop":window.innerWidth>window.innerHeight?"mobile-landscape":"mobile-portrait");return m.useEffect(()=>{function l(){if(typeof window>"u")return;const{innerWidth:o,innerHeight:u}=window;o>=1024?a("desktop"):o>u?a("mobile-landscape"):a("mobile-portrait")}return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]),t}function PX({layout:t,onOpenHelpOverlay:a}){return r.jsxs("div",{className:`flex h-full ${C2} overflow-hidden`,children:[r.jsxs("div",{className:`flex min-w-0 flex-[1.22] flex-col ${C2} overflow-y-auto pr-0`,children:[r.jsx(ea,{}),r.jsx(_p,{}),r.jsx(pp,{})]}),r.jsxs("div",{className:`flex min-w-0 flex-1 flex-col ${C2} overflow-y-auto`,children:[r.jsx(I7,{layout:t}),r.jsx(zX,{layout:t,onOpenHelpOverlay:a})]})]})}function _u({layout:t,onOpenHelpOverlay:a,roomPanelId:l}){const[o,u]=m.useState("chat"),d=h1(w=>!!w.session?.isVerified),p=h1(w=>String(w.session?.assignment?.roverId||"").trim()),v=h1(w=>{const C=String(w.session?.assignment?.roverId||"").trim();return C&&w.session?.audioForward?.[C]||null}),g=R1(w=>!!w.state.mic?.pttActive),{value:x}=N1("vipAudio",{openMicEnabled:!1,pttMode:"live"}),z=d?"bg-emerald-400":"bg-amber-400",M=!!x?.openMicEnabled,y=x?.pttMode==="clip"?"clip":"live",H=!!(p&&d&&(y==="clip"?g:M||g)),S=!!(p&&d&&y==="clip"&&v?.source==="upload"&&v?.state==="playing");return r.jsx("section",{className:"text-base",children:r.jsxs(la,{defaultTab:"chat",currentTab:o,onTabChange:u,children:[r.jsxs(ra,{children:[r.jsx(I2,{id:"chat",children:"Chat"}),r.jsx(I2,{id:"activities",children:"Activities"}),r.jsx(I2,{id:"vip",highlight:S?"green":H?"pink":"none",children:r.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[r.jsx("span",{children:"VIP"}),r.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${z}`,"aria-hidden":"true",title:d?"Verified":"Not verified"})]})}),r.jsx(I2,{id:"roomcontrols",children:"Room Controls"}),r.jsx(I2,{id:"help",children:"Help"}),r.jsx(I2,{id:"settings",children:"Settings"})]}),r.jsxs(ia,{children:[r.jsx(Y2,{id:"chat",children:r.jsxs("div",{className:v6,children:[r.jsx(U8,{nicknameLayout:"stacked"}),r.jsxs("div",{className:v6,children:[r.jsx("div",{className:`grid ${C2} md:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]`,children:r.jsx(sa,{})}),r.jsxs("div",{className:`grid ${C2} grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[r.jsx(Du,{}),r.jsx(G7,{hideNicknameForm:!0})]})]})]})}),r.jsx(Y2,{id:"activities",children:r.jsxs("div",{className:`flex flex-col ${C2}`,children:[r.jsx(P7,{}),r.jsx(pu,{})]})}),r.jsx(Y2,{id:"vip",keepMounted:!0,children:r.jsx(qu,{isActive:o==="vip"})}),r.jsx(Y2,{id:"roomcontrols",children:r.jsxs("div",{className:v6,children:[r.jsx(Vu,{}),r.jsx(Wc,{panelId:l})]})}),r.jsx(Y2,{id:"help",children:r.jsx(Eu,{layout:t,onOpenOverlay:a})}),r.jsx(Y2,{id:"settings",children:r.jsx("div",{className:v6,children:r.jsx(Fu,{})})})]})]})})}function IX({onOpenHelpOverlay:t,swapMobileControlColumns:a=!1}){const l="h-[min(60svh,24rem)]",o=a?r.jsx(Z7,{layout:"portrait",className:l}):r.jsx(U7,{layout:"portrait",className:l}),u=a?r.jsx(U7,{layout:"portrait",className:l}):r.jsx(Z7,{layout:"portrait",className:l});return r.jsxs("div",{className:`flex flex-col ${C2}`,children:[r.jsx(ea,{layoutFormat:"mobile-portrait"}),r.jsx("section",{className:"mobile-touch-control text-white",children:r.jsxs("div",{className:"mobile-touch-control grid grid-cols-2 gap-0.5 items-stretch",children:[o,u]})}),r.jsxs("div",{className:`grid ${C2} grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[r.jsx(Zc,{panelId:"replay-sources-mobile-portrait"}),r.jsx(rt,{})]}),r.jsx(_u,{layout:"mobile-portrait",onOpenHelpOverlay:t,roomPanelId:"mobile-portrait-room"})]})}function YX({onOpenHelpOverlay:t,swapMobileControlColumns:a=!1}){const l="self-start h-[min(100svh,32rem)]",o=a?r.jsx(Z7,{layout:"landscape",className:l}):r.jsx(U7,{layout:"landscape",className:l}),u=a?r.jsx(U7,{layout:"landscape",className:l}):r.jsx(Z7,{layout:"landscape",className:l});return r.jsxs("div",{className:`flex flex-col ${C2}`,children:[r.jsxs("section",{className:`grid min-h-screen grid-cols-[minmax(0,0.7fr)_minmax(0,2.1fr)_minmax(0,0.7fr)] ${C2}`,children:[o,r.jsxs("div",{children:[r.jsx(ea,{layoutFormat:"mobile-landscape"}),r.jsxs("div",{className:`grid ${C2} grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[r.jsx(Zc,{panelId:"replay-sources-mobile-landscape"}),r.jsx(rt,{})]})]}),u]}),r.jsx("div",{className:`flex flex-col ${C2} pb-0`,children:r.jsx(_u,{layout:"mobile-landscape",onOpenHelpOverlay:t,roomPanelId:"mobile-landscape-room"})})]})}function KX(){const t=GX(),a=t==="desktop",l=NX(t);return r.jsx("div",{className:`${oQ} text-slate-100 ${a?"h-screen overflow-hidden":"ios-safe-screen min-h-screen"}`,children:r.jsx(QX,{layout:t,isDesktop:a,fullscreen:l})})}function QX({layout:t,isDesktop:a,fullscreen:l}){$8(),G8(),Kv({mobile:!a});const{visible:o,mode:u,isIOS:d,nativeSupported:p,enterFullscreen:v,dismiss:g,showPrompt:x}=l,{value:z,save:M}=N1("help",{showOnLoad:!0}),{value:y,status:H,save:S}=N1("quickstart",{showOnLoad:!0}),{value:w}=N1("page",{swapMobileControlColumns:!1}),C=!!w?.swapMobileControlColumns,V=C?"left":"right",A=!a&&(d||p),[B,k]=m.useState(!1),[D,N]=m.useState(!1);m.useEffect(()=>{H==="ready"&&N(y?.showOnLoad!==!1)},[H,y?.showOnLoad]);const j=m.useCallback(()=>k(!0),[]),E=m.useCallback(()=>k(!1),[]),Z=m.useCallback(()=>N(!1),[]),q=m.useCallback(async()=>{if(d){x();return}await v()||x()},[v,d,x]),T=m.useCallback(n1=>{const I=!!n1;S(R=>({...R??{},showOnLoad:I})),I||N(!1)},[S]),P=m.useCallback(()=>{N(!1),k(!0)},[]),o1=m.useMemo(()=>a?r.jsx(PX,{layout:t,onOpenHelpOverlay:j}):t==="mobile-landscape"?r.jsx(YX,{onOpenHelpOverlay:j,swapMobileControlColumns:C}):r.jsx(IX,{onOpenHelpOverlay:j,swapMobileControlColumns:C}),[a,t,j,C]);return r.jsxs(NI,{children:[r.jsx(II,{}),r.jsx(lY,{}),r.jsxs("main",{className:`flex w-full flex-col ${C2} text-base ${a?"h-full overflow-hidden":""}`,children:[a?null:r.jsx(I7,{layout:t}),o1]}),r.jsx(Pc,{}),r.jsx(oa,{}),r.jsx(VX,{}),r.jsx(wX,{}),r.jsx(Ou,{}),r.jsx(FX,{visible:B,layout:t,onClose:E,showOnLoad:z?.showOnLoad!==!1,onToggleShowOnLoad:n1=>M(I=>({...I??{},showOnLoad:!!n1}))}),r.jsx(AX,{visible:o,mode:u,onEnterFullscreen:v,onDismiss:g}),r.jsx(EX,{visible:D,layout:t,showOnLoad:y?.showOnLoad!==!1,onToggleShowOnLoad:T,onOpenHelp:P,onClose:Z}),A?r.jsx(LX,{side:V,onClick:q}):null]})}function it(){const{session:t,setRole:a,subscribeAll:l,connected:o}=C0(),[u,d]=m.useState(!1);return m.useEffect(()=>{let p=!1;async function v(){if(t?.mode==="lockdown"){d(!1);return}try{t?.role!=="spectator"&&await a("spectator"),await l(),p||d(!0)}catch(g){console.error("Failed to enter spectator mode",g),p||d(!1)}}return v(),()=>{p=!0}},[o,t?.mode,t?.role,a,l]),u}function XX(){const[t,a]=m.useState(()=>typeof window>"u"?!1:window.matchMedia("(max-aspect-ratio: 4/3)").matches);return m.useEffect(()=>{if(typeof window>"u")return;const l=window.matchMedia("(max-aspect-ratio: 4/3)"),o=u=>a(u.matches);return l.addEventListener?l.addEventListener("change",o):l.addListener(o),()=>{l.removeEventListener?l.removeEventListener("change",o):l.removeListener(o)}},[]),t}function JX({show:t=!1,roverId:a=null,sensors:l,batteryConfig:o,mobileHud:u=!1}){const d=U4(a,tt,W7),p=h1(z=>a?(z.session?.roster||[]).find(H=>String(H.id)===String(a))?.battery??null:null),v=l?{batteryChargeMah:l?.batteryChargeMah??null,batteryCapacityMah:l?.batteryCapacityMah??null}:d,g=o??p,x=_8({charge:v?.batteryChargeMah??null,config:g});return!t||!x?.available?null:r.jsx("div",{className:"pointer-events-none absolute right-1 top-1/2 flex h-[70%] -translate-y-1/2 flex-col items-center justify-center rounded bg-black/60 px-0.5 pb-1 pt-1",children:r.jsx(at,{visual:x,orientation:"vertical",variant:"inline",compact:u,className:"h-full w-4"})})}const WX=w2.memo(JX);function tJ({roverId:t=null,label:a,fitParent:l=!1,layoutFormat:o="desktop"}){return r.jsx("div",{className:`flex flex-col gap-0.5 ${l?"h-full":""}`,children:r.jsxs("div",{className:`relative w-full overflow-hidden bg-black ${l?"h-full flex-1":"aspect-[4/3]"}`,children:[r.jsx(N8,{roverId:t,label:a}),r.jsx(Cu,{roverId:t,variant:"spectator",mobileHud:!1}),r.jsx(yu,{roverId:t,layoutFormat:o,variant:"spectator",mobileHud:!1,labelScale:1}),r.jsx(wu,{roverId:t,compact:!1}),r.jsx(Hu,{roverId:t,compact:!1}),r.jsx(WX,{show:!0,roverId:t,mobileHud:!1})]})})}function eJ({rover:t}){return r.jsx("article",{className:"min-h-[16rem] rounded bg-zinc-900 p-0 sm:min-h-[18rem]",children:r.jsx("div",{className:"min-h-0 overflow-hidden rounded bg-black/20",children:r.jsx(tJ,{roverId:t.id,label:t.name})})})}function cJ({roster:t}){return t.length===0?r.jsx("p",{className:"col-span-full text-slate-400",children:"No rovers registered."}):r.jsx("section",{className:"grid grid-cols-1 gap-0.5 md:grid-cols-2",children:t.map(a=>r.jsx(eJ,{rover:a},a.id))})}function aJ(){return r.jsx("section",{className:"min-h-0",children:r.jsx("div",{className:"surface min-h-[14rem] overflow-hidden",children:r.jsx(Wc,{defaultOrientation:"horizontal",hideLayoutToggle:!0,hideHeader:!0,panelId:"spectator-secondary"})})})}function nJ(){const t=q2(),a=h1(o=>o.logs),l=m.useMemo(()=>a.slice().reverse(),[a]);return m.useEffect(()=>{const o=()=>{t.emit("log:subscribe")};return o(),t.on("connect",o),()=>{t.off("connect",o),t.emit("log:unsubscribe")}},[t]),r.jsx(B1,{title:"Server logs",bodyClassName:"space-y-0.5 text-base",children:r.jsx("div",{className:"surface h-64 overflow-y-auto font-mono text-xs",children:a.length===0?r.jsx("p",{children:"No logs yet."}):l.map(o=>r.jsxs("div",{className:"surface",children:[r.jsx("span",{className:"text-amber-400",children:o.timestamp})," ",r.jsxs("span",{className:"text-lime-400",children:["[",o.level,"]"]})," ",o.label&&r.jsxs("span",{className:"text-teal-400",children:["[",o.label,"]"]})," ",r.jsx("span",{children:o.message})]},o.id))})})}function lJ({className:t=""}){return r.jsx("div",{className:`panel ${t}`,children:r.jsx(nJ,{})})}function rJ(){const{session:t}=C0(),a=h1(M=>M.latestReplay),{clearLatestReplay:l}=$2(),o=t?.mode==="lockdown";$8(),G8(),it();const u=XX(),d=t?.roster??[];if(o)return r.jsx("div",{className:"flex min-h-screen items-center justify-center bg-black text-slate-200",children:r.jsxs("div",{className:"surface max-w-md space-y-0.5 p-1 text-center text-sm",children:[r.jsx("p",{className:"text-lg font-semibold text-white",children:"Spectate disabled during lockdown."}),r.jsx("p",{className:"text-slate-300",children:"Please wait until the server leaves lockdown to view streams."})]})});const p=u?"flex min-h-screen flex-col bg-black text-slate-100 md:h-screen md:overflow-hidden":"grid min-h-screen grid-cols-1 gap-0.5 bg-black text-slate-100 md:h-full md:min-h-0 md:grid-cols-[minmax(0,1fr)_18rem] lg:grid-cols-[minmax(0,1fr)_20rem]",v=u?"order-2 flex min-h-0 min-w-0 flex-1 flex-col gap-0.5 overflow-y-auto":"order-1 flex min-h-0 min-w-0 flex-col gap-0.5 md:overflow-y-auto",g=u?"order-1 grid w-full min-h-0 items-stretch gap-0.5 border-b border-slate-800/60 bg-slate-950/90 p-0.5 grid-cols-[minmax(0,1fr)_minmax(0,0.7fr)_minmax(0,1.9fr)_minmax(0,0.7fr)]":"order-2 flex min-h-0 min-w-0 flex-col gap-0.5 border-l border-slate-800/60 bg-slate-950/90 md:h-full md:overflow-y-auto",x="",z=u?"h-64":"";return r.jsxs("div",{className:"min-h-screen bg-black text-slate-100 md:h-screen md:overflow-hidden",children:[r.jsxs("main",{className:p,children:[r.jsxs("section",{className:g,children:[u?r.jsxs("div",{className:`${x} ${z} flex flex-col gap-0.5`,children:[r.jsx(I7,{layout:"desktop",dismissable:!1,className:"text-sm"}),r.jsx(P7,{}),r.jsx("div",{className:"min-h-0 flex-1",children:r.jsx(G7,{hideNicknameForm:!0,hideHeader:!0,compact:!0,fillHeight:!0,className:"h-full"})})]}):r.jsxs("div",{className:x,children:[r.jsx(I7,{layout:"desktop",dismissable:!1,className:"text-sm"}),r.jsx(P7,{})]}),r.jsx("div",{className:`${x} ${u?`${z} overflow-y-auto`:""}`,children:r.jsx("div",{className:"panel h-full",children:r.jsx(rt,{title:"Rovers"})})}),u?null:r.jsx("div",{className:`${x} flex-1 min-h-0`,children:r.jsx(G7,{hideNicknameForm:!0,hideHeader:!0,compact:!0,fillHeight:!0,className:"h-full"})}),r.jsx("div",{className:`${x} ${u?z:"flex-[1.1] min-h-0"}`,children:r.jsx(U8,{allowSpectatorInput:!0,hideSpectatorNotice:!0,fillHeight:!0})}),r.jsx("div",{className:`${x} ${u?z:""}`,children:r.jsx(lJ,{className:`${u?"h-full":"h-40"} overflow-hidden`})})]}),r.jsxs("section",{className:v,children:[r.jsx(cJ,{roster:d}),r.jsx(aJ,{})]})]}),r.jsx(Pc,{}),r.jsx(oa,{}),r.jsx(Uc,{replay:a,onClose:l})]})}function iJ(){return r.jsx(rJ,{})}function sJ({children:t}){return r.jsx("div",{className:"flex h-full w-full items-center justify-start overflow-hidden bg-black",children:r.jsx("div",{className:"relative flex items-center justify-center overflow-hidden bg-black",style:{width:"min(100%, calc(100vh * 4 / 3))",height:"min(100%, calc(100vw * 3 / 4))",maxWidth:"100%",maxHeight:"100%",aspectRatio:"4 / 3"},children:r.jsx("div",{className:"flex h-full w-full items-center justify-center overflow-hidden",children:t})})})}function oJ({roverId:t,session:a}){const l=a?.activeDrivers?.[t]||null,u=(a?.users||[]).find(v=>v.socketId===l)?.nickname||(l?l.slice(0,6):"No driver"),d=a?.mode,p=a?.turnQueues?.[t];return d==="turns"&&p?.current?`${u}`:u}function uJ({rover:t,frame:a}){const l=a?.sensors?.batteryChargeMah??null,o=t?.battery??null;return _8({batteryState:t?.batteryState??null,charge:l,config:o})}function d3({children:t,className:a="",maxSize:l=1e3,minSize:o=14,style:u=void 0}){const d=m.useRef(null),p=m.useRef(null),[v,g]=m.useState(l);return m.useLayoutEffect(()=>{const x=d.current,z=p.current;if(!x||!z)return;let M=null;const y=()=>{const w=x.clientWidth;if(!w){H();return}let C=o,V=l,A=o;for(;C<=V;){const B=Math.floor((C+V)/2);z.style.fontSize=`${B}px`,z.scrollWidth<=w?(A=B,C=B+1):V=B-1}g(A)},H=()=>{M&&cancelAnimationFrame(M),M=requestAnimationFrame(y)};H();const S=new ResizeObserver(H);return S.observe(x),()=>{M&&cancelAnimationFrame(M),S.disconnect()}},[t,l,o]),r.jsx("div",{ref:d,className:"w-full min-w-0",children:r.jsx("div",{ref:p,className:`whitespace-nowrap ${a}`,style:{fontSize:`${v}px`,lineHeight:1.1,...u||{}},children:t})})}function Ts({rover:t,frame:a,driverLabel:l,sessionInfo:o,videoMode:u="snapshot",snapshotFeed:d,withDivider:p=!1,showPreview:v=!0,variant:g="stacked"}){const x=uJ({rover:t,frame:a}),z=x?.available?x.percentDisplay:null,M=g==="active";return r.jsxs("div",{className:`relative flex min-w-0 flex-1 flex-col gap-4 overflow-hidden bg-black px-0 py-0 ${p?"border-r border-slate-700/60":""}`,children:[r.jsx(at,{visual:x,orientation:M?"vertical":"horizontal",variant:"background"}),M?r.jsxs("div",{className:"relative z-10 flex min-w-0 flex-1 flex-col justify-between text-center",children:[r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(V4,{rover:t,fallback:t.id,as:d3,className:"leading-none",maxSize:1e3,minSize:18})}),l?r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:1e3,minSize:16,children:l})}):r.jsx("div",{}),r.jsx("div",{className:"relative min-w-0 overflow-hidden bg-transparent px-0 py-0 leading-none",children:r.jsx("div",{className:"relative",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:1e3,minSize:16,children:z==null?"--%":`${z}%`})})})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"relative z-10 flex min-w-0 flex-col gap-1 text-center",children:[r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(V4,{rover:t,fallback:t.id,as:d3,className:"leading-none",maxSize:1e3,minSize:18})}),l?r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:1e3,minSize:16,children:l})}):null,r.jsx("div",{className:"relative min-w-0 overflow-hidden bg-transparent px-0 py-0 leading-none",children:r.jsx("div",{className:"relative",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:80,minSize:16,children:z==null?"--%":`${z}%`})})})]}),r.jsx("div",{className:"relative z-10 flex min-w-0 flex-1 flex-col gap-4",children:r.jsx("div",{className:"flex w-full min-w-0 flex-1 flex-col items-center gap-4",children:v?r.jsx("div",{className:"mt-auto w-full",children:r.jsx("div",{className:"w-full aspect-[4/3]",children:r.jsx(N8,{sessionInfo:o,videoMode:u,snapshotFeed:d,audioSessionInfo:null,label:t.name||t.id,sensors:a?.sensors||null})})}):null})})]})]})}const hJ=2e4,dJ=3600*1e3;function fJ(){const{session:t}=C0(),a=it();$8(),G8();const l=t?.mode==="lockdown",o=!!t?.isLocalNetwork,u=Yv(),d=t?.roster??[],[p,v]=m.useState(0),g=t?.activeDrivers||{},x=m.useMemo(()=>d.filter(q=>g[q.id]),[d,g]),z=x.length?x:d,M=gu(z.map(q=>q.id),{enabled:!l&&!o,version:t?.mode}),y=m.useMemo(()=>o?z.map(q=>({type:"rover",id:q.id,key:q.id})):[],[o,z]),H=yc(y,{enabled:!l&&o,version:t?.mode}),S=m.useMemo(()=>x.flatMap(q=>{if(!q?.id||!q.media?.audioPublishUrl)return[];const T=String(q.id);return[{type:"rover",id:`${T}-audio`,key:`${T}-audio`}]}),[x]),w=yc(S,{enabled:!l,version:t?.mode}),C=m.useMemo(()=>{if(!x.length)return[];if(!o){const T=x.filter(P=>M[P.id]?.objectUrl);return T.length?T:x}const q=x.filter(T=>{const P=H[T.id];return P?.url&&!P?.error});return q.length?q:x},[x,M,H,o]),V=m.useMemo(()=>C.map(q=>({type:"rover",rover:q})),[C]),A=m.useMemo(()=>V.map(q=>`r:${q.rover.id}`).join("|"),[V]);m.useEffect(()=>{v(0)},[A]),m.useEffect(()=>{if(!V.length)return;const q=setInterval(()=>{v(T=>(T+1)%V.length)},hJ);return()=>clearInterval(q)},[V.length,A]);const B=V.length?V[p%V.length]:null,k=B?.type==="rover"?B.rover:null,D=!o&&k&&M[k.id]||null,N=o&&k&&H[k.id]||null,j=k&&w[`${k.id}-audio`]||null,E=k&&u[k.id]||null,Z=k?oJ({roverId:k.id,session:t}):null;return l?r.jsx("div",{className:"relative flex h-screen w-screen items-center justify-center bg-black text-slate-200",children:r.jsxs("div",{className:"surface max-w-sm space-y-0.5 p-1 text-center text-sm",children:[r.jsx("p",{className:"text-lg font-semibold text-white",children:"Mini spectator is disabled in lockdown."}),r.jsx("p",{className:"text-slate-300",children:"It will automatically resume once lockdown ends."})]})}):x.length?r.jsxs("div",{className:"relative flex h-screen w-screen overflow-hidden bg-black text-slate-100",children:[r.jsx("section",{className:"relative flex h-full shrink-0 items-center justify-start overflow-hidden bg-black",style:{width:"min(100vw, calc(100vh * 4 / 3))"},children:a?k?r.jsx(sJ,{children:o?r.jsx("div",{className:"relative h-full w-full",children:V.map(q=>{const T=q.rover,P=k?.id===T.id;return r.jsx("div",{className:`absolute inset-0 ${P?"opacity-100":"opacity-0 pointer-events-none"}`,children:r.jsx(N8,{sessionInfo:H[T.id]||null,videoMode:"whep",snapshotFeed:null,audioSessionInfo:P?j:null,forceMute:!P,label:T.name||T.id,sensors:u[T.id]?.sensors||null})},T.id)})}):r.jsx(N8,{sessionInfo:null,videoMode:"snapshot",snapshotFeed:D,audioSessionInfo:j,label:k.name||k.id,sensors:E?.sensors||null})}):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:x.length?"No sources available.":"No active drivers."}):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:"Switching to spectator…"})}),r.jsx("aside",{className:"flex h-full min-w-0 flex-1 flex-col border-l border-slate-800/60 bg-black",children:k?r.jsx(Ts,{rover:k,frame:E,driverLabel:Z,sessionInfo:o?N:null,videoMode:o?"whep":"snapshot",snapshotFeed:o?null:M[k.id]||null,showPreview:!1,variant:"active"}):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:"No active rover."})})]}):r.jsx("div",{className:"relative flex h-screen w-screen overflow-hidden bg-black text-slate-100",children:r.jsx("section",{className:"flex h-full w-full gap-x-3 bg-slate-900 px-0",children:d.length?d.map(q=>r.jsx(Ts,{rover:q,frame:u[q.id]||null,driverLabel:null,sessionInfo:o&&H[q.id]||null,videoMode:o?"whep":"snapshot",snapshotFeed:o?null:M[q.id]||null,showPreview:!0,withDivider:!1},q.id)):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:"No rovers available."})})})}function mJ(){return m.useEffect(()=>{if(typeof window>"u")return;const t=setTimeout(()=>{const a=new URL(window.location.href);a.searchParams.set("refresh",Date.now().toString()),window.location.replace(a.toString())},dJ);return()=>clearTimeout(t)},[]),r.jsxs(r.Fragment,{children:[r.jsx(fJ,{}),r.jsx(Pc,{scale:3})]})}function Uu(t){return String(t?.nickname||t?.socketId?.slice(0,6)||"unknown").trim()}function vJ({roverId:t,session:a}){const l=a?.activeDrivers?.[t]||null;if(!l)return null;const o=(a?.users||[]).find(u=>u.socketId===l);return{socketId:l,label:Uu(o||{socketId:l})}}function pJ({rover:t,frame:a}){return _8({batteryState:t?.batteryState??null,charge:a?.sensors?.batteryChargeMah??null,config:t?.battery??null})}function gJ(t){return t?.available?t.urgentActive?`${t.percentDisplay}% Low`:t.warnActive?`${t.percentDisplay}% Low`:`${t.percentDisplay}%`:"--"}function xJ(t,a){const l=[];return t?.private?.enabled&&t?.private?.open&&l.push("Private"),(a?.urgentActive||a?.warnActive)&&l.push("Low"),l.join(" · ")}function zJ(t){return t<=1?"grid-cols-1":t===2||t===4?"grid-cols-2":"grid-cols-3"}function MJ(...t){return t.filter(Boolean).join(" ")}function bJ({users:t=[]}){const a=m.useRef(null),l=m.useRef(null),o=m.useRef(null),[u,d]=m.useState(!1),p=m.useMemo(()=>t.filter(x=>x?.role!=="spectator").map(Uu).filter(Boolean).sort((x,z)=>x.localeCompare(z)),[t]);m.useEffect(()=>{const x=a.current,z=o.current;if(!x||!z)return;const M=()=>{d(z.scrollWidth>x.clientWidth+4)};M();const y=new ResizeObserver(M);return y.observe(x),y.observe(z),()=>y.disconnect()},[p]),m.useEffect(()=>{const x=l.current;if(!x||!u)return;const z=x.animate([{transform:"translateX(0)"},{transform:"translateX(-50%)"}],{duration:42e3,iterations:1/0,easing:"linear"});return()=>z.cancel()},[u,p]);const g=(p.length?p:["No one online"]).map((x,z)=>r.jsx("span",{className:"shrink-0 px-[1.6vw] font-black tracking-normal text-slate-100",children:x},`${x}-${z}`));return r.jsx("div",{ref:a,className:"relative h-full min-w-0 overflow-hidden border-b border-slate-800/80 bg-black",children:r.jsxs("div",{ref:l,className:MJ("flex h-full w-max items-center whitespace-nowrap text-[clamp(2.5rem,5.3vh,5.8rem)] leading-none"),children:[r.jsx("div",{ref:o,className:"flex h-full items-center",children:g}),u?r.jsx("div",{className:"flex h-full items-center","aria-hidden":"true",children:g}):null]})})}function ac(...t){return t.filter(Boolean).join(" ")}function yJ({rover:t,session:a}){const o={sensors:U4(t?.id,tt,W7)},u=pJ({rover:t,frame:o}),d=vJ({roverId:t?.id,session:a}),p=xJ(t,u),v=gJ(u),g=!!d,x=!!u?.urgentActive,z=!!u?.warnActive,M=!!t?.locked;return r.jsxs("article",{className:ac("relative min-h-0 overflow-hidden border border-slate-800 bg-black",M?"border-red-400 ring-4 ring-red-500/80":"",!M&&g?"ring-2 ring-sky-400/80":"",!M&&x?"ring-4 ring-red-500/90":!M&&z?"ring-2 ring-amber-300/80":""),children:[r.jsx(at,{visual:u,variant:"background",orientation:"vertical"}),r.jsxs("div",{className:"relative z-10 grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)_auto] gap-[0.55vh] p-[0.85vw] text-center",children:[r.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-start gap-[0.8vw]",children:[r.jsx("div",{className:"min-w-0",children:r.jsx(V4,{rover:t,fallback:t?.id,as:d3,className:"leading-none",maxSize:108,minSize:26})}),M?r.jsxs("div",{className:"max-w-[40vw] border-4 border-red-100 bg-red-700 px-[1vw] py-[0.55vh] text-center text-[clamp(2rem,5vh,5.2rem)] font-black leading-none text-white",children:[r.jsx("div",{children:"LOCKED"}),t?.lockReason?r.jsx("div",{className:"mt-[0.35vh] text-[clamp(1.2rem,2.9vh,3rem)] leading-none text-red-50",children:t.lockReason}):null]}):null]}),r.jsxs("div",{className:"grid min-h-0 min-w-0 grid-cols-[minmax(0,1.45fr)_minmax(0,0.85fr)] items-center gap-[1vw]",children:[r.jsx("div",{className:"min-w-0",children:r.jsx(d3,{className:ac("font-black leading-none",g?"text-white":"text-slate-400"),maxSize:172,minSize:38,children:d?.label||"Idle"})}),r.jsx("div",{className:"min-w-0",children:r.jsx(d3,{className:ac("font-black leading-none",x?"text-red-100":z?"text-amber-100":"text-slate-100"),maxSize:136,minSize:32,children:v})})]}),p?r.jsx("div",{className:"min-w-0 text-[clamp(1.25rem,2.5vh,2.6rem)] font-black leading-none text-amber-100",children:p}):r.jsx("div",{"aria-hidden":"true"})]})]})}function CJ({roster:t=[],session:a}){return t.length?r.jsx("section",{className:`grid h-full min-h-0 ${zJ(t.length)} auto-rows-fr gap-0.5 bg-slate-950 p-0.5`,children:t.map(l=>r.jsx(yJ,{rover:l,session:a},l.id))}):r.jsx("section",{className:"flex h-full min-h-0 items-center justify-center border-b border-slate-800 bg-black text-[clamp(2.5rem,7vh,7rem)] font-black text-slate-500",children:"No rovers"})}function wJ(){return r.jsx("section",{className:"h-full min-h-0 overflow-hidden border-t border-slate-800 bg-black",children:r.jsx("div",{className:"origin-top-left",style:{width:`calc(100% / ${4.6})`,height:`calc(100% / ${4.6})`,transform:`scale(${4.6})`},children:r.jsx(U8,{minimal:!0,fillHeight:!0,hideSpectatorNotice:!0})})})}const HJ=4500;function SJ(t={}){const a=String(t?.text||"").trim();if(!a)return null;const l=Number.isFinite(Number(t?.durationMs))?Math.max(1200,Math.min(15e3,Number(t.durationMs))):HJ;return{id:t?.id||`display-notice-${Date.now()}`,text:a,durationMs:l}}function VJ(){const t=q2(),[a,l]=m.useState(null),o=m.useRef(null);return m.useEffect(()=>{function u(){o.current&&(clearTimeout(o.current),o.current=null)}function d(p={}){const v=SJ(p);v&&(u(),l(v),o.current=setTimeout(()=>{l(g=>g?.id===v.id?null:g),o.current=null},v.durationMs))}return t.on("display:notice",d),()=>{u(),t.off("display:notice",d)}},[t]),a?r.jsx("div",{className:"pointer-events-none fixed inset-0 z-[130] flex items-center justify-center bg-black px-[4vw] py-[4vh]",children:r.jsx("div",{className:"max-w-[92vw] border-4 border-cyan-200 bg-slate-950 px-[3vw] py-[2.5vh] text-center",children:r.jsx("div",{className:"whitespace-pre-wrap text-[clamp(3.2rem,11vh,11rem)] font-black leading-[0.95] text-white",children:a.text})})}):null}function AJ(){const{session:t}=C0(),a=h1(u=>u.latestReplay),{clearLatestReplay:l}=$2(),o=t?.mode==="lockdown";return $8(),G8(),it(),o?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-black text-[clamp(2.5rem,8vh,8rem)] font-black text-slate-200",children:"Lockdown"}):r.jsxs("div",{className:"display-page flex h-screen w-screen flex-col overflow-hidden bg-black text-slate-100",children:[r.jsx("div",{className:"h-[8vh] min-h-[4rem] shrink-0",children:r.jsx(bJ,{users:t?.users||[]})}),r.jsx("div",{className:"min-h-0 flex-[0.72]",children:r.jsx(CJ,{roster:t?.roster||[],session:t})}),r.jsx("div",{className:"min-h-0 flex-[1.28]",children:r.jsx(wJ,{})}),r.jsx(VJ,{}),r.jsx(oa,{}),r.jsx(Uc,{replay:a,onClose:l})]})}function LJ(){return r.jsx(AJ,{})}const BJ=1500,jJ=700,NJ=350,FJ="scanner.preferredVoiceName",qs=/female|samantha|victoria|allison|zira|karen|moira|serena|ava|susan|hazel|google (us|uk) english/i,kJ=/whisper|bubbles|bells|boing|bad news|bahh|cellos|deranged|good news|hysterical|pipe organ|trinoids|zarvox/i;function RJ(t){return kJ.test(String(t?.name||""))}function Ds(t){const a=typeof t?.getVoices=="function"?t.getVoices():[];if(!a.length)return null;const l=typeof window<"u"?String(window.localStorage.getItem(FJ)||"").trim():"",o=l?a.find(v=>String(v?.name||"")===l):null;if(o)return o;const u=a.filter(v=>!RJ(v)),d=u.find(v=>v?.default)||null,p=u.filter(v=>String(v?.lang||"").toLowerCase().startsWith("en"));return p.find(v=>qs.test(String(v?.name||"")))||u.find(v=>qs.test(String(v?.name||"")))||d||p[0]||u[0]||null}function EJ(t){return t?t instanceof ArrayBuffer?t:ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):Array.isArray(t)?new Uint8Array(t).buffer:null:null}function TJ(t){const a=EJ(t?.buffer);if(!a)return null;const l=String(t?.mime||"audio/wav").trim()||"audio/wav",o=new Blob([a],{type:l}),u=URL.createObjectURL(o),d=new Audio(u);return d.volume=1,{play:()=>d.play().finally(()=>{d.onended=()=>URL.revokeObjectURL(u)}),stop:()=>{d.pause(),d.removeAttribute("src"),d.load(),URL.revokeObjectURL(u)}}}function qJ(t,a=null){const l=m.useRef(null),o=m.useRef(null),u=m.useRef(null),d=m.useRef(null),p=m.useRef(null);m.useEffect(()=>()=>{window.clearTimeout(l.current),window.clearTimeout(o.current),window.clearTimeout(d.current),p.current?.stop()},[]),m.useEffect(()=>{const v=String(t?.speechText||"").trim(),g=t?.scannedAt?`${t.scannedAt}:${v}`:"";if(!v||!g||u.current===g)return;let x=!1;function z(){window.clearTimeout(l.current),window.clearTimeout(o.current),window.clearTimeout(d.current),l.current=null,o.current=null,d.current=null}function M(){x||(z(),l.current=window.setTimeout(()=>S(),jJ))}function y(){const w=window.speechSynthesis;if(!w||typeof window.SpeechSynthesisUtterance!="function"){M();return}z(),w.cancel();const C=new window.SpeechSynthesisUtterance(v),V=Ds(w);V&&(C.voice=V,C.lang=V.lang),C.rate=1,C.pitch=1,C.volume=1,C.onstart=()=>{window.clearTimeout(o.current),o.current=null},C.onend=()=>{z()},C.onerror=()=>{M()},w.speak(C),o.current=window.setTimeout(()=>{w.cancel(),M()},BJ)}function H(){u.current=g}function S(){x||(H(),z(),p.current?.stop(),y())}return d.current=window.setTimeout(S,NJ),()=>{x=!0,z(),p.current?.stop()}},[t]),m.useEffect(()=>{const v=String(a?.scan?.speechText||"").trim(),g=a?.scan?.scannedAt?`${a.scan.scannedAt}:${v}`:"",x=String(t?.speechText||"").trim(),z=t?.scannedAt?`${t.scannedAt}:${x}`:"";if(!g||g!==z||u.current===g)return;const M=TJ(a.audio);M&&(window.clearTimeout(d.current),d.current=null,u.current=g,p.current?.stop(),p.current=M,M.play().catch(()=>{u.current=g;const y=window.speechSynthesis;if(!y||typeof window.SpeechSynthesisUtterance!="function")return;y.cancel();const H=new window.SpeechSynthesisUtterance(x),S=Ds(y);S&&(H.voice=S,H.lang=S.lang),H.rate=1,H.pitch=1,H.volume=1,y.speak(H)}))},[t,a])}const Os={beepAllowed:!1,lastScan:null,registryError:null};function DJ(){const t=window.AudioContext||window.webkitAudioContext;if(!t)return;const a=new t,l=a.createOscillator(),o=a.createGain(),u=a.currentTime;l.type="square",l.frequency.setValueAtTime(980,u),o.gain.setValueAtTime(1e-4,u),o.gain.exponentialRampToValueAtTime(.95,u+.015),o.gain.exponentialRampToValueAtTime(1e-4,u+.2),l.connect(o),o.connect(a.destination),l.start(u),l.stop(u+.22),l.onended=()=>{a.close().catch(()=>{})}}function OJ(){const t=q2(),a=m.useRef(null),l=m.useRef(null),[o,u]=m.useState(Os),[d,p]=m.useState(null),[v,g]=m.useState(!1);$8(),G8(),it(),qJ(o.lastScan,d);const x=m.useCallback(()=>{a.current?.focus()},[]);m.useEffect(()=>{x()},[x]),m.useEffect(()=>()=>{window.clearTimeout(l.current)},[]),m.useEffect(()=>{function H(w={}){u({...Os,...w&&typeof w=="object"?w:{}})}function S(w=null){p(w&&typeof w=="object"?w:null)}return t.emit("barcode:subscribe",{},()=>{}),t.on("barcode:state",H),t.on("barcode:scanAudio",S),()=>{t.off("barcode:state",H),t.off("barcode:scanAudio",S)}},[t]);const z=m.useCallback(()=>{const H=String(a.current?.value||"").trim();if(!H){x();return}o.beepAllowed&&(window.clearTimeout(l.current),g(!0),l.current=window.setTimeout(()=>{g(!1)},120),DJ()),t.emit("barcode:scan",{code:H},()=>{}),a.current.value="",x()},[x,o.beepAllowed,t]),y=o.lastScan?.label||"waiting";return r.jsxs("main",{className:`flex min-h-screen cursor-default flex-col items-center justify-center overflow-hidden px-6 text-center ${v?"bg-white text-black":"bg-black text-white"}`,onClick:x,children:[r.jsx("input",{ref:a,"aria-label":"barcode scanner input",className:"absolute left-0 top-0 h-px w-px opacity-0",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:H=>{H.key==="Enter"&&(H.preventDefault(),z())}}),r.jsx("section",{className:"flex min-h-screen w-full items-center justify-center",children:r.jsx("h1",{className:"max-w-full break-words text-[18vw] font-black leading-none tracking-normal",children:y})}),r.jsx(Ou,{})]})}function _J(){return r.jsx(OJ,{})}function g7(t){if(!t||!t.length)return null;const a=Math.floor(Math.random()*t.length);return t[a]||null}function UJ(){if(typeof document>"u"||!document.body)return;const t=document.body.getElementsByTagName("*");if(!t||t.length<2)return;const a=g7(t),l=g7(t),o=a?.classList?.[0]||null;if(o&&l?.classList)try{l.classList.add(o)}catch{}const u=g7(t),d=g7(t),p=u?.classList?.[1]||null;if(p&&d?.classList)try{d.classList.add(p)}catch{}}function ZJ(){const t=h1(a=>!!a.session?.moderation?.isDeterred);return m.useEffect(()=>{if(!t)return;const a=window.setInterval(()=>{UJ()},1);return()=>{window.clearInterval(a)}},[t]),null}df.createRoot(document.getElementById("root")).render(r.jsx(m.StrictMode,{children:r.jsx(Dv,{children:r.jsx(Zv,{children:r.jsx(Iv,{children:r.jsx(Yp,{children:r.jsxs(RI,{children:[r.jsx(ZJ,{}),r.jsx(Vm,{children:r.jsxs(nm,{children:[r.jsx(o0,{path:"/",element:r.jsx(KX,{})}),r.jsx(o0,{path:"/spectate",element:r.jsx(iJ,{})}),r.jsx(o0,{path:"/mini",element:r.jsx(mJ,{})}),r.jsx(o0,{path:"/display",element:r.jsx(LJ,{})}),r.jsx(o0,{path:"/scanner",element:r.jsx(_J,{})})]})})]})})})})})})); +fling`;function qX(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""}function DX(){const t=String(TX).split(/\r?\n/).map(l=>l.trim()).filter(Boolean);return t.length?(t[Math.floor(Math.random()*t.length)]||"").trim():""}function $8(){const{setNickname:t}=$2(),{value:a,status:l,save:o}=N1("profile",{nickname:""}),u=m.useRef(!1);m.useEffect(()=>{if(l!=="ready"||u.current||(a.nickname||"").trim())return;u.current=!0;const p=qX(DX()).slice(0,32);if(!p)return;(async()=>{try{await t(p)}catch{}finally{o({nickname:p})}})()},[o,t,l,a.nickname])}function G8(){const t=q2(),a=h1(B=>B.connected),{identifySession:l}=$2(),{value:o,status:u,save:d}=N1("identity",{cookieUserId:""}),{value:p,status:v}=N1("profile",{nickname:""}),{value:g,status:x}=N1("overseerPreference",{enabled:!1}),z=m.useRef(!1),M=m.useRef(null),y=m.useRef(null),H=u==="ready"&&v==="ready"&&x==="ready",S=(o?.cookieUserId||"").trim(),w=(p?.nickname||"").trim(),C=!!g?.enabled,V=m.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null)},[]),A=m.useCallback(async()=>{if(!(!H||!a||!t?.id||z.current)){z.current=!0;try{const k=((await l({cookieUserId:S,nickname:w,overseerEnabled:C}))?.cookieUserId||"").trim();k&&k!==S&&d(D=>({...D||{},cookieUserId:k})),M.current=t.id,V()}catch{V(),y.current=setTimeout(()=>{A()},2e3)}finally{z.current=!1}}},[V,a,S,l,w,C,H,d,t?.id]);m.useEffect(()=>{!H||!a||!t?.id||M.current!==t.id&&A()},[a,H,A,t?.id]),m.useEffect(()=>{!H||!a||!t?.id||A()},[H,a,t?.id,S,w,C,A]),m.useEffect(()=>{const B=()=>{t?.connected&&A()},k=()=>{typeof document>"u"||document.visibilityState!=="visible"||t?.connected&&A()};return window.addEventListener("online",B),document.addEventListener("visibilitychange",k),()=>{window.removeEventListener("online",B),document.removeEventListener("visibilitychange",k)}},[A,t?.connected]),m.useEffect(()=>{if(!H||!t?.connected)return;const B=setInterval(()=>{t?.connected&&A()},6e4);return()=>clearInterval(B)},[H,A,t?.connected]),m.useEffect(()=>()=>V(),[V])}const ec=1e4,cc=28,OX=14;function _X(t){const a=String(t||"").trim(),l=a.startsWith("#")?a.slice(1):a;if(!/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$/.test(l))return null;const o=l.length===3?l.split("").map(u=>u+u).join(""):l;return{r:Number.parseInt(o.slice(0,2),16),g:Number.parseInt(o.slice(2,4),16),b:Number.parseInt(o.slice(4,6),16)}}function Rs(t,a){return`rgba(${t.r}, ${t.g}, ${t.b}, ${a})`}function I7({layout:t="desktop",className:a="",dismissable:l=!0}){const o=h1(k=>{const D=k.session?.globalObjective?.text;return D?String(D).trim():""}),u=h1(k=>{const D=String(k.session?.assignment?.roverId||"").trim();return D&&(Array.isArray(k.session?.roster)?k.session.roster:[]).find(E=>String(E?.id)===D)?.color||null}),d=t==="mobile-portrait"||t==="mobile-landscape"||t==="mobile",[p,v]=m.useState(!1),[g,x]=m.useState(cc),[z,M]=m.useState(0),y=m.useRef(null),H=m.useRef(null),S=m.useRef(null);m.useEffect(()=>{if(!o){v(!1);return}if(v(!0),!d||!l)return;const k=Date.now();M(ec);const D=setTimeout(()=>v(!1),ec),N=setInterval(()=>{const j=Date.now()-k;M(Math.max(0,ec-j))},250);return()=>{clearTimeout(D),clearInterval(N)}},[o,d]),m.useEffect(()=>{if(!o)return;x(cc);let k=0;const D=()=>{const j=S.current,E=H.current;if(!j||!E)return;const Z=j.clientWidth;if(!Z)return;const q=E.scrollWidth;if(!q)return;const T=Math.min(1,Z/q),P=Math.max(OX,Math.floor(cc*T));x(P)};k=window.requestAnimationFrame(D);const N=new ResizeObserver(()=>{window.cancelAnimationFrame(k),k=window.requestAnimationFrame(D)});return y.current&&N.observe(y.current),()=>{window.cancelAnimationFrame(k),N.disconnect()}},[o]);const w=m.useMemo(()=>["panel-section flex w-full items-center justify-center border border-neutral-500/60 shadow-[0_1px_0_rgba(255,255,255,0.05)_inset,0_10px_24px_rgba(0,0,0,0.28)]",d?"rounded-none":"rounded","px-1 py-1 text-center font-semibold tracking-tight",a].filter(Boolean).join(" "),[a,d]),C=_X(u),V=C?{borderColor:Rs(C,.35),backgroundImage:`linear-gradient(90deg, rgba(23,23,23,0.96) 0%, rgba(38,38,38,0.94) 58%, ${Rs(C,.18)} 100%)`}:void 0;if(!o||!p)return null;const A=d?Math.ceil(z/1e3):null,B=l?{onClick:()=>v(!1),role:"button",tabIndex:0}:{};return r.jsx("div",{ref:y,className:w,style:{...V||{},fontSize:`${g}px`,lineHeight:1.1},...B,children:r.jsxs("span",{className:"flex w-full items-stretch gap-0.5 whitespace-nowrap rounded-md",children:[r.jsxs("span",{className:"flex flex-col justify-center border-r border-slate-700/60 px-0.5 text-[0.55em] font-semibold leading-tight text-slate-400",children:[r.jsx("span",{children:"Global"}),r.jsx("span",{children:"Objective"})]}),r.jsx("span",{ref:S,className:"flex-1 overflow-hidden text-slate-100",children:r.jsx("span",{ref:H,className:"block",children:o})}),d?r.jsxs("span",{className:"flex items-center border-l border-slate-700/60 px-0.5 text-[0.55em] font-semibold uppercase tracking-wide text-slate-400",children:[A,"s"]}):null]})})}const UX=3200;function ZX(t={}){const a=typeof t.rewardName=="string"&&t.rewardName.trim()?t.rewardName.trim():"Unknown Event",l=Number.isFinite(Number(t.goal))?Math.max(1,Math.floor(Number(t.goal))):0,o=Number.isFinite(Number(t.count))?Math.max(0,Math.floor(Number(t.count))):l;return{rewardName:a,goal:l,count:o,ts:Date.now()}}function oa(){const t=q2(),{value:a}=N1("audio",p2),l=Number.isFinite(a?.masterVolume)?a.masterVolume:p2.masterVolume,o=Number.isFinite(a?.alertVolume)?a.alertVolume:p2.alertVolume,u=Math.max(0,Math.min(1,l*o)),[d,p]=m.useState(null),v=m.useRef(null);return m.useEffect(()=>{v.current=new Audio("/tada.mp3"),v.current.volume=u,v.current.load()},[u]),m.useEffect(()=>{let g=null;function x(){const y=v.current;y&&(y.volume=u,y.currentTime=0,y.play().catch(()=>{}))}function z(y={}){const H=ZX(y);p(H),x(),g&&clearTimeout(g),g=setTimeout(()=>{p(null)},UX)}function M(y){z(y?.detail||{})}return t.on("buttonBox:rewardRun",z),window.addEventListener("buttonBox:rewardRunLocalTest",M),()=>{g&&clearTimeout(g),t.off("buttonBox:rewardRun",z),window.removeEventListener("buttonBox:rewardRunLocalTest",M)}},[u,t]),d?r.jsx("div",{className:"pointer-events-none fixed inset-0 z-[120] flex items-center justify-center bg-black/75 px-1 py-1",children:r.jsx("div",{className:"pointer-events-auto w-full max-w-2xl",children:r.jsx("div",{className:"surface rounded-none border-2 border-cyan-300 bg-amber-100/95 px-1 py-1 text-center text-black shadow-2xl",children:r.jsxs("div",{className:"flex items-center justify-center gap-1 border-2 border-blue-600 bg-yellow-100 px-0.5 py-1",children:[r.jsx("img",{src:"/party1.gif",alt:"",className:"hidden shrink-0 sm:block"}),r.jsxs("div",{children:[r.jsxs("p",{className:"font-mono text-2xl font-bold text-red-700 sm:text-3xl",children:["Running event: ",d.rewardName,"!"]}),r.jsxs("p",{className:"font-mono text-xl font-bold text-blue-800 sm:text-2xl",children:[d.count,"/",d.goal]})]}),r.jsx("img",{src:"/party2.gif",alt:"",className:"hidden shrink-0 sm:block"})]})})})}):null}const $X=4e3;function Es(...t){return t.filter(Boolean).join(" ")}function Ou(){const t=q2(),[a,l]=m.useState(!!t?.connected),[o,u]=m.useState(""),[d,p]=m.useState(!0),[v,g]=m.useState(!1),x=m.useRef(null);m.useEffect(()=>{const S=()=>{x.current&&(clearTimeout(x.current),x.current=null)},w=()=>{S(),p(!0),g(!1)},C=()=>{S(),x.current=setTimeout(()=>{g(!0)},$X)},V=()=>{l(!0),u(""),w(),C()},A=D=>{l(!1),u(typeof D=="string"?D:"disconnected"),w()},B=D=>{l(!1),u(D?.message||"connect error"),w()},k=()=>{l(!1),w()};return t.on("connect",V),t.on("disconnect",A),t.on("connect_error",B),t.io.on("reconnect_attempt",k),t.connected&&C(),()=>{S(),t.off("connect",V),t.off("disconnect",A),t.off("connect_error",B),t.io.off("reconnect_attempt",k)}},[t]);const z=typeof navigator<"u"?navigator.onLine===!1:!1,M=a?"Connected to socket.io":z?"Offline":"Reconnecting...",y=a?"":o,H=a?"bg-emerald-700 text-emerald-100":z?"bg-red-800 text-red-100":"bg-amber-800 text-amber-100";return r.jsx("div",{className:Es("fixed bottom-2 left-2 z-[120] transition-opacity duration-500",!d&&"hidden",v?"opacity-0 pointer-events-none":"opacity-100"),"aria-live":"polite",children:r.jsxs("div",{className:Es("rounded-sm px-2 py-1 text-xs",H),children:[r.jsx("span",{className:"font-semibold",children:M}),y?r.jsxs("span",{className:"ml-1 opacity-85",children:["(",y,")"]}):null]})})}function GX(){const[t,a]=m.useState(()=>typeof window>"u"||window.innerWidth>=1024?"desktop":window.innerWidth>window.innerHeight?"mobile-landscape":"mobile-portrait");return m.useEffect(()=>{function l(){if(typeof window>"u")return;const{innerWidth:o,innerHeight:u}=window;o>=1024?a("desktop"):o>u?a("mobile-landscape"):a("mobile-portrait")}return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]),t}function PX({layout:t,onOpenHelpOverlay:a}){return r.jsxs("div",{className:`flex h-full ${C2} overflow-hidden`,children:[r.jsxs("div",{className:`flex min-w-0 flex-[1.22] flex-col ${C2} overflow-y-auto pr-0`,children:[r.jsx(ea,{}),r.jsx(_p,{}),r.jsx(pp,{})]}),r.jsxs("div",{className:`flex min-w-0 flex-1 flex-col ${C2} overflow-y-auto`,children:[r.jsx(I7,{layout:t}),r.jsx(zX,{layout:t,onOpenHelpOverlay:a})]})]})}function _u({layout:t,onOpenHelpOverlay:a,roomPanelId:l}){const[o,u]=m.useState("chat"),d=h1(w=>!!w.session?.isVerified),p=h1(w=>String(w.session?.assignment?.roverId||"").trim()),v=h1(w=>{const C=String(w.session?.assignment?.roverId||"").trim();return C&&w.session?.audioForward?.[C]||null}),g=R1(w=>!!w.state.mic?.pttActive),{value:x}=N1("vipAudio",{openMicEnabled:!1,pttMode:"live"}),z=d?"bg-emerald-400":"bg-amber-400",M=!!x?.openMicEnabled,y=x?.pttMode==="clip"?"clip":"live",H=!!(p&&d&&(y==="clip"?g:M||g)),S=!!(p&&d&&y==="clip"&&v?.source==="upload"&&v?.state==="playing");return r.jsx("section",{className:"text-base",children:r.jsxs(la,{defaultTab:"chat",currentTab:o,onTabChange:u,children:[r.jsxs(ra,{children:[r.jsx(I2,{id:"chat",children:"Chat"}),r.jsx(I2,{id:"activities",children:"Activities"}),r.jsx(I2,{id:"vip",highlight:S?"green":H?"pink":"none",children:r.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[r.jsx("span",{children:"VIP"}),r.jsx("span",{className:`inline-block h-1.5 w-1.5 rounded-full ${z}`,"aria-hidden":"true",title:d?"Verified":"Not verified"})]})}),r.jsx(I2,{id:"roomcontrols",children:"Room Controls"}),r.jsx(I2,{id:"help",children:"Help"}),r.jsx(I2,{id:"settings",children:"Settings"})]}),r.jsxs(ia,{children:[r.jsx(Y2,{id:"chat",children:r.jsxs("div",{className:v6,children:[r.jsx(U8,{nicknameLayout:"stacked"}),r.jsxs("div",{className:v6,children:[r.jsx("div",{className:`grid ${C2} md:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]`,children:r.jsx(sa,{})}),r.jsxs("div",{className:`grid ${C2} grid-cols-[minmax(0,1fr)_minmax(0,1fr)]`,children:[r.jsx(Du,{}),r.jsx(G7,{hideNicknameForm:!0})]})]})]})}),r.jsx(Y2,{id:"activities",children:r.jsxs("div",{className:`flex flex-col ${C2}`,children:[r.jsx(P7,{}),r.jsx(pu,{})]})}),r.jsx(Y2,{id:"vip",keepMounted:!0,children:r.jsx(qu,{isActive:o==="vip"})}),r.jsx(Y2,{id:"roomcontrols",children:r.jsxs("div",{className:v6,children:[r.jsx(Vu,{}),r.jsx(Wc,{panelId:l})]})}),r.jsx(Y2,{id:"help",children:r.jsx(Eu,{layout:t,onOpenOverlay:a})}),r.jsx(Y2,{id:"settings",children:r.jsx("div",{className:v6,children:r.jsx(Fu,{})})})]})]})})}function IX({onOpenHelpOverlay:t,swapMobileControlColumns:a=!1}){const l="h-[min(60svh,24rem)]",o=a?r.jsx(Z7,{layout:"portrait",className:l}):r.jsx(U7,{layout:"portrait",className:l}),u=a?r.jsx(U7,{layout:"portrait",className:l}):r.jsx(Z7,{layout:"portrait",className:l});return r.jsxs("div",{className:`flex flex-col ${C2}`,children:[r.jsx(ea,{layoutFormat:"mobile-portrait"}),r.jsx("section",{className:"mobile-touch-control text-white",children:r.jsxs("div",{className:"mobile-touch-control grid grid-cols-2 gap-0.5 items-stretch",children:[o,u]})}),r.jsxs("div",{className:`grid ${C2} grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[r.jsx(Zc,{panelId:"replay-sources-mobile-portrait"}),r.jsx(rt,{})]}),r.jsx(_u,{layout:"mobile-portrait",onOpenHelpOverlay:t,roomPanelId:"mobile-portrait-room"})]})}function YX({onOpenHelpOverlay:t,swapMobileControlColumns:a=!1}){const l="self-start h-[min(100svh,32rem)]",o=a?r.jsx(Z7,{layout:"landscape",className:l}):r.jsx(U7,{layout:"landscape",className:l}),u=a?r.jsx(U7,{layout:"landscape",className:l}):r.jsx(Z7,{layout:"landscape",className:l});return r.jsxs("div",{className:`flex flex-col ${C2}`,children:[r.jsxs("section",{className:`grid min-h-screen grid-cols-[minmax(0,0.7fr)_minmax(0,2.1fr)_minmax(0,0.7fr)] ${C2}`,children:[o,r.jsxs("div",{children:[r.jsx(ea,{layoutFormat:"mobile-landscape"}),r.jsxs("div",{className:`grid ${C2} grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[r.jsx(Zc,{panelId:"replay-sources-mobile-landscape"}),r.jsx(rt,{})]})]}),u]}),r.jsx("div",{className:`flex flex-col ${C2} pb-0`,children:r.jsx(_u,{layout:"mobile-landscape",onOpenHelpOverlay:t,roomPanelId:"mobile-landscape-room"})})]})}function KX(){const t=GX(),a=t==="desktop",l=NX(t);return r.jsxs("div",{className:`${oQ} text-slate-100 ${a?"h-screen overflow-hidden":"ios-safe-screen min-h-screen"}`,children:[r.jsx("script",{defer:!0,src:"https://analytics.otter.land/script.js","data-website-id":"82dd56a5-db44-4279-bd1e-a4d9fee39af7"}),r.jsx("script",{defer:!0,src:"https://analytics.otter.land/recorder.js","data-website-id":"82dd56a5-db44-4279-bd1e-a4d9fee39af7","data-sample-rate":"0.4","data-mask-level":"moderate","data-max-duration":"300000"}),r.jsx(QX,{layout:t,isDesktop:a,fullscreen:l})]})}function QX({layout:t,isDesktop:a,fullscreen:l}){$8(),G8(),Kv({mobile:!a});const{visible:o,mode:u,isIOS:d,nativeSupported:p,enterFullscreen:v,dismiss:g,showPrompt:x}=l,{value:z,save:M}=N1("help",{showOnLoad:!0}),{value:y,status:H,save:S}=N1("quickstart",{showOnLoad:!0}),{value:w}=N1("page",{swapMobileControlColumns:!1}),C=!!w?.swapMobileControlColumns,V=C?"left":"right",A=!a&&(d||p),[B,k]=m.useState(!1),[D,N]=m.useState(!1);m.useEffect(()=>{H==="ready"&&N(y?.showOnLoad!==!1)},[H,y?.showOnLoad]);const j=m.useCallback(()=>k(!0),[]),E=m.useCallback(()=>k(!1),[]),Z=m.useCallback(()=>N(!1),[]),q=m.useCallback(async()=>{if(d){x();return}await v()||x()},[v,d,x]),T=m.useCallback(n1=>{const I=!!n1;S(R=>({...R??{},showOnLoad:I})),I||N(!1)},[S]),P=m.useCallback(()=>{N(!1),k(!0)},[]),o1=m.useMemo(()=>a?r.jsx(PX,{layout:t,onOpenHelpOverlay:j}):t==="mobile-landscape"?r.jsx(YX,{onOpenHelpOverlay:j,swapMobileControlColumns:C}):r.jsx(IX,{onOpenHelpOverlay:j,swapMobileControlColumns:C}),[a,t,j,C]);return r.jsxs(NI,{children:[r.jsx(II,{}),r.jsx(lY,{}),r.jsxs("main",{className:`flex w-full flex-col ${C2} text-base ${a?"h-full overflow-hidden":""}`,children:[a?null:r.jsx(I7,{layout:t}),o1]}),r.jsx(Pc,{}),r.jsx(oa,{}),r.jsx(VX,{}),r.jsx(wX,{}),r.jsx(Ou,{}),r.jsx(FX,{visible:B,layout:t,onClose:E,showOnLoad:z?.showOnLoad!==!1,onToggleShowOnLoad:n1=>M(I=>({...I??{},showOnLoad:!!n1}))}),r.jsx(AX,{visible:o,mode:u,onEnterFullscreen:v,onDismiss:g}),r.jsx(EX,{visible:D,layout:t,showOnLoad:y?.showOnLoad!==!1,onToggleShowOnLoad:T,onOpenHelp:P,onClose:Z}),A?r.jsx(LX,{side:V,onClick:q}):null]})}function it(){const{session:t,setRole:a,subscribeAll:l,connected:o}=C0(),[u,d]=m.useState(!1);return m.useEffect(()=>{let p=!1;async function v(){if(t?.mode==="lockdown"){d(!1);return}try{t?.role!=="spectator"&&await a("spectator"),await l(),p||d(!0)}catch(g){console.error("Failed to enter spectator mode",g),p||d(!1)}}return v(),()=>{p=!0}},[o,t?.mode,t?.role,a,l]),u}function XX(){const[t,a]=m.useState(()=>typeof window>"u"?!1:window.matchMedia("(max-aspect-ratio: 4/3)").matches);return m.useEffect(()=>{if(typeof window>"u")return;const l=window.matchMedia("(max-aspect-ratio: 4/3)"),o=u=>a(u.matches);return l.addEventListener?l.addEventListener("change",o):l.addListener(o),()=>{l.removeEventListener?l.removeEventListener("change",o):l.removeListener(o)}},[]),t}function JX({show:t=!1,roverId:a=null,sensors:l,batteryConfig:o,mobileHud:u=!1}){const d=U4(a,tt,W7),p=h1(z=>a?(z.session?.roster||[]).find(H=>String(H.id)===String(a))?.battery??null:null),v=l?{batteryChargeMah:l?.batteryChargeMah??null,batteryCapacityMah:l?.batteryCapacityMah??null}:d,g=o??p,x=_8({charge:v?.batteryChargeMah??null,config:g});return!t||!x?.available?null:r.jsx("div",{className:"pointer-events-none absolute right-1 top-1/2 flex h-[70%] -translate-y-1/2 flex-col items-center justify-center rounded bg-black/60 px-0.5 pb-1 pt-1",children:r.jsx(at,{visual:x,orientation:"vertical",variant:"inline",compact:u,className:"h-full w-4"})})}const WX=w2.memo(JX);function tJ({roverId:t=null,label:a,fitParent:l=!1,layoutFormat:o="desktop"}){return r.jsx("div",{className:`flex flex-col gap-0.5 ${l?"h-full":""}`,children:r.jsxs("div",{className:`relative w-full overflow-hidden bg-black ${l?"h-full flex-1":"aspect-[4/3]"}`,children:[r.jsx(N8,{roverId:t,label:a}),r.jsx(Cu,{roverId:t,variant:"spectator",mobileHud:!1}),r.jsx(yu,{roverId:t,layoutFormat:o,variant:"spectator",mobileHud:!1,labelScale:1}),r.jsx(wu,{roverId:t,compact:!1}),r.jsx(Hu,{roverId:t,compact:!1}),r.jsx(WX,{show:!0,roverId:t,mobileHud:!1})]})})}function eJ({rover:t}){return r.jsx("article",{className:"min-h-[16rem] rounded bg-zinc-900 p-0 sm:min-h-[18rem]",children:r.jsx("div",{className:"min-h-0 overflow-hidden rounded bg-black/20",children:r.jsx(tJ,{roverId:t.id,label:t.name})})})}function cJ({roster:t}){return t.length===0?r.jsx("p",{className:"col-span-full text-slate-400",children:"No rovers registered."}):r.jsx("section",{className:"grid grid-cols-1 gap-0.5 md:grid-cols-2",children:t.map(a=>r.jsx(eJ,{rover:a},a.id))})}function aJ(){return r.jsx("section",{className:"min-h-0",children:r.jsx("div",{className:"surface min-h-[14rem] overflow-hidden",children:r.jsx(Wc,{defaultOrientation:"horizontal",hideLayoutToggle:!0,hideHeader:!0,panelId:"spectator-secondary"})})})}function nJ(){const t=q2(),a=h1(o=>o.logs),l=m.useMemo(()=>a.slice().reverse(),[a]);return m.useEffect(()=>{const o=()=>{t.emit("log:subscribe")};return o(),t.on("connect",o),()=>{t.off("connect",o),t.emit("log:unsubscribe")}},[t]),r.jsx(B1,{title:"Server logs",bodyClassName:"space-y-0.5 text-base",children:r.jsx("div",{className:"surface h-64 overflow-y-auto font-mono text-xs",children:a.length===0?r.jsx("p",{children:"No logs yet."}):l.map(o=>r.jsxs("div",{className:"surface",children:[r.jsx("span",{className:"text-amber-400",children:o.timestamp})," ",r.jsxs("span",{className:"text-lime-400",children:["[",o.level,"]"]})," ",o.label&&r.jsxs("span",{className:"text-teal-400",children:["[",o.label,"]"]})," ",r.jsx("span",{children:o.message})]},o.id))})})}function lJ({className:t=""}){return r.jsx("div",{className:`panel ${t}`,children:r.jsx(nJ,{})})}function rJ(){const{session:t}=C0(),a=h1(M=>M.latestReplay),{clearLatestReplay:l}=$2(),o=t?.mode==="lockdown";$8(),G8(),it();const u=XX(),d=t?.roster??[];if(o)return r.jsx("div",{className:"flex min-h-screen items-center justify-center bg-black text-slate-200",children:r.jsxs("div",{className:"surface max-w-md space-y-0.5 p-1 text-center text-sm",children:[r.jsx("p",{className:"text-lg font-semibold text-white",children:"Spectate disabled during lockdown."}),r.jsx("p",{className:"text-slate-300",children:"Please wait until the server leaves lockdown to view streams."})]})});const p=u?"flex min-h-screen flex-col bg-black text-slate-100 md:h-screen md:overflow-hidden":"grid min-h-screen grid-cols-1 gap-0.5 bg-black text-slate-100 md:h-full md:min-h-0 md:grid-cols-[minmax(0,1fr)_18rem] lg:grid-cols-[minmax(0,1fr)_20rem]",v=u?"order-2 flex min-h-0 min-w-0 flex-1 flex-col gap-0.5 overflow-y-auto":"order-1 flex min-h-0 min-w-0 flex-col gap-0.5 md:overflow-y-auto",g=u?"order-1 grid w-full min-h-0 items-stretch gap-0.5 border-b border-slate-800/60 bg-slate-950/90 p-0.5 grid-cols-[minmax(0,1fr)_minmax(0,0.7fr)_minmax(0,1.9fr)_minmax(0,0.7fr)]":"order-2 flex min-h-0 min-w-0 flex-col gap-0.5 border-l border-slate-800/60 bg-slate-950/90 md:h-full md:overflow-y-auto",x="",z=u?"h-64":"";return r.jsxs("div",{className:"min-h-screen bg-black text-slate-100 md:h-screen md:overflow-hidden",children:[r.jsxs("main",{className:p,children:[r.jsxs("section",{className:g,children:[u?r.jsxs("div",{className:`${x} ${z} flex flex-col gap-0.5`,children:[r.jsx(I7,{layout:"desktop",dismissable:!1,className:"text-sm"}),r.jsx(P7,{}),r.jsx("div",{className:"min-h-0 flex-1",children:r.jsx(G7,{hideNicknameForm:!0,hideHeader:!0,compact:!0,fillHeight:!0,className:"h-full"})})]}):r.jsxs("div",{className:x,children:[r.jsx(I7,{layout:"desktop",dismissable:!1,className:"text-sm"}),r.jsx(P7,{})]}),r.jsx("div",{className:`${x} ${u?`${z} overflow-y-auto`:""}`,children:r.jsx("div",{className:"panel h-full",children:r.jsx(rt,{title:"Rovers"})})}),u?null:r.jsx("div",{className:`${x} flex-1 min-h-0`,children:r.jsx(G7,{hideNicknameForm:!0,hideHeader:!0,compact:!0,fillHeight:!0,className:"h-full"})}),r.jsx("div",{className:`${x} ${u?z:"flex-[1.1] min-h-0"}`,children:r.jsx(U8,{allowSpectatorInput:!0,hideSpectatorNotice:!0,fillHeight:!0})}),r.jsx("div",{className:`${x} ${u?z:""}`,children:r.jsx(lJ,{className:`${u?"h-full":"h-40"} overflow-hidden`})})]}),r.jsxs("section",{className:v,children:[r.jsx(cJ,{roster:d}),r.jsx(aJ,{})]})]}),r.jsx(Pc,{}),r.jsx(oa,{}),r.jsx(Uc,{replay:a,onClose:l})]})}function iJ(){return r.jsx(rJ,{})}function sJ({children:t}){return r.jsx("div",{className:"flex h-full w-full items-center justify-start overflow-hidden bg-black",children:r.jsx("div",{className:"relative flex items-center justify-center overflow-hidden bg-black",style:{width:"min(100%, calc(100vh * 4 / 3))",height:"min(100%, calc(100vw * 3 / 4))",maxWidth:"100%",maxHeight:"100%",aspectRatio:"4 / 3"},children:r.jsx("div",{className:"flex h-full w-full items-center justify-center overflow-hidden",children:t})})})}function oJ({roverId:t,session:a}){const l=a?.activeDrivers?.[t]||null,u=(a?.users||[]).find(v=>v.socketId===l)?.nickname||(l?l.slice(0,6):"No driver"),d=a?.mode,p=a?.turnQueues?.[t];return d==="turns"&&p?.current?`${u}`:u}function uJ({rover:t,frame:a}){const l=a?.sensors?.batteryChargeMah??null,o=t?.battery??null;return _8({batteryState:t?.batteryState??null,charge:l,config:o})}function d3({children:t,className:a="",maxSize:l=1e3,minSize:o=14,style:u=void 0}){const d=m.useRef(null),p=m.useRef(null),[v,g]=m.useState(l);return m.useLayoutEffect(()=>{const x=d.current,z=p.current;if(!x||!z)return;let M=null;const y=()=>{const w=x.clientWidth;if(!w){H();return}let C=o,V=l,A=o;for(;C<=V;){const B=Math.floor((C+V)/2);z.style.fontSize=`${B}px`,z.scrollWidth<=w?(A=B,C=B+1):V=B-1}g(A)},H=()=>{M&&cancelAnimationFrame(M),M=requestAnimationFrame(y)};H();const S=new ResizeObserver(H);return S.observe(x),()=>{M&&cancelAnimationFrame(M),S.disconnect()}},[t,l,o]),r.jsx("div",{ref:d,className:"w-full min-w-0",children:r.jsx("div",{ref:p,className:`whitespace-nowrap ${a}`,style:{fontSize:`${v}px`,lineHeight:1.1,...u||{}},children:t})})}function Ts({rover:t,frame:a,driverLabel:l,sessionInfo:o,videoMode:u="snapshot",snapshotFeed:d,withDivider:p=!1,showPreview:v=!0,variant:g="stacked"}){const x=uJ({rover:t,frame:a}),z=x?.available?x.percentDisplay:null,M=g==="active";return r.jsxs("div",{className:`relative flex min-w-0 flex-1 flex-col gap-4 overflow-hidden bg-black px-0 py-0 ${p?"border-r border-slate-700/60":""}`,children:[r.jsx(at,{visual:x,orientation:M?"vertical":"horizontal",variant:"background"}),M?r.jsxs("div",{className:"relative z-10 flex min-w-0 flex-1 flex-col justify-between text-center",children:[r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(V4,{rover:t,fallback:t.id,as:d3,className:"leading-none",maxSize:1e3,minSize:18})}),l?r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:1e3,minSize:16,children:l})}):r.jsx("div",{}),r.jsx("div",{className:"relative min-w-0 overflow-hidden bg-transparent px-0 py-0 leading-none",children:r.jsx("div",{className:"relative",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:1e3,minSize:16,children:z==null?"--%":`${z}%`})})})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"relative z-10 flex min-w-0 flex-col gap-1 text-center",children:[r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(V4,{rover:t,fallback:t.id,as:d3,className:"leading-none",maxSize:1e3,minSize:18})}),l?r.jsx("div",{className:"min-w-0 bg-transparent px-0 py-0 leading-none",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:1e3,minSize:16,children:l})}):null,r.jsx("div",{className:"relative min-w-0 overflow-hidden bg-transparent px-0 py-0 leading-none",children:r.jsx("div",{className:"relative",children:r.jsx(d3,{className:"font-semibold leading-none text-white",maxSize:80,minSize:16,children:z==null?"--%":`${z}%`})})})]}),r.jsx("div",{className:"relative z-10 flex min-w-0 flex-1 flex-col gap-4",children:r.jsx("div",{className:"flex w-full min-w-0 flex-1 flex-col items-center gap-4",children:v?r.jsx("div",{className:"mt-auto w-full",children:r.jsx("div",{className:"w-full aspect-[4/3]",children:r.jsx(N8,{sessionInfo:o,videoMode:u,snapshotFeed:d,audioSessionInfo:null,label:t.name||t.id,sensors:a?.sensors||null})})}):null})})]})]})}const hJ=2e4,dJ=3600*1e3;function fJ(){const{session:t}=C0(),a=it();$8(),G8();const l=t?.mode==="lockdown",o=!!t?.isLocalNetwork,u=Yv(),d=t?.roster??[],[p,v]=m.useState(0),g=t?.activeDrivers||{},x=m.useMemo(()=>d.filter(q=>g[q.id]),[d,g]),z=x.length?x:d,M=gu(z.map(q=>q.id),{enabled:!l&&!o,version:t?.mode}),y=m.useMemo(()=>o?z.map(q=>({type:"rover",id:q.id,key:q.id})):[],[o,z]),H=yc(y,{enabled:!l&&o,version:t?.mode}),S=m.useMemo(()=>x.flatMap(q=>{if(!q?.id||!q.media?.audioPublishUrl)return[];const T=String(q.id);return[{type:"rover",id:`${T}-audio`,key:`${T}-audio`}]}),[x]),w=yc(S,{enabled:!l,version:t?.mode}),C=m.useMemo(()=>{if(!x.length)return[];if(!o){const T=x.filter(P=>M[P.id]?.objectUrl);return T.length?T:x}const q=x.filter(T=>{const P=H[T.id];return P?.url&&!P?.error});return q.length?q:x},[x,M,H,o]),V=m.useMemo(()=>C.map(q=>({type:"rover",rover:q})),[C]),A=m.useMemo(()=>V.map(q=>`r:${q.rover.id}`).join("|"),[V]);m.useEffect(()=>{v(0)},[A]),m.useEffect(()=>{if(!V.length)return;const q=setInterval(()=>{v(T=>(T+1)%V.length)},hJ);return()=>clearInterval(q)},[V.length,A]);const B=V.length?V[p%V.length]:null,k=B?.type==="rover"?B.rover:null,D=!o&&k&&M[k.id]||null,N=o&&k&&H[k.id]||null,j=k&&w[`${k.id}-audio`]||null,E=k&&u[k.id]||null,Z=k?oJ({roverId:k.id,session:t}):null;return l?r.jsx("div",{className:"relative flex h-screen w-screen items-center justify-center bg-black text-slate-200",children:r.jsxs("div",{className:"surface max-w-sm space-y-0.5 p-1 text-center text-sm",children:[r.jsx("p",{className:"text-lg font-semibold text-white",children:"Mini spectator is disabled in lockdown."}),r.jsx("p",{className:"text-slate-300",children:"It will automatically resume once lockdown ends."})]})}):x.length?r.jsxs("div",{className:"relative flex h-screen w-screen overflow-hidden bg-black text-slate-100",children:[r.jsx("section",{className:"relative flex h-full shrink-0 items-center justify-start overflow-hidden bg-black",style:{width:"min(100vw, calc(100vh * 4 / 3))"},children:a?k?r.jsx(sJ,{children:o?r.jsx("div",{className:"relative h-full w-full",children:V.map(q=>{const T=q.rover,P=k?.id===T.id;return r.jsx("div",{className:`absolute inset-0 ${P?"opacity-100":"opacity-0 pointer-events-none"}`,children:r.jsx(N8,{sessionInfo:H[T.id]||null,videoMode:"whep",snapshotFeed:null,audioSessionInfo:P?j:null,forceMute:!P,label:T.name||T.id,sensors:u[T.id]?.sensors||null})},T.id)})}):r.jsx(N8,{sessionInfo:null,videoMode:"snapshot",snapshotFeed:D,audioSessionInfo:j,label:k.name||k.id,sensors:E?.sensors||null})}):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:x.length?"No sources available.":"No active drivers."}):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:"Switching to spectator…"})}),r.jsx("aside",{className:"flex h-full min-w-0 flex-1 flex-col border-l border-slate-800/60 bg-black",children:k?r.jsx(Ts,{rover:k,frame:E,driverLabel:Z,sessionInfo:o?N:null,videoMode:o?"whep":"snapshot",snapshotFeed:o?null:M[k.id]||null,showPreview:!1,variant:"active"}):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:"No active rover."})})]}):r.jsx("div",{className:"relative flex h-screen w-screen overflow-hidden bg-black text-slate-100",children:r.jsx("section",{className:"flex h-full w-full gap-x-3 bg-slate-900 px-0",children:d.length?d.map(q=>r.jsx(Ts,{rover:q,frame:u[q.id]||null,driverLabel:null,sessionInfo:o&&H[q.id]||null,videoMode:o?"whep":"snapshot",snapshotFeed:o?null:M[q.id]||null,showPreview:!0,withDivider:!1},q.id)):r.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-slate-500",children:"No rovers available."})})})}function mJ(){return m.useEffect(()=>{if(typeof window>"u")return;const t=setTimeout(()=>{const a=new URL(window.location.href);a.searchParams.set("refresh",Date.now().toString()),window.location.replace(a.toString())},dJ);return()=>clearTimeout(t)},[]),r.jsxs(r.Fragment,{children:[r.jsx(fJ,{}),r.jsx(Pc,{scale:3})]})}function Uu(t){return String(t?.nickname||t?.socketId?.slice(0,6)||"unknown").trim()}function vJ({roverId:t,session:a}){const l=a?.activeDrivers?.[t]||null;if(!l)return null;const o=(a?.users||[]).find(u=>u.socketId===l);return{socketId:l,label:Uu(o||{socketId:l})}}function pJ({rover:t,frame:a}){return _8({batteryState:t?.batteryState??null,charge:a?.sensors?.batteryChargeMah??null,config:t?.battery??null})}function gJ(t){return t?.available?t.urgentActive?`${t.percentDisplay}% Low`:t.warnActive?`${t.percentDisplay}% Low`:`${t.percentDisplay}%`:"--"}function xJ(t,a){const l=[];return t?.private?.enabled&&t?.private?.open&&l.push("Private"),(a?.urgentActive||a?.warnActive)&&l.push("Low"),l.join(" · ")}function zJ(t){return t<=1?"grid-cols-1":t===2||t===4?"grid-cols-2":"grid-cols-3"}function MJ(...t){return t.filter(Boolean).join(" ")}function bJ({users:t=[]}){const a=m.useRef(null),l=m.useRef(null),o=m.useRef(null),[u,d]=m.useState(!1),p=m.useMemo(()=>t.filter(x=>x?.role!=="spectator").map(Uu).filter(Boolean).sort((x,z)=>x.localeCompare(z)),[t]);m.useEffect(()=>{const x=a.current,z=o.current;if(!x||!z)return;const M=()=>{d(z.scrollWidth>x.clientWidth+4)};M();const y=new ResizeObserver(M);return y.observe(x),y.observe(z),()=>y.disconnect()},[p]),m.useEffect(()=>{const x=l.current;if(!x||!u)return;const z=x.animate([{transform:"translateX(0)"},{transform:"translateX(-50%)"}],{duration:42e3,iterations:1/0,easing:"linear"});return()=>z.cancel()},[u,p]);const g=(p.length?p:["No one online"]).map((x,z)=>r.jsx("span",{className:"shrink-0 px-[1.6vw] font-black tracking-normal text-slate-100",children:x},`${x}-${z}`));return r.jsx("div",{ref:a,className:"relative h-full min-w-0 overflow-hidden border-b border-slate-800/80 bg-black",children:r.jsxs("div",{ref:l,className:MJ("flex h-full w-max items-center whitespace-nowrap text-[clamp(2.5rem,5.3vh,5.8rem)] leading-none"),children:[r.jsx("div",{ref:o,className:"flex h-full items-center",children:g}),u?r.jsx("div",{className:"flex h-full items-center","aria-hidden":"true",children:g}):null]})})}function ac(...t){return t.filter(Boolean).join(" ")}function yJ({rover:t,session:a}){const o={sensors:U4(t?.id,tt,W7)},u=pJ({rover:t,frame:o}),d=vJ({roverId:t?.id,session:a}),p=xJ(t,u),v=gJ(u),g=!!d,x=!!u?.urgentActive,z=!!u?.warnActive,M=!!t?.locked;return r.jsxs("article",{className:ac("relative min-h-0 overflow-hidden border border-slate-800 bg-black",M?"border-red-400 ring-4 ring-red-500/80":"",!M&&g?"ring-2 ring-sky-400/80":"",!M&&x?"ring-4 ring-red-500/90":!M&&z?"ring-2 ring-amber-300/80":""),children:[r.jsx(at,{visual:u,variant:"background",orientation:"vertical"}),r.jsxs("div",{className:"relative z-10 grid h-full min-h-0 grid-rows-[auto_minmax(0,1fr)_auto] gap-[0.55vh] p-[0.85vw] text-center",children:[r.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-start gap-[0.8vw]",children:[r.jsx("div",{className:"min-w-0",children:r.jsx(V4,{rover:t,fallback:t?.id,as:d3,className:"leading-none",maxSize:108,minSize:26})}),M?r.jsxs("div",{className:"max-w-[40vw] border-4 border-red-100 bg-red-700 px-[1vw] py-[0.55vh] text-center text-[clamp(2rem,5vh,5.2rem)] font-black leading-none text-white",children:[r.jsx("div",{children:"LOCKED"}),t?.lockReason?r.jsx("div",{className:"mt-[0.35vh] text-[clamp(1.2rem,2.9vh,3rem)] leading-none text-red-50",children:t.lockReason}):null]}):null]}),r.jsxs("div",{className:"grid min-h-0 min-w-0 grid-cols-[minmax(0,1.45fr)_minmax(0,0.85fr)] items-center gap-[1vw]",children:[r.jsx("div",{className:"min-w-0",children:r.jsx(d3,{className:ac("font-black leading-none",g?"text-white":"text-slate-400"),maxSize:172,minSize:38,children:d?.label||"Idle"})}),r.jsx("div",{className:"min-w-0",children:r.jsx(d3,{className:ac("font-black leading-none",x?"text-red-100":z?"text-amber-100":"text-slate-100"),maxSize:136,minSize:32,children:v})})]}),p?r.jsx("div",{className:"min-w-0 text-[clamp(1.25rem,2.5vh,2.6rem)] font-black leading-none text-amber-100",children:p}):r.jsx("div",{"aria-hidden":"true"})]})]})}function CJ({roster:t=[],session:a}){return t.length?r.jsx("section",{className:`grid h-full min-h-0 ${zJ(t.length)} auto-rows-fr gap-0.5 bg-slate-950 p-0.5`,children:t.map(l=>r.jsx(yJ,{rover:l,session:a},l.id))}):r.jsx("section",{className:"flex h-full min-h-0 items-center justify-center border-b border-slate-800 bg-black text-[clamp(2.5rem,7vh,7rem)] font-black text-slate-500",children:"No rovers"})}function wJ(){return r.jsx("section",{className:"h-full min-h-0 overflow-hidden border-t border-slate-800 bg-black",children:r.jsx("div",{className:"origin-top-left",style:{width:`calc(100% / ${4.6})`,height:`calc(100% / ${4.6})`,transform:`scale(${4.6})`},children:r.jsx(U8,{minimal:!0,fillHeight:!0,hideSpectatorNotice:!0})})})}const HJ=4500;function SJ(t={}){const a=String(t?.text||"").trim();if(!a)return null;const l=Number.isFinite(Number(t?.durationMs))?Math.max(1200,Math.min(15e3,Number(t.durationMs))):HJ;return{id:t?.id||`display-notice-${Date.now()}`,text:a,durationMs:l}}function VJ(){const t=q2(),[a,l]=m.useState(null),o=m.useRef(null);return m.useEffect(()=>{function u(){o.current&&(clearTimeout(o.current),o.current=null)}function d(p={}){const v=SJ(p);v&&(u(),l(v),o.current=setTimeout(()=>{l(g=>g?.id===v.id?null:g),o.current=null},v.durationMs))}return t.on("display:notice",d),()=>{u(),t.off("display:notice",d)}},[t]),a?r.jsx("div",{className:"pointer-events-none fixed inset-0 z-[130] flex items-center justify-center bg-black px-[4vw] py-[4vh]",children:r.jsx("div",{className:"max-w-[92vw] border-4 border-cyan-200 bg-slate-950 px-[3vw] py-[2.5vh] text-center",children:r.jsx("div",{className:"whitespace-pre-wrap text-[clamp(3.2rem,11vh,11rem)] font-black leading-[0.95] text-white",children:a.text})})}):null}function AJ(){const{session:t}=C0(),a=h1(u=>u.latestReplay),{clearLatestReplay:l}=$2(),o=t?.mode==="lockdown";return $8(),G8(),it(),o?r.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-black text-[clamp(2.5rem,8vh,8rem)] font-black text-slate-200",children:"Lockdown"}):r.jsxs("div",{className:"display-page flex h-screen w-screen flex-col overflow-hidden bg-black text-slate-100",children:[r.jsx("div",{className:"h-[8vh] min-h-[4rem] shrink-0",children:r.jsx(bJ,{users:t?.users||[]})}),r.jsx("div",{className:"min-h-0 flex-[0.72]",children:r.jsx(CJ,{roster:t?.roster||[],session:t})}),r.jsx("div",{className:"min-h-0 flex-[1.28]",children:r.jsx(wJ,{})}),r.jsx(VJ,{}),r.jsx(oa,{}),r.jsx(Uc,{replay:a,onClose:l})]})}function LJ(){return r.jsx(AJ,{})}const BJ=1500,jJ=700,NJ=350,FJ="scanner.preferredVoiceName",qs=/female|samantha|victoria|allison|zira|karen|moira|serena|ava|susan|hazel|google (us|uk) english/i,kJ=/whisper|bubbles|bells|boing|bad news|bahh|cellos|deranged|good news|hysterical|pipe organ|trinoids|zarvox/i;function RJ(t){return kJ.test(String(t?.name||""))}function Ds(t){const a=typeof t?.getVoices=="function"?t.getVoices():[];if(!a.length)return null;const l=typeof window<"u"?String(window.localStorage.getItem(FJ)||"").trim():"",o=l?a.find(v=>String(v?.name||"")===l):null;if(o)return o;const u=a.filter(v=>!RJ(v)),d=u.find(v=>v?.default)||null,p=u.filter(v=>String(v?.lang||"").toLowerCase().startsWith("en"));return p.find(v=>qs.test(String(v?.name||"")))||u.find(v=>qs.test(String(v?.name||"")))||d||p[0]||u[0]||null}function EJ(t){return t?t instanceof ArrayBuffer?t:ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):Array.isArray(t)?new Uint8Array(t).buffer:null:null}function TJ(t){const a=EJ(t?.buffer);if(!a)return null;const l=String(t?.mime||"audio/wav").trim()||"audio/wav",o=new Blob([a],{type:l}),u=URL.createObjectURL(o),d=new Audio(u);return d.volume=1,{play:()=>d.play().finally(()=>{d.onended=()=>URL.revokeObjectURL(u)}),stop:()=>{d.pause(),d.removeAttribute("src"),d.load(),URL.revokeObjectURL(u)}}}function qJ(t,a=null){const l=m.useRef(null),o=m.useRef(null),u=m.useRef(null),d=m.useRef(null),p=m.useRef(null);m.useEffect(()=>()=>{window.clearTimeout(l.current),window.clearTimeout(o.current),window.clearTimeout(d.current),p.current?.stop()},[]),m.useEffect(()=>{const v=String(t?.speechText||"").trim(),g=t?.scannedAt?`${t.scannedAt}:${v}`:"";if(!v||!g||u.current===g)return;let x=!1;function z(){window.clearTimeout(l.current),window.clearTimeout(o.current),window.clearTimeout(d.current),l.current=null,o.current=null,d.current=null}function M(){x||(z(),l.current=window.setTimeout(()=>S(),jJ))}function y(){const w=window.speechSynthesis;if(!w||typeof window.SpeechSynthesisUtterance!="function"){M();return}z(),w.cancel();const C=new window.SpeechSynthesisUtterance(v),V=Ds(w);V&&(C.voice=V,C.lang=V.lang),C.rate=1,C.pitch=1,C.volume=1,C.onstart=()=>{window.clearTimeout(o.current),o.current=null},C.onend=()=>{z()},C.onerror=()=>{M()},w.speak(C),o.current=window.setTimeout(()=>{w.cancel(),M()},BJ)}function H(){u.current=g}function S(){x||(H(),z(),p.current?.stop(),y())}return d.current=window.setTimeout(S,NJ),()=>{x=!0,z(),p.current?.stop()}},[t]),m.useEffect(()=>{const v=String(a?.scan?.speechText||"").trim(),g=a?.scan?.scannedAt?`${a.scan.scannedAt}:${v}`:"",x=String(t?.speechText||"").trim(),z=t?.scannedAt?`${t.scannedAt}:${x}`:"";if(!g||g!==z||u.current===g)return;const M=TJ(a.audio);M&&(window.clearTimeout(d.current),d.current=null,u.current=g,p.current?.stop(),p.current=M,M.play().catch(()=>{u.current=g;const y=window.speechSynthesis;if(!y||typeof window.SpeechSynthesisUtterance!="function")return;y.cancel();const H=new window.SpeechSynthesisUtterance(x),S=Ds(y);S&&(H.voice=S,H.lang=S.lang),H.rate=1,H.pitch=1,H.volume=1,y.speak(H)}))},[t,a])}const Os={beepAllowed:!1,lastScan:null,registryError:null};function DJ(){const t=window.AudioContext||window.webkitAudioContext;if(!t)return;const a=new t,l=a.createOscillator(),o=a.createGain(),u=a.currentTime;l.type="square",l.frequency.setValueAtTime(980,u),o.gain.setValueAtTime(1e-4,u),o.gain.exponentialRampToValueAtTime(.95,u+.015),o.gain.exponentialRampToValueAtTime(1e-4,u+.2),l.connect(o),o.connect(a.destination),l.start(u),l.stop(u+.22),l.onended=()=>{a.close().catch(()=>{})}}function OJ(){const t=q2(),a=m.useRef(null),l=m.useRef(null),[o,u]=m.useState(Os),[d,p]=m.useState(null),[v,g]=m.useState(!1);$8(),G8(),it(),qJ(o.lastScan,d);const x=m.useCallback(()=>{a.current?.focus()},[]);m.useEffect(()=>{x()},[x]),m.useEffect(()=>()=>{window.clearTimeout(l.current)},[]),m.useEffect(()=>{function H(w={}){u({...Os,...w&&typeof w=="object"?w:{}})}function S(w=null){p(w&&typeof w=="object"?w:null)}return t.emit("barcode:subscribe",{},()=>{}),t.on("barcode:state",H),t.on("barcode:scanAudio",S),()=>{t.off("barcode:state",H),t.off("barcode:scanAudio",S)}},[t]);const z=m.useCallback(()=>{const H=String(a.current?.value||"").trim();if(!H){x();return}o.beepAllowed&&(window.clearTimeout(l.current),g(!0),l.current=window.setTimeout(()=>{g(!1)},120),DJ()),t.emit("barcode:scan",{code:H},()=>{}),a.current.value="",x()},[x,o.beepAllowed,t]),y=o.lastScan?.label||"waiting";return r.jsxs("main",{className:`flex min-h-screen cursor-default flex-col items-center justify-center overflow-hidden px-6 text-center ${v?"bg-white text-black":"bg-black text-white"}`,onClick:x,children:[r.jsx("input",{ref:a,"aria-label":"barcode scanner input",className:"absolute left-0 top-0 h-px w-px opacity-0",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:H=>{H.key==="Enter"&&(H.preventDefault(),z())}}),r.jsx("section",{className:"flex min-h-screen w-full items-center justify-center",children:r.jsx("h1",{className:"max-w-full break-words text-[18vw] font-black leading-none tracking-normal",children:y})}),r.jsx(Ou,{})]})}function _J(){return r.jsx(OJ,{})}function g7(t){if(!t||!t.length)return null;const a=Math.floor(Math.random()*t.length);return t[a]||null}function UJ(){if(typeof document>"u"||!document.body)return;const t=document.body.getElementsByTagName("*");if(!t||t.length<2)return;const a=g7(t),l=g7(t),o=a?.classList?.[0]||null;if(o&&l?.classList)try{l.classList.add(o)}catch{}const u=g7(t),d=g7(t),p=u?.classList?.[1]||null;if(p&&d?.classList)try{d.classList.add(p)}catch{}}function ZJ(){const t=h1(a=>!!a.session?.moderation?.isDeterred);return m.useEffect(()=>{if(!t)return;const a=window.setInterval(()=>{UJ()},1);return()=>{window.clearInterval(a)}},[t]),null}df.createRoot(document.getElementById("root")).render(r.jsx(m.StrictMode,{children:r.jsx(Dv,{children:r.jsx(Zv,{children:r.jsx(Iv,{children:r.jsx(Yp,{children:r.jsxs(RI,{children:[r.jsx(ZJ,{}),r.jsx(Vm,{children:r.jsxs(nm,{children:[r.jsx(o0,{path:"/",element:r.jsx(KX,{})}),r.jsx(o0,{path:"/spectate",element:r.jsx(iJ,{})}),r.jsx(o0,{path:"/mini",element:r.jsx(mJ,{})}),r.jsx(o0,{path:"/display",element:r.jsx(LJ,{})}),r.jsx(o0,{path:"/scanner",element:r.jsx(_J,{})})]})})]})})})})})})); diff --git a/server/public/index.html b/server/public/index.html index 3d14b853..aa4a61d5 100644 --- a/server/public/index.html +++ b/server/public/index.html @@ -11,13 +11,8 @@ - - - - - Roomba Rover - + diff --git a/webui/index.html b/webui/index.html index 9ab96267..cd06b34e 100644 --- a/webui/index.html +++ b/webui/index.html @@ -11,11 +11,6 @@ - - - - - Roomba Rover diff --git a/webui/src/App.jsx b/webui/src/App.jsx index ab92dd51..1600d02c 100644 --- a/webui/src/App.jsx +++ b/webui/src/App.jsx @@ -261,6 +261,9 @@ function App() { return (
+ {/* */} + +
);