Re: [csswg-drafts] [css-color] Clamping alpha at computed-value time vs parsing time (#7677)

Clamping at parse time may be an exception for sRGB color functions. [CSSOM](https://drafts.csswg.org/cssom-1/#ref-for-alphavalue-def) defines how to serialize `<alphavalue>` (aside: note the missing `-` between "alpha" and "value") as an 8-bit integer (between 0 and 255). This might be the (historical) reason why browsers do clamping at parse time, as noted in [15.2 Serializing sRGB values](https://drafts.csswg.org/css-color-4/#serializing-sRGB-values):

> For compatibility, the sRGB component values are serialized in `<number>` form, not `<percentage>`). Also for compatibility, the component values are serialized in base 10, with a range of [0-255], regardless of the bit depth with which they are stored.

Aside: there is an extra `)` in the first sentence.

But this same section also has...

> The serialized form of the following sRGB values [...] is derived from the computed value and thus, uses either the `rgb()` or `rgba()` form (depending on whether the alpha is exactly 1, or not)

... and I am very confused that I have to use a computed value to serialize a specified value. And [15. Serializing `<color>` Values](https://drafts.csswg.org/css-color-4/#serializing-color-values) starts with:

> This section updates and replaces that part of CSS Object Model, section Serializing CSS Values, which relates to serializing `<color>` values.

Apart from this, there are also math functions, whose value is [clamped at computed value time](https://drafts.csswg.org/css-values-4/#calc-range), eg. `rgb(0, 0, 0, calc(-1))`, and `opacity` is also defined with `<alpha-value>` and its specified value is not clamped.

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


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

Received on Saturday, 3 September 2022 05:39:37 UTC