[csswg-drafts] [css-color] Should colors nested in a parent color function (RCS, color-mix, light-dark, color-contrast) serialize in their most precision saving form (#10328)

weinig has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-color] Should colors nested in a parent color function (RCS, color-mix, light-dark, color-contrast) serialize in their most precision saving form ==
In CSS Color 5, the [serialization of relative colors](https://drafts.csswg.org/css-color-5/#serial-relative-color) is defined with the following:

> The serialization of the declared value of a relative color function is a string identifying the color function in all-lowercase, followed by "(from ", followed by the __serialization of the declared value of the origin color__, followed by a single space, followed by a singly-space-separated list of the arguments to the color function, followed by ")".

(emphasis added)

If taken at face value, this would mean that relative colors do not round trip faithfully when the origin color has values outside the reference range, as the [processing model for relative colors](https://drafts.csswg.org/css-color-5/#rcs-intro) states:

> When relative color syntax is used, color channel values, whether directly specified or arising from color space conversion, are not clamped to the reference ranges but are retained as-is. This preserves out of gamut values, if the destination color space is capable of representing them.

So, in an example like:

```css
rgb(from rgb(200% 100% 100%) r g b)
```

my reading is that the declared value would serialize as: `rgb(from rgb(255, 255, 255) r g b)`, but the computed value would be `color(srgb 2 1 1) `

I would like to propose that nested colors, both for RCS and the other color functions that take color arguments, the nested colors serialize in a way that preserves the behavior of the parent. The most straightforward way I can think to have that work would be to serialize the declared value according to normal (not encumbered by the legacy of color serialization) CSS serialization rules for declared values - aka minimal needed, calc() preserving, etc.

In the case above, that would mean serializing the declared value exactly as written:

```css
rgb(from rgb(200% 100% 100%) r g b)
```


To expand with another example:

```css
rgb(from hsl(calc(30 + 60) 50% none) r g b)
```

would serialize the declared value as:

```css
rgb(from hsl(calc(90) 50% none) r g b)
```


Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10328 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 16:01:53 UTC