Thema-fundament: variant (B/E) x modus (licht/donker), tijdreis-knop en overgang

Vervangt rood/paars door tokens per variant en modus, voegt ModeToggle en
icoon-knop VariantToggle toe, VariantRenderer met lazy E-chunk, dither-overgang
(uit bij minder beweging), theme-init.js tegen themaflits en tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 21:14:11 +01:00
co-authored by Claude Sonnet 5.5
parent 1047c738b5
commit 0854e3a096
37 changed files with 1389 additions and 269 deletions
+42
View File
@@ -0,0 +1,42 @@
import { vi } from 'vitest';
type Listener = (event: { matches: boolean }) => void;
/**
* Installs a controllable `window.matchMedia` (jsdom has none). `initial` maps a media query to
* its current result; `set()` flips a query and notifies subscribers like a real change event.
*/
export function mockMatchMedia(initial: Record<string, boolean> = {}) {
const state: Record<string, boolean> = { ...initial };
const listeners = new Map<string, Set<Listener>>();
window.matchMedia = vi.fn((query: string) => ({
get matches() {
return Boolean(state[query]);
},
media: query,
onchange: null,
addEventListener: (_type: string, cb: Listener) => {
if (!listeners.has(query)) listeners.set(query, new Set());
listeners.get(query)!.add(cb);
},
removeEventListener: (_type: string, cb: Listener) => {
listeners.get(query)?.delete(cb);
},
addListener: () => {},
removeListener: () => {},
dispatchEvent: () => false,
})) as unknown as typeof window.matchMedia;
return {
set(query: string, value: boolean) {
state[query] = value;
listeners.get(query)?.forEach((cb) => cb({ matches: value }));
},
};
}
/** Restores the jsdom default: no `matchMedia` at all. */
export function clearMatchMedia() {
delete (window as unknown as { matchMedia?: unknown }).matchMedia;
}
+4
View File
@@ -1 +1,5 @@
import '@testing-library/jest-dom/vitest';
import { vi } from 'vitest';
// jsdom does not implement window.scrollTo; the variant switch scrolls to the top (BR-U1-6).
window.scrollTo = vi.fn() as unknown as typeof window.scrollTo;