@tsparticles/engine 3.3.0 → 3.5.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 +57 -44
- 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 +28 -14
- 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 +57 -44
- 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 +24 -19
- package/cjs/Utils/ColorUtils.js +37 -30
- package/cjs/Utils/EventDispatcher.js +1 -1
- package/cjs/Utils/HslColorManager.js +11 -4
- package/cjs/Utils/NumberUtils.js +54 -38
- package/cjs/Utils/OptionsUtils.js +2 -3
- package/cjs/Utils/RgbColorManager.js +11 -4
- package/cjs/Utils/TypeUtils.js +6 -7
- package/cjs/Utils/Utils.js +66 -61
- package/cjs/init.js +1 -2
- package/esm/Core/Canvas.js +27 -22
- package/esm/Core/Container.js +57 -44
- 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 +28 -14
- 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/types/Utils/NumberUtils.d.ts +3 -0
- package/umd/Core/Canvas.js +27 -22
- package/umd/Core/Container.js +58 -45
- 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 +25 -20
- package/umd/Utils/ColorUtils.js +38 -31
- package/umd/Utils/EventDispatcher.js +1 -1
- package/umd/Utils/HslColorManager.js +11 -4
- package/umd/Utils/NumberUtils.js +55 -39
- package/umd/Utils/OptionsUtils.js +2 -3
- package/umd/Utils/RgbColorManager.js +11 -4
- package/umd/Utils/TypeUtils.js +6 -7
- package/umd/Utils/Utils.js +67 -62
- package/umd/init.js +1 -2
- package/174.min.js +0 -2
- package/174.min.js.LICENSE.txt +0 -1
- package/dist_browser_Core_Container_js.js +0 -102
package/cjs/Core/Container.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Container = void 0;
|
|
4
|
+
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
4
5
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
5
6
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
6
7
|
const Canvas_js_1 = require("./Canvas.js");
|
|
7
8
|
const EventListeners_js_1 = require("./Utils/EventListeners.js");
|
|
9
|
+
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
8
10
|
const Options_js_1 = require("../Options/Classes/Options.js");
|
|
9
11
|
const Particles_js_1 = require("./Particles.js");
|
|
10
12
|
const Retina_js_1 = require("./Retina.js");
|
|
11
|
-
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
12
13
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
13
14
|
function guardCheck(container) {
|
|
14
15
|
return container && !container.destroyed;
|
|
@@ -27,7 +28,7 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
|
27
28
|
}
|
|
28
29
|
class Container {
|
|
29
30
|
constructor(engine, id, sourceOptions) {
|
|
30
|
-
this._intersectionManager =
|
|
31
|
+
this._intersectionManager = entries => {
|
|
31
32
|
if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
@@ -86,6 +87,7 @@ class Container {
|
|
|
86
87
|
this._lastFrameTime = 0;
|
|
87
88
|
this.zLayers = 100;
|
|
88
89
|
this.pageHidden = false;
|
|
90
|
+
this._clickHandlers = new Map();
|
|
89
91
|
this._sourceOptions = sourceOptions;
|
|
90
92
|
this._initialSourceOptions = sourceOptions;
|
|
91
93
|
this.retina = new Retina_js_1.Retina(this);
|
|
@@ -104,8 +106,8 @@ class Container {
|
|
|
104
106
|
this._options = loadContainerOptions(this._engine, this);
|
|
105
107
|
this.actualOptions = loadContainerOptions(this._engine, this);
|
|
106
108
|
this._eventListeners = new EventListeners_js_1.EventListeners(this);
|
|
107
|
-
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(
|
|
108
|
-
this._engine.dispatchEvent(
|
|
109
|
+
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(entries => this._intersectionManager(entries));
|
|
110
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerBuilt, { container: this });
|
|
109
111
|
}
|
|
110
112
|
get animationStatus() {
|
|
111
113
|
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
@@ -133,8 +135,7 @@ class Container {
|
|
|
133
135
|
y: pos.y * pxRatio,
|
|
134
136
|
}, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
|
|
135
137
|
callback(e, particles);
|
|
136
|
-
}
|
|
137
|
-
const clickHandler = (e) => {
|
|
138
|
+
}, clickHandler = (e) => {
|
|
138
139
|
if (!guardCheck(this)) {
|
|
139
140
|
return;
|
|
140
141
|
}
|
|
@@ -143,27 +144,23 @@ class Container {
|
|
|
143
144
|
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
144
145
|
}, radius = 1;
|
|
145
146
|
clickOrTouchHandler(e, pos, radius);
|
|
146
|
-
}
|
|
147
|
-
const touchStartHandler = () => {
|
|
147
|
+
}, touchStartHandler = () => {
|
|
148
148
|
if (!guardCheck(this)) {
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
touched = true;
|
|
152
152
|
touchMoved = false;
|
|
153
|
-
}
|
|
154
|
-
const touchMoveHandler = () => {
|
|
153
|
+
}, touchMoveHandler = () => {
|
|
155
154
|
if (!guardCheck(this)) {
|
|
156
155
|
return;
|
|
157
156
|
}
|
|
158
157
|
touchMoved = true;
|
|
159
|
-
}
|
|
160
|
-
const touchEndHandler = (e) => {
|
|
158
|
+
}, touchEndHandler = (e) => {
|
|
161
159
|
if (!guardCheck(this)) {
|
|
162
160
|
return;
|
|
163
161
|
}
|
|
164
162
|
if (touched && !touchMoved) {
|
|
165
|
-
const touchEvent = e;
|
|
166
|
-
const lengthOffset = 1;
|
|
163
|
+
const touchEvent = e, lengthOffset = 1;
|
|
167
164
|
let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
|
|
168
165
|
if (!lastTouch) {
|
|
169
166
|
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
|
|
@@ -179,8 +176,7 @@ class Container {
|
|
|
179
176
|
}
|
|
180
177
|
touched = false;
|
|
181
178
|
touchMoved = false;
|
|
182
|
-
}
|
|
183
|
-
const touchCancelHandler = () => {
|
|
179
|
+
}, touchCancelHandler = () => {
|
|
184
180
|
if (!guardCheck(this)) {
|
|
185
181
|
return;
|
|
186
182
|
}
|
|
@@ -188,11 +184,14 @@ class Container {
|
|
|
188
184
|
touchMoved = false;
|
|
189
185
|
};
|
|
190
186
|
let touched = false, touchMoved = false;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
187
|
+
this._clickHandlers.set("click", clickHandler);
|
|
188
|
+
this._clickHandlers.set("touchstart", touchStartHandler);
|
|
189
|
+
this._clickHandlers.set("touchmove", touchMoveHandler);
|
|
190
|
+
this._clickHandlers.set("touchend", touchEndHandler);
|
|
191
|
+
this._clickHandlers.set("touchcancel", touchCancelHandler);
|
|
192
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
193
|
+
el.addEventListener(key, handler);
|
|
194
|
+
}
|
|
196
195
|
}
|
|
197
196
|
addLifeTime(value) {
|
|
198
197
|
this._lifeTime += value;
|
|
@@ -207,11 +206,21 @@ class Container {
|
|
|
207
206
|
alive() {
|
|
208
207
|
return !this._duration || this._lifeTime <= this._duration;
|
|
209
208
|
}
|
|
210
|
-
|
|
209
|
+
clearClickHandlers() {
|
|
210
|
+
if (!guardCheck(this)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
214
|
+
this.interactivity.element?.removeEventListener(key, handler);
|
|
215
|
+
}
|
|
216
|
+
this._clickHandlers.clear();
|
|
217
|
+
}
|
|
218
|
+
destroy(remove = true) {
|
|
211
219
|
if (!guardCheck(this)) {
|
|
212
220
|
return;
|
|
213
221
|
}
|
|
214
222
|
this.stop();
|
|
223
|
+
this.clearClickHandlers();
|
|
215
224
|
this.particles.destroy();
|
|
216
225
|
this.canvas.destroy();
|
|
217
226
|
for (const [, effectDrawer] of this.effectDrawers) {
|
|
@@ -228,12 +237,14 @@ class Container {
|
|
|
228
237
|
}
|
|
229
238
|
this._engine.clearPlugins(this);
|
|
230
239
|
this.destroyed = true;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
240
|
+
if (remove) {
|
|
241
|
+
const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
|
|
242
|
+
if (idx >= minIndex) {
|
|
243
|
+
const deleteCount = 1;
|
|
244
|
+
mainArr.splice(idx, deleteCount);
|
|
245
|
+
}
|
|
235
246
|
}
|
|
236
|
-
this._engine.dispatchEvent(
|
|
247
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerDestroyed, { container: this });
|
|
237
248
|
}
|
|
238
249
|
draw(force) {
|
|
239
250
|
if (!guardCheck(this)) {
|
|
@@ -247,7 +258,7 @@ class Container {
|
|
|
247
258
|
}
|
|
248
259
|
this._nextFrame(timestamp);
|
|
249
260
|
};
|
|
250
|
-
this._drawAnimationFrame =
|
|
261
|
+
this._drawAnimationFrame = (0, NumberUtils_js_1.animate)(timestamp => frame(timestamp));
|
|
251
262
|
}
|
|
252
263
|
async export(type, options = {}) {
|
|
253
264
|
for (const [, plugin] of this.plugins) {
|
|
@@ -301,13 +312,14 @@ class Container {
|
|
|
301
312
|
this.updateActualOptions();
|
|
302
313
|
this.canvas.initBackground();
|
|
303
314
|
this.canvas.resize();
|
|
304
|
-
|
|
305
|
-
this.
|
|
306
|
-
this.
|
|
315
|
+
const { zLayers, duration, delay, fpsLimit, smooth } = this.actualOptions;
|
|
316
|
+
this.zLayers = zLayers;
|
|
317
|
+
this._duration = (0, NumberUtils_js_1.getRangeValue)(duration) * Constants_js_1.millisecondsToSeconds;
|
|
318
|
+
this._delay = (0, NumberUtils_js_1.getRangeValue)(delay) * Constants_js_1.millisecondsToSeconds;
|
|
307
319
|
this._lifeTime = 0;
|
|
308
320
|
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
309
|
-
this.fpsLimit =
|
|
310
|
-
this._smooth =
|
|
321
|
+
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
322
|
+
this._smooth = smooth;
|
|
311
323
|
for (const [, drawer] of this.effectDrawers) {
|
|
312
324
|
await drawer.init?.(this);
|
|
313
325
|
}
|
|
@@ -317,13 +329,13 @@ class Container {
|
|
|
317
329
|
for (const [, plugin] of this.plugins) {
|
|
318
330
|
await plugin.init?.();
|
|
319
331
|
}
|
|
320
|
-
this._engine.dispatchEvent(
|
|
332
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerInit, { container: this });
|
|
321
333
|
await this.particles.init();
|
|
322
334
|
this.particles.setDensity();
|
|
323
335
|
for (const [, plugin] of this.plugins) {
|
|
324
336
|
plugin.particlesSetup?.();
|
|
325
337
|
}
|
|
326
|
-
this._engine.dispatchEvent(
|
|
338
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.particlesSetup, { container: this });
|
|
327
339
|
}
|
|
328
340
|
async loadTheme(name) {
|
|
329
341
|
if (!guardCheck(this)) {
|
|
@@ -337,7 +349,7 @@ class Container {
|
|
|
337
349
|
return;
|
|
338
350
|
}
|
|
339
351
|
if (this._drawAnimationFrame !== undefined) {
|
|
340
|
-
|
|
352
|
+
(0, NumberUtils_js_1.cancelAnimation)(this._drawAnimationFrame);
|
|
341
353
|
delete this._drawAnimationFrame;
|
|
342
354
|
}
|
|
343
355
|
if (this._paused) {
|
|
@@ -349,7 +361,7 @@ class Container {
|
|
|
349
361
|
if (!this.pageHidden) {
|
|
350
362
|
this._paused = true;
|
|
351
363
|
}
|
|
352
|
-
this._engine.dispatchEvent(
|
|
364
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerPaused, { container: this });
|
|
353
365
|
}
|
|
354
366
|
play(force) {
|
|
355
367
|
if (!guardCheck(this)) {
|
|
@@ -370,7 +382,7 @@ class Container {
|
|
|
370
382
|
}
|
|
371
383
|
}
|
|
372
384
|
}
|
|
373
|
-
this._engine.dispatchEvent(
|
|
385
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerPlay, { container: this });
|
|
374
386
|
this.draw(needsUpdate ?? false);
|
|
375
387
|
}
|
|
376
388
|
async refresh() {
|
|
@@ -380,12 +392,13 @@ class Container {
|
|
|
380
392
|
this.stop();
|
|
381
393
|
return this.start();
|
|
382
394
|
}
|
|
383
|
-
async reset() {
|
|
395
|
+
async reset(sourceOptions) {
|
|
384
396
|
if (!guardCheck(this)) {
|
|
385
397
|
return;
|
|
386
398
|
}
|
|
387
|
-
this._initialSourceOptions =
|
|
388
|
-
this.
|
|
399
|
+
this._initialSourceOptions = sourceOptions;
|
|
400
|
+
this._sourceOptions = sourceOptions;
|
|
401
|
+
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
389
402
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
390
403
|
return this.refresh();
|
|
391
404
|
}
|
|
@@ -395,7 +408,7 @@ class Container {
|
|
|
395
408
|
}
|
|
396
409
|
await this.init();
|
|
397
410
|
this.started = true;
|
|
398
|
-
await new Promise(
|
|
411
|
+
await new Promise(resolve => {
|
|
399
412
|
const start = async () => {
|
|
400
413
|
this._eventListeners.addListeners();
|
|
401
414
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
@@ -404,7 +417,7 @@ class Container {
|
|
|
404
417
|
for (const [, plugin] of this.plugins) {
|
|
405
418
|
await plugin.start?.();
|
|
406
419
|
}
|
|
407
|
-
this._engine.dispatchEvent(
|
|
420
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerStarted, { container: this });
|
|
408
421
|
this.play();
|
|
409
422
|
resolve();
|
|
410
423
|
};
|
|
@@ -435,7 +448,7 @@ class Container {
|
|
|
435
448
|
this.plugins.delete(key);
|
|
436
449
|
}
|
|
437
450
|
this._sourceOptions = this._options;
|
|
438
|
-
this._engine.dispatchEvent(
|
|
451
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerStopped, { container: this });
|
|
439
452
|
}
|
|
440
453
|
updateActualOptions() {
|
|
441
454
|
this.actualOptions.responsive = [];
|
package/cjs/Core/Engine.js
CHANGED
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Engine = void 0;
|
|
4
4
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
5
5
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
6
|
+
const Container_js_1 = require("./Container.js");
|
|
6
7
|
const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
|
|
8
|
+
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
7
9
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
8
10
|
async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
9
11
|
let res = map.get(container);
|
|
10
12
|
if (!res || force) {
|
|
11
|
-
res = await Promise.all([...initializers.values()].map(
|
|
13
|
+
res = await Promise.all([...initializers.values()].map(t => t(container)));
|
|
12
14
|
map.set(container, res);
|
|
13
15
|
}
|
|
14
16
|
return res;
|
|
@@ -25,6 +27,46 @@ async function getDataFromUrl(data) {
|
|
|
25
27
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
26
28
|
return data.fallback;
|
|
27
29
|
}
|
|
30
|
+
const generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", getCanvasFromContainer = (domContainer) => {
|
|
31
|
+
let canvasEl;
|
|
32
|
+
if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag) {
|
|
33
|
+
canvasEl = domContainer;
|
|
34
|
+
if (!canvasEl.dataset[Constants_js_1.generatedAttribute]) {
|
|
35
|
+
canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedFalse;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const existingCanvases = domContainer.getElementsByTagName(canvasTag);
|
|
40
|
+
if (existingCanvases.length) {
|
|
41
|
+
const firstIndex = 0;
|
|
42
|
+
canvasEl = existingCanvases[firstIndex];
|
|
43
|
+
canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedFalse;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
canvasEl = document.createElement(canvasTag);
|
|
47
|
+
canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedTrue;
|
|
48
|
+
domContainer.appendChild(canvasEl);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const fullPercent = "100%";
|
|
52
|
+
if (!canvasEl.style.width) {
|
|
53
|
+
canvasEl.style.width = fullPercent;
|
|
54
|
+
}
|
|
55
|
+
if (!canvasEl.style.height) {
|
|
56
|
+
canvasEl.style.height = fullPercent;
|
|
57
|
+
}
|
|
58
|
+
return canvasEl;
|
|
59
|
+
}, getDomContainer = (id, source) => {
|
|
60
|
+
let domContainer = source ?? document.getElementById(id);
|
|
61
|
+
if (domContainer) {
|
|
62
|
+
return domContainer;
|
|
63
|
+
}
|
|
64
|
+
domContainer = document.createElement("div");
|
|
65
|
+
domContainer.id = id;
|
|
66
|
+
domContainer.dataset[Constants_js_1.generatedAttribute] = generatedTrue;
|
|
67
|
+
document.body.append(domContainer);
|
|
68
|
+
return domContainer;
|
|
69
|
+
};
|
|
28
70
|
class Engine {
|
|
29
71
|
constructor() {
|
|
30
72
|
this._configs = new Map();
|
|
@@ -52,16 +94,19 @@ class Engine {
|
|
|
52
94
|
}
|
|
53
95
|
return res;
|
|
54
96
|
}
|
|
97
|
+
get items() {
|
|
98
|
+
return this._domArray;
|
|
99
|
+
}
|
|
55
100
|
get version() {
|
|
56
|
-
return "3.
|
|
101
|
+
return "3.5.0";
|
|
57
102
|
}
|
|
58
103
|
addConfig(config) {
|
|
59
104
|
const key = config.key ?? config.name ?? "default";
|
|
60
105
|
this._configs.set(key, config);
|
|
61
|
-
this._eventDispatcher.dispatchEvent(
|
|
106
|
+
this._eventDispatcher.dispatchEvent(EventType_js_1.EventType.configAdded, { data: { name: key, config } });
|
|
62
107
|
}
|
|
63
108
|
async addEffect(effect, drawer, refresh = true) {
|
|
64
|
-
(0, Utils_js_1.executeOnSingleOrMultiple)(effect,
|
|
109
|
+
(0, Utils_js_1.executeOnSingleOrMultiple)(effect, type => {
|
|
65
110
|
if (!this.getEffectDrawer(type)) {
|
|
66
111
|
this.effectDrawers.set(type, drawer);
|
|
67
112
|
}
|
|
@@ -101,12 +146,13 @@ class Engine {
|
|
|
101
146
|
}
|
|
102
147
|
await this.refresh(refresh);
|
|
103
148
|
}
|
|
104
|
-
async addShape(
|
|
105
|
-
(
|
|
106
|
-
if (
|
|
107
|
-
|
|
149
|
+
async addShape(drawer, refresh = true) {
|
|
150
|
+
for (const validType of drawer.validTypes) {
|
|
151
|
+
if (this.getShapeDrawer(validType)) {
|
|
152
|
+
continue;
|
|
108
153
|
}
|
|
109
|
-
|
|
154
|
+
this.shapeDrawers.set(validType, drawer);
|
|
155
|
+
}
|
|
110
156
|
await this.refresh(refresh);
|
|
111
157
|
}
|
|
112
158
|
clearPlugins(container) {
|
|
@@ -118,16 +164,10 @@ class Engine {
|
|
|
118
164
|
this._eventDispatcher.dispatchEvent(type, args);
|
|
119
165
|
}
|
|
120
166
|
dom() {
|
|
121
|
-
return this.
|
|
167
|
+
return this.items;
|
|
122
168
|
}
|
|
123
169
|
domItem(index) {
|
|
124
|
-
|
|
125
|
-
if (!item || item.destroyed) {
|
|
126
|
-
const deleteCount = 1;
|
|
127
|
-
dom.splice(index, deleteCount);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
return item;
|
|
170
|
+
return this.item(index);
|
|
131
171
|
}
|
|
132
172
|
async getAvailablePlugins(container) {
|
|
133
173
|
const res = new Map();
|
|
@@ -142,16 +182,16 @@ class Engine {
|
|
|
142
182
|
return this.effectDrawers.get(type);
|
|
143
183
|
}
|
|
144
184
|
async getInteractors(container, force = false) {
|
|
145
|
-
return
|
|
185
|
+
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
146
186
|
}
|
|
147
187
|
async getMovers(container, force = false) {
|
|
148
|
-
return
|
|
188
|
+
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
149
189
|
}
|
|
150
190
|
getPathGenerator(type) {
|
|
151
191
|
return this.pathGenerators.get(type);
|
|
152
192
|
}
|
|
153
193
|
getPlugin(plugin) {
|
|
154
|
-
return this.plugins.find(
|
|
194
|
+
return this.plugins.find(t => t.id === plugin);
|
|
155
195
|
}
|
|
156
196
|
getPreset(preset) {
|
|
157
197
|
return this.presets.get(preset);
|
|
@@ -166,7 +206,7 @@ class Engine {
|
|
|
166
206
|
return this.shapeDrawers.keys();
|
|
167
207
|
}
|
|
168
208
|
async getUpdaters(container, force = false) {
|
|
169
|
-
return
|
|
209
|
+
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
170
210
|
}
|
|
171
211
|
init() {
|
|
172
212
|
if (this._initialized) {
|
|
@@ -174,90 +214,58 @@ class Engine {
|
|
|
174
214
|
}
|
|
175
215
|
this._initialized = true;
|
|
176
216
|
}
|
|
217
|
+
item(index) {
|
|
218
|
+
const { items } = this, item = items[index];
|
|
219
|
+
if (!item || item.destroyed) {
|
|
220
|
+
const deleteCount = 1;
|
|
221
|
+
items.splice(index, deleteCount);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
return item;
|
|
225
|
+
}
|
|
177
226
|
async load(params) {
|
|
178
227
|
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;
|
|
179
|
-
|
|
180
|
-
if (!domContainer) {
|
|
181
|
-
domContainer = document.createElement("div");
|
|
182
|
-
domContainer.id = id;
|
|
183
|
-
document.body.append(domContainer);
|
|
184
|
-
}
|
|
185
|
-
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id), minIndex = 0;
|
|
228
|
+
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), minIndex = 0, newItem = new Container_js_1.Container(this, id, currentOptions);
|
|
186
229
|
if (oldIndex >= minIndex) {
|
|
187
|
-
const old = this.
|
|
230
|
+
const old = this.item(oldIndex), one = 1, none = 0, deleteCount = old ? one : none;
|
|
188
231
|
if (old && !old.destroyed) {
|
|
189
|
-
old.destroy();
|
|
190
|
-
const deleteCount = 1;
|
|
191
|
-
dom.splice(oldIndex, deleteCount);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
let canvasEl;
|
|
195
|
-
if (domContainer.tagName.toLowerCase() === "canvas") {
|
|
196
|
-
canvasEl = domContainer;
|
|
197
|
-
canvasEl.dataset[Constants_js_1.generatedAttribute] = "false";
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
const existingCanvases = domContainer.getElementsByTagName("canvas");
|
|
201
|
-
if (existingCanvases.length) {
|
|
202
|
-
const firstIndex = 0;
|
|
203
|
-
canvasEl = existingCanvases[firstIndex];
|
|
204
|
-
canvasEl.dataset[Constants_js_1.generatedAttribute] = "false";
|
|
232
|
+
old.destroy(false);
|
|
205
233
|
}
|
|
206
|
-
|
|
207
|
-
canvasEl = document.createElement("canvas");
|
|
208
|
-
canvasEl.dataset[Constants_js_1.generatedAttribute] = "true";
|
|
209
|
-
domContainer.appendChild(canvasEl);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (!canvasEl.style.width) {
|
|
213
|
-
canvasEl.style.width = "100%";
|
|
214
|
-
}
|
|
215
|
-
if (!canvasEl.style.height) {
|
|
216
|
-
canvasEl.style.height = "100%";
|
|
217
|
-
}
|
|
218
|
-
const { Container } = await import("./Container.js"), newItem = new Container(this, id, currentOptions);
|
|
219
|
-
if (oldIndex >= minIndex) {
|
|
220
|
-
const deleteCount = 0;
|
|
221
|
-
dom.splice(oldIndex, deleteCount, newItem);
|
|
234
|
+
items.splice(oldIndex, deleteCount, newItem);
|
|
222
235
|
}
|
|
223
236
|
else {
|
|
224
|
-
|
|
237
|
+
items.push(newItem);
|
|
225
238
|
}
|
|
239
|
+
const domContainer = getDomContainer(id, params.element), canvasEl = getCanvasFromContainer(domContainer);
|
|
226
240
|
newItem.canvas.loadCanvas(canvasEl);
|
|
227
241
|
await newItem.start();
|
|
228
242
|
return newItem;
|
|
229
243
|
}
|
|
230
244
|
loadOptions(options, sourceOptions) {
|
|
231
|
-
|
|
232
|
-
plugin.loadOptions(options, sourceOptions);
|
|
233
|
-
}
|
|
245
|
+
this.plugins.forEach(plugin => plugin.loadOptions?.(options, sourceOptions));
|
|
234
246
|
}
|
|
235
247
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
236
248
|
const updaters = this.updaters.get(container);
|
|
237
249
|
if (!updaters) {
|
|
238
250
|
return;
|
|
239
251
|
}
|
|
240
|
-
|
|
241
|
-
updater.loadOptions?.(options, ...sourceOptions);
|
|
242
|
-
}
|
|
252
|
+
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
243
253
|
}
|
|
244
254
|
async refresh(refresh = true) {
|
|
245
255
|
if (!refresh) {
|
|
246
256
|
return;
|
|
247
257
|
}
|
|
248
|
-
await Promise.all(this.
|
|
258
|
+
await Promise.all(this.items.map(t => t.refresh()));
|
|
249
259
|
}
|
|
250
260
|
removeEventListener(type, listener) {
|
|
251
261
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
252
262
|
}
|
|
253
263
|
setOnClickHandler(callback) {
|
|
254
|
-
const
|
|
255
|
-
if (!
|
|
264
|
+
const { items } = this;
|
|
265
|
+
if (!items.length) {
|
|
256
266
|
throw new Error(`${Constants_js_1.errorPrefix} can only set click handlers after calling tsParticles.load()`);
|
|
257
267
|
}
|
|
258
|
-
|
|
259
|
-
domItem.addClickHandler(callback);
|
|
260
|
-
}
|
|
268
|
+
items.forEach(item => item.addClickHandler(callback));
|
|
261
269
|
}
|
|
262
270
|
}
|
|
263
271
|
exports.Engine = Engine;
|
package/cjs/Core/Particle.js
CHANGED
|
@@ -6,10 +6,15 @@ const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
|
6
6
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
7
7
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
8
8
|
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
9
|
+
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
9
10
|
const Interactivity_js_1 = require("../Options/Classes/Interactivity/Interactivity.js");
|
|
11
|
+
const MoveDirection_js_1 = require("../Enums/Directions/MoveDirection.js");
|
|
12
|
+
const OutMode_js_1 = require("../Enums/Modes/OutMode.js");
|
|
13
|
+
const ParticleOutType_js_1 = require("../Enums/Types/ParticleOutType.js");
|
|
14
|
+
const PixelMode_js_1 = require("../Enums/Modes/PixelMode.js");
|
|
10
15
|
const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
|
|
11
16
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
12
|
-
const defaultRetryCount = 0, double = 2, half = 0.5, squareExp = 2;
|
|
17
|
+
const defaultRetryCount = 0, double = 2, half = 0.5, squareExp = 2, randomString = "random";
|
|
13
18
|
function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
|
|
14
19
|
const effectData = effectOptions.options[effect];
|
|
15
20
|
if (!effectData) {
|
|
@@ -58,7 +63,7 @@ class Particle {
|
|
|
58
63
|
}), pos = Vectors_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
|
|
59
64
|
fixOutMode({
|
|
60
65
|
outMode,
|
|
61
|
-
checkModes: [
|
|
66
|
+
checkModes: [OutMode_js_1.OutMode.bounce],
|
|
62
67
|
coord: pos.x,
|
|
63
68
|
maxCoord: container.canvas.size.width,
|
|
64
69
|
setCb: (value) => (pos.x += value),
|
|
@@ -67,7 +72,7 @@ class Particle {
|
|
|
67
72
|
}, fixVertical = (outMode) => {
|
|
68
73
|
fixOutMode({
|
|
69
74
|
outMode,
|
|
70
|
-
checkModes: [
|
|
75
|
+
checkModes: [OutMode_js_1.OutMode.bounce],
|
|
71
76
|
coord: pos.y,
|
|
72
77
|
maxCoord: container.canvas.size.height,
|
|
73
78
|
setCb: (value) => (pos.y += value),
|
|
@@ -86,7 +91,7 @@ class Particle {
|
|
|
86
91
|
};
|
|
87
92
|
this._calculateVelocity = () => {
|
|
88
93
|
const baseVelocity = (0, NumberUtils_js_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
|
|
89
|
-
if (moveOptions.direction ===
|
|
94
|
+
if (moveOptions.direction === MoveDirection_js_1.MoveDirection.inside || moveOptions.direction === MoveDirection_js_1.MoveDirection.outside) {
|
|
90
95
|
return res;
|
|
91
96
|
}
|
|
92
97
|
const rad = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
|
|
@@ -114,9 +119,9 @@ class Particle {
|
|
|
114
119
|
if (retries >= minRetries && tryCount > retries) {
|
|
115
120
|
throw new Error(`${Constants_js_1.errorPrefix} particle is overlapping and can't be placed`);
|
|
116
121
|
}
|
|
117
|
-
return !!this.container.particles.find(
|
|
122
|
+
return !!this.container.particles.find(particle => (0, NumberUtils_js_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
|
|
118
123
|
};
|
|
119
|
-
this._getRollColor =
|
|
124
|
+
this._getRollColor = color => {
|
|
120
125
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
121
126
|
return color;
|
|
122
127
|
}
|
|
@@ -132,7 +137,7 @@ class Particle {
|
|
|
132
137
|
}
|
|
133
138
|
return color;
|
|
134
139
|
};
|
|
135
|
-
this._initPosition =
|
|
140
|
+
this._initPosition = position => {
|
|
136
141
|
const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value), minZ = 0;
|
|
137
142
|
this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, minZ, container.zLayers));
|
|
138
143
|
this.initialPosition = this.position.copy();
|
|
@@ -140,15 +145,15 @@ class Particle {
|
|
|
140
145
|
this.moveCenter = {
|
|
141
146
|
...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
|
|
142
147
|
radius: this.options.move.center.radius ?? defaultRadius,
|
|
143
|
-
mode: this.options.move.center.mode ??
|
|
148
|
+
mode: this.options.move.center.mode ?? PixelMode_js_1.PixelMode.percent,
|
|
144
149
|
};
|
|
145
150
|
this.direction = (0, NumberUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
|
|
146
151
|
switch (this.options.move.direction) {
|
|
147
|
-
case
|
|
148
|
-
this.outType =
|
|
152
|
+
case MoveDirection_js_1.MoveDirection.inside:
|
|
153
|
+
this.outType = ParticleOutType_js_1.ParticleOutType.inside;
|
|
149
154
|
break;
|
|
150
|
-
case
|
|
151
|
-
this.outType =
|
|
155
|
+
case MoveDirection_js_1.MoveDirection.outside:
|
|
156
|
+
this.outType = ParticleOutType_js_1.ParticleOutType.outside;
|
|
152
157
|
break;
|
|
153
158
|
}
|
|
154
159
|
this.offset = Vectors_js_1.Vector.origin;
|
|
@@ -171,7 +176,7 @@ class Particle {
|
|
|
171
176
|
updater.particleDestroyed?.(this, override);
|
|
172
177
|
}
|
|
173
178
|
pathGenerator?.reset(this);
|
|
174
|
-
this._engine.dispatchEvent(
|
|
179
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.particleDestroyed, {
|
|
175
180
|
container: this.container,
|
|
176
181
|
data: {
|
|
177
182
|
particle: this,
|
|
@@ -216,14 +221,15 @@ class Particle {
|
|
|
216
221
|
this.lastPathTime = 0;
|
|
217
222
|
this.destroyed = false;
|
|
218
223
|
this.unbreakable = false;
|
|
224
|
+
this.isRotating = false;
|
|
219
225
|
this.rotation = 0;
|
|
220
226
|
this.misplaced = false;
|
|
221
227
|
this.retina = {
|
|
222
228
|
maxDistance: {},
|
|
223
229
|
};
|
|
224
|
-
this.outType =
|
|
230
|
+
this.outType = ParticleOutType_js_1.ParticleOutType.normal;
|
|
225
231
|
this.ignoresResizeRatio = true;
|
|
226
|
-
const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type
|
|
232
|
+
const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), { reduceDuplicates } = particlesOptions, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
227
233
|
this.effect = (0, Utils_js_1.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);
|
|
228
234
|
this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
|
|
229
235
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
@@ -243,6 +249,14 @@ class Particle {
|
|
|
243
249
|
}
|
|
244
250
|
}
|
|
245
251
|
}
|
|
252
|
+
if (this.effect === randomString) {
|
|
253
|
+
const availableEffects = [...this.container.effectDrawers.keys()];
|
|
254
|
+
this.effect = availableEffects[Math.floor(Math.random() * availableEffects.length)];
|
|
255
|
+
}
|
|
256
|
+
if (this.shape === randomString) {
|
|
257
|
+
const availableShapes = [...this.container.shapeDrawers.keys()];
|
|
258
|
+
this.shape = availableShapes[Math.floor(Math.random() * availableShapes.length)];
|
|
259
|
+
}
|
|
246
260
|
this.effectData = loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates);
|
|
247
261
|
this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);
|
|
248
262
|
particlesOptions.load(overrideOptions);
|