@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/Engine.js
CHANGED
|
@@ -1,24 +1,47 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
1
24
|
(function (factory) {
|
|
2
25
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
26
|
var v = factory(require, exports);
|
|
4
27
|
if (v !== undefined) module.exports = v;
|
|
5
28
|
}
|
|
6
29
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "
|
|
30
|
+
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/EventDispatcher.js", "../Utils/NumberUtils.js"], factory);
|
|
8
31
|
}
|
|
9
32
|
})(function (require, exports) {
|
|
10
33
|
"use strict";
|
|
34
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.Engine = void 0;
|
|
13
37
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
14
38
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
15
|
-
const Container_js_1 = require("./Container.js");
|
|
16
39
|
const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
|
|
17
40
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
18
|
-
function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
41
|
+
async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
19
42
|
let res = map.get(container);
|
|
20
43
|
if (!res || force) {
|
|
21
|
-
res = [...initializers.values()].map((t) => t(container));
|
|
44
|
+
res = await Promise.all([...initializers.values()].map((t) => t(container)));
|
|
22
45
|
map.set(container, res);
|
|
23
46
|
}
|
|
24
47
|
return res;
|
|
@@ -30,7 +53,7 @@
|
|
|
30
53
|
}
|
|
31
54
|
const response = await fetch(url);
|
|
32
55
|
if (response.ok) {
|
|
33
|
-
return response.json();
|
|
56
|
+
return (await response.json());
|
|
34
57
|
}
|
|
35
58
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
36
59
|
return data.fallback;
|
|
@@ -63,16 +86,18 @@
|
|
|
63
86
|
return res;
|
|
64
87
|
}
|
|
65
88
|
get version() {
|
|
66
|
-
return "3.0
|
|
89
|
+
return "3.2.0";
|
|
67
90
|
}
|
|
68
91
|
addConfig(config) {
|
|
69
|
-
const
|
|
70
|
-
this._configs.set(
|
|
71
|
-
this._eventDispatcher.dispatchEvent("configAdded", { data: { name, config } });
|
|
92
|
+
const key = config.key ?? config.name ?? "default";
|
|
93
|
+
this._configs.set(key, config);
|
|
94
|
+
this._eventDispatcher.dispatchEvent("configAdded", { data: { name: key, config } });
|
|
72
95
|
}
|
|
73
96
|
async addEffect(effect, drawer, refresh = true) {
|
|
74
97
|
(0, Utils_js_1.executeOnSingleOrMultiple)(effect, (type) => {
|
|
75
|
-
!this.getEffectDrawer(type)
|
|
98
|
+
if (!this.getEffectDrawer(type)) {
|
|
99
|
+
this.effectDrawers.set(type, drawer);
|
|
100
|
+
}
|
|
76
101
|
});
|
|
77
102
|
await this.refresh(refresh);
|
|
78
103
|
}
|
|
@@ -92,20 +117,28 @@
|
|
|
92
117
|
await this.refresh(refresh);
|
|
93
118
|
}
|
|
94
119
|
async addPathGenerator(name, generator, refresh = true) {
|
|
95
|
-
!this.getPathGenerator(name)
|
|
120
|
+
if (!this.getPathGenerator(name)) {
|
|
121
|
+
this.pathGenerators.set(name, generator);
|
|
122
|
+
}
|
|
96
123
|
await this.refresh(refresh);
|
|
97
124
|
}
|
|
98
125
|
async addPlugin(plugin, refresh = true) {
|
|
99
|
-
!this.getPlugin(plugin.id)
|
|
126
|
+
if (!this.getPlugin(plugin.id)) {
|
|
127
|
+
this.plugins.push(plugin);
|
|
128
|
+
}
|
|
100
129
|
await this.refresh(refresh);
|
|
101
130
|
}
|
|
102
131
|
async addPreset(preset, options, override = false, refresh = true) {
|
|
103
|
-
(override || !this.getPreset(preset))
|
|
132
|
+
if (override || !this.getPreset(preset)) {
|
|
133
|
+
this.presets.set(preset, options);
|
|
134
|
+
}
|
|
104
135
|
await this.refresh(refresh);
|
|
105
136
|
}
|
|
106
137
|
async addShape(shape, drawer, refresh = true) {
|
|
107
138
|
(0, Utils_js_1.executeOnSingleOrMultiple)(shape, (type) => {
|
|
108
|
-
!this.getShapeDrawer(type)
|
|
139
|
+
if (!this.getShapeDrawer(type)) {
|
|
140
|
+
this.shapeDrawers.set(type, drawer);
|
|
141
|
+
}
|
|
109
142
|
});
|
|
110
143
|
await this.refresh(refresh);
|
|
111
144
|
}
|
|
@@ -123,26 +156,29 @@
|
|
|
123
156
|
domItem(index) {
|
|
124
157
|
const dom = this.dom(), item = dom[index];
|
|
125
158
|
if (!item || item.destroyed) {
|
|
126
|
-
|
|
159
|
+
const deleteCount = 1;
|
|
160
|
+
dom.splice(index, deleteCount);
|
|
127
161
|
return;
|
|
128
162
|
}
|
|
129
163
|
return item;
|
|
130
164
|
}
|
|
131
|
-
getAvailablePlugins(container) {
|
|
165
|
+
async getAvailablePlugins(container) {
|
|
132
166
|
const res = new Map();
|
|
133
167
|
for (const plugin of this.plugins) {
|
|
134
|
-
plugin.needsPlugin(container.actualOptions)
|
|
168
|
+
if (plugin.needsPlugin(container.actualOptions)) {
|
|
169
|
+
res.set(plugin.id, await plugin.getPlugin(container));
|
|
170
|
+
}
|
|
135
171
|
}
|
|
136
172
|
return res;
|
|
137
173
|
}
|
|
138
174
|
getEffectDrawer(type) {
|
|
139
175
|
return this.effectDrawers.get(type);
|
|
140
176
|
}
|
|
141
|
-
getInteractors(container, force = false) {
|
|
142
|
-
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
177
|
+
async getInteractors(container, force = false) {
|
|
178
|
+
return await getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
143
179
|
}
|
|
144
|
-
getMovers(container, force = false) {
|
|
145
|
-
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
180
|
+
async getMovers(container, force = false) {
|
|
181
|
+
return await getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
146
182
|
}
|
|
147
183
|
getPathGenerator(type) {
|
|
148
184
|
return this.pathGenerators.get(type);
|
|
@@ -162,8 +198,8 @@
|
|
|
162
198
|
getSupportedShapes() {
|
|
163
199
|
return this.shapeDrawers.keys();
|
|
164
200
|
}
|
|
165
|
-
getUpdaters(container, force = false) {
|
|
166
|
-
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
201
|
+
async getUpdaters(container, force = false) {
|
|
202
|
+
return await getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
167
203
|
}
|
|
168
204
|
init() {
|
|
169
205
|
if (this._initialized) {
|
|
@@ -172,19 +208,20 @@
|
|
|
172
208
|
this._initialized = true;
|
|
173
209
|
}
|
|
174
210
|
async load(params) {
|
|
175
|
-
const id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() *
|
|
211
|
+
const randomFactor = 10000, id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() * randomFactor)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
|
|
176
212
|
let domContainer = params.element ?? document.getElementById(id);
|
|
177
213
|
if (!domContainer) {
|
|
178
214
|
domContainer = document.createElement("div");
|
|
179
215
|
domContainer.id = id;
|
|
180
216
|
document.body.append(domContainer);
|
|
181
217
|
}
|
|
182
|
-
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id);
|
|
183
|
-
if (oldIndex >=
|
|
218
|
+
const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id.description === id), minIndex = 0;
|
|
219
|
+
if (oldIndex >= minIndex) {
|
|
184
220
|
const old = this.domItem(oldIndex);
|
|
185
221
|
if (old && !old.destroyed) {
|
|
186
222
|
old.destroy();
|
|
187
|
-
|
|
223
|
+
const deleteCount = 1;
|
|
224
|
+
dom.splice(oldIndex, deleteCount);
|
|
188
225
|
}
|
|
189
226
|
}
|
|
190
227
|
let canvasEl;
|
|
@@ -195,7 +232,8 @@
|
|
|
195
232
|
else {
|
|
196
233
|
const existingCanvases = domContainer.getElementsByTagName("canvas");
|
|
197
234
|
if (existingCanvases.length) {
|
|
198
|
-
|
|
235
|
+
const firstIndex = 0;
|
|
236
|
+
canvasEl = existingCanvases[firstIndex];
|
|
199
237
|
canvasEl.dataset[Constants_js_1.generatedAttribute] = "false";
|
|
200
238
|
}
|
|
201
239
|
else {
|
|
@@ -210,9 +248,10 @@
|
|
|
210
248
|
if (!canvasEl.style.height) {
|
|
211
249
|
canvasEl.style.height = "100%";
|
|
212
250
|
}
|
|
213
|
-
const newItem = new
|
|
214
|
-
if (oldIndex >=
|
|
215
|
-
|
|
251
|
+
const { Container } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Container.js"))) : new Promise((resolve_1, reject_1) => { require(["./Container.js"], resolve_1, reject_1); }).then(__importStar)), newItem = new Container(this, id, currentOptions);
|
|
252
|
+
if (oldIndex >= minIndex) {
|
|
253
|
+
const deleteCount = 0;
|
|
254
|
+
dom.splice(oldIndex, deleteCount, newItem);
|
|
216
255
|
}
|
|
217
256
|
else {
|
|
218
257
|
dom.push(newItem);
|
|
@@ -232,14 +271,14 @@
|
|
|
232
271
|
return;
|
|
233
272
|
}
|
|
234
273
|
for (const updater of updaters) {
|
|
235
|
-
updater.loadOptions
|
|
274
|
+
updater.loadOptions?.(options, ...sourceOptions);
|
|
236
275
|
}
|
|
237
276
|
}
|
|
238
277
|
async refresh(refresh = true) {
|
|
239
278
|
if (!refresh) {
|
|
240
279
|
return;
|
|
241
280
|
}
|
|
242
|
-
this.dom().
|
|
281
|
+
await Promise.all(this.dom().map((t) => t.refresh()));
|
|
243
282
|
}
|
|
244
283
|
removeEventListener(type, listener) {
|
|
245
284
|
this._eventDispatcher.removeEventListener(type, listener);
|
package/umd/Core/Particle.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/NumberUtils.js", "../Utils/Utils.js", "../Utils/ColorUtils.js", "../Options/Classes/Interactivity/Interactivity.js", "./Utils/Vector.js", "./Utils/Vector3d.js", "../Utils/CanvasUtils.js", "
|
|
7
|
+
define(["require", "exports", "../Utils/NumberUtils.js", "../Utils/Utils.js", "./Utils/Constants.js", "../Utils/ColorUtils.js", "../Options/Classes/Interactivity/Interactivity.js", "./Utils/Vector.js", "./Utils/Vector3d.js", "../Utils/CanvasUtils.js", "../Utils/OptionsUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
exports.Particle = void 0;
|
|
13
13
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
14
14
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
15
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
15
16
|
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
16
17
|
const Interactivity_js_1 = require("../Options/Classes/Interactivity/Interactivity.js");
|
|
17
18
|
const Vector_js_1 = require("./Utils/Vector.js");
|
|
18
19
|
const Vector3d_js_1 = require("./Utils/Vector3d.js");
|
|
19
20
|
const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
|
|
20
|
-
const Constants_js_1 = require("./Utils/Constants.js");
|
|
21
21
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
22
|
+
const defaultRetryCount = 0, double = 2, half = 0.5, squareExp = 2;
|
|
22
23
|
function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
|
|
23
24
|
const effectData = effectOptions.options[effect];
|
|
24
25
|
if (!effectData) {
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
if (!(0, Utils_js_1.isInArray)(data.outMode, data.checkModes)) {
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
|
-
const diameter = data.radius *
|
|
47
|
+
const diameter = data.radius * double;
|
|
47
48
|
if (data.coord > data.maxCoord - diameter) {
|
|
48
49
|
data.setCb(-data.radius);
|
|
49
50
|
}
|
|
@@ -52,9 +53,9 @@
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
class Particle {
|
|
55
|
-
constructor(engine,
|
|
56
|
+
constructor(engine, container) {
|
|
56
57
|
this.container = container;
|
|
57
|
-
this._calcPosition = (container, position, zIndex, tryCount =
|
|
58
|
+
this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
|
|
58
59
|
for (const [, plugin] of container.plugins) {
|
|
59
60
|
const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
|
60
61
|
if (pluginPos) {
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
}), pos = Vector3d_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
|
|
68
69
|
fixOutMode({
|
|
69
70
|
outMode,
|
|
70
|
-
checkModes: ["bounce"
|
|
71
|
+
checkModes: ["bounce"],
|
|
71
72
|
coord: pos.x,
|
|
72
73
|
maxCoord: container.canvas.size.width,
|
|
73
74
|
setCb: (value) => (pos.x += value),
|
|
@@ -76,7 +77,7 @@
|
|
|
76
77
|
}, fixVertical = (outMode) => {
|
|
77
78
|
fixOutMode({
|
|
78
79
|
outMode,
|
|
79
|
-
checkModes: ["bounce"
|
|
80
|
+
checkModes: ["bounce"],
|
|
80
81
|
coord: pos.y,
|
|
81
82
|
maxCoord: container.canvas.size.height,
|
|
82
83
|
setCb: (value) => (pos.y += value),
|
|
@@ -88,7 +89,8 @@
|
|
|
88
89
|
fixVertical(outModes.top ?? outModes.default);
|
|
89
90
|
fixVertical(outModes.bottom ?? outModes.default);
|
|
90
91
|
if (this._checkOverlap(pos, tryCount)) {
|
|
91
|
-
|
|
92
|
+
const increment = 1;
|
|
93
|
+
return this._calcPosition(container, undefined, zIndex, tryCount + increment);
|
|
92
94
|
}
|
|
93
95
|
return pos;
|
|
94
96
|
};
|
|
@@ -97,9 +99,9 @@
|
|
|
97
99
|
if (moveOptions.direction === "inside" || moveOptions.direction === "outside") {
|
|
98
100
|
return res;
|
|
99
101
|
}
|
|
100
|
-
const rad = (
|
|
101
|
-
left: radOffset - rad *
|
|
102
|
-
right: radOffset + rad *
|
|
102
|
+
const rad = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
|
|
103
|
+
left: radOffset - rad * half,
|
|
104
|
+
right: radOffset + rad * half,
|
|
103
105
|
};
|
|
104
106
|
if (!moveOptions.straight) {
|
|
105
107
|
res.angle += (0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(range.left, range.right));
|
|
@@ -109,7 +111,7 @@
|
|
|
109
111
|
}
|
|
110
112
|
return res;
|
|
111
113
|
};
|
|
112
|
-
this._checkOverlap = (pos, tryCount =
|
|
114
|
+
this._checkOverlap = (pos, tryCount = defaultRetryCount) => {
|
|
113
115
|
const collisionsOptions = this.options.collisions, radius = this.getRadius();
|
|
114
116
|
if (!collisionsOptions.enable) {
|
|
115
117
|
return false;
|
|
@@ -118,8 +120,8 @@
|
|
|
118
120
|
if (overlapOptions.enable) {
|
|
119
121
|
return false;
|
|
120
122
|
}
|
|
121
|
-
const retries = overlapOptions.retries;
|
|
122
|
-
if (retries >=
|
|
123
|
+
const retries = overlapOptions.retries, minRetries = 0;
|
|
124
|
+
if (retries >= minRetries && tryCount > retries) {
|
|
123
125
|
throw new Error(`${Constants_js_1.errorPrefix} particle is overlapping and can't be placed`);
|
|
124
126
|
}
|
|
125
127
|
return !!this.container.particles.find((particle) => (0, NumberUtils_js_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
|
|
@@ -128,7 +130,7 @@
|
|
|
128
130
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
129
131
|
return color;
|
|
130
132
|
}
|
|
131
|
-
const backFactor = this.roll.horizontal && this.roll.vertical ?
|
|
133
|
+
const rollFactor = 1, none = 0, backFactor = this.roll.horizontal && this.roll.vertical ? double * rollFactor : rollFactor, backSum = this.roll.horizontal ? Math.PI * half : none, rolled = Math.floor(((this.roll.angle ?? none) + backSum) / (Math.PI / backFactor)) % double;
|
|
132
134
|
if (!rolled) {
|
|
133
135
|
return color;
|
|
134
136
|
}
|
|
@@ -141,13 +143,13 @@
|
|
|
141
143
|
return color;
|
|
142
144
|
};
|
|
143
145
|
this._initPosition = (position) => {
|
|
144
|
-
const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value);
|
|
145
|
-
this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue,
|
|
146
|
+
const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value), minZ = 0;
|
|
147
|
+
this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, minZ, container.zLayers));
|
|
146
148
|
this.initialPosition = this.position.copy();
|
|
147
|
-
const canvasSize = container.canvas.size;
|
|
149
|
+
const canvasSize = container.canvas.size, defaultRadius = 0;
|
|
148
150
|
this.moveCenter = {
|
|
149
151
|
...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
|
|
150
|
-
radius: this.options.move.center.radius ??
|
|
152
|
+
radius: this.options.move.center.radius ?? defaultRadius,
|
|
151
153
|
mode: this.options.move.center.mode ?? "percent",
|
|
152
154
|
};
|
|
153
155
|
this.direction = (0, NumberUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
|
|
@@ -162,7 +164,6 @@
|
|
|
162
164
|
this.offset = Vector_js_1.Vector.origin;
|
|
163
165
|
};
|
|
164
166
|
this._engine = engine;
|
|
165
|
-
this.init(id, position, overrideOptions, group);
|
|
166
167
|
}
|
|
167
168
|
destroy(override) {
|
|
168
169
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -172,14 +173,14 @@
|
|
|
172
173
|
this.bubble.inRange = false;
|
|
173
174
|
this.slow.inRange = false;
|
|
174
175
|
const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
175
|
-
shapeDrawer
|
|
176
|
+
shapeDrawer?.particleDestroy?.(this);
|
|
176
177
|
for (const [, plugin] of container.plugins) {
|
|
177
|
-
plugin.particleDestroyed
|
|
178
|
+
plugin.particleDestroyed?.(this, override);
|
|
178
179
|
}
|
|
179
180
|
for (const updater of container.particles.updaters) {
|
|
180
|
-
updater.particleDestroyed
|
|
181
|
+
updater.particleDestroyed?.(this, override);
|
|
181
182
|
}
|
|
182
|
-
pathGenerator
|
|
183
|
+
pathGenerator?.reset(this);
|
|
183
184
|
this._engine.dispatchEvent("particleDestroyed", {
|
|
184
185
|
container: this.container,
|
|
185
186
|
data: {
|
|
@@ -187,18 +188,18 @@
|
|
|
187
188
|
},
|
|
188
189
|
});
|
|
189
190
|
}
|
|
190
|
-
draw(delta) {
|
|
191
|
+
async draw(delta) {
|
|
191
192
|
const container = this.container, canvas = container.canvas;
|
|
192
193
|
for (const [, plugin] of container.plugins) {
|
|
193
|
-
canvas.drawParticlePlugin(plugin, this, delta);
|
|
194
|
+
await canvas.drawParticlePlugin(plugin, this, delta);
|
|
194
195
|
}
|
|
195
|
-
canvas.drawParticle(this, delta);
|
|
196
|
+
await canvas.drawParticle(this, delta);
|
|
196
197
|
}
|
|
197
198
|
getFillColor() {
|
|
198
199
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
|
|
199
200
|
}
|
|
200
201
|
getMass() {
|
|
201
|
-
return this.getRadius() **
|
|
202
|
+
return this.getRadius() ** squareExp * Math.PI * half;
|
|
202
203
|
}
|
|
203
204
|
getPosition() {
|
|
204
205
|
return {
|
|
@@ -213,7 +214,7 @@
|
|
|
213
214
|
getStrokeColor() {
|
|
214
215
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.strokeColor));
|
|
215
216
|
}
|
|
216
|
-
init(id, position, overrideOptions, group) {
|
|
217
|
+
async init(id, position, overrideOptions, group) {
|
|
217
218
|
const container = this.container, engine = this._engine;
|
|
218
219
|
this.id = id;
|
|
219
220
|
this.group = group;
|
|
@@ -237,14 +238,14 @@
|
|
|
237
238
|
this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
|
|
238
239
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
239
240
|
if (overrideOptions) {
|
|
240
|
-
if (overrideOptions.effect
|
|
241
|
+
if (overrideOptions.effect?.type) {
|
|
241
242
|
const overrideEffectType = overrideOptions.effect.type, effect = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);
|
|
242
243
|
if (effect) {
|
|
243
244
|
this.effect = effect;
|
|
244
245
|
effectOptions.load(overrideOptions.effect);
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
|
-
if (overrideOptions.shape
|
|
248
|
+
if (overrideOptions.shape?.type) {
|
|
248
249
|
const overrideShapeType = overrideOptions.shape.type, shape = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);
|
|
249
250
|
if (shape) {
|
|
250
251
|
this.shape = shape;
|
|
@@ -273,11 +274,11 @@
|
|
|
273
274
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
274
275
|
this.options = particlesOptions;
|
|
275
276
|
const pathOptions = this.options.move.path;
|
|
276
|
-
this.pathDelay = (0, NumberUtils_js_1.getRangeValue)(pathOptions.delay.value) *
|
|
277
|
+
this.pathDelay = (0, NumberUtils_js_1.getRangeValue)(pathOptions.delay.value) * Constants_js_1.millisecondsToSeconds;
|
|
277
278
|
if (pathOptions.generator) {
|
|
278
279
|
this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);
|
|
279
280
|
if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
|
|
280
|
-
this.pathGenerator.init(container);
|
|
281
|
+
await this.pathGenerator.init(container);
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
container.retina.initParticle(this);
|
|
@@ -292,7 +293,8 @@
|
|
|
292
293
|
this._initPosition(position);
|
|
293
294
|
this.initialVelocity = this._calculateVelocity();
|
|
294
295
|
this.velocity = this.initialVelocity.copy();
|
|
295
|
-
|
|
296
|
+
const decayOffset = 1;
|
|
297
|
+
this.moveDecay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
|
|
296
298
|
const particles = container.particles;
|
|
297
299
|
particles.setLastZIndex(this.position.z);
|
|
298
300
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
@@ -304,8 +306,8 @@
|
|
|
304
306
|
container.effectDrawers.set(this.effect, effectDrawer);
|
|
305
307
|
}
|
|
306
308
|
}
|
|
307
|
-
if (effectDrawer
|
|
308
|
-
effectDrawer.loadEffect(this);
|
|
309
|
+
if (effectDrawer?.loadEffect) {
|
|
310
|
+
await effectDrawer.loadEffect(this);
|
|
309
311
|
}
|
|
310
312
|
let shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
311
313
|
if (!shapeDrawer) {
|
|
@@ -314,8 +316,8 @@
|
|
|
314
316
|
container.shapeDrawers.set(this.shape, shapeDrawer);
|
|
315
317
|
}
|
|
316
318
|
}
|
|
317
|
-
if (shapeDrawer
|
|
318
|
-
shapeDrawer.loadShape(this);
|
|
319
|
+
if (shapeDrawer?.loadShape) {
|
|
320
|
+
await shapeDrawer.loadShape(this);
|
|
319
321
|
}
|
|
320
322
|
const sideCountFunc = shapeDrawer?.getSidesCount;
|
|
321
323
|
if (sideCountFunc) {
|
|
@@ -324,19 +326,15 @@
|
|
|
324
326
|
this.spawning = false;
|
|
325
327
|
this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this.options.shadow.color);
|
|
326
328
|
for (const updater of particles.updaters) {
|
|
327
|
-
updater.init(this);
|
|
329
|
+
await updater.init(this);
|
|
328
330
|
}
|
|
329
331
|
for (const mover of particles.movers) {
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
if (effectDrawer && effectDrawer.particleInit) {
|
|
333
|
-
effectDrawer.particleInit(container, this);
|
|
334
|
-
}
|
|
335
|
-
if (shapeDrawer && shapeDrawer.particleInit) {
|
|
336
|
-
shapeDrawer.particleInit(container, this);
|
|
332
|
+
await mover.init?.(this);
|
|
337
333
|
}
|
|
334
|
+
await effectDrawer?.particleInit?.(container, this);
|
|
335
|
+
await shapeDrawer?.particleInit?.(container, this);
|
|
338
336
|
for (const [, plugin] of container.plugins) {
|
|
339
|
-
plugin.particleCreated
|
|
337
|
+
plugin.particleCreated?.(this);
|
|
340
338
|
}
|
|
341
339
|
}
|
|
342
340
|
isInsideCanvas() {
|
|
@@ -351,7 +349,7 @@
|
|
|
351
349
|
}
|
|
352
350
|
reset() {
|
|
353
351
|
for (const updater of this.container.particles.updaters) {
|
|
354
|
-
updater.reset
|
|
352
|
+
updater.reset?.(this);
|
|
355
353
|
}
|
|
356
354
|
}
|
|
357
355
|
}
|