Skip to content

Preferences: accent ink and links keep contrast with the picked accent - #997

Open
juanlentino wants to merge 2 commits into
WordPress:trunkfrom
juanlentino:fix/accent-ink-wcag-crossover
Open

juanlentino wants to merge 2 commits into
WordPress:trunkfrom
juanlentino:fix/accent-ink-wcag-crossover

Conversation

@juanlentino

@juanlentino juanlentino commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #996

accentWantsDarkInk compared the accent's relative luminance against 0.35. The crossover where Void (#0c0b0f) and Starlight (#fffbff) have equal contrast on a fill is about 0.184, so between the two the picker chose the ink with less contrast.

What changed

  • src/settings/index.ts: the threshold is now 0.184, with the formula in the docblock. Pulse returns early and keeps Starlight, as the docblock already promised.
  • assets/css/variables.css and docs/desktop-themes.md: the comment and the token description now say Void is written when it has more contrast on the accent, and name the swatches that get it.

Swatches whose ink changes to Void (dark)

Swatch Starlight before Void after
Teal #04a4cc 2.85:1 6.71:1
Amber #d97706 3.11:1 6.16:1
Emerald #059669 3.68:1 5.21:1

Custom accents with luminance between 0.184 and 0.35 change too, for example #ff0000: 3.90:1 before, 4.91:1 after. Pulse, WordPress Blue, Indigo and Rose keep Starlight; Nebula, Sirius, Lagoon and Starlight keep Void.

Links

The picker wrote --os-ui-accent, its ink and its dim, and left --os-link and --os-ui-accent-strong at the palette's Nebula (#ec9bff). Every link and accent-strong label stayed pink whichever accent was picked.

apply() now writes both inline on <body> with accentLinkColor() in src/settings/index.ts. If the accent reads at 4.5:1 on Astro (#33303a, the lightest surface the palette puts text on), it is used as is. Otherwise it is mixed toward Starlight in 5% steps until it reads at 4.5:1. Pulse keeps Nebula, as it keeps its dim. Nothing is written while a desktop theme is worn, because the theme owns the surfaces the link sits on. assets/css/variables.css and docs/desktop-themes.md describe the two tokens.

Contrast on Astro:

Accent Accent as link Link written Link contrast
Nebula #ec9bff 6.59:1 #ec9bff 6.59:1
Sirius #9af2ff 10.17:1 #9af2ff 10.17:1
Lagoon #9f98ff 5.18:1 #9f98ff 5.18:1
Starlight #fffbff 12.62:1 #fffbff 12.62:1
WordPress Blue #2271b1 2.50:1 #6fa1cc 4.71:1
Indigo #3858e9 2.30:1 #8899f2 4.85:1
Teal #04a4cc 4.42:1 #11a8cf 4.63:1
Emerald #059669 3.43:1 #44af8e 4.78:1
Amber #d97706 4.06:1 #dd841f 4.55:1
Rose #e11d48 2.75:1 #ed7691 4.68:1
Custom #ff0000 3.23:1 #ff7173 4.84:1

tests/vitest/os-settings-accent-link-apply.test.ts (new, 14 cases):

  • For every built-in swatch, both tokens reach at least 4.5:1 on Void, Obsidian and Astro, and every swatch other than Pulse moves them off Nebula.
  • Pulse and Nebula leave them at #ec9bff.
  • A worn desktop theme gets no inline write.

With the link change reverted, 9 of the 14 cases fail (Sirius, Lagoon, Starlight, WordPress Blue, Indigo, Teal, Emerald, Amber, Rose). With it, all pass. With both changes, npm run lint (0 errors), npm run typecheck, npm run build and npm run test:js (537 files, 6,722 tests) pass.

Testing

  • tests/vitest/accent-ink.test.ts (new): for every built-in swatch except Pulse, and for custom #ff0000, #00a000 and #000080, the chosen ink has more contrast than the other one, computed independently in the test; #ff0000 reaches AA 4.5:1; Pulse keeps Starlight; a value that is not a six-digit hex keeps Starlight. On trunk 6 of the 16 cases fail (Teal, Emerald, Amber, #ff0000, #00a000, and the AA check); with this change all pass.
  • npm run lint (0 errors), npm run typecheck, and npm run test:js (535 files, 6,700 tests) pass.

Engineered with Claude as a pair programmer.

🤖 Generated with Claude Code

Open WordPress Playground Preview

juanlentino and others added 2 commits October 12, 2026 09:33
accentWantsDarkInk compared relative luminance against 0.35. The
crossover where Void and Starlight have equal contrast is about 0.184,
so between the two the picker chose Starlight where Void reads better:
Teal, Emerald, Amber and custom colours such as #ff0000 (3.90:1 with
Starlight, 4.91:1 with Void). Pulse keeps Starlight as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The accent picker wrote --os-ui-accent, its ink and its dim, and left
--os-link and --os-ui-accent-strong at the palette's Nebula, so links
and accent-strong labels stayed pink whatever swatch was picked.

apply() now writes both inline on <body>: the accent itself when it
reads at 4.5:1 on Astro, otherwise the accent mixed toward Starlight
until it does. Pulse keeps the palette's Nebula, as it keeps its dim,
and nothing is written while a desktop theme is worn, since the theme
owns the surfaces the link sits on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juanlentino juanlentino changed the title Preferences: Pick the accent ink with more contrast on the fill Preferences: accent ink and links keep contrast with the picked accent Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preferences: the accent picker puts light text on mid-luminance accents where dark text has more contrast

1 participant