Skip to content

Commit

Permalink
Introduce luminance function.
Browse files Browse the repository at this point in the history
The behaviour of this function is identical to luma prior to LESS 1.7.
  • Loading branch information
Roel van Duijnhoven committed Feb 27, 2014
1 parent 193ce01 commit e7389a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/less/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ tree.functions = {
luma: function (color) {
return new(tree.Dimension)(Math.round(color.luma() * color.alpha * 100), '%');
},
luminance: function (color) {
var luminance =
(0.2126 * color.rgb[0] / 255)
+ (0.7152 * color.rgb[1] / 255)
+ (0.0722 * color.rgb[2] / 255);

return new(tree.Dimension)(Math.round(luminance * color.alpha * 100), '%');
},
saturate: function (color, amount) {
// filter: saturate(3.2);
// should be kept as is, so check for color
Expand Down
6 changes: 5 additions & 1 deletion test/css/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
luma-yellow: 93%;
luma-cyan: 79%;
luma-differs-from-luminance: 24%;
luma-white-alpha: 50%;
luminance-white: 100%;
luminance-black: 0%;
luminance-black-alpha: 0%;
luminance-red: 21%;
luminance-differs-from-luma: 36%;
contrast-filter: contrast(30%);
saturate-filter: saturate(5%);
contrast-white: #000000;
Expand Down
6 changes: 5 additions & 1 deletion test/less/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
luma-yellow: luma(#ffff00);
luma-cyan: luma(#00ffff);
luma-differs-from-luminance: luma(#ff3600);
luma-white-alpha: luma(rgba(255,255,255,0.5));
luminance-white: luma(#fff);
luminance-black: luma(#000);
luminance-black-alpha: luma(rgba(0,0,0,0.5));
luminance-red: luma(#ff0000);
luminance-differs-from-luma: luminance(#ff3600);
contrast-filter: contrast(30%);
saturate-filter: saturate(5%);
contrast-white: contrast(#fff);
Expand Down

0 comments on commit e7389a0

Please sign in to comment.