From 05268257a1a7c5b2976f5ac5d6d8bbfd78d430c9 Mon Sep 17 00:00:00 2001 From: Kier Darby Date: Tue, 6 Feb 2024 10:51:06 +0000 Subject: [PATCH] Rename LESS clamp() to clamp_less() to hopefully avoid conflicts with CSS clamp() --- lib/Less/Functions.php | 22 +++++++++++----------- lib/Less/Tree/Color.php | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Less/Functions.php b/lib/Less/Functions.php index 80ad4b71..1254ee5f 100644 --- a/lib/Less/Functions.php +++ b/lib/Less/Functions.php @@ -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 ); } @@ -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; @@ -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'] ); } @@ -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'] ); } @@ -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'] ); } @@ -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'] ); } @@ -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'] ); } @@ -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'] ); } @@ -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'] ); } diff --git a/lib/Less/Tree/Color.php b/lib/Less/Tree/Color.php index 427f47dc..867c8dd0 100644 --- a/lib/Less/Tree/Color.php +++ b/lib/Less/Tree/Color.php @@ -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; @@ -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'; }