UNPKG

1.97 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 * Decreases the intensity of a color. Its range is between 0 to 1. The first
13 * argument of the desaturate function is the amount by how much the color
14 * intensity should be decreased.
15 *
16 * @example
17 * // Styles as object usage
18 * const styles = {
19 * background: desaturate(0.2, '#CCCD64'),
20 * background: desaturate('0.2', 'rgba(204,205,100,0.7)'),
21 * }
22 *
23 * // styled-components usage
24 * const div = styled.div`
25 * background: ${desaturate(0.2, '#CCCD64')};
26 * background: ${desaturate('0.2', 'rgba(204,205,100,0.7)')};
27 * `
28 *
29 * // CSS in JS Output
30 * element {
31 * background: "#b8b979";
32 * background: "rgba(184,185,121,0.7)";
33 * }
34 */
35function desaturate(amount, color) {
36 if (color === 'transparent') return color;
37 var hslColor = (0, _parseToHsl["default"])(color);
38 return (0, _toColorString["default"])(_extends({}, hslColor, {
39 saturation: (0, _guard["default"])(0, 1, hslColor.saturation - parseFloat(amount))
40 }));
41}
42
43// prettier-ignore
44var curriedDesaturate = (0, _curry["default"] /* ::<number | string, string, string> */)(desaturate);
45var _default = exports["default"] = curriedDesaturate;
46module.exports = exports.default;
\No newline at end of file