-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support CSS Color Level 4 hwb/lab/lch/gray functions (and related adjustments) #2831
Comments
I'd definitely like to expand the set of built-in color functions, like we did for math functions in #851. Miriam, are you interested in writing up a proposal? |
Yeah, I'm happy to. I see a few potential issues right away, and I'd love your thoughts: Currently, The level 5 spec provides a clever solution with the relative colors syntax, defining adjustments inside the respective color functions ( Also: since no browsers support the new color formats, we're likely converting everything to sRGB for output. Since sRGB and CIE provide different color gamuts, that may not be a good long term solution, once CIE is supported in browsers. Do we need to plan ahead for that change in some way? |
Good questions! I think my first high-level response is another question: what's the benefit of providing LAB- and LCH-friendly functions if we can't accurately represent their color spaces? Does it even make sense to start adding those when we know we'll probably want to support them differently in the future? |
The main advantage is that values & adjustments in the CIE color space are perceptually uniform. So blue and yellow hues at the same chroma & lightness (in LCH) will look similarly bright to the eye, and provide similar contrast ratios against a background color. That's a big advantage for doing any sort of automated color management… assuming you stay in the rgb gamut. I think that conversion will likely still happen for most users even once browsers support CIE formats, because most monitors use sRGB for display. If that's true, the conversion would only become an issue for people designing for wide-gamut displays…? I could do a bit more research… |
ok, I have confirmation from Tab that it's a reasonable idea to do some conversion:
There's a lot of detail in the spec, including sample conversion functions. |
I'm not sure how safe it is for us to rely on "most monitors". Sass is generally pretty conservative with its polyfilling, for a couple reasons:
These factors make me want to avoid eagerly or silently converting colors to RGB. I think you're probably right that it's useful to do transformations and definitions in these color spaces, but we need to find a way to do that that will continue to make sense if wide-gamut colors become widespread. |
Yeah, I think we should not be adding these to the global namespace. But if we put them in the I'm thinking of them like the While there are several methods for handling out-of-gamut colors, it's clear (and defined in the CSS spec) that we should be using "relative-colorimetric" rendering. That doesn't leave much that we need to decide. At this point, I think if we can find a good method for calculating relative-colorimetric adjustments, I can finish putting together a proposal. |
|
I'm told by the editors of CSS Color level 4 that the best solution is to lock I've created a (rough, slow) demo of that approach. |
Ok, colors are complex. I think we can break this down a bit more, and take it a step at a time
|
Sorry for taking so long to come back to this.
Cordoning functions in a module is beneficial because it makes it less likely that we'll need to migrate away from those functions, but it doesn't really make it less painful if we do end up needing to migrate. I want to make sure (as much as possible) that any functions we add are future-proof in and of themselves, even if there's a reasonable migration path. I'm not saying there's no way it makes sense to fake wider gamuts in the short term, but whatever function names and syntax we come up with for doing so need to be able to do the same thing, and still be comprehensible, in a hypothetical future world where 99% of monitors and browsers support wide-gamut colors. If we end up in that world and Sass has a One possibility would be to define a function like
👍
Looking forward to reading your proposals!
My guess is that this is something we'll have to punt to render-time for the most part—it's unlikely that we'll be able to accurately resolve at least URLs in
Yeah, it would be cool to support this in Sass but also a LOT of work. |
This approach makes a lot of sense to me. Maybe
#2835 is ready for review, unless we want to consider adjusting it based on the broader discussion: like adding a I wonder if a solution like this could extend to existing formats like |
I don't like the idea of further muddying the distinction between color functions and color spaces. In my experience, conflating two similar ideas in the name of simplicity causes more confusion than being consistently clear about which type of name goes where.
Reviewed!
I really don't want to make color output formats super customizable. It adds overhead to the internal color representation and its behavior in compressed mode is either going to be frustrating to some people because it prefers the chosen format rather than the smallest format, or frustrating to others because it makes the opposite decision. |
It's also worth noting that the |
Should a separate issue be opened for the syntax mentioned above? The syntax is recommended by Mathias Bynens, but it's not possible to use it with Sass:
|
@glen-84 That syntax has been supported in Dart Sass since version 1.15.0. See the Sass documentation for details. |
Apologies, I have found #2564 and sass/libsass#2722. I guess CodePen is using LibSass. This is also true for some of my own projects. Thanks. |
Any movement on this? It would make implementing Material 3's tonal color palettes a breeze. |
@mirisuzanne is planning to start working on a design here in December. |
@nex3, @mirisuzanne Always nice when either of you two pop up in an issue. Usually means things are going to work eventually. @mirisuzanne I'm currently using blend to get pretttttty close to Material 3's tonal palettes, thanks! |
Although these are still in flux (largely due to CSS changing under our feet to some degree), it's been almost two years since we put them out for review initially so I think it's fair to say that the core principles are solid. See #2831
Although these are still in flux (largely due to CSS changing under our feet to some degree), it's been almost two years since we put them out for review initially so I think it's fair to say that the core principles are solid. See #2831
See sass/sass#2831 Co-authored-by: Miriam Suzanne <[email protected]>
See sass/sass#2831 Co-authored-by: Miriam Suzanne <[email protected]>
Due to Sass incompatibilities See: sass/sass#2831
Due to Sass incompatibilities See: sass/sass#2831
…ard (#10564) * Replace stylelint-config-recommended-scss with stylelint-config-standard-scss changelog: Internal, Build Tools, Replace stylelint-config-recommended-scss with stylelint-config-standard-scss * Disable color-function-notation Due to Sass incompatibilities See: sass/sass#2831 * Fix lint errors * Bump version to 5.0.0-beta.1 * Move reportNeedlessDisables into shared configuration
Not sure if this should be its own issue, but seems related given the timing and error message: 1.79.1 broke my team's SASS builds which are compiled through dartsass (via a .dart script, not the js port). The compilation runs fine on 1.78.0, and the error is related to color spaces. Our
Is what I'm seeing here likely a bug with 1.79.1 release or was there an intended breaking change? (in the second case there should be a major version bump instead of a minor one per semantic versioning, right?) |
Per Sass's backwards compatibility policy, we don't consider changes to stylesheets that already produced invalid CSS to be breaking changes that need a major semantic versioning release. If you're parsing the syntax @function color(...$args) {
@return #{color}(...$args);
} (Example) |
See Color Level 4
Having access to CIE colors/adjustments would be particularly useful for design systems, and it seems like we could provide the syntax in
sass:color
without waiting on browsers to support the CSS variant.When I say adjustments, I'm not referring to the new CSS color functions in Level 5. I think we need to wait for those to solidify. I'm thinking of something similar to, or extending,
color.adjust()
.The text was updated successfully, but these errors were encountered: