@tsparticles/plugin-emitters 3.0.0-alpha.0 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -11
- package/browser/EmitterInstance.js +99 -111
- package/browser/Emitters.js +29 -25
- package/browser/Options/Classes/Emitter.js +3 -3
- package/browser/Options/Classes/EmitterLife.js +4 -3
- package/browser/index.js +14 -17
- package/cjs/EmitterInstance.js +98 -110
- package/cjs/Emitters.js +37 -44
- package/cjs/Options/Classes/Emitter.js +2 -2
- package/cjs/Options/Classes/EmitterLife.js +4 -3
- package/cjs/Shapes/Circle/CircleShape.js +1 -1
- package/cjs/index.js +23 -37
- package/esm/EmitterInstance.js +99 -111
- package/esm/Emitters.js +29 -25
- package/esm/Options/Classes/Emitter.js +3 -3
- package/esm/Options/Classes/EmitterLife.js +4 -3
- package/esm/index.js +14 -17
- package/package.json +6 -5
- package/report.html +4 -4
- package/tsparticles.plugin.emitters.js +137 -145
- package/tsparticles.plugin.emitters.min.js +1 -1
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -8
- package/types/EmitterInstance.d.ts +7 -7
- package/types/Emitters.d.ts +1 -1
- package/types/Enums/EmitterShapeType.d.ts +3 -1
- package/types/Options/Classes/Emitter.d.ts +1 -2
- package/types/Options/Classes/EmitterLife.d.ts +3 -3
- package/types/Options/Classes/EmitterRate.d.ts +1 -1
- package/types/Options/Classes/EmitterSize.d.ts +2 -3
- package/types/Options/Interfaces/IEmitterLife.d.ts +3 -2
- package/types/Options/Interfaces/IEmitterSize.d.ts +2 -2
- package/types/Shapes/Circle/CircleShape.d.ts +1 -1
- package/types/Shapes/Square/SquareShape.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/umd/EmitterInstance.js +98 -110
- package/umd/Emitters.js +28 -24
- package/umd/Options/Classes/Emitter.js +2 -2
- package/umd/Options/Classes/EmitterLife.js +5 -4
- package/umd/index.js +13 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IDimension,
|
|
1
|
+
import type { IDimension, PixelMode } from "@tsparticles/engine";
|
|
2
2
|
export interface IEmitterSize extends IDimension {
|
|
3
|
-
mode:
|
|
3
|
+
mode: PixelMode | keyof typeof PixelMode;
|
|
4
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ICoordinates, type IDimension } from "@tsparticles/engine";
|
|
2
2
|
import type { IEmitterShape } from "../../IEmitterShape";
|
|
3
3
|
export declare class CircleShape implements IEmitterShape {
|
|
4
4
|
randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ICoordinates, type IDimension } from "@tsparticles/engine";
|
|
2
2
|
import type { IEmitterShape } from "../../IEmitterShape";
|
|
3
3
|
export declare class SquareShape implements IEmitterShape {
|
|
4
4
|
randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EmittersEngine } from "./EmittersEngine";
|
|
2
|
-
export declare function loadEmittersPlugin(engine: EmittersEngine): Promise<void>;
|
|
2
|
+
export declare function loadEmittersPlugin(engine: EmittersEngine, refresh?: boolean): Promise<void>;
|
|
3
3
|
export * from "./EmitterContainer";
|
|
4
4
|
export * from "./EmittersEngine";
|
|
5
5
|
export * from "./Enums/EmitterClickMode";
|
package/umd/EmitterInstance.js
CHANGED
|
@@ -15,10 +15,77 @@
|
|
|
15
15
|
const EmitterSize_1 = require("./Options/Classes/EmitterSize");
|
|
16
16
|
class EmitterInstance {
|
|
17
17
|
constructor(engine, emitters, container, options, position) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
|
-
var _h;
|
|
20
18
|
this.emitters = emitters;
|
|
21
19
|
this.container = container;
|
|
20
|
+
this._calcPosition = () => {
|
|
21
|
+
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
22
|
+
size: this.container.canvas.size,
|
|
23
|
+
position: this.options.position,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
this._destroy = () => {
|
|
27
|
+
this.emitters.removeEmitter(this);
|
|
28
|
+
this._engine.dispatchEvent("emitterDestroyed", {
|
|
29
|
+
container: this.container,
|
|
30
|
+
data: {
|
|
31
|
+
emitter: this,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
this._emit = () => {
|
|
36
|
+
if (this._paused) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
|
|
40
|
+
this._emitParticles(quantity);
|
|
41
|
+
};
|
|
42
|
+
this._emitParticles = (quantity) => {
|
|
43
|
+
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
|
|
44
|
+
for (let i = 0; i < quantity; i++) {
|
|
45
|
+
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
|
|
46
|
+
if (this.spawnColor) {
|
|
47
|
+
const hslAnimation = this.options.spawnColor?.animation;
|
|
48
|
+
if (hslAnimation) {
|
|
49
|
+
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
50
|
+
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
51
|
+
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
52
|
+
}
|
|
53
|
+
if (!particlesOptions.color) {
|
|
54
|
+
particlesOptions.color = {
|
|
55
|
+
value: this.spawnColor,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
particlesOptions.color.value = this.spawnColor;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!position) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
|
|
66
|
+
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this._prepareToDie = () => {
|
|
70
|
+
if (this._paused) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined;
|
|
74
|
+
if (this.container.retina.reduceFactor &&
|
|
75
|
+
(this._lifeCount > 0 || this._immortal) &&
|
|
76
|
+
duration !== undefined &&
|
|
77
|
+
duration > 0) {
|
|
78
|
+
this._duration = duration * 1000;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
this._setColorAnimation = (animation, initValue, maxValue) => {
|
|
82
|
+
const container = this.container;
|
|
83
|
+
if (!animation.enable) {
|
|
84
|
+
return initValue;
|
|
85
|
+
}
|
|
86
|
+
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);
|
|
87
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
|
|
88
|
+
};
|
|
22
89
|
this._engine = engine;
|
|
23
90
|
this._currentDuration = 0;
|
|
24
91
|
this._currentEmitDelay = 0;
|
|
@@ -31,33 +98,34 @@
|
|
|
31
98
|
this.options = new Emitter_1.Emitter();
|
|
32
99
|
this.options.load(options);
|
|
33
100
|
}
|
|
34
|
-
this._spawnDelay = (((
|
|
35
|
-
this.position =
|
|
101
|
+
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
102
|
+
this.position = this._initialPosition ?? this._calcPosition();
|
|
36
103
|
this.name = this.options.name;
|
|
37
|
-
this._shape =
|
|
104
|
+
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
|
|
38
105
|
this.fill = this.options.fill;
|
|
39
106
|
this._firstSpawn = !this.options.life.wait;
|
|
40
107
|
this._startParticlesAdded = false;
|
|
41
108
|
let particlesOptions = (0, engine_1.deepExtend)({}, this.options.particles);
|
|
42
|
-
particlesOptions
|
|
43
|
-
|
|
44
|
-
|
|
109
|
+
particlesOptions ??= {};
|
|
110
|
+
particlesOptions.move ??= {};
|
|
111
|
+
particlesOptions.move.direction ??= this.options.direction;
|
|
45
112
|
if (this.options.spawnColor) {
|
|
46
113
|
this.spawnColor = (0, engine_1.rangeColorToHsl)(this.options.spawnColor);
|
|
47
114
|
}
|
|
48
115
|
this._paused = !this.options.autoPlay;
|
|
49
116
|
this._particlesOptions = particlesOptions;
|
|
50
117
|
this.size =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
118
|
+
this.options.size ??
|
|
119
|
+
(() => {
|
|
120
|
+
const size = new EmitterSize_1.EmitterSize();
|
|
121
|
+
size.load({
|
|
122
|
+
height: 0,
|
|
123
|
+
mode: "percent",
|
|
124
|
+
width: 0,
|
|
125
|
+
});
|
|
126
|
+
return size;
|
|
127
|
+
})();
|
|
128
|
+
this._lifeCount = this.options.life.count ?? -1;
|
|
61
129
|
this._immortal = this._lifeCount <= 0;
|
|
62
130
|
this._engine.dispatchEvent("emitterCreated", {
|
|
63
131
|
container,
|
|
@@ -100,14 +168,7 @@
|
|
|
100
168
|
};
|
|
101
169
|
}
|
|
102
170
|
}
|
|
103
|
-
return
|
|
104
|
-
width: this.size.mode === "percent"
|
|
105
|
-
? (container.canvas.size.width * this.size.width) / 100
|
|
106
|
-
: this.size.width,
|
|
107
|
-
height: this.size.mode === "percent"
|
|
108
|
-
? (container.canvas.size.height * this.size.height) / 100
|
|
109
|
-
: this.size.height,
|
|
110
|
-
};
|
|
171
|
+
return (0, engine_1.getSize)(this.size, container.canvas.size);
|
|
111
172
|
}
|
|
112
173
|
pause() {
|
|
113
174
|
if (this._paused) {
|
|
@@ -116,13 +177,12 @@
|
|
|
116
177
|
delete this._emitDelay;
|
|
117
178
|
}
|
|
118
179
|
play() {
|
|
119
|
-
var _a;
|
|
120
180
|
if (this._paused) {
|
|
121
181
|
return;
|
|
122
182
|
}
|
|
123
183
|
if (!(this.container.retina.reduceFactor &&
|
|
124
184
|
(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
|
|
125
|
-
(this._firstSpawn || this._currentSpawnDelay >= (
|
|
185
|
+
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
|
|
126
186
|
return;
|
|
127
187
|
}
|
|
128
188
|
if (this._emitDelay === undefined) {
|
|
@@ -130,7 +190,7 @@
|
|
|
130
190
|
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
|
|
131
191
|
}
|
|
132
192
|
if (this._lifeCount > 0 || this._immortal) {
|
|
133
|
-
this.
|
|
193
|
+
this._prepareToDie();
|
|
134
194
|
}
|
|
135
195
|
}
|
|
136
196
|
resize() {
|
|
@@ -138,21 +198,20 @@
|
|
|
138
198
|
this.position =
|
|
139
199
|
initialPosition && (0, engine_1.isPointInside)(initialPosition, this.container.canvas.size, engine_1.Vector.origin)
|
|
140
200
|
? initialPosition
|
|
141
|
-
: this.
|
|
201
|
+
: this._calcPosition();
|
|
142
202
|
}
|
|
143
203
|
update(delta) {
|
|
144
|
-
var _a, _b, _c;
|
|
145
204
|
if (this._paused) {
|
|
146
205
|
return;
|
|
147
206
|
}
|
|
148
207
|
if (this._firstSpawn) {
|
|
149
208
|
this._firstSpawn = false;
|
|
150
|
-
this._currentSpawnDelay =
|
|
151
|
-
this._currentEmitDelay =
|
|
209
|
+
this._currentSpawnDelay = this._spawnDelay ?? 0;
|
|
210
|
+
this._currentEmitDelay = this._emitDelay ?? 0;
|
|
152
211
|
}
|
|
153
212
|
if (!this._startParticlesAdded) {
|
|
154
213
|
this._startParticlesAdded = true;
|
|
155
|
-
this.
|
|
214
|
+
this._emitParticles(this.options.startCount);
|
|
156
215
|
}
|
|
157
216
|
if (this._duration !== undefined) {
|
|
158
217
|
this._currentDuration += delta.value;
|
|
@@ -165,11 +224,12 @@
|
|
|
165
224
|
this._lifeCount--;
|
|
166
225
|
}
|
|
167
226
|
if (this._lifeCount > 0 || this._immortal) {
|
|
168
|
-
this.position = this.
|
|
169
|
-
this._spawnDelay =
|
|
227
|
+
this.position = this._calcPosition();
|
|
228
|
+
this._spawnDelay =
|
|
229
|
+
((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
170
230
|
}
|
|
171
231
|
else {
|
|
172
|
-
this.
|
|
232
|
+
this._destroy();
|
|
173
233
|
}
|
|
174
234
|
this._currentDuration -= this._duration;
|
|
175
235
|
delete this._duration;
|
|
@@ -189,83 +249,11 @@
|
|
|
189
249
|
if (this._emitDelay !== undefined) {
|
|
190
250
|
this._currentEmitDelay += delta.value;
|
|
191
251
|
if (this._currentEmitDelay >= this._emitDelay) {
|
|
192
|
-
this.
|
|
252
|
+
this._emit();
|
|
193
253
|
this._currentEmitDelay -= this._emitDelay;
|
|
194
254
|
}
|
|
195
255
|
}
|
|
196
256
|
}
|
|
197
|
-
calcPosition() {
|
|
198
|
-
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
199
|
-
size: this.container.canvas.size,
|
|
200
|
-
position: this.options.position,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
destroy() {
|
|
204
|
-
this.emitters.removeEmitter(this);
|
|
205
|
-
this._engine.dispatchEvent("emitterDestroyed", {
|
|
206
|
-
container: this.container,
|
|
207
|
-
data: {
|
|
208
|
-
emitter: this,
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
emit() {
|
|
213
|
-
if (this._paused) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
|
|
217
|
-
this.emitParticles(quantity);
|
|
218
|
-
}
|
|
219
|
-
emitParticles(quantity) {
|
|
220
|
-
var _a, _b, _c;
|
|
221
|
-
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
|
|
222
|
-
for (let i = 0; i < quantity; i++) {
|
|
223
|
-
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
|
|
224
|
-
if (this.spawnColor) {
|
|
225
|
-
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
|
|
226
|
-
if (hslAnimation) {
|
|
227
|
-
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
228
|
-
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
229
|
-
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
230
|
-
}
|
|
231
|
-
if (!particlesOptions.color) {
|
|
232
|
-
particlesOptions.color = {
|
|
233
|
-
value: this.spawnColor,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
particlesOptions.color.value = this.spawnColor;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (!position) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
|
|
244
|
-
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
prepareToDie() {
|
|
248
|
-
var _a;
|
|
249
|
-
if (this._paused) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
|
|
253
|
-
if (this.container.retina.reduceFactor &&
|
|
254
|
-
(this._lifeCount > 0 || this._immortal) &&
|
|
255
|
-
duration !== undefined &&
|
|
256
|
-
duration > 0) {
|
|
257
|
-
this._duration = duration * 1000;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
setColorAnimation(animation, initValue, maxValue) {
|
|
261
|
-
var _a;
|
|
262
|
-
const container = this.container;
|
|
263
|
-
if (!animation.enable) {
|
|
264
|
-
return initValue;
|
|
265
|
-
}
|
|
266
|
-
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);
|
|
267
|
-
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
|
|
268
|
-
}
|
|
269
257
|
}
|
|
270
258
|
exports.EmitterInstance = EmitterInstance;
|
|
271
259
|
});
|
package/umd/Emitters.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
value: [],
|
|
28
28
|
};
|
|
29
|
-
container.getEmitter = (idxOrName) => idxOrName === undefined ||
|
|
29
|
+
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
|
|
30
30
|
? this.array[idxOrName || 0]
|
|
31
31
|
: this.array.find((t) => t.name === idxOrName);
|
|
32
32
|
container.addEmitter = (options, position) => this.addEmitter(options, position);
|
|
@@ -58,39 +58,43 @@
|
|
|
58
58
|
}
|
|
59
59
|
handleClickMode(mode) {
|
|
60
60
|
const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
|
|
61
|
-
if (mode
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
|
|
61
|
+
if (mode !== "emitter") {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let emittersModeOptions;
|
|
65
|
+
if (modeEmitters && (0, engine_1.isArray)(modeEmitters.value)) {
|
|
66
|
+
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
|
|
67
|
+
emittersModeOptions = [];
|
|
68
|
+
const usedIndexes = [];
|
|
69
|
+
for (let i = 0; i < modeEmitters.random.count; i++) {
|
|
70
|
+
const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
|
|
71
|
+
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
|
|
72
|
+
i--;
|
|
73
|
+
continue;
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
emittersModeOptions = modeEmitters.value;
|
|
75
|
+
usedIndexes.push(idx);
|
|
76
|
+
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
else {
|
|
82
|
-
emittersModeOptions = modeEmitters
|
|
80
|
+
emittersModeOptions = modeEmitters.value;
|
|
83
81
|
}
|
|
84
|
-
const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
|
|
85
|
-
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
|
|
86
|
-
this.addEmitter(emitter, ePosition);
|
|
87
|
-
});
|
|
88
82
|
}
|
|
83
|
+
else {
|
|
84
|
+
emittersModeOptions = modeEmitters?.value;
|
|
85
|
+
}
|
|
86
|
+
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
|
|
87
|
+
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
|
|
88
|
+
this.addEmitter(emitter, ePosition);
|
|
89
|
+
});
|
|
89
90
|
}
|
|
90
91
|
async init() {
|
|
91
92
|
this.emitters = this.container.actualOptions.emitters;
|
|
92
93
|
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
|
|
93
|
-
if (this.emitters
|
|
94
|
+
if (!this.emitters) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if ((0, engine_1.isArray)(this.emitters)) {
|
|
94
98
|
for (const emitterOptions of this.emitters) {
|
|
95
99
|
this.addEmitter(emitterOptions);
|
|
96
100
|
}
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
this.startCount = 0;
|
|
25
25
|
}
|
|
26
26
|
load(data) {
|
|
27
|
-
if (data
|
|
27
|
+
if (!data) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
if (data.autoPlay !== undefined) {
|
|
31
31
|
this.autoPlay = data.autoPlay;
|
|
32
32
|
}
|
|
33
33
|
if (data.size !== undefined) {
|
|
34
|
-
if (this.size
|
|
34
|
+
if (!this.size) {
|
|
35
35
|
this.size = new EmitterSize_1.EmitterSize();
|
|
36
36
|
}
|
|
37
37
|
this.size.load(data.size);
|
|
@@ -4,28 +4,29 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EmitterLife = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
13
14
|
class EmitterLife {
|
|
14
15
|
constructor() {
|
|
15
16
|
this.wait = false;
|
|
16
17
|
}
|
|
17
18
|
load(data) {
|
|
18
|
-
if (data
|
|
19
|
+
if (!data) {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
if (data.count !== undefined) {
|
|
22
23
|
this.count = data.count;
|
|
23
24
|
}
|
|
24
25
|
if (data.delay !== undefined) {
|
|
25
|
-
this.delay = data.delay;
|
|
26
|
+
this.delay = (0, engine_1.setRangeValue)(data.delay);
|
|
26
27
|
}
|
|
27
28
|
if (data.duration !== undefined) {
|
|
28
|
-
this.duration = data.duration;
|
|
29
|
+
this.duration = (0, engine_1.setRangeValue)(data.duration);
|
|
29
30
|
}
|
|
30
31
|
if (data.wait !== undefined) {
|
|
31
32
|
this.wait = data.wait;
|
package/umd/index.js
CHANGED
|
@@ -39,20 +39,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
39
39
|
return new Emitters_1.Emitters(this._engine, container);
|
|
40
40
|
}
|
|
41
41
|
loadOptions(options, source) {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f;
|
|
43
42
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
44
43
|
return;
|
|
45
44
|
}
|
|
46
|
-
if (source
|
|
45
|
+
if (source?.emitters) {
|
|
47
46
|
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {
|
|
48
47
|
const tmp = new Emitter_1.Emitter();
|
|
49
48
|
tmp.load(emitter);
|
|
50
49
|
return tmp;
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
|
-
const interactivityEmitters =
|
|
52
|
+
const interactivityEmitters = source?.interactivity?.modes?.emitters;
|
|
54
53
|
if (interactivityEmitters) {
|
|
55
|
-
if (
|
|
54
|
+
if ((0, engine_1.isArray)(interactivityEmitters)) {
|
|
56
55
|
options.interactivity.modes.emitters = {
|
|
57
56
|
random: {
|
|
58
57
|
count: 1,
|
|
@@ -68,11 +67,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
68
67
|
else {
|
|
69
68
|
const emitterMode = interactivityEmitters;
|
|
70
69
|
if (emitterMode.value !== undefined) {
|
|
71
|
-
if (emitterMode.value
|
|
70
|
+
if ((0, engine_1.isArray)(emitterMode.value)) {
|
|
72
71
|
options.interactivity.modes.emitters = {
|
|
73
72
|
random: {
|
|
74
|
-
count:
|
|
75
|
-
enable:
|
|
73
|
+
count: emitterMode.random.count ?? 1,
|
|
74
|
+
enable: emitterMode.random.enable ?? false,
|
|
76
75
|
},
|
|
77
76
|
value: emitterMode.value.map((s) => {
|
|
78
77
|
const tmp = new Emitter_1.Emitter();
|
|
@@ -86,8 +85,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
86
85
|
tmp.load(emitterMode.value);
|
|
87
86
|
options.interactivity.modes.emitters = {
|
|
88
87
|
random: {
|
|
89
|
-
count:
|
|
90
|
-
enable:
|
|
88
|
+
count: emitterMode.random.count ?? 1,
|
|
89
|
+
enable: emitterMode.random.enable ?? false,
|
|
91
90
|
},
|
|
92
91
|
value: tmp,
|
|
93
92
|
};
|
|
@@ -107,29 +106,27 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
108
|
needsPlugin(options) {
|
|
110
|
-
var _a, _b, _c;
|
|
111
109
|
if (!options) {
|
|
112
110
|
return false;
|
|
113
111
|
}
|
|
114
112
|
const emitters = options.emitters;
|
|
115
|
-
return ((emitters
|
|
113
|
+
return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
|
|
116
114
|
emitters !== undefined ||
|
|
117
|
-
(!!
|
|
115
|
+
(!!options.interactivity?.events?.onClick?.mode &&
|
|
118
116
|
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
async function loadEmittersPlugin(engine) {
|
|
119
|
+
async function loadEmittersPlugin(engine, refresh = true) {
|
|
122
120
|
if (!engine.emitterShapeManager) {
|
|
123
121
|
engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);
|
|
124
122
|
}
|
|
125
123
|
if (!engine.addEmitterShape) {
|
|
126
124
|
engine.addEmitterShape = (name, shape) => {
|
|
127
|
-
|
|
128
|
-
(_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
|
|
125
|
+
engine.emitterShapeManager?.addShape(name, shape);
|
|
129
126
|
};
|
|
130
127
|
}
|
|
131
128
|
const plugin = new EmittersPlugin(engine);
|
|
132
|
-
await engine.addPlugin(plugin);
|
|
129
|
+
await engine.addPlugin(plugin, refresh);
|
|
133
130
|
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
|
|
134
131
|
engine.addEmitterShape("square", new SquareShape_1.SquareShape());
|
|
135
132
|
}
|