UNPKG

@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.

65 lines (64 loc) 2.45 kB
import { isString, tsParticles } from "@tsparticles/engine/lazy"; import { getFireworksInstance } from "./utils.js"; let initPromise = null; async function doInitPlugins(engine) { engine.checkVersion("4.2.0"); await engine.pluginManager.register(async (e) => { const [{ loadBasic }, { loadLineShape }, { loadBlendPlugin }, { loadEmittersPluginSimple }, { loadEmittersShapeSquare }, { loadSoundsPlugin }, { loadRotateUpdater }, { loadDestroyUpdater }, { loadLifeUpdater }, { loadPaintUpdater },] = await Promise.all([ import("@tsparticles/basic/lazy"), import("@tsparticles/shape-line"), import("@tsparticles/plugin-blend"), import("@tsparticles/plugin-emitters/plugin"), import("@tsparticles/plugin-emitters-shape-square"), import("@tsparticles/plugin-sounds"), import("@tsparticles/updater-rotate/lazy"), import("@tsparticles/updater-destroy/lazy"), import("@tsparticles/updater-life/lazy"), import("@tsparticles/updater-paint/lazy"), ]), 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;