@tsparticles/engine 3.2.2 → 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 +34 -29
- package/browser/Core/Container.js +60 -47
- package/browser/Core/Engine.js +82 -74
- package/browser/Core/Particle.js +40 -26
- package/browser/Core/Particles.js +51 -52
- package/browser/Core/Utils/EventListeners.js +18 -17
- package/browser/Core/Utils/ExternalInteractorBase.js +2 -1
- package/browser/Core/Utils/InteractionManager.js +7 -6
- 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 +27 -21
- 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 +34 -29
- package/cjs/Core/Container.js +60 -47
- package/cjs/Core/Engine.js +82 -97
- package/cjs/Core/Particle.js +40 -26
- package/cjs/Core/Particles.js +52 -76
- package/cjs/Core/Utils/EventListeners.js +18 -17
- package/cjs/Core/Utils/ExternalInteractorBase.js +2 -1
- package/cjs/Core/Utils/InteractionManager.js +7 -6
- 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 +27 -21
- 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 +34 -29
- package/esm/Core/Container.js +60 -47
- package/esm/Core/Engine.js +82 -74
- package/esm/Core/Particle.js +40 -26
- package/esm/Core/Particles.js +51 -52
- package/esm/Core/Utils/EventListeners.js +18 -17
- package/esm/Core/Utils/ExternalInteractorBase.js +2 -1
- package/esm/Core/Utils/InteractionManager.js +7 -6
- 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 +27 -21
- 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/Canvas.d.ts +4 -4
- package/types/Core/Container.d.ts +4 -2
- package/types/Core/Engine.d.ts +6 -5
- package/types/Core/Interfaces/IContainerPlugin.d.ts +4 -4
- package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
- package/types/Core/Interfaces/IExternalInteractor.d.ts +1 -1
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
- package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IParticlesInteractor.d.ts +1 -1
- package/types/Core/Interfaces/IPlugin.d.ts +3 -4
- package/types/Core/Interfaces/IShapeDrawer.d.ts +5 -4
- package/types/Core/Particle.d.ts +3 -2
- package/types/Core/Particles.d.ts +7 -7
- package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
- package/types/Core/Utils/InteractionManager.d.ts +2 -2
- package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
- 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/types/Utils/CanvasUtils.d.ts +6 -6
- package/umd/Core/Canvas.js +34 -29
- package/umd/Core/Container.js +61 -48
- package/umd/Core/Engine.js +83 -99
- package/umd/Core/Particle.js +41 -27
- package/umd/Core/Particles.js +53 -78
- package/umd/Core/Utils/EventListeners.js +19 -18
- package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
- package/umd/Core/Utils/InteractionManager.js +8 -7
- 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 +28 -22
- 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/373.min.js +0 -2
- package/373.min.js.LICENSE.txt +0 -1
- package/438.min.js +0 -2
- package/438.min.js.LICENSE.txt +0 -1
- package/dist_browser_Core_Container_js.js +0 -92
- package/dist_browser_Core_Particle_js.js +0 -32
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
|
}
|
|
@@ -270,11 +275,11 @@ export class Canvas {
|
|
|
270
275
|
drawAsync(cb) {
|
|
271
276
|
const ctx = this._context;
|
|
272
277
|
if (!ctx) {
|
|
273
|
-
return
|
|
278
|
+
return undefined;
|
|
274
279
|
}
|
|
275
280
|
return cb(ctx);
|
|
276
281
|
}
|
|
277
|
-
|
|
282
|
+
drawParticle(particle, delta) {
|
|
278
283
|
if (particle.spawning || particle.destroyed) {
|
|
279
284
|
return;
|
|
280
285
|
}
|
|
@@ -293,13 +298,13 @@ export class Canvas {
|
|
|
293
298
|
if (!fColor && !sColor) {
|
|
294
299
|
return;
|
|
295
300
|
}
|
|
296
|
-
|
|
301
|
+
this.draw((ctx) => {
|
|
297
302
|
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
298
303
|
fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined,
|
|
299
304
|
};
|
|
300
305
|
colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
|
|
301
306
|
this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
|
|
302
|
-
|
|
307
|
+
drawParticle({
|
|
303
308
|
container,
|
|
304
309
|
context: ctx,
|
|
305
310
|
particle,
|
|
@@ -315,15 +320,15 @@ export class Canvas {
|
|
|
315
320
|
this._applyPostDrawUpdaters(particle);
|
|
316
321
|
});
|
|
317
322
|
}
|
|
318
|
-
|
|
319
|
-
|
|
323
|
+
drawParticlePlugin(plugin, particle, delta) {
|
|
324
|
+
this.draw(ctx => drawParticlePlugin(ctx, plugin, particle, delta));
|
|
320
325
|
}
|
|
321
|
-
|
|
322
|
-
|
|
326
|
+
drawPlugin(plugin, delta) {
|
|
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,16 +468,16 @@ 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()) {
|
|
472
477
|
return;
|
|
473
478
|
}
|
|
474
479
|
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
475
|
-
|
|
480
|
+
container.particles.setDensity();
|
|
476
481
|
this._applyResizePlugins();
|
|
477
482
|
if (needsRefresh) {
|
|
478
483
|
await container.refresh();
|
|
@@ -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
|
}
|
|
@@ -40,7 +41,7 @@ export class Container {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
|
-
this._nextFrame =
|
|
44
|
+
this._nextFrame = (timestamp) => {
|
|
44
45
|
try {
|
|
45
46
|
if (!this._smooth &&
|
|
46
47
|
this._lastFrameTime !== undefined &&
|
|
@@ -56,7 +57,7 @@ export class Container {
|
|
|
56
57
|
this.draw(false);
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
this.particles.draw(delta);
|
|
60
61
|
if (!this.alive()) {
|
|
61
62
|
this.destroy();
|
|
62
63
|
return;
|
|
@@ -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,26 +234,28 @@ 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)) {
|
|
237
248
|
return;
|
|
238
249
|
}
|
|
239
250
|
let refreshTime = force;
|
|
240
|
-
const frame =
|
|
251
|
+
const frame = (timestamp) => {
|
|
241
252
|
if (refreshTime) {
|
|
242
253
|
this._lastFrameTime = undefined;
|
|
243
254
|
refreshTime = false;
|
|
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 = [];
|