@stats-organization/github-readme-stats-core 0.0.1
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/LICENSE +21 -0
- package/README.md +1 -0
- package/build/api/gist.d.ts +19 -0
- package/build/api/gist.d.ts.map +1 -0
- package/build/api/gist.js +77 -0
- package/build/api/index.d.ts +37 -0
- package/build/api/index.d.ts.map +1 -0
- package/build/api/index.js +115 -0
- package/build/api/pin.d.ts +27 -0
- package/build/api/pin.d.ts.map +1 -0
- package/build/api/pin.js +104 -0
- package/build/api/top-langs.d.ts +31 -0
- package/build/api/top-langs.d.ts.map +1 -0
- package/build/api/top-langs.js +121 -0
- package/build/api/wakatime.d.ts +28 -0
- package/build/api/wakatime.d.ts.map +1 -0
- package/build/api/wakatime.js +85 -0
- package/build/calculateRank.d.ts +28 -0
- package/build/calculateRank.d.ts.map +1 -0
- package/build/calculateRank.js +63 -0
- package/build/cards/gist.d.ts +21 -0
- package/build/cards/gist.d.ts.map +1 -0
- package/build/cards/gist.js +124 -0
- package/build/cards/repo.d.ts +21 -0
- package/build/cards/repo.d.ts.map +1 -0
- package/build/cards/repo.js +264 -0
- package/build/cards/stats.d.ts +49 -0
- package/build/cards/stats.d.ts.map +1 -0
- package/build/cards/stats.js +527 -0
- package/build/cards/top-languages.d.ts +143 -0
- package/build/cards/top-languages.d.ts.map +1 -0
- package/build/cards/top-languages.js +795 -0
- package/build/cards/wakatime.d.ts +16 -0
- package/build/cards/wakatime.d.ts.map +1 -0
- package/build/cards/wakatime.js +387 -0
- package/build/common/Card.d.ts +109 -0
- package/build/common/Card.d.ts.map +1 -0
- package/build/common/Card.js +241 -0
- package/build/common/I18n.d.ts +26 -0
- package/build/common/I18n.d.ts.map +1 -0
- package/build/common/I18n.js +34 -0
- package/build/common/color.d.ts +53 -0
- package/build/common/color.d.ts.map +1 -0
- package/build/common/color.js +92 -0
- package/build/common/config.d.ts +3 -0
- package/build/common/config.d.ts.map +1 -0
- package/build/common/config.js +69 -0
- package/build/common/constants.d.ts +6 -0
- package/build/common/constants.d.ts.map +1 -0
- package/build/common/constants.js +7 -0
- package/build/common/error.d.ts +53 -0
- package/build/common/error.d.ts.map +1 -0
- package/build/common/error.js +72 -0
- package/build/common/fmt.d.ts +27 -0
- package/build/common/fmt.d.ts.map +1 -0
- package/build/common/fmt.js +66 -0
- package/build/common/html.d.ts +10 -0
- package/build/common/html.d.ts.map +1 -0
- package/build/common/html.js +18 -0
- package/build/common/http.d.ts +9 -0
- package/build/common/http.d.ts.map +1 -0
- package/build/common/http.js +18 -0
- package/build/common/icons.d.ts +26 -0
- package/build/common/icons.d.ts.map +1 -0
- package/build/common/icons.js +77 -0
- package/build/common/languageColors.json +667 -0
- package/build/common/log.d.ts +9 -0
- package/build/common/log.d.ts.map +1 -0
- package/build/common/log.js +8 -0
- package/build/common/ops.d.ts +65 -0
- package/build/common/ops.d.ts.map +1 -0
- package/build/common/ops.js +137 -0
- package/build/common/render.d.ts +155 -0
- package/build/common/render.d.ts.map +1 -0
- package/build/common/render.js +361 -0
- package/build/common/retryer.d.ts +22 -0
- package/build/common/retryer.d.ts.map +1 -0
- package/build/common/retryer.js +86 -0
- package/build/fetchers/gist.d.ts +26 -0
- package/build/fetchers/gist.d.ts.map +1 -0
- package/build/fetchers/gist.js +99 -0
- package/build/fetchers/repo.d.ts +16 -0
- package/build/fetchers/repo.d.ts.map +1 -0
- package/build/fetchers/repo.js +116 -0
- package/build/fetchers/stats.d.ts +22 -0
- package/build/fetchers/stats.d.ts.map +1 -0
- package/build/fetchers/stats.js +339 -0
- package/build/fetchers/top-languages.d.ts +20 -0
- package/build/fetchers/top-languages.d.ts.map +1 -0
- package/build/fetchers/top-languages.js +139 -0
- package/build/fetchers/wakatime.d.ts +11 -0
- package/build/fetchers/wakatime.d.ts.map +1 -0
- package/build/fetchers/wakatime.js +25 -0
- package/build/index.d.ts +20 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +19 -0
- package/build/themes/index.d.ts +469 -0
- package/build/themes/index.d.ts.map +1 -0
- package/build/themes/index.js +468 -0
- package/build/translations.d.ts +533 -0
- package/build/translations.d.ts.map +1 -0
- package/build/translations.js +1140 -0
- package/package.json +94 -0
- package/src/api/gist.js +99 -0
- package/src/api/index.js +185 -0
- package/src/api/pin.js +146 -0
- package/src/api/top-langs.js +168 -0
- package/src/api/wakatime.js +113 -0
- package/src/calculateRank.js +86 -0
- package/src/cards/gist.js +187 -0
- package/src/cards/repo.js +365 -0
- package/src/cards/stats.js +673 -0
- package/src/cards/top-languages.js +1023 -0
- package/src/cards/types.d.ts +78 -0
- package/src/cards/wakatime.js +471 -0
- package/src/common/Card.js +275 -0
- package/src/common/I18n.js +42 -0
- package/src/common/color.js +145 -0
- package/src/common/config.js +78 -0
- package/src/common/constants.js +9 -0
- package/src/common/error.js +90 -0
- package/src/common/fmt.js +80 -0
- package/src/common/html.js +22 -0
- package/src/common/http.js +21 -0
- package/src/common/icons.js +81 -0
- package/src/common/languageColors.json +667 -0
- package/src/common/log.ts +12 -0
- package/src/common/ops.js +172 -0
- package/src/common/render.js +442 -0
- package/src/common/retryer.js +104 -0
- package/src/fetchers/gist.js +114 -0
- package/src/fetchers/repo.js +165 -0
- package/src/fetchers/stats.js +478 -0
- package/src/fetchers/top-languages.js +177 -0
- package/src/fetchers/types.d.ts +128 -0
- package/src/fetchers/wakatime.js +37 -0
- package/src/index.ts +25 -0
- package/src/themes/README.md +229 -0
- package/src/themes/index.ts +476 -0
- package/src/translations.js +1156 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { encodeHTML } from "./html.js";
|
|
3
|
+
import { flexLayout } from "./render.js";
|
|
4
|
+
class Card {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new card instance.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} args Card arguments.
|
|
9
|
+
* @param {number=} args.width Card width.
|
|
10
|
+
* @param {number=} args.height Card height.
|
|
11
|
+
* @param {number=} args.border_radius Card border radius.
|
|
12
|
+
* @param {string=} args.customTitle Card custom title.
|
|
13
|
+
* @param {string=} args.defaultTitle Card default title.
|
|
14
|
+
* @param {string=} args.titlePrefixIcon Card title prefix icon.
|
|
15
|
+
* @param {object} [args.colors={}] Card colors arguments.
|
|
16
|
+
* @param {string=} args.colors.titleColor Card title color.
|
|
17
|
+
* @param {string=} args.colors.textColor Card text color.
|
|
18
|
+
* @param {string=} args.colors.iconColor Card icon color.
|
|
19
|
+
* @param {string|string[]=} args.colors.bgColor Card background color.
|
|
20
|
+
* @param {string=} args.colors.borderColor Card border color.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ width = 100, height = 100, border_radius = 4.5, colors = {}, customTitle, defaultTitle = "", titlePrefixIcon, }) {
|
|
23
|
+
this.width = width;
|
|
24
|
+
this.height = height;
|
|
25
|
+
this.hideBorder = false;
|
|
26
|
+
this.hideTitle = false;
|
|
27
|
+
this.border_radius = border_radius;
|
|
28
|
+
// returns theme based colors with proper overrides and defaults
|
|
29
|
+
this.colors = colors;
|
|
30
|
+
this.title =
|
|
31
|
+
customTitle === undefined
|
|
32
|
+
? encodeHTML(defaultTitle)
|
|
33
|
+
: encodeHTML(customTitle);
|
|
34
|
+
this.css = "";
|
|
35
|
+
this.paddingX = 25;
|
|
36
|
+
this.paddingY = 35;
|
|
37
|
+
this.titlePrefixIcon = titlePrefixIcon;
|
|
38
|
+
this.animations = true;
|
|
39
|
+
this.a11yTitle = "";
|
|
40
|
+
this.a11yDesc = "";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @returns {void}
|
|
44
|
+
*/
|
|
45
|
+
disableAnimations() {
|
|
46
|
+
this.animations = false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param {Object} props The props object.
|
|
50
|
+
* @param {string} props.title Accessibility title.
|
|
51
|
+
* @param {string} props.desc Accessibility description.
|
|
52
|
+
* @returns {void}
|
|
53
|
+
*/
|
|
54
|
+
setAccessibilityLabel({ title, desc }) {
|
|
55
|
+
this.a11yTitle = title;
|
|
56
|
+
this.a11yDesc = desc;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} value The CSS to add to the card.
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/
|
|
62
|
+
setCSS(value) {
|
|
63
|
+
this.css = value;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @param {boolean} value Whether to hide the border or not.
|
|
67
|
+
* @returns {void}
|
|
68
|
+
*/
|
|
69
|
+
setHideBorder(value) {
|
|
70
|
+
this.hideBorder = value;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @param {boolean} value Whether to hide the title or not.
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
setHideTitle(value) {
|
|
77
|
+
this.hideTitle = value;
|
|
78
|
+
if (value) {
|
|
79
|
+
this.height -= 30;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} text The title to set.
|
|
84
|
+
* @returns {void}
|
|
85
|
+
*/
|
|
86
|
+
setTitle(text) {
|
|
87
|
+
this.title = text;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @returns {string} The rendered card title.
|
|
91
|
+
*/
|
|
92
|
+
renderTitle() {
|
|
93
|
+
const titleText = `
|
|
94
|
+
<text
|
|
95
|
+
x="0"
|
|
96
|
+
y="0"
|
|
97
|
+
class="header"
|
|
98
|
+
data-testid="header"
|
|
99
|
+
>${this.title}</text>
|
|
100
|
+
`;
|
|
101
|
+
const prefixIcon = `
|
|
102
|
+
<svg
|
|
103
|
+
class="icon"
|
|
104
|
+
x="0"
|
|
105
|
+
y="-13"
|
|
106
|
+
viewBox="0 0 16 16"
|
|
107
|
+
version="1.1"
|
|
108
|
+
width="16"
|
|
109
|
+
height="16"
|
|
110
|
+
>
|
|
111
|
+
${this.titlePrefixIcon}
|
|
112
|
+
</svg>
|
|
113
|
+
`;
|
|
114
|
+
return `
|
|
115
|
+
<g
|
|
116
|
+
data-testid="card-title"
|
|
117
|
+
transform="translate(${this.paddingX}, ${this.paddingY})"
|
|
118
|
+
>
|
|
119
|
+
${flexLayout({
|
|
120
|
+
items: [this.titlePrefixIcon ? prefixIcon : "", titleText],
|
|
121
|
+
gap: 25,
|
|
122
|
+
}).join("")}
|
|
123
|
+
</g>
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @returns {string} The rendered card gradient.
|
|
128
|
+
*/
|
|
129
|
+
renderGradient() {
|
|
130
|
+
if (typeof this.colors.bgColor !== "object") {
|
|
131
|
+
return "";
|
|
132
|
+
}
|
|
133
|
+
const gradients = this.colors.bgColor.slice(1);
|
|
134
|
+
return typeof this.colors.bgColor === "object"
|
|
135
|
+
? `
|
|
136
|
+
<defs>
|
|
137
|
+
<linearGradient
|
|
138
|
+
id="gradient"
|
|
139
|
+
gradientTransform="rotate(${this.colors.bgColor[0]})"
|
|
140
|
+
gradientUnits="userSpaceOnUse"
|
|
141
|
+
>
|
|
142
|
+
${gradients.map((grad, index) => {
|
|
143
|
+
let offset = (index * 100) / (gradients.length - 1);
|
|
144
|
+
return `<stop offset="${offset}%" stop-color="#${grad}" />`;
|
|
145
|
+
})}
|
|
146
|
+
</linearGradient>
|
|
147
|
+
</defs>
|
|
148
|
+
`
|
|
149
|
+
: "";
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Retrieves css animations for a card.
|
|
153
|
+
*
|
|
154
|
+
* @returns {string} Animation css.
|
|
155
|
+
*/
|
|
156
|
+
getAnimations = () => {
|
|
157
|
+
return `
|
|
158
|
+
/* Animations */
|
|
159
|
+
@keyframes scaleInAnimation {
|
|
160
|
+
from {
|
|
161
|
+
transform: translate(-5px, 5px) scale(0);
|
|
162
|
+
}
|
|
163
|
+
to {
|
|
164
|
+
transform: translate(-5px, 5px) scale(1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
@keyframes fadeInAnimation {
|
|
168
|
+
from {
|
|
169
|
+
opacity: 0;
|
|
170
|
+
}
|
|
171
|
+
to {
|
|
172
|
+
opacity: 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* @param {string} body The inner body of the card.
|
|
179
|
+
* @returns {string} The rendered card.
|
|
180
|
+
*/
|
|
181
|
+
render(body) {
|
|
182
|
+
return `
|
|
183
|
+
<svg
|
|
184
|
+
width="${this.width}"
|
|
185
|
+
height="${this.height}"
|
|
186
|
+
viewBox="0 0 ${this.width} ${this.height}"
|
|
187
|
+
fill="none"
|
|
188
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
189
|
+
role="img"
|
|
190
|
+
aria-labelledby="descId"
|
|
191
|
+
>
|
|
192
|
+
<title id="titleId">${this.a11yTitle}</title>
|
|
193
|
+
<desc id="descId">${this.a11yDesc}</desc>
|
|
194
|
+
<style>
|
|
195
|
+
.header {
|
|
196
|
+
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
|
|
197
|
+
fill: ${this.colors.titleColor};
|
|
198
|
+
animation: fadeInAnimation 0.8s ease-in-out forwards;
|
|
199
|
+
}
|
|
200
|
+
@supports(-moz-appearance: auto) {
|
|
201
|
+
/* Selector detects Firefox */
|
|
202
|
+
.header { font-size: 15.5px; }
|
|
203
|
+
}
|
|
204
|
+
${this.css}
|
|
205
|
+
|
|
206
|
+
${this.getAnimations()}
|
|
207
|
+
${this.animations === false
|
|
208
|
+
? `* { animation-duration: 0s !important; animation-delay: 0s !important; }`
|
|
209
|
+
: ""}
|
|
210
|
+
</style>
|
|
211
|
+
|
|
212
|
+
${this.renderGradient()}
|
|
213
|
+
|
|
214
|
+
<rect
|
|
215
|
+
data-testid="card-bg"
|
|
216
|
+
x="0.5"
|
|
217
|
+
y="0.5"
|
|
218
|
+
rx="${this.border_radius}"
|
|
219
|
+
height="99%"
|
|
220
|
+
stroke="${this.colors.borderColor}"
|
|
221
|
+
width="${this.width - 1}"
|
|
222
|
+
fill="${typeof this.colors.bgColor === "object"
|
|
223
|
+
? "url(#gradient)"
|
|
224
|
+
: this.colors.bgColor}"
|
|
225
|
+
stroke-opacity="${this.hideBorder ? 0 : 1}"
|
|
226
|
+
/>
|
|
227
|
+
|
|
228
|
+
${this.hideTitle ? "" : this.renderTitle()}
|
|
229
|
+
|
|
230
|
+
<g
|
|
231
|
+
data-testid="main-card-body"
|
|
232
|
+
transform="translate(0, ${this.hideTitle ? this.paddingX : this.paddingY + 20})"
|
|
233
|
+
>
|
|
234
|
+
${body}
|
|
235
|
+
</g>
|
|
236
|
+
</svg>
|
|
237
|
+
`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
export { Card };
|
|
241
|
+
export default Card;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* I18n translation class.
|
|
3
|
+
*/
|
|
4
|
+
export class I18n {
|
|
5
|
+
/**
|
|
6
|
+
* Constructor.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} options Options.
|
|
9
|
+
* @param {string=} options.locale Locale.
|
|
10
|
+
* @param {any} options.translations Translations.
|
|
11
|
+
*/
|
|
12
|
+
constructor({ locale, translations }: {
|
|
13
|
+
locale?: string | undefined;
|
|
14
|
+
translations: any;
|
|
15
|
+
});
|
|
16
|
+
locale: string;
|
|
17
|
+
translations: any;
|
|
18
|
+
/**
|
|
19
|
+
* Get translation.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} str String to translate.
|
|
22
|
+
* @returns {string} Translated string.
|
|
23
|
+
*/
|
|
24
|
+
t(str: string): string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=I18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"I18n.d.ts","sourceRoot":"","sources":["../../src/common/I18n.js"],"names":[],"mappings":"AAIA;;GAEG;AACH;IACE;;;;;;OAMG;IACH,sCAHG;QAAyB,MAAM,GAAvB,MAAM,YAAC;QACM,YAAY,EAAzB,GAAG;KACb,EAIA;IAFC,eAAuC;IACvC,kBAAgC;IAGlC;;;;;OAKG;IACH,OAHW,MAAM,GACJ,MAAM,CAclB;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const FALLBACK_LOCALE = "en";
|
|
3
|
+
/**
|
|
4
|
+
* I18n translation class.
|
|
5
|
+
*/
|
|
6
|
+
class I18n {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} options Options.
|
|
11
|
+
* @param {string=} options.locale Locale.
|
|
12
|
+
* @param {any} options.translations Translations.
|
|
13
|
+
*/
|
|
14
|
+
constructor({ locale, translations }) {
|
|
15
|
+
this.locale = locale || FALLBACK_LOCALE;
|
|
16
|
+
this.translations = translations;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get translation.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} str String to translate.
|
|
22
|
+
* @returns {string} Translated string.
|
|
23
|
+
*/
|
|
24
|
+
t(str) {
|
|
25
|
+
if (!this.translations[str]) {
|
|
26
|
+
throw new Error(`${str} Translation string not found`);
|
|
27
|
+
}
|
|
28
|
+
if (!this.translations[str][this.locale]) {
|
|
29
|
+
throw new Error(`'${str}' translation not found for locale '${this.locale}'`);
|
|
30
|
+
}
|
|
31
|
+
return this.translations[str][this.locale];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export { I18n };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object containing card colors.
|
|
3
|
+
*/
|
|
4
|
+
export type CardColors = {
|
|
5
|
+
titleColor: string;
|
|
6
|
+
iconColor: string;
|
|
7
|
+
textColor: string;
|
|
8
|
+
bgColor: string | string[];
|
|
9
|
+
borderColor: string;
|
|
10
|
+
ringColor: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves a gradient if color has more than one valid hex codes else a single color.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} color The color to parse.
|
|
16
|
+
* @param {string | string[]} fallbackColor The fallback color.
|
|
17
|
+
* @returns {string | string[]} The gradient or color.
|
|
18
|
+
*/
|
|
19
|
+
export function fallbackColor(color: string, fallbackColor: string | string[]): string | string[];
|
|
20
|
+
/**
|
|
21
|
+
* Object containing card colors.
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* titleColor: string;
|
|
24
|
+
* iconColor: string;
|
|
25
|
+
* textColor: string;
|
|
26
|
+
* bgColor: string | string[];
|
|
27
|
+
* borderColor: string;
|
|
28
|
+
* ringColor: string;
|
|
29
|
+
* }} CardColors
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Returns theme based colors with proper overrides and defaults.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} args Function arguments.
|
|
35
|
+
* @param {string=} args.title_color Card title color.
|
|
36
|
+
* @param {string=} args.text_color Card text color.
|
|
37
|
+
* @param {string=} args.icon_color Card icon color.
|
|
38
|
+
* @param {string=} args.bg_color Card background color.
|
|
39
|
+
* @param {string=} args.border_color Card border color.
|
|
40
|
+
* @param {string=} args.ring_color Card ring color.
|
|
41
|
+
* @param {string=} args.theme Card theme.
|
|
42
|
+
* @returns {CardColors} Card colors.
|
|
43
|
+
*/
|
|
44
|
+
export function getCardColors({ title_color, text_color, icon_color, bg_color, border_color, ring_color, theme, }: {
|
|
45
|
+
title_color?: string | undefined;
|
|
46
|
+
text_color?: string | undefined;
|
|
47
|
+
icon_color?: string | undefined;
|
|
48
|
+
bg_color?: string | undefined;
|
|
49
|
+
border_color?: string | undefined;
|
|
50
|
+
ring_color?: string | undefined;
|
|
51
|
+
theme?: string | undefined;
|
|
52
|
+
}): CardColors;
|
|
53
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/common/color.js"],"names":[],"mappings":";;;yBAoDa;IACT,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CAClB;AA9BJ;;;;;;GAMG;AACH,qCAJW,MAAM,iBACN,MAAM,GAAG,MAAM,EAAE,GACf,MAAM,GAAG,MAAM,EAAE,CAc7B;AAED;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;GAYG;AACH,mHATG;IAAsB,WAAW,GAAzB,MAAM,YAAC;IACO,UAAU,GAAxB,MAAM,YAAC;IACO,UAAU,GAAxB,MAAM,YAAC;IACO,QAAQ,GAAtB,MAAM,YAAC;IACO,YAAY,GAA1B,MAAM,YAAC;IACO,UAAU,GAAxB,MAAM,YAAC;IACO,KAAK,GAAnB,MAAM,YAAC;CACf,GAAU,UAAU,CAqEtB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { themes } from "../themes/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a string is a valid hex color.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} hexColor String to check.
|
|
7
|
+
* @returns {boolean} True if the given string is a valid hex color.
|
|
8
|
+
*/
|
|
9
|
+
const isValidHexColor = (hexColor) => {
|
|
10
|
+
return new RegExp(/^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4})$/).test(hexColor);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Check if the given string is a valid gradient.
|
|
14
|
+
*
|
|
15
|
+
* @param {string[]} colors Array of colors.
|
|
16
|
+
* @returns {boolean} True if the given string is a valid gradient.
|
|
17
|
+
*/
|
|
18
|
+
const isValidGradient = (colors) => {
|
|
19
|
+
return (colors.length > 2 &&
|
|
20
|
+
colors.slice(1).every((color) => isValidHexColor(color)));
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves a gradient if color has more than one valid hex codes else a single color.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} color The color to parse.
|
|
26
|
+
* @param {string | string[]} fallbackColor The fallback color.
|
|
27
|
+
* @returns {string | string[]} The gradient or color.
|
|
28
|
+
*/
|
|
29
|
+
const fallbackColor = (color, fallbackColor) => {
|
|
30
|
+
let gradient = null;
|
|
31
|
+
let colors = color ? color.split(",") : [];
|
|
32
|
+
if (colors.length > 1 && isValidGradient(colors)) {
|
|
33
|
+
gradient = colors;
|
|
34
|
+
}
|
|
35
|
+
return ((gradient ? gradient : isValidHexColor(color) && `#${color}`) ||
|
|
36
|
+
fallbackColor);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Object containing card colors.
|
|
40
|
+
* @typedef {{
|
|
41
|
+
* titleColor: string;
|
|
42
|
+
* iconColor: string;
|
|
43
|
+
* textColor: string;
|
|
44
|
+
* bgColor: string | string[];
|
|
45
|
+
* borderColor: string;
|
|
46
|
+
* ringColor: string;
|
|
47
|
+
* }} CardColors
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Returns theme based colors with proper overrides and defaults.
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} args Function arguments.
|
|
53
|
+
* @param {string=} args.title_color Card title color.
|
|
54
|
+
* @param {string=} args.text_color Card text color.
|
|
55
|
+
* @param {string=} args.icon_color Card icon color.
|
|
56
|
+
* @param {string=} args.bg_color Card background color.
|
|
57
|
+
* @param {string=} args.border_color Card border color.
|
|
58
|
+
* @param {string=} args.ring_color Card ring color.
|
|
59
|
+
* @param {string=} args.theme Card theme.
|
|
60
|
+
* @returns {CardColors} Card colors.
|
|
61
|
+
*/
|
|
62
|
+
const getCardColors = ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, theme, }) => {
|
|
63
|
+
const defaultTheme = themes["default"];
|
|
64
|
+
const isThemeProvided = theme !== null && theme !== undefined && theme in themes;
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
const selectedTheme = isThemeProvided ? themes[theme] : defaultTheme;
|
|
67
|
+
const defaultBorderColor = "border_color" in selectedTheme
|
|
68
|
+
? selectedTheme.border_color
|
|
69
|
+
: // @ts-ignore
|
|
70
|
+
defaultTheme.border_color;
|
|
71
|
+
// get the color provided by the user else the theme color
|
|
72
|
+
// finally if both colors are invalid fallback to default theme
|
|
73
|
+
const titleColor = fallbackColor(title_color || selectedTheme.title_color, "#" + defaultTheme.title_color);
|
|
74
|
+
// get the color provided by the user else the theme color
|
|
75
|
+
// finally if both colors are invalid we use the titleColor
|
|
76
|
+
const ringColor = fallbackColor(
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
ring_color || selectedTheme.ring_color, titleColor);
|
|
79
|
+
const iconColor = fallbackColor(icon_color || selectedTheme.icon_color, "#" + defaultTheme.icon_color);
|
|
80
|
+
const textColor = fallbackColor(text_color || selectedTheme.text_color, "#" + defaultTheme.text_color);
|
|
81
|
+
const bgColor = fallbackColor(bg_color || selectedTheme.bg_color, "#" + defaultTheme.bg_color);
|
|
82
|
+
const borderColor = fallbackColor(border_color || defaultBorderColor, "#" + defaultBorderColor);
|
|
83
|
+
if (typeof titleColor !== "string" ||
|
|
84
|
+
typeof textColor !== "string" ||
|
|
85
|
+
typeof ringColor !== "string" ||
|
|
86
|
+
typeof iconColor !== "string" ||
|
|
87
|
+
typeof borderColor !== "string") {
|
|
88
|
+
throw new Error("Unexpected behavior, all colors except background should be string.");
|
|
89
|
+
}
|
|
90
|
+
return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor };
|
|
91
|
+
};
|
|
92
|
+
export { fallbackColor, getCardColors };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/common/config.js"],"names":[],"mappings":"AA6DO,wCAFI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,QAc5C;AAIM,iCAAqC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @param {string | undefined} value Comma-separated string.
|
|
4
|
+
* @returns {string[] | undefined} Parsed string values.
|
|
5
|
+
*/
|
|
6
|
+
const parseCsv = (value) => {
|
|
7
|
+
if (!value) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return value.split(",");
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @param {Record<string, string | undefined>} env Environment variables to inspect.
|
|
14
|
+
* @returns {{name: string, value: string}[]} Personal access tokens found in the environment.
|
|
15
|
+
*/
|
|
16
|
+
const parsePATsFromEnv = (env) => {
|
|
17
|
+
return Object.keys(env)
|
|
18
|
+
.filter((key) => /PAT_\d*$/.exec(key))
|
|
19
|
+
.map((name) => ({
|
|
20
|
+
name,
|
|
21
|
+
value: env[name],
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @returns {Record<string, string | undefined>} `process.env` if available, otherwise `{}`.
|
|
26
|
+
*/
|
|
27
|
+
const getDefaultEnv = () => {
|
|
28
|
+
if (typeof process !== "undefined" && process?.env) {
|
|
29
|
+
return process.env;
|
|
30
|
+
}
|
|
31
|
+
return {};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @param {Partial<ReturnType<typeof loadConfigFromEnv>>} config (Partial) config values to normalize.
|
|
35
|
+
* @returns {{
|
|
36
|
+
* whitelist: string[] | undefined,
|
|
37
|
+
* gistWhitelist: string[] | undefined,
|
|
38
|
+
* excludeRepositories: string[],
|
|
39
|
+
* fetchMultiPageStars: string | undefined,
|
|
40
|
+
* pats: {name: string, value: string}[],
|
|
41
|
+
* }} Normalized config object with defaults applied.
|
|
42
|
+
*/
|
|
43
|
+
const normalizeConfig = (config = {}) => {
|
|
44
|
+
return {
|
|
45
|
+
whitelist: config.whitelist,
|
|
46
|
+
gistWhitelist: config.gistWhitelist,
|
|
47
|
+
excludeRepositories: config.excludeRepositories || [],
|
|
48
|
+
fetchMultiPageStars: config.fetchMultiPageStars,
|
|
49
|
+
pats: config.pats || [],
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
let currentConfig;
|
|
53
|
+
/**
|
|
54
|
+
* @param {Record<string, string | undefined>} env Environment variables used to build the runtime config.
|
|
55
|
+
*/
|
|
56
|
+
export const loadConfigFromEnv = (env = getDefaultEnv()) => {
|
|
57
|
+
const whitelist = parseCsv(env.WHITELIST);
|
|
58
|
+
const gistWhitelist = parseCsv(env.GIST_WHITELIST);
|
|
59
|
+
const excludeRepositories = parseCsv(env.EXCLUDE_REPO) || [];
|
|
60
|
+
currentConfig = normalizeConfig({
|
|
61
|
+
whitelist,
|
|
62
|
+
gistWhitelist,
|
|
63
|
+
excludeRepositories,
|
|
64
|
+
fetchMultiPageStars: env.FETCH_MULTI_PAGE_STARS,
|
|
65
|
+
pats: parsePATsFromEnv(env),
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
loadConfigFromEnv();
|
|
69
|
+
export const getConfig = () => currentConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.js"],"names":[],"mappings":"AAEA;;;GAGG;AACH,iCAFU,KAAK,CAAC,MAAM,CAAC,CAEqD"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class to handle custom GRS errors.
|
|
3
|
+
*/
|
|
4
|
+
export class CustomError extends Error {
|
|
5
|
+
static MAX_RETRY: string;
|
|
6
|
+
static NO_TOKENS: string;
|
|
7
|
+
static USER_NOT_FOUND: string;
|
|
8
|
+
static GRAPHQL_ERROR: string;
|
|
9
|
+
static GITHUB_REST_API_ERROR: string;
|
|
10
|
+
static WAKATIME_ERROR: string;
|
|
11
|
+
static INVALID_AFFILIATION: string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom error constructor.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} message Error message.
|
|
16
|
+
* @param {string} type Error type.
|
|
17
|
+
*/
|
|
18
|
+
constructor(message: string, type: string);
|
|
19
|
+
type: string;
|
|
20
|
+
secondaryMessage: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Missing query parameter class.
|
|
24
|
+
*/
|
|
25
|
+
export class MissingParamError extends Error {
|
|
26
|
+
/**
|
|
27
|
+
* Missing query parameter error constructor.
|
|
28
|
+
*
|
|
29
|
+
* @param {string[]} missedParams An array of missing parameters names.
|
|
30
|
+
* @param {string=} secondaryMessage Optional secondary message to display.
|
|
31
|
+
*/
|
|
32
|
+
constructor(missedParams: string[], secondaryMessage?: string | undefined);
|
|
33
|
+
missedParams: string[];
|
|
34
|
+
secondaryMessage: string | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @type {Object<string, string>} A map of error types to secondary error messages.
|
|
38
|
+
*/
|
|
39
|
+
export const SECONDARY_ERROR_MESSAGES: {
|
|
40
|
+
[x: string]: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @type {string} A general message to ask user to try again later.
|
|
44
|
+
*/
|
|
45
|
+
export const TRY_AGAIN_LATER: string;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve secondary message from an error object.
|
|
48
|
+
*
|
|
49
|
+
* @param {Error} err The error object.
|
|
50
|
+
* @returns {string|undefined} The secondary message if available, otherwise undefined.
|
|
51
|
+
*/
|
|
52
|
+
export function retrieveSecondaryMessage(err: Error): string | undefined;
|
|
53
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/common/error.js"],"names":[],"mappings":"AA0BA;;GAEG;AACH;IAaE,yBAA+B;IAC/B,yBAA+B;IAC/B,8BAAyC;IACzC,6BAAuC;IACvC,qCAAuD;IACvD,8BAAyC;IACzC,mCAAmD;IAlBnD;;;;;OAKG;IACH,qBAHW,MAAM,QACN,MAAM,EAMhB;IAFC,aAAgB;IAChB,yBAA8D;CAUjE;AAED;;GAEG;AACH;IACE;;;;;OAKG;IACH,0BAHW,MAAM,EAAE,qBACR,MAAM,YAAC,EASjB;IAFC,uBAAgC;IAChC,qCAAwC;CAE3C;AA5DD;;GAEG;AACH;;EAYE;AApBF;;GAEG;AACH,8BAFU,MAAM,CAEiC;AAgEjD;;;;;GAKG;AACH,8CAHW,KAAK,GACH,MAAM,GAAC,SAAS,CAM5B"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { OWNER_AFFILIATIONS } from "./constants.js";
|
|
3
|
+
/**
|
|
4
|
+
* @type {string} A general message to ask user to try again later.
|
|
5
|
+
*/
|
|
6
|
+
const TRY_AGAIN_LATER = "Please try again later";
|
|
7
|
+
/**
|
|
8
|
+
* @type {Object<string, string>} A map of error types to secondary error messages.
|
|
9
|
+
*/
|
|
10
|
+
const SECONDARY_ERROR_MESSAGES = {
|
|
11
|
+
MAX_RETRY: "You can deploy own instance or wait until public will be no longer limited",
|
|
12
|
+
NO_TOKENS: "Please add an env variable called PAT_1 with your GitHub API token in vercel",
|
|
13
|
+
USER_NOT_FOUND: "Make sure the provided username is not an organization",
|
|
14
|
+
GRAPHQL_ERROR: TRY_AGAIN_LATER,
|
|
15
|
+
GITHUB_REST_API_ERROR: TRY_AGAIN_LATER,
|
|
16
|
+
WAKATIME_USER_NOT_FOUND: "Make sure you have a public WakaTime profile",
|
|
17
|
+
INVALID_AFFILIATION: `Invalid owner affiliations. Valid values are: ${OWNER_AFFILIATIONS.join(", ")}`,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Custom error class to handle custom GRS errors.
|
|
21
|
+
*/
|
|
22
|
+
class CustomError extends Error {
|
|
23
|
+
/**
|
|
24
|
+
* Custom error constructor.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} message Error message.
|
|
27
|
+
* @param {string} type Error type.
|
|
28
|
+
*/
|
|
29
|
+
constructor(message, type) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.type = type;
|
|
32
|
+
this.secondaryMessage = SECONDARY_ERROR_MESSAGES[type] || type;
|
|
33
|
+
}
|
|
34
|
+
static MAX_RETRY = "MAX_RETRY";
|
|
35
|
+
static NO_TOKENS = "NO_TOKENS";
|
|
36
|
+
static USER_NOT_FOUND = "USER_NOT_FOUND";
|
|
37
|
+
static GRAPHQL_ERROR = "GRAPHQL_ERROR";
|
|
38
|
+
static GITHUB_REST_API_ERROR = "GITHUB_REST_API_ERROR";
|
|
39
|
+
static WAKATIME_ERROR = "WAKATIME_ERROR";
|
|
40
|
+
static INVALID_AFFILIATION = "INVALID_AFFILIATION";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Missing query parameter class.
|
|
44
|
+
*/
|
|
45
|
+
class MissingParamError extends Error {
|
|
46
|
+
/**
|
|
47
|
+
* Missing query parameter error constructor.
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} missedParams An array of missing parameters names.
|
|
50
|
+
* @param {string=} secondaryMessage Optional secondary message to display.
|
|
51
|
+
*/
|
|
52
|
+
constructor(missedParams, secondaryMessage) {
|
|
53
|
+
const msg = `Missing params ${missedParams
|
|
54
|
+
.map((p) => `"${p}"`)
|
|
55
|
+
.join(", ")} make sure you pass the parameters in URL`;
|
|
56
|
+
super(msg);
|
|
57
|
+
this.missedParams = missedParams;
|
|
58
|
+
this.secondaryMessage = secondaryMessage;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Retrieve secondary message from an error object.
|
|
63
|
+
*
|
|
64
|
+
* @param {Error} err The error object.
|
|
65
|
+
* @returns {string|undefined} The secondary message if available, otherwise undefined.
|
|
66
|
+
*/
|
|
67
|
+
const retrieveSecondaryMessage = (err) => {
|
|
68
|
+
return "secondaryMessage" in err && typeof err.secondaryMessage === "string"
|
|
69
|
+
? err.secondaryMessage
|
|
70
|
+
: undefined;
|
|
71
|
+
};
|
|
72
|
+
export { CustomError, MissingParamError, SECONDARY_ERROR_MESSAGES, TRY_AGAIN_LATER, retrieveSecondaryMessage, };
|