diff --git a/desktop-next/DESIGN.md b/desktop-next/DESIGN.md index 27bc0632dc..421c264953 100644 --- a/desktop-next/DESIGN.md +++ b/desktop-next/DESIGN.md @@ -80,6 +80,36 @@ Buzz is a place where people build together and bring their agents into the room - **Never use a status colour decoratively.** A green that does not mean success teaches people to stop trusting green. - **Categorical colours are the one place appearance-naming is allowed.** Telling two projects apart genuinely is a choice about appearance. +## Contrast + +Buzz judges contrast with **APCA** (the perceptual algorithm in the WCAG 3 +draft), not the WCAG 2 ratio. Target **Lc 60** for body text, Lc 45 for large +or non-essential text. This is a deliberate position, taken with evidence, and +it is the rule a generated theme is measured against. + +- **Why.** The WCAG 2 ratio underweights blue and ignores polarity, so it + systematically recommends dark text on saturated mid-tone fills where light + text is plainly more readable. Measured: white on `#3b82f6` scores WCAG 3.68 + (fail) but APCA Lc 69 (pass); black on the same fill scores WCAG 5.71 (pass) + but Lc 40 — badly unreadable. Apple ships white on `#0088ff`–`#3daefc` in + Messages at WCAG 2.4–3.5, and Tailwind, Bootstrap, and Radix all ship white + on their primary blue below or near the WCAG threshold. Three independent + signals agree with the eye; one number disagrees with all of them. +- **APCA is not the looser choice.** It is stricter wherever WCAG 2 is + permissive: red on black (WCAG 5.25 pass, Lc 38 fail) and every dark-mode + mid-grey. Adopting it tightens more pairings than it relaxes. +- **Report both.** WCAG 2 is what an audit measures and what regulators + recognise today. Design to APCA, and know the WCAG number before shipping a + surface that will be scanned. Where they disagree, say so in the change. +- **Constrain the fill, never degrade the text.** If neither black nor white + carries a fill legibly, the fill is wrong — it is not a valid solid. Move the + fill's lightness and keep the hue; do not settle for the less-bad text. +- **A paired text token is derived, not authored.** `text-on-*` is a function of + its fill, so it is generated with the fill and never hand-set. Every hand-set + pairing in this system has been wrong at least once. +- **One implementation of the rule.** Desktop, mobile, and web must not each + compute their own pairing; they diverge and the same defect ships three times. + ## Writing - **Every word earns its place.** Prefer the shortest phrasing that stays accurate. diff --git a/desktop/src/shared/theme/ThemeProvider.tsx b/desktop/src/shared/theme/ThemeProvider.tsx index 63fd3adb4d..65651bc9fd 100644 --- a/desktop/src/shared/theme/ThemeProvider.tsx +++ b/desktop/src/shared/theme/ThemeProvider.tsx @@ -43,7 +43,7 @@ const GLASS_VIBRANCY_MATERIAL = "sidebar"; export const ACCENT_COLORS = [ { name: "Neutral", value: NEUTRAL_ACCENT }, - { name: "Blue", value: "#3b82f6" }, + { name: "Blue", value: "#2563eb" }, { name: "Cyan", value: "#06b6d4" }, { name: "Green", value: "#22c55e" }, { name: "Orange", value: "#f97316" }, @@ -54,7 +54,37 @@ export const ACCENT_COLORS = [ { name: "Indigo", value: "#6366f1" }, ] as const; -const DEFAULT_ACCENT = "#3b82f6"; +/** + * One step deeper than the blue it replaced (`#3b82f6`), so white label text is + * legible on it by both standards: WCAG 5.17:1 and APCA Lc 80, against 3.68 and + * Lc 69 before. The old value failed WCAG AA on every primary button and active + * sidebar row in the default install. + * + * Darkening the fill is the fix rather than switching the label to black — + * black on this hue measures Lc 40, which is perceptually unreadable even + * though WCAG 2 scores it 5.71 and calls it a pass. See DESIGN.md § Contrast. + */ +const DEFAULT_ACCENT = "#2563eb"; + +/** + * Accent hexes that were offered once and are still in people's storage, mapped + * to what replaced them. + * + * A retired hex is not merely cosmetic debt: it is no longer in + * `ACCENT_COLORS`, so it fails the community-theme allowlist and would + * otherwise persist locally forever, leaving one surface on a value the product + * has decided is not legible. + */ +const RETIRED_ACCENTS: Record = { + "#3b82f6": "#2563eb", +}; + +/** Reads the stored accent, upgrading a retired value on the way through. */ +function readStoredAccent(): string { + const stored = getStorageItem(ACCENT_STORAGE_KEY); + if (!stored) return DEFAULT_ACCENT; + return RETIRED_ACCENTS[stored] ?? stored; +} type ThemeContextValue = { themeName: string; @@ -410,7 +440,7 @@ function applyCachedVars(): string | null { applyBuzzSidebar(themeName); glassThemeReady = true; - const accent = getStorageItem(ACCENT_STORAGE_KEY) ?? DEFAULT_ACCENT; + const accent = readStoredAccent(); // Pin Buzz themes to the neutral accent here too, matching applyTheme. // Otherwise a cached Buzz theme + non-neutral stored accent flashes the // old accent on reload until the async applyTheme effect runs. @@ -457,12 +487,7 @@ async function applyTheme(name: SyntaxThemeName): Promise<{ // microtask (e.g. the caller's `.then`) let the previous accent flash on the // new theme for a frame — the flicker seen when switching to Buzz. Buzz // themes resolve to the neutral accent regardless of the stored value. - applyAccentColor( - resolveEffectiveAccent( - name, - getStorageItem(ACCENT_STORAGE_KEY) ?? DEFAULT_ACCENT, - ), - ); + applyAccentColor(resolveEffectiveAccent(name, readStoredAccent())); // Cache for FOUC prevention try { @@ -499,7 +524,7 @@ export function ThemeProvider({ const [accentColor, setAccentColorState] = useState(() => { // block/buzz#5078 — use the throw-safe accessor for init-time reads; a // denied-storage origin would otherwise kill the root on first mount. - return getStorageItem(ACCENT_STORAGE_KEY) ?? DEFAULT_ACCENT; + return readStoredAccent(); }); const [glassBackground, setGlassBackgroundState] = useState(() => { const stored = getStorageItem(GLASS_BACKGROUND_STORAGE_KEY); diff --git a/desktop/src/shared/theme/communityThemePreference.test.mjs b/desktop/src/shared/theme/communityThemePreference.test.mjs index 1cc689cf4b..fbe2833070 100644 --- a/desktop/src/shared/theme/communityThemePreference.test.mjs +++ b/desktop/src/shared/theme/communityThemePreference.test.mjs @@ -209,3 +209,45 @@ test("community switch defers stale outgoing appearance persistence", () => { ); assert.equal(communityThemePersistenceAction(null, incoming), "persist"); }); + +test("a retired accent hex is migrated rather than discarding the whole theme", () => { + // #3b82f6 was the default until it was deepened to #2563eb for legible white + // label text. It is no longer in ACCENT_COLORS, so without a migration it + // fails the allowlist and takes the user's syntax theme and follow-system + // flag down with it. + const stored = { + version: 1, + theme: "catppuccin-latte", + accent: "#3b82f6", + followSystem: false, + }; + + const parsed = parseCommunityThemePreference(stored); + + assert.notEqual( + parsed, + null, + "a retired accent must not void the preference", + ); + assert.equal(parsed.accent, "#2563eb", "the retired hex is upgraded"); + assert.equal( + parsed.theme, + "catppuccin-latte", + "the rest of the theme survives", + ); + assert.equal(parsed.followSystem, false); +}); + +test("an accent that was never offered is still rejected", () => { + // The migration must not become a general-purpose escape hatch: an arbitrary + // hex is not a retired value and still fails the allowlist. + assert.equal( + parseCommunityThemePreference({ + version: 1, + theme: "buzz", + accent: "#123456", + followSystem: true, + }), + null, + ); +}); diff --git a/desktop/src/shared/theme/communityThemePreference.ts b/desktop/src/shared/theme/communityThemePreference.ts index d9b13c0562..0115c8f511 100644 --- a/desktop/src/shared/theme/communityThemePreference.ts +++ b/desktop/src/shared/theme/communityThemePreference.ts @@ -16,13 +16,28 @@ export type CommunityThemePreference = { export const DEFAULT_COMMUNITY_THEME: CommunityThemePreference = Object.freeze({ version: 1, theme: "buzz", - accent: "#3b82f6", + accent: "#2563eb", followSystem: true, }); const THEME_NAMES = new Set(SYNTAX_THEMES); const ACCENTS = new Set(ACCENT_COLORS.map(({ value }) => value)); +/** + * Accent hexes that are no longer offered but are still sitting in people's + * stored preferences, mapped to their replacement. + * + * Without this, retiring a hex from `ACCENT_COLORS` makes every stored + * preference holding it fail validation — `parseCommunityThemePreference` + * returns null and the whole saved theme, including the chosen syntax theme and + * follow-system flag, is silently discarded. Migrating the one field preserves + * the rest. + */ +const RETIRED_ACCENTS = new Map([ + // Deepened so white label text is legible on it; see DESIGN.md § Contrast. + ["#3b82f6", "#2563eb"], +]); + export function communityThemeStorageKey( pubkey: string, relayUrl: string, @@ -44,12 +59,16 @@ export function parseCommunityThemePreference( return null; } const candidate = value as Record; + const accent = + typeof candidate.accent === "string" + ? (RETIRED_ACCENTS.get(candidate.accent) ?? candidate.accent) + : candidate.accent; if ( candidate.version !== 1 || typeof candidate.theme !== "string" || !THEME_NAMES.has(candidate.theme) || - typeof candidate.accent !== "string" || - !ACCENTS.has(candidate.accent) || + typeof accent !== "string" || + !ACCENTS.has(accent) || typeof candidate.followSystem !== "boolean" ) { return null; @@ -57,7 +76,7 @@ export function parseCommunityThemePreference( return { version: 1, theme: candidate.theme as SyntaxThemeName, - accent: candidate.accent, + accent, followSystem: candidate.followSystem, }; } diff --git a/desktop/src/shared/theme/communityThemeSync.test.mjs b/desktop/src/shared/theme/communityThemeSync.test.mjs index 956197125c..280529e28f 100644 --- a/desktop/src/shared/theme/communityThemeSync.test.mjs +++ b/desktop/src/shared/theme/communityThemeSync.test.mjs @@ -11,7 +11,7 @@ import { const preference = { version: 1, theme: "houston", - accent: "#3b82f6", + accent: "#2563eb", followSystem: false, };