Re: [csswg-drafts] [css-color] Should relative `rgb()`/`rgba()` and relative `hsl()`/`hsla()` serialize exactly as declared? (#10327)

The spec goes on to state:
> The serialization of the result of a relative color function depends on whether the keyword [currentColor](https://drafts.csswg.org/css-color-4/#valdef-color-currentcolor) is the [origin color](https://drafts.csswg.org/css-color-5/#origin-color). If so, the result is serialized as the declared value. This allows the correct value to be used on child elements whose [color](https://drafts.csswg.org/css-values-5/#valdef-attr-color) property has a different value. Otherwise, it is the resolved value, which is a [`<color>`](https://drafts.csswg.org/css-color-5/#typedef-color), as defined in [CSS Color 4 ยง  15. Serializing `<color>` Values](https://drafts.csswg.org/css-color-4/#serializing-color-values).

I understand this to mean:
1. If the origin color is `currentColor`, then serialize the spelling as declared. (We don't know the origin color and thus cannot canonicalize it.)
2. If the origin color is not `currentColor`, then resolve the relative color and serialize canonically as described in Color 4.

There are few tests with examples for how canonicalization happens in case 2: [color-valid.html](https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/color-valid.html), [color-valid-rgb.html](https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/color-valid-rgb.html), [color-valid-hsl.html](https://github.com/web-platform-tests/wpt/blob/master/css/css-color/parsing/color-valid-hsl.html). Notably:
- `hsla(...)` canonicalizes to `rgba(...)`, and `hsl(...)` canonicalizes to `rgb(...)`
- `rgb(...)` is used if the clamped alpha is exactly 1, otherwise `rgba(...)` is used

cc @svgeesus to confirm.

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


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

Received on Monday, 13 May 2024 19:08:57 UTC