@tsparticles/engine 3.1.0 → 3.2.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/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 +72 -71
- package/browser/Core/Canvas.js +85 -32
- package/browser/Core/Container.js +8 -7
- package/browser/Core/Engine.js +14 -15
- package/browser/Core/Particle.js +14 -15
- package/browser/Core/Particles.js +42 -35
- package/browser/Core/Utils/EventListeners.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +3 -2
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/browser/Utils/CanvasUtils.js +14 -14
- package/cjs/Core/Canvas.js +85 -32
- package/cjs/Core/Container.js +8 -7
- package/cjs/Core/Engine.js +37 -15
- package/cjs/Core/Particle.js +14 -15
- package/cjs/Core/Particles.js +65 -35
- package/cjs/Core/Utils/EventListeners.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +3 -2
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/cjs/Utils/CanvasUtils.js +14 -14
- package/dist_browser_Core_Container_js.js +92 -0
- package/dist_browser_Core_Particle_js.js +32 -0
- package/esm/Core/Canvas.js +85 -32
- package/esm/Core/Container.js +8 -7
- package/esm/Core/Engine.js +14 -15
- package/esm/Core/Particle.js +14 -15
- package/esm/Core/Particles.js +42 -35
- package/esm/Core/Utils/EventListeners.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +3 -2
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/esm/Utils/CanvasUtils.js +14 -14
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +894 -5820
- 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/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IPlugin.d.ts +1 -1
- 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/InteractionManager.d.ts +2 -2
- package/types/Enums/Modes/OutMode.d.ts +0 -3
- package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +2 -1
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +6 -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/Particles/Move/IMove.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IOutModes.d.ts +6 -6
- package/types/Utils/CanvasUtils.d.ts +6 -6
- package/umd/Core/Canvas.js +85 -32
- package/umd/Core/Container.js +8 -7
- package/umd/Core/Engine.js +39 -16
- package/umd/Core/Particle.js +14 -15
- package/umd/Core/Particles.js +67 -36
- package/umd/Core/Utils/EventListeners.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +3 -2
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/umd/Utils/CanvasUtils.js +14 -14
package/cjs/Core/Container.js
CHANGED
|
@@ -64,7 +64,7 @@ class Container {
|
|
|
64
64
|
this.destroy();
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
if (this.
|
|
67
|
+
if (this.animationStatus) {
|
|
68
68
|
this.draw(false);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -107,6 +107,9 @@ class Container {
|
|
|
107
107
|
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)((entries) => this._intersectionManager(entries));
|
|
108
108
|
this._engine.dispatchEvent("containerBuilt", { container: this });
|
|
109
109
|
}
|
|
110
|
+
get animationStatus() {
|
|
111
|
+
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
112
|
+
}
|
|
110
113
|
get options() {
|
|
111
114
|
return this._options;
|
|
112
115
|
}
|
|
@@ -259,9 +262,6 @@ class Container {
|
|
|
259
262
|
}
|
|
260
263
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} - Export plugin with type ${type} not found`);
|
|
261
264
|
}
|
|
262
|
-
getAnimationStatus() {
|
|
263
|
-
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
264
|
-
}
|
|
265
265
|
handleClickMode(mode) {
|
|
266
266
|
if (!guardCheck(this)) {
|
|
267
267
|
return;
|
|
@@ -289,9 +289,10 @@ class Container {
|
|
|
289
289
|
this.shapeDrawers.set(type, drawer);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
|
+
await this.particles.initPlugins();
|
|
292
293
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
293
294
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
294
|
-
const availablePlugins = this._engine.getAvailablePlugins(this);
|
|
295
|
+
const availablePlugins = await this._engine.getAvailablePlugins(this);
|
|
295
296
|
for (const [id, plugin] of availablePlugins) {
|
|
296
297
|
this.plugins.set(id, plugin);
|
|
297
298
|
}
|
|
@@ -317,8 +318,8 @@ class Container {
|
|
|
317
318
|
await plugin.init?.();
|
|
318
319
|
}
|
|
319
320
|
this._engine.dispatchEvent("containerInit", { container: this });
|
|
320
|
-
this.particles.init();
|
|
321
|
-
this.particles.setDensity();
|
|
321
|
+
await this.particles.init();
|
|
322
|
+
await this.particles.setDensity();
|
|
322
323
|
for (const [, plugin] of this.plugins) {
|
|
323
324
|
plugin.particlesSetup?.();
|
|
324
325
|
}
|
package/cjs/Core/Engine.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Engine = void 0;
|
|
4
27
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
5
28
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
6
|
-
const Container_js_1 = require("./Container.js");
|
|
7
29
|
const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
|
|
8
30
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
9
|
-
function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
31
|
+
async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
10
32
|
let res = map.get(container);
|
|
11
33
|
if (!res || force) {
|
|
12
|
-
res = [...initializers.values()].map((t) => t(container));
|
|
34
|
+
res = await Promise.all([...initializers.values()].map((t) => t(container)));
|
|
13
35
|
map.set(container, res);
|
|
14
36
|
}
|
|
15
37
|
return res;
|
|
@@ -21,7 +43,7 @@ async function getDataFromUrl(data) {
|
|
|
21
43
|
}
|
|
22
44
|
const response = await fetch(url);
|
|
23
45
|
if (response.ok) {
|
|
24
|
-
return response.json();
|
|
46
|
+
return (await response.json());
|
|
25
47
|
}
|
|
26
48
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
27
49
|
return data.fallback;
|
|
@@ -54,7 +76,7 @@ class Engine {
|
|
|
54
76
|
return res;
|
|
55
77
|
}
|
|
56
78
|
get version() {
|
|
57
|
-
return "3.1
|
|
79
|
+
return "3.2.1";
|
|
58
80
|
}
|
|
59
81
|
addConfig(config) {
|
|
60
82
|
const key = config.key ?? config.name ?? "default";
|
|
@@ -130,11 +152,11 @@ class Engine {
|
|
|
130
152
|
}
|
|
131
153
|
return item;
|
|
132
154
|
}
|
|
133
|
-
getAvailablePlugins(container) {
|
|
155
|
+
async getAvailablePlugins(container) {
|
|
134
156
|
const res = new Map();
|
|
135
157
|
for (const plugin of this.plugins) {
|
|
136
158
|
if (plugin.needsPlugin(container.actualOptions)) {
|
|
137
|
-
res.set(plugin.id, plugin.getPlugin(container));
|
|
159
|
+
res.set(plugin.id, await plugin.getPlugin(container));
|
|
138
160
|
}
|
|
139
161
|
}
|
|
140
162
|
return res;
|
|
@@ -142,11 +164,11 @@ class Engine {
|
|
|
142
164
|
getEffectDrawer(type) {
|
|
143
165
|
return this.effectDrawers.get(type);
|
|
144
166
|
}
|
|
145
|
-
getInteractors(container, force = false) {
|
|
146
|
-
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
167
|
+
async getInteractors(container, force = false) {
|
|
168
|
+
return await getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
147
169
|
}
|
|
148
|
-
getMovers(container, force = false) {
|
|
149
|
-
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
170
|
+
async getMovers(container, force = false) {
|
|
171
|
+
return await getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
150
172
|
}
|
|
151
173
|
getPathGenerator(type) {
|
|
152
174
|
return this.pathGenerators.get(type);
|
|
@@ -166,8 +188,8 @@ class Engine {
|
|
|
166
188
|
getSupportedShapes() {
|
|
167
189
|
return this.shapeDrawers.keys();
|
|
168
190
|
}
|
|
169
|
-
getUpdaters(container, force = false) {
|
|
170
|
-
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
191
|
+
async getUpdaters(container, force = false) {
|
|
192
|
+
return await getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
171
193
|
}
|
|
172
194
|
init() {
|
|
173
195
|
if (this._initialized) {
|
|
@@ -216,7 +238,7 @@ class Engine {
|
|
|
216
238
|
if (!canvasEl.style.height) {
|
|
217
239
|
canvasEl.style.height = "100%";
|
|
218
240
|
}
|
|
219
|
-
const newItem = new
|
|
241
|
+
const { Container } = await Promise.resolve().then(() => __importStar(require("./Container.js"))), newItem = new Container(this, id, currentOptions);
|
|
220
242
|
if (oldIndex >= minIndex) {
|
|
221
243
|
const deleteCount = 0;
|
|
222
244
|
dom.splice(oldIndex, deleteCount, newItem);
|
|
@@ -246,7 +268,7 @@ class Engine {
|
|
|
246
268
|
if (!refresh) {
|
|
247
269
|
return;
|
|
248
270
|
}
|
|
249
|
-
await Promise.
|
|
271
|
+
await Promise.all(this.dom().map((t) => t.refresh()));
|
|
250
272
|
}
|
|
251
273
|
removeEventListener(type, listener) {
|
|
252
274
|
this._eventDispatcher.removeEventListener(type, listener);
|
package/cjs/Core/Particle.js
CHANGED
|
@@ -44,7 +44,7 @@ function fixOutMode(data) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
class Particle {
|
|
47
|
-
constructor(engine,
|
|
47
|
+
constructor(engine, container) {
|
|
48
48
|
this.container = container;
|
|
49
49
|
this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
|
|
50
50
|
for (const [, plugin] of container.plugins) {
|
|
@@ -59,7 +59,7 @@ class Particle {
|
|
|
59
59
|
}), pos = Vector3d_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
|
|
60
60
|
fixOutMode({
|
|
61
61
|
outMode,
|
|
62
|
-
checkModes: ["bounce"
|
|
62
|
+
checkModes: ["bounce"],
|
|
63
63
|
coord: pos.x,
|
|
64
64
|
maxCoord: container.canvas.size.width,
|
|
65
65
|
setCb: (value) => (pos.x += value),
|
|
@@ -68,7 +68,7 @@ class Particle {
|
|
|
68
68
|
}, fixVertical = (outMode) => {
|
|
69
69
|
fixOutMode({
|
|
70
70
|
outMode,
|
|
71
|
-
checkModes: ["bounce"
|
|
71
|
+
checkModes: ["bounce"],
|
|
72
72
|
coord: pos.y,
|
|
73
73
|
maxCoord: container.canvas.size.height,
|
|
74
74
|
setCb: (value) => (pos.y += value),
|
|
@@ -155,7 +155,6 @@ class Particle {
|
|
|
155
155
|
this.offset = Vector_js_1.Vector.origin;
|
|
156
156
|
};
|
|
157
157
|
this._engine = engine;
|
|
158
|
-
this.init(id, position, overrideOptions, group);
|
|
159
158
|
}
|
|
160
159
|
destroy(override) {
|
|
161
160
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -180,12 +179,12 @@ class Particle {
|
|
|
180
179
|
},
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
|
-
draw(delta) {
|
|
182
|
+
async draw(delta) {
|
|
184
183
|
const container = this.container, canvas = container.canvas;
|
|
185
184
|
for (const [, plugin] of container.plugins) {
|
|
186
|
-
canvas.drawParticlePlugin(plugin, this, delta);
|
|
185
|
+
await canvas.drawParticlePlugin(plugin, this, delta);
|
|
187
186
|
}
|
|
188
|
-
canvas.drawParticle(this, delta);
|
|
187
|
+
await canvas.drawParticle(this, delta);
|
|
189
188
|
}
|
|
190
189
|
getFillColor() {
|
|
191
190
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
|
|
@@ -206,7 +205,7 @@ class Particle {
|
|
|
206
205
|
getStrokeColor() {
|
|
207
206
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.strokeColor));
|
|
208
207
|
}
|
|
209
|
-
init(id, position, overrideOptions, group) {
|
|
208
|
+
async init(id, position, overrideOptions, group) {
|
|
210
209
|
const container = this.container, engine = this._engine;
|
|
211
210
|
this.id = id;
|
|
212
211
|
this.group = group;
|
|
@@ -270,7 +269,7 @@ class Particle {
|
|
|
270
269
|
if (pathOptions.generator) {
|
|
271
270
|
this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);
|
|
272
271
|
if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
|
|
273
|
-
this.pathGenerator.init(container);
|
|
272
|
+
await this.pathGenerator.init(container);
|
|
274
273
|
}
|
|
275
274
|
}
|
|
276
275
|
container.retina.initParticle(this);
|
|
@@ -299,7 +298,7 @@ class Particle {
|
|
|
299
298
|
}
|
|
300
299
|
}
|
|
301
300
|
if (effectDrawer?.loadEffect) {
|
|
302
|
-
effectDrawer.loadEffect(this);
|
|
301
|
+
await effectDrawer.loadEffect(this);
|
|
303
302
|
}
|
|
304
303
|
let shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
305
304
|
if (!shapeDrawer) {
|
|
@@ -309,7 +308,7 @@ class Particle {
|
|
|
309
308
|
}
|
|
310
309
|
}
|
|
311
310
|
if (shapeDrawer?.loadShape) {
|
|
312
|
-
shapeDrawer.loadShape(this);
|
|
311
|
+
await shapeDrawer.loadShape(this);
|
|
313
312
|
}
|
|
314
313
|
const sideCountFunc = shapeDrawer?.getSidesCount;
|
|
315
314
|
if (sideCountFunc) {
|
|
@@ -318,13 +317,13 @@ class Particle {
|
|
|
318
317
|
this.spawning = false;
|
|
319
318
|
this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this.options.shadow.color);
|
|
320
319
|
for (const updater of particles.updaters) {
|
|
321
|
-
updater.init(this);
|
|
320
|
+
await updater.init(this);
|
|
322
321
|
}
|
|
323
322
|
for (const mover of particles.movers) {
|
|
324
|
-
mover.init?.(this);
|
|
323
|
+
await mover.init?.(this);
|
|
325
324
|
}
|
|
326
|
-
effectDrawer?.particleInit?.(container, this);
|
|
327
|
-
shapeDrawer?.particleInit?.(container, this);
|
|
325
|
+
await effectDrawer?.particleInit?.(container, this);
|
|
326
|
+
await shapeDrawer?.particleInit?.(container, this);
|
|
328
327
|
for (const [, plugin] of container.plugins) {
|
|
329
328
|
plugin.particleCreated?.(this);
|
|
330
329
|
}
|
package/cjs/Core/Particles.js
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Particles = void 0;
|
|
4
27
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
5
28
|
const InteractionManager_js_1 = require("./Utils/InteractionManager.js");
|
|
6
|
-
const Particle_js_1 = require("./Particle.js");
|
|
7
29
|
const Point_js_1 = require("./Utils/Point.js");
|
|
8
30
|
const QuadTree_js_1 = require("./Utils/QuadTree.js");
|
|
9
31
|
const Rectangle_js_1 = require("./Utils/Rectangle.js");
|
|
@@ -20,7 +42,7 @@ class Particles {
|
|
|
20
42
|
this._pool.push(particle);
|
|
21
43
|
}
|
|
22
44
|
};
|
|
23
|
-
this._applyDensity = (options, manualCount, group) => {
|
|
45
|
+
this._applyDensity = async (options, manualCount, group) => {
|
|
24
46
|
const numberOptions = options.number;
|
|
25
47
|
if (!options.number.density?.enable) {
|
|
26
48
|
if (group === undefined) {
|
|
@@ -39,7 +61,7 @@ class Particles {
|
|
|
39
61
|
this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
40
62
|
}
|
|
41
63
|
if (particlesCount < particlesNumber) {
|
|
42
|
-
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
64
|
+
await this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
43
65
|
}
|
|
44
66
|
else if (particlesCount > particlesNumber) {
|
|
45
67
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
@@ -53,15 +75,14 @@ class Particles {
|
|
|
53
75
|
const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
|
|
54
76
|
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
|
|
55
77
|
};
|
|
56
|
-
this._pushParticle = (position, overrideOptions, group, initializer) => {
|
|
78
|
+
this._pushParticle = async (position, overrideOptions, group, initializer) => {
|
|
57
79
|
try {
|
|
58
80
|
let particle = this._pool.pop();
|
|
59
|
-
if (particle) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
else {
|
|
63
|
-
particle = new Particle_js_1.Particle(this._engine, this._nextId, this._container, position, overrideOptions, group);
|
|
81
|
+
if (!particle) {
|
|
82
|
+
const { Particle } = await Promise.resolve().then(() => __importStar(require("./Particle.js")));
|
|
83
|
+
particle = new Particle(this._engine, this._container);
|
|
64
84
|
}
|
|
85
|
+
await particle.init(this._nextId, position, overrideOptions, group);
|
|
65
86
|
let canAdd = true;
|
|
66
87
|
if (initializer) {
|
|
67
88
|
canAdd = initializer(particle);
|
|
@@ -113,21 +134,22 @@ class Particles {
|
|
|
113
134
|
this._needsSort = false;
|
|
114
135
|
this._lastZIndex = 0;
|
|
115
136
|
this._interactionManager = new InteractionManager_js_1.InteractionManager(engine, container);
|
|
137
|
+
this._pluginsInitialized = false;
|
|
116
138
|
const canvasSize = container.canvas.size;
|
|
117
139
|
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
|
|
118
|
-
this.movers =
|
|
119
|
-
this.updaters =
|
|
140
|
+
this.movers = [];
|
|
141
|
+
this.updaters = [];
|
|
120
142
|
}
|
|
121
143
|
get count() {
|
|
122
144
|
return this._array.length;
|
|
123
145
|
}
|
|
124
|
-
addManualParticles() {
|
|
146
|
+
async addManualParticles() {
|
|
125
147
|
const container = this._container, options = container.actualOptions;
|
|
126
148
|
for (const particle of options.manualParticles) {
|
|
127
|
-
this.addParticle(particle.position ? (0, Utils_js_1.getPosition)(particle.position, container.canvas.size) : undefined, particle.options);
|
|
149
|
+
await this.addParticle(particle.position ? (0, Utils_js_1.getPosition)(particle.position, container.canvas.size) : undefined, particle.options);
|
|
128
150
|
}
|
|
129
151
|
}
|
|
130
|
-
addParticle(position, overrideOptions, group, initializer) {
|
|
152
|
+
async addParticle(position, overrideOptions, group, initializer) {
|
|
131
153
|
const limitOptions = this._container.actualOptions.particles.number.limit, limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit, currentCount = this.count, minLimit = 0;
|
|
132
154
|
if (limit > minLimit) {
|
|
133
155
|
if (limitOptions.mode === "delete") {
|
|
@@ -142,11 +164,12 @@ class Particles {
|
|
|
142
164
|
}
|
|
143
165
|
}
|
|
144
166
|
}
|
|
145
|
-
return this._pushParticle(position, overrideOptions, group, initializer);
|
|
167
|
+
return await this._pushParticle(position, overrideOptions, group, initializer);
|
|
146
168
|
}
|
|
147
169
|
clear() {
|
|
148
170
|
this._array = [];
|
|
149
171
|
this._zArray = [];
|
|
172
|
+
this._pluginsInitialized = false;
|
|
150
173
|
}
|
|
151
174
|
destroy() {
|
|
152
175
|
this._array = [];
|
|
@@ -159,10 +182,10 @@ class Particles {
|
|
|
159
182
|
canvas.clear();
|
|
160
183
|
await this.update(delta);
|
|
161
184
|
for (const [, plugin] of container.plugins) {
|
|
162
|
-
canvas.drawPlugin(plugin, delta);
|
|
185
|
+
await canvas.drawPlugin(plugin, delta);
|
|
163
186
|
}
|
|
164
187
|
for (const p of this._zArray) {
|
|
165
|
-
p.draw(delta);
|
|
188
|
+
await p.draw(delta);
|
|
166
189
|
}
|
|
167
190
|
}
|
|
168
191
|
filter(condition) {
|
|
@@ -177,13 +200,12 @@ class Particles {
|
|
|
177
200
|
handleClickMode(mode) {
|
|
178
201
|
this._interactionManager.handleClickMode(mode);
|
|
179
202
|
}
|
|
180
|
-
init() {
|
|
203
|
+
async init() {
|
|
181
204
|
const container = this._container, options = container.actualOptions;
|
|
182
205
|
this._lastZIndex = 0;
|
|
183
206
|
this._needsSort = false;
|
|
207
|
+
await this.initPlugins();
|
|
184
208
|
let handled = false;
|
|
185
|
-
this.updaters = this._engine.getUpdaters(container, true);
|
|
186
|
-
this._interactionManager.init();
|
|
187
209
|
for (const [, plugin] of container.plugins) {
|
|
188
210
|
if (plugin.particlesInitialization !== undefined) {
|
|
189
211
|
handled = plugin.particlesInitialization();
|
|
@@ -192,32 +214,40 @@ class Particles {
|
|
|
192
214
|
break;
|
|
193
215
|
}
|
|
194
216
|
}
|
|
195
|
-
this.
|
|
196
|
-
for (const [, pathGenerator] of container.pathGenerators) {
|
|
197
|
-
pathGenerator.init(container);
|
|
198
|
-
}
|
|
199
|
-
this.addManualParticles();
|
|
217
|
+
await this.addManualParticles();
|
|
200
218
|
if (!handled) {
|
|
201
219
|
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
202
220
|
for (const group in groups) {
|
|
203
221
|
const groupOptions = groups[group];
|
|
204
222
|
for (let i = this.count, j = 0; j < groupOptions.number?.value && i < particlesOptions.number.value; i++, j++) {
|
|
205
|
-
this.addParticle(undefined, groupOptions, group);
|
|
223
|
+
await this.addParticle(undefined, groupOptions, group);
|
|
206
224
|
}
|
|
207
225
|
}
|
|
208
226
|
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
209
|
-
this.addParticle();
|
|
227
|
+
await this.addParticle();
|
|
210
228
|
}
|
|
211
229
|
}
|
|
212
230
|
}
|
|
213
|
-
|
|
231
|
+
async initPlugins() {
|
|
232
|
+
if (this._pluginsInitialized) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const container = this._container;
|
|
236
|
+
this.movers = await this._engine.getMovers(container, true);
|
|
237
|
+
this.updaters = await this._engine.getUpdaters(container, true);
|
|
238
|
+
await this._interactionManager.init();
|
|
239
|
+
for (const [, pathGenerator] of container.pathGenerators) {
|
|
240
|
+
await pathGenerator.init(container);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async push(nb, mouse, overrideOptions, group) {
|
|
214
244
|
for (let i = 0; i < nb; i++) {
|
|
215
|
-
this.addParticle(mouse?.position, overrideOptions, group);
|
|
245
|
+
await this.addParticle(mouse?.position, overrideOptions, group);
|
|
216
246
|
}
|
|
217
247
|
}
|
|
218
248
|
async redraw() {
|
|
219
249
|
this.clear();
|
|
220
|
-
this.init();
|
|
250
|
+
await this.init();
|
|
221
251
|
await this.draw({ value: 0, factor: 0 });
|
|
222
252
|
}
|
|
223
253
|
remove(particle, group, override) {
|
|
@@ -239,12 +269,12 @@ class Particles {
|
|
|
239
269
|
const defaultIndex = 0;
|
|
240
270
|
this.removeAt(defaultIndex, quantity, group);
|
|
241
271
|
}
|
|
242
|
-
setDensity() {
|
|
272
|
+
async setDensity() {
|
|
243
273
|
const options = this._container.actualOptions, groups = options.particles.groups, manualCount = 0;
|
|
244
274
|
for (const group in groups) {
|
|
245
|
-
this._applyDensity(groups[group], manualCount, group);
|
|
275
|
+
await this._applyDensity(groups[group], manualCount, group);
|
|
246
276
|
}
|
|
247
|
-
this._applyDensity(options.particles, options.manualParticles.length);
|
|
277
|
+
await this._applyDensity(options.particles, options.manualParticles.length);
|
|
248
278
|
}
|
|
249
279
|
setLastZIndex(zIndex) {
|
|
250
280
|
this._lastZIndex = zIndex;
|
|
@@ -280,7 +310,7 @@ class Particles {
|
|
|
280
310
|
}
|
|
281
311
|
for (const mover of this.movers) {
|
|
282
312
|
if (mover.isEnabled(particle)) {
|
|
283
|
-
mover.move(particle, delta);
|
|
313
|
+
await mover.move(particle, delta);
|
|
284
314
|
}
|
|
285
315
|
}
|
|
286
316
|
if (particle.destroyed) {
|
|
@@ -306,7 +336,7 @@ class Particles {
|
|
|
306
336
|
await this._interactionManager.externalInteract(delta);
|
|
307
337
|
for (const particle of this._array) {
|
|
308
338
|
for (const updater of this.updaters) {
|
|
309
|
-
updater.update(particle, delta);
|
|
339
|
+
await updater.update(particle, delta);
|
|
310
340
|
}
|
|
311
341
|
if (!particle.destroyed && !particle.spawning) {
|
|
312
342
|
await this._interactionManager.particlesInteract(particle, delta);
|
|
@@ -5,7 +5,7 @@ class InteractionManager {
|
|
|
5
5
|
constructor(engine, container) {
|
|
6
6
|
this.container = container;
|
|
7
7
|
this._engine = engine;
|
|
8
|
-
this._interactors =
|
|
8
|
+
this._interactors = [];
|
|
9
9
|
this._externalInteractors = [];
|
|
10
10
|
this._particleInteractors = [];
|
|
11
11
|
}
|
|
@@ -21,7 +21,8 @@ class InteractionManager {
|
|
|
21
21
|
interactor.handleClickMode?.(mode);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
init() {
|
|
24
|
+
async init() {
|
|
25
|
+
this._interactors = await this._engine.getInteractors(this.container, true);
|
|
25
26
|
this._externalInteractors = [];
|
|
26
27
|
this._particleInteractors = [];
|
|
27
28
|
for (const interactor of this._interactors) {
|
|
@@ -18,7 +18,7 @@ class BackgroundMask {
|
|
|
18
18
|
}
|
|
19
19
|
if (data.cover !== undefined) {
|
|
20
20
|
const cover = data.cover, color = ((0, Utils_js_1.isString)(data.cover) ? { color: data.cover } : data.cover);
|
|
21
|
-
this.cover.load(cover.color !== undefined ? cover : { color: color });
|
|
21
|
+
this.cover.load(cover.color !== undefined || cover.image !== undefined ? cover : { color: color });
|
|
22
22
|
}
|
|
23
23
|
if (data.enable !== undefined) {
|
|
24
24
|
this.enable = data.enable;
|
|
@@ -4,8 +4,6 @@ exports.BackgroundMaskCover = void 0;
|
|
|
4
4
|
const OptionsColor_js_1 = require("../OptionsColor.js");
|
|
5
5
|
class BackgroundMaskCover {
|
|
6
6
|
constructor() {
|
|
7
|
-
this.color = new OptionsColor_js_1.OptionsColor();
|
|
8
|
-
this.color.value = "#fff";
|
|
9
7
|
this.opacity = 1;
|
|
10
8
|
}
|
|
11
9
|
load(data) {
|
|
@@ -15,6 +13,9 @@ class BackgroundMaskCover {
|
|
|
15
13
|
if (data.color !== undefined) {
|
|
16
14
|
this.color = OptionsColor_js_1.OptionsColor.create(this.color, data.color);
|
|
17
15
|
}
|
|
16
|
+
if (data.image !== undefined) {
|
|
17
|
+
this.image = data.image;
|
|
18
|
+
}
|
|
18
19
|
if (data.opacity !== undefined) {
|
|
19
20
|
this.opacity = data.opacity;
|
|
20
21
|
}
|
package/cjs/Utils/CanvasUtils.js
CHANGED
|
@@ -28,7 +28,7 @@ function clear(context, dimension) {
|
|
|
28
28
|
context.clearRect(origin.x, origin.y, dimension.width, dimension.height);
|
|
29
29
|
}
|
|
30
30
|
exports.clear = clear;
|
|
31
|
-
function drawParticle(data) {
|
|
31
|
+
async function drawParticle(data) {
|
|
32
32
|
const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data, pos = particle.getPosition(), defaultAngle = 0, angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : defaultAngle), rotateData = {
|
|
33
33
|
sin: Math.sin(angle),
|
|
34
34
|
cos: Math.cos(angle),
|
|
@@ -67,14 +67,14 @@ function drawParticle(data) {
|
|
|
67
67
|
transformData,
|
|
68
68
|
strokeWidth,
|
|
69
69
|
};
|
|
70
|
-
drawShape(drawData);
|
|
71
|
-
drawShapeAfterDraw(drawData);
|
|
72
|
-
drawEffect(drawData);
|
|
70
|
+
await drawShape(drawData);
|
|
71
|
+
await drawShapeAfterDraw(drawData);
|
|
72
|
+
await drawEffect(drawData);
|
|
73
73
|
context.globalCompositeOperation = "source-over";
|
|
74
74
|
context.resetTransform();
|
|
75
75
|
}
|
|
76
76
|
exports.drawParticle = drawParticle;
|
|
77
|
-
function drawEffect(data) {
|
|
77
|
+
async function drawEffect(data) {
|
|
78
78
|
const { container, context, particle, radius, opacity, delta, transformData } = data;
|
|
79
79
|
if (!particle.effect) {
|
|
80
80
|
return;
|
|
@@ -83,7 +83,7 @@ function drawEffect(data) {
|
|
|
83
83
|
if (!drawer) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
drawer.draw({
|
|
86
|
+
await drawer.draw({
|
|
87
87
|
context,
|
|
88
88
|
particle,
|
|
89
89
|
radius,
|
|
@@ -94,7 +94,7 @@ function drawEffect(data) {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
exports.drawEffect = drawEffect;
|
|
97
|
-
function drawShape(data) {
|
|
97
|
+
async function drawShape(data) {
|
|
98
98
|
const { container, context, particle, radius, opacity, delta, strokeWidth, transformData } = data, minStrokeWidth = 0;
|
|
99
99
|
if (!particle.shape) {
|
|
100
100
|
return;
|
|
@@ -104,7 +104,7 @@ function drawShape(data) {
|
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
context.beginPath();
|
|
107
|
-
drawer.draw({
|
|
107
|
+
await drawer.draw({
|
|
108
108
|
context,
|
|
109
109
|
particle,
|
|
110
110
|
radius,
|
|
@@ -124,7 +124,7 @@ function drawShape(data) {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
exports.drawShape = drawShape;
|
|
127
|
-
function drawShapeAfterDraw(data) {
|
|
127
|
+
async function drawShapeAfterDraw(data) {
|
|
128
128
|
const { container, context, particle, radius, opacity, delta, transformData } = data;
|
|
129
129
|
if (!particle.shape) {
|
|
130
130
|
return;
|
|
@@ -133,7 +133,7 @@ function drawShapeAfterDraw(data) {
|
|
|
133
133
|
if (!drawer?.afterDraw) {
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
drawer.afterDraw({
|
|
136
|
+
await drawer.afterDraw({
|
|
137
137
|
context,
|
|
138
138
|
particle,
|
|
139
139
|
radius,
|
|
@@ -144,18 +144,18 @@ function drawShapeAfterDraw(data) {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
exports.drawShapeAfterDraw = drawShapeAfterDraw;
|
|
147
|
-
function drawPlugin(context, plugin, delta) {
|
|
147
|
+
async function drawPlugin(context, plugin, delta) {
|
|
148
148
|
if (!plugin.draw) {
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
|
-
plugin.draw(context, delta);
|
|
151
|
+
await plugin.draw(context, delta);
|
|
152
152
|
}
|
|
153
153
|
exports.drawPlugin = drawPlugin;
|
|
154
|
-
function drawParticlePlugin(context, plugin, particle, delta) {
|
|
154
|
+
async function drawParticlePlugin(context, plugin, particle, delta) {
|
|
155
155
|
if (!plugin.drawParticle) {
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
|
-
plugin.drawParticle(context, particle, delta);
|
|
158
|
+
await plugin.drawParticle(context, particle, delta);
|
|
159
159
|
}
|
|
160
160
|
exports.drawParticlePlugin = drawParticlePlugin;
|
|
161
161
|
function alterHsl(color, type, value) {
|