Skip to content
pixi-silk
GitHub repository
Class

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#

ParameterType
optionsColorModelOptions

Returns#

ColorModel

Properties#

PropertyModifierTypeDefault valueDescriptionDefined in
committedreadonlySignal<number>undefinedCounts commits, for apps that save on release.ui/color/model.ts:142
historyreadonlySignal<readonly number[]>undefinedLast committed colours, newest first, as 0xRRGGBB.ui/color/model.ts:140
originpublicunknownnullWho made the last change, as passed to the setters. Pickers use it to ignore their own echo.ui/color/model.ts:144
valuereadonlySignal<HSVA>undefinedCurrent 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

OKLCH


rgb#

Get Signature#

get rgb(): RGB;

Current colour as straight sRGB 0..1, without alpha. A new array each read.

Returns

RGB


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#

ParameterTypeDefault value
hexnumberundefined
alpha?numberundefined
origin?unknownnull

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#

ParameterTypeDefault value
nextPartial<HSVA>undefined
originunknownnull

Returns#

void


setOklch()#

setOklch(lch: OKLCH, origin?: unknown): void;

Sets the colour from OKLCH, reducing chroma to fit sRGB. Alpha is unchanged.

Parameters#

ParameterTypeDefault value
lchOKLCHundefined
originunknownnull

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#

ParameterTypeDefault value
rgbRGBundefined
originunknownnull

Returns#

void