import { readFileSync, writeFileSync } from "node:fs";
import { renderToStaticMarkup } from "react-dom/server";
import { Glyph, type GlyphName } from "../src/client/ui/icons";
// Diagrams explain relationships; controls and colour still come from the UI.
// Embed the palette so GitHub's image renderer needs no external stylesheet.
const palette = readFileSync(new URL("../src/client/ui/palette.css", import.meta.url), "utf8")
.replace(/:root\[data-theme="dark"\], :root\.dark \{([^}]+)\}/, "@media (prefers-color-scheme: dark) { :root {$1} }");
const style = `${palette}
text { fill: var(--ink); font: 600 26px system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif; text-anchor: middle; }
.node { fill: var(--paper); stroke: var(--control-edge); stroke-width: 2; }
.input { fill: var(--control-selected); }
.glyph { color: var(--ink); }
.source .glyph { color: var(--control-selected-ink); }
.source text { fill: var(--control-selected-ink); }
.path { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
`;
function AudioPaths({ english }: { english: boolean }) {
const rows: { source: GlyphName; output: GlyphName; from: string; to: string }[] = [
{ source: "window", output: "speaker", from: english ? "Source audio" : "来源声音", to: english ? "Playback volume" : "播放音量" },
{ source: "microphone", output: "speaker", from: english ? "Share microphone" : "分享麦克风", to: english ? "Playback volume" : "播放音量" },
{ source: "microphone", output: "headphones", from: english ? "Room voice" : "房间语音", to: english ? "Voice volume" : "语音收听" },
];
return ;
}
function NetworkPaths({ english }: { english: boolean }) {
return ;
}
function VirtualLanSteps({ english }: { english: boolean }) {
const steps: { icon: GlyphName; title: string; detail: string }[] = english ? [
{ icon: "network", title: "Join the same virtual LAN", detail: "Keep the tool running on both sides." },
{ icon: "window", title: "Choose the virtual address", detail: "Local room → select the virtual IP" },
{ icon: "link", title: "Send the complete invitation", detail: "Confirm the certificate and join." },
] : [
{ icon: "network", title: "加入同一虚拟网络", detail: "房主和朋友都保持组网工具运行" },
{ icon: "window", title: "选择虚拟地址", detail: "本地房间 → 局域网邀请地址" },
{ icon: "link", title: "发送完整邀请链接", detail: "朋友核对本地证书,进入房间" },
];
return ;
}
function publish(path: URL, image: string) {
if (process.argv.includes("--check")) {
if (readFileSync(path, "utf8") !== image) throw new Error("Refresh guide diagrams: npx tsx --tsconfig scripts/tsconfig.json scripts/update-guide-diagrams.tsx");
} else writeFileSync(path, image);
}
for (const language of ["en", "zh-CN"]) {
for (const [name, Diagram] of [["audio-paths", AudioPaths], ["network-paths", NetworkPaths], ["virtual-lan", VirtualLanSteps]] as const) {
publish(new URL(`../docs/assets/guide/${name}.${language}.svg`, import.meta.url),
renderToStaticMarkup() + "\n");
}
}
// Keep authored scene geometry and motion; only the surrounding UI uses the palette.
const quickstartPath = new URL("../docs/assets/quickstart.svg", import.meta.url);
const quickstart = readFileSync(quickstartPath, "utf8");
const paletteBlock = /`));