Skip to content

Commit e7389a0

Browse files
author
Roel van Duijnhoven
committed
Introduce luminance function.
The behaviour of this function is identical to luma prior to LESS 1.7.
1 parent 193ce01 commit e7389a0

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/less/functions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ tree.functions = {
9595
luma: function (color) {
9696
return new(tree.Dimension)(Math.round(color.luma() * color.alpha * 100), '%');
9797
},
98+
luminance: function (color) {
99+
var luminance =
100+
(0.2126 * color.rgb[0] / 255)
101+
+ (0.7152 * color.rgb[1] / 255)
102+
+ (0.0722 * color.rgb[2] / 255);
103+
104+
return new(tree.Dimension)(Math.round(luminance * color.alpha * 100), '%');
105+
},
98106
saturate: function (color, amount) {
99107
// filter: saturate(3.2);
100108
// should be kept as is, so check for color

test/css/functions.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
luma-yellow: 93%;
2626
luma-cyan: 79%;
2727
luma-differs-from-luminance: 24%;
28-
luma-white-alpha: 50%;
28+
luminance-white: 100%;
29+
luminance-black: 0%;
30+
luminance-black-alpha: 0%;
31+
luminance-red: 21%;
32+
luminance-differs-from-luma: 36%;
2933
contrast-filter: contrast(30%);
3034
saturate-filter: saturate(5%);
3135
contrast-white: #000000;

test/less/functions.less

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
luma-yellow: luma(#ffff00);
3030
luma-cyan: luma(#00ffff);
3131
luma-differs-from-luminance: luma(#ff3600);
32-
luma-white-alpha: luma(rgba(255,255,255,0.5));
32+
luminance-white: luma(#fff);
33+
luminance-black: luma(#000);
34+
luminance-black-alpha: luma(rgba(0,0,0,0.5));
35+
luminance-red: luma(#ff0000);
36+
luminance-differs-from-luma: luminance(#ff3600);
3337
contrast-filter: contrast(30%);
3438
saturate-filter: saturate(5%);
3539
contrast-white: contrast(#fff);

0 commit comments

Comments
 (0)