tsparticles
Version:
Easily create highly customizable particle animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
87 lines (86 loc) • 2.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Plugins = void 0;
const plugins = [];
const interactorsInitializers = new Map();
const updatersInitializers = new Map();
const interactors = new Map();
const updaters = new Map();
const presets = new Map();
const drawers = new Map();
const pathGenerators = new Map();
class Plugins {
static getPlugin(plugin) {
return plugins.find((t) => t.id === plugin);
}
static addPlugin(plugin) {
if (!Plugins.getPlugin(plugin.id)) {
plugins.push(plugin);
}
}
static getAvailablePlugins(container) {
const res = new Map();
for (const plugin of plugins) {
if (!plugin.needsPlugin(container.actualOptions)) {
continue;
}
res.set(plugin.id, plugin.getPlugin(container));
}
return res;
}
static loadOptions(options, sourceOptions) {
for (const plugin of plugins) {
plugin.loadOptions(options, sourceOptions);
}
}
static getPreset(preset) {
return presets.get(preset);
}
static addPreset(presetKey, options, override = false) {
if (override || !Plugins.getPreset(presetKey)) {
presets.set(presetKey, options);
}
}
static addShapeDrawer(type, drawer) {
if (!Plugins.getShapeDrawer(type)) {
drawers.set(type, drawer);
}
}
static getShapeDrawer(type) {
return drawers.get(type);
}
static getSupportedShapes() {
return drawers.keys();
}
static getPathGenerator(type) {
return pathGenerators.get(type);
}
static addPathGenerator(type, pathGenerator) {
if (!Plugins.getPathGenerator(type)) {
pathGenerators.set(type, pathGenerator);
}
}
static getInteractors(container) {
let res = interactors.get(container);
if (!res) {
res = [...interactorsInitializers.values()].map((t) => t(container));
interactors.set(container, res);
}
return res;
}
static addInteractor(name, initInteractor) {
interactorsInitializers.set(name, initInteractor);
}
static getUpdaters(container) {
let res = updaters.get(container);
if (!res) {
res = [...updatersInitializers.values()].map((t) => t(container));
updaters.set(container, res);
}
return res;
}
static addParticleUpdater(name, initUpdater) {
updatersInitializers.set(name, initUpdater);
}
}
exports.Plugins = Plugins;
;