@tsparticles/fireworks
Version:
tsParticles fireworks bundle — easily create spectacular fireworks and fountain particle effects with built-in presets. Ready to use components available for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
64 lines (63 loc) • 2.29 kB
JavaScript
import { isString, tsParticles } from "@tsparticles/engine";
import { getFireworksInstance } from "./utils.js";
import { loadBasic } from "@tsparticles/basic";
import { loadBlendPlugin } from "@tsparticles/plugin-blend";
import { loadDestroyUpdater } from "@tsparticles/updater-destroy";
import { loadEmittersPluginSimple } from "@tsparticles/plugin-emitters/plugin";
import { loadEmittersShapeSquare } from "@tsparticles/plugin-emitters-shape-square";
import { loadLifeUpdater } from "@tsparticles/updater-life";
import { loadLineShape } from "@tsparticles/shape-line";
import { loadPaintUpdater } from "@tsparticles/updater-paint";
import { loadRotateUpdater } from "@tsparticles/updater-rotate";
import { loadSoundsPlugin } from "@tsparticles/plugin-sounds";
let initPromise = null;
async function doInitPlugins(engine) {
engine.checkVersion("4.2.0");
await engine.pluginManager.register(async (e) => {
const loadEmittersForFireworks = async (e) => {
await loadEmittersPluginSimple(e);
await loadEmittersShapeSquare(e);
};
await Promise.all([
loadBasic(e),
loadLineShape(e),
loadBlendPlugin(e),
loadEmittersForFireworks(e),
loadSoundsPlugin(e),
loadRotateUpdater(e),
loadDestroyUpdater(e),
loadLifeUpdater(e),
loadPaintUpdater(e),
]);
});
}
async function initPlugins(engine) {
if (initPromise) {
return initPromise;
}
initPromise = doInitPlugins(engine);
return initPromise;
}
export async function fireworks(idOrOptions, sourceOptions) {
await initPlugins(tsParticles);
let id, options;
if (isString(idOrOptions)) {
id = idOrOptions;
options = sourceOptions ?? {};
}
else {
id = "fireworks";
options = idOrOptions ?? {};
}
return getFireworksInstance(tsParticles, id, options);
}
fireworks.create = async (canvas, options) => {
await initPlugins(tsParticles);
const id = canvas?.id ?? "fireworks";
return getFireworksInstance(tsParticles, id, options ?? {}, canvas ?? undefined);
};
fireworks.init = async () => {
await initPlugins(tsParticles);
};
fireworks.version = "4.2.0";
globalThis.fireworks = fireworks;