@tsparticles/engine 3.1.0 → 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 +72 -71
- package/browser/Core/Canvas.js +85 -32
- package/browser/Core/Container.js +8 -7
- package/browser/Core/Engine.js +14 -15
- package/browser/Core/Particle.js +14 -15
- package/browser/Core/Particles.js +42 -35
- package/browser/Core/Utils/EventListeners.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +3 -2
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/browser/Utils/CanvasUtils.js +14 -14
- package/cjs/Core/Canvas.js +85 -32
- package/cjs/Core/Container.js +8 -7
- package/cjs/Core/Engine.js +37 -15
- package/cjs/Core/Particle.js +14 -15
- package/cjs/Core/Particles.js +65 -35
- package/cjs/Core/Utils/EventListeners.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +3 -2
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/cjs/Utils/CanvasUtils.js +14 -14
- package/dist_browser_Core_Container_js.js +92 -0
- package/dist_browser_Core_Particle_js.js +32 -0
- package/esm/Core/Canvas.js +85 -32
- package/esm/Core/Container.js +8 -7
- package/esm/Core/Engine.js +14 -15
- package/esm/Core/Particle.js +14 -15
- package/esm/Core/Particles.js +42 -35
- package/esm/Core/Utils/EventListeners.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +3 -2
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/esm/Utils/CanvasUtils.js +14 -14
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +894 -5820
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +5 -3
- package/types/Core/Container.d.ts +1 -1
- package/types/Core/Engine.d.ts +13 -8
- package/types/Core/Interfaces/IContainerPlugin.d.ts +3 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
- package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IPlugin.d.ts +1 -1
- package/types/Core/Interfaces/IShapeDrawer.d.ts +4 -4
- package/types/Core/Particle.d.ts +3 -3
- package/types/Core/Particles.d.ts +12 -8
- package/types/Core/Utils/InteractionManager.d.ts +2 -2
- package/types/Enums/Modes/OutMode.d.ts +0 -3
- package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +2 -1
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +6 -6
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMask.d.ts +2 -1
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.d.ts +2 -1
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IOutModes.d.ts +6 -6
- package/types/Utils/CanvasUtils.d.ts +6 -6
- package/umd/Core/Canvas.js +85 -32
- package/umd/Core/Container.js +8 -7
- package/umd/Core/Engine.js +39 -16
- package/umd/Core/Particle.js +14 -15
- package/umd/Core/Particles.js +67 -36
- package/umd/Core/Utils/EventListeners.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +3 -2
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/umd/Utils/CanvasUtils.js +14 -14
|
@@ -6,12 +6,12 @@ export declare class InteractionManager {
|
|
|
6
6
|
private readonly container;
|
|
7
7
|
private readonly _engine;
|
|
8
8
|
private _externalInteractors;
|
|
9
|
-
private
|
|
9
|
+
private _interactors;
|
|
10
10
|
private _particleInteractors;
|
|
11
11
|
constructor(engine: Engine, container: Container);
|
|
12
12
|
externalInteract(delta: IDelta): Promise<void>;
|
|
13
13
|
handleClickMode(mode: string): void;
|
|
14
|
-
init(): void
|
|
14
|
+
init(): Promise<void>;
|
|
15
15
|
particlesInteract(particle: Particle, delta: IDelta): Promise<void>;
|
|
16
16
|
reset(particle: Particle): void;
|
|
17
17
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
export declare const enum OutMode {
|
|
2
2
|
bounce = "bounce",
|
|
3
|
-
bounceHorizontal = "bounce-horizontal",
|
|
4
|
-
bounceVertical = "bounce-vertical",
|
|
5
3
|
none = "none",
|
|
6
4
|
out = "out",
|
|
7
5
|
destroy = "destroy",
|
|
8
6
|
split = "split"
|
|
9
7
|
}
|
|
10
|
-
export type OutModeAlt = "bounce-horizontal" | "bounce-vertical";
|
|
@@ -3,7 +3,8 @@ import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
|
|
|
3
3
|
import { OptionsColor } from "../OptionsColor.js";
|
|
4
4
|
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
|
|
5
5
|
export declare class BackgroundMaskCover implements IBackgroundMaskCover, IOptionLoader<IBackgroundMaskCover> {
|
|
6
|
-
color
|
|
6
|
+
color?: OptionsColor;
|
|
7
|
+
image?: string;
|
|
7
8
|
opacity: number;
|
|
8
9
|
constructor();
|
|
9
10
|
load(data?: RecursivePartial<IBackgroundMaskCover> | undefined): void;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { OutMode, type OutModeAlt } from "../../../../Enums/Modes/OutMode.js";
|
|
2
1
|
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader.js";
|
|
3
2
|
import type { IOutModes } from "../../../Interfaces/Particles/Move/IOutModes.js";
|
|
3
|
+
import { OutMode } from "../../../../Enums/Modes/OutMode.js";
|
|
4
4
|
import type { RecursivePartial } from "../../../../Types/RecursivePartial.js";
|
|
5
5
|
export declare class OutModes implements IOutModes, IOptionLoader<IOutModes> {
|
|
6
|
-
bottom?: OutMode | keyof typeof OutMode
|
|
7
|
-
default: OutMode | keyof typeof OutMode
|
|
8
|
-
left?: OutMode | keyof typeof OutMode
|
|
9
|
-
right?: OutMode | keyof typeof OutMode
|
|
10
|
-
top?: OutMode | keyof typeof OutMode
|
|
6
|
+
bottom?: OutMode | keyof typeof OutMode;
|
|
7
|
+
default: OutMode | keyof typeof OutMode;
|
|
8
|
+
left?: OutMode | keyof typeof OutMode;
|
|
9
|
+
right?: OutMode | keyof typeof OutMode;
|
|
10
|
+
top?: OutMode | keyof typeof OutMode;
|
|
11
11
|
constructor();
|
|
12
12
|
load(data?: RecursivePartial<IOutModes>): void;
|
|
13
13
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { IBackgroundMaskCover } from "./IBackgroundMaskCover.js";
|
|
2
2
|
import type { IColor } from "../../../Core/Interfaces/Colors.js";
|
|
3
|
+
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
|
|
3
4
|
export interface IBackgroundMask {
|
|
4
5
|
composite: GlobalCompositeOperation;
|
|
5
|
-
cover: IBackgroundMaskCover | IColor | string;
|
|
6
|
+
cover: RecursivePartial<IBackgroundMaskCover> | IColor | string;
|
|
6
7
|
enable: boolean;
|
|
7
8
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { MoveDirection, MoveDirectionAlt } from "../../../../Enums/Directions/MoveDirection.js";
|
|
2
|
-
import type { OutMode, OutModeAlt } from "../../../../Enums/Modes/OutMode.js";
|
|
3
2
|
import type { IDistance } from "../../../../Core/Interfaces/IDistance.js";
|
|
4
3
|
import type { IMoveAngle } from "./IMoveAngle.js";
|
|
5
4
|
import type { IMoveAttract } from "./IMoveAttract.js";
|
|
@@ -9,6 +8,7 @@ import type { IMovePath } from "./Path/IMovePath.js";
|
|
|
9
8
|
import type { IMoveTrail } from "./IMoveTrail.js";
|
|
10
9
|
import type { IOutModes } from "./IOutModes.js";
|
|
11
10
|
import type { ISpin } from "./ISpin.js";
|
|
11
|
+
import type { OutMode } from "../../../../Enums/Modes/OutMode.js";
|
|
12
12
|
import type { RangeValue } from "../../../../Types/RangeValue.js";
|
|
13
13
|
export interface IMove {
|
|
14
14
|
angle: number | IMoveAngle;
|
|
@@ -20,7 +20,7 @@ export interface IMove {
|
|
|
20
20
|
drift: RangeValue;
|
|
21
21
|
enable: boolean;
|
|
22
22
|
gravity: IMoveGravity;
|
|
23
|
-
outModes: IOutModes | OutMode | keyof typeof OutMode
|
|
23
|
+
outModes: IOutModes | OutMode | keyof typeof OutMode;
|
|
24
24
|
path: IMovePath;
|
|
25
25
|
random: boolean;
|
|
26
26
|
size: boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { OutMode
|
|
1
|
+
import type { OutMode } from "../../../../Enums/Modes/OutMode.js";
|
|
2
2
|
export interface IOutModes {
|
|
3
|
-
bottom?: OutMode | keyof typeof OutMode
|
|
4
|
-
default: OutMode | keyof typeof OutMode
|
|
5
|
-
left?: OutMode | keyof typeof OutMode
|
|
6
|
-
right?: OutMode | keyof typeof OutMode
|
|
7
|
-
top?: OutMode | keyof typeof OutMode
|
|
3
|
+
bottom?: OutMode | keyof typeof OutMode;
|
|
4
|
+
default: OutMode | keyof typeof OutMode;
|
|
5
|
+
left?: OutMode | keyof typeof OutMode;
|
|
6
|
+
right?: OutMode | keyof typeof OutMode;
|
|
7
|
+
top?: OutMode | keyof typeof OutMode;
|
|
8
8
|
}
|
|
@@ -11,7 +11,7 @@ export declare function drawLine(context: CanvasRenderingContext2D, begin: ICoor
|
|
|
11
11
|
export declare function paintBase(context: CanvasRenderingContext2D, dimension: IDimension, baseColor?: string): void;
|
|
12
12
|
export declare function paintImage(context: CanvasRenderingContext2D, dimension: IDimension, image: HTMLImageElement | undefined, opacity: number): void;
|
|
13
13
|
export declare function clear(context: CanvasRenderingContext2D, dimension: IDimension): void;
|
|
14
|
-
export declare function drawParticle(data: IDrawParticleParams): void
|
|
14
|
+
export declare function drawParticle(data: IDrawParticleParams): Promise<void>;
|
|
15
15
|
interface DrawShapeData {
|
|
16
16
|
container: Container;
|
|
17
17
|
context: CanvasRenderingContext2D;
|
|
@@ -27,10 +27,10 @@ interface DrawShapeData {
|
|
|
27
27
|
d: number;
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
export declare function drawEffect(data: DrawShapeData): void
|
|
31
|
-
export declare function drawShape(data: DrawShapeData): void
|
|
32
|
-
export declare function drawShapeAfterDraw(data: DrawShapeData): void
|
|
33
|
-
export declare function drawPlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, delta: IDelta): void
|
|
34
|
-
export declare function drawParticlePlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, particle: Particle, delta: IDelta): void
|
|
30
|
+
export declare function drawEffect(data: DrawShapeData): Promise<void>;
|
|
31
|
+
export declare function drawShape(data: DrawShapeData): Promise<void>;
|
|
32
|
+
export declare function drawShapeAfterDraw(data: DrawShapeData): Promise<void>;
|
|
33
|
+
export declare function drawPlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, delta: IDelta): Promise<void>;
|
|
34
|
+
export declare function drawParticlePlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, particle: Particle, delta: IDelta): Promise<void>;
|
|
35
35
|
export declare function alterHsl(color: IHsl, type: AlterType, value: number): IHsl;
|
|
36
36
|
export {};
|
package/umd/Core/Canvas.js
CHANGED
|
@@ -20,6 +20,26 @@
|
|
|
20
20
|
factor[key] = (factor[key] ?? defaultValue) * newValue;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
function setStyle(canvas, style, important = false) {
|
|
24
|
+
if (!style) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const element = canvas;
|
|
28
|
+
if (!element) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const elementStyle = element.style;
|
|
32
|
+
if (!elementStyle) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const key in style) {
|
|
36
|
+
const value = style[key];
|
|
37
|
+
if (!value) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
23
43
|
class Canvas {
|
|
24
44
|
constructor(container) {
|
|
25
45
|
this.container = container;
|
|
@@ -68,14 +88,36 @@
|
|
|
68
88
|
}
|
|
69
89
|
return [fColor, sColor];
|
|
70
90
|
};
|
|
71
|
-
this._initCover = () => {
|
|
72
|
-
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
this._initCover = async () => {
|
|
92
|
+
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color;
|
|
93
|
+
if (color) {
|
|
94
|
+
const coverRgb = (0, ColorUtils_js_1.rangeColorToRgb)(color);
|
|
95
|
+
if (coverRgb) {
|
|
96
|
+
const coverColor = {
|
|
97
|
+
...coverRgb,
|
|
98
|
+
a: cover.opacity,
|
|
99
|
+
};
|
|
100
|
+
this._coverColorStyle = (0, ColorUtils_js_1.getStyleFromRgb)(coverColor, coverColor.a);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
if (!cover.image) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const img = document.createElement("img");
|
|
109
|
+
img.addEventListener("load", () => {
|
|
110
|
+
this._coverImage = {
|
|
111
|
+
image: img,
|
|
112
|
+
opacity: cover.opacity,
|
|
113
|
+
};
|
|
114
|
+
resolve();
|
|
115
|
+
});
|
|
116
|
+
img.addEventListener("error", (evt) => {
|
|
117
|
+
reject(evt.error);
|
|
118
|
+
});
|
|
119
|
+
img.src = cover.image;
|
|
120
|
+
});
|
|
79
121
|
}
|
|
80
122
|
};
|
|
81
123
|
this._initStyle = () => {
|
|
@@ -160,13 +202,7 @@
|
|
|
160
202
|
if (!(element && originalStyle)) {
|
|
161
203
|
return;
|
|
162
204
|
}
|
|
163
|
-
|
|
164
|
-
style.position = originalStyle.position;
|
|
165
|
-
style.zIndex = originalStyle.zIndex;
|
|
166
|
-
style.top = originalStyle.top;
|
|
167
|
-
style.left = originalStyle.left;
|
|
168
|
-
style.width = originalStyle.width;
|
|
169
|
-
style.height = originalStyle.height;
|
|
205
|
+
setStyle(element, originalStyle);
|
|
170
206
|
};
|
|
171
207
|
this._safeMutationObserver = (callback) => {
|
|
172
208
|
if (!this._mutationObserver) {
|
|
@@ -179,13 +215,15 @@
|
|
|
179
215
|
if (!element) {
|
|
180
216
|
return;
|
|
181
217
|
}
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
218
|
+
const radix = 10;
|
|
219
|
+
setStyle(element, {
|
|
220
|
+
position: "fixed",
|
|
221
|
+
zIndex: this.container.actualOptions.fullScreen.zIndex.toString(radix),
|
|
222
|
+
top: "0",
|
|
223
|
+
left: "0",
|
|
224
|
+
width: "100%",
|
|
225
|
+
height: "100%",
|
|
226
|
+
}, true);
|
|
189
227
|
};
|
|
190
228
|
this.size = {
|
|
191
229
|
height: 0,
|
|
@@ -241,7 +279,14 @@
|
|
|
241
279
|
}
|
|
242
280
|
return cb(ctx);
|
|
243
281
|
}
|
|
244
|
-
|
|
282
|
+
drawAsync(cb) {
|
|
283
|
+
const ctx = this._context;
|
|
284
|
+
if (!ctx) {
|
|
285
|
+
return Promise.resolve(undefined);
|
|
286
|
+
}
|
|
287
|
+
return cb(ctx);
|
|
288
|
+
}
|
|
289
|
+
async drawParticle(particle, delta) {
|
|
245
290
|
if (particle.spawning || particle.destroyed) {
|
|
246
291
|
return;
|
|
247
292
|
}
|
|
@@ -260,13 +305,13 @@
|
|
|
260
305
|
if (!fColor && !sColor) {
|
|
261
306
|
return;
|
|
262
307
|
}
|
|
263
|
-
this.
|
|
308
|
+
await this.drawAsync(async (ctx) => {
|
|
264
309
|
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
265
310
|
fill: fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, zOpacity) : undefined,
|
|
266
311
|
};
|
|
267
312
|
colorStyles.stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, zStrokeOpacity) : colorStyles.fill;
|
|
268
313
|
this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
|
|
269
|
-
(0, CanvasUtils_js_1.drawParticle)({
|
|
314
|
+
await (0, CanvasUtils_js_1.drawParticle)({
|
|
270
315
|
container,
|
|
271
316
|
context: ctx,
|
|
272
317
|
particle,
|
|
@@ -282,11 +327,11 @@
|
|
|
282
327
|
this._applyPostDrawUpdaters(particle);
|
|
283
328
|
});
|
|
284
329
|
}
|
|
285
|
-
drawParticlePlugin(plugin, particle, delta) {
|
|
286
|
-
this.
|
|
330
|
+
async drawParticlePlugin(plugin, particle, delta) {
|
|
331
|
+
await this.drawAsync((ctx) => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
|
|
287
332
|
}
|
|
288
|
-
drawPlugin(plugin, delta) {
|
|
289
|
-
this.
|
|
333
|
+
async drawPlugin(plugin, delta) {
|
|
334
|
+
await this.drawAsync((ctx) => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
|
|
290
335
|
}
|
|
291
336
|
async init() {
|
|
292
337
|
this._safeMutationObserver((obs) => obs.disconnect());
|
|
@@ -299,7 +344,7 @@
|
|
|
299
344
|
});
|
|
300
345
|
this.resize();
|
|
301
346
|
this._initStyle();
|
|
302
|
-
this._initCover();
|
|
347
|
+
await this._initCover();
|
|
303
348
|
try {
|
|
304
349
|
await this._initTrail();
|
|
305
350
|
}
|
|
@@ -389,7 +434,15 @@
|
|
|
389
434
|
this.draw((ctx) => {
|
|
390
435
|
if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
|
391
436
|
(0, CanvasUtils_js_1.clear)(ctx, this.size);
|
|
392
|
-
|
|
437
|
+
if (this._coverImage) {
|
|
438
|
+
this._paintImage(this._coverImage.image, this._coverImage.opacity);
|
|
439
|
+
}
|
|
440
|
+
else if (this._coverColorStyle) {
|
|
441
|
+
this._paintBase(this._coverColorStyle);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
this._paintBase();
|
|
445
|
+
}
|
|
393
446
|
}
|
|
394
447
|
else {
|
|
395
448
|
this._paintBase();
|
|
@@ -431,7 +484,7 @@
|
|
|
431
484
|
return;
|
|
432
485
|
}
|
|
433
486
|
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
434
|
-
container.particles.setDensity();
|
|
487
|
+
await container.particles.setDensity();
|
|
435
488
|
this._applyResizePlugins();
|
|
436
489
|
if (needsRefresh) {
|
|
437
490
|
await container.refresh();
|
package/umd/Core/Container.js
CHANGED
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
this.destroy();
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
if (this.
|
|
76
|
+
if (this.animationStatus) {
|
|
77
77
|
this.draw(false);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -116,6 +116,9 @@
|
|
|
116
116
|
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)((entries) => this._intersectionManager(entries));
|
|
117
117
|
this._engine.dispatchEvent("containerBuilt", { container: this });
|
|
118
118
|
}
|
|
119
|
+
get animationStatus() {
|
|
120
|
+
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
121
|
+
}
|
|
119
122
|
get options() {
|
|
120
123
|
return this._options;
|
|
121
124
|
}
|
|
@@ -268,9 +271,6 @@
|
|
|
268
271
|
}
|
|
269
272
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} - Export plugin with type ${type} not found`);
|
|
270
273
|
}
|
|
271
|
-
getAnimationStatus() {
|
|
272
|
-
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
273
|
-
}
|
|
274
274
|
handleClickMode(mode) {
|
|
275
275
|
if (!guardCheck(this)) {
|
|
276
276
|
return;
|
|
@@ -298,9 +298,10 @@
|
|
|
298
298
|
this.shapeDrawers.set(type, drawer);
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
+
await this.particles.initPlugins();
|
|
301
302
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
302
303
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
303
|
-
const availablePlugins = this._engine.getAvailablePlugins(this);
|
|
304
|
+
const availablePlugins = await this._engine.getAvailablePlugins(this);
|
|
304
305
|
for (const [id, plugin] of availablePlugins) {
|
|
305
306
|
this.plugins.set(id, plugin);
|
|
306
307
|
}
|
|
@@ -326,8 +327,8 @@
|
|
|
326
327
|
await plugin.init?.();
|
|
327
328
|
}
|
|
328
329
|
this._engine.dispatchEvent("containerInit", { container: this });
|
|
329
|
-
this.particles.init();
|
|
330
|
-
this.particles.setDensity();
|
|
330
|
+
await this.particles.init();
|
|
331
|
+
await this.particles.setDensity();
|
|
331
332
|
for (const [, plugin] of this.plugins) {
|
|
332
333
|
plugin.particlesSetup?.();
|
|
333
334
|
}
|
package/umd/Core/Engine.js
CHANGED
|
@@ -1,24 +1,47 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
1
24
|
(function (factory) {
|
|
2
25
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
26
|
var v = factory(require, exports);
|
|
4
27
|
if (v !== undefined) module.exports = v;
|
|
5
28
|
}
|
|
6
29
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "
|
|
30
|
+
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/EventDispatcher.js", "../Utils/NumberUtils.js"], factory);
|
|
8
31
|
}
|
|
9
32
|
})(function (require, exports) {
|
|
10
33
|
"use strict";
|
|
34
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.Engine = void 0;
|
|
13
37
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
14
38
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
15
|
-
const Container_js_1 = require("./Container.js");
|
|
16
39
|
const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
|
|
17
40
|
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
18
|
-
function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
41
|
+
async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
19
42
|
let res = map.get(container);
|
|
20
43
|
if (!res || force) {
|
|
21
|
-
res = [...initializers.values()].map((t) => t(container));
|
|
44
|
+
res = await Promise.all([...initializers.values()].map((t) => t(container)));
|
|
22
45
|
map.set(container, res);
|
|
23
46
|
}
|
|
24
47
|
return res;
|
|
@@ -30,7 +53,7 @@
|
|
|
30
53
|
}
|
|
31
54
|
const response = await fetch(url);
|
|
32
55
|
if (response.ok) {
|
|
33
|
-
return response.json();
|
|
56
|
+
return (await response.json());
|
|
34
57
|
}
|
|
35
58
|
(0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
|
|
36
59
|
return data.fallback;
|
|
@@ -63,7 +86,7 @@
|
|
|
63
86
|
return res;
|
|
64
87
|
}
|
|
65
88
|
get version() {
|
|
66
|
-
return "3.
|
|
89
|
+
return "3.2.0";
|
|
67
90
|
}
|
|
68
91
|
addConfig(config) {
|
|
69
92
|
const key = config.key ?? config.name ?? "default";
|
|
@@ -139,11 +162,11 @@
|
|
|
139
162
|
}
|
|
140
163
|
return item;
|
|
141
164
|
}
|
|
142
|
-
getAvailablePlugins(container) {
|
|
165
|
+
async getAvailablePlugins(container) {
|
|
143
166
|
const res = new Map();
|
|
144
167
|
for (const plugin of this.plugins) {
|
|
145
168
|
if (plugin.needsPlugin(container.actualOptions)) {
|
|
146
|
-
res.set(plugin.id, plugin.getPlugin(container));
|
|
169
|
+
res.set(plugin.id, await plugin.getPlugin(container));
|
|
147
170
|
}
|
|
148
171
|
}
|
|
149
172
|
return res;
|
|
@@ -151,11 +174,11 @@
|
|
|
151
174
|
getEffectDrawer(type) {
|
|
152
175
|
return this.effectDrawers.get(type);
|
|
153
176
|
}
|
|
154
|
-
getInteractors(container, force = false) {
|
|
155
|
-
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
177
|
+
async getInteractors(container, force = false) {
|
|
178
|
+
return await getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
156
179
|
}
|
|
157
|
-
getMovers(container, force = false) {
|
|
158
|
-
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
180
|
+
async getMovers(container, force = false) {
|
|
181
|
+
return await getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
159
182
|
}
|
|
160
183
|
getPathGenerator(type) {
|
|
161
184
|
return this.pathGenerators.get(type);
|
|
@@ -175,8 +198,8 @@
|
|
|
175
198
|
getSupportedShapes() {
|
|
176
199
|
return this.shapeDrawers.keys();
|
|
177
200
|
}
|
|
178
|
-
getUpdaters(container, force = false) {
|
|
179
|
-
return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
201
|
+
async getUpdaters(container, force = false) {
|
|
202
|
+
return await getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
|
180
203
|
}
|
|
181
204
|
init() {
|
|
182
205
|
if (this._initialized) {
|
|
@@ -225,7 +248,7 @@
|
|
|
225
248
|
if (!canvasEl.style.height) {
|
|
226
249
|
canvasEl.style.height = "100%";
|
|
227
250
|
}
|
|
228
|
-
const newItem = new
|
|
251
|
+
const { Container } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Container.js"))) : new Promise((resolve_1, reject_1) => { require(["./Container.js"], resolve_1, reject_1); }).then(__importStar)), newItem = new Container(this, id, currentOptions);
|
|
229
252
|
if (oldIndex >= minIndex) {
|
|
230
253
|
const deleteCount = 0;
|
|
231
254
|
dom.splice(oldIndex, deleteCount, newItem);
|
|
@@ -255,7 +278,7 @@
|
|
|
255
278
|
if (!refresh) {
|
|
256
279
|
return;
|
|
257
280
|
}
|
|
258
|
-
await Promise.
|
|
281
|
+
await Promise.all(this.dom().map((t) => t.refresh()));
|
|
259
282
|
}
|
|
260
283
|
removeEventListener(type, listener) {
|
|
261
284
|
this._eventDispatcher.removeEventListener(type, listener);
|
package/umd/Core/Particle.js
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
class Particle {
|
|
56
|
-
constructor(engine,
|
|
56
|
+
constructor(engine, container) {
|
|
57
57
|
this.container = container;
|
|
58
58
|
this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
|
|
59
59
|
for (const [, plugin] of container.plugins) {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
}), pos = Vector3d_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
|
|
69
69
|
fixOutMode({
|
|
70
70
|
outMode,
|
|
71
|
-
checkModes: ["bounce"
|
|
71
|
+
checkModes: ["bounce"],
|
|
72
72
|
coord: pos.x,
|
|
73
73
|
maxCoord: container.canvas.size.width,
|
|
74
74
|
setCb: (value) => (pos.x += value),
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
}, fixVertical = (outMode) => {
|
|
78
78
|
fixOutMode({
|
|
79
79
|
outMode,
|
|
80
|
-
checkModes: ["bounce"
|
|
80
|
+
checkModes: ["bounce"],
|
|
81
81
|
coord: pos.y,
|
|
82
82
|
maxCoord: container.canvas.size.height,
|
|
83
83
|
setCb: (value) => (pos.y += value),
|
|
@@ -164,7 +164,6 @@
|
|
|
164
164
|
this.offset = Vector_js_1.Vector.origin;
|
|
165
165
|
};
|
|
166
166
|
this._engine = engine;
|
|
167
|
-
this.init(id, position, overrideOptions, group);
|
|
168
167
|
}
|
|
169
168
|
destroy(override) {
|
|
170
169
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -189,12 +188,12 @@
|
|
|
189
188
|
},
|
|
190
189
|
});
|
|
191
190
|
}
|
|
192
|
-
draw(delta) {
|
|
191
|
+
async draw(delta) {
|
|
193
192
|
const container = this.container, canvas = container.canvas;
|
|
194
193
|
for (const [, plugin] of container.plugins) {
|
|
195
|
-
canvas.drawParticlePlugin(plugin, this, delta);
|
|
194
|
+
await canvas.drawParticlePlugin(plugin, this, delta);
|
|
196
195
|
}
|
|
197
|
-
canvas.drawParticle(this, delta);
|
|
196
|
+
await canvas.drawParticle(this, delta);
|
|
198
197
|
}
|
|
199
198
|
getFillColor() {
|
|
200
199
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
|
|
@@ -215,7 +214,7 @@
|
|
|
215
214
|
getStrokeColor() {
|
|
216
215
|
return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.strokeColor));
|
|
217
216
|
}
|
|
218
|
-
init(id, position, overrideOptions, group) {
|
|
217
|
+
async init(id, position, overrideOptions, group) {
|
|
219
218
|
const container = this.container, engine = this._engine;
|
|
220
219
|
this.id = id;
|
|
221
220
|
this.group = group;
|
|
@@ -279,7 +278,7 @@
|
|
|
279
278
|
if (pathOptions.generator) {
|
|
280
279
|
this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);
|
|
281
280
|
if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
|
|
282
|
-
this.pathGenerator.init(container);
|
|
281
|
+
await this.pathGenerator.init(container);
|
|
283
282
|
}
|
|
284
283
|
}
|
|
285
284
|
container.retina.initParticle(this);
|
|
@@ -308,7 +307,7 @@
|
|
|
308
307
|
}
|
|
309
308
|
}
|
|
310
309
|
if (effectDrawer?.loadEffect) {
|
|
311
|
-
effectDrawer.loadEffect(this);
|
|
310
|
+
await effectDrawer.loadEffect(this);
|
|
312
311
|
}
|
|
313
312
|
let shapeDrawer = container.shapeDrawers.get(this.shape);
|
|
314
313
|
if (!shapeDrawer) {
|
|
@@ -318,7 +317,7 @@
|
|
|
318
317
|
}
|
|
319
318
|
}
|
|
320
319
|
if (shapeDrawer?.loadShape) {
|
|
321
|
-
shapeDrawer.loadShape(this);
|
|
320
|
+
await shapeDrawer.loadShape(this);
|
|
322
321
|
}
|
|
323
322
|
const sideCountFunc = shapeDrawer?.getSidesCount;
|
|
324
323
|
if (sideCountFunc) {
|
|
@@ -327,13 +326,13 @@
|
|
|
327
326
|
this.spawning = false;
|
|
328
327
|
this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this.options.shadow.color);
|
|
329
328
|
for (const updater of particles.updaters) {
|
|
330
|
-
updater.init(this);
|
|
329
|
+
await updater.init(this);
|
|
331
330
|
}
|
|
332
331
|
for (const mover of particles.movers) {
|
|
333
|
-
mover.init?.(this);
|
|
332
|
+
await mover.init?.(this);
|
|
334
333
|
}
|
|
335
|
-
effectDrawer?.particleInit?.(container, this);
|
|
336
|
-
shapeDrawer?.particleInit?.(container, this);
|
|
334
|
+
await effectDrawer?.particleInit?.(container, this);
|
|
335
|
+
await shapeDrawer?.particleInit?.(container, this);
|
|
337
336
|
for (const [, plugin] of container.plugins) {
|
|
338
337
|
plugin.particleCreated?.(this);
|
|
339
338
|
}
|