Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/less/less.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage committed Mar 20, 2015
2 parents 936b78c + a6dca88 commit 5c0179d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
54 changes: 42 additions & 12 deletions lib/less/functions/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,50 +141,80 @@ colorFunctions = {

return new Dimension(luminance * color.alpha * 100, '%');
},
saturate: function (color, amount) {
saturate: function (color, amount, method) {
// filter: saturate(3.2);
// should be kept as is, so check for color
if (!color.rgb) {
return null;
}
var hsl = color.toHSL();

hsl.s += amount.value / 100;
if (typeof method !== "undefined" && method.value === "relative") {
hsl.s += hsl.s * amount.value / 100;
}
else {
hsl.s += amount.value / 100;
}
hsl.s = clamp(hsl.s);
return hsla(hsl);
},
desaturate: function (color, amount) {
desaturate: function (color, amount, method) {
var hsl = color.toHSL();

hsl.s -= amount.value / 100;
if (typeof method !== "undefined" && method.value === "relative") {
hsl.s -= hsl.s * amount.value / 100;
}
else {
hsl.s -= amount.value / 100;
}
hsl.s = clamp(hsl.s);
return hsla(hsl);
},
lighten: function (color, amount) {
lighten: function (color, amount, method) {
var hsl = color.toHSL();

hsl.l += amount.value / 100;
if (typeof method !== "undefined" && method.value === "relative") {
hsl.l += hsl.l * amount.value / 100;
}
else {
hsl.l += amount.value / 100;
}
hsl.l = clamp(hsl.l);
return hsla(hsl);
},
darken: function (color, amount) {
darken: function (color, amount, method) {
var hsl = color.toHSL();

hsl.l -= amount.value / 100;
if (typeof method !== "undefined" && method.value === "relative") {
hsl.l -= hsl.l * amount.value / 100;
}
else {
hsl.l -= amount.value / 100;
}
hsl.l = clamp(hsl.l);
return hsla(hsl);
},
fadein: function (color, amount) {
fadein: function (color, amount, method) {
var hsl = color.toHSL();

hsl.a += amount.value / 100;
if (typeof method !== "undefined" && method.value === "relative") {
hsl.a += hsl.a * amount.value / 100;
}
else {
hsl.a += amount.value / 100;
}
hsl.a = clamp(hsl.a);
return hsla(hsl);
},
fadeout: function (color, amount) {
fadeout: function (color, amount, method) {
var hsl = color.toHSL();

hsl.a -= amount.value / 100;
if (typeof method !== "undefined" && method.value === "relative") {
hsl.a -= hsl.a * amount.value / 100;
}
else {
hsl.a -= amount.value / 100;
}
hsl.a = clamp(hsl.a);
return hsla(hsl);
},
Expand Down
8 changes: 8 additions & 0 deletions test/css/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#built-in {
escaped: -Some::weird(#thing, y);
lighten: #ffcccc;
lighten-relative: #ff6666;
darken: #330000;
darken-relative: #990000;
saturate: #203c31;
saturate-relative: #28342f;
desaturate: #29332f;
desaturate-relative: #233930;
greyscale: #2e2e2e;
hsl-clamp: #ffffff;
spin-p: #bf6a40;
Expand Down Expand Up @@ -118,6 +122,10 @@
shade-negative: #868686;
fade-out: rgba(255, 0, 0, 0.95);
fade-in: rgba(255, 0, 0, 0.95);
fade-out-relative: rgba(255, 0, 0, 0.95);
fade-in-relative: rgba(255, 0, 0, 0.945);
fade-out2: rgba(255, 0, 0, 0);
fade-out2-relative: rgba(255, 0, 0, 0.25);
hsv: #4d2926;
hsva: rgba(77, 40, 38, 0.2);
mix: #ff3300;
Expand Down
12 changes: 10 additions & 2 deletions test/less/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
@r: 32;
escaped: e("-Some::weird(#thing, y)");
lighten: lighten(#ff0000, 40%);
lighten-relative: lighten(#ff0000, 40%, relative);
darken: darken(#ff0000, 40%);
darken-relative: darken(#ff0000, 40%, relative);
saturate: saturate(#29332f, 20%);
saturate-relative: saturate(#29332f, 20%, relative);
desaturate: desaturate(#203c31, 20%);
desaturate-relative: desaturate(#203c31, 20%, relative);
greyscale: greyscale(#203c31);
hsl-clamp: hsl(380, 150%, 150%);
spin-p: spin(hsl(340, 50%, 50%), 40);
Expand Down Expand Up @@ -124,9 +128,13 @@
shade-percent: shade(#777777, 13%);
shade-negative: shade(#777777, -13%);

fade-out: fadeOut(red, 5%); // support fadeOut and fadeout
fade-out: fadeout(red, 5%); // support fadeOut and fadeout
fade-in: fadein(fadeout(red, 10%), 5%);

fade-out-relative: fadeout(red, 5%,relative);
fade-in-relative: fadein(fadeout(red, 10%, relative), 5%, relative);
fade-out2: fadeout(fadeout(red, 50%), 50%);
fade-out2-relative: fadeout(fadeout(red, 50%, relative), 50%, relative);

hsv: hsv(5, 50%, 30%);
hsva: hsva(3, 50%, 30%, 0.2);

Expand Down

0 comments on commit 5c0179d

Please sign in to comment.