@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/README.md
CHANGED
|
@@ -18,8 +18,6 @@ React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Riot.j
|
|
|
18
18
|
[](https://repl.it/github/tsparticles/tsparticles)
|
|
19
19
|
|
|
20
20
|
[](https://discord.gg/hACwv45Hme)
|
|
21
|
-
[](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI)
|
|
22
|
-
[](https://chat.whatsapp.com/KQyHc9UEbRc2qlqNQR2J5c)
|
|
23
21
|
[](https://t.me/tsparticles)
|
|
24
22
|
[](https://www.reddit.com/r/tsParticles/)
|
|
25
23
|
|
package/browser/Core/Canvas.js
CHANGED
|
@@ -22,9 +22,6 @@ function setStyle(canvas, style, important = false) {
|
|
|
22
22
|
}
|
|
23
23
|
for (const key in style) {
|
|
24
24
|
const value = style[key];
|
|
25
|
-
if (!value) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
25
|
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
29
26
|
}
|
|
30
27
|
}
|
|
@@ -208,10 +205,11 @@ export class Canvas {
|
|
|
208
205
|
if (!element) {
|
|
209
206
|
return;
|
|
210
207
|
}
|
|
211
|
-
const radix = 10;
|
|
208
|
+
const radix = 10, zIndex = this.container.actualOptions.fullScreen.zIndex.toString(radix);
|
|
212
209
|
setStyle(element, {
|
|
213
210
|
position: "fixed",
|
|
214
|
-
|
|
211
|
+
"z-index": zIndex,
|
|
212
|
+
zIndex: zIndex,
|
|
215
213
|
top: "0",
|
|
216
214
|
left: "0",
|
|
217
215
|
width: "100%",
|
|
@@ -378,7 +376,7 @@ export class Canvas {
|
|
|
378
376
|
}
|
|
379
377
|
initPlugins() {
|
|
380
378
|
this._resizePlugins = [];
|
|
381
|
-
for (const
|
|
379
|
+
for (const plugin of this.container.plugins.values()) {
|
|
382
380
|
if (plugin.resize) {
|
|
383
381
|
this._resizePlugins.push(plugin);
|
|
384
382
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { animate, cancelAnimation, getRangeValue } from "../Utils/NumberUtils.js";
|
|
1
2
|
import { errorPrefix, millisecondsToSeconds } from "./Utils/Constants.js";
|
|
2
3
|
import { getLogger, safeIntersectionObserver } from "../Utils/Utils.js";
|
|
3
4
|
import { Canvas } from "./Canvas.js";
|
|
@@ -6,7 +7,6 @@ import { EventType } from "../Enums/Types/EventType.js";
|
|
|
6
7
|
import { Options } from "../Options/Classes/Options.js";
|
|
7
8
|
import { Particles } from "./Particles.js";
|
|
8
9
|
import { Retina } from "./Retina.js";
|
|
9
|
-
import { getRangeValue } from "../Utils/NumberUtils.js";
|
|
10
10
|
import { loadOptions } from "../Utils/OptionsUtils.js";
|
|
11
11
|
function guardCheck(container) {
|
|
12
12
|
return container && !container.destroyed;
|
|
@@ -220,10 +220,10 @@ export class Container {
|
|
|
220
220
|
this.clearClickHandlers();
|
|
221
221
|
this.particles.destroy();
|
|
222
222
|
this.canvas.destroy();
|
|
223
|
-
for (const
|
|
223
|
+
for (const effectDrawer of this.effectDrawers.values()) {
|
|
224
224
|
effectDrawer.destroy?.(this);
|
|
225
225
|
}
|
|
226
|
-
for (const
|
|
226
|
+
for (const shapeDrawer of this.shapeDrawers.values()) {
|
|
227
227
|
shapeDrawer.destroy?.(this);
|
|
228
228
|
}
|
|
229
229
|
for (const key of this.effectDrawers.keys()) {
|
|
@@ -255,10 +255,10 @@ export class Container {
|
|
|
255
255
|
}
|
|
256
256
|
this._nextFrame(timestamp);
|
|
257
257
|
};
|
|
258
|
-
this._drawAnimationFrame =
|
|
258
|
+
this._drawAnimationFrame = animate(timestamp => frame(timestamp));
|
|
259
259
|
}
|
|
260
260
|
async export(type, options = {}) {
|
|
261
|
-
for (const
|
|
261
|
+
for (const plugin of this.plugins.values()) {
|
|
262
262
|
if (!plugin.export) {
|
|
263
263
|
continue;
|
|
264
264
|
}
|
|
@@ -275,7 +275,7 @@ export class Container {
|
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
277
|
this.particles.handleClickMode(mode);
|
|
278
|
-
for (const
|
|
278
|
+
for (const plugin of this.plugins.values()) {
|
|
279
279
|
plugin.handleClickMode?.(mode);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
@@ -317,19 +317,19 @@ export class Container {
|
|
|
317
317
|
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
318
318
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
319
319
|
this._smooth = smooth;
|
|
320
|
-
for (const
|
|
320
|
+
for (const drawer of this.effectDrawers.values()) {
|
|
321
321
|
await drawer.init?.(this);
|
|
322
322
|
}
|
|
323
|
-
for (const
|
|
323
|
+
for (const drawer of this.shapeDrawers.values()) {
|
|
324
324
|
await drawer.init?.(this);
|
|
325
325
|
}
|
|
326
|
-
for (const
|
|
326
|
+
for (const plugin of this.plugins.values()) {
|
|
327
327
|
await plugin.init?.();
|
|
328
328
|
}
|
|
329
329
|
this._engine.dispatchEvent(EventType.containerInit, { container: this });
|
|
330
330
|
await this.particles.init();
|
|
331
331
|
this.particles.setDensity();
|
|
332
|
-
for (const
|
|
332
|
+
for (const plugin of this.plugins.values()) {
|
|
333
333
|
plugin.particlesSetup?.();
|
|
334
334
|
}
|
|
335
335
|
this._engine.dispatchEvent(EventType.particlesSetup, { container: this });
|
|
@@ -346,13 +346,13 @@ export class Container {
|
|
|
346
346
|
return;
|
|
347
347
|
}
|
|
348
348
|
if (this._drawAnimationFrame !== undefined) {
|
|
349
|
-
|
|
349
|
+
cancelAnimation(this._drawAnimationFrame);
|
|
350
350
|
delete this._drawAnimationFrame;
|
|
351
351
|
}
|
|
352
352
|
if (this._paused) {
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
|
-
for (const
|
|
355
|
+
for (const plugin of this.plugins.values()) {
|
|
356
356
|
plugin.pause?.();
|
|
357
357
|
}
|
|
358
358
|
if (!this.pageHidden) {
|
|
@@ -373,7 +373,7 @@ export class Container {
|
|
|
373
373
|
this._paused = false;
|
|
374
374
|
}
|
|
375
375
|
if (needsUpdate) {
|
|
376
|
-
for (const
|
|
376
|
+
for (const plugin of this.plugins.values()) {
|
|
377
377
|
if (plugin.play) {
|
|
378
378
|
plugin.play();
|
|
379
379
|
}
|
|
@@ -411,7 +411,7 @@ export class Container {
|
|
|
411
411
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
412
412
|
this._intersectionObserver.observe(this.interactivity.element);
|
|
413
413
|
}
|
|
414
|
-
for (const
|
|
414
|
+
for (const plugin of this.plugins.values()) {
|
|
415
415
|
await plugin.start?.();
|
|
416
416
|
}
|
|
417
417
|
this._engine.dispatchEvent(EventType.containerStarted, { container: this });
|
|
@@ -438,7 +438,7 @@ export class Container {
|
|
|
438
438
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
439
439
|
this._intersectionObserver.unobserve(this.interactivity.element);
|
|
440
440
|
}
|
|
441
|
-
for (const
|
|
441
|
+
for (const plugin of this.plugins.values()) {
|
|
442
442
|
plugin.stop?.();
|
|
443
443
|
}
|
|
444
444
|
for (const key of this.plugins.keys()) {
|
package/browser/Core/Engine.js
CHANGED
package/browser/Core/Particle.js
CHANGED
|
@@ -48,7 +48,7 @@ export class Particle {
|
|
|
48
48
|
constructor(engine, container) {
|
|
49
49
|
this.container = container;
|
|
50
50
|
this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
|
|
51
|
-
for (const
|
|
51
|
+
for (const plugin of container.plugins.values()) {
|
|
52
52
|
const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
|
53
53
|
if (pluginPos) {
|
|
54
54
|
return Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
|
|
@@ -166,7 +166,7 @@ export class Particle {
|
|
|
166
166
|
this.slow.inRange = false;
|
|
167
167
|
const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
168
168
|
shapeDrawer?.particleDestroy?.(this);
|
|
169
|
-
for (const
|
|
169
|
+
for (const plugin of container.plugins.values()) {
|
|
170
170
|
plugin.particleDestroyed?.(this, override);
|
|
171
171
|
}
|
|
172
172
|
for (const updater of container.particles.updaters) {
|
|
@@ -182,7 +182,7 @@ export class Particle {
|
|
|
182
182
|
}
|
|
183
183
|
draw(delta) {
|
|
184
184
|
const container = this.container, canvas = container.canvas;
|
|
185
|
-
for (const
|
|
185
|
+
for (const plugin of container.plugins.values()) {
|
|
186
186
|
canvas.drawParticlePlugin(plugin, this, delta);
|
|
187
187
|
}
|
|
188
188
|
canvas.drawParticle(this, delta);
|
|
@@ -334,7 +334,7 @@ export class Particle {
|
|
|
334
334
|
}
|
|
335
335
|
effectDrawer?.particleInit?.(container, this);
|
|
336
336
|
shapeDrawer?.particleInit?.(container, this);
|
|
337
|
-
for (const
|
|
337
|
+
for (const plugin of container.plugins.values()) {
|
|
338
338
|
plugin.particleCreated?.(this);
|
|
339
339
|
}
|
|
340
340
|
}
|
|
@@ -122,7 +122,7 @@ export class Particles {
|
|
|
122
122
|
options.manualParticles.forEach(p => this.addParticle(p.position ? getPosition(p.position, container.canvas.size) : undefined, p.options));
|
|
123
123
|
}
|
|
124
124
|
addParticle(position, overrideOptions, group, initializer) {
|
|
125
|
-
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit, currentCount = this.count, minLimit = 0;
|
|
125
|
+
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count, minLimit = 0;
|
|
126
126
|
if (limit > minLimit) {
|
|
127
127
|
switch (limitMode) {
|
|
128
128
|
case LimitMode.delete: {
|
|
@@ -156,7 +156,7 @@ export class Particles {
|
|
|
156
156
|
const container = this._container, canvas = container.canvas;
|
|
157
157
|
canvas.clear();
|
|
158
158
|
this.update(delta);
|
|
159
|
-
for (const
|
|
159
|
+
for (const plugin of container.plugins.values()) {
|
|
160
160
|
canvas.drawPlugin(plugin, delta);
|
|
161
161
|
}
|
|
162
162
|
for (const p of this._zArray) {
|
|
@@ -181,7 +181,7 @@ export class Particles {
|
|
|
181
181
|
this._needsSort = false;
|
|
182
182
|
await this.initPlugins();
|
|
183
183
|
let handled = false;
|
|
184
|
-
for (const
|
|
184
|
+
for (const plugin of container.plugins.values()) {
|
|
185
185
|
handled = plugin.particlesInitialization?.() ?? handled;
|
|
186
186
|
if (handled) {
|
|
187
187
|
break;
|
|
@@ -209,7 +209,7 @@ export class Particles {
|
|
|
209
209
|
this.movers = await this._engine.getMovers(container, true);
|
|
210
210
|
this.updaters = await this._engine.getUpdaters(container, true);
|
|
211
211
|
await this._interactionManager.init();
|
|
212
|
-
for (const
|
|
212
|
+
for (const pathGenerator of container.pathGenerators.values()) {
|
|
213
213
|
pathGenerator.init(container);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -233,7 +233,8 @@ export class Particles {
|
|
|
233
233
|
}
|
|
234
234
|
let deleted = 0;
|
|
235
235
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
236
|
-
if (this._removeParticle(i
|
|
236
|
+
if (this._removeParticle(i, group, override)) {
|
|
237
|
+
i--;
|
|
237
238
|
deleted++;
|
|
238
239
|
}
|
|
239
240
|
}
|
|
@@ -259,10 +260,10 @@ export class Particles {
|
|
|
259
260
|
update(delta) {
|
|
260
261
|
const container = this._container, particlesToDelete = new Set();
|
|
261
262
|
this.quadTree = new QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
|
|
262
|
-
for (const
|
|
263
|
+
for (const pathGenerator of container.pathGenerators.values()) {
|
|
263
264
|
pathGenerator.update();
|
|
264
265
|
}
|
|
265
|
-
for (const
|
|
266
|
+
for (const plugin of container.plugins.values()) {
|
|
266
267
|
plugin.update?.(delta);
|
|
267
268
|
}
|
|
268
269
|
const resizeFactor = this._resizeFactor;
|
|
@@ -275,7 +276,7 @@ export class Particles {
|
|
|
275
276
|
}
|
|
276
277
|
particle.ignoresResizeRatio = false;
|
|
277
278
|
this._interactionManager.reset(particle);
|
|
278
|
-
for (const
|
|
279
|
+
for (const plugin of this._container.plugins.values()) {
|
|
279
280
|
if (particle.destroyed) {
|
|
280
281
|
break;
|
|
281
282
|
}
|
|
@@ -187,7 +187,7 @@ export class EventListeners {
|
|
|
187
187
|
if (!mousePosition || !options.interactivity.events.onClick.enable) {
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
|
-
for (const
|
|
190
|
+
for (const plugin of container.plugins.values()) {
|
|
191
191
|
if (!plugin.clickPositionValid) {
|
|
192
192
|
continue;
|
|
193
193
|
}
|
|
@@ -33,8 +33,8 @@ export function drawParticle(data) {
|
|
|
33
33
|
cos: Math.cos(angle),
|
|
34
34
|
}, rotating = !!angle, identity = 1, transformData = {
|
|
35
35
|
a: rotateData.cos * (transform.a ?? defaultTransform.a),
|
|
36
|
-
b: rotating ? rotateData.sin * (transform.b ?? identity) : transform.b ?? defaultTransform.b,
|
|
37
|
-
c: rotating ? -rotateData.sin * (transform.c ?? identity) : transform.c ?? defaultTransform.c,
|
|
36
|
+
b: rotating ? rotateData.sin * (transform.b ?? identity) : (transform.b ?? defaultTransform.b),
|
|
37
|
+
c: rotating ? -rotateData.sin * (transform.c ?? identity) : (transform.c ?? defaultTransform.c),
|
|
38
38
|
d: rotateData.cos * (transform.d ?? defaultTransform.d),
|
|
39
39
|
};
|
|
40
40
|
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
|
@@ -15,7 +15,7 @@ export function addColorManager(manager) {
|
|
|
15
15
|
colorManagers.set(manager.key, manager);
|
|
16
16
|
}
|
|
17
17
|
function stringToRgba(input) {
|
|
18
|
-
for (const
|
|
18
|
+
for (const manager of colorManagers.values()) {
|
|
19
19
|
if (input.startsWith(manager.stringPrefix)) {
|
|
20
20
|
return manager.parseString(input);
|
|
21
21
|
}
|
|
@@ -47,7 +47,7 @@ export function rangeColorToRgb(input, index, useIndex = true) {
|
|
|
47
47
|
value: itemFromArray(color.value, index, useIndex),
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
for (const
|
|
50
|
+
for (const manager of colorManagers.values()) {
|
|
51
51
|
const res = manager.handleRangeColor(color);
|
|
52
52
|
if (res) {
|
|
53
53
|
return res;
|
|
@@ -67,7 +67,7 @@ export function colorToRgb(input, index, useIndex = true) {
|
|
|
67
67
|
value: itemFromArray(color.value, index, useIndex),
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
for (const
|
|
70
|
+
for (const manager of colorManagers.values()) {
|
|
71
71
|
const res = manager.handleColor(color);
|
|
72
72
|
if (res) {
|
|
73
73
|
return res;
|
|
@@ -3,15 +3,18 @@ import { Vector } from "../Core/Utils/Vectors.js";
|
|
|
3
3
|
import { isNumber } from "./TypeUtils.js";
|
|
4
4
|
import { percentDenominator } from "../Core/Utils/Constants.js";
|
|
5
5
|
let _random = Math.random;
|
|
6
|
-
const
|
|
6
|
+
const _animationLoop = {
|
|
7
|
+
nextFrame: (cb) => requestAnimationFrame(cb),
|
|
8
|
+
cancel: (idx) => cancelAnimationFrame(idx),
|
|
9
|
+
}, easingFunctions = new Map(), double = 2, doublePI = Math.PI * double;
|
|
7
10
|
export function addEasing(name, easing) {
|
|
8
|
-
if (
|
|
11
|
+
if (easingFunctions.get(name)) {
|
|
9
12
|
return;
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
easingFunctions.set(name, easing);
|
|
12
15
|
}
|
|
13
16
|
export function getEasing(name) {
|
|
14
|
-
return
|
|
17
|
+
return easingFunctions.get(name) ?? ((value) => value);
|
|
15
18
|
}
|
|
16
19
|
export function setRandom(rnd = Math.random) {
|
|
17
20
|
_random = rnd;
|
|
@@ -20,6 +23,16 @@ export function getRandom() {
|
|
|
20
23
|
const min = 0, max = 1;
|
|
21
24
|
return clamp(_random(), min, max - Number.EPSILON);
|
|
22
25
|
}
|
|
26
|
+
export function setAnimationFunctions(nextFrame, cancel) {
|
|
27
|
+
_animationLoop.nextFrame = (callback) => nextFrame(callback);
|
|
28
|
+
_animationLoop.cancel = (handle) => cancel(handle);
|
|
29
|
+
}
|
|
30
|
+
export function animate(fn) {
|
|
31
|
+
return _animationLoop.nextFrame(fn);
|
|
32
|
+
}
|
|
33
|
+
export function cancelAnimation(handle) {
|
|
34
|
+
_animationLoop.cancel(handle);
|
|
35
|
+
}
|
|
23
36
|
export function clamp(num, min, max) {
|
|
24
37
|
return Math.min(Math.max(num, min), max);
|
|
25
38
|
}
|
package/cjs/Core/Canvas.js
CHANGED
|
@@ -25,9 +25,6 @@ function setStyle(canvas, style, important = false) {
|
|
|
25
25
|
}
|
|
26
26
|
for (const key in style) {
|
|
27
27
|
const value = style[key];
|
|
28
|
-
if (!value) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
28
|
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
32
29
|
}
|
|
33
30
|
}
|
|
@@ -211,10 +208,11 @@ class Canvas {
|
|
|
211
208
|
if (!element) {
|
|
212
209
|
return;
|
|
213
210
|
}
|
|
214
|
-
const radix = 10;
|
|
211
|
+
const radix = 10, zIndex = this.container.actualOptions.fullScreen.zIndex.toString(radix);
|
|
215
212
|
setStyle(element, {
|
|
216
213
|
position: "fixed",
|
|
217
|
-
|
|
214
|
+
"z-index": zIndex,
|
|
215
|
+
zIndex: zIndex,
|
|
218
216
|
top: "0",
|
|
219
217
|
left: "0",
|
|
220
218
|
width: "100%",
|
|
@@ -381,7 +379,7 @@ class Canvas {
|
|
|
381
379
|
}
|
|
382
380
|
initPlugins() {
|
|
383
381
|
this._resizePlugins = [];
|
|
384
|
-
for (const
|
|
382
|
+
for (const plugin of this.container.plugins.values()) {
|
|
385
383
|
if (plugin.resize) {
|
|
386
384
|
this._resizePlugins.push(plugin);
|
|
387
385
|
}
|
package/cjs/Core/Container.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Container = void 0;
|
|
4
|
+
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
4
5
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
5
6
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
6
7
|
const Canvas_js_1 = require("./Canvas.js");
|
|
@@ -9,7 +10,6 @@ const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
|
9
10
|
const Options_js_1 = require("../Options/Classes/Options.js");
|
|
10
11
|
const Particles_js_1 = require("./Particles.js");
|
|
11
12
|
const Retina_js_1 = require("./Retina.js");
|
|
12
|
-
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
13
13
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
14
14
|
function guardCheck(container) {
|
|
15
15
|
return container && !container.destroyed;
|
|
@@ -223,10 +223,10 @@ class Container {
|
|
|
223
223
|
this.clearClickHandlers();
|
|
224
224
|
this.particles.destroy();
|
|
225
225
|
this.canvas.destroy();
|
|
226
|
-
for (const
|
|
226
|
+
for (const effectDrawer of this.effectDrawers.values()) {
|
|
227
227
|
effectDrawer.destroy?.(this);
|
|
228
228
|
}
|
|
229
|
-
for (const
|
|
229
|
+
for (const shapeDrawer of this.shapeDrawers.values()) {
|
|
230
230
|
shapeDrawer.destroy?.(this);
|
|
231
231
|
}
|
|
232
232
|
for (const key of this.effectDrawers.keys()) {
|
|
@@ -258,10 +258,10 @@ class Container {
|
|
|
258
258
|
}
|
|
259
259
|
this._nextFrame(timestamp);
|
|
260
260
|
};
|
|
261
|
-
this._drawAnimationFrame =
|
|
261
|
+
this._drawAnimationFrame = (0, NumberUtils_js_1.animate)(timestamp => frame(timestamp));
|
|
262
262
|
}
|
|
263
263
|
async export(type, options = {}) {
|
|
264
|
-
for (const
|
|
264
|
+
for (const plugin of this.plugins.values()) {
|
|
265
265
|
if (!plugin.export) {
|
|
266
266
|
continue;
|
|
267
267
|
}
|
|
@@ -278,7 +278,7 @@ class Container {
|
|
|
278
278
|
return;
|
|
279
279
|
}
|
|
280
280
|
this.particles.handleClickMode(mode);
|
|
281
|
-
for (const
|
|
281
|
+
for (const plugin of this.plugins.values()) {
|
|
282
282
|
plugin.handleClickMode?.(mode);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
@@ -320,19 +320,19 @@ class Container {
|
|
|
320
320
|
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
321
321
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
322
322
|
this._smooth = smooth;
|
|
323
|
-
for (const
|
|
323
|
+
for (const drawer of this.effectDrawers.values()) {
|
|
324
324
|
await drawer.init?.(this);
|
|
325
325
|
}
|
|
326
|
-
for (const
|
|
326
|
+
for (const drawer of this.shapeDrawers.values()) {
|
|
327
327
|
await drawer.init?.(this);
|
|
328
328
|
}
|
|
329
|
-
for (const
|
|
329
|
+
for (const plugin of this.plugins.values()) {
|
|
330
330
|
await plugin.init?.();
|
|
331
331
|
}
|
|
332
332
|
this._engine.dispatchEvent(EventType_js_1.EventType.containerInit, { container: this });
|
|
333
333
|
await this.particles.init();
|
|
334
334
|
this.particles.setDensity();
|
|
335
|
-
for (const
|
|
335
|
+
for (const plugin of this.plugins.values()) {
|
|
336
336
|
plugin.particlesSetup?.();
|
|
337
337
|
}
|
|
338
338
|
this._engine.dispatchEvent(EventType_js_1.EventType.particlesSetup, { container: this });
|
|
@@ -349,13 +349,13 @@ class Container {
|
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
351
351
|
if (this._drawAnimationFrame !== undefined) {
|
|
352
|
-
|
|
352
|
+
(0, NumberUtils_js_1.cancelAnimation)(this._drawAnimationFrame);
|
|
353
353
|
delete this._drawAnimationFrame;
|
|
354
354
|
}
|
|
355
355
|
if (this._paused) {
|
|
356
356
|
return;
|
|
357
357
|
}
|
|
358
|
-
for (const
|
|
358
|
+
for (const plugin of this.plugins.values()) {
|
|
359
359
|
plugin.pause?.();
|
|
360
360
|
}
|
|
361
361
|
if (!this.pageHidden) {
|
|
@@ -376,7 +376,7 @@ class Container {
|
|
|
376
376
|
this._paused = false;
|
|
377
377
|
}
|
|
378
378
|
if (needsUpdate) {
|
|
379
|
-
for (const
|
|
379
|
+
for (const plugin of this.plugins.values()) {
|
|
380
380
|
if (plugin.play) {
|
|
381
381
|
plugin.play();
|
|
382
382
|
}
|
|
@@ -414,7 +414,7 @@ class Container {
|
|
|
414
414
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
415
415
|
this._intersectionObserver.observe(this.interactivity.element);
|
|
416
416
|
}
|
|
417
|
-
for (const
|
|
417
|
+
for (const plugin of this.plugins.values()) {
|
|
418
418
|
await plugin.start?.();
|
|
419
419
|
}
|
|
420
420
|
this._engine.dispatchEvent(EventType_js_1.EventType.containerStarted, { container: this });
|
|
@@ -441,7 +441,7 @@ class Container {
|
|
|
441
441
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
442
442
|
this._intersectionObserver.unobserve(this.interactivity.element);
|
|
443
443
|
}
|
|
444
|
-
for (const
|
|
444
|
+
for (const plugin of this.plugins.values()) {
|
|
445
445
|
plugin.stop?.();
|
|
446
446
|
}
|
|
447
447
|
for (const key of this.plugins.keys()) {
|
package/cjs/Core/Engine.js
CHANGED
package/cjs/Core/Particle.js
CHANGED
|
@@ -51,7 +51,7 @@ class Particle {
|
|
|
51
51
|
constructor(engine, container) {
|
|
52
52
|
this.container = container;
|
|
53
53
|
this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
|
|
54
|
-
for (const
|
|
54
|
+
for (const plugin of container.plugins.values()) {
|
|
55
55
|
const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
|
56
56
|
if (pluginPos) {
|
|
57
57
|
return Vectors_js_1.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
|
|
@@ -169,7 +169,7 @@ class Particle {
|
|
|
169
169
|
this.slow.inRange = false;
|
|
170
170
|
const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
171
171
|
shapeDrawer?.particleDestroy?.(this);
|
|
172
|
-
for (const
|
|
172
|
+
for (const plugin of container.plugins.values()) {
|
|
173
173
|
plugin.particleDestroyed?.(this, override);
|
|
174
174
|
}
|
|
175
175
|
for (const updater of container.particles.updaters) {
|
|
@@ -185,7 +185,7 @@ class Particle {
|
|
|
185
185
|
}
|
|
186
186
|
draw(delta) {
|
|
187
187
|
const container = this.container, canvas = container.canvas;
|
|
188
|
-
for (const
|
|
188
|
+
for (const plugin of container.plugins.values()) {
|
|
189
189
|
canvas.drawParticlePlugin(plugin, this, delta);
|
|
190
190
|
}
|
|
191
191
|
canvas.drawParticle(this, delta);
|
|
@@ -337,7 +337,7 @@ class Particle {
|
|
|
337
337
|
}
|
|
338
338
|
effectDrawer?.particleInit?.(container, this);
|
|
339
339
|
shapeDrawer?.particleInit?.(container, this);
|
|
340
|
-
for (const
|
|
340
|
+
for (const plugin of container.plugins.values()) {
|
|
341
341
|
plugin.particleCreated?.(this);
|
|
342
342
|
}
|
|
343
343
|
}
|
package/cjs/Core/Particles.js
CHANGED
|
@@ -125,7 +125,7 @@ class Particles {
|
|
|
125
125
|
options.manualParticles.forEach(p => this.addParticle(p.position ? (0, Utils_js_1.getPosition)(p.position, container.canvas.size) : undefined, p.options));
|
|
126
126
|
}
|
|
127
127
|
addParticle(position, overrideOptions, group, initializer) {
|
|
128
|
-
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit, currentCount = this.count, minLimit = 0;
|
|
128
|
+
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count, minLimit = 0;
|
|
129
129
|
if (limit > minLimit) {
|
|
130
130
|
switch (limitMode) {
|
|
131
131
|
case LimitMode_js_1.LimitMode.delete: {
|
|
@@ -159,7 +159,7 @@ class Particles {
|
|
|
159
159
|
const container = this._container, canvas = container.canvas;
|
|
160
160
|
canvas.clear();
|
|
161
161
|
this.update(delta);
|
|
162
|
-
for (const
|
|
162
|
+
for (const plugin of container.plugins.values()) {
|
|
163
163
|
canvas.drawPlugin(plugin, delta);
|
|
164
164
|
}
|
|
165
165
|
for (const p of this._zArray) {
|
|
@@ -184,7 +184,7 @@ class Particles {
|
|
|
184
184
|
this._needsSort = false;
|
|
185
185
|
await this.initPlugins();
|
|
186
186
|
let handled = false;
|
|
187
|
-
for (const
|
|
187
|
+
for (const plugin of container.plugins.values()) {
|
|
188
188
|
handled = plugin.particlesInitialization?.() ?? handled;
|
|
189
189
|
if (handled) {
|
|
190
190
|
break;
|
|
@@ -212,7 +212,7 @@ class Particles {
|
|
|
212
212
|
this.movers = await this._engine.getMovers(container, true);
|
|
213
213
|
this.updaters = await this._engine.getUpdaters(container, true);
|
|
214
214
|
await this._interactionManager.init();
|
|
215
|
-
for (const
|
|
215
|
+
for (const pathGenerator of container.pathGenerators.values()) {
|
|
216
216
|
pathGenerator.init(container);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
@@ -236,7 +236,8 @@ class Particles {
|
|
|
236
236
|
}
|
|
237
237
|
let deleted = 0;
|
|
238
238
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
239
|
-
if (this._removeParticle(i
|
|
239
|
+
if (this._removeParticle(i, group, override)) {
|
|
240
|
+
i--;
|
|
240
241
|
deleted++;
|
|
241
242
|
}
|
|
242
243
|
}
|
|
@@ -262,10 +263,10 @@ class Particles {
|
|
|
262
263
|
update(delta) {
|
|
263
264
|
const container = this._container, particlesToDelete = new Set();
|
|
264
265
|
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
|
|
265
|
-
for (const
|
|
266
|
+
for (const pathGenerator of container.pathGenerators.values()) {
|
|
266
267
|
pathGenerator.update();
|
|
267
268
|
}
|
|
268
|
-
for (const
|
|
269
|
+
for (const plugin of container.plugins.values()) {
|
|
269
270
|
plugin.update?.(delta);
|
|
270
271
|
}
|
|
271
272
|
const resizeFactor = this._resizeFactor;
|
|
@@ -278,7 +279,7 @@ class Particles {
|
|
|
278
279
|
}
|
|
279
280
|
particle.ignoresResizeRatio = false;
|
|
280
281
|
this._interactionManager.reset(particle);
|
|
281
|
-
for (const
|
|
282
|
+
for (const plugin of this._container.plugins.values()) {
|
|
282
283
|
if (particle.destroyed) {
|
|
283
284
|
break;
|
|
284
285
|
}
|
|
@@ -190,7 +190,7 @@ class EventListeners {
|
|
|
190
190
|
if (!mousePosition || !options.interactivity.events.onClick.enable) {
|
|
191
191
|
return;
|
|
192
192
|
}
|
|
193
|
-
for (const
|
|
193
|
+
for (const plugin of container.plugins.values()) {
|
|
194
194
|
if (!plugin.clickPositionValid) {
|
|
195
195
|
continue;
|
|
196
196
|
}
|