From cf66666846b00bb54564ef2070c6575da6b1e53e Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Thu, 8 Aug 2024 10:14:05 +0200
Subject: [PATCH] Fix/css4 rgb parsing: PR rebased.

---
 src/Value/Color.php | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/Value/Color.php b/src/Value/Color.php
index a084fd35..1cd5ee43 100644
--- a/src/Value/Color.php
+++ b/src/Value/Color.php
@@ -71,14 +71,21 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
             $oParserState->consume('(');
 
             $bContainsVar = false;
-            $iLength = $oParserState->strlen($sColorMode);
+            if ($sColorMode === 'rgb') {
+                $sColorTarget = 'rgba';
+            } elseif ($sColorMode === 'hsl') {
+                $sColorTarget = 'hsla';
+            } else {
+                $sColorTarget = $sColorMode;
+            }
+            $iLength = $oParserState->strlen($sColorTarget);
             for ($i = 0; $i < $iLength; ++$i) {
                 $oParserState->consumeWhiteSpace();
                 if ($oParserState->comes('var')) {
-                    $aColor[$sColorMode[$i]] = CSSFunction::parseIdentifierOrFunction($oParserState);
+                    $aColor[$sColorTarget[$i]] = CSSFunction::parseIdentifierOrFunction($oParserState);
                     $bContainsVar = true;
                 } else {
-                    $aColor[$sColorMode[$i]] = Size::parse($oParserState, true);
+                    $aColor[$sColorTarget[$i]] = Size::parse($oParserState, true);
                 }
 
                 if ($bContainsVar && $oParserState->comes(')')) {
@@ -88,7 +95,14 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
 
                 $oParserState->consumeWhiteSpace();
                 if ($i < ($iLength - 1)) {
-                    $oParserState->consume(',');
+                    if ($oParserState->comes(',')) {
+                        $oParserState->consume(',');
+                    } elseif ($oParserState->comes('/')) {
+                        $oParserState->consume('/');
+                    } elseif ($oParserState->comes(')')) {
+                        // No alpha channel information
+                        break;
+                    }
                 }
             }
             $oParserState->consume(')');
