ColorModel
import { ColorModel } from 'pixi-silk/ui/color';
The colour every picker edits. Stored as HSV + alpha (so hue survives greys and black), readable and writable as hex, RGB and OKLCH. Bind several pickers to one model and they stay in sync.
value changes continuously during drags. commit() (called by pickers when a drag ends)
records the colour in history and bumps committed, which is what an app usually saves.
Constructors#
Constructor#
new ColorModel(options?: ColorModelOptions): ColorModel;
Parameters#
| Parameter | Type |
|---|---|
options | ColorModelOptions |
Returns#
ColorModel
Properties#
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
committed | readonly | Signal<number> | undefined | Counts commits, for apps that save on release. | ui/color/model.ts:142 |
history | readonly | Signal<readonly number[]> | undefined | Last committed colours, newest first, as 0xRRGGBB. | ui/color/model.ts:140 |
origin | public | unknown | null | Who made the last change, as passed to the setters. Pickers use it to ignore their own echo. | ui/color/model.ts:144 |
value | readonly | Signal<HSVA> | undefined | Current colour as HSVA. Replace the object to change it (it is compared by identity). | ui/color/model.ts:138 |
Accessors#
alpha#
Get Signature#
get alpha(): number;
Alpha, 0 to 1.
Returns
number
h#
Get Signature#
get h(): number;
Hue in degrees, 0 to 360.
Returns
number
hex#
Get Signature#
get hex(): number;
Current colour as 0xRRGGBB, without alpha.
Returns
number
oklch#
Get Signature#
get oklch(): OKLCH;
Current colour as OKLCH.
Returns
rgb#
Get Signature#
get rgb(): RGB;
Current colour as straight sRGB 0..1, without alpha. A new array each read.
Returns
s#
Get Signature#
get s(): number;
HSV saturation, 0 to 1.
Returns
number
v#
Get Signature#
get v(): number;
HSV value (brightness), 0 to 1.
Returns
number
Methods#
commit()#
commit(): void;
Records the current colour in history (no duplicates) and bumps committed.
Returns#
void
setHex()#
setHex(
hex: number,
alpha?: number,
origin?: unknown
): void;
Sets the colour from 0xRRGGBB (alpha unchanged unless given).
Parameters#
| Parameter | Type | Default value |
|---|---|---|
hex | number | undefined |
alpha? | number | undefined |
origin? | unknown | null |
Returns#
void
setHsv()#
setHsv(next: Partial<HSVA>, origin?: unknown): void;
Changes any of h, s, v, a. Values are clamped and the hue wrapped. No change, no signal.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
next | Partial<HSVA> | undefined |
origin | unknown | null |
Returns#
void
setOklch()#
setOklch(lch: OKLCH, origin?: unknown): void;
Sets the colour from OKLCH, reducing chroma to fit sRGB. Alpha is unchanged.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
lch | OKLCH | undefined |
origin | unknown | null |
Returns#
void
setRgb()#
setRgb(rgb: RGB, origin?: unknown): void;
Sets the colour from sRGB 0..1 (clamped), keeping the hue when the colour is grey. Alpha is unchanged.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
rgb | RGB | undefined |
origin | unknown | null |
Returns#
void