ColorPaletteInterface
InterfacePublic contract for color palette value objects.
Methods
Get all colors in the palette as an array.
Returns an associative array for named palettes (name => ColorInterface)
or a sequential array for scale palettes.
Get a color at a specific relative position in the palette.
Only available for scale palettes. Uses interpolation between existing
colors to return a color at the given position (0.0 to 1.0).
| Name | Type | Default |
|---|---|---|
$position |
float | - |
Find the color in the palette that is closest to a target color.
By default, the match is the one with the smallest Euclidean distance in
the Oklab color space.
or null for the default Oklab Euclidean distance
| Name | Type | Default |
|---|---|---|
$color |
ColorInterface | - |
$metric |
ColorDistanceInterface | null |
Decrease the lightness of all colors in the palette.
Adjusts lightness in Oklch space by the given amount.
| Name | Type | Default |
|---|---|---|
$amount |
float | - |
Decrease the chroma (saturation) of all colors in the palette.
Adjusts chroma in Oklch space by the given amount.
| Name | Type | Default |
|---|---|---|
$amount |
float | - |
Filter the colors in the palette using a predicate function.
Returns a new palette containing only the colors that match the predicate.
| Name | Type | Default |
|---|---|---|
$callback |
callable | - |
Get a specific color by its index or name.
| Name | Type | Default |
|---|---|---|
$key |
string|int | - |
Check if the palette is a named palette.
Returns true if colors are associated with string names, false if it's a scale.
Increase the lightness of all colors in the palette.
Adjusts lightness in Oklch space by the given amount.
| Name | Type | Default |
|---|---|---|
$amount |
float | - |
Transform all colors in the palette using a mapping function.
Returns a new palette with the results of the transformation.
| Name | Type | Default |
|---|---|---|
$callback |
callable | - |
Merge this palette with another palette.
Only available for scale palettes. Returns a new palette combining both.
| Name | Type | Default |
|---|---|---|
$palette |
ColorPaletteInterface | - |
Get the names of all colors in the palette.
Only available for named palettes. Returns an array of color names.
Reverse the order of colors in the palette.
Only available for scale palettes.
Rotate the hue of all colors in the palette.
Adjusts the hue in Oklch space by the given number of degrees.
| Name | Type | Default |
|---|---|---|
$angle |
float | - |
Increase the chroma (saturation) of all colors in the palette.
Adjusts chroma in Oklch space by the given amount.
| Name | Type | Default |
|---|---|---|
$amount |
float | - |
Get a sub-slice of the palette.
Only available for scale palettes. Works like array_slice().
| Name | Type | Default |
|---|---|---|
$offset |
int | - |
$length |
int | null |
Convert all colors in the palette to a specific color space.
| Name | Type | Default |
|---|---|---|
$space |
string | - |
Convert all colors in the palette to CSS color strings.
| Name | Type | Default |
|---|---|---|
$format |
string | null |
Generate CSS custom properties (variables) for the palette.
Only available for named palettes. Generates a string of CSS variable
declarations like '--prefix-name: color;'.
sRGB colors are written as hexadecimal, other spaces keep their own CSS
notation so that no gamut or precision is lost.
| Name | Type | Default |
|---|---|---|
$prefix |
string | "color" |
Convert all colors in the palette to hexadecimal color strings.