8000 [css-color-4] HTML needs an html-compatible, hex serialization of 8 bit/component sRGB colors · Issue #10550 · w3c/csswg-drafts · GitHub
[go: up one dir, main page]

Skip to content

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

@svgeesus

Description

@svgeesus

Originally posted by @annevk in whatwg/html#8917 (comment)

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 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0