@tsparticles/plugin-emitters
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -1,4 +0,5 @@ | ||
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine"; | ||
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, millisecondsToSeconds, randomInRange, rangeColorToHsl, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { EmitterSize } from "./Options/Classes/EmitterSize.js"; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -35,8 +36,8 @@ if (particlesOptions.color) { | ||
} | ||
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined; | ||
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0; | ||
if (this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal) && | ||
(this._lifeCount > minLifeCount || this._immortal) && | ||
duration !== undefined && | ||
duration > 0) { | ||
this._duration = duration * 1000; | ||
duration > minDuration) { | ||
this._duration = duration * millisecondsToSeconds; | ||
} | ||
@@ -49,4 +50,4 @@ }; | ||
} | ||
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; | ||
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorFactor = 3.6, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
}; | ||
@@ -65,3 +66,5 @@ this._engine = engine; | ||
} | ||
this._spawnDelay = (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
this._spawnDelay = | ||
(getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
this.position = this._initialPosition ?? this._calcPosition(); | ||
@@ -83,4 +86,4 @@ this.name = this.options.name; | ||
this.size = getSize(this._size, this.container.canvas.size); | ||
this._lifeCount = this.options.life.count ?? -1; | ||
this._immortal = this._lifeCount <= 0; | ||
this._lifeCount = this.options.life.count ?? defaultLifeCount; | ||
this._immortal = this._lifeCount <= minLifeCount; | ||
if (this.options.domId) { | ||
@@ -136,4 +139,4 @@ const element = document.getElementById(this.options.domId); | ||
if (!(this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) { | ||
(this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) { | ||
return; | ||
@@ -143,5 +146,5 @@ } | ||
const delay = getRangeValue(this.options.rate.delay); | ||
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor; | ||
this._emitDelay = (delay * millisecondsToSeconds) / this.container.retina.reduceFactor; | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this._prepareToDie(); | ||
@@ -166,4 +169,4 @@ } | ||
this._firstSpawn = false; | ||
this._currentSpawnDelay = this._spawnDelay ?? 0; | ||
this._currentEmitDelay = this._emitDelay ?? 0; | ||
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay; | ||
this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay; | ||
} | ||
@@ -184,7 +187,8 @@ if (!this._startParticlesAdded) { | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this.position = this._calcPosition(); | ||
this._shape?.resize(this.position, this.size); | ||
this._spawnDelay = | ||
(getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
(getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
} | ||
@@ -212,3 +216,3 @@ else { | ||
if (this._currentEmitDelay >= this._emitDelay) { | ||
this._emit(); | ||
await this._emit(); | ||
this._currentEmitDelay -= this._emitDelay; | ||
@@ -222,6 +226,6 @@ } | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(); | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
return { | ||
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio, | ||
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio, | ||
x: (elRect.x + elRect.width * half) * pxRatio, | ||
y: (elRect.y + elRect.height * half) * pxRatio, | ||
}; | ||
@@ -273,5 +277,10 @@ } | ||
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); | ||
const maxValues = { | ||
h: 360, | ||
s: 100, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
} | ||
@@ -278,0 +287,0 @@ setParticlesOptionsColor(particlesOptions, this.spawnColor); |
@@ -17,4 +17,5 @@ import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine"; | ||
}; | ||
const defaultIndex = 0; | ||
container.getEmitter = (idxOrName) => idxOrName === undefined || isNumber(idxOrName) | ||
? this.array[idxOrName || 0] | ||
? this.array[idxOrName ?? defaultIndex] | ||
: this.array.find((t) => t.name === idxOrName); | ||
@@ -56,3 +57,4 @@ container.addEmitter = async (options, position) => this.addEmitter(options, position); | ||
if (modeEmitters && isArray(modeEmitters.value)) { | ||
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) { | ||
const minLength = 0; | ||
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) { | ||
emittersModeOptions = []; | ||
@@ -78,4 +80,4 @@ const usedIndexes = []; | ||
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition; | ||
executeOnSingleOrMultiple(emittersOptions, (emitter) => { | ||
this.addEmitter(emitter, ePosition); | ||
void executeOnSingleOrMultiple(emittersOptions, async (emitter) => { | ||
await this.addEmitter(emitter, ePosition); | ||
}); | ||
@@ -109,5 +111,5 @@ } | ||
removeEmitter(emitter) { | ||
const index = this.array.indexOf(emitter); | ||
if (index >= 0) { | ||
this.array.splice(index, 1); | ||
const index = this.array.indexOf(emitter), minIndex = 0, deleteCount = 1; | ||
if (index >= minIndex) { | ||
this.array.splice(index, deleteCount); | ||
} | ||
@@ -114,0 +116,0 @@ } |
@@ -42,6 +42,7 @@ import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine"; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if (isArray(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -61,3 +62,3 @@ }, | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -64,0 +65,0 @@ }, |
@@ -7,2 +7,3 @@ "use strict"; | ||
const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js"); | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -39,8 +40,8 @@ if (particlesOptions.color) { | ||
} | ||
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined; | ||
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0; | ||
if (this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal) && | ||
(this._lifeCount > minLifeCount || this._immortal) && | ||
duration !== undefined && | ||
duration > 0) { | ||
this._duration = duration * 1000; | ||
duration > minDuration) { | ||
this._duration = duration * engine_1.millisecondsToSeconds; | ||
} | ||
@@ -53,4 +54,4 @@ }; | ||
} | ||
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; | ||
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (delay * engine_1.millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorFactor = 3.6, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
}; | ||
@@ -69,3 +70,5 @@ this._engine = engine; | ||
} | ||
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
this._spawnDelay = | ||
((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
this.position = this._initialPosition ?? this._calcPosition(); | ||
@@ -87,4 +90,4 @@ this.name = this.options.name; | ||
this.size = (0, engine_1.getSize)(this._size, this.container.canvas.size); | ||
this._lifeCount = this.options.life.count ?? -1; | ||
this._immortal = this._lifeCount <= 0; | ||
this._lifeCount = this.options.life.count ?? defaultLifeCount; | ||
this._immortal = this._lifeCount <= minLifeCount; | ||
if (this.options.domId) { | ||
@@ -140,4 +143,4 @@ const element = document.getElementById(this.options.domId); | ||
if (!(this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) { | ||
(this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) { | ||
return; | ||
@@ -147,5 +150,5 @@ } | ||
const delay = (0, engine_1.getRangeValue)(this.options.rate.delay); | ||
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor; | ||
this._emitDelay = (delay * engine_1.millisecondsToSeconds) / this.container.retina.reduceFactor; | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this._prepareToDie(); | ||
@@ -170,4 +173,4 @@ } | ||
this._firstSpawn = false; | ||
this._currentSpawnDelay = this._spawnDelay ?? 0; | ||
this._currentEmitDelay = this._emitDelay ?? 0; | ||
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay; | ||
this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay; | ||
} | ||
@@ -188,7 +191,8 @@ if (!this._startParticlesAdded) { | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this.position = this._calcPosition(); | ||
this._shape?.resize(this.position, this.size); | ||
this._spawnDelay = | ||
((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
} | ||
@@ -216,3 +220,3 @@ else { | ||
if (this._currentEmitDelay >= this._emitDelay) { | ||
this._emit(); | ||
await this._emit(); | ||
this._currentEmitDelay -= this._emitDelay; | ||
@@ -226,6 +230,6 @@ } | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(); | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
return { | ||
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio, | ||
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio, | ||
x: (elRect.x + elRect.width * half) * pxRatio, | ||
y: (elRect.y + elRect.height * half) * pxRatio, | ||
}; | ||
@@ -277,5 +281,10 @@ } | ||
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); | ||
const maxValues = { | ||
h: 360, | ||
s: 100, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
} | ||
@@ -282,0 +291,0 @@ setParticlesOptionsColor(particlesOptions, this.spawnColor); |
@@ -20,4 +20,5 @@ "use strict"; | ||
}; | ||
const defaultIndex = 0; | ||
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName) | ||
? this.array[idxOrName || 0] | ||
? this.array[idxOrName ?? defaultIndex] | ||
: this.array.find((t) => t.name === idxOrName); | ||
@@ -59,3 +60,4 @@ container.addEmitter = async (options, position) => this.addEmitter(options, position); | ||
if (modeEmitters && (0, engine_1.isArray)(modeEmitters.value)) { | ||
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) { | ||
const minLength = 0; | ||
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) { | ||
emittersModeOptions = []; | ||
@@ -81,4 +83,4 @@ const usedIndexes = []; | ||
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition; | ||
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => { | ||
this.addEmitter(emitter, ePosition); | ||
void (0, engine_1.executeOnSingleOrMultiple)(emittersOptions, async (emitter) => { | ||
await this.addEmitter(emitter, ePosition); | ||
}); | ||
@@ -112,5 +114,5 @@ } | ||
removeEmitter(emitter) { | ||
const index = this.array.indexOf(emitter); | ||
if (index >= 0) { | ||
this.array.splice(index, 1); | ||
const index = this.array.indexOf(emitter), minIndex = 0, deleteCount = 1; | ||
if (index >= minIndex) { | ||
this.array.splice(index, deleteCount); | ||
} | ||
@@ -117,0 +119,0 @@ } |
@@ -59,6 +59,7 @@ "use strict"; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if ((0, engine_1.isArray)(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -78,3 +79,3 @@ }, | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -81,0 +82,0 @@ }, |
@@ -1,4 +0,5 @@ | ||
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine"; | ||
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, millisecondsToSeconds, randomInRange, rangeColorToHsl, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { EmitterSize } from "./Options/Classes/EmitterSize.js"; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -35,8 +36,8 @@ if (particlesOptions.color) { | ||
} | ||
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined; | ||
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0; | ||
if (this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal) && | ||
(this._lifeCount > minLifeCount || this._immortal) && | ||
duration !== undefined && | ||
duration > 0) { | ||
this._duration = duration * 1000; | ||
duration > minDuration) { | ||
this._duration = duration * millisecondsToSeconds; | ||
} | ||
@@ -49,4 +50,4 @@ }; | ||
} | ||
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; | ||
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorFactor = 3.6, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
}; | ||
@@ -65,3 +66,5 @@ this._engine = engine; | ||
} | ||
this._spawnDelay = (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
this._spawnDelay = | ||
(getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
this.position = this._initialPosition ?? this._calcPosition(); | ||
@@ -83,4 +86,4 @@ this.name = this.options.name; | ||
this.size = getSize(this._size, this.container.canvas.size); | ||
this._lifeCount = this.options.life.count ?? -1; | ||
this._immortal = this._lifeCount <= 0; | ||
this._lifeCount = this.options.life.count ?? defaultLifeCount; | ||
this._immortal = this._lifeCount <= minLifeCount; | ||
if (this.options.domId) { | ||
@@ -136,4 +139,4 @@ const element = document.getElementById(this.options.domId); | ||
if (!(this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) { | ||
(this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) { | ||
return; | ||
@@ -143,5 +146,5 @@ } | ||
const delay = getRangeValue(this.options.rate.delay); | ||
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor; | ||
this._emitDelay = (delay * millisecondsToSeconds) / this.container.retina.reduceFactor; | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this._prepareToDie(); | ||
@@ -166,4 +169,4 @@ } | ||
this._firstSpawn = false; | ||
this._currentSpawnDelay = this._spawnDelay ?? 0; | ||
this._currentEmitDelay = this._emitDelay ?? 0; | ||
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay; | ||
this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay; | ||
} | ||
@@ -184,7 +187,8 @@ if (!this._startParticlesAdded) { | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this.position = this._calcPosition(); | ||
this._shape?.resize(this.position, this.size); | ||
this._spawnDelay = | ||
(getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
(getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
} | ||
@@ -212,3 +216,3 @@ else { | ||
if (this._currentEmitDelay >= this._emitDelay) { | ||
this._emit(); | ||
await this._emit(); | ||
this._currentEmitDelay -= this._emitDelay; | ||
@@ -222,6 +226,6 @@ } | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(); | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
return { | ||
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio, | ||
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio, | ||
x: (elRect.x + elRect.width * half) * pxRatio, | ||
y: (elRect.y + elRect.height * half) * pxRatio, | ||
}; | ||
@@ -273,5 +277,10 @@ } | ||
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); | ||
const maxValues = { | ||
h: 360, | ||
s: 100, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
} | ||
@@ -278,0 +287,0 @@ setParticlesOptionsColor(particlesOptions, this.spawnColor); |
@@ -17,4 +17,5 @@ import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine"; | ||
}; | ||
const defaultIndex = 0; | ||
container.getEmitter = (idxOrName) => idxOrName === undefined || isNumber(idxOrName) | ||
? this.array[idxOrName || 0] | ||
? this.array[idxOrName ?? defaultIndex] | ||
: this.array.find((t) => t.name === idxOrName); | ||
@@ -56,3 +57,4 @@ container.addEmitter = async (options, position) => this.addEmitter(options, position); | ||
if (modeEmitters && isArray(modeEmitters.value)) { | ||
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) { | ||
const minLength = 0; | ||
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) { | ||
emittersModeOptions = []; | ||
@@ -78,4 +80,4 @@ const usedIndexes = []; | ||
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition; | ||
executeOnSingleOrMultiple(emittersOptions, (emitter) => { | ||
this.addEmitter(emitter, ePosition); | ||
void executeOnSingleOrMultiple(emittersOptions, async (emitter) => { | ||
await this.addEmitter(emitter, ePosition); | ||
}); | ||
@@ -109,5 +111,5 @@ } | ||
removeEmitter(emitter) { | ||
const index = this.array.indexOf(emitter); | ||
if (index >= 0) { | ||
this.array.splice(index, 1); | ||
const index = this.array.indexOf(emitter), minIndex = 0, deleteCount = 1; | ||
if (index >= minIndex) { | ||
this.array.splice(index, deleteCount); | ||
} | ||
@@ -114,0 +116,0 @@ } |
@@ -42,6 +42,7 @@ import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine"; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if (isArray(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -61,3 +62,3 @@ }, | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -64,0 +65,0 @@ }, |
{ | ||
"name": "@tsparticles/plugin-emitters", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "tsParticles emitters plugin", | ||
@@ -89,3 +89,3 @@ "homepage": "https://particles.js.org", | ||
"dependencies": { | ||
"@tsparticles/engine": "^3.0.3" | ||
"@tsparticles/engine": "^3.1.0" | ||
}, | ||
@@ -92,0 +92,0 @@ "publishConfig": { |
@@ -7,3 +7,3 @@ /*! | ||
* How to use? : Check the GitHub README | ||
* v3.0.3 | ||
* v3.1.0 | ||
*/ | ||
@@ -272,2 +272,8 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
const half = 0.5, | ||
defaultLifeDelay = 0, | ||
minLifeCount = 0, | ||
defaultSpawnDelay = 0, | ||
defaultEmitDelay = 0, | ||
defaultLifeCount = -1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -303,5 +309,7 @@ if (particlesOptions.color) { | ||
} | ||
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; | ||
const duration = this.options.life?.duration !== undefined ? (0,engine_root_window_.getRangeValue)(this.options.life.duration) : undefined, | ||
minDuration = 0, | ||
minLifeCount = 0; | ||
if (this.container.retina.reduceFactor && (this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) { | ||
this._duration = duration * engine_root_window_.millisecondsToSeconds; | ||
} | ||
@@ -316,5 +324,7 @@ }; | ||
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; | ||
emitFactor = delay * engine_root_window_.millisecondsToSeconds / container.retina.reduceFactor, | ||
defaultColorSpeed = 0, | ||
colorFactor = 3.6, | ||
colorSpeed = (0,engine_root_window_.getRangeValue)(animation.speed ?? defaultColorSpeed); | ||
return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * colorFactor) % maxValue; | ||
}; | ||
@@ -332,3 +342,3 @@ this._engine = engine; | ||
} | ||
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor; | ||
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_root_window_.millisecondsToSeconds / this.container.retina.reduceFactor; | ||
this.position = this._initialPosition ?? this._calcPosition(); | ||
@@ -350,4 +360,4 @@ this.name = this.options.name; | ||
this.size = (0,engine_root_window_.getSize)(this._size, this.container.canvas.size); | ||
this._lifeCount = this.options.life.count ?? -1; | ||
this._immortal = this._lifeCount <= 0; | ||
this._lifeCount = this.options.life.count ?? defaultLifeCount; | ||
this._immortal = this._lifeCount <= minLifeCount; | ||
if (this.options.domId) { | ||
@@ -403,3 +413,3 @@ const element = document.getElementById(this.options.domId); | ||
} | ||
if (!(this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) { | ||
if (!(this.container.retina.reduceFactor && (this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) { | ||
return; | ||
@@ -409,5 +419,5 @@ } | ||
const delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay); | ||
this._emitDelay = 1000 * delay / this.container.retina.reduceFactor; | ||
this._emitDelay = delay * engine_root_window_.millisecondsToSeconds / this.container.retina.reduceFactor; | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this._prepareToDie(); | ||
@@ -429,4 +439,4 @@ } | ||
this._firstSpawn = false; | ||
this._currentSpawnDelay = this._spawnDelay ?? 0; | ||
this._currentEmitDelay = this._emitDelay ?? 0; | ||
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay; | ||
this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay; | ||
} | ||
@@ -447,6 +457,6 @@ if (!this._startParticlesAdded) { | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this.position = this._calcPosition(); | ||
this._shape?.resize(this.position, this.size); | ||
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor; | ||
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_root_window_.millisecondsToSeconds / this.container.retina.reduceFactor; | ||
} else { | ||
@@ -473,3 +483,3 @@ this._destroy(); | ||
if (this._currentEmitDelay >= this._emitDelay) { | ||
this._emit(); | ||
await this._emit(); | ||
this._currentEmitDelay -= this._emitDelay; | ||
@@ -484,6 +494,7 @@ } | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(); | ||
const elRect = element.getBoundingClientRect(), | ||
pxRatio = container.retina.pixelRatio; | ||
return { | ||
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio, | ||
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio | ||
x: (elRect.x + elRect.width * half) * pxRatio, | ||
y: (elRect.y + elRect.height * half) * pxRatio | ||
}; | ||
@@ -534,5 +545,10 @@ } | ||
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); | ||
const maxValues = { | ||
h: 360, | ||
s: 100, | ||
l: 100 | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
} | ||
@@ -587,3 +603,4 @@ setParticlesOptionsColor(particlesOptions, this.spawnColor); | ||
}; | ||
container.getEmitter = idxOrName => idxOrName === undefined || (0,engine_root_window_.isNumber)(idxOrName) ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName); | ||
const defaultIndex = 0; | ||
container.getEmitter = idxOrName => idxOrName === undefined || (0,engine_root_window_.isNumber)(idxOrName) ? this.array[idxOrName ?? defaultIndex] : this.array.find(t => t.name === idxOrName); | ||
container.addEmitter = async (options, position) => this.addEmitter(options, position); | ||
@@ -625,3 +642,4 @@ container.removeEmitter = idxOrName => { | ||
if (modeEmitters && (0,engine_root_window_.isArray)(modeEmitters.value)) { | ||
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) { | ||
const minLength = 0; | ||
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) { | ||
emittersModeOptions = []; | ||
@@ -646,4 +664,4 @@ const usedIndexes = []; | ||
ePosition = this.container.interactivity.mouse.clickPosition; | ||
(0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, emitter => { | ||
this.addEmitter(emitter, ePosition); | ||
void (0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, async emitter => { | ||
await this.addEmitter(emitter, ePosition); | ||
}); | ||
@@ -676,5 +694,7 @@ } | ||
removeEmitter(emitter) { | ||
const index = this.array.indexOf(emitter); | ||
if (index >= 0) { | ||
this.array.splice(index, 1); | ||
const index = this.array.indexOf(emitter), | ||
minIndex = 0, | ||
deleteCount = 1; | ||
if (index >= minIndex) { | ||
this.array.splice(index, deleteCount); | ||
} | ||
@@ -768,6 +788,7 @@ } | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if ((0,engine_root_window_.isArray)(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false | ||
@@ -786,3 +807,3 @@ }, | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false | ||
@@ -789,0 +810,0 @@ }, |
/*! 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 o=e[t];if(void 0!==o)return o.exports;var n=e[t]={exports:{}};return i[t](n,n.exports,s),n.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 o={};return(()=>{s.r(o),s.d(o,{EmitterShapeBase:()=>m,loadEmittersPlugin:()=>_});var t=s(533);class i{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 e{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 n{constructor(){this.color=!1,this.opacity=!1}load(t){t&&(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class a{constructor(){this.options={},this.replace=new n,this.type="square"}load(i){i&&(void 0!==i.options&&(this.options=(0,t.deepExtend)({},i.options??{})),this.replace.load(i.replace),void 0!==i.type&&(this.type=i.type))}}class r{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 h{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new i,this.rate=new e,this.shape=new a,this.startCount=0}load(i){i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(this.size||(this.size=new r),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),this.shape.load(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))}}function l(t,i){t.color?t.color.value=i:t.color={value:i}}class c{constructor(i,e,s,o,n){this.emitters=e,this.container=s,this._destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},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 o=this.container;if(!i.enable)return e;const n=(0,t.randomInRange)(i.offset),a=1e3*(0,t.getRangeValue)(this.options.rate.delay)/o.retina.reduceFactor;return(e+(0,t.getRangeValue)(i.speed??0)*o.fpsLimit/a+3.6*n)%s},this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=n,o instanceof h?this.options=o:(this.options=new h,this.options.load(o)),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.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let a=(0,t.deepExtend)({},this.options.particles);if(a??={},a.move??={},a.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=a,this._size=this._calcSize(),this.size=(0,t.getSize)(this._size,this.container.canvas.size),this._lifeCount=this.options.life.count??-1,this._immortal=this._lifeCount<=0,this.options.domId){const t=document.getElementById(this.options.domId);t&&(this._mutationObserver=new MutationObserver((()=>{this.resize()})),this._resizeObserver=new ResizeObserver((()=>{this.resize()})),this._mutationObserver.observe(t,{attributes:!0,attributeFilter:["style","width","height"]}),this._resizeObserver.observe(t))}const r=this.options.shape,l=this._engine.emitterShapeManager?.getShapeGenerator(r.type);l&&(this._shape=l.generate(this.position,this.size,this.fill,r.options)),this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}async init(){await(this._shape?.init())}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(),this._size=this._calcSize(),this.size=(0,t.getSize)(this._size,this.container.canvas.size),this._shape?.resize(this.position,this.size)}async update(i){this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,await 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._shape?.resize(this.position,this.size),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)))}_calcPosition(){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(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position})}_calcSize(){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,mode:"precise"}}}return this.options.size??(()=>{const t=new r;return t.load({height:0,mode:"percent",width:0}),t})()}async _emit(){if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);await this._emitParticles(i)}async _emitParticles(i){const e=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let s=0;s<i;s++){const i=(0,t.deepExtend)({},e);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)),l(i,this.spawnColor)}const s=this.options.shape;let o=this.position;if(this._shape){const t=await this._shape.randomPosition();if(t){o=t.position;const e=s.replace;e.color&&t.color&&l(i,t.color),e.opacity&&(i.opacity?i.opacity.value=t.opacity:i.opacity={value:t.opacity})}else o=null}o&&this.container.particles.addParticle(o,i)}}}class d{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=async(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()}}async addEmitter(t,i){const e=new h;e.load(t);const s=new c(this._engine,this,this.container,e,i);return await s.init(),this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"!==i)return;let o;if(s&&(0,t.isArray)(s.value))if(s.value.length>0&&s.random.enable){o=[];const i=[];for(let e=0;e<s.random.count;e++){const n=(0,t.arrayRandomIndex)(s.value);i.includes(n)&&i.length<s.value.length?e--:(i.push(n),o.push((0,t.itemFromArray)(s.value,n)))}}else o=s.value;else o=s?.value;const n=o??e,a=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(n,(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)await this.addEmitter(t);else await 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=[]}async update(t){for(const i of this.array)await i.update(t)}}const p=new Map;class u{constructor(t){this._engine=t}addShapeGenerator(t,i){this.getShapeGenerator(t)||p.set(t,i)}getShapeGenerator(t){return p.get(t)}getSupportedShapeGenerators(){return p.keys()}}class m{constructor(t,i,e,s){this.position=t,this.size=i,this.fill=e,this.options=s}resize(t,i){this.position=t,this.size=i}}class y{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new d(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 h;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 h;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 h;return i.load(t),i}))};else{const t=new h;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 h}).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 _(t,i=!0){t.emitterShapeManager||(t.emitterShapeManager=new u(t)),t.addEmitterShapeGenerator||(t.addEmitterShapeGenerator=(i,e)=>{t.emitterShapeManager?.addShapeGenerator(i,e)});const e=new y(t);await t.addPlugin(e,i)}})(),o})())); | ||
!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 o=e[t];if(void 0!==o)return o.exports;var n=e[t]={exports:{}};return i[t](n,n.exports,s),n.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 o={};return(()=>{s.r(o),s.d(o,{EmitterShapeBase:()=>m,loadEmittersPlugin:()=>_});var t=s(533);class i{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 e{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 n{constructor(){this.color=!1,this.opacity=!1}load(t){t&&(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class a{constructor(){this.options={},this.replace=new n,this.type="square"}load(i){i&&(void 0!==i.options&&(this.options=(0,t.deepExtend)({},i.options??{})),this.replace.load(i.replace),void 0!==i.type&&(this.type=i.type))}}class r{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 h{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new i,this.rate=new e,this.shape=new a,this.startCount=0}load(i){i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(this.size||(this.size=new r),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),this.shape.load(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))}}function l(t,i){t.color?t.color.value=i:t.color={value:i}}class c{constructor(i,e,s,o,n){this.emitters=e,this.container=s,this._destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},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=i*t.millisecondsToSeconds)},this._setColorAnimation=(i,e,s)=>{const o=this.container;if(!i.enable)return e;const n=(0,t.randomInRange)(i.offset),a=(0,t.getRangeValue)(this.options.rate.delay)*t.millisecondsToSeconds/o.retina.reduceFactor;return(e+(0,t.getRangeValue)(i.speed??0)*o.fpsLimit/a+3.6*n)%s},this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=n,o instanceof h?this.options=o:(this.options=new h,this.options.load(o)),this._spawnDelay=(0,t.getRangeValue)(this.options.life.delay??0)*t.millisecondsToSeconds/this.container.retina.reduceFactor,this.position=this._initialPosition??this._calcPosition(),this.name=this.options.name,this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let a=(0,t.deepExtend)({},this.options.particles);if(a??={},a.move??={},a.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=a,this._size=this._calcSize(),this.size=(0,t.getSize)(this._size,this.container.canvas.size),this._lifeCount=this.options.life.count??-1,this._immortal=this._lifeCount<=0,this.options.domId){const t=document.getElementById(this.options.domId);t&&(this._mutationObserver=new MutationObserver((()=>{this.resize()})),this._resizeObserver=new ResizeObserver((()=>{this.resize()})),this._mutationObserver.observe(t,{attributes:!0,attributeFilter:["style","width","height"]}),this._resizeObserver.observe(t))}const r=this.options.shape,l=this._engine.emitterShapeManager?.getShapeGenerator(r.type);l&&(this._shape=l.generate(this.position,this.size,this.fill,r.options)),this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}async init(){await(this._shape?.init())}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=i*t.millisecondsToSeconds/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(),this._size=this._calcSize(),this.size=(0,t.getSize)(this._size,this.container.canvas.size),this._shape?.resize(this.position,this.size)}async update(i){this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,await 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._shape?.resize(this.position,this.size),this._spawnDelay=(0,t.getRangeValue)(this.options.life.delay??0)*t.millisecondsToSeconds/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&&(await this._emit(),this._currentEmitDelay-=this._emitDelay)))}_calcPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect(),s=t.retina.pixelRatio;return{x:(e.x+.5*e.width)*s,y:(e.y+.5*e.height)*s}}}return(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position})}_calcSize(){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,mode:"precise"}}}return this.options.size??(()=>{const t=new r;return t.load({height:0,mode:"percent",width:0}),t})()}async _emit(){if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);await this._emitParticles(i)}async _emitParticles(i){const e=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let s=0;s<i;s++){const i=(0,t.deepExtend)({},e);if(this.spawnColor){const t=this.options.spawnColor?.animation;if(t){const i={h:360,s:100,l:100};this.spawnColor.h=this._setColorAnimation(t.h,this.spawnColor.h,i.h),this.spawnColor.s=this._setColorAnimation(t.s,this.spawnColor.s,i.s),this.spawnColor.l=this._setColorAnimation(t.l,this.spawnColor.l,i.l)}l(i,this.spawnColor)}const s=this.options.shape;let o=this.position;if(this._shape){const t=await this._shape.randomPosition();if(t){o=t.position;const e=s.replace;e.color&&t.color&&l(i,t.color),e.opacity&&(i.opacity?i.opacity.value=t.opacity:i.opacity={value:t.opacity})}else o=null}o&&this.container.particles.addParticle(o,i)}}}class d{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=async(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()}}async addEmitter(t,i){const e=new h;e.load(t);const s=new c(this._engine,this,this.container,e,i);return await s.init(),this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"!==i)return;let o;if(s&&(0,t.isArray)(s.value)){const i=0;if(s.value.length>i&&s.random.enable){o=[];const i=[];for(let e=0;e<s.random.count;e++){const n=(0,t.arrayRandomIndex)(s.value);i.includes(n)&&i.length<s.value.length?e--:(i.push(n),o.push((0,t.itemFromArray)(s.value,n)))}}else o=s.value}else o=s?.value;const n=o??e,a=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(n,(async t=>{await 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)await this.addEmitter(t);else await 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=[]}async update(t){for(const i of this.array)await i.update(t)}}const p=new Map;class u{constructor(t){this._engine=t}addShapeGenerator(t,i){this.getShapeGenerator(t)||p.set(t,i)}getShapeGenerator(t){return p.get(t)}getSupportedShapeGenerators(){return p.keys()}}class m{constructor(t,i,e,s){this.position=t,this.size=i,this.fill=e,this.options=s}resize(t,i){this.position=t,this.size=i}}class y{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new d(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 h;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 h;return i.load(t),i}))};else{const e=s;if(void 0!==e.value){const s=1;if((0,t.isArray)(e.value))i.interactivity.modes.emitters={random:{count:e.random.count??s,enable:e.random.enable??!1},value:e.value.map((t=>{const i=new h;return i.load(t),i}))};else{const t=new h;t.load(e.value),i.interactivity.modes.emitters={random:{count:e.random.count??s,enable:e.random.enable??!1},value:t}}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new h}).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 _(t,i=!0){t.emitterShapeManager||(t.emitterShapeManager=new u(t)),t.addEmitterShapeGenerator||(t.addEmitterShapeGenerator=(i,e)=>{t.emitterShapeManager?.addShapeGenerator(i,e)});const e=new y(t);await t.addPlugin(e,i)}})(),o})())); |
@@ -1,1 +0,1 @@ | ||
/*! tsParticles Emitters Plugin v3.0.3 by Matteo Bruni */ | ||
/*! tsParticles Emitters Plugin v3.1.0 by Matteo Bruni */ |
@@ -16,2 +16,3 @@ (function (factory) { | ||
const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js"); | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -48,8 +49,8 @@ if (particlesOptions.color) { | ||
} | ||
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined; | ||
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0; | ||
if (this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal) && | ||
(this._lifeCount > minLifeCount || this._immortal) && | ||
duration !== undefined && | ||
duration > 0) { | ||
this._duration = duration * 1000; | ||
duration > minDuration) { | ||
this._duration = duration * engine_1.millisecondsToSeconds; | ||
} | ||
@@ -62,4 +63,4 @@ }; | ||
} | ||
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; | ||
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (delay * engine_1.millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorFactor = 3.6, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
}; | ||
@@ -78,3 +79,5 @@ this._engine = engine; | ||
} | ||
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
this._spawnDelay = | ||
((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
this.position = this._initialPosition ?? this._calcPosition(); | ||
@@ -96,4 +99,4 @@ this.name = this.options.name; | ||
this.size = (0, engine_1.getSize)(this._size, this.container.canvas.size); | ||
this._lifeCount = this.options.life.count ?? -1; | ||
this._immortal = this._lifeCount <= 0; | ||
this._lifeCount = this.options.life.count ?? defaultLifeCount; | ||
this._immortal = this._lifeCount <= minLifeCount; | ||
if (this.options.domId) { | ||
@@ -149,4 +152,4 @@ const element = document.getElementById(this.options.domId); | ||
if (!(this.container.retina.reduceFactor && | ||
(this._lifeCount > 0 || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) { | ||
(this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && | ||
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) { | ||
return; | ||
@@ -156,5 +159,5 @@ } | ||
const delay = (0, engine_1.getRangeValue)(this.options.rate.delay); | ||
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor; | ||
this._emitDelay = (delay * engine_1.millisecondsToSeconds) / this.container.retina.reduceFactor; | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this._prepareToDie(); | ||
@@ -179,4 +182,4 @@ } | ||
this._firstSpawn = false; | ||
this._currentSpawnDelay = this._spawnDelay ?? 0; | ||
this._currentEmitDelay = this._emitDelay ?? 0; | ||
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay; | ||
this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay; | ||
} | ||
@@ -197,7 +200,8 @@ if (!this._startParticlesAdded) { | ||
} | ||
if (this._lifeCount > 0 || this._immortal) { | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this.position = this._calcPosition(); | ||
this._shape?.resize(this.position, this.size); | ||
this._spawnDelay = | ||
((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor; | ||
((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) / | ||
this.container.retina.reduceFactor; | ||
} | ||
@@ -225,3 +229,3 @@ else { | ||
if (this._currentEmitDelay >= this._emitDelay) { | ||
this._emit(); | ||
await this._emit(); | ||
this._currentEmitDelay -= this._emitDelay; | ||
@@ -235,6 +239,6 @@ } | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(); | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
return { | ||
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio, | ||
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio, | ||
x: (elRect.x + elRect.width * half) * pxRatio, | ||
y: (elRect.y + elRect.height * half) * pxRatio, | ||
}; | ||
@@ -286,5 +290,10 @@ } | ||
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); | ||
const maxValues = { | ||
h: 360, | ||
s: 100, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
} | ||
@@ -291,0 +300,0 @@ setParticlesOptionsColor(particlesOptions, this.spawnColor); |
@@ -29,4 +29,5 @@ (function (factory) { | ||
}; | ||
const defaultIndex = 0; | ||
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName) | ||
? this.array[idxOrName || 0] | ||
? this.array[idxOrName ?? defaultIndex] | ||
: this.array.find((t) => t.name === idxOrName); | ||
@@ -68,3 +69,4 @@ container.addEmitter = async (options, position) => this.addEmitter(options, position); | ||
if (modeEmitters && (0, engine_1.isArray)(modeEmitters.value)) { | ||
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) { | ||
const minLength = 0; | ||
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) { | ||
emittersModeOptions = []; | ||
@@ -90,4 +92,4 @@ const usedIndexes = []; | ||
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition; | ||
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => { | ||
this.addEmitter(emitter, ePosition); | ||
void (0, engine_1.executeOnSingleOrMultiple)(emittersOptions, async (emitter) => { | ||
await this.addEmitter(emitter, ePosition); | ||
}); | ||
@@ -121,5 +123,5 @@ } | ||
removeEmitter(emitter) { | ||
const index = this.array.indexOf(emitter); | ||
if (index >= 0) { | ||
this.array.splice(index, 1); | ||
const index = this.array.indexOf(emitter), minIndex = 0, deleteCount = 1; | ||
if (index >= minIndex) { | ||
this.array.splice(index, deleteCount); | ||
} | ||
@@ -126,0 +128,0 @@ } |
@@ -68,6 +68,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if ((0, engine_1.isArray)(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -87,3 +88,3 @@ }, | ||
random: { | ||
count: emitterMode.random.count ?? 1, | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
@@ -90,0 +91,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
462462
4470
Updated@tsparticles/engine@^3.1.0