-
Notifications
You must be signed in to change notification settings - Fork 546
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
feat: support modern css colors #347
Conversation
cc @zyyv Alright, changing of the CIELab white reference point can now be done using this API: chroma('hotpink').lab(); // [65.49,64.24,-10.65]
chroma.setLabWhitePoint('D50');
chroma('hotpink').lab(); // [65.86,63.27,-9.64] This will affect the CIELab color spaces Lab and Lch. I thought this makes it easier to just switch once and for all rather than having to pass the white point as additional argument in all the places where you can define an output mode. More importantly, chroma.js will ensure that when you export a color as a CSS Lab string, it uses the D50 white point. Otherwise, the color would show up differently in a browser. |
I'll add the other CSS color spaces Lch, Oklab, and Oklch before merging this. |
Dang, of course, OKLab is also dependent on a white reference point, and according to the official paper by Björn Ottosson, it's hard-coded to the D65 illuminant:
But as far as I can see, W3C has adapted their implementation of I've solved this problem for the CIE Lab space, but I don't know if I can also do this for the Oklab space. We're using the official conversion matrices, which are hard-coded to D65.
|
or perhaps I'm misunderstanding something here. In any case, W3C seems to be using a more complicated method to convert from RGB to OKLab and back. Fortunately, they've published the JS code for their conversions, so we could try to re-use it: https://www.w3.org/TR/css-color-4/#color-conversion-code |
merging this now, and will fix the oklab issues in another PR. |
CSS now supports a modern syntax and the one currently implemented in chroma.js is rebranded as "legacy". So we should go with the times and change the default output of
color.css()
to the modern syntax.Since this is a breaking change I think we should bump the version number to 3.
This branch will also add support for Lab, Lch, OkLab, and OkLch CSS exports, e.g.
getLabWhitePoint
andsetLabWhitePoint
.css('lab')
.css('lch')
.css('oklab')
.css('oklch')