Repository navigation
Theme: Preserve contrast after color rounding - #86189
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +153 B (0%) Total Size: 8.63 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. As a user I expect my navigation to use the colors I selected for it in
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the contrast-rounding and final-color validation changes.
No open issues 🎉
What changed in this PR
This PR updates @wordpress/theme color generation to preserve contrast targets after 8-bit sRGB rounding and report remaining failures from the final emitted colors.
Changes:
- Makes the rounding margin proportional to the contrast target and accounts for solver tolerance.
- Validates final colors after seed adjustment, including reused steps, while preserving existing exclusions.
- Adds regression coverage and regenerates default ramps, tokens, and fallbacks.
| File | Description |
|---|---|
packages/theme/tokens/color.json |
Updates generated color values. |
packages/theme/src/test/theme-provider.browser.test.tsx |
Updates browser warning expectations. |
packages/theme/src/test/theme-provider-color-warnings.test.ts |
Updates the seed-adjustment regression case. |
packages/theme/src/color-ramps/test/index.test.ts |
Adds contrast and rounding regression tests. |
packages/theme/src/color-ramps/lib/utils.ts |
Applies proportional margin and solver-tolerance compensation. |
packages/theme/src/color-ramps/lib/index.ts |
Checks final emitted colors for contrast failures. |
packages/theme/src/color-ramps/lib/default-ramps.ts |
Refreshes precomputed default ramps. |
packages/theme/src/color-ramps/lib/constants.ts |
Defines the rounding margin and clarifies tolerance units. |
packages/theme/README.md |
Updates documented contrast ratios. |
packages/theme/prebuilt/js/design-tokens.mjs |
Refreshes generated token metadata and fallbacks. |
packages/theme/prebuilt/js/design-token-fallbacks.mjs |
Refreshes JavaScript token fallbacks. |
packages/theme/prebuilt/css/design-tokens.css |
Refreshes generated CSS token values. |
packages/theme/CHANGELOG.md |
Records the contrast correction. |
packages/base-styles/internal/_wpds-token-fallbacks.scss |
Synchronizes Sass token fallbacks. |
Review effort: Balanced
8956d47 to
16c3715
Compare
| it( 'reports a ramp warning when rounded colors miss a required contrast target', () => { | ||
| const { ramp, warnings } = buildRamp( | ||
| 'rgb(0 10.6 0)', | ||
| { | ||
| ...BG_RAMP_CONFIG, | ||
| fgSurface3: { | ||
| contrast: { | ||
| reference: 'seed', | ||
| followDirection: 'lighter', | ||
| target: 20.05, | ||
| }, | ||
| lightness: () => 1, | ||
| }, | ||
| }, | ||
| { rescaleToFitContrastTargets: false } | ||
| ); | ||
|
|
||
| expect( getContrast( ramp.surface2, ramp.fgSurface3 ) ).toBeLessThan( | ||
| 20.05 | ||
| ); | ||
| expect( warnings ).toContain( 'fgSurface3' ); |
There was a problem hiding this comment.
I think this passes with the old warning logic too. Is that expected?
There was a problem hiding this comment.
True, I missed that.
I've added a new regression test that fails with the old logic: meeting the configured target must clear the warning even if the rounding reserve is missed.
16c3715 to
e4d93ad
Compare
Follow-up to #82505 and #82591.
What?
Preserve configured contrast targets after generated colors are rounded to 8-bit sRGB, and report remaining failures from the final emitted colors. Generated default color token values shift slightly too.
Why?
Blue and Ocean weak neutral text fell below 4.5:1 even though their internal color calculations reached 4.52:1.
How?
Make the rounding reserve proportional to the contrast target and account for the solver's logarithmic tolerance. Check every configured reference after seed adjustment, including reused colors, while preserving the existing exclusions. Restore the
fgFilltarget to 4.5 because the shared reserve now handles rounding, avoiding unnecessary seed adjustments.Default ramps, tokens, and fallbacks are rebuilt. The separate 3:1 brand-fill warnings remain.
Testing Instructions
#1e1e1ewith primary#3858e9. Confirm the resting brand-fill warnings remain, while text passes its contrast checks.Testing Instructions for Keyboard
Use the keyboard to edit the Default story's color controls and confirm that the warning report updates with the same results.
Verification
All 321 affected tests pass, including Chromium. The production build, theme typecheck, and JavaScript lint pass. A comparison covering 2,560 seed and background-lightness combinations reduces adjusted seeds from 396 to 374 when the
fgFilltarget returns from 4.55 to 4.5. Both fill states retain at least 4.5576:1 text contrast in that sample.Use of AI Tools
Codex investigated the failures, implemented the numerical safeguards and regression tests, regenerated the token files, ran verification, addressed review feedback, and drafted this description. Separate Codex agents reviewed the changes.