@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.
- package/browser/Core/CanvasManager.js +72 -72
- package/browser/Core/Container.js +85 -85
- package/browser/Core/Engine.js +11 -11
- package/browser/Core/Particle.js +142 -63
- package/browser/Core/ParticlesManager.js +138 -138
- package/browser/Core/RenderManager.js +110 -110
- package/browser/Core/Retina.js +3 -4
- package/browser/Core/Utils/EventListeners.js +31 -31
- package/browser/Core/Utils/PluginManager.js +26 -26
- package/browser/Core/Utils/SpatialHashGrid.js +36 -36
- package/browser/Core/Utils/Vectors.js +3 -3
- package/browser/Options/Classes/Options.js +13 -13
- package/browser/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/browser/Utils/EventDispatcher.js +10 -10
- package/browser/exports.js +0 -4
- package/cjs/Core/CanvasManager.js +72 -72
- package/cjs/Core/Container.js +85 -85
- package/cjs/Core/Engine.js +11 -11
- package/cjs/Core/Particle.js +142 -63
- package/cjs/Core/ParticlesManager.js +138 -138
- package/cjs/Core/RenderManager.js +110 -110
- package/cjs/Core/Retina.js +3 -4
- package/cjs/Core/Utils/EventListeners.js +31 -31
- package/cjs/Core/Utils/PluginManager.js +26 -26
- package/cjs/Core/Utils/SpatialHashGrid.js +36 -36
- package/cjs/Core/Utils/Vectors.js +3 -3
- package/cjs/Options/Classes/Options.js +13 -13
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/cjs/Utils/EventDispatcher.js +10 -10
- package/cjs/exports.js +0 -4
- package/esm/Core/CanvasManager.js +72 -72
- package/esm/Core/Container.js +85 -85
- package/esm/Core/Engine.js +11 -11
- package/esm/Core/Particle.js +142 -63
- package/esm/Core/ParticlesManager.js +138 -138
- package/esm/Core/RenderManager.js +110 -110
- package/esm/Core/Retina.js +3 -4
- package/esm/Core/Utils/EventListeners.js +31 -31
- package/esm/Core/Utils/PluginManager.js +26 -26
- package/esm/Core/Utils/SpatialHashGrid.js +36 -36
- package/esm/Core/Utils/Vectors.js +3 -3
- package/esm/Options/Classes/Options.js +13 -13
- package/esm/Options/Classes/Particles/ParticlesOptions.js +11 -19
- package/esm/Utils/EventDispatcher.js +10 -10
- package/esm/exports.js +0 -4
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +690 -697
- package/tsparticles.engine.min.js +1 -1
- package/types/Core/CanvasManager.d.ts +1 -16
- package/types/Core/Container.d.ts +1 -18
- package/types/Core/Engine.d.ts +1 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +2 -0
- package/types/Core/Interfaces/IParticleCanvasBounds.d.ts +16 -0
- package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -0
- package/types/Core/Interfaces/IShapeDrawer.d.ts +2 -0
- package/types/Core/Particle.d.ts +5 -13
- package/types/Core/ParticlesManager.d.ts +1 -28
- package/types/Core/RenderManager.d.ts +1 -23
- package/types/Core/Retina.d.ts +1 -1
- package/types/Core/Utils/EventListeners.d.ts +1 -8
- package/types/Core/Utils/PluginManager.d.ts +1 -8
- package/types/Core/Utils/SpatialHashGrid.d.ts +1 -12
- package/types/Core/Utils/Vectors.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +1 -4
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -7
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -4
- package/types/Utils/EventDispatcher.d.ts +1 -1
- package/types/export-types.d.ts +1 -4
- package/types/exports.d.ts +0 -4
- package/browser/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/browser/Options/Classes/Particles/Size/Size.js +0 -21
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/browser/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/cjs/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/cjs/Options/Classes/Particles/Size/Size.js +0 -21
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/cjs/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
- package/cjs/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
- package/cjs/Options/Interfaces/Particles/Size/ISize.js +0 -1
- package/cjs/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/esm/Options/Classes/Particles/Opacity/Opacity.js +0 -21
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -20
- package/esm/Options/Classes/Particles/Size/Size.js +0 -21
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -20
- package/esm/Options/Interfaces/Particles/Opacity/IOpacity.js +0 -1
- package/esm/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +0 -1
- package/esm/Options/Interfaces/Particles/Size/ISize.js +0 -1
- package/esm/Options/Interfaces/Particles/Size/ISizeAnimation.js +0 -1
- package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +0 -10
- package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -10
- package/types/Options/Classes/Particles/Size/Size.d.ts +0 -10
- package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -10
- package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -5
- package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -5
- /package/browser/{Options/Interfaces/Particles/Opacity/IOpacity.js → Core/Interfaces/IParticleCanvasBounds.js} +0 -0
- /package/{browser/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js → cjs/Core/Interfaces/IParticleCanvasBounds.js} +0 -0
- /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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
34
|
-
this
|
|
35
|
-
this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
38
|
-
this
|
|
39
|
-
this
|
|
40
|
-
this
|
|
41
|
-
this
|
|
42
|
-
this
|
|
43
|
-
this
|
|
44
|
-
this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
47
|
-
this
|
|
48
|
-
this
|
|
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
|
|
51
|
+
return this.#contextSettings;
|
|
52
52
|
}
|
|
53
53
|
canvasClear() {
|
|
54
|
-
if (!this.
|
|
54
|
+
if (!this.#container.actualOptions.clear) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
this.draw(ctx => {
|
|
58
|
-
clear(ctx, this.
|
|
58
|
+
clear(ctx, this.#canvasManager.size);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
clear() {
|
|
62
62
|
let pluginHandled = false;
|
|
63
|
-
for (const plugin of this
|
|
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
|
|
77
|
-
this
|
|
78
|
-
this
|
|
79
|
-
this
|
|
80
|
-
this
|
|
81
|
-
this
|
|
82
|
-
this
|
|
83
|
-
this
|
|
84
|
-
this
|
|
85
|
-
this
|
|
86
|
-
this
|
|
87
|
-
this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
116
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
117
117
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
118
118
|
}
|
|
119
|
-
this
|
|
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
|
|
131
|
-
for (const plugin of this
|
|
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
|
|
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
|
|
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
|
|
148
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
149
149
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
150
150
|
}
|
|
151
|
-
for (const plugin of this
|
|
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
|
|
155
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
156
156
|
plugin.clearDraw?.(ctx, delta);
|
|
157
157
|
}
|
|
158
|
-
for (const plugin of this
|
|
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
|
|
170
|
-
this
|
|
171
|
-
this
|
|
172
|
-
this
|
|
173
|
-
this
|
|
174
|
-
this
|
|
175
|
-
this
|
|
176
|
-
this
|
|
177
|
-
this
|
|
178
|
-
this
|
|
179
|
-
for (const plugin of this.
|
|
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.
|
|
181
|
+
this.#colorPlugins.push(plugin);
|
|
182
182
|
}
|
|
183
183
|
if (plugin.canvasClear) {
|
|
184
|
-
this.
|
|
184
|
+
this.#canvasClearPlugins.push(plugin);
|
|
185
185
|
}
|
|
186
186
|
if (plugin.canvasPaint) {
|
|
187
|
-
this.
|
|
187
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
188
188
|
}
|
|
189
189
|
if (plugin.drawParticle) {
|
|
190
|
-
this.
|
|
190
|
+
this.#drawParticlePlugins.push(plugin);
|
|
191
191
|
}
|
|
192
192
|
if (plugin.drawParticleSetup) {
|
|
193
|
-
this.
|
|
193
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
194
194
|
}
|
|
195
195
|
if (plugin.drawParticleCleanup) {
|
|
196
|
-
this.
|
|
196
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
197
197
|
}
|
|
198
198
|
if (plugin.draw) {
|
|
199
|
-
this.
|
|
199
|
+
this.#drawPlugins.push(plugin);
|
|
200
200
|
}
|
|
201
201
|
if (plugin.drawSettingsSetup) {
|
|
202
|
-
this.
|
|
202
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
203
203
|
}
|
|
204
204
|
if (plugin.drawSettingsCleanup) {
|
|
205
|
-
this.
|
|
205
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
206
206
|
}
|
|
207
207
|
if (plugin.clearDraw) {
|
|
208
|
-
this.
|
|
208
|
+
this.#clearDrawPlugins.push(plugin);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
initUpdaters() {
|
|
213
|
-
this
|
|
214
|
-
this
|
|
215
|
-
for (const updater of this.
|
|
213
|
+
this.#preDrawUpdaters = [];
|
|
214
|
+
this.#postDrawUpdaters = [];
|
|
215
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
216
216
|
if (updater.afterDraw) {
|
|
217
|
-
this.
|
|
217
|
+
this.#postDrawUpdaters.push(updater);
|
|
218
218
|
}
|
|
219
219
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
220
|
-
this.
|
|
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
|
|
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.
|
|
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.
|
|
244
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
setContext(context) {
|
|
248
|
-
this
|
|
249
|
-
if (this
|
|
250
|
-
this.
|
|
248
|
+
this.#context = context;
|
|
249
|
+
if (this.#context) {
|
|
250
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
setContextSettings(settings) {
|
|
254
|
-
this
|
|
254
|
+
this.#contextSettings = settings;
|
|
255
255
|
}
|
|
256
256
|
stop() {
|
|
257
257
|
this.draw(ctx => {
|
|
258
|
-
clear(ctx, this.
|
|
258
|
+
clear(ctx, this.#canvasManager.size);
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
|
-
|
|
262
|
-
for (const updater of this
|
|
261
|
+
#applyPostDrawUpdaters = particle => {
|
|
262
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
263
263
|
updater.afterDraw?.(particle);
|
|
264
264
|
}
|
|
265
265
|
};
|
|
266
|
-
|
|
267
|
-
for (const updater of this
|
|
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
|
-
|
|
286
|
+
#getPluginParticleColors = particle => {
|
|
287
287
|
let fColor, sColor;
|
|
288
|
-
for (const plugin of this
|
|
288
|
+
for (const plugin of this.#colorPlugins) {
|
|
289
289
|
if (!fColor && plugin.particleFillColor) {
|
|
290
|
-
fColor = rangeColorToHsl(this
|
|
290
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
291
291
|
}
|
|
292
292
|
if (!sColor && plugin.particleStrokeColor) {
|
|
293
|
-
sColor = rangeColorToHsl(this
|
|
293
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
294
294
|
}
|
|
295
295
|
if (fColor && sColor) {
|
|
296
296
|
break;
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
|
-
this
|
|
300
|
-
this
|
|
301
|
-
return this
|
|
299
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
300
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
301
|
+
return this.#reusablePluginColors;
|
|
302
302
|
};
|
|
303
303
|
}
|
package/browser/Core/Retina.js
CHANGED
|
@@ -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
|
|
8
|
+
this.#container = container;
|
|
9
9
|
this.pixelRatio = defaultRatio;
|
|
10
10
|
this.reduceFactor = defaultReduceFactor;
|
|
11
11
|
}
|
|
12
12
|
init() {
|
|
13
|
-
const container = this
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
#container;
|
|
5
|
+
#handlers;
|
|
6
|
+
#resizeObserver;
|
|
7
|
+
#resizeTimeout;
|
|
8
8
|
constructor(container) {
|
|
9
|
-
this
|
|
10
|
-
this
|
|
9
|
+
this.#container = container;
|
|
10
|
+
this.#handlers = {
|
|
11
11
|
visibilityChange: () => {
|
|
12
|
-
this
|
|
12
|
+
this.#handleVisibilityChange();
|
|
13
13
|
},
|
|
14
14
|
resize: () => {
|
|
15
|
-
this
|
|
15
|
+
this.#handleWindowResize();
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
addListeners() {
|
|
20
|
-
this
|
|
20
|
+
this.#manageListeners(true);
|
|
21
21
|
}
|
|
22
22
|
removeListeners() {
|
|
23
|
-
this
|
|
23
|
+
this.#manageListeners(false);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
const container = this
|
|
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
|
-
|
|
45
|
-
if (this
|
|
46
|
-
clearTimeout(this
|
|
47
|
-
|
|
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
|
|
50
|
+
const canvas = this.#container.canvas;
|
|
51
51
|
await canvas.windowResize();
|
|
52
52
|
};
|
|
53
|
-
this
|
|
53
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
54
54
|
};
|
|
55
|
-
|
|
56
|
-
const handlers = this
|
|
57
|
-
this
|
|
55
|
+
#manageListeners = add => {
|
|
56
|
+
const handlers = this.#handlers;
|
|
57
|
+
this.#manageResize(add);
|
|
58
58
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
const handlers = this
|
|
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
|
|
70
|
+
if (this.#resizeObserver && !add) {
|
|
71
71
|
if (canvasEl) {
|
|
72
|
-
this.
|
|
72
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
73
73
|
}
|
|
74
|
-
this.
|
|
75
|
-
|
|
74
|
+
this.#resizeObserver.disconnect();
|
|
75
|
+
this.#resizeObserver = undefined;
|
|
76
76
|
}
|
|
77
|
-
else if (!this
|
|
78
|
-
this
|
|
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
|
|
83
|
+
this.#handleWindowResize();
|
|
84
84
|
});
|
|
85
|
-
this.
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
25
|
+
this.#engine = engine;
|
|
26
26
|
}
|
|
27
27
|
get configs() {
|
|
28
28
|
const res = {};
|
|
29
|
-
for (const [name, config] of this
|
|
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.
|
|
40
|
-
this.
|
|
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
|
|
101
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
|
-
this
|
|
105
|
-
this
|
|
106
|
-
this
|
|
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
|
|
109
|
-
await this
|
|
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.
|
|
114
|
-
this
|
|
115
|
-
this
|
|
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
|
|
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
|
|
131
|
-
await this
|
|
130
|
+
if (this.#isRunningLoaders) {
|
|
131
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
this.
|
|
134
|
+
this.#loadPromises.add(loader);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
async
|
|
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
|
|
143
|
+
await loader(this.#engine);
|
|
144
144
|
}
|
|
145
145
|
}
|