@tsparticles/engine 3.4.0 → 3.6.0-beta.0
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 +0 -2
- package/browser/Core/Canvas.js +4 -6
- package/browser/Core/Container.js +15 -15
- package/browser/Core/Engine.js +1 -1
- package/browser/Core/Particle.js +4 -4
- package/browser/Core/Particles.js +9 -8
- package/browser/Core/Utils/EventListeners.js +1 -1
- package/browser/Utils/CanvasUtils.js +2 -2
- package/browser/Utils/ColorUtils.js +3 -3
- package/browser/Utils/NumberUtils.js +17 -4
- package/cjs/Core/Canvas.js +4 -6
- package/cjs/Core/Container.js +15 -15
- package/cjs/Core/Engine.js +1 -1
- package/cjs/Core/Particle.js +4 -4
- package/cjs/Core/Particles.js +9 -8
- package/cjs/Core/Utils/EventListeners.js +1 -1
- package/cjs/Utils/CanvasUtils.js +13 -14
- package/cjs/Utils/ColorUtils.js +23 -24
- package/cjs/Utils/NumberUtils.js +43 -28
- package/cjs/Utils/OptionsUtils.js +2 -3
- package/cjs/Utils/TypeUtils.js +6 -7
- package/cjs/Utils/Utils.js +29 -30
- package/cjs/init.js +1 -2
- package/esm/Core/Canvas.js +4 -6
- package/esm/Core/Container.js +15 -15
- package/esm/Core/Engine.js +1 -1
- package/esm/Core/Particle.js +4 -4
- package/esm/Core/Particles.js +9 -8
- package/esm/Core/Utils/EventListeners.js +1 -1
- package/esm/Utils/CanvasUtils.js +2 -2
- package/esm/Utils/ColorUtils.js +3 -3
- package/esm/Utils/NumberUtils.js +17 -4
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +12 -12
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Utils/NumberUtils.d.ts +3 -0
- package/umd/Core/Canvas.js +4 -6
- package/umd/Core/Container.js +16 -16
- package/umd/Core/Engine.js +1 -1
- package/umd/Core/Particle.js +4 -4
- package/umd/Core/Particles.js +9 -8
- package/umd/Core/Utils/EventListeners.js +1 -1
- package/umd/Utils/CanvasUtils.js +13 -14
- package/umd/Utils/ColorUtils.js +23 -24
- package/umd/Utils/NumberUtils.js +43 -28
- package/umd/Utils/OptionsUtils.js +2 -3
- package/umd/Utils/TypeUtils.js +6 -7
- package/umd/Utils/Utils.js +29 -30
- package/umd/init.js +1 -2
package/umd/Utils/Utils.js
CHANGED
|
@@ -9,7 +9,35 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.setLogger = setLogger;
|
|
13
|
+
exports.getLogger = getLogger;
|
|
14
|
+
exports.isSsr = isSsr;
|
|
15
|
+
exports.hasMatchMedia = hasMatchMedia;
|
|
16
|
+
exports.safeMatchMedia = safeMatchMedia;
|
|
17
|
+
exports.safeIntersectionObserver = safeIntersectionObserver;
|
|
18
|
+
exports.safeMutationObserver = safeMutationObserver;
|
|
19
|
+
exports.isInArray = isInArray;
|
|
20
|
+
exports.loadFont = loadFont;
|
|
21
|
+
exports.arrayRandomIndex = arrayRandomIndex;
|
|
22
|
+
exports.itemFromArray = itemFromArray;
|
|
23
|
+
exports.isPointInside = isPointInside;
|
|
24
|
+
exports.areBoundsInside = areBoundsInside;
|
|
25
|
+
exports.calculateBounds = calculateBounds;
|
|
26
|
+
exports.deepExtend = deepExtend;
|
|
27
|
+
exports.isDivModeEnabled = isDivModeEnabled;
|
|
28
|
+
exports.divModeExecute = divModeExecute;
|
|
29
|
+
exports.singleDivModeExecute = singleDivModeExecute;
|
|
30
|
+
exports.divMode = divMode;
|
|
31
|
+
exports.circleBounceDataFromParticle = circleBounceDataFromParticle;
|
|
32
|
+
exports.circleBounce = circleBounce;
|
|
33
|
+
exports.rectBounce = rectBounce;
|
|
34
|
+
exports.executeOnSingleOrMultiple = executeOnSingleOrMultiple;
|
|
35
|
+
exports.itemFromSingleOrMultiple = itemFromSingleOrMultiple;
|
|
36
|
+
exports.findItemFromSingleOrMultiple = findItemFromSingleOrMultiple;
|
|
37
|
+
exports.initParticleNumericAnimationValue = initParticleNumericAnimationValue;
|
|
38
|
+
exports.getPosition = getPosition;
|
|
39
|
+
exports.getSize = getSize;
|
|
40
|
+
exports.updateAnimation = updateAnimation;
|
|
13
41
|
const NumberUtils_js_1 = require("./NumberUtils.js");
|
|
14
42
|
const Constants_js_1 = require("../Core/Utils/Constants.js");
|
|
15
43
|
const TypeUtils_js_1 = require("./TypeUtils.js");
|
|
@@ -36,11 +64,9 @@
|
|
|
36
64
|
_logger.verbose = logger.verbose || _logger.verbose;
|
|
37
65
|
_logger.warning = logger.warning || _logger.warning;
|
|
38
66
|
}
|
|
39
|
-
exports.setLogger = setLogger;
|
|
40
67
|
function getLogger() {
|
|
41
68
|
return _logger;
|
|
42
69
|
}
|
|
43
|
-
exports.getLogger = getLogger;
|
|
44
70
|
function rectSideBounce(data) {
|
|
45
71
|
const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data, half = 0.5, minVelocity = 0;
|
|
46
72
|
if (pOtherSide.min < rectOtherSide.min ||
|
|
@@ -65,37 +91,31 @@
|
|
|
65
91
|
function isSsr() {
|
|
66
92
|
return typeof window === "undefined" || !window || typeof window.document === "undefined" || !window.document;
|
|
67
93
|
}
|
|
68
|
-
exports.isSsr = isSsr;
|
|
69
94
|
function hasMatchMedia() {
|
|
70
95
|
return !isSsr() && typeof matchMedia !== "undefined";
|
|
71
96
|
}
|
|
72
|
-
exports.hasMatchMedia = hasMatchMedia;
|
|
73
97
|
function safeMatchMedia(query) {
|
|
74
98
|
if (!hasMatchMedia()) {
|
|
75
99
|
return;
|
|
76
100
|
}
|
|
77
101
|
return matchMedia(query);
|
|
78
102
|
}
|
|
79
|
-
exports.safeMatchMedia = safeMatchMedia;
|
|
80
103
|
function safeIntersectionObserver(callback) {
|
|
81
104
|
if (isSsr() || typeof IntersectionObserver === "undefined") {
|
|
82
105
|
return;
|
|
83
106
|
}
|
|
84
107
|
return new IntersectionObserver(callback);
|
|
85
108
|
}
|
|
86
|
-
exports.safeIntersectionObserver = safeIntersectionObserver;
|
|
87
109
|
function safeMutationObserver(callback) {
|
|
88
110
|
if (isSsr() || typeof MutationObserver === "undefined") {
|
|
89
111
|
return;
|
|
90
112
|
}
|
|
91
113
|
return new MutationObserver(callback);
|
|
92
114
|
}
|
|
93
|
-
exports.safeMutationObserver = safeMutationObserver;
|
|
94
115
|
function isInArray(value, array) {
|
|
95
116
|
const invalidIndex = -1;
|
|
96
117
|
return value === array || ((0, TypeUtils_js_1.isArray)(array) && array.indexOf(value) > invalidIndex);
|
|
97
118
|
}
|
|
98
|
-
exports.isInArray = isInArray;
|
|
99
119
|
async function loadFont(font, weight) {
|
|
100
120
|
try {
|
|
101
121
|
await document.fonts.load(`${weight ?? "400"} 36px '${font ?? "Verdana"}'`);
|
|
@@ -103,20 +123,16 @@
|
|
|
103
123
|
catch {
|
|
104
124
|
}
|
|
105
125
|
}
|
|
106
|
-
exports.loadFont = loadFont;
|
|
107
126
|
function arrayRandomIndex(array) {
|
|
108
127
|
return Math.floor((0, NumberUtils_js_1.getRandom)() * array.length);
|
|
109
128
|
}
|
|
110
|
-
exports.arrayRandomIndex = arrayRandomIndex;
|
|
111
129
|
function itemFromArray(array, index, useIndex = true) {
|
|
112
130
|
return array[index !== undefined && useIndex ? index % array.length : arrayRandomIndex(array)];
|
|
113
131
|
}
|
|
114
|
-
exports.itemFromArray = itemFromArray;
|
|
115
132
|
function isPointInside(point, size, offset, radius, direction) {
|
|
116
133
|
const minRadius = 0;
|
|
117
134
|
return areBoundsInside(calculateBounds(point, radius ?? minRadius), size, offset, direction);
|
|
118
135
|
}
|
|
119
|
-
exports.isPointInside = isPointInside;
|
|
120
136
|
function areBoundsInside(bounds, size, offset, direction) {
|
|
121
137
|
let inside = true;
|
|
122
138
|
if (!direction || direction === OutModeDirection_js_1.OutModeDirection.bottom) {
|
|
@@ -133,7 +149,6 @@
|
|
|
133
149
|
}
|
|
134
150
|
return inside;
|
|
135
151
|
}
|
|
136
|
-
exports.areBoundsInside = areBoundsInside;
|
|
137
152
|
function calculateBounds(point, radius) {
|
|
138
153
|
return {
|
|
139
154
|
bottom: point.y + radius,
|
|
@@ -142,7 +157,6 @@
|
|
|
142
157
|
top: point.y - radius,
|
|
143
158
|
};
|
|
144
159
|
}
|
|
145
|
-
exports.calculateBounds = calculateBounds;
|
|
146
160
|
function deepExtend(destination, ...sources) {
|
|
147
161
|
for (const source of sources) {
|
|
148
162
|
if (source === undefined || source === null) {
|
|
@@ -172,11 +186,9 @@
|
|
|
172
186
|
}
|
|
173
187
|
return destination;
|
|
174
188
|
}
|
|
175
|
-
exports.deepExtend = deepExtend;
|
|
176
189
|
function isDivModeEnabled(mode, divs) {
|
|
177
190
|
return !!findItemFromSingleOrMultiple(divs, t => t.enable && isInArray(mode, t.mode));
|
|
178
191
|
}
|
|
179
|
-
exports.isDivModeEnabled = isDivModeEnabled;
|
|
180
192
|
function divModeExecute(mode, divs, callback) {
|
|
181
193
|
executeOnSingleOrMultiple(divs, div => {
|
|
182
194
|
const divMode = div.mode, divEnabled = div.enable;
|
|
@@ -185,14 +197,12 @@
|
|
|
185
197
|
}
|
|
186
198
|
});
|
|
187
199
|
}
|
|
188
|
-
exports.divModeExecute = divModeExecute;
|
|
189
200
|
function singleDivModeExecute(div, callback) {
|
|
190
201
|
const selectors = div.selectors;
|
|
191
202
|
executeOnSingleOrMultiple(selectors, selector => {
|
|
192
203
|
callback(selector, div);
|
|
193
204
|
});
|
|
194
205
|
}
|
|
195
|
-
exports.singleDivModeExecute = singleDivModeExecute;
|
|
196
206
|
function divMode(divs, element) {
|
|
197
207
|
if (!element || !divs) {
|
|
198
208
|
return;
|
|
@@ -201,7 +211,6 @@
|
|
|
201
211
|
return checkSelector(element, div.selectors);
|
|
202
212
|
});
|
|
203
213
|
}
|
|
204
|
-
exports.divMode = divMode;
|
|
205
214
|
function circleBounceDataFromParticle(p) {
|
|
206
215
|
return {
|
|
207
216
|
position: p.getPosition(),
|
|
@@ -211,7 +220,6 @@
|
|
|
211
220
|
factor: Vectors_js_1.Vector.create((0, NumberUtils_js_1.getRangeValue)(p.options.bounce.horizontal.value), (0, NumberUtils_js_1.getRangeValue)(p.options.bounce.vertical.value)),
|
|
212
221
|
};
|
|
213
222
|
}
|
|
214
|
-
exports.circleBounceDataFromParticle = circleBounceDataFromParticle;
|
|
215
223
|
function circleBounce(p1, p2) {
|
|
216
224
|
const { x: xVelocityDiff, y: yVelocityDiff } = p1.velocity.sub(p2.velocity), [pos1, pos2] = [p1.position, p2.position], { dx: xDist, dy: yDist } = (0, NumberUtils_js_1.getDistances)(pos2, pos1), minimumDistance = 0;
|
|
217
225
|
if (xVelocityDiff * xDist + yVelocityDiff * yDist < minimumDistance) {
|
|
@@ -223,7 +231,6 @@
|
|
|
223
231
|
p2.velocity.x = vFinal2.x * p2.factor.x;
|
|
224
232
|
p2.velocity.y = vFinal2.y * p2.factor.y;
|
|
225
233
|
}
|
|
226
|
-
exports.circleBounce = circleBounce;
|
|
227
234
|
function rectBounce(particle, divBounds) {
|
|
228
235
|
const pPos = particle.getPosition(), size = particle.getRadius(), bounds = calculateBounds(pPos, size), bounceOptions = particle.options.bounce, resH = rectSideBounce({
|
|
229
236
|
pSide: {
|
|
@@ -282,16 +289,13 @@
|
|
|
282
289
|
}
|
|
283
290
|
}
|
|
284
291
|
}
|
|
285
|
-
exports.rectBounce = rectBounce;
|
|
286
292
|
function executeOnSingleOrMultiple(obj, callback) {
|
|
287
293
|
const defaultIndex = 0;
|
|
288
294
|
return (0, TypeUtils_js_1.isArray)(obj) ? obj.map((item, index) => callback(item, index)) : callback(obj, defaultIndex);
|
|
289
295
|
}
|
|
290
|
-
exports.executeOnSingleOrMultiple = executeOnSingleOrMultiple;
|
|
291
296
|
function itemFromSingleOrMultiple(obj, index, useIndex) {
|
|
292
297
|
return (0, TypeUtils_js_1.isArray)(obj) ? itemFromArray(obj, index, useIndex) : obj;
|
|
293
298
|
}
|
|
294
|
-
exports.itemFromSingleOrMultiple = itemFromSingleOrMultiple;
|
|
295
299
|
function findItemFromSingleOrMultiple(obj, callback) {
|
|
296
300
|
if ((0, TypeUtils_js_1.isArray)(obj)) {
|
|
297
301
|
return obj.find((t, index) => callback(t, index));
|
|
@@ -299,7 +303,6 @@
|
|
|
299
303
|
const defaultIndex = 0;
|
|
300
304
|
return callback(obj, defaultIndex) ? obj : undefined;
|
|
301
305
|
}
|
|
302
|
-
exports.findItemFromSingleOrMultiple = findItemFromSingleOrMultiple;
|
|
303
306
|
function initParticleNumericAnimationValue(options, pxRatio) {
|
|
304
307
|
const valueRange = options.value, animationOptions = options.animation, res = {
|
|
305
308
|
delayTime: (0, NumberUtils_js_1.getRangeValue)(animationOptions.delay) * Constants_js_1.millisecondsToSeconds,
|
|
@@ -350,7 +353,6 @@
|
|
|
350
353
|
res.initialValue = res.value;
|
|
351
354
|
return res;
|
|
352
355
|
}
|
|
353
|
-
exports.initParticleNumericAnimationValue = initParticleNumericAnimationValue;
|
|
354
356
|
function getPositionOrSize(positionOrSize, canvasSize) {
|
|
355
357
|
const isPercent = positionOrSize.mode === PixelMode_js_1.PixelMode.percent;
|
|
356
358
|
if (!isPercent) {
|
|
@@ -374,11 +376,9 @@
|
|
|
374
376
|
function getPosition(position, canvasSize) {
|
|
375
377
|
return getPositionOrSize(position, canvasSize);
|
|
376
378
|
}
|
|
377
|
-
exports.getPosition = getPosition;
|
|
378
379
|
function getSize(size, canvasSize) {
|
|
379
380
|
return getPositionOrSize(size, canvasSize);
|
|
380
381
|
}
|
|
381
|
-
exports.getSize = getSize;
|
|
382
382
|
function checkDestroy(particle, destroyType, value, minValue, maxValue) {
|
|
383
383
|
switch (destroyType) {
|
|
384
384
|
case DestroyType_js_1.DestroyType.max:
|
|
@@ -454,5 +454,4 @@
|
|
|
454
454
|
data.value = (0, NumberUtils_js_1.clamp)(data.value, minValue, maxValue);
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
|
-
exports.updateAnimation = updateAnimation;
|
|
458
457
|
});
|
package/umd/init.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.init =
|
|
12
|
+
exports.init = init;
|
|
13
13
|
const Engine_js_1 = require("./Core/Engine.js");
|
|
14
14
|
const HslColorManager_js_1 = require("./Utils/HslColorManager.js");
|
|
15
15
|
const RgbColorManager_js_1 = require("./Utils/RgbColorManager.js");
|
|
@@ -22,5 +22,4 @@
|
|
|
22
22
|
engine.init();
|
|
23
23
|
return engine;
|
|
24
24
|
}
|
|
25
|
-
exports.init = init;
|
|
26
25
|
});
|