diff --git a/src/Value/Color.php b/src/Value/Color.php index a084fd35..5b54ce45 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(')'); @@ -163,7 +177,7 @@ public function render(OutputFormat $oOutputFormat) $this->aComponents['b']->getSize() ); return '#' . (($sResult[0] == $sResult[1]) && ($sResult[2] == $sResult[3]) && ($sResult[4] == $sResult[5]) - ? "$sResult[0]$sResult[2]$sResult[4]" : $sResult); + ? "$sResult[0]$sResult[2]$sResult[4]" : $sResult); } return parent::render($oOutputFormat); } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 2c1c7287..8832a661 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -164,7 +164,9 @@ public function colorParsing(): void . 'background-color: rgb(255,var(--rg));background-color: hsl(var(--some-hsl));}' . "\n" . '#variables-alpha {background-color: rgba(var(--some-rgb),.1);' - . 'background-color: rgba(var(--some-rg),255,.1);background-color: hsla(var(--some-hsl),.1);}', + . 'background-color: rgba(var(--some-rg),255,.1);background-color: hsla(var(--some-hsl),.1);}' + . "\n" + . '#css4-rgba {background-color: rgba(242,245,249,45%);background-color: #f2f5f9;}', $oDoc->render() ); } diff --git a/tests/fixtures/colortest.css b/tests/fixtures/colortest.css index f834aa77..41c5d223 100644 --- a/tests/fixtures/colortest.css +++ b/tests/fixtures/colortest.css @@ -27,3 +27,8 @@ background-color: rgba(var(--some-rg), 255, 0.1); background-color: hsla(var(--some-hsl), 0.1); } + +#css4-rgba { + background-color: rgb(242 245 249 / 45%); + background-color: rgba(242 245 249); +}