@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
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../Utils/CanvasUtils.js", "./Utils/Constants.js", "../Utils/ColorUtils.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RenderManager = void 0;
|
|
13
|
+
const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
|
|
14
|
+
const Constants_js_1 = require("./Utils/Constants.js");
|
|
15
|
+
const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
|
|
16
|
+
const fColorIndex = 0, sColorIndex = 1;
|
|
17
|
+
function setTransformValue(factor, newFactor, key) {
|
|
18
|
+
const newValue = newFactor[key];
|
|
19
|
+
if (newValue !== undefined) {
|
|
20
|
+
factor[key] = (factor[key] ?? Constants_js_1.defaultTransformValue) * newValue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class RenderManager {
|
|
24
|
+
_canvasClearPlugins;
|
|
25
|
+
_canvasManager;
|
|
26
|
+
_canvasPaintPlugins;
|
|
27
|
+
_clearDrawPlugins;
|
|
28
|
+
_colorPlugins;
|
|
29
|
+
_container;
|
|
30
|
+
_context;
|
|
31
|
+
_contextSettings;
|
|
32
|
+
_drawParticlePlugins;
|
|
33
|
+
_drawParticlesCleanupPlugins;
|
|
34
|
+
_drawParticlesSetupPlugins;
|
|
35
|
+
_drawPlugins;
|
|
36
|
+
_drawSettingsCleanupPlugins;
|
|
37
|
+
_drawSettingsSetupPlugins;
|
|
38
|
+
_pluginManager;
|
|
39
|
+
_postDrawUpdaters;
|
|
40
|
+
_preDrawUpdaters;
|
|
41
|
+
_reusableColorStyles = {};
|
|
42
|
+
_reusablePluginColors = [undefined, undefined];
|
|
43
|
+
_reusableTransform = {};
|
|
44
|
+
constructor(pluginManager, container, canvasManager) {
|
|
45
|
+
this._pluginManager = pluginManager;
|
|
46
|
+
this._container = container;
|
|
47
|
+
this._canvasManager = canvasManager;
|
|
48
|
+
this._context = null;
|
|
49
|
+
this._preDrawUpdaters = [];
|
|
50
|
+
this._postDrawUpdaters = [];
|
|
51
|
+
this._colorPlugins = [];
|
|
52
|
+
this._canvasClearPlugins = [];
|
|
53
|
+
this._canvasPaintPlugins = [];
|
|
54
|
+
this._clearDrawPlugins = [];
|
|
55
|
+
this._drawParticlePlugins = [];
|
|
56
|
+
this._drawParticlesCleanupPlugins = [];
|
|
57
|
+
this._drawParticlesSetupPlugins = [];
|
|
58
|
+
this._drawPlugins = [];
|
|
59
|
+
this._drawSettingsSetupPlugins = [];
|
|
60
|
+
this._drawSettingsCleanupPlugins = [];
|
|
61
|
+
}
|
|
62
|
+
get settings() {
|
|
63
|
+
return this._contextSettings;
|
|
64
|
+
}
|
|
65
|
+
canvasClear() {
|
|
66
|
+
if (!this._container.actualOptions.clear) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.draw(ctx => {
|
|
70
|
+
(0, CanvasUtils_js_1.clear)(ctx, this._canvasManager.size);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
clear() {
|
|
74
|
+
let pluginHandled = false;
|
|
75
|
+
for (const plugin of this._canvasClearPlugins) {
|
|
76
|
+
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
77
|
+
if (pluginHandled) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (pluginHandled) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.canvasClear();
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
this.stop();
|
|
88
|
+
this._preDrawUpdaters = [];
|
|
89
|
+
this._postDrawUpdaters = [];
|
|
90
|
+
this._colorPlugins = [];
|
|
91
|
+
this._canvasClearPlugins = [];
|
|
92
|
+
this._canvasPaintPlugins = [];
|
|
93
|
+
this._clearDrawPlugins = [];
|
|
94
|
+
this._drawParticlePlugins = [];
|
|
95
|
+
this._drawParticlesCleanupPlugins = [];
|
|
96
|
+
this._drawParticlesSetupPlugins = [];
|
|
97
|
+
this._drawPlugins = [];
|
|
98
|
+
this._drawSettingsSetupPlugins = [];
|
|
99
|
+
this._drawSettingsCleanupPlugins = [];
|
|
100
|
+
}
|
|
101
|
+
draw(cb) {
|
|
102
|
+
const ctx = this._context;
|
|
103
|
+
if (!ctx) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
return cb(ctx);
|
|
107
|
+
}
|
|
108
|
+
drawParticle(particle, delta) {
|
|
109
|
+
if (particle.spawning || particle.destroyed) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const radius = particle.getRadius();
|
|
113
|
+
if (radius <= Constants_js_1.minimumSize) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
117
|
+
let [fColor, sColor] = this._getPluginParticleColors(particle);
|
|
118
|
+
fColor ??= pfColor;
|
|
119
|
+
sColor ??= psColor;
|
|
120
|
+
if (!fColor && !sColor) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const container = this._container, zIndexOptions = particle.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, container.hdr, strokeOpacity * opacity) : fill;
|
|
124
|
+
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
125
|
+
colorStyles.fill = fill;
|
|
126
|
+
colorStyles.stroke = stroke;
|
|
127
|
+
this.draw((context) => {
|
|
128
|
+
for (const plugin of this._drawParticlesSetupPlugins) {
|
|
129
|
+
plugin.drawParticleSetup?.(context, particle, delta);
|
|
130
|
+
}
|
|
131
|
+
this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
132
|
+
(0, CanvasUtils_js_1.drawParticle)({
|
|
133
|
+
container,
|
|
134
|
+
context,
|
|
135
|
+
particle,
|
|
136
|
+
delta,
|
|
137
|
+
colorStyles,
|
|
138
|
+
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
139
|
+
opacity: opacity,
|
|
140
|
+
transform,
|
|
141
|
+
});
|
|
142
|
+
this._applyPostDrawUpdaters(particle);
|
|
143
|
+
for (const plugin of this._drawParticlesCleanupPlugins) {
|
|
144
|
+
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
drawParticlePlugins(particle, delta) {
|
|
149
|
+
this.draw(ctx => {
|
|
150
|
+
for (const plugin of this._drawParticlePlugins) {
|
|
151
|
+
(0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
drawParticles(delta) {
|
|
156
|
+
const { particles } = this._container;
|
|
157
|
+
this.clear();
|
|
158
|
+
particles.update(delta);
|
|
159
|
+
this.draw(ctx => {
|
|
160
|
+
for (const plugin of this._drawSettingsSetupPlugins) {
|
|
161
|
+
plugin.drawSettingsSetup?.(ctx, delta);
|
|
162
|
+
}
|
|
163
|
+
for (const plugin of this._drawPlugins) {
|
|
164
|
+
plugin.draw?.(ctx, delta);
|
|
165
|
+
}
|
|
166
|
+
particles.drawParticles(delta);
|
|
167
|
+
for (const plugin of this._clearDrawPlugins) {
|
|
168
|
+
plugin.clearDraw?.(ctx, delta);
|
|
169
|
+
}
|
|
170
|
+
for (const plugin of this._drawSettingsCleanupPlugins) {
|
|
171
|
+
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
init() {
|
|
176
|
+
this.initUpdaters();
|
|
177
|
+
this.initPlugins();
|
|
178
|
+
this.paint();
|
|
179
|
+
}
|
|
180
|
+
initPlugins() {
|
|
181
|
+
this._colorPlugins = [];
|
|
182
|
+
this._canvasClearPlugins = [];
|
|
183
|
+
this._canvasPaintPlugins = [];
|
|
184
|
+
this._clearDrawPlugins = [];
|
|
185
|
+
this._drawParticlePlugins = [];
|
|
186
|
+
this._drawParticlesSetupPlugins = [];
|
|
187
|
+
this._drawParticlesCleanupPlugins = [];
|
|
188
|
+
this._drawPlugins = [];
|
|
189
|
+
this._drawSettingsSetupPlugins = [];
|
|
190
|
+
this._drawSettingsCleanupPlugins = [];
|
|
191
|
+
for (const plugin of this._container.plugins) {
|
|
192
|
+
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
193
|
+
this._colorPlugins.push(plugin);
|
|
194
|
+
}
|
|
195
|
+
if (plugin.canvasClear) {
|
|
196
|
+
this._canvasClearPlugins.push(plugin);
|
|
197
|
+
}
|
|
198
|
+
if (plugin.canvasPaint) {
|
|
199
|
+
this._canvasPaintPlugins.push(plugin);
|
|
200
|
+
}
|
|
201
|
+
if (plugin.drawParticle) {
|
|
202
|
+
this._drawParticlePlugins.push(plugin);
|
|
203
|
+
}
|
|
204
|
+
if (plugin.drawParticleSetup) {
|
|
205
|
+
this._drawParticlesSetupPlugins.push(plugin);
|
|
206
|
+
}
|
|
207
|
+
if (plugin.drawParticleCleanup) {
|
|
208
|
+
this._drawParticlesCleanupPlugins.push(plugin);
|
|
209
|
+
}
|
|
210
|
+
if (plugin.draw) {
|
|
211
|
+
this._drawPlugins.push(plugin);
|
|
212
|
+
}
|
|
213
|
+
if (plugin.drawSettingsSetup) {
|
|
214
|
+
this._drawSettingsSetupPlugins.push(plugin);
|
|
215
|
+
}
|
|
216
|
+
if (plugin.drawSettingsCleanup) {
|
|
217
|
+
this._drawSettingsCleanupPlugins.push(plugin);
|
|
218
|
+
}
|
|
219
|
+
if (plugin.clearDraw) {
|
|
220
|
+
this._clearDrawPlugins.push(plugin);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
initUpdaters() {
|
|
225
|
+
this._preDrawUpdaters = [];
|
|
226
|
+
this._postDrawUpdaters = [];
|
|
227
|
+
for (const updater of this._container.particleUpdaters) {
|
|
228
|
+
if (updater.afterDraw) {
|
|
229
|
+
this._postDrawUpdaters.push(updater);
|
|
230
|
+
}
|
|
231
|
+
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
232
|
+
this._preDrawUpdaters.push(updater);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
paint() {
|
|
237
|
+
let handled = false;
|
|
238
|
+
for (const plugin of this._canvasPaintPlugins) {
|
|
239
|
+
handled = plugin.canvasPaint?.() ?? false;
|
|
240
|
+
if (handled) {
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (handled) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this.paintBase();
|
|
248
|
+
}
|
|
249
|
+
paintBase(baseColor) {
|
|
250
|
+
this.draw(ctx => {
|
|
251
|
+
(0, CanvasUtils_js_1.paintBase)(ctx, this._canvasManager.size, baseColor);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
paintImage(image, opacity) {
|
|
255
|
+
this.draw(ctx => {
|
|
256
|
+
(0, CanvasUtils_js_1.paintImage)(ctx, this._canvasManager.size, image, opacity);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
setContext(context) {
|
|
260
|
+
this._context = context;
|
|
261
|
+
if (this._context) {
|
|
262
|
+
this._context.globalCompositeOperation = Constants_js_1.defaultCompositeValue;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
setContextSettings(settings) {
|
|
266
|
+
this._contextSettings = settings;
|
|
267
|
+
}
|
|
268
|
+
stop() {
|
|
269
|
+
this.draw(ctx => {
|
|
270
|
+
(0, CanvasUtils_js_1.clear)(ctx, this._canvasManager.size);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
_applyPostDrawUpdaters = particle => {
|
|
274
|
+
for (const updater of this._postDrawUpdaters) {
|
|
275
|
+
updater.afterDraw?.(particle);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
_applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
279
|
+
for (const updater of this._preDrawUpdaters) {
|
|
280
|
+
if (updater.getColorStyles) {
|
|
281
|
+
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
282
|
+
if (fill) {
|
|
283
|
+
colorStyles.fill = fill;
|
|
284
|
+
}
|
|
285
|
+
if (stroke) {
|
|
286
|
+
colorStyles.stroke = stroke;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (updater.getTransformValues) {
|
|
290
|
+
const updaterTransform = updater.getTransformValues(particle);
|
|
291
|
+
for (const key in updaterTransform) {
|
|
292
|
+
setTransformValue(transform, updaterTransform, key);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
updater.beforeDraw?.(particle);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
_getPluginParticleColors = particle => {
|
|
299
|
+
let fColor, sColor;
|
|
300
|
+
for (const plugin of this._colorPlugins) {
|
|
301
|
+
if (!fColor && plugin.particleFillColor) {
|
|
302
|
+
fColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._pluginManager, plugin.particleFillColor(particle));
|
|
303
|
+
}
|
|
304
|
+
if (!sColor && plugin.particleStrokeColor) {
|
|
305
|
+
sColor = (0, ColorUtils_js_1.rangeColorToHsl)(this._pluginManager, plugin.particleStrokeColor(particle));
|
|
306
|
+
}
|
|
307
|
+
if (fColor && sColor) {
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
this._reusablePluginColors[fColorIndex] = fColor;
|
|
312
|
+
this._reusablePluginColors[sColorIndex] = sColor;
|
|
313
|
+
return this._reusablePluginColors;
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
exports.RenderManager = RenderManager;
|
|
317
|
+
});
|
package/umd/Core/Retina.js
CHANGED
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
const MathUtils_js_1 = require("../Utils/MathUtils.js");
|
|
15
15
|
class Retina {
|
|
16
16
|
container;
|
|
17
|
-
maxSpeed;
|
|
18
17
|
pixelRatio;
|
|
19
18
|
reduceFactor;
|
|
20
|
-
sizeAnimationSpeed;
|
|
21
19
|
constructor(container) {
|
|
22
20
|
this.container = container;
|
|
23
21
|
this.pixelRatio = Constants_js_1.defaultRatio;
|
|
@@ -33,19 +31,16 @@
|
|
|
33
31
|
canvas.size.width = element.offsetWidth * ratio;
|
|
34
32
|
canvas.size.height = element.offsetHeight * ratio;
|
|
35
33
|
}
|
|
36
|
-
const particles = options.particles, moveOptions = particles.move;
|
|
37
|
-
this.maxSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;
|
|
38
|
-
this.sizeAnimationSpeed = (0, MathUtils_js_1.getRangeValue)(particles.size.animation.speed) * ratio;
|
|
39
34
|
}
|
|
40
35
|
initParticle(particle) {
|
|
41
36
|
const options = particle.options, ratio = this.pixelRatio, moveOptions = options.move, moveDistance = moveOptions.distance, props = particle.retina;
|
|
37
|
+
props.maxSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;
|
|
42
38
|
props.moveDrift = (0, MathUtils_js_1.getRangeValue)(moveOptions.drift) * ratio;
|
|
43
39
|
props.moveSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.speed) * ratio;
|
|
44
40
|
props.sizeAnimationSpeed = (0, MathUtils_js_1.getRangeValue)(options.size.animation.speed) * ratio;
|
|
45
41
|
const maxDistance = props.maxDistance;
|
|
46
|
-
maxDistance.horizontal = moveDistance.horizontal
|
|
47
|
-
maxDistance.vertical = moveDistance.vertical
|
|
48
|
-
props.maxSpeed = (0, MathUtils_js_1.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;
|
|
42
|
+
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
43
|
+
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
exports.Retina = Retina;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "../../Utils/Utils.js", "../../Enums/Types/EventType.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PluginManager = void 0;
|
|
13
|
+
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
14
|
+
const EventType_js_1 = require("../../Enums/Types/EventType.js");
|
|
15
|
+
class PluginManager {
|
|
16
|
+
colorManagers = new Map();
|
|
17
|
+
easingFunctions = new Map();
|
|
18
|
+
effectDrawers = new Map();
|
|
19
|
+
initializers = {
|
|
20
|
+
effects: new Map(),
|
|
21
|
+
shapes: new Map(),
|
|
22
|
+
updaters: new Map(),
|
|
23
|
+
};
|
|
24
|
+
palettes = new Map();
|
|
25
|
+
plugins = [];
|
|
26
|
+
presets = new Map();
|
|
27
|
+
shapeDrawers = new Map();
|
|
28
|
+
updaters = new Map();
|
|
29
|
+
_allLoadersSet = new Set();
|
|
30
|
+
_configs = new Map();
|
|
31
|
+
_engine;
|
|
32
|
+
_executedSet = new Set();
|
|
33
|
+
_initialized = false;
|
|
34
|
+
_isRunningLoaders = false;
|
|
35
|
+
_loadPromises = new Set();
|
|
36
|
+
constructor(engine) {
|
|
37
|
+
this._engine = engine;
|
|
38
|
+
}
|
|
39
|
+
get configs() {
|
|
40
|
+
const res = {};
|
|
41
|
+
for (const [name, config] of this._configs) {
|
|
42
|
+
res[name] = config;
|
|
43
|
+
}
|
|
44
|
+
return res;
|
|
45
|
+
}
|
|
46
|
+
addColorManager(name, manager) {
|
|
47
|
+
this.colorManagers.set(name, manager);
|
|
48
|
+
}
|
|
49
|
+
addConfig(config) {
|
|
50
|
+
const key = config.key ?? config.name ?? "default";
|
|
51
|
+
this._configs.set(key, config);
|
|
52
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.configAdded, { data: { name: key, config } });
|
|
53
|
+
}
|
|
54
|
+
addEasing(name, easing) {
|
|
55
|
+
if (this.easingFunctions.get(name)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.easingFunctions.set(name, easing);
|
|
59
|
+
}
|
|
60
|
+
addEffect(effect, drawer) {
|
|
61
|
+
this.initializers.effects.set(effect, drawer);
|
|
62
|
+
}
|
|
63
|
+
addPalette(name, palette) {
|
|
64
|
+
this.palettes.set(name, palette);
|
|
65
|
+
}
|
|
66
|
+
addParticleUpdater(name, updaterInitializer) {
|
|
67
|
+
this.initializers.updaters.set(name, updaterInitializer);
|
|
68
|
+
}
|
|
69
|
+
addPlugin(plugin) {
|
|
70
|
+
if (this.getPlugin(plugin.id)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.plugins.push(plugin);
|
|
74
|
+
}
|
|
75
|
+
addPreset(preset, options, override = false) {
|
|
76
|
+
if (!(override || !this.getPreset(preset))) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.presets.set(preset, options);
|
|
80
|
+
}
|
|
81
|
+
addShape(shapes, drawer) {
|
|
82
|
+
for (const shape of shapes) {
|
|
83
|
+
this.initializers.shapes.set(shape, drawer);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
clearPlugins(container) {
|
|
87
|
+
this.effectDrawers.delete(container);
|
|
88
|
+
this.shapeDrawers.delete(container);
|
|
89
|
+
this.updaters.delete(container);
|
|
90
|
+
}
|
|
91
|
+
getEasing(name) {
|
|
92
|
+
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
93
|
+
}
|
|
94
|
+
getEffectDrawers(container, force = false) {
|
|
95
|
+
return (0, Utils_js_1.getItemMapFromInitializer)(container, this.effectDrawers, this.initializers.effects, force);
|
|
96
|
+
}
|
|
97
|
+
getPalette(name) {
|
|
98
|
+
return this.palettes.get(name);
|
|
99
|
+
}
|
|
100
|
+
getPlugin(plugin) {
|
|
101
|
+
return this.plugins.find(t => t.id === plugin);
|
|
102
|
+
}
|
|
103
|
+
getPreset(preset) {
|
|
104
|
+
return this.presets.get(preset);
|
|
105
|
+
}
|
|
106
|
+
async getShapeDrawers(container, force = false) {
|
|
107
|
+
return (0, Utils_js_1.getItemMapFromInitializer)(container, this.shapeDrawers, this.initializers.shapes, force);
|
|
108
|
+
}
|
|
109
|
+
async getUpdaters(container, force = false) {
|
|
110
|
+
return (0, Utils_js_1.getItemsFromInitializer)(container, this.updaters, this.initializers.updaters, force);
|
|
111
|
+
}
|
|
112
|
+
async init() {
|
|
113
|
+
if (this._initialized || this._isRunningLoaders) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this._isRunningLoaders = true;
|
|
117
|
+
this._executedSet = new Set();
|
|
118
|
+
this._allLoadersSet = new Set(this._loadPromises);
|
|
119
|
+
try {
|
|
120
|
+
for (const loader of this._allLoadersSet) {
|
|
121
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
this._loadPromises.clear();
|
|
126
|
+
this._isRunningLoaders = false;
|
|
127
|
+
this._initialized = true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
131
|
+
const updaters = this.updaters.get(container);
|
|
132
|
+
if (!updaters) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
136
|
+
}
|
|
137
|
+
async register(...loaders) {
|
|
138
|
+
if (this._initialized) {
|
|
139
|
+
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
140
|
+
}
|
|
141
|
+
for (const loader of loaders) {
|
|
142
|
+
if (this._isRunningLoaders) {
|
|
143
|
+
await this._runLoader(loader, this._executedSet, this._allLoadersSet);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this._loadPromises.add(loader);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async _runLoader(loader, executed, allLoaders) {
|
|
151
|
+
if (executed.has(loader))
|
|
152
|
+
return;
|
|
153
|
+
executed.add(loader);
|
|
154
|
+
allLoaders.add(loader);
|
|
155
|
+
await loader(this._engine);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.PluginManager = PluginManager;
|
|
159
|
+
});
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
style;
|
|
41
41
|
zLayers;
|
|
42
42
|
_container;
|
|
43
|
-
|
|
44
|
-
constructor(
|
|
45
|
-
this.
|
|
43
|
+
_pluginManager;
|
|
44
|
+
constructor(pluginManager, container) {
|
|
45
|
+
this._pluginManager = pluginManager;
|
|
46
46
|
this._container = container;
|
|
47
47
|
this.autoPlay = true;
|
|
48
48
|
this.background = new Background_js_1.Background();
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
this.duration = 0;
|
|
55
55
|
this.fpsLimit = 120;
|
|
56
56
|
this.hdr = true;
|
|
57
|
-
this.particles = (0, OptionsUtils_js_1.loadParticlesOptions)(this.
|
|
57
|
+
this.particles = (0, OptionsUtils_js_1.loadParticlesOptions)(this._pluginManager, this._container);
|
|
58
58
|
this.pauseOnBlur = true;
|
|
59
59
|
this.pauseOnOutsideViewport = true;
|
|
60
60
|
this.resize = new ResizeEvent_js_1.ResizeEvent();
|
|
@@ -128,12 +128,12 @@
|
|
|
128
128
|
if (data.smooth !== undefined) {
|
|
129
129
|
this.smooth = data.smooth;
|
|
130
130
|
}
|
|
131
|
-
this.
|
|
131
|
+
this._pluginManager.plugins.forEach(plugin => {
|
|
132
132
|
plugin.loadOptions(this._container, this, data);
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
_importPalette = palette => {
|
|
136
|
-
const paletteData = this.
|
|
136
|
+
const paletteData = this._pluginManager.getPalette(palette);
|
|
137
137
|
if (!paletteData) {
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
});
|
|
165
165
|
};
|
|
166
166
|
_importPreset = preset => {
|
|
167
|
-
this.load(this.
|
|
167
|
+
this.load(this._pluginManager.getPreset(preset));
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
exports.Options = Options;
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
stroke;
|
|
37
37
|
zIndex;
|
|
38
38
|
_container;
|
|
39
|
-
|
|
40
|
-
constructor(
|
|
41
|
-
this.
|
|
39
|
+
_pluginManager;
|
|
40
|
+
constructor(pluginManager, container) {
|
|
41
|
+
this._pluginManager = pluginManager;
|
|
42
42
|
this._container = container;
|
|
43
43
|
this.bounce = new ParticlesBounce_js_1.ParticlesBounce();
|
|
44
44
|
this.effect = new Effect_js_1.Effect();
|
|
@@ -96,12 +96,12 @@
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
if (this._container) {
|
|
99
|
-
for (const plugin of this.
|
|
99
|
+
for (const plugin of this._pluginManager.plugins) {
|
|
100
100
|
if (plugin.loadParticlesOptions) {
|
|
101
101
|
plugin.loadParticlesOptions(this._container, this, data);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
const updaters = this.
|
|
104
|
+
const updaters = this._pluginManager.updaters.get(this._container);
|
|
105
105
|
if (updaters) {
|
|
106
106
|
for (const updater of updaters) {
|
|
107
107
|
if (updater.loadOptions) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/Utils/CanvasUtils.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
context.clearRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
|
|
38
38
|
}
|
|
39
39
|
function drawParticle(data) {
|
|
40
|
-
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container
|
|
40
|
+
const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = Constants_js_1.defaultZoom, drawPosition = {
|
|
41
41
|
x: pos.x,
|
|
42
42
|
y: pos.y,
|
|
43
43
|
};
|