alpha.js 748 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var nodes = require('../nodes')
  2. , rgba = require('./rgba');
  3. /**
  4. * Return the alpha component of the given `color`,
  5. * or set the alpha component to the optional second `value` argument.
  6. *
  7. * Examples:
  8. *
  9. * alpha(#fff)
  10. * // => 1
  11. *
  12. * alpha(rgba(0,0,0,0.3))
  13. * // => 0.3
  14. *
  15. * alpha(#fff, 0.5)
  16. * // => rgba(255,255,255,0.5)
  17. *
  18. * @param {RGBA|HSLA} color
  19. * @param {Unit} [value]
  20. * @return {Unit|RGBA}
  21. * @api public
  22. */
  23. function alpha(color, value){
  24. color = color.rgba;
  25. if (value) {
  26. return rgba(
  27. new nodes.Unit(color.r),
  28. new nodes.Unit(color.g),
  29. new nodes.Unit(color.b),
  30. value
  31. );
  32. }
  33. return new nodes.Unit(color.a, '');
  34. };
  35. alpha.params = ['color', 'value'];
  36. module.exports = alpha;