From 1bc8af99b71a93f9e6fc9548f9bdc80e556ba624 Mon Sep 17 00:00:00 2001 From: Connor Burgess Date: Thu, 3 Dec 2026 16:49:56 +0700 Subject: [PATCH 1/2] skins: warn at the text floors tokens.css promises (fg-2 7:1, fg-3 5:1) Symptom: a skin whose --fg-2 is 5.3:1 and --fg-3 4.6:1 on its page (#6b6b6b and #757575 on white) is listed with no warning, although tokens.css promises secondary text at 7:1 and meta text at 5:1. Cause: shared/contrast.ts checked --fg-2 against 5 and --fg-3 against 4.5, while its own header says it measures the floors tokens.css promises. docs/skin-authoring.md repeated 5 / 4.5 in its prose, contradicting its own token table (7 / 5 / 3). Fix: TEXT_TIERS now holds --fg-2 to 7 and --fg-3 to 5; --fg, --fg-4 and the focus ring are unchanged. The header comment, the warning examples in skin-api.ts and the skin-authoring paragraph say the same. A new test in shared/contrast.test.ts fails before and passes after; the built-in skins and the stock schemes still clear every floor. Signed-off-by: Connor Burgess --- docs/skin-authoring.md | 4 ++-- server/skins/skins.test.ts | 2 +- shared/contrast.test.ts | 15 +++++++++++++++ shared/contrast.ts | 10 +++++----- shared/skin-api.ts | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/docs/skin-authoring.md b/docs/skin-authoring.md index 328b30c7..edbff2c2 100644 --- a/docs/skin-authoring.md +++ b/docs/skin-authoring.md @@ -82,11 +82,11 @@ the **colour tokens**; the scheme's defaults fill the rest: Values are plain CSS colours (`oklch(…)`, `#hex`, `rgb(…)`, a keyword): no `url()`, no braces, no semicolons. Keep the text tiers at their floors on the page and the card -(`--fg` ≥ 7:1, `--fg-2` ≥ 5:1, `--fg-3` ≥ 4.5:1 for the 12–13 px meta text, `--fg-4` +(`--fg` ≥ 7:1, `--fg-2` ≥ 7:1, `--fg-3` ≥ 5:1 for the 12–13 px meta text, `--fg-4` ≥ 3:1, marks only, each on `--bg` and `--bg-2`). The server measures them when it lists a skin (`shared/contrast.ts`; oklch, hex and rgb values; a token you leave unset is measured against the stock scheme's) and reports a shortfall in the skin's `warning` -("low contrast: --fg-3 on --bg 3.9:1, needs 4.5"), shown in the popover's row; the skin +("low contrast: --fg-3 on --bg 3.9:1, needs 5"), shown in the popover's row; the skin still applies. The themes repo's `packages/color-themes/scripts/check.mjs` measures a whole token set, with more pairs. diff --git a/server/skins/skins.test.ts b/server/skins/skins.test.ts index 40f1f082..0847731c 100644 --- a/server/skins/skins.test.ts +++ b/server/skins/skins.test.ts @@ -523,7 +523,7 @@ describe("contrast", () => { const { contrastWarning } = requireRegistry(); for (const b of BUILTIN_SKINS) expect(contrastWarning(b), b.id).toBeUndefined(); const low = contrastWarning({ scheme: "light", tokens: { light: { "--fg-3": "oklch(0.7 0.01 60)" } } }); - expect(low).toMatch(/^low contrast: --fg-3 on --bg \d\.\d:1, needs 4\.5 · --fg-3 on --bg-2/); + expect(low).toMatch(/^low contrast: --fg-3 on --bg \d\.\d:1, needs 5 · --fg-3 on --bg-2/); const both = contrastWarning({ scheme: "both", tokens: { dark: { "--fg-4": "oklch(0.3 0 0)" }, light: { "--fg": "#000", "--bg": "#fff" } }, diff --git a/shared/contrast.test.ts b/shared/contrast.test.ts index d906768d..9cef596a 100644 --- a/shared/contrast.test.ts +++ b/shared/contrast.test.ts @@ -24,3 +24,18 @@ describe("the focus ring's floor", () => { expect(textTierWarnings({ "--focus": "color-mix(in oklch, var(--fg) 20%, transparent)" }, "light")).toEqual([]); }); }); + +describe("the text tiers' floors are the ones tokens.css promises", () => { + it("secondary text under 7:1 and meta text under 5:1 warn, though they clear 5 and 4.5", () => { + expect(textTierWarnings({ "--fg-2": "#6b6b6b", "--fg-3": "#757575" }, "light")).toEqual([ + "--fg-2 on --bg 5.3:1, needs 7", + "--fg-2 on --bg-2 5.3:1, needs 7", + "--fg-3 on --bg 4.6:1, needs 5", + "--fg-3 on --bg-2 4.6:1, needs 5", + ]); + }); + + it("tiers at the floors do not", () => { + expect(textTierWarnings({ "--fg-2": "#595959", "--fg-3": "#6e6e6e" }, "light")).toEqual([]); + }); +}); diff --git a/shared/contrast.ts b/shared/contrast.ts index 3343bd8e..58e5219a 100644 --- a/shared/contrast.ts +++ b/shared/contrast.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // WCAG contrast for the token values a skin sets, so the server can say when a skin's -// text tiers or marks fall under the floors tokens.css promises (fg ≥ 7:1, fg-2 ≥ 5:1, -// fg-3 ≥ 4.5:1 for 12–13 px meta text, fg-4 ≥ 3:1 for marks only, the focus ring ≥ 3:1) +// text tiers or marks fall under the floors tokens.css promises (fg ≥ 7:1, fg-2 ≥ 7:1, +// fg-3 ≥ 5:1 for 12–13 px meta text, fg-4 ≥ 3:1 for marks only, the focus ring ≥ 3:1) // on the page and the card. Parses the colour forms a skin is likely to use: oklch(), // #hex, rgb(). Anything else is left unmeasured rather than guessed. No dependencies. import type { SkinTokens } from "./skin-api.js"; @@ -56,8 +56,8 @@ export function contrastRatio(a: string, b: string): number | null { /** The text tiers and the floor each must clear on `--bg` and `--bg-2`. */ export const TEXT_TIERS: readonly [token: "--fg" | "--fg-2" | "--fg-3" | "--fg-4", floor: number][] = [ ["--fg", 7], - ["--fg-2", 5], - ["--fg-3", 4.5], + ["--fg-2", 7], + ["--fg-3", 5], ["--fg-4", 3], ]; /** The marks that are not text and the floor each must clear on `--bg` and `--bg-2`: the @@ -94,7 +94,7 @@ export const STOCK_TEXT_TOKENS: Record< }; /** Every text tier and mark under its floor on the page or the card, as one short line each - * ("--fg-3 on --bg 3.9:1, needs 4.5"); empty when all clear or nothing is measurable. */ + * ("--fg-3 on --bg 3.9:1, needs 5"); empty when all clear or nothing is measurable. */ export function textTierWarnings(tokens: SkinTokens, scheme: "dark" | "light"): string[] { const stock = STOCK_TEXT_TOKENS[scheme]; const value = (k: keyof typeof stock): string => tokens[k] ?? stock[k]; diff --git a/shared/skin-api.ts b/shared/skin-api.ts index 8fb50249..f8bf6235 100644 --- a/shared/skin-api.ts +++ b/shared/skin-api.ts @@ -123,7 +123,7 @@ export interface InstalledSkin { /** Why it cannot be applied; listed so the problem shows. */ error?: string; /** Applied all the same, but its text tiers fall under the floors (shared/contrast.ts): - * "--fg-3 on --bg 3.9:1, needs 4.5 · …", per scheme for a "both" skin. */ + * "--fg-3 on --bg 3.9:1, needs 5 · …", per scheme for a "both" skin. */ warning?: string; } From c52f45ea90a05a92dce0f0afca389708f990c9cd Mon Sep 17 00:00:00 2001 From: Connor Burgess Date: Sat, 5 Dec 2026 07:19:27 +0700 Subject: [PATCH 2/2] docs: record the fix under Unreleased Signed-off-by: Connor Burgess --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5299e266..0c34d5ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to `sessionpipe-gui`. The format follows ## [Unreleased] +### Fixed + +- Skin contrast warnings use the text floors promised by the built-in tokens: 7:1 for secondary text and 5:1 for meta text. + ## [0.8.18] - 2026-12-04 ### Fixed