@tsparticles/interaction-external-bubble 3.9.0 → 4.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/809.min.js +2 -0
- package/809.min.js.LICENSE.txt +1 -0
- package/browser/Bubbler.js +12 -20
- package/browser/Utils.js +1 -0
- package/browser/index.js +8 -9
- package/cjs/Bubbler.js +44 -56
- package/cjs/Enums.js +2 -5
- package/cjs/Interfaces.js +1 -2
- package/cjs/Options/Classes/Bubble.js +7 -11
- package/cjs/Options/Classes/BubbleBase.js +6 -10
- package/cjs/Options/Classes/BubbleDiv.js +4 -8
- package/cjs/Options/Classes/BubbleOptions.js +1 -2
- package/cjs/Options/Interfaces/IBubble.js +1 -2
- package/cjs/Options/Interfaces/IBubbleBase.js +1 -2
- package/cjs/Options/Interfaces/IBubbleDiv.js +1 -2
- package/cjs/Types.js +1 -2
- package/cjs/Utils.js +5 -7
- package/cjs/index.js +11 -29
- package/dist_browser_Bubbler_js.js +50 -0
- package/esm/Bubbler.js +12 -20
- package/esm/Utils.js +1 -0
- package/esm/index.js +8 -9
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.interaction.external.bubble.js +221 -62
- package/tsparticles.interaction.external.bubble.min.js +1 -1
- package/tsparticles.interaction.external.bubble.min.js.LICENSE.txt +1 -1
- package/types/Bubbler.d.ts +2 -2
- package/types/index.d.ts +4 -4
- package/umd/Bubbler.js +11 -19
- package/umd/Utils.js +1 -0
- package/umd/index.js +32 -10
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.0 by Matteo Bruni */
|
package/browser/Bubbler.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
214
|
-
container.bubble = {};
|
|
215
|
-
}
|
|
209
|
+
container.bubble ??= {};
|
|
216
210
|
this.handleClickMode = (mode) => {
|
|
217
211
|
if (mode !== bubbleMode) {
|
|
218
212
|
return;
|
|
219
213
|
}
|
|
220
|
-
|
|
221
|
-
container.bubble = {};
|
|
222
|
-
}
|
|
214
|
+
container.bubble ??= {};
|
|
223
215
|
container.bubble.clicking = true;
|
|
224
216
|
};
|
|
225
217
|
}
|
|
226
|
-
clear(particle,
|
|
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) =>
|
|
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
|
-
|
|
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
package/browser/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function loadExternalBubbleInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
10
|
-
constructor(
|
|
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
|
-
|
|
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 =
|
|
31
|
-
|
|
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:
|
|
40
|
+
optValue: getRangeMax(particle.options.size.value) * container.retina.pixelRatio,
|
|
46
41
|
value: particle.size.value,
|
|
47
42
|
},
|
|
48
|
-
type:
|
|
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:
|
|
52
|
+
optValue: getRangeMax(particle.options.opacity.value),
|
|
58
53
|
value: particle.opacity?.value ?? defaultOpacity,
|
|
59
54
|
},
|
|
60
|
-
type:
|
|
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 =
|
|
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 ===
|
|
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 ===
|
|
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 =
|
|
106
|
-
particle.bubble.finalColor =
|
|
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
|
-
?
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
152
|
-
container.bubble = {};
|
|
153
|
-
}
|
|
146
|
+
container.bubble ??= {};
|
|
154
147
|
if (container.bubble.durationEnd) {
|
|
155
148
|
if (pObjBubble) {
|
|
156
|
-
if (type ===
|
|
149
|
+
if (type === ProcessBubbleType.size) {
|
|
157
150
|
delete particle.bubble.radius;
|
|
158
151
|
}
|
|
159
|
-
if (type ===
|
|
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 ===
|
|
162
|
+
if (type === ProcessBubbleType.size) {
|
|
170
163
|
particle.bubble.radius = value;
|
|
171
164
|
}
|
|
172
|
-
if (type ===
|
|
165
|
+
if (type === ProcessBubbleType.opacity) {
|
|
173
166
|
particle.bubble.opacity = value;
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
169
|
}
|
|
177
170
|
else {
|
|
178
|
-
if (type ===
|
|
171
|
+
if (type === ProcessBubbleType.size) {
|
|
179
172
|
delete particle.bubble.radius;
|
|
180
173
|
}
|
|
181
|
-
if (type ===
|
|
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 =
|
|
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 ===
|
|
197
|
-
? new
|
|
198
|
-
: new
|
|
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 =
|
|
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
|
-
|
|
217
|
-
container.bubble = {};
|
|
218
|
-
}
|
|
209
|
+
container.bubble ??= {};
|
|
219
210
|
this.handleClickMode = (mode) => {
|
|
220
211
|
if (mode !== bubbleMode) {
|
|
221
212
|
return;
|
|
222
213
|
}
|
|
223
|
-
|
|
224
|
-
container.bubble = {};
|
|
225
|
-
}
|
|
214
|
+
container.bubble ??= {};
|
|
226
215
|
container.bubble.clicking = true;
|
|
227
216
|
};
|
|
228
217
|
}
|
|
229
|
-
clear(particle,
|
|
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 &&
|
|
239
|
+
if (hoverEnabled && isInArray(bubbleMode, hoverMode)) {
|
|
251
240
|
this._hoverBubble();
|
|
252
241
|
}
|
|
253
|
-
else if (clickEnabled &&
|
|
242
|
+
else if (clickEnabled && isInArray(bubbleMode, clickMode)) {
|
|
254
243
|
this._clickBubble();
|
|
255
244
|
}
|
|
256
245
|
else {
|
|
257
|
-
|
|
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 =
|
|
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
|
|
256
|
+
return isInArray(bubbleMode, onHover.mode) || isInArray(bubbleMode, onClick.mode) || divBubble;
|
|
266
257
|
}
|
|
267
258
|
loadModeOptions(options, ...sources) {
|
|
268
|
-
|
|
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
|
-
|
|
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 || (
|
|
6
|
+
})(ProcessBubbleType || (ProcessBubbleType = {}));
|
package/cjs/Interfaces.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 (
|
|
7
|
+
if (isNull(data)) {
|
|
11
8
|
return;
|
|
12
9
|
}
|
|
13
|
-
this.divs =
|
|
14
|
-
const tmp = new
|
|
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
|
-
|
|
2
|
-
|
|
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 (
|
|
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 =
|
|
29
|
-
this.color =
|
|
30
|
-
return
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 (
|
|
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
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/Types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/Utils.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
5
|
+
return clamp(value, particleValue, modeValue);
|
|
9
6
|
}
|
|
10
7
|
else if (modeValue < optionsValue) {
|
|
11
8
|
const value = particleValue - (optionsValue - modeValue) * ratio;
|
|
12
|
-
return
|
|
9
|
+
return clamp(value, modeValue, particleValue);
|
|
13
10
|
}
|
|
11
|
+
return undefined;
|
|
14
12
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.0");
|
|
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.0");
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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";
|