@pbroom/color-kit/driverColor slider

colorFromColorSliderKey

Keyboard model for a 1D color slider:

functionimport { colorFromColorSliderKey } from '@pbroom/color-kit/driver';color-slider.ts:272
function colorFromColorSliderKey(
  color: Color,
  channel: ColorSliderChannel,
  key: string,
  stepRatio: number,
  range: [number, number],
  options?: ColorSliderKeyOptions,
): Color | null;
  • Arrow Right/Up and Left/Down step by stepRatio of the range.
  • PageUp/PageDown step by largeStepRatio of the range.
  • Home/End jump to the range start/end.

Steps wrap for hue (by default) and clamp otherwise. Returns null for keys the slider does not handle. Modifier keys are not read: pass a larger stepRatio for Shift+Arrow.

Parameters

keystring
stepRationumber
Arrow-key step as a fraction of the range, e.g. 0.01.
range[number, number]

Returns

Color | null

Example

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

const color = { l: 0.6, c: 0.1, h: 350, alpha: 1 };
colorFromColorSliderKey(color, 'h', 'PageUp', 0.01, [0, 360]); // → { l: 0.6, c: 0.1, h: 26, alpha: 1 }
colorFromColorSliderKey(color, 'l', 'End', 0.01, [0, 1]); // → { l: 1, c: 0.1, h: 350, alpha: 1 }
colorFromColorSliderKey(color, 'l', 'Enter', 0.01, [0, 1]); // → null