@tsparticles/engine 4.0.0-alpha.25 → 4.0.0-alpha.26
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/622.min.js +1 -0
- package/README.md +2 -2
- package/browser/Core/Engine.js +1 -18
- package/browser/Core/Particle.js +2 -23
- package/browser/Core/Particles.js +0 -23
- package/browser/Core/Utils/Ranges.js +2 -2
- package/browser/Core/Utils/Vectors.js +10 -7
- package/browser/Options/Classes/Particles/Move/Move.js +0 -4
- package/browser/Utils/CanvasUtils.js +29 -32
- package/browser/Utils/MathUtils.js +8 -1
- package/browser/Utils/Utils.js +10 -14
- package/browser/exports.js +0 -1
- package/cjs/Core/Engine.js +1 -18
- package/cjs/Core/Particle.js +2 -23
- package/cjs/Core/Particles.js +0 -23
- package/cjs/Core/Utils/Ranges.js +2 -2
- package/cjs/Core/Utils/Vectors.js +10 -7
- package/cjs/Options/Classes/Particles/Move/Move.js +0 -4
- package/cjs/Utils/CanvasUtils.js +29 -32
- package/cjs/Utils/MathUtils.js +8 -1
- package/cjs/Utils/Utils.js +10 -14
- package/cjs/exports.js +0 -1
- package/dist_browser_Core_Container_js.js +3 -3
- package/esm/Core/Engine.js +1 -18
- package/esm/Core/Particle.js +2 -23
- package/esm/Core/Particles.js +0 -23
- package/esm/Core/Utils/Ranges.js +2 -2
- package/esm/Core/Utils/Vectors.js +10 -7
- package/esm/Options/Classes/Particles/Move/Move.js +0 -4
- package/esm/Utils/CanvasUtils.js +29 -32
- package/esm/Utils/MathUtils.js +8 -1
- package/esm/Utils/Utils.js +10 -14
- package/esm/exports.js +0 -1
- package/package.json +1 -1
- package/report.html +1 -1
- package/scripts/install.js +2 -2
- package/tsparticles.engine.js +10 -20
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/Engine.d.ts +1 -9
- package/types/Core/Particle.d.ts +0 -4
- package/types/Core/Particles.d.ts +0 -5
- package/types/Core/Utils/Vectors.d.ts +6 -6
- package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
- package/types/Types/EngineInitializers.d.ts +0 -6
- package/types/Utils/CanvasUtils.d.ts +6 -7
- package/types/Utils/MathUtils.d.ts +2 -0
- package/types/export-types.d.ts +0 -3
- package/types/exports.d.ts +0 -1
- package/umd/Core/Engine.js +1 -18
- package/umd/Core/Particle.js +3 -24
- package/umd/Core/Particles.js +0 -23
- package/umd/Core/Utils/Ranges.js +1 -1
- package/umd/Core/Utils/Vectors.js +10 -7
- package/umd/Options/Classes/Particles/Move/Move.js +1 -5
- package/umd/Utils/CanvasUtils.js +29 -32
- package/umd/Utils/MathUtils.js +10 -1
- package/umd/Utils/Utils.js +10 -14
- package/umd/exports.js +1 -2
- package/152.min.js +0 -1
- package/browser/Core/Interfaces/IMovePathGenerator.js +0 -1
- package/browser/Core/Interfaces/IParticleMover.js +0 -1
- package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/browser/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- package/cjs/Core/Interfaces/IMovePathGenerator.js +0 -1
- package/cjs/Core/Interfaces/IParticleMover.js +0 -1
- package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -36
- package/cjs/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
- 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/Core/Interfaces/IMovePathGenerator.js +0 -12
- package/umd/Core/Interfaces/IParticleMover.js +0 -12
- package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -50
- package/umd/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -12
package/cjs/Core/Particle.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Vector, Vector3d } from "./Utils/Vectors.js";
|
|
2
2
|
import { alterHsl, getHslFromAnimation } from "../Utils/ColorUtils.js";
|
|
3
3
|
import { calcExactPositionOrRandomFromSize, clamp, degToRad, getParticleBaseVelocity, getParticleDirectionAngle, getRandom, getRangeValue, randomInRangeValue, setRangeValue, } from "../Utils/MathUtils.js";
|
|
4
|
-
import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, doublePI, half, identity, millisecondsToSeconds, minZ, randomColorValue, squareExp, triple, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
5
4
|
import { deepExtend, getPosition, initParticleNumericAnimationValue, isInArray, itemFromSingleOrMultiple, } from "../Utils/Utils.js";
|
|
5
|
+
import { defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, doublePI, half, identity, minZ, randomColorValue, squareExp, triple, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
6
6
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
7
7
|
import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
|
|
8
8
|
import { OutMode } from "../Enums/Modes/OutMode.js";
|
|
@@ -54,13 +54,10 @@ export class Particle {
|
|
|
54
54
|
lastPathTime;
|
|
55
55
|
misplaced;
|
|
56
56
|
moveCenter;
|
|
57
|
-
moveDecay;
|
|
58
57
|
offset;
|
|
59
58
|
opacity;
|
|
60
59
|
options;
|
|
61
60
|
outType;
|
|
62
|
-
pathDelay;
|
|
63
|
-
pathGenerator;
|
|
64
61
|
pathRotation;
|
|
65
62
|
position;
|
|
66
63
|
randomIndexData;
|
|
@@ -105,7 +102,7 @@ export class Particle {
|
|
|
105
102
|
this.destroyed = true;
|
|
106
103
|
this.bubble.inRange = false;
|
|
107
104
|
this.slow.inRange = false;
|
|
108
|
-
const container = this.container,
|
|
105
|
+
const container = this.container, shapeDrawer = this.shape ? container.particles.shapeDrawers.get(this.shape) : undefined;
|
|
109
106
|
shapeDrawer?.particleDestroy?.(this);
|
|
110
107
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
111
108
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -113,7 +110,6 @@ export class Particle {
|
|
|
113
110
|
for (const updater of container.particles.updaters) {
|
|
114
111
|
updater.particleDestroyed?.(this, override);
|
|
115
112
|
}
|
|
116
|
-
pathGenerator?.reset(this);
|
|
117
113
|
this._engine.dispatchEvent(EventType.particleDestroyed, {
|
|
118
114
|
container: this.container,
|
|
119
115
|
data: {
|
|
@@ -235,19 +231,6 @@ export class Particle {
|
|
|
235
231
|
this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
|
|
236
232
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
237
233
|
this.options = particlesOptions;
|
|
238
|
-
const pathOptions = this.options.move.path;
|
|
239
|
-
this.pathDelay = getRangeValue(pathOptions.delay.value) * millisecondsToSeconds;
|
|
240
|
-
if (pathOptions.generator) {
|
|
241
|
-
let pathGenerator = this.container.particles.pathGenerators.get(pathOptions.generator);
|
|
242
|
-
if (!pathGenerator) {
|
|
243
|
-
pathGenerator = this.container.particles.availablePathGenerators.get(pathOptions.generator);
|
|
244
|
-
if (pathGenerator) {
|
|
245
|
-
this.container.particles.pathGenerators.set(pathOptions.generator, pathGenerator);
|
|
246
|
-
pathGenerator.init();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
this.pathGenerator = pathGenerator;
|
|
250
|
-
}
|
|
251
234
|
container.retina.initParticle(this);
|
|
252
235
|
this.size = initParticleNumericAnimationValue(this.options.size, pxRatio);
|
|
253
236
|
this.bubble = {
|
|
@@ -260,7 +243,6 @@ export class Particle {
|
|
|
260
243
|
this._initPosition(position);
|
|
261
244
|
this.initialVelocity = this._calculateVelocity();
|
|
262
245
|
this.velocity = this.initialVelocity.copy();
|
|
263
|
-
this.moveDecay = decayOffset - getRangeValue(this.options.move.decay);
|
|
264
246
|
const particles = container.particles;
|
|
265
247
|
particles.setLastZIndex(this.position.z);
|
|
266
248
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
@@ -286,9 +268,6 @@ export class Particle {
|
|
|
286
268
|
for (const updater of particles.updaters) {
|
|
287
269
|
updater.init(this);
|
|
288
270
|
}
|
|
289
|
-
for (const mover of particles.movers) {
|
|
290
|
-
mover.init(this);
|
|
291
|
-
}
|
|
292
271
|
effectDrawer?.particleInit?.(container, this);
|
|
293
272
|
shapeDrawer?.particleInit?.(container, this);
|
|
294
273
|
for (const plugin of container.particleCreatedPlugins) {
|
package/cjs/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;
|
package/cjs/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;
|
|
@@ -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);
|
package/cjs/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
|
};
|
|
@@ -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, particle, stroke } = data;
|
|
83
|
+
if (!particle.shape) {
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
context.beginPath();
|
|
@@ -96,26 +95,24 @@ export function drawShape(container, data) {
|
|
|
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/cjs/Utils/MathUtils.js
CHANGED
|
@@ -69,8 +69,15 @@ export function getDistances(pointA, pointB) {
|
|
|
69
69
|
const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
|
|
70
70
|
return { dx: dx, dy: dy, distance: Math.hypot(dx, dy) };
|
|
71
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;
|
|
75
|
+
}
|
|
72
76
|
export function getDistance(pointA, pointB) {
|
|
73
|
-
return
|
|
77
|
+
return Math.sqrt(getDistanceSq(pointA, pointB));
|
|
78
|
+
}
|
|
79
|
+
export function checkDistance(pointA, pointB, distance) {
|
|
80
|
+
return getDistanceSq(pointA, pointB) <= distance * distance;
|
|
74
81
|
}
|
|
75
82
|
export function degToRad(degrees) {
|
|
76
83
|
return degrees * degToRadFactor;
|
package/cjs/Utils/Utils.js
CHANGED
|
@@ -83,33 +83,29 @@ export function calculateBounds(point, radius) {
|
|
|
83
83
|
}
|
|
84
84
|
export function deepExtend(destination, ...sources) {
|
|
85
85
|
for (const source of sources) {
|
|
86
|
-
if (source
|
|
86
|
+
if (isNull(source)) {
|
|
87
87
|
continue;
|
|
88
88
|
}
|
|
89
89
|
if (!isObject(source)) {
|
|
90
90
|
destination = source;
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
if (sourceIsArray) {
|
|
93
|
+
if (Array.isArray(source)) {
|
|
95
94
|
if (!Array.isArray(destination)) {
|
|
96
95
|
destination = [];
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
|
-
else {
|
|
100
|
-
|
|
101
|
-
destination = {};
|
|
102
|
-
}
|
|
98
|
+
else if (!isObject(destination) || Array.isArray(destination)) {
|
|
99
|
+
destination = {};
|
|
103
100
|
}
|
|
104
|
-
for (const key
|
|
105
|
-
if (key === "__proto__") {
|
|
101
|
+
for (const key of Object.keys(source)) {
|
|
102
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
106
103
|
continue;
|
|
107
104
|
}
|
|
108
|
-
const sourceDict = source, value = sourceDict[key]
|
|
109
|
-
destDict[key] =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
: deepExtend(destDict[key], value);
|
|
105
|
+
const sourceDict = source, destDict = destination, value = sourceDict[key];
|
|
106
|
+
destDict[key] = Array.isArray(value)
|
|
107
|
+
? value.map(v => deepExtend(undefined, v))
|
|
108
|
+
: deepExtend(destDict[key], value);
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
return destination;
|
package/cjs/exports.js
CHANGED
|
@@ -28,7 +28,6 @@ export * from "./Options/Classes/Particles/Bounce/ParticlesBounce.js";
|
|
|
28
28
|
export * from "./Options/Classes/Particles/Bounce/ParticlesBounceFactor.js";
|
|
29
29
|
export * from "./Options/Classes/Particles/ParticlesOptions.js";
|
|
30
30
|
export * from "./Options/Classes/Particles/Stroke.js";
|
|
31
|
-
export * from "./Options/Classes/Particles/Move/MoveAttract.js";
|
|
32
31
|
export * from "./Options/Classes/Particles/Move/Move.js";
|
|
33
32
|
export * from "./Options/Classes/Particles/Move/MoveAngle.js";
|
|
34
33
|
export * from "./Options/Classes/Particles/Move/MoveCenter.js";
|