@tsparticles/engine 4.0.4 → 4.1.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/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
|
@@ -56,53 +56,53 @@ export class CanvasManager {
|
|
|
56
56
|
renderCanvas;
|
|
57
57
|
size;
|
|
58
58
|
zoom = defaultZoom;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
#container;
|
|
60
|
+
#generated;
|
|
61
|
+
#mutationObserver;
|
|
62
|
+
#originalStyle;
|
|
63
|
+
#pluginManager;
|
|
64
|
+
#pointerEvents;
|
|
65
|
+
#resizePlugins;
|
|
66
|
+
#standardSize;
|
|
67
|
+
#zoomCenter;
|
|
68
68
|
constructor(pluginManager, container) {
|
|
69
|
-
this
|
|
70
|
-
this
|
|
69
|
+
this.#pluginManager = pluginManager;
|
|
70
|
+
this.#container = container;
|
|
71
71
|
this.render = new RenderManager(pluginManager, container, this);
|
|
72
|
-
this
|
|
72
|
+
this.#standardSize = {
|
|
73
73
|
height: 0,
|
|
74
74
|
width: 0,
|
|
75
75
|
};
|
|
76
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
76
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
77
77
|
this.size = {
|
|
78
78
|
height: stdSize.height * pxRatio,
|
|
79
79
|
width: stdSize.width * pxRatio,
|
|
80
80
|
};
|
|
81
|
-
this
|
|
82
|
-
this
|
|
83
|
-
this
|
|
81
|
+
this.#generated = false;
|
|
82
|
+
this.#resizePlugins = [];
|
|
83
|
+
this.#pointerEvents = "none";
|
|
84
84
|
}
|
|
85
|
-
get
|
|
86
|
-
return this.
|
|
85
|
+
get #fullScreen() {
|
|
86
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
87
87
|
}
|
|
88
88
|
destroy() {
|
|
89
89
|
this.stop();
|
|
90
|
-
if (this
|
|
90
|
+
if (this.#generated) {
|
|
91
91
|
const element = this.domElement;
|
|
92
92
|
element?.remove();
|
|
93
93
|
this.domElement = undefined;
|
|
94
94
|
this.renderCanvas = undefined;
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
|
-
this
|
|
97
|
+
this.#resetOriginalStyle();
|
|
98
98
|
}
|
|
99
99
|
this.render.destroy();
|
|
100
|
-
this
|
|
100
|
+
this.#resizePlugins = [];
|
|
101
101
|
}
|
|
102
102
|
getZoomCenter() {
|
|
103
|
-
const pxRatio = this.
|
|
104
|
-
if (this
|
|
105
|
-
return this
|
|
103
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
104
|
+
if (this.#zoomCenter) {
|
|
105
|
+
return this.#zoomCenter;
|
|
106
106
|
}
|
|
107
107
|
return {
|
|
108
108
|
x: (width * half) / pxRatio,
|
|
@@ -110,20 +110,20 @@ export class CanvasManager {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
init() {
|
|
113
|
-
this
|
|
113
|
+
this.#safeMutationObserver(obs => {
|
|
114
114
|
obs.disconnect();
|
|
115
115
|
});
|
|
116
|
-
this
|
|
116
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
117
117
|
for (const record of records) {
|
|
118
118
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
119
|
-
this
|
|
119
|
+
this.#repairStyle();
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
this.resize();
|
|
124
|
-
this
|
|
124
|
+
this.#initStyle();
|
|
125
125
|
this.initBackground();
|
|
126
|
-
this
|
|
126
|
+
this.#safeMutationObserver(obs => {
|
|
127
127
|
const element = this.domElement;
|
|
128
128
|
if (!element || !(element instanceof Node)) {
|
|
129
129
|
return;
|
|
@@ -134,13 +134,13 @@ export class CanvasManager {
|
|
|
134
134
|
this.render.init();
|
|
135
135
|
}
|
|
136
136
|
initBackground() {
|
|
137
|
-
const
|
|
137
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
138
138
|
if (!element) {
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
141
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
142
142
|
if (color) {
|
|
143
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
143
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
146
|
elementStyle.backgroundColor = "";
|
|
@@ -151,27 +151,27 @@ export class CanvasManager {
|
|
|
151
151
|
elementStyle.backgroundSize = background.size || "";
|
|
152
152
|
}
|
|
153
153
|
initPlugins() {
|
|
154
|
-
this
|
|
155
|
-
for (const plugin of this.
|
|
154
|
+
this.#resizePlugins = [];
|
|
155
|
+
for (const plugin of this.#container.plugins) {
|
|
156
156
|
if (plugin.resize) {
|
|
157
|
-
this.
|
|
157
|
+
this.#resizePlugins.push(plugin);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
loadCanvas(canvas) {
|
|
162
|
-
if (this
|
|
162
|
+
if (this.#generated && this.domElement) {
|
|
163
163
|
this.domElement.remove();
|
|
164
164
|
}
|
|
165
|
-
const container = this
|
|
165
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
166
166
|
this.domElement = domCanvas;
|
|
167
|
-
this
|
|
167
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
168
168
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
169
169
|
const domElement = this.domElement;
|
|
170
170
|
if (domElement) {
|
|
171
171
|
domElement.ariaHidden = "true";
|
|
172
|
-
this
|
|
172
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
173
173
|
}
|
|
174
|
-
const standardSize = this
|
|
174
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
175
175
|
if (domElement) {
|
|
176
176
|
standardSize.height = domElement.offsetHeight;
|
|
177
177
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -180,7 +180,7 @@ export class CanvasManager {
|
|
|
180
180
|
standardSize.height = renderCanvas.height;
|
|
181
181
|
standardSize.width = renderCanvas.width;
|
|
182
182
|
}
|
|
183
|
-
const pxRatio = this.
|
|
183
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
184
184
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
185
185
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
186
186
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -191,12 +191,12 @@ export class CanvasManager {
|
|
|
191
191
|
willReadFrequently: false,
|
|
192
192
|
});
|
|
193
193
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
194
|
-
this
|
|
194
|
+
this.#safeMutationObserver(obs => {
|
|
195
195
|
obs.disconnect();
|
|
196
196
|
});
|
|
197
197
|
container.retina.init();
|
|
198
198
|
this.initBackground();
|
|
199
|
-
this
|
|
199
|
+
this.#safeMutationObserver(obs => {
|
|
200
200
|
const element = this.domElement;
|
|
201
201
|
if (!element || !(element instanceof Node)) {
|
|
202
202
|
return;
|
|
@@ -209,11 +209,11 @@ export class CanvasManager {
|
|
|
209
209
|
if (!element) {
|
|
210
210
|
return false;
|
|
211
211
|
}
|
|
212
|
-
const container = this
|
|
212
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
213
213
|
if (renderCanvas === undefined) {
|
|
214
214
|
return false;
|
|
215
215
|
}
|
|
216
|
-
const currentSize = container.canvas
|
|
216
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
217
217
|
width: element.offsetWidth,
|
|
218
218
|
height: element.offsetHeight,
|
|
219
219
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -232,7 +232,7 @@ export class CanvasManager {
|
|
|
232
232
|
const canvasSize = this.size;
|
|
233
233
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
234
234
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
235
|
-
if (this.
|
|
235
|
+
if (this.#container.started) {
|
|
236
236
|
container.particles.setResizeFactor({
|
|
237
237
|
width: currentSize.width / oldSize.width,
|
|
238
238
|
height: currentSize.height / oldSize.height,
|
|
@@ -245,46 +245,46 @@ export class CanvasManager {
|
|
|
245
245
|
if (!element) {
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
|
-
this
|
|
249
|
-
this
|
|
248
|
+
this.#pointerEvents = type;
|
|
249
|
+
this.#repairStyle();
|
|
250
250
|
}
|
|
251
251
|
setZoom(zoomLevel, center) {
|
|
252
252
|
this.zoom = zoomLevel;
|
|
253
|
-
this
|
|
253
|
+
this.#zoomCenter = center;
|
|
254
254
|
}
|
|
255
255
|
stop() {
|
|
256
|
-
this
|
|
256
|
+
this.#safeMutationObserver(obs => {
|
|
257
257
|
obs.disconnect();
|
|
258
258
|
});
|
|
259
|
-
this
|
|
259
|
+
this.#mutationObserver = undefined;
|
|
260
260
|
this.render.stop();
|
|
261
261
|
}
|
|
262
262
|
async windowResize() {
|
|
263
263
|
if (!this.domElement || !this.resize()) {
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
|
-
const container = this
|
|
266
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
267
267
|
container.particles.setDensity();
|
|
268
|
-
this
|
|
268
|
+
this.#applyResizePlugins();
|
|
269
269
|
if (needsRefresh) {
|
|
270
270
|
await container.refresh();
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
|
|
274
|
-
for (const plugin of this
|
|
273
|
+
#applyResizePlugins = () => {
|
|
274
|
+
for (const plugin of this.#resizePlugins) {
|
|
275
275
|
plugin.resize?.();
|
|
276
276
|
}
|
|
277
277
|
};
|
|
278
|
-
|
|
279
|
-
const element = this.domElement, options = this.
|
|
278
|
+
#initStyle = () => {
|
|
279
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
280
280
|
if (!element) {
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
|
-
if (this
|
|
284
|
-
this
|
|
283
|
+
if (this.#fullScreen) {
|
|
284
|
+
this.#setFullScreenStyle();
|
|
285
285
|
}
|
|
286
286
|
else {
|
|
287
|
-
this
|
|
287
|
+
this.#resetOriginalStyle();
|
|
288
288
|
}
|
|
289
289
|
for (const key in options.style) {
|
|
290
290
|
if (!key || !(key in options.style)) {
|
|
@@ -297,44 +297,44 @@ export class CanvasManager {
|
|
|
297
297
|
element.style.setProperty(key, value, "important");
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
|
-
|
|
300
|
+
#repairStyle = () => {
|
|
301
301
|
const element = this.domElement;
|
|
302
302
|
if (!element) {
|
|
303
303
|
return;
|
|
304
304
|
}
|
|
305
|
-
this
|
|
305
|
+
this.#safeMutationObserver(observer => {
|
|
306
306
|
observer.disconnect();
|
|
307
307
|
});
|
|
308
|
-
this
|
|
308
|
+
this.#initStyle();
|
|
309
309
|
this.initBackground();
|
|
310
|
-
const pointerEvents = this
|
|
310
|
+
const pointerEvents = this.#pointerEvents;
|
|
311
311
|
element.style.pointerEvents = pointerEvents;
|
|
312
312
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
313
|
-
this
|
|
313
|
+
this.#safeMutationObserver(observer => {
|
|
314
314
|
if (!(element instanceof Node)) {
|
|
315
315
|
return;
|
|
316
316
|
}
|
|
317
317
|
observer.observe(element, { attributes: true });
|
|
318
318
|
});
|
|
319
319
|
};
|
|
320
|
-
|
|
321
|
-
const element = this.domElement, originalStyle = this
|
|
320
|
+
#resetOriginalStyle = () => {
|
|
321
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
322
322
|
if (!element || !originalStyle) {
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
325
325
|
setStyle(element, originalStyle, true);
|
|
326
326
|
};
|
|
327
|
-
|
|
328
|
-
if (!this
|
|
327
|
+
#safeMutationObserver = callback => {
|
|
328
|
+
if (!this.#mutationObserver) {
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
331
|
-
callback(this
|
|
331
|
+
callback(this.#mutationObserver);
|
|
332
332
|
};
|
|
333
|
-
|
|
333
|
+
#setFullScreenStyle = () => {
|
|
334
334
|
const element = this.domElement;
|
|
335
335
|
if (!element) {
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
|
-
setStyle(element, getFullScreenStyle(this.
|
|
338
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
339
339
|
};
|
|
340
340
|
}
|
package/cjs/Core/Container.js
CHANGED
|
@@ -39,73 +39,73 @@ export class Container {
|
|
|
39
39
|
shapeDrawers;
|
|
40
40
|
started;
|
|
41
41
|
zLayers;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
#delay;
|
|
43
|
+
#delayTimeout;
|
|
44
|
+
#delta = { value: 0, factor: 0 };
|
|
45
|
+
#dispatchCallback;
|
|
46
|
+
#drawAnimationFrame;
|
|
47
|
+
#duration;
|
|
48
|
+
#eventListeners;
|
|
49
|
+
#firstStart;
|
|
50
|
+
#initialSourceOptions;
|
|
51
|
+
#lastFrameTime;
|
|
52
|
+
#lifeTime;
|
|
53
|
+
#onDestroy;
|
|
54
|
+
#options;
|
|
55
|
+
#paused;
|
|
56
|
+
#pluginManager;
|
|
57
|
+
#smooth;
|
|
58
|
+
#sourceOptions;
|
|
59
59
|
constructor(params) {
|
|
60
60
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
61
|
-
this
|
|
62
|
-
this
|
|
63
|
-
this
|
|
61
|
+
this.#pluginManager = pluginManager;
|
|
62
|
+
this.#dispatchCallback = dispatchCallback;
|
|
63
|
+
this.#onDestroy = onDestroy;
|
|
64
64
|
this.id = Symbol(id);
|
|
65
65
|
this.fpsLimit = 120;
|
|
66
66
|
this.hdr = false;
|
|
67
|
-
this
|
|
68
|
-
this
|
|
69
|
-
this
|
|
70
|
-
this
|
|
71
|
-
this
|
|
67
|
+
this.#smooth = false;
|
|
68
|
+
this.#delay = 0;
|
|
69
|
+
this.#duration = 0;
|
|
70
|
+
this.#lifeTime = 0;
|
|
71
|
+
this.#firstStart = true;
|
|
72
72
|
this.started = false;
|
|
73
73
|
this.destroyed = false;
|
|
74
|
-
this
|
|
75
|
-
this
|
|
74
|
+
this.#paused = true;
|
|
75
|
+
this.#lastFrameTime = 0;
|
|
76
76
|
this.zLayers = 100;
|
|
77
77
|
this.pageHidden = false;
|
|
78
|
-
this
|
|
79
|
-
this
|
|
78
|
+
this.#sourceOptions = sourceOptions;
|
|
79
|
+
this.#initialSourceOptions = sourceOptions;
|
|
80
80
|
this.effectDrawers = new Map();
|
|
81
81
|
this.shapeDrawers = new Map();
|
|
82
82
|
this.particleUpdaters = [];
|
|
83
83
|
this.retina = new Retina(this);
|
|
84
|
-
this.canvas = new CanvasManager(this
|
|
85
|
-
this.particles = new ParticlesManager(this
|
|
84
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
85
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
86
86
|
this.plugins = [];
|
|
87
87
|
this.particleDestroyedPlugins = [];
|
|
88
88
|
this.particleCreatedPlugins = [];
|
|
89
89
|
this.particlePositionPlugins = [];
|
|
90
|
-
this
|
|
91
|
-
this.actualOptions = loadContainerOptions(this
|
|
92
|
-
this
|
|
90
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
91
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
92
|
+
this.#eventListeners = new EventListeners(this);
|
|
93
93
|
this.dispatchEvent(EventType.containerBuilt);
|
|
94
94
|
}
|
|
95
95
|
get animationStatus() {
|
|
96
|
-
return !this
|
|
96
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
97
97
|
}
|
|
98
98
|
get options() {
|
|
99
|
-
return this
|
|
99
|
+
return this.#options;
|
|
100
100
|
}
|
|
101
101
|
get sourceOptions() {
|
|
102
|
-
return this
|
|
102
|
+
return this.#sourceOptions;
|
|
103
103
|
}
|
|
104
104
|
addLifeTime(value) {
|
|
105
|
-
this
|
|
105
|
+
this.#lifeTime += value;
|
|
106
106
|
}
|
|
107
107
|
alive() {
|
|
108
|
-
return !this
|
|
108
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
109
109
|
}
|
|
110
110
|
destroy(remove = true) {
|
|
111
111
|
if (!guardCheck(this)) {
|
|
@@ -127,13 +127,13 @@ export class Container {
|
|
|
127
127
|
this.shapeDrawers = new Map();
|
|
128
128
|
this.particleUpdaters = [];
|
|
129
129
|
this.plugins.length = 0;
|
|
130
|
-
this.
|
|
130
|
+
this.#pluginManager.clearPlugins(this);
|
|
131
131
|
this.destroyed = true;
|
|
132
|
-
this
|
|
132
|
+
this.#onDestroy(remove);
|
|
133
133
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
134
134
|
}
|
|
135
135
|
dispatchEvent(type, data) {
|
|
136
|
-
this
|
|
136
|
+
this.#dispatchCallback(type, {
|
|
137
137
|
container: this,
|
|
138
138
|
data,
|
|
139
139
|
});
|
|
@@ -143,12 +143,12 @@ export class Container {
|
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
let refreshTime = force;
|
|
146
|
-
this
|
|
146
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
147
147
|
if (refreshTime) {
|
|
148
|
-
this
|
|
148
|
+
this.#lastFrameTime = undefined;
|
|
149
149
|
refreshTime = false;
|
|
150
150
|
}
|
|
151
|
-
this
|
|
151
|
+
this.#nextFrame(timestamp);
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
async export(type, options = {}) {
|
|
@@ -170,7 +170,7 @@ export class Container {
|
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
const allContainerPlugins = new Map();
|
|
173
|
-
for (const plugin of this.
|
|
173
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
174
174
|
const containerPlugin = await plugin.getPlugin(this);
|
|
175
175
|
if (containerPlugin.preInit) {
|
|
176
176
|
await containerPlugin.preInit();
|
|
@@ -178,8 +178,8 @@ export class Container {
|
|
|
178
178
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
179
179
|
}
|
|
180
180
|
await this.initDrawersAndUpdaters();
|
|
181
|
-
this
|
|
182
|
-
this.actualOptions = loadContainerOptions(this
|
|
181
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
182
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
183
183
|
this.plugins.length = 0;
|
|
184
184
|
this.particleDestroyedPlugins.length = 0;
|
|
185
185
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -206,11 +206,11 @@ export class Container {
|
|
|
206
206
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
207
207
|
this.hdr = hdr;
|
|
208
208
|
this.zLayers = zLayers;
|
|
209
|
-
this
|
|
210
|
-
this
|
|
211
|
-
this
|
|
209
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
210
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
211
|
+
this.#lifeTime = 0;
|
|
212
212
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
213
|
-
this
|
|
213
|
+
this.#smooth = smooth;
|
|
214
214
|
for (const plugin of this.plugins) {
|
|
215
215
|
await plugin.init?.();
|
|
216
216
|
}
|
|
@@ -223,7 +223,7 @@ export class Container {
|
|
|
223
223
|
this.dispatchEvent(EventType.particlesSetup);
|
|
224
224
|
}
|
|
225
225
|
async initDrawersAndUpdaters() {
|
|
226
|
-
const pluginManager = this
|
|
226
|
+
const pluginManager = this.#pluginManager;
|
|
227
227
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
228
228
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
229
229
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -232,18 +232,18 @@ export class Container {
|
|
|
232
232
|
if (!guardCheck(this)) {
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
|
-
if (this
|
|
236
|
-
cancelAnimation(this
|
|
237
|
-
|
|
235
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
236
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
237
|
+
this.#drawAnimationFrame = undefined;
|
|
238
238
|
}
|
|
239
|
-
if (this
|
|
239
|
+
if (this.#paused) {
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
242
|
for (const plugin of this.plugins) {
|
|
243
243
|
plugin.pause?.();
|
|
244
244
|
}
|
|
245
245
|
if (!this.pageHidden) {
|
|
246
|
-
this
|
|
246
|
+
this.#paused = true;
|
|
247
247
|
}
|
|
248
248
|
this.dispatchEvent(EventType.containerPaused);
|
|
249
249
|
}
|
|
@@ -251,13 +251,13 @@ export class Container {
|
|
|
251
251
|
if (!guardCheck(this)) {
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
|
-
const needsUpdate = this
|
|
255
|
-
if (this
|
|
256
|
-
this
|
|
254
|
+
const needsUpdate = this.#paused || force;
|
|
255
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
256
|
+
this.#firstStart = false;
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
259
|
-
if (this
|
|
260
|
-
this
|
|
259
|
+
if (this.#paused) {
|
|
260
|
+
this.#paused = false;
|
|
261
261
|
}
|
|
262
262
|
if (needsUpdate) {
|
|
263
263
|
for (const plugin of this.plugins) {
|
|
@@ -280,10 +280,10 @@ export class Container {
|
|
|
280
280
|
if (!guardCheck(this)) {
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
|
-
this
|
|
284
|
-
this
|
|
285
|
-
this
|
|
286
|
-
this.actualOptions = loadContainerOptions(this
|
|
283
|
+
this.#initialSourceOptions = sourceOptions;
|
|
284
|
+
this.#sourceOptions = sourceOptions;
|
|
285
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
286
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
287
287
|
return this.refresh();
|
|
288
288
|
}
|
|
289
289
|
async start() {
|
|
@@ -294,7 +294,7 @@ export class Container {
|
|
|
294
294
|
this.started = true;
|
|
295
295
|
await new Promise(resolve => {
|
|
296
296
|
const start = async () => {
|
|
297
|
-
this.
|
|
297
|
+
this.#eventListeners.addListeners();
|
|
298
298
|
for (const plugin of this.plugins) {
|
|
299
299
|
await plugin.start?.();
|
|
300
300
|
}
|
|
@@ -302,20 +302,20 @@ export class Container {
|
|
|
302
302
|
this.play();
|
|
303
303
|
resolve();
|
|
304
304
|
};
|
|
305
|
-
this
|
|
305
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
306
306
|
});
|
|
307
307
|
}
|
|
308
308
|
stop() {
|
|
309
309
|
if (!guardCheck(this) || !this.started) {
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
|
-
if (this
|
|
313
|
-
clearTimeout(this
|
|
314
|
-
|
|
312
|
+
if (this.#delayTimeout) {
|
|
313
|
+
clearTimeout(this.#delayTimeout);
|
|
314
|
+
this.#delayTimeout = undefined;
|
|
315
315
|
}
|
|
316
|
-
this
|
|
316
|
+
this.#firstStart = true;
|
|
317
317
|
this.started = false;
|
|
318
|
-
this.
|
|
318
|
+
this.#eventListeners.removeListeners();
|
|
319
319
|
this.pause();
|
|
320
320
|
this.particles.clear();
|
|
321
321
|
this.canvas.stop();
|
|
@@ -325,7 +325,7 @@ export class Container {
|
|
|
325
325
|
this.particleCreatedPlugins.length = 0;
|
|
326
326
|
this.particleDestroyedPlugins.length = 0;
|
|
327
327
|
this.particlePositionPlugins.length = 0;
|
|
328
|
-
this
|
|
328
|
+
this.#sourceOptions = this.#options;
|
|
329
329
|
this.dispatchEvent(EventType.containerStopped);
|
|
330
330
|
}
|
|
331
331
|
updateActualOptions() {
|
|
@@ -337,23 +337,23 @@ export class Container {
|
|
|
337
337
|
}
|
|
338
338
|
return refresh;
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
#nextFrame = (timestamp) => {
|
|
341
341
|
try {
|
|
342
|
-
if (!this
|
|
343
|
-
this
|
|
344
|
-
timestamp < this
|
|
342
|
+
if (!this.#smooth &&
|
|
343
|
+
this.#lastFrameTime !== undefined &&
|
|
344
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
345
345
|
this.draw(false);
|
|
346
346
|
return;
|
|
347
347
|
}
|
|
348
|
-
this
|
|
349
|
-
updateDelta(this
|
|
350
|
-
this.addLifeTime(this.
|
|
351
|
-
this
|
|
352
|
-
if (this.
|
|
348
|
+
this.#lastFrameTime ??= timestamp;
|
|
349
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
350
|
+
this.addLifeTime(this.#delta.value);
|
|
351
|
+
this.#lastFrameTime = timestamp;
|
|
352
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
353
353
|
this.draw(false);
|
|
354
354
|
return;
|
|
355
355
|
}
|
|
356
|
-
this.canvas.render.drawParticles(this
|
|
356
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
357
357
|
if (!this.alive()) {
|
|
358
358
|
this.destroy();
|
|
359
359
|
return;
|