@tsparticles/engine 4.0.0-alpha.25 → 4.0.0-alpha.27
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 +3 -3
- package/browser/Core/Canvas.js +7 -4
- package/browser/Core/Engine.js +6 -16
- package/browser/Core/Particle.js +10 -35
- package/browser/Core/Particles.js +0 -23
- package/browser/Core/Utils/Constants.js +1 -1
- package/browser/Core/Utils/Ranges.js +2 -2
- package/browser/Core/Utils/Vectors.js +10 -7
- package/browser/Options/Classes/ColorAnimation.js +11 -1
- package/browser/Options/Classes/HslAnimation.js +4 -3
- package/browser/Options/Classes/Options.js +38 -1
- package/browser/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/browser/Options/Classes/Particles/Fill.js +28 -0
- package/browser/Options/Classes/Particles/Move/Move.js +0 -4
- package/browser/Options/Classes/Particles/ParticlesOptions.js +12 -6
- package/browser/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/browser/Utils/CanvasUtils.js +33 -36
- package/browser/Utils/ColorUtils.js +22 -19
- package/browser/Utils/MathUtils.js +8 -1
- package/browser/Utils/Utils.js +93 -24
- package/browser/exports.js +1 -1
- package/cjs/Core/Canvas.js +7 -4
- package/cjs/Core/Engine.js +6 -16
- package/cjs/Core/Particle.js +10 -35
- package/cjs/Core/Particles.js +0 -23
- package/cjs/Core/Utils/Constants.js +1 -1
- package/cjs/Core/Utils/Ranges.js +2 -2
- package/cjs/Core/Utils/Vectors.js +10 -7
- package/cjs/Options/Classes/ColorAnimation.js +11 -1
- package/cjs/Options/Classes/HslAnimation.js +4 -3
- package/cjs/Options/Classes/Options.js +38 -1
- package/cjs/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/cjs/Options/Classes/Particles/Fill.js +28 -0
- package/cjs/Options/Classes/Particles/Move/Move.js +0 -4
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +12 -6
- package/cjs/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/cjs/Utils/CanvasUtils.js +33 -36
- package/cjs/Utils/ColorUtils.js +22 -19
- package/cjs/Utils/MathUtils.js +8 -1
- package/cjs/Utils/Utils.js +93 -24
- package/cjs/exports.js +1 -1
- package/dist_browser_Core_Container_js.js +4 -4
- package/esm/Core/Canvas.js +7 -4
- package/esm/Core/Engine.js +6 -16
- package/esm/Core/Particle.js +10 -35
- package/esm/Core/Particles.js +0 -23
- package/esm/Core/Utils/Constants.js +1 -1
- package/esm/Core/Utils/Ranges.js +2 -2
- package/esm/Core/Utils/Vectors.js +10 -7
- package/esm/Options/Classes/ColorAnimation.js +11 -1
- package/esm/Options/Classes/HslAnimation.js +4 -3
- package/esm/Options/Classes/Options.js +38 -1
- package/esm/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/esm/Options/Classes/Particles/Fill.js +28 -0
- package/esm/Options/Classes/Particles/Move/Move.js +0 -4
- package/esm/Options/Classes/Particles/ParticlesOptions.js +12 -6
- package/esm/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/esm/Utils/CanvasUtils.js +33 -36
- package/esm/Utils/ColorUtils.js +22 -19
- package/esm/Utils/MathUtils.js +8 -1
- package/esm/Utils/Utils.js +93 -24
- package/esm/exports.js +1 -1
- package/package.json +1 -1
- package/report.html +1 -1
- package/scripts/install.js +4 -20
- package/tsparticles.engine.js +34 -34
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/Engine.d.ts +5 -9
- 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/IShapeValues.d.ts +0 -1
- package/types/Core/Particle.d.ts +3 -7
- package/types/Core/Particles.d.ts +0 -5
- package/types/Core/Utils/Constants.d.ts +1 -1
- package/types/Core/Utils/Vectors.d.ts +6 -6
- package/types/Options/Classes/ColorAnimation.d.ts +3 -1
- 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/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 +0 -6
- package/types/Utils/CanvasUtils.d.ts +6 -7
- package/types/Utils/ColorUtils.d.ts +1 -2
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/Utils/Utils.d.ts +7 -0
- package/types/export-types.d.ts +2 -4
- package/types/exports.d.ts +1 -1
- package/umd/Core/Canvas.js +6 -3
- package/umd/Core/Engine.js +6 -16
- package/umd/Core/Particle.js +11 -36
- package/umd/Core/Particles.js +0 -23
- package/umd/Core/Utils/Constants.js +2 -2
- package/umd/Core/Utils/Ranges.js +1 -1
- package/umd/Core/Utils/Vectors.js +10 -7
- package/umd/Options/Classes/ColorAnimation.js +11 -1
- package/umd/Options/Classes/HslAnimation.js +5 -4
- package/umd/Options/Classes/Options.js +38 -1
- package/umd/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/umd/Options/Classes/Particles/Fill.js +42 -0
- package/umd/Options/Classes/Particles/Move/Move.js +1 -5
- package/umd/Options/Classes/Particles/ParticlesOptions.js +13 -7
- package/umd/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/umd/Utils/CanvasUtils.js +33 -36
- package/umd/Utils/ColorUtils.js +21 -18
- package/umd/Utils/MathUtils.js +10 -1
- package/umd/Utils/Utils.js +94 -24
- package/umd/exports.js +2 -2
- package/152.min.js +0 -1
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/esm/Core/Interfaces/IMovePathGenerator.js +0 -1
- package/esm/Core/Interfaces/IParticleMover.js +0 -1
- package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/esm/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -9
- package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
- package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
- package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -50
- 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
package/esm/Core/Particles.js
CHANGED
|
@@ -6,12 +6,9 @@ import { SpatialHashGrid } from "./Utils/SpatialHashGrid.js";
|
|
|
6
6
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
7
7
|
import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
|
|
8
8
|
export class Particles {
|
|
9
|
-
availablePathGenerators;
|
|
10
9
|
checkParticlePositionPlugins;
|
|
11
10
|
effectDrawers;
|
|
12
11
|
grid;
|
|
13
|
-
movers;
|
|
14
|
-
pathGenerators;
|
|
15
12
|
shapeDrawers;
|
|
16
13
|
updaters;
|
|
17
14
|
_array;
|
|
@@ -45,9 +42,6 @@ export class Particles {
|
|
|
45
42
|
this._maxZIndex = 0;
|
|
46
43
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
47
44
|
this.effectDrawers = new Map();
|
|
48
|
-
this.movers = [];
|
|
49
|
-
this.availablePathGenerators = new Map();
|
|
50
|
-
this.pathGenerators = new Map();
|
|
51
45
|
this.shapeDrawers = new Map();
|
|
52
46
|
this.updaters = [];
|
|
53
47
|
this.checkParticlePositionPlugins = [];
|
|
@@ -123,9 +117,6 @@ export class Particles {
|
|
|
123
117
|
this._pool.length = 0;
|
|
124
118
|
this._zArray = [];
|
|
125
119
|
this.effectDrawers = new Map();
|
|
126
|
-
this.movers = [];
|
|
127
|
-
this.availablePathGenerators = new Map();
|
|
128
|
-
this.pathGenerators = new Map();
|
|
129
120
|
this.shapeDrawers = new Map();
|
|
130
121
|
this.updaters = [];
|
|
131
122
|
this.checkParticlePositionPlugins = [];
|
|
@@ -217,14 +208,8 @@ export class Particles {
|
|
|
217
208
|
async initPlugins() {
|
|
218
209
|
const container = this._container;
|
|
219
210
|
this.effectDrawers = await this._engine.getEffectDrawers(container, true);
|
|
220
|
-
this.movers = await this._engine.getMovers(container, true);
|
|
221
|
-
this.availablePathGenerators = await this._engine.getPathGenerators(container, true);
|
|
222
|
-
this.pathGenerators = new Map();
|
|
223
211
|
this.shapeDrawers = await this._engine.getShapeDrawers(container, true);
|
|
224
212
|
this.updaters = await this._engine.getUpdaters(container, true);
|
|
225
|
-
for (const pathGenerator of this.pathGenerators.values()) {
|
|
226
|
-
pathGenerator.init();
|
|
227
|
-
}
|
|
228
213
|
}
|
|
229
214
|
push(nb, position, overrideOptions, group) {
|
|
230
215
|
for (let i = 0; i < nb; i++) {
|
|
@@ -281,9 +266,6 @@ export class Particles {
|
|
|
281
266
|
update(delta) {
|
|
282
267
|
const particlesToDelete = new Set();
|
|
283
268
|
this.grid.clear();
|
|
284
|
-
for (const pathGenerator of this.pathGenerators.values()) {
|
|
285
|
-
pathGenerator.update();
|
|
286
|
-
}
|
|
287
269
|
for (const plugin of this._updatePlugins) {
|
|
288
270
|
plugin.update?.(delta);
|
|
289
271
|
}
|
|
@@ -305,11 +287,6 @@ export class Particles {
|
|
|
305
287
|
}
|
|
306
288
|
plugin.particleUpdate?.(particle, delta);
|
|
307
289
|
}
|
|
308
|
-
for (const mover of this.movers) {
|
|
309
|
-
if (mover.isEnabled(particle)) {
|
|
310
|
-
mover.move(particle, delta);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
290
|
if (particle.destroyed) {
|
|
314
291
|
particlesToDelete.add(particle);
|
|
315
292
|
continue;
|
|
@@ -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,
|
package/esm/Core/Utils/Ranges.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
position;
|
|
@@ -19,7 +19,7 @@ export class Circle extends BaseRange {
|
|
|
19
19
|
this.radius = radius;
|
|
20
20
|
}
|
|
21
21
|
contains(point) {
|
|
22
|
-
return
|
|
22
|
+
return checkDistance(point, this.position, this.radius);
|
|
23
23
|
}
|
|
24
24
|
intersects(range) {
|
|
25
25
|
const pos1 = this.position, pos2 = range.position, distPos = { x: Math.abs(pos2.x - pos1.x), y: Math.abs(pos2.y - pos1.y) }, r = this.radius;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { inverseFactorNumerator, none, originPoint, squareExp } from "./Constants.js";
|
|
2
|
+
function getZ(source) {
|
|
3
|
+
return "z" in source ? source.z : originPoint.z;
|
|
4
|
+
}
|
|
2
5
|
export class Vector3d {
|
|
3
6
|
x;
|
|
4
7
|
y;
|
|
@@ -24,21 +27,21 @@ export class Vector3d {
|
|
|
24
27
|
this._updateFromAngle(this.angle, length);
|
|
25
28
|
}
|
|
26
29
|
static clone(source) {
|
|
27
|
-
return Vector3d.create(source.x, source.y, source
|
|
30
|
+
return Vector3d.create(source.x, source.y, getZ(source));
|
|
28
31
|
}
|
|
29
32
|
static create(x, y, z) {
|
|
30
33
|
if (typeof x === "number") {
|
|
31
34
|
return new Vector3d(x, y ?? originPoint.y, z ?? originPoint.z);
|
|
32
35
|
}
|
|
33
|
-
return new Vector3d(x.x, x.y,
|
|
36
|
+
return new Vector3d(x.x, x.y, getZ(x));
|
|
34
37
|
}
|
|
35
38
|
add(v) {
|
|
36
|
-
return Vector3d.create(this.x + v.x, this.y + v.y, this.z + v
|
|
39
|
+
return Vector3d.create(this.x + v.x, this.y + v.y, this.z + getZ(v));
|
|
37
40
|
}
|
|
38
41
|
addTo(v) {
|
|
39
42
|
this.x += v.x;
|
|
40
43
|
this.y += v.y;
|
|
41
|
-
this.z += v
|
|
44
|
+
this.z += getZ(v);
|
|
42
45
|
}
|
|
43
46
|
copy() {
|
|
44
47
|
return Vector3d.clone(this);
|
|
@@ -74,15 +77,15 @@ export class Vector3d {
|
|
|
74
77
|
setTo(c) {
|
|
75
78
|
this.x = c.x;
|
|
76
79
|
this.y = c.y;
|
|
77
|
-
this.z =
|
|
80
|
+
this.z = getZ(c);
|
|
78
81
|
}
|
|
79
82
|
sub(v) {
|
|
80
|
-
return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v
|
|
83
|
+
return Vector3d.create(this.x - v.x, this.y - v.y, this.z - getZ(v));
|
|
81
84
|
}
|
|
82
85
|
subFrom(v) {
|
|
83
86
|
this.x -= v.x;
|
|
84
87
|
this.y -= v.y;
|
|
85
|
-
this.z -= v
|
|
88
|
+
this.z -= getZ(v);
|
|
86
89
|
}
|
|
87
90
|
_updateFromAngle(angle, length) {
|
|
88
91
|
this.x = Math.cos(angle) * length;
|
|
@@ -2,9 +2,13 @@ import { AnimationOptions } from "./AnimationOptions.js";
|
|
|
2
2
|
import { isNull } from "../../Utils/TypeUtils.js";
|
|
3
3
|
import { setRangeValue } from "../../Utils/MathUtils.js";
|
|
4
4
|
export class ColorAnimation extends AnimationOptions {
|
|
5
|
+
max;
|
|
6
|
+
min;
|
|
5
7
|
offset;
|
|
6
|
-
constructor() {
|
|
8
|
+
constructor(min, max) {
|
|
7
9
|
super();
|
|
10
|
+
this.min = min;
|
|
11
|
+
this.max = max;
|
|
8
12
|
this.offset = 0;
|
|
9
13
|
this.sync = true;
|
|
10
14
|
}
|
|
@@ -13,6 +17,12 @@ export class ColorAnimation extends AnimationOptions {
|
|
|
13
17
|
if (isNull(data)) {
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
20
|
+
if (data.max !== undefined) {
|
|
21
|
+
this.max = data.max;
|
|
22
|
+
}
|
|
23
|
+
if (data.min !== undefined) {
|
|
24
|
+
this.min = data.min;
|
|
25
|
+
}
|
|
16
26
|
if (data.offset !== undefined) {
|
|
17
27
|
this.offset = setRangeValue(data.offset);
|
|
18
28
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { hMax, hMin, lMax, lMin, sMax, sMin } from "../../Core/Utils/Constants.js";
|
|
1
2
|
import { ColorAnimation } from "./ColorAnimation.js";
|
|
2
3
|
import { isNull } from "../../Utils/TypeUtils.js";
|
|
3
4
|
export class HslAnimation {
|
|
4
|
-
h = new ColorAnimation();
|
|
5
|
-
l = new ColorAnimation();
|
|
6
|
-
s = new ColorAnimation();
|
|
5
|
+
h = new ColorAnimation(hMin, hMax);
|
|
6
|
+
l = new ColorAnimation(lMin, lMax);
|
|
7
|
+
s = new ColorAnimation(sMin, sMax);
|
|
7
8
|
load(data) {
|
|
8
9
|
if (isNull(data)) {
|
|
9
10
|
return;
|
|
@@ -18,6 +18,7 @@ export class Options {
|
|
|
18
18
|
hdr;
|
|
19
19
|
key;
|
|
20
20
|
name;
|
|
21
|
+
palette;
|
|
21
22
|
particles;
|
|
22
23
|
pauseOnBlur;
|
|
23
24
|
pauseOnOutsideViewport;
|
|
@@ -54,10 +55,15 @@ export class Options {
|
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
if (data.preset !== undefined) {
|
|
57
|
-
|
|
58
|
+
this.preset = data.preset;
|
|
59
|
+
executeOnSingleOrMultiple(this.preset, preset => {
|
|
58
60
|
this._importPreset(preset);
|
|
59
61
|
});
|
|
60
62
|
}
|
|
63
|
+
if (data.palette !== undefined) {
|
|
64
|
+
this.palette = data.palette;
|
|
65
|
+
this._importPalette(this.palette);
|
|
66
|
+
}
|
|
61
67
|
if (data.autoPlay !== undefined) {
|
|
62
68
|
this.autoPlay = data.autoPlay;
|
|
63
69
|
}
|
|
@@ -114,6 +120,37 @@ export class Options {
|
|
|
114
120
|
plugin.loadOptions(this._container, this, data);
|
|
115
121
|
});
|
|
116
122
|
}
|
|
123
|
+
_importPalette = palette => {
|
|
124
|
+
const paletteData = this._engine.getPalette(palette);
|
|
125
|
+
if (!paletteData) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.load({
|
|
129
|
+
background: {
|
|
130
|
+
color: paletteData.background,
|
|
131
|
+
},
|
|
132
|
+
blend: {
|
|
133
|
+
enable: true,
|
|
134
|
+
mode: paletteData.blendMode,
|
|
135
|
+
},
|
|
136
|
+
particles: {
|
|
137
|
+
fill: {
|
|
138
|
+
color: paletteData.fill
|
|
139
|
+
? {
|
|
140
|
+
value: paletteData.colors,
|
|
141
|
+
}
|
|
142
|
+
: undefined,
|
|
143
|
+
enable: paletteData.fill,
|
|
144
|
+
},
|
|
145
|
+
stroke: !paletteData.fill
|
|
146
|
+
? paletteData.colors.map(color => ({
|
|
147
|
+
color: { value: color },
|
|
148
|
+
width: 1,
|
|
149
|
+
}))
|
|
150
|
+
: undefined,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
};
|
|
117
154
|
_importPreset = preset => {
|
|
118
155
|
this.load(this._engine.getPreset(preset));
|
|
119
156
|
};
|
|
@@ -2,12 +2,10 @@ import { deepExtend } from "../../../../Utils/Utils.js";
|
|
|
2
2
|
import { isNull } from "../../../../Utils/TypeUtils.js";
|
|
3
3
|
export class Effect {
|
|
4
4
|
close;
|
|
5
|
-
fill;
|
|
6
5
|
options;
|
|
7
6
|
type;
|
|
8
7
|
constructor() {
|
|
9
8
|
this.close = true;
|
|
10
|
-
this.fill = true;
|
|
11
9
|
this.options = {};
|
|
12
10
|
this.type = [];
|
|
13
11
|
}
|
|
@@ -27,9 +25,6 @@ export class Effect {
|
|
|
27
25
|
if (data.close !== undefined) {
|
|
28
26
|
this.close = data.close;
|
|
29
27
|
}
|
|
30
|
-
if (data.fill !== undefined) {
|
|
31
|
-
this.fill = data.fill;
|
|
32
|
-
}
|
|
33
28
|
if (data.type !== undefined) {
|
|
34
29
|
this.type = data.type;
|
|
35
30
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AnimatableColor } from "../AnimatableColor.js";
|
|
2
|
+
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
3
|
+
import { setRangeValue } from "../../../Utils/MathUtils.js";
|
|
4
|
+
export class Fill {
|
|
5
|
+
color;
|
|
6
|
+
enable;
|
|
7
|
+
opacity;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.enable = true;
|
|
10
|
+
this.color = new AnimatableColor();
|
|
11
|
+
this.color.value = "#fff";
|
|
12
|
+
this.opacity = 1;
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
if (isNull(data)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (data.color !== undefined) {
|
|
19
|
+
this.color = AnimatableColor.create(this.color, data.color);
|
|
20
|
+
}
|
|
21
|
+
if (data.enable !== undefined) {
|
|
22
|
+
this.enable = data.enable;
|
|
23
|
+
}
|
|
24
|
+
if (data.opacity !== undefined) {
|
|
25
|
+
this.opacity = setRangeValue(data.opacity);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MoveDirection } from "../../../../Enums/Directions/MoveDirection.js";
|
|
2
2
|
import { isNull, isNumber, isObject } from "../../../../Utils/TypeUtils.js";
|
|
3
3
|
import { MoveAngle } from "./MoveAngle.js";
|
|
4
|
-
import { MoveAttract } from "./MoveAttract.js";
|
|
5
4
|
import { MoveCenter } from "./MoveCenter.js";
|
|
6
5
|
import { MoveGravity } from "./MoveGravity.js";
|
|
7
6
|
import { MovePath } from "./Path/MovePath.js";
|
|
@@ -10,7 +9,6 @@ import { Spin } from "./Spin.js";
|
|
|
10
9
|
import { setRangeValue } from "../../../../Utils/MathUtils.js";
|
|
11
10
|
export class Move {
|
|
12
11
|
angle;
|
|
13
|
-
attract;
|
|
14
12
|
center;
|
|
15
13
|
decay;
|
|
16
14
|
direction;
|
|
@@ -29,7 +27,6 @@ export class Move {
|
|
|
29
27
|
warp;
|
|
30
28
|
constructor() {
|
|
31
29
|
this.angle = new MoveAngle();
|
|
32
|
-
this.attract = new MoveAttract();
|
|
33
30
|
this.center = new MoveCenter();
|
|
34
31
|
this.decay = 0;
|
|
35
32
|
this.distance = {};
|
|
@@ -52,7 +49,6 @@ export class Move {
|
|
|
52
49
|
return;
|
|
53
50
|
}
|
|
54
51
|
this.angle.load(isNumber(data.angle) ? { value: data.angle } : data.angle);
|
|
55
|
-
this.attract.load(data.attract);
|
|
56
52
|
this.center.load(data.center);
|
|
57
53
|
if (data.decay !== undefined) {
|
|
58
54
|
this.decay = setRangeValue(data.decay);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deepExtend, executeOnSingleOrMultiple } from "../../../Utils/Utils.js";
|
|
2
|
-
import { AnimatableColor } from "../AnimatableColor.js";
|
|
3
2
|
import { Effect } from "./Effect/Effect.js";
|
|
3
|
+
import { Fill } from "./Fill.js";
|
|
4
4
|
import { Move } from "./Move/Move.js";
|
|
5
5
|
import { Opacity } from "./Opacity/Opacity.js";
|
|
6
6
|
import { ParticlesBounce } from "./Bounce/ParticlesBounce.js";
|
|
@@ -12,8 +12,8 @@ import { ZIndex } from "./ZIndex/ZIndex.js";
|
|
|
12
12
|
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
13
13
|
export class ParticlesOptions {
|
|
14
14
|
bounce;
|
|
15
|
-
color;
|
|
16
15
|
effect;
|
|
16
|
+
fill;
|
|
17
17
|
groups;
|
|
18
18
|
move;
|
|
19
19
|
number;
|
|
@@ -29,9 +29,8 @@ export class ParticlesOptions {
|
|
|
29
29
|
this._engine = engine;
|
|
30
30
|
this._container = container;
|
|
31
31
|
this.bounce = new ParticlesBounce();
|
|
32
|
-
this.color = new AnimatableColor();
|
|
33
|
-
this.color.value = "#fff";
|
|
34
32
|
this.effect = new Effect();
|
|
33
|
+
this.fill = new Fill();
|
|
35
34
|
this.groups = {};
|
|
36
35
|
this.move = new Move();
|
|
37
36
|
this.number = new ParticlesNumber();
|
|
@@ -48,7 +47,7 @@ export class ParticlesOptions {
|
|
|
48
47
|
}
|
|
49
48
|
if (data.groups !== undefined) {
|
|
50
49
|
for (const group of Object.keys(data.groups)) {
|
|
51
|
-
if (!
|
|
50
|
+
if (!(group in data.groups)) {
|
|
52
51
|
continue;
|
|
53
52
|
}
|
|
54
53
|
const item = data.groups[group];
|
|
@@ -61,7 +60,6 @@ export class ParticlesOptions {
|
|
|
61
60
|
this.reduceDuplicates = data.reduceDuplicates;
|
|
62
61
|
}
|
|
63
62
|
this.bounce.load(data.bounce);
|
|
64
|
-
this.color.load(AnimatableColor.create(this.color, data.color));
|
|
65
63
|
this.effect.load(data.effect);
|
|
66
64
|
this.move.load(data.move);
|
|
67
65
|
this.number.load(data.number);
|
|
@@ -69,6 +67,14 @@ export class ParticlesOptions {
|
|
|
69
67
|
this.shape.load(data.shape);
|
|
70
68
|
this.size.load(data.size);
|
|
71
69
|
this.zIndex.load(data.zIndex);
|
|
70
|
+
const fillToLoad = data.fill;
|
|
71
|
+
if (fillToLoad) {
|
|
72
|
+
this.fill = executeOnSingleOrMultiple(fillToLoad, t => {
|
|
73
|
+
const tmp = new Fill();
|
|
74
|
+
tmp.load(t);
|
|
75
|
+
return tmp;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
72
78
|
const strokeToLoad = data.stroke;
|
|
73
79
|
if (strokeToLoad) {
|
|
74
80
|
this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
|
|
@@ -2,12 +2,10 @@ import { deepExtend } from "../../../../Utils/Utils.js";
|
|
|
2
2
|
import { isNull } from "../../../../Utils/TypeUtils.js";
|
|
3
3
|
export class Shape {
|
|
4
4
|
close;
|
|
5
|
-
fill;
|
|
6
5
|
options;
|
|
7
6
|
type;
|
|
8
7
|
constructor() {
|
|
9
8
|
this.close = true;
|
|
10
|
-
this.fill = true;
|
|
11
9
|
this.options = {};
|
|
12
10
|
this.type = "circle";
|
|
13
11
|
}
|
|
@@ -27,9 +25,6 @@ export class Shape {
|
|
|
27
25
|
if (data.close !== undefined) {
|
|
28
26
|
this.close = data.close;
|
|
29
27
|
}
|
|
30
|
-
if (data.fill !== undefined) {
|
|
31
|
-
this.fill = data.fill;
|
|
32
|
-
}
|
|
33
28
|
if (data.type !== undefined) {
|
|
34
29
|
this.type = data.type;
|
|
35
30
|
}
|
package/esm/Utils/CanvasUtils.js
CHANGED
|
@@ -7,15 +7,16 @@ export function paintImage(context, dimension, image, opacity) {
|
|
|
7
7
|
if (!image) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
+
const prevAlpha = context.globalAlpha;
|
|
10
11
|
context.globalAlpha = opacity;
|
|
11
12
|
context.drawImage(image, originPoint.x, originPoint.y, dimension.width, dimension.height);
|
|
12
|
-
context.globalAlpha =
|
|
13
|
+
context.globalAlpha = prevAlpha;
|
|
13
14
|
}
|
|
14
15
|
export function clear(context, dimension) {
|
|
15
16
|
context.clearRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
|
|
16
17
|
}
|
|
17
18
|
export function drawParticle(data) {
|
|
18
|
-
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
|
|
19
|
+
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container.particles, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
|
|
19
20
|
x: pos.x,
|
|
20
21
|
y: pos.y,
|
|
21
22
|
};
|
|
@@ -23,7 +24,7 @@ export function drawParticle(data) {
|
|
|
23
24
|
if (colorStyles.fill) {
|
|
24
25
|
context.fillStyle = colorStyles.fill;
|
|
25
26
|
}
|
|
26
|
-
const strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
27
|
+
const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
27
28
|
context.lineWidth = strokeWidth;
|
|
28
29
|
if (colorStyles.stroke) {
|
|
29
30
|
context.strokeStyle = colorStyles.stroke;
|
|
@@ -36,8 +37,8 @@ export function drawParticle(data) {
|
|
|
36
37
|
opacity,
|
|
37
38
|
delta,
|
|
38
39
|
pixelRatio: container.retina.pixelRatio,
|
|
39
|
-
fill:
|
|
40
|
-
stroke: strokeWidth > minStrokeWidth
|
|
40
|
+
fill: fillEnabled,
|
|
41
|
+
stroke: strokeWidth > minStrokeWidth,
|
|
41
42
|
transformData,
|
|
42
43
|
position: { ...pos },
|
|
43
44
|
drawPosition,
|
|
@@ -46,42 +47,40 @@ export function drawParticle(data) {
|
|
|
46
47
|
for (const plugin of container.plugins) {
|
|
47
48
|
plugin.drawParticleTransform?.(drawData);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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);
|
|
54
56
|
context.resetTransform();
|
|
55
57
|
}
|
|
56
|
-
export function drawAfterEffect(
|
|
58
|
+
export function drawAfterEffect(drawer, data) {
|
|
59
|
+
if (!drawer?.drawAfter) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
57
62
|
const { particle } = data;
|
|
58
63
|
if (!particle.effect) {
|
|
59
64
|
return;
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
drawer.drawAfter(data);
|
|
67
|
+
}
|
|
68
|
+
export function drawBeforeEffect(drawer, data) {
|
|
69
|
+
if (!drawer?.drawBefore) {
|
|
63
70
|
return;
|
|
64
71
|
}
|
|
65
|
-
drawFunc(data);
|
|
66
|
-
}
|
|
67
|
-
export function drawBeforeEffect(container, data) {
|
|
68
72
|
const { particle } = data;
|
|
69
73
|
if (!particle.effect) {
|
|
70
74
|
return;
|
|
71
75
|
}
|
|
72
|
-
const drawer = container.particles.effectDrawers.get(particle.effect);
|
|
73
|
-
if (!drawer?.drawBefore) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
76
|
drawer.drawBefore(data);
|
|
77
77
|
}
|
|
78
|
-
export function drawShape(
|
|
79
|
-
|
|
80
|
-
if (!particle.shape) {
|
|
78
|
+
export function drawShape(drawer, data) {
|
|
79
|
+
if (!drawer) {
|
|
81
80
|
return;
|
|
82
81
|
}
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
82
|
+
const { context, fill, particle, stroke } = data;
|
|
83
|
+
if (!particle.shape) {
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
context.beginPath();
|
|
@@ -92,30 +91,28 @@ export function drawShape(container, data) {
|
|
|
92
91
|
if (stroke) {
|
|
93
92
|
context.stroke();
|
|
94
93
|
}
|
|
95
|
-
if (
|
|
94
|
+
if (fill) {
|
|
96
95
|
context.fill();
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
|
-
export function drawShapeAfterDraw(
|
|
100
|
-
const { particle } = data;
|
|
101
|
-
if (!particle.shape) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const drawer = container.particles.shapeDrawers.get(particle.shape);
|
|
98
|
+
export function drawShapeAfterDraw(drawer, data) {
|
|
105
99
|
if (!drawer?.afterDraw) {
|
|
106
100
|
return;
|
|
107
101
|
}
|
|
108
|
-
drawer.afterDraw(data);
|
|
109
|
-
}
|
|
110
|
-
export function drawShapeBeforeDraw(container, data) {
|
|
111
102
|
const { particle } = data;
|
|
112
103
|
if (!particle.shape) {
|
|
113
104
|
return;
|
|
114
105
|
}
|
|
115
|
-
|
|
106
|
+
drawer.afterDraw(data);
|
|
107
|
+
}
|
|
108
|
+
export function drawShapeBeforeDraw(drawer, data) {
|
|
116
109
|
if (!drawer?.beforeDraw) {
|
|
117
110
|
return;
|
|
118
111
|
}
|
|
112
|
+
const { particle } = data;
|
|
113
|
+
if (!particle.shape) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
119
116
|
drawer.beforeDraw(data);
|
|
120
117
|
}
|
|
121
118
|
export function drawParticlePlugin(context, plugin, particle, delta) {
|
package/esm/Utils/ColorUtils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clamp, getRandom, getRandomInRange,
|
|
1
|
+
import { clamp, getRandom, getRandomInRange, getRangeValue, mix, randomInRangeValue, setRangeValue, } from "./MathUtils.js";
|
|
2
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
4
|
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
@@ -190,10 +190,10 @@ function getSdrStyleFromHsl(color, opacity) {
|
|
|
190
190
|
}
|
|
191
191
|
export function colorMix(color1, color2, size1, size2) {
|
|
192
192
|
let rgb1 = color1, rgb2 = color2;
|
|
193
|
-
if (!
|
|
193
|
+
if (!("r" in rgb1)) {
|
|
194
194
|
rgb1 = hslToRgb(color1);
|
|
195
195
|
}
|
|
196
|
-
if (!
|
|
196
|
+
if (!("r" in rgb2)) {
|
|
197
197
|
rgb2 = hslToRgb(color2);
|
|
198
198
|
}
|
|
199
199
|
return {
|
|
@@ -246,27 +246,33 @@ export function getLinkRandomColor(engine, optColor, blink, consent) {
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
export function getHslFromAnimation(animation) {
|
|
249
|
-
return animation
|
|
250
|
-
?
|
|
249
|
+
return animation === undefined
|
|
250
|
+
? undefined
|
|
251
|
+
: {
|
|
251
252
|
h: animation.h.value,
|
|
252
253
|
s: animation.s.value,
|
|
253
254
|
l: animation.l.value,
|
|
254
|
-
}
|
|
255
|
-
: undefined;
|
|
255
|
+
};
|
|
256
256
|
}
|
|
257
257
|
export function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
258
258
|
const resColor = {
|
|
259
259
|
h: {
|
|
260
260
|
enable: false,
|
|
261
261
|
value: hsl.h,
|
|
262
|
+
min: hMin,
|
|
263
|
+
max: hMax,
|
|
262
264
|
},
|
|
263
265
|
s: {
|
|
264
266
|
enable: false,
|
|
265
267
|
value: hsl.s,
|
|
268
|
+
min: sMin,
|
|
269
|
+
max: sMax,
|
|
266
270
|
},
|
|
267
271
|
l: {
|
|
268
272
|
enable: false,
|
|
269
273
|
value: hsl.l,
|
|
274
|
+
min: lMin,
|
|
275
|
+
max: lMax,
|
|
270
276
|
},
|
|
271
277
|
};
|
|
272
278
|
if (animationOptions) {
|
|
@@ -278,6 +284,8 @@ export function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
|
278
284
|
}
|
|
279
285
|
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
280
286
|
colorValue.enable = colorAnimation.enable;
|
|
287
|
+
colorValue.min = colorAnimation.min;
|
|
288
|
+
colorValue.max = colorAnimation.max;
|
|
281
289
|
if (colorValue.enable) {
|
|
282
290
|
colorValue.velocity = (getRangeValue(colorAnimation.speed) / percentDenominator) * reduceFactor;
|
|
283
291
|
colorValue.decay = decayOffset - getRangeValue(colorAnimation.decay);
|
|
@@ -297,7 +305,7 @@ function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
|
297
305
|
colorValue.velocity = defaultVelocity;
|
|
298
306
|
}
|
|
299
307
|
}
|
|
300
|
-
export function updateColorValue(data,
|
|
308
|
+
export function updateColorValue(data, decrease, delta) {
|
|
301
309
|
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
|
|
302
310
|
if (!data.enable ||
|
|
303
311
|
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
|
|
@@ -310,7 +318,7 @@ export function updateColorValue(data, range, decrease, delta) {
|
|
|
310
318
|
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
311
319
|
return;
|
|
312
320
|
}
|
|
313
|
-
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;
|
|
314
322
|
if (!decrease || data.status === AnimationStatus.increasing) {
|
|
315
323
|
data.value += velocity;
|
|
316
324
|
if (data.value > max) {
|
|
@@ -326,8 +334,7 @@ export function updateColorValue(data, range, decrease, delta) {
|
|
|
326
334
|
}
|
|
327
335
|
else {
|
|
328
336
|
data.value -= velocity;
|
|
329
|
-
|
|
330
|
-
if (data.value < minValue) {
|
|
337
|
+
if (data.value < min) {
|
|
331
338
|
data.loops ??= 0;
|
|
332
339
|
data.loops++;
|
|
333
340
|
data.status = AnimationStatus.increasing;
|
|
@@ -342,14 +349,10 @@ export function updateColor(color, delta) {
|
|
|
342
349
|
if (!color) {
|
|
343
350
|
return;
|
|
344
351
|
}
|
|
345
|
-
const { h, s, l } = color
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
};
|
|
350
|
-
updateColorValue(h, ranges.h, false, delta);
|
|
351
|
-
updateColorValue(s, ranges.s, true, delta);
|
|
352
|
-
updateColorValue(l, ranges.l, true, delta);
|
|
352
|
+
const { h, s, l } = color;
|
|
353
|
+
updateColorValue(h, false, delta);
|
|
354
|
+
updateColorValue(s, true, delta);
|
|
355
|
+
updateColorValue(l, true, delta);
|
|
353
356
|
}
|
|
354
357
|
export function alterHsl(color, type, value) {
|
|
355
358
|
return {
|