Repository navigation
Theme: Carry near-gray seed tints into generated neutral tokens - #86052
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @yaman-694! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 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 |
|
Hello, and thank you for working on this! This looks like a viable solution to improve on the abrupt near-gray cutoff. It also fits with the perceptual-scale work in #82294 and the foreground experiments in #82037, which retain the neutral chroma taper. Could you add before-and-after comparisons (screenshots) for a few example color ramps? Especially the ones you mentioned (modern, light)? Maybe you could use this storybook example. Separately, can you also add a Theme changelog entry? Thank you 🙏 |
|
Hi @ciampo added the screenshot and Changelog |
|
Thank you, the screenshots definitely help with getting a sense for the changes. In general, I think that the PR is currently adding too much of the seed's chroma into the remp. Light's generated neutral surfaces reach about five times the seed's chroma, which makes the ramp look noticeably greener than the seed. Could we carry its hue while keeping the neutral ramp closer to the seed's chroma? If this issue is specific to neutral scales, the brand and other accent ramps should retain their existing treatment. The experimental diff below reproduces the subtler seed-bounded result for neutral ramps while leaving the accent algorithm unchanged. Proposed experiment and diffThis adds an internal option to bound chroma by the seed's chroma after applying the existing taper. It enables that option only for the background ramp. The contrast solver and gamut mapping stay in place. Against diff --git a/packages/theme/src/color-ramps/lib/taper-chroma.ts b/packages/theme/src/color-ramps/lib/taper-chroma.ts
--- a/packages/theme/src/color-ramps/lib/taper-chroma.ts
+++ b/packages/theme/src/color-ramps/lib/taper-chroma.ts
@@ -16,6 +16,7 @@
radiusDark?: number; // distance in L where kDark is reached (default 0.20)
kLight?: number; // floor multiplier near lighter side (default 0.85)
kDark?: number; // floor multiplier near darker side (default 0.85)
+ limitToSeedChroma?: boolean; // keep neutral chroma at or below the tapered seed chroma
// Near-gray handling: cap C at C_seed * nearGrayChromaRatio * (1 + (C_seed / nearGrayChroma)²)
nearGrayChromaRatio?: number; // cap multiplier for a near-gray seed (default 4)
nearGrayChroma?: number; // seed C above which the cap quickly stops binding (default 0.005)
@@ -105,7 +106,10 @@
kLight,
kDark,
} );
- const cPlanned = Math.min( cWithCarry * t, cCap );
+ const cPlanned = Math.min(
+ cWithCarry * t,
+ options.limitToSeedChroma ? cSeed * t : cCap
+ );
// Downward-only clamp (preserve L & H)
const lOut = clamp01( lTarget );
diff --git a/packages/theme/src/color-ramps/lib/ramp-configs.ts b/packages/theme/src/color-ramps/lib/ramp-configs.ts
--- a/packages/theme/src/color-ramps/lib/ramp-configs.ts
+++ b/packages/theme/src/color-ramps/lib/ramp-configs.ts
@@ -50,7 +50,7 @@
taperChromaOptions: FG_TAPER_CHROMA,
};
-export const BG_RAMP_CONFIG: RampConfig = {
+const BASE_RAMP_CONFIG: RampConfig = {
// Surface
surface1: {
contrast: {
@@ -231,37 +231,53 @@
},
};
+// Bound neutral ramps independently of the accent ramp's chroma treatment.
+export const BG_RAMP_CONFIG = Object.fromEntries(
+ Object.entries( BASE_RAMP_CONFIG ).map( ( [ stepName, step ] ) => [
+ stepName,
+ step.taperChromaOptions
+ ? {
+ ...step,
+ taperChromaOptions: {
+ ...step.taperChromaOptions,
+ limitToSeedChroma: true,
+ },
+ }
+ : step,
+ ] )
+) as RampConfig;
+
// BG_RAMP: seed => surface2 => {bgFill, surface3 => all other tokens}
// ACCENT_RAMP: seed => bgFill1 => surface2 => surface3 => all other tokens
export const ACCENT_RAMP_CONFIG: RampConfig = {
- ...BG_RAMP_CONFIG,
+ ...BASE_RAMP_CONFIG,
surface1: {
- ...BG_RAMP_CONFIG.surface1,
+ ...BASE_RAMP_CONFIG.surface1,
taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,
},
surface2: {
contrast: {
reference: 'bgFill1',
followDirection: 'opposite',
- target: BG_RAMP_CONFIG.bgFill1.contrast.target,
+ target: BASE_RAMP_CONFIG.bgFill1.contrast.target,
ignoreWhenAdjustingSeed: true,
},
taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,
},
surface3: {
- ...BG_RAMP_CONFIG.surface3,
+ ...BASE_RAMP_CONFIG.surface3,
taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,
},
surface4: {
- ...BG_RAMP_CONFIG.surface4,
+ ...BASE_RAMP_CONFIG.surface4,
taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,
},
surface5: {
- ...BG_RAMP_CONFIG.surface5,
+ ...BASE_RAMP_CONFIG.surface5,
taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,
},
surface6: {
- ...BG_RAMP_CONFIG.surface6,
+ ...BASE_RAMP_CONFIG.surface6,
taperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,
},
bgFill1: {
@@ -272,36 +288,36 @@
},
},
stroke1: {
- ...BG_RAMP_CONFIG.stroke1,
+ ...BASE_RAMP_CONFIG.stroke1,
},
stroke2: {
- ...BG_RAMP_CONFIG.stroke2,
+ ...BASE_RAMP_CONFIG.stroke2,
},
stroke3: {
- ...BG_RAMP_CONFIG.stroke3,
+ ...BASE_RAMP_CONFIG.stroke3,
sameAsIfPossible: 'fgSurface3',
taperChromaOptions: undefined,
},
stroke4: {
- ...BG_RAMP_CONFIG.stroke4,
+ ...BASE_RAMP_CONFIG.stroke4,
taperChromaOptions: undefined,
},
// fgSurface: do not de-saturate
fgSurface1: {
- ...BG_RAMP_CONFIG.fgSurface1,
+ ...BASE_RAMP_CONFIG.fgSurface1,
taperChromaOptions: undefined,
},
fgSurface2: {
- ...BG_RAMP_CONFIG.fgSurface2,
+ ...BASE_RAMP_CONFIG.fgSurface2,
taperChromaOptions: undefined,
},
fgSurface3: {
- ...BG_RAMP_CONFIG.fgSurface3,
+ ...BASE_RAMP_CONFIG.fgSurface3,
taperChromaOptions: undefined,
sameAsIfPossible: 'bgFill1',
},
fgSurface4: {
- ...BG_RAMP_CONFIG.fgSurface4,
- taperChromaOptions: undefined,
- },
-};
+ ...BASE_RAMP_CONFIG.fgSurface4,
+ taperChromaOptions: undefined,
+ },
+};WDYT ? |
|
Thanks @ciampo, I tried the diff locally and it matches what you described. The near-gray neutral steps now stay within about 1.0-1.2x of the seed chroma (Light was at ~5x before), the accent ramps are unchanged, and there are no new contrast warnings. One thing I noticed: since limitToSeedChroma applies to every background ramp, it also lowers the chroma of saturated background seeds, so all of the background ramp snapshots at lightness 10-90 change (for example, at L50 / H0, surface6 goes from #9a5859 to #8e5e5e). Is that intended? If so, I'll update the snapshots and note it in the changelog entry. If not, I can scope the bound to near-gray seeds only. I'll also rework the near-gray test as you suggested: assert chroma ≤ seed chroma instead of nonzero chroma, and check hue only on steps whose chroma survives 8-bit rounding.
|
|
Yeah, that broader desaturation isn't great. I decided to try an approach; I've merged trunk and replaced the global seed limit with a "softer ceiling" (quadratic) for background ramps, so near-gray seeds keep their subtle tint while richer backgrounds retain their previous treatment. Accent ramps keep their existing treatment too. I kept the saturated-surface changes and the missing 3:1 constraints separate in the stacked draft #86614, since those can change the generated primary color quite visibly. The soft quadratic ceiling is the third row. It allows chroma up to
What do you think? |
|
Thanks @ciampo, I like this approach a lot. I pulled your commit and ran the color-ramps tests (all 135 pass). I also compared all nine admin scheme backgrounds against trunk:
I think this is actually the consistent outcome: those schemes had the same over-tinting that made Light look too green, and now every near-gray scheme is treated the same way, with no jump around the old threshold. Leaving them as they were would mean a steep transition somewhere between C 0.005 and 0.007, which is the kind of discontinuity this PR set out to remove. Just flagging it since it goes beyond Modern and Light. Does that sound right to you (and maybe @jameskoster from the design side)? If so, I'll update the PR description: the before/after tables, the list of affected schemes, and the screenshots for the new ceiling. Happy to also look at #86614 once this lands. |
A background seed with an OKLCH chroma just under the 0.005 achromatic threshold, such as the "Modern" admin scheme's #222524, kept its tint on the base surface while every tapered step came out pure gray, so the two mixed on the same screen. Seeds either side of the threshold also gave visibly different ramps. Fade the carried chroma linearly to zero below the threshold instead of cutting it off, so a slight tint carries into every step in proportion. Seeds at or above the threshold and gray seeds are unchanged.
Fading the carried chroma below the old threshold still let the seed-relative normalization amplify imperceptible tints near the lightness extremes: #f6f7f9 (C 0.0029) produced strokes at C 0.032. Cap the carried chroma at a multiple of the seed's own chroma instead. The allowance grows quadratically with the seed chroma, so it only binds for near-gray seeds, keeps every ramp continuous and fades to gray as the seed does. This makes the achromatic threshold unnecessary, so remove it together with the unused hueFallback option.
…o generated surfaces and strokes
3323459 to
39b519e
Compare
ciampo
left a comment
There was a problem hiding this comment.
@yaman-694 I pushed a small and updated the PR description.
LGTM 🚀
Although let's see if anyone else from @WordPress/gutenberg-components wants to share any additional feedback.
|
I'll go ahead and merge, happy to address any additional feedback in follow-ups. |
…Press#86052) * Theme: Carry near-gray seed tints into generated neutral tokens A background seed with an OKLCH chroma just under the 0.005 achromatic threshold, such as the "Modern" admin scheme's #222524, kept its tint on the base surface while every tapered step came out pure gray, so the two mixed on the same screen. Seeds either side of the threshold also gave visibly different ramps. Fade the carried chroma linearly to zero below the threshold instead of cutting it off, so a slight tint carries into every step in proportion. Seeds at or above the threshold and gray seeds are unchanged. * Theme: Cap near-gray tints instead of fading them Fading the carried chroma below the old threshold still let the seed-relative normalization amplify imperceptible tints near the lightness extremes: #f6f7f9 (C 0.0029) produced strokes at C 0.032. Cap the carried chroma at a multiple of the seed's own chroma instead. The allowance grows quadratically with the seed chroma, so it only binds for near-gray seeds, keeps every ramp continuous and fades to gray as the seed does. This makes the achromatic threshold unnecessary, so remove it together with the unused hueFallback option. * Theme: Add changelog entry for near-gray seed tint fix * ThemeProvider: Ensure near-gray background seeds carry their tint into generated surfaces and strokes * Theme: Soften the near-gray chroma ceiling * Theme: Preserve accent ramps for near-gray primary colors --------- Co-authored-by: yaman-694 <yamanzyan@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: jameskoster <jameskoster@git.wordpress.org>





Closes #86038. Related contrast work is in #86614.
What?
Modern and Light now carry their background tint into the neutral surfaces and strokes generated by
ThemeProvider. Fresh, Midnight, and Coffee also change: their neutrals stay closer to the original background color. Blue, Ectoplasm, Ocean, and Sunrise produce the same background ramps as trunk.Why?
The old taper treated a color as gray when its OKLCH chroma fell below 0.005. Modern (
#222524) and Light (#eaeeed) both fall below that cutoff, so their base surface kept its tint while neighboring surfaces turned gray. Just above the cutoff, the taper could amplify a faint tint.How?
Tapered background steps now use a ceiling that grows with the seed's chroma. A faint tint stays close to the seed, and richer colors can use the existing taper. Accent ramps keep their existing behavior, including when a custom primary color is near gray.
Chroma ceiling and measured color changes
For seed chroma
C, the ceiling isC × (1 + (C / 0.02)²). The ramp applies it before rounding to 8-bit RGB. A very faint tint can still round to gray.#222524#2a2a2a#282b2a#eaeeed#f6f6f6#f3f8f6#25292b#263034#2a2f31#3d4042#3d464c#424547#5b534d#655448#61554cTesting Instructions
surface3in the background ramp against the table above. Compare the neutral surfaces and strokes with the screenshots.surface3is#3f5c64on both revisions.#222524and the background to#fcfcfc. Expand Color values. In the primary ramp,surface2is#f8f8f8andsurface6is#d1d1d1, matching trunk.Testing Instructions for Keyboard
Tab to Color values and press Enter to expand the table. Each swatch has a text value for comparison.
Screenshots or screencast
Each overview shows the input seed beside six neutral surface and stroke tokens rendered by
ThemeProvider. Modern and Light gain a faint tint. Fresh, Midnight, and Coffee move closer to their seeds.The full ramps below compare all 22 generated steps, with the names used in Storybook's Color values table. The input seed appears above each ramp. For Coffee, the seed is
#5b534d, while both revisions generate#59514bfor the base surface (surface2).Full background ramps for Modern and Light
Full background ramps for Fresh, Midnight, and Coffee
Near-white background, Ocean, and a near-gray primary
With the near-white seed
#fcfcfd, some steps pick up a faint tint whilesurface3still rounds to white. All 22 steps match trunk for the Ocean background and for#222524used as a primary color on#fcfcfc.Use of AI Tools
Codex assisted with the rebase, code review, accent-ramp fix, regression tests, screenshots, and this description.