Skip to content

Commit

Permalink
Rename LESS clamp() to clamp_less() to hopefully avoid conflicts with…
Browse files Browse the repository at this point in the history
… CSS clamp()
  • Loading branch information
Kier committed Feb 6, 2024
1 parent 6a84349 commit 0526825
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/Less/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function operate( $op, $a, $b ) {
}
}

public static function clamp( $val, $max = 1 ) {
public static function clamp_less($val, $max = 1 ) {
return min( max( $val, 0 ), $max );
}

Expand Down Expand Up @@ -87,9 +87,9 @@ public function hsl( $h, $s, $l ) {

public function hsla( $h, $s, $l, $a ) {
$h = fmod( self::number( $h ), 360 ) / 360; // Classic % operator will change float to int
$s = self::clamp( self::number( $s ) );
$l = self::clamp( self::number( $l ) );
$a = self::clamp( self::number( $a ) );
$s = self::clamp_less( self::number( $s ) );
$l = self::clamp_less( self::number( $l ) );
$a = self::clamp_less( self::number( $a ) );

$m2 = $l <= 0.5 ? $l * ( $s + 1 ) : $l + $s - $l * $s;

Expand Down Expand Up @@ -289,7 +289,7 @@ public function saturate( $color = null, $amount = null ) {
$hsl = $color->toHSL();

$hsl['s'] += $amount->value / 100;
$hsl['s'] = self::clamp( $hsl['s'] );
$hsl['s'] = self::clamp_less( $hsl['s'] );

return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}
Expand All @@ -308,7 +308,7 @@ public function desaturate( $color = null, $amount = null ) {

$hsl = $color->toHSL();
$hsl['s'] -= $amount->value / 100;
$hsl['s'] = self::clamp( $hsl['s'] );
$hsl['s'] = self::clamp_less( $hsl['s'] );

return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}
Expand All @@ -324,7 +324,7 @@ public function lighten( $color = null, $amount = null ) {
$hsl = $color->toHSL();

$hsl['l'] += $amount->value / 100;
$hsl['l'] = self::clamp( $hsl['l'] );
$hsl['l'] = self::clamp_less( $hsl['l'] );

return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}
Expand All @@ -339,7 +339,7 @@ public function darken( $color = null, $amount = null ) {

$hsl = $color->toHSL();
$hsl['l'] -= $amount->value / 100;
$hsl['l'] = self::clamp( $hsl['l'] );
$hsl['l'] = self::clamp_less( $hsl['l'] );

return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}
Expand All @@ -354,7 +354,7 @@ public function fadein( $color = null, $amount = null ) {

$hsl = $color->toHSL();
$hsl['a'] += $amount->value / 100;
$hsl['a'] = self::clamp( $hsl['a'] );
$hsl['a'] = self::clamp_less( $hsl['a'] );
return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}

Expand All @@ -368,7 +368,7 @@ public function fadeout( $color = null, $amount = null ) {

$hsl = $color->toHSL();
$hsl['a'] -= $amount->value / 100;
$hsl['a'] = self::clamp( $hsl['a'] );
$hsl['a'] = self::clamp_less( $hsl['a'] );
return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}

Expand All @@ -383,7 +383,7 @@ public function fade( $color = null, $amount = null ) {
$hsl = $color->toHSL();

$hsl['a'] = $amount->value / 100;
$hsl['a'] = self::clamp( $hsl['a'] );
$hsl['a'] = self::clamp_less( $hsl['a'] );
return $this->hsla( $hsl['h'], $hsl['s'], $hsl['l'], $hsl['a'] );
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Less/Tree/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function toCSS( $doNotCompress = false ) {

$values = [];
foreach ( $this->rgb as $c ) {
$values[] = Less_Functions::clamp( round( $c ), 255 );
$values[] = Less_Functions::clamp_less( round( $c ), 255 );
}
$values[] = $alpha;

Expand Down Expand Up @@ -199,7 +199,7 @@ public function compare( $x ) {
public function toHex( $v ) {
$ret = '#';
foreach ( $v as $c ) {
$c = Less_Functions::clamp( Less_Parser::round( $c ), 255 );
$c = Less_Functions::clamp_less( Less_Parser::round( $c ), 255 );
if ( $c < 16 ) {
$ret .= '0';
}
Expand Down

0 comments on commit 0526825

Please sign in to comment.