-
Notifications
You must be signed in to change notification settings - Fork 676
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
[css-color-5] Findings on SCSS function usage to inform direction of Color 5 #5782
Comments
It is super valuable to see what is being used in the wild, in a massive-scale project like the Web Almanac. Since native CSS does not yet have the color manipulation functionality, being able to reach back from the deployed CSS via sourcemaps to infer the original SCSS is the only way to get at this data. SCSS only has the ability to manipulate in HSL, so that should be borne in mid when comparing functionality. Quoting from the HSL section of Color 4:
(I d suggest following the link, because Color 4 also has worked examples that show the magnitude of that effect. It is not small). So, the In Color 5 we can approach that in various ways:
I need to read more on how exactly SCSS computes lighten and darken (is it a simple addition or subtraction, with clamp to keep the value in range, or is there a sigmoid function). I also see some criticism of
So that needs to be investigated. Mixing in white or black sounds like manipulation in HWB, or using The point about extracting, manipulating, and re-inserting color components is interesting. It also allows the manipulation to be done in JS, as an extensibility point. We should definitely explore it. In SCSS, re-inserting is free because it is just string concatenation; we would need a way to enable re-creating a color from components.
I don't have a strong opinion on the naming, but yes they do need to be distinct (the same color has very different hue angles in different systems). I have a slight preference for |
Ok it is a simple addition or subtraction (followed by clamping):
I see |
So my assumption in #3187 that authors will routinely be doing color component arithmetics if possible – even though their calculations are often too naive – seems to be close to reality. |
We can already do that, e.g. |
The findings shown here are exactly the type of things that powered Una and I to reach out with a request like "can we get some of the basic ones in first, before we solve the entire thing. Most of the usage we've seen in our teams/careers are super basic color manipulations, and designers aren't complaining about the results." We could pacify the majority of users with basic lighten, darken, mix and alpha functions on srgb colors. To me these results look like clear reasons to simplify, but I also really like the direction things are right now. Relative color manipulation, from css and js, looks super rad and I want it, today lol. It's also worth noting from the HTTP Archive results, that most stylesheets did not create robust custom property graphs, and rarely went over 3 nested references. We're all definitely at the tip of the spear when it comes to color manipulation, fidelity and systems. I'd love to make sure my Mom or little brother can use these color functions too, but it's easy to get in the weeds of color space stretching and clamping and distortion. I'm stuck somewhere in the middle of these 2 worlds! Could |
I'm leaning towards that too, to keep the API surface small-ish. Same for
A few more questions we need to answer (@svgeesus @argyleink @una):
If my co-editors agree and we reach consensus on these, I could make the edits. |
I still like color-adjust because it enables more room to grow in the future. I've felt that we should implement these with existing popular web color spaces today if the input colors are within those color spaces. I.e. if the input is RGB or HSL, we should still be able to make adjustments. This would make implementation in a timely manner much more likely, and also can still work with planning for future color spaces (the optional attribute to set which color space the mixing occurs in, or if any of the input arguments are in that color space). Allowing for transformations in HSL or RGB color spaces would mean that developers could use these today (something they are clearly asking for, as evidenced above), and browsers could implement them without the additional performance hit (and pre-requisite) of supporting a more advanced color format. Also, would we be able to adjust multiple components at a time?
Same question above -- I want to avoid creating new custom properties for each transformation if we wanted to adjust both saturation and lightness of a single theme variable. (This would be a common example of translating a theme color for dark themes)
Regardless of usage, they would enable a more complete system, so I do think we should add them. RGB channels are often tweaked in SVG filters to create unique effects.
If we go down this route, yes.
I think we'll still need
I agree we need a solution for multiple transforms at the same time |
@argyleink wrote
Most of the usage in SCSS etc uses HSL because that is all that is available although I understand @mirisuzanne added some support for LCH recently. So concluding that sRGB-based HSL is all that is needed, because that is what people use, is cyclical. That said, yes, we clearly need --col1: hsl(120 100% 80%);
--col2: hsl(190 100% 70%);
--col3: hsl(40 100% 60%);
--col1d: lighten(var(--col1),40);
--col2d: lighten(var(--col2),40);
--col3d: lighten(var(--col3),40); makes them all white. Which might be okay, but I have also been exploring sigmoid functions so there is more of a roll-off at the very light and very dark ends. |
That means:
|
the problem, or gamut clamp, starts earlier than SCSS imo. starts with designers and their color tools. most designers hunt and peck inside the rgb spectrum square.. designers deliver hex, developers receive hex. eg: nearly every single "developer designer handoff tool" delivers hex colors. even most CSS libraries deliver hex. it's at this point, with these values, "most" devs are in SCSS and need to darken it on hover.. without asking the ${insert dependency here}. and, tons of color function use is possible with css syntax today, but there's a belief that css can't do it. hsl can do most of it, but hsl is even too advanced for many people. it can't be ignored that massive amounts of scss stylesheets have code like how much lch adoption was there in the scss source maps? i tried looking in the spreadsheet data, but saw no values? |
If you feel strongly about keeping it, we can keep both that and the relative syntax and have all three, but ultimately, we'll need to settle on one for FPWD.
On the contrary, if color manipulation motivates browsers to implement colors beyond sRGB, that's a Good Thing™, because it's about damn time. Most authors are fine to use sRGB for manipulation because that's all they've known from preprocessors, because there was no alternative. It's our job to give them good defaults that work well and manipulations in gamma-corrected sRGB are suboptimal. It's not good for the Web in the long run to favor speedy implementation for a subpar feature that we'll be stuck with for decades.
Of course. The functions are independent. E.g. lch(lightness(var(--primary) lch) calc(chroma(var(--primary) lch) * 1.1) calc(hue(var(--primary) lch) + 10)) to manipulate both chroma and hue. lch(lch-l(var(--primary)) calc(lch-c(var(--primary)) * 1.1) calc(lch-h(var(--primary)) + 10)) Yes, it's very verbose, but also it can do anything (including combine channels from multiple different colors).
I'm not sure why you'd think you need to define new custom properties? Is it for readability? Given your earlier question about whether manipulating multiple channels is possible, I think you may have misunderstood and thought I was proposing these functions as the way to manipulate individual components, e.g.
I believe in SVG filters, the color manipulation also happens in the SVG filter, e.g. via
We tend to add things if there are use cases, not for completeness. If there are no or very niche use cases for these, we could start without them and add them once/if use cases emerge.
I'm not sure I follow, how does serialization relate? |
Libraries and tooling are going to hand off sRGB, if CSS only supports sRGB. If a value is generated anyway and edited visually, there is little value in handing off a more readable form of sRGB. However,
I'm not sure I follow that one.
You may be preaching to the choir here. Indeed, most manipulations are simple, hence why both Chris and I are in favor of
Are you seriously suggesting we determine course of action for LCH based on its adoption in preprocessors which a) has barely been an option for MONTHS and b) has no color modification functions tied to it? c) is not even built-in, but an add-on?! The Web can't stay in sRGB forever, screens have moved past it for years now. We already can't access one third of our screen colors with CSS. The "engineering fear" will need to get resolved eventually anyway, just like engineers eventually had to deal with higher pixel densities and didn't advocate that we pretend all monitors are still VGA to avoid "performance implications". |
@una wrote
Yes and those are linear-light sRGB values, not gamma-encoded sRGB. |
This is very true. The Web is in serious catch-up mode now. Native has had wide color gamut for a couple of decades, and even consumer Android and iOS phones and tablets have had P3 screens for four years. Streaming services like Netflix, Disney+ and Amazon Prime video have not only been shipping content in rec2020 wide gamut color, but also in rec2100 PQ High Dynamic Range. Gaming consoles are WCG and HDR. |
I'm not suggesting we stay in sRGB forever. I'm suggesting we change our approach from graceful degradation (srgb fallback), to progressively enhance (lab/lch as an upgrade).
Yes, I think we should look at adoption (if any). Even if it's a short blip of time in comparison for CSS. And it's not just about CSS's adoption of LCH, look at the whole industry. Lab / perceptual color spaces have been around since the 70's, have terrible adoption in tooling (designer and developer tooling), and while a very meaningful upgrade from sRGB, in many many ways (again i'm on your side here in 100% wanting lab/lch/etc color spaces to be available from CSS), I can't ignore this 50 year adoption curve. I don't think this is the right carrot to dangle in front of browsers or engineers to get them to add color spaces. I don't think if browser shipped lab/lch today, that design tools or handoff tools would swift off of hex. From what I can tell, we all agree on:
What we disagree on:
Again, I'm not advocating against adding color spaces. I'm advocating for unblocking. Allowing color functions and color spaces to progress individually. The package deal isn't selling well, to eng or the community. The outcome y'all pitch for, which again I want and agree with, this ability for CSS to use the higher quality colors in these powerful displays, can happen eventually. And again, I 100% see the value of color manipulation in lab/lch, it's the right goal. I think we can get there with smaller steps, instead of waiting for a big step. And yes, I understand this pitch is probably getting old. This pitch of, "can't we just use sRGB for today." I still believe there's room for everyone to win here. |
Lab/LCH have poor adoption for user-facing stuff, but are used internally for a number of algorithms. We've already discussed why web-facing stuff doesn't use them.
There is no blocking: Engineers are free to implement these functions with an explicit And here is a lovely video explainer: https://www.youtube.com/watch?v=LKnqECcg6Gw Once we define One thing to communicate to your engineers is that perhaps they don't actually need to implement Lab/LCH color values to do simple color manipulation in these spaces. The math is actually pretty simple, and they can just implement that directly until they're ready to properly implement Lab/LCH. One downside if they take that route and output sRGB as the result is there will be pointless gamut clipping for colors outside sRGB but within the screen gamut. They could get around to that by implementing In any case, it would be good to invite said engineers either in this issue or another one to express their implementation concerns so @svgeesus and I could talk to them directly, as this game of broken telephone does not facilitate communication. We have both seen a lot of such concerns that upon closer investigation turned out to be unfounded, so I think it could be a very productive discussion.
I don't think these are things we all agree on, since I proposed removing both of these in an earlier comment. |
Just to clarify some of the Sass context here…
Part of this also comes down to timing. The
I wrote the oddbird/blend library, which provides conversion between Sass colors & LCH, but we have not added any LCH functionality to the Sass core. We did add Also worth note: all Sass output is in hex, color keywords, or |
As part of our recent analysis of the state of CSS by querying the HTTPArchive corpus, we looked at preprocessor usage (SCSS only, where available via sourcemaps).
One thing of personal interest to me as co-editor of Color 5 was how frequently are the various color manipulation and extraction functions used? Here are the results for all SCSS function calls. We looked at 14 million function calls from nearly 300K SCSS stylesheets.
Here is the lowdown:
darken()
is by far the most frequently used function of all, even higher than the genericif()
. Half of all color manipulation usage is calls todarken()
, i.e. 17% of all function calls.lighten()
is the second most used color manipulation function (6th overall). 5.5% of all function calls are calls tolighten()
mix()
was pretty high: 3.5% of all function calls, 10% of color manipulation callsalpha()
,red()
,hue()
etc. These can then be passed on to regular color functions likehsl()
orrgb()
. Adjusting components viaadjust-color()
was relatively rare however (0.2% of all function calls), indicating that for complex color manipulations authors may find it more natural to do math on color components and plug them in to an existing color function than to use a color adjustment function.What does this tell us about future directions for Color 5?
color-adjust()
. However, I'm not sure anymore about the idea of having keywords for each component that only work as a relative syntax within each function. This is much harder to implement incrementally, and addresses fewer use cases. We may want to go a similar (to SCSS) route and introduce functions for extracting individual components, that authors can then use as they wish, in any function they want, even to combine components from multiple colors without the weirdness ofcolor-mix()
(which is very nice and natural for simple interpolation, but gets weird fast when per-component adjusters come into play). The challenge is: how to define such functions for more spaces than sRGB, without getting overly verbose? Would things likelch-hue()
be too verbose? Should we have a generichue()
for LCH and ahsl-hue()
for HSL?CC @svgeesus @una @argyleink
The text was updated successfully, but these errors were encountered: