Parse color input
Accept supported concrete CSS colors through one entry point and keep the resulting color space explicit.
#3b82f6SrgbColoroklch(0.65 0.18 264)OklchColorcolor(display-p3 ...)DisplayP3ColorrebeccapurpleSrgbColorDifferent formats enter the same typed workflow
Hex, CSS names, perceptual functions, and wide-gamut colors become concrete objects. The input space remains visible wherever PHPColor has a corresponding type.
One method reaches every supported concrete format
The parser returns the object; the object exposes its space and native CSS representation. No format-specific branch is required in application code.
<?php
use PhpColor\Color\Color;
$color = Color::parse(
'color(display-p3 0.25 0.5 0.9 / 0.75)'
);
echo $color::getSpaceName();
// display-p3
echo $color->toCss();
// color(display-p3 0.25 0.5 0.9 / 0.75)
use PhpColor\Color\Color;
$color = Color::parse(
'color(display-p3 0.25 0.5 0.9 / 0.75)'
);
echo $color::getSpaceName();
// display-p3
echo $color->toCss();
// color(display-p3 0.25 0.5 0.9 / 0.75)
Wide-gamut input does not become hex on arrival
A Display P3 value remains a Display P3 object and can leave the application in its native CSS syntax. Conversion happens only when the next operation or consumer asks for it.
- Type
- DisplayP3Color
- Space
- display-p3
- CSS
- color(display-p3 ...)
Concrete colors stop where CSS context begins
The promise covers values that can resolve on their own. Variables, currentColor, and light-dark() use the contextual CSS workflow instead.
Concrete#3b82f6, oklch(), color(display-p3)
Contextualvar(), currentColor, light-dark()