@qoretechnologies/reqore 0.78.11-pr.723.g4423093 → 0.78.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordion/index.d.ts.map +1 -1
- package/dist/components/Accordion/index.js +14 -60
- package/dist/components/Accordion/index.js.map +1 -1
- package/dist/components/Breadcrumbs/index.d.ts.map +1 -1
- package/dist/components/Breadcrumbs/index.js +21 -58
- package/dist/components/Breadcrumbs/index.js.map +1 -1
- package/dist/components/Bubble/index.d.ts.map +1 -1
- package/dist/components/Bubble/index.js +4 -13
- package/dist/components/Bubble/index.js.map +1 -1
- package/dist/components/Button/index.d.ts +0 -67
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Button/index.js +98 -238
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Callout/index.d.ts.map +1 -1
- package/dist/components/Callout/index.js +29 -49
- package/dist/components/Callout/index.js.map +1 -1
- package/dist/components/Checkbox/index.d.ts.map +1 -1
- package/dist/components/Checkbox/index.js +36 -112
- package/dist/components/Checkbox/index.js.map +1 -1
- package/dist/components/CollapsibleContent/index.d.ts.map +1 -1
- package/dist/components/CollapsibleContent/index.js +2 -6
- package/dist/components/CollapsibleContent/index.js.map +1 -1
- package/dist/components/ControlGroup/index.d.ts.map +1 -1
- package/dist/components/ControlGroup/index.js +1 -22
- package/dist/components/ControlGroup/index.js.map +1 -1
- package/dist/components/DataView/index.d.ts.map +1 -1
- package/dist/components/DataView/index.js +10 -13
- package/dist/components/DataView/index.js.map +1 -1
- package/dist/components/DescriptionList/index.d.ts.map +1 -1
- package/dist/components/DescriptionList/index.js +4 -30
- package/dist/components/DescriptionList/index.js.map +1 -1
- package/dist/components/Drawer/index.d.ts.map +1 -1
- package/dist/components/Drawer/index.js +25 -41
- package/dist/components/Drawer/index.js.map +1 -1
- package/dist/components/Dropdown/list.d.ts.map +1 -1
- package/dist/components/Dropdown/list.js +14 -19
- package/dist/components/Dropdown/list.js.map +1 -1
- package/dist/components/Effect/index.d.ts +0 -37
- package/dist/components/Effect/index.d.ts.map +1 -1
- package/dist/components/Effect/index.js +58 -224
- package/dist/components/Effect/index.js.map +1 -1
- package/dist/components/EntityRow/index.d.ts.map +1 -1
- package/dist/components/EntityRow/index.js +59 -98
- package/dist/components/EntityRow/index.js.map +1 -1
- package/dist/components/FeatureCard/index.d.ts.map +1 -1
- package/dist/components/FeatureCard/index.js +21 -54
- package/dist/components/FeatureCard/index.js.map +1 -1
- package/dist/components/Header/index.d.ts.map +1 -1
- package/dist/components/Header/index.js +4 -7
- package/dist/components/Header/index.js.map +1 -1
- package/dist/components/Icon/index.d.ts.map +1 -1
- package/dist/components/Icon/index.js +3 -13
- package/dist/components/Icon/index.js.map +1 -1
- package/dist/components/Input/index.d.ts +1 -44
- package/dist/components/Input/index.d.ts.map +1 -1
- package/dist/components/Input/index.js +23 -89
- package/dist/components/Input/index.js.map +1 -1
- package/dist/components/InputClearButton/index.d.ts +2 -7
- package/dist/components/InputClearButton/index.d.ts.map +1 -1
- package/dist/components/InputClearButton/index.js +5 -12
- package/dist/components/InputClearButton/index.js.map +1 -1
- package/dist/components/InternalPopover/index.d.ts.map +1 -1
- package/dist/components/InternalPopover/index.js +10 -19
- package/dist/components/InternalPopover/index.js.map +1 -1
- package/dist/components/Link/index.d.ts.map +1 -1
- package/dist/components/Link/index.js +1 -6
- package/dist/components/Link/index.js.map +1 -1
- package/dist/components/Menu/divider.d.ts.map +1 -1
- package/dist/components/Menu/divider.js +3 -8
- package/dist/components/Menu/divider.js.map +1 -1
- package/dist/components/Menu/index.d.ts.map +1 -1
- package/dist/components/Menu/index.js +4 -17
- package/dist/components/Menu/index.js.map +1 -1
- package/dist/components/Message/index.d.ts.map +1 -1
- package/dist/components/Message/index.js +4 -20
- package/dist/components/Message/index.js.map +1 -1
- package/dist/components/NavRail/index.d.ts +0 -2
- package/dist/components/NavRail/index.d.ts.map +1 -1
- package/dist/components/NavRail/index.js +40 -120
- package/dist/components/NavRail/index.js.map +1 -1
- package/dist/components/Notifications/notification.d.ts +2 -6
- package/dist/components/Notifications/notification.d.ts.map +1 -1
- package/dist/components/Notifications/notification.js +18 -78
- package/dist/components/Notifications/notification.js.map +1 -1
- package/dist/components/Notifications/styles.d.ts +0 -20
- package/dist/components/Notifications/styles.d.ts.map +1 -1
- package/dist/components/Notifications/styles.js +9 -37
- package/dist/components/Notifications/styles.js.map +1 -1
- package/dist/components/Panel/index.d.ts +0 -3
- package/dist/components/Panel/index.d.ts.map +1 -1
- package/dist/components/Panel/index.js +153 -214
- package/dist/components/Panel/index.js.map +1 -1
- package/dist/components/Paragraph/index.d.ts.map +1 -1
- package/dist/components/Paragraph/index.js +5 -8
- package/dist/components/Paragraph/index.js.map +1 -1
- package/dist/components/Progress/index.d.ts.map +1 -1
- package/dist/components/Progress/index.js +1 -1
- package/dist/components/Progress/index.js.map +1 -1
- package/dist/components/Rating/index.d.ts.map +1 -1
- package/dist/components/Rating/index.js +8 -20
- package/dist/components/Rating/index.js.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts +5 -0
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +52 -90
- package/dist/components/RichTextEditor/index.js.map +1 -1
- package/dist/components/SegmentedControl/index.d.ts.map +1 -1
- package/dist/components/SegmentedControl/index.js +42 -87
- package/dist/components/SegmentedControl/index.js.map +1 -1
- package/dist/components/SeverityRow/index.d.ts.map +1 -1
- package/dist/components/SeverityRow/index.js +1 -1
- package/dist/components/SeverityRow/index.js.map +1 -1
- package/dist/components/Span/index.d.ts.map +1 -1
- package/dist/components/Span/index.js +5 -8
- package/dist/components/Span/index.js.map +1 -1
- package/dist/components/StackedBar/index.d.ts.map +1 -1
- package/dist/components/StackedBar/index.js +12 -42
- package/dist/components/StackedBar/index.js.map +1 -1
- package/dist/components/Statistic/index.d.ts.map +1 -1
- package/dist/components/Statistic/index.js +6 -34
- package/dist/components/Statistic/index.js.map +1 -1
- package/dist/components/Table/cell.d.ts.map +1 -1
- package/dist/components/Table/cell.js +41 -72
- package/dist/components/Table/cell.js.map +1 -1
- package/dist/components/Table/headerCell.d.ts.map +1 -1
- package/dist/components/Table/headerCell.js +5 -7
- package/dist/components/Table/headerCell.js.map +1 -1
- package/dist/components/Tag/index.d.ts +3 -70
- package/dist/components/Tag/index.d.ts.map +1 -1
- package/dist/components/Tag/index.js +67 -233
- package/dist/components/Tag/index.js.map +1 -1
- package/dist/components/Testimonial/index.d.ts.map +1 -1
- package/dist/components/Testimonial/index.js +20 -35
- package/dist/components/Testimonial/index.js.map +1 -1
- package/dist/components/Textarea/index.d.ts +0 -6
- package/dist/components/Textarea/index.d.ts.map +1 -1
- package/dist/components/Textarea/index.js +20 -20
- package/dist/components/Textarea/index.js.map +1 -1
- package/dist/components/Timeline/index.d.ts +0 -2
- package/dist/components/Timeline/index.d.ts.map +1 -1
- package/dist/components/Timeline/index.js +13 -56
- package/dist/components/Timeline/index.js.map +1 -1
- package/dist/components/Tree/index.d.ts.map +1 -1
- package/dist/components/Tree/index.js +20 -24
- package/dist/components/Tree/index.js.map +1 -1
- package/dist/containers/UIProvider.d.ts +0 -10
- package/dist/containers/UIProvider.d.ts.map +1 -1
- package/dist/containers/UIProvider.js +4 -33
- package/dist/containers/UIProvider.js.map +1 -1
- package/dist/helpers/colors.d.ts +2 -184
- package/dist/helpers/colors.d.ts.map +1 -1
- package/dist/helpers/colors.js +86 -739
- package/dist/helpers/colors.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/tests.json +1 -0
- package/vitest.config.ts +0 -10
- package/dist/context/SurfaceContext.d.ts +0 -18
- package/dist/context/SurfaceContext.d.ts.map +0 -1
- package/dist/context/SurfaceContext.js +0 -39
- package/dist/context/SurfaceContext.js.map +0 -1
- package/dist/helpers/iconProps.d.ts +0 -14
- package/dist/helpers/iconProps.d.ts.map +0 -1
- package/dist/helpers/iconProps.js +0 -33
- package/dist/helpers/iconProps.js.map +0 -1
- package/dist/helpers/surface.d.ts +0 -31
- package/dist/helpers/surface.d.ts.map +0 -1
- package/dist/helpers/surface.js +0 -87
- package/dist/helpers/surface.js.map +0 -1
- package/dist/hooks/useDrawnSurface.d.ts +0 -38
- package/dist/hooks/useDrawnSurface.d.ts.map +0 -1
- package/dist/hooks/useDrawnSurface.js +0 -48
- package/dist/hooks/useDrawnSurface.js.map +0 -1
package/dist/helpers/colors.js
CHANGED
|
@@ -1,84 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
-
if (ar || !(i in from)) {
|
|
16
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
-
ar[i] = from[i];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
3
|
+
exports.getGradientMix = exports.getNthGradientColor = exports.buildGradientColorsFromString = exports.createEffectGradient = exports.getColorFromMaybeString = exports.getMainBackgroundColor = exports.getNotificationIntent = exports.mergeThemes = exports.buildTheme = exports.isValidSixCharHex = exports.getColorByBgColor = exports.getReadableAccentColor = exports.getOpaqueColor = exports.changeDarkness = exports.changeLightness = exports.getMainColor = exports.shouldDarken = exports.RGBAToHexA = exports.hexAToRGBA = exports.getRGBAFromHex = exports.percentToHexAlpha = exports.isAchromatic = exports.getReadableColorFrom = exports.getReadableColor = void 0;
|
|
24
4
|
var lodash_1 = require("lodash");
|
|
25
5
|
var polished_1 = require("polished");
|
|
26
6
|
var colors_1 = require("../constants/colors");
|
|
27
7
|
var theme_1 = require("../constants/theme");
|
|
28
|
-
/**
|
|
29
|
-
* How many results each cached helper keeps. The color maths runs while components render - a button works out its
|
|
30
|
-
* text, its hover and its icons from what it is drawn on, a gradient each of its colors - and a page draws the same
|
|
31
|
-
* few colors over and over (a table of 500 buttons in one theme), so each helper remembers its last results. A
|
|
32
|
-
* page that keeps meeting new colors only ever holds this many: the one used least recently goes first.
|
|
33
|
-
*/
|
|
34
|
-
var COLOR_CACHE_SIZE = 2000;
|
|
35
|
-
/**
|
|
36
|
-
* A helper's memory of its results (see `COLOR_CACHE_SIZE`): `remember(key, compute)`. Also for a component's
|
|
37
|
-
* color work that is a function of its key alone (an effect's gradient pass): not part of the package's API.
|
|
38
|
-
*/
|
|
39
|
-
var createColorCache = function () {
|
|
40
|
-
var results = new Map();
|
|
41
|
-
return function (key, compute) {
|
|
42
|
-
if (results.has(key)) {
|
|
43
|
-
var result_1 = results.get(key);
|
|
44
|
-
// the most recently used goes to the end, so the oldest is the first one out
|
|
45
|
-
results.delete(key);
|
|
46
|
-
results.set(key, result_1);
|
|
47
|
-
return result_1;
|
|
48
|
-
}
|
|
49
|
-
var result = compute();
|
|
50
|
-
results.set(key, result);
|
|
51
|
-
if (results.size > COLOR_CACHE_SIZE) {
|
|
52
|
-
results.delete(results.keys().next().value);
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
exports.createColorCache = createColorCache;
|
|
58
|
-
/** One key for any list of a helper's arguments (colors, numbers, flags, lists of colors). */
|
|
59
|
-
var cacheKey = function () {
|
|
60
|
-
var parts = [];
|
|
61
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
62
|
-
parts[_i] = arguments[_i];
|
|
63
|
-
}
|
|
64
|
-
return parts.map(function (part) { return (Array.isArray(part) ? part.join(',') : String(part)); }).join('|');
|
|
65
|
-
};
|
|
66
|
-
exports.cacheKey = cacheKey;
|
|
67
|
-
var intentKeys = new WeakMap();
|
|
68
|
-
/**
|
|
69
|
-
* What of a theme the helpers that take one read: its main, the main it was made from, and its intents. The
|
|
70
|
-
* intents are written out once per intents object.
|
|
71
|
-
*/
|
|
72
|
-
var getThemeColorKey = function (theme) {
|
|
73
|
-
var intents = theme.intents;
|
|
74
|
-
var key = intents ? intentKeys.get(intents) : '';
|
|
75
|
-
if (key === undefined) {
|
|
76
|
-
key = JSON.stringify(intents);
|
|
77
|
-
intentKeys.set(intents, key);
|
|
78
|
-
}
|
|
79
|
-
return "".concat(theme.main, "|").concat(theme.originalMain, "|").concat(key);
|
|
80
|
-
};
|
|
81
|
-
exports.getThemeColorKey = getThemeColorKey;
|
|
82
8
|
var getReadableColor = function (theme, ifLight, ifDark, dimmed, fallback) {
|
|
83
9
|
var _a, _b;
|
|
84
10
|
if ((_a = theme.text) === null || _a === void 0 ? void 0 : _a.color) {
|
|
@@ -90,338 +16,16 @@ var getReadableColor = function (theme, ifLight, ifDark, dimmed, fallback) {
|
|
|
90
16
|
}
|
|
91
17
|
var shouldDim = ((_b = theme.text) === null || _b === void 0 ? void 0 : _b.dim) && dimmed;
|
|
92
18
|
var from = fallback || theme.main;
|
|
93
|
-
|
|
94
|
-
return (0, exports.getReadableColorFrom)(from, shouldDim, ifLight, ifDark, theme.originalMain);
|
|
19
|
+
return (0, exports.getReadableColorFrom)(from, shouldDim, ifLight, ifDark);
|
|
95
20
|
};
|
|
96
21
|
exports.getReadableColor = getReadableColor;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
* How far an icon (or any other graphic a control needs to be understood) and large text have to stand out from
|
|
103
|
-
* what they are drawn on (WCAG 2.1 AA, 1.4.11 and 1.4.3): 3:1.
|
|
104
|
-
*/
|
|
105
|
-
exports.READABLE_ICON_CONTRAST = 3;
|
|
106
|
-
/** The least size (px) from which bold text is large in WCAG's sense (14pt), and needs to stand out by 3:1 only. */
|
|
107
|
-
exports.LARGE_BOLD_TEXT_PX = 18.66;
|
|
108
|
-
var rememberParts = (0, exports.createColorCache)();
|
|
109
|
-
/**
|
|
110
|
-
* The red, green, blue and alpha of a color - any a browser and polished both read: a hex of 3, 4, 6 or 8 digits,
|
|
111
|
-
* `rgb()`, `rgba()`, `hsl()`, a named color. Undefined for one they do not (a CSS variable, `currentColor`, a
|
|
112
|
-
* typo), which is the caller's to draw as it is: the helpers below leave such a color alone instead of throwing
|
|
113
|
-
* while a component renders. `'transparent'` is black at no alpha: it draws nothing.
|
|
114
|
-
*/
|
|
115
|
-
var parseColor = function (color) {
|
|
116
|
-
if (typeof color !== 'string' || !color) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
return rememberParts(color, function () {
|
|
120
|
-
var _a;
|
|
121
|
-
if (color === 'transparent') {
|
|
122
|
-
return { red: 0, green: 0, blue: 0, alpha: 0 };
|
|
123
|
-
}
|
|
124
|
-
try {
|
|
125
|
-
var parsed = (0, polished_1.parseToRgb)(color);
|
|
126
|
-
return {
|
|
127
|
-
red: parsed.red,
|
|
128
|
-
green: parsed.green,
|
|
129
|
-
blue: parsed.blue,
|
|
130
|
-
alpha: (_a = parsed.alpha) !== null && _a !== void 0 ? _a : 1,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
catch (_b) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
/** Whether the helpers can read `color` (see `parseColor`). */
|
|
139
|
-
var isReadableColor = function (color) { return !!parseColor(color); };
|
|
140
|
-
exports.isReadableColor = isReadableColor;
|
|
141
|
-
/** Whether `color` is a color drawn opaque, which text can be read on. */
|
|
142
|
-
var isOpaque = function (color) { var _a; return ((_a = parseColor(color)) === null || _a === void 0 ? void 0 : _a.alpha) === 1; };
|
|
143
|
-
var toHexColor = function (_a) {
|
|
144
|
-
var red = _a.red, green = _a.green, blue = _a.blue;
|
|
145
|
-
return "#".concat([red, green, blue]
|
|
146
|
-
.map(function (part) {
|
|
147
|
-
return Math.round(Math.min(255, Math.max(0, part)))
|
|
148
|
-
.toString(16)
|
|
149
|
-
.padStart(2, '0');
|
|
150
|
-
})
|
|
151
|
-
.join(''));
|
|
152
|
-
};
|
|
153
|
-
var rememberAlphaColor = (0, exports.createColorCache)();
|
|
154
|
-
/**
|
|
155
|
-
* `color` at `alpha`, as polished's `rgba(color, alpha)` writes it. A color it cannot read (a CSS variable,
|
|
156
|
-
* `currentColor`) is drawn as given, not thrown on: at an alpha below 1, mixed with nothing by the browser
|
|
157
|
-
* (`color-mix(in srgb, var(--brand) 20%, transparent)`), so a wash of it is still a wash and not the solid color
|
|
158
|
-
* the text on it is written in.
|
|
159
|
-
*/
|
|
160
|
-
var getColorAtAlpha = function (color, alpha) {
|
|
161
|
-
if (typeof color !== 'string' || !color) {
|
|
162
|
-
return color;
|
|
163
|
-
}
|
|
164
|
-
return rememberAlphaColor((0, exports.cacheKey)(color, alpha), function () {
|
|
165
|
-
if (parseColor(color)) {
|
|
166
|
-
return (0, polished_1.rgba)(color, alpha);
|
|
167
|
-
}
|
|
168
|
-
return alpha >= 1
|
|
169
|
-
? color
|
|
170
|
-
: "color-mix(in srgb, ".concat(color, " ").concat(Math.round(Math.max(0, alpha) * 1000) / 10, "%, transparent)");
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
exports.getColorAtAlpha = getColorAtAlpha;
|
|
174
|
-
var rememberTint = (0, exports.createColorCache)();
|
|
175
|
-
/**
|
|
176
|
-
* `color` tinted toward white by `amount` and fully saturated: the light shade of it an outlined control (a minimal
|
|
177
|
-
* button, a minimal tag) starts its text from, before it is made to read (`getReadableAccentColorOn`). A translucent
|
|
178
|
-
* color is its own hue drawn opaque; one it cannot read is as it is.
|
|
179
|
-
*/
|
|
180
|
-
var getSaturatedTint = function (color, amount) {
|
|
181
|
-
var drawn = (0, exports.getDrawnColor)(color);
|
|
182
|
-
if (!isOpaque(drawn)) {
|
|
183
|
-
return drawn;
|
|
184
|
-
}
|
|
185
|
-
return rememberTint((0, exports.cacheKey)(drawn, amount), function () {
|
|
186
|
-
return (0, exports.getOpaqueColor)((0, polished_1.saturate)(1, (0, polished_1.tint)(amount, drawn)));
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
exports.getSaturatedTint = getSaturatedTint;
|
|
190
|
-
var rememberDrawn = (0, exports.createColorCache)();
|
|
191
|
-
/**
|
|
192
|
-
* `color` as it is drawn over `under`: a translucent color blended into what is under it, the way the browser
|
|
193
|
-
* draws it, and an opaque one as it is. Without `under` (or over one it cannot read), a translucent color counts as
|
|
194
|
-
* its own hue drawn opaque. An opaque six-digit hex - except for a color that draws nothing there
|
|
195
|
-
* (`'transparent'` with nothing under it) or one it cannot read (a CSS variable), which comes back as it is given.
|
|
196
|
-
*/
|
|
197
|
-
var getDrawnColor = function (color, under) {
|
|
198
|
-
return rememberDrawn((0, exports.cacheKey)(color, under), function () {
|
|
199
|
-
var top = parseColor(color);
|
|
200
|
-
if (!top) {
|
|
201
|
-
return color;
|
|
202
|
-
}
|
|
203
|
-
var bottom = top.alpha < 1 && under ? parseColor((0, exports.getDrawnColor)(under)) : undefined;
|
|
204
|
-
if (!bottom || bottom.alpha < 1) {
|
|
205
|
-
// nothing under it that can be read: its own hue, if it draws anything at all
|
|
206
|
-
return top.alpha > 0 ? toHexColor(top) : color;
|
|
207
|
-
}
|
|
208
|
-
var blend = function (above, below) { return above * top.alpha + below * (1 - top.alpha); };
|
|
209
|
-
return toHexColor({
|
|
210
|
-
red: blend(top.red, bottom.red),
|
|
211
|
-
green: blend(top.green, bottom.green),
|
|
212
|
-
blue: blend(top.blue, bottom.blue),
|
|
213
|
-
alpha: 1,
|
|
214
|
-
});
|
|
215
|
-
});
|
|
22
|
+
var getReadableColorFrom = function (from, dim, ifLight, ifDark) {
|
|
23
|
+
var returnIfLight = ifLight || (0, polished_1.lighten)(dim ? 0.05 : 0, colors_1.Colors.DARK);
|
|
24
|
+
var returnIfDark = ifDark || (0, polished_1.darken)(dim ? 0.05 : 0, colors_1.Colors.LIGHT);
|
|
25
|
+
var fixedColor = (0, exports.hexAToRGBA)(from);
|
|
26
|
+
return (0, polished_1.readableColor)(fixedColor, returnIfLight, returnIfDark, false);
|
|
216
27
|
};
|
|
217
|
-
exports.getDrawnColor = getDrawnColor;
|
|
218
|
-
/**
|
|
219
|
-
* `color` at `opacity` of the alpha it already has: a translucent color (a theme made from the muted intent) drawn
|
|
220
|
-
* at a panel's opacity stays as translucent, and more. `rgba(color, opacity)` replaced its alpha, so a panel in the
|
|
221
|
-
* muted intent's near-white drawn at 19% was drawn near-white and opaque. A color it cannot read is as it is.
|
|
222
|
-
*/
|
|
223
|
-
var fadeColor = function (color, opacity) {
|
|
224
|
-
var parts = parseColor(color);
|
|
225
|
-
if (!parts) {
|
|
226
|
-
return color;
|
|
227
|
-
}
|
|
228
|
-
return (0, polished_1.rgba)(parts.red, parts.green, parts.blue, parts.alpha * opacity);
|
|
229
|
-
};
|
|
230
|
-
exports.fadeColor = fadeColor;
|
|
231
|
-
/**
|
|
232
|
-
* The WCAG relative luminance of an opaque color, not rounded: polished's `getLuminance` rounds to three decimals,
|
|
233
|
-
* which moves a ratio near a threshold across it (`#595959` on black is 2.998:1, not 3).
|
|
234
|
-
*/
|
|
235
|
-
var getRelativeLuminance = function (_a) {
|
|
236
|
-
var red = _a.red, green = _a.green, blue = _a.blue;
|
|
237
|
-
var linear = function (channel) {
|
|
238
|
-
var value = channel / 255;
|
|
239
|
-
return value <= 0.03928 ? value / 12.92 : Math.pow(((value + 0.055) / 1.055), 2.4);
|
|
240
|
-
};
|
|
241
|
-
return 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue);
|
|
242
|
-
};
|
|
243
|
-
var rememberContrast = (0, exports.createColorCache)();
|
|
244
|
-
/**
|
|
245
|
-
* The WCAG contrast ratio of two colors, each drawn opaque: from 1 to 21, not rounded. NaN when either cannot be
|
|
246
|
-
* read or draws nothing (a CSS variable, `'transparent'`): there is no telling how far it stands out.
|
|
247
|
-
*/
|
|
248
|
-
var getContrastRatio = function (first, second) {
|
|
249
|
-
return rememberContrast((0, exports.cacheKey)(first, second), function () {
|
|
250
|
-
var one = parseColor((0, exports.getDrawnColor)(first));
|
|
251
|
-
var other = parseColor((0, exports.getDrawnColor)(second));
|
|
252
|
-
if (!one || !other || one.alpha < 1 || other.alpha < 1) {
|
|
253
|
-
return NaN;
|
|
254
|
-
}
|
|
255
|
-
var _a = [getRelativeLuminance(one), getRelativeLuminance(other)].sort(function (a, b) { return b - a; }), lighter = _a[0], darker = _a[1];
|
|
256
|
-
return (lighter + 0.05) / (darker + 0.05);
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
exports.getContrastRatio = getContrastRatio;
|
|
260
|
-
/** The worst contrast `color` has with any of `backgrounds`. */
|
|
261
|
-
var getWorstContrast = function (color, backgrounds) {
|
|
262
|
-
return Math.min.apply(Math, backgrounds.map(function (background) { return (0, exports.getContrastRatio)(color, background); }));
|
|
263
|
-
};
|
|
264
|
-
/** Of `colors`, as each is drawn over `under`, those text can be read on: opaque, and colors the helpers read. */
|
|
265
|
-
var getReadableSurfaces = function (colors, under) {
|
|
266
|
-
return colors.map(function (color) { return (0, exports.getDrawnColor)(color, under); }).filter(function (color) { return isOpaque(color); });
|
|
267
|
-
};
|
|
268
|
-
// the theme's text colors, a shade softer (`dim`)
|
|
269
|
-
var DIM_ON_LIGHT = (0, polished_1.lighten)(0.05, colors_1.Colors.DARK);
|
|
270
|
-
var DIM_ON_DARK = (0, polished_1.darken)(0.05, colors_1.Colors.LIGHT);
|
|
271
|
-
var rememberReadableOn = (0, exports.createColorCache)();
|
|
272
|
-
/**
|
|
273
|
-
* The text color that reads on every one of `backgrounds` (each drawn over `under` when it is translucent - the
|
|
274
|
-
* colors of a gradient, or a single surface): of the text colors for a light and for a dark background (`ifLight`,
|
|
275
|
-
* `ifDark`; black and white, a shade softer when `dim`), the one that stands out more. When even that one does not
|
|
276
|
-
* reach 4.5:1, a color the caller gave stays theirs (the better of their pair); the default shades give way to pure
|
|
277
|
-
* black or white, whichever stands out more: a dimmed shade is a nicety, being read is not. A background it cannot
|
|
278
|
-
* read is left out; with none left, the text for a dark background (Reqore's default theme).
|
|
279
|
-
*/
|
|
280
|
-
var getReadableColorOn = function (backgrounds, dim, ifLight, ifDark, under) {
|
|
281
|
-
return rememberReadableOn((0, exports.cacheKey)(backgrounds, dim, ifLight, ifDark, under), function () {
|
|
282
|
-
var surfaces = getReadableSurfaces(backgrounds, under);
|
|
283
|
-
var onLight = ifLight || (dim ? DIM_ON_LIGHT : colors_1.Colors.DARK);
|
|
284
|
-
var onDark = ifDark || (dim ? DIM_ON_DARK : colors_1.Colors.LIGHT);
|
|
285
|
-
if (!surfaces.length) {
|
|
286
|
-
return onDark;
|
|
287
|
-
}
|
|
288
|
-
var preferred = getWorstContrast(onLight, surfaces) >= getWorstContrast(onDark, surfaces) ? onLight : onDark;
|
|
289
|
-
if (getWorstContrast(preferred, surfaces) >= exports.READABLE_TEXT_CONTRAST ||
|
|
290
|
-
(preferred === onLight ? !!ifLight : !!ifDark)) {
|
|
291
|
-
return preferred;
|
|
292
|
-
}
|
|
293
|
-
return getWorstContrast(colors_1.Colors.DARK, surfaces) >= getWorstContrast(colors_1.Colors.LIGHT, surfaces)
|
|
294
|
-
? colors_1.Colors.DARK
|
|
295
|
-
: colors_1.Colors.LIGHT;
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
exports.getReadableColorOn = getReadableColorOn;
|
|
299
|
-
/** The contrast of `color` (its red, green and blue), drawn at `alpha` over the opaque `background`, with it. */
|
|
300
|
-
var getContrastAtAlpha = function (_a, background, alpha) {
|
|
301
|
-
var red = _a.red, green = _a.green, blue = _a.blue;
|
|
302
|
-
return (0, exports.getContrastRatio)((0, exports.getDrawnColor)((0, polished_1.rgba)(red, green, blue, alpha), background), background);
|
|
303
|
-
};
|
|
304
|
-
/** How far past the ratio `getReadableAlpha` aims: see there. */
|
|
305
|
-
var READABLE_ALPHA_MARGIN = 0.1;
|
|
306
|
-
/**
|
|
307
|
-
* The least alpha (or opacity), from `alpha` up, at which `color` drawn over `background` (each of them, for a list)
|
|
308
|
-
* still stands out from it by `minContrast`: secondary text or an icon fades only as far as it can and still be read.
|
|
309
|
-
* `alpha` itself when it already reads; 1 when even the full color does not, which is for whoever chose that color to
|
|
310
|
-
* fix. A color or a background it cannot read (none given, a CSS variable) leaves `alpha` as it is: there is no
|
|
311
|
-
* telling how far it stands out.
|
|
312
|
-
*/
|
|
313
|
-
var getReadableAlpha = function (color, background, alpha, minContrast) {
|
|
314
|
-
if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
|
|
315
|
-
return Math.max.apply(Math, __spreadArray([alpha], (Array.isArray(background) ? background : [background]).map(function (each) {
|
|
316
|
-
return getReadableAlphaOn(color, each, alpha, minContrast);
|
|
317
|
-
}), false));
|
|
318
|
-
};
|
|
319
|
-
exports.getReadableAlpha = getReadableAlpha;
|
|
320
|
-
/**
|
|
321
|
-
* The least alpha from `from` up to 1 at which `reads` holds, to a hundredth, rounded up: `reads` holds at 1 and not
|
|
322
|
-
* at `from`. The range in which it starts to hold is halved until it is less than half a hundredth wide.
|
|
323
|
-
*/
|
|
324
|
-
var leastReadingAlpha = function (from, reads) {
|
|
325
|
-
var low = from;
|
|
326
|
-
var high = 1;
|
|
327
|
-
while (high - low > 0.005) {
|
|
328
|
-
var middle = (low + high) / 2;
|
|
329
|
-
if (reads(middle)) {
|
|
330
|
-
high = middle;
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
low = middle;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return Math.min(1, Math.ceil(high * 100) / 100);
|
|
337
|
-
};
|
|
338
|
-
var rememberAlpha = (0, exports.createColorCache)();
|
|
339
|
-
var getReadableAlphaOn = function (color, background, alpha, ratio) {
|
|
340
|
-
return rememberAlpha((0, exports.cacheKey)(color, background, alpha, ratio), function () {
|
|
341
|
-
var parts = parseColor(color);
|
|
342
|
-
var surface = (0, exports.getDrawnColor)(background);
|
|
343
|
-
if (alpha >= 1 || !parts || !isOpaque(surface)) {
|
|
344
|
-
return alpha;
|
|
345
|
-
}
|
|
346
|
-
// A browser blends a translucent color a shade differently (an alpha of 255ths, its own rounding): an alpha
|
|
347
|
-
// that just reaches the ratio here can fall a hair short on the page, so it aims a little past it.
|
|
348
|
-
var minContrast = ratio + READABLE_ALPHA_MARGIN;
|
|
349
|
-
if (getContrastAtAlpha(parts, surface, alpha) >= minContrast) {
|
|
350
|
-
return alpha;
|
|
351
|
-
}
|
|
352
|
-
if (getContrastAtAlpha(parts, surface, 1) < minContrast) {
|
|
353
|
-
return 1;
|
|
354
|
-
}
|
|
355
|
-
return leastReadingAlpha(alpha, function (at) { return getContrastAtAlpha(parts, surface, at) >= minContrast; });
|
|
356
|
-
});
|
|
357
|
-
};
|
|
358
|
-
/**
|
|
359
|
-
* How far a group drawn as a whole (`opacity` on it: an idle rail resting dim) can be faded over `under` and every
|
|
360
|
-
* one of `marks` in it still stand out from what it is drawn on by `minContrast`: `opacity`, or as little more as
|
|
361
|
-
* it takes. Faded, a mark and what it is on both fade into `under`, so they draw closer together.
|
|
362
|
-
*/
|
|
363
|
-
var getReadableGroupOpacity = function (marks, under, opacity, minContrast) {
|
|
364
|
-
if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
|
|
365
|
-
var page = (0, exports.getDrawnColor)(under);
|
|
366
|
-
// aims a little past the ratio, as getReadableAlpha does: the browser blends a shade differently
|
|
367
|
-
var target = minContrast + READABLE_ALPHA_MARGIN;
|
|
368
|
-
// a mark, or what it is on, that cannot be read (a CSS variable) cannot be measured: it is left out
|
|
369
|
-
var drawn = marks
|
|
370
|
-
.map(function (_a) {
|
|
371
|
-
var color = _a.color, alpha = _a.alpha, on = _a.on;
|
|
372
|
-
var fill = (0, exports.getDrawnColor)(on);
|
|
373
|
-
return { fill: fill, mark: (0, exports.getDrawnColor)((0, exports.fadeColor)(color, alpha), fill) };
|
|
374
|
-
})
|
|
375
|
-
.filter(function (_a) {
|
|
376
|
-
var fill = _a.fill, mark = _a.mark;
|
|
377
|
-
return isOpaque(fill) && isOpaque(mark);
|
|
378
|
-
});
|
|
379
|
-
if (!isOpaque(page) || !drawn.length) {
|
|
380
|
-
return opacity;
|
|
381
|
-
}
|
|
382
|
-
var reads = function (at) {
|
|
383
|
-
return drawn.every(function (_a) {
|
|
384
|
-
var fill = _a.fill, mark = _a.mark;
|
|
385
|
-
return (0, exports.getContrastRatio)((0, exports.getDrawnColor)((0, polished_1.rgba)(mark, at), page), (0, exports.getDrawnColor)((0, polished_1.rgba)(fill, at), page)) >=
|
|
386
|
-
target;
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
|
-
if (opacity >= 1 || reads(opacity)) {
|
|
390
|
-
return opacity;
|
|
391
|
-
}
|
|
392
|
-
if (!reads(1)) {
|
|
393
|
-
return 1;
|
|
394
|
-
}
|
|
395
|
-
return leastReadingAlpha(opacity, reads);
|
|
396
|
-
};
|
|
397
|
-
exports.getReadableGroupOpacity = getReadableGroupOpacity;
|
|
398
|
-
/** `color` at `alpha`, or at as much more as it needs to stand out from `background` (`getReadableAlpha`). */
|
|
399
|
-
var getReadableFadedColor = function (color, background, alpha, minContrast) {
|
|
400
|
-
if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
|
|
401
|
-
return isOpaque((0, exports.getDrawnColor)(color))
|
|
402
|
-
? (0, polished_1.rgba)((0, exports.getDrawnColor)(color), (0, exports.getReadableAlpha)(color, background, alpha, minContrast))
|
|
403
|
-
: color;
|
|
404
|
-
};
|
|
405
|
-
exports.getReadableFadedColor = getReadableFadedColor;
|
|
406
|
-
/**
|
|
407
|
-
* A theme's text color on every one of `backgrounds` (what a component is drawn in - each color of its gradient):
|
|
408
|
-
* the theme's own text color when it names one, else the one that reads on all of them (`getReadableColorOn`),
|
|
409
|
-
* dimmed when the theme dims its text.
|
|
410
|
-
*/
|
|
411
|
-
var getReadableTextOn = function (theme, backgrounds, dimmed) {
|
|
412
|
-
var _a, _b;
|
|
413
|
-
if (dimmed === void 0) { dimmed = true; }
|
|
414
|
-
return ((_a = theme.text) === null || _a === void 0 ? void 0 : _a.color)
|
|
415
|
-
? (0, exports.getReadableColor)(theme, undefined, undefined, dimmed)
|
|
416
|
-
: (0, exports.getReadableColorOn)(backgrounds, !!((_b = theme.text) === null || _b === void 0 ? void 0 : _b.dim) && dimmed);
|
|
417
|
-
};
|
|
418
|
-
exports.getReadableTextOn = getReadableTextOn;
|
|
419
|
-
/**
|
|
420
|
-
* The text color that reads on `from` (drawn over `under` when it is translucent): see `getReadableColorOn`.
|
|
421
|
-
*/
|
|
422
|
-
var getReadableColorFrom = function (from, dim, ifLight, ifDark, under) { return (0, exports.getReadableColorOn)([from], dim, ifLight, ifDark, under); };
|
|
423
28
|
exports.getReadableColorFrom = getReadableColorFrom;
|
|
424
|
-
/** Whether `color` is a gray (black and white included); false for one it cannot read. */
|
|
425
29
|
var isAchromatic = function (color) {
|
|
426
30
|
var fixedColor = (0, exports.getRGBAFromHex)(color);
|
|
427
31
|
return fixedColor.r === fixedColor.g && fixedColor.g === fixedColor.b;
|
|
@@ -434,59 +38,31 @@ var percentToHexAlpha = function (p) {
|
|
|
434
38
|
return hexValue.padStart(2, '0').toUpperCase(); // format with leading 0 and upper case characters
|
|
435
39
|
};
|
|
436
40
|
exports.percentToHexAlpha = percentToHexAlpha;
|
|
437
|
-
/** A hex color of 3, 4, 6 or 8 digits: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`. */
|
|
438
|
-
var HEX_COLOR = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
439
|
-
/**
|
|
440
|
-
* A hex color in its long form, as CSS reads a short one - each digit doubled: `#fdc` is `#ffddcc`, `#f00a` is
|
|
441
|
-
* `#ff0000aa`. A long one, or anything that is not a hex color, as it is.
|
|
442
|
-
*/
|
|
443
|
-
var expandHexColor = function (color) {
|
|
444
|
-
return HEX_COLOR.test(color) && color.length <= 5
|
|
445
|
-
? "#".concat(Array.from(color.slice(1), function (digit) { return digit + digit; }).join(''))
|
|
446
|
-
: color;
|
|
447
|
-
};
|
|
448
|
-
var NO_RGBA = { r: NaN, g: NaN, b: NaN, a: NaN };
|
|
449
|
-
/**
|
|
450
|
-
* The red, green, blue (0-255) and alpha (0-1) of a color: a hex of 3, 4, 6 or 8 digits, `rgb()`/`rgba()`, or any
|
|
451
|
-
* other color polished reads (`hsl()`, a named one). NaN in each for one it cannot read (a CSS variable).
|
|
452
|
-
*
|
|
453
|
-
* A short hex is each of its digits doubled (`#fdc` is `#ffddcc`). It was repeated (`#fdcfdc`, another hue), and
|
|
454
|
-
* polished writes the colors it works out short wherever it can, so a readable shade made from one of them took
|
|
455
|
-
* the wrong hue: a minimal button in `#ff5500` had lilac text instead of peach.
|
|
456
|
-
*/
|
|
457
41
|
var getRGBAFromHex = function (color) {
|
|
458
|
-
|
|
459
|
-
return NO_RGBA;
|
|
460
|
-
}
|
|
42
|
+
var hexColor = color;
|
|
461
43
|
// If this is already an rgba color, we need to convert it to hex
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
var parts = parseColor(color);
|
|
465
|
-
return parts ? { r: parts.red, g: parts.green, b: parts.blue, a: parts.alpha } : NO_RGBA;
|
|
44
|
+
if (color.startsWith('rgba')) {
|
|
45
|
+
hexColor = (0, exports.RGBAToHexA)(color);
|
|
466
46
|
}
|
|
467
|
-
var
|
|
468
|
-
var
|
|
469
|
-
var
|
|
470
|
-
var
|
|
47
|
+
var colorWithAlpha = hexColor.length === 4 ? hexColor + hexColor.slice(1, 4) : hexColor;
|
|
48
|
+
var r = parseInt(colorWithAlpha.slice(1, 3), 16);
|
|
49
|
+
var g = parseInt(colorWithAlpha.slice(3, 5), 16);
|
|
50
|
+
var b = parseInt(colorWithAlpha.slice(5, 7), 16);
|
|
51
|
+
var a = parseInt(colorWithAlpha.slice(7, 9) || 'ff', 16) / 255;
|
|
471
52
|
return { r: r, g: g, b: b, a: a };
|
|
472
53
|
};
|
|
473
54
|
exports.getRGBAFromHex = getRGBAFromHex;
|
|
474
|
-
/** `hex` as `rgba(r, g, b, a)`; an `rgb()`/`rgba()` color, and one it cannot read, as it is. */
|
|
475
55
|
var hexAToRGBA = function (hex) {
|
|
476
56
|
// Check if this color is already in rgba format
|
|
477
|
-
if (
|
|
57
|
+
if (hex.startsWith('rgb')) {
|
|
478
58
|
return hex;
|
|
479
59
|
}
|
|
480
60
|
var _a = (0, exports.getRGBAFromHex)(hex), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
|
|
481
|
-
if (Number.isNaN(r)) {
|
|
482
|
-
return hex;
|
|
483
|
-
}
|
|
484
61
|
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a.toFixed(2), ")");
|
|
485
62
|
};
|
|
486
63
|
exports.hexAToRGBA = hexAToRGBA;
|
|
487
64
|
var RGBAToHexA = function (rgba, forceRemoveAlpha) {
|
|
488
65
|
if (forceRemoveAlpha === void 0) { forceRemoveAlpha = false; }
|
|
489
|
-
// a hex already, of any length (`#f00a` too, which the parse below would write as `#NaN`)
|
|
490
66
|
if ((0, exports.isValidSixCharHex)(rgba)) {
|
|
491
67
|
return rgba;
|
|
492
68
|
}
|
|
@@ -502,50 +78,41 @@ var RGBAToHexA = function (rgba, forceRemoveAlpha) {
|
|
|
502
78
|
.join('')); // Puts the array to togehter to a string
|
|
503
79
|
};
|
|
504
80
|
exports.RGBAToHexA = RGBAToHexA;
|
|
505
|
-
/** Whether `mainColor` is light (a lighter shade of it is made darker); false for one it cannot read. */
|
|
506
81
|
var shouldDarken = function (mainColor) {
|
|
507
|
-
return (0,
|
|
82
|
+
return (0, polished_1.getLuminance)((0, exports.hexAToRGBA)(mainColor)) > 0.2;
|
|
508
83
|
};
|
|
509
84
|
exports.shouldDarken = shouldDarken;
|
|
510
85
|
var getMainColor = function (theme, component) { var _a; return ((_a = theme[component]) === null || _a === void 0 ? void 0 : _a.main) || theme.main; };
|
|
511
86
|
exports.getMainColor = getMainColor;
|
|
512
87
|
//export const changeBasedOnContrast = (color: string, lightness?: number): string =>
|
|
513
|
-
var rememberLightness = (0, exports.createColorCache)();
|
|
514
|
-
/**
|
|
515
|
-
* `color` moved by `lightness` away from what it is (`towardContrast`: a light color darker, a dark one lighter)
|
|
516
|
-
* or toward it. A color it cannot read is as it is.
|
|
517
|
-
*/
|
|
518
|
-
var shiftLightness = function (color, lightness, towardContrast) {
|
|
519
|
-
if (!lightness || !(0, exports.isReadableColor)(color)) {
|
|
520
|
-
return color;
|
|
521
|
-
}
|
|
522
|
-
return rememberLightness((0, exports.cacheKey)(color, lightness, towardContrast), function () {
|
|
523
|
-
var fixedColor = (0, exports.hexAToRGBA)(color);
|
|
524
|
-
return ((0, exports.shouldDarken)(fixedColor) === towardContrast
|
|
525
|
-
? (0, polished_1.darken)(lightness, fixedColor)
|
|
526
|
-
: (0, polished_1.lighten)(lightness, fixedColor));
|
|
527
|
-
});
|
|
528
|
-
};
|
|
529
88
|
var changeLightness = function (color, lightness) {
|
|
530
|
-
|
|
89
|
+
var fixedColor = (0, exports.hexAToRGBA)(color);
|
|
90
|
+
return lightness
|
|
91
|
+
? (0, exports.shouldDarken)(fixedColor)
|
|
92
|
+
? (0, polished_1.darken)(lightness, fixedColor)
|
|
93
|
+
: (0, polished_1.lighten)(lightness, fixedColor)
|
|
94
|
+
: color;
|
|
531
95
|
};
|
|
532
96
|
exports.changeLightness = changeLightness;
|
|
533
97
|
var changeDarkness = function (color, lightness) {
|
|
534
|
-
|
|
98
|
+
var fixedColor = (0, exports.hexAToRGBA)(color);
|
|
99
|
+
return lightness
|
|
100
|
+
? (0, exports.shouldDarken)(fixedColor)
|
|
101
|
+
? (0, polished_1.lighten)(lightness, fixedColor)
|
|
102
|
+
: (0, polished_1.darken)(lightness, fixedColor)
|
|
103
|
+
: color;
|
|
535
104
|
};
|
|
536
105
|
exports.changeDarkness = changeDarkness;
|
|
537
106
|
/**
|
|
538
107
|
* The colour without its alpha channel, as a six-digit hex: `#e6e6e630` → `#e6e6e6`,
|
|
539
108
|
* `rgba(10, 102, 64, 0.5)` → `#0a6640`. For colour maths that needs the hue a colour
|
|
540
109
|
* is drawn in rather than how faintly it is drawn (Reqore's muted intent, for one, is
|
|
541
|
-
* an eight-digit hex).
|
|
110
|
+
* an eight-digit hex).
|
|
542
111
|
*/
|
|
543
112
|
var getOpaqueColor = function (color) {
|
|
544
113
|
var _a = (0, exports.getRGBAFromHex)(color), r = _a.r, g = _a.g, b = _a.b;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
return toHexColor({ red: r, green: g, blue: b, alpha: 1 });
|
|
114
|
+
var toHex = function (value) { return value.toString(16).padStart(2, '0'); };
|
|
115
|
+
return "#".concat(toHex(r)).concat(toHex(g)).concat(toHex(b));
|
|
549
116
|
};
|
|
550
117
|
exports.getOpaqueColor = getOpaqueColor;
|
|
551
118
|
/**
|
|
@@ -559,140 +126,26 @@ exports.getOpaqueColor = getOpaqueColor;
|
|
|
559
126
|
* ends at white or black, which always can.
|
|
560
127
|
*/
|
|
561
128
|
var getReadableAccentColor = function (color, background, minContrast) {
|
|
562
|
-
if (minContrast === void 0) { minContrast =
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
* `getReadableAccentColor`): moved toward whichever of white and black stands out more from the worst of them, until
|
|
570
|
-
* it stands out from all of them - or is that white or black, when nothing does. Always a six-digit hex; a color it
|
|
571
|
-
* cannot read is as it is, and a background it cannot read is left out.
|
|
572
|
-
*/
|
|
573
|
-
var getReadableAccentColorOn = function (color, backgrounds, minContrast) {
|
|
574
|
-
if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
|
|
575
|
-
var start = (0, exports.getOpaqueColor)(color);
|
|
576
|
-
if (!isOpaque(start)) {
|
|
577
|
-
return start;
|
|
578
|
-
}
|
|
579
|
-
return rememberAccent((0, exports.cacheKey)(start, backgrounds, minContrast), function () {
|
|
580
|
-
var surfaces = backgrounds
|
|
581
|
-
.map(function (background) { return (0, exports.getOpaqueColor)(background); })
|
|
582
|
-
.filter(function (surface) { return isOpaque(surface); });
|
|
583
|
-
var worst = function (candidate) {
|
|
584
|
-
return Math.min.apply(Math, surfaces.map(function (surface) { return (0, exports.getContrastRatio)(candidate, surface); }));
|
|
585
|
-
};
|
|
586
|
-
var lighter = worst(colors_1.Colors.LIGHT) >= worst(colors_1.Colors.DARK);
|
|
587
|
-
var accent = start;
|
|
588
|
-
// 25 steps of 4% lightness cover the whole range, so the loop always ends.
|
|
589
|
-
for (var step = 0; step < 25 && surfaces.length && worst(accent) < minContrast; step++) {
|
|
590
|
-
accent = (lighter ? (0, polished_1.lighten)(0.04, accent) : (0, polished_1.darken)(0.04, accent));
|
|
591
|
-
}
|
|
592
|
-
// polished writes a color short where it can (`#fff`): the long form, for whoever adds an alpha to it
|
|
593
|
-
return (0, exports.getOpaqueColor)(accent);
|
|
594
|
-
});
|
|
595
|
-
};
|
|
596
|
-
exports.getReadableAccentColorOn = getReadableAccentColorOn;
|
|
597
|
-
/**
|
|
598
|
-
* How a control draws an icon on `backgrounds` (what it is drawn on: one color, or each it may be) beside its `text`:
|
|
599
|
-
* in its own `color` or else in the text color it inherits; at `opacity`, or as much more as it needs to stand out
|
|
600
|
-
* by 3:1. A theme's color (an intent, the theme's main, a shade of one) is drawn in the shade of it that stands
|
|
601
|
-
* out by 3:1; any other color (an explicit hex) as it is given, as a standalone `ReqoreIcon` draws it. `color` is
|
|
602
|
-
* undefined when the icon inherits the text color.
|
|
603
|
-
*/
|
|
604
|
-
var getReadableIconLook = function (theme, backgrounds, text, opacity, color) {
|
|
605
|
-
if (opacity === void 0) { opacity = 1; }
|
|
606
|
-
var iconColor = color
|
|
607
|
-
? (0, exports.getReadableThemeColor)(theme, color, exports.READABLE_ICON_CONTRAST, undefined, backgrounds)
|
|
608
|
-
: undefined;
|
|
609
|
-
return {
|
|
610
|
-
color: iconColor,
|
|
611
|
-
opacity: (0, exports.getReadableAlpha)(iconColor !== null && iconColor !== void 0 ? iconColor : text, backgrounds, opacity, exports.READABLE_ICON_CONTRAST),
|
|
612
|
-
};
|
|
613
|
-
};
|
|
614
|
-
exports.getReadableIconLook = getReadableIconLook;
|
|
615
|
-
/**
|
|
616
|
-
* What a component is drawn on: `surface`, when a component around it has said (`useReqoreSurface`), or else the
|
|
617
|
-
* surface of the theme it was picked in - the layout's, the theme's main a step lighter (`getMainBackgroundColor`).
|
|
618
|
-
* One color: the first of a gradient's (`getThemeSurfaces` gives every one).
|
|
619
|
-
*/
|
|
620
|
-
var getThemeSurface = function (theme, surface) { return (0, exports.getThemeSurfaces)(theme, surface)[0]; };
|
|
621
|
-
exports.getThemeSurface = getThemeSurface;
|
|
622
|
-
/**
|
|
623
|
-
* Every color a component is drawn on (see `getThemeSurface`): each of a gradient's, or the one. A color that draws
|
|
624
|
-
* nothing (`'transparent'`) or that cannot be read (a CSS variable) is no surface to read on and is left out; with
|
|
625
|
-
* none left, the theme's.
|
|
626
|
-
*/
|
|
627
|
-
var getThemeSurfaces = function (theme, surface) {
|
|
628
|
-
var given = getReadableSurfaces(Array.isArray(surface) ? surface : surface ? [surface] : []);
|
|
629
|
-
return given.length
|
|
630
|
-
? given
|
|
631
|
-
: [(0, exports.getDrawnColor)((0, exports.changeLightness)(theme.originalMain || theme.main, 0.02))];
|
|
632
|
-
};
|
|
633
|
-
exports.getThemeSurfaces = getThemeSurfaces;
|
|
634
|
-
var rememberIntentColor = (0, exports.createColorCache)();
|
|
635
|
-
var rememberThemeColor = (0, exports.createColorCache)();
|
|
636
|
-
/**
|
|
637
|
-
* Text (or an icon, at `minContrast` 3) in an intent's color on what it is drawn on (`surface`, or the theme's: see
|
|
638
|
-
* `getThemeSurface`): the intent in the shade that stands out there - a warning stays orange, an orange light enough
|
|
639
|
-
* to read on a dark theme. A translucent intent (muted) is drawn over that surface first.
|
|
640
|
-
*/
|
|
641
|
-
var getReadableIntentColor = function (theme, intent, minContrast, surface) {
|
|
642
|
-
if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
|
|
643
|
-
return rememberIntentColor((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), intent, minContrast, surface), function () {
|
|
644
|
-
var unders = (0, exports.getThemeSurfaces)(theme, surface);
|
|
645
|
-
return (0, exports.getReadableAccentColorOn)((0, exports.getDrawnColor)(theme.intents[intent] || unders[0], unders[0]), unders, minContrast);
|
|
646
|
-
});
|
|
647
|
-
};
|
|
648
|
-
exports.getReadableIntentColor = getReadableIntentColor;
|
|
649
|
-
/**
|
|
650
|
-
* The color a span, a paragraph or a link writes its text in: an intent in a shade of it that reads on what the text
|
|
651
|
-
* is drawn on (`surface`, or the theme's), else the theme's text color, else what it inherits.
|
|
652
|
-
*/
|
|
653
|
-
var getReadableTextColor = function (theme, intent, surface) {
|
|
654
|
-
var _a;
|
|
655
|
-
return intent
|
|
656
|
-
? (0, exports.getReadableIntentColor)(theme, intent, undefined, surface)
|
|
657
|
-
: ((_a = theme.text) === null || _a === void 0 ? void 0 : _a.color) || 'inherit';
|
|
658
|
-
};
|
|
659
|
-
exports.getReadableTextColor = getReadableTextColor;
|
|
660
|
-
/**
|
|
661
|
-
* A theme's color - an intent, the theme's main, a shade of one ('info', 'success:lighten:5') - in the shade of it
|
|
662
|
-
* that stands out by `minContrast` from what it is drawn on: `backgrounds` when they are known (a tag's fill, each
|
|
663
|
-
* color of a gradient), else `surface` or the theme's (`getThemeSurface`). The theme picks the hue, not how faint
|
|
664
|
-
* it is. Any other color is as it is given.
|
|
665
|
-
*/
|
|
666
|
-
var getReadableThemeColor = function (theme, color, minContrast, surface, backgrounds) {
|
|
667
|
-
var _a;
|
|
668
|
-
if (minContrast === void 0) { minContrast = exports.READABLE_TEXT_CONTRAST; }
|
|
669
|
-
var resolved = (0, exports.getColorFromMaybeString)(theme, color);
|
|
670
|
-
var base = typeof color === 'string' ? color.split(':')[0] : undefined;
|
|
671
|
-
if (!resolved || !base || (base !== 'main' && !((_a = theme.intents) === null || _a === void 0 ? void 0 : _a[base]))) {
|
|
672
|
-
return resolved;
|
|
129
|
+
if (minContrast === void 0) { minContrast = 4.5; }
|
|
130
|
+
var surface = (0, exports.getOpaqueColor)(background);
|
|
131
|
+
var onLight = (0, exports.shouldDarken)(surface);
|
|
132
|
+
var accent = (0, exports.getOpaqueColor)(color);
|
|
133
|
+
// 25 steps of 4% lightness cover the whole range, so the loop always ends.
|
|
134
|
+
for (var step = 0; step < 25 && (0, polished_1.getContrast)(accent, surface) < minContrast; step++) {
|
|
135
|
+
accent = (onLight ? (0, polished_1.darken)(0.04, accent) : (0, polished_1.lighten)(0.04, accent));
|
|
673
136
|
}
|
|
674
|
-
return
|
|
675
|
-
var under = (backgrounds === null || backgrounds === void 0 ? void 0 : backgrounds.length) ? backgrounds : (0, exports.getThemeSurfaces)(theme, surface);
|
|
676
|
-
return (0, exports.getReadableAccentColorOn)((0, exports.getDrawnColor)(resolved, under[0]), under, minContrast);
|
|
677
|
-
});
|
|
137
|
+
return accent;
|
|
678
138
|
};
|
|
679
|
-
exports.
|
|
680
|
-
/**
|
|
681
|
-
* Black or white for a background, by its value in the long form (a short hex, `#fff`, was read as the number
|
|
682
|
-
* `0xfff`: white text on white). Empty for no background; white for one it cannot read.
|
|
683
|
-
*/
|
|
139
|
+
exports.getReadableAccentColor = getReadableAccentColor;
|
|
684
140
|
var getColorByBgColor = function (bgColor) {
|
|
685
141
|
if (!bgColor) {
|
|
686
142
|
return '';
|
|
687
143
|
}
|
|
688
|
-
return parseInt(
|
|
689
|
-
? '#000000'
|
|
690
|
-
: '#ffffff';
|
|
144
|
+
return parseInt(bgColor.replace('#', ''), 16) > 0xffffff / 2 ? '#000000' : '#ffffff';
|
|
691
145
|
};
|
|
692
146
|
exports.getColorByBgColor = getColorByBgColor;
|
|
693
|
-
/** A hex color of 3, 4, 6 or 8 digits (the name is older than the rule): one CSS and the helpers read. */
|
|
694
147
|
var isValidSixCharHex = function (hex) {
|
|
695
|
-
return
|
|
148
|
+
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/.test(hex);
|
|
696
149
|
};
|
|
697
150
|
exports.isValidSixCharHex = isValidSixCharHex;
|
|
698
151
|
var buildTheme = function (theme) {
|
|
@@ -758,68 +211,40 @@ var getMainBackgroundColor = function (theme) {
|
|
|
758
211
|
return (0, exports.changeLightness)(theme.main, 0.02);
|
|
759
212
|
};
|
|
760
213
|
exports.getMainBackgroundColor = getMainBackgroundColor;
|
|
761
|
-
/**
|
|
762
|
-
* Whether `color` is one CSS draws though Reqore has no name for it: a color function (`var(--brand)`, `hsl()`,
|
|
763
|
-
* `color-mix()`), `currentColor`, or a color polished reads (a named one, `red`).
|
|
764
|
-
*/
|
|
765
|
-
var isCssColor = function (color) {
|
|
766
|
-
return color.includes('(') || /^currentcolor$/i.test(color) || (0, exports.isReadableColor)(color);
|
|
767
|
-
};
|
|
768
|
-
var rememberColor = (0, exports.createColorCache)();
|
|
769
|
-
/**
|
|
770
|
-
* The color `color` names: an intent, the theme's main (`main`, or nothing before the first colon), a hex (a short
|
|
771
|
-
* one with an alpha, `#f00a`, in its long form), or `transparent` (the theme's original main), lightened or
|
|
772
|
-
* darkened by a number of steps and drawn at an alpha (`info:lighten:2:0.5`). A color CSS draws but Reqore has no
|
|
773
|
-
* name for (`red`, `var(--brand)`, `currentColor`) is as it is given, and so is a color that cannot be lightened (an
|
|
774
|
-
* intent that is a CSS variable); a name nothing knows is undefined.
|
|
775
|
-
*/
|
|
776
214
|
var getColorFromMaybeString = function (theme, color) {
|
|
777
|
-
|
|
778
|
-
if (!color || typeof color !== 'string') {
|
|
215
|
+
if (!color) {
|
|
779
216
|
return undefined;
|
|
780
217
|
}
|
|
781
218
|
if (color.startsWith('rgba')) {
|
|
782
219
|
return (0, exports.RGBAToHexA)(color);
|
|
783
220
|
}
|
|
784
|
-
var
|
|
221
|
+
var _a = color.split(':'), providedColor = _a[0], shading = _a[1], _b = _a[2], multiplier = _b === void 0 ? 1 : _b, _c = _a[3], alpha = _c === void 0 ? 1 : _c;
|
|
785
222
|
if (providedColor === 'transparent') {
|
|
786
223
|
return theme.originalMain;
|
|
787
224
|
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
else if (!_color && providedColor && isCssColor(providedColor)) {
|
|
803
|
-
_color = providedColor;
|
|
804
|
-
}
|
|
805
|
-
// a color that cannot be read (a CSS variable) cannot be shaded either: it is drawn as it is
|
|
806
|
-
if (!(0, exports.isReadableColor)(_color)) {
|
|
807
|
-
return _color;
|
|
808
|
-
}
|
|
809
|
-
if (shading) {
|
|
810
|
-
if (shading === 'lighten') {
|
|
811
|
-
_color = (0, polished_1.lighten)(0.033 * multiplier, _color);
|
|
812
|
-
}
|
|
813
|
-
else if (shading === 'darken') {
|
|
814
|
-
_color = (0, polished_1.darken)(0.033 * multiplier, _color);
|
|
815
|
-
}
|
|
225
|
+
// First we need to get the actual color
|
|
226
|
+
var _color;
|
|
227
|
+
if (!providedColor || providedColor === 'main') {
|
|
228
|
+
_color = theme.main;
|
|
229
|
+
}
|
|
230
|
+
if (theme.intents[providedColor]) {
|
|
231
|
+
_color = theme.intents[providedColor];
|
|
232
|
+
}
|
|
233
|
+
if ((0, exports.isValidSixCharHex)(providedColor)) {
|
|
234
|
+
_color = providedColor;
|
|
235
|
+
}
|
|
236
|
+
if (shading) {
|
|
237
|
+
if (shading === 'lighten') {
|
|
238
|
+
_color = (0, polished_1.lighten)(0.033 * multiplier, _color);
|
|
816
239
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
_color = (0, exports.RGBAToHexA)((0, polished_1.transparentize)(1 - alpha, _color));
|
|
240
|
+
else if (shading === 'darken') {
|
|
241
|
+
_color = (0, polished_1.darken)(0.033 * multiplier, _color);
|
|
820
242
|
}
|
|
821
|
-
|
|
822
|
-
|
|
243
|
+
}
|
|
244
|
+
if (_color && _color.length === 7 && alpha < 1) {
|
|
245
|
+
_color = (0, exports.RGBAToHexA)((0, polished_1.transparentize)(1 - alpha, _color));
|
|
246
|
+
}
|
|
247
|
+
return _color;
|
|
823
248
|
};
|
|
824
249
|
exports.getColorFromMaybeString = getColorFromMaybeString;
|
|
825
250
|
var createEffectGradient = function (theme, colors, lighten, minimal, active, transparent) {
|
|
@@ -829,82 +254,36 @@ var createEffectGradient = function (theme, colors, lighten, minimal, active, tr
|
|
|
829
254
|
if (!colors) {
|
|
830
255
|
throw new Error('You need to provide colors');
|
|
831
256
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
return
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
? (0, exports.getColorAtAlpha)((0, exports.changeLightness)(stop, lighten), 0.25)
|
|
848
|
-
: (0, exports.changeLightness)(stop, lighten), " ").concat(percentage, "%");
|
|
849
|
-
}, '');
|
|
850
|
-
});
|
|
257
|
+
if (typeof colors === 'string') {
|
|
258
|
+
_colors = (0, exports.buildGradientColorsFromString)(theme, colors);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
_colors = colors;
|
|
262
|
+
}
|
|
263
|
+
return (0, lodash_1.reduce)(_colors, function (colorsString, color, percentage) {
|
|
264
|
+
return "".concat(colorsString, ", ").concat(transparent
|
|
265
|
+
? active
|
|
266
|
+
? theme.originalMain
|
|
267
|
+
: (0, exports.changeLightness)(theme.originalMain, lighten)
|
|
268
|
+
: minimal
|
|
269
|
+
? (0, polished_1.rgba)((0, exports.changeLightness)((0, exports.getColorFromMaybeString)(theme, color), lighten), 0.25)
|
|
270
|
+
: (0, exports.changeLightness)((0, exports.getColorFromMaybeString)(theme, color), lighten), " ").concat(percentage, "%");
|
|
271
|
+
}, '');
|
|
851
272
|
};
|
|
852
273
|
exports.createEffectGradient = createEffectGradient;
|
|
853
|
-
var rememberEffectGradient = (0, exports.createColorCache)();
|
|
854
|
-
var rememberGradientColors = (0, exports.createColorCache)();
|
|
855
|
-
/**
|
|
856
|
-
* A gradient made from one color (`'info'`, `'#0776cb'`): see `buildGradientShades`. A color it cannot read (a CSS
|
|
857
|
-
* variable) is the gradient's both ends.
|
|
858
|
-
*/
|
|
859
274
|
var buildGradientColorsFromString = function (theme, colorString) {
|
|
860
275
|
if (!colorString) {
|
|
861
276
|
throw new Error('You need to provide a color or intent');
|
|
862
277
|
}
|
|
863
278
|
var finalColor = (0, exports.getColorFromMaybeString)(theme, colorString);
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
}
|
|
867
|
-
// the shades depend only on the color: a copy, so a caller that changes it changes nobody else's
|
|
868
|
-
return __assign({}, rememberGradientColors(finalColor, function () { return buildGradientShades(theme, finalColor); }));
|
|
869
|
-
};
|
|
870
|
-
exports.buildGradientColorsFromString = buildGradientColorsFromString;
|
|
871
|
-
var buildGradientShades = function (theme, finalColor) {
|
|
872
|
-
/* A lighter and a darker shade of the color, each as far as five steps from it - but only as far as the text
|
|
873
|
-
that reads on the color still reads on the shade: a gradient made from one color is a color text is put on,
|
|
874
|
-
and a blue lightened past where white reads on it was white text on a light blue at one end. */
|
|
875
|
-
var text = (0, exports.getReadableColorOn)([finalColor]);
|
|
876
|
-
// read at rest and a step lighter, as the effect draws it hovered or pressed
|
|
877
|
-
var readsOn = function (shade) {
|
|
878
|
-
return (0, exports.getContrastRatio)(text, shade) >= exports.READABLE_TEXT_CONTRAST &&
|
|
879
|
-
(0, exports.getContrastRatio)(text, (0, exports.changeLightness)(shade, 0.05)) >= exports.READABLE_TEXT_CONTRAST;
|
|
880
|
-
};
|
|
881
|
-
var getShade = function (shading) {
|
|
882
|
-
for (var steps = 5; steps > 0; steps--) {
|
|
883
|
-
var shade = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":").concat(shading, ":").concat(steps, ":1"));
|
|
884
|
-
if (readsOn(shade)) {
|
|
885
|
-
return shade;
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
if (readsOn(finalColor)) {
|
|
889
|
-
return finalColor;
|
|
890
|
-
}
|
|
891
|
-
// the color itself does not read once lightened: as little the other way as it takes
|
|
892
|
-
var opposite = shading === 'lighten' ? 'darken' : 'lighten';
|
|
893
|
-
for (var steps = 1; steps <= 5; steps++) {
|
|
894
|
-
var shade = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":").concat(opposite, ":").concat(steps, ":1"));
|
|
895
|
-
if (readsOn(shade)) {
|
|
896
|
-
return shade;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
return finalColor;
|
|
900
|
-
};
|
|
901
|
-
var colorFrom = getShade('lighten');
|
|
902
|
-
var colorTo = getShade('darken');
|
|
279
|
+
var colorFrom = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":lighten:5:1"));
|
|
280
|
+
var colorTo = (0, exports.getColorFromMaybeString)(theme, "".concat(finalColor, ":darken:5:1"));
|
|
903
281
|
return {
|
|
904
282
|
0: colorFrom,
|
|
905
283
|
100: colorTo,
|
|
906
284
|
};
|
|
907
285
|
};
|
|
286
|
+
exports.buildGradientColorsFromString = buildGradientColorsFromString;
|
|
908
287
|
var getNthGradientColor = function (theme, colors, nth) {
|
|
909
288
|
if (nth === void 0) { nth = 1; }
|
|
910
289
|
var _colors = typeof colors === 'string' ? (0, exports.buildGradientColorsFromString)(theme, colors) : colors;
|
|
@@ -914,16 +293,7 @@ var getNthGradientColor = function (theme, colors, nth) {
|
|
|
914
293
|
return undefined;
|
|
915
294
|
};
|
|
916
295
|
exports.getNthGradientColor = getNthGradientColor;
|
|
917
|
-
var rememberGradientMix = (0, exports.createColorCache)();
|
|
918
296
|
var getGradientMix = function (theme, colors, fallback) {
|
|
919
|
-
if (!colors) {
|
|
920
|
-
return fallback;
|
|
921
|
-
}
|
|
922
|
-
return rememberGradientMix((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), typeof colors === 'string' ? colors : JSON.stringify(colors), fallback), function () { return mixGradient(theme, colors, fallback); });
|
|
923
|
-
};
|
|
924
|
-
exports.getGradientMix = getGradientMix;
|
|
925
|
-
/** The middle of a gradient, the mix of its first and last colors: see `getGradientMix`. */
|
|
926
|
-
var mixGradient = function (theme, colors, fallback) {
|
|
927
297
|
var _colors = typeof colors === 'string' ? (0, exports.buildGradientColorsFromString)(theme, colors) : colors;
|
|
928
298
|
if (!_colors) {
|
|
929
299
|
return fallback;
|
|
@@ -931,30 +301,7 @@ var mixGradient = function (theme, colors, fallback) {
|
|
|
931
301
|
// If there are more than 2 colors, we can't mix them, so we get the first and last color
|
|
932
302
|
var gradientColor1 = (0, exports.getNthGradientColor)(theme, _colors);
|
|
933
303
|
var gradientColor2 = (0, exports.getNthGradientColor)(theme, _colors, (0, lodash_1.size)(_colors));
|
|
934
|
-
|
|
935
|
-
var last = gradientColor2 === '#00000000' ? theme.main : gradientColor2;
|
|
936
|
-
// colors it cannot read (a CSS variable) cannot be mixed: the first that can be, or the fallback
|
|
937
|
-
if (!(0, exports.isReadableColor)(first) || !(0, exports.isReadableColor)(last)) {
|
|
938
|
-
return [first, last].find(function (color) { return (0, exports.isReadableColor)(color); }) || fallback || first;
|
|
939
|
-
}
|
|
940
|
-
return (0, exports.RGBAToHexA)((0, polished_1.mix)(0.5, first, last));
|
|
304
|
+
return (0, exports.RGBAToHexA)((0, polished_1.mix)(0.5, gradientColor1 === '#00000000' ? theme.main : gradientColor1, gradientColor2 === '#00000000' ? theme.main : gradientColor2));
|
|
941
305
|
};
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* Each color a gradient is drawn in, as given (a translucent one stays translucent): what text on the gradient has
|
|
945
|
-
* to stand out from, every one of them.
|
|
946
|
-
*/
|
|
947
|
-
var getGradientColorList = function (theme, colors) {
|
|
948
|
-
if (!colors) {
|
|
949
|
-
return [];
|
|
950
|
-
}
|
|
951
|
-
// a copy: a caller that changes the list changes nobody else's
|
|
952
|
-
return __spreadArray([], rememberGradientList((0, exports.cacheKey)((0, exports.getThemeColorKey)(theme), typeof colors === 'string' ? colors : JSON.stringify(colors)), function () {
|
|
953
|
-
var _colors = typeof colors === 'string' ? (0, exports.buildGradientColorsFromString)(theme, colors) : colors;
|
|
954
|
-
return Object.values(_colors)
|
|
955
|
-
.map(function (color) { return (0, exports.getColorFromMaybeString)(theme, color); })
|
|
956
|
-
.filter(function (color) { return !!color; });
|
|
957
|
-
}), true);
|
|
958
|
-
};
|
|
959
|
-
exports.getGradientColorList = getGradientColorList;
|
|
306
|
+
exports.getGradientMix = getGradientMix;
|
|
960
307
|
//# sourceMappingURL=colors.js.map
|