@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
|
@@ -6,7 +6,7 @@ const Constants_1 = require("./Constants");
|
|
|
6
6
|
function manageListener(element, event, handler, add, options) {
|
|
7
7
|
if (add) {
|
|
8
8
|
let addOptions = { passive: true };
|
|
9
|
-
if (
|
|
9
|
+
if ((0, Utils_1.isBoolean)(options)) {
|
|
10
10
|
addOptions.capture = options;
|
|
11
11
|
}
|
|
12
12
|
else if (options !== undefined) {
|
|
@@ -22,101 +22,71 @@ function manageListener(element, event, handler, add, options) {
|
|
|
22
22
|
class EventListeners {
|
|
23
23
|
constructor(container) {
|
|
24
24
|
this.container = container;
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
this._doMouseTouchClick = (e) => {
|
|
26
|
+
const container = this.container, options = container.actualOptions;
|
|
27
|
+
if (this._canPush) {
|
|
28
|
+
const mouseInteractivity = container.interactivity.mouse, mousePos = mouseInteractivity.position;
|
|
29
|
+
if (!mousePos) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
mouseInteractivity.clickPosition = { ...mousePos };
|
|
33
|
+
mouseInteractivity.clickTime = new Date().getTime();
|
|
34
|
+
const onClick = options.interactivity.events.onClick;
|
|
35
|
+
(0, Utils_1.executeOnSingleOrMultiple)(onClick.mode, (mode) => this.container.handleClickMode(mode));
|
|
36
|
+
}
|
|
37
|
+
if (e.type === "touchend") {
|
|
38
|
+
setTimeout(() => this._mouseTouchFinish(), 500);
|
|
39
|
+
}
|
|
40
40
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const mouseInteractivity = container.interactivity.mouse, mousePos = mouseInteractivity.position;
|
|
52
|
-
if (!mousePos) {
|
|
41
|
+
this._handleThemeChange = (e) => {
|
|
42
|
+
const mediaEvent = e, container = this.container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes.find((theme) => theme.name === themeName);
|
|
43
|
+
if (theme && theme.default.auto) {
|
|
44
|
+
container.loadTheme(themeName);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
this._handleVisibilityChange = () => {
|
|
48
|
+
const container = this.container, options = container.actualOptions;
|
|
49
|
+
this._mouseTouchFinish();
|
|
50
|
+
if (!options.pauseOnBlur) {
|
|
53
51
|
return;
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(0, Utils_1.executeOnSingleOrMultiple)(onClick.mode, (mode) => this._handleClickMode(mode));
|
|
59
|
-
}
|
|
60
|
-
if (e.type === "touchend") {
|
|
61
|
-
setTimeout(() => this._mouseTouchFinish(), 500);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
_handleClickMode(mode) {
|
|
65
|
-
this.container.handleClickMode(mode);
|
|
66
|
-
}
|
|
67
|
-
_handleThemeChange(e) {
|
|
68
|
-
const mediaEvent = e, container = this.container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes.find((theme) => theme.name === themeName);
|
|
69
|
-
if (theme && theme.default.auto) {
|
|
70
|
-
container.loadTheme(themeName);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
_handleVisibilityChange() {
|
|
74
|
-
const container = this.container, options = container.actualOptions;
|
|
75
|
-
this._mouseTouchFinish();
|
|
76
|
-
if (!options.pauseOnBlur) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
container.pageHidden = (document === null || document === void 0 ? void 0 : document.hidden) || false;
|
|
80
|
-
if (container.pageHidden) {
|
|
81
|
-
container.pause();
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
if (container.getAnimationStatus()) {
|
|
85
|
-
container.play(true);
|
|
53
|
+
if (document && document.hidden) {
|
|
54
|
+
container.pageHidden = true;
|
|
55
|
+
container.pause();
|
|
86
56
|
}
|
|
87
57
|
else {
|
|
88
|
-
container.
|
|
58
|
+
container.pageHidden = false;
|
|
59
|
+
if (container.getAnimationStatus()) {
|
|
60
|
+
container.play(true);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
container.draw(true);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this._handleWindowResize = async () => {
|
|
68
|
+
if (this._resizeTimeout) {
|
|
69
|
+
clearTimeout(this._resizeTimeout);
|
|
70
|
+
delete this._resizeTimeout;
|
|
71
|
+
}
|
|
72
|
+
this._resizeTimeout = setTimeout(async () => {
|
|
73
|
+
const canvas = this.container.canvas;
|
|
74
|
+
canvas && (await canvas.windowResize());
|
|
75
|
+
}, this.container.actualOptions.interactivity.events.resize.delay * 1000);
|
|
76
|
+
};
|
|
77
|
+
this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
|
|
78
|
+
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
79
|
+
const interactivityEl = container.interactivity.element;
|
|
80
|
+
if (!interactivityEl) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const html = interactivityEl, canvasEl = container.canvas.element;
|
|
84
|
+
if (canvasEl) {
|
|
85
|
+
canvasEl.style.pointerEvents = html === canvasEl ? "initial" : "none";
|
|
86
|
+
}
|
|
87
|
+
if (!(options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable)) {
|
|
88
|
+
return;
|
|
89
89
|
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
_handleWindowResize() {
|
|
93
|
-
if (this.resizeTimeout) {
|
|
94
|
-
clearTimeout(this.resizeTimeout);
|
|
95
|
-
delete this.resizeTimeout;
|
|
96
|
-
}
|
|
97
|
-
this.resizeTimeout = setTimeout(async () => { var _a; return (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize(); }, this.container.actualOptions.interactivity.events.resize.delay * 1000);
|
|
98
|
-
}
|
|
99
|
-
_manageInteractivityEvents(add) {
|
|
100
|
-
var _a;
|
|
101
|
-
const handlers = this.handlers, container = this.container, options = container.actualOptions, detectType = options.interactivity.detectsOn;
|
|
102
|
-
let mouseLeaveTmpEvent = Constants_1.mouseLeaveEvent;
|
|
103
|
-
if (detectType === "window") {
|
|
104
|
-
container.interactivity.element = window;
|
|
105
|
-
mouseLeaveTmpEvent = Constants_1.mouseOutEvent;
|
|
106
|
-
}
|
|
107
|
-
else if (detectType === "parent" && container.canvas.element) {
|
|
108
|
-
const canvasEl = container.canvas.element;
|
|
109
|
-
container.interactivity.element = (_a = canvasEl.parentElement) !== null && _a !== void 0 ? _a : canvasEl.parentNode;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
container.interactivity.element = container.canvas.element;
|
|
113
|
-
}
|
|
114
|
-
const interactivityEl = container.interactivity.element;
|
|
115
|
-
if (!interactivityEl) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const html = interactivityEl;
|
|
119
|
-
if (options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable) {
|
|
120
90
|
manageListener(interactivityEl, Constants_1.mouseMoveEvent, handlers.mouseMove, add);
|
|
121
91
|
manageListener(interactivityEl, Constants_1.touchStartEvent, handlers.touchStart, add);
|
|
122
92
|
manageListener(interactivityEl, Constants_1.touchMoveEvent, handlers.touchMove, add);
|
|
@@ -130,170 +100,224 @@ class EventListeners {
|
|
|
130
100
|
}
|
|
131
101
|
manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
|
|
132
102
|
manageListener(interactivityEl, Constants_1.touchCancelEvent, handlers.touchCancel, add);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
container.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
103
|
+
};
|
|
104
|
+
this._manageListeners = (add) => {
|
|
105
|
+
const handlers = this._handlers, container = this.container, options = container.actualOptions, detectType = options.interactivity.detectsOn, canvasEl = container.canvas.element;
|
|
106
|
+
let mouseLeaveTmpEvent = Constants_1.mouseLeaveEvent;
|
|
107
|
+
if (detectType === "window") {
|
|
108
|
+
container.interactivity.element = window;
|
|
109
|
+
mouseLeaveTmpEvent = Constants_1.mouseOutEvent;
|
|
110
|
+
}
|
|
111
|
+
else if (detectType === "parent" && canvasEl) {
|
|
112
|
+
container.interactivity.element = canvasEl.parentElement ?? canvasEl.parentNode;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
container.interactivity.element = canvasEl;
|
|
116
|
+
}
|
|
117
|
+
this._manageMediaMatch(add);
|
|
118
|
+
this._manageResize(add);
|
|
119
|
+
this._manageInteractivityListeners(mouseLeaveTmpEvent, add);
|
|
120
|
+
if (document) {
|
|
121
|
+
manageListener(document, Constants_1.visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
this._manageMediaMatch = (add) => {
|
|
125
|
+
const handlers = this._handlers, mediaMatch = (0, Utils_1.safeMatchMedia)("(prefers-color-scheme: dark)");
|
|
126
|
+
if (!mediaMatch) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (mediaMatch.addEventListener !== undefined) {
|
|
130
|
+
manageListener(mediaMatch, "change", handlers.themeChange, add);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (mediaMatch.addListener === undefined) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
154
136
|
if (add) {
|
|
155
137
|
mediaMatch.addListener(handlers.oldThemeChange);
|
|
156
138
|
}
|
|
157
139
|
else {
|
|
158
140
|
mediaMatch.removeListener(handlers.oldThemeChange);
|
|
159
141
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (typeof ResizeObserver === "undefined") {
|
|
168
|
-
manageListener(window, Constants_1.resizeEvent, handlers.resize, add);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (this.resizeObserver && !add) {
|
|
172
|
-
if (container.canvas.element) {
|
|
173
|
-
this.resizeObserver.unobserve(container.canvas.element);
|
|
142
|
+
};
|
|
143
|
+
this._manageResize = (add) => {
|
|
144
|
+
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
145
|
+
if (!options.interactivity.events.resize) {
|
|
146
|
+
return;
|
|
174
147
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
148
|
+
if (typeof ResizeObserver === "undefined") {
|
|
149
|
+
manageListener(window, Constants_1.resizeEvent, handlers.resize, add);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const canvasEl = container.canvas.element;
|
|
153
|
+
if (this._resizeObserver && !add) {
|
|
154
|
+
if (canvasEl) {
|
|
155
|
+
this._resizeObserver.unobserve(canvasEl);
|
|
183
156
|
}
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
157
|
+
this._resizeObserver.disconnect();
|
|
158
|
+
delete this._resizeObserver;
|
|
159
|
+
}
|
|
160
|
+
else if (!this._resizeObserver && add && canvasEl) {
|
|
161
|
+
this._resizeObserver = new ResizeObserver(async (entries) => {
|
|
162
|
+
const entry = entries.find((e) => e.target === canvasEl);
|
|
163
|
+
if (!entry) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await this._handleWindowResize();
|
|
167
|
+
});
|
|
168
|
+
this._resizeObserver.observe(canvasEl);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
this._mouseDown = () => {
|
|
172
|
+
const { interactivity } = this.container;
|
|
173
|
+
if (!interactivity) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const { mouse } = interactivity;
|
|
199
177
|
mouse.clicking = true;
|
|
200
178
|
mouse.downPosition = mouse.position;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
for (const [, plugin] of container.plugins) {
|
|
212
|
-
if (!plugin.clickPositionValid) {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
handled = plugin.clickPositionValid(mousePosition);
|
|
216
|
-
if (handled) {
|
|
217
|
-
break;
|
|
179
|
+
};
|
|
180
|
+
this._mouseTouchClick = (e) => {
|
|
181
|
+
const container = this.container, options = container.actualOptions, { mouse } = container.interactivity;
|
|
182
|
+
mouse.inside = true;
|
|
183
|
+
let handled = false;
|
|
184
|
+
const mousePosition = mouse.position;
|
|
185
|
+
if (!mousePosition || !options.interactivity.events.onClick.enable) {
|
|
186
|
+
return;
|
|
218
187
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
mouse.clicking = false;
|
|
224
|
-
}
|
|
225
|
-
_mouseTouchFinish() {
|
|
226
|
-
const interactivity = this.container.interactivity;
|
|
227
|
-
if (!interactivity) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const mouse = interactivity.mouse;
|
|
231
|
-
delete mouse.position;
|
|
232
|
-
delete mouse.clickPosition;
|
|
233
|
-
delete mouse.downPosition;
|
|
234
|
-
interactivity.status = Constants_1.mouseLeaveEvent;
|
|
235
|
-
mouse.inside = false;
|
|
236
|
-
mouse.clicking = false;
|
|
237
|
-
}
|
|
238
|
-
_mouseTouchMove(e) {
|
|
239
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
240
|
-
const container = this.container, options = container.actualOptions;
|
|
241
|
-
if (!((_a = container.interactivity) === null || _a === void 0 ? void 0 : _a.element)) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
container.interactivity.mouse.inside = true;
|
|
245
|
-
let pos;
|
|
246
|
-
const canvas = container.canvas.element;
|
|
247
|
-
if (e.type.startsWith("pointer")) {
|
|
248
|
-
this.canPush = true;
|
|
249
|
-
const mouseEvent = e;
|
|
250
|
-
if (container.interactivity.element === window) {
|
|
251
|
-
if (canvas) {
|
|
252
|
-
const clientRect = canvas.getBoundingClientRect();
|
|
253
|
-
pos = {
|
|
254
|
-
x: mouseEvent.clientX - clientRect.left,
|
|
255
|
-
y: mouseEvent.clientY - clientRect.top,
|
|
256
|
-
};
|
|
188
|
+
for (const [, plugin] of container.plugins) {
|
|
189
|
+
if (!plugin.clickPositionValid) {
|
|
190
|
+
continue;
|
|
257
191
|
}
|
|
192
|
+
handled = plugin.clickPositionValid(mousePosition);
|
|
193
|
+
if (handled) {
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (!handled) {
|
|
198
|
+
this._doMouseTouchClick(e);
|
|
199
|
+
}
|
|
200
|
+
mouse.clicking = false;
|
|
201
|
+
};
|
|
202
|
+
this._mouseTouchFinish = () => {
|
|
203
|
+
const interactivity = this.container.interactivity;
|
|
204
|
+
if (!interactivity) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const mouse = interactivity.mouse;
|
|
208
|
+
delete mouse.position;
|
|
209
|
+
delete mouse.clickPosition;
|
|
210
|
+
delete mouse.downPosition;
|
|
211
|
+
interactivity.status = Constants_1.mouseLeaveEvent;
|
|
212
|
+
mouse.inside = false;
|
|
213
|
+
mouse.clicking = false;
|
|
214
|
+
};
|
|
215
|
+
this._mouseTouchMove = (e) => {
|
|
216
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity, canvasEl = container.canvas.element;
|
|
217
|
+
if (!interactivity || !interactivity.element) {
|
|
218
|
+
return;
|
|
258
219
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
220
|
+
interactivity.mouse.inside = true;
|
|
221
|
+
let pos;
|
|
222
|
+
if (e.type.startsWith("pointer")) {
|
|
223
|
+
this._canPush = true;
|
|
224
|
+
const mouseEvent = e;
|
|
225
|
+
if (interactivity.element === window) {
|
|
226
|
+
if (canvasEl) {
|
|
227
|
+
const clientRect = canvasEl.getBoundingClientRect();
|
|
228
|
+
pos = {
|
|
229
|
+
x: mouseEvent.clientX - clientRect.left,
|
|
230
|
+
y: mouseEvent.clientY - clientRect.top,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else if (options.interactivity.detectsOn === "parent") {
|
|
235
|
+
const source = mouseEvent.target, target = mouseEvent.currentTarget;
|
|
236
|
+
if (source && target && canvasEl) {
|
|
237
|
+
const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
|
|
238
|
+
pos = {
|
|
239
|
+
x: mouseEvent.offsetX + 2 * sourceRect.left - (targetRect.left + canvasRect.left),
|
|
240
|
+
y: mouseEvent.offsetY + 2 * sourceRect.top - (targetRect.top + canvasRect.top),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
pos = {
|
|
245
|
+
x: mouseEvent.offsetX ?? mouseEvent.clientX,
|
|
246
|
+
y: mouseEvent.offsetY ?? mouseEvent.clientY,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (mouseEvent.target === canvasEl) {
|
|
263
251
|
pos = {
|
|
264
|
-
x: mouseEvent.offsetX
|
|
265
|
-
y: mouseEvent.offsetY
|
|
252
|
+
x: mouseEvent.offsetX ?? mouseEvent.clientX,
|
|
253
|
+
y: mouseEvent.offsetY ?? mouseEvent.clientY,
|
|
266
254
|
};
|
|
267
255
|
}
|
|
268
|
-
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
this._canPush = e.type !== "touchmove";
|
|
259
|
+
if (canvasEl) {
|
|
260
|
+
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - 1], canvasRect = canvasEl.getBoundingClientRect();
|
|
269
261
|
pos = {
|
|
270
|
-
x:
|
|
271
|
-
y:
|
|
262
|
+
x: lastTouch.clientX - (canvasRect.left ?? 0),
|
|
263
|
+
y: lastTouch.clientY - (canvasRect.top ?? 0),
|
|
272
264
|
};
|
|
273
265
|
}
|
|
274
266
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
};
|
|
267
|
+
const pxRatio = container.retina.pixelRatio;
|
|
268
|
+
if (pos) {
|
|
269
|
+
pos.x *= pxRatio;
|
|
270
|
+
pos.y *= pxRatio;
|
|
280
271
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
272
|
+
interactivity.mouse.position = pos;
|
|
273
|
+
interactivity.status = Constants_1.mouseMoveEvent;
|
|
274
|
+
};
|
|
275
|
+
this._touchEnd = (e) => {
|
|
276
|
+
const evt = e, touches = Array.from(evt.changedTouches);
|
|
277
|
+
for (const touch of touches) {
|
|
278
|
+
this._touches.delete(touch.identifier);
|
|
279
|
+
}
|
|
280
|
+
this._mouseTouchFinish();
|
|
281
|
+
};
|
|
282
|
+
this._touchEndClick = (e) => {
|
|
283
|
+
const evt = e, touches = Array.from(evt.changedTouches);
|
|
284
|
+
for (const touch of touches) {
|
|
285
|
+
this._touches.delete(touch.identifier);
|
|
286
|
+
}
|
|
287
|
+
this._mouseTouchClick(e);
|
|
288
|
+
};
|
|
289
|
+
this._touchStart = (e) => {
|
|
290
|
+
const evt = e, touches = Array.from(evt.changedTouches);
|
|
291
|
+
for (const touch of touches) {
|
|
292
|
+
this._touches.set(touch.identifier, performance.now());
|
|
293
|
+
}
|
|
294
|
+
this._mouseTouchMove(e);
|
|
295
|
+
};
|
|
296
|
+
this._canPush = true;
|
|
297
|
+
this._touches = new Map();
|
|
298
|
+
this._handlers = {
|
|
299
|
+
mouseDown: () => this._mouseDown(),
|
|
300
|
+
mouseLeave: () => this._mouseTouchFinish(),
|
|
301
|
+
mouseMove: (e) => this._mouseTouchMove(e),
|
|
302
|
+
mouseUp: (e) => this._mouseTouchClick(e),
|
|
303
|
+
touchStart: (e) => this._touchStart(e),
|
|
304
|
+
touchMove: (e) => this._mouseTouchMove(e),
|
|
305
|
+
touchEnd: (e) => this._touchEnd(e),
|
|
306
|
+
touchCancel: (e) => this._touchEnd(e),
|
|
307
|
+
touchEndClick: (e) => this._touchEndClick(e),
|
|
308
|
+
visibilityChange: () => this._handleVisibilityChange(),
|
|
309
|
+
themeChange: (e) => this._handleThemeChange(e),
|
|
310
|
+
oldThemeChange: (e) => this._handleThemeChange(e),
|
|
311
|
+
resize: () => {
|
|
312
|
+
this._handleWindowResize();
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
addListeners() {
|
|
317
|
+
this._manageListeners(true);
|
|
318
|
+
}
|
|
319
|
+
removeListeners() {
|
|
320
|
+
this._manageListeners(false);
|
|
297
321
|
}
|
|
298
322
|
}
|
|
299
323
|
exports.EventListeners = EventListeners;
|
|
@@ -5,22 +5,18 @@ class InteractionManager {
|
|
|
5
5
|
constructor(engine, container) {
|
|
6
6
|
this.container = container;
|
|
7
7
|
this._engine = engine;
|
|
8
|
-
this._interactors =
|
|
8
|
+
this._interactors = engine.getInteractors(this.container, true);
|
|
9
9
|
this._externalInteractors = [];
|
|
10
10
|
this._particleInteractors = [];
|
|
11
11
|
}
|
|
12
12
|
async externalInteract(delta) {
|
|
13
13
|
for (const interactor of this._externalInteractors) {
|
|
14
|
-
|
|
15
|
-
await interactor.interact(delta);
|
|
16
|
-
}
|
|
14
|
+
interactor.isEnabled() && (await interactor.interact(delta));
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
handleClickMode(mode) {
|
|
20
18
|
for (const interactor of this._externalInteractors) {
|
|
21
|
-
|
|
22
|
-
interactor.handleClickMode(mode);
|
|
23
|
-
}
|
|
19
|
+
interactor.handleClickMode && interactor.handleClickMode(mode);
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
22
|
init() {
|
|
@@ -43,21 +39,15 @@ class InteractionManager {
|
|
|
43
39
|
interactor.clear(particle, delta);
|
|
44
40
|
}
|
|
45
41
|
for (const interactor of this._particleInteractors) {
|
|
46
|
-
|
|
47
|
-
await interactor.interact(particle, delta);
|
|
48
|
-
}
|
|
42
|
+
interactor.isEnabled(particle) && (await interactor.interact(particle, delta));
|
|
49
43
|
}
|
|
50
44
|
}
|
|
51
45
|
async reset(particle) {
|
|
52
46
|
for (const interactor of this._externalInteractors) {
|
|
53
|
-
|
|
54
|
-
await interactor.reset(particle);
|
|
55
|
-
}
|
|
47
|
+
interactor.isEnabled() && interactor.reset(particle);
|
|
56
48
|
}
|
|
57
49
|
for (const interactor of this._particleInteractors) {
|
|
58
|
-
|
|
59
|
-
await interactor.reset(particle);
|
|
60
|
-
}
|
|
50
|
+
interactor.isEnabled(particle) && interactor.reset(particle);
|
|
61
51
|
}
|
|
62
52
|
}
|
|
63
53
|
}
|
|
@@ -8,11 +8,18 @@ class QuadTree {
|
|
|
8
8
|
constructor(rectangle, capacity) {
|
|
9
9
|
this.rectangle = rectangle;
|
|
10
10
|
this.capacity = capacity;
|
|
11
|
+
this._subdivide = () => {
|
|
12
|
+
const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
|
|
13
|
+
for (let i = 0; i < 4; i++) {
|
|
14
|
+
this._subs.push(new QuadTree(new Rectangle_1.Rectangle(x + (width / 2) * (i % 2), y + (height / 2) * (Math.round(i / 2) - (i % 2)), width / 2, height / 2), capacity));
|
|
15
|
+
}
|
|
16
|
+
this._divided = true;
|
|
17
|
+
};
|
|
11
18
|
this._points = [];
|
|
12
19
|
this._divided = false;
|
|
20
|
+
this._subs = [];
|
|
13
21
|
}
|
|
14
22
|
insert(point) {
|
|
15
|
-
var _a, _b, _c, _d, _e;
|
|
16
23
|
if (!this.rectangle.contains(point.position)) {
|
|
17
24
|
return false;
|
|
18
25
|
}
|
|
@@ -21,16 +28,12 @@ class QuadTree {
|
|
|
21
28
|
return true;
|
|
22
29
|
}
|
|
23
30
|
if (!this._divided) {
|
|
24
|
-
this.
|
|
31
|
+
this._subdivide();
|
|
25
32
|
}
|
|
26
|
-
return ((
|
|
27
|
-
((_b = this._NW) === null || _b === void 0 ? void 0 : _b.insert(point)) ||
|
|
28
|
-
((_c = this._SE) === null || _c === void 0 ? void 0 : _c.insert(point)) ||
|
|
29
|
-
((_d = this._SW) === null || _d === void 0 ? void 0 : _d.insert(point)))) !== null && _e !== void 0 ? _e : false);
|
|
33
|
+
return this._subs.some((sub) => sub.insert(point));
|
|
30
34
|
}
|
|
31
35
|
query(range, check, found) {
|
|
32
|
-
|
|
33
|
-
const res = found !== null && found !== void 0 ? found : [];
|
|
36
|
+
const res = found || [];
|
|
34
37
|
if (!range.intersects(this.rectangle)) {
|
|
35
38
|
return [];
|
|
36
39
|
}
|
|
@@ -43,10 +46,9 @@ class QuadTree {
|
|
|
43
46
|
res.push(p.particle);
|
|
44
47
|
}
|
|
45
48
|
if (this._divided) {
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
(_d = this._SW) === null || _d === void 0 ? void 0 : _d.query(range, check, res);
|
|
49
|
+
for (const sub of this._subs) {
|
|
50
|
+
sub.query(range, check, res);
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
return res;
|
|
52
54
|
}
|
|
@@ -56,13 +58,5 @@ class QuadTree {
|
|
|
56
58
|
queryRectangle(position, size, check) {
|
|
57
59
|
return this.query(new Rectangle_1.Rectangle(position.x, position.y, size.width, size.height), check);
|
|
58
60
|
}
|
|
59
|
-
subdivide() {
|
|
60
|
-
const x = this.rectangle.position.x, y = this.rectangle.position.y, w = this.rectangle.size.width, h = this.rectangle.size.height, capacity = this.capacity;
|
|
61
|
-
this._NE = new QuadTree(new Rectangle_1.Rectangle(x, y, w / 2, h / 2), capacity);
|
|
62
|
-
this._NW = new QuadTree(new Rectangle_1.Rectangle(x + w / 2, y, w / 2, h / 2), capacity);
|
|
63
|
-
this._SE = new QuadTree(new Rectangle_1.Rectangle(x, y + h / 2, w / 2, h / 2), capacity);
|
|
64
|
-
this._SW = new QuadTree(new Rectangle_1.Rectangle(x + w / 2, y + h / 2, w / 2, h / 2), capacity);
|
|
65
|
-
this._divided = true;
|
|
66
|
-
}
|
|
67
61
|
}
|
|
68
62
|
exports.QuadTree = QuadTree;
|