Re: [csswg-drafts] [css-color-4] Parse-time clip of HSL negative saturation for modern syntax? (#9222)

I would definitely expect channel values to not be clamped before mixing colors (unless otherwise specified at parse time).

The definition of [`hslToRgb()`](https://drafts.csswg.org/css-color-4/#hsl-to-rgb) says:

  > It returns an array of three numbers [...] normalized to the range [0, 1].

And its saturation/lightness argument should be *in reference range [0,100]*.

Now, `hslToRgb(0, 150, 40)` returns `[1, -0.2, -0.2]`. It would serialize as `rgb(255, 0, 0)` assuming values outside of `[0,255]` are clamped, which is only specified to apply at parse time for `rgb()`.

It returns `[0.8, 0, 0]` if saturation is clamped before, which would serialize as `rgb(204, 0, 0)`.

And the specified/computed value of `hsl(0, 150%, 40%)` is currently `rgb(204, 0, 0)`, not `rgb(255, 0, 0)`.

```js
// Chrome-FF -> rgb(204, 0, 0)
element.style.color = 'hsl(0, 150%, 40%)'
getComputedStyle(element).color; 
// Chrome-FF -> rgb(204, 0, 0)
element.style.color = 'hsl(0 150% 40%)'
getComputedStyle(element).color; 

// Chrome-FF -> color(srgb 0.8 0 0)
element.style.color = 'color-mix(in srgb, hsl(0, 150%, 40%), hsl(0, 150%, 40%))'
getComputedStyle(element).color; 
// Chrome -> color(srgb 1 -0.2 -0.2) ; FF -> color(srgb 0.8 0 0)
specified.color = 'color-mix(in srgb, hsl(0 150% 40%), hsl(0 150% 40%))'
getComputedStyle(element).color; 

// Chrome-FF -> color(srgb 0.8 0 0)
element.style.color = 'rgb(from hsl(0, 150%, 40%) r g b)'
getComputedStyle(element).color; 
// Chrome -> color(srgb 1 -0.2 -0.2) [FF] color(srgb 0.8 0 0)
specified.color = 'rgb(from hsl(0 150% 40%) r g b)'
getComputedStyle(element).color; 
```

Unfortunately, I cannot find any test on WPT with a saturation greater than 100% in `hsl()`.

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


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

Received on Monday, 19 February 2024 08:11:50 UTC