-
Notifications
You must be signed in to change notification settings - Fork 3
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
What to do with serialization of author-defined color spaces? #25
Comments
The question to be answered first is what the purpose of serializing is. If it's just another way of representing the color, similar to But if it's to produce a string that can be used in CSS and other web-platform things that rely on CSS colors, then we need to be sure to only emit strings that are valid CSS. That probably means we need to walk up the color space tree until we find a space that we do know how to serialize into a valid CSS value. This implies that different browsers can produce different serializations, if the set of color spaces they support in CSS is different. |
If we introduce ways to plumb author-defined spaces into CSS, then we can stop at those instead of only searching for browser-recognized spaces, of course. |
Thinking about this some more, I think we should separate out the Color object serialization ( In color spaces that are natively supported in CSS, such as the built-in ones, these could return the same thing. In custom color spaces, or anonymous color spaces, Perhaps we could even have additional sugar: (I have mistyped Thoughts, @svgeesus @tabatkins ? |
We should really decide what to do with parsing and serialization.
For color spaces that are supported by CSS, this is easy: it should parse all CSS formats (through
CSSColorValue
internally) and serialize to a supported CSS value. Even for built-in color spaces it's still nice if the behavior is expressed using the same primitives as author-provided color spaces.But what to do with author-defined color spaces? They still need to serialize somehow.
From #23 (comment) :
What we do in Color.js is that each color space may provide parse and stringify methods, and if it doesn't, the default serialization is
color(colorSpace ...coords / alpha)
, whether it produces a valid CSS color or not.I think that may work here too. The idea of producing invalid colors doesn't make me too happy, but given these color spaces are not supported by CSS yet, there's no way to serialize them into a valid color anyway.
Maybe we should make it obvious that they are not valid CSS colors by prepending their color space id with something?
But what if Color API is used to polyfill color spaces that browsers don't natively support yet but are actually in the spec?
The text was updated successfully, but these errors were encountered: