fix: 帮助页夜间配色并让流程图适应窗口
This commit is contained in:
+59
-1
@@ -40,11 +40,44 @@ export async function drawDiagrams(root: ParentNode, dark: boolean): Promise<voi
|
|||||||
const nodes = [...root.querySelectorAll<HTMLElement>(".diagram")];
|
const nodes = [...root.querySelectorAll<HTMLElement>(".diagram")];
|
||||||
if (nodes.length === 0 || import.meta.env.VITEST) return;
|
if (nodes.length === 0 || import.meta.env.VITEST) return;
|
||||||
const mermaid = (await import("mermaid")).default;
|
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({
|
mermaid.initialize({
|
||||||
startOnLoad: false,
|
startOnLoad: false,
|
||||||
securityLevel: "strict",
|
securityLevel: "strict",
|
||||||
theme: dark ? "dark" : "neutral",
|
theme: "base",
|
||||||
fontFamily: '"Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
|
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) {
|
for (const node of nodes) {
|
||||||
const source = node.dataset.source ?? "";
|
const source = node.dataset.source ?? "";
|
||||||
@@ -52,4 +85,29 @@ export async function drawDiagrams(root: ParentNode, dark: boolean): Promise<voi
|
|||||||
node.removeAttribute("data-processed");
|
node.removeAttribute("data-processed");
|
||||||
}
|
}
|
||||||
await mermaid.run({ nodes });
|
await mermaid.run({ nodes });
|
||||||
|
fitDiagrams(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fitDiagrams(root: ParentNode): void {
|
||||||
|
for (const node of root.querySelectorAll<HTMLElement>(".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";
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-24
@@ -1,8 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { nextTick, onMounted, ref, watch } from "vue";
|
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||||
import PageHeader from "@/components/PageHeader.vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
||||||
import source from "@/help/help.md?raw";
|
import source from "@/help/help.md?raw";
|
||||||
import { drawDiagrams, renderHelp } from "@/help/render";
|
import { drawDiagrams, fitDiagrams, renderHelp } from "@/help/render";
|
||||||
import { useAppTheme } from "@/theme";
|
import { useAppTheme } from "@/theme";
|
||||||
|
|
||||||
const html = renderHelp(source);
|
const html = renderHelp(source);
|
||||||
@@ -51,8 +51,18 @@ async function paint() {
|
|||||||
for (const node of list) observer.observe(node);
|
for (const node of list) observer.observe(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onResize() {
|
||||||
|
if (article.value) fitDiagrams(article.value);
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void paint();
|
void paint();
|
||||||
|
window.addEventListener("resize", onResize);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener("resize", onResize);
|
||||||
|
observer?.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(isDark, () => {
|
watch(isDark, () => {
|
||||||
@@ -61,7 +71,7 @@ watch(isDark, () => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page" :class="{ dark: isDark }">
|
||||||
<PageHeader title="帮助" />
|
<PageHeader title="帮助" />
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<nav class="toc" aria-label="帮助目录">
|
<nav class="toc" aria-label="帮助目录">
|
||||||
@@ -128,8 +138,16 @@ watch(isDark, () => {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
padding: 20px 32px 56px;
|
padding: 20px 32px 56px;
|
||||||
}
|
}
|
||||||
|
.doc :deep(h2),
|
||||||
|
.doc :deep(h3),
|
||||||
|
.doc :deep(p),
|
||||||
|
.doc :deep(li),
|
||||||
|
.doc :deep(td),
|
||||||
|
.doc :deep(th) {
|
||||||
|
color: #1f2328;
|
||||||
|
}
|
||||||
.doc :deep(h2) {
|
.doc :deep(h2) {
|
||||||
max-width: 920px;
|
max-width: none;
|
||||||
margin: 32px 0 12px;
|
margin: 32px 0 12px;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: 650;
|
font-weight: 650;
|
||||||
@@ -141,7 +159,7 @@ watch(isDark, () => {
|
|||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
.doc :deep(h3) {
|
.doc :deep(h3) {
|
||||||
max-width: 72ch;
|
max-width: none;
|
||||||
margin: 26px 0 8px;
|
margin: 26px 0 8px;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
font-weight: 650;
|
font-weight: 650;
|
||||||
@@ -173,7 +191,7 @@ watch(isDark, () => {
|
|||||||
}
|
}
|
||||||
.doc :deep(table) {
|
.doc :deep(table) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 920px;
|
max-width: 100%;
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
@@ -189,16 +207,16 @@ watch(isDark, () => {
|
|||||||
.doc :deep(th) {
|
.doc :deep(th) {
|
||||||
background: #f6f8fa;
|
background: #f6f8fa;
|
||||||
font-weight: 650;
|
font-weight: 650;
|
||||||
white-space: nowrap;
|
|
||||||
}
|
}
|
||||||
.doc :deep(pre) {
|
.doc :deep(pre) {
|
||||||
max-width: 920px;
|
max-width: 100%;
|
||||||
margin: 12px 0 0;
|
margin: 12px 0 0;
|
||||||
padding: 12px 14px;
|
padding: 12px 14px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
border: 1px solid #d0d7de;
|
border: 1px solid #d0d7de;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background: #f6f8fa;
|
background: #f6f8fa;
|
||||||
|
color: #1f2328;
|
||||||
font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
|
font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
|
||||||
font-size: 12.5px;
|
font-size: 12.5px;
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
@@ -215,10 +233,11 @@ watch(isDark, () => {
|
|||||||
background: rgba(9, 105, 218, 0.08);
|
background: rgba(9, 105, 218, 0.08);
|
||||||
}
|
}
|
||||||
.doc :deep(.diagram) {
|
.doc :deep(.diagram) {
|
||||||
max-width: 920px;
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
padding: 12px 8px;
|
padding: 8px;
|
||||||
overflow: auto;
|
overflow: hidden;
|
||||||
border: 1px solid #d0d7de;
|
border: 1px solid #d0d7de;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
@@ -227,33 +246,52 @@ watch(isDark, () => {
|
|||||||
display: block;
|
display: block;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
margin: 0 auto;
|
|
||||||
}
|
}
|
||||||
:global(html.dark) .toc {
|
.doc :deep(.diagram svg text.actor) {
|
||||||
|
fill: #ffffff !important;
|
||||||
|
}
|
||||||
|
.page.dark .toc {
|
||||||
border-right-color: #30363d;
|
border-right-color: #30363d;
|
||||||
}
|
}
|
||||||
:global(html.dark) .toc a {
|
.page.dark .toc a {
|
||||||
color: #e6edf3;
|
color: #e6edf3;
|
||||||
}
|
}
|
||||||
:global(html.dark) .toc a.on {
|
.page.dark .toc a.on {
|
||||||
color: #4493f8;
|
color: #4493f8;
|
||||||
background: rgba(68, 147, 248, 0.16);
|
background: rgba(68, 147, 248, 0.16);
|
||||||
}
|
}
|
||||||
:global(html.dark) .doc :deep(th),
|
.page.dark .doc :deep(h2),
|
||||||
:global(html.dark) .doc :deep(pre),
|
.page.dark .doc :deep(h3),
|
||||||
:global(html.dark) .doc :deep(.diagram) {
|
.page.dark .doc :deep(p),
|
||||||
|
.page.dark .doc :deep(li),
|
||||||
|
.page.dark .doc :deep(td),
|
||||||
|
.page.dark .doc :deep(th),
|
||||||
|
.page.dark .doc :deep(pre),
|
||||||
|
.page.dark .doc :deep(code) {
|
||||||
|
color: #e6edf3;
|
||||||
|
}
|
||||||
|
.page.dark .doc :deep(th),
|
||||||
|
.page.dark .doc :deep(pre) {
|
||||||
background: #161b22;
|
background: #161b22;
|
||||||
|
}
|
||||||
|
.page.dark .doc :deep(th),
|
||||||
|
.page.dark .doc :deep(td),
|
||||||
|
.page.dark .doc :deep(pre),
|
||||||
|
.page.dark .doc :deep(.diagram) {
|
||||||
border-color: #30363d;
|
border-color: #30363d;
|
||||||
}
|
}
|
||||||
:global(html.dark) .doc :deep(th),
|
.page.dark .doc :deep(.diagram) {
|
||||||
:global(html.dark) .doc :deep(td),
|
background: #0d1117;
|
||||||
:global(html.dark) .doc :deep(pre) {
|
|
||||||
border-color: #30363d;
|
|
||||||
}
|
}
|
||||||
:global(html.dark) .doc :deep(a) {
|
.page.dark .doc :deep(a) {
|
||||||
color: #4493f8;
|
color: #4493f8;
|
||||||
}
|
}
|
||||||
@media (max-width: 760px) {
|
.page.dark .doc :deep(p code),
|
||||||
|
.page.dark .doc :deep(td code),
|
||||||
|
.page.dark .doc :deep(li code) {
|
||||||
|
background: rgba(68, 147, 248, 0.16);
|
||||||
|
}
|
||||||
|
@media (max-width: 1100px) {
|
||||||
.body {
|
.body {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
@@ -269,6 +307,9 @@ watch(isDark, () => {
|
|||||||
.toc a {
|
.toc a {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
.page.dark .toc {
|
||||||
|
border-bottom-color: #30363d;
|
||||||
|
}
|
||||||
.doc {
|
.doc {
|
||||||
padding: 16px 16px 40px;
|
padding: 16px 16px 40px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user