@tsparticles/plugin-interactivity 4.0.0-alpha.14

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