@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
@@ -9,58 +9,58 @@ function setTransformValue(factor, newFactor, key) {
9
9
  }
10
10
  }
11
11
  export class RenderManager {
12
- _canvasClearPlugins;
13
- _canvasManager;
14
- _canvasPaintPlugins;
15
- _clearDrawPlugins;
16
- _colorPlugins;
17
- _container;
18
- _context;
19
- _contextSettings;
20
- _drawParticlePlugins;
21
- _drawParticlesCleanupPlugins;
22
- _drawParticlesSetupPlugins;
23
- _drawPlugins;
24
- _drawSettingsCleanupPlugins;
25
- _drawSettingsSetupPlugins;
26
- _pluginManager;
27
- _postDrawUpdaters;
28
- _preDrawUpdaters;
29
- _reusableColorStyles = {};
30
- _reusablePluginColors = [undefined, undefined];
31
- _reusableTransform = {};
12
+ #canvasClearPlugins;
13
+ #canvasManager;
14
+ #canvasPaintPlugins;
15
+ #clearDrawPlugins;
16
+ #colorPlugins;
17
+ #container;
18
+ #context;
19
+ #contextSettings;
20
+ #drawParticlePlugins;
21
+ #drawParticlesCleanupPlugins;
22
+ #drawParticlesSetupPlugins;
23
+ #drawPlugins;
24
+ #drawSettingsCleanupPlugins;
25
+ #drawSettingsSetupPlugins;
26
+ #pluginManager;
27
+ #postDrawUpdaters;
28
+ #preDrawUpdaters;
29
+ #reusableColorStyles = {};
30
+ #reusablePluginColors = [undefined, undefined];
31
+ #reusableTransform = {};
32
32
  constructor(pluginManager, container, canvasManager) {
33
- this._pluginManager = pluginManager;
34
- this._container = container;
35
- this._canvasManager = canvasManager;
36
- this._context = null;
37
- this._preDrawUpdaters = [];
38
- this._postDrawUpdaters = [];
39
- this._colorPlugins = [];
40
- this._canvasClearPlugins = [];
41
- this._canvasPaintPlugins = [];
42
- this._clearDrawPlugins = [];
43
- this._drawParticlePlugins = [];
44
- this._drawParticlesCleanupPlugins = [];
45
- this._drawParticlesSetupPlugins = [];
46
- this._drawPlugins = [];
47
- this._drawSettingsSetupPlugins = [];
48
- this._drawSettingsCleanupPlugins = [];
33
+ this.#pluginManager = pluginManager;
34
+ this.#container = container;
35
+ this.#canvasManager = canvasManager;
36
+ this.#context = null;
37
+ this.#preDrawUpdaters = [];
38
+ this.#postDrawUpdaters = [];
39
+ this.#colorPlugins = [];
40
+ this.#canvasClearPlugins = [];
41
+ this.#canvasPaintPlugins = [];
42
+ this.#clearDrawPlugins = [];
43
+ this.#drawParticlePlugins = [];
44
+ this.#drawParticlesCleanupPlugins = [];
45
+ this.#drawParticlesSetupPlugins = [];
46
+ this.#drawPlugins = [];
47
+ this.#drawSettingsSetupPlugins = [];
48
+ this.#drawSettingsCleanupPlugins = [];
49
49
  }
50
50
  get settings() {
51
- return this._contextSettings;
51
+ return this.#contextSettings;
52
52
  }
53
53
  canvasClear() {
54
- if (!this._container.actualOptions.clear) {
54
+ if (!this.#container.actualOptions.clear) {
55
55
  return;
56
56
  }
57
57
  this.draw(ctx => {
58
- clear(ctx, this._canvasManager.size);
58
+ clear(ctx, this.#canvasManager.size);
59
59
  });
60
60
  }
61
61
  clear() {
62
62
  let pluginHandled = false;
63
- for (const plugin of this._canvasClearPlugins) {
63
+ for (const plugin of this.#canvasClearPlugins) {
64
64
  pluginHandled = plugin.canvasClear?.() ?? false;
65
65
  if (pluginHandled) {
66
66
  break;
@@ -73,21 +73,21 @@ export class RenderManager {
73
73
  }
74
74
  destroy() {
75
75
  this.stop();
76
- this._preDrawUpdaters = [];
77
- this._postDrawUpdaters = [];
78
- this._colorPlugins = [];
79
- this._canvasClearPlugins = [];
80
- this._canvasPaintPlugins = [];
81
- this._clearDrawPlugins = [];
82
- this._drawParticlePlugins = [];
83
- this._drawParticlesCleanupPlugins = [];
84
- this._drawParticlesSetupPlugins = [];
85
- this._drawPlugins = [];
86
- this._drawSettingsSetupPlugins = [];
87
- this._drawSettingsCleanupPlugins = [];
76
+ this.#preDrawUpdaters = [];
77
+ this.#postDrawUpdaters = [];
78
+ this.#colorPlugins = [];
79
+ this.#canvasClearPlugins = [];
80
+ this.#canvasPaintPlugins = [];
81
+ this.#clearDrawPlugins = [];
82
+ this.#drawParticlePlugins = [];
83
+ this.#drawParticlesCleanupPlugins = [];
84
+ this.#drawParticlesSetupPlugins = [];
85
+ this.#drawPlugins = [];
86
+ this.#drawSettingsSetupPlugins = [];
87
+ this.#drawSettingsCleanupPlugins = [];
88
88
  }
89
89
  draw(cb) {
90
- const ctx = this._context;
90
+ const ctx = this.#context;
91
91
  if (!ctx) {
92
92
  return;
93
93
  }
@@ -102,21 +102,21 @@ export class RenderManager {
102
102
  return;
103
103
  }
104
104
  const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
105
- let [fColor, sColor] = this._getPluginParticleColors(particle);
105
+ let [fColor, sColor] = this.#getPluginParticleColors(particle);
106
106
  fColor ??= pfColor;
107
107
  sColor ??= psColor;
108
108
  if (!fColor && !sColor) {
109
109
  return;
110
110
  }
111
- const container = this._container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
111
+ const container = this.#container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this.#reusableTransform, colorStyles = this.#reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
112
112
  transform.a = transform.b = transform.c = transform.d = undefined;
113
113
  colorStyles.fill = fill;
114
114
  colorStyles.stroke = stroke;
115
115
  this.draw((context) => {
116
- for (const plugin of this._drawParticlesSetupPlugins) {
116
+ for (const plugin of this.#drawParticlesSetupPlugins) {
117
117
  plugin.drawParticleSetup?.(context, particle, delta);
118
118
  }
119
- this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
119
+ this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
120
120
  drawParticle({
121
121
  container,
122
122
  context,
@@ -127,35 +127,35 @@ export class RenderManager {
127
127
  opacity: opacity,
128
128
  transform,
129
129
  });
130
- this._applyPostDrawUpdaters(particle);
131
- for (const plugin of this._drawParticlesCleanupPlugins) {
130
+ this.#applyPostDrawUpdaters(particle);
131
+ for (const plugin of this.#drawParticlesCleanupPlugins) {
132
132
  plugin.drawParticleCleanup?.(context, particle, delta);
133
133
  }
134
134
  });
135
135
  }
136
136
  drawParticlePlugins(particle, delta) {
137
137
  this.draw(ctx => {
138
- for (const plugin of this._drawParticlePlugins) {
138
+ for (const plugin of this.#drawParticlePlugins) {
139
139
  drawParticlePlugin(ctx, plugin, particle, delta);
140
140
  }
141
141
  });
142
142
  }
143
143
  drawParticles(delta) {
144
- const { particles } = this._container;
144
+ const { particles } = this.#container;
145
145
  this.clear();
146
146
  particles.update(delta);
147
147
  this.draw(ctx => {
148
- for (const plugin of this._drawSettingsSetupPlugins) {
148
+ for (const plugin of this.#drawSettingsSetupPlugins) {
149
149
  plugin.drawSettingsSetup?.(ctx, delta);
150
150
  }
151
- for (const plugin of this._drawPlugins) {
151
+ for (const plugin of this.#drawPlugins) {
152
152
  plugin.draw?.(ctx, delta);
153
153
  }
154
154
  particles.drawParticles(delta);
155
- for (const plugin of this._clearDrawPlugins) {
155
+ for (const plugin of this.#clearDrawPlugins) {
156
156
  plugin.clearDraw?.(ctx, delta);
157
157
  }
158
- for (const plugin of this._drawSettingsCleanupPlugins) {
158
+ for (const plugin of this.#drawSettingsCleanupPlugins) {
159
159
  plugin.drawSettingsCleanup?.(ctx, delta);
160
160
  }
161
161
  });
@@ -166,64 +166,64 @@ export class RenderManager {
166
166
  this.paint();
167
167
  }
168
168
  initPlugins() {
169
- this._colorPlugins = [];
170
- this._canvasClearPlugins = [];
171
- this._canvasPaintPlugins = [];
172
- this._clearDrawPlugins = [];
173
- this._drawParticlePlugins = [];
174
- this._drawParticlesSetupPlugins = [];
175
- this._drawParticlesCleanupPlugins = [];
176
- this._drawPlugins = [];
177
- this._drawSettingsSetupPlugins = [];
178
- this._drawSettingsCleanupPlugins = [];
179
- for (const plugin of this._container.plugins) {
169
+ this.#colorPlugins = [];
170
+ this.#canvasClearPlugins = [];
171
+ this.#canvasPaintPlugins = [];
172
+ this.#clearDrawPlugins = [];
173
+ this.#drawParticlePlugins = [];
174
+ this.#drawParticlesSetupPlugins = [];
175
+ this.#drawParticlesCleanupPlugins = [];
176
+ this.#drawPlugins = [];
177
+ this.#drawSettingsSetupPlugins = [];
178
+ this.#drawSettingsCleanupPlugins = [];
179
+ for (const plugin of this.#container.plugins) {
180
180
  if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
181
- this._colorPlugins.push(plugin);
181
+ this.#colorPlugins.push(plugin);
182
182
  }
183
183
  if (plugin.canvasClear) {
184
- this._canvasClearPlugins.push(plugin);
184
+ this.#canvasClearPlugins.push(plugin);
185
185
  }
186
186
  if (plugin.canvasPaint) {
187
- this._canvasPaintPlugins.push(plugin);
187
+ this.#canvasPaintPlugins.push(plugin);
188
188
  }
189
189
  if (plugin.drawParticle) {
190
- this._drawParticlePlugins.push(plugin);
190
+ this.#drawParticlePlugins.push(plugin);
191
191
  }
192
192
  if (plugin.drawParticleSetup) {
193
- this._drawParticlesSetupPlugins.push(plugin);
193
+ this.#drawParticlesSetupPlugins.push(plugin);
194
194
  }
195
195
  if (plugin.drawParticleCleanup) {
196
- this._drawParticlesCleanupPlugins.push(plugin);
196
+ this.#drawParticlesCleanupPlugins.push(plugin);
197
197
  }
198
198
  if (plugin.draw) {
199
- this._drawPlugins.push(plugin);
199
+ this.#drawPlugins.push(plugin);
200
200
  }
201
201
  if (plugin.drawSettingsSetup) {
202
- this._drawSettingsSetupPlugins.push(plugin);
202
+ this.#drawSettingsSetupPlugins.push(plugin);
203
203
  }
204
204
  if (plugin.drawSettingsCleanup) {
205
- this._drawSettingsCleanupPlugins.push(plugin);
205
+ this.#drawSettingsCleanupPlugins.push(plugin);
206
206
  }
207
207
  if (plugin.clearDraw) {
208
- this._clearDrawPlugins.push(plugin);
208
+ this.#clearDrawPlugins.push(plugin);
209
209
  }
210
210
  }
211
211
  }
212
212
  initUpdaters() {
213
- this._preDrawUpdaters = [];
214
- this._postDrawUpdaters = [];
215
- for (const updater of this._container.particleUpdaters) {
213
+ this.#preDrawUpdaters = [];
214
+ this.#postDrawUpdaters = [];
215
+ for (const updater of this.#container.particleUpdaters) {
216
216
  if (updater.afterDraw) {
217
- this._postDrawUpdaters.push(updater);
217
+ this.#postDrawUpdaters.push(updater);
218
218
  }
219
219
  if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
220
- this._preDrawUpdaters.push(updater);
220
+ this.#preDrawUpdaters.push(updater);
221
221
  }
222
222
  }
223
223
  }
224
224
  paint() {
225
225
  let handled = false;
226
- for (const plugin of this._canvasPaintPlugins) {
226
+ for (const plugin of this.#canvasPaintPlugins) {
227
227
  handled = plugin.canvasPaint?.() ?? false;
228
228
  if (handled) {
229
229
  break;
@@ -236,35 +236,35 @@ export class RenderManager {
236
236
  }
237
237
  paintBase(baseColor) {
238
238
  this.draw(ctx => {
239
- paintBase(ctx, this._canvasManager.size, baseColor);
239
+ paintBase(ctx, this.#canvasManager.size, baseColor);
240
240
  });
241
241
  }
242
242
  paintImage(image, opacity) {
243
243
  this.draw(ctx => {
244
- paintImage(ctx, this._canvasManager.size, image, opacity);
244
+ paintImage(ctx, this.#canvasManager.size, image, opacity);
245
245
  });
246
246
  }
247
247
  setContext(context) {
248
- this._context = context;
249
- if (this._context) {
250
- this._context.globalCompositeOperation = defaultCompositeValue;
248
+ this.#context = context;
249
+ if (this.#context) {
250
+ this.#context.globalCompositeOperation = defaultCompositeValue;
251
251
  }
252
252
  }
253
253
  setContextSettings(settings) {
254
- this._contextSettings = settings;
254
+ this.#contextSettings = settings;
255
255
  }
256
256
  stop() {
257
257
  this.draw(ctx => {
258
- clear(ctx, this._canvasManager.size);
258
+ clear(ctx, this.#canvasManager.size);
259
259
  });
260
260
  }
261
- _applyPostDrawUpdaters = particle => {
262
- for (const updater of this._postDrawUpdaters) {
261
+ #applyPostDrawUpdaters = particle => {
262
+ for (const updater of this.#postDrawUpdaters) {
263
263
  updater.afterDraw?.(particle);
264
264
  }
265
265
  };
266
- _applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
267
- for (const updater of this._preDrawUpdaters) {
266
+ #applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
267
+ for (const updater of this.#preDrawUpdaters) {
268
268
  if (updater.getColorStyles) {
269
269
  const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
270
270
  if (fill) {
@@ -283,21 +283,21 @@ export class RenderManager {
283
283
  updater.beforeDraw?.(particle);
284
284
  }
285
285
  };
286
- _getPluginParticleColors = particle => {
286
+ #getPluginParticleColors = particle => {
287
287
  let fColor, sColor;
288
- for (const plugin of this._colorPlugins) {
288
+ for (const plugin of this.#colorPlugins) {
289
289
  if (!fColor && plugin.particleFillColor) {
290
- fColor = rangeColorToHsl(this._pluginManager, plugin.particleFillColor(particle));
290
+ fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
291
291
  }
292
292
  if (!sColor && plugin.particleStrokeColor) {
293
- sColor = rangeColorToHsl(this._pluginManager, plugin.particleStrokeColor(particle));
293
+ sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
294
294
  }
295
295
  if (fColor && sColor) {
296
296
  break;
297
297
  }
298
298
  }
299
- this._reusablePluginColors[fColorIndex] = fColor;
300
- this._reusablePluginColors[sColorIndex] = sColor;
301
- return this._reusablePluginColors;
299
+ this.#reusablePluginColors[fColorIndex] = fColor;
300
+ this.#reusablePluginColors[sColorIndex] = sColor;
301
+ return this.#reusablePluginColors;
302
302
  };
303
303
  }
@@ -1,16 +1,16 @@
1
1
  import { defaultRatio, defaultReduceFactor } from "./Utils/Constants.js";
2
2
  import { getRangeValue } from "../Utils/MathUtils.js";
3
3
  export class Retina {
4
- container;
5
4
  pixelRatio;
6
5
  reduceFactor;
6
+ #container;
7
7
  constructor(container) {
8
- this.container = container;
8
+ this.#container = container;
9
9
  this.pixelRatio = defaultRatio;
10
10
  this.reduceFactor = defaultReduceFactor;
11
11
  }
12
12
  init() {
13
- const container = this.container, options = container.actualOptions;
13
+ const container = this.#container, options = container.actualOptions;
14
14
  this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
15
15
  this.reduceFactor = defaultReduceFactor;
16
16
  const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
@@ -24,7 +24,6 @@ export class Retina {
24
24
  props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
25
25
  props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
26
26
  props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
27
- props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
28
27
  const maxDistance = props.maxDistance;
29
28
  maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
30
29
  maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
@@ -1,29 +1,29 @@
1
1
  import { manageListener, safeDocument } from "../../Utils/Utils.js";
2
2
  import { millisecondsToSeconds, resizeEvent, visibilityChangeEvent } from "./Constants.js";
3
3
  export class EventListeners {
4
- container;
5
- _handlers;
6
- _resizeObserver;
7
- _resizeTimeout;
4
+ #container;
5
+ #handlers;
6
+ #resizeObserver;
7
+ #resizeTimeout;
8
8
  constructor(container) {
9
- this.container = container;
10
- this._handlers = {
9
+ this.#container = container;
10
+ this.#handlers = {
11
11
  visibilityChange: () => {
12
- this._handleVisibilityChange();
12
+ this.#handleVisibilityChange();
13
13
  },
14
14
  resize: () => {
15
- this._handleWindowResize();
15
+ this.#handleWindowResize();
16
16
  },
17
17
  };
18
18
  }
19
19
  addListeners() {
20
- this._manageListeners(true);
20
+ this.#manageListeners(true);
21
21
  }
22
22
  removeListeners() {
23
- this._manageListeners(false);
23
+ this.#manageListeners(false);
24
24
  }
25
- _handleVisibilityChange = () => {
26
- const container = this.container, options = container.actualOptions;
25
+ #handleVisibilityChange = () => {
26
+ const container = this.#container, options = container.actualOptions;
27
27
  if (!options.pauseOnBlur) {
28
28
  return;
29
29
  }
@@ -41,24 +41,24 @@ export class EventListeners {
41
41
  }
42
42
  }
43
43
  };
44
- _handleWindowResize = () => {
45
- if (this._resizeTimeout) {
46
- clearTimeout(this._resizeTimeout);
47
- delete this._resizeTimeout;
44
+ #handleWindowResize = () => {
45
+ if (this.#resizeTimeout) {
46
+ clearTimeout(this.#resizeTimeout);
47
+ this.#resizeTimeout = undefined;
48
48
  }
49
49
  const handleResize = async () => {
50
- const canvas = this.container.canvas;
50
+ const canvas = this.#container.canvas;
51
51
  await canvas.windowResize();
52
52
  };
53
- this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.resize.delay * millisecondsToSeconds);
53
+ this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
54
54
  };
55
- _manageListeners = add => {
56
- const handlers = this._handlers;
57
- this._manageResize(add);
55
+ #manageListeners = add => {
56
+ const handlers = this.#handlers;
57
+ this.#manageResize(add);
58
58
  manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
59
59
  };
60
- _manageResize = add => {
61
- const handlers = this._handlers, container = this.container, options = container.actualOptions;
60
+ #manageResize = add => {
61
+ const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
62
62
  if (!options.resize.enable) {
63
63
  return;
64
64
  }
@@ -67,22 +67,22 @@ export class EventListeners {
67
67
  return;
68
68
  }
69
69
  const canvasEl = container.canvas.domElement;
70
- if (this._resizeObserver && !add) {
70
+ if (this.#resizeObserver && !add) {
71
71
  if (canvasEl) {
72
- this._resizeObserver.unobserve(canvasEl);
72
+ this.#resizeObserver.unobserve(canvasEl);
73
73
  }
74
- this._resizeObserver.disconnect();
75
- delete this._resizeObserver;
74
+ this.#resizeObserver.disconnect();
75
+ this.#resizeObserver = undefined;
76
76
  }
77
- else if (!this._resizeObserver && add && canvasEl) {
78
- this._resizeObserver = new ResizeObserver((entries) => {
77
+ else if (!this.#resizeObserver && add && canvasEl) {
78
+ this.#resizeObserver = new ResizeObserver((entries) => {
79
79
  const entry = entries.find(e => e.target === canvasEl);
80
80
  if (!entry) {
81
81
  return;
82
82
  }
83
- this._handleWindowResize();
83
+ this.#handleWindowResize();
84
84
  });
85
- this._resizeObserver.observe(canvasEl);
85
+ this.#resizeObserver.observe(canvasEl);
86
86
  }
87
87
  };
88
88
  }
@@ -14,19 +14,19 @@ export class PluginManager {
14
14
  presets = new Map();
15
15
  shapeDrawers = new Map();
16
16
  updaters = new Map();
17
- _allLoadersSet = new Set();
18
- _configs = new Map();
19
- _engine;
20
- _executedSet = new Set();
21
- _initialized = false;
22
- _isRunningLoaders = false;
23
- _loadPromises = new Set();
17
+ #allLoadersSet = new Set();
18
+ #configs = new Map();
19
+ #engine;
20
+ #executedSet = new Set();
21
+ #initialized = false;
22
+ #isRunningLoaders = false;
23
+ #loadPromises = new Set();
24
24
  constructor(engine) {
25
- this._engine = engine;
25
+ this.#engine = engine;
26
26
  }
27
27
  get configs() {
28
28
  const res = {};
29
- for (const [name, config] of this._configs) {
29
+ for (const [name, config] of this.#configs) {
30
30
  res[name] = config;
31
31
  }
32
32
  return res;
@@ -36,8 +36,8 @@ export class PluginManager {
36
36
  }
37
37
  addConfig(config) {
38
38
  const key = config.key ?? config.name ?? "default";
39
- this._configs.set(key, config);
40
- this._engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
39
+ this.#configs.set(key, config);
40
+ this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
41
41
  }
42
42
  addEasing(name, easing) {
43
43
  if (this.easingFunctions.get(name)) {
@@ -98,21 +98,21 @@ export class PluginManager {
98
98
  return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
99
99
  }
100
100
  async init() {
101
- if (this._initialized || this._isRunningLoaders) {
101
+ if (this.#initialized || this.#isRunningLoaders) {
102
102
  return;
103
103
  }
104
- this._isRunningLoaders = true;
105
- this._executedSet = new Set();
106
- this._allLoadersSet = new Set(this._loadPromises);
104
+ this.#isRunningLoaders = true;
105
+ this.#executedSet = new Set();
106
+ this.#allLoadersSet = new Set(this.#loadPromises);
107
107
  try {
108
- for (const loader of this._allLoadersSet) {
109
- await this._runLoader(loader, this._executedSet, this._allLoadersSet);
108
+ for (const loader of this.#allLoadersSet) {
109
+ await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
110
110
  }
111
111
  }
112
112
  finally {
113
- this._loadPromises.clear();
114
- this._isRunningLoaders = false;
115
- this._initialized = true;
113
+ this.#loadPromises.clear();
114
+ this.#isRunningLoaders = false;
115
+ this.#initialized = true;
116
116
  }
117
117
  }
118
118
  loadParticlesOptions(container, options, ...sourceOptions) {
@@ -123,23 +123,23 @@ export class PluginManager {
123
123
  updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
124
124
  }
125
125
  async register(...loaders) {
126
- if (this._initialized) {
126
+ if (this.#initialized) {
127
127
  throw new Error("Register plugins can only be done before calling tsParticles.load()");
128
128
  }
129
129
  for (const loader of loaders) {
130
- if (this._isRunningLoaders) {
131
- await this._runLoader(loader, this._executedSet, this._allLoadersSet);
130
+ if (this.#isRunningLoaders) {
131
+ await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
132
132
  }
133
133
  else {
134
- this._loadPromises.add(loader);
134
+ this.#loadPromises.add(loader);
135
135
  }
136
136
  }
137
137
  }
138
- async _runLoader(loader, executed, allLoaders) {
138
+ async #runLoader(loader, executed, allLoaders) {
139
139
  if (executed.has(loader))
140
140
  return;
141
141
  executed.add(loader);
142
142
  allLoaders.add(loader);
143
- await loader(this._engine);
143
+ await loader(this.#engine);
144
144
  }
145
145
  }