Files
piik/src/client/pages/TooltipPreviewPage.tsx
T
AAA 2921ebe9c2 refactor(site): retire the 2.x README fixture and what only it kept
This line's guide images already come from production components, and
the maintenance branch owns its 2.x screenshots and README stills. The
fixture under site/film/ui still built the 2.x room here, from
components the 3.0 product's entry no longer reaches, and was the one
thing outside previews and tests that kept them.

Gone: the fixture, its entry, page and license output in the website
build and its include in the scripts' TypeScript project; the 14
modules only it kept (the 2.x status model, presence and viewer
presentation, and the playback bar, room chip, couch, status
indicator, host toolbar and room interactions panel); and what only
they kept, followed until nothing more fell out: the title-frame
catalogues of each locale with their reader and useDocumentTitle, 109
copy keys, one stylesheet and the rules of 130 classes, Row, the TV
frame's indicator slot, the SFU route and relay-volunteer sections of
PlaybackSettings, and the shared-protocol shapes only they read.

Kept: the public film and its build, the product's own title
(usePageTitle with composeDocumentTitle), and every preview section and
test assertion about product components. The playback preview and the
status scenarios existed for the removed modules and went. Four test
files held only removed modules and went, with the title hook's; four
mixed files lost the cases about them.

How it was established: the product's entry reaches 303 files before
and after; the type check proves the copy keys, since every use is
typed against the English catalogue; every removed rule belongs to a
class no source file writes, and no class still written lost every
rule it had, except lr-playback-compact-picture, whose only rules
needed the old bar as an ancestor.

Documents: the three that described the fixture no longer do and keep
the rule that current screenshots use real components. In the visual
language standard two rows of the text-only table described the title
catalogues and the status model and are removed, with the sentence
that named the presence module, so that its links resolve.
2026-11-29 19:38:39 +08:00

177 lines
12 KiB
TypeScript

import { useState } from "react";
import { AppHeader, LedStrip } from "../components/living/Header";
import { Tooltip } from "../components/living/Tooltip";
import { ControlsPreview } from "./ControlsPreview";
import { WelcomeLine } from "../components/living/WelcomeLine";
import { locales } from "../locales";
import { HINT_KINDS, HintComic, isHintKind, type HintKind } from "../components/living/hints";
import { Comic, type ComicKind } from "../components/living/Comic";
import { COMIC_KINDS, getComicPresentation, type ComicTone, type ComicMotion } from "../components/living/comic-presentation";
import { useCopy, type CopyKey } from "../ui/copy";
import { replaySvgAnimations } from "../ui/animation";
import { MetricCells } from "../components/living/Metrics";
import { PREVIEW_METRICS } from "./preview-metrics";
import { usePreviewAnchor } from "./use-preview-anchor";
import { usePreviewReducedMotion } from "./use-preview-reduced-motion";
import { ChannelGuidePreview } from "./ChannelGuidePreview";
import { ChannelRoomPreview } from "./ChannelRoomPreview";
import { ChannelIntegrationPreview } from "./ChannelIntegrationPreview";
import { GlyphMotionPreview } from "./GlyphMotionPreview";
import { LauncherDesignPreview } from "./LauncherDesignPreview";
const EXAMPLES: { label: string; kind: HintKind | ComicKind; tone: ComicTone; motion: ComicMotion; text: CopyKey }[] = [
{ label: "说明 / Neutral", kind: "hint-volume", tone: "off", motion: "demo", text: "playback.volume" },
{ label: "成功 / Success", kind: "hint-copy-code", tone: "live", motion: "still", text: "common.copied" },
{ label: "受限 / Limited", kind: "hint-route-p2p-required", tone: "warn", motion: "still", text: "host.advanced.route.peerOnlyRequired" },
{ label: "App incompatible", kind: "warning", tone: "warn", motion: "still", text: "native.incompatible" },
{ label: "Fullscreen waiting", kind: "hint-fullscreen-unavailable", tone: "warn", motion: "still", text: "playback.fullscreenWaiting" },
{ label: "Fullscreen failed", kind: "hint-fullscreen-unavailable", tone: "bad", motion: "still", text: "playback.fullscreenFailed" },
{ label: "失败 / Failed", kind: "warning", tone: "bad", motion: "still", text: "common.copyFailed" },
{ label: "连接中 / Connecting", kind: "signal-connecting", tone: "busy", motion: "progress", text: "state.signal.connecting" },
{ label: "恢复中 / Recovering", kind: "recovering", tone: "warn", motion: "progress", text: "state.peer.reconnecting" },
];
function PreviewCard({ kind, tone, motion, label, text }: {
kind: ComicKind | HintKind; tone?: ComicTone; motion?: ComicMotion; label?: string; text?: string;
}) {
const defaults = getComicPresentation(kind);
const replay = (card: HTMLElement) => {
const scene = card.querySelector(".lr-tooltip-preview-art > svg");
if (scene) replaySvgAnimations(scene);
};
return <section id={label ? undefined : kind} className="lr-tooltip-preview-card"
onPointerEnter={(event) => { if (event.pointerType !== "touch") replay(event.currentTarget); }}
onPointerDown={(event) => { if (event.pointerType === "touch") replay(event.currentTarget); }}
onFocusCapture={(event) => replay(event.currentTarget)}>
<header>
<code>{label ?? kind}</code>
<span className="lr-tooltip-preview-actions">
<Tooltip toggleOnClick kind={kind} tone={tone} motion={motion} text={text} place="below">
<button type="button" aria-label={`Preview ${label ?? kind}`} className="lr-tooltip-preview-trigger">Aa</button>
</Tooltip>
</span>
</header>
<div className="lr-tooltip-preview-art">
{isHintKind(kind) ? <HintComic kind={kind} size={320} tone={tone} motion={motion} />
: <Comic kind={kind} size={320} theme="paper" tone={tone} motion={motion} />}
</div>
<small>{tone ?? defaults.tone} · {motion ?? defaults.motion}</small>
</section>;
}
export function TooltipPreviewPage() {
if (new URLSearchParams(location.search).has("launcher-design")) return <LauncherDesignPreview />;
if (new URLSearchParams(location.search).has("glyph-motion")) return <GlyphMotionPreview />;
if (new URLSearchParams(location.search).has("channel-entry")) return <ChannelRoomPreview firstUse />;
if (new URLSearchParams(location.search).has("channel-integrations")) return <ChannelIntegrationPreview />;
if (new URLSearchParams(location.search).has("channel-room")) return <ChannelRoomPreview />;
return <TooltipCatalogue />;
}
function TooltipCatalogue() {
usePreviewAnchor();
const { t, lang } = useCopy();
const en = lang === "en";
const splitShare = new URLSearchParams(location.search).get("share") === "split";
const [reducedMotion, setReducedMotion] = useState(false);
usePreviewReducedMotion(reducedMotion);
return (
<div className="lr-app" data-comic-reduced-motion={reducedMotion || undefined}>
<AppHeader appControl={null} diagnosticControl={null} led={<LedStrip state="live" label={t("state.signal.connected")} comic="signal-connected" />} />
<main className="lr-room lr-tooltip-preview">
<header className="lr-tooltip-preview-head">
<h1>{en ? "Piik · UI catalogue" : "Piik · UI 控件大全"}</h1>
<p>{en ? "Actual components, sample data. Comics loop while displayed. Use the corner buttons to open the same tooltip on hover, focus or tap." : "正式组件,示例数据。漫画在展示期间循环;悬停、聚焦或点击角上的按钮,可查看实际提示。"}</p>
<label><input type="checkbox" checked={reducedMotion} onChange={event => setReducedMotion(event.target.checked)} />
{en ? "Reduced motion" : "减少动态效果"}</label>
</header>
<nav className="cp-nav" aria-label={en ? "Preview sections" : "预览目录"}>
<a href="/__tooltip-preview?channel-integrations">{en ? "Bot & OBS proposals" : "Bot 与 OBS 设计稿"}</a>
<a href="/__tooltip-preview?channel-entry">{en ? "First-use interface" : "首次进入界面"}</a>
<a href="/__tooltip-preview?glyph-motion">{en ? "Icon stroke order" : "图标笔顺"}</a>
<a href="#button-preview">{en ? "Buttons" : "按钮"}</a><a href="#option-preview">{en ? "Options" : "选择与开关"}</a>
<a href="#sharing-preview">{t("host.advanced")}</a>
<a href="#input-preview">{en ? "Inputs" : "输入"}</a><a href="#feedback-preview">{en ? "Feedback" : "反馈"}</a>
<a href="#people-preview">{en ? "People" : "人物"}</a>
<a href="#channel-connections-preview">{t("host.details")}</a>
<a href="#source-preview">{en ? "Source picker" : "画面选择"}</a>
<a href="#pawn-appearance-preview">{en ? "Participant states" : "人物状态"}</a>
<a href="#comic-preview">{en ? "Tooltips & comics" : "提示与漫画"}</a>
<a href="#launcher-preview">{en ? "App launcher" : "模式选择"}</a>
<a href="/__tooltip-preview?channel-room">{en ? "Chat & reactions" : "聊天与互动"}</a>
<a href="#remote-control-preview">{t("remote.inputTools")}</a>
<a href="#remote-permission-preview">{en ? "Input access requests" : "权限申请"}</a>
<a href="#brand-preview">{en ? "Brand motion" : "Mascot 动画"}</a>
<a href="#admission-preview">{en ? "Room entry" : "房间准入"}</a>
<a href="#metrics-preview">{en ? "Metrics" : "连接数据"}</a>
<a href="#welcome-preview">{en ? "Opening lines" : "开场白"}</a>
<a href="/__status-preview">{en ? "Loading and waiting" : "加载与等待"}</a>
<a href="/__status-preview?channel-entry">{en ? "Site connection" : "站点连接"}</a>
<a href="/__tooltip-preview#channel-guide-preview">{en ? "3.0 rooms" : "3.0 房间"}</a>
<a href="/__tooltip-preview?share=split#channel-guide-preview">{en ? "Split share control" : "分享组合按钮"}</a>
<a href="/__tooltip-preview?channel-room">{en ? "3.0 sharing view" : "3.0 分享视图"}</a>
</nav>
<details className="cp-catalog-scope">
<summary>{en ? "Shared controls and surfaces" : "控件与容器的复用范围"}</summary>
<p>{en ? "These examples render production components with sample data. Page layouts combine them; a different caption or arrangement does not create a new control type."
: "这里用示例数据渲染正式组件。业务页面组合这些组件;文案或排列不同,不代表另造一种控件。"}</p>
<ul>
<li><a href="#button-preview">{en ? "Buttons" : "按钮"}</a> · <code>Btn / button.css</code></li>
<li><a href="#option-preview">{en ? "Choices and toggles" : "选择与开关"}</a> · <code>Chip / SwitchItem / segmented-control.css</code></li>
<li><a href="#sharing-preview">{en ? "Numeric settings and inline tabs" : "数值设置与页内选项卡"}</a> · <code>QualityPresets / SharingSettings</code></li>
<li><a href="/__tooltip-preview?channel-room">{en ? "Persistent and detachable tools" : "常驻与可独立的工具窗"}</a> · <code>FloatingPanel / usePanelWindow</code></li>
</ul>
<p>{en ? "Source selection stays inside the television. Browser capture permissions, native select menus and operating-system window frames are platform UI, verified in their actual environment. Website and documentation navigation retain their page-specific layouts."
: "选源界面留在电视内。浏览器采集授权、原生下拉菜单和操作系统窗框属于平台界面,在实际环境验收;官网与文档导航保留各自的页面布局。"}</p>
</details>
<ChannelGuidePreview shareVariant={splitShare ? "split" : undefined} />
<ControlsPreview />
<MetricPreview />
<WelcomeLine still={reducedMotion} />
<details id="welcome-preview" className="lr-welcome-catalog" open>
<summary>{locales[lang].playful.welcome.length} {en ? "opening lines" : "句开场白"}</summary>
<p>{en ? "One random line per entry, with no automatic rotation. Each language has its own pool." : "每次进入随机一句,停留时不轮播。各语言独立维护词库。"}</p>
<ol>{locales[lang].playful.welcome.map(({ text }) => <li key={text}><span>{text}</span></li>)}</ol>
</details>
<h2 id="comic-preview">语义规则 / Semantic grammar</h2>
<p>{en ? "Open the tooltip to see the scene and its caption." : "打开提示,查看图示与文字说明。"}</p>
<div className="lr-tooltip-preview-grid">
{EXAMPLES.map((example) => <PreviewCard key={example.label} {...example} text={t(example.text)} />)}
</div>
<h2>操作说明 / Controls</h2>
<div className="lr-tooltip-preview-grid">
{HINT_KINDS.map((kind) => <PreviewCard key={kind} kind={kind} />)}
</div>
<h2>状态说明 / States</h2>
<div className="lr-tooltip-preview-grid">
{COMIC_KINDS.map((kind) => <PreviewCard key={kind} kind={kind} />)}
</div>
</main>
</div>
);
}
function MetricPreview() {
const { t, lang } = useCopy();
const en = lang === "en";
const [reason, setReason] = useState("other");
const [sendExpanded, setSendExpanded] = useState(true);
const [receiveExpanded, setReceiveExpanded] = useState(true);
const metrics = { ...PREVIEW_METRICS, qualityLimitationReason: reason };
return <section id="metrics-preview" className="cp-section">
<h2>{en ? "Connection metrics" : "连接数据"}</h2>
<p>{en ? "Sample observations in the actual detail cells. Sender limits do not describe the receiver's playback."
: "用正式详情控件展示示例观测。发送端的限制不代表观众的播放状态。"}</p>
<label>{t("stats.qualityState")} <select value={reason} onChange={event => setReason(event.target.value)}>
{(["none", "bandwidth", "cpu", "other", "unclassified"] as const).map(value => <option key={value} value={value}>
{t(value === "none" ? "stats.quality.normal" : `stats.quality.${value}`)}
</option>)}
</select></label>
<h3>{en ? "Sending" : "发送"}</h3>
<MetricCells metrics={metrics} direction="send" expanded={sendExpanded} onToggle={setSendExpanded} />
<h3>{en ? "Receiving" : "接收"}</h3>
<MetricCells metrics={metrics} direction="receive" expanded={receiveExpanded} onToggle={setReceiveExpanded} />
</section>;
}