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 CSS Color Module Level 4 #47

Closed
12 tasks done
liZe opened this issue Apr 28, 2022 · 9 comments · Fixed by #53
Closed
12 tasks done

Support CSS Color Module Level 4 #47

liZe opened this issue Apr 28, 2022 · 9 comments · Fixed by #53

Comments

@liZe
Copy link
Member

liZe commented Apr 28, 2022

(Current code is in the color4 branch.)

The primary change, compared to CSS Color 3, is that CSS colors are no longer restricted to the narrow gamut of sRGB.

To support this, several brand new features have been added:

Other technical changes:

  • Serialization of <color> is now specified here, rather than in the CSS Object Model
  • hwb() function, for specifying sRGB colors in the HWB notation.
  • Addition of named color rebeccapurple.

In addition, there have been some syntactic changes:

@liZe
Copy link
Member Author

liZe commented Sep 6, 2022

Kudos to @ax-sc!

The level 3 test suite passes with the color4 module 🚀. I’ll add more tests in the test suite when everything in the list above is resolved.

Note that CMYK support has been postponed to level 5 (it was already postponed from level 3 to 4).

@liZe
Copy link
Member Author

liZe commented Sep 7, 2022

The level 3 test suite passes with the color4 module .

Well, it doesn’t. Thanks to isort I’ve found that imports were broken. But news are still really good: the tests failing are the ones that are supposed to give different results with Level 3 and Level 4.

I’ll open a PR to split 3 and 4 in the testing suite. (Edit: CourtBouillon/css-parsing-tests#10.)

@ax-sc
Copy link
Contributor

ax-sc commented Sep 15, 2022

Thanks for moving this forward, @liZe. I added some test cases for the parts of the specification introduced with #48 in CourtBouillon/css-parsing-tests#11.

If you want, i can have a look at the missing lab(), lch, oklab and oklch functions but i´m not sure when i will find the time do so, so i can not promise to have them implemented at a specific date.

@liZe
Copy link
Member Author

liZe commented Sep 15, 2022

I added some test cases for the parts of the specification introduced with #48 in CourtBouillon/css-parsing-tests#11.

Amazing, thanks a lot!

If you want, i can have a look at the missing lab(), lch, oklab and oklch functions but i´m not sure when i will find the time do so, so i can not promise to have them implemented at a specific date.

It will be probably more difficult to test, because these functions don’t directly return sRGB colors. I have to read the specification again and again to understand how "device-independent colors" work and thus how they can be tested. If you know anything about gamuts and color spaces, don’t hesitate to share your hints! It could be easier to understand than Wikipedia’s very informative but quite dense pages.

@ax-sc
Copy link
Contributor

ax-sc commented Sep 15, 2022

It will be probably more difficult to test, because these functions don’t directly return sRGB colors.

Yes, that´s the reason why i did not implement them in the first step.

I have to read the specification again and again to understand how "device-independent colors" work and thus how they can be tested. If you know anything about gamuts and color spaces, don’t hesitate to share your hints! It could be easier to understand than Wikipedia’s very informative but quite dense pages.

Although i know some things about color spaces etc., i would definitely need to look at the specification myself again as well. I will keep you updated and try to summarise the most important information once i have done this.

@liZe
Copy link
Member Author

liZe commented Sep 18, 2022

Although i know some things about color spaces etc., i would definitely need to look at the specification myself again as well. I will keep you updated and try to summarise the most important information once i have done this.

I’ve added some code to handle the missing lab and oklab functions. I hope that I’ve understood the specifications correctly, don’t hesitate to tell me what’s wrong!

@liZe
Copy link
Member Author

liZe commented Sep 19, 2022

Handling the none value adds an interesting complexity. And by "interesting", I mean another word.

As we sometimes convert the original value into "normalized" value (for example hsl to rgb or now lab to xyz), there’s no way to keep the information of the original unknown channels. As a low-level CSS parser, it seems important to keep this information that could be useful for example for gradients (and could become even more important in level 5 when it’s possible to extrapolate colors with CSS functions 🤯️).

Leading to this question: is the new standard Color class a good idea? It seems to be both right and quite easy to use as it is now, but it’s obviously not compatible with the none keyword.

A solution would be to keep this class to store the computed value, but add the original function in other fields. This way, we could keep the current "simple" computed fields while keeping the original fields (possibly containing none) for cases where it’s useful.

@jmmelko
Copy link

jmmelko commented Feb 18, 2023

Sorry to interrupt, do you think it is safe to pip install this branch? I need hsl support.
Or is there a chance that you do a pull request before solving 100% of what you planned to do?

@liZe
Copy link
Member Author

liZe commented Feb 20, 2023

I need hsl support.

As explained in Kozea/CairoSVG#379, hsl is already supported in Level 3.

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

Successfully merging a pull request may close this issue.

3 participants