Namespace: colors

qui.utils.colors

Deals with color format conversions and color adjustments.

Contains code taken from https://github.com/antimatter15/rgb-lab/

Source:

Methods

(static) alpha(strColor, factor) → {String}

Alter the alpha factor of a color.

Accepted string color formats are rgb(r, g, b), rgba(r, g, b, a), #rrggbb and an HTML color name.

Parameters:
Name Type Description
strColor String
factor Number

the alpha factor (from 0 to 1)

Source:
Returns:
Type
String

(static) contrast(rgb1, rgb2) → {Number}

Compute the contrast ratio between two colors, as defined by https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef.

red, green and blue range from 0 to 255. contrast ranges from 1 to 21.

Parameters:
Name Type Description
rgb1 Array.<Number>

a 3 elements array representing the red, green and blue components of the first color

rgb2 Array.<Number>

a 3 elements array representing the red, green and blue components of the second color

Source:
Returns:
Type
Number

(static) darker(strColor, amount) → {String}

Return a darker variant of a given color.

Accepted string color formats are rgb(r, g, b), rgba(r, g, b, a), #rrggbb and an HTML color name.

Parameters:
Name Type Description
strColor String
amount Number

the fraction used to alter the value component (from 0 to 1)

Source:
Returns:
Type
String

(static) deltaE(lab1, lab2) → {Number}

Compute the distance between two colors, as defined by the deltaE CIE94 specification.

lightness ranges from 0 to 100, while a and b range from -100 to 100. deltaE ranges from 0 to 255.

Parameters:
Name Type Description
lab1 Array.<Number>

a 3 elements array representing the lightness, a and b components of the first color

lab2 Array.<Number>

a 3 elements array representing the lightness, a and b components of the second color

Source:
Returns:
Type
Number

(static) hsv2rgb(hsv) → {Array.<Number>}

Convert a tuple of (hue, saturation, value) components into (red, green, blue) equivalent.

red, green and blue range from 0 to 255. hue ranges from 0 to 359, while saturation and value range from 0 to 1.

Parameters:
Name Type Description
hsv Array.<Number>

a 3 elements array representing the hue, saturation and value components

Source:
Returns:

a 3 elements array representing the red, green and blue components

Type
Array.<Number>

(static) lab2rgb(lab) → {Array.<Number>}

Convert a tuple of (lightness, a, b) components into (red, green, blue) equivalent. The lightness, a and b components are defined by the CIELAB color space.

red, green and blue range from 0 to 255. lightness ranges from 0 to 100, while a and b range from -100 to 100.

Parameters:
Name Type Description
lab Array.<Number>

a 3 elements array representing the lightness, a and b components

Source:
Returns:

a 3 elements array representing the red, green and blue components

Type
Array.<Number>

(static) lighter(strColor, amount) → {String}

Return a lighter variant of a given color.

Accepted string color formats are rgb(r, g, b), rgba(r, g, b, a), #rrggbb and an HTML color name.

Parameters:
Name Type Description
strColor String
amount Number

the fraction used to alter the value component (from 0 to 1)

Source:
Returns:
Type
String

(static) luminance(rgb) → {Number}

Compute the luminance of a color, as defined by https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef.

red, green and blue range from 0 to 255. luminance ranges from 0 to 1.

Parameters:
Name Type Description
rgb Array.<Number>

a 3 elements array representing the red, green and blue components

Source:
Returns:
Type
Number

(static) mix(strColor1, strColor2, factor) → {String}

Mix two colors.

Accepted string color formats are rgb(r, g, b), rgba(r, g, b, a), #rrggbb and an HTML color name.

Parameters:
Name Type Description
strColor1 String
strColor2 String
factor Number

the ratio by which the two input colors contribute to the output color; 0 results in 100% of strColor1 and 1 results in 100% of strColor2

Source:
Returns:
Type
String

(static) normalize(strColor) → {String}

Normalize a color by converting it to the most appropriate string format.

Accepted string color formats are rgb(r, g, b), rgba(r, g, b, a), #rrggbb and an HTML color name.

Colors with alpha factor are represented as rgba(r, g, b, a), while those without alpha factor are represented as #rrggbb.

Parameters:
Name Type Description
strColor String
Source:
Returns:
Type
String

(static) rgb2hsv(rgb) → {Array.<Number>}

Convert a tuple of (red, green, blue) components into (hue, saturation, value) equivalent.

red, green and blue range from 0 to 255. hue ranges from 0 to 359, while saturation and value range from 0 to 1.

Parameters:
Name Type Description
rgb Array.<Number>

a 3 elements array representing the red, green and blue components

Source:
Returns:

a 3 elements array representing the hue, saturation and value components

Type
Array.<Number>

(static) rgb2lab(rgb) → {Array.<Number>}

Convert a tuple of (red, green, blue) components into (lightness, a, b) equivalent. The lightness, a and b components are defined by the CIELAB color space.

red, green and blue range from 0 to 255. lightness ranges from 0 to 100, while a and b range from -100 to 100.

Parameters:
Name Type Description
rgb Array.<Number>

a 3 elements array representing the red, green and blue components

Source:
Returns:

lab a 3 elements array representing the lightness, a and b components

Type
Array.<Number>

(static) rgba2str(rgba) → {String}

Convert a tuple of (red, green, blue, alpha) components into color string equivalent.

red, green and blue range from 0 to 255, while alpha ranges from 0 to 1. Returned string color format is rgba(r, g, b, a) or #rrggbb, depending on the presence of the alpha factor.

Parameters:
Name Type Description
rgba Array.<Number>

a 4 elements array representing the red, green, blue and alpha components, respectively

Source:
Returns:
Type
String

(static) str2rgba(strColor) → {Array.<Number>}

Convert a color string into (red, green, blue, alpha) equivalent.

red, green and blue range from 0 to 255, while alpha ranges from 0 to 1. Accepted string color formats are rgb(r, g, b), rgba(r, g, b, a), #rrggbb and an HTML color name.

Parameters:
Name Type Description
strColor String
Source:
Returns:

a 4 elements array representing the red, green, blue and alpha components

Type
Array.<Number>