Files
Zakk 4ef14859e8 perf(appearance): load non-default palettes on demand
Every palette family but Rose Pine now loads its stylesheet the way Glass
and Halloween already do: the first-paint script links a stored palette's
sheet before the main stylesheet, and a picked palette applies once its
sheet has loaded. paletteSheets.ts holds the seven sheets' URLs and links
them through paletteSheet.ts; useAppearance.ts imports it on demand, so
neither enters the startup bundle. vite.config.ts derives the stamped list
from the palette list, so every family but the default's is covered.

The sheets land before every other stylesheet, as they sat first in
theme.css before; only Rose Pine's :root defaults now follow them, and
each family's blocks outrank those, so every palette resolves as before.

E2e specs that switch palettes by writing the root's attributes link the
sheets first, and a new spec checks a stored palette's tokens on the
first frame and that the default palette loads none of the sheets.
2026-11-04 23:15:27 +00:00

4.3 KiB

Themes and palettes

English / 简体中文 / 繁體中文

The standard edition defines 16 palettes, each pairing light and dark colors. For choosing a palette, wallpaper or transparency setting, see appearance settings.

See the palette comparison for light and dark examples.

Source map

Source Responsibility
src/shell/palettes.ts Palette IDs, menu order, label keys, optional wording overrides and the default rose-pine/moon
src/shell/preferences.ts Stored palette validation and system, light or dark color scheme
src/shell/useAppearance.ts Apply data-family, data-flavour and data-scheme to the document root
src/ui/styles/palettes/ One CSS file per palette family, with light and dark tokens
src/ui/styles/palettes.css Import of the default family, rose-pine, which loads at startup
src/shell/glass.ts Load Glass styles and wallpaper when needed
src/shell/halloween.ts Load Halloween styles, card art and logo when needed
src/shell/paletteSheet.ts Link the stylesheet of a family that loads on demand
src/shell/paletteSheets.ts Stylesheets of the other token-only families, loaded on demand
src/ui/charts/palette.ts Read CSS tokens for charts and observe palette changes

Palette contract

A palette ID has the form family/flavour. A single-flavour family repeats the name, as in nord/nord. CSS selectors use those two values and data-scheme to select tokens. Components consume the shared --rp-* tokens.

Each palette supplies surface, text, accent, chart, highlight and shadow tokens. The complete token table and contrast rules are in Add a palette. tools/palettes.test.mjs checks family files, imports and required tokens.

Glass tokens load through src/ui/styles/glass.css, alongside the material styles. Preserve this separate loading path when changing a Glass palette. The Halloween stylesheet, with its card art and the logo it swaps in, loads the same way, only for that palette.

In the Qiangguo palette, a running state reads Improving; unavailable and degraded states read Severe test. In the Halloween palette they read Haunting and Cursed. These wording overrides are defined in src/shell/palettes.ts and the locale catalogues.

Add or update a palette

  1. Update src/shell/palettes.ts and the family stylesheet. Register a new family in the sheets map of src/shell/paletteSheets.ts and in the families map of src/shell/useAppearance.ts, which load it on demand; only the default family is imported from src/ui/styles/palettes.css.
  2. Add label keys to src/i18n/locales/. An optional words map in the registry redirects existing translation keys to palette-specific ones.
  3. Keep family images beside the stylesheet under src/ui/styles/palettes/<family>/. Record their sources and licences in NOTICE and REUSE.toml.
  4. Update the palette map in e2e/contrast.spec.ts. Run the palette and contrast checks required by CONTRIBUTING.md, and inspect both schemes. The contrast spec excludes translucent Glass surfaces from its numeric checks.