@pbroom/color-kit/driverMulti color
addMultiColorEntry
Appends an entry (string colors are parsed). Selects it only when nothing was selected. No-op when id already exists.
import { addMultiColorEntry } from '@pbroom/color-kit/driver';multi-color-state.ts:550function addMultiColorEntry(
model: MultiColorModel,
id: string,
color: string | Color,
source?: ColorSource,
): MultiColorModel;Parameters
- id
string - source?
ColorSourcedefault'programmatic' - Source of the new entry.
Returns
Throws
- When
coloris neither a string nor an object. - When
coloris a string that cannot be parsed (fromparse).
Example
import { addMultiColorEntry, createMultiColorModel } from '@pbroom/color-kit/driver';
const model = createMultiColorModel({ colors: { bg: '#ffffff', fg: '#3b82f6' } });
const next = addMultiColorEntry(model, 'accent', '#f97316');
next.order; // → ['bg', 'fg', 'accent']
next.selectedId; // → 'bg'
addMultiColorEntry(next, 'accent', '#000') === next; // → true