lightness.js 794 B

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