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-typed-om] Move ".colorspace" to the color superclass, readonly #1036

Closed
tabatkins opened this issue May 13, 2021 · 5 comments
Closed

[css-typed-om] Move ".colorspace" to the color superclass, readonly #1036

tabatkins opened this issue May 13, 2021 · 5 comments

Comments

@tabatkins
Copy link
Member

In #1034 (comment), Lea points out that it's annoying to figure out what the colorspace of a color object is.

We already have precedent in Typed OM for helping with this - the math function subclasses expose their function name as a property as well, precisely to avoid this annoying hacky work.

Seems like the most straightforward fix is to move ".colorspace" to the CSSColorValue superclass, as a readonly property that's automatically set to the corresponding function name, and then make it writable on CSSColor.

(Conveniently, the CSSWG just resolved to drop the "lab" predefined color space for color(), so there's no clashes anymore. "rgb" (for rgb()) and "srgb" (for color(srgb)) will be close, but they're distinct.)

@tabatkins
Copy link
Member Author

If we have this, then it also gives us an identifier we can use to make the toX() function generic, rather than having specialized names. That is, we can write .to("rgb") to get a CSSRGB object, or to("rec2020") to get a CSSColor object set to the rec2020 color space.

This would solve another problem Lea pointed out in the comment linked above, and would make it more consistent with the .to() function in CSSNumericValue, which is a nice bonus.

@svgeesus
Copy link
Contributor

If we have this, then it also gives us an identifier we can use to make the toX() function generic, rather than having specialized names. That is, we can write .to("rgb") to get a CSSRGB object, or to("rec2020") to get a CSSColor object set to the rec2020 color space.

That would be much better, yes.

It should be noted that the domain and range are unbounded, so that there is no hidden clipping or gamut mapping, when converting from one space to another (i.e. you can convert back without loss).

@svgeesus
Copy link
Contributor

Seems like the most straightforward fix is to move ".colorspace" to the CSSColorValue superclass, as a readonly property that's automatically set to the corresponding function name, and then make it writable on CSSColor.

So, the only object that allows this type of colorspace conversion is CSSColor?

And, there is both .to("rgb") and .to("srgb" which both do the same conversion, but give you different types of object?

@tabatkins
Copy link
Member Author

So, the only object that allows this type of colorspace conversion is CSSColor?

No, it would be on CSSColorValue, the superclass, where the .toX() methods currently live.

And, there is both .to("rgb") and .to("srgb") which both do the same conversion, but give you different types of object?

Yup.

@LeaVerou
Copy link
Member

I support this change and think it's an improvement over the current API, though to("srgb") and to("rgb") performing the same conversion but returning different object is pretty weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants