-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-color-4] HTML needs an html-compatible, hex serialization of 8 bit/component sRGB colors #10550
Comments
CSS Color 4 has a concept of legacy color syntax. Essentially, pre-css color 4 colors (rgb, rgba, hsl, hsla) get serialized as they always have. Non-legacy colors are serialized as described in csswg.sesse.net/css-color-4. The simplest solution would just be to do exactly what CSS is doing, while preserving "opaque colors are hex" quirk from https://html.spec.whatwg.org/#serialisation-of-a-color.
Could we even link to https://csswg.sesse.net/css-color-4/#serializing-color-function-values? Originally posted by @mysteryDate in whatwg/html#8917 (comment) |
This is to allow the HTML spec "serialization of a color" to be replaced by a reference to CSS Color; while also updating it to cover
|
HTML PRs are now up:
CSS Color defining |
Proposed resolution: CSS WG will work together with WhatWG to add an HTML-compatible, hex serialization of 8 bit/component color, for ease of referencing from HTML LS |
The CSSWG will automatically accept this resolution one week from now if no objections are raised here. Anyone can add an emoji to this comment to express support. If you do not support this resolution, please add a new comment. Proposed Resolution: CSS WG will work together with WhatWG to add an HTML-compatible, hex serialization of 8 bit/component color, for ease of referencing from HTML LS |
RESOLVED: CSS WG will work together with WhatWG to add an HTML-compatible, hex serialization of 8 bit/component color, for ease of referencing from HTML LS |
Great to see this resolved! @svgeesus when do you plan on adding this? |
Sorry I have been busy. Will get to it. If you have concrete wording suggestions please drop them into this thread, of course. |
Thanks @svgeesus for adding https://drafts.csswg.org/css-color-4/#serializing-sRGB-values. Per feedback from Domenic "htmlCompatible" would be better. I was also hoping for an actual algorithm, which the current setup doesn't entirely lean itself to. But perhaps we can pretend it is one for now. I also noticed these other things:
|
With respect to "actual algorithm", we currently invoke https://drafts.csswg.org/css-color/#parse-a-css-color-value from HTML for parsing. Having a serialization counterpart to that would be ideal, but for now we can pretend these serialization sections represent that I suppose. |
In terms of an actual algorithm, the procedure I described in prose is consistent with the rest of the CSS Color 4 serialization section. It is also, by the way, consistent with (the first part of) HTML LS serialization of a color:
If there is really a preference for using a more algorithmic approach I can do that, but assembling a seven-character string from " |
It's mostly that how to invoke it from HTML is a bit ambiguous, but if the way I did it in whatwg/html#10481 works for everyone I'm okay. I found something else when testing
Maybe we should standardize on what Chrome and Firefox do here? It seems more useful if they all get serialized using the same form. This sRGB section also doesn't address mapping "none" to 0, but it probably should? cc @weinig |
Because it is not specific to sRGB. It is defined in 4.4. “Missing” Color Components and the
Hex colors are a legacy color syntax. But then, 5.2.2. CSS serialization of sRGB values does reiterate it:
So maybe the |
The additional point about out-of-range values should probably move up as well then to apply to both HTML sRGB and normal sRGB. |
Correct, it is not
Yup
Good idea |
I agree that how it's invoked from HTML is too ambiguous. It would have been nice to have a full algorithm for converting a well-defined "CSS color" data structure into a string, with a named htmlCompatible argument. I can understand if culturally that is not how the CSSWG does serialization though. That is, apparently there is no "CSS color" data structure but instead a To bridge these worlds, I think the minimum we'd need would be a well-defined linkable
to
and then we can update the HTML side to say something like |
@svgeesus @tabatkins it'd be great to get @domenic's comment resolved as that's currently blocking a bunch of work on the HTML side, including |
That is correct. Interoperability of CSS implementations is defined over the CSS content that they parse as input; the precise details of internal representation are intentionally not described, they can and do vary between implementations. I added the |
…s to both HTML-compatible and CSS serializations #10550
Agreed and also done @annevk you said the examples of where HTML-compatible serialization would be used are wrong because they only apply to things like fill and stroke, not reading colors back from canvas. Can you suggest a better example that I could use instead? |
…alization, they will already have been converted to zero #10550
@domenic The link is now available and |
Thanks! Some examples (mainly borrowed from the tests I wrote): context.fillStyle = "#ff00ff00";
console.log(context.fillStyle); // "rgba(255, 0, 255, 0)"
context.fillStyle = "lab(29% 39 20)";
console.log(context.fillStyle); // "lab(29 39 20)"
context.fillStyle = "rgb(255, 0, 255)"
console.log(context.fillStyle); // "#ff00ff" |
…#10550 Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148 UltraBlame original commit: ba0041c24e1332e588896b9fb72ed44e32f1a385
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148 UltraBlame original commit: ba0041c24e1332e588896b9fb72ed44e32f1a385
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148 UltraBlame original commit: ba0041c24e1332e588896b9fb72ed44e32f1a385
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148
Originally posted by @annevk in whatwg/html#8917 (comment)
From HTML's perspective we have these requirements:
#...
(when opaque) orrgba(...)
(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 thecolorspace
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 canvasI think for
<input type=color>
:So here is what this would mean for the CSS Color specification for maximum clarity:
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.The text was updated successfully, but these errors were encountered: