Module: CSSUtils

Some CSS utilities.
Source:

Methods

(static) applyCSS(elem, prop)

Apply CSS styles to element.
Parameters:
Name Type Description
elem object DOM element.
prop string CSS property.
Source:

(static) brightness(rgb) → {number}

Compute color brightness.
Parameters:
Name Type Description
rgb string RGB color.
Source:
Returns:
Type
number

(static) colorContrast(elem) → {number}

Compute color contrast.
Parameters:
Name Type Description
elem object DOM element.
Source:
Returns:
Type
number

(static) colorTuple(color) → {array}

Transform color to a 3 or 4 length tuple (array).
Parameters:
Name Type Description
color string RGB color.
Source:
Returns:
Type
array

(static) cssColor(num) → {string}

Number to CSS color.
Parameters:
Name Type Description
num int Decimal number
Source:
Returns:
Type
string

(static) dash2camel(str) → {string}

Convert str with dashes to camelCaseNotation.
Parameters:
Name Type Description
str string Input string.
Source:
Returns:
Type
string

(static) getStyle(elem, prop) → {string}

Get the CSS style of a DOM element, after all styles are applied to the page.
Parameters:
Name Type Description
elem object DOM element.
prop string CSS property.
Source:
Returns:
Type
string

(static) parseColor(color) → {array}

Convert a color to an array of R,G,B values in [0, 255].
Parameters:
Name Type Description
color string Color definition: rgb(R,G,B) or rgba(R,G,B,A) or hsl(H,S,L) or hsl(H,S,L,A) or #RGB or # RRGGBB.
Source:
Returns:
Type
array

(static) parseDimension(dim) → {object|number|string}

Retrieve the parts of a dimension definition (e.g. "15px", "2.5em"...)
Parameters:
Name Type Description
dim string Input dimension.
Source:
Returns:
  • result
    Type
    object
  • result.value
    Type
    number
  • result.unit
    Type
    string

(static) rgb2dec(R,G,B) → {int}

R,G,B array color to decimal number.
Parameters:
Name Type Description
R,G,B array values.
Source:
Returns:
Type
int

(static) rgb2hex(R,G,B) → {int}

R,G,B array color to hexadecimal.
Parameters:
Name Type Description
R,G,B array values.
Source:
Returns:
Type
int

(static) rgba2rgb(num) → {string}

Convert RGBA to RGB.
Parameters:
Name Type Description
num int Decimal number
Source:
Returns:
Type
string

(static) rgbDiff(num) → {string}

Compute difference between 2 RGB colors.
Parameters:
Name Type Description
num int Decimal number
Source:
Returns:
Type
string

(static) setStyle(elem, prop, value)

Set a CSS style for a given DOM element.
Parameters:
Name Type Description
elem object DOM element
prop string CSS property
value string CSS value
Source: