@tsparticles/engine
Version:
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 React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
65 lines (64 loc) • 2.24 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InteractionManager = void 0;
const InteractorType_js_1 = require("../../Enums/Types/InteractorType.js");
class InteractionManager {
constructor(engine, container) {
this.container = container;
this._engine = engine;
this._interactors = [];
this._externalInteractors = [];
this._particleInteractors = [];
}
externalInteract(delta) {
for (const interactor of this._externalInteractors) {
if (interactor.isEnabled()) {
interactor.interact(delta);
}
}
}
handleClickMode(mode) {
for (const interactor of this._externalInteractors) {
interactor.handleClickMode?.(mode);
}
}
async init() {
this._interactors = await this._engine.getInteractors(this.container, true);
this._externalInteractors = [];
this._particleInteractors = [];
for (const interactor of this._interactors) {
switch (interactor.type) {
case InteractorType_js_1.InteractorType.external:
this._externalInteractors.push(interactor);
break;
case InteractorType_js_1.InteractorType.particles:
this._particleInteractors.push(interactor);
break;
}
interactor.init();
}
}
particlesInteract(particle, delta) {
for (const interactor of this._externalInteractors) {
interactor.clear(particle, delta);
}
for (const interactor of this._particleInteractors) {
if (interactor.isEnabled(particle)) {
interactor.interact(particle, delta);
}
}
}
reset(particle) {
for (const interactor of this._externalInteractors) {
if (interactor.isEnabled()) {
interactor.reset(particle);
}
}
for (const interactor of this._particleInteractors) {
if (interactor.isEnabled(particle)) {
interactor.reset(particle);
}
}
}
}
exports.InteractionManager = InteractionManager;