Skip to content

postcss-gamut-mapping #1144

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

Merged
merged 17 commits into from
Oct 9, 2023

Conversation

romainmenke
Copy link
Member

@romainmenke romainmenke commented Oct 8, 2023

fixes : #1049

p {
	background-color: oklch(80% 0.05 0.39 / 0.5);
	color: oklch(20% 0.234 0.39 / 0.5);
	border-color: color(display-p3 0 1 0);
}

/* becomes */

p {
	background-color: oklch(80% 0.05 0.39 / 0.5);
	color: rgba(50, 0, 20, 0.5);
	border-color: rgb(0, 249, 66);
}

@media (color-gamut: rec2020) {
p {
	color: oklch(20% 0.234 0.39 / 0.5);
}
}

@media (color-gamut: p3) {
p {
	border-color: color(display-p3 0 1 0);
}
}

This does not "fix" massively out of gamut source colors so that they fit within display-p3 or rec2020. Only a single srgb fallback is provided.

Providing fallbacks for each wide gamut option would be slow and would needlessly bloat the output.

I am making the assumption that authors have the tools to choose and write colors that fit within either display-p3 or rec2020 and that it is sufficient to provide an srgb fallback so that clipping is avoided. Clipping is the most harmful effect as it radically alters the color, away from the intention of the author.

I don't think we need to provide a tool to enforce that wide gamut colors are real colors or that these fit within rec2020. Linters are better suited to that specific task.

rec2020 is currently the widest gamut expected to be supported by displays. Authoring colors that do not fit within rec2020 doesn't make sense today. The chance that hardware beyond rec2020 will become wide spread before browsers ship gamut mapping is small. If that happens we can adjust how this plugin works.


This also better integrates postcss-progressive-custom-properties into postcss-preset-env.

It is now part of the determined plugin order.

There will be some duplication in the output if a source requires many transforms.
The current form is the best balance between duplicate/redundant output and complexity in multiple plugins.

The only way to reduce duplication further is by bringing both gamut mapping fallbacks and progressive props to each and every plugin that might be related to colors. I don't see the point in doing that. A little bit of duplication is short term cost, eventually users will require fewer fallbacks.

@romainmenke romainmenke changed the title postcss-progressive-color-gamut postcss-gamut-mapping Oct 8, 2023
@romainmenke romainmenke marked this pull request as ready for review October 8, 2023 17:46
@Antonio-Laguna Antonio-Laguna self-requested a review October 9, 2023 10:00
Copy link
Member

@Antonio-Laguna Antonio-Laguna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romainmenke this looks great to me! Left a few minor questions but great to go!

@romainmenke romainmenke merged commit 6b0dd12 into main Oct 9, 2023
@romainmenke romainmenke deleted the progressive-color-gamut--practical-dodo-be5d547194 branch October 9, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment