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

Gray color is not correctly cast to a string #475

Closed
star-over opened this issue Mar 9, 2024 · 7 comments
Closed

Gray color is not correctly cast to a string #475

star-over opened this issue Mar 9, 2024 · 7 comments

Comments

@star-over
Copy link

I noticed a problem when trying to use the API in the developer tools.
Specifically, when I tried to convert the color 'gray' to HSL and then to a string, the result displayed 'none'. Other color names do not have this result.

(new Color("gray")).to("hsl").toString()
>> 'hsl(none 0% 50.196%)'
image
@facelessuser
Copy link
Collaborator

What hue would you suggest gray has? The reason why you get an undefined hue (none) is because the color is achromatic and has no hue.

@star-over
Copy link
Author

star-over commented Mar 10, 2024

I suggest use 0 instead none when color stringify. So, I expect hsl(0 0% 50.196%) but not a hsl(none 0% 50.196%)

Because converting color with none to other format is another issue:

(new Color("hsl(none 0% 50.196%)")).to("srgb").toString()
>>> 'rgb(none none none)'

but with 0 instead none it works corretly:

(new Color("hsl(0 0% 50.196%)")).to("srgb").toString()
>>> 'rgb(50.196% 50.196% 50.196%)'

@facelessuser
Copy link
Collaborator

none is now supported in the CSS spec and has been implemented in a number of browsers. Gray doesn't actually have a red (0deg) hue, but regardless of technicalities of what is more correct, I can imagine some people desiring a way to serialize without none. There was an option to do so for some amount of time, but it was removed in e28cd6a.

Below does look like a bug to me though. Undefined values should be handled before conversion, but that does not appear to be happening currently.

new Color("hsl(none 0% 50.196%)").to("srgb").toString()
>>> 'rgb(none none none)'

@star-over
Copy link
Author

I just fixed problem for a while with a .toString().replaceAll("none", "0") after any stringify.

@facelessuser
Copy link
Collaborator

I personally think an option to allow omitting none in serialization seems reasonable, but thenone conversion issue should definitely get fixed.

@facelessuser
Copy link
Collaborator

I've created a PR (#476) to adjust the bad "none" handling across the library.

@svgeesus and @LeaVerou would need to make a decision on whether it is desired to expose conditional "none" serialization. If they decided that they wanted to move forward with this, I'd be happy to make the PR.

@facelessuser
Copy link
Collaborator

None bug has been fixed on main. A new issue is opened that, when implemented, could solve the serialization request: #479. I will resolve this as a duplicate of that issue. I advise following that issue to stay on top of progress.

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

No branches or pull requests

2 participants