@pbroom/color-kit/driverColor state

setColorRequested

Replaces the requested color, re-deriving displayed colors and gamut flags while keeping the active gamut/view and gamut mapping method (state.meta.gamutMapMethod, unless options.gamutMapMethod overrides it). An achromatic requested keeps the current hue when options.explicitHue is false or its hue is not finite (see resolveIncomingRequested). No-op (returns state) when the resolved requested color, source and gamut mapping method are unchanged.

functionimport { setColorRequested } from '@pbroom/color-kit/driver';color-state.ts:390
function setColorRequested(
  state: ColorState,
  incoming: Color,
  source: ColorSource,
  options?: SetColorRequestedOptions,
): ColorState;

Parameters

stateColorState
Current state.
incomingColor
New requested OKLCH color; stored unclamped.
sourceColorSource
Source recorded in meta.source.

Returns

ColorState

Example

TypeScript
import { parse, toHex } from '@pbroom/color-kit';
import { createColorState, setColorRequested } from '@pbroom/color-kit/driver';

const state = createColorState(parse('#3b82f6'));
const gray = parse('#808080');
const next = setColorRequested(state, gray, 'user', { explicitHue: false });
toHex(next.requested); // → '#808080'
next.requested.h === state.requested.h; // → true (blue hue kept)
setColorRequested(next, gray, 'user', { explicitHue: false }) === next; // → true