Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | 2x 2x 2x 2x 2x 2x 2x | /**
* @module Shared/Theme
* @description Cyberpunk design system theme constants with dark/light mode support.
* Single source of truth for colors, breakpoints, and typography used across all dashboards.
*
* Theme architecture:
* – `DARK_THEME_COLORS` → Ingress-inspired neon palette (matches html[data-theme="dark"])
* – `LIGHT_THEME_COLORS` → Professional green palette (matches html[data-theme="light"] / :root)
* – `THEME_COLORS` → Deprecated constant alias of `DARK_THEME_COLORS` (kept for backwards compatibility; not runtime-resolved)
*
* WCAG 2.1 AA compliance:
* Dark #001a1a / #f0f0f0 → 18.1:1 ✅ Cyan #00d9ff / #001a1a → 9.4:1 ✅
* Light #f5f5f5 / #1a1a1a → 16.1:1 ✅ Cyan #0077b6 / #f5f5f5 → 5.2:1 ✅
*
* @intelligence Visual intelligence presentation standards — cyberpunk design system encoding
* risk severity (CRITICAL red → LOW green), classification levels, and intelligence hierarchy
* through consistent color semantics and typography.
*
* @business Brand identity infrastructure — the cyberpunk theme is a key differentiator
* creating instant visual recognition. Design system consistency reduces development cost
* for new features and ensures professional appearance across all 14 language versions.
*
* @marketing Brand consistency engine — ensures every screenshot, embed, and shared
* visualization carries the distinctive Riksdagsmonitor visual identity. CSS custom
* properties enable white-label customization for enterprise/B2G clients.
*/
import type { ThemeColors, Breakpoints } from './types.js';
/* ── Party colour palette (theme-invariant) ─────────────────────────────── */
const PARTY_COLORS: Readonly<Record<string, string>> = {
S: '#E8112d',
M: '#52BDEC',
SD: '#DDDD00',
C: '#009933',
V: '#DA291C',
KD: '#000077',
L: '#006AB3',
MP: '#83CF39',
} as const;
/* ── Dark theme (Ingress-inspired, neon) ────────────────────────────────── */
/**
* Dark cyberpunk theme.
* Matches CSS custom properties under `html[data-theme="dark"]` in styles.css.
* All values pass WCAG 2.1 AA (≥ 4.5:1) against the dark background #001a1a.
*/
export const DARK_THEME_COLORS: ThemeColors = {
cyan: '#00d9ff', // 9.4:1 on #001a1a ✅
magenta: '#ff006e',
yellow: '#ffbe0b',
green: '#06d6a0',
orange: '#fb8500',
purple: '#bd93f9',
red: '#ef476f',
blue: '#58a6ff',
tooltipBg: 'rgba(10, 14, 39, 0.95)',
bodyText: '#e0e0e0',
tickColor: '#a0a0a0',
gridColor: 'rgba(255,255,255,0.07)',
parties: PARTY_COLORS,
} as const;
/* ── Light theme (professional green) ──────────────────────────────────── */
/**
* Light professional theme.
* Matches CSS custom properties under `html[data-theme="light"]` in styles.css.
* All values pass WCAG 2.1 AA (≥ 4.5:1) against the light background #f5f5f5.
*/
export const LIGHT_THEME_COLORS: ThemeColors = {
cyan: '#0077b6', // 5.2:1 on #f5f5f5 ✅ (--primary-cyan light per spec)
magenta: '#c2185b',
yellow: '#b35a00', // accessible amber
green: '#006633',
orange: '#cc5200',
purple: '#7B2CBF',
red: '#DC3545',
blue: '#007744',
tooltipBg: 'rgba(245, 245, 245, 0.95)',
bodyText: '#1a1e3d',
tickColor: '#555555',
gridColor: 'rgba(0,0,0,0.08)',
parties: PARTY_COLORS,
} as const;
/* ── Runtime theme resolution ───────────────────────────────────────────── */
/**
* Returns the active ThemeColors based on the current `data-theme` attribute
* on `<html>`. When the attribute is absent (e.g. before the anti-flash
* snippet runs), falls back to `prefers-color-scheme` — consistent with the
* CSS `@media (prefers-color-scheme: dark)` default. Defaults to
* `DARK_THEME_COLORS` only in SSR / test environments where `document` is
* undefined; in a browser without `matchMedia` support it defaults to
* `LIGHT_THEME_COLORS` (matching the CSS `:root` base styles).
*
* Call this wherever Chart.js datasets need the current palette, e.g.:
* ```ts
* const colors = getActiveThemeColors();
* chart.data.datasets[0].backgroundColor = colors.cyan;
* ```
*/
export function getActiveThemeColors(): ThemeColors {
if (typeof document === 'undefined') return DARK_THEME_COLORS; // SSR / test guard
const theme = document.documentElement.getAttribute('data-theme');
if (theme === 'light') return LIGHT_THEME_COLORS;
if (theme === 'dark') return DARK_THEME_COLORS;
// data-theme not set — mirror the CSS prefers-color-scheme behaviour
if (typeof window !== 'undefined' && window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches) {
return DARK_THEME_COLORS;
}
return LIGHT_THEME_COLORS;
}
/**
* Cyberpunk (dark) theme color palette — kept as the default export for
* backwards compatibility with existing Chart.js consumers.
*
* @deprecated Prefer `getActiveThemeColors()` which returns the correct palette for the
* current `data-theme` value. Migration:
* ```ts
* // Before
* import { THEME_COLORS } from './theme.js';
* chart.data.datasets[0].borderColor = THEME_COLORS.cyan;
*
* // After
* import { getActiveThemeColors } from './theme.js';
* chart.data.datasets[0].borderColor = getActiveThemeColors().cyan;
* ```
*/
export const THEME_COLORS: ThemeColors = DARK_THEME_COLORS;
/* ── Breakpoints ────────────────────────────────────────────────────────── */
/**
* Responsive breakpoints (mobile-first, in px).
*/
export const BREAKPOINTS: Breakpoints = {
mobile: 320,
tablet: 768,
desktop: 1024,
large: 1440,
} as const;
/* ── Chart palettes ─────────────────────────────────────────────────────── */
/**
* Chart color palette for sequential data series (dark theme).
*/
export const CHART_PALETTE = [
DARK_THEME_COLORS.cyan,
DARK_THEME_COLORS.magenta,
DARK_THEME_COLORS.yellow,
DARK_THEME_COLORS.green,
DARK_THEME_COLORS.orange,
DARK_THEME_COLORS.purple,
DARK_THEME_COLORS.red,
DARK_THEME_COLORS.blue,
] as const;
/**
* Chart color palette for sequential data series (light theme).
*/
export const CHART_PALETTE_LIGHT = [
LIGHT_THEME_COLORS.cyan,
LIGHT_THEME_COLORS.magenta,
LIGHT_THEME_COLORS.yellow,
LIGHT_THEME_COLORS.green,
LIGHT_THEME_COLORS.orange,
LIGHT_THEME_COLORS.purple,
LIGHT_THEME_COLORS.red,
LIGHT_THEME_COLORS.blue,
] as const;
/**
* Returns the appropriate chart palette for the current theme.
*/
export function getChartPalette(): readonly string[] {
return getActiveThemeColors() === LIGHT_THEME_COLORS
? CHART_PALETTE_LIGHT
: CHART_PALETTE;
}
/* ── Utilities ──────────────────────────────────────────────────────────── */
/**
* Get party color by party abbreviation.
* Party colors are theme-invariant (official brand colours).
* Falls back to the active theme's cyan for unknown parties.
*/
export function getPartyColor(party: string): string {
return PARTY_COLORS[party] ?? getActiveThemeColors().cyan;
}
/**
* Subscribe to theme changes and invoke the callback with the new ThemeColors.
* Returns an unsubscribe function.
*
* ```ts
* const unsub = onThemeChange((colors) => {
* chart.data.datasets[0].backgroundColor = colors.cyan;
* chart.update();
* });
* ```
*/
export function onThemeChange(
callback: (colors: ThemeColors) => void,
): () => void {
if (typeof MutationObserver === 'undefined' || typeof document === 'undefined')
return () => {};
const observer = new MutationObserver((mutations) => {
for (const m of mutations) {
if (m.attributeName === 'data-theme') {
callback(getActiveThemeColors());
break;
}
}
});
observer.observe(document.documentElement, { attributes: true });
return () => observer.disconnect();
}
|