Skip to content

Theme: Generate perceptually balanced color ramps - #82294

Open
ciampo wants to merge 6 commits into
trunkfrom
codex/theme-anchored-foreground-scale
Open

ciampo wants to merge 6 commits into
trunkfrom
codex/theme-anchored-foreground-scale

Conversation

@ciampo

@ciampo ciampo commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #77153. Follow-up to #82037. Alternative to #81537.

What?

Generate more evenly spaced color ramps across light, dark, and tinted themes. Body text and resting controls use the fourth foreground step. A new fifth step gives headings, overlay titles, and active controls stronger emphasis. In the default light theme, headings use #141414 and body text uses #464646. Brand and status text keep more of their color on dark and tinted surfaces.

Why?

Equal lightness increments can look uneven. When body text and headings share the strongest foreground, there is little room to distinguish a heading or an active control from the surrounding text.

How?

The generator uses OKLr lightness for surfaces, perceptual color differences for strokes, and APCA for foreground spacing. It checks the configured WCAG floors against the final sRGB colors. The neutral strong-content token maps to the new step and is checked against all three neutral surfaces. Text heading variants, static editor and panel headings, and overlay titles use it. The WidgetRender identity example pairs its caption with the info surface. Applying opacity to the new neutral text color had dropped the caption to 4.49:1. The paired color measures 4.91:1 in the light theme.

Near black or white, sRGB has little room for chroma. If accent text used the same contrast target as neutral body text, brand and status text would turn almost white on dark surfaces. So the fourth step stops short of its preferred contrast when it would keep less than 80% of the highest chroma available above its minimum. Gray paths have almost no chroma, so neutral text keeps its preferred contrast. WCAG floors and the weak-to-normal gap still apply. On mid-tone surfaces such as Coffee, Blue, and Sunrise, the gap leaves no room, so their resting brand text stays pale.

The branch builds on the pressed control and header colors from #86684, the saturated-surface and brand contrast fixes from #86614, and the Toolbar, Widgets, and Customizer changes from #84573. The active-fill fix for #81162 landed in #82542, and the default-ramp build-order fix landed in #82525.

Independent drafts targeting trunk

#87427, #87428, and #87429 apply cleanly together on trunk at ff082402202. #87426 now conflicts with trunk in packages/editor/CHANGELOG.md. When rebasing this PR after #87426, keep the strong color on the inspector and complementary-area headings. If #87429 lands, retain its two fill aliases and regenerate the token fallbacks.

#87453, which colors the current Site Editor v2 sidebar item with the resting brand color, landed on trunk. The heading token and its consumers are part of this PR. #87424 was closed because they depend on the new foreground step. #82528 (skip unused accent outputs) and #81088 (ItemGroup theming) remain follow-ups for after this PR.

Testing Instructions

  1. In Storybook, open Design System → Theme → Foreground Emphasis → Comparison. Compare the heading, body text, and supporting text across the light, dark, and Ectoplasm samples. Open a Dialog or Popover and compare its title with its description.
  2. Open Design System → Theme → Theme Provider → Color Scales → Sample Combinations. Compare the surfaces, foreground steps, and reported contrast warnings. In Default, try #ffffff, #fefefe, #000000, and #010101 as backgrounds.
  3. Open the Button and Skeleton stories. Switch between light and dark themes. Check the labels, control states, and Skeleton against each background.
  4. With the gutenberg-extensible-site-editor experiment enabled, open Appearance → Design with the Ectoplasm or Modern admin color scheme. In the sidebar, check that the current item keeps a visible brand tint and that a hovered item has more contrast than the current one.

Testing Instructions for Keyboard

Tab through the controls in Foreground Emphasis → Comparison. Use the arrow keys to change tabs. In the Button stories, press Space or Enter and compare the focused, pressed, and resting states.

Screenshots

After shows this PR at 83e58fefdf2. The sidebar and Pages screen captures compare it with trunk at ff082402202, which includes #87453. The other Before images show trunk at 0ca9dc73d8c. Since then, trunk has not changed the theme, UI, or components packages.

The first three comparisons use the tokens that ThemeProvider generates for each admin color scheme, rendered as plain HTML.

Brand links

Each cell shows the neutral surface, a heading, body text, and a brand link at rest and on hover.

Before After
Trunk brand links at rest and on hover in every admin color scheme PR brand links at rest and on hover in every admin color scheme

Status text

Error, warning, info, and success text with its weak variant.

Before After
Trunk status text and weak status text in every admin color scheme PR status text and weak status text in every admin color scheme

Small panel

A heading, body text with a link, supporting text, an outline brand Button at rest and on hover, and an error notice.

Before After
Trunk panel recap in six color schemes PR panel recap in six color schemes

Generated colors

Headings and body text share a color on trunk in all three themes. This PR gives them separate colors. The bottom row shows how the same #777777 seed produces a lighter base surface on trunk and a darker one on this branch.

Before After
Trunk foreground swatches in Light, Dark and Ectoplasm and surfaces generated from mid-gray PR foreground swatches in Light, Dark and Ectoplasm and surfaces generated from mid-gray
Site Editor v2 sidebar in every admin color scheme

Each capture shows the Pages screen. Pages is the current item, the pointer hovers Templates, and the other items are at rest. The labels show the measured text colors. Since #87453, both trunk and this PR use the resting brand color for the current item and the active brand color for hover. This PR changes the colors those tokens produce: the current item gets more contrast, and hover moves toward black or white.

Before After
Ectoplasm on trunk: current Pages #B8C290, hovered Templates #EDF7C3 Ectoplasm on this PR: current Pages #E7F5AB, hovered Templates #FDFEF9
Light on trunk: current Pages #0069A6, hovered Templates #002041 Light on this PR: current Pages #004063, hovered Templates #001424

Other admin color schemes

On Coffee, Blue, and Sunrise, the current item is paler on this PR than on trunk. Their mid-tone surfaces leave little contrast range between weak and normal text, as described in How?.

Before After
Modern on trunk: current Pages #8FB0FF, hovered Templates #E4F0FF Modern on this PR: current Pages #9EB8FC, hovered Templates #FDFEFF
Default (Fresh) on trunk: current Pages #5EBEFF, hovered Templates #D5F5FF Default (Fresh) on this PR: current Pages #75C5FE, hovered Templates #FCFEFF
Midnight on trunk: current Pages #FF9788, hovered Templates #FFE6E0 Midnight on this PR: current Pages #F9C7C0, hovered Templates #FFFDFD
Coffee on trunk: current Pages #F5C6A1, hovered Templates #FFE8CC Coffee on this PR: current Pages #F5ECE6, hovered Templates #FEFDFD
Ocean on trunk: current Pages #B3D9B4, hovered Templates #D5FDD7 Ocean on this PR: current Pages #D7EED8, hovered Templates #FDFEFD
Blue on trunk: current Pages #9CD6FF, hovered Templates #D8F4FF Blue on this PR: current Pages #E5EFF9, hovered Templates #FDFEFE
Sunrise on trunk: current Pages #FFC48E, hovered Templates #FFE8CD Sunrise on this PR: current Pages #FAEBE1, hovered Templates #FFFDFC

Full Pages screen in Ectoplasm

Before After
Trunk Pages screen in Ectoplasm with About selected PR Pages screen in Ectoplasm with About selected
Button examples in light and dark themes

Captured from Design System → Components → Button → All Tones And Variants in Storybook. In the light theme, the neutral minimal Button label is #1E1E1E at rest and on hover on trunk. On this branch it changes from #464646 at rest to #141414 on hover. In the dark theme, the brand outline label at rest is #8EB0FF on trunk and #98B4FC on this branch.

Before After
Trunk brand outline and neutral minimal Buttons at rest, on hover and disabled in light and dark themes PR brand outline and neutral minimal Buttons at rest, on hover and disabled in light and dark themes
Rename dialog in the v2 Pages screen

The dialog title and the Name label are both #1E1E1E on trunk. On this branch the title is #141414 and the label is #404040. Cancel has keyboard focus in both captures.

Before After
Trunk Rename dialog with About in the Name field and keyboard focus on Cancel PR Rename dialog with About in the Name field and keyboard focus on Cancel

Performance

Uncached generation of one background and six accent ramps took 4.53 ms on trunk and 19.14 ms on this branch, an increase of 14.61 ms (4.23×). Most of the increase comes from the perceptual placement. The chroma check adds about 5 ms of it. ThemeProvider memoizes the result. This measures the cost of generating a new palette.

Operation Trunk 0ca9dc73d8c This PR
Background ramp 0.285 ms 0.803 ms
Primary accent with a prepared background 1.644 ms 3.764 ms
Complete uncached theme 4.529 ms 19.137 ms

Measured with Node v24.20.0 on macOS arm64. Six alternating pairs of fresh processes ran eight warmups and 30 measured iterations each. Each iteration averaged the default light, default dark, and Ectoplasm fixtures. The table reports the median of the six process medians.

Use of AI Tools

OpenAI Codex helped implement the algorithm and tests, rebase the work, extract the independent changes, and update the benchmark and Storybook screenshots. Claude Code added the chroma check, extracted the sidebar change into #87453, rebased the branch, and captured the current screenshots and benchmark.

@github-actions github-actions Bot added [Package] Base styles /packages/base-styles [Package] Theme /packages/theme labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: hi0001234d <emptyopssphere@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +7.51 kB (+0.09%)

Total Size: 8.73 MB

📦 View Changed
Filename Size Change
build/modules/boot/index.min.js 51.8 kB +43 B (+0.08%)
build/modules/core-fields/attachment.min.js 44.3 kB +42 B (+0.09%)
build/modules/core-fields/page.min.js 7.2 kB +42 B (+0.59%)
build/modules/core-fields/post_type_supports.min.js 82.1 kB +13 B (+0.02%)
build/modules/core-fields/wp_block.min.js 32.9 kB +2 B (+0.01%)
build/modules/core-fields/wp_template_part.min.js 39.5 kB +5 B (+0.01%)
build/modules/workflow/index.min.js 42.3 kB +17 B (+0.04%)
build/scripts/block-directory/index.min.js 42.6 kB +42 B (+0.1%)
build/scripts/block-editor/index.min.js 562 kB +66 B (+0.01%)
build/scripts/block-library/index.min.js 429 kB +20 B (0%)
build/scripts/components/index.min.js 356 kB +78 B (+0.02%)
build/scripts/customize-widgets/index.min.js 22.9 kB +33 B (+0.14%)
build/scripts/edit-post/index.min.js 45.2 kB +4 B (+0.01%)
build/scripts/edit-site/index.min.js 384 kB +93 B (+0.02%)
build/scripts/edit-widgets/index.min.js 29.2 kB +81 B (+0.28%)
build/scripts/editor/index.min.js 575 kB +39 B (+0.01%)
build/scripts/format-library/index.min.js 73.4 kB +13 B (+0.02%)
build/scripts/media-utils/index.min.js 238 kB +82 B (+0.03%)
build/scripts/notices/index.min.js 48 kB +61 B (+0.13%)
build/scripts/patterns/index.min.js 12.6 kB +46 B (+0.37%)
build/scripts/theme/index.min.js 34.6 kB +5.83 kB (+20.26%) 🚨
build/scripts/widgets/index.min.js 65.1 kB +17 B (+0.03%)
build/styles/block-editor/style-rtl.css 20.3 kB +27 B (+0.13%)
build/styles/block-editor/style-rtl.min.css 17.2 kB +26 B (+0.15%)
build/styles/block-editor/style.css 20.4 kB +28 B (+0.14%)
build/styles/block-editor/style.min.css 17.2 kB +26 B (+0.15%)
build/styles/block-library/editor-rtl.css 12.9 kB +1 B (+0.01%)
build/styles/block-library/editor-rtl.min.css 10.6 kB +1 B (+0.01%)
build/styles/block-library/editor.css 13 kB +1 B (+0.01%)
build/styles/block-library/icon/editor-rtl.min.css 586 B +1 B (+0.17%)
build/styles/block-library/query/editor-rtl.css 1.47 kB +1 B (+0.07%)
build/styles/block-library/query/editor-rtl.min.css 540 B +1 B (+0.19%)
build/styles/block-library/query/editor.css 1.47 kB +1 B (+0.07%)
build/styles/block-library/query/editor.min.css 540 B +1 B (+0.19%)
build/styles/components/style-rtl.css 18.6 kB +44 B (+0.24%)
build/styles/components/style-rtl.min.css 15.7 kB +33 B (+0.21%)
build/styles/components/style.css 18.6 kB +44 B (+0.24%)
build/styles/components/style.min.css 15.7 kB +32 B (+0.2%)
build/styles/edit-site/style-rtl.css 21.4 kB +38 B (+0.18%)
build/styles/edit-site/style-rtl.min.css 17.3 kB +45 B (+0.26%)
build/styles/edit-site/style.css 21.4 kB +40 B (+0.19%)
build/styles/edit-site/style.min.css 17.3 kB +43 B (+0.25%)
build/styles/edit-widgets/style-rtl.css 5.48 kB +20 B (+0.37%)
build/styles/edit-widgets/style-rtl.min.css 4.06 kB +18 B (+0.44%)
build/styles/edit-widgets/style.css 5.47 kB +18 B (+0.33%)
build/styles/edit-widgets/style.min.css 4.06 kB +17 B (+0.42%)
build/styles/editor/style-rtl.css 32.3 kB +49 B (+0.15%)
build/styles/editor/style-rtl.min.css 27.9 kB +34 B (+0.12%)
build/styles/editor/style.css 32.4 kB +49 B (+0.15%)
build/styles/editor/style.min.css 27.9 kB +33 B (+0.12%)
build/styles/theme/design-tokens-rtl.css 3.36 kB +53 B (+1.6%)
build/styles/theme/design-tokens-rtl.min.css 1.61 kB +35 B (+2.22%)
build/styles/theme/design-tokens.css 3.36 kB +53 B (+1.6%)
build/styles/theme/design-tokens.min.css 1.61 kB +35 B (+2.22%)

83e58fe Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 07a1447 trunk % Change
timeToFirstByte 50.9 ms +5.5% -1.77% 50.3 ms +10.14% -2.49% 1.19%
largestContentfulPaint 84 ms +4.76% -4.76% 80 ms +5% -5% 5%
lcpMinusTtfb 33.45 ms +11.81% -12.26% 27.5 ms +5.45% -3.27% 21.64%
wpBeforeTemplate 25.14 ms +6.8% -1.71% 24.92 ms +10.11% -1.69% 0.88%
wpTemplate 21.52 ms +2.46% -5.2% 21.14 ms +1.47% -3.36% 1.8%
wpTotal 46.86 ms +5.55% -2.11% 46.39 ms +8.15% -2.35% 1.01%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 07a1447 trunk % Change
timeToFirstByte 42.5 ms +2.59% -1.65% 40.85 ms +4.41% -1.35% 4.04%
largestContentfulPaint 76 ms +0% -0% 76 ms +0% -0% 0%
lcpMinusTtfb 33.65 ms +3.12% -2.38% 35.2 ms +2.56% -5.26% -4.4%
wpBeforeTemplate 22.11 ms +6.74% -2.04% 21.83 ms +3.89% -1.97% 1.28%
wpTemplate 16.54 ms +2.96% -4.41% 15.62 ms +3.71% -2.5% 5.89%
wpTotal 39.12 ms +2.35% -1.99% 37.5 ms +4.51% -1.47% 4.32%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 07a1447 trunk % Change
mediaProcessingJpeg 401.56 ms +0.95% -0.37% 399.6 ms +1.79% -0.26% 0.49%
mediaProcessingAvif 5850.55 ms +0.89% -0.01% 5869.67 ms +0.21% -0.12% -0.33%
mediaProcessingJpegToAvif 4013.34 ms +0.21% -0.34% 4011.05 ms +0.36% -0.04% 0.06%

media-upload

Metric 07a1447 trunk % Change
jpegUploadProcessing 1495.98 ms +35.62% -1.16% 1508.48 ms +0.85% -1.53% -0.83%
pngUploadProcessing 254.34 ms +0.92% -3.02% 251.89 ms +1.66% -1.21% 0.97%
largeJpegUploadProcessing 1489 ms +0.9% -0.91% 1485.19 ms +1.24% -0.49% 0.26%
multipleImageUploadProcessing 2058.27 ms +0.71% -4.95% 2045.21 ms +1.88% -3.91% 0.64%

post-editor

Metric 07a1447 trunk % Change
serverResponse 495.62 ms +2.16% -9.68% 480.74 ms +3.45% -8.92% 3.1%
firstPaint 458.27 ms +3.8% -7.07% 423.34 ms +6.98% -7.93% 8.25%
domContentLoaded 872.18 ms +1.64% -2.59% 818.33 ms +0.99% -1.13% 6.58%
loaded 873.3 ms +1.65% -2.58% 819.22 ms +1.01% -1.1% 6.6%
firstContentfulPaint 485.77 ms +7.88% -2.08% 462.51 ms +1.88% -2.08% 5.03%
firstBlock 2315.7 ms +0.61% -0.83% 2227.74 ms +0.59% -1.19% 3.95%
type 17.46 ms +4.3% -3.32% 18.05 ms +4.32% -4.04% -3.27%
typeWithoutInspector 17.34 ms +12.28% -12.63% 18.2 ms +4.12% -18.63% -4.73%
typeWithTopToolbar 25.57 ms +4.26% -7.59% 22.46 ms +7.03% -2.8% 13.85%
typeContainer 8.75 ms +22.4% -24.57% 8.14 ms +4.79% -11.3% 7.49%
focus 118.96 ms +2.49% -7.36% 111.89 ms +9.25% -8.91% 6.32%
firstFocus 263.39 ms +0% -0% 274.31 ms +0% -0% -3.98%
selectAll 411.59 ms +2.28% -2.31% 423.44 ms +2.71% -5.86% -2.8%
undo 29.42 ms +2.07% -4.45% 29.11 ms +3.64% -10.2% 1.06%
listViewOpen 36.81 ms +12.66% -1.66% 39.94 ms +2.63% -4.43% -7.84%
inserterOpen 42.7 ms +9.37% -13.75% 40.86 ms +11.5% -10.62% 4.5%
inserterHover 11.17 ms +5.01% -14.41% 11.23 ms +2.32% -6.86% -0.53%
inserterSearch 8.33 ms +3.36% -8.76% 8.12 ms +2.22% -5.79% 2.59%
loadPatterns 620.78 ms +7.69% -3.21% 656.42 ms +5.08% -4.51% -5.43%
wpTotal 485.95 ms +1.94% -9.88% 470.93 ms +3.33% -9.07% 3.19%
wpMemoryUsage 14.81 MB +0% -0% 14.76 MB +0% -0% 0.33%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 07a1447 trunk % Change
serverResponse 303.35 ms +5.4% -6.68% 319.79 ms +1.83% -1.57% -5.14%
firstPaint 310.22 ms +26.48% -7.12% 320.51 ms +14.94% -3.19% -3.21%
domContentLoaded 658.96 ms +1.92% -1.95% 663.83 ms +0.76% -1.13% -0.73%
loaded 659.76 ms +1.92% -1.95% 664.65 ms +0.76% -1.14% -0.74%
firstContentfulPaint 373.52 ms +5.05% -1.78% 373.05 ms +1.16% -1.25% 0.13%
firstBlock 2038.12 ms +4.68% -1.13% 2053.47 ms +0.84% -1.3% -0.75%
type 14.82 ms +1.82% -4.45% 14.54 ms +4.68% -5.98% 1.93%
navigate 85.83 ms +7.56% -1.08% 96.1 ms +7.87% -8.57% -10.69%
loadPatterns 1094.08 ms +11.62% -14.21% 1103.31 ms +9.5% -11.64% -0.84%
loadPages 982.08 ms +2.06% -6.44% 1012.01 ms +1.42% -3.19% -2.96%
wpTotal 294.96 ms +5.57% -6.84% 311.44 ms +1.77% -1.64% -5.29%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

83e58fe Run

🏁 Flaky tests

Some 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.

returns focus to the item's Options after adding a submenu link in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('treegrid', { name: 'Block navigation structure' }).getByRole('row', { name: 'Existing Item' }).getByRole('button', { name: 'Options' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('treegrid', { name: 'Block navigation structure' }).getByRole('row', { name: 'Existing Item' }).getByRole('button', { name: 'Options' }) with timeout 5000ms
  - waiting for getByRole('treegrid', { name: 'Block navigation structure' }).getByRole('row', { name: 'Existing Item' }).getByRole('button', { name: 'Options' })

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:492:34
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:486:3

83e58fe Run

@ciampo ciampo self-assigned this Sep 1, 2026
@ciampo
ciampo force-pushed the codex/theme-anchored-foreground-scale branch 4 times, most recently from 07a2661 to 4bb53ec Compare September 2, 2026 23:36
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review.

Walkthrough

Theme color-ramp generation now rebuilds surfaces, strokes, and foreground scales with perceptual and contrast constraints. Accent ramps support semantic purposes. ThemeProvider integration, generated token assets, fallbacks, documentation, examples, and regression tests were updated.

Changes: Color ramp generation

Layer / File(s) Summary
Ramp contracts and shared constraints
packages/theme/src/color-ramps/lib/*
Ramp types and configurations now separate base steps from foreground scales. Contrast references support additional dependencies. Color utilities register spaces lazily, and taper-chroma caching uses exact per-space keys.
Perceptual ramp reconstruction and purpose selection
packages/theme/src/color-ramps/index.ts, packages/theme/src/color-ramps/lib/index.ts, packages/theme/src/color-ramps/lib/build-foreground-scale.ts, packages/theme/src/color-ramps/lib/build-perceptual-steps.ts
Background polarity selection, surface and stroke rebuilding, APCA/WCAG foreground solving, lazy strong-color calculation, and full, interactive, and status accent outputs were added.
Theme integration and generated token outputs
packages/theme/src/use-theme-provider-styles.ts, packages/theme/src/theme-provider-color-warnings.ts, packages/theme/tokens/color.json, packages/theme/prebuilt/*, packages/base-styles/internal/_wpds-token-fallbacks.scss, packages/theme/package.json
ThemeProvider now generates purpose-specific accent ramps. Primitive tokens, aliases, CSS assets, JavaScript fallbacks, SCSS fallbacks, and build ordering were updated.
Ramp validation and examples
packages/theme/src/color-ramps/test/*, packages/theme/src/test/*, packages/theme/src/color-ramps/stories/*, storybook/stories/design-system/*
Tests cover contrast, polarity, spacing, serialization, cache isolation, color-space registration, purpose-specific output, and ThemeProvider rerenders. Example theme colors and ramp previews were updated.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ThemeProvider
  participant buildBgRamp
  participant buildRamp
  participant buildPerceptualSteps
  participant buildForegroundScale
  participant colorTokensCSS
  ThemeProvider->>buildBgRamp: build background ramp
  ThemeProvider->>buildRamp: build purpose-specific accent ramp
  buildRamp->>buildPerceptualSteps: rebuild surfaces and strokes
  buildPerceptualSteps->>buildForegroundScale: solve foreground scale
  buildRamp-->>ThemeProvider: return typed ramp result
  ThemeProvider->>colorTokensCSS: generate CSS tokens and fallbacks
Loading

Suggested reviewers: aduth

Merge Risk: Minimal · up to 06682

Theme color scales now provide perceptually balanced text and interaction colors while retaining contrast constraints. No concrete merge-blocking behavior or production risk is identified in the supplied current-head evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed The changes address both linked issues. For [#81162], the new foreground-scale, active-fill, multi-reference contrast checks, and regression tests enforce contrast for active semantic pairs while pres…
Out of Scope Changes check Passed The implementation, generated outputs, documentation, changelog updates, and tests support the color-scale, contrast, and interactive-state objectives. No unrelated code changes are evident.
Title check Passed The title "Theme: Generate perceptually balanced color ramps" matches the main change in the changeset. The PR rebuilds color ramps with perceptual lightness (OKLr), perceptual stroke differences, and…
Description check Passed The description is specific and related to the changeset. It states the goal of generating more evenly spaced color ramps across themes and the new fifth foreground step. It names the affected tokens …
Full details: Linked Issues check

Explanation

The changes address both linked issues. For [#81162], the new foreground-scale, active-fill, multi-reference contrast checks, and regression tests enforce contrast for active semantic pairs while preserving seeds when possible. For [#77153], interactive ramp purposes and stronger foreground steps produce distinct active values, with dedicated tests covering this behavior.

Full details: Title check

Explanation

The title "Theme: Generate perceptually balanced color ramps" matches the main change in the changeset. The PR rebuilds color ramps with perceptual lightness (OKLr), perceptual stroke differences, and APCA-based foreground steps. The new build-perceptual-steps.ts and build-foreground-scale.ts modules and the regenerated default ramps and tokens all support this. The title is specific and concise.

Full details: Description check

Explanation

The description is specific and related to the changeset. It states the goal of generating more evenly spaced color ramps across themes and the new fifth foreground step. It names the affected tokens (neutral strong-content token, heading variants, overlay titles) and the generator approach (OKLr lightness, perceptual stroke differences, APCA foreground spacing, WCAG floors). It also covers testing steps, screenshots, and a benchmark table, all of which match the summarized theme, ramp, and test changes.

Finishing Touches

🧪 Generate unit tests (beta)

  • Create PR with unit tests
  • Commit unit tests in branch codex/theme-anchored-foreground-scale
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

ℹ️ Recent review info

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: c5070a1b-9313-4f26-9df9-dbe8d16a14f3

📥 Commits

Reviewing files that changed from the base of the PR and between 2abea89 and 06682eb.

📒 Files selected for processing (3)

  • packages/theme/src/color-ramps/lib/build-foreground-scale.ts
  • packages/theme/src/color-ramps/lib/color-utils.ts
  • packages/theme/src/color-ramps/test/color-space-registration.test.ts
💤 Files with no reviewable changes (1)

  • packages/theme/src/color-ramps/test/color-space-registration.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Sep 3, 2026
@ciampo
ciampo marked this pull request as ready for review September 3, 2026 11:22
@ciampo
ciampo requested a review from a team as a code owner September 3, 2026 11:22
@ciampo
ciampo requested review from a team and fushar September 3, 2026 11:27
@ciampo ciampo changed the title Theme: Use a perceptual five-step foreground scale Theme: Perceptually balanced color scales Sep 3, 2026
@mirka

mirka commented Sep 3, 2026

Copy link
Copy Markdown
Member

One warning about the video in the PR description — the ItemGroup in the site editor sidebar (or just real Gutenberg UIs in general) are not always a good place to judge the overall theming validity, because so many parts of it are not yet properly themed, or ad hoc overridden 😅

But regardless, I do definitely perceive the improvement here in the "perception parity" between light and dark scales 🎉

@jasmussen

Copy link
Copy Markdown
Contributor

This is a nice PR. It deserves more poring over than it might seem to need. For that reason, I wonder if it can wait until @jameskoster has a time to look?

@ciampo

ciampo commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Sure, let's wait for @jameskoster . It will be a nice way for him to dive back into DS / theming

Although I still reccomend y'all take this PR up for a spin and try out Storybook and Editor, to get a first intuiton of whether this overall feels good, and if there any obvious regressions.

@ciampo
ciampo force-pushed the codex/theme-anchored-foreground-scale branch from 06682eb to cbf1909 Compare September 7, 2026 09:45
@ciampo ciampo changed the title Theme: Perceptually balanced color scales Theme: Generate perceptually balanced color ramps Sep 7, 2026
@ciampo
ciampo force-pushed the codex/theme-anchored-foreground-scale branch from 5765f76 to f3d4a2a Compare November 25, 2026 23:43
@ciampo
ciampo requested a review from spacedmonkey as a code owner November 25, 2026 23:43
@github-actions github-actions Bot removed [Package] Editor /packages/editor [Package] Block editor /packages/block-editor [Package] Edit Widgets /packages/edit-widgets [Package] Interface /packages/interface [Package] UI /packages/ui labels Nov 25, 2026
@github-actions
github-actions Bot requested a review from aduth November 25, 2026 23:44
@github-actions github-actions Bot added [Package] Block editor /packages/block-editor [Package] Interface /packages/interface [Package] UI /packages/ui labels Nov 25, 2026
@ciampo
ciampo requested a review from retrofox as a code owner November 26, 2026 00:11
@github-actions github-actions Bot added [Package] Widget primitives /packages/widget-primitives [Package] Boot /packages/boot labels Nov 26, 2026
ciampo and others added 6 commits November 26, 2026 11:38
Rebase the foreground, surface and stroke solvers onto trunk's primary contrast and background saturation changes. Keep the dark fill steps used by Switch and regenerate the theme tokens and admin color schemes.
Near black or white, sRGB has little room for chroma, so placing accent
FGS4 at the neutral body-text contrast washed brand and status text out
on dark and tinted surfaces. Stop FGS4 short of its preferred contrast
when it would keep less than 80% of the highest chroma available above
its minimum. Neutral paths stay below the chroma minimum, so gray text
keeps the preferred contrast. WCAG floors and the weak-to-normal gap
still apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chroma along one hue rises to a single cusp, so five samples and eight
refinement steps find the same resting brand colors. This cuts the cost
of the chroma-retention search from about 7.4 ms to 4.7 ms per theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ciampo
ciampo force-pushed the codex/theme-anchored-foreground-scale branch from 1dccd67 to 83e58fe Compare November 26, 2026 10:41
@github-actions github-actions Bot removed the [Package] Boot /packages/boot label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Base styles /packages/base-styles [Package] Block editor /packages/block-editor [Package] Components /packages/components [Package] Interface /packages/interface [Package] Theme Build Tools [Package] Theme /packages/theme [Package] UI /packages/ui [Package] Widget primitives /packages/widget-primitives [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Theme: Some color token values that should differ do not

5 participants