diff options
Diffstat (limited to 'node_modules/stylus/lib/functions/luminosity.js')
| -rw-r--r-- | node_modules/stylus/lib/functions/luminosity.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/node_modules/stylus/lib/functions/luminosity.js b/node_modules/stylus/lib/functions/luminosity.js new file mode 100644 index 00000000..6b6cf7d0 --- /dev/null +++ b/node_modules/stylus/lib/functions/luminosity.js @@ -0,0 +1,38 @@ +var utils = require('../utils') + , nodes = require('../nodes'); + +/** + * Returns the relative luminance of the given `color`, + * see http://www.w3.org/TR/WCAG20/#relativeluminancedef + * + * Examples: + * + * luminosity(white) + * // => 1 + * + * luminosity(#000) + * // => 0 + * + * luminosity(red) + * // => 0.2126 + * + * @param {RGBA|HSLA} color + * @return {Unit} + * @api public + */ + +module.exports = function luminosity(color){ + utils.assertColor(color); + color = color.rgba; + function processChannel(channel) { + channel = channel / 255; + return (0.03928 > channel) + ? channel / 12.92 + : Math.pow(((channel + 0.055) / 1.055), 2.4); + } + return new nodes.Unit( + 0.2126 * processChannel(color.r) + + 0.7152 * processChannel(color.g) + + 0.0722 * processChannel(color.b) + ); +}; |
