@tsparticles/interaction-external-bubble 3.0.0-alpha.0 → 3.0.0-beta.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 (46) hide show
  1. package/README.md +25 -19
  2. package/browser/Bubbler.js +211 -234
  3. package/browser/Options/Classes/Bubble.js +1 -1
  4. package/browser/Options/Classes/BubbleBase.js +2 -2
  5. package/browser/Options/Classes/BubbleDiv.js +0 -10
  6. package/browser/Utils.js +11 -0
  7. package/browser/index.js +2 -2
  8. package/cjs/Bubbler.js +218 -252
  9. package/cjs/Options/Classes/Bubble.js +1 -1
  10. package/cjs/Options/Classes/BubbleBase.js +1 -1
  11. package/cjs/Options/Classes/BubbleDiv.js +0 -10
  12. package/cjs/Utils.js +15 -0
  13. package/cjs/index.js +2 -13
  14. package/esm/Bubbler.js +211 -234
  15. package/esm/Options/Classes/Bubble.js +1 -1
  16. package/esm/Options/Classes/BubbleBase.js +2 -2
  17. package/esm/Options/Classes/BubbleDiv.js +0 -10
  18. package/esm/Utils.js +11 -0
  19. package/esm/index.js +2 -2
  20. package/package.json +6 -5
  21. package/report.html +4 -4
  22. package/tsparticles.interaction.external.bubble.js +255 -262
  23. package/tsparticles.interaction.external.bubble.min.js +1 -1
  24. package/tsparticles.interaction.external.bubble.min.js.LICENSE.txt +1 -8
  25. package/types/Bubbler.d.ts +8 -9
  26. package/types/{IBubblerProcessParam.d.ts → Interfaces.d.ts} +2 -2
  27. package/types/Options/Classes/Bubble.d.ts +1 -1
  28. package/types/Options/Classes/BubbleBase.d.ts +1 -2
  29. package/types/Options/Classes/BubbleDiv.d.ts +1 -3
  30. package/types/Utils.d.ts +1 -0
  31. package/types/index.d.ts +1 -1
  32. package/umd/Bubbler.js +211 -234
  33. package/umd/Options/Classes/Bubble.js +2 -2
  34. package/umd/Options/Classes/BubbleBase.js +1 -1
  35. package/umd/Options/Classes/BubbleDiv.js +1 -11
  36. package/umd/Utils.js +25 -0
  37. package/umd/index.js +2 -2
  38. /package/browser/{IBubblerProcessParam.js → Enums.js} +0 -0
  39. /package/browser/{ProcessBubbleType.js → Interfaces.js} +0 -0
  40. /package/cjs/{IBubblerProcessParam.js → Enums.js} +0 -0
  41. /package/cjs/{ProcessBubbleType.js → Interfaces.js} +0 -0
  42. /package/esm/{IBubblerProcessParam.js → Enums.js} +0 -0
  43. /package/esm/{ProcessBubbleType.js → Interfaces.js} +0 -0
  44. /package/types/{ProcessBubbleType.d.ts → Enums.d.ts} +0 -0
  45. /package/umd/{IBubblerProcessParam.js → Enums.js} +0 -0
  46. /package/umd/{ProcessBubbleType.js → Interfaces.js} +0 -0
package/cjs/Bubbler.js CHANGED
@@ -1,30 +1,214 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Bubbler = void 0;
13
4
  const engine_1 = require("@tsparticles/engine");
14
5
  const Bubble_1 = require("./Options/Classes/Bubble");
15
- function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
16
- if (modeValue >= optionsValue) {
17
- const value = particleValue + (modeValue - optionsValue) * ratio;
18
- return (0, engine_1.clamp)(value, particleValue, modeValue);
19
- }
20
- else if (modeValue < optionsValue) {
21
- const value = particleValue - (optionsValue - modeValue) * ratio;
22
- return (0, engine_1.clamp)(value, modeValue, particleValue);
23
- }
24
- }
6
+ const Utils_1 = require("./Utils");
25
7
  class Bubbler extends engine_1.ExternalInteractorBase {
26
8
  constructor(container) {
27
9
  super(container);
10
+ this._clickBubble = () => {
11
+ const container = this.container, options = container.actualOptions, mouseClickPos = container.interactivity.mouse.clickPosition, bubbleOptions = options.interactivity.modes.bubble;
12
+ if (!bubbleOptions || !mouseClickPos) {
13
+ return;
14
+ }
15
+ if (!container.bubble) {
16
+ container.bubble = {};
17
+ }
18
+ const distance = container.retina.bubbleModeDistance;
19
+ if (!distance || distance < 0) {
20
+ return;
21
+ }
22
+ const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, (p) => this.isEnabled(p)), { bubble } = container;
23
+ for (const particle of query) {
24
+ if (!bubble.clicking) {
25
+ continue;
26
+ }
27
+ particle.bubble.inRange = !bubble.durationEnd;
28
+ const pos = particle.getPosition(), distMouse = (0, engine_1.getDistance)(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
29
+ if (timeSpent > bubbleOptions.duration) {
30
+ bubble.durationEnd = true;
31
+ }
32
+ if (timeSpent > bubbleOptions.duration * 2) {
33
+ bubble.clicking = false;
34
+ bubble.durationEnd = false;
35
+ }
36
+ const sizeData = {
37
+ bubbleObj: {
38
+ optValue: container.retina.bubbleModeSize,
39
+ value: particle.bubble.radius,
40
+ },
41
+ particlesObj: {
42
+ optValue: (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio,
43
+ value: particle.size.value,
44
+ },
45
+ type: "size",
46
+ };
47
+ this._process(particle, distMouse, timeSpent, sizeData);
48
+ const opacityData = {
49
+ bubbleObj: {
50
+ optValue: bubbleOptions.opacity,
51
+ value: particle.bubble.opacity,
52
+ },
53
+ particlesObj: {
54
+ optValue: (0, engine_1.getRangeMax)(particle.options.opacity.value),
55
+ value: particle.opacity?.value ?? 1,
56
+ },
57
+ type: "opacity",
58
+ };
59
+ this._process(particle, distMouse, timeSpent, opacityData);
60
+ if (!bubble.durationEnd && distMouse <= distance) {
61
+ this._hoverBubbleColor(particle, distMouse);
62
+ }
63
+ else {
64
+ delete particle.bubble.color;
65
+ }
66
+ }
67
+ };
68
+ this._hoverBubble = () => {
69
+ const container = this.container, mousePos = container.interactivity.mouse.position, distance = container.retina.bubbleModeDistance;
70
+ if (!distance || distance < 0 || mousePos === undefined) {
71
+ return;
72
+ }
73
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
74
+ for (const particle of query) {
75
+ particle.bubble.inRange = true;
76
+ const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos), ratio = 1 - pointDistance / distance;
77
+ if (pointDistance <= distance) {
78
+ if (ratio >= 0 && container.interactivity.status === engine_1.mouseMoveEvent) {
79
+ this._hoverBubbleSize(particle, ratio);
80
+ this._hoverBubbleOpacity(particle, ratio);
81
+ this._hoverBubbleColor(particle, ratio);
82
+ }
83
+ }
84
+ else {
85
+ this.reset(particle);
86
+ }
87
+ if (container.interactivity.status === engine_1.mouseLeaveEvent) {
88
+ this.reset(particle);
89
+ }
90
+ }
91
+ };
92
+ this._hoverBubbleColor = (particle, ratio, divBubble) => {
93
+ const options = this.container.actualOptions, bubbleOptions = divBubble ?? options.interactivity.modes.bubble;
94
+ if (!bubbleOptions) {
95
+ return;
96
+ }
97
+ if (!particle.bubble.finalColor) {
98
+ const modeColor = bubbleOptions.color;
99
+ if (!modeColor) {
100
+ return;
101
+ }
102
+ const bubbleColor = (0, engine_1.itemFromSingleOrMultiple)(modeColor);
103
+ particle.bubble.finalColor = (0, engine_1.rangeColorToHsl)(bubbleColor);
104
+ }
105
+ if (!particle.bubble.finalColor) {
106
+ return;
107
+ }
108
+ if (bubbleOptions.mix) {
109
+ particle.bubble.color = undefined;
110
+ const pColor = particle.getFillColor();
111
+ particle.bubble.color = pColor
112
+ ? (0, engine_1.rgbToHsl)((0, engine_1.colorMix)(pColor, particle.bubble.finalColor, 1 - ratio, ratio))
113
+ : particle.bubble.finalColor;
114
+ }
115
+ else {
116
+ particle.bubble.color = particle.bubble.finalColor;
117
+ }
118
+ };
119
+ this._hoverBubbleOpacity = (particle, ratio, divBubble) => {
120
+ const container = this.container, options = container.actualOptions, modeOpacity = divBubble?.opacity ?? options.interactivity.modes.bubble?.opacity;
121
+ if (!modeOpacity) {
122
+ return;
123
+ }
124
+ const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? 1, opacity = (0, Utils_1.calculateBubbleValue)(pOpacity, modeOpacity, (0, engine_1.getRangeMax)(optOpacity), ratio);
125
+ if (opacity !== undefined) {
126
+ particle.bubble.opacity = opacity;
127
+ }
128
+ };
129
+ this._hoverBubbleSize = (particle, ratio, divBubble) => {
130
+ const container = this.container, modeSize = divBubble?.size ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;
131
+ if (modeSize === undefined) {
132
+ return;
133
+ }
134
+ const optSize = (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio, pSize = particle.size.value, size = (0, Utils_1.calculateBubbleValue)(pSize, modeSize, optSize, ratio);
135
+ if (size !== undefined) {
136
+ particle.bubble.radius = size;
137
+ }
138
+ };
139
+ this._process = (particle, distMouse, timeSpent, data) => {
140
+ const container = this.container, bubbleParam = data.bubbleObj.optValue, options = container.actualOptions, bubbleOptions = options.interactivity.modes.bubble;
141
+ if (!bubbleOptions || bubbleParam === undefined) {
142
+ return;
143
+ }
144
+ const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value || 0, type = data.type;
145
+ if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
146
+ return;
147
+ }
148
+ if (!container.bubble) {
149
+ container.bubble = {};
150
+ }
151
+ if (container.bubble.durationEnd) {
152
+ if (pObjBubble) {
153
+ if (type === "size") {
154
+ delete particle.bubble.radius;
155
+ }
156
+ if (type === "opacity") {
157
+ delete particle.bubble.opacity;
158
+ }
159
+ }
160
+ }
161
+ else {
162
+ if (distMouse <= bubbleDistance) {
163
+ const obj = pObjBubble ?? pObj;
164
+ if (obj !== bubbleParam) {
165
+ const value = pObj - (timeSpent * (pObj - bubbleParam)) / bubbleDuration;
166
+ if (type === "size") {
167
+ particle.bubble.radius = value;
168
+ }
169
+ if (type === "opacity") {
170
+ particle.bubble.opacity = value;
171
+ }
172
+ }
173
+ }
174
+ else {
175
+ if (type === "size") {
176
+ delete particle.bubble.radius;
177
+ }
178
+ if (type === "opacity") {
179
+ delete particle.bubble.opacity;
180
+ }
181
+ }
182
+ }
183
+ };
184
+ this._singleSelectorHover = (delta, selector, div) => {
185
+ const container = this.container, selectors = document.querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
186
+ if (!bubble || !selectors.length) {
187
+ return;
188
+ }
189
+ selectors.forEach((item) => {
190
+ const elem = item, pxRatio = container.retina.pixelRatio, pos = {
191
+ x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
192
+ y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
193
+ }, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
194
+ ? new engine_1.Circle(pos.x, pos.y, repulseRadius)
195
+ : new engine_1.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
196
+ for (const particle of query) {
197
+ if (!area.contains(particle.getPosition())) {
198
+ continue;
199
+ }
200
+ particle.bubble.inRange = true;
201
+ const divs = bubble.divs, divBubble = (0, engine_1.divMode)(divs, elem);
202
+ if (!particle.bubble.div || particle.bubble.div !== elem) {
203
+ this.clear(particle, delta, true);
204
+ particle.bubble.div = elem;
205
+ }
206
+ this._hoverBubbleSize(particle, 1, divBubble);
207
+ this._hoverBubbleOpacity(particle, 1, divBubble);
208
+ this._hoverBubbleColor(particle, 1, divBubble);
209
+ }
210
+ });
211
+ };
28
212
  if (!container.bubble) {
29
213
  container.bubble = {};
30
214
  }
@@ -57,253 +241,35 @@ class Bubbler extends engine_1.ExternalInteractorBase {
57
241
  container.retina.bubbleModeSize = bubble.size * container.retina.pixelRatio;
58
242
  }
59
243
  }
60
- interact(delta) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const options = this.container.actualOptions, events = options.interactivity.events, onHover = events.onHover, onClick = events.onClick, hoverEnabled = onHover.enable, hoverMode = onHover.mode, clickEnabled = onClick.enable, clickMode = onClick.mode, divs = events.onDiv;
63
- if (hoverEnabled && (0, engine_1.isInArray)("bubble", hoverMode)) {
64
- this.hoverBubble(delta);
65
- }
66
- else if (clickEnabled && (0, engine_1.isInArray)("bubble", clickMode)) {
67
- this.clickBubble(delta);
68
- }
69
- else {
70
- (0, engine_1.divModeExecute)("bubble", divs, (selector, div) => this.singleSelectorHover(delta, selector, div));
71
- }
72
- });
244
+ async interact(delta) {
245
+ const options = this.container.actualOptions, events = options.interactivity.events, onHover = events.onHover, onClick = events.onClick, hoverEnabled = onHover.enable, hoverMode = onHover.mode, clickEnabled = onClick.enable, clickMode = onClick.mode, divs = events.onDiv;
246
+ if (hoverEnabled && (0, engine_1.isInArray)("bubble", hoverMode)) {
247
+ this._hoverBubble();
248
+ }
249
+ else if (clickEnabled && (0, engine_1.isInArray)("bubble", clickMode)) {
250
+ this._clickBubble();
251
+ }
252
+ else {
253
+ (0, engine_1.divModeExecute)("bubble", divs, (selector, div) => this._singleSelectorHover(delta, selector, div));
254
+ }
73
255
  }
74
256
  isEnabled(particle) {
75
- var _a;
76
- const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events, divs = events.onDiv, divBubble = (0, engine_1.isDivModeEnabled)("bubble", divs);
77
- if (!(divBubble || (events.onHover.enable && mouse.position) || (events.onClick.enable && mouse.clickPosition))) {
257
+ const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, { onClick, onDiv, onHover } = events, divBubble = (0, engine_1.isDivModeEnabled)("bubble", onDiv);
258
+ if (!(divBubble || (onHover.enable && mouse.position) || (onClick.enable && mouse.clickPosition))) {
78
259
  return false;
79
260
  }
80
- const hoverMode = events.onHover.mode;
81
- const clickMode = events.onClick.mode;
82
- return (0, engine_1.isInArray)("bubble", hoverMode) || (0, engine_1.isInArray)("bubble", clickMode) || divBubble;
261
+ return (0, engine_1.isInArray)("bubble", onHover.mode) || (0, engine_1.isInArray)("bubble", onClick.mode) || divBubble;
83
262
  }
84
263
  loadModeOptions(options, ...sources) {
85
264
  if (!options.bubble) {
86
265
  options.bubble = new Bubble_1.Bubble();
87
266
  }
88
267
  for (const source of sources) {
89
- options.bubble.load(source === null || source === void 0 ? void 0 : source.bubble);
268
+ options.bubble.load(source?.bubble);
90
269
  }
91
270
  }
92
271
  reset(particle) {
93
272
  particle.bubble.inRange = false;
94
273
  }
95
- clickBubble(delta) {
96
- var _a, _b;
97
- const container = this.container, options = container.actualOptions, mouseClickPos = container.interactivity.mouse.clickPosition, bubble = options.interactivity.modes.bubble;
98
- if (!bubble || !mouseClickPos) {
99
- return;
100
- }
101
- if (!container.bubble) {
102
- container.bubble = {};
103
- }
104
- const distance = container.retina.bubbleModeDistance;
105
- if (!distance || distance < 0) {
106
- return;
107
- }
108
- const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, (p) => this.isEnabled(p));
109
- for (const particle of query) {
110
- if (!container.bubble.clicking) {
111
- continue;
112
- }
113
- particle.bubble.inRange = !container.bubble.durationEnd;
114
- const pos = particle.getPosition(), distMouse = (0, engine_1.getDistance)(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
115
- if (timeSpent > bubble.duration) {
116
- container.bubble.durationEnd = true;
117
- }
118
- if (timeSpent > bubble.duration * 2) {
119
- container.bubble.clicking = false;
120
- container.bubble.durationEnd = false;
121
- }
122
- const sizeData = {
123
- bubbleObj: {
124
- optValue: container.retina.bubbleModeSize,
125
- value: particle.bubble.radius,
126
- },
127
- particlesObj: {
128
- optValue: (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio,
129
- value: particle.size.value,
130
- },
131
- type: "size",
132
- };
133
- this.process(particle, distMouse, timeSpent, sizeData);
134
- const opacityData = {
135
- bubbleObj: {
136
- optValue: bubble.opacity,
137
- value: particle.bubble.opacity,
138
- },
139
- particlesObj: {
140
- optValue: (0, engine_1.getRangeMax)(particle.options.opacity.value),
141
- value: (_b = (_a = particle.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1,
142
- },
143
- type: "opacity",
144
- };
145
- this.process(particle, distMouse, timeSpent, opacityData);
146
- if (!container.bubble.durationEnd) {
147
- if (distMouse <= distance) {
148
- this.hoverBubbleColor(particle, distMouse);
149
- }
150
- else {
151
- delete particle.bubble.color;
152
- }
153
- }
154
- else {
155
- delete particle.bubble.color;
156
- }
157
- }
158
- }
159
- hoverBubble(delta) {
160
- const container = this.container, mousePos = container.interactivity.mouse.position, distance = container.retina.bubbleModeDistance;
161
- if (!distance || distance < 0 || mousePos === undefined) {
162
- return;
163
- }
164
- const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
165
- for (const particle of query) {
166
- particle.bubble.inRange = true;
167
- const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos), ratio = 1 - pointDistance / distance;
168
- if (pointDistance <= distance) {
169
- if (ratio >= 0 && container.interactivity.status === engine_1.mouseMoveEvent) {
170
- this.hoverBubbleSize(particle, ratio);
171
- this.hoverBubbleOpacity(particle, ratio);
172
- this.hoverBubbleColor(particle, ratio);
173
- }
174
- }
175
- else {
176
- this.reset(particle);
177
- }
178
- if (container.interactivity.status === engine_1.mouseLeaveEvent) {
179
- this.reset(particle);
180
- }
181
- }
182
- }
183
- hoverBubbleColor(particle, ratio, divBubble) {
184
- const options = this.container.actualOptions;
185
- const bubbleOptions = divBubble !== null && divBubble !== void 0 ? divBubble : options.interactivity.modes.bubble;
186
- if (!bubbleOptions) {
187
- return;
188
- }
189
- if (!particle.bubble.finalColor) {
190
- const modeColor = bubbleOptions.color;
191
- if (!modeColor) {
192
- return;
193
- }
194
- const bubbleColor = (0, engine_1.itemFromSingleOrMultiple)(modeColor);
195
- particle.bubble.finalColor = (0, engine_1.rangeColorToHsl)(bubbleColor);
196
- }
197
- if (!particle.bubble.finalColor) {
198
- return;
199
- }
200
- if (bubbleOptions.mix) {
201
- particle.bubble.color = undefined;
202
- const pColor = particle.getFillColor();
203
- particle.bubble.color = pColor
204
- ? (0, engine_1.rgbToHsl)((0, engine_1.colorMix)(pColor, particle.bubble.finalColor, 1 - ratio, ratio))
205
- : particle.bubble.finalColor;
206
- }
207
- else {
208
- particle.bubble.color = particle.bubble.finalColor;
209
- }
210
- }
211
- hoverBubbleOpacity(particle, ratio, divBubble) {
212
- var _a, _b, _c, _d;
213
- const container = this.container, options = container.actualOptions, 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;
214
- if (!modeOpacity) {
215
- return;
216
- }
217
- const optOpacity = particle.options.opacity.value;
218
- const pOpacity = (_d = (_c = particle.opacity) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 1;
219
- const opacity = calculateBubbleValue(pOpacity, modeOpacity, (0, engine_1.getRangeMax)(optOpacity), ratio);
220
- if (opacity !== undefined) {
221
- particle.bubble.opacity = opacity;
222
- }
223
- }
224
- hoverBubbleSize(particle, ratio, divBubble) {
225
- const container = this.container, modeSize = (divBubble === null || divBubble === void 0 ? void 0 : divBubble.size) ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;
226
- if (modeSize === undefined) {
227
- return;
228
- }
229
- const optSize = (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio;
230
- const pSize = particle.size.value;
231
- const size = calculateBubbleValue(pSize, modeSize, optSize, ratio);
232
- if (size !== undefined) {
233
- particle.bubble.radius = size;
234
- }
235
- }
236
- process(particle, distMouse, timeSpent, data) {
237
- const container = this.container, bubbleParam = data.bubbleObj.optValue, options = container.actualOptions, bubble = options.interactivity.modes.bubble;
238
- if (!bubble || bubbleParam === undefined) {
239
- return;
240
- }
241
- const bubbleDuration = bubble.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value || 0, type = data.type;
242
- if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
243
- return;
244
- }
245
- if (!container.bubble) {
246
- container.bubble = {};
247
- }
248
- if (!container.bubble.durationEnd) {
249
- if (distMouse <= bubbleDistance) {
250
- const obj = pObjBubble !== null && pObjBubble !== void 0 ? pObjBubble : pObj;
251
- if (obj !== bubbleParam) {
252
- const value = pObj - (timeSpent * (pObj - bubbleParam)) / bubbleDuration;
253
- if (type === "size") {
254
- particle.bubble.radius = value;
255
- }
256
- if (type === "opacity") {
257
- particle.bubble.opacity = value;
258
- }
259
- }
260
- }
261
- else {
262
- if (type === "size") {
263
- delete particle.bubble.radius;
264
- }
265
- if (type === "opacity") {
266
- delete particle.bubble.opacity;
267
- }
268
- }
269
- }
270
- else if (pObjBubble) {
271
- if (type === "size") {
272
- delete particle.bubble.radius;
273
- }
274
- if (type === "opacity") {
275
- delete particle.bubble.opacity;
276
- }
277
- }
278
- }
279
- singleSelectorHover(delta, selector, div) {
280
- const container = this.container, selectors = document.querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
281
- if (!bubble || !selectors.length) {
282
- return;
283
- }
284
- selectors.forEach((item) => {
285
- const elem = item, pxRatio = container.retina.pixelRatio, pos = {
286
- x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
287
- y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
288
- }, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
289
- ? new engine_1.Circle(pos.x, pos.y, repulseRadius)
290
- : new engine_1.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
291
- for (const particle of query) {
292
- if (!area.contains(particle.getPosition())) {
293
- continue;
294
- }
295
- particle.bubble.inRange = true;
296
- const divs = bubble.divs;
297
- const divBubble = (0, engine_1.divMode)(divs, elem);
298
- if (!particle.bubble.div || particle.bubble.div !== elem) {
299
- this.clear(particle, delta, true);
300
- particle.bubble.div = elem;
301
- }
302
- this.hoverBubbleSize(particle, 1, divBubble);
303
- this.hoverBubbleOpacity(particle, 1, divBubble);
304
- this.hoverBubbleColor(particle, 1, divBubble);
305
- }
306
- });
307
- }
308
274
  }
309
275
  exports.Bubbler = Bubbler;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Bubble = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
4
5
  const BubbleBase_1 = require("./BubbleBase");
5
6
  const BubbleDiv_1 = require("./BubbleDiv");
6
- const engine_1 = require("@tsparticles/engine");
7
7
  class Bubble extends BubbleBase_1.BubbleBase {
8
8
  load(data) {
9
9
  super.load(data);
@@ -25,7 +25,7 @@ class BubbleBase {
25
25
  this.opacity = data.opacity;
26
26
  }
27
27
  if (data.color !== undefined) {
28
- const sourceColor = this.color instanceof Array ? undefined : this.color;
28
+ const sourceColor = (0, engine_1.isArray)(this.color) ? undefined : this.color;
29
29
  this.color = (0, engine_1.executeOnSingleOrMultiple)(data.color, (color) => {
30
30
  return engine_1.OptionsColor.create(sourceColor, color);
31
31
  });
@@ -2,26 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BubbleDiv = void 0;
4
4
  const BubbleBase_1 = require("./BubbleBase");
5
- const engine_1 = require("@tsparticles/engine");
6
5
  class BubbleDiv extends BubbleBase_1.BubbleBase {
7
6
  constructor() {
8
7
  super();
9
8
  this.selectors = [];
10
9
  }
11
- get ids() {
12
- return (0, engine_1.executeOnSingleOrMultiple)(this.selectors, (t) => t.replace("#", ""));
13
- }
14
- set ids(value) {
15
- this.selectors = (0, engine_1.executeOnSingleOrMultiple)(value, (t) => `#${t}`);
16
- }
17
10
  load(data) {
18
11
  super.load(data);
19
12
  if (!data) {
20
13
  return;
21
14
  }
22
- if (data.ids !== undefined) {
23
- this.ids = data.ids;
24
- }
25
15
  if (data.selectors !== undefined) {
26
16
  this.selectors = data.selectors;
27
17
  }
package/cjs/Utils.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateBubbleValue = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
6
+ if (modeValue >= optionsValue) {
7
+ const value = particleValue + (modeValue - optionsValue) * ratio;
8
+ return (0, engine_1.clamp)(value, particleValue, modeValue);
9
+ }
10
+ else if (modeValue < optionsValue) {
11
+ const value = particleValue - (optionsValue - modeValue) * ratio;
12
+ return (0, engine_1.clamp)(value, modeValue, particleValue);
13
+ }
14
+ }
15
+ exports.calculateBubbleValue = calculateBubbleValue;
package/cjs/index.js CHANGED
@@ -13,22 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
16
  Object.defineProperty(exports, "__esModule", { value: true });
26
17
  exports.loadExternalBubbleInteraction = void 0;
27
18
  const Bubbler_1 = require("./Bubbler");
28
- function loadExternalBubbleInteraction(engine) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- yield engine.addInteractor("externalBubble", (container) => new Bubbler_1.Bubbler(container));
31
- });
19
+ async function loadExternalBubbleInteraction(engine, refresh = true) {
20
+ await engine.addInteractor("externalBubble", (container) => new Bubbler_1.Bubbler(container), refresh);
32
21
  }
33
22
  exports.loadExternalBubbleInteraction = loadExternalBubbleInteraction;
34
23
  __exportStar(require("./Options/Classes/BubbleBase"), exports);