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 {english ? "Shared sound and room voice" : "分享声音与房间语音"} {english ? "Source audio and the optional share microphone follow the picture and playback volume. Room voice uses its separate listening controls." : "来源声音与可选的分享麦克风跟随画面,由播放音量控制。房间语音使用独立的收听音量。"} {rows.map((row, i) => {row.from} {row.to} )} ; } function NetworkPaths({ english }: { english: boolean }) { return {english ? "Web and media use separate connections" : "网页与媒体使用不同的连接"} {english ? "The Host and friend connect to the Piik site for the web page and chat. Picture and sound need a separate media connection, directly or through forwarding." : "房主和朋友通过 Piik 站点访问网页与聊天;画面和声音需要另建媒体连接,可通过直连或服务器转发传输。"} {english ? "Piik site" : "Piik 站点"} {[{ x: 12, label: english ? "Host" : "房主" }, { x: 436, label: english ? "Friend" : "朋友" }].map(node => {node.label} )} {english ? "Web & chat" : "网页与聊天"} {english ? "Picture & sound" : "画面与声音"} {english ? "Direct or forwarded media connection" : "独立的媒体连接:直连或服务器转发"} ; } 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 {english ? "Use Piik over a virtual LAN" : "通过虚拟局域网使用 Piik"} {steps.map(step => `${step.title}: ${step.detail}`).join(". ")} {steps.map((step, i) => 0{i + 1} {step.title} {step.detail} )} ; } 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 = /`));