@tsparticles/interaction-external-bubble 3.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/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/Bubbler.js +294 -0
- package/browser/IBubblerProcessParam.js +1 -0
- package/browser/Options/Classes/Bubble.js +16 -0
- package/browser/Options/Classes/BubbleBase.js +34 -0
- package/browser/Options/Classes/BubbleDiv.js +26 -0
- package/browser/Options/Classes/BubbleOptions.js +1 -0
- package/browser/Options/Interfaces/IBubble.js +1 -0
- package/browser/Options/Interfaces/IBubbleBase.js +1 -0
- package/browser/Options/Interfaces/IBubbleDiv.js +1 -0
- package/browser/ProcessBubbleType.js +1 -0
- package/browser/Types.js +1 -0
- package/browser/index.js +10 -0
- package/cjs/Bubbler.js +309 -0
- package/cjs/IBubblerProcessParam.js +2 -0
- package/cjs/Options/Classes/Bubble.js +20 -0
- package/cjs/Options/Classes/BubbleBase.js +38 -0
- package/cjs/Options/Classes/BubbleDiv.js +30 -0
- package/cjs/Options/Classes/BubbleOptions.js +2 -0
- package/cjs/Options/Interfaces/IBubble.js +2 -0
- package/cjs/Options/Interfaces/IBubbleBase.js +2 -0
- package/cjs/Options/Interfaces/IBubbleDiv.js +2 -0
- package/cjs/ProcessBubbleType.js +2 -0
- package/cjs/Types.js +2 -0
- package/cjs/index.js +39 -0
- package/esm/Bubbler.js +294 -0
- package/esm/IBubblerProcessParam.js +1 -0
- package/esm/Options/Classes/Bubble.js +16 -0
- package/esm/Options/Classes/BubbleBase.js +34 -0
- package/esm/Options/Classes/BubbleDiv.js +26 -0
- package/esm/Options/Classes/BubbleOptions.js +1 -0
- package/esm/Options/Interfaces/IBubble.js +1 -0
- package/esm/Options/Interfaces/IBubbleBase.js +1 -0
- package/esm/Options/Interfaces/IBubbleDiv.js +1 -0
- package/esm/ProcessBubbleType.js +1 -0
- package/esm/Types.js +1 -0
- package/esm/index.js +10 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.interaction.external.bubble.js +520 -0
- package/tsparticles.interaction.external.bubble.min.js +2 -0
- package/tsparticles.interaction.external.bubble.min.js.LICENSE.txt +8 -0
- package/types/Bubbler.d.ts +20 -0
- package/types/IBubblerProcessParam.d.ts +10 -0
- package/types/Options/Classes/Bubble.d.ts +8 -0
- package/types/Options/Classes/BubbleBase.d.ts +13 -0
- package/types/Options/Classes/BubbleDiv.d.ts +10 -0
- package/types/Options/Classes/BubbleOptions.d.ts +7 -0
- package/types/Options/Interfaces/IBubble.d.ts +6 -0
- package/types/Options/Interfaces/IBubbleBase.d.ts +9 -0
- package/types/Options/Interfaces/IBubbleDiv.d.ts +4 -0
- package/types/ProcessBubbleType.d.ts +5 -0
- package/types/Types.d.ts +23 -0
- package/types/index.d.ts +8 -0
- package/umd/Bubbler.js +308 -0
- package/umd/IBubblerProcessParam.js +12 -0
- package/umd/Options/Classes/Bubble.js +30 -0
- package/umd/Options/Classes/BubbleBase.js +48 -0
- package/umd/Options/Classes/BubbleDiv.js +40 -0
- package/umd/Options/Classes/BubbleOptions.js +12 -0
- package/umd/Options/Interfaces/IBubble.js +12 -0
- package/umd/Options/Interfaces/IBubbleBase.js +12 -0
- package/umd/Options/Interfaces/IBubbleDiv.js +12 -0
- package/umd/ProcessBubbleType.js +12 -0
- package/umd/Types.js +12 -0
- package/umd/index.js +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles External Bubble Interaction
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-interaction-external-bubble)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-interaction-external-bubble)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-interaction-external-bubble) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for bubble effect around mouse or HTML
|
|
10
|
+
elements.
|
|
11
|
+
|
|
12
|
+
## How to use it
|
|
13
|
+
|
|
14
|
+
### CDN / Vanilla JS / jQuery
|
|
15
|
+
|
|
16
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
17
|
+
|
|
18
|
+
Including the `tsparticles.interaction.external.bubble.min.js` file will export the function to load the interaction
|
|
19
|
+
plugin:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
loadExternalBubbleInteraction;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Usage
|
|
26
|
+
|
|
27
|
+
Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
loadExternalBubbleInteraction(tsParticles);
|
|
31
|
+
|
|
32
|
+
tsParticles.load({
|
|
33
|
+
id: "tsparticles",
|
|
34
|
+
options: {
|
|
35
|
+
/* options */
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install tsparticles-interaction-external-bubble
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-interaction-external-bubble
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("tsparticles-engine");
|
|
58
|
+
const { loadExternalBubbleInteraction } = require("tsparticles-interaction-external-bubble");
|
|
59
|
+
|
|
60
|
+
loadExternalBubbleInteraction(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadExternalBubbleInteraction } from "tsparticles-interaction-external-bubble";
|
|
68
|
+
|
|
69
|
+
loadExternalBubbleInteraction(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { Circle, ExternalInteractorBase, Rectangle, clamp, colorMix, divMode, divModeExecute, getDistance, getRangeMax, isDivModeEnabled, isInArray, itemFromSingleOrMultiple, mouseLeaveEvent, mouseMoveEvent, rangeColorToHsl, rgbToHsl, } from "@tsparticles/engine";
|
|
2
|
+
import { Bubble } from "./Options/Classes/Bubble";
|
|
3
|
+
function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
|
|
4
|
+
if (modeValue >= optionsValue) {
|
|
5
|
+
const value = particleValue + (modeValue - optionsValue) * ratio;
|
|
6
|
+
return clamp(value, particleValue, modeValue);
|
|
7
|
+
}
|
|
8
|
+
else if (modeValue < optionsValue) {
|
|
9
|
+
const value = particleValue - (optionsValue - modeValue) * ratio;
|
|
10
|
+
return clamp(value, modeValue, particleValue);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class Bubbler extends ExternalInteractorBase {
|
|
14
|
+
constructor(container) {
|
|
15
|
+
super(container);
|
|
16
|
+
if (!container.bubble) {
|
|
17
|
+
container.bubble = {};
|
|
18
|
+
}
|
|
19
|
+
this.handleClickMode = (mode) => {
|
|
20
|
+
if (mode !== "bubble") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!container.bubble) {
|
|
24
|
+
container.bubble = {};
|
|
25
|
+
}
|
|
26
|
+
container.bubble.clicking = true;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
clear(particle, delta, force) {
|
|
30
|
+
if (particle.bubble.inRange && !force) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
delete particle.bubble.div;
|
|
34
|
+
delete particle.bubble.opacity;
|
|
35
|
+
delete particle.bubble.radius;
|
|
36
|
+
delete particle.bubble.color;
|
|
37
|
+
}
|
|
38
|
+
init() {
|
|
39
|
+
const container = this.container, bubble = container.actualOptions.interactivity.modes.bubble;
|
|
40
|
+
if (!bubble) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
container.retina.bubbleModeDistance = bubble.distance * container.retina.pixelRatio;
|
|
44
|
+
if (bubble.size !== undefined) {
|
|
45
|
+
container.retina.bubbleModeSize = bubble.size * container.retina.pixelRatio;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async interact(delta) {
|
|
49
|
+
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;
|
|
50
|
+
if (hoverEnabled && isInArray("bubble", hoverMode)) {
|
|
51
|
+
this.hoverBubble(delta);
|
|
52
|
+
}
|
|
53
|
+
else if (clickEnabled && isInArray("bubble", clickMode)) {
|
|
54
|
+
this.clickBubble(delta);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
divModeExecute("bubble", divs, (selector, div) => this.singleSelectorHover(delta, selector, div));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
isEnabled(particle) {
|
|
61
|
+
var _a;
|
|
62
|
+
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events, divs = events.onDiv, divBubble = isDivModeEnabled("bubble", divs);
|
|
63
|
+
if (!(divBubble || (events.onHover.enable && mouse.position) || (events.onClick.enable && mouse.clickPosition))) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const hoverMode = events.onHover.mode;
|
|
67
|
+
const clickMode = events.onClick.mode;
|
|
68
|
+
return isInArray("bubble", hoverMode) || isInArray("bubble", clickMode) || divBubble;
|
|
69
|
+
}
|
|
70
|
+
loadModeOptions(options, ...sources) {
|
|
71
|
+
if (!options.bubble) {
|
|
72
|
+
options.bubble = new Bubble();
|
|
73
|
+
}
|
|
74
|
+
for (const source of sources) {
|
|
75
|
+
options.bubble.load(source === null || source === void 0 ? void 0 : source.bubble);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
reset(particle) {
|
|
79
|
+
particle.bubble.inRange = false;
|
|
80
|
+
}
|
|
81
|
+
clickBubble(delta) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
const container = this.container, options = container.actualOptions, mouseClickPos = container.interactivity.mouse.clickPosition, bubble = options.interactivity.modes.bubble;
|
|
84
|
+
if (!bubble || !mouseClickPos) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!container.bubble) {
|
|
88
|
+
container.bubble = {};
|
|
89
|
+
}
|
|
90
|
+
const distance = container.retina.bubbleModeDistance;
|
|
91
|
+
if (!distance || distance < 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, (p) => this.isEnabled(p));
|
|
95
|
+
for (const particle of query) {
|
|
96
|
+
if (!container.bubble.clicking) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
particle.bubble.inRange = !container.bubble.durationEnd;
|
|
100
|
+
const pos = particle.getPosition(), distMouse = getDistance(pos, mouseClickPos), timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
|
|
101
|
+
if (timeSpent > bubble.duration) {
|
|
102
|
+
container.bubble.durationEnd = true;
|
|
103
|
+
}
|
|
104
|
+
if (timeSpent > bubble.duration * 2) {
|
|
105
|
+
container.bubble.clicking = false;
|
|
106
|
+
container.bubble.durationEnd = false;
|
|
107
|
+
}
|
|
108
|
+
const sizeData = {
|
|
109
|
+
bubbleObj: {
|
|
110
|
+
optValue: container.retina.bubbleModeSize,
|
|
111
|
+
value: particle.bubble.radius,
|
|
112
|
+
},
|
|
113
|
+
particlesObj: {
|
|
114
|
+
optValue: getRangeMax(particle.options.size.value) * container.retina.pixelRatio,
|
|
115
|
+
value: particle.size.value,
|
|
116
|
+
},
|
|
117
|
+
type: "size",
|
|
118
|
+
};
|
|
119
|
+
this.process(particle, distMouse, timeSpent, sizeData);
|
|
120
|
+
const opacityData = {
|
|
121
|
+
bubbleObj: {
|
|
122
|
+
optValue: bubble.opacity,
|
|
123
|
+
value: particle.bubble.opacity,
|
|
124
|
+
},
|
|
125
|
+
particlesObj: {
|
|
126
|
+
optValue: getRangeMax(particle.options.opacity.value),
|
|
127
|
+
value: (_b = (_a = particle.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1,
|
|
128
|
+
},
|
|
129
|
+
type: "opacity",
|
|
130
|
+
};
|
|
131
|
+
this.process(particle, distMouse, timeSpent, opacityData);
|
|
132
|
+
if (!container.bubble.durationEnd) {
|
|
133
|
+
if (distMouse <= distance) {
|
|
134
|
+
this.hoverBubbleColor(particle, distMouse);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
delete particle.bubble.color;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
delete particle.bubble.color;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
hoverBubble(delta) {
|
|
146
|
+
const container = this.container, mousePos = container.interactivity.mouse.position, distance = container.retina.bubbleModeDistance;
|
|
147
|
+
if (!distance || distance < 0 || mousePos === undefined) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
|
|
151
|
+
for (const particle of query) {
|
|
152
|
+
particle.bubble.inRange = true;
|
|
153
|
+
const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos), ratio = 1 - pointDistance / distance;
|
|
154
|
+
if (pointDistance <= distance) {
|
|
155
|
+
if (ratio >= 0 && container.interactivity.status === mouseMoveEvent) {
|
|
156
|
+
this.hoverBubbleSize(particle, ratio);
|
|
157
|
+
this.hoverBubbleOpacity(particle, ratio);
|
|
158
|
+
this.hoverBubbleColor(particle, ratio);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.reset(particle);
|
|
163
|
+
}
|
|
164
|
+
if (container.interactivity.status === mouseLeaveEvent) {
|
|
165
|
+
this.reset(particle);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
hoverBubbleColor(particle, ratio, divBubble) {
|
|
170
|
+
const options = this.container.actualOptions;
|
|
171
|
+
const bubbleOptions = divBubble !== null && divBubble !== void 0 ? divBubble : options.interactivity.modes.bubble;
|
|
172
|
+
if (!bubbleOptions) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!particle.bubble.finalColor) {
|
|
176
|
+
const modeColor = bubbleOptions.color;
|
|
177
|
+
if (!modeColor) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const bubbleColor = itemFromSingleOrMultiple(modeColor);
|
|
181
|
+
particle.bubble.finalColor = rangeColorToHsl(bubbleColor);
|
|
182
|
+
}
|
|
183
|
+
if (!particle.bubble.finalColor) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (bubbleOptions.mix) {
|
|
187
|
+
particle.bubble.color = undefined;
|
|
188
|
+
const pColor = particle.getFillColor();
|
|
189
|
+
particle.bubble.color = pColor
|
|
190
|
+
? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, 1 - ratio, ratio))
|
|
191
|
+
: particle.bubble.finalColor;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
particle.bubble.color = particle.bubble.finalColor;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
hoverBubbleOpacity(particle, ratio, divBubble) {
|
|
198
|
+
var _a, _b, _c, _d;
|
|
199
|
+
const container = this.container, options = container.actualOptions, modeOpacity = (_a = divBubble === null || divBubble === void 0 ? void 0 : divBubble.opacity) !== null && _a !== void 0 ? _a : (_b = options.interactivity.modes.bubble) === null || _b === void 0 ? void 0 : _b.opacity;
|
|
200
|
+
if (!modeOpacity) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const optOpacity = particle.options.opacity.value;
|
|
204
|
+
const pOpacity = (_d = (_c = particle.opacity) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 1;
|
|
205
|
+
const opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
|
|
206
|
+
if (opacity !== undefined) {
|
|
207
|
+
particle.bubble.opacity = opacity;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
hoverBubbleSize(particle, ratio, divBubble) {
|
|
211
|
+
const container = this.container, modeSize = (divBubble === null || divBubble === void 0 ? void 0 : divBubble.size) ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;
|
|
212
|
+
if (modeSize === undefined) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const optSize = getRangeMax(particle.options.size.value) * container.retina.pixelRatio;
|
|
216
|
+
const pSize = particle.size.value;
|
|
217
|
+
const size = calculateBubbleValue(pSize, modeSize, optSize, ratio);
|
|
218
|
+
if (size !== undefined) {
|
|
219
|
+
particle.bubble.radius = size;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
process(particle, distMouse, timeSpent, data) {
|
|
223
|
+
const container = this.container, bubbleParam = data.bubbleObj.optValue, options = container.actualOptions, bubble = options.interactivity.modes.bubble;
|
|
224
|
+
if (!bubble || bubbleParam === undefined) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const bubbleDuration = bubble.duration, bubbleDistance = container.retina.bubbleModeDistance, particlesParam = data.particlesObj.optValue, pObjBubble = data.bubbleObj.value, pObj = data.particlesObj.value || 0, type = data.type;
|
|
228
|
+
if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (!container.bubble) {
|
|
232
|
+
container.bubble = {};
|
|
233
|
+
}
|
|
234
|
+
if (!container.bubble.durationEnd) {
|
|
235
|
+
if (distMouse <= bubbleDistance) {
|
|
236
|
+
const obj = pObjBubble !== null && pObjBubble !== void 0 ? pObjBubble : pObj;
|
|
237
|
+
if (obj !== bubbleParam) {
|
|
238
|
+
const value = pObj - (timeSpent * (pObj - bubbleParam)) / bubbleDuration;
|
|
239
|
+
if (type === "size") {
|
|
240
|
+
particle.bubble.radius = value;
|
|
241
|
+
}
|
|
242
|
+
if (type === "opacity") {
|
|
243
|
+
particle.bubble.opacity = value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
if (type === "size") {
|
|
249
|
+
delete particle.bubble.radius;
|
|
250
|
+
}
|
|
251
|
+
if (type === "opacity") {
|
|
252
|
+
delete particle.bubble.opacity;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (pObjBubble) {
|
|
257
|
+
if (type === "size") {
|
|
258
|
+
delete particle.bubble.radius;
|
|
259
|
+
}
|
|
260
|
+
if (type === "opacity") {
|
|
261
|
+
delete particle.bubble.opacity;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
singleSelectorHover(delta, selector, div) {
|
|
266
|
+
const container = this.container, selectors = document.querySelectorAll(selector), bubble = container.actualOptions.interactivity.modes.bubble;
|
|
267
|
+
if (!bubble || !selectors.length) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
selectors.forEach((item) => {
|
|
271
|
+
const elem = item, pxRatio = container.retina.pixelRatio, pos = {
|
|
272
|
+
x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
|
273
|
+
y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
|
|
274
|
+
}, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
|
|
275
|
+
? new Circle(pos.x, pos.y, repulseRadius)
|
|
276
|
+
: new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
|
|
277
|
+
for (const particle of query) {
|
|
278
|
+
if (!area.contains(particle.getPosition())) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
particle.bubble.inRange = true;
|
|
282
|
+
const divs = bubble.divs;
|
|
283
|
+
const divBubble = divMode(divs, elem);
|
|
284
|
+
if (!particle.bubble.div || particle.bubble.div !== elem) {
|
|
285
|
+
this.clear(particle, delta, true);
|
|
286
|
+
particle.bubble.div = elem;
|
|
287
|
+
}
|
|
288
|
+
this.hoverBubbleSize(particle, 1, divBubble);
|
|
289
|
+
this.hoverBubbleOpacity(particle, 1, divBubble);
|
|
290
|
+
this.hoverBubbleColor(particle, 1, divBubble);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BubbleBase } from "./BubbleBase";
|
|
2
|
+
import { BubbleDiv } from "./BubbleDiv";
|
|
3
|
+
import { executeOnSingleOrMultiple } from "@tsparticles/engine";
|
|
4
|
+
export class Bubble extends BubbleBase {
|
|
5
|
+
load(data) {
|
|
6
|
+
super.load(data);
|
|
7
|
+
if (!data) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
this.divs = executeOnSingleOrMultiple(data.divs, (div) => {
|
|
11
|
+
const tmp = new BubbleDiv();
|
|
12
|
+
tmp.load(div);
|
|
13
|
+
return tmp;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OptionsColor, executeOnSingleOrMultiple } from "@tsparticles/engine";
|
|
2
|
+
export class BubbleBase {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.distance = 200;
|
|
5
|
+
this.duration = 0.4;
|
|
6
|
+
this.mix = false;
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.distance !== undefined) {
|
|
13
|
+
this.distance = data.distance;
|
|
14
|
+
}
|
|
15
|
+
if (data.duration !== undefined) {
|
|
16
|
+
this.duration = data.duration;
|
|
17
|
+
}
|
|
18
|
+
if (data.mix !== undefined) {
|
|
19
|
+
this.mix = data.mix;
|
|
20
|
+
}
|
|
21
|
+
if (data.opacity !== undefined) {
|
|
22
|
+
this.opacity = data.opacity;
|
|
23
|
+
}
|
|
24
|
+
if (data.color !== undefined) {
|
|
25
|
+
const sourceColor = this.color instanceof Array ? undefined : this.color;
|
|
26
|
+
this.color = executeOnSingleOrMultiple(data.color, (color) => {
|
|
27
|
+
return OptionsColor.create(sourceColor, color);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (data.size !== undefined) {
|
|
31
|
+
this.size = data.size;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BubbleBase } from "./BubbleBase";
|
|
2
|
+
import { executeOnSingleOrMultiple } from "@tsparticles/engine";
|
|
3
|
+
export class BubbleDiv extends BubbleBase {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.selectors = [];
|
|
7
|
+
}
|
|
8
|
+
get ids() {
|
|
9
|
+
return executeOnSingleOrMultiple(this.selectors, (t) => t.replace("#", ""));
|
|
10
|
+
}
|
|
11
|
+
set ids(value) {
|
|
12
|
+
this.selectors = executeOnSingleOrMultiple(value, (t) => `#${t}`);
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
super.load(data);
|
|
16
|
+
if (!data) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (data.ids !== undefined) {
|
|
20
|
+
this.ids = data.ids;
|
|
21
|
+
}
|
|
22
|
+
if (data.selectors !== undefined) {
|
|
23
|
+
this.selectors = data.selectors;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Bubbler } from "./Bubbler";
|
|
2
|
+
export async function loadExternalBubbleInteraction(engine) {
|
|
3
|
+
await engine.addInteractor("externalBubble", (container) => new Bubbler(container));
|
|
4
|
+
}
|
|
5
|
+
export * from "./Options/Classes/BubbleBase";
|
|
6
|
+
export * from "./Options/Classes/BubbleDiv";
|
|
7
|
+
export * from "./Options/Classes/Bubble";
|
|
8
|
+
export * from "./Options/Interfaces/IBubbleBase";
|
|
9
|
+
export * from "./Options/Interfaces/IBubbleDiv";
|
|
10
|
+
export * from "./Options/Interfaces/IBubble";
|