diff --git a/lessc.inc.php b/lessc.inc.php index 2292f219..3131e28a 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -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)"); + } + } + // mixes two colors by weight // mix(@color1, @color2, [@weight: 50%]); // http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method diff --git a/tests/inputs/colors.less b/tests/inputs/colors.less index 7fd47a3c..90d01728 100644 --- a/tests/inputs/colors.less +++ b/tests/inputs/colors.less @@ -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%); diff --git a/tests/outputs/colors.css b/tests/outputs/colors.css index 5310ffb0..9a6243c6 100644 --- a/tests/outputs/colors.css +++ b/tests/outputs/colors.css @@ -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);