UNPKG

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.

91 lines (90 loc) 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Infecter = void 0; class Infecter { constructor(container) { this.container = container; } startInfection(stage) { const options = this.container.actualOptions; const stages = options.infection.stages; const stagesCount = stages.length; if (stage > stagesCount || stage < 0) { return; } this.infectionDelay = 0; this.infectionDelayStage = stage; } updateInfectionStage(stage) { const options = this.container.actualOptions; const stagesCount = options.infection.stages.length; if (stage > stagesCount || stage < 0 || (this.infectionStage !== undefined && this.infectionStage > stage)) { return; } this.infectionStage = stage; this.infectionTime = 0; } updateInfection(delta) { const options = this.container.actualOptions; const infection = options.infection; const stages = options.infection.stages; const stagesCount = stages.length; if (this.infectionDelay !== undefined && this.infectionDelayStage !== undefined) { const stage = this.infectionDelayStage; if (stage > stagesCount || stage < 0) { return; } if (this.infectionDelay > infection.delay * 1000) { this.infectionStage = stage; this.infectionTime = 0; delete this.infectionDelay; delete this.infectionDelayStage; } else { this.infectionDelay += delta; } } else { delete this.infectionDelay; delete this.infectionDelayStage; } if (this.infectionStage !== undefined && this.infectionTime !== undefined) { const infectionStage = stages[this.infectionStage]; if (infectionStage.duration !== undefined && infectionStage.duration >= 0) { if (this.infectionTime > infectionStage.duration * 1000) { this.nextInfectionStage(); } else { this.infectionTime += delta; } } else { this.infectionTime += delta; } } else { delete this.infectionStage; delete this.infectionTime; } } nextInfectionStage() { const options = this.container.actualOptions; const stagesCount = options.infection.stages.length; if (stagesCount <= 0 || this.infectionStage === undefined) { return; } this.infectionTime = 0; if (stagesCount <= ++this.infectionStage) { if (options.infection.cure) { delete this.infectionStage; delete this.infectionTime; return; } else { this.infectionStage = 0; this.infectionTime = 0; } } } } exports.Infecter = Infecter;