@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/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
|
};
|
|
@@ -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/cjs/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 {
|
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
|
@@ -8,16 +8,70 @@ import { OutModeDirection } from "../Enums/Directions/OutModeDirection.js";
|
|
|
8
8
|
import { PixelMode } from "../Enums/Modes/PixelMode.js";
|
|
9
9
|
import { StartValueType } from "../Enums/Types/StartValueType.js";
|
|
10
10
|
import { Vector } from "../Core/Utils/Vectors.js";
|
|
11
|
-
const minRadius = 0;
|
|
12
|
-
function memoize(fn) {
|
|
13
|
-
const cache = new Map()
|
|
11
|
+
const minRadius = 0, minMemoizeSize = 0;
|
|
12
|
+
export function memoize(fn, options) {
|
|
13
|
+
const cache = new Map(), maxSize = options?.maxSize, ttlMs = options?.ttlMs, keyFn = options?.keyFn, stableStringify = (obj, seen = new WeakSet()) => {
|
|
14
|
+
if (obj === null) {
|
|
15
|
+
return "null";
|
|
16
|
+
}
|
|
17
|
+
const t = typeof obj;
|
|
18
|
+
if (t === "undefined") {
|
|
19
|
+
return "undefined";
|
|
20
|
+
}
|
|
21
|
+
if (t === "number" || t === "boolean" || t === "string") {
|
|
22
|
+
return JSON.stringify(obj);
|
|
23
|
+
}
|
|
24
|
+
if (t === "function") {
|
|
25
|
+
try {
|
|
26
|
+
const fn = obj;
|
|
27
|
+
return fn.toString();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return '"[Function]"';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (t === "symbol") {
|
|
34
|
+
try {
|
|
35
|
+
return obj.toString();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return '"[Symbol]"';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
return `[${obj.map(i => stableStringify(i, seen)).join(",")}]`;
|
|
43
|
+
}
|
|
44
|
+
if (seen.has(obj)) {
|
|
45
|
+
return '"[Circular]"';
|
|
46
|
+
}
|
|
47
|
+
seen.add(obj);
|
|
48
|
+
const keys = Object.keys(obj).sort();
|
|
49
|
+
return `{${keys.map(k => `${JSON.stringify(k)}:${stableStringify(obj[k], seen)}`).join(",")}}`;
|
|
50
|
+
}, defaultKeyer = (args) => stableStringify(args), makeKey = (args) => (keyFn ? keyFn(args) : defaultKeyer(args)), ensureBounds = () => {
|
|
51
|
+
if (typeof maxSize === "number" && maxSize >= minMemoizeSize) {
|
|
52
|
+
while (cache.size > maxSize) {
|
|
53
|
+
const firstKey = cache.keys().next().value;
|
|
54
|
+
if (firstKey === undefined)
|
|
55
|
+
break;
|
|
56
|
+
cache.delete(firstKey);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
14
60
|
return (...args) => {
|
|
15
|
-
const key =
|
|
16
|
-
if (
|
|
17
|
-
|
|
61
|
+
const key = makeKey(args), now = Date.now(), entry = cache.get(key);
|
|
62
|
+
if (entry !== undefined) {
|
|
63
|
+
if (ttlMs && now - entry.ts > ttlMs) {
|
|
64
|
+
cache.delete(key);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
cache.delete(key);
|
|
68
|
+
cache.set(key, { value: entry.value, ts: entry.ts });
|
|
69
|
+
return entry.value;
|
|
70
|
+
}
|
|
18
71
|
}
|
|
19
72
|
const result = fn(...args);
|
|
20
|
-
cache.set(key, result);
|
|
73
|
+
cache.set(key, { value: result, ts: now });
|
|
74
|
+
ensureBounds();
|
|
21
75
|
return result;
|
|
22
76
|
};
|
|
23
77
|
}
|
|
@@ -83,33 +137,48 @@ export function calculateBounds(point, radius) {
|
|
|
83
137
|
}
|
|
84
138
|
export function deepExtend(destination, ...sources) {
|
|
85
139
|
for (const source of sources) {
|
|
86
|
-
if (source
|
|
140
|
+
if (isNull(source)) {
|
|
87
141
|
continue;
|
|
88
142
|
}
|
|
89
143
|
if (!isObject(source)) {
|
|
90
144
|
destination = source;
|
|
91
145
|
continue;
|
|
92
146
|
}
|
|
93
|
-
|
|
94
|
-
if (sourceIsArray) {
|
|
147
|
+
if (Array.isArray(source)) {
|
|
95
148
|
if (!Array.isArray(destination)) {
|
|
96
149
|
destination = [];
|
|
97
150
|
}
|
|
98
151
|
}
|
|
99
|
-
else {
|
|
100
|
-
|
|
101
|
-
|
|
152
|
+
else if (!isObject(destination) || Array.isArray(destination)) {
|
|
153
|
+
destination = {};
|
|
154
|
+
}
|
|
155
|
+
const sourceKeys = Object.keys(source), dangerousKeys = new Set(["__proto__", "constructor", "prototype"]), hasNested = sourceKeys.some(k => {
|
|
156
|
+
const v = source[k];
|
|
157
|
+
return isObject(v) || Array.isArray(v);
|
|
158
|
+
});
|
|
159
|
+
if (!hasNested) {
|
|
160
|
+
const sourceDict = source, destDict = destination;
|
|
161
|
+
for (const key of sourceKeys) {
|
|
162
|
+
if (dangerousKeys.has(key)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (key in sourceDict) {
|
|
166
|
+
const v = sourceDict[key];
|
|
167
|
+
if (v !== undefined) {
|
|
168
|
+
destDict[key] = v;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
102
171
|
}
|
|
172
|
+
continue;
|
|
103
173
|
}
|
|
104
|
-
for (const key
|
|
105
|
-
if (key
|
|
174
|
+
for (const key of sourceKeys) {
|
|
175
|
+
if (dangerousKeys.has(key)) {
|
|
106
176
|
continue;
|
|
107
177
|
}
|
|
108
|
-
const sourceDict = source, value = sourceDict[key]
|
|
109
|
-
destDict[key] =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
: deepExtend(destDict[key], value);
|
|
178
|
+
const sourceDict = source, destDict = destination, value = sourceDict[key];
|
|
179
|
+
destDict[key] = Array.isArray(value)
|
|
180
|
+
? value.map(v => deepExtend(undefined, v))
|
|
181
|
+
: deepExtend(destDict[key], value);
|
|
113
182
|
}
|
|
114
183
|
}
|
|
115
184
|
return destination;
|
|
@@ -301,7 +370,7 @@ export function cloneStyle(style) {
|
|
|
301
370
|
const clonedStyle = safeDocument().createElement("div").style;
|
|
302
371
|
for (const key in style) {
|
|
303
372
|
const styleKey = style[key];
|
|
304
|
-
if (!
|
|
373
|
+
if (!(key in style) || isNull(styleKey)) {
|
|
305
374
|
continue;
|
|
306
375
|
}
|
|
307
376
|
const styleValue = style.getPropertyValue?.(styleKey);
|
|
@@ -309,11 +378,11 @@ export function cloneStyle(style) {
|
|
|
309
378
|
continue;
|
|
310
379
|
}
|
|
311
380
|
const stylePriority = style.getPropertyPriority?.(styleKey);
|
|
312
|
-
if (
|
|
313
|
-
clonedStyle.setProperty(styleKey, styleValue);
|
|
381
|
+
if (stylePriority) {
|
|
382
|
+
clonedStyle.setProperty(styleKey, styleValue, stylePriority);
|
|
314
383
|
}
|
|
315
384
|
else {
|
|
316
|
-
clonedStyle.setProperty(styleKey, styleValue
|
|
385
|
+
clonedStyle.setProperty(styleKey, styleValue);
|
|
317
386
|
}
|
|
318
387
|
}
|
|
319
388
|
return clonedStyle;
|
package/cjs/exports.js
CHANGED
|
@@ -27,8 +27,8 @@ export * from "./Options/Classes/OptionsColor.js";
|
|
|
27
27
|
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
|
+
export * from "./Options/Classes/Particles/Fill.js";
|
|
30
31
|
export * from "./Options/Classes/Particles/Stroke.js";
|
|
31
|
-
export * from "./Options/Classes/Particles/Move/MoveAttract.js";
|
|
32
32
|
export * from "./Options/Classes/Particles/Move/Move.js";
|
|
33
33
|
export * from "./Options/Classes/Particles/Move/MoveAngle.js";
|
|
34
34
|
export * from "./Options/Classes/Particles/Move/MoveCenter.js";
|