1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.selectedStyle = exports.activeStyle = exports.backgroundStyle = exports.backgroundIsDark = exports.normalizeBackground = void 0;
|
5 |
|
6 | var _styledComponents = require("styled-components");
|
7 |
|
8 | var _colors = require("./colors");
|
9 |
|
10 | var _styles = require("./styles");
|
11 |
|
12 | var normalizeBackground = function normalizeBackground(background, theme) {
|
13 |
|
14 | var result = background;
|
15 |
|
16 | if (background) {
|
17 | if (theme.dark && background.dark && typeof background.dark !== 'boolean') {
|
18 | result = background.dark;
|
19 | } else if (!theme.dark && background.light && typeof background.light !== 'boolean') {
|
20 | result = background.light;
|
21 | }
|
22 |
|
23 | result = (0, _styles.evalStyle)(result, theme);
|
24 | }
|
25 |
|
26 | return result;
|
27 | };
|
28 |
|
29 | exports.normalizeBackground = normalizeBackground;
|
30 |
|
31 | var backgroundIsDark = function backgroundIsDark(backgroundArg, theme) {
|
32 | var background = normalizeBackground(backgroundArg, theme);
|
33 | var result;
|
34 |
|
35 | if (background) {
|
36 | if (typeof background === 'object') {
|
37 | var color = background.color,
|
38 | dark = background.dark,
|
39 | opacity = background.opacity;
|
40 |
|
41 | if (typeof dark === 'boolean') {
|
42 | result = dark;
|
43 | } else if (color && (
|
44 | !opacity || opacity !== 'weak')) {
|
45 | var backgroundColor = (0, _colors.normalizeColor)(background.color, theme);
|
46 |
|
47 | if (backgroundColor) {
|
48 | result = (0, _colors.colorIsDark)(backgroundColor);
|
49 | }
|
50 | }
|
51 | } else {
|
52 | var _color = (0, _colors.normalizeColor)(background, theme);
|
53 |
|
54 | if (_color) {
|
55 | result = (0, _colors.colorIsDark)(_color);
|
56 | }
|
57 | }
|
58 | }
|
59 |
|
60 | return result;
|
61 | };
|
62 |
|
63 | exports.backgroundIsDark = backgroundIsDark;
|
64 |
|
65 | var backgroundStyle = function backgroundStyle(backgroundArg, theme, textColorArg) {
|
66 |
|
67 | var background = normalizeBackground(backgroundArg, theme);
|
68 | var textColor = textColorArg || theme.global.colors.text;
|
69 |
|
70 | if (typeof background === 'object') {
|
71 | var styles = [];
|
72 |
|
73 | if (background.image) {
|
74 | var color;
|
75 |
|
76 | if (background.dark === false) {
|
77 | color = textColor.light;
|
78 | } else if (background.dark) {
|
79 | color = textColor.dark;
|
80 | } else if (!textColorArg) {
|
81 | color = 'inherit';
|
82 | }
|
83 |
|
84 | styles.push((0, _styledComponents.css)(["background-image:", ";background-repeat:no-repeat;background-position:", ";background-size:cover;color:", ";"], background.image, background.position || 'center center', color));
|
85 | }
|
86 |
|
87 | if (background.color) {
|
88 | var _color2 = (0, _colors.normalizeColor)(background.color, theme);
|
89 |
|
90 | var backgroundColor = (0, _colors.getRGBA)(_color2, background.opacity === true ? theme.global.opacity.medium : theme.global.opacity[background.opacity] || background.opacity) || _color2;
|
91 |
|
92 | styles.push((0, _styledComponents.css)(["background-color:", ";", ""], backgroundColor, (!background.opacity || background.opacity !== 'weak') && "color: " + textColor[background.dark || (0, _colors.colorIsDark)(backgroundColor) ? 'dark' : 'light'] + ";"));
|
93 | }
|
94 |
|
95 | if (background.dark === false) {
|
96 | styles.push((0, _styledComponents.css)(["color:", ";"], textColor.light));
|
97 | } else if (background.dark) {
|
98 | styles.push((0, _styledComponents.css)(["color:", ";"], textColor.dark));
|
99 | }
|
100 |
|
101 | return styles;
|
102 | }
|
103 |
|
104 | if (background) {
|
105 | if (background.lastIndexOf('url', 0) === 0) {
|
106 | return (0, _styledComponents.css)(["background:", " no-repeat center center;background-size:cover;"], background);
|
107 | }
|
108 |
|
109 | var _color3 = (0, _colors.normalizeColor)(background, theme);
|
110 |
|
111 | if (_color3) {
|
112 | return (0, _styledComponents.css)(["background:", ";color:", ";"], _color3, textColor[(0, _colors.colorIsDark)(_color3) ? 'dark' : 'light']);
|
113 | }
|
114 | }
|
115 |
|
116 | return undefined;
|
117 | };
|
118 |
|
119 | exports.backgroundStyle = backgroundStyle;
|
120 | var activeStyle = (0, _styledComponents.css)(["", " color:", ";"], function (props) {
|
121 | return backgroundStyle((0, _colors.normalizeColor)(props.theme.global.hover.background, props.theme), props.theme);
|
122 | }, function (props) {
|
123 | return (0, _colors.normalizeColor)(props.theme.global.hover.color, props.theme);
|
124 | });
|
125 | exports.activeStyle = activeStyle;
|
126 | var selectedStyle = (0, _styledComponents.css)(["", " color:", ";"], function (props) {
|
127 | return backgroundStyle((0, _colors.normalizeColor)(props.theme.global.selected.background, props.theme), props.theme);
|
128 | }, function (props) {
|
129 | return (0, _colors.normalizeColor)(props.theme.global.selected.color, props.theme);
|
130 | });
|
131 | exports.selectedStyle = selectedStyle; |
\ | No newline at end of file |