@tsparticles/engine 3.3.0 → 3.4.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 +0 -4
- package/browser/Core/Canvas.js +27 -22
- package/browser/Core/Container.js +55 -42
- package/browser/Core/Engine.js +82 -74
- package/browser/Core/Particle.js +29 -15
- package/browser/Core/Particles.js +23 -24
- package/browser/Core/Utils/EventListeners.js +18 -17
- package/browser/Core/Utils/ExternalInteractorBase.js +2 -1
- package/browser/Core/Utils/InteractionManager.js +3 -2
- package/browser/Core/Utils/ParticlesInteractorBase.js +2 -1
- package/browser/Core/Utils/QuadTree.js +1 -1
- package/browser/Core/Utils/Ranges.js +5 -4
- package/browser/Enums/AnimationStatus.js +5 -1
- package/browser/Enums/Directions/MoveDirection.js +14 -1
- package/browser/Enums/Directions/OutModeDirection.js +7 -1
- package/browser/Enums/Directions/RotateDirection.js +6 -1
- package/browser/Enums/InteractivityDetect.js +6 -1
- package/browser/Enums/Modes/AnimationMode.js +7 -1
- package/browser/Enums/Modes/CollisionMode.js +6 -1
- package/browser/Enums/Modes/LimitMode.js +5 -1
- package/browser/Enums/Modes/OutMode.js +8 -1
- package/browser/Enums/Modes/PixelMode.js +5 -1
- package/browser/Enums/Modes/ResponsiveMode.js +5 -1
- package/browser/Enums/Modes/ThemeMode.js +6 -1
- package/browser/Enums/Types/AlterType.js +5 -1
- package/browser/Enums/Types/DestroyType.js +6 -1
- package/browser/Enums/Types/DivType.js +5 -1
- package/browser/Enums/Types/EasingType.js +30 -1
- package/browser/Enums/Types/EventType.js +15 -1
- package/browser/Enums/Types/GradientType.js +6 -1
- package/browser/Enums/Types/InteractorType.js +5 -1
- package/browser/Enums/Types/ParticleOutType.js +6 -1
- package/browser/Enums/Types/StartValueType.js +6 -1
- package/browser/Options/Classes/AnimationOptions.js +4 -2
- package/browser/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
- package/browser/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/browser/Options/Classes/Interactivity/Interactivity.js +2 -1
- package/browser/Options/Classes/ManualParticle.js +2 -1
- package/browser/Options/Classes/Options.js +14 -12
- package/browser/Options/Classes/Particles/Collisions/Collisions.js +2 -1
- package/browser/Options/Classes/Particles/Move/Move.js +2 -1
- package/browser/Options/Classes/Particles/Move/MoveCenter.js +2 -1
- package/browser/Options/Classes/Particles/Move/OutModes.js +2 -1
- package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
- package/browser/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
- package/browser/Options/Classes/Responsive.js +5 -4
- package/browser/Options/Classes/Theme/ThemeDefault.js +2 -1
- package/browser/Types/RangeType.js +5 -1
- package/browser/Utils/CanvasUtils.js +13 -7
- package/browser/Utils/ColorUtils.js +17 -9
- package/browser/Utils/EventDispatcher.js +1 -1
- package/browser/Utils/HslColorManager.js +11 -4
- package/browser/Utils/NumberUtils.js +11 -10
- package/browser/Utils/RgbColorManager.js +11 -4
- package/browser/Utils/Utils.js +37 -31
- package/cjs/Core/Canvas.js +27 -22
- package/cjs/Core/Container.js +55 -42
- package/cjs/Core/Engine.js +82 -74
- package/cjs/Core/Particle.js +29 -15
- package/cjs/Core/Particles.js +23 -24
- package/cjs/Core/Utils/EventListeners.js +18 -17
- package/cjs/Core/Utils/ExternalInteractorBase.js +2 -1
- package/cjs/Core/Utils/InteractionManager.js +3 -2
- package/cjs/Core/Utils/ParticlesInteractorBase.js +2 -1
- package/cjs/Core/Utils/QuadTree.js +1 -1
- package/cjs/Core/Utils/Ranges.js +5 -4
- package/cjs/Enums/AnimationStatus.js +6 -0
- package/cjs/Enums/Directions/MoveDirection.js +15 -0
- package/cjs/Enums/Directions/OutModeDirection.js +8 -0
- package/cjs/Enums/Directions/RotateDirection.js +7 -0
- package/cjs/Enums/InteractivityDetect.js +7 -0
- package/cjs/Enums/Modes/AnimationMode.js +8 -0
- package/cjs/Enums/Modes/CollisionMode.js +7 -0
- package/cjs/Enums/Modes/LimitMode.js +6 -0
- package/cjs/Enums/Modes/OutMode.js +9 -0
- package/cjs/Enums/Modes/PixelMode.js +6 -0
- package/cjs/Enums/Modes/ResponsiveMode.js +6 -0
- package/cjs/Enums/Modes/ThemeMode.js +7 -0
- package/cjs/Enums/Types/AlterType.js +6 -0
- package/cjs/Enums/Types/DestroyType.js +7 -0
- package/cjs/Enums/Types/DivType.js +6 -0
- package/cjs/Enums/Types/EasingType.js +31 -0
- package/cjs/Enums/Types/EventType.js +16 -0
- package/cjs/Enums/Types/GradientType.js +7 -0
- package/cjs/Enums/Types/InteractorType.js +6 -0
- package/cjs/Enums/Types/ParticleOutType.js +7 -0
- package/cjs/Enums/Types/StartValueType.js +7 -0
- package/cjs/Options/Classes/AnimationOptions.js +4 -2
- package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
- package/cjs/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/cjs/Options/Classes/Interactivity/Interactivity.js +2 -1
- package/cjs/Options/Classes/ManualParticle.js +2 -1
- package/cjs/Options/Classes/Options.js +14 -12
- package/cjs/Options/Classes/Particles/Collisions/Collisions.js +2 -1
- package/cjs/Options/Classes/Particles/Move/Move.js +2 -1
- package/cjs/Options/Classes/Particles/Move/MoveCenter.js +2 -1
- package/cjs/Options/Classes/Particles/Move/OutModes.js +2 -1
- package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
- package/cjs/Options/Classes/Responsive.js +5 -4
- package/cjs/Options/Classes/Theme/ThemeDefault.js +2 -1
- package/cjs/Types/RangeType.js +6 -0
- package/cjs/Utils/CanvasUtils.js +13 -7
- package/cjs/Utils/ColorUtils.js +17 -9
- package/cjs/Utils/EventDispatcher.js +1 -1
- package/cjs/Utils/HslColorManager.js +11 -4
- package/cjs/Utils/NumberUtils.js +11 -10
- package/cjs/Utils/RgbColorManager.js +11 -4
- package/cjs/Utils/Utils.js +37 -31
- package/esm/Core/Canvas.js +27 -22
- package/esm/Core/Container.js +55 -42
- package/esm/Core/Engine.js +82 -74
- package/esm/Core/Particle.js +29 -15
- package/esm/Core/Particles.js +23 -24
- package/esm/Core/Utils/EventListeners.js +18 -17
- package/esm/Core/Utils/ExternalInteractorBase.js +2 -1
- package/esm/Core/Utils/InteractionManager.js +3 -2
- package/esm/Core/Utils/ParticlesInteractorBase.js +2 -1
- package/esm/Core/Utils/QuadTree.js +1 -1
- package/esm/Core/Utils/Ranges.js +5 -4
- package/esm/Enums/AnimationStatus.js +5 -1
- package/esm/Enums/Directions/MoveDirection.js +14 -1
- package/esm/Enums/Directions/OutModeDirection.js +7 -1
- package/esm/Enums/Directions/RotateDirection.js +6 -1
- package/esm/Enums/InteractivityDetect.js +6 -1
- package/esm/Enums/Modes/AnimationMode.js +7 -1
- package/esm/Enums/Modes/CollisionMode.js +6 -1
- package/esm/Enums/Modes/LimitMode.js +5 -1
- package/esm/Enums/Modes/OutMode.js +8 -1
- package/esm/Enums/Modes/PixelMode.js +5 -1
- package/esm/Enums/Modes/ResponsiveMode.js +5 -1
- package/esm/Enums/Modes/ThemeMode.js +6 -1
- package/esm/Enums/Types/AlterType.js +5 -1
- package/esm/Enums/Types/DestroyType.js +6 -1
- package/esm/Enums/Types/DivType.js +5 -1
- package/esm/Enums/Types/EasingType.js +30 -1
- package/esm/Enums/Types/EventType.js +15 -1
- package/esm/Enums/Types/GradientType.js +6 -1
- package/esm/Enums/Types/InteractorType.js +5 -1
- package/esm/Enums/Types/ParticleOutType.js +6 -1
- package/esm/Enums/Types/StartValueType.js +6 -1
- package/esm/Options/Classes/AnimationOptions.js +4 -2
- package/esm/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
- package/esm/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/esm/Options/Classes/Interactivity/Interactivity.js +2 -1
- package/esm/Options/Classes/ManualParticle.js +2 -1
- package/esm/Options/Classes/Options.js +14 -12
- package/esm/Options/Classes/Particles/Collisions/Collisions.js +2 -1
- package/esm/Options/Classes/Particles/Move/Move.js +2 -1
- package/esm/Options/Classes/Particles/Move/MoveCenter.js +2 -1
- package/esm/Options/Classes/Particles/Move/OutModes.js +2 -1
- package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
- package/esm/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
- package/esm/Options/Classes/Responsive.js +5 -4
- package/esm/Options/Classes/Theme/ThemeDefault.js +2 -1
- package/esm/Types/RangeType.js +5 -1
- package/esm/Utils/CanvasUtils.js +13 -7
- package/esm/Utils/ColorUtils.js +17 -9
- package/esm/Utils/EventDispatcher.js +1 -1
- package/esm/Utils/HslColorManager.js +11 -4
- package/esm/Utils/NumberUtils.js +11 -10
- package/esm/Utils/RgbColorManager.js +11 -4
- package/esm/Utils/Utils.js +37 -31
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +327 -225
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Container.d.ts +4 -2
- package/types/Core/Engine.d.ts +6 -5
- package/types/Core/Interfaces/IPlugin.d.ts +3 -4
- package/types/Core/Interfaces/IShapeDrawer.d.ts +1 -0
- package/types/Core/Particle.d.ts +1 -0
- package/types/Enums/AnimationStatus.d.ts +1 -1
- package/types/Enums/Directions/MoveDirection.d.ts +1 -1
- package/types/Enums/Directions/OutModeDirection.d.ts +1 -1
- package/types/Enums/Directions/RotateDirection.d.ts +1 -1
- package/types/Enums/InteractivityDetect.d.ts +1 -1
- package/types/Enums/Modes/AnimationMode.d.ts +1 -1
- package/types/Enums/Modes/CollisionMode.d.ts +1 -1
- package/types/Enums/Modes/LimitMode.d.ts +1 -1
- package/types/Enums/Modes/OutMode.d.ts +1 -1
- package/types/Enums/Modes/PixelMode.d.ts +1 -1
- package/types/Enums/Modes/ResponsiveMode.d.ts +1 -1
- package/types/Enums/Modes/ThemeMode.d.ts +1 -1
- package/types/Enums/Types/AlterType.d.ts +1 -1
- package/types/Enums/Types/DestroyType.d.ts +1 -1
- package/types/Enums/Types/DivType.d.ts +1 -1
- package/types/Enums/Types/EasingType.d.ts +1 -1
- package/types/Enums/Types/EventType.d.ts +1 -1
- package/types/Enums/Types/GradientType.d.ts +1 -1
- package/types/Enums/Types/InteractorType.d.ts +1 -1
- package/types/Enums/Types/ParticleOutType.d.ts +1 -1
- package/types/Enums/Types/StartValueType.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +2 -1
- package/types/Options/Classes/Responsive.d.ts +2 -2
- package/types/Options/Classes/Theme/Theme.d.ts +2 -2
- package/types/Options/Interfaces/IResponsive.d.ts +2 -3
- package/types/Options/Interfaces/Theme/ITheme.d.ts +2 -3
- package/types/Types/RangeType.d.ts +1 -1
- package/umd/Core/Canvas.js +27 -22
- package/umd/Core/Container.js +56 -43
- package/umd/Core/Engine.js +83 -99
- package/umd/Core/Particle.js +30 -16
- package/umd/Core/Particles.js +24 -25
- package/umd/Core/Utils/EventListeners.js +19 -18
- package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
- package/umd/Core/Utils/InteractionManager.js +4 -3
- package/umd/Core/Utils/ParticlesInteractorBase.js +3 -2
- package/umd/Core/Utils/QuadTree.js +1 -1
- package/umd/Core/Utils/Ranges.js +6 -5
- package/umd/Enums/AnimationStatus.js +6 -0
- package/umd/Enums/Directions/MoveDirection.js +15 -0
- package/umd/Enums/Directions/OutModeDirection.js +8 -0
- package/umd/Enums/Directions/RotateDirection.js +7 -0
- package/umd/Enums/InteractivityDetect.js +7 -0
- package/umd/Enums/Modes/AnimationMode.js +8 -0
- package/umd/Enums/Modes/CollisionMode.js +7 -0
- package/umd/Enums/Modes/LimitMode.js +6 -0
- package/umd/Enums/Modes/OutMode.js +9 -0
- package/umd/Enums/Modes/PixelMode.js +6 -0
- package/umd/Enums/Modes/ResponsiveMode.js +6 -0
- package/umd/Enums/Modes/ThemeMode.js +7 -0
- package/umd/Enums/Types/AlterType.js +6 -0
- package/umd/Enums/Types/DestroyType.js +7 -0
- package/umd/Enums/Types/DivType.js +6 -0
- package/umd/Enums/Types/EasingType.js +31 -0
- package/umd/Enums/Types/EventType.js +16 -0
- package/umd/Enums/Types/GradientType.js +7 -0
- package/umd/Enums/Types/InteractorType.js +6 -0
- package/umd/Enums/Types/ParticleOutType.js +7 -0
- package/umd/Enums/Types/StartValueType.js +7 -0
- package/umd/Options/Classes/AnimationOptions.js +5 -3
- package/umd/Options/Classes/Interactivity/Events/DivEvent.js +3 -2
- package/umd/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/umd/Options/Classes/Interactivity/Interactivity.js +3 -2
- package/umd/Options/Classes/ManualParticle.js +3 -2
- package/umd/Options/Classes/Options.js +15 -13
- package/umd/Options/Classes/Particles/Collisions/Collisions.js +3 -2
- package/umd/Options/Classes/Particles/Move/Move.js +3 -2
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +3 -2
- package/umd/Options/Classes/Particles/Move/OutModes.js +3 -2
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +3 -2
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +3 -2
- package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +3 -2
- package/umd/Options/Classes/Responsive.js +6 -5
- package/umd/Options/Classes/Theme/ThemeDefault.js +3 -2
- package/umd/Types/RangeType.js +6 -0
- package/umd/Utils/CanvasUtils.js +14 -8
- package/umd/Utils/ColorUtils.js +18 -10
- package/umd/Utils/EventDispatcher.js +1 -1
- package/umd/Utils/HslColorManager.js +11 -4
- package/umd/Utils/NumberUtils.js +12 -11
- package/umd/Utils/RgbColorManager.js +11 -4
- package/umd/Utils/Utils.js +38 -32
- package/174.min.js +0 -2
- package/174.min.js.LICENSE.txt +0 -1
- package/dist_browser_Core_Container_js.js +0 -102
package/README.md
CHANGED
|
@@ -969,10 +969,6 @@ flowchart TD
|
|
|
969
969
|
|
|
970
970
|
## Sponsors
|
|
971
971
|
|
|
972
|
-
### ScribbleMaps
|
|
973
|
-
|
|
974
|
-
Huge thanks to [ScribbleMaps](https://www.scribblemaps.com/) for their support on this project.
|
|
975
|
-
|
|
976
972
|
### JetBrains
|
|
977
973
|
|
|
978
974
|
Huge thanks to [JetBrains](https://www.jetbrains.com/?from=tsParticles) for the 2020-2022 Open Source Licenses!
|
package/browser/Core/Canvas.js
CHANGED
|
@@ -31,7 +31,7 @@ function setStyle(canvas, style, important = false) {
|
|
|
31
31
|
export class Canvas {
|
|
32
32
|
constructor(container) {
|
|
33
33
|
this.container = container;
|
|
34
|
-
this._applyPostDrawUpdaters =
|
|
34
|
+
this._applyPostDrawUpdaters = particle => {
|
|
35
35
|
for (const updater of this._postDrawUpdaters) {
|
|
36
36
|
updater.afterDraw?.(particle);
|
|
37
37
|
}
|
|
@@ -61,7 +61,7 @@ export class Canvas {
|
|
|
61
61
|
plugin.resize?.();
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
this._getPluginParticleColors =
|
|
64
|
+
this._getPluginParticleColors = particle => {
|
|
65
65
|
let fColor, sColor;
|
|
66
66
|
for (const plugin of this._colorPlugins) {
|
|
67
67
|
if (!fColor && plugin.particleFillColor) {
|
|
@@ -101,7 +101,7 @@ export class Canvas {
|
|
|
101
101
|
};
|
|
102
102
|
resolve();
|
|
103
103
|
});
|
|
104
|
-
img.addEventListener("error",
|
|
104
|
+
img.addEventListener("error", evt => {
|
|
105
105
|
reject(evt.error);
|
|
106
106
|
});
|
|
107
107
|
img.src = cover.image;
|
|
@@ -162,28 +162,33 @@ export class Canvas {
|
|
|
162
162
|
};
|
|
163
163
|
resolve();
|
|
164
164
|
});
|
|
165
|
-
img.addEventListener("error",
|
|
165
|
+
img.addEventListener("error", evt => {
|
|
166
166
|
reject(evt.error);
|
|
167
167
|
});
|
|
168
168
|
img.src = trailFill.image;
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
this._paintBase =
|
|
173
|
-
this.draw(
|
|
172
|
+
this._paintBase = baseColor => {
|
|
173
|
+
this.draw(ctx => paintBase(ctx, this.size, baseColor));
|
|
174
174
|
};
|
|
175
175
|
this._paintImage = (image, opacity) => {
|
|
176
|
-
this.draw(
|
|
176
|
+
this.draw(ctx => paintImage(ctx, this.size, image, opacity));
|
|
177
177
|
};
|
|
178
178
|
this._repairStyle = () => {
|
|
179
179
|
const element = this.element;
|
|
180
180
|
if (!element) {
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
|
-
this._safeMutationObserver(
|
|
183
|
+
this._safeMutationObserver(observer => observer.disconnect());
|
|
184
184
|
this._initStyle();
|
|
185
185
|
this.initBackground();
|
|
186
|
-
this._safeMutationObserver(
|
|
186
|
+
this._safeMutationObserver(observer => {
|
|
187
|
+
if (!element || !(element instanceof Node)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
observer.observe(element, { attributes: true });
|
|
191
|
+
});
|
|
187
192
|
};
|
|
188
193
|
this._resetOriginalStyle = () => {
|
|
189
194
|
const element = this.element, originalStyle = this._originalStyle;
|
|
@@ -192,7 +197,7 @@ export class Canvas {
|
|
|
192
197
|
}
|
|
193
198
|
setStyle(element, originalStyle);
|
|
194
199
|
};
|
|
195
|
-
this._safeMutationObserver =
|
|
200
|
+
this._safeMutationObserver = callback => {
|
|
196
201
|
if (!this._mutationObserver) {
|
|
197
202
|
return;
|
|
198
203
|
}
|
|
@@ -241,7 +246,7 @@ export class Canvas {
|
|
|
241
246
|
}
|
|
242
247
|
}
|
|
243
248
|
else if (options.clear) {
|
|
244
|
-
this.draw(
|
|
249
|
+
this.draw(ctx => {
|
|
245
250
|
clear(ctx, this.size);
|
|
246
251
|
});
|
|
247
252
|
}
|
|
@@ -316,14 +321,14 @@ export class Canvas {
|
|
|
316
321
|
});
|
|
317
322
|
}
|
|
318
323
|
drawParticlePlugin(plugin, particle, delta) {
|
|
319
|
-
this.draw(
|
|
324
|
+
this.draw(ctx => drawParticlePlugin(ctx, plugin, particle, delta));
|
|
320
325
|
}
|
|
321
326
|
drawPlugin(plugin, delta) {
|
|
322
|
-
this.draw(
|
|
327
|
+
this.draw(ctx => drawPlugin(ctx, plugin, delta));
|
|
323
328
|
}
|
|
324
329
|
async init() {
|
|
325
|
-
this._safeMutationObserver(
|
|
326
|
-
this._mutationObserver = safeMutationObserver(
|
|
330
|
+
this._safeMutationObserver(obs => obs.disconnect());
|
|
331
|
+
this._mutationObserver = safeMutationObserver(records => {
|
|
327
332
|
for (const record of records) {
|
|
328
333
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
329
334
|
this._repairStyle();
|
|
@@ -340,8 +345,8 @@ export class Canvas {
|
|
|
340
345
|
getLogger().error(e);
|
|
341
346
|
}
|
|
342
347
|
this.initBackground();
|
|
343
|
-
this._safeMutationObserver(
|
|
344
|
-
if (!this.element) {
|
|
348
|
+
this._safeMutationObserver(obs => {
|
|
349
|
+
if (!this.element || !(this.element instanceof Node)) {
|
|
345
350
|
return;
|
|
346
351
|
}
|
|
347
352
|
obs.observe(this.element, { attributes: true });
|
|
@@ -408,8 +413,8 @@ export class Canvas {
|
|
|
408
413
|
this.size.height = canvas.offsetHeight;
|
|
409
414
|
this.size.width = canvas.offsetWidth;
|
|
410
415
|
this._context = this.element.getContext("2d");
|
|
411
|
-
this._safeMutationObserver(
|
|
412
|
-
if (!this.element) {
|
|
416
|
+
this._safeMutationObserver(obs => {
|
|
417
|
+
if (!this.element || !(this.element instanceof Node)) {
|
|
413
418
|
return;
|
|
414
419
|
}
|
|
415
420
|
obs.observe(this.element, { attributes: true });
|
|
@@ -419,7 +424,7 @@ export class Canvas {
|
|
|
419
424
|
}
|
|
420
425
|
paint() {
|
|
421
426
|
const options = this.container.actualOptions;
|
|
422
|
-
this.draw(
|
|
427
|
+
this.draw(ctx => {
|
|
423
428
|
if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
|
424
429
|
clear(ctx, this.size);
|
|
425
430
|
if (this._coverImage) {
|
|
@@ -463,9 +468,9 @@ export class Canvas {
|
|
|
463
468
|
return true;
|
|
464
469
|
}
|
|
465
470
|
stop() {
|
|
466
|
-
this._safeMutationObserver(
|
|
471
|
+
this._safeMutationObserver(obs => obs.disconnect());
|
|
467
472
|
this._mutationObserver = undefined;
|
|
468
|
-
this.draw(
|
|
473
|
+
this.draw(ctx => clear(ctx, this.size));
|
|
469
474
|
}
|
|
470
475
|
async windowResize() {
|
|
471
476
|
if (!this.element || !this.resize()) {
|
|
@@ -2,6 +2,7 @@ import { errorPrefix, millisecondsToSeconds } from "./Utils/Constants.js";
|
|
|
2
2
|
import { getLogger, safeIntersectionObserver } from "../Utils/Utils.js";
|
|
3
3
|
import { Canvas } from "./Canvas.js";
|
|
4
4
|
import { EventListeners } from "./Utils/EventListeners.js";
|
|
5
|
+
import { EventType } from "../Enums/Types/EventType.js";
|
|
5
6
|
import { Options } from "../Options/Classes/Options.js";
|
|
6
7
|
import { Particles } from "./Particles.js";
|
|
7
8
|
import { Retina } from "./Retina.js";
|
|
@@ -24,7 +25,7 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
|
24
25
|
}
|
|
25
26
|
export class Container {
|
|
26
27
|
constructor(engine, id, sourceOptions) {
|
|
27
|
-
this._intersectionManager =
|
|
28
|
+
this._intersectionManager = entries => {
|
|
28
29
|
if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
@@ -83,6 +84,7 @@ export class Container {
|
|
|
83
84
|
this._lastFrameTime = 0;
|
|
84
85
|
this.zLayers = 100;
|
|
85
86
|
this.pageHidden = false;
|
|
87
|
+
this._clickHandlers = new Map();
|
|
86
88
|
this._sourceOptions = sourceOptions;
|
|
87
89
|
this._initialSourceOptions = sourceOptions;
|
|
88
90
|
this.retina = new Retina(this);
|
|
@@ -101,8 +103,8 @@ export class Container {
|
|
|
101
103
|
this._options = loadContainerOptions(this._engine, this);
|
|
102
104
|
this.actualOptions = loadContainerOptions(this._engine, this);
|
|
103
105
|
this._eventListeners = new EventListeners(this);
|
|
104
|
-
this._intersectionObserver = safeIntersectionObserver(
|
|
105
|
-
this._engine.dispatchEvent(
|
|
106
|
+
this._intersectionObserver = safeIntersectionObserver(entries => this._intersectionManager(entries));
|
|
107
|
+
this._engine.dispatchEvent(EventType.containerBuilt, { container: this });
|
|
106
108
|
}
|
|
107
109
|
get animationStatus() {
|
|
108
110
|
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
@@ -130,8 +132,7 @@ export class Container {
|
|
|
130
132
|
y: pos.y * pxRatio,
|
|
131
133
|
}, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
|
|
132
134
|
callback(e, particles);
|
|
133
|
-
}
|
|
134
|
-
const clickHandler = (e) => {
|
|
135
|
+
}, clickHandler = (e) => {
|
|
135
136
|
if (!guardCheck(this)) {
|
|
136
137
|
return;
|
|
137
138
|
}
|
|
@@ -140,27 +141,23 @@ export class Container {
|
|
|
140
141
|
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
141
142
|
}, radius = 1;
|
|
142
143
|
clickOrTouchHandler(e, pos, radius);
|
|
143
|
-
}
|
|
144
|
-
const touchStartHandler = () => {
|
|
144
|
+
}, touchStartHandler = () => {
|
|
145
145
|
if (!guardCheck(this)) {
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
touched = true;
|
|
149
149
|
touchMoved = false;
|
|
150
|
-
}
|
|
151
|
-
const touchMoveHandler = () => {
|
|
150
|
+
}, touchMoveHandler = () => {
|
|
152
151
|
if (!guardCheck(this)) {
|
|
153
152
|
return;
|
|
154
153
|
}
|
|
155
154
|
touchMoved = true;
|
|
156
|
-
}
|
|
157
|
-
const touchEndHandler = (e) => {
|
|
155
|
+
}, touchEndHandler = (e) => {
|
|
158
156
|
if (!guardCheck(this)) {
|
|
159
157
|
return;
|
|
160
158
|
}
|
|
161
159
|
if (touched && !touchMoved) {
|
|
162
|
-
const touchEvent = e;
|
|
163
|
-
const lengthOffset = 1;
|
|
160
|
+
const touchEvent = e, lengthOffset = 1;
|
|
164
161
|
let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
|
|
165
162
|
if (!lastTouch) {
|
|
166
163
|
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
|
|
@@ -176,8 +173,7 @@ export class Container {
|
|
|
176
173
|
}
|
|
177
174
|
touched = false;
|
|
178
175
|
touchMoved = false;
|
|
179
|
-
}
|
|
180
|
-
const touchCancelHandler = () => {
|
|
176
|
+
}, touchCancelHandler = () => {
|
|
181
177
|
if (!guardCheck(this)) {
|
|
182
178
|
return;
|
|
183
179
|
}
|
|
@@ -185,11 +181,14 @@ export class Container {
|
|
|
185
181
|
touchMoved = false;
|
|
186
182
|
};
|
|
187
183
|
let touched = false, touchMoved = false;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
184
|
+
this._clickHandlers.set("click", clickHandler);
|
|
185
|
+
this._clickHandlers.set("touchstart", touchStartHandler);
|
|
186
|
+
this._clickHandlers.set("touchmove", touchMoveHandler);
|
|
187
|
+
this._clickHandlers.set("touchend", touchEndHandler);
|
|
188
|
+
this._clickHandlers.set("touchcancel", touchCancelHandler);
|
|
189
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
190
|
+
el.addEventListener(key, handler);
|
|
191
|
+
}
|
|
193
192
|
}
|
|
194
193
|
addLifeTime(value) {
|
|
195
194
|
this._lifeTime += value;
|
|
@@ -204,11 +203,21 @@ export class Container {
|
|
|
204
203
|
alive() {
|
|
205
204
|
return !this._duration || this._lifeTime <= this._duration;
|
|
206
205
|
}
|
|
207
|
-
|
|
206
|
+
clearClickHandlers() {
|
|
207
|
+
if (!guardCheck(this)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
211
|
+
this.interactivity.element?.removeEventListener(key, handler);
|
|
212
|
+
}
|
|
213
|
+
this._clickHandlers.clear();
|
|
214
|
+
}
|
|
215
|
+
destroy(remove = true) {
|
|
208
216
|
if (!guardCheck(this)) {
|
|
209
217
|
return;
|
|
210
218
|
}
|
|
211
219
|
this.stop();
|
|
220
|
+
this.clearClickHandlers();
|
|
212
221
|
this.particles.destroy();
|
|
213
222
|
this.canvas.destroy();
|
|
214
223
|
for (const [, effectDrawer] of this.effectDrawers) {
|
|
@@ -225,12 +234,14 @@ export class Container {
|
|
|
225
234
|
}
|
|
226
235
|
this._engine.clearPlugins(this);
|
|
227
236
|
this.destroyed = true;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
if (remove) {
|
|
238
|
+
const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
|
|
239
|
+
if (idx >= minIndex) {
|
|
240
|
+
const deleteCount = 1;
|
|
241
|
+
mainArr.splice(idx, deleteCount);
|
|
242
|
+
}
|
|
232
243
|
}
|
|
233
|
-
this._engine.dispatchEvent(
|
|
244
|
+
this._engine.dispatchEvent(EventType.containerDestroyed, { container: this });
|
|
234
245
|
}
|
|
235
246
|
draw(force) {
|
|
236
247
|
if (!guardCheck(this)) {
|
|
@@ -244,7 +255,7 @@ export class Container {
|
|
|
244
255
|
}
|
|
245
256
|
this._nextFrame(timestamp);
|
|
246
257
|
};
|
|
247
|
-
this._drawAnimationFrame = requestAnimationFrame(
|
|
258
|
+
this._drawAnimationFrame = requestAnimationFrame(timestamp => frame(timestamp));
|
|
248
259
|
}
|
|
249
260
|
async export(type, options = {}) {
|
|
250
261
|
for (const [, plugin] of this.plugins) {
|
|
@@ -298,13 +309,14 @@ export class Container {
|
|
|
298
309
|
this.updateActualOptions();
|
|
299
310
|
this.canvas.initBackground();
|
|
300
311
|
this.canvas.resize();
|
|
301
|
-
|
|
302
|
-
this.
|
|
303
|
-
this.
|
|
312
|
+
const { zLayers, duration, delay, fpsLimit, smooth } = this.actualOptions;
|
|
313
|
+
this.zLayers = zLayers;
|
|
314
|
+
this._duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
315
|
+
this._delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
304
316
|
this._lifeTime = 0;
|
|
305
317
|
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
306
|
-
this.fpsLimit =
|
|
307
|
-
this._smooth =
|
|
318
|
+
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
319
|
+
this._smooth = smooth;
|
|
308
320
|
for (const [, drawer] of this.effectDrawers) {
|
|
309
321
|
await drawer.init?.(this);
|
|
310
322
|
}
|
|
@@ -314,13 +326,13 @@ export class Container {
|
|
|
314
326
|
for (const [, plugin] of this.plugins) {
|
|
315
327
|
await plugin.init?.();
|
|
316
328
|
}
|
|
317
|
-
this._engine.dispatchEvent(
|
|
329
|
+
this._engine.dispatchEvent(EventType.containerInit, { container: this });
|
|
318
330
|
await this.particles.init();
|
|
319
331
|
this.particles.setDensity();
|
|
320
332
|
for (const [, plugin] of this.plugins) {
|
|
321
333
|
plugin.particlesSetup?.();
|
|
322
334
|
}
|
|
323
|
-
this._engine.dispatchEvent(
|
|
335
|
+
this._engine.dispatchEvent(EventType.particlesSetup, { container: this });
|
|
324
336
|
}
|
|
325
337
|
async loadTheme(name) {
|
|
326
338
|
if (!guardCheck(this)) {
|
|
@@ -346,7 +358,7 @@ export class Container {
|
|
|
346
358
|
if (!this.pageHidden) {
|
|
347
359
|
this._paused = true;
|
|
348
360
|
}
|
|
349
|
-
this._engine.dispatchEvent(
|
|
361
|
+
this._engine.dispatchEvent(EventType.containerPaused, { container: this });
|
|
350
362
|
}
|
|
351
363
|
play(force) {
|
|
352
364
|
if (!guardCheck(this)) {
|
|
@@ -367,7 +379,7 @@ export class Container {
|
|
|
367
379
|
}
|
|
368
380
|
}
|
|
369
381
|
}
|
|
370
|
-
this._engine.dispatchEvent(
|
|
382
|
+
this._engine.dispatchEvent(EventType.containerPlay, { container: this });
|
|
371
383
|
this.draw(needsUpdate ?? false);
|
|
372
384
|
}
|
|
373
385
|
async refresh() {
|
|
@@ -377,12 +389,13 @@ export class Container {
|
|
|
377
389
|
this.stop();
|
|
378
390
|
return this.start();
|
|
379
391
|
}
|
|
380
|
-
async reset() {
|
|
392
|
+
async reset(sourceOptions) {
|
|
381
393
|
if (!guardCheck(this)) {
|
|
382
394
|
return;
|
|
383
395
|
}
|
|
384
|
-
this._initialSourceOptions =
|
|
385
|
-
this.
|
|
396
|
+
this._initialSourceOptions = sourceOptions;
|
|
397
|
+
this._sourceOptions = sourceOptions;
|
|
398
|
+
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
386
399
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
387
400
|
return this.refresh();
|
|
388
401
|
}
|
|
@@ -392,7 +405,7 @@ export class Container {
|
|
|
392
405
|
}
|
|
393
406
|
await this.init();
|
|
394
407
|
this.started = true;
|
|
395
|
-
await new Promise(
|
|
408
|
+
await new Promise(resolve => {
|
|
396
409
|
const start = async () => {
|
|
397
410
|
this._eventListeners.addListeners();
|
|
398
411
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
@@ -401,7 +414,7 @@ export class Container {
|
|
|
401
414
|
for (const [, plugin] of this.plugins) {
|
|
402
415
|
await plugin.start?.();
|
|
403
416
|
}
|
|
404
|
-
this._engine.dispatchEvent(
|
|
417
|
+
this._engine.dispatchEvent(EventType.containerStarted, { container: this });
|
|
405
418
|
this.play();
|
|
406
419
|
resolve();
|
|
407
420
|
};
|
|
@@ -432,7 +445,7 @@ export class Container {
|
|
|
432
445
|
this.plugins.delete(key);
|
|
433
446
|
}
|
|
434
447
|
this._sourceOptions = this._options;
|
|
435
|
-
this._engine.dispatchEvent(
|
|
448
|
+
this._engine.dispatchEvent(EventType.containerStopped, { container: this });
|
|
436
449
|
}
|
|
437
450
|
updateActualOptions() {
|
|
438
451
|
this.actualOptions.responsive = [];
|
package/browser/Core/Engine.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { errorPrefix, generatedAttribute } from "./Utils/Constants.js";
|
|
2
2
|
import { executeOnSingleOrMultiple, getLogger, itemFromSingleOrMultiple } from "../Utils/Utils.js";
|
|
3
|
+
import { Container } from "./Container.js";
|
|
3
4
|
import { EventDispatcher } from "../Utils/EventDispatcher.js";
|
|
5
|
+
import { EventType } from "../Enums/Types/EventType.js";
|
|
4
6
|
import { getRandom } from "../Utils/NumberUtils.js";
|
|
5
7
|
async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
6
8
|
let res = map.get(container);
|
|
7
9
|
if (!res || force) {
|
|
8
|
-
res = await Promise.all([...initializers.values()].map(
|
|
10
|
+
res = await Promise.all([...initializers.values()].map(t => t(container)));
|
|
9
11
|
map.set(container, res);
|
|
10
12
|
}
|
|
11
13
|
return res;
|
|
@@ -22,6 +24,46 @@ async function getDataFromUrl(data) {
|
|
|
22
24
|
getLogger().error(`${errorPrefix} ${response.status} while retrieving config file`);
|
|
23
25
|
return data.fallback;
|
|
24
26
|
}
|
|
27
|
+
const generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", getCanvasFromContainer = (domContainer) => {
|
|
28
|
+
let canvasEl;
|
|
29
|
+
if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag) {
|
|
30
|
+
canvasEl = domContainer;
|
|
31
|
+
if (!canvasEl.dataset[generatedAttribute]) {
|
|
32
|
+
canvasEl.dataset[generatedAttribute] = generatedFalse;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const existingCanvases = domContainer.getElementsByTagName(canvasTag);
|
|
37
|
+
if (existingCanvases.length) {
|
|
38
|
+
const firstIndex = 0;
|
|
39
|
+
canvasEl = existingCanvases[firstIndex];
|
|
40
|
+
canvasEl.dataset[generatedAttribute] = generatedFalse;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
canvasEl = document.createElement(canvasTag);
|
|
44
|
+
canvasEl.dataset[generatedAttribute] = generatedTrue;
|
|
45
|
+
domContainer.appendChild(canvasEl);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const fullPercent = "100%";
|
|
49
|
+
if (!canvasEl.style.width) {
|
|
50
|
+
canvasEl.style.width = fullPercent;
|
|
51
|
+
}
|
|
52
|
+
if (!canvasEl.style.height) {
|
|
53
|
+
canvasEl.style.height = fullPercent;
|
|
54
|
+
}
|
|
55
|
+
return canvasEl;
|
|
56
|
+
}, getDomContainer = (id, source) => {
|
|
57
|
+
let domContainer = source ?? document.getElementById(id);
|
|
58
|
+
if (domContainer) {
|
|
59
|
+
return domContainer;
|
|
60
|
+
}
|
|
61
|
+
domContainer = document.createElement("div");
|
|
62
|
+
domContainer.id = id;
|
|
63
|
+
domContainer.dataset[generatedAttribute] = generatedTrue;
|
|
64
|
+
document.body.append(domContainer);
|
|
65
|
+
return domContainer;
|
|
66
|
+
};
|
|
25
67
|
export class Engine {
|
|
26
68
|
constructor() {
|
|
27
69
|
this._configs = new Map();
|
|
@@ -49,16 +91,19 @@ export class Engine {
|
|
|
49
91
|
}
|
|
50
92
|
return res;
|
|
51
93
|
}
|
|
94
|
+
get items() {
|
|
95
|
+
return this._domArray;
|
|
96
|
+
}
|
|
52
97
|
get version() {
|
|
53
|
-
return "3.
|
|
98
|
+
return "3.4.0";
|
|
54
99
|
}
|
|
55
100
|
addConfig(config) {
|
|
56
101
|
const key = config.key ?? config.name ?? "default";
|
|
57
102
|
this._configs.set(key, config);
|
|
58
|
-
this._eventDispatcher.dispatchEvent(
|
|
103
|
+
this._eventDispatcher.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
59
104
|
}
|
|
60
105
|
async addEffect(effect, drawer, refresh = true) {
|
|
61
|
-
executeOnSingleOrMultiple(effect,
|
|
106
|
+
executeOnSingleOrMultiple(effect, type => {
|
|
62
107
|
if (!this.getEffectDrawer(type)) {
|
|
63
108
|
this.effectDrawers.set(type, drawer);
|
|
64
109
|
}
|
|
@@ -98,12 +143,13 @@ export class Engine {
|
|
|
98
143
|
}
|
|
99
144
|
await this.refresh(refresh);
|
|
100
145
|
}
|
|
101
|
-
async addShape(
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
146
|
+
async addShape(drawer, refresh = true) {
|
|
147
|
+
for (const validType of drawer.validTypes) {
|
|
148
|
+
if (this.getShapeDrawer(validType)) {
|
|
149
|
+
continue;
|
|
105
150
|
}
|
|
106
|
-
|
|
151
|
+
this.shapeDrawers.set(validType, drawer);
|
|
152
|
+
}
|
|
107
153
|
await this.refresh(refresh);
|
|
108
154
|
}
|
|
109
155
|
clearPlugins(container) {
|
|
@@ -115,16 +161,10 @@ export class Engine {
|
|
|
115
161
|
this._eventDispatcher.dispatchEvent(type, args);
|
|
116
162
|
}
|
|
117
163
|
dom() {
|
|
118
|
-
return this.
|
|
164
|
+
return this.items;
|
|
119
165
|
}
|
|
120
166
|
domItem(index) {
|
|
121
|
-
|
|
122
|
-
if (!item || item.destroyed) {
|
|
123
|
-
const deleteCount = 1;
|
|
124
|
-
dom.splice(index, deleteCount);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
return item;
|
|
167
|
+
return this.item(index);
|
|
128
168
|
}
|
|
129
169
|
async getAvailablePlugins(container) {
|
|
130
170
|
const res = new Map();
|
|
@@ -139,16 +179,16 @@ export class Engine {
|
|
|
139
179
|
return this.effectDrawers.get(type);
|
|
140
180
|
}
|
|
141
181
|
async getInteractors(container, force = false) {
|
|
142
|
-
return
|
|
182
|
+
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
143
183
|
}
|
|
144
184
|
async getMovers(container, force = false) {
|
|
145
|
-
return
|
|
185
|
+
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
146
186
|
}
|
|
147
187
|
getPathGenerator(type) {
|
|
148
188
|
return this.pathGenerators.get(type);
|
|
149
189
|
}
|
|
150
190
|
getPlugin(plugin) {
|
|
151
|
-
return this.plugins.find(
|
|
191
|
+
return this.plugins.find(t => t.id === plugin);
|
|
152
192
|
}
|
|
153
193
|
getPreset(preset) {
|
|
154
194
|
return this.presets.get(preset);
|
|
@@ -163,7 +203,7 @@ export class Engine {
|
|
|
163
203
|
return this.shapeDrawers.keys();
|
|
164
204
|
}
|
|
165
205
|
async getUpdaters(container, force = false) {
|
|
166
|
-
return
|
|
206
|
+
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
167
207
|
}
|
|
168
208
|
init() {
|
|
169
209
|
if (this._initialized) {
|
|
@@ -171,89 +211,57 @@ export class Engine {
|
|
|
171
211
|
}
|
|
172
212
|
this._initialized = true;
|
|
173
213
|
}
|
|
214
|
+
item(index) {
|
|
215
|
+
const { items } = this, item = items[index];
|
|
216
|
+
if (!item || item.destroyed) {
|
|
217
|
+
const deleteCount = 1;
|
|
218
|
+
items.splice(index, deleteCount);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
return item;
|
|
222
|
+
}
|
|
174
223
|
async load(params) {
|
|
175
224
|
const randomFactor = 10000, id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * randomFactor)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
|
|
176
|
-
|
|
177
|
-
if (!domContainer) {
|
|
178
|
-
domContainer = document.createElement("div");
|
|
179
|
-
domContainer.id = id;
|
|
180
|
-
document.body.append(domContainer);
|
|
181
|
-
}
|
|
182
|
-
const currentOptions = itemFromSingleOrMultiple(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id), minIndex = 0;
|
|
225
|
+
const currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), minIndex = 0, newItem = new Container(this, id, currentOptions);
|
|
183
226
|
if (oldIndex >= minIndex) {
|
|
184
|
-
const old = this.
|
|
227
|
+
const old = this.item(oldIndex), one = 1, none = 0, deleteCount = old ? one : none;
|
|
185
228
|
if (old && !old.destroyed) {
|
|
186
|
-
old.destroy();
|
|
187
|
-
const deleteCount = 1;
|
|
188
|
-
dom.splice(oldIndex, deleteCount);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
let canvasEl;
|
|
192
|
-
if (domContainer.tagName.toLowerCase() === "canvas") {
|
|
193
|
-
canvasEl = domContainer;
|
|
194
|
-
canvasEl.dataset[generatedAttribute] = "false";
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
const existingCanvases = domContainer.getElementsByTagName("canvas");
|
|
198
|
-
if (existingCanvases.length) {
|
|
199
|
-
const firstIndex = 0;
|
|
200
|
-
canvasEl = existingCanvases[firstIndex];
|
|
201
|
-
canvasEl.dataset[generatedAttribute] = "false";
|
|
229
|
+
old.destroy(false);
|
|
202
230
|
}
|
|
203
|
-
|
|
204
|
-
canvasEl = document.createElement("canvas");
|
|
205
|
-
canvasEl.dataset[generatedAttribute] = "true";
|
|
206
|
-
domContainer.appendChild(canvasEl);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (!canvasEl.style.width) {
|
|
210
|
-
canvasEl.style.width = "100%";
|
|
211
|
-
}
|
|
212
|
-
if (!canvasEl.style.height) {
|
|
213
|
-
canvasEl.style.height = "100%";
|
|
214
|
-
}
|
|
215
|
-
const { Container } = await import("./Container.js"), newItem = new Container(this, id, currentOptions);
|
|
216
|
-
if (oldIndex >= minIndex) {
|
|
217
|
-
const deleteCount = 0;
|
|
218
|
-
dom.splice(oldIndex, deleteCount, newItem);
|
|
231
|
+
items.splice(oldIndex, deleteCount, newItem);
|
|
219
232
|
}
|
|
220
233
|
else {
|
|
221
|
-
|
|
234
|
+
items.push(newItem);
|
|
222
235
|
}
|
|
236
|
+
const domContainer = getDomContainer(id, params.element), canvasEl = getCanvasFromContainer(domContainer);
|
|
223
237
|
newItem.canvas.loadCanvas(canvasEl);
|
|
224
238
|
await newItem.start();
|
|
225
239
|
return newItem;
|
|
226
240
|
}
|
|
227
241
|
loadOptions(options, sourceOptions) {
|
|
228
|
-
|
|
229
|
-
plugin.loadOptions(options, sourceOptions);
|
|
230
|
-
}
|
|
242
|
+
this.plugins.forEach(plugin => plugin.loadOptions?.(options, sourceOptions));
|
|
231
243
|
}
|
|
232
244
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
233
245
|
const updaters = this.updaters.get(container);
|
|
234
246
|
if (!updaters) {
|
|
235
247
|
return;
|
|
236
248
|
}
|
|
237
|
-
|
|
238
|
-
updater.loadOptions?.(options, ...sourceOptions);
|
|
239
|
-
}
|
|
249
|
+
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
240
250
|
}
|
|
241
251
|
async refresh(refresh = true) {
|
|
242
252
|
if (!refresh) {
|
|
243
253
|
return;
|
|
244
254
|
}
|
|
245
|
-
await Promise.all(this.
|
|
255
|
+
await Promise.all(this.items.map(t => t.refresh()));
|
|
246
256
|
}
|
|
247
257
|
removeEventListener(type, listener) {
|
|
248
258
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
249
259
|
}
|
|
250
260
|
setOnClickHandler(callback) {
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
261
|
+
const { items } = this;
|
|
262
|
+
if (!items.length) {
|
|
253
263
|
throw new Error(`${errorPrefix} can only set click handlers after calling tsParticles.load()`);
|
|
254
264
|
}
|
|
255
|
-
|
|
256
|
-
domItem.addClickHandler(callback);
|
|
257
|
-
}
|
|
265
|
+
items.forEach(item => item.addClickHandler(callback));
|
|
258
266
|
}
|
|
259
267
|
}
|