@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/cjs/Core/Engine.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { canvasFirstIndex, canvasTag, generatedAttribute, generatedFalse, generatedTrue, loadMinIndex, loadRandomFactor, none, one, removeDeleteCount, } from "./Utils/Constants.js";
|
|
2
|
-
import { itemFromSingleOrMultiple, safeDocument } from "../Utils/Utils.js";
|
|
2
|
+
import { getItemsFromInitializer, itemFromSingleOrMultiple, safeDocument } from "../Utils/Utils.js";
|
|
3
3
|
import { EventDispatcher } from "../Utils/EventDispatcher.js";
|
|
4
4
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
5
5
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
6
6
|
import { getRandom } from "../Utils/MathUtils.js";
|
|
7
|
-
|
|
8
|
-
let res = map.get(container);
|
|
9
|
-
if (!res || force) {
|
|
10
|
-
res = await Promise.all([...initializers.values()].map(t => t(container)));
|
|
11
|
-
map.set(container, res);
|
|
12
|
-
}
|
|
13
|
-
return res;
|
|
14
|
-
}
|
|
7
|
+
const fullPercent = "100%";
|
|
15
8
|
async function getDataFromUrl(data) {
|
|
16
9
|
const url = itemFromSingleOrMultiple(data.url, data.index);
|
|
17
10
|
if (!url) {
|
|
@@ -25,6 +18,7 @@ async function getDataFromUrl(data) {
|
|
|
25
18
|
return data.fallback;
|
|
26
19
|
}
|
|
27
20
|
const getCanvasFromContainer = (domContainer) => {
|
|
21
|
+
const documentSafe = safeDocument();
|
|
28
22
|
let canvasEl;
|
|
29
23
|
if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag) {
|
|
30
24
|
canvasEl = domContainer;
|
|
@@ -37,28 +31,24 @@ const getCanvasFromContainer = (domContainer) => {
|
|
|
37
31
|
canvasEl.dataset[generatedAttribute] = generatedFalse;
|
|
38
32
|
}
|
|
39
33
|
else {
|
|
40
|
-
canvasEl =
|
|
34
|
+
canvasEl = documentSafe.createElement(canvasTag);
|
|
41
35
|
canvasEl.dataset[generatedAttribute] = generatedTrue;
|
|
42
36
|
domContainer.appendChild(canvasEl);
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
canvasEl.style.width = fullPercent;
|
|
48
|
-
}
|
|
49
|
-
if (!canvasEl.style.height) {
|
|
50
|
-
canvasEl.style.height = fullPercent;
|
|
51
|
-
}
|
|
39
|
+
canvasEl.style.width ||= fullPercent;
|
|
40
|
+
canvasEl.style.height ||= fullPercent;
|
|
52
41
|
return canvasEl;
|
|
53
42
|
}, getDomContainer = (id, source) => {
|
|
54
|
-
|
|
43
|
+
const documentSafe = safeDocument();
|
|
44
|
+
let domContainer = source ?? documentSafe.getElementById(id);
|
|
55
45
|
if (domContainer) {
|
|
56
46
|
return domContainer;
|
|
57
47
|
}
|
|
58
|
-
domContainer =
|
|
48
|
+
domContainer = documentSafe.createElement("div");
|
|
59
49
|
domContainer.id = id;
|
|
60
50
|
domContainer.dataset[generatedAttribute] = generatedTrue;
|
|
61
|
-
|
|
51
|
+
documentSafe.body.append(domContainer);
|
|
62
52
|
return domContainer;
|
|
63
53
|
};
|
|
64
54
|
export class Engine {
|
|
@@ -72,11 +62,9 @@ export class Engine {
|
|
|
72
62
|
this.colorManagers = new Map();
|
|
73
63
|
this.easingFunctions = new Map();
|
|
74
64
|
this._initializers = {
|
|
75
|
-
interactors: new Map(),
|
|
76
65
|
movers: new Map(),
|
|
77
66
|
updaters: new Map(),
|
|
78
67
|
};
|
|
79
|
-
this.interactors = new Map();
|
|
80
68
|
this.movers = new Map();
|
|
81
69
|
this.updaters = new Map();
|
|
82
70
|
this.presets = new Map();
|
|
@@ -95,7 +83,7 @@ export class Engine {
|
|
|
95
83
|
return this._domArray;
|
|
96
84
|
}
|
|
97
85
|
get version() {
|
|
98
|
-
return "4.0.0-alpha.
|
|
86
|
+
return "4.0.0-alpha.4";
|
|
99
87
|
}
|
|
100
88
|
addColorManager(manager) {
|
|
101
89
|
this.colorManagers.set(manager.key, manager);
|
|
@@ -120,9 +108,6 @@ export class Engine {
|
|
|
120
108
|
addEventListener(type, listener) {
|
|
121
109
|
this._eventDispatcher.addEventListener(type, listener);
|
|
122
110
|
}
|
|
123
|
-
addInteractor(name, interactorInitializer) {
|
|
124
|
-
this._initializers.interactors.set(name, interactorInitializer);
|
|
125
|
-
}
|
|
126
111
|
addMover(name, moverInitializer) {
|
|
127
112
|
this._initializers.movers.set(name, moverInitializer);
|
|
128
113
|
}
|
|
@@ -164,35 +149,16 @@ export class Engine {
|
|
|
164
149
|
clearPlugins(container) {
|
|
165
150
|
this.updaters.delete(container);
|
|
166
151
|
this.movers.delete(container);
|
|
167
|
-
this.interactors.delete(container);
|
|
168
152
|
}
|
|
169
153
|
dispatchEvent(type, args) {
|
|
170
154
|
this._eventDispatcher.dispatchEvent(type, args);
|
|
171
155
|
}
|
|
172
|
-
dom() {
|
|
173
|
-
return this.items;
|
|
174
|
-
}
|
|
175
|
-
domItem(index) {
|
|
176
|
-
return this.item(index);
|
|
177
|
-
}
|
|
178
|
-
async getAvailablePlugins(container) {
|
|
179
|
-
const res = new Map();
|
|
180
|
-
for (const plugin of this.plugins) {
|
|
181
|
-
if (plugin.needsPlugin(container.actualOptions)) {
|
|
182
|
-
res.set(plugin.id, await plugin.getPlugin(container));
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return res;
|
|
186
|
-
}
|
|
187
156
|
getEasing(name) {
|
|
188
157
|
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
189
158
|
}
|
|
190
159
|
getEffectDrawer(type) {
|
|
191
160
|
return this.effectDrawers.get(type);
|
|
192
161
|
}
|
|
193
|
-
async getInteractors(container, force = false) {
|
|
194
|
-
return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
|
195
|
-
}
|
|
196
162
|
async getMovers(container, force = false) {
|
|
197
163
|
return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
|
198
164
|
}
|
|
@@ -221,10 +187,36 @@ export class Engine {
|
|
|
221
187
|
if (this._initialized) {
|
|
222
188
|
return;
|
|
223
189
|
}
|
|
224
|
-
|
|
225
|
-
|
|
190
|
+
const executed = new Set(), allLoaders = new Set(this._loadPromises), stack = [...allLoaders];
|
|
191
|
+
while (stack.length) {
|
|
192
|
+
const loader = stack.shift();
|
|
193
|
+
if (!loader) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (executed.has(loader)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
executed.add(loader);
|
|
200
|
+
const inner = [], origRegister = this.register.bind(this);
|
|
201
|
+
this.register = (...loaders) => {
|
|
202
|
+
inner.push(...loaders);
|
|
203
|
+
for (const loader of loaders) {
|
|
204
|
+
allLoaders.add(loader);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
await loader(this);
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
this.register = origRegister;
|
|
212
|
+
}
|
|
213
|
+
stack.unshift(...inner);
|
|
214
|
+
this._loadPromises.delete(loader);
|
|
226
215
|
}
|
|
227
216
|
this._loadPromises.clear();
|
|
217
|
+
for (const loader of allLoaders) {
|
|
218
|
+
this._loadPromises.add(loader);
|
|
219
|
+
}
|
|
228
220
|
this._initialized = true;
|
|
229
221
|
}
|
|
230
222
|
item(index) {
|
|
@@ -237,6 +229,7 @@ export class Engine {
|
|
|
237
229
|
}
|
|
238
230
|
async load(params) {
|
|
239
231
|
await this.init();
|
|
232
|
+
this._loadPromises.clear();
|
|
240
233
|
const { Container } = await import("./Container.js"), id = params.id ??
|
|
241
234
|
params.element?.id ??
|
|
242
235
|
`tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(this, id, currentOptions);
|
|
@@ -255,11 +248,6 @@ export class Engine {
|
|
|
255
248
|
await newItem.start();
|
|
256
249
|
return newItem;
|
|
257
250
|
}
|
|
258
|
-
loadOptions(options, sourceOptions) {
|
|
259
|
-
this.plugins.forEach(plugin => {
|
|
260
|
-
plugin.loadOptions(options, sourceOptions);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
251
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
264
252
|
const updaters = this.updaters.get(container);
|
|
265
253
|
if (!updaters) {
|
|
@@ -284,13 +272,4 @@ export class Engine {
|
|
|
284
272
|
removeEventListener(type, listener) {
|
|
285
273
|
this._eventDispatcher.removeEventListener(type, listener);
|
|
286
274
|
}
|
|
287
|
-
setOnClickHandler(callback) {
|
|
288
|
-
const { items } = this;
|
|
289
|
-
if (!items.length) {
|
|
290
|
-
throw new Error("Click handlers can only be set after calling tsParticles.load()");
|
|
291
|
-
}
|
|
292
|
-
items.forEach(item => {
|
|
293
|
-
item.addClickHandler(callback);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
275
|
}
|
package/cjs/Core/Particle.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Vector, Vector3d } from "./Utils/Vectors.js";
|
|
2
2
|
import { calcExactPositionOrRandomFromSize, clamp, degToRad, getParticleBaseVelocity, getParticleDirectionAngle, getRandom, getRangeValue, randomInRangeValue, setRangeValue, } from "../Utils/MathUtils.js";
|
|
3
|
-
import { decayOffset, defaultAngle, defaultRetryCount, double, half, millisecondsToSeconds, minZ, none, randomColorValue, rollFactor, squareExp, tryCountIncrement, } from "./Utils/Constants.js";
|
|
3
|
+
import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, half, identity, millisecondsToSeconds, minZ, none, randomColorValue, rollFactor, squareExp, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
4
4
|
import { deepExtend, getPosition, initParticleNumericAnimationValue, isInArray, itemFromSingleOrMultiple, } from "../Utils/Utils.js";
|
|
5
5
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
6
|
-
import { Interactivity } from "../Options/Classes/Interactivity/Interactivity.js";
|
|
7
6
|
import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
|
|
8
7
|
import { OutMode } from "../Enums/Modes/OutMode.js";
|
|
9
8
|
import { ParticleOutType } from "../Enums/Types/ParticleOutType.js";
|
|
@@ -39,51 +38,50 @@ function fixOutMode(data) {
|
|
|
39
38
|
export class Particle {
|
|
40
39
|
constructor(engine, container) {
|
|
41
40
|
this.container = container;
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
this._cachedOpacityData = {
|
|
42
|
+
opacity: defaultOpacity,
|
|
43
|
+
strokeOpacity: defaultOpacity,
|
|
44
|
+
};
|
|
45
|
+
this._cachedPosition = Vector3d.origin;
|
|
46
|
+
this._cachedRotateData = { sin: 0, cos: 0 };
|
|
47
|
+
this._cachedTransform = {
|
|
48
|
+
a: 1,
|
|
49
|
+
b: 0,
|
|
50
|
+
c: 0,
|
|
51
|
+
d: 1,
|
|
52
|
+
};
|
|
53
|
+
this._calcPosition = (position, zIndex) => {
|
|
54
|
+
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
55
|
+
const container = this.container, plugins = Array.from(container.plugins), outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
56
|
+
while (!signal.aborted) {
|
|
57
|
+
for (const plugin of plugins) {
|
|
58
|
+
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
59
|
+
if (pluginPos) {
|
|
60
|
+
return Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
|
|
61
|
+
}
|
|
48
62
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
fixOutMode({
|
|
64
|
-
outMode,
|
|
65
|
-
checkModes: [OutMode.bounce],
|
|
66
|
-
coord: pos.y,
|
|
67
|
-
maxCoord: container.canvas.size.height,
|
|
68
|
-
setCb: (value) => (pos.y += value),
|
|
69
|
-
radius,
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
fixHorizontal(outModes.left ?? outModes.default);
|
|
73
|
-
fixHorizontal(outModes.right ?? outModes.default);
|
|
74
|
-
fixVertical(outModes.top ?? outModes.default);
|
|
75
|
-
fixVertical(outModes.bottom ?? outModes.default);
|
|
76
|
-
let isValidPosition = true;
|
|
77
|
-
for (const plugin of plugins) {
|
|
78
|
-
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount);
|
|
79
|
-
if (isValidPosition === false) {
|
|
80
|
-
break;
|
|
63
|
+
const exactPosition = calcExactPositionOrRandomFromSize({
|
|
64
|
+
size: canvasSize,
|
|
65
|
+
position: posVec,
|
|
66
|
+
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
67
|
+
this._fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
68
|
+
this._fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
69
|
+
this._fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
70
|
+
this._fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
71
|
+
let isValidPosition = true;
|
|
72
|
+
for (const plugin of plugins) {
|
|
73
|
+
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
74
|
+
if (!isValidPosition) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
81
77
|
}
|
|
78
|
+
if (isValidPosition) {
|
|
79
|
+
return pos;
|
|
80
|
+
}
|
|
81
|
+
tryCount += tryCountIncrement;
|
|
82
|
+
posVec = undefined;
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
return this._calcPosition(container, undefined, zIndex, tryCount + tryCountIncrement);
|
|
85
|
-
}
|
|
86
|
-
return pos;
|
|
84
|
+
return posVec;
|
|
87
85
|
};
|
|
88
86
|
this._calculateVelocity = () => {
|
|
89
87
|
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
|
|
@@ -102,6 +100,26 @@ export class Particle {
|
|
|
102
100
|
}
|
|
103
101
|
return res;
|
|
104
102
|
};
|
|
103
|
+
this._fixHorizontal = (pos, radius, outMode) => {
|
|
104
|
+
fixOutMode({
|
|
105
|
+
outMode,
|
|
106
|
+
checkModes: [OutMode.bounce],
|
|
107
|
+
coord: pos.x,
|
|
108
|
+
maxCoord: this.container.canvas.size.width,
|
|
109
|
+
setCb: (value) => (pos.x += value),
|
|
110
|
+
radius,
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
this._fixVertical = (pos, radius, outMode) => {
|
|
114
|
+
fixOutMode({
|
|
115
|
+
outMode,
|
|
116
|
+
checkModes: [OutMode.bounce],
|
|
117
|
+
coord: pos.y,
|
|
118
|
+
maxCoord: this.container.canvas.size.height,
|
|
119
|
+
setCb: (value) => (pos.y += value),
|
|
120
|
+
radius,
|
|
121
|
+
});
|
|
122
|
+
};
|
|
105
123
|
this._getRollColor = color => {
|
|
106
124
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
107
125
|
return color;
|
|
@@ -120,7 +138,11 @@ export class Particle {
|
|
|
120
138
|
};
|
|
121
139
|
this._initPosition = position => {
|
|
122
140
|
const container = this.container, zIndexValue = getRangeValue(this.options.zIndex.value);
|
|
123
|
-
|
|
141
|
+
const initialPosition = this._calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
142
|
+
if (!initialPosition) {
|
|
143
|
+
throw new Error("a valid position cannot be found for particle");
|
|
144
|
+
}
|
|
145
|
+
this.position = initialPosition;
|
|
124
146
|
this.initialPosition = this.position.copy();
|
|
125
147
|
const canvasSize = container.canvas.size;
|
|
126
148
|
this.moveCenter = {
|
|
@@ -150,7 +172,7 @@ export class Particle {
|
|
|
150
172
|
this.slow.inRange = false;
|
|
151
173
|
const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
152
174
|
shapeDrawer?.particleDestroy?.(this);
|
|
153
|
-
for (const plugin of container.plugins
|
|
175
|
+
for (const plugin of container.plugins) {
|
|
154
176
|
plugin.particleDestroyed?.(this, override);
|
|
155
177
|
}
|
|
156
178
|
for (const updater of container.particles.updaters) {
|
|
@@ -166,7 +188,7 @@ export class Particle {
|
|
|
166
188
|
}
|
|
167
189
|
draw(delta) {
|
|
168
190
|
const container = this.container, canvas = container.canvas;
|
|
169
|
-
for (const plugin of container.plugins
|
|
191
|
+
for (const plugin of container.plugins) {
|
|
170
192
|
canvas.drawParticlePlugin(plugin, this, delta);
|
|
171
193
|
}
|
|
172
194
|
canvas.drawParticle(this, delta);
|
|
@@ -180,21 +202,44 @@ export class Particle {
|
|
|
180
202
|
getMass() {
|
|
181
203
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
182
204
|
}
|
|
205
|
+
getOpacity() {
|
|
206
|
+
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? getRangeValue(this.opacity?.value ?? defaultOpacity), strokeOpacity = this.strokeOpacity ?? opacity;
|
|
207
|
+
this._cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
208
|
+
this._cachedOpacityData.strokeOpacity = strokeOpacity * zOpacityFactor;
|
|
209
|
+
return this._cachedOpacityData;
|
|
210
|
+
}
|
|
183
211
|
getPosition() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
};
|
|
212
|
+
this._cachedPosition.x = this.position.x + this.offset.x;
|
|
213
|
+
this._cachedPosition.y = this.position.y + this.offset.y;
|
|
214
|
+
this._cachedPosition.z = this.position.z;
|
|
215
|
+
return this._cachedPosition;
|
|
189
216
|
}
|
|
190
217
|
getRadius() {
|
|
191
218
|
return this.bubble.radius ?? this.size.value;
|
|
192
219
|
}
|
|
220
|
+
getRotateData() {
|
|
221
|
+
const angle = this.getAngle();
|
|
222
|
+
this._cachedRotateData.sin = Math.sin(angle);
|
|
223
|
+
this._cachedRotateData.cos = Math.cos(angle);
|
|
224
|
+
return this._cachedRotateData;
|
|
225
|
+
}
|
|
193
226
|
getStrokeColor() {
|
|
194
227
|
return this._getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
195
228
|
}
|
|
229
|
+
getTransformData(externalTransform) {
|
|
230
|
+
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
231
|
+
this._cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
232
|
+
this._cachedTransform.b = rotating
|
|
233
|
+
? rotateData.sin * (externalTransform.b ?? identity)
|
|
234
|
+
: (externalTransform.b ?? defaultTransform.b);
|
|
235
|
+
this._cachedTransform.c = rotating
|
|
236
|
+
? -rotateData.sin * (externalTransform.c ?? identity)
|
|
237
|
+
: (externalTransform.c ?? defaultTransform.c);
|
|
238
|
+
this._cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
239
|
+
return this._cachedTransform;
|
|
240
|
+
}
|
|
196
241
|
init(id, position, overrideOptions, group) {
|
|
197
|
-
const container = this.container
|
|
242
|
+
const container = this.container;
|
|
198
243
|
this.id = id;
|
|
199
244
|
this.group = group;
|
|
200
245
|
this.effectClose = true;
|
|
@@ -254,10 +299,6 @@ export class Particle {
|
|
|
254
299
|
if (shapeData) {
|
|
255
300
|
particlesOptions.load(shapeData.particles);
|
|
256
301
|
}
|
|
257
|
-
const interactivity = new Interactivity(engine, container);
|
|
258
|
-
interactivity.load(container.actualOptions.interactivity);
|
|
259
|
-
interactivity.load(particlesOptions.interactivity);
|
|
260
|
-
this.interactivity = interactivity;
|
|
261
302
|
this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;
|
|
262
303
|
this.effectClose = effectData?.close ?? particlesOptions.effect.close;
|
|
263
304
|
this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
|
|
@@ -326,7 +367,7 @@ export class Particle {
|
|
|
326
367
|
}
|
|
327
368
|
effectDrawer?.particleInit?.(container, this);
|
|
328
369
|
shapeDrawer?.particleInit?.(container, this);
|
|
329
|
-
for (const plugin of container.plugins
|
|
370
|
+
for (const plugin of container.plugins) {
|
|
330
371
|
plugin.particleCreated?.(this);
|
|
331
372
|
}
|
|
332
373
|
}
|
package/cjs/Core/Particles.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, posOffset, qTreeCapacity, sizeFactor, squareExp, } from "./Utils/Constants.js";
|
|
2
2
|
import { EventType } from "../Enums/Types/EventType.js";
|
|
3
|
-
import { InteractionManager } from "./Utils/InteractionManager.js";
|
|
4
3
|
import { LimitMode } from "../Enums/Modes/LimitMode.js";
|
|
5
4
|
import { Particle } from "./Particle.js";
|
|
6
5
|
import { Point } from "./Utils/Point.js";
|
|
7
6
|
import { QuadTree } from "./Utils/QuadTree.js";
|
|
8
7
|
import { Rectangle } from "./Utils/Ranges.js";
|
|
9
8
|
import { getLogger } from "../Utils/LogUtils.js";
|
|
10
|
-
import { getPosition } from "../Utils/Utils.js";
|
|
11
9
|
import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
|
|
12
10
|
const qTreeRectangle = (canvasSize) => {
|
|
13
11
|
const { height, width } = canvasSize;
|
|
@@ -18,7 +16,7 @@ export class Particles {
|
|
|
18
16
|
this._addToPool = (...particles) => {
|
|
19
17
|
this._pool.push(...particles);
|
|
20
18
|
};
|
|
21
|
-
this._applyDensity = (options,
|
|
19
|
+
this._applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
22
20
|
const numberOptions = options.number;
|
|
23
21
|
if (!numberOptions.density.enable) {
|
|
24
22
|
if (group === undefined) {
|
|
@@ -29,7 +27,7 @@ export class Particles {
|
|
|
29
27
|
}
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
|
-
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor +
|
|
30
|
+
const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
|
|
33
31
|
if (group === undefined) {
|
|
34
32
|
this._limit = numberOptions.limit.value * densityFactor;
|
|
35
33
|
}
|
|
@@ -109,7 +107,6 @@ export class Particles {
|
|
|
109
107
|
this._groupLimits = new Map();
|
|
110
108
|
this._needsSort = false;
|
|
111
109
|
this._lastZIndex = 0;
|
|
112
|
-
this._interactionManager = new InteractionManager(engine, container);
|
|
113
110
|
this._pluginsInitialized = false;
|
|
114
111
|
const canvasSize = container.canvas.size;
|
|
115
112
|
this.quadTree = new QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
|
|
@@ -119,10 +116,6 @@ export class Particles {
|
|
|
119
116
|
get count() {
|
|
120
117
|
return this._array.length;
|
|
121
118
|
}
|
|
122
|
-
addManualParticles() {
|
|
123
|
-
const container = this._container, options = container.actualOptions;
|
|
124
|
-
options.manualParticles.forEach(p => this.addParticle(p.position ? getPosition(p.position, container.canvas.size) : undefined, p.options));
|
|
125
|
-
}
|
|
126
119
|
addParticle(position, overrideOptions, group, initializer) {
|
|
127
120
|
const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
|
|
128
121
|
if (limit > minLimit) {
|
|
@@ -168,22 +161,23 @@ export class Particles {
|
|
|
168
161
|
get(index) {
|
|
169
162
|
return this._array[index];
|
|
170
163
|
}
|
|
171
|
-
handleClickMode(mode) {
|
|
172
|
-
this._interactionManager.handleClickMode(mode);
|
|
173
|
-
}
|
|
174
164
|
async init() {
|
|
175
165
|
const container = this._container, options = container.actualOptions;
|
|
176
166
|
this._lastZIndex = 0;
|
|
177
167
|
this._needsSort = false;
|
|
168
|
+
for (const plugin of container.plugins) {
|
|
169
|
+
if (plugin.redrawInit) {
|
|
170
|
+
await plugin.redrawInit();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
178
173
|
await this.initPlugins();
|
|
179
174
|
let handled = false;
|
|
180
|
-
for (const plugin of container.plugins
|
|
175
|
+
for (const plugin of container.plugins) {
|
|
181
176
|
handled = plugin.particlesInitialization?.() ?? handled;
|
|
182
177
|
if (handled) {
|
|
183
178
|
break;
|
|
184
179
|
}
|
|
185
180
|
}
|
|
186
|
-
this.addManualParticles();
|
|
187
181
|
if (!handled) {
|
|
188
182
|
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
189
183
|
for (const group in groups) {
|
|
@@ -207,14 +201,13 @@ export class Particles {
|
|
|
207
201
|
const container = this._container;
|
|
208
202
|
this.movers = await this._engine.getMovers(container, true);
|
|
209
203
|
this.updaters = await this._engine.getUpdaters(container, true);
|
|
210
|
-
await this._interactionManager.init();
|
|
211
204
|
for (const pathGenerator of container.pathGenerators.values()) {
|
|
212
205
|
pathGenerator.init(container);
|
|
213
206
|
}
|
|
214
207
|
}
|
|
215
|
-
push(nb,
|
|
208
|
+
push(nb, position, overrideOptions, group) {
|
|
216
209
|
for (let i = 0; i < nb; i++) {
|
|
217
|
-
this.addParticle(
|
|
210
|
+
this.addParticle(position, overrideOptions, group);
|
|
218
211
|
}
|
|
219
212
|
}
|
|
220
213
|
async redraw() {
|
|
@@ -241,16 +234,22 @@ export class Particles {
|
|
|
241
234
|
this.removeAt(minIndex, quantity, group);
|
|
242
235
|
}
|
|
243
236
|
setDensity() {
|
|
244
|
-
const options = this._container.actualOptions, groups = options.particles.groups
|
|
237
|
+
const options = this._container.actualOptions, groups = options.particles.groups;
|
|
238
|
+
let pluginsCount = 0;
|
|
239
|
+
for (const plugin of this._container.plugins) {
|
|
240
|
+
if (plugin.particlesDensityCount) {
|
|
241
|
+
pluginsCount += plugin.particlesDensityCount();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
245
244
|
for (const group in groups) {
|
|
246
245
|
const groupData = groups[group];
|
|
247
246
|
if (!groupData) {
|
|
248
247
|
continue;
|
|
249
248
|
}
|
|
250
249
|
const groupDataOptions = loadParticlesOptions(this._engine, this._container, groupData);
|
|
251
|
-
this._applyDensity(groupDataOptions,
|
|
250
|
+
this._applyDensity(groupDataOptions, pluginsCount, group);
|
|
252
251
|
}
|
|
253
|
-
this._applyDensity(options.particles,
|
|
252
|
+
this._applyDensity(options.particles, pluginsCount);
|
|
254
253
|
}
|
|
255
254
|
setLastZIndex(zIndex) {
|
|
256
255
|
this._lastZIndex = zIndex;
|
|
@@ -265,7 +264,7 @@ export class Particles {
|
|
|
265
264
|
for (const pathGenerator of container.pathGenerators.values()) {
|
|
266
265
|
pathGenerator.update();
|
|
267
266
|
}
|
|
268
|
-
for (const plugin of container.plugins
|
|
267
|
+
for (const plugin of container.plugins) {
|
|
269
268
|
plugin.update?.(delta);
|
|
270
269
|
}
|
|
271
270
|
const resizeFactor = this._resizeFactor;
|
|
@@ -277,8 +276,12 @@ export class Particles {
|
|
|
277
276
|
particle.initialPosition.y *= resizeFactor.height;
|
|
278
277
|
}
|
|
279
278
|
particle.ignoresResizeRatio = false;
|
|
280
|
-
this.
|
|
281
|
-
|
|
279
|
+
for (const plugin of this._container.plugins) {
|
|
280
|
+
if (plugin.particleReset) {
|
|
281
|
+
plugin.particleReset(particle);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
for (const plugin of this._container.plugins) {
|
|
282
285
|
if (particle.destroyed) {
|
|
283
286
|
break;
|
|
284
287
|
}
|
|
@@ -309,13 +312,21 @@ export class Particles {
|
|
|
309
312
|
}
|
|
310
313
|
this._addToPool(...particlesToDelete);
|
|
311
314
|
}
|
|
312
|
-
|
|
315
|
+
for (const plugin of container.plugins) {
|
|
316
|
+
if (plugin.postUpdate) {
|
|
317
|
+
plugin.postUpdate(delta);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
313
320
|
for (const particle of this._array) {
|
|
314
321
|
for (const updater of this.updaters) {
|
|
315
322
|
updater.update(particle, delta);
|
|
316
323
|
}
|
|
317
324
|
if (!particle.destroyed && !particle.spawning) {
|
|
318
|
-
|
|
325
|
+
for (const plugin of container.plugins) {
|
|
326
|
+
if (plugin.postParticleUpdate) {
|
|
327
|
+
plugin.postParticleUpdate(particle, delta);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
319
330
|
}
|
|
320
331
|
}
|
|
321
332
|
delete this._resizeFactor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const generatedAttribute = "generated",
|
|
1
|
+
export const generatedAttribute = "generated", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
|
|
2
2
|
x: 0,
|
|
3
3
|
y: 0,
|
|
4
4
|
z: 0,
|
|
@@ -7,4 +7,4 @@ export const generatedAttribute = "generated", mouseDownEvent = "pointerdown", m
|
|
|
7
7
|
b: 0,
|
|
8
8
|
c: 0,
|
|
9
9
|
d: 1,
|
|
10
|
-
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, rollFactor = 1, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0,
|
|
10
|
+
}, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, rollFactor = 1, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0;
|