@tsparticles/engine 4.0.0-alpha.8 → 4.0.0-beta.1
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/155.min.js +1 -0
- package/README.md +41 -28
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +134 -101
- package/browser/Core/Engine.js +29 -162
- package/browser/Core/Particle.js +197 -183
- package/browser/Core/ParticlesManager.js +363 -0
- package/browser/Core/RenderManager.js +303 -0
- package/browser/Core/Retina.js +6 -6
- package/browser/Core/Utils/Constants.js +2 -2
- package/browser/Core/Utils/EventListeners.js +67 -63
- package/browser/Core/Utils/PluginManager.js +145 -0
- package/browser/Core/Utils/Ranges.js +29 -10
- package/browser/Core/Utils/SpatialHashGrid.js +102 -0
- package/browser/Core/Utils/Vectors.js +17 -18
- package/browser/Options/Classes/AnimatableColor.js +1 -0
- package/browser/Options/Classes/AnimationOptions.js +8 -0
- package/browser/Options/Classes/Background/Background.js +6 -0
- package/browser/Options/Classes/ColorAnimation.js +12 -1
- package/browser/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/browser/Options/Classes/HslAnimation.js +4 -5
- package/browser/Options/Classes/Options.js +67 -8
- package/browser/Options/Classes/OptionsColor.js +1 -0
- package/browser/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/browser/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/browser/Options/Classes/Particles/Fill.js +28 -0
- package/browser/Options/Classes/Particles/Move/Move.js +17 -3
- package/browser/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/browser/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/browser/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/browser/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/browser/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/browser/Options/Classes/Particles/Move/Spin.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/browser/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/browser/Options/Classes/Particles/Size/Size.js +1 -0
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/browser/Options/Classes/Particles/Stroke.js +3 -0
- package/browser/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/browser/Options/Classes/ResizeEvent.js +2 -0
- package/browser/Options/Classes/ValueWithRandom.js +3 -4
- package/browser/Utils/CanvasUtils.js +44 -51
- package/browser/Utils/ColorUtils.js +51 -40
- package/browser/Utils/EventDispatcher.js +1 -0
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/MathUtils.js +12 -7
- package/browser/Utils/OptionsUtils.js +2 -2
- package/browser/Utils/Utils.js +109 -31
- package/browser/exports.js +1 -2
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +134 -101
- package/cjs/Core/Engine.js +29 -162
- package/cjs/Core/Particle.js +197 -183
- package/cjs/Core/ParticlesManager.js +363 -0
- package/cjs/Core/RenderManager.js +303 -0
- package/cjs/Core/Retina.js +6 -6
- package/cjs/Core/Utils/Constants.js +2 -2
- package/cjs/Core/Utils/EventListeners.js +67 -63
- package/cjs/Core/Utils/PluginManager.js +145 -0
- package/cjs/Core/Utils/Ranges.js +29 -10
- package/cjs/Core/Utils/SpatialHashGrid.js +102 -0
- package/cjs/Core/Utils/Vectors.js +17 -18
- package/cjs/Options/Classes/AnimatableColor.js +1 -0
- package/cjs/Options/Classes/AnimationOptions.js +8 -0
- package/cjs/Options/Classes/Background/Background.js +6 -0
- package/cjs/Options/Classes/ColorAnimation.js +12 -1
- package/cjs/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/cjs/Options/Classes/HslAnimation.js +4 -5
- package/cjs/Options/Classes/Options.js +67 -8
- package/cjs/Options/Classes/OptionsColor.js +1 -0
- package/cjs/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/cjs/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/cjs/Options/Classes/Particles/Fill.js +28 -0
- package/cjs/Options/Classes/Particles/Move/Move.js +17 -3
- package/cjs/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/cjs/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/cjs/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/cjs/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Spin.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/cjs/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/cjs/Options/Classes/Particles/Size/Size.js +1 -0
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/cjs/Options/Classes/Particles/Stroke.js +3 -0
- package/cjs/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/cjs/Options/Classes/ResizeEvent.js +2 -0
- package/cjs/Options/Classes/ValueWithRandom.js +3 -4
- package/cjs/Utils/CanvasUtils.js +44 -51
- package/cjs/Utils/ColorUtils.js +51 -40
- package/cjs/Utils/EventDispatcher.js +1 -0
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/MathUtils.js +12 -7
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/cjs/Utils/Utils.js +109 -31
- package/cjs/exports.js +1 -2
- package/dist_browser_Core_Container_js.js +30 -20
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +134 -101
- package/esm/Core/Engine.js +29 -162
- package/esm/Core/Particle.js +197 -183
- package/esm/Core/ParticlesManager.js +363 -0
- package/esm/Core/RenderManager.js +303 -0
- package/esm/Core/Retina.js +6 -6
- package/esm/Core/Utils/Constants.js +2 -2
- package/esm/Core/Utils/EventListeners.js +67 -63
- package/esm/Core/Utils/PluginManager.js +145 -0
- package/esm/Core/Utils/Ranges.js +29 -10
- package/esm/Core/Utils/SpatialHashGrid.js +102 -0
- package/esm/Core/Utils/Vectors.js +17 -18
- package/esm/Options/Classes/AnimatableColor.js +1 -0
- package/esm/Options/Classes/AnimationOptions.js +8 -0
- package/esm/Options/Classes/Background/Background.js +6 -0
- package/esm/Options/Classes/ColorAnimation.js +12 -1
- package/esm/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/esm/Options/Classes/HslAnimation.js +4 -5
- package/esm/Options/Classes/Options.js +67 -8
- package/esm/Options/Classes/OptionsColor.js +1 -0
- package/esm/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/esm/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/esm/Options/Classes/Particles/Fill.js +28 -0
- package/esm/Options/Classes/Particles/Move/Move.js +17 -3
- package/esm/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/esm/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/esm/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/esm/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/esm/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/esm/Options/Classes/Particles/Move/Spin.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/esm/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/esm/Options/Classes/Particles/Size/Size.js +1 -0
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/esm/Options/Classes/Particles/Stroke.js +3 -0
- package/esm/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/esm/Options/Classes/ResizeEvent.js +2 -0
- package/esm/Options/Classes/ValueWithRandom.js +3 -4
- package/esm/Utils/CanvasUtils.js +44 -51
- package/esm/Utils/ColorUtils.js +51 -40
- package/esm/Utils/EventDispatcher.js +1 -0
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/MathUtils.js +12 -7
- package/esm/Utils/OptionsUtils.js +2 -2
- package/esm/Utils/Utils.js +109 -31
- package/esm/exports.js +1 -2
- package/package.json +1 -1
- package/report.html +84 -29
- package/scripts/install.js +4 -20
- package/tsparticles.engine.js +98 -86
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/CanvasManager.d.ts +39 -0
- package/types/Core/Container.d.ts +29 -14
- package/types/Core/Engine.d.ts +2 -61
- package/types/Core/Interfaces/IColorManager.d.ts +0 -1
- package/types/Core/Interfaces/IContainerPlugin.d.ts +10 -8
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
- package/types/Core/Interfaces/IPalette.d.ts +7 -0
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
- package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
- package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -1
- package/types/Core/Interfaces/IShapeDrawer.d.ts +0 -1
- package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
- package/types/Core/Particle.d.ts +7 -11
- package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +15 -14
- package/types/Core/RenderManager.d.ts +49 -0
- package/types/Core/Retina.d.ts +0 -2
- package/types/Core/Utils/Constants.d.ts +2 -2
- package/types/Core/Utils/PluginManager.d.ts +62 -0
- package/types/Core/Utils/Ranges.d.ts +4 -1
- package/types/Core/Utils/SpatialHashGrid.d.ts +25 -0
- package/types/Core/Utils/Vectors.d.ts +8 -10
- package/types/Options/Classes/ColorAnimation.d.ts +3 -1
- package/types/Options/Classes/HslAnimation.d.ts +3 -4
- package/types/Options/Classes/Options.d.ts +5 -3
- package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
- package/types/Options/Classes/Particles/Fill.d.ts +12 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +5 -5
- package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
- package/types/Options/Classes/ValueWithRandom.d.ts +0 -1
- package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
- package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
- package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
- package/types/Types/CanvasContextType.d.ts +1 -0
- package/types/Types/EngineInitializers.d.ts +6 -3
- package/types/Utils/CanvasUtils.d.ts +13 -16
- package/types/Utils/ColorUtils.d.ts +11 -10
- package/types/Utils/LogUtils.d.ts +1 -0
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/Utils/OptionsUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +8 -1
- package/types/export-types.d.ts +7 -7
- package/types/exports.d.ts +1 -2
- package/umd/Core/CanvasManager.js +317 -0
- package/umd/Core/Container.js +134 -101
- package/umd/Core/Engine.js +28 -161
- package/umd/Core/Particle.js +198 -184
- package/umd/Core/{Particles.js → ParticlesManager.js} +186 -167
- package/umd/Core/RenderManager.js +317 -0
- package/umd/Core/Retina.js +6 -6
- package/umd/Core/Utils/Constants.js +3 -3
- package/umd/Core/Utils/EventListeners.js +67 -63
- package/umd/Core/Utils/PluginManager.js +159 -0
- package/umd/Core/Utils/Ranges.js +28 -9
- package/umd/Core/Utils/SpatialHashGrid.js +116 -0
- package/umd/Core/Utils/Vectors.js +17 -18
- package/umd/Options/Classes/AnimatableColor.js +1 -0
- package/umd/Options/Classes/AnimationOptions.js +8 -0
- package/umd/Options/Classes/Background/Background.js +6 -0
- package/umd/Options/Classes/ColorAnimation.js +12 -1
- package/umd/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/umd/Options/Classes/HslAnimation.js +5 -6
- package/umd/Options/Classes/Options.js +67 -8
- package/umd/Options/Classes/OptionsColor.js +1 -0
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/umd/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/umd/Options/Classes/Particles/Fill.js +42 -0
- package/umd/Options/Classes/Particles/Move/Move.js +18 -4
- package/umd/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/umd/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/umd/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/umd/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/umd/Options/Classes/Particles/Move/Spin.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/umd/Options/Classes/Particles/ParticlesOptions.js +30 -10
- package/umd/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/umd/Options/Classes/Particles/Size/Size.js +1 -0
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/umd/Options/Classes/Particles/Stroke.js +3 -0
- package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/umd/Options/Classes/ResizeEvent.js +2 -0
- package/umd/Options/Classes/ValueWithRandom.js +3 -4
- package/umd/Utils/CanvasUtils.js +44 -53
- package/umd/Utils/ColorUtils.js +51 -39
- package/umd/Utils/EventDispatcher.js +1 -0
- package/umd/Utils/LogUtils.js +1 -0
- package/umd/Utils/MathUtils.js +14 -7
- package/umd/Utils/OptionsUtils.js +2 -2
- package/umd/Utils/Utils.js +111 -32
- package/umd/exports.js +2 -3
- package/794.min.js +0 -2
- package/794.min.js.LICENSE.txt +0 -1
- package/browser/Core/Canvas.js +0 -469
- package/browser/Core/Particles.js +0 -344
- package/browser/Core/Utils/Point.js +0 -6
- package/browser/Core/Utils/QuadTree.js +0 -59
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/cjs/Core/Canvas.js +0 -469
- package/cjs/Core/Particles.js +0 -344
- package/cjs/Core/Utils/Point.js +0 -6
- package/cjs/Core/Utils/QuadTree.js +0 -59
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/esm/Core/Canvas.js +0 -469
- package/esm/Core/Particles.js +0 -344
- package/esm/Core/Utils/Point.js +0 -6
- package/esm/Core/Utils/QuadTree.js +0 -59
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/tsparticles.engine.min.js.LICENSE.txt +0 -1
- package/types/Core/Canvas.d.ts +0 -55
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -10
- package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
- package/types/Core/Utils/Point.d.ts +0 -7
- package/types/Core/Utils/QuadTree.d.ts +0 -18
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
- package/umd/Core/Canvas.js +0 -483
- package/umd/Core/Utils/Point.js +0 -20
- package/umd/Core/Utils/QuadTree.js +0 -73
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -47
- /package/browser/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/browser/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/browser/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/cjs/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/cjs/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/esm/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/esm/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/esm/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/umd/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/umd/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/umd/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { animate, cancelAnimation, getRangeValue } from "../Utils/MathUtils.js";
|
|
2
|
-
import { defaultFps, defaultFpsLimit, millisecondsToSeconds, minFpsLimit
|
|
3
|
-
import {
|
|
2
|
+
import { defaultFps, defaultFpsLimit, millisecondsToSeconds, minFpsLimit } from "./Utils/Constants.js";
|
|
3
|
+
import { CanvasManager } from "./CanvasManager.js";
|
|
4
4
|
import { EventListeners } from "./Utils/EventListeners.js";
|
|
5
5
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
6
6
|
import { Options } from "../Options/Classes/Options.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ParticlesManager } from "./ParticlesManager.js";
|
|
8
8
|
import { Retina } from "./Retina.js";
|
|
9
9
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
10
10
|
import { loadOptions } from "../Utils/OptionsUtils.js";
|
|
@@ -15,44 +15,52 @@ function updateDelta(delta, value, fpsLimit = defaultFps, smooth = false) {
|
|
|
15
15
|
delta.value = value;
|
|
16
16
|
delta.factor = smooth ? defaultFps / fpsLimit : (defaultFps * value) / millisecondsToSeconds;
|
|
17
17
|
}
|
|
18
|
-
function loadContainerOptions(
|
|
19
|
-
const options = new Options(
|
|
18
|
+
function loadContainerOptions(pluginManager, container, ...sourceOptionsArr) {
|
|
19
|
+
const options = new Options(pluginManager, container);
|
|
20
20
|
loadOptions(options, ...sourceOptionsArr);
|
|
21
21
|
return options;
|
|
22
22
|
}
|
|
23
23
|
export class Container {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
24
|
+
actualOptions;
|
|
25
|
+
canvas;
|
|
26
|
+
destroyed;
|
|
27
|
+
effectDrawers;
|
|
28
|
+
fpsLimit;
|
|
29
|
+
hdr;
|
|
30
|
+
id;
|
|
31
|
+
pageHidden;
|
|
32
|
+
particleCreatedPlugins;
|
|
33
|
+
particleDestroyedPlugins;
|
|
34
|
+
particlePositionPlugins;
|
|
35
|
+
particleUpdaters;
|
|
36
|
+
particles;
|
|
37
|
+
plugins;
|
|
38
|
+
retina;
|
|
39
|
+
shapeDrawers;
|
|
40
|
+
started;
|
|
41
|
+
zLayers;
|
|
42
|
+
_delay;
|
|
43
|
+
_delayTimeout;
|
|
44
|
+
_delta = { value: 0, factor: 0 };
|
|
45
|
+
_dispatchCallback;
|
|
46
|
+
_drawAnimationFrame;
|
|
47
|
+
_duration;
|
|
48
|
+
_eventListeners;
|
|
49
|
+
_firstStart;
|
|
50
|
+
_initialSourceOptions;
|
|
51
|
+
_lastFrameTime;
|
|
52
|
+
_lifeTime;
|
|
53
|
+
_onDestroy;
|
|
54
|
+
_options;
|
|
55
|
+
_paused;
|
|
56
|
+
_pluginManager;
|
|
57
|
+
_smooth;
|
|
58
|
+
_sourceOptions;
|
|
59
|
+
constructor(params) {
|
|
60
|
+
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
61
|
+
this._pluginManager = pluginManager;
|
|
62
|
+
this._dispatchCallback = dispatchCallback;
|
|
63
|
+
this._onDestroy = onDestroy;
|
|
56
64
|
this.id = Symbol(id);
|
|
57
65
|
this.fpsLimit = 120;
|
|
58
66
|
this.hdr = false;
|
|
@@ -69,17 +77,20 @@ export class Container {
|
|
|
69
77
|
this.pageHidden = false;
|
|
70
78
|
this._sourceOptions = sourceOptions;
|
|
71
79
|
this._initialSourceOptions = sourceOptions;
|
|
72
|
-
this.retina = new Retina(this);
|
|
73
|
-
this.canvas = new Canvas(this, this._engine);
|
|
74
|
-
this.particles = new Particles(this._engine, this);
|
|
75
|
-
this.pathGenerators = new Map();
|
|
76
|
-
this.plugins = [];
|
|
77
80
|
this.effectDrawers = new Map();
|
|
78
81
|
this.shapeDrawers = new Map();
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
82
|
+
this.particleUpdaters = [];
|
|
83
|
+
this.retina = new Retina(this);
|
|
84
|
+
this.canvas = new CanvasManager(this._pluginManager, this);
|
|
85
|
+
this.particles = new ParticlesManager(this._pluginManager, this);
|
|
86
|
+
this.plugins = [];
|
|
87
|
+
this.particleDestroyedPlugins = [];
|
|
88
|
+
this.particleCreatedPlugins = [];
|
|
89
|
+
this.particlePositionPlugins = [];
|
|
90
|
+
this._options = loadContainerOptions(this._pluginManager, this);
|
|
91
|
+
this.actualOptions = loadContainerOptions(this._pluginManager, this);
|
|
81
92
|
this._eventListeners = new EventListeners(this);
|
|
82
|
-
this.
|
|
93
|
+
this.dispatchEvent(EventType.containerBuilt);
|
|
83
94
|
}
|
|
84
95
|
get animationStatus() {
|
|
85
96
|
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
@@ -93,13 +104,6 @@ export class Container {
|
|
|
93
104
|
addLifeTime(value) {
|
|
94
105
|
this._lifeTime += value;
|
|
95
106
|
}
|
|
96
|
-
addPath(key, generator, override = false) {
|
|
97
|
-
if (!guardCheck(this) || (!override && this.pathGenerators.has(key))) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
this.pathGenerators.set(key, generator);
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
107
|
alive() {
|
|
104
108
|
return !this._duration || this._lifeTime <= this._duration;
|
|
105
109
|
}
|
|
@@ -110,42 +114,41 @@ export class Container {
|
|
|
110
114
|
this.stop();
|
|
111
115
|
this.particles.destroy();
|
|
112
116
|
this.canvas.destroy();
|
|
113
|
-
for (const effectDrawer of this.effectDrawers
|
|
117
|
+
for (const [, effectDrawer] of this.effectDrawers) {
|
|
114
118
|
effectDrawer.destroy?.(this);
|
|
115
119
|
}
|
|
116
|
-
this.
|
|
117
|
-
for (const shapeDrawer of this.shapeDrawers.values()) {
|
|
120
|
+
for (const [, shapeDrawer] of this.shapeDrawers) {
|
|
118
121
|
shapeDrawer.destroy?.(this);
|
|
119
122
|
}
|
|
120
|
-
this.shapeDrawers.clear();
|
|
121
123
|
for (const plugin of this.plugins) {
|
|
122
124
|
plugin.destroy?.();
|
|
123
125
|
}
|
|
126
|
+
this.effectDrawers = new Map();
|
|
127
|
+
this.shapeDrawers = new Map();
|
|
128
|
+
this.particleUpdaters = [];
|
|
124
129
|
this.plugins.length = 0;
|
|
125
|
-
this.
|
|
130
|
+
this._pluginManager.clearPlugins(this);
|
|
126
131
|
this.destroyed = true;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
this._onDestroy(remove);
|
|
133
|
+
this.dispatchEvent(EventType.containerDestroyed);
|
|
134
|
+
}
|
|
135
|
+
dispatchEvent(type, data) {
|
|
136
|
+
this._dispatchCallback(type, {
|
|
137
|
+
container: this,
|
|
138
|
+
data,
|
|
139
|
+
});
|
|
134
140
|
}
|
|
135
141
|
draw(force) {
|
|
136
142
|
if (!guardCheck(this)) {
|
|
137
143
|
return;
|
|
138
144
|
}
|
|
139
145
|
let refreshTime = force;
|
|
140
|
-
|
|
146
|
+
this._drawAnimationFrame = animate((timestamp) => {
|
|
141
147
|
if (refreshTime) {
|
|
142
148
|
this._lastFrameTime = undefined;
|
|
143
149
|
refreshTime = false;
|
|
144
150
|
}
|
|
145
151
|
this._nextFrame(timestamp);
|
|
146
|
-
};
|
|
147
|
-
this._drawAnimationFrame = animate(timestamp => {
|
|
148
|
-
frame(timestamp);
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
async export(type, options = {}) {
|
|
@@ -166,34 +169,33 @@ export class Container {
|
|
|
166
169
|
if (!guardCheck(this)) {
|
|
167
170
|
return;
|
|
168
171
|
}
|
|
169
|
-
const effects = this._engine.getSupportedEffects();
|
|
170
|
-
for (const type of effects) {
|
|
171
|
-
const drawer = this._engine.getEffectDrawer(type);
|
|
172
|
-
if (drawer) {
|
|
173
|
-
this.effectDrawers.set(type, drawer);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const shapes = this._engine.getSupportedShapes();
|
|
177
|
-
for (const type of shapes) {
|
|
178
|
-
const drawer = this._engine.getShapeDrawer(type);
|
|
179
|
-
if (drawer) {
|
|
180
|
-
this.shapeDrawers.set(type, drawer);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
172
|
const allContainerPlugins = new Map();
|
|
184
|
-
for (const plugin of this.
|
|
173
|
+
for (const plugin of this._pluginManager.plugins) {
|
|
185
174
|
const containerPlugin = await plugin.getPlugin(this);
|
|
186
175
|
if (containerPlugin.preInit) {
|
|
187
176
|
await containerPlugin.preInit();
|
|
188
177
|
}
|
|
189
178
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
190
179
|
}
|
|
191
|
-
await this.
|
|
192
|
-
this._options = loadContainerOptions(this.
|
|
193
|
-
this.actualOptions = loadContainerOptions(this.
|
|
180
|
+
await this.initDrawersAndUpdaters();
|
|
181
|
+
this._options = loadContainerOptions(this._pluginManager, this, this._initialSourceOptions, this.sourceOptions);
|
|
182
|
+
this.actualOptions = loadContainerOptions(this._pluginManager, this, this._options);
|
|
183
|
+
this.plugins.length = 0;
|
|
184
|
+
this.particleDestroyedPlugins.length = 0;
|
|
185
|
+
this.particleCreatedPlugins.length = 0;
|
|
186
|
+
this.particlePositionPlugins.length = 0;
|
|
194
187
|
for (const [plugin, containerPlugin] of allContainerPlugins) {
|
|
195
188
|
if (plugin.needsPlugin(this.actualOptions)) {
|
|
196
189
|
this.plugins.push(containerPlugin);
|
|
190
|
+
if (containerPlugin.particleCreated) {
|
|
191
|
+
this.particleCreatedPlugins.push(containerPlugin);
|
|
192
|
+
}
|
|
193
|
+
if (containerPlugin.particleDestroyed) {
|
|
194
|
+
this.particleDestroyedPlugins.push(containerPlugin);
|
|
195
|
+
}
|
|
196
|
+
if (containerPlugin.particlePosition) {
|
|
197
|
+
this.particlePositionPlugins.push(containerPlugin);
|
|
198
|
+
}
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
201
|
this.retina.init();
|
|
@@ -212,19 +214,19 @@ export class Container {
|
|
|
212
214
|
for (const plugin of this.plugins) {
|
|
213
215
|
await plugin.init?.();
|
|
214
216
|
}
|
|
215
|
-
for (const drawer of this.effectDrawers.values()) {
|
|
216
|
-
await drawer.init?.(this);
|
|
217
|
-
}
|
|
218
|
-
for (const drawer of this.shapeDrawers.values()) {
|
|
219
|
-
await drawer.init?.(this);
|
|
220
|
-
}
|
|
221
|
-
this._engine.dispatchEvent(EventType.containerInit, { container: this });
|
|
222
217
|
await this.particles.init();
|
|
218
|
+
this.dispatchEvent(EventType.containerInit);
|
|
223
219
|
this.particles.setDensity();
|
|
224
220
|
for (const plugin of this.plugins) {
|
|
225
221
|
plugin.particlesSetup?.();
|
|
226
222
|
}
|
|
227
|
-
this.
|
|
223
|
+
this.dispatchEvent(EventType.particlesSetup);
|
|
224
|
+
}
|
|
225
|
+
async initDrawersAndUpdaters() {
|
|
226
|
+
const pluginManager = this._pluginManager;
|
|
227
|
+
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
228
|
+
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
229
|
+
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
228
230
|
}
|
|
229
231
|
pause() {
|
|
230
232
|
if (!guardCheck(this)) {
|
|
@@ -243,7 +245,7 @@ export class Container {
|
|
|
243
245
|
if (!this.pageHidden) {
|
|
244
246
|
this._paused = true;
|
|
245
247
|
}
|
|
246
|
-
this.
|
|
248
|
+
this.dispatchEvent(EventType.containerPaused);
|
|
247
249
|
}
|
|
248
250
|
play(force) {
|
|
249
251
|
if (!guardCheck(this)) {
|
|
@@ -264,7 +266,7 @@ export class Container {
|
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
|
-
this.
|
|
269
|
+
this.dispatchEvent(EventType.containerPlay);
|
|
268
270
|
this.draw(needsUpdate ?? false);
|
|
269
271
|
}
|
|
270
272
|
async refresh() {
|
|
@@ -280,8 +282,8 @@ export class Container {
|
|
|
280
282
|
}
|
|
281
283
|
this._initialSourceOptions = sourceOptions;
|
|
282
284
|
this._sourceOptions = sourceOptions;
|
|
283
|
-
this._options = loadContainerOptions(this.
|
|
284
|
-
this.actualOptions = loadContainerOptions(this.
|
|
285
|
+
this._options = loadContainerOptions(this._pluginManager, this, this._initialSourceOptions, this.sourceOptions);
|
|
286
|
+
this.actualOptions = loadContainerOptions(this._pluginManager, this, this._options);
|
|
285
287
|
return this.refresh();
|
|
286
288
|
}
|
|
287
289
|
async start() {
|
|
@@ -296,7 +298,7 @@ export class Container {
|
|
|
296
298
|
for (const plugin of this.plugins) {
|
|
297
299
|
await plugin.start?.();
|
|
298
300
|
}
|
|
299
|
-
this.
|
|
301
|
+
this.dispatchEvent(EventType.containerStarted);
|
|
300
302
|
this.play();
|
|
301
303
|
resolve();
|
|
302
304
|
};
|
|
@@ -320,9 +322,11 @@ export class Container {
|
|
|
320
322
|
for (const plugin of this.plugins) {
|
|
321
323
|
plugin.stop?.();
|
|
322
324
|
}
|
|
323
|
-
this.
|
|
325
|
+
this.particleCreatedPlugins.length = 0;
|
|
326
|
+
this.particleDestroyedPlugins.length = 0;
|
|
327
|
+
this.particlePositionPlugins.length = 0;
|
|
324
328
|
this._sourceOptions = this._options;
|
|
325
|
-
this.
|
|
329
|
+
this.dispatchEvent(EventType.containerStopped);
|
|
326
330
|
}
|
|
327
331
|
updateActualOptions() {
|
|
328
332
|
let refresh = false;
|
|
@@ -333,4 +337,33 @@ export class Container {
|
|
|
333
337
|
}
|
|
334
338
|
return refresh;
|
|
335
339
|
}
|
|
340
|
+
_nextFrame = (timestamp) => {
|
|
341
|
+
try {
|
|
342
|
+
if (!this._smooth &&
|
|
343
|
+
this._lastFrameTime !== undefined &&
|
|
344
|
+
timestamp < this._lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
345
|
+
this.draw(false);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
this._lastFrameTime ??= timestamp;
|
|
349
|
+
updateDelta(this._delta, timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
|
|
350
|
+
this.addLifeTime(this._delta.value);
|
|
351
|
+
this._lastFrameTime = timestamp;
|
|
352
|
+
if (this._delta.value > millisecondsToSeconds) {
|
|
353
|
+
this.draw(false);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
this.canvas.render.drawParticles(this._delta);
|
|
357
|
+
if (!this.alive()) {
|
|
358
|
+
this.destroy();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (this.animationStatus) {
|
|
362
|
+
this.draw(false);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch (e) {
|
|
366
|
+
getLogger().error("error in animation loop", e);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
336
369
|
}
|
package/browser/Core/Engine.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { canvasFirstIndex, canvasTag, generatedAttribute, generatedFalse, generatedTrue, loadMinIndex, loadRandomFactor, none, one, removeDeleteCount, } from "./Utils/Constants.js";
|
|
2
|
-
import {
|
|
1
|
+
import { canvasFirstIndex, canvasTag, generatedAttribute, generatedFalse, generatedTrue, loadMinIndex, loadRandomFactor, none, one, removeDeleteCount, removeMinIndex, } from "./Utils/Constants.js";
|
|
2
|
+
import { itemFromSingleOrMultiple, safeDocument } from "../Utils/Utils.js";
|
|
3
3
|
import { EventDispatcher } from "../Utils/EventDispatcher.js";
|
|
4
|
-
import {
|
|
4
|
+
import { PluginManager } from "./Utils/PluginManager.js";
|
|
5
5
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
6
6
|
import { getRandom } from "../Utils/MathUtils.js";
|
|
7
7
|
const fullPercent = "100%";
|
|
@@ -45,163 +45,41 @@ const getCanvasFromContainer = (domContainer) => {
|
|
|
45
45
|
if (domContainer) {
|
|
46
46
|
return domContainer;
|
|
47
47
|
}
|
|
48
|
-
domContainer = documentSafe.createElement("
|
|
48
|
+
domContainer = documentSafe.createElement("canvas");
|
|
49
49
|
domContainer.id = id;
|
|
50
50
|
domContainer.dataset[generatedAttribute] = generatedTrue;
|
|
51
51
|
documentSafe.body.append(domContainer);
|
|
52
52
|
return domContainer;
|
|
53
53
|
};
|
|
54
54
|
export class Engine {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this._initialized = false;
|
|
60
|
-
this._isRunningLoaders = false;
|
|
61
|
-
this._loadPromises = new Set();
|
|
62
|
-
this._allLoadersSet = new Set();
|
|
63
|
-
this._executedSet = new Set();
|
|
64
|
-
this.plugins = [];
|
|
65
|
-
this.colorManagers = new Map();
|
|
66
|
-
this.easingFunctions = new Map();
|
|
67
|
-
this._initializers = {
|
|
68
|
-
movers: new Map(),
|
|
69
|
-
updaters: new Map(),
|
|
70
|
-
};
|
|
71
|
-
this.movers = new Map();
|
|
72
|
-
this.updaters = new Map();
|
|
73
|
-
this.presets = new Map();
|
|
74
|
-
this.effectDrawers = new Map();
|
|
75
|
-
this.shapeDrawers = new Map();
|
|
76
|
-
this.pathGenerators = new Map();
|
|
77
|
-
}
|
|
78
|
-
get configs() {
|
|
79
|
-
const res = {};
|
|
80
|
-
for (const [name, config] of this._configs) {
|
|
81
|
-
res[name] = config;
|
|
82
|
-
}
|
|
83
|
-
return res;
|
|
84
|
-
}
|
|
55
|
+
pluginManager = new PluginManager(this);
|
|
56
|
+
_domArray = [];
|
|
57
|
+
_eventDispatcher = new EventDispatcher();
|
|
58
|
+
_initialized = false;
|
|
85
59
|
get items() {
|
|
86
60
|
return this._domArray;
|
|
87
61
|
}
|
|
88
62
|
get version() {
|
|
89
|
-
return "4.0.0-
|
|
90
|
-
}
|
|
91
|
-
addColorManager(manager) {
|
|
92
|
-
this.colorManagers.set(manager.key, manager);
|
|
93
|
-
}
|
|
94
|
-
addConfig(config) {
|
|
95
|
-
const key = config.key ?? config.name ?? "default";
|
|
96
|
-
this._configs.set(key, config);
|
|
97
|
-
this._eventDispatcher.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
98
|
-
}
|
|
99
|
-
addEasing(name, easing) {
|
|
100
|
-
if (this.easingFunctions.get(name)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
this.easingFunctions.set(name, easing);
|
|
104
|
-
}
|
|
105
|
-
addEffect(effect, drawer) {
|
|
106
|
-
if (this.getEffectDrawer(effect)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.effectDrawers.set(effect, drawer);
|
|
63
|
+
return "4.0.0-beta.1";
|
|
110
64
|
}
|
|
111
65
|
addEventListener(type, listener) {
|
|
112
66
|
this._eventDispatcher.addEventListener(type, listener);
|
|
113
67
|
}
|
|
114
|
-
addMover(name, moverInitializer) {
|
|
115
|
-
this._initializers.movers.set(name, moverInitializer);
|
|
116
|
-
}
|
|
117
|
-
addParticleUpdater(name, updaterInitializer) {
|
|
118
|
-
this._initializers.updaters.set(name, updaterInitializer);
|
|
119
|
-
}
|
|
120
|
-
addPathGenerator(name, generator) {
|
|
121
|
-
if (this.getPathGenerator(name)) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.pathGenerators.set(name, generator);
|
|
125
|
-
}
|
|
126
|
-
addPlugin(plugin) {
|
|
127
|
-
if (this.getPlugin(plugin.id)) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
this.plugins.push(plugin);
|
|
131
|
-
}
|
|
132
|
-
addPreset(preset, options, override = false) {
|
|
133
|
-
if (!(override || !this.getPreset(preset))) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
this.presets.set(preset, options);
|
|
137
|
-
}
|
|
138
|
-
addShape(drawer) {
|
|
139
|
-
for (const validType of drawer.validTypes) {
|
|
140
|
-
if (this.getShapeDrawer(validType)) {
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
this.shapeDrawers.set(validType, drawer);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
68
|
checkVersion(pluginVersion) {
|
|
147
69
|
if (this.version === pluginVersion) {
|
|
148
70
|
return;
|
|
149
71
|
}
|
|
150
72
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
151
73
|
}
|
|
152
|
-
clearPlugins(container) {
|
|
153
|
-
this.updaters.delete(container);
|
|
154
|
-
this.movers.delete(container);
|
|
155
|
-
}
|
|
156
74
|
dispatchEvent(type, args) {
|
|
157
75
|
this._eventDispatcher.dispatchEvent(type, args);
|
|
158
76
|
}
|
|
159
|
-
getEasing(name) {
|
|
160
|
-
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
161
|
-
}
|
|
162
|
-
getEffectDrawer(type) {
|
|
163
|
-
return this.effectDrawers.get(type);
|
|
164
|
-
}
|
|
165
|
-
async getMovers(container, force = false) {
|
|
166
|
-
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
167
|
-
}
|
|
168
|
-
getPathGenerator(type) {
|
|
169
|
-
return this.pathGenerators.get(type);
|
|
170
|
-
}
|
|
171
|
-
getPlugin(plugin) {
|
|
172
|
-
return this.plugins.find(t => t.id === plugin);
|
|
173
|
-
}
|
|
174
|
-
getPreset(preset) {
|
|
175
|
-
return this.presets.get(preset);
|
|
176
|
-
}
|
|
177
|
-
getShapeDrawer(type) {
|
|
178
|
-
return this.shapeDrawers.get(type);
|
|
179
|
-
}
|
|
180
|
-
getSupportedEffects() {
|
|
181
|
-
return this.effectDrawers.keys();
|
|
182
|
-
}
|
|
183
|
-
getSupportedShapes() {
|
|
184
|
-
return this.shapeDrawers.keys();
|
|
185
|
-
}
|
|
186
|
-
async getUpdaters(container, force = false) {
|
|
187
|
-
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
188
|
-
}
|
|
189
77
|
async init() {
|
|
190
|
-
if (this._initialized
|
|
78
|
+
if (this._initialized) {
|
|
191
79
|
return;
|
|
192
|
-
this._isRunningLoaders = true;
|
|
193
|
-
this._executedSet = new Set();
|
|
194
|
-
this._allLoadersSet = new Set(this._loadPromises);
|
|
195
|
-
try {
|
|
196
|
-
for (const loader of this._allLoadersSet) {
|
|
197
|
-
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
finally {
|
|
201
|
-
this._loadPromises.clear();
|
|
202
|
-
this._isRunningLoaders = false;
|
|
203
|
-
this._initialized = true;
|
|
204
80
|
}
|
|
81
|
+
await this.pluginManager.init();
|
|
82
|
+
this._initialized = true;
|
|
205
83
|
}
|
|
206
84
|
item(index) {
|
|
207
85
|
const { items } = this, item = items[index];
|
|
@@ -213,7 +91,23 @@ export class Engine {
|
|
|
213
91
|
}
|
|
214
92
|
async load(params) {
|
|
215
93
|
await this.init();
|
|
216
|
-
const { Container } = await import("./Container.js"), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(
|
|
94
|
+
const { Container } = await import("./Container.js"), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
|
|
95
|
+
dispatchCallback: (eventType, args) => {
|
|
96
|
+
this.dispatchEvent(eventType, args);
|
|
97
|
+
},
|
|
98
|
+
id,
|
|
99
|
+
onDestroy: (remove) => {
|
|
100
|
+
if (!remove) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const mainArr = this.items, idx = mainArr.indexOf(newItem);
|
|
104
|
+
if (idx >= removeMinIndex) {
|
|
105
|
+
mainArr.splice(idx, removeDeleteCount);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
pluginManager: this.pluginManager,
|
|
109
|
+
sourceOptions: currentOptions,
|
|
110
|
+
});
|
|
217
111
|
if (oldIndex >= loadMinIndex) {
|
|
218
112
|
const old = this.item(oldIndex), deleteCount = old ? one : none;
|
|
219
113
|
if (old && !old.destroyed) {
|
|
@@ -229,40 +123,13 @@ export class Engine {
|
|
|
229
123
|
await newItem.start();
|
|
230
124
|
return newItem;
|
|
231
125
|
}
|
|
232
|
-
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
233
|
-
const updaters = this.updaters.get(container);
|
|
234
|
-
if (!updaters) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
238
|
-
}
|
|
239
126
|
async refresh(refresh = true) {
|
|
240
127
|
if (!refresh) {
|
|
241
128
|
return;
|
|
242
129
|
}
|
|
243
130
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
244
131
|
}
|
|
245
|
-
async register(...loaders) {
|
|
246
|
-
if (this._initialized) {
|
|
247
|
-
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
248
|
-
}
|
|
249
|
-
for (const loader of loaders) {
|
|
250
|
-
if (this._isRunningLoaders) {
|
|
251
|
-
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
this._loadPromises.add(loader);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
132
|
removeEventListener(type, listener) {
|
|
259
133
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
260
134
|
}
|
|
261
|
-
async _runLoader(loader, executed, allLoaders) {
|
|
262
|
-
if (executed.has(loader))
|
|
263
|
-
return;
|
|
264
|
-
executed.add(loader);
|
|
265
|
-
allLoaders.add(loader);
|
|
266
|
-
await loader(this);
|
|
267
|
-
}
|
|
268
135
|
}
|