UNPKG

1.48 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = invert;
5var _parseToRgb = _interopRequireDefault(require("./parseToRgb"));
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 * Inverts the red, green and blue values of a color.
11 *
12 * @example
13 * // Styles as object usage
14 * const styles = {
15 * background: invert('#CCCD64'),
16 * background: invert('rgba(101,100,205,0.7)'),
17 * }
18 *
19 * // styled-components usage
20 * const div = styled.div`
21 * background: ${invert('#CCCD64')};
22 * background: ${invert('rgba(101,100,205,0.7)')};
23 * `
24 *
25 * // CSS in JS Output
26 *
27 * element {
28 * background: "#33329b";
29 * background: "rgba(154,155,50,0.7)";
30 * }
31 */
32function invert(color) {
33 if (color === 'transparent') return color;
34 // parse color string to rgb
35 var value = (0, _parseToRgb["default"])(color);
36 return (0, _toColorString["default"])(_extends({}, value, {
37 red: 255 - value.red,
38 green: 255 - value.green,
39 blue: 255 - value.blue
40 }));
41}
42module.exports = exports.default;
\No newline at end of file