@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.
Files changed (171) hide show
  1. package/284.min.js +2 -0
  2. package/284.min.js.LICENSE.txt +1 -0
  3. package/721.min.js +2 -0
  4. package/721.min.js.LICENSE.txt +1 -0
  5. package/LICENSE +21 -0
  6. package/README.md +74 -0
  7. package/browser/DivType.js +5 -0
  8. package/browser/ExternalInteractorBase.js +7 -0
  9. package/browser/IExternalInteractor.js +1 -0
  10. package/browser/IInteractivityData.js +1 -0
  11. package/browser/IInteractor.js +1 -0
  12. package/browser/IMouseData.js +1 -0
  13. package/browser/IParticlesInteractor.js +1 -0
  14. package/browser/InteractionManager.js +202 -0
  15. package/browser/InteractivityConstants.js +1 -0
  16. package/browser/InteractivityDetect.js +6 -0
  17. package/browser/InteractivityEventListeners.js +235 -0
  18. package/browser/InteractivityPlugin.js +48 -0
  19. package/browser/InteractivityPluginInstance.js +52 -0
  20. package/browser/InteractorType.js +5 -0
  21. package/browser/Options/Classes/Events/ClickEvent.js +18 -0
  22. package/browser/Options/Classes/Events/DivEvent.js +27 -0
  23. package/browser/Options/Classes/Events/Events.js +26 -0
  24. package/browser/Options/Classes/Events/HoverEvent.js +18 -0
  25. package/browser/Options/Classes/Interactivity.js +22 -0
  26. package/browser/Options/Classes/Modes/Modes.js +25 -0
  27. package/browser/Options/Interfaces/Events/IClickEvent.js +1 -0
  28. package/browser/Options/Interfaces/Events/IDivEvent.js +1 -0
  29. package/browser/Options/Interfaces/Events/IEvents.js +1 -0
  30. package/browser/Options/Interfaces/Events/IHoverEvent.js +1 -0
  31. package/browser/Options/Interfaces/IInteractivity.js +1 -0
  32. package/browser/Options/Interfaces/Modes/IModeDiv.js +1 -0
  33. package/browser/Options/Interfaces/Modes/IModes.js +1 -0
  34. package/browser/ParticlesInteractorBase.js +7 -0
  35. package/browser/index.js +38 -0
  36. package/browser/package.json +1 -0
  37. package/browser/types.js +1 -0
  38. package/browser/utils.js +32 -0
  39. package/cjs/DivType.js +5 -0
  40. package/cjs/ExternalInteractorBase.js +7 -0
  41. package/cjs/IExternalInteractor.js +1 -0
  42. package/cjs/IInteractivityData.js +1 -0
  43. package/cjs/IInteractor.js +1 -0
  44. package/cjs/IMouseData.js +1 -0
  45. package/cjs/IParticlesInteractor.js +1 -0
  46. package/cjs/InteractionManager.js +202 -0
  47. package/cjs/InteractivityConstants.js +1 -0
  48. package/cjs/InteractivityDetect.js +6 -0
  49. package/cjs/InteractivityEventListeners.js +235 -0
  50. package/cjs/InteractivityPlugin.js +48 -0
  51. package/cjs/InteractivityPluginInstance.js +52 -0
  52. package/cjs/InteractorType.js +5 -0
  53. package/cjs/Options/Classes/Events/ClickEvent.js +18 -0
  54. package/cjs/Options/Classes/Events/DivEvent.js +27 -0
  55. package/cjs/Options/Classes/Events/Events.js +26 -0
  56. package/cjs/Options/Classes/Events/HoverEvent.js +18 -0
  57. package/cjs/Options/Classes/Interactivity.js +22 -0
  58. package/cjs/Options/Classes/Modes/Modes.js +25 -0
  59. package/cjs/Options/Interfaces/Events/IClickEvent.js +1 -0
  60. package/cjs/Options/Interfaces/Events/IDivEvent.js +1 -0
  61. package/cjs/Options/Interfaces/Events/IEvents.js +1 -0
  62. package/cjs/Options/Interfaces/Events/IHoverEvent.js +1 -0
  63. package/cjs/Options/Interfaces/IInteractivity.js +1 -0
  64. package/cjs/Options/Interfaces/Modes/IModeDiv.js +1 -0
  65. package/cjs/Options/Interfaces/Modes/IModes.js +1 -0
  66. package/cjs/ParticlesInteractorBase.js +7 -0
  67. package/cjs/index.js +38 -0
  68. package/cjs/package.json +1 -0
  69. package/cjs/types.js +1 -0
  70. package/cjs/utils.js +32 -0
  71. package/dist_browser_InteractivityPluginInstance_js.js +50 -0
  72. package/dist_browser_InteractivityPlugin_js.js +70 -0
  73. package/esm/DivType.js +5 -0
  74. package/esm/ExternalInteractorBase.js +7 -0
  75. package/esm/IExternalInteractor.js +1 -0
  76. package/esm/IInteractivityData.js +1 -0
  77. package/esm/IInteractor.js +1 -0
  78. package/esm/IMouseData.js +1 -0
  79. package/esm/IParticlesInteractor.js +1 -0
  80. package/esm/InteractionManager.js +202 -0
  81. package/esm/InteractivityConstants.js +1 -0
  82. package/esm/InteractivityDetect.js +6 -0
  83. package/esm/InteractivityEventListeners.js +235 -0
  84. package/esm/InteractivityPlugin.js +48 -0
  85. package/esm/InteractivityPluginInstance.js +52 -0
  86. package/esm/InteractorType.js +5 -0
  87. package/esm/Options/Classes/Events/ClickEvent.js +18 -0
  88. package/esm/Options/Classes/Events/DivEvent.js +27 -0
  89. package/esm/Options/Classes/Events/Events.js +26 -0
  90. package/esm/Options/Classes/Events/HoverEvent.js +18 -0
  91. package/esm/Options/Classes/Interactivity.js +22 -0
  92. package/esm/Options/Classes/Modes/Modes.js +25 -0
  93. package/esm/Options/Interfaces/Events/IClickEvent.js +1 -0
  94. package/esm/Options/Interfaces/Events/IDivEvent.js +1 -0
  95. package/esm/Options/Interfaces/Events/IEvents.js +1 -0
  96. package/esm/Options/Interfaces/Events/IHoverEvent.js +1 -0
  97. package/esm/Options/Interfaces/IInteractivity.js +1 -0
  98. package/esm/Options/Interfaces/Modes/IModeDiv.js +1 -0
  99. package/esm/Options/Interfaces/Modes/IModes.js +1 -0
  100. package/esm/ParticlesInteractorBase.js +7 -0
  101. package/esm/index.js +38 -0
  102. package/esm/package.json +1 -0
  103. package/esm/types.js +1 -0
  104. package/esm/utils.js +32 -0
  105. package/package.json +95 -0
  106. package/report.html +40 -0
  107. package/tsparticles.plugin.interactivity.js +395 -0
  108. package/tsparticles.plugin.interactivity.min.js +2 -0
  109. package/tsparticles.plugin.interactivity.min.js.LICENSE.txt +1 -0
  110. package/types/DivType.d.ts +4 -0
  111. package/types/ExternalInteractorBase.d.ts +15 -0
  112. package/types/IExternalInteractor.d.ts +11 -0
  113. package/types/IInteractivityData.d.ts +6 -0
  114. package/types/IInteractor.d.ts +12 -0
  115. package/types/IMouseData.d.ts +9 -0
  116. package/types/IParticlesInteractor.d.ts +7 -0
  117. package/types/InteractionManager.d.ts +27 -0
  118. package/types/InteractivityConstants.d.ts +1 -0
  119. package/types/InteractivityDetect.d.ts +5 -0
  120. package/types/InteractivityEventListeners.d.ts +23 -0
  121. package/types/InteractivityPlugin.d.ts +11 -0
  122. package/types/InteractivityPluginInstance.d.ts +20 -0
  123. package/types/InteractorType.d.ts +4 -0
  124. package/types/Options/Classes/Events/ClickEvent.d.ts +8 -0
  125. package/types/Options/Classes/Events/DivEvent.d.ts +11 -0
  126. package/types/Options/Classes/Events/Events.d.ts +12 -0
  127. package/types/Options/Classes/Events/HoverEvent.d.ts +8 -0
  128. package/types/Options/Classes/Interactivity.d.ts +14 -0
  129. package/types/Options/Classes/Modes/Modes.d.ts +10 -0
  130. package/types/Options/Interfaces/Events/IClickEvent.d.ts +5 -0
  131. package/types/Options/Interfaces/Events/IDivEvent.d.ts +8 -0
  132. package/types/Options/Interfaces/Events/IEvents.d.ts +9 -0
  133. package/types/Options/Interfaces/Events/IHoverEvent.d.ts +5 -0
  134. package/types/Options/Interfaces/IInteractivity.d.ts +9 -0
  135. package/types/Options/Interfaces/Modes/IModeDiv.d.ts +4 -0
  136. package/types/Options/Interfaces/Modes/IModes.d.ts +1 -0
  137. package/types/ParticlesInteractorBase.d.ts +15 -0
  138. package/types/index.d.ts +19 -0
  139. package/types/types.d.ts +32 -0
  140. package/types/utils.d.ts +7 -0
  141. package/umd/DivType.js +18 -0
  142. package/umd/ExternalInteractorBase.js +21 -0
  143. package/umd/IExternalInteractor.js +12 -0
  144. package/umd/IInteractivityData.js +12 -0
  145. package/umd/IInteractor.js +12 -0
  146. package/umd/IMouseData.js +12 -0
  147. package/umd/IParticlesInteractor.js +12 -0
  148. package/umd/InteractionManager.js +216 -0
  149. package/umd/InteractivityConstants.js +14 -0
  150. package/umd/InteractivityDetect.js +19 -0
  151. package/umd/InteractivityEventListeners.js +249 -0
  152. package/umd/InteractivityPlugin.js +96 -0
  153. package/umd/InteractivityPluginInstance.js +66 -0
  154. package/umd/InteractorType.js +18 -0
  155. package/umd/Options/Classes/Events/ClickEvent.js +32 -0
  156. package/umd/Options/Classes/Events/DivEvent.js +41 -0
  157. package/umd/Options/Classes/Events/Events.js +40 -0
  158. package/umd/Options/Classes/Events/HoverEvent.js +32 -0
  159. package/umd/Options/Classes/Interactivity.js +36 -0
  160. package/umd/Options/Classes/Modes/Modes.js +39 -0
  161. package/umd/Options/Interfaces/Events/IClickEvent.js +12 -0
  162. package/umd/Options/Interfaces/Events/IDivEvent.js +12 -0
  163. package/umd/Options/Interfaces/Events/IEvents.js +12 -0
  164. package/umd/Options/Interfaces/Events/IHoverEvent.js +12 -0
  165. package/umd/Options/Interfaces/IInteractivity.js +12 -0
  166. package/umd/Options/Interfaces/Modes/IModeDiv.js +12 -0
  167. package/umd/Options/Interfaces/Modes/IModes.js +12 -0
  168. package/umd/ParticlesInteractorBase.js +21 -0
  169. package/umd/index.js +88 -0
  170. package/umd/types.js +12 -0
  171. package/umd/utils.js +48 -0
@@ -0,0 +1,235 @@
1
+ import { double, executeOnSingleOrMultiple, lengthOffset, manageListener, touchDelay, visibilityChangeEvent, } from "@tsparticles/engine";
2
+ import { mouseDownEvent, mouseLeaveEvent, mouseMoveEvent, mouseOutEvent, mouseUpEvent, touchCancelEvent, touchEndEvent, touchMoveEvent, touchStartEvent, } from "./InteractivityConstants.js";
3
+ import { InteractivityDetect } from "./InteractivityDetect.js";
4
+ export class InteractivityEventListeners {
5
+ constructor(container, interactionManager) {
6
+ this._canPush = true;
7
+ this._doMouseTouchClick = e => {
8
+ const container = this._container, interactionManager = this._interactionManager, options = container.actualOptions;
9
+ if (this._canPush) {
10
+ const mouseInteractivity = interactionManager.interactivityData.mouse, mousePos = mouseInteractivity.position;
11
+ if (!mousePos) {
12
+ return;
13
+ }
14
+ mouseInteractivity.clickPosition = { ...mousePos };
15
+ mouseInteractivity.clickTime = Date.now();
16
+ const onClick = options.interactivity?.events.onClick;
17
+ if (!onClick?.mode) {
18
+ return;
19
+ }
20
+ executeOnSingleOrMultiple(onClick.mode, mode => {
21
+ interactionManager.handleClickMode(mode);
22
+ });
23
+ }
24
+ if (e.type === "touchend") {
25
+ setTimeout(() => {
26
+ this._mouseTouchFinish();
27
+ }, touchDelay);
28
+ }
29
+ };
30
+ this._handleVisibilityChange = () => {
31
+ this._mouseTouchFinish();
32
+ };
33
+ this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
34
+ const handlers = this._handlers, container = this._container, interactionManager = this._interactionManager, options = container.actualOptions, interactivityEl = interactionManager.interactivityData.element;
35
+ if (!interactivityEl) {
36
+ return;
37
+ }
38
+ const html = interactivityEl, canvas = container.canvas;
39
+ canvas.setPointerEvents(html === canvas.element ? "initial" : "none");
40
+ if (!(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
41
+ return;
42
+ }
43
+ manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
44
+ manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
45
+ manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
46
+ if (options.interactivity.events.onClick.enable) {
47
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
48
+ manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
49
+ manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
50
+ }
51
+ else {
52
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
53
+ }
54
+ manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
55
+ manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
56
+ };
57
+ this._manageListeners = add => {
58
+ const handlers = this._handlers, container = this._container, interactionManager = this._interactionManager, options = container.actualOptions, detectType = options.interactivity?.detectsOn, canvasEl = container.canvas.element;
59
+ let mouseLeaveTmpEvent = mouseLeaveEvent;
60
+ if (detectType === InteractivityDetect.window) {
61
+ interactionManager.interactivityData.element = globalThis;
62
+ mouseLeaveTmpEvent = mouseOutEvent;
63
+ }
64
+ else if (detectType === InteractivityDetect.parent && canvasEl) {
65
+ interactionManager.interactivityData.element = canvasEl.parentElement ?? canvasEl.parentNode;
66
+ }
67
+ else {
68
+ interactionManager.interactivityData.element = canvasEl;
69
+ }
70
+ this._manageInteractivityListeners(mouseLeaveTmpEvent, add);
71
+ manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
72
+ };
73
+ this._mouseDown = () => {
74
+ const { interactivityData } = this._interactionManager, { mouse } = interactivityData;
75
+ mouse.clicking = true;
76
+ mouse.downPosition = mouse.position;
77
+ };
78
+ this._mouseTouchClick = e => {
79
+ const container = this._container, interactionManager = this._interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
80
+ mouse.inside = true;
81
+ let handled = false;
82
+ const mousePosition = mouse.position;
83
+ if (!mousePosition || !options.interactivity?.events.onClick.enable) {
84
+ return;
85
+ }
86
+ for (const plugin of container.plugins) {
87
+ if (!plugin.clickPositionValid) {
88
+ continue;
89
+ }
90
+ handled = plugin.clickPositionValid(mousePosition);
91
+ if (handled) {
92
+ break;
93
+ }
94
+ }
95
+ if (!handled) {
96
+ this._doMouseTouchClick(e);
97
+ }
98
+ mouse.clicking = false;
99
+ };
100
+ this._mouseTouchFinish = () => {
101
+ const { interactivityData } = this._interactionManager, { mouse } = interactivityData;
102
+ delete mouse.position;
103
+ delete mouse.clickPosition;
104
+ delete mouse.downPosition;
105
+ interactivityData.status = mouseLeaveEvent;
106
+ mouse.inside = false;
107
+ mouse.clicking = false;
108
+ };
109
+ this._mouseTouchMove = e => {
110
+ const container = this._container, interactionManager = this._interactionManager, options = container.actualOptions, interactivity = interactionManager.interactivityData, canvasEl = container.canvas.element;
111
+ if (!interactivity.element) {
112
+ return;
113
+ }
114
+ interactivity.mouse.inside = true;
115
+ let pos;
116
+ if (e.type.startsWith("pointer")) {
117
+ this._canPush = true;
118
+ const mouseEvent = e;
119
+ if (interactivity.element === globalThis) {
120
+ if (canvasEl) {
121
+ const clientRect = canvasEl.getBoundingClientRect();
122
+ pos = {
123
+ x: mouseEvent.clientX - clientRect.left,
124
+ y: mouseEvent.clientY - clientRect.top,
125
+ };
126
+ }
127
+ }
128
+ else if (options.interactivity?.detectsOn === InteractivityDetect.parent) {
129
+ const source = mouseEvent.target, target = mouseEvent.currentTarget;
130
+ if (canvasEl) {
131
+ const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
132
+ pos = {
133
+ x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),
134
+ y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top),
135
+ };
136
+ }
137
+ else {
138
+ pos = {
139
+ x: mouseEvent.offsetX,
140
+ y: mouseEvent.offsetY,
141
+ };
142
+ }
143
+ }
144
+ else if (mouseEvent.target === canvasEl) {
145
+ pos = {
146
+ x: mouseEvent.offsetX,
147
+ y: mouseEvent.offsetY,
148
+ };
149
+ }
150
+ }
151
+ else {
152
+ this._canPush = e.type !== "touchmove";
153
+ if (canvasEl) {
154
+ const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
155
+ if (!lastTouch) {
156
+ return;
157
+ }
158
+ pos = {
159
+ x: lastTouch.clientX - canvasRect.left,
160
+ y: lastTouch.clientY - canvasRect.top,
161
+ };
162
+ }
163
+ }
164
+ const pxRatio = container.retina.pixelRatio;
165
+ if (pos) {
166
+ pos.x *= pxRatio;
167
+ pos.y *= pxRatio;
168
+ }
169
+ interactivity.mouse.position = pos;
170
+ interactivity.status = mouseMoveEvent;
171
+ };
172
+ this._touchEnd = e => {
173
+ const evt = e, touches = Array.from(evt.changedTouches);
174
+ for (const touch of touches) {
175
+ this._touches.delete(touch.identifier);
176
+ }
177
+ this._mouseTouchFinish();
178
+ };
179
+ this._touchEndClick = e => {
180
+ const evt = e, touches = Array.from(evt.changedTouches);
181
+ for (const touch of touches) {
182
+ this._touches.delete(touch.identifier);
183
+ }
184
+ this._mouseTouchClick(e);
185
+ };
186
+ this._touchStart = e => {
187
+ const evt = e, touches = Array.from(evt.changedTouches);
188
+ for (const touch of touches) {
189
+ this._touches.set(touch.identifier, performance.now());
190
+ }
191
+ this._mouseTouchMove(e);
192
+ };
193
+ this._container = container;
194
+ this._interactionManager = interactionManager;
195
+ this._touches = new Map();
196
+ this._handlers = {
197
+ mouseDown: () => {
198
+ this._mouseDown();
199
+ },
200
+ mouseLeave: () => {
201
+ this._mouseTouchFinish();
202
+ },
203
+ mouseMove: (e) => {
204
+ this._mouseTouchMove(e);
205
+ },
206
+ mouseUp: (e) => {
207
+ this._mouseTouchClick(e);
208
+ },
209
+ touchStart: (e) => {
210
+ this._touchStart(e);
211
+ },
212
+ touchMove: (e) => {
213
+ this._mouseTouchMove(e);
214
+ },
215
+ touchEnd: (e) => {
216
+ this._touchEnd(e);
217
+ },
218
+ touchCancel: (e) => {
219
+ this._touchEnd(e);
220
+ },
221
+ touchEndClick: (e) => {
222
+ this._touchEndClick(e);
223
+ },
224
+ visibilityChange: () => {
225
+ this._handleVisibilityChange();
226
+ },
227
+ };
228
+ }
229
+ addListeners() {
230
+ this._manageListeners(true);
231
+ }
232
+ removeListeners() {
233
+ this._manageListeners(false);
234
+ }
235
+ }
@@ -0,0 +1,48 @@
1
+ import { deepExtend, } from "@tsparticles/engine";
2
+ import { Interactivity } from "./Options/Classes/Interactivity.js";
3
+ export class InteractivityPlugin {
4
+ constructor(engine) {
5
+ this._engine = engine;
6
+ this.id = "interactivity";
7
+ }
8
+ async getPlugin(container) {
9
+ const { InteractivityPluginInstance } = await import("./InteractivityPluginInstance.js");
10
+ return new InteractivityPluginInstance(this._engine, container);
11
+ }
12
+ loadOptions(container, options, source) {
13
+ if (!this.needsPlugin()) {
14
+ return;
15
+ }
16
+ let interactivityOptions = options.interactivity;
17
+ if (!interactivityOptions?.load) {
18
+ options.interactivity = interactivityOptions = new Interactivity(this._engine, container);
19
+ }
20
+ interactivityOptions.load(source?.interactivity);
21
+ const interactors = this._engine.interactors?.get(container);
22
+ if (!interactors) {
23
+ return;
24
+ }
25
+ for (const interactor of interactors) {
26
+ if (interactor.loadOptions) {
27
+ interactor.loadOptions(options, source);
28
+ }
29
+ }
30
+ }
31
+ loadParticlesOptions(container, options, source) {
32
+ if (source?.interactivity) {
33
+ options.interactivity = deepExtend({}, source.interactivity);
34
+ }
35
+ const interactors = this._engine.interactors?.get(container);
36
+ if (!interactors) {
37
+ return;
38
+ }
39
+ for (const interactor of interactors) {
40
+ if (interactor.loadParticlesOptions) {
41
+ interactor.loadParticlesOptions(options, source);
42
+ }
43
+ }
44
+ }
45
+ needsPlugin() {
46
+ return true;
47
+ }
48
+ }
@@ -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,5 @@
1
+ export var InteractorType;
2
+ (function (InteractorType) {
3
+ InteractorType["external"] = "external";
4
+ InteractorType["particles"] = "particles";
5
+ })(InteractorType || (InteractorType = {}));
@@ -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 {};
@@ -0,0 +1,7 @@
1
+ import { InteractorType } from "./InteractorType.js";
2
+ export class ParticlesInteractorBase {
3
+ constructor(container) {
4
+ this.type = InteractorType.particles;
5
+ this.container = container;
6
+ }
7
+ }
package/esm/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/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/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
+ }