@tsparticles/plugin-interactivity 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/284.min.js +2 -0
- package/284.min.js.LICENSE.txt +1 -0
- package/721.min.js +2 -0
- package/721.min.js.LICENSE.txt +1 -0
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/browser/DivType.js +5 -0
- package/browser/ExternalInteractorBase.js +7 -0
- package/browser/IExternalInteractor.js +1 -0
- package/browser/IInteractivityData.js +1 -0
- package/browser/IInteractor.js +1 -0
- package/browser/IMouseData.js +1 -0
- package/browser/IParticlesInteractor.js +1 -0
- package/browser/InteractionManager.js +202 -0
- package/browser/InteractivityConstants.js +1 -0
- package/browser/InteractivityDetect.js +6 -0
- package/browser/InteractivityEventListeners.js +235 -0
- package/browser/InteractivityPlugin.js +48 -0
- package/browser/InteractivityPluginInstance.js +52 -0
- package/browser/InteractorType.js +5 -0
- package/browser/Options/Classes/Events/ClickEvent.js +18 -0
- package/browser/Options/Classes/Events/DivEvent.js +27 -0
- package/browser/Options/Classes/Events/Events.js +26 -0
- package/browser/Options/Classes/Events/HoverEvent.js +18 -0
- package/browser/Options/Classes/Interactivity.js +22 -0
- package/browser/Options/Classes/Modes/Modes.js +25 -0
- package/browser/Options/Interfaces/Events/IClickEvent.js +1 -0
- package/browser/Options/Interfaces/Events/IDivEvent.js +1 -0
- package/browser/Options/Interfaces/Events/IEvents.js +1 -0
- package/browser/Options/Interfaces/Events/IHoverEvent.js +1 -0
- package/browser/Options/Interfaces/IInteractivity.js +1 -0
- package/browser/Options/Interfaces/Modes/IModeDiv.js +1 -0
- package/browser/Options/Interfaces/Modes/IModes.js +1 -0
- package/browser/ParticlesInteractorBase.js +7 -0
- package/browser/index.js +38 -0
- package/browser/package.json +1 -0
- package/browser/types.js +1 -0
- package/browser/utils.js +32 -0
- package/cjs/DivType.js +5 -0
- package/cjs/ExternalInteractorBase.js +7 -0
- package/cjs/IExternalInteractor.js +1 -0
- package/cjs/IInteractivityData.js +1 -0
- package/cjs/IInteractor.js +1 -0
- package/cjs/IMouseData.js +1 -0
- package/cjs/IParticlesInteractor.js +1 -0
- package/cjs/InteractionManager.js +202 -0
- package/cjs/InteractivityConstants.js +1 -0
- package/cjs/InteractivityDetect.js +6 -0
- package/cjs/InteractivityEventListeners.js +235 -0
- package/cjs/InteractivityPlugin.js +48 -0
- package/cjs/InteractivityPluginInstance.js +52 -0
- package/cjs/InteractorType.js +5 -0
- package/cjs/Options/Classes/Events/ClickEvent.js +18 -0
- package/cjs/Options/Classes/Events/DivEvent.js +27 -0
- package/cjs/Options/Classes/Events/Events.js +26 -0
- package/cjs/Options/Classes/Events/HoverEvent.js +18 -0
- package/cjs/Options/Classes/Interactivity.js +22 -0
- package/cjs/Options/Classes/Modes/Modes.js +25 -0
- package/cjs/Options/Interfaces/Events/IClickEvent.js +1 -0
- package/cjs/Options/Interfaces/Events/IDivEvent.js +1 -0
- package/cjs/Options/Interfaces/Events/IEvents.js +1 -0
- package/cjs/Options/Interfaces/Events/IHoverEvent.js +1 -0
- package/cjs/Options/Interfaces/IInteractivity.js +1 -0
- package/cjs/Options/Interfaces/Modes/IModeDiv.js +1 -0
- package/cjs/Options/Interfaces/Modes/IModes.js +1 -0
- package/cjs/ParticlesInteractorBase.js +7 -0
- package/cjs/index.js +38 -0
- package/cjs/package.json +1 -0
- package/cjs/types.js +1 -0
- package/cjs/utils.js +32 -0
- package/dist_browser_InteractivityPluginInstance_js.js +50 -0
- package/dist_browser_InteractivityPlugin_js.js +70 -0
- package/esm/DivType.js +5 -0
- package/esm/ExternalInteractorBase.js +7 -0
- package/esm/IExternalInteractor.js +1 -0
- package/esm/IInteractivityData.js +1 -0
- package/esm/IInteractor.js +1 -0
- package/esm/IMouseData.js +1 -0
- package/esm/IParticlesInteractor.js +1 -0
- package/esm/InteractionManager.js +202 -0
- package/esm/InteractivityConstants.js +1 -0
- package/esm/InteractivityDetect.js +6 -0
- package/esm/InteractivityEventListeners.js +235 -0
- package/esm/InteractivityPlugin.js +48 -0
- package/esm/InteractivityPluginInstance.js +52 -0
- package/esm/InteractorType.js +5 -0
- package/esm/Options/Classes/Events/ClickEvent.js +18 -0
- package/esm/Options/Classes/Events/DivEvent.js +27 -0
- package/esm/Options/Classes/Events/Events.js +26 -0
- package/esm/Options/Classes/Events/HoverEvent.js +18 -0
- package/esm/Options/Classes/Interactivity.js +22 -0
- package/esm/Options/Classes/Modes/Modes.js +25 -0
- package/esm/Options/Interfaces/Events/IClickEvent.js +1 -0
- package/esm/Options/Interfaces/Events/IDivEvent.js +1 -0
- package/esm/Options/Interfaces/Events/IEvents.js +1 -0
- package/esm/Options/Interfaces/Events/IHoverEvent.js +1 -0
- package/esm/Options/Interfaces/IInteractivity.js +1 -0
- package/esm/Options/Interfaces/Modes/IModeDiv.js +1 -0
- package/esm/Options/Interfaces/Modes/IModes.js +1 -0
- package/esm/ParticlesInteractorBase.js +7 -0
- package/esm/index.js +38 -0
- package/esm/package.json +1 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +32 -0
- package/package.json +95 -0
- package/report.html +40 -0
- package/tsparticles.plugin.interactivity.js +395 -0
- package/tsparticles.plugin.interactivity.min.js +2 -0
- package/tsparticles.plugin.interactivity.min.js.LICENSE.txt +1 -0
- package/types/DivType.d.ts +4 -0
- package/types/ExternalInteractorBase.d.ts +15 -0
- package/types/IExternalInteractor.d.ts +11 -0
- package/types/IInteractivityData.d.ts +6 -0
- package/types/IInteractor.d.ts +12 -0
- package/types/IMouseData.d.ts +9 -0
- package/types/IParticlesInteractor.d.ts +7 -0
- package/types/InteractionManager.d.ts +27 -0
- package/types/InteractivityConstants.d.ts +1 -0
- package/types/InteractivityDetect.d.ts +5 -0
- package/types/InteractivityEventListeners.d.ts +23 -0
- package/types/InteractivityPlugin.d.ts +11 -0
- package/types/InteractivityPluginInstance.d.ts +20 -0
- package/types/InteractorType.d.ts +4 -0
- package/types/Options/Classes/Events/ClickEvent.d.ts +8 -0
- package/types/Options/Classes/Events/DivEvent.d.ts +11 -0
- package/types/Options/Classes/Events/Events.d.ts +12 -0
- package/types/Options/Classes/Events/HoverEvent.d.ts +8 -0
- package/types/Options/Classes/Interactivity.d.ts +14 -0
- package/types/Options/Classes/Modes/Modes.d.ts +10 -0
- package/types/Options/Interfaces/Events/IClickEvent.d.ts +5 -0
- package/types/Options/Interfaces/Events/IDivEvent.d.ts +8 -0
- package/types/Options/Interfaces/Events/IEvents.d.ts +9 -0
- package/types/Options/Interfaces/Events/IHoverEvent.d.ts +5 -0
- package/types/Options/Interfaces/IInteractivity.d.ts +9 -0
- package/types/Options/Interfaces/Modes/IModeDiv.d.ts +4 -0
- package/types/Options/Interfaces/Modes/IModes.d.ts +1 -0
- package/types/ParticlesInteractorBase.d.ts +15 -0
- package/types/index.d.ts +19 -0
- package/types/types.d.ts +32 -0
- package/types/utils.d.ts +7 -0
- package/umd/DivType.js +18 -0
- package/umd/ExternalInteractorBase.js +21 -0
- package/umd/IExternalInteractor.js +12 -0
- package/umd/IInteractivityData.js +12 -0
- package/umd/IInteractor.js +12 -0
- package/umd/IMouseData.js +12 -0
- package/umd/IParticlesInteractor.js +12 -0
- package/umd/InteractionManager.js +216 -0
- package/umd/InteractivityConstants.js +14 -0
- package/umd/InteractivityDetect.js +19 -0
- package/umd/InteractivityEventListeners.js +249 -0
- package/umd/InteractivityPlugin.js +96 -0
- package/umd/InteractivityPluginInstance.js +66 -0
- package/umd/InteractorType.js +18 -0
- package/umd/Options/Classes/Events/ClickEvent.js +32 -0
- package/umd/Options/Classes/Events/DivEvent.js +41 -0
- package/umd/Options/Classes/Events/Events.js +40 -0
- package/umd/Options/Classes/Events/HoverEvent.js +32 -0
- package/umd/Options/Classes/Interactivity.js +36 -0
- package/umd/Options/Classes/Modes/Modes.js +39 -0
- package/umd/Options/Interfaces/Events/IClickEvent.js +12 -0
- package/umd/Options/Interfaces/Events/IDivEvent.js +12 -0
- package/umd/Options/Interfaces/Events/IEvents.js +12 -0
- package/umd/Options/Interfaces/Events/IHoverEvent.js +12 -0
- package/umd/Options/Interfaces/IInteractivity.js +12 -0
- package/umd/Options/Interfaces/Modes/IModeDiv.js +12 -0
- package/umd/Options/Interfaces/Modes/IModes.js +12 -0
- package/umd/ParticlesInteractorBase.js +21 -0
- package/umd/index.js +88 -0
- package/umd/types.js +12 -0
- package/umd/utils.js +48 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { InteractionManager } from "./InteractionManager.js";
|
|
2
|
+
import { Interactivity } from "./Options/Classes/Interactivity.js";
|
|
3
|
+
export class InteractivityPluginInstance {
|
|
4
|
+
constructor(engine, container) {
|
|
5
|
+
this._container = container;
|
|
6
|
+
this._engine = engine;
|
|
7
|
+
this.interactionManager = new InteractionManager(engine, container);
|
|
8
|
+
this._container.addClickHandler = (callback) => {
|
|
9
|
+
this.interactionManager.addClickHandler(callback);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
addClickHandler(callback) {
|
|
13
|
+
this.interactionManager.addClickHandler(callback);
|
|
14
|
+
}
|
|
15
|
+
clearClickHandlers() {
|
|
16
|
+
this.interactionManager.clearClickHandlers();
|
|
17
|
+
}
|
|
18
|
+
destroy() {
|
|
19
|
+
this.clearClickHandlers();
|
|
20
|
+
this._engine.interactors?.delete(this._container);
|
|
21
|
+
}
|
|
22
|
+
particleCreated(particle) {
|
|
23
|
+
const interactivityParticle = particle, interactivity = new Interactivity(this._engine, this._container);
|
|
24
|
+
interactivity.load(this._container.actualOptions.interactivity);
|
|
25
|
+
interactivity.load(interactivityParticle.options.interactivity);
|
|
26
|
+
interactivityParticle.interactivity = interactivity;
|
|
27
|
+
}
|
|
28
|
+
particleReset(particle) {
|
|
29
|
+
this.interactionManager.reset(particle);
|
|
30
|
+
}
|
|
31
|
+
postParticleUpdate(particle, delta) {
|
|
32
|
+
this.interactionManager.particlesInteract(particle, delta);
|
|
33
|
+
}
|
|
34
|
+
postUpdate(delta) {
|
|
35
|
+
this.interactionManager.externalInteract(delta);
|
|
36
|
+
}
|
|
37
|
+
async preInit() {
|
|
38
|
+
await this.interactionManager.init();
|
|
39
|
+
}
|
|
40
|
+
async redrawInit() {
|
|
41
|
+
await this.interactionManager.init();
|
|
42
|
+
}
|
|
43
|
+
start() {
|
|
44
|
+
this.interactionManager.addListeners();
|
|
45
|
+
this.interactionManager.startObserving();
|
|
46
|
+
return Promise.resolve();
|
|
47
|
+
}
|
|
48
|
+
stop() {
|
|
49
|
+
this.interactionManager.removeListeners();
|
|
50
|
+
this.interactionManager.stopObserving();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class ClickEvent {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.enable = false;
|
|
5
|
+
this.mode = [];
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.enable !== undefined) {
|
|
12
|
+
this.enable = data.enable;
|
|
13
|
+
}
|
|
14
|
+
if (data.mode !== undefined) {
|
|
15
|
+
this.mode = data.mode;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { DivType } from "../../../DivType.js";
|
|
3
|
+
export class DivEvent {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.selectors = [];
|
|
6
|
+
this.enable = false;
|
|
7
|
+
this.mode = [];
|
|
8
|
+
this.type = DivType.circle;
|
|
9
|
+
}
|
|
10
|
+
load(data) {
|
|
11
|
+
if (isNull(data)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (data.selectors !== undefined) {
|
|
15
|
+
this.selectors = data.selectors;
|
|
16
|
+
}
|
|
17
|
+
if (data.enable !== undefined) {
|
|
18
|
+
this.enable = data.enable;
|
|
19
|
+
}
|
|
20
|
+
if (data.mode !== undefined) {
|
|
21
|
+
this.mode = data.mode;
|
|
22
|
+
}
|
|
23
|
+
if (data.type !== undefined) {
|
|
24
|
+
this.type = data.type;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { executeOnSingleOrMultiple, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { ClickEvent } from "./ClickEvent.js";
|
|
3
|
+
import { DivEvent } from "./DivEvent.js";
|
|
4
|
+
import { HoverEvent } from "./HoverEvent.js";
|
|
5
|
+
export class Events {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.onClick = new ClickEvent();
|
|
8
|
+
this.onDiv = new DivEvent();
|
|
9
|
+
this.onHover = new HoverEvent();
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (isNull(data)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.onClick.load(data.onClick);
|
|
16
|
+
const onDiv = data.onDiv;
|
|
17
|
+
if (onDiv !== undefined) {
|
|
18
|
+
this.onDiv = executeOnSingleOrMultiple(onDiv, t => {
|
|
19
|
+
const tmp = new DivEvent();
|
|
20
|
+
tmp.load(t);
|
|
21
|
+
return tmp;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
this.onHover.load(data.onHover);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class HoverEvent {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.enable = false;
|
|
5
|
+
this.mode = [];
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.enable !== undefined) {
|
|
12
|
+
this.enable = data.enable;
|
|
13
|
+
}
|
|
14
|
+
if (data.mode !== undefined) {
|
|
15
|
+
this.mode = data.mode;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { Events } from "./Events/Events.js";
|
|
3
|
+
import { InteractivityDetect } from "../../InteractivityDetect.js";
|
|
4
|
+
import { Modes } from "./Modes/Modes.js";
|
|
5
|
+
export class Interactivity {
|
|
6
|
+
constructor(engine, container) {
|
|
7
|
+
this.detectsOn = InteractivityDetect.window;
|
|
8
|
+
this.events = new Events();
|
|
9
|
+
this.modes = new Modes(engine, container);
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (isNull(data)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const detectsOn = data.detectsOn;
|
|
16
|
+
if (detectsOn !== undefined) {
|
|
17
|
+
this.detectsOn = detectsOn;
|
|
18
|
+
}
|
|
19
|
+
this.events.load(data.events);
|
|
20
|
+
this.modes.load(data.modes);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class Modes {
|
|
3
|
+
constructor(engine, container) {
|
|
4
|
+
this._engine = engine;
|
|
5
|
+
this._container = container;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (isNull(data)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!this._container) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const interactors = this._engine.interactors?.get(this._container);
|
|
15
|
+
if (!interactors) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
for (const interactor of interactors) {
|
|
19
|
+
if (!interactor.loadModeOptions) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
interactor.loadModeOptions(this, data);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getItemsFromInitializer } from "@tsparticles/engine";
|
|
2
|
+
export function loadInteractivityPlugin(engine) {
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.4");
|
|
4
|
+
engine.register(async (e) => {
|
|
5
|
+
const interactivityEngine = e, { InteractivityPlugin } = await import("./InteractivityPlugin.js");
|
|
6
|
+
interactivityEngine.addPlugin(new InteractivityPlugin(interactivityEngine));
|
|
7
|
+
interactivityEngine.interactorsInitializers ??= new Map();
|
|
8
|
+
interactivityEngine.interactors ??= new Map();
|
|
9
|
+
interactivityEngine.addInteractor = (name, interactorInitializer) => {
|
|
10
|
+
interactivityEngine.interactorsInitializers ??= new Map();
|
|
11
|
+
interactivityEngine.interactorsInitializers.set(name, interactorInitializer);
|
|
12
|
+
};
|
|
13
|
+
interactivityEngine.getInteractors = async (container, force = false) => {
|
|
14
|
+
interactivityEngine.interactors ??= new Map();
|
|
15
|
+
interactivityEngine.interactorsInitializers ??= new Map();
|
|
16
|
+
return getItemsFromInitializer(container, interactivityEngine.interactors, interactivityEngine.interactorsInitializers, force);
|
|
17
|
+
};
|
|
18
|
+
interactivityEngine.setOnClickHandler = (callback) => {
|
|
19
|
+
const { items } = interactivityEngine;
|
|
20
|
+
if (!items.length) {
|
|
21
|
+
throw new Error("Click handlers can only be set after calling tsParticles.load()");
|
|
22
|
+
}
|
|
23
|
+
items.forEach(item => {
|
|
24
|
+
const interactivityContainer = item;
|
|
25
|
+
interactivityContainer.addClickHandler?.(callback);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export * from "./DivType.js";
|
|
31
|
+
export * from "./ExternalInteractorBase.js";
|
|
32
|
+
export * from "./InteractivityConstants.js";
|
|
33
|
+
export * from "./InteractivityDetect.js";
|
|
34
|
+
export * from "./InteractorType.js";
|
|
35
|
+
export * from "./ParticlesInteractorBase.js";
|
|
36
|
+
export * from "./utils.js";
|
|
37
|
+
export * from "./Options/Classes/Events/DivEvent.js";
|
|
38
|
+
export * from "./Options/Classes/Modes/Modes.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/browser/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/utils.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { executeOnSingleOrMultiple, findItemFromSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
|
|
2
|
+
function checkSelector(element, selectors) {
|
|
3
|
+
const res = executeOnSingleOrMultiple(selectors, selector => {
|
|
4
|
+
return element.matches(selector);
|
|
5
|
+
});
|
|
6
|
+
return isArray(res) ? res.some(t => t) : res;
|
|
7
|
+
}
|
|
8
|
+
export function isDivModeEnabled(mode, divs) {
|
|
9
|
+
return !!findItemFromSingleOrMultiple(divs, t => t.enable && isInArray(mode, t.mode));
|
|
10
|
+
}
|
|
11
|
+
export function divModeExecute(mode, divs, callback) {
|
|
12
|
+
executeOnSingleOrMultiple(divs, div => {
|
|
13
|
+
const divMode = div.mode, divEnabled = div.enable;
|
|
14
|
+
if (divEnabled && isInArray(mode, divMode)) {
|
|
15
|
+
singleDivModeExecute(div, callback);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function singleDivModeExecute(div, callback) {
|
|
20
|
+
const selectors = div.selectors;
|
|
21
|
+
executeOnSingleOrMultiple(selectors, selector => {
|
|
22
|
+
callback(selector, div);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function divMode(divs, element) {
|
|
26
|
+
if (!element || !divs) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
return findItemFromSingleOrMultiple(divs, div => {
|
|
30
|
+
return checkSelector(element, div.selectors);
|
|
31
|
+
});
|
|
32
|
+
}
|
package/cjs/DivType.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { clickRadius, minCoordinate, safeIntersectionObserver, touchEndLengthOffset, } from "@tsparticles/engine";
|
|
2
|
+
import { clickEvent, touchCancelEvent, touchEndEvent, touchMoveEvent, touchStartEvent, } from "./InteractivityConstants.js";
|
|
3
|
+
import { InteractivityEventListeners } from "./InteractivityEventListeners.js";
|
|
4
|
+
import { InteractorType } from "./InteractorType.js";
|
|
5
|
+
export class InteractionManager {
|
|
6
|
+
constructor(engine, container) {
|
|
7
|
+
this.container = container;
|
|
8
|
+
this._intersectionManager = entries => {
|
|
9
|
+
const { container } = this;
|
|
10
|
+
if (container.destroyed || !container.actualOptions.pauseOnOutsideViewport) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (entry.target !== this.interactivityData.element) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (entry.isIntersecting) {
|
|
18
|
+
container.play();
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
container.pause();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this._engine = engine;
|
|
26
|
+
this._interactors = [];
|
|
27
|
+
this._externalInteractors = [];
|
|
28
|
+
this._particleInteractors = [];
|
|
29
|
+
this._clickHandlers = new Map();
|
|
30
|
+
this._eventListeners = new InteractivityEventListeners(container, this);
|
|
31
|
+
this.interactivityData = {
|
|
32
|
+
mouse: {
|
|
33
|
+
clicking: false,
|
|
34
|
+
inside: false,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
this._intersectionObserver = safeIntersectionObserver(entries => {
|
|
38
|
+
this._intersectionManager(entries);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
addClickHandler(callback) {
|
|
42
|
+
const { container, interactivityData } = this;
|
|
43
|
+
if (container.destroyed) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const el = interactivityData.element;
|
|
47
|
+
if (!el) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const clickOrTouchHandler = (e, pos, radius) => {
|
|
51
|
+
if (container.destroyed) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const pxRatio = container.retina.pixelRatio, posRetina = {
|
|
55
|
+
x: pos.x * pxRatio,
|
|
56
|
+
y: pos.y * pxRatio,
|
|
57
|
+
}, particles = container.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
|
|
58
|
+
callback(e, particles);
|
|
59
|
+
}, clickHandler = (e) => {
|
|
60
|
+
if (container.destroyed) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const mouseEvent = e, pos = {
|
|
64
|
+
x: mouseEvent.offsetX,
|
|
65
|
+
y: mouseEvent.offsetY,
|
|
66
|
+
};
|
|
67
|
+
clickOrTouchHandler(e, pos, clickRadius);
|
|
68
|
+
}, touchStartHandler = () => {
|
|
69
|
+
if (container.destroyed) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
touched = true;
|
|
73
|
+
touchMoved = false;
|
|
74
|
+
}, touchMoveHandler = () => {
|
|
75
|
+
if (container.destroyed) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
touchMoved = true;
|
|
79
|
+
}, touchEndHandler = (e) => {
|
|
80
|
+
if (container.destroyed) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (touched && !touchMoved) {
|
|
84
|
+
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - touchEndLengthOffset];
|
|
85
|
+
if (!lastTouch) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const element = container.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
|
|
89
|
+
x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
|
|
90
|
+
y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
|
|
91
|
+
};
|
|
92
|
+
clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
|
|
93
|
+
}
|
|
94
|
+
touched = false;
|
|
95
|
+
touchMoved = false;
|
|
96
|
+
}, touchCancelHandler = () => {
|
|
97
|
+
if (container.destroyed) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
touched = false;
|
|
101
|
+
touchMoved = false;
|
|
102
|
+
};
|
|
103
|
+
let touched = false, touchMoved = false;
|
|
104
|
+
this._clickHandlers.set(clickEvent, clickHandler);
|
|
105
|
+
this._clickHandlers.set(touchStartEvent, touchStartHandler);
|
|
106
|
+
this._clickHandlers.set(touchMoveEvent, touchMoveHandler);
|
|
107
|
+
this._clickHandlers.set(touchEndEvent, touchEndHandler);
|
|
108
|
+
this._clickHandlers.set(touchCancelEvent, touchCancelHandler);
|
|
109
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
110
|
+
el.addEventListener(key, handler);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
addListeners() {
|
|
114
|
+
this._eventListeners.addListeners();
|
|
115
|
+
}
|
|
116
|
+
clearClickHandlers() {
|
|
117
|
+
const { container, interactivityData } = this;
|
|
118
|
+
if (container.destroyed) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
for (const [key, handler] of this._clickHandlers) {
|
|
122
|
+
interactivityData.element?.removeEventListener(key, handler);
|
|
123
|
+
}
|
|
124
|
+
this._clickHandlers.clear();
|
|
125
|
+
}
|
|
126
|
+
externalInteract(delta) {
|
|
127
|
+
for (const interactor of this._externalInteractors) {
|
|
128
|
+
const { interactivityData } = this;
|
|
129
|
+
if (interactor.isEnabled(interactivityData)) {
|
|
130
|
+
interactor.interact(interactivityData, delta);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
handleClickMode(mode) {
|
|
135
|
+
if (this.container.destroyed) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const { interactivityData } = this;
|
|
139
|
+
for (const interactor of this._externalInteractors) {
|
|
140
|
+
interactor.handleClickMode?.(mode, interactivityData);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async init() {
|
|
144
|
+
const interactors = await this._engine.getInteractors?.(this.container, true);
|
|
145
|
+
if (!interactors) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this._interactors = interactors;
|
|
149
|
+
this._externalInteractors = [];
|
|
150
|
+
this._particleInteractors = [];
|
|
151
|
+
for (const interactor of this._interactors) {
|
|
152
|
+
switch (interactor.type) {
|
|
153
|
+
case InteractorType.external:
|
|
154
|
+
this._externalInteractors.push(interactor);
|
|
155
|
+
break;
|
|
156
|
+
case InteractorType.particles:
|
|
157
|
+
this._particleInteractors.push(interactor);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
interactor.init();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
particlesInteract(particle, delta) {
|
|
164
|
+
const { interactivityData } = this;
|
|
165
|
+
for (const interactor of this._externalInteractors) {
|
|
166
|
+
interactor.clear(particle, delta);
|
|
167
|
+
}
|
|
168
|
+
for (const interactor of this._particleInteractors) {
|
|
169
|
+
if (interactor.isEnabled(particle, interactivityData)) {
|
|
170
|
+
interactor.interact(particle, interactivityData, delta);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
removeListeners() {
|
|
175
|
+
this._eventListeners.removeListeners();
|
|
176
|
+
}
|
|
177
|
+
reset(particle) {
|
|
178
|
+
const { interactivityData } = this;
|
|
179
|
+
for (const interactor of this._externalInteractors) {
|
|
180
|
+
if (interactor.isEnabled(interactivityData)) {
|
|
181
|
+
interactor.reset(interactivityData, particle);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const interactor of this._particleInteractors) {
|
|
185
|
+
if (interactor.isEnabled(particle, interactivityData)) {
|
|
186
|
+
interactor.reset(interactivityData, particle);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
startObserving() {
|
|
191
|
+
const { interactivityData } = this;
|
|
192
|
+
if (interactivityData.element instanceof HTMLElement && this._intersectionObserver) {
|
|
193
|
+
this._intersectionObserver.observe(interactivityData.element);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
stopObserving() {
|
|
197
|
+
const { interactivityData } = this;
|
|
198
|
+
if (interactivityData.element instanceof HTMLElement && this._intersectionObserver) {
|
|
199
|
+
this._intersectionObserver.unobserve(interactivityData.element);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseOutEvent = "pointerout", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
|