hue.js 750 B

123456789101112131415161718192021222324252627282930313233343536
  1. var nodes = require('../nodes')
  2. , hsla = require('./hsla')
  3. , component = require('./component');
  4. /**
  5. * Return the hue component of the given `color`,
  6. * or set the hue component to the optional second `value` argument.
  7. *
  8. * Examples:
  9. *
  10. * hue(#00c)
  11. * // => 240deg
  12. *
  13. * hue(#00c, 90deg)
  14. * // => #6c0
  15. *
  16. * @param {RGBA|HSLA} color
  17. * @param {Unit} [value]
  18. * @return {Unit|RGBA}
  19. * @api public
  20. */
  21. function hue(color, value){
  22. if (value) {
  23. var hslaColor = color.hsla;
  24. return hsla(
  25. value,
  26. new nodes.Unit(hslaColor.s),
  27. new nodes.Unit(hslaColor.l),
  28. new nodes.Unit(hslaColor.a)
  29. )
  30. }
  31. return component(color, new nodes.String('hue'));
  32. };
  33. hue.params = ['color', 'value'];
  34. module.exports = hue;