@stats-organization/github-readme-stats-core 2.1.4 → 2.1.5
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.map +1 -1
- package/build/api/gist.js +34 -0
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +18 -0
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +17 -0
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +36 -4
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +34 -0
- package/build/calculateRank.d.ts +12 -11
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +18 -18
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +29 -20
- package/build/cards/stats.d.ts +4 -2
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +21 -8
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +39 -11
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +29 -8
- package/build/common/Card.d.ts +9 -3
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +47 -19
- package/build/common/color.d.ts +42 -8
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +62 -13
- package/build/common/html.js +1 -1
- package/build/common/http.d.ts +13 -4
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +3 -3
- package/build/common/languageColors.json +9 -1
- package/build/common/ops.d.ts +30 -29
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +32 -37
- package/build/common/render.d.ts +115 -111
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +138 -87
- package/build/common/retryer.d.ts +14 -6
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +1 -0
- package/build/fetchers/gist.d.ts +6 -21
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +30 -35
- package/build/fetchers/repo.js +1 -1
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +0 -1
- package/build/fetchers/types.d.ts +126 -0
- package/build/fetchers/types.d.ts.map +1 -0
- package/build/fetchers/types.js +1 -0
- package/package.json +4 -4
- package/src/_emoji-name-map.d.ts +10 -0
- package/src/api/gist.js +36 -0
- package/src/api/index.js +19 -0
- package/src/api/pin.js +18 -0
- package/src/api/top-langs.js +38 -4
- package/src/api/wakatime.js +36 -0
- package/src/{calculateRank.js → calculateRank.ts} +29 -19
- package/src/cards/repo.js +30 -20
- package/src/cards/stats.js +22 -8
- package/src/cards/top-languages.js +49 -11
- package/src/cards/wakatime.js +33 -8
- package/src/common/Card.ts +51 -16
- package/src/common/color.ts +85 -22
- package/src/common/html.ts +1 -1
- package/src/common/http.ts +31 -0
- package/src/common/languageColors.json +9 -1
- package/src/common/{ops.js → ops.ts} +48 -50
- package/src/common/{render.js → render.ts} +208 -96
- package/src/common/retryer.ts +18 -10
- package/src/fetchers/gist.ts +136 -0
- package/src/fetchers/repo.js +1 -1
- package/src/fetchers/stats.js +0 -1
- package/src/common/http.js +0 -19
- package/src/fetchers/gist.js +0 -112
- /package/src/fetchers/{types.d.ts → types.ts} +0 -0
package/build/common/render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCardColors } from "./color.js";
|
|
1
|
+
import { getCardColors, isPrefixedHexColor } from "./color.js";
|
|
2
2
|
import { SECONDARY_ERROR_MESSAGES, TRY_AGAIN_LATER } from "./error.js";
|
|
3
3
|
import { encodeHTML } from "./html.js";
|
|
4
4
|
import { clampValue } from "./ops.js";
|
|
@@ -6,14 +6,19 @@ import { clampValue } from "./ops.js";
|
|
|
6
6
|
* Auto layout utility, allows us to layout things vertically or horizontally with
|
|
7
7
|
* proper gaping.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
9
|
+
* The caller must ensure that the passed `items` are properly sanitized!
|
|
10
|
+
*
|
|
11
|
+
* @param props Function properties.
|
|
12
|
+
* @param props.items Array of sanitized items to layout.
|
|
13
|
+
* @param props.gap Gap between items.
|
|
14
|
+
* @param props.direction Direction to layout items.
|
|
15
|
+
* @param props.sizes Array of sizes for each item.
|
|
16
|
+
* @returns Array of items with proper layout.
|
|
15
17
|
*/
|
|
16
|
-
const flexLayout = ({ items, gap, direction, sizes = [] }) => {
|
|
18
|
+
const flexLayout = ({ items, gap, direction, sizes = [], }) => {
|
|
19
|
+
if (sizes.some((size) => !Number.isFinite(size))) {
|
|
20
|
+
throw new Error("flexLayout: `sizes` must contain only numbers");
|
|
21
|
+
}
|
|
17
22
|
let lastSize = 0;
|
|
18
23
|
// filter() for filtering out empty strings
|
|
19
24
|
return items.filter(Boolean).map((item, i) => {
|
|
@@ -29,32 +34,53 @@ const flexLayout = ({ items, gap, direction, sizes = [] }) => {
|
|
|
29
34
|
/**
|
|
30
35
|
* Creates a node to display the primary programming language of the repository/gist.
|
|
31
36
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns
|
|
37
|
+
* @param langName Language name.
|
|
38
|
+
* @param langColor Language color.
|
|
39
|
+
* @returns Language display SVG object.
|
|
35
40
|
*/
|
|
36
41
|
const createLanguageNode = (langName, langColor) => {
|
|
42
|
+
if (!isPrefixedHexColor(langColor)) {
|
|
43
|
+
throw new Error(`Invalid language color: "${langColor}"`);
|
|
44
|
+
}
|
|
37
45
|
return `
|
|
38
46
|
<g data-testid="primary-lang">
|
|
39
47
|
<circle data-testid="lang-color" cx="0" cy="-5" r="6" fill="${langColor}" />
|
|
40
|
-
<text data-testid="lang-name" class="gray" x="15">${langName}</text>
|
|
48
|
+
<text data-testid="lang-name" class="gray" x="15">${encodeHTML(langName)}</text>
|
|
41
49
|
</g>
|
|
42
50
|
`;
|
|
43
51
|
};
|
|
44
52
|
/**
|
|
45
53
|
* Create a node to indicate progress in percentage along a horizontal line.
|
|
46
54
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @returns
|
|
55
|
+
* @param params Object that contains the createProgressNode parameters.
|
|
56
|
+
* @param params.x X-axis position.
|
|
57
|
+
* @param params.y Y-axis position.
|
|
58
|
+
* @param params.width Width of progress bar.
|
|
59
|
+
* @param params.color Progress color.
|
|
60
|
+
* @param params.progress Progress value.
|
|
61
|
+
* @param params.progressBarBackgroundColor Progress bar bg color.
|
|
62
|
+
* @param params.delay Delay before animation starts.
|
|
63
|
+
* @returns Progress node.
|
|
56
64
|
*/
|
|
57
65
|
const createProgressNode = ({ x, y, width, color, progress, progressBarBackgroundColor, delay, }) => {
|
|
66
|
+
if (!isPrefixedHexColor(color)) {
|
|
67
|
+
throw new Error(`Invalid progress color: "${color}"`);
|
|
68
|
+
}
|
|
69
|
+
if (!isPrefixedHexColor(progressBarBackgroundColor)) {
|
|
70
|
+
throw new Error(`Invalid progress bar background color: "${progressBarBackgroundColor}"`);
|
|
71
|
+
}
|
|
72
|
+
if (!Number.isFinite(width)) {
|
|
73
|
+
throw new Error(`Invalid width: "${width}"`);
|
|
74
|
+
}
|
|
75
|
+
if (!Number.isFinite(x)) {
|
|
76
|
+
throw new Error(`Invalid x: "${x}"`);
|
|
77
|
+
}
|
|
78
|
+
if (!Number.isFinite(y)) {
|
|
79
|
+
throw new Error(`Invalid y: "${y}"`);
|
|
80
|
+
}
|
|
81
|
+
if (!Number.isFinite(delay)) {
|
|
82
|
+
throw new Error(`Invalid delay: "${delay}"`);
|
|
83
|
+
}
|
|
58
84
|
const progressPercentage = clampValue(progress, 2, 100);
|
|
59
85
|
return `
|
|
60
86
|
<svg width="${width}" x="${x}" y="${y}">
|
|
@@ -76,22 +102,37 @@ const createProgressNode = ({ x, y, width, color, progress, progressBarBackgroun
|
|
|
76
102
|
* native, font-aware wrapping. Content overflowing `lineCount` lines is
|
|
77
103
|
* clipped (with an ellipsis on the last visible line) by CSS line-clamp.
|
|
78
104
|
*
|
|
79
|
-
* @param
|
|
80
|
-
* @param
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* @param
|
|
88
|
-
* @returns
|
|
105
|
+
* @param props Function properties.
|
|
106
|
+
* @param props.text Text to render (will be HTML-encoded).
|
|
107
|
+
* @param props.x X position of the foreignObject.
|
|
108
|
+
* @param props.y Y position of the foreignObject.
|
|
109
|
+
* @param props.width Width of the wrap box.
|
|
110
|
+
* @param props.height Height of the wrap box.
|
|
111
|
+
* @param props.lineCount Maximum number of lines to display.
|
|
112
|
+
* @param props.className CSS class applied to the inner element.
|
|
113
|
+
* @param props.testId Optional test id for the inner element.
|
|
114
|
+
* @returns foreignObject SVG node.
|
|
89
115
|
*/
|
|
90
116
|
const wrappedTextNode = ({ text, x, y, width, height, lineCount, className, testId, }) => {
|
|
91
|
-
|
|
117
|
+
if (!Number.isFinite(x)) {
|
|
118
|
+
throw new Error(`Invalid x: "${x}"`);
|
|
119
|
+
}
|
|
120
|
+
if (!Number.isFinite(y)) {
|
|
121
|
+
throw new Error(`Invalid y: "${y}"`);
|
|
122
|
+
}
|
|
123
|
+
if (!Number.isFinite(width)) {
|
|
124
|
+
throw new Error(`Invalid width: "${width}"`);
|
|
125
|
+
}
|
|
126
|
+
if (!Number.isFinite(height)) {
|
|
127
|
+
throw new Error(`Invalid height: "${height}"`);
|
|
128
|
+
}
|
|
129
|
+
if (!Number.isFinite(lineCount)) {
|
|
130
|
+
throw new Error(`Invalid lineCount: "${lineCount}"`);
|
|
131
|
+
}
|
|
132
|
+
const testIdAttr = testId ? ` data-testid="${encodeHTML(testId)}"` : "";
|
|
92
133
|
return `
|
|
93
134
|
<foreignObject x="${x}" y="${y}" width="${width}" height="${height}">
|
|
94
|
-
<div xmlns="http://www.w3.org/1999/xhtml" class="${className}" style="--lines: ${lineCount};"${testIdAttr}>${encodeHTML(text)}</div>
|
|
135
|
+
<div xmlns="http://www.w3.org/1999/xhtml" class="${encodeHTML(className)}" style="--lines: ${lineCount};"${testIdAttr}>${encodeHTML(text)}</div>
|
|
95
136
|
</foreignObject>
|
|
96
137
|
`;
|
|
97
138
|
};
|
|
@@ -101,36 +142,46 @@ const wrappedTextNode = ({ text, x, y, width, height, lineCount, className, test
|
|
|
101
142
|
* browser handles wrapping and the line count is taken from the `--lines`
|
|
102
143
|
* custom property set on the element.
|
|
103
144
|
*
|
|
104
|
-
* @param
|
|
105
|
-
* @returns
|
|
145
|
+
* @param color Text color (CSS `color` property).
|
|
146
|
+
* @returns CSS rules block (without the surrounding selector).
|
|
106
147
|
*/
|
|
107
|
-
const wrappedTextStyles = (color) =>
|
|
108
|
-
color
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
148
|
+
const wrappedTextStyles = (color) => {
|
|
149
|
+
if (!isPrefixedHexColor(color)) {
|
|
150
|
+
throw new Error(`Invalid text color: "${color}"`);
|
|
151
|
+
}
|
|
152
|
+
return `
|
|
153
|
+
color: ${color};
|
|
154
|
+
margin: 0;
|
|
155
|
+
line-height: 1.2;
|
|
156
|
+
overflow-wrap: anywhere;
|
|
157
|
+
word-break: break-word;
|
|
158
|
+
display: -webkit-box;
|
|
159
|
+
-webkit-box-orient: vertical;
|
|
160
|
+
-webkit-line-clamp: var(--lines);
|
|
161
|
+
line-clamp: var(--lines);
|
|
162
|
+
overflow: hidden;
|
|
163
|
+
text-overflow: ellipsis;
|
|
164
|
+
padding-bottom: 0.15em;
|
|
165
|
+
`;
|
|
166
|
+
};
|
|
121
167
|
/**
|
|
122
168
|
* Creates an icon with label to display repository/gist stats like forks, stars, etc.
|
|
123
169
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param
|
|
127
|
-
* @param
|
|
128
|
-
* @
|
|
170
|
+
* The caller must ensure that the passed `icon` is properly sanitized!
|
|
171
|
+
*
|
|
172
|
+
* @param icon The sanitized icon to display.
|
|
173
|
+
* @param label The label to display.
|
|
174
|
+
* @param testid The testid to assign to the label.
|
|
175
|
+
* @param iconSize The size of the icon.
|
|
176
|
+
* @returns Icon with label SVG object.
|
|
129
177
|
*/
|
|
130
178
|
const iconWithLabel = (icon, label, testid, iconSize) => {
|
|
131
179
|
if (typeof label === "number" && label <= 0) {
|
|
132
180
|
return "";
|
|
133
181
|
}
|
|
182
|
+
if (!Number.isFinite(iconSize)) {
|
|
183
|
+
throw new Error(`Invalid iconSize: "${iconSize}"`);
|
|
184
|
+
}
|
|
134
185
|
const iconSvg = `
|
|
135
186
|
<svg
|
|
136
187
|
class="icon"
|
|
@@ -143,7 +194,7 @@ const iconWithLabel = (icon, label, testid, iconSize) => {
|
|
|
143
194
|
${icon}
|
|
144
195
|
</svg>
|
|
145
196
|
`;
|
|
146
|
-
const text = `<text data-testid="${testid}" class="gray">${label}</text>`;
|
|
197
|
+
const text = `<text data-testid="${encodeHTML(testid)}" class="gray">${encodeHTML(String(label))}</text>`;
|
|
147
198
|
return flexLayout({ items: [iconSvg, text], gap: 20 }).join("");
|
|
148
199
|
};
|
|
149
200
|
// Script parameters.
|
|
@@ -155,17 +206,17 @@ const UPSTREAM_API_ERRORS = [
|
|
|
155
206
|
/**
|
|
156
207
|
* Renders error message on the card.
|
|
157
208
|
*
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
161
|
-
* @param
|
|
162
|
-
* @param
|
|
163
|
-
* @param
|
|
164
|
-
* @param
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @returns
|
|
209
|
+
* @param args Function arguments.
|
|
210
|
+
* @param args.message Main error message.
|
|
211
|
+
* @param args.secondaryMessage The secondary error message.
|
|
212
|
+
* @param args.renderOptions Render options.
|
|
213
|
+
* @param args.renderOptions.title_color Card title color.
|
|
214
|
+
* @param args.renderOptions.text_color Card text color.
|
|
215
|
+
* @param args.renderOptions.bg_color Card background color.
|
|
216
|
+
* @param args.renderOptions.border_color Card border color.
|
|
217
|
+
* @param args.renderOptions.theme Card theme.
|
|
218
|
+
* @param args.renderOptions.show_repo_link Whether to show repo link or not.
|
|
219
|
+
* @returns The SVG markup.
|
|
169
220
|
*/
|
|
170
221
|
const renderError = ({ message, secondaryMessage = "", renderOptions = {}, }) => {
|
|
171
222
|
const { title_color, text_color, bg_color, border_color, theme = "default", show_repo_link = true, } = renderOptions;
|
|
@@ -180,19 +231,19 @@ const renderError = ({ message, secondaryMessage = "", renderOptions = {}, }) =>
|
|
|
180
231
|
theme,
|
|
181
232
|
});
|
|
182
233
|
return `
|
|
183
|
-
<svg width="${ERROR_CARD_LENGTH}" height="120" viewBox="0 0 ${ERROR_CARD_LENGTH} 120" fill="${bgColor}" xmlns="http://www.w3.org/2000/svg">
|
|
234
|
+
<svg width="${ERROR_CARD_LENGTH}" height="120" viewBox="0 0 ${ERROR_CARD_LENGTH} 120" fill="${String(bgColor)}" xmlns="http://www.w3.org/2000/svg">
|
|
184
235
|
<style>
|
|
185
236
|
.text { font: 600 16px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${titleColor} }
|
|
186
237
|
.small { font: 600 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
|
|
187
238
|
.gray { fill: #858585 }
|
|
188
239
|
</style>
|
|
189
|
-
<rect x="0.5" y="0.5" width="${ERROR_CARD_LENGTH - 1}" height="99%" rx="4.5" fill="${bgColor}" stroke="${borderColor}"/>
|
|
240
|
+
<rect x="0.5" y="0.5" width="${ERROR_CARD_LENGTH - 1}" height="99%" rx="4.5" fill="${String(bgColor)}" stroke="${borderColor}"/>
|
|
190
241
|
<text x="25" y="45" class="text">Something went wrong!${UPSTREAM_API_ERRORS.includes(secondaryMessage) || !show_repo_link
|
|
191
242
|
? ""
|
|
192
243
|
: " file an issue at https://tinyurl.com/github-stats"}</text>
|
|
193
244
|
<text data-testid="message" x="25" y="55" class="text small">
|
|
194
245
|
<tspan x="25" dy="18">${encodeHTML(message)}</tspan>
|
|
195
|
-
<tspan x="25" dy="18" class="gray">${secondaryMessage}</tspan>
|
|
246
|
+
<tspan x="25" dy="18" class="gray">${encodeHTML(secondaryMessage)}</tspan>
|
|
196
247
|
</text>
|
|
197
248
|
</svg>
|
|
198
249
|
`;
|
|
@@ -201,9 +252,9 @@ const renderError = ({ message, secondaryMessage = "", renderOptions = {}, }) =>
|
|
|
201
252
|
* Retrieve text length based on Segoe UI font.
|
|
202
253
|
*
|
|
203
254
|
* @see https://stackoverflow.com/a/48172630/10629172
|
|
204
|
-
* @param
|
|
205
|
-
* @param
|
|
206
|
-
* @returns
|
|
255
|
+
* @param str String to measure.
|
|
256
|
+
* @param fontSize Font size.
|
|
257
|
+
* @returns Text length.
|
|
207
258
|
*/
|
|
208
259
|
const measureText = (str, fontSize = 10) => {
|
|
209
260
|
// prettier-ignore
|
|
@@ -254,7 +305,7 @@ const measureText = (str, fontSize = 10) => {
|
|
|
254
305
|
return 1;
|
|
255
306
|
}
|
|
256
307
|
if (c.charCodeAt(0) < widths.length) {
|
|
257
|
-
return widths[c.charCodeAt(0)];
|
|
308
|
+
return widths[c.charCodeAt(0)] ?? avg;
|
|
258
309
|
}
|
|
259
310
|
else {
|
|
260
311
|
return avg;
|
|
@@ -269,10 +320,10 @@ const measureText = (str, fontSize = 10) => {
|
|
|
269
320
|
* The browser still does the real wrap inside the foreignObject; this is only
|
|
270
321
|
* used to size the SVG.
|
|
271
322
|
*
|
|
272
|
-
* @param
|
|
273
|
-
* @param
|
|
274
|
-
* @param
|
|
275
|
-
* @returns
|
|
323
|
+
* @param text Text to split.
|
|
324
|
+
* @param fontSize Font size in px (matches `measureText`).
|
|
325
|
+
* @param maxWidth Available wrap width in px.
|
|
326
|
+
* @returns Estimated wrapped lines.
|
|
276
327
|
*/
|
|
277
328
|
const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
278
329
|
if (!text) {
|
|
@@ -288,8 +339,8 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
288
339
|
// Korean Hangul (U+AC00–U+D7AF) is intentionally NOT in the CJK range
|
|
289
340
|
// because Korean wraps at word boundaries by default in HTML.
|
|
290
341
|
// ASCII whitespace is collapsed to a single space per CSS `white-space: normal;`
|
|
291
|
-
|
|
292
|
-
const tokens =
|
|
342
|
+
const normalizedText = text.replace(/[\t\n\r ]+/g, " ");
|
|
343
|
+
const tokens = normalizedText.match(/\s|[\u3000-\u9FFF\uFF00-\uFFEF]|[^\s\u3000-\u9FFF\uFF00-\uFFEF]+/g);
|
|
293
344
|
if (!tokens) {
|
|
294
345
|
return [];
|
|
295
346
|
}
|
|
@@ -318,7 +369,7 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
318
369
|
if (currentWidth === 0) {
|
|
319
370
|
continue;
|
|
320
371
|
}
|
|
321
|
-
lines[lines.length - 1]
|
|
372
|
+
lines[lines.length - 1] = (lines[lines.length - 1] ?? "") + token;
|
|
322
373
|
currentWidth += measureText(token, fontSize);
|
|
323
374
|
continue;
|
|
324
375
|
}
|
|
@@ -326,7 +377,7 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
326
377
|
while (remaining) {
|
|
327
378
|
const w = measureText(remaining, fontSize);
|
|
328
379
|
if (currentWidth + w <= maxWidth) {
|
|
329
|
-
lines[lines.length - 1]
|
|
380
|
+
lines[lines.length - 1] = (lines[lines.length - 1] ?? "") + remaining;
|
|
330
381
|
currentWidth += w;
|
|
331
382
|
break;
|
|
332
383
|
}
|
|
@@ -337,7 +388,7 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
337
388
|
}
|
|
338
389
|
// An atom wider than the box wraps mid-glyph (overflow-wrap: anywhere).
|
|
339
390
|
const { segment, width } = takeFittingSegment(remaining, maxWidth);
|
|
340
|
-
lines[lines.length - 1]
|
|
391
|
+
lines[lines.length - 1] = (lines[lines.length - 1] ?? "") + segment;
|
|
341
392
|
currentWidth = width;
|
|
342
393
|
remaining = remaining.slice(segment.length);
|
|
343
394
|
}
|
|
@@ -348,11 +399,11 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
348
399
|
* Estimate how many lines a string will wrap to when laid out greedily at the
|
|
349
400
|
* given font size inside a box of width `maxWidth`, capped at `maxLines`.
|
|
350
401
|
*
|
|
351
|
-
* @param
|
|
352
|
-
* @param
|
|
353
|
-
* @param
|
|
354
|
-
* @param
|
|
355
|
-
* @returns
|
|
402
|
+
* @param text Text to estimate.
|
|
403
|
+
* @param fontSize Font size in px (matches `measureText`).
|
|
404
|
+
* @param maxWidth Available wrap width in px.
|
|
405
|
+
* @param maxLines Cap on the returned line count.
|
|
406
|
+
* @returns Estimated line count, at least 1, at most `maxLines`.
|
|
356
407
|
*/
|
|
357
408
|
const countWrappedLines = (text, fontSize, maxWidth, maxLines) => {
|
|
358
409
|
return Math.min(Math.max(1, splitWrappedText(text, fontSize, maxWidth).length), maxLines);
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
import type { AxiosResponse } from "axios";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Error-detection fields the retryer inspects to detect rate-limiting and credential failures.
|
|
4
|
+
* Every fetcher's payload is intersected with
|
|
5
|
+
* this, so the retryer can read `errors`/`message` regardless of the payload's own shape.
|
|
5
6
|
*/
|
|
6
|
-
interface
|
|
7
|
+
interface ResponseErrors {
|
|
7
8
|
errors?: Array<{
|
|
8
9
|
type?: string;
|
|
9
10
|
message?: string;
|
|
10
11
|
}>;
|
|
11
12
|
message?: string;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* A fetcher's Axios response. `TData` is the shape of `response.data`,
|
|
16
|
+
* which is intersected with {@link ResponseErrors} so the retryer can inspect
|
|
17
|
+
* `errors`/`message`.
|
|
18
|
+
* Defaults to `unknown` (error fields only) for callers that don't care about the payload.
|
|
19
|
+
*/
|
|
20
|
+
type FetcherResponse<TData = unknown> = AxiosResponse<TData & ResponseErrors>;
|
|
21
|
+
type FetcherFunction<TData = unknown> = (variables: Record<string, unknown>, token: string, retriesForTests?: number) => Promise<FetcherResponse<TData>>;
|
|
15
22
|
/**
|
|
16
23
|
* Try to execute the fetcher function until it succeeds or the max number of retries is reached.
|
|
17
24
|
*
|
|
25
|
+
* @template TData Shape of `response.data` returned by the fetcher.
|
|
18
26
|
* @param fetcher The fetcher function.
|
|
19
27
|
* @param variables Object with arguments to pass to the fetcher function.
|
|
20
28
|
* @param pat Optional PAT override.
|
|
21
29
|
* @returns The response from the fetcher function.
|
|
22
30
|
*/
|
|
23
|
-
declare const retryer: (fetcher: FetcherFunction
|
|
31
|
+
declare const retryer: <TData = unknown>(fetcher: FetcherFunction<TData>, variables: Record<string, unknown>, pat?: string | null) => Promise<FetcherResponse<TData>>;
|
|
24
32
|
export { retryer };
|
|
25
33
|
//# sourceMappingURL=retryer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryer.d.ts","sourceRoot":"","sources":["../../src/common/retryer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAM3C
|
|
1
|
+
{"version":3,"file":"retryer.d.ts","sourceRoot":"","sources":["../../src/common/retryer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAM3C;;;;GAIG;AACH,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAgBD;;;;;GAKG;AACH,KAAK,eAAe,CAAC,KAAK,GAAG,OAAO,IAAI,aAAa,CAAC,KAAK,GAAG,cAAc,CAAC,CAAC;AAE9E,KAAK,eAAe,CAAC,KAAK,GAAG,OAAO,IAAI,CACtC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AAErC;;;;;;;;GAQG;AACH,QAAA,MAAM,OAAO,GAAU,KAAK,GAAG,OAAO,EACpC,SAAS,eAAe,CAAC,KAAK,CAAC,EAC/B,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,MAAK,MAAM,GAAG,IAAW,KACxB,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAiEhC,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/build/common/retryer.js
CHANGED
|
@@ -17,6 +17,7 @@ function getRandomInt(max) {
|
|
|
17
17
|
/**
|
|
18
18
|
* Try to execute the fetcher function until it succeeds or the max number of retries is reached.
|
|
19
19
|
*
|
|
20
|
+
* @template TData Shape of `response.data` returned by the fetcher.
|
|
20
21
|
* @param fetcher The fetcher function.
|
|
21
22
|
* @param variables Object with arguments to pass to the fetcher function.
|
|
22
23
|
* @param pat Optional PAT override.
|
package/build/fetchers/gist.d.ts
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
* Gist file.
|
|
3
|
-
*/
|
|
4
|
-
export type GistFile = {
|
|
5
|
-
name: string;
|
|
6
|
-
language: {
|
|
7
|
-
name: string;
|
|
8
|
-
};
|
|
9
|
-
size: number;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Gist data.
|
|
13
|
-
*/
|
|
14
|
-
export type GistData = any;
|
|
15
|
-
/**
|
|
16
|
-
* @typedef {import('./types').GistData} GistData Gist data.
|
|
17
|
-
*/
|
|
1
|
+
import type { GistData } from "./types.js";
|
|
18
2
|
/**
|
|
19
3
|
* Fetch GitHub gist information by given username and ID.
|
|
20
4
|
*
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @returns
|
|
5
|
+
* @param id GitHub gist ID.
|
|
6
|
+
* @param pat Optional PAT override.
|
|
7
|
+
* @returns Gist data.
|
|
24
8
|
*/
|
|
25
|
-
|
|
9
|
+
declare const fetchGist: (id: string, pat?: string | null) => Promise<GistData>;
|
|
10
|
+
export { fetchGist };
|
|
26
11
|
//# sourceMappingURL=gist.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gist.d.ts","sourceRoot":"","sources":["../../src/fetchers/gist.
|
|
1
|
+
{"version":3,"file":"gist.d.ts","sourceRoot":"","sources":["../../src/fetchers/gist.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6F3C;;;;;;GAMG;AACH,QAAA,MAAM,SAAS,GACb,IAAI,MAAM,EACV,MAAK,MAAM,GAAG,IAAW,KACxB,OAAO,CAAC,QAAQ,CAwBlB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/build/fetchers/gist.js
CHANGED
|
@@ -27,52 +27,43 @@ query gistInfo($gistName: String!) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Gist data fetcher.
|
|
29
29
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @returns
|
|
30
|
+
* @param variables Fetcher variables.
|
|
31
|
+
* @param token GitHub token.
|
|
32
|
+
* @returns The response.
|
|
33
33
|
*/
|
|
34
|
-
const fetcher =
|
|
35
|
-
return
|
|
34
|
+
const fetcher = (variables, token) => {
|
|
35
|
+
return request({ query: QUERY, variables }, { Authorization: `token ${token}` });
|
|
36
36
|
};
|
|
37
|
-
/**
|
|
38
|
-
* @typedef {{ name: string; language: { name: string; }, size: number }} GistFile Gist file.
|
|
39
|
-
*/
|
|
40
37
|
/**
|
|
41
38
|
* This function calculates the primary language of a gist by files size.
|
|
42
39
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @returns
|
|
40
|
+
* @param files Files.
|
|
41
|
+
* @returns Primary language, or `null` when no file has a language.
|
|
45
42
|
*/
|
|
46
43
|
const calculatePrimaryLanguage = (files) => {
|
|
47
|
-
/** @type {Record<string, number>} */
|
|
48
44
|
const languages = {};
|
|
49
45
|
for (const file of files) {
|
|
50
46
|
if (file.language) {
|
|
51
|
-
|
|
52
|
-
languages[file.language.name]
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
languages[file.language.name] = file.size;
|
|
56
|
-
}
|
|
47
|
+
languages[file.language.name] =
|
|
48
|
+
(languages[file.language.name] ?? 0) + file.size;
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
|
-
let primaryLanguage =
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
let primaryLanguage = null;
|
|
52
|
+
let maxSize = -1;
|
|
53
|
+
for (const [language, size] of Object.entries(languages)) {
|
|
54
|
+
if (size > maxSize) {
|
|
55
|
+
maxSize = size;
|
|
62
56
|
primaryLanguage = language;
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
59
|
return primaryLanguage;
|
|
66
60
|
};
|
|
67
|
-
/**
|
|
68
|
-
* @typedef {import('./types').GistData} GistData Gist data.
|
|
69
|
-
*/
|
|
70
61
|
/**
|
|
71
62
|
* Fetch GitHub gist information by given username and ID.
|
|
72
63
|
*
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
75
|
-
* @returns
|
|
64
|
+
* @param id GitHub gist ID.
|
|
65
|
+
* @param pat Optional PAT override.
|
|
66
|
+
* @returns Gist data.
|
|
76
67
|
*/
|
|
77
68
|
const fetchGist = async (id, pat = null) => {
|
|
78
69
|
if (!id) {
|
|
@@ -80,19 +71,23 @@ const fetchGist = async (id, pat = null) => {
|
|
|
80
71
|
}
|
|
81
72
|
const res = await retryer(fetcher, { gistName: id }, pat);
|
|
82
73
|
if (res.data.errors) {
|
|
83
|
-
throw new Error(res.data.errors[0]
|
|
74
|
+
throw new Error(res.data.errors[0]?.message);
|
|
84
75
|
}
|
|
85
|
-
|
|
76
|
+
const gist = res.data.data.viewer.gist;
|
|
77
|
+
if (!gist) {
|
|
86
78
|
throw new Error("Gist not found");
|
|
87
79
|
}
|
|
88
|
-
const
|
|
80
|
+
const firstFile = gist.files[0];
|
|
81
|
+
if (!firstFile) {
|
|
82
|
+
throw new Error("Gist has no files");
|
|
83
|
+
}
|
|
89
84
|
return {
|
|
90
|
-
name:
|
|
91
|
-
nameWithOwner: `${
|
|
92
|
-
description:
|
|
93
|
-
language: calculatePrimaryLanguage(
|
|
94
|
-
starsCount:
|
|
95
|
-
forksCount:
|
|
85
|
+
name: firstFile.name,
|
|
86
|
+
nameWithOwner: `${gist.owner.login}/${firstFile.name}`,
|
|
87
|
+
description: gist.description,
|
|
88
|
+
language: calculatePrimaryLanguage(gist.files),
|
|
89
|
+
starsCount: gist.stargazerCount,
|
|
90
|
+
forksCount: gist.forks.totalCount,
|
|
96
91
|
};
|
|
97
92
|
};
|
|
98
93
|
export { fetchGist };
|
package/build/fetchers/repo.js
CHANGED
|
@@ -45,7 +45,7 @@ const fetcher = (variables, token) => {
|
|
|
45
45
|
Authorization: `token ${token}`,
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
-
const urlExample = "/api/pin?username=USERNAME&
|
|
48
|
+
const urlExample = "/api/pin?username=USERNAME&repo=REPO_NAME";
|
|
49
49
|
/**
|
|
50
50
|
* @typedef {import("./types").RepositoryData} RepositoryData Repository data.
|
|
51
51
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/fetchers/stats.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/fetchers/stats.js"],"names":[],"mappings":"AAkTA;;;;;;;;;;;;GAYG;AACH,qCAVW,MAAM,uBACN,OAAO,4BACP,MAAM,EAAE,4CACR,OAAO,mCACP,OAAO,2CACP,OAAO,4BACP,MAAM,GAAC,SAAS,2NAChB,MAAM,EAAE,eACN,OAAO,CAAC,GAA2B,CAAC,CAyJhD;AArOD;;;;;;GA+DC"}
|
package/build/fetchers/stats.js
CHANGED
|
@@ -134,7 +134,6 @@ const statsFetcher = async ({ username, includeMergedPullRequests, includeDiscus
|
|
|
134
134
|
else {
|
|
135
135
|
stats = res;
|
|
136
136
|
}
|
|
137
|
-
// Disable multi page fetching on public Vercel instance due to rate limits.
|
|
138
137
|
fetchedPages++;
|
|
139
138
|
const repoNodesWithStars = repoNodes.filter((node) => node.stargazerCount !== 0);
|
|
140
139
|
hasNextPage =
|