@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/render.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
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
|
+
import { kFormatter } from "./fmt.js";
|
|
3
4
|
import { encodeHTML } from "./html.js";
|
|
4
5
|
import { clampValue } from "./ops.js";
|
|
5
6
|
/**
|
|
6
7
|
* Auto layout utility, allows us to layout things vertically or horizontally with
|
|
7
8
|
* proper gaping.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
10
|
+
* The caller must ensure that the passed `items` are properly sanitized!
|
|
11
|
+
*
|
|
12
|
+
* @param props Function properties.
|
|
13
|
+
* @param props.items Array of sanitized items to layout.
|
|
14
|
+
* @param props.gap Gap between items.
|
|
15
|
+
* @param props.direction Direction to layout items.
|
|
16
|
+
* @param props.sizes Array of sizes for each item.
|
|
17
|
+
* @returns Array of items with proper layout.
|
|
15
18
|
*/
|
|
16
|
-
const flexLayout = ({ items, gap, direction, sizes = [] }) => {
|
|
19
|
+
const flexLayout = ({ items, gap, direction, sizes = [], }) => {
|
|
20
|
+
if (sizes.some((size) => !Number.isFinite(size))) {
|
|
21
|
+
throw new Error("flexLayout: `sizes` must contain only numbers");
|
|
22
|
+
}
|
|
17
23
|
let lastSize = 0;
|
|
18
24
|
// filter() for filtering out empty strings
|
|
19
25
|
return items.filter(Boolean).map((item, i) => {
|
|
@@ -29,40 +35,58 @@ const flexLayout = ({ items, gap, direction, sizes = [] }) => {
|
|
|
29
35
|
/**
|
|
30
36
|
* Creates a node to display the primary programming language of the repository/gist.
|
|
31
37
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns
|
|
38
|
+
* @param langName Language name.
|
|
39
|
+
* @param langColor Language color.
|
|
40
|
+
* @returns Language display SVG object.
|
|
35
41
|
*/
|
|
36
42
|
const createLanguageNode = (langName, langColor) => {
|
|
43
|
+
if (!isPrefixedHexColor(langColor)) {
|
|
44
|
+
throw new Error(`Invalid language color: "${langColor}"`);
|
|
45
|
+
}
|
|
37
46
|
return `
|
|
38
47
|
<g data-testid="primary-lang">
|
|
39
48
|
<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>
|
|
49
|
+
<text data-testid="lang-name" class="gray" x="15">${encodeHTML(langName)}</text>
|
|
41
50
|
</g>
|
|
42
51
|
`;
|
|
43
52
|
};
|
|
44
53
|
/**
|
|
45
54
|
* Create a node to indicate progress in percentage along a horizontal line.
|
|
46
55
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
*
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @returns
|
|
56
|
+
* @param params Object that contains the createProgressNode parameters.
|
|
57
|
+
* @param params.x X-axis position.
|
|
58
|
+
* @param params.y Y-axis position.
|
|
59
|
+
* @param params.width Width of progress bar.
|
|
60
|
+
* @param params.color Optional foreground color as an inline fill fallback.
|
|
61
|
+
* When omitted, the color must be set via a `.lang-progress` CSS rule.
|
|
62
|
+
* @param params.progress Progress value.
|
|
63
|
+
* @param params.delay Delay before animation starts.
|
|
64
|
+
* @returns Progress node.
|
|
56
65
|
*/
|
|
57
|
-
const createProgressNode = ({ x, y, width, color, progress,
|
|
66
|
+
const createProgressNode = ({ x, y, width, color, progress, delay, }) => {
|
|
67
|
+
if (color !== undefined && !isPrefixedHexColor(color)) {
|
|
68
|
+
throw new Error(`Invalid progress color: "${color}"`);
|
|
69
|
+
}
|
|
70
|
+
if (!Number.isFinite(width)) {
|
|
71
|
+
throw new Error(`Invalid width: "${width}"`);
|
|
72
|
+
}
|
|
73
|
+
if (!Number.isFinite(x)) {
|
|
74
|
+
throw new Error(`Invalid x: "${x}"`);
|
|
75
|
+
}
|
|
76
|
+
if (!Number.isFinite(y)) {
|
|
77
|
+
throw new Error(`Invalid y: "${y}"`);
|
|
78
|
+
}
|
|
79
|
+
if (!Number.isFinite(delay)) {
|
|
80
|
+
throw new Error(`Invalid delay: "${delay}"`);
|
|
81
|
+
}
|
|
58
82
|
const progressPercentage = clampValue(progress, 2, 100);
|
|
59
83
|
return `
|
|
60
84
|
<svg width="${width}" x="${x}" y="${y}">
|
|
61
|
-
<rect data-testid="progress-background" rx="5" ry="5" x="0" y="0" width="${width}" height="8"
|
|
85
|
+
<rect data-testid="progress-background" class="progress-background" rx="5" ry="5" x="0" y="0" width="${width}" height="8"></rect>
|
|
62
86
|
<svg data-testid="lang-progress" width="${progressPercentage}%">
|
|
63
87
|
<rect
|
|
64
88
|
height="8"
|
|
65
|
-
fill="${color}"
|
|
89
|
+
${color === undefined ? "" : `fill="${color}"`}
|
|
66
90
|
rx="5" ry="5" x="0" y="0"
|
|
67
91
|
class="lang-progress"
|
|
68
92
|
style="animation-delay: ${delay}ms;"
|
|
@@ -76,22 +100,37 @@ const createProgressNode = ({ x, y, width, color, progress, progressBarBackgroun
|
|
|
76
100
|
* native, font-aware wrapping. Content overflowing `lineCount` lines is
|
|
77
101
|
* clipped (with an ellipsis on the last visible line) by CSS line-clamp.
|
|
78
102
|
*
|
|
79
|
-
* @param
|
|
80
|
-
* @param
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* @param
|
|
88
|
-
* @returns
|
|
103
|
+
* @param props Function properties.
|
|
104
|
+
* @param props.text Text to render (will be HTML-encoded).
|
|
105
|
+
* @param props.x X position of the foreignObject.
|
|
106
|
+
* @param props.y Y position of the foreignObject.
|
|
107
|
+
* @param props.width Width of the wrap box.
|
|
108
|
+
* @param props.height Height of the wrap box.
|
|
109
|
+
* @param props.lineCount Maximum number of lines to display.
|
|
110
|
+
* @param props.className CSS class applied to the inner element.
|
|
111
|
+
* @param props.testId Optional test id for the inner element.
|
|
112
|
+
* @returns foreignObject SVG node.
|
|
89
113
|
*/
|
|
90
114
|
const wrappedTextNode = ({ text, x, y, width, height, lineCount, className, testId, }) => {
|
|
91
|
-
|
|
115
|
+
if (!Number.isFinite(x)) {
|
|
116
|
+
throw new Error(`Invalid x: "${x}"`);
|
|
117
|
+
}
|
|
118
|
+
if (!Number.isFinite(y)) {
|
|
119
|
+
throw new Error(`Invalid y: "${y}"`);
|
|
120
|
+
}
|
|
121
|
+
if (!Number.isFinite(width)) {
|
|
122
|
+
throw new Error(`Invalid width: "${width}"`);
|
|
123
|
+
}
|
|
124
|
+
if (!Number.isFinite(height)) {
|
|
125
|
+
throw new Error(`Invalid height: "${height}"`);
|
|
126
|
+
}
|
|
127
|
+
if (!Number.isFinite(lineCount)) {
|
|
128
|
+
throw new Error(`Invalid lineCount: "${lineCount}"`);
|
|
129
|
+
}
|
|
130
|
+
const testIdAttr = testId ? ` data-testid="${encodeHTML(testId)}"` : "";
|
|
92
131
|
return `
|
|
93
132
|
<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>
|
|
133
|
+
<div xmlns="http://www.w3.org/1999/xhtml" class="${encodeHTML(className)}" style="--lines: ${lineCount};"${testIdAttr}>${encodeHTML(text)}</div>
|
|
95
134
|
</foreignObject>
|
|
96
135
|
`;
|
|
97
136
|
};
|
|
@@ -101,36 +140,46 @@ const wrappedTextNode = ({ text, x, y, width, height, lineCount, className, test
|
|
|
101
140
|
* browser handles wrapping and the line count is taken from the `--lines`
|
|
102
141
|
* custom property set on the element.
|
|
103
142
|
*
|
|
104
|
-
* @param
|
|
105
|
-
* @returns
|
|
143
|
+
* @param color Text color (CSS `color` property).
|
|
144
|
+
* @returns CSS rules block (without the surrounding selector).
|
|
106
145
|
*/
|
|
107
|
-
const wrappedTextStyles = (color) =>
|
|
108
|
-
color
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
146
|
+
const wrappedTextStyles = (color) => {
|
|
147
|
+
if (!isPrefixedHexColor(color)) {
|
|
148
|
+
throw new Error(`Invalid text color: "${color}"`);
|
|
149
|
+
}
|
|
150
|
+
return `
|
|
151
|
+
color: ${color};
|
|
152
|
+
margin: 0;
|
|
153
|
+
line-height: 1.2;
|
|
154
|
+
overflow-wrap: anywhere;
|
|
155
|
+
word-break: break-word;
|
|
156
|
+
display: -webkit-box;
|
|
157
|
+
-webkit-box-orient: vertical;
|
|
158
|
+
-webkit-line-clamp: var(--lines);
|
|
159
|
+
line-clamp: var(--lines);
|
|
160
|
+
overflow: hidden;
|
|
161
|
+
text-overflow: ellipsis;
|
|
162
|
+
padding-bottom: 0.15em;
|
|
163
|
+
`;
|
|
164
|
+
};
|
|
121
165
|
/**
|
|
122
166
|
* Creates an icon with label to display repository/gist stats like forks, stars, etc.
|
|
123
167
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @param
|
|
127
|
-
* @param
|
|
128
|
-
* @
|
|
168
|
+
* The caller must ensure that the passed `icon` is properly sanitized!
|
|
169
|
+
*
|
|
170
|
+
* @param icon The sanitized icon to display.
|
|
171
|
+
* @param label The label to display.
|
|
172
|
+
* @param testid The testid to assign to the label.
|
|
173
|
+
* @param iconSize The size of the icon.
|
|
174
|
+
* @returns Icon with label SVG object.
|
|
129
175
|
*/
|
|
130
176
|
const iconWithLabel = (icon, label, testid, iconSize) => {
|
|
131
177
|
if (typeof label === "number" && label <= 0) {
|
|
132
178
|
return "";
|
|
133
179
|
}
|
|
180
|
+
if (!Number.isFinite(iconSize)) {
|
|
181
|
+
throw new Error(`Invalid iconSize: "${iconSize}"`);
|
|
182
|
+
}
|
|
134
183
|
const iconSvg = `
|
|
135
184
|
<svg
|
|
136
185
|
class="icon"
|
|
@@ -143,9 +192,78 @@ const iconWithLabel = (icon, label, testid, iconSize) => {
|
|
|
143
192
|
${icon}
|
|
144
193
|
</svg>
|
|
145
194
|
`;
|
|
146
|
-
const text = `<text data-testid="${testid}" class="gray">${label}</text>`;
|
|
195
|
+
const text = `<text data-testid="${encodeHTML(testid)}" class="gray">${encodeHTML(String(label))}</text>`;
|
|
147
196
|
return flexLayout({ items: [iconSvg, text], gap: 20 }).join("");
|
|
148
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Create a labelled stat text item
|
|
200
|
+
* (a label and its value, optionally with an icon and link).
|
|
201
|
+
* Shared by the stats and repo cards.
|
|
202
|
+
*
|
|
203
|
+
* The caller must ensure that the passed `icon` and `link` are properly sanitized!
|
|
204
|
+
*
|
|
205
|
+
* @param params Object that contains the createTextNode parameters.
|
|
206
|
+
* @param params.icon The sanitized icon to display.
|
|
207
|
+
* @param params.label The label to display.
|
|
208
|
+
* @param params.value The value to display.
|
|
209
|
+
* @param params.id The id of the stat.
|
|
210
|
+
* @param params.unitSymbol The unit symbol of the stat.
|
|
211
|
+
* @param params.index The index of the stat.
|
|
212
|
+
* @param params.showIcons Whether to show icons.
|
|
213
|
+
* @param params.shiftValuePos Number of pixels the value has to be shifted to the right.
|
|
214
|
+
* @param params.bold Whether to bold the label.
|
|
215
|
+
* @param params.numberFormat The format of numbers on card.
|
|
216
|
+
* @param params.numberPrecision The precision of numbers on card.
|
|
217
|
+
* @param params.link Sanitized url to link to.
|
|
218
|
+
* @param params.labelXOffset horizontal offset for label.
|
|
219
|
+
* @returns The stats card text item SVG object.
|
|
220
|
+
*/
|
|
221
|
+
const createTextNode = ({ icon, label, value, id, unitSymbol, index, showIcons, shiftValuePos, bold, numberFormat, numberPrecision, link, labelXOffset = 25, }) => {
|
|
222
|
+
if (!Number.isFinite(labelXOffset)) {
|
|
223
|
+
throw new Error(`Invalid labelXOffset: "${labelXOffset}"`);
|
|
224
|
+
}
|
|
225
|
+
if (!Number.isFinite(shiftValuePos)) {
|
|
226
|
+
throw new Error(`Invalid shiftValuePos: "${shiftValuePos}"`);
|
|
227
|
+
}
|
|
228
|
+
if (!Number.isFinite(index)) {
|
|
229
|
+
throw new Error(`Invalid index: "${index}"`);
|
|
230
|
+
}
|
|
231
|
+
const precision = numberPrecision !== undefined && Number.isFinite(numberPrecision)
|
|
232
|
+
? clampValue(numberPrecision, 0, 2)
|
|
233
|
+
: undefined;
|
|
234
|
+
// `long` format and the percentage stat keep the raw value; everything else
|
|
235
|
+
// (always a number here) is abbreviated via kFormatter.
|
|
236
|
+
const rawValue = numberFormat.toLowerCase() === "long" || id === "prs_merged_percentage";
|
|
237
|
+
const kValue = rawValue || typeof value !== "number"
|
|
238
|
+
? value
|
|
239
|
+
: kFormatter(value, precision);
|
|
240
|
+
const staggerDelay = (index + 3) * 150;
|
|
241
|
+
const boldClass = bold ? " bold" : "not_bold";
|
|
242
|
+
const valueX = (showIcons ? 140 : 120) + (bold ? 5 : 0) + shiftValuePos;
|
|
243
|
+
const unit = unitSymbol ? ` ${unitSymbol}` : "";
|
|
244
|
+
const labelOffset = showIcons ? `x="${labelXOffset}"` : "";
|
|
245
|
+
const iconSvg = showIcons
|
|
246
|
+
? `
|
|
247
|
+
<svg data-testid="icon" class="icon" viewBox="0 0 16 16" version="1.1" width="16" height="16">
|
|
248
|
+
${icon}
|
|
249
|
+
</svg>
|
|
250
|
+
`
|
|
251
|
+
: "";
|
|
252
|
+
const content = `
|
|
253
|
+
${iconSvg}
|
|
254
|
+
<text class="stat ${boldClass}" ${labelOffset} y="12.5">${encodeHTML(label)}:</text>
|
|
255
|
+
<text
|
|
256
|
+
class="stat ${boldClass}"
|
|
257
|
+
x="${valueX}"
|
|
258
|
+
y="12.5"
|
|
259
|
+
data-testid="${id}"
|
|
260
|
+
>${kValue}${unit}</text>`;
|
|
261
|
+
const inner = link ? `<a href="${link}">${content}</a>` : content;
|
|
262
|
+
return `
|
|
263
|
+
<g class="stagger" style="animation-delay: ${staggerDelay}ms" transform="translate(25, 0)">${inner}
|
|
264
|
+
</g>
|
|
265
|
+
`;
|
|
266
|
+
};
|
|
149
267
|
// Script parameters.
|
|
150
268
|
const ERROR_CARD_LENGTH = 576.5;
|
|
151
269
|
const UPSTREAM_API_ERRORS = [
|
|
@@ -155,21 +273,20 @@ const UPSTREAM_API_ERRORS = [
|
|
|
155
273
|
/**
|
|
156
274
|
* Renders error message on the card.
|
|
157
275
|
*
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
161
|
-
* @param
|
|
162
|
-
* @param
|
|
163
|
-
* @param
|
|
164
|
-
* @param
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @returns
|
|
276
|
+
* @param args Function arguments.
|
|
277
|
+
* @param args.message Main error message.
|
|
278
|
+
* @param args.secondaryMessage The secondary error message.
|
|
279
|
+
* @param args.renderOptions Render options.
|
|
280
|
+
* @param args.renderOptions.title_color Card title color.
|
|
281
|
+
* @param args.renderOptions.text_color Card text color.
|
|
282
|
+
* @param args.renderOptions.bg_color Card background color.
|
|
283
|
+
* @param args.renderOptions.border_color Card border color.
|
|
284
|
+
* @param args.renderOptions.theme Card theme.
|
|
285
|
+
* @param args.renderOptions.show_repo_link Whether to show repo link or not.
|
|
286
|
+
* @returns The SVG markup.
|
|
169
287
|
*/
|
|
170
288
|
const renderError = ({ message, secondaryMessage = "", renderOptions = {}, }) => {
|
|
171
289
|
const { title_color, text_color, bg_color, border_color, theme = "default", show_repo_link = true, } = renderOptions;
|
|
172
|
-
// returns theme based colors with proper overrides and defaults
|
|
173
290
|
const { titleColor, textColor, bgColor, borderColor } = getCardColors({
|
|
174
291
|
title_color,
|
|
175
292
|
text_color,
|
|
@@ -180,19 +297,19 @@ const renderError = ({ message, secondaryMessage = "", renderOptions = {}, }) =>
|
|
|
180
297
|
theme,
|
|
181
298
|
});
|
|
182
299
|
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">
|
|
300
|
+
<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
301
|
<style>
|
|
185
302
|
.text { font: 600 16px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${titleColor} }
|
|
186
303
|
.small { font: 600 12px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
|
|
187
304
|
.gray { fill: #858585 }
|
|
188
305
|
</style>
|
|
189
|
-
<rect x="0.5" y="0.5" width="${ERROR_CARD_LENGTH - 1}" height="99%" rx="4.5" fill="${bgColor}" stroke="${borderColor}"/>
|
|
306
|
+
<rect x="0.5" y="0.5" width="${ERROR_CARD_LENGTH - 1}" height="99%" rx="4.5" fill="${String(bgColor)}" stroke="${borderColor}"/>
|
|
190
307
|
<text x="25" y="45" class="text">Something went wrong!${UPSTREAM_API_ERRORS.includes(secondaryMessage) || !show_repo_link
|
|
191
308
|
? ""
|
|
192
309
|
: " file an issue at https://tinyurl.com/github-stats"}</text>
|
|
193
310
|
<text data-testid="message" x="25" y="55" class="text small">
|
|
194
311
|
<tspan x="25" dy="18">${encodeHTML(message)}</tspan>
|
|
195
|
-
<tspan x="25" dy="18" class="gray">${secondaryMessage}</tspan>
|
|
312
|
+
<tspan x="25" dy="18" class="gray">${encodeHTML(secondaryMessage)}</tspan>
|
|
196
313
|
</text>
|
|
197
314
|
</svg>
|
|
198
315
|
`;
|
|
@@ -201,9 +318,9 @@ const renderError = ({ message, secondaryMessage = "", renderOptions = {}, }) =>
|
|
|
201
318
|
* Retrieve text length based on Segoe UI font.
|
|
202
319
|
*
|
|
203
320
|
* @see https://stackoverflow.com/a/48172630/10629172
|
|
204
|
-
* @param
|
|
205
|
-
* @param
|
|
206
|
-
* @returns
|
|
321
|
+
* @param str String to measure.
|
|
322
|
+
* @param fontSize Font size.
|
|
323
|
+
* @returns Text length.
|
|
207
324
|
*/
|
|
208
325
|
const measureText = (str, fontSize = 10) => {
|
|
209
326
|
// prettier-ignore
|
|
@@ -254,7 +371,7 @@ const measureText = (str, fontSize = 10) => {
|
|
|
254
371
|
return 1;
|
|
255
372
|
}
|
|
256
373
|
if (c.charCodeAt(0) < widths.length) {
|
|
257
|
-
return widths[c.charCodeAt(0)];
|
|
374
|
+
return widths[c.charCodeAt(0)] ?? avg;
|
|
258
375
|
}
|
|
259
376
|
else {
|
|
260
377
|
return avg;
|
|
@@ -269,10 +386,10 @@ const measureText = (str, fontSize = 10) => {
|
|
|
269
386
|
* The browser still does the real wrap inside the foreignObject; this is only
|
|
270
387
|
* used to size the SVG.
|
|
271
388
|
*
|
|
272
|
-
* @param
|
|
273
|
-
* @param
|
|
274
|
-
* @param
|
|
275
|
-
* @returns
|
|
389
|
+
* @param text Text to split.
|
|
390
|
+
* @param fontSize Font size in px (matches `measureText`).
|
|
391
|
+
* @param maxWidth Available wrap width in px.
|
|
392
|
+
* @returns Estimated wrapped lines.
|
|
276
393
|
*/
|
|
277
394
|
const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
278
395
|
if (!text) {
|
|
@@ -288,8 +405,8 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
288
405
|
// Korean Hangul (U+AC00–U+D7AF) is intentionally NOT in the CJK range
|
|
289
406
|
// because Korean wraps at word boundaries by default in HTML.
|
|
290
407
|
// ASCII whitespace is collapsed to a single space per CSS `white-space: normal;`
|
|
291
|
-
|
|
292
|
-
const tokens =
|
|
408
|
+
const normalizedText = text.replace(/[\t\n\r ]+/g, " ");
|
|
409
|
+
const tokens = normalizedText.match(/\s|[\u3000-\u9FFF\uFF00-\uFFEF]|[^\s\u3000-\u9FFF\uFF00-\uFFEF]+/g);
|
|
293
410
|
if (!tokens) {
|
|
294
411
|
return [];
|
|
295
412
|
}
|
|
@@ -318,7 +435,7 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
318
435
|
if (currentWidth === 0) {
|
|
319
436
|
continue;
|
|
320
437
|
}
|
|
321
|
-
lines[lines.length - 1]
|
|
438
|
+
lines[lines.length - 1] = (lines[lines.length - 1] ?? "") + token;
|
|
322
439
|
currentWidth += measureText(token, fontSize);
|
|
323
440
|
continue;
|
|
324
441
|
}
|
|
@@ -326,7 +443,7 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
326
443
|
while (remaining) {
|
|
327
444
|
const w = measureText(remaining, fontSize);
|
|
328
445
|
if (currentWidth + w <= maxWidth) {
|
|
329
|
-
lines[lines.length - 1]
|
|
446
|
+
lines[lines.length - 1] = (lines[lines.length - 1] ?? "") + remaining;
|
|
330
447
|
currentWidth += w;
|
|
331
448
|
break;
|
|
332
449
|
}
|
|
@@ -337,7 +454,7 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
337
454
|
}
|
|
338
455
|
// An atom wider than the box wraps mid-glyph (overflow-wrap: anywhere).
|
|
339
456
|
const { segment, width } = takeFittingSegment(remaining, maxWidth);
|
|
340
|
-
lines[lines.length - 1]
|
|
457
|
+
lines[lines.length - 1] = (lines[lines.length - 1] ?? "") + segment;
|
|
341
458
|
currentWidth = width;
|
|
342
459
|
remaining = remaining.slice(segment.length);
|
|
343
460
|
}
|
|
@@ -348,13 +465,13 @@ const splitWrappedText = (text, fontSize, maxWidth) => {
|
|
|
348
465
|
* Estimate how many lines a string will wrap to when laid out greedily at the
|
|
349
466
|
* given font size inside a box of width `maxWidth`, capped at `maxLines`.
|
|
350
467
|
*
|
|
351
|
-
* @param
|
|
352
|
-
* @param
|
|
353
|
-
* @param
|
|
354
|
-
* @param
|
|
355
|
-
* @returns
|
|
468
|
+
* @param text Text to estimate.
|
|
469
|
+
* @param fontSize Font size in px (matches `measureText`).
|
|
470
|
+
* @param maxWidth Available wrap width in px.
|
|
471
|
+
* @param maxLines Cap on the returned line count.
|
|
472
|
+
* @returns Estimated line count, at least 1, at most `maxLines`.
|
|
356
473
|
*/
|
|
357
474
|
const countWrappedLines = (text, fontSize, maxWidth, maxLines) => {
|
|
358
475
|
return Math.min(Math.max(1, splitWrappedText(text, fontSize, maxWidth).length), maxLines);
|
|
359
476
|
};
|
|
360
|
-
export { renderError, createLanguageNode, createProgressNode, iconWithLabel, flexLayout, measureText, splitWrappedText, countWrappedLines, wrappedTextNode, wrappedTextStyles, };
|
|
477
|
+
export { renderError, createLanguageNode, createProgressNode, createTextNode, iconWithLabel, flexLayout, measureText, splitWrappedText, countWrappedLines, wrappedTextNode, wrappedTextStyles, };
|
|
@@ -1,25 +1,34 @@
|
|
|
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, TVariables = Record<string, unknown>> = (variables: TVariables, 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.
|
|
26
|
+
* @template TVariables Variables the fetcher accepts.
|
|
18
27
|
* @param fetcher The fetcher function.
|
|
19
28
|
* @param variables Object with arguments to pass to the fetcher function.
|
|
20
29
|
* @param pat Optional PAT override.
|
|
21
30
|
* @returns The response from the fetcher function.
|
|
22
31
|
*/
|
|
23
|
-
declare const retryer: (fetcher: FetcherFunction, variables:
|
|
32
|
+
declare const retryer: <TData = unknown, TVariables = Record<string, unknown>>(fetcher: FetcherFunction<TData, TVariables>, variables: TVariables, pat?: string | null) => Promise<FetcherResponse<TData>>;
|
|
24
33
|
export { retryer };
|
|
25
34
|
//# 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,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAC5E,SAAS,EAAE,UAAU,EACrB,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;AAErC;;;;;;;;;GASG;AACH,QAAA,MAAM,OAAO,GAAU,KAAK,GAAG,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1E,SAAS,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,EAC3C,WAAW,UAAU,EACrB,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,8 @@ 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.
|
|
21
|
+
* @template TVariables Variables the fetcher accepts.
|
|
20
22
|
* @param fetcher The fetcher function.
|
|
21
23
|
* @param variables Object with arguments to pass to the fetcher function.
|
|
22
24
|
* @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;AAkC3C;;;;;;GAMG;AACH,QAAA,MAAM,SAAS,GACb,IAAI,MAAM,EACV,MAAK,MAAM,GAAG,IAAW,KACxB,OAAO,CAAC,QAAQ,CA0BlB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|