feat(ui,manager): looks: light / dark / device, palettes and styles, chosen in the manager's profile menu (platform-v2 step 6.15)
- @xenia/ui theme.js: a look = mode (light | dark | system) + palette (data-palette) + style (data-style); applyLook / getStoredLook (per device), 'system' resolved with matchMedia and followed live, so a palette is just a light and a dark token block; applyTheme kept for older callers (keeps palette and style) - tokens.css: 'Palettes' (first: Nord, light + dark, every colour and the nav rail) and 'Styles' (first: sharp: small corners, 1.5px borders, flat cards); --x-border-width used by every component and Tailwind's 'border' - contrast test: every palette in both modes (+ the nav rail); it caught the default rail's active item at 3.7:1 -> 5.5:1 - manager: the saved look applied at start (was light only); profile menu -> Look: Light / Dark / Device, Colours (Xenia, Nord), Shapes (Rounded, Sharp), applied at once and kept on this device - e2e: manager_look.mjs (every page in light and dark, no large near-white area in dark, contact sheets; 'nord-sharp' adds that look; in run-all), manager.mjs 'look:' (dark at once, kept after a reload, Device follows the device) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { test } from 'node:test'
|
||||
import { PALETTES } from '../src/theme.js'
|
||||
|
||||
const css = readFileSync(new URL('../src/tokens.css', import.meta.url), 'utf8')
|
||||
|
||||
@@ -59,6 +60,28 @@ for (const venue of venues) {
|
||||
}
|
||||
}
|
||||
|
||||
// Palettes (6.15): every palette in theme.js, light and dark, the same pairs as the default plus
|
||||
// the nav rail. A palette block sets every colour itself, so it is checked on its own.
|
||||
const navPairs = [['nav-ink', 'nav-bg', TEXT], ['nav-ink-2', 'nav-bg', TEXT], ['nav-ink-3', 'nav-bg', TEXT], ['nav-ink', 'nav-active', TEXT], ['nav-ink-2', 'nav-raised', TEXT]]
|
||||
const check = (t, list) => list.filter(([fg, bg]) => t[fg] && t[bg]).map(([fg, bg, min]) => [fg, bg, min, ratio(t[fg], t[bg])])
|
||||
.filter(([, , min, r]) => r < min).map(([fg, bg, min, r]) => `${fg} on ${bg}: ${r.toFixed(2)} < ${min}`)
|
||||
for (const palette of PALETTES.filter(p => p !== 'default')) {
|
||||
for (const [mode, sel] of [['light', `[data-palette="${palette}"]`], ['dark', `[data-palette="${palette}"][data-theme="dark"]`]]) {
|
||||
test(`palette ${palette} / ${mode}`, () => {
|
||||
const t = rule(sel)
|
||||
const missing = [...pairs, ...navPairs].flatMap(([fg, bg]) => [fg, bg]).filter(k => !t[k])
|
||||
assert.deepEqual([...new Set(missing)], [], 'a palette sets every colour token')
|
||||
assert.deepEqual(check(t, [...pairs, ...navPairs]), [])
|
||||
})
|
||||
}
|
||||
}
|
||||
test('the default nav rail is readable', () => {
|
||||
const nav = rule(':root') // first :root holds the colours; the nav set is its own :root block
|
||||
const navRoot = Object.fromEntries([...css.slice(css.indexOf('/* ── Nav')).matchAll(/--x-(nav-[\w-]+)-rgb:\s*([\d\s]+);/g)].slice(0, 8).map(([, k, v]) => [k, v.trim().split(/\s+/).map(Number)]))
|
||||
assert.ok(nav.canvas && navRoot['nav-bg'])
|
||||
assert.deepEqual(check(navRoot, navPairs), [])
|
||||
})
|
||||
|
||||
test('system theme mirrors dark', () => {
|
||||
const sys = css.slice(css.indexOf('@media (prefers-color-scheme: dark)'))
|
||||
assert.match(sys, /\[data-theme="system"\]/)
|
||||
|
||||
Reference in New Issue
Block a user