Expand description
Shared theme loading + intent resolution for TOML-based theme files.
Used by GoingsOn, Balanced Breakfast (Tauri apps), audiofiles (egui), and the MNW web server. Themes are authored by intent (“human design”): colors are declared by role (surface / content / action / status / line / category), not by hue. This crate is the single place that resolves an authored theme into a full set of intent tokens — including the derived interactive states (hover/active/selection/row-stripe/contrast) that each app used to recompute itself — and emits them as CSS variables or RGB tuples.
Theme file shape:
[meta]
name = "Nord"
variant = "dark" # or "light"
[surface] # container backgrounds by role/elevation
page = "#2e3440"; raised = "#3b4252"; sunken = "#434c5e"; overlay = "#3b4252"
[content] # text/ink by emphasis
primary = "#d8dee9"; secondary = "#e5e9f0"; muted = "#616e88"
[action] # interactive / brand color
primary = "#81a1c1"
[status] # state semantics
danger = "#bf616a"; success = "#a3be8c"; warning = "#ebcb8b"; info = "#88c0d0"
[line]
border = "#4c566a"
[category] # distinct decorative colors for tags/badges/charts
one = "#bf616a"; two = "#a3be8c"; three = "#81a1c1"
four = "#ebcb8b"; five = "#b48ead"; six = "#88c0d0"Structs§
- Oklab
- A color in OKLab (perceptually uniform):
llightness in [0,1],a/bopponent axes. - Rgb
- An sRGB color. Hex round-trips losslessly.
- Semantic
Tokens - A fully resolved intent layer: every token key → concrete
#rrggbb. Includes both authored base intents and the computed derived intents. - Theme
Colors - A loaded theme: metadata plus the authored colors, flattened to dotted keys
(e.g.
"surface.page","status.danger","category.one"). - Theme
Meta - Theme metadata parsed from the
[meta]section. - Theme
Preview - A four-color preview for theme thumbnails: the representative swatch from each of the principal roles.
Constants§
- BASE_
INTENTS - Authored base intents: (TOML dotted source key, canonical token key).
These are read straight from the theme; the token key is the CSS-var stem
(
--{token}) and thergb()lookup key. - COLOR_
SECTIONS - The color sections an authored theme may declare.
Functions§
- bundled_
themes_ dir - The theme directory this crate ships, for use as a build-from-source fallback.
- darken
- Shift OKLab lightness down by
delta(perceptually uniform). - delete_
theme - Delete a custom theme by ID.
- export_
theme - Export a theme to a user-chosen path.
- extract_
colors - Extract the intent color sections into a flat
HashMapwith dotted keys like"surface.page","status.danger","category.one". - find_
theme_ path - Find a theme file by ID in the given directories.
- import_
theme - Import a theme TOML file into the custom themes directory.
- intent_
css_ declarations - Emit the resolved intent layer as CSS declarations (no selector), one
--token: #hex;line each, in deterministic (BTreeMap) order. - intent_
css_ vars - Emit the resolved intent layer as a
:root { … }block — the single TOML → CSS mapping every web surface injects. - lighten
- Shift OKLab lightness by
delta(perceptually uniform). Positive lightens. - list_
themes_ from_ dirs - Scan directories for
.tomltheme files and return metadata for each. - load_
semantic - Load a theme and resolve it to the full intent token set in one step.
- load_
theme - Load a complete theme (metadata + colors) by ID from the given directories.
- load_
theme_ preview - Load just the preview swatches for a theme — for UI thumbnails.
- mix
- Interpolate between
aandbbytin [0,1] in OKLab (perceptual blend). - parse_
meta - Parse the
[meta]section intoThemeMeta. - parse_
theme_ str - Parse a complete theme (metadata + colors) from raw TOML content, with no filesystem access. For callers that embed themes at compile time.
- readable_
on - Pick black or white for legible text on
bg, by the higher WCAG contrast ratio (so the choice meets AA wherever the background allows it). - resolve
- Resolve an authored theme into the full intent token set.
- validate_
theme_ id - Validate a theme ID contains only safe characters (alphanumeric, hyphens, underscores).
- wcag_
contrast - WCAG 2.x contrast ratio between two colors, in [1, 21].