-
Notifications
You must be signed in to change notification settings - Fork 190
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
lab, lch, oklab and oklch syntax lowering does not support numeric values for L component #445
Comments
I've been poking at this over the past few days, out of curiosity. The underlying issue about parsing the functional notation, parsing the L component as either a number of a percentage. With that change, there is a follow-up issue for the relative component parsing, which is currently giving me trouble. In relative color syntax, the channel keywords now resolve to numbers (e.g. On a related note, the WPT tests have also been updated recently. They use the numeric syntax and also show some of the calculations. I updated the tests to this latest version, for completeness. I noticed while going through the specs, that the serialisation of the lab/lch/oklab/oklch component values has also changed since lightningcss' implementation. The components now are serialised as numbers base 10, instead of percentages. Serialised, L is [0,1] for oklab/oklch and [0,100] for lab/lch. So it makes sense to support the number or percentage parsing for round-tripping. Updating the serialisation can be done in another PR, it might need updates to the tests iirc. (It's possible I am missing something again 😅 ) |
Thanks for all your research on this! Should be fixed by above commit. For now I've left the serialization alone. Safari 15 implemented the old spec as well, and does not support numeric values for l or percentages for the other components, so serializing the old way is the most compatible. |
So it turns out that the way relative colors work also changed, which will break existing code using lightningcss. This is kinda unfortunate and I'm not sure what to do about it. w3c/csswg-drafts#7876 (comment) |
Yeah for nesting and custom media queries they are under an opt in flag (eg |
I opened a PR #465 to implement the latest spec changes for relative colors. Haven't decided how to release it yet since it is a breaking change. Wasn't really planning on doing Lightning CSS 2.0 yet, but I guess we could. Otherwise we could hold this change until then, or try to investigate backward compatibility but not sure if that's a good idea. If you have any ideas let me know. |
Thank you for your work on this 🙇 Looking at the PR clarifies some of the questions when I tried implementing this, and also how far-reaching the changes are (specifically changing the channel types for each colorspace, and carrying the types over during parsing). My main idea to delay a v2 release, would be to put this new implementation under a flag, such as Looking at the code, it seems like large parts of Another thought I had, was offering a custom transform (or would a codemod be better?), to rewrite relevant It would be nice to have some metrics about the usage of the relative syntax in lightningcss, to understand how wide the breakage would be. |
The
lab()
,lch()
,oklab()
andoklch()
functional notations support a numeric value for the L component. However, lightningcss only supports percentage values for those components, and bails out if a number is used.In other words, these two declarations should be equivalent and lowered to
background: #777
:But this is the output instead:
Link to the playground, showing the lack of lowering for the numeric L component
Expected behaviour
lch()
should allow numeric values of [0,100] for the L componentlab()
should allow numeric values of [0,100] for the L componentokch()
should allow numeric values of [0,1] for the L componentoklab()
should allow numeric values of [0,1] for the L componentNote the difference in the numeric range:
lch()
andlab()
define them as [0,100] corresponding to 0% and 100%, whileoklch
andoklab
define them as [0,1.0] corresponding to 0% and 100%.Reference for
lch()
andlab()
numeric rangeReference for
oklch()
andoklab()
numeric rangePlease let me know if there is any other information that I can provide, or whether I missed something! I would be happy to contribute a PR for this :)
The text was updated successfully, but these errors were encountered: