Skip to content

Color

Defined in: src/color/Color.ts:17

Color common color operations

colors

new Color(color?): Color

Defined in: src/color/Color.ts:25

TColorArg

optional in hex or rgb(a) or hsl format or from known color list

Color

isUnrecognised: boolean = false

Defined in: src/color/Color.ts:19

getAlpha(): number

Defined in: src/color/Color.ts:133

Gets value of alpha channel for this color

number

0-1


getSource(): TRGBAColorSource

Defined in: src/color/Color.ts:64

Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])

TRGBAColorSource


overlayWith(otherColor): Color

Defined in: src/color/Color.ts:173

Overlays color with another color

string | Color

Color

thisArg


setAlpha(alpha): Color

Defined in: src/color/Color.ts:142

Sets value of alpha channel for this color

number

Alpha value 0-1

Color

thisArg


setSource(source): void

Defined in: src/color/Color.ts:72

Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1])

TRGBAColorSource

void


toBlackWhite(threshold): Color

Defined in: src/color/Color.ts:161

Transforms color to its black and white representation

number

Color

thisArg


toGrayscale(): Color

Defined in: src/color/Color.ts:151

Transforms color to its grayscale representation

Color

thisArg


toHex(): string

Defined in: src/color/Color.ts:115

Returns color representation in HEX format

string

ex: FF5555


toHexa(): string

Defined in: src/color/Color.ts:124

Returns color representation in HEXA format

string

ex: FF5555CC


toHsl(): string

Defined in: src/color/Color.ts:97

Returns color representation in HSL format

string

ex: hsl(0-360,0%-100%,0%-100%)


toHsla(): string

Defined in: src/color/Color.ts:106

Returns color representation in HSLA format

string

ex: hsla(0-360,0%-100%,0%-100%,0-1)


toRgb(): string

Defined in: src/color/Color.ts:80

Returns color representation in RGB format

string

ex: rgb(0-255,0-255,0-255)


toRgba(): string

Defined in: src/color/Color.ts:89

Returns color representation in RGBA format

string

ex: rgba(0-255,0-255,0-255,0-1)


static fromHex(color): Color

Defined in: src/color/Color.ts:298

Returns new color object, when given a color in HEX format

string

Color value ex: FF5555

Color

Color


static fromHsl(color): Color

Defined in: src/color/Color.ts:236

Returns new color object, when given a color in HSL format

string

Color value ex: hsl(0-260,0%-100%,0%-100%)

Color

Color


static fromHsla(color): Color

Defined in: src/color/Color.ts:248

Function

Returns new color object, when given a color in HSLA format

string

Color

Color


static fromRgb(color): Color

Defined in: src/color/Color.ts:195

Returns new color object, when given a color in RGB format

string

Color value ex: rgb(0-255,0-255,0-255)

Color

Color


static fromRgba(color): Color

Defined in: src/color/Color.ts:207

Function

Returns new color object, when given a color in RGBA format

string

Color

Color


static parseAngletoDegrees(value): number

Defined in: src/color/Color.ts:334

Converts a string that could be any angle notation (50deg, 0.5turn, 2rad) into degrees without the ‘deg’ suffix

string

ex: 0deg, 0.5turn, 2rad

number

number in degrees or NaN if inputs are invalid

Color


static sourceFromHex(color): undefined | TRGBAColorSource

Defined in: src/color/Color.ts:309

Returns array representation (ex: [100, 100, 200, 1]) of a color that’s in HEX format

string

ex: FF5555 or FF5544CC (RGBa)

undefined | TRGBAColorSource

source

Color


static sourceFromHsl(color): undefined | TRGBAColorSource

Defined in: src/color/Color.ts:260

Returns array representation (ex: [100, 100, 200, 1]) of a color that’s in HSL or HSLA format. Adapted from https://github.com/mjijackson

string

Color value ex: hsl(0-360,0%-100%,0%-100%) or hsla(0-360,0%-100%,0%-100%, 0-1)

undefined | TRGBAColorSource

source

Color

http://http://www.w3.org/TR/css3-color/#hsl-color


static sourceFromRgb(color): undefined | TRGBAColorSource

Defined in: src/color/Color.ts:217

Returns array representation (ex: [100, 100, 200, 1]) of a color that’s in RGB or RGBA format

string

Color value ex: rgb(0-255,0-255,0-255), rgb(0%-100%,0%-100%,0%-100%)

undefined | TRGBAColorSource

source

Color