@pbroom/color-kit/driverColor slider
colorFromColorSliderKey
Keyboard model for a 1D color slider:
import { colorFromColorSliderKey } from '@pbroom/color-kit/driver';color-slider.ts:272function colorFromColorSliderKey(
color: Color,
channel: ColorSliderChannel,
key: string,
stepRatio: number,
range: [number, number],
options?: ColorSliderKeyOptions,
): Color | null;- Arrow Right/Up and Left/Down step by
stepRatioof the range. - PageUp/PageDown step by
largeStepRatioof 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
- key
string - stepRatio
number - Arrow-key step as a fraction of the range, e.g.
0.01. - range
[number, number] - options?
ColorSliderKeyOptionsdefault{}
Returns
Color | null
Example
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