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