@pbroom/color-kit/planeCompile

definePlaneFromColor

Defines a plane whose fixed channels are taken from an anchor color.

functionimport { definePlaneFromColor } from '@pbroom/color-kit/plane';resolve.ts:290
function 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

colorColor
Anchor color converted into the selected model.
planeObject?Omit<PlaneDefinition<'oklch'>, 'color'>
Optional plane definition overrides (any PlaneDefinition field except color).

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

colorColor
Anchor color converted into the selected model.
planeObjectOmit<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 model is not a supported plane model.
  • When an axis or fixed channel is not valid for the model.

Example

TypeScript
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