@tsparticles/engine 3.3.0 → 3.5.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/README.md +0 -4
- package/browser/Core/Canvas.js +27 -22
- package/browser/Core/Container.js +57 -44
- package/browser/Core/Engine.js +82 -74
- package/browser/Core/Particle.js +29 -15
- package/browser/Core/Particles.js +23 -24
- package/browser/Core/Utils/EventListeners.js +18 -17
- package/browser/Core/Utils/ExternalInteractorBase.js +2 -1
- package/browser/Core/Utils/InteractionManager.js +3 -2
- package/browser/Core/Utils/ParticlesInteractorBase.js +2 -1
- package/browser/Core/Utils/QuadTree.js +1 -1
- package/browser/Core/Utils/Ranges.js +5 -4
- package/browser/Enums/AnimationStatus.js +5 -1
- package/browser/Enums/Directions/MoveDirection.js +14 -1
- package/browser/Enums/Directions/OutModeDirection.js +7 -1
- package/browser/Enums/Directions/RotateDirection.js +6 -1
- package/browser/Enums/InteractivityDetect.js +6 -1
- package/browser/Enums/Modes/AnimationMode.js +7 -1
- package/browser/Enums/Modes/CollisionMode.js +6 -1
- package/browser/Enums/Modes/LimitMode.js +5 -1
- package/browser/Enums/Modes/OutMode.js +8 -1
- package/browser/Enums/Modes/PixelMode.js +5 -1
- package/browser/Enums/Modes/ResponsiveMode.js +5 -1
- package/browser/Enums/Modes/ThemeMode.js +6 -1
- package/browser/Enums/Types/AlterType.js +5 -1
- package/browser/Enums/Types/DestroyType.js +6 -1
- package/browser/Enums/Types/DivType.js +5 -1
- package/browser/Enums/Types/EasingType.js +30 -1
- package/browser/Enums/Types/EventType.js +15 -1
- package/browser/Enums/Types/GradientType.js +6 -1
- package/browser/Enums/Types/InteractorType.js +5 -1
- package/browser/Enums/Types/ParticleOutType.js +6 -1
- package/browser/Enums/Types/StartValueType.js +6 -1
- package/browser/Options/Classes/AnimationOptions.js +4 -2
- package/browser/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
- package/browser/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/browser/Options/Classes/Interactivity/Interactivity.js +2 -1
- package/browser/Options/Classes/ManualParticle.js +2 -1
- package/browser/Options/Classes/Options.js +14 -12
- package/browser/Options/Classes/Particles/Collisions/Collisions.js +2 -1
- package/browser/Options/Classes/Particles/Move/Move.js +2 -1
- package/browser/Options/Classes/Particles/Move/MoveCenter.js +2 -1
- package/browser/Options/Classes/Particles/Move/OutModes.js +2 -1
- package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
- package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
- package/browser/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/browser/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
- package/browser/Options/Classes/Responsive.js +5 -4
- package/browser/Options/Classes/Theme/ThemeDefault.js +2 -1
- package/browser/Types/RangeType.js +5 -1
- package/browser/Utils/CanvasUtils.js +13 -7
- package/browser/Utils/ColorUtils.js +17 -9
- package/browser/Utils/EventDispatcher.js +1 -1
- package/browser/Utils/HslColorManager.js +11 -4
- package/browser/Utils/NumberUtils.js +28 -14
- package/browser/Utils/RgbColorManager.js +11 -4
- package/browser/Utils/Utils.js +37 -31
- package/cjs/Core/Canvas.js +27 -22
- package/cjs/Core/Container.js +57 -44
- package/cjs/Core/Engine.js +82 -74
- package/cjs/Core/Particle.js +29 -15
- package/cjs/Core/Particles.js +23 -24
- package/cjs/Core/Utils/EventListeners.js +18 -17
- package/cjs/Core/Utils/ExternalInteractorBase.js +2 -1
- package/cjs/Core/Utils/InteractionManager.js +3 -2
- package/cjs/Core/Utils/ParticlesInteractorBase.js +2 -1
- package/cjs/Core/Utils/QuadTree.js +1 -1
- package/cjs/Core/Utils/Ranges.js +5 -4
- package/cjs/Enums/AnimationStatus.js +6 -0
- package/cjs/Enums/Directions/MoveDirection.js +15 -0
- package/cjs/Enums/Directions/OutModeDirection.js +8 -0
- package/cjs/Enums/Directions/RotateDirection.js +7 -0
- package/cjs/Enums/InteractivityDetect.js +7 -0
- package/cjs/Enums/Modes/AnimationMode.js +8 -0
- package/cjs/Enums/Modes/CollisionMode.js +7 -0
- package/cjs/Enums/Modes/LimitMode.js +6 -0
- package/cjs/Enums/Modes/OutMode.js +9 -0
- package/cjs/Enums/Modes/PixelMode.js +6 -0
- package/cjs/Enums/Modes/ResponsiveMode.js +6 -0
- package/cjs/Enums/Modes/ThemeMode.js +7 -0
- package/cjs/Enums/Types/AlterType.js +6 -0
- package/cjs/Enums/Types/DestroyType.js +7 -0
- package/cjs/Enums/Types/DivType.js +6 -0
- package/cjs/Enums/Types/EasingType.js +31 -0
- package/cjs/Enums/Types/EventType.js +16 -0
- package/cjs/Enums/Types/GradientType.js +7 -0
- package/cjs/Enums/Types/InteractorType.js +6 -0
- package/cjs/Enums/Types/ParticleOutType.js +7 -0
- package/cjs/Enums/Types/StartValueType.js +7 -0
- package/cjs/Options/Classes/AnimationOptions.js +4 -2
- package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
- package/cjs/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/cjs/Options/Classes/Interactivity/Interactivity.js +2 -1
- package/cjs/Options/Classes/ManualParticle.js +2 -1
- package/cjs/Options/Classes/Options.js +14 -12
- package/cjs/Options/Classes/Particles/Collisions/Collisions.js +2 -1
- package/cjs/Options/Classes/Particles/Move/Move.js +2 -1
- package/cjs/Options/Classes/Particles/Move/MoveCenter.js +2 -1
- package/cjs/Options/Classes/Particles/Move/OutModes.js +2 -1
- package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
- package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
- package/cjs/Options/Classes/Responsive.js +5 -4
- package/cjs/Options/Classes/Theme/ThemeDefault.js +2 -1
- package/cjs/Types/RangeType.js +6 -0
- package/cjs/Utils/CanvasUtils.js +24 -19
- package/cjs/Utils/ColorUtils.js +37 -30
- package/cjs/Utils/EventDispatcher.js +1 -1
- package/cjs/Utils/HslColorManager.js +11 -4
- package/cjs/Utils/NumberUtils.js +54 -38
- package/cjs/Utils/OptionsUtils.js +2 -3
- package/cjs/Utils/RgbColorManager.js +11 -4
- package/cjs/Utils/TypeUtils.js +6 -7
- package/cjs/Utils/Utils.js +66 -61
- package/cjs/init.js +1 -2
- package/esm/Core/Canvas.js +27 -22
- package/esm/Core/Container.js +57 -44
- package/esm/Core/Engine.js +82 -74
- package/esm/Core/Particle.js +29 -15
- package/esm/Core/Particles.js +23 -24
- package/esm/Core/Utils/EventListeners.js +18 -17
- package/esm/Core/Utils/ExternalInteractorBase.js +2 -1
- package/esm/Core/Utils/InteractionManager.js +3 -2
- package/esm/Core/Utils/ParticlesInteractorBase.js +2 -1
- package/esm/Core/Utils/QuadTree.js +1 -1
- package/esm/Core/Utils/Ranges.js +5 -4
- package/esm/Enums/AnimationStatus.js +5 -1
- package/esm/Enums/Directions/MoveDirection.js +14 -1
- package/esm/Enums/Directions/OutModeDirection.js +7 -1
- package/esm/Enums/Directions/RotateDirection.js +6 -1
- package/esm/Enums/InteractivityDetect.js +6 -1
- package/esm/Enums/Modes/AnimationMode.js +7 -1
- package/esm/Enums/Modes/CollisionMode.js +6 -1
- package/esm/Enums/Modes/LimitMode.js +5 -1
- package/esm/Enums/Modes/OutMode.js +8 -1
- package/esm/Enums/Modes/PixelMode.js +5 -1
- package/esm/Enums/Modes/ResponsiveMode.js +5 -1
- package/esm/Enums/Modes/ThemeMode.js +6 -1
- package/esm/Enums/Types/AlterType.js +5 -1
- package/esm/Enums/Types/DestroyType.js +6 -1
- package/esm/Enums/Types/DivType.js +5 -1
- package/esm/Enums/Types/EasingType.js +30 -1
- package/esm/Enums/Types/EventType.js +15 -1
- package/esm/Enums/Types/GradientType.js +6 -1
- package/esm/Enums/Types/InteractorType.js +5 -1
- package/esm/Enums/Types/ParticleOutType.js +6 -1
- package/esm/Enums/Types/StartValueType.js +6 -1
- package/esm/Options/Classes/AnimationOptions.js +4 -2
- package/esm/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
- package/esm/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/esm/Options/Classes/Interactivity/Interactivity.js +2 -1
- package/esm/Options/Classes/ManualParticle.js +2 -1
- package/esm/Options/Classes/Options.js +14 -12
- package/esm/Options/Classes/Particles/Collisions/Collisions.js +2 -1
- package/esm/Options/Classes/Particles/Move/Move.js +2 -1
- package/esm/Options/Classes/Particles/Move/MoveCenter.js +2 -1
- package/esm/Options/Classes/Particles/Move/OutModes.js +2 -1
- package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
- package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
- package/esm/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/esm/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
- package/esm/Options/Classes/Responsive.js +5 -4
- package/esm/Options/Classes/Theme/ThemeDefault.js +2 -1
- package/esm/Types/RangeType.js +5 -1
- package/esm/Utils/CanvasUtils.js +13 -7
- package/esm/Utils/ColorUtils.js +17 -9
- package/esm/Utils/EventDispatcher.js +1 -1
- package/esm/Utils/HslColorManager.js +11 -4
- package/esm/Utils/NumberUtils.js +28 -14
- package/esm/Utils/RgbColorManager.js +11 -4
- package/esm/Utils/Utils.js +37 -31
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +327 -225
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Container.d.ts +4 -2
- package/types/Core/Engine.d.ts +6 -5
- package/types/Core/Interfaces/IPlugin.d.ts +3 -4
- package/types/Core/Interfaces/IShapeDrawer.d.ts +1 -0
- package/types/Core/Particle.d.ts +1 -0
- package/types/Enums/AnimationStatus.d.ts +1 -1
- package/types/Enums/Directions/MoveDirection.d.ts +1 -1
- package/types/Enums/Directions/OutModeDirection.d.ts +1 -1
- package/types/Enums/Directions/RotateDirection.d.ts +1 -1
- package/types/Enums/InteractivityDetect.d.ts +1 -1
- package/types/Enums/Modes/AnimationMode.d.ts +1 -1
- package/types/Enums/Modes/CollisionMode.d.ts +1 -1
- package/types/Enums/Modes/LimitMode.d.ts +1 -1
- package/types/Enums/Modes/OutMode.d.ts +1 -1
- package/types/Enums/Modes/PixelMode.d.ts +1 -1
- package/types/Enums/Modes/ResponsiveMode.d.ts +1 -1
- package/types/Enums/Modes/ThemeMode.d.ts +1 -1
- package/types/Enums/Types/AlterType.d.ts +1 -1
- package/types/Enums/Types/DestroyType.d.ts +1 -1
- package/types/Enums/Types/DivType.d.ts +1 -1
- package/types/Enums/Types/EasingType.d.ts +1 -1
- package/types/Enums/Types/EventType.d.ts +1 -1
- package/types/Enums/Types/GradientType.d.ts +1 -1
- package/types/Enums/Types/InteractorType.d.ts +1 -1
- package/types/Enums/Types/ParticleOutType.d.ts +1 -1
- package/types/Enums/Types/StartValueType.d.ts +1 -1
- package/types/Options/Classes/Options.d.ts +2 -1
- package/types/Options/Classes/Responsive.d.ts +2 -2
- package/types/Options/Classes/Theme/Theme.d.ts +2 -2
- package/types/Options/Interfaces/IResponsive.d.ts +2 -3
- package/types/Options/Interfaces/Theme/ITheme.d.ts +2 -3
- package/types/Types/RangeType.d.ts +1 -1
- package/types/Utils/NumberUtils.d.ts +3 -0
- package/umd/Core/Canvas.js +27 -22
- package/umd/Core/Container.js +58 -45
- package/umd/Core/Engine.js +83 -99
- package/umd/Core/Particle.js +30 -16
- package/umd/Core/Particles.js +24 -25
- package/umd/Core/Utils/EventListeners.js +19 -18
- package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
- package/umd/Core/Utils/InteractionManager.js +4 -3
- package/umd/Core/Utils/ParticlesInteractorBase.js +3 -2
- package/umd/Core/Utils/QuadTree.js +1 -1
- package/umd/Core/Utils/Ranges.js +6 -5
- package/umd/Enums/AnimationStatus.js +6 -0
- package/umd/Enums/Directions/MoveDirection.js +15 -0
- package/umd/Enums/Directions/OutModeDirection.js +8 -0
- package/umd/Enums/Directions/RotateDirection.js +7 -0
- package/umd/Enums/InteractivityDetect.js +7 -0
- package/umd/Enums/Modes/AnimationMode.js +8 -0
- package/umd/Enums/Modes/CollisionMode.js +7 -0
- package/umd/Enums/Modes/LimitMode.js +6 -0
- package/umd/Enums/Modes/OutMode.js +9 -0
- package/umd/Enums/Modes/PixelMode.js +6 -0
- package/umd/Enums/Modes/ResponsiveMode.js +6 -0
- package/umd/Enums/Modes/ThemeMode.js +7 -0
- package/umd/Enums/Types/AlterType.js +6 -0
- package/umd/Enums/Types/DestroyType.js +7 -0
- package/umd/Enums/Types/DivType.js +6 -0
- package/umd/Enums/Types/EasingType.js +31 -0
- package/umd/Enums/Types/EventType.js +16 -0
- package/umd/Enums/Types/GradientType.js +7 -0
- package/umd/Enums/Types/InteractorType.js +6 -0
- package/umd/Enums/Types/ParticleOutType.js +7 -0
- package/umd/Enums/Types/StartValueType.js +7 -0
- package/umd/Options/Classes/AnimationOptions.js +5 -3
- package/umd/Options/Classes/Interactivity/Events/DivEvent.js +3 -2
- package/umd/Options/Classes/Interactivity/Events/Events.js +1 -1
- package/umd/Options/Classes/Interactivity/Interactivity.js +3 -2
- package/umd/Options/Classes/ManualParticle.js +3 -2
- package/umd/Options/Classes/Options.js +15 -13
- package/umd/Options/Classes/Particles/Collisions/Collisions.js +3 -2
- package/umd/Options/Classes/Particles/Move/Move.js +3 -2
- package/umd/Options/Classes/Particles/Move/MoveCenter.js +3 -2
- package/umd/Options/Classes/Particles/Move/OutModes.js +3 -2
- package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +3 -2
- package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +3 -2
- package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -1
- package/umd/Options/Classes/Particles/Size/SizeAnimation.js +3 -2
- package/umd/Options/Classes/Responsive.js +6 -5
- package/umd/Options/Classes/Theme/ThemeDefault.js +3 -2
- package/umd/Types/RangeType.js +6 -0
- package/umd/Utils/CanvasUtils.js +25 -20
- package/umd/Utils/ColorUtils.js +38 -31
- package/umd/Utils/EventDispatcher.js +1 -1
- package/umd/Utils/HslColorManager.js +11 -4
- package/umd/Utils/NumberUtils.js +55 -39
- package/umd/Utils/OptionsUtils.js +2 -3
- package/umd/Utils/RgbColorManager.js +11 -4
- package/umd/Utils/TypeUtils.js +6 -7
- package/umd/Utils/Utils.js +67 -62
- package/umd/init.js +1 -2
- package/174.min.js +0 -2
- package/174.min.js.LICENSE.txt +0 -1
- package/dist_browser_Core_Container_js.js +0 -102
|
@@ -5,6 +5,7 @@ import type { Engine } from "../../Core/Engine.js";
|
|
|
5
5
|
import { FullScreen } from "./FullScreen/FullScreen.js";
|
|
6
6
|
import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
|
|
7
7
|
import type { IOptions } from "../Interfaces/IOptions.js";
|
|
8
|
+
import type { ISourceOptions } from "../../Types/ISourceOptions.js";
|
|
8
9
|
import { Interactivity } from "./Interactivity/Interactivity.js";
|
|
9
10
|
import { ManualParticle } from "./ManualParticle.js";
|
|
10
11
|
import type { RangeValue } from "../../Types/RangeValue.js";
|
|
@@ -44,7 +45,7 @@ export declare class Options implements IOptions, IOptionLoader<IOptions> {
|
|
|
44
45
|
private readonly _container;
|
|
45
46
|
private readonly _engine;
|
|
46
47
|
constructor(engine: Engine, container: Container);
|
|
47
|
-
load(data?:
|
|
48
|
+
load(data?: ISourceOptions): void;
|
|
48
49
|
setResponsive(width: number, pxRatio: number, defaultOptions: IOptions): number | undefined;
|
|
49
50
|
setTheme(name?: string): void;
|
|
50
51
|
private readonly _findDefaultTheme;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
|
|
2
|
-
import type { IOptions } from "../Interfaces/IOptions.js";
|
|
3
2
|
import type { IResponsive } from "../Interfaces/IResponsive.js";
|
|
3
|
+
import type { ISourceOptions } from "../../Types/ISourceOptions.js";
|
|
4
4
|
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
|
|
5
5
|
import { ResponsiveMode } from "../../Enums/Modes/ResponsiveMode.js";
|
|
6
6
|
export declare class Responsive implements IResponsive, IOptionLoader<IResponsive> {
|
|
7
7
|
maxWidth: number;
|
|
8
8
|
mode: ResponsiveMode | keyof typeof ResponsiveMode;
|
|
9
|
-
options:
|
|
9
|
+
options: ISourceOptions;
|
|
10
10
|
constructor();
|
|
11
11
|
load(data?: RecursivePartial<IResponsive>): void;
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ISourceOptions } from "../../../Types/ISourceOptions.js";
|
|
3
3
|
import type { ITheme } from "../../Interfaces/Theme/ITheme.js";
|
|
4
4
|
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
|
|
5
5
|
import { ThemeDefault } from "./ThemeDefault.js";
|
|
6
6
|
export declare class Theme implements ITheme, IOptionLoader<ITheme> {
|
|
7
7
|
readonly default: ThemeDefault;
|
|
8
8
|
name: string;
|
|
9
|
-
options?:
|
|
9
|
+
options?: ISourceOptions;
|
|
10
10
|
constructor();
|
|
11
11
|
load(data?: RecursivePartial<ITheme>): void;
|
|
12
12
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
|
|
1
|
+
import type { ISourceOptions } from "../../Types/ISourceOptions.js";
|
|
3
2
|
import type { ResponsiveMode } from "../../Enums/Modes/ResponsiveMode.js";
|
|
4
3
|
export interface IResponsive {
|
|
5
4
|
maxWidth: number;
|
|
6
5
|
mode: ResponsiveMode | keyof typeof ResponsiveMode;
|
|
7
|
-
options:
|
|
6
|
+
options: ISourceOptions;
|
|
8
7
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ISourceOptions } from "../../../Types/ISourceOptions.js";
|
|
2
2
|
import type { IThemeDefault } from "./IThemeDefault.js";
|
|
3
|
-
import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
|
|
4
3
|
export interface ITheme {
|
|
5
4
|
default: IThemeDefault;
|
|
6
5
|
name: string;
|
|
7
|
-
options?:
|
|
6
|
+
options?: ISourceOptions;
|
|
8
7
|
}
|
|
@@ -9,6 +9,9 @@ export declare function addEasing(name: EasingType | EasingTypeAlt, easing: Easi
|
|
|
9
9
|
export declare function getEasing(name: EasingType | EasingTypeAlt): EasingFunction;
|
|
10
10
|
export declare function setRandom(rnd?: () => number): void;
|
|
11
11
|
export declare function getRandom(): number;
|
|
12
|
+
export declare function setAnimationFunctions(nextFrame: (callback: FrameRequestCallback) => number, cancel: (handle: number) => void): void;
|
|
13
|
+
export declare function animate(fn: FrameRequestCallback): number;
|
|
14
|
+
export declare function cancelAnimation(handle: number): void;
|
|
12
15
|
export declare function clamp(num: number, min: number, max: number): number;
|
|
13
16
|
export declare function mix(comp1: number, comp2: number, weight1: number, weight2: number): number;
|
|
14
17
|
export declare function randomInRange(r: RangeValue): number;
|
package/umd/Core/Canvas.js
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
class Canvas {
|
|
44
44
|
constructor(container) {
|
|
45
45
|
this.container = container;
|
|
46
|
-
this._applyPostDrawUpdaters =
|
|
46
|
+
this._applyPostDrawUpdaters = particle => {
|
|
47
47
|
for (const updater of this._postDrawUpdaters) {
|
|
48
48
|
updater.afterDraw?.(particle);
|
|
49
49
|
}
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
plugin.resize?.();
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
this._getPluginParticleColors =
|
|
76
|
+
this._getPluginParticleColors = particle => {
|
|
77
77
|
let fColor, sColor;
|
|
78
78
|
for (const plugin of this._colorPlugins) {
|
|
79
79
|
if (!fColor && plugin.particleFillColor) {
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
};
|
|
114
114
|
resolve();
|
|
115
115
|
});
|
|
116
|
-
img.addEventListener("error",
|
|
116
|
+
img.addEventListener("error", evt => {
|
|
117
117
|
reject(evt.error);
|
|
118
118
|
});
|
|
119
119
|
img.src = cover.image;
|
|
@@ -174,28 +174,33 @@
|
|
|
174
174
|
};
|
|
175
175
|
resolve();
|
|
176
176
|
});
|
|
177
|
-
img.addEventListener("error",
|
|
177
|
+
img.addEventListener("error", evt => {
|
|
178
178
|
reject(evt.error);
|
|
179
179
|
});
|
|
180
180
|
img.src = trailFill.image;
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
|
-
this._paintBase =
|
|
185
|
-
this.draw(
|
|
184
|
+
this._paintBase = baseColor => {
|
|
185
|
+
this.draw(ctx => (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor));
|
|
186
186
|
};
|
|
187
187
|
this._paintImage = (image, opacity) => {
|
|
188
|
-
this.draw(
|
|
188
|
+
this.draw(ctx => (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity));
|
|
189
189
|
};
|
|
190
190
|
this._repairStyle = () => {
|
|
191
191
|
const element = this.element;
|
|
192
192
|
if (!element) {
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
this._safeMutationObserver(
|
|
195
|
+
this._safeMutationObserver(observer => observer.disconnect());
|
|
196
196
|
this._initStyle();
|
|
197
197
|
this.initBackground();
|
|
198
|
-
this._safeMutationObserver(
|
|
198
|
+
this._safeMutationObserver(observer => {
|
|
199
|
+
if (!element || !(element instanceof Node)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
observer.observe(element, { attributes: true });
|
|
203
|
+
});
|
|
199
204
|
};
|
|
200
205
|
this._resetOriginalStyle = () => {
|
|
201
206
|
const element = this.element, originalStyle = this._originalStyle;
|
|
@@ -204,7 +209,7 @@
|
|
|
204
209
|
}
|
|
205
210
|
setStyle(element, originalStyle);
|
|
206
211
|
};
|
|
207
|
-
this._safeMutationObserver =
|
|
212
|
+
this._safeMutationObserver = callback => {
|
|
208
213
|
if (!this._mutationObserver) {
|
|
209
214
|
return;
|
|
210
215
|
}
|
|
@@ -253,7 +258,7 @@
|
|
|
253
258
|
}
|
|
254
259
|
}
|
|
255
260
|
else if (options.clear) {
|
|
256
|
-
this.draw(
|
|
261
|
+
this.draw(ctx => {
|
|
257
262
|
(0, CanvasUtils_js_1.clear)(ctx, this.size);
|
|
258
263
|
});
|
|
259
264
|
}
|
|
@@ -328,14 +333,14 @@
|
|
|
328
333
|
});
|
|
329
334
|
}
|
|
330
335
|
drawParticlePlugin(plugin, particle, delta) {
|
|
331
|
-
this.draw(
|
|
336
|
+
this.draw(ctx => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
|
|
332
337
|
}
|
|
333
338
|
drawPlugin(plugin, delta) {
|
|
334
|
-
this.draw(
|
|
339
|
+
this.draw(ctx => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
|
|
335
340
|
}
|
|
336
341
|
async init() {
|
|
337
|
-
this._safeMutationObserver(
|
|
338
|
-
this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(
|
|
342
|
+
this._safeMutationObserver(obs => obs.disconnect());
|
|
343
|
+
this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(records => {
|
|
339
344
|
for (const record of records) {
|
|
340
345
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
341
346
|
this._repairStyle();
|
|
@@ -352,8 +357,8 @@
|
|
|
352
357
|
(0, Utils_js_1.getLogger)().error(e);
|
|
353
358
|
}
|
|
354
359
|
this.initBackground();
|
|
355
|
-
this._safeMutationObserver(
|
|
356
|
-
if (!this.element) {
|
|
360
|
+
this._safeMutationObserver(obs => {
|
|
361
|
+
if (!this.element || !(this.element instanceof Node)) {
|
|
357
362
|
return;
|
|
358
363
|
}
|
|
359
364
|
obs.observe(this.element, { attributes: true });
|
|
@@ -420,8 +425,8 @@
|
|
|
420
425
|
this.size.height = canvas.offsetHeight;
|
|
421
426
|
this.size.width = canvas.offsetWidth;
|
|
422
427
|
this._context = this.element.getContext("2d");
|
|
423
|
-
this._safeMutationObserver(
|
|
424
|
-
if (!this.element) {
|
|
428
|
+
this._safeMutationObserver(obs => {
|
|
429
|
+
if (!this.element || !(this.element instanceof Node)) {
|
|
425
430
|
return;
|
|
426
431
|
}
|
|
427
432
|
obs.observe(this.element, { attributes: true });
|
|
@@ -431,7 +436,7 @@
|
|
|
431
436
|
}
|
|
432
437
|
paint() {
|
|
433
438
|
const options = this.container.actualOptions;
|
|
434
|
-
this.draw(
|
|
439
|
+
this.draw(ctx => {
|
|
435
440
|
if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
|
436
441
|
(0, CanvasUtils_js_1.clear)(ctx, this.size);
|
|
437
442
|
if (this._coverImage) {
|
|
@@ -475,9 +480,9 @@
|
|
|
475
480
|
return true;
|
|
476
481
|
}
|
|
477
482
|
stop() {
|
|
478
|
-
this._safeMutationObserver(
|
|
483
|
+
this._safeMutationObserver(obs => obs.disconnect());
|
|
479
484
|
this._mutationObserver = undefined;
|
|
480
|
-
this.draw(
|
|
485
|
+
this.draw(ctx => (0, CanvasUtils_js_1.clear)(ctx, this.size));
|
|
481
486
|
}
|
|
482
487
|
async windowResize() {
|
|
483
488
|
if (!this.element || !this.resize()) {
|
package/umd/Core/Container.js
CHANGED
|
@@ -4,20 +4,21 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "./Canvas.js", "./Utils/EventListeners.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/
|
|
7
|
+
define(["require", "exports", "../Utils/NumberUtils.js", "./Utils/Constants.js", "../Utils/Utils.js", "./Canvas.js", "./Utils/EventListeners.js", "../Enums/Types/EventType.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/OptionsUtils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Container = void 0;
|
|
13
|
+
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
13
14
|
const Constants_js_1 = require("./Utils/Constants.js");
|
|
14
15
|
const Utils_js_1 = require("../Utils/Utils.js");
|
|
15
16
|
const Canvas_js_1 = require("./Canvas.js");
|
|
16
17
|
const EventListeners_js_1 = require("./Utils/EventListeners.js");
|
|
18
|
+
const EventType_js_1 = require("../Enums/Types/EventType.js");
|
|
17
19
|
const Options_js_1 = require("../Options/Classes/Options.js");
|
|
18
20
|
const Particles_js_1 = require("./Particles.js");
|
|
19
21
|
const Retina_js_1 = require("./Retina.js");
|
|
20
|
-
const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
|
|
21
22
|
const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
|
|
22
23
|
function guardCheck(container) {
|
|
23
24
|
return container && !container.destroyed;
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
}
|
|
37
38
|
class Container {
|
|
38
39
|
constructor(engine, id, sourceOptions) {
|
|
39
|
-
this._intersectionManager =
|
|
40
|
+
this._intersectionManager = entries => {
|
|
40
41
|
if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
@@ -95,6 +96,7 @@
|
|
|
95
96
|
this._lastFrameTime = 0;
|
|
96
97
|
this.zLayers = 100;
|
|
97
98
|
this.pageHidden = false;
|
|
99
|
+
this._clickHandlers = new Map();
|
|
98
100
|
this._sourceOptions = sourceOptions;
|
|
99
101
|
this._initialSourceOptions = sourceOptions;
|
|
100
102
|
this.retina = new Retina_js_1.Retina(this);
|
|
@@ -113,8 +115,8 @@
|
|
|
113
115
|
this._options = loadContainerOptions(this._engine, this);
|
|
114
116
|
this.actualOptions = loadContainerOptions(this._engine, this);
|
|
115
117
|
this._eventListeners = new EventListeners_js_1.EventListeners(this);
|
|
116
|
-
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(
|
|
117
|
-
this._engine.dispatchEvent(
|
|
118
|
+
this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(entries => this._intersectionManager(entries));
|
|
119
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerBuilt, { container: this });
|
|
118
120
|
}
|
|
119
121
|
get animationStatus() {
|
|
120
122
|
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
@@ -142,8 +144,7 @@
|
|
|
142
144
|
y: pos.y * pxRatio,
|
|
143
145
|
}, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
|
|
144
146
|
callback(e, particles);
|
|
145
|
-
}
|
|
146
|
-
const clickHandler = (e) => {
|
|
147
|
+
}, clickHandler = (e) => {
|
|
147
148
|
if (!guardCheck(this)) {
|
|
148
149
|
return;
|
|
149
150
|
}
|
|
@@ -152,27 +153,23 @@
|
|
|
152
153
|
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
153
154
|
}, radius = 1;
|
|
154
155
|
clickOrTouchHandler(e, pos, radius);
|
|
155
|
-
}
|
|
156
|
-
const touchStartHandler = () => {
|
|
156
|
+
}, touchStartHandler = () => {
|
|
157
157
|
if (!guardCheck(this)) {
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
touched = true;
|
|
161
161
|
touchMoved = false;
|
|
162
|
-
}
|
|
163
|
-
const touchMoveHandler = () => {
|
|
162
|
+
}, touchMoveHandler = () => {
|
|
164
163
|
if (!guardCheck(this)) {
|
|
165
164
|
return;
|
|
166
165
|
}
|
|
167
166
|
touchMoved = true;
|
|
168
|
-
}
|
|
169
|
-
const touchEndHandler = (e) => {
|
|
167
|
+
}, touchEndHandler = (e) => {
|
|
170
168
|
if (!guardCheck(this)) {
|
|
171
169
|
return;
|
|
172
170
|
}
|
|
173
171
|
if (touched && !touchMoved) {
|
|
174
|
-
const touchEvent = e;
|
|
175
|
-
const lengthOffset = 1;
|
|
172
|
+
const touchEvent = e, lengthOffset = 1;
|
|
176
173
|
let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
|
|
177
174
|
if (!lastTouch) {
|
|
178
175
|
lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
|
|
@@ -188,8 +185,7 @@
|
|
|
188
185
|
}
|
|
189
186
|
touched = false;
|
|
190
187
|
touchMoved = false;
|
|
191
|
-
}
|
|
192
|
-
const touchCancelHandler = () => {
|
|
188
|
+
}, touchCancelHandler = () => {
|
|
193
189
|
if (!guardCheck(this)) {
|
|
194
190
|
return;
|
|
195
191
|
}
|
|
@@ -197,11 +193,14 @@
|
|
|
197
193
|
touchMoved = false;
|
|
198
194
|
};
|
|
199
195
|
let touched = false, touchMoved = false;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
this._clickHandlers.set("click", clickHandler);
|
|
197
|
+
this._clickHandlers.set("touchstart", touchStartHandler);
|
|
198
|
+
this._clickHandlers.set("touchmove", touchMoveHandler);
|
|
199
|
+
this._clickHandlers.set("touchend", touchEndHandler);
|
|
200
|
+
this._clickHandlers.set("touchcancel", touchCancelHandler);
|
|
201
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
202
|
+
el.addEventListener(key, handler);
|
|
203
|
+
}
|
|
205
204
|
}
|
|
206
205
|
addLifeTime(value) {
|
|
207
206
|
this._lifeTime += value;
|
|
@@ -216,11 +215,21 @@
|
|
|
216
215
|
alive() {
|
|
217
216
|
return !this._duration || this._lifeTime <= this._duration;
|
|
218
217
|
}
|
|
219
|
-
|
|
218
|
+
clearClickHandlers() {
|
|
219
|
+
if (!guardCheck(this)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
223
|
+
this.interactivity.element?.removeEventListener(key, handler);
|
|
224
|
+
}
|
|
225
|
+
this._clickHandlers.clear();
|
|
226
|
+
}
|
|
227
|
+
destroy(remove = true) {
|
|
220
228
|
if (!guardCheck(this)) {
|
|
221
229
|
return;
|
|
222
230
|
}
|
|
223
231
|
this.stop();
|
|
232
|
+
this.clearClickHandlers();
|
|
224
233
|
this.particles.destroy();
|
|
225
234
|
this.canvas.destroy();
|
|
226
235
|
for (const [, effectDrawer] of this.effectDrawers) {
|
|
@@ -237,12 +246,14 @@
|
|
|
237
246
|
}
|
|
238
247
|
this._engine.clearPlugins(this);
|
|
239
248
|
this.destroyed = true;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
if (remove) {
|
|
250
|
+
const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
|
|
251
|
+
if (idx >= minIndex) {
|
|
252
|
+
const deleteCount = 1;
|
|
253
|
+
mainArr.splice(idx, deleteCount);
|
|
254
|
+
}
|
|
244
255
|
}
|
|
245
|
-
this._engine.dispatchEvent(
|
|
256
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerDestroyed, { container: this });
|
|
246
257
|
}
|
|
247
258
|
draw(force) {
|
|
248
259
|
if (!guardCheck(this)) {
|
|
@@ -256,7 +267,7 @@
|
|
|
256
267
|
}
|
|
257
268
|
this._nextFrame(timestamp);
|
|
258
269
|
};
|
|
259
|
-
this._drawAnimationFrame =
|
|
270
|
+
this._drawAnimationFrame = (0, NumberUtils_js_1.animate)(timestamp => frame(timestamp));
|
|
260
271
|
}
|
|
261
272
|
async export(type, options = {}) {
|
|
262
273
|
for (const [, plugin] of this.plugins) {
|
|
@@ -310,13 +321,14 @@
|
|
|
310
321
|
this.updateActualOptions();
|
|
311
322
|
this.canvas.initBackground();
|
|
312
323
|
this.canvas.resize();
|
|
313
|
-
|
|
314
|
-
this.
|
|
315
|
-
this.
|
|
324
|
+
const { zLayers, duration, delay, fpsLimit, smooth } = this.actualOptions;
|
|
325
|
+
this.zLayers = zLayers;
|
|
326
|
+
this._duration = (0, NumberUtils_js_1.getRangeValue)(duration) * Constants_js_1.millisecondsToSeconds;
|
|
327
|
+
this._delay = (0, NumberUtils_js_1.getRangeValue)(delay) * Constants_js_1.millisecondsToSeconds;
|
|
316
328
|
this._lifeTime = 0;
|
|
317
329
|
const defaultFpsLimit = 120, minFpsLimit = 0;
|
|
318
|
-
this.fpsLimit =
|
|
319
|
-
this._smooth =
|
|
330
|
+
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
331
|
+
this._smooth = smooth;
|
|
320
332
|
for (const [, drawer] of this.effectDrawers) {
|
|
321
333
|
await drawer.init?.(this);
|
|
322
334
|
}
|
|
@@ -326,13 +338,13 @@
|
|
|
326
338
|
for (const [, plugin] of this.plugins) {
|
|
327
339
|
await plugin.init?.();
|
|
328
340
|
}
|
|
329
|
-
this._engine.dispatchEvent(
|
|
341
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerInit, { container: this });
|
|
330
342
|
await this.particles.init();
|
|
331
343
|
this.particles.setDensity();
|
|
332
344
|
for (const [, plugin] of this.plugins) {
|
|
333
345
|
plugin.particlesSetup?.();
|
|
334
346
|
}
|
|
335
|
-
this._engine.dispatchEvent(
|
|
347
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.particlesSetup, { container: this });
|
|
336
348
|
}
|
|
337
349
|
async loadTheme(name) {
|
|
338
350
|
if (!guardCheck(this)) {
|
|
@@ -346,7 +358,7 @@
|
|
|
346
358
|
return;
|
|
347
359
|
}
|
|
348
360
|
if (this._drawAnimationFrame !== undefined) {
|
|
349
|
-
|
|
361
|
+
(0, NumberUtils_js_1.cancelAnimation)(this._drawAnimationFrame);
|
|
350
362
|
delete this._drawAnimationFrame;
|
|
351
363
|
}
|
|
352
364
|
if (this._paused) {
|
|
@@ -358,7 +370,7 @@
|
|
|
358
370
|
if (!this.pageHidden) {
|
|
359
371
|
this._paused = true;
|
|
360
372
|
}
|
|
361
|
-
this._engine.dispatchEvent(
|
|
373
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerPaused, { container: this });
|
|
362
374
|
}
|
|
363
375
|
play(force) {
|
|
364
376
|
if (!guardCheck(this)) {
|
|
@@ -379,7 +391,7 @@
|
|
|
379
391
|
}
|
|
380
392
|
}
|
|
381
393
|
}
|
|
382
|
-
this._engine.dispatchEvent(
|
|
394
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerPlay, { container: this });
|
|
383
395
|
this.draw(needsUpdate ?? false);
|
|
384
396
|
}
|
|
385
397
|
async refresh() {
|
|
@@ -389,12 +401,13 @@
|
|
|
389
401
|
this.stop();
|
|
390
402
|
return this.start();
|
|
391
403
|
}
|
|
392
|
-
async reset() {
|
|
404
|
+
async reset(sourceOptions) {
|
|
393
405
|
if (!guardCheck(this)) {
|
|
394
406
|
return;
|
|
395
407
|
}
|
|
396
|
-
this._initialSourceOptions =
|
|
397
|
-
this.
|
|
408
|
+
this._initialSourceOptions = sourceOptions;
|
|
409
|
+
this._sourceOptions = sourceOptions;
|
|
410
|
+
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
398
411
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
399
412
|
return this.refresh();
|
|
400
413
|
}
|
|
@@ -404,7 +417,7 @@
|
|
|
404
417
|
}
|
|
405
418
|
await this.init();
|
|
406
419
|
this.started = true;
|
|
407
|
-
await new Promise(
|
|
420
|
+
await new Promise(resolve => {
|
|
408
421
|
const start = async () => {
|
|
409
422
|
this._eventListeners.addListeners();
|
|
410
423
|
if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
|
@@ -413,7 +426,7 @@
|
|
|
413
426
|
for (const [, plugin] of this.plugins) {
|
|
414
427
|
await plugin.start?.();
|
|
415
428
|
}
|
|
416
|
-
this._engine.dispatchEvent(
|
|
429
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerStarted, { container: this });
|
|
417
430
|
this.play();
|
|
418
431
|
resolve();
|
|
419
432
|
};
|
|
@@ -444,7 +457,7 @@
|
|
|
444
457
|
this.plugins.delete(key);
|
|
445
458
|
}
|
|
446
459
|
this._sourceOptions = this._options;
|
|
447
|
-
this._engine.dispatchEvent(
|
|
460
|
+
this._engine.dispatchEvent(EventType_js_1.EventType.containerStopped, { container: this });
|
|
448
461
|
}
|
|
449
462
|
updateActualOptions() {
|
|
450
463
|
this.actualOptions.responsive = [];
|