[css-values] Make min and max value optional in clamp()
(original) (raw)
As we know, we added clamp() because doing clamping logic with min()
and max()
is counterintuitive.
However, this doesn't only apply when you have both a min and a max, it’s still counterintuitive when you only have one of two. I keep finding myself using clamp()
with dummy min or max values so that I can only use it for max or min respectively, which not only adds cognitive overhead, but also pointless computation.
A nice little improvement could be to make the min and max values optional via none
keywords:
<clamp()> = clamp( <calc-sum>#{3} )
After:
<clamp()> = clamp( [ <calc-sum> | none ] , <calc-sum> , [ <calc-sum> | none ])
Alternative syntax: Using empty tokens for the omitted argument
<clamp()> = clamp( <calc-sum>? , <calc-sum> , <calc-sum>? )
Note that this is different from clamp( <calc-sum>#{2, 3} )
: we still need empty tokens for the missing arguments, otherwise we wouldn't be able to disambiguate. I.e. clamp(3rem, 10vh)
would not be valid, it would need to be either clamp(3rem, 10vh, )
or clamp( , 3rem, 10vh)
.
If we go that route we'd also need to add an exception to require the comma with empty arguments, per normal grammar specification rules the comma would be omitted, making disambiguation impossible.
When I first posted this I thought going the empty token route would be ideal, as none
seemed too verbose, but I now think the clarity hit is not worth it, especially if we take the editorial challenges into account.
Hopefully this is such a small change we may be able to wedge it in css-values-4.
Edit: Agenda+ after discussing it with @fantasai and @tabatkins — this seems like such an easy win and pretty uncontroversial so we could move forwards with hopefully very little call time.