From af617e7699b3757589ff8d77931e0c7c859d36e2 Mon Sep 17 00:00:00 2001 From: Makis Tracend Date: Tue, 12 Mar 2024 03:29:26 +1100 Subject: [PATCH] :star: better color conversion (hex->int) in less converter --- app/lib/lessc.inc.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/lib/lessc.inc.php b/app/lib/lessc.inc.php index 0be1e5d..e5576e9 100644 --- a/app/lib/lessc.inc.php +++ b/app/lib/lessc.inc.php @@ -1565,14 +1565,12 @@ protected function coerceColor($value) { case 'raw_color': $c = array("color", 0, 0, 0); $colorStr = substr($value[1], 1); - $num = hexdec($colorStr); - $width = strlen($colorStr) == 3 ? 16 : 256; + $length = strlen($colorStr); + $width = $length == 3 ? 1 : 2; for ($i = 3; $i > 0; $i--) { // 3 2 1 - $t = $num % $width; - $num /= $width; - - $c[$i] = $t * (256/$width) + $t * floor(16/$width); + $t = ($i-1) * $width; + $c[$i] = hexdec($length == 6 ? substr($colorStr, $t, $width) : ($length == 3 ? str_repeat(substr($colorStr, 0, 1), 2) : 0)); } return $c;