UNPKG

1.81 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 * Returns a string value for the lightened color.
13 *
14 * @example
15 * // Styles as object usage
16 * const styles = {
17 * background: lighten(0.2, '#CCCD64'),
18 * background: lighten('0.2', 'rgba(204,205,100,0.7)'),
19 * }
20 *
21 * // styled-components usage
22 * const div = styled.div`
23 * background: ${lighten(0.2, '#FFCD64')};
24 * background: ${lighten('0.2', 'rgba(204,205,100,0.7)')};
25 * `
26 *
27 * // CSS in JS Output
28 *
29 * element {
30 * background: "#e5e6b1";
31 * background: "rgba(229,230,177,0.7)";
32 * }
33 */
34function lighten(amount, color) {
35 if (color === 'transparent') return color;
36 var hslColor = (0, _parseToHsl["default"])(color);
37 return (0, _toColorString["default"])(_extends({}, hslColor, {
38 lightness: (0, _guard["default"])(0, 1, hslColor.lightness + parseFloat(amount))
39 }));
40}
41
42// prettier-ignore
43var curriedLighten = (0, _curry["default"] /* ::<number | string, string, string> */)(lighten);
44var _default = exports["default"] = curriedLighten;
45module.exports = exports.default;
\No newline at end of file