@stats-forge/github-stats-forge-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/build/api/api-result.d.ts +44 -0
  4. package/build/api/api-result.d.ts.map +1 -0
  5. package/build/api/api-result.js +33 -0
  6. package/build/api/gist.d.ts +29 -0
  7. package/build/api/gist.d.ts.map +1 -0
  8. package/build/api/gist.js +52 -0
  9. package/build/api/index.d.ts +13 -0
  10. package/build/api/index.d.ts.map +1 -0
  11. package/build/api/index.js +8 -0
  12. package/build/api/params.d.ts +93 -0
  13. package/build/api/params.d.ts.map +1 -0
  14. package/build/api/params.js +145 -0
  15. package/build/api/pin.d.ts +47 -0
  16. package/build/api/pin.d.ts.map +1 -0
  17. package/build/api/pin.js +87 -0
  18. package/build/api/stats.d.ts +42 -0
  19. package/build/api/stats.d.ts.map +1 -0
  20. package/build/api/stats.js +132 -0
  21. package/build/api/top-langs.d.ts +37 -0
  22. package/build/api/top-langs.d.ts.map +1 -0
  23. package/build/api/top-langs.js +101 -0
  24. package/build/api/wakatime.d.ts +34 -0
  25. package/build/api/wakatime.d.ts.map +1 -0
  26. package/build/api/wakatime.js +91 -0
  27. package/build/calculateRank.d.ts +29 -0
  28. package/build/calculateRank.d.ts.map +1 -0
  29. package/build/calculateRank.js +58 -0
  30. package/build/cards/gist.d.ts +16 -0
  31. package/build/cards/gist.d.ts.map +1 -0
  32. package/build/cards/gist.js +119 -0
  33. package/build/cards/index.d.ts +11 -0
  34. package/build/cards/index.d.ts.map +1 -0
  35. package/build/cards/index.js +7 -0
  36. package/build/cards/options.d.ts +19 -0
  37. package/build/cards/options.d.ts.map +1 -0
  38. package/build/cards/options.js +1 -0
  39. package/build/cards/repo.d.ts +25 -0
  40. package/build/cards/repo.d.ts.map +1 -0
  41. package/build/cards/repo.js +276 -0
  42. package/build/cards/stats.d.ts +37 -0
  43. package/build/cards/stats.d.ts.map +1 -0
  44. package/build/cards/stats.js +457 -0
  45. package/build/cards/top-languages.d.ts +153 -0
  46. package/build/cards/top-languages.d.ts.map +1 -0
  47. package/build/cards/top-languages.js +805 -0
  48. package/build/cards/wakatime.d.ts +31 -0
  49. package/build/cards/wakatime.d.ts.map +1 -0
  50. package/build/cards/wakatime.js +376 -0
  51. package/build/common/Card.d.ts +121 -0
  52. package/build/common/Card.d.ts.map +1 -0
  53. package/build/common/Card.js +305 -0
  54. package/build/common/I18n.d.ts +27 -0
  55. package/build/common/I18n.d.ts.map +1 -0
  56. package/build/common/I18n.js +35 -0
  57. package/build/common/color.d.ts +112 -0
  58. package/build/common/color.d.ts.map +1 -0
  59. package/build/common/color.js +188 -0
  60. package/build/common/config.d.ts +53 -0
  61. package/build/common/config.d.ts.map +1 -0
  62. package/build/common/config.js +87 -0
  63. package/build/common/constants.d.ts +7 -0
  64. package/build/common/constants.d.ts.map +1 -0
  65. package/build/common/constants.js +9 -0
  66. package/build/common/date.d.ts +29 -0
  67. package/build/common/date.d.ts.map +1 -0
  68. package/build/common/date.js +23 -0
  69. package/build/common/error.d.ts +87 -0
  70. package/build/common/error.d.ts.map +1 -0
  71. package/build/common/error.js +108 -0
  72. package/build/common/fmt.d.ts +28 -0
  73. package/build/common/fmt.d.ts.map +1 -0
  74. package/build/common/fmt.js +68 -0
  75. package/build/common/html.d.ts +8 -0
  76. package/build/common/html.d.ts.map +1 -0
  77. package/build/common/html.js +14 -0
  78. package/build/common/http.d.ts +53 -0
  79. package/build/common/http.d.ts.map +1 -0
  80. package/build/common/http.js +47 -0
  81. package/build/common/icons.d.ts +28 -0
  82. package/build/common/icons.d.ts.map +1 -0
  83. package/build/common/icons.js +77 -0
  84. package/build/common/languageColors.d.ts +11 -0
  85. package/build/common/languageColors.d.ts.map +1 -0
  86. package/build/common/languageColors.js +15 -0
  87. package/build/common/languageColors.json +678 -0
  88. package/build/common/log.d.ts +9 -0
  89. package/build/common/log.d.ts.map +1 -0
  90. package/build/common/log.js +8 -0
  91. package/build/common/ops.d.ts +59 -0
  92. package/build/common/ops.d.ts.map +1 -0
  93. package/build/common/ops.js +115 -0
  94. package/build/common/render.d.ts +196 -0
  95. package/build/common/render.d.ts.map +1 -0
  96. package/build/common/render.js +474 -0
  97. package/build/common/retryer.d.ts +36 -0
  98. package/build/common/retryer.d.ts.map +1 -0
  99. package/build/common/retryer.js +67 -0
  100. package/build/fetchers/gist.d.ts +15 -0
  101. package/build/fetchers/gist.d.ts.map +1 -0
  102. package/build/fetchers/gist.js +68 -0
  103. package/build/fetchers/index.d.ts +13 -0
  104. package/build/fetchers/index.d.ts.map +1 -0
  105. package/build/fetchers/index.js +10 -0
  106. package/build/fetchers/repo.d.ts +27 -0
  107. package/build/fetchers/repo.d.ts.map +1 -0
  108. package/build/fetchers/repo.js +100 -0
  109. package/build/fetchers/stats.d.ts +74 -0
  110. package/build/fetchers/stats.d.ts.map +1 -0
  111. package/build/fetchers/stats.js +498 -0
  112. package/build/fetchers/top-languages.d.ts +23 -0
  113. package/build/fetchers/top-languages.d.ts.map +1 -0
  114. package/build/fetchers/top-languages.js +89 -0
  115. package/build/fetchers/types.d.ts +130 -0
  116. package/build/fetchers/types.d.ts.map +1 -0
  117. package/build/fetchers/types.js +1 -0
  118. package/build/fetchers/wakatime.d.ts +19 -0
  119. package/build/fetchers/wakatime.d.ts.map +1 -0
  120. package/build/fetchers/wakatime.js +36 -0
  121. package/build/graphql/contributionsDocument.d.ts +18 -0
  122. package/build/graphql/contributionsDocument.d.ts.map +1 -0
  123. package/build/graphql/contributionsDocument.js +30 -0
  124. package/build/graphql/generated/common.d.ts +42 -0
  125. package/build/graphql/generated/common.d.ts.map +1 -0
  126. package/build/graphql/generated/common.js +2 -0
  127. package/build/graphql/generated/gist.d.ts +44 -0
  128. package/build/graphql/generated/gist.d.ts.map +1 -0
  129. package/build/graphql/generated/gist.js +27 -0
  130. package/build/graphql/generated/repo.d.ts +67 -0
  131. package/build/graphql/generated/repo.d.ts.map +1 -0
  132. package/build/graphql/generated/repo.js +30 -0
  133. package/build/graphql/generated/stats.d.ts +150 -0
  134. package/build/graphql/generated/stats.d.ts.map +1 -0
  135. package/build/graphql/generated/stats.js +95 -0
  136. package/build/graphql/generated/top-languages.d.ts +54 -0
  137. package/build/graphql/generated/top-languages.d.ts.map +1 -0
  138. package/build/graphql/generated/top-languages.js +27 -0
  139. package/build/graphql/graphqlDocument.d.ts +22 -0
  140. package/build/graphql/graphqlDocument.d.ts.map +1 -0
  141. package/build/graphql/graphqlDocument.js +8 -0
  142. package/build/graphql/reposContributedToDocument.d.ts +27 -0
  143. package/build/graphql/reposContributedToDocument.d.ts.map +1 -0
  144. package/build/graphql/reposContributedToDocument.js +59 -0
  145. package/build/index.d.ts +15 -0
  146. package/build/index.d.ts.map +1 -0
  147. package/build/index.js +10 -0
  148. package/build/themes/index.d.ts +505 -0
  149. package/build/themes/index.d.ts.map +1 -0
  150. package/build/themes/index.js +505 -0
  151. package/build/translations.d.ts +1153 -0
  152. package/build/translations.d.ts.map +1 -0
  153. package/build/translations.js +1156 -0
  154. package/package.json +114 -0
  155. package/src/_emoji-name-map.d.ts +10 -0
  156. package/src/_github-username-regex.d.ts +4 -0
  157. package/src/api/api-result.ts +69 -0
  158. package/src/api/gist.ts +66 -0
  159. package/src/api/index.ts +16 -0
  160. package/src/api/params.ts +221 -0
  161. package/src/api/pin.ts +126 -0
  162. package/src/api/stats.ts +195 -0
  163. package/src/api/top-langs.ts +150 -0
  164. package/src/api/wakatime.ts +130 -0
  165. package/src/calculateRank.ts +91 -0
  166. package/src/cards/gist.ts +169 -0
  167. package/src/cards/index.ts +21 -0
  168. package/src/cards/options.ts +18 -0
  169. package/src/cards/repo.ts +376 -0
  170. package/src/cards/stats.ts +615 -0
  171. package/src/cards/top-languages.ts +1077 -0
  172. package/src/cards/wakatime.ts +501 -0
  173. package/src/common/Card.ts +364 -0
  174. package/src/common/I18n.ts +51 -0
  175. package/src/common/color.ts +296 -0
  176. package/src/common/config.ts +118 -0
  177. package/src/common/constants.ts +12 -0
  178. package/src/common/date.ts +34 -0
  179. package/src/common/error.ts +163 -0
  180. package/src/common/fmt.ts +86 -0
  181. package/src/common/html.ts +17 -0
  182. package/src/common/http.ts +98 -0
  183. package/src/common/icons.ts +80 -0
  184. package/src/common/languageColors.json +678 -0
  185. package/src/common/languageColors.ts +19 -0
  186. package/src/common/log.ts +12 -0
  187. package/src/common/ops.ts +145 -0
  188. package/src/common/render.ts +641 -0
  189. package/src/common/retryer.ts +111 -0
  190. package/src/fetchers/gist.ts +82 -0
  191. package/src/fetchers/index.ts +25 -0
  192. package/src/fetchers/repo.ts +140 -0
  193. package/src/fetchers/stats.ts +742 -0
  194. package/src/fetchers/top-languages.ts +134 -0
  195. package/src/fetchers/types.ts +136 -0
  196. package/src/fetchers/wakatime.ts +56 -0
  197. package/src/graphql/contributionsDocument.ts +44 -0
  198. package/src/graphql/generated/common.ts +26 -0
  199. package/src/graphql/generated/gist.ts +56 -0
  200. package/src/graphql/generated/repo.ts +79 -0
  201. package/src/graphql/generated/stats.ts +180 -0
  202. package/src/graphql/generated/top-languages.ts +66 -0
  203. package/src/graphql/graphqlDocument.ts +25 -0
  204. package/src/graphql/queries/gist.graphql +25 -0
  205. package/src/graphql/queries/repo.graphql +28 -0
  206. package/src/graphql/queries/stats.graphql +113 -0
  207. package/src/graphql/queries/top-languages.graphql +27 -0
  208. package/src/graphql/reposContributedToDocument.ts +83 -0
  209. package/src/index.ts +18 -0
  210. package/src/themes/index.ts +519 -0
  211. package/src/translations.ts +1169 -0
@@ -0,0 +1,501 @@
1
+ import { Card } from '../common/Card.js';
2
+ import { getLightDarkColors, isPrefixedHexColor } from '../common/color.js';
3
+ import { encodeHTML } from '../common/html.js';
4
+ import { I18n } from '../common/I18n.js';
5
+ import { getLanguageColor } from '../common/languageColors.js';
6
+ import { clampValue, lowercaseTrim } from '../common/ops.js';
7
+ import { createProgressNode, flexLayout } from '../common/render.js';
8
+ import type { WakaTimeData, WakaTimeLang } from '../fetchers/types.js';
9
+ import { wakatimeCardLocales } from '../translations.js';
10
+
11
+ import type { CardOptions, CommonCardOptions } from './options.js';
12
+
13
+ const DEFAULT_CARD_WIDTH = 495;
14
+ const MIN_CARD_WIDTH = 250;
15
+ const COMPACT_LAYOUT_MIN_WIDTH = 400;
16
+ const DEFAULT_LINE_HEIGHT = 25;
17
+ const PROGRESSBAR_PADDING = 130;
18
+ const HIDDEN_PROGRESSBAR_PADDING = 170;
19
+ const COMPACT_LAYOUT_PROGRESSBAR_PADDING = 25;
20
+ const TOTAL_TEXT_WIDTH = 275;
21
+
22
+ /** Layouts the card can draw; the api validates `layout` against this. */
23
+ const WAKATIME_LAYOUTS = ['compact', 'normal'] as const;
24
+ type WakaTimeLayout = (typeof WAKATIME_LAYOUTS)[number];
25
+
26
+ /** How a language's time is written; the api validates `display_format` against this. */
27
+ const DISPLAY_FORMATS = ['time', 'percent'] as const;
28
+ type DisplayFormat = (typeof DISPLAY_FORMATS)[number];
29
+
30
+ interface WakaTimeOptions extends CommonCardOptions {
31
+ locale: string;
32
+ hide_title: boolean;
33
+ hide: Array<string>;
34
+ card_width: number;
35
+ line_height: number | string;
36
+ hide_progress: boolean;
37
+ custom_title: string;
38
+ layout: WakaTimeLayout;
39
+ langs_count: number;
40
+ display_format: DisplayFormat;
41
+ disable_animations: boolean;
42
+ }
43
+
44
+ /**
45
+ * Creates the no coding activity SVG node.
46
+ *
47
+ * @param props The function properties.
48
+ * @param props.text No coding activity translated text.
49
+ * @returns No coding activity SVG node string.
50
+ */
51
+ const noCodingActivityNode = ({ text }: { text: string }): string => {
52
+ return `
53
+ <text x="25" y="11" class="stat bold">${encodeHTML(text)}</text>
54
+ `;
55
+ };
56
+
57
+ /**
58
+ * Format language value.
59
+ *
60
+ * @param args The function arguments.
61
+ * @param args.lang The language object.
62
+ * @param args.display_format The display format of the language node.
63
+ * @returns The formatted language value.
64
+ */
65
+ const formatLanguageValue = ({
66
+ display_format,
67
+ lang,
68
+ }: {
69
+ display_format: DisplayFormat;
70
+ lang: WakaTimeLang;
71
+ }): string => {
72
+ return display_format === 'percent' ? `${lang.percent.toFixed(2)} %` : lang.text;
73
+ };
74
+
75
+ /**
76
+ * Create compact WakaTime layout.
77
+ *
78
+ * @param args The function arguments.
79
+ * @param args.lang The languages array.
80
+ * @param args.x The x position of the language node.
81
+ * @param args.y The y position of the language node.
82
+ * @param args.display_format The display format of the language node.
83
+ * @returns The compact layout language SVG node.
84
+ */
85
+ const createCompactLangNode = ({
86
+ lang,
87
+ x,
88
+ y,
89
+ display_format,
90
+ }: {
91
+ lang: WakaTimeLang;
92
+ x: number;
93
+ y: number;
94
+ display_format: DisplayFormat;
95
+ }): string => {
96
+ if (!Number.isFinite(x)) {
97
+ throw new Error(`Invalid x: "${x}"`);
98
+ }
99
+ if (!Number.isFinite(y)) {
100
+ throw new Error(`Invalid y: "${y}"`);
101
+ }
102
+
103
+ const color = getLanguageColor(lang.name);
104
+ const value = formatLanguageValue({ display_format, lang });
105
+
106
+ return `
107
+ <g transform="translate(${x}, ${y})">
108
+ <circle cx="5" cy="6" r="5" fill="${color}" />
109
+ <text data-testid="lang-name" x="15" y="10" class='lang-name'>
110
+ ${encodeHTML(lang.name)} - ${encodeHTML(value)}
111
+ </text>
112
+ </g>
113
+ `;
114
+ };
115
+
116
+ /**
117
+ * Create WakaTime language text node item.
118
+ *
119
+ * @param args The function arguments.
120
+ * @param args.langs The language objects.
121
+ * @param args.y The y position of the language node.
122
+ * @param args.display_format The display format of the language node.
123
+ * @param args.card_width Width in px of the card.
124
+ * @returns The language text node items.
125
+ */
126
+ const createLanguageTextNode = ({
127
+ langs,
128
+ y,
129
+ display_format,
130
+ card_width,
131
+ }: {
132
+ langs: Array<WakaTimeLang>;
133
+ y: number;
134
+ display_format: DisplayFormat;
135
+ card_width: number;
136
+ }): Array<string> => {
137
+ const LEFT_X = 25;
138
+ const RIGHT_X_BASE = 230;
139
+ const rightOffset = (card_width - DEFAULT_CARD_WIDTH) / 2;
140
+ const RIGHT_X = RIGHT_X_BASE + rightOffset;
141
+
142
+ return langs.map((lang, index) => {
143
+ const isLeft = index % 2 === 0;
144
+ return createCompactLangNode({
145
+ lang,
146
+ x: isLeft ? LEFT_X : RIGHT_X,
147
+ y: y + DEFAULT_LINE_HEIGHT * Math.floor(index / 2),
148
+ display_format,
149
+ });
150
+ });
151
+ };
152
+
153
+ /**
154
+ * Create WakaTime text item.
155
+ *
156
+ * @param args The function arguments.
157
+ * @param args.id The id of the text node item.
158
+ * @param args.label The label of the text node item.
159
+ * @param args.value The value of the text node item.
160
+ * @param args.index The index of the text node item.
161
+ * @param args.percent Percentage of the text node item.
162
+ * @param args.hideProgress Whether to hide the progress bar.
163
+ * @param args.progressBarWidth The width of the progress bar.
164
+ * @returns The text SVG node.
165
+ */
166
+ const createTextNode = ({
167
+ id,
168
+ label,
169
+ value,
170
+ index,
171
+ percent,
172
+ hideProgress,
173
+ progressBarWidth,
174
+ }: {
175
+ id: string;
176
+ label: string;
177
+ value: string;
178
+ index: number;
179
+ percent: number;
180
+ hideProgress?: boolean | undefined;
181
+ progressBarWidth: number;
182
+ }): string => {
183
+ if (!Number.isFinite(index)) {
184
+ throw new Error(`Invalid index: "${index}"`);
185
+ }
186
+ if (!Number.isFinite(progressBarWidth)) {
187
+ throw new Error(`Invalid progressBarWidth: "${progressBarWidth}"`);
188
+ }
189
+
190
+ const staggerDelay = (index + 3) * 150;
191
+ const cardProgress = hideProgress
192
+ ? null
193
+ : createProgressNode({
194
+ x: 110,
195
+ y: 4,
196
+ progress: percent,
197
+ width: progressBarWidth,
198
+ delay: staggerDelay + 300,
199
+ });
200
+
201
+ return `
202
+ <g class="stagger" style="animation-delay: ${staggerDelay}ms" transform="translate(25, 0)">
203
+ <text class="stat bold" y="12.5" data-testid="${encodeHTML(id)}">${encodeHTML(label)}:</text>
204
+ <text
205
+ class="stat"
206
+ x="${hideProgress ? HIDDEN_PROGRESSBAR_PADDING : PROGRESSBAR_PADDING + progressBarWidth}"
207
+ y="12.5"
208
+ >${encodeHTML(value)}</text>
209
+ ${String(cardProgress)}
210
+ </g>
211
+ `;
212
+ };
213
+
214
+ /**
215
+ * Recalculating percentages so that, compact layout's progress bar does not break when
216
+ * hiding languages.
217
+ *
218
+ * @param languages The languages array.
219
+ */
220
+ const recalculatePercentages = (languages: Array<WakaTimeLang>): void => {
221
+ const totalSum = languages.reduce((totalSum, language) => totalSum + language.percent, 0);
222
+ const weight = +(100 / totalSum).toFixed(2);
223
+ languages.forEach((language) => {
224
+ language.percent = +(language.percent * weight).toFixed(2);
225
+ });
226
+ };
227
+
228
+ /**
229
+ * Retrieves CSS styles for a card.
230
+ *
231
+ * @param colors The colors to use for the card.
232
+ * @param colors.textColor The text color.
233
+ * @returns Card CSS styles.
234
+ */
235
+ const getStyles = ({ textColor }: { textColor: string }): string => {
236
+ if (!isPrefixedHexColor(textColor)) {
237
+ throw new Error(`Invalid text color: "${textColor}"`);
238
+ }
239
+
240
+ return `
241
+ .stat {
242
+ font: 600 14px 'Segoe UI', Ubuntu, "Helvetica Neue", Sans-Serif; fill: ${textColor};
243
+ }
244
+ @supports(-moz-appearance: auto) {
245
+ /* Selector detects Firefox */
246
+ .stat { font-size:12px; }
247
+ }
248
+ .stagger {
249
+ opacity: 0;
250
+ animation: fadeInAnimation 0.3s ease-in-out forwards;
251
+ }
252
+ .not_bold { font-weight: 400 }
253
+ .bold { font-weight: 700 }
254
+ `;
255
+ };
256
+
257
+ /**
258
+ * Normalize incoming width (string or number) and clamp to minimum.
259
+ *
260
+ * @param args The function arguments.
261
+ * @param args.layout The incoming layout value.
262
+ * @param args.value The incoming width value.
263
+ * @returns The normalized width value.
264
+ */
265
+ const normalizeCardWidth = ({
266
+ value,
267
+ layout,
268
+ }: {
269
+ value?: number | undefined;
270
+ layout?: WakaTimeLayout | undefined;
271
+ }): number => {
272
+ if (value === undefined || isNaN(value)) {
273
+ return DEFAULT_CARD_WIDTH;
274
+ }
275
+ return Math.max(layout === 'compact' ? COMPACT_LAYOUT_MIN_WIDTH : MIN_CARD_WIDTH, value);
276
+ };
277
+
278
+ /**
279
+ * Renders WakaTime card.
280
+ *
281
+ * @param stats WakaTime stats.
282
+ * @param options Card options.
283
+ * @returns WakaTime card SVG.
284
+ */
285
+ const renderWakatimeCard = (
286
+ stats: Partial<WakaTimeData> = {},
287
+ options: CardOptions<WakaTimeOptions> = { hide: [] },
288
+ ): string => {
289
+ let { languages = [] } = stats;
290
+ const {
291
+ hide_title = false,
292
+ hide_border = false,
293
+ card_width,
294
+ hide,
295
+ line_height = DEFAULT_LINE_HEIGHT,
296
+ hide_progress,
297
+ custom_title,
298
+ locale,
299
+ layout,
300
+ langs_count = languages.length,
301
+ border_radius,
302
+ display_format = 'time',
303
+ disable_animations,
304
+ } = options;
305
+
306
+ const normalizedWidth = normalizeCardWidth({ value: card_width, layout });
307
+
308
+ const shouldHideLangs = Array.isArray(hide) && hide.length > 0;
309
+ if (shouldHideLangs) {
310
+ const languagesToHide = new Set(hide.map((lang) => lowercaseTrim(lang)));
311
+ languages = languages.filter((lang) => !languagesToHide.has(lowercaseTrim(lang.name)));
312
+ }
313
+
314
+ // Since the percentages are sorted in descending order, we can just
315
+ // slice from the beginning without sorting.
316
+ languages = languages.slice(0, langs_count);
317
+ recalculatePercentages(languages);
318
+
319
+ const i18n = new I18n({
320
+ locale,
321
+ translations: wakatimeCardLocales,
322
+ });
323
+
324
+ const lheight = parseInt(String(line_height), 10);
325
+
326
+ const langsCount = clampValue(langs_count, 1, langs_count);
327
+
328
+ const { lightColors, darkColors } = getLightDarkColors(options);
329
+
330
+ const filteredLanguages = languages
331
+ .filter((language) => language.hours || language.minutes)
332
+ .slice(0, langsCount);
333
+
334
+ // Calculate the card height depending on how many items there are
335
+ // but if rank circle is visible clamp the minimum height to `150`
336
+ let height = Math.max(45 + (filteredLanguages.length + 1) * lheight, 150);
337
+
338
+ let finalLayout: string;
339
+
340
+ // RENDER COMPACT LAYOUT
341
+ if (layout === 'compact') {
342
+ const width = normalizedWidth - 5;
343
+ height = 90 + Math.round(filteredLanguages.length / 2) * DEFAULT_LINE_HEIGHT;
344
+
345
+ // progressOffset holds the previous language's width and used to offset the next language
346
+ // so that we can stack them one after another, like this: [--][----][---]
347
+ let progressOffset = 0;
348
+ const compactProgressBar = filteredLanguages
349
+ .map((language) => {
350
+ const progress = ((width - COMPACT_LAYOUT_PROGRESSBAR_PADDING) * language.percent) / 100;
351
+
352
+ const languageColor = getLanguageColor(language.name);
353
+
354
+ const output = `
355
+ <rect
356
+ mask="url(#rect-mask)"
357
+ data-testid="lang-progress"
358
+ x="${progressOffset}"
359
+ y="0"
360
+ width="${progress}"
361
+ height="8"
362
+ fill="${languageColor}"
363
+ />
364
+ `;
365
+ progressOffset += progress;
366
+ return output;
367
+ })
368
+ .join('');
369
+
370
+ finalLayout = `
371
+ <mask id="rect-mask">
372
+ <rect x="${COMPACT_LAYOUT_PROGRESSBAR_PADDING}" y="0" width="${width - 2 * COMPACT_LAYOUT_PROGRESSBAR_PADDING}" height="8" fill="white" rx="5" />
373
+ </mask>
374
+ ${compactProgressBar}
375
+ ${
376
+ filteredLanguages.length
377
+ ? createLanguageTextNode({
378
+ y: 25,
379
+ langs: filteredLanguages,
380
+ display_format,
381
+ card_width: normalizedWidth,
382
+ }).join('')
383
+ : noCodingActivityNode({
384
+ text: stats.is_coding_activity_visible
385
+ ? stats.is_other_usage_visible
386
+ ? i18n.t('wakatimecard.nocodingactivity')
387
+ : i18n.t('wakatimecard.nocodedetails')
388
+ : i18n.t('wakatimecard.notpublic'),
389
+ })
390
+ }
391
+ `;
392
+ } else {
393
+ finalLayout = flexLayout({
394
+ items: filteredLanguages.length
395
+ ? filteredLanguages.map((language, index) => {
396
+ return createTextNode({
397
+ id: language.name,
398
+ label: language.name,
399
+ value: formatLanguageValue({ display_format, lang: language }),
400
+ index,
401
+ percent: language.percent,
402
+ hideProgress: hide_progress,
403
+ progressBarWidth: normalizedWidth - TOTAL_TEXT_WIDTH,
404
+ });
405
+ })
406
+ : [
407
+ noCodingActivityNode({
408
+ text: stats.is_coding_activity_visible
409
+ ? stats.is_other_usage_visible
410
+ ? i18n.t('wakatimecard.nocodingactivity')
411
+ : i18n.t('wakatimecard.nocodedetails')
412
+ : i18n.t('wakatimecard.notpublic'),
413
+ }),
414
+ ],
415
+ gap: lheight,
416
+ direction: 'column',
417
+ }).join('');
418
+ }
419
+
420
+ // Get title range text
421
+ let titleText = i18n.t('wakatimecard.title');
422
+ switch (stats.range) {
423
+ case 'last_7_days':
424
+ titleText += ` (${i18n.t('wakatimecard.last7days')})`;
425
+ break;
426
+ case 'last_year':
427
+ titleText += ` (${i18n.t('wakatimecard.lastyear')})`;
428
+ break;
429
+ }
430
+
431
+ const card = new Card({
432
+ customTitle: custom_title,
433
+ defaultTitle: titleText,
434
+ width: normalizedWidth,
435
+ height,
436
+ border_radius,
437
+ colors: { light: lightColors, dark: darkColors },
438
+ });
439
+
440
+ if (disable_animations) {
441
+ card.disableAnimations();
442
+ }
443
+
444
+ card.setHideBorder(hide_border);
445
+ card.setHideTitle(hide_title);
446
+ card.setCSS({
447
+ light: ({ titleColor, textColor }) => `
448
+ ${getStyles({ textColor })}
449
+ @keyframes slideInAnimation {
450
+ from {
451
+ width: 0;
452
+ }
453
+ to {
454
+ width: calc(100%-100px);
455
+ }
456
+ }
457
+ @keyframes growWidthAnimation {
458
+ from {
459
+ width: 0;
460
+ }
461
+ to {
462
+ width: 100%;
463
+ }
464
+ }
465
+ .lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
466
+ #rect-mask rect{
467
+ animation: slideInAnimation 1s ease-in-out forwards;
468
+ }
469
+ .lang-progress{
470
+ animation: growWidthAnimation 0.6s ease-in-out forwards;
471
+ fill: ${titleColor};
472
+ }
473
+ .progress-background { fill: ${textColor === titleColor ? '#fff0' /* transparent */ : textColor}; }
474
+ `,
475
+ dark: ({ titleColor, textColor }) => `
476
+ ${getStyles({ textColor })}
477
+ .lang-name { fill: ${textColor} }
478
+ .lang-progress { fill: ${titleColor}; }
479
+ .progress-background { fill: ${textColor === titleColor ? '#fff0' /* transparent */ : textColor}; }
480
+ `,
481
+ });
482
+
483
+ // `role="img"` hides the inner text from assistive tech, so everything the card
484
+ // shows has to be repeated here.
485
+ card.setAccessibilityLabel({
486
+ title: card.title,
487
+ desc: filteredLanguages.length
488
+ ? filteredLanguages
489
+ .map((lang) => `${lang.name}: ${formatLanguageValue({ display_format, lang })}`)
490
+ .join(', ')
491
+ : i18n.t('wakatimecard.nocodingactivity'),
492
+ });
493
+
494
+ return card.render(`
495
+ <svg x="0" y="0" width="100%">
496
+ ${finalLayout}
497
+ </svg>
498
+ `);
499
+ };
500
+
501
+ export { DISPLAY_FORMATS, WAKATIME_LAYOUTS, renderWakatimeCard };