Feature:新增多套应用配色主题 (#2559)

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
zipgandstaff authored and GitHub committed 2026-07-05 00:34:47 +08:00
1 parent 896580f1c5
commit 5c35755219
27 files changed
+1884 -99

No files matched your search

+407 -7
View File
@@ -1,6 +1,6 @@
import type { Extension } from "@codemirror/state";
import type { EditorTheme, CustomThemeColors } from "@/stores/settingsStore";
import type { AppThemeAppearance } from "@/lib/app/appTheme";
import type { AppThemeAppearance, AppThemePalette } from "@/lib/app/appTheme";
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
import { tags } from "@lezer/highlight";
@@ -54,7 +54,7 @@ function createCustomTheme(EditorView: typeof import("@codemirror/view").EditorV
// 根据系统主题设置默认背景色和前景色
const defaultColors = isDark ? { background: "#1e1e2e", foreground: "#cdd6f4" } : { background: "#fafafa", foreground: "#242424" };
const c = { ...defaultColors, ...customThemeColors, ...(colors || {}) };
const c = { ...defaultColors, ...customThemeColors, ...colors };
// 映射用户自定义属性名到 CodeMirror 内部属性名
if (colors) {
@@ -179,6 +179,371 @@ function createCustomTheme(EditorView: typeof import("@codemirror/view").EditorV
return [theme, syntaxHighlighting(highlightStyle)];
}
type IdeEditorThemeColors = {
dark: boolean;
background: string;
foreground: string;
selection: string;
selectionMatch: string;
cursor: string;
gutterBackground: string;
gutterForeground: string;
gutterActiveForeground: string;
activeLine: string;
matchingBracket: string;
gutterBorder: string;
keyword: string;
string: string;
number: string;
comment: string;
type: string;
variable: string;
function: string;
operator: string;
punctuation: string;
property: string;
builtin: string;
meta: string;
invalid: string;
tag: string;
attribute: string;
className: string;
keywordBold?: boolean;
stringBold?: boolean;
numberBold?: boolean;
};
const IDE_EDITOR_THEMES = {
ideaLight: {
dark: false,
background: "#ffffff",
foreground: "#080808",
selection: "#a6d2ff",
selectionMatch: "#93d9d9",
cursor: "#000000",
gutterBackground: "#f2f2f2",
gutterForeground: "#adadad",
gutterActiveForeground: "#767a8a",
activeLine: "#fcfaed",
matchingBracket: "#93d9d9",
gutterBorder: "#d4d4d4",
keyword: "#0033b3",
string: "#067d17",
number: "#1750eb",
comment: "#8c8c8c",
type: "#0033b3",
variable: "#174ad4",
function: "#00627a",
operator: "#080808",
punctuation: "#080808",
property: "#871094",
builtin: "#0033b3",
meta: "#9e880d",
invalid: "#f50000",
tag: "#0033b3",
attribute: "#871094",
className: "#174be6",
keywordBold: true,
stringBold: true,
numberBold: true,
},
ideaDark: {
dark: true,
background: "#2b2b2b",
foreground: "#a9b7c6",
selection: "#214283",
selectionMatch: "#3b514d",
cursor: "#bbbbbb",
gutterBackground: "#313335",
gutterForeground: "#606366",
gutterActiveForeground: "#a4a3a3",
activeLine: "#323232",
matchingBracket: "#3b514d",
gutterBorder: "#4d4d4d",
keyword: "#cc7832",
string: "#6a8759",
number: "#6897bb",
comment: "#808080",
type: "#a9b7c6",
variable: "#a9b7c6",
function: "#ffc66d",
operator: "#cc7832",
punctuation: "#a9b7c6",
property: "#9876aa",
builtin: "#cc7832",
meta: "#bbb529",
invalid: "#ff0000",
tag: "#e8bf6a",
attribute: "#bababa",
className: "#a9b7c6",
},
jetbrainsLight: {
dark: false,
background: "#ffffff",
foreground: "#080808",
selection: "#a6d2ff",
selectionMatch: "#c9ecec",
cursor: "#000000",
gutterBackground: "#ffffff",
gutterForeground: "#aeb3c2",
gutterActiveForeground: "#767a8a",
activeLine: "#f5f8fe",
matchingBracket: "#93d9d9",
gutterBorder: "#ebecf0",
keyword: "#0033b3",
string: "#067d17",
number: "#1750eb",
comment: "#8c8c8c",
type: "#0033b3",
variable: "#174ad4",
function: "#00627a",
operator: "#080808",
punctuation: "#080808",
property: "#871094",
builtin: "#0033b3",
meta: "#9e880d",
invalid: "#f50000",
tag: "#0033b3",
attribute: "#871094",
className: "#174be6",
keywordBold: true,
stringBold: true,
numberBold: true,
},
jetbrainsDark: {
dark: true,
background: "#1e1f22",
foreground: "#bcbec4",
selection: "#2e436e",
selectionMatch: "#114957",
cursor: "#ced0d6",
gutterBackground: "#1e1f22",
gutterForeground: "#4b5059",
gutterActiveForeground: "#a1a3ab",
activeLine: "#26282e",
matchingBracket: "#43454a",
gutterBorder: "#313438",
keyword: "#cf8e6d",
string: "#6aab73",
number: "#2aacb8",
comment: "#7a7e85",
type: "#cf8e6d",
variable: "#bcbec4",
function: "#56a8f5",
operator: "#bcbec4",
punctuation: "#bcbec4",
property: "#c77dbb",
builtin: "#cf8e6d",
meta: "#b3ae60",
invalid: "#f75464",
tag: "#2fbaa3",
attribute: "#b3ae60",
className: "#56a8f5",
},
cursorLight: {
dark: false,
background: "#fcfcfc",
foreground: "#141414eb",
selection: "#1414141e",
selectionMatch: "#14141411",
cursor: "#141414eb",
gutterBackground: "#fcfcfc",
gutterForeground: "#1414147a",
gutterActiveForeground: "#141414ad",
activeLine: "#ededed",
matchingBracket: "#1414141e",
gutterBorder: "#14141413",
keyword: "#b3003f",
string: "#9e94d5",
number: "#b8448b",
comment: "#141414ad",
type: "#206595",
variable: "#206595",
function: "#db704b",
operator: "#b3003f",
punctuation: "#141414eb",
property: "#1f8a65",
builtin: "#206595",
meta: "#1f8a65",
invalid: "#cf2d56",
tag: "#206595",
attribute: "#6049b3",
className: "#206595",
},
cursorDark: {
dark: true,
background: "#181818",
foreground: "#e4e4e4eb",
selection: "#40404099",
selectionMatch: "#404040cc",
cursor: "#e4e4e4eb",
gutterBackground: "#181818",
gutterForeground: "#e4e4e442",
gutterActiveForeground: "#e4e4e4eb",
activeLine: "#262626",
matchingBracket: "#e4e4e41e",
gutterBorder: "#e4e4e413",
keyword: "#82d2ce",
string: "#e394dc",
number: "#ebc88d",
comment: "#e4e4e45e",
type: "#efb080",
variable: "#87c3ff",
function: "#efb080",
operator: "#d6d6dd",
punctuation: "#d6d6dd",
property: "#82d2ce",
builtin: "#a8cc7c",
meta: "#a8cc7c",
invalid: "#e34671",
tag: "#82d2ce",
attribute: "#aaa0fa",
className: "#efb080",
},
claudeLight: {
dark: false,
background: "#fffdf8",
foreground: "#302820",
selection: "#ead8c6",
selectionMatch: "#e7d8c8",
cursor: "#b86b3c",
gutterBackground: "#f8f1e9",
gutterForeground: "#9a7f66",
gutterActiveForeground: "#5f4b3a",
activeLine: "#f4e9de",
matchingBracket: "#e2c9b1",
gutterBorder: "#ddcdbb",
keyword: "#9a4f2e",
string: "#4f7d5d",
number: "#2d6f91",
comment: "#8c745f",
type: "#7a5aa8",
variable: "#3e5f75",
function: "#b86b3c",
operator: "#6b5544",
punctuation: "#6b5544",
property: "#9a4f2e",
builtin: "#4f7d5d",
meta: "#8f6b2e",
invalid: "#c3493d",
tag: "#7a5aa8",
attribute: "#b86b3c",
className: "#7a5aa8",
},
claudeDark: {
dark: true,
background: "#211f1c",
foreground: "#d8d0c4",
selection: "#44382f",
selectionMatch: "#564539",
cursor: "#d28a5f",
gutterBackground: "#1b1917",
gutterForeground: "#8f7f70",
gutterActiveForeground: "#d8d0c4",
activeLine: "#2a2723",
matchingBracket: "#564539",
gutterBorder: "#7f6c5b59",
keyword: "#d28a5f",
string: "#74b195",
number: "#65a1c6",
comment: "#a39686",
type: "#a08fcd",
variable: "#d8d0c4",
function: "#d69a6b",
operator: "#e0d0c0",
punctuation: "#c9b9a7",
property: "#d28a5f",
builtin: "#74b195",
meta: "#d4ae63",
invalid: "#e2675f",
tag: "#a08fcd",
attribute: "#d69a6b",
className: "#a08fcd",
},
} satisfies Record<string, IdeEditorThemeColors>;
function createIdeEditorTheme(EditorView: typeof import("@codemirror/view").EditorView, c: IdeEditorThemeColors): Extension {
const theme = EditorView.theme(
{
"&": {
backgroundColor: c.background,
color: c.foreground,
[EDITOR_SELECTION_BACKGROUND_CSS_VAR]: c.selection,
},
".cm-scroller": {
backgroundColor: c.background,
},
".cm-content": {
caretColor: c.cursor,
},
".cm-cursor": {
borderLeftColor: c.cursor,
},
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
backgroundColor: c.selection,
},
".cm-selectionMatch": {
backgroundColor: c.selectionMatch,
},
".cm-activeLine": {
backgroundColor: c.activeLine,
},
".cm-gutters": {
backgroundColor: c.gutterBackground,
borderRight: `1px solid ${c.gutterBorder}`,
color: c.gutterForeground,
},
".cm-activeLineGutter": {
backgroundColor: c.activeLine,
color: c.gutterActiveForeground,
},
".cm-matchingBracket": {
backgroundColor: c.matchingBracket,
outline: "none",
},
},
{ dark: c.dark },
);
const highlightStyle = HighlightStyle.define([
{ tag: [tags.keyword, tags.controlKeyword, tags.definitionKeyword, tags.moduleKeyword, tags.operatorKeyword, tags.modifier, tags.bool, tags.null], color: c.keyword, ...(c.keywordBold ? { fontWeight: "bold" } : {}) },
{ tag: [tags.string, tags.special(tags.string), tags.regexp, tags.escape, tags.inserted], color: c.string, ...(c.stringBold ? { fontWeight: "bold" } : {}) },
{ tag: [tags.number, tags.integer, tags.float], color: c.number, ...(c.numberBold ? { fontWeight: "bold" } : {}) },
{ tag: [tags.comment, tags.lineComment, tags.blockComment, tags.quote], color: c.comment, fontStyle: "italic" },
{ tag: [tags.typeName, tags.typeOperator, tags.unit], color: c.type },
{ tag: [tags.name, tags.variableName, tags.definition(tags.variableName)], color: c.variable },
{ tag: [tags.function(tags.variableName), tags.function(tags.propertyName), tags.function(tags.name), tags.macroName], color: c.function },
{ tag: [tags.standard(tags.variableName), tags.special(tags.name)], color: c.builtin },
{ tag: [tags.propertyName, tags.labelName, tags.annotation], color: c.property },
{ tag: [tags.operator, tags.compareOperator, tags.logicOperator, tags.arithmeticOperator, tags.derefOperator], color: c.operator },
{ tag: [tags.punctuation, tags.separator, tags.paren, tags.brace, tags.bracket, tags.angleBracket], color: c.punctuation },
{ tag: tags.tagName, color: c.tag },
{ tag: tags.attributeName, color: c.attribute },
{ tag: tags.attributeValue, color: c.string },
{ tag: [tags.className, tags.namespace], color: c.className },
{ tag: [tags.meta, tags.processingInstruction], color: c.meta },
{ tag: tags.invalid, color: c.invalid },
{ tag: [tags.heading, tags.heading1, tags.heading2, tags.heading3], color: c.keyword, fontWeight: "bold" },
{ tag: tags.strong, color: c.foreground, fontWeight: "bold" },
{ tag: tags.emphasis, color: c.foreground, fontStyle: "italic" },
{ tag: [tags.link, tags.url], color: c.type, textDecoration: "underline" },
{ tag: tags.literal, color: c.string },
{ tag: tags.deleted, color: c.invalid },
{ tag: tags.changed, color: c.property },
{ tag: tags.self, color: c.keyword },
{ tag: tags.list, color: c.foreground },
{ tag: tags.monospace, color: c.foreground },
{ tag: tags.strikethrough, color: c.invalid, textDecoration: "line-through" },
{ tag: tags.contentSeparator, color: c.operator },
]);
return [theme, syntaxHighlighting(highlightStyle)];
}
async function loadIdeEditorTheme(colors: IdeEditorThemeColors): Promise<Extension> {
return createIdeEditorTheme((await import("@codemirror/view")).EditorView, colors);
}
// ======================================================
const TABLE_ICON: LucideIconNode = [
@@ -242,15 +607,32 @@ export function cellDetailActiveLineColor(): string {
return colorMixValue("var(--accent)", "color-mix(in oklch, var(--foreground) 4%, transparent)");
}
/** Load a CodeMirror theme extension by theme name. */
export function resolveEditorTheme(theme: EditorTheme, appAppearance: AppThemeAppearance): Exclude<EditorTheme, "app"> {
if (theme === "app") return appAppearance === "dark" ? "one-dark" : "vscode-light";
/** Resolve the concrete CodeMirror theme used by the "Follow app theme" setting. */
export function resolveEditorTheme(theme: EditorTheme, appAppearance: AppThemeAppearance, appPalette: AppThemePalette = "pearl"): Exclude<EditorTheme, "app"> {
if (theme === "app") {
switch (appPalette) {
case "vscode":
return appAppearance === "dark" ? "vscode-dark" : "vscode-light";
case "idea":
return appAppearance === "dark" ? "idea-dark" : "idea-light";
case "xcode":
return appAppearance === "dark" ? "xcode-dark" : "xcode";
case "jetbrains":
return appAppearance === "dark" ? "jetbrains-dark" : "jetbrains-light";
case "cursor":
return appAppearance === "dark" ? "cursor-dark" : "cursor-light";
case "claude":
return appAppearance === "dark" ? "claude-dark" : "claude-light";
default:
return appAppearance === "dark" ? "one-dark" : "vscode-light";
}
}
return theme;
}
/** Load a CodeMirror theme extension by theme name. */
export async function loadEditorTheme(theme: EditorTheme, appAppearance: AppThemeAppearance = "dark", customColors?: CustomThemeColors): Promise<Extension> {
const resolvedTheme = resolveEditorTheme(theme, appAppearance);
export async function loadEditorTheme(theme: EditorTheme, appAppearance: AppThemeAppearance = "dark", customColors?: CustomThemeColors, appPalette: AppThemePalette = "pearl"): Promise<Extension> {
const resolvedTheme = resolveEditorTheme(theme, appAppearance, appPalette);
switch (resolvedTheme) {
case "one-dark":
return (await import("@codemirror/theme-one-dark")).oneDark;
@@ -270,6 +652,24 @@ export async function loadEditorTheme(theme: EditorTheme, appAppearance: AppThem
return (await import("@uiw/codemirror-theme-duotone")).duotoneDark;
case "xcode":
return (await import("@uiw/codemirror-theme-xcode")).xcodeLight;
case "xcode-dark":
return (await import("@uiw/codemirror-theme-xcode")).xcodeDark;
case "idea-light":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.ideaLight);
case "idea-dark":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.ideaDark);
case "jetbrains-light":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.jetbrainsLight);
case "jetbrains-dark":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.jetbrainsDark);
case "cursor-light":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.cursorLight);
case "cursor-dark":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.cursorDark);
case "claude-light":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.claudeLight);
case "claude-dark":
return loadIdeEditorTheme(IDE_EDITOR_THEMES.claudeDark);
case "custom":
return createCustomTheme((await import("@codemirror/view")).EditorView, customColors, appAppearance === "dark");
default: