Give each color a token name, then choose the shared variable prefix:
use PhpColor\Color\Palette\ColorPalette;
$tokens = ColorPalette::parse([
'brand' => '#7c3aed',
'accent' => '#f59e0b',
'surface' => '#f8fafc',
]);
echo $tokens->toCssVariables('theme');
use PhpColor\Color\Palette\ColorPalette;
$tokens = ColorPalette::parse([
'brand' => '#7c3aed',
'accent' => '#f59e0b',
'surface' => '#f8fafc',
]);
echo $tokens->toCssVariables('theme');
The result is ready to place inside a selector:
--theme-brand: #7c3aed;
--theme-accent: #f59e0b;
--theme-surface: #f8fafc;
--theme-brand: #7c3aed;
--theme-accent: #f59e0b;
--theme-surface: #f8fafc;
toCssVariables() emits declarations only. It does not add :root, braces, or sanitize token names and prefixes.