@tsparticles/plugin-emitters 3.0.0-alpha.1 → 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
package/cjs/EmitterInstance.js
CHANGED
|
@@ -6,10 +6,77 @@ const Emitter_1 = require("./Options/Classes/Emitter");
|
|
|
6
6
|
const EmitterSize_1 = require("./Options/Classes/EmitterSize");
|
|
7
7
|
class EmitterInstance {
|
|
8
8
|
constructor(engine, emitters, container, options, position) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
|
-
var _h;
|
|
11
9
|
this.emitters = emitters;
|
|
12
10
|
this.container = container;
|
|
11
|
+
this._calcPosition = () => {
|
|
12
|
+
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
13
|
+
size: this.container.canvas.size,
|
|
14
|
+
position: this.options.position,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
this._destroy = () => {
|
|
18
|
+
this.emitters.removeEmitter(this);
|
|
19
|
+
this._engine.dispatchEvent("emitterDestroyed", {
|
|
20
|
+
container: this.container,
|
|
21
|
+
data: {
|
|
22
|
+
emitter: this,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
this._emit = () => {
|
|
27
|
+
if (this._paused) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
|
|
31
|
+
this._emitParticles(quantity);
|
|
32
|
+
};
|
|
33
|
+
this._emitParticles = (quantity) => {
|
|
34
|
+
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
|
|
35
|
+
for (let i = 0; i < quantity; i++) {
|
|
36
|
+
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
|
|
37
|
+
if (this.spawnColor) {
|
|
38
|
+
const hslAnimation = this.options.spawnColor?.animation;
|
|
39
|
+
if (hslAnimation) {
|
|
40
|
+
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
41
|
+
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
42
|
+
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
43
|
+
}
|
|
44
|
+
if (!particlesOptions.color) {
|
|
45
|
+
particlesOptions.color = {
|
|
46
|
+
value: this.spawnColor,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
particlesOptions.color.value = this.spawnColor;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!position) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
|
|
57
|
+
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this._prepareToDie = () => {
|
|
61
|
+
if (this._paused) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const duration = this.options.life?.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined;
|
|
65
|
+
if (this.container.retina.reduceFactor &&
|
|
66
|
+
(this._lifeCount > 0 || this._immortal) &&
|
|
67
|
+
duration !== undefined &&
|
|
68
|
+
duration > 0) {
|
|
69
|
+
this._duration = duration * 1000;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
this._setColorAnimation = (animation, initValue, maxValue) => {
|
|
73
|
+
const container = this.container;
|
|
74
|
+
if (!animation.enable) {
|
|
75
|
+
return initValue;
|
|
76
|
+
}
|
|
77
|
+
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);
|
|
78
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
|
|
79
|
+
};
|
|
13
80
|
this._engine = engine;
|
|
14
81
|
this._currentDuration = 0;
|
|
15
82
|
this._currentEmitDelay = 0;
|
|
@@ -22,33 +89,34 @@ class EmitterInstance {
|
|
|
22
89
|
this.options = new Emitter_1.Emitter();
|
|
23
90
|
this.options.load(options);
|
|
24
91
|
}
|
|
25
|
-
this._spawnDelay = (((
|
|
26
|
-
this.position =
|
|
92
|
+
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
93
|
+
this.position = this._initialPosition ?? this._calcPosition();
|
|
27
94
|
this.name = this.options.name;
|
|
28
|
-
this._shape =
|
|
95
|
+
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
|
|
29
96
|
this.fill = this.options.fill;
|
|
30
97
|
this._firstSpawn = !this.options.life.wait;
|
|
31
98
|
this._startParticlesAdded = false;
|
|
32
99
|
let particlesOptions = (0, engine_1.deepExtend)({}, this.options.particles);
|
|
33
|
-
particlesOptions
|
|
34
|
-
|
|
35
|
-
|
|
100
|
+
particlesOptions ??= {};
|
|
101
|
+
particlesOptions.move ??= {};
|
|
102
|
+
particlesOptions.move.direction ??= this.options.direction;
|
|
36
103
|
if (this.options.spawnColor) {
|
|
37
104
|
this.spawnColor = (0, engine_1.rangeColorToHsl)(this.options.spawnColor);
|
|
38
105
|
}
|
|
39
106
|
this._paused = !this.options.autoPlay;
|
|
40
107
|
this._particlesOptions = particlesOptions;
|
|
41
108
|
this.size =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
109
|
+
this.options.size ??
|
|
110
|
+
(() => {
|
|
111
|
+
const size = new EmitterSize_1.EmitterSize();
|
|
112
|
+
size.load({
|
|
113
|
+
height: 0,
|
|
114
|
+
mode: "percent",
|
|
115
|
+
width: 0,
|
|
116
|
+
});
|
|
117
|
+
return size;
|
|
118
|
+
})();
|
|
119
|
+
this._lifeCount = this.options.life.count ?? -1;
|
|
52
120
|
this._immortal = this._lifeCount <= 0;
|
|
53
121
|
this._engine.dispatchEvent("emitterCreated", {
|
|
54
122
|
container,
|
|
@@ -91,14 +159,7 @@ class EmitterInstance {
|
|
|
91
159
|
};
|
|
92
160
|
}
|
|
93
161
|
}
|
|
94
|
-
return
|
|
95
|
-
width: this.size.mode === "percent"
|
|
96
|
-
? (container.canvas.size.width * this.size.width) / 100
|
|
97
|
-
: this.size.width,
|
|
98
|
-
height: this.size.mode === "percent"
|
|
99
|
-
? (container.canvas.size.height * this.size.height) / 100
|
|
100
|
-
: this.size.height,
|
|
101
|
-
};
|
|
162
|
+
return (0, engine_1.getSize)(this.size, container.canvas.size);
|
|
102
163
|
}
|
|
103
164
|
pause() {
|
|
104
165
|
if (this._paused) {
|
|
@@ -107,13 +168,12 @@ class EmitterInstance {
|
|
|
107
168
|
delete this._emitDelay;
|
|
108
169
|
}
|
|
109
170
|
play() {
|
|
110
|
-
var _a;
|
|
111
171
|
if (this._paused) {
|
|
112
172
|
return;
|
|
113
173
|
}
|
|
114
174
|
if (!(this.container.retina.reduceFactor &&
|
|
115
175
|
(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
|
|
116
|
-
(this._firstSpawn || this._currentSpawnDelay >= (
|
|
176
|
+
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
|
|
117
177
|
return;
|
|
118
178
|
}
|
|
119
179
|
if (this._emitDelay === undefined) {
|
|
@@ -121,7 +181,7 @@ class EmitterInstance {
|
|
|
121
181
|
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
|
|
122
182
|
}
|
|
123
183
|
if (this._lifeCount > 0 || this._immortal) {
|
|
124
|
-
this.
|
|
184
|
+
this._prepareToDie();
|
|
125
185
|
}
|
|
126
186
|
}
|
|
127
187
|
resize() {
|
|
@@ -129,21 +189,20 @@ class EmitterInstance {
|
|
|
129
189
|
this.position =
|
|
130
190
|
initialPosition && (0, engine_1.isPointInside)(initialPosition, this.container.canvas.size, engine_1.Vector.origin)
|
|
131
191
|
? initialPosition
|
|
132
|
-
: this.
|
|
192
|
+
: this._calcPosition();
|
|
133
193
|
}
|
|
134
194
|
update(delta) {
|
|
135
|
-
var _a, _b, _c;
|
|
136
195
|
if (this._paused) {
|
|
137
196
|
return;
|
|
138
197
|
}
|
|
139
198
|
if (this._firstSpawn) {
|
|
140
199
|
this._firstSpawn = false;
|
|
141
|
-
this._currentSpawnDelay =
|
|
142
|
-
this._currentEmitDelay =
|
|
200
|
+
this._currentSpawnDelay = this._spawnDelay ?? 0;
|
|
201
|
+
this._currentEmitDelay = this._emitDelay ?? 0;
|
|
143
202
|
}
|
|
144
203
|
if (!this._startParticlesAdded) {
|
|
145
204
|
this._startParticlesAdded = true;
|
|
146
|
-
this.
|
|
205
|
+
this._emitParticles(this.options.startCount);
|
|
147
206
|
}
|
|
148
207
|
if (this._duration !== undefined) {
|
|
149
208
|
this._currentDuration += delta.value;
|
|
@@ -156,11 +215,12 @@ class EmitterInstance {
|
|
|
156
215
|
this._lifeCount--;
|
|
157
216
|
}
|
|
158
217
|
if (this._lifeCount > 0 || this._immortal) {
|
|
159
|
-
this.position = this.
|
|
160
|
-
this._spawnDelay =
|
|
218
|
+
this.position = this._calcPosition();
|
|
219
|
+
this._spawnDelay =
|
|
220
|
+
((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
161
221
|
}
|
|
162
222
|
else {
|
|
163
|
-
this.
|
|
223
|
+
this._destroy();
|
|
164
224
|
}
|
|
165
225
|
this._currentDuration -= this._duration;
|
|
166
226
|
delete this._duration;
|
|
@@ -180,82 +240,10 @@ class EmitterInstance {
|
|
|
180
240
|
if (this._emitDelay !== undefined) {
|
|
181
241
|
this._currentEmitDelay += delta.value;
|
|
182
242
|
if (this._currentEmitDelay >= this._emitDelay) {
|
|
183
|
-
this.
|
|
243
|
+
this._emit();
|
|
184
244
|
this._currentEmitDelay -= this._emitDelay;
|
|
185
245
|
}
|
|
186
246
|
}
|
|
187
247
|
}
|
|
188
|
-
calcPosition() {
|
|
189
|
-
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
190
|
-
size: this.container.canvas.size,
|
|
191
|
-
position: this.options.position,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
destroy() {
|
|
195
|
-
this.emitters.removeEmitter(this);
|
|
196
|
-
this._engine.dispatchEvent("emitterDestroyed", {
|
|
197
|
-
container: this.container,
|
|
198
|
-
data: {
|
|
199
|
-
emitter: this,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
emit() {
|
|
204
|
-
if (this._paused) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
|
|
208
|
-
this.emitParticles(quantity);
|
|
209
|
-
}
|
|
210
|
-
emitParticles(quantity) {
|
|
211
|
-
var _a, _b, _c;
|
|
212
|
-
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
|
|
213
|
-
for (let i = 0; i < quantity; i++) {
|
|
214
|
-
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
|
|
215
|
-
if (this.spawnColor) {
|
|
216
|
-
const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
|
|
217
|
-
if (hslAnimation) {
|
|
218
|
-
this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
219
|
-
this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
220
|
-
this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
221
|
-
}
|
|
222
|
-
if (!particlesOptions.color) {
|
|
223
|
-
particlesOptions.color = {
|
|
224
|
-
value: this.spawnColor,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
particlesOptions.color.value = this.spawnColor;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (!position) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
|
|
235
|
-
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
prepareToDie() {
|
|
239
|
-
var _a;
|
|
240
|
-
if (this._paused) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
|
|
244
|
-
if (this.container.retina.reduceFactor &&
|
|
245
|
-
(this._lifeCount > 0 || this._immortal) &&
|
|
246
|
-
duration !== undefined &&
|
|
247
|
-
duration > 0) {
|
|
248
|
-
this._duration = duration * 1000;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
setColorAnimation(animation, initValue, maxValue) {
|
|
252
|
-
var _a;
|
|
253
|
-
const container = this.container;
|
|
254
|
-
if (!animation.enable) {
|
|
255
|
-
return initValue;
|
|
256
|
-
}
|
|
257
|
-
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);
|
|
258
|
-
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
|
|
259
|
-
}
|
|
260
248
|
}
|
|
261
249
|
exports.EmitterInstance = EmitterInstance;
|
package/cjs/Emitters.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.Emitters = void 0;
|
|
13
4
|
const engine_1 = require("@tsparticles/engine");
|
|
@@ -26,7 +17,7 @@ class Emitters {
|
|
|
26
17
|
},
|
|
27
18
|
value: [],
|
|
28
19
|
};
|
|
29
|
-
container.getEmitter = (idxOrName) => idxOrName === undefined ||
|
|
20
|
+
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
|
|
30
21
|
? this.array[idxOrName || 0]
|
|
31
22
|
: this.array.find((t) => t.name === idxOrName);
|
|
32
23
|
container.addEmitter = (options, position) => this.addEmitter(options, position);
|
|
@@ -58,48 +49,50 @@ class Emitters {
|
|
|
58
49
|
}
|
|
59
50
|
handleClickMode(mode) {
|
|
60
51
|
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));
|
|
52
|
+
if (mode !== "emitter") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let emittersModeOptions;
|
|
56
|
+
if (modeEmitters && (0, engine_1.isArray)(modeEmitters.value)) {
|
|
57
|
+
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
|
|
58
|
+
emittersModeOptions = [];
|
|
59
|
+
const usedIndexes = [];
|
|
60
|
+
for (let i = 0; i < modeEmitters.random.count; i++) {
|
|
61
|
+
const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
|
|
62
|
+
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
|
|
63
|
+
i--;
|
|
64
|
+
continue;
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
emittersModeOptions = modeEmitters.value;
|
|
66
|
+
usedIndexes.push(idx);
|
|
67
|
+
emittersModeOptions.push((0, engine_1.itemFromArray)(modeEmitters.value, idx));
|
|
79
68
|
}
|
|
80
69
|
}
|
|
81
70
|
else {
|
|
82
|
-
emittersModeOptions = modeEmitters
|
|
71
|
+
emittersModeOptions = modeEmitters.value;
|
|
83
72
|
}
|
|
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
73
|
}
|
|
74
|
+
else {
|
|
75
|
+
emittersModeOptions = modeEmitters?.value;
|
|
76
|
+
}
|
|
77
|
+
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
|
|
78
|
+
(0, engine_1.executeOnSingleOrMultiple)(emittersOptions, (emitter) => {
|
|
79
|
+
this.addEmitter(emitter, ePosition);
|
|
80
|
+
});
|
|
89
81
|
}
|
|
90
|
-
init() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
else {
|
|
100
|
-
this.addEmitter(this.emitters);
|
|
82
|
+
async init() {
|
|
83
|
+
this.emitters = this.container.actualOptions.emitters;
|
|
84
|
+
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
|
|
85
|
+
if (!this.emitters) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if ((0, engine_1.isArray)(this.emitters)) {
|
|
89
|
+
for (const emitterOptions of this.emitters) {
|
|
90
|
+
this.addEmitter(emitterOptions);
|
|
101
91
|
}
|
|
102
|
-
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.addEmitter(this.emitters);
|
|
95
|
+
}
|
|
103
96
|
}
|
|
104
97
|
pause() {
|
|
105
98
|
for (const emitter of this.array) {
|
|
@@ -15,14 +15,14 @@ class Emitter {
|
|
|
15
15
|
this.startCount = 0;
|
|
16
16
|
}
|
|
17
17
|
load(data) {
|
|
18
|
-
if (data
|
|
18
|
+
if (!data) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
if (data.autoPlay !== undefined) {
|
|
22
22
|
this.autoPlay = data.autoPlay;
|
|
23
23
|
}
|
|
24
24
|
if (data.size !== undefined) {
|
|
25
|
-
if (this.size
|
|
25
|
+
if (!this.size) {
|
|
26
26
|
this.size = new EmitterSize_1.EmitterSize();
|
|
27
27
|
}
|
|
28
28
|
this.size.load(data.size);
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmitterLife = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
4
5
|
class EmitterLife {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.wait = false;
|
|
7
8
|
}
|
|
8
9
|
load(data) {
|
|
9
|
-
if (data
|
|
10
|
+
if (!data) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
if (data.count !== undefined) {
|
|
13
14
|
this.count = data.count;
|
|
14
15
|
}
|
|
15
16
|
if (data.delay !== undefined) {
|
|
16
|
-
this.delay = data.delay;
|
|
17
|
+
this.delay = (0, engine_1.setRangeValue)(data.delay);
|
|
17
18
|
}
|
|
18
19
|
if (data.duration !== undefined) {
|
|
19
|
-
this.duration = data.duration;
|
|
20
|
+
this.duration = (0, engine_1.setRangeValue)(data.duration);
|
|
20
21
|
}
|
|
21
22
|
if (data.wait !== undefined) {
|
|
22
23
|
this.wait = data.wait;
|
|
@@ -18,7 +18,7 @@ class CircleShape {
|
|
|
18
18
|
else {
|
|
19
19
|
return -theta;
|
|
20
20
|
}
|
|
21
|
-
}, radius = (x, y, theta) => (x * y) / Math.sqrt(
|
|
21
|
+
}, 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;
|
|
22
22
|
return {
|
|
23
23
|
x: position.x + randomRadius * Math.cos(randomTheta),
|
|
24
24
|
y: position.y + randomRadius * Math.sin(randomTheta),
|
package/cjs/index.js
CHANGED
|
@@ -13,15 +13,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
17
|
exports.loadEmittersPlugin = void 0;
|
|
27
18
|
const engine_1 = require("@tsparticles/engine");
|
|
@@ -39,20 +30,19 @@ class EmittersPlugin {
|
|
|
39
30
|
return new Emitters_1.Emitters(this._engine, container);
|
|
40
31
|
}
|
|
41
32
|
loadOptions(options, source) {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f;
|
|
43
33
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
44
34
|
return;
|
|
45
35
|
}
|
|
46
|
-
if (source
|
|
36
|
+
if (source?.emitters) {
|
|
47
37
|
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {
|
|
48
38
|
const tmp = new Emitter_1.Emitter();
|
|
49
39
|
tmp.load(emitter);
|
|
50
40
|
return tmp;
|
|
51
41
|
});
|
|
52
42
|
}
|
|
53
|
-
const interactivityEmitters =
|
|
43
|
+
const interactivityEmitters = source?.interactivity?.modes?.emitters;
|
|
54
44
|
if (interactivityEmitters) {
|
|
55
|
-
if (
|
|
45
|
+
if ((0, engine_1.isArray)(interactivityEmitters)) {
|
|
56
46
|
options.interactivity.modes.emitters = {
|
|
57
47
|
random: {
|
|
58
48
|
count: 1,
|
|
@@ -68,11 +58,11 @@ class EmittersPlugin {
|
|
|
68
58
|
else {
|
|
69
59
|
const emitterMode = interactivityEmitters;
|
|
70
60
|
if (emitterMode.value !== undefined) {
|
|
71
|
-
if (emitterMode.value
|
|
61
|
+
if ((0, engine_1.isArray)(emitterMode.value)) {
|
|
72
62
|
options.interactivity.modes.emitters = {
|
|
73
63
|
random: {
|
|
74
|
-
count:
|
|
75
|
-
enable:
|
|
64
|
+
count: emitterMode.random.count ?? 1,
|
|
65
|
+
enable: emitterMode.random.enable ?? false,
|
|
76
66
|
},
|
|
77
67
|
value: emitterMode.value.map((s) => {
|
|
78
68
|
const tmp = new Emitter_1.Emitter();
|
|
@@ -86,8 +76,8 @@ class EmittersPlugin {
|
|
|
86
76
|
tmp.load(emitterMode.value);
|
|
87
77
|
options.interactivity.modes.emitters = {
|
|
88
78
|
random: {
|
|
89
|
-
count:
|
|
90
|
-
enable:
|
|
79
|
+
count: emitterMode.random.count ?? 1,
|
|
80
|
+
enable: emitterMode.random.enable ?? false,
|
|
91
81
|
},
|
|
92
82
|
value: tmp,
|
|
93
83
|
};
|
|
@@ -107,33 +97,29 @@ class EmittersPlugin {
|
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
needsPlugin(options) {
|
|
110
|
-
var _a, _b, _c;
|
|
111
100
|
if (!options) {
|
|
112
101
|
return false;
|
|
113
102
|
}
|
|
114
103
|
const emitters = options.emitters;
|
|
115
|
-
return ((emitters
|
|
104
|
+
return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
|
|
116
105
|
emitters !== undefined ||
|
|
117
|
-
(!!
|
|
106
|
+
(!!options.interactivity?.events?.onClick?.mode &&
|
|
118
107
|
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
|
|
119
108
|
}
|
|
120
109
|
}
|
|
121
|
-
function loadEmittersPlugin(engine) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
engine.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
|
|
135
|
-
engine.addEmitterShape("square", new SquareShape_1.SquareShape());
|
|
136
|
-
});
|
|
110
|
+
async function loadEmittersPlugin(engine, refresh = true) {
|
|
111
|
+
if (!engine.emitterShapeManager) {
|
|
112
|
+
engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);
|
|
113
|
+
}
|
|
114
|
+
if (!engine.addEmitterShape) {
|
|
115
|
+
engine.addEmitterShape = (name, shape) => {
|
|
116
|
+
engine.emitterShapeManager?.addShape(name, shape);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const plugin = new EmittersPlugin(engine);
|
|
120
|
+
await engine.addPlugin(plugin, refresh);
|
|
121
|
+
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
|
|
122
|
+
engine.addEmitterShape("square", new SquareShape_1.SquareShape());
|
|
137
123
|
}
|
|
138
124
|
exports.loadEmittersPlugin = loadEmittersPlugin;
|
|
139
125
|
__exportStar(require("./EmitterContainer"), exports);
|