@stats-organization/github-readme-stats-core 2.1.2 → 2.1.4
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/README.md +1 -1
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +0 -1
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +0 -1
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +0 -1
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +0 -1
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +0 -1
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +0 -1
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +0 -1
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +0 -1
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +0 -1
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +0 -1
- package/build/common/Card.d.ts +48 -60
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +49 -50
- package/build/common/I18n.d.ts +13 -14
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +13 -12
- package/build/common/color.d.ts +30 -40
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +30 -42
- package/build/common/config.d.ts +18 -2
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +17 -26
- package/build/common/constants.d.ts +2 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +5 -3
- package/build/common/error.d.ts +36 -29
- package/build/common/error.d.ts.map +1 -1
- package/build/common/error.js +14 -10
- package/build/common/fmt.d.ts +14 -13
- package/build/common/fmt.d.ts.map +1 -1
- package/build/common/fmt.js +19 -15
- package/build/common/html.d.ts +2 -4
- package/build/common/html.d.ts.map +1 -1
- package/build/common/html.js +1 -5
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +0 -1
- package/build/common/icons.d.ts +22 -21
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +4 -5
- package/build/common/languageColors.json +2 -0
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +0 -1
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +0 -1
- package/build/common/retryer.d.ts +18 -15
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +21 -30
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +0 -1
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +3 -6
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +3 -6
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +0 -1
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +0 -1
- package/build/translations.d.ts +627 -24
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +7 -8
- package/package.json +5 -5
- package/src/api/gist.js +0 -2
- package/src/api/index.js +0 -2
- package/src/api/pin.js +0 -2
- package/src/api/top-langs.js +0 -2
- package/src/api/wakatime.js +0 -2
- package/src/cards/gist.js +0 -2
- package/src/cards/repo.js +0 -2
- package/src/cards/stats.js +0 -2
- package/src/cards/top-languages.js +0 -2
- package/src/cards/wakatime.js +0 -2
- package/src/common/{Card.js → Card.ts} +89 -61
- package/src/common/I18n.ts +49 -0
- package/src/common/{color.js → color.ts} +55 -51
- package/src/common/config.ts +83 -0
- package/src/common/constants.ts +10 -0
- package/src/common/{error.js → error.ts} +20 -14
- package/src/common/{fmt.js → fmt.ts} +27 -19
- package/src/common/{html.js → html.ts} +3 -8
- package/src/common/http.js +0 -2
- package/src/common/{icons.js → icons.ts} +9 -7
- package/src/common/languageColors.json +2 -0
- package/src/common/ops.js +0 -2
- package/src/common/render.js +0 -2
- package/src/common/{retryer.js → retryer.ts} +45 -32
- package/src/fetchers/gist.js +0 -2
- package/src/fetchers/repo.js +3 -7
- package/src/fetchers/stats.js +3 -7
- package/src/fetchers/top-languages.js +0 -2
- package/src/fetchers/types.d.ts +1 -1
- package/src/fetchers/wakatime.js +0 -2
- package/src/{translations.js → translations.ts} +14 -10
- package/src/common/I18n.js +0 -42
- package/src/common/config.js +0 -78
- package/src/common/constants.js +0 -9
package/build/translations.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
import { encodeHTML } from "./common/html.js";
|
|
3
2
|
/**
|
|
4
3
|
* Retrieves stat card labels in the available locales.
|
|
5
4
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @returns
|
|
5
|
+
* @param props Function arguments.
|
|
6
|
+
* @param props.name The name of the locale.
|
|
7
|
+
* @param props.apostrophe Whether to use apostrophe or not.
|
|
8
|
+
* @returns The locales object.
|
|
10
9
|
*
|
|
11
10
|
* @see https://www.andiamo.co.uk/resources/iso-language-codes/ for language codes.
|
|
12
11
|
*/
|
|
13
|
-
const statCardLocales = ({ name, apostrophe }) => {
|
|
12
|
+
const statCardLocales = ({ name, apostrophe, }) => {
|
|
14
13
|
const encodedName = encodeHTML(name);
|
|
15
14
|
return {
|
|
16
15
|
"statcard.title": {
|
|
@@ -1131,8 +1130,8 @@ const availableLocales = Object.keys(repoCardLocales["repocard.archived"]);
|
|
|
1131
1130
|
/**
|
|
1132
1131
|
* Checks whether the locale is available or not.
|
|
1133
1132
|
*
|
|
1134
|
-
* @param
|
|
1135
|
-
* @returns
|
|
1133
|
+
* @param locale The locale to check.
|
|
1134
|
+
* @returns Boolean specifying whether the locale is available or not.
|
|
1136
1135
|
*/
|
|
1137
1136
|
const isLocaleAvailable = (locale) => {
|
|
1138
1137
|
return availableLocales.includes(locale.toLowerCase());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stats-organization/github-readme-stats-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github-stats-extended.vercel.app/frontend",
|
|
6
6
|
"bugs": {
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"@testing-library/jest-dom": "6.9.1",
|
|
72
72
|
"@uppercod/css-to-object": "1.1.1",
|
|
73
73
|
"axios-mock-adapter": "2.1.0",
|
|
74
|
-
"js-yaml": "4.
|
|
75
|
-
"jsdom": "29.
|
|
76
|
-
"vitest": "4.1.
|
|
74
|
+
"js-yaml": "4.2.0",
|
|
75
|
+
"jsdom": "29.1.1",
|
|
76
|
+
"vitest": "4.1.8"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"axios": "^1.
|
|
79
|
+
"axios": "^1.17.0",
|
|
80
80
|
"emoji-name-map": "^2.0.3",
|
|
81
81
|
"github-username-regex": "^1.0.0"
|
|
82
82
|
},
|
package/src/api/gist.js
CHANGED
package/src/api/index.js
CHANGED
package/src/api/pin.js
CHANGED
package/src/api/top-langs.js
CHANGED
package/src/api/wakatime.js
CHANGED
package/src/cards/gist.js
CHANGED
package/src/cards/repo.js
CHANGED
package/src/cards/stats.js
CHANGED
package/src/cards/wakatime.js
CHANGED
|
@@ -1,25 +1,46 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
1
|
import { encodeHTML } from "./html.js";
|
|
4
2
|
import { flexLayout } from "./render.js";
|
|
5
3
|
|
|
4
|
+
interface CardColors {
|
|
5
|
+
/** Card title color. */
|
|
6
|
+
titleColor?: string;
|
|
7
|
+
/** Card text color. */
|
|
8
|
+
textColor?: string;
|
|
9
|
+
/** Card icon color. */
|
|
10
|
+
iconColor?: string;
|
|
11
|
+
/** Card background color. */
|
|
12
|
+
bgColor?: string | Array<string>;
|
|
13
|
+
/** Card border color. */
|
|
14
|
+
borderColor?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
class Card {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
hideBorder: boolean;
|
|
21
|
+
hideTitle: boolean;
|
|
22
|
+
border_radius: number;
|
|
23
|
+
colors: CardColors;
|
|
24
|
+
title: string;
|
|
25
|
+
css: string;
|
|
26
|
+
paddingX: number;
|
|
27
|
+
paddingY: number;
|
|
28
|
+
titlePrefixIcon: string | undefined;
|
|
29
|
+
animations: boolean;
|
|
30
|
+
a11yTitle: string;
|
|
31
|
+
a11yDesc: string;
|
|
32
|
+
|
|
7
33
|
/**
|
|
8
34
|
* Creates a new card instance.
|
|
9
35
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param {string=} args.colors.titleColor Card title color.
|
|
19
|
-
* @param {string=} args.colors.textColor Card text color.
|
|
20
|
-
* @param {string=} args.colors.iconColor Card icon color.
|
|
21
|
-
* @param {string|string[]=} args.colors.bgColor Card background color.
|
|
22
|
-
* @param {string=} args.colors.borderColor Card border color.
|
|
36
|
+
* @param props Card arguments.
|
|
37
|
+
* @param props.width Card width.
|
|
38
|
+
* @param props.height Card height.
|
|
39
|
+
* @param props.border_radius Card border radius.
|
|
40
|
+
* @param props.colors Card colors arguments.
|
|
41
|
+
* @param props.customTitle Card custom title.
|
|
42
|
+
* @param props.defaultTitle Card default title.
|
|
43
|
+
* @param props.titlePrefixIcon Card title prefix icon.
|
|
23
44
|
*/
|
|
24
45
|
constructor({
|
|
25
46
|
width = 100,
|
|
@@ -29,6 +50,14 @@ class Card {
|
|
|
29
50
|
customTitle,
|
|
30
51
|
defaultTitle = "",
|
|
31
52
|
titlePrefixIcon,
|
|
53
|
+
}: {
|
|
54
|
+
width?: number;
|
|
55
|
+
height?: number;
|
|
56
|
+
border_radius?: number;
|
|
57
|
+
colors?: CardColors;
|
|
58
|
+
customTitle?: string;
|
|
59
|
+
defaultTitle?: string;
|
|
60
|
+
titlePrefixIcon?: string;
|
|
32
61
|
}) {
|
|
33
62
|
this.width = width;
|
|
34
63
|
this.height = height;
|
|
@@ -40,10 +69,9 @@ class Card {
|
|
|
40
69
|
|
|
41
70
|
// returns theme based colors with proper overrides and defaults
|
|
42
71
|
this.colors = colors;
|
|
43
|
-
this.title =
|
|
44
|
-
customTitle === undefined
|
|
45
|
-
|
|
46
|
-
: encodeHTML(customTitle);
|
|
72
|
+
this.title = encodeHTML(
|
|
73
|
+
customTitle === undefined ? defaultTitle : customTitle,
|
|
74
|
+
);
|
|
47
75
|
|
|
48
76
|
this.css = "";
|
|
49
77
|
|
|
@@ -55,45 +83,44 @@ class Card {
|
|
|
55
83
|
this.a11yDesc = "";
|
|
56
84
|
}
|
|
57
85
|
|
|
58
|
-
|
|
59
|
-
* @returns {void}
|
|
60
|
-
*/
|
|
61
|
-
disableAnimations() {
|
|
86
|
+
disableAnimations(): void {
|
|
62
87
|
this.animations = false;
|
|
63
88
|
}
|
|
64
89
|
|
|
65
90
|
/**
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @returns {void}
|
|
91
|
+
* @param props The props object.
|
|
92
|
+
* @param props.title Accessibility title.
|
|
93
|
+
* @param props.desc Accessibility description.
|
|
70
94
|
*/
|
|
71
|
-
setAccessibilityLabel({
|
|
95
|
+
setAccessibilityLabel({
|
|
96
|
+
title,
|
|
97
|
+
desc,
|
|
98
|
+
}: {
|
|
99
|
+
title: string;
|
|
100
|
+
desc: string;
|
|
101
|
+
}): void {
|
|
72
102
|
this.a11yTitle = title;
|
|
73
103
|
this.a11yDesc = desc;
|
|
74
104
|
}
|
|
75
105
|
|
|
76
106
|
/**
|
|
77
|
-
* @param
|
|
78
|
-
* @returns {void}
|
|
107
|
+
* @param value The CSS to add to the card.
|
|
79
108
|
*/
|
|
80
|
-
setCSS(value) {
|
|
109
|
+
setCSS(value: string): void {
|
|
81
110
|
this.css = value;
|
|
82
111
|
}
|
|
83
112
|
|
|
84
113
|
/**
|
|
85
|
-
* @param
|
|
86
|
-
* @returns {void}
|
|
114
|
+
* @param value Whether to hide the border or not.
|
|
87
115
|
*/
|
|
88
|
-
setHideBorder(value) {
|
|
116
|
+
setHideBorder(value: boolean): void {
|
|
89
117
|
this.hideBorder = value;
|
|
90
118
|
}
|
|
91
119
|
|
|
92
120
|
/**
|
|
93
|
-
* @param
|
|
94
|
-
* @returns {void}
|
|
121
|
+
* @param value Whether to hide the title or not.
|
|
95
122
|
*/
|
|
96
|
-
setHideTitle(value) {
|
|
123
|
+
setHideTitle(value: boolean): void {
|
|
97
124
|
this.hideTitle = value;
|
|
98
125
|
if (value) {
|
|
99
126
|
this.height -= 30;
|
|
@@ -101,17 +128,16 @@ class Card {
|
|
|
101
128
|
}
|
|
102
129
|
|
|
103
130
|
/**
|
|
104
|
-
* @param
|
|
105
|
-
* @returns {void}
|
|
131
|
+
* @param text The title to set.
|
|
106
132
|
*/
|
|
107
|
-
setTitle(text) {
|
|
133
|
+
setTitle(text: string): void {
|
|
108
134
|
this.title = text;
|
|
109
135
|
}
|
|
110
136
|
|
|
111
137
|
/**
|
|
112
|
-
* @returns
|
|
138
|
+
* @returns The rendered card title.
|
|
113
139
|
*/
|
|
114
|
-
renderTitle() {
|
|
140
|
+
renderTitle(): string {
|
|
115
141
|
const titleText = `
|
|
116
142
|
<text
|
|
117
143
|
x="0"
|
|
@@ -131,7 +157,7 @@ class Card {
|
|
|
131
157
|
width="16"
|
|
132
158
|
height="16"
|
|
133
159
|
>
|
|
134
|
-
${this.titlePrefixIcon}
|
|
160
|
+
${String(this.titlePrefixIcon)}
|
|
135
161
|
</svg>
|
|
136
162
|
`;
|
|
137
163
|
return `
|
|
@@ -148,9 +174,9 @@ class Card {
|
|
|
148
174
|
}
|
|
149
175
|
|
|
150
176
|
/**
|
|
151
|
-
* @returns
|
|
177
|
+
* @returns The rendered card gradient.
|
|
152
178
|
*/
|
|
153
|
-
renderGradient() {
|
|
179
|
+
renderGradient(): string {
|
|
154
180
|
if (typeof this.colors.bgColor !== "object") {
|
|
155
181
|
return "";
|
|
156
182
|
}
|
|
@@ -161,13 +187,15 @@ class Card {
|
|
|
161
187
|
<defs>
|
|
162
188
|
<linearGradient
|
|
163
189
|
id="gradient"
|
|
164
|
-
gradientTransform="rotate(${this.colors.bgColor[0]})"
|
|
190
|
+
gradientTransform="rotate(${String(this.colors.bgColor[0])})"
|
|
165
191
|
gradientUnits="userSpaceOnUse"
|
|
166
192
|
>
|
|
167
|
-
${gradients
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
193
|
+
${gradients
|
|
194
|
+
.map((grad, index) => {
|
|
195
|
+
const offset = (index * 100) / (gradients.length - 1);
|
|
196
|
+
return `<stop offset="${offset}%" stop-color="#${grad}" />`;
|
|
197
|
+
})
|
|
198
|
+
.join(",")}
|
|
171
199
|
</linearGradient>
|
|
172
200
|
</defs>
|
|
173
201
|
`
|
|
@@ -177,9 +205,9 @@ class Card {
|
|
|
177
205
|
/**
|
|
178
206
|
* Retrieves css animations for a card.
|
|
179
207
|
*
|
|
180
|
-
* @returns
|
|
208
|
+
* @returns Animation css.
|
|
181
209
|
*/
|
|
182
|
-
getAnimations = () => {
|
|
210
|
+
getAnimations = (): string => {
|
|
183
211
|
return `
|
|
184
212
|
/* Animations */
|
|
185
213
|
@keyframes scaleInAnimation {
|
|
@@ -202,10 +230,10 @@ class Card {
|
|
|
202
230
|
};
|
|
203
231
|
|
|
204
232
|
/**
|
|
205
|
-
* @param
|
|
206
|
-
* @returns
|
|
233
|
+
* @param body The inner body of the card.
|
|
234
|
+
* @returns The rendered card.
|
|
207
235
|
*/
|
|
208
|
-
render(body) {
|
|
236
|
+
render(body: string): string {
|
|
209
237
|
return `
|
|
210
238
|
<svg
|
|
211
239
|
width="${this.width}"
|
|
@@ -221,7 +249,7 @@ class Card {
|
|
|
221
249
|
<style>
|
|
222
250
|
.header {
|
|
223
251
|
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
|
|
224
|
-
fill: ${this.colors.titleColor};
|
|
252
|
+
fill: ${String(this.colors.titleColor)};
|
|
225
253
|
animation: fadeInAnimation 0.8s ease-in-out forwards;
|
|
226
254
|
}
|
|
227
255
|
@supports(-moz-appearance: auto) {
|
|
@@ -232,9 +260,9 @@ class Card {
|
|
|
232
260
|
|
|
233
261
|
${this.getAnimations()}
|
|
234
262
|
${
|
|
235
|
-
this.animations
|
|
236
|
-
?
|
|
237
|
-
:
|
|
263
|
+
this.animations
|
|
264
|
+
? ""
|
|
265
|
+
: `* { animation-duration: 0s !important; animation-delay: 0s !important; }`
|
|
238
266
|
}
|
|
239
267
|
</style>
|
|
240
268
|
|
|
@@ -246,12 +274,12 @@ class Card {
|
|
|
246
274
|
y="0.5"
|
|
247
275
|
rx="${this.border_radius}"
|
|
248
276
|
height="99%"
|
|
249
|
-
stroke="${this.colors.borderColor}"
|
|
277
|
+
stroke="${String(this.colors.borderColor)}"
|
|
250
278
|
width="${this.width - 1}"
|
|
251
279
|
fill="${
|
|
252
280
|
typeof this.colors.bgColor === "object"
|
|
253
281
|
? "url(#gradient)"
|
|
254
|
-
: this.colors.bgColor
|
|
282
|
+
: String(this.colors.bgColor)
|
|
255
283
|
}"
|
|
256
284
|
stroke-opacity="${this.hideBorder ? 0 : 1}"
|
|
257
285
|
/>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const FALLBACK_LOCALE = "en";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* I18n translation class.
|
|
5
|
+
*/
|
|
6
|
+
class I18n<Translations extends Record<string, Record<string, string>>> {
|
|
7
|
+
locale: string;
|
|
8
|
+
translations: Translations;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param props Constructor arguments.
|
|
12
|
+
* @param props.locale Locale.
|
|
13
|
+
* @param props.translations Translations.
|
|
14
|
+
*/
|
|
15
|
+
constructor({
|
|
16
|
+
locale,
|
|
17
|
+
translations,
|
|
18
|
+
}: {
|
|
19
|
+
locale?: string;
|
|
20
|
+
translations: Translations;
|
|
21
|
+
}) {
|
|
22
|
+
this.locale = locale || FALLBACK_LOCALE;
|
|
23
|
+
this.translations = translations;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get translation.
|
|
28
|
+
*
|
|
29
|
+
* @param str String to translate.
|
|
30
|
+
* @returns Translated string.
|
|
31
|
+
*/
|
|
32
|
+
t(str: keyof Translations & string): string {
|
|
33
|
+
const translation = this.translations[str];
|
|
34
|
+
if (!translation) {
|
|
35
|
+
throw new Error(`${str} Translation string not found`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const localized = translation[this.locale];
|
|
39
|
+
if (!localized) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`'${str}' translation not found for locale '${this.locale}'`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return localized;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { I18n };
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
1
|
import { themes } from "../themes/index.js";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Checks if a string is a valid hex color.
|
|
7
5
|
*
|
|
8
|
-
* @param
|
|
9
|
-
* @returns
|
|
6
|
+
* @param hexColor String to check.
|
|
7
|
+
* @returns True if the given string is a valid hex color.
|
|
10
8
|
*/
|
|
11
|
-
const isValidHexColor = (hexColor) => {
|
|
9
|
+
const isValidHexColor = (hexColor: string): boolean => {
|
|
12
10
|
return new RegExp(
|
|
13
11
|
/^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4})$/,
|
|
14
12
|
).test(hexColor);
|
|
@@ -17,10 +15,10 @@ const isValidHexColor = (hexColor) => {
|
|
|
17
15
|
/**
|
|
18
16
|
* Check if the given string is a valid gradient.
|
|
19
17
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @returns
|
|
18
|
+
* @param colors Array of colors.
|
|
19
|
+
* @returns True if the given string is a valid gradient.
|
|
22
20
|
*/
|
|
23
|
-
const isValidGradient = (colors) => {
|
|
21
|
+
const isValidGradient = (colors: Array<string>): boolean => {
|
|
24
22
|
return (
|
|
25
23
|
colors.length > 2 &&
|
|
26
24
|
colors.slice(1).every((color) => isValidHexColor(color))
|
|
@@ -30,48 +28,50 @@ const isValidGradient = (colors) => {
|
|
|
30
28
|
/**
|
|
31
29
|
* Retrieves a gradient if color has more than one valid hex codes else a single color.
|
|
32
30
|
*
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @returns
|
|
31
|
+
* @param color The color to parse.
|
|
32
|
+
* @param fallbackColor The fallback color.
|
|
33
|
+
* @returns The gradient or color.
|
|
36
34
|
*/
|
|
37
|
-
const fallbackColor = (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const fallbackColor = (
|
|
36
|
+
color: string | undefined,
|
|
37
|
+
fallbackColor: string | Array<string>,
|
|
38
|
+
): string | Array<string> => {
|
|
39
|
+
const colors = color ? color.split(",") : [];
|
|
41
40
|
if (colors.length > 1 && isValidGradient(colors)) {
|
|
42
|
-
|
|
41
|
+
return colors;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (color !== undefined && isValidHexColor(color)) {
|
|
45
|
+
return `#${color}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return fallbackColor;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Object containing card colors.
|
|
53
|
-
* @typedef {{
|
|
54
|
-
* titleColor: string;
|
|
55
|
-
* iconColor: string;
|
|
56
|
-
* textColor: string;
|
|
57
|
-
* bgColor: string | string[];
|
|
58
|
-
* borderColor: string;
|
|
59
|
-
* ringColor: string;
|
|
60
|
-
* }} CardColors
|
|
61
53
|
*/
|
|
54
|
+
interface CardColors {
|
|
55
|
+
titleColor: string;
|
|
56
|
+
iconColor: string;
|
|
57
|
+
textColor: string;
|
|
58
|
+
bgColor: string | Array<string>;
|
|
59
|
+
borderColor: string;
|
|
60
|
+
ringColor: string;
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Returns theme based colors with proper overrides and defaults.
|
|
65
65
|
*
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @param
|
|
72
|
-
* @param
|
|
73
|
-
* @param
|
|
74
|
-
* @returns
|
|
66
|
+
* @param props Function arguments.
|
|
67
|
+
* @param props.title_color Card title color.
|
|
68
|
+
* @param props.text_color Card text color.
|
|
69
|
+
* @param props.icon_color Card icon color.
|
|
70
|
+
* @param props.bg_color Card background color.
|
|
71
|
+
* @param props.border_color Card border color.
|
|
72
|
+
* @param props.ring_color Card ring color.
|
|
73
|
+
* @param props.theme Card theme.
|
|
74
|
+
* @returns Card colors.
|
|
75
75
|
*/
|
|
76
76
|
const getCardColors = ({
|
|
77
77
|
title_color,
|
|
@@ -81,19 +81,26 @@ const getCardColors = ({
|
|
|
81
81
|
border_color,
|
|
82
82
|
ring_color,
|
|
83
83
|
theme,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
}: {
|
|
85
|
+
title_color?: string;
|
|
86
|
+
text_color?: string;
|
|
87
|
+
icon_color?: string;
|
|
88
|
+
bg_color?: string;
|
|
89
|
+
border_color?: string;
|
|
90
|
+
ring_color?: string;
|
|
91
|
+
theme?: string;
|
|
92
|
+
}): CardColors => {
|
|
93
|
+
const defaultTheme = themes.default;
|
|
94
|
+
const isThemeProvided = theme !== undefined && theme in themes;
|
|
95
|
+
|
|
96
|
+
const selectedTheme = isThemeProvided
|
|
97
|
+
? themes[theme as keyof typeof themes]
|
|
98
|
+
: defaultTheme;
|
|
91
99
|
|
|
92
100
|
const defaultBorderColor =
|
|
93
101
|
"border_color" in selectedTheme
|
|
94
102
|
? selectedTheme.border_color
|
|
95
|
-
:
|
|
96
|
-
defaultTheme.border_color;
|
|
103
|
+
: defaultTheme.border_color;
|
|
97
104
|
|
|
98
105
|
// get the color provided by the user else the theme color
|
|
99
106
|
// finally if both colors are invalid fallback to default theme
|
|
@@ -104,11 +111,8 @@ const getCardColors = ({
|
|
|
104
111
|
|
|
105
112
|
// get the color provided by the user else the theme color
|
|
106
113
|
// finally if both colors are invalid we use the titleColor
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
ring_color || selectedTheme.ring_color,
|
|
110
|
-
titleColor,
|
|
111
|
-
);
|
|
114
|
+
// NOTE: no built-in theme defines `ring_color`, so it falls back to the title color.
|
|
115
|
+
const ringColor = fallbackColor(ring_color, titleColor);
|
|
112
116
|
const iconColor = fallbackColor(
|
|
113
117
|
icon_color || selectedTheme.icon_color,
|
|
114
118
|
"#" + defaultTheme.icon_color,
|