~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A host's operator sets the colour that acts, and a cooler set of colours

Merged
Merged chadtmiller.com asked to merge into feature/branding from chadtmiller.com/group-host:branding/colours
1 reviewer 1 asked for changes

A host's operator can now set the colour of the console's buttons and links (PRIMARY_COLOR, PRIMARY_COLOR_DARK), and switch the rest of its colours from warm paper to a cool slate (THEME=slate). Stacked on the approval-page pull; the diff includes it until that one lands.

Claude Opus 5.5 · high effort

What changes

Host. PRIMARY_COLOR and PRIMARY_COLOR_DARK take only #rgb or #rrggbb and are kept lower case. THEME takes paper or slate; paper, the console's own set, counts as unset. The host refuses to start on any other value. getBrand answers colors (primary, primaryDark) and theme.

Console. brandStyle in #lib/brand.ts writes a <style> into the head that sets --primary and the tokens drawn from it:

  • --primary-hover, --primary-soft and --link-line are color-mixes of it.
  • --on-primary is white or the theme's ink, whichever reads better by WCAG contrast.
  • Without a dark colour, the dark scheme uses the light one lifted to a lightness of at least 0.72 (oklch(from …)), with dark ink on it.

Its selectors carry one more element than the tokens', so they win in either order and in a forced light or dark scheme. Only a colour matching #rgb/#rrggbb is written in, checked again here, though the host already checks.

THEME=slate puts <meta name="theme" content="slate"> in the head. tokens.css gives slate's surfaces, ink, lines and shadows under :root:has(meta[name='theme'][content='slate']), light and dark, so every token stays in tokens.css. Slate sets no --primary: what acts is the operator's colour, or terracotta.

Why

A host run by an app wants its pages in that app's colours. A primary colour alone on warm paper looked like someone else's site for Grain, so there is one built-in cool set beside it. The neutral colours stay presets, not free values, so their contrast is checked once rather than per host.

How it was checked

  • tests/config.rs: colours read and lower-cased, #rgb kept, four malformed colours and an unknown theme refused, paper read as unset.
  • tests/brand.rs: getBrand answers colors and theme.
  • just look with Grain's #3b4ddb / #85a1ff and slate: a group's page in light, the approval page on a phone in dark. With only #0f766e: home in light, and in dark with the derived lighter teal and dark ink on it.
  • svelte-check, layers, strings, clippy, just lex, docs links.

Shortcomings

  • oklch(from …) needs Chrome 119, Safari 16.4 or Firefox 128. Older browsers drop the derived dark colour and keep the console's own.
  • :has() needs Chrome 105, Safari 15.4 or Firefox 121. Older browsers draw slate's pages in paper.
Asked for changes

This adds PRIMARY_COLOR, PRIMARY_COLOR_DARK and THEME to the host config. They reach the console through getBrand, where brandStyle writes the <style> and slate's tokens are chosen by a <meta>. I read the colour and theme parts of the diff: config, brand.rs, brand.ts, +layout.svelte, tokens.css and the lib.rs and app.css hunks. I did not read the rest of the stacked approval-page pull, which has its own review. I didn't run anything, and I didn't check the tests, docs or lexicon for this part.

The host-side validation looks right. Specificity works out: html:root and html[data-theme=…] beat the token rules. Only a regex-checked hex reaches the <style>.

One thing needs fixing. The "Shortcomings" claim that older browsers "keep the console's own" dark colour is wrong for the derived dark colour (see the comment on brand.ts).

web/src/lib/brand.tsline 78
const d =
given && HEX.test(given)
? acting(given, onColour(given, darkInk), true)
: acting(`oklch(from ${light} max(l, 0.72) c h)`, darkInk, true);
review.knotless.dev

This will not fall back as the body says. --primary: oklch(from …) is a valid custom-property declaration in every browser. It only goes invalid when var(--primary) is used, and then it computes to unset, not to the console's own terracotta. So on a browser without relative colour syntax, the dark scheme gets no primary background or link colour. --on-primary and the color-mixes off it also break. Wrap the derived dark block in @supports (color: oklch(from red l c h)), so older browsers skip it and keep the token defaults. Alternatively, derive the lighter colour in TS.

Merged as bc8f310