@pbroom/color-kit/planeCompile
definePlaneFromColor
Defines a plane whose fixed channels are taken from an anchor color.
import { definePlaneFromColor } from '@pbroom/color-kit/plane';resolve.ts:290function definePlaneFromColor(
color: Color,
planeObject?: Omit<PlaneDefinition<'oklch'>, 'color'>,
): Plane<'oklch'>;
function definePlaneFromColor<Model extends 'hsl' | 'hsv' | 'oklab' | 'display-p3' | 'rgb' | 'hct'>(
color: Color,
planeObject: Omit<PlaneDefinitionFor<Model>, 'color'>,
): Plane<Model>;Equivalent to definePlane({ ...planeObject, color }): the color is converted into the plane's model to fill every channel not on an axis, and explicit fixed values still win. Useful for a picker plane that follows the current color, or for switching models while keeping the same color.
Overload 1 of 2
Parameters
- planeObject?
Omit<PlaneDefinition<'oklch'>, 'color'> - Optional plane definition overrides (any
PlaneDefinitionfield exceptcolor).
Returns
Plane<'oklch'>A new resolved plane with explicit axes, ranges and fixed channels.
Overload 2 of 2
Defines a plane for a non-OKLCH model whose fixed channels are taken from an anchor color (model is required).
Parameters
- planeObject
Omit<PlaneDefinitionFor<Model>, 'color'> - Plane definition with an explicit
model.
Returns
Plane<Model>A new resolved plane with explicit axes, ranges and fixed channels.
Throws
- When
modelis not a supported plane model. - When an axis or fixed channel is not valid for the model.
Example
import { parse } from '@pbroom/color-kit';
import { definePlaneFromColor } from '@pbroom/color-kit/plane';
const plane = definePlaneFromColor(parse('#7c3aed'), {
model: 'hsl',
x: { channel: 'h' },
y: { channel: 's' },
});
plane.fixed.l?.toFixed(1); // → '57.8' (HSL lightness of the anchor)See also
Also exported from
@pbroom/color-kitthe same declaration, re-exported