@tsparticles/interaction-external-bubble 3.9.1 → 4.0.0-alpha.1

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/809.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 809.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_interaction_external_bubble=this.webpackChunk_tsparticles_interaction_external_bubble||[]).push([[809],{809(e,i,t){t.d(i,{Bubbler:()=>a});var o,b=t(303),n=t(888);function l(e,i,t,o){if(i>=t){const n=e+(i-t)*o;return(0,b.clamp)(n,e,i)}if(i<t){const n=e-(t-i)*o;return(0,b.clamp)(n,i,e)}}!function(e){e.color="color",e.opacity="opacity",e.size="size"}(o||(o={}));const s="bubble";class a extends b.ExternalInteractorBase{constructor(e,i){super(i),this._clickBubble=()=>{const e=this.container,i=e.actualOptions,t=e.interactivity.mouse.clickPosition,n=i.interactivity.modes.bubble;if(!n||!t)return;e.bubble??={};const l=e.retina.bubbleModeDistance;if(!l||l<0)return;const s=e.particles.quadTree.queryCircle(t,l,(e=>this.isEnabled(e))),{bubble:a}=e;for(const i of s){if(!a.clicking)continue;i.bubble.inRange=!a.durationEnd;const s=i.getPosition(),r=(0,b.getDistance)(s,t),c=((new Date).getTime()-(e.interactivity.mouse.clickTime??0))/b.millisecondsToSeconds;c>n.duration&&(a.durationEnd=!0),c>2*n.duration&&(a.clicking=!1,a.durationEnd=!1);const u={bubbleObj:{optValue:e.retina.bubbleModeSize,value:i.bubble.radius},particlesObj:{optValue:(0,b.getRangeMax)(i.options.size.value)*e.retina.pixelRatio,value:i.size.value},type:o.size};this._process(i,r,c,u);const d={bubbleObj:{optValue:n.opacity,value:i.bubble.opacity},particlesObj:{optValue:(0,b.getRangeMax)(i.options.opacity.value),value:i.opacity?.value??1},type:o.opacity};this._process(i,r,c,d),!a.durationEnd&&r<=l?this._hoverBubbleColor(i,r):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 o=e.particles.quadTree.queryCircle(i,t,(e=>this.isEnabled(e)));for(const n of o){n.bubble.inRange=!0;const o=n.getPosition(),l=(0,b.getDistance)(o,i),s=1-l/t;l<=t?s>=0&&e.interactivity.status===b.mouseMoveEvent&&(this._hoverBubbleSize(n,s),this._hoverBubbleOpacity(n,s),this._hoverBubbleColor(n,s)):this.reset(n),e.interactivity.status===b.mouseLeaveEvent&&this.reset(n)}},this._hoverBubbleColor=(e,i,t)=>{const o=this.container.actualOptions,n=t??o.interactivity.modes.bubble;if(n){if(!e.bubble.finalColor){const i=n.color;if(!i)return;const t=(0,b.itemFromSingleOrMultiple)(i);e.bubble.finalColor=(0,b.rangeColorToHsl)(this._engine,t)}if(e.bubble.finalColor)if(n.mix){e.bubble.color=void 0;const t=e.getFillColor();e.bubble.color=t?(0,b.rgbToHsl)((0,b.colorMix)(t,e.bubble.finalColor,1-i,i)):e.bubble.finalColor}else e.bubble.color=e.bubble.finalColor}},this._hoverBubbleOpacity=(e,i,t)=>{const o=this.container.actualOptions,n=t?.opacity??o.interactivity.modes.bubble?.opacity;if(!n)return;const s=e.options.opacity.value,a=l(e.opacity?.value??1,n,(0,b.getRangeMax)(s),i);void 0!==a&&(e.bubble.opacity=a)},this._hoverBubbleSize=(e,i,t)=>{const o=this.container,n=t?.size?t.size*o.retina.pixelRatio:o.retina.bubbleModeSize;if(void 0===n)return;const s=(0,b.getRangeMax)(e.options.size.value)*o.retina.pixelRatio,a=l(e.size.value,n,s,i);void 0!==a&&(e.bubble.radius=a)},this._process=(e,i,t,b)=>{const n=this.container,l=b.bubbleObj.optValue,s=n.actualOptions.interactivity.modes.bubble;if(!s||void 0===l)return;const a=s.duration,r=n.retina.bubbleModeDistance,c=b.particlesObj.optValue,u=b.bubbleObj.value,d=b.particlesObj.value??0,p=b.type;if(r&&!(r<0)&&l!==c)if(n.bubble??={},n.bubble.durationEnd)u&&(p===o.size&&delete e.bubble.radius,p===o.opacity&&delete e.bubble.opacity);else if(i<=r){if((u??d)!==l){const i=d-t*(d-l)/a;p===o.size&&(e.bubble.radius=i),p===o.opacity&&(e.bubble.opacity=i)}}else p===o.size&&delete e.bubble.radius,p===o.opacity&&delete e.bubble.opacity},this._singleSelectorHover=(e,i,t)=>{const o=this.container,n=(0,b.safeDocument)().querySelectorAll(i),l=o.actualOptions.interactivity.modes.bubble;l&&n.length&&n.forEach((i=>{const n=i,s=o.retina.pixelRatio,a={x:(n.offsetLeft+.5*n.offsetWidth)*s,y:(n.offsetTop+.5*n.offsetHeight)*s},r=.5*n.offsetWidth*s,c=t.type===b.DivType.circle?new b.Circle(a.x,a.y,r):new b.Rectangle(n.offsetLeft*s,n.offsetTop*s,n.offsetWidth*s,n.offsetHeight*s),u=o.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=l.divs,o=(0,b.divMode)(t,n);i.bubble.div&&i.bubble.div===n||(this.clear(i,e,!0),i.bubble.div=n),this._hoverBubbleSize(i,1,o),this._hoverBubbleOpacity(i,1,o),this._hoverBubbleColor(i,1,o)}}))},this._engine=e,i.bubble??={},this.handleClickMode=e=>{e===s&&(i.bubble??={},i.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))}interact(e){const i=this.container.actualOptions.interactivity.events,t=i.onHover,o=i.onClick,n=t.enable,l=t.mode,a=o.enable,r=o.mode,c=i.onDiv;n&&(0,b.isInArray)(s,l)?this._hoverBubble():a&&(0,b.isInArray)(s,r)?this._clickBubble():(0,b.divModeExecute)(s,c,((i,t)=>{this._singleSelectorHover(e,i,t)}))}isEnabled(e){const i=this.container,t=i.actualOptions,o=i.interactivity.mouse,n=(e?.interactivity??t.interactivity).events,{onClick:l,onDiv:a,onHover:r}=n,c=(0,b.isDivModeEnabled)(s,a);return!!(c||r.enable&&o.position||l.enable&&o.clickPosition)&&((0,b.isInArray)(s,r.mode)||(0,b.isInArray)(s,l.mode)||c)}loadModeOptions(e,...i){e.bubble??=new n.Z;for(const t of i)e.bubble.load(t?.bubble)}reset(e){e.bubble.inRange=!1}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Bubble External Interaction v4.0.0-alpha.1 by Matteo Bruni */
@@ -1,19 +1,17 @@
1
- import { Circle, DivType, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, millisecondsToSeconds, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, } from "@tsparticles/engine";
1
+ import { Circle, DivType, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, millisecondsToSeconds, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, safeDocument, } from "@tsparticles/engine";
2
2
  import { Bubble } from "./Options/Classes/Bubble.js";
3
3
  import { ProcessBubbleType } from "./Enums.js";
4
4
  import { calculateBubbleValue } from "./Utils.js";
5
5
  const bubbleMode = "bubble", minDistance = 0, defaultClickTime = 0, double = 2, defaultOpacity = 1, ratioOffset = 1, defaultBubbleValue = 0, minRatio = 0, half = 0.5, defaultRatio = 1;
6
6
  export class Bubbler extends ExternalInteractorBase {
7
- constructor(container, engine) {
7
+ constructor(engine, container) {
8
8
  super(container);
9
9
  this._clickBubble = () => {
10
10
  const container = this.container, options = container.actualOptions, mouseClickPos = container.interactivity.mouse.clickPosition, bubbleOptions = options.interactivity.modes.bubble;
11
11
  if (!bubbleOptions || !mouseClickPos) {
12
12
  return;
13
13
  }
14
- if (!container.bubble) {
15
- container.bubble = {};
16
- }
14
+ container.bubble ??= {};
17
15
  const distance = container.retina.bubbleModeDistance;
18
16
  if (!distance || distance < minDistance) {
19
17
  return;
@@ -145,9 +143,7 @@ export class Bubbler extends ExternalInteractorBase {
145
143
  if (!bubbleDistance || bubbleDistance < minDistance || bubbleParam === particlesParam) {
146
144
  return;
147
145
  }
148
- if (!container.bubble) {
149
- container.bubble = {};
150
- }
146
+ container.bubble ??= {};
151
147
  if (container.bubble.durationEnd) {
152
148
  if (pObjBubble) {
153
149
  if (type === ProcessBubbleType.size) {
@@ -182,7 +178,7 @@ export class Bubbler extends ExternalInteractorBase {
182
178
  }
183
179
  };
184
180
  this._singleSelectorHover = (delta, selector, div) => {
185
- const container = this.container, selectors = document.querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
181
+ const container = this.container, selectors = safeDocument().querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
186
182
  if (!bubble || !selectors.length) {
187
183
  return;
188
184
  }
@@ -210,20 +206,16 @@ export class Bubbler extends ExternalInteractorBase {
210
206
  });
211
207
  };
212
208
  this._engine = engine;
213
- if (!container.bubble) {
214
- container.bubble = {};
215
- }
209
+ container.bubble ??= {};
216
210
  this.handleClickMode = (mode) => {
217
211
  if (mode !== bubbleMode) {
218
212
  return;
219
213
  }
220
- if (!container.bubble) {
221
- container.bubble = {};
222
- }
214
+ container.bubble ??= {};
223
215
  container.bubble.clicking = true;
224
216
  };
225
217
  }
226
- clear(particle, delta, force) {
218
+ clear(particle, _delta, force) {
227
219
  if (particle.bubble.inRange && !force) {
228
220
  return;
229
221
  }
@@ -251,7 +243,9 @@ export class Bubbler extends ExternalInteractorBase {
251
243
  this._clickBubble();
252
244
  }
253
245
  else {
254
- divModeExecute(bubbleMode, divs, (selector, div) => this._singleSelectorHover(delta, selector, div));
246
+ divModeExecute(bubbleMode, divs, (selector, div) => {
247
+ this._singleSelectorHover(delta, selector, div);
248
+ });
255
249
  }
256
250
  }
257
251
  isEnabled(particle) {
@@ -262,9 +256,7 @@ export class Bubbler extends ExternalInteractorBase {
262
256
  return isInArray(bubbleMode, onHover.mode) || isInArray(bubbleMode, onClick.mode) || divBubble;
263
257
  }
264
258
  loadModeOptions(options, ...sources) {
265
- if (!options.bubble) {
266
- options.bubble = new Bubble();
267
- }
259
+ options.bubble ??= new Bubble();
268
260
  for (const source of sources) {
269
261
  options.bubble.load(source?.bubble);
270
262
  }
package/browser/Utils.js CHANGED
@@ -8,4 +8,5 @@ export function calculateBubbleValue(particleValue, modeValue, optionsValue, rat
8
8
  const value = particleValue - (optionsValue - modeValue) * ratio;
9
9
  return clamp(value, modeValue, particleValue);
10
10
  }
11
+ return undefined;
11
12
  }
package/browser/index.js CHANGED
@@ -1,13 +1,12 @@
1
- import { Bubbler } from "./Bubbler.js";
2
- export async function loadExternalBubbleInteraction(engine, refresh = true) {
3
- engine.checkVersion("3.9.1");
4
- await engine.addInteractor("externalBubble", container => {
5
- return Promise.resolve(new Bubbler(container, engine));
6
- }, refresh);
1
+ export function loadExternalBubbleInteraction(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(e => {
4
+ e.addInteractor("externalBubble", async (container) => {
5
+ const { Bubbler } = await import("./Bubbler.js");
6
+ return new Bubbler(e, container);
7
+ });
8
+ });
7
9
  }
8
10
  export * from "./Options/Classes/BubbleBase.js";
9
11
  export * from "./Options/Classes/BubbleDiv.js";
10
12
  export * from "./Options/Classes/Bubble.js";
11
- export * from "./Options/Interfaces/IBubbleBase.js";
12
- export * from "./Options/Interfaces/IBubbleDiv.js";
13
- export * from "./Options/Interfaces/IBubble.js";
package/cjs/Bubbler.js CHANGED
@@ -1,22 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Bubbler = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const Bubble_js_1 = require("./Options/Classes/Bubble.js");
6
- const Enums_js_1 = require("./Enums.js");
7
- const Utils_js_1 = require("./Utils.js");
1
+ import { Circle, DivType, ExternalInteractorBase, Rectangle, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, millisecondsToSeconds, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, safeDocument, } from "@tsparticles/engine";
2
+ import { Bubble } from "./Options/Classes/Bubble.js";
3
+ import { ProcessBubbleType } from "./Enums.js";
4
+ import { calculateBubbleValue } from "./Utils.js";
8
5
  const bubbleMode = "bubble", minDistance = 0, defaultClickTime = 0, double = 2, defaultOpacity = 1, ratioOffset = 1, defaultBubbleValue = 0, minRatio = 0, half = 0.5, defaultRatio = 1;
9
- class Bubbler extends engine_1.ExternalInteractorBase {
10
- constructor(container, engine) {
6
+ export class Bubbler extends ExternalInteractorBase {
7
+ constructor(engine, container) {
11
8
  super(container);
12
9
  this._clickBubble = () => {
13
10
  const container = this.container, options = container.actualOptions, mouseClickPos = container.interactivity.mouse.clickPosition, bubbleOptions = options.interactivity.modes.bubble;
14
11
  if (!bubbleOptions || !mouseClickPos) {
15
12
  return;
16
13
  }
17
- if (!container.bubble) {
18
- container.bubble = {};
19
- }
14
+ container.bubble ??= {};
20
15
  const distance = container.retina.bubbleModeDistance;
21
16
  if (!distance || distance < minDistance) {
22
17
  return;
@@ -27,8 +22,8 @@ class Bubbler extends engine_1.ExternalInteractorBase {
27
22
  continue;
28
23
  }
29
24
  particle.bubble.inRange = !bubble.durationEnd;
30
- const pos = particle.getPosition(), distMouse = (0, engine_1.getDistance)(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime ?? defaultClickTime)) /
31
- engine_1.millisecondsToSeconds;
25
+ const pos = particle.getPosition(), distMouse = getDistance(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime ?? defaultClickTime)) /
26
+ millisecondsToSeconds;
32
27
  if (timeSpent > bubbleOptions.duration) {
33
28
  bubble.durationEnd = true;
34
29
  }
@@ -42,10 +37,10 @@ class Bubbler extends engine_1.ExternalInteractorBase {
42
37
  value: particle.bubble.radius,
43
38
  },
44
39
  particlesObj: {
45
- optValue: (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio,
40
+ optValue: getRangeMax(particle.options.size.value) * container.retina.pixelRatio,
46
41
  value: particle.size.value,
47
42
  },
48
- type: Enums_js_1.ProcessBubbleType.size,
43
+ type: ProcessBubbleType.size,
49
44
  };
50
45
  this._process(particle, distMouse, timeSpent, sizeData);
51
46
  const opacityData = {
@@ -54,10 +49,10 @@ class Bubbler extends engine_1.ExternalInteractorBase {
54
49
  value: particle.bubble.opacity,
55
50
  },
56
51
  particlesObj: {
57
- optValue: (0, engine_1.getRangeMax)(particle.options.opacity.value),
52
+ optValue: getRangeMax(particle.options.opacity.value),
58
53
  value: particle.opacity?.value ?? defaultOpacity,
59
54
  },
60
- type: Enums_js_1.ProcessBubbleType.opacity,
55
+ type: ProcessBubbleType.opacity,
61
56
  };
62
57
  this._process(particle, distMouse, timeSpent, opacityData);
63
58
  if (!bubble.durationEnd && distMouse <= distance) {
@@ -76,9 +71,9 @@ class Bubbler extends engine_1.ExternalInteractorBase {
76
71
  const query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
77
72
  for (const particle of query) {
78
73
  particle.bubble.inRange = true;
79
- const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos), ratio = ratioOffset - pointDistance / distance;
74
+ const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos), ratio = ratioOffset - pointDistance / distance;
80
75
  if (pointDistance <= distance) {
81
- if (ratio >= minRatio && container.interactivity.status === engine_1.mouseMoveEvent) {
76
+ if (ratio >= minRatio && container.interactivity.status === mouseMoveEvent) {
82
77
  this._hoverBubbleSize(particle, ratio);
83
78
  this._hoverBubbleOpacity(particle, ratio);
84
79
  this._hoverBubbleColor(particle, ratio);
@@ -87,7 +82,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
87
82
  else {
88
83
  this.reset(particle);
89
84
  }
90
- if (container.interactivity.status === engine_1.mouseLeaveEvent) {
85
+ if (container.interactivity.status === mouseLeaveEvent) {
91
86
  this.reset(particle);
92
87
  }
93
88
  }
@@ -102,8 +97,8 @@ class Bubbler extends engine_1.ExternalInteractorBase {
102
97
  if (!modeColor) {
103
98
  return;
104
99
  }
105
- const bubbleColor = (0, engine_1.itemFromSingleOrMultiple)(modeColor);
106
- particle.bubble.finalColor = (0, engine_1.rangeColorToHsl)(this._engine, bubbleColor);
100
+ const bubbleColor = itemFromSingleOrMultiple(modeColor);
101
+ particle.bubble.finalColor = rangeColorToHsl(this._engine, bubbleColor);
107
102
  }
108
103
  if (!particle.bubble.finalColor) {
109
104
  return;
@@ -112,7 +107,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
112
107
  particle.bubble.color = undefined;
113
108
  const pColor = particle.getFillColor();
114
109
  particle.bubble.color = pColor
115
- ? (0, engine_1.rgbToHsl)((0, engine_1.colorMix)(pColor, particle.bubble.finalColor, ratioOffset - ratio, ratio))
110
+ ? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, ratioOffset - ratio, ratio))
116
111
  : particle.bubble.finalColor;
117
112
  }
118
113
  else {
@@ -124,7 +119,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
124
119
  if (!modeOpacity) {
125
120
  return;
126
121
  }
127
- 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);
122
+ const optOpacity = particle.options.opacity.value, pOpacity = particle.opacity?.value ?? defaultOpacity, opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
128
123
  if (opacity !== undefined) {
129
124
  particle.bubble.opacity = opacity;
130
125
  }
@@ -134,7 +129,7 @@ class Bubbler extends engine_1.ExternalInteractorBase {
134
129
  if (modeSize === undefined) {
135
130
  return;
136
131
  }
137
- const optSize = (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio, pSize = particle.size.value, size = (0, Utils_js_1.calculateBubbleValue)(pSize, modeSize, optSize, ratio);
132
+ const optSize = getRangeMax(particle.options.size.value) * container.retina.pixelRatio, pSize = particle.size.value, size = calculateBubbleValue(pSize, modeSize, optSize, ratio);
138
133
  if (size !== undefined) {
139
134
  particle.bubble.radius = size;
140
135
  }
@@ -148,15 +143,13 @@ class Bubbler extends engine_1.ExternalInteractorBase {
148
143
  if (!bubbleDistance || bubbleDistance < minDistance || bubbleParam === particlesParam) {
149
144
  return;
150
145
  }
151
- if (!container.bubble) {
152
- container.bubble = {};
153
- }
146
+ container.bubble ??= {};
154
147
  if (container.bubble.durationEnd) {
155
148
  if (pObjBubble) {
156
- if (type === Enums_js_1.ProcessBubbleType.size) {
149
+ if (type === ProcessBubbleType.size) {
157
150
  delete particle.bubble.radius;
158
151
  }
159
- if (type === Enums_js_1.ProcessBubbleType.opacity) {
152
+ if (type === ProcessBubbleType.opacity) {
160
153
  delete particle.bubble.opacity;
161
154
  }
162
155
  }
@@ -166,26 +159,26 @@ class Bubbler extends engine_1.ExternalInteractorBase {
166
159
  const obj = pObjBubble ?? pObj;
167
160
  if (obj !== bubbleParam) {
168
161
  const value = pObj - (timeSpent * (pObj - bubbleParam)) / bubbleDuration;
169
- if (type === Enums_js_1.ProcessBubbleType.size) {
162
+ if (type === ProcessBubbleType.size) {
170
163
  particle.bubble.radius = value;
171
164
  }
172
- if (type === Enums_js_1.ProcessBubbleType.opacity) {
165
+ if (type === ProcessBubbleType.opacity) {
173
166
  particle.bubble.opacity = value;
174
167
  }
175
168
  }
176
169
  }
177
170
  else {
178
- if (type === Enums_js_1.ProcessBubbleType.size) {
171
+ if (type === ProcessBubbleType.size) {
179
172
  delete particle.bubble.radius;
180
173
  }
181
- if (type === Enums_js_1.ProcessBubbleType.opacity) {
174
+ if (type === ProcessBubbleType.opacity) {
182
175
  delete particle.bubble.opacity;
183
176
  }
184
177
  }
185
178
  }
186
179
  };
187
180
  this._singleSelectorHover = (delta, selector, div) => {
188
- const container = this.container, selectors = document.querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
181
+ const container = this.container, selectors = safeDocument().querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
189
182
  if (!bubble || !selectors.length) {
190
183
  return;
191
184
  }
@@ -193,15 +186,15 @@ class Bubbler extends engine_1.ExternalInteractorBase {
193
186
  const elem = item, pxRatio = container.retina.pixelRatio, pos = {
194
187
  x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
195
188
  y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
196
- }, repulseRadius = elem.offsetWidth * half * pxRatio, area = div.type === engine_1.DivType.circle
197
- ? new engine_1.Circle(pos.x, pos.y, repulseRadius)
198
- : 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));
189
+ }, repulseRadius = elem.offsetWidth * half * pxRatio, area = div.type === DivType.circle
190
+ ? new Circle(pos.x, pos.y, repulseRadius)
191
+ : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), query = container.particles.quadTree.query(area, p => this.isEnabled(p));
199
192
  for (const particle of query) {
200
193
  if (!area.contains(particle.getPosition())) {
201
194
  continue;
202
195
  }
203
196
  particle.bubble.inRange = true;
204
- const divs = bubble.divs, divBubble = (0, engine_1.divMode)(divs, elem);
197
+ const divs = bubble.divs, divBubble = divMode(divs, elem);
205
198
  if (!particle.bubble.div || particle.bubble.div !== elem) {
206
199
  this.clear(particle, delta, true);
207
200
  particle.bubble.div = elem;
@@ -213,20 +206,16 @@ class Bubbler extends engine_1.ExternalInteractorBase {
213
206
  });
214
207
  };
215
208
  this._engine = engine;
216
- if (!container.bubble) {
217
- container.bubble = {};
218
- }
209
+ container.bubble ??= {};
219
210
  this.handleClickMode = (mode) => {
220
211
  if (mode !== bubbleMode) {
221
212
  return;
222
213
  }
223
- if (!container.bubble) {
224
- container.bubble = {};
225
- }
214
+ container.bubble ??= {};
226
215
  container.bubble.clicking = true;
227
216
  };
228
217
  }
229
- clear(particle, delta, force) {
218
+ clear(particle, _delta, force) {
230
219
  if (particle.bubble.inRange && !force) {
231
220
  return;
232
221
  }
@@ -247,27 +236,27 @@ class Bubbler extends engine_1.ExternalInteractorBase {
247
236
  }
248
237
  interact(delta) {
249
238
  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;
250
- if (hoverEnabled && (0, engine_1.isInArray)(bubbleMode, hoverMode)) {
239
+ if (hoverEnabled && isInArray(bubbleMode, hoverMode)) {
251
240
  this._hoverBubble();
252
241
  }
253
- else if (clickEnabled && (0, engine_1.isInArray)(bubbleMode, clickMode)) {
242
+ else if (clickEnabled && isInArray(bubbleMode, clickMode)) {
254
243
  this._clickBubble();
255
244
  }
256
245
  else {
257
- (0, engine_1.divModeExecute)(bubbleMode, divs, (selector, div) => this._singleSelectorHover(delta, selector, div));
246
+ divModeExecute(bubbleMode, divs, (selector, div) => {
247
+ this._singleSelectorHover(delta, selector, div);
248
+ });
258
249
  }
259
250
  }
260
251
  isEnabled(particle) {
261
- 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);
252
+ 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);
262
253
  if (!(divBubble || (onHover.enable && !!mouse.position) || (onClick.enable && mouse.clickPosition))) {
263
254
  return false;
264
255
  }
265
- return (0, engine_1.isInArray)(bubbleMode, onHover.mode) || (0, engine_1.isInArray)(bubbleMode, onClick.mode) || divBubble;
256
+ return isInArray(bubbleMode, onHover.mode) || isInArray(bubbleMode, onClick.mode) || divBubble;
266
257
  }
267
258
  loadModeOptions(options, ...sources) {
268
- if (!options.bubble) {
269
- options.bubble = new Bubble_js_1.Bubble();
270
- }
259
+ options.bubble ??= new Bubble();
271
260
  for (const source of sources) {
272
261
  options.bubble.load(source?.bubble);
273
262
  }
@@ -276,4 +265,3 @@ class Bubbler extends engine_1.ExternalInteractorBase {
276
265
  particle.bubble.inRange = false;
277
266
  }
278
267
  }
279
- exports.Bubbler = Bubbler;
package/cjs/Enums.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProcessBubbleType = void 0;
4
- var ProcessBubbleType;
1
+ export var ProcessBubbleType;
5
2
  (function (ProcessBubbleType) {
6
3
  ProcessBubbleType["color"] = "color";
7
4
  ProcessBubbleType["opacity"] = "opacity";
8
5
  ProcessBubbleType["size"] = "size";
9
- })(ProcessBubbleType || (exports.ProcessBubbleType = ProcessBubbleType = {}));
6
+ })(ProcessBubbleType || (ProcessBubbleType = {}));
package/cjs/Interfaces.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,20 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Bubble = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const BubbleBase_js_1 = require("./BubbleBase.js");
6
- const BubbleDiv_js_1 = require("./BubbleDiv.js");
7
- class Bubble extends BubbleBase_js_1.BubbleBase {
1
+ import { executeOnSingleOrMultiple, isNull, } from "@tsparticles/engine";
2
+ import { BubbleBase } from "./BubbleBase.js";
3
+ import { BubbleDiv } from "./BubbleDiv.js";
4
+ export class Bubble extends BubbleBase {
8
5
  load(data) {
9
6
  super.load(data);
10
- if ((0, engine_1.isNull)(data)) {
7
+ if (isNull(data)) {
11
8
  return;
12
9
  }
13
- this.divs = (0, engine_1.executeOnSingleOrMultiple)(data.divs, div => {
14
- const tmp = new BubbleDiv_js_1.BubbleDiv();
10
+ this.divs = executeOnSingleOrMultiple(data.divs, div => {
11
+ const tmp = new BubbleDiv();
15
12
  tmp.load(div);
16
13
  return tmp;
17
14
  });
18
15
  }
19
16
  }
20
- exports.Bubble = Bubble;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BubbleBase = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- class BubbleBase {
1
+ import { OptionsColor, executeOnSingleOrMultiple, isArray, isNull, } from "@tsparticles/engine";
2
+ export class BubbleBase {
6
3
  constructor() {
7
4
  this.distance = 200;
8
5
  this.duration = 0.4;
9
6
  this.mix = false;
10
7
  }
11
8
  load(data) {
12
- if ((0, engine_1.isNull)(data)) {
9
+ if (isNull(data)) {
13
10
  return;
14
11
  }
15
12
  if (data.distance !== undefined) {
@@ -25,9 +22,9 @@ class BubbleBase {
25
22
  this.opacity = data.opacity;
26
23
  }
27
24
  if (data.color !== undefined) {
28
- const sourceColor = (0, engine_1.isArray)(this.color) ? undefined : this.color;
29
- this.color = (0, engine_1.executeOnSingleOrMultiple)(data.color, color => {
30
- return engine_1.OptionsColor.create(sourceColor, color);
25
+ const sourceColor = isArray(this.color) ? undefined : this.color;
26
+ this.color = executeOnSingleOrMultiple(data.color, color => {
27
+ return OptionsColor.create(sourceColor, color);
31
28
  });
32
29
  }
33
30
  if (data.size !== undefined) {
@@ -35,4 +32,3 @@ class BubbleBase {
35
32
  }
36
33
  }
37
34
  }
38
- exports.BubbleBase = BubbleBase;
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BubbleDiv = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const BubbleBase_js_1 = require("./BubbleBase.js");
6
- class BubbleDiv extends BubbleBase_js_1.BubbleBase {
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { BubbleBase } from "./BubbleBase.js";
3
+ export class BubbleDiv extends BubbleBase {
7
4
  constructor() {
8
5
  super();
9
6
  this.selectors = [];
10
7
  }
11
8
  load(data) {
12
9
  super.load(data);
13
- if ((0, engine_1.isNull)(data)) {
10
+ if (isNull(data)) {
14
11
  return;
15
12
  }
16
13
  if (data.selectors !== undefined) {
@@ -18,4 +15,3 @@ class BubbleDiv extends BubbleBase_js_1.BubbleBase {
18
15
  }
19
16
  }
20
17
  }
21
- exports.BubbleDiv = BubbleDiv;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/Types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/Utils.js CHANGED
@@ -1,14 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateBubbleValue = calculateBubbleValue;
4
- const engine_1 = require("@tsparticles/engine");
5
- function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
1
+ import { clamp } from "@tsparticles/engine";
2
+ export function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
6
3
  if (modeValue >= optionsValue) {
7
4
  const value = particleValue + (modeValue - optionsValue) * ratio;
8
- return (0, engine_1.clamp)(value, particleValue, modeValue);
5
+ return clamp(value, particleValue, modeValue);
9
6
  }
10
7
  else if (modeValue < optionsValue) {
11
8
  const value = particleValue - (optionsValue - modeValue) * ratio;
12
- return (0, engine_1.clamp)(value, modeValue, particleValue);
9
+ return clamp(value, modeValue, particleValue);
13
10
  }
11
+ return undefined;
14
12
  }
package/cjs/index.js CHANGED
@@ -1,30 +1,12 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.loadExternalBubbleInteraction = loadExternalBubbleInteraction;
18
- const Bubbler_js_1 = require("./Bubbler.js");
19
- async function loadExternalBubbleInteraction(engine, refresh = true) {
20
- engine.checkVersion("3.9.1");
21
- await engine.addInteractor("externalBubble", container => {
22
- return Promise.resolve(new Bubbler_js_1.Bubbler(container, engine));
23
- }, refresh);
1
+ export function loadExternalBubbleInteraction(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(e => {
4
+ e.addInteractor("externalBubble", async (container) => {
5
+ const { Bubbler } = await import("./Bubbler.js");
6
+ return new Bubbler(e, container);
7
+ });
8
+ });
24
9
  }
25
- __exportStar(require("./Options/Classes/BubbleBase.js"), exports);
26
- __exportStar(require("./Options/Classes/BubbleDiv.js"), exports);
27
- __exportStar(require("./Options/Classes/Bubble.js"), exports);
28
- __exportStar(require("./Options/Interfaces/IBubbleBase.js"), exports);
29
- __exportStar(require("./Options/Interfaces/IBubbleDiv.js"), exports);
30
- __exportStar(require("./Options/Interfaces/IBubble.js"), exports);
10
+ export * from "./Options/Classes/BubbleBase.js";
11
+ export * from "./Options/Classes/BubbleDiv.js";
12
+ export * from "./Options/Classes/Bubble.js";