Skip to content
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] Clarify how color() values with fallback should serialize #5904

Closed
weinig opened this issue Jan 27, 2021 · 8 comments
Closed
Assignees
Labels
Closed Accepted by Editor Discretion Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-color-4 Current Work

Comments

@weinig
Copy link
Contributor

weinig commented Jan 27, 2021

It is not clear to me from the wording how color() values with fallback (e.g. color(display-p3 0 1 0, srgb 0 1 0)) should be serialized. It would be good to at least have an example, if not explicitly call it out.

@svgeesus
Copy link
Contributor

You are right, this is not covered at all, and should be, explicitly, not just as an example.

In general, the design principles for <<color>> serialization were:

  1. For legacy formats, maximal backwards compat so comma separators between color components, etc
  2. For the new formats, normalize the values (such as trimming trailing zeroes) but otherwise serialize as-is
  3. Normalize fully opaque colors by using an implicit alpha, except for legacy rgb/rgba, hsl/hsla

So it seems therefore that the serialized form, in the case of fallback, should be serialization as-is except for the various normalizations. Does that seem reasonable?

(Note to self to make sure Typed OM also handles fallback colors on the color() function).

Also btw your example is incorrect, it should either be

color(display-p3 0 1 0, rgb(0 100% 0))

using the legacy syntax as a fallback, or

color(display-p3 0 1 0, color(srgb 0 1 0))

using another color function as a fallback. Note that in this second case, the fallback could itself have a fallback. Here is an example:

color(rec2020 0 0 1, color(display-p3 0.119 0 0.415, rgb(14.1% 0% 43.8%)))

image

@weinig
Copy link
Contributor Author

weinig commented Jan 28, 2021

Thanks for the details, I'm just starting to look into fallback now, so haven't really studied this part of the spec yet. There are a few examples that don't seem to match this pattern like Example 40 in https://drafts.csswg.org/css-color-4/#color-function.

color(prophoto-rgb 0.4835 0.9167 0.2188, display-p3 0.3499 0.9800 0.1399, rgb(33.44% 96.68% 21.07%))

@weinig
Copy link
Contributor Author

weinig commented Jan 28, 2021

So it seems therefore that the serialized form, in the case of fallback, should be serialization as-is except for the various normalizations. Does that seem reasonable?

Yeah, that makes sense to me.

@svgeesus svgeesus added Closed Accepted by Editor Discretion Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. labels Jan 28, 2021
@svgeesus
Copy link
Contributor

@carlosame
Copy link

fallback examples fixed to use the actual grammar

The syntax is supposed to be this:

color() = color( [ [<ident> | <dashed-ident>] [ <number-percentage>+ | <string> ] [ / <alpha-value> ]? ]# , <color>? )

where "Each argument represents either an invalid color, as described below, or a valid color", so

color(prophoto-rgb 0.4835 0.9167 0.2188, display-p3 0.3499 0.9800 0.1399, rgb(33.44% 96.68% 21.07%))

seems correct.

If it is not, then the above grammar should be modified as well. Also, the current one probably meant:

color() = color( [ [<ident> | <dashed-ident>] [ <number-percentage>+ | <string> ] [ / <alpha-value> ]? ]# [, <color>]? )

@weinig
Copy link
Contributor Author

weinig commented Jan 31, 2021

I guess one other thing that would be good to call out is how are things like the following (taken from wpt predefined-014.html) serialized:

color(banana 0.1 0.2 0.3, #009900)

That is, an invalid color (invalid because it is non-dashed ident representing a color space that isn't predefined) with a valid fallback color.

Similarly, explicitly codifying how something like the following serializes would be helpful:

color(--banana 0.1 0.2 0.3, #009900)

That is, an invalid color (invalid because there is no @color-profile --banana { ... }) with a valid fallback color as well.

(Note, Example 19 makes it clear how this would serialize if there was a specified @color-profile --banana { ... }, though it might be worth calling out that it would serialize the same regardless of whether the src had loaded, if that is indeed the case).

@svgeesus
Copy link
Contributor

(No action pending resolution of #5931 which would make this one moot)

@svgeesus
Copy link
Contributor

Closed because the color() syntax no longer includes a fallback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted by Editor Discretion Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-color-4 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants