kira-arts 1.5.0 → 1.6.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 +16 -15
- package/dist/index.cjs +29 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +29 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ A TypeScript library for generating Discord-style visual cards — profiles, wel
|
|
|
32
32
|
- ⚡ Built-in, configurable in-memory cache for fetched user data (`setCacheOptions`, `clearCache`, `getCacheSize`)
|
|
33
33
|
- 🛡️ Typed error handling with `KiraError` and `KiraErrorCode`, instead of opaque runtime failures
|
|
34
34
|
- 📦 Dual package: ESM and CommonJS builds, both with full type declarations, no extra config needed
|
|
35
|
+
- 📐 Selectable `size` (`compact`, `standard`, `wide`) for Level Up cards, rendered as vectors so every size stays sharp
|
|
35
36
|
|
|
36
37
|
## 📦 Installation
|
|
37
38
|
|
|
@@ -82,21 +83,21 @@ Every other card, the music adapters, theming, caching, error handling, and outp
|
|
|
82
83
|
|
|
83
84
|
## 🃏 Cards at a glance
|
|
84
85
|
|
|
85
|
-
| Card | Function | What it's for
|
|
86
|
-
| ------------ | ------------------------------------------------- |
|
|
87
|
-
| Profile | `profileImage(userId, options)` | Avatar, badges, nameplate, server tag, rank
|
|
88
|
-
| Welcome | `welcomeImage(userId, guildName, options)` | Member join events
|
|
89
|
-
| Leave | `leaveImage(userId, guildName, options)` | Member leave events
|
|
90
|
-
| Level Up | `levelUpImage(userId, level, options)` | XP progress bar on level-up
|
|
91
|
-
| Achievement | `achievementImage(userId, title, options)` | Unlockable achievements with rarity tiers
|
|
92
|
-
| Leaderboard | `leaderboardImage(entries, options)` | Server ranking table
|
|
93
|
-
| Ship | `shipImage(leftUserId, rightUserId, options)` | Compatibility between two users
|
|
94
|
-
| Now Playing | `nowPlayingImage(track, options)` | Music player card with source detection
|
|
95
|
-
| Giveaway | `giveawayImage(prize, options)` | Prize, host, entry count, winners on end
|
|
96
|
-
| Birthday | `birthdayImage(userId, options)` | Balloons, confetti, and an optional age/years counter
|
|
97
|
-
| Marriage | `marriageImage(leftUserId, rightUserId, options)` | Certificate-style card with automatic days-together count
|
|
98
|
-
| Weekly Recap | `weeklyRecapImage(userId, options)` | Wrapped-style weekly summary with a 7-day activity chart
|
|
99
|
-
| Code Snippet | `codeSnippetImage(code, options)` | Carbon-style syntax-highlighted code screenshot
|
|
86
|
+
| Card | Function | What it's for |
|
|
87
|
+
| ------------ | ------------------------------------------------- | ----------------------------------------------------------- |
|
|
88
|
+
| Profile | `profileImage(userId, options)` | Avatar, badges, nameplate, server tag, rank |
|
|
89
|
+
| Welcome | `welcomeImage(userId, guildName, options)` | Member join events |
|
|
90
|
+
| Leave | `leaveImage(userId, guildName, options)` | Member leave events |
|
|
91
|
+
| Level Up | `levelUpImage(userId, level, options)` | XP progress bar on level-up, in compact/standard/wide sizes |
|
|
92
|
+
| Achievement | `achievementImage(userId, title, options)` | Unlockable achievements with rarity tiers |
|
|
93
|
+
| Leaderboard | `leaderboardImage(entries, options)` | Server ranking table |
|
|
94
|
+
| Ship | `shipImage(leftUserId, rightUserId, options)` | Compatibility between two users |
|
|
95
|
+
| Now Playing | `nowPlayingImage(track, options)` | Music player card with source detection |
|
|
96
|
+
| Giveaway | `giveawayImage(prize, options)` | Prize, host, entry count, winners on end |
|
|
97
|
+
| Birthday | `birthdayImage(userId, options)` | Balloons, confetti, and an optional age/years counter |
|
|
98
|
+
| Marriage | `marriageImage(leftUserId, rightUserId, options)` | Certificate-style card with automatic days-together count |
|
|
99
|
+
| Weekly Recap | `weeklyRecapImage(userId, options)` | Wrapped-style weekly summary with a 7-day activity chart |
|
|
100
|
+
| Code Snippet | `codeSnippetImage(code, options)` | Carbon-style syntax-highlighted code screenshot |
|
|
100
101
|
|
|
101
102
|
## 🛠️ Utilities
|
|
102
103
|
|
package/dist/index.cjs
CHANGED
|
@@ -1779,12 +1779,12 @@ const BANNER_SIZE_SCALE = {
|
|
|
1779
1779
|
function normalizeFontScale(fontScale) {
|
|
1780
1780
|
return fontScale && fontScale > 0 ? fontScale : 1;
|
|
1781
1781
|
}
|
|
1782
|
-
function normalizeSize(size) {
|
|
1782
|
+
function normalizeSize$1(size) {
|
|
1783
1783
|
return size === "compact" || size === "wide" ? size : "standard";
|
|
1784
1784
|
}
|
|
1785
1785
|
function computeEffectiveFontScale(layout) {
|
|
1786
1786
|
const fontScale = normalizeFontScale(layout.fontScale);
|
|
1787
|
-
const size = normalizeSize(layout.size);
|
|
1787
|
+
const size = normalizeSize$1(layout.size);
|
|
1788
1788
|
return fontScale * (layout.layoutStyle === "banner" ? BANNER_SIZE_SCALE[size] : CENTERED_FONT_SCALE[size]);
|
|
1789
1789
|
}
|
|
1790
1790
|
function computeAvatarSize(fontScale) {
|
|
@@ -1802,7 +1802,7 @@ function computeBodyHeight(hasMessage, hasSecondaryMessage, hasMemberCount, hasD
|
|
|
1802
1802
|
}
|
|
1803
1803
|
function getCardDimensions$9(layout) {
|
|
1804
1804
|
if (layout.layoutStyle === "banner") {
|
|
1805
|
-
const preset = BANNER_DIMENSIONS[normalizeSize(layout.size)];
|
|
1805
|
+
const preset = BANNER_DIMENSIONS[normalizeSize$1(layout.size)];
|
|
1806
1806
|
return {
|
|
1807
1807
|
width: preset.width,
|
|
1808
1808
|
height: preset.height
|
|
@@ -1817,7 +1817,7 @@ function getCardDimensions$9(layout) {
|
|
|
1817
1817
|
const bodyHeight = computeBodyHeight(hasMessage, hasSecondaryMessage, hasMemberCount, hasDate, fontScale);
|
|
1818
1818
|
const height = Math.round(170 + avatarSize / 2 + bodyHeight);
|
|
1819
1819
|
return {
|
|
1820
|
-
width: CENTERED_WIDTH_PRESET[normalizeSize(layout.size)],
|
|
1820
|
+
width: CENTERED_WIDTH_PRESET[normalizeSize$1(layout.size)],
|
|
1821
1821
|
height
|
|
1822
1822
|
};
|
|
1823
1823
|
}
|
|
@@ -2574,12 +2574,27 @@ async function leaveImage(userId, guildName, options = {}) {
|
|
|
2574
2574
|
return renderMemberEventCard(userId, guildName, DEFAULT_LEAVE_MESSAGE, options, "leave");
|
|
2575
2575
|
}
|
|
2576
2576
|
|
|
2577
|
+
//#endregion
|
|
2578
|
+
//#region Src/Utils/LevelUpCard/constants.ts
|
|
2579
|
+
const LEVEL_UP_SIZE_SCALE = {
|
|
2580
|
+
compact: .8,
|
|
2581
|
+
standard: 1,
|
|
2582
|
+
wide: 1.2
|
|
2583
|
+
};
|
|
2584
|
+
|
|
2577
2585
|
//#endregion
|
|
2578
2586
|
//#region Src/Utils/LevelUpCard/dimensions.ts
|
|
2579
|
-
function
|
|
2587
|
+
function normalizeSize(size) {
|
|
2588
|
+
return size === "compact" || size === "wide" ? size : "standard";
|
|
2589
|
+
}
|
|
2590
|
+
function getSizeScale(size) {
|
|
2591
|
+
return LEVEL_UP_SIZE_SCALE[normalizeSize(size)];
|
|
2592
|
+
}
|
|
2593
|
+
function getCardDimensions$8(size) {
|
|
2594
|
+
const scale = getSizeScale(size);
|
|
2580
2595
|
return {
|
|
2581
|
-
width: 700,
|
|
2582
|
-
height: 260
|
|
2596
|
+
width: Math.round(700 * scale),
|
|
2597
|
+
height: Math.round(260 * scale)
|
|
2583
2598
|
};
|
|
2584
2599
|
}
|
|
2585
2600
|
function createLevelUpCanvas(width, height) {
|
|
@@ -2901,9 +2916,13 @@ async function drawLevelUpCard(ctx, width, height, layout) {
|
|
|
2901
2916
|
//#endregion
|
|
2902
2917
|
//#region Src/Utils/levelUpCard.output.utils.ts
|
|
2903
2918
|
async function genLevelUpPng(layout, output) {
|
|
2904
|
-
const { width, height } = getCardDimensions$8();
|
|
2919
|
+
const { width, height } = getCardDimensions$8(layout.size);
|
|
2920
|
+
const scale = getSizeScale(layout.size);
|
|
2905
2921
|
const { canvas, ctx } = createLevelUpCanvas(width, height);
|
|
2906
|
-
|
|
2922
|
+
ctx.save();
|
|
2923
|
+
ctx.scale(scale, scale);
|
|
2924
|
+
await drawLevelUpCard(ctx, 700, 260, layout);
|
|
2925
|
+
ctx.restore();
|
|
2907
2926
|
return encodeCanvas(canvas, output);
|
|
2908
2927
|
}
|
|
2909
2928
|
|
|
@@ -2934,6 +2953,7 @@ async function levelUpImage(userId, level, options = {}) {
|
|
|
2934
2953
|
const avatarFrameUrl = options.showAvatarDecoration !== false ? data.decoration.avatarFrame : null;
|
|
2935
2954
|
const badges = options.showBadges ? data.assets.badges : void 0;
|
|
2936
2955
|
const layout = {
|
|
2956
|
+
size: options.size ?? "standard",
|
|
2937
2957
|
username,
|
|
2938
2958
|
avatarUrl,
|
|
2939
2959
|
level,
|