diff --git a/apps/mobile/lib/cover-palette.ts b/apps/mobile/lib/cover-palette.ts index 9c4253d..fa441fb 100644 --- a/apps/mobile/lib/cover-palette.ts +++ b/apps/mobile/lib/cover-palette.ts @@ -28,7 +28,9 @@ export type CoverSwatches = { accent: string[] } -const PRIMARY_MIN_CONTRAST = 7 +// Best effort: `legibleBackground` only guarantees that white or black reaches +// 7:1, so on some backgrounds primary text settles for pure white or black. +const PRIMARY_MIN_CONTRAST = 10 const SECONDARY_MIN_CONTRAST = 4.5 const SECONDARY_TO_PRIMARY_CONTRAST = 0.62 const ACCENT_MIN_CONTRAST = 3 @@ -97,12 +99,9 @@ export function deriveCoverPalette( ) const accent = pickAccent(swatches.accent, background) ?? foreground - const accentForeground = - contrastRatio(background, accent) >= SECONDARY_MIN_CONTRAST - ? background - : contrastRatio([255, 255, 255], accent) >= contrastRatio([0, 0, 0], accent) - ? ([255, 255, 255] as Rgb) - : ([0, 0, 0] as Rgb) + const accentForeground: Rgb = prefersLightText(accent) + ? [255, 255, 255] + : [0, 0, 0] return { background: toHex(background), @@ -129,7 +128,7 @@ function legibleBackground(color: Rgb, schemeIsDark: boolean): Rgb { return clamped } - const pivot = schemeIsDark ? 0.24 : 0.16 + const pivot = schemeIsDark ? 0.28 : 0.14 return y < pivot ? withLuminance(clamped, DARK_BACKGROUND_MAX_LUMINANCE) : withLuminance(clamped, LIGHT_BACKGROUND_MIN_LUMINANCE)