Skip to content

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

feat(web): add a device-local font for the interface

tianma-if94666a8fd42a
diff --git a/apps/web/src/components/EditorOutline.tsx b/apps/web/src/components/EditorOutline.tsx
index f92dcb63..1e9e014d 100644
--- a/apps/web/src/components/EditorOutline.tsx
+++ b/apps/web/src/components/EditorOutline.tsx
@@ -273,10 +273,7 @@ export const EditorOutline = ({ editor, scrollContainer, collapsed, shortcutLabe
? "absolute right-2 top-6 z-10 h-8 w-8 overflow-hidden"
: "sticky top-6 h-fit max-h-[calc(100vh-8rem)] shrink-0 overflow-y-auto py-2"
)}
- style={{
- ...(!collapsed ? { width: EDITOR_OUTLINE_WIDTH } : {}),
- fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif',
- }}
+ style={!collapsed ? { width: EDITOR_OUTLINE_WIDTH } : undefined}
aria-label={t("editor.outline")}
>
<div className={cn("flex", collapsed ? "justify-center" : "mb-3 justify-between px-1")}>
diff --git a/apps/web/src/components/settings/PreferenceCard.test.mjs b/apps/web/src/components/settings/PreferenceCard.test.mjs
index 450b14ed..56c68c01 100644
--- a/apps/web/src/components/settings/PreferenceCard.test.mjs
+++ b/apps/web/src/components/settings/PreferenceCard.test.mjs
@@ -14,7 +14,12 @@ describe("editor body font preference", () => {
expect(fontFaces).toContain('fontFace("EdgeEver Kai"');
expect(fontFaces).toContain('fontFace("EdgeEver Song"');
expect(fontFaces).toContain("kai.woff2?url");
+ expect(preferenceCard).toContain('t("settings.uiFontTitle")');
+ expect(preferenceCard).toContain("applyUiFontPreference");
expect(editorFonts).toContain("html[data-editor-body-font] .edgeever-editor .ProseMirror");
+ expect(editorFonts).toContain("html[data-ui-font]");
+ expect(editorFonts).toContain("html[data-ui-font]:not([data-editor-body-font]) .edgeever-editor[data-editor-theme=\"default\"] .ProseMirror");
+ expect(editorFonts).toContain("html[data-ui-font] .edgeever-public-share");
expect(editorFonts).not.toContain(".edgeever-code-source");
for (const fileName of ["kai.woff2", "kai-screen.woff2", "song.woff2", "hei.woff2", "source-serif-4-regular.woff2", "OFL-lxgw-wenkai.txt", "OFL-source-han-serif.txt", "OFL-source-serif-4.txt"]) {
expect(existsSync(new URL(`../../assets/fonts/editor-body/${fileName}`, import.meta.url))).toBe(true);
diff --git a/apps/web/src/components/settings/PreferenceCard.tsx b/apps/web/src/components/settings/PreferenceCard.tsx
index a2333c7c..265f4e13 100644
--- a/apps/web/src/components/settings/PreferenceCard.tsx
+++ b/apps/web/src/components/settings/PreferenceCard.tsx
@@ -43,7 +43,9 @@ import {
readEditorBodyFontPreference,
writeEditorBodyFontPreference,
type EditorBodyFontChoice,
+ type EditorBodyFontPreference,
} from "@/lib/editor-body-font";
+import { applyUiFontPreference, readUiFontPreference, writeUiFontPreference } from "@/lib/ui-font";
import { syncPublishedNoteBodyFont } from "@/lib/published-note-body-font";
import { ShortcutSettingsItem } from "./ShortcutSettingsItem";
import { CustomEditorThemeDialog } from "./CustomEditorThemeDialog";
@@ -59,6 +61,49 @@ import {
type ThemePreference,
} from "../ThemeProvider";
+const FontChoiceFields = ({
+ label,
+ preference,
+ onChange,
+}: {
+ label: string;
+ preference: EditorBodyFontPreference;
+ onChange: (preference: EditorBodyFontPreference) => void;
+}) => {
+ const { t } = useTranslation();
+ return (
+ <div className="flex w-full shrink-0 flex-col gap-2 sm:w-80">
+ <Select
+ value={preference.choice}
+ onValueChange={(value) => onChange({ choice: value as EditorBodyFontChoice, customFamily: preference.customFamily })}
+ >
+ <SelectTrigger aria-label={label} className="h-9 bg-card">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="system">{t("settings.editorBodyFonts.system")}</SelectItem>
+ <SelectItem value="wenkai">{t("settings.editorBodyFonts.wenkai")}</SelectItem>
+ <SelectItem value="wenkai-screen">{t("settings.editorBodyFonts.wenkaiScreen")}</SelectItem>
+ <SelectItem value="source-han-serif">{t("settings.editorBodyFonts.sourceHanSerif")}</SelectItem>
+ <SelectItem value="source-han-sans">{t("settings.editorBodyFonts.sourceHanSans")}</SelectItem>
+ <SelectItem value="source-serif">{t("settings.editorBodyFonts.sourceSerif")}</SelectItem>
+ <SelectItem value="custom">{t("settings.editorBodyFonts.custom")}</SelectItem>
+ </SelectContent>
+ </Select>
+ {preference.choice === "custom" ? (
+ <Input
+ value={preference.customFamily}
+ aria-label={t("settings.editorBodyFontCustomLabel")}
+ placeholder={t("settings.editorBodyFontCustomPlaceholder")}
+ className="h-9"
+ maxLength={200}
+ onChange={(event) => onChange({ choice: "custom", customFamily: event.target.value })}
+ />
+ ) : null}
+ </div>
+ );
+};
+
interface PreferenceCardProps {
imageCompressionEnabled: boolean;
onImageCompressionChange: (enabled: boolean) => void;
@@ -93,6 +138,7 @@ export const PreferenceCard = ({
const [aiSelectionMenuEnabled, setAiSelectionMenuEnabled] = useState(readAiSelectionMenuPreference);
const [aiSpaceShortcutEnabled, setAiSpaceShortcutEnabled] = useState(readAiSpaceShortcutPreference);
const [editorBodyFont, setEditorBodyFont] = useState(readEditorBodyFontPreference);
+ const [uiFont, setUiFont] = useState(readUiFontPreference);
useEffect(() => {
const mediaQuery = window.matchMedia("(max-width: 640px)");
@@ -204,13 +250,19 @@ export const PreferenceCard = ({
void changeAppLocalePreference(preference);
};
- const updateEditorBodyFont = (preference: { choice: EditorBodyFontChoice; customFamily: string }) => {
+ const updateEditorBodyFont = (preference: EditorBodyFontPreference) => {
setEditorBodyFont(preference);
writeEditorBodyFontPreference(preference);
applyEditorBodyFontPreference(preference);
void syncPublishedNoteBodyFont();
};
+ const updateUiFont = (preference: EditorBodyFontPreference) => {
+ setUiFont(preference);
+ writeUiFontPreference(preference);
+ applyUiFontPreference(preference);
+ };
+
return (
<Card className="w-full min-w-0 overflow-hidden shadow-none">
<CardHeader className={SETTINGS_CARD_HEADER_CLASSNAME}>
@@ -305,35 +357,26 @@ export const PreferenceCard = ({
<div className={SETTINGS_ITEM_DESCRIPTION_CLASSNAME}>{t("settings.editorBodyFontDescription")}</div>
</div>
</div>
- <div className="flex w-full shrink-0 flex-col gap-2 sm:w-80">
- <Select
- value={editorBodyFont.choice}
- onValueChange={(value) => updateEditorBodyFont({ choice: value as EditorBodyFontChoice, customFamily: editorBodyFont.customFamily })}
- >
- <SelectTrigger aria-label={t("settings.editorBodyFontTitle")} className="h-9 bg-card">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="system">{t("settings.editorBodyFonts.system")}</SelectItem>
- <SelectItem value="wenkai">{t("settings.editorBodyFonts.wenkai")}</SelectItem>
- <SelectItem value="wenkai-screen">{t("settings.editorBodyFonts.wenkaiScreen")}</SelectItem>
- <SelectItem value="source-han-serif">{t("settings.editorBodyFonts.sourceHanSerif")}</SelectItem>
- <SelectItem value="source-han-sans">{t("settings.editorBodyFonts.sourceHanSans")}</SelectItem>
- <SelectItem value="source-serif">{t("settings.editorBodyFonts.sourceSerif")}</SelectItem>
- <SelectItem value="custom">{t("settings.editorBodyFonts.custom")}</SelectItem>
- </SelectContent>
- </Select>
- {editorBodyFont.choice === "custom" ? (
- <Input
- value={editorBodyFont.customFamily}
- aria-label={t("settings.editorBodyFontCustomLabel")}
- placeholder={t("settings.editorBodyFontCustomPlaceholder")}
- className="h-9"
- maxLength={200}
- onChange={(event) => updateEditorBodyFont({ choice: "custom", customFamily: event.target.value })}
- />
- ) : null}
+ <FontChoiceFields
+ label={t("settings.editorBodyFontTitle")}
+ preference={editorBodyFont}
+ onChange={updateEditorBodyFont}
+ />
+ </div>
+
+ <div className="flex min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
+ <div className="flex min-w-0 items-start gap-3">
+ <Type className={SETTINGS_ITEM_ICON_CLASSNAME} />
+ <div className="min-w-0">
+ <div className={SETTINGS_ITEM_TITLE_CLASSNAME}>{t("settings.uiFontTitle")}</div>
+ <div className={SETTINGS_ITEM_DESCRIPTION_CLASSNAME}>{t("settings.uiFontDescription")}</div>
+ </div>
</div>
+ <FontChoiceFields
+ label={t("settings.uiFontTitle")}
+ preference={uiFont}
+ onChange={updateUiFont}
+ />
</div>
{!isMobile && (
diff --git a/apps/web/src/lib/ui-font.test.mjs b/apps/web/src/lib/ui-font.test.mjs
new file mode 100644
index 00000000..555ab2f6
--- /dev/null
+++ b/apps/web/src/lib/ui-font.test.mjs
@@ -0,0 +1,86 @@
+import { afterEach, describe, expect, test } from "bun:test";
+import {
+ UI_FONT_CUSTOM_STORAGE_KEY,
+ UI_FONT_STORAGE_KEY,
+ applyUiFontPreference,
+ readUiFontPreference,
+ writeUiFontPreference,
+} from "./ui-font.ts";
+
+const installLocalStorage = () => {
+ const values = new Map();
+ globalThis.window = {
+ localStorage: {
+ getItem: (key) => values.get(key) ?? null,
+ setItem: (key, value) => values.set(key, String(value)),
+ },
+ };
+ return values;
+};
+
+describe("interface font preference", () => {
+ afterEach(() => {
+ delete globalThis.window;
+ delete globalThis.document;
+ });
+
+ test("defaults to the system face and ignores unknown choices", () => {
+ const values = installLocalStorage();
+ expect(readUiFontPreference()).toEqual({ choice: "system", customFamily: "" });
+
+ values.set(UI_FONT_STORAGE_KEY, "comic-sans");
+ expect(readUiFontPreference().choice).toBe("system");
+ });
+
+ test("persists a bundled face and a custom family independently of note text", () => {
+ const values = installLocalStorage();
+ writeUiFontPreference({ choice: "wenkai", customFamily: "霞鹜文楷" });
+ expect(values.get(UI_FONT_STORAGE_KEY)).toBe("wenkai");
+ expect(values.get(UI_FONT_CUSTOM_STORAGE_KEY)).toBe("霞鹜文楷");
+ expect(values.has("edgeever.editorBodyFont")).toBe(false);
+ expect(readUiFontPreference()).toEqual({ choice: "wenkai", customFamily: "霞鹜文楷" });
+ });
+
+ test("falls back when local storage is unavailable", () => {
+ globalThis.window = {
+ localStorage: {
+ getItem: () => {
+ throw new Error("blocked");
+ },
+ setItem: () => {
+ throw new Error("blocked");
+ },
+ },
+ };
+ expect(readUiFontPreference()).toEqual({ choice: "system", customFamily: "" });
+ expect(() => writeUiFontPreference({ choice: "source-han-sans", customFamily: "" })).not.toThrow();
+ });
+
+ test("publishes the resolved stack on the document and clears it for the system face", () => {
+ installLocalStorage();
+ const style = new Map();
+ const dataset = {};
+ globalThis.document = {
+ documentElement: {
+ dataset,
+ style: {
+ setProperty: (key, value) => style.set(key, value),
+ removeProperty: (key) => style.delete(key),
+ },
+ },
+ };
+
+ applyUiFontPreference({ choice: "custom", customFamily: "Songti SC" });
+ expect(dataset.uiFont).toBe("custom");
+ expect(style.get("--ui-font-family")).toContain("Songti SC");
+ expect(style.get("--ui-font-family")).toContain("PingFang SC");
+
+ applyUiFontPreference({ choice: "custom", customFamily: "bad; family" });
+ expect(dataset.uiFont).toBeUndefined();
+ expect(style.has("--ui-font-family")).toBe(false);
+
+ applyUiFontPreference({ choice: "system", customFamily: "" });
+ expect(dataset.uiFont).toBeUndefined();
+ expect(style.has("--ui-font-family")).toBe(false);
+ });
+});
diff --git a/apps/web/src/lib/ui-font.ts b/apps/web/src/lib/ui-font.ts
new file mode 100644
index 00000000..66b64d9c
--- /dev/null
+++ b/apps/web/src/lib/ui-font.ts
@@ -0,0 +1,58 @@
+import {
+ type EditorBodyFontChoice,
+ type EditorBodyFontPreference,
+ isEditorBodyFontChoice,
+ resolveEditorBodyFontStack,
+} from "./editor-body-font";
+
+export const UI_FONT_STORAGE_KEY = "edgeever.uiFont";
+export const UI_FONT_CUSTOM_STORAGE_KEY = "edgeever.uiFontCustom";
+
+export type UiFontChoice = EditorBodyFontChoice;
+export type UiFontPreference = EditorBodyFontPreference;
+
+const DEFAULT_PREFERENCE: UiFontPreference = {
+ choice: "system",
+ customFamily: "",
+};
+
+const readStorage = (key: string) => {
+ try {
+ return window.localStorage.getItem(key);
+ } catch {
+ return null;
+ }
+};
+
+const writeStorage = (key: string, value: string) => {
+ try {
+ window.localStorage.setItem(key, value);
+ } catch {
+ // Local storage can be unavailable in private or restricted browser contexts.
+ }
+};
+
+export const readUiFontPreference = (): UiFontPreference => {
+ const storedChoice = readStorage(UI_FONT_STORAGE_KEY);
+ const customFamily = readStorage(UI_FONT_CUSTOM_STORAGE_KEY) ?? "";
+ if (!isEditorBodyFontChoice(storedChoice)) return { ...DEFAULT_PREFERENCE, customFamily };
+ return { choice: storedChoice, customFamily };
+};
+
+export const writeUiFontPreference = (preference: UiFontPreference) => {
+ writeStorage(UI_FONT_STORAGE_KEY, preference.choice);
+ writeStorage(UI_FONT_CUSTOM_STORAGE_KEY, preference.customFamily.slice(0, 200));
+};
+
+export const applyUiFontPreference = (preference = readUiFontPreference()) => {
+ if (typeof document === "undefined") return;
+ const root = document.documentElement;
+ const stack = resolveEditorBodyFontStack(preference);
+ if (!stack) {
+ delete root.dataset.uiFont;
+ root.style.removeProperty("--ui-font-family");
+ return;
+ }
+ root.dataset.uiFont = preference.choice;
+ root.style.setProperty("--ui-font-family", stack);
+};
diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx
index 293d2301..84b7fad5 100644
--- a/apps/web/src/main.tsx
+++ b/apps/web/src/main.tsx
@@ -10,6 +10,7 @@ import { withEnvironmentTitlePrefix } from "./lib/environment-title";
import { initializeTheme, ThemeProvider } from "./components/ThemeProvider";
import { applyEditorBodyFontPreference } from "./lib/editor-body-font";
import { installEditorBodyFontFaces } from "./lib/editor-body-font-faces";
+import { applyUiFontPreference } from "./lib/ui-font";
import { DesktopRendererErrorBoundary } from "./components/DesktopRendererErrorBoundary";
import { reportDesktopRendererReadyAfterPaint } from "./lib/desktop-renderer-ready";
import "./styles/globals.css";
@@ -118,6 +119,7 @@ const mountApp = () => {
initializeTheme();
installEditorBodyFontFaces();
applyEditorBodyFontPreference();
+ applyUiFontPreference();
const Router = isDesktopRenderer ? HashRouter : BrowserRouter;
createRoot(root, {
diff --git a/apps/web/src/mobile-edit.tsx b/apps/web/src/mobile-edit.tsx
index bae0606c..81c08ab9 100644
--- a/apps/web/src/mobile-edit.tsx
+++ b/apps/web/src/mobile-edit.tsx
@@ -5,6 +5,7 @@ import { MobileStandaloneTiptapEditor } from "@/components/MobileStandaloneTipta
import { initializeTheme } from "@/components/ThemeProvider";
import { applyEditorBodyFontPreference } from "@/lib/editor-body-font";
import { installEditorBodyFontFaces } from "@/lib/editor-body-font-faces";
+import { applyUiFontPreference } from "@/lib/ui-font";
import { bootstrapI18n } from "@/i18n";
import { defaultLocale, getBrowserLocale } from "@/i18n/locales";
import "./styles/mobile-markdown-editor.css";
@@ -79,6 +80,7 @@ if (!root) {
initializeTheme();
installEditorBodyFontFaces();
applyEditorBodyFontPreference();
+applyUiFontPreference();
const queryClient = new QueryClient({
defaultOptions: { queries: { refetchOnWindowFocus: false, retry: 1, staleTime: 15_000 } },
diff --git a/apps/web/src/styles/editor-body-fonts.css b/apps/web/src/styles/editor-body-fonts.css
index e13d87ce..2a9825a7 100644
--- a/apps/web/src/styles/editor-body-fonts.css
+++ b/apps/web/src/styles/editor-body-fonts.css
@@ -14,3 +14,24 @@ html[data-editor-body-font] .edgeever-editor[data-editor-theme] .ProseMirror :is
html[data-editor-body-font] .edgeever-mobile-tiptap-content :is(h1, h2, h3, h4, h5, h6, p, li, blockquote, th, td) {
font-family: var(--editor-body-font-family);
}
+
+/* Interface font is the device chrome. A system note stays on the product
+ * sans stack, and a chosen note face still wins above. Themed editors keep
+ * their own family. Share pages stay on the sans stack so a viewer's
+ * interface font does not restyle the published note. */
+html[data-ui-font],
+html[data-ui-font] body {
+ font-family: var(--ui-font-family);
+ font-synthesis: weight style;
+}
+
+html[data-ui-font]:not([data-editor-body-font]) .edgeever-editor[data-editor-theme="default"] .ProseMirror,
+html[data-ui-font]:not([data-editor-body-font]) .edgeever-editor:not([data-editor-theme]) .ProseMirror,
+html[data-ui-font]:not([data-editor-body-font]) .edgeever-editor textarea[data-edgeever-mobile-editor="plain-textarea"],
+html[data-ui-font]:not([data-editor-body-font]) .edgeever-mobile-tiptap-content {
+ font-family: var(--edgeever-system-font-family);
+}
+
+html[data-ui-font] .edgeever-public-share {
+ font-family: var(--edgeever-system-font-family);
+}
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index 528f2b5d..bad43463 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -174,6 +174,7 @@ html.dark[data-edgeever-environment="demo"] body::after {
--blue-600-rgb: 37 99 235;
--dark-surface-rgb: 255 255 255;
--editor-body-font-size: 0.9375rem;
+ --edgeever-system-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Inter, ui-sans-serif, system-ui, sans-serif;
--editor-body-line-height: 1.6;
--editor-paragraph-spacing: 0.35rem;
--memo-content-divider-color: rgb(var(--brand-green-300-rgb));
@@ -2055,7 +2056,7 @@ textarea {
/* Standard Markdown Content Rendering Styles */
.markdown-content {
- font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
+ font-family: var(--ui-font-family, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
color: #1e293b;
line-height: 1.7;
word-break: break-word;
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 5f49254b..49e8730c 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -766,6 +766,8 @@ export const enUS = {
},
editorBodyFontCustomLabel: "Font name",
editorBodyFontCustomPlaceholder: "LXGW WenKai",
+ uiFontTitle: "Interface font",
+ uiFontDescription: "Changes interface text on this device.",
editorThemes: {
default: "Native theme",
letter: "Warm Page",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index b447ecd3..4dec0bf2 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -766,6 +766,8 @@ export const ja = {
},
editorBodyFontCustomLabel: "フォント名",
editorBodyFontCustomPlaceholder: "LXGW WenKai",
+ uiFontTitle: "画面のフォント",
+ uiFontDescription: "この端末の画面の文字だけを変えます。",
editorThemes: {
default: "標準テーマ",
letter: "あたたかな紙",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index b07b505f..49dc66ec 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -766,6 +766,8 @@ export const zhCN = {
},
editorBodyFontCustomLabel: "字体名称",
editorBodyFontCustomPlaceholder: "例如 LXGW WenKai",
+ uiFontTitle: "界面字体",
+ uiFontDescription: "只改变本机的界面文字。",
editorThemes: {
default: "原生主题",
letter: "日暖素笺",