@tsparticles/engine 4.0.0-alpha.2 → 4.0.0-alpha.4
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/794.min.js +2 -0
- package/794.min.js.LICENSE.txt +1 -0
- package/README.md +2 -5
- package/browser/Core/Canvas.js +18 -22
- package/browser/Core/Container.js +44 -169
- package/browser/Core/Engine.js +40 -61
- package/browser/Core/Particle.js +99 -58
- package/browser/Core/Particles.js +36 -25
- package/browser/Core/Utils/Constants.js +2 -2
- package/browser/Core/Utils/EventListeners.js +5 -250
- package/browser/Options/Classes/Options.js +7 -75
- package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -11
- package/{esm/Options/Classes/Interactivity/Events → browser/Options/Classes}/ResizeEvent.js +1 -1
- package/browser/Utils/CanvasUtils.js +26 -83
- package/browser/Utils/ColorUtils.js +17 -2
- package/browser/Utils/MathUtils.js +3 -2
- package/browser/Utils/Utils.js +26 -33
- package/browser/exports.js +1 -21
- package/cjs/Core/Canvas.js +18 -22
- package/cjs/Core/Container.js +44 -169
- package/cjs/Core/Engine.js +40 -61
- package/cjs/Core/Particle.js +99 -58
- package/cjs/Core/Particles.js +36 -25
- package/cjs/Core/Utils/Constants.js +2 -2
- package/cjs/Core/Utils/EventListeners.js +5 -250
- package/cjs/Options/Classes/Options.js +7 -75
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -11
- package/cjs/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +1 -1
- package/cjs/Utils/CanvasUtils.js +26 -83
- package/cjs/Utils/ColorUtils.js +17 -2
- package/cjs/Utils/MathUtils.js +3 -2
- package/cjs/Utils/Utils.js +26 -33
- package/cjs/exports.js +1 -21
- package/dist_browser_Core_Container_js.js +6 -16
- package/esm/Core/Canvas.js +18 -22
- package/esm/Core/Container.js +44 -169
- package/esm/Core/Engine.js +40 -61
- package/esm/Core/Particle.js +99 -58
- package/esm/Core/Particles.js +36 -25
- package/esm/Core/Utils/Constants.js +2 -2
- package/esm/Core/Utils/EventListeners.js +5 -250
- package/esm/Options/Classes/Options.js +7 -75
- package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -11
- package/{browser/Options/Classes/Interactivity/Events → esm/Options/Classes}/ResizeEvent.js +1 -1
- package/esm/Utils/CanvasUtils.js +26 -83
- package/esm/Utils/ColorUtils.js +17 -2
- package/esm/Utils/MathUtils.js +3 -2
- package/esm/Utils/Utils.js +26 -33
- package/esm/exports.js +1 -21
- package/package.json +1 -1
- package/report.html +1 -1
- package/tsparticles.engine.js +16 -208
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +3 -0
- package/types/Core/Container.d.ts +4 -15
- package/types/Core/Engine.d.ts +4 -19
- package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -1
- package/types/Core/Interfaces/IDrawParticleParams.d.ts +1 -1
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +4 -0
- package/types/Core/Interfaces/IParticleRotateData.d.ts +4 -0
- package/types/Core/Interfaces/IParticleTransformValues.d.ts +4 -4
- package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -1
- package/types/Core/Interfaces/IPlugin.d.ts +5 -1
- package/types/Core/Particle.d.ts +12 -2
- package/types/Core/Particles.d.ts +1 -5
- package/types/Core/Utils/Constants.d.ts +2 -2
- package/types/Core/Utils/EventListeners.d.ts +0 -14
- package/types/Options/Classes/Options.d.ts +2 -11
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +0 -2
- package/types/Options/Classes/ResizeEvent.d.ts +9 -0
- package/types/Options/Interfaces/IOptions.d.ts +2 -8
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -3
- package/types/Types/CustomEventListener.d.ts +1 -1
- package/types/Types/EngineInitializers.d.ts +10 -0
- package/types/Utils/CanvasUtils.d.ts +6 -21
- package/types/Utils/EventDispatcher.d.ts +1 -1
- package/types/Utils/Utils.d.ts +4 -6
- package/types/export-types.d.ts +3 -19
- package/types/exports.d.ts +1 -21
- package/umd/Core/Canvas.js +17 -21
- package/umd/Core/Container.js +44 -169
- package/umd/Core/Engine.js +41 -62
- package/umd/Core/Particle.js +99 -58
- package/umd/Core/Particles.js +37 -26
- package/umd/Core/Utils/Constants.js +3 -3
- package/umd/Core/Utils/EventListeners.js +7 -252
- package/umd/Options/Classes/Options.js +7 -75
- package/umd/Options/Classes/Particles/ParticlesOptions.js +5 -11
- package/umd/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +2 -2
- package/umd/Utils/CanvasUtils.js +25 -82
- package/umd/Utils/ColorUtils.js +17 -2
- package/umd/Utils/MathUtils.js +3 -2
- package/umd/Utils/Utils.js +27 -36
- package/umd/exports.js +2 -22
- package/638.min.js +0 -2
- package/638.min.js.LICENSE.txt +0 -1
- package/browser/Core/Utils/ExternalInteractorBase.js +0 -7
- package/browser/Core/Utils/InteractionManager.js +0 -60
- package/browser/Core/Utils/ParticlesInteractorBase.js +0 -7
- package/browser/Enums/InteractivityDetect.js +0 -6
- package/browser/Enums/Modes/ResponsiveMode.js +0 -5
- package/browser/Enums/Modes/ThemeMode.js +0 -6
- package/browser/Enums/Types/DivType.js +0 -5
- package/browser/Enums/Types/InteractorType.js +0 -5
- package/browser/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
- package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
- package/browser/Options/Classes/Interactivity/Events/Events.js +0 -30
- package/browser/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
- package/browser/Options/Classes/Interactivity/Events/Parallax.js +0 -22
- package/browser/Options/Classes/Interactivity/Interactivity.js +0 -22
- package/browser/Options/Classes/Interactivity/Modes/Modes.js +0 -25
- package/browser/Options/Classes/ManualParticle.js +0 -21
- package/browser/Options/Classes/Responsive.js +0 -29
- package/browser/Options/Classes/Theme/Theme.js +0 -21
- package/browser/Options/Classes/Theme/ThemeDefault.js +0 -23
- package/browser/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
- package/browser/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
- package/browser/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
- package/browser/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
- package/browser/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
- package/browser/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
- package/browser/Options/Interfaces/Theme/ITheme.js +0 -1
- package/browser/Options/Interfaces/Theme/IThemeDefault.js +0 -1
- package/cjs/Core/Interfaces/IContainerInteractivity.js +0 -1
- package/cjs/Core/Interfaces/IExternalInteractor.js +0 -1
- package/cjs/Core/Interfaces/IInteractor.js +0 -1
- package/cjs/Core/Interfaces/IMouseData.js +0 -1
- package/cjs/Core/Interfaces/IParticlesInteractor.js +0 -1
- package/cjs/Core/Utils/ExternalInteractorBase.js +0 -7
- package/cjs/Core/Utils/InteractionManager.js +0 -60
- package/cjs/Core/Utils/ParticlesInteractorBase.js +0 -7
- package/cjs/Enums/InteractivityDetect.js +0 -6
- package/cjs/Enums/Modes/ResponsiveMode.js +0 -5
- package/cjs/Enums/Modes/ThemeMode.js +0 -6
- package/cjs/Enums/Types/DivType.js +0 -5
- package/cjs/Enums/Types/InteractorType.js +0 -5
- package/cjs/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
- package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
- package/cjs/Options/Classes/Interactivity/Events/Events.js +0 -30
- package/cjs/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
- package/cjs/Options/Classes/Interactivity/Events/Parallax.js +0 -22
- package/cjs/Options/Classes/Interactivity/Interactivity.js +0 -22
- package/cjs/Options/Classes/Interactivity/Modes/Modes.js +0 -25
- package/cjs/Options/Classes/ManualParticle.js +0 -21
- package/cjs/Options/Classes/Responsive.js +0 -29
- package/cjs/Options/Classes/Theme/Theme.js +0 -21
- package/cjs/Options/Classes/Theme/ThemeDefault.js +0 -23
- package/cjs/Options/Interfaces/IManualParticle.js +0 -1
- package/cjs/Options/Interfaces/IResponsive.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
- package/cjs/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
- package/cjs/Options/Interfaces/Theme/ITheme.js +0 -1
- package/cjs/Options/Interfaces/Theme/IThemeDefault.js +0 -1
- package/esm/Core/Interfaces/IContainerInteractivity.js +0 -1
- package/esm/Core/Interfaces/IExternalInteractor.js +0 -1
- package/esm/Core/Interfaces/IInteractor.js +0 -1
- package/esm/Core/Interfaces/IMouseData.js +0 -1
- package/esm/Core/Interfaces/IParticlesInteractor.js +0 -1
- package/esm/Core/Utils/ExternalInteractorBase.js +0 -7
- package/esm/Core/Utils/InteractionManager.js +0 -60
- package/esm/Core/Utils/ParticlesInteractorBase.js +0 -7
- package/esm/Enums/InteractivityDetect.js +0 -6
- package/esm/Enums/Modes/ResponsiveMode.js +0 -5
- package/esm/Enums/Modes/ThemeMode.js +0 -6
- package/esm/Enums/Types/DivType.js +0 -5
- package/esm/Enums/Types/InteractorType.js +0 -5
- package/esm/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
- package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
- package/esm/Options/Classes/Interactivity/Events/Events.js +0 -30
- package/esm/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
- package/esm/Options/Classes/Interactivity/Events/Parallax.js +0 -22
- package/esm/Options/Classes/Interactivity/Interactivity.js +0 -22
- package/esm/Options/Classes/Interactivity/Modes/Modes.js +0 -25
- package/esm/Options/Classes/ManualParticle.js +0 -21
- package/esm/Options/Classes/Responsive.js +0 -29
- package/esm/Options/Classes/Theme/Theme.js +0 -21
- package/esm/Options/Classes/Theme/ThemeDefault.js +0 -23
- package/esm/Options/Interfaces/IManualParticle.js +0 -1
- package/esm/Options/Interfaces/IResponsive.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
- package/esm/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
- package/esm/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
- package/esm/Options/Interfaces/Theme/ITheme.js +0 -1
- package/esm/Options/Interfaces/Theme/IThemeDefault.js +0 -1
- package/types/Core/Interfaces/IContainerInteractivity.d.ts +0 -6
- package/types/Core/Interfaces/IExternalInteractor.d.ts +0 -12
- package/types/Core/Interfaces/IInteractor.d.ts +0 -16
- package/types/Core/Interfaces/IMouseData.d.ts +0 -9
- package/types/Core/Interfaces/IParticlesInteractor.d.ts +0 -7
- package/types/Core/Utils/ExternalInteractorBase.d.ts +0 -15
- package/types/Core/Utils/InteractionManager.d.ts +0 -17
- package/types/Core/Utils/ParticlesInteractorBase.d.ts +0 -15
- package/types/Enums/InteractivityDetect.d.ts +0 -5
- package/types/Enums/Modes/ResponsiveMode.d.ts +0 -4
- package/types/Enums/Modes/ThemeMode.d.ts +0 -5
- package/types/Enums/Types/DivType.d.ts +0 -4
- package/types/Enums/Types/InteractorType.d.ts +0 -4
- package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +0 -10
- package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -13
- package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -16
- package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +0 -12
- package/types/Options/Classes/Interactivity/Events/Parallax.d.ts +0 -10
- package/types/Options/Classes/Interactivity/Events/ResizeEvent.d.ts +0 -9
- package/types/Options/Classes/Interactivity/Interactivity.d.ts +0 -16
- package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +0 -12
- package/types/Options/Classes/ManualParticle.d.ts +0 -10
- package/types/Options/Classes/Responsive.d.ts +0 -12
- package/types/Options/Classes/Theme/Theme.d.ts +0 -12
- package/types/Options/Classes/Theme/ThemeDefault.d.ts +0 -11
- package/types/Options/Interfaces/IManualParticle.d.ts +0 -7
- package/types/Options/Interfaces/IResponsive.d.ts +0 -7
- package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +0 -5
- package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -8
- package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -11
- package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +0 -7
- package/types/Options/Interfaces/Interactivity/Events/IParallax.d.ts +0 -5
- package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -9
- package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -4
- package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +0 -1
- package/types/Options/Interfaces/Theme/ITheme.d.ts +0 -7
- package/types/Options/Interfaces/Theme/IThemeDefault.d.ts +0 -6
- package/umd/Core/Interfaces/IMouseData.js +0 -12
- package/umd/Core/Interfaces/IParticlesInteractor.js +0 -12
- package/umd/Core/Utils/ExternalInteractorBase.js +0 -21
- package/umd/Core/Utils/InteractionManager.js +0 -74
- package/umd/Core/Utils/ParticlesInteractorBase.js +0 -21
- package/umd/Enums/InteractivityDetect.js +0 -19
- package/umd/Enums/Modes/ResponsiveMode.js +0 -18
- package/umd/Enums/Modes/ThemeMode.js +0 -19
- package/umd/Enums/Types/DivType.js +0 -18
- package/umd/Enums/Types/InteractorType.js +0 -18
- package/umd/Options/Classes/Interactivity/Events/ClickEvent.js +0 -32
- package/umd/Options/Classes/Interactivity/Events/DivEvent.js +0 -41
- package/umd/Options/Classes/Interactivity/Events/Events.js +0 -44
- package/umd/Options/Classes/Interactivity/Events/HoverEvent.js +0 -35
- package/umd/Options/Classes/Interactivity/Events/Parallax.js +0 -36
- package/umd/Options/Classes/Interactivity/Interactivity.js +0 -36
- package/umd/Options/Classes/Interactivity/Modes/Modes.js +0 -39
- package/umd/Options/Classes/ManualParticle.js +0 -35
- package/umd/Options/Classes/Responsive.js +0 -43
- package/umd/Options/Classes/Theme/Theme.js +0 -35
- package/umd/Options/Classes/Theme/ThemeDefault.js +0 -37
- package/umd/Options/Interfaces/IManualParticle.js +0 -12
- package/umd/Options/Interfaces/IResponsive.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Events/IEvents.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Events/IParallax.js +0 -12
- package/umd/Options/Interfaces/Interactivity/IInteractivity.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -12
- package/umd/Options/Interfaces/Interactivity/Modes/IModes.js +0 -12
- package/umd/Options/Interfaces/Theme/ITheme.js +0 -12
- package/umd/Options/Interfaces/Theme/IThemeDefault.js +0 -12
- /package/browser/Core/Interfaces/{IContainerInteractivity.js → IParticleOpacityData.js} +0 -0
- /package/browser/Core/Interfaces/{IExternalInteractor.js → IParticleRotateData.js} +0 -0
- /package/browser/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
- /package/browser/{Core/Interfaces/IInteractor.js → Types/EngineInitializers.js} +0 -0
- /package/{browser/Core/Interfaces/IMouseData.js → cjs/Core/Interfaces/IParticleOpacityData.js} +0 -0
- /package/{browser/Core/Interfaces/IParticlesInteractor.js → cjs/Core/Interfaces/IParticleRotateData.js} +0 -0
- /package/cjs/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
- /package/{browser/Options/Interfaces/IManualParticle.js → cjs/Types/EngineInitializers.js} +0 -0
- /package/{browser/Options/Interfaces/IResponsive.js → esm/Core/Interfaces/IParticleOpacityData.js} +0 -0
- /package/{browser/Options/Interfaces/Interactivity/Events/IClickEvent.js → esm/Core/Interfaces/IParticleRotateData.js} +0 -0
- /package/esm/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
- /package/{browser/Options/Interfaces/Interactivity/Events/IDivEvent.js → esm/Types/EngineInitializers.js} +0 -0
- /package/types/Options/Interfaces/{Interactivity/Events/IResizeEvent.d.ts → IResizeEvent.d.ts} +0 -0
- /package/umd/Core/Interfaces/{IContainerInteractivity.js → IParticleOpacityData.js} +0 -0
- /package/umd/Core/Interfaces/{IExternalInteractor.js → IParticleRotateData.js} +0 -0
- /package/umd/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
- /package/umd/{Core/Interfaces/IInteractor.js → Types/EngineInitializers.js} +0 -0
package/browser/Utils/Utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clamp, collisionVelocity, getDistances, getRandom, getRangeMax, getRangeMin, getRangeValue, randomInRangeValue, } from "./MathUtils.js";
|
|
2
2
|
import { half, millisecondsToSeconds, percentDenominator } from "../Core/Utils/Constants.js";
|
|
3
|
-
import { isArray, isNull, isObject } from "./TypeUtils.js";
|
|
3
|
+
import { isArray, isBoolean, isNull, isObject } from "./TypeUtils.js";
|
|
4
4
|
import { AnimationMode } from "../Enums/Modes/AnimationMode.js";
|
|
5
5
|
import { AnimationStatus } from "../Enums/AnimationStatus.js";
|
|
6
6
|
import { DestroyType } from "../Enums/Types/DestroyType.js";
|
|
@@ -21,12 +21,6 @@ function memoize(fn) {
|
|
|
21
21
|
return result;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function checkSelector(element, selectors) {
|
|
25
|
-
const res = executeOnSingleOrMultiple(selectors, selector => {
|
|
26
|
-
return element.matches(selector);
|
|
27
|
-
});
|
|
28
|
-
return isArray(res) ? res.some(t => t) : res;
|
|
29
|
-
}
|
|
30
24
|
export function hasMatchMedia() {
|
|
31
25
|
return typeof matchMedia !== "undefined";
|
|
32
26
|
}
|
|
@@ -123,31 +117,6 @@ export function deepExtend(destination, ...sources) {
|
|
|
123
117
|
}
|
|
124
118
|
return destination;
|
|
125
119
|
}
|
|
126
|
-
export function isDivModeEnabled(mode, divs) {
|
|
127
|
-
return !!findItemFromSingleOrMultiple(divs, t => t.enable && isInArray(mode, t.mode));
|
|
128
|
-
}
|
|
129
|
-
export function divModeExecute(mode, divs, callback) {
|
|
130
|
-
executeOnSingleOrMultiple(divs, div => {
|
|
131
|
-
const divMode = div.mode, divEnabled = div.enable;
|
|
132
|
-
if (divEnabled && isInArray(mode, divMode)) {
|
|
133
|
-
singleDivModeExecute(div, callback);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
export function singleDivModeExecute(div, callback) {
|
|
138
|
-
const selectors = div.selectors;
|
|
139
|
-
executeOnSingleOrMultiple(selectors, selector => {
|
|
140
|
-
callback(selector, div);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
export function divMode(divs, element) {
|
|
144
|
-
if (!element || !divs) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
return findItemFromSingleOrMultiple(divs, div => {
|
|
148
|
-
return checkSelector(element, div.selectors);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
120
|
export function circleBounceDataFromParticle(p) {
|
|
152
121
|
return {
|
|
153
122
|
position: p.getPosition(),
|
|
@@ -328,7 +297,7 @@ export function cloneStyle(style) {
|
|
|
328
297
|
const clonedStyle = safeDocument().createElement("div").style;
|
|
329
298
|
for (const key in style) {
|
|
330
299
|
const styleKey = style[key];
|
|
331
|
-
if (!Object.
|
|
300
|
+
if (!Object.hasOwn(style, key) || isNull(styleKey)) {
|
|
332
301
|
continue;
|
|
333
302
|
}
|
|
334
303
|
const styleValue = style.getPropertyValue?.(styleKey);
|
|
@@ -368,3 +337,27 @@ function computeFullScreenStyle(zIndex) {
|
|
|
368
337
|
return fullScreenStyle;
|
|
369
338
|
}
|
|
370
339
|
export const getFullScreenStyle = memoize(computeFullScreenStyle);
|
|
340
|
+
export function manageListener(element, event, handler, add, options) {
|
|
341
|
+
if (add) {
|
|
342
|
+
let addOptions = { passive: true };
|
|
343
|
+
if (isBoolean(options)) {
|
|
344
|
+
addOptions.capture = options;
|
|
345
|
+
}
|
|
346
|
+
else if (options !== undefined) {
|
|
347
|
+
addOptions = options;
|
|
348
|
+
}
|
|
349
|
+
element.addEventListener(event, handler, addOptions);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
const removeOptions = options;
|
|
353
|
+
element.removeEventListener(event, handler, removeOptions);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
export async function getItemsFromInitializer(container, map, initializers, force = false) {
|
|
357
|
+
let res = map.get(container);
|
|
358
|
+
if (!res || force) {
|
|
359
|
+
res = await Promise.all([...initializers.values()].map(t => t(container)));
|
|
360
|
+
map.set(container, res);
|
|
361
|
+
}
|
|
362
|
+
return res;
|
|
363
|
+
}
|
package/browser/exports.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from "./Core/Utils/Constants.js";
|
|
2
|
-
export * from "./Core/Utils/ExternalInteractorBase.js";
|
|
3
|
-
export * from "./Core/Utils/ParticlesInteractorBase.js";
|
|
4
2
|
export * from "./Core/Utils/Point.js";
|
|
5
3
|
export * from "./Core/Utils/Ranges.js";
|
|
6
4
|
export * from "./Core/Utils/Vectors.js";
|
|
@@ -11,36 +9,20 @@ export * from "./Enums/Modes/AnimationMode.js";
|
|
|
11
9
|
export * from "./Enums/Modes/LimitMode.js";
|
|
12
10
|
export * from "./Enums/Modes/OutMode.js";
|
|
13
11
|
export * from "./Enums/Modes/PixelMode.js";
|
|
14
|
-
export * from "./Enums/Modes/ThemeMode.js";
|
|
15
|
-
export * from "./Enums/Modes/ResponsiveMode.js";
|
|
16
12
|
export * from "./Enums/Types/AlterType.js";
|
|
17
13
|
export * from "./Enums/Types/DestroyType.js";
|
|
18
14
|
export * from "./Enums/Types/GradientType.js";
|
|
19
|
-
export * from "./Enums/Types/InteractorType.js";
|
|
20
15
|
export * from "./Enums/Types/ParticleOutType.js";
|
|
21
16
|
export * from "./Enums/Types/StartValueType.js";
|
|
22
|
-
export * from "./Enums/Types/DivType.js";
|
|
23
17
|
export * from "./Enums/Types/EasingType.js";
|
|
24
18
|
export * from "./Enums/Types/EventType.js";
|
|
25
19
|
export * from "./Enums/AnimationStatus.js";
|
|
26
|
-
export * from "./Enums/InteractivityDetect.js";
|
|
27
20
|
export * from "./Options/Classes/AnimatableColor.js";
|
|
28
21
|
export * from "./Options/Classes/AnimationOptions.js";
|
|
29
22
|
export * from "./Options/Classes/Background/Background.js";
|
|
30
23
|
export * from "./Options/Classes/ColorAnimation.js";
|
|
31
24
|
export * from "./Options/Classes/FullScreen/FullScreen.js";
|
|
32
25
|
export * from "./Options/Classes/HslAnimation.js";
|
|
33
|
-
export * from "./Options/Classes/Interactivity/Events/ClickEvent.js";
|
|
34
|
-
export * from "./Options/Classes/Interactivity/Events/DivEvent.js";
|
|
35
|
-
export * from "./Options/Classes/Interactivity/Events/ClickEvent.js";
|
|
36
|
-
export * from "./Options/Classes/Interactivity/Events/DivEvent.js";
|
|
37
|
-
export * from "./Options/Classes/Interactivity/Events/Events.js";
|
|
38
|
-
export * from "./Options/Classes/Interactivity/Events/HoverEvent.js";
|
|
39
|
-
export * from "./Options/Classes/Interactivity/Events/Parallax.js";
|
|
40
|
-
export * from "./Options/Classes/Interactivity/Events/ResizeEvent.js";
|
|
41
|
-
export * from "./Options/Classes/Interactivity/Interactivity.js";
|
|
42
|
-
export * from "./Options/Classes/Interactivity/Modes/Modes.js";
|
|
43
|
-
export * from "./Options/Classes/ManualParticle.js";
|
|
44
26
|
export * from "./Options/Classes/Options.js";
|
|
45
27
|
export * from "./Options/Classes/OptionsColor.js";
|
|
46
28
|
export * from "./Options/Classes/Particles/Bounce/ParticlesBounce.js";
|
|
@@ -64,9 +46,7 @@ export * from "./Options/Classes/Particles/Shape/Shape.js";
|
|
|
64
46
|
export * from "./Options/Classes/Particles/Size/Size.js";
|
|
65
47
|
export * from "./Options/Classes/Particles/Size/SizeAnimation.js";
|
|
66
48
|
export * from "./Options/Classes/Particles/ZIndex/ZIndex.js";
|
|
67
|
-
export * from "./Options/Classes/
|
|
68
|
-
export * from "./Options/Classes/Theme/Theme.js";
|
|
69
|
-
export * from "./Options/Classes/Theme/ThemeDefault.js";
|
|
49
|
+
export * from "./Options/Classes/ResizeEvent.js";
|
|
70
50
|
export * from "./Options/Classes/ValueWithRandom.js";
|
|
71
51
|
export * from "./Utils/CanvasUtils.js";
|
|
72
52
|
export * from "./Utils/ColorUtils.js";
|
package/cjs/Core/Canvas.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { clear, clearDrawPlugin, drawParticle, drawParticlePlugin, drawPlugin, paintBase, paintImage, } from "../Utils/CanvasUtils.js";
|
|
2
2
|
import { cloneStyle, getFullScreenStyle, safeMatchMedia, safeMutationObserver } from "../Utils/Utils.js";
|
|
3
|
-
import {
|
|
3
|
+
import { defaultTransformValue, generatedAttribute, minimumSize, zIndexFactorOffset } from "./Utils/Constants.js";
|
|
4
4
|
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
|
|
5
|
+
const fColorIndex = 0, sColorIndex = 1;
|
|
5
6
|
function setTransformValue(factor, newFactor, key) {
|
|
6
7
|
const newValue = newFactor[key];
|
|
7
8
|
if (newValue !== undefined) {
|
|
@@ -40,6 +41,9 @@ function setStyle(canvas, style, important = false) {
|
|
|
40
41
|
export class Canvas {
|
|
41
42
|
constructor(container, engine) {
|
|
42
43
|
this.container = container;
|
|
44
|
+
this._reusableColorStyles = {};
|
|
45
|
+
this._reusablePluginColors = [undefined, undefined];
|
|
46
|
+
this._reusableTransform = {};
|
|
43
47
|
this._applyPostDrawUpdaters = particle => {
|
|
44
48
|
for (const updater of this._postDrawUpdaters) {
|
|
45
49
|
updater.afterDraw?.(particle);
|
|
@@ -83,7 +87,9 @@ export class Canvas {
|
|
|
83
87
|
break;
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
|
-
|
|
90
|
+
this._reusablePluginColors[fColorIndex] = fColor;
|
|
91
|
+
this._reusablePluginColors[sColorIndex] = sColor;
|
|
92
|
+
return this._reusablePluginColors;
|
|
87
93
|
};
|
|
88
94
|
this._initStyle = () => {
|
|
89
95
|
const element = this.element, options = this.container.actualOptions;
|
|
@@ -97,7 +103,7 @@ export class Canvas {
|
|
|
97
103
|
this._resetOriginalStyle();
|
|
98
104
|
}
|
|
99
105
|
for (const key in options.style) {
|
|
100
|
-
if (!key || !Object.
|
|
106
|
+
if (!key || !Object.hasOwn(options.style, key)) {
|
|
101
107
|
continue;
|
|
102
108
|
}
|
|
103
109
|
const value = options.style[key];
|
|
@@ -178,7 +184,7 @@ export class Canvas {
|
|
|
178
184
|
}
|
|
179
185
|
clear() {
|
|
180
186
|
let pluginHandled = false;
|
|
181
|
-
for (const plugin of this.container.plugins
|
|
187
|
+
for (const plugin of this.container.plugins) {
|
|
182
188
|
if (!pluginHandled && plugin.canvasClear) {
|
|
183
189
|
pluginHandled = plugin.canvasClear();
|
|
184
190
|
}
|
|
@@ -230,22 +236,12 @@ export class Canvas {
|
|
|
230
236
|
if (!fColor && !sColor) {
|
|
231
237
|
return;
|
|
232
238
|
}
|
|
233
|
-
const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return getStyleFromHsl(fColor, container.hdr, zOpacity);
|
|
238
|
-
}, colorStyles = {
|
|
239
|
-
fill: getFillStyle(),
|
|
240
|
-
}, getStrokestyle = () => {
|
|
241
|
-
if (!sColor) {
|
|
242
|
-
return colorStyles.fill;
|
|
243
|
-
}
|
|
244
|
-
return getStyleFromHsl(sColor, container.hdr, zStrokeOpacity);
|
|
245
|
-
};
|
|
246
|
-
colorStyles.stroke = getStrokestyle();
|
|
239
|
+
const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity) : fill;
|
|
240
|
+
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
241
|
+
colorStyles.fill = fill;
|
|
242
|
+
colorStyles.stroke = stroke;
|
|
247
243
|
this.draw((context) => {
|
|
248
|
-
this._applyPreDrawUpdaters(context, particle, radius,
|
|
244
|
+
this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
249
245
|
drawParticle({
|
|
250
246
|
container,
|
|
251
247
|
context,
|
|
@@ -253,7 +249,7 @@ export class Canvas {
|
|
|
253
249
|
delta,
|
|
254
250
|
colorStyles,
|
|
255
251
|
radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
|
|
256
|
-
opacity:
|
|
252
|
+
opacity: opacity,
|
|
257
253
|
transform,
|
|
258
254
|
});
|
|
259
255
|
});
|
|
@@ -326,7 +322,7 @@ export class Canvas {
|
|
|
326
322
|
}
|
|
327
323
|
initPlugins() {
|
|
328
324
|
this._resizePlugins = [];
|
|
329
|
-
for (const plugin of this.container.plugins
|
|
325
|
+
for (const plugin of this.container.plugins) {
|
|
330
326
|
if (plugin.resize) {
|
|
331
327
|
this._resizePlugins.push(plugin);
|
|
332
328
|
}
|
|
@@ -384,7 +380,7 @@ export class Canvas {
|
|
|
384
380
|
}
|
|
385
381
|
paint() {
|
|
386
382
|
let handled = false;
|
|
387
|
-
for (const plugin of this.container.plugins
|
|
383
|
+
for (const plugin of this.container.plugins) {
|
|
388
384
|
if (handled) {
|
|
389
385
|
break;
|
|
390
386
|
}
|
package/cjs/Core/Container.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { animate, cancelAnimation, getRangeValue } from "../Utils/MathUtils.js";
|
|
2
|
-
import {
|
|
2
|
+
import { defaultFps, defaultFpsLimit, millisecondsToSeconds, minFpsLimit, removeDeleteCount, removeMinIndex, } from "./Utils/Constants.js";
|
|
3
3
|
import { Canvas } from "./Canvas.js";
|
|
4
4
|
import { EventListeners } from "./Utils/EventListeners.js";
|
|
5
5
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
@@ -8,15 +8,12 @@ import { Particles } from "./Particles.js";
|
|
|
8
8
|
import { Retina } from "./Retina.js";
|
|
9
9
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
10
10
|
import { loadOptions } from "../Utils/OptionsUtils.js";
|
|
11
|
-
import { safeIntersectionObserver } from "../Utils/Utils.js";
|
|
12
11
|
function guardCheck(container) {
|
|
13
12
|
return !container.destroyed;
|
|
14
13
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
factor: smooth ? defaultFps / fpsLimit : (defaultFps * value) / millisecondsToSeconds,
|
|
19
|
-
};
|
|
14
|
+
function updateDelta(delta, value, fpsLimit = defaultFps, smooth = false) {
|
|
15
|
+
delta.value = value;
|
|
16
|
+
delta.factor = smooth ? defaultFps / fpsLimit : (defaultFps * value) / millisecondsToSeconds;
|
|
20
17
|
}
|
|
21
18
|
function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
22
19
|
const options = new Options(engine, container);
|
|
@@ -25,22 +22,7 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
|
|
25
22
|
}
|
|
26
23
|
export class Container {
|
|
27
24
|
constructor(engine, id, sourceOptions) {
|
|
28
|
-
this.
|
|
29
|
-
if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
for (const entry of entries) {
|
|
33
|
-
if (entry.target !== this.interactivity.element) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (entry.isIntersecting) {
|
|
37
|
-
this.play();
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.pause();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
25
|
+
this._delta = { value: 0, factor: 0 };
|
|
44
26
|
this._nextFrame = (timestamp) => {
|
|
45
27
|
try {
|
|
46
28
|
if (!this._smooth &&
|
|
@@ -50,14 +32,14 @@ export class Container {
|
|
|
50
32
|
return;
|
|
51
33
|
}
|
|
52
34
|
this._lastFrameTime ??= timestamp;
|
|
53
|
-
|
|
54
|
-
this.addLifeTime(
|
|
35
|
+
updateDelta(this._delta, timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
|
|
36
|
+
this.addLifeTime(this._delta.value);
|
|
55
37
|
this._lastFrameTime = timestamp;
|
|
56
|
-
if (
|
|
38
|
+
if (this._delta.value > millisecondsToSeconds) {
|
|
57
39
|
this.draw(false);
|
|
58
40
|
return;
|
|
59
41
|
}
|
|
60
|
-
this.canvas.drawParticles(
|
|
42
|
+
this.canvas.drawParticles(this._delta);
|
|
61
43
|
if (!this.alive()) {
|
|
62
44
|
this.destroy();
|
|
63
45
|
return;
|
|
@@ -85,28 +67,18 @@ export class Container {
|
|
|
85
67
|
this._lastFrameTime = 0;
|
|
86
68
|
this.zLayers = 100;
|
|
87
69
|
this.pageHidden = false;
|
|
88
|
-
this._clickHandlers = new Map();
|
|
89
70
|
this._sourceOptions = sourceOptions;
|
|
90
71
|
this._initialSourceOptions = sourceOptions;
|
|
91
72
|
this.retina = new Retina(this);
|
|
92
73
|
this.canvas = new Canvas(this, this._engine);
|
|
93
74
|
this.particles = new Particles(this._engine, this);
|
|
94
75
|
this.pathGenerators = new Map();
|
|
95
|
-
this.
|
|
96
|
-
mouse: {
|
|
97
|
-
clicking: false,
|
|
98
|
-
inside: false,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
this.plugins = new Map();
|
|
76
|
+
this.plugins = [];
|
|
102
77
|
this.effectDrawers = new Map();
|
|
103
78
|
this.shapeDrawers = new Map();
|
|
104
79
|
this._options = loadContainerOptions(this._engine, this);
|
|
105
80
|
this.actualOptions = loadContainerOptions(this._engine, this);
|
|
106
81
|
this._eventListeners = new EventListeners(this);
|
|
107
|
-
this._intersectionObserver = safeIntersectionObserver(entries => {
|
|
108
|
-
this._intersectionManager(entries);
|
|
109
|
-
});
|
|
110
82
|
this._engine.dispatchEvent(EventType.containerBuilt, { container: this });
|
|
111
83
|
}
|
|
112
84
|
get animationStatus() {
|
|
@@ -118,77 +90,6 @@ export class Container {
|
|
|
118
90
|
get sourceOptions() {
|
|
119
91
|
return this._sourceOptions;
|
|
120
92
|
}
|
|
121
|
-
addClickHandler(callback) {
|
|
122
|
-
if (!guardCheck(this)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const el = this.interactivity.element;
|
|
126
|
-
if (!el) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const clickOrTouchHandler = (e, pos, radius) => {
|
|
130
|
-
if (!guardCheck(this)) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const pxRatio = this.retina.pixelRatio, posRetina = {
|
|
134
|
-
x: pos.x * pxRatio,
|
|
135
|
-
y: pos.y * pxRatio,
|
|
136
|
-
}, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
|
|
137
|
-
callback(e, particles);
|
|
138
|
-
}, clickHandler = (e) => {
|
|
139
|
-
if (!guardCheck(this)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const mouseEvent = e, pos = {
|
|
143
|
-
x: mouseEvent.offsetX || mouseEvent.clientX,
|
|
144
|
-
y: mouseEvent.offsetY || mouseEvent.clientY,
|
|
145
|
-
};
|
|
146
|
-
clickOrTouchHandler(e, pos, clickRadius);
|
|
147
|
-
}, touchStartHandler = () => {
|
|
148
|
-
if (!guardCheck(this)) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
touched = true;
|
|
152
|
-
touchMoved = false;
|
|
153
|
-
}, touchMoveHandler = () => {
|
|
154
|
-
if (!guardCheck(this)) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
touchMoved = true;
|
|
158
|
-
}, touchEndHandler = (e) => {
|
|
159
|
-
if (!guardCheck(this)) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (touched && !touchMoved) {
|
|
163
|
-
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - touchEndLengthOffset];
|
|
164
|
-
if (!lastTouch) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
|
|
168
|
-
x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
|
|
169
|
-
y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
|
|
170
|
-
};
|
|
171
|
-
clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
|
|
172
|
-
}
|
|
173
|
-
touched = false;
|
|
174
|
-
touchMoved = false;
|
|
175
|
-
}, touchCancelHandler = () => {
|
|
176
|
-
if (!guardCheck(this)) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
touched = false;
|
|
180
|
-
touchMoved = false;
|
|
181
|
-
};
|
|
182
|
-
let touched = false, touchMoved = false;
|
|
183
|
-
this._clickHandlers.set("click", clickHandler);
|
|
184
|
-
this._clickHandlers.set("touchstart", touchStartHandler);
|
|
185
|
-
this._clickHandlers.set("touchmove", touchMoveHandler);
|
|
186
|
-
this._clickHandlers.set("touchend", touchEndHandler);
|
|
187
|
-
this._clickHandlers.set("touchcancel", touchCancelHandler);
|
|
188
|
-
for (const [key, handler] of this._clickHandlers) {
|
|
189
|
-
el.addEventListener(key, handler);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
93
|
addLifeTime(value) {
|
|
193
94
|
this._lifeTime += value;
|
|
194
95
|
}
|
|
@@ -202,39 +103,29 @@ export class Container {
|
|
|
202
103
|
alive() {
|
|
203
104
|
return !this._duration || this._lifeTime <= this._duration;
|
|
204
105
|
}
|
|
205
|
-
clearClickHandlers() {
|
|
206
|
-
if (!guardCheck(this)) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
for (const [key, handler] of this._clickHandlers) {
|
|
210
|
-
this.interactivity.element?.removeEventListener(key, handler);
|
|
211
|
-
}
|
|
212
|
-
this._clickHandlers.clear();
|
|
213
|
-
}
|
|
214
106
|
destroy(remove = true) {
|
|
215
107
|
if (!guardCheck(this)) {
|
|
216
108
|
return;
|
|
217
109
|
}
|
|
218
110
|
this.stop();
|
|
219
|
-
this.clearClickHandlers();
|
|
220
111
|
this.particles.destroy();
|
|
221
112
|
this.canvas.destroy();
|
|
222
113
|
for (const effectDrawer of this.effectDrawers.values()) {
|
|
223
114
|
effectDrawer.destroy?.(this);
|
|
224
115
|
}
|
|
116
|
+
this.effectDrawers.clear();
|
|
225
117
|
for (const shapeDrawer of this.shapeDrawers.values()) {
|
|
226
118
|
shapeDrawer.destroy?.(this);
|
|
227
119
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
for (const key of this.shapeDrawers.keys()) {
|
|
232
|
-
this.shapeDrawers.delete(key);
|
|
120
|
+
this.shapeDrawers.clear();
|
|
121
|
+
for (const plugin of this.plugins) {
|
|
122
|
+
plugin.destroy?.();
|
|
233
123
|
}
|
|
124
|
+
this.plugins.length = 0;
|
|
234
125
|
this._engine.clearPlugins(this);
|
|
235
126
|
this.destroyed = true;
|
|
236
127
|
if (remove) {
|
|
237
|
-
const mainArr = this._engine.items, idx = mainArr.
|
|
128
|
+
const mainArr = this._engine.items, idx = mainArr.indexOf(this);
|
|
238
129
|
if (idx >= removeMinIndex) {
|
|
239
130
|
mainArr.splice(idx, removeDeleteCount);
|
|
240
131
|
}
|
|
@@ -258,7 +149,7 @@ export class Container {
|
|
|
258
149
|
});
|
|
259
150
|
}
|
|
260
151
|
async export(type, options = {}) {
|
|
261
|
-
for (const plugin of this.plugins
|
|
152
|
+
for (const plugin of this.plugins) {
|
|
262
153
|
if (!plugin.export) {
|
|
263
154
|
continue;
|
|
264
155
|
}
|
|
@@ -271,15 +162,6 @@ export class Container {
|
|
|
271
162
|
getLogger().error(`Export plugin with type ${type} not found`);
|
|
272
163
|
return undefined;
|
|
273
164
|
}
|
|
274
|
-
handleClickMode(mode) {
|
|
275
|
-
if (!guardCheck(this)) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
this.particles.handleClickMode(mode);
|
|
279
|
-
for (const plugin of this.plugins.values()) {
|
|
280
|
-
plugin.handleClickMode?.(mode);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
165
|
async init() {
|
|
284
166
|
if (!guardCheck(this)) {
|
|
285
167
|
return;
|
|
@@ -298,12 +180,21 @@ export class Container {
|
|
|
298
180
|
this.shapeDrawers.set(type, drawer);
|
|
299
181
|
}
|
|
300
182
|
}
|
|
183
|
+
const allContainerPlugins = new Map();
|
|
184
|
+
for (const plugin of this._engine.plugins) {
|
|
185
|
+
const containerPlugin = await plugin.getPlugin(this);
|
|
186
|
+
if (containerPlugin.preInit) {
|
|
187
|
+
await containerPlugin.preInit();
|
|
188
|
+
}
|
|
189
|
+
allContainerPlugins.set(plugin, containerPlugin);
|
|
190
|
+
}
|
|
301
191
|
await this.particles.initPlugins();
|
|
302
192
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
303
193
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
194
|
+
for (const [plugin, containerPlugin] of allContainerPlugins) {
|
|
195
|
+
if (plugin.needsPlugin(this.actualOptions)) {
|
|
196
|
+
this.plugins.push(containerPlugin);
|
|
197
|
+
}
|
|
307
198
|
}
|
|
308
199
|
this.retina.init();
|
|
309
200
|
this.canvas.init();
|
|
@@ -318,30 +209,23 @@ export class Container {
|
|
|
318
209
|
this._lifeTime = 0;
|
|
319
210
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
320
211
|
this._smooth = smooth;
|
|
212
|
+
for (const plugin of this.plugins) {
|
|
213
|
+
await plugin.init?.();
|
|
214
|
+
}
|
|
321
215
|
for (const drawer of this.effectDrawers.values()) {
|
|
322
216
|
await drawer.init?.(this);
|
|
323
217
|
}
|
|
324
218
|
for (const drawer of this.shapeDrawers.values()) {
|
|
325
219
|
await drawer.init?.(this);
|
|
326
220
|
}
|
|
327
|
-
for (const plugin of this.plugins.values()) {
|
|
328
|
-
await plugin.init?.();
|
|
329
|
-
}
|
|
330
221
|
this._engine.dispatchEvent(EventType.containerInit, { container: this });
|
|
331
222
|
await this.particles.init();
|
|
332
223
|
this.particles.setDensity();
|
|
333
|
-
for (const plugin of this.plugins
|
|
224
|
+
for (const plugin of this.plugins) {
|
|
334
225
|
plugin.particlesSetup?.();
|
|
335
226
|
}
|
|
336
227
|
this._engine.dispatchEvent(EventType.particlesSetup, { container: this });
|
|
337
228
|
}
|
|
338
|
-
async loadTheme(name) {
|
|
339
|
-
if (!guardCheck(this)) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
this._currentTheme = name;
|
|
343
|
-
await this.refresh();
|
|
344
|
-
}
|
|
345
229
|
pause() {
|
|
346
230
|
if (!guardCheck(this)) {
|
|
347
231
|
return;
|
|
@@ -353,7 +237,7 @@ export class Container {
|
|
|
353
237
|
if (this._paused) {
|
|
354
238
|
return;
|
|
355
239
|
}
|
|
356
|
-
for (const plugin of this.plugins
|
|
240
|
+
for (const plugin of this.plugins) {
|
|
357
241
|
plugin.pause?.();
|
|
358
242
|
}
|
|
359
243
|
if (!this.pageHidden) {
|
|
@@ -374,7 +258,7 @@ export class Container {
|
|
|
374
258
|
this._paused = false;
|
|
375
259
|
}
|
|
376
260
|
if (needsUpdate) {
|
|
377
|
-
for (const plugin of this.plugins
|
|
261
|
+
for (const plugin of this.plugins) {
|
|
378
262
|
if (plugin.play) {
|
|
379
263
|
plugin.play();
|
|
380
264
|
}
|
|
@@ -409,10 +293,7 @@ export class Container {
|
|
|
409
293
|
await new Promise(resolve => {
|
|
410
294
|
const start = async () => {
|
|
411
295
|
this._eventListeners.addListeners();
|
|
412
|
-
|
|
413
|
-
this._intersectionObserver.observe(this.interactivity.element);
|
|
414
|
-
}
|
|
415
|
-
for (const plugin of this.plugins.values()) {
|
|
296
|
+
for (const plugin of this.plugins) {
|
|
416
297
|
await plugin.start?.();
|
|
417
298
|
}
|
|
418
299
|
this._engine.dispatchEvent(EventType.containerStarted, { container: this });
|
|
@@ -436,26 +317,20 @@ export class Container {
|
|
|
436
317
|
this.pause();
|
|
437
318
|
this.particles.clear();
|
|
438
319
|
this.canvas.stop();
|
|
439
|
-
|
|
440
|
-
this._intersectionObserver.unobserve(this.interactivity.element);
|
|
441
|
-
}
|
|
442
|
-
for (const plugin of this.plugins.values()) {
|
|
320
|
+
for (const plugin of this.plugins) {
|
|
443
321
|
plugin.stop?.();
|
|
444
322
|
}
|
|
445
|
-
|
|
446
|
-
this.plugins.delete(key);
|
|
447
|
-
}
|
|
323
|
+
this.plugins.length = 0;
|
|
448
324
|
this._sourceOptions = this._options;
|
|
449
325
|
this._engine.dispatchEvent(EventType.containerStopped, { container: this });
|
|
450
326
|
}
|
|
451
327
|
updateActualOptions() {
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
328
|
+
let refresh = false;
|
|
329
|
+
for (const plugin of this.plugins) {
|
|
330
|
+
if (plugin.updateActualOptions) {
|
|
331
|
+
refresh = plugin.updateActualOptions() || refresh;
|
|
332
|
+
}
|
|
457
333
|
}
|
|
458
|
-
|
|
459
|
-
return true;
|
|
334
|
+
return refresh;
|
|
460
335
|
}
|
|
461
336
|
}
|