mirror of
https://github.com/db9979/tidefront.git
synced 2026-12-06 12:54:09 +01:00
- Zentrale Tokens (theme.css, hell/dunkel) und Abbildung aller Farbklassen per @theme inline; Zeichnungen, Diagramme und Kurstafel auf Tokens statt fester Hexwerte - Modus: Systemeinstellung als Standard, Einstellungen → Spiel → Darstellung (Wie System/Hell/Dunkel), ohne Flackern (Inline-Skript in index.html), theme-color passend - Dunkle Kopfleiste mit Füllstandsbalken (orange ab 85 %), Rang-Chip, Desktop mit Kopfleiste über volle Breite - Lage (Rangzeile, Alarmkarte, Fraunces-Titel, Umrissknopf), Gebäudeblatt (Jetzt/Stufe n, Kostenbalken, feste Bauleiste) - Schriften selbst ausgeliefert (+ Fraunces 700); Kartenfarben als lib/theme-map.ts (noch nicht verdrahtet) - Tests: Kontrast-Test der Tokens, E2E Moduswechsel und Bildschirmfotos hell/dunkel bei 390/1440 px
62 lines
2.5 KiB
TypeScript
62 lines
2.5 KiB
TypeScript
// Seekarte 2.0: Kontrast der Design-Tokens (apps/web/src/theme.css) in hell und dunkel – Schrift ≥ 4,5:1 auf allen
|
||
// Flächen, auf denen sie steht (WCAG 2.1 AA). Liest die Datei direkt, damit Werte und Prüfung nicht auseinanderlaufen.
|
||
import { test } from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import { readFileSync } from "node:fs";
|
||
|
||
const css = readFileSync(new URL("../../../apps/web/src/theme.css", import.meta.url), "utf8");
|
||
|
||
function block(selector: string): Record<string, string> {
|
||
const start = css.indexOf(`${selector} {`);
|
||
assert.ok(start >= 0, `Block ${selector} fehlt`);
|
||
const body = css.slice(start, css.indexOf("}", start));
|
||
const out: Record<string, string> = {};
|
||
for (const m of body.matchAll(/--tf-([a-z0-9-]+):\s*(#[0-9a-f]{6})/gi)) out[m[1]] = m[2].toLowerCase();
|
||
return out;
|
||
}
|
||
|
||
function lum(hex: string): number {
|
||
const c = [1, 3, 5].map((i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255).map((s) => (s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4));
|
||
return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
|
||
}
|
||
export function contrast(a: string, b: string): number {
|
||
const [x, y] = [lum(a), lum(b)].sort((p, q) => q - p);
|
||
return (x + 0.05) / (y + 0.05);
|
||
}
|
||
|
||
const light = block(":root");
|
||
const dark = { ...light, ...block(':root[data-theme="dark"]') };
|
||
|
||
/** Schrift-Token → Flächen, auf denen es als Text vorkommt. */
|
||
const TEXT_ON: [string, string[]][] = [
|
||
["ink", ["paper", "card", "inset", "track", "field", "plate", "nav-sel", "moos-bg", "siegel-bg"]],
|
||
["ink2", ["paper", "card", "inset", "field", "plate", "moos-bg"]],
|
||
["accent-ink", ["paper", "card", "inset", "nav-sel"]],
|
||
["see", ["paper", "card", "inset"]],
|
||
["siegel", ["paper", "card", "inset", "siegel-bg"]],
|
||
["siegel-ink", ["siegel-bg"]],
|
||
["moos", ["paper", "card", "inset", "moos-bg"]],
|
||
["messing", ["paper", "card", "inset"]],
|
||
["warn-ink", ["paper", "card"]],
|
||
["on-accent", ["accent"]],
|
||
["on-strong", ["siegel", "moos"]],
|
||
["head-ink", ["head", "head-track"]],
|
||
["head-muted", ["head"]],
|
||
["head-good", ["head"]],
|
||
["head-alarm", ["head"]],
|
||
["head-warn", ["head"]],
|
||
["placeholder", ["field"]],
|
||
];
|
||
|
||
for (const [mode, t] of [["hell", light], ["dunkel", dark]] as const) {
|
||
test(`Seekarte 2.0 ${mode}: Schrift-Tokens ≥ 4,5:1`, () => {
|
||
const low: string[] = [];
|
||
for (const [fg, bgs] of TEXT_ON) for (const bg of bgs) {
|
||
assert.ok(t[fg] && t[bg], `${fg}/${bg} fehlt`);
|
||
const r = contrast(t[fg], t[bg]);
|
||
if (r < 4.5) low.push(`${fg} auf ${bg}: ${r.toFixed(2)}`);
|
||
}
|
||
assert.deepEqual(low, []);
|
||
});
|
||
}
|