@tsparticles/interaction-external-bubble 3.0.3 → 3.2.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.
package/582.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 582.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_interaction_external_bubble=this.webpackChunk_tsparticles_interaction_external_bubble||[]).push([[582],{582:(e,i,t)=>{t.d(i,{Bubbler:()=>a});var o=t(533),b=t(585);function l(e,i,t,b){if(i>=t){const l=e+(i-t)*b;return(0,o.clamp)(l,e,i)}if(i<t){const l=e-(t-i)*b;return(0,o.clamp)(l,i,e)}}const n="bubble";class a extends o.ExternalInteractorBase{constructor(e){super(e),this._clickBubble=()=>{const e=this.container,i=e.actualOptions,t=e.interactivity.mouse.clickPosition,b=i.interactivity.modes.bubble;if(!b||!t)return;e.bubble||(e.bubble={});const l=e.retina.bubbleModeDistance;if(!l||l<0)return;const n=e.particles.quadTree.queryCircle(t,l,(e=>this.isEnabled(e))),{bubble:a}=e;for(const i of n){if(!a.clicking)continue;i.bubble.inRange=!a.durationEnd;const n=i.getPosition(),s=(0,o.getDistance)(n,t),r=((new Date).getTime()-(e.interactivity.mouse.clickTime??0))/o.millisecondsToSeconds;r>b.duration&&(a.durationEnd=!0),r>2*b.duration&&(a.clicking=!1,a.durationEnd=!1);const c={bubbleObj:{optValue:e.retina.bubbleModeSize,value:i.bubble.radius},particlesObj:{optValue:(0,o.getRangeMax)(i.options.size.value)*e.retina.pixelRatio,value:i.size.value},type:"size"};this._process(i,s,r,c);const u={bubbleObj:{optValue:b.opacity,value:i.bubble.opacity},particlesObj:{optValue:(0,o.getRangeMax)(i.options.opacity.value),value:i.opacity?.value??1},type:"opacity"};this._process(i,s,r,u),!a.durationEnd&&s<=l?this._hoverBubbleColor(i,s):delete i.bubble.color}},this._hoverBubble=()=>{const e=this.container,i=e.interactivity.mouse.position,t=e.retina.bubbleModeDistance;if(!t||t<0||!i)return;const b=e.particles.quadTree.queryCircle(i,t,(e=>this.isEnabled(e)));for(const l of b){l.bubble.inRange=!0;const b=l.getPosition(),n=(0,o.getDistance)(b,i),a=1-n/t;n<=t?a>=0&&e.interactivity.status===o.mouseMoveEvent&&(this._hoverBubbleSize(l,a),this._hoverBubbleOpacity(l,a),this._hoverBubbleColor(l,a)):this.reset(l),e.interactivity.status===o.mouseLeaveEvent&&this.reset(l)}},this._hoverBubbleColor=(e,i,t)=>{const b=this.container.actualOptions,l=t??b.interactivity.modes.bubble;if(l){if(!e.bubble.finalColor){const i=l.color;if(!i)return;const t=(0,o.itemFromSingleOrMultiple)(i);e.bubble.finalColor=(0,o.rangeColorToHsl)(t)}if(e.bubble.finalColor)if(l.mix){e.bubble.color=void 0;const t=e.getFillColor();e.bubble.color=t?(0,o.rgbToHsl)((0,o.colorMix)(t,e.bubble.finalColor,1-i,i)):e.bubble.finalColor}else e.bubble.color=e.bubble.finalColor}},this._hoverBubbleOpacity=(e,i,t)=>{const b=this.container.actualOptions,n=t?.opacity??b.interactivity.modes.bubble?.opacity;if(!n)return;const a=e.options.opacity.value,s=l(e.opacity?.value??1,n,(0,o.getRangeMax)(a),i);void 0!==s&&(e.bubble.opacity=s)},this._hoverBubbleSize=(e,i,t)=>{const b=this.container,n=t?.size?t.size*b.retina.pixelRatio:b.retina.bubbleModeSize;if(void 0===n)return;const a=(0,o.getRangeMax)(e.options.size.value)*b.retina.pixelRatio,s=l(e.size.value,n,a,i);void 0!==s&&(e.bubble.radius=s)},this._process=(e,i,t,o)=>{const b=this.container,l=o.bubbleObj.optValue,n=b.actualOptions.interactivity.modes.bubble;if(!n||void 0===l)return;const a=n.duration,s=b.retina.bubbleModeDistance,r=o.particlesObj.optValue,c=o.bubbleObj.value,u=o.particlesObj.value??0,d=o.type;if(s&&!(s<0)&&l!==r)if(b.bubble||(b.bubble={}),b.bubble.durationEnd)c&&("size"===d&&delete e.bubble.radius,"opacity"===d&&delete e.bubble.opacity);else if(i<=s){if((c??u)!==l){const i=u-t*(u-l)/a;"size"===d&&(e.bubble.radius=i),"opacity"===d&&(e.bubble.opacity=i)}}else"size"===d&&delete e.bubble.radius,"opacity"===d&&delete e.bubble.opacity},this._singleSelectorHover=(e,i,t)=>{const b=this.container,l=document.querySelectorAll(i),n=b.actualOptions.interactivity.modes.bubble;n&&l.length&&l.forEach((i=>{const l=i,a=b.retina.pixelRatio,s={x:(l.offsetLeft+.5*l.offsetWidth)*a,y:(l.offsetTop+.5*l.offsetHeight)*a},r=.5*l.offsetWidth*a,c="circle"===t.type?new o.Circle(s.x,s.y,r):new o.Rectangle(l.offsetLeft*a,l.offsetTop*a,l.offsetWidth*a,l.offsetHeight*a),u=b.particles.quadTree.query(c,(e=>this.isEnabled(e)));for(const i of u){if(!c.contains(i.getPosition()))continue;i.bubble.inRange=!0;const t=n.divs,b=(0,o.divMode)(t,l);i.bubble.div&&i.bubble.div===l||(this.clear(i,e,!0),i.bubble.div=l),this._hoverBubbleSize(i,1,b),this._hoverBubbleOpacity(i,1,b),this._hoverBubbleColor(i,1,b)}}))},e.bubble||(e.bubble={}),this.handleClickMode=i=>{i===n&&(e.bubble||(e.bubble={}),e.bubble.clicking=!0)}}clear(e,i,t){e.bubble.inRange&&!t||(delete e.bubble.div,delete e.bubble.opacity,delete e.bubble.radius,delete e.bubble.color)}init(){const e=this.container,i=e.actualOptions.interactivity.modes.bubble;i&&(e.retina.bubbleModeDistance=i.distance*e.retina.pixelRatio,void 0!==i.size&&(e.retina.bubbleModeSize=i.size*e.retina.pixelRatio))}async interact(e){const i=this.container.actualOptions.interactivity.events,t=i.onHover,b=i.onClick,l=t.enable,a=t.mode,s=b.enable,r=b.mode,c=i.onDiv;l&&(0,o.isInArray)(n,a)?this._hoverBubble():s&&(0,o.isInArray)(n,r)?this._clickBubble():(0,o.divModeExecute)(n,c,((i,t)=>this._singleSelectorHover(e,i,t))),await Promise.resolve()}isEnabled(e){const i=this.container,t=i.actualOptions,b=i.interactivity.mouse,l=(e?.interactivity??t.interactivity).events,{onClick:a,onDiv:s,onHover:r}=l,c=(0,o.isDivModeEnabled)(n,s);return!!(c||r.enable&&b.position||a.enable&&b.clickPosition)&&((0,o.isInArray)(n,r.mode)||(0,o.isInArray)(n,a.mode)||c)}loadModeOptions(e,...i){e.bubble||(e.bubble=new b.x);for(const t of i)e.bubble.load(t?.bubble)}reset(e){e.bubble.inRange=!1}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Bubble External Interaction v3.2.0 by Matteo Bruni */
@@ -1,7 +1,7 @@
1
- import { Circle, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, } from "@tsparticles/engine";
1
+ import { Circle, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, millisecondsToSeconds, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, } from "@tsparticles/engine";
2
2
  import { Bubble } from "./Options/Classes/Bubble.js";
3
3
  import { calculateBubbleValue } from "./Utils.js";
4
- const bubbleMode = "bubble";
4
+ const bubbleMode = "bubble", minDistance = 0, defaultClickTime = 0, double = 2, defaultOpacity = 1, ratioOffset = 1, defaultBubbleValue = 0, minRatio = 0, half = 0.5, defaultRatio = 1;
5
5
  export class Bubbler extends ExternalInteractorBase {
6
6
  constructor(container) {
7
7
  super(container);
@@ -14,7 +14,7 @@ export class Bubbler extends ExternalInteractorBase {
14
14
  container.bubble = {};
15
15
  }
16
16
  const distance = container.retina.bubbleModeDistance;
17
- if (!distance || distance < 0) {
17
+ if (!distance || distance < minDistance) {
18
18
  return;
19
19
  }
20
20
  const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, (p) => this.isEnabled(p)), { bubble } = container;
@@ -23,11 +23,12 @@ export class Bubbler extends ExternalInteractorBase {
23
23
  continue;
24
24
  }
25
25
  particle.bubble.inRange = !bubble.durationEnd;
26
- const pos = particle.getPosition(), distMouse = getDistance(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
26
+ const pos = particle.getPosition(), distMouse = getDistance(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime ?? defaultClickTime)) /
27
+ millisecondsToSeconds;
27
28
  if (timeSpent > bubbleOptions.duration) {
28
29
  bubble.durationEnd = true;
29
30
  }
30
- if (timeSpent > bubbleOptions.duration * 2) {
31
+ if (timeSpent > bubbleOptions.duration * double) {
31
32
  bubble.clicking = false;
32
33
  bubble.durationEnd = false;
33
34
  }
@@ -50,7 +51,7 @@ export class Bubbler extends ExternalInteractorBase {
50
51
  },
51
52
  particlesObj: {
52
53
  optValue: getRangeMax(particle.options.opacity.value),
53
- value: particle.opacity?.value ?? 1,
54
+ value: particle.opacity?.value ?? defaultOpacity,
54
55
  },
55
56
  type: "opacity",
56
57
  };
@@ -65,15 +66,15 @@ export class Bubbler extends ExternalInteractorBase {
65
66
  };
66
67
  this._hoverBubble = () => {
67
68
  const container = this.container, mousePos = container.interactivity.mouse.position, distance = container.retina.bubbleModeDistance;
68
- if (!distance || distance < 0 || mousePos === undefined) {
69
+ if (!distance || distance < minDistance || !mousePos) {
69
70
  return;
70
71
  }
71
72
  const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
72
73
  for (const particle of query) {
73
74
  particle.bubble.inRange = true;
74
- const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos), ratio = 1 - pointDistance / distance;
75
+ const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos), ratio = ratioOffset - pointDistance / distance;
75
76
  if (pointDistance <= distance) {
76
- if (ratio >= 0 && container.interactivity.status === mouseMoveEvent) {
77
+ if (ratio >= minRatio && container.interactivity.status === mouseMoveEvent) {
77
78
  this._hoverBubbleSize(particle, ratio);
78
79
  this._hoverBubbleOpacity(particle, ratio);
79
80
  this._hoverBubbleColor(particle, ratio);
@@ -107,7 +108,7 @@ export class Bubbler extends ExternalInteractorBase {
107
108
  particle.bubble.color = undefined;
108
109
  const pColor = particle.getFillColor();
109
110
  particle.bubble.color = pColor
110
- ? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, 1 - ratio, ratio))
111
+ ? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, ratioOffset - ratio, ratio))
111
112
  : particle.bubble.finalColor;
112
113
  }
113
114
  else {
@@ -119,7 +120,7 @@ export class Bubbler extends ExternalInteractorBase {
119
120
  if (!modeOpacity) {
120
121
  return;
121
122
  }
122
- const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? 1, opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
123
+ const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? defaultOpacity, opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
123
124
  if (opacity !== undefined) {
124
125
  particle.bubble.opacity = opacity;
125
126
  }
@@ -139,8 +140,8 @@ export class Bubbler extends ExternalInteractorBase {
139
140
  if (!bubbleOptions || bubbleParam === undefined) {
140
141
  return;
141
142
  }
142
- const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value || 0, type = data.type;
143
- if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
143
+ const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value ?? defaultBubbleValue, type = data.type;
144
+ if (!bubbleDistance || bubbleDistance < minDistance || bubbleParam === particlesParam) {
144
145
  return;
145
146
  }
146
147
  if (!container.bubble) {
@@ -186,9 +187,9 @@ export class Bubbler extends ExternalInteractorBase {
186
187
  }
187
188
  selectors.forEach((item) => {
188
189
  const elem = item, pxRatio = container.retina.pixelRatio, pos = {
189
- x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
190
- y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
191
- }, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
190
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
191
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
192
+ }, repulseRadius = elem.offsetWidth * half * pxRatio, area = div.type === "circle"
192
193
  ? new Circle(pos.x, pos.y, repulseRadius)
193
194
  : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
194
195
  for (const particle of query) {
@@ -201,9 +202,9 @@ export class Bubbler extends ExternalInteractorBase {
201
202
  this.clear(particle, delta, true);
202
203
  particle.bubble.div = elem;
203
204
  }
204
- this._hoverBubbleSize(particle, 1, divBubble);
205
- this._hoverBubbleOpacity(particle, 1, divBubble);
206
- this._hoverBubbleColor(particle, 1, divBubble);
205
+ this._hoverBubbleSize(particle, defaultRatio, divBubble);
206
+ this._hoverBubbleOpacity(particle, defaultRatio, divBubble);
207
+ this._hoverBubbleColor(particle, defaultRatio, divBubble);
207
208
  }
208
209
  });
209
210
  };
@@ -250,10 +251,11 @@ export class Bubbler extends ExternalInteractorBase {
250
251
  else {
251
252
  divModeExecute(bubbleMode, divs, (selector, div) => this._singleSelectorHover(delta, selector, div));
252
253
  }
254
+ await Promise.resolve();
253
255
  }
254
256
  isEnabled(particle) {
255
257
  const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, { onClick, onDiv, onHover } = events, divBubble = isDivModeEnabled(bubbleMode, onDiv);
256
- if (!(divBubble || (onHover.enable && mouse.position) || (onClick.enable && mouse.clickPosition))) {
258
+ if (!(divBubble || (onHover.enable && !!mouse.position) || (onClick.enable && mouse.clickPosition))) {
257
259
  return false;
258
260
  }
259
261
  return isInArray(bubbleMode, onHover.mode) || isInArray(bubbleMode, onClick.mode) || divBubble;
package/browser/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import { Bubbler } from "./Bubbler.js";
2
1
  export async function loadExternalBubbleInteraction(engine, refresh = true) {
3
- await engine.addInteractor("externalBubble", (container) => new Bubbler(container), refresh);
2
+ await engine.addInteractor("externalBubble", async (container) => {
3
+ const { Bubbler } = await import("./Bubbler.js");
4
+ return new Bubbler(container);
5
+ }, refresh);
4
6
  }
5
7
  export * from "./Options/Classes/BubbleBase.js";
6
8
  export * from "./Options/Classes/BubbleDiv.js";
package/cjs/Bubbler.js CHANGED
@@ -4,7 +4,7 @@ exports.Bubbler = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const Bubble_js_1 = require("./Options/Classes/Bubble.js");
6
6
  const Utils_js_1 = require("./Utils.js");
7
- const bubbleMode = "bubble";
7
+ const bubbleMode = "bubble", minDistance = 0, defaultClickTime = 0, double = 2, defaultOpacity = 1, ratioOffset = 1, defaultBubbleValue = 0, minRatio = 0, half = 0.5, defaultRatio = 1;
8
8
  class Bubbler extends engine_1.ExternalInteractorBase {
9
9
  constructor(container) {
10
10
  super(container);
@@ -17,7 +17,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
17
17
  container.bubble = {};
18
18
  }
19
19
  const distance = container.retina.bubbleModeDistance;
20
- if (!distance || distance < 0) {
20
+ if (!distance || distance < minDistance) {
21
21
  return;
22
22
  }
23
23
  const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, (p) => this.isEnabled(p)), { bubble } = container;
@@ -26,11 +26,12 @@ class Bubbler extends engine_1.ExternalInteractorBase {
26
26
  continue;
27
27
  }
28
28
  particle.bubble.inRange = !bubble.durationEnd;
29
- const pos = particle.getPosition(), distMouse = (0, engine_1.getDistance)(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
29
+ const pos = particle.getPosition(), distMouse = (0, engine_1.getDistance)(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime ?? defaultClickTime)) /
30
+ engine_1.millisecondsToSeconds;
30
31
  if (timeSpent > bubbleOptions.duration) {
31
32
  bubble.durationEnd = true;
32
33
  }
33
- if (timeSpent > bubbleOptions.duration * 2) {
34
+ if (timeSpent > bubbleOptions.duration * double) {
34
35
  bubble.clicking = false;
35
36
  bubble.durationEnd = false;
36
37
  }
@@ -53,7 +54,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
53
54
  },
54
55
  particlesObj: {
55
56
  optValue: (0, engine_1.getRangeMax)(particle.options.opacity.value),
56
- value: particle.opacity?.value ?? 1,
57
+ value: particle.opacity?.value ?? defaultOpacity,
57
58
  },
58
59
  type: "opacity",
59
60
  };
@@ -68,15 +69,15 @@ class Bubbler extends engine_1.ExternalInteractorBase {
68
69
  };
69
70
  this._hoverBubble = () => {
70
71
  const container = this.container, mousePos = container.interactivity.mouse.position, distance = container.retina.bubbleModeDistance;
71
- if (!distance || distance < 0 || mousePos === undefined) {
72
+ if (!distance || distance < minDistance || !mousePos) {
72
73
  return;
73
74
  }
74
75
  const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
75
76
  for (const particle of query) {
76
77
  particle.bubble.inRange = true;
77
- const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos), ratio = 1 - pointDistance / distance;
78
+ const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos), ratio = ratioOffset - pointDistance / distance;
78
79
  if (pointDistance <= distance) {
79
- if (ratio >= 0 && container.interactivity.status === engine_1.mouseMoveEvent) {
80
+ if (ratio >= minRatio && container.interactivity.status === engine_1.mouseMoveEvent) {
80
81
  this._hoverBubbleSize(particle, ratio);
81
82
  this._hoverBubbleOpacity(particle, ratio);
82
83
  this._hoverBubbleColor(particle, ratio);
@@ -110,7 +111,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
110
111
  particle.bubble.color = undefined;
111
112
  const pColor = particle.getFillColor();
112
113
  particle.bubble.color = pColor
113
- ? (0, engine_1.rgbToHsl)((0, engine_1.colorMix)(pColor, particle.bubble.finalColor, 1 - ratio, ratio))
114
+ ? (0, engine_1.rgbToHsl)((0, engine_1.colorMix)(pColor, particle.bubble.finalColor, ratioOffset - ratio, ratio))
114
115
  : particle.bubble.finalColor;
115
116
  }
116
117
  else {
@@ -122,7 +123,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
122
123
  if (!modeOpacity) {
123
124
  return;
124
125
  }
125
- const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? 1, opacity = (0, Utils_js_1.calculateBubbleValue)(pOpacity, modeOpacity, (0, engine_1.getRangeMax)(optOpacity), ratio);
126
+ const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? defaultOpacity, opacity = (0, Utils_js_1.calculateBubbleValue)(pOpacity, modeOpacity, (0, engine_1.getRangeMax)(optOpacity), ratio);
126
127
  if (opacity !== undefined) {
127
128
  particle.bubble.opacity = opacity;
128
129
  }
@@ -142,8 +143,8 @@ class Bubbler extends engine_1.ExternalInteractorBase {
142
143
  if (!bubbleOptions || bubbleParam === undefined) {
143
144
  return;
144
145
  }
145
- const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value || 0, type = data.type;
146
- if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
146
+ const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value ?? defaultBubbleValue, type = data.type;
147
+ if (!bubbleDistance || bubbleDistance < minDistance || bubbleParam === particlesParam) {
147
148
  return;
148
149
  }
149
150
  if (!container.bubble) {
@@ -189,9 +190,9 @@ class Bubbler extends engine_1.ExternalInteractorBase {
189
190
  }
190
191
  selectors.forEach((item) => {
191
192
  const elem = item, pxRatio = container.retina.pixelRatio, pos = {
192
- x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
193
- y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
194
- }, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
193
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
194
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
195
+ }, repulseRadius = elem.offsetWidth * half * pxRatio, area = div.type === "circle"
195
196
  ? new engine_1.Circle(pos.x, pos.y, repulseRadius)
196
197
  : 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));
197
198
  for (const particle of query) {
@@ -204,9 +205,9 @@ class Bubbler extends engine_1.ExternalInteractorBase {
204
205
  this.clear(particle, delta, true);
205
206
  particle.bubble.div = elem;
206
207
  }
207
- this._hoverBubbleSize(particle, 1, divBubble);
208
- this._hoverBubbleOpacity(particle, 1, divBubble);
209
- this._hoverBubbleColor(particle, 1, divBubble);
208
+ this._hoverBubbleSize(particle, defaultRatio, divBubble);
209
+ this._hoverBubbleOpacity(particle, defaultRatio, divBubble);
210
+ this._hoverBubbleColor(particle, defaultRatio, divBubble);
210
211
  }
211
212
  });
212
213
  };
@@ -253,10 +254,11 @@ class Bubbler extends engine_1.ExternalInteractorBase {
253
254
  else {
254
255
  (0, engine_1.divModeExecute)(bubbleMode, divs, (selector, div) => this._singleSelectorHover(delta, selector, div));
255
256
  }
257
+ await Promise.resolve();
256
258
  }
257
259
  isEnabled(particle) {
258
260
  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)(bubbleMode, onDiv);
259
- if (!(divBubble || (onHover.enable && mouse.position) || (onClick.enable && mouse.clickPosition))) {
261
+ if (!(divBubble || (onHover.enable && !!mouse.position) || (onClick.enable && mouse.clickPosition))) {
260
262
  return false;
261
263
  }
262
264
  return (0, engine_1.isInArray)(bubbleMode, onHover.mode) || (0, engine_1.isInArray)(bubbleMode, onClick.mode) || divBubble;
package/cjs/index.js CHANGED
@@ -10,14 +10,28 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
17
29
  exports.loadExternalBubbleInteraction = void 0;
18
- const Bubbler_js_1 = require("./Bubbler.js");
19
30
  async function loadExternalBubbleInteraction(engine, refresh = true) {
20
- await engine.addInteractor("externalBubble", (container) => new Bubbler_js_1.Bubbler(container), refresh);
31
+ await engine.addInteractor("externalBubble", async (container) => {
32
+ const { Bubbler } = await Promise.resolve().then(() => __importStar(require("./Bubbler.js")));
33
+ return new Bubbler(container);
34
+ }, refresh);
21
35
  }
22
36
  exports.loadExternalBubbleInteraction = loadExternalBubbleInteraction;
23
37
  __exportStar(require("./Options/Classes/BubbleBase.js"), exports);
@@ -0,0 +1,40 @@
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.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_interaction_external_bubble"] = this["webpackChunk_tsparticles_interaction_external_bubble"] || []).push([["dist_browser_Bubbler_js"],{
19
+
20
+ /***/ "./dist/browser/Bubbler.js":
21
+ /*!*********************************!*\
22
+ !*** ./dist/browser/Bubbler.js ***!
23
+ \*********************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Bubbler: () => (/* binding */ Bubbler)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Options_Classes_Bubble_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Bubble.js */ \"./dist/browser/Options/Classes/Bubble.js\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\n\nconst bubbleMode = \"bubble\",\n minDistance = 0,\n defaultClickTime = 0,\n double = 2,\n defaultOpacity = 1,\n ratioOffset = 1,\n defaultBubbleValue = 0,\n minRatio = 0,\n half = 0.5,\n defaultRatio = 1;\nclass Bubbler extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ExternalInteractorBase {\n constructor(container) {\n super(container);\n this._clickBubble = () => {\n const container = this.container,\n options = container.actualOptions,\n mouseClickPos = container.interactivity.mouse.clickPosition,\n bubbleOptions = options.interactivity.modes.bubble;\n if (!bubbleOptions || !mouseClickPos) {\n return;\n }\n if (!container.bubble) {\n container.bubble = {};\n }\n const distance = container.retina.bubbleModeDistance;\n if (!distance || distance < minDistance) {\n return;\n }\n const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, p => this.isEnabled(p)),\n {\n bubble\n } = container;\n for (const particle of query) {\n if (!bubble.clicking) {\n continue;\n }\n particle.bubble.inRange = !bubble.durationEnd;\n const pos = particle.getPosition(),\n distMouse = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(pos, mouseClickPos),\n timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime ?? defaultClickTime)) / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n if (timeSpent > bubbleOptions.duration) {\n bubble.durationEnd = true;\n }\n if (timeSpent > bubbleOptions.duration * double) {\n bubble.clicking = false;\n bubble.durationEnd = false;\n }\n const sizeData = {\n bubbleObj: {\n optValue: container.retina.bubbleModeSize,\n value: particle.bubble.radius\n },\n particlesObj: {\n optValue: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio,\n value: particle.size.value\n },\n type: \"size\"\n };\n this._process(particle, distMouse, timeSpent, sizeData);\n const opacityData = {\n bubbleObj: {\n optValue: bubbleOptions.opacity,\n value: particle.bubble.opacity\n },\n particlesObj: {\n optValue: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particle.options.opacity.value),\n value: particle.opacity?.value ?? defaultOpacity\n },\n type: \"opacity\"\n };\n this._process(particle, distMouse, timeSpent, opacityData);\n if (!bubble.durationEnd && distMouse <= distance) {\n this._hoverBubbleColor(particle, distMouse);\n } else {\n delete particle.bubble.color;\n }\n }\n };\n this._hoverBubble = () => {\n const container = this.container,\n mousePos = container.interactivity.mouse.position,\n distance = container.retina.bubbleModeDistance;\n if (!distance || distance < minDistance || !mousePos) {\n return;\n }\n const query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));\n for (const particle of query) {\n particle.bubble.inRange = true;\n const pos = particle.getPosition(),\n pointDistance = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(pos, mousePos),\n ratio = ratioOffset - pointDistance / distance;\n if (pointDistance <= distance) {\n if (ratio >= minRatio && container.interactivity.status === _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.mouseMoveEvent) {\n this._hoverBubbleSize(particle, ratio);\n this._hoverBubbleOpacity(particle, ratio);\n this._hoverBubbleColor(particle, ratio);\n }\n } else {\n this.reset(particle);\n }\n if (container.interactivity.status === _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.mouseLeaveEvent) {\n this.reset(particle);\n }\n }\n };\n this._hoverBubbleColor = (particle, ratio, divBubble) => {\n const options = this.container.actualOptions,\n bubbleOptions = divBubble ?? options.interactivity.modes.bubble;\n if (!bubbleOptions) {\n return;\n }\n if (!particle.bubble.finalColor) {\n const modeColor = bubbleOptions.color;\n if (!modeColor) {\n return;\n }\n const bubbleColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(modeColor);\n particle.bubble.finalColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(bubbleColor);\n }\n if (!particle.bubble.finalColor) {\n return;\n }\n if (bubbleOptions.mix) {\n particle.bubble.color = undefined;\n const pColor = particle.getFillColor();\n particle.bubble.color = pColor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rgbToHsl)((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.colorMix)(pColor, particle.bubble.finalColor, ratioOffset - ratio, ratio)) : particle.bubble.finalColor;\n } else {\n particle.bubble.color = particle.bubble.finalColor;\n }\n };\n this._hoverBubbleOpacity = (particle, ratio, divBubble) => {\n const container = this.container,\n options = container.actualOptions,\n modeOpacity = divBubble?.opacity ?? options.interactivity.modes.bubble?.opacity;\n if (!modeOpacity) {\n return;\n }\n const optOpacity = particle.options.opacity.value,\n pOpacity = particle.opacity?.value ?? defaultOpacity,\n opacity = (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.calculateBubbleValue)(pOpacity, modeOpacity, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(optOpacity), ratio);\n if (opacity !== undefined) {\n particle.bubble.opacity = opacity;\n }\n };\n this._hoverBubbleSize = (particle, ratio, divBubble) => {\n const container = this.container,\n modeSize = divBubble?.size ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;\n if (modeSize === undefined) {\n return;\n }\n const optSize = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio,\n pSize = particle.size.value,\n size = (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.calculateBubbleValue)(pSize, modeSize, optSize, ratio);\n if (size !== undefined) {\n particle.bubble.radius = size;\n }\n };\n this._process = (particle, distMouse, timeSpent, data) => {\n const container = this.container,\n bubbleParam = data.bubbleObj.optValue,\n options = container.actualOptions,\n bubbleOptions = options.interactivity.modes.bubble;\n if (!bubbleOptions || bubbleParam === undefined) {\n return;\n }\n const bubbleDuration = bubbleOptions.duration,\n bubbleDistance = container.retina.bubbleModeDistance,\n particlesParam = data.particlesObj.optValue,\n pObjBubble = data.bubbleObj.value,\n pObj = data.particlesObj.value ?? defaultBubbleValue,\n type = data.type;\n if (!bubbleDistance || bubbleDistance < minDistance || bubbleParam === particlesParam) {\n return;\n }\n if (!container.bubble) {\n container.bubble = {};\n }\n if (container.bubble.durationEnd) {\n if (pObjBubble) {\n if (type === \"size\") {\n delete particle.bubble.radius;\n }\n if (type === \"opacity\") {\n delete particle.bubble.opacity;\n }\n }\n } else {\n if (distMouse <= bubbleDistance) {\n const obj = pObjBubble ?? pObj;\n if (obj !== bubbleParam) {\n const value = pObj - timeSpent * (pObj - bubbleParam) / bubbleDuration;\n if (type === \"size\") {\n particle.bubble.radius = value;\n }\n if (type === \"opacity\") {\n particle.bubble.opacity = value;\n }\n }\n } else {\n if (type === \"size\") {\n delete particle.bubble.radius;\n }\n if (type === \"opacity\") {\n delete particle.bubble.opacity;\n }\n }\n }\n };\n this._singleSelectorHover = (delta, selector, div) => {\n const container = this.container,\n selectors = document.querySelectorAll(selector),\n bubble = container.actualOptions.interactivity.modes.bubble;\n if (!bubble || !selectors.length) {\n return;\n }\n selectors.forEach(item => {\n const elem = item,\n pxRatio = container.retina.pixelRatio,\n pos = {\n x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,\n y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio\n },\n repulseRadius = elem.offsetWidth * half * pxRatio,\n area = div.type === \"circle\" ? new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(pos.x, pos.y, repulseRadius) : new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio),\n query = container.particles.quadTree.query(area, p => this.isEnabled(p));\n for (const particle of query) {\n if (!area.contains(particle.getPosition())) {\n continue;\n }\n particle.bubble.inRange = true;\n const divs = bubble.divs,\n divBubble = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.divMode)(divs, elem);\n if (!particle.bubble.div || particle.bubble.div !== elem) {\n this.clear(particle, delta, true);\n particle.bubble.div = elem;\n }\n this._hoverBubbleSize(particle, defaultRatio, divBubble);\n this._hoverBubbleOpacity(particle, defaultRatio, divBubble);\n this._hoverBubbleColor(particle, defaultRatio, divBubble);\n }\n });\n };\n if (!container.bubble) {\n container.bubble = {};\n }\n this.handleClickMode = mode => {\n if (mode !== bubbleMode) {\n return;\n }\n if (!container.bubble) {\n container.bubble = {};\n }\n container.bubble.clicking = true;\n };\n }\n clear(particle, delta, force) {\n if (particle.bubble.inRange && !force) {\n return;\n }\n delete particle.bubble.div;\n delete particle.bubble.opacity;\n delete particle.bubble.radius;\n delete particle.bubble.color;\n }\n init() {\n const container = this.container,\n bubble = container.actualOptions.interactivity.modes.bubble;\n if (!bubble) {\n return;\n }\n container.retina.bubbleModeDistance = bubble.distance * container.retina.pixelRatio;\n if (bubble.size !== undefined) {\n container.retina.bubbleModeSize = bubble.size * container.retina.pixelRatio;\n }\n }\n async interact(delta) {\n const options = this.container.actualOptions,\n events = options.interactivity.events,\n onHover = events.onHover,\n onClick = events.onClick,\n hoverEnabled = onHover.enable,\n hoverMode = onHover.mode,\n clickEnabled = onClick.enable,\n clickMode = onClick.mode,\n divs = events.onDiv;\n if (hoverEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(bubbleMode, hoverMode)) {\n this._hoverBubble();\n } else if (clickEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(bubbleMode, clickMode)) {\n this._clickBubble();\n } else {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.divModeExecute)(bubbleMode, divs, (selector, div) => this._singleSelectorHover(delta, selector, div));\n }\n await Promise.resolve();\n }\n isEnabled(particle) {\n const container = this.container,\n options = container.actualOptions,\n mouse = container.interactivity.mouse,\n events = (particle?.interactivity ?? options.interactivity).events,\n {\n onClick,\n onDiv,\n onHover\n } = events,\n divBubble = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isDivModeEnabled)(bubbleMode, onDiv);\n if (!(divBubble || onHover.enable && !!mouse.position || onClick.enable && mouse.clickPosition)) {\n return false;\n }\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(bubbleMode, onHover.mode) || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(bubbleMode, onClick.mode) || divBubble;\n }\n loadModeOptions(options, ...sources) {\n if (!options.bubble) {\n options.bubble = new _Options_Classes_Bubble_js__WEBPACK_IMPORTED_MODULE_2__.Bubble();\n }\n for (const source of sources) {\n options.bubble.load(source?.bubble);\n }\n }\n reset(particle) {\n particle.bubble.inRange = false;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-external-bubble/./dist/browser/Bubbler.js?");
27
+
28
+ /***/ }),
29
+
30
+ /***/ "./dist/browser/Utils.js":
31
+ /*!*******************************!*\
32
+ !*** ./dist/browser/Utils.js ***!
33
+ \*******************************/
34
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
35
+
36
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ calculateBubbleValue: () => (/* binding */ calculateBubbleValue)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nfunction calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {\n if (modeValue >= optionsValue) {\n const value = particleValue + (modeValue - optionsValue) * ratio;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.clamp)(value, particleValue, modeValue);\n } else if (modeValue < optionsValue) {\n const value = particleValue - (optionsValue - modeValue) * ratio;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.clamp)(value, modeValue, particleValue);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-external-bubble/./dist/browser/Utils.js?");
37
+
38
+ /***/ })
39
+
40
+ }]);
package/esm/Bubbler.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Circle, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, } from "@tsparticles/engine";
1
+ import { Circle, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, millisecondsToSeconds, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, } from "@tsparticles/engine";
2
2
  import { Bubble } from "./Options/Classes/Bubble.js";
3
3
  import { calculateBubbleValue } from "./Utils.js";
4
- const bubbleMode = "bubble";
4
+ const bubbleMode = "bubble", minDistance = 0, defaultClickTime = 0, double = 2, defaultOpacity = 1, ratioOffset = 1, defaultBubbleValue = 0, minRatio = 0, half = 0.5, defaultRatio = 1;
5
5
  export class Bubbler extends ExternalInteractorBase {
6
6
  constructor(container) {
7
7
  super(container);
@@ -14,7 +14,7 @@ export class Bubbler extends ExternalInteractorBase {
14
14
  container.bubble = {};
15
15
  }
16
16
  const distance = container.retina.bubbleModeDistance;
17
- if (!distance || distance < 0) {
17
+ if (!distance || distance < minDistance) {
18
18
  return;
19
19
  }
20
20
  const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, (p) => this.isEnabled(p)), { bubble } = container;
@@ -23,11 +23,12 @@ export class Bubbler extends ExternalInteractorBase {
23
23
  continue;
24
24
  }
25
25
  particle.bubble.inRange = !bubble.durationEnd;
26
- const pos = particle.getPosition(), distMouse = getDistance(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
26
+ const pos = particle.getPosition(), distMouse = getDistance(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime ?? defaultClickTime)) /
27
+ millisecondsToSeconds;
27
28
  if (timeSpent > bubbleOptions.duration) {
28
29
  bubble.durationEnd = true;
29
30
  }
30
- if (timeSpent > bubbleOptions.duration * 2) {
31
+ if (timeSpent > bubbleOptions.duration * double) {
31
32
  bubble.clicking = false;
32
33
  bubble.durationEnd = false;
33
34
  }
@@ -50,7 +51,7 @@ export class Bubbler extends ExternalInteractorBase {
50
51
  },
51
52
  particlesObj: {
52
53
  optValue: getRangeMax(particle.options.opacity.value),
53
- value: particle.opacity?.value ?? 1,
54
+ value: particle.opacity?.value ?? defaultOpacity,
54
55
  },
55
56
  type: "opacity",
56
57
  };
@@ -65,15 +66,15 @@ export class Bubbler extends ExternalInteractorBase {
65
66
  };
66
67
  this._hoverBubble = () => {
67
68
  const container = this.container, mousePos = container.interactivity.mouse.position, distance = container.retina.bubbleModeDistance;
68
- if (!distance || distance < 0 || mousePos === undefined) {
69
+ if (!distance || distance < minDistance || !mousePos) {
69
70
  return;
70
71
  }
71
72
  const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
72
73
  for (const particle of query) {
73
74
  particle.bubble.inRange = true;
74
- const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos), ratio = 1 - pointDistance / distance;
75
+ const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos), ratio = ratioOffset - pointDistance / distance;
75
76
  if (pointDistance <= distance) {
76
- if (ratio >= 0 && container.interactivity.status === mouseMoveEvent) {
77
+ if (ratio >= minRatio && container.interactivity.status === mouseMoveEvent) {
77
78
  this._hoverBubbleSize(particle, ratio);
78
79
  this._hoverBubbleOpacity(particle, ratio);
79
80
  this._hoverBubbleColor(particle, ratio);
@@ -107,7 +108,7 @@ export class Bubbler extends ExternalInteractorBase {
107
108
  particle.bubble.color = undefined;
108
109
  const pColor = particle.getFillColor();
109
110
  particle.bubble.color = pColor
110
- ? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, 1 - ratio, ratio))
111
+ ? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, ratioOffset - ratio, ratio))
111
112
  : particle.bubble.finalColor;
112
113
  }
113
114
  else {
@@ -119,7 +120,7 @@ export class Bubbler extends ExternalInteractorBase {
119
120
  if (!modeOpacity) {
120
121
  return;
121
122
  }
122
- const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? 1, opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
123
+ const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? defaultOpacity, opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
123
124
  if (opacity !== undefined) {
124
125
  particle.bubble.opacity = opacity;
125
126
  }
@@ -139,8 +140,8 @@ export class Bubbler extends ExternalInteractorBase {
139
140
  if (!bubbleOptions || bubbleParam === undefined) {
140
141
  return;
141
142
  }
142
- const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value || 0, type = data.type;
143
- if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
143
+ const bubbleDuration = bubbleOptions.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value ?? defaultBubbleValue, type = data.type;
144
+ if (!bubbleDistance || bubbleDistance < minDistance || bubbleParam === particlesParam) {
144
145
  return;
145
146
  }
146
147
  if (!container.bubble) {
@@ -186,9 +187,9 @@ export class Bubbler extends ExternalInteractorBase {
186
187
  }
187
188
  selectors.forEach((item) => {
188
189
  const elem = item, pxRatio = container.retina.pixelRatio, pos = {
189
- x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
190
- y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
191
- }, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
190
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
191
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
192
+ }, repulseRadius = elem.offsetWidth * half * pxRatio, area = div.type === "circle"
192
193
  ? new Circle(pos.x, pos.y, repulseRadius)
193
194
  : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
194
195
  for (const particle of query) {
@@ -201,9 +202,9 @@ export class Bubbler extends ExternalInteractorBase {
201
202
  this.clear(particle, delta, true);
202
203
  particle.bubble.div = elem;
203
204
  }
204
- this._hoverBubbleSize(particle, 1, divBubble);
205
- this._hoverBubbleOpacity(particle, 1, divBubble);
206
- this._hoverBubbleColor(particle, 1, divBubble);
205
+ this._hoverBubbleSize(particle, defaultRatio, divBubble);
206
+ this._hoverBubbleOpacity(particle, defaultRatio, divBubble);
207
+ this._hoverBubbleColor(particle, defaultRatio, divBubble);
207
208
  }
208
209
  });
209
210
  };
@@ -250,10 +251,11 @@ export class Bubbler extends ExternalInteractorBase {
250
251
  else {
251
252
  divModeExecute(bubbleMode, divs, (selector, div) => this._singleSelectorHover(delta, selector, div));
252
253
  }
254
+ await Promise.resolve();
253
255
  }
254
256
  isEnabled(particle) {
255
257
  const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, { onClick, onDiv, onHover } = events, divBubble = isDivModeEnabled(bubbleMode, onDiv);
256
- if (!(divBubble || (onHover.enable && mouse.position) || (onClick.enable && mouse.clickPosition))) {
258
+ if (!(divBubble || (onHover.enable && !!mouse.position) || (onClick.enable && mouse.clickPosition))) {
257
259
  return false;
258
260
  }
259
261
  return isInArray(bubbleMode, onHover.mode) || isInArray(bubbleMode, onClick.mode) || divBubble;
package/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
- import { Bubbler } from "./Bubbler.js";
2
1
  export async function loadExternalBubbleInteraction(engine, refresh = true) {
3
- await engine.addInteractor("externalBubble", (container) => new Bubbler(container), refresh);
2
+ await engine.addInteractor("externalBubble", async (container) => {
3
+ const { Bubbler } = await import("./Bubbler.js");
4
+ return new Bubbler(container);
5
+ }, refresh);
4
6
  }
5
7
  export * from "./Options/Classes/BubbleBase.js";
6
8
  export * from "./Options/Classes/BubbleDiv.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/interaction-external-bubble",
3
- "version": "3.0.3",
3
+ "version": "3.2.0",
4
4
  "description": "tsParticles bubble external interaction",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -87,7 +87,7 @@
87
87
  "./package.json": "./package.json"
88
88
  },
89
89
  "dependencies": {
90
- "@tsparticles/engine": "^3.0.3"
90
+ "@tsparticles/engine": "^3.2.0"
91
91
  },
92
92
  "publishConfig": {
93
93
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/interaction-external-bubble [26 Dec 2023 at 19:24]</title>
6
+ <title>@tsparticles/interaction-external-bubble [31 Jan 2024 at 02:03]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -31,8 +31,8 @@
31
31
  <body>
32
32
  <div id="app"></div>
33
33
  <script>
34
- window.chartData = [{"label":"tsparticles.interaction.external.bubble.js","isAsset":true,"statSize":14238,"parsedSize":18134,"gzipSize":4062,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":14196,"groups":[{"id":403,"label":"index.js + 5 modules (concatenated)","path":"./dist/browser/index.js + 5 modules (concatenated)","statSize":14196,"parsedSize":18134,"gzipSize":4062,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser","statSize":14196,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/index.js","statSize":509,"parsedSize":650,"gzipSize":145,"inaccurateSizes":true},{"id":null,"label":"Bubbler.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Bubbler.js","statSize":11607,"parsedSize":14826,"gzipSize":3321,"inaccurateSizes":true},{"label":"Options/Classes","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes","statSize":1626,"groups":[{"id":null,"label":"Bubble.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes/Bubble.js","statSize":419,"parsedSize":535,"gzipSize":119,"inaccurateSizes":true},{"id":null,"label":"BubbleBase.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes/BubbleBase.js","statSize":893,"parsedSize":1140,"gzipSize":255,"inaccurateSizes":true},{"id":null,"label":"BubbleDiv.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Options/Classes/BubbleDiv.js","statSize":314,"parsedSize":401,"gzipSize":89,"inaccurateSizes":true}],"parsedSize":2077,"gzipSize":465,"inaccurateSizes":true},{"id":null,"label":"Utils.js","path":"./dist/browser/index.js + 5 modules (concatenated)/dist/browser/Utils.js","statSize":454,"parsedSize":579,"gzipSize":129,"inaccurateSizes":true}],"parsedSize":18134,"gzipSize":4062,"inaccurateSizes":true}]}],"parsedSize":18134,"gzipSize":4062},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.interaction.external.bubble":true}}];
35
- window.entrypoints = ["tsparticles.interaction.external.bubble","tsparticles.interaction.external.bubble.min"];
34
+ window.chartData = [];
35
+ window.entrypoints = ["tsparticles.interaction.external.bubble.min"];
36
36
  window.defaultSizes = "parsed";
37
37
  </script>
38
38
  </body>