@stats-organization/github-readme-stats-core 2.1.5 → 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 (169) 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 +9 -41
  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 +23 -45
  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 +9 -41
  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 +11 -55
  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 +9 -41
  16. package/build/cards/common-options.d.ts +13 -0
  17. package/build/cards/common-options.d.ts.map +1 -0
  18. package/build/cards/common-options.js +1 -0
  19. package/build/cards/gist.d.ts +11 -16
  20. package/build/cards/gist.d.ts.map +1 -1
  21. package/build/cards/gist.js +26 -31
  22. package/build/cards/repo.d.ts +19 -16
  23. package/build/cards/repo.d.ts.map +1 -1
  24. package/build/cards/repo.js +58 -60
  25. package/build/cards/stats.d.ts +29 -46
  26. package/build/cards/stats.d.ts.map +1 -1
  27. package/build/cards/stats.js +113 -181
  28. package/build/cards/top-languages.d.ts +81 -77
  29. package/build/cards/top-languages.d.ts.map +1 -1
  30. package/build/cards/top-languages.js +174 -200
  31. package/build/cards/wakatime.d.ts +21 -11
  32. package/build/cards/wakatime.d.ts.map +1 -1
  33. package/build/cards/wakatime.js +73 -111
  34. package/build/common/Card.d.ts +34 -13
  35. package/build/common/Card.d.ts.map +1 -1
  36. package/build/common/Card.js +73 -40
  37. package/build/common/I18n.d.ts +4 -2
  38. package/build/common/I18n.d.ts.map +1 -1
  39. package/build/common/color.d.ts +60 -18
  40. package/build/common/color.d.ts.map +1 -1
  41. package/build/common/color.js +102 -5
  42. package/build/common/config.d.ts +2 -1
  43. package/build/common/config.d.ts.map +1 -1
  44. package/build/common/config.js +16 -26
  45. package/build/common/constants.d.ts +2 -1
  46. package/build/common/constants.d.ts.map +1 -1
  47. package/build/common/date.d.ts +37 -0
  48. package/build/common/date.d.ts.map +1 -0
  49. package/build/common/date.js +31 -0
  50. package/build/common/http.d.ts +25 -2
  51. package/build/common/http.d.ts.map +1 -1
  52. package/build/common/http.js +26 -3
  53. package/build/common/icons.d.ts +1 -0
  54. package/build/common/icons.d.ts.map +1 -1
  55. package/build/common/icons.js +1 -0
  56. package/build/common/languageColors.d.ts +11 -0
  57. package/build/common/languageColors.d.ts.map +1 -0
  58. package/build/common/languageColors.js +15 -0
  59. package/build/common/languageColors.json +1 -0
  60. package/build/common/ops.d.ts +3 -10
  61. package/build/common/ops.d.ts.map +1 -1
  62. package/build/common/ops.js +3 -15
  63. package/build/common/render.d.ts +43 -6
  64. package/build/common/render.d.ts.map +1 -1
  65. package/build/common/render.js +77 -11
  66. package/build/common/retryer.d.ts +3 -2
  67. package/build/common/retryer.d.ts.map +1 -1
  68. package/build/common/retryer.js +1 -0
  69. package/build/fetchers/gist.d.ts.map +1 -1
  70. package/build/fetchers/gist.js +8 -39
  71. package/build/fetchers/repo.d.ts +12 -11
  72. package/build/fetchers/repo.d.ts.map +1 -1
  73. package/build/fetchers/repo.js +26 -67
  74. package/build/fetchers/stats.d.ts +24 -17
  75. package/build/fetchers/stats.d.ts.map +1 -1
  76. package/build/fetchers/stats.js +302 -183
  77. package/build/fetchers/top-languages.d.ts +10 -15
  78. package/build/fetchers/top-languages.d.ts.map +1 -1
  79. package/build/fetchers/top-languages.js +52 -103
  80. package/build/fetchers/types.d.ts +24 -20
  81. package/build/fetchers/types.d.ts.map +1 -1
  82. package/build/fetchers/wakatime.d.ts +9 -5
  83. package/build/fetchers/wakatime.d.ts.map +1 -1
  84. package/build/fetchers/wakatime.js +8 -4
  85. package/build/graphql/contributionsDocument.d.ts +18 -0
  86. package/build/graphql/contributionsDocument.d.ts.map +1 -0
  87. package/build/graphql/contributionsDocument.js +30 -0
  88. package/build/graphql/generated/common.d.ts +42 -0
  89. package/build/graphql/generated/common.d.ts.map +1 -0
  90. package/build/graphql/generated/common.js +2 -0
  91. package/build/graphql/generated/gist.d.ts +44 -0
  92. package/build/graphql/generated/gist.d.ts.map +1 -0
  93. package/build/graphql/generated/gist.js +27 -0
  94. package/build/graphql/generated/repo.d.ts +67 -0
  95. package/build/graphql/generated/repo.d.ts.map +1 -0
  96. package/build/graphql/generated/repo.js +30 -0
  97. package/build/graphql/generated/stats.d.ts +150 -0
  98. package/build/graphql/generated/stats.d.ts.map +1 -0
  99. package/build/graphql/generated/stats.js +95 -0
  100. package/build/graphql/generated/top-languages.d.ts +54 -0
  101. package/build/graphql/generated/top-languages.d.ts.map +1 -0
  102. package/build/graphql/generated/top-languages.js +27 -0
  103. package/build/graphql/graphqlDocument.d.ts +22 -0
  104. package/build/graphql/graphqlDocument.d.ts.map +1 -0
  105. package/build/graphql/graphqlDocument.js +8 -0
  106. package/build/graphql/reposContributedToDocument.d.ts +27 -0
  107. package/build/graphql/reposContributedToDocument.d.ts.map +1 -0
  108. package/build/graphql/reposContributedToDocument.js +59 -0
  109. package/build/index.d.ts +3 -1
  110. package/build/index.d.ts.map +1 -1
  111. package/build/index.js +2 -1
  112. package/build/themes/index.d.ts +32 -0
  113. package/build/themes/index.d.ts.map +1 -1
  114. package/build/themes/index.js +28 -0
  115. package/build/translations.d.ts +17 -0
  116. package/build/translations.d.ts.map +1 -1
  117. package/build/translations.js +17 -0
  118. package/package.json +13 -7
  119. package/src/_github-username-regex.d.ts +4 -0
  120. package/src/api/gist.js +10 -46
  121. package/src/api/index.js +30 -51
  122. package/src/api/pin.js +10 -46
  123. package/src/api/top-langs.js +13 -60
  124. package/src/api/wakatime.js +10 -46
  125. package/src/cards/common-options.ts +13 -0
  126. package/src/cards/{gist.js → gist.ts} +37 -37
  127. package/src/cards/{repo.js → repo.ts} +86 -68
  128. package/src/cards/{stats.js → stats.ts} +168 -219
  129. package/src/cards/{top-languages.js → top-languages.ts} +309 -265
  130. package/src/cards/{wakatime.js → wakatime.ts} +136 -130
  131. package/src/common/Card.ts +94 -49
  132. package/src/common/I18n.ts +6 -2
  133. package/src/common/color.ts +163 -14
  134. package/src/common/config.ts +22 -29
  135. package/src/common/constants.ts +3 -1
  136. package/src/common/date.ts +45 -0
  137. package/src/common/http.ts +43 -3
  138. package/src/common/icons.ts +1 -0
  139. package/src/common/languageColors.json +1 -0
  140. package/src/common/languageColors.ts +19 -0
  141. package/src/common/ops.ts +8 -18
  142. package/src/common/render.ts +114 -14
  143. package/src/common/retryer.ts +6 -5
  144. package/src/fetchers/gist.ts +15 -72
  145. package/src/fetchers/repo.ts +114 -0
  146. package/src/fetchers/stats.ts +743 -0
  147. package/src/fetchers/top-languages.ts +135 -0
  148. package/src/fetchers/types.ts +28 -20
  149. package/src/fetchers/{wakatime.js → wakatime.ts} +19 -5
  150. package/src/graphql/contributionsDocument.ts +44 -0
  151. package/src/graphql/generated/common.ts +26 -0
  152. package/src/graphql/generated/gist.ts +59 -0
  153. package/src/graphql/generated/repo.ts +90 -0
  154. package/src/graphql/generated/stats.ts +194 -0
  155. package/src/graphql/generated/top-languages.ts +75 -0
  156. package/src/graphql/graphqlDocument.ts +25 -0
  157. package/src/graphql/queries/gist.graphql +25 -0
  158. package/src/graphql/queries/repo.graphql +28 -0
  159. package/src/graphql/queries/stats.graphql +120 -0
  160. package/src/graphql/queries/top-languages.graphql +34 -0
  161. package/src/graphql/reposContributedToDocument.ts +86 -0
  162. package/src/index.ts +3 -1
  163. package/src/themes/index.ts +33 -0
  164. package/src/translations.ts +17 -0
  165. package/src/cards/types.d.ts +0 -78
  166. package/src/fetchers/repo.js +0 -161
  167. package/src/fetchers/stats.js +0 -473
  168. package/src/fetchers/top-languages.js +0 -175
  169. package/src/themes/README.md +0 -229
@@ -1,16 +1,26 @@
1
- export type WakaTimeLang = any;
2
- export type WakaTimeData = any;
3
- export type WakaTimeOptions = any;
4
- /**
5
- * @typedef {import('../fetchers/types').WakaTimeData} WakaTimeData
6
- * @typedef {import('./types').WakaTimeOptions} WakaTimeOptions
7
- */
1
+ import type { WakaTimeData } from "../fetchers/types.js";
2
+ import type { CommonOptions } from "./common-options.js";
3
+ type WakaTimeLayout = "compact" | "normal";
4
+ type DisplayFormat = "time" | "percent";
5
+ interface WakaTimeOptions extends CommonOptions {
6
+ hide_title: boolean;
7
+ hide: Array<string>;
8
+ card_width: number;
9
+ line_height: number | string;
10
+ hide_progress: boolean;
11
+ custom_title: string;
12
+ layout: WakaTimeLayout;
13
+ langs_count: number;
14
+ display_format: DisplayFormat;
15
+ disable_animations: boolean;
16
+ }
8
17
  /**
9
18
  * Renders WakaTime card.
10
19
  *
11
- * @param {Partial<WakaTimeData>} stats WakaTime stats.
12
- * @param {Partial<WakaTimeOptions>} options Card options.
13
- * @returns {string} WakaTime card SVG.
20
+ * @param stats WakaTime stats.
21
+ * @param options Card options.
22
+ * @returns WakaTime card SVG.
14
23
  */
15
- export function renderWakatimeCard(stats?: Partial<WakaTimeData>, options?: Partial<WakaTimeOptions>): string;
24
+ declare const renderWakatimeCard: (stats?: Partial<WakaTimeData>, options?: Partial<WakaTimeOptions>) => string;
25
+ export { renderWakatimeCard };
16
26
  //# sourceMappingURL=wakatime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wakatime.d.ts","sourceRoot":"","sources":["../../src/cards/wakatime.js"],"names":[],"mappings":";;;AAoPA;;;GAGG;AAEH;;;;;;GAMG;AACH,2CAJW,OAAO,CAAC,YAAY,CAAC,YACrB,OAAO,CAAC,eAAe,CAAC,GACtB,MAAM,CA6OlB"}
1
+ {"version":3,"file":"wakatime.d.ts","sourceRoot":"","sources":["../../src/cards/wakatime.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,sBAAsB,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAWzD,KAAK,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAC3C,KAAK,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;AAExC,UAAU,eAAgB,SAAQ,aAAa;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,cAAc,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,aAAa,CAAC;IAC9B,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAoPD;;;;;;GAMG;AACH,QAAA,MAAM,kBAAkB,GACtB,QAAO,OAAO,CAAC,YAAY,CAAM,EACjC,UAAS,OAAO,CAAC,eAAe,CAAgB,KAC/C,MAgNF,CAAC;AAEF,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { Card } from "../common/Card.js";
2
2
  import { I18n } from "../common/I18n.js";
3
- import { getCardColors, isPrefixedHexColor } from "../common/color.js";
3
+ import { getLightDarkColors, isPrefixedHexColor } from "../common/color.js";
4
4
  import { encodeHTML } from "../common/html.js";
5
- import languageColors from "../common/languageColors.json" with { type: "json" };
5
+ import { getLanguageColor } from "../common/languageColors.js";
6
6
  import { clampValue, lowercaseTrim } from "../common/ops.js";
7
7
  import { createProgressNode, flexLayout } from "../common/render.js";
8
8
  import { wakatimeCardLocales } from "../translations.js";
@@ -17,54 +17,46 @@ const TOTAL_TEXT_WIDTH = 275;
17
17
  /**
18
18
  * Creates the no coding activity SVG node.
19
19
  *
20
- * @param {object} props The function properties.
21
- * @param {string} props.color No coding activity text color.
22
- * @param {string} props.text No coding activity translated text.
23
- * @returns {string} No coding activity SVG node string.
20
+ * @param props The function properties.
21
+ * @param props.text No coding activity translated text.
22
+ * @returns No coding activity SVG node string.
24
23
  */
25
- const noCodingActivityNode = ({ color, text }) => {
26
- if (!isPrefixedHexColor(color)) {
27
- throw new Error(`Invalid text color: "${color}"`);
28
- }
24
+ const noCodingActivityNode = ({ text }) => {
29
25
  return `
30
- <text x="25" y="11" class="stat bold" fill="${color}">${encodeHTML(text)}</text>
26
+ <text x="25" y="11" class="stat bold">${encodeHTML(text)}</text>
31
27
  `;
32
28
  };
33
- /**
34
- * @typedef {import('../fetchers/types').WakaTimeLang} WakaTimeLang
35
- */
36
29
  /**
37
30
  * Format language value.
38
31
  *
39
- * @param {Object} args The function arguments.
40
- * @param {WakaTimeLang} args.lang The language object.
41
- * @param {"time" | "percent"} args.display_format The display format of the language node.
42
- * @returns {string} The formatted language value.
32
+ * @param args The function arguments.
33
+ * @param args.lang The language object.
34
+ * @param args.display_format The display format of the language node.
35
+ * @returns The formatted language value.
43
36
  */
44
- const formatLanguageValue = ({ display_format, lang }) => {
37
+ const formatLanguageValue = ({ display_format, lang, }) => {
45
38
  return display_format === "percent"
46
- ? `${lang.percent.toFixed(2).toString()} %`
39
+ ? `${lang.percent.toFixed(2)} %`
47
40
  : lang.text;
48
41
  };
49
42
  /**
50
43
  * Create compact WakaTime layout.
51
44
  *
52
- * @param {Object} args The function arguments.
53
- * @param {WakaTimeLang} args.lang The languages array.
54
- * @param {number} args.x The x position of the language node.
55
- * @param {number} args.y The y position of the language node.
56
- * @param {"time" | "percent"} args.display_format The display format of the language node.
57
- * @returns {string} The compact layout language SVG node.
45
+ * @param args The function arguments.
46
+ * @param args.lang The languages array.
47
+ * @param args.x The x position of the language node.
48
+ * @param args.y The y position of the language node.
49
+ * @param args.display_format The display format of the language node.
50
+ * @returns The compact layout language SVG node.
58
51
  */
59
- const createCompactLangNode = ({ lang, x, y, display_format }) => {
52
+ const createCompactLangNode = ({ lang, x, y, display_format, }) => {
60
53
  if (!Number.isFinite(x)) {
61
54
  throw new Error(`Invalid x: "${x}"`);
62
55
  }
63
56
  if (!Number.isFinite(y)) {
64
57
  throw new Error(`Invalid y: "${y}"`);
65
58
  }
66
- // @ts-ignore
67
- const color = languageColors[lang.name] || "#858585";
59
+ const color = getLanguageColor(lang.name);
68
60
  const value = formatLanguageValue({ display_format, lang });
69
61
  return `
70
62
  <g transform="translate(${x}, ${y})">
@@ -78,14 +70,14 @@ const createCompactLangNode = ({ lang, x, y, display_format }) => {
78
70
  /**
79
71
  * Create WakaTime language text node item.
80
72
  *
81
- * @param {Object} args The function arguments.
82
- * @param {WakaTimeLang[]} args.langs The language objects.
83
- * @param {number} args.y The y position of the language node.
84
- * @param {"time" | "percent"} args.display_format The display format of the language node.
85
- * @param {number} args.card_width Width in px of the card.
86
- * @returns {string[]} The language text node items.
73
+ * @param args The function arguments.
74
+ * @param args.langs The language objects.
75
+ * @param args.y The y position of the language node.
76
+ * @param args.display_format The display format of the language node.
77
+ * @param args.card_width Width in px of the card.
78
+ * @returns The language text node items.
87
79
  */
88
- const createLanguageTextNode = ({ langs, y, display_format, card_width }) => {
80
+ const createLanguageTextNode = ({ langs, y, display_format, card_width, }) => {
89
81
  const LEFT_X = 25;
90
82
  const RIGHT_X_BASE = 230;
91
83
  const rightOffset = (card_width - DEFAULT_CARD_WIDTH) / 2;
@@ -103,19 +95,17 @@ const createLanguageTextNode = ({ langs, y, display_format, card_width }) => {
103
95
  /**
104
96
  * Create WakaTime text item.
105
97
  *
106
- * @param {Object} args The function arguments.
107
- * @param {string} args.id The id of the text node item.
108
- * @param {string} args.label The label of the text node item.
109
- * @param {string} args.value The value of the text node item.
110
- * @param {number} args.index The index of the text node item.
111
- * @param {number} args.percent Percentage of the text node item.
112
- * @param {boolean=} args.hideProgress Whether to hide the progress bar.
113
- * @param {string} args.progressBarColor The color of the progress bar.
114
- * @param {string} args.progressBarBackgroundColor The color of the progress bar background.
115
- * @param {number} args.progressBarWidth The width of the progress bar.
116
- * @returns {string} The text SVG node.
98
+ * @param args The function arguments.
99
+ * @param args.id The id of the text node item.
100
+ * @param args.label The label of the text node item.
101
+ * @param args.value The value of the text node item.
102
+ * @param args.index The index of the text node item.
103
+ * @param args.percent Percentage of the text node item.
104
+ * @param args.hideProgress Whether to hide the progress bar.
105
+ * @param args.progressBarWidth The width of the progress bar.
106
+ * @returns The text SVG node.
117
107
  */
118
- const createTextNode = ({ id, label, value, index, percent, hideProgress, progressBarColor, progressBarBackgroundColor, progressBarWidth, }) => {
108
+ const createTextNode = ({ id, label, value, index, percent, hideProgress, progressBarWidth, }) => {
119
109
  if (!Number.isFinite(index)) {
120
110
  throw new Error(`Invalid index: "${index}"`);
121
111
  }
@@ -129,11 +119,7 @@ const createTextNode = ({ id, label, value, index, percent, hideProgress, progre
129
119
  x: 110,
130
120
  y: 4,
131
121
  progress: percent,
132
- color: progressBarColor,
133
122
  width: progressBarWidth,
134
- // @ts-ignore
135
- name: label,
136
- progressBarBackgroundColor,
137
123
  delay: staggerDelay + 300,
138
124
  });
139
125
  return `
@@ -144,7 +130,7 @@ const createTextNode = ({ id, label, value, index, percent, hideProgress, progre
144
130
  x="${hideProgress ? HIDDEN_PROGRESSBAR_PADDING : PROGRESSBAR_PADDING + progressBarWidth}"
145
131
  y="12.5"
146
132
  >${encodeHTML(value)}</text>
147
- ${cardProgress}
133
+ ${String(cardProgress)}
148
134
  </g>
149
135
  `;
150
136
  };
@@ -152,8 +138,7 @@ const createTextNode = ({ id, label, value, index, percent, hideProgress, progre
152
138
  * Recalculating percentages so that, compact layout's progress bar does not break when
153
139
  * hiding languages.
154
140
  *
155
- * @param {WakaTimeLang[]} languages The languages array.
156
- * @returns {void} The recalculated languages array.
141
+ * @param languages The languages array.
157
142
  */
158
143
  const recalculatePercentages = (languages) => {
159
144
  const totalSum = languages.reduce((totalSum, language) => totalSum + language.percent, 0);
@@ -165,14 +150,11 @@ const recalculatePercentages = (languages) => {
165
150
  /**
166
151
  * Retrieves CSS styles for a card.
167
152
  *
168
- * @param {Object} colors The colors to use for the card.
169
- * @param {string} colors.titleColor The title color.
170
- * @param {string} colors.textColor The text color.
171
- * @returns {string} Card CSS styles.
153
+ * @param colors The colors to use for the card.
154
+ * @param colors.textColor The text color.
155
+ * @returns Card CSS styles.
172
156
  */
173
- const getStyles = function ({
174
- // eslint-disable-next-line no-unused-vars
175
- titleColor, textColor, }) {
157
+ const getStyles = ({ textColor }) => {
176
158
  if (!isPrefixedHexColor(textColor)) {
177
159
  throw new Error(`Invalid text color: "${textColor}"`);
178
160
  }
@@ -195,31 +177,27 @@ titleColor, textColor, }) {
195
177
  /**
196
178
  * Normalize incoming width (string or number) and clamp to minimum.
197
179
  *
198
- * @param {Object} args The function arguments.
199
- * @param {WakaTimeOptions["layout"] | undefined} args.layout The incoming layout value.
200
- * @param {number|undefined} args.value The incoming width value.
201
- * @returns {number} The normalized width value.
180
+ * @param args The function arguments.
181
+ * @param args.layout The incoming layout value.
182
+ * @param args.value The incoming width value.
183
+ * @returns The normalized width value.
202
184
  */
203
- const normalizeCardWidth = ({ value, layout }) => {
204
- if (value === undefined || value === null || isNaN(value)) {
185
+ const normalizeCardWidth = ({ value, layout, }) => {
186
+ if (value === undefined || isNaN(value)) {
205
187
  return DEFAULT_CARD_WIDTH;
206
188
  }
207
189
  return Math.max(layout === "compact" ? COMPACT_LAYOUT_MIN_WIDTH : MIN_CARD_WIDTH, value);
208
190
  };
209
- /**
210
- * @typedef {import('../fetchers/types').WakaTimeData} WakaTimeData
211
- * @typedef {import('./types').WakaTimeOptions} WakaTimeOptions
212
- */
213
191
  /**
214
192
  * Renders WakaTime card.
215
193
  *
216
- * @param {Partial<WakaTimeData>} stats WakaTime stats.
217
- * @param {Partial<WakaTimeOptions>} options Card options.
218
- * @returns {string} WakaTime card SVG.
194
+ * @param stats WakaTime stats.
195
+ * @param options Card options.
196
+ * @returns WakaTime card SVG.
219
197
  */
220
198
  const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
221
199
  let { languages = [] } = stats;
222
- const { hide_title = false, hide_border = false, card_width, hide, line_height = DEFAULT_LINE_HEIGHT, title_color, icon_color, text_color, bg_color, theme = "default", hide_progress, custom_title, locale, layout, langs_count = languages.length, border_radius, border_color, display_format = "time", disable_animations, } = options;
200
+ const { hide_title = false, hide_border = false, card_width, hide, line_height = DEFAULT_LINE_HEIGHT, hide_progress, custom_title, locale, layout, langs_count = languages.length, border_radius, display_format = "time", disable_animations, } = options;
223
201
  const normalizedWidth = normalizeCardWidth({ value: card_width, layout });
224
202
  const shouldHideLangs = Array.isArray(hide) && hide.length > 0;
225
203
  if (shouldHideLangs) {
@@ -236,25 +214,14 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
236
214
  });
237
215
  const lheight = parseInt(String(line_height), 10);
238
216
  const langsCount = clampValue(langs_count, 1, langs_count);
239
- // returns theme based colors with proper overrides and defaults
240
- const { titleColor, textColor, iconColor, bgColor, borderColor } = getCardColors({
241
- title_color,
242
- icon_color,
243
- text_color,
244
- bg_color,
245
- border_color,
246
- theme,
247
- });
217
+ const { lightColors, darkColors } = getLightDarkColors(options);
218
+ const { titleColor, textColor } = lightColors;
248
219
  const filteredLanguages = languages
249
220
  .filter((language) => language.hours || language.minutes)
250
221
  .slice(0, langsCount);
251
222
  // Calculate the card height depending on how many items there are
252
223
  // but if rank circle is visible clamp the minimum height to `150`
253
224
  let height = Math.max(45 + (filteredLanguages.length + 1) * lheight, 150);
254
- const cssStyles = getStyles({
255
- titleColor,
256
- textColor,
257
- });
258
225
  let finalLayout;
259
226
  // RENDER COMPACT LAYOUT
260
227
  if (layout === "compact") {
@@ -268,8 +235,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
268
235
  .map((language) => {
269
236
  const progress = ((width - COMPACT_LAYOUT_PROGRESSBAR_PADDING) * language.percent) /
270
237
  100;
271
- // @ts-ignore
272
- const languageColor = languageColors[language.name] || "#858585";
238
+ const languageColor = getLanguageColor(language.name);
273
239
  const output = `
274
240
  <rect
275
241
  mask="url(#rect-mask)"
@@ -298,8 +264,6 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
298
264
  card_width: normalizedWidth,
299
265
  }).join("")
300
266
  : noCodingActivityNode({
301
- // @ts-ignore
302
- color: textColor,
303
267
  text: stats.is_coding_activity_visible
304
268
  ? stats.is_other_usage_visible
305
269
  ? i18n.t("wakatimecard.nocodingactivity")
@@ -318,20 +282,12 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
318
282
  value: formatLanguageValue({ display_format, lang: language }),
319
283
  index,
320
284
  percent: language.percent,
321
- // @ts-ignore
322
- progressBarColor: titleColor,
323
- // @ts-ignore
324
- progressBarBackgroundColor: textColor === titleColor
325
- ? "#fff0" // transparent
326
- : textColor,
327
285
  hideProgress: hide_progress,
328
286
  progressBarWidth: normalizedWidth - TOTAL_TEXT_WIDTH,
329
287
  });
330
288
  })
331
289
  : [
332
290
  noCodingActivityNode({
333
- // @ts-ignore
334
- color: textColor,
335
291
  text: stats.is_coding_activity_visible
336
292
  ? stats.is_other_usage_visible
337
293
  ? i18n.t("wakatimecard.nocodingactivity")
@@ -359,21 +315,16 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
359
315
  width: normalizedWidth,
360
316
  height,
361
317
  border_radius,
362
- colors: {
363
- titleColor,
364
- textColor,
365
- iconColor,
366
- bgColor,
367
- borderColor,
368
- },
318
+ colors: { light: lightColors, dark: darkColors },
369
319
  });
370
320
  if (disable_animations) {
371
321
  card.disableAnimations();
372
322
  }
373
323
  card.setHideBorder(hide_border);
374
324
  card.setHideTitle(hide_title);
375
- card.setCSS(`
376
- ${cssStyles}
325
+ card.setCSS({
326
+ light: `
327
+ ${getStyles({ textColor })}
377
328
  @keyframes slideInAnimation {
378
329
  from {
379
330
  width: 0;
@@ -396,8 +347,19 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
396
347
  }
397
348
  .lang-progress{
398
349
  animation: growWidthAnimation 0.6s ease-in-out forwards;
350
+ fill: ${titleColor};
399
351
  }
400
- `);
352
+ .progress-background { fill: ${textColor === titleColor ? "#fff0" /* transparent */ : textColor}; }
353
+ `,
354
+ dark: darkColors
355
+ ? `
356
+ ${getStyles({ textColor: darkColors.textColor })}
357
+ .lang-name { fill: ${darkColors.textColor} }
358
+ .lang-progress { fill: ${darkColors.titleColor}; }
359
+ .progress-background { fill: ${darkColors.textColor === darkColors.titleColor ? "#fff0" /* transparent */ : darkColors.textColor}; }
360
+ `
361
+ : null,
362
+ });
401
363
  return card.render(`
402
364
  <svg x="0" y="0" width="100%">
403
365
  ${finalLayout}
@@ -1,14 +1,14 @@
1
1
  interface CardColors {
2
2
  /** Card title color. */
3
- titleColor?: string;
3
+ titleColor: string;
4
4
  /** Card text color. */
5
- textColor?: string;
5
+ textColor: string;
6
6
  /** Card icon color. */
7
- iconColor?: string;
7
+ iconColor: string;
8
8
  /** Card background color. */
9
- bgColor?: string | Array<string>;
9
+ bgColor: string | Array<string>;
10
10
  /** Card border color. */
11
- borderColor?: string;
11
+ borderColor: string;
12
12
  }
13
13
  declare class Card {
14
14
  width: number;
@@ -16,9 +16,13 @@ declare class Card {
16
16
  hideBorder: boolean;
17
17
  hideTitle: boolean;
18
18
  border_radius: number;
19
- colors: CardColors;
19
+ colors: {
20
+ light: CardColors;
21
+ dark: CardColors | null;
22
+ };
20
23
  title: string;
21
24
  css: string;
25
+ darkCss: string;
22
26
  paddingX: number;
23
27
  paddingY: number;
24
28
  titlePrefixIcon: string | undefined;
@@ -34,7 +38,9 @@ declare class Card {
34
38
  * @param props.width Card width.
35
39
  * @param props.height Card height.
36
40
  * @param props.border_radius Card border radius.
37
- * @param props.colors Card colors arguments.
41
+ * @param props.colors Card colors for light and dark mode.
42
+ * @param props.colors.light Card colors for light mode.
43
+ * @param props.colors.dark Card colors for dark mode, or `null` when no dark-mode override is needed.
38
44
  * @param props.customTitle Card custom title.
39
45
  * @param props.defaultTitle Card default title.
40
46
  * @param props.titlePrefixIcon Sanitized card title prefix icon.
@@ -42,9 +48,12 @@ declare class Card {
42
48
  constructor({ width, height, border_radius, colors, customTitle, defaultTitle, titlePrefixIcon, }: {
43
49
  width?: number;
44
50
  height?: number;
45
- border_radius?: number;
46
- colors?: CardColors;
47
- customTitle?: string;
51
+ border_radius?: number | undefined;
52
+ colors?: {
53
+ light: CardColors;
54
+ dark: CardColors | null;
55
+ };
56
+ customTitle?: string | undefined;
48
57
  defaultTitle?: string;
49
58
  titlePrefixIcon?: string;
50
59
  });
@@ -59,11 +68,18 @@ declare class Card {
59
68
  desc: string;
60
69
  }): void;
61
70
  /**
62
- * The caller must ensure that the passed `css` string is properly sanitized!
71
+ * Sets the card CSS for light and dark mode.
63
72
  *
64
- * @param value The sanitized CSS to add to the card.
73
+ * The caller must ensure that the passed CSS strings are properly sanitized!
74
+ *
75
+ * @param props The props object.
76
+ * @param props.light CSS applied unconditionally (light/default mode).
77
+ * @param props.dark CSS placed inside a `@media (prefers-color-scheme: dark)` block. Pass `null` when not needed.
65
78
  */
66
- setCSS(value: string): void;
79
+ setCSS({ light, dark }: {
80
+ light: string;
81
+ dark?: string | null;
82
+ }): void;
67
83
  /**
68
84
  * @param value Whether to hide the border or not.
69
85
  */
@@ -90,6 +106,11 @@ declare class Card {
90
106
  * @returns Animation css.
91
107
  */
92
108
  getAnimations: () => string;
109
+ /**
110
+ * Builds the @media (prefers-color-scheme: dark) CSS block for the card.
111
+ * Returns an empty string when no dark colors are set.
112
+ */
113
+ private renderDarkMediaBlock;
93
114
  /**
94
115
  * The caller must ensure that the passed `body` string is properly sanitized!
95
116
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Card.d.ts","sourceRoot":"","sources":["../../src/common/Card.ts"],"names":[],"mappings":"AAIA,UAAU,UAAU;IAClB,wBAAwB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IAC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