UNPKG

1.95 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _curry = _interopRequireDefault(require("../internalHelpers/_curry"));
6var _guard = _interopRequireDefault(require("../internalHelpers/_guard"));
7var _parseToHsl = _interopRequireDefault(require("./parseToHsl"));
8var _toColorString = _interopRequireDefault(require("./toColorString"));
9function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10function _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); }
11/**
12 * Increases the intensity of a color. Its range is between 0 to 1. The first
13 * argument of the saturate function is the amount by how much the color
14 * intensity should be increased.
15 *
16 * @example
17 * // Styles as object usage
18 * const styles = {
19 * background: saturate(0.2, '#CCCD64'),
20 * background: saturate('0.2', 'rgba(204,205,100,0.7)'),
21 * }
22 *
23 * // styled-components usage
24 * const div = styled.div`
25 * background: ${saturate(0.2, '#FFCD64')};
26 * background: ${saturate('0.2', 'rgba(204,205,100,0.7)')};
27 * `
28 *
29 * // CSS in JS Output
30 *
31 * element {
32 * background: "#e0e250";
33 * background: "rgba(224,226,80,0.7)";
34 * }
35 */
36function saturate(amount, color) {
37 if (color === 'transparent') return color;
38 var hslColor = (0, _parseToHsl["default"])(color);
39 return (0, _toColorString["default"])(_extends({}, hslColor, {
40 saturation: (0, _guard["default"])(0, 1, hslColor.saturation + parseFloat(amount))
41 }));
42}
43
44// prettier-ignore
45var curriedSaturate = (0, _curry["default"] /* ::<number | string, string, string> */)(saturate);
46var _default = exports["default"] = curriedSaturate;
47module.exports = exports.default;
\No newline at end of file