UNPKG

@tsparticles/vue3

Version:

Official tsParticles Vue.js 3.x Component - Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for Web Components, React, Vue.js 2.x,

40 lines (39 loc) 1.12 kB
import { defineComponent as l, onMounted as p, nextTick as u, onUnmounted as m, openBlock as f, createElementBlock as v } from "vue"; import { tsParticles as o } from "@tsparticles/engine"; const _ = ["id"], w = /* @__PURE__ */ l({ __name: "vue-particles", props: { id: {}, options: {}, url: {} }, emits: ["particlesLoaded"], setup(r, { emit: e }) { let t, i; const n = r, c = e; addEventListener("particlesInit", (s) => { i = s.detail, a(); }); const a = async () => { i || (i = o), t = await i.load({ id: n.id, url: n.url, options: n.options }), c("particlesLoaded", t); }; return p(() => { u(() => { if (!n.id) throw new Error("Prop 'id' is required!"); a(); }); }), m(() => { t && (t.destroy(), t = void 0); }), (s, d) => (f(), v("div", { id: s.id }, null, 8, _)); } }), P = (r, e) => { r.component("vue-particles", w), (async () => (o.init(), e.init && await e.init(o), dispatchEvent(new CustomEvent("particlesInit", { detail: o }))))(); }; export { P as default };