@tsparticles/engine 3.0.0-alpha.1 → 3.0.0-beta.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 +244 -188
- package/browser/Core/Canvas.js +271 -241
- package/browser/Core/Container.js +90 -106
- package/browser/Core/Engine.js +271 -0
- package/browser/Core/Particle.js +158 -165
- package/browser/Core/Particles.js +148 -143
- package/browser/Core/Retina.js +15 -13
- package/browser/Core/Utils/Circle.js +10 -6
- package/browser/Core/Utils/Constants.js +4 -3
- package/browser/Core/Utils/EventListeners.js +258 -234
- package/browser/Core/Utils/InteractionManager.js +6 -16
- package/browser/Core/Utils/QuadTree.js +14 -20
- package/browser/Core/Utils/Vector3d.js +17 -9
- package/browser/Options/Classes/AnimatableColor.js +2 -1
- package/browser/Options/Classes/AnimationOptions.js +4 -3
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
- package/browser/Options/Classes/ColorAnimation.js +4 -0
- package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
- package/browser/Options/Classes/Interactivity/Events/Events.js +5 -24
- package/browser/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/browser/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/browser/Options/Classes/ManualParticle.js +5 -6
- package/browser/Options/Classes/Options.js +19 -39
- package/browser/Options/Classes/OptionsColor.js +3 -2
- package/browser/Options/Classes/Particles/Collisions/Collisions.js +5 -0
- package/browser/Options/Classes/Particles/Move/Move.js +11 -41
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/browser/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/browser/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/browser/Options/Classes/Particles/Move/Spin.js +3 -1
- package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +11 -7
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/browser/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/browser/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/browser/Options/Classes/Particles/Size/Size.js +11 -7
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/browser/Options/Classes/ValueWithRandom.js +4 -17
- package/browser/Utils/CanvasUtils.js +18 -54
- package/browser/Utils/ColorUtils.js +17 -19
- package/browser/Utils/EventDispatcher.js +7 -6
- package/browser/Utils/HslColorManager.js +2 -4
- package/browser/Utils/NumberUtils.js +41 -45
- package/browser/Utils/RgbColorManager.js +2 -4
- package/browser/Utils/Utils.js +133 -62
- package/browser/bundle.js +4 -97
- package/browser/export-types.js +97 -0
- package/browser/exports.js +89 -0
- package/browser/index.js +8 -199
- package/browser/init.js +12 -0
- package/cjs/Core/Canvas.js +269 -239
- package/cjs/Core/Container.js +90 -106
- package/cjs/Core/Engine.js +275 -0
- package/cjs/Core/Particle.js +157 -164
- package/cjs/Core/Particles.js +148 -143
- package/cjs/Core/Retina.js +15 -13
- package/cjs/Core/Utils/Circle.js +10 -6
- package/cjs/Core/Utils/Constants.js +5 -4
- package/cjs/Core/Utils/EventListeners.js +257 -233
- package/cjs/Core/Utils/InteractionManager.js +6 -16
- package/cjs/Core/Utils/QuadTree.js +14 -20
- package/cjs/Core/Utils/Vector3d.js +17 -9
- package/cjs/Options/Classes/AnimatableColor.js +2 -1
- package/cjs/Options/Classes/AnimationOptions.js +4 -3
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
- package/cjs/Options/Classes/ColorAnimation.js +4 -0
- package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
- package/cjs/Options/Classes/Interactivity/Events/Events.js +5 -24
- package/cjs/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/cjs/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/cjs/Options/Classes/ManualParticle.js +5 -6
- package/cjs/Options/Classes/Options.js +18 -38
- package/cjs/Options/Classes/OptionsColor.js +3 -2
- package/cjs/Options/Classes/Particles/Collisions/Collisions.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Move.js +11 -41
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/cjs/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/cjs/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/cjs/Options/Classes/Particles/Move/Spin.js +3 -1
- package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +10 -6
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/cjs/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/cjs/Options/Classes/Particles/Size/Size.js +11 -7
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/cjs/Options/Classes/ValueWithRandom.js +4 -17
- package/cjs/Utils/CanvasUtils.js +21 -58
- package/cjs/Utils/ColorUtils.js +16 -18
- package/cjs/Utils/EventDispatcher.js +7 -6
- package/cjs/Utils/HslColorManager.js +2 -4
- package/cjs/Utils/NumberUtils.js +41 -45
- package/cjs/Utils/RgbColorManager.js +2 -4
- package/cjs/Utils/Utils.js +146 -66
- package/cjs/bundle.js +4 -97
- package/cjs/export-types.js +113 -0
- package/cjs/exports.js +105 -0
- package/cjs/index.js +8 -199
- package/cjs/init.js +16 -0
- package/esm/Core/Canvas.js +271 -241
- package/esm/Core/Container.js +90 -106
- package/esm/Core/Engine.js +271 -0
- package/esm/Core/Particle.js +158 -165
- package/esm/Core/Particles.js +148 -143
- package/esm/Core/Retina.js +15 -13
- package/esm/Core/Utils/Circle.js +10 -6
- package/esm/Core/Utils/Constants.js +4 -3
- package/esm/Core/Utils/EventListeners.js +258 -234
- package/esm/Core/Utils/InteractionManager.js +6 -16
- package/esm/Core/Utils/QuadTree.js +14 -20
- package/esm/Core/Utils/Vector3d.js +17 -9
- package/esm/Options/Classes/AnimatableColor.js +2 -1
- package/esm/Options/Classes/AnimationOptions.js +4 -3
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
- package/esm/Options/Classes/ColorAnimation.js +4 -0
- package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
- package/esm/Options/Classes/Interactivity/Events/Events.js +5 -24
- package/esm/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/esm/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/esm/Options/Classes/ManualParticle.js +5 -6
- package/esm/Options/Classes/Options.js +19 -39
- package/esm/Options/Classes/OptionsColor.js +3 -2
- package/esm/Options/Classes/Particles/Collisions/Collisions.js +5 -0
- package/esm/Options/Classes/Particles/Move/Move.js +11 -41
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/esm/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/esm/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/esm/Options/Classes/Particles/Move/Spin.js +3 -1
- package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +11 -7
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/esm/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/esm/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/esm/Options/Classes/Particles/Size/Size.js +11 -7
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/esm/Options/Classes/ValueWithRandom.js +4 -17
- package/esm/Utils/CanvasUtils.js +18 -54
- package/esm/Utils/ColorUtils.js +17 -19
- package/esm/Utils/EventDispatcher.js +7 -6
- package/esm/Utils/HslColorManager.js +2 -4
- package/esm/Utils/NumberUtils.js +41 -45
- package/esm/Utils/RgbColorManager.js +2 -4
- package/esm/Utils/Utils.js +133 -62
- package/esm/bundle.js +4 -97
- package/esm/export-types.js +97 -0
- package/esm/exports.js +89 -0
- package/esm/index.js +8 -199
- package/esm/init.js +12 -0
- package/package.json +17 -2
- package/report.html +4 -4
- package/scripts/install.js +90 -33
- package/tsparticles.engine.js +1832 -2007
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -10
- package/types/Core/Canvas.d.ts +20 -16
- package/types/Core/Container.d.ts +10 -14
- package/types/Core/Engine.d.ts +71 -0
- package/types/Core/Interfaces/IContainerPlugin.d.ts +2 -0
- package/types/Core/Interfaces/ICoordinates.d.ts +2 -2
- package/types/Core/Interfaces/IDimension.d.ts +2 -2
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -1
- package/types/Core/Interfaces/IParticleUpdater.d.ts +0 -2
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +2 -0
- package/types/Core/Interfaces/IPlugin.d.ts +4 -3
- package/types/Core/Particle.d.ts +7 -7
- package/types/Core/Particles.d.ts +14 -11
- package/types/Core/Utils/Constants.d.ts +4 -3
- package/types/Core/Utils/EventListeners.d.ts +20 -18
- package/types/Core/Utils/InteractionManager.d.ts +1 -1
- package/types/Core/Utils/QuadTree.d.ts +2 -5
- package/types/Core/Utils/Vector3d.d.ts +2 -1
- package/types/Enums/Modes/{SizeMode.d.ts → PixelMode.d.ts} +1 -1
- package/types/Options/Classes/AnimationOptions.d.ts +1 -1
- package/types/Options/Classes/ColorAnimation.d.ts +1 -0
- package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -6
- package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -6
- package/types/Options/Classes/Interactivity/Interactivity.d.ts +1 -3
- package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +5 -12
- package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +2 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -11
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -4
- package/types/Options/Classes/Particles/Move/MoveCenter.d.ts +2 -2
- package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +0 -3
- package/types/Options/Classes/Particles/Number/ParticlesDensity.d.ts +0 -6
- package/types/Options/Classes/Particles/Number/ParticlesNumber.d.ts +0 -2
- package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +4 -4
- package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -2
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -1
- package/types/Options/Classes/Particles/Size/Size.d.ts +4 -4
- package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -2
- package/types/Options/Classes/Responsive.d.ts +3 -3
- package/types/Options/Classes/Theme/Theme.d.ts +2 -2
- package/types/Options/Classes/ValueWithRandom.d.ts +2 -6
- package/types/Options/Interfaces/IAnimation.d.ts +1 -1
- package/types/Options/Interfaces/IOptions.d.ts +1 -4
- package/types/Options/Interfaces/IResponsive.d.ts +4 -3
- package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -3
- package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -3
- package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -1
- package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Collisions/ICollisions.d.ts +2 -0
- package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -1
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Move/IMoveTrail.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Number/IParticlesDensity.d.ts +0 -3
- package/types/Options/Interfaces/Particles/Number/IParticlesNumber.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -1
- package/types/Options/Interfaces/Theme/ITheme.d.ts +3 -2
- package/types/Types/ExportResult.d.ts +5 -0
- package/types/Utils/CanvasUtils.d.ts +2 -5
- package/types/Utils/OptionsUtils.d.ts +1 -1
- package/types/Utils/Utils.d.ts +22 -4
- package/types/bundle.d.ts +2 -91
- package/types/export-types.d.ts +107 -0
- package/types/exports.d.ts +89 -0
- package/types/index.d.ts +3 -204
- package/types/init.d.ts +2 -0
- package/umd/Core/Canvas.js +269 -239
- package/umd/Core/Container.js +91 -107
- package/umd/Core/Engine.js +285 -0
- package/umd/Core/Particle.js +158 -165
- package/umd/Core/Particles.js +149 -144
- package/umd/Core/Retina.js +15 -13
- package/umd/Core/Utils/Circle.js +11 -7
- package/umd/Core/Utils/Constants.js +5 -4
- package/umd/Core/Utils/EventListeners.js +257 -233
- package/umd/Core/Utils/InteractionManager.js +6 -16
- package/umd/Core/Utils/QuadTree.js +14 -20
- package/umd/Core/Utils/Vector3d.js +18 -10
- package/umd/Options/Classes/AnimatableColor.js +3 -2
- package/umd/Options/Classes/AnimationOptions.js +4 -3
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +3 -2
- package/umd/Options/Classes/ColorAnimation.js +4 -0
- package/umd/Options/Classes/Interactivity/Events/DivEvent.js +1 -25
- package/umd/Options/Classes/Interactivity/Events/Events.js +6 -25
- package/umd/Options/Classes/Interactivity/Interactivity.js +1 -8
- package/umd/Options/Classes/Interactivity/Modes/Modes.js +11 -8
- package/umd/Options/Classes/ManualParticle.js +5 -6
- package/umd/Options/Classes/Options.js +18 -38
- package/umd/Options/Classes/OptionsColor.js +4 -3
- package/umd/Options/Classes/Particles/Collisions/Collisions.js +6 -1
- package/umd/Options/Classes/Particles/Move/Move.js +12 -42
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +9 -20
- package/umd/Options/Classes/Particles/Move/MoveTrail.js +2 -8
- package/umd/Options/Classes/Particles/Move/OutModes.js +4 -5
- package/umd/Options/Classes/Particles/Move/Spin.js +3 -1
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +10 -6
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
- package/umd/Options/Classes/Particles/ParticlesOptions.js +6 -11
- package/umd/Options/Classes/Particles/Shape/Shape.js +9 -10
- package/umd/Options/Classes/Particles/Size/Size.js +12 -8
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
- package/umd/Options/Classes/ValueWithRandom.js +5 -18
- package/umd/Utils/CanvasUtils.js +21 -58
- package/umd/Utils/ColorUtils.js +16 -18
- package/umd/Utils/EventDispatcher.js +7 -6
- package/umd/Utils/HslColorManager.js +2 -4
- package/umd/Utils/NumberUtils.js +42 -46
- package/umd/Utils/RgbColorManager.js +2 -4
- package/umd/Utils/Utils.js +146 -66
- package/umd/bundle.js +5 -98
- package/umd/export-types.js +123 -0
- package/umd/exports.js +115 -0
- package/umd/index.js +9 -200
- package/umd/init.js +26 -0
- package/browser/Core/Utils/FrameManager.js +0 -42
- package/browser/Core/Utils/Plugins.js +0 -112
- package/browser/Options/Interfaces/Particles/Shape/IImageShape.js +0 -1
- package/browser/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -1
- package/browser/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -1
- package/browser/Options/Interfaces/Particles/Shape/IStarShape.js +0 -1
- package/browser/engine.js +0 -175
- package/cjs/Core/Utils/FrameManager.js +0 -46
- package/cjs/Core/Utils/Plugins.js +0 -116
- package/cjs/Enums/Modes/SizeMode.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/IImageShape.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -2
- package/cjs/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -17
- package/cjs/Options/Interfaces/Particles/Shape/IStarShape.js +0 -2
- package/cjs/engine.js +0 -179
- package/esm/Core/Interfaces/IParticleOverride.js +0 -1
- package/esm/Core/Interfaces/IParticlesMover.js +0 -1
- package/esm/Core/Utils/FrameManager.js +0 -42
- package/esm/Core/Utils/Plugins.js +0 -112
- package/esm/Enums/Modes/SizeMode.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IImageShape.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -1
- package/esm/Options/Interfaces/Particles/Shape/IStarShape.js +0 -1
- package/esm/engine.js +0 -175
- package/types/Core/Interfaces/IParticleOverride.d.ts +0 -6
- package/types/Core/Interfaces/IParticlesMover.d.ts +0 -7
- package/types/Core/Utils/FrameManager.d.ts +0 -6
- package/types/Core/Utils/Plugins.d.ts +0 -51
- package/types/Options/Interfaces/Particles/Shape/ICharacterShape.d.ts +0 -8
- package/types/Options/Interfaces/Particles/Shape/IImageShape.d.ts +0 -8
- package/types/Options/Interfaces/Particles/Shape/IPolygonShape.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Shape/IShapeValues.d.ts +0 -1
- package/types/Options/Interfaces/Particles/Shape/IStarShape.d.ts +0 -6
- package/types/engine.d.ts +0 -39
- package/umd/Core/Utils/FrameManager.js +0 -56
- package/umd/Core/Utils/Plugins.js +0 -126
- package/umd/Enums/Modes/SizeMode.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IImageShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -12
- package/umd/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -27
- package/umd/Options/Interfaces/Particles/Shape/IStarShape.js +0 -12
- package/umd/engine.js +0 -189
- /package/browser/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
- /package/browser/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
- /package/{browser/Enums/Modes/SizeMode.js → esm/Enums/Modes/PixelMode.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Shape/ICharacterShape.js → esm/Types/ExportResult.js} +0 -0
- /package/umd/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
- /package/umd/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
package/cjs/Core/Container.js
CHANGED
|
@@ -1,45 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Container = void 0;
|
|
4
|
-
const Utils_1 = require("../Utils/Utils");
|
|
5
4
|
const Canvas_1 = require("./Canvas");
|
|
6
5
|
const EventListeners_1 = require("./Utils/EventListeners");
|
|
7
|
-
const FrameManager_1 = require("./Utils/FrameManager");
|
|
8
6
|
const Options_1 = require("../Options/Classes/Options");
|
|
9
7
|
const Particles_1 = require("./Particles");
|
|
10
8
|
const Retina_1 = require("./Retina");
|
|
9
|
+
const Constants_1 = require("./Utils/Constants");
|
|
10
|
+
const Utils_1 = require("../Utils/Utils");
|
|
11
11
|
const NumberUtils_1 = require("../Utils/NumberUtils");
|
|
12
12
|
const OptionsUtils_1 = require("../Utils/OptionsUtils");
|
|
13
13
|
function guardCheck(container) {
|
|
14
14
|
return container && !container.destroyed;
|
|
15
15
|
}
|
|
16
|
+
function initDelta(value, fpsLimit = 60, smooth = false) {
|
|
17
|
+
return {
|
|
18
|
+
value,
|
|
19
|
+
factor: smooth ? 60 / fpsLimit : (60 * value) / 1000,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
16
22
|
function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
17
23
|
const options = new Options_1.Options(engine, container);
|
|
18
24
|
(0, OptionsUtils_1.loadOptions)(options, ...sourceOptionsArr);
|
|
19
25
|
return options;
|
|
20
26
|
}
|
|
21
|
-
const defaultPathGeneratorKey = "default", defaultPathGenerator = {
|
|
22
|
-
generate: (p) => {
|
|
23
|
-
const v = p.velocity.copy();
|
|
24
|
-
v.angle += (v.length * Math.PI) / 180;
|
|
25
|
-
return v;
|
|
26
|
-
},
|
|
27
|
-
init: () => {
|
|
28
|
-
},
|
|
29
|
-
update: () => {
|
|
30
|
-
},
|
|
31
|
-
reset: () => {
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
27
|
class Container {
|
|
35
28
|
constructor(engine, id, sourceOptions) {
|
|
36
29
|
this.id = id;
|
|
30
|
+
this._intersectionManager = (entries) => {
|
|
31
|
+
if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
if (entry.target !== this.interactivity.element) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
(entry.isIntersecting ? this.play : this.pause)();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
this._nextFrame = async (timestamp) => {
|
|
42
|
+
try {
|
|
43
|
+
if (!this.smooth &&
|
|
44
|
+
this.lastFrameTime !== undefined &&
|
|
45
|
+
timestamp < this.lastFrameTime + 1000 / this.fpsLimit) {
|
|
46
|
+
this.draw(false);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.lastFrameTime ??= timestamp;
|
|
50
|
+
const delta = initDelta(timestamp - this.lastFrameTime, this.fpsLimit, this.smooth);
|
|
51
|
+
this.addLifeTime(delta.value);
|
|
52
|
+
this.lastFrameTime = timestamp;
|
|
53
|
+
if (delta.value > 1000) {
|
|
54
|
+
this.draw(false);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await this.particles.draw(delta);
|
|
58
|
+
if (!this.alive()) {
|
|
59
|
+
this.destroy();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (this.getAnimationStatus()) {
|
|
63
|
+
this.draw(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
(0, Utils_1.getLogger)().error(`${Constants_1.errorPrefix} in animation loop`, e);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
37
70
|
this._engine = engine;
|
|
38
71
|
this.fpsLimit = 120;
|
|
39
72
|
this.smooth = false;
|
|
40
73
|
this._delay = 0;
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
74
|
+
this._duration = 0;
|
|
75
|
+
this._lifeTime = 0;
|
|
43
76
|
this._firstStart = true;
|
|
44
77
|
this.started = false;
|
|
45
78
|
this.destroyed = false;
|
|
@@ -52,7 +85,6 @@ class Container {
|
|
|
52
85
|
this.retina = new Retina_1.Retina(this);
|
|
53
86
|
this.canvas = new Canvas_1.Canvas(this);
|
|
54
87
|
this.particles = new Particles_1.Particles(this._engine, this);
|
|
55
|
-
this.frameManager = new FrameManager_1.FrameManager(this);
|
|
56
88
|
this.pathGenerators = new Map();
|
|
57
89
|
this.interactivity = {
|
|
58
90
|
mouse: {
|
|
@@ -153,13 +185,19 @@ class Container {
|
|
|
153
185
|
el.addEventListener("touchend", touchEndHandler);
|
|
154
186
|
el.addEventListener("touchcancel", touchCancelHandler);
|
|
155
187
|
}
|
|
188
|
+
addLifeTime(value) {
|
|
189
|
+
this._lifeTime += value;
|
|
190
|
+
}
|
|
156
191
|
addPath(key, generator, override = false) {
|
|
157
192
|
if (!guardCheck(this) || (!override && this.pathGenerators.has(key))) {
|
|
158
193
|
return false;
|
|
159
194
|
}
|
|
160
|
-
this.pathGenerators.set(key, generator
|
|
195
|
+
this.pathGenerators.set(key, generator);
|
|
161
196
|
return true;
|
|
162
197
|
}
|
|
198
|
+
alive() {
|
|
199
|
+
return !this._duration || this._lifeTime <= this._duration;
|
|
200
|
+
}
|
|
163
201
|
destroy() {
|
|
164
202
|
if (!guardCheck(this)) {
|
|
165
203
|
return;
|
|
@@ -168,14 +206,12 @@ class Container {
|
|
|
168
206
|
this.particles.destroy();
|
|
169
207
|
this.canvas.destroy();
|
|
170
208
|
for (const [, drawer] of this.drawers) {
|
|
171
|
-
|
|
172
|
-
drawer.destroy(this);
|
|
173
|
-
}
|
|
209
|
+
drawer.destroy && drawer.destroy(this);
|
|
174
210
|
}
|
|
175
211
|
for (const key of this.drawers.keys()) {
|
|
176
212
|
this.drawers.delete(key);
|
|
177
213
|
}
|
|
178
|
-
this._engine.
|
|
214
|
+
this._engine.clearPlugins(this);
|
|
179
215
|
this.destroyed = true;
|
|
180
216
|
const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this);
|
|
181
217
|
if (idx >= 0) {
|
|
@@ -188,30 +224,26 @@ class Container {
|
|
|
188
224
|
return;
|
|
189
225
|
}
|
|
190
226
|
let refreshTime = force;
|
|
191
|
-
this._drawAnimationFrame = (
|
|
227
|
+
this._drawAnimationFrame = requestAnimationFrame(async (timestamp) => {
|
|
192
228
|
if (refreshTime) {
|
|
193
229
|
this.lastFrameTime = undefined;
|
|
194
230
|
refreshTime = false;
|
|
195
231
|
}
|
|
196
|
-
await this.
|
|
232
|
+
await this._nextFrame(timestamp);
|
|
197
233
|
});
|
|
198
234
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
235
|
+
async export(type, options = {}) {
|
|
236
|
+
for (const [, plugin] of this.plugins) {
|
|
237
|
+
if (!plugin.export) {
|
|
238
|
+
continue;
|
|
203
239
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (element) {
|
|
210
|
-
element.toBlob(callback, type !== null && type !== void 0 ? type : "image/png", quality);
|
|
240
|
+
const res = await plugin.export(type, options);
|
|
241
|
+
if (!res.supported) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
return res.blob;
|
|
211
245
|
}
|
|
212
|
-
|
|
213
|
-
exportImg(callback) {
|
|
214
|
-
this.exportImage(callback);
|
|
246
|
+
(0, Utils_1.getLogger)().error(`${Constants_1.errorPrefix} - Export plugin with type ${type} not found`);
|
|
215
247
|
}
|
|
216
248
|
getAnimationStatus() {
|
|
217
249
|
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
@@ -222,53 +254,48 @@ class Container {
|
|
|
222
254
|
}
|
|
223
255
|
this.particles.handleClickMode(mode);
|
|
224
256
|
for (const [, plugin] of this.plugins) {
|
|
225
|
-
|
|
226
|
-
plugin.handleClickMode(mode);
|
|
227
|
-
}
|
|
257
|
+
plugin.handleClickMode && plugin.handleClickMode(mode);
|
|
228
258
|
}
|
|
229
259
|
}
|
|
230
260
|
async init() {
|
|
231
261
|
if (!guardCheck(this)) {
|
|
232
262
|
return;
|
|
233
263
|
}
|
|
234
|
-
const shapes = this._engine.
|
|
264
|
+
const shapes = this._engine.getSupportedShapes();
|
|
235
265
|
for (const type of shapes) {
|
|
236
|
-
const drawer = this._engine.
|
|
266
|
+
const drawer = this._engine.getShapeDrawer(type);
|
|
237
267
|
if (drawer) {
|
|
238
268
|
this.drawers.set(type, drawer);
|
|
239
269
|
}
|
|
240
270
|
}
|
|
241
271
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
242
272
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
243
|
-
const availablePlugins = this._engine.
|
|
273
|
+
const availablePlugins = this._engine.getAvailablePlugins(this);
|
|
244
274
|
for (const [id, plugin] of availablePlugins) {
|
|
245
275
|
this.plugins.set(id, plugin);
|
|
246
276
|
}
|
|
247
277
|
this.retina.init();
|
|
248
278
|
await this.canvas.init();
|
|
279
|
+
this.updateActualOptions();
|
|
280
|
+
this.canvas.initBackground();
|
|
281
|
+
this.canvas.resize();
|
|
249
282
|
this.zLayers = this.actualOptions.zLayers;
|
|
250
|
-
this.
|
|
283
|
+
this._duration = (0, NumberUtils_1.getRangeValue)(this.actualOptions.duration) * 1000;
|
|
251
284
|
this._delay = (0, NumberUtils_1.getRangeValue)(this.actualOptions.delay) * 1000;
|
|
252
|
-
this.
|
|
285
|
+
this._lifeTime = 0;
|
|
253
286
|
this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 120;
|
|
254
287
|
this.smooth = this.actualOptions.smooth;
|
|
255
288
|
for (const [, drawer] of this.drawers) {
|
|
256
|
-
|
|
257
|
-
await drawer.init(this);
|
|
258
|
-
}
|
|
289
|
+
drawer.init && (await drawer.init(this));
|
|
259
290
|
}
|
|
260
291
|
for (const [, plugin] of this.plugins) {
|
|
261
|
-
|
|
262
|
-
await plugin.init();
|
|
263
|
-
}
|
|
292
|
+
plugin.init && (await plugin.init());
|
|
264
293
|
}
|
|
265
294
|
this._engine.dispatchEvent("containerInit", { container: this });
|
|
266
295
|
this.particles.init();
|
|
267
296
|
this.particles.setDensity();
|
|
268
297
|
for (const [, plugin] of this.plugins) {
|
|
269
|
-
|
|
270
|
-
plugin.particlesSetup();
|
|
271
|
-
}
|
|
298
|
+
plugin.particlesSetup && plugin.particlesSetup();
|
|
272
299
|
}
|
|
273
300
|
this._engine.dispatchEvent("particlesSetup", { container: this });
|
|
274
301
|
}
|
|
@@ -284,16 +311,14 @@ class Container {
|
|
|
284
311
|
return;
|
|
285
312
|
}
|
|
286
313
|
if (this._drawAnimationFrame !== undefined) {
|
|
287
|
-
(
|
|
314
|
+
cancelAnimationFrame(this._drawAnimationFrame);
|
|
288
315
|
delete this._drawAnimationFrame;
|
|
289
316
|
}
|
|
290
317
|
if (this._paused) {
|
|
291
318
|
return;
|
|
292
319
|
}
|
|
293
320
|
for (const [, plugin] of this.plugins) {
|
|
294
|
-
|
|
295
|
-
plugin.pause();
|
|
296
|
-
}
|
|
321
|
+
plugin.pause && plugin.pause();
|
|
297
322
|
}
|
|
298
323
|
if (!this.pageHidden) {
|
|
299
324
|
this._paused = true;
|
|
@@ -333,37 +358,11 @@ class Container {
|
|
|
333
358
|
if (!guardCheck(this)) {
|
|
334
359
|
return;
|
|
335
360
|
}
|
|
361
|
+
this._initialSourceOptions = undefined;
|
|
336
362
|
this._options = loadContainerOptions(this._engine, this);
|
|
363
|
+
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
337
364
|
return this.refresh();
|
|
338
365
|
}
|
|
339
|
-
setNoise(noiseOrGenerator, init, update) {
|
|
340
|
-
if (!guardCheck(this)) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
this.setPath(noiseOrGenerator, init, update);
|
|
344
|
-
}
|
|
345
|
-
setPath(pathOrGenerator, init, update) {
|
|
346
|
-
if (!pathOrGenerator || !guardCheck(this)) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
const pathGenerator = Object.assign({}, defaultPathGenerator);
|
|
350
|
-
if (typeof pathOrGenerator === "function") {
|
|
351
|
-
pathGenerator.generate = pathOrGenerator;
|
|
352
|
-
if (init) {
|
|
353
|
-
pathGenerator.init = init;
|
|
354
|
-
}
|
|
355
|
-
if (update) {
|
|
356
|
-
pathGenerator.update = update;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
const oldGenerator = pathGenerator;
|
|
361
|
-
pathGenerator.generate = pathOrGenerator.generate || oldGenerator.generate;
|
|
362
|
-
pathGenerator.init = pathOrGenerator.init || oldGenerator.init;
|
|
363
|
-
pathGenerator.update = pathOrGenerator.update || oldGenerator.update;
|
|
364
|
-
}
|
|
365
|
-
this.addPath(defaultPathGeneratorKey, pathGenerator, true);
|
|
366
|
-
}
|
|
367
366
|
async start() {
|
|
368
367
|
if (!guardCheck(this) || this.started) {
|
|
369
368
|
return;
|
|
@@ -377,9 +376,7 @@ class Container {
|
|
|
377
376
|
this._intersectionObserver.observe(this.interactivity.element);
|
|
378
377
|
}
|
|
379
378
|
for (const [, plugin] of this.plugins) {
|
|
380
|
-
|
|
381
|
-
await plugin.start();
|
|
382
|
-
}
|
|
379
|
+
plugin.start && (await plugin.start());
|
|
383
380
|
}
|
|
384
381
|
this._engine.dispatchEvent("containerStarted", { container: this });
|
|
385
382
|
this.play();
|
|
@@ -400,14 +397,12 @@ class Container {
|
|
|
400
397
|
this._eventListeners.removeListeners();
|
|
401
398
|
this.pause();
|
|
402
399
|
this.particles.clear();
|
|
403
|
-
this.canvas.
|
|
400
|
+
this.canvas.stop();
|
|
404
401
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
405
402
|
this._intersectionObserver.unobserve(this.interactivity.element);
|
|
406
403
|
}
|
|
407
404
|
for (const [, plugin] of this.plugins) {
|
|
408
|
-
|
|
409
|
-
plugin.stop();
|
|
410
|
-
}
|
|
405
|
+
plugin.stop && plugin.stop();
|
|
411
406
|
}
|
|
412
407
|
for (const key of this.plugins.keys()) {
|
|
413
408
|
this.plugins.delete(key);
|
|
@@ -425,16 +420,5 @@ class Container {
|
|
|
425
420
|
this.responsiveMaxWidth = newMaxWidth;
|
|
426
421
|
return true;
|
|
427
422
|
}
|
|
428
|
-
_intersectionManager(entries) {
|
|
429
|
-
if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
for (const entry of entries) {
|
|
433
|
-
if (entry.target !== this.interactivity.element) {
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
(entry.isIntersecting ? this.play : this.pause)();
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
423
|
}
|
|
440
424
|
exports.Container = Container;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Engine = void 0;
|
|
4
|
+
const Constants_1 = require("./Utils/Constants");
|
|
5
|
+
const Utils_1 = require("../Utils/Utils");
|
|
6
|
+
const Container_1 = require("./Container");
|
|
7
|
+
const EventDispatcher_1 = require("../Utils/EventDispatcher");
|
|
8
|
+
const NumberUtils_1 = require("../Utils/NumberUtils");
|
|
9
|
+
function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
10
|
+
let res = map.get(container);
|
|
11
|
+
if (!res || force) {
|
|
12
|
+
res = [...initializers.values()].map((t) => t(container));
|
|
13
|
+
map.set(container, res);
|
|
14
|
+
}
|
|
15
|
+
return res;
|
|
16
|
+
}
|
|
17
|
+
async function getDataFromUrl(data) {
|
|
18
|
+
const url = (0, Utils_1.itemFromSingleOrMultiple)(data.url, data.index);
|
|
19
|
+
if (!url) {
|
|
20
|
+
return data.fallback;
|
|
21
|
+
}
|
|
22
|
+
const response = await fetch(url);
|
|
23
|
+
if (response.ok) {
|
|
24
|
+
return response.json();
|
|
25
|
+
}
|
|
26
|
+
(0, Utils_1.getLogger)().error(`${Constants_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
27
|
+
return data.fallback;
|
|
28
|
+
}
|
|
29
|
+
class Engine {
|
|
30
|
+
constructor() {
|
|
31
|
+
this._configs = new Map();
|
|
32
|
+
this._domArray = [];
|
|
33
|
+
this._eventDispatcher = new EventDispatcher_1.EventDispatcher();
|
|
34
|
+
this._initialized = false;
|
|
35
|
+
this.plugins = [];
|
|
36
|
+
this._initializers = {
|
|
37
|
+
interactors: new Map(),
|
|
38
|
+
movers: new Map(),
|
|
39
|
+
updaters: new Map(),
|
|
40
|
+
};
|
|
41
|
+
this.interactors = new Map();
|
|
42
|
+
this.movers = new Map();
|
|
43
|
+
this.updaters = new Map();
|
|
44
|
+
this.presets = new Map();
|
|
45
|
+
this.drawers = new Map();
|
|
46
|
+
this.pathGenerators = new Map();
|
|
47
|
+
}
|
|
48
|
+
get configs() {
|
|
49
|
+
const res = {};
|
|
50
|
+
for (const [name, config] of this._configs) {
|
|
51
|
+
res[name] = config;
|
|
52
|
+
}
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
get version() {
|
|
56
|
+
return "3.0.0-beta.0";
|
|
57
|
+
}
|
|
58
|
+
addConfig(nameOrConfig, config) {
|
|
59
|
+
if ((0, Utils_1.isString)(nameOrConfig)) {
|
|
60
|
+
if (config) {
|
|
61
|
+
config.name = nameOrConfig;
|
|
62
|
+
this._configs.set(nameOrConfig, config);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this._configs.set(nameOrConfig.name ?? "default", nameOrConfig);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
addEventListener(type, listener) {
|
|
70
|
+
this._eventDispatcher.addEventListener(type, listener);
|
|
71
|
+
}
|
|
72
|
+
async addInteractor(name, interactorInitializer, refresh = true) {
|
|
73
|
+
this._initializers.interactors.set(name, interactorInitializer);
|
|
74
|
+
await this.refresh(refresh);
|
|
75
|
+
}
|
|
76
|
+
async addMover(name, moverInitializer, refresh = true) {
|
|
77
|
+
this._initializers.movers.set(name, moverInitializer);
|
|
78
|
+
await this.refresh(refresh);
|
|
79
|
+
}
|
|
80
|
+
async addParticleUpdater(name, updaterInitializer, refresh = true) {
|
|
81
|
+
this._initializers.updaters.set(name, updaterInitializer);
|
|
82
|
+
await this.refresh(refresh);
|
|
83
|
+
}
|
|
84
|
+
async addPathGenerator(name, generator, refresh = true) {
|
|
85
|
+
!this.getPathGenerator(name) && this.pathGenerators.set(name, generator);
|
|
86
|
+
await this.refresh(refresh);
|
|
87
|
+
}
|
|
88
|
+
async addPlugin(plugin, refresh = true) {
|
|
89
|
+
!this.getPlugin(plugin.id) && this.plugins.push(plugin);
|
|
90
|
+
await this.refresh(refresh);
|
|
91
|
+
}
|
|
92
|
+
async addPreset(preset, options, override = false, refresh = true) {
|
|
93
|
+
(override || !this.getPreset(preset)) && this.presets.set(preset, options);
|
|
94
|
+
await this.refresh(refresh);
|
|
95
|
+
}
|
|
96
|
+
async addShape(shape, drawer, initOrRefresh, afterEffectOrRefresh, destroyOrRefresh, refresh = true) {
|
|
97
|
+
let customDrawer;
|
|
98
|
+
let realRefresh = refresh, realInit, realAfterEffect, realDestroy;
|
|
99
|
+
if ((0, Utils_1.isBoolean)(initOrRefresh)) {
|
|
100
|
+
realRefresh = initOrRefresh;
|
|
101
|
+
realInit = undefined;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
realInit = initOrRefresh;
|
|
105
|
+
}
|
|
106
|
+
if ((0, Utils_1.isBoolean)(afterEffectOrRefresh)) {
|
|
107
|
+
realRefresh = afterEffectOrRefresh;
|
|
108
|
+
realAfterEffect = undefined;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
realAfterEffect = afterEffectOrRefresh;
|
|
112
|
+
}
|
|
113
|
+
if ((0, Utils_1.isBoolean)(destroyOrRefresh)) {
|
|
114
|
+
realRefresh = destroyOrRefresh;
|
|
115
|
+
realDestroy = undefined;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
realDestroy = destroyOrRefresh;
|
|
119
|
+
}
|
|
120
|
+
if ((0, Utils_1.isFunction)(drawer)) {
|
|
121
|
+
customDrawer = {
|
|
122
|
+
afterEffect: realAfterEffect,
|
|
123
|
+
destroy: realDestroy,
|
|
124
|
+
draw: drawer,
|
|
125
|
+
init: realInit,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
customDrawer = drawer;
|
|
130
|
+
}
|
|
131
|
+
(0, Utils_1.executeOnSingleOrMultiple)(shape, (type) => {
|
|
132
|
+
!this.getShapeDrawer(type) && this.drawers.set(type, customDrawer);
|
|
133
|
+
});
|
|
134
|
+
await this.refresh(realRefresh);
|
|
135
|
+
}
|
|
136
|
+
clearPlugins(container) {
|
|
137
|
+
this.updaters.delete(container);
|
|
138
|
+
this.movers.delete(container);
|
|
139
|
+
this.interactors.delete(container);
|
|
140
|
+
}
|
|
141
|
+
dispatchEvent(type, args) {
|
|
142
|
+
this._eventDispatcher.dispatchEvent(type, args);
|
|
143
|
+
}
|
|
144
|
+
dom() {
|
|
145
|
+
return this._domArray;
|
|
146
|
+
}
|
|
147
|
+
domItem(index) {
|
|
148
|
+
const dom = this.dom(), item = dom[index];
|
|
149
|
+
if (!item || item.destroyed) {
|
|
150
|
+
dom.splice(index, 1);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
return item;
|
|
154
|
+
}
|
|
155
|
+
getAvailablePlugins(container) {
|
|
156
|
+
const res = new Map();
|
|
157
|
+
for (const plugin of this.plugins) {
|
|
158
|
+
plugin.needsPlugin(container.actualOptions) && res.set(plugin.id, plugin.getPlugin(container));
|
|
159
|
+
}
|
|
160
|
+
return res;
|
|
161
|
+
}
|
|
162
|
+
getInteractors(container, force = false) {
|
|
163
|
+
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
164
|
+
}
|
|
165
|
+
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.drawers.get(type);
|
|
179
|
+
}
|
|
180
|
+
getSupportedShapes() {
|
|
181
|
+
return this.drawers.keys();
|
|
182
|
+
}
|
|
183
|
+
getUpdaters(container, force = false) {
|
|
184
|
+
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
185
|
+
}
|
|
186
|
+
init() {
|
|
187
|
+
if (this._initialized) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this._initialized = true;
|
|
191
|
+
}
|
|
192
|
+
async load(params) {
|
|
193
|
+
const id = params.id ?? `tsparticles${Math.floor((0, NumberUtils_1.getRandom)() * 10000)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
|
|
194
|
+
let domContainer = params.element ?? document.getElementById(id);
|
|
195
|
+
if (!domContainer) {
|
|
196
|
+
domContainer = document.createElement("div");
|
|
197
|
+
domContainer.id = id;
|
|
198
|
+
document.body.append(domContainer);
|
|
199
|
+
}
|
|
200
|
+
const currentOptions = (0, Utils_1.itemFromSingleOrMultiple)(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id === id);
|
|
201
|
+
if (oldIndex >= 0) {
|
|
202
|
+
const old = this.domItem(oldIndex);
|
|
203
|
+
if (old && !old.destroyed) {
|
|
204
|
+
old.destroy();
|
|
205
|
+
dom.splice(oldIndex, 1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
let canvasEl;
|
|
209
|
+
if (domContainer.tagName.toLowerCase() === "canvas") {
|
|
210
|
+
canvasEl = domContainer;
|
|
211
|
+
canvasEl.dataset[Constants_1.generatedAttribute] = "false";
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
const existingCanvases = domContainer.getElementsByTagName("canvas");
|
|
215
|
+
if (existingCanvases.length) {
|
|
216
|
+
canvasEl = existingCanvases[0];
|
|
217
|
+
canvasEl.dataset[Constants_1.generatedAttribute] = "false";
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
canvasEl = document.createElement("canvas");
|
|
221
|
+
canvasEl.dataset[Constants_1.generatedAttribute] = "true";
|
|
222
|
+
domContainer.appendChild(canvasEl);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (!canvasEl.style.width) {
|
|
226
|
+
canvasEl.style.width = "100%";
|
|
227
|
+
}
|
|
228
|
+
if (!canvasEl.style.height) {
|
|
229
|
+
canvasEl.style.height = "100%";
|
|
230
|
+
}
|
|
231
|
+
const newItem = new Container_1.Container(this, id, currentOptions);
|
|
232
|
+
if (oldIndex >= 0) {
|
|
233
|
+
dom.splice(oldIndex, 0, newItem);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
dom.push(newItem);
|
|
237
|
+
}
|
|
238
|
+
newItem.canvas.loadCanvas(canvasEl);
|
|
239
|
+
await newItem.start();
|
|
240
|
+
return newItem;
|
|
241
|
+
}
|
|
242
|
+
loadOptions(options, sourceOptions) {
|
|
243
|
+
for (const plugin of this.plugins) {
|
|
244
|
+
plugin.loadOptions(options, sourceOptions);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
248
|
+
const updaters = this.updaters.get(container);
|
|
249
|
+
if (!updaters) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
for (const updater of updaters) {
|
|
253
|
+
updater.loadOptions && updater.loadOptions(options, ...sourceOptions);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async refresh(refresh = true) {
|
|
257
|
+
if (!refresh) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.dom().forEach((t) => t.refresh());
|
|
261
|
+
}
|
|
262
|
+
removeEventListener(type, listener) {
|
|
263
|
+
this._eventDispatcher.removeEventListener(type, listener);
|
|
264
|
+
}
|
|
265
|
+
setOnClickHandler(callback) {
|
|
266
|
+
const dom = this.dom();
|
|
267
|
+
if (!dom.length) {
|
|
268
|
+
throw new Error(`${Constants_1.errorPrefix} can only set click handlers after calling tsParticles.load()`);
|
|
269
|
+
}
|
|
270
|
+
for (const domItem of dom) {
|
|
271
|
+
domItem.addClickHandler(callback);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.Engine = Engine;
|