UNPKG

@litecanvas/utils

Version:

Utilities to help build litecanvas games

97 lines (88 loc) 3.05 kB
(() => { var __defProp = Object.defineProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; // src/_global.js globalThis.utils = globalThis.utils || {}; globalThis.utils.global = (overrides = true) => { for (const key in globalThis.utils) { if ("global" === key) continue; if (overrides || globalThis[key] === void 0) { globalThis[key] = globalThis.utils[key]; } } }; // src/image/index.js var index_exports = {}; __export(index_exports, { flipImage: () => flip_default, makeCircle: () => make_circle_default, makeRectangle: () => make_rectangle_default, scaleImage: () => scale_default, tintImage: () => tint_default }); // src/image/flip.js var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => { return engine.paint(img.width, img.height, (ctx) => { engine.push(); engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1); engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img); engine.pop(); }); }; // src/image/scale.js var scale_default = (img, factor, pixelart = true, engine = globalThis) => { return engine.paint(img.width * factor, img.height * factor, (ctx) => { engine.push(); ctx.imageSmoothingEnabled = !pixelart; engine.scale(factor); engine.image(0, 0, img); engine.pop(); }); }; // src/image/tint.js var tint_default = (img, color, opacity = 1, engine = globalThis) => { return engine.paint(img.width, img.height, (ctx) => { engine.push(); engine.alpha(opacity); engine.rectfill(0, 0, img.width, img.height, color); ctx.globalCompositeOperation = "destination-atop"; engine.alpha(1); engine.image(0, 0, img); engine.pop(); }); }; // src/image/make-circle.js var make_circle_default = (radius, color, { borderWidth = 0, borderColor = 0, engine = globalThis } = {}) => { const imageSize = radius * 2 + borderWidth; return engine.paint(imageSize, imageSize, () => { engine.circfill(imageSize / 2, imageSize / 2, radius, color); if (borderWidth > 0) { engine.linewidth(borderWidth); engine.stroke(borderColor); } }); }; // src/image/make-rectangle.js var make_rectangle_default = (width, height, color, { borderWidth = 0, borderColor = 0, engine = globalThis } = {}) => { const imageWidth = width + borderWidth * 2; const imageHeight = height + borderWidth * 2; return engine.paint(imageWidth, imageHeight, () => { engine.rectfill( borderWidth > 0 ? borderWidth : 0, borderWidth > 0 ? borderWidth : 0, width, height, color ); if (borderWidth > 0) { engine.linewidth(borderWidth); engine.stroke(borderColor); } }); }; // src/image/_web.js globalThis.utils = Object.assign(globalThis.utils || {}, index_exports); })();