From 648aa96b98783aeaa12abc95b7198a6ee562e68d Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Wed, 7 Oct 2026 21:02:36 +0200 Subject: [PATCH] fix(a11y): make light-theme accent text readable on the canvas --- web/src/lib/Theme/accentPalette.ts | 8 ++++---- web/src/styles.css | 4 ++-- web/src/tests/lib/Theme/accent-palette.test.ts | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/web/src/lib/Theme/accentPalette.ts b/web/src/lib/Theme/accentPalette.ts index 7a937f228..3e0f48798 100644 --- a/web/src/lib/Theme/accentPalette.ts +++ b/web/src/lib/Theme/accentPalette.ts @@ -4,7 +4,7 @@ import { DEFAULT_ACCENT_COLOR } from '@/config/appearance.config.ts' const DARK_INK = '#020a0b' const WHITE = '#ffffff' const BLACK = '#000000' -const LIGHT_SURFACE = '#fbfdfc' +const LIGHT_CANVAS = '#eef4f0' const DARK_SURFACE = '#0d0f12' const MIN_TEXT_CONTRAST = 4.5 @@ -71,11 +71,11 @@ const DEFAULT_PALETTE: AccentPalette = { brand400: '#4ee99a', brand500: DEFAULT_ACCENT_COLOR, brand600: '#0fb33a', - brand700: '#0d8a31', + brand700: '#0c7f2d', foreground: DARK_INK, hover: '#65f586', active: '#0fb33a', - textLight: '#0d8a31', + textLight: '#0c7f2d', textDark: '#65f586', rgb: '48 238 97', } @@ -90,7 +90,7 @@ export function deriveAccentPalette(value: string): AccentPalette { relativeLuminance(accent) > 0.85 ? BLACK : foreground === BLACK ? WHITE : BLACK const brand300 = ensureContrast(mix(accent, WHITE, 0.28), DARK_SURFACE) const brand400 = ensureContrast(mix(accent, WHITE, 0.16), DARK_SURFACE) - const brand700 = ensureContrast(mix(accent, BLACK, 0.25), LIGHT_SURFACE) + const brand700 = ensureContrast(mix(accent, BLACK, 0.25), LIGHT_CANVAS) const channels = parseHex(accent) return { diff --git a/web/src/styles.css b/web/src/styles.css index 6c53c3350..aa98f009f 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -91,11 +91,11 @@ --accent-400: #4ee99a; --accent-500: #30ee61; --accent-600: #0fb33a; - --accent-700: #0d8a31; + --accent-700: #0c7f2d; --accent-foreground: #020a0b; --accent-hover: #65f586; --accent-active: #0fb33a; - --accent-text-light: #0d8a31; + --accent-text-light: #0c7f2d; --accent-text-dark: #65f586; --accent-rgb: 48 238 97; } diff --git a/web/src/tests/lib/Theme/accent-palette.test.ts b/web/src/tests/lib/Theme/accent-palette.test.ts index a4c1fb7bf..7fa36d361 100644 --- a/web/src/tests/lib/Theme/accent-palette.test.ts +++ b/web/src/tests/lib/Theme/accent-palette.test.ts @@ -7,24 +7,33 @@ import { } from '@/lib/Theme/accentPalette.ts' describe('system accent palette', () => { - test('keeps the existing green palette exactly when no color is configured', () => { + test('keeps the default accent and uses readable light-theme text when no color is configured', () => { expect(deriveAccentPalette('#30ee61')).toEqual({ accent: '#30ee61', brand300: '#65f586', brand400: '#4ee99a', brand500: '#30ee61', brand600: '#0fb33a', - brand700: '#0d8a31', + brand700: '#0c7f2d', foreground: '#020a0b', hover: '#65f586', active: '#0fb33a', - textLight: '#0d8a31', + textLight: '#0c7f2d', textDark: '#65f586', rgb: '48 238 97', }) expect(deriveAccentPalette('invalid')).toEqual(deriveAccentPalette('#30ee61')) }) + test('default light-theme text is readable on the canvas and every standard surface', () => { + const palette = deriveAccentPalette('#30ee61') + for (const background of ['#eef4f0', '#fbfdfc', '#ffffff', '#f4f8f5', '#f7fbf8']) { + expect(accentContrastRatio(palette.textLight, background)).toBeGreaterThanOrEqual(4.5) + expect(accentContrastRatio(palette.brand700, background)).toBeGreaterThanOrEqual(4.5) + } + expect(accentCssVariables('#30ee61')['--accent-text-light']).toBe(palette.textLight) + }) + test('derives legible foreground and theme text for arbitrary colors', () => { for (const color of [ '#000000', @@ -49,6 +58,7 @@ describe('system accent palette', () => { 4.5, ) expect(accentContrastRatio(palette.textLight, '#fbfdfc')).toBeGreaterThanOrEqual(4.5) + expect(accentContrastRatio(palette.textLight, '#eef4f0')).toBeGreaterThanOrEqual(4.5) expect(accentContrastRatio(palette.textDark, '#0d0f12')).toBeGreaterThanOrEqual(4.5) expect(accentContrastRatio(palette.brand300, '#0d0f12')).toBeGreaterThanOrEqual(4.5) expect(accentContrastRatio(palette.brand400, '#0d0f12')).toBeGreaterThanOrEqual(4.5)