Resolve `currentColor`

Resolve currentColor only when the server knows the inherited foreground that the browser would otherwise supply.

Preserve currentColor when the browser owns inheritance. Resolve it in PHP only when the server has an authoritative foreground for the component or artifact being produced.

Treat the current color as contextual input

currentColor is not a fixed color name. It refers to the element's computed color, so PHPColor needs that foreground supplied explicitly:

use PhpColor\Color\Css\CssColor;
use PhpColor\Color\Css\CssContext;

$expression = CssColor::currentColor();
$context = CssContext::light([], '#0f172a');

$color = CssColor::resolve($expression, $context);

echo $color->toHex();
use PhpColor\Color\Css\CssColor; use PhpColor\Color\Css\CssContext; $expression = CssColor::currentColor(); $context = CssContext::light([], '#0f172a'); $color = CssColor::resolve($expression, $context); echo $color->toHex();

The output is #0f172a.

Preserve or reject a missing foreground

CssColor::parse('currentColor') creates the same kind of expression. The context value can be a concrete color or a string containing another resolvable expression.

When no current color is available, non-strict mode returns the unresolved CurrentColor. Strict mode throws InvalidColorException.

The context value can itself contain another resolvable expression. Avoid recursive definitions in which currentColor eventually points back to itself.

PHPColor does not inspect DOM inheritance or computed styles. Continue with Build resolution contexts, Resolve CSS currentColor, or CurrentColor.