@tsparticles/confetti
Version:
tsParticles confetti bundle — easily create confetti, confetti cannon, confetti explosions, confetti falling, and confetti parade animations with presets. Ready to use components available for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact,
98 lines (97 loc) • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.confetti = confetti;
const engine_1 = require("@tsparticles/engine");
const basic_1 = require("@tsparticles/basic");
const suits_1 = require("@tsparticles/shape-cards/suits");
const plugin_1 = require("@tsparticles/plugin-emitters/plugin");
const shape_emoji_1 = require("@tsparticles/shape-emoji");
const shape_heart_1 = require("@tsparticles/shape-heart");
const shape_image_1 = require("@tsparticles/shape-image");
const updater_life_1 = require("@tsparticles/updater-life");
const plugin_motion_1 = require("@tsparticles/plugin-motion");
const shape_polygon_1 = require("@tsparticles/shape-polygon");
const updater_roll_1 = require("@tsparticles/updater-roll");
const updater_rotate_1 = require("@tsparticles/updater-rotate");
const shape_square_1 = require("@tsparticles/shape-square");
const shape_star_1 = require("@tsparticles/shape-star");
const updater_tilt_1 = require("@tsparticles/updater-tilt");
const updater_wobble_1 = require("@tsparticles/updater-wobble");
const utils_js_1 = require("./utils.js");
let initPromise = null;
async function doInitPlugins(engine) {
engine.checkVersion("4.6.0");
await engine.pluginManager.register(async (e) => {
await Promise.all([
(0, basic_1.loadBasic)(e),
(0, plugin_motion_1.loadMotionPlugin)(e),
(0, plugin_1.loadEmittersPluginSimple)(e),
(0, suits_1.loadCardSuitsShape)(e),
(0, shape_heart_1.loadHeartShape)(e),
(0, shape_image_1.loadImageShape)(e),
(0, shape_polygon_1.loadPolygonShape)(e),
(0, shape_square_1.loadSquareShape)(e),
(0, shape_star_1.loadStarShape)(e),
(0, shape_emoji_1.loadEmojiShape)(e),
(0, updater_rotate_1.loadRotateUpdater)(e),
(0, updater_life_1.loadLifeUpdater)(e),
(0, updater_roll_1.loadRollUpdater)(e),
(0, updater_tilt_1.loadTiltUpdater)(e),
(0, updater_wobble_1.loadWobbleUpdater)(e),
]);
});
}
async function initPlugins(engine) {
if (initPromise) {
return initPromise;
}
initPromise = doInitPlugins(engine);
return initPromise;
}
async function confetti(idOrOptions, confettiOptions) {
await initPlugins(engine_1.tsParticles);
let options, id;
if ((0, engine_1.isString)(idOrOptions)) {
id = idOrOptions;
options = confettiOptions ?? {};
}
else {
id = "confetti";
options = idOrOptions;
}
return (0, utils_js_1.setConfetti)(engine_1.tsParticles, {
id,
options,
});
}
confetti.create = async (canvas, options = {}) => {
await initPlugins(engine_1.tsParticles);
const id = canvas?.getAttribute("id") ?? "confetti";
canvas?.setAttribute("id", id);
await (0, utils_js_1.setConfetti)(engine_1.tsParticles, {
id,
canvas: canvas ?? undefined,
options,
});
return async (idOrOptions, confettiOptions) => {
let subOptions, subId;
if ((0, engine_1.isString)(idOrOptions)) {
subId = idOrOptions;
subOptions = confettiOptions ?? options;
}
else {
subId = id;
subOptions = idOrOptions;
}
return (0, utils_js_1.setConfetti)(engine_1.tsParticles, {
id: subId,
canvas: canvas ?? undefined,
options: subOptions,
});
};
};
confetti.init = async () => {
await initPlugins(engine_1.tsParticles);
};
confetti.version = "4.6.0";
globalThis.confetti = confetti;