@tsparticles/interaction-particles-links 4.0.4 → 4.1.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/browser/CircleWarp.js +4 -4
- package/browser/LinkInstance.js +31 -31
- package/browser/Linker.js +12 -12
- package/browser/LinksPlugin.js +3 -3
- package/browser/index.js +1 -1
- package/browser/index.lazy.js +1 -1
- package/cjs/CircleWarp.js +4 -4
- package/cjs/LinkInstance.js +31 -31
- package/cjs/Linker.js +12 -12
- package/cjs/LinksPlugin.js +3 -3
- package/cjs/index.js +1 -1
- package/cjs/index.lazy.js +1 -1
- package/esm/CircleWarp.js +4 -4
- package/esm/LinkInstance.js +31 -31
- package/esm/Linker.js +12 -12
- package/esm/LinksPlugin.js +3 -3
- package/esm/index.js +1 -1
- package/esm/index.lazy.js +1 -1
- package/package.json +4 -4
- package/report.html +1 -1
- package/tsparticles.interaction.particles.links.js +52 -52
- package/tsparticles.interaction.particles.links.min.js +1 -1
- package/types/CircleWarp.d.ts +1 -1
- package/types/LinkInstance.d.ts +1 -8
- package/types/Linker.d.ts +1 -4
- package/types/LinksPlugin.d.ts +1 -1
package/browser/CircleWarp.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
2
2
|
export class CircleWarp extends Circle {
|
|
3
|
-
canvasSize;
|
|
3
|
+
#canvasSize;
|
|
4
4
|
constructor(x, y, radius, canvasSize) {
|
|
5
5
|
super(x, y, radius);
|
|
6
|
-
this
|
|
6
|
+
this.#canvasSize = canvasSize;
|
|
7
7
|
}
|
|
8
8
|
contains(point) {
|
|
9
9
|
if (super.contains(point))
|
|
10
10
|
return true;
|
|
11
|
-
const { width, height } = this
|
|
11
|
+
const { width, height } = this.#canvasSize, { x, y } = point;
|
|
12
12
|
return (super.contains({ x: x - width, y }) ||
|
|
13
13
|
super.contains({ x: x + width, y }) ||
|
|
14
14
|
super.contains({ x, y: y - height }) ||
|
|
@@ -21,7 +21,7 @@ export class CircleWarp extends Circle {
|
|
|
21
21
|
intersects(range) {
|
|
22
22
|
if (super.intersects(range))
|
|
23
23
|
return true;
|
|
24
|
-
const { width, height } = this
|
|
24
|
+
const { width, height } = this.#canvasSize, pos = range.position, shifts = [
|
|
25
25
|
{ x: -width, y: 0 },
|
|
26
26
|
{ x: width, y: 0 },
|
|
27
27
|
{ x: 0, y: -height },
|
package/browser/LinkInstance.js
CHANGED
|
@@ -2,14 +2,14 @@ import { getLinkColor as engineGetLinkColor, getRandom, getRangeValue, getStyleF
|
|
|
2
2
|
import { setLinkFrequency } from "./Utils.js";
|
|
3
3
|
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;
|
|
4
4
|
export class LinkInstance {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
#colorCache = new Map();
|
|
6
|
+
#container;
|
|
7
|
+
#freqs;
|
|
8
|
+
#pluginManager;
|
|
9
9
|
constructor(pluginManager, container) {
|
|
10
|
-
this
|
|
11
|
-
this
|
|
12
|
-
this
|
|
10
|
+
this.#pluginManager = pluginManager;
|
|
11
|
+
this.#container = container;
|
|
12
|
+
this.#freqs = { links: new Map(), triangles: new Map() };
|
|
13
13
|
}
|
|
14
14
|
drawParticle(context, particle) {
|
|
15
15
|
const { links, options } = particle;
|
|
@@ -26,13 +26,13 @@ export class LinkInstance {
|
|
|
26
26
|
};
|
|
27
27
|
for (const link of links) {
|
|
28
28
|
if (linkOpts.frequency < maxFrequency &&
|
|
29
|
-
this
|
|
29
|
+
this.#getLinkFrequency(particle, link.destination) > linkOpts.frequency) {
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
const pos2 = link.destination.getPosition();
|
|
33
33
|
if (trianglesEnabled && !link.isWarped && p1Destinations) {
|
|
34
34
|
flushLines();
|
|
35
|
-
this
|
|
35
|
+
this.#drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);
|
|
36
36
|
}
|
|
37
37
|
if (link.opacity <= minOpacity || width <= minWidth) {
|
|
38
38
|
continue;
|
|
@@ -42,7 +42,7 @@ export class LinkInstance {
|
|
|
42
42
|
}
|
|
43
43
|
let opacity = link.opacity, colorLine = link.color;
|
|
44
44
|
const twinkleRgb = twinkle?.enable && getRandom() < twinkle.frequency
|
|
45
|
-
? rangeColorToRgb(this
|
|
45
|
+
? rangeColorToRgb(this.#pluginManager, twinkle.color)
|
|
46
46
|
: undefined;
|
|
47
47
|
if (twinkle && twinkleRgb) {
|
|
48
48
|
colorLine = twinkleRgb;
|
|
@@ -50,14 +50,14 @@ export class LinkInstance {
|
|
|
50
50
|
}
|
|
51
51
|
if (!colorLine) {
|
|
52
52
|
const linkColor = linkOpts.id !== undefined
|
|
53
|
-
? this.
|
|
54
|
-
: this.
|
|
53
|
+
? this.#container.particles.linksColors.get(linkOpts.id)
|
|
54
|
+
: this.#container.particles.linksColor;
|
|
55
55
|
colorLine = engineGetLinkColor(particle, link.destination, linkColor);
|
|
56
56
|
}
|
|
57
57
|
if (!colorLine) {
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
|
-
const colorStyle = this
|
|
60
|
+
const colorStyle = this.#getCachedStyle(colorLine);
|
|
61
61
|
if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {
|
|
62
62
|
flushLines();
|
|
63
63
|
context.strokeStyle = colorStyle;
|
|
@@ -70,7 +70,7 @@ export class LinkInstance {
|
|
|
70
70
|
pathOpen = true;
|
|
71
71
|
}
|
|
72
72
|
if (link.isWarped) {
|
|
73
|
-
const canvasSize = this.
|
|
73
|
+
const canvasSize = this.#container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
74
74
|
let sx = originPoint.x, sy = originPoint.y;
|
|
75
75
|
if (Math.abs(dx) > canvasSize.width * half) {
|
|
76
76
|
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
@@ -92,9 +92,9 @@ export class LinkInstance {
|
|
|
92
92
|
context.globalAlpha = originalAlpha;
|
|
93
93
|
}
|
|
94
94
|
init() {
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
95
|
+
this.#freqs.links.clear();
|
|
96
|
+
this.#freqs.triangles.clear();
|
|
97
|
+
this.#colorCache.clear();
|
|
98
98
|
return Promise.resolve();
|
|
99
99
|
}
|
|
100
100
|
particleCreated(particle) {
|
|
@@ -104,14 +104,14 @@ export class LinkInstance {
|
|
|
104
104
|
}
|
|
105
105
|
particle.linksDistance = particle.options.links.distance;
|
|
106
106
|
particle.linksWidth = particle.options.links.width;
|
|
107
|
-
const ratio = this.
|
|
107
|
+
const ratio = this.#container.retina.pixelRatio;
|
|
108
108
|
particle.retina.linksDistance = particle.linksDistance * ratio;
|
|
109
109
|
particle.retina.linksWidth = particle.linksWidth * ratio;
|
|
110
110
|
}
|
|
111
111
|
particleDestroyed(particle) {
|
|
112
112
|
particle.links = [];
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
#drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {
|
|
115
115
|
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
116
116
|
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
117
117
|
return;
|
|
@@ -122,21 +122,21 @@ export class LinkInstance {
|
|
|
122
122
|
}
|
|
123
123
|
for (const vertex of p2Links) {
|
|
124
124
|
if (vertex.isWarped ||
|
|
125
|
-
this
|
|
125
|
+
this.#getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency ||
|
|
126
126
|
!p1Destinations.has(vertex.destination.id)) {
|
|
127
127
|
continue;
|
|
128
128
|
}
|
|
129
129
|
const p3 = vertex.destination;
|
|
130
|
-
if (this
|
|
130
|
+
if (this.#getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
131
131
|
continue;
|
|
132
132
|
}
|
|
133
|
-
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this
|
|
133
|
+
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this.#pluginManager, triangleOptions.color) ?? link.color;
|
|
134
134
|
if (!colorTriangle || opacityTriangle <= minOpacity) {
|
|
135
135
|
continue;
|
|
136
136
|
}
|
|
137
137
|
const pos3 = p3.getPosition();
|
|
138
138
|
context.save();
|
|
139
|
-
context.fillStyle = this
|
|
139
|
+
context.fillStyle = this.#getCachedStyle(colorTriangle);
|
|
140
140
|
context.globalAlpha = opacityTriangle;
|
|
141
141
|
context.beginPath();
|
|
142
142
|
context.moveTo(pos1.x, pos1.y);
|
|
@@ -147,19 +147,19 @@ export class LinkInstance {
|
|
|
147
147
|
context.restore();
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
#getCachedStyle(rgb) {
|
|
151
151
|
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
152
|
-
let style = this.
|
|
152
|
+
let style = this.#colorCache.get(key);
|
|
153
153
|
if (!style) {
|
|
154
|
-
style = getStyleFromRgb(rgb, this.
|
|
155
|
-
this.
|
|
154
|
+
style = getStyleFromRgb(rgb, this.#container.hdr);
|
|
155
|
+
this.#colorCache.set(key, style);
|
|
156
156
|
}
|
|
157
157
|
return style;
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
return setLinkFrequency([p1, p2], this.
|
|
159
|
+
#getLinkFrequency(p1, p2) {
|
|
160
|
+
return setLinkFrequency([p1, p2], this.#freqs.links);
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
return setLinkFrequency([p1, p2, p3], this.
|
|
162
|
+
#getTriangleFrequency(p1, p2, p3) {
|
|
163
|
+
return setLinkFrequency([p1, p2, p3], this.#freqs.triangles);
|
|
164
164
|
}
|
|
165
165
|
}
|
package/browser/Linker.js
CHANGED
|
@@ -11,15 +11,15 @@ function getWarpDistance(pos1, pos2, canvasSize) {
|
|
|
11
11
|
return Math.hypot(warpDistances.x, warpDistances.y);
|
|
12
12
|
}
|
|
13
13
|
export class Linker extends ParticlesInteractorBase {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
#maxDistance;
|
|
15
|
+
#pluginManager;
|
|
16
16
|
constructor(pluginManager, container) {
|
|
17
17
|
super(container);
|
|
18
|
-
this
|
|
19
|
-
this
|
|
18
|
+
this.#pluginManager = pluginManager;
|
|
19
|
+
this.#maxDistance = 0;
|
|
20
20
|
}
|
|
21
21
|
get maxDistance() {
|
|
22
|
-
return this
|
|
22
|
+
return this.#maxDistance;
|
|
23
23
|
}
|
|
24
24
|
clear() {
|
|
25
25
|
}
|
|
@@ -32,8 +32,8 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
p1.links = [];
|
|
35
|
-
if (p1.linksDistance && p1.linksDistance > this
|
|
36
|
-
this
|
|
35
|
+
if (p1.linksDistance && p1.linksDistance > this.#maxDistance) {
|
|
36
|
+
this.#maxDistance = p1.linksDistance;
|
|
37
37
|
}
|
|
38
38
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
39
39
|
if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
@@ -61,11 +61,11 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
61
61
|
continue;
|
|
62
62
|
}
|
|
63
63
|
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
64
|
-
this
|
|
64
|
+
this.#setColor(p1);
|
|
65
65
|
p1.links.push({
|
|
66
66
|
destination: p2,
|
|
67
67
|
opacity: opacityLine,
|
|
68
|
-
color: this
|
|
68
|
+
color: this.#getLinkColor(p1, p2),
|
|
69
69
|
isWarped: distWarp < distDirect,
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -81,7 +81,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
81
81
|
}
|
|
82
82
|
reset() {
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
#getLinkColor(p1, p2) {
|
|
85
85
|
const container = this.container, linksOptions = p1.options.links;
|
|
86
86
|
if (!linksOptions) {
|
|
87
87
|
return;
|
|
@@ -91,7 +91,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
91
91
|
: container.particles.linksColor;
|
|
92
92
|
return getLinkColor(p1, p2, linkColor);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
#setColor(p1) {
|
|
95
95
|
if (!p1.options.links) {
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
@@ -102,7 +102,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
102
102
|
if (linkColor) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
linkColor = getLinkRandomColor(this
|
|
105
|
+
linkColor = getLinkRandomColor(this.#pluginManager, linksOptions.color, linksOptions.blink, linksOptions.consent);
|
|
106
106
|
if (linksOptions.id === undefined) {
|
|
107
107
|
container.particles.linksColor = linkColor;
|
|
108
108
|
}
|
package/browser/LinksPlugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export class LinksPlugin {
|
|
2
2
|
id = "links";
|
|
3
|
-
|
|
3
|
+
#pluginManager;
|
|
4
4
|
constructor(pluginManager) {
|
|
5
|
-
this
|
|
5
|
+
this.#pluginManager = pluginManager;
|
|
6
6
|
}
|
|
7
7
|
async getPlugin(container) {
|
|
8
8
|
const { LinkInstance } = await import("./LinkInstance.js");
|
|
9
|
-
return new LinkInstance(this
|
|
9
|
+
return new LinkInstance(this.#pluginManager, container);
|
|
10
10
|
}
|
|
11
11
|
loadOptions() {
|
|
12
12
|
}
|
package/browser/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ensureInteractivityPluginLoaded } from "@tsparticles/plugin-interactivi
|
|
|
2
2
|
import { Linker } from "./Linker.js";
|
|
3
3
|
import { LinksPlugin } from "./LinksPlugin.js";
|
|
4
4
|
export async function loadParticlesLinksInteraction(engine) {
|
|
5
|
-
engine.checkVersion("4.0
|
|
5
|
+
engine.checkVersion("4.1.0");
|
|
6
6
|
await engine.pluginManager.register((e) => {
|
|
7
7
|
const pluginManager = e.pluginManager;
|
|
8
8
|
ensureInteractivityPluginLoaded(e);
|
package/browser/index.lazy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export async function loadParticlesLinksInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0
|
|
2
|
+
engine.checkVersion("4.1.0");
|
|
3
3
|
await engine.pluginManager.register(async (e) => {
|
|
4
4
|
const pluginManager = e.pluginManager, [{ ensureInteractivityPluginLoaded }, { LinksPlugin },] = await Promise.all([
|
|
5
5
|
import("@tsparticles/plugin-interactivity/lazy"),
|
package/cjs/CircleWarp.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
2
2
|
export class CircleWarp extends Circle {
|
|
3
|
-
canvasSize;
|
|
3
|
+
#canvasSize;
|
|
4
4
|
constructor(x, y, radius, canvasSize) {
|
|
5
5
|
super(x, y, radius);
|
|
6
|
-
this
|
|
6
|
+
this.#canvasSize = canvasSize;
|
|
7
7
|
}
|
|
8
8
|
contains(point) {
|
|
9
9
|
if (super.contains(point))
|
|
10
10
|
return true;
|
|
11
|
-
const { width, height } = this
|
|
11
|
+
const { width, height } = this.#canvasSize, { x, y } = point;
|
|
12
12
|
return (super.contains({ x: x - width, y }) ||
|
|
13
13
|
super.contains({ x: x + width, y }) ||
|
|
14
14
|
super.contains({ x, y: y - height }) ||
|
|
@@ -21,7 +21,7 @@ export class CircleWarp extends Circle {
|
|
|
21
21
|
intersects(range) {
|
|
22
22
|
if (super.intersects(range))
|
|
23
23
|
return true;
|
|
24
|
-
const { width, height } = this
|
|
24
|
+
const { width, height } = this.#canvasSize, pos = range.position, shifts = [
|
|
25
25
|
{ x: -width, y: 0 },
|
|
26
26
|
{ x: width, y: 0 },
|
|
27
27
|
{ x: 0, y: -height },
|
package/cjs/LinkInstance.js
CHANGED
|
@@ -2,14 +2,14 @@ import { getLinkColor as engineGetLinkColor, getRandom, getRangeValue, getStyleF
|
|
|
2
2
|
import { setLinkFrequency } from "./Utils.js";
|
|
3
3
|
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;
|
|
4
4
|
export class LinkInstance {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
#colorCache = new Map();
|
|
6
|
+
#container;
|
|
7
|
+
#freqs;
|
|
8
|
+
#pluginManager;
|
|
9
9
|
constructor(pluginManager, container) {
|
|
10
|
-
this
|
|
11
|
-
this
|
|
12
|
-
this
|
|
10
|
+
this.#pluginManager = pluginManager;
|
|
11
|
+
this.#container = container;
|
|
12
|
+
this.#freqs = { links: new Map(), triangles: new Map() };
|
|
13
13
|
}
|
|
14
14
|
drawParticle(context, particle) {
|
|
15
15
|
const { links, options } = particle;
|
|
@@ -26,13 +26,13 @@ export class LinkInstance {
|
|
|
26
26
|
};
|
|
27
27
|
for (const link of links) {
|
|
28
28
|
if (linkOpts.frequency < maxFrequency &&
|
|
29
|
-
this
|
|
29
|
+
this.#getLinkFrequency(particle, link.destination) > linkOpts.frequency) {
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
const pos2 = link.destination.getPosition();
|
|
33
33
|
if (trianglesEnabled && !link.isWarped && p1Destinations) {
|
|
34
34
|
flushLines();
|
|
35
|
-
this
|
|
35
|
+
this.#drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);
|
|
36
36
|
}
|
|
37
37
|
if (link.opacity <= minOpacity || width <= minWidth) {
|
|
38
38
|
continue;
|
|
@@ -42,7 +42,7 @@ export class LinkInstance {
|
|
|
42
42
|
}
|
|
43
43
|
let opacity = link.opacity, colorLine = link.color;
|
|
44
44
|
const twinkleRgb = twinkle?.enable && getRandom() < twinkle.frequency
|
|
45
|
-
? rangeColorToRgb(this
|
|
45
|
+
? rangeColorToRgb(this.#pluginManager, twinkle.color)
|
|
46
46
|
: undefined;
|
|
47
47
|
if (twinkle && twinkleRgb) {
|
|
48
48
|
colorLine = twinkleRgb;
|
|
@@ -50,14 +50,14 @@ export class LinkInstance {
|
|
|
50
50
|
}
|
|
51
51
|
if (!colorLine) {
|
|
52
52
|
const linkColor = linkOpts.id !== undefined
|
|
53
|
-
? this.
|
|
54
|
-
: this.
|
|
53
|
+
? this.#container.particles.linksColors.get(linkOpts.id)
|
|
54
|
+
: this.#container.particles.linksColor;
|
|
55
55
|
colorLine = engineGetLinkColor(particle, link.destination, linkColor);
|
|
56
56
|
}
|
|
57
57
|
if (!colorLine) {
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
|
-
const colorStyle = this
|
|
60
|
+
const colorStyle = this.#getCachedStyle(colorLine);
|
|
61
61
|
if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {
|
|
62
62
|
flushLines();
|
|
63
63
|
context.strokeStyle = colorStyle;
|
|
@@ -70,7 +70,7 @@ export class LinkInstance {
|
|
|
70
70
|
pathOpen = true;
|
|
71
71
|
}
|
|
72
72
|
if (link.isWarped) {
|
|
73
|
-
const canvasSize = this.
|
|
73
|
+
const canvasSize = this.#container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
74
74
|
let sx = originPoint.x, sy = originPoint.y;
|
|
75
75
|
if (Math.abs(dx) > canvasSize.width * half) {
|
|
76
76
|
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
@@ -92,9 +92,9 @@ export class LinkInstance {
|
|
|
92
92
|
context.globalAlpha = originalAlpha;
|
|
93
93
|
}
|
|
94
94
|
init() {
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
95
|
+
this.#freqs.links.clear();
|
|
96
|
+
this.#freqs.triangles.clear();
|
|
97
|
+
this.#colorCache.clear();
|
|
98
98
|
return Promise.resolve();
|
|
99
99
|
}
|
|
100
100
|
particleCreated(particle) {
|
|
@@ -104,14 +104,14 @@ export class LinkInstance {
|
|
|
104
104
|
}
|
|
105
105
|
particle.linksDistance = particle.options.links.distance;
|
|
106
106
|
particle.linksWidth = particle.options.links.width;
|
|
107
|
-
const ratio = this.
|
|
107
|
+
const ratio = this.#container.retina.pixelRatio;
|
|
108
108
|
particle.retina.linksDistance = particle.linksDistance * ratio;
|
|
109
109
|
particle.retina.linksWidth = particle.linksWidth * ratio;
|
|
110
110
|
}
|
|
111
111
|
particleDestroyed(particle) {
|
|
112
112
|
particle.links = [];
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
#drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {
|
|
115
115
|
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
116
116
|
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
117
117
|
return;
|
|
@@ -122,21 +122,21 @@ export class LinkInstance {
|
|
|
122
122
|
}
|
|
123
123
|
for (const vertex of p2Links) {
|
|
124
124
|
if (vertex.isWarped ||
|
|
125
|
-
this
|
|
125
|
+
this.#getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency ||
|
|
126
126
|
!p1Destinations.has(vertex.destination.id)) {
|
|
127
127
|
continue;
|
|
128
128
|
}
|
|
129
129
|
const p3 = vertex.destination;
|
|
130
|
-
if (this
|
|
130
|
+
if (this.#getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
131
131
|
continue;
|
|
132
132
|
}
|
|
133
|
-
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this
|
|
133
|
+
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this.#pluginManager, triangleOptions.color) ?? link.color;
|
|
134
134
|
if (!colorTriangle || opacityTriangle <= minOpacity) {
|
|
135
135
|
continue;
|
|
136
136
|
}
|
|
137
137
|
const pos3 = p3.getPosition();
|
|
138
138
|
context.save();
|
|
139
|
-
context.fillStyle = this
|
|
139
|
+
context.fillStyle = this.#getCachedStyle(colorTriangle);
|
|
140
140
|
context.globalAlpha = opacityTriangle;
|
|
141
141
|
context.beginPath();
|
|
142
142
|
context.moveTo(pos1.x, pos1.y);
|
|
@@ -147,19 +147,19 @@ export class LinkInstance {
|
|
|
147
147
|
context.restore();
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
#getCachedStyle(rgb) {
|
|
151
151
|
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
152
|
-
let style = this.
|
|
152
|
+
let style = this.#colorCache.get(key);
|
|
153
153
|
if (!style) {
|
|
154
|
-
style = getStyleFromRgb(rgb, this.
|
|
155
|
-
this.
|
|
154
|
+
style = getStyleFromRgb(rgb, this.#container.hdr);
|
|
155
|
+
this.#colorCache.set(key, style);
|
|
156
156
|
}
|
|
157
157
|
return style;
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
return setLinkFrequency([p1, p2], this.
|
|
159
|
+
#getLinkFrequency(p1, p2) {
|
|
160
|
+
return setLinkFrequency([p1, p2], this.#freqs.links);
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
return setLinkFrequency([p1, p2, p3], this.
|
|
162
|
+
#getTriangleFrequency(p1, p2, p3) {
|
|
163
|
+
return setLinkFrequency([p1, p2, p3], this.#freqs.triangles);
|
|
164
164
|
}
|
|
165
165
|
}
|
package/cjs/Linker.js
CHANGED
|
@@ -11,15 +11,15 @@ function getWarpDistance(pos1, pos2, canvasSize) {
|
|
|
11
11
|
return Math.hypot(warpDistances.x, warpDistances.y);
|
|
12
12
|
}
|
|
13
13
|
export class Linker extends ParticlesInteractorBase {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
#maxDistance;
|
|
15
|
+
#pluginManager;
|
|
16
16
|
constructor(pluginManager, container) {
|
|
17
17
|
super(container);
|
|
18
|
-
this
|
|
19
|
-
this
|
|
18
|
+
this.#pluginManager = pluginManager;
|
|
19
|
+
this.#maxDistance = 0;
|
|
20
20
|
}
|
|
21
21
|
get maxDistance() {
|
|
22
|
-
return this
|
|
22
|
+
return this.#maxDistance;
|
|
23
23
|
}
|
|
24
24
|
clear() {
|
|
25
25
|
}
|
|
@@ -32,8 +32,8 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
p1.links = [];
|
|
35
|
-
if (p1.linksDistance && p1.linksDistance > this
|
|
36
|
-
this
|
|
35
|
+
if (p1.linksDistance && p1.linksDistance > this.#maxDistance) {
|
|
36
|
+
this.#maxDistance = p1.linksDistance;
|
|
37
37
|
}
|
|
38
38
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
39
39
|
if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
@@ -61,11 +61,11 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
61
61
|
continue;
|
|
62
62
|
}
|
|
63
63
|
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
64
|
-
this
|
|
64
|
+
this.#setColor(p1);
|
|
65
65
|
p1.links.push({
|
|
66
66
|
destination: p2,
|
|
67
67
|
opacity: opacityLine,
|
|
68
|
-
color: this
|
|
68
|
+
color: this.#getLinkColor(p1, p2),
|
|
69
69
|
isWarped: distWarp < distDirect,
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -81,7 +81,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
81
81
|
}
|
|
82
82
|
reset() {
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
#getLinkColor(p1, p2) {
|
|
85
85
|
const container = this.container, linksOptions = p1.options.links;
|
|
86
86
|
if (!linksOptions) {
|
|
87
87
|
return;
|
|
@@ -91,7 +91,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
91
91
|
: container.particles.linksColor;
|
|
92
92
|
return getLinkColor(p1, p2, linkColor);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
#setColor(p1) {
|
|
95
95
|
if (!p1.options.links) {
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
@@ -102,7 +102,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
102
102
|
if (linkColor) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
linkColor = getLinkRandomColor(this
|
|
105
|
+
linkColor = getLinkRandomColor(this.#pluginManager, linksOptions.color, linksOptions.blink, linksOptions.consent);
|
|
106
106
|
if (linksOptions.id === undefined) {
|
|
107
107
|
container.particles.linksColor = linkColor;
|
|
108
108
|
}
|
package/cjs/LinksPlugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export class LinksPlugin {
|
|
2
2
|
id = "links";
|
|
3
|
-
|
|
3
|
+
#pluginManager;
|
|
4
4
|
constructor(pluginManager) {
|
|
5
|
-
this
|
|
5
|
+
this.#pluginManager = pluginManager;
|
|
6
6
|
}
|
|
7
7
|
async getPlugin(container) {
|
|
8
8
|
const { LinkInstance } = await import("./LinkInstance.js");
|
|
9
|
-
return new LinkInstance(this
|
|
9
|
+
return new LinkInstance(this.#pluginManager, container);
|
|
10
10
|
}
|
|
11
11
|
loadOptions() {
|
|
12
12
|
}
|
package/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ensureInteractivityPluginLoaded } from "@tsparticles/plugin-interactivi
|
|
|
2
2
|
import { Linker } from "./Linker.js";
|
|
3
3
|
import { LinksPlugin } from "./LinksPlugin.js";
|
|
4
4
|
export async function loadParticlesLinksInteraction(engine) {
|
|
5
|
-
engine.checkVersion("4.0
|
|
5
|
+
engine.checkVersion("4.1.0");
|
|
6
6
|
await engine.pluginManager.register((e) => {
|
|
7
7
|
const pluginManager = e.pluginManager;
|
|
8
8
|
ensureInteractivityPluginLoaded(e);
|
package/cjs/index.lazy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export async function loadParticlesLinksInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0
|
|
2
|
+
engine.checkVersion("4.1.0");
|
|
3
3
|
await engine.pluginManager.register(async (e) => {
|
|
4
4
|
const pluginManager = e.pluginManager, [{ ensureInteractivityPluginLoaded }, { LinksPlugin },] = await Promise.all([
|
|
5
5
|
import("@tsparticles/plugin-interactivity/lazy"),
|
package/esm/CircleWarp.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
2
2
|
export class CircleWarp extends Circle {
|
|
3
|
-
canvasSize;
|
|
3
|
+
#canvasSize;
|
|
4
4
|
constructor(x, y, radius, canvasSize) {
|
|
5
5
|
super(x, y, radius);
|
|
6
|
-
this
|
|
6
|
+
this.#canvasSize = canvasSize;
|
|
7
7
|
}
|
|
8
8
|
contains(point) {
|
|
9
9
|
if (super.contains(point))
|
|
10
10
|
return true;
|
|
11
|
-
const { width, height } = this
|
|
11
|
+
const { width, height } = this.#canvasSize, { x, y } = point;
|
|
12
12
|
return (super.contains({ x: x - width, y }) ||
|
|
13
13
|
super.contains({ x: x + width, y }) ||
|
|
14
14
|
super.contains({ x, y: y - height }) ||
|
|
@@ -21,7 +21,7 @@ export class CircleWarp extends Circle {
|
|
|
21
21
|
intersects(range) {
|
|
22
22
|
if (super.intersects(range))
|
|
23
23
|
return true;
|
|
24
|
-
const { width, height } = this
|
|
24
|
+
const { width, height } = this.#canvasSize, pos = range.position, shifts = [
|
|
25
25
|
{ x: -width, y: 0 },
|
|
26
26
|
{ x: width, y: 0 },
|
|
27
27
|
{ x: 0, y: -height },
|