UNPKG

1.86 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _parseToHsl = _interopRequireDefault(require("./parseToHsl"));
6var _toColorString = _interopRequireDefault(require("./toColorString"));
7var _curry = _interopRequireDefault(require("../internalHelpers/_curry"));
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
10/**
11 * Changes the hue of the color. Hue is a number between 0 to 360. The first
12 * argument for adjustHue is the amount of degrees the color is rotated around
13 * the color wheel, always producing a positive hue value.
14 *
15 * @example
16 * // Styles as object usage
17 * const styles = {
18 * background: adjustHue(180, '#448'),
19 * background: adjustHue('180', 'rgba(101,100,205,0.7)'),
20 * }
21 *
22 * // styled-components usage
23 * const div = styled.div`
24 * background: ${adjustHue(180, '#448')};
25 * background: ${adjustHue('180', 'rgba(101,100,205,0.7)')};
26 * `
27 *
28 * // CSS in JS Output
29 * element {
30 * background: "#888844";
31 * background: "rgba(136,136,68,0.7)";
32 * }
33 */
34function adjustHue(degree, color) {
35 if (color === 'transparent') return color;
36 var hslColor = (0, _parseToHsl["default"])(color);
37 return (0, _toColorString["default"])(_extends({}, hslColor, {
38 hue: hslColor.hue + parseFloat(degree)
39 }));
40}
41
42// prettier-ignore
43var curriedAdjustHue = (0, _curry["default"] /* ::<number | string, string, string> */)(adjustHue);
44var _default = exports["default"] = curriedAdjustHue;
45module.exports = exports.default;
\No newline at end of file