@stats-forge/github-stats-forge-core 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -10
- package/build/api/api-result.d.ts +6 -7
- package/build/api/api-result.d.ts.map +1 -1
- package/build/api/api-result.js +4 -5
- package/build/api/gist.d.ts +3 -10
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +4 -11
- package/build/api/index.d.ts +12 -12
- package/build/api/params.d.ts +11 -8
- package/build/api/params.d.ts.map +1 -1
- package/build/api/params.js +16 -14
- package/build/api/pin.d.ts +3 -19
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +6 -22
- package/build/api/stats.d.ts +10 -4
- package/build/api/stats.d.ts.map +1 -1
- package/build/api/stats.js +6 -32
- package/build/api/top-langs.d.ts +12 -6
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +6 -26
- package/build/api/wakatime.d.ts +13 -5
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +4 -21
- package/build/calculateRank.d.ts +0 -9
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +12 -17
- package/build/cards/gist.d.ts +2 -4
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +27 -36
- package/build/cards/options.d.ts +1 -1
- package/build/cards/repo.d.ts +2 -4
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +61 -93
- package/build/cards/stats.d.ts +3 -8
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +119 -165
- package/build/cards/top-languages.d.ts +5 -31
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +176 -384
- package/build/cards/wakatime.d.ts +4 -6
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +118 -185
- package/build/common/Card.d.ts +14 -62
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +97 -199
- package/build/common/I18n.d.ts +0 -6
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +3 -6
- package/build/common/color.d.ts +4 -17
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +67 -49
- package/build/common/config.d.ts +4 -14
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +3 -16
- package/build/common/constants.d.ts +4 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +3 -1
- package/build/common/date.d.ts +0 -2
- package/build/common/date.d.ts.map +1 -1
- package/build/common/date.js +0 -2
- package/build/common/emojiMap.d.ts +8 -0
- package/build/common/emojiMap.d.ts.map +1 -0
- package/build/common/emojiMap.js +10 -0
- package/build/common/emojiMap.json +1915 -0
- package/build/common/error.d.ts +1 -10
- package/build/common/error.d.ts.map +1 -1
- package/build/common/error.js +1 -10
- package/build/common/fmt.d.ts +3 -15
- package/build/common/fmt.d.ts.map +1 -1
- package/build/common/fmt.js +7 -35
- package/build/common/http.d.ts +2 -7
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +8 -17
- package/build/common/icons.d.ts +18 -20
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +103 -67
- package/build/common/languageColors.d.ts +0 -1
- package/build/common/languageColors.d.ts.map +1 -1
- package/build/common/languageColors.js +1 -4
- package/build/common/languageColors.json +18 -2
- package/build/common/ops.d.ts +3 -14
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +19 -30
- package/build/common/render.d.ts +28 -82
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +175 -211
- package/build/common/retryer.d.ts +2 -7
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +4 -11
- package/build/fetchers/gist.d.ts +2 -5
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +1 -5
- package/build/fetchers/index.d.ts +12 -12
- package/build/fetchers/repo.d.ts +2 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +20 -33
- package/build/fetchers/stats.d.ts +2 -32
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +27 -86
- package/build/fetchers/top-languages.d.ts +2 -9
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +15 -31
- package/build/fetchers/types.d.ts +1 -1
- package/build/fetchers/wakatime.d.ts +2 -6
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +1 -5
- package/build/graphql/contributionsDocument.d.ts +3 -3
- package/build/graphql/contributionsDocument.d.ts.map +1 -1
- package/build/graphql/contributionsDocument.js +0 -1
- package/build/graphql/generated/gist.d.ts +1 -1
- package/build/graphql/generated/repo.d.ts +1 -1
- package/build/graphql/generated/stats.d.ts +3 -3
- package/build/graphql/generated/top-languages.d.ts +2 -2
- package/build/graphql/graphqlDocument.d.ts +0 -1
- package/build/graphql/graphqlDocument.d.ts.map +1 -1
- package/build/graphql/graphqlDocument.js +0 -1
- package/build/graphql/reposContributedToDocument.d.ts +4 -5
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
- package/build/graphql/reposContributedToDocument.js +0 -2
- package/build/markup/css.d.ts +35 -0
- package/build/markup/css.d.ts.map +1 -0
- package/build/markup/css.js +64 -0
- package/build/markup/element.d.ts +41 -0
- package/build/markup/element.d.ts.map +1 -0
- package/build/markup/element.js +127 -0
- package/build/markup/html.d.ts +13 -0
- package/build/markup/html.d.ts.map +1 -0
- package/build/markup/html.js +27 -0
- package/build/markup/index.d.ts +9 -0
- package/build/markup/index.d.ts.map +1 -0
- package/build/markup/index.js +6 -0
- package/build/markup/serialize.d.ts +16 -0
- package/build/markup/serialize.d.ts.map +1 -0
- package/build/markup/serialize.js +17 -0
- package/build/themes/index.d.ts +332 -333
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +1 -1
- package/build/translations.d.ts +2 -6
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +621 -628
- package/package.json +17 -26
- package/src/api/api-result.ts +10 -9
- package/src/api/gist.ts +11 -18
- package/src/api/index.ts +12 -12
- package/src/api/params.ts +27 -21
- package/src/api/pin.ts +13 -28
- package/src/api/stats.ts +13 -39
- package/src/api/top-langs.ts +13 -33
- package/src/api/wakatime.ts +11 -28
- package/src/calculateRank.ts +12 -23
- package/src/cards/gist.ts +40 -43
- package/src/cards/options.ts +1 -1
- package/src/cards/repo.ts +97 -107
- package/src/cards/stats.ts +165 -184
- package/src/cards/top-languages.ts +297 -413
- package/src/cards/wakatime.ts +193 -221
- package/src/common/Card.ts +165 -217
- package/src/common/I18n.ts +3 -6
- package/src/common/color.ts +80 -57
- package/src/common/config.ts +5 -18
- package/src/common/constants.ts +5 -2
- package/src/common/date.ts +0 -2
- package/src/common/emojiMap.json +1915 -0
- package/src/common/emojiMap.ts +13 -0
- package/src/common/error.ts +2 -11
- package/src/common/fmt.ts +7 -44
- package/src/common/http.ts +9 -15
- package/src/common/icons.ts +117 -42
- package/src/common/languageColors.json +18 -2
- package/src/common/languageColors.ts +1 -4
- package/src/common/ops.ts +26 -34
- package/src/common/render.ts +279 -232
- package/src/common/retryer.ts +8 -15
- package/src/fetchers/gist.ts +8 -12
- package/src/fetchers/index.ts +12 -12
- package/src/fetchers/repo.ts +27 -40
- package/src/fetchers/stats.ts +44 -102
- package/src/fetchers/top-languages.ts +26 -40
- package/src/fetchers/types.ts +1 -1
- package/src/fetchers/wakatime.ts +5 -9
- package/src/graphql/contributionsDocument.ts +7 -5
- package/src/graphql/generated/gist.ts +1 -1
- package/src/graphql/generated/repo.ts +1 -1
- package/src/graphql/generated/stats.ts +2 -2
- package/src/graphql/generated/top-languages.ts +2 -2
- package/src/graphql/graphqlDocument.ts +0 -1
- package/src/graphql/reposContributedToDocument.ts +6 -7
- package/src/markup/css.ts +118 -0
- package/src/markup/element.ts +246 -0
- package/src/markup/html.ts +34 -0
- package/src/markup/index.ts +9 -0
- package/src/markup/serialize.ts +27 -0
- package/src/themes/index.ts +1 -1
- package/src/translations.ts +622 -629
- package/build/cards/index.d.ts +0 -11
- package/build/cards/index.d.ts.map +0 -1
- package/build/cards/index.js +0 -7
- package/build/common/html.d.ts +0 -8
- package/build/common/html.d.ts.map +0 -1
- package/build/common/html.js +0 -14
- package/build/index.d.ts +0 -15
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -10
- package/src/_emoji-name-map.d.ts +0 -10
- package/src/_github-username-regex.d.ts +0 -4
- package/src/cards/index.ts +0 -21
- package/src/common/html.ts +0 -17
- package/src/index.ts +0 -18
package/build/common/Card.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
|
+
import { atRule, cssComment, el, renderMarkup, rule, style } from '../markup/index.js';
|
|
1
2
|
import { getCardColors, isPrefixedHexColor, isValidGradient } from './color.js';
|
|
2
|
-
import { encodeHTML } from './html.js';
|
|
3
3
|
import { flexLayout } from './render.js';
|
|
4
|
+
/** Stops every animation, whether the reader asked or the card did. */
|
|
5
|
+
const NO_MOTION = {
|
|
6
|
+
'animation-duration': '0s !important',
|
|
7
|
+
'animation-delay': '0s !important',
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves css animations for a card.
|
|
11
|
+
*
|
|
12
|
+
* @returns Animation css.
|
|
13
|
+
*/
|
|
14
|
+
const getAnimations = () => [
|
|
15
|
+
cssComment('Animations'),
|
|
16
|
+
atRule('@keyframes scaleInAnimation', rule('from', { transform: 'translate(-5px, 5px) scale(0)' }), rule('to', { transform: 'translate(-5px, 5px) scale(1)' })),
|
|
17
|
+
atRule('@keyframes fadeInAnimation', rule('from', { opacity: 0 }), rule('to', { opacity: 1 })),
|
|
18
|
+
atRule('@media (prefers-reduced-motion: reduce)', rule('*', NO_MOTION)),
|
|
19
|
+
];
|
|
20
|
+
/** One `linearGradient` definition, built from an angle followed by its stops. */
|
|
21
|
+
const buildGradientDef = (id, bgColor) => {
|
|
22
|
+
const gradients = bgColor.slice(1);
|
|
23
|
+
return el('linearGradient', {
|
|
24
|
+
id,
|
|
25
|
+
gradientTransform: `rotate(${String(bgColor[0])})`,
|
|
26
|
+
gradientUnits: 'userSpaceOnUse',
|
|
27
|
+
}, gradients.map((grad, index) => el('stop', {
|
|
28
|
+
offset: `${(index * 100) / (gradients.length - 1)}%`,
|
|
29
|
+
'stop-color': `#${grad}`,
|
|
30
|
+
})));
|
|
31
|
+
};
|
|
4
32
|
class Card {
|
|
5
33
|
width;
|
|
6
34
|
height;
|
|
@@ -19,30 +47,17 @@ class Card {
|
|
|
19
47
|
a11yDesc;
|
|
20
48
|
/**
|
|
21
49
|
* Creates a new card instance.
|
|
22
|
-
*
|
|
23
|
-
* The caller must ensure that the passed `titlePrefixIcon` is properly sanitized!
|
|
24
|
-
*
|
|
25
|
-
* @param props Card arguments.
|
|
26
|
-
* @param props.width Card width.
|
|
27
|
-
* @param props.height Card height.
|
|
28
|
-
* @param props.border_radius Card border radius.
|
|
29
|
-
* @param props.colors Card colors for light and dark mode.
|
|
30
|
-
* @param props.colors.light Card colors for light mode.
|
|
31
|
-
* @param props.colors.dark Card colors for dark mode, or `null` when no dark-mode override is needed.
|
|
32
|
-
* @param props.customTitle Card custom title.
|
|
33
|
-
* @param props.defaultTitle Card default title.
|
|
34
|
-
* @param props.titlePrefixIcon Sanitized card title prefix icon.
|
|
35
50
|
*/
|
|
36
|
-
constructor({ width = 100, height = 100, border_radius =
|
|
51
|
+
constructor({ width = 100, height = 100, border_radius = 8, colors = { light: getCardColors({}), dark: null }, customTitle, defaultTitle = '', titlePrefixIcon, }) {
|
|
37
52
|
this.width = width;
|
|
38
53
|
this.height = height;
|
|
39
54
|
this.hideBorder = false;
|
|
40
55
|
this.hideTitle = false;
|
|
41
|
-
this.border_radius = parseFloat(String(border_radius));
|
|
56
|
+
this.border_radius = Number.parseFloat(String(border_radius));
|
|
42
57
|
this.colors = colors;
|
|
43
|
-
this.title = customTitle
|
|
44
|
-
this.css =
|
|
45
|
-
this.darkCss =
|
|
58
|
+
this.title = customTitle ?? defaultTitle;
|
|
59
|
+
this.css = [];
|
|
60
|
+
this.darkCss = [];
|
|
46
61
|
this.paddingX = 25;
|
|
47
62
|
this.paddingY = 35;
|
|
48
63
|
this.titlePrefixIcon = titlePrefixIcon;
|
|
@@ -53,11 +68,6 @@ class Card {
|
|
|
53
68
|
disableAnimations() {
|
|
54
69
|
this.animations = false;
|
|
55
70
|
}
|
|
56
|
-
/**
|
|
57
|
-
* @param props The props object.
|
|
58
|
-
* @param props.title Accessibility title.
|
|
59
|
-
* @param props.desc Accessibility description.
|
|
60
|
-
*/
|
|
61
71
|
setAccessibilityLabel({ title, desc }) {
|
|
62
72
|
this.a11yTitle = title;
|
|
63
73
|
this.a11yDesc = desc;
|
|
@@ -68,26 +78,14 @@ class Card {
|
|
|
68
78
|
* Each builder receives the colors of its own color scheme,
|
|
69
79
|
* so a card never handles a missing dark palette itself:
|
|
70
80
|
* `dark` runs only when the card has dark colors, and always with non-null ones.
|
|
71
|
-
*
|
|
72
|
-
* @warning The caller must ensure that the returned CSS strings are properly sanitized!
|
|
73
|
-
*
|
|
74
|
-
* @param props The props object.
|
|
75
|
-
* @param props.light Builds the CSS applied unconditionally (light/default mode).
|
|
76
|
-
* @param props.dark Builds the CSS placed inside a `@media (prefers-color-scheme: dark)` block.
|
|
77
81
|
*/
|
|
78
82
|
setCSS({ light, dark }) {
|
|
79
83
|
this.css = light(this.colors.light);
|
|
80
|
-
this.darkCss = this.colors.dark ? dark(this.colors.dark) :
|
|
84
|
+
this.darkCss = this.colors.dark ? dark(this.colors.dark) : [];
|
|
81
85
|
}
|
|
82
|
-
/**
|
|
83
|
-
* @param value Whether to hide the border or not.
|
|
84
|
-
*/
|
|
85
86
|
setHideBorder(value) {
|
|
86
87
|
this.hideBorder = value;
|
|
87
88
|
}
|
|
88
|
-
/**
|
|
89
|
-
* @param value Whether to hide the title or not.
|
|
90
|
-
*/
|
|
91
89
|
setHideTitle(value) {
|
|
92
90
|
if (value && !this.hideTitle) {
|
|
93
91
|
this.height -= 30;
|
|
@@ -97,69 +95,33 @@ class Card {
|
|
|
97
95
|
}
|
|
98
96
|
this.hideTitle = value;
|
|
99
97
|
}
|
|
100
|
-
/**
|
|
101
|
-
* @param text The title to set.
|
|
102
|
-
*/
|
|
103
98
|
setTitle(text) {
|
|
104
99
|
this.title = text;
|
|
105
100
|
}
|
|
106
|
-
/**
|
|
107
|
-
* @returns The rendered card title.
|
|
108
|
-
*/
|
|
101
|
+
/** @returns The rendered card title. */
|
|
109
102
|
renderTitle() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
>
|
|
128
|
-
${String(this.titlePrefixIcon)}
|
|
129
|
-
</svg>
|
|
130
|
-
`;
|
|
131
|
-
return `
|
|
132
|
-
<g
|
|
133
|
-
data-testid="card-title"
|
|
134
|
-
transform="translate(${this.paddingX}, ${this.paddingY})"
|
|
135
|
-
>
|
|
136
|
-
${flexLayout({
|
|
137
|
-
items: [this.titlePrefixIcon ? prefixIcon : '', titleText],
|
|
103
|
+
return el('g', {
|
|
104
|
+
'data-testid': 'card-title',
|
|
105
|
+
transform: `translate(${this.paddingX}, ${this.paddingY})`,
|
|
106
|
+
}, flexLayout({
|
|
107
|
+
items: [
|
|
108
|
+
this.titlePrefixIcon &&
|
|
109
|
+
el('svg', {
|
|
110
|
+
class: 'icon',
|
|
111
|
+
x: 0,
|
|
112
|
+
y: -13,
|
|
113
|
+
viewBox: '0 0 16 16',
|
|
114
|
+
version: '1.1',
|
|
115
|
+
width: 16,
|
|
116
|
+
height: 16,
|
|
117
|
+
}, this.titlePrefixIcon),
|
|
118
|
+
el('text', { x: 0, y: 0, class: 'header', 'data-testid': 'header' }, this.title),
|
|
119
|
+
],
|
|
138
120
|
gap: 25,
|
|
139
|
-
})
|
|
140
|
-
</g>
|
|
141
|
-
`;
|
|
121
|
+
}));
|
|
142
122
|
}
|
|
143
|
-
/**
|
|
144
|
-
* @returns The rendered card gradient.
|
|
145
|
-
*/
|
|
123
|
+
/** @returns The card's gradient definitions, or nothing when no color is a gradient. */
|
|
146
124
|
renderGradient() {
|
|
147
|
-
const buildGradientDef = (id, bgColor) => {
|
|
148
|
-
const gradients = bgColor.slice(1);
|
|
149
|
-
return `
|
|
150
|
-
<linearGradient
|
|
151
|
-
id="${id}"
|
|
152
|
-
gradientTransform="rotate(${String(bgColor[0])})"
|
|
153
|
-
gradientUnits="userSpaceOnUse"
|
|
154
|
-
>
|
|
155
|
-
${gradients
|
|
156
|
-
.map((grad, index) => {
|
|
157
|
-
const offset = (index * 100) / (gradients.length - 1);
|
|
158
|
-
return `<stop offset="${offset}%" stop-color="#${grad}" />`;
|
|
159
|
-
})
|
|
160
|
-
.join(',')}
|
|
161
|
-
</linearGradient>`;
|
|
162
|
-
};
|
|
163
125
|
if (typeof this.colors.light.bgColor === 'object' &&
|
|
164
126
|
!isValidGradient(this.colors.light.bgColor)) {
|
|
165
127
|
throw new Error(`Invalid gradient: ${this.colors.light.bgColor.join(',')}`);
|
|
@@ -169,66 +131,32 @@ class Card {
|
|
|
169
131
|
!isValidGradient(this.colors.dark.bgColor)) {
|
|
170
132
|
throw new Error(`Invalid dark gradient: ${this.colors.dark.bgColor.join(',')}`);
|
|
171
133
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
134
|
+
const defs = [
|
|
135
|
+
typeof this.colors.light.bgColor === 'object' &&
|
|
136
|
+
buildGradientDef('gradient', this.colors.light.bgColor),
|
|
137
|
+
this.colors.dark &&
|
|
138
|
+
typeof this.colors.dark.bgColor === 'object' &&
|
|
139
|
+
buildGradientDef('gradient-dark', this.colors.dark.bgColor),
|
|
140
|
+
].filter(Boolean);
|
|
141
|
+
return defs.length === 0 ? undefined : el('defs', {}, defs);
|
|
178
142
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Retrieves css animations for a card.
|
|
181
|
-
*
|
|
182
|
-
* @returns Animation css.
|
|
183
|
-
*/
|
|
184
|
-
getAnimations = () => {
|
|
185
|
-
return `
|
|
186
|
-
/* Animations */
|
|
187
|
-
@keyframes scaleInAnimation {
|
|
188
|
-
from {
|
|
189
|
-
transform: translate(-5px, 5px) scale(0);
|
|
190
|
-
}
|
|
191
|
-
to {
|
|
192
|
-
transform: translate(-5px, 5px) scale(1);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
@keyframes fadeInAnimation {
|
|
196
|
-
from {
|
|
197
|
-
opacity: 0;
|
|
198
|
-
}
|
|
199
|
-
to {
|
|
200
|
-
opacity: 1;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
`;
|
|
204
|
-
};
|
|
205
143
|
/**
|
|
206
144
|
* Builds the @media (prefers-color-scheme: dark) CSS block for the card.
|
|
207
|
-
* Returns
|
|
145
|
+
* Returns nothing when no dark colors are set.
|
|
208
146
|
*/
|
|
209
147
|
renderDarkMediaBlock() {
|
|
210
148
|
if (!this.colors.dark) {
|
|
211
|
-
return
|
|
149
|
+
return undefined;
|
|
212
150
|
}
|
|
213
151
|
const bgFill = typeof this.colors.dark.bgColor === 'object'
|
|
214
152
|
? 'url(#gradient-dark)'
|
|
215
153
|
: this.colors.dark.bgColor;
|
|
216
|
-
return
|
|
217
|
-
@media (prefers-color-scheme: dark) {
|
|
218
|
-
.header { fill: ${this.colors.dark.titleColor}; }
|
|
219
|
-
.card-bg { fill: ${bgFill}; stroke: ${this.colors.dark.borderColor}; }
|
|
220
|
-
${this.darkCss}
|
|
221
|
-
}`;
|
|
154
|
+
return atRule('@media (prefers-color-scheme: dark)', rule('.header', { fill: this.colors.dark.titleColor }), rule('.card-bg', { fill: bgFill, stroke: this.colors.dark.borderColor }), this.darkCss);
|
|
222
155
|
}
|
|
223
|
-
/**
|
|
224
|
-
* The caller must ensure that the passed `body` string is properly sanitized!
|
|
225
|
-
*
|
|
226
|
-
* @param body The sanitized inner body of the card.
|
|
227
|
-
* @returns The rendered card.
|
|
228
|
-
*/
|
|
156
|
+
/** @returns The rendered card. */
|
|
229
157
|
render(body) {
|
|
230
158
|
if (!Number.isFinite(this.border_radius)) {
|
|
231
|
-
throw new
|
|
159
|
+
throw new TypeError(`Invalid border radius: "${this.border_radius}"`);
|
|
232
160
|
}
|
|
233
161
|
if (!isPrefixedHexColor(this.colors.light.titleColor)) {
|
|
234
162
|
throw new Error(`Invalid title color: "${this.colors.light.titleColor}"`);
|
|
@@ -241,65 +169,35 @@ class Card {
|
|
|
241
169
|
: isPrefixedHexColor(this.colors.light.bgColor))) {
|
|
242
170
|
throw new Error(`Invalid background color: ${String(this.colors.light.bgColor)}`);
|
|
243
171
|
}
|
|
244
|
-
return
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
?
|
|
272
|
-
|
|
273
|
-
</style>
|
|
274
|
-
|
|
275
|
-
${this.renderGradient()}
|
|
276
|
-
|
|
277
|
-
<rect
|
|
278
|
-
data-testid="card-bg"
|
|
279
|
-
class="card-bg"
|
|
280
|
-
x="0.5"
|
|
281
|
-
y="0.5"
|
|
282
|
-
rx="${this.border_radius}"
|
|
283
|
-
height="99%"
|
|
284
|
-
stroke="${this.colors.light.borderColor}"
|
|
285
|
-
width="${this.width - 1}"
|
|
286
|
-
fill="${typeof this.colors.light.bgColor === 'object'
|
|
287
|
-
? 'url(#gradient)'
|
|
288
|
-
: this.colors.light.bgColor}"
|
|
289
|
-
stroke-opacity="${this.hideBorder ? 0 : 1}"
|
|
290
|
-
/>
|
|
291
|
-
|
|
292
|
-
${this.hideTitle ? '' : this.renderTitle()}
|
|
293
|
-
|
|
294
|
-
<g
|
|
295
|
-
data-testid="main-card-body"
|
|
296
|
-
transform="translate(0, ${this.hideTitle ? this.paddingX : this.paddingY + 20})"
|
|
297
|
-
>
|
|
298
|
-
${body}
|
|
299
|
-
</g>
|
|
300
|
-
</svg>
|
|
301
|
-
`;
|
|
172
|
+
return renderMarkup(el('svg', {
|
|
173
|
+
width: this.width,
|
|
174
|
+
height: this.height,
|
|
175
|
+
viewBox: `0 0 ${this.width} ${this.height}`,
|
|
176
|
+
fill: 'none',
|
|
177
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
178
|
+
role: 'img',
|
|
179
|
+
'aria-labelledby': 'titleId descId',
|
|
180
|
+
}, el('title', { id: 'titleId' }, this.a11yTitle), el('desc', { id: 'descId' }, this.a11yDesc), style(rule('.header', {
|
|
181
|
+
font: "600 18px 'Segoe UI', Ubuntu, Sans-Serif",
|
|
182
|
+
fill: this.colors.light.titleColor,
|
|
183
|
+
animation: 'fadeInAnimation 0.8s ease-in-out forwards',
|
|
184
|
+
}), atRule('@supports(-moz-appearance: auto)', cssComment('Selector detects Firefox'), rule('.header', { 'font-size': '15.5px' })), this.css, this.renderDarkMediaBlock(), getAnimations(), !this.animations && rule('*', NO_MOTION)), this.renderGradient(), el('rect', {
|
|
185
|
+
'data-testid': 'card-bg',
|
|
186
|
+
class: 'card-bg',
|
|
187
|
+
x: 0.5,
|
|
188
|
+
y: 0.5,
|
|
189
|
+
rx: this.border_radius,
|
|
190
|
+
height: '99%',
|
|
191
|
+
stroke: this.colors.light.borderColor,
|
|
192
|
+
width: this.width - 1,
|
|
193
|
+
fill: typeof this.colors.light.bgColor === 'object'
|
|
194
|
+
? 'url(#gradient)'
|
|
195
|
+
: this.colors.light.bgColor,
|
|
196
|
+
'stroke-opacity': this.hideBorder ? 0 : 1,
|
|
197
|
+
}), !this.hideTitle && this.renderTitle(), el('g', {
|
|
198
|
+
'data-testid': 'main-card-body',
|
|
199
|
+
transform: `translate(0, ${this.hideTitle ? this.paddingX : this.paddingY + 20})`,
|
|
200
|
+
}, body)));
|
|
302
201
|
}
|
|
303
202
|
}
|
|
304
203
|
export { Card };
|
|
305
|
-
export default Card;
|
package/build/common/I18n.d.ts
CHANGED
|
@@ -6,11 +6,6 @@ type TranslationsMap = Record<string, Record<string, string>>;
|
|
|
6
6
|
declare class I18n<Translations extends TranslationsMap = TranslationsMap> {
|
|
7
7
|
locale: string;
|
|
8
8
|
translations: Translations;
|
|
9
|
-
/**
|
|
10
|
-
* @param props Constructor arguments.
|
|
11
|
-
* @param props.locale Locale.
|
|
12
|
-
* @param props.translations Translations.
|
|
13
|
-
*/
|
|
14
9
|
constructor({ locale, translations, }: {
|
|
15
10
|
locale?: string | undefined;
|
|
16
11
|
translations: Translations;
|
|
@@ -18,7 +13,6 @@ declare class I18n<Translations extends TranslationsMap = TranslationsMap> {
|
|
|
18
13
|
/**
|
|
19
14
|
* Get translation.
|
|
20
15
|
*
|
|
21
|
-
* @param str String to translate.
|
|
22
16
|
* @returns Translated string.
|
|
23
17
|
*/
|
|
24
18
|
t(str: keyof Translations & string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"I18n.d.ts","sourceRoot":"","sources":["../../src/common/I18n.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D;;GAEG;AACH,cAAM,IAAI,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAE3B
|
|
1
|
+
{"version":3,"file":"I18n.d.ts","sourceRoot":"","sources":["../../src/common/I18n.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D;;GAEG;AACH,cAAM,IAAI,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAE3B,YAAY,EACV,MAAM,EACN,YAAY,GACb,EAAE;QAED,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,YAAY,EAAE,YAAY,CAAC;KAC5B,EAGA;IAED;;;;OAIG;IACH,CAAC,CAAC,GAAG,EAAE,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAe1C;CACF;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/build/common/I18n.js
CHANGED
|
@@ -5,11 +5,6 @@ const FALLBACK_LOCALE = 'en';
|
|
|
5
5
|
class I18n {
|
|
6
6
|
locale;
|
|
7
7
|
translations;
|
|
8
|
-
/**
|
|
9
|
-
* @param props Constructor arguments.
|
|
10
|
-
* @param props.locale Locale.
|
|
11
|
-
* @param props.translations Translations.
|
|
12
|
-
*/
|
|
13
8
|
constructor({ locale, translations, }) {
|
|
14
9
|
this.locale = locale || FALLBACK_LOCALE;
|
|
15
10
|
this.translations = translations;
|
|
@@ -17,11 +12,13 @@ class I18n {
|
|
|
17
12
|
/**
|
|
18
13
|
* Get translation.
|
|
19
14
|
*
|
|
20
|
-
* @param str String to translate.
|
|
21
15
|
* @returns Translated string.
|
|
22
16
|
*/
|
|
23
17
|
t(str) {
|
|
24
18
|
const translation = this.translations[str];
|
|
19
|
+
// A key the type says is present can still be missing at runtime: a card passes
|
|
20
|
+
// a locale table it built, and `i18n.test.ts` covers exactly that.
|
|
21
|
+
// oxlint-disable-next-line typescript/no-unnecessary-condition
|
|
25
22
|
if (!translation) {
|
|
26
23
|
throw new Error(`${str} Translation string not found`);
|
|
27
24
|
}
|
package/build/common/color.d.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* (`"f00"`, `"ffffff"`). This is the form user-supplied color params and
|
|
4
4
|
* gradient stops arrive in.
|
|
5
5
|
*
|
|
6
|
-
* @param value Value to check.
|
|
7
6
|
* @returns True if the value is a bare hex color.
|
|
8
7
|
*/
|
|
9
8
|
declare const isBareHexColor: (value: unknown) => boolean;
|
|
@@ -12,7 +11,6 @@ declare const isBareHexColor: (value: unknown) => boolean;
|
|
|
12
11
|
* is the form colors take once resolved by {@link getCardColors}, i.e. right
|
|
13
12
|
* before they are written into the SVG.
|
|
14
13
|
*
|
|
15
|
-
* @param value Value to check.
|
|
16
14
|
* @returns True if the value is a `#`-prefixed hex color.
|
|
17
15
|
*/
|
|
18
16
|
declare const isPrefixedHexColor: (value: unknown) => boolean;
|
|
@@ -21,14 +19,12 @@ declare const isPrefixedHexColor: (value: unknown) => boolean;
|
|
|
21
19
|
* followed by at least two bare-hex color stops, e.g. `["90", "f00", "0f0"]`.
|
|
22
20
|
* The angle is written into the SVG `gradientTransform="rotate(...)"`.
|
|
23
21
|
*
|
|
24
|
-
* @param parts Gradient parts: `[angle, ...stops]`.
|
|
25
22
|
* @returns True if the parts form a valid gradient.
|
|
26
23
|
*/
|
|
27
24
|
declare const isValidGradient: (parts: Array<string>) => boolean;
|
|
28
25
|
/**
|
|
29
26
|
* Checks if a string is a valid input for a color or gradient.
|
|
30
27
|
*
|
|
31
|
-
* @param color String to check, may be null or undefined.
|
|
32
28
|
* @returns True if the given string is a valid input.
|
|
33
29
|
*/
|
|
34
30
|
declare const isValidColorInput: (color: string | null | undefined) => boolean;
|
|
@@ -57,8 +53,8 @@ interface CardColors {
|
|
|
57
53
|
* Single source of truth: the param types and {@link COLOR_PARAM_KEYS} are all
|
|
58
54
|
* derived from this, so adding a param here is enough.
|
|
59
55
|
*/
|
|
60
|
-
declare const BASE_COLOR_KEYS: readonly [
|
|
61
|
-
declare const THEME_VARIANTS: readonly [
|
|
56
|
+
declare const BASE_COLOR_KEYS: readonly ['title_color', 'icon_color', 'text_color', 'bg_color', 'border_color', 'ring_color', 'prog_bar_bg_color', 'theme'];
|
|
57
|
+
declare const THEME_VARIANTS: readonly ['light', 'dark'];
|
|
62
58
|
type BaseColorKey = (typeof BASE_COLOR_KEYS)[number];
|
|
63
59
|
type ThemeVariant = (typeof THEME_VARIANTS)[number];
|
|
64
60
|
/**
|
|
@@ -70,15 +66,6 @@ type ColorInput = Partial<Record<BaseColorKey, string | undefined>>;
|
|
|
70
66
|
/**
|
|
71
67
|
* Returns theme based colors with proper overrides and defaults.
|
|
72
68
|
*
|
|
73
|
-
* @param props Function arguments.
|
|
74
|
-
* @param props.title_color Card title color.
|
|
75
|
-
* @param props.text_color Card text color.
|
|
76
|
-
* @param props.icon_color Card icon color.
|
|
77
|
-
* @param props.bg_color Card background color.
|
|
78
|
-
* @param props.border_color Card border color.
|
|
79
|
-
* @param props.ring_color Card ring color.
|
|
80
|
-
* @param props.prog_bar_bg_color Progress bar background color.
|
|
81
|
-
* @param props.theme Card theme.
|
|
82
69
|
* @returns Card colors.
|
|
83
70
|
*/
|
|
84
71
|
declare const getCardColors: ({ title_color, text_color, icon_color, bg_color, border_color, ring_color, prog_bar_bg_color, theme, }: ColorInput) => CardColors;
|
|
@@ -94,9 +81,9 @@ type LightDarkColorParams = Partial<Record<`${BaseColorKey}_${ThemeVariant}`, st
|
|
|
94
81
|
* Anything a mode does not override falls back to the general params,
|
|
95
82
|
* so a partial override such as `bg_color_dark` alone keeps every other color from the base theme.
|
|
96
83
|
*
|
|
97
|
-
* When no `_light` / `_dark` param is provided at all,
|
|
84
|
+
* When no `_light` / `_dark` param is provided at all,
|
|
85
|
+
* `darkColors` is `null` and the caller emits no dark-mode block.
|
|
98
86
|
*
|
|
99
|
-
* @param params Raw query params, containing both general and `_light`/`_dark` suffixed colors and themes.
|
|
100
87
|
* @returns `{ lightColors, darkColors }`, resolved colors for both light and dark mode
|
|
101
88
|
*/
|
|
102
89
|
declare const getLightDarkColors: (params: ColorInput & LightDarkColorParams) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/common/color.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../src/common/color.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,QAAA,MAAM,cAAc,UAAW,OAAO,KAAG,OACW,CAAC;AAErD;;;;;;GAMG;AACH,QAAA,MAAM,kBAAkB,UAAW,OAAO,KAAG,OACyC,CAAC;AAEvF;;;;;;GAMG;AACH,QAAA,MAAM,eAAe,UAAW,KAAK,CAAC,MAAM,CAAC,KAAG,OAS/C,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,UAAW,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAK7D,CAAC;AA8DF;;GAEG;AACH,UAAU,UAAU;IAClB,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,yBAAyB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,QAAA,MAAM,eAAe,YACnB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,OAAO,CACC,CAAC;AAEX,QAAA,MAAM,cAAc,YAAI,OAAO,EAAE,MAAM,CAAU,CAAC;AAElD,KAAK,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,KAAK,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpD;;;;GAIG;AACH,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAEpE;;;;GAIG;AACH,QAAA,MAAM,aAAa,2GAShB,UAAU,KAAG,UA+Cf,CAAC;AAEF,KAAK,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,IAAI,YAAY,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AA8BnG;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,kBAAkB,WACd,UAAU,GAAG,oBAAoB,KACxC;IAAE,WAAW,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAA;CAU1D,CAAC;AAEF,KAAK,WAAW,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAErD,QAAA,MAAM,gBAAgB,EAAE,aAAa,CAAC,MAAM,WAAW,CAKtD,CAAC;AAEF,+DAA+D;AAC/D,QAAA,MAAM,gBAAgB,EAAE,aAAa,CAAC,MAAM,WAAW,CAGtD,CAAC;AAEF,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AAExC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAIlB,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,CAAC"}
|