From 58fbb5b1b3172a05fd583480919fdd6cc38a49bb Mon Sep 17 00:00:00 2001 From: Nixevol Date: Wed, 21 Oct 2026 20:29:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B8=AE=E5=8A=A9=E9=A1=B5=E5=A4=9C?= =?UTF-8?q?=E9=97=B4=E9=85=8D=E8=89=B2=E5=B9=B6=E8=AE=A9=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=9B=BE=E9=80=82=E5=BA=94=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/help/render.ts | 60 ++++++++++++++++++++++++- web/src/views/HelpView.vue | 89 ++++++++++++++++++++++++++++---------- 2 files changed, 124 insertions(+), 25 deletions(-) diff --git a/web/src/help/render.ts b/web/src/help/render.ts index 20cb92b..ab9c729 100644 --- a/web/src/help/render.ts +++ b/web/src/help/render.ts @@ -40,11 +40,44 @@ export async function drawDiagrams(root: ParentNode, dark: boolean): Promise(".diagram")]; if (nodes.length === 0 || import.meta.env.VITEST) return; const mermaid = (await import("mermaid")).default; + const ink = dark ? "#e6edf3" : "#1f2328"; + const muted = dark ? "#8b949e" : "#59636e"; + const panel = dark ? "#161b22" : "#f6f8fa"; + const canvas = dark ? "#0d1117" : "#ffffff"; + const line = dark ? "#30363d" : "#d0d7de"; mermaid.initialize({ startOnLoad: false, securityLevel: "strict", - theme: dark ? "dark" : "neutral", + theme: "base", fontFamily: '"Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif', + themeVariables: { + darkMode: dark, + background: canvas, + primaryColor: panel, + primaryTextColor: ink, + primaryBorderColor: line, + secondaryColor: panel, + secondaryTextColor: ink, + tertiaryColor: canvas, + tertiaryTextColor: ink, + lineColor: muted, + textColor: ink, + actorBkg: "#0969da", + actorBorder: dark ? "#4493f8" : "#0969da", + actorTextColor: "#ffffff", + actorLineColor: muted, + signalColor: ink, + signalTextColor: ink, + labelBoxBkgColor: panel, + labelBoxBorderColor: line, + labelTextColor: ink, + noteBkgColor: panel, + noteBorderColor: line, + noteTextColor: ink, + activationBkgColor: panel, + activationBorderColor: line, + }, + sequence: { useMaxWidth: true, diagramMarginX: 12, diagramMarginY: 12 }, }); for (const node of nodes) { const source = node.dataset.source ?? ""; @@ -52,4 +85,29 @@ export async function drawDiagrams(root: ParentNode, dark: boolean): Promise(".diagram")) fitDiagram(node); +} + +function fitDiagram(node: HTMLElement): void { + const svg = node.querySelector("svg"); + if (!svg) return; + const box = svg.getBBox(); + const pad = 16; + const width = box.width + pad * 2; + const height = box.height + pad * 2; + svg.setAttribute("viewBox", `${box.x - pad} ${box.y - pad} ${width} ${height}`); + svg.removeAttribute("height"); + svg.removeAttribute("width"); + const availW = Math.max(240, node.clientWidth - 8); + const availH = Math.max(320, window.innerHeight - 220); + const scale = Math.min(availW / width, availH / height); + svg.style.display = "block"; + svg.style.width = `${Math.floor(width * scale)}px`; + svg.style.height = `${Math.floor(height * scale)}px`; + svg.style.maxWidth = "100%"; + svg.style.margin = "0 auto"; } diff --git a/web/src/views/HelpView.vue b/web/src/views/HelpView.vue index ea7c6d8..8e07264 100644 --- a/web/src/views/HelpView.vue +++ b/web/src/views/HelpView.vue @@ -1,8 +1,8 @@