Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tsparticles/plugin-emitters

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsparticles/plugin-emitters - npm Package Compare versions

Comparing version 3.0.0-alpha.1 to 3.0.0-beta.0

210

browser/EmitterInstance.js

@@ -1,2 +0,2 @@

import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
import { Emitter } from "./Options/Classes/Emitter";

@@ -6,6 +6,73 @@ import { EmitterSize } from "./Options/Classes/EmitterSize";

constructor(engine, emitters, container, options, position) {
var _a, _b, _c, _d, _e, _f, _g;
var _h;
this.emitters = emitters;
this.container = container;
this._calcPosition = () => {
return calcPositionOrRandomFromSizeRanged({
size: this.container.canvas.size,
position: this.options.position,
});
};
this._destroy = () => {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
};
this._emit = () => {
if (this._paused) {
return;
}
const quantity = getRangeValue(this.options.rate.quantity);
this._emitParticles(quantity);
};
this._emitParticles = (quantity) => {
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = deepExtend({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = this.options.spawnColor?.animation;
if (hslAnimation) {
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
};
this._prepareToDie = () => {
if (this._paused) {
return;
}
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
};
this._setColorAnimation = (animation, initValue, maxValue) => {
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue(animation.speed ?? 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
};
this._engine = engine;

@@ -23,6 +90,6 @@ this._currentDuration = 0;

}
this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
this._spawnDelay = (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._initialPosition ?? this._calcPosition();
this.name = this.options.name;
this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
this.fill = this.options.fill;

@@ -32,5 +99,5 @@ this._firstSpawn = !this.options.life.wait;

let particlesOptions = deepExtend({}, this.options.particles);
particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
(_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
(_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
particlesOptions ??= {};
particlesOptions.move ??= {};
particlesOptions.move.direction ??= this.options.direction;
if (this.options.spawnColor) {

@@ -42,12 +109,13 @@ this.spawnColor = rangeColorToHsl(this.options.spawnColor);

this.size =
(_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
const size = new EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
this.options.size ??
(() => {
const size = new EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = this.options.life.count ?? -1;
this._immortal = this._lifeCount <= 0;

@@ -95,10 +163,3 @@ this._engine.dispatchEvent("emitterCreated", {

}
return {
width: this.size.mode === "percent"
? (container.canvas.size.width * this.size.width) / 100
: this.size.width,
height: this.size.mode === "percent"
? (container.canvas.size.height * this.size.height) / 100
: this.size.height,
};
return getSize(this.size, container.canvas.size);
}

@@ -112,3 +173,2 @@ pause() {

play() {
var _a;
if (this._paused) {

@@ -119,3 +179,3 @@ return;

(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
(this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
return;

@@ -128,3 +188,3 @@ }

if (this._lifeCount > 0 || this._immortal) {
this.prepareToDie();
this._prepareToDie();
}

@@ -137,6 +197,5 @@ }

? initialPosition
: this.calcPosition();
: this._calcPosition();
}
update(delta) {
var _a, _b, _c;
if (this._paused) {

@@ -147,8 +206,8 @@ return;

this._firstSpawn = false;
this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
this._currentSpawnDelay = this._spawnDelay ?? 0;
this._currentEmitDelay = this._emitDelay ?? 0;
}
if (!this._startParticlesAdded) {
this._startParticlesAdded = true;
this.emitParticles(this.options.startCount);
this._emitParticles(this.options.startCount);
}

@@ -166,7 +225,8 @@ if (this._duration !== undefined) {

if (this._lifeCount > 0 || this._immortal) {
this.position = this.calcPosition();
this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._calcPosition();
this._spawnDelay =
(getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
}
else {
this.destroy();
this._destroy();
}

@@ -191,3 +251,3 @@ this._currentDuration -= this._duration;

if (this._currentEmitDelay >= this._emitDelay) {
this.emit();
this._emit();
this._currentEmitDelay -= this._emitDelay;

@@ -197,74 +257,2 @@ }

}
calcPosition() {
return calcPositionOrRandomFromSizeRanged({
size: this.container.canvas.size,
position: this.options.position,
});
}
destroy() {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
}
emit() {
if (this._paused) {
return;
}
const quantity = getRangeValue(this.options.rate.quantity);
this.emitParticles(quantity);
}
emitParticles(quantity) {
var _a, _b, _c;
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = deepExtend({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
if (hslAnimation) {
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
}
prepareToDie() {
var _a;
if (this._paused) {
return;
}
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
}
setColorAnimation(animation, initValue, maxValue) {
var _a;
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
}
}

@@ -1,2 +0,2 @@

import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine";
import { Emitter } from "./Options/Classes/Emitter";

@@ -17,3 +17,3 @@ import { EmitterInstance } from "./EmitterInstance";

};
container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
container.getEmitter = (idxOrName) => idxOrName === undefined || isNumber(idxOrName)
? this.array[idxOrName || 0]

@@ -50,30 +50,31 @@ : this.array.find((t) => t.name === idxOrName);

const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
if (mode === "emitter") {
let emittersModeOptions;
if (modeEmitters && modeEmitters.value instanceof Array) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = arrayRandomIndex(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
if (mode !== "emitter") {
return;
}
let emittersModeOptions;
if (modeEmitters && isArray(modeEmitters.value)) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = arrayRandomIndex(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
}
else {
emittersModeOptions = modeEmitters.value;
}
}
else {
emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
emittersModeOptions = modeEmitters.value;
}
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
executeOnSingleOrMultiple(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}
else {
emittersModeOptions = modeEmitters?.value;
}
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
executeOnSingleOrMultiple(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}

@@ -83,3 +84,6 @@ async init() {

this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
if (this.emitters instanceof Array) {
if (!this.emitters) {
return;
}
if (isArray(this.emitters)) {
for (const emitterOptions of this.emitters) {

@@ -86,0 +90,0 @@ this.addEmitter(emitterOptions);

@@ -1,2 +0,2 @@

import { executeOnSingleOrMultiple, isInArray } from "@tsparticles/engine";
import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
import { CircleShape } from "./Shapes/Circle/CircleShape";

@@ -16,7 +16,6 @@ import { Emitter } from "./Options/Classes/Emitter";

loadOptions(options, source) {
var _a, _b, _c, _d, _e, _f;
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
return;
}
if (source === null || source === void 0 ? void 0 : source.emitters) {
if (source?.emitters) {
options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {

@@ -28,5 +27,5 @@ const tmp = new Emitter();

}
const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
const interactivityEmitters = source?.interactivity?.modes?.emitters;
if (interactivityEmitters) {
if (interactivityEmitters instanceof Array) {
if (isArray(interactivityEmitters)) {
options.interactivity.modes.emitters = {

@@ -47,7 +46,7 @@ random: {

if (emitterMode.value !== undefined) {
if (emitterMode.value instanceof Array) {
if (isArray(emitterMode.value)) {
options.interactivity.modes.emitters = {
random: {
count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -66,4 +65,4 @@ value: emitterMode.value.map((s) => {

random: {
count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -88,3 +87,2 @@ value: tmp,

needsPlugin(options) {
var _a, _b, _c;
if (!options) {

@@ -94,9 +92,9 @@ return false;

const emitters = options.emitters;
return ((emitters instanceof Array && !!emitters.length) ||
return ((isArray(emitters) && !!emitters.length) ||
emitters !== undefined ||
(!!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
(!!options.interactivity?.events?.onClick?.mode &&
isInArray("emitter", options.interactivity.events.onClick.mode)));
}
}
export async function loadEmittersPlugin(engine) {
export async function loadEmittersPlugin(engine, refresh = true) {
if (!engine.emitterShapeManager) {

@@ -107,8 +105,7 @@ engine.emitterShapeManager = new ShapeManager(engine);

engine.addEmitterShape = (name, shape) => {
var _a;
(_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
engine.emitterShapeManager?.addShape(name, shape);
};
}
const plugin = new EmittersPlugin(engine);
await engine.addPlugin(plugin);
await engine.addPlugin(plugin, refresh);
engine.addEmitterShape("circle", new CircleShape());

@@ -115,0 +112,0 @@ engine.addEmitterShape("square", new SquareShape());

@@ -1,2 +0,2 @@

import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue, } from "@tsparticles/engine";
import { EmitterLife } from "./EmitterLife";

@@ -15,3 +15,3 @@ import { EmitterRate } from "./EmitterRate";

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -23,3 +23,3 @@ }

if (data.size !== undefined) {
if (this.size === undefined) {
if (!this.size) {
this.size = new EmitterSize();

@@ -26,0 +26,0 @@ }

@@ -0,1 +1,2 @@

import { setRangeValue } from "@tsparticles/engine";
export class EmitterLife {

@@ -6,3 +7,3 @@ constructor() {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -14,6 +15,6 @@ }

if (data.delay !== undefined) {
this.delay = data.delay;
this.delay = setRangeValue(data.delay);
}
if (data.duration !== undefined) {
this.duration = data.duration;
this.duration = setRangeValue(data.duration);
}

@@ -20,0 +21,0 @@ if (data.wait !== undefined) {

@@ -9,6 +9,73 @@ "use strict";

constructor(engine, emitters, container, options, position) {
var _a, _b, _c, _d, _e, _f, _g;
var _h;
this.emitters = emitters;
this.container = container;
this._calcPosition = () => {
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
size: this.container.canvas.size,
position: this.options.position,
});
};
this._destroy = () => {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
};
this._emit = () => {
if (this._paused) {
return;
}
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
this._emitParticles(quantity);
};
this._emitParticles = (quantity) => {
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = this.options.spawnColor?.animation;
if (hslAnimation) {
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
};
this._prepareToDie = () => {
if (this._paused) {
return;
}
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
};
this._setColorAnimation = (animation, initValue, maxValue) => {
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
};
this._engine = engine;

@@ -26,6 +93,6 @@ this._currentDuration = 0;

}
this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._initialPosition ?? this._calcPosition();
this.name = this.options.name;
this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
this.fill = this.options.fill;

@@ -35,5 +102,5 @@ this._firstSpawn = !this.options.life.wait;

let particlesOptions = (0, engine_1.deepExtend)({}, this.options.particles);
particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
(_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
(_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
particlesOptions ??= {};
particlesOptions.move ??= {};
particlesOptions.move.direction ??= this.options.direction;
if (this.options.spawnColor) {

@@ -45,12 +112,13 @@ this.spawnColor = (0, engine_1.rangeColorToHsl)(this.options.spawnColor);

this.size =
(_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
const size = new EmitterSize_1.EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
this.options.size ??
(() => {
const size = new EmitterSize_1.EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = this.options.life.count ?? -1;
this._immortal = this._lifeCount <= 0;

@@ -98,10 +166,3 @@ this._engine.dispatchEvent("emitterCreated", {

}
return {
width: this.size.mode === "percent"
? (container.canvas.size.width * this.size.width) / 100
: this.size.width,
height: this.size.mode === "percent"
? (container.canvas.size.height * this.size.height) / 100
: this.size.height,
};
return (0, engine_1.getSize)(this.size, container.canvas.size);
}

@@ -115,3 +176,2 @@ pause() {

play() {
var _a;
if (this._paused) {

@@ -122,3 +182,3 @@ return;

(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
(this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
return;

@@ -131,3 +191,3 @@ }

if (this._lifeCount > 0 || this._immortal) {
this.prepareToDie();
this._prepareToDie();
}

@@ -140,6 +200,5 @@ }

? initialPosition
: this.calcPosition();
: this._calcPosition();
}
update(delta) {
var _a, _b, _c;
if (this._paused) {

@@ -150,8 +209,8 @@ return;

this._firstSpawn = false;
this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
this._currentSpawnDelay = this._spawnDelay ?? 0;
this._currentEmitDelay = this._emitDelay ?? 0;
}
if (!this._startParticlesAdded) {
this._startParticlesAdded = true;
this.emitParticles(this.options.startCount);
this._emitParticles(this.options.startCount);
}

@@ -169,7 +228,8 @@ if (this._duration !== undefined) {

if (this._lifeCount > 0 || this._immortal) {
this.position = this.calcPosition();
this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._calcPosition();
this._spawnDelay =
((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
}
else {
this.destroy();
this._destroy();
}

@@ -194,3 +254,3 @@ this._currentDuration -= this._duration;

if (this._currentEmitDelay >= this._emitDelay) {
this.emit();
this._emit();
this._currentEmitDelay -= this._emitDelay;

@@ -200,75 +260,3 @@ }

}
calcPosition() {
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
size: this.container.canvas.size,
position: this.options.position,
});
}
destroy() {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
}
emit() {
if (this._paused) {
return;
}
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
this.emitParticles(quantity);
}
emitParticles(quantity) {
var _a, _b, _c;
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
if (hslAnimation) {
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
}
prepareToDie() {
var _a;
if (this._paused) {
return;
}
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
}
setColorAnimation(animation, initValue, maxValue) {
var _a;
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = (0, engine_1.getRangeValue)((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
}
}
exports.EmitterInstance = EmitterInstance;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -29,3 +20,3 @@ exports.Emitters = void 0;

};
container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
? this.array[idxOrName || 0]

@@ -62,44 +53,46 @@ : this.array.find((t) => t.name === idxOrName);

const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
if (mode === "emitter") {
let emittersModeOptions;
if (modeEmitters && modeEmitters.value instanceof Array) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
if (mode !== "emitter") {
return;
}
let emittersModeOptions;
if (modeEmitters && (0, engine_1.isArray)(modeEmitters.value)) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
}
else {
emittersModeOptions = modeEmitters.value;
}
}
else {
emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
emittersModeOptions = modeEmitters.value;
}
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}
else {
emittersModeOptions = modeEmitters?.value;
}
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}
init() {
return __awaiter(this, void 0, void 0, function* () {
this.emitters = this.container.actualOptions.emitters;
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
if (this.emitters instanceof Array) {
for (const emitterOptions of this.emitters) {
this.addEmitter(emitterOptions);
}
async init() {
this.emitters = this.container.actualOptions.emitters;
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
if (!this.emitters) {
return;
}
if ((0, engine_1.isArray)(this.emitters)) {
for (const emitterOptions of this.emitters) {
this.addEmitter(emitterOptions);
}
else {
this.addEmitter(this.emitters);
}
});
}
else {
this.addEmitter(this.emitters);
}
}

@@ -106,0 +99,0 @@ pause() {

@@ -16,11 +16,2 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -43,7 +34,6 @@ exports.loadEmittersPlugin = void 0;

loadOptions(options, source) {
var _a, _b, _c, _d, _e, _f;
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
return;
}
if (source === null || source === void 0 ? void 0 : source.emitters) {
if (source?.emitters) {
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {

@@ -55,5 +45,5 @@ const tmp = new Emitter_1.Emitter();

}
const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
const interactivityEmitters = source?.interactivity?.modes?.emitters;
if (interactivityEmitters) {
if (interactivityEmitters instanceof Array) {
if ((0, engine_1.isArray)(interactivityEmitters)) {
options.interactivity.modes.emitters = {

@@ -74,7 +64,7 @@ random: {

if (emitterMode.value !== undefined) {
if (emitterMode.value instanceof Array) {
if ((0, engine_1.isArray)(emitterMode.value)) {
options.interactivity.modes.emitters = {
random: {
count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -93,4 +83,4 @@ value: emitterMode.value.map((s) => {

random: {
count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -115,3 +105,2 @@ value: tmp,

needsPlugin(options) {
var _a, _b, _c;
if (!options) {

@@ -121,24 +110,21 @@ return false;

const emitters = options.emitters;
return ((emitters instanceof Array && !!emitters.length) ||
return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
emitters !== undefined ||
(!!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
(!!options.interactivity?.events?.onClick?.mode &&
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
}
}
function loadEmittersPlugin(engine) {
return __awaiter(this, void 0, void 0, function* () {
if (!engine.emitterShapeManager) {
engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);
}
if (!engine.addEmitterShape) {
engine.addEmitterShape = (name, shape) => {
var _a;
(_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
};
}
const plugin = new EmittersPlugin(engine);
yield engine.addPlugin(plugin);
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
engine.addEmitterShape("square", new SquareShape_1.SquareShape());
});
async function loadEmittersPlugin(engine, refresh = true) {
if (!engine.emitterShapeManager) {
engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);
}
if (!engine.addEmitterShape) {
engine.addEmitterShape = (name, shape) => {
engine.emitterShapeManager?.addShape(name, shape);
};
}
const plugin = new EmittersPlugin(engine);
await engine.addPlugin(plugin, refresh);
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
engine.addEmitterShape("square", new SquareShape_1.SquareShape());
}

@@ -145,0 +131,0 @@ exports.loadEmittersPlugin = loadEmittersPlugin;

@@ -18,3 +18,3 @@ "use strict";

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -26,3 +26,3 @@ }

if (data.size !== undefined) {
if (this.size === undefined) {
if (!this.size) {
this.size = new EmitterSize_1.EmitterSize();

@@ -29,0 +29,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmitterLife = void 0;
const engine_1 = require("@tsparticles/engine");
class EmitterLife {

@@ -9,3 +10,3 @@ constructor() {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -17,6 +18,6 @@ }

if (data.delay !== undefined) {
this.delay = data.delay;
this.delay = (0, engine_1.setRangeValue)(data.delay);
}
if (data.duration !== undefined) {
this.duration = data.duration;
this.duration = (0, engine_1.setRangeValue)(data.duration);
}

@@ -23,0 +24,0 @@ if (data.wait !== undefined) {

@@ -21,3 +21,3 @@ "use strict";

}
}, radius = (x, y, theta) => (x * y) / Math.sqrt(Math.pow((y * Math.cos(theta)), 2) + Math.pow((x * Math.sin(theta)), 2)), [a, b] = [size.width / 2, size.height / 2], randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt((0, engine_1.getRandom)()) : maxRadius;
}, radius = (x, y, theta) => (x * y) / Math.sqrt((y * Math.cos(theta)) ** 2 + (x * Math.sin(theta)) ** 2), [a, b] = [size.width / 2, size.height / 2], randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt((0, engine_1.getRandom)()) : maxRadius;
return {

@@ -24,0 +24,0 @@ x: position.x + randomRadius * Math.cos(randomTheta),

@@ -1,2 +0,2 @@

import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
import { Emitter } from "./Options/Classes/Emitter";

@@ -6,6 +6,73 @@ import { EmitterSize } from "./Options/Classes/EmitterSize";

constructor(engine, emitters, container, options, position) {
var _a, _b, _c, _d, _e, _f, _g;
var _h;
this.emitters = emitters;
this.container = container;
this._calcPosition = () => {
return calcPositionOrRandomFromSizeRanged({
size: this.container.canvas.size,
position: this.options.position,
});
};
this._destroy = () => {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
};
this._emit = () => {
if (this._paused) {
return;
}
const quantity = getRangeValue(this.options.rate.quantity);
this._emitParticles(quantity);
};
this._emitParticles = (quantity) => {
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = deepExtend({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = this.options.spawnColor?.animation;
if (hslAnimation) {
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
};
this._prepareToDie = () => {
if (this._paused) {
return;
}
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
};
this._setColorAnimation = (animation, initValue, maxValue) => {
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue(animation.speed ?? 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
};
this._engine = engine;

@@ -23,6 +90,6 @@ this._currentDuration = 0;

}
this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
this._spawnDelay = (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._initialPosition ?? this._calcPosition();
this.name = this.options.name;
this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
this.fill = this.options.fill;

@@ -32,5 +99,5 @@ this._firstSpawn = !this.options.life.wait;

let particlesOptions = deepExtend({}, this.options.particles);
particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
(_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
(_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
particlesOptions ??= {};
particlesOptions.move ??= {};
particlesOptions.move.direction ??= this.options.direction;
if (this.options.spawnColor) {

@@ -42,12 +109,13 @@ this.spawnColor = rangeColorToHsl(this.options.spawnColor);

this.size =
(_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
const size = new EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
this.options.size ??
(() => {
const size = new EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = this.options.life.count ?? -1;
this._immortal = this._lifeCount <= 0;

@@ -95,10 +163,3 @@ this._engine.dispatchEvent("emitterCreated", {

}
return {
width: this.size.mode === "percent"
? (container.canvas.size.width * this.size.width) / 100
: this.size.width,
height: this.size.mode === "percent"
? (container.canvas.size.height * this.size.height) / 100
: this.size.height,
};
return getSize(this.size, container.canvas.size);
}

@@ -112,3 +173,2 @@ pause() {

play() {
var _a;
if (this._paused) {

@@ -119,3 +179,3 @@ return;

(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
(this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
return;

@@ -128,3 +188,3 @@ }

if (this._lifeCount > 0 || this._immortal) {
this.prepareToDie();
this._prepareToDie();
}

@@ -137,6 +197,5 @@ }

? initialPosition
: this.calcPosition();
: this._calcPosition();
}
update(delta) {
var _a, _b, _c;
if (this._paused) {

@@ -147,8 +206,8 @@ return;

this._firstSpawn = false;
this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
this._currentSpawnDelay = this._spawnDelay ?? 0;
this._currentEmitDelay = this._emitDelay ?? 0;
}
if (!this._startParticlesAdded) {
this._startParticlesAdded = true;
this.emitParticles(this.options.startCount);
this._emitParticles(this.options.startCount);
}

@@ -166,7 +225,8 @@ if (this._duration !== undefined) {

if (this._lifeCount > 0 || this._immortal) {
this.position = this.calcPosition();
this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._calcPosition();
this._spawnDelay =
(getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
}
else {
this.destroy();
this._destroy();
}

@@ -191,3 +251,3 @@ this._currentDuration -= this._duration;

if (this._currentEmitDelay >= this._emitDelay) {
this.emit();
this._emit();
this._currentEmitDelay -= this._emitDelay;

@@ -197,74 +257,2 @@ }

}
calcPosition() {
return calcPositionOrRandomFromSizeRanged({
size: this.container.canvas.size,
position: this.options.position,
});
}
destroy() {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
}
emit() {
if (this._paused) {
return;
}
const quantity = getRangeValue(this.options.rate.quantity);
this.emitParticles(quantity);
}
emitParticles(quantity) {
var _a, _b, _c;
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = deepExtend({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
if (hslAnimation) {
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
}
prepareToDie() {
var _a;
if (this._paused) {
return;
}
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
}
setColorAnimation(animation, initValue, maxValue) {
var _a;
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
}
}

@@ -1,2 +0,2 @@

import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine";
import { Emitter } from "./Options/Classes/Emitter";

@@ -17,3 +17,3 @@ import { EmitterInstance } from "./EmitterInstance";

};
container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
container.getEmitter = (idxOrName) => idxOrName === undefined || isNumber(idxOrName)
? this.array[idxOrName || 0]

@@ -50,30 +50,31 @@ : this.array.find((t) => t.name === idxOrName);

const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
if (mode === "emitter") {
let emittersModeOptions;
if (modeEmitters && modeEmitters.value instanceof Array) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = arrayRandomIndex(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
if (mode !== "emitter") {
return;
}
let emittersModeOptions;
if (modeEmitters && isArray(modeEmitters.value)) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = arrayRandomIndex(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
}
else {
emittersModeOptions = modeEmitters.value;
}
}
else {
emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
emittersModeOptions = modeEmitters.value;
}
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
executeOnSingleOrMultiple(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}
else {
emittersModeOptions = modeEmitters?.value;
}
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
executeOnSingleOrMultiple(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}

@@ -83,3 +84,6 @@ async init() {

this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
if (this.emitters instanceof Array) {
if (!this.emitters) {
return;
}
if (isArray(this.emitters)) {
for (const emitterOptions of this.emitters) {

@@ -86,0 +90,0 @@ this.addEmitter(emitterOptions);

@@ -1,2 +0,2 @@

import { executeOnSingleOrMultiple, isInArray } from "@tsparticles/engine";
import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
import { CircleShape } from "./Shapes/Circle/CircleShape";

@@ -16,7 +16,6 @@ import { Emitter } from "./Options/Classes/Emitter";

loadOptions(options, source) {
var _a, _b, _c, _d, _e, _f;
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
return;
}
if (source === null || source === void 0 ? void 0 : source.emitters) {
if (source?.emitters) {
options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {

@@ -28,5 +27,5 @@ const tmp = new Emitter();

}
const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
const interactivityEmitters = source?.interactivity?.modes?.emitters;
if (interactivityEmitters) {
if (interactivityEmitters instanceof Array) {
if (isArray(interactivityEmitters)) {
options.interactivity.modes.emitters = {

@@ -47,7 +46,7 @@ random: {

if (emitterMode.value !== undefined) {
if (emitterMode.value instanceof Array) {
if (isArray(emitterMode.value)) {
options.interactivity.modes.emitters = {
random: {
count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -66,4 +65,4 @@ value: emitterMode.value.map((s) => {

random: {
count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -88,3 +87,2 @@ value: tmp,

needsPlugin(options) {
var _a, _b, _c;
if (!options) {

@@ -94,9 +92,9 @@ return false;

const emitters = options.emitters;
return ((emitters instanceof Array && !!emitters.length) ||
return ((isArray(emitters) && !!emitters.length) ||
emitters !== undefined ||
(!!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
(!!options.interactivity?.events?.onClick?.mode &&
isInArray("emitter", options.interactivity.events.onClick.mode)));
}
}
export async function loadEmittersPlugin(engine) {
export async function loadEmittersPlugin(engine, refresh = true) {
if (!engine.emitterShapeManager) {

@@ -107,8 +105,7 @@ engine.emitterShapeManager = new ShapeManager(engine);

engine.addEmitterShape = (name, shape) => {
var _a;
(_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
engine.emitterShapeManager?.addShape(name, shape);
};
}
const plugin = new EmittersPlugin(engine);
await engine.addPlugin(plugin);
await engine.addPlugin(plugin, refresh);
engine.addEmitterShape("circle", new CircleShape());

@@ -115,0 +112,0 @@ engine.addEmitterShape("square", new SquareShape());

@@ -1,2 +0,2 @@

import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue, } from "@tsparticles/engine";
import { EmitterLife } from "./EmitterLife";

@@ -15,3 +15,3 @@ import { EmitterRate } from "./EmitterRate";

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -23,3 +23,3 @@ }

if (data.size !== undefined) {
if (this.size === undefined) {
if (!this.size) {
this.size = new EmitterSize();

@@ -26,0 +26,0 @@ }

@@ -0,1 +1,2 @@

import { setRangeValue } from "@tsparticles/engine";
export class EmitterLife {

@@ -6,3 +7,3 @@ constructor() {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -14,6 +15,6 @@ }

if (data.delay !== undefined) {
this.delay = data.delay;
this.delay = setRangeValue(data.delay);
}
if (data.duration !== undefined) {
this.duration = data.duration;
this.duration = setRangeValue(data.duration);
}

@@ -20,0 +21,0 @@ if (data.wait !== undefined) {

{
"name": "@tsparticles/plugin-emitters",
"version": "3.0.0-alpha.1",
"version": "3.0.0-beta.0",
"description": "tsParticles emitters plugin",

@@ -75,8 +75,9 @@ "homepage": "https://particles.js.org",

"types": "types/index.d.ts",
"sideEffects": false,
"dependencies": {
"@tsparticles/engine": "^3.0.0-beta.0"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@tsparticles/engine": "^3.0.0-alpha.1"
}
}
}

@@ -5,5 +5,5 @@ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)

[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-plugin-emitters/badge)](https://www.jsdelivr.com/package/npm/tsparticles-plugin-emitters)
[![npmjs](https://badge.fury.io/js/tsparticles-plugin-emitters.svg)](https://www.npmjs.com/package/tsparticles-plugin-emitters)
[![npmjs](https://img.shields.io/npm/dt/tsparticles-plugin-emitters)](https://www.npmjs.com/package/tsparticles-plugin-emitters) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-emitters/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-emitters)
[![npmjs](https://badge.fury.io/js/@tsparticles/plugin-emitters.svg)](https://www.npmjs.com/package/@tsparticles/plugin-emitters)
[![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-emitters)](https://www.npmjs.com/package/@tsparticles/plugin-emitters) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)

@@ -46,3 +46,3 @@ [tsParticles](https://github.com/matteobruni/tsparticles) plugin for particles emitters.

```shell
$ npm install tsparticles-plugin-emitters
$ npm install @tsparticles/plugin-emitters
```

@@ -53,3 +53,3 @@

```shell
$ yarn add tsparticles-plugin-emitters
$ yarn add @tsparticles/plugin-emitters
```

@@ -60,6 +60,8 @@

```javascript
const { tsParticles } = require("tsparticles-engine");
const { loadEmittersPlugin } = require("tsparticles-plugin-emitters");
const { tsParticles } = require("@tsparticles/engine");
const { loadEmittersPlugin } = require("@tsparticles/plugin-emitters");
loadEmittersPlugin(tsParticles);
(async () => {
await loadEmittersPlugin(tsParticles);
})();
```

@@ -70,6 +72,8 @@

```javascript
import { tsParticles } from "tsparticles-engine";
import { loadEmittersPlugin } from "tsparticles-plugin-emitters";
import { tsParticles } from "@tsparticles/engine";
import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
loadEmittersPlugin(tsParticles);
(async () => {
await loadEmittersPlugin(tsParticles);
})();
```

@@ -7,3 +7,3 @@ /*!

* How to use? : Check the GitHub README
* v3.0.0-alpha.1
* v3.0.0-beta.0
*/

@@ -95,3 +95,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

__webpack_require__.d(__webpack_exports__, {
"loadEmittersPlugin": () => (/* binding */ loadEmittersPlugin)
loadEmittersPlugin: () => (/* binding */ loadEmittersPlugin)
});

@@ -131,2 +131,3 @@

;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterLife.js
class EmitterLife {

@@ -137,3 +138,3 @@ constructor() {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -145,6 +146,6 @@ }

if (data.delay !== undefined) {
this.delay = data.delay;
this.delay = (0,engine_root_window_.setRangeValue)(data.delay);
}
if (data.duration !== undefined) {
this.duration = data.duration;
this.duration = (0,engine_root_window_.setRangeValue)(data.duration);
}

@@ -212,3 +213,3 @@ if (data.wait !== undefined) {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -220,3 +221,3 @@ }

if (data.size !== undefined) {
if (this.size === undefined) {
if (!this.size) {
this.size = new EmitterSize();

@@ -268,6 +269,74 @@ }

constructor(engine, emitters, container, options, position) {
var _a, _b, _c, _d, _e, _f, _g;
var _h;
this.emitters = emitters;
this.container = container;
this._calcPosition = () => {
return (0,engine_root_window_.calcPositionOrRandomFromSizeRanged)({
size: this.container.canvas.size,
position: this.options.position
});
};
this._destroy = () => {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this
}
});
};
this._emit = () => {
if (this._paused) {
return;
}
const quantity = (0,engine_root_window_.getRangeValue)(this.options.rate.quantity);
this._emitParticles(quantity);
};
this._emitParticles = quantity => {
const position = this.getPosition(),
size = this.getSize(),
singleParticlesOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = (0,engine_root_window_.deepExtend)({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = this.options.spawnColor?.animation;
if (hslAnimation) {
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor
};
} else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
};
this._prepareToDie = () => {
if (this._paused) {
return;
}
const duration = this.options.life?.duration !== undefined ? (0,engine_root_window_.getRangeValue)(this.options.life.duration) : undefined;
if (this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal) && duration !== undefined && duration > 0) {
this._duration = duration * 1000;
}
};
this._setColorAnimation = (animation, initValue, maxValue) => {
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = (0,engine_root_window_.randomInRange)(animation.offset),
delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay),
emitFactor = 1000 * delay / container.retina.reduceFactor,
colorSpeed = (0,engine_root_window_.getRangeValue)(animation.speed ?? 0);
return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * 3.6) % maxValue;
};
this._engine = engine;

@@ -284,6 +353,6 @@ this._currentDuration = 0;

}
this._spawnDelay = ((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000 / this.container.retina.reduceFactor;
this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor;
this.position = this._initialPosition ?? this._calcPosition();
this.name = this.options.name;
this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
this.fill = this.options.fill;

@@ -293,5 +362,5 @@ this._firstSpawn = !this.options.life.wait;

let particlesOptions = (0,engine_root_window_.deepExtend)({}, this.options.particles);
particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : particlesOptions = {};
(_d = particlesOptions.move) !== null && _d !== void 0 ? _d : particlesOptions.move = {};
(_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : _h.direction = this.options.direction;
particlesOptions ??= {};
particlesOptions.move ??= {};
particlesOptions.move.direction ??= this.options.direction;
if (this.options.spawnColor) {

@@ -302,3 +371,3 @@ this.spawnColor = (0,engine_root_window_.rangeColorToHsl)(this.options.spawnColor);

this._particlesOptions = particlesOptions;
this.size = (_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
this.size = this.options.size ?? (() => {
const size = new EmitterSize();

@@ -312,3 +381,3 @@ size.load({

})();
this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
this._lifeCount = this.options.life.count ?? -1;
this._immortal = this._lifeCount <= 0;

@@ -357,6 +426,3 @@ this._engine.dispatchEvent("emitterCreated", {

}
return {
width: this.size.mode === "percent" ? container.canvas.size.width * this.size.width / 100 : this.size.width,
height: this.size.mode === "percent" ? container.canvas.size.height * this.size.height / 100 : this.size.height
};
return (0,engine_root_window_.getSize)(this.size, container.canvas.size);
}

@@ -370,7 +436,6 @@ pause() {

play() {
var _a;
if (this._paused) {
return;
}
if (!(this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
if (!(this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
return;

@@ -383,3 +448,3 @@ }

if (this._lifeCount > 0 || this._immortal) {
this.prepareToDie();
this._prepareToDie();
}

@@ -389,6 +454,5 @@ }

const initialPosition = this._initialPosition;
this.position = initialPosition && (0,engine_root_window_.isPointInside)(initialPosition, this.container.canvas.size, engine_root_window_.Vector.origin) ? initialPosition : this.calcPosition();
this.position = initialPosition && (0,engine_root_window_.isPointInside)(initialPosition, this.container.canvas.size, engine_root_window_.Vector.origin) ? initialPosition : this._calcPosition();
}
update(delta) {
var _a, _b, _c;
if (this._paused) {

@@ -399,8 +463,8 @@ return;

this._firstSpawn = false;
this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
this._currentSpawnDelay = this._spawnDelay ?? 0;
this._currentEmitDelay = this._emitDelay ?? 0;
}
if (!this._startParticlesAdded) {
this._startParticlesAdded = true;
this.emitParticles(this.options.startCount);
this._emitParticles(this.options.startCount);
}

@@ -418,6 +482,6 @@ if (this._duration !== undefined) {

if (this._lifeCount > 0 || this._immortal) {
this.position = this.calcPosition();
this._spawnDelay = ((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000 / this.container.retina.reduceFactor;
this.position = this._calcPosition();
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor;
} else {
this.destroy();
this._destroy();
}

@@ -442,3 +506,3 @@ this._currentDuration -= this._duration;

if (this._currentEmitDelay >= this._emitDelay) {
this.emit();
this._emit();
this._currentEmitDelay -= this._emitDelay;

@@ -448,75 +512,2 @@ }

}
calcPosition() {
return (0,engine_root_window_.calcPositionOrRandomFromSizeRanged)({
size: this.container.canvas.size,
position: this.options.position
});
}
destroy() {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this
}
});
}
emit() {
if (this._paused) {
return;
}
const quantity = (0,engine_root_window_.getRangeValue)(this.options.rate.quantity);
this.emitParticles(quantity);
}
emitParticles(quantity) {
var _a, _b, _c;
const position = this.getPosition(),
size = this.getSize(),
singleParticlesOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = (0,engine_root_window_.deepExtend)({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
if (hslAnimation) {
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor
};
} else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
}
prepareToDie() {
var _a;
if (this._paused) {
return;
}
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
if (this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal) && duration !== undefined && duration > 0) {
this._duration = duration * 1000;
}
}
setColorAnimation(animation, initValue, maxValue) {
var _a;
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = (0,engine_root_window_.randomInRange)(animation.offset),
delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay),
emitFactor = 1000 * delay / container.retina.reduceFactor,
colorSpeed = (0,engine_root_window_.getRangeValue)((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * 3.6) % maxValue;
}
}

@@ -540,3 +531,3 @@ ;// CONCATENATED MODULE: ./dist/browser/Emitters.js

};
container.getEmitter = idxOrName => idxOrName === undefined || typeof idxOrName === "number" ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
container.getEmitter = idxOrName => idxOrName === undefined || (0,engine_root_window_.isNumber)(idxOrName) ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
container.addEmitter = (options, position) => this.addEmitter(options, position);

@@ -572,29 +563,30 @@ container.removeEmitter = idxOrName => {

modeEmitters = this.interactivityEmitters;
if (mode === "emitter") {
let emittersModeOptions;
if (modeEmitters && modeEmitters.value instanceof Array) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = (0,engine_root_window_.arrayRandomIndex)(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push((0,engine_root_window_.itemFromArray)(modeEmitters.value, idx));
if (mode !== "emitter") {
return;
}
let emittersModeOptions;
if (modeEmitters && (0,engine_root_window_.isArray)(modeEmitters.value)) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = (0,engine_root_window_.arrayRandomIndex)(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
} else {
emittersModeOptions = modeEmitters.value;
usedIndexes.push(idx);
emittersModeOptions.push((0,engine_root_window_.itemFromArray)(modeEmitters.value, idx));
}
} else {
emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
emittersModeOptions = modeEmitters.value;
}
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions,
ePosition = this.container.interactivity.mouse.clickPosition;
(0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, emitter => {
this.addEmitter(emitter, ePosition);
});
} else {
emittersModeOptions = modeEmitters?.value;
}
const emittersOptions = emittersModeOptions ?? emitterOptions,
ePosition = this.container.interactivity.mouse.clickPosition;
(0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, emitter => {
this.addEmitter(emitter, ePosition);
});
}

@@ -604,3 +596,6 @@ async init() {

this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
if (this.emitters instanceof Array) {
if (!this.emitters) {
return;
}
if ((0,engine_root_window_.isArray)(this.emitters)) {
for (const emitterOptions of this.emitters) {

@@ -720,7 +715,6 @@ this.addEmitter(emitterOptions);

loadOptions(options, source) {
var _a, _b, _c, _d, _e, _f;
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
return;
}
if (source === null || source === void 0 ? void 0 : source.emitters) {
if (source?.emitters) {
options.emitters = (0,engine_root_window_.executeOnSingleOrMultiple)(source.emitters, emitter => {

@@ -732,5 +726,5 @@ const tmp = new Emitter();

}
const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
const interactivityEmitters = source?.interactivity?.modes?.emitters;
if (interactivityEmitters) {
if (interactivityEmitters instanceof Array) {
if ((0,engine_root_window_.isArray)(interactivityEmitters)) {
options.interactivity.modes.emitters = {

@@ -750,7 +744,7 @@ random: {

if (emitterMode.value !== undefined) {
if (emitterMode.value instanceof Array) {
if ((0,engine_root_window_.isArray)(emitterMode.value)) {
options.interactivity.modes.emitters = {
random: {
count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false
},

@@ -768,4 +762,4 @@ value: emitterMode.value.map(s => {

random: {
count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false
},

@@ -789,3 +783,2 @@ value: tmp

needsPlugin(options) {
var _a, _b, _c;
if (!options) {

@@ -795,6 +788,6 @@ return false;

const emitters = options.emitters;
return emitters instanceof Array && !!emitters.length || emitters !== undefined || !!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) && (0,engine_root_window_.isInArray)("emitter", options.interactivity.events.onClick.mode);
return (0,engine_root_window_.isArray)(emitters) && !!emitters.length || emitters !== undefined || !!options.interactivity?.events?.onClick?.mode && (0,engine_root_window_.isInArray)("emitter", options.interactivity.events.onClick.mode);
}
}
async function loadEmittersPlugin(engine) {
async function loadEmittersPlugin(engine, refresh = true) {
if (!engine.emitterShapeManager) {

@@ -805,8 +798,7 @@ engine.emitterShapeManager = new ShapeManager(engine);

engine.addEmitterShape = (name, shape) => {
var _a;
(_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
engine.emitterShapeManager?.addShape(name, shape);
};
}
const plugin = new EmittersPlugin(engine);
await engine.addPlugin(plugin);
await engine.addPlugin(plugin, refresh);
engine.addEmitterShape("circle", new CircleShape());

@@ -813,0 +805,0 @@ engine.addEmitterShape("square", new SquareShape());

/*! For license information please see tsparticles.plugin.emitters.min.js.LICENSE.txt */
!function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var e="object"==typeof exports?i(require("@tsparticles/engine")):i(t.window);for(var s in e)("object"==typeof exports?exports:t)[s]=e[s]}}(this,(t=>(()=>{"use strict";var i={533:i=>{i.exports=t}},e={};function s(t){var n=e[t];if(void 0!==n)return n.exports;var o=e[t]={exports:{}};return i[t](o,o.exports,s),o.exports}s.d=(t,i)=>{for(var e in i)s.o(i,e)&&!s.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:i[e]})},s.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{s.r(n),s.d(n,{loadEmittersPlugin:()=>v});var t=s(533);class i{randomPosition(i,e,s){const[n,o]=[e.width/2,e.height/2],a=((i,e)=>{const s=(0,t.getRandom)()/4,n=Math.atan(e/i*Math.tan(2*Math.PI*s)),o=(0,t.getRandom)();return o<.25?n:o<.5?Math.PI-n:o<.75?Math.PI+n:-n})(n,o),r=(c=a,(h=n)*(d=o)/Math.sqrt((d*Math.cos(c))**2+(h*Math.sin(c))**2)),l=s?r*Math.sqrt((0,t.getRandom)()):r;var h,d,c;return{x:i.x+l*Math.cos(a),y:i.y+l*Math.sin(a)}}}class e{constructor(){this.wait=!1}load(t){void 0!==t&&(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=t.delay),void 0!==t.duration&&(this.duration=t.duration),void 0!==t.wait&&(this.wait=t.wait))}}class o{constructor(){this.quantity=1,this.delay=.1}load(i){void 0!==i&&(void 0!==i.quantity&&(this.quantity=(0,t.setRangeValue)(i.quantity)),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)))}}class a{constructor(){this.mode="percent",this.height=0,this.width=0}load(t){void 0!==t&&(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}class r{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new o,this.shape="square",this.startCount=0}load(i){void 0!==i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(void 0===this.size&&(this.size=new a),this.size.load(i.size)),void 0!==i.direction&&(this.direction=i.direction),this.domId=i.domId,void 0!==i.fill&&(this.fill=i.fill),this.life.load(i.life),this.name=i.name,this.particles=(0,t.executeOnSingleOrMultiple)(i.particles,(i=>(0,t.deepExtend)({},i))),this.rate.load(i.rate),void 0!==i.shape&&(this.shape=i.shape),void 0!==i.position&&(this.position={},void 0!==i.position.x&&(this.position.x=(0,t.setRangeValue)(i.position.x)),void 0!==i.position.y&&(this.position.y=(0,t.setRangeValue)(i.position.y))),void 0!==i.spawnColor&&(void 0===this.spawnColor&&(this.spawnColor=new t.AnimatableColor),this.spawnColor.load(i.spawnColor)),void 0!==i.startCount&&(this.startCount=i.startCount))}}class l{constructor(i,e,s,n,o){var l,h,d,c,u,p,m,v;this.emitters=e,this.container=s,this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=o,n instanceof r?this.options=n:(this.options=new r,this.options.load(n)),this._spawnDelay=1e3*(null!==(l=this.options.life.delay)&&void 0!==l?l:0)/this.container.retina.reduceFactor,this.position=null!==(h=this._initialPosition)&&void 0!==h?h:this.calcPosition(),this.name=this.options.name,this._shape=null===(d=this._engine.emitterShapeManager)||void 0===d?void 0:d.getShape(this.options.shape),this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let y=(0,t.deepExtend)({},this.options.particles);null!=y||(y={}),null!==(c=y.move)&&void 0!==c||(y.move={}),null!==(u=(v=y.move).direction)&&void 0!==u||(v.direction=this.options.direction),this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=y,this.size=null!==(p=this.options.size)&&void 0!==p?p:(()=>{const t=new a;return t.load({height:0,mode:"percent",width:0}),t})(),this._lifeCount=null!==(m=this.options.life.count)&&void 0!==m?m:-1,this._immortal=this._lifeCount<=0,this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}getPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{x:(e.x+e.width/2)*t.retina.pixelRatio,y:(e.y+e.height/2)*t.retina.pixelRatio}}}return this.position}getSize(){const t=this.container;if(this.options.domId){const i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{width:e.width*t.retina.pixelRatio,height:e.height*t.retina.pixelRatio}}}return{width:"percent"===this.size.mode?t.canvas.size.width*this.size.width/100:this.size.width,height:"percent"===this.size.mode?t.canvas.size.height*this.size.height/100:this.size.height}}pause(){this._paused||delete this._emitDelay}play(){var i;if(!this._paused&&this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(null!==(i=this._spawnDelay)&&void 0!==i?i:0))){if(void 0===this._emitDelay){const i=(0,t.getRangeValue)(this.options.rate.delay);this._emitDelay=1e3*i/this.container.retina.reduceFactor}(this._lifeCount>0||this._immortal)&&this.prepareToDie()}}resize(){const i=this._initialPosition;this.position=i&&(0,t.isPointInside)(i,this.container.canvas.size,t.Vector.origin)?i:this.calcPosition()}update(t){var i,e,s;this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=null!==(i=this._spawnDelay)&&void 0!==i?i:0,this._currentEmitDelay=null!==(e=this._emitDelay)&&void 0!==e?e:0),this._startParticlesAdded||(this._startParticlesAdded=!0,this.emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=t.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,this._immortal||this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this.calcPosition(),this._spawnDelay=1e3*(null!==(s=this.options.life.delay)&&void 0!==s?s:0)/this.container.retina.reduceFactor):this.destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=t.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this.emit(),this._currentEmitDelay-=this._emitDelay)))}calcPosition(){return(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position})}destroy(){this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})}emit(){if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);this.emitParticles(i)}emitParticles(i){var e,s,n;const o=this.getPosition(),a=this.getSize(),r=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let l=0;l<i;l++){const i=(0,t.deepExtend)({},r);if(this.spawnColor){const t=null===(e=this.options.spawnColor)||void 0===e?void 0:e.animation;t&&(this.spawnColor.h=this.setColorAnimation(t.h,this.spawnColor.h,360),this.spawnColor.s=this.setColorAnimation(t.s,this.spawnColor.s,100),this.spawnColor.l=this.setColorAnimation(t.l,this.spawnColor.l,100)),i.color?i.color.value=this.spawnColor:i.color={value:this.spawnColor}}if(!o)return;const l=null!==(n=null===(s=this._shape)||void 0===s?void 0:s.randomPosition(o,a,this.fill))&&void 0!==n?n:o;this.container.particles.addParticle(l,i)}}prepareToDie(){var t;if(this._paused)return;const i=null===(t=this.options.life)||void 0===t?void 0:t.duration;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==i&&i>0&&(this._duration=1e3*i)}setColorAnimation(i,e,s){var n;const o=this.container;if(!i.enable)return e;const a=(0,t.randomInRange)(i.offset),r=1e3*(0,t.getRangeValue)(this.options.rate.delay)/o.retina.reduceFactor;return(e+(0,t.getRangeValue)(null!==(n=i.speed)&&void 0!==n?n:0)*o.fpsLimit/r+3.6*a)%s}}class h{constructor(t,i){this.container=i,this._engine=t,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]},i.getEmitter=t=>void 0===t||"number"==typeof t?this.array[t||0]:this.array.find((i=>i.name===t)),i.addEmitter=(t,i)=>this.addEmitter(t,i),i.removeEmitter=t=>{const e=i.getEmitter(t);e&&this.removeEmitter(e)},i.playEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPlay()},i.pauseEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPause()}}addEmitter(t,i){const e=new r;e.load(t);const s=new l(this._engine,this,this.container,e,i);return this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"===i){let i;if(s&&s.value instanceof Array)if(s.value.length>0&&s.random.enable){i=[];const e=[];for(let n=0;n<s.random.count;n++){const o=(0,t.arrayRandomIndex)(s.value);e.includes(o)&&e.length<s.value.length?n--:(e.push(o),i.push((0,t.itemFromArray)(s.value,o)))}}else i=s.value;else i=null==s?void 0:s.value;const n=null!=i?i:e,o=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(n,(t=>{this.addEmitter(t,o)}))}}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters instanceof Array)for(const t of this.emitters)this.addEmitter(t);else this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){for(const i of this.array)i.update(t)}}const d=new Map;class c{constructor(t){this._engine=t}addShape(t,i){this.getShape(t)||d.set(t,i)}getShape(t){return d.get(t)}getSupportedShapes(){return d.keys()}}function u(i,e){return i+e*((0,t.getRandom)()-.5)}class p{randomPosition(i,e,s){if(s)return{x:u(i.x,e.width),y:u(i.y,e.height)};{const s=e.width/2,n=e.height/2,o=Math.floor(4*(0,t.getRandom)()),a=2*((0,t.getRandom)()-.5);switch(o){case 0:return{x:i.x+a*s,y:i.y-n};case 1:return{x:i.x-s,y:i.y+a*n};case 2:return{x:i.x+a*s,y:i.y+n};default:return{x:i.x+s,y:i.y+a*n}}}}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new h(this._engine,t)}loadOptions(i,e){var s,n,o,a,l,h;if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;(null==e?void 0:e.emitters)&&(i.emitters=(0,t.executeOnSingleOrMultiple)(e.emitters,(t=>{const i=new r;return i.load(t),i})));const d=null===(n=null===(s=null==e?void 0:e.interactivity)||void 0===s?void 0:s.modes)||void 0===n?void 0:n.emitters;if(d)if(d instanceof Array)i.interactivity.modes.emitters={random:{count:1,enable:!0},value:d.map((t=>{const i=new r;return i.load(t),i}))};else{const t=d;if(void 0!==t.value)if(t.value instanceof Array)i.interactivity.modes.emitters={random:{count:null!==(o=t.random.count)&&void 0!==o?o:1,enable:null!==(a=t.random.enable)&&void 0!==a&&a},value:t.value.map((t=>{const i=new r;return i.load(t),i}))};else{const e=new r;e.load(t.value),i.interactivity.modes.emitters={random:{count:null!==(l=t.random.count)&&void 0!==l?l:1,enable:null!==(h=t.random.enable)&&void 0!==h&&h},value:e}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new r}).value.load(d)}}}needsPlugin(i){var e,s,n;if(!i)return!1;const o=i.emitters;return o instanceof Array&&!!o.length||void 0!==o||!!(null===(n=null===(s=null===(e=i.interactivity)||void 0===e?void 0:e.events)||void 0===s?void 0:s.onClick)||void 0===n?void 0:n.mode)&&(0,t.isInArray)("emitter",i.interactivity.events.onClick.mode)}}async function v(t){t.emitterShapeManager||(t.emitterShapeManager=new c(t)),t.addEmitterShape||(t.addEmitterShape=(i,e)=>{var s;null===(s=t.emitterShapeManager)||void 0===s||s.addShape(i,e)});const e=new m(t);await t.addPlugin(e),t.addEmitterShape("circle",new i),t.addEmitterShape("square",new p)}})(),n})()));
!function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var e="object"==typeof exports?i(require("@tsparticles/engine")):i(t.window);for(var s in e)("object"==typeof exports?exports:t)[s]=e[s]}}(this,(t=>(()=>{"use strict";var i={533:i=>{i.exports=t}},e={};function s(t){var n=e[t];if(void 0!==n)return n.exports;var o=e[t]={exports:{}};return i[t](o,o.exports,s),o.exports}s.d=(t,i)=>{for(var e in i)s.o(i,e)&&!s.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:i[e]})},s.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{s.r(n),s.d(n,{loadEmittersPlugin:()=>y});var t=s(533);class i{randomPosition(i,e,s){const[n,o]=[e.width/2,e.height/2],a=((i,e)=>{const s=(0,t.getRandom)()/4,n=Math.atan(e/i*Math.tan(2*Math.PI*s)),o=(0,t.getRandom)();return o<.25?n:o<.5?Math.PI-n:o<.75?Math.PI+n:-n})(n,o),r=(c=a,(l=n)*(d=o)/Math.sqrt((d*Math.cos(c))**2+(l*Math.sin(c))**2)),h=s?r*Math.sqrt((0,t.getRandom)()):r;var l,d,c;return{x:i.x+h*Math.cos(a),y:i.y+h*Math.sin(a)}}}class e{constructor(){this.wait=!1}load(i){i&&(void 0!==i.count&&(this.count=i.count),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)),void 0!==i.duration&&(this.duration=(0,t.setRangeValue)(i.duration)),void 0!==i.wait&&(this.wait=i.wait))}}class o{constructor(){this.quantity=1,this.delay=.1}load(i){void 0!==i&&(void 0!==i.quantity&&(this.quantity=(0,t.setRangeValue)(i.quantity)),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)))}}class a{constructor(){this.mode="percent",this.height=0,this.width=0}load(t){void 0!==t&&(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}class r{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new o,this.shape="square",this.startCount=0}load(i){i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(this.size||(this.size=new a),this.size.load(i.size)),void 0!==i.direction&&(this.direction=i.direction),this.domId=i.domId,void 0!==i.fill&&(this.fill=i.fill),this.life.load(i.life),this.name=i.name,this.particles=(0,t.executeOnSingleOrMultiple)(i.particles,(i=>(0,t.deepExtend)({},i))),this.rate.load(i.rate),void 0!==i.shape&&(this.shape=i.shape),void 0!==i.position&&(this.position={},void 0!==i.position.x&&(this.position.x=(0,t.setRangeValue)(i.position.x)),void 0!==i.position.y&&(this.position.y=(0,t.setRangeValue)(i.position.y))),void 0!==i.spawnColor&&(void 0===this.spawnColor&&(this.spawnColor=new t.AnimatableColor),this.spawnColor.load(i.spawnColor)),void 0!==i.startCount&&(this.startCount=i.startCount))}}class h{constructor(i,e,s,n,o){this.emitters=e,this.container=s,this._calcPosition=()=>(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position}),this._destroy=()=>{this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},this._emit=()=>{if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);this._emitParticles(i)},this._emitParticles=i=>{const e=this.getPosition(),s=this.getSize(),n=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let o=0;o<i;o++){const i=(0,t.deepExtend)({},n);if(this.spawnColor){const t=this.options.spawnColor?.animation;t&&(this.spawnColor.h=this._setColorAnimation(t.h,this.spawnColor.h,360),this.spawnColor.s=this._setColorAnimation(t.s,this.spawnColor.s,100),this.spawnColor.l=this._setColorAnimation(t.l,this.spawnColor.l,100)),i.color?i.color.value=this.spawnColor:i.color={value:this.spawnColor}}if(!e)return;const o=this._shape?.randomPosition(e,s,this.fill)??e;this.container.particles.addParticle(o,i)}},this._prepareToDie=()=>{if(this._paused)return;const i=void 0!==this.options.life?.duration?(0,t.getRangeValue)(this.options.life.duration):void 0;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==i&&i>0&&(this._duration=1e3*i)},this._setColorAnimation=(i,e,s)=>{const n=this.container;if(!i.enable)return e;const o=(0,t.randomInRange)(i.offset),a=1e3*(0,t.getRangeValue)(this.options.rate.delay)/n.retina.reduceFactor;return(e+(0,t.getRangeValue)(i.speed??0)*n.fpsLimit/a+3.6*o)%s},this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=o,n instanceof r?this.options=n:(this.options=new r,this.options.load(n)),this._spawnDelay=1e3*(0,t.getRangeValue)(this.options.life.delay??0)/this.container.retina.reduceFactor,this.position=this._initialPosition??this._calcPosition(),this.name=this.options.name,this._shape=this._engine.emitterShapeManager?.getShape(this.options.shape),this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let h=(0,t.deepExtend)({},this.options.particles);h??={},h.move??={},h.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=h,this.size=this.options.size??(()=>{const t=new a;return t.load({height:0,mode:"percent",width:0}),t})(),this._lifeCount=this.options.life.count??-1,this._immortal=this._lifeCount<=0,this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}getPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{x:(e.x+e.width/2)*t.retina.pixelRatio,y:(e.y+e.height/2)*t.retina.pixelRatio}}}return this.position}getSize(){const i=this.container;if(this.options.domId){const t=document.getElementById(this.options.domId);if(t){const e=t.getBoundingClientRect();return{width:e.width*i.retina.pixelRatio,height:e.height*i.retina.pixelRatio}}}return(0,t.getSize)(this.size,i.canvas.size)}pause(){this._paused||delete this._emitDelay}play(){if(!this._paused&&this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0))){if(void 0===this._emitDelay){const i=(0,t.getRangeValue)(this.options.rate.delay);this._emitDelay=1e3*i/this.container.retina.reduceFactor}(this._lifeCount>0||this._immortal)&&this._prepareToDie()}}resize(){const i=this._initialPosition;this.position=i&&(0,t.isPointInside)(i,this.container.canvas.size,t.Vector.origin)?i:this._calcPosition()}update(i){this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,this._emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=i.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,this._immortal||this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this._calcPosition(),this._spawnDelay=1e3*(0,t.getRangeValue)(this.options.life.delay??0)/this.container.retina.reduceFactor):this._destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=i.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=i.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay)))}}class l{constructor(i,e){this.container=e,this._engine=i,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]},e.getEmitter=i=>void 0===i||(0,t.isNumber)(i)?this.array[i||0]:this.array.find((t=>t.name===i)),e.addEmitter=(t,i)=>this.addEmitter(t,i),e.removeEmitter=t=>{const i=e.getEmitter(t);i&&this.removeEmitter(i)},e.playEmitter=t=>{const i=e.getEmitter(t);i&&i.externalPlay()},e.pauseEmitter=t=>{const i=e.getEmitter(t);i&&i.externalPause()}}addEmitter(t,i){const e=new r;e.load(t);const s=new h(this._engine,this,this.container,e,i);return this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"!==i)return;let n;if(s&&(0,t.isArray)(s.value))if(s.value.length>0&&s.random.enable){n=[];const i=[];for(let e=0;e<s.random.count;e++){const o=(0,t.arrayRandomIndex)(s.value);i.includes(o)&&i.length<s.value.length?e--:(i.push(o),n.push((0,t.itemFromArray)(s.value,o)))}}else n=s.value;else n=s?.value;const o=n??e,a=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(o,(t=>{this.addEmitter(t,a)}))}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters)if((0,t.isArray)(this.emitters))for(const t of this.emitters)this.addEmitter(t);else this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){for(const i of this.array)i.update(t)}}const d=new Map;class c{constructor(t){this._engine=t}addShape(t,i){this.getShape(t)||d.set(t,i)}getShape(t){return d.get(t)}getSupportedShapes(){return d.keys()}}function u(i,e){return i+e*((0,t.getRandom)()-.5)}class p{randomPosition(i,e,s){if(s)return{x:u(i.x,e.width),y:u(i.y,e.height)};{const s=e.width/2,n=e.height/2,o=Math.floor(4*(0,t.getRandom)()),a=2*((0,t.getRandom)()-.5);switch(o){case 0:return{x:i.x+a*s,y:i.y-n};case 1:return{x:i.x-s,y:i.y+a*n};case 2:return{x:i.x+a*s,y:i.y+n};default:return{x:i.x+s,y:i.y+a*n}}}}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new l(this._engine,t)}loadOptions(i,e){if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;e?.emitters&&(i.emitters=(0,t.executeOnSingleOrMultiple)(e.emitters,(t=>{const i=new r;return i.load(t),i})));const s=e?.interactivity?.modes?.emitters;if(s)if((0,t.isArray)(s))i.interactivity.modes.emitters={random:{count:1,enable:!0},value:s.map((t=>{const i=new r;return i.load(t),i}))};else{const e=s;if(void 0!==e.value)if((0,t.isArray)(e.value))i.interactivity.modes.emitters={random:{count:e.random.count??1,enable:e.random.enable??!1},value:e.value.map((t=>{const i=new r;return i.load(t),i}))};else{const t=new r;t.load(e.value),i.interactivity.modes.emitters={random:{count:e.random.count??1,enable:e.random.enable??!1},value:t}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new r}).value.load(s)}}}needsPlugin(i){if(!i)return!1;const e=i.emitters;return(0,t.isArray)(e)&&!!e.length||void 0!==e||!!i.interactivity?.events?.onClick?.mode&&(0,t.isInArray)("emitter",i.interactivity.events.onClick.mode)}}async function y(t,e=!0){t.emitterShapeManager||(t.emitterShapeManager=new c(t)),t.addEmitterShape||(t.addEmitterShape=(i,e)=>{t.emitterShapeManager?.addShape(i,e)});const s=new m(t);await t.addPlugin(s,e),t.addEmitterShape("circle",new i),t.addEmitterShape("square",new p)}})(),n})()));

@@ -1,8 +0,1 @@

/*!
* Author : Matteo Bruni
* MIT license: https://opensource.org/licenses/MIT
* Demo / Generator : https://particles.js.org/
* GitHub : https://www.github.com/matteobruni/tsparticles
* How to use? : Check the GitHub README
* v3.0.0-alpha.1
*/
/*! tsParticles Emitters Plugin v3.0.0-beta.0 by Matteo Bruni */

@@ -1,2 +0,2 @@

import type { Container, ICoordinates, IDelta, IDimension, IHsl, RecursivePartial } from "@tsparticles/engine";
import { type Container, type ICoordinates, type IDelta, type IDimension, type IHsl, type RecursivePartial } from "@tsparticles/engine";
import { Emitter } from "./Options/Classes/Emitter";

@@ -40,8 +40,8 @@ import type { Emitters } from "./Emitters";

update(delta: IDelta): void;
private calcPosition;
private destroy;
private emit;
private emitParticles;
private prepareToDie;
private setColorAnimation;
private readonly _calcPosition;
private readonly _destroy;
private readonly _emit;
private readonly _emitParticles;
private readonly _prepareToDie;
private readonly _setColorAnimation;
}

@@ -1,2 +0,2 @@

import type { IContainerPlugin, ICoordinates, IDelta, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
import { type IContainerPlugin, type ICoordinates, type IDelta, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
import { Emitter } from "./Options/Classes/Emitter";

@@ -3,0 +3,0 @@ import type { EmitterContainer } from "./EmitterContainer";

export declare const enum EmitterShapeType {
circle = "circle",
square = "square"
polygon = "polygon",
square = "square",
star = "star"
}
import type { EmittersEngine } from "./EmittersEngine";
export declare function loadEmittersPlugin(engine: EmittersEngine): Promise<void>;
export declare function loadEmittersPlugin(engine: EmittersEngine, refresh?: boolean): Promise<void>;
export * from "./EmitterContainer";

@@ -4,0 +4,0 @@ export * from "./EmittersEngine";

@@ -1,3 +0,2 @@

import { AnimatableColor } from "@tsparticles/engine";
import type { IOptionLoader, IParticlesOptions, IRangedCoordinates, MoveDirection, MoveDirectionAlt, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
import { AnimatableColor, type IOptionLoader, type IParticlesOptions, type IRangedCoordinates, type MoveDirection, type MoveDirectionAlt, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
import { EmitterLife } from "./EmitterLife";

@@ -4,0 +3,0 @@ import { EmitterRate } from "./EmitterRate";

@@ -1,7 +0,7 @@

import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
import type { IEmitterLife } from "../Interfaces/IEmitterLife";
export declare class EmitterLife implements IEmitterLife, IOptionLoader<IEmitterLife> {
count?: number;
delay?: number;
duration?: number;
delay?: RangeValue;
duration?: RangeValue;
wait: boolean;

@@ -8,0 +8,0 @@ constructor();

@@ -1,2 +0,2 @@

import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
import type { IEmitterRate } from "../Interfaces/IEmitterRate";

@@ -3,0 +3,0 @@ export declare class EmitterRate implements IEmitterRate, IOptionLoader<IEmitterRate> {

@@ -1,7 +0,6 @@

import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
import { type IOptionLoader, PixelMode, type RecursivePartial } from "@tsparticles/engine";
import type { IEmitterSize } from "../Interfaces/IEmitterSize";
import { SizeMode } from "@tsparticles/engine";
export declare class EmitterSize implements IEmitterSize, IOptionLoader<IEmitterSize> {
height: number;
mode: SizeMode | keyof typeof SizeMode;
mode: PixelMode | keyof typeof PixelMode;
width: number;

@@ -8,0 +7,0 @@ constructor();

@@ -0,6 +1,7 @@

import type { RangeValue } from "@tsparticles/engine";
export interface IEmitterLife {
count?: number;
delay?: number;
duration?: number;
delay?: RangeValue;
duration?: RangeValue;
wait: boolean;
}

@@ -1,4 +0,4 @@

import type { IDimension, SizeMode } from "@tsparticles/engine";
import type { IDimension, PixelMode } from "@tsparticles/engine";
export interface IEmitterSize extends IDimension {
mode: SizeMode | keyof typeof SizeMode;
mode: PixelMode | keyof typeof PixelMode;
}

@@ -1,2 +0,2 @@

import type { ICoordinates, IDimension } from "@tsparticles/engine";
import { type ICoordinates, type IDimension } from "@tsparticles/engine";
import type { IEmitterShape } from "../../IEmitterShape";

@@ -3,0 +3,0 @@ export declare class CircleShape implements IEmitterShape {

@@ -1,2 +0,2 @@

import type { ICoordinates, IDimension } from "@tsparticles/engine";
import { type ICoordinates, type IDimension } from "@tsparticles/engine";
import type { IEmitterShape } from "../../IEmitterShape";

@@ -3,0 +3,0 @@ export declare class SquareShape implements IEmitterShape {

@@ -18,6 +18,73 @@ (function (factory) {

constructor(engine, emitters, container, options, position) {
var _a, _b, _c, _d, _e, _f, _g;
var _h;
this.emitters = emitters;
this.container = container;
this._calcPosition = () => {
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
size: this.container.canvas.size,
position: this.options.position,
});
};
this._destroy = () => {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
};
this._emit = () => {
if (this._paused) {
return;
}
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
this._emitParticles(quantity);
};
this._emitParticles = (quantity) => {
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = this.options.spawnColor?.animation;
if (hslAnimation) {
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
};
this._prepareToDie = () => {
if (this._paused) {
return;
}
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
};
this._setColorAnimation = (animation, initValue, maxValue) => {
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
};
this._engine = engine;

@@ -35,6 +102,6 @@ this._currentDuration = 0;

}
this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._initialPosition ?? this._calcPosition();
this.name = this.options.name;
this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
this.fill = this.options.fill;

@@ -44,5 +111,5 @@ this._firstSpawn = !this.options.life.wait;

let particlesOptions = (0, engine_1.deepExtend)({}, this.options.particles);
particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
(_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
(_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
particlesOptions ??= {};
particlesOptions.move ??= {};
particlesOptions.move.direction ??= this.options.direction;
if (this.options.spawnColor) {

@@ -54,12 +121,13 @@ this.spawnColor = (0, engine_1.rangeColorToHsl)(this.options.spawnColor);

this.size =
(_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
const size = new EmitterSize_1.EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
this.options.size ??
(() => {
const size = new EmitterSize_1.EmitterSize();
size.load({
height: 0,
mode: "percent",
width: 0,
});
return size;
})();
this._lifeCount = this.options.life.count ?? -1;
this._immortal = this._lifeCount <= 0;

@@ -107,10 +175,3 @@ this._engine.dispatchEvent("emitterCreated", {

}
return {
width: this.size.mode === "percent"
? (container.canvas.size.width * this.size.width) / 100
: this.size.width,
height: this.size.mode === "percent"
? (container.canvas.size.height * this.size.height) / 100
: this.size.height,
};
return (0, engine_1.getSize)(this.size, container.canvas.size);
}

@@ -124,3 +185,2 @@ pause() {

play() {
var _a;
if (this._paused) {

@@ -131,3 +191,3 @@ return;

(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
(this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
return;

@@ -140,3 +200,3 @@ }

if (this._lifeCount > 0 || this._immortal) {
this.prepareToDie();
this._prepareToDie();
}

@@ -149,6 +209,5 @@ }

? initialPosition
: this.calcPosition();
: this._calcPosition();
}
update(delta) {
var _a, _b, _c;
if (this._paused) {

@@ -159,8 +218,8 @@ return;

this._firstSpawn = false;
this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
this._currentSpawnDelay = this._spawnDelay ?? 0;
this._currentEmitDelay = this._emitDelay ?? 0;
}
if (!this._startParticlesAdded) {
this._startParticlesAdded = true;
this.emitParticles(this.options.startCount);
this._emitParticles(this.options.startCount);
}

@@ -178,7 +237,8 @@ if (this._duration !== undefined) {

if (this._lifeCount > 0 || this._immortal) {
this.position = this.calcPosition();
this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
this.position = this._calcPosition();
this._spawnDelay =
((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
}
else {
this.destroy();
this._destroy();
}

@@ -203,3 +263,3 @@ this._currentDuration -= this._duration;

if (this._currentEmitDelay >= this._emitDelay) {
this.emit();
this._emit();
this._currentEmitDelay -= this._emitDelay;

@@ -209,76 +269,4 @@ }

}
calcPosition() {
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
size: this.container.canvas.size,
position: this.options.position,
});
}
destroy() {
this.emitters.removeEmitter(this);
this._engine.dispatchEvent("emitterDestroyed", {
container: this.container,
data: {
emitter: this,
},
});
}
emit() {
if (this._paused) {
return;
}
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
this.emitParticles(quantity);
}
emitParticles(quantity) {
var _a, _b, _c;
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
for (let i = 0; i < quantity; i++) {
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
if (this.spawnColor) {
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
if (hslAnimation) {
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
}
if (!particlesOptions.color) {
particlesOptions.color = {
value: this.spawnColor,
};
}
else {
particlesOptions.color.value = this.spawnColor;
}
}
if (!position) {
return;
}
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
this.container.particles.addParticle(pPosition, particlesOptions);
}
}
prepareToDie() {
var _a;
if (this._paused) {
return;
}
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
if (this.container.retina.reduceFactor &&
(this._lifeCount > 0 || this._immortal) &&
duration !== undefined &&
duration > 0) {
this._duration = duration * 1000;
}
}
setColorAnimation(animation, initValue, maxValue) {
var _a;
const container = this.container;
if (!animation.enable) {
return initValue;
}
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = (0, engine_1.getRangeValue)((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
}
}
exports.EmitterInstance = EmitterInstance;
});

@@ -29,3 +29,3 @@ (function (factory) {

};
container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
? this.array[idxOrName || 0]

@@ -62,30 +62,31 @@ : this.array.find((t) => t.name === idxOrName);

const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
if (mode === "emitter") {
let emittersModeOptions;
if (modeEmitters && modeEmitters.value instanceof Array) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
if (mode !== "emitter") {
return;
}
let emittersModeOptions;
if (modeEmitters && (0, engine_1.isArray)(modeEmitters.value)) {
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
emittersModeOptions = [];
const usedIndexes = [];
for (let i = 0; i < modeEmitters.random.count; i++) {
const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
i--;
continue;
}
usedIndexes.push(idx);
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
}
else {
emittersModeOptions = modeEmitters.value;
}
}
else {
emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
emittersModeOptions = modeEmitters.value;
}
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}
else {
emittersModeOptions = modeEmitters?.value;
}
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
this.addEmitter(emitter, ePosition);
});
}

@@ -95,3 +96,6 @@ async init() {

this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
if (this.emitters instanceof Array) {
if (!this.emitters) {
return;
}
if ((0, engine_1.isArray)(this.emitters)) {
for (const emitterOptions of this.emitters) {

@@ -98,0 +102,0 @@ this.addEmitter(emitterOptions);

@@ -42,7 +42,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

loadOptions(options, source) {
var _a, _b, _c, _d, _e, _f;
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
return;
}
if (source === null || source === void 0 ? void 0 : source.emitters) {
if (source?.emitters) {
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {

@@ -54,5 +53,5 @@ const tmp = new Emitter_1.Emitter();

}
const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
const interactivityEmitters = source?.interactivity?.modes?.emitters;
if (interactivityEmitters) {
if (interactivityEmitters instanceof Array) {
if ((0, engine_1.isArray)(interactivityEmitters)) {
options.interactivity.modes.emitters = {

@@ -73,7 +72,7 @@ random: {

if (emitterMode.value !== undefined) {
if (emitterMode.value instanceof Array) {
if ((0, engine_1.isArray)(emitterMode.value)) {
options.interactivity.modes.emitters = {
random: {
count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -92,4 +91,4 @@ value: emitterMode.value.map((s) => {

random: {
count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
count: emitterMode.random.count ?? 1,
enable: emitterMode.random.enable ?? false,
},

@@ -114,3 +113,2 @@ value: tmp,

needsPlugin(options) {
var _a, _b, _c;
if (!options) {

@@ -120,9 +118,9 @@ return false;

const emitters = options.emitters;
return ((emitters instanceof Array && !!emitters.length) ||
return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
emitters !== undefined ||
(!!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
(!!options.interactivity?.events?.onClick?.mode &&
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
}
}
async function loadEmittersPlugin(engine) {
async function loadEmittersPlugin(engine, refresh = true) {
if (!engine.emitterShapeManager) {

@@ -133,8 +131,7 @@ engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);

engine.addEmitterShape = (name, shape) => {
var _a;
(_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
engine.emitterShapeManager?.addShape(name, shape);
};
}
const plugin = new EmittersPlugin(engine);
await engine.addPlugin(plugin);
await engine.addPlugin(plugin, refresh);
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());

@@ -141,0 +138,0 @@ engine.addEmitterShape("square", new SquareShape_1.SquareShape());

@@ -27,3 +27,3 @@ (function (factory) {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -35,3 +35,3 @@ }

if (data.size !== undefined) {
if (this.size === undefined) {
if (!this.size) {
this.size = new EmitterSize_1.EmitterSize();

@@ -38,0 +38,0 @@ }

@@ -7,3 +7,3 @@ (function (factory) {

else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
define(["require", "exports", "@tsparticles/engine"], factory);
}

@@ -14,2 +14,3 @@ })(function (require, exports) {

exports.EmitterLife = void 0;
const engine_1 = require("@tsparticles/engine");
class EmitterLife {

@@ -20,3 +21,3 @@ constructor() {

load(data) {
if (data === undefined) {
if (!data) {
return;

@@ -28,6 +29,6 @@ }

if (data.delay !== undefined) {
this.delay = data.delay;
this.delay = (0, engine_1.setRangeValue)(data.delay);
}
if (data.duration !== undefined) {
this.duration = data.duration;
this.duration = (0, engine_1.setRangeValue)(data.duration);
}

@@ -34,0 +35,0 @@ if (data.wait !== undefined) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc