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
Parameter | Type |
---|---|
color | string | RGB | HSL | HSV | CMYK | LAB | LCH | XYZ | YUV | Oklab | Oklch | LUV | HSLuv | HPLuv | CIExyY | SRGB | HSI | HWB | AdobeRGB |
Returns
Defined in
color.ts:96
Accessors
a
get
a():number
set
a(value
):void
Parameters
Parameter | Type |
---|---|
value | number |
Returns
number
Defined in
color.ts:167
b
get
b():number
set
b(value
):void
Parameters
Parameter | Type |
---|---|
value | number |
Returns
number
Defined in
color.ts:164
g
get
g():number
set
g(value
):void
Parameters
Parameter | Type |
---|---|
value | number |
Returns
number
Defined in
color.ts:161
r
get
r():number
set
r(value
):void
Parameters
Parameter | Type |
---|---|
value | number |
Returns
number
Defined in
color.ts:158
Methods
adjustAlpha()
adjustAlpha(
amount
):Color
Parameters
Parameter | Type |
---|---|
amount | number |
Returns
Defined in
color.ts:304
adjustHue()
adjustHue(
amount
):Color
Parameters
Parameter | Type |
---|---|
amount | number |
Returns
Defined in
color.ts:301
adjustLightness()
adjustLightness(
amount
):Color
Parameters
Parameter | Type |
---|---|
amount | number |
Returns
Defined in
color.ts:295
adjustSaturation()
adjustSaturation(
amount
):Color
Parameters
Parameter | Type |
---|---|
amount | number |
Returns
Defined in
color.ts:298
analogous()
Parameters
Parameter | Type |
---|---|
angle ? | number |
Returns
Defined in
color.ts:262
complementary()
Returns
Defined in
color.ts:259
doubleSplitComplementary()
doubleSplitComplementary(
angle
?): [Color
,Color
,Color
,Color
,Color
]
Parameters
Parameter | Type |
---|---|
angle ? | number |
Returns
[Color
, Color
, Color
, Color
, Color
]
Defined in
color.ts:280
equals()
equals(
other
):boolean
Parameters
Parameter | Type |
---|---|
other | Color |
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
Parameter | Type | Description |
---|---|---|
otherColor | Color | The 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
Parameter | Type | Description |
---|---|---|
otherColor | Color | The color to compare against. |
size | TextSize | The size of the text ('Normal' or 'Large'). |
Returns
object
An object containing the compliance level and the contrast ratio.
Name | Type | Defined in |
---|---|---|
contrastRatio | number | color.ts:372 |
level | WCAGComplianceLevel | color.ts:372 |
Defined in
color.ts:372
grayscale()
grayscale():
Color
Returns
Defined in
color.ts:310
invert()
invert():
Color
Returns
Defined in
color.ts:307
isLight()
isLight(
threshold
):boolean
Parameters
Parameter | Type | Default value |
---|---|---|
threshold | number | 128 |
Returns
boolean
Defined in
color.ts:345
mix()
mix(
color
,amount
):Color
Parameters
Parameter | Type |
---|---|
color | Color |
amount | number |
Returns
Defined in
color.ts:313
monochromatic()
monochromatic(
count
?):Color
[]
Parameters
Parameter | Type |
---|---|
count ? | number |
Returns
Color
[]
Defined in
color.ts:274
setAlpha()
setAlpha(
value
):Color
Parameters
Parameter | Type |
---|---|
value | number |
Returns
Defined in
color.ts:326
shades()
shades(
count
?):Color
[]
Parameters
Parameter | Type |
---|---|
count ? | number |
Returns
Color
[]
Defined in
color.ts:283
splitComplementary()
Parameters
Parameter | Type |
---|---|
angle ? | number |
Returns
Defined in
color.ts:271
square()
Returns
Defined in
color.ts:277
tetradic()
Parameters
Parameter | Type |
---|---|
angle ? | number |
Returns
Defined in
color.ts:268
tints()
tints(
count
?):Color
[]
Parameters
Parameter | Type |
---|---|
count ? | number |
Returns
Color
[]
Defined in
color.ts:286
toAdobeRGB()
toAdobeRGB():
AdobeRGB
Returns
Defined in
color.ts:241
toCIELuv()
toCIELuv():
LUV
Returns
Defined in
color.ts:235
toCIExyY()
toCIExyY():
CIExyY
Returns
Defined in
color.ts:238
toCmyk()
toCmyk():
CMYK
Returns
Defined in
color.ts:220
toHex()
toHex(
includeAlpha
):string
Parameters
Parameter | Type |
---|---|
includeAlpha | boolean |
Returns
string
Defined in
color.ts:195
toHPLuv()
toHPLuv():
HPLuv
Returns
Defined in
color.ts:232
toHsi()
toHsi():
HSI
Returns
Defined in
color.ts:208
toHsl()
toHsl():
HSL
Returns
Defined in
color.ts:202
toHSLuv()
toHSLuv():
HSLuv
Returns
Defined in
color.ts:229
toHsv()
toHsv():
HSV
Returns
Defined in
color.ts:205
toHwb()
toHwb():
HWB
Returns
Defined in
color.ts:211
toLab()
toLab():
LAB
Returns
Defined in
color.ts:250
toLabD50()
toLabD50():
LAB
Returns
Defined in
color.ts:253
toLch()
toLch():
LCH
Returns
Defined in
color.ts:214
tones()
tones(
count
?):Color
[]
Parameters
Parameter | Type |
---|---|
count ? | number |
Returns
Color
[]
Defined in
color.ts:289
toOklab()
toOklab():
Oklab
Returns
Defined in
color.ts:223
toOklch()
toOklch():
Oklch
Returns
Defined in
color.ts:226
toRgb()
toRgb():
RGB
Returns
Defined in
color.ts:190
toSrgb()
toSrgb():
SRGB
Returns
Defined in
color.ts:199
toString()
toString(
includeAlpha
):string
Parameters
Parameter | Type | Default value |
---|---|---|
includeAlpha | boolean | false |
Returns
string
Defined in
color.ts:322
toXyz()
toXyz():
XYZ
Returns
Defined in
color.ts:244
toXyzD50()
toXyzD50():
XYZ
Returns
Defined in
color.ts:247
toYuv()
toYuv():
YUV
Returns
Defined in
color.ts:217
triadic()
Returns
Defined in
color.ts:265
setPrecision()
static
setPrecision(precision
):void
Parameters
Parameter | Type |
---|---|
precision | number |
Returns
void
Defined in
color.ts:318