@stats-organization/github-readme-stats-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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/build/api/gist.d.ts +19 -0
- package/build/api/gist.d.ts.map +1 -0
- package/build/api/gist.js +77 -0
- package/build/api/index.d.ts +37 -0
- package/build/api/index.d.ts.map +1 -0
- package/build/api/index.js +115 -0
- package/build/api/pin.d.ts +27 -0
- package/build/api/pin.d.ts.map +1 -0
- package/build/api/pin.js +104 -0
- package/build/api/top-langs.d.ts +31 -0
- package/build/api/top-langs.d.ts.map +1 -0
- package/build/api/top-langs.js +121 -0
- package/build/api/wakatime.d.ts +28 -0
- package/build/api/wakatime.d.ts.map +1 -0
- package/build/api/wakatime.js +85 -0
- package/build/calculateRank.d.ts +28 -0
- package/build/calculateRank.d.ts.map +1 -0
- package/build/calculateRank.js +63 -0
- package/build/cards/gist.d.ts +21 -0
- package/build/cards/gist.d.ts.map +1 -0
- package/build/cards/gist.js +124 -0
- package/build/cards/repo.d.ts +21 -0
- package/build/cards/repo.d.ts.map +1 -0
- package/build/cards/repo.js +264 -0
- package/build/cards/stats.d.ts +49 -0
- package/build/cards/stats.d.ts.map +1 -0
- package/build/cards/stats.js +527 -0
- package/build/cards/top-languages.d.ts +143 -0
- package/build/cards/top-languages.d.ts.map +1 -0
- package/build/cards/top-languages.js +795 -0
- package/build/cards/wakatime.d.ts +16 -0
- package/build/cards/wakatime.d.ts.map +1 -0
- package/build/cards/wakatime.js +387 -0
- package/build/common/Card.d.ts +109 -0
- package/build/common/Card.d.ts.map +1 -0
- package/build/common/Card.js +241 -0
- package/build/common/I18n.d.ts +26 -0
- package/build/common/I18n.d.ts.map +1 -0
- package/build/common/I18n.js +34 -0
- package/build/common/color.d.ts +53 -0
- package/build/common/color.d.ts.map +1 -0
- package/build/common/color.js +92 -0
- package/build/common/config.d.ts +3 -0
- package/build/common/config.d.ts.map +1 -0
- package/build/common/config.js +69 -0
- package/build/common/constants.d.ts +6 -0
- package/build/common/constants.d.ts.map +1 -0
- package/build/common/constants.js +7 -0
- package/build/common/error.d.ts +53 -0
- package/build/common/error.d.ts.map +1 -0
- package/build/common/error.js +72 -0
- package/build/common/fmt.d.ts +27 -0
- package/build/common/fmt.d.ts.map +1 -0
- package/build/common/fmt.js +66 -0
- package/build/common/html.d.ts +10 -0
- package/build/common/html.d.ts.map +1 -0
- package/build/common/html.js +18 -0
- package/build/common/http.d.ts +9 -0
- package/build/common/http.d.ts.map +1 -0
- package/build/common/http.js +18 -0
- package/build/common/icons.d.ts +26 -0
- package/build/common/icons.d.ts.map +1 -0
- package/build/common/icons.js +77 -0
- package/build/common/languageColors.json +667 -0
- package/build/common/log.d.ts +9 -0
- package/build/common/log.d.ts.map +1 -0
- package/build/common/log.js +8 -0
- package/build/common/ops.d.ts +65 -0
- package/build/common/ops.d.ts.map +1 -0
- package/build/common/ops.js +137 -0
- package/build/common/render.d.ts +155 -0
- package/build/common/render.d.ts.map +1 -0
- package/build/common/render.js +361 -0
- package/build/common/retryer.d.ts +22 -0
- package/build/common/retryer.d.ts.map +1 -0
- package/build/common/retryer.js +86 -0
- package/build/fetchers/gist.d.ts +26 -0
- package/build/fetchers/gist.d.ts.map +1 -0
- package/build/fetchers/gist.js +99 -0
- package/build/fetchers/repo.d.ts +16 -0
- package/build/fetchers/repo.d.ts.map +1 -0
- package/build/fetchers/repo.js +116 -0
- package/build/fetchers/stats.d.ts +22 -0
- package/build/fetchers/stats.d.ts.map +1 -0
- package/build/fetchers/stats.js +339 -0
- package/build/fetchers/top-languages.d.ts +20 -0
- package/build/fetchers/top-languages.d.ts.map +1 -0
- package/build/fetchers/top-languages.js +139 -0
- package/build/fetchers/wakatime.d.ts +11 -0
- package/build/fetchers/wakatime.d.ts.map +1 -0
- package/build/fetchers/wakatime.js +25 -0
- package/build/index.d.ts +20 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +19 -0
- package/build/themes/index.d.ts +469 -0
- package/build/themes/index.d.ts.map +1 -0
- package/build/themes/index.js +468 -0
- package/build/translations.d.ts +533 -0
- package/build/translations.d.ts.map +1 -0
- package/build/translations.js +1140 -0
- package/package.json +94 -0
- package/src/api/gist.js +99 -0
- package/src/api/index.js +185 -0
- package/src/api/pin.js +146 -0
- package/src/api/top-langs.js +168 -0
- package/src/api/wakatime.js +113 -0
- package/src/calculateRank.js +86 -0
- package/src/cards/gist.js +187 -0
- package/src/cards/repo.js +365 -0
- package/src/cards/stats.js +673 -0
- package/src/cards/top-languages.js +1023 -0
- package/src/cards/types.d.ts +78 -0
- package/src/cards/wakatime.js +471 -0
- package/src/common/Card.js +275 -0
- package/src/common/I18n.js +42 -0
- package/src/common/color.js +145 -0
- package/src/common/config.js +78 -0
- package/src/common/constants.js +9 -0
- package/src/common/error.js +90 -0
- package/src/common/fmt.js +80 -0
- package/src/common/html.js +22 -0
- package/src/common/http.js +21 -0
- package/src/common/icons.js +81 -0
- package/src/common/languageColors.json +667 -0
- package/src/common/log.ts +12 -0
- package/src/common/ops.js +172 -0
- package/src/common/render.js +442 -0
- package/src/common/retryer.js +104 -0
- package/src/fetchers/gist.js +114 -0
- package/src/fetchers/repo.js +165 -0
- package/src/fetchers/stats.js +478 -0
- package/src/fetchers/top-languages.js +177 -0
- package/src/fetchers/types.d.ts +128 -0
- package/src/fetchers/wakatime.js +37 -0
- package/src/index.ts +25 -0
- package/src/themes/README.md +229 -0
- package/src/themes/index.ts +476 -0
- package/src/translations.js +1156 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns boolean if value is either "true" or "false" else the value as it is.
|
|
3
|
+
*
|
|
4
|
+
* @param {string | boolean} value The value to parse.
|
|
5
|
+
* @returns {boolean | undefined } The parsed value.
|
|
6
|
+
*/
|
|
7
|
+
export function parseBoolean(value: string | boolean): boolean | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Parse string to array of strings.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} str The string to parse.
|
|
12
|
+
* @returns {string[]} The array of strings.
|
|
13
|
+
*/
|
|
14
|
+
export function parseArray(str: string): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Clamp the given number between the given range.
|
|
17
|
+
*
|
|
18
|
+
* @param {number} number The number to clamp.
|
|
19
|
+
* @param {number} min The minimum value.
|
|
20
|
+
* @param {number} max The maximum value.
|
|
21
|
+
* @returns {number} The clamped number.
|
|
22
|
+
*/
|
|
23
|
+
export function clampValue(number: number, min: number, max: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Lowercase and trim string.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} name String to lowercase and trim.
|
|
28
|
+
* @returns {string} Lowercased and trimmed string.
|
|
29
|
+
*/
|
|
30
|
+
export function lowercaseTrim(name: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Split array of languages in two columns.
|
|
33
|
+
*
|
|
34
|
+
* @template T Language object.
|
|
35
|
+
* @param {Array<T>} arr Array of languages.
|
|
36
|
+
* @param {number} perChunk Number of languages per column.
|
|
37
|
+
* @returns {Array<T>} Array of languages split in two columns.
|
|
38
|
+
*/
|
|
39
|
+
export function chunkArray<T>(arr: Array<T>, perChunk: number): Array<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Parse emoji from string.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} str String to parse emoji from.
|
|
44
|
+
* @returns {string} String with emoji parsed.
|
|
45
|
+
*/
|
|
46
|
+
export function parseEmojis(str: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Get diff in minutes between two dates.
|
|
49
|
+
*
|
|
50
|
+
* @param {Date} d1 First date.
|
|
51
|
+
* @param {Date} d2 Second date.
|
|
52
|
+
* @returns {number} Number of minutes between the two dates.
|
|
53
|
+
*/
|
|
54
|
+
export function dateDiff(d1: Date, d2: Date): number;
|
|
55
|
+
/**
|
|
56
|
+
* Parse owner affiliations.
|
|
57
|
+
*
|
|
58
|
+
* @param {string[]} affiliations input affiliations to be parsed.
|
|
59
|
+
* @returns {string[]} Parsed affiliations.
|
|
60
|
+
*
|
|
61
|
+
* @throws {CustomError} If affiliations contains invalid values.
|
|
62
|
+
*/
|
|
63
|
+
export function parseOwnerAffiliations(affiliations: string[]): string[];
|
|
64
|
+
export function buildSearchFilter(repos?: any[], owners?: any[]): string;
|
|
65
|
+
//# sourceMappingURL=ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops.d.ts","sourceRoot":"","sources":["../../src/common/ops.js"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,oCAHW,MAAM,GAAG,OAAO,GACd,OAAO,GAAG,SAAS,CAe/B;AAED;;;;;GAKG;AACH,gCAHW,MAAM,GACJ,MAAM,EAAE,CAOpB;AAED;;;;;;;GAOG;AACH,mCALW,MAAM,OACN,MAAM,OACN,MAAM,GACJ,MAAM,CAQlB;AAED;;;;;GAKG;AACH,oCAHW,MAAM,GACJ,MAAM,CAEsC;AAEzD;;;;;;;GAOG;AACH,2BALa,CAAC,OACH,KAAK,CAAC,CAAC,CAAC,YACR,MAAM,GACJ,KAAK,CAAC,CAAC,CAAC,CAgBpB;AAED;;;;;GAKG;AACH,iCAHW,MAAM,GACJ,MAAM,CASlB;AAED;;;;;;GAMG;AACH,6BAJW,IAAI,MACJ,IAAI,GACF,MAAM,CAOlB;AAED;;;;;;;GAOG;AACH,qDALW,MAAM,EAAE,GACN,MAAM,EAAE,CAyBpB;AAED,yEAUC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import toEmoji from "emoji-name-map";
|
|
3
|
+
import { OWNER_AFFILIATIONS } from "./constants.js";
|
|
4
|
+
import { CustomError } from "./error.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns boolean if value is either "true" or "false" else the value as it is.
|
|
7
|
+
*
|
|
8
|
+
* @param {string | boolean} value The value to parse.
|
|
9
|
+
* @returns {boolean | undefined } The parsed value.
|
|
10
|
+
*/
|
|
11
|
+
const parseBoolean = (value) => {
|
|
12
|
+
if (typeof value === "boolean") {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === "string") {
|
|
16
|
+
if (value.toLowerCase() === "true") {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
else if (value.toLowerCase() === "false") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Parse string to array of strings.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} str The string to parse.
|
|
29
|
+
* @returns {string[]} The array of strings.
|
|
30
|
+
*/
|
|
31
|
+
const parseArray = (str) => {
|
|
32
|
+
if (!str) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return str.split(",");
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Clamp the given number between the given range.
|
|
39
|
+
*
|
|
40
|
+
* @param {number} number The number to clamp.
|
|
41
|
+
* @param {number} min The minimum value.
|
|
42
|
+
* @param {number} max The maximum value.
|
|
43
|
+
* @returns {number} The clamped number.
|
|
44
|
+
*/
|
|
45
|
+
const clampValue = (number, min, max) => {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
if (Number.isNaN(parseInt(number, 10))) {
|
|
48
|
+
return min;
|
|
49
|
+
}
|
|
50
|
+
return Math.max(min, Math.min(number, max));
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Lowercase and trim string.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} name String to lowercase and trim.
|
|
56
|
+
* @returns {string} Lowercased and trimmed string.
|
|
57
|
+
*/
|
|
58
|
+
const lowercaseTrim = (name) => name.toLowerCase().trim();
|
|
59
|
+
/**
|
|
60
|
+
* Split array of languages in two columns.
|
|
61
|
+
*
|
|
62
|
+
* @template T Language object.
|
|
63
|
+
* @param {Array<T>} arr Array of languages.
|
|
64
|
+
* @param {number} perChunk Number of languages per column.
|
|
65
|
+
* @returns {Array<T>} Array of languages split in two columns.
|
|
66
|
+
*/
|
|
67
|
+
const chunkArray = (arr, perChunk) => {
|
|
68
|
+
return arr.reduce((resultArray, item, index) => {
|
|
69
|
+
const chunkIndex = Math.floor(index / perChunk);
|
|
70
|
+
if (!resultArray[chunkIndex]) {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
resultArray[chunkIndex] = []; // start a new chunk
|
|
73
|
+
}
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
resultArray[chunkIndex].push(item);
|
|
76
|
+
return resultArray;
|
|
77
|
+
}, []);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Parse emoji from string.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} str String to parse emoji from.
|
|
83
|
+
* @returns {string} String with emoji parsed.
|
|
84
|
+
*/
|
|
85
|
+
const parseEmojis = (str) => {
|
|
86
|
+
if (!str) {
|
|
87
|
+
throw new Error("[parseEmoji]: str argument not provided");
|
|
88
|
+
}
|
|
89
|
+
return str.replace(/:\w+:/gm, (emoji) => {
|
|
90
|
+
return toEmoji.get(emoji) || "";
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Get diff in minutes between two dates.
|
|
95
|
+
*
|
|
96
|
+
* @param {Date} d1 First date.
|
|
97
|
+
* @param {Date} d2 Second date.
|
|
98
|
+
* @returns {number} Number of minutes between the two dates.
|
|
99
|
+
*/
|
|
100
|
+
const dateDiff = (d1, d2) => {
|
|
101
|
+
const date1 = new Date(d1);
|
|
102
|
+
const date2 = new Date(d2);
|
|
103
|
+
const diff = date1.getTime() - date2.getTime();
|
|
104
|
+
return Math.round(diff / (1000 * 60));
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Parse owner affiliations.
|
|
108
|
+
*
|
|
109
|
+
* @param {string[]} affiliations input affiliations to be parsed.
|
|
110
|
+
* @returns {string[]} Parsed affiliations.
|
|
111
|
+
*
|
|
112
|
+
* @throws {CustomError} If affiliations contains invalid values.
|
|
113
|
+
*/
|
|
114
|
+
const parseOwnerAffiliations = (affiliations) => {
|
|
115
|
+
// Set default value for ownerAffiliations.
|
|
116
|
+
// NOTE: Done here since parseArray() will always return an empty array even nothing
|
|
117
|
+
//was specified.
|
|
118
|
+
affiliations =
|
|
119
|
+
affiliations && affiliations.length > 0
|
|
120
|
+
? affiliations.map((affiliation) => affiliation.toUpperCase())
|
|
121
|
+
: ["OWNER"];
|
|
122
|
+
// Check if ownerAffiliations contains valid values.
|
|
123
|
+
if (affiliations.some((affiliation) => !OWNER_AFFILIATIONS.includes(affiliation))) {
|
|
124
|
+
throw new CustomError("Invalid query parameter", CustomError.INVALID_AFFILIATION);
|
|
125
|
+
}
|
|
126
|
+
return affiliations;
|
|
127
|
+
};
|
|
128
|
+
const buildSearchFilter = (repos = [], owners = []) => {
|
|
129
|
+
let repoFilter = Array.isArray(repos) && repos.length > 0
|
|
130
|
+
? repos.map((r) => `repo:${r} `).join("")
|
|
131
|
+
: "";
|
|
132
|
+
let orgFilter = Array.isArray(owners) && owners.length > 0
|
|
133
|
+
? owners.map((o) => `owner:${o} `).join("")
|
|
134
|
+
: "";
|
|
135
|
+
return repoFilter + orgFilter;
|
|
136
|
+
};
|
|
137
|
+
export { parseBoolean, parseArray, clampValue, lowercaseTrim, chunkArray, parseEmojis, dateDiff, parseOwnerAffiliations, buildSearchFilter, };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders error message on the card.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} args Function arguments.
|
|
5
|
+
* @param {string} args.message Main error message.
|
|
6
|
+
* @param {string} [args.secondaryMessage=""] The secondary error message.
|
|
7
|
+
* @param {object} [args.renderOptions={}] Render options.
|
|
8
|
+
* @param {string=} args.renderOptions.title_color Card title color.
|
|
9
|
+
* @param {string=} args.renderOptions.text_color Card text color.
|
|
10
|
+
* @param {string=} args.renderOptions.bg_color Card background color.
|
|
11
|
+
* @param {string=} args.renderOptions.border_color Card border color.
|
|
12
|
+
* @param {Parameters<typeof getCardColors>[0]["theme"]=} args.renderOptions.theme Card theme.
|
|
13
|
+
* @param {boolean=} args.renderOptions.show_repo_link Whether to show repo link or not.
|
|
14
|
+
* @returns {string} The SVG markup.
|
|
15
|
+
*/
|
|
16
|
+
export function renderError({ message, secondaryMessage, renderOptions, }: {
|
|
17
|
+
message: string;
|
|
18
|
+
secondaryMessage?: string | undefined;
|
|
19
|
+
renderOptions?: {
|
|
20
|
+
title_color?: string | undefined;
|
|
21
|
+
text_color?: string | undefined;
|
|
22
|
+
bg_color?: string | undefined;
|
|
23
|
+
border_color?: string | undefined;
|
|
24
|
+
theme?: Parameters<typeof getCardColors>[0]["theme"] | undefined;
|
|
25
|
+
show_repo_link?: boolean | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
}): string;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a node to display the primary programming language of the repository/gist.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} langName Language name.
|
|
32
|
+
* @param {string} langColor Language color.
|
|
33
|
+
* @returns {string} Language display SVG object.
|
|
34
|
+
*/
|
|
35
|
+
export function createLanguageNode(langName: string, langColor: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Create a node to indicate progress in percentage along a horizontal line.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} params Object that contains the createProgressNode parameters.
|
|
40
|
+
* @param {number} params.x X-axis position.
|
|
41
|
+
* @param {number} params.y Y-axis position.
|
|
42
|
+
* @param {number} params.width Width of progress bar.
|
|
43
|
+
* @param {string} params.color Progress color.
|
|
44
|
+
* @param {number} params.progress Progress value.
|
|
45
|
+
* @param {string} params.progressBarBackgroundColor Progress bar bg color.
|
|
46
|
+
* @param {number} params.delay Delay before animation starts.
|
|
47
|
+
* @returns {string} Progress node.
|
|
48
|
+
*/
|
|
49
|
+
export function createProgressNode({ x, y, width, color, progress, progressBarBackgroundColor, delay, }: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
width: number;
|
|
53
|
+
color: string;
|
|
54
|
+
progress: number;
|
|
55
|
+
progressBarBackgroundColor: string;
|
|
56
|
+
delay: number;
|
|
57
|
+
}): string;
|
|
58
|
+
/**
|
|
59
|
+
* Creates an icon with label to display repository/gist stats like forks, stars, etc.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} icon The icon to display.
|
|
62
|
+
* @param {number|string} label The label to display.
|
|
63
|
+
* @param {string} testid The testid to assign to the label.
|
|
64
|
+
* @param {number} iconSize The size of the icon.
|
|
65
|
+
* @returns {string} Icon with label SVG object.
|
|
66
|
+
*/
|
|
67
|
+
export function iconWithLabel(icon: string, label: number | string, testid: string, iconSize: number): string;
|
|
68
|
+
/**
|
|
69
|
+
* Auto layout utility, allows us to layout things vertically or horizontally with
|
|
70
|
+
* proper gaping.
|
|
71
|
+
*
|
|
72
|
+
* @param {object} props Function properties.
|
|
73
|
+
* @param {string[]} props.items Array of items to layout.
|
|
74
|
+
* @param {number} props.gap Gap between items.
|
|
75
|
+
* @param {"column" | "row"=} props.direction Direction to layout items.
|
|
76
|
+
* @param {number[]=} props.sizes Array of sizes for each item.
|
|
77
|
+
* @returns {string[]} Array of items with proper layout.
|
|
78
|
+
*/
|
|
79
|
+
export function flexLayout({ items, gap, direction, sizes }: {
|
|
80
|
+
items: string[];
|
|
81
|
+
gap: number;
|
|
82
|
+
direction?: ("column" | "row") | undefined;
|
|
83
|
+
sizes?: number[] | undefined;
|
|
84
|
+
}): string[];
|
|
85
|
+
/**
|
|
86
|
+
* Retrieve text length based on Segoe UI font.
|
|
87
|
+
*
|
|
88
|
+
* @see https://stackoverflow.com/a/48172630/10629172
|
|
89
|
+
* @param {string} str String to measure.
|
|
90
|
+
* @param {number} fontSize Font size.
|
|
91
|
+
* @returns {number} Text length.
|
|
92
|
+
*/
|
|
93
|
+
export function measureText(str: string, fontSize?: number): number;
|
|
94
|
+
/**
|
|
95
|
+
* Split text into the lines it would wrap to when laid out greedily at the
|
|
96
|
+
* given font size inside a box of width `maxWidth`. Uses `measureText` so the
|
|
97
|
+
* estimate reflects actual font metrics rather than a fixed character count.
|
|
98
|
+
* The browser still does the real wrap inside the foreignObject; this is only
|
|
99
|
+
* used to size the SVG.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} text Text to split.
|
|
102
|
+
* @param {number} fontSize Font size in px (matches `measureText`).
|
|
103
|
+
* @param {number} maxWidth Available wrap width in px.
|
|
104
|
+
* @returns {string[]} Estimated wrapped lines.
|
|
105
|
+
*/
|
|
106
|
+
export function splitWrappedText(text: string, fontSize: number, maxWidth: number): string[];
|
|
107
|
+
/**
|
|
108
|
+
* Estimate how many lines a string will wrap to when laid out greedily at the
|
|
109
|
+
* given font size inside a box of width `maxWidth`, capped at `maxLines`.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} text Text to estimate.
|
|
112
|
+
* @param {number} fontSize Font size in px (matches `measureText`).
|
|
113
|
+
* @param {number} maxWidth Available wrap width in px.
|
|
114
|
+
* @param {number} maxLines Cap on the returned line count.
|
|
115
|
+
* @returns {number} Estimated line count, at least 1, at most `maxLines`.
|
|
116
|
+
*/
|
|
117
|
+
export function countWrappedLines(text: string, fontSize: number, maxWidth: number, maxLines: number): number;
|
|
118
|
+
/**
|
|
119
|
+
* Renders multi-line text via a `foreignObject` so the browser performs
|
|
120
|
+
* native, font-aware wrapping. Content overflowing `lineCount` lines is
|
|
121
|
+
* clipped (with an ellipsis on the last visible line) by CSS line-clamp.
|
|
122
|
+
*
|
|
123
|
+
* @param {object} props Function properties.
|
|
124
|
+
* @param {string} props.text Text to render (will be HTML-encoded).
|
|
125
|
+
* @param {number} props.x X position of the foreignObject.
|
|
126
|
+
* @param {number} props.y Y position of the foreignObject.
|
|
127
|
+
* @param {number} props.width Width of the wrap box.
|
|
128
|
+
* @param {number} props.height Height of the wrap box.
|
|
129
|
+
* @param {number} props.lineCount Maximum number of lines to display.
|
|
130
|
+
* @param {string} props.className CSS class applied to the inner element.
|
|
131
|
+
* @param {string=} props.testId Optional test id for the inner element.
|
|
132
|
+
* @returns {string} foreignObject SVG node.
|
|
133
|
+
*/
|
|
134
|
+
export function wrappedTextNode({ text, x, y, width, height, lineCount, className, testId, }: {
|
|
135
|
+
text: string;
|
|
136
|
+
x: number;
|
|
137
|
+
y: number;
|
|
138
|
+
width: number;
|
|
139
|
+
height: number;
|
|
140
|
+
lineCount: number;
|
|
141
|
+
className: string;
|
|
142
|
+
testId?: string | undefined;
|
|
143
|
+
}): string;
|
|
144
|
+
/**
|
|
145
|
+
* CSS rules used to render multi-line text inside a `foreignObject`. Apply this
|
|
146
|
+
* to a CSS class (e.g. `.description`) shared with `wrappedTextNode` so the
|
|
147
|
+
* browser handles wrapping and the line count is taken from the `--lines`
|
|
148
|
+
* custom property set on the element.
|
|
149
|
+
*
|
|
150
|
+
* @param {string} color Text color (CSS `color` property).
|
|
151
|
+
* @returns {string} CSS rules block (without the surrounding selector).
|
|
152
|
+
*/
|
|
153
|
+
export function wrappedTextStyles(color: string): string;
|
|
154
|
+
import { getCardColors } from "./color.js";
|
|
155
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/common/render.js"],"names":[],"mappings":"AAyLA;;;;;;;;;;;;;;GAcG;AACH,2EAXG;IAAqB,OAAO,EAApB,MAAM;IACQ,gBAAgB;IAChB,aAAa;sBAC3B,MAAM,YAAC;qBACP,MAAM,YAAC;mBACP,MAAM,YAAC;uBACP,MAAM,YAAC;gBACP,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAC;yBAC7C,OAAO,YAAC;;CAChB,GAAU,MAAM,CAgDlB;AAtND;;;;;;GAMG;AACH,6CAJW,MAAM,aACN,MAAM,GACJ,MAAM,CASlB;AAED;;;;;;;;;;;;GAYG;AACH,yGATG;IAAuB,CAAC,EAAhB,MAAM;IACS,CAAC,EAAhB,MAAM;IACS,KAAK,EAApB,MAAM;IACS,KAAK,EAApB,MAAM;IACS,QAAQ,EAAvB,MAAM;IACS,0BAA0B,EAAzC,MAAM;IACS,KAAK,EAApB,MAAM;CACd,GAAU,MAAM,CA2BlB;AA8DD;;;;;;;;GAQG;AACH,oCANW,MAAM,SACN,MAAM,GAAC,MAAM,UACb,MAAM,YACN,MAAM,GACJ,MAAM,CAoBlB;AAxKD;;;;;;;;;;GAUG;AACH,6DANG;IAAwB,KAAK,EAArB,MAAM,EAAE;IACM,GAAG,EAAjB,MAAM;IACmB,SAAS,GAAlC,CAAA,QAAQ,GAAG,KAAK,aAAC;IACA,KAAK,GAAtB,MAAM,EAAE,YAAC;CACjB,GAAU,MAAM,EAAE,CAcpB;AA0ND;;;;;;;GAOG;AACH,iCAJW,MAAM,aACN,MAAM,GACJ,MAAM,CA6DlB;AAED;;;;;;;;;;;GAWG;AACH,uCALW,MAAM,YACN,MAAM,YACN,MAAM,GACJ,MAAM,EAAE,CAoFpB;AAED;;;;;;;;;GASG;AACH,wCANW,MAAM,YACN,MAAM,YACN,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB;AApVD;;;;;;;;;;;;;;;GAeG;AACH,8FAVG;IAAsB,IAAI,EAAlB,MAAM;IACQ,CAAC,EAAf,MAAM;IACQ,CAAC,EAAf,MAAM;IACQ,KAAK,EAAnB,MAAM;IACQ,MAAM,EAApB,MAAM;IACQ,SAAS,EAAvB,MAAM;IACQ,SAAS,EAAvB,MAAM;IACS,MAAM,GAArB,MAAM,YAAC;CACf,GAAU,MAAM,CAoBlB;AAED;;;;;;;;GAQG;AACH,yCAHW,MAAM,GACJ,MAAM,CAelB;8BAhJ6B,YAAY"}
|