"""The pages the router serves: the landing form and the per-session viewer.
Everything here is one self-contained HTML string. No CDN, no framework, no
build step -- "webapp" means a router and legible pages, not a toolchain. The
viewer page is the one that matters: it is an ```` pointed at the MJPEG
route, because a top-level ``multipart/x-mixed-replace`` document is unreliable
on phones while an image tag is not.
The landing page is a **form, never a list**. The phrase is the password to a
stream and is known only by whoever enabled it, so the root page must not
enumerate sessions or leak phrases; it just hands the typed phrase to
``//``.
"""
from __future__ import annotations
import html
from functools import lru_cache
_STYLE = """
:root{color-scheme:dark}
*{box-sizing:border-box}
body{margin:0;background:#0b0d12;color:#e6e8ee;font:15px/1.5 ui-sans-serif,system-ui,sans-serif}
main{max-width:960px;margin:0 auto;padding:24px}
h1{font-size:20px;margin:0 0 4px}
a{color:#7cc4ff}
.muted{color:#8b93a7}
.card{background:#141821;border:1px solid #232838;border-radius:12px;padding:20px}
img{width:100%;height:auto;display:block;border-radius:8px;background:#000}
input{width:100%;padding:12px 14px;margin:10px 0 14px;border-radius:8px;
border:1px solid #2c3346;background:#0e121b;color:inherit;font:inherit}
button{padding:11px 16px;border:0;border-radius:8px;background:#3b82f6;color:#fff;
font:inherit;cursor:pointer}
button:hover{background:#2f6fd6}
.badge{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:#8b93a7}
.dot{width:8px;height:8px;border-radius:50%;background:#3ddc84;box-shadow:0 0 8px #3ddc84}
.row{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
.tools{display:flex;gap:14px;font-size:13px;margin-top:12px}
"""
def _esc(text: str) -> str:
return html.escape(text, quote=True)
@lru_cache(maxsize=1)
def landing_page(app_name: str = "hhstream live") -> str:
"""The root page: a box to type a phrase into. No session list, ever."""
return f"""
{_esc(app_name)}
{_esc(app_name)}
A live view is opened with the phrase printed when its session
was enabled.
"""
def viewer_page(phrase: str, label: str, output: str, fps: int) -> str:
"""The page you watch: an `` on the stream, plus a small live readout."""
base = f"/{phrase}"
return f"""
{_esc(label)} — live