Skip to content

Commit

Permalink
Revert contrast() changes in 2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-dean committed Jan 5, 2017
1 parent 5621cb9 commit c93b7f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
40 changes: 16 additions & 24 deletions lib/less/functions/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,41 +266,33 @@ colorFunctions = {
greyscale: function (color) {
return colorFunctions.desaturate(color, new Dimension(100));
},
contrast: function (color, color1, color2, threshold) {
// Return which of `color1` and `color2` has the greatest contrast with `color`
// according to the standard WCAG contrast ratio calculation.
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
// The threshold param is no longer used, in line with SASS.
contrast: function (color, dark, light, threshold) {
// filter: contrast(3.2);
// should be kept as is, so check for color
if (!color.rgb) {
return null;
}
if (typeof color1 === 'undefined') {
color1 = colorFunctions.rgba(0, 0, 0, 1.0);
if (typeof light === 'undefined') {
light = colorFunctions.rgba(255, 255, 255, 1.0);
}
if (typeof color2 === 'undefined') {
color2 = colorFunctions.rgba(255, 255, 255, 1.0);
if (typeof dark === 'undefined') {
dark = colorFunctions.rgba(0, 0, 0, 1.0);
}
var contrast1, contrast2;
var luma = color.luma();
var luma1 = color1.luma();
var luma2 = color2.luma();
// Calculate contrast ratios for each color
if (luma > luma1) {
contrast1 = (luma + 0.05) / (luma1 + 0.05);
} else {
contrast1 = (luma1 + 0.05) / (luma + 0.05);
//Figure out which is actually light and dark!
if (dark.luma() > light.luma()) {
var t = light;
light = dark;
dark = t;
}
if (luma > luma2) {
contrast2 = (luma + 0.05) / (luma2 + 0.05);
if (typeof threshold === 'undefined') {
threshold = 0.43;
} else {
contrast2 = (luma2 + 0.05) / (luma + 0.05);
threshold = number(threshold);
}
if (contrast1 > contrast2) {
return color1;
if (color.luma() < threshold) {
return light;
} else {
return color2;
return dark;
}
},
argb: function (color) {
Expand Down
2 changes: 1 addition & 1 deletion lib/less/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function(environment, fileManagers) {
var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;

var less = {
version: [2, 7, 1],
version: [2, 7, 2],
data: require('./data'),
tree: require('./tree'),
Environment: (Environment = require("./environment/environment")),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "less",
"version": "2.7.1",
"version": "2.7.2",
"description": "Leaner CSS",
"homepage": "http://lesscss.org",
"author": {
Expand Down

0 comments on commit c93b7f6

Please sign in to comment.