Skip to content
Open
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
10 changes: 8 additions & 2 deletions lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1242,12 +1242,18 @@ protected function lib_contrast($args) {
$darkColor = array('color', 0, 0, 0);
$lightColor = array('color', 255, 255, 255);
$threshold = 0.43;

if ( $args[0] == 'list' ) {
$inputColor = ( isset($args[2][0]) ) ? $this->assertColor($args[2][0]) : $lightColor;
$darkColor = ( isset($args[2][1]) ) ? $this->assertColor($args[2][1]) : $darkColor;
$lightColor = ( isset($args[2][2]) ) ? $this->assertColor($args[2][2]) : $lightColor;
$threshold = ( isset($args[2][3]) ) ? $this->assertNumber($args[2][3]) : $threshold;

if( isset($args[2][3]) ) {
if( isset($args[2][3][2]) && $args[2][3][2] == '%' ) {
$args[2][3][1] /= 100;
unset($args[2][3][2]);
}
$threshold = $this->assertNumber($args[2][3]);
}
}
else {
$inputColor = $this->assertColor($args);
Expand Down
3 changes: 3 additions & 0 deletions tests/inputs/colors.less
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ fade {
.contrast {
color1: contrast(#000, red, blue);
color2: contrast(#fff, red, blue);
color3: contrast(#333, #000, #fff); // Default threshold
color4: contrast(#333, #000, #fff, 0.1); // Threshold weighted towards dark colour
color5: contrast(#333, #000, #fff, 10%); // Threshold weighted as percentage
}

.percent {
Expand Down
3 changes: 3 additions & 0 deletions tests/outputs/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ fade {
.contrast {
color1: #ff0000;
color2: #0000ff;
color3: #ffffff;
color4: #000000;
color5: #000000;
}
.percent {
per: 50%;
Expand Down