UNPKG

@discord-card/core

Version:
52 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.roundRect = roundRect; exports.changeFont = changeFont; exports.changeFontSize = changeFontSize; exports.blur = blur; function roundRect(ctx, x, y, w, h, r) { if (w < 2 * r) r = w / 2; if (h < 2 * r) r = h / 2; ctx.beginPath(); ctx.moveTo(x + r, y); ctx.arcTo(x + w, y, x + w, y + h, r); ctx.arcTo(x + w, y + h, x, y + h, r); ctx.arcTo(x, y + h, x, y, r); ctx.arcTo(x, y, x + w, y, r); ctx.closePath(); return ctx; } function changeFont(ctx, font) { var _a; const fontArgs = ctx.font.split(' '); let size = (_a = fontArgs[0]) !== null && _a !== void 0 ? _a : '15px'; ctx.font = `${size} ${font}, SegoeUI, SegoeUIEmoji`; /// using the first part return ctx; } function changeFontSize(ctx, size) { const fontArgs = ctx.font.split(' '); ctx.font = `${size} ${fontArgs.slice(1).join(' ')}`; /// using the last part return ctx; } function blur(canvas, strength = 1) { let ctx = canvas.getContext('2d'); ctx.globalAlpha = 0.5; // Higher alpha made it more smooth // Add blur layers by strength to x and y // 2 made it a bit faster without noticeable quality loss for (var y = -strength; y <= strength; y += 2) { for (var x = -strength; x <= strength; x += 2) { // Apply layers ctx.drawImage(canvas, x, y); // Add an extra layer, prevents it from rendering lines // on top of the images (does makes it slower though) if (x >= 0 && y >= 0) { ctx.drawImage(canvas, -(x - 1), -(y - 1)); } } } ctx.globalAlpha = 1.0; return canvas; } //# sourceMappingURL=lib.js.map