@pbroom/color-kit/driverColor input
getColorInputChannelValue
Reads one channel of color in model. For an achromatic color (a gray, black or white) the HSL hue is not the canonical 0 but the HSL hue of the stored OKLCH hue: the hue of the 1%-saturated HSL color at the same lightness (clamped to 5-95%) whose OKLCH hue is color.h.
import { getColorInputChannelValue } from '@pbroom/color-kit/driver';color-input.ts:504function getColorInputChannelValue<Model extends ColorInputModel>(
color: Color,
model: Model,
channel: ColorInputChannelFor<Model>,
): number;Values are unrounded, in the channel's units (RGB 0-255, HSL s/l 0-100); format them with formatColorInputChannelValue.
Parameters
- model
Model - channel
ColorInputChannelFor<Model>
Returns
number
Throws
- When
channeldoes not belong tomodel.
Example
import { parse } from '@pbroom/color-kit';
import { getColorInputChannelValue } from '@pbroom/color-kit/driver';
const blue = parse('#3b82f6');
getColorInputChannelValue(blue, 'rgb', 'r'); // → 59
getColorInputChannelValue(blue, 'hsl', 'h').toFixed(1); // → '217.2'
const gray = { l: 0.6, c: 0, h: 250, alpha: 1 };
getColorInputChannelValue(gray, 'hsl', 'h').toFixed(1); // → '211.2'