-
Notifications
You must be signed in to change notification settings - Fork 182
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() and lch() color previews added #306
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR, it looks promising. I added comments.
|
Done! Didn't know about the formatter, I'll keep that in mind going forward. And I've replaced const when possible. Is the functionality required all covered by this? I'll add more test cases and the other two functions if so. Thank you. |
Thank you for this @GauravB159! I've gone over these changes and the conversions don't seem to be accurate. Good reference code can be found here : https://github.com/w3c/csswg-drafts/tree/main/css-color-4 We also have a bunch of tests : https://github.com/csstools/postcss-plugins/blob/main/plugins/postcss-lab-function/test/basic.display-p3-false.preserve-true.expect.css But best of all would be to use https://github.com/LeaVerou/color.js, if @aeschli is open to adding this as a dependency? One important aspect that doesn't seem to be covered here is out of gamut color handling. It is not possible to round trip |
Hi @romainmenke I used this webpage for a reference for the formulae. Is there somewhere I could see the correct values? I was using this online converter to verify my values. It does give values in decimals, but rgb requires whole numbers I guess, so I have rounded the values at the end. Maybe that is causing an issue?
Thanks for your help! I'll check out the code you linked, maybe there's some issue with the formula implementation. |
Thanks for the great info @romainmenke ! |
Rounding errors might also cause this, but those would be very small deviations. I think there are three options :
The "right" option depends on the function of this feature in VSCode :
Got it! The code linked from the CSSTools repo is a port to TypeScript from the reference implementation that exists in the csswg-drafts repo. It has the same W3C license because the only thing I did was add typings. |
@romainmenke Yeah, I understand what you're saying. Now that you mention it, I remember there were negative and valuss greater than 255 after converting to sRGB. I clamped those values to 0-255 which might be causing the loss. @aeschli Which option do you recommend we go with? We could store the negative values and clamp them just while displaying the color possibly. |
Conversion from a wide to a narrow gamut is naturally lossy, so that should not be avoided. In the case of the color picker, the users can be informed that conversion is lossy, like in Chrome's DevTools color picker: https://developer.chrome.com/docs/devtools/css/color#convert-colors This approach may require ditching the click-to-convert in favor of a dropdown. |
When displaying a color on a screen or in print, yes. But wide gamut colors can still be represented in narrow gamut notations by going beyond the value ranges that describe the boundaries of the narrower gamut.
There is no mathematical reason to make these lossy when converting from one notation to another. |
Interesting,
fits VSCode usecase the best, though I'm curious how would |
Issue #305
Main Repo Issue microsoft/vscode#165207