@tsparticles/engine 4.0.5 → 4.1.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.
Files changed (102) hide show
  1. package/browser/Core/CanvasManager.js +72 -72
  2. package/browser/Core/Container.js +85 -85
  3. package/browser/Core/Engine.js +11 -11
  4. package/browser/Core/Particle.js +142 -63
  5. package/browser/Core/ParticlesManager.js +138 -138
  6. package/browser/Core/RenderManager.js +110 -110
  7. package/browser/Core/Retina.js +3 -4
  8. package/browser/Core/Utils/EventListeners.js +31 -31
  9. package/browser/Core/Utils/PluginManager.js +26 -26
  10. package/browser/Core/Utils/SpatialHashGrid.js +36 -36
  11. package/browser/Core/Utils/Vectors.js +3 -3
  12. package/browser/Options/Classes/Options.js +13 -13
  13. package/browser/Options/Classes/Particles/ParticlesOptions.js +11 -19
  14. package/browser/Utils/EventDispatcher.js +10 -10
  15. package/browser/exports.js +0 -4
  16. package/cjs/Core/CanvasManager.js +72 -72
  17. package/cjs/Core/Container.js +85 -85
  18. package/cjs/Core/Engine.js +11 -11
  19. package/cjs/Core/Particle.js +142 -63
  20. package/cjs/Core/ParticlesManager.js +138 -138
  21. package/cjs/Core/RenderManager.js +110 -110
  22. package/cjs/Core/Retina.js +3 -4
  23. package/cjs/Core/Utils/EventListeners.js +31 -31
  24. package/cjs/Core/Utils/PluginManager.js +26 -26
  25. package/cjs/Core/Utils/SpatialHashGrid.js +36 -36
  26. package/cjs/Core/Utils/Vectors.js +3 -3
  27. package/cjs/Options/Classes/Options.js +13 -13
  28. package/cjs/Options/Classes/Particles/ParticlesOptions.js +11 -19
  29. package/cjs/Utils/EventDispatcher.js +10 -10
  30. package/cjs/exports.js +0 -4
  31. package/esm/Core/CanvasManager.js +72 -72
  32. package/esm/Core/Container.js +85 -85
  33. package/esm/Core/Engine.js +11 -11
  34. package/esm/Core/Particle.js +142 -63
  35. package/esm/Core/ParticlesManager.js +138 -138
  36. package/esm/Core/RenderManager.js +110 -110
  37. package/esm/Core/Retina.js +3 -4
  38. package/esm/Core/Utils/EventListeners.js +31 -31
  39. package/esm/Core/Utils/PluginManager.js +26 -26
  40. package/esm/Core/Utils/SpatialHashGrid.js +36 -36
  41. package/esm/Core/Utils/Vectors.js +3 -3
  42. package/esm/Options/Classes/Options.js +13 -13
  43. package/esm/Options/Classes/Particles/ParticlesOptions.js +11 -19
  44. package/esm/Utils/EventDispatcher.js +10 -10
  45. package/esm/exports.js +0 -4
  46. package/package.json +1 -1
  47. package/report.html +1 -1
  48. package/tsparticles.engine.js +690 -697
  49. package/tsparticles.engine.min.js +1 -1
  50. package/types/Core/CanvasManager.d.ts +1 -16
  51. package/types/Core/Container.d.ts +1 -18
  52. package/types/Core/Engine.d.ts +1 -3
  53. package/types/Core/Interfaces/IEffectDrawer.d.ts +2 -0
  54. package/types/Core/Interfaces/IParticleCanvasBounds.d.ts +16 -0
  55. package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -0
  56. package/types/Core/Interfaces/IShapeDrawer.d.ts +2 -0
  57. package/types/Core/Particle.d.ts +5 -13
  58. package/types/Core/ParticlesManager.d.ts +1 -28
  59. package/types/Core/RenderManager.d.ts +1 -23
  60. package/types/Core/Retina.d.ts +1 -1
  61. package/types/Core/Utils/EventListeners.d.ts +1 -8
  62. package/types/Core/Utils/PluginManager.d.ts +1 -8
  63. package/types/Core/Utils/SpatialHashGrid.d.ts +1 -12
  64. package/types/Core/Utils/Vectors.d.ts +1 -1
  65. package/types/Options/Classes/Options.d.ts +1 -4
  66. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -7
  67. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -4
  68. package/types/Utils/EventDispatcher.d.ts +1 -1
  69. package/types/export-types.d.ts +1 -4
  70. package/types/exports.d.ts +0 -4
  71. package/browser/Options/Classes/Particles/Opacity/Opacity.js +0 -21
  72. package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
  73. package/browser/Options/Classes/Particles/Size/Size.js +0 -21
  74. package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
  75. package/browser/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
  76. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +0 -21
  77. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
  78. package/cjs/Options/Classes/Particles/Size/Size.js +0 -21
  79. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
  80. package/cjs/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
  81. package/cjs/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
  82. package/cjs/Options/Interfaces/Particles/Size/ISize.js +0 -1
  83. package/cjs/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
  84. package/esm/Options/Classes/Particles/Opacity/Opacity.js +0 -21
  85. package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
  86. package/esm/Options/Classes/Particles/Size/Size.js +0 -21
  87. package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
  88. package/esm/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
  89. package/esm/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
  90. package/esm/Options/Interfaces/Particles/Size/ISize.js +0 -1
  91. package/esm/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
  92. package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +0 -10
  93. package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -10
  94. package/types/Options/Classes/Particles/Size/Size.d.ts +0 -10
  95. package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -10
  96. package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -5
  97. package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -5
  98. package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -5
  99. package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -5
  100. /package/browser/{Options/Interfaces/Particles/Opacity/IOpacity.js → Core/Interfaces/IParticleCanvasBounds.js} +0 -0
  101. /package/{browser/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js → cjs/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
  102. /package/{browser/Options/Interfaces/Particles/Size/ISize.js → esm/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
@@ -8,44 +8,44 @@ import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
8
8
  export class ParticlesManager {
9
9
  checkParticlePositionPlugins;
10
10
  grid;
11
- _array;
12
- _container;
13
- _groupLimits;
14
- _limit;
15
- _nextId;
16
- _particleBuckets;
17
- _particleResetPlugins;
18
- _particleUpdatePlugins;
19
- _pluginManager;
20
- _pool;
21
- _postParticleUpdatePlugins;
22
- _postUpdatePlugins;
23
- _resizeFactor;
24
- _updatePlugins;
25
- _zBuckets;
11
+ #array;
12
+ #container;
13
+ #groupLimits;
14
+ #limit;
15
+ #nextId;
16
+ #particleBuckets;
17
+ #particleResetPlugins;
18
+ #particleUpdatePlugins;
19
+ #pluginManager;
20
+ #pool;
21
+ #postParticleUpdatePlugins;
22
+ #postUpdatePlugins;
23
+ #resizeFactor;
24
+ #updatePlugins;
25
+ #zBuckets;
26
26
  constructor(pluginManager, container) {
27
- this._pluginManager = pluginManager;
28
- this._container = container;
29
- this._nextId = 0;
30
- this._array = [];
31
- this._pool = [];
32
- this._limit = 0;
33
- this._groupLimits = new Map();
34
- this._particleBuckets = new Map();
35
- this._zBuckets = this._createBuckets(this._container.zLayers);
27
+ this.#pluginManager = pluginManager;
28
+ this.#container = container;
29
+ this.#nextId = 0;
30
+ this.#array = [];
31
+ this.#pool = [];
32
+ this.#limit = 0;
33
+ this.#groupLimits = new Map();
34
+ this.#particleBuckets = new Map();
35
+ this.#zBuckets = this.#createBuckets(this.#container.zLayers);
36
36
  this.grid = new SpatialHashGrid(spatialHashGridCellSize);
37
37
  this.checkParticlePositionPlugins = [];
38
- this._particleResetPlugins = [];
39
- this._particleUpdatePlugins = [];
40
- this._postUpdatePlugins = [];
41
- this._postParticleUpdatePlugins = [];
42
- this._updatePlugins = [];
38
+ this.#particleResetPlugins = [];
39
+ this.#particleUpdatePlugins = [];
40
+ this.#postUpdatePlugins = [];
41
+ this.#postParticleUpdatePlugins = [];
42
+ this.#updatePlugins = [];
43
43
  }
44
44
  get count() {
45
- return this._array.length;
45
+ return this.#array.length;
46
46
  }
47
47
  addParticle(position, overrideOptions, group, initializer) {
48
- const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
48
+ const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
49
49
  if (limit > minLimit) {
50
50
  switch (limitMode) {
51
51
  case LimitMode.delete: {
@@ -65,20 +65,20 @@ export class ParticlesManager {
65
65
  }
66
66
  }
67
67
  try {
68
- const particle = this._pool.pop() ?? new Particle(this._pluginManager, this._container);
69
- particle.init(this._nextId, position, overrideOptions, group);
68
+ const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
69
+ particle.init(this.#nextId, position, overrideOptions, group);
70
70
  let canAdd = true;
71
71
  if (initializer) {
72
72
  canAdd = initializer(particle);
73
73
  }
74
74
  if (!canAdd) {
75
- this._pool.push(particle);
75
+ this.#pool.push(particle);
76
76
  return;
77
77
  }
78
- this._array.push(particle);
79
- this._insertParticleIntoBucket(particle);
80
- this._nextId++;
81
- this._container.dispatchEvent(EventType.particleAdded, {
78
+ this.#array.push(particle);
79
+ this.#insertParticleIntoBucket(particle);
80
+ this.#nextId++;
81
+ this.#container.dispatchEvent(EventType.particleAdded, {
82
82
  particle,
83
83
  });
84
84
  return particle;
@@ -89,25 +89,25 @@ export class ParticlesManager {
89
89
  return undefined;
90
90
  }
91
91
  clear() {
92
- this._array = [];
93
- this._particleBuckets.clear();
94
- this._resetBuckets(this._container.zLayers);
92
+ this.#array = [];
93
+ this.#particleBuckets.clear();
94
+ this.#resetBuckets(this.#container.zLayers);
95
95
  }
96
96
  destroy() {
97
- this._array = [];
98
- this._pool.length = 0;
99
- this._particleBuckets.clear();
100
- this._zBuckets = [];
97
+ this.#array = [];
98
+ this.#pool.length = 0;
99
+ this.#particleBuckets.clear();
100
+ this.#zBuckets = [];
101
101
  this.checkParticlePositionPlugins = [];
102
- this._particleResetPlugins = [];
103
- this._particleUpdatePlugins = [];
104
- this._postUpdatePlugins = [];
105
- this._postParticleUpdatePlugins = [];
106
- this._updatePlugins = [];
102
+ this.#particleResetPlugins = [];
103
+ this.#particleUpdatePlugins = [];
104
+ this.#postUpdatePlugins = [];
105
+ this.#postParticleUpdatePlugins = [];
106
+ this.#updatePlugins = [];
107
107
  }
108
108
  drawParticles(delta) {
109
- for (let i = this._zBuckets.length - one; i >= minIndex; i--) {
110
- const bucket = this._zBuckets[i];
109
+ for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
110
+ const bucket = this.#zBuckets[i];
111
111
  if (!bucket) {
112
112
  continue;
113
113
  }
@@ -117,24 +117,24 @@ export class ParticlesManager {
117
117
  }
118
118
  }
119
119
  filter(condition) {
120
- return this._array.filter(condition);
120
+ return this.#array.filter(condition);
121
121
  }
122
122
  find(condition) {
123
- return this._array.find(condition);
123
+ return this.#array.find(condition);
124
124
  }
125
125
  get(index) {
126
- return this._array[index];
126
+ return this.#array[index];
127
127
  }
128
128
  async init() {
129
- const container = this._container, options = container.actualOptions;
129
+ const container = this.#container, options = container.actualOptions;
130
130
  this.checkParticlePositionPlugins = [];
131
- this._updatePlugins = [];
132
- this._particleUpdatePlugins = [];
133
- this._postUpdatePlugins = [];
134
- this._particleResetPlugins = [];
135
- this._postParticleUpdatePlugins = [];
136
- this._particleBuckets.clear();
137
- this._resetBuckets(container.zLayers);
131
+ this.#updatePlugins = [];
132
+ this.#particleUpdatePlugins = [];
133
+ this.#postUpdatePlugins = [];
134
+ this.#particleResetPlugins = [];
135
+ this.#postParticleUpdatePlugins = [];
136
+ this.#particleBuckets.clear();
137
+ this.#resetBuckets(container.zLayers);
138
138
  this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
139
139
  for (const plugin of container.plugins) {
140
140
  if (plugin.redrawInit) {
@@ -144,26 +144,26 @@ export class ParticlesManager {
144
144
  this.checkParticlePositionPlugins.push(plugin);
145
145
  }
146
146
  if (plugin.update) {
147
- this._updatePlugins.push(plugin);
147
+ this.#updatePlugins.push(plugin);
148
148
  }
149
149
  if (plugin.particleUpdate) {
150
- this._particleUpdatePlugins.push(plugin);
150
+ this.#particleUpdatePlugins.push(plugin);
151
151
  }
152
152
  if (plugin.postUpdate) {
153
- this._postUpdatePlugins.push(plugin);
153
+ this.#postUpdatePlugins.push(plugin);
154
154
  }
155
155
  if (plugin.particleReset) {
156
- this._particleResetPlugins.push(plugin);
156
+ this.#particleResetPlugins.push(plugin);
157
157
  }
158
158
  if (plugin.postParticleUpdate) {
159
- this._postParticleUpdatePlugins.push(plugin);
159
+ this.#postParticleUpdatePlugins.push(plugin);
160
160
  }
161
161
  }
162
- await this._container.initDrawersAndUpdaters();
163
- for (const drawer of this._container.effectDrawers.values()) {
162
+ await this.#container.initDrawersAndUpdaters();
163
+ for (const drawer of this.#container.effectDrawers.values()) {
164
164
  await drawer.init?.(container);
165
165
  }
166
- for (const drawer of this._container.shapeDrawers.values()) {
166
+ for (const drawer of this.#container.shapeDrawers.values()) {
167
167
  await drawer.init?.(container);
168
168
  }
169
169
  let handled = false;
@@ -197,10 +197,10 @@ export class ParticlesManager {
197
197
  async redraw() {
198
198
  this.clear();
199
199
  await this.init();
200
- this._container.canvas.render.drawParticles({ value: 0, factor: 0 });
200
+ this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
201
201
  }
202
202
  remove(particle, group, override) {
203
- this.removeAt(this._array.indexOf(particle), undefined, group, override);
203
+ this.removeAt(this.#array.indexOf(particle), undefined, group, override);
204
204
  }
205
205
  removeAt(index, quantity = defaultRemoveQuantity, group, override) {
206
206
  if (index < minIndex || index > this.count) {
@@ -208,7 +208,7 @@ export class ParticlesManager {
208
208
  }
209
209
  let deleted = 0;
210
210
  for (let i = index; deleted < quantity && i < this.count; i++) {
211
- if (this._removeParticle(i, group, override)) {
211
+ if (this.#removeParticle(i, group, override)) {
212
212
  i--;
213
213
  deleted++;
214
214
  }
@@ -218,9 +218,9 @@ export class ParticlesManager {
218
218
  this.removeAt(minIndex, quantity, group);
219
219
  }
220
220
  setDensity() {
221
- const options = this._container.actualOptions, groups = options.particles.groups;
221
+ const options = this.#container.actualOptions, groups = options.particles.groups;
222
222
  let pluginsCount = 0;
223
- for (const plugin of this._container.plugins) {
223
+ for (const plugin of this.#container.plugins) {
224
224
  if (plugin.particlesDensityCount) {
225
225
  pluginsCount += plugin.particlesDensityCount();
226
226
  }
@@ -230,51 +230,51 @@ export class ParticlesManager {
230
230
  if (!groupData) {
231
231
  continue;
232
232
  }
233
- const groupDataOptions = loadParticlesOptions(this._pluginManager, this._container, groupData);
234
- this._applyDensity(groupDataOptions, pluginsCount, group);
233
+ const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
234
+ this.#applyDensity(groupDataOptions, pluginsCount, group);
235
235
  }
236
- this._applyDensity(options.particles, pluginsCount);
236
+ this.#applyDensity(options.particles, pluginsCount);
237
237
  }
238
238
  setResizeFactor(factor) {
239
- this._resizeFactor = factor;
239
+ this.#resizeFactor = factor;
240
240
  }
241
241
  update(delta) {
242
242
  this.grid.clear();
243
- for (const plugin of this._updatePlugins) {
243
+ for (const plugin of this.#updatePlugins) {
244
244
  plugin.update?.(delta);
245
245
  }
246
- const particlesToDelete = this._updateParticlesPhase1(delta);
247
- for (const plugin of this._postUpdatePlugins) {
246
+ const particlesToDelete = this.#updateParticlesPhase1(delta);
247
+ for (const plugin of this.#postUpdatePlugins) {
248
248
  plugin.postUpdate?.(delta);
249
249
  }
250
- this._updateParticlesPhase2(delta, particlesToDelete);
250
+ this.#updateParticlesPhase2(delta, particlesToDelete);
251
251
  if (particlesToDelete.size) {
252
252
  for (const particle of particlesToDelete) {
253
253
  this.remove(particle);
254
254
  }
255
255
  }
256
- delete this._resizeFactor;
256
+ this.#resizeFactor = undefined;
257
257
  }
258
- _addToPool = (...particles) => {
259
- this._pool.push(...particles);
258
+ #addToPool = (...particles) => {
259
+ this.#pool.push(...particles);
260
260
  };
261
- _applyDensity = (options, pluginsCount, group, groupOptions) => {
261
+ #applyDensity = (options, pluginsCount, group, groupOptions) => {
262
262
  const numberOptions = options.number;
263
263
  if (!numberOptions.density.enable) {
264
264
  if (group === undefined) {
265
- this._limit = numberOptions.limit.value;
265
+ this.#limit = numberOptions.limit.value;
266
266
  }
267
267
  else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
268
- this._groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
268
+ this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
269
269
  }
270
270
  return;
271
271
  }
272
- const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
272
+ const densityFactor = this.#initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
273
273
  if (group === undefined) {
274
- this._limit = numberOptions.limit.value * densityFactor;
274
+ this.#limit = numberOptions.limit.value * densityFactor;
275
275
  }
276
276
  else {
277
- this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
277
+ this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
278
278
  }
279
279
  if (particlesCount < particlesNumber) {
280
280
  this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
@@ -283,18 +283,18 @@ export class ParticlesManager {
283
283
  this.removeQuantity(particlesCount - particlesNumber, group);
284
284
  }
285
285
  };
286
- _createBuckets = (zLayers) => {
286
+ #createBuckets = (zLayers) => {
287
287
  const bucketCount = Math.max(Math.floor(zLayers), one);
288
288
  return Array.from({ length: bucketCount }, () => []);
289
289
  };
290
- _getBucketIndex = (zIndex) => {
291
- const maxBucketIndex = this._zBuckets.length - one;
290
+ #getBucketIndex = (zIndex) => {
291
+ const maxBucketIndex = this.#zBuckets.length - one;
292
292
  if (maxBucketIndex <= minIndex) {
293
293
  return minIndex;
294
294
  }
295
295
  return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
296
296
  };
297
- _getParticleInsertIndex = (bucket, particleId) => {
297
+ #getParticleInsertIndex = (bucket, particleId) => {
298
298
  let start = minIndex, end = bucket.length;
299
299
  while (start < end) {
300
300
  const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
@@ -311,8 +311,8 @@ export class ParticlesManager {
311
311
  }
312
312
  return start;
313
313
  };
314
- _initDensityFactor = densityOptions => {
315
- const container = this._container;
314
+ #initDensityFactor = densityOptions => {
315
+ const container = this.#container;
316
316
  if (!densityOptions.enable) {
317
317
  return defaultDensityFactor;
318
318
  }
@@ -322,82 +322,82 @@ export class ParticlesManager {
322
322
  }
323
323
  return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
324
324
  };
325
- _insertParticleIntoBucket = (particle) => {
326
- const bucketIndex = this._getBucketIndex(particle.position.z), bucket = this._zBuckets[bucketIndex];
325
+ #insertParticleIntoBucket = (particle) => {
326
+ const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
327
327
  if (!bucket) {
328
328
  return;
329
329
  }
330
- bucket.splice(this._getParticleInsertIndex(bucket, particle.id), empty, particle);
331
- this._particleBuckets.set(particle.id, bucketIndex);
330
+ bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
331
+ this.#particleBuckets.set(particle.id, bucketIndex);
332
332
  };
333
- _removeParticle = (index, group, override) => {
334
- const particle = this._array[index];
333
+ #removeParticle = (index, group, override) => {
334
+ const particle = this.#array[index];
335
335
  if (!particle) {
336
336
  return false;
337
337
  }
338
338
  if (particle.group !== group) {
339
339
  return false;
340
340
  }
341
- this._array.splice(index, deleteCount);
342
- this._removeParticleFromBucket(particle);
341
+ this.#array.splice(index, deleteCount);
342
+ this.#removeParticleFromBucket(particle);
343
343
  particle.destroy(override);
344
- this._container.dispatchEvent(EventType.particleRemoved, {
344
+ this.#container.dispatchEvent(EventType.particleRemoved, {
345
345
  particle,
346
346
  });
347
- this._addToPool(particle);
347
+ this.#addToPool(particle);
348
348
  return true;
349
349
  };
350
- _removeParticleFromBucket = (particle) => {
351
- const bucketIndex = this._particleBuckets.get(particle.id) ?? this._getBucketIndex(particle.position.z), bucket = this._zBuckets[bucketIndex];
350
+ #removeParticleFromBucket = (particle) => {
351
+ const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
352
352
  if (!bucket) {
353
- this._particleBuckets.delete(particle.id);
353
+ this.#particleBuckets.delete(particle.id);
354
354
  return;
355
355
  }
356
- const particleIndex = this._getParticleInsertIndex(bucket, particle.id);
356
+ const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
357
357
  if (bucket[particleIndex]?.id !== particle.id) {
358
- this._particleBuckets.delete(particle.id);
358
+ this.#particleBuckets.delete(particle.id);
359
359
  return;
360
360
  }
361
361
  bucket.splice(particleIndex, deleteCount);
362
- this._particleBuckets.delete(particle.id);
362
+ this.#particleBuckets.delete(particle.id);
363
363
  };
364
- _resetBuckets = (zLayers) => {
364
+ #resetBuckets = (zLayers) => {
365
365
  const bucketCount = Math.max(Math.floor(zLayers), one);
366
- if (this._zBuckets.length !== bucketCount) {
367
- this._zBuckets = this._createBuckets(bucketCount);
366
+ if (this.#zBuckets.length !== bucketCount) {
367
+ this.#zBuckets = this.#createBuckets(bucketCount);
368
368
  return;
369
369
  }
370
- for (const bucket of this._zBuckets) {
370
+ for (const bucket of this.#zBuckets) {
371
371
  bucket.length = minIndex;
372
372
  }
373
373
  };
374
- _updateParticleBucket = (particle) => {
375
- const newBucketIndex = this._getBucketIndex(particle.position.z), currentBucketIndex = this._particleBuckets.get(particle.id);
374
+ #updateParticleBucket = (particle) => {
375
+ const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
376
376
  if (currentBucketIndex === undefined) {
377
- this._insertParticleIntoBucket(particle);
377
+ this.#insertParticleIntoBucket(particle);
378
378
  return;
379
379
  }
380
380
  if (currentBucketIndex === newBucketIndex) {
381
381
  return;
382
382
  }
383
- const currentBucket = this._zBuckets[currentBucketIndex];
383
+ const currentBucket = this.#zBuckets[currentBucketIndex];
384
384
  if (currentBucket) {
385
- const particleIndex = this._getParticleInsertIndex(currentBucket, particle.id);
385
+ const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
386
386
  if (currentBucket[particleIndex]?.id === particle.id) {
387
387
  currentBucket.splice(particleIndex, deleteCount);
388
388
  }
389
389
  }
390
- const newBucket = this._zBuckets[newBucketIndex];
390
+ const newBucket = this.#zBuckets[newBucketIndex];
391
391
  if (!newBucket) {
392
- this._particleBuckets.set(particle.id, newBucketIndex);
392
+ this.#particleBuckets.set(particle.id, newBucketIndex);
393
393
  return;
394
394
  }
395
- newBucket.splice(this._getParticleInsertIndex(newBucket, particle.id), empty, particle);
396
- this._particleBuckets.set(particle.id, newBucketIndex);
395
+ newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
396
+ this.#particleBuckets.set(particle.id, newBucketIndex);
397
397
  };
398
- _updateParticlesPhase1 = (delta) => {
399
- const particlesToDelete = new Set(), resizeFactor = this._resizeFactor;
400
- for (const particle of this._array) {
398
+ #updateParticlesPhase1 = (delta) => {
399
+ const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
400
+ for (const particle of this.#array) {
401
401
  if (resizeFactor && !particle.ignoresResizeRatio) {
402
402
  particle.position.x *= resizeFactor.width;
403
403
  particle.position.y *= resizeFactor.height;
@@ -405,10 +405,10 @@ export class ParticlesManager {
405
405
  particle.initialPosition.y *= resizeFactor.height;
406
406
  }
407
407
  particle.ignoresResizeRatio = false;
408
- for (const plugin of this._particleResetPlugins) {
408
+ for (const plugin of this.#particleResetPlugins) {
409
409
  plugin.particleReset?.(particle);
410
410
  }
411
- for (const plugin of this._particleUpdatePlugins) {
411
+ for (const plugin of this.#particleUpdatePlugins) {
412
412
  if (particle.destroyed) {
413
413
  break;
414
414
  }
@@ -422,21 +422,21 @@ export class ParticlesManager {
422
422
  }
423
423
  return particlesToDelete;
424
424
  };
425
- _updateParticlesPhase2 = (delta, particlesToDelete) => {
426
- for (const particle of this._array) {
425
+ #updateParticlesPhase2 = (delta, particlesToDelete) => {
426
+ for (const particle of this.#array) {
427
427
  if (particle.destroyed) {
428
428
  particlesToDelete.add(particle);
429
429
  continue;
430
430
  }
431
- for (const updater of this._container.particleUpdaters) {
431
+ for (const updater of this.#container.particleUpdaters) {
432
432
  updater.update(particle, delta);
433
433
  }
434
434
  if (!particle.spawning) {
435
- for (const plugin of this._postParticleUpdatePlugins) {
435
+ for (const plugin of this.#postParticleUpdatePlugins) {
436
436
  plugin.postParticleUpdate?.(particle, delta);
437
437
  }
438
438
  }
439
- this._updateParticleBucket(particle);
439
+ this.#updateParticleBucket(particle);
440
440
  }
441
441
  };
442
442
  }