@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/Particles.js
CHANGED
|
@@ -1,23 +1,46 @@
|
|
|
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/Utils.js", "./Utils/InteractionManager.js", "./
|
|
30
|
+
define(["require", "exports", "../Utils/Utils.js", "./Utils/InteractionManager.js", "./Utils/Point.js", "./Utils/QuadTree.js", "./Utils/Rectangle.js", "./Utils/Constants.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.Particles = void 0;
|
|
13
37
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
14
38
|
const InteractionManager_js_1 = require("./Utils/InteractionManager.js");
|
|
15
|
-
const Particle_js_1 = require("./Particle.js");
|
|
16
39
|
const Point_js_1 = require("./Utils/Point.js");
|
|
17
40
|
const QuadTree_js_1 = require("./Utils/QuadTree.js");
|
|
18
41
|
const Rectangle_js_1 = require("./Utils/Rectangle.js");
|
|
19
42
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
20
|
-
const qTreeCapacity = 4;
|
|
43
|
+
const qTreeCapacity = 4, squareExp = 2, defaultRemoveQuantity = 1;
|
|
21
44
|
const qTreeRectangle = (canvasSize) => {
|
|
22
45
|
const { height, width } = canvasSize, posOffset = -0.25, sizeFactor = 1.5;
|
|
23
46
|
return new Rectangle_js_1.Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
|
|
@@ -29,7 +52,7 @@
|
|
|
29
52
|
this._pool.push(particle);
|
|
30
53
|
}
|
|
31
54
|
};
|
|
32
|
-
this._applyDensity = (options, manualCount, group) => {
|
|
55
|
+
this._applyDensity = async (options, manualCount, group) => {
|
|
33
56
|
const numberOptions = options.number;
|
|
34
57
|
if (!options.number.density?.enable) {
|
|
35
58
|
if (group === undefined) {
|
|
@@ -40,7 +63,7 @@
|
|
|
40
63
|
}
|
|
41
64
|
return;
|
|
42
65
|
}
|
|
43
|
-
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value >
|
|
66
|
+
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, minLimit = 0, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter((t) => t.group === group).length);
|
|
44
67
|
if (group === undefined) {
|
|
45
68
|
this._limit = numberOptions.limit.value * densityFactor;
|
|
46
69
|
}
|
|
@@ -48,29 +71,28 @@
|
|
|
48
71
|
this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
49
72
|
}
|
|
50
73
|
if (particlesCount < particlesNumber) {
|
|
51
|
-
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
74
|
+
await this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
52
75
|
}
|
|
53
76
|
else if (particlesCount > particlesNumber) {
|
|
54
77
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
55
78
|
}
|
|
56
79
|
};
|
|
57
80
|
this._initDensityFactor = (densityOptions) => {
|
|
58
|
-
const container = this._container;
|
|
81
|
+
const container = this._container, defaultFactor = 1;
|
|
59
82
|
if (!container.canvas.element || !densityOptions.enable) {
|
|
60
|
-
return
|
|
83
|
+
return defaultFactor;
|
|
61
84
|
}
|
|
62
85
|
const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
|
|
63
|
-
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio **
|
|
86
|
+
return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
|
|
64
87
|
};
|
|
65
|
-
this._pushParticle = (position, overrideOptions, group, initializer) => {
|
|
88
|
+
this._pushParticle = async (position, overrideOptions, group, initializer) => {
|
|
66
89
|
try {
|
|
67
90
|
let particle = this._pool.pop();
|
|
68
|
-
if (particle) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
else {
|
|
72
|
-
particle = new Particle_js_1.Particle(this._engine, this._nextId, this._container, position, overrideOptions, group);
|
|
91
|
+
if (!particle) {
|
|
92
|
+
const { Particle } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Particle.js"))) : new Promise((resolve_1, reject_1) => { require(["./Particle.js"], resolve_1, reject_1); }).then(__importStar));
|
|
93
|
+
particle = new Particle(this._engine, this._container);
|
|
73
94
|
}
|
|
95
|
+
await particle.init(this._nextId, position, overrideOptions, group);
|
|
74
96
|
let canAdd = true;
|
|
75
97
|
if (initializer) {
|
|
76
98
|
canAdd = initializer(particle);
|
|
@@ -91,7 +113,6 @@
|
|
|
91
113
|
}
|
|
92
114
|
catch (e) {
|
|
93
115
|
(0, Utils_js_1.getLogger)().warning(`${Constants_js_1.errorPrefix} adding particle: ${e}`);
|
|
94
|
-
return;
|
|
95
116
|
}
|
|
96
117
|
};
|
|
97
118
|
this._removeParticle = (index, group, override) => {
|
|
@@ -99,9 +120,9 @@
|
|
|
99
120
|
if (!particle || particle.group !== group) {
|
|
100
121
|
return false;
|
|
101
122
|
}
|
|
102
|
-
const zIdx = this._zArray.indexOf(particle);
|
|
103
|
-
this._array.splice(index,
|
|
104
|
-
this._zArray.splice(zIdx,
|
|
123
|
+
const zIdx = this._zArray.indexOf(particle), deleteCount = 1;
|
|
124
|
+
this._array.splice(index, deleteCount);
|
|
125
|
+
this._zArray.splice(zIdx, deleteCount);
|
|
105
126
|
particle.destroy(override);
|
|
106
127
|
this._engine.dispatchEvent("particleRemoved", {
|
|
107
128
|
container: this._container,
|
|
@@ -123,26 +144,27 @@
|
|
|
123
144
|
this._needsSort = false;
|
|
124
145
|
this._lastZIndex = 0;
|
|
125
146
|
this._interactionManager = new InteractionManager_js_1.InteractionManager(engine, container);
|
|
147
|
+
this._pluginsInitialized = false;
|
|
126
148
|
const canvasSize = container.canvas.size;
|
|
127
149
|
this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
|
|
128
|
-
this.movers =
|
|
129
|
-
this.updaters =
|
|
150
|
+
this.movers = [];
|
|
151
|
+
this.updaters = [];
|
|
130
152
|
}
|
|
131
153
|
get count() {
|
|
132
154
|
return this._array.length;
|
|
133
155
|
}
|
|
134
|
-
addManualParticles() {
|
|
156
|
+
async addManualParticles() {
|
|
135
157
|
const container = this._container, options = container.actualOptions;
|
|
136
158
|
for (const particle of options.manualParticles) {
|
|
137
|
-
this.addParticle(particle.position ? (0, Utils_js_1.getPosition)(particle.position, container.canvas.size) : undefined, particle.options);
|
|
159
|
+
await this.addParticle(particle.position ? (0, Utils_js_1.getPosition)(particle.position, container.canvas.size) : undefined, particle.options);
|
|
138
160
|
}
|
|
139
161
|
}
|
|
140
|
-
addParticle(position, overrideOptions, group, initializer) {
|
|
141
|
-
const limitOptions = this._container.actualOptions.particles.number.limit, limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit, currentCount = this.count;
|
|
142
|
-
if (limit >
|
|
162
|
+
async addParticle(position, overrideOptions, group, initializer) {
|
|
163
|
+
const limitOptions = this._container.actualOptions.particles.number.limit, limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit, currentCount = this.count, minLimit = 0;
|
|
164
|
+
if (limit > minLimit) {
|
|
143
165
|
if (limitOptions.mode === "delete") {
|
|
144
|
-
const countToRemove = currentCount +
|
|
145
|
-
if (countToRemove >
|
|
166
|
+
const countOffset = 1, minCount = 0, countToRemove = currentCount + countOffset - limit;
|
|
167
|
+
if (countToRemove > minCount) {
|
|
146
168
|
this.removeQuantity(countToRemove);
|
|
147
169
|
}
|
|
148
170
|
}
|
|
@@ -152,11 +174,12 @@
|
|
|
152
174
|
}
|
|
153
175
|
}
|
|
154
176
|
}
|
|
155
|
-
return this._pushParticle(position, overrideOptions, group, initializer);
|
|
177
|
+
return await this._pushParticle(position, overrideOptions, group, initializer);
|
|
156
178
|
}
|
|
157
179
|
clear() {
|
|
158
180
|
this._array = [];
|
|
159
181
|
this._zArray = [];
|
|
182
|
+
this._pluginsInitialized = false;
|
|
160
183
|
}
|
|
161
184
|
destroy() {
|
|
162
185
|
this._array = [];
|
|
@@ -169,10 +192,10 @@
|
|
|
169
192
|
canvas.clear();
|
|
170
193
|
await this.update(delta);
|
|
171
194
|
for (const [, plugin] of container.plugins) {
|
|
172
|
-
canvas.drawPlugin(plugin, delta);
|
|
195
|
+
await canvas.drawPlugin(plugin, delta);
|
|
173
196
|
}
|
|
174
197
|
for (const p of this._zArray) {
|
|
175
|
-
p.draw(delta);
|
|
198
|
+
await p.draw(delta);
|
|
176
199
|
}
|
|
177
200
|
}
|
|
178
201
|
filter(condition) {
|
|
@@ -187,13 +210,12 @@
|
|
|
187
210
|
handleClickMode(mode) {
|
|
188
211
|
this._interactionManager.handleClickMode(mode);
|
|
189
212
|
}
|
|
190
|
-
init() {
|
|
213
|
+
async init() {
|
|
191
214
|
const container = this._container, options = container.actualOptions;
|
|
192
215
|
this._lastZIndex = 0;
|
|
193
216
|
this._needsSort = false;
|
|
217
|
+
await this.initPlugins();
|
|
194
218
|
let handled = false;
|
|
195
|
-
this.updaters = this._engine.getUpdaters(container, true);
|
|
196
|
-
this._interactionManager.init();
|
|
197
219
|
for (const [, plugin] of container.plugins) {
|
|
198
220
|
if (plugin.particlesInitialization !== undefined) {
|
|
199
221
|
handled = plugin.particlesInitialization();
|
|
@@ -202,55 +224,67 @@
|
|
|
202
224
|
break;
|
|
203
225
|
}
|
|
204
226
|
}
|
|
205
|
-
this.
|
|
206
|
-
for (const [, pathGenerator] of container.pathGenerators) {
|
|
207
|
-
pathGenerator.init(container);
|
|
208
|
-
}
|
|
209
|
-
this.addManualParticles();
|
|
227
|
+
await this.addManualParticles();
|
|
210
228
|
if (!handled) {
|
|
211
229
|
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
212
230
|
for (const group in groups) {
|
|
213
231
|
const groupOptions = groups[group];
|
|
214
232
|
for (let i = this.count, j = 0; j < groupOptions.number?.value && i < particlesOptions.number.value; i++, j++) {
|
|
215
|
-
this.addParticle(undefined, groupOptions, group);
|
|
233
|
+
await this.addParticle(undefined, groupOptions, group);
|
|
216
234
|
}
|
|
217
235
|
}
|
|
218
236
|
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
219
|
-
this.addParticle();
|
|
237
|
+
await this.addParticle();
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
240
|
}
|
|
223
|
-
|
|
241
|
+
async initPlugins() {
|
|
242
|
+
if (this._pluginsInitialized) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const container = this._container;
|
|
246
|
+
this.movers = await this._engine.getMovers(container, true);
|
|
247
|
+
this.updaters = await this._engine.getUpdaters(container, true);
|
|
248
|
+
await this._interactionManager.init();
|
|
249
|
+
for (const [, pathGenerator] of container.pathGenerators) {
|
|
250
|
+
await pathGenerator.init(container);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async push(nb, mouse, overrideOptions, group) {
|
|
224
254
|
for (let i = 0; i < nb; i++) {
|
|
225
|
-
this.addParticle(mouse?.position, overrideOptions, group);
|
|
255
|
+
await this.addParticle(mouse?.position, overrideOptions, group);
|
|
226
256
|
}
|
|
227
257
|
}
|
|
228
258
|
async redraw() {
|
|
229
259
|
this.clear();
|
|
230
|
-
this.init();
|
|
260
|
+
await this.init();
|
|
231
261
|
await this.draw({ value: 0, factor: 0 });
|
|
232
262
|
}
|
|
233
263
|
remove(particle, group, override) {
|
|
234
264
|
this.removeAt(this._array.indexOf(particle), undefined, group, override);
|
|
235
265
|
}
|
|
236
|
-
removeAt(index, quantity =
|
|
237
|
-
|
|
266
|
+
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
267
|
+
const minIndex = 0;
|
|
268
|
+
if (index < minIndex || index > this.count) {
|
|
238
269
|
return;
|
|
239
270
|
}
|
|
240
271
|
let deleted = 0;
|
|
241
272
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
242
|
-
this._removeParticle(i--, group, override)
|
|
273
|
+
if (this._removeParticle(i--, group, override)) {
|
|
274
|
+
deleted++;
|
|
275
|
+
}
|
|
243
276
|
}
|
|
244
277
|
}
|
|
245
278
|
removeQuantity(quantity, group) {
|
|
246
|
-
|
|
279
|
+
const defaultIndex = 0;
|
|
280
|
+
this.removeAt(defaultIndex, quantity, group);
|
|
247
281
|
}
|
|
248
|
-
setDensity() {
|
|
249
|
-
const options = this._container.actualOptions, groups = options.particles.groups;
|
|
282
|
+
async setDensity() {
|
|
283
|
+
const options = this._container.actualOptions, groups = options.particles.groups, manualCount = 0;
|
|
250
284
|
for (const group in groups) {
|
|
251
|
-
this._applyDensity(groups[group],
|
|
285
|
+
await this._applyDensity(groups[group], manualCount, group);
|
|
252
286
|
}
|
|
253
|
-
this._applyDensity(options.particles, options.manualParticles.length);
|
|
287
|
+
await this._applyDensity(options.particles, options.manualParticles.length);
|
|
254
288
|
}
|
|
255
289
|
setLastZIndex(zIndex) {
|
|
256
290
|
this._lastZIndex = zIndex;
|
|
@@ -266,7 +300,7 @@
|
|
|
266
300
|
pathGenerator.update();
|
|
267
301
|
}
|
|
268
302
|
for (const [, plugin] of container.plugins) {
|
|
269
|
-
|
|
303
|
+
await plugin.update?.(delta);
|
|
270
304
|
}
|
|
271
305
|
const resizeFactor = this._resizeFactor;
|
|
272
306
|
for (const particle of this._array) {
|
|
@@ -277,15 +311,17 @@
|
|
|
277
311
|
particle.initialPosition.y *= resizeFactor.height;
|
|
278
312
|
}
|
|
279
313
|
particle.ignoresResizeRatio = false;
|
|
280
|
-
|
|
314
|
+
this._interactionManager.reset(particle);
|
|
281
315
|
for (const [, plugin] of this._container.plugins) {
|
|
282
316
|
if (particle.destroyed) {
|
|
283
317
|
break;
|
|
284
318
|
}
|
|
285
|
-
plugin.particleUpdate
|
|
319
|
+
plugin.particleUpdate?.(particle, delta);
|
|
286
320
|
}
|
|
287
321
|
for (const mover of this.movers) {
|
|
288
|
-
mover.isEnabled(particle)
|
|
322
|
+
if (mover.isEnabled(particle)) {
|
|
323
|
+
await mover.move(particle, delta);
|
|
324
|
+
}
|
|
289
325
|
}
|
|
290
326
|
if (particle.destroyed) {
|
|
291
327
|
particlesToDelete.add(particle);
|
|
@@ -310,7 +346,7 @@
|
|
|
310
346
|
await this._interactionManager.externalInteract(delta);
|
|
311
347
|
for (const particle of this._array) {
|
|
312
348
|
for (const updater of this.updaters) {
|
|
313
|
-
updater.update(particle, delta);
|
|
349
|
+
await updater.update(particle, delta);
|
|
314
350
|
}
|
|
315
351
|
if (!particle.destroyed && !particle.spawning) {
|
|
316
352
|
await this._interactionManager.particlesInteract(particle, delta);
|
|
@@ -320,7 +356,8 @@
|
|
|
320
356
|
if (this._needsSort) {
|
|
321
357
|
const zArray = this._zArray;
|
|
322
358
|
zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
|
|
323
|
-
|
|
359
|
+
const lengthOffset = 1;
|
|
360
|
+
this._lastZIndex = zArray[zArray.length - lengthOffset].position.z;
|
|
324
361
|
this._needsSort = false;
|
|
325
362
|
}
|
|
326
363
|
}
|
package/umd/Core/Retina.js
CHANGED
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
exports.Retina = void 0;
|
|
13
13
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
14
14
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
15
|
+
const defaultRatio = 1, defaultReduceFactor = 1;
|
|
15
16
|
class Retina {
|
|
16
17
|
constructor(container) {
|
|
17
18
|
this.container = container;
|
|
18
|
-
this.pixelRatio =
|
|
19
|
-
this.reduceFactor =
|
|
19
|
+
this.pixelRatio = defaultRatio;
|
|
20
|
+
this.reduceFactor = defaultReduceFactor;
|
|
20
21
|
}
|
|
21
22
|
init() {
|
|
22
23
|
const container = this.container, options = container.actualOptions;
|
|
23
|
-
this.pixelRatio = !options.detectRetina || (0, Utils_js_1.isSsr)() ?
|
|
24
|
-
this.reduceFactor =
|
|
24
|
+
this.pixelRatio = !options.detectRetina || (0, Utils_js_1.isSsr)() ? defaultRatio : window.devicePixelRatio;
|
|
25
|
+
this.reduceFactor = defaultReduceFactor;
|
|
25
26
|
const ratio = this.pixelRatio, canvas = container.canvas;
|
|
26
27
|
if (canvas.element) {
|
|
27
28
|
const element = canvas.element;
|
package/umd/Core/Utils/Circle.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
const Range_js_1 = require("./Range.js");
|
|
14
14
|
const Rectangle_js_1 = require("./Rectangle.js");
|
|
15
15
|
const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
|
|
16
|
+
const squareExp = 2;
|
|
16
17
|
class Circle extends Range_js_1.Range {
|
|
17
18
|
constructor(x, y, radius) {
|
|
18
19
|
super(x, y);
|
|
@@ -24,12 +25,12 @@
|
|
|
24
25
|
intersects(range) {
|
|
25
26
|
const pos1 = this.position, pos2 = range.position, distPos = { x: Math.abs(pos2.x - pos1.x), y: Math.abs(pos2.y - pos1.y) }, r = this.radius;
|
|
26
27
|
if (range instanceof Circle) {
|
|
27
|
-
const rSum = r + range.radius, dist = Math.sqrt(distPos.x **
|
|
28
|
+
const rSum = r + range.radius, dist = Math.sqrt(distPos.x ** squareExp + distPos.y ** squareExp);
|
|
28
29
|
return rSum > dist;
|
|
29
30
|
}
|
|
30
31
|
else if (range instanceof Rectangle_js_1.Rectangle) {
|
|
31
|
-
const { width, height } = range.size, edges = Math.pow(distPos.x - width,
|
|
32
|
-
return (edges <= r **
|
|
32
|
+
const { width, height } = range.size, edges = Math.pow(distPos.x - width, squareExp) + Math.pow(distPos.y - height, squareExp);
|
|
33
|
+
return (edges <= r ** squareExp ||
|
|
33
34
|
(distPos.x <= r + width && distPos.y <= r + height) ||
|
|
34
35
|
distPos.x <= width ||
|
|
35
36
|
distPos.y <= height);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
|
|
12
|
+
exports.millisecondsToSeconds = exports.halfRandom = exports.percentDenominator = exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
|
|
13
13
|
exports.generatedAttribute = "generated";
|
|
14
14
|
exports.mouseDownEvent = "pointerdown";
|
|
15
15
|
exports.mouseUpEvent = "pointerup";
|
|
@@ -23,4 +23,7 @@
|
|
|
23
23
|
exports.resizeEvent = "resize";
|
|
24
24
|
exports.visibilityChangeEvent = "visibilitychange";
|
|
25
25
|
exports.errorPrefix = "tsParticles - Error";
|
|
26
|
+
exports.percentDenominator = 100;
|
|
27
|
+
exports.halfRandom = 0.5;
|
|
28
|
+
exports.millisecondsToSeconds = 1000;
|
|
26
29
|
});
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
exports.EventListeners = void 0;
|
|
13
13
|
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
14
14
|
const Constants_js_1 = require("./Constants.js");
|
|
15
|
+
const double = 2;
|
|
15
16
|
function manageListener(element, event, handler, add, options) {
|
|
16
17
|
if (add) {
|
|
17
18
|
let addOptions = { passive: true };
|
|
@@ -44,13 +45,14 @@
|
|
|
44
45
|
(0, Utils_js_1.executeOnSingleOrMultiple)(onClick.mode, (mode) => this.container.handleClickMode(mode));
|
|
45
46
|
}
|
|
46
47
|
if (e.type === "touchend") {
|
|
47
|
-
|
|
48
|
+
const touchDelay = 500;
|
|
49
|
+
setTimeout(() => this._mouseTouchFinish(), touchDelay);
|
|
48
50
|
}
|
|
49
51
|
};
|
|
50
52
|
this._handleThemeChange = (e) => {
|
|
51
53
|
const mediaEvent = e, container = this.container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes.find((theme) => theme.name === themeName);
|
|
52
54
|
if (theme && theme.default.auto) {
|
|
53
|
-
container.loadTheme(themeName);
|
|
55
|
+
void container.loadTheme(themeName);
|
|
54
56
|
}
|
|
55
57
|
};
|
|
56
58
|
this._handleVisibilityChange = () => {
|
|
@@ -65,7 +67,7 @@
|
|
|
65
67
|
}
|
|
66
68
|
else {
|
|
67
69
|
container.pageHidden = false;
|
|
68
|
-
if (container.
|
|
70
|
+
if (container.animationStatus) {
|
|
69
71
|
container.play(true);
|
|
70
72
|
}
|
|
71
73
|
else {
|
|
@@ -73,15 +75,16 @@
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
|
-
this._handleWindowResize =
|
|
78
|
+
this._handleWindowResize = () => {
|
|
77
79
|
if (this._resizeTimeout) {
|
|
78
80
|
clearTimeout(this._resizeTimeout);
|
|
79
81
|
delete this._resizeTimeout;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
const handleResize = async () => {
|
|
82
84
|
const canvas = this.container.canvas;
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
+
await canvas?.windowResize();
|
|
86
|
+
};
|
|
87
|
+
this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.interactivity.events.resize.delay * Constants_js_1.millisecondsToSeconds);
|
|
85
88
|
};
|
|
86
89
|
this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
|
|
87
90
|
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
@@ -167,12 +170,12 @@
|
|
|
167
170
|
delete this._resizeObserver;
|
|
168
171
|
}
|
|
169
172
|
else if (!this._resizeObserver && add && canvasEl) {
|
|
170
|
-
this._resizeObserver = new ResizeObserver(
|
|
173
|
+
this._resizeObserver = new ResizeObserver((entries) => {
|
|
171
174
|
const entry = entries.find((e) => e.target === canvasEl);
|
|
172
175
|
if (!entry) {
|
|
173
176
|
return;
|
|
174
177
|
}
|
|
175
|
-
|
|
178
|
+
this._handleWindowResize();
|
|
176
179
|
});
|
|
177
180
|
this._resizeObserver.observe(canvasEl);
|
|
178
181
|
}
|
|
@@ -223,7 +226,7 @@
|
|
|
223
226
|
};
|
|
224
227
|
this._mouseTouchMove = (e) => {
|
|
225
228
|
const container = this.container, options = container.actualOptions, interactivity = container.interactivity, canvasEl = container.canvas.element;
|
|
226
|
-
if (!interactivity
|
|
229
|
+
if (!interactivity?.element) {
|
|
227
230
|
return;
|
|
228
231
|
}
|
|
229
232
|
interactivity.mouse.inside = true;
|
|
@@ -245,8 +248,8 @@
|
|
|
245
248
|
if (source && target && canvasEl) {
|
|
246
249
|
const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
|
|
247
250
|
pos = {
|
|
248
|
-
x: mouseEvent.offsetX +
|
|
249
|
-
y: mouseEvent.offsetY +
|
|
251
|
+
x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),
|
|
252
|
+
y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top),
|
|
250
253
|
};
|
|
251
254
|
}
|
|
252
255
|
else {
|
|
@@ -266,10 +269,10 @@
|
|
|
266
269
|
else {
|
|
267
270
|
this._canPush = e.type !== "touchmove";
|
|
268
271
|
if (canvasEl) {
|
|
269
|
-
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length -
|
|
272
|
+
const touchEvent = e, lengthOffset = 1, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect(), defaultCoordinate = 0;
|
|
270
273
|
pos = {
|
|
271
|
-
x: lastTouch.clientX - (canvasRect.left ??
|
|
272
|
-
y: lastTouch.clientY - (canvasRect.top ??
|
|
274
|
+
x: lastTouch.clientX - (canvasRect.left ?? defaultCoordinate),
|
|
275
|
+
y: lastTouch.clientY - (canvasRect.top ?? defaultCoordinate),
|
|
273
276
|
};
|
|
274
277
|
}
|
|
275
278
|
}
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
exports.ExternalInteractorBase = void 0;
|
|
13
13
|
class ExternalInteractorBase {
|
|
14
14
|
constructor(container) {
|
|
15
|
-
this.container = container;
|
|
16
15
|
this.type = "external";
|
|
16
|
+
this.container = container;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.ExternalInteractorBase = ExternalInteractorBase;
|
|
@@ -14,21 +14,24 @@
|
|
|
14
14
|
constructor(engine, container) {
|
|
15
15
|
this.container = container;
|
|
16
16
|
this._engine = engine;
|
|
17
|
-
this._interactors =
|
|
17
|
+
this._interactors = [];
|
|
18
18
|
this._externalInteractors = [];
|
|
19
19
|
this._particleInteractors = [];
|
|
20
20
|
}
|
|
21
21
|
async externalInteract(delta) {
|
|
22
22
|
for (const interactor of this._externalInteractors) {
|
|
23
|
-
|
|
23
|
+
if (interactor.isEnabled()) {
|
|
24
|
+
await interactor.interact(delta);
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
handleClickMode(mode) {
|
|
27
29
|
for (const interactor of this._externalInteractors) {
|
|
28
|
-
interactor.handleClickMode
|
|
30
|
+
interactor.handleClickMode?.(mode);
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
|
-
init() {
|
|
33
|
+
async init() {
|
|
34
|
+
this._interactors = await this._engine.getInteractors(this.container, true);
|
|
32
35
|
this._externalInteractors = [];
|
|
33
36
|
this._particleInteractors = [];
|
|
34
37
|
for (const interactor of this._interactors) {
|
|
@@ -48,15 +51,21 @@
|
|
|
48
51
|
interactor.clear(particle, delta);
|
|
49
52
|
}
|
|
50
53
|
for (const interactor of this._particleInteractors) {
|
|
51
|
-
|
|
54
|
+
if (interactor.isEnabled(particle)) {
|
|
55
|
+
await interactor.interact(particle, delta);
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
reset(particle) {
|
|
55
60
|
for (const interactor of this._externalInteractors) {
|
|
56
|
-
interactor.isEnabled()
|
|
61
|
+
if (interactor.isEnabled()) {
|
|
62
|
+
interactor.reset(particle);
|
|
63
|
+
}
|
|
57
64
|
}
|
|
58
65
|
for (const interactor of this._particleInteractors) {
|
|
59
|
-
interactor.isEnabled(particle)
|
|
66
|
+
if (interactor.isEnabled(particle)) {
|
|
67
|
+
interactor.reset(particle);
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
}
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
exports.ParticlesInteractorBase = void 0;
|
|
13
13
|
class ParticlesInteractorBase {
|
|
14
14
|
constructor(container) {
|
|
15
|
-
this.container = container;
|
|
16
15
|
this.type = "particles";
|
|
16
|
+
this.container = container;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.ParticlesInteractorBase = ParticlesInteractorBase;
|
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
const Circle_js_1 = require("./Circle.js");
|
|
14
14
|
const Rectangle_js_1 = require("./Rectangle.js");
|
|
15
15
|
const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
|
|
16
|
+
const half = 0.5, double = 2, subdivideCount = 4;
|
|
16
17
|
class QuadTree {
|
|
17
18
|
constructor(rectangle, capacity) {
|
|
18
19
|
this.rectangle = rectangle;
|
|
19
20
|
this.capacity = capacity;
|
|
20
21
|
this._subdivide = () => {
|
|
21
22
|
const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
|
|
22
|
-
for (let i = 0; i <
|
|
23
|
-
|
|
23
|
+
for (let i = 0; i < subdivideCount; i++) {
|
|
24
|
+
const fixedIndex = i % double;
|
|
25
|
+
this._subs.push(new QuadTree(new Rectangle_js_1.Rectangle(x + width * half * fixedIndex, y + height * half * (Math.round(i * half) - fixedIndex), width * half, height * half), capacity));
|
|
24
26
|
}
|
|
25
27
|
this._divided = true;
|
|
26
28
|
};
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
return this._subs.some((sub) => sub.insert(point));
|
|
43
45
|
}
|
|
44
46
|
query(range, check, found) {
|
|
45
|
-
const res = found
|
|
47
|
+
const res = found ?? [];
|
|
46
48
|
if (!range.intersects(this.rectangle)) {
|
|
47
49
|
return [];
|
|
48
50
|
}
|
package/umd/Core/Utils/Vector.js
CHANGED
|
@@ -11,12 +11,17 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Vector = void 0;
|
|
13
13
|
const Vector3d_js_1 = require("./Vector3d.js");
|
|
14
|
+
const origin = {
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0,
|
|
17
|
+
z: 0,
|
|
18
|
+
};
|
|
14
19
|
class Vector extends Vector3d_js_1.Vector3d {
|
|
15
20
|
constructor(xOrCoords, y) {
|
|
16
|
-
super(xOrCoords, y,
|
|
21
|
+
super(xOrCoords, y, origin.z);
|
|
17
22
|
}
|
|
18
23
|
static get origin() {
|
|
19
|
-
return Vector.create(
|
|
24
|
+
return Vector.create(origin.x, origin.y);
|
|
20
25
|
}
|
|
21
26
|
static clone(source) {
|
|
22
27
|
return Vector.create(source.x, source.y);
|