@tsparticles/engine 3.6.0 → 3.7.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/README.md +6 -1
- package/browser/Core/Canvas.js +37 -21
- package/browser/Core/Container.js +1 -1
- package/browser/Core/Engine.js +17 -1
- package/browser/Core/Particle.js +1 -1
- package/browser/Types/EasingFunction.js +1 -0
- package/browser/Utils/ColorUtils.js +25 -45
- package/browser/Utils/NumberUtils.js +1 -10
- package/browser/Utils/Utils.js +6 -0
- package/browser/exports.js +0 -2
- package/browser/init.js +0 -6
- package/cjs/Core/Canvas.js +37 -21
- package/cjs/Core/Container.js +1 -1
- package/cjs/Core/Engine.js +17 -1
- package/cjs/Core/Particle.js +1 -1
- package/cjs/Types/EasingFunction.js +2 -0
- package/cjs/Utils/ColorUtils.js +25 -46
- package/cjs/Utils/NumberUtils.js +1 -12
- package/cjs/Utils/Utils.js +7 -0
- package/cjs/exports.js +0 -2
- package/cjs/init.js +0 -6
- package/esm/Core/Canvas.js +37 -21
- package/esm/Core/Container.js +1 -1
- package/esm/Core/Engine.js +17 -1
- package/esm/Core/Particle.js +1 -1
- package/esm/Types/EasingFunction.js +1 -0
- package/esm/Utils/ColorUtils.js +25 -45
- package/esm/Utils/NumberUtils.js +1 -10
- package/esm/Utils/Utils.js +6 -0
- package/esm/exports.js +0 -2
- package/esm/init.js +0 -6
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +11 -31
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +4 -1
- package/types/Core/Engine.d.ts +9 -1
- package/types/Types/EasingFunction.d.ts +1 -0
- package/types/Utils/ColorUtils.d.ts +8 -9
- package/types/Utils/NumberUtils.d.ts +0 -5
- package/types/Utils/Utils.d.ts +2 -0
- package/types/exports.d.ts +0 -2
- package/umd/Core/Canvas.js +37 -21
- package/umd/Core/Container.js +1 -1
- package/umd/Core/Engine.js +17 -1
- package/umd/Core/Particle.js +1 -1
- package/umd/Types/EasingFunction.js +12 -0
- package/umd/Utils/ColorUtils.js +25 -46
- package/umd/Utils/NumberUtils.js +1 -12
- package/umd/Utils/Utils.js +7 -0
- package/umd/exports.js +1 -3
- package/umd/init.js +1 -7
- package/browser/Utils/HslColorManager.js +0 -45
- package/browser/Utils/RgbColorManager.js +0 -44
- package/cjs/Utils/HslColorManager.js +0 -49
- package/cjs/Utils/RgbColorManager.js +0 -48
- package/esm/Utils/HslColorManager.js +0 -45
- package/esm/Utils/RgbColorManager.js +0 -44
- package/types/Utils/HslColorManager.d.ts +0 -10
- package/types/Utils/RgbColorManager.d.ts +0 -10
- package/umd/Utils/HslColorManager.js +0 -59
- package/umd/Utils/RgbColorManager.js +0 -58
package/cjs/Utils/ColorUtils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addColorManager = addColorManager;
|
|
4
3
|
exports.rangeColorToRgb = rangeColorToRgb;
|
|
5
4
|
exports.colorToRgb = colorToRgb;
|
|
6
5
|
exports.colorToHsl = colorToHsl;
|
|
@@ -25,83 +24,63 @@ const TypeUtils_js_1 = require("./TypeUtils.js");
|
|
|
25
24
|
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
26
25
|
const AnimationStatus_js_1 = require("../Enums/AnimationStatus.js");
|
|
27
26
|
const Utils_js_1 = require("./Utils.js");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})(RgbIndexes || (RgbIndexes = {}));
|
|
35
|
-
const randomColorValue = "random", midColorValue = "mid", colorManagers = new Map();
|
|
36
|
-
function addColorManager(manager) {
|
|
37
|
-
colorManagers.set(manager.key, manager);
|
|
38
|
-
}
|
|
39
|
-
function stringToRgba(input) {
|
|
40
|
-
for (const manager of colorManagers.values()) {
|
|
27
|
+
const randomColorValue = "random", midColorValue = "mid";
|
|
28
|
+
function stringToRgba(engine, input) {
|
|
29
|
+
if (!input) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
for (const manager of engine.colorManagers.values()) {
|
|
41
33
|
if (input.startsWith(manager.stringPrefix)) {
|
|
42
34
|
return manager.parseString(input);
|
|
43
35
|
}
|
|
44
36
|
}
|
|
45
|
-
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexFixed = input.replace(shorthandRegex, (_, r, g, b, a) => {
|
|
46
|
-
return r + r + g + g + b + b + (a !== undefined ? a + a : "");
|
|
47
|
-
}), regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, result = regex.exec(hexFixed), radix = 16, defaultAlpha = 1, alphaFactor = 0xff;
|
|
48
|
-
return result
|
|
49
|
-
? {
|
|
50
|
-
a: result[RgbIndexes.a] !== undefined
|
|
51
|
-
? parseInt(result[RgbIndexes.a], radix) / alphaFactor
|
|
52
|
-
: defaultAlpha,
|
|
53
|
-
b: parseInt(result[RgbIndexes.b], radix),
|
|
54
|
-
g: parseInt(result[RgbIndexes.g], radix),
|
|
55
|
-
r: parseInt(result[RgbIndexes.r], radix),
|
|
56
|
-
}
|
|
57
|
-
: undefined;
|
|
58
37
|
}
|
|
59
|
-
function rangeColorToRgb(input, index, useIndex = true) {
|
|
38
|
+
function rangeColorToRgb(engine, input, index, useIndex = true) {
|
|
60
39
|
if (!input) {
|
|
61
40
|
return;
|
|
62
41
|
}
|
|
63
42
|
const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
|
|
64
43
|
if ((0, TypeUtils_js_1.isString)(color.value)) {
|
|
65
|
-
return colorToRgb(color.value, index, useIndex);
|
|
44
|
+
return colorToRgb(engine, color.value, index, useIndex);
|
|
66
45
|
}
|
|
67
46
|
if ((0, TypeUtils_js_1.isArray)(color.value)) {
|
|
68
|
-
return rangeColorToRgb({
|
|
47
|
+
return rangeColorToRgb(engine, {
|
|
69
48
|
value: (0, Utils_js_1.itemFromArray)(color.value, index, useIndex),
|
|
70
49
|
});
|
|
71
50
|
}
|
|
72
|
-
for (const manager of colorManagers.values()) {
|
|
51
|
+
for (const manager of engine.colorManagers.values()) {
|
|
73
52
|
const res = manager.handleRangeColor(color);
|
|
74
53
|
if (res) {
|
|
75
54
|
return res;
|
|
76
55
|
}
|
|
77
56
|
}
|
|
78
57
|
}
|
|
79
|
-
function colorToRgb(input, index, useIndex = true) {
|
|
58
|
+
function colorToRgb(engine, input, index, useIndex = true) {
|
|
80
59
|
if (!input) {
|
|
81
60
|
return;
|
|
82
61
|
}
|
|
83
62
|
const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
|
|
84
63
|
if ((0, TypeUtils_js_1.isString)(color.value)) {
|
|
85
|
-
return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(color.value);
|
|
64
|
+
return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(engine, color.value);
|
|
86
65
|
}
|
|
87
66
|
if ((0, TypeUtils_js_1.isArray)(color.value)) {
|
|
88
|
-
return colorToRgb({
|
|
67
|
+
return colorToRgb(engine, {
|
|
89
68
|
value: (0, Utils_js_1.itemFromArray)(color.value, index, useIndex),
|
|
90
69
|
});
|
|
91
70
|
}
|
|
92
|
-
for (const manager of colorManagers.values()) {
|
|
71
|
+
for (const manager of engine.colorManagers.values()) {
|
|
93
72
|
const res = manager.handleColor(color);
|
|
94
73
|
if (res) {
|
|
95
74
|
return res;
|
|
96
75
|
}
|
|
97
76
|
}
|
|
98
77
|
}
|
|
99
|
-
function colorToHsl(color, index, useIndex = true) {
|
|
100
|
-
const rgb = colorToRgb(color, index, useIndex);
|
|
78
|
+
function colorToHsl(engine, color, index, useIndex = true) {
|
|
79
|
+
const rgb = colorToRgb(engine, color, index, useIndex);
|
|
101
80
|
return rgb ? rgbToHsl(rgb) : undefined;
|
|
102
81
|
}
|
|
103
|
-
function rangeColorToHsl(color, index, useIndex = true) {
|
|
104
|
-
const rgb = rangeColorToRgb(color, index, useIndex);
|
|
82
|
+
function rangeColorToHsl(engine, color, index, useIndex = true) {
|
|
83
|
+
const rgb = rangeColorToRgb(engine, color, index, useIndex);
|
|
105
84
|
return rgb ? rgbToHsl(rgb) : undefined;
|
|
106
85
|
}
|
|
107
86
|
function rgbToHsl(color) {
|
|
@@ -128,11 +107,11 @@ function rgbToHsl(color) {
|
|
|
128
107
|
}
|
|
129
108
|
return res;
|
|
130
109
|
}
|
|
131
|
-
function stringToAlpha(input) {
|
|
132
|
-
return stringToRgba(input)?.a;
|
|
110
|
+
function stringToAlpha(engine, input) {
|
|
111
|
+
return stringToRgba(engine, input)?.a;
|
|
133
112
|
}
|
|
134
|
-
function stringToRgb(input) {
|
|
135
|
-
return stringToRgba(input);
|
|
113
|
+
function stringToRgb(engine, input) {
|
|
114
|
+
return stringToRgba(engine, input);
|
|
136
115
|
}
|
|
137
116
|
function hslToRgb(hsl) {
|
|
138
117
|
const hMax = 360, sMax = 100, lMax = 100, sMin = 0, lMin = 0, 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, rgbFactor = 255, triple = 3;
|
|
@@ -223,11 +202,11 @@ function getLinkColor(p1, p2, linkColor) {
|
|
|
223
202
|
return linkColor;
|
|
224
203
|
}
|
|
225
204
|
}
|
|
226
|
-
function getLinkRandomColor(optColor, blink, consent) {
|
|
205
|
+
function getLinkRandomColor(engine, optColor, blink, consent) {
|
|
227
206
|
const color = (0, TypeUtils_js_1.isString)(optColor) ? optColor : optColor.value;
|
|
228
207
|
if (color === randomColorValue) {
|
|
229
208
|
if (consent) {
|
|
230
|
-
return rangeColorToRgb({
|
|
209
|
+
return rangeColorToRgb(engine, {
|
|
231
210
|
value: color,
|
|
232
211
|
});
|
|
233
212
|
}
|
|
@@ -240,7 +219,7 @@ function getLinkRandomColor(optColor, blink, consent) {
|
|
|
240
219
|
return midColorValue;
|
|
241
220
|
}
|
|
242
221
|
else {
|
|
243
|
-
return rangeColorToRgb({
|
|
222
|
+
return rangeColorToRgb(engine, {
|
|
244
223
|
value: color,
|
|
245
224
|
});
|
|
246
225
|
}
|
package/cjs/Utils/NumberUtils.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addEasing = addEasing;
|
|
4
|
-
exports.getEasing = getEasing;
|
|
5
3
|
exports.setRandom = setRandom;
|
|
6
4
|
exports.getRandom = getRandom;
|
|
7
5
|
exports.setAnimationFunctions = setAnimationFunctions;
|
|
@@ -34,16 +32,7 @@ let _random = Math.random;
|
|
|
34
32
|
const _animationLoop = {
|
|
35
33
|
nextFrame: (cb) => requestAnimationFrame(cb),
|
|
36
34
|
cancel: (idx) => cancelAnimationFrame(idx),
|
|
37
|
-
},
|
|
38
|
-
function addEasing(name, easing) {
|
|
39
|
-
if (easingFunctions.get(name)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
easingFunctions.set(name, easing);
|
|
43
|
-
}
|
|
44
|
-
function getEasing(name) {
|
|
45
|
-
return easingFunctions.get(name) ?? ((value) => value);
|
|
46
|
-
}
|
|
35
|
+
}, double = 2, doublePI = Math.PI * double;
|
|
47
36
|
function setRandom(rnd = Math.random) {
|
|
48
37
|
_random = rnd;
|
|
49
38
|
}
|
package/cjs/Utils/Utils.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.initParticleNumericAnimationValue = initParticleNumericAnimationValue;
|
|
|
29
29
|
exports.getPosition = getPosition;
|
|
30
30
|
exports.getSize = getSize;
|
|
31
31
|
exports.updateAnimation = updateAnimation;
|
|
32
|
+
exports.assertValidVersion = assertValidVersion;
|
|
32
33
|
const NumberUtils_js_1 = require("./NumberUtils.js");
|
|
33
34
|
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
34
35
|
const TypeUtils_js_1 = require("./TypeUtils.js");
|
|
@@ -445,3 +446,9 @@ function updateAnimation(particle, data, changeDirection, destroyType, delta) {
|
|
|
445
446
|
data.value = (0, NumberUtils_js_1.clamp)(data.value, minValue, maxValue);
|
|
446
447
|
}
|
|
447
448
|
}
|
|
449
|
+
function assertValidVersion(engine, pluginVersion) {
|
|
450
|
+
if (engine.version === pluginVersion) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${engine.version}. Plugins version: ${pluginVersion}`);
|
|
454
|
+
}
|
package/cjs/exports.js
CHANGED
|
@@ -94,9 +94,7 @@ __exportStar(require("./Options/Classes/Theme/ThemeDefault.js"), exports);
|
|
|
94
94
|
__exportStar(require("./Options/Classes/ValueWithRandom.js"), exports);
|
|
95
95
|
__exportStar(require("./Utils/CanvasUtils.js"), exports);
|
|
96
96
|
__exportStar(require("./Utils/ColorUtils.js"), exports);
|
|
97
|
-
__exportStar(require("./Utils/HslColorManager.js"), exports);
|
|
98
97
|
__exportStar(require("./Utils/NumberUtils.js"), exports);
|
|
99
98
|
__exportStar(require("./Utils/OptionsUtils.js"), exports);
|
|
100
|
-
__exportStar(require("./Utils/RgbColorManager.js"), exports);
|
|
101
99
|
__exportStar(require("./Utils/Utils.js"), exports);
|
|
102
100
|
__exportStar(require("./Utils/TypeUtils.js"), exports);
|
package/cjs/init.js
CHANGED
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
4
|
const Engine_js_1 = require("./Core/Engine.js");
|
|
5
|
-
const HslColorManager_js_1 = require("./Utils/HslColorManager.js");
|
|
6
|
-
const RgbColorManager_js_1 = require("./Utils/RgbColorManager.js");
|
|
7
|
-
const ColorUtils_js_1 = require("./Utils/ColorUtils.js");
|
|
8
5
|
function init() {
|
|
9
|
-
const rgbColorManager = new RgbColorManager_js_1.RgbColorManager(), hslColorManager = new HslColorManager_js_1.HslColorManager();
|
|
10
|
-
(0, ColorUtils_js_1.addColorManager)(rgbColorManager);
|
|
11
|
-
(0, ColorUtils_js_1.addColorManager)(hslColorManager);
|
|
12
6
|
const engine = new Engine_js_1.Engine();
|
|
13
7
|
engine.init();
|
|
14
8
|
return engine;
|
package/esm/Core/Canvas.js
CHANGED
|
@@ -26,7 +26,7 @@ function setStyle(canvas, style, important = false) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
export class Canvas {
|
|
29
|
-
constructor(container) {
|
|
29
|
+
constructor(container, engine) {
|
|
30
30
|
this.container = container;
|
|
31
31
|
this._applyPostDrawUpdaters = particle => {
|
|
32
32
|
for (const updater of this._postDrawUpdaters) {
|
|
@@ -62,10 +62,10 @@ export class Canvas {
|
|
|
62
62
|
let fColor, sColor;
|
|
63
63
|
for (const plugin of this._colorPlugins) {
|
|
64
64
|
if (!fColor && plugin.particleFillColor) {
|
|
65
|
-
fColor = rangeColorToHsl(plugin.particleFillColor(particle));
|
|
65
|
+
fColor = rangeColorToHsl(this._engine, plugin.particleFillColor(particle));
|
|
66
66
|
}
|
|
67
67
|
if (!sColor && plugin.particleStrokeColor) {
|
|
68
|
-
sColor = rangeColorToHsl(plugin.particleStrokeColor(particle));
|
|
68
|
+
sColor = rangeColorToHsl(this._engine, plugin.particleStrokeColor(particle));
|
|
69
69
|
}
|
|
70
70
|
if (fColor && sColor) {
|
|
71
71
|
break;
|
|
@@ -76,7 +76,7 @@ export class Canvas {
|
|
|
76
76
|
this._initCover = async () => {
|
|
77
77
|
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color;
|
|
78
78
|
if (color) {
|
|
79
|
-
const coverRgb = rangeColorToRgb(color);
|
|
79
|
+
const coverRgb = rangeColorToRgb(this._engine, color);
|
|
80
80
|
if (coverRgb) {
|
|
81
81
|
const coverColor = {
|
|
82
82
|
...coverRgb,
|
|
@@ -135,7 +135,7 @@ export class Canvas {
|
|
|
135
135
|
}
|
|
136
136
|
const factorNumerator = 1, opacity = factorNumerator / trail.length;
|
|
137
137
|
if (trailFill.color) {
|
|
138
|
-
const fillColor = rangeColorToRgb(trailFill.color);
|
|
138
|
+
const fillColor = rangeColorToRgb(this._engine, trailFill.color);
|
|
139
139
|
if (!fillColor) {
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
@@ -216,10 +216,16 @@ export class Canvas {
|
|
|
216
216
|
height: "100%",
|
|
217
217
|
}, true);
|
|
218
218
|
};
|
|
219
|
-
this.
|
|
219
|
+
this._engine = engine;
|
|
220
|
+
this._standardSize = {
|
|
220
221
|
height: 0,
|
|
221
222
|
width: 0,
|
|
222
223
|
};
|
|
224
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
|
|
225
|
+
this.size = {
|
|
226
|
+
height: stdSize.height * pxRatio,
|
|
227
|
+
width: stdSize.width * pxRatio,
|
|
228
|
+
};
|
|
223
229
|
this._context = null;
|
|
224
230
|
this._generated = false;
|
|
225
231
|
this._preDrawUpdaters = [];
|
|
@@ -363,7 +369,7 @@ export class Canvas {
|
|
|
363
369
|
return;
|
|
364
370
|
}
|
|
365
371
|
if (background.color) {
|
|
366
|
-
const color = rangeColorToRgb(background.color);
|
|
372
|
+
const color = rangeColorToRgb(this._engine, background.color);
|
|
367
373
|
elementStyle.backgroundColor = color ? getStyleFromRgb(color, background.opacity) : "";
|
|
368
374
|
}
|
|
369
375
|
else {
|
|
@@ -408,8 +414,12 @@ export class Canvas {
|
|
|
408
414
|
this.element = canvas;
|
|
409
415
|
this.element.ariaHidden = "true";
|
|
410
416
|
this._originalStyle = deepExtend({}, this.element.style);
|
|
411
|
-
|
|
412
|
-
|
|
417
|
+
const standardSize = this._standardSize;
|
|
418
|
+
standardSize.height = canvas.offsetHeight;
|
|
419
|
+
standardSize.width = canvas.offsetWidth;
|
|
420
|
+
const pxRatio = this.container.retina.pixelRatio, retinaSize = this.size;
|
|
421
|
+
canvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
422
|
+
canvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
413
423
|
this._context = this.element.getContext("2d");
|
|
414
424
|
this._safeMutationObserver(obs => {
|
|
415
425
|
if (!this.element || !(this.element instanceof Node)) {
|
|
@@ -444,23 +454,29 @@ export class Canvas {
|
|
|
444
454
|
if (!this.element) {
|
|
445
455
|
return false;
|
|
446
456
|
}
|
|
447
|
-
const container = this.container,
|
|
448
|
-
width: this.element.offsetWidth
|
|
449
|
-
height: this.element.offsetHeight
|
|
457
|
+
const container = this.container, currentSize = container.canvas._standardSize, newSize = {
|
|
458
|
+
width: this.element.offsetWidth,
|
|
459
|
+
height: this.element.offsetHeight,
|
|
460
|
+
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
461
|
+
width: newSize.width * pxRatio,
|
|
462
|
+
height: newSize.height * pxRatio,
|
|
450
463
|
};
|
|
451
|
-
if (newSize.height ===
|
|
452
|
-
newSize.width ===
|
|
453
|
-
|
|
454
|
-
|
|
464
|
+
if (newSize.height === currentSize.height &&
|
|
465
|
+
newSize.width === currentSize.width &&
|
|
466
|
+
retinaSize.height === this.element.height &&
|
|
467
|
+
retinaSize.width === this.element.width) {
|
|
455
468
|
return false;
|
|
456
469
|
}
|
|
457
|
-
const oldSize = { ...
|
|
458
|
-
|
|
459
|
-
|
|
470
|
+
const oldSize = { ...currentSize };
|
|
471
|
+
currentSize.height = newSize.height;
|
|
472
|
+
currentSize.width = newSize.width;
|
|
473
|
+
const canvasSize = this.size;
|
|
474
|
+
this.element.width = canvasSize.width = retinaSize.width;
|
|
475
|
+
this.element.height = canvasSize.height = retinaSize.height;
|
|
460
476
|
if (this.container.started) {
|
|
461
477
|
container.particles.setResizeFactor({
|
|
462
|
-
width:
|
|
463
|
-
height:
|
|
478
|
+
width: currentSize.width / oldSize.width,
|
|
479
|
+
height: currentSize.height / oldSize.height,
|
|
464
480
|
});
|
|
465
481
|
}
|
|
466
482
|
return true;
|
package/esm/Core/Container.js
CHANGED
|
@@ -88,7 +88,7 @@ export class Container {
|
|
|
88
88
|
this._sourceOptions = sourceOptions;
|
|
89
89
|
this._initialSourceOptions = sourceOptions;
|
|
90
90
|
this.retina = new Retina(this);
|
|
91
|
-
this.canvas = new Canvas(this);
|
|
91
|
+
this.canvas = new Canvas(this, this._engine);
|
|
92
92
|
this.particles = new Particles(this._engine, this);
|
|
93
93
|
this.pathGenerators = new Map();
|
|
94
94
|
this.interactivity = {
|
package/esm/Core/Engine.js
CHANGED
|
@@ -71,6 +71,8 @@ export class Engine {
|
|
|
71
71
|
this._eventDispatcher = new EventDispatcher();
|
|
72
72
|
this._initialized = false;
|
|
73
73
|
this.plugins = [];
|
|
74
|
+
this.colorManagers = new Map();
|
|
75
|
+
this.easingFunctions = new Map();
|
|
74
76
|
this._initializers = {
|
|
75
77
|
interactors: new Map(),
|
|
76
78
|
movers: new Map(),
|
|
@@ -95,13 +97,24 @@ export class Engine {
|
|
|
95
97
|
return this._domArray;
|
|
96
98
|
}
|
|
97
99
|
get version() {
|
|
98
|
-
return "3.
|
|
100
|
+
return "3.7.1";
|
|
101
|
+
}
|
|
102
|
+
async addColorManager(manager, refresh = true) {
|
|
103
|
+
this.colorManagers.set(manager.key, manager);
|
|
104
|
+
await this.refresh(refresh);
|
|
99
105
|
}
|
|
100
106
|
addConfig(config) {
|
|
101
107
|
const key = config.key ?? config.name ?? "default";
|
|
102
108
|
this._configs.set(key, config);
|
|
103
109
|
this._eventDispatcher.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
104
110
|
}
|
|
111
|
+
async addEasing(name, easing, refresh = true) {
|
|
112
|
+
if (this.getEasing(name)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.easingFunctions.set(name, easing);
|
|
116
|
+
await this.refresh(refresh);
|
|
117
|
+
}
|
|
105
118
|
async addEffect(effect, drawer, refresh = true) {
|
|
106
119
|
executeOnSingleOrMultiple(effect, type => {
|
|
107
120
|
if (!this.getEffectDrawer(type)) {
|
|
@@ -175,6 +188,9 @@ export class Engine {
|
|
|
175
188
|
}
|
|
176
189
|
return res;
|
|
177
190
|
}
|
|
191
|
+
getEasing(name) {
|
|
192
|
+
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
193
|
+
}
|
|
178
194
|
getEffectDrawer(type) {
|
|
179
195
|
return this.effectDrawers.get(type);
|
|
180
196
|
}
|
package/esm/Core/Particle.js
CHANGED
|
@@ -325,7 +325,7 @@ export class Particle {
|
|
|
325
325
|
this.sides = sideCountFunc(this);
|
|
326
326
|
}
|
|
327
327
|
this.spawning = false;
|
|
328
|
-
this.shadowColor = rangeColorToRgb(this.options.shadow.color);
|
|
328
|
+
this.shadowColor = rangeColorToRgb(this._engine, this.options.shadow.color);
|
|
329
329
|
for (const updater of particles.updaters) {
|
|
330
330
|
updater.init(this);
|
|
331
331
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Utils/ColorUtils.js
CHANGED
|
@@ -3,83 +3,63 @@ import { isArray, isString } from "./TypeUtils.js";
|
|
|
3
3
|
import { millisecondsToSeconds, percentDenominator } from "../Core/Utils/Constants.js";
|
|
4
4
|
import { AnimationStatus } from "../Enums/AnimationStatus.js";
|
|
5
5
|
import { itemFromArray } from "./Utils.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})(RgbIndexes || (RgbIndexes = {}));
|
|
13
|
-
const randomColorValue = "random", midColorValue = "mid", colorManagers = new Map();
|
|
14
|
-
export function addColorManager(manager) {
|
|
15
|
-
colorManagers.set(manager.key, manager);
|
|
16
|
-
}
|
|
17
|
-
function stringToRgba(input) {
|
|
18
|
-
for (const manager of colorManagers.values()) {
|
|
6
|
+
const randomColorValue = "random", midColorValue = "mid";
|
|
7
|
+
function stringToRgba(engine, input) {
|
|
8
|
+
if (!input) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
for (const manager of engine.colorManagers.values()) {
|
|
19
12
|
if (input.startsWith(manager.stringPrefix)) {
|
|
20
13
|
return manager.parseString(input);
|
|
21
14
|
}
|
|
22
15
|
}
|
|
23
|
-
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexFixed = input.replace(shorthandRegex, (_, r, g, b, a) => {
|
|
24
|
-
return r + r + g + g + b + b + (a !== undefined ? a + a : "");
|
|
25
|
-
}), regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, result = regex.exec(hexFixed), radix = 16, defaultAlpha = 1, alphaFactor = 0xff;
|
|
26
|
-
return result
|
|
27
|
-
? {
|
|
28
|
-
a: result[RgbIndexes.a] !== undefined
|
|
29
|
-
? parseInt(result[RgbIndexes.a], radix) / alphaFactor
|
|
30
|
-
: defaultAlpha,
|
|
31
|
-
b: parseInt(result[RgbIndexes.b], radix),
|
|
32
|
-
g: parseInt(result[RgbIndexes.g], radix),
|
|
33
|
-
r: parseInt(result[RgbIndexes.r], radix),
|
|
34
|
-
}
|
|
35
|
-
: undefined;
|
|
36
16
|
}
|
|
37
|
-
export function rangeColorToRgb(input, index, useIndex = true) {
|
|
17
|
+
export function rangeColorToRgb(engine, input, index, useIndex = true) {
|
|
38
18
|
if (!input) {
|
|
39
19
|
return;
|
|
40
20
|
}
|
|
41
21
|
const color = isString(input) ? { value: input } : input;
|
|
42
22
|
if (isString(color.value)) {
|
|
43
|
-
return colorToRgb(color.value, index, useIndex);
|
|
23
|
+
return colorToRgb(engine, color.value, index, useIndex);
|
|
44
24
|
}
|
|
45
25
|
if (isArray(color.value)) {
|
|
46
|
-
return rangeColorToRgb({
|
|
26
|
+
return rangeColorToRgb(engine, {
|
|
47
27
|
value: itemFromArray(color.value, index, useIndex),
|
|
48
28
|
});
|
|
49
29
|
}
|
|
50
|
-
for (const manager of colorManagers.values()) {
|
|
30
|
+
for (const manager of engine.colorManagers.values()) {
|
|
51
31
|
const res = manager.handleRangeColor(color);
|
|
52
32
|
if (res) {
|
|
53
33
|
return res;
|
|
54
34
|
}
|
|
55
35
|
}
|
|
56
36
|
}
|
|
57
|
-
export function colorToRgb(input, index, useIndex = true) {
|
|
37
|
+
export function colorToRgb(engine, input, index, useIndex = true) {
|
|
58
38
|
if (!input) {
|
|
59
39
|
return;
|
|
60
40
|
}
|
|
61
41
|
const color = isString(input) ? { value: input } : input;
|
|
62
42
|
if (isString(color.value)) {
|
|
63
|
-
return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(color.value);
|
|
43
|
+
return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(engine, color.value);
|
|
64
44
|
}
|
|
65
45
|
if (isArray(color.value)) {
|
|
66
|
-
return colorToRgb({
|
|
46
|
+
return colorToRgb(engine, {
|
|
67
47
|
value: itemFromArray(color.value, index, useIndex),
|
|
68
48
|
});
|
|
69
49
|
}
|
|
70
|
-
for (const manager of colorManagers.values()) {
|
|
50
|
+
for (const manager of engine.colorManagers.values()) {
|
|
71
51
|
const res = manager.handleColor(color);
|
|
72
52
|
if (res) {
|
|
73
53
|
return res;
|
|
74
54
|
}
|
|
75
55
|
}
|
|
76
56
|
}
|
|
77
|
-
export function colorToHsl(color, index, useIndex = true) {
|
|
78
|
-
const rgb = colorToRgb(color, index, useIndex);
|
|
57
|
+
export function colorToHsl(engine, color, index, useIndex = true) {
|
|
58
|
+
const rgb = colorToRgb(engine, color, index, useIndex);
|
|
79
59
|
return rgb ? rgbToHsl(rgb) : undefined;
|
|
80
60
|
}
|
|
81
|
-
export function rangeColorToHsl(color, index, useIndex = true) {
|
|
82
|
-
const rgb = rangeColorToRgb(color, index, useIndex);
|
|
61
|
+
export function rangeColorToHsl(engine, color, index, useIndex = true) {
|
|
62
|
+
const rgb = rangeColorToRgb(engine, color, index, useIndex);
|
|
83
63
|
return rgb ? rgbToHsl(rgb) : undefined;
|
|
84
64
|
}
|
|
85
65
|
export function rgbToHsl(color) {
|
|
@@ -106,11 +86,11 @@ export function rgbToHsl(color) {
|
|
|
106
86
|
}
|
|
107
87
|
return res;
|
|
108
88
|
}
|
|
109
|
-
export function stringToAlpha(input) {
|
|
110
|
-
return stringToRgba(input)?.a;
|
|
89
|
+
export function stringToAlpha(engine, input) {
|
|
90
|
+
return stringToRgba(engine, input)?.a;
|
|
111
91
|
}
|
|
112
|
-
export function stringToRgb(input) {
|
|
113
|
-
return stringToRgba(input);
|
|
92
|
+
export function stringToRgb(engine, input) {
|
|
93
|
+
return stringToRgba(engine, input);
|
|
114
94
|
}
|
|
115
95
|
export function hslToRgb(hsl) {
|
|
116
96
|
const hMax = 360, sMax = 100, lMax = 100, sMin = 0, lMin = 0, 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, rgbFactor = 255, triple = 3;
|
|
@@ -201,11 +181,11 @@ export function getLinkColor(p1, p2, linkColor) {
|
|
|
201
181
|
return linkColor;
|
|
202
182
|
}
|
|
203
183
|
}
|
|
204
|
-
export function getLinkRandomColor(optColor, blink, consent) {
|
|
184
|
+
export function getLinkRandomColor(engine, optColor, blink, consent) {
|
|
205
185
|
const color = isString(optColor) ? optColor : optColor.value;
|
|
206
186
|
if (color === randomColorValue) {
|
|
207
187
|
if (consent) {
|
|
208
|
-
return rangeColorToRgb({
|
|
188
|
+
return rangeColorToRgb(engine, {
|
|
209
189
|
value: color,
|
|
210
190
|
});
|
|
211
191
|
}
|
|
@@ -218,7 +198,7 @@ export function getLinkRandomColor(optColor, blink, consent) {
|
|
|
218
198
|
return midColorValue;
|
|
219
199
|
}
|
|
220
200
|
else {
|
|
221
|
-
return rangeColorToRgb({
|
|
201
|
+
return rangeColorToRgb(engine, {
|
|
222
202
|
value: color,
|
|
223
203
|
});
|
|
224
204
|
}
|
package/esm/Utils/NumberUtils.js
CHANGED
|
@@ -6,16 +6,7 @@ let _random = Math.random;
|
|
|
6
6
|
const _animationLoop = {
|
|
7
7
|
nextFrame: (cb) => requestAnimationFrame(cb),
|
|
8
8
|
cancel: (idx) => cancelAnimationFrame(idx),
|
|
9
|
-
},
|
|
10
|
-
export function addEasing(name, easing) {
|
|
11
|
-
if (easingFunctions.get(name)) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
easingFunctions.set(name, easing);
|
|
15
|
-
}
|
|
16
|
-
export function getEasing(name) {
|
|
17
|
-
return easingFunctions.get(name) ?? ((value) => value);
|
|
18
|
-
}
|
|
9
|
+
}, double = 2, doublePI = Math.PI * double;
|
|
19
10
|
export function setRandom(rnd = Math.random) {
|
|
20
11
|
_random = rnd;
|
|
21
12
|
}
|
package/esm/Utils/Utils.js
CHANGED
|
@@ -414,3 +414,9 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
|
|
|
414
414
|
data.value = clamp(data.value, minValue, maxValue);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
+
export function assertValidVersion(engine, pluginVersion) {
|
|
418
|
+
if (engine.version === pluginVersion) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${engine.version}. Plugins version: ${pluginVersion}`);
|
|
422
|
+
}
|
package/esm/exports.js
CHANGED
|
@@ -78,9 +78,7 @@ export * from "./Options/Classes/Theme/ThemeDefault.js";
|
|
|
78
78
|
export * from "./Options/Classes/ValueWithRandom.js";
|
|
79
79
|
export * from "./Utils/CanvasUtils.js";
|
|
80
80
|
export * from "./Utils/ColorUtils.js";
|
|
81
|
-
export * from "./Utils/HslColorManager.js";
|
|
82
81
|
export * from "./Utils/NumberUtils.js";
|
|
83
82
|
export * from "./Utils/OptionsUtils.js";
|
|
84
|
-
export * from "./Utils/RgbColorManager.js";
|
|
85
83
|
export * from "./Utils/Utils.js";
|
|
86
84
|
export * from "./Utils/TypeUtils.js";
|
package/esm/init.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { Engine } from "./Core/Engine.js";
|
|
2
|
-
import { HslColorManager } from "./Utils/HslColorManager.js";
|
|
3
|
-
import { RgbColorManager } from "./Utils/RgbColorManager.js";
|
|
4
|
-
import { addColorManager } from "./Utils/ColorUtils.js";
|
|
5
2
|
export function init() {
|
|
6
|
-
const rgbColorManager = new RgbColorManager(), hslColorManager = new HslColorManager();
|
|
7
|
-
addColorManager(rgbColorManager);
|
|
8
|
-
addColorManager(hslColorManager);
|
|
9
3
|
const engine = new Engine();
|
|
10
4
|
engine.init();
|
|
11
5
|
return engine;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/engine",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"scripts": {
|
package/report.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8"/>
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
6
|
-
<title>@tsparticles/engine [
|
|
6
|
+
<title>@tsparticles/engine [24 Nov 2024 at 23:35]</title>
|
|
7
7
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v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