AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix: refine prose reading palettes for light and dark modes
tianma-ifd482d841acd8
diff --git a/apps/web/src/lib/wechat-copy.test.mjs b/apps/web/src/lib/wechat-copy.test.mjsindex 8e332fec..80171800 100644--- a/apps/web/src/lib/wechat-copy.test.mjs+++ b/apps/web/src/lib/wechat-copy.test.mjs@@ -38,11 +38,13 @@ const css = (element) => (element?.style.cssText ?? "").replace(/:\s+/g, ":");let preparePublishArticle;let prepareMarkdownPublishArticle;+let readEditorCopyContext;beforeAll(async () => {const module = await import("./wechat-copy.ts");preparePublishArticle = module.preparePublishArticle;prepareMarkdownPublishArticle = module.prepareMarkdownPublishArticle;+ readEditorCopyContext = module.readEditorCopyContext;});const MARKDOWN = `@@ -69,6 +71,27 @@ curl -fsSL https://edgeever.org/install.sh | bash`;describe("preparePublishArticle", () => {+ test("exports a light reading accent from a dark editor", () => {+ const container = document.createElement("div");+ container.dataset.notePalette = "violet";+ const previous = globalThis.getComputedStyle;+ globalThis.getComputedStyle = () => ({+ getPropertyValue: (name) => ({+ "--note-palette-accent": "#B39AE8",+ "--note-palette-light-accent": "#7351CF",+ "--note-palette-text": "#3F3F46",+ })[name] ?? "",+ });+ try {+ const context = readEditorCopyContext(container);+ expect(context.colors.accent).toBe("#7351CF");+ const root = preparePublishArticle("<p><strong>重点</strong></p>", container);+ expect(css(root.querySelector("strong"))).toContain("color:#7351CF");+ } finally {+ globalThis.getComputedStyle = previous;+ }+ });+test("matches the light editor instead of the old rose-and-green paste", () => {const root = preparePublishArticle(["<blockquote><p>引用</p></blockquote>",diff --git a/apps/web/src/lib/wechat-copy.ts b/apps/web/src/lib/wechat-copy.tsindex 6afbf6e3..5bf55295 100644--- a/apps/web/src/lib/wechat-copy.ts+++ b/apps/web/src/lib/wechat-copy.ts@@ -1049,7 +1049,9 @@ export const readEditorCopyContext = (from?: HTMLElement | null) => {const palette = container?.dataset.notePalette;let colors: NoteProsePaletteColors | null = null;if (style && palette && palette !== "native") {- const accent = readPaletteColor(style, "--note-palette-accent");+ // Publishing uses a light surface even when the editor is in dark mode.+ const accent = readPaletteColor(style, "--note-palette-light-accent")+ || readPaletteColor(style, "--note-palette-accent");const text = readPaletteColor(style, "--note-palette-text");if (accent && text) {colors = {diff --git a/apps/web/src/styles/editor-typography.test.mjs b/apps/web/src/styles/editor-typography.test.mjsindex 596afd25..136c8c62 100644--- a/apps/web/src/styles/editor-typography.test.mjs+++ b/apps/web/src/styles/editor-typography.test.mjs@@ -77,7 +77,7 @@ describe("editor typography contract", () => {const boldRules = declarationsForSelector(prose, ".ProseMirror strong");expect(boldRules).toMatch(/color:\s*var\(--note-palette-accent\)/);- expect(prose).not.toMatch(/--note-palette-dark-accent/);+ expect(prose).toMatch(/--note-palette-accent:\s*var\(--note-palette-dark-accent\)\s*!important/);expect(prose).not.toContain('data-note-palette="custom"');});diff --git a/apps/web/src/styles/note-prose.css b/apps/web/src/styles/note-prose.cssindex 36b5f91e..6dc3802e 100644--- a/apps/web/src/styles/note-prose.css+++ b/apps/web/src/styles/note-prose.css@@ -1,6 +1,7 @@/* Named hues tint links, inline code, bold, and checked task boxes. Body, quotes, rules, tables, and code chrome stay native. */-:root.dark .edgeever-editor[data-note-palette="violet"] {- --note-palette-accent: #B39AE8 !important;+:root.dark .edgeever-editor[data-note-palette]:not([data-note-palette="native"]) {+ /* Override the light accent supplied by inline account prose variables. */+ --note-palette-accent: var(--note-palette-dark-accent) !important;}.edgeever-editor[data-note-palette]:not([data-note-palette="native"]) .ProseMirror a:not(.edgeever-attachment-link) {diff --git a/packages/shared/src/note-prose.test.mjs b/packages/shared/src/note-prose.test.mjsindex 51f5901a..457ff864 100644--- a/packages/shared/src/note-prose.test.mjs+++ b/packages/shared/src/note-prose.test.mjs@@ -1,6 +1,9 @@import { describe, expect, test } from "bun:test";import {MAX_NOTE_PROSE_CSS_BYTES,+ NOTE_PROSE_PALETTES,+ NOTE_PROSE_DARK_ACCENTS,+ noteProseCssVariables,NoteProseUpdateSchema,noteProseCodeFontSize,noteProseMigrationPatch,@@ -21,6 +24,38 @@ const emptyAccount = () => ({});describe("note prose", () => {+ test("checks reading contrast with an intentional bright teal emphasis exception", () => {+ const luminance = (hex) => {+ const channels = [1, 3, 5].map((offset) => {+ const value = parseInt(hex.slice(offset, offset + 2), 16) / 255;+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;+ });+ return channels[0] * 0.2126 + channels[1] * 0.7152 + channels[2] * 0.0722;+ };+ const contrast = (foreground, background) => {+ const values = [luminance(foreground), luminance(background)].sort((a, b) => a - b);+ return (values[1] + 0.05) / (values[0] + 0.05);+ };+ for (const [id, colors] of Object.entries(NOTE_PROSE_PALETTES)) {+ for (const background of ["#FFFFFF", "#F8FAFB"]) {+ // Teal emphasis intentionally stays close to the original bright hue.+ // It does not meet normal-text AA; links and code retain the 4.5 minimum.+ expect(contrast(colors.accent, background)).toBeGreaterThanOrEqual(id === "teal" ? 2.5 : 4.5);+ for (const foreground of [colors.link, colors.codeText]) {+ expect(contrast(foreground, background)).toBeGreaterThanOrEqual(4.5);+ }+ }+ for (const background of ["#222325", "#333638"]) {+ expect(contrast(NOTE_PROSE_DARK_ACCENTS[id], background)).toBeGreaterThanOrEqual(4.5);+ }+ const variables = noteProseCssVariables(resolveNoteProse({ palette: id }));+ expect(variables["--note-palette-accent"]).toBe(colors.accent);+ expect(variables["--note-palette-dark-accent"]).toBe(NOTE_PROSE_DARK_ACCENTS[id]);+ }+ expect(noteProseCssVariables(resolveNoteProse({ palette: "native" })))+ .not.toHaveProperty("--note-palette-dark-accent");+ });+test("maps retired editor themes onto color names and leaves the native theme unset", () => {expect(paletteForLegacyEditorTheme("stance")).toBe("clay");expect(paletteForLegacyEditorTheme("stub")).toBe("dawn");diff --git a/packages/shared/src/note-prose.ts b/packages/shared/src/note-prose.tsindex 49ea428f..2fd1c7df 100644--- a/packages/shared/src/note-prose.ts+++ b/packages/shared/src/note-prose.ts@@ -110,7 +110,7 @@ const palette = (colors: NoteProsePaletteColors): NoteProsePaletteColors => coloexport const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteColors> = {clay: palette({- accent: "#E02D32",+ accent: "#C13C42",text: "#374151",muted: "#374151",surface: "#FFF7F7",@@ -121,7 +121,7 @@ export const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteColbackground: "#FFFFFF",}),orange: palette({- accent: "#E07A2D",+ accent: "#A65B24",text: "#3A2E28",muted: "#746055",surface: "#FFF4EA",@@ -132,7 +132,7 @@ export const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteColbackground: "#FFFFFF",}),dawn: palette({- accent: "#D9A521",+ accent: "#8A6716",text: "#3D2A1B",muted: "#74613C",surface: "#FFFDF8",@@ -143,18 +143,18 @@ export const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteColbackground: "#FFFFFF",}),teal: palette({- accent: "#22B8A7",+ accent: "#20AD9D",text: "#3E4C4A",muted: "#5C6E6B",surface: "#F2FBFA",divider: "#CDEFEA",- link: "#1A8F82",+ link: "#14796E",codeBackground: "#ECFBF8",- codeText: "#1A8F82",+ codeText: "#14796E",background: "#FFFFFF",}),azure: palette({- accent: "#2F80ED",+ accent: "#356CC4",text: "#374151",muted: "#4B5563",surface: "#F5F8FC",@@ -176,7 +176,7 @@ export const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteColbackground: "#FFFFFF",}),pink: palette({- accent: "#D4537E",+ accent: "#BB456E",text: "#3A2E34",muted: "#746068",surface: "#FDF2F6",@@ -187,7 +187,7 @@ export const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteColbackground: "#FFFFFF",}),slate: palette({- accent: "#89798B",+ accent: "#796B7C",text: "#5C505E",muted: "#5C505E",surface: "#FAFAFA",@@ -199,6 +199,18 @@ export const NOTE_PROSE_PALETTES: Record<NoteProsePaletteId, NoteProsePaletteCol}),};+// Dark reading surfaces need lighter accents than the white-background palette.+export const NOTE_PROSE_DARK_ACCENTS: Record<NoteProsePaletteId, string> = {+ clay: "#F08B8E",+ orange: "#E7A16A",+ dawn: "#D9B65C",+ teal: "#70C7B8",+ azure: "#8CB4F0",+ violet: "#B39AE8",+ pink: "#E794B0",+ slate: "#BCACBF",+};+const LEGACY_EDITOR_THEME_PALETTES: Record<string, NoteProsePaletteChoice> = {letter: "dawn",stub: "dawn",@@ -362,6 +374,10 @@ export const noteProseCssVariables = (prose: ResolvedNoteProse): Record<string,const colors = noteProsePaletteColors(prose);if (!colors) return variables;variables["--note-palette-accent"] = colors.accent;+ variables["--note-palette-light-accent"] = colors.accent;+ if (prose.palette !== "native") {+ variables["--note-palette-dark-accent"] = NOTE_PROSE_DARK_ACCENTS[prose.palette];+ }variables["--note-palette-text"] = colors.text;variables["--note-palette-muted"] = colors.muted;variables["--note-palette-surface"] = colors.surface;