Give themes named color roles, theme data files, and file format 3

Phase 5a-1 and 5a-2.

- roles.ts names 51 color roles. One derivation rule fills the roles
  that a theme does not give, for all themes. tokens.css keeps only the
  root defaults, without theme blocks.
- Each built-in theme is one data file in src/lib/theme/themes/. No code
  outside the theme data names a theme ID. characterThemes.ts is gone.
- New roles: link, focus, on-accent, highlight, scrim, the syntax roles,
  and 16 terminal (ANSI) roles. Stray colors in components use the roles.
- contrast.ts checks each theme against the readability rules of
  docs/ui-color.md. The tests mark the known palette failures as todo,
  and a second test fails when a known failure starts to pass.
- Theme files use schema 3 with a mode and an optional built-in base.
  A short file gets the missing colors and fonts from the base. Schema 1
  and 2 files still import. Old syntax names convert on import.
- Docs: ui-color.md, plugin-development.md (theme tokens), ui-design.md,
  guides/themes.md, and UI-041 and UI-042 in design-decisions.md.

The applied colors stay the same for every built-in theme, except three
small changes: the conflict line uses the warn color, the Write
highlight uses the highlight role, and two dialog backdrops use the
scrim role.

pnpm check passes. pnpm test: 447 pass, 31 todo, 0 fail. Full smoke
suite: 93 passed, 2 known. appearance/palettes read the old syntax
names and passed 3 of 3 times after the fix. workspace/manageTemplates
failed one time and passed on retry.
This commit is contained in:
Knotty Wyvern
2026-10-28 15:50:45 -07:00
parent af68d92969
commit 5bd616d7fd
55 changed files with 928 additions and 355 deletions
+37
View File
@@ -565,6 +565,7 @@ Replaced by: [UI-024](#ui-024--assertive-functional-color-by-default) strengthen
- Evidence: tests/smoke/settings/displayLanguage.smoke.mjs, tests/unit/theme/customThemes.spec.ts, and the affected cards retain checks and screenshots.
- Follow-up evidence: Cards 5a56a250-b46a-4319-8f25-5f6ac4362a32, 682ad51f-66a1-477d-b02e-c1acb1c14d4e, and 97fe6f6b-5780-436e-abd8-a8135efbbe87 cover the full range, themed slider, and missing font stacks. `tests/smoke/appearance/themeVariants.smoke.mjs` checks the exact controls and exports.
- Limits: Browser checks use desktop mocks. Native display and user acceptance remain open.
- Replaced by: [UI-042](#ui-042--theme-file-format-3-and-terminal-colors) replaces the template format. The transparency rule remains.
### UI-029 — Text selection transparency
@@ -773,3 +774,39 @@ Native shell, background image, and desktop acceptance remain open.
- Evidence files: output/smoke/editor/listNesting/.
- Replaces / replaced by: None.
- Limits: Source has no minimap, no command palette, and no bracket pair colors. Browser checks use desktop service mocks. Native desktop acceptance remains open.
### UI-041 — Theme roles and theme data
- Type: Rule change
- Date: 2026-10-28
- Status: Implemented for user review
- Decision source: The approved Phase 5a plan of 2026-10-28, stage 5a-1.
- Previous rule: `appearance.ts` kept palettes as arrays with fixed slot positions. Branches on theme IDs chose the secondary accent, status, syntax, and font values. `tokens.css` repeated the fonts and the selection fill for each palette. The contrast tests covered only the character palettes.
- New rule: Each built-in theme is a data file in `src/lib/theme/themes/`. `roles.ts` names each color role and the one rule that fills a missing role. No code outside the theme data names a theme ID. `contrast.ts` holds the readability rules, and a test applies them to every palette.
- New roles: `--rs-link`, `--rs-focus`, `--rs-on-accent`, `--rs-highlight`, and `--rs-scrim`. `--rs-item-selection-bg` and `--rs-line-highlight` are now roles. `--rs-danger` is removed, and its users take `--rs-error`.
- Reason: One definition for each color, and one place to correct it. The rules show which palettes fail and why.
- Scope: Built-in and custom themes, link text, focus outlines, dialog backdrops, highlighted text, and plugin views through the tokens.
- Shared implementation: `roles.ts`, `color.ts`, `contrast.ts`, `themes/`, `appearance.ts`, and `tokens.css`. [Theme tokens](plugin-development.md#theme-tokens) lists the tokens for plugin authors.
- Visible changes: The save conflict banner uses `--rs-warn` for its line. It used the fallback of the undefined token `--rs-warning`. Highlighted text in Write takes its color from `--rs-highlight` (`#edc65b` instead of `#e7c56a`, with the same 22% fill). Plugin Manager and image viewer backdrops use the shared 53% scrim instead of 60%.
- Custom themes: A theme export now writes the colors that the app applies. A derived role follows the theme's own colors, not the RuneStone colors.
- Evidence: A comparison of the applied colors before and after the change gives the same values for every built-in theme and mode. `tests/unit/theme/contrast.spec.ts` lists 29 rule failures of the current palettes as `todo`. Stages 5a-3 and 5a-4 remove them.
- Replaces / replaced by: None.
- Limits: Browser checks use desktop service mocks. Native desktop acceptance remains open.
### UI-042 — Theme file format 3 and terminal colors
- Type: Rule change
- Date: 2026-10-28
- Status: Implemented for user review
- Decision source: The approved Phase 5a plan of 2026-10-28, stage 5a-2, and card 90906e18. The owner approved the terminal roles on 2026-10-28.
- Previous rule: Theme files used schema 2: one `colors` palette with 26 keys and no mode. A custom theme took missing colors from RuneStone in the mode of its background. Five syntax keys had Monaco names, and two of them had no use in Source.
- New rule: Theme files use schema 3 with `mode`, an optional built-in `base`, and `colors` keys equal to the role names. The export writes every role and font. An import takes the missing colors and fonts from the base theme, by default RuneStone. Built-in themes pass the same parser.
- Syntax roles: `variable`, `property`, `constant`, `punctuation`, and `heading` replace `local`, `instance`, and `global`. `parameter` and `static` are gone. Schema 1 and 2 files convert on import.
- Terminal roles: `--rs-ansi-*` and `--rs-ansi-bright-*` give the 16 terminal colors. Red, green, and yellow follow the status colors. Blue, magenta, and cyan have their own defaults, so a red accent no longer makes terminal blue red.
- Reason: Short theme files that build on a built-in theme. One name for each color in the file, the CSS token, and the docs. Terminal colors that keep their meaning in every theme.
- Scope: Theme import, export, saved custom themes, Source syntax colors, and the terminal tokens. The Terminal plugin adopts the terminal roles in its own repository.
- Shared implementation: `customThemes.ts`, `roles.ts`, `appearance.ts`, `contrast.ts`, and `sourceView.ts`.
- Visible changes: None in the app. Exported files and import error messages change. The terminal colors change only after the Terminal plugin uses the new tokens.
- Evidence: The applied colors and the Source colors of each tag group are the same as before stage 5a-1, for every built-in theme and a saved schema 2 custom theme. `tests/unit/theme/customThemes.spec.ts` covers schema 3, `base`, and the conversion of old syntax names.
- Replaces / replaced by: The template format of [UI-028](#ui-028--adjustable-surface-transparency-and-fixed-custom-palettes). Its transparency rule remains.
- Limits: Browser checks use desktop service mocks. Native desktop acceptance remains open.