@@ -20,6 +20,18 @@ private static function _clamp( $val, $max = 1 ) {
2020 return min ( max ( $ val , 0 ), $ max );
2121 }
2222
23+ private function _hsla ( $ origColor , $ hsl ) {
24+ $ color = $ this ->hsla ( $ hsl ["h " ], $ hsl ["s " ], $ hsl ["l " ], $ hsl ["a " ] );
25+ if ( $ color ) {
26+ if ( $ origColor ->value && preg_match ( '/^(rgb|hsl)/ ' , $ origColor ->value ) ) {
27+ $ color ->value = $ origColor ->value ;
28+ } else {
29+ $ color ->value = 'rgb ' ;
30+ }
31+ return $ color ;
32+ }
33+ }
34+
2335 private static function _number ( $ n ) {
2436 if ( $ n instanceof Less_Tree_Dimension ) {
2537 return floatval ( $ n ->unit ->is ( '% ' ) ? $ n ->value / 100 : $ n ->value );
@@ -42,7 +54,11 @@ public function rgb( $r = null, $g = null, $b = null ) {
4254 if ( $ r === null || $ g === null || $ b === null ) {
4355 throw new Less_Exception_Compiler ( "rgb expects three parameters " );
4456 }
45- return $ this ->rgba ( $ r , $ g , $ b , 1.0 );
57+ $ color = $ this ->rgba ( $ r , $ g , $ b , 1.0 );
58+ if ( $ color ) {
59+ $ color ->value = 'rgb ' ;
60+ return $ color ;
61+ }
4662 }
4763
4864 public function rgba ( $ r = null , $ g = null , $ b = null , $ a = null ) {
@@ -53,11 +69,15 @@ public function rgba( $r = null, $g = null, $b = null, $a = null ) {
5369 ];
5470
5571 $ a = self ::_number ( $ a );
56- return new Less_Tree_Color ( $ rgb , $ a );
72+ return new Less_Tree_Color ( $ rgb , $ a, ' rgba ' );
5773 }
5874
5975 public function hsl ( $ h , $ s , $ l ) {
60- return $ this ->hsla ( $ h , $ s , $ l , 1.0 );
76+ $ color = $ this ->hsla ( $ h , $ s , $ l , 1.0 );
77+ if ( $ color ) {
78+ $ color ->value = "hsl " ;
79+ return $ color ;
80+ }
6181 }
6282
6383 public function hsla ( $ h , $ s , $ l , $ a ) {
@@ -70,12 +90,13 @@ public function hsla( $h, $s, $l, $a ) {
7090
7191 $ m1 = $ l * 2 - $ m2 ;
7292
73- return $ this -> rgba (
93+ $ rgb = [
7494 self ::hsla_hue ( $ h + 1 / 3 , $ m1 , $ m2 ) * 255 ,
7595 self ::hsla_hue ( $ h , $ m1 , $ m2 ) * 255 ,
7696 self ::hsla_hue ( $ h - 1 / 3 , $ m1 , $ m2 ) * 255 ,
77- $ a
78- );
97+ ];
98+ $ a = self ::_number ( $ a );
99+ return new Less_Tree_Color ( $ rgb , $ a , 'hsla ' );
79100 }
80101
81102 /**
@@ -297,7 +318,7 @@ public function saturate( $color = null, $amount = null, $method = null ) {
297318 $ hsl ['s ' ] += $ amount ->value / 100 ;
298319 } $ hsl ['s ' ] = self ::_clamp ( $ hsl ['s ' ] );
299320
300- return $ this ->hsla ( $ hsl [ ' h ' ] , $ hsl[ ' s ' ], $ hsl [ ' l ' ], $ hsl [ ' a ' ] );
321+ return $ this ->_hsla ( $ color , $ hsl );
301322 }
302323
303324 /**
@@ -327,7 +348,7 @@ public function desaturate( $color = null, $amount = null, $method = null ) {
327348
328349 $ hsl ['s ' ] = self ::_clamp ( $ hsl ['s ' ] );
329350
330- return $ this ->hsla ( $ hsl [ ' h ' ] , $ hsl[ ' s ' ], $ hsl [ ' l ' ], $ hsl [ ' a ' ] );
351+ return $ this ->_hsla ( $ color , $ hsl );
331352 }
332353
333354 public function lighten ( $ color = null , $ amount = null , $ method = null ) {
@@ -351,8 +372,7 @@ public function lighten( $color = null, $amount = null, $method = null ) {
351372 }
352373
353374 $ hsl ['l ' ] = self ::_clamp ( $ hsl ['l ' ] );
354-
355- return $ this ->hsla ( $ hsl ['h ' ], $ hsl ['s ' ], $ hsl ['l ' ], $ hsl ['a ' ] );
375+ return $ this ->_hsla ( $ color , $ hsl );
356376 }
357377
358378 public function darken ( $ color = null , $ amount = null , $ method = null ) {
@@ -374,8 +394,7 @@ public function darken( $color = null, $amount = null, $method = null ) {
374394 $ hsl ['l ' ] -= $ amount ->value / 100 ;
375395 }
376396 $ hsl ['l ' ] = self ::_clamp ( $ hsl ['l ' ] );
377-
378- return $ this ->hsla ( $ hsl ['h ' ], $ hsl ['s ' ], $ hsl ['l ' ], $ hsl ['a ' ] );
397+ return $ this ->_hsla ( $ color , $ hsl );
379398 }
380399
381400 public function fadein ( $ color = null , $ amount = null , $ method = null ) {
@@ -399,7 +418,7 @@ public function fadein( $color = null, $amount = null, $method = null ) {
399418 }
400419
401420 $ hsl ['a ' ] = self ::_clamp ( $ hsl ['a ' ] );
402- return $ this ->hsla ( $ hsl [ ' h ' ] , $ hsl[ ' s ' ], $ hsl [ ' l ' ], $ hsl [ ' a ' ] );
421+ return $ this ->_hsla ( $ color , $ hsl );
403422 }
404423
405424 public function fadeout ( $ color = null , $ amount = null , $ method = null ) {
@@ -423,7 +442,7 @@ public function fadeout( $color = null, $amount = null, $method = null ) {
423442 }
424443
425444 $ hsl ['a ' ] = self ::_clamp ( $ hsl ['a ' ] );
426- return $ this ->hsla ( $ hsl [ ' h ' ] , $ hsl[ ' s ' ], $ hsl [ ' l ' ], $ hsl [ ' a ' ] );
445+ return $ this ->_hsla ( $ color , $ hsl );
427446 }
428447
429448 public function fade ( $ color = null , $ amount = null ) {
@@ -442,7 +461,7 @@ public function fade( $color = null, $amount = null ) {
442461
443462 $ hsl ['a ' ] = $ amount ->value / 100 ;
444463 $ hsl ['a ' ] = self ::_clamp ( $ hsl ['a ' ] );
445- return $ this ->hsla ( $ hsl [ ' h ' ] , $ hsl[ ' s ' ], $ hsl [ ' l ' ], $ hsl [ ' a ' ] );
464+ return $ this ->_hsla ( $ color , $ hsl );
446465 }
447466
448467 public function spin ( $ color = null , $ amount = null ) {
@@ -462,7 +481,7 @@ public function spin( $color = null, $amount = null ) {
462481
463482 $ hsl ['h ' ] = $ hue < 0 ? 360 + $ hue : $ hue ;
464483
465- return $ this ->hsla ( $ hsl [ ' h ' ] , $ hsl[ ' s ' ], $ hsl [ ' l ' ], $ hsl [ ' a ' ] );
484+ return $ this ->_hsla ( $ color , $ hsl );
466485 }
467486
468487 //
@@ -863,15 +882,16 @@ public function percentage( $n ) {
863882 }
864883
865884 /**
866- * @see less-2.5.3 .js#colorFunctions.color
885+ * @see less-3.13.1 .js#colorFunctions.color
867886 * @param Less_Tree_Quoted|Less_Tree_Color|Less_Tree_Keyword $c
868887 * @return Less_Tree_Color
869888 */
870889 public function color ( $ c ) {
871890 if ( ( $ c instanceof Less_Tree_Quoted ) &&
872- preg_match ( '/^#([a- f0-9]{6}|[a- f0-9]{3}) / ' , $ c ->value )
891+ preg_match ( '/^#([A-Fa- f0-9]{8}|[A-Fa-f0-9]{ 6}|[A-Fa- f0-9]{3,4})$ / ' , $ c ->value )
873892 ) {
874- return new Less_Tree_Color ( substr ( $ c ->value , 1 ) );
893+ $ value = substr ( $ c ->value , 1 );
894+ return new Less_Tree_Color ( $ value , null , '# ' . $ value );
875895 }
876896
877897 // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition
@@ -880,7 +900,7 @@ public function color( $c ) {
880900 return $ c ;
881901 }
882902
883- throw new Less_Exception_Compiler ( "argument must be a color keyword or 3/6 digit hex e.g. #FFF " );
903+ throw new Less_Exception_Compiler ( "argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF " );
884904 }
885905
886906 public function isruleset ( $ n ) {
0 commit comments