From ca9c6bfa453a8f81e8926bc4268f86c44cb73e5a Mon Sep 17 00:00:00 2001 From: Quick104 <31828688+Quick104@users.noreply.github.com> Date: Fri, 20 Nov 2026 20:25:57 -0500 Subject: [PATCH 1/2] fix(web): keep accent-colored text readable on Cinema Dark An admin accent was drawn as text in its raw color, so five of the eight presets read below 4.5:1 on Cinema Dark's surfaces, most visibly on the active sidebar item. text-primary now resolves to --primary-text, which the accent sets to itself lightened just enough to read on the lightest surface and on its own strongest tint, with a second value for high contrast's lighter surfaces. Fills, borders, and rings keep the exact accent. Text that bypassed or faded the token now reads too: the current episode's caption uses text-primary, text links underline on hover instead of fading to 80%, and premiere badges get an opaque, accent-tinted fill over artwork. Co-Authored-By: Claude Opus 5.5 --- docs/settings-api.md | 5 ++ web/docs/design-system.md | 1 + web/src/app.css | 4 ++ .../admin/libraries/LibraryFormSections.tsx | 2 +- .../watchlist/WatchlistTitlesTab.tsx | 2 +- web/src/contexts/BrandingProvider.tsx | 7 ++- web/src/lib/accentColor.ts | 63 +++++++++++++++---- web/src/lib/upcomingEventPresentation.ts | 2 +- web/src/pages/AdminPlaybackHistory.tsx | 2 +- .../components/EpisodeCardCaption.tsx | 7 ++- web/src/pages/Recommendations.tsx | 2 +- web/src/pages/RecommendationsSection.tsx | 2 +- web/src/pages/RequestDiscoverSection.tsx | 2 +- web/src/pages/Requests.tsx | 4 +- 14 files changed, 79 insertions(+), 26 deletions(-) diff --git a/docs/settings-api.md b/docs/settings-api.md index 09dec59ea1..17ed7e858a 100644 --- a/docs/settings-api.md +++ b/docs/settings-api.md @@ -489,6 +489,11 @@ accent as stored. A stored value that is not a `#rgb` or the web app manifest use it too. The branding document has no default theme or light-theme logo URLs, and the API has no theme overrides or theme catalog. +Text in the accent color (`text-primary`) doesn't use the stored value as is. +The web client lightens the accent just enough to read at 4.5:1 on Cinema +Dark's lightest surface and on the accent's own 20% tint, with a paler variant +for high contrast. Fills, borders and the focus ring keep the stored color. + ### Retired theme settings Manifest revision 12 deprecates `ui.theme`, `ui.custom_theme_vars` and diff --git a/web/docs/design-system.md b/web/docs/design-system.md index f36e151e0b..a3f52373c1 100644 --- a/web/docs/design-system.md +++ b/web/docs/design-system.md @@ -138,6 +138,7 @@ Colors are organized as semantic layers. `app.css` provides the actual values; c - `--primary`: primary action color - `--primary-foreground`: text on primary elements +- `--primary-text`: the primary color as text, which `text-primary` uses. An admin accent sets it to a lighter variant that reads at 4.5:1 on Cinema Dark's surfaces; without one it is `--primary`. Draw accent-colored text with `text-primary`, never `var(--primary)` - `--secondary`: secondary element backgrounds - `--accent`: highlighted and active backgrounds - `--destructive`: danger and error text, icons, borders, and status dots diff --git a/web/src/app.css b/web/src/app.css index 17914688eb..710739911a 100644 --- a/web/src/app.css +++ b/web/src/app.css @@ -57,6 +57,10 @@ /* ── Interactive ─────────────────────────────────────────── */ --color-primary: var(--primary); --color-primary-foreground: var(--primary-foreground); + /* Text in the primary color. An admin accent sets --primary-text to a + variant that reads on Cinema Dark's surfaces (lib/accentColor.ts); fills, + borders, and rings keep the accent itself. */ + --text-color-primary: var(--primary-text, var(--primary)); --color-secondary: var(--secondary); --color-secondary-foreground: var(--secondary-foreground); --color-muted: var(--muted); diff --git a/web/src/components/admin/libraries/LibraryFormSections.tsx b/web/src/components/admin/libraries/LibraryFormSections.tsx index 7651aa5726..2feab45ce4 100644 --- a/web/src/components/admin/libraries/LibraryFormSections.tsx +++ b/web/src/components/admin/libraries/LibraryFormSections.tsx @@ -331,7 +331,7 @@ function ProviderLevelSection({ type="button" onClick={() => setCollapsed(!collapsed)} aria-expanded={!collapsed} - className="text-primary hover:text-primary/80 mb-1.5 flex min-h-11 items-center gap-1.5 text-start text-xs font-semibold tracking-wider uppercase sm:min-h-0" + className="text-primary mb-1.5 flex min-h-11 items-center gap-1.5 text-start text-xs font-semibold tracking-wider uppercase hover:underline sm:min-h-0" > {collapsed ? : } {contentLevelLabel(level)} diff --git a/web/src/components/watchlist/WatchlistTitlesTab.tsx b/web/src/components/watchlist/WatchlistTitlesTab.tsx index 13a07de31e..91921ac7e6 100644 --- a/web/src/components/watchlist/WatchlistTitlesTab.tsx +++ b/web/src/components/watchlist/WatchlistTitlesTab.tsx @@ -101,7 +101,7 @@ export default function WatchlistTitlesTab({

{watchlistTitlesHint(watchlistRequests)}

{t("web.library.watchlist.findMore")} diff --git a/web/src/contexts/BrandingProvider.tsx b/web/src/contexts/BrandingProvider.tsx index c99d8fb750..d49c05ab3c 100644 --- a/web/src/contexts/BrandingProvider.tsx +++ b/web/src/contexts/BrandingProvider.tsx @@ -95,7 +95,8 @@ const ACCENT_STYLE_ID = "silo-accent"; * to , so it wins over the theme's layered tokens. That would also beat * high contrast's boosted focus ring, so a second unlayered rule restores it: * a dark accent must not hide keyboard focus for someone who asked for high - * contrast. + * contrast. The same rule swaps accent text to the variant that reads on high + * contrast's lighter surfaces. */ function applyAccent(hex: string | null) { if (typeof document === "undefined") return; @@ -103,7 +104,9 @@ function applyAccent(hex: string | null) { const css = declarations ? `:root {\n${Object.entries(declarations) .map(([token, value]) => ` --${token}: ${value};`) - .join("\n")}\n}\nhtml[data-high-contrast="true"] {\n --ring: var(--contrast-boost);\n}` + .join( + "\n", + )}\n}\nhtml[data-high-contrast="true"] {\n --ring: var(--contrast-boost);\n --primary-text: var(--primary-text-high-contrast);\n}` : ""; let style = document.getElementById(ACCENT_STYLE_ID) as HTMLStyleElement | null; if (!css) { diff --git a/web/src/lib/accentColor.ts b/web/src/lib/accentColor.ts index 683a64491e..c6dddd2f9f 100644 --- a/web/src/lib/accentColor.ts +++ b/web/src/lib/accentColor.ts @@ -49,17 +49,29 @@ function contrastRatio(a: string, b: string): number { return (light! + 0.05) / (dark! + 0.05); } -function mixWithWhite(hex: string, amount: number): string { - const value = parseInt(hex.slice(1), 16); +/** Moves `hex` toward `target` by `amount` (0 keeps `hex`, 1 gives `target`). */ +function mixToward(hex: string, target: string, amount: number): string { + const from = parseInt(hex.slice(1), 16); + const to = parseInt(target.slice(1), 16); const channel = (shift: number) => { - const c = (value >> shift) & 0xff; - return Math.round(c + (255 - c) * amount) + const a = (from >> shift) & 0xff; + const b = (to >> shift) & 0xff; + return Math.round(a + (b - a) * amount) .toString(16) .padStart(2, "0"); }; return `#${channel(16)}${channel(8)}${channel(0)}`; } +/** The accent mixed toward white in twentieths until `reads` accepts it, or white. */ +function lightenUntil(hex: string, reads: (candidate: string) => boolean): string { + for (let step = 0; step <= 20; step++) { + const candidate = mixToward(hex, WHITE_LABEL, step / 20); + if (reads(candidate)) return candidate; + } + return WHITE_LABEL; +} + /** The label drawn on an accent: white or Cinema Dark's dark label, whichever reads better. */ function labelOn(hex: string): string { return prefersWhiteLabel(hex) ? WHITE_LABEL : DARK_LABEL; @@ -83,16 +95,37 @@ function primaryLabelOn(hex: string): string { * badge) still reads. */ function accentOnDark(hex: string): string { - for (let step = 0; step <= 20; step++) { - const candidate = mixWithWhite(hex, step / 20); - if ( + return lightenUntil( + hex, + (candidate) => contrastRatio(candidate, PLAYER_PANEL) >= MIN_PLAYER_CONTRAST && - contrastRatio(candidate, labelOn(candidate)) >= MIN_PLAYER_CONTRAST - ) { - return candidate; - } - } - return WHITE_LABEL; + contrastRatio(candidate, labelOn(candidate)) >= MIN_PLAYER_CONTRAST, + ); +} + +/** Cinema Dark's lightest surface under text, --surface-raised. */ +const LIGHTEST_SURFACE = "#28282e"; +/** High contrast mixes 20% of its white boost into --surface-raised (app.css). */ +const LIGHTEST_SURFACE_HIGH_CONTRAST = mixToward(LIGHTEST_SURFACE, WHITE_LABEL, 0.2); +/** The strongest accent tint text sits on: `bg-primary/20`. */ +const STRONGEST_TINT = 0.2; +/** WCAG AA for normal text. */ +const MIN_TEXT_CONTRAST = 4.5; + +/** + * The accent as text (`text-primary`) on Cinema Dark: unchanged when it + * already reads at 4.5:1 on `surface`, the lightest surface text sits on, and + * on the accent's own strongest tint over it; otherwise lightened just enough. + * Darker surfaces then read at least as well. + */ +function accentText(hex: string, surface: string): string { + const tint = mixToward(surface, hex, STRONGEST_TINT); + return lightenUntil( + hex, + (candidate) => + contrastRatio(candidate, surface) >= MIN_TEXT_CONTRAST && + contrastRatio(candidate, tint) >= MIN_TEXT_CONTRAST, + ); } /** @@ -113,6 +146,10 @@ export function accentDeclarations(accent: string): Record | nul "sidebar-primary": hex, "accent-on-dark": onDark, "accent-on-dark-foreground": labelOn(onDark), + // app.css maps text-primary to --primary-text; BrandingProvider swaps in + // the high contrast value under that setting. + "primary-text": accentText(hex, LIGHTEST_SURFACE), + "primary-text-high-contrast": accentText(hex, LIGHTEST_SURFACE_HIGH_CONTRAST), }; const label = primaryLabelOn(hex); if (label !== DARK_LABEL) { diff --git a/web/src/lib/upcomingEventPresentation.ts b/web/src/lib/upcomingEventPresentation.ts index b47f1607bc..f6b3c4c843 100644 --- a/web/src/lib/upcomingEventPresentation.ts +++ b/web/src/lib/upcomingEventPresentation.ts @@ -36,7 +36,7 @@ export function upcomingBadgeClass(badge: string): string { switch (badge) { case "series_premiere": case "season_premiere": - return "border-primary/40 bg-primary/20 text-primary"; + return "border-primary/40 bg-[color-mix(in_srgb,var(--primary)_20%,var(--accent))] text-primary shadow-sm backdrop-blur-none"; case "finale": return "border-orange-800/55 bg-orange-950/90 text-orange-50 shadow-sm backdrop-blur-none"; case "digital": diff --git a/web/src/pages/AdminPlaybackHistory.tsx b/web/src/pages/AdminPlaybackHistory.tsx index 5813550f5b..d267ecee63 100644 --- a/web/src/pages/AdminPlaybackHistory.tsx +++ b/web/src/pages/AdminPlaybackHistory.tsx @@ -412,7 +412,7 @@ export default function AdminPlaybackHistory() { {t("web.admin.activity.row.ffmpegLogs")} diff --git a/web/src/pages/ItemDetail/components/EpisodeCardCaption.tsx b/web/src/pages/ItemDetail/components/EpisodeCardCaption.tsx index 5e3b7a32e7..b899f060b2 100644 --- a/web/src/pages/ItemDetail/components/EpisodeCardCaption.tsx +++ b/web/src/pages/ItemDetail/components/EpisodeCardCaption.tsx @@ -1,6 +1,7 @@ import type { ReactNode } from "react"; import type { EpisodeListItem } from "@/api/types"; import { useAppLanguage } from "@/i18n"; +import { cn } from "@/lib/utils"; import MachineTranslatedLabel from "./MachineTranslatedLabel"; import { hasMachineTranslation } from "./machineTranslation"; import { episodeCardMetadata, episodeCardSpokenTitle, episodeCardTitle } from "./episodeCardText"; @@ -38,8 +39,10 @@ export default function EpisodeCardCaption({

{episodeCardSpokenTitle(episode)} diff --git a/web/src/pages/Recommendations.tsx b/web/src/pages/Recommendations.tsx index 779f144bca..64cf6c9905 100644 --- a/web/src/pages/Recommendations.tsx +++ b/web/src/pages/Recommendations.tsx @@ -121,7 +121,7 @@ function DiscoverErrorState({ onRetry }: { onRetry: () => void }) {

{t("web.recommendations.loadFailed")}