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