@tsparticles/interaction-external-bubble 3.0.0-alpha.0

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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Bubbler.js +294 -0
  4. package/browser/IBubblerProcessParam.js +1 -0
  5. package/browser/Options/Classes/Bubble.js +16 -0
  6. package/browser/Options/Classes/BubbleBase.js +34 -0
  7. package/browser/Options/Classes/BubbleDiv.js +26 -0
  8. package/browser/Options/Classes/BubbleOptions.js +1 -0
  9. package/browser/Options/Interfaces/IBubble.js +1 -0
  10. package/browser/Options/Interfaces/IBubbleBase.js +1 -0
  11. package/browser/Options/Interfaces/IBubbleDiv.js +1 -0
  12. package/browser/ProcessBubbleType.js +1 -0
  13. package/browser/Types.js +1 -0
  14. package/browser/index.js +10 -0
  15. package/cjs/Bubbler.js +309 -0
  16. package/cjs/IBubblerProcessParam.js +2 -0
  17. package/cjs/Options/Classes/Bubble.js +20 -0
  18. package/cjs/Options/Classes/BubbleBase.js +38 -0
  19. package/cjs/Options/Classes/BubbleDiv.js +30 -0
  20. package/cjs/Options/Classes/BubbleOptions.js +2 -0
  21. package/cjs/Options/Interfaces/IBubble.js +2 -0
  22. package/cjs/Options/Interfaces/IBubbleBase.js +2 -0
  23. package/cjs/Options/Interfaces/IBubbleDiv.js +2 -0
  24. package/cjs/ProcessBubbleType.js +2 -0
  25. package/cjs/Types.js +2 -0
  26. package/cjs/index.js +39 -0
  27. package/esm/Bubbler.js +294 -0
  28. package/esm/IBubblerProcessParam.js +1 -0
  29. package/esm/Options/Classes/Bubble.js +16 -0
  30. package/esm/Options/Classes/BubbleBase.js +34 -0
  31. package/esm/Options/Classes/BubbleDiv.js +26 -0
  32. package/esm/Options/Classes/BubbleOptions.js +1 -0
  33. package/esm/Options/Interfaces/IBubble.js +1 -0
  34. package/esm/Options/Interfaces/IBubbleBase.js +1 -0
  35. package/esm/Options/Interfaces/IBubbleDiv.js +1 -0
  36. package/esm/ProcessBubbleType.js +1 -0
  37. package/esm/Types.js +1 -0
  38. package/esm/index.js +10 -0
  39. package/package.json +82 -0
  40. package/report.html +39 -0
  41. package/tsparticles.interaction.external.bubble.js +520 -0
  42. package/tsparticles.interaction.external.bubble.min.js +2 -0
  43. package/tsparticles.interaction.external.bubble.min.js.LICENSE.txt +8 -0
  44. package/types/Bubbler.d.ts +20 -0
  45. package/types/IBubblerProcessParam.d.ts +10 -0
  46. package/types/Options/Classes/Bubble.d.ts +8 -0
  47. package/types/Options/Classes/BubbleBase.d.ts +13 -0
  48. package/types/Options/Classes/BubbleDiv.d.ts +10 -0
  49. package/types/Options/Classes/BubbleOptions.d.ts +7 -0
  50. package/types/Options/Interfaces/IBubble.d.ts +6 -0
  51. package/types/Options/Interfaces/IBubbleBase.d.ts +9 -0
  52. package/types/Options/Interfaces/IBubbleDiv.d.ts +4 -0
  53. package/types/ProcessBubbleType.d.ts +5 -0
  54. package/types/Types.d.ts +23 -0
  55. package/types/index.d.ts +8 -0
  56. package/umd/Bubbler.js +308 -0
  57. package/umd/IBubblerProcessParam.js +12 -0
  58. package/umd/Options/Classes/Bubble.js +30 -0
  59. package/umd/Options/Classes/BubbleBase.js +48 -0
  60. package/umd/Options/Classes/BubbleDiv.js +40 -0
  61. package/umd/Options/Classes/BubbleOptions.js +12 -0
  62. package/umd/Options/Interfaces/IBubble.js +12 -0
  63. package/umd/Options/Interfaces/IBubbleBase.js +12 -0
  64. package/umd/Options/Interfaces/IBubbleDiv.js +12 -0
  65. package/umd/ProcessBubbleType.js +12 -0
  66. package/umd/Types.js +12 -0
  67. package/umd/index.js +38 -0
@@ -0,0 +1,520 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
55
+ /******/
56
+ /************************************************************************/
57
+ /******/ /* webpack/runtime/define property getters */
58
+ /******/ (() => {
59
+ /******/ // define getter functions for harmony exports
60
+ /******/ __webpack_require__.d = (exports, definition) => {
61
+ /******/ for(var key in definition) {
62
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
63
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
64
+ /******/ }
65
+ /******/ }
66
+ /******/ };
67
+ /******/ })();
68
+ /******/
69
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
+ /******/ (() => {
71
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
+ /******/ })();
73
+ /******/
74
+ /******/ /* webpack/runtime/make namespace object */
75
+ /******/ (() => {
76
+ /******/ // define __esModule on exports
77
+ /******/ __webpack_require__.r = (exports) => {
78
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
79
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
80
+ /******/ }
81
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
82
+ /******/ };
83
+ /******/ })();
84
+ /******/
85
+ /************************************************************************/
86
+ var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
89
+ // ESM COMPAT FLAG
90
+ __webpack_require__.r(__webpack_exports__);
91
+
92
+ // EXPORTS
93
+ __webpack_require__.d(__webpack_exports__, {
94
+ "Bubble": () => (/* reexport */ Bubble),
95
+ "BubbleBase": () => (/* reexport */ BubbleBase),
96
+ "BubbleDiv": () => (/* reexport */ BubbleDiv),
97
+ "loadExternalBubbleInteraction": () => (/* binding */ loadExternalBubbleInteraction)
98
+ });
99
+
100
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
101
+ var engine_root_window_ = __webpack_require__(533);
102
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/BubbleBase.js
103
+
104
+ class BubbleBase {
105
+ constructor() {
106
+ this.distance = 200;
107
+ this.duration = 0.4;
108
+ this.mix = false;
109
+ }
110
+ load(data) {
111
+ if (!data) {
112
+ return;
113
+ }
114
+ if (data.distance !== undefined) {
115
+ this.distance = data.distance;
116
+ }
117
+ if (data.duration !== undefined) {
118
+ this.duration = data.duration;
119
+ }
120
+ if (data.mix !== undefined) {
121
+ this.mix = data.mix;
122
+ }
123
+ if (data.opacity !== undefined) {
124
+ this.opacity = data.opacity;
125
+ }
126
+ if (data.color !== undefined) {
127
+ const sourceColor = this.color instanceof Array ? undefined : this.color;
128
+ this.color = (0,engine_root_window_.executeOnSingleOrMultiple)(data.color, color => {
129
+ return engine_root_window_.OptionsColor.create(sourceColor, color);
130
+ });
131
+ }
132
+ if (data.size !== undefined) {
133
+ this.size = data.size;
134
+ }
135
+ }
136
+ }
137
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/BubbleDiv.js
138
+
139
+
140
+ class BubbleDiv extends BubbleBase {
141
+ constructor() {
142
+ super();
143
+ this.selectors = [];
144
+ }
145
+ get ids() {
146
+ return (0,engine_root_window_.executeOnSingleOrMultiple)(this.selectors, t => t.replace("#", ""));
147
+ }
148
+ set ids(value) {
149
+ this.selectors = (0,engine_root_window_.executeOnSingleOrMultiple)(value, t => `#${t}`);
150
+ }
151
+ load(data) {
152
+ super.load(data);
153
+ if (!data) {
154
+ return;
155
+ }
156
+ if (data.ids !== undefined) {
157
+ this.ids = data.ids;
158
+ }
159
+ if (data.selectors !== undefined) {
160
+ this.selectors = data.selectors;
161
+ }
162
+ }
163
+ }
164
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Bubble.js
165
+
166
+
167
+
168
+ class Bubble extends BubbleBase {
169
+ load(data) {
170
+ super.load(data);
171
+ if (!data) {
172
+ return;
173
+ }
174
+ this.divs = (0,engine_root_window_.executeOnSingleOrMultiple)(data.divs, div => {
175
+ const tmp = new BubbleDiv();
176
+ tmp.load(div);
177
+ return tmp;
178
+ });
179
+ }
180
+ }
181
+ ;// CONCATENATED MODULE: ./dist/browser/Bubbler.js
182
+
183
+
184
+ function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
185
+ if (modeValue >= optionsValue) {
186
+ const value = particleValue + (modeValue - optionsValue) * ratio;
187
+ return (0,engine_root_window_.clamp)(value, particleValue, modeValue);
188
+ } else if (modeValue < optionsValue) {
189
+ const value = particleValue - (optionsValue - modeValue) * ratio;
190
+ return (0,engine_root_window_.clamp)(value, modeValue, particleValue);
191
+ }
192
+ }
193
+ class Bubbler extends engine_root_window_.ExternalInteractorBase {
194
+ constructor(container) {
195
+ super(container);
196
+ if (!container.bubble) {
197
+ container.bubble = {};
198
+ }
199
+ this.handleClickMode = mode => {
200
+ if (mode !== "bubble") {
201
+ return;
202
+ }
203
+ if (!container.bubble) {
204
+ container.bubble = {};
205
+ }
206
+ container.bubble.clicking = true;
207
+ };
208
+ }
209
+ clear(particle, delta, force) {
210
+ if (particle.bubble.inRange && !force) {
211
+ return;
212
+ }
213
+ delete particle.bubble.div;
214
+ delete particle.bubble.opacity;
215
+ delete particle.bubble.radius;
216
+ delete particle.bubble.color;
217
+ }
218
+ init() {
219
+ const container = this.container,
220
+ bubble = container.actualOptions.interactivity.modes.bubble;
221
+ if (!bubble) {
222
+ return;
223
+ }
224
+ container.retina.bubbleModeDistance = bubble.distance * container.retina.pixelRatio;
225
+ if (bubble.size !== undefined) {
226
+ container.retina.bubbleModeSize = bubble.size * container.retina.pixelRatio;
227
+ }
228
+ }
229
+ async interact(delta) {
230
+ const options = this.container.actualOptions,
231
+ events = options.interactivity.events,
232
+ onHover = events.onHover,
233
+ onClick = events.onClick,
234
+ hoverEnabled = onHover.enable,
235
+ hoverMode = onHover.mode,
236
+ clickEnabled = onClick.enable,
237
+ clickMode = onClick.mode,
238
+ divs = events.onDiv;
239
+ if (hoverEnabled && (0,engine_root_window_.isInArray)("bubble", hoverMode)) {
240
+ this.hoverBubble(delta);
241
+ } else if (clickEnabled && (0,engine_root_window_.isInArray)("bubble", clickMode)) {
242
+ this.clickBubble(delta);
243
+ } else {
244
+ (0,engine_root_window_.divModeExecute)("bubble", divs, (selector, div) => this.singleSelectorHover(delta, selector, div));
245
+ }
246
+ }
247
+ isEnabled(particle) {
248
+ var _a;
249
+ const container = this.container,
250
+ options = container.actualOptions,
251
+ mouse = container.interactivity.mouse,
252
+ events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events,
253
+ divs = events.onDiv,
254
+ divBubble = (0,engine_root_window_.isDivModeEnabled)("bubble", divs);
255
+ if (!(divBubble || events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
256
+ return false;
257
+ }
258
+ const hoverMode = events.onHover.mode;
259
+ const clickMode = events.onClick.mode;
260
+ return (0,engine_root_window_.isInArray)("bubble", hoverMode) || (0,engine_root_window_.isInArray)("bubble", clickMode) || divBubble;
261
+ }
262
+ loadModeOptions(options, ...sources) {
263
+ if (!options.bubble) {
264
+ options.bubble = new Bubble();
265
+ }
266
+ for (const source of sources) {
267
+ options.bubble.load(source === null || source === void 0 ? void 0 : source.bubble);
268
+ }
269
+ }
270
+ reset(particle) {
271
+ particle.bubble.inRange = false;
272
+ }
273
+ clickBubble(delta) {
274
+ var _a, _b;
275
+ const container = this.container,
276
+ options = container.actualOptions,
277
+ mouseClickPos = container.interactivity.mouse.clickPosition,
278
+ bubble = options.interactivity.modes.bubble;
279
+ if (!bubble || !mouseClickPos) {
280
+ return;
281
+ }
282
+ if (!container.bubble) {
283
+ container.bubble = {};
284
+ }
285
+ const distance = container.retina.bubbleModeDistance;
286
+ if (!distance || distance < 0) {
287
+ return;
288
+ }
289
+ const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, p => this.isEnabled(p));
290
+ for (const particle of query) {
291
+ if (!container.bubble.clicking) {
292
+ continue;
293
+ }
294
+ particle.bubble.inRange = !container.bubble.durationEnd;
295
+ const pos = particle.getPosition(),
296
+ distMouse = (0,engine_root_window_.getDistance)(pos, mouseClickPos),
297
+ timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
298
+ if (timeSpent > bubble.duration) {
299
+ container.bubble.durationEnd = true;
300
+ }
301
+ if (timeSpent > bubble.duration * 2) {
302
+ container.bubble.clicking = false;
303
+ container.bubble.durationEnd = false;
304
+ }
305
+ const sizeData = {
306
+ bubbleObj: {
307
+ optValue: container.retina.bubbleModeSize,
308
+ value: particle.bubble.radius
309
+ },
310
+ particlesObj: {
311
+ optValue: (0,engine_root_window_.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio,
312
+ value: particle.size.value
313
+ },
314
+ type: "size"
315
+ };
316
+ this.process(particle, distMouse, timeSpent, sizeData);
317
+ const opacityData = {
318
+ bubbleObj: {
319
+ optValue: bubble.opacity,
320
+ value: particle.bubble.opacity
321
+ },
322
+ particlesObj: {
323
+ optValue: (0,engine_root_window_.getRangeMax)(particle.options.opacity.value),
324
+ value: (_b = (_a = particle.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1
325
+ },
326
+ type: "opacity"
327
+ };
328
+ this.process(particle, distMouse, timeSpent, opacityData);
329
+ if (!container.bubble.durationEnd) {
330
+ if (distMouse <= distance) {
331
+ this.hoverBubbleColor(particle, distMouse);
332
+ } else {
333
+ delete particle.bubble.color;
334
+ }
335
+ } else {
336
+ delete particle.bubble.color;
337
+ }
338
+ }
339
+ }
340
+ hoverBubble(delta) {
341
+ const container = this.container,
342
+ mousePos = container.interactivity.mouse.position,
343
+ distance = container.retina.bubbleModeDistance;
344
+ if (!distance || distance < 0 || mousePos === undefined) {
345
+ return;
346
+ }
347
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
348
+ for (const particle of query) {
349
+ particle.bubble.inRange = true;
350
+ const pos = particle.getPosition(),
351
+ pointDistance = (0,engine_root_window_.getDistance)(pos, mousePos),
352
+ ratio = 1 - pointDistance / distance;
353
+ if (pointDistance <= distance) {
354
+ if (ratio >= 0 && container.interactivity.status === engine_root_window_.mouseMoveEvent) {
355
+ this.hoverBubbleSize(particle, ratio);
356
+ this.hoverBubbleOpacity(particle, ratio);
357
+ this.hoverBubbleColor(particle, ratio);
358
+ }
359
+ } else {
360
+ this.reset(particle);
361
+ }
362
+ if (container.interactivity.status === engine_root_window_.mouseLeaveEvent) {
363
+ this.reset(particle);
364
+ }
365
+ }
366
+ }
367
+ hoverBubbleColor(particle, ratio, divBubble) {
368
+ const options = this.container.actualOptions;
369
+ const bubbleOptions = divBubble !== null && divBubble !== void 0 ? divBubble : options.interactivity.modes.bubble;
370
+ if (!bubbleOptions) {
371
+ return;
372
+ }
373
+ if (!particle.bubble.finalColor) {
374
+ const modeColor = bubbleOptions.color;
375
+ if (!modeColor) {
376
+ return;
377
+ }
378
+ const bubbleColor = (0,engine_root_window_.itemFromSingleOrMultiple)(modeColor);
379
+ particle.bubble.finalColor = (0,engine_root_window_.rangeColorToHsl)(bubbleColor);
380
+ }
381
+ if (!particle.bubble.finalColor) {
382
+ return;
383
+ }
384
+ if (bubbleOptions.mix) {
385
+ particle.bubble.color = undefined;
386
+ const pColor = particle.getFillColor();
387
+ particle.bubble.color = pColor ? (0,engine_root_window_.rgbToHsl)((0,engine_root_window_.colorMix)(pColor, particle.bubble.finalColor, 1 - ratio, ratio)) : particle.bubble.finalColor;
388
+ } else {
389
+ particle.bubble.color = particle.bubble.finalColor;
390
+ }
391
+ }
392
+ hoverBubbleOpacity(particle, ratio, divBubble) {
393
+ var _a, _b, _c, _d;
394
+ const container = this.container,
395
+ options = container.actualOptions,
396
+ modeOpacity = (_a = divBubble === null || divBubble === void 0 ? void 0 : divBubble.opacity) !== null && _a !== void 0 ? _a : (_b = options.interactivity.modes.bubble) === null || _b === void 0 ? void 0 : _b.opacity;
397
+ if (!modeOpacity) {
398
+ return;
399
+ }
400
+ const optOpacity = particle.options.opacity.value;
401
+ const pOpacity = (_d = (_c = particle.opacity) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 1;
402
+ const opacity = calculateBubbleValue(pOpacity, modeOpacity, (0,engine_root_window_.getRangeMax)(optOpacity), ratio);
403
+ if (opacity !== undefined) {
404
+ particle.bubble.opacity = opacity;
405
+ }
406
+ }
407
+ hoverBubbleSize(particle, ratio, divBubble) {
408
+ const container = this.container,
409
+ modeSize = (divBubble === null || divBubble === void 0 ? void 0 : divBubble.size) ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;
410
+ if (modeSize === undefined) {
411
+ return;
412
+ }
413
+ const optSize = (0,engine_root_window_.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio;
414
+ const pSize = particle.size.value;
415
+ const size = calculateBubbleValue(pSize, modeSize, optSize, ratio);
416
+ if (size !== undefined) {
417
+ particle.bubble.radius = size;
418
+ }
419
+ }
420
+ process(particle, distMouse, timeSpent, data) {
421
+ const container = this.container,
422
+ bubbleParam = data.bubbleObj.optValue,
423
+ options = container.actualOptions,
424
+ bubble = options.interactivity.modes.bubble;
425
+ if (!bubble || bubbleParam === undefined) {
426
+ return;
427
+ }
428
+ const bubbleDuration = bubble.duration,
429
+ bubbleDistance = container.retina.bubbleModeDistance,
430
+ particlesParam = data.particlesObj.optValue,
431
+ pObjBubble = data.bubbleObj.value,
432
+ pObj = data.particlesObj.value || 0,
433
+ type = data.type;
434
+ if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
435
+ return;
436
+ }
437
+ if (!container.bubble) {
438
+ container.bubble = {};
439
+ }
440
+ if (!container.bubble.durationEnd) {
441
+ if (distMouse <= bubbleDistance) {
442
+ const obj = pObjBubble !== null && pObjBubble !== void 0 ? pObjBubble : pObj;
443
+ if (obj !== bubbleParam) {
444
+ const value = pObj - timeSpent * (pObj - bubbleParam) / bubbleDuration;
445
+ if (type === "size") {
446
+ particle.bubble.radius = value;
447
+ }
448
+ if (type === "opacity") {
449
+ particle.bubble.opacity = value;
450
+ }
451
+ }
452
+ } else {
453
+ if (type === "size") {
454
+ delete particle.bubble.radius;
455
+ }
456
+ if (type === "opacity") {
457
+ delete particle.bubble.opacity;
458
+ }
459
+ }
460
+ } else if (pObjBubble) {
461
+ if (type === "size") {
462
+ delete particle.bubble.radius;
463
+ }
464
+ if (type === "opacity") {
465
+ delete particle.bubble.opacity;
466
+ }
467
+ }
468
+ }
469
+ singleSelectorHover(delta, selector, div) {
470
+ const container = this.container,
471
+ selectors = document.querySelectorAll(selector),
472
+ bubble = container.actualOptions.interactivity.modes.bubble;
473
+ if (!bubble || !selectors.length) {
474
+ return;
475
+ }
476
+ selectors.forEach(item => {
477
+ const elem = item,
478
+ pxRatio = container.retina.pixelRatio,
479
+ pos = {
480
+ x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
481
+ y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
482
+ },
483
+ repulseRadius = elem.offsetWidth / 2 * pxRatio,
484
+ area = div.type === "circle" ? new engine_root_window_.Circle(pos.x, pos.y, repulseRadius) : new engine_root_window_.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio),
485
+ query = container.particles.quadTree.query(area, p => this.isEnabled(p));
486
+ for (const particle of query) {
487
+ if (!area.contains(particle.getPosition())) {
488
+ continue;
489
+ }
490
+ particle.bubble.inRange = true;
491
+ const divs = bubble.divs;
492
+ const divBubble = (0,engine_root_window_.divMode)(divs, elem);
493
+ if (!particle.bubble.div || particle.bubble.div !== elem) {
494
+ this.clear(particle, delta, true);
495
+ particle.bubble.div = elem;
496
+ }
497
+ this.hoverBubbleSize(particle, 1, divBubble);
498
+ this.hoverBubbleOpacity(particle, 1, divBubble);
499
+ this.hoverBubbleColor(particle, 1, divBubble);
500
+ }
501
+ });
502
+ }
503
+ }
504
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
505
+
506
+ async function loadExternalBubbleInteraction(engine) {
507
+ await engine.addInteractor("externalBubble", container => new Bubbler(container));
508
+ }
509
+
510
+
511
+
512
+
513
+
514
+
515
+ })();
516
+
517
+ /******/ return __webpack_exports__;
518
+ /******/ })()
519
+ ;
520
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.interaction.external.bubble.min.js.LICENSE.txt */
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in i)("object"==typeof exports?exports:e)[o]=i[o]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function o(e){var l=i[e];if(void 0!==l)return l.exports;var b=i[e]={exports:{}};return t[e](b,b.exports,o),b.exports}o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};return(()=>{o.r(l),o.d(l,{Bubble:()=>b,BubbleBase:()=>t,BubbleDiv:()=>i,loadExternalBubbleInteraction:()=>r});var e=o(533);class t{constructor(){this.distance=200,this.duration=.4,this.mix=!1}load(t){if(t){if(void 0!==t.distance&&(this.distance=t.distance),void 0!==t.duration&&(this.duration=t.duration),void 0!==t.mix&&(this.mix=t.mix),void 0!==t.opacity&&(this.opacity=t.opacity),void 0!==t.color){const i=this.color instanceof Array?void 0:this.color;this.color=(0,e.executeOnSingleOrMultiple)(t.color,(t=>e.OptionsColor.create(i,t)))}void 0!==t.size&&(this.size=t.size)}}}class i extends t{constructor(){super(),this.selectors=[]}get ids(){return(0,e.executeOnSingleOrMultiple)(this.selectors,(e=>e.replace("#","")))}set ids(t){this.selectors=(0,e.executeOnSingleOrMultiple)(t,(e=>`#${e}`))}load(e){super.load(e),e&&(void 0!==e.ids&&(this.ids=e.ids),void 0!==e.selectors&&(this.selectors=e.selectors))}}class b extends t{load(t){super.load(t),t&&(this.divs=(0,e.executeOnSingleOrMultiple)(t.divs,(e=>{const t=new i;return t.load(e),t})))}}function n(t,i,o,l){if(i>=o){const b=t+(i-o)*l;return(0,e.clamp)(b,t,i)}if(i<o){const b=t-(o-i)*l;return(0,e.clamp)(b,i,t)}}class s extends e.ExternalInteractorBase{constructor(e){super(e),e.bubble||(e.bubble={}),this.handleClickMode=t=>{"bubble"===t&&(e.bubble||(e.bubble={}),e.bubble.clicking=!0)}}clear(e,t,i){e.bubble.inRange&&!i||(delete e.bubble.div,delete e.bubble.opacity,delete e.bubble.radius,delete e.bubble.color)}init(){const e=this.container,t=e.actualOptions.interactivity.modes.bubble;t&&(e.retina.bubbleModeDistance=t.distance*e.retina.pixelRatio,void 0!==t.size&&(e.retina.bubbleModeSize=t.size*e.retina.pixelRatio))}async interact(t){const i=this.container.actualOptions.interactivity.events,o=i.onHover,l=i.onClick,b=o.enable,n=o.mode,s=l.enable,r=l.mode,a=i.onDiv;b&&(0,e.isInArray)("bubble",n)?this.hoverBubble(t):s&&(0,e.isInArray)("bubble",r)?this.clickBubble(t):(0,e.divModeExecute)("bubble",a,((e,i)=>this.singleSelectorHover(t,e,i)))}isEnabled(t){var i;const o=this.container,l=o.actualOptions,b=o.interactivity.mouse,n=(null!==(i=null==t?void 0:t.interactivity)&&void 0!==i?i:l.interactivity).events,s=n.onDiv,r=(0,e.isDivModeEnabled)("bubble",s);if(!(r||n.onHover.enable&&b.position||n.onClick.enable&&b.clickPosition))return!1;const a=n.onHover.mode,u=n.onClick.mode;return(0,e.isInArray)("bubble",a)||(0,e.isInArray)("bubble",u)||r}loadModeOptions(e,...t){e.bubble||(e.bubble=new b);for(const i of t)e.bubble.load(null==i?void 0:i.bubble)}reset(e){e.bubble.inRange=!1}clickBubble(t){var i,o;const l=this.container,b=l.actualOptions,n=l.interactivity.mouse.clickPosition,s=b.interactivity.modes.bubble;if(!s||!n)return;l.bubble||(l.bubble={});const r=l.retina.bubbleModeDistance;if(!r||r<0)return;const a=l.particles.quadTree.queryCircle(n,r,(e=>this.isEnabled(e)));for(const t of a){if(!l.bubble.clicking)continue;t.bubble.inRange=!l.bubble.durationEnd;const b=t.getPosition(),a=(0,e.getDistance)(b,n),u=((new Date).getTime()-(l.interactivity.mouse.clickTime||0))/1e3;u>s.duration&&(l.bubble.durationEnd=!0),u>2*s.duration&&(l.bubble.clicking=!1,l.bubble.durationEnd=!1);const c={bubbleObj:{optValue:l.retina.bubbleModeSize,value:t.bubble.radius},particlesObj:{optValue:(0,e.getRangeMax)(t.options.size.value)*l.retina.pixelRatio,value:t.size.value},type:"size"};this.process(t,a,u,c);const d={bubbleObj:{optValue:s.opacity,value:t.bubble.opacity},particlesObj:{optValue:(0,e.getRangeMax)(t.options.opacity.value),value:null!==(o=null===(i=t.opacity)||void 0===i?void 0:i.value)&&void 0!==o?o:1},type:"opacity"};this.process(t,a,u,d),l.bubble.durationEnd?delete t.bubble.color:a<=r?this.hoverBubbleColor(t,a):delete t.bubble.color}}hoverBubble(t){const i=this.container,o=i.interactivity.mouse.position,l=i.retina.bubbleModeDistance;if(!l||l<0||void 0===o)return;const b=i.particles.quadTree.queryCircle(o,l,(e=>this.isEnabled(e)));for(const t of b){t.bubble.inRange=!0;const b=t.getPosition(),n=(0,e.getDistance)(b,o),s=1-n/l;n<=l?s>=0&&i.interactivity.status===e.mouseMoveEvent&&(this.hoverBubbleSize(t,s),this.hoverBubbleOpacity(t,s),this.hoverBubbleColor(t,s)):this.reset(t),i.interactivity.status===e.mouseLeaveEvent&&this.reset(t)}}hoverBubbleColor(t,i,o){const l=this.container.actualOptions,b=null!=o?o:l.interactivity.modes.bubble;if(b){if(!t.bubble.finalColor){const i=b.color;if(!i)return;const o=(0,e.itemFromSingleOrMultiple)(i);t.bubble.finalColor=(0,e.rangeColorToHsl)(o)}if(t.bubble.finalColor)if(b.mix){t.bubble.color=void 0;const o=t.getFillColor();t.bubble.color=o?(0,e.rgbToHsl)((0,e.colorMix)(o,t.bubble.finalColor,1-i,i)):t.bubble.finalColor}else t.bubble.color=t.bubble.finalColor}}hoverBubbleOpacity(t,i,o){var l,b,s,r;const a=this.container.actualOptions,u=null!==(l=null==o?void 0:o.opacity)&&void 0!==l?l:null===(b=a.interactivity.modes.bubble)||void 0===b?void 0:b.opacity;if(!u)return;const c=t.options.opacity.value,d=n(null!==(r=null===(s=t.opacity)||void 0===s?void 0:s.value)&&void 0!==r?r:1,u,(0,e.getRangeMax)(c),i);void 0!==d&&(t.bubble.opacity=d)}hoverBubbleSize(t,i,o){const l=this.container,b=(null==o?void 0:o.size)?o.size*l.retina.pixelRatio:l.retina.bubbleModeSize;if(void 0===b)return;const s=(0,e.getRangeMax)(t.options.size.value)*l.retina.pixelRatio,r=n(t.size.value,b,s,i);void 0!==r&&(t.bubble.radius=r)}process(e,t,i,o){const l=this.container,b=o.bubbleObj.optValue,n=l.actualOptions.interactivity.modes.bubble;if(!n||void 0===b)return;const s=n.duration,r=l.retina.bubbleModeDistance,a=o.particlesObj.optValue,u=o.bubbleObj.value,c=o.particlesObj.value||0,d=o.type;if(r&&!(r<0)&&b!==a)if(l.bubble||(l.bubble={}),l.bubble.durationEnd)u&&("size"===d&&delete e.bubble.radius,"opacity"===d&&delete e.bubble.opacity);else if(t<=r){if((null!=u?u:c)!==b){const t=c-i*(c-b)/s;"size"===d&&(e.bubble.radius=t),"opacity"===d&&(e.bubble.opacity=t)}}else"size"===d&&delete e.bubble.radius,"opacity"===d&&delete e.bubble.opacity}singleSelectorHover(t,i,o){const l=this.container,b=document.querySelectorAll(i),n=l.actualOptions.interactivity.modes.bubble;n&&b.length&&b.forEach((i=>{const b=i,s=l.retina.pixelRatio,r={x:(b.offsetLeft+b.offsetWidth/2)*s,y:(b.offsetTop+b.offsetHeight/2)*s},a=b.offsetWidth/2*s,u="circle"===o.type?new e.Circle(r.x,r.y,a):new e.Rectangle(b.offsetLeft*s,b.offsetTop*s,b.offsetWidth*s,b.offsetHeight*s),c=l.particles.quadTree.query(u,(e=>this.isEnabled(e)));for(const i of c){if(!u.contains(i.getPosition()))continue;i.bubble.inRange=!0;const o=n.divs,l=(0,e.divMode)(o,b);i.bubble.div&&i.bubble.div===b||(this.clear(i,t,!0),i.bubble.div=b),this.hoverBubbleSize(i,1,l),this.hoverBubbleOpacity(i,1,l),this.hoverBubbleColor(i,1,l)}}))}}async function r(e){await e.addInteractor("externalBubble",(e=>new s(e)))}})(),l})()));
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
@@ -0,0 +1,20 @@
1
+ import type { BubbleContainer, BubbleMode, IBubbleMode } from "./Types";
2
+ import { ClickMode, ExternalInteractorBase } from "@tsparticles/engine";
3
+ import type { IDelta, IModes, Modes, Particle, RecursivePartial } from "@tsparticles/engine";
4
+ export declare class Bubbler extends ExternalInteractorBase<BubbleContainer> {
5
+ handleClickMode: (mode: ClickMode | string) => void;
6
+ constructor(container: BubbleContainer);
7
+ clear(particle: Particle, delta: IDelta, force?: boolean): void;
8
+ init(): void;
9
+ interact(delta: IDelta): Promise<void>;
10
+ isEnabled(particle?: Particle): boolean;
11
+ loadModeOptions(options: Modes & BubbleMode, ...sources: RecursivePartial<(IModes & IBubbleMode) | undefined>[]): void;
12
+ reset(particle: Particle): void;
13
+ private clickBubble;
14
+ private hoverBubble;
15
+ private hoverBubbleColor;
16
+ private hoverBubbleOpacity;
17
+ private hoverBubbleSize;
18
+ private process;
19
+ private singleSelectorHover;
20
+ }
@@ -0,0 +1,10 @@
1
+ import type { ProcessBubbleType } from "./ProcessBubbleType";
2
+ export interface IBubblerProcessParam {
3
+ bubbleObj: IBubblerProcessParamObj;
4
+ particlesObj: IBubblerProcessParamObj;
5
+ type: ProcessBubbleType;
6
+ }
7
+ export interface IBubblerProcessParamObj {
8
+ optValue?: number;
9
+ value?: number;
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { IOptionLoader, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import { BubbleBase } from "./BubbleBase";
3
+ import { BubbleDiv } from "./BubbleDiv";
4
+ import type { IBubble } from "../Interfaces/IBubble";
5
+ export declare class Bubble extends BubbleBase implements IBubble, IOptionLoader<IBubble> {
6
+ divs?: SingleOrMultiple<BubbleDiv>;
7
+ load(data?: RecursivePartial<IBubble>): void;
8
+ }
@@ -0,0 +1,13 @@
1
+ import type { IOptionLoader, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import { OptionsColor } from "@tsparticles/engine";
3
+ import type { IBubbleBase } from "../Interfaces/IBubbleBase";
4
+ export declare abstract class BubbleBase implements IBubbleBase, IOptionLoader<IBubbleBase> {
5
+ color?: SingleOrMultiple<OptionsColor>;
6
+ distance: number;
7
+ duration: number;
8
+ mix: boolean;
9
+ opacity?: number;
10
+ size?: number;
11
+ constructor();
12
+ load(data?: RecursivePartial<IBubbleBase>): void;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { IOptionLoader, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import { BubbleBase } from "./BubbleBase";
3
+ import type { IBubbleDiv } from "../Interfaces/IBubbleDiv";
4
+ export declare class BubbleDiv extends BubbleBase implements IBubbleDiv, IOptionLoader<IBubbleDiv> {
5
+ selectors: SingleOrMultiple<string>;
6
+ constructor();
7
+ get ids(): SingleOrMultiple<string>;
8
+ set ids(value: SingleOrMultiple<string>);
9
+ load(data?: RecursivePartial<IBubbleDiv>): void;
10
+ }
@@ -0,0 +1,7 @@
1
+ import type { BubbleMode } from "../../Types";
2
+ import type { Options } from "@tsparticles/engine";
3
+ export type BubbleOptions = Options & {
4
+ interactivity: {
5
+ modes: BubbleMode;
6
+ };
7
+ };
@@ -0,0 +1,6 @@
1
+ import type { IBubbleBase } from "./IBubbleBase";
2
+ import type { IBubbleDiv } from "./IBubbleDiv";
3
+ import type { SingleOrMultiple } from "@tsparticles/engine";
4
+ export interface IBubble extends IBubbleBase {
5
+ divs?: SingleOrMultiple<IBubbleDiv>;
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { IOptionsColor, SingleOrMultiple } from "@tsparticles/engine";
2
+ export interface IBubbleBase {
3
+ color?: SingleOrMultiple<string | IOptionsColor>;
4
+ distance: number;
5
+ duration: number;
6
+ mix: boolean;
7
+ opacity?: number;
8
+ size?: number;
9
+ }
@@ -0,0 +1,4 @@
1
+ import type { IBubbleBase } from "./IBubbleBase";
2
+ import type { IModeDiv } from "@tsparticles/engine";
3
+ export interface IBubbleDiv extends IBubbleBase, IModeDiv {
4
+ }
@@ -0,0 +1,5 @@
1
+ export declare const enum ProcessBubbleType {
2
+ color = "color",
3
+ opacity = "opacity",
4
+ size = "size"
5
+ }
@@ -0,0 +1,23 @@
1
+ import type { Bubble } from "./Options/Classes/Bubble";
2
+ import type { BubbleOptions } from "./Options/Classes/BubbleOptions";
3
+ import type { Container } from "@tsparticles/engine";
4
+ import type { IBubble } from "./Options/Interfaces/IBubble";
5
+ export type IBubbleMode = {
6
+ bubble: IBubble;
7
+ };
8
+ export type BubbleMode = {
9
+ bubble?: Bubble;
10
+ };
11
+ interface IContainerBubble {
12
+ clicking?: boolean;
13
+ durationEnd?: boolean;
14
+ }
15
+ export type BubbleContainer = Container & {
16
+ actualOptions: BubbleOptions;
17
+ bubble?: IContainerBubble;
18
+ retina: {
19
+ bubbleModeDistance?: number;
20
+ bubbleModeSize?: number;
21
+ };
22
+ };
23
+ export {};