Color Class
Color provides static methods for color conversion.
Y.Color.toRGB('f00'); // rgb(255, 0, 0)
Y.Color.toHex('rgb(255, 255, 0)'); // #ffff00
Index
Methods
Methods
_convertTo
-
clr
-
to
Converts the provided color string to the value type provided as to
Parameters:
-
clr
String -
to
String
Returns:
_getAlpha
-
clr
Retrives the alpha channel from the provided string. If no alpha
channel is present, 1
will be returned.
Parameters:
-
clr
String
Returns:
_hexToRgb
-
str
-
[toArray]
Processes the hex string into r, g, b values. Will return values as an array, or as an rgb string.
Parameters:
-
str
String -
[toArray]
Boolean optional
Returns:
_keywordToHex
-
clr
Returns the hex value string if found in the KEYWORDS object
Parameters:
-
clr
String
Returns:
_rgbToHex
-
str
-
[toArray]
Processes the rgb string into r, g, b values. Will return values as an array, or as a hex string.
Parameters:
-
str
String -
[toArray]
Boolean optional
Returns:
convert
-
str
-
to
Converts the provided string to the provided type.
You can use the Y.Color.TYPES
to get a valid to
type.
If the color cannot be converted, the original color will be returned.
Parameters:
-
str
String -
to
String
Returns:
findType
-
str
Finds the value type based on the str value provided.
Parameters:
-
str
String
Returns:
fromArray
-
arr
-
template
Converts the array of values to a string based on the provided template.
Parameters:
-
arr
Array -
template
String
Returns:
toArray
-
str
Converts the provided color string to an array of values where the last value is the alpha value. Will return an empty array if the provided string is not able to be parsed.
NOTE: (\ufffe)?
is added to HEX
and HEX3
Regular Expressions to
carve out a place for the alpha channel that is returned from
toArray without compromising any usage of the Regular Expression
Y.Color.toArray('fff'); // ['ff', 'ff', 'ff', 1]
Y.Color.toArray('rgb(0, 0, 0)'); // ['0', '0', '0', 1]
Y.Color.toArray('rgba(0, 0, 0, 0)'); // ['0', '0', '0', 1]
Parameters:
-
str
String
Returns:
toHex
-
str
Converts provided color value to a hex value string
Parameters:
-
str
StringHex or RGB value string
Returns:
returns array of values or CSS string if options.css is true
toRGB
-
str
Converts provided color value to an RGB value string
Parameters:
-
str
StringHex or RGB value string
Returns:
toRGBA
-
str
Converts provided color value to an RGB value string
Parameters:
-
str
StringHex or RGB value string
Returns:
Properties
CONVERTS
Object
static
Default: {}
KEYWORDS
Object
static
REGEX_HEX
RegExp
static
NOTE: (\ufffe)?
is added to the Regular Expression to carve out a
place for the alpha channel that is returned from toArray
without compromising any usage of the Regular Expression
Default: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})(\ufffe)?/
REGEX_HEX3
RegExp
static
NOTE: (\ufffe)?
is added to the Regular Expression to carve out a
place for the alpha channel that is returned from toArray
without compromising any usage of the Regular Expression
Default: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})(\ufffe)?/
REGEX_RGB
RegExp
static
Default: /rgba?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}),? ?([.0-9]{1,3})?\)/
STR_HEX
String
static
Default: #{*}{*}{*}
STR_RGB
String
static
Default: rgb({*}, {*}, {*})
STR_RGBA
String
static
Default: rgba({*}, {*}, {*}, {*})
TYPES
Object
static
Default: {'rgb':'rgb', 'rgba':'rgba'}