-
Notifications
You must be signed in to change notification settings - Fork 707
[css-values-5] Accept more than 2 values in *-mix(<progress>, ...)
and progress()
notations
#11530
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
Comments
*-mix(<progress>, ...)
notation with more than 2 values*-mix(<progress>, ...)
and progress()
notations
I don't understand what difference you are implying
I don't understand how this is supposed to behave |
This should be better explained in the spec, which just mentions the two concepts :/
Basically mixing has the opposite behavior of interpolation: While it's unclear what something like
I think understanding the difference of mixing vs interpolation is kinda a prerequisite for this proposal. |
I disagree that they are opposites. Whether you call
Well, I think https://drafts.csswg.org/css-color-5/#color-mix-percent-norm could be generalized in a quite natural way:
So in this case it would be
Yes that can work, though I would maybe call this color picking rather than mixing/interpolating. Because it's placing colors at equidistant positions between 0% and 100%, and then picking the color at the provided percentage, falling back to interpolating the nearest pair of colors if there is no color at that exact position. However, I think forcing equidistant positions may be a bit inflexible. Just like gradients, I suspect that authors will ask to be able to assign colors at a custom percentage position, or even a range. But these positions could be confused with mixing weights, so I would prefer a different function name. |
Happy to generalize it to the version with weights too, though I do think it's somewhat less intuitive.
Note that this doesn't just affect
I completely agree, but equidistant is fine for an MVP — we can add positions later. Far, far easier to add intermediate color stops to fake the lack of positions than to deal with a quadratic number of nested calls.
I agree |
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> TabAtkins: This was about allowing more than 2 values to be mixed together.<fantasai> TabAtkins: resolution from https://github.com//issues/6245#issuecomment-2685746280 addresses this request <oriol> q+ <astearns> ack oriol <fantasai> TabAtkins: Will need edits to colors to allow color-mix() to have more than 2 values <fantasai> oriol: When we were discussing what value should be with multiple values <fantasai> oriol: Lea was saying you would pick the two values and interpolate them <fantasai> oriol: another option would be weighted value among all values <fantasai> oriol: I'm not sure how these map <fantasai> TabAtkins: mix() all do weighted average, and map() does chained interpolation pairs <fantasai> ChrisL: Not totally clear that I understand about chained pairs <fantasai> ChrisL: color-mix() says if you don't specify either you have 50% <fantasai> ChrisL: you want to allow more than 2? <fantasai> ChrisL: if none is specified, you divide 100% by number? <fantasai> lea: yep <fantasai> ChrisL: Specify some but not all? <fantasai> TabAtkins: Split remainder among unspecified ones <fantasai> lea: and scale down sums above 100% <fantasai> ChrisL: will need to expand tests <fantasai> lea: expand but not change <TabAtkins> fantasai: should we keep this open to track edits for color-mix()? <fantasai> astearns: objections to updating color-mix() to match the plan for other mix() functions? <fantasai> RESOLVED: Update color-mix() to accept N arguments. |
A common need in design systems is to get a value based on its position in a list. E.g. get the lightest color tint, or the smallest font-size etc.
In css-values-5 we define
*-mix()
functions (calc-mix()
,color-mix()
etc) that interpolate rather than mix, i.e. 0% gets you the first color and 100% the second one instead of the way around which is how the mixing version works.This means they do not actually need to be limited to two arguments!
All we need to solve a lot of the use cases that motivated #10034 and a host more is to convert the grammars of these mix functions from:
to
And similarly for
cross-fade()
andtransform-mix()
though I haven't found use cases for these.Yes, it can be emulated with the 2-value
*-mix()
, but the code to do it is abysmal and its complexity increases quadratically with the number of values.The same argument applies to
progress()
, being the inverse of these. Currently it is defined as:With this change, it would become:
(or just
progress( <calc-sum>#)
but separating the first argument may be better for clarity)A nice-to-have could also be to support percentages as well with the values, which would work in the same way as gradient color stops, i.e. affect how the interpolation works.
This is a change that only very slightly increases implementation effort for these functions, and would save authors a ton of pain, so it seems like a no-brainer to me.
The text was updated successfully, but these errors were encountered: