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:
+34
-10
@@ -16,20 +16,30 @@ Agents also apply the user-level `ui-functional-color` skill. This guide adds th
|
||||
|
||||
## Roles and tokens
|
||||
|
||||
All tokens are in `src/lib/theme/tokens.css`, unless the table names another file. Correct a wrong token at its source. Do not add local saturation or opacity overrides.
|
||||
A theme is data. Each built-in theme is one file in `src/lib/theme/themes/`, with one palette for each mode that it offers.
|
||||
`src/lib/theme/roles.ts` lists the color roles. Each role is the CSS token `--rs-<role>`.
|
||||
A theme gives the base roles. One rule for all themes fills each other role from the base roles, unless the theme gives a value.
|
||||
No code outside the theme data names a theme ID. `tests/unit/theme/contrast.spec.ts` checks this.
|
||||
|
||||
Correct a wrong color in the theme data or in the derivation rule. Do not add local saturation or opacity overrides.
|
||||
|
||||
| Role | Tokens | Requirement |
|
||||
| --- | --- | --- |
|
||||
| Theme identity | `--rs-accent`, `--rs-accent-2`, palette surfaces in `src/lib/theme/characterThemes.ts` | Keep the characteristic hues of the reference at their strength. |
|
||||
| Theme identity | `--rs-accent`, `--rs-accent-2` | Keep the characteristic hues of the reference at their strength. |
|
||||
| Status | `--rs-error`, `--rs-warn`, `--rs-warn-hot`, `--rs-ok` | Use clear, assertive colors. Pair color with a shape or text. |
|
||||
| Priority (Project Management) | `--pm-priority-color` in the plugin `src/style.css` | Full saturation and value, with opaque symbols and readable text. |
|
||||
| Links and actions | `--rs-accent` | Keep actionable text distinct and readable on its actual surface. |
|
||||
| Selection and focus | `--rs-item-selection-*`, `--rs-selection`, `--rs-selection-text` | Show a clear state change and boundary. Content inside the selection stays readable. |
|
||||
| Links and actions | `--rs-link` (from `--rs-accent` unless the theme sets it) | Keep actionable text distinct and readable on its actual surface. |
|
||||
| Text on an accent fill | `--rs-on-accent` (black or white, whichever is more readable) | Readable text and icons on accent buttons and badges. |
|
||||
| Focus | `--rs-focus` (from `--rs-accent` unless the theme sets it) | A visible outline on every surface. |
|
||||
| Selection | `--rs-item-selection-*`, `--rs-selection`, `--rs-selection-text` | Show a clear state change and boundary. Content inside the selection stays readable. |
|
||||
| Highlighted text | `--rs-highlight` | A fill that keeps the text readable. |
|
||||
| Syntax | `--rs-syntax-*`, one for each role in `SYNTAX_ROLES` | Give each meaning a distinct color. A palette has at least 7 distinct syntax colors. |
|
||||
| Surfaces and dividers | `--rs-bg`, `--rs-bg-elevated`, `--rs-bg-active`, `--rs-border`, `--rs-image-*` tints | Support the content. Choose their strength by function. |
|
||||
| Terminal | `--rs-ansi-*` and `--rs-ansi-bright-*`, one for each color in `ANSI_COLORS` | Each color keeps its ANSI hue in every theme. Blue stays blue, also in a red theme. |
|
||||
| Surfaces and dividers | `--rs-bg`, `--rs-bg-elevated`, `--rs-bg-active`, `--rs-border`, `--rs-line-highlight`, `--rs-scrim`, `--rs-image-*` tints | Support the content. Choose their strength by function. |
|
||||
| Disabled states | Role tokens of the control | Keep labels readable. Do not apply disabled opacity to enabled content. |
|
||||
|
||||
Do not fade a whole badge, row, or container when only its background needs transparency.
|
||||
Plugins use the same tokens. [Theme tokens](plugin-development.md#theme-tokens) lists them for plugin authors.
|
||||
|
||||
## Theme references
|
||||
|
||||
@@ -51,15 +61,29 @@ The October 13 review found these problems. The values record that correction. T
|
||||
|
||||
The [October 13 menu and color review](archive/menu-audit-2026-10-13.md) holds the measurements and the image-surface limits.
|
||||
|
||||
## Contrast thresholds
|
||||
## Readability rules
|
||||
|
||||
| Pair | Minimum | Test |
|
||||
`src/lib/theme/contrast.ts` holds these rules. `tests/unit/theme/contrast.spec.ts` applies them to every built-in palette. The theme editor can show the same results.
|
||||
Each surface is the color that the app draws: a translucent role is composited onto `bg`. Text selection is at most 65% opaque.
|
||||
|
||||
| Rule | Check | Minimum |
|
||||
| --- | --- | --- |
|
||||
| `text`, `text-dim`, `text-strong`, and `accent` on `bg`, `bg-elevated`, `bg-active`, and `selection` | 4.5:1 | `tests/unit/theme/appearance.spec.ts`, `tests/unit/theme/themePalette.spec.ts` |
|
||||
| Each syntax role on `bg` and `bg-active` | 4.5:1 | `tests/unit/theme/appearance.spec.ts` |
|
||||
| Accent selection perimeter on the selection fill | 3:1 | `tests/unit/theme/malfoidPalette.spec.ts` |
|
||||
| `text` | `text`, `text-dim`, and `text-strong` on `bg`, `bg-elevated`, `bg-active`, and `selection` | 4.5:1 |
|
||||
| `accent-text` | `accent` and `link` on `bg`, `bg-elevated`, and `bg-active` | 4.5:1 |
|
||||
| `status-text` | `error`, `warn`, and `ok` on `bg` and `bg-elevated` | 4.5:1 |
|
||||
| `syntax` | Each syntax role on `bg`, `bg-active`, and `line-highlight` | 4.5:1 |
|
||||
| `ansi` | Red, green, yellow, blue, magenta, and cyan terminal colors, and their bright variants, on `bg` | 4.5:1 |
|
||||
| `focus` | `focus` on `bg`, `bg-elevated`, and `bg-active` | 3:1 |
|
||||
| `on-accent` | `on-accent` on `accent` | 4.5:1 |
|
||||
| `highlight` | `text` on highlighted text | 4.5:1 |
|
||||
| `selection-outline` | `accent` on the item selection fill over `bg-elevated` | 3:1 |
|
||||
| `status-distinct` | OKLab distance between `accent`, `error`, `warn`, and `ok`, in pairs | 0.1 |
|
||||
| `syntax-variety` | Distinct syntax colors | 7 |
|
||||
| `light-page` | In a light palette, `bg` is lighter than `bg-elevated` and `bg-active` | — |
|
||||
|
||||
`accent` on `selection` is exempt from the 4.5:1 text check. Run the tests with `pnpm test`.
|
||||
The test lists the failures of current palettes as `todo`. A palette change removes its entries. The test fails when a listed rule passes, so the list cannot go stale.
|
||||
`tests/unit/theme/characterPalettes.spec.ts` adds the checks of each character palette, for example over image tints.
|
||||
Over a user image, contrast depends on the composite surface. Measure the 82% and 90% tints over the image that the change uses. Do not claim contrast over every possible image or overlay.
|
||||
When contrast fails, change the foreground, background, surface, or role before you reduce color strength.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user