@tsparticles/particles
Version:
Minimal tsParticles particles bundle — lightweight particle engine without confetti or fireworks extras. Perfect for pure particle backgrounds. Ready to use components available for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, In
165 lines (157 loc) • 9.66 kB
JavaScript
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
/* tsParticles v4.2.1 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/engine'), require('@tsparticles/basic'), require('@tsparticles/plugin-interactivity'), require('@tsparticles/interaction-particles-collisions'), require('@tsparticles/interaction-particles-links')) :
typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/engine', '@tsparticles/basic', '@tsparticles/plugin-interactivity', '@tsparticles/interaction-particles-collisions', '@tsparticles/interaction-particles-links'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.bundles = global.__tsParticlesInternals.bundles || {}, global.__tsParticlesInternals.bundles.particles = global.__tsParticlesInternals.bundles.particles || {}), global.__tsParticlesInternals.engine, global.__tsParticlesInternals.bundles.basic, global.__tsParticlesInternals.plugins.interactivity, global.__tsParticlesInternals.interactions.particlesCollisions, global.__tsParticlesInternals.interactions.particlesLinks));
})(this, (function (exports, engine, basic, pluginInteractivity, interactionParticlesCollisions, interactionParticlesLinks) { 'use strict';
const instances = new Map();
function deleteParticlesInstance(id) {
instances.delete(id);
}
const defaultCount = 80, defaultLinksWidth = 100, defaultSpeed = 3, defaultOpacity = 1, defaultRadius = 3;
function getDefaultOptions(options, canvas) {
return {
fullScreen: {
enable: !canvas,
},
particles: {
number: {
value: options.count ?? defaultCount,
},
color: {
value: options.color ?? "#fff",
},
links: {
enable: options.links ?? false,
color: options.linksColor ?? "#fff",
distance: options.linksLength ?? defaultLinksWidth,
},
collisions: {
enable: options.collisions ?? false,
},
move: {
enable: true,
speed: options.speed ?? defaultSpeed,
},
opacity: {
value: options.opacity ?? defaultOpacity,
},
shape: {
type: options.shape ?? "circle",
},
size: {
value: options.radius ?? defaultRadius,
},
},
};
}
async function getParticlesInstance(engine, id, sourceOptions, canvas) {
const existing = instances.get(id);
if (existing instanceof Promise) {
return existing;
}
if (existing) {
if (!existing.destroyed) {
return existing;
}
instances.delete(id);
}
const create = async () => {
const particlesOptions = getDefaultOptions(sourceOptions, canvas), container = await engine.load({ id, element: canvas, options: particlesOptions });
if (!container) {
instances.delete(id);
return;
}
const { ParticlesInstance } = await Promise.resolve().then(function () { return ParticlesInstance$1; }), instance = new ParticlesInstance(container, id);
instances.set(id, instance);
return instance;
}, createPromise = create();
instances.set(id, createPromise);
return createPromise;
}
let initPromise = null;
async function doInitPlugins(engine) {
engine.checkVersion("4.2.1");
await engine.pluginManager.register(async (e) => {
const loadParticlesInteractivity = async (e) => {
await pluginInteractivity.loadInteractivityPlugin(e);
await Promise.all([
interactionParticlesCollisions.loadParticlesCollisionsInteraction(e),
interactionParticlesLinks.loadParticlesLinksInteraction(e),
]);
};
await Promise.all([
basic.loadBasic(e),
loadParticlesInteractivity(e),
]);
});
}
async function initPlugins(engine) {
if (initPromise) {
return initPromise;
}
initPromise = doInitPlugins(engine);
return initPromise;
}
async function particles(idOrOptions, sourceOptions) {
await initPlugins(engine.tsParticles);
let id, options;
if (engine.isString(idOrOptions)) {
id = idOrOptions;
options = sourceOptions ?? {};
}
else {
id = "particles";
options = idOrOptions ?? {};
}
return getParticlesInstance(engine.tsParticles, id, options);
}
particles.create = async (canvas, options) => {
await initPlugins(engine.tsParticles);
const id = canvas?.id ?? "particles";
return getParticlesInstance(engine.tsParticles, id, options ?? {}, canvas ?? undefined);
};
particles.init = async () => {
await initPlugins(engine.tsParticles);
};
particles.version = "4.2.1";
globalThis.particles = particles;
const globalObject = globalThis;
globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
globalObject.particles = particles;
class ParticlesInstance {
#container;
#id;
constructor(container, id) {
this.#container = container;
this.#id = id;
}
get destroyed() {
return this.#container.destroyed;
}
destroy() {
this.#container.destroy();
deleteParticlesInstance(this.#id);
}
pause() {
this.#container.pause();
}
play() {
this.#container.play();
}
stop() {
this.#container.stop();
}
}
var ParticlesInstance$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
ParticlesInstance: ParticlesInstance
});
exports.particles = particles;
}));
globalThis.__tsParticlesInternals = globalThis.__tsParticlesInternals || {};
if (!globalThis.__tsParticlesInternals.engine || !globalThis.__tsParticlesInternals.engine.tsParticles) {
globalThis.__tsParticlesInternals.engine = globalThis.__tsParticlesInternals.bundles.particles || {};
}
delete (globalThis.window || globalThis).tsparticlesInternalExports;