Skip to main content

Class: Color

The Color class represents a color with various color space representations and manipulation methods.

The class supports multiple color spaces, including RGB, HSL, HSV, CMYK, LAB, LCH, XYZ, and YUV. It also provides methods for converting between color spaces and generating harmony colors.

The class offers various color manipulation methods, such as adjusting lightness, saturation, hue, and alpha. It also provides methods for converting colors to different string representations and retrieving information about the color.

The class also includes utility methods for determining the perceived brightness of the color and checking if it is light or dark.

Constructors

new Color()

new Color(color): Color

Parameters

ParameterType
colorstring | RGB | HSL | HSV | CMYK | LAB | LCH | XYZ | YUV | Oklab | Oklch | LUV | HSLuv | HPLuv | CIExyY | SRGB | HSI | HWB | AdobeRGB

Returns

Color

Defined in

color.ts:96

Accessors

a

get a(): number

set a(value): void

Parameters

ParameterType
valuenumber

Returns

number

Defined in

color.ts:167


b

get b(): number

set b(value): void

Parameters

ParameterType
valuenumber

Returns

number

Defined in

color.ts:164


g

get g(): number

set g(value): void

Parameters

ParameterType
valuenumber

Returns

number

Defined in

color.ts:161


r

get r(): number

set r(value): void

Parameters

ParameterType
valuenumber

Returns

number

Defined in

color.ts:158

Methods

adjustAlpha()

adjustAlpha(amount): Color

Parameters

ParameterType
amountnumber

Returns

Color

Defined in

color.ts:304


adjustHue()

adjustHue(amount): Color

Parameters

ParameterType
amountnumber

Returns

Color

Defined in

color.ts:301


adjustLightness()

adjustLightness(amount): Color

Parameters

ParameterType
amountnumber

Returns

Color

Defined in

color.ts:295


adjustSaturation()

adjustSaturation(amount): Color

Parameters

ParameterType
amountnumber

Returns

Color

Defined in

color.ts:298


analogous()

analogous(angle?): [Color, Color, Color]

Parameters

ParameterType
angle?number

Returns

[Color, Color, Color]

Defined in

color.ts:262


complementary()

complementary(): [Color, Color]

Returns

[Color, Color]

Defined in

color.ts:259


doubleSplitComplementary()

doubleSplitComplementary(angle?): [Color, Color, Color, Color, Color]

Parameters

ParameterType
angle?number

Returns

[Color, Color, Color, Color, Color]

Defined in

color.ts:280


equals()

equals(other): boolean

Parameters

ParameterType
otherColor

Returns

boolean

Defined in

color.ts:376


getBrightness()

getBrightness(): number

Returns

number

Defined in

color.ts:341


getContrastRatio()

getContrastRatio(otherColor): number

Calculates the contrast ratio between this color and another color.

Parameters

ParameterTypeDescription
otherColorColorThe color to compare against.

Returns

number

The contrast ratio between the two colors.

Defined in

color.ts:362


getEffectiveAlpha()

getEffectiveAlpha(): number

Returns

number

Defined in

color.ts:330


getInfo()

getInfo(): Promise<ColorInfo>

Returns

Promise<ColorInfo>

Defined in

color.ts:337


getName()

getName(): Promise<string>

Returns

Promise<string>

Defined in

color.ts:334


getRelativeLuminance()

getRelativeLuminance(): number

Calculates the relative luminance of the color.

Returns

number

The relative luminance value between 0 and 1.

Defined in

color.ts:353


getWCAGCompliance()

getWCAGCompliance(otherColor, size): object

Determines the WCAG compliance level for the contrast between this color and another color.

Parameters

ParameterTypeDescription
otherColorColorThe color to compare against.
sizeTextSizeThe size of the text ('Normal' or 'Large').

Returns

object

An object containing the compliance level and the contrast ratio.

NameTypeDefined in
contrastRationumbercolor.ts:372
levelWCAGComplianceLevelcolor.ts:372

Defined in

color.ts:372


grayscale()

grayscale(): Color

Returns

Color

Defined in

color.ts:310


invert()

invert(): Color

Returns

Color

Defined in

color.ts:307


isLight()

isLight(threshold): boolean

Parameters

ParameterTypeDefault value
thresholdnumber128

Returns

boolean

Defined in

color.ts:345


mix()

mix(color, amount): Color

Parameters

ParameterType
colorColor
amountnumber

Returns

Color

Defined in

color.ts:313


monochromatic()

monochromatic(count?): Color[]

Parameters

ParameterType
count?number

Returns

Color[]

Defined in

color.ts:274


setAlpha()

setAlpha(value): Color

Parameters

ParameterType
valuenumber

Returns

Color

Defined in

color.ts:326


shades()

shades(count?): Color[]

Parameters

ParameterType
count?number

Returns

Color[]

Defined in

color.ts:283


splitComplementary()

splitComplementary(angle?): [Color, Color, Color]

Parameters

ParameterType
angle?number

Returns

[Color, Color, Color]

Defined in

color.ts:271


square()

square(): [Color, Color, Color, Color]

Returns

[Color, Color, Color, Color]

Defined in

color.ts:277


tetradic()

tetradic(angle?): [Color, Color, Color, Color]

Parameters

ParameterType
angle?number

Returns

[Color, Color, Color, Color]

Defined in

color.ts:268


tints()

tints(count?): Color[]

Parameters

ParameterType
count?number

Returns

Color[]

Defined in

color.ts:286


toAdobeRGB()

toAdobeRGB(): AdobeRGB

Returns

AdobeRGB

Defined in

color.ts:241


toCIELuv()

toCIELuv(): LUV

Returns

LUV

Defined in

color.ts:235


toCIExyY()

toCIExyY(): CIExyY

Returns

CIExyY

Defined in

color.ts:238


toCmyk()

toCmyk(): CMYK

Returns

CMYK

Defined in

color.ts:220


toHex()

toHex(includeAlpha): string

Parameters

ParameterType
includeAlphaboolean

Returns

string

Defined in

color.ts:195


toHPLuv()

toHPLuv(): HPLuv

Returns

HPLuv

Defined in

color.ts:232


toHsi()

toHsi(): HSI

Returns

HSI

Defined in

color.ts:208


toHsl()

toHsl(): HSL

Returns

HSL

Defined in

color.ts:202


toHSLuv()

toHSLuv(): HSLuv

Returns

HSLuv

Defined in

color.ts:229


toHsv()

toHsv(): HSV

Returns

HSV

Defined in

color.ts:205


toHwb()

toHwb(): HWB

Returns

HWB

Defined in

color.ts:211


toLab()

toLab(): LAB

Returns

LAB

Defined in

color.ts:250


toLabD50()

toLabD50(): LAB

Returns

LAB

Defined in

color.ts:253


toLch()

toLch(): LCH

Returns

LCH

Defined in

color.ts:214


tones()

tones(count?): Color[]

Parameters

ParameterType
count?number

Returns

Color[]

Defined in

color.ts:289


toOklab()

toOklab(): Oklab

Returns

Oklab

Defined in

color.ts:223


toOklch()

toOklch(): Oklch

Returns

Oklch

Defined in

color.ts:226


toRgb()

toRgb(): RGB

Returns

RGB

Defined in

color.ts:190


toSrgb()

toSrgb(): SRGB

Returns

SRGB

Defined in

color.ts:199


toString()

toString(includeAlpha): string

Parameters

ParameterTypeDefault value
includeAlphabooleanfalse

Returns

string

Defined in

color.ts:322


toXyz()

toXyz(): XYZ

Returns

XYZ

Defined in

color.ts:244


toXyzD50()

toXyzD50(): XYZ

Returns

XYZ

Defined in

color.ts:247


toYuv()

toYuv(): YUV

Returns

YUV

Defined in

color.ts:217


triadic()

triadic(): [Color, Color, Color]

Returns

[Color, Color, Color]

Defined in

color.ts:265


setPrecision()

static setPrecision(precision): void

Parameters

ParameterType
precisionnumber

Returns

void

Defined in

color.ts:318