@stats-organization/github-readme-stats-core 2.1.4 → 2.2.0
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/build/api/gist.d.ts +2 -7
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +28 -26
- package/build/api/index.d.ts +3 -8
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +32 -36
- package/build/api/pin.d.ts +2 -7
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +18 -33
- package/build/api/top-langs.d.ts +2 -7
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +32 -44
- package/build/api/wakatime.d.ts +2 -7
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +28 -26
- package/build/calculateRank.d.ts +12 -11
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +18 -18
- package/build/cards/common-options.d.ts +13 -0
- package/build/cards/common-options.d.ts.map +1 -0
- package/build/cards/common-options.js +1 -0
- package/build/cards/gist.d.ts +11 -16
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +26 -31
- package/build/cards/repo.d.ts +19 -16
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +79 -72
- package/build/cards/stats.d.ts +29 -44
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +118 -173
- package/build/cards/top-languages.d.ts +81 -77
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +186 -184
- package/build/cards/wakatime.d.ts +21 -11
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +92 -109
- package/build/common/Card.d.ts +41 -14
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +92 -31
- package/build/common/I18n.d.ts +4 -2
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/color.d.ts +91 -15
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +163 -17
- package/build/common/config.d.ts +2 -1
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +16 -26
- package/build/common/constants.d.ts +2 -1
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/date.d.ts +37 -0
- package/build/common/date.d.ts.map +1 -0
- package/build/common/date.js +31 -0
- package/build/common/html.js +1 -1
- package/build/common/http.d.ts +37 -5
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +29 -6
- package/build/common/icons.d.ts +1 -0
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +1 -0
- package/build/common/languageColors.d.ts +11 -0
- package/build/common/languageColors.d.ts.map +1 -0
- package/build/common/languageColors.js +15 -0
- package/build/common/languageColors.json +10 -1
- package/build/common/ops.d.ts +27 -33
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +31 -48
- package/build/common/render.d.ts +154 -113
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +209 -92
- package/build/common/retryer.d.ts +15 -6
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +2 -0
- package/build/fetchers/gist.d.ts +6 -21
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +28 -64
- package/build/fetchers/repo.d.ts +12 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +27 -68
- package/build/fetchers/stats.d.ts +24 -17
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +302 -184
- package/build/fetchers/top-languages.d.ts +10 -15
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +52 -103
- package/build/fetchers/types.d.ts +130 -0
- package/build/fetchers/types.d.ts.map +1 -0
- package/build/fetchers/types.js +1 -0
- package/build/fetchers/wakatime.d.ts +9 -5
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +8 -4
- package/build/graphql/contributionsDocument.d.ts +18 -0
- package/build/graphql/contributionsDocument.d.ts.map +1 -0
- package/build/graphql/contributionsDocument.js +30 -0
- package/build/graphql/generated/common.d.ts +42 -0
- package/build/graphql/generated/common.d.ts.map +1 -0
- package/build/graphql/generated/common.js +2 -0
- package/build/graphql/generated/gist.d.ts +44 -0
- package/build/graphql/generated/gist.d.ts.map +1 -0
- package/build/graphql/generated/gist.js +27 -0
- package/build/graphql/generated/repo.d.ts +67 -0
- package/build/graphql/generated/repo.d.ts.map +1 -0
- package/build/graphql/generated/repo.js +30 -0
- package/build/graphql/generated/stats.d.ts +150 -0
- package/build/graphql/generated/stats.d.ts.map +1 -0
- package/build/graphql/generated/stats.js +95 -0
- package/build/graphql/generated/top-languages.d.ts +54 -0
- package/build/graphql/generated/top-languages.d.ts.map +1 -0
- package/build/graphql/generated/top-languages.js +27 -0
- package/build/graphql/graphqlDocument.d.ts +22 -0
- package/build/graphql/graphqlDocument.d.ts.map +1 -0
- package/build/graphql/graphqlDocument.js +8 -0
- package/build/graphql/reposContributedToDocument.d.ts +27 -0
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -0
- package/build/graphql/reposContributedToDocument.js +59 -0
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/themes/index.d.ts +32 -0
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +28 -0
- package/build/translations.d.ts +17 -0
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +17 -0
- package/package.json +14 -8
- package/src/_emoji-name-map.d.ts +10 -0
- package/src/_github-username-regex.d.ts +4 -0
- package/src/api/gist.js +31 -31
- package/src/api/index.js +40 -42
- package/src/api/pin.js +20 -38
- package/src/api/top-langs.js +36 -49
- package/src/api/wakatime.js +31 -31
- package/src/{calculateRank.js → calculateRank.ts} +29 -19
- package/src/cards/common-options.ts +13 -0
- package/src/cards/{gist.js → gist.ts} +37 -37
- package/src/cards/{repo.js → repo.ts} +107 -79
- package/src/cards/{stats.js → stats.ts} +173 -210
- package/src/cards/{top-languages.js → top-languages.ts} +325 -243
- package/src/cards/{wakatime.js → wakatime.ts} +158 -127
- package/src/common/Card.ts +123 -43
- package/src/common/I18n.ts +6 -2
- package/src/common/color.ts +240 -28
- package/src/common/config.ts +22 -29
- package/src/common/constants.ts +3 -1
- package/src/common/date.ts +45 -0
- package/src/common/html.ts +1 -1
- package/src/common/http.ts +71 -0
- package/src/common/icons.ts +1 -0
- package/src/common/languageColors.json +10 -1
- package/src/common/languageColors.ts +19 -0
- package/src/common/ops.ts +158 -0
- package/src/common/render.ts +652 -0
- package/src/common/retryer.ts +21 -12
- package/src/fetchers/gist.ts +79 -0
- package/src/fetchers/repo.ts +114 -0
- package/src/fetchers/stats.ts +743 -0
- package/src/fetchers/top-languages.ts +135 -0
- package/src/fetchers/{types.d.ts → types.ts} +28 -20
- package/src/fetchers/{wakatime.js → wakatime.ts} +19 -5
- package/src/graphql/contributionsDocument.ts +44 -0
- package/src/graphql/generated/common.ts +26 -0
- package/src/graphql/generated/gist.ts +59 -0
- package/src/graphql/generated/repo.ts +90 -0
- package/src/graphql/generated/stats.ts +194 -0
- package/src/graphql/generated/top-languages.ts +75 -0
- package/src/graphql/graphqlDocument.ts +25 -0
- package/src/graphql/queries/gist.graphql +25 -0
- package/src/graphql/queries/repo.graphql +28 -0
- package/src/graphql/queries/stats.graphql +120 -0
- package/src/graphql/queries/top-languages.graphql +34 -0
- package/src/graphql/reposContributedToDocument.ts +86 -0
- package/src/index.ts +3 -1
- package/src/themes/index.ts +33 -0
- package/src/translations.ts +17 -0
- package/src/cards/types.d.ts +0 -78
- package/src/common/http.js +0 -19
- package/src/common/ops.js +0 -170
- package/src/common/render.js +0 -440
- package/src/fetchers/gist.js +0 -112
- package/src/fetchers/repo.js +0 -161
- package/src/fetchers/stats.js +0 -474
- package/src/fetchers/top-languages.js +0 -175
- package/src/themes/README.md +0 -229
package/build/common/Card.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getCardColors, isPrefixedHexColor, isValidGradient } from "./color.js";
|
|
1
2
|
import { encodeHTML } from "./html.js";
|
|
2
3
|
import { flexLayout } from "./render.js";
|
|
3
4
|
class Card {
|
|
@@ -9,6 +10,7 @@ class Card {
|
|
|
9
10
|
colors;
|
|
10
11
|
title;
|
|
11
12
|
css;
|
|
13
|
+
darkCss;
|
|
12
14
|
paddingX;
|
|
13
15
|
paddingY;
|
|
14
16
|
titlePrefixIcon;
|
|
@@ -18,25 +20,29 @@ class Card {
|
|
|
18
20
|
/**
|
|
19
21
|
* Creates a new card instance.
|
|
20
22
|
*
|
|
23
|
+
* The caller must ensure that the passed `titlePrefixIcon` is properly sanitized!
|
|
24
|
+
*
|
|
21
25
|
* @param props Card arguments.
|
|
22
26
|
* @param props.width Card width.
|
|
23
27
|
* @param props.height Card height.
|
|
24
28
|
* @param props.border_radius Card border radius.
|
|
25
|
-
* @param props.colors Card colors
|
|
29
|
+
* @param props.colors Card colors for light and dark mode.
|
|
30
|
+
* @param props.colors.light Card colors for light mode.
|
|
31
|
+
* @param props.colors.dark Card colors for dark mode, or `null` when no dark-mode override is needed.
|
|
26
32
|
* @param props.customTitle Card custom title.
|
|
27
33
|
* @param props.defaultTitle Card default title.
|
|
28
|
-
* @param props.titlePrefixIcon
|
|
34
|
+
* @param props.titlePrefixIcon Sanitized card title prefix icon.
|
|
29
35
|
*/
|
|
30
|
-
constructor({ width = 100, height = 100, border_radius = 4.5, colors = {}, customTitle, defaultTitle = "", titlePrefixIcon, }) {
|
|
36
|
+
constructor({ width = 100, height = 100, border_radius = 4.5, colors = { light: getCardColors({}), dark: null }, customTitle, defaultTitle = "", titlePrefixIcon, }) {
|
|
31
37
|
this.width = width;
|
|
32
38
|
this.height = height;
|
|
33
39
|
this.hideBorder = false;
|
|
34
40
|
this.hideTitle = false;
|
|
35
|
-
this.border_radius = border_radius;
|
|
36
|
-
// returns theme based colors with proper overrides and defaults
|
|
41
|
+
this.border_radius = parseFloat(String(border_radius));
|
|
37
42
|
this.colors = colors;
|
|
38
|
-
this.title =
|
|
43
|
+
this.title = customTitle === undefined ? defaultTitle : customTitle;
|
|
39
44
|
this.css = "";
|
|
45
|
+
this.darkCss = "";
|
|
40
46
|
this.paddingX = 25;
|
|
41
47
|
this.paddingY = 35;
|
|
42
48
|
this.titlePrefixIcon = titlePrefixIcon;
|
|
@@ -57,10 +63,17 @@ class Card {
|
|
|
57
63
|
this.a11yDesc = desc;
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
*
|
|
66
|
+
* Sets the card CSS for light and dark mode.
|
|
67
|
+
*
|
|
68
|
+
* The caller must ensure that the passed CSS strings are properly sanitized!
|
|
69
|
+
*
|
|
70
|
+
* @param props The props object.
|
|
71
|
+
* @param props.light CSS applied unconditionally (light/default mode).
|
|
72
|
+
* @param props.dark CSS placed inside a `@media (prefers-color-scheme: dark)` block. Pass `null` when not needed.
|
|
61
73
|
*/
|
|
62
|
-
setCSS(
|
|
63
|
-
this.css =
|
|
74
|
+
setCSS({ light, dark }) {
|
|
75
|
+
this.css = light;
|
|
76
|
+
this.darkCss = dark ?? "";
|
|
64
77
|
}
|
|
65
78
|
/**
|
|
66
79
|
* @param value Whether to hide the border or not.
|
|
@@ -72,10 +85,13 @@ class Card {
|
|
|
72
85
|
* @param value Whether to hide the title or not.
|
|
73
86
|
*/
|
|
74
87
|
setHideTitle(value) {
|
|
75
|
-
this.hideTitle
|
|
76
|
-
if (value) {
|
|
88
|
+
if (value && !this.hideTitle) {
|
|
77
89
|
this.height -= 30;
|
|
78
90
|
}
|
|
91
|
+
if (!value && this.hideTitle) {
|
|
92
|
+
this.height += 30;
|
|
93
|
+
}
|
|
94
|
+
this.hideTitle = value;
|
|
79
95
|
}
|
|
80
96
|
/**
|
|
81
97
|
* @param text The title to set.
|
|
@@ -93,7 +109,7 @@ class Card {
|
|
|
93
109
|
y="0"
|
|
94
110
|
class="header"
|
|
95
111
|
data-testid="header"
|
|
96
|
-
>${this.title}</text>
|
|
112
|
+
>${encodeHTML(this.title)}</text>
|
|
97
113
|
`;
|
|
98
114
|
const prefixIcon = `
|
|
99
115
|
<svg
|
|
@@ -124,16 +140,12 @@ class Card {
|
|
|
124
140
|
* @returns The rendered card gradient.
|
|
125
141
|
*/
|
|
126
142
|
renderGradient() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const gradients = this.colors.bgColor.slice(1);
|
|
131
|
-
return typeof this.colors.bgColor === "object"
|
|
132
|
-
? `
|
|
133
|
-
<defs>
|
|
143
|
+
const buildGradientDef = (id, bgColor) => {
|
|
144
|
+
const gradients = bgColor.slice(1);
|
|
145
|
+
return `
|
|
134
146
|
<linearGradient
|
|
135
|
-
id="
|
|
136
|
-
gradientTransform="rotate(${String(
|
|
147
|
+
id="${id}"
|
|
148
|
+
gradientTransform="rotate(${String(bgColor[0])})"
|
|
137
149
|
gradientUnits="userSpaceOnUse"
|
|
138
150
|
>
|
|
139
151
|
${gradients
|
|
@@ -142,10 +154,23 @@ class Card {
|
|
|
142
154
|
return `<stop offset="${offset}%" stop-color="#${grad}" />`;
|
|
143
155
|
})
|
|
144
156
|
.join(",")}
|
|
145
|
-
</linearGradient
|
|
157
|
+
</linearGradient>`;
|
|
158
|
+
};
|
|
159
|
+
if (typeof this.colors.light.bgColor === "object" &&
|
|
160
|
+
!isValidGradient(this.colors.light.bgColor)) {
|
|
161
|
+
throw new Error(`Invalid gradient: ${this.colors.light.bgColor.join(",")}`);
|
|
162
|
+
}
|
|
163
|
+
if (this.colors.dark &&
|
|
164
|
+
typeof this.colors.dark.bgColor === "object" &&
|
|
165
|
+
!isValidGradient(this.colors.dark.bgColor)) {
|
|
166
|
+
throw new Error(`Invalid dark gradient: ${this.colors.dark.bgColor.join(",")}`);
|
|
167
|
+
}
|
|
168
|
+
return `
|
|
169
|
+
<defs>
|
|
170
|
+
${typeof this.colors.light.bgColor === "object" ? buildGradientDef("gradient", this.colors.light.bgColor) : ""}
|
|
171
|
+
${this.colors.dark && typeof this.colors.dark.bgColor === "object" ? buildGradientDef("gradient-dark", this.colors.dark.bgColor) : ""}
|
|
146
172
|
</defs>
|
|
147
|
-
|
|
148
|
-
: "";
|
|
173
|
+
`;
|
|
149
174
|
}
|
|
150
175
|
/**
|
|
151
176
|
* Retrieves css animations for a card.
|
|
@@ -174,10 +199,44 @@ class Card {
|
|
|
174
199
|
`;
|
|
175
200
|
};
|
|
176
201
|
/**
|
|
177
|
-
* @
|
|
202
|
+
* Builds the @media (prefers-color-scheme: dark) CSS block for the card.
|
|
203
|
+
* Returns an empty string when no dark colors are set.
|
|
204
|
+
*/
|
|
205
|
+
renderDarkMediaBlock() {
|
|
206
|
+
if (!this.colors.dark) {
|
|
207
|
+
return "";
|
|
208
|
+
}
|
|
209
|
+
const bgFill = typeof this.colors.dark.bgColor === "object"
|
|
210
|
+
? "url(#gradient-dark)"
|
|
211
|
+
: this.colors.dark.bgColor;
|
|
212
|
+
return `
|
|
213
|
+
@media (prefers-color-scheme: dark) {
|
|
214
|
+
.header { fill: ${this.colors.dark.titleColor}; }
|
|
215
|
+
.card-bg { fill: ${bgFill}; stroke: ${this.colors.dark.borderColor}; }
|
|
216
|
+
${this.darkCss}
|
|
217
|
+
}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The caller must ensure that the passed `body` string is properly sanitized!
|
|
221
|
+
*
|
|
222
|
+
* @param body The sanitized inner body of the card.
|
|
178
223
|
* @returns The rendered card.
|
|
179
224
|
*/
|
|
180
225
|
render(body) {
|
|
226
|
+
if (!Number.isFinite(this.border_radius)) {
|
|
227
|
+
throw new Error(`Invalid border radius: "${this.border_radius}"`);
|
|
228
|
+
}
|
|
229
|
+
if (!isPrefixedHexColor(this.colors.light.titleColor)) {
|
|
230
|
+
throw new Error(`Invalid title color: "${this.colors.light.titleColor}"`);
|
|
231
|
+
}
|
|
232
|
+
if (!isPrefixedHexColor(this.colors.light.borderColor)) {
|
|
233
|
+
throw new Error(`Invalid border color: "${this.colors.light.borderColor}"`);
|
|
234
|
+
}
|
|
235
|
+
if (!(typeof this.colors.light.bgColor === "object"
|
|
236
|
+
? isValidGradient(this.colors.light.bgColor)
|
|
237
|
+
: isPrefixedHexColor(this.colors.light.bgColor))) {
|
|
238
|
+
throw new Error(`Invalid background color: ${String(this.colors.light.bgColor)}`);
|
|
239
|
+
}
|
|
181
240
|
return `
|
|
182
241
|
<svg
|
|
183
242
|
width="${this.width}"
|
|
@@ -188,12 +247,12 @@ class Card {
|
|
|
188
247
|
role="img"
|
|
189
248
|
aria-labelledby="descId"
|
|
190
249
|
>
|
|
191
|
-
<title id="titleId">${this.a11yTitle}</title>
|
|
192
|
-
<desc id="descId">${this.a11yDesc}</desc>
|
|
250
|
+
<title id="titleId">${encodeHTML(this.a11yTitle)}</title>
|
|
251
|
+
<desc id="descId">${encodeHTML(this.a11yDesc)}</desc>
|
|
193
252
|
<style>
|
|
194
253
|
.header {
|
|
195
254
|
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
|
|
196
|
-
fill: ${
|
|
255
|
+
fill: ${this.colors.light.titleColor};
|
|
197
256
|
animation: fadeInAnimation 0.8s ease-in-out forwards;
|
|
198
257
|
}
|
|
199
258
|
@supports(-moz-appearance: auto) {
|
|
@@ -201,6 +260,7 @@ class Card {
|
|
|
201
260
|
.header { font-size: 15.5px; }
|
|
202
261
|
}
|
|
203
262
|
${this.css}
|
|
263
|
+
${this.renderDarkMediaBlock()}
|
|
204
264
|
|
|
205
265
|
${this.getAnimations()}
|
|
206
266
|
${this.animations
|
|
@@ -212,15 +272,16 @@ class Card {
|
|
|
212
272
|
|
|
213
273
|
<rect
|
|
214
274
|
data-testid="card-bg"
|
|
275
|
+
class="card-bg"
|
|
215
276
|
x="0.5"
|
|
216
277
|
y="0.5"
|
|
217
278
|
rx="${this.border_radius}"
|
|
218
279
|
height="99%"
|
|
219
|
-
stroke="${
|
|
280
|
+
stroke="${this.colors.light.borderColor}"
|
|
220
281
|
width="${this.width - 1}"
|
|
221
|
-
fill="${typeof this.colors.bgColor === "object"
|
|
282
|
+
fill="${typeof this.colors.light.bgColor === "object"
|
|
222
283
|
? "url(#gradient)"
|
|
223
|
-
:
|
|
284
|
+
: this.colors.light.bgColor}"
|
|
224
285
|
stroke-opacity="${this.hideBorder ? 0 : 1}"
|
|
225
286
|
/>
|
|
226
287
|
|
package/build/common/I18n.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/** A map of translation keys to per-locale strings. */
|
|
2
|
+
type TranslationsMap = Record<string, Record<string, string>>;
|
|
1
3
|
/**
|
|
2
4
|
* I18n translation class.
|
|
3
5
|
*/
|
|
4
|
-
declare class I18n<Translations extends
|
|
6
|
+
declare class I18n<Translations extends TranslationsMap = TranslationsMap> {
|
|
5
7
|
locale: string;
|
|
6
8
|
translations: Translations;
|
|
7
9
|
/**
|
|
@@ -10,7 +12,7 @@ declare class I18n<Translations extends Record<string, Record<string, string>>>
|
|
|
10
12
|
* @param props.translations Translations.
|
|
11
13
|
*/
|
|
12
14
|
constructor({ locale, translations, }: {
|
|
13
|
-
locale?: string;
|
|
15
|
+
locale?: string | undefined;
|
|
14
16
|
translations: Translations;
|
|
15
17
|
});
|
|
16
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18n.d.ts","sourceRoot":"","sources":["../../src/common/I18n.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"I18n.d.ts","sourceRoot":"","sources":["../../src/common/I18n.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D;;GAEG;AACH,cAAM,IAAI,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAE3B;;;;OAIG;gBACS,EACV,MAAM,EACN,YAAY,GACb,EAAE;QAED,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,YAAY,EAAE,YAAY,CAAC;KAC5B;IAKD;;;;;OAKG;IACH,CAAC,CAAC,GAAG,EAAE,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM;CAe5C;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/build/common/color.d.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Checks if a value is a bare hex color, i.e. hex digits with no `#` prefix
|
|
3
|
+
* (`"f00"`, `"ffffff"`). This is the form user-supplied color params and
|
|
4
|
+
* gradient stops arrive in.
|
|
3
5
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
6
|
-
* @returns The gradient or color.
|
|
6
|
+
* @param value Value to check.
|
|
7
|
+
* @returns True if the value is a bare hex color.
|
|
7
8
|
*/
|
|
8
|
-
declare const
|
|
9
|
+
declare const isBareHexColor: (value: unknown) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a value is a `#`-prefixed hex color (`"#f00"`, `"#ffffff"`). This
|
|
12
|
+
* is the form colors take once resolved by {@link getCardColors}, i.e. right
|
|
13
|
+
* before they are written into the SVG.
|
|
14
|
+
*
|
|
15
|
+
* @param value Value to check.
|
|
16
|
+
* @returns True if the value is a `#`-prefixed hex color.
|
|
17
|
+
*/
|
|
18
|
+
declare const isPrefixedHexColor: (value: unknown) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the given parts form a valid gradient: a finite numeric angle
|
|
21
|
+
* followed by at least two bare-hex color stops, e.g. `["90", "f00", "0f0"]`.
|
|
22
|
+
* The angle is written into the SVG `gradientTransform="rotate(...)"`.
|
|
23
|
+
*
|
|
24
|
+
* @param parts Gradient parts: `[angle, ...stops]`.
|
|
25
|
+
* @returns True if the parts form a valid gradient.
|
|
26
|
+
*/
|
|
27
|
+
declare const isValidGradient: (parts: Array<string>) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Iterates over a collection of colors inputs and verifies that each is a valid color or gradient.
|
|
30
|
+
*
|
|
31
|
+
* @param colors Object whose values are checked as valid color inputs.
|
|
32
|
+
* @return The first key where the associated input value is not valid. null if all inputs are valid.
|
|
33
|
+
*/
|
|
34
|
+
declare const findInvalidColor: (colors: Record<string, string | null | undefined>) => string | null;
|
|
9
35
|
/**
|
|
10
36
|
* Object containing card colors.
|
|
11
37
|
*/
|
|
@@ -16,7 +42,24 @@ interface CardColors {
|
|
|
16
42
|
bgColor: string | Array<string>;
|
|
17
43
|
borderColor: string;
|
|
18
44
|
ringColor: string;
|
|
45
|
+
progBarBgColor: string;
|
|
19
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Every color param a card accepts, before any `_light` / `_dark` suffix.
|
|
49
|
+
*
|
|
50
|
+
* Single source of truth: the param types and {@link COLOR_PARAM_KEYS} are all
|
|
51
|
+
* derived from this, so adding a param here is enough.
|
|
52
|
+
*/
|
|
53
|
+
declare const BASE_COLOR_KEYS: readonly ["title_color", "icon_color", "text_color", "bg_color", "border_color", "ring_color", "prog_bar_bg_color", "theme"];
|
|
54
|
+
declare const THEME_VARIANTS: readonly ["light", "dark"];
|
|
55
|
+
type BaseColorKey = (typeof BASE_COLOR_KEYS)[number];
|
|
56
|
+
type ThemeVariant = (typeof THEME_VARIANTS)[number];
|
|
57
|
+
/**
|
|
58
|
+
* Object with all input color params. Not every field is consumed by every card
|
|
59
|
+
* (e.g. `prog_bar_bg_color` is only used by the top-languages card's `normal`
|
|
60
|
+
* layout).
|
|
61
|
+
*/
|
|
62
|
+
type ColorInput = Partial<Record<BaseColorKey, string | undefined>>;
|
|
20
63
|
/**
|
|
21
64
|
* Returns theme based colors with proper overrides and defaults.
|
|
22
65
|
*
|
|
@@ -27,17 +70,50 @@ interface CardColors {
|
|
|
27
70
|
* @param props.bg_color Card background color.
|
|
28
71
|
* @param props.border_color Card border color.
|
|
29
72
|
* @param props.ring_color Card ring color.
|
|
73
|
+
* @param props.prog_bar_bg_color Progress bar background color.
|
|
30
74
|
* @param props.theme Card theme.
|
|
31
75
|
* @returns Card colors.
|
|
32
76
|
*/
|
|
33
|
-
declare const getCardColors: ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, theme, }:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
77
|
+
declare const getCardColors: ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, prog_bar_bg_color, theme, }: ColorInput) => CardColors;
|
|
78
|
+
type LightDarkColorParams = Partial<Record<`${BaseColorKey}_${ThemeVariant}`, string | undefined>>;
|
|
79
|
+
/**
|
|
80
|
+
* Returns resolved colors for both light and dark mode given all input params.
|
|
81
|
+
*
|
|
82
|
+
* Each mode resolves independently, then runs the normal `getCardColors` precedence
|
|
83
|
+
* (explicit color -> theme color -> default theme):
|
|
84
|
+
* light: `theme_light ?? theme`, with `*_light` params overriding general ones
|
|
85
|
+
* dark: `theme_dark ?? theme`, with `*_dark` params overriding general ones
|
|
86
|
+
*
|
|
87
|
+
* Anything a mode does not override falls back to the general params,
|
|
88
|
+
* so a partial override such as `bg_color_dark` alone keeps every other color from the base theme.
|
|
89
|
+
*
|
|
90
|
+
* When no `_light` / `_dark` param is provided at all, `darkColors` is `null` and the caller emits no dark-mode block.
|
|
91
|
+
*
|
|
92
|
+
* @param params Raw query params, containing both general and `_light`/`_dark` suffixed colors and themes.
|
|
93
|
+
* @returns `{ lightColors, darkColors }`, resolved colors for both light and dark mode
|
|
94
|
+
*/
|
|
95
|
+
declare const getLightDarkColors: (params: ColorInput & LightDarkColorParams) => {
|
|
96
|
+
lightColors: CardColors;
|
|
97
|
+
darkColors: CardColors | null;
|
|
98
|
+
};
|
|
99
|
+
type ColorParams = ColorInput & LightDarkColorParams;
|
|
100
|
+
declare const COLOR_PARAM_KEYS: ReadonlyArray<keyof ColorParams>;
|
|
101
|
+
/**
|
|
102
|
+
* Picks all color-related parameters from a query object.
|
|
103
|
+
*
|
|
104
|
+
* @param query Raw query parameters.
|
|
105
|
+
* @returns All color-related parameters.
|
|
106
|
+
*/
|
|
107
|
+
declare const pickColorParams: (query: Record<string, string | undefined>) => ColorParams;
|
|
108
|
+
/**
|
|
109
|
+
* Finds the first color param holding an invalid color.
|
|
110
|
+
*
|
|
111
|
+
* Theme params are skipped: they name a theme, and an unknown name falls back
|
|
112
|
+
* to the default rather than being an error.
|
|
113
|
+
*
|
|
114
|
+
* @param params Color params, as returned by {@link pickColorParams}.
|
|
115
|
+
* @returns The first invalid param name, or null if all are valid.
|
|
116
|
+
*/
|
|
117
|
+
declare const findInvalidColorParam: (params: ColorParams) => string | null;
|
|
118
|
+
export { getCardColors, getLightDarkColors, findInvalidColor, findInvalidColorParam, pickColorParams, isValidGradient, isBareHexColor, isPrefixedHexColor, BASE_COLOR_KEYS, THEME_VARIANTS, COLOR_PARAM_KEYS, };
|
|
43
119
|
//# sourceMappingURL=color.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/common/color.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/common/color.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,QAAA,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,OAExC,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,kBAAkB,GAAI,OAAO,OAAO,KAAG,OAM5C,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,eAAe,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,OAS/C,CAAC;AAeF;;;;;GAKG;AACH,QAAA,MAAM,gBAAgB,GACpB,QAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,KAChD,MAAM,GAAG,IAOX,CAAC;AAyBF;;GAEG;AACH,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,QAAA,MAAM,eAAe,8HASX,CAAC;AAEX,QAAA,MAAM,cAAc,4BAA6B,CAAC;AAElD,KAAK,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,KAAK,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpD;;;;GAIG;AACH,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,aAAa,GAAI,wGASpB,UAAU,KAAG,UAkEf,CAAC;AAEF,KAAK,oBAAoB,GAAG,OAAO,CACjC,MAAM,CAAC,GAAG,YAAY,IAAI,YAAY,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC,CAC9D,CAAC;AAkBF;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,kBAAkB,GACtB,QAAQ,UAAU,GAAG,oBAAoB,KACxC;IAAE,WAAW,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAA;CAmB1D,CAAC;AAEF,KAAK,WAAW,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAErD,QAAA,MAAM,gBAAgB,EAAE,aAAa,CAAC,MAAM,WAAW,CAKtD,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,eAAe,GACnB,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KACxC,WAGA,CAAC;AAQJ;;;;;;;;GAQG;AACH,QAAA,MAAM,qBAAqB,GAAI,QAAQ,WAAW,KAAG,MAAM,GAAG,IAO3D,CAAC;AAEJ,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,cAAc,EACd,kBAAkB,EAIlB,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,CAAC"}
|
package/build/common/color.js
CHANGED
|
@@ -1,22 +1,71 @@
|
|
|
1
1
|
import { themes } from "../themes/index.js";
|
|
2
|
+
/** Matches a 3-, 4-, 6-, or 8-digit hex color with no leading `#`. */
|
|
3
|
+
const HEX_COLOR = /^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{3})$/;
|
|
2
4
|
/**
|
|
3
|
-
* Checks if a
|
|
5
|
+
* Checks if a value is a bare hex color, i.e. hex digits with no `#` prefix
|
|
6
|
+
* (`"f00"`, `"ffffff"`). This is the form user-supplied color params and
|
|
7
|
+
* gradient stops arrive in.
|
|
4
8
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @returns True if the
|
|
9
|
+
* @param value Value to check.
|
|
10
|
+
* @returns True if the value is a bare hex color.
|
|
7
11
|
*/
|
|
8
|
-
const
|
|
9
|
-
return
|
|
12
|
+
const isBareHexColor = (value) => {
|
|
13
|
+
return typeof value === "string" && HEX_COLOR.test(value);
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
|
-
*
|
|
16
|
+
* Checks if a value is a `#`-prefixed hex color (`"#f00"`, `"#ffffff"`). This
|
|
17
|
+
* is the form colors take once resolved by {@link getCardColors}, i.e. right
|
|
18
|
+
* before they are written into the SVG.
|
|
13
19
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @returns True if the
|
|
20
|
+
* @param value Value to check.
|
|
21
|
+
* @returns True if the value is a `#`-prefixed hex color.
|
|
16
22
|
*/
|
|
17
|
-
const
|
|
18
|
-
return (
|
|
19
|
-
|
|
23
|
+
const isPrefixedHexColor = (value) => {
|
|
24
|
+
return (typeof value === "string" &&
|
|
25
|
+
value.startsWith("#") &&
|
|
26
|
+
HEX_COLOR.test(value.slice(1)));
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the given parts form a valid gradient: a finite numeric angle
|
|
30
|
+
* followed by at least two bare-hex color stops, e.g. `["90", "f00", "0f0"]`.
|
|
31
|
+
* The angle is written into the SVG `gradientTransform="rotate(...)"`.
|
|
32
|
+
*
|
|
33
|
+
* @param parts Gradient parts: `[angle, ...stops]`.
|
|
34
|
+
* @returns True if the parts form a valid gradient.
|
|
35
|
+
*/
|
|
36
|
+
const isValidGradient = (parts) => {
|
|
37
|
+
const [angle, ...stops] = parts;
|
|
38
|
+
return (stops.length >= 2 &&
|
|
39
|
+
angle !== undefined &&
|
|
40
|
+
angle.trim() !== "" &&
|
|
41
|
+
Number.isFinite(Number(angle)) &&
|
|
42
|
+
stops.every(isBareHexColor));
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a string is a valid input for a color or gradient.
|
|
46
|
+
*
|
|
47
|
+
* @param color String to check, may be null or undefined.
|
|
48
|
+
* @returns True if the given string is a valid input.
|
|
49
|
+
*/
|
|
50
|
+
const isValidColorInput = (color) => {
|
|
51
|
+
if (color === null || color === undefined) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return isValidGradient(color.split(",")) || isBareHexColor(color);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Iterates over a collection of colors inputs and verifies that each is a valid color or gradient.
|
|
58
|
+
*
|
|
59
|
+
* @param colors Object whose values are checked as valid color inputs.
|
|
60
|
+
* @return The first key where the associated input value is not valid. null if all inputs are valid.
|
|
61
|
+
*/
|
|
62
|
+
const findInvalidColor = (colors) => {
|
|
63
|
+
for (const [key, value] of Object.entries(colors)) {
|
|
64
|
+
if (!isValidColorInput(value)) {
|
|
65
|
+
return key;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
20
69
|
};
|
|
21
70
|
/**
|
|
22
71
|
* Retrieves a gradient if color has more than one valid hex codes else a single color.
|
|
@@ -30,11 +79,28 @@ const fallbackColor = (color, fallbackColor) => {
|
|
|
30
79
|
if (colors.length > 1 && isValidGradient(colors)) {
|
|
31
80
|
return colors;
|
|
32
81
|
}
|
|
33
|
-
if (color !== undefined &&
|
|
82
|
+
if (color !== undefined && isBareHexColor(color)) {
|
|
34
83
|
return `#${color}`;
|
|
35
84
|
}
|
|
36
85
|
return fallbackColor;
|
|
37
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Every color param a card accepts, before any `_light` / `_dark` suffix.
|
|
89
|
+
*
|
|
90
|
+
* Single source of truth: the param types and {@link COLOR_PARAM_KEYS} are all
|
|
91
|
+
* derived from this, so adding a param here is enough.
|
|
92
|
+
*/
|
|
93
|
+
const BASE_COLOR_KEYS = [
|
|
94
|
+
"title_color",
|
|
95
|
+
"icon_color",
|
|
96
|
+
"text_color",
|
|
97
|
+
"bg_color",
|
|
98
|
+
"border_color",
|
|
99
|
+
"ring_color",
|
|
100
|
+
"prog_bar_bg_color",
|
|
101
|
+
"theme",
|
|
102
|
+
];
|
|
103
|
+
const THEME_VARIANTS = ["light", "dark"];
|
|
38
104
|
/**
|
|
39
105
|
* Returns theme based colors with proper overrides and defaults.
|
|
40
106
|
*
|
|
@@ -45,10 +111,11 @@ const fallbackColor = (color, fallbackColor) => {
|
|
|
45
111
|
* @param props.bg_color Card background color.
|
|
46
112
|
* @param props.border_color Card border color.
|
|
47
113
|
* @param props.ring_color Card ring color.
|
|
114
|
+
* @param props.prog_bar_bg_color Progress bar background color.
|
|
48
115
|
* @param props.theme Card theme.
|
|
49
116
|
* @returns Card colors.
|
|
50
117
|
*/
|
|
51
|
-
const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, theme, }) => {
|
|
118
|
+
const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, prog_bar_bg_color, theme, }) => {
|
|
52
119
|
const defaultTheme = themes.default;
|
|
53
120
|
const isThemeProvided = theme !== undefined && theme in themes;
|
|
54
121
|
const selectedTheme = isThemeProvided
|
|
@@ -62,19 +129,98 @@ const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_c
|
|
|
62
129
|
const titleColor = fallbackColor(title_color || selectedTheme.title_color, "#" + defaultTheme.title_color);
|
|
63
130
|
// get the color provided by the user else the theme color
|
|
64
131
|
// finally if both colors are invalid we use the titleColor
|
|
65
|
-
// NOTE: no built-in theme defines `ring_color`, so it falls back to the title color.
|
|
66
|
-
const ringColor = fallbackColor(ring_color, titleColor);
|
|
67
132
|
const iconColor = fallbackColor(icon_color || selectedTheme.icon_color, "#" + defaultTheme.icon_color);
|
|
68
133
|
const textColor = fallbackColor(text_color || selectedTheme.text_color, "#" + defaultTheme.text_color);
|
|
69
134
|
const bgColor = fallbackColor(bg_color || selectedTheme.bg_color, "#" + defaultTheme.bg_color);
|
|
70
135
|
const borderColor = fallbackColor(border_color || defaultBorderColor, "#" + defaultBorderColor);
|
|
136
|
+
// No theme defines `ring_color`, so it falls back to the title color.
|
|
137
|
+
const ringColor = fallbackColor(ring_color, titleColor);
|
|
138
|
+
// No theme defines `prog_bar_bg_color`, so it falls back to "#ddd".
|
|
139
|
+
const progBarBgColor = fallbackColor(prog_bar_bg_color, "#ddd");
|
|
71
140
|
if (typeof titleColor !== "string" ||
|
|
72
141
|
typeof textColor !== "string" ||
|
|
73
142
|
typeof ringColor !== "string" ||
|
|
143
|
+
typeof progBarBgColor !== "string" ||
|
|
74
144
|
typeof iconColor !== "string" ||
|
|
75
145
|
typeof borderColor !== "string") {
|
|
76
146
|
throw new Error("Unexpected behavior, all colors except background should be string.");
|
|
77
147
|
}
|
|
78
|
-
return {
|
|
148
|
+
return {
|
|
149
|
+
titleColor,
|
|
150
|
+
iconColor,
|
|
151
|
+
textColor,
|
|
152
|
+
bgColor,
|
|
153
|
+
borderColor,
|
|
154
|
+
ringColor,
|
|
155
|
+
progBarBgColor,
|
|
156
|
+
};
|
|
79
157
|
};
|
|
80
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Returns the light- or dark-mode-specific color params, given a set of
|
|
160
|
+
* raw query params. Also removes the "_light" or "_dark" suffixes.
|
|
161
|
+
*
|
|
162
|
+
* @param params Raw query params with optional `_light` / `_dark` suffixes.
|
|
163
|
+
* @param suffix `"_light"` or `"_dark"`.
|
|
164
|
+
* @returns ColorInput with the suffix stripped, ready for `getCardColors`.
|
|
165
|
+
*/
|
|
166
|
+
const extractLightDarkColors = (params, suffix) => Object.fromEntries(BASE_COLOR_KEYS.map((key) => [key, params[`${key}${suffix}`]]));
|
|
167
|
+
/**
|
|
168
|
+
* Returns resolved colors for both light and dark mode given all input params.
|
|
169
|
+
*
|
|
170
|
+
* Each mode resolves independently, then runs the normal `getCardColors` precedence
|
|
171
|
+
* (explicit color -> theme color -> default theme):
|
|
172
|
+
* light: `theme_light ?? theme`, with `*_light` params overriding general ones
|
|
173
|
+
* dark: `theme_dark ?? theme`, with `*_dark` params overriding general ones
|
|
174
|
+
*
|
|
175
|
+
* Anything a mode does not override falls back to the general params,
|
|
176
|
+
* so a partial override such as `bg_color_dark` alone keeps every other color from the base theme.
|
|
177
|
+
*
|
|
178
|
+
* When no `_light` / `_dark` param is provided at all, `darkColors` is `null` and the caller emits no dark-mode block.
|
|
179
|
+
*
|
|
180
|
+
* @param params Raw query params, containing both general and `_light`/`_dark` suffixed colors and themes.
|
|
181
|
+
* @returns `{ lightColors, darkColors }`, resolved colors for both light and dark mode
|
|
182
|
+
*/
|
|
183
|
+
const getLightDarkColors = (params) => {
|
|
184
|
+
const lightOverrides = extractLightDarkColors(params, "_light");
|
|
185
|
+
const darkOverrides = extractLightDarkColors(params, "_dark");
|
|
186
|
+
const hasModeOverrides = Object.values(lightOverrides).some((v) => v !== undefined) ||
|
|
187
|
+
Object.values(darkOverrides).some((v) => v !== undefined);
|
|
188
|
+
if (!hasModeOverrides) {
|
|
189
|
+
return { lightColors: getCardColors(params), darkColors: null };
|
|
190
|
+
}
|
|
191
|
+
const defined = (obj) => Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
|
|
192
|
+
return {
|
|
193
|
+
lightColors: getCardColors({ ...params, ...defined(lightOverrides) }),
|
|
194
|
+
darkColors: getCardColors({ ...params, ...defined(darkOverrides) }),
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
const COLOR_PARAM_KEYS = [
|
|
198
|
+
...BASE_COLOR_KEYS,
|
|
199
|
+
...THEME_VARIANTS.flatMap((variant) => BASE_COLOR_KEYS.map((key) => `${key}_${variant}`)),
|
|
200
|
+
];
|
|
201
|
+
/**
|
|
202
|
+
* Picks all color-related parameters from a query object.
|
|
203
|
+
*
|
|
204
|
+
* @param query Raw query parameters.
|
|
205
|
+
* @returns All color-related parameters.
|
|
206
|
+
*/
|
|
207
|
+
const pickColorParams = (query) => Object.fromEntries(COLOR_PARAM_KEYS.filter((k) => k in query).map((k) => [k, query[k]]));
|
|
208
|
+
/** Params naming a theme rather than holding a color value. */
|
|
209
|
+
const THEME_PARAM_KEYS = [
|
|
210
|
+
"theme",
|
|
211
|
+
...THEME_VARIANTS.map((variant) => `theme_${variant}`),
|
|
212
|
+
];
|
|
213
|
+
/**
|
|
214
|
+
* Finds the first color param holding an invalid color.
|
|
215
|
+
*
|
|
216
|
+
* Theme params are skipped: they name a theme, and an unknown name falls back
|
|
217
|
+
* to the default rather than being an error.
|
|
218
|
+
*
|
|
219
|
+
* @param params Color params, as returned by {@link pickColorParams}.
|
|
220
|
+
* @returns The first invalid param name, or null if all are valid.
|
|
221
|
+
*/
|
|
222
|
+
const findInvalidColorParam = (params) => findInvalidColor(Object.fromEntries(Object.entries(params).filter(([key]) => !THEME_PARAM_KEYS.includes(key))));
|
|
223
|
+
export { getCardColors, getLightDarkColors, findInvalidColor, findInvalidColorParam, pickColorParams, isValidGradient, isBareHexColor, isPrefixedHexColor,
|
|
224
|
+
// Not re-exported from the package index: internal,
|
|
225
|
+
// exposed so tests can pin the accepted param list.
|
|
226
|
+
BASE_COLOR_KEYS, THEME_VARIANTS, COLOR_PARAM_KEYS, };
|
package/build/common/config.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ interface Config {
|
|
|
7
7
|
whitelist: Array<string> | undefined;
|
|
8
8
|
gistWhitelist: Array<string> | undefined;
|
|
9
9
|
excludeRepositories: Array<string>;
|
|
10
|
-
|
|
10
|
+
/** Max pages of starred repos to fetch; `Infinity` means every page, `1` only the first. */
|
|
11
|
+
fetchMultiPageStars: number;
|
|
11
12
|
pats: Array<PersonalAccessToken>;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/common/config.ts"],"names":[],"mappings":"AAAA,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE9C,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,MAAM;IACd,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACrC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACzC,mBAAmB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/common/config.ts"],"names":[],"mappings":"AAAA,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE9C,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,MAAM;IACd,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACrC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACzC,mBAAmB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,4FAA4F;IAC5F,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;CAClC;AA4CD;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAK,GAAqB,KAAG,IAU9D,CAAC;AAIF,eAAO,MAAM,SAAS,QAAO,MAAuB,CAAC"}
|