-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Let luma
follow spec
#1890
Let luma
follow spec
#1890
Conversation
The `luma` function found in LESS is not implemented as defined in the specification (http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef).
Well, there's difference between In general I'm somewhat neutral about this change but... if the function uses |
The diference between the two implementations is that the one @roelvanduijnhoven suggests includes gamma correction and uses the sRGB space - the coefficients are the same, and the resuts will not be that different. Strictly speaking, This calculation also appears inline in the contrast function as I couldn't work out how to call this one from there, so it either needs copying there, or that figured out! I'm +1 for using this version, though the test cases need updating too. |
@marcus luma is simply a function on the color object. Thus one can access I'll update tests.
|
Tests are updated. |
|
It looks like this should be merged into 2.0.0 since it is a breaking change. Any objections to that plan? |
Strictly speaking it's a bug fix rather than a breaking change, and changing the calculation won't break anyones Less files. It's also a reasonably subtle change, and more likely to match what was actually expected. You could push it to 2.0, but I don't see too much harm in doing it now. |
Okay.. should contrast use luma or luminance? The thing with contrast is it could produce some quite big changes... |
p.s. I'm just about ready to release 1.7.0 apart from this and 2.0.0 shouldn't be more than a couple of months away. I don't think it would be good to go into a patch release 1.7.x so... would be good to make a decision soon ;) |
The W3C spec says to use the gamma-corrected calculation so that's the right thing to do really. If we are going to roll this into 1.7, I think we should leave the current calc in there but rename it |
@Synchro sounds like a plan, but which should contrast use? |
Contrast should remain using luma (i.e. no code change needed there), though it will be using the new version. The change will be less obvious in the contrast function as it doesn't affect the colours directly, but it may choose a different one in some edge cases. |
See #1894 - it seems there is still a demand to have an inline conditional like this. I'm more concerned about contrast being a breaking change than luma so for that reason I'm leaning towards making the change but leaving contrast using luminence so it is unchanged and then changing contrast in 2.0 |
Here is an example showing the difference between the two calculations when used in a contrast function. The left hand table is the current luminance calculation, the right hand is the new luma calculation. With the stock 43% threshold, luma is generally biased towards lighter results, I think it's hard to call which looks better - there are cases either way: compare Just to complicate things further 😇, I ran into another discussion of these calculations, suggesting that because the input colours are already gamma-corrected, you should un-correct them before calculating luma. |
okay then I'm taking this into 1.7 (scream now or hold your peace!) and adding a luminence function for backwards compatability and fixing the tests so that contrast-low-threshold still comes out with the same colour (changing threshold from 10% to 9% seems to do it) |
Allright. I'm all for it. I'll finish of my PR using input given in this thread.
|
The behaviour of this function is identical to luma prior to LESS 1.7.
PR is updated. I chose to implement luminance as a function instead of adding it as a method on the Color prototype. |
Cool perfect. I was part of the way through making the changes myself, but I will just take yours. |
Less 1.7 use a different way to calculate the luma() of a color, see: less/less.js#1890 luminance() gives the "old" value for backward compatibility.
The
luma
function found in LESS is not implemented as defined in the specification (http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef).