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:
@@ -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
@@ -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).
|
||||
|
||||
@@ -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
@@ -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
@@ -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
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
<style>
|
||||
.bookmarks{color:var(--rs-text);font-family:var(--rs-font-ui)}.row{display:flex;align-items:center;padding:0 5px;border-radius:var(--rs-control-radius)}.row:hover{background:var(--rs-bg-active)}
|
||||
.link{display:flex;align-items:center;gap:8px;flex:1;min-width:0;padding:7px 5px;border:0;border-radius:var(--rs-control-radius);color:inherit;background:transparent;text-align:left;cursor:pointer}
|
||||
span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.link:focus-visible{outline:2px solid var(--rs-accent)}p{color:var(--rs-error);padding:8px;font-size:12px}
|
||||
span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.link:focus-visible{outline:2px solid var(--rs-focus)}p{color:var(--rs-error);padding:8px;font-size:12px}
|
||||
</style>
|
||||
|
||||
@@ -293,13 +293,13 @@
|
||||
.toolbar,.findbar{display:flex;align-items:center;gap:4px;padding:5px 8px;border-bottom:1px solid var(--rs-border);background:var(--rs-bg-elevated)}
|
||||
.toolbar{flex-wrap:wrap}.toolbar input{flex:1 1 120px}.findbar input{max-width:320px}.find-count{font-size:12px;white-space:nowrap;color:var(--rs-text-dim);min-width:66px}
|
||||
input,.profile-choice{min-width:0;border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg);color:var(--rs-text);font:inherit;padding:5px 8px}
|
||||
input{flex:1}.profile-choice{max-width:160px;display:flex;align-items:center;gap:var(--rs-menu-icon-gap);cursor:pointer}input:focus-visible,.profile-choice:focus-visible{outline:2px solid var(--rs-accent)}
|
||||
input{flex:1}.profile-choice{max-width:160px;display:flex;align-items:center;gap:var(--rs-menu-icon-gap);cursor:pointer}input:focus-visible,.profile-choice:focus-visible{outline:2px solid var(--rs-focus)}
|
||||
.surface{position:relative;flex:1;min-height:0;overflow:hidden;outline:none;background:var(--rs-bg)}.surface:focus-visible{box-shadow:inset 0 0 0 1px var(--rs-accent)}
|
||||
.browser.blank,.blank .surface{background:transparent}
|
||||
.surface.autoscroll{cursor:all-scroll}.scroll-anchor{position:absolute;transform:translate(-50%,-50%);display:grid;place-items:center;width:24px;height:24px;border:1px solid var(--rs-text);border-radius:50%;background:var(--rs-bg-elevated);color:var(--rs-text);font-size:20px;pointer-events:none;box-shadow:0 1px 4px #0006}
|
||||
img{display:block;pointer-events:none;user-select:none;will-change:transform}img.exact{image-rendering:pixelated}.error{margin:0;padding:5px 10px;color:var(--rs-error);font-size:12px}
|
||||
.error p{margin:4px 0}.status,.diagnostics{margin:0;padding:8px 10px;font-size:12px;color:var(--rs-text-dim)}
|
||||
.reconnect{padding:6px 12px;margin:4px 0;border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg-elevated);color:var(--rs-text);cursor:pointer}
|
||||
.reconnect:focus-visible,summary:focus-visible{outline:2px solid var(--rs-accent);outline-offset:2px}summary{cursor:pointer}
|
||||
.reconnect:focus-visible,summary:focus-visible{outline:2px solid var(--rs-focus);outline-offset:2px}summary{cursor:pointer}
|
||||
dl{display:grid;grid-template-columns:auto 1fr;gap:4px 12px}dd{margin:0;overflow-wrap:anywhere;user-select:text}
|
||||
</style>
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
p{color:var(--rs-text-dim);font-size:var(--rs-settings-description-size);line-height:1.6}.card{padding:0 var(--rs-settings-row-padding);background:var(--rs-bg-elevated);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
|
||||
.row{display:flex;justify-content:space-between;align-items:center;gap:var(--rs-settings-gap);padding:var(--rs-settings-row-padding) 0}.row+.row{border-top:1px solid var(--rs-border)}
|
||||
input,textarea,button{border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg);color:var(--rs-text);font:inherit;box-sizing:border-box;min-height:var(--rs-settings-control-height);padding:4px 8px}
|
||||
button{display:inline-flex;align-items:center;gap:7px;background:var(--rs-bg-elevated);cursor:pointer}button:hover{background:var(--rs-bg-active)}button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--rs-accent);outline-offset:1px}
|
||||
button{display:inline-flex;align-items:center;gap:7px;background:var(--rs-bg-elevated);cursor:pointer}button:hover{background:var(--rs-bg-active)}button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--rs-focus);outline-offset:1px}
|
||||
.picker{justify-content:space-between;min-width:140px;max-width:100%;overflow-wrap:anywhere;text-align:left}
|
||||
.rules{display:flex;flex-direction:column;gap:7px;margin:16px 0}.profiles{padding-top:16px;padding-bottom:8px}.profiles label,.profile-choice{display:flex;flex-direction:column;gap:7px;margin-bottom:14px}
|
||||
.actions{display:flex;flex-wrap:wrap;gap:8px}.note{margin-bottom:0}
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
section{margin-top:var(--rs-settings-section-gap)}.toolbar{display:flex;align-items:end;gap:var(--rs-settings-gap);flex-wrap:wrap}
|
||||
label,.choice{display:flex;flex-direction:column;gap:4px}.search{flex:1;min-width:150px}input,button{min-height:var(--rs-settings-control-height);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg-elevated);color:var(--rs-text);font:inherit;padding:4px 8px}
|
||||
button{display:inline-flex;align-items:center;justify-content:center;gap:6px;flex:none;cursor:pointer}button:hover{background:var(--rs-bg-active)}button:disabled{opacity:.6;cursor:wait}
|
||||
button:focus-visible,input:focus-visible{outline:2px solid var(--rs-accent);outline-offset:1px}
|
||||
button:focus-visible,input:focus-visible{outline:2px solid var(--rs-focus);outline-offset:1px}
|
||||
p,small{font-size:var(--rs-settings-description-size);color:var(--rs-text-dim);line-height:1.5}.entries{max-height:320px;overflow:auto;border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);padding:0 var(--rs-settings-row-padding)}
|
||||
.entry{display:flex;gap:var(--rs-settings-gap);align-items:center;padding:var(--rs-settings-row-padding) 0}.entry+.entry{border-top:1px solid var(--rs-border)}.entry>div{flex:1;min-width:0;overflow-wrap:anywhere}small{display:block}strong{font-weight:500}[role=alert]{color:var(--rs-error)}
|
||||
@media(max-width:450px){.entry{flex-wrap:wrap}.entry>div{flex-basis:100%}}
|
||||
|
||||
@@ -5,7 +5,7 @@ export const registerCompletionInput: CompletionApi["registerInput"] = (element,
|
||||
let revision = 0, composing = false;
|
||||
const hint = document.createElement("div");
|
||||
hint.className = "rs-completion-hint";
|
||||
hint.style.cssText = "position:fixed;z-index:10000;pointer-events:none;max-width:40em;padding:6px 10px;border-radius:var(--rs-control-radius,6px);background:var(--rs-bg,#20242a);color:var(--rs-text,#eee);border:1px solid currentColor;font:inherit;white-space:pre-wrap";
|
||||
hint.style.cssText = "position:fixed;z-index:10000;pointer-events:none;max-width:40em;padding:6px 10px;border-radius:var(--rs-control-radius);background:var(--rs-bg);color:var(--rs-text);border:1px solid currentColor;font:inherit;white-space:pre-wrap";
|
||||
hint.hidden = true;
|
||||
hint.setAttribute("aria-hidden", "true");
|
||||
document.body.append(hint);
|
||||
|
||||
@@ -469,8 +469,8 @@
|
||||
.live-writer :global(.writer-strong) { font-weight: 600; color: var(--rs-text-strong); }
|
||||
.live-writer :global(.writer-emphasis) { font-style: italic; }
|
||||
.live-writer :global(.writer-strike), .live-writer :global(.writer-completed) { text-decoration: line-through; color: var(--rs-text-dim); }
|
||||
.live-writer :global(.writer-link) { color: var(--rs-accent); text-decoration: underline; text-underline-offset: 3px; }
|
||||
.live-writer :global(.writer-link-source) { color: var(--rs-accent); }
|
||||
.live-writer :global(.writer-link) { color: var(--rs-link); text-decoration: underline; text-underline-offset: 3px; }
|
||||
.live-writer :global(.writer-link-source) { color: var(--rs-link); }
|
||||
.live-writer :global(.writer-link-target) { text-decoration: underline; text-underline-offset: 3px; }
|
||||
.live-writer :global(.writer-inline-code), .live-writer :global(.writer-code-source) { font-family: var(--rs-font-mono); font-size: .9em; }
|
||||
.live-writer :global(.writer-inline-code) { background: var(--rs-bg-elevated); border-radius: 3px; }
|
||||
@@ -479,8 +479,8 @@
|
||||
.live-writer :global(.writer-code-last) { padding-bottom: 10px; border-bottom: 1px solid var(--rs-border); border-radius: 0 0 var(--rs-control-radius) var(--rs-control-radius); }
|
||||
.live-writer :global(.writer-code-fence) { color: var(--rs-text-dim); }
|
||||
.live-writer :global(.writer-code-copy) { top: 4px; border-radius: var(--rs-control-radius); }
|
||||
.live-writer :global(.writer-code-copy:focus-visible) { outline: 1px solid var(--rs-accent); outline-offset: -2px; }
|
||||
.live-writer :global(.writer-highlight) { background: #e7c56a38; color: var(--rs-text-strong); }
|
||||
.live-writer :global(.writer-code-copy:focus-visible) { outline: 1px solid var(--rs-focus); outline-offset: -2px; }
|
||||
.live-writer :global(.writer-highlight) { background: color-mix(in srgb, var(--rs-highlight) 22%, transparent); color: var(--rs-text-strong); }
|
||||
.live-writer :global(.writer-math) { font-family: var(--rs-font-mono); font-style: italic; }
|
||||
.live-writer :global(.writer-comment) { color: var(--rs-text-dim); background: var(--rs-bg-active); }
|
||||
.live-writer :global(.writer-divider-line) { display: flex; align-items: center; }
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
.live-writer .rs-heading-toggle { top: .7em; }
|
||||
.rs-heading-toggle { position: absolute; inset-inline-start: -30px; top: 0; width: 28px; height: 28px; padding: 6px; border: 0; border-radius: var(--rs-control-radius); color: var(--rs-text-dim); background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; }
|
||||
.rs-heading-toggle:hover, .rs-heading-toggle:focus-visible { color: var(--rs-text); background: var(--rs-bg-active); }
|
||||
.rs-heading-toggle:focus-visible { outline: 1px solid var(--rs-accent); outline-offset: 1px; }
|
||||
.rs-heading-toggle:focus-visible { outline: 1px solid var(--rs-focus); outline-offset: 1px; }
|
||||
.rs-heading-toggle svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.rs-heading-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
|
||||
.rs-heading-collapsed::after { content: " …"; color: var(--rs-text-dim); font-weight: normal; }
|
||||
@@ -16,4 +16,4 @@
|
||||
.reading .md-footnotes li { padding-inline-start: .3em; }
|
||||
.reading .md-footnotes li > p:last-of-type { display: inline; }
|
||||
.reading .md-footnote-back { margin-inline-start: .4em; }
|
||||
.reading .md-footnote-ref a:focus-visible, .reading .md-footnote-back:focus-visible { outline: 1px solid var(--rs-accent); outline-offset: 3px; border-radius: var(--rs-control-radius); }
|
||||
.reading .md-footnote-ref a:focus-visible, .reading .md-footnote-back:focus-visible { outline: 1px solid var(--rs-focus); outline-offset: 3px; border-radius: var(--rs-control-radius); }
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
.md-image-frame:hover .md-image-actions, .md-image-frame:focus-within .md-image-actions { opacity: 1; }
|
||||
.image-action { position: relative; display: inline-grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; padding: 6px; color: var(--rs-text); border: 0; border-radius: 4px; background: transparent; cursor: pointer; }
|
||||
.image-action:hover, .image-action:focus-visible { background: var(--rs-bg-active); color: var(--rs-text-strong); }
|
||||
.image-action:focus-visible { outline: 2px solid var(--rs-accent); outline-offset: 1px; }
|
||||
.image-action:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: 1px; }
|
||||
.image-action:disabled { opacity: .4; cursor: default; }
|
||||
.image-lightbox { position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #090a0de8; color: var(--rs-text); }
|
||||
.image-lightbox { position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--rs-image-viewer-bg); color: var(--rs-text); }
|
||||
.image-lightbox[open] { display: flex; flex-direction: column; }
|
||||
.image-lightbox::backdrop { background: #0009; }
|
||||
.image-lightbox::backdrop { background: var(--rs-scrim); }
|
||||
.image-lightbox-toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--rs-bg-elevated); z-index: 1; }
|
||||
.image-lightbox-name { margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.image-lightbox-scale { min-width: 44px; text-align: center; font-size: 12px; }
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
.note-title-button { position: relative; display: inline-flex; align-items: center; gap: 12px; max-width: 100%; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: left; overflow-wrap: anywhere; cursor: text; }
|
||||
.note-title-button .action-icon { opacity: .45; }
|
||||
.note-title-button:hover .action-icon, .note-title-button:focus-visible .action-icon { opacity: 1; color: var(--rs-accent); }
|
||||
.note-title-button:focus-visible { outline: 1px solid var(--rs-accent); outline-offset: 4px; border-radius: 3px; }
|
||||
.note-title-button:focus-visible { outline: 1px solid var(--rs-focus); outline-offset: 4px; border-radius: 3px; }
|
||||
.note-title-input { box-sizing: border-box; width: 100%; min-width: 0; padding: 0; border: 0; border-radius: 2px; outline: 1px solid var(--rs-accent); outline-offset: 4px; background: transparent; color: inherit; font: inherit; }
|
||||
.note-title-input[aria-invalid] { outline-color: var(--rs-danger, #e57878); }
|
||||
.note-title-error { margin: -.8em 0 1em; color: var(--rs-danger, #e57878); font: 13px/1.5 var(--rs-font-ui); }
|
||||
.note-title-input[aria-invalid] { outline-color: var(--rs-error); }
|
||||
.note-title-error { margin: -.8em 0 1em; color: var(--rs-error); font: 13px/1.5 var(--rs-font-ui); }
|
||||
.note-title-button[hidden], .note-title-input[hidden], .note-title-error[hidden] { display: none; }
|
||||
|
||||
@@ -13,20 +13,20 @@ const syntax = (role: string, fallback: string) => `var(--rs-syntax-${role}, ${f
|
||||
/** Syntax colors come from the theme tokens, so a theme change needs no editor update. */
|
||||
const sourceHighlight = HighlightStyle.define([
|
||||
{ tag: [tags.keyword, tags.modifier, tags.operatorKeyword, tags.controlKeyword, tags.definitionKeyword, tags.moduleKeyword, tags.tagName], color: syntax("keyword", "var(--rs-accent)") },
|
||||
{ tag: tags.heading, color: syntax("keyword", "var(--rs-accent)"), fontWeight: "600" },
|
||||
{ tag: tags.heading, color: syntax("heading", "var(--rs-accent)"), fontWeight: "600" },
|
||||
{ tag: [tags.string, tags.special(tags.string), tags.regexp, tags.attributeValue, tags.url, tags.monospace], color: syntax("string", "var(--rs-ok)") },
|
||||
{ tag: [tags.number, tags.bool, tags.null, tags.atom, tags.unit], color: syntax("number", "var(--rs-special)") },
|
||||
{ tag: tags.comment, color: syntax("comment", "var(--rs-text-dim)") },
|
||||
{ tag: [tags.typeName, tags.className, tags.namespace], color: syntax("type", "var(--rs-accent-2)") },
|
||||
{ tag: [tags.function(tags.variableName), tags.function(tags.propertyName), tags.macroName], color: syntax("function", "var(--rs-accent-2)") },
|
||||
{ tag: [tags.propertyName, tags.attributeName], color: syntax("instance", "var(--rs-accent-2)") },
|
||||
{ tag: [tags.standard(tags.variableName), tags.self, tags.special(tags.variableName)], color: syntax("global", "var(--rs-text-dim)") },
|
||||
{ tag: tags.variableName, color: syntax("local", "var(--rs-text)") },
|
||||
{ tag: [tags.punctuation, tags.operator, tags.meta, tags.processingInstruction], color: syntax("global", "var(--rs-text-dim)") },
|
||||
{ tag: [tags.propertyName, tags.attributeName], color: syntax("property", "var(--rs-accent-2)") },
|
||||
{ tag: [tags.standard(tags.variableName), tags.self, tags.special(tags.variableName)], color: syntax("constant", "var(--rs-text-dim)") },
|
||||
{ tag: tags.variableName, color: syntax("variable", "var(--rs-text)") },
|
||||
{ tag: [tags.punctuation, tags.operator, tags.meta, tags.processingInstruction], color: syntax("punctuation", "var(--rs-text-dim)") },
|
||||
{ tag: tags.emphasis, fontStyle: "italic" },
|
||||
{ tag: tags.strong, fontWeight: "600" },
|
||||
{ tag: tags.strikethrough, textDecoration: "line-through" },
|
||||
{ tag: tags.link, color: "var(--rs-accent)", textDecoration: "underline" },
|
||||
{ tag: tags.link, color: "var(--rs-link)", textDecoration: "underline" },
|
||||
{ tag: tags.invalid, color: "var(--rs-error)" },
|
||||
]);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* Table formula results and help below a table. */
|
||||
.md-table-formula { color: var(--rs-accent); font-variant-numeric: tabular-nums; }
|
||||
.md-table-formula.is-error { color: var(--rs-danger, #ed8796); text-decoration: underline dotted; }
|
||||
.md-table-formula.is-error { color: var(--rs-error); text-decoration: underline dotted; }
|
||||
.table-footer { display: grid; gap: 8px; margin: 0 26px 1.4em; min-width: 0; font: 12px/1.5 var(--rs-font-ui); color: var(--rs-text-dim); white-space: normal; overflow-wrap: anywhere; }
|
||||
.table-formula-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; min-width: 0; }
|
||||
.table-formula-help { min-width: 0; }
|
||||
.table-formula-help summary { display: flex; align-items: center; gap: 5px; cursor: pointer; min-height: 28px; border-radius: 4px; }
|
||||
.table-formula-help summary:hover, .table-formula-help summary:focus-visible { color: var(--rs-accent); }
|
||||
.table-formula-help summary:focus-visible { outline: 1px solid var(--rs-accent); outline-offset: 2px; }
|
||||
.table-formula-help summary:focus-visible { outline: 1px solid var(--rs-focus); outline-offset: 2px; }
|
||||
.table-formula-help[open] { flex-basis: 100%; }
|
||||
.table-formula-instructions { display: grid; gap: 12px; max-width: 680px; padding: 12px; border: 1px solid var(--rs-border); border-radius: 6px; line-height: 1.7; color: var(--rs-text); background: var(--rs-bg-elevated); }
|
||||
.table-formula-instructions p, .table-formula-instructions dl, .table-formula-instructions dd { margin: 0; }
|
||||
|
||||
@@ -3454,7 +3454,10 @@ export const messageRows: [string, string, string, string][] = [
|
||||
["Image clipboard is unavailable.", "Le presse-papiers d’images n’est pas disponible.", "画像のクリップボードを利用できません。", "图像剪贴板不可用。"],
|
||||
["Choose an image of 50 MiB or less.", "Choisissez une image de 50 Mio au plus.", "50 MiB 以下の画像を選択してください。", "请选择 50 MiB 或更小的图像。"],
|
||||
["Choose a RuneStone theme JSON file.", "Choisissez un fichier de thème RuneStone au format JSON.", "RuneStone のテーマ JSON ファイルを選択してください。", "请选择 RuneStone 主题 JSON 文件。"],
|
||||
["The theme needs schema 2, an ID, and a name.", "Le thème nécessite le schéma 2, un identifiant et un nom.", "テーマにはスキーマ 2、ID、名前が必要です。", "主题需要架构 2、ID 和名称。"],
|
||||
["The theme needs a schema number, an ID, and a name.", "Le thème nécessite un numéro de schéma, un identifiant et un nom.", "テーマにはスキーマ番号、ID、名前が必要です。", "主题需要架构编号、ID 和名称。"],
|
||||
["Use light or dark for the theme mode.", "Utilisez light ou dark pour le mode du thème.", "テーマのモードには light または dark を使用してください。", "主题模式请使用 light 或 dark。"],
|
||||
["Use a built-in theme with a {mode} palette as the base.", "Utilisez comme base un thème intégré qui a une palette {mode}.", "{mode} パレットを持つ組み込みテーマをベースとして使用してください。", "请使用具有 {mode} 调色板的内置主题作为基础。"],
|
||||
["Use an object for theme colors.", "Utilisez un objet pour les couleurs du thème.", "テーマの色にはオブジェクトを使用してください。", "主题颜色请使用对象。"],
|
||||
["The theme needs {mode} colors.", "Le thème nécessite des couleurs {mode}.", "テーマには {mode} の色が必要です。", "主题需要 {mode} 颜色。"],
|
||||
["Unknown theme color: {key}", "Couleur de thème inconnue : {key}", "不明なテーマの色: {key}", "未知的主题颜色:{key}"],
|
||||
["Use a hexadecimal color for {key}.", "Utilisez une couleur hexadécimale pour {key}.", "{key} には16進数の色を使用してください。", "请为 {key} 使用十六进制颜色。"],
|
||||
|
||||
@@ -67,12 +67,12 @@
|
||||
.content[hidden] { display: none; }
|
||||
ul { list-style: none; padding: 2px 6px 6px; margin: 0; }
|
||||
.source { width: 100%; display: block; padding: 6px; border: 0; border-radius: var(--rs-control-radius); background: transparent; color: var(--rs-text); text-align: left; font: inherit; }
|
||||
.source-title { display: flex; align-items: center; gap: 6px; color: var(--rs-accent); }
|
||||
.source-title { display: flex; align-items: center; gap: 6px; color: var(--rs-link); }
|
||||
.source-title > span:first-of-type { min-width: 0; overflow-wrap: anywhere; }
|
||||
.line { margin-left: auto; color: var(--rs-text-dim); font-variant-numeric: tabular-nums; }
|
||||
.excerpt { display: -webkit-box; line-clamp: 2; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 3px; font-size: 12px; overflow-wrap: anywhere; }
|
||||
.toggle:hover, .source:hover { background: var(--rs-bg-active); }
|
||||
.toggle:focus-visible, .source:focus-visible { outline: 2px solid var(--rs-accent); outline-offset: -2px; }
|
||||
.toggle:focus-visible, .source:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: -2px; }
|
||||
.placeholder, .error { margin: 8px 12px; font-size: 12px; overflow-wrap: anywhere; }
|
||||
.placeholder { color: var(--rs-text-dim); }
|
||||
.error { color: var(--rs-error); }
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
<style>
|
||||
dialog { margin-top: 12vh; width: min(640px, 85vw); }
|
||||
dialog::backdrop { background: #0008; }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
input { width: 100%; padding: 16px; border: 0; background: var(--rs-bg); color: var(--rs-text-strong); }
|
||||
.results { max-height: 50vh; overflow: auto; }
|
||||
.file-detail { min-width: 0; overflow-wrap: anywhere; }
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
|
||||
<style>
|
||||
dialog { width: min(920px, calc(100vw - 32px)); height: min(650px, calc(100dvh - 32px)); max-width: none; max-height: none; padding: 0; background: var(--rs-bg); color: var(--rs-text); border: 1px solid var(--rs-border); border-radius: 12px; box-shadow: 0 24px 80px #0008; overflow: hidden; }
|
||||
dialog::backdrop { background: #0008; }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
dialog.standalone { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
|
||||
dialog.help { width: min(650px, calc(100vw - 32px)); }
|
||||
header { height: var(--rs-titlebar-height); padding: 0 4px 0 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rs-border); background: var(--rs-bg-elevated); }
|
||||
@@ -187,7 +187,7 @@
|
||||
.body { display: flex; height: calc(100% - var(--rs-titlebar-height)); min-height: 0; }
|
||||
aside { width: 220px; flex-shrink: 0; padding: 12px 8px; background: var(--rs-bg-elevated); border-right: 1px solid var(--rs-border); display: flex; flex-direction: column; overflow: auto; }
|
||||
.search { display: flex; gap: var(--rs-settings-gap); align-items: center; min-height: var(--rs-settings-control-height); background: var(--rs-bg-active); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); padding: 4px 8px; color: var(--rs-text-dim); }
|
||||
.search:focus-within { outline: 2px solid var(--rs-accent); }
|
||||
.search:focus-within { outline: 2px solid var(--rs-focus); }
|
||||
.search input { width: 100%; min-width: 0; border: 0; padding: 0; outline: none; background: transparent; color: var(--rs-text); }
|
||||
.nav-heading { margin: 16px 8px 6px; font-size: 11px; color: var(--rs-text-dim); }
|
||||
nav { display: flex; flex-direction: column; gap: 2px; }
|
||||
|
||||
@@ -67,12 +67,12 @@
|
||||
|
||||
<style>
|
||||
dialog{width:min(600px,90vw);max-height:80vh;padding:var(--rs-settings-section-gap);background:var(--rs-bg);color:var(--rs-text);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
|
||||
dialog::backdrop{background:#0008}
|
||||
dialog::backdrop{background:var(--rs-scrim)}
|
||||
header,.row,.actions,.new{display:flex;align-items:center;gap:var(--rs-settings-gap)}
|
||||
header{justify-content:space-between}h2{margin:0;font-size:var(--rs-settings-heading-size)}
|
||||
p{font-size:var(--rs-settings-description-size);color:var(--rs-text-dim);line-height:1.5}
|
||||
.list{margin-top:var(--rs-settings-gap);max-height:50vh;overflow:auto}.row{padding:var(--rs-settings-row-padding);border-bottom:1px solid var(--rs-border);flex-wrap:wrap}.row>span{flex:1;min-width:100px;overflow-wrap:anywhere}
|
||||
.new{min-height:var(--rs-settings-control-height);padding:4px 8px;background:var(--rs-bg-elevated);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
|
||||
.new :global(svg){width:16px;height:16px}[role=alert]{color:var(--rs-error)}
|
||||
.rename{display:flex;align-items:center;gap:4px;min-height:28px;padding:4px 8px;background:transparent;border:0;border-radius:var(--rs-control-radius)}.rename:hover{background:var(--rs-bg-active)}.rename:focus-visible{outline:2px solid var(--rs-accent)}.rename :global(svg){width:16px;height:16px}
|
||||
.rename{display:flex;align-items:center;gap:4px;min-height:28px;padding:4px 8px;background:transparent;border:0;border-radius:var(--rs-control-radius)}.rename:hover{background:var(--rs-bg-active)}.rename:focus-visible{outline:2px solid var(--rs-focus)}.rename :global(svg){width:16px;height:16px}
|
||||
</style>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<style>
|
||||
dialog { width: min(480px, 90vw); padding: 22px; background: var(--rs-bg-elevated); color: var(--rs-text); border: 1px solid var(--rs-border); }
|
||||
dialog::backdrop { background: #0008; }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
form { display: flex; flex-direction: column; gap: 16px; }
|
||||
input { width: 100%; background: var(--rs-bg); color: var(--rs-text-strong); border: 1px solid var(--rs-border); padding: 9px; }
|
||||
form div { display: flex; justify-content: flex-end; gap: 8px; }
|
||||
|
||||
@@ -1441,7 +1441,7 @@
|
||||
.terminal-hidden { display: none !important; }
|
||||
.terminal-maximized > .center, .terminal-maximized > .gutter-h { display: none; }
|
||||
.terminal-maximized > .bottom { flex: 1; height: auto; }
|
||||
.conflict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: var(--rs-bg-active); border-bottom: 1px solid var(--rs-warning, #ebcb8b); }
|
||||
.conflict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: var(--rs-bg-active); border-bottom: 1px solid var(--rs-warn); }
|
||||
.conflict span { flex: 1 1 300px; }
|
||||
.conflict button { border: 1px solid var(--rs-border); background: var(--rs-bg); padding: 4px 8px; }
|
||||
.disk-review { padding: 8px 12px; max-height: 35vh; overflow: auto; flex: 0 0 auto; }
|
||||
|
||||
@@ -160,7 +160,7 @@
|
||||
.recent { max-height: min(360px, 45vh); overflow: auto; }
|
||||
form button { display: flex; align-items: center; gap: 10px; background: transparent; border: 1px solid transparent; border-radius: var(--rs-control-radius); padding: 9px 10px; color: var(--rs-text); text-align: left; }
|
||||
form button:hover { background: var(--rs-bg-active); }
|
||||
form button:focus-visible, input:focus-visible { outline: 2px solid var(--rs-accent); outline-offset: -2px; }
|
||||
form button:focus-visible, input:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: -2px; }
|
||||
form button:disabled { opacity: .5; }
|
||||
.workspace-row, footer button { width: 100%; }
|
||||
.workspace-entry { display: flex; align-items: stretch; }
|
||||
@@ -171,7 +171,7 @@
|
||||
.current-label { font-size: 11px; color: var(--rs-accent); }
|
||||
footer { border-top: 1px solid var(--rs-border); margin-top: 6px; padding-top: 6px; }
|
||||
dialog { width: min(480px, calc(100vw - 32px)); padding: 22px; }
|
||||
dialog::backdrop { background: #0008; }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
form { display: flex; flex-direction: column; gap: 12px; }
|
||||
form h2, form p { padding: 0; margin: 0; }
|
||||
form label { font-size: 13px; }
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
.reading > :first-child { margin-top: 0; }
|
||||
.reading p { margin: 0 0 .75em; white-space: pre-line; }
|
||||
.reading strong { font-weight: 600; color: var(--rs-text-strong); }
|
||||
.reading a { color: var(--rs-accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
|
||||
.reading a { color: var(--rs-link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
|
||||
.reading a:hover { color: var(--rs-accent-2); }
|
||||
.reading hr { border: 0; border-top: 1px solid var(--rs-border); margin: 2em 0; }
|
||||
|
||||
@@ -156,7 +156,7 @@
|
||||
.reading .md-properties summary { padding: 9px 12px; cursor: pointer; }
|
||||
.reading .md-properties summary:hover { color: var(--rs-text-strong); }
|
||||
.reading .md-properties pre { margin: 0; padding: 12px; border: 0; border-top: 1px solid var(--rs-border); border-radius: 0 0 6px 6px; white-space: pre-wrap; }
|
||||
.reading mark { background: color-mix(in srgb, #edc65b 30%, transparent); color: inherit; border-radius: 2px; }
|
||||
.reading mark { background: color-mix(in srgb, var(--rs-highlight) 30%, transparent); color: inherit; border-radius: 2px; }
|
||||
.reading .md-inline-math { font-family: var(--rs-font-mono); font-style: italic; }
|
||||
.reading .md-inline-comment { display: none; }
|
||||
.reading:not(.cm-content) :is(p, h1, h2, h3, h4, h5, h6):not(td *, th *) { position: relative; }
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<style>
|
||||
.access-button { display: flex; align-items: center; gap: 6px; white-space: nowrap; min-height: 32px; padding: 5px 8px; border: 0; border-radius: var(--rs-control-radius); background: transparent; color: var(--rs-text); }
|
||||
.access-button:hover, .access-button[aria-expanded="true"] { background: var(--rs-bg-active); }
|
||||
.access-button:focus-visible { outline: 2px solid var(--rs-accent); outline-offset: -2px; }
|
||||
.access-button:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: -2px; }
|
||||
.access-button.compact { position: relative; width: 28px; height: 28px; min-height: 28px; padding: 5px; }
|
||||
.error { position: fixed; top: 48px; right: 12px; z-index: 60; max-width: 420px; padding: 12px; background: var(--rs-bg); color: var(--rs-error); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||||
</style>
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
input[role=switch]:checked { background: var(--rs-accent); border-color: var(--rs-accent); }
|
||||
input[role=switch]:checked::before { transform: translateX(16px); background: var(--rs-bg); }
|
||||
dialog { width: min(650px, 90vw); max-height: 85vh; padding: 16px; color: var(--rs-text); background: var(--rs-bg); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||||
dialog::backdrop { background: #0009; }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
footer { justify-content: flex-end; margin-top: var(--rs-settings-section-gap); }
|
||||
.candidate { padding: var(--rs-settings-row-padding) 0; border-bottom: 1px solid var(--rs-border); }
|
||||
.candidate label { display: flex; gap: 8px; }
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
{/if}
|
||||
<style>
|
||||
dialog { width: min(800px, 90vw); max-height: 85vh; padding: 20px; color: var(--rs-text); background: var(--rs-bg); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||||
dialog::backdrop { background: #0008; }
|
||||
dialog::backdrop { background: var(--rs-scrim); }
|
||||
header { display: flex; justify-content: space-between; align-items: center; }
|
||||
h2 { font-size: 18px; }
|
||||
.plugin-content { min-height: 140px; }
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { showActionMenu } from '$lib/ui/managedActionMenu';
|
||||
import { saveBackgroundImage, removeBackgroundImage } from './backgroundImages';
|
||||
import { onSettingsChange } from '$lib/settings/store';
|
||||
import { DEFAULT_APPEARANCE, BUILTIN_THEMES, themeModes, BACKGROUND_POSITIONS, BACKGROUND_SIZES, readAppearance, normalizeAppearance, saveAppearance, exportAppearanceTheme, type Appearance, type ThemeName } from './appearance';
|
||||
import { DEFAULT_APPEARANCE, BUILTIN_THEMES, themeModes, themeNotice, BACKGROUND_POSITIONS, BACKGROUND_SIZES, readAppearance, normalizeAppearance, saveAppearance, exportAppearanceTheme, type Appearance, type ThemeName } from './appearance';
|
||||
let appearance = $state<Appearance>({ ...DEFAULT_APPEARANCE });
|
||||
let error = $state('');
|
||||
let status = $state('');
|
||||
@@ -22,6 +22,7 @@
|
||||
themeModes(theme.id).map(mode => ({
|
||||
theme: theme.id, mode, name: themeModes(theme.id).length === 1 ? theme.name : `${theme.name} ${mode === 'light' ? $t('Light') : $t('Dark')}`,
|
||||
}))));
|
||||
const notice = $derived(themeNotice(appearance.theme));
|
||||
onDestroy(() => closePicker());
|
||||
function picker(event: MouseEvent) {
|
||||
closePicker();
|
||||
@@ -131,7 +132,7 @@
|
||||
}} />{/if}
|
||||
</div>
|
||||
<p>{$t("Edit the exported JSON colors and fonts, then choose Install theme. The template contains one color palette and font families.")}</p>
|
||||
{#if appearance.theme === 'sakura'}<p>{$t("Sakura uses a light appearance.")}</p>{/if}
|
||||
{#if notice}<p>{$t(notice)}</p>{/if}
|
||||
<h3>{$t("Transparency")}</h3>
|
||||
<div class="card">
|
||||
<label><span>{$t("Transparent surfaces")}</span><input type="checkbox" role="switch" checked={appearance.transparency?.enabled !== false} onchange={event => change({ ...appearance, transparency: { amount: appearance.transparency?.amount ?? 18, enabled: event.currentTarget.checked } })} /></label>
|
||||
@@ -165,7 +166,7 @@
|
||||
.setting-row+.setting-row{border-top:1px solid var(--rs-border)}
|
||||
.picker{display:flex;align-items:center;gap:8px;min-height:var(--rs-settings-control-height);max-width:100%;padding:4px 8px;background:var(--rs-bg);color:var(--rs-text);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius)}
|
||||
.picker :global(svg){width:14px;height:14px;flex-shrink:0}
|
||||
.picker:focus-visible{outline:2px solid var(--rs-accent);outline-offset:2px}
|
||||
.picker:focus-visible{outline:2px solid var(--rs-focus);outline-offset:2px}
|
||||
.theme-preview{display:flex;gap:var(--rs-settings-gap);margin-top:var(--rs-settings-gap);padding:var(--rs-settings-row-padding);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg);min-height:100px}
|
||||
.preview-sidebar{display:flex;flex-direction:column;gap:var(--rs-settings-gap);width:22%;padding:var(--rs-settings-row-padding);background:var(--rs-bg-elevated);border-radius:var(--rs-control-radius)}
|
||||
.preview-sidebar span{height:6px;background:var(--rs-text-dim);opacity:.5;border-radius:var(--rs-control-radius)}
|
||||
@@ -174,7 +175,7 @@
|
||||
.preview-document strong{color:var(--rs-text-strong);font-family:var(--rs-font-heading)}
|
||||
.preview-prose{font-family:var(--rs-font-prose);color:var(--rs-text)}
|
||||
.preview-selection{background:var(--rs-selection);color:var(--rs-text);padding:2px 4px;border-radius:var(--rs-item-selection-radius)}
|
||||
.preview-link{color:var(--rs-accent);font-size:var(--rs-settings-description-size)}
|
||||
.preview-link{color:var(--rs-link);font-size:var(--rs-settings-description-size)}
|
||||
.preview-code{font-family:var(--rs-font-mono);font-size:var(--rs-settings-description-size);line-height:1.6;overflow-wrap:anywhere;white-space:normal}
|
||||
.preview-keyword{color:var(--rs-syntax-keyword)}
|
||||
.preview-string{color:var(--rs-syntax-string,var(--rs-ok))}
|
||||
@@ -189,13 +190,13 @@
|
||||
.overlay-controls input[type=range]::-webkit-slider-thumb{appearance:none;width:18px;height:18px;margin-top:-7px;background:var(--rs-accent);border:2px solid var(--rs-text-strong);border-radius:50%}
|
||||
.overlay-controls input[type=range]::-moz-range-track{height:4px;background:var(--rs-bg-active);border:1px solid var(--rs-text-dim);border-radius:var(--rs-control-radius)}
|
||||
.overlay-controls input[type=range]::-moz-range-thumb{width:14px;height:14px;background:var(--rs-accent);border:2px solid var(--rs-text-strong);border-radius:50%}
|
||||
.overlay-controls input[type=range]:focus-visible{outline:2px solid var(--rs-accent);outline-offset:2px;border-radius:var(--rs-control-radius)}
|
||||
.overlay-controls input[type=range]:focus-visible{outline:2px solid var(--rs-focus);outline-offset:2px;border-radius:var(--rs-control-radius)}
|
||||
.overlay-controls input[type=range]:disabled{cursor:default}
|
||||
.overlay-controls input[type=range]:disabled::-webkit-slider-thumb{background:var(--rs-text-dim)}
|
||||
.overlay-controls input[type=range]:disabled::-moz-range-thumb{background:var(--rs-text-dim)}
|
||||
.overlay-value{padding:0;gap:4px;flex-wrap:nowrap}
|
||||
.overlay-value input{width:64px;min-height:var(--rs-settings-control-height);box-sizing:border-box;padding:4px 6px;background:var(--rs-bg);color:var(--rs-text);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);font:inherit}
|
||||
.overlay-value input:focus-visible{outline:2px solid var(--rs-accent);outline-offset:2px}
|
||||
.overlay-value input:focus-visible{outline:2px solid var(--rs-focus);outline-offset:2px}
|
||||
[role=alert]{color:var(--rs-error)}
|
||||
.theme-actions{display:flex;gap:var(--rs-settings-gap);flex-wrap:wrap;margin-top:var(--rs-settings-gap)}
|
||||
.theme-actions button{min-height:var(--rs-settings-control-height);border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg-elevated);color:var(--rs-text);padding:4px 8px}
|
||||
|
||||
+44
-95
@@ -1,21 +1,24 @@
|
||||
import { customThemes, FONT_ROLES, type ThemeFonts, type ThemeColors, type CustomTheme } from './customThemes.ts';
|
||||
import { customThemes, FONT_ROLES, type ThemeFonts, type CustomTheme } from './customThemes.ts';
|
||||
import { readBackgroundImage } from './backgroundImages.ts';
|
||||
import { characterTheme, characterSyntax, SYNTAX_ROLES } from './characterThemes.ts';
|
||||
import { readSection, writeSection } from '../settings/store.ts';
|
||||
import { BUILTIN_THEMES as THEME_DATA, DEFAULT_FONTS, DEFAULT_THEME, LEGACY_THEME_IDS, builtinTheme, type BuiltinThemeId } from './themes/index.ts';
|
||||
import { ROLES, resolveColors, type Mode, type ResolvedColors } from './roles.ts';
|
||||
import { appliedColors } from './contrast.ts';
|
||||
/** The old localStorage key. The appearance section of the settings file replaces it. */
|
||||
export const APPEARANCE_KEY = 'runestone.appearance';
|
||||
export const THEMES = ['default', 'claude', 'sakura', 'harvest-moon', 'crimson-pilot', 'silver-serpent'] as const;
|
||||
export const BUILTIN_THEMES = [
|
||||
{ id: 'default', name: 'RuneStone' }, { id: 'claude', name: 'Claude' }, { id: 'sakura', name: 'Sakura' },
|
||||
{ id: 'harvest-moon', name: 'Harvest Moon' }, { id: 'crimson-pilot', name: 'Crimson Pilot' }, { id: 'silver-serpent', name: 'Silver Serpent' },
|
||||
] as const;
|
||||
// Preserve selections saved before the public palette IDs changed.
|
||||
const LEGACY_THEME_IDS: Record<string, typeof THEMES[number]> = { holo: 'harvest-moon', asuka: 'crimson-pilot', malfoid: 'silver-serpent' };
|
||||
export function themeModes(theme: string): readonly ('light' | 'dark')[] {
|
||||
const character = characterTheme(theme);
|
||||
return theme.startsWith('custom:') ? [customThemeMode(customThemes().find(item => `custom:${item.id}` === theme)?.colors)] : character ? [character.mode] : theme === 'sakura' ? ['light'] : ['light', 'dark'];
|
||||
export const THEMES: readonly BuiltinThemeId[] = THEME_DATA.map(theme => theme.id);
|
||||
export const BUILTIN_THEMES: readonly { id: BuiltinThemeId; name: string }[] = THEME_DATA.map(({ id, name }) => ({ id, name }));
|
||||
const MODES = ['light', 'dark'] as const;
|
||||
export function themeModes(theme: string): readonly Mode[] {
|
||||
if (theme.startsWith('custom:')) return [customThemes().find(item => `custom:${item.id}` === theme)?.mode ?? 'dark'];
|
||||
const builtin = builtinTheme(theme);
|
||||
return builtin ? MODES.filter(mode => builtin.variants[mode]) : MODES;
|
||||
}
|
||||
export type ThemeName = typeof THEMES[number] | `custom:${string}`;
|
||||
/** The catalog key of a notice that the Appearance settings show for the theme, if any. */
|
||||
export function themeNotice(theme: string): string | undefined {
|
||||
return builtinTheme(theme)?.notice;
|
||||
}
|
||||
export type ThemeName = BuiltinThemeId | `custom:${string}`;
|
||||
export const BACKGROUND_POSITIONS = ['center', 'top left', 'top', 'top right', 'left', 'right', 'bottom left', 'bottom', 'bottom right'] as const;
|
||||
export const BACKGROUND_SIZES = ['cover', 'contain', 'auto'] as const;
|
||||
export type Appearance = { transparency?: { enabled: boolean; amount: number }; theme: ThemeName; mode: 'light' | 'dark'; newTabBackground?: { image?: string; imageId?: string; overlay?: number; position?: typeof BACKGROUND_POSITIONS[number]; size?: typeof BACKGROUND_SIZES[number] } };
|
||||
@@ -25,7 +28,8 @@ export function normalizeAppearance(value: { theme?: unknown; mode?: unknown; ne
|
||||
const savedTheme = typeof value?.theme === 'string' && Object.hasOwn(LEGACY_THEME_IDS, value.theme) ? LEGACY_THEME_IDS[value.theme] : value?.theme;
|
||||
const theme: ThemeName = typeof savedTheme === 'string' && (/^custom:[a-z][a-z0-9-]{0,63}$/.test(savedTheme) || (THEMES as readonly string[]).includes(savedTheme)) ? savedTheme as ThemeName : 'default';
|
||||
const selectedCustom = theme.startsWith('custom:') ? (themes ?? customThemes(value?.mode === 'light' ? 'light' : 'dark')).find(item => `custom:${item.id}` === theme) : undefined;
|
||||
const result: Appearance = { theme, mode: selectedCustom ? customThemeMode(selectedCustom.colors) : characterTheme(theme)?.mode ?? (theme === 'sakura' || value?.mode === 'light' ? 'light' : 'dark') };
|
||||
const builtinModes = builtinTheme(theme) ? themeModes(theme) : undefined;
|
||||
const result: Appearance = { theme, mode: selectedCustom ? selectedCustom.mode : builtinModes?.length === 1 ? builtinModes[0] : value?.mode === 'light' ? 'light' : 'dark' };
|
||||
if (value?.transparency && typeof value.transparency === 'object') {
|
||||
const source = value.transparency as { enabled?: unknown; amount?: unknown };
|
||||
result.transparency = { enabled: source.enabled !== false, amount: typeof source.amount === 'number' && Number.isFinite(source.amount) ? Math.max(0, Math.min(100, Math.round(source.amount))) : 18 };
|
||||
@@ -51,62 +55,31 @@ export function readAppearance(): Appearance {
|
||||
const value = readSection('appearance');
|
||||
return normalizeAppearance(value && typeof value === 'object' && !Array.isArray(value) ? value : null);
|
||||
}
|
||||
const keys = ['bg', 'bg-elevated', 'bg-active', 'border', 'text-dim', 'text', 'text-strong', 'accent', 'selection'] as const;
|
||||
const palettes = {
|
||||
default: {
|
||||
dark: ['#141414','#1c1c1c','#2a2a2a','#2e2e2e','#9a9a9a','#e6e6e6','#f3f3f3','#82aaff','#264f78'],
|
||||
light: ['#f3f3f3','#ffffff','#e8e8e8','#d4d4d4','#626262','#1e1e1e','#111111','#315fb3','#add6ff'],
|
||||
},
|
||||
// Anthropic brand guidelines: https://github.com/anthropics/skills/blob/main/skills/brand-guidelines/SKILL.md
|
||||
claude: {
|
||||
dark: ['#141413','#20201e','#32322e','#5a5952','#b0aea5','#faf9f5','#faf9f5','#d97757','#674435'],
|
||||
light: ['#faf9f5','#faf9f5','#e8e6dc','#b0aea5','#67665f','#141413','#141413','#d97757','#e8e6dc'],
|
||||
},
|
||||
// Palette from pm-image:7968b79c-9d80-40a5-9e9a-696c26aacfb9. Sakura supports light mode only.
|
||||
sakura: {
|
||||
light: ['#fefcfc','#fefcfc','#dbeacb','#f8dbe6','#687788','#513346','#321c2a','#98556c','#ffc9dc'],
|
||||
},
|
||||
|
||||
};
|
||||
function builtinPalette(theme: ThemeName) {
|
||||
if (theme === 'sakura') return { light: palettes.sakura.light, dark: palettes.sakura.light };
|
||||
const character = characterTheme(theme);
|
||||
if (character) return { light: character.surfaces, dark: character.surfaces };
|
||||
return palettes[theme === 'claude' ? 'claude' : 'default'];
|
||||
/**
|
||||
* Every color role and the font stacks of a theme. A custom theme uses its own mode, and gets missing roles from its base theme.
|
||||
* `legacyMode` selects the palette of a schema 1 custom theme.
|
||||
*/
|
||||
export function resolveTheme(theme: ThemeName, mode: Mode, legacyMode: Mode = mode): { mode: Mode; colors: ResolvedColors; fonts: Required<ThemeFonts> } {
|
||||
const custom = theme.startsWith('custom:') ? customThemes(legacyMode).find(item => `custom:${item.id}` === theme) : undefined;
|
||||
if (custom) {
|
||||
const base = builtinTheme(custom.base ?? DEFAULT_THEME.id)?.variants[custom.mode] ?? DEFAULT_THEME.variants[custom.mode];
|
||||
return { mode: custom.mode, colors: resolveColors(custom.colors, custom.mode, base), fonts: { ...themeFonts(custom.base ?? DEFAULT_THEME.id), ...custom.fonts } };
|
||||
}
|
||||
const builtin = builtinTheme(theme);
|
||||
if (builtin && !builtin.variants[mode]) mode = themeModes(theme)[0];
|
||||
return { mode, colors: resolveColors(builtin?.variants[mode] ?? DEFAULT_THEME.variants[mode], mode), fonts: themeFonts(theme) };
|
||||
}
|
||||
export function customThemeMode(colors?: ThemeColors): 'light' | 'dark' {
|
||||
const hex = colors?.bg?.slice(1) ?? '141414';
|
||||
const full = hex.length <= 4 ? [...hex.slice(0, 3)].map(value => value + value).join('') : hex.slice(0, 6);
|
||||
const rgb = [0, 2, 4].map(index => parseInt(full.slice(index, index + 2), 16) / 255)
|
||||
.map(value => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
|
||||
return rgb[0] * .2126 + rgb[1] * .7152 + rgb[2] * .0722 > .179 ? 'light' : 'dark';
|
||||
}
|
||||
export function exportAppearanceTheme(theme: ThemeName, mode: 'light' | 'dark' = 'dark'): CustomTheme {
|
||||
/** A complete theme file of schema 3, with every role and font stack. */
|
||||
export function exportAppearanceTheme(theme: ThemeName, mode: Mode = 'dark'): CustomTheme {
|
||||
const custom = customThemes(mode).find(item => `custom:${item.id}` === theme);
|
||||
if (custom) mode = customThemeMode(custom.colors);
|
||||
mode = characterTheme(theme)?.mode ?? (theme === 'sakura' ? 'light' : mode);
|
||||
const palette = builtinPalette(theme)[mode];
|
||||
const colors: ThemeColors = Object.fromEntries(keys.map((key, index) => [key, palette[index]]));
|
||||
colors['accent-2'] = characterTheme(theme)?.secondary ?? (theme === 'claude' ? '#6a9bcc' : theme === 'sakura' ? '#607fa9' : colors.accent);
|
||||
const semantic = mode === 'light' ? ['#b42323', '#8a5700', '#806600', '#287b29', '#7740a5'] : ['#f44747', '#d68a00', '#cca700', '#89d185', '#c792ea'];
|
||||
if (theme === 'claude') { semantic[3] = '#788c5d'; semantic[4] = '#6a9bcc'; }
|
||||
if (theme === 'sakura') { semantic[3] = '#618c71'; semantic[4] = '#cb6b91'; }
|
||||
(['error', 'warn-hot', 'warn', 'ok', 'special'] as const).forEach((key, index) => colors[key] = semantic[index]);
|
||||
const syntax = theme === 'sakura' ? ['#cb6b91', '#98556c', '#618c71', '#69a2bd', '#607fa9', '#687788'] : [colors.special, colors.accent, colors.text, colors['accent-2'], colors['accent-2'], colors['text-dim']];
|
||||
(['parameter', 'keyword', 'local', 'static', 'instance', 'global'] as const).forEach((key, index) => colors[`syntax-${key}`] = syntax[index]);
|
||||
Object.assign(colors, { 'syntax-string': colors.ok, 'syntax-number': colors.special, 'syntax-comment': colors['text-dim'], 'syntax-type': colors['accent-2'], 'syntax-function': colors['accent-2'] }, characterSyntax(theme));
|
||||
return { schema: 2, id: custom?.id ?? 'my-theme', name: custom?.name ?? 'My theme', colors: { ...colors, ...custom?.colors }, fonts: { ...themeFonts(theme), ...custom?.fonts } };
|
||||
const resolved = resolveTheme(theme, mode);
|
||||
return {
|
||||
schema: 3, id: custom?.id ?? 'my-theme', name: custom?.name ?? 'My theme', mode: resolved.mode,
|
||||
colors: Object.fromEntries(ROLES.map(role => [role, resolved.colors[role]])), fonts: resolved.fonts,
|
||||
};
|
||||
}
|
||||
export function themeFonts(theme: ThemeName): Required<ThemeFonts> {
|
||||
const ui = '"Segoe UI Variable Text", "Segoe UI", ui-sans-serif, system-ui, sans-serif';
|
||||
const prose = '"Segoe UI Variable Display", "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif';
|
||||
const mono = '"Cascadia Mono", "Cascadia Code", "JetBrains Mono", "Fira Code", Consolas, ui-monospace, monospace';
|
||||
const fonts = { ui, prose, heading: prose, mono };
|
||||
if (theme === 'claude') return { ...fonts, ui: '"Lora", Georgia, serif', prose: '"Lora", Georgia, serif', heading: '"Poppins", Arial, sans-serif' };
|
||||
if (theme === 'harvest-moon') return { ...fonts, ui: 'Candara, "Trebuchet MS", "Segoe UI", sans-serif', prose: 'Constantia, Georgia, "Times New Roman", serif', heading: 'Constantia, Georgia, "Times New Roman", serif' };
|
||||
if (theme === 'crimson-pilot') return { ...fonts, ui: 'Bahnschrift, "Trebuchet MS", Arial, sans-serif', prose: '"Segoe UI", "Helvetica Neue", Arial, sans-serif', heading: 'Bahnschrift, "Trebuchet MS", Arial, sans-serif' };
|
||||
if (theme === 'silver-serpent') return { ...fonts, ui: 'Corbel, "Segoe UI", "Helvetica Neue", Arial, sans-serif', prose: '"Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif', heading: '"Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif' };
|
||||
return fonts;
|
||||
export function themeFonts(theme: string): Required<ThemeFonts> {
|
||||
return { ...DEFAULT_FONTS, ...builtinTheme(theme)?.fonts };
|
||||
}
|
||||
export function applyTransparency(value: Appearance['transparency'], root: HTMLElement) {
|
||||
const supplied = value?.amount ?? 18;
|
||||
@@ -168,8 +141,7 @@ function applyBackgroundImage(root: HTMLElement, image?: string) {
|
||||
export function applyAppearance(value: Appearance, root = document.documentElement) {
|
||||
const normalized = normalizeAppearance(value);
|
||||
const { theme, newTabBackground } = normalized;
|
||||
const custom = theme.startsWith('custom:') ? customThemes(normalized.mode).find(item => item.id === theme.slice(7)) : undefined;
|
||||
const mode = custom ? customThemeMode(custom.colors) : normalized.mode;
|
||||
const { mode, colors, fonts } = resolveTheme(theme, normalized.mode);
|
||||
applyTransparency(normalized.transparency, root);
|
||||
root.style.setProperty('--rs-new-tab-bg', 'var(--rs-bg)');
|
||||
const overlay = newTabBackground?.overlay ?? 0;
|
||||
@@ -182,33 +154,10 @@ export function applyAppearance(value: Appearance, root = document.documentEleme
|
||||
root.dataset.theme = mode;
|
||||
root.dataset.palette = theme;
|
||||
root.style.colorScheme = mode;
|
||||
const fonts = { ...themeFonts(theme), ...custom?.fonts };
|
||||
FONT_ROLES.forEach(role => root.style.setProperty(`--rs-font-${role}`, fonts[role]));
|
||||
const palette = builtinPalette(theme)[mode];
|
||||
keys.forEach((key, index) => root.style.setProperty(`--rs-${key}`, palette[index]));
|
||||
root.style.setProperty('--rs-accent-2', characterTheme(theme)?.secondary ?? (theme === 'claude' ? '#6a9bcc' : theme === 'sakura' ? '#607fa9' : 'var(--rs-accent)'));
|
||||
root.style.setProperty('--rs-accent-dim', 'color-mix(in srgb, var(--rs-accent) 80%, var(--rs-bg))');
|
||||
root.style.setProperty('--rs-accent-deep', 'color-mix(in srgb, var(--rs-accent) 60%, var(--rs-bg))');
|
||||
const semantic = mode === 'light' ? ['#b42323', '#8a5700', '#806600', '#287b29', '#7740a5']
|
||||
: ['#f44747', '#d68a00', '#cca700', '#89d185', '#c792ea'];
|
||||
if (theme === 'claude') { semantic[3] = '#788c5d'; semantic[4] = '#6a9bcc'; }
|
||||
if (theme === 'sakura') { semantic[3] = '#618c71'; semantic[4] = '#cb6b91'; }
|
||||
['error', 'warn-hot', 'warn', 'ok', 'special'].forEach((key, index) => root.style.setProperty(`--rs-${key}`, semantic[index]));
|
||||
SYNTAX_ROLES.forEach(role => root.style.removeProperty(`--rs-syntax-${role}`));
|
||||
const syntax = theme === 'sakura'
|
||||
? ['#cb6b91', '#98556c', '#618c71', '#69a2bd', '#607fa9', '#687788']
|
||||
: ['var(--rs-special)', 'var(--rs-accent)', 'var(--rs-text)', 'var(--rs-accent-2)', 'var(--rs-accent-2)', 'var(--rs-text-dim)'];
|
||||
['parameter', 'keyword', 'local', 'static', 'instance', 'global'].forEach((key, index) => root.style.setProperty(`--rs-syntax-${key}`, syntax[index]));
|
||||
for (const [key, color] of Object.entries(characterSyntax(theme))) root.style.setProperty(`--rs-${key}`, color);
|
||||
root.style.setProperty('--rs-danger', 'var(--rs-error)');
|
||||
if (custom) for (const [key, color] of Object.entries(custom.colors)) root.style.setProperty(`--rs-${key}`, color);
|
||||
// Keep the theme hue while exposing the background beneath selected text.
|
||||
const selection = root.style.getPropertyValue('--rs-selection').trim().slice(1);
|
||||
const fullSelection = selection.length <= 4 ? [...selection].map(part => part + part).join('') : selection;
|
||||
if (/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(fullSelection)) {
|
||||
const alpha = Math.min(166, fullSelection.length === 8 ? parseInt(fullSelection.slice(6), 16) : 255);
|
||||
root.style.setProperty('--rs-selection', `#${fullSelection.slice(0, 6)}${alpha.toString(16).padStart(2, '0')}`);
|
||||
}
|
||||
// Text selection keeps the theme hue and shows the background beneath it.
|
||||
const applied = appliedColors(colors);
|
||||
for (const role of ROLES) root.style.setProperty(`--rs-${role}`, applied[role]);
|
||||
window.dispatchEvent(new CustomEvent('runestone-theme-changed'));
|
||||
}
|
||||
/** Save and apply an appearance. Throws at once if browser storage refuses it. The promise reports a failed save. */
|
||||
|
||||
@@ -40,7 +40,7 @@ button:disabled {
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 1px solid var(--rs-accent);
|
||||
outline: 1px solid var(--rs-focus);
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import type { ThemeColors } from './customThemes.ts';
|
||||
|
||||
export const SYNTAX_ROLES = ['parameter', 'keyword', 'local', 'static', 'instance', 'global', 'string', 'number', 'comment', 'type', 'function'] as const;
|
||||
type CharacterTheme = { mode: 'light' | 'dark'; surfaces: string[]; syntax: string[]; secondary: string };
|
||||
|
||||
export const CHARACTER_THEMES = {
|
||||
'harvest-moon': {
|
||||
mode: 'dark',
|
||||
// Current Holo fan art: copper hair, brown tail, cream fur, and red eyes/apple.
|
||||
// Amber carries active and selected states. Green scenery is outside this palette.
|
||||
surfaces: ['#251b17', '#382820', '#40291c', '#ae744a', '#d3aa8b', '#eee3d1', '#fff4df', '#ffb52e', '#482714'],
|
||||
secondary: '#ff6740',
|
||||
syntax: ['#ffcc66', '#ff6740', '#eee3d1', '#ffe7b3', '#e5ae7e', '#ff8d55', '#ffc45b', '#ffffff', '#d3aa8b', '#ffe19a', '#ffb52e'],
|
||||
},
|
||||
'crimson-pilot': {
|
||||
mode: 'dark',
|
||||
surfaces: ['#210b10', '#341018', '#461620', '#d93840', '#e0b48e', '#f4ece1', '#ffffff', '#ff5b50', '#122b45'],
|
||||
secondary: '#ff9b18',
|
||||
syntax: ['#ffad32', '#ff5b50', '#f4ece1', '#b6dfff', '#efb278', '#83dc52', '#ffe066', '#ff8a3d', '#e0b48e', '#64c9ff', '#559fff'],
|
||||
},
|
||||
'silver-serpent': {
|
||||
mode: 'dark',
|
||||
surfaces: ['#151c1b', '#1d3029', '#223a32', '#528f74', '#bec8ce', '#e3e7eb', '#fff5d5', '#36e395', '#13533a'],
|
||||
secondary: '#c5d5e2',
|
||||
syntax: ['#f5d58c', '#36e395', '#e3e7eb', '#b8cbdd', '#f4c6ae', '#edc45f', '#a7e7c4', '#ffb79b', '#bec8ce', '#ffffff', '#61dfbb'],
|
||||
},
|
||||
} satisfies Record<string, CharacterTheme>;
|
||||
|
||||
export function characterTheme(theme: string): CharacterTheme | undefined {
|
||||
return CHARACTER_THEMES[theme as keyof typeof CHARACTER_THEMES];
|
||||
}
|
||||
|
||||
export function characterSyntax(theme: string): ThemeColors {
|
||||
const palette = characterTheme(theme);
|
||||
return palette ? Object.fromEntries(SYNTAX_ROLES.map((role, index) => [`syntax-${role}`, palette.syntax[index]])) : {};
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Color arithmetic for theme roles: hex parsing, sRGB mixing, WCAG contrast, and OKLab distance.
|
||||
|
||||
/** Red, green, and blue from 0 to 255, and alpha from 0 to 1. */
|
||||
export type Rgba = [number, number, number, number];
|
||||
|
||||
const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
||||
|
||||
export function isHex(value: unknown): value is string {
|
||||
return typeof value === 'string' && HEX.test(value);
|
||||
}
|
||||
|
||||
export function parseHex(color: string): Rgba {
|
||||
if (!isHex(color)) throw new Error(`Not a hexadecimal color: ${color}`);
|
||||
let digits = color.slice(1);
|
||||
if (digits.length <= 4) digits = [...digits].map(digit => digit + digit).join('');
|
||||
const values = digits.match(/../g)!.map(pair => parseInt(pair, 16));
|
||||
return [values[0], values[1], values[2], values.length === 4 ? values[3] / 255 : 1];
|
||||
}
|
||||
|
||||
/** Six hex digits for an opaque color, eight for a transparent one. */
|
||||
export function formatHex([red, green, blue, alpha]: Rgba): string {
|
||||
const channel = (value: number) => Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, '0');
|
||||
return `#${channel(red)}${channel(green)}${channel(blue)}${alpha >= 1 ? '' : channel(alpha * 255)}`;
|
||||
}
|
||||
|
||||
/** The long form of a hex color, in lowercase. */
|
||||
export function normalizeHex(color: string): string {
|
||||
return formatHex(parseHex(color));
|
||||
}
|
||||
|
||||
/** Set the alpha of a color, from 0 to 1. */
|
||||
export function withAlpha(color: string, alpha: number): string {
|
||||
const [red, green, blue] = parseHex(color);
|
||||
return formatHex([red, green, blue, alpha]);
|
||||
}
|
||||
|
||||
/** CSS `color-mix(in srgb, first amount, second)`, with premultiplied alpha. */
|
||||
export function mix(first: string, second: string, amount: number): string {
|
||||
const a = parseHex(first), b = parseHex(second);
|
||||
const alpha = a[3] * amount + b[3] * (1 - amount);
|
||||
if (alpha === 0) return formatHex([0, 0, 0, 0]);
|
||||
const channel = (index: number) => (a[index] * a[3] * amount + b[index] * b[3] * (1 - amount)) / alpha;
|
||||
return formatHex([channel(0), channel(1), channel(2), alpha]);
|
||||
}
|
||||
|
||||
/** The opaque color that a transparent foreground shows over an opaque background. */
|
||||
export function composite(foreground: string, background: string): string {
|
||||
const top = parseHex(foreground), bottom = parseHex(background);
|
||||
const channel = (index: number) => top[index] * top[3] + bottom[index] * (1 - top[3]);
|
||||
return formatHex([channel(0), channel(1), channel(2), 1]);
|
||||
}
|
||||
|
||||
function linear(value: number) {
|
||||
const channel = value / 255;
|
||||
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
||||
}
|
||||
|
||||
/** WCAG relative luminance of an opaque color. */
|
||||
export function luminance(color: string): number {
|
||||
const [red, green, blue] = parseHex(color);
|
||||
return linear(red) * 0.2126 + linear(green) * 0.7152 + linear(blue) * 0.0722;
|
||||
}
|
||||
|
||||
/** WCAG contrast ratio of two opaque colors, from 1 to 21. */
|
||||
export function contrast(first: string, second: string): number {
|
||||
const [high, low] = [luminance(first), luminance(second)].sort((a, b) => b - a);
|
||||
return (high + 0.05) / (low + 0.05);
|
||||
}
|
||||
|
||||
/** OKLab lightness and the a and b axes of an opaque color. */
|
||||
export function oklab(color: string): [number, number, number] {
|
||||
const [red, green, blue] = parseHex(color).slice(0, 3).map(linear);
|
||||
const l = Math.cbrt(0.4122214708 * red + 0.5363325363 * green + 0.0514459929 * blue);
|
||||
const m = Math.cbrt(0.2119034982 * red + 0.6806995451 * green + 0.1073969566 * blue);
|
||||
const s = Math.cbrt(0.0883024619 * red + 0.2817188376 * green + 0.6299787005 * blue);
|
||||
return [
|
||||
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
||||
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
||||
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
||||
];
|
||||
}
|
||||
|
||||
/** Euclidean distance in OKLab. About 0.02 is the smallest visible step. */
|
||||
export function distance(first: string, second: string): number {
|
||||
const a = oklab(first), b = oklab(second);
|
||||
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
||||
}
|
||||
|
||||
/** Black or white, whichever has more contrast on the color. */
|
||||
export function readableOn(color: string): string {
|
||||
return contrast('#000000', color) >= contrast('#ffffff', color) ? '#000000' : '#ffffff';
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Readability rules for theme roles. The unit tests and the theme editor use the same rules.
|
||||
// docs/ui-color.md lists the thresholds.
|
||||
import { composite, contrast, distance, formatHex, luminance, mix, parseHex } from './color.ts';
|
||||
import { ANSI_COLORS, SYNTAX_ROLES, type Mode, type ResolvedColors, type Role } from './roles.ts';
|
||||
|
||||
/** Text selection keeps at most this alpha, so the background shows through (UI-029). */
|
||||
export const SELECTION_ALPHA = 166 / 255;
|
||||
|
||||
/** The colors that the app applies. Text selection is at most 65% opaque. */
|
||||
export function appliedColors(colors: ResolvedColors): ResolvedColors {
|
||||
const [red, green, blue, alpha] = parseHex(colors.selection);
|
||||
return { ...colors, selection: formatHex([red, green, blue, Math.min(SELECTION_ALPHA, alpha)]) };
|
||||
}
|
||||
|
||||
/** Opaque surfaces as the app draws them. Each takes the applied colors of a theme. */
|
||||
export const SURFACES = {
|
||||
bg: colors => opaque(colors.bg),
|
||||
'bg-elevated': colors => composite(colors['bg-elevated'], opaque(colors.bg)),
|
||||
'bg-active': colors => composite(colors['bg-active'], opaque(colors.bg)),
|
||||
selection: colors => composite(colors.selection, opaque(colors.bg)),
|
||||
'line-highlight': colors => composite(colors['line-highlight'], opaque(colors.bg)),
|
||||
highlight: colors => composite(mix(colors.highlight, '#0000', 0.3), opaque(colors.bg)),
|
||||
'item-selection': colors => composite(colors['item-selection-bg'], composite(colors['bg-elevated'], opaque(colors.bg))),
|
||||
accent: colors => composite(colors.accent, opaque(colors.bg)),
|
||||
} satisfies Record<string, (colors: ResolvedColors) => string>;
|
||||
export type Surface = keyof typeof SURFACES;
|
||||
|
||||
function opaque(color: string) { return composite(color, '#000000'); }
|
||||
|
||||
const SYNTAX = SYNTAX_ROLES.map(role => `syntax-${role}` as const);
|
||||
// Black and white are exempt: one of them always matches the terminal background.
|
||||
const ANSI = ANSI_COLORS.filter(color => color !== 'black' && color !== 'white').flatMap(color => [`ansi-${color}`, `ansi-bright-${color}`] as const);
|
||||
|
||||
export type ContrastRule = { id: string; kind: 'contrast'; foregrounds: readonly Role[]; surfaces: readonly Surface[]; min: number };
|
||||
export type DistinctRule = { id: string; kind: 'distinct'; pairs: readonly (readonly [Role, Role])[]; min: number };
|
||||
export type VarietyRule = { id: string; kind: 'variety'; roles: readonly Role[]; min: number };
|
||||
export type LightestRule = { id: string; kind: 'lightest'; mode: Mode; role: Role; others: readonly Role[] };
|
||||
export type Rule = ContrastRule | DistinctRule | VarietyRule | LightestRule;
|
||||
|
||||
/** OKLab distance that keeps two status or identity colors apart. */
|
||||
export const DISTINCT_DISTANCE = 0.1;
|
||||
|
||||
export const RULES: readonly Rule[] = [
|
||||
{ id: 'text', kind: 'contrast', foregrounds: ['text', 'text-dim', 'text-strong'], surfaces: ['bg', 'bg-elevated', 'bg-active', 'selection'], min: 4.5 },
|
||||
{ id: 'accent-text', kind: 'contrast', foregrounds: ['accent', 'link'], surfaces: ['bg', 'bg-elevated', 'bg-active'], min: 4.5 },
|
||||
{ id: 'status-text', kind: 'contrast', foregrounds: ['error', 'warn', 'ok'], surfaces: ['bg', 'bg-elevated'], min: 4.5 },
|
||||
{ id: 'syntax', kind: 'contrast', foregrounds: SYNTAX, surfaces: ['bg', 'bg-active', 'line-highlight'], min: 4.5 },
|
||||
{ id: 'ansi', kind: 'contrast', foregrounds: ANSI, surfaces: ['bg'], min: 4.5 },
|
||||
{ id: 'focus', kind: 'contrast', foregrounds: ['focus'], surfaces: ['bg', 'bg-elevated', 'bg-active'], min: 3 },
|
||||
{ id: 'on-accent', kind: 'contrast', foregrounds: ['on-accent'], surfaces: ['accent'], min: 4.5 },
|
||||
{ id: 'highlight', kind: 'contrast', foregrounds: ['text'], surfaces: ['highlight'], min: 4.5 },
|
||||
{ id: 'selection-outline', kind: 'contrast', foregrounds: ['accent'], surfaces: ['item-selection'], min: 3 },
|
||||
{ id: 'status-distinct', kind: 'distinct', pairs: [['accent', 'error'], ['accent', 'warn'], ['accent', 'ok'], ['error', 'warn'], ['warn', 'ok'], ['error', 'ok']], min: DISTINCT_DISTANCE },
|
||||
{ id: 'syntax-variety', kind: 'variety', roles: SYNTAX, min: 7 },
|
||||
{ id: 'light-page', kind: 'lightest', mode: 'light', role: 'bg', others: ['bg-elevated', 'bg-active'] },
|
||||
];
|
||||
|
||||
export type Finding = { rule: string; subject: string; value: number; min: number; pass: boolean };
|
||||
|
||||
/** Every check of every rule for one theme. `colors` are the resolved colors, before the selection cap. */
|
||||
export function checkTheme(resolved: ResolvedColors, mode: Mode, rules: readonly Rule[] = RULES): Finding[] {
|
||||
const colors = appliedColors(resolved);
|
||||
const findings: Finding[] = [];
|
||||
const surfaceColors = Object.fromEntries(Object.entries(SURFACES).map(([name, color]) => [name, color(colors)])) as Record<Surface, string>;
|
||||
for (const rule of rules) {
|
||||
if (rule.kind === 'contrast') {
|
||||
for (const foreground of rule.foregrounds) for (const surface of rule.surfaces) {
|
||||
const value = contrast(composite(colors[foreground], surfaceColors[surface]), surfaceColors[surface]);
|
||||
findings.push({ rule: rule.id, subject: `${foreground} on ${surface}`, value, min: rule.min, pass: value >= rule.min });
|
||||
}
|
||||
} else if (rule.kind === 'distinct') {
|
||||
for (const [first, second] of rule.pairs) {
|
||||
const value = distance(composite(colors[first], surfaceColors.bg), composite(colors[second], surfaceColors.bg));
|
||||
findings.push({ rule: rule.id, subject: `${first} and ${second}`, value, min: rule.min, pass: value >= rule.min });
|
||||
}
|
||||
} else if (rule.kind === 'variety') {
|
||||
const value = new Set(rule.roles.map(role => colors[role].toLowerCase())).size;
|
||||
findings.push({ rule: rule.id, subject: 'distinct colors', value, min: rule.min, pass: value >= rule.min });
|
||||
} else if (rule.mode === mode) {
|
||||
const page = luminance(surfaceColors.bg);
|
||||
for (const other of rule.others) {
|
||||
const value = page - luminance(composite(colors[other], surfaceColors.bg));
|
||||
findings.push({ rule: rule.id, subject: `${rule.role} lighter than ${other}`, value, min: 0, pass: value > 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
return findings;
|
||||
}
|
||||
@@ -1,49 +1,92 @@
|
||||
import { tr } from "../i18n/index.ts";
|
||||
import { readSection, writeSection } from '../settings/store.ts';
|
||||
import { isHex, luminance } from './color.ts';
|
||||
import { ROLES, type Mode, type Role, type ThemeColors } from './roles.ts';
|
||||
import { builtinTheme } from './themes/index.ts';
|
||||
|
||||
export type { ThemeColors } from './roles.ts';
|
||||
|
||||
/** The old localStorage key. The customThemes section of the settings file replaces it. */
|
||||
export const CUSTOM_THEMES_KEY = "runestone.custom-themes";
|
||||
export const COLOR_TOKENS = ["bg", "bg-elevated", "bg-active", "border", "text", "text-dim", "text-strong", "accent", "accent-2", "selection", "error", "warn", "warn-hot", "ok", "special", "syntax-parameter", "syntax-keyword", "syntax-local", "syntax-static", "syntax-instance", "syntax-global", "syntax-string", "syntax-number", "syntax-comment", "syntax-type", "syntax-function"] as const;
|
||||
export type ThemeColors = Partial<Record<typeof COLOR_TOKENS[number], string>>;
|
||||
/** The color keys of schema 1 and 2 files. */
|
||||
export const LEGACY_COLOR_TOKENS = ["bg", "bg-elevated", "bg-active", "border", "text", "text-dim", "text-strong", "accent", "accent-2", "selection", "error", "warn", "warn-hot", "ok", "special", "syntax-parameter", "syntax-keyword", "syntax-local", "syntax-static", "syntax-instance", "syntax-global", "syntax-string", "syntax-number", "syntax-comment", "syntax-type", "syntax-function"] as const;
|
||||
// Schema 3 renamed these syntax roles. Source never used the parameter and static colors, so they have no new role.
|
||||
const LEGACY_SYNTAX: Readonly<Record<string, readonly Role[]>> = {
|
||||
"syntax-local": ["syntax-variable"], "syntax-instance": ["syntax-property"], "syntax-global": ["syntax-constant", "syntax-punctuation"],
|
||||
"syntax-parameter": [], "syntax-static": [],
|
||||
};
|
||||
export const FONT_ROLES = ['ui', 'prose', 'heading', 'mono'] as const;
|
||||
export type ThemeFonts = Partial<Record<typeof FONT_ROLES[number], string>>;
|
||||
export type CustomTheme = { schema: 2; id: string; name: string; colors: ThemeColors; fonts?: ThemeFonts };
|
||||
/**
|
||||
* A theme file and a saved custom theme. `base` is a built-in theme with a palette in `mode`.
|
||||
* Colors that the file does not give come from the base theme, by default RuneStone.
|
||||
*/
|
||||
export type CustomTheme = { schema: 3; id: string; name: string; mode: Mode; base?: string; colors: ThemeColors; fonts?: ThemeFonts };
|
||||
export type LegacyCustomTheme = { schema: 1; id: string; name: string; light: ThemeColors; dark: ThemeColors };
|
||||
|
||||
export function parseCustomTheme(input: unknown, legacyMode: "light" | "dark" = "dark"): CustomTheme {
|
||||
if (!input || typeof input !== "object") throw new Error(tr("Choose a RuneStone theme JSON file."));
|
||||
const value = input as Record<string, unknown>;
|
||||
if ((value.schema !== 1 && value.schema !== 2) || typeof value.id !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(value.id)
|
||||
|| typeof value.name !== "string" || !value.name.trim() || value.name.length > 80) throw new Error(tr("The theme needs schema 2, an ID, and a name."));
|
||||
const colors = (mode: string): ThemeColors => {
|
||||
const source = value[mode];
|
||||
if (!source || typeof source !== "object" || Array.isArray(source)) throw new Error(tr("The theme needs {mode} colors.", { mode }));
|
||||
const result: ThemeColors = {};
|
||||
for (const [key, color] of Object.entries(source)) {
|
||||
if (!(COLOR_TOKENS as readonly string[]).includes(key)) throw new Error(tr("Unknown theme color: {key}", { key }));
|
||||
if (typeof color !== "string" || !/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(color)) throw new Error(tr("Use a hexadecimal color for {key}.", { key }));
|
||||
result[key as keyof ThemeColors] = color;
|
||||
}
|
||||
if (!result.bg || !result.text || !result.accent) throw new Error(tr("The {mode} palette needs bg, text, and accent.", { mode }));
|
||||
return result;
|
||||
};
|
||||
if (value.schema === 1) { colors("light"); colors("dark"); }
|
||||
let fonts: ThemeFonts | undefined;
|
||||
if (value.fonts !== undefined) {
|
||||
if (!value.fonts || typeof value.fonts !== 'object' || Array.isArray(value.fonts)) throw new Error(tr("Use an object for theme fonts."));
|
||||
fonts = {};
|
||||
for (const [role, stack] of Object.entries(value.fonts)) {
|
||||
if (!(FONT_ROLES as readonly string[]).includes(role)) throw new Error(tr("Unknown theme font: {role}", { role }));
|
||||
if (typeof stack !== 'string' || stack.length > 512 || !/^[\p{L}\p{N} _,'"-]+$/u.test(stack) || !stack.trim()
|
||||
|| stack.split(',').some(family => !/^(?:"[^"\n]+"|'[^'\n]+'|[\p{L}\p{N}_ -]+)$/u.test(family.trim()))) throw new Error(tr("Use a font family stack for {role}.", { role }));
|
||||
fonts[role as keyof ThemeFonts] = stack.trim();
|
||||
}
|
||||
/** The mode of a schema 1 or 2 palette, from the lightness of its background. */
|
||||
function paletteMode(colors: ThemeColors): Mode {
|
||||
return luminance(colors.bg ?? '#141414') > .179 ? 'light' : 'dark';
|
||||
}
|
||||
|
||||
function parseColors(source: unknown, allowed: readonly string[]): ThemeColors {
|
||||
if (!source || typeof source !== "object" || Array.isArray(source)) throw new Error(tr("Use an object for theme colors."));
|
||||
const result: ThemeColors = {};
|
||||
for (const [key, color] of Object.entries(source)) {
|
||||
if (!allowed.includes(key)) throw new Error(tr("Unknown theme color: {key}", { key }));
|
||||
if (!isHex(color)) throw new Error(tr("Use a hexadecimal color for {key}.", { key }));
|
||||
result[key as Role] = color;
|
||||
}
|
||||
return { schema: 2, id: value.id, name: value.name.trim(), colors: colors(value.schema === 1 ? legacyMode : "colors"), ...(fonts ? { fonts } : {}) };
|
||||
return result;
|
||||
}
|
||||
|
||||
/** A schema 1 or 2 palette with the schema 3 role names. */
|
||||
function legacyColors(source: unknown, mode: string): ThemeColors {
|
||||
if (!source || typeof source !== "object" || Array.isArray(source)) throw new Error(tr("The theme needs {mode} colors.", { mode }));
|
||||
const colors = parseColors(source, LEGACY_COLOR_TOKENS);
|
||||
if (!colors.bg || !colors.text || !colors.accent) throw new Error(tr("The {mode} palette needs bg, text, and accent.", { mode }));
|
||||
const result: ThemeColors = {};
|
||||
for (const [key, color] of Object.entries(colors)) {
|
||||
for (const role of Object.hasOwn(LEGACY_SYNTAX, key) ? LEGACY_SYNTAX[key] : [key as Role]) result[role] = color;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseFonts(source: unknown): ThemeFonts | undefined {
|
||||
if (source === undefined) return undefined;
|
||||
if (!source || typeof source !== 'object' || Array.isArray(source)) throw new Error(tr("Use an object for theme fonts."));
|
||||
const fonts: ThemeFonts = {};
|
||||
for (const [role, stack] of Object.entries(source)) {
|
||||
if (!(FONT_ROLES as readonly string[]).includes(role)) throw new Error(tr("Unknown theme font: {role}", { role }));
|
||||
if (typeof stack !== 'string' || stack.length > 512 || !/^[\p{L}\p{N} _,'"-]+$/u.test(stack) || !stack.trim()
|
||||
|| stack.split(',').some(family => !/^(?:"[^"\n]+"|'[^'\n]+'|[\p{L}\p{N}_ -]+)$/u.test(family.trim()))) throw new Error(tr("Use a font family stack for {role}.", { role }));
|
||||
fonts[role as keyof ThemeFonts] = stack.trim();
|
||||
}
|
||||
return fonts;
|
||||
}
|
||||
|
||||
/** A theme file of schema 1, 2, or 3, as schema 3. A schema 1 file gives the palette of `legacyMode`. */
|
||||
export function parseCustomTheme(input: unknown, legacyMode: Mode = "dark"): CustomTheme {
|
||||
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error(tr("Choose a RuneStone theme JSON file."));
|
||||
const value = input as Record<string, unknown>;
|
||||
if ((value.schema !== 1 && value.schema !== 2 && value.schema !== 3) || typeof value.id !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(value.id)
|
||||
|| typeof value.name !== "string" || !value.name.trim() || value.name.length > 80) throw new Error(tr("The theme needs a schema number, an ID, and a name."));
|
||||
const fonts = parseFonts(value.fonts);
|
||||
const common = { schema: 3 as const, id: value.id, name: value.name.trim(), ...(fonts ? { fonts } : {}) };
|
||||
if (value.schema === 3) {
|
||||
if (value.mode !== 'light' && value.mode !== 'dark') throw new Error(tr("Use light or dark for the theme mode."));
|
||||
const mode: Mode = value.mode;
|
||||
const base = value.base === undefined ? undefined : typeof value.base === 'string' ? builtinTheme(value.base) : undefined;
|
||||
if (value.base !== undefined && !base?.variants[mode]) throw new Error(tr("Use a built-in theme with a {mode} palette as the base.", { mode }));
|
||||
return { ...common, mode, ...(base ? { base: base.id } : {}), colors: parseColors(value.colors, ROLES) };
|
||||
}
|
||||
if (value.schema === 1) { legacyColors(value.light, "light"); legacyColors(value.dark, "dark"); }
|
||||
const colors = value.schema === 1 ? legacyColors(value[legacyMode], legacyMode) : legacyColors(value.colors, "colors");
|
||||
return { ...common, mode: paletteMode(colors), colors };
|
||||
}
|
||||
|
||||
/** The saved custom themes. Version 1 themes use the palette of `legacyMode`, by default the saved appearance mode. */
|
||||
export function customThemes(legacyMode?: "light" | "dark"): CustomTheme[] {
|
||||
export function customThemes(legacyMode?: Mode): CustomTheme[] {
|
||||
try {
|
||||
const stored = readSection('customThemes');
|
||||
if (!Array.isArray(stored)) return [];
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Theme roles: the named colors of a theme. Each role is the CSS token `--rs-<role>`.
|
||||
// A theme gives the base roles. The other roles come from the base roles through one rule for all themes.
|
||||
// docs/ui-color.md describes each role and its contrast requirement.
|
||||
import { mix, readableOn } from './color.ts';
|
||||
|
||||
export type Mode = 'light' | 'dark';
|
||||
|
||||
/** Code colors in Source. src/lib/editor/sourceView.ts maps the syntax tags to these roles. */
|
||||
export const SYNTAX_ROLES = ['keyword', 'string', 'number', 'comment', 'type', 'function', 'property', 'variable', 'constant', 'punctuation', 'heading'] as const;
|
||||
/** The eight terminal colors. Each has a bright variant, for example `ansi-bright-red`. */
|
||||
export const ANSI_COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'] as const;
|
||||
|
||||
/** Every role, in the order of theme files and of resolution. A derived role comes after the roles that it uses. */
|
||||
export const ROLES = [
|
||||
'bg', 'bg-elevated', 'bg-active', 'border', 'text', 'text-dim', 'text-strong',
|
||||
'accent', 'accent-2', 'accent-dim', 'accent-deep', 'link', 'focus', 'on-accent',
|
||||
'selection', 'item-selection-bg', 'line-highlight', 'highlight', 'scrim',
|
||||
'error', 'warn', 'warn-hot', 'ok', 'special',
|
||||
'syntax-keyword', 'syntax-string', 'syntax-number', 'syntax-comment', 'syntax-type', 'syntax-function',
|
||||
'syntax-property', 'syntax-variable', 'syntax-constant', 'syntax-punctuation', 'syntax-heading',
|
||||
'ansi-black', 'ansi-red', 'ansi-green', 'ansi-yellow', 'ansi-blue', 'ansi-magenta', 'ansi-cyan', 'ansi-white',
|
||||
'ansi-bright-black', 'ansi-bright-red', 'ansi-bright-green', 'ansi-bright-yellow',
|
||||
'ansi-bright-blue', 'ansi-bright-magenta', 'ansi-bright-cyan', 'ansi-bright-white',
|
||||
] as const;
|
||||
export type Role = typeof ROLES[number];
|
||||
export type ThemeColors = Partial<Record<Role, string>>;
|
||||
export type ResolvedColors = Record<Role, string>;
|
||||
|
||||
/** The roles that every built-in theme gives. Other themes get the missing ones from their base theme. */
|
||||
export const BASE_ROLES = ['bg', 'bg-elevated', 'bg-active', 'border', 'text', 'text-dim', 'text-strong', 'accent', 'selection', 'error', 'warn', 'warn-hot', 'ok', 'special'] as const satisfies readonly Role[];
|
||||
|
||||
type Derive = (colors: ResolvedColors, mode: Mode) => string;
|
||||
const bright = (role: Role): Derive => colors => colors[role];
|
||||
|
||||
// Terminal red, green, and yellow follow the status colors. Blue, magenta, and cyan have their own defaults,
|
||||
// because the accent and special colors of a theme can have any hue.
|
||||
const DERIVED: Record<Exclude<Role, typeof BASE_ROLES[number]>, Derive> = {
|
||||
'accent-2': colors => colors.accent,
|
||||
'accent-dim': colors => mix(colors.accent, colors.bg, 0.8),
|
||||
'accent-deep': colors => mix(colors.accent, colors.bg, 0.6),
|
||||
link: colors => colors.accent,
|
||||
focus: colors => colors.accent,
|
||||
'on-accent': colors => readableOn(colors.accent),
|
||||
'item-selection-bg': colors => mix(colors.accent, '#0000', 0.2),
|
||||
'line-highlight': (_, mode) => mode === 'light' ? '#0000000d' : '#ffffff0d',
|
||||
highlight: () => '#edc65b',
|
||||
scrim: () => '#00000088',
|
||||
'syntax-keyword': colors => colors.accent,
|
||||
'syntax-string': colors => colors.ok,
|
||||
'syntax-number': colors => colors.special,
|
||||
'syntax-comment': colors => colors['text-dim'],
|
||||
'syntax-type': colors => colors['accent-2'],
|
||||
'syntax-function': colors => colors['accent-2'],
|
||||
'syntax-property': colors => colors['accent-2'],
|
||||
'syntax-variable': colors => colors.text,
|
||||
'syntax-constant': colors => colors['text-dim'],
|
||||
'syntax-punctuation': colors => colors['text-dim'],
|
||||
'syntax-heading': colors => colors['syntax-keyword'],
|
||||
'ansi-black': colors => colors['text-dim'],
|
||||
'ansi-red': colors => colors.error,
|
||||
'ansi-green': colors => colors.ok,
|
||||
'ansi-yellow': colors => colors.warn,
|
||||
'ansi-blue': (_, mode) => mode === 'light' ? '#0451a5' : '#3b8eea',
|
||||
'ansi-magenta': (_, mode) => mode === 'light' ? '#a626a4' : '#d670d6',
|
||||
'ansi-cyan': (_, mode) => mode === 'light' ? '#05748a' : '#29b8db',
|
||||
'ansi-white': colors => colors.text,
|
||||
'ansi-bright-black': colors => colors['text-dim'],
|
||||
'ansi-bright-red': bright('ansi-red'),
|
||||
'ansi-bright-green': bright('ansi-green'),
|
||||
'ansi-bright-yellow': bright('ansi-yellow'),
|
||||
'ansi-bright-blue': bright('ansi-blue'),
|
||||
'ansi-bright-magenta': bright('ansi-magenta'),
|
||||
'ansi-bright-cyan': bright('ansi-cyan'),
|
||||
'ansi-bright-white': colors => colors['text-strong'],
|
||||
};
|
||||
|
||||
/** Every role of a theme. `colors` wins over `base`, and the derivation rules fill the rest. */
|
||||
export function resolveColors(colors: ThemeColors, mode: Mode, base: ThemeColors = {}): ResolvedColors {
|
||||
const result = { ...base, ...colors } as ResolvedColors;
|
||||
for (const role of ROLES) {
|
||||
if (result[role]) continue;
|
||||
const derive = DERIVED[role as keyof typeof DERIVED];
|
||||
if (!derive) throw new Error(`The theme has no ${role} color.`);
|
||||
result[role] = derive(result, mode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { BuiltinTheme } from './index.ts';
|
||||
|
||||
// Anthropic brand guidelines: https://github.com/anthropics/skills/blob/main/skills/brand-guidelines/SKILL.md
|
||||
export const claude = {
|
||||
id: 'claude' as const,
|
||||
name: 'Claude',
|
||||
fonts: { ui: '"Lora", Georgia, serif', prose: '"Lora", Georgia, serif', heading: '"Poppins", Arial, sans-serif' },
|
||||
variants: {
|
||||
dark: {
|
||||
bg: '#141413', 'bg-elevated': '#20201e', 'bg-active': '#32322e', border: '#5a5952',
|
||||
text: '#faf9f5', 'text-dim': '#b0aea5', 'text-strong': '#faf9f5',
|
||||
accent: '#d97757', 'accent-2': '#6a9bcc', selection: '#674435',
|
||||
error: '#f44747', 'warn-hot': '#d68a00', warn: '#cca700', ok: '#788c5d', special: '#6a9bcc',
|
||||
},
|
||||
light: {
|
||||
bg: '#faf9f5', 'bg-elevated': '#faf9f5', 'bg-active': '#e8e6dc', border: '#b0aea5',
|
||||
text: '#141413', 'text-dim': '#67665f', 'text-strong': '#141413',
|
||||
accent: '#d97757', 'accent-2': '#6a9bcc', selection: '#e8e6dc',
|
||||
error: '#b42323', 'warn-hot': '#8a5700', warn: '#806600', ok: '#788c5d', special: '#6a9bcc',
|
||||
},
|
||||
},
|
||||
} satisfies BuiltinTheme;
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { BuiltinTheme } from './index.ts';
|
||||
|
||||
// Asuka Langley Soryu (Neon Genesis Evangelion).
|
||||
export const crimsonPilot = {
|
||||
id: 'crimson-pilot' as const,
|
||||
name: 'Crimson Pilot',
|
||||
legacyIds: ['asuka'],
|
||||
fonts: { ui: 'Bahnschrift, "Trebuchet MS", Arial, sans-serif', prose: '"Segoe UI", "Helvetica Neue", Arial, sans-serif', heading: 'Bahnschrift, "Trebuchet MS", Arial, sans-serif' },
|
||||
variants: {
|
||||
dark: {
|
||||
bg: '#210b10', 'bg-elevated': '#341018', 'bg-active': '#461620', border: '#d93840',
|
||||
text: '#f4ece1', 'text-dim': '#e0b48e', 'text-strong': '#ffffff',
|
||||
accent: '#ff5b50', 'accent-2': '#ff9b18', selection: '#122b45', 'item-selection-bg': '#122b45a6',
|
||||
error: '#f44747', 'warn-hot': '#d68a00', warn: '#cca700', ok: '#89d185', special: '#c792ea',
|
||||
'syntax-keyword': '#ff5b50', 'syntax-variable': '#f4ece1', 'syntax-property': '#efb278', 'syntax-constant': '#83dc52', 'syntax-punctuation': '#83dc52', 'syntax-string': '#ffe066', 'syntax-number': '#ff8a3d',
|
||||
'syntax-comment': '#e0b48e', 'syntax-type': '#64c9ff', 'syntax-function': '#559fff',
|
||||
},
|
||||
},
|
||||
} satisfies BuiltinTheme;
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { BuiltinTheme } from './index.ts';
|
||||
|
||||
// Holo (Spice and Wolf), from the current fan art: copper hair, brown tail, cream fur, and red eyes and apple.
|
||||
// Amber carries active and selected states. Green scenery is outside this palette.
|
||||
export const harvestMoon = {
|
||||
id: 'harvest-moon' as const,
|
||||
name: 'Harvest Moon',
|
||||
legacyIds: ['holo'],
|
||||
fonts: { ui: 'Candara, "Trebuchet MS", "Segoe UI", sans-serif', prose: 'Constantia, Georgia, "Times New Roman", serif', heading: 'Constantia, Georgia, "Times New Roman", serif' },
|
||||
variants: {
|
||||
dark: {
|
||||
bg: '#251b17', 'bg-elevated': '#382820', 'bg-active': '#40291c', border: '#ae744a',
|
||||
text: '#eee3d1', 'text-dim': '#d3aa8b', 'text-strong': '#fff4df',
|
||||
accent: '#ffb52e', 'accent-2': '#ff6740', selection: '#482714', 'item-selection-bg': '#482714a6',
|
||||
error: '#f44747', 'warn-hot': '#d68a00', warn: '#cca700', ok: '#89d185', special: '#c792ea',
|
||||
'syntax-keyword': '#ff6740', 'syntax-variable': '#eee3d1', 'syntax-property': '#e5ae7e', 'syntax-constant': '#ff8d55', 'syntax-punctuation': '#ff8d55', 'syntax-string': '#ffc45b', 'syntax-number': '#ffffff',
|
||||
'syntax-comment': '#d3aa8b', 'syntax-type': '#ffe19a', 'syntax-function': '#ffb52e',
|
||||
},
|
||||
},
|
||||
} satisfies BuiltinTheme;
|
||||
@@ -0,0 +1,45 @@
|
||||
// The built-in themes. Each theme is data: no code outside this folder may name a theme ID.
|
||||
import type { Mode, ThemeColors } from '../roles.ts';
|
||||
import type { ThemeFonts } from '../customThemes.ts';
|
||||
import { runestone } from './runestone.ts';
|
||||
import { claude } from './claude.ts';
|
||||
import { sakura } from './sakura.ts';
|
||||
import { harvestMoon } from './harvestMoon.ts';
|
||||
import { crimsonPilot } from './crimsonPilot.ts';
|
||||
import { silverSerpent } from './silverSerpent.ts';
|
||||
|
||||
export type BuiltinTheme = {
|
||||
id: string;
|
||||
name: string;
|
||||
/** Earlier IDs of this theme. A saved choice of an earlier ID selects this theme. */
|
||||
legacyIds?: readonly string[];
|
||||
/** A catalog key that the Appearance settings show while the theme is selected. */
|
||||
notice?: string;
|
||||
/** Font stacks that differ from the RuneStone stacks. */
|
||||
fonts?: ThemeFonts;
|
||||
/** One complete palette for each mode that the theme offers. */
|
||||
variants: Partial<Record<Mode, ThemeColors>>;
|
||||
};
|
||||
|
||||
export const DEFAULT_FONTS = {
|
||||
ui: '"Segoe UI Variable Text", "Segoe UI", ui-sans-serif, system-ui, sans-serif',
|
||||
prose: '"Segoe UI Variable Display", "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif',
|
||||
heading: '"Segoe UI Variable Display", "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif',
|
||||
mono: '"Cascadia Mono", "Cascadia Code", "JetBrains Mono", "Fira Code", Consolas, ui-monospace, monospace',
|
||||
} as const satisfies Required<ThemeFonts>;
|
||||
|
||||
/** The theme that a removed theme ID returns to, and the base of custom themes. */
|
||||
export const DEFAULT_THEME = runestone;
|
||||
|
||||
export const BUILTIN_THEMES = [runestone, claude, sakura, harvestMoon, crimsonPilot, silverSerpent] as const;
|
||||
export type BuiltinThemeId = typeof BUILTIN_THEMES[number]['id'];
|
||||
|
||||
/** The current ID for each earlier ID of a built-in theme. */
|
||||
export const LEGACY_THEME_IDS: Readonly<Record<string, BuiltinThemeId>> = Object.fromEntries(
|
||||
BUILTIN_THEMES.flatMap(theme => ('legacyIds' in theme ? theme.legacyIds : []).map(legacy => [legacy, theme.id])));
|
||||
|
||||
/** The built-in theme with this ID or earlier ID. */
|
||||
export function builtinTheme(id: string): BuiltinTheme | undefined {
|
||||
const current = Object.hasOwn(LEGACY_THEME_IDS, id) ? LEGACY_THEME_IDS[id] : id;
|
||||
return BUILTIN_THEMES.find(theme => theme.id === current);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { BuiltinTheme } from './index.ts';
|
||||
|
||||
export const runestone = {
|
||||
id: 'default' as const,
|
||||
name: 'RuneStone',
|
||||
variants: {
|
||||
dark: {
|
||||
bg: '#141414', 'bg-elevated': '#1c1c1c', 'bg-active': '#2a2a2a', border: '#2e2e2e',
|
||||
text: '#e6e6e6', 'text-dim': '#9a9a9a', 'text-strong': '#f3f3f3',
|
||||
accent: '#82aaff', selection: '#264f78',
|
||||
error: '#f44747', 'warn-hot': '#d68a00', warn: '#cca700', ok: '#89d185', special: '#c792ea',
|
||||
},
|
||||
light: {
|
||||
bg: '#f3f3f3', 'bg-elevated': '#ffffff', 'bg-active': '#e8e8e8', border: '#d4d4d4',
|
||||
text: '#1e1e1e', 'text-dim': '#626262', 'text-strong': '#111111',
|
||||
accent: '#315fb3', selection: '#add6ff',
|
||||
error: '#b42323', 'warn-hot': '#8a5700', warn: '#806600', ok: '#287b29', special: '#7740a5',
|
||||
},
|
||||
},
|
||||
} satisfies BuiltinTheme;
|
||||
@@ -0,0 +1,19 @@
|
||||
import { message } from '../../i18n/index.ts';
|
||||
import type { BuiltinTheme } from './index.ts';
|
||||
|
||||
// Palette from pm-image:7968b79c-9d80-40a5-9e9a-696c26aacfb9.
|
||||
export const sakura = {
|
||||
id: 'sakura' as const,
|
||||
name: 'Sakura',
|
||||
notice: message('Sakura uses a light appearance.'),
|
||||
variants: {
|
||||
light: {
|
||||
bg: '#fefcfc', 'bg-elevated': '#fefcfc', 'bg-active': '#dbeacb', border: '#f8dbe6',
|
||||
text: '#513346', 'text-dim': '#687788', 'text-strong': '#321c2a',
|
||||
accent: '#98556c', 'accent-2': '#607fa9', selection: '#ffc9dc', 'item-selection-bg': '#ffc9dca6',
|
||||
error: '#b42323', 'warn-hot': '#8a5700', warn: '#806600', ok: '#618c71', special: '#cb6b91',
|
||||
'syntax-keyword': '#98556c', 'syntax-variable': '#618c71',
|
||||
'syntax-property': '#607fa9', 'syntax-constant': '#687788', 'syntax-punctuation': '#687788',
|
||||
},
|
||||
},
|
||||
} satisfies BuiltinTheme;
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { BuiltinTheme } from './index.ts';
|
||||
|
||||
// "Malfoid", a fan creation: Draco Malfoy written as a female character. The books win over fan art.
|
||||
export const silverSerpent = {
|
||||
id: 'silver-serpent' as const,
|
||||
name: 'Silver Serpent',
|
||||
legacyIds: ['malfoid'],
|
||||
fonts: { ui: 'Corbel, "Segoe UI", "Helvetica Neue", Arial, sans-serif', prose: '"Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif', heading: '"Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif' },
|
||||
variants: {
|
||||
dark: {
|
||||
bg: '#151c1b', 'bg-elevated': '#1d3029', 'bg-active': '#223a32', border: '#528f74',
|
||||
text: '#e3e7eb', 'text-dim': '#bec8ce', 'text-strong': '#fff5d5',
|
||||
accent: '#36e395', 'accent-2': '#c5d5e2', selection: '#13533a', 'item-selection-bg': '#13533aa6',
|
||||
error: '#f44747', 'warn-hot': '#d68a00', warn: '#cca700', ok: '#89d185', special: '#c792ea',
|
||||
'syntax-keyword': '#36e395', 'syntax-variable': '#e3e7eb', 'syntax-property': '#f4c6ae', 'syntax-constant': '#edc45f', 'syntax-punctuation': '#edc45f', 'syntax-string': '#a7e7c4', 'syntax-number': '#ffb79b',
|
||||
'syntax-comment': '#bec8ce', 'syntax-type': '#ffffff', 'syntax-function': '#61dfbb',
|
||||
},
|
||||
},
|
||||
} satisfies BuiltinTheme;
|
||||
@@ -1,3 +1,4 @@
|
||||
/* Defaults until ThemeSync applies the theme. src/lib/theme/roles.ts lists the color roles that each theme sets. */
|
||||
:root {
|
||||
--rs-selection-text: var(--rs-text);
|
||||
--rs-tooltip-padding: 6px 10px;
|
||||
@@ -57,6 +58,11 @@
|
||||
--rs-warn: #cca700;
|
||||
--rs-ok: #89d185;
|
||||
--rs-special: #c792ea;
|
||||
--rs-link: var(--rs-accent);
|
||||
--rs-focus: var(--rs-accent);
|
||||
--rs-on-accent: #000000;
|
||||
--rs-highlight: #edc65b;
|
||||
--rs-scrim: #00000088;
|
||||
|
||||
--rs-font-ui: "Segoe UI Variable Text", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
|
||||
--rs-font-prose: "Segoe UI Variable Display", "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
|
||||
@@ -86,44 +92,7 @@
|
||||
--rs-h4: var(--rs-text);
|
||||
--rs-h5: var(--rs-text-dim);
|
||||
--rs-h6: var(--rs-text-dim);
|
||||
}
|
||||
|
||||
[data-theme="light"] {
|
||||
--rs-bg: #f3f3f3;
|
||||
--rs-bg-elevated: #ffffff;
|
||||
--rs-bg-active: #e8e8e8;
|
||||
--rs-border: #d4d4d4;
|
||||
--rs-text-dim: #6b6b6b;
|
||||
--rs-text: #1e1e1e;
|
||||
--rs-text-strong: #111111;
|
||||
--rs-selection: #add6ff;
|
||||
--rs-line-highlight: #0000000d;
|
||||
}
|
||||
|
||||
[data-palette="claude"] {
|
||||
--rs-font-ui: "Lora", Georgia, serif;
|
||||
--rs-font-prose: "Lora", Georgia, serif;
|
||||
--rs-font-heading: "Poppins", Arial, sans-serif;
|
||||
}
|
||||
|
||||
[data-palette="sakura"], [data-palette="harvest-moon"], [data-palette="crimson-pilot"], [data-palette="silver-serpent"] {
|
||||
--rs-item-selection-bg: var(--rs-selection);
|
||||
}
|
||||
|
||||
[data-palette="harvest-moon"] {
|
||||
--rs-font-ui: Candara, "Trebuchet MS", "Segoe UI", sans-serif;
|
||||
--rs-font-prose: Constantia, Georgia, "Times New Roman", serif;
|
||||
--rs-font-heading: var(--rs-font-prose);
|
||||
}
|
||||
|
||||
[data-palette="crimson-pilot"] {
|
||||
--rs-font-ui: Bahnschrift, "Trebuchet MS", Arial, sans-serif;
|
||||
--rs-font-prose: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
|
||||
--rs-font-heading: var(--rs-font-ui);
|
||||
}
|
||||
|
||||
[data-palette="silver-serpent"] {
|
||||
--rs-font-ui: Corbel, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
|
||||
--rs-font-prose: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
|
||||
--rs-font-heading: var(--rs-font-prose);
|
||||
/* Fixed colors that do not change with the theme. */
|
||||
--rs-caption-close-bg: #c42b1c;
|
||||
--rs-image-viewer-bg: #090a0de8;
|
||||
}
|
||||
|
||||
@@ -58,5 +58,5 @@
|
||||
border: 0;
|
||||
border-radius: var(--rs-control-radius);
|
||||
}
|
||||
.window-close :global(.icon-btn:hover) { background: #c42b1c; color: white; }
|
||||
.window-close :global(.icon-btn:hover) { background: var(--rs-caption-close-bg); color: white; }
|
||||
</style>
|
||||
|
||||
@@ -76,13 +76,13 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
|
||||
await settings.setViewportSize({ width: 1100, height: 780 });
|
||||
await choose('Color theme', label);
|
||||
await waitForAppearance(theme, mode);
|
||||
// The export is now one theme template, { schema, id, name, colors, fonts }, for the theme's own mode (src/lib/theme/appearance.ts:76-91).
|
||||
// The export is one schema 3 theme file with every role, for the theme's own mode (exportAppearanceTheme in src/lib/theme/appearance.ts).
|
||||
const template = await settings.evaluate(async theme => {
|
||||
const { exportAppearanceTheme } = await import('/src/lib/theme/appearance.ts');
|
||||
return exportAppearanceTheme(theme);
|
||||
}, theme);
|
||||
const colors = template.colors;
|
||||
// The applied selection color caps its alpha at a6 so text backgrounds show through (src/lib/theme/appearance.ts:197-203).
|
||||
// The applied selection color caps its alpha at a6 so text backgrounds show through (appliedColors in src/lib/theme/contrast.ts).
|
||||
const applied = { ...colors, selection: `${colors.selection.slice(0, 7)}a6` };
|
||||
const actual = await settings.evaluate(keys => {
|
||||
const css = getComputedStyle(document.documentElement);
|
||||
|
||||
@@ -128,10 +128,10 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
|
||||
assert.equal(await picker(secondSettings, "Appearance").count(), 0);
|
||||
const sakura = await settings.evaluate(() => {
|
||||
const css = getComputedStyle(document.documentElement);
|
||||
return Object.fromEntries(["bg", "border", "selection", "bg-active", "syntax-parameter", "syntax-keyword", "syntax-local", "syntax-static", "syntax-instance", "syntax-global"].map(key => [key, css.getPropertyValue(`--rs-${key}`).trim()]));
|
||||
return Object.fromEntries(["bg", "border", "selection", "bg-active", "syntax-keyword", "syntax-variable", "syntax-property", "syntax-constant", "syntax-punctuation"].map(key => [key, css.getPropertyValue(`--rs-${key}`).trim()]));
|
||||
});
|
||||
// The applied selection color caps its alpha at a6 so text backgrounds show through (src/lib/theme/appearance.ts:197-203).
|
||||
assert.deepEqual(sakura, { bg: "#fefcfc", border: "#f8dbe6", selection: "#ffc9dca6", "bg-active": "#dbeacb", "syntax-parameter": "#cb6b91", "syntax-keyword": "#98556c", "syntax-local": "#618c71", "syntax-static": "#69a2bd", "syntax-instance": "#607fa9", "syntax-global": "#687788" });
|
||||
// The applied selection color caps its alpha at a6 so text backgrounds show through (appliedColors in src/lib/theme/contrast.ts).
|
||||
assert.deepEqual(sakura, { bg: "#fefcfc", border: "#f8dbe6", selection: "#ffc9dca6", "bg-active": "#dbeacb", "syntax-keyword": "#98556c", "syntax-variable": "#618c71", "syntax-property": "#607fa9", "syntax-constant": "#687788", "syntax-punctuation": "#687788" });
|
||||
for (const [theme, savedMode, expectedTheme, mode] of [
|
||||
["gpt", "light", "default", "light"],
|
||||
["terminal", "dark", "default", "dark"],
|
||||
|
||||
@@ -19,8 +19,8 @@ await runSmoke("appearance/themeExport", async ({ page }) => {
|
||||
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
await exportButton.click();
|
||||
await page.getByRole("status").filter({ hasText: "Theme saved to" }).waitFor();
|
||||
// Exported templates use theme schema 2 (src/lib/theme/appearance.ts:90).
|
||||
assert.equal(await page.evaluate(() => JSON.parse(window.__TEST__.calls.find(call => call.command === "theme_export").args.contents).schema), 2);
|
||||
// Exported templates use theme schema 3 (exportAppearanceTheme in src/lib/theme/appearance.ts).
|
||||
assert.equal(await page.evaluate(() => JSON.parse(window.__TEST__.calls.find(call => call.command === "theme_export").args.contents).schema), 3);
|
||||
await page.evaluate(() => { window.__TEST__.state.exportResult = null; });
|
||||
await exportButton.click();
|
||||
await page.getByText("Export canceled.", { exact: true }).waitFor();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Import a custom theme JSON in Settings > Appearance; its dark and light backgrounds apply.
|
||||
// Import custom theme files in Settings > Appearance: schema 1 palettes for each mode, and a short schema 3 file with a base theme.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
@@ -15,8 +15,9 @@ await runSmoke(name, async ({ page }) => {
|
||||
await page.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
const theme = { schema: 1, id: "smoke", name: "Smoke theme", light: { bg: "#fefefe", text: "#222222", accent: "#334499" }, dark: { bg: "#181820", text: "#eeeeee", accent: "#aabbff" } };
|
||||
const importTheme = () => page.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: "smoke.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(theme)) });
|
||||
const background = () => page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim());
|
||||
const importTheme = (file = theme) => page.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: "smoke.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(file)) });
|
||||
const token = name => page.evaluate(name => getComputedStyle(document.documentElement).getPropertyValue(`--rs-${name}`).trim(), name);
|
||||
const background = () => token("bg");
|
||||
await importTheme();
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke");
|
||||
assert.equal(await background(), "#181820");
|
||||
@@ -29,5 +30,18 @@ await runSmoke(name, async ({ page }) => {
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke");
|
||||
assert.equal(await background(), "#fefefe");
|
||||
await page.screenshot({ path: path.join(output, "custom-theme-light.png") });
|
||||
console.log("PASS: custom theme import applies its dark and light backgrounds");
|
||||
|
||||
// A short schema 3 file takes the missing colors and fonts from its base theme. An earlier theme ID names the base.
|
||||
await importTheme({ schema: 3, id: "short", name: "Short theme", mode: "dark", base: "holo", colors: { accent: "#00c8ff" } });
|
||||
await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:short");
|
||||
assert.deepEqual([await background(), await token("accent"), await token("link"), await token("syntax-keyword")], ["#251b17", "#00c8ff", "#00c8ff", "#ff6740"]);
|
||||
assert.match(await token("font-ui"), /Candara/);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.dataset.theme), "dark");
|
||||
await page.screenshot({ path: path.join(output, "custom-theme-short.png") });
|
||||
|
||||
// A base without a palette in the file's mode stops the installation with an error.
|
||||
await importTheme({ schema: 3, id: "wrong", name: "Wrong base", mode: "dark", base: "sakura", colors: {} });
|
||||
await page.getByRole("alert").filter({ hasText: "Use a built-in theme with a dark palette as the base." }).waitFor();
|
||||
assert.equal(await page.evaluate(() => document.documentElement.dataset.palette), "custom:short");
|
||||
console.log("PASS: custom theme import applies schema 1 palettes, a short schema 3 file with a base, and rejects a wrong base");
|
||||
}, { timeout: 15000 });
|
||||
|
||||
@@ -65,14 +65,17 @@ await runSmoke('appearance/typography', async ({ browser }) => {
|
||||
await main.waitForFunction(theme => document.documentElement.dataset.palette === theme, theme);
|
||||
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).press('Control+Home');
|
||||
await main.evaluate(() => { getSelection().removeAllRanges(); document.activeElement?.blur(); });
|
||||
// The theme sets its fonts as inline properties of the root. Put back those values after each temporary change.
|
||||
for (const page of [main, settings]) {
|
||||
await page.evaluate(font => {
|
||||
for (const role of ['ui', 'prose', 'heading']) document.documentElement.style.setProperty(`--rs-font-${role}`, `"${font}"`);
|
||||
}, oldFont);
|
||||
const saved = await page.evaluate(font => ['ui', 'prose', 'heading'].map(role => {
|
||||
const value = document.documentElement.style.getPropertyValue(`--rs-font-${role}`);
|
||||
document.documentElement.style.setProperty(`--rs-font-${role}`, `"${font}"`);
|
||||
return value;
|
||||
}), oldFont);
|
||||
await page.screenshot({ path: path.join(output, `${theme}-before-${page === main ? 'document' : 'settings'}.png`) });
|
||||
await page.evaluate(() => {
|
||||
for (const role of ['ui', 'prose', 'heading']) document.documentElement.style.removeProperty(`--rs-font-${role}`);
|
||||
});
|
||||
await page.evaluate(saved => {
|
||||
['ui', 'prose', 'heading'].forEach((role, index) => document.documentElement.style.setProperty(`--rs-font-${role}`, saved[index]));
|
||||
}, saved);
|
||||
}
|
||||
const roles = {
|
||||
ui: await rendered(settings, selectors.ui),
|
||||
@@ -118,14 +121,14 @@ await runSmoke('appearance/typography', async ({ browser }) => {
|
||||
// Drop the first family from each stack and check that the fallback still renders glyphs.
|
||||
const fallback = {};
|
||||
for (const [role, page] of [['ui', settings], ['prose', main], ['heading', main]]) {
|
||||
await page.evaluate(role => {
|
||||
const css = getComputedStyle(document.documentElement);
|
||||
const stack = css.getPropertyValue(`--rs-font-${role}`);
|
||||
const stack = await page.evaluate(role => {
|
||||
const stack = getComputedStyle(document.documentElement).getPropertyValue(`--rs-font-${role}`);
|
||||
document.documentElement.style.setProperty(`--rs-font-${role}`, stack.slice(stack.indexOf(',') + 1));
|
||||
return stack;
|
||||
}, role);
|
||||
fallback[role] = await rendered(page, selectors[role]);
|
||||
assert(fallback[role].rendered.length > 0);
|
||||
await page.evaluate(role => document.documentElement.style.removeProperty(`--rs-font-${role}`), role);
|
||||
await page.evaluate(([role, stack]) => document.documentElement.style.setProperty(`--rs-font-${role}`, stack), [role, stack]);
|
||||
}
|
||||
report.push({ theme, oldFont, roles, fallback });
|
||||
console.log(`PASS ${theme}: real UI and prose sizes, rendered fonts, shared monospace, selection, narrow settings, keyboard focus, long plugin navigation`);
|
||||
|
||||
@@ -18,7 +18,7 @@ test('Migration reads the four old keys and the theme backup, and normalizes eac
|
||||
assert.deepEqual(sections, {
|
||||
general: { autosaveEnabled: false, autosaveSeconds: 5, showInternalFolder: false, tableFormulas: true },
|
||||
language: 'fr',
|
||||
customThemes: [custom],
|
||||
customThemes: [{ ...custom, schema: 3, mode: 'dark' }],
|
||||
customThemesLegacy: [{ schema: 1, id: 'kept' }],
|
||||
// The mode comes from the migrated custom theme, not from a store that is still empty.
|
||||
appearance: { theme: 'custom:night', mode: 'dark', transparency: { enabled: true, amount: 100 } },
|
||||
@@ -32,7 +32,7 @@ test('Migration of version 1 themes keeps the saved palette and adds the origina
|
||||
'runestone.custom-themes': JSON.stringify([legacy]),
|
||||
'runestone.custom-themes.legacy': JSON.stringify([legacy]),
|
||||
}));
|
||||
assert.deepEqual(sections.customThemes, [{ schema: 2, id: 'old', name: 'Old', colors: legacy.light }]);
|
||||
assert.deepEqual(sections.customThemes, [{ schema: 3, id: 'old', name: 'Old', mode: 'light', colors: legacy.light }]);
|
||||
assert.deepEqual(sections.customThemesLegacy, [legacy]);
|
||||
assert.deepEqual(sections.appearance, { theme: 'custom:old', mode: 'light' });
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { parseCustomTheme } from '../../../src/lib/theme/customThemes.ts';
|
||||
import { CHARACTER_THEMES, SYNTAX_ROLES } from '../../../src/lib/theme/characterThemes.ts';
|
||||
import { SYNTAX_ROLES } from '../../../src/lib/theme/roles.ts';
|
||||
import { parseAppearance, normalizeAppearance, exportAppearanceTheme, BUILTIN_THEMES, THEMES, themeModes } from '../../../src/lib/theme/appearance.ts';
|
||||
|
||||
test('Removed palettes preserve the saved mode with the default palette', () => {
|
||||
@@ -33,37 +33,17 @@ test('Removed character themes retain the saved background', () => {
|
||||
}
|
||||
});
|
||||
|
||||
function luminance(color: string) {
|
||||
const rgb = color.slice(1).match(/../g)!.map(value => parseInt(value, 16) / 255)
|
||||
.map(value => value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4);
|
||||
return rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722;
|
||||
}
|
||||
function contrast(foreground: string, background: string) {
|
||||
const values = [luminance(foreground), luminance(background)].sort((a, b) => b - a);
|
||||
return (values[0] + 0.05) / (values[1] + 0.05);
|
||||
}
|
||||
test('Character palettes restore one appearance and export readable surfaces and syntax', () => {
|
||||
for (const theme of Object.keys(CHARACTER_THEMES) as (keyof typeof CHARACTER_THEMES)[]) {
|
||||
const exported = exportAppearanceTheme(theme);
|
||||
// tests/unit/theme/contrast.spec.ts checks the readability of every palette.
|
||||
test('Single-mode palettes restore their one appearance and export a valid theme', () => {
|
||||
for (const { id } of BUILTIN_THEMES.filter(item => themeModes(item.id).length === 1)) {
|
||||
const [only] = themeModes(id);
|
||||
const exported = exportAppearanceTheme(id);
|
||||
for (const mode of ['light', 'dark'] as const) {
|
||||
assert.deepEqual(parseAppearance(JSON.stringify({ theme, mode })), { theme, mode: CHARACTER_THEMES[theme].mode });
|
||||
const colors = exported.colors;
|
||||
for (const foreground of ['text', 'text-dim', 'text-strong', 'accent'] as const) {
|
||||
for (const background of ['bg', 'bg-elevated', 'bg-active', 'selection'] as const) {
|
||||
if (foreground === 'accent' && background === 'selection') continue;
|
||||
assert(contrast(colors[foreground]!, colors[background]!) >= 4.5, `${theme} ${mode}: ${foreground} on ${background}`);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(parseAppearance(JSON.stringify({ theme: id, mode })), { theme: id, mode: only });
|
||||
}
|
||||
assert.deepEqual(themeModes(theme), [CHARACTER_THEMES[theme].mode]);
|
||||
assert.equal(exported.schema, 2);
|
||||
assert.equal(exported.schema, 3);
|
||||
assert.deepEqual(parseCustomTheme(exported), exported);
|
||||
for (const role of SYNTAX_ROLES) {
|
||||
for (const background of ['bg', 'bg-active'] as const) {
|
||||
assert(contrast(exported.colors[`syntax-${role}`]!, exported.colors[background]!) >= 4.5, `${theme}: ${role} on ${background}`);
|
||||
}
|
||||
}
|
||||
assert(new Set(SYNTAX_ROLES.map(role => exported.colors[`syntax-${role}`])).size >= 7);
|
||||
for (const role of SYNTAX_ROLES) assert.match(exported.colors[`syntax-${role}`] ?? '', /^#[0-9a-f]{6}$/);
|
||||
assert.notDeepEqual(exported.colors, exportAppearanceTheme('default').colors);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
// Character palettes: WCAG contrast of text and syntax colors on opaque and image-tinted surfaces, plus per-theme palette rules.
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { characterTheme, characterSyntax, SYNTAX_ROLES } from '../../../src/lib/theme/characterThemes.ts';
|
||||
import { BUILTIN_THEMES } from '../../../src/lib/theme/themes/index.ts';
|
||||
import { SYNTAX_ROLES, resolveColors } from '../../../src/lib/theme/roles.ts';
|
||||
|
||||
/** Every role of a dark character palette, with the derived roles. */
|
||||
function characterTheme(theme: string) {
|
||||
const palette = BUILTIN_THEMES.find(item => item.id === theme);
|
||||
return palette && 'dark' in palette.variants ? resolveColors(palette.variants.dark, 'dark') : undefined;
|
||||
}
|
||||
|
||||
const rgb = (color: string) => color.slice(1).match(/../g)!.map(value => parseInt(value, 16));
|
||||
const mix = (foreground: string, background: string, opacity: number) => '#' + rgb(foreground)
|
||||
@@ -19,13 +26,13 @@ function contrast(foreground: string, background: string) {
|
||||
/** Named foreground groups and surfaces of a palette. Image surfaces are tinted over a white image. */
|
||||
function roles(theme: string) {
|
||||
const palette = characterTheme(theme)!;
|
||||
const [bg, elevated, active, , dim, text, strong, accent, selection] = palette.surfaces;
|
||||
const { bg, 'bg-elevated': elevated, 'bg-active': active, 'text-dim': dim, text, 'text-strong': strong, accent, selection } = palette;
|
||||
const editorOnWhite = mix(bg, '#ffffff', 0.9);
|
||||
const panelOnWhite = mix(elevated, '#ffffff', 0.82);
|
||||
const foregrounds = {
|
||||
ui: { dim, text, strong },
|
||||
accents: { accent, secondary: palette.secondary },
|
||||
syntax: Object.fromEntries(SYNTAX_ROLES.map((role, index) => [`syntax-${role}`, palette.syntax[index]])),
|
||||
accents: { accent, secondary: palette['accent-2'] },
|
||||
syntax: Object.fromEntries(SYNTAX_ROLES.map(role => [`syntax-${role}`, palette[`syntax-${role}`]])),
|
||||
};
|
||||
const surfaces = {
|
||||
bg, elevated, active, selection, editorOnWhite, panelOnWhite,
|
||||
@@ -69,14 +76,14 @@ for (const { theme, name, checks } of readable) {
|
||||
|
||||
test('Harvest Moon uses the warm character colors for all palette roles', () => {
|
||||
const palette = characterTheme('harvest-moon')!;
|
||||
for (const color of [...palette.surfaces, palette.secondary, ...palette.syntax]) {
|
||||
const identity = ['bg', 'bg-elevated', 'bg-active', 'border', 'text', 'text-dim', 'text-strong', 'accent', 'accent-2', 'selection', ...SYNTAX_ROLES.map(role => `syntax-${role}` as const)] as const;
|
||||
for (const role of identity) {
|
||||
const color = palette[role];
|
||||
assert.match(color, /^#[0-9a-f]{6}$/i);
|
||||
const [red, green, blue] = rgb(color);
|
||||
assert(red >= green && green >= blue, `${color} must follow the copper, amber, red, or cream palette`);
|
||||
assert(red >= green && green >= blue, `${role} ${color} must follow the copper, amber, red, or cream palette`);
|
||||
}
|
||||
assert.equal(palette.mode, 'dark');
|
||||
assert.equal(Object.keys(characterSyntax('harvest-moon')).length, SYNTAX_ROLES.length);
|
||||
assert.deepEqual(characterSyntax('unknown'), {});
|
||||
assert.deepEqual(Object.keys(BUILTIN_THEMES.find(item => item.id === 'harvest-moon')!.variants), ['dark']);
|
||||
});
|
||||
|
||||
test('Silver Serpent selection has a readable perimeter and a separate fill', () => {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Readability rules for every built-in theme (src/lib/theme/contrast.ts), and the rule that only theme data names a theme.
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
||||
import { join, relative } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { BUILTIN_THEMES } from '../../../src/lib/theme/themes/index.ts';
|
||||
import { BASE_ROLES, resolveColors, type Mode } from '../../../src/lib/theme/roles.ts';
|
||||
import { RULES, checkTheme } from '../../../src/lib/theme/contrast.ts';
|
||||
import { composite, contrast, distance, formatHex, mix, parseHex } from '../../../src/lib/theme/color.ts';
|
||||
|
||||
// Rules that a palette fails today. Stages 5a-3 and 5a-4 redesign these palettes and remove each entry.
|
||||
const KNOWN_FAILURES: Record<string, readonly string[]> = {
|
||||
'default/dark': ['text', 'syntax-variety'],
|
||||
'default/light': ['text', 'syntax', 'syntax-variety', 'light-page'],
|
||||
'claude/dark': ['accent-text', 'status-text', 'syntax', 'status-distinct', 'syntax-variety'],
|
||||
'claude/light': ['accent-text', 'status-text', 'syntax', 'ansi', 'focus', 'selection-outline', 'syntax-variety', 'light-page'],
|
||||
'sakura/light': ['text', 'accent-text', 'status-text', 'syntax', 'ansi', 'syntax-variety', 'light-page'],
|
||||
'harvest-moon/dark': ['status-text', 'status-distinct'],
|
||||
'crimson-pilot/dark': ['status-distinct'],
|
||||
'silver-serpent/dark': ['status-text', 'status-distinct'],
|
||||
};
|
||||
|
||||
const variants = BUILTIN_THEMES.flatMap(theme => Object.entries(theme.variants).map(([mode, colors]) => ({ key: `${theme.id}/${mode}`, mode: mode as Mode, colors: colors! })));
|
||||
|
||||
for (const variant of variants) {
|
||||
const findings = checkTheme(resolveColors(variant.colors, variant.mode), variant.mode);
|
||||
for (const rule of RULES) {
|
||||
const results = findings.filter(finding => finding.rule === rule.id);
|
||||
if (!results.length) continue;
|
||||
const known = KNOWN_FAILURES[variant.key]?.includes(rule.id);
|
||||
const failures = results.filter(finding => !finding.pass).map(finding => `${finding.subject}: ${finding.value.toFixed(2)} (minimum ${finding.min})`);
|
||||
test(`${variant.key} passes the ${rule.id} rule`, known ? { todo: 'Known palette failure. Stages 5a-3 and 5a-4 redesign this palette.' } : {}, () => {
|
||||
assert.deepEqual(failures, []);
|
||||
});
|
||||
if (known) test(`${variant.key} still fails the known ${rule.id} rule`, () => {
|
||||
assert(failures.length > 0, `Remove ${rule.id} from KNOWN_FAILURES['${variant.key}'].`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test('Each known failure names a built-in variant and a rule', () => {
|
||||
for (const [key, rules] of Object.entries(KNOWN_FAILURES)) {
|
||||
assert(variants.some(variant => variant.key === key), key);
|
||||
for (const rule of rules) assert(RULES.some(item => item.id === rule), `${key}: ${rule}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('Every built-in variant gives all base roles as hex colors', () => {
|
||||
for (const variant of variants) {
|
||||
for (const role of BASE_ROLES) assert.match(variant.colors[role] ?? '', /^#[0-9a-f]{6}$/, `${variant.key}: ${role}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('Color arithmetic matches CSS and WCAG', () => {
|
||||
assert.deepEqual(parseHex('#0f08'), [0, 255, 0, 136 / 255]);
|
||||
assert.equal(formatHex([255, 0, 0, 1]), '#ff0000');
|
||||
assert.equal(mix('#82aaff', '#141414', 0.8), '#6c8cd0');
|
||||
assert.equal(mix('#82aaff', '#0000', 0.2), '#82aaff33');
|
||||
assert.equal(composite('#ffffff80', '#000000'), '#808080');
|
||||
assert.equal(contrast('#000000', '#ffffff').toFixed(1), '21.0');
|
||||
assert(distance('#ff0000', '#ff0000') === 0 && distance('#000000', '#ffffff') > 0.99);
|
||||
});
|
||||
|
||||
test('Only theme data names a theme ID', () => {
|
||||
const root = fileURLToPath(new URL('../../../src', import.meta.url));
|
||||
const ids = BUILTIN_THEMES.flatMap(theme => [theme.id, ...('legacyIds' in theme ? theme.legacyIds : [])]).filter(id => id !== 'default');
|
||||
const pattern = new RegExp(`(['"\`])(?:${ids.join('|')})\\1|data-palette=`);
|
||||
const files = (function walk(folder: string): string[] {
|
||||
return readdirSync(folder).flatMap(name => {
|
||||
const path = join(folder, name);
|
||||
return statSync(path).isDirectory() ? walk(path) : /\.(ts|svelte|css)$/.test(name) ? [path] : [];
|
||||
});
|
||||
})(root);
|
||||
const found = files.filter(file => !relative(root, file).startsWith(join('lib', 'theme', 'themes')) && !file.endsWith('messages.ts'))
|
||||
.filter(file => pattern.test(readFileSync(file, 'utf8')))
|
||||
.map(file => relative(root, file));
|
||||
assert.deepEqual(found, []);
|
||||
});
|
||||
@@ -1,11 +1,44 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { COLOR_TOKENS, parseCustomTheme } from '../../../src/lib/theme/customThemes.ts';
|
||||
import { applyTransparency, normalizeAppearance, exportAppearanceTheme, BUILTIN_THEMES, themeModes } from '../../../src/lib/theme/appearance.ts';
|
||||
import { parseCustomTheme } from '../../../src/lib/theme/customThemes.ts';
|
||||
import { ROLES } from '../../../src/lib/theme/roles.ts';
|
||||
import { BUILTIN_THEMES as THEME_DATA } from '../../../src/lib/theme/themes/index.ts';
|
||||
import { applyTransparency, normalizeAppearance, exportAppearanceTheme, resolveTheme, BUILTIN_THEMES, themeModes } from '../../../src/lib/theme/appearance.ts';
|
||||
const palette = { bg: '#123', text: '#abcdef', accent: '#AABBCC' };
|
||||
const theme = { schema: 2, id: 'my-theme', name: 'My theme', colors: palette };
|
||||
test('Fixed theme palettes retain all supplied colors', () => {
|
||||
assert.deepEqual(parseCustomTheme(theme), theme);
|
||||
test('Schema 2 palettes convert to schema 3 and retain all supplied colors', () => {
|
||||
assert.deepEqual(parseCustomTheme(theme), { ...theme, schema: 3, mode: 'dark' });
|
||||
assert.equal(parseCustomTheme({ ...theme, colors: { ...palette, bg: '#fafafa' } }).mode, 'light');
|
||||
});
|
||||
test('Old syntax names convert to the schema 3 roles', () => {
|
||||
const colors = { ...palette, 'syntax-local': '#111111', 'syntax-instance': '#222222', 'syntax-global': '#333333', 'syntax-parameter': '#444444', 'syntax-static': '#555555', 'syntax-keyword': '#666666' };
|
||||
assert.deepEqual(parseCustomTheme({ ...theme, colors }).colors, {
|
||||
...palette, 'syntax-variable': '#111111', 'syntax-property': '#222222', 'syntax-constant': '#333333', 'syntax-punctuation': '#333333', 'syntax-keyword': '#666666',
|
||||
});
|
||||
assert.throws(() => parseCustomTheme({ ...theme, colors: { ...palette, 'syntax-variable': '#111111' } }), /Unknown theme color/);
|
||||
});
|
||||
test('Schema 3 files name their mode and can take missing colors from a built-in base', () => {
|
||||
const file = { schema: 3, id: 'amber', name: 'Amber', mode: 'dark', base: 'holo', colors: { accent: '#00ff00', 'ansi-blue': '#0000ff' } };
|
||||
assert.deepEqual(parseCustomTheme(file), { ...file, base: 'harvest-moon' });
|
||||
assert.deepEqual(parseCustomTheme({ ...file, base: undefined, colors: {} }), { schema: 3, id: 'amber', name: 'Amber', mode: 'dark', colors: {} });
|
||||
for (const invalid of [{ mode: 'dim' }, { mode: undefined }, { base: 'sakura' }, { base: 'unknown' }, { base: 4 }, { colors: [] }, { colors: { 'accent-x': '#000' } }, { colors: { accent: 'red' } }]) {
|
||||
assert.throws(() => parseCustomTheme({ ...file, ...invalid }), JSON.stringify(invalid));
|
||||
}
|
||||
const previous = globalThis.localStorage;
|
||||
try {
|
||||
const stored = new Map([['runestone.custom-themes', JSON.stringify([file])]]);
|
||||
globalThis.localStorage = { getItem: (key: string) => stored.get(key) ?? null, setItem: (key: string, value: string) => stored.set(key, value) } as unknown as Storage;
|
||||
const resolved = resolveTheme('custom:amber', 'light');
|
||||
const harvest = THEME_DATA.find(item => item.id === 'harvest-moon')!;
|
||||
assert.equal(resolved.mode, 'dark');
|
||||
assert.equal(resolved.colors.bg, harvest.variants.dark.bg);
|
||||
assert.equal(resolved.colors.accent, '#00ff00');
|
||||
assert.equal(resolved.colors['syntax-keyword'], harvest.variants.dark['syntax-keyword']);
|
||||
assert.equal(resolved.colors.link, '#00ff00', 'A derived role follows the colors of the file');
|
||||
assert.equal(resolved.colors['ansi-blue'], '#0000ff');
|
||||
assert.match(resolved.fonts.ui, /Candara/);
|
||||
assert.deepEqual(themeModes('custom:amber'), ['dark']);
|
||||
} finally { globalThis.localStorage = previous; }
|
||||
});
|
||||
test('Legacy import selects the current appearance and validates both palettes', () => {
|
||||
const light = { ...palette, bg: '#fff' };
|
||||
@@ -20,10 +53,11 @@ test('Theme files reject CSS injection, unknown tokens, and incomplete palettes'
|
||||
}
|
||||
assert.throws(() => parseCustomTheme({ ...theme, id: '../unsafe' }));
|
||||
});
|
||||
test('Every built-in template contains every current color token and one palette', () => {
|
||||
test('Every built-in template contains every role and one palette', () => {
|
||||
for (const item of BUILTIN_THEMES) for (const mode of themeModes(item.id)) {
|
||||
const exported = exportAppearanceTheme(item.id, mode);
|
||||
assert.deepEqual(Object.keys(exported.colors).sort(), [...COLOR_TOKENS].sort());
|
||||
assert.deepEqual(Object.keys(exported.colors), [...ROLES]);
|
||||
assert.equal(exported.mode, mode);
|
||||
assert.deepEqual(parseCustomTheme(exported), exported);
|
||||
assert.equal('light' in exported, false);
|
||||
assert.equal('dark' in exported, false);
|
||||
@@ -86,7 +120,7 @@ test('Saved legacy light themes migrate once and preserve both original palettes
|
||||
const legacy = { schema: 1, id: 'saved-light', name: 'Saved light', light: { ...palette, bg: '#fff' }, dark: { ...palette, bg: '#111' } };
|
||||
const old = new Map([[CUSTOM_THEMES_KEY, JSON.stringify([legacy])], ['runestone.appearance', JSON.stringify({ theme: 'custom:saved-light', mode: 'light' })]]);
|
||||
const sections = migrateLegacyPreferences(key => old.get(key) ?? null);
|
||||
assert.equal((sections.customThemes as { schema: number }[])[0].schema, 2);
|
||||
assert.equal((sections.customThemes as { schema: number }[])[0].schema, 3);
|
||||
assert.deepEqual(sections.customThemesLegacy, [legacy]);
|
||||
assert.deepEqual(sections.appearance, { theme: 'custom:saved-light', mode: 'light' });
|
||||
// The browser preview store reads the sections from their old keys.
|
||||
|
||||
Reference in New Issue
Block a user