Roles come from your application
The transformer does not understand what background, text, accent, or border means.
Transform a named light palette into a dark counterpart while keeping the input keys aligned.
#f8fafc→#0b0c0e#0f172a→#c0cde7#2563eb→#4f88fc#cbd5e1→#0d141cThe returned palette keeps the source keys and order, so light and dark values remain aligned under the names assigned by your application.
DarkModeColorPaletteTransformer adjusts lightness and chroma across the complete palette and returns new color objects.
<?php
use PhpColor\Color\Palette\ColorPalette;
use PhpColor\Color\Palette\Transformer\DarkModeColorPaletteTransformer;
$light = ColorPalette::parse([
'background' => '#f8fafc',
'text' => '#0f172a',
'accent' => '#2563eb',
'border' => '#cbd5e1',
]);
$dark = (new DarkModeColorPaletteTransformer())->transform($light);
print_r($dark->toHex());
use PhpColor\Color\Palette\ColorPalette;
use PhpColor\Color\Palette\Transformer\DarkModeColorPaletteTransformer;
$light = ColorPalette::parse([
'background' => '#f8fafc',
'text' => '#0f172a',
'accent' => '#2563eb',
'border' => '#cbd5e1',
]);
$dark = (new DarkModeColorPaletteTransformer())->transform($light);
print_r($dark->toHex());
Each transformed value retains its source color-space type and alpha. The intended OKLCH hue is preserved before conversion back to that type.
Array
(
[background] => #0b0c0e
[text] => #c0cde7
[accent] => #4f88fc
[border] => #0d141c
)
The transformation provides a coherent starting point. Check the actual foreground and background pairs after serialization.
The transformer does not understand what background, text, accent, or border means.
One fixed formula does not guarantee pairwise contrast or an accessible dark theme.