mirror of https://github.com/jkjoy/sunpeiwen.git
37 lines
794 B
JavaScript
37 lines
794 B
JavaScript
|
var nodes = require('../nodes')
|
||
|
, hsla = require('./hsla')
|
||
|
, component = require('./component');
|
||
|
|
||
|
/**
|
||
|
* Return the lightness component of the given `color`,
|
||
|
* or set the lightness component to the optional second `value` argument.
|
||
|
*
|
||
|
* Examples:
|
||
|
*
|
||
|
* lightness(#00c)
|
||
|
* // => 100%
|
||
|
*
|
||
|
* lightness(#00c, 80%)
|
||
|
* // => #99f
|
||
|
*
|
||
|
* @param {RGBA|HSLA} color
|
||
|
* @param {Unit} [value]
|
||
|
* @return {Unit|RGBA}
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
function lightness(color, value){
|
||
|
if (value) {
|
||
|
var hslaColor = color.hsla;
|
||
|
return hsla(
|
||
|
new nodes.Unit(hslaColor.h),
|
||
|
new nodes.Unit(hslaColor.s),
|
||
|
value,
|
||
|
new nodes.Unit(hslaColor.a)
|
||
|
)
|
||
|
}
|
||
|
return component(color, new nodes.String('lightness'));
|
||
|
};
|
||
|
lightness.params = ['color', 'value'];
|
||
|
module.exports = lightness;
|