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

Support for none #228

Closed
svgeesus opened this issue Oct 20, 2022 · 6 comments
Closed

Support for none #228

svgeesus opened this issue Oct 20, 2022 · 6 comments
Labels
spec-parity Parity with the CSS Color specs

Comments

@svgeesus
Copy link
Member

We currently don't accept the keyword none, nor do we generate it on serialization.

@svgeesus
Copy link
Member Author

svgeesus commented Jul 6, 2023

Even when we generate a color with NaN as the hue, we still serialize it as 0: rgba(0 0 0 / 0) converts to Oklch with the coordinates [0, 0, NaN] and we serialize as oklch(0 0 0 / 0)

@svgeesus
Copy link
Member Author

svgeesus commented Jul 6, 2023

Culprit is in serialize.js

	// Convert NaN to zeros to have a chance at a valid CSS color
	// Also convert -0 to 0
	// This also clones it so we can manipulate it
	coords = coords.map(c => c? c : 0);

@LeaVerou
Copy link
Member

LeaVerou commented Sep 3, 2023

So there are two components to this:

  • Support parsing none (convert it to NaN)
  • Support outputting none

The last bit is tricky: we want serialize() to output none, but display() should not unless the browser actually supports it. So, the only way I see to do this, is to

  • add an option to serialize() which converts NaN to 0 (the current default, which should now be the not-default — I think the compat risk here is minimal).

Then, if the color has NaN components,

  • display() can check if none is supported, and use the appropriate option.

LeaVerou added a commit that referenced this issue Sep 3, 2023
LeaVerou added a commit that referenced this issue Sep 3, 2023
@LeaVerou
Copy link
Member

LeaVerou commented Sep 3, 2023

Done, we can probably close this now.
In the end display() does its own stripping of none so we ended up not needing the option in serialize() so I removed it.

@LeaVerou LeaVerou closed this as completed Sep 3, 2023
@svgeesus
Copy link
Member Author

svgeesus commented Oct 2, 2023

@LeaVerou our color parsing tests are still failing because they expect to find NaN in coords but find null instead.

@svgeesus svgeesus reopened this Oct 2, 2023
@LeaVerou
Copy link
Member

LeaVerou commented Feb 9, 2024

@LeaVerou our color parsing tests are still failing because they expect to find NaN in coords but find null instead.

They're all passing, so closing this again

@LeaVerou LeaVerou closed this as completed Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec-parity Parity with the CSS Color specs
Projects
None yet
Development

No branches or pull requests

2 participants