UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = complement;
5var _parseToHsl = _interopRequireDefault(require("./parseToHsl"));
6var _toColorString = _interopRequireDefault(require("./toColorString"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8function _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); }
9/**
10 * Returns the complement of the provided color. This is identical to adjustHue(180, <color>).
11 *
12 * @example
13 * // Styles as object usage
14 * const styles = {
15 * background: complement('#448'),
16 * background: complement('rgba(204,205,100,0.7)'),
17 * }
18 *
19 * // styled-components usage
20 * const div = styled.div`
21 * background: ${complement('#448')};
22 * background: ${complement('rgba(204,205,100,0.7)')};
23 * `
24 *
25 * // CSS in JS Output
26 * element {
27 * background: "#884";
28 * background: "rgba(153,153,153,0.7)";
29 * }
30 */
31function complement(color) {
32 if (color === 'transparent') return color;
33 var hslColor = (0, _parseToHsl["default"])(color);
34 return (0, _toColorString["default"])(_extends({}, hslColor, {
35 hue: (hslColor.hue + 180) % 360
36 }));
37}
38module.exports = exports.default;
\No newline at end of file