kira-arts 1.4.1 → 1.4.2
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 +2 -0
- package/dist/index.cjs +9 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +9 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
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, now-playing music cards, and giveaways — rendered natively for speed and zero runtime dependencies on a browser or headless Chromium.
|
|
4
4
|
|
|
5
|
+
<img src="https://i.imgur.com/AMk4jWr.png" alt="Kira Arts" width="100%">
|
|
6
|
+
|
|
5
7
|
**📚 Full documentation, live examples, and a Playground: [documentation](https://guide.worddevs.dev/docs/kira-arts)**
|
|
6
8
|
|
|
7
9
|
[](https://www.npmjs.com/package/kira-arts)
|
package/dist/index.cjs
CHANGED
|
@@ -2405,7 +2405,7 @@ async function resolveStaticImage(bytes, fallbackUrl) {
|
|
|
2405
2405
|
}
|
|
2406
2406
|
return (0, _napi_rs_canvas.loadImage)(fallbackUrl).catch(() => void 0);
|
|
2407
2407
|
}
|
|
2408
|
-
async function renderAnimatedMemberEvent(avatarUrl, username, layout, width, height) {
|
|
2408
|
+
async function renderAnimatedMemberEvent(avatarUrl, username, layout, width, height, output) {
|
|
2409
2409
|
const avatarSource = await fetchImageSource(avatarUrl).catch(() => null);
|
|
2410
2410
|
const animatedAvatar = avatarSource?.animated ?? null;
|
|
2411
2411
|
const avatarImage = animatedAvatar ? void 0 : await resolveStaticImage(avatarSource?.bytes, avatarUrl);
|
|
@@ -2414,7 +2414,7 @@ async function renderAnimatedMemberEvent(avatarUrl, username, layout, width, hei
|
|
|
2414
2414
|
const staticBackgroundImage = !animatedBackground && layout.customBackground ? await resolveStaticImage(backgroundSource?.bytes, layout.customBackground) : void 0;
|
|
2415
2415
|
const wantsConfetti = layout.confetti === true;
|
|
2416
2416
|
const frameCount = resolveGifFrameCount(layout.gifSeconds);
|
|
2417
|
-
if (!animatedBackground && !animatedAvatar && !wantsConfetti) return
|
|
2417
|
+
if (!animatedBackground && !animatedAvatar && !wantsConfetti) return renderStaticMemberEventImage(avatarUrl, username, layout, width, height, avatarImage, staticBackgroundImage, output);
|
|
2418
2418
|
const particles = wantsConfetti ? generateConfetti(width, height, layout.accentColor) : [];
|
|
2419
2419
|
const frames = [];
|
|
2420
2420
|
if (animatedBackground || animatedAvatar) {
|
|
@@ -2461,7 +2461,7 @@ async function renderAnimatedMemberEvent(avatarUrl, username, layout, width, hei
|
|
|
2461
2461
|
}
|
|
2462
2462
|
return encodeGif(frames, GIF_FRAME_DELAY_MS);
|
|
2463
2463
|
}
|
|
2464
|
-
async function
|
|
2464
|
+
async function renderStaticMemberEventImage(avatarUrl, username, layout, width, height, avatarImage, backgroundImage, output) {
|
|
2465
2465
|
const canvas = (0, _napi_rs_canvas.createCanvas)(width, height);
|
|
2466
2466
|
const ctx = canvas.getContext("2d");
|
|
2467
2467
|
fillOpaqueBase(ctx, width, height);
|
|
@@ -2470,16 +2470,11 @@ async function renderStaticMemberEventGif(avatarUrl, username, layout, width, he
|
|
|
2470
2470
|
backgroundImage
|
|
2471
2471
|
});
|
|
2472
2472
|
await applyWatermarkToCanvas(canvas);
|
|
2473
|
-
|
|
2474
|
-
return encodeGif([{
|
|
2475
|
-
data: imageData.data,
|
|
2476
|
-
width,
|
|
2477
|
-
height
|
|
2478
|
-
}], GIF_FRAME_DELAY_MS);
|
|
2473
|
+
return encodeCanvas(canvas, output);
|
|
2479
2474
|
}
|
|
2480
2475
|
async function genMemberEventPng(avatarUrl, username, layout, output) {
|
|
2481
2476
|
const { width, height } = getCardDimensions$5(layout);
|
|
2482
|
-
if (layout.animated) return renderAnimatedMemberEvent(avatarUrl, username, layout, width, height);
|
|
2477
|
+
if (layout.animated) return renderAnimatedMemberEvent(avatarUrl, username, layout, width, height, output);
|
|
2483
2478
|
const { canvas, ctx } = createMemberEventCanvas(width, height);
|
|
2484
2479
|
await drawMemberEventCard(ctx, width, height, avatarUrl, username, layout);
|
|
2485
2480
|
return encodeCanvas(canvas, output);
|
|
@@ -2492,12 +2487,12 @@ function formatMessage(template, username, guildName, memberCount) {
|
|
|
2492
2487
|
return template.replace(/\{username\}/g, username).replace(/\{user\}/g, username).replace(/\{server\}/g, guildName).replace(/\{memberCount\}/g, memberCount != null ? String(memberCount) : "");
|
|
2493
2488
|
}
|
|
2494
2489
|
function formatMemberCount(memberCount, localDateType) {
|
|
2495
|
-
return localDateType.startsWith("es") ? `
|
|
2490
|
+
return localDateType.startsWith("es") ? `Miembro #${memberCount}` : `Member #${memberCount}`;
|
|
2496
2491
|
}
|
|
2497
2492
|
function formatKindLabel(kind, localDateType) {
|
|
2498
2493
|
const isEs = localDateType.startsWith("es");
|
|
2499
|
-
if (kind === "welcome") return isEs ? "
|
|
2500
|
-
return isEs ? "
|
|
2494
|
+
if (kind === "welcome") return isEs ? "NUEVO MIEMBRO" : "NEW MEMBER";
|
|
2495
|
+
return isEs ? "MIEMBRO SALIÓ" : "MEMBER LEFT";
|
|
2501
2496
|
}
|
|
2502
2497
|
async function renderMemberEventCard(userId, guildName, defaultMessage, options = {}, kind = "welcome") {
|
|
2503
2498
|
if (!userId || typeof userId !== "string") throw new KiraError("A valid userId is required", "VALIDATION");
|
|
@@ -2516,7 +2511,7 @@ async function renderMemberEventCard(userId, guildName, defaultMessage, options
|
|
|
2516
2511
|
roleColor: data.decoration.roleColor,
|
|
2517
2512
|
fallback: palette?.borderColor ?? [accentColor]
|
|
2518
2513
|
});
|
|
2519
|
-
const localDateType = options.localDateType ?? "
|
|
2514
|
+
const localDateType = options.localDateType ?? "en";
|
|
2520
2515
|
const rawMessage = options.message === "" ? void 0 : options.message ?? defaultMessage;
|
|
2521
2516
|
const message = rawMessage ? normalizeDisplayText(formatMessage(rawMessage, username, normalizeDisplayText(guildName), options.memberCount)) : void 0;
|
|
2522
2517
|
const secondaryMessage = options.secondaryMessage ? normalizeDisplayText(formatMessage(options.secondaryMessage, username, normalizeDisplayText(guildName), options.memberCount)) : void 0;
|