-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Theme: fix color ramp generation to avoid unmet contrasts #73331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
|
Size Change: -15 B (0%) Total Size: 2.49 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in e8bce5d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19411403142
|
jameskoster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
aduth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Couple side-observations:
- The "Sample Combinations" story shows some warnings, though it doesn't appear to have regressed (or made any better) with the changes here
- On your point about P3 -> hex conversions, would these potential inaccuracies extend to any of the internal P3 usage?
The two questions are related. Why are there warnings in the sample combinations story? One of the color ramps that fail is background ramp for WP Blue,
What does this chart show?
Now, this seed color has insufficient contrast against white. It's just 6.63, while We could get a darker color by changing (lowering) the chroma C, by making the color less blue and more gray/black. That's what the
The only other internal usage of P3 is in |

Several tweaks to the color ramp generation algorithm that ensure that contrast targets are always reliably met.
@aduth reported that the Storybook color scales story reports unmet contrast targets:
The real contrasts are not 4.5 and 3.0 but only 4.47 and 2.99, respectively. I'm addressing the reason why these slight mismatches happen.
I'm also making adjustments to the
stroke1andstroke2target contrasts that @jameskoster proposed recently. They are quite unrelated, but not entirely: this PR changes the generated colors in three distinct ways, and I wanted to see the entire effect of all three changes together.Change number 1: change
clampToGamutto use the sRGB color space instead of P3. When we generate a color, we eventually store it in the RGB hex format, like#c8ba80. As part of this formatting, colors that are outside the sRGB gamut are automatically mapped to sRGB, otherwise they couldn't be expressed in the hex format. Here it can happen that two colors that previously had sufficient contrast in a wide-gamut space (like P3), have a slightly lower contrast after the sRGB conversion. That's one way how the contrast target could be missed. WithclampToGamutconverting to sRGB, we use sRGB colors during the actual color search and its contrast checks.I'm also moving
clampToGamutto the color-utils.ts file, as that's a nicer place for the function.Change number 2: Increase the "contrast topup" from 0.012 to 0.02. It's a safer value for edge cases when the lighter color is rounded down, to a slightly darker color, and the darker color is rounded up, to a slightly lighter color. Then the contrast can have as big as a 0.016 difference. This was another reason why target contrasts were missed sometimes.
Change number 3: Apply @jameskoster's suggestion to change contrast targets for
stroke1andstroke2, so that the two colors are less prominent against the background surface. If these changes were applied alone, then for the default background ramp (#f8f8f8seed) thestroke1andstroke2colors were#e1e1e1and#d8d8d8. When all three tweaks in this PR are applied together, the colors are#e0e0e0and#d8d8d8. A minimal difference. This difference I what I wanted to see, and verify that the other two changes don't change the colors substantially.How to test: In Storybook, look at the
/story/design-system-theme-provider-color-scales--defaultstory, and verify that the contrast mismatch warnings are gone.