@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.
Files changed (182) hide show
  1. package/build/api/gist.d.ts +2 -7
  2. package/build/api/gist.d.ts.map +1 -1
  3. package/build/api/gist.js +28 -26
  4. package/build/api/index.d.ts +3 -8
  5. package/build/api/index.d.ts.map +1 -1
  6. package/build/api/index.js +32 -36
  7. package/build/api/pin.d.ts +2 -7
  8. package/build/api/pin.d.ts.map +1 -1
  9. package/build/api/pin.js +18 -33
  10. package/build/api/top-langs.d.ts +2 -7
  11. package/build/api/top-langs.d.ts.map +1 -1
  12. package/build/api/top-langs.js +32 -44
  13. package/build/api/wakatime.d.ts +2 -7
  14. package/build/api/wakatime.d.ts.map +1 -1
  15. package/build/api/wakatime.js +28 -26
  16. package/build/calculateRank.d.ts +12 -11
  17. package/build/calculateRank.d.ts.map +1 -1
  18. package/build/calculateRank.js +18 -18
  19. package/build/cards/common-options.d.ts +13 -0
  20. package/build/cards/common-options.d.ts.map +1 -0
  21. package/build/cards/common-options.js +1 -0
  22. package/build/cards/gist.d.ts +11 -16
  23. package/build/cards/gist.d.ts.map +1 -1
  24. package/build/cards/gist.js +26 -31
  25. package/build/cards/repo.d.ts +19 -16
  26. package/build/cards/repo.d.ts.map +1 -1
  27. package/build/cards/repo.js +79 -72
  28. package/build/cards/stats.d.ts +29 -44
  29. package/build/cards/stats.d.ts.map +1 -1
  30. package/build/cards/stats.js +118 -173
  31. package/build/cards/top-languages.d.ts +81 -77
  32. package/build/cards/top-languages.d.ts.map +1 -1
  33. package/build/cards/top-languages.js +186 -184
  34. package/build/cards/wakatime.d.ts +21 -11
  35. package/build/cards/wakatime.d.ts.map +1 -1
  36. package/build/cards/wakatime.js +92 -109
  37. package/build/common/Card.d.ts +41 -14
  38. package/build/common/Card.d.ts.map +1 -1
  39. package/build/common/Card.js +92 -31
  40. package/build/common/I18n.d.ts +4 -2
  41. package/build/common/I18n.d.ts.map +1 -1
  42. package/build/common/color.d.ts +91 -15
  43. package/build/common/color.d.ts.map +1 -1
  44. package/build/common/color.js +163 -17
  45. package/build/common/config.d.ts +2 -1
  46. package/build/common/config.d.ts.map +1 -1
  47. package/build/common/config.js +16 -26
  48. package/build/common/constants.d.ts +2 -1
  49. package/build/common/constants.d.ts.map +1 -1
  50. package/build/common/date.d.ts +37 -0
  51. package/build/common/date.d.ts.map +1 -0
  52. package/build/common/date.js +31 -0
  53. package/build/common/html.js +1 -1
  54. package/build/common/http.d.ts +37 -5
  55. package/build/common/http.d.ts.map +1 -1
  56. package/build/common/http.js +29 -6
  57. package/build/common/icons.d.ts +1 -0
  58. package/build/common/icons.d.ts.map +1 -1
  59. package/build/common/icons.js +1 -0
  60. package/build/common/languageColors.d.ts +11 -0
  61. package/build/common/languageColors.d.ts.map +1 -0
  62. package/build/common/languageColors.js +15 -0
  63. package/build/common/languageColors.json +10 -1
  64. package/build/common/ops.d.ts +27 -33
  65. package/build/common/ops.d.ts.map +1 -1
  66. package/build/common/ops.js +31 -48
  67. package/build/common/render.d.ts +154 -113
  68. package/build/common/render.d.ts.map +1 -1
  69. package/build/common/render.js +209 -92
  70. package/build/common/retryer.d.ts +15 -6
  71. package/build/common/retryer.d.ts.map +1 -1
  72. package/build/common/retryer.js +2 -0
  73. package/build/fetchers/gist.d.ts +6 -21
  74. package/build/fetchers/gist.d.ts.map +1 -1
  75. package/build/fetchers/gist.js +28 -64
  76. package/build/fetchers/repo.d.ts +12 -11
  77. package/build/fetchers/repo.d.ts.map +1 -1
  78. package/build/fetchers/repo.js +27 -68
  79. package/build/fetchers/stats.d.ts +24 -17
  80. package/build/fetchers/stats.d.ts.map +1 -1
  81. package/build/fetchers/stats.js +302 -184
  82. package/build/fetchers/top-languages.d.ts +10 -15
  83. package/build/fetchers/top-languages.d.ts.map +1 -1
  84. package/build/fetchers/top-languages.js +52 -103
  85. package/build/fetchers/types.d.ts +130 -0
  86. package/build/fetchers/types.d.ts.map +1 -0
  87. package/build/fetchers/types.js +1 -0
  88. package/build/fetchers/wakatime.d.ts +9 -5
  89. package/build/fetchers/wakatime.d.ts.map +1 -1
  90. package/build/fetchers/wakatime.js +8 -4
  91. package/build/graphql/contributionsDocument.d.ts +18 -0
  92. package/build/graphql/contributionsDocument.d.ts.map +1 -0
  93. package/build/graphql/contributionsDocument.js +30 -0
  94. package/build/graphql/generated/common.d.ts +42 -0
  95. package/build/graphql/generated/common.d.ts.map +1 -0
  96. package/build/graphql/generated/common.js +2 -0
  97. package/build/graphql/generated/gist.d.ts +44 -0
  98. package/build/graphql/generated/gist.d.ts.map +1 -0
  99. package/build/graphql/generated/gist.js +27 -0
  100. package/build/graphql/generated/repo.d.ts +67 -0
  101. package/build/graphql/generated/repo.d.ts.map +1 -0
  102. package/build/graphql/generated/repo.js +30 -0
  103. package/build/graphql/generated/stats.d.ts +150 -0
  104. package/build/graphql/generated/stats.d.ts.map +1 -0
  105. package/build/graphql/generated/stats.js +95 -0
  106. package/build/graphql/generated/top-languages.d.ts +54 -0
  107. package/build/graphql/generated/top-languages.d.ts.map +1 -0
  108. package/build/graphql/generated/top-languages.js +27 -0
  109. package/build/graphql/graphqlDocument.d.ts +22 -0
  110. package/build/graphql/graphqlDocument.d.ts.map +1 -0
  111. package/build/graphql/graphqlDocument.js +8 -0
  112. package/build/graphql/reposContributedToDocument.d.ts +27 -0
  113. package/build/graphql/reposContributedToDocument.d.ts.map +1 -0
  114. package/build/graphql/reposContributedToDocument.js +59 -0
  115. package/build/index.d.ts +3 -1
  116. package/build/index.d.ts.map +1 -1
  117. package/build/index.js +2 -1
  118. package/build/themes/index.d.ts +32 -0
  119. package/build/themes/index.d.ts.map +1 -1
  120. package/build/themes/index.js +28 -0
  121. package/build/translations.d.ts +17 -0
  122. package/build/translations.d.ts.map +1 -1
  123. package/build/translations.js +17 -0
  124. package/package.json +14 -8
  125. package/src/_emoji-name-map.d.ts +10 -0
  126. package/src/_github-username-regex.d.ts +4 -0
  127. package/src/api/gist.js +31 -31
  128. package/src/api/index.js +40 -42
  129. package/src/api/pin.js +20 -38
  130. package/src/api/top-langs.js +36 -49
  131. package/src/api/wakatime.js +31 -31
  132. package/src/{calculateRank.js → calculateRank.ts} +29 -19
  133. package/src/cards/common-options.ts +13 -0
  134. package/src/cards/{gist.js → gist.ts} +37 -37
  135. package/src/cards/{repo.js → repo.ts} +107 -79
  136. package/src/cards/{stats.js → stats.ts} +173 -210
  137. package/src/cards/{top-languages.js → top-languages.ts} +325 -243
  138. package/src/cards/{wakatime.js → wakatime.ts} +158 -127
  139. package/src/common/Card.ts +123 -43
  140. package/src/common/I18n.ts +6 -2
  141. package/src/common/color.ts +240 -28
  142. package/src/common/config.ts +22 -29
  143. package/src/common/constants.ts +3 -1
  144. package/src/common/date.ts +45 -0
  145. package/src/common/html.ts +1 -1
  146. package/src/common/http.ts +71 -0
  147. package/src/common/icons.ts +1 -0
  148. package/src/common/languageColors.json +10 -1
  149. package/src/common/languageColors.ts +19 -0
  150. package/src/common/ops.ts +158 -0
  151. package/src/common/render.ts +652 -0
  152. package/src/common/retryer.ts +21 -12
  153. package/src/fetchers/gist.ts +79 -0
  154. package/src/fetchers/repo.ts +114 -0
  155. package/src/fetchers/stats.ts +743 -0
  156. package/src/fetchers/top-languages.ts +135 -0
  157. package/src/fetchers/{types.d.ts → types.ts} +28 -20
  158. package/src/fetchers/{wakatime.js → wakatime.ts} +19 -5
  159. package/src/graphql/contributionsDocument.ts +44 -0
  160. package/src/graphql/generated/common.ts +26 -0
  161. package/src/graphql/generated/gist.ts +59 -0
  162. package/src/graphql/generated/repo.ts +90 -0
  163. package/src/graphql/generated/stats.ts +194 -0
  164. package/src/graphql/generated/top-languages.ts +75 -0
  165. package/src/graphql/graphqlDocument.ts +25 -0
  166. package/src/graphql/queries/gist.graphql +25 -0
  167. package/src/graphql/queries/repo.graphql +28 -0
  168. package/src/graphql/queries/stats.graphql +120 -0
  169. package/src/graphql/queries/top-languages.graphql +34 -0
  170. package/src/graphql/reposContributedToDocument.ts +86 -0
  171. package/src/index.ts +3 -1
  172. package/src/themes/index.ts +33 -0
  173. package/src/translations.ts +17 -0
  174. package/src/cards/types.d.ts +0 -78
  175. package/src/common/http.js +0 -19
  176. package/src/common/ops.js +0 -170
  177. package/src/common/render.js +0 -440
  178. package/src/fetchers/gist.js +0 -112
  179. package/src/fetchers/repo.js +0 -161
  180. package/src/fetchers/stats.js +0 -474
  181. package/src/fetchers/top-languages.js +0 -175
  182. package/src/themes/README.md +0 -229
@@ -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
- * @param {object} props Function properties.
10
- * @param {string[]} props.items Array of items to layout.
11
- * @param {number} props.gap Gap between items.
12
- * @param {"column" | "row"=} props.direction Direction to layout items.
13
- * @param {number[]=} props.sizes Array of sizes for each item.
14
- * @returns {string[]} Array of items with proper layout.
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 {string} langName Language name.
33
- * @param {string} langColor Language color.
34
- * @returns {string} Language display SVG object.
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 {Object} params Object that contains the createProgressNode parameters.
48
- * @param {number} params.x X-axis position.
49
- * @param {number} params.y Y-axis position.
50
- * @param {number} params.width Width of progress bar.
51
- * @param {string} params.color Progress color.
52
- * @param {number} params.progress Progress value.
53
- * @param {string} params.progressBarBackgroundColor Progress bar bg color.
54
- * @param {number} params.delay Delay before animation starts.
55
- * @returns {string} Progress node.
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, progressBarBackgroundColor, delay, }) => {
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" fill="${progressBarBackgroundColor}"></rect>
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 {object} props Function properties.
80
- * @param {string} props.text Text to render (will be HTML-encoded).
81
- * @param {number} props.x X position of the foreignObject.
82
- * @param {number} props.y Y position of the foreignObject.
83
- * @param {number} props.width Width of the wrap box.
84
- * @param {number} props.height Height of the wrap box.
85
- * @param {number} props.lineCount Maximum number of lines to display.
86
- * @param {string} props.className CSS class applied to the inner element.
87
- * @param {string=} props.testId Optional test id for the inner element.
88
- * @returns {string} foreignObject SVG node.
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
- const testIdAttr = testId ? ` data-testid="${testId}"` : "";
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 {string} color Text color (CSS `color` property).
105
- * @returns {string} CSS rules block (without the surrounding selector).
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: ${color};
109
- margin: 0;
110
- line-height: 1.2;
111
- overflow-wrap: anywhere;
112
- word-break: break-word;
113
- display: -webkit-box;
114
- -webkit-box-orient: vertical;
115
- -webkit-line-clamp: var(--lines);
116
- line-clamp: var(--lines);
117
- overflow: hidden;
118
- text-overflow: ellipsis;
119
- padding-bottom: 0.15em;
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
- * @param {string} icon The icon to display.
125
- * @param {number|string} label The label to display.
126
- * @param {string} testid The testid to assign to the label.
127
- * @param {number} iconSize The size of the icon.
128
- * @returns {string} Icon with label SVG object.
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 {object} args Function arguments.
159
- * @param {string} args.message Main error message.
160
- * @param {string} [args.secondaryMessage=""] The secondary error message.
161
- * @param {object} [args.renderOptions={}] Render options.
162
- * @param {string=} args.renderOptions.title_color Card title color.
163
- * @param {string=} args.renderOptions.text_color Card text color.
164
- * @param {string=} args.renderOptions.bg_color Card background color.
165
- * @param {string=} args.renderOptions.border_color Card border color.
166
- * @param {Parameters<typeof getCardColors>[0]["theme"]=} args.renderOptions.theme Card theme.
167
- * @param {boolean=} args.renderOptions.show_repo_link Whether to show repo link or not.
168
- * @returns {string} The SVG markup.
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 {string} str String to measure.
205
- * @param {number} fontSize Font size.
206
- * @returns {number} Text length.
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 {string} text Text to split.
273
- * @param {number} fontSize Font size in px (matches `measureText`).
274
- * @param {number} maxWidth Available wrap width in px.
275
- * @returns {string[]} Estimated wrapped lines.
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
- text = text.replace(/[\t\n\r ]+/g, " ");
292
- const tokens = text.match(/\s|[\u3000-\u9FFF\uFF00-\uFFEF]|[^\s\u3000-\u9FFF\uFF00-\uFFEF]+/g);
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] += token;
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] += remaining;
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] += segment;
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 {string} text Text to estimate.
352
- * @param {number} fontSize Font size in px (matches `measureText`).
353
- * @param {number} maxWidth Available wrap width in px.
354
- * @param {number} maxLines Cap on the returned line count.
355
- * @returns {number} Estimated line count, at least 1, at most `maxLines`.
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
- * Subset of the response payload the retryer inspects to detect
4
- * rate-limiting and credential failures.
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 ResponseData {
7
+ interface ResponseErrors {
7
8
  errors?: Array<{
8
9
  type?: string;
9
10
  message?: string;
10
11
  }>;
11
12
  message?: string;
12
13
  }
13
- type FetcherResponse = AxiosResponse<ResponseData>;
14
- type FetcherFunction = (variables: Record<string, unknown>, token: string, retriesForTests?: number) => Promise<FetcherResponse>;
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: Record<string, unknown>, pat?: string | null) => Promise<FetcherResponse>;
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;;;GAGG;AACH,UAAU,YAAY;IACpB,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,KAAK,eAAe,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;AAEnD,KAAK,eAAe,GAAG,CACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,KACrB,OAAO,CAAC,eAAe,CAAC,CAAC;AAE9B;;;;;;;GAOG;AACH,QAAA,MAAM,OAAO,GACX,SAAS,eAAe,EACxB,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,MAAK,MAAM,GAAG,IAAW,KACxB,OAAO,CAAC,eAAe,CAiEzB,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
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"}
@@ -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.
@@ -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 {string} id GitHub gist ID.
22
- * @param {string | null} pat Optional PAT override.
23
- * @returns {Promise<GistData>} Gist data.
5
+ * @param id GitHub gist ID.
6
+ * @param pat Optional PAT override.
7
+ * @returns Gist data.
24
8
  */
25
- export function fetchGist(id: string, pat?: string | null): Promise<GistData>;
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.js"],"names":[],"mappings":";;;uBA2Ca;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;KAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;;;;;AAiCxE;;GAEG;AAEH;;;;;;GAMG;AACH,8BAJW,MAAM,QACN,MAAM,GAAG,IAAI,GACX,OAAO,CAAC,QAAQ,CAAC,CAwB7B"}
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"}