source: trip-planner-front/node_modules/stylus/lib/functions/blend.js

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

initial commit

  • Property mode set to 100644
File size: 937 bytes
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes');
3
4/**
5 * Blend the `top` color over the `bottom`
6 *
7 * Examples:
8 *
9 * blend(rgba(#FFF, 0.5), #000)
10 * // => #808080
11 *
12 * blend(rgba(#FFDE00,.42), #19C261)
13 * // => #7ace38
14 *
15 * blend(rgba(lime, 0.5), rgba(red, 0.25))
16 * // => rgba(128,128,0,0.625)
17 *
18 * @param {RGBA|HSLA} top
19 * @param {RGBA|HSLA} [bottom=#fff]
20 * @return {RGBA}
21 * @api public
22 */
23
24function blend(top, bottom){
25 // TODO: different blend modes like overlay etc.
26 utils.assertColor(top);
27 top = top.rgba;
28 bottom = bottom || new nodes.RGBA(255, 255, 255, 1);
29 utils.assertColor(bottom);
30 bottom = bottom.rgba;
31
32 return new nodes.RGBA(
33 top.r * top.a + bottom.r * (1 - top.a),
34 top.g * top.a + bottom.g * (1 - top.a),
35 top.b * top.a + bottom.b * (1 - top.a),
36 top.a + bottom.a - top.a * bottom.a);
37};
38blend.params = ['top', 'bottom'];
39module.exports = blend;
Note: See TracBrowser for help on using the repository browser.