Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(diagram): default mind maps and flowcharts to a plain theme

tianma-if0c37516e3f13
diff --git a/apps/api/src/mcp-tool-service.ts b/apps/api/src/mcp-tool-service.ts
index 960c5ca2..0e29c2aa 100644
--- a/apps/api/src/mcp-tool-service.ts
+++ b/apps/api/src/mcp-tool-service.ts
@@ -280,7 +280,7 @@ const parseDiagramMemoIr = (args: Record<string, unknown>): DiagramIr => {
if (args.edges !== undefined && (!Array.isArray(args.edges) || args.edges.length > 400)) {
throw new AppError("invalid_params", "edges must be an array with at most 400 items", 400);
}
- if (args.theme !== undefined && !["brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron", "ocean", "ink", "classic", "paper"].includes(String(args.theme))) {
+ if (args.theme !== undefined && !["plain", "brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron", "ocean", "ink", "classic", "paper"].includes(String(args.theme))) {
throw new AppError("invalid_params", "theme is not a supported diagram color scheme", 400);
}
if (args.structure !== undefined && !["map", "line", "capsule", "box", "circle", "ellipse", "hexagon", "logic", "tree", "brace", "org", "timeline", "fishbone"].includes(String(args.structure))) {
diff --git a/apps/api/src/mcp-tools.ts b/apps/api/src/mcp-tools.ts
index af358563..37c79226 100644
--- a/apps/api/src/mcp-tools.ts
+++ b/apps/api/src/mcp-tools.ts
@@ -144,7 +144,7 @@ const MCP_TOOL_DEFINITIONS = [
notebookId: { type: "string", minLength: 1 },
title: { type: "string", maxLength: 160 },
kind: { type: "string", enum: ["mind-map", "flowchart", "architecture"] },
- theme: { type: "string", enum: ["brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron", "ocean", "ink", "classic", "paper"] },
+ theme: { type: "string", enum: ["plain", "brand", "sun", "wa", "island", "rose", "mint", "cosmos", "tea", "naive", "macaron", "ocean", "ink", "classic", "paper"] },
structure: { type: "string", enum: ["map", "line", "capsule", "box", "circle", "ellipse", "hexagon", "logic", "tree", "brace", "org", "timeline", "fishbone"] },
layout: {
type: "object",
diff --git a/apps/ios/EditorSource/src/styles.css b/apps/ios/EditorSource/src/styles.css
index 1f59ec27..76feaf03 100644
--- a/apps/ios/EditorSource/src/styles.css
+++ b/apps/ios/EditorSource/src/styles.css
@@ -886,7 +886,7 @@ html[data-theme="dark"] .ProseMirror pre code {
overflow: hidden;
border: 1px solid #e3ece7;
border-radius: 14px;
- background: #f8faf9;
+ background: #f8fafb;
touch-action: none;
}
@@ -896,7 +896,7 @@ html[data-theme="dark"] .ProseMirror pre code {
html[data-theme="dark"] .edgeever-x6-diagram {
border-color: #26382f;
- background: #101311;
+ background: #191e1b;
}
/* Viewer: no toolbar band, full-area scroll still via #editor */
diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsx
index b7e71936..2fbd50b6 100644
--- a/apps/mobile/src/components/LocalTiptapEditor.tsx
+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx
@@ -37,6 +37,8 @@ import {
getImageReferrerPolicy,
ImageGallery,
getResourceIdFromUrl,
+ DIAGRAM_CANVAS_DARK,
+ DIAGRAM_CANVAS_LIGHT,
diagramDocumentToX6Cells,
attachDiagramReader,
MIND_MAP_CONNECTOR_NAME,
@@ -3224,7 +3226,7 @@ const getEditorStyles = (theme: "light" | "dark", options?: { viewer?: boolean }
.edgeever-editor-scroll:has(.edgeever-x6-document) { display: flex; flex-direction: column; overflow: hidden; }
.edgeever-x6-document, .edgeever-diagram-reader-host { display: flex; flex-direction: column; height: 100%; min-height: 100%; padding: 8px 12px 12px; background: ${theme === "dark" ? "#0f172a" : "#fff"}; }
.edgeever-diagram-reader-controls { flex: 0 0 auto; }
- .edgeever-x6-diagram { flex: 1 1 auto; width: 100%; height: auto; min-height: 240px; overflow: hidden; border: 1px solid ${theme === "dark" ? "#26382f" : "#e3ece7"}; border-radius: 14px; background: ${theme === "dark" ? "#101311" : "#f8faf9"}; touch-action: none; }
+ .edgeever-x6-diagram { flex: 1 1 auto; width: 100%; height: auto; min-height: 240px; overflow: hidden; border: 1px solid ${theme === "dark" ? "#26382f" : "#e3ece7"}; border-radius: 14px; background: ${theme === "dark" ? DIAGRAM_CANVAS_DARK : DIAGRAM_CANVAS_LIGHT}; touch-action: none; }
.edgeever-x6-diagram .x6-graph-svg { overflow: hidden; }
.edgeever-x6-diagram .x6-node { cursor: pointer; }
.edgeever-mermaid-code-block > pre { display: none; margin: 8px 0 0; }
diff --git a/apps/web/src/components/DiagramEditorPane.tsx b/apps/web/src/components/DiagramEditorPane.tsx
index 4795341c..7b242d34 100644
--- a/apps/web/src/components/DiagramEditorPane.tsx
+++ b/apps/web/src/components/DiagramEditorPane.tsx
@@ -1647,9 +1647,11 @@ export const DiagramEditorPane = ({
const editSessionRef = useRef<MemoEditSession | null>(null);
const saveRef = useRef<() => void>(() => undefined);
const document = parseDiagramDocument(memo.contentMarkdown);
- const documentTheme = document?.kind === "flowchart"
- ? resolveFlowchartTheme(document.theme)
- : resolveDiagramTheme(document?.theme);
+ const documentTheme = document?.kind === "architecture"
+ ? resolveDiagramTheme(document.theme ?? "brand")
+ : document?.kind === "flowchart"
+ ? resolveFlowchartTheme(document.theme)
+ : resolveDiagramTheme(document?.theme);
const documentStructure = resolveDiagramStructure(document?.structure);
const [title, setTitle] = useState(memo.title ?? "");
const [tagsText, setTagsText] = useState(memo.tags.join(", "));
diff --git a/apps/web/src/components/ReadOnlyX6Diagram.tsx b/apps/web/src/components/ReadOnlyX6Diagram.tsx
index f3d6d822..ff012737 100644
--- a/apps/web/src/components/ReadOnlyX6Diagram.tsx
+++ b/apps/web/src/components/ReadOnlyX6Diagram.tsx
@@ -2,6 +2,8 @@ import { useEffect, useRef } from "react";
import { Graph } from "@antv/x6";
import {
attachDiagramReader,
+ DIAGRAM_CANVAS_DARK,
+ DIAGRAM_CANVAS_LIGHT,
diagramDocumentToX6Cells,
MIND_MAP_CONNECTOR_NAME,
mindMapConnector,
@@ -102,7 +104,7 @@ export const ReadOnlyX6Diagram = ({
overflow: hidden;
border: 1px solid ${theme === "dark" ? "#26382f" : "#e3ece7"};
border-radius: 14px;
- background: ${theme === "dark" ? "#101311" : "#f8faf9"};
+ background: ${theme === "dark" ? DIAGRAM_CANVAS_DARK : DIAGRAM_CANVAS_LIGHT};
touch-action: none;
}
.edgeever-x6-diagram .x6-graph-svg { overflow: hidden; }
diff --git a/apps/web/src/lib/diagram-editor-snapshot.test.mjs b/apps/web/src/lib/diagram-editor-snapshot.test.mjs
index f0e8be34..326de22a 100644
--- a/apps/web/src/lib/diagram-editor-snapshot.test.mjs
+++ b/apps/web/src/lib/diagram-editor-snapshot.test.mjs
@@ -19,6 +19,21 @@ test("font wrapping and compact rendering do not create a content edit", () => {
expect(snapshot(rendered)).toBe(snapshot(document));
});
+test("an unthemed mind map matches the plain default without matching forest green", () => {
+ const mindMap = {
+ schemaVersion: 1,
+ kind: "mind-map",
+ nodes: [{ id: "root", label: "Root", shape: "topic", x: 0, y: 0, width: 120, height: 46 }],
+ edges: [],
+ };
+ const plain = structuredClone(mindMap);
+ plain.theme = "plain";
+ const forest = structuredClone(mindMap);
+ forest.theme = "brand";
+ expect(snapshot(plain)).toBe(snapshot(mindMap));
+ expect(snapshot(forest)).not.toBe(snapshot(mindMap));
+});
+
test("authored geometry, text, connections and theme remain editable", () => {
for (const change of [
(d) => { d.nodes[0].width += 10; },
diff --git a/apps/web/src/lib/diagram-editor-snapshot.ts b/apps/web/src/lib/diagram-editor-snapshot.ts
index 204ac070..f1655155 100644
--- a/apps/web/src/lib/diagram-editor-snapshot.ts
+++ b/apps/web/src/lib/diagram-editor-snapshot.ts
@@ -1,13 +1,15 @@
-import type { DiagramDocument } from "@edgeever/shared";
+import { DIAGRAM_DEFAULT_THEME, type DiagramDocument } from "@edgeever/shared";
// Ordinary node dimensions are computed by the renderer, including font metrics.
// Only boundaries have authored dimensions. Display changes must not create edits.
+// Mind maps and flowcharts materialize the plain default. Architecture keeps the
+// previous materialized theme so opening one does not write a color scheme.
export const diagramEditorSnapshot = (title: string, document: DiagramDocument) => JSON.stringify({
title,
document: {
schemaVersion: document.schemaVersion,
kind: document.kind,
- theme: document.theme ?? "brand",
+ theme: document.theme ?? (document.kind === "architecture" ? "brand" : DIAGRAM_DEFAULT_THEME),
structure: document.kind === "mind-map" ? document.structure ?? "map" : undefined,
nodes: document.nodes.map((node) => ({
id: node.id, label: node.label, x: node.x, y: node.y, shape: node.shape,
diff --git a/apps/web/src/lib/diagram-layout.test.mjs b/apps/web/src/lib/diagram-layout.test.mjs
index ed42d81e..ec8c4803 100644
--- a/apps/web/src/lib/diagram-layout.test.mjs
+++ b/apps/web/src/lib/diagram-layout.test.mjs
@@ -97,6 +97,23 @@ describe("diagram auto layout", () => {
expect(positions.detached.y).toBeGreaterThan(positions["flow-end"].y + 44);
});
+ test("writes the plain theme on new mind maps and flowcharts", () => {
+ expect(compileDiagramIr({ kind: "mind-map", nodes: [{ id: "root", label: "Root" }] }).theme).toBe("plain");
+ expect(compileDiagramIr({
+ kind: "flowchart",
+ nodes: [{ id: "start", label: "Start", type: "start" }],
+ }).theme).toBe("plain");
+ expect(compileDiagramIr({
+ kind: "architecture",
+ nodes: [{ id: "api", label: "API", type: "service" }],
+ }).theme).toBeUndefined();
+ expect(compileDiagramIr({
+ kind: "mind-map",
+ theme: "brand",
+ nodes: [{ id: "root", label: "Root" }],
+ }).theme).toBe("brand");
+ });
+
test("aligns a sequential flowchart spine even when a loop returns from below", () => {
const document = compileDiagramIr({
kind: "flowchart",
diff --git a/apps/web/src/lib/diagram-theme.test.mjs b/apps/web/src/lib/diagram-theme.test.mjs
index 7fa6d0b3..9542e60d 100644
--- a/apps/web/src/lib/diagram-theme.test.mjs
+++ b/apps/web/src/lib/diagram-theme.test.mjs
@@ -1,4 +1,6 @@
+import { readFileSync } from "node:fs";
import { describe, expect, test } from "bun:test";
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "@edgeever/shared";
import { DIAGRAM_THEME_PALETTES, resolveDiagramPalette } from "./diagram-theme.ts";
const channel = (value) => {
@@ -33,10 +35,18 @@ describe("diagram appearance palettes", () => {
expect(resolveDiagramPalette("ink", "dark")).toEqual(resolveDiagramPalette("brand", "dark"));
});
- test("keeps the ten selectable color schemes distinct from forest green", () => {
+ test("keeps selectable color schemes distinct from forest green", () => {
expect(Object.keys(DIAGRAM_THEME_PALETTES)).toEqual(expect.arrayContaining([
- "brand", "cosmos", "dune", "slate", "prism", "sunrise", "marine", "blossom", "mint", "macaron",
+ "plain", "brand", "cosmos", "dune", "slate", "prism", "sunrise", "marine", "blossom", "mint", "macaron",
]));
+ expect(resolveDiagramPalette("plain", "light").topicFill).toBe("#525252");
+ const globals = readFileSync(new URL("../styles/globals.css", import.meta.url), "utf8");
+ expect(globals).toContain(`--workspace-editor: ${DIAGRAM_CANVAS_LIGHT};`);
+ expect(globals).toContain(`--workspace-editor: ${DIAGRAM_CANVAS_DARK};`);
+ for (const theme of Object.keys(DIAGRAM_THEME_PALETTES)) {
+ expect(resolveDiagramPalette(theme, "light").canvas).toBe(DIAGRAM_CANVAS_LIGHT);
+ expect(resolveDiagramPalette(theme, "dark").canvas).toBe(DIAGRAM_CANVAS_DARK);
+ }
expect(resolveDiagramPalette("mint", "light").topicFill).not.toBe(resolveDiagramPalette("brand", "light").topicFill);
expect(resolveDiagramPalette("ocean", "light")).toEqual(resolveDiagramPalette("brand", "light"));
});
diff --git a/apps/web/src/lib/diagram-theme.ts b/apps/web/src/lib/diagram-theme.ts
index c4e6acd3..d5a624a2 100644
--- a/apps/web/src/lib/diagram-theme.ts
+++ b/apps/web/src/lib/diagram-theme.ts
@@ -16,18 +16,29 @@ export type DiagramPalette = {
gridStrong: string;
};
-const withGrid = (palette: ReturnType<typeof buildDiagramPalette>, appearance: DiagramAppearance): DiagramPalette => ({
- ...palette,
- grid: appearance === "dark" ? "#1D2722" : "#E6EEE9",
- gridStrong: appearance === "dark" ? "#2B3A33" : "#CFDDD5",
-});
+const withGrid = (
+ palette: ReturnType<typeof buildDiagramPalette>,
+ appearance: DiagramAppearance,
+ theme: DiagramTheme,
+): DiagramPalette => {
+ const plain = resolveDiagramTheme(theme) === "plain";
+ return {
+ ...palette,
+ grid: plain
+ ? (appearance === "dark" ? "#242424" : "#E6E6E6")
+ : (appearance === "dark" ? "#1D2722" : "#E6EEE9"),
+ gridStrong: plain
+ ? (appearance === "dark" ? "#333333" : "#D4D4D4")
+ : (appearance === "dark" ? "#2B3A33" : "#CFDDD5"),
+ };
+};
export const DIAGRAM_THEME_PALETTES = Object.fromEntries(
DIAGRAM_SELECTABLE_THEMES.map((theme) => [theme, {
- light: withGrid(buildDiagramPalette(theme, "light"), "light"),
- dark: withGrid(buildDiagramPalette(theme, "dark"), "dark"),
+ light: withGrid(buildDiagramPalette(theme, "light"), "light", theme),
+ dark: withGrid(buildDiagramPalette(theme, "dark"), "dark", theme),
}]),
) as Record<typeof DIAGRAM_SELECTABLE_THEMES[number], Record<DiagramAppearance, DiagramPalette>>;
export const resolveDiagramPalette = (theme: DiagramTheme, appearance: DiagramAppearance) =>
- withGrid(buildDiagramPalette(resolveDiagramTheme(theme), appearance), appearance);
+ withGrid(buildDiagramPalette(resolveDiagramTheme(theme), appearance), appearance, theme);
diff --git a/packages/shared/src/diagram-architecture-style.ts b/packages/shared/src/diagram-architecture-style.ts
index a4f0d944..952c594a 100644
--- a/packages/shared/src/diagram-architecture-style.ts
+++ b/packages/shared/src/diagram-architecture-style.ts
@@ -1,3 +1,4 @@
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "./diagram-canvas";
import type { ArchitectureResourceIcon, DiagramEdgeKind, DiagramNodeShape } from "./diagram";
import {
ARCHITECTURE_RESOURCE_ICON_ELEMENTS,
@@ -101,7 +102,7 @@ export type ArchitectureSurface = {
export const ARCHITECTURE_SURFACES: Record<ArchitectureAppearance, ArchitectureSurface> = {
light: {
- canvas: "#F5F8F6",
+ canvas: DIAGRAM_CANVAS_LIGHT,
boundaryStroke: "#7B8F86",
boundaryText: "#1C3D31",
boundaryFill: "rgba(123, 143, 134, 0.05)",
@@ -125,7 +126,7 @@ export const ARCHITECTURE_SURFACES: Record<ArchitectureAppearance, ArchitectureS
},
},
dark: {
- canvas: "#101311",
+ canvas: DIAGRAM_CANVAS_DARK,
boundaryStroke: "#5B6F66",
boundaryText: "#D7F4E8",
boundaryFill: "rgba(91, 111, 102, 0.12)",
diff --git a/packages/shared/src/diagram-canvas.ts b/packages/shared/src/diagram-canvas.ts
new file mode 100644
index 00000000..1542c039
--- /dev/null
+++ b/packages/shared/src/diagram-canvas.ts
@@ -0,0 +1,4 @@
+// The note editor surface, `--workspace-editor` in apps/web/src/styles/globals.css.
+// Every diagram canvas uses it, so a color theme does not tint the page.
+export const DIAGRAM_CANVAS_LIGHT = "#f8fafb";
+export const DIAGRAM_CANVAS_DARK = "#191e1b";
diff --git a/packages/shared/src/diagram-flowchart-style.test.mjs b/packages/shared/src/diagram-flowchart-style.test.mjs
index fa9bf08a..805172b6 100644
--- a/packages/shared/src/diagram-flowchart-style.test.mjs
+++ b/packages/shared/src/diagram-flowchart-style.test.mjs
@@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test";
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "./diagram-canvas.ts";
import { flowchartNodePresentation } from "./diagram-node-presentation.ts";
import {
DIAGRAM_READABLE_MIN_SCALE,
@@ -60,22 +61,31 @@ describe("flowchart semantic paint", () => {
});
test("uses outlined capsules and Inter for terminator labels", () => {
- const visual = flowchartNodeVisual("terminator", "light", { width: 116, height: 40 });
+ const visual = flowchartNodeVisual("terminator", "light", { width: 116, height: 40 }, "brand");
expect(visual.body.rx).toBe(20);
expect(visual.body.fill).toBe(FLOWCHART_SURFACES.brand.light.terminator.fill);
expect(visual.label.fontFamily).toContain("Inter");
});
- test("offers ten flowchart surfaces and maps leftover ids onto them", () => {
- expect(FLOWCHART_SELECTABLE_THEMES).toHaveLength(10);
+ test("offers flowchart surfaces and maps leftover ids onto them", () => {
+ expect(FLOWCHART_SELECTABLE_THEMES).toHaveLength(11);
expect([...FLOWCHART_THEME_GROUPS.classic, ...FLOWCHART_THEME_GROUPS.vivid]).toEqual([...FLOWCHART_SELECTABLE_THEMES]);
+ expect(resolveFlowchartTheme()).toBe("plain");
expect(resolveFlowchartTheme("mint")).toBe("mint");
+ expect(resolveFlowchartTheme("brand")).toBe("brand");
expect(resolveFlowchartTheme("classic")).toBe("paper");
expect(resolveFlowchartTheme("naive")).toBe("brand");
+ expect(FLOWCHART_SURFACES.plain.light.canvas).toBe(DIAGRAM_CANVAS_LIGHT);
+ expect(FLOWCHART_SURFACES.plain.dark.canvas).toBe(DIAGRAM_CANVAS_DARK);
+ expect(new Set(FLOWCHART_SELECTABLE_THEMES.flatMap((theme) => [
+ FLOWCHART_SURFACES[theme].light.canvas,
+ FLOWCHART_SURFACES[theme].dark.canvas,
+ ]))).toEqual(new Set([DIAGRAM_CANVAS_LIGHT, DIAGRAM_CANVAS_DARK]));
+ expect(FLOWCHART_SURFACES.plain.light.terminator.fill).toBe("#525252");
expect(FLOWCHART_SURFACES.brand.light.terminator.stroke).toBe("#16A06E");
- expect(new Set(FLOWCHART_SELECTABLE_THEMES.map((theme) => FLOWCHART_SURFACES[theme].light.terminator.stroke)).size).toBe(10);
+ expect(new Set(FLOWCHART_SELECTABLE_THEMES.map((theme) => FLOWCHART_SURFACES[theme].light.terminator.stroke)).size).toBe(11);
expect(resolveFlowchartSurface("light", "ink").terminator.stroke).toBe("#3A4656");
- expect(resolveFlowchartSurface("light", "paper").canvas).toBe("#F6F1E8");
+ expect(resolveFlowchartSurface("light", "paper").process.fill).toBe("#FFFCF6");
expect(resolveFlowchartSurface("light", "mint").terminator.stroke).toBe("#1A7A70");
});
@@ -84,6 +94,8 @@ describe("flowchart semantic paint", () => {
for (const theme of ["ink", "paper", "island", "tea", "sun", "wa", "rose"]) {
expect(resolveFlowchartTheme(theme)).toBe(theme);
}
+ expect(resolveDiagramTheme()).toBe("plain");
+ expect(resolveDiagramTheme("brand")).toBe("brand");
expect(resolveDiagramTheme("ink")).toBe("brand");
expect(resolveDiagramTheme("paper")).toBe("brand");
expect(resolveDiagramTheme("island")).toBe("dune");
diff --git a/packages/shared/src/diagram-flowchart-style.ts b/packages/shared/src/diagram-flowchart-style.ts
index 5a2860c1..7c5cd010 100644
--- a/packages/shared/src/diagram-flowchart-style.ts
+++ b/packages/shared/src/diagram-flowchart-style.ts
@@ -1,3 +1,4 @@
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "./diagram-canvas";
import type { DiagramNodeShape, DiagramTheme } from "./diagram";
export const FLOWCHART_LABEL_FONT =
@@ -66,11 +67,11 @@ export const flowchartFitsReadableViewport = (
export type FlowchartAppearance = "light" | "dark";
export const FLOWCHART_SELECTABLE_THEMES = [
- "brand", "ink", "paper", "island", "tea", "cosmos", "sun", "wa", "rose", "mint",
+ "plain", "brand", "ink", "paper", "island", "tea", "cosmos", "sun", "wa", "rose", "mint",
] as const;
export type FlowchartTheme = (typeof FLOWCHART_SELECTABLE_THEMES)[number];
export const FLOWCHART_THEME_GROUPS = {
- classic: ["brand", "ink", "paper", "island", "tea", "cosmos"],
+ classic: ["plain", "brand", "ink", "paper", "island", "tea", "cosmos"],
vivid: ["sun", "wa", "rose", "mint"],
} as const;
@@ -102,20 +103,38 @@ const FLOWCHART_THEME_ALIASES: Partial<Record<DiagramTheme, FlowchartTheme>> = {
export const resolveFlowchartTheme = (theme?: DiagramTheme): FlowchartTheme => {
if (theme && (FLOWCHART_SELECTABLE_THEMES as readonly string[]).includes(theme)) return theme as FlowchartTheme;
- return FLOWCHART_THEME_ALIASES[theme ?? "brand"] ?? "brand";
+ // A stored legacy id keeps its alias. Only a missing theme uses the plain default.
+ if (theme) return FLOWCHART_THEME_ALIASES[theme] ?? "brand";
+ return "plain";
};
export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearance, FlowchartSurface>> = {
+ plain: {
+ light: {
+ canvas: DIAGRAM_CANVAS_LIGHT,
+ edge: "#737373",
+ process: { fill: "#FFFFFF", stroke: "#D4D4D4", text: "#212121" },
+ decision: { fill: "#F4F4F5", stroke: "#737373", text: "#212121" },
+ terminator: { fill: "#525252", stroke: "#525252", text: "#FFFFFF" },
+ },
+ dark: {
+ canvas: DIAGRAM_CANVAS_DARK,
+ edge: "#A3A3A3",
+ process: { fill: "#1C1C1C", stroke: "#3A3A3A", text: "#F4F4F5" },
+ decision: { fill: "#262626", stroke: "#A3A3A3", text: "#F4F4F5" },
+ terminator: { fill: "#F5F5F5", stroke: "#F5F5F5", text: "#212121" },
+ },
+ },
brand: {
light: {
- canvas: "#F5F8F6",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#5C7166",
process: { fill: "#FFFFFF", stroke: "#6F9B88", text: "#1C3D31" },
decision: { fill: "#FFF6E5", stroke: "#D4A24A", text: "#7A4A12" },
terminator: { fill: "#E7F6EF", stroke: "#16A06E", text: "#145C40" },
},
dark: {
- canvas: "#101311",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#8CA397",
process: { fill: "#1B2420", stroke: "#5B7569", text: "#E8F2ED" },
decision: { fill: "#2A2316", stroke: "#E0B35C", text: "#F8E4B8" },
@@ -124,14 +143,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
ink: {
light: {
- canvas: "#F3F5F7",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#64748B",
process: { fill: "#FFFFFF", stroke: "#7D8794", text: "#1C232C" },
decision: { fill: "#E8EDF3", stroke: "#6E7C8F", text: "#243044" },
terminator: { fill: "#E6EAEF", stroke: "#3A4656", text: "#1A222C" },
},
dark: {
- canvas: "#101214",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#94A3B8",
process: { fill: "#1B1E23", stroke: "#6B7380", text: "#E8ECF1" },
decision: { fill: "#222830", stroke: "#8B9BB0", text: "#D5DDE8" },
@@ -140,14 +159,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
paper: {
light: {
- canvas: "#F6F1E8",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#78716C",
process: { fill: "#FFFCF6", stroke: "#C4B396", text: "#3A3126" },
decision: { fill: "#F4E4CC", stroke: "#C08A48", text: "#6A3F14" },
terminator: { fill: "#F0E4D0", stroke: "#7A5230", text: "#3F2A16" },
},
dark: {
- canvas: "#161310",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#A8A29E",
process: { fill: "#221E19", stroke: "#7A6A56", text: "#F3EBE0" },
decision: { fill: "#2C2418", stroke: "#D4A06A", text: "#F6E2C4" },
@@ -156,14 +175,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
island: {
light: {
- canvas: "#F6EEE8",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#7C6F68",
process: { fill: "#FFF8F3", stroke: "#C4A090", text: "#3A2A22" },
decision: { fill: "#F3D8C8", stroke: "#C46A48", text: "#6A3220" },
terminator: { fill: "#EBD0C0", stroke: "#8B4A32", text: "#3F2418" },
},
dark: {
- canvas: "#161210",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#ABA09A",
process: { fill: "#231C18", stroke: "#8A6A56", text: "#F3E8E0" },
decision: { fill: "#2C2018", stroke: "#D49070", text: "#F6D8C4" },
@@ -172,14 +191,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
tea: {
light: {
- canvas: "#F4F6EE",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#657361",
process: { fill: "#FFFFFF", stroke: "#8A9A72", text: "#2A3420" },
decision: { fill: "#E8EED4", stroke: "#8A9A48", text: "#3F4A18" },
terminator: { fill: "#DCE6C8", stroke: "#4F6A32", text: "#243018" },
},
dark: {
- canvas: "#121410",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#97A693",
process: { fill: "#1C2018", stroke: "#6A7A56", text: "#E8F0DC" },
decision: { fill: "#222618", stroke: "#B8C46A", text: "#E8F0C4" },
@@ -188,14 +207,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
cosmos: {
light: {
- canvas: "#F2F5F8",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#5C6D7E",
process: { fill: "#FFFFFF", stroke: "#7A94A8", text: "#1C2A38" },
decision: { fill: "#E4EEF5", stroke: "#5A82A0", text: "#1E3A52" },
terminator: { fill: "#D8E6F0", stroke: "#2A5470", text: "#163044" },
},
dark: {
- canvas: "#101218",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#8EA0B2",
process: { fill: "#181E26", stroke: "#5A7088", text: "#E0E8F0" },
decision: { fill: "#1C2834", stroke: "#7AA0C0", text: "#D0E4F4" },
@@ -204,14 +223,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
sun: {
light: {
- canvas: "#F8F6EC",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#736B5E",
process: { fill: "#FFFEF6", stroke: "#D4C47A", text: "#3A3418" },
decision: { fill: "#FFF0C4", stroke: "#E0B040", text: "#6A4A08" },
terminator: { fill: "#F8E8B0", stroke: "#C09020", text: "#4A3808" },
},
dark: {
- canvas: "#16140C",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#A8A092",
process: { fill: "#242018", stroke: "#8A7A48", text: "#F6F0D8" },
decision: { fill: "#2C2410", stroke: "#E0B848", text: "#F8E8B8" },
@@ -220,14 +239,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
wa: {
light: {
- canvas: "#F4F7F9",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#5B6F7D",
process: { fill: "#FFFFFF", stroke: "#8AA8C0", text: "#1C2C3A" },
decision: { fill: "#FCE8DC", stroke: "#E09070", text: "#7A3A24" },
terminator: { fill: "#DCE8F4", stroke: "#2A5A88", text: "#1A3858" },
},
dark: {
- canvas: "#101418",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#8EA3B3",
process: { fill: "#182028", stroke: "#5A7088", text: "#E0E8F0" },
decision: { fill: "#2C2018", stroke: "#E0A080", text: "#F8DCC8" },
@@ -236,14 +255,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
rose: {
light: {
- canvas: "#F8F3F5",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#75646B",
process: { fill: "#FFFFFF", stroke: "#C49AAC", text: "#3A2430" },
decision: { fill: "#F8E4EC", stroke: "#D0809A", text: "#7A3048" },
terminator: { fill: "#F0D8E2", stroke: "#A04060", text: "#4A2030" },
},
dark: {
- canvas: "#161014",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#A8969D",
process: { fill: "#24181C", stroke: "#8A5A6A", text: "#F4E4EA" },
decision: { fill: "#2C1A22", stroke: "#E090A8", text: "#F8D8E4" },
@@ -252,14 +271,14 @@ export const FLOWCHART_SURFACES: Record<FlowchartTheme, Record<FlowchartAppearan
},
mint: {
light: {
- canvas: "#F2F8F7",
+ canvas: DIAGRAM_CANVAS_LIGHT,
edge: "#5A736F",
process: { fill: "#FFFFFF", stroke: "#7AB0A8", text: "#1C3A38" },
decision: { fill: "#E4F4F0", stroke: "#4AA89A", text: "#1A5A52" },
terminator: { fill: "#D4EEE8", stroke: "#1A7A70", text: "#145048" },
},
dark: {
- canvas: "#101614",
+ canvas: DIAGRAM_CANVAS_DARK,
edge: "#8EA8A4",
process: { fill: "#182422", stroke: "#4A786E", text: "#DCF0EC" },
decision: { fill: "#1A2C28", stroke: "#6AC4B4", text: "#D0F0E8" },
diff --git a/packages/shared/src/diagram-layout.ts b/packages/shared/src/diagram-layout.ts
index 1ef29507..b3268dc5 100644
--- a/packages/shared/src/diagram-layout.ts
+++ b/packages/shared/src/diagram-layout.ts
@@ -22,6 +22,7 @@ export { compactMindMapNodeSize } from "./diagram-mindmap-style";
import { graphlib, layout as runDagreLayout } from "@dagrejs/dagre";
import {
ARCHITECTURE_DIAGRAM_SCHEMA_VERSION,
+ DIAGRAM_DEFAULT_THEME,
DIAGRAM_SCHEMA_VERSION,
type ArchitectureResourceIcon,
type DiagramDocument,
@@ -1020,7 +1021,11 @@ export const compileDiagramIr = (ir: DiagramIr): DiagramDocument => {
const document: DiagramDocument = {
schemaVersion: ir.kind === "architecture" ? ARCHITECTURE_DIAGRAM_SCHEMA_VERSION : DIAGRAM_SCHEMA_VERSION,
kind: ir.kind,
- ...(ir.theme ? { theme: ir.theme } : {}),
+ ...(ir.theme
+ ? { theme: ir.theme }
+ : ir.kind === "architecture"
+ ? {}
+ : { theme: DIAGRAM_DEFAULT_THEME }),
...(ir.kind === "mind-map" && ir.structure ? { structure: ir.structure } : {}),
nodes,
edges,
diff --git a/packages/shared/src/diagram-mindmap-style.test.mjs b/packages/shared/src/diagram-mindmap-style.test.mjs
index 3624dd93..ead2cc40 100644
--- a/packages/shared/src/diagram-mindmap-style.test.mjs
+++ b/packages/shared/src/diagram-mindmap-style.test.mjs
@@ -134,6 +134,9 @@ describe("mind map presentation", () => {
expect(styled.visual.underline.stroke).toBe(mindMapBranchTint(0, "light", "sun")?.edge);
const brandNested = resolveMindMapNodeStyle(nodes, "one-a", palette, "brand", "light", { width: 96, height: 32 });
expect(brandNested.visual.underline.stroke).toBe(palette.mindMapEdge);
+ const plainNested = resolveMindMapNodeStyle(nodes, "one-a", palette, "plain", "light", { width: 96, height: 32 });
+ expect(plainNested.tint).toBeUndefined();
+ expect(resolveMindMapNodeStyle(nodes, "one", palette, undefined, "light", { width: 96, height: 36 }).tint).toBeUndefined();
});
test("builds a closed horizontal cubic ribbon that is thicker at the source", () => {
diff --git a/packages/shared/src/diagram-palette.ts b/packages/shared/src/diagram-palette.ts
index 4cfb1340..e59e9397 100644
--- a/packages/shared/src/diagram-palette.ts
+++ b/packages/shared/src/diagram-palette.ts
@@ -1,3 +1,4 @@
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "./diagram-canvas";
import type { DiagramTheme } from "./diagram";
import { resolveDiagramTheme } from "./diagram";
@@ -13,99 +14,83 @@ type DiagramThemeDefinition = {
id: Exclude<ReturnType<typeof resolveDiagramTheme>, never>;
group: "vivid" | "classic";
colors: readonly [string, string, string, string, string, string];
- lightCanvas: string;
- darkCanvas: string;
accent: string;
};
export const DIAGRAM_THEME_DEFINITIONS: Record<
- "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
+ "plain" | "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
DiagramThemeDefinition
> = {
+ plain: {
+ id: "plain",
+ group: "classic",
+ colors: ["#525252", "#737373", "#8A8A8A", "#A3A3A3", "#D4D4D4", "#FFFFFF"],
+ accent: "#525252",
+ },
brand: {
id: "brand",
group: "classic",
colors: ["#16A06E", "#059669", "#0D9488", "#10B981", "#047857", "#065F46"],
- lightCanvas: "#F8FAF9",
- darkCanvas: "#101311",
accent: "#16A06E",
},
cosmos: {
id: "cosmos",
group: "classic",
colors: ["#2563EB", "#0284C7", "#4F46E5", "#0D9488", "#3B82F6", "#1D4ED8"],
- lightCanvas: "#F8FAFC",
- darkCanvas: "#0F1318",
accent: "#2563EB",
},
dune: {
id: "dune",
group: "classic",
colors: ["#C2410C", "#D97706", "#B45309", "#A16207", "#78350F", "#9A3412"],
- lightCanvas: "#FAF8F5",
- darkCanvas: "#151311",
accent: "#B45309",
},
slate: {
id: "slate",
group: "classic",
colors: ["#475569", "#52525B", "#4B5563", "#334155", "#64748B", "#1E293B"],
- lightCanvas: "#F8F9FA",
- darkCanvas: "#121416",
accent: "#475569",
},
prism: {
id: "prism",
group: "vivid",
colors: ["#E11D48", "#EA580C", "#D97706", "#059669", "#2563EB", "#7C3AED"],
- lightCanvas: "#FAFAFA",
- darkCanvas: "#111215",
accent: "#6366F1",
},
sunrise: {
id: "sunrise",
group: "vivid",
colors: ["#E11D48", "#F97316", "#F59E0B", "#D97706", "#DC2626", "#EA580C"],
- lightCanvas: "#FFFDF7",
- darkCanvas: "#16130E",
accent: "#EA580C",
},
marine: {
id: "marine",
group: "vivid",
colors: ["#0284C7", "#06B6D4", "#0D9488", "#2563EB", "#0891B2", "#1D4ED8"],
- lightCanvas: "#F5FAFD",
- darkCanvas: "#0C1318",
accent: "#0284C7",
},
blossom: {
id: "blossom",
group: "vivid",
colors: ["#DB2777", "#C026D3", "#9333EA", "#E11D48", "#BE185D", "#7C3AED"],
- lightCanvas: "#FDF8FA",
- darkCanvas: "#160F14",
accent: "#DB2777",
},
mint: {
id: "mint",
group: "vivid",
colors: ["#0D9488", "#059669", "#10B981", "#0891B2", "#16A34A", "#047857"],
- lightCanvas: "#F5FAF8",
- darkCanvas: "#0D1512",
accent: "#0D9488",
},
macaron: {
id: "macaron",
group: "vivid",
colors: ["#EC4899", "#FB923C", "#EAB308", "#10B981", "#38BDF8", "#8B5CF6"],
- lightCanvas: "#FAF9F8",
- darkCanvas: "#131316",
accent: "#EC4899",
},
};
export const DIAGRAM_COLOR_STRIPS: Record<
- "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
+ "plain" | "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
DiagramColorStrip
> = Object.fromEntries(
Object.entries(DIAGRAM_THEME_DEFINITIONS).map(([id, def]) => [
@@ -113,13 +98,13 @@ export const DIAGRAM_COLOR_STRIPS: Record<
{ id: def.id, group: def.group, colors: def.colors },
]),
) as Record<
- "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
+ "plain" | "brand" | "cosmos" | "dune" | "slate" | "prism" | "sunrise" | "marine" | "blossom" | "mint" | "macaron",
DiagramColorStrip
>;
export const DIAGRAM_THEME_GROUPS = {
vivid: ["prism", "sunrise", "marine", "blossom", "mint", "macaron"],
- classic: ["brand", "cosmos", "dune", "slate"],
+ classic: ["plain", "brand", "cosmos", "dune", "slate"],
} as const;
const hexToRgb = (hex: string) => {
@@ -154,7 +139,10 @@ const readableText = (fill: string) => (luminance(fill) > 0.35 ? "#1C1917" : "#F
export const diagramThemeSwatches = (theme?: DiagramTheme) =>
DIAGRAM_COLOR_STRIPS[resolveDiagramTheme(theme)].colors;
-export const diagramThemeUsesBranchColors = (theme?: DiagramTheme) => resolveDiagramTheme(theme) !== "brand";
+export const diagramThemeUsesBranchColors = (theme?: DiagramTheme) => {
+ const resolved = resolveDiagramTheme(theme);
+ return resolved !== "brand" && resolved !== "plain";
+};
const resolveBranchEdge = (color: string, appearance: DiagramAppearance) => {
const lum = luminance(color);
@@ -182,6 +170,32 @@ export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance:
const resolved = resolveDiagramTheme(theme);
const def = DIAGRAM_THEME_DEFINITIONS[resolved];
const accent = def.accent;
+ if (resolved === "plain") {
+ if (appearance === "dark") {
+ return {
+ topicFill: "#F5F5F5",
+ topicText: "#212121",
+ nodeFill: "#1C1C1C",
+ nodeText: "#F4F4F5",
+ nodeStroke: "#3A3A3A",
+ topicStroke: "#F5F5F5",
+ mindMapEdge: "#A3A3A3",
+ flowEdge: "#A3A3A3",
+ canvas: DIAGRAM_CANVAS_DARK,
+ };
+ }
+ return {
+ topicFill: "#525252",
+ topicText: "#FFFFFF",
+ nodeFill: "#FFFFFF",
+ nodeText: "#212121",
+ nodeStroke: "#D4D4D4",
+ topicStroke: "#525252",
+ mindMapEdge: "#737373",
+ flowEdge: "#737373",
+ canvas: DIAGRAM_CANVAS_LIGHT,
+ };
+ }
if (resolved === "brand") {
if (appearance === "dark") {
return {
@@ -193,7 +207,7 @@ export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance:
topicStroke: "#58CDA4",
mindMapEdge: "#4DB58B",
flowEdge: "#72B99B",
- canvas: "#101311",
+ canvas: DIAGRAM_CANVAS_DARK,
};
}
return {
@@ -205,7 +219,7 @@ export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance:
topicStroke: "#12845B",
mindMapEdge: "#55B891",
flowEdge: "#408A6D",
- canvas: "#F8FAF9",
+ canvas: DIAGRAM_CANVAS_LIGHT,
};
}
if (appearance === "dark") {
@@ -219,7 +233,7 @@ export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance:
topicStroke: mix(accent, "#FFFFFF", 0.25),
mindMapEdge: edge,
flowEdge: mix(accent, "#FFFFFF", 0.15),
- canvas: def.darkCanvas,
+ canvas: DIAGRAM_CANVAS_DARK,
};
}
const edge = resolveBranchEdge(accent, "light");
@@ -232,6 +246,6 @@ export const buildDiagramPalette = (theme: DiagramTheme | undefined, appearance:
topicStroke: mix(accent, "#1C1917", 0.15),
mindMapEdge: edge,
flowEdge: mix(accent, "#1C1917", 0.15),
- canvas: def.lightCanvas,
+ canvas: DIAGRAM_CANVAS_LIGHT,
};
};
diff --git a/packages/shared/src/diagram-view.ts b/packages/shared/src/diagram-view.ts
index d2e80407..2695770c 100644
--- a/packages/shared/src/diagram-view.ts
+++ b/packages/shared/src/diagram-view.ts
@@ -50,7 +50,7 @@ export type DiagramPalette = {
};
export const resolvePortableDiagramPalette = (
- theme: DiagramTheme = "brand",
+ theme?: DiagramTheme,
appearance: DiagramAppearance = "light",
) => buildDiagramPalette(theme, appearance);
@@ -59,7 +59,10 @@ export const diagramDocumentToX6Cells = (
document: DiagramDocument,
appearance: DiagramAppearance,
) => {
- const palette = resolvePortableDiagramPalette(document.theme ?? "brand", appearance);
+ const palette = resolvePortableDiagramPalette(
+ document.kind === "architecture" ? (document.theme ?? "brand") : document.theme,
+ appearance,
+ );
const flowchartSurface = document.kind === "flowchart" ? resolveFlowchartSurface(appearance, document.theme) : null;
const architectureSurface = document.kind === "architecture" ? resolveArchitectureSurface(appearance) : null;
const nodes = document.nodes.map((node) => {
diff --git a/packages/shared/src/diagram.test.mjs b/packages/shared/src/diagram.test.mjs
index 5431b049..093af7b4 100644
--- a/packages/shared/src/diagram.test.mjs
+++ b/packages/shared/src/diagram.test.mjs
@@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test";
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "./diagram-canvas.ts";
import { createDefaultDiagramDocument, DIAGRAM_SELECTABLE_STRUCTURES, DIAGRAM_SELECTABLE_THEMES, diagramDocumentToMermaid, diagramFallbackMarkdown, hasDiagramDocumentMarker, parseDiagramDocument, serializeDiagramDocument, stripDiagramDocumentMarker } from "./diagram.ts";
import { diagramDocumentToX6Cells } from "./diagram-view.ts";
import { markdownToDoc } from "./content.ts";
@@ -12,12 +13,13 @@ describe("diagram document", () => {
expect(parseDiagramDocument(serializeDiagramDocument(document))).toEqual(document);
});
- test("offers selectable mind-map layouts and ten color schemes", () => {
+ test("offers selectable mind-map layouts and color schemes", () => {
expect(DIAGRAM_SELECTABLE_STRUCTURES).toEqual([
"map", "line", "capsule", "box", "circle", "ellipse", "hexagon",
"logic", "tree", "brace", "org", "timeline", "fishbone",
]);
- expect(DIAGRAM_SELECTABLE_THEMES).toHaveLength(10);
+ expect(DIAGRAM_SELECTABLE_THEMES[0]).toBe("plain");
+ expect(DIAGRAM_SELECTABLE_THEMES).toHaveLength(11);
const document = createDefaultDiagramDocument("mind-map");
document.theme = "mint";
document.structure = "fishbone";
@@ -70,7 +72,8 @@ describe("diagram document", () => {
expect(markdown).toContain("# 流程图");
expect(markdown).toContain("```mermaid\nflowchart TD");
expect(markdown).toContain('n1["处理步骤"]');
- expect(markdown).toContain("classDef flowProcess fill:#FFFFFF,stroke:#6F9B88");
+ expect(markdown).toContain("classDef flowProcess fill:#FFFFFF,stroke:#D4D4D4,color:#212121");
+ expect(markdown).toContain("classDef flowTerminator fill:#525252,stroke:#525252,color:#FFFFFF");
expect(markdown).toContain("class n1 flowProcess");
expect(markdown).toContain("class n0 flowTerminator");
@@ -93,18 +96,31 @@ describe("diagram document", () => {
document.theme = "paper";
expect(parseDiagramDocument(serializeDiagramDocument(document))?.theme).toBe("paper");
const paper = diagramDocumentToX6Cells(document, "light");
- expect(paper.canvas).toBe("#F6F1E8");
+ expect(paper.canvas).toBe(DIAGRAM_CANVAS_LIGHT);
expect(paper.nodes.find((node) => node.id === "flow-start").attrs.body.stroke).toBe("#7A5230");
document.theme = "ink";
const ink = diagramDocumentToX6Cells(document, "light");
- expect(ink.canvas).toBe("#F3F5F7");
+ expect(ink.canvas).toBe(DIAGRAM_CANVAS_LIGHT);
expect(ink.nodes.find((node) => node.id === "flow-start").attrs.body.stroke).toBe("#3A4656");
});
test("projects native viewers into the same branded X6 palette", () => {
const document = createDefaultDiagramDocument("mind-map");
+ expect(document.theme).toBe("plain");
+ const plain = diagramDocumentToX6Cells(document, "light");
+ expect(plain.canvas).toBe(DIAGRAM_CANVAS_LIGHT);
+ expect(plain.nodes[0].attrs.body.fill).toBe("#525252");
+ expect(plain.nodes[0].attrs.label.fill).toBe("#FFFFFF");
+ expect(plain.nodes[1].attrs.body.fill).toBe("#FFFFFF");
+ expect(plain.nodes[1].attrs.body.stroke).toBe(plain.nodes[2].attrs.body.stroke);
+ expect(plain.nodes.find((node) => node.id === "topic-1-a").attrs.underline.stroke).toBe("#737373");
+ const unset = structuredClone(document);
+ delete unset.theme;
+ expect(diagramDocumentToX6Cells(unset, "light").nodes[0].attrs.body.fill).toBe("#525252");
+
+ document.theme = "brand";
const light = diagramDocumentToX6Cells(document, "light");
- expect(light.canvas).toBe("#F8FAF9");
+ expect(light.canvas).toBe(DIAGRAM_CANVAS_LIGHT);
expect(light.nodes[0].attrs.body.fill).toBe("#16A06E");
expect(light.nodes[0].attrs.body.rx).toBe(23);
expect(light.nodes[1].attrs.body.fill).toBe("#F0F8F4");
@@ -132,7 +148,7 @@ describe("diagram document", () => {
.toBe(classic.edges.find((edge) => edge.target.cell === "topic-1").attrs.line.stroke);
const dark = diagramDocumentToX6Cells(document, "dark");
- expect(dark.canvas).toBe("#101311");
+ expect(dark.canvas).toBe(DIAGRAM_CANVAS_DARK);
expect(dark.nodes[1].attrs.body.fill).toBe("#18211D");
});
@@ -144,6 +160,7 @@ describe("diagram document", () => {
expect(source).toContain("核心 &lt;主题&gt; &quot;A&amp;B&quot;");
expect(source).toContain("n0 --- n1");
expect(source).toContain("class n0 mindRoot");
+ expect(source).toContain("classDef mindRoot fill:#525252,stroke:#525252,color:#FFFFFF");
});
test("round-trips architecture components, boundaries, and semantic connections", () => {
diff --git a/packages/shared/src/diagram.ts b/packages/shared/src/diagram.ts
index 8038cce5..bfb4edec 100644
--- a/packages/shared/src/diagram.ts
+++ b/packages/shared/src/diagram.ts
@@ -26,10 +26,11 @@ export type DiagramNodeShape =
| "boundary";
export type DiagramEdgeKind = "dependency" | "request" | "async" | "data";
export const DIAGRAM_SELECTABLE_THEMES = [
- "brand", "cosmos", "dune", "slate", "prism", "sunrise", "marine", "blossom", "mint", "macaron",
+ "plain", "brand", "cosmos", "dune", "slate", "prism", "sunrise", "marine", "blossom", "mint", "macaron",
] as const;
+export const DIAGRAM_DEFAULT_THEME = "plain" as const;
export const DIAGRAM_THEMES = [
- "brand", "ocean", "ink", "classic", "sky", "sunset", "violet", "rose", "sand", "slate", "aurora", "mono",
+ "plain", "brand", "ocean", "ink", "classic", "sky", "sunset", "violet", "rose", "sand", "slate", "aurora", "mono",
"sun", "wa", "island", "mint", "cosmos", "tea", "naive", "macaron", "paper",
"dune", "prism", "sunrise", "marine", "blossom",
] as const;
@@ -80,7 +81,9 @@ const THEME_ALIASES: Partial<Record<DiagramTheme, typeof DIAGRAM_SELECTABLE_THEM
export const resolveDiagramTheme = (theme?: DiagramTheme): typeof DIAGRAM_SELECTABLE_THEMES[number] => {
if (theme && (DIAGRAM_SELECTABLE_THEMES as readonly string[]).includes(theme)) return theme as typeof DIAGRAM_SELECTABLE_THEMES[number];
- return THEME_ALIASES[theme ?? "brand"] ?? "brand";
+ // A stored legacy id keeps its alias. Only a missing theme uses the plain default.
+ if (theme) return THEME_ALIASES[theme] ?? "brand";
+ return DIAGRAM_DEFAULT_THEME;
};
export const resolveDiagramStructure = (structure?: DiagramStructure): DiagramStructure => (
@@ -371,7 +374,10 @@ export const diagramDocumentToMermaid = (document: DiagramDocument) => {
const root = document.nodes.find((node) => node.shape === "topic" && !node.parentId);
const rootId = root ? nodeIds.get(root.id) : undefined;
if (rootId) {
- lines.push(" classDef mindRoot fill:#16A06E,stroke:#12845B,color:#fff,stroke-width:1.5px");
+ const rootStyle = resolveDiagramTheme(document.theme) === "plain"
+ ? "fill:#525252,stroke:#525252,color:#FFFFFF,stroke-width:1.5px"
+ : "fill:#16A06E,stroke:#12845B,color:#fff,stroke-width:1.5px";
+ lines.push(` classDef mindRoot ${rootStyle}`);
lines.push(` class ${rootId} mindRoot`);
}
}
@@ -387,6 +393,7 @@ export const createDefaultDiagramDocument = (kind: DiagramKind): DiagramDocument
return {
schemaVersion: DIAGRAM_SCHEMA_VERSION,
kind,
+ theme: DIAGRAM_DEFAULT_THEME,
nodes: [
{ id: "topic-root", label: "核心主题", x: 72, y: 168, width: 124, height: 46, shape: "topic" },
{ id: "topic-1", label: "采集想法", x: 268, y: 117, width: 96, height: 36, shape: "topic", parentId: "topic-root" },
@@ -429,6 +436,7 @@ export const createDefaultDiagramDocument = (kind: DiagramKind): DiagramDocument
return {
schemaVersion: DIAGRAM_SCHEMA_VERSION,
kind,
+ theme: DIAGRAM_DEFAULT_THEME,
nodes: [
{ id: "flow-start", label: "开始", x: 98, y: 48, width: 140, height: 44, shape: "terminator" },
{ id: "flow-process", label: "处理步骤", x: 80, y: 140, width: 176, height: 56, shape: "process" },
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index bdfdf188..9af61234 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -540,6 +540,7 @@ export const enUS = {
theme: "Color scheme",
themeGroupVivid: "Bright",
themeGroupClassic: "Quiet",
+ themePlain: "Plain",
themeBrand: "Forest",
themeCosmos: "Cosmos",
themeDune: "Dune",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index c2adaa40..65739e99 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -540,6 +540,7 @@ export const ja = {
theme: "配色",
themeGroupVivid: "鮮やか",
themeGroupClassic: "落ち着き",
+ themePlain: "素",
themeBrand: "森",
themeCosmos: "星空",
themeDune: "砂丘",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index b9dd6e62..6b215da6 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -540,6 +540,7 @@ export const zhCN = {
theme: "配色",
themeGroupVivid: "鲜亮",
themeGroupClassic: "沉静",
+ themePlain: "素简",
themeBrand: "森绿",
themeCosmos: "夜航",
themeDune: "砂丘",
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index 1a392437..bc60dafd 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -34,6 +34,7 @@ export * from "./desktop-rpc";
export * from "./details";
export * from "./deployment-metadata";
export * from "./diagram";
+export * from "./diagram-canvas";
export * from "./infographic";
export * from "./table";
export * from "./diagram-palette";