Note: The source code for v0.5.0 shows that lessphp is also now checking luma values instead of lightness (used in v0.4.0) and hence upgrading to the latest version should also solve the problem.
This doesn't seem to be a bug but rather a difference in terms of how the contrast
function works in Less.js, Less.PHP and lessphp (upto v0.4.0).
In Less.js and Less.PHP, the contrast function decides on output color based on the luma
value of the reference color. The luma
values of the 2 colors given in question are less than 43% and hence they output the @lightcolor
.
You can check the output of the below code at Less2CSS.org (Online Less.js compiler) and Online Less.PHP compiler.
#sample{
color:contrast(@color1, @darkcolor, @lightcolor);
luma-color1: luma(@color1);
luma-color2: luma(@color2);
}
@color1: #2196F3;
@color2: #03A9F4;
@darkcolor: black;
@lightcolor: white;
The lessphp documentation however describes the contrast
function as follows: (looks like the doc is not updated with v0.5.0 changes)
contrast(color, dark, light)
— if color has a lightness value greater than 50% then dark is returned, otherwise return light.
The lightness
value for the first color is 54% while that for the second color is 48%. Because of this, lessphp outputs the @darkcolor
when the first color is used as reference and @lightcolor
when the second color is used as reference.
You can try the below code at the Online lessphp compiler for v0.4.0 to see what I mean:
#sample{
color:contrast(@color2, @darkcolor, @lightcolor);
lightness-color1: lightness(@color1);
lightness-color2: lightness(@color2);
}
@color1: #2196F3;
@color2: #03A9F4;
@darkcolor: black;
@lightcolor: white;
It could very easily be that lessphp introduced the contrast
function at first based on lightness
value before the official Less (the JS version) compiler implemented the same function but based it on luma
instead of lightness
value. The below statement could be found in the Less documentation:
This function works the same way as the contrast function in Compass for SASS. In accordance with WCAG 2.0, colors are compared using their gamma-corrected luma value, not their lightness.