Re: [csswg-drafts] [css-color-4] Computed value and serialization of `Infinity` and `NaN` in color functions (#8629)

There's no meaningful difference between `calc(infinity)` and `calc(1e6)`. If the number has an enforced range at parse time, they'll both act as the clamped value; if it's unclamped, they'll both be essentially identical in behavior anyway. We shouldn't be treating the two cases differently.

> All things that I am familiar with do not become invalid when out of range.

A number of things have ranges that are checked at parse-time. They'll be invalid if you use an out-of-range value by itself, but math functions change that behavior - see <https://drafts.csswg.org/css-values/#calc-range>. Instead, if a value is the result of a math function, it's treated as valid at parse time, and clamped at computed and/or used-value time to the allowed range.  For example, `width: -1px` is invalid, but `width: calc(-1px);` is valid and equivalent to `width: 0;`. We do this because it's not always possible to tell how large a value is going to be, and even whether it'll be positive or negative, until computed or used value time. (For example, `calc(16px - 1em)` can be positive, negative, or zero depending on the size of the `em`, which isn't known until computed-value time.)

This is why [the serialization algorithm](https://drafts.csswg.org/css-values/#calc-serialize) has a branch for computed or later values in the first step; specified values have to preserve the fact that the value is in a math function, in case the value is outside the allowed range, so you can round-trip the value.

> To pass these tests will involve restructuring things quite a bit and creating a sort of "unresolved color" type so that the color can be serialized differently at parse time than at computed time.

This is required anyway to handle cases like a `color-mix()` or relative color referring to `currentcolor`, which also isn't known until computed-value time.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8629#issuecomment-1569081966 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 30 May 2023 20:49:26 UTC