kira-arts 1.2.5 → 1.3.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 +13 -187
- package/README.npm.md +58 -0
- package/dist/index.cjs +492 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +491 -11
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A TypeScript library for generating Discord-style visual cards — profiles, welcome/leave events, level-ups, achievements, leaderboards, compatibility "ship" cards, and now-playing music cards — all powered by `@napi-rs/canvas`.
|
|
4
4
|
|
|
5
|
+
**📚 Full documentation, live examples, and a Playground: [documentation](https://kira-arts.chocofactory.dev/)**
|
|
6
|
+
|
|
5
7
|
[](https://www.npmjs.com/package/kira-arts)
|
|
6
8
|
[](https://www.npmjs.com/package/kira-arts)
|
|
7
9
|
[](https://packagephobia.com/result?p=kira-arts)
|
|
@@ -21,26 +23,17 @@ A TypeScript library for generating Discord-style visual cards — profiles, wel
|
|
|
21
23
|
|
|
22
24
|
## ✨ Features
|
|
23
25
|
|
|
24
|
-
- 🖼️
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
- 🏅 **Leaderboard Card** — ranking table with up to 15 entries.
|
|
29
|
-
- 💘 **Ship Card** — compatibility card between two users.
|
|
30
|
-
- 🎵 **Now Playing Card** — music player card with progress bar, source badge (YouTube, Spotify, SoundCloud, Twitch, Deezer, Apple Music, etc.), and live-stream support. Ships with adapters for moonlink.js, Lavalink-based clients, discord-player, and distube.
|
|
31
|
-
- 🎨 **Built-in themes**: `discord`, `midnight`, `sunset`, `neon`, `forest`, `sakura`, `monochrome`, `gold`.
|
|
32
|
-
- 🗃️ Configurable internal cache for user data.
|
|
33
|
-
- 🧾 Output as `png`, `jpeg`, or `webp`, ready to use as a discord.js `AttachmentBuilder`.
|
|
26
|
+
- 🖼️ Profile, Welcome/Leave, Level Up, Achievement, Leaderboard, Ship (compatibility), and Now Playing cards
|
|
27
|
+
- 🎵 Now Playing card ships with adapters for moonlink.js, Lavalink-based clients, discord-player, and distube
|
|
28
|
+
- 🎨 8 built-in themes, Nitro/role-color aware borders
|
|
29
|
+
- 🧾 Output as `png`, `jpeg`, or `webp`, ready to use as a discord.js `AttachmentBuilder`
|
|
34
30
|
|
|
35
31
|
## 📦 Installation
|
|
36
32
|
|
|
37
|
-
```
|
|
33
|
+
```bash
|
|
38
34
|
npm install kira-arts
|
|
39
|
-
|
|
40
|
-
pnpm add kira-arts
|
|
41
|
-
|
|
42
35
|
yarn add kira-arts
|
|
43
|
-
|
|
36
|
+
pnpm add kira-arts
|
|
44
37
|
bun add kira-arts
|
|
45
38
|
```
|
|
46
39
|
|
|
@@ -48,11 +41,9 @@ bun add kira-arts
|
|
|
48
41
|
|
|
49
42
|
## 🚀 Quick usage
|
|
50
43
|
|
|
51
|
-
Register your discord.js client **once** at startup:
|
|
52
|
-
|
|
53
44
|
```ts
|
|
54
45
|
import { Client, GatewayIntentBits } from "discord.js";
|
|
55
|
-
import { setClient } from "kira-arts";
|
|
46
|
+
import { setClient, profileImage, toAttachment } from "kira-arts";
|
|
56
47
|
|
|
57
48
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
58
49
|
|
|
@@ -61,178 +52,12 @@ client.once("ready", () => {
|
|
|
61
52
|
});
|
|
62
53
|
|
|
63
54
|
client.login(process.env.TOKEN);
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Profile card
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import { profileImage, toAttachment } from "kira-arts";
|
|
70
|
-
|
|
71
|
-
const buffer = await profileImage(userId, {
|
|
72
|
-
guildId: interaction.guildId!,
|
|
73
|
-
useRoleColor: true,
|
|
74
|
-
theme: "discord",
|
|
75
|
-
presenceStatus: "online",
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const attachment = toAttachment(buffer, "profile", "png");
|
|
79
|
-
await interaction.reply({ files: [attachment] });
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Welcome / leave
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
import { welcomeImage, leaveImage } from "kira-arts";
|
|
86
|
-
|
|
87
|
-
const buffer = await welcomeImage(userId, guild.name, {
|
|
88
|
-
memberCount: guild.memberCount,
|
|
89
|
-
theme: "sunset",
|
|
90
|
-
});
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Level up
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
import { levelUpImage } from "kira-arts";
|
|
97
|
-
|
|
98
|
-
const buffer = await levelUpImage(userId, 12, {
|
|
99
|
-
currentXp: 450,
|
|
100
|
-
requiredXp: 1000,
|
|
101
|
-
theme: "neon",
|
|
102
|
-
});
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Achievement
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
import { achievementImage } from "kira-arts";
|
|
109
|
-
|
|
110
|
-
const buffer = await achievementImage(userId, "First victory!", {
|
|
111
|
-
description: "Win your first ranked match.",
|
|
112
|
-
rarity: "epic",
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Leaderboard
|
|
117
|
-
|
|
118
|
-
```ts
|
|
119
|
-
import { leaderboardImage } from "kira-arts";
|
|
120
|
-
|
|
121
|
-
const buffer = await leaderboardImage(
|
|
122
|
-
[
|
|
123
|
-
{ userId: "111", currentXp: 900, requiredXp: 1000, level: 20 },
|
|
124
|
-
{ userId: "222", currentXp: 300, requiredXp: 800, level: 14 },
|
|
125
|
-
],
|
|
126
|
-
{ title: "Server Top", theme: "gold", maxEntries: 10 },
|
|
127
|
-
);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Ship (compatibility)
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
import { shipImage } from "kira-arts";
|
|
134
55
|
|
|
135
|
-
const buffer = await
|
|
136
|
-
|
|
137
|
-
showText: true,
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Now playing
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
import { nowPlayingImage } from "kira-arts";
|
|
145
|
-
|
|
146
|
-
const buffer = await nowPlayingImage(
|
|
147
|
-
{
|
|
148
|
-
title: "Blinding Lights",
|
|
149
|
-
author: "The Weeknd",
|
|
150
|
-
artworkUrl: track.artworkUrl,
|
|
151
|
-
duration: 200_040,
|
|
152
|
-
sourceName: "spotify",
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
position: 45_000,
|
|
156
|
-
requesterId: interaction.user.id,
|
|
157
|
-
guildId: interaction.guildId!,
|
|
158
|
-
theme: "midnight",
|
|
159
|
-
},
|
|
160
|
-
);
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
For a livestream / radio, omit `duration` (or set it to `0`) and set `isStream: true` — the card shows a `LIVE` badge and a full progress bar instead of a position.
|
|
164
|
-
|
|
165
|
-
#### Music library adapters
|
|
166
|
-
|
|
167
|
-
You don't have to build the `track` object by hand. If you're using a supported player library, convert its track object directly:
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
import { nowPlayingImage, fromMoonlinkTrack, fromLavalinkTrack, fromDiscordPlayerTrack, fromDistubeTrack, extractRequesterId } from "kira-arts";
|
|
171
|
-
|
|
172
|
-
// moonlink.js
|
|
173
|
-
const buffer = await nowPlayingImage(fromMoonlinkTrack(player.current), {
|
|
174
|
-
requesterId: extractRequesterId(player.current),
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Lavalink-based clients (erela.js, Shoukaku, Kazagumo, Riffy, Magmastream, lavalink-client)
|
|
178
|
-
const buffer = await nowPlayingImage(fromLavalinkTrack(track));
|
|
179
|
-
|
|
180
|
-
// discord-player
|
|
181
|
-
const buffer = await nowPlayingImage(fromDiscordPlayerTrack(queue.currentTrack));
|
|
182
|
-
|
|
183
|
-
// distube
|
|
184
|
-
const buffer = await nowPlayingImage(fromDistubeTrack(queue.songs[0]));
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
Each adapter is a plain duck-typed converter — kira-arts doesn't depend on any of these libraries, so any object with a matching shape works, including one you build yourself from a raw API response.
|
|
188
|
-
|
|
189
|
-
## 🎨 Available themes
|
|
190
|
-
|
|
191
|
-
```
|
|
192
|
-
discord | midnight | sunset | neon | forest | sakura | monochrome | gold
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
Pass it as `theme` in any card's options, or use `getThemePalette(theme)` to get the raw palette.
|
|
196
|
-
|
|
197
|
-
## 🗃️ Cache
|
|
198
|
-
|
|
199
|
-
```ts
|
|
200
|
-
import { setCacheOptions, clearCache, getCacheSize } from "kira-arts";
|
|
201
|
-
|
|
202
|
-
setCacheOptions({ ttl: 60_000 }); // example, adjust to your actual options
|
|
203
|
-
clearCache();
|
|
204
|
-
console.log(getCacheSize());
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
## ⚠️ Error handling
|
|
208
|
-
|
|
209
|
-
Every function throws a `KiraError` with a typed `code` (`KiraErrorCode`):
|
|
210
|
-
|
|
211
|
-
```ts
|
|
212
|
-
import { KiraError, KiraErrorCode } from "kira-arts";
|
|
213
|
-
|
|
214
|
-
try {
|
|
215
|
-
await profileImage(userId);
|
|
216
|
-
} catch (err) {
|
|
217
|
-
if (err instanceof KiraError && err.code === KiraErrorCode.Validation) {
|
|
218
|
-
// handle validation error
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
Available codes: `Validation`, `Fetch`, `AssetLoad`, `Render`, `Config`.
|
|
224
|
-
|
|
225
|
-
## 📤 Output format
|
|
226
|
-
|
|
227
|
-
Every image-generating function returns a `Buffer`. Control format/quality with `output`:
|
|
228
|
-
|
|
229
|
-
```ts
|
|
230
|
-
await profileImage(userId, {
|
|
231
|
-
output: { format: "webp", quality: 90 },
|
|
232
|
-
});
|
|
56
|
+
const buffer = await profileImage(userId, { guildId, useRoleColor: true, theme: "discord" });
|
|
57
|
+
await interaction.reply({ files: [toAttachment(buffer, "profile", "png")] });
|
|
233
58
|
```
|
|
234
59
|
|
|
235
|
-
|
|
60
|
+
Every other card, the music adapters, theming, caching, error handling, and output options are documented with live examples at **[documentation](https://kira-arts.chocofactory.dev/)**.
|
|
236
61
|
|
|
237
62
|
## 📄 License
|
|
238
63
|
|
|
@@ -240,5 +65,6 @@ Apache-2.0 © [worddevs](https://github.com/worddevs)
|
|
|
240
65
|
|
|
241
66
|
## 🔗 Links
|
|
242
67
|
|
|
68
|
+
- Documentation: https://kira-arts.chocofactory.dev/
|
|
243
69
|
- Repository: https://github.com/worddevs/kira-arts
|
|
244
70
|
- Issues: https://github.com/worddevs/kira-arts/issues
|
package/README.npm.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# kira-arts 💞
|
|
2
|
+
|
|
3
|
+
A TypeScript library for generating Discord-style visual cards — profiles, welcome/leave events, level-ups, achievements, leaderboards, compatibility "ship" cards, and now-playing music cards — all powered by `@napi-rs/canvas`.
|
|
4
|
+
|
|
5
|
+
**📚 Full documentation, live examples, and a Playground: [documentation](https://kira-arts.chocofactory.dev/)**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/kira-arts)
|
|
8
|
+
[](https://github.com/worddevs/kira-arts/blob/main/LICENSE)
|
|
9
|
+
[](https://www.npmjs.com/package/kira-arts)
|
|
10
|
+
[](https://github.com/worddevs/kira-arts)
|
|
11
|
+
|
|
12
|
+
## ✨ Features
|
|
13
|
+
|
|
14
|
+
- 🖼️ Profile, Welcome/Leave, Level Up, Achievement, Leaderboard, Ship (compatibility), and Now Playing cards
|
|
15
|
+
- 🎵 Now Playing card ships with adapters for moonlink.js, Lavalink-based clients, discord-player, and distube
|
|
16
|
+
- 🎨 8 built-in themes, Nitro/role-color aware borders
|
|
17
|
+
- 🧾 Output as `png`, `jpeg`, or `webp`, ready to use as a discord.js `AttachmentBuilder`
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install kira-arts
|
|
23
|
+
yarn add kira-arts
|
|
24
|
+
pnpm add kira-arts
|
|
25
|
+
bun add kira-arts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> Requires Node.js >= 20 and a project with `discord.js` ^14.27.0 already installed (peer dependency).
|
|
29
|
+
|
|
30
|
+
## 🚀 Quick usage
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Client, GatewayIntentBits } from "discord.js";
|
|
34
|
+
import { setClient, profileImage, toAttachment } from "kira-arts";
|
|
35
|
+
|
|
36
|
+
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
37
|
+
|
|
38
|
+
client.once("ready", () => {
|
|
39
|
+
setClient(client); // 👈 required before generating any card
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
client.login(process.env.TOKEN);
|
|
43
|
+
|
|
44
|
+
const buffer = await profileImage(userId, { guildId, useRoleColor: true, theme: "discord" });
|
|
45
|
+
await interaction.reply({ files: [toAttachment(buffer, "profile", "png")] });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Every other card, the music adapters, theming, caching, error handling, and output options are documented with live examples at **[kira-arts.chocofactory.dev](https://kira-arts.chocofactory.dev/)**.
|
|
49
|
+
|
|
50
|
+
## 📄 License
|
|
51
|
+
|
|
52
|
+
Apache-2.0 © [worddevs](https://github.com/worddevs)
|
|
53
|
+
|
|
54
|
+
## 🔗 Links
|
|
55
|
+
|
|
56
|
+
- Documentation: https://kira-arts.chocofactory.dev/
|
|
57
|
+
- Repository: https://github.com/worddevs/kira-arts
|
|
58
|
+
- Issues: https://github.com/worddevs/kira-arts/issues
|