@tsparticles/engine 4.0.0-beta.0 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/155.min.js +1 -0
- package/README.md +0 -21
- package/browser/Core/CanvasManager.js +303 -0
- package/browser/Core/Container.js +61 -34
- package/browser/Core/Engine.js +26 -138
- package/browser/Core/Particle.js +29 -28
- package/{cjs/Core/Particles.js → browser/Core/ParticlesManager.js} +27 -57
- package/browser/Core/RenderManager.js +303 -0
- package/browser/Core/Retina.js +3 -8
- package/browser/Core/Utils/PluginManager.js +145 -0
- package/browser/Options/Classes/Options.js +7 -7
- package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/browser/Types/CanvasContextType.js +1 -0
- package/browser/Utils/CanvasUtils.js +1 -1
- package/browser/Utils/ColorUtils.js +21 -21
- package/browser/Utils/LogUtils.js +1 -0
- package/browser/Utils/OptionsUtils.js +2 -2
- package/cjs/Core/CanvasManager.js +303 -0
- package/cjs/Core/Container.js +61 -34
- package/cjs/Core/Engine.js +26 -138
- package/cjs/Core/Particle.js +29 -28
- package/{esm/Core/Particles.js → cjs/Core/ParticlesManager.js} +27 -57
- package/cjs/Core/RenderManager.js +303 -0
- package/cjs/Core/Retina.js +3 -8
- package/cjs/Core/Utils/PluginManager.js +145 -0
- package/cjs/Options/Classes/Options.js +7 -7
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/cjs/Types/CanvasContextType.js +1 -0
- package/cjs/Utils/CanvasUtils.js +1 -1
- package/cjs/Utils/ColorUtils.js +21 -21
- package/cjs/Utils/LogUtils.js +1 -0
- package/cjs/Utils/OptionsUtils.js +2 -2
- package/dist_browser_Core_Container_js.js +24 -14
- package/esm/Core/CanvasManager.js +303 -0
- package/esm/Core/Container.js +61 -34
- package/esm/Core/Engine.js +26 -138
- package/esm/Core/Particle.js +29 -28
- package/{browser/Core/Particles.js → esm/Core/ParticlesManager.js} +27 -57
- package/esm/Core/RenderManager.js +303 -0
- package/esm/Core/Retina.js +3 -8
- package/esm/Core/Utils/PluginManager.js +145 -0
- package/esm/Options/Classes/Options.js +7 -7
- package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/esm/Types/CanvasContextType.js +1 -0
- package/esm/Utils/CanvasUtils.js +1 -1
- package/esm/Utils/ColorUtils.js +21 -21
- package/esm/Utils/LogUtils.js +1 -0
- package/esm/Utils/OptionsUtils.js +2 -2
- package/package.json +1 -1
- package/report.html +84 -29
- package/tsparticles.engine.js +18 -8
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/CanvasManager.d.ts +39 -0
- package/types/Core/Container.d.ts +26 -7
- package/types/Core/Engine.d.ts +2 -54
- package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -7
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
- package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -1
- package/types/Core/Particle.d.ts +4 -4
- package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +4 -11
- package/types/Core/{Canvas.d.ts → RenderManager.d.ts} +12 -33
- package/types/Core/Retina.d.ts +0 -2
- package/types/Core/Utils/PluginManager.d.ts +62 -0
- package/types/Options/Classes/Options.d.ts +3 -3
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +3 -3
- package/types/Types/CanvasContextType.d.ts +1 -0
- package/types/Utils/CanvasUtils.d.ts +8 -5
- package/types/Utils/ColorUtils.d.ts +8 -8
- package/types/Utils/LogUtils.d.ts +1 -0
- package/types/Utils/OptionsUtils.d.ts +2 -2
- package/types/export-types.d.ts +4 -2
- package/umd/Core/CanvasManager.js +317 -0
- package/umd/Core/Container.js +61 -34
- package/umd/Core/Engine.js +25 -137
- package/umd/Core/Particle.js +29 -28
- package/umd/Core/{Particles.js → ParticlesManager.js} +29 -59
- package/umd/Core/RenderManager.js +317 -0
- package/umd/Core/Retina.js +3 -8
- package/umd/Core/Utils/PluginManager.js +159 -0
- package/umd/Options/Classes/Options.js +7 -7
- package/umd/Options/Classes/Particles/ParticlesOptions.js +5 -5
- package/umd/Types/CanvasContextType.js +12 -0
- package/umd/Utils/CanvasUtils.js +1 -1
- package/umd/Utils/ColorUtils.js +21 -21
- package/umd/Utils/LogUtils.js +1 -0
- package/umd/Utils/OptionsUtils.js +2 -2
- package/164.min.js +0 -1
- package/browser/Core/Canvas.js +0 -570
- package/cjs/Core/Canvas.js +0 -570
- package/esm/Core/Canvas.js +0 -570
- package/umd/Core/Canvas.js +0 -584
package/umd/Core/Engine.js
CHANGED
|
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
if (v !== undefined) module.exports = v;
|
|
38
38
|
}
|
|
39
39
|
else if (typeof define === "function" && define.amd) {
|
|
40
|
-
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/EventDispatcher.js", "
|
|
40
|
+
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/EventDispatcher.js", "./Utils/PluginManager.js", "../Utils/LogUtils.js", "../Utils/MathUtils.js"], factory);
|
|
41
41
|
}
|
|
42
42
|
})(function (require, exports) {
|
|
43
43
|
"use strict";
|
|
@@ -47,7 +47,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
47
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
48
48
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
49
49
|
const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
|
|
50
|
-
const
|
|
50
|
+
const PluginManager_js_1 = require("./Utils/PluginManager.js");
|
|
51
51
|
const LogUtils_js_1 = require("../Utils/LogUtils.js");
|
|
52
52
|
const MathUtils_js_1 = require("../Utils/MathUtils.js");
|
|
53
53
|
const fullPercent = "100%";
|
|
@@ -91,142 +91,41 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
91
91
|
if (domContainer) {
|
|
92
92
|
return domContainer;
|
|
93
93
|
}
|
|
94
|
-
domContainer = documentSafe.createElement("
|
|
94
|
+
domContainer = documentSafe.createElement("canvas");
|
|
95
95
|
domContainer.id = id;
|
|
96
96
|
domContainer.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
|
|
97
97
|
documentSafe.body.append(domContainer);
|
|
98
98
|
return domContainer;
|
|
99
99
|
};
|
|
100
100
|
class Engine {
|
|
101
|
-
|
|
102
|
-
easingFunctions = new Map();
|
|
103
|
-
effectDrawers = new Map();
|
|
104
|
-
initializers = {
|
|
105
|
-
effects: new Map(),
|
|
106
|
-
shapes: new Map(),
|
|
107
|
-
updaters: new Map(),
|
|
108
|
-
};
|
|
109
|
-
palettes = new Map();
|
|
110
|
-
plugins = [];
|
|
111
|
-
presets = new Map();
|
|
112
|
-
shapeDrawers = new Map();
|
|
113
|
-
updaters = new Map();
|
|
114
|
-
_allLoadersSet = new Set();
|
|
115
|
-
_configs = new Map();
|
|
101
|
+
pluginManager = new PluginManager_js_1.PluginManager(this);
|
|
116
102
|
_domArray = [];
|
|
117
103
|
_eventDispatcher = new EventDispatcher_js_1.EventDispatcher();
|
|
118
|
-
_executedSet = new Set();
|
|
119
104
|
_initialized = false;
|
|
120
|
-
_isRunningLoaders = false;
|
|
121
|
-
_loadPromises = new Set();
|
|
122
|
-
get configs() {
|
|
123
|
-
const res = {};
|
|
124
|
-
for (const [name, config] of this._configs) {
|
|
125
|
-
res[name] = config;
|
|
126
|
-
}
|
|
127
|
-
return res;
|
|
128
|
-
}
|
|
129
105
|
get items() {
|
|
130
106
|
return this._domArray;
|
|
131
107
|
}
|
|
132
108
|
get version() {
|
|
133
|
-
return "4.0.0-beta.
|
|
134
|
-
}
|
|
135
|
-
addColorManager(name, manager) {
|
|
136
|
-
this.colorManagers.set(name, manager);
|
|
137
|
-
}
|
|
138
|
-
addConfig(config) {
|
|
139
|
-
const key = config.key ?? config.name ?? "default";
|
|
140
|
-
this._configs.set(key, config);
|
|
141
|
-
this._eventDispatcher.dispatchEvent(EventType_js_1.EventType.configAdded, { data: { name: key, config } });
|
|
142
|
-
}
|
|
143
|
-
addEasing(name, easing) {
|
|
144
|
-
if (this.easingFunctions.get(name)) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
this.easingFunctions.set(name, easing);
|
|
148
|
-
}
|
|
149
|
-
addEffect(effect, drawer) {
|
|
150
|
-
this.initializers.effects.set(effect, drawer);
|
|
109
|
+
return "4.0.0-beta.1";
|
|
151
110
|
}
|
|
152
111
|
addEventListener(type, listener) {
|
|
153
112
|
this._eventDispatcher.addEventListener(type, listener);
|
|
154
113
|
}
|
|
155
|
-
addPalette(name, palette) {
|
|
156
|
-
this.palettes.set(name, palette);
|
|
157
|
-
}
|
|
158
|
-
addParticleUpdater(name, updaterInitializer) {
|
|
159
|
-
this.initializers.updaters.set(name, updaterInitializer);
|
|
160
|
-
}
|
|
161
|
-
addPlugin(plugin) {
|
|
162
|
-
if (this.getPlugin(plugin.id)) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
this.plugins.push(plugin);
|
|
166
|
-
}
|
|
167
|
-
addPreset(preset, options, override = false) {
|
|
168
|
-
if (!(override || !this.getPreset(preset))) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
this.presets.set(preset, options);
|
|
172
|
-
}
|
|
173
|
-
addShape(shapes, drawer) {
|
|
174
|
-
for (const shape of shapes) {
|
|
175
|
-
this.initializers.shapes.set(shape, drawer);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
114
|
checkVersion(pluginVersion) {
|
|
179
115
|
if (this.version === pluginVersion) {
|
|
180
116
|
return;
|
|
181
117
|
}
|
|
182
118
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
183
119
|
}
|
|
184
|
-
clearPlugins(container) {
|
|
185
|
-
this.effectDrawers.delete(container);
|
|
186
|
-
this.shapeDrawers.delete(container);
|
|
187
|
-
this.updaters.delete(container);
|
|
188
|
-
}
|
|
189
120
|
dispatchEvent(type, args) {
|
|
190
121
|
this._eventDispatcher.dispatchEvent(type, args);
|
|
191
122
|
}
|
|
192
|
-
getEasing(name) {
|
|
193
|
-
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
194
|
-
}
|
|
195
|
-
getEffectDrawers(container, force = false) {
|
|
196
|
-
return (0, Utils_js_1.getItemMapFromInitializer)(container, this.effectDrawers, this.initializers.effects, force);
|
|
197
|
-
}
|
|
198
|
-
getPalette(name) {
|
|
199
|
-
return this.palettes.get(name);
|
|
200
|
-
}
|
|
201
|
-
getPlugin(plugin) {
|
|
202
|
-
return this.plugins.find(t => t.id === plugin);
|
|
203
|
-
}
|
|
204
|
-
getPreset(preset) {
|
|
205
|
-
return this.presets.get(preset);
|
|
206
|
-
}
|
|
207
|
-
async getShapeDrawers(container, force = false) {
|
|
208
|
-
return (0, Utils_js_1.getItemMapFromInitializer)(container, this.shapeDrawers, this.initializers.shapes, force);
|
|
209
|
-
}
|
|
210
|
-
async getUpdaters(container, force = false) {
|
|
211
|
-
return (0, Utils_js_1.getItemsFromInitializer)(container, this.updaters, this.initializers.updaters, force);
|
|
212
|
-
}
|
|
213
123
|
async init() {
|
|
214
|
-
if (this._initialized
|
|
124
|
+
if (this._initialized) {
|
|
215
125
|
return;
|
|
216
126
|
}
|
|
217
|
-
this.
|
|
218
|
-
this.
|
|
219
|
-
this._allLoadersSet = new Set(this._loadPromises);
|
|
220
|
-
try {
|
|
221
|
-
for (const loader of this._allLoadersSet) {
|
|
222
|
-
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
finally {
|
|
226
|
-
this._loadPromises.clear();
|
|
227
|
-
this._isRunningLoaders = false;
|
|
228
|
-
this._initialized = true;
|
|
229
|
-
}
|
|
127
|
+
await this.pluginManager.init();
|
|
128
|
+
this._initialized = true;
|
|
230
129
|
}
|
|
231
130
|
item(index) {
|
|
232
131
|
const { items } = this, item = items[index];
|
|
@@ -238,7 +137,23 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
238
137
|
}
|
|
239
138
|
async load(params) {
|
|
240
139
|
await this.init();
|
|
241
|
-
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)), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, MathUtils_js_1.getRandom)() * Constants_js_1.loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(
|
|
140
|
+
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)), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, MathUtils_js_1.getRandom)() * Constants_js_1.loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
|
|
141
|
+
dispatchCallback: (eventType, args) => {
|
|
142
|
+
this.dispatchEvent(eventType, args);
|
|
143
|
+
},
|
|
144
|
+
id,
|
|
145
|
+
onDestroy: (remove) => {
|
|
146
|
+
if (!remove) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const mainArr = this.items, idx = mainArr.indexOf(newItem);
|
|
150
|
+
if (idx >= Constants_js_1.removeMinIndex) {
|
|
151
|
+
mainArr.splice(idx, Constants_js_1.removeDeleteCount);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
pluginManager: this.pluginManager,
|
|
155
|
+
sourceOptions: currentOptions,
|
|
156
|
+
});
|
|
242
157
|
if (oldIndex >= Constants_js_1.loadMinIndex) {
|
|
243
158
|
const old = this.item(oldIndex), deleteCount = old ? Constants_js_1.one : Constants_js_1.none;
|
|
244
159
|
if (old && !old.destroyed) {
|
|
@@ -254,42 +169,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
254
169
|
await newItem.start();
|
|
255
170
|
return newItem;
|
|
256
171
|
}
|
|
257
|
-
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
258
|
-
const updaters = this.updaters.get(container);
|
|
259
|
-
if (!updaters) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
263
|
-
}
|
|
264
172
|
async refresh(refresh = true) {
|
|
265
173
|
if (!refresh) {
|
|
266
174
|
return;
|
|
267
175
|
}
|
|
268
176
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
269
177
|
}
|
|
270
|
-
async register(...loaders) {
|
|
271
|
-
if (this._initialized) {
|
|
272
|
-
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
273
|
-
}
|
|
274
|
-
for (const loader of loaders) {
|
|
275
|
-
if (this._isRunningLoaders) {
|
|
276
|
-
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
this._loadPromises.add(loader);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
178
|
removeEventListener(type, listener) {
|
|
284
179
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
285
180
|
}
|
|
286
|
-
async _runLoader(loader, executed, allLoaders) {
|
|
287
|
-
if (executed.has(loader))
|
|
288
|
-
return;
|
|
289
|
-
executed.add(loader);
|
|
290
|
-
allLoaders.add(loader);
|
|
291
|
-
await loader(this);
|
|
292
|
-
}
|
|
293
181
|
}
|
|
294
182
|
exports.Engine = Engine;
|
|
295
183
|
});
|
package/umd/Core/Particle.js
CHANGED
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
class Particle {
|
|
48
|
-
container;
|
|
49
48
|
backColor;
|
|
50
49
|
bubble;
|
|
51
50
|
destroyed;
|
|
@@ -101,10 +100,11 @@
|
|
|
101
100
|
c: 0,
|
|
102
101
|
d: 1,
|
|
103
102
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
103
|
+
_container;
|
|
104
|
+
_pluginManager;
|
|
105
|
+
constructor(pluginManager, container) {
|
|
106
|
+
this._pluginManager = pluginManager;
|
|
107
|
+
this._container = container;
|
|
108
108
|
}
|
|
109
109
|
destroy(override) {
|
|
110
110
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -113,25 +113,22 @@
|
|
|
113
113
|
this.destroyed = true;
|
|
114
114
|
this.bubble.inRange = false;
|
|
115
115
|
this.slow.inRange = false;
|
|
116
|
-
const container = this.
|
|
116
|
+
const container = this._container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
117
117
|
shapeDrawer?.particleDestroy?.(this);
|
|
118
118
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
119
119
|
plugin.particleDestroyed?.(this, override);
|
|
120
120
|
}
|
|
121
|
-
for (const updater of container.
|
|
121
|
+
for (const updater of container.particleUpdaters) {
|
|
122
122
|
updater.particleDestroyed?.(this, override);
|
|
123
123
|
}
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
data: {
|
|
127
|
-
particle: this,
|
|
128
|
-
},
|
|
124
|
+
this._container.dispatchEvent(EventType_js_1.EventType.particleDestroyed, {
|
|
125
|
+
particle: this,
|
|
129
126
|
});
|
|
130
127
|
}
|
|
131
128
|
draw(delta) {
|
|
132
|
-
const container = this.
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
const container = this._container, render = container.canvas.render;
|
|
130
|
+
render.drawParticlePlugins(this, delta);
|
|
131
|
+
render.drawParticle(this, delta);
|
|
135
132
|
}
|
|
136
133
|
getAngle() {
|
|
137
134
|
return this.rotation + (this.pathRotation ? this.velocity.angle : Constants_js_1.defaultAngle);
|
|
@@ -180,7 +177,7 @@
|
|
|
180
177
|
return this._cachedTransform;
|
|
181
178
|
}
|
|
182
179
|
init(id, position, overrideOptions, group) {
|
|
183
|
-
const container = this.
|
|
180
|
+
const container = this._container;
|
|
184
181
|
this.id = id;
|
|
185
182
|
this.group = group;
|
|
186
183
|
this.effectClose = true;
|
|
@@ -194,10 +191,14 @@
|
|
|
194
191
|
this.misplaced = false;
|
|
195
192
|
this.retina = {
|
|
196
193
|
maxDistance: {},
|
|
194
|
+
maxSpeed: 0,
|
|
195
|
+
moveDrift: 0,
|
|
196
|
+
moveSpeed: 0,
|
|
197
|
+
sizeAnimationSpeed: 0,
|
|
197
198
|
};
|
|
198
199
|
this.outType = ParticleOutType_js_1.ParticleOutType.normal;
|
|
199
200
|
this.ignoresResizeRatio = true;
|
|
200
|
-
const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this.
|
|
201
|
+
const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
201
202
|
this.effect = (0, Utils_js_1.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);
|
|
202
203
|
this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
|
|
203
204
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
@@ -218,11 +219,11 @@
|
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
if (this.effect === Constants_js_1.randomColorValue) {
|
|
221
|
-
const availableEffects = [...this.
|
|
222
|
+
const availableEffects = [...this._container.effectDrawers.keys()];
|
|
222
223
|
this.effect = availableEffects[Math.floor((0, MathUtils_js_1.getRandom)() * availableEffects.length)];
|
|
223
224
|
}
|
|
224
225
|
if (this.shape === Constants_js_1.randomColorValue) {
|
|
225
|
-
const availableShapes = [...this.
|
|
226
|
+
const availableShapes = [...this._container.shapeDrawers.keys()];
|
|
226
227
|
this.shape = availableShapes[Math.floor((0, MathUtils_js_1.getRandom)() * availableShapes.length)];
|
|
227
228
|
}
|
|
228
229
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
@@ -257,13 +258,13 @@
|
|
|
257
258
|
this.sides = 24;
|
|
258
259
|
let effectDrawer, shapeDrawer;
|
|
259
260
|
if (this.effect) {
|
|
260
|
-
effectDrawer = container.
|
|
261
|
+
effectDrawer = container.effectDrawers.get(this.effect);
|
|
261
262
|
}
|
|
262
263
|
if (effectDrawer?.loadEffect) {
|
|
263
264
|
effectDrawer.loadEffect(this);
|
|
264
265
|
}
|
|
265
266
|
if (this.shape) {
|
|
266
|
-
shapeDrawer = container.
|
|
267
|
+
shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
267
268
|
}
|
|
268
269
|
if (shapeDrawer?.loadShape) {
|
|
269
270
|
shapeDrawer.loadShape(this);
|
|
@@ -273,7 +274,7 @@
|
|
|
273
274
|
this.sides = sideCountFunc(this);
|
|
274
275
|
}
|
|
275
276
|
this.spawning = false;
|
|
276
|
-
for (const updater of
|
|
277
|
+
for (const updater of container.particleUpdaters) {
|
|
277
278
|
updater.init(this);
|
|
278
279
|
}
|
|
279
280
|
effectDrawer?.particleInit?.(container, this);
|
|
@@ -283,7 +284,7 @@
|
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
286
|
isInsideCanvas() {
|
|
286
|
-
const radius = this.getRadius(), canvasSize = this.
|
|
287
|
+
const radius = this.getRadius(), canvasSize = this._container.canvas.size, position = this.position;
|
|
287
288
|
return (position.x >= -radius &&
|
|
288
289
|
position.y >= -radius &&
|
|
289
290
|
position.y <= canvasSize.height + radius &&
|
|
@@ -312,13 +313,13 @@
|
|
|
312
313
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
313
314
|
}
|
|
314
315
|
reset() {
|
|
315
|
-
for (const updater of this.
|
|
316
|
+
for (const updater of this._container.particleUpdaters) {
|
|
316
317
|
updater.reset?.(this);
|
|
317
318
|
}
|
|
318
319
|
}
|
|
319
320
|
_calcPosition = (position, zIndex) => {
|
|
320
321
|
let tryCount = Constants_js_1.defaultRetryCount, posVec = position ? Vectors_js_1.Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
321
|
-
const container = this.
|
|
322
|
+
const container = this._container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
322
323
|
while (!signal.aborted) {
|
|
323
324
|
for (const plugin of plugins) {
|
|
324
325
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -371,7 +372,7 @@
|
|
|
371
372
|
outMode,
|
|
372
373
|
checkModes: [OutMode_js_1.OutMode.bounce],
|
|
373
374
|
coord: pos.x,
|
|
374
|
-
maxCoord: this.
|
|
375
|
+
maxCoord: this._container.canvas.size.width,
|
|
375
376
|
setCb: (value) => (pos.x += value),
|
|
376
377
|
radius,
|
|
377
378
|
});
|
|
@@ -381,7 +382,7 @@
|
|
|
381
382
|
outMode,
|
|
382
383
|
checkModes: [OutMode_js_1.OutMode.bounce],
|
|
383
384
|
coord: pos.y,
|
|
384
|
-
maxCoord: this.
|
|
385
|
+
maxCoord: this._container.canvas.size.height,
|
|
385
386
|
setCb: (value) => (pos.y += value),
|
|
386
387
|
radius,
|
|
387
388
|
});
|
|
@@ -402,7 +403,7 @@
|
|
|
402
403
|
return color;
|
|
403
404
|
};
|
|
404
405
|
_initPosition = position => {
|
|
405
|
-
const container = this.
|
|
406
|
+
const container = this._container, zIndexValue = (0, MathUtils_js_1.getRangeValue)(this.options.zIndex.value), initialPosition = this._calcPosition(position, (0, MathUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
|
|
406
407
|
if (!initialPosition) {
|
|
407
408
|
throw new Error("a valid position cannot be found for particle");
|
|
408
409
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.ParticlesManager = void 0;
|
|
13
13
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
14
14
|
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
15
15
|
const LimitMode_js_1 = require("../Enums/Modes/LimitMode.js");
|
|
@@ -17,15 +17,11 @@
|
|
|
17
17
|
const SpatialHashGrid_js_1 = require("./Utils/SpatialHashGrid.js");
|
|
18
18
|
const LogUtils_js_1 = require("../Utils/LogUtils.js");
|
|
19
19
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
20
|
-
class
|
|
20
|
+
class ParticlesManager {
|
|
21
21
|
checkParticlePositionPlugins;
|
|
22
|
-
effectDrawers;
|
|
23
22
|
grid;
|
|
24
|
-
shapeDrawers;
|
|
25
|
-
updaters;
|
|
26
23
|
_array;
|
|
27
24
|
_container;
|
|
28
|
-
_engine;
|
|
29
25
|
_groupLimits;
|
|
30
26
|
_limit;
|
|
31
27
|
_maxZIndex;
|
|
@@ -34,14 +30,15 @@
|
|
|
34
30
|
_nextId;
|
|
35
31
|
_particleResetPlugins;
|
|
36
32
|
_particleUpdatePlugins;
|
|
33
|
+
_pluginManager;
|
|
37
34
|
_pool;
|
|
38
35
|
_postParticleUpdatePlugins;
|
|
39
36
|
_postUpdatePlugins;
|
|
40
37
|
_resizeFactor;
|
|
41
38
|
_updatePlugins;
|
|
42
39
|
_zArray;
|
|
43
|
-
constructor(
|
|
44
|
-
this.
|
|
40
|
+
constructor(pluginManager, container) {
|
|
41
|
+
this._pluginManager = pluginManager;
|
|
45
42
|
this._container = container;
|
|
46
43
|
this._nextId = 0;
|
|
47
44
|
this._array = [];
|
|
@@ -53,9 +50,6 @@
|
|
|
53
50
|
this._minZIndex = 0;
|
|
54
51
|
this._maxZIndex = 0;
|
|
55
52
|
this.grid = new SpatialHashGrid_js_1.SpatialHashGrid(Constants_js_1.spatialHashGridCellSize);
|
|
56
|
-
this.effectDrawers = new Map();
|
|
57
|
-
this.shapeDrawers = new Map();
|
|
58
|
-
this.updaters = [];
|
|
59
53
|
this.checkParticlePositionPlugins = [];
|
|
60
54
|
this._particleResetPlugins = [];
|
|
61
55
|
this._particleUpdatePlugins = [];
|
|
@@ -87,7 +81,7 @@
|
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
83
|
try {
|
|
90
|
-
const particle = this._pool.pop() ?? new Particle_js_1.Particle(this.
|
|
84
|
+
const particle = this._pool.pop() ?? new Particle_js_1.Particle(this._pluginManager, this._container);
|
|
91
85
|
particle.init(this._nextId, position, overrideOptions, group);
|
|
92
86
|
let canAdd = true;
|
|
93
87
|
if (initializer) {
|
|
@@ -100,11 +94,8 @@
|
|
|
100
94
|
this._array.push(particle);
|
|
101
95
|
this._zArray.push(particle);
|
|
102
96
|
this._nextId++;
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
data: {
|
|
106
|
-
particle,
|
|
107
|
-
},
|
|
97
|
+
this._container.dispatchEvent(EventType_js_1.EventType.particleAdded, {
|
|
98
|
+
particle,
|
|
108
99
|
});
|
|
109
100
|
return particle;
|
|
110
101
|
}
|
|
@@ -118,19 +109,9 @@
|
|
|
118
109
|
this._zArray = [];
|
|
119
110
|
}
|
|
120
111
|
destroy() {
|
|
121
|
-
const container = this._container;
|
|
122
|
-
for (const [, effectDrawer] of this.effectDrawers) {
|
|
123
|
-
effectDrawer.destroy?.(container);
|
|
124
|
-
}
|
|
125
|
-
for (const [, shapeDrawer] of this.shapeDrawers) {
|
|
126
|
-
shapeDrawer.destroy?.(container);
|
|
127
|
-
}
|
|
128
112
|
this._array = [];
|
|
129
113
|
this._pool.length = 0;
|
|
130
114
|
this._zArray = [];
|
|
131
|
-
this.effectDrawers = new Map();
|
|
132
|
-
this.shapeDrawers = new Map();
|
|
133
|
-
this.updaters = [];
|
|
134
115
|
this.checkParticlePositionPlugins = [];
|
|
135
116
|
this._particleResetPlugins = [];
|
|
136
117
|
this._particleUpdatePlugins = [];
|
|
@@ -187,11 +168,11 @@
|
|
|
187
168
|
this._postParticleUpdatePlugins.push(plugin);
|
|
188
169
|
}
|
|
189
170
|
}
|
|
190
|
-
await this.
|
|
191
|
-
for (const drawer of this.effectDrawers.values()) {
|
|
171
|
+
await this._container.initDrawersAndUpdaters();
|
|
172
|
+
for (const drawer of this._container.effectDrawers.values()) {
|
|
192
173
|
await drawer.init?.(container);
|
|
193
174
|
}
|
|
194
|
-
for (const drawer of this.shapeDrawers.values()) {
|
|
175
|
+
for (const drawer of this._container.shapeDrawers.values()) {
|
|
195
176
|
await drawer.init?.(container);
|
|
196
177
|
}
|
|
197
178
|
let handled = false;
|
|
@@ -217,12 +198,6 @@
|
|
|
217
198
|
}
|
|
218
199
|
}
|
|
219
200
|
}
|
|
220
|
-
async initPlugins() {
|
|
221
|
-
const container = this._container;
|
|
222
|
-
this.effectDrawers = await this._engine.getEffectDrawers(container, true);
|
|
223
|
-
this.shapeDrawers = await this._engine.getShapeDrawers(container, true);
|
|
224
|
-
this.updaters = await this._engine.getUpdaters(container, true);
|
|
225
|
-
}
|
|
226
201
|
push(nb, position, overrideOptions, group) {
|
|
227
202
|
for (let i = 0; i < nb; i++) {
|
|
228
203
|
this.addParticle(position, overrideOptions, group);
|
|
@@ -231,7 +206,7 @@
|
|
|
231
206
|
async redraw() {
|
|
232
207
|
this.clear();
|
|
233
208
|
await this.init();
|
|
234
|
-
this._container.canvas.drawParticles({ value: 0, factor: 0 });
|
|
209
|
+
this._container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
235
210
|
}
|
|
236
211
|
remove(particle, group, override) {
|
|
237
212
|
this.removeAt(this._array.indexOf(particle), undefined, group, override);
|
|
@@ -264,7 +239,7 @@
|
|
|
264
239
|
if (!groupData) {
|
|
265
240
|
continue;
|
|
266
241
|
}
|
|
267
|
-
const groupDataOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this.
|
|
242
|
+
const groupDataOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._pluginManager, this._container, groupData);
|
|
268
243
|
this._applyDensity(groupDataOptions, pluginsCount, group);
|
|
269
244
|
}
|
|
270
245
|
this._applyDensity(options.particles, pluginsCount);
|
|
@@ -305,25 +280,15 @@
|
|
|
305
280
|
}
|
|
306
281
|
this.grid.insert(particle);
|
|
307
282
|
}
|
|
308
|
-
if (particlesToDelete.size) {
|
|
309
|
-
const checkDelete = (p) => !particlesToDelete.has(p);
|
|
310
|
-
this._array = this.filter(checkDelete);
|
|
311
|
-
this._zArray = this._zArray.filter(checkDelete);
|
|
312
|
-
for (const particle of particlesToDelete) {
|
|
313
|
-
this._engine.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
|
|
314
|
-
container: this._container,
|
|
315
|
-
data: {
|
|
316
|
-
particle,
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
this._addToPool(...particlesToDelete);
|
|
321
|
-
}
|
|
322
283
|
for (const plugin of this._postUpdatePlugins) {
|
|
323
284
|
plugin.postUpdate?.(delta);
|
|
324
285
|
}
|
|
325
286
|
for (const particle of this._array) {
|
|
326
|
-
|
|
287
|
+
if (particle.destroyed) {
|
|
288
|
+
particlesToDelete.add(particle);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
for (const updater of this._container.particleUpdaters) {
|
|
327
292
|
updater.update(particle, delta);
|
|
328
293
|
}
|
|
329
294
|
if (!particle.destroyed && !particle.spawning) {
|
|
@@ -331,6 +296,14 @@
|
|
|
331
296
|
plugin.postParticleUpdate?.(particle, delta);
|
|
332
297
|
}
|
|
333
298
|
}
|
|
299
|
+
else if (particle.destroyed) {
|
|
300
|
+
particlesToDelete.add(particle);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (particlesToDelete.size) {
|
|
304
|
+
for (const particle of particlesToDelete) {
|
|
305
|
+
this.remove(particle);
|
|
306
|
+
}
|
|
334
307
|
}
|
|
335
308
|
delete this._resizeFactor;
|
|
336
309
|
if (this._needsSort) {
|
|
@@ -393,15 +366,12 @@
|
|
|
393
366
|
this._array.splice(index, Constants_js_1.deleteCount);
|
|
394
367
|
this._zArray.splice(zIdx, Constants_js_1.deleteCount);
|
|
395
368
|
particle.destroy(override);
|
|
396
|
-
this.
|
|
397
|
-
|
|
398
|
-
data: {
|
|
399
|
-
particle,
|
|
400
|
-
},
|
|
369
|
+
this._container.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
|
|
370
|
+
particle,
|
|
401
371
|
});
|
|
402
372
|
this._addToPool(particle);
|
|
403
373
|
return true;
|
|
404
374
|
};
|
|
405
375
|
}
|
|
406
|
-
exports.
|
|
376
|
+
exports.ParticlesManager = ParticlesManager;
|
|
407
377
|
});
|