The goog.color.alpha Namespace

.extractAlpha(colorWithAlpha)

Gets the alpha color part of an alpha hex color. For example, from '#abcdef55' return '55'. The result is guaranteed to be two characters long.

colorWithAlpha {string}
The alpha hex color to get the hex color from.
returns {string}
The hex color where the alpha part has been stripped off.

.extractHexColor(colorWithAlpha)

Gets the hex color part of an alpha hex color. For example, from '#abcdef55' return '#abcdef'.

colorWithAlpha {string}
The alpha hex color to get the hex color from.
returns {string}
The hex color where the alpha part has been stripped off.

.hexToRgba(hexColor)

Converts an 8-hex representation of a color to RGBA.

hexColor {string}
Color to convert.
returns {Array}
array containing [r, g, b] as ints in [0, 255].

.hexToRgbaStyle(hexColor)

Converts a hex representation of a color to RGBA.

hexColor {string}
Color to convert.
returns {string}
string of the form 'rgba(R,G,B,A)' which can be used in styles.

.hslaArrayToHex(hsla)

Converts a color from HSLA to hex representation.

hsla {Array.<number>}
Array of [h, s, l, a], where h is an integer in [0, 360], s and l are integers in [0, 100], and a is in [0, 1].
returns {string}
hex representation of the color, such as '#af457eff'.

.hslaArrayToRgbaStyle(hsla)

Converts a color from HSLA to an RGBA style string.

hsla {Array.<number>}
Array of [h, s, l, a], where h is and integer in [0, 360], s and l are integers in [0, 100], and a is in [0, 1].
returns {string}
An 'rgba(r,g,b,a)' string ready for use in a CSS rule.

.hslaToHex(h, s, l, a)

Converts a color from HSLA to hex representation.

h {number}
Amount of hue, int between 0 and 360.
s {number}
Amount of saturation, int between 0 and 100.
l {number}
Amount of lightness, int between 0 and 100.
a {number}
Amount of alpha, float between 0 and 1.
returns {string}
hex representation of the color.

.hslaToRgba(h, s, l, a)

Converts a color from HSLA color space to RGBA color space.

h {number}
Amount of hue, int between 0 and 360.
s {number}
Amount of saturation, int between 0 and 100.
l {number}
Amount of lightness, int between 0 and 100.
a {number}
Amount of alpha, float between 0 and 1.
returns {Array.<number>}
[r, g, b, a] values for the color, where r, g, b are integers in [0, 255] and a is a float in [0, 1].

.hslaToRgbaStyle(h, s, l, a)

Converts a color from HSLA to an RGBA style string.

h {number}
Amount of hue, int between 0 and 360.
s {number}
Amount of saturation, int between 0 and 100.
l {number}
Amount of lightness, int between 0 and 100.
a {number}
Amount of alpha, float between 0 and 1.
returns {string}
An 'rgba(r,g,b,a)' string ready for use in a CSS rule. styles.

.hsvaArrayToHex(hsva)

Converts from an HSVA array to a hex string

hsva {Array}
Array of [h, s, v, a] in [[0, 1], [0, 1], [0, 255], [0, 1]].
returns {string}
hex representation of the color.

.hsvaToHex(h, s, v, a)

Converts from h,s,v,a values to a hex string

h {number}
Hue, in [0, 1].
s {number}
Saturation, in [0, 1].
v {number}
Value, in [0, 255].
a {number}
Alpha, in [0, 1].
returns {string}
hex representation of the color.

.parse(str)

Parses an alpha color out of a string.

str {string}
Color in some format.
returns {Object}
Contains two properties: 'hex', which is a string containing a hex representation of the color, as well as 'type', which is a string containing the type of color format passed in ('hex', 'rgb', 'named').

.rgbaArrayToHex(rgba)

Converts a color from RGBA to hex representation.

rgba {Array.<number>}
Array of [r, g, b, a], with r, g, b in [0, 255] and a in [0, 1].
returns {string}
hex representation of the color.

.rgbaArrayToHsla(rgba)

Converts a color from RGBA color space to HSLA color space.

rgba {Array.<number>}
[r, g, b, a] values for the color, each in [0, 255].
returns {Array.<number>}
[h, s, l, a] values for the color, with h in [0, 360] and s, l and a in [0, 1].

.rgbaArrayToRgbaStyle(rgba)

Converts a color from RGBA to an RGBA style string.

rgba {(Array.<number>|Float32Array)}
Array of [r, g, b, a], with r, g, b in [0, 255] and a in [0, 1].
returns {string}
An 'rgba(r,g,b,a)' string ready for use in a CSS rule.

.rgbaToHex(r, g, b, a)

Converts a color from RGBA to hex representation.

r {number}
Amount of red, int between 0 and 255.
g {number}
Amount of green, int between 0 and 255.
b {number}
Amount of blue, int between 0 and 255.
a {number}
Amount of alpha, float between 0 and 1.
returns {string}
hex representation of the color.

.rgbaToHsla(r, g, b, a)

Converts a color from RGBA color space to HSLA color space. Modified from {@link http://en.wikipedia.org/wiki/HLS_color_space}.

r {number}
Value of red, in [0, 255].
g {number}
Value of green, in [0, 255].
b {number}
Value of blue, in [0, 255].
a {number}
Value of alpha, in [0, 255].
returns {Array.<number>}
[h, s, l, a] values for the color, with h an int in [0, 360] and s, l and a in [0, 1].

.rgbaToRgbaStyle(r, g, b, a)

Converts a color from RGBA to an RGBA style string.

r {number}
Value of red, in [0, 255].
g {number}
Value of green, in [0, 255].
b {number}
Value of blue, in [0, 255].
a {number}
Value of alpha, in [0, 1].
returns {string}
An 'rgba(r,g,b,a)' string ready for use in a CSS rule.