1 | var nodes = require('../nodes')
|
2 | , rgba = require('./rgba');
|
3 |
|
4 | /**
|
5 | * Return the alpha component of the given `color`,
|
6 | * or set the alpha component to the optional second `value` argument.
|
7 | *
|
8 | * Examples:
|
9 | *
|
10 | * alpha(#fff)
|
11 | * // => 1
|
12 | *
|
13 | * alpha(rgba(0,0,0,0.3))
|
14 | * // => 0.3
|
15 | *
|
16 | * alpha(#fff, 0.5)
|
17 | * // => rgba(255,255,255,0.5)
|
18 | *
|
19 | * @param {RGBA|HSLA} color
|
20 | * @param {Unit} [value]
|
21 | * @return {Unit|RGBA}
|
22 | * @api public
|
23 | */
|
24 |
|
25 | function alpha(color, value){
|
26 | color = color.rgba;
|
27 | if (value) {
|
28 | return rgba(
|
29 | new nodes.Unit(color.r),
|
30 | new nodes.Unit(color.g),
|
31 | new nodes.Unit(color.b),
|
32 | value
|
33 | );
|
34 | }
|
35 | return new nodes.Unit(color.a, '');
|
36 | };
|
37 | alpha.params = ['color', 'value'];
|
38 | module.exports = alpha;
|