red.js 670 B

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