@tsparticles/engine 4.0.0-alpha.8 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/155.min.js +1 -0
- package/README.md +41 -28
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +134 -101
- package/browser/Core/Engine.js +29 -162
- package/browser/Core/Particle.js +197 -183
- package/browser/Core/ParticlesManager.js +363 -0
- package/browser/Core/RenderManager.js +303 -0
- package/browser/Core/Retina.js +6 -6
- package/browser/Core/Utils/Constants.js +2 -2
- package/browser/Core/Utils/EventListeners.js +67 -63
- package/browser/Core/Utils/PluginManager.js +145 -0
- package/browser/Core/Utils/Ranges.js +29 -10
- package/browser/Core/Utils/SpatialHashGrid.js +102 -0
- package/browser/Core/Utils/Vectors.js +17 -18
- package/browser/Options/Classes/AnimatableColor.js +1 -0
- package/browser/Options/Classes/AnimationOptions.js +8 -0
- package/browser/Options/Classes/Background/Background.js +6 -0
- package/browser/Options/Classes/ColorAnimation.js +12 -1
- package/browser/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/browser/Options/Classes/HslAnimation.js +4 -5
- package/browser/Options/Classes/Options.js +67 -8
- package/browser/Options/Classes/OptionsColor.js +1 -0
- package/browser/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/browser/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/browser/Options/Classes/Particles/Fill.js +28 -0
- package/browser/Options/Classes/Particles/Move/Move.js +17 -3
- package/browser/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/browser/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/browser/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/browser/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/browser/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/browser/Options/Classes/Particles/Move/Spin.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/browser/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/browser/Options/Classes/Particles/Size/Size.js +1 -0
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/browser/Options/Classes/Particles/Stroke.js +3 -0
- package/browser/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/browser/Options/Classes/ResizeEvent.js +2 -0
- package/browser/Options/Classes/ValueWithRandom.js +3 -4
- package/browser/Utils/CanvasUtils.js +44 -51
- package/browser/Utils/ColorUtils.js +51 -40
- package/browser/Utils/EventDispatcher.js +1 -0
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/MathUtils.js +12 -7
- package/browser/Utils/OptionsUtils.js +2 -2
- package/browser/Utils/Utils.js +109 -31
- package/browser/exports.js +1 -2
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +134 -101
- package/cjs/Core/Engine.js +29 -162
- package/cjs/Core/Particle.js +197 -183
- package/cjs/Core/ParticlesManager.js +363 -0
- package/cjs/Core/RenderManager.js +303 -0
- package/cjs/Core/Retina.js +6 -6
- package/cjs/Core/Utils/Constants.js +2 -2
- package/cjs/Core/Utils/EventListeners.js +67 -63
- package/cjs/Core/Utils/PluginManager.js +145 -0
- package/cjs/Core/Utils/Ranges.js +29 -10
- package/cjs/Core/Utils/SpatialHashGrid.js +102 -0
- package/cjs/Core/Utils/Vectors.js +17 -18
- package/cjs/Options/Classes/AnimatableColor.js +1 -0
- package/cjs/Options/Classes/AnimationOptions.js +8 -0
- package/cjs/Options/Classes/Background/Background.js +6 -0
- package/cjs/Options/Classes/ColorAnimation.js +12 -1
- package/cjs/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/cjs/Options/Classes/HslAnimation.js +4 -5
- package/cjs/Options/Classes/Options.js +67 -8
- package/cjs/Options/Classes/OptionsColor.js +1 -0
- package/cjs/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/cjs/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/cjs/Options/Classes/Particles/Fill.js +28 -0
- package/cjs/Options/Classes/Particles/Move/Move.js +17 -3
- package/cjs/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/cjs/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/cjs/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/cjs/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/cjs/Options/Classes/Particles/Move/Spin.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/cjs/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/cjs/Options/Classes/Particles/Size/Size.js +1 -0
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/cjs/Options/Classes/Particles/Stroke.js +3 -0
- package/cjs/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/cjs/Options/Classes/ResizeEvent.js +2 -0
- package/cjs/Options/Classes/ValueWithRandom.js +3 -4
- package/cjs/Utils/CanvasUtils.js +44 -51
- package/cjs/Utils/ColorUtils.js +51 -40
- package/cjs/Utils/EventDispatcher.js +1 -0
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/MathUtils.js +12 -7
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/cjs/Utils/Utils.js +109 -31
- package/cjs/exports.js +1 -2
- package/dist_browser_Core_Container_js.js +30 -20
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +134 -101
- package/esm/Core/Engine.js +29 -162
- package/esm/Core/Particle.js +197 -183
- package/esm/Core/ParticlesManager.js +363 -0
- package/esm/Core/RenderManager.js +303 -0
- package/esm/Core/Retina.js +6 -6
- package/esm/Core/Utils/Constants.js +2 -2
- package/esm/Core/Utils/EventListeners.js +67 -63
- package/esm/Core/Utils/PluginManager.js +145 -0
- package/esm/Core/Utils/Ranges.js +29 -10
- package/esm/Core/Utils/SpatialHashGrid.js +102 -0
- package/esm/Core/Utils/Vectors.js +17 -18
- package/esm/Options/Classes/AnimatableColor.js +1 -0
- package/esm/Options/Classes/AnimationOptions.js +8 -0
- package/esm/Options/Classes/Background/Background.js +6 -0
- package/esm/Options/Classes/ColorAnimation.js +12 -1
- package/esm/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/esm/Options/Classes/HslAnimation.js +4 -5
- package/esm/Options/Classes/Options.js +67 -8
- package/esm/Options/Classes/OptionsColor.js +1 -0
- package/esm/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/esm/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/esm/Options/Classes/Particles/Fill.js +28 -0
- package/esm/Options/Classes/Particles/Move/Move.js +17 -3
- package/esm/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/esm/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/esm/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/esm/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/esm/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/esm/Options/Classes/Particles/Move/Spin.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +29 -9
- package/esm/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/esm/Options/Classes/Particles/Size/Size.js +1 -0
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/esm/Options/Classes/Particles/Stroke.js +3 -0
- package/esm/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/esm/Options/Classes/ResizeEvent.js +2 -0
- package/esm/Options/Classes/ValueWithRandom.js +3 -4
- package/esm/Utils/CanvasUtils.js +44 -51
- package/esm/Utils/ColorUtils.js +51 -40
- package/esm/Utils/EventDispatcher.js +1 -0
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/MathUtils.js +12 -7
- package/esm/Utils/OptionsUtils.js +2 -2
- package/esm/Utils/Utils.js +109 -31
- package/esm/exports.js +1 -2
- package/package.json +1 -1
- package/report.html +84 -29
- package/scripts/install.js +4 -20
- package/tsparticles.engine.js +98 -86
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/CanvasManager.d.ts +39 -0
- package/types/Core/Container.d.ts +29 -14
- package/types/Core/Engine.d.ts +2 -61
- package/types/Core/Interfaces/IColorManager.d.ts +0 -1
- package/types/Core/Interfaces/IContainerPlugin.d.ts +10 -8
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
- package/types/Core/Interfaces/IPalette.d.ts +7 -0
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
- package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
- package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -1
- package/types/Core/Interfaces/IShapeDrawer.d.ts +0 -1
- package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
- package/types/Core/Particle.d.ts +7 -11
- package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +15 -14
- package/types/Core/RenderManager.d.ts +49 -0
- package/types/Core/Retina.d.ts +0 -2
- package/types/Core/Utils/Constants.d.ts +2 -2
- package/types/Core/Utils/PluginManager.d.ts +62 -0
- package/types/Core/Utils/Ranges.d.ts +4 -1
- package/types/Core/Utils/SpatialHashGrid.d.ts +25 -0
- package/types/Core/Utils/Vectors.d.ts +8 -10
- package/types/Options/Classes/ColorAnimation.d.ts +3 -1
- package/types/Options/Classes/HslAnimation.d.ts +3 -4
- package/types/Options/Classes/Options.d.ts +5 -3
- package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
- package/types/Options/Classes/Particles/Fill.d.ts +12 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +5 -5
- package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
- package/types/Options/Classes/ValueWithRandom.d.ts +0 -1
- package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
- package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
- package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
- package/types/Types/CanvasContextType.d.ts +1 -0
- package/types/Types/EngineInitializers.d.ts +6 -3
- package/types/Utils/CanvasUtils.d.ts +13 -16
- package/types/Utils/ColorUtils.d.ts +11 -10
- package/types/Utils/LogUtils.d.ts +1 -0
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/Utils/OptionsUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +8 -1
- package/types/export-types.d.ts +7 -7
- package/types/exports.d.ts +1 -2
- package/umd/Core/CanvasManager.js +317 -0
- package/umd/Core/Container.js +134 -101
- package/umd/Core/Engine.js +28 -161
- package/umd/Core/Particle.js +198 -184
- package/umd/Core/{Particles.js → ParticlesManager.js} +186 -167
- package/umd/Core/RenderManager.js +317 -0
- package/umd/Core/Retina.js +6 -6
- package/umd/Core/Utils/Constants.js +3 -3
- package/umd/Core/Utils/EventListeners.js +67 -63
- package/umd/Core/Utils/PluginManager.js +159 -0
- package/umd/Core/Utils/Ranges.js +28 -9
- package/umd/Core/Utils/SpatialHashGrid.js +116 -0
- package/umd/Core/Utils/Vectors.js +17 -18
- package/umd/Options/Classes/AnimatableColor.js +1 -0
- package/umd/Options/Classes/AnimationOptions.js +8 -0
- package/umd/Options/Classes/Background/Background.js +6 -0
- package/umd/Options/Classes/ColorAnimation.js +12 -1
- package/umd/Options/Classes/FullScreen/FullScreen.js +2 -0
- package/umd/Options/Classes/HslAnimation.js +5 -6
- package/umd/Options/Classes/Options.js +67 -8
- package/umd/Options/Classes/OptionsColor.js +1 -0
- package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
- package/umd/Options/Classes/Particles/Effect/Effect.js +3 -4
- package/umd/Options/Classes/Particles/Fill.js +42 -0
- package/umd/Options/Classes/Particles/Move/Move.js +18 -4
- package/umd/Options/Classes/Particles/Move/MoveAngle.js +2 -0
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +4 -0
- package/umd/Options/Classes/Particles/Move/MoveGravity.js +4 -0
- package/umd/Options/Classes/Particles/Move/OutModes.js +5 -0
- package/umd/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
- package/umd/Options/Classes/Particles/Move/Spin.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
- package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -0
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
- package/umd/Options/Classes/Particles/ParticlesOptions.js +30 -10
- package/umd/Options/Classes/Particles/Shape/Shape.js +3 -4
- package/umd/Options/Classes/Particles/Size/Size.js +1 -0
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
- package/umd/Options/Classes/Particles/Stroke.js +3 -0
- package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
- package/umd/Options/Classes/ResizeEvent.js +2 -0
- package/umd/Options/Classes/ValueWithRandom.js +3 -4
- package/umd/Utils/CanvasUtils.js +44 -53
- package/umd/Utils/ColorUtils.js +51 -39
- package/umd/Utils/EventDispatcher.js +1 -0
- package/umd/Utils/LogUtils.js +1 -0
- package/umd/Utils/MathUtils.js +14 -7
- package/umd/Utils/OptionsUtils.js +2 -2
- package/umd/Utils/Utils.js +111 -32
- package/umd/exports.js +2 -3
- package/794.min.js +0 -2
- package/794.min.js.LICENSE.txt +0 -1
- package/browser/Core/Canvas.js +0 -469
- package/browser/Core/Particles.js +0 -344
- package/browser/Core/Utils/Point.js +0 -6
- package/browser/Core/Utils/QuadTree.js +0 -59
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/cjs/Core/Canvas.js +0 -469
- package/cjs/Core/Particles.js +0 -344
- package/cjs/Core/Utils/Point.js +0 -6
- package/cjs/Core/Utils/QuadTree.js +0 -59
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/esm/Core/Canvas.js +0 -469
- package/esm/Core/Particles.js +0 -344
- package/esm/Core/Utils/Point.js +0 -6
- package/esm/Core/Utils/QuadTree.js +0 -59
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -33
- package/tsparticles.engine.min.js.LICENSE.txt +0 -1
- package/types/Core/Canvas.d.ts +0 -55
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -10
- package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
- package/types/Core/Utils/Point.d.ts +0 -7
- package/types/Core/Utils/QuadTree.d.ts +0 -18
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
- package/umd/Core/Canvas.js +0 -483
- package/umd/Core/Utils/Point.js +0 -20
- package/umd/Core/Utils/QuadTree.js +0 -73
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -47
- /package/browser/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/browser/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/browser/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/cjs/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/cjs/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/cjs/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/esm/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/esm/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/esm/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
- /package/umd/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
- /package/umd/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
- /package/umd/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
package/esm/Utils/CanvasUtils.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
3
|
-
export function drawLine(context, begin, end) {
|
|
4
|
-
context.beginPath();
|
|
5
|
-
context.moveTo(begin.x, begin.y);
|
|
6
|
-
context.lineTo(end.x, end.y);
|
|
7
|
-
context.closePath();
|
|
8
|
-
}
|
|
1
|
+
import { defaultZoom, minStrokeWidth, originPoint } from "../Core/Utils/Constants.js";
|
|
9
2
|
export function paintBase(context, dimension, baseColor) {
|
|
10
3
|
context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
|
|
11
4
|
context.fillRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
|
|
@@ -14,20 +7,24 @@ export function paintImage(context, dimension, image, opacity) {
|
|
|
14
7
|
if (!image) {
|
|
15
8
|
return;
|
|
16
9
|
}
|
|
10
|
+
const prevAlpha = context.globalAlpha;
|
|
17
11
|
context.globalAlpha = opacity;
|
|
18
12
|
context.drawImage(image, originPoint.x, originPoint.y, dimension.width, dimension.height);
|
|
19
|
-
context.globalAlpha =
|
|
13
|
+
context.globalAlpha = prevAlpha;
|
|
20
14
|
}
|
|
21
15
|
export function clear(context, dimension) {
|
|
22
16
|
context.clearRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
|
|
23
17
|
}
|
|
24
18
|
export function drawParticle(data) {
|
|
25
|
-
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(), transformData = particle.getTransformData(transform)
|
|
19
|
+
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
|
|
20
|
+
x: pos.x,
|
|
21
|
+
y: pos.y,
|
|
22
|
+
};
|
|
26
23
|
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
|
27
24
|
if (colorStyles.fill) {
|
|
28
25
|
context.fillStyle = colorStyles.fill;
|
|
29
26
|
}
|
|
30
|
-
const strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
27
|
+
const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
31
28
|
context.lineWidth = strokeWidth;
|
|
32
29
|
if (colorStyles.stroke) {
|
|
33
30
|
context.strokeStyle = colorStyles.stroke;
|
|
@@ -36,49 +33,54 @@ export function drawParticle(data) {
|
|
|
36
33
|
context,
|
|
37
34
|
particle,
|
|
38
35
|
radius,
|
|
36
|
+
drawRadius: radius * drawScale,
|
|
39
37
|
opacity,
|
|
40
38
|
delta,
|
|
41
39
|
pixelRatio: container.retina.pixelRatio,
|
|
42
|
-
fill:
|
|
43
|
-
stroke: strokeWidth > minStrokeWidth
|
|
40
|
+
fill: fillEnabled,
|
|
41
|
+
stroke: strokeWidth > minStrokeWidth,
|
|
44
42
|
transformData,
|
|
43
|
+
position: { ...pos },
|
|
44
|
+
drawPosition,
|
|
45
|
+
drawScale,
|
|
45
46
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
for (const plugin of container.plugins) {
|
|
48
|
+
plugin.drawParticleTransform?.(drawData);
|
|
49
|
+
}
|
|
50
|
+
const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
|
|
51
|
+
drawBeforeEffect(effect, drawData);
|
|
52
|
+
drawShapeBeforeDraw(shape, drawData);
|
|
53
|
+
drawShape(shape, drawData);
|
|
54
|
+
drawShapeAfterDraw(shape, drawData);
|
|
55
|
+
drawAfterEffect(effect, drawData);
|
|
51
56
|
context.resetTransform();
|
|
52
57
|
}
|
|
53
|
-
export function drawAfterEffect(
|
|
58
|
+
export function drawAfterEffect(drawer, data) {
|
|
59
|
+
if (!drawer?.drawAfter) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
54
62
|
const { particle } = data;
|
|
55
63
|
if (!particle.effect) {
|
|
56
64
|
return;
|
|
57
65
|
}
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
drawer.drawAfter(data);
|
|
67
|
+
}
|
|
68
|
+
export function drawBeforeEffect(drawer, data) {
|
|
69
|
+
if (!drawer?.drawBefore) {
|
|
60
70
|
return;
|
|
61
71
|
}
|
|
62
|
-
drawFunc(data);
|
|
63
|
-
}
|
|
64
|
-
export function drawBeforeEffect(container, data) {
|
|
65
72
|
const { particle } = data;
|
|
66
73
|
if (!particle.effect) {
|
|
67
74
|
return;
|
|
68
75
|
}
|
|
69
|
-
const drawer = container.effectDrawers.get(particle.effect);
|
|
70
|
-
if (!drawer?.drawBefore) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
76
|
drawer.drawBefore(data);
|
|
74
77
|
}
|
|
75
|
-
export function drawShape(
|
|
76
|
-
|
|
77
|
-
if (!particle.shape) {
|
|
78
|
+
export function drawShape(drawer, data) {
|
|
79
|
+
if (!drawer) {
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
+
const { context, fill, particle, stroke } = data;
|
|
83
|
+
if (!particle.shape) {
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
86
|
context.beginPath();
|
|
@@ -89,30 +91,28 @@ export function drawShape(container, data) {
|
|
|
89
91
|
if (stroke) {
|
|
90
92
|
context.stroke();
|
|
91
93
|
}
|
|
92
|
-
if (
|
|
94
|
+
if (fill) {
|
|
93
95
|
context.fill();
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
|
-
export function drawShapeAfterDraw(
|
|
97
|
-
const { particle } = data;
|
|
98
|
-
if (!particle.shape) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const drawer = container.shapeDrawers.get(particle.shape);
|
|
98
|
+
export function drawShapeAfterDraw(drawer, data) {
|
|
102
99
|
if (!drawer?.afterDraw) {
|
|
103
100
|
return;
|
|
104
101
|
}
|
|
105
|
-
drawer.afterDraw(data);
|
|
106
|
-
}
|
|
107
|
-
export function drawShapeBeforeDraw(container, data) {
|
|
108
102
|
const { particle } = data;
|
|
109
103
|
if (!particle.shape) {
|
|
110
104
|
return;
|
|
111
105
|
}
|
|
112
|
-
|
|
106
|
+
drawer.afterDraw(data);
|
|
107
|
+
}
|
|
108
|
+
export function drawShapeBeforeDraw(drawer, data) {
|
|
113
109
|
if (!drawer?.beforeDraw) {
|
|
114
110
|
return;
|
|
115
111
|
}
|
|
112
|
+
const { particle } = data;
|
|
113
|
+
if (!particle.shape) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
116
|
drawer.beforeDraw(data);
|
|
117
117
|
}
|
|
118
118
|
export function drawParticlePlugin(context, plugin, particle, delta) {
|
|
@@ -121,10 +121,3 @@ export function drawParticlePlugin(context, plugin, particle, delta) {
|
|
|
121
121
|
}
|
|
122
122
|
plugin.drawParticle(context, particle, delta);
|
|
123
123
|
}
|
|
124
|
-
export function alterHsl(color, type, value) {
|
|
125
|
-
return {
|
|
126
|
-
h: color.h,
|
|
127
|
-
s: color.s,
|
|
128
|
-
l: color.l + (type === AlterType.darken ? -lFactor : lFactor) * value,
|
|
129
|
-
};
|
|
130
|
-
}
|
package/esm/Utils/ColorUtils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { clamp, getRandom, getRandomInRange,
|
|
2
|
-
import { decayOffset, defaultLoops, defaultOpacity, defaultRgbMin, defaultTime, defaultVelocity, double, hMax, hMin, hPhase, half, identity, lMax, lMin, midColorValue, millisecondsToSeconds, percentDenominator, phaseNumerator, randomColorValue, rgbMax, sMax, sMin, sNormalizedOffset, sextuple, triple, } from "../Core/Utils/Constants.js";
|
|
1
|
+
import { clamp, getRandom, getRandomInRange, getRangeValue, mix, randomInRangeValue, setRangeValue, } from "./MathUtils.js";
|
|
2
|
+
import { decayOffset, defaultLoops, defaultOpacity, defaultRgbMin, defaultTime, defaultVelocity, double, hMax, hMin, hPhase, half, identity, lFactor, lMax, lMin, midColorValue, millisecondsToSeconds, percentDenominator, phaseNumerator, randomColorValue, rgbMax, sMax, sMin, sNormalizedOffset, sextuple, triple, } from "../Core/Utils/Constants.js";
|
|
3
3
|
import { isArray, isString } from "./TypeUtils.js";
|
|
4
|
+
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
4
5
|
import { AnimationStatus } from "../Enums/AnimationStatus.js";
|
|
5
6
|
import { itemFromArray } from "./Utils.js";
|
|
6
7
|
const styleCache = new Map(), maxCacheSize = 1000, firstIndex = 0, rgbFixedPrecision = 2, hslFixedPrecision = 2;
|
|
@@ -16,35 +17,35 @@ function getCachedStyle(key, generator) {
|
|
|
16
17
|
}
|
|
17
18
|
return cached;
|
|
18
19
|
}
|
|
19
|
-
function stringToRgba(
|
|
20
|
+
function stringToRgba(pluginManager, input) {
|
|
20
21
|
if (!input) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
|
-
for (const manager of
|
|
24
|
+
for (const manager of pluginManager.colorManagers.values()) {
|
|
24
25
|
if (manager.accepts(input)) {
|
|
25
26
|
return manager.parseString(input);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
return undefined;
|
|
29
30
|
}
|
|
30
|
-
export function rangeColorToRgb(
|
|
31
|
+
export function rangeColorToRgb(pluginManager, input, index, useIndex = true) {
|
|
31
32
|
if (!input) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
const color = isString(input) ? { value: input } : input;
|
|
35
36
|
if (isString(color.value)) {
|
|
36
|
-
return colorToRgb(
|
|
37
|
+
return colorToRgb(pluginManager, color.value, index, useIndex);
|
|
37
38
|
}
|
|
38
39
|
if (isArray(color.value)) {
|
|
39
40
|
const value = itemFromArray(color.value, index, useIndex);
|
|
40
41
|
if (!value) {
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
|
-
return rangeColorToRgb(
|
|
44
|
+
return rangeColorToRgb(pluginManager, {
|
|
44
45
|
value,
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
|
-
for (const manager of
|
|
48
|
+
for (const manager of pluginManager.colorManagers.values()) {
|
|
48
49
|
const res = manager.handleRangeColor(color);
|
|
49
50
|
if (res) {
|
|
50
51
|
return res;
|
|
@@ -52,24 +53,24 @@ export function rangeColorToRgb(engine, input, index, useIndex = true) {
|
|
|
52
53
|
}
|
|
53
54
|
return undefined;
|
|
54
55
|
}
|
|
55
|
-
export function colorToRgb(
|
|
56
|
+
export function colorToRgb(pluginManager, input, index, useIndex = true) {
|
|
56
57
|
if (!input) {
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
60
|
const color = isString(input) ? { value: input } : input;
|
|
60
61
|
if (isString(color.value)) {
|
|
61
|
-
return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(
|
|
62
|
+
return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(pluginManager, color.value);
|
|
62
63
|
}
|
|
63
64
|
if (isArray(color.value)) {
|
|
64
65
|
const value = itemFromArray(color.value, index, useIndex);
|
|
65
66
|
if (!value) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
|
-
return colorToRgb(
|
|
69
|
+
return colorToRgb(pluginManager, {
|
|
69
70
|
value,
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
|
-
for (const manager of
|
|
73
|
+
for (const manager of pluginManager.colorManagers.values()) {
|
|
73
74
|
const res = manager.handleColor(color);
|
|
74
75
|
if (res) {
|
|
75
76
|
return res;
|
|
@@ -77,12 +78,12 @@ export function colorToRgb(engine, input, index, useIndex = true) {
|
|
|
77
78
|
}
|
|
78
79
|
return undefined;
|
|
79
80
|
}
|
|
80
|
-
export function colorToHsl(
|
|
81
|
-
const rgb = colorToRgb(
|
|
81
|
+
export function colorToHsl(pluginManager, color, index, useIndex = true) {
|
|
82
|
+
const rgb = colorToRgb(pluginManager, color, index, useIndex);
|
|
82
83
|
return rgb ? rgbToHsl(rgb) : undefined;
|
|
83
84
|
}
|
|
84
|
-
export function rangeColorToHsl(
|
|
85
|
-
const rgb = rangeColorToRgb(
|
|
85
|
+
export function rangeColorToHsl(pluginManager, color, index, useIndex = true) {
|
|
86
|
+
const rgb = rangeColorToRgb(pluginManager, color, index, useIndex);
|
|
86
87
|
return rgb ? rgbToHsl(rgb) : undefined;
|
|
87
88
|
}
|
|
88
89
|
export function rgbToHsl(color) {
|
|
@@ -114,11 +115,11 @@ export function rgbToHsl(color) {
|
|
|
114
115
|
}
|
|
115
116
|
return res;
|
|
116
117
|
}
|
|
117
|
-
export function stringToAlpha(
|
|
118
|
-
return stringToRgba(
|
|
118
|
+
export function stringToAlpha(pluginManager, input) {
|
|
119
|
+
return stringToRgba(pluginManager, input)?.a;
|
|
119
120
|
}
|
|
120
|
-
export function stringToRgb(
|
|
121
|
-
return stringToRgba(
|
|
121
|
+
export function stringToRgb(pluginManager, input) {
|
|
122
|
+
return stringToRgba(pluginManager, input);
|
|
122
123
|
}
|
|
123
124
|
export function hslToRgb(hsl) {
|
|
124
125
|
const h = ((hsl.h % hMax) + hMax) % hMax, s = Math.max(sMin, Math.min(sMax, hsl.s)), l = Math.max(lMin, Math.min(lMax, hsl.l)), hNormalized = h / hMax, sNormalized = s / sMax, lNormalized = l / lMax;
|
|
@@ -189,10 +190,10 @@ function getSdrStyleFromHsl(color, opacity) {
|
|
|
189
190
|
}
|
|
190
191
|
export function colorMix(color1, color2, size1, size2) {
|
|
191
192
|
let rgb1 = color1, rgb2 = color2;
|
|
192
|
-
if (!
|
|
193
|
+
if (!("r" in rgb1)) {
|
|
193
194
|
rgb1 = hslToRgb(color1);
|
|
194
195
|
}
|
|
195
|
-
if (!
|
|
196
|
+
if (!("r" in rgb2)) {
|
|
196
197
|
rgb2 = hslToRgb(color2);
|
|
197
198
|
}
|
|
198
199
|
return {
|
|
@@ -222,11 +223,11 @@ export function getLinkColor(p1, p2, linkColor) {
|
|
|
222
223
|
}
|
|
223
224
|
return undefined;
|
|
224
225
|
}
|
|
225
|
-
export function getLinkRandomColor(
|
|
226
|
+
export function getLinkRandomColor(pluginManager, optColor, blink, consent) {
|
|
226
227
|
const color = isString(optColor) ? optColor : optColor.value;
|
|
227
228
|
if (color === randomColorValue) {
|
|
228
229
|
if (consent) {
|
|
229
|
-
return rangeColorToRgb(
|
|
230
|
+
return rangeColorToRgb(pluginManager, {
|
|
230
231
|
value: color,
|
|
231
232
|
});
|
|
232
233
|
}
|
|
@@ -239,33 +240,39 @@ export function getLinkRandomColor(engine, optColor, blink, consent) {
|
|
|
239
240
|
return midColorValue;
|
|
240
241
|
}
|
|
241
242
|
else {
|
|
242
|
-
return rangeColorToRgb(
|
|
243
|
+
return rangeColorToRgb(pluginManager, {
|
|
243
244
|
value: color,
|
|
244
245
|
});
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
export function getHslFromAnimation(animation) {
|
|
248
|
-
return animation
|
|
249
|
-
?
|
|
249
|
+
return animation === undefined
|
|
250
|
+
? undefined
|
|
251
|
+
: {
|
|
250
252
|
h: animation.h.value,
|
|
251
253
|
s: animation.s.value,
|
|
252
254
|
l: animation.l.value,
|
|
253
|
-
}
|
|
254
|
-
: undefined;
|
|
255
|
+
};
|
|
255
256
|
}
|
|
256
257
|
export function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
257
258
|
const resColor = {
|
|
258
259
|
h: {
|
|
259
260
|
enable: false,
|
|
260
261
|
value: hsl.h,
|
|
262
|
+
min: hMin,
|
|
263
|
+
max: hMax,
|
|
261
264
|
},
|
|
262
265
|
s: {
|
|
263
266
|
enable: false,
|
|
264
267
|
value: hsl.s,
|
|
268
|
+
min: sMin,
|
|
269
|
+
max: sMax,
|
|
265
270
|
},
|
|
266
271
|
l: {
|
|
267
272
|
enable: false,
|
|
268
273
|
value: hsl.l,
|
|
274
|
+
min: lMin,
|
|
275
|
+
max: lMax,
|
|
269
276
|
},
|
|
270
277
|
};
|
|
271
278
|
if (animationOptions) {
|
|
@@ -277,6 +284,8 @@ export function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
|
277
284
|
}
|
|
278
285
|
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
279
286
|
colorValue.enable = colorAnimation.enable;
|
|
287
|
+
colorValue.min = colorAnimation.min;
|
|
288
|
+
colorValue.max = colorAnimation.max;
|
|
280
289
|
if (colorValue.enable) {
|
|
281
290
|
colorValue.velocity = (getRangeValue(colorAnimation.speed) / percentDenominator) * reduceFactor;
|
|
282
291
|
colorValue.decay = decayOffset - getRangeValue(colorAnimation.decay);
|
|
@@ -296,7 +305,7 @@ function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
|
296
305
|
colorValue.velocity = defaultVelocity;
|
|
297
306
|
}
|
|
298
307
|
}
|
|
299
|
-
export function updateColorValue(data,
|
|
308
|
+
export function updateColorValue(data, decrease, delta) {
|
|
300
309
|
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
|
|
301
310
|
if (!data.enable ||
|
|
302
311
|
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
|
|
@@ -309,7 +318,7 @@ export function updateColorValue(data, range, decrease, delta) {
|
|
|
309
318
|
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
310
319
|
return;
|
|
311
320
|
}
|
|
312
|
-
const offset = data.offset ? randomInRangeValue(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max =
|
|
321
|
+
const offset = data.offset ? randomInRangeValue(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
|
|
313
322
|
if (!decrease || data.status === AnimationStatus.increasing) {
|
|
314
323
|
data.value += velocity;
|
|
315
324
|
if (data.value > max) {
|
|
@@ -325,8 +334,7 @@ export function updateColorValue(data, range, decrease, delta) {
|
|
|
325
334
|
}
|
|
326
335
|
else {
|
|
327
336
|
data.value -= velocity;
|
|
328
|
-
|
|
329
|
-
if (data.value < minValue) {
|
|
337
|
+
if (data.value < min) {
|
|
330
338
|
data.loops ??= 0;
|
|
331
339
|
data.loops++;
|
|
332
340
|
data.status = AnimationStatus.increasing;
|
|
@@ -341,12 +349,15 @@ export function updateColor(color, delta) {
|
|
|
341
349
|
if (!color) {
|
|
342
350
|
return;
|
|
343
351
|
}
|
|
344
|
-
const { h, s, l } = color
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
352
|
+
const { h, s, l } = color;
|
|
353
|
+
updateColorValue(h, false, delta);
|
|
354
|
+
updateColorValue(s, true, delta);
|
|
355
|
+
updateColorValue(l, true, delta);
|
|
356
|
+
}
|
|
357
|
+
export function alterHsl(color, type, value) {
|
|
358
|
+
return {
|
|
359
|
+
h: color.h,
|
|
360
|
+
s: color.s,
|
|
361
|
+
l: color.l + (type === AlterType.darken ? -lFactor : lFactor) * value,
|
|
348
362
|
};
|
|
349
|
-
updateColorValue(h, ranges.h, false, delta);
|
|
350
|
-
updateColorValue(s, ranges.s, true, delta);
|
|
351
|
-
updateColorValue(l, ranges.l, true, delta);
|
|
352
363
|
}
|
package/esm/Utils/LogUtils.js
CHANGED
package/esm/Utils/MathUtils.js
CHANGED
|
@@ -21,10 +21,8 @@ export function getRandomInRange(min, max) {
|
|
|
21
21
|
return getRandom() * (max - min) + min;
|
|
22
22
|
}
|
|
23
23
|
export function setAnimationFunctions(nextFrame, cancel) {
|
|
24
|
-
_animationLoop.nextFrame =
|
|
25
|
-
_animationLoop.cancel =
|
|
26
|
-
cancel(handle);
|
|
27
|
-
};
|
|
24
|
+
_animationLoop.nextFrame = nextFrame;
|
|
25
|
+
_animationLoop.cancel = cancel;
|
|
28
26
|
}
|
|
29
27
|
export function animate(fn) {
|
|
30
28
|
return _animationLoop.nextFrame(fn);
|
|
@@ -68,11 +66,18 @@ export function setRangeValue(source, value) {
|
|
|
68
66
|
: setRangeValue(min, max);
|
|
69
67
|
}
|
|
70
68
|
export function getDistances(pointA, pointB) {
|
|
71
|
-
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y
|
|
72
|
-
return { dx: dx, dy: dy, distance: Math.
|
|
69
|
+
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
|
|
70
|
+
return { dx: dx, dy: dy, distance: Math.hypot(dx, dy) };
|
|
71
|
+
}
|
|
72
|
+
export function getDistanceSq(pointA, pointB) {
|
|
73
|
+
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
|
|
74
|
+
return dx * dx + dy * dy;
|
|
73
75
|
}
|
|
74
76
|
export function getDistance(pointA, pointB) {
|
|
75
|
-
return
|
|
77
|
+
return Math.sqrt(getDistanceSq(pointA, pointB));
|
|
78
|
+
}
|
|
79
|
+
export function checkDistance(pointA, pointB, distance) {
|
|
80
|
+
return getDistanceSq(pointA, pointB) <= distance * distance;
|
|
76
81
|
}
|
|
77
82
|
export function degToRad(degrees) {
|
|
78
83
|
return degrees * degToRadFactor;
|
|
@@ -4,8 +4,8 @@ export function loadOptions(options, ...sourceOptionsArr) {
|
|
|
4
4
|
options.load(sourceOptions);
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
export function loadParticlesOptions(
|
|
8
|
-
const options = new ParticlesOptions(
|
|
7
|
+
export function loadParticlesOptions(pluginManager, container, ...sourceOptionsArr) {
|
|
8
|
+
const options = new ParticlesOptions(pluginManager, container);
|
|
9
9
|
loadOptions(options, ...sourceOptionsArr);
|
|
10
10
|
return options;
|
|
11
11
|
}
|