@tsparticles/engine 3.0.3 → 3.2.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/373.min.js +2 -0
- package/373.min.js.LICENSE.txt +1 -0
- package/438.min.js +2 -0
- package/438.min.js.LICENSE.txt +1 -0
- package/README.md +337 -216
- package/browser/Core/Canvas.js +102 -49
- package/browser/Core/Container.js +53 -41
- package/browser/Core/Engine.js +47 -32
- package/browser/Core/Particle.js +46 -48
- package/browser/Core/Particles.js +70 -57
- package/browser/Core/Retina.js +5 -4
- package/browser/Core/Utils/Circle.js +4 -3
- package/browser/Core/Utils/Constants.js +3 -0
- package/browser/Core/Utils/EventListeners.js +19 -16
- package/browser/Core/Utils/ExternalInteractorBase.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +17 -8
- package/browser/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/browser/Core/Utils/QuadTree.js +5 -3
- package/browser/Core/Utils/Vector.js +7 -2
- package/browser/Core/Utils/Vector3d.js +14 -9
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/browser/Options/Classes/ManualParticle.js +3 -2
- package/browser/Options/Classes/Options.js +3 -0
- package/browser/Utils/CanvasUtils.js +50 -40
- package/browser/Utils/ColorUtils.js +124 -45
- package/browser/Utils/EventDispatcher.js +6 -5
- package/browser/Utils/HslColorManager.js +5 -5
- package/browser/Utils/NumberUtils.js +35 -23
- package/browser/Utils/RgbColorManager.js +5 -5
- package/browser/Utils/Utils.js +102 -19
- package/cjs/Core/Canvas.js +102 -49
- package/cjs/Core/Container.js +53 -41
- package/cjs/Core/Engine.js +70 -32
- package/cjs/Core/Particle.js +45 -47
- package/cjs/Core/Particles.js +93 -57
- package/cjs/Core/Retina.js +5 -4
- package/cjs/Core/Utils/Circle.js +4 -3
- package/cjs/Core/Utils/Constants.js +4 -1
- package/cjs/Core/Utils/EventListeners.js +18 -15
- package/cjs/Core/Utils/ExternalInteractorBase.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +17 -8
- package/cjs/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/cjs/Core/Utils/QuadTree.js +5 -3
- package/cjs/Core/Utils/Vector.js +7 -2
- package/cjs/Core/Utils/Vector3d.js +14 -9
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/cjs/Options/Classes/ManualParticle.js +3 -2
- package/cjs/Options/Classes/Options.js +3 -0
- package/cjs/Utils/CanvasUtils.js +50 -40
- package/cjs/Utils/ColorUtils.js +126 -45
- package/cjs/Utils/EventDispatcher.js +6 -5
- package/cjs/Utils/HslColorManager.js +5 -5
- package/cjs/Utils/NumberUtils.js +37 -24
- package/cjs/Utils/RgbColorManager.js +5 -5
- package/cjs/Utils/Utils.js +103 -19
- package/dist_browser_Core_Container_js.js +92 -0
- package/dist_browser_Core_Particle_js.js +32 -0
- package/esm/Core/Canvas.js +102 -49
- package/esm/Core/Container.js +53 -41
- package/esm/Core/Engine.js +47 -32
- package/esm/Core/Particle.js +46 -48
- package/esm/Core/Particles.js +70 -57
- package/esm/Core/Retina.js +5 -4
- package/esm/Core/Utils/Circle.js +4 -3
- package/esm/Core/Utils/Constants.js +3 -0
- package/esm/Core/Utils/EventListeners.js +19 -16
- package/esm/Core/Utils/ExternalInteractorBase.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +17 -8
- package/esm/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/esm/Core/Utils/QuadTree.js +5 -3
- package/esm/Core/Utils/Vector.js +7 -2
- package/esm/Core/Utils/Vector3d.js +14 -9
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/esm/Options/Classes/ManualParticle.js +3 -2
- package/esm/Options/Classes/Options.js +3 -0
- package/esm/Utils/CanvasUtils.js +50 -40
- package/esm/Utils/ColorUtils.js +124 -45
- package/esm/Utils/EventDispatcher.js +6 -5
- package/esm/Utils/HslColorManager.js +5 -5
- package/esm/Utils/NumberUtils.js +35 -23
- package/esm/Utils/RgbColorManager.js +5 -5
- package/esm/Utils/Utils.js +102 -19
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +894 -5461
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +5 -3
- package/types/Core/Container.d.ts +1 -1
- package/types/Core/Engine.d.ts +13 -8
- package/types/Core/Interfaces/IContainerPlugin.d.ts +3 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
- package/types/Core/Interfaces/IParticleHslAnimation.d.ts +4 -4
- package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +4 -0
- package/types/Core/Interfaces/IPlugin.d.ts +1 -1
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -2
- package/types/Core/Interfaces/IShapeDrawer.d.ts +4 -4
- package/types/Core/Particle.d.ts +3 -3
- package/types/Core/Particles.d.ts +12 -8
- package/types/Core/Utils/Constants.d.ts +3 -0
- package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
- package/types/Core/Utils/InteractionManager.d.ts +3 -3
- package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
- package/types/Core/Utils/Point.d.ts +1 -1
- package/types/Enums/Modes/OutMode.d.ts +0 -3
- package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +2 -1
- package/types/Options/Classes/Options.d.ts +1 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +1 -2
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +5 -6
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMask.d.ts +2 -1
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.d.ts +2 -1
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +1 -3
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IOutModes.d.ts +6 -6
- package/types/Types/CustomEventArgs.d.ts +2 -2
- package/types/Types/ExportResult.d.ts +2 -2
- package/types/Types/ParticlesGroups.d.ts +1 -3
- package/types/Types/PathOptions.d.ts +1 -3
- package/types/Types/ShapeData.d.ts +1 -3
- package/types/Utils/CanvasUtils.d.ts +9 -8
- package/types/Utils/ColorUtils.d.ts +5 -0
- package/types/Utils/NumberUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +9 -6
- package/umd/Core/Canvas.js +102 -49
- package/umd/Core/Container.js +54 -42
- package/umd/Core/Engine.js +72 -33
- package/umd/Core/Particle.js +46 -48
- package/umd/Core/Particles.js +95 -58
- package/umd/Core/Retina.js +5 -4
- package/umd/Core/Utils/Circle.js +4 -3
- package/umd/Core/Utils/Constants.js +4 -1
- package/umd/Core/Utils/EventListeners.js +18 -15
- package/umd/Core/Utils/ExternalInteractorBase.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +17 -8
- package/umd/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/umd/Core/Utils/QuadTree.js +5 -3
- package/umd/Core/Utils/Vector.js +7 -2
- package/umd/Core/Utils/Vector3d.js +14 -9
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/umd/Options/Classes/ManualParticle.js +3 -2
- package/umd/Options/Classes/Options.js +3 -0
- package/umd/Utils/CanvasUtils.js +50 -40
- package/umd/Utils/ColorUtils.js +127 -46
- package/umd/Utils/EventDispatcher.js +6 -5
- package/umd/Utils/HslColorManager.js +5 -5
- package/umd/Utils/NumberUtils.js +38 -25
- package/umd/Utils/RgbColorManager.js +5 -5
- package/umd/Utils/Utils.js +104 -20
package/umd/Core/Canvas.js
CHANGED
|
@@ -15,9 +15,29 @@
|
|
|
15
15
|
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
16
16
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
17
17
|
function setTransformValue(factor, newFactor, key) {
|
|
18
|
-
const newValue = newFactor[key];
|
|
18
|
+
const newValue = newFactor[key], defaultValue = 1;
|
|
19
19
|
if (newValue !== undefined) {
|
|
20
|
-
factor[key] = (factor[key] ??
|
|
20
|
+
factor[key] = (factor[key] ?? defaultValue) * newValue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function setStyle(canvas, style, important = false) {
|
|
24
|
+
if (!style) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const element = canvas;
|
|
28
|
+
if (!element) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const elementStyle = element.style;
|
|
32
|
+
if (!elementStyle) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const key in style) {
|
|
36
|
+
const value = style[key];
|
|
37
|
+
if (!value) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
21
41
|
}
|
|
22
42
|
}
|
|
23
43
|
class Canvas {
|
|
@@ -25,7 +45,7 @@
|
|
|
25
45
|
this.container = container;
|
|
26
46
|
this._applyPostDrawUpdaters = (particle) => {
|
|
27
47
|
for (const updater of this._postDrawUpdaters) {
|
|
28
|
-
updater.afterDraw
|
|
48
|
+
updater.afterDraw?.(particle);
|
|
29
49
|
}
|
|
30
50
|
};
|
|
31
51
|
this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
@@ -45,12 +65,12 @@
|
|
|
45
65
|
setTransformValue(transform, updaterTransform, key);
|
|
46
66
|
}
|
|
47
67
|
}
|
|
48
|
-
updater.beforeDraw
|
|
68
|
+
updater.beforeDraw?.(particle);
|
|
49
69
|
}
|
|
50
70
|
};
|
|
51
71
|
this._applyResizePlugins = () => {
|
|
52
72
|
for (const plugin of this._resizePlugins) {
|
|
53
|
-
plugin.resize
|
|
73
|
+
plugin.resize?.();
|
|
54
74
|
}
|
|
55
75
|
};
|
|
56
76
|
this._getPluginParticleColors = (particle) => {
|
|
@@ -68,14 +88,36 @@
|
|
|
68
88
|
}
|
|
69
89
|
return [fColor, sColor];
|
|
70
90
|
};
|
|
71
|
-
this._initCover = () => {
|
|
72
|
-
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
this._initCover = async () => {
|
|
92
|
+
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color;
|
|
93
|
+
if (color) {
|
|
94
|
+
const coverRgb = (0, ColorUtils_js_1.rangeColorToRgb)(color);
|
|
95
|
+
if (coverRgb) {
|
|
96
|
+
const coverColor = {
|
|
97
|
+
...coverRgb,
|
|
98
|
+
a: cover.opacity,
|
|
99
|
+
};
|
|
100
|
+
this._coverColorStyle = (0, ColorUtils_js_1.getStyleFromRgb)(coverColor, coverColor.a);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
if (!cover.image) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const img = document.createElement("img");
|
|
109
|
+
img.addEventListener("load", () => {
|
|
110
|
+
this._coverImage = {
|
|
111
|
+
image: img,
|
|
112
|
+
opacity: cover.opacity,
|
|
113
|
+
};
|
|
114
|
+
resolve();
|
|
115
|
+
});
|
|
116
|
+
img.addEventListener("error", (evt) => {
|
|
117
|
+
reject(evt.error);
|
|
118
|
+
});
|
|
119
|
+
img.src = cover.image;
|
|
120
|
+
});
|
|
79
121
|
}
|
|
80
122
|
};
|
|
81
123
|
this._initStyle = () => {
|
|
@@ -106,17 +148,17 @@
|
|
|
106
148
|
if (!trail.enable) {
|
|
107
149
|
return;
|
|
108
150
|
}
|
|
151
|
+
const factorNumerator = 1, opacity = factorNumerator / trail.length;
|
|
109
152
|
if (trailFill.color) {
|
|
110
153
|
const fillColor = (0, ColorUtils_js_1.rangeColorToRgb)(trailFill.color);
|
|
111
154
|
if (!fillColor) {
|
|
112
155
|
return;
|
|
113
156
|
}
|
|
114
|
-
const trail = options.particles.move.trail;
|
|
115
157
|
this._trailFill = {
|
|
116
158
|
color: {
|
|
117
159
|
...fillColor,
|
|
118
160
|
},
|
|
119
|
-
opacity
|
|
161
|
+
opacity,
|
|
120
162
|
};
|
|
121
163
|
}
|
|
122
164
|
else {
|
|
@@ -128,7 +170,7 @@
|
|
|
128
170
|
img.addEventListener("load", () => {
|
|
129
171
|
this._trailFill = {
|
|
130
172
|
image: img,
|
|
131
|
-
opacity
|
|
173
|
+
opacity,
|
|
132
174
|
};
|
|
133
175
|
resolve();
|
|
134
176
|
});
|
|
@@ -160,13 +202,7 @@
|
|
|
160
202
|
if (!(element && originalStyle)) {
|
|
161
203
|
return;
|
|
162
204
|
}
|
|
163
|
-
|
|
164
|
-
style.position = originalStyle.position;
|
|
165
|
-
style.zIndex = originalStyle.zIndex;
|
|
166
|
-
style.top = originalStyle.top;
|
|
167
|
-
style.left = originalStyle.left;
|
|
168
|
-
style.width = originalStyle.width;
|
|
169
|
-
style.height = originalStyle.height;
|
|
205
|
+
setStyle(element, originalStyle);
|
|
170
206
|
};
|
|
171
207
|
this._safeMutationObserver = (callback) => {
|
|
172
208
|
if (!this._mutationObserver) {
|
|
@@ -179,13 +215,15 @@
|
|
|
179
215
|
if (!element) {
|
|
180
216
|
return;
|
|
181
217
|
}
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
218
|
+
const radix = 10;
|
|
219
|
+
setStyle(element, {
|
|
220
|
+
position: "fixed",
|
|
221
|
+
zIndex: this.container.actualOptions.fullScreen.zIndex.toString(radix),
|
|
222
|
+
top: "0",
|
|
223
|
+
left: "0",
|
|
224
|
+
width: "100%",
|
|
225
|
+
height: "100%",
|
|
226
|
+
}, true);
|
|
189
227
|
};
|
|
190
228
|
this.size = {
|
|
191
229
|
height: 0,
|
|
@@ -202,11 +240,11 @@
|
|
|
202
240
|
return this.container.actualOptions.fullScreen.enable;
|
|
203
241
|
}
|
|
204
242
|
clear() {
|
|
205
|
-
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill;
|
|
243
|
+
const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill, minimumLength = 0;
|
|
206
244
|
if (options.backgroundMask.enable) {
|
|
207
245
|
this.paint();
|
|
208
246
|
}
|
|
209
|
-
else if (trail.enable && trail.length >
|
|
247
|
+
else if (trail.enable && trail.length > minimumLength && trailFill) {
|
|
210
248
|
if (trailFill.color) {
|
|
211
249
|
this._paintBase((0, ColorUtils_js_1.getStyleFromRgb)(trailFill.color, trailFill.opacity));
|
|
212
250
|
}
|
|
@@ -224,7 +262,7 @@
|
|
|
224
262
|
this.stop();
|
|
225
263
|
if (this._generated) {
|
|
226
264
|
const element = this.element;
|
|
227
|
-
element
|
|
265
|
+
element?.remove();
|
|
228
266
|
}
|
|
229
267
|
else {
|
|
230
268
|
this._resetOriginalStyle();
|
|
@@ -241,12 +279,19 @@
|
|
|
241
279
|
}
|
|
242
280
|
return cb(ctx);
|
|
243
281
|
}
|
|
244
|
-
|
|
282
|
+
drawAsync(cb) {
|
|
283
|
+
const ctx = this._context;
|
|
284
|
+
if (!ctx) {
|
|
285
|
+
return Promise.resolve(undefined);
|
|
286
|
+
}
|
|
287
|
+
return cb(ctx);
|
|
288
|
+
}
|
|
289
|
+
async drawParticle(particle, delta) {
|
|
245
290
|
if (particle.spawning || particle.destroyed) {
|
|
246
291
|
return;
|
|
247
292
|
}
|
|
248
|
-
const radius = particle.getRadius();
|
|
249
|
-
if (radius <=
|
|
293
|
+
const radius = particle.getRadius(), minimumSize = 0;
|
|
294
|
+
if (radius <= minimumSize) {
|
|
250
295
|
return;
|
|
251
296
|
}
|
|
252
297
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor() ?? pfColor;
|
|
@@ -260,13 +305,13 @@
|
|
|
260
305
|
if (!fColor && !sColor) {
|
|
261
306
|
return;
|
|
262
307
|
}
|
|
263
|
-
this.
|
|
264
|
-
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex,
|
|
308
|
+
await this.drawAsync(async (ctx) => {
|
|
309
|
+
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
265
310
|
fill: fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, zOpacity) : undefined,
|
|
266
311
|
};
|
|
267
312
|
colorStyles.stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, zStrokeOpacity) : colorStyles.fill;
|
|
268
313
|
this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
|
|
269
|
-
(0, CanvasUtils_js_1.drawParticle)({
|
|
314
|
+
await (0, CanvasUtils_js_1.drawParticle)({
|
|
270
315
|
container,
|
|
271
316
|
context: ctx,
|
|
272
317
|
particle,
|
|
@@ -274,7 +319,7 @@
|
|
|
274
319
|
colorStyles,
|
|
275
320
|
backgroundMask: options.backgroundMask.enable,
|
|
276
321
|
composite: options.backgroundMask.composite,
|
|
277
|
-
radius: radius *
|
|
322
|
+
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
278
323
|
opacity: zOpacity,
|
|
279
324
|
shadow: particle.options.shadow,
|
|
280
325
|
transform,
|
|
@@ -282,11 +327,11 @@
|
|
|
282
327
|
this._applyPostDrawUpdaters(particle);
|
|
283
328
|
});
|
|
284
329
|
}
|
|
285
|
-
drawParticlePlugin(plugin, particle, delta) {
|
|
286
|
-
this.
|
|
330
|
+
async drawParticlePlugin(plugin, particle, delta) {
|
|
331
|
+
await this.drawAsync((ctx) => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
|
|
287
332
|
}
|
|
288
|
-
drawPlugin(plugin, delta) {
|
|
289
|
-
this.
|
|
333
|
+
async drawPlugin(plugin, delta) {
|
|
334
|
+
await this.drawAsync((ctx) => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
|
|
290
335
|
}
|
|
291
336
|
async init() {
|
|
292
337
|
this._safeMutationObserver((obs) => obs.disconnect());
|
|
@@ -299,7 +344,7 @@
|
|
|
299
344
|
});
|
|
300
345
|
this.resize();
|
|
301
346
|
this._initStyle();
|
|
302
|
-
this._initCover();
|
|
347
|
+
await this._initCover();
|
|
303
348
|
try {
|
|
304
349
|
await this._initTrail();
|
|
305
350
|
}
|
|
@@ -344,7 +389,7 @@
|
|
|
344
389
|
if (plugin.resize) {
|
|
345
390
|
this._resizePlugins.push(plugin);
|
|
346
391
|
}
|
|
347
|
-
if (plugin.particleFillColor
|
|
392
|
+
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
348
393
|
this._colorPlugins.push(plugin);
|
|
349
394
|
}
|
|
350
395
|
}
|
|
@@ -356,7 +401,7 @@
|
|
|
356
401
|
if (updater.afterDraw) {
|
|
357
402
|
this._postDrawUpdaters.push(updater);
|
|
358
403
|
}
|
|
359
|
-
if (updater.getColorStyles
|
|
404
|
+
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
360
405
|
this._preDrawUpdaters.push(updater);
|
|
361
406
|
}
|
|
362
407
|
}
|
|
@@ -389,7 +434,15 @@
|
|
|
389
434
|
this.draw((ctx) => {
|
|
390
435
|
if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
|
391
436
|
(0, CanvasUtils_js_1.clear)(ctx, this.size);
|
|
392
|
-
|
|
437
|
+
if (this._coverImage) {
|
|
438
|
+
this._paintImage(this._coverImage.image, this._coverImage.opacity);
|
|
439
|
+
}
|
|
440
|
+
else if (this._coverColorStyle) {
|
|
441
|
+
this._paintBase(this._coverColorStyle);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
this._paintBase();
|
|
445
|
+
}
|
|
393
446
|
}
|
|
394
447
|
else {
|
|
395
448
|
this._paintBase();
|
|
@@ -431,7 +484,7 @@
|
|
|
431
484
|
return;
|
|
432
485
|
}
|
|
433
486
|
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
434
|
-
container.particles.setDensity();
|
|
487
|
+
await container.particles.setDensity();
|
|
435
488
|
this._applyResizePlugins();
|
|
436
489
|
if (needsRefresh) {
|
|
437
490
|
await container.refresh();
|
package/umd/Core/Container.js
CHANGED
|
@@ -4,28 +4,29 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "../Utils/Utils.js", "./Canvas.js", "./Utils/EventListeners.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "
|
|
7
|
+
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "./Canvas.js", "./Utils/EventListeners.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/NumberUtils.js", "../Utils/OptionsUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Container = void 0;
|
|
13
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
13
14
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
14
15
|
const Canvas_js_1 = require("./Canvas.js");
|
|
15
16
|
const EventListeners_js_1 = require("./Utils/EventListeners.js");
|
|
16
17
|
const Options_js_1 = require("../Options/Classes/Options.js");
|
|
17
18
|
const Particles_js_1 = require("./Particles.js");
|
|
18
19
|
const Retina_js_1 = require("./Retina.js");
|
|
19
|
-
const Constants_js_1 = require("./Utils/Constants.js");
|
|
20
20
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
21
21
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
22
22
|
function guardCheck(container) {
|
|
23
23
|
return container && !container.destroyed;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
const defaultFps = 60;
|
|
26
|
+
function initDelta(value, fpsLimit = defaultFps, smooth = false) {
|
|
26
27
|
return {
|
|
27
28
|
value,
|
|
28
|
-
factor: smooth ?
|
|
29
|
+
factor: smooth ? defaultFps / fpsLimit : (defaultFps * value) / Constants_js_1.millisecondsToSeconds,
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
@@ -43,14 +44,19 @@
|
|
|
43
44
|
if (entry.target !== this.interactivity.element) {
|
|
44
45
|
continue;
|
|
45
46
|
}
|
|
46
|
-
(entry.isIntersecting
|
|
47
|
+
if (entry.isIntersecting) {
|
|
48
|
+
this.play();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.pause();
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
this._nextFrame = async (timestamp) => {
|
|
50
56
|
try {
|
|
51
57
|
if (!this._smooth &&
|
|
52
58
|
this._lastFrameTime !== undefined &&
|
|
53
|
-
timestamp < this._lastFrameTime +
|
|
59
|
+
timestamp < this._lastFrameTime + Constants_js_1.millisecondsToSeconds / this.fpsLimit) {
|
|
54
60
|
this.draw(false);
|
|
55
61
|
return;
|
|
56
62
|
}
|
|
@@ -58,7 +64,7 @@
|
|
|
58
64
|
const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
|
|
59
65
|
this.addLifeTime(delta.value);
|
|
60
66
|
this._lastFrameTime = timestamp;
|
|
61
|
-
if (delta.value >
|
|
67
|
+
if (delta.value > Constants_js_1.millisecondsToSeconds) {
|
|
62
68
|
this.draw(false);
|
|
63
69
|
return;
|
|
64
70
|
}
|
|
@@ -67,7 +73,7 @@
|
|
|
67
73
|
this.destroy();
|
|
68
74
|
return;
|
|
69
75
|
}
|
|
70
|
-
if (this.
|
|
76
|
+
if (this.animationStatus) {
|
|
71
77
|
this.draw(false);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
@@ -110,6 +116,9 @@
|
|
|
110
116
|
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)((entries) => this._intersectionManager(entries));
|
|
111
117
|
this._engine.dispatchEvent("containerBuilt", { container: this });
|
|
112
118
|
}
|
|
119
|
+
get animationStatus() {
|
|
120
|
+
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
121
|
+
}
|
|
113
122
|
get options() {
|
|
114
123
|
return this._options;
|
|
115
124
|
}
|
|
@@ -141,8 +150,8 @@
|
|
|
141
150
|
const mouseEvent = e, pos = {
|
|
142
151
|
x: mouseEvent.offsetX || mouseEvent.clientX,
|
|
143
152
|
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
144
|
-
};
|
|
145
|
-
clickOrTouchHandler(e, pos,
|
|
153
|
+
}, radius = 1;
|
|
154
|
+
clickOrTouchHandler(e, pos, radius);
|
|
146
155
|
};
|
|
147
156
|
const touchStartHandler = () => {
|
|
148
157
|
if (!guardCheck(this)) {
|
|
@@ -163,16 +172,17 @@
|
|
|
163
172
|
}
|
|
164
173
|
if (touched && !touchMoved) {
|
|
165
174
|
const touchEvent = e;
|
|
166
|
-
|
|
175
|
+
const lengthOffset = 1;
|
|
176
|
+
let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
|
|
167
177
|
if (!lastTouch) {
|
|
168
|
-
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length -
|
|
178
|
+
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
|
|
169
179
|
if (!lastTouch) {
|
|
170
180
|
return;
|
|
171
181
|
}
|
|
172
182
|
}
|
|
173
|
-
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
|
|
174
|
-
x: lastTouch.clientX - (canvasRect ? canvasRect.left :
|
|
175
|
-
y: lastTouch.clientY - (canvasRect ? canvasRect.top :
|
|
183
|
+
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, minCoordinate = 0, pos = {
|
|
184
|
+
x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
|
|
185
|
+
y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
|
|
176
186
|
};
|
|
177
187
|
clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
|
|
178
188
|
}
|
|
@@ -214,10 +224,10 @@
|
|
|
214
224
|
this.particles.destroy();
|
|
215
225
|
this.canvas.destroy();
|
|
216
226
|
for (const [, effectDrawer] of this.effectDrawers) {
|
|
217
|
-
effectDrawer.destroy
|
|
227
|
+
effectDrawer.destroy?.(this);
|
|
218
228
|
}
|
|
219
229
|
for (const [, shapeDrawer] of this.shapeDrawers) {
|
|
220
|
-
shapeDrawer.destroy
|
|
230
|
+
shapeDrawer.destroy?.(this);
|
|
221
231
|
}
|
|
222
232
|
for (const key of this.effectDrawers.keys()) {
|
|
223
233
|
this.effectDrawers.delete(key);
|
|
@@ -227,9 +237,10 @@
|
|
|
227
237
|
}
|
|
228
238
|
this._engine.clearPlugins(this);
|
|
229
239
|
this.destroyed = true;
|
|
230
|
-
const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this);
|
|
231
|
-
if (idx >=
|
|
232
|
-
|
|
240
|
+
const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this), minIndex = 0;
|
|
241
|
+
if (idx >= minIndex) {
|
|
242
|
+
const deleteCount = 1;
|
|
243
|
+
mainArr.splice(idx, deleteCount);
|
|
233
244
|
}
|
|
234
245
|
this._engine.dispatchEvent("containerDestroyed", { container: this });
|
|
235
246
|
}
|
|
@@ -238,13 +249,14 @@
|
|
|
238
249
|
return;
|
|
239
250
|
}
|
|
240
251
|
let refreshTime = force;
|
|
241
|
-
|
|
252
|
+
const frame = async (timestamp) => {
|
|
242
253
|
if (refreshTime) {
|
|
243
254
|
this._lastFrameTime = undefined;
|
|
244
255
|
refreshTime = false;
|
|
245
256
|
}
|
|
246
257
|
await this._nextFrame(timestamp);
|
|
247
|
-
}
|
|
258
|
+
};
|
|
259
|
+
this._drawAnimationFrame = requestAnimationFrame((timestamp) => void frame(timestamp));
|
|
248
260
|
}
|
|
249
261
|
async export(type, options = {}) {
|
|
250
262
|
for (const [, plugin] of this.plugins) {
|
|
@@ -259,16 +271,13 @@
|
|
|
259
271
|
}
|
|
260
272
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} - Export plugin with type ${type} not found`);
|
|
261
273
|
}
|
|
262
|
-
getAnimationStatus() {
|
|
263
|
-
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
264
|
-
}
|
|
265
274
|
handleClickMode(mode) {
|
|
266
275
|
if (!guardCheck(this)) {
|
|
267
276
|
return;
|
|
268
277
|
}
|
|
269
278
|
this.particles.handleClickMode(mode);
|
|
270
279
|
for (const [, plugin] of this.plugins) {
|
|
271
|
-
plugin.handleClickMode
|
|
280
|
+
plugin.handleClickMode?.(mode);
|
|
272
281
|
}
|
|
273
282
|
}
|
|
274
283
|
async init() {
|
|
@@ -289,9 +298,10 @@
|
|
|
289
298
|
this.shapeDrawers.set(type, drawer);
|
|
290
299
|
}
|
|
291
300
|
}
|
|
301
|
+
await this.particles.initPlugins();
|
|
292
302
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
293
303
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
294
|
-
const availablePlugins = this._engine.getAvailablePlugins(this);
|
|
304
|
+
const availablePlugins = await this._engine.getAvailablePlugins(this);
|
|
295
305
|
for (const [id, plugin] of availablePlugins) {
|
|
296
306
|
this.plugins.set(id, plugin);
|
|
297
307
|
}
|
|
@@ -301,25 +311,26 @@
|
|
|
301
311
|
this.canvas.initBackground();
|
|
302
312
|
this.canvas.resize();
|
|
303
313
|
this.zLayers = this.actualOptions.zLayers;
|
|
304
|
-
this._duration = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.duration) *
|
|
305
|
-
this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) *
|
|
314
|
+
this._duration = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.duration) * Constants_js_1.millisecondsToSeconds;
|
|
315
|
+
this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) * Constants_js_1.millisecondsToSeconds;
|
|
306
316
|
this._lifeTime = 0;
|
|
307
|
-
|
|
317
|
+
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
318
|
+
this.fpsLimit = this.actualOptions.fpsLimit > minFpsLimit ? this.actualOptions.fpsLimit : defaultFpsLimit;
|
|
308
319
|
this._smooth = this.actualOptions.smooth;
|
|
309
320
|
for (const [, drawer] of this.effectDrawers) {
|
|
310
|
-
|
|
321
|
+
await drawer.init?.(this);
|
|
311
322
|
}
|
|
312
323
|
for (const [, drawer] of this.shapeDrawers) {
|
|
313
|
-
|
|
324
|
+
await drawer.init?.(this);
|
|
314
325
|
}
|
|
315
326
|
for (const [, plugin] of this.plugins) {
|
|
316
|
-
|
|
327
|
+
await plugin.init?.();
|
|
317
328
|
}
|
|
318
329
|
this._engine.dispatchEvent("containerInit", { container: this });
|
|
319
|
-
this.particles.init();
|
|
320
|
-
this.particles.setDensity();
|
|
330
|
+
await this.particles.init();
|
|
331
|
+
await this.particles.setDensity();
|
|
321
332
|
for (const [, plugin] of this.plugins) {
|
|
322
|
-
plugin.particlesSetup
|
|
333
|
+
plugin.particlesSetup?.();
|
|
323
334
|
}
|
|
324
335
|
this._engine.dispatchEvent("particlesSetup", { container: this });
|
|
325
336
|
}
|
|
@@ -342,7 +353,7 @@
|
|
|
342
353
|
return;
|
|
343
354
|
}
|
|
344
355
|
for (const [, plugin] of this.plugins) {
|
|
345
|
-
plugin.pause
|
|
356
|
+
plugin.pause?.();
|
|
346
357
|
}
|
|
347
358
|
if (!this.pageHidden) {
|
|
348
359
|
this._paused = true;
|
|
@@ -369,7 +380,7 @@
|
|
|
369
380
|
}
|
|
370
381
|
}
|
|
371
382
|
this._engine.dispatchEvent("containerPlay", { container: this });
|
|
372
|
-
this.draw(needsUpdate
|
|
383
|
+
this.draw(needsUpdate ?? false);
|
|
373
384
|
}
|
|
374
385
|
async refresh() {
|
|
375
386
|
if (!guardCheck(this)) {
|
|
@@ -394,18 +405,19 @@
|
|
|
394
405
|
await this.init();
|
|
395
406
|
this.started = true;
|
|
396
407
|
await new Promise((resolve) => {
|
|
397
|
-
|
|
408
|
+
const start = async () => {
|
|
398
409
|
this._eventListeners.addListeners();
|
|
399
410
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
400
411
|
this._intersectionObserver.observe(this.interactivity.element);
|
|
401
412
|
}
|
|
402
413
|
for (const [, plugin] of this.plugins) {
|
|
403
|
-
|
|
414
|
+
await plugin.start?.();
|
|
404
415
|
}
|
|
405
416
|
this._engine.dispatchEvent("containerStarted", { container: this });
|
|
406
417
|
this.play();
|
|
407
418
|
resolve();
|
|
408
|
-
}
|
|
419
|
+
};
|
|
420
|
+
this._delayTimeout = setTimeout(() => void start(), this._delay);
|
|
409
421
|
});
|
|
410
422
|
}
|
|
411
423
|
stop() {
|
|
@@ -426,7 +438,7 @@
|
|
|
426
438
|
this._intersectionObserver.unobserve(this.interactivity.element);
|
|
427
439
|
}
|
|
428
440
|
for (const [, plugin] of this.plugins) {
|
|
429
|
-
plugin.stop
|
|
441
|
+
plugin.stop?.();
|
|
430
442
|
}
|
|
431
443
|
for (const key of this.plugins.keys()) {
|
|
432
444
|
this.plugins.delete(key);
|