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

The console's colours are each written once, as light-dark()

Merged
Merged chadtmiller.com asked to merge into feature/branding from chadtmiller.com/group-host:tokens/light-dark

Every colour token is now written once, as light-dark(light, dark), and the page's color-scheme picks between them. Before, the full set was repeated under prefers-color-scheme: dark and again under [data-theme='dark']. Nothing anyone sees changes: every palette, light and dark, draws the same pixels as before.

Claude Opus 5.5 · medium effort

What changes

tokens.css. :root sets color-scheme: light dark, and every colour token is light-dark(light, dark), the shadows and scrim included (per shadow layer). A reader's choice is [data-theme='light'] { color-scheme: light } or [data-theme='dark'] { color-scheme: dark }. The two dark blocks and the media query are gone.

The avatar's initial. --initial-wash and --initial-ink are a lightness and chroma, not colours, so they can't go in light-dark(). Each now has a -dark twin, and span.av in app.css picks between them with light-dark(oklch(var(--initial-wash) var(--hue)), oklch(var(--initial-wash-dark) var(--hue))).

brandStyle keeps its three rules. It writes a <style> as the page is drawn, after the build. The build lets older browsers read light-dark() (below), but a runtime style gets no such help, so light-dark() there would need Safari 17.5. A comment in brand.ts says so.

Older browsers. Vite 8's CSS minifier, Lightning CSS, targets Vite's default baseline-widely-available (Safari 16.4). For that target it rewrites light-dark() into its --lightningcss-light/--lightningcss-dark switch, inside custom properties too, and writes the matching prefers-color-scheme and [data-theme] rules. The built stylesheet therefore works without native light-dark(); vite dev serves it natively.

The .alone backdrop rules in app.css still use the media query, because they switch background images, which light-dark() doesn't take in today's browsers.

Changeset: none

Why

The same 20-odd tokens were written three times: in :root, under the media query, and under [data-theme='dark']. Changing a dark colour meant changing two places, and a missed one showed only to readers who had chosen dark. With light-dark(), each colour is one line with both values side by side.

How it was checked

  • Pixels. I redrew /g/lanterns.groups.test as alice with --seed full, light and dark, in all five palettes, and compared against the pictures from before. Page background and card colours are identical. The top of each page (header and group card) differs by at most 1 in one channel, along the header's edge. The other difference is the group's picture, which loaded in one world and not the other. Where a group's initial was drawn, its wash and ink are identical before and after: light (219,226,193)/(74,83,13), dark (54,59,28)/(205,216,163).
  • Explicit choice against the system, in Chromium, both for vite dev (native light-dark()) and the built console (node build, rewritten for older browsers):
SystemChosedata-themePage backgroundButton
lightsystem—oklch(0.96 …)rgb(184 72 43)
darksystem—oklch(0.187 …)rgb(240 138 99)
lightdarkdarkoklch(0.187 …)rgb(240 138 99)
darklightlightoklch(0.96 …)rgb(184 72 43)
  • npm run check: 0 errors, 0 warnings. just fmt and node harness/strings.mjs pass.

Shortcomings

  • brandStyle's dark colour without PRIMARY_COLOR_DARK uses oklch(from …), relative colour syntax, which needs Safari 18; that predates this pull. On Safari 16.4–17.x, a host with PRIMARY_COLOR and no PRIMARY_COLOR_DARK gets a --primary browsers can't read in dark, and its buttons lose their fill. Working out the lifted colour in brand.ts would fix that; it's left for its own pull.
  • Not drawn on a real Safari 16 or 17.
Approved

This folds the repeated dark token blocks and the media query in tokens.css into one light-dark() per colour. color-scheme: light dark on :root picks between them, and [data-theme] forces one side. I compared the light and dark values against the removed blocks and found no difference. The shadows, the scrim and the --on-danger and --danger-soft tokens all match.

The avatar fallback is handled correctly. The --initial-* tokens are lightness and chroma pairs, so they can't go in light-dark(). The -dark twins and the span.av rule are the only users, and I found no other reference to these tokens. brandStyle still writes plain rules, so its overrides keep working, and the comment in brand.ts gives the reason.

I couldn't run the build, so I didn't check the Lightning CSS rewrite for older Safari. The author says they checked it in Chromium and not on a real Safari 16 or 17. The Changeset: none line is there for the check, which reads the body.

All checks have passed

5 passed, 1 skipped

Merged as 5658b6d