source: trip-planner-front/node_modules/stylus/lib/functions/component.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes');
3
4/**
5 * Color component name map.
6 */
7
8var componentMap = {
9 red: 'r'
10 , green: 'g'
11 , blue: 'b'
12 , alpha: 'a'
13 , hue: 'h'
14 , saturation: 's'
15 , lightness: 'l'
16};
17
18/**
19 * Color component unit type map.
20 */
21
22var unitMap = {
23 hue: 'deg'
24 , saturation: '%'
25 , lightness: '%'
26};
27
28/**
29 * Color type map.
30 */
31
32var typeMap = {
33 red: 'rgba'
34 , blue: 'rgba'
35 , green: 'rgba'
36 , alpha: 'rgba'
37 , hue: 'hsla'
38 , saturation: 'hsla'
39 , lightness: 'hsla'
40};
41
42/**
43 * Return component `name` for the given `color`.
44 *
45 * @param {RGBA|HSLA} color
46 * @param {String} name
47 * @return {Unit}
48 * @api public
49 */
50
51function component(color, name) {
52 utils.assertColor(color, 'color');
53 utils.assertString(name, 'name');
54 var name = name.string
55 , unit = unitMap[name]
56 , type = typeMap[name]
57 , name = componentMap[name];
58 if (!name) throw new Error('invalid color component "' + name + '"');
59 return new nodes.Unit(color[type][name], unit);
60};
61component.params = ['color', 'name'];
62module.exports = component;
Note: See TracBrowser for help on using the repository browser.