[csswg-drafts] [css-color-4] HTML needs an html-compatible, hex serialization of 8 bit/component sRGB colors (#10550)

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

== [css-color-4] HTML needs an html-compatible, hex serialization of 8 bit/component sRGB colors ==

_Originally posted by @annevk in https://github.com/whatwg/html/issues/8917#issuecomment-2216693534_

              
From HTML's perspective we have these requirements:

- 2D canvas: stores a CSS color and when that color happens to use 8-bit per component it needs to be serialized as `#...` (when opaque) or `rgba(...)` (when not opaque). I think it would make sense if we could set a boolean [named parameter](https://infra.spec.whatwg.org/#algorithm-params) called "HTMLCompatible" or some such when serializing to enable that.
- `<input type=color>`: stores a CSS color, but when serializing that color a) needs to be converted to a color space according to the `colorspace` attribute b) when that is Limited sRGB that color b1) needs to be rounded to 8-bits per component and b2) use "HTMLCompatible" just like 2D canvas

I think for `<input type=color>`:

- HTML should probably do the color space conversion upon the CSS color.
- HTML should probably do the rounding as well, although I could also see this being an additional named parameter, but I don't see much utility in that unless there's multiple callers needing it.

So here is what this would mean for the CSS Color specification for maximum clarity:

- It needs to define a "serialize a CSS color" operation that takes a CSS color and outputs a string (doh).
- It needs to define a "HTMLCompatible" named parameter for that operation that influences the serialization when the passed CSS color is a) in the 'srgb' color space and b) uses 8-bits per component. In particular for colors meeting those requirements it will use https://html.spec.whatwg.org/multipage/canvas.html#serialisation-of-a-color (which it defines itself so that definition can be removed from HTML).

Does that make sense? Once that's in place I can update the `<input type=color>` PR and perhaps also create a separate PR to ensure 2D canvas is properly defined.

            

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10550 using your GitHub account


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

Received on Wednesday, 10 July 2024 11:54:46 UTC