Files
Menghuan1918 040b182b1c refactor(theme): One Dark/Light 语法色板单源化
新增 src/client/one-dark-palette.ts,作为 one-dark / one-light 两套语法
色系的唯一来源:TerminalView 的 ANSI 16 与 cm-themes 的 CodeMirror 高亮
规则改为从色板常量组装各自的映射(ANSI 槽位 / lezer tag 到色相的映射
仍留在各消费方——两边的角色映射本就不同)。

行为不变的纯重构:每个 hex/rgba 迁移前后逐字节一致(旧新片段在桩
tags 下求值深度比对相等;产物 hex 清单无删除、非色板 hex 计数零变化)。
TerminalView 的 token 兜底色与 cm-themes 的 selection/activeLine rgba
与语法色系无关,保留原处未合并。

chunk 边界:色板为纯常量,被 terminal / editor 两个懒 chunk 各自内联
(每 chunk 约 200B 字面量),不引入跨 chunk import;核心 bundle
(client.js / client-registry.js)对该模块零引用(grep 产物验证)。
tests/one-dark-palette.spec.ts 钉住色板字面量防意外漂移。
2026-09-03 19:59:00 +08:00

63 lines
2.2 KiB
TypeScript

/**
* The single source for the syntax color families the app's code surfaces
* use: one-dark for the dark scheme, one-light for the light scheme. Two
* lazy-chunk consumers assemble their theme objects from these constants —
* the terminal's curated ANSI 16 (TerminalView.tsx) and CodeMirror's
* highlight rules (cm-themes.ts) — so a family color is defined exactly
* once and the two views can never drift apart.
*
* The palette holds only the syntax hues; surface colors (background,
* foreground, caret, gutter) are theme-token driven and selection tints /
* token-fallback colors stay with their consumers (they are not part of
* the designed syntax families).
*
* Chunk boundary: this module is inlined into BOTH lazy chunks that import
* it (terminal and editor) — the constants are plain strings, the per-chunk
* copy is a few hundred bytes, and no cross-chunk import is introduced. The
* core bundle does not (and must not) import this module.
*/
/** one-dark family (dark scheme) syntax hues. */
export const ONE_DARK = {
/** Editor-background tone; ANSI black. */
black: '#282c34',
/** Default foreground gray; ANSI white. */
gray: '#abb2bf',
/** Comment gray; ANSI bright black. */
faintGray: '#5c6370',
/** Pure white; ANSI bright white and the invalid-token color. */
white: '#ffffff',
red: '#e06c75',
green: '#98c379',
yellow: '#e5c07b',
blue: '#61afef',
magenta: '#c678dd',
cyan: '#56b6c2',
/** Numbers, bools, atoms, attribute names. */
orange: '#d19a66',
} as const
/** one-light family (light scheme) syntax hues. */
export const ONE_LIGHT = {
/** Foreground dark; ANSI black and the operator color. */
black: '#383a42',
/** Comment gray; ANSI white. */
gray: '#a0a1a7',
/** ANSI bright black. */
faintGray: '#4f525e',
/** Pure white; the invalid-token color (stays white in light for contrast). */
white: '#ffffff',
/** Off-white; ANSI bright white. */
offWhite: '#fafafa',
red: '#e45649',
green: '#50a14f',
yellow: '#c18401',
blue: '#0184bc',
magenta: '#a626a4',
cyan: '#0997b3',
/** Numbers and attribute names. */
orange: '#986801',
/** Markdown links — the light family's dedicated link blue (dark rides blue). */
link: '#4078f2',
} as const