@tsparticles/engine 4.0.0-beta.0 → 4.0.0-beta.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/155.min.js +1 -0
- package/README.md +0 -21
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +61 -34
- package/browser/Core/Engine.js +26 -138
- package/browser/Core/Particle.js +29 -28
- package/{cjs/Core/Particles.js → browser/Core/ParticlesManager.js} +27 -57
- package/browser/Core/RenderManager.js +303 -0
- package/browser/Core/Retina.js +3 -8
- package/browser/Core/Utils/PluginManager.js +145 -0
- package/browser/Options/Classes/Options.js +7 -7
- package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/browser/Types/CanvasContextType.js +1 -0
- package/browser/Utils/CanvasUtils.js +1 -1
- package/browser/Utils/ColorUtils.js +21 -21
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/OptionsUtils.js +2 -2
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +61 -34
- package/cjs/Core/Engine.js +26 -138
- package/cjs/Core/Particle.js +29 -28
- package/{esm/Core/Particles.js → cjs/Core/ParticlesManager.js} +27 -57
- package/cjs/Core/RenderManager.js +303 -0
- package/cjs/Core/Retina.js +3 -8
- package/cjs/Core/Utils/PluginManager.js +145 -0
- package/cjs/Options/Classes/Options.js +7 -7
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/cjs/Types/CanvasContextType.js +1 -0
- package/cjs/Utils/CanvasUtils.js +1 -1
- package/cjs/Utils/ColorUtils.js +21 -21
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/dist_browser_Core_Container_js.js +24 -14
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +61 -34
- package/esm/Core/Engine.js +26 -138
- package/esm/Core/Particle.js +29 -28
- package/{browser/Core/Particles.js → esm/Core/ParticlesManager.js} +27 -57
- package/esm/Core/RenderManager.js +303 -0
- package/esm/Core/Retina.js +3 -8
- package/esm/Core/Utils/PluginManager.js +145 -0
- package/esm/Options/Classes/Options.js +7 -7
- package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/esm/Types/CanvasContextType.js +1 -0
- package/esm/Utils/CanvasUtils.js +1 -1
- package/esm/Utils/ColorUtils.js +21 -21
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/OptionsUtils.js +2 -2
- package/package.json +1 -1
- package/report.html +84 -29
- package/tsparticles.engine.js +18 -8
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/CanvasManager.d.ts +39 -0
- package/types/Core/Container.d.ts +26 -7
- package/types/Core/Engine.d.ts +2 -54
- package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -7
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
- package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -1
- package/types/Core/Particle.d.ts +4 -4
- package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +4 -11
- package/types/Core/{Canvas.d.ts → RenderManager.d.ts} +12 -33
- package/types/Core/Retina.d.ts +0 -2
- package/types/Core/Utils/PluginManager.d.ts +62 -0
- package/types/Options/Classes/Options.d.ts +3 -3
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +3 -3
- package/types/Types/CanvasContextType.d.ts +1 -0
- package/types/Utils/CanvasUtils.d.ts +8 -5
- package/types/Utils/ColorUtils.d.ts +8 -8
- package/types/Utils/LogUtils.d.ts +1 -0
- package/types/Utils/OptionsUtils.d.ts +2 -2
- package/types/export-types.d.ts +4 -2
- package/umd/Core/CanvasManager.js +317 -0
- package/umd/Core/Container.js +61 -34
- package/umd/Core/Engine.js +25 -137
- package/umd/Core/Particle.js +29 -28
- package/umd/Core/{Particles.js → ParticlesManager.js} +29 -59
- package/umd/Core/RenderManager.js +317 -0
- package/umd/Core/Retina.js +3 -8
- package/umd/Core/Utils/PluginManager.js +159 -0
- package/umd/Options/Classes/Options.js +7 -7
- package/umd/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/umd/Types/CanvasContextType.js +12 -0
- package/umd/Utils/CanvasUtils.js +1 -1
- package/umd/Utils/ColorUtils.js +21 -21
- package/umd/Utils/LogUtils.js +1 -0
- package/umd/Utils/OptionsUtils.js +2 -2
- package/164.min.js +0 -1
- package/browser/Core/Canvas.js +0 -570
- package/cjs/Core/Canvas.js +0 -570
- package/esm/Core/Canvas.js +0 -570
- package/umd/Core/Canvas.js +0 -584
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../Utils/Utils.js", "./Utils/Constants.js", "../Utils/ColorUtils.js", "./RenderManager.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CanvasManager = void 0;
|
|
13
|
+
const Utils_js_1 = require("../Utils/Utils.js");
|
|
14
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
15
|
+
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
16
|
+
const RenderManager_js_1 = require("./RenderManager.js");
|
|
17
|
+
function setStyle(canvas, style, important = false) {
|
|
18
|
+
if (!style) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const element = canvas, elementStyle = element.style, keys = new Set();
|
|
22
|
+
for (let i = 0; i < elementStyle.length; i++) {
|
|
23
|
+
const key = elementStyle.item(i);
|
|
24
|
+
if (!key) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
keys.add(key);
|
|
28
|
+
}
|
|
29
|
+
for (let i = 0; i < style.length; i++) {
|
|
30
|
+
const key = style.item(i);
|
|
31
|
+
if (!key) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
keys.add(key);
|
|
35
|
+
}
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
const value = style.getPropertyValue(key);
|
|
38
|
+
if (value) {
|
|
39
|
+
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
elementStyle.removeProperty(key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class CanvasManager {
|
|
47
|
+
element;
|
|
48
|
+
render;
|
|
49
|
+
size;
|
|
50
|
+
zoom = Constants_js_1.defaultZoom;
|
|
51
|
+
_container;
|
|
52
|
+
_generated;
|
|
53
|
+
_mutationObserver;
|
|
54
|
+
_originalStyle;
|
|
55
|
+
_pluginManager;
|
|
56
|
+
_pointerEvents;
|
|
57
|
+
_resizePlugins;
|
|
58
|
+
_standardSize;
|
|
59
|
+
_zoomCenter;
|
|
60
|
+
constructor(pluginManager, container) {
|
|
61
|
+
this._pluginManager = pluginManager;
|
|
62
|
+
this._container = container;
|
|
63
|
+
this.render = new RenderManager_js_1.RenderManager(pluginManager, container, this);
|
|
64
|
+
this._standardSize = {
|
|
65
|
+
height: 0,
|
|
66
|
+
width: 0,
|
|
67
|
+
};
|
|
68
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this._standardSize;
|
|
69
|
+
this.size = {
|
|
70
|
+
height: stdSize.height * pxRatio,
|
|
71
|
+
width: stdSize.width * pxRatio,
|
|
72
|
+
};
|
|
73
|
+
this._generated = false;
|
|
74
|
+
this._resizePlugins = [];
|
|
75
|
+
this._pointerEvents = "none";
|
|
76
|
+
}
|
|
77
|
+
get _fullScreen() {
|
|
78
|
+
return this._container.actualOptions.fullScreen.enable;
|
|
79
|
+
}
|
|
80
|
+
destroy() {
|
|
81
|
+
this.stop();
|
|
82
|
+
if (this._generated) {
|
|
83
|
+
const element = this.element;
|
|
84
|
+
element?.remove();
|
|
85
|
+
this.element = undefined;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this._resetOriginalStyle();
|
|
89
|
+
}
|
|
90
|
+
this.render.destroy();
|
|
91
|
+
this._resizePlugins = [];
|
|
92
|
+
}
|
|
93
|
+
getZoomCenter() {
|
|
94
|
+
const pxRatio = this._container.retina.pixelRatio, { width, height } = this.size;
|
|
95
|
+
if (this._zoomCenter) {
|
|
96
|
+
return this._zoomCenter;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
x: (width * Constants_js_1.half) / pxRatio,
|
|
100
|
+
y: (height * Constants_js_1.half) / pxRatio,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
init() {
|
|
104
|
+
this._safeMutationObserver(obs => {
|
|
105
|
+
obs.disconnect();
|
|
106
|
+
});
|
|
107
|
+
this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(records => {
|
|
108
|
+
for (const record of records) {
|
|
109
|
+
if (record.type === "attributes" && record.attributeName === "style") {
|
|
110
|
+
this._repairStyle();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.resize();
|
|
115
|
+
this._initStyle();
|
|
116
|
+
this.initBackground();
|
|
117
|
+
this._safeMutationObserver(obs => {
|
|
118
|
+
if (!this.element || !(this.element instanceof Node)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
obs.observe(this.element, { attributes: true });
|
|
122
|
+
});
|
|
123
|
+
this.initPlugins();
|
|
124
|
+
this.render.init();
|
|
125
|
+
}
|
|
126
|
+
initBackground() {
|
|
127
|
+
const { _container } = this, options = _container.actualOptions, background = options.background, element = this.element;
|
|
128
|
+
if (!element) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const elementStyle = element.style, color = (0, ColorUtils_js_1.rangeColorToRgb)(this._pluginManager, background.color);
|
|
132
|
+
if (color) {
|
|
133
|
+
elementStyle.backgroundColor = (0, ColorUtils_js_1.getStyleFromRgb)(color, _container.hdr, background.opacity);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
elementStyle.backgroundColor = "";
|
|
137
|
+
}
|
|
138
|
+
elementStyle.backgroundImage = background.image || "";
|
|
139
|
+
elementStyle.backgroundPosition = background.position || "";
|
|
140
|
+
elementStyle.backgroundRepeat = background.repeat || "";
|
|
141
|
+
elementStyle.backgroundSize = background.size || "";
|
|
142
|
+
}
|
|
143
|
+
initPlugins() {
|
|
144
|
+
this._resizePlugins = [];
|
|
145
|
+
for (const plugin of this._container.plugins) {
|
|
146
|
+
if (plugin.resize) {
|
|
147
|
+
this._resizePlugins.push(plugin);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
loadCanvas(canvas) {
|
|
152
|
+
if (this._generated && this.element) {
|
|
153
|
+
this.element.remove();
|
|
154
|
+
}
|
|
155
|
+
const container = this._container;
|
|
156
|
+
this._generated =
|
|
157
|
+
Constants_js_1.generatedAttribute in canvas.dataset ? canvas.dataset[Constants_js_1.generatedAttribute] === "true" : this._generated;
|
|
158
|
+
this.element = canvas;
|
|
159
|
+
this.element.ariaHidden = "true";
|
|
160
|
+
this._originalStyle = (0, Utils_js_1.cloneStyle)(this.element.style);
|
|
161
|
+
const standardSize = this._standardSize;
|
|
162
|
+
standardSize.height = canvas.offsetHeight;
|
|
163
|
+
standardSize.width = canvas.offsetWidth;
|
|
164
|
+
const pxRatio = this._container.retina.pixelRatio, retinaSize = this.size;
|
|
165
|
+
canvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
166
|
+
canvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
167
|
+
const canSupportHdrQuery = (0, Utils_js_1.safeMatchMedia)("(color-gamut: p3)");
|
|
168
|
+
this.render.setContextSettings({
|
|
169
|
+
alpha: true,
|
|
170
|
+
colorSpace: canSupportHdrQuery?.matches && container.hdr ? "display-p3" : "srgb",
|
|
171
|
+
desynchronized: true,
|
|
172
|
+
willReadFrequently: false,
|
|
173
|
+
});
|
|
174
|
+
this.render.setContext(this.element.getContext("2d", this.render.settings));
|
|
175
|
+
this._safeMutationObserver(obs => {
|
|
176
|
+
obs.disconnect();
|
|
177
|
+
});
|
|
178
|
+
container.retina.init();
|
|
179
|
+
this.initBackground();
|
|
180
|
+
this._safeMutationObserver(obs => {
|
|
181
|
+
if (!this.element || !(this.element instanceof Node)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
obs.observe(this.element, { attributes: true });
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
resize() {
|
|
188
|
+
if (!this.element) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
const container = this._container, currentSize = container.canvas._standardSize, newSize = {
|
|
192
|
+
width: this.element.offsetWidth,
|
|
193
|
+
height: this.element.offsetHeight,
|
|
194
|
+
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
195
|
+
width: newSize.width * pxRatio,
|
|
196
|
+
height: newSize.height * pxRatio,
|
|
197
|
+
};
|
|
198
|
+
if (newSize.height === currentSize.height &&
|
|
199
|
+
newSize.width === currentSize.width &&
|
|
200
|
+
retinaSize.height === this.element.height &&
|
|
201
|
+
retinaSize.width === this.element.width) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
const oldSize = { ...currentSize };
|
|
205
|
+
currentSize.height = newSize.height;
|
|
206
|
+
currentSize.width = newSize.width;
|
|
207
|
+
const canvasSize = this.size;
|
|
208
|
+
this.element.width = canvasSize.width = retinaSize.width;
|
|
209
|
+
this.element.height = canvasSize.height = retinaSize.height;
|
|
210
|
+
if (this._container.started) {
|
|
211
|
+
container.particles.setResizeFactor({
|
|
212
|
+
width: currentSize.width / oldSize.width,
|
|
213
|
+
height: currentSize.height / oldSize.height,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
setPointerEvents(type) {
|
|
219
|
+
const element = this.element;
|
|
220
|
+
if (!element) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this._pointerEvents = type;
|
|
224
|
+
this._repairStyle();
|
|
225
|
+
}
|
|
226
|
+
setZoom(zoomLevel, center) {
|
|
227
|
+
this.zoom = zoomLevel;
|
|
228
|
+
this._zoomCenter = center;
|
|
229
|
+
}
|
|
230
|
+
stop() {
|
|
231
|
+
this._safeMutationObserver(obs => {
|
|
232
|
+
obs.disconnect();
|
|
233
|
+
});
|
|
234
|
+
this._mutationObserver = undefined;
|
|
235
|
+
this.render.stop();
|
|
236
|
+
}
|
|
237
|
+
async windowResize() {
|
|
238
|
+
if (!this.element || !this.resize()) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const container = this._container, needsRefresh = container.updateActualOptions();
|
|
242
|
+
container.particles.setDensity();
|
|
243
|
+
this._applyResizePlugins();
|
|
244
|
+
if (needsRefresh) {
|
|
245
|
+
await container.refresh();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
_applyResizePlugins = () => {
|
|
249
|
+
for (const plugin of this._resizePlugins) {
|
|
250
|
+
plugin.resize?.();
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
_initStyle = () => {
|
|
254
|
+
const element = this.element, options = this._container.actualOptions;
|
|
255
|
+
if (!element) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (this._fullScreen) {
|
|
259
|
+
this._setFullScreenStyle();
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
this._resetOriginalStyle();
|
|
263
|
+
}
|
|
264
|
+
for (const key in options.style) {
|
|
265
|
+
if (!key || !(key in options.style)) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const value = options.style[key];
|
|
269
|
+
if (!value) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
element.style.setProperty(key, value, "important");
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
_repairStyle = () => {
|
|
276
|
+
const element = this.element;
|
|
277
|
+
if (!element) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this._safeMutationObserver(observer => {
|
|
281
|
+
observer.disconnect();
|
|
282
|
+
});
|
|
283
|
+
this._initStyle();
|
|
284
|
+
this.initBackground();
|
|
285
|
+
const pointerEvents = this._pointerEvents;
|
|
286
|
+
element.style.pointerEvents = pointerEvents;
|
|
287
|
+
element.setAttribute("pointer-events", pointerEvents);
|
|
288
|
+
this._safeMutationObserver(observer => {
|
|
289
|
+
if (!(element instanceof Node)) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
observer.observe(element, { attributes: true });
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
_resetOriginalStyle = () => {
|
|
296
|
+
const element = this.element, originalStyle = this._originalStyle;
|
|
297
|
+
if (!element || !originalStyle) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
setStyle(element, originalStyle, true);
|
|
301
|
+
};
|
|
302
|
+
_safeMutationObserver = callback => {
|
|
303
|
+
if (!this._mutationObserver) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
callback(this._mutationObserver);
|
|
307
|
+
};
|
|
308
|
+
_setFullScreenStyle = () => {
|
|
309
|
+
const element = this.element;
|
|
310
|
+
if (!element) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
setStyle(element, (0, Utils_js_1.getFullScreenStyle)(this._container.actualOptions.fullScreen.zIndex), true);
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
exports.CanvasManager = CanvasManager;
|
|
317
|
+
});
|
package/umd/Core/Container.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../Utils/MathUtils.js", "./Utils/Constants.js", "./
|
|
7
|
+
define(["require", "exports", "../Utils/MathUtils.js", "./Utils/Constants.js", "./CanvasManager.js", "./Utils/EventListeners.js", "../Enums/Types/EventType.js", "../Options/Classes/Options.js", "./ParticlesManager.js", "./Retina.js", "../Utils/LogUtils.js", "../Utils/OptionsUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
exports.Container = void 0;
|
|
13
13
|
const MathUtils_js_1 = require("../Utils/MathUtils.js");
|
|
14
14
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
15
|
-
const
|
|
15
|
+
const CanvasManager_js_1 = require("./CanvasManager.js");
|
|
16
16
|
const EventListeners_js_1 = require("./Utils/EventListeners.js");
|
|
17
17
|
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
18
18
|
const Options_js_1 = require("../Options/Classes/Options.js");
|
|
19
|
-
const
|
|
19
|
+
const ParticlesManager_js_1 = require("./ParticlesManager.js");
|
|
20
20
|
const Retina_js_1 = require("./Retina.js");
|
|
21
21
|
const LogUtils_js_1 = require("../Utils/LogUtils.js");
|
|
22
22
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
delta.value = value;
|
|
28
28
|
delta.factor = smooth ? Constants_js_1.defaultFps / fpsLimit : (Constants_js_1.defaultFps * value) / Constants_js_1.millisecondsToSeconds;
|
|
29
29
|
}
|
|
30
|
-
function loadContainerOptions(
|
|
31
|
-
const options = new Options_js_1.Options(
|
|
30
|
+
function loadContainerOptions(pluginManager, container, ...sourceOptionsArr) {
|
|
31
|
+
const options = new Options_js_1.Options(pluginManager, container);
|
|
32
32
|
(0, OptionsUtils_js_1.loadOptions)(options, ...sourceOptionsArr);
|
|
33
33
|
return options;
|
|
34
34
|
}
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
actualOptions;
|
|
37
37
|
canvas;
|
|
38
38
|
destroyed;
|
|
39
|
+
effectDrawers;
|
|
39
40
|
fpsLimit;
|
|
40
41
|
hdr;
|
|
41
42
|
id;
|
|
@@ -43,28 +44,35 @@
|
|
|
43
44
|
particleCreatedPlugins;
|
|
44
45
|
particleDestroyedPlugins;
|
|
45
46
|
particlePositionPlugins;
|
|
47
|
+
particleUpdaters;
|
|
46
48
|
particles;
|
|
47
49
|
plugins;
|
|
48
50
|
retina;
|
|
51
|
+
shapeDrawers;
|
|
49
52
|
started;
|
|
50
53
|
zLayers;
|
|
51
54
|
_delay;
|
|
52
55
|
_delayTimeout;
|
|
53
56
|
_delta = { value: 0, factor: 0 };
|
|
57
|
+
_dispatchCallback;
|
|
54
58
|
_drawAnimationFrame;
|
|
55
59
|
_duration;
|
|
56
|
-
_engine;
|
|
57
60
|
_eventListeners;
|
|
58
61
|
_firstStart;
|
|
59
62
|
_initialSourceOptions;
|
|
60
63
|
_lastFrameTime;
|
|
61
64
|
_lifeTime;
|
|
65
|
+
_onDestroy;
|
|
62
66
|
_options;
|
|
63
67
|
_paused;
|
|
68
|
+
_pluginManager;
|
|
64
69
|
_smooth;
|
|
65
70
|
_sourceOptions;
|
|
66
|
-
constructor(
|
|
67
|
-
|
|
71
|
+
constructor(params) {
|
|
72
|
+
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
73
|
+
this._pluginManager = pluginManager;
|
|
74
|
+
this._dispatchCallback = dispatchCallback;
|
|
75
|
+
this._onDestroy = onDestroy;
|
|
68
76
|
this.id = Symbol(id);
|
|
69
77
|
this.fpsLimit = 120;
|
|
70
78
|
this.hdr = false;
|
|
@@ -81,17 +89,20 @@
|
|
|
81
89
|
this.pageHidden = false;
|
|
82
90
|
this._sourceOptions = sourceOptions;
|
|
83
91
|
this._initialSourceOptions = sourceOptions;
|
|
92
|
+
this.effectDrawers = new Map();
|
|
93
|
+
this.shapeDrawers = new Map();
|
|
94
|
+
this.particleUpdaters = [];
|
|
84
95
|
this.retina = new Retina_js_1.Retina(this);
|
|
85
|
-
this.canvas = new
|
|
86
|
-
this.particles = new
|
|
96
|
+
this.canvas = new CanvasManager_js_1.CanvasManager(this._pluginManager, this);
|
|
97
|
+
this.particles = new ParticlesManager_js_1.ParticlesManager(this._pluginManager, this);
|
|
87
98
|
this.plugins = [];
|
|
88
99
|
this.particleDestroyedPlugins = [];
|
|
89
100
|
this.particleCreatedPlugins = [];
|
|
90
101
|
this.particlePositionPlugins = [];
|
|
91
|
-
this._options = loadContainerOptions(this.
|
|
92
|
-
this.actualOptions = loadContainerOptions(this.
|
|
102
|
+
this._options = loadContainerOptions(this._pluginManager, this);
|
|
103
|
+
this.actualOptions = loadContainerOptions(this._pluginManager, this);
|
|
93
104
|
this._eventListeners = new EventListeners_js_1.EventListeners(this);
|
|
94
|
-
this.
|
|
105
|
+
this.dispatchEvent(EventType_js_1.EventType.containerBuilt);
|
|
95
106
|
}
|
|
96
107
|
get animationStatus() {
|
|
97
108
|
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
@@ -115,19 +126,29 @@
|
|
|
115
126
|
this.stop();
|
|
116
127
|
this.particles.destroy();
|
|
117
128
|
this.canvas.destroy();
|
|
129
|
+
for (const [, effectDrawer] of this.effectDrawers) {
|
|
130
|
+
effectDrawer.destroy?.(this);
|
|
131
|
+
}
|
|
132
|
+
for (const [, shapeDrawer] of this.shapeDrawers) {
|
|
133
|
+
shapeDrawer.destroy?.(this);
|
|
134
|
+
}
|
|
118
135
|
for (const plugin of this.plugins) {
|
|
119
136
|
plugin.destroy?.();
|
|
120
137
|
}
|
|
138
|
+
this.effectDrawers = new Map();
|
|
139
|
+
this.shapeDrawers = new Map();
|
|
140
|
+
this.particleUpdaters = [];
|
|
121
141
|
this.plugins.length = 0;
|
|
122
|
-
this.
|
|
142
|
+
this._pluginManager.clearPlugins(this);
|
|
123
143
|
this.destroyed = true;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
this._onDestroy(remove);
|
|
145
|
+
this.dispatchEvent(EventType_js_1.EventType.containerDestroyed);
|
|
146
|
+
}
|
|
147
|
+
dispatchEvent(type, data) {
|
|
148
|
+
this._dispatchCallback(type, {
|
|
149
|
+
container: this,
|
|
150
|
+
data,
|
|
151
|
+
});
|
|
131
152
|
}
|
|
132
153
|
draw(force) {
|
|
133
154
|
if (!guardCheck(this)) {
|
|
@@ -161,16 +182,16 @@
|
|
|
161
182
|
return;
|
|
162
183
|
}
|
|
163
184
|
const allContainerPlugins = new Map();
|
|
164
|
-
for (const plugin of this.
|
|
185
|
+
for (const plugin of this._pluginManager.plugins) {
|
|
165
186
|
const containerPlugin = await plugin.getPlugin(this);
|
|
166
187
|
if (containerPlugin.preInit) {
|
|
167
188
|
await containerPlugin.preInit();
|
|
168
189
|
}
|
|
169
190
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
170
191
|
}
|
|
171
|
-
await this.
|
|
172
|
-
this._options = loadContainerOptions(this.
|
|
173
|
-
this.actualOptions = loadContainerOptions(this.
|
|
192
|
+
await this.initDrawersAndUpdaters();
|
|
193
|
+
this._options = loadContainerOptions(this._pluginManager, this, this._initialSourceOptions, this.sourceOptions);
|
|
194
|
+
this.actualOptions = loadContainerOptions(this._pluginManager, this, this._options);
|
|
174
195
|
this.plugins.length = 0;
|
|
175
196
|
this.particleDestroyedPlugins.length = 0;
|
|
176
197
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -206,12 +227,18 @@
|
|
|
206
227
|
await plugin.init?.();
|
|
207
228
|
}
|
|
208
229
|
await this.particles.init();
|
|
209
|
-
this.
|
|
230
|
+
this.dispatchEvent(EventType_js_1.EventType.containerInit);
|
|
210
231
|
this.particles.setDensity();
|
|
211
232
|
for (const plugin of this.plugins) {
|
|
212
233
|
plugin.particlesSetup?.();
|
|
213
234
|
}
|
|
214
|
-
this.
|
|
235
|
+
this.dispatchEvent(EventType_js_1.EventType.particlesSetup);
|
|
236
|
+
}
|
|
237
|
+
async initDrawersAndUpdaters() {
|
|
238
|
+
const pluginManager = this._pluginManager;
|
|
239
|
+
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
240
|
+
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
241
|
+
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
215
242
|
}
|
|
216
243
|
pause() {
|
|
217
244
|
if (!guardCheck(this)) {
|
|
@@ -230,7 +257,7 @@
|
|
|
230
257
|
if (!this.pageHidden) {
|
|
231
258
|
this._paused = true;
|
|
232
259
|
}
|
|
233
|
-
this.
|
|
260
|
+
this.dispatchEvent(EventType_js_1.EventType.containerPaused);
|
|
234
261
|
}
|
|
235
262
|
play(force) {
|
|
236
263
|
if (!guardCheck(this)) {
|
|
@@ -251,7 +278,7 @@
|
|
|
251
278
|
}
|
|
252
279
|
}
|
|
253
280
|
}
|
|
254
|
-
this.
|
|
281
|
+
this.dispatchEvent(EventType_js_1.EventType.containerPlay);
|
|
255
282
|
this.draw(needsUpdate ?? false);
|
|
256
283
|
}
|
|
257
284
|
async refresh() {
|
|
@@ -267,8 +294,8 @@
|
|
|
267
294
|
}
|
|
268
295
|
this._initialSourceOptions = sourceOptions;
|
|
269
296
|
this._sourceOptions = sourceOptions;
|
|
270
|
-
this._options = loadContainerOptions(this.
|
|
271
|
-
this.actualOptions = loadContainerOptions(this.
|
|
297
|
+
this._options = loadContainerOptions(this._pluginManager, this, this._initialSourceOptions, this.sourceOptions);
|
|
298
|
+
this.actualOptions = loadContainerOptions(this._pluginManager, this, this._options);
|
|
272
299
|
return this.refresh();
|
|
273
300
|
}
|
|
274
301
|
async start() {
|
|
@@ -283,7 +310,7 @@
|
|
|
283
310
|
for (const plugin of this.plugins) {
|
|
284
311
|
await plugin.start?.();
|
|
285
312
|
}
|
|
286
|
-
this.
|
|
313
|
+
this.dispatchEvent(EventType_js_1.EventType.containerStarted);
|
|
287
314
|
this.play();
|
|
288
315
|
resolve();
|
|
289
316
|
};
|
|
@@ -311,7 +338,7 @@
|
|
|
311
338
|
this.particleDestroyedPlugins.length = 0;
|
|
312
339
|
this.particlePositionPlugins.length = 0;
|
|
313
340
|
this._sourceOptions = this._options;
|
|
314
|
-
this.
|
|
341
|
+
this.dispatchEvent(EventType_js_1.EventType.containerStopped);
|
|
315
342
|
}
|
|
316
343
|
updateActualOptions() {
|
|
317
344
|
let refresh = false;
|
|
@@ -338,7 +365,7 @@
|
|
|
338
365
|
this.draw(false);
|
|
339
366
|
return;
|
|
340
367
|
}
|
|
341
|
-
this.canvas.drawParticles(this._delta);
|
|
368
|
+
this.canvas.render.drawParticles(this._delta);
|
|
342
369
|
if (!this.alive()) {
|
|
343
370
|
this.destroy();
|
|
344
371
|
return;
|