mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Add contrast function following the same format as sass. Added tests.
Added luma calculation.
This commit is contained in:
committed by
Luke Page
parent
7fc6275ba8
commit
bb0886fcc9
@@ -44,6 +44,12 @@ tree.functions = {
|
||||
alpha: function (color) {
|
||||
return new(tree.Dimension)(color.toHSL().a);
|
||||
},
|
||||
luma: function (color) {
|
||||
return new(tree.Dimension)(Math.round((0.2126 * (color.rgb[0]/255) +
|
||||
0.7152 * (color.rgb[1]/255) +
|
||||
0.0722 * (color.rgb[2]/255))
|
||||
* color.alpha * 100), '%');
|
||||
},
|
||||
saturate: function (color, amount) {
|
||||
var hsl = color.toHSL();
|
||||
|
||||
@@ -127,6 +133,24 @@ tree.functions = {
|
||||
greyscale: function (color) {
|
||||
return this.desaturate(color, new(tree.Dimension)(100));
|
||||
},
|
||||
contrast: function (color, dark, light, threshold) {
|
||||
if (typeof light === 'undefined') {
|
||||
light = this.rgba(255, 255, 255, 1.0);
|
||||
}
|
||||
if (typeof dark === 'undefined') {
|
||||
dark = this.rgba(0, 0, 0, 1.0);
|
||||
}
|
||||
if (typeof threshold === 'undefined') {
|
||||
threshold = 0.43;
|
||||
} else {
|
||||
threshold = threshold.value;
|
||||
}
|
||||
if (((0.2126 * (color.rgb[0]/255) + 0.7152 * (color.rgb[1]/255) + 0.0722 * (color.rgb[2]/255)) * color.alpha) < threshold) {
|
||||
return light;
|
||||
} else {
|
||||
return dark;
|
||||
}
|
||||
},
|
||||
e: function (str) {
|
||||
return new(tree.Anonymous)(str instanceof tree.JavaScript ? str.evaluated : str);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user