Skip to content

[css-typed-om] toColor() intentionally restricted to predefined colors? #1030

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

Closed
svgeesus opened this issue May 11, 2021 · 2 comments
Closed

Comments

@svgeesus
Copy link
Contributor

In 4.6 CSSColorValue objects, the toColor(colorspace) method states:

  1. If colorspace’s value is not one of the predefined colorspaces, throw a SyntaxError.

However, in CSS Color 4, the syntax of the color() function is:

<pre class='prod'>
	<dfn>color()</dfn> = color( [<<ident>> | <<dashed-ident>>] [ <<number-percentage>>+ ] [ / <<alpha-value>> ]? )
</pre>

while currently, CSSColorValue only handles the <ident> case and not the <dashed-ident> case.

Is this an intentional restriction, or an oversight? If intentional, what is the rationale?

@tabatkins
Copy link
Member

Currently intentional, but intended to be temporary.

Basically, I'm not sure how to handle the reference to a custom space when doing color conversion (to or from CSSColor). This is a somewhat generic problem with CSS-based references vs JS - in CSS references are defined on a per-tree basis (so shadows don't interact with each other, and can theoretically have same-name references without colliding), but JS stretches across trees, so it's not clear where it should be grabbing the ref from.

(I know that I'm inconsistent here - the other conversion functions don't check that a CSSColor value is using a predefined space. They should, and throw in that case.)

Note that you can directly create a CSSColor in a custom colorspace, so you can still use it in CSS; you just can't convert it to other spaces.

My vague plan is to let people provide a Document/ShadowRoot reference to the conversion functions, and have it draw on that to figure out the definition of the custom colorspace. (And use the same strategy for other cases across CSS that run into the same problem.)

@svgeesus
Copy link
Contributor Author

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

2 participants