Sha256: b69b4d87173693d82e08f77f3579b7feb06ff1d7b40b66e7d51198e0edfb43f8
Contents?: true
Size: 1.44 KB
Versions: 39
Compression:
Stored size: 1.44 KB
Contents
var utils = require('../utils') , nodes = require('../nodes'); /** * Return a `RGBA` from the r,g,b,a channels. * * Examples: * * rgba(255,0,0,0.5) * // => rgba(255,0,0,0.5) * * rgba(255,0,0,1) * // => #ff0000 * * rgba(#ffcc00, 50%) * // rgba(255,204,0,0.5) * * @param {Unit|RGBA|HSLA} red * @param {Unit} green * @param {Unit} blue * @param {Unit} alpha * @return {RGBA} * @api public */ module.exports = function rgba(red, green, blue, alpha){ switch (arguments.length) { case 1: utils.assertColor(red); return red.rgba; case 2: utils.assertColor(red); var color = red.rgba; utils.assertType(green, 'unit', 'alpha'); alpha = green.clone(); if ('%' == alpha.type) alpha.val /= 100; return new nodes.RGBA( color.r , color.g , color.b , alpha.val); default: utils.assertType(red, 'unit', 'red'); utils.assertType(green, 'unit', 'green'); utils.assertType(blue, 'unit', 'blue'); utils.assertType(alpha, 'unit', 'alpha'); var r = '%' == red.type ? Math.round(red.val * 2.55) : red.val , g = '%' == green.type ? Math.round(green.val * 2.55) : green.val , b = '%' == blue.type ? Math.round(blue.val * 2.55) : blue.val; alpha = alpha.clone(); if (alpha && '%' == alpha.type) alpha.val /= 100; return new nodes.RGBA( r , g , b , alpha.val); } };
Version data entries
39 entries across 20 versions & 2 rubygems