mirror of
https://github.com/block/buzz.git
synced 2026-11-29 12:42:49 +00:00
fix(desktop): deepen the default accent so its white label text is legible
The default accent was #3b82f6, and white label text on it measures WCAG 2 3.68:1 — below the 4.5:1 AA minimum for normal text. That applied to every primary button and active sidebar row in a fresh install, not to a setting someone had opted into. Move it to #2563eb, one step deeper: WCAG 5.17:1 and APCA Lc 80, so it now passes both standards. Radix, Bootstrap, and Tailwind's blue-600 all sit in this range, which is where a blue has to be to carry white text. Darkening the fill is the fix rather than switching the label to black. Black on the old hue scores WCAG 5.71 and would "pass", but measures APCA Lc 40 — perceptually unreadable, and visibly worse. This is the documented WCAG 2 flaw on saturated blue: the formula underweights the blue channel and ignores polarity. Apple ships white on #0088ff–#3daefc in Messages at WCAG 2.4–3.5 for the same reason. DESIGN.md now records the position (judge with APCA, report WCAG, constrain the fill rather than degrade the text) so it is a decision with evidence rather than a preference. Retiring a hex is not only cosmetic: it leaves the old value in people's storage, where it is no longer in ACCENT_COLORS and therefore fails the community-theme allowlist — parseCommunityThemePreference would return null and discard the user's syntax theme and follow-system flag along with the accent. Both storage paths now migrate the retired value instead: the community preference maps it on parse, and the local accent upgrades on read (all three read sites go through one helper). A regression test covers the migration and asserts an arbitrary hex is still rejected, so the migration cannot become a general escape hatch; removing the mapping fails that test. The communityThemeSync fixture moves to a current accent — it covers coordinate logic, and a retired hex there would be rewritten mid-assertion for reasons unrelated to what it tests. Verified: 6112 desktop tests pass, tsc clean, biome clean. Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<string, string> = {
|
||||
"#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<string>(() => {
|
||||
// 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<boolean>(() => {
|
||||
const stored = getStorageItem(GLASS_BACKGROUND_STORAGE_KEY);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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<string>(SYNTAX_THEMES);
|
||||
const ACCENTS = new Set<string>(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<string, string>([
|
||||
// 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<string, unknown>;
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
const preference = {
|
||||
version: 1,
|
||||
theme: "houston",
|
||||
accent: "#3b82f6",
|
||||
accent: "#2563eb",
|
||||
followSystem: false,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user