mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 01:46:18 -05:00
A component now asks for what a colour MEANS -- `danger` -- and the theme
decides how that looks. Five roles: neutral, info, success, warning, danger.
The names are the ones already in the tree. `--primary/--success/--warning/
--danger` were declared in tokens.css with ZERO consumers, and `MessageKind`
was already `info|success|warning|error`; this is one vocabulary instead of
three. `error` stays a valid kind because 26 call sites write it, and `danger`
is the same thing under the token's name for new code.
The token set is the easy half. Light and dark spend a hue per role. Night is
red and nothing else and amber is amber and nothing else, and there a role has
to be a step on a BRIGHTNESS ramp -- which is why this was worth doing:
night --orange is byte-identical to --text
--yellow is byte-identical to --amber
amber the same collisions, one hue over
A call site picking between hue names in those themes is picking between
synonyms. That is why all four toast kinds were the same pixel in night, and
why an error and an informational message were indistinguishable.
Both ramps are built rather than copied: every role clears 3:1 on the panel
(neutral is allowed lower -- for pending and disabled, dim IS the signal),
severity is strictly increasing in contrast, and danger reaches that theme's
own --text brightness so the loudest role is never quieter than prose. Amber
needed its own scale, not night's: its --text is 8.6:1 where night's is 5.0:1,
so night's ramp would have left every role dimmer than ordinary text.
Fixes in passing: night's info was 2.29:1, under the 3:1 floor. And Status
loses its three `html[data-theme="night"]` overrides entirely -- it was the one
component already encoding severity by brightness by hand, and the roles are
that generalised.
Roles are registered as Mantine colors too, so `color='danger'` works anywhere
`color='red'` does.
`isMonochromeTheme` is a new predicate in themes/names. It is the same set as
`explicitOnlyThemes` today and deliberately separate: one is about how a theme
is chosen, the other about what a theme has to work with.
Scope: tokens plus the library. The ~24 app-level `color='...'` call sites are
a follow-up -- they need a judgement per site, and two of them already disagree
(Downloads.js colours the same "Download error" label `orange` on one line and
`red` on another). The 22 `violet` uses are not semantic at all and stay hues.
Tests: the ramp claims are asserted per theme in a browser, and the ordering
and danger-vs-text claims run ONLY for the monochrome themes -- in light, blue
is darker than green on white, so a brightness ramp there would fail a design
that is perfectly fine. Every guard checked red against a planted regression,
including the original bug (warning and danger collapsed to one value in night)
and night's info back at its old 2.29:1.
The roles were folded into each theme's own block rather than kept in a
standalone one, so the existing "same tokens in every theme" and "only red hues
in night" guards cover them for free.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
343 lines
12 KiB
CSS
343 lines
12 KiB
CSS
/*
|
|
* WROLPi theme tokens.
|
|
*
|
|
* Every color in the interface resolves through these custom properties, so a
|
|
* theme is a table of values and components never branch on the current mode.
|
|
* See ui-design.md for the design rules and ui-migration-plan.md for the
|
|
* migration this is part of.
|
|
*
|
|
* Four built-in themes:
|
|
* light - default
|
|
* dark - default when the OS prefers dark
|
|
* night - night-vision preserving; red hues ONLY. Status is encoded by
|
|
* brightness, danger by dashed borders. Explicit choice only.
|
|
* amber - monochrome amber terminal palette. Explicit choice only.
|
|
*
|
|
* `data-theme` is stamped on <html> by an inline script in index.html before
|
|
* first paint, then maintained by ThemeProvider.
|
|
*/
|
|
|
|
/* Light is also the fallback when `data-theme` is missing or unrecognized. */
|
|
:root,
|
|
html[data-theme="light"] {
|
|
--bg: #f3f4f3;
|
|
--panel: #ffffff;
|
|
--head: #e4e6e5;
|
|
--border: #8f9698;
|
|
/* The rule between table rows: softer than --border, which reads as a grid. */
|
|
--table-line: #eceeed;
|
|
--text: #22282a;
|
|
--muted: #5f686a;
|
|
|
|
--red: #b23a3a;
|
|
--amber: #95661a;
|
|
--orange: #b05a24;
|
|
--yellow: #96821c;
|
|
--olive: #6f7a24;
|
|
--green: #3f7a2e;
|
|
--teal: #2a7d78;
|
|
--blue: #20629c;
|
|
--violet: #5c4fa8;
|
|
--purple: #7b3f9c;
|
|
--pink: #b03a72;
|
|
--brown: #7a5233;
|
|
--grey: #6a7072;
|
|
--black: #22282a;
|
|
--white: #ffffff;
|
|
|
|
/* Text drawn on top of a filled color button. */
|
|
--btn-text: #ffffff;
|
|
|
|
/* Switch thumbs and slider handles. */
|
|
--knob: #ffffff;
|
|
|
|
/* Roles: light has hues to spend, so each role is simply the hue that means it. */
|
|
--neutral: var(--grey);
|
|
--info: var(--blue);
|
|
--success: var(--green);
|
|
--warning: var(--amber);
|
|
--danger: var(--red);
|
|
}
|
|
|
|
/*
|
|
* Semantic roles.
|
|
*
|
|
* What a colour MEANS, separate from what hue it happens to be. A call site asks
|
|
* for `--danger`, not `--red`, and each theme decides how danger looks.
|
|
*
|
|
* This matters because two of the four themes have no hues to spend. Night is red
|
|
* and nothing else; amber is amber and nothing else. There, a role is a step on a
|
|
* BRIGHTNESS ramp -- and it has to be, because `--orange` in night is byte-identical
|
|
* to `--text` and `--yellow` is byte-identical to `--amber`, so a call site choosing
|
|
* between hue names there is choosing between synonyms. That is why all four toast
|
|
* kinds looked the same in night, and why a warning and an error were the same pixel.
|
|
*
|
|
* The ramps below are built so that in every theme:
|
|
* - the order neutral < info < success < warning < danger is strictly increasing in
|
|
* contrast against the panel, so severity reads as brightness even without hue;
|
|
* - every role except neutral clears 3:1 against the panel;
|
|
* - danger reaches that theme's own `--text` brightness, so the loudest role is
|
|
* never quieter than ordinary prose;
|
|
* - neutral sits deliberately below the rest -- for `pending` and disabled, being
|
|
* dim IS the signal.
|
|
*
|
|
* `ui-layout.cy.js` asserts all of that, per theme, in a real browser.
|
|
*
|
|
* `--primary` is deliberately NOT one of these. "The colour of a primary button" and
|
|
* "the colour that means informational" are different jobs, and a user who recolours
|
|
* their buttons should not thereby recolour their messages.
|
|
*/
|
|
:root {
|
|
--primary: var(--blue);
|
|
}
|
|
|
|
html[data-theme="dark"] {
|
|
--bg: #1c1f21;
|
|
--panel: #26292b;
|
|
--head: #141617;
|
|
--border: #4a5052;
|
|
/* The rule between table rows: softer than --border, which reads as a grid. */
|
|
--table-line: #343a3c;
|
|
--text: #e6e8e6;
|
|
--muted: #93999b;
|
|
|
|
--red: #e06c6c;
|
|
--amber: #d6a656;
|
|
--orange: #dd8a55;
|
|
--yellow: #d6c156;
|
|
--olive: #b5bd63;
|
|
--green: #7fb069;
|
|
--teal: #63bdb6;
|
|
--blue: #5c9dd6;
|
|
--violet: #9a8fe0;
|
|
--purple: #b884d6;
|
|
--pink: #dd7fae;
|
|
--brown: #b08a68;
|
|
--grey: #93999b;
|
|
--black: #0d0f10;
|
|
--white: #e6e8e6;
|
|
|
|
--btn-text: #1c1f21;
|
|
--knob: var(--text);
|
|
|
|
/* Roles: as light -- a hue each. See the note above the :root block. */
|
|
--neutral: var(--grey);
|
|
--info: var(--blue);
|
|
--success: var(--green);
|
|
--warning: var(--amber);
|
|
--danger: var(--red);
|
|
}
|
|
|
|
/*
|
|
* Night: red hues only. A single non-red pixel defeats the purpose of the
|
|
* mode, so the whole palette collapses onto one red ramp ordered by
|
|
* brightness — dim for structural roles, brightest reserved for danger.
|
|
*/
|
|
html[data-theme="night"] {
|
|
--bg: #0a0000;
|
|
--panel: #160404;
|
|
--head: #000000;
|
|
--border: #5c1010;
|
|
/* The rule between table rows: softer than --border, which reads as a grid. */
|
|
--table-line: #3a0d0d;
|
|
--text: #e04a4a;
|
|
--muted: #7a2525;
|
|
|
|
--red: #ff3b3b;
|
|
--amber: #d94040;
|
|
--orange: #e04a4a;
|
|
--yellow: #d94040;
|
|
--olive: #5c1a1a;
|
|
--green: #b03030;
|
|
--teal: #963030;
|
|
--blue: #8a2828;
|
|
--violet: #7a2929;
|
|
--purple: #6e2020;
|
|
--pink: #c04848;
|
|
--brown: #451212;
|
|
--grey: #7a2525;
|
|
--black: #2a0808;
|
|
--white: #ff8a8a;
|
|
|
|
--btn-text: #0a0000;
|
|
--knob: var(--text);
|
|
|
|
/* Roles: one hue, five brightnesses; saturation climbs with severity too. */
|
|
--neutral: #992c2c;
|
|
--info: #c02929;
|
|
--success: #e02323;
|
|
--warning: #ee3434;
|
|
--danger: #ff3e3e;
|
|
}
|
|
|
|
/* Amber: a monochrome amber terminal palette, same flat style as the rest. */
|
|
html[data-theme="amber"] {
|
|
--bg: #0d0600;
|
|
--panel: #1a0f00;
|
|
--head: #000000;
|
|
--border: #5c3a08;
|
|
/* The rule between table rows: softer than --border, which reads as a grid. */
|
|
--table-line: #3d2708;
|
|
--text: #ff9500;
|
|
--muted: #8a5810;
|
|
|
|
--red: #ffc040;
|
|
--amber: #e08a20;
|
|
--orange: #f09428;
|
|
--yellow: #e08a20;
|
|
--olive: #6e4610;
|
|
--green: #c97a10;
|
|
--teal: #8a581c;
|
|
--blue: #a86618;
|
|
--violet: #7a4c14;
|
|
--purple: #6e4410;
|
|
--pink: #d08430;
|
|
--brown: #452708;
|
|
--grey: #8a5810;
|
|
--black: #241504;
|
|
--white: #ffc875;
|
|
|
|
--btn-text: #0d0600;
|
|
--knob: var(--text);
|
|
|
|
/* Amber assigns the mono face to the body role; that is its character. */
|
|
--font-body: var(--font-system-mono);
|
|
|
|
/* Roles: scaled to amber's own headroom (--text is 8.6:1, night's is 5.0:1). */
|
|
--neutral: #815825;
|
|
--info: #b06e1f;
|
|
--success: #d37c11;
|
|
--warning: #f18806;
|
|
--danger: #ff9e29;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
/* Shell */
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/*
|
|
* Base element styling.
|
|
*
|
|
* semantic.min.css used to supply all of this, and removing it took the lot with it --
|
|
* links lost their colour and gained the browser's underline and visited purple, and
|
|
* every padded element silently changed size when `box-sizing: border-box` went away.
|
|
* None of it belonged to Semantic; it belongs here, expressed in tokens.
|
|
*/
|
|
|
|
html {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: inherit;
|
|
}
|
|
|
|
body {
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
font-family: var(--font-body);
|
|
}
|
|
|
|
/*
|
|
* Links take the primary token rather than the browser's blue, and carry no underline
|
|
* until hovered -- a great many of them wrap cards, posters, statistics and icons, where
|
|
* a permanent underline is noise. `--blue` remaps per theme, so night gets a dim red
|
|
* link and amber an amber one without another rule.
|
|
*/
|
|
a {
|
|
color: var(--blue);
|
|
text-decoration: none;
|
|
}
|
|
|
|
a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
/* A link wrapping a card, poster or icon carries no text of its own to underline. */
|
|
a:has(img, svg, .wrolpi-card-icon):hover {
|
|
text-decoration: none;
|
|
}
|
|
|
|
a:focus-visible {
|
|
outline: 2px solid var(--blue);
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
html[data-theme="night"] a:focus-visible,
|
|
html[data-theme="amber"] a:focus-visible {
|
|
outline-color: var(--text);
|
|
}
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
/* Media filtering */
|
|
/* ------------------------------------------------------------------------- */
|
|
/*
|
|
* Videos, images, PDFs, embedded pages, and the map canvas cannot consume
|
|
* tokens, so a theme can pass them through an SVG color matrix instead. Night
|
|
* maps luminance onto the red channel so nothing a user opens can break their
|
|
* dark adaptation; amber tints media to match the interface.
|
|
*
|
|
* These rules key on `data-media-filter`, not `data-theme`, because filtering is
|
|
* a per-theme setting the user controls rather than a property of the theme's
|
|
* palette: night is filtered unless turned off, amber is unfiltered unless
|
|
* turned on. An empty or absent attribute filters nothing, so light and dark —
|
|
* which offer no filter — match no rule at all. ThemeProvider stamps the
|
|
* attribute, and index.html stamps it before first paint (an unfiltered flash of
|
|
* thumbnails would cost the user their dark adaptation before React even loads).
|
|
*
|
|
* The selectors target element types rather than an opt-in class on purpose:
|
|
* filtering has to fail safe. A library of thousands of files reaches the
|
|
* screen through many components, and one that forgot to opt in would undo half
|
|
* an hour of dark adaptation. `.media` stays available for a wrapper that needs
|
|
* filtering as a unit (a player with custom controls, say), and
|
|
* `.night-unfiltered` opts a single element out — for media whose real colors
|
|
* are the point, like the side-by-side comparison on /theme-sample.
|
|
*
|
|
* Only leaf media is filtered, never an app-level ancestor: a CSS filter
|
|
* creates a containing block, which would break `position: fixed` descendants
|
|
* like modals and the nav bar. These elements have no such descendants — an
|
|
* iframe's contents are a separate document with their own viewport.
|
|
*
|
|
* Filter definitions live in <MediaFilterDefs/> (mounted once by App).
|
|
*/
|
|
html[data-media-filter="night-red"] :is(img, video, canvas, iframe, embed, object, .media):not(.night-unfiltered) {
|
|
filter: url(#wrolpi-night-red);
|
|
}
|
|
|
|
html[data-media-filter="amber-mono"] :is(img, video, canvas, iframe, embed, object, .media):not(.night-unfiltered) {
|
|
filter: url(#wrolpi-amber-mono);
|
|
}
|
|
|
|
/*
|
|
* A `.media` wrapper filters its whole subtree as one unit, so the leaf media inside
|
|
* it must not be filtered a second time. Two passes of a luminance-to-red matrix is
|
|
* not the same as one: the second pass takes the luminance of an already-red pixel
|
|
* (0.2126 of it) and the image comes out markedly darker than everything around it.
|
|
*
|
|
* The audio player's poster is the case that found this — the poster sits under
|
|
* custom control glyphs, so the wrapper is filtered to keep the two tinted together.
|
|
*
|
|
* The trailing `:not(.night-unfiltered)` is here for specificity, not for its meaning.
|
|
* The rule above scores (0,3,1) — an attribute, a `.media` inside `:is()`, and a `:not()`
|
|
* — so this reset had to reach three class-level components to win it; without the extra
|
|
* one it scored (0,2,2) and silently lost every time, which is exactly what it did until
|
|
* a browser test measured the leaf and found it filtered twice. jsdom cannot catch this:
|
|
* it never resolves `filter` at all.
|
|
*/
|
|
html[data-media-filter] .media :is(img, video, canvas, iframe, embed, object):not(.night-unfiltered) {
|
|
filter: none;
|
|
}
|
|
|
|
/*
|
|
* A filter on an ancestor stops applying once the browser promotes a video to
|
|
* native fullscreen, so the filter is restated on the fullscreened element.
|
|
*/
|
|
html[data-media-filter="night-red"] :fullscreen:not(.night-unfiltered) {
|
|
filter: url(#wrolpi-night-red);
|
|
}
|
|
|
|
html[data-media-filter="amber-mono"] :fullscreen:not(.night-unfiltered) {
|
|
filter: url(#wrolpi-amber-mono);
|
|
}
|