source: trip-planner-front/node_modules/stylus/lib/functions/luminosity.js@ eed0bf8

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

initial commit

  • Property mode set to 100644
File size: 864 bytes
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes');
3
4/**
5 * Returns the relative luminance of the given `color`,
6 * see http://www.w3.org/TR/WCAG20/#relativeluminancedef
7 *
8 * Examples:
9 *
10 * luminosity(white)
11 * // => 1
12 *
13 * luminosity(#000)
14 * // => 0
15 *
16 * luminosity(red)
17 * // => 0.2126
18 *
19 * @param {RGBA|HSLA} color
20 * @return {Unit}
21 * @api public
22 */
23
24function luminosity(color){
25 utils.assertColor(color);
26 color = color.rgba;
27 function processChannel(channel) {
28 channel = channel / 255;
29 return (0.03928 > channel)
30 ? channel / 12.92
31 : Math.pow(((channel + 0.055) / 1.055), 2.4);
32 }
33 return new nodes.Unit(
34 0.2126 * processChannel(color.r)
35 + 0.7152 * processChannel(color.g)
36 + 0.0722 * processChannel(color.b)
37 );
38};
39luminosity.params = ['color'];
40module.exports = luminosity;
Note: See TracBrowser for help on using the repository browser.