@tsparticles/engine 3.0.3 → 3.2.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/373.min.js +2 -0
- package/373.min.js.LICENSE.txt +1 -0
- package/438.min.js +2 -0
- package/438.min.js.LICENSE.txt +1 -0
- package/README.md +337 -216
- package/browser/Core/Canvas.js +102 -49
- package/browser/Core/Container.js +53 -41
- package/browser/Core/Engine.js +47 -32
- package/browser/Core/Particle.js +46 -48
- package/browser/Core/Particles.js +70 -57
- package/browser/Core/Retina.js +5 -4
- package/browser/Core/Utils/Circle.js +4 -3
- package/browser/Core/Utils/Constants.js +3 -0
- package/browser/Core/Utils/EventListeners.js +19 -16
- package/browser/Core/Utils/ExternalInteractorBase.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +17 -8
- package/browser/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/browser/Core/Utils/QuadTree.js +5 -3
- package/browser/Core/Utils/Vector.js +7 -2
- package/browser/Core/Utils/Vector3d.js +14 -9
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/browser/Options/Classes/ManualParticle.js +3 -2
- package/browser/Options/Classes/Options.js +3 -0
- package/browser/Utils/CanvasUtils.js +50 -40
- package/browser/Utils/ColorUtils.js +124 -45
- package/browser/Utils/EventDispatcher.js +6 -5
- package/browser/Utils/HslColorManager.js +5 -5
- package/browser/Utils/NumberUtils.js +35 -23
- package/browser/Utils/RgbColorManager.js +5 -5
- package/browser/Utils/Utils.js +102 -19
- package/cjs/Core/Canvas.js +102 -49
- package/cjs/Core/Container.js +53 -41
- package/cjs/Core/Engine.js +70 -32
- package/cjs/Core/Particle.js +45 -47
- package/cjs/Core/Particles.js +93 -57
- package/cjs/Core/Retina.js +5 -4
- package/cjs/Core/Utils/Circle.js +4 -3
- package/cjs/Core/Utils/Constants.js +4 -1
- package/cjs/Core/Utils/EventListeners.js +18 -15
- package/cjs/Core/Utils/ExternalInteractorBase.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +17 -8
- package/cjs/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/cjs/Core/Utils/QuadTree.js +5 -3
- package/cjs/Core/Utils/Vector.js +7 -2
- package/cjs/Core/Utils/Vector3d.js +14 -9
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/cjs/Options/Classes/ManualParticle.js +3 -2
- package/cjs/Options/Classes/Options.js +3 -0
- package/cjs/Utils/CanvasUtils.js +50 -40
- package/cjs/Utils/ColorUtils.js +126 -45
- package/cjs/Utils/EventDispatcher.js +6 -5
- package/cjs/Utils/HslColorManager.js +5 -5
- package/cjs/Utils/NumberUtils.js +37 -24
- package/cjs/Utils/RgbColorManager.js +5 -5
- package/cjs/Utils/Utils.js +103 -19
- package/dist_browser_Core_Container_js.js +92 -0
- package/dist_browser_Core_Particle_js.js +32 -0
- package/esm/Core/Canvas.js +102 -49
- package/esm/Core/Container.js +53 -41
- package/esm/Core/Engine.js +47 -32
- package/esm/Core/Particle.js +46 -48
- package/esm/Core/Particles.js +70 -57
- package/esm/Core/Retina.js +5 -4
- package/esm/Core/Utils/Circle.js +4 -3
- package/esm/Core/Utils/Constants.js +3 -0
- package/esm/Core/Utils/EventListeners.js +19 -16
- package/esm/Core/Utils/ExternalInteractorBase.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +17 -8
- package/esm/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/esm/Core/Utils/QuadTree.js +5 -3
- package/esm/Core/Utils/Vector.js +7 -2
- package/esm/Core/Utils/Vector3d.js +14 -9
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/esm/Options/Classes/ManualParticle.js +3 -2
- package/esm/Options/Classes/Options.js +3 -0
- package/esm/Utils/CanvasUtils.js +50 -40
- package/esm/Utils/ColorUtils.js +124 -45
- package/esm/Utils/EventDispatcher.js +6 -5
- package/esm/Utils/HslColorManager.js +5 -5
- package/esm/Utils/NumberUtils.js +35 -23
- package/esm/Utils/RgbColorManager.js +5 -5
- package/esm/Utils/Utils.js +102 -19
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +894 -5461
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +5 -3
- package/types/Core/Container.d.ts +1 -1
- package/types/Core/Engine.d.ts +13 -8
- package/types/Core/Interfaces/IContainerPlugin.d.ts +3 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
- package/types/Core/Interfaces/IParticleHslAnimation.d.ts +4 -4
- package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +4 -0
- package/types/Core/Interfaces/IPlugin.d.ts +1 -1
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -2
- package/types/Core/Interfaces/IShapeDrawer.d.ts +4 -4
- package/types/Core/Particle.d.ts +3 -3
- package/types/Core/Particles.d.ts +12 -8
- package/types/Core/Utils/Constants.d.ts +3 -0
- package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
- package/types/Core/Utils/InteractionManager.d.ts +3 -3
- package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
- package/types/Core/Utils/Point.d.ts +1 -1
- package/types/Enums/Modes/OutMode.d.ts +0 -3
- package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +2 -1
- package/types/Options/Classes/Options.d.ts +1 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +1 -2
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +5 -6
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMask.d.ts +2 -1
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.d.ts +2 -1
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +1 -3
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IOutModes.d.ts +6 -6
- package/types/Types/CustomEventArgs.d.ts +2 -2
- package/types/Types/ExportResult.d.ts +2 -2
- package/types/Types/ParticlesGroups.d.ts +1 -3
- package/types/Types/PathOptions.d.ts +1 -3
- package/types/Types/ShapeData.d.ts +1 -3
- package/types/Utils/CanvasUtils.d.ts +9 -8
- package/types/Utils/ColorUtils.d.ts +5 -0
- package/types/Utils/NumberUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +9 -6
- package/umd/Core/Canvas.js +102 -49
- package/umd/Core/Container.js +54 -42
- package/umd/Core/Engine.js +72 -33
- package/umd/Core/Particle.js +46 -48
- package/umd/Core/Particles.js +95 -58
- package/umd/Core/Retina.js +5 -4
- package/umd/Core/Utils/Circle.js +4 -3
- package/umd/Core/Utils/Constants.js +4 -1
- package/umd/Core/Utils/EventListeners.js +18 -15
- package/umd/Core/Utils/ExternalInteractorBase.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +17 -8
- package/umd/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/umd/Core/Utils/QuadTree.js +5 -3
- package/umd/Core/Utils/Vector.js +7 -2
- package/umd/Core/Utils/Vector3d.js +14 -9
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/umd/Options/Classes/ManualParticle.js +3 -2
- package/umd/Options/Classes/Options.js +3 -0
- package/umd/Utils/CanvasUtils.js +50 -40
- package/umd/Utils/ColorUtils.js +127 -46
- package/umd/Utils/EventDispatcher.js +6 -5
- package/umd/Utils/HslColorManager.js +5 -5
- package/umd/Utils/NumberUtils.js +38 -25
- package/umd/Utils/RgbColorManager.js +5 -5
- package/umd/Utils/Utils.js +104 -20
package/cjs/Core/Container.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Container = void 0;
|
|
4
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
4
5
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
5
6
|
const Canvas_js_1 = require("./Canvas.js");
|
|
6
7
|
const EventListeners_js_1 = require("./Utils/EventListeners.js");
|
|
7
8
|
const Options_js_1 = require("../Options/Classes/Options.js");
|
|
8
9
|
const Particles_js_1 = require("./Particles.js");
|
|
9
10
|
const Retina_js_1 = require("./Retina.js");
|
|
10
|
-
const Constants_js_1 = require("./Utils/Constants.js");
|
|
11
11
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
12
12
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
13
13
|
function guardCheck(container) {
|
|
14
14
|
return container && !container.destroyed;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
const defaultFps = 60;
|
|
17
|
+
function initDelta(value, fpsLimit = defaultFps, smooth = false) {
|
|
17
18
|
return {
|
|
18
19
|
value,
|
|
19
|
-
factor: smooth ?
|
|
20
|
+
factor: smooth ? defaultFps / fpsLimit : (defaultFps * value) / Constants_js_1.millisecondsToSeconds,
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
@@ -34,14 +35,19 @@ class Container {
|
|
|
34
35
|
if (entry.target !== this.interactivity.element) {
|
|
35
36
|
continue;
|
|
36
37
|
}
|
|
37
|
-
(entry.isIntersecting
|
|
38
|
+
if (entry.isIntersecting) {
|
|
39
|
+
this.play();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.pause();
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
};
|
|
40
46
|
this._nextFrame = async (timestamp) => {
|
|
41
47
|
try {
|
|
42
48
|
if (!this._smooth &&
|
|
43
49
|
this._lastFrameTime !== undefined &&
|
|
44
|
-
timestamp < this._lastFrameTime +
|
|
50
|
+
timestamp < this._lastFrameTime + Constants_js_1.millisecondsToSeconds / this.fpsLimit) {
|
|
45
51
|
this.draw(false);
|
|
46
52
|
return;
|
|
47
53
|
}
|
|
@@ -49,7 +55,7 @@ class Container {
|
|
|
49
55
|
const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
|
|
50
56
|
this.addLifeTime(delta.value);
|
|
51
57
|
this._lastFrameTime = timestamp;
|
|
52
|
-
if (delta.value >
|
|
58
|
+
if (delta.value > Constants_js_1.millisecondsToSeconds) {
|
|
53
59
|
this.draw(false);
|
|
54
60
|
return;
|
|
55
61
|
}
|
|
@@ -58,7 +64,7 @@ class Container {
|
|
|
58
64
|
this.destroy();
|
|
59
65
|
return;
|
|
60
66
|
}
|
|
61
|
-
if (this.
|
|
67
|
+
if (this.animationStatus) {
|
|
62
68
|
this.draw(false);
|
|
63
69
|
}
|
|
64
70
|
}
|
|
@@ -101,6 +107,9 @@ class Container {
|
|
|
101
107
|
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)((entries) => this._intersectionManager(entries));
|
|
102
108
|
this._engine.dispatchEvent("containerBuilt", { container: this });
|
|
103
109
|
}
|
|
110
|
+
get animationStatus() {
|
|
111
|
+
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
112
|
+
}
|
|
104
113
|
get options() {
|
|
105
114
|
return this._options;
|
|
106
115
|
}
|
|
@@ -132,8 +141,8 @@ class Container {
|
|
|
132
141
|
const mouseEvent = e, pos = {
|
|
133
142
|
x: mouseEvent.offsetX || mouseEvent.clientX,
|
|
134
143
|
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
135
|
-
};
|
|
136
|
-
clickOrTouchHandler(e, pos,
|
|
144
|
+
}, radius = 1;
|
|
145
|
+
clickOrTouchHandler(e, pos, radius);
|
|
137
146
|
};
|
|
138
147
|
const touchStartHandler = () => {
|
|
139
148
|
if (!guardCheck(this)) {
|
|
@@ -154,16 +163,17 @@ class Container {
|
|
|
154
163
|
}
|
|
155
164
|
if (touched && !touchMoved) {
|
|
156
165
|
const touchEvent = e;
|
|
157
|
-
|
|
166
|
+
const lengthOffset = 1;
|
|
167
|
+
let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
|
|
158
168
|
if (!lastTouch) {
|
|
159
|
-
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length -
|
|
169
|
+
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
|
|
160
170
|
if (!lastTouch) {
|
|
161
171
|
return;
|
|
162
172
|
}
|
|
163
173
|
}
|
|
164
|
-
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
|
|
165
|
-
x: lastTouch.clientX - (canvasRect ? canvasRect.left :
|
|
166
|
-
y: lastTouch.clientY - (canvasRect ? canvasRect.top :
|
|
174
|
+
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, minCoordinate = 0, pos = {
|
|
175
|
+
x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
|
|
176
|
+
y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
|
|
167
177
|
};
|
|
168
178
|
clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
|
|
169
179
|
}
|
|
@@ -205,10 +215,10 @@ class Container {
|
|
|
205
215
|
this.particles.destroy();
|
|
206
216
|
this.canvas.destroy();
|
|
207
217
|
for (const [, effectDrawer] of this.effectDrawers) {
|
|
208
|
-
effectDrawer.destroy
|
|
218
|
+
effectDrawer.destroy?.(this);
|
|
209
219
|
}
|
|
210
220
|
for (const [, shapeDrawer] of this.shapeDrawers) {
|
|
211
|
-
shapeDrawer.destroy
|
|
221
|
+
shapeDrawer.destroy?.(this);
|
|
212
222
|
}
|
|
213
223
|
for (const key of this.effectDrawers.keys()) {
|
|
214
224
|
this.effectDrawers.delete(key);
|
|
@@ -218,9 +228,10 @@ class Container {
|
|
|
218
228
|
}
|
|
219
229
|
this._engine.clearPlugins(this);
|
|
220
230
|
this.destroyed = true;
|
|
221
|
-
const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this);
|
|
222
|
-
if (idx >=
|
|
223
|
-
|
|
231
|
+
const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this), minIndex = 0;
|
|
232
|
+
if (idx >= minIndex) {
|
|
233
|
+
const deleteCount = 1;
|
|
234
|
+
mainArr.splice(idx, deleteCount);
|
|
224
235
|
}
|
|
225
236
|
this._engine.dispatchEvent("containerDestroyed", { container: this });
|
|
226
237
|
}
|
|
@@ -229,13 +240,14 @@ class Container {
|
|
|
229
240
|
return;
|
|
230
241
|
}
|
|
231
242
|
let refreshTime = force;
|
|
232
|
-
|
|
243
|
+
const frame = async (timestamp) => {
|
|
233
244
|
if (refreshTime) {
|
|
234
245
|
this._lastFrameTime = undefined;
|
|
235
246
|
refreshTime = false;
|
|
236
247
|
}
|
|
237
248
|
await this._nextFrame(timestamp);
|
|
238
|
-
}
|
|
249
|
+
};
|
|
250
|
+
this._drawAnimationFrame = requestAnimationFrame((timestamp) => void frame(timestamp));
|
|
239
251
|
}
|
|
240
252
|
async export(type, options = {}) {
|
|
241
253
|
for (const [, plugin] of this.plugins) {
|
|
@@ -250,16 +262,13 @@ class Container {
|
|
|
250
262
|
}
|
|
251
263
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} - Export plugin with type ${type} not found`);
|
|
252
264
|
}
|
|
253
|
-
getAnimationStatus() {
|
|
254
|
-
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
255
|
-
}
|
|
256
265
|
handleClickMode(mode) {
|
|
257
266
|
if (!guardCheck(this)) {
|
|
258
267
|
return;
|
|
259
268
|
}
|
|
260
269
|
this.particles.handleClickMode(mode);
|
|
261
270
|
for (const [, plugin] of this.plugins) {
|
|
262
|
-
plugin.handleClickMode
|
|
271
|
+
plugin.handleClickMode?.(mode);
|
|
263
272
|
}
|
|
264
273
|
}
|
|
265
274
|
async init() {
|
|
@@ -280,9 +289,10 @@ class Container {
|
|
|
280
289
|
this.shapeDrawers.set(type, drawer);
|
|
281
290
|
}
|
|
282
291
|
}
|
|
292
|
+
await this.particles.initPlugins();
|
|
283
293
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
284
294
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
285
|
-
const availablePlugins = this._engine.getAvailablePlugins(this);
|
|
295
|
+
const availablePlugins = await this._engine.getAvailablePlugins(this);
|
|
286
296
|
for (const [id, plugin] of availablePlugins) {
|
|
287
297
|
this.plugins.set(id, plugin);
|
|
288
298
|
}
|
|
@@ -292,25 +302,26 @@ class Container {
|
|
|
292
302
|
this.canvas.initBackground();
|
|
293
303
|
this.canvas.resize();
|
|
294
304
|
this.zLayers = this.actualOptions.zLayers;
|
|
295
|
-
this._duration = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.duration) *
|
|
296
|
-
this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) *
|
|
305
|
+
this._duration = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.duration) * Constants_js_1.millisecondsToSeconds;
|
|
306
|
+
this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) * Constants_js_1.millisecondsToSeconds;
|
|
297
307
|
this._lifeTime = 0;
|
|
298
|
-
|
|
308
|
+
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
309
|
+
this.fpsLimit = this.actualOptions.fpsLimit > minFpsLimit ? this.actualOptions.fpsLimit : defaultFpsLimit;
|
|
299
310
|
this._smooth = this.actualOptions.smooth;
|
|
300
311
|
for (const [, drawer] of this.effectDrawers) {
|
|
301
|
-
|
|
312
|
+
await drawer.init?.(this);
|
|
302
313
|
}
|
|
303
314
|
for (const [, drawer] of this.shapeDrawers) {
|
|
304
|
-
|
|
315
|
+
await drawer.init?.(this);
|
|
305
316
|
}
|
|
306
317
|
for (const [, plugin] of this.plugins) {
|
|
307
|
-
|
|
318
|
+
await plugin.init?.();
|
|
308
319
|
}
|
|
309
320
|
this._engine.dispatchEvent("containerInit", { container: this });
|
|
310
|
-
this.particles.init();
|
|
311
|
-
this.particles.setDensity();
|
|
321
|
+
await this.particles.init();
|
|
322
|
+
await this.particles.setDensity();
|
|
312
323
|
for (const [, plugin] of this.plugins) {
|
|
313
|
-
plugin.particlesSetup
|
|
324
|
+
plugin.particlesSetup?.();
|
|
314
325
|
}
|
|
315
326
|
this._engine.dispatchEvent("particlesSetup", { container: this });
|
|
316
327
|
}
|
|
@@ -333,7 +344,7 @@ class Container {
|
|
|
333
344
|
return;
|
|
334
345
|
}
|
|
335
346
|
for (const [, plugin] of this.plugins) {
|
|
336
|
-
plugin.pause
|
|
347
|
+
plugin.pause?.();
|
|
337
348
|
}
|
|
338
349
|
if (!this.pageHidden) {
|
|
339
350
|
this._paused = true;
|
|
@@ -360,7 +371,7 @@ class Container {
|
|
|
360
371
|
}
|
|
361
372
|
}
|
|
362
373
|
this._engine.dispatchEvent("containerPlay", { container: this });
|
|
363
|
-
this.draw(needsUpdate
|
|
374
|
+
this.draw(needsUpdate ?? false);
|
|
364
375
|
}
|
|
365
376
|
async refresh() {
|
|
366
377
|
if (!guardCheck(this)) {
|
|
@@ -385,18 +396,19 @@ class Container {
|
|
|
385
396
|
await this.init();
|
|
386
397
|
this.started = true;
|
|
387
398
|
await new Promise((resolve) => {
|
|
388
|
-
|
|
399
|
+
const start = async () => {
|
|
389
400
|
this._eventListeners.addListeners();
|
|
390
401
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
391
402
|
this._intersectionObserver.observe(this.interactivity.element);
|
|
392
403
|
}
|
|
393
404
|
for (const [, plugin] of this.plugins) {
|
|
394
|
-
|
|
405
|
+
await plugin.start?.();
|
|
395
406
|
}
|
|
396
407
|
this._engine.dispatchEvent("containerStarted", { container: this });
|
|
397
408
|
this.play();
|
|
398
409
|
resolve();
|
|
399
|
-
}
|
|
410
|
+
};
|
|
411
|
+
this._delayTimeout = setTimeout(() => void start(), this._delay);
|
|
400
412
|
});
|
|
401
413
|
}
|
|
402
414
|
stop() {
|
|
@@ -417,7 +429,7 @@ class Container {
|
|
|
417
429
|
this._intersectionObserver.unobserve(this.interactivity.element);
|
|
418
430
|
}
|
|
419
431
|
for (const [, plugin] of this.plugins) {
|
|
420
|
-
plugin.stop
|
|
432
|
+
plugin.stop?.();
|
|
421
433
|
}
|
|
422
434
|
for (const key of this.plugins.keys()) {
|
|
423
435
|
this.plugins.delete(key);
|
package/cjs/Core/Engine.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Engine = void 0;
|
|
4
27
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
5
28
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
6
|
-
const Container_js_1 = require("./Container.js");
|
|
7
29
|
const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
|
|
8
30
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
9
|
-
function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
31
|
+
async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
10
32
|
let res = map.get(container);
|
|
11
33
|
if (!res || force) {
|
|
12
|
-
res = [...initializers.values()].map((t) => t(container));
|
|
34
|
+
res = await Promise.all([...initializers.values()].map((t) => t(container)));
|
|
13
35
|
map.set(container, res);
|
|
14
36
|
}
|
|
15
37
|
return res;
|
|
@@ -21,7 +43,7 @@ async function getDataFromUrl(data) {
|
|
|
21
43
|
}
|
|
22
44
|
const response = await fetch(url);
|
|
23
45
|
if (response.ok) {
|
|
24
|
-
return response.json();
|
|
46
|
+
return (await response.json());
|
|
25
47
|
}
|
|
26
48
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
27
49
|
return data.fallback;
|
|
@@ -54,16 +76,18 @@ class Engine {
|
|
|
54
76
|
return res;
|
|
55
77
|
}
|
|
56
78
|
get version() {
|
|
57
|
-
return "3.0
|
|
79
|
+
return "3.2.0";
|
|
58
80
|
}
|
|
59
81
|
addConfig(config) {
|
|
60
|
-
const
|
|
61
|
-
this._configs.set(
|
|
62
|
-
this._eventDispatcher.dispatchEvent("configAdded", { data: { name, config } });
|
|
82
|
+
const key = config.key ?? config.name ?? "default";
|
|
83
|
+
this._configs.set(key, config);
|
|
84
|
+
this._eventDispatcher.dispatchEvent("configAdded", { data: { name: key, config } });
|
|
63
85
|
}
|
|
64
86
|
async addEffect(effect, drawer, refresh = true) {
|
|
65
87
|
(0, Utils_js_1.executeOnSingleOrMultiple)(effect, (type) => {
|
|
66
|
-
!this.getEffectDrawer(type)
|
|
88
|
+
if (!this.getEffectDrawer(type)) {
|
|
89
|
+
this.effectDrawers.set(type, drawer);
|
|
90
|
+
}
|
|
67
91
|
});
|
|
68
92
|
await this.refresh(refresh);
|
|
69
93
|
}
|
|
@@ -83,20 +107,28 @@ class Engine {
|
|
|
83
107
|
await this.refresh(refresh);
|
|
84
108
|
}
|
|
85
109
|
async addPathGenerator(name, generator, refresh = true) {
|
|
86
|
-
!this.getPathGenerator(name)
|
|
110
|
+
if (!this.getPathGenerator(name)) {
|
|
111
|
+
this.pathGenerators.set(name, generator);
|
|
112
|
+
}
|
|
87
113
|
await this.refresh(refresh);
|
|
88
114
|
}
|
|
89
115
|
async addPlugin(plugin, refresh = true) {
|
|
90
|
-
!this.getPlugin(plugin.id)
|
|
116
|
+
if (!this.getPlugin(plugin.id)) {
|
|
117
|
+
this.plugins.push(plugin);
|
|
118
|
+
}
|
|
91
119
|
await this.refresh(refresh);
|
|
92
120
|
}
|
|
93
121
|
async addPreset(preset, options, override = false, refresh = true) {
|
|
94
|
-
(override || !this.getPreset(preset))
|
|
122
|
+
if (override || !this.getPreset(preset)) {
|
|
123
|
+
this.presets.set(preset, options);
|
|
124
|
+
}
|
|
95
125
|
await this.refresh(refresh);
|
|
96
126
|
}
|
|
97
127
|
async addShape(shape, drawer, refresh = true) {
|
|
98
128
|
(0, Utils_js_1.executeOnSingleOrMultiple)(shape, (type) => {
|
|
99
|
-
!this.getShapeDrawer(type)
|
|
129
|
+
if (!this.getShapeDrawer(type)) {
|
|
130
|
+
this.shapeDrawers.set(type, drawer);
|
|
131
|
+
}
|
|
100
132
|
});
|
|
101
133
|
await this.refresh(refresh);
|
|
102
134
|
}
|
|
@@ -114,26 +146,29 @@ class Engine {
|
|
|
114
146
|
domItem(index) {
|
|
115
147
|
const dom = this.dom(), item = dom[index];
|
|
116
148
|
if (!item || item.destroyed) {
|
|
117
|
-
|
|
149
|
+
const deleteCount = 1;
|
|
150
|
+
dom.splice(index, deleteCount);
|
|
118
151
|
return;
|
|
119
152
|
}
|
|
120
153
|
return item;
|
|
121
154
|
}
|
|
122
|
-
getAvailablePlugins(container) {
|
|
155
|
+
async getAvailablePlugins(container) {
|
|
123
156
|
const res = new Map();
|
|
124
157
|
for (const plugin of this.plugins) {
|
|
125
|
-
plugin.needsPlugin(container.actualOptions)
|
|
158
|
+
if (plugin.needsPlugin(container.actualOptions)) {
|
|
159
|
+
res.set(plugin.id, await plugin.getPlugin(container));
|
|
160
|
+
}
|
|
126
161
|
}
|
|
127
162
|
return res;
|
|
128
163
|
}
|
|
129
164
|
getEffectDrawer(type) {
|
|
130
165
|
return this.effectDrawers.get(type);
|
|
131
166
|
}
|
|
132
|
-
getInteractors(container, force = false) {
|
|
133
|
-
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
167
|
+
async getInteractors(container, force = false) {
|
|
168
|
+
return await getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
134
169
|
}
|
|
135
|
-
getMovers(container, force = false) {
|
|
136
|
-
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
170
|
+
async getMovers(container, force = false) {
|
|
171
|
+
return await getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
137
172
|
}
|
|
138
173
|
getPathGenerator(type) {
|
|
139
174
|
return this.pathGenerators.get(type);
|
|
@@ -153,8 +188,8 @@ class Engine {
|
|
|
153
188
|
getSupportedShapes() {
|
|
154
189
|
return this.shapeDrawers.keys();
|
|
155
190
|
}
|
|
156
|
-
getUpdaters(container, force = false) {
|
|
157
|
-
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
191
|
+
async getUpdaters(container, force = false) {
|
|
192
|
+
return await getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
158
193
|
}
|
|
159
194
|
init() {
|
|
160
195
|
if (this._initialized) {
|
|
@@ -163,19 +198,20 @@ class Engine {
|
|
|
163
198
|
this._initialized = true;
|
|
164
199
|
}
|
|
165
200
|
async load(params) {
|
|
166
|
-
const id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() *
|
|
201
|
+
const randomFactor = 10000, id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() * randomFactor)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
|
|
167
202
|
let domContainer = params.element ?? document.getElementById(id);
|
|
168
203
|
if (!domContainer) {
|
|
169
204
|
domContainer = document.createElement("div");
|
|
170
205
|
domContainer.id = id;
|
|
171
206
|
document.body.append(domContainer);
|
|
172
207
|
}
|
|
173
|
-
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id);
|
|
174
|
-
if (oldIndex >=
|
|
208
|
+
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id), minIndex = 0;
|
|
209
|
+
if (oldIndex >= minIndex) {
|
|
175
210
|
const old = this.domItem(oldIndex);
|
|
176
211
|
if (old && !old.destroyed) {
|
|
177
212
|
old.destroy();
|
|
178
|
-
|
|
213
|
+
const deleteCount = 1;
|
|
214
|
+
dom.splice(oldIndex, deleteCount);
|
|
179
215
|
}
|
|
180
216
|
}
|
|
181
217
|
let canvasEl;
|
|
@@ -186,7 +222,8 @@ class Engine {
|
|
|
186
222
|
else {
|
|
187
223
|
const existingCanvases = domContainer.getElementsByTagName("canvas");
|
|
188
224
|
if (existingCanvases.length) {
|
|
189
|
-
|
|
225
|
+
const firstIndex = 0;
|
|
226
|
+
canvasEl = existingCanvases[firstIndex];
|
|
190
227
|
canvasEl.dataset[Constants_js_1.generatedAttribute] = "false";
|
|
191
228
|
}
|
|
192
229
|
else {
|
|
@@ -201,9 +238,10 @@ class Engine {
|
|
|
201
238
|
if (!canvasEl.style.height) {
|
|
202
239
|
canvasEl.style.height = "100%";
|
|
203
240
|
}
|
|
204
|
-
const newItem = new
|
|
205
|
-
if (oldIndex >=
|
|
206
|
-
|
|
241
|
+
const { Container } = await Promise.resolve().then(() => __importStar(require("./Container.js"))), newItem = new Container(this, id, currentOptions);
|
|
242
|
+
if (oldIndex >= minIndex) {
|
|
243
|
+
const deleteCount = 0;
|
|
244
|
+
dom.splice(oldIndex, deleteCount, newItem);
|
|
207
245
|
}
|
|
208
246
|
else {
|
|
209
247
|
dom.push(newItem);
|
|
@@ -223,14 +261,14 @@ class Engine {
|
|
|
223
261
|
return;
|
|
224
262
|
}
|
|
225
263
|
for (const updater of updaters) {
|
|
226
|
-
updater.loadOptions
|
|
264
|
+
updater.loadOptions?.(options, ...sourceOptions);
|
|
227
265
|
}
|
|
228
266
|
}
|
|
229
267
|
async refresh(refresh = true) {
|
|
230
268
|
if (!refresh) {
|
|
231
269
|
return;
|
|
232
270
|
}
|
|
233
|
-
this.dom().
|
|
271
|
+
await Promise.all(this.dom().map((t) => t.refresh()));
|
|
234
272
|
}
|
|
235
273
|
removeEventListener(type, listener) {
|
|
236
274
|
this._eventDispatcher.removeEventListener(type, listener);
|