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.
+23 -19
View File
@@ -40,25 +40,22 @@ The Project Management plugin can keep a separate image for a board. The Backgro
3. Edit the saved JSON file in a text editor.
4. Choose **Install theme** and select the file.
The template contains one `colors` palette and the current `fonts`. A custom theme has one fixed palette, without separate light and dark versions.
The template contains every color and font of the theme. A custom theme has one fixed mode: light or dark.
Example (a minimal theme file):
A theme file can also be short. It gives only the colors that differ from its `base` theme. The base theme gives all other colors and its fonts.
Example (a short theme file that changes two colors of Harvest Moon):
```json
{
"schema": 2,
"schema": 3,
"id": "harbor",
"name": "Harbor",
"mode": "dark",
"base": "harvest-moon",
"colors": {
"bg": "#141414",
"bg-elevated": "#1c1c1c",
"bg-active": "#2a2a2a",
"border": "#454545",
"text": "#e6e6e6",
"text-dim": "#b0b0b0",
"text-strong": "#ffffff",
"accent": "#00c8ff",
"selection": "#264f78"
"link": "#5cd6ff"
}
}
```
@@ -68,26 +65,33 @@ Example (a minimal theme file):
| Field | Rule |
| --- | --- |
| File | JSON, smaller than 64 KiB |
| `schema` | `2`. RuneStone also imports schema 1 files and converts them to one palette for the current appearance. |
| `schema` | `3`. RuneStone also imports schema 1 and 2 files and converts them. A schema 1 file gives the palette of the current appearance. |
| `id` | Starts with a lowercase letter. Lowercase letters, numbers, and hyphens. Up to 64 characters. A theme with the same ID replaces the installed theme. |
| `name` | Up to 80 characters |
| `colors` | Must contain `bg`, `text`, and `accent`. Each value is a hexadecimal color with 3, 4, 6, or 8 digits. |
| `fonts` | Optional. Font stacks for `ui`, `prose`, `heading`, and `mono`, such as `"mono": "Cascadia Mono, monospace"`. |
| `mode` | `light` or `dark` |
| `base` | Optional. The ID of a built-in theme that has a palette in `mode`: `default` (RuneStone), `claude`, `sakura`, `harvest-moon`, `crimson-pilot`, or `silver-serpent`. Without `base`, RuneStone is the base. |
| `colors` | The colors that differ from the base theme. Each value is a hexadecimal color with 3, 4, 6, or 8 digits. |
| `fonts` | Optional. Font stacks for `ui`, `prose`, `heading`, and `mono`, such as `"mono": "Cascadia Mono, monospace"`. Without a stack, the base theme gives it. |
An unknown key or a color that is not valid stops the installation with an error.
If you omit an optional color, RuneStone uses the color of the base appearance. If you omit `fonts`, the theme uses the normal fonts.
Some colors come from other colors when neither the file nor the base theme gives them. For example, `link` and `focus` come from `accent`.
Font stacks name fonts that are installed on the computer. A theme file cannot install fonts or contain scripts, style rules, or plugin code.
### Color keys
| Keys | Use |
| --- | --- |
| `bg`, `bg-elevated`, `bg-active`, `border` | Surfaces and borders |
| `bg`, `bg-elevated`, `bg-active`, `border` | The page, side panes and menus, hover fills, and borders |
| `text`, `text-dim`, `text-strong` | Normal, secondary, and prominent text |
| `accent`, `accent-2`, `selection` | Links, accents, and editor selection |
| `accent`, `accent-2`, `accent-dim`, `accent-deep` | Theme colors for active states, indicators, and icons |
| `link`, `focus`, `on-accent` | Link text, keyboard focus outlines, and text on an accent fill |
| `selection`, `item-selection-bg`, `line-highlight`, `highlight`, `scrim` | Text selection, selected rows, the current line in Source, highlighted text, and the backdrop behind dialogs |
| `error`, `warn`, `warn-hot`, `ok`, `special` | Status and special content |
| `syntax-parameter`, `syntax-keyword`, `syntax-local`, `syntax-static`, `syntax-instance`, `syntax-global` | Code identifiers and keywords |
| `syntax-string`, `syntax-number`, `syntax-comment`, `syntax-type`, `syntax-function` | Code values, comments, types, and functions |
| `syntax-keyword`, `syntax-string`, `syntax-number`, `syntax-comment`, `syntax-type`, `syntax-function` | Code keywords, values, comments, types, and functions |
| `syntax-property`, `syntax-variable`, `syntax-constant`, `syntax-punctuation`, `syntax-heading` | Code properties, variables, constants, punctuation, and Markdown headings |
| `ansi-black` to `ansi-white`, `ansi-bright-black` to `ansi-bright-white` | The 16 terminal colors: black, red, green, yellow, blue, magenta, cyan, and white, and a bright variant of each |
Schema 1 and 2 files used other names for some code colors. RuneStone converts them: `syntax-local` to `syntax-variable`, `syntax-instance` to `syntax-property`, and `syntax-global` to `syntax-constant` and `syntax-punctuation`. Source never used `syntax-parameter` and `syntax-static`, so RuneStone ignores them.
Before you share a theme, check text, links, focus outlines, selections, and surfaces with a background image.
Keep informative text and symbols opaque. See the [functional color requirements](../ui-color.md).
+30
View File
@@ -392,6 +392,36 @@ Only one enabled plugin can own each key. The host removes contributions before
A terminal contribution must stop its controls and native sessions before its cleanup finishes.
### Theme tokens
Style plugin views with the host CSS custom properties. The host sets them on the root element for the current theme.
Do not hard-code colors, and do not choose colors from a theme ID.
| Token | Use |
| --- | --- |
| `--rs-bg` | The page: document and editor surfaces |
| `--rs-bg-elevated` | Side panes, menus, cards, and dialogs |
| `--rs-bg-active` | Hover and pressed fills |
| `--rs-border` | Dividers and control borders |
| `--rs-text`, `--rs-text-dim`, `--rs-text-strong` | Body text, secondary text, and headings |
| `--rs-accent`, `--rs-accent-2` | Theme identity: active states, indicators, and icons |
| `--rs-link` | Link and action text |
| `--rs-focus` | Keyboard focus outlines |
| `--rs-on-accent` | Text and icons on an accent fill |
| `--rs-selection`, `--rs-selection-text` | Text selection. The fill is at most 65% opaque. |
| `--rs-item-selection-bg`, `--rs-item-selection-border` | Selected rows, cards, and cells |
| `--rs-highlight` | Highlighted text |
| `--rs-scrim` | The backdrop behind a dialog |
| `--rs-error`, `--rs-warn`, `--rs-warn-hot`, `--rs-ok` | Status. Show an icon or text with each status color. |
| `--rs-special` | One more distinct color, for example for numbers |
| `--rs-syntax-*` | Code colors. [Functional color](ui-color.md#roles-and-tokens) lists the roles. |
| `--rs-ansi-black` to `--rs-ansi-white`, `--rs-ansi-bright-black` to `--rs-ansi-bright-white` | The 16 terminal colors. Each keeps its ANSI hue in every theme. |
[Interface design](ui-design.md#shared-components-and-tokens) lists the size, menu, settings, and tooltip tokens.
The root element also has `data-theme` (`light` or `dark`) and `data-palette` (the theme ID). Use `data-theme` for differences between light and dark.
The window sends a `runestone-theme-changed` event after each theme change. A plugin that copies token values, for example into a canvas or a terminal, reads them again on that event.
## Use the SDK instead of native calls
Do not call `invoke`, `listen`, or other `@tauri-apps/api` functions from a plugin. Do not read the private files of other plugins.
+34 -10
View File
@@ -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.
+4 -3
View File
@@ -31,7 +31,8 @@ Do not copy feature-specific colors into a shared control.
| Undo, Redo, clipboard, and search rows | `src/lib/ui/menuItems.ts` |
| Menu and picker presentation | `src/lib/ui/menu.css` |
| Find | `src/lib/editor/FindPanel.svelte` and `src/lib/ui/find.css`. Write and Source search with `editorSearch.ts`. Read and plugin views search with `readingSearch.ts`. |
| Dimensions and colors | `src/lib/theme/tokens.css` |
| Dimensions and fixed colors | `src/lib/theme/tokens.css` |
| Theme colors | The roles in `src/lib/theme/roles.ts` and the theme data in `src/lib/theme/themes/`. See [Functional color](ui-color.md#roles-and-tokens). |
| Token | Default | Use |
| --- | --- | --- |
@@ -153,9 +154,9 @@ Decisions: [UI-004](design-decisions.md#ui-004--detached-tab-work-area), [UI-039
- Controls wrap at narrow widths, and the content area scrolls. Long navigation must leave room for the selected page.
- General offers the interface language through the shared action menu.
- The transparency slider covers 0% to 100% and uses the accent and surface tokens of the current theme.
- Custom theme templates use schema 2: one fixed `colors` palette and `fonts` stacks for interface, prose, headings, and code. A schema 1 import selects the palette of the current appearance.
- Custom theme files use schema 3: one `mode`, an optional built-in `base` theme, the `colors` that differ from the base, and `fonts` stacks for interface, prose, headings, and code. The export writes every color and font. Schema 1 and 2 imports convert to schema 3. A schema 1 import selects the palette of the current appearance.
Decisions: [UI-028](design-decisions.md#ui-028--adjustable-surface-transparency-and-fixed-custom-palettes).
Decisions: [UI-028](design-decisions.md#ui-028--adjustable-surface-transparency-and-fixed-custom-palettes), [UI-042](design-decisions.md#ui-042--theme-file-format-3-and-terminal-colors).
## Typography and tables