@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/Particle.js
CHANGED
|
@@ -8,54 +8,174 @@ const Interactivity_1 = require("../Options/Classes/Interactivity/Interactivity"
|
|
|
8
8
|
const Vector_1 = require("./Utils/Vector");
|
|
9
9
|
const Vector3d_1 = require("./Utils/Vector3d");
|
|
10
10
|
const CanvasUtils_1 = require("../Utils/CanvasUtils");
|
|
11
|
+
const Constants_1 = require("./Utils/Constants");
|
|
11
12
|
const OptionsUtils_1 = require("../Utils/OptionsUtils");
|
|
12
13
|
const fixOutMode = (data) => {
|
|
13
14
|
if (!(0, Utils_1.isInArray)(data.outMode, data.checkModes)) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
const diameter = data.radius * 2;
|
|
18
|
+
if (data.coord > data.maxCoord - diameter) {
|
|
17
19
|
data.setCb(-data.radius);
|
|
18
20
|
}
|
|
19
|
-
else if (data.coord <
|
|
21
|
+
else if (data.coord < diameter) {
|
|
20
22
|
data.setCb(data.radius);
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
class Particle {
|
|
24
26
|
constructor(engine, id, container, position, overrideOptions, group) {
|
|
25
27
|
this.container = container;
|
|
28
|
+
this._calcPosition = (container, position, zIndex, tryCount = 0) => {
|
|
29
|
+
for (const [, plugin] of container.plugins) {
|
|
30
|
+
const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
|
31
|
+
if (pluginPos) {
|
|
32
|
+
return Vector3d_1.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const canvasSize = container.canvas.size, exactPosition = (0, NumberUtils_1.calcExactPositionOrRandomFromSize)({
|
|
36
|
+
size: canvasSize,
|
|
37
|
+
position: position,
|
|
38
|
+
}), pos = Vector3d_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
|
|
39
|
+
fixOutMode({
|
|
40
|
+
outMode,
|
|
41
|
+
checkModes: ["bounce", "bounce-horizontal"],
|
|
42
|
+
coord: pos.x,
|
|
43
|
+
maxCoord: container.canvas.size.width,
|
|
44
|
+
setCb: (value) => (pos.x += value),
|
|
45
|
+
radius,
|
|
46
|
+
});
|
|
47
|
+
}, fixVertical = (outMode) => {
|
|
48
|
+
fixOutMode({
|
|
49
|
+
outMode,
|
|
50
|
+
checkModes: ["bounce", "bounce-vertical"],
|
|
51
|
+
coord: pos.y,
|
|
52
|
+
maxCoord: container.canvas.size.height,
|
|
53
|
+
setCb: (value) => (pos.y += value),
|
|
54
|
+
radius,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
fixHorizontal(outModes.left ?? outModes.default);
|
|
58
|
+
fixHorizontal(outModes.right ?? outModes.default);
|
|
59
|
+
fixVertical(outModes.top ?? outModes.default);
|
|
60
|
+
fixVertical(outModes.bottom ?? outModes.default);
|
|
61
|
+
if (this._checkOverlap(pos, tryCount)) {
|
|
62
|
+
return this._calcPosition(container, undefined, zIndex, tryCount + 1);
|
|
63
|
+
}
|
|
64
|
+
return pos;
|
|
65
|
+
};
|
|
66
|
+
this._calculateVelocity = () => {
|
|
67
|
+
const baseVelocity = (0, NumberUtils_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
|
|
68
|
+
if (moveOptions.direction === "inside" || moveOptions.direction === "outside") {
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
const rad = (Math.PI / 180) * (0, NumberUtils_1.getRangeValue)(moveOptions.angle.value), radOffset = (Math.PI / 180) * (0, NumberUtils_1.getRangeValue)(moveOptions.angle.offset), range = {
|
|
72
|
+
left: radOffset - rad / 2,
|
|
73
|
+
right: radOffset + rad / 2,
|
|
74
|
+
};
|
|
75
|
+
if (!moveOptions.straight) {
|
|
76
|
+
res.angle += (0, NumberUtils_1.randomInRange)((0, NumberUtils_1.setRangeValue)(range.left, range.right));
|
|
77
|
+
}
|
|
78
|
+
if (moveOptions.random && typeof moveOptions.speed === "number") {
|
|
79
|
+
res.length *= (0, NumberUtils_1.getRandom)();
|
|
80
|
+
}
|
|
81
|
+
return res;
|
|
82
|
+
};
|
|
83
|
+
this._checkOverlap = (pos, tryCount = 0) => {
|
|
84
|
+
const collisionsOptions = this.options.collisions, radius = this.getRadius();
|
|
85
|
+
if (!collisionsOptions.enable) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const overlapOptions = collisionsOptions.overlap;
|
|
89
|
+
if (overlapOptions.enable) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const retries = overlapOptions.retries;
|
|
93
|
+
if (retries >= 0 && tryCount > retries) {
|
|
94
|
+
throw new Error(`${Constants_1.errorPrefix} particle is overlapping and can't be placed`);
|
|
95
|
+
}
|
|
96
|
+
return !!this.container.particles.find((particle) => (0, NumberUtils_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
|
|
97
|
+
};
|
|
98
|
+
this._getRollColor = (color) => {
|
|
99
|
+
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
100
|
+
return color;
|
|
101
|
+
}
|
|
102
|
+
const backFactor = this.roll.horizontal && this.roll.vertical ? 2 : 1, backSum = this.roll.horizontal ? Math.PI / 2 : 0, rolled = Math.floor(((this.roll.angle ?? 0) + backSum) / (Math.PI / backFactor)) % 2;
|
|
103
|
+
if (!rolled) {
|
|
104
|
+
return color;
|
|
105
|
+
}
|
|
106
|
+
if (this.backColor) {
|
|
107
|
+
return this.backColor;
|
|
108
|
+
}
|
|
109
|
+
if (this.roll.alter) {
|
|
110
|
+
return (0, CanvasUtils_1.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);
|
|
111
|
+
}
|
|
112
|
+
return color;
|
|
113
|
+
};
|
|
114
|
+
this._initPosition = (position) => {
|
|
115
|
+
const container = this.container, zIndexValue = (0, NumberUtils_1.getRangeValue)(this.options.zIndex.value);
|
|
116
|
+
this.position = this._calcPosition(container, position, (0, NumberUtils_1.clamp)(zIndexValue, 0, container.zLayers));
|
|
117
|
+
this.initialPosition = this.position.copy();
|
|
118
|
+
const canvasSize = container.canvas.size;
|
|
119
|
+
this.moveCenter = {
|
|
120
|
+
...(0, Utils_1.getPosition)(this.options.move.center, canvasSize),
|
|
121
|
+
radius: this.options.move.center.radius ?? 0,
|
|
122
|
+
mode: this.options.move.center.mode ?? "percent",
|
|
123
|
+
};
|
|
124
|
+
this.direction = (0, NumberUtils_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
|
|
125
|
+
switch (this.options.move.direction) {
|
|
126
|
+
case "inside":
|
|
127
|
+
this.outType = "inside";
|
|
128
|
+
break;
|
|
129
|
+
case "outside":
|
|
130
|
+
this.outType = "outside";
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
this.offset = Vector_1.Vector.origin;
|
|
134
|
+
};
|
|
135
|
+
this._loadShapeData = (shapeOptions, reduceDuplicates) => {
|
|
136
|
+
const shapeData = shapeOptions.options[this.shape];
|
|
137
|
+
if (!shapeData) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return (0, Utils_1.deepExtend)({
|
|
141
|
+
close: shapeOptions.close,
|
|
142
|
+
fill: shapeOptions.fill,
|
|
143
|
+
}, (0, Utils_1.itemFromSingleOrMultiple)(shapeData, this.id, reduceDuplicates));
|
|
144
|
+
};
|
|
26
145
|
this._engine = engine;
|
|
27
146
|
this.init(id, position, overrideOptions, group);
|
|
28
147
|
}
|
|
29
148
|
destroy(override) {
|
|
30
|
-
var _a;
|
|
31
149
|
if (this.unbreakable || this.destroyed) {
|
|
32
150
|
return;
|
|
33
151
|
}
|
|
34
152
|
this.destroyed = true;
|
|
35
153
|
this.bubble.inRange = false;
|
|
36
154
|
this.slow.inRange = false;
|
|
37
|
-
|
|
155
|
+
const container = this.container, pathGenerator = this.pathGenerator;
|
|
156
|
+
for (const [, plugin] of container.plugins) {
|
|
38
157
|
if (plugin.particleDestroyed) {
|
|
39
158
|
plugin.particleDestroyed(this, override);
|
|
40
159
|
}
|
|
41
160
|
}
|
|
42
|
-
for (const updater of
|
|
161
|
+
for (const updater of container.particles.updaters) {
|
|
43
162
|
if (updater.particleDestroyed) {
|
|
44
163
|
updater.particleDestroyed(this, override);
|
|
45
164
|
}
|
|
46
165
|
}
|
|
47
|
-
(
|
|
166
|
+
if (pathGenerator) {
|
|
167
|
+
pathGenerator.reset(this);
|
|
168
|
+
}
|
|
48
169
|
}
|
|
49
170
|
draw(delta) {
|
|
50
|
-
const container = this.container;
|
|
171
|
+
const container = this.container, canvas = container.canvas;
|
|
51
172
|
for (const [, plugin] of container.plugins) {
|
|
52
|
-
|
|
173
|
+
canvas.drawParticlePlugin(plugin, this, delta);
|
|
53
174
|
}
|
|
54
|
-
|
|
175
|
+
canvas.drawParticle(this, delta);
|
|
55
176
|
}
|
|
56
177
|
getFillColor() {
|
|
57
|
-
|
|
58
|
-
return this._getRollColor((_a = this.bubble.color) !== null && _a !== void 0 ? _a : (0, ColorUtils_1.getHslFromAnimation)(this.color));
|
|
178
|
+
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_1.getHslFromAnimation)(this.color));
|
|
59
179
|
}
|
|
60
180
|
getMass() {
|
|
61
181
|
return (this.getRadius() ** 2 * Math.PI) / 2;
|
|
@@ -68,15 +188,12 @@ class Particle {
|
|
|
68
188
|
};
|
|
69
189
|
}
|
|
70
190
|
getRadius() {
|
|
71
|
-
|
|
72
|
-
return (_a = this.bubble.radius) !== null && _a !== void 0 ? _a : this.size.value;
|
|
191
|
+
return this.bubble.radius ?? this.size.value;
|
|
73
192
|
}
|
|
74
193
|
getStrokeColor() {
|
|
75
|
-
|
|
76
|
-
return this._getRollColor((_a = this.bubble.color) !== null && _a !== void 0 ? _a : (0, ColorUtils_1.getHslFromAnimation)(this.strokeColor));
|
|
194
|
+
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_1.getHslFromAnimation)(this.strokeColor));
|
|
77
195
|
}
|
|
78
196
|
init(id, position, overrideOptions, group) {
|
|
79
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
80
197
|
const container = this.container, engine = this._engine;
|
|
81
198
|
this.id = id;
|
|
82
199
|
this.group = group;
|
|
@@ -105,17 +222,21 @@ class Particle {
|
|
|
105
222
|
}
|
|
106
223
|
this.shapeData = this._loadShapeData(shapeOptions, reduceDuplicates);
|
|
107
224
|
particlesOptions.load(overrideOptions);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
225
|
+
const shapeData = this.shapeData;
|
|
226
|
+
if (shapeData) {
|
|
227
|
+
particlesOptions.load(shapeData.particles);
|
|
228
|
+
}
|
|
229
|
+
const interactivity = new Interactivity_1.Interactivity(engine, container);
|
|
230
|
+
interactivity.load(container.actualOptions.interactivity);
|
|
231
|
+
interactivity.load(particlesOptions.interactivity);
|
|
232
|
+
this.interactivity = interactivity;
|
|
233
|
+
this.fill = shapeData?.fill ?? particlesOptions.shape.fill;
|
|
234
|
+
this.close = shapeData?.close ?? particlesOptions.shape.close;
|
|
114
235
|
this.options = particlesOptions;
|
|
115
236
|
const pathOptions = this.options.move.path;
|
|
116
237
|
this.pathDelay = (0, NumberUtils_1.getValue)(pathOptions.delay) * 1000;
|
|
117
238
|
if (pathOptions.generator) {
|
|
118
|
-
this.pathGenerator = this._engine.
|
|
239
|
+
this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);
|
|
119
240
|
if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
|
|
120
241
|
this.pathGenerator.init(container);
|
|
121
242
|
}
|
|
@@ -140,15 +261,15 @@ class Particle {
|
|
|
140
261
|
this.sides = 24;
|
|
141
262
|
let drawer = container.drawers.get(this.shape);
|
|
142
263
|
if (!drawer) {
|
|
143
|
-
drawer = this._engine.
|
|
264
|
+
drawer = this._engine.getShapeDrawer(this.shape);
|
|
144
265
|
if (drawer) {
|
|
145
266
|
container.drawers.set(this.shape, drawer);
|
|
146
267
|
}
|
|
147
268
|
}
|
|
148
|
-
if (drawer
|
|
149
|
-
drawer
|
|
269
|
+
if (drawer && drawer.loadShape) {
|
|
270
|
+
drawer.loadShape(this);
|
|
150
271
|
}
|
|
151
|
-
const sideCountFunc = drawer
|
|
272
|
+
const sideCountFunc = drawer?.getSidesCount;
|
|
152
273
|
if (sideCountFunc) {
|
|
153
274
|
this.sides = sideCountFunc(this);
|
|
154
275
|
}
|
|
@@ -158,156 +279,28 @@ class Particle {
|
|
|
158
279
|
updater.init(this);
|
|
159
280
|
}
|
|
160
281
|
for (const mover of container.particles.movers) {
|
|
161
|
-
|
|
282
|
+
mover.init && mover.init(this);
|
|
162
283
|
}
|
|
163
|
-
if (drawer
|
|
284
|
+
if (drawer && drawer.particleInit) {
|
|
164
285
|
drawer.particleInit(container, this);
|
|
165
286
|
}
|
|
166
287
|
for (const [, plugin] of container.plugins) {
|
|
167
|
-
|
|
288
|
+
plugin.particleCreated && plugin.particleCreated(this);
|
|
168
289
|
}
|
|
169
290
|
}
|
|
170
291
|
isInsideCanvas() {
|
|
171
|
-
const radius = this.getRadius(), canvasSize = this.container.canvas.size;
|
|
172
|
-
return (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
292
|
+
const radius = this.getRadius(), canvasSize = this.container.canvas.size, position = this.position;
|
|
293
|
+
return (position.x >= -radius &&
|
|
294
|
+
position.y >= -radius &&
|
|
295
|
+
position.y <= canvasSize.height + radius &&
|
|
296
|
+
position.x <= canvasSize.width + radius);
|
|
176
297
|
}
|
|
177
298
|
isVisible() {
|
|
178
299
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
179
300
|
}
|
|
180
301
|
reset() {
|
|
181
|
-
var _a;
|
|
182
302
|
for (const updater of this.container.particles.updaters) {
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
_calcPosition(container, position, zIndex, tryCount = 0) {
|
|
187
|
-
var _a, _b, _c, _d;
|
|
188
|
-
for (const [, plugin] of container.plugins) {
|
|
189
|
-
const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
|
190
|
-
if (pluginPos !== undefined) {
|
|
191
|
-
return Vector3d_1.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const canvasSize = container.canvas.size, exactPosition = (0, NumberUtils_1.calcExactPositionOrRandomFromSize)({
|
|
195
|
-
size: canvasSize,
|
|
196
|
-
position: position,
|
|
197
|
-
}), pos = Vector3d_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
|
|
198
|
-
fixOutMode({
|
|
199
|
-
outMode,
|
|
200
|
-
checkModes: ["bounce", "bounce-horizontal"],
|
|
201
|
-
coord: pos.x,
|
|
202
|
-
maxCoord: container.canvas.size.width,
|
|
203
|
-
setCb: (value) => (pos.x += value),
|
|
204
|
-
radius,
|
|
205
|
-
});
|
|
206
|
-
}, fixVertical = (outMode) => {
|
|
207
|
-
fixOutMode({
|
|
208
|
-
outMode,
|
|
209
|
-
checkModes: ["bounce", "bounce-vertical"],
|
|
210
|
-
coord: pos.y,
|
|
211
|
-
maxCoord: container.canvas.size.height,
|
|
212
|
-
setCb: (value) => (pos.y += value),
|
|
213
|
-
radius,
|
|
214
|
-
});
|
|
215
|
-
};
|
|
216
|
-
fixHorizontal((_a = outModes.left) !== null && _a !== void 0 ? _a : outModes.default);
|
|
217
|
-
fixHorizontal((_b = outModes.right) !== null && _b !== void 0 ? _b : outModes.default);
|
|
218
|
-
fixVertical((_c = outModes.top) !== null && _c !== void 0 ? _c : outModes.default);
|
|
219
|
-
fixVertical((_d = outModes.bottom) !== null && _d !== void 0 ? _d : outModes.default);
|
|
220
|
-
if (this._checkOverlap(pos, tryCount)) {
|
|
221
|
-
return this._calcPosition(container, undefined, zIndex, tryCount + 1);
|
|
222
|
-
}
|
|
223
|
-
return pos;
|
|
224
|
-
}
|
|
225
|
-
_calculateVelocity() {
|
|
226
|
-
const baseVelocity = (0, NumberUtils_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
|
|
227
|
-
if (moveOptions.direction === "inside" || moveOptions.direction === "outside") {
|
|
228
|
-
return res;
|
|
229
|
-
}
|
|
230
|
-
const rad = (Math.PI / 180) * (0, NumberUtils_1.getRangeValue)(moveOptions.angle.value), radOffset = (Math.PI / 180) * (0, NumberUtils_1.getRangeValue)(moveOptions.angle.offset), range = {
|
|
231
|
-
left: radOffset - rad / 2,
|
|
232
|
-
right: radOffset + rad / 2,
|
|
233
|
-
};
|
|
234
|
-
if (!moveOptions.straight) {
|
|
235
|
-
res.angle += (0, NumberUtils_1.randomInRange)((0, NumberUtils_1.setRangeValue)(range.left, range.right));
|
|
236
|
-
}
|
|
237
|
-
if (moveOptions.random && typeof moveOptions.speed === "number") {
|
|
238
|
-
res.length *= (0, NumberUtils_1.getRandom)();
|
|
239
|
-
}
|
|
240
|
-
return res;
|
|
241
|
-
}
|
|
242
|
-
_checkOverlap(pos, tryCount = 0) {
|
|
243
|
-
const collisionsOptions = this.options.collisions, radius = this.getRadius();
|
|
244
|
-
if (!collisionsOptions.enable) {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
const overlapOptions = collisionsOptions.overlap;
|
|
248
|
-
if (overlapOptions.enable) {
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
const retries = overlapOptions.retries;
|
|
252
|
-
if (retries >= 0 && tryCount > retries) {
|
|
253
|
-
throw new Error("Particle is overlapping and can't be placed");
|
|
254
|
-
}
|
|
255
|
-
let overlaps = false;
|
|
256
|
-
for (const particle of this.container.particles.array) {
|
|
257
|
-
if ((0, NumberUtils_1.getDistance)(pos, particle.position) < radius + particle.getRadius()) {
|
|
258
|
-
overlaps = true;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return overlaps;
|
|
263
|
-
}
|
|
264
|
-
_getRollColor(color) {
|
|
265
|
-
var _a;
|
|
266
|
-
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
267
|
-
return color;
|
|
268
|
-
}
|
|
269
|
-
const backFactor = this.roll.horizontal && this.roll.vertical ? 2 : 1, backSum = this.roll.horizontal ? Math.PI / 2 : 0, rolled = Math.floor((((_a = this.roll.angle) !== null && _a !== void 0 ? _a : 0) + backSum) / (Math.PI / backFactor)) % 2;
|
|
270
|
-
if (!rolled) {
|
|
271
|
-
return color;
|
|
272
|
-
}
|
|
273
|
-
if (this.backColor) {
|
|
274
|
-
return this.backColor;
|
|
275
|
-
}
|
|
276
|
-
if (this.roll.alter) {
|
|
277
|
-
return (0, CanvasUtils_1.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);
|
|
278
|
-
}
|
|
279
|
-
return color;
|
|
280
|
-
}
|
|
281
|
-
_initPosition(position) {
|
|
282
|
-
var _a, _b;
|
|
283
|
-
const container = this.container, zIndexValue = (0, NumberUtils_1.getRangeValue)(this.options.zIndex.value);
|
|
284
|
-
this.position = this._calcPosition(container, position, (0, NumberUtils_1.clamp)(zIndexValue, 0, container.zLayers));
|
|
285
|
-
this.initialPosition = this.position.copy();
|
|
286
|
-
const canvasSize = container.canvas.size, moveCenter = Object.assign({}, this.options.move.center), isCenterPercent = moveCenter.mode === "percent";
|
|
287
|
-
this.moveCenter = {
|
|
288
|
-
x: moveCenter.x * (isCenterPercent ? canvasSize.width / 100 : 1),
|
|
289
|
-
y: moveCenter.y * (isCenterPercent ? canvasSize.height / 100 : 1),
|
|
290
|
-
radius: (_a = this.options.move.center.radius) !== null && _a !== void 0 ? _a : 0,
|
|
291
|
-
mode: (_b = this.options.move.center.mode) !== null && _b !== void 0 ? _b : "percent",
|
|
292
|
-
};
|
|
293
|
-
this.direction = (0, NumberUtils_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
|
|
294
|
-
switch (this.options.move.direction) {
|
|
295
|
-
case "inside":
|
|
296
|
-
this.outType = "inside";
|
|
297
|
-
break;
|
|
298
|
-
case "outside":
|
|
299
|
-
this.outType = "outside";
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
302
|
-
this.offset = Vector_1.Vector.origin;
|
|
303
|
-
}
|
|
304
|
-
_loadShapeData(shapeOptions, reduceDuplicates) {
|
|
305
|
-
const shapeData = shapeOptions.options[this.shape];
|
|
306
|
-
if (shapeData) {
|
|
307
|
-
return (0, Utils_1.deepExtend)({
|
|
308
|
-
close: shapeOptions.close,
|
|
309
|
-
fill: shapeOptions.fill,
|
|
310
|
-
}, (0, Utils_1.itemFromSingleOrMultiple)(shapeData, this.id, reduceDuplicates));
|
|
303
|
+
updater.reset && updater.reset(this);
|
|
311
304
|
}
|
|
312
305
|
}
|
|
313
306
|
}
|