Dark mode: red text and the market's heat tags read on the dark panels (#80)

Red warning text used var(--bad), 3.8 to 4.8:1 on the dark cards and tints.
Every text use now takes var(--tx-red,var(--bad)): light mode keeps --bad,
dark gets #FF8E9B (5.65:1 or better on paper, soft and every tint). --bad
stays the fill under white letters (buttons, counters, bars).

Lambda Bazaar's Hot and Cool tags kept their light pastel chips at night.
They now use the dark tints (--tint-o, --tint-b) with --tx-amber and a new
--tx-blue, keeping the same colours by day.

The dark-mode test checks the tags, the text tokens on every dark card, that
no tag keeps a bare pastel fill, and that no red text in --bad is left in the
styles or the game's markup.
This commit is contained in:
jvanvik 2026-11-09 22:48:09 +01:00
parent 8068a45abd
commit 27ffa33d7c
27 changed files with 93 additions and 49 deletions

View file

@ -349,7 +349,8 @@ test('the dark look defines every token it is used with, and its text reads (AA)
for (const m of css.matchAll(/var\(--([a-z0-9-]+)\)/g)) if (!/^(tabbar|app-h|c|rc|d|x|t|r|dl|pzdock)$/.test(m[1])) assert.ok(val(light, m[1]), `--${m[1]} is defined`);
const bgs = ['paper', 'soft', 'tint-y', 'tint-g', 'tint-r', 'tint-p', 'tint-b', 'tint-v', 'tint-o', 'tint-n'].map((k) => [k, val(dark, k)]);
for (const t of ['text', 'ink2', 'eye']) for (const [k, b] of bgs) assert.ok(cr(val(dark, t), b) >= 4.5, `--${t} on --${k}: ${cr(val(dark, t), b).toFixed(2)}`);
for (const t of ['tx-red', 'tx-amber']) assert.ok(cr(val(dark, t), val(dark, 'paper')) >= 4.5, `--${t} on the dark paper`);
// The text colours of warnings and tags read on every card and tint they sit on, not only on the paper.
for (const t of ['tx-red', 'tx-amber', 'tx-blue']) for (const [k, b] of bgs) assert.ok(cr(val(dark, t), b) >= 4.5, `--${t} on --${k}: ${cr(val(dark, t), b).toFixed(2)}`);
// The outline stays dark in both looks, so text on bright fills (yellow buttons, warning tags) keeps reading.
assert.ok(cr(val(dark, 'ink'), '#FFD23F') >= 7, 'dark ink on the yellow buttons');
// Badge labels (10px, so 4.5:1) on their night cards: each variant's gradient, and the dimmed card of one not earned now.
@ -366,6 +367,47 @@ test('the dark look defines every token it is used with, and its text reads (AA)
assert.ok(cr(val(dark, 'text'), val(dark, 'paper')) >= 3, 'at night the key\'s outline shows on the card');
});
// Two things that kept their day colours at night: the capacity market's Hot and Cool tags (bright pastel chips on the
// dark dashboard), and red warning text in var(--bad), 3.8 to 4.8:1 on the dark cards. --bad stays the fill under white
// letters (buttons, counters, bars); text takes var(--tx-red,var(--bad)), which by day is --bad as before.
test('at night the market\'s Hot and Cool tags take the dark tints, and red text reads (AA) on every card', () => {
const html = assemble().html, css = html.slice(html.indexOf('<style>'), html.indexOf('</style>')).replace(/\/\*[\s\S]*?\*\//g, '');
const block = (sel) => { const i = css.indexOf(sel + '{'); return css.slice(i, css.indexOf('}', i)); };
const dark = block(':root[data-theme="dark"]'), light = block(':root');
const val = (b, k) => { const m = new RegExp(`--${k}:\\s*([^;\\n]+);`).exec(b); return m && m[1].trim(); };
const rules = css.split('}').map((r) => { const i = r.indexOf('{'); return i < 0 ? null : { sel: r.slice(0, i).split(',').map((x) => x.trim()), body: r.slice(i + 1) }; }).filter(Boolean);
const decl = (sel, prop) => { let v = null; for (const r of rules) if (r.sel.includes(sel)) { const m = new RegExp(`(?:^|;)\\s*${prop}\\s*:\\s*([^;]+)`).exec(r.body); if (m) v = m[1].trim(); } return v; };
// var(--token,fallback) as each look paints it: the dark value, or the fallback (the light look never sets the tint).
const paint = (v, look) => { const m = /^var\(--([a-z-]+),\s*(#[0-9A-Fa-f]{6})\)$/.exec(v); assert.ok(m, `a themed colour: ${v}`); return look === 'dark' ? val(dark, m[1]) : (assert.equal(val(light, m[1]), null, `--${m[1]} is dark-only`), m[2]); };
for (const [tag, bg, fg, was] of [['cmhot', 'tint-o', 'tx-amber', ['#FFE1D6', '#B43A12']], ['cmcool', 'tint-b', 'tx-blue', ['#DDF1FB', '#1E6A8C']]]) {
const b = decl(`.tag.${tag}`, 'background'), c = decl(`.tag.${tag}`, 'color');
assert.ok(b.startsWith(`var(--${bg},`) && c.startsWith(`var(--${fg},`), `.tag.${tag}: ${b} / ${c}`);
assert.deepEqual([paint(b, 'light'), paint(c, 'light')], was, `.tag.${tag} looks as it did by day`);
const r = cr(paint(c, 'dark'), paint(b, 'dark'));
assert.ok(r >= 4.5, `.tag.${tag} at night: ${r.toFixed(2)}`);
}
// No tag keeps a bare pastel fill: it would be a bright patch on the dark panels.
const pale = (h) => lum(h) > 0.5;
for (const r of rules) if (!r.sel.some((s) => s.startsWith(':root')) && r.sel.some((s) => /\.tag\b/.test(s))) {
const m = /(?:^|;)\s*background\s*:\s*(#[0-9A-Fa-f]{6})\b/.exec(r.body);
assert.ok(!(m && pale(m[1])), `${r.sel.join(',')} has a bare pastel background ${m && m[1]}`);
}
// Red as text takes the dark-aware colour everywhere, in the styles and in the game's own markup and HUD (the test
// above checks --tx-red on every card and tint). `color:var(--bad)`, `color:${x?'var(--bad)':…}`, `.style.color=…'var(--bad)'`.
const RED = /(?<![-\w])color\s*(?::|=)\s*(?:\$\{[^}]*?|[^;'"`{}(]*?)'?(?<!--tx-red,)var\(--bad\)/g;
const cssLeft = [...css.matchAll(RED)].map((m) => m[0]);
assert.deepEqual(cssLeft, [], 'red text in the styles in --bad');
const dir = path.join(__dirname, '..', 'src', 'game'), left = [];
for (const f of fs.readdirSync(dir, { recursive: true }).filter((f) => f.endsWith('.js'))) {
const s = fs.readFileSync(path.join(dir, f), 'utf8');
for (const m of s.matchAll(RED)) left.push(`${f}: ${m[0].slice(-60)}`);
}
assert.deepEqual(left, [], 'red text in the game\'s markup in --bad');
// The fills keep --bad (white letters on it): a button, a counter, a bar.
assert.equal(decl('.b.red', 'background'), 'var(--bad)');
assert.equal(decl('.b.red', 'color'), '#fff');
});
test('the dashboard\'s Demand key matches its dashed line, by night too', () => {
const { dom, ev, errors } = load({ storage: { 'sot-theme': 'dark' } });
ev(started + "for(let i=0;i<3;i++)dayTick();ACT.dash({});");