@pbroom/color-kit/driverColor input
resolveColorInputDraftValue
Parses a typed draft with parseColorInputExpression, then wraps or clamps the result into options.range (see normalizeColorInputValue). Returns null when the draft does not parse, so the input can keep or revert its value.
import { resolveColorInputDraftValue } from '@pbroom/color-kit/driver';color-input.ts:836function resolveColorInputDraftValue(
input: string,
options: ResolveColorInputDraftValueOptions,
): number | null;Parameters
- input
string
Returns
number | null
Example
import { resolveColorInputDraftValue } from '@pbroom/color-kit/driver';
const alpha = { currentValue: 0.3, range: [0, 1] as [number, number] };
resolveColorInputDraftValue('50%', alpha); // → 0.5
resolveColorInputDraftValue('1.5', alpha); // → 1
resolveColorInputDraftValue('abc', alpha); // → null
resolveColorInputDraftValue('+0.1', { ...alpha, allowExpressions: true }); // → 0.4
const hue = { currentValue: 0, range: [0, 360] as [number, number] };
resolveColorInputDraftValue('370deg', { ...hue, wrap: true }); // → 10