From 8744973bf3346f9e5f0fc63478bfbef0f0c2f5e5 Mon Sep 17 00:00:00 2001 From: Kier Darby Date: Wed, 7 Feb 2024 12:47:31 +0000 Subject: [PATCH] Allow hsl() and rgb() to spit out the raw incoming CSS if LESS doesn't get the expected inputs --- lib/Less/Functions.php | 43 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/Less/Functions.php b/lib/Less/Functions.php index 6dfa7626..56e62e28 100644 --- a/lib/Less/Functions.php +++ b/lib/Less/Functions.php @@ -67,9 +67,21 @@ public static function scaled( $n, $size = 255 ) { } public function rgb( $r = null, $g = null, $b = null ) { - if ( $r === null || $g === null || $b === null ) { - throw new Less_Exception_Compiler( "rgb expects three parameters" ); + $components = func_get_args(); + + if (count( $components ) != 3) + { + return null; + } + + foreach ( $components AS $component ) + { + if ( !$component instanceof Less_Tree_Dimension ) + { + return null; + } } + return $this->rgba( $r, $g, $b, 1.0 ); } @@ -81,28 +93,23 @@ public function rgba( $r = null, $g = null, $b = null, $a = null ) { return new Less_Tree_Color( $rgb, $a ); } - public function hsl( $h, $s, $l ) { - if (self::isLessHsl( $h, $s, $l )) { - return $this->hsla( $h, $s, $l, 1.0 ); - } - - return 'hsl(' . $h . ')'; - } + public function hsl( $h, $s = null, $l = null ) { + $components = func_get_args(); - protected function isLessHsl( $h, $s, $l ) { - $hsl = func_get_args(); - - if (count( $hsl ) != 3) { - return false; + if (count( $components ) != 3) + { + return null; } - foreach ( $hsl AS $arg ) { - if ( !$arg instanceof Less_Tree_Dimension ) { - return false; + foreach ( $components AS $component ) + { + if ( !$component instanceof Less_Tree_Dimension ) + { + return null; } } - return true; + return $this->hsla( $h, $s, $l, 1.0 ); } public function hsla( $h, $s, $l, $a ) {