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
30 changes: 30 additions & 0 deletions lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,36 @@ protected function lib_percentage($arg) {
return array("number", $num*100, "%");
}

// Mix color with white in variable proportion. It is the same as calling mix(#ffffff, @color, @weight)
// tint(@color, [@weight: 50%]);
// Returns: color
// http://lesscss.org/functions/#color-operations-tint
protected function lib_tint($args) {
$white = ['color', 255, 255, 255];
if ($args[0] == 'color') {
return $this->lib_mix([ 'list', ',', [$white, $args] ]);
} elseif ($args[0] == "list" && count($args[2]) == 2) {
return $this->lib_mix([ $args[0], $args[1], [$white, $args[2][0], $args[2][1]] ]);
} else {
$this->throwError("tint expects (color, weight)");
}
}

// Mix color with black in variable proportion. It is the same as calling mix(#000000, @color, @weight)
// shade(@color, [@weight: 50%]);
// Returns: color
// http://lesscss.org/functions/#color-operations-shade
protected function lib_shade($args) {
$black = ['color', 0, 0, 0];
if ($args[0] == 'color') {
return $this->lib_mix([ 'list', ',', [$black, $args] ]);
} elseif ($args[0] == "list" && count($args[2]) == 2) {
return $this->lib_mix([ $args[0], $args[1], [$black, $args[2][0], $args[2][1]] ]);
} else {
$this->throwError("tint expects (color, weight)");
Copy link

@theFeu theFeu Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"shade expects (color, weight)"

would probably be a better message ;)
but thanks a lot for saving me some time writing this :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've fixed this as part of the merge.

}
}

// mixes two colors by weight
// mix(@color1, @color2, [@weight: 50%]);
// http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method
Expand Down
5 changes: 5 additions & 0 deletions tests/inputs/colors.less
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ body {
two1: fadeout(#029f23, 10%);
two2: fadein(#029f23, -10%);

tint1: tint(#e0e0e0);
tint2: tint(#e0e0e0, 40%);

shade1: shade(#e0e0e0);
shade2: shade(#e0e0e0, 40%);

three1: fadein(rgba(1,2,3, 0.5), 10%);
three2: fadeout(rgba(1,2,3, 0.5), -10%);
Expand Down
4 changes: 4 additions & 0 deletions tests/outputs/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ body {
one2: #abcdef;
two1: rgba(2,159,35,0.9);
two2: rgba(2,159,35,0.9);
tint1: #f0f0f0;
tint2: #ececec;
shade1: #707070;
shade2: #868686;
three1: rgba(1,2,3,0.6);
three2: rgba(1,2,3,0.6);
four1: rgba(1,2,3,0);
Expand Down