Skip to content

Commit

Permalink
⭐ better color conversion (hex->int) in less converter
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Mar 11, 2024
1 parent fdc8b3d commit af617e7
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/lib/lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit af617e7

Please sign in to comment.