Skip to content

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

Improve Mermaid diagram layout scrolling and zinc theme palette contrast

tianma-if761e78382376
diff --git a/apps/web/src/components/ThemeProvider.tsx b/apps/web/src/components/ThemeProvider.tsx
index c9dda8b4..6d4353f4 100644
--- a/apps/web/src/components/ThemeProvider.tsx
+++ b/apps/web/src/components/ThemeProvider.tsx
@@ -1,4 +1,5 @@
import { createContext, useCallback, useContext, useEffect, useMemo, useState, type ReactNode } from "react";
+import { DIAGRAM_CANVAS_DARK, DIAGRAM_CANVAS_LIGHT } from "@edgeever/shared";
import {
DEFAULT_CUSTOM_DARK_COLORS,
DEFAULT_CUSTOM_EDITOR_THEME,
@@ -50,8 +51,24 @@ export interface MermaidThemePalette {
}
export const MERMAID_THEME_PALETTES: Record<MermaidThemeName, MermaidThemePalette> = {
- "zinc-light": { bg: "#FFFFFF", fg: "#27272A", line: "#a1a1aa", accent: "#52525b", muted: "#71717a" },
- "zinc-dark": { bg: "#18181B", fg: "#FAFAFA", line: "#52525b", accent: "#a1a1aa", muted: "#a1a1aa" },
+ "zinc-light": {
+ bg: DIAGRAM_CANVAS_LIGHT,
+ fg: "#27272A",
+ line: "#52525b",
+ accent: "#52525b",
+ muted: "#3f3f46",
+ surface: "#ffffff",
+ border: "#d4d4d8",
+ },
+ "zinc-dark": {
+ bg: DIAGRAM_CANVAS_DARK,
+ fg: "#FAFAFA",
+ line: "#8b938c",
+ accent: "#d4d4d8",
+ muted: "#d4d4d8",
+ surface: "#242b27",
+ border: "#3d4741",
+ },
"tokyo-night": { bg: "#1a1b26", fg: "#a9b1d6", line: "#3d59a1", accent: "#7aa2f7", muted: "#7c85ac" },
"tokyo-night-storm": { bg: "#24283b", fg: "#a9b1d6", line: "#3d59a1", accent: "#7aa2f7", muted: "#8991b8" },
"tokyo-night-light": { bg: "#d5d6db", fg: "#343b58", line: "#34548a", accent: "#34548a", muted: "#545a71" },
diff --git a/apps/web/src/lib/mermaid-theme.test.mjs b/apps/web/src/lib/mermaid-theme.test.mjs
index e5776899..884c8def 100644
--- a/apps/web/src/lib/mermaid-theme.test.mjs
+++ b/apps/web/src/lib/mermaid-theme.test.mjs
@@ -28,14 +28,25 @@ describe("official Mermaid theme variables", () => {
}
});
- test("keeps the zinc light theme coherent", () => {
- const palette = MERMAID_THEME_PALETTES["zinc-light"];
- const variables = getOfficialMermaidThemeVariables(palette);
-
- expect(variables.background).toBe(palette.bg);
- expect(variables.primaryColor).toBe(palette.bg);
- expect(variables.primaryBorderColor).toBe(palette.muted);
- expect(variables.signalColor).toBe(palette.accent);
+ test("keeps the default themes on the note surface with a solid node plate", () => {
+ const light = MERMAID_THEME_PALETTES["zinc-light"];
+ const dark = MERMAID_THEME_PALETTES["zinc-dark"];
+ const lightVariables = getOfficialMermaidThemeVariables(light);
+
+ expect(light.bg).toBe("#f8fafb");
+ expect(light.fg).toBe("#27272A");
+ expect(light.muted).toBe("#3f3f46");
+ expect(light.line).toBe("#52525b");
+ expect(light.surface).toBe("#ffffff");
+ expect(light.border).toBe("#d4d4d8");
+ expect(lightVariables.background).toBe(light.bg);
+ expect(lightVariables.primaryColor).toBe(light.surface);
+ expect(lightVariables.primaryTextColor).toBe(light.fg);
+ expect(lightVariables.primaryBorderColor).toBe(light.border);
+ expect(lightVariables.lineColor).toBe(light.line);
+ expect(dark.bg).toBe("#191e1b");
+ expect(dark.surface).toBe("#242b27");
+ expect(dark.muted).toBe("#d4d4d8");
});
test("keeps primary and secondary diagram text readable in every theme", () => {
@@ -43,6 +54,9 @@ describe("official Mermaid theme variables", () => {
expect(contrastRatio(palette.fg, palette.bg), `${theme} primary text`).toBeGreaterThanOrEqual(4.5);
expect(palette.muted, `${theme} secondary text color`).toBeDefined();
expect(contrastRatio(palette.muted, palette.bg), `${theme} secondary text`).toBeGreaterThanOrEqual(4.5);
+ if (palette.surface) {
+ expect(contrastRatio(palette.fg, palette.surface), `${theme} node text`).toBeGreaterThanOrEqual(4.5);
+ }
}
});
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index ddd06b8b..8d87a4a1 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -1700,13 +1700,6 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
background: transparent;
}
-@media (min-width: 1280px) {
- .ProseMirror .edgeever-mermaid-code-block {
- max-width: min(60vw, 52rem);
- margin-inline: auto;
- }
-}
-
.ProseMirror .edgeever-mermaid-toolbar {
position: absolute;
top: 0.5rem;
@@ -1715,7 +1708,7 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
display: flex;
gap: 0.25rem;
padding: 0.25rem;
- border: 1px solid #d9e2dc;
+ border: 1px solid #e3ece7;
border-radius: 7px;
background: rgb(255 255 255 / 0.94);
box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
@@ -1766,15 +1759,15 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
display: flex;
max-height: min(70vh, 44rem);
min-height: 6rem;
- align-items: center;
- justify-content: center;
+ align-items: flex-start;
+ justify-content: flex-start;
overflow: auto;
overscroll-behavior-x: contain;
overscroll-behavior-y: auto;
- padding: 3.25rem 1rem 1rem;
- border: 1px solid #d9e2dc;
+ padding: 1rem;
+ border: 1px solid #e3ece7;
border-radius: 8px;
- background: #fbfdfb;
+ background: var(--workspace-editor);
scrollbar-color: var(--scrollbar-thumb) transparent;
}
@@ -1791,8 +1784,9 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
.ProseMirror .edgeever-mermaid-svg {
display: flex;
- width: 100%;
- min-width: 0;
+ width: max-content;
+ min-width: 100%;
+ flex: none;
align-self: flex-start;
justify-content: center;
}
@@ -1800,9 +1794,19 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
.ProseMirror .edgeever-mermaid-svg svg {
display: block;
width: auto;
- max-width: 100%;
+ max-width: none;
height: auto;
- max-height: 30rem;
+ max-height: none;
+ flex: none;
+}
+
+.ProseMirror .edgeever-mermaid-svg text {
+ font-family: var(--editor-body-font-family, var(--edgeever-system-font-family));
+ font-synthesis: weight;
+}
+
+.ProseMirror .edgeever-mermaid-svg text[font-weight="500"] {
+ font-weight: 550;
}
.ProseMirror .edgeever-mermaid-source {
@@ -2735,10 +2739,6 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
height: 2.75rem;
flex-basis: 2.75rem;
}
-
- .ProseMirror .edgeever-mermaid-preview {
- padding-top: 4rem;
- }
}
@media (prefers-reduced-motion: reduce) {
diff --git a/apps/web/src/styles/mermaid-layout.test.mjs b/apps/web/src/styles/mermaid-layout.test.mjs
index dc43b52d..d355631a 100644
--- a/apps/web/src/styles/mermaid-layout.test.mjs
+++ b/apps/web/src/styles/mermaid-layout.test.mjs
@@ -3,17 +3,29 @@ import { readFileSync } from "node:fs";
const globals = readFileSync(new URL("./globals.css", import.meta.url), "utf8");
+const mobile = readFileSync(new URL("./mobile-markdown-editor.css", import.meta.url), "utf8");
+
describe("Mermaid editor layout", () => {
- test("caps wide-screen diagram blocks without narrowing compact viewports", () => {
+ test("uses the note column and scrolls wide diagrams at their drawn size", () => {
+ expect(globals).not.toContain("max-width: min(60vw, 52rem)");
expect(globals).toMatch(
- /@media \(min-width: 1280px\)\s*{\s*\.ProseMirror \.edgeever-mermaid-code-block\s*{[^}]*max-width: min\(60vw, 52rem\);[^}]*margin-inline: auto;/s,
+ /\.ProseMirror \.edgeever-mermaid-preview\s*{[^}]*max-height: min\(70vh, 44rem\);[^}]*overflow: auto;/s,
);
- });
-
- test("keeps rendered diagrams within the capped block", () => {
expect(globals).toMatch(
- /\.ProseMirror \.edgeever-mermaid-svg svg\s*{[^}]*width: auto;[^}]*max-width: 100%;[^}]*max-height: 30rem;/s,
+ /\.ProseMirror \.edgeever-mermaid-svg svg\s*{[^}]*width: auto;[^}]*max-width: none;[^}]*max-height: none;/s,
);
+ expect(globals).toMatch(
+ /\.ProseMirror \.edgeever-mermaid-svg text\s*{[^}]*font-family: var\(--editor-body-font-family, var\(--edgeever-system-font-family\)\);[^}]*font-synthesis: weight;/s,
+ );
+ expect(globals).toContain('.ProseMirror .edgeever-mermaid-svg text[font-weight="500"]');
+ expect(globals).toContain("font-weight: 550;");
});
+ test("keeps the phone editor on the same readable diagram size", () => {
+ expect(mobile).toMatch(
+ /\.edgeever-mobile-tiptap-content \.edgeever-mermaid-svg svg\s*{[^}]*max-width: none;[^}]*max-height: none;/s,
+ );
+ expect(mobile).toContain("font-weight: 550;");
+ expect(mobile).not.toContain("max-height: 440px");
+ });
});
diff --git a/apps/web/src/styles/mobile-markdown-editor.css b/apps/web/src/styles/mobile-markdown-editor.css
index 6a2f2f1c..cd9f21ff 100644
--- a/apps/web/src/styles/mobile-markdown-editor.css
+++ b/apps/web/src/styles/mobile-markdown-editor.css
@@ -702,7 +702,7 @@ html.dark .edgeever-mobile-tiptap-content a:hover {
display: flex;
gap: 0.25rem;
padding: 0.25rem;
- border: 1px solid #d9e2dc;
+ border: 1px solid #e3ece7;
border-radius: 7px;
background: rgb(255 255 255 / 0.94);
box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
@@ -748,22 +748,23 @@ html.dark .edgeever-mobile-tiptap-content a:hover {
display: flex;
max-height: min(70vh, 36rem);
min-height: 6rem;
- align-items: center;
- justify-content: center;
+ align-items: flex-start;
+ justify-content: flex-start;
overflow: auto;
overscroll-behavior-x: contain;
overscroll-behavior-y: auto;
- padding: 4rem 0.75rem 0.75rem;
- border: 1px solid #d9e2dc;
+ padding: 1rem 0.75rem 0.75rem;
+ border: 1px solid #e3ece7;
border-radius: 8px;
- background: #fbfdfb;
+ background: var(--workspace-editor, #f8fafb);
scrollbar-color: rgb(100 116 139 / 0.35) transparent;
}
.edgeever-mobile-tiptap-content .edgeever-mermaid-svg {
display: flex;
- width: 100%;
- min-width: 0;
+ width: max-content;
+ min-width: 100%;
+ flex: none;
align-self: flex-start;
justify-content: center;
}
@@ -771,9 +772,19 @@ html.dark .edgeever-mobile-tiptap-content a:hover {
.edgeever-mobile-tiptap-content .edgeever-mermaid-svg svg {
display: block;
width: auto;
- max-width: 100%;
+ max-width: none;
height: auto;
- max-height: 440px;
+ max-height: none;
+ flex: none;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-svg text {
+ font-family: var(--editor-body-font-family, var(--edgeever-system-font-family, -apple-system, "PingFang SC", "Noto Sans SC", sans-serif));
+ font-synthesis: weight;
+}
+
+.edgeever-mobile-tiptap-content .edgeever-mermaid-svg text[font-weight="500"] {
+ font-weight: 550;
}
.edgeever-mobile-tiptap-content .edgeever-mermaid-source {