Files
craft-libs/crates/theme
dotCooCoo 5d4e8da624 theme: ArtCraft app palettes keep faint text at 4.5:1; dark raised keeps its lift
The WordCraft and PdfCraft palettes in artcraft.json pinned text.faint
at 3.4 to 4.4:1 on their hover, pressed and background fills. Their
light faint and muted pins and WordCraft's dark pins move along their
own hue so faint text reads at 4.5:1 there and muted text stays 1.25
times above it. The faint text test now resolves every built-in alone
and with each app palette it carries, and the fills it leaves out must
match a named list.

ArtCraft dark pins surface.raised to #5e5e5e, so raised fills stand
above the #535353 panel again (the contrast pass had darkened them to
#545454). Normal text reads at 5.59:1 on that fill, which leaves no
room for a muted grey between faint and normal, so faint text on it
stays listed as a warning, like the control, hover and pressed fills.
High contrast keeps its #595959 raised fill, and the WordCraft and
PdfCraft palettes keep their own raised fills (#353535 and #2e2e33) in
both contrasts.
2026-11-28 09:20:18 -08:00
..

craft-theme

The Craft design system's theme model. A theme is a few seeds and optional pins; resolve turns it, with an appearance (mode, contrast, size, text size), into tokens that apps map onto their own styles.

Pure data and functions: no egui, no I/O, no threads, and it builds for wasm. Theme files on disk, the suite folder and change watching belong to craft-theme-store; craft_ui::style converts tokens for egui. docs/suite-themes.md is the reference for theme authors and app developers.

use craft_theme::{Appearance, Contrast, Mode, Size, TextSize, builtins, resolve};

let theme = builtins().iter().find(|t| t.id.as_str() == "craft.graphite").unwrap();
let appearance = Appearance { mode: Mode::Dark, contrast: Contrast::Standard, size: Size::Compact, text_size: TextSize::Small, reduced_motion: false };
let resolved = resolve(theme, appearance, None);
// resolved.tokens: colours, shape, size, space and type tokens; resolved.warnings: contrast misses.

Tokens

Two layers, the second derived from the first:

  1. Primitives: sRGB and OKLCH colour, WCAG contrast, 12-step colour ramps, fixed scales (space, radius, stroke, opacity, duration, easing, elevation).
  2. Semantic tokens: surface, text, line, state, accent, status, overlay, data and caption colours; shape, size, space, motion and type tokens. Seeds (neutral, accent, four status colours) generate ramps, and ramps fill the tokens.

A theme sets seeds and may pin any colour token ("surface.panel": "#F0F0F0") per mode. Pins win over derivation. Apps can pin per app (apps.<id>).

Contrast

Text, state indicators, canvas overlays and data graphics have rules: text on surfaces, state fills and solid fills (4.5, high contrast 7); focus rings, accent marks and a list's drop marker on its halo (3, high contrast 4.5); overlay strokes on their halo and the marquee on its dashes (3, high contrast 4.5); and the channel colours a curve editor draws (data.red, data.green, data.blue, data.cyan, data.magenta, data.yellow) on surface.sunken (3, high contrast 4.5). Hover, pressed, dividers, edges, knob faces and row selection fills have none, and neither have guide and smart-guide colours, which are the user's choice, nor overlay.line, the bare accent line of boxes, paths and meshes on the canvas. In standard contrast an unpinned colour is moved to the minimum and a failing pin is kept and reported, with every component pair it makes fail; in high contrast every colour is fixed, pins included.

Files, built-ins, selection

Module What it is
format the craft-design-theme v1 file: parse, write, to_file; every error with its path
builtins() twelve craft.* themes, embedded from themes/*.json
selection Selection, SuiteChoice, AppChoice (an app's own theme, mode and size over the suite's), AppDefaults (with the app's AppSizes), resolve_selection: what the user picked, filled in and resolved against what the OS reports
ThemeId, AppId, APP_DEFAULT, SUITE_DEFAULT ids [a-z0-9][a-z0-9._-]{1,63}; craft. is reserved for built-ins

The craft-theme check <file>... [--json] binary parses and validates theme files and prints contrast warnings for every appearance. It exits 1 if any file has an error.

The selection types and the enums they hold implement Serialize/Deserialize: colours as "#rrggbb[aa]", ids as strings, enums in snake_case.