Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/less/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ tree.functions = {
greyscale: function (color) {
return this.desaturate(color, new(tree.Dimension)(100));
},
contrast: function (color, light, dark) {
var hsl = color.toHSL();
if (arguments.length == 1) {
if (hsl.l > 0.5) {
return this.rgba(0, 0, 0, 1.0);
} else {
return this.rgba(255, 255, 255, 1.0);
}
} else if (arguments.length == 3) {
if (hsl.l > 0.5) {
return dark;
} else {
return light;
}
}
},
e: function (str) {
return new(tree.Anonymous)(str instanceof tree.JavaScript ? str.evaluated : str);
},
Expand Down
4 changes: 4 additions & 0 deletions test/css/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
greyscale: #2e2e2e;
spin-p: #bf6a40;
spin-n: #bf4055;
contrast-white: #000000;
contrast-black: #ffffff;
contrast-light: #111111;
contrast-dark: #eeeeee;
format: "rgb(32, 128, 64)";
format-string: "hello world";
format-multiple: "hello earth 2";
Expand Down
4 changes: 4 additions & 0 deletions test/less/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
greyscale: greyscale(#203c31);
spin-p: spin(hsl(340, 50%, 50%), 40);
spin-n: spin(hsl(30, 50%, 50%), -40);
contrast-white: contrast(#fff);
contrast-black: contrast(#000);
contrast-light: contrast(#fff, #eeeeee, #111111);
contrast-dark: contrast(#000, #eeeeee, #111111);
format: %("rgb(%d, %d, %d)", @r, 128, 64);
format-string: %("hello %s", "world");
format-multiple: %("hello %s %d", "earth", 2);
Expand Down