Skip to content

Commit c93b7f6

Browse files
committed
Revert contrast() changes in 2.7.1
1 parent 5621cb9 commit c93b7f6

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

lib/less/functions/color.js

+16-24
Original file line numberDiff line numberDiff line change
@@ -266,41 +266,33 @@ colorFunctions = {
266266
greyscale: function (color) {
267267
return colorFunctions.desaturate(color, new Dimension(100));
268268
},
269-
contrast: function (color, color1, color2, threshold) {
270-
// Return which of `color1` and `color2` has the greatest contrast with `color`
271-
// according to the standard WCAG contrast ratio calculation.
272-
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
273-
// The threshold param is no longer used, in line with SASS.
269+
contrast: function (color, dark, light, threshold) {
274270
// filter: contrast(3.2);
275271
// should be kept as is, so check for color
276272
if (!color.rgb) {
277273
return null;
278274
}
279-
if (typeof color1 === 'undefined') {
280-
color1 = colorFunctions.rgba(0, 0, 0, 1.0);
275+
if (typeof light === 'undefined') {
276+
light = colorFunctions.rgba(255, 255, 255, 1.0);
281277
}
282-
if (typeof color2 === 'undefined') {
283-
color2 = colorFunctions.rgba(255, 255, 255, 1.0);
278+
if (typeof dark === 'undefined') {
279+
dark = colorFunctions.rgba(0, 0, 0, 1.0);
284280
}
285-
var contrast1, contrast2;
286-
var luma = color.luma();
287-
var luma1 = color1.luma();
288-
var luma2 = color2.luma();
289-
// Calculate contrast ratios for each color
290-
if (luma > luma1) {
291-
contrast1 = (luma + 0.05) / (luma1 + 0.05);
292-
} else {
293-
contrast1 = (luma1 + 0.05) / (luma + 0.05);
281+
//Figure out which is actually light and dark!
282+
if (dark.luma() > light.luma()) {
283+
var t = light;
284+
light = dark;
285+
dark = t;
294286
}
295-
if (luma > luma2) {
296-
contrast2 = (luma + 0.05) / (luma2 + 0.05);
287+
if (typeof threshold === 'undefined') {
288+
threshold = 0.43;
297289
} else {
298-
contrast2 = (luma2 + 0.05) / (luma + 0.05);
290+
threshold = number(threshold);
299291
}
300-
if (contrast1 > contrast2) {
301-
return color1;
292+
if (color.luma() < threshold) {
293+
return light;
302294
} else {
303-
return color2;
295+
return dark;
304296
}
305297
},
306298
argb: function (color) {

lib/less/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = function(environment, fileManagers) {
22
var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;
33

44
var less = {
5-
version: [2, 7, 1],
5+
version: [2, 7, 2],
66
data: require('./data'),
77
tree: require('./tree'),
88
Environment: (Environment = require("./environment/environment")),

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "less",
3-
"version": "2.7.1",
3+
"version": "2.7.2",
44
"description": "Leaner CSS",
55
"homepage": "http://lesscss.org",
66
"author": {

0 commit comments

Comments
 (0)