sfcode
An Online Competing and Development Environment
|
JavaScript library for color conversion and manipulation with support for CSS color strings.
Pass any valid CSS color string into Color()
or a hash of values. Also load in color values with rgb()
, hsl()
, hsv()
, hwb()
, and cmyk()
.
Set the values for individual channels with alpha
, red
, green
, blue
, hue
, saturation
(hsl), saturationv
(hsv), lightness
, whiteness
, blackness
, cyan
, magenta
, yellow
, black
Get a hash of the rgb values with rgb()
, similarly for hsl()
, hsv()
, and cmyk()
Get an array of the values with rgbArray()
, hslArray()
, hsvArray()
, and cmykArray()
.
Get the value for an individual channel.
Different CSS String formats for the color are on hexString
, rgbString
, percentString
, hslString
, hwbString
, and keyword
(undefined if it's not a keyword color). "rgba"
and "hsla"
are used if the current alpha value of the color isn't 1
.
The WCAG luminosity of the color. 0 is black, 1 is white.
The WCAG contrast ratio to another color, from 1 (same color) to 21 (contrast b/w white and black).
Get whether the color is "light" or "dark", useful for deciding text color.
You can can create a copy of an existing color object using clone()
:
And more to come...
The API was inspired by color-js. Manipulation functions by CSS tools like Sass, LESS, and Stylus.