@tsparticles/engine 4.0.0-alpha.5 → 4.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/164.min.js +1 -0
- package/README.md +41 -7
- package/browser/Core/Canvas.js +250 -143
- package/browser/Core/Container.js +80 -74
- package/browser/Core/Engine.js +44 -67
- package/browser/Core/Particle.js +202 -173
- package/browser/Core/Particles.js +187 -138
- package/browser/Core/Retina.js +5 -0
- package/browser/Core/Utils/Constants.js +2 -2
- package/browser/Core/Utils/EventListeners.js +67 -63
- 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/Enums/Types/EasingType.js +18 -3
- 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 +63 -4
- 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 +25 -5
- 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 +43 -62
- package/browser/Utils/ColorUtils.js +30 -19
- package/browser/Utils/EventDispatcher.js +1 -0
- package/browser/Utils/MathUtils.js +12 -7
- package/browser/Utils/Utils.js +109 -31
- package/browser/exports.js +1 -2
- package/cjs/Core/Canvas.js +250 -143
- package/cjs/Core/Container.js +80 -74
- package/cjs/Core/Engine.js +44 -67
- package/cjs/Core/Particle.js +202 -173
- package/cjs/Core/Particles.js +187 -138
- package/cjs/Core/Retina.js +5 -0
- package/cjs/Core/Utils/Constants.js +2 -2
- package/cjs/Core/Utils/EventListeners.js +67 -63
- 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/Enums/Types/EasingType.js +18 -3
- 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 +63 -4
- 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 +25 -5
- 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 +43 -62
- package/cjs/Utils/ColorUtils.js +30 -19
- package/cjs/Utils/EventDispatcher.js +1 -0
- package/cjs/Utils/MathUtils.js +12 -7
- package/cjs/Utils/Utils.js +109 -31
- package/cjs/exports.js +1 -2
- package/dist_browser_Core_Container_js.js +12 -12
- package/esm/Core/Canvas.js +250 -143
- package/esm/Core/Container.js +80 -74
- package/esm/Core/Engine.js +44 -67
- package/esm/Core/Particle.js +202 -173
- package/esm/Core/Particles.js +187 -138
- package/esm/Core/Retina.js +5 -0
- package/esm/Core/Utils/Constants.js +2 -2
- package/esm/Core/Utils/EventListeners.js +67 -63
- 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/Enums/Types/EasingType.js +18 -3
- 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 +63 -4
- 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 +25 -5
- 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 +43 -62
- package/esm/Utils/ColorUtils.js +30 -19
- package/esm/Utils/EventDispatcher.js +1 -0
- package/esm/Utils/MathUtils.js +12 -7
- package/esm/Utils/Utils.js +109 -31
- package/esm/exports.js +1 -2
- package/package.json +1 -1
- package/report.html +3 -3
- package/scripts/install.js +4 -20
- package/tsparticles.engine.js +93 -91
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/Canvas.d.ts +17 -4
- package/types/Core/Container.d.ts +3 -7
- package/types/Core/Engine.d.ts +13 -20
- package/types/Core/Interfaces/IColorManager.d.ts +0 -1
- package/types/Core/Interfaces/IContainerPlugin.d.ts +6 -1
- package/types/Core/Interfaces/IPalette.d.ts +7 -0
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
- package/types/Core/Interfaces/IShapeDrawData.d.ts +8 -0
- package/types/Core/Interfaces/IShapeDrawer.d.ts +0 -1
- package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
- package/types/Core/Particle.d.ts +4 -7
- package/types/Core/Particles.d.ts +15 -7
- package/types/Core/Utils/Constants.d.ts +2 -2
- 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/Enums/Types/EasingType.d.ts +20 -5
- 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 +2 -0
- 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 +2 -2
- 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/EngineInitializers.d.ts +6 -3
- package/types/Utils/CanvasUtils.d.ts +6 -14
- package/types/Utils/ColorUtils.d.ts +3 -2
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/Utils/Utils.d.ts +8 -1
- package/types/export-types.d.ts +3 -5
- package/types/exports.d.ts +1 -2
- package/umd/Core/Canvas.js +248 -141
- package/umd/Core/Container.js +80 -74
- package/umd/Core/Engine.js +43 -66
- package/umd/Core/Particle.js +203 -174
- package/umd/Core/Particles.js +187 -138
- package/umd/Core/Retina.js +5 -0
- package/umd/Core/Utils/Constants.js +3 -3
- package/umd/Core/Utils/EventListeners.js +67 -63
- 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/Enums/Types/EasingType.js +18 -3
- 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 +63 -4
- 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 +26 -6
- 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 +43 -66
- package/umd/Utils/ColorUtils.js +30 -18
- package/umd/Utils/EventDispatcher.js +1 -0
- package/umd/Utils/MathUtils.js +14 -7
- 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/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/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/Interfaces/IMovePathGenerator.js +0 -1
- package/esm/Core/Interfaces/IParticleMover.js +0 -1
- 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/esm/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- package/tsparticles.engine.min.js.LICENSE.txt +0 -1
- 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/Utils/Point.js +0 -20
- package/umd/Core/Utils/QuadTree.js +0 -73
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -47
- package/umd/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -12
- /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 → cjs/Core/Interfaces/IPalette.js} +0 -0
- /package/cjs/{Core/Interfaces/IMovePathGenerator.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/{cjs/Core/Interfaces/IParticleMover.js → esm/Core/Interfaces/IPalette.js} +0 -0
- /package/{cjs/Options/Interfaces/Particles/Move/IMoveAttract.js → esm/Options/Interfaces/Particles/IFill.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
|
@@ -1,102 +1,34 @@
|
|
|
1
|
-
import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit,
|
|
1
|
+
import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, spatialHashGridCellSize, squareExp, } from "./Utils/Constants.js";
|
|
2
2
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
3
3
|
import { LimitMode } from "../Enums/Modes/LimitMode.js";
|
|
4
4
|
import { Particle } from "./Particle.js";
|
|
5
|
-
import {
|
|
6
|
-
import { QuadTree } from "./Utils/QuadTree.js";
|
|
7
|
-
import { Rectangle } from "./Utils/Ranges.js";
|
|
5
|
+
import { SpatialHashGrid } from "./Utils/SpatialHashGrid.js";
|
|
8
6
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
9
7
|
import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
|
|
10
|
-
const qTreeRectangle = (canvasSize) => {
|
|
11
|
-
const { height, width } = canvasSize;
|
|
12
|
-
return new Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
|
|
13
|
-
};
|
|
14
8
|
export class Particles {
|
|
9
|
+
checkParticlePositionPlugins;
|
|
10
|
+
effectDrawers;
|
|
11
|
+
grid;
|
|
12
|
+
shapeDrawers;
|
|
13
|
+
updaters;
|
|
14
|
+
_array;
|
|
15
|
+
_container;
|
|
16
|
+
_engine;
|
|
17
|
+
_groupLimits;
|
|
18
|
+
_limit;
|
|
19
|
+
_maxZIndex;
|
|
20
|
+
_minZIndex;
|
|
21
|
+
_needsSort;
|
|
22
|
+
_nextId;
|
|
23
|
+
_particleResetPlugins;
|
|
24
|
+
_particleUpdatePlugins;
|
|
25
|
+
_pool;
|
|
26
|
+
_postParticleUpdatePlugins;
|
|
27
|
+
_postUpdatePlugins;
|
|
28
|
+
_resizeFactor;
|
|
29
|
+
_updatePlugins;
|
|
30
|
+
_zArray;
|
|
15
31
|
constructor(engine, container) {
|
|
16
|
-
this._addToPool = (...particles) => {
|
|
17
|
-
this._pool.push(...particles);
|
|
18
|
-
};
|
|
19
|
-
this._applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
20
|
-
const numberOptions = options.number;
|
|
21
|
-
if (!numberOptions.density.enable) {
|
|
22
|
-
if (group === undefined) {
|
|
23
|
-
this._limit = numberOptions.limit.value;
|
|
24
|
-
}
|
|
25
|
-
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
26
|
-
this._groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
31
|
-
if (group === undefined) {
|
|
32
|
-
this._limit = numberOptions.limit.value * densityFactor;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
36
|
-
}
|
|
37
|
-
if (particlesCount < particlesNumber) {
|
|
38
|
-
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
39
|
-
}
|
|
40
|
-
else if (particlesCount > particlesNumber) {
|
|
41
|
-
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
this._initDensityFactor = densityOptions => {
|
|
45
|
-
const container = this._container;
|
|
46
|
-
if (!container.canvas.element || !densityOptions.enable) {
|
|
47
|
-
return defaultDensityFactor;
|
|
48
|
-
}
|
|
49
|
-
const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
|
|
50
|
-
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
|
|
51
|
-
};
|
|
52
|
-
this._pushParticle = (position, overrideOptions, group, initializer) => {
|
|
53
|
-
try {
|
|
54
|
-
const particle = this._pool.pop() ?? new Particle(this._engine, this._container);
|
|
55
|
-
particle.init(this._nextId, position, overrideOptions, group);
|
|
56
|
-
let canAdd = true;
|
|
57
|
-
if (initializer) {
|
|
58
|
-
canAdd = initializer(particle);
|
|
59
|
-
}
|
|
60
|
-
if (!canAdd) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this._array.push(particle);
|
|
64
|
-
this._zArray.push(particle);
|
|
65
|
-
this._nextId++;
|
|
66
|
-
this._engine.dispatchEvent(EventType.particleAdded, {
|
|
67
|
-
container: this._container,
|
|
68
|
-
data: {
|
|
69
|
-
particle,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
return particle;
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
getLogger().warning(`error adding particle: ${e}`);
|
|
76
|
-
}
|
|
77
|
-
return undefined;
|
|
78
|
-
};
|
|
79
|
-
this._removeParticle = (index, group, override) => {
|
|
80
|
-
const particle = this._array[index];
|
|
81
|
-
if (!particle) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (particle.group !== group) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const zIdx = this._zArray.indexOf(particle);
|
|
88
|
-
this._array.splice(index, deleteCount);
|
|
89
|
-
this._zArray.splice(zIdx, deleteCount);
|
|
90
|
-
particle.destroy(override);
|
|
91
|
-
this._engine.dispatchEvent(EventType.particleRemoved, {
|
|
92
|
-
container: this._container,
|
|
93
|
-
data: {
|
|
94
|
-
particle,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
this._addToPool(particle);
|
|
98
|
-
return true;
|
|
99
|
-
};
|
|
100
32
|
this._engine = engine;
|
|
101
33
|
this._container = container;
|
|
102
34
|
this._nextId = 0;
|
|
@@ -106,12 +38,18 @@ export class Particles {
|
|
|
106
38
|
this._limit = 0;
|
|
107
39
|
this._groupLimits = new Map();
|
|
108
40
|
this._needsSort = false;
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
41
|
+
this._minZIndex = 0;
|
|
42
|
+
this._maxZIndex = 0;
|
|
43
|
+
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
44
|
+
this.effectDrawers = new Map();
|
|
45
|
+
this.shapeDrawers = new Map();
|
|
114
46
|
this.updaters = [];
|
|
47
|
+
this.checkParticlePositionPlugins = [];
|
|
48
|
+
this._particleResetPlugins = [];
|
|
49
|
+
this._particleUpdatePlugins = [];
|
|
50
|
+
this._postUpdatePlugins = [];
|
|
51
|
+
this._postParticleUpdatePlugins = [];
|
|
52
|
+
this._updatePlugins = [];
|
|
115
53
|
}
|
|
116
54
|
get count() {
|
|
117
55
|
return this._array.length;
|
|
@@ -132,20 +70,61 @@ export class Particles {
|
|
|
132
70
|
return;
|
|
133
71
|
}
|
|
134
72
|
break;
|
|
73
|
+
default:
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const particle = this._pool.pop() ?? new Particle(this._engine, this._container);
|
|
79
|
+
particle.init(this._nextId, position, overrideOptions, group);
|
|
80
|
+
let canAdd = true;
|
|
81
|
+
if (initializer) {
|
|
82
|
+
canAdd = initializer(particle);
|
|
83
|
+
}
|
|
84
|
+
if (!canAdd) {
|
|
85
|
+
this._pool.push(particle);
|
|
86
|
+
return;
|
|
135
87
|
}
|
|
88
|
+
this._array.push(particle);
|
|
89
|
+
this._zArray.push(particle);
|
|
90
|
+
this._nextId++;
|
|
91
|
+
this._engine.dispatchEvent(EventType.particleAdded, {
|
|
92
|
+
container: this._container,
|
|
93
|
+
data: {
|
|
94
|
+
particle,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
return particle;
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
getLogger().warning(`error adding particle: ${e}`);
|
|
136
101
|
}
|
|
137
|
-
return
|
|
102
|
+
return undefined;
|
|
138
103
|
}
|
|
139
104
|
clear() {
|
|
140
105
|
this._array = [];
|
|
141
106
|
this._zArray = [];
|
|
142
|
-
this._pluginsInitialized = false;
|
|
143
107
|
}
|
|
144
108
|
destroy() {
|
|
109
|
+
const container = this._container;
|
|
110
|
+
for (const [, effectDrawer] of this.effectDrawers) {
|
|
111
|
+
effectDrawer.destroy?.(container);
|
|
112
|
+
}
|
|
113
|
+
for (const [, shapeDrawer] of this.shapeDrawers) {
|
|
114
|
+
shapeDrawer.destroy?.(container);
|
|
115
|
+
}
|
|
145
116
|
this._array = [];
|
|
117
|
+
this._pool.length = 0;
|
|
146
118
|
this._zArray = [];
|
|
147
|
-
this.
|
|
119
|
+
this.effectDrawers = new Map();
|
|
120
|
+
this.shapeDrawers = new Map();
|
|
148
121
|
this.updaters = [];
|
|
122
|
+
this.checkParticlePositionPlugins = [];
|
|
123
|
+
this._particleResetPlugins = [];
|
|
124
|
+
this._particleUpdatePlugins = [];
|
|
125
|
+
this._postUpdatePlugins = [];
|
|
126
|
+
this._postParticleUpdatePlugins = [];
|
|
127
|
+
this._updatePlugins = [];
|
|
149
128
|
}
|
|
150
129
|
drawParticles(delta) {
|
|
151
130
|
for (const particle of this._zArray) {
|
|
@@ -163,14 +142,46 @@ export class Particles {
|
|
|
163
142
|
}
|
|
164
143
|
async init() {
|
|
165
144
|
const container = this._container, options = container.actualOptions;
|
|
166
|
-
this.
|
|
145
|
+
this._minZIndex = 0;
|
|
146
|
+
this._maxZIndex = 0;
|
|
167
147
|
this._needsSort = false;
|
|
148
|
+
this.checkParticlePositionPlugins = [];
|
|
149
|
+
this._updatePlugins = [];
|
|
150
|
+
this._particleUpdatePlugins = [];
|
|
151
|
+
this._postUpdatePlugins = [];
|
|
152
|
+
this._particleResetPlugins = [];
|
|
153
|
+
this._postParticleUpdatePlugins = [];
|
|
154
|
+
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
168
155
|
for (const plugin of container.plugins) {
|
|
169
156
|
if (plugin.redrawInit) {
|
|
170
157
|
await plugin.redrawInit();
|
|
171
158
|
}
|
|
159
|
+
if (plugin.checkParticlePosition) {
|
|
160
|
+
this.checkParticlePositionPlugins.push(plugin);
|
|
161
|
+
}
|
|
162
|
+
if (plugin.update) {
|
|
163
|
+
this._updatePlugins.push(plugin);
|
|
164
|
+
}
|
|
165
|
+
if (plugin.particleUpdate) {
|
|
166
|
+
this._particleUpdatePlugins.push(plugin);
|
|
167
|
+
}
|
|
168
|
+
if (plugin.postUpdate) {
|
|
169
|
+
this._postUpdatePlugins.push(plugin);
|
|
170
|
+
}
|
|
171
|
+
if (plugin.particleReset) {
|
|
172
|
+
this._particleResetPlugins.push(plugin);
|
|
173
|
+
}
|
|
174
|
+
if (plugin.postParticleUpdate) {
|
|
175
|
+
this._postParticleUpdatePlugins.push(plugin);
|
|
176
|
+
}
|
|
172
177
|
}
|
|
173
178
|
await this.initPlugins();
|
|
179
|
+
for (const drawer of this.effectDrawers.values()) {
|
|
180
|
+
await drawer.init?.(container);
|
|
181
|
+
}
|
|
182
|
+
for (const drawer of this.shapeDrawers.values()) {
|
|
183
|
+
await drawer.init?.(container);
|
|
184
|
+
}
|
|
174
185
|
let handled = false;
|
|
175
186
|
for (const plugin of container.plugins) {
|
|
176
187
|
handled = plugin.particlesInitialization?.() ?? handled;
|
|
@@ -195,15 +206,10 @@ export class Particles {
|
|
|
195
206
|
}
|
|
196
207
|
}
|
|
197
208
|
async initPlugins() {
|
|
198
|
-
if (this._pluginsInitialized) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
209
|
const container = this._container;
|
|
202
|
-
this.
|
|
210
|
+
this.effectDrawers = await this._engine.getEffectDrawers(container, true);
|
|
211
|
+
this.shapeDrawers = await this._engine.getShapeDrawers(container, true);
|
|
203
212
|
this.updaters = await this._engine.getUpdaters(container, true);
|
|
204
|
-
for (const pathGenerator of container.pathGenerators.values()) {
|
|
205
|
-
pathGenerator.init(container);
|
|
206
|
-
}
|
|
207
213
|
}
|
|
208
214
|
push(nb, position, overrideOptions, group) {
|
|
209
215
|
for (let i = 0; i < nb; i++) {
|
|
@@ -252,19 +258,15 @@ export class Particles {
|
|
|
252
258
|
this._applyDensity(options.particles, pluginsCount);
|
|
253
259
|
}
|
|
254
260
|
setLastZIndex(zIndex) {
|
|
255
|
-
this.
|
|
256
|
-
this._needsSort = this._needsSort || this._lastZIndex < zIndex;
|
|
261
|
+
this._needsSort ||= zIndex >= this._maxZIndex || (zIndex > this._minZIndex && zIndex < this._maxZIndex);
|
|
257
262
|
}
|
|
258
263
|
setResizeFactor(factor) {
|
|
259
264
|
this._resizeFactor = factor;
|
|
260
265
|
}
|
|
261
266
|
update(delta) {
|
|
262
|
-
const
|
|
263
|
-
this.
|
|
264
|
-
for (const
|
|
265
|
-
pathGenerator.update();
|
|
266
|
-
}
|
|
267
|
-
for (const plugin of container.plugins) {
|
|
267
|
+
const particlesToDelete = new Set();
|
|
268
|
+
this.grid.clear();
|
|
269
|
+
for (const plugin of this._updatePlugins) {
|
|
268
270
|
plugin.update?.(delta);
|
|
269
271
|
}
|
|
270
272
|
const resizeFactor = this._resizeFactor;
|
|
@@ -276,27 +278,20 @@ export class Particles {
|
|
|
276
278
|
particle.initialPosition.y *= resizeFactor.height;
|
|
277
279
|
}
|
|
278
280
|
particle.ignoresResizeRatio = false;
|
|
279
|
-
for (const plugin of this.
|
|
280
|
-
|
|
281
|
-
plugin.particleReset(particle);
|
|
282
|
-
}
|
|
281
|
+
for (const plugin of this._particleResetPlugins) {
|
|
282
|
+
plugin.particleReset?.(particle);
|
|
283
283
|
}
|
|
284
|
-
for (const plugin of this.
|
|
284
|
+
for (const plugin of this._particleUpdatePlugins) {
|
|
285
285
|
if (particle.destroyed) {
|
|
286
286
|
break;
|
|
287
287
|
}
|
|
288
288
|
plugin.particleUpdate?.(particle, delta);
|
|
289
289
|
}
|
|
290
|
-
for (const mover of this.movers) {
|
|
291
|
-
if (mover.isEnabled(particle)) {
|
|
292
|
-
mover.move(particle, delta);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
290
|
if (particle.destroyed) {
|
|
296
291
|
particlesToDelete.add(particle);
|
|
297
292
|
continue;
|
|
298
293
|
}
|
|
299
|
-
this.
|
|
294
|
+
this.grid.insert(particle);
|
|
300
295
|
}
|
|
301
296
|
if (particlesToDelete.size) {
|
|
302
297
|
const checkDelete = (p) => !particlesToDelete.has(p);
|
|
@@ -312,20 +307,16 @@ export class Particles {
|
|
|
312
307
|
}
|
|
313
308
|
this._addToPool(...particlesToDelete);
|
|
314
309
|
}
|
|
315
|
-
for (const plugin of
|
|
316
|
-
|
|
317
|
-
plugin.postUpdate(delta);
|
|
318
|
-
}
|
|
310
|
+
for (const plugin of this._postUpdatePlugins) {
|
|
311
|
+
plugin.postUpdate?.(delta);
|
|
319
312
|
}
|
|
320
313
|
for (const particle of this._array) {
|
|
321
314
|
for (const updater of this.updaters) {
|
|
322
315
|
updater.update(particle, delta);
|
|
323
316
|
}
|
|
324
317
|
if (!particle.destroyed && !particle.spawning) {
|
|
325
|
-
for (const plugin of
|
|
326
|
-
|
|
327
|
-
plugin.postParticleUpdate(particle, delta);
|
|
328
|
-
}
|
|
318
|
+
for (const plugin of this._postParticleUpdatePlugins) {
|
|
319
|
+
plugin.postParticleUpdate?.(particle, delta);
|
|
329
320
|
}
|
|
330
321
|
}
|
|
331
322
|
}
|
|
@@ -333,12 +324,70 @@ export class Particles {
|
|
|
333
324
|
if (this._needsSort) {
|
|
334
325
|
const zArray = this._zArray;
|
|
335
326
|
zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
|
|
336
|
-
const lastItem = zArray[zArray.length - lengthOffset];
|
|
337
|
-
if (!lastItem) {
|
|
327
|
+
const firstItem = zArray[minIndex], lastItem = zArray[zArray.length - lengthOffset];
|
|
328
|
+
if (!firstItem || !lastItem) {
|
|
338
329
|
return;
|
|
339
330
|
}
|
|
340
|
-
this.
|
|
331
|
+
this._maxZIndex = firstItem.position.z;
|
|
332
|
+
this._minZIndex = lastItem.position.z;
|
|
341
333
|
this._needsSort = false;
|
|
342
334
|
}
|
|
343
335
|
}
|
|
336
|
+
_addToPool = (...particles) => {
|
|
337
|
+
this._pool.push(...particles);
|
|
338
|
+
};
|
|
339
|
+
_applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
340
|
+
const numberOptions = options.number;
|
|
341
|
+
if (!numberOptions.density.enable) {
|
|
342
|
+
if (group === undefined) {
|
|
343
|
+
this._limit = numberOptions.limit.value;
|
|
344
|
+
}
|
|
345
|
+
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
346
|
+
this._groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
351
|
+
if (group === undefined) {
|
|
352
|
+
this._limit = numberOptions.limit.value * densityFactor;
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
356
|
+
}
|
|
357
|
+
if (particlesCount < particlesNumber) {
|
|
358
|
+
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
359
|
+
}
|
|
360
|
+
else if (particlesCount > particlesNumber) {
|
|
361
|
+
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
_initDensityFactor = densityOptions => {
|
|
365
|
+
const container = this._container;
|
|
366
|
+
if (!container.canvas.element || !densityOptions.enable) {
|
|
367
|
+
return defaultDensityFactor;
|
|
368
|
+
}
|
|
369
|
+
const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
|
|
370
|
+
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
|
|
371
|
+
};
|
|
372
|
+
_removeParticle = (index, group, override) => {
|
|
373
|
+
const particle = this._array[index];
|
|
374
|
+
if (!particle) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
if (particle.group !== group) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
const zIdx = this._zArray.indexOf(particle);
|
|
381
|
+
this._array.splice(index, deleteCount);
|
|
382
|
+
this._zArray.splice(zIdx, deleteCount);
|
|
383
|
+
particle.destroy(override);
|
|
384
|
+
this._engine.dispatchEvent(EventType.particleRemoved, {
|
|
385
|
+
container: this._container,
|
|
386
|
+
data: {
|
|
387
|
+
particle,
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
this._addToPool(particle);
|
|
391
|
+
return true;
|
|
392
|
+
};
|
|
344
393
|
}
|
package/browser/Core/Retina.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { defaultRatio, defaultReduceFactor } from "./Utils/Constants.js";
|
|
2
2
|
import { getRangeValue } from "../Utils/MathUtils.js";
|
|
3
3
|
export class Retina {
|
|
4
|
+
container;
|
|
5
|
+
maxSpeed;
|
|
6
|
+
pixelRatio;
|
|
7
|
+
reduceFactor;
|
|
8
|
+
sizeAnimationSpeed;
|
|
4
9
|
constructor(container) {
|
|
5
10
|
this.container = container;
|
|
6
11
|
this.pixelRatio = defaultRatio;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const generatedAttribute = "generated", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
|
|
1
|
+
export const generatedAttribute = "generated", defaultCompositeValue = "source-over", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
|
|
2
2
|
x: 0,
|
|
3
3
|
y: 0,
|
|
4
4
|
z: 0,
|
|
@@ -7,4 +7,4 @@ export const generatedAttribute = "generated", resizeEvent = "resize", visibilit
|
|
|
7
7
|
b: 0,
|
|
8
8
|
c: 0,
|
|
9
9
|
d: 1,
|
|
10
|
-
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2,
|
|
10
|
+
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, spatialHashGridCellSize = 100, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, inverseFactorNumerator = 1, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, zIndexFactorOffset = 1, defaultOpacity = 1, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minZ = 0, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0, defaultZoom = 1;
|
|
@@ -1,71 +1,12 @@
|
|
|
1
1
|
import { manageListener, safeDocument } from "../../Utils/Utils.js";
|
|
2
2
|
import { millisecondsToSeconds, resizeEvent, visibilityChangeEvent } from "./Constants.js";
|
|
3
3
|
export class EventListeners {
|
|
4
|
+
container;
|
|
5
|
+
_handlers;
|
|
6
|
+
_resizeObserver;
|
|
7
|
+
_resizeTimeout;
|
|
4
8
|
constructor(container) {
|
|
5
9
|
this.container = container;
|
|
6
|
-
this._handleVisibilityChange = () => {
|
|
7
|
-
const container = this.container, options = container.actualOptions;
|
|
8
|
-
if (!options.pauseOnBlur) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (safeDocument().hidden) {
|
|
12
|
-
container.pageHidden = true;
|
|
13
|
-
container.pause();
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
container.pageHidden = false;
|
|
17
|
-
if (container.animationStatus) {
|
|
18
|
-
container.play(true);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
container.draw(true);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
this._handleWindowResize = () => {
|
|
26
|
-
if (this._resizeTimeout) {
|
|
27
|
-
clearTimeout(this._resizeTimeout);
|
|
28
|
-
delete this._resizeTimeout;
|
|
29
|
-
}
|
|
30
|
-
const handleResize = async () => {
|
|
31
|
-
const canvas = this.container.canvas;
|
|
32
|
-
await canvas.windowResize();
|
|
33
|
-
};
|
|
34
|
-
this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
35
|
-
};
|
|
36
|
-
this._manageListeners = add => {
|
|
37
|
-
const handlers = this._handlers;
|
|
38
|
-
this._manageResize(add);
|
|
39
|
-
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
40
|
-
};
|
|
41
|
-
this._manageResize = add => {
|
|
42
|
-
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
43
|
-
if (!options.resize.enable) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (typeof ResizeObserver === "undefined") {
|
|
47
|
-
manageListener(globalThis, resizeEvent, handlers.resize, add);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const canvasEl = container.canvas.element;
|
|
51
|
-
if (this._resizeObserver && !add) {
|
|
52
|
-
if (canvasEl) {
|
|
53
|
-
this._resizeObserver.unobserve(canvasEl);
|
|
54
|
-
}
|
|
55
|
-
this._resizeObserver.disconnect();
|
|
56
|
-
delete this._resizeObserver;
|
|
57
|
-
}
|
|
58
|
-
else if (!this._resizeObserver && add && canvasEl) {
|
|
59
|
-
this._resizeObserver = new ResizeObserver((entries) => {
|
|
60
|
-
const entry = entries.find(e => e.target === canvasEl);
|
|
61
|
-
if (!entry) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this._handleWindowResize();
|
|
65
|
-
});
|
|
66
|
-
this._resizeObserver.observe(canvasEl);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
10
|
this._handlers = {
|
|
70
11
|
visibilityChange: () => {
|
|
71
12
|
this._handleVisibilityChange();
|
|
@@ -81,4 +22,67 @@ export class EventListeners {
|
|
|
81
22
|
removeListeners() {
|
|
82
23
|
this._manageListeners(false);
|
|
83
24
|
}
|
|
25
|
+
_handleVisibilityChange = () => {
|
|
26
|
+
const container = this.container, options = container.actualOptions;
|
|
27
|
+
if (!options.pauseOnBlur) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (safeDocument().hidden) {
|
|
31
|
+
container.pageHidden = true;
|
|
32
|
+
container.pause();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
container.pageHidden = false;
|
|
36
|
+
if (container.animationStatus) {
|
|
37
|
+
container.play(true);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
container.draw(true);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
_handleWindowResize = () => {
|
|
45
|
+
if (this._resizeTimeout) {
|
|
46
|
+
clearTimeout(this._resizeTimeout);
|
|
47
|
+
delete this._resizeTimeout;
|
|
48
|
+
}
|
|
49
|
+
const handleResize = async () => {
|
|
50
|
+
const canvas = this.container.canvas;
|
|
51
|
+
await canvas.windowResize();
|
|
52
|
+
};
|
|
53
|
+
this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
54
|
+
};
|
|
55
|
+
_manageListeners = add => {
|
|
56
|
+
const handlers = this._handlers;
|
|
57
|
+
this._manageResize(add);
|
|
58
|
+
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
59
|
+
};
|
|
60
|
+
_manageResize = add => {
|
|
61
|
+
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
62
|
+
if (!options.resize.enable) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (typeof ResizeObserver === "undefined") {
|
|
66
|
+
manageListener(globalThis, resizeEvent, handlers.resize, add);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const canvasEl = container.canvas.element;
|
|
70
|
+
if (this._resizeObserver && !add) {
|
|
71
|
+
if (canvasEl) {
|
|
72
|
+
this._resizeObserver.unobserve(canvasEl);
|
|
73
|
+
}
|
|
74
|
+
this._resizeObserver.disconnect();
|
|
75
|
+
delete this._resizeObserver;
|
|
76
|
+
}
|
|
77
|
+
else if (!this._resizeObserver && add && canvasEl) {
|
|
78
|
+
this._resizeObserver = new ResizeObserver((entries) => {
|
|
79
|
+
const entry = entries.find(e => e.target === canvasEl);
|
|
80
|
+
if (!entry) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this._handleWindowResize();
|
|
84
|
+
});
|
|
85
|
+
this._resizeObserver.observe(canvasEl);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
84
88
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { RangeType } from "../../Enums/RangeType.js";
|
|
2
|
-
import {
|
|
2
|
+
import { checkDistance } from "../../Utils/MathUtils.js";
|
|
3
3
|
import { squareExp } from "./Constants.js";
|
|
4
4
|
export class BaseRange {
|
|
5
|
+
position;
|
|
6
|
+
type;
|
|
5
7
|
constructor(x, y, type) {
|
|
6
8
|
this.position = {
|
|
7
9
|
x: x,
|
|
@@ -9,32 +11,40 @@ export class BaseRange {
|
|
|
9
11
|
};
|
|
10
12
|
this.type = type;
|
|
11
13
|
}
|
|
14
|
+
_resetPosition(x, y) {
|
|
15
|
+
this.position.x = x;
|
|
16
|
+
this.position.y = y;
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
19
|
export class Circle extends BaseRange {
|
|
20
|
+
radius;
|
|
14
21
|
constructor(x, y, radius) {
|
|
15
22
|
super(x, y, RangeType.circle);
|
|
16
23
|
this.radius = radius;
|
|
17
24
|
}
|
|
18
25
|
contains(point) {
|
|
19
|
-
return
|
|
26
|
+
return checkDistance(point, this.position, this.radius);
|
|
20
27
|
}
|
|
21
28
|
intersects(range) {
|
|
22
|
-
const pos1 = this.position, pos2 = range.position,
|
|
29
|
+
const pos1 = this.position, pos2 = range.position, r = this.radius, dx = Math.abs(pos2.x - pos1.x), dy = Math.abs(pos2.y - pos1.y);
|
|
23
30
|
if (range instanceof Circle || range.type === RangeType.circle) {
|
|
24
|
-
const circleRange = range, rSum = r + circleRange.radius, dist = Math.
|
|
31
|
+
const circleRange = range, rSum = r + circleRange.radius, dist = Math.hypot(dx, dy);
|
|
25
32
|
return rSum > dist;
|
|
26
33
|
}
|
|
27
34
|
else if (range instanceof Rectangle || range.type === RangeType.rectangle) {
|
|
28
|
-
const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(
|
|
29
|
-
return
|
|
30
|
-
(distPos.x <= r + width && distPos.y <= r + height) ||
|
|
31
|
-
distPos.x <= width ||
|
|
32
|
-
distPos.y <= height);
|
|
35
|
+
const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(dx - width, squareExp) + Math.pow(dy - height, squareExp);
|
|
36
|
+
return edges <= r ** squareExp || (dx <= r + width && dy <= r + height) || dx <= width || dy <= height;
|
|
33
37
|
}
|
|
34
38
|
return false;
|
|
35
39
|
}
|
|
40
|
+
reset(x, y, radius) {
|
|
41
|
+
this._resetPosition(x, y);
|
|
42
|
+
this.radius = radius;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
36
45
|
}
|
|
37
46
|
export class Rectangle extends BaseRange {
|
|
47
|
+
size;
|
|
38
48
|
constructor(x, y, width, height) {
|
|
39
49
|
super(x, y, RangeType.rectangle);
|
|
40
50
|
this.size = {
|
|
@@ -50,7 +60,16 @@ export class Rectangle extends BaseRange {
|
|
|
50
60
|
if (range instanceof Circle) {
|
|
51
61
|
return range.intersects(this);
|
|
52
62
|
}
|
|
53
|
-
|
|
63
|
+
if (!(range instanceof Rectangle)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const w = this.size.width, h = this.size.height, pos1 = this.position, pos2 = range.position, size2 = range.size, w2 = size2.width, h2 = size2.height;
|
|
54
67
|
return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y;
|
|
55
68
|
}
|
|
69
|
+
reset(x, y, width, height) {
|
|
70
|
+
this._resetPosition(x, y);
|
|
71
|
+
this.size.width = width;
|
|
72
|
+
this.size.height = height;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
56
75
|
}
|