UNPKG

1.8 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 darkened color.
13 *
14 * @example
15 * // Styles as object usage
16 * const styles = {
17 * background: darken(0.2, '#FFCD64'),
18 * background: darken('0.2', 'rgba(255,205,100,0.7)'),
19 * }
20 *
21 * // styled-components usage
22 * const div = styled.div`
23 * background: ${darken(0.2, '#FFCD64')};
24 * background: ${darken('0.2', 'rgba(255,205,100,0.7)')};
25 * `
26 *
27 * // CSS in JS Output
28 *
29 * element {
30 * background: "#ffbd31";
31 * background: "rgba(255,189,49,0.7)";
32 * }
33 */
34function darken(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 curriedDarken = (0, _curry["default"] /* ::<number | string, string, string> */)(darken);
44var _default = exports["default"] = curriedDarken;
45module.exports = exports.default;
\No newline at end of file