@pbroom/color-kit/driverColor state

createColorState

Creates a ColorState from a requested OKLCH color: copies requested as is (no clamping) and derives the displayed sRGB and P3 colors and out-of-gamut flags with mapDisplayedColors.

functionimport { createColorState } from '@pbroom/color-kit/driver';color-state.ts:197
function createColorState(
  requested: Color,
  options?: CreateColorStateOptions,
): ColorState;

Parameters

Returns

ColorState

Throws

  • When options.activeGamut is not 'srgb' or 'display-p3' (for example the removed 'p3' spelling). The message ends 'p3' is not supported; use 'display-p3' for 'p3'.

Example

TypeScript
import { createColorState } from '@pbroom/color-kit/driver';

const state = createColorState({ l: 0.75, c: 0.22, h: 150, alpha: 1 });
state.requested.c; // → 0.22
state.displayed.srgb.c.toFixed(3); // → '0.207'
state.meta.outOfGamut; // → { srgb: true, p3: false }
state.activeGamut; // → 'display-p3'