@tsparticles/interaction-particles-links 4.0.0-alpha.5 → 4.0.0-beta.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/13.min.js +1 -0
- package/342.min.js +1 -0
- package/823.min.js +1 -0
- package/README.md +5 -0
- package/browser/CircleWarp.js +34 -18
- package/browser/LinkInstance.js +138 -131
- package/browser/Linker.js +49 -50
- package/browser/LinksPlugin.js +2 -1
- package/browser/Options/Classes/Links.js +12 -0
- package/browser/Options/Classes/LinksShadow.js +3 -0
- package/browser/Options/Classes/LinksTriangle.js +4 -0
- package/browser/Utils.js +2 -83
- package/browser/index.js +7 -4
- package/cjs/CircleWarp.js +34 -18
- package/cjs/LinkInstance.js +138 -131
- package/cjs/Linker.js +49 -50
- package/cjs/LinksPlugin.js +2 -1
- package/cjs/Options/Classes/Links.js +12 -0
- package/cjs/Options/Classes/LinksShadow.js +3 -0
- package/cjs/Options/Classes/LinksTriangle.js +4 -0
- package/cjs/Utils.js +2 -83
- package/cjs/index.js +7 -4
- package/dist_browser_LinkInstance_js.js +3 -3
- package/dist_browser_Linker_js.js +3 -3
- package/dist_browser_LinksPlugin_js.js +2 -2
- package/esm/CircleWarp.js +34 -18
- package/esm/LinkInstance.js +138 -131
- package/esm/Linker.js +49 -50
- package/esm/LinksPlugin.js +2 -1
- package/esm/Options/Classes/Links.js +12 -0
- package/esm/Options/Classes/LinksShadow.js +3 -0
- package/esm/Options/Classes/LinksTriangle.js +4 -0
- package/esm/Utils.js +2 -83
- package/esm/index.js +7 -4
- package/package.json +4 -3
- package/report.html +3 -3
- package/tsparticles.interaction.particles.links.js +45 -33
- package/tsparticles.interaction.particles.links.min.js +2 -2
- package/types/CircleWarp.d.ts +2 -2
- package/types/Interfaces.d.ts +4 -2
- package/types/LinkInstance.d.ts +6 -6
- package/types/Linker.d.ts +4 -1
- package/types/LinksPlugin.d.ts +1 -1
- package/types/Types.d.ts +11 -20
- package/types/Utils.d.ts +1 -5
- package/umd/CircleWarp.js +33 -17
- package/umd/LinkInstance.js +136 -129
- package/umd/Linker.js +48 -49
- package/umd/LinksPlugin.js +2 -1
- package/umd/Options/Classes/Links.js +12 -0
- package/umd/Options/Classes/LinksShadow.js +3 -0
- package/umd/Options/Classes/LinksTriangle.js +4 -0
- package/umd/Utils.js +1 -85
- package/umd/index.js +7 -4
- package/161.min.js +0 -2
- package/161.min.js.LICENSE.txt +0 -1
- package/29.min.js +0 -2
- package/29.min.js.LICENSE.txt +0 -1
- package/94.min.js +0 -2
- package/94.min.js.LICENSE.txt +0 -1
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +0 -1
package/umd/LinkInstance.js
CHANGED
|
@@ -12,159 +12,166 @@
|
|
|
12
12
|
exports.LinkInstance = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Utils_js_1 = require("./Utils.js");
|
|
15
|
-
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1;
|
|
15
|
+
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;
|
|
16
16
|
class LinkInstance {
|
|
17
|
+
_colorCache = new Map();
|
|
18
|
+
_container;
|
|
19
|
+
_engine;
|
|
20
|
+
_freqs;
|
|
17
21
|
constructor(container, engine) {
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
this._container = container;
|
|
23
|
+
this._engine = engine;
|
|
24
|
+
this._freqs = { links: new Map(), triangles: new Map() };
|
|
25
|
+
}
|
|
26
|
+
drawParticle(context, particle) {
|
|
27
|
+
const { links, options } = particle;
|
|
28
|
+
if (!links?.length || !options.links) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const linkOpts = options.links, width = particle.retina.linksWidth ?? minWidth, pos1 = particle.getPosition(), twinkle = particle.options["twinkle"]?.links, trianglesEnabled = linkOpts.triangles.enable, p1Destinations = trianglesEnabled ? new Set(links.map(l => l.destination.id)) : null, originalAlpha = context.globalAlpha;
|
|
32
|
+
let currentColorStyle = "", currentWidth = -1, currentAlpha = -1, pathOpen = false;
|
|
33
|
+
const flushLines = () => {
|
|
34
|
+
if (pathOpen) {
|
|
35
|
+
context.stroke();
|
|
36
|
+
pathOpen = false;
|
|
22
37
|
}
|
|
23
|
-
const container = this._container, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
24
|
-
let opacity = link.opacity;
|
|
25
|
-
container.canvas.draw(ctx => {
|
|
26
|
-
let colorLine;
|
|
27
|
-
const twinkle = p1.options["twinkle"]?.lines;
|
|
28
|
-
if (twinkle?.enable) {
|
|
29
|
-
const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(this._engine, twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
|
|
30
|
-
if (twinkling && twinkleRgb) {
|
|
31
|
-
colorLine = twinkleRgb;
|
|
32
|
-
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (!colorLine) {
|
|
36
|
-
const linkColor = p1LinksOptions.id !== undefined
|
|
37
|
-
? container.particles.linksColors.get(p1LinksOptions.id)
|
|
38
|
-
: container.particles.linksColor;
|
|
39
|
-
colorLine = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
40
|
-
}
|
|
41
|
-
if (!colorLine) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance;
|
|
45
|
-
(0, Utils_js_1.drawLinkLine)({
|
|
46
|
-
context: ctx,
|
|
47
|
-
width,
|
|
48
|
-
begin: pos1,
|
|
49
|
-
end: pos2,
|
|
50
|
-
engine: this._engine,
|
|
51
|
-
maxDistance,
|
|
52
|
-
canvasSize: container.canvas.size,
|
|
53
|
-
links: p1LinksOptions,
|
|
54
|
-
colorLine,
|
|
55
|
-
opacity,
|
|
56
|
-
hdr: container.hdr,
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
38
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
39
|
+
for (const link of links) {
|
|
40
|
+
if (linkOpts.frequency < maxFrequency &&
|
|
41
|
+
this._getLinkFrequency(particle, link.destination) > linkOpts.frequency) {
|
|
42
|
+
continue;
|
|
64
43
|
}
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
67
|
-
|
|
44
|
+
const pos2 = link.destination.getPosition();
|
|
45
|
+
if (trianglesEnabled && !link.isWarped && p1Destinations) {
|
|
46
|
+
flushLines();
|
|
47
|
+
this._drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);
|
|
68
48
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return;
|
|
49
|
+
if (link.opacity <= minOpacity || width <= minWidth) {
|
|
50
|
+
continue;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!colorTriangle) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
(0, Utils_js_1.drawLinkTriangle)({
|
|
91
|
-
context: ctx,
|
|
92
|
-
pos1,
|
|
93
|
-
pos2,
|
|
94
|
-
pos3,
|
|
95
|
-
colorTriangle,
|
|
96
|
-
opacityTriangle,
|
|
97
|
-
hdr: container.hdr,
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
this._drawTriangles = (options, p1, link, p1Links) => {
|
|
102
|
-
const p2 = link.destination;
|
|
103
|
-
if (!(options.links?.triangles.enable && p2.options.links?.triangles.enable)) {
|
|
104
|
-
return;
|
|
52
|
+
if (!linkOpts.enable) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
let opacity = link.opacity, colorLine = link.color;
|
|
56
|
+
const twinkleRgb = twinkle?.enable && (0, engine_1.getRandom)() < twinkle.frequency ? (0, engine_1.rangeColorToRgb)(this._engine, twinkle.color) : undefined;
|
|
57
|
+
if (twinkle && twinkleRgb) {
|
|
58
|
+
colorLine = twinkleRgb;
|
|
59
|
+
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
60
|
+
}
|
|
61
|
+
if (!colorLine) {
|
|
62
|
+
const linkColor = linkOpts.id !== undefined
|
|
63
|
+
? this._container.particles.linksColors.get(linkOpts.id)
|
|
64
|
+
: this._container.particles.linksColor;
|
|
65
|
+
colorLine = (0, engine_1.getLinkColor)(particle, link.destination, linkColor);
|
|
105
66
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return (p2.options.links &&
|
|
109
|
-
linkFreq <= p2.options.links.frequency &&
|
|
110
|
-
p1Links.findIndex(l => l.destination === t.destination) >= minCount);
|
|
111
|
-
});
|
|
112
|
-
if (!vertices?.length) {
|
|
113
|
-
return;
|
|
67
|
+
if (!colorLine) {
|
|
68
|
+
continue;
|
|
114
69
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
70
|
+
const colorStyle = this._getCachedStyle(colorLine);
|
|
71
|
+
if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {
|
|
72
|
+
flushLines();
|
|
73
|
+
context.strokeStyle = colorStyle;
|
|
74
|
+
context.lineWidth = width;
|
|
75
|
+
context.globalAlpha = opacity;
|
|
76
|
+
currentColorStyle = colorStyle;
|
|
77
|
+
currentWidth = width;
|
|
78
|
+
currentAlpha = opacity;
|
|
79
|
+
context.beginPath();
|
|
80
|
+
pathOpen = true;
|
|
81
|
+
}
|
|
82
|
+
if (link.isWarped) {
|
|
83
|
+
const canvasSize = this._container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
84
|
+
let sx = engine_1.originPoint.x, sy = engine_1.originPoint.y;
|
|
85
|
+
if (Math.abs(dx) > canvasSize.width * engine_1.half) {
|
|
86
|
+
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
87
|
+
}
|
|
88
|
+
if (Math.abs(dy) > canvasSize.height * engine_1.half) {
|
|
89
|
+
sy = dy > minDistance ? -canvasSize.height : canvasSize.height;
|
|
119
90
|
}
|
|
120
|
-
|
|
91
|
+
context.moveTo(pos1.x, pos1.y);
|
|
92
|
+
context.lineTo(pos2.x + sx, pos2.y + sy);
|
|
93
|
+
context.moveTo(pos1.x - sx, pos1.y - sy);
|
|
94
|
+
context.lineTo(pos2.x, pos2.y);
|
|
121
95
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
this._getTriangleFrequency = (p1, p2, p3) => {
|
|
127
|
-
return (0, Utils_js_1.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);
|
|
128
|
-
};
|
|
129
|
-
this._container = container;
|
|
130
|
-
this._engine = engine;
|
|
131
|
-
this._freqs = {
|
|
132
|
-
links: new Map(),
|
|
133
|
-
triangles: new Map(),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
drawParticle(_context, particle) {
|
|
137
|
-
const { links, options } = particle;
|
|
138
|
-
if (!links?.length) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const p1Links = links.filter(l => options.links &&
|
|
142
|
-
(options.links.frequency >= maxFrequency ||
|
|
143
|
-
this._getLinkFrequency(particle, l.destination) <= options.links.frequency));
|
|
144
|
-
for (const link of p1Links) {
|
|
145
|
-
this._drawTriangles(options, particle, link, p1Links);
|
|
146
|
-
if (link.opacity > minOpacity && (particle.retina.linksWidth ?? minWidth) > minWidth) {
|
|
147
|
-
this._drawLinkLine(particle, link);
|
|
96
|
+
else {
|
|
97
|
+
context.moveTo(pos1.x, pos1.y);
|
|
98
|
+
context.lineTo(pos2.x, pos2.y);
|
|
148
99
|
}
|
|
149
100
|
}
|
|
101
|
+
flushLines();
|
|
102
|
+
context.globalAlpha = originalAlpha;
|
|
150
103
|
}
|
|
151
|
-
|
|
152
|
-
this._freqs.links
|
|
153
|
-
this._freqs.triangles
|
|
154
|
-
|
|
104
|
+
init() {
|
|
105
|
+
this._freqs.links.clear();
|
|
106
|
+
this._freqs.triangles.clear();
|
|
107
|
+
this._colorCache.clear();
|
|
108
|
+
return Promise.resolve();
|
|
155
109
|
}
|
|
156
110
|
particleCreated(particle) {
|
|
157
111
|
particle.links = [];
|
|
158
112
|
if (!particle.options.links) {
|
|
159
113
|
return;
|
|
160
114
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
115
|
+
particle.linksDistance = particle.options.links.distance;
|
|
116
|
+
particle.linksWidth = particle.options.links.width;
|
|
117
|
+
const ratio = this._container.retina.pixelRatio;
|
|
118
|
+
particle.retina.linksDistance = particle.linksDistance * ratio;
|
|
119
|
+
particle.retina.linksWidth = particle.linksWidth * ratio;
|
|
164
120
|
}
|
|
165
121
|
particleDestroyed(particle) {
|
|
166
122
|
particle.links = [];
|
|
167
123
|
}
|
|
124
|
+
_drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {
|
|
125
|
+
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
126
|
+
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const p2Links = p2.links;
|
|
130
|
+
if (!p2Links?.length) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
for (const vertex of p2Links) {
|
|
134
|
+
if (vertex.isWarped ||
|
|
135
|
+
this._getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency ||
|
|
136
|
+
!p1Destinations.has(vertex.destination.id)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const p3 = vertex.destination;
|
|
140
|
+
if (this._getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * engine_1.half, colorTriangle = (0, engine_1.rangeColorToRgb)(this._engine, triangleOptions.color) ?? link.color;
|
|
144
|
+
if (!colorTriangle || opacityTriangle <= minOpacity) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const pos3 = p3.getPosition();
|
|
148
|
+
context.save();
|
|
149
|
+
context.fillStyle = this._getCachedStyle(colorTriangle);
|
|
150
|
+
context.globalAlpha = opacityTriangle;
|
|
151
|
+
context.beginPath();
|
|
152
|
+
context.moveTo(pos1.x, pos1.y);
|
|
153
|
+
context.lineTo(pos2.x, pos2.y);
|
|
154
|
+
context.lineTo(pos3.x, pos3.y);
|
|
155
|
+
context.closePath();
|
|
156
|
+
context.fill();
|
|
157
|
+
context.restore();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
_getCachedStyle(rgb) {
|
|
161
|
+
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
162
|
+
let style = this._colorCache.get(key);
|
|
163
|
+
if (!style) {
|
|
164
|
+
style = (0, engine_1.getStyleFromRgb)(rgb, this._container.hdr);
|
|
165
|
+
this._colorCache.set(key, style);
|
|
166
|
+
}
|
|
167
|
+
return style;
|
|
168
|
+
}
|
|
169
|
+
_getLinkFrequency(p1, p2) {
|
|
170
|
+
return (0, Utils_js_1.setLinkFrequency)([p1, p2], this._freqs.links);
|
|
171
|
+
}
|
|
172
|
+
_getTriangleFrequency(p1, p2, p3) {
|
|
173
|
+
return (0, Utils_js_1.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);
|
|
174
|
+
}
|
|
168
175
|
}
|
|
169
176
|
exports.LinkInstance = LinkInstance;
|
|
170
177
|
});
|
package/umd/Linker.js
CHANGED
|
@@ -14,45 +14,24 @@
|
|
|
14
14
|
const CircleWarp_js_1 = require("./CircleWarp.js");
|
|
15
15
|
const Links_js_1 = require("./Options/Classes/Links.js");
|
|
16
16
|
const plugin_interactivity_1 = require("@tsparticles/plugin-interactivity");
|
|
17
|
-
const
|
|
18
|
-
function
|
|
19
|
-
const { dx, dy
|
|
20
|
-
if (!warp || distance <= optDistance) {
|
|
21
|
-
return distance;
|
|
22
|
-
}
|
|
23
|
-
const absDiffs = {
|
|
24
|
-
x: Math.abs(dx),
|
|
25
|
-
y: Math.abs(dy),
|
|
26
|
-
}, warpDistances = {
|
|
17
|
+
const opacityOffset = 1, minDistance = 0;
|
|
18
|
+
function getWarpDistance(pos1, pos2, canvasSize) {
|
|
19
|
+
const { dx, dy } = (0, engine_1.getDistances)(pos1, pos2), absDiffs = { x: Math.abs(dx), y: Math.abs(dy) }, warpDistances = {
|
|
27
20
|
x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),
|
|
28
21
|
y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y),
|
|
29
22
|
};
|
|
30
|
-
return Math.
|
|
23
|
+
return Math.hypot(warpDistances.x, warpDistances.y);
|
|
31
24
|
}
|
|
32
25
|
class Linker extends plugin_interactivity_1.ParticlesInteractorBase {
|
|
26
|
+
_engine;
|
|
27
|
+
_maxDistance;
|
|
33
28
|
constructor(container, engine) {
|
|
34
29
|
super(container);
|
|
35
|
-
this._setColor = p1 => {
|
|
36
|
-
if (!p1.options.links) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const container = this.container, linksOptions = p1.options.links;
|
|
40
|
-
let linkColor = linksOptions.id === undefined
|
|
41
|
-
? container.particles.linksColor
|
|
42
|
-
: container.particles.linksColors.get(linksOptions.id);
|
|
43
|
-
if (linkColor) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const optColor = linksOptions.color;
|
|
47
|
-
linkColor = (0, engine_1.getLinkRandomColor)(this._engine, optColor, linksOptions.blink, linksOptions.consent);
|
|
48
|
-
if (linksOptions.id === undefined) {
|
|
49
|
-
container.particles.linksColor = linkColor;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
30
|
this._engine = engine;
|
|
31
|
+
this._maxDistance = 0;
|
|
32
|
+
}
|
|
33
|
+
get maxDistance() {
|
|
34
|
+
return this._maxDistance;
|
|
56
35
|
}
|
|
57
36
|
clear() {
|
|
58
37
|
}
|
|
@@ -65,22 +44,14 @@
|
|
|
65
44
|
return;
|
|
66
45
|
}
|
|
67
46
|
p1.links = [];
|
|
47
|
+
if (p1.linksDistance && p1.linksDistance > this._maxDistance) {
|
|
48
|
+
this._maxDistance = p1.linksDistance;
|
|
49
|
+
}
|
|
68
50
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
69
|
-
if (pos1.x < engine_1.originPoint.x ||
|
|
70
|
-
pos1.y < engine_1.originPoint.y ||
|
|
71
|
-
pos1.x > canvasSize.width ||
|
|
72
|
-
pos1.y > canvasSize.height) {
|
|
51
|
+
if (pos1.x < engine_1.originPoint.x || pos1.y < engine_1.originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
73
52
|
return;
|
|
74
53
|
}
|
|
75
|
-
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp;
|
|
76
|
-
let range;
|
|
77
|
-
if (warp) {
|
|
78
|
-
range = new CircleWarp_js_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
range = new engine_1.Circle(pos1.x, pos1.y, optDistance);
|
|
82
|
-
}
|
|
83
|
-
const query = container.particles.quadTree.query(range);
|
|
54
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp, range = warp ? new CircleWarp_js_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize) : new engine_1.Circle(pos1.x, pos1.y, optDistance), query = container.particles.grid.query(range);
|
|
84
55
|
for (const p2 of query) {
|
|
85
56
|
const linkOpt2 = p2.options.links;
|
|
86
57
|
if (p1 === p2 ||
|
|
@@ -94,13 +65,10 @@
|
|
|
94
65
|
continue;
|
|
95
66
|
}
|
|
96
67
|
const pos2 = p2.getPosition();
|
|
97
|
-
if (pos2.x < engine_1.originPoint.x ||
|
|
98
|
-
pos2.y < engine_1.originPoint.y ||
|
|
99
|
-
pos2.x > canvasSize.width ||
|
|
100
|
-
pos2.y > canvasSize.height) {
|
|
68
|
+
if (pos2.x < engine_1.originPoint.x || pos2.y < engine_1.originPoint.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
|
101
69
|
continue;
|
|
102
70
|
}
|
|
103
|
-
const
|
|
71
|
+
const distDirect = (0, engine_1.getDistances)(pos1, pos2).distance, distWarp = warp && linkOpt2.warp ? getWarpDistance(pos1, pos2, canvasSize) : distDirect, distance = Math.min(distDirect, distWarp);
|
|
104
72
|
if (distance > optDistance) {
|
|
105
73
|
continue;
|
|
106
74
|
}
|
|
@@ -109,6 +77,8 @@
|
|
|
109
77
|
p1.links.push({
|
|
110
78
|
destination: p2,
|
|
111
79
|
opacity: opacityLine,
|
|
80
|
+
color: this._getLinkColor(p1, p2),
|
|
81
|
+
isWarped: distWarp < distDirect,
|
|
112
82
|
});
|
|
113
83
|
}
|
|
114
84
|
}
|
|
@@ -123,6 +93,35 @@
|
|
|
123
93
|
}
|
|
124
94
|
reset() {
|
|
125
95
|
}
|
|
96
|
+
_getLinkColor(p1, p2) {
|
|
97
|
+
const container = this.container, linksOptions = p1.options.links;
|
|
98
|
+
if (!linksOptions) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const linkColor = linksOptions.id !== undefined
|
|
102
|
+
? container.particles.linksColors.get(linksOptions.id)
|
|
103
|
+
: container.particles.linksColor;
|
|
104
|
+
return (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
105
|
+
}
|
|
106
|
+
_setColor(p1) {
|
|
107
|
+
if (!p1.options.links) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const container = this.container, linksOptions = p1.options.links;
|
|
111
|
+
let linkColor = linksOptions.id === undefined
|
|
112
|
+
? container.particles.linksColor
|
|
113
|
+
: container.particles.linksColors.get(linksOptions.id);
|
|
114
|
+
if (linkColor) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
linkColor = (0, engine_1.getLinkRandomColor)(this._engine, linksOptions.color, linksOptions.blink, linksOptions.consent);
|
|
118
|
+
if (linksOptions.id === undefined) {
|
|
119
|
+
container.particles.linksColor = linkColor;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
126
125
|
}
|
|
127
126
|
exports.Linker = Linker;
|
|
128
127
|
});
|
package/umd/LinksPlugin.js
CHANGED
|
@@ -45,8 +45,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.LinksPlugin = void 0;
|
|
47
47
|
class LinksPlugin {
|
|
48
|
+
id = "links";
|
|
49
|
+
_engine;
|
|
48
50
|
constructor(engine) {
|
|
49
|
-
this.id = "links";
|
|
50
51
|
this._engine = engine;
|
|
51
52
|
}
|
|
52
53
|
async getPlugin(container) {
|
|
@@ -14,6 +14,18 @@
|
|
|
14
14
|
const LinksShadow_js_1 = require("./LinksShadow.js");
|
|
15
15
|
const LinksTriangle_js_1 = require("./LinksTriangle.js");
|
|
16
16
|
class Links {
|
|
17
|
+
blink;
|
|
18
|
+
color;
|
|
19
|
+
consent;
|
|
20
|
+
distance;
|
|
21
|
+
enable;
|
|
22
|
+
frequency;
|
|
23
|
+
id;
|
|
24
|
+
opacity;
|
|
25
|
+
shadow;
|
|
26
|
+
triangles;
|
|
27
|
+
warp;
|
|
28
|
+
width;
|
|
17
29
|
constructor() {
|
|
18
30
|
this.blink = false;
|
|
19
31
|
this.color = new engine_1.OptionsColor();
|
package/umd/Utils.js
CHANGED
|
@@ -9,95 +9,11 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.drawTriangle = drawTriangle;
|
|
13
|
-
exports.drawLinkLine = drawLinkLine;
|
|
14
|
-
exports.drawLinkTriangle = drawLinkTriangle;
|
|
15
12
|
exports.getLinkKey = getLinkKey;
|
|
16
13
|
exports.setLinkFrequency = setLinkFrequency;
|
|
17
14
|
const engine_1 = require("@tsparticles/engine");
|
|
18
|
-
function drawTriangle(context, p1, p2, p3) {
|
|
19
|
-
context.beginPath();
|
|
20
|
-
context.moveTo(p1.x, p1.y);
|
|
21
|
-
context.lineTo(p2.x, p2.y);
|
|
22
|
-
context.lineTo(p3.x, p3.y);
|
|
23
|
-
context.closePath();
|
|
24
|
-
}
|
|
25
|
-
function drawLinkLine(params) {
|
|
26
|
-
let drawn = false;
|
|
27
|
-
const { begin, end, engine, maxDistance, context, canvasSize, width, colorLine, opacity, links, hdr } = params;
|
|
28
|
-
if ((0, engine_1.getDistance)(begin, end) <= maxDistance) {
|
|
29
|
-
(0, engine_1.drawLine)(context, begin, end);
|
|
30
|
-
drawn = true;
|
|
31
|
-
}
|
|
32
|
-
else if (links.warp) {
|
|
33
|
-
let pi1;
|
|
34
|
-
let pi2;
|
|
35
|
-
const endNE = {
|
|
36
|
-
x: end.x - canvasSize.width,
|
|
37
|
-
y: end.y,
|
|
38
|
-
};
|
|
39
|
-
const d1 = (0, engine_1.getDistances)(begin, endNE);
|
|
40
|
-
if (d1.distance <= maxDistance) {
|
|
41
|
-
const yi = begin.y - (d1.dy / d1.dx) * begin.x;
|
|
42
|
-
pi1 = { x: 0, y: yi };
|
|
43
|
-
pi2 = { x: canvasSize.width, y: yi };
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const endSW = {
|
|
47
|
-
x: end.x,
|
|
48
|
-
y: end.y - canvasSize.height,
|
|
49
|
-
};
|
|
50
|
-
const d2 = (0, engine_1.getDistances)(begin, endSW);
|
|
51
|
-
if (d2.distance <= maxDistance) {
|
|
52
|
-
const yi = begin.y - (d2.dy / d2.dx) * begin.x;
|
|
53
|
-
const xi = -yi / (d2.dy / d2.dx);
|
|
54
|
-
pi1 = { x: xi, y: 0 };
|
|
55
|
-
pi2 = { x: xi, y: canvasSize.height };
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const endSE = {
|
|
59
|
-
x: end.x - canvasSize.width,
|
|
60
|
-
y: end.y - canvasSize.height,
|
|
61
|
-
};
|
|
62
|
-
const d3 = (0, engine_1.getDistances)(begin, endSE);
|
|
63
|
-
if (d3.distance <= maxDistance) {
|
|
64
|
-
const yi = begin.y - (d3.dy / d3.dx) * begin.x;
|
|
65
|
-
const xi = -yi / (d3.dy / d3.dx);
|
|
66
|
-
pi1 = { x: xi, y: yi };
|
|
67
|
-
pi2 = { x: pi1.x + canvasSize.width, y: pi1.y + canvasSize.height };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (pi1 && pi2) {
|
|
72
|
-
(0, engine_1.drawLine)(context, begin, pi1);
|
|
73
|
-
(0, engine_1.drawLine)(context, end, pi2);
|
|
74
|
-
drawn = true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (!drawn) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
context.lineWidth = width;
|
|
81
|
-
context.strokeStyle = (0, engine_1.getStyleFromRgb)(colorLine, hdr, opacity);
|
|
82
|
-
const { shadow } = links;
|
|
83
|
-
if (shadow.enable) {
|
|
84
|
-
const shadowColor = (0, engine_1.rangeColorToRgb)(engine, shadow.color);
|
|
85
|
-
if (shadowColor) {
|
|
86
|
-
context.shadowBlur = shadow.blur;
|
|
87
|
-
context.shadowColor = (0, engine_1.getStyleFromRgb)(shadowColor, hdr);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
context.stroke();
|
|
91
|
-
}
|
|
92
|
-
function drawLinkTriangle(params) {
|
|
93
|
-
const { context, hdr, pos1, pos2, pos3, colorTriangle, opacityTriangle } = params;
|
|
94
|
-
drawTriangle(context, pos1, pos2, pos3);
|
|
95
|
-
context.fillStyle = (0, engine_1.getStyleFromRgb)(colorTriangle, hdr, opacityTriangle);
|
|
96
|
-
context.fill();
|
|
97
|
-
}
|
|
98
15
|
function getLinkKey(ids) {
|
|
99
|
-
ids.sort((a, b) => a - b);
|
|
100
|
-
return ids.join("_");
|
|
16
|
+
return [...ids].sort((a, b) => a - b).join("_");
|
|
101
17
|
}
|
|
102
18
|
function setLinkFrequency(particles, dictionary) {
|
|
103
19
|
const key = getLinkKey(particles.map(t => t.id));
|
package/umd/index.js
CHANGED
|
@@ -48,14 +48,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.loadParticlesLinksInteraction = loadParticlesLinksInteraction;
|
|
50
50
|
async function loadParticlesLinksInteraction(engine) {
|
|
51
|
-
engine.checkVersion("4.0.0-
|
|
51
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
52
52
|
await engine.register(async (e) => {
|
|
53
|
-
const {
|
|
54
|
-
|
|
53
|
+
const [{ ensureInteractivityPluginLoaded }, { LinksPlugin },] = await Promise.all([
|
|
54
|
+
__syncRequire ? Promise.resolve().then(() => __importStar(require("@tsparticles/plugin-interactivity"))) : new Promise((resolve_1, reject_1) => { require(["@tsparticles/plugin-interactivity"], resolve_1, reject_1); }).then(__importStar),
|
|
55
|
+
__syncRequire ? Promise.resolve().then(() => __importStar(require("./LinksPlugin.js"))) : new Promise((resolve_2, reject_2) => { require(["./LinksPlugin.js"], resolve_2, reject_2); }).then(__importStar),
|
|
56
|
+
]);
|
|
57
|
+
ensureInteractivityPluginLoaded(e);
|
|
55
58
|
e.addPlugin(new LinksPlugin(e));
|
|
56
59
|
e.addInteractor?.("particlesLinks", async (container) => {
|
|
57
60
|
const { Linker } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Linker.js"))) : new Promise((resolve_3, reject_3) => { require(["./Linker.js"], resolve_3, reject_3); }).then(__importStar));
|
|
58
|
-
return new Linker(container,
|
|
61
|
+
return new Linker(container, e);
|
|
59
62
|
});
|
|
60
63
|
});
|
|
61
64
|
}
|
package/161.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 161.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[161],{161(n,i,t){t.d(i,{LinksPlugin:()=>s});class s{constructor(n){this.id="links",this._engine=n}async getPlugin(n){const{LinkInstance:i}=await t.e(29).then(t.bind(t,29));return new i(n,this._engine)}loadOptions(){}needsPlugin(){return!0}}}}]);
|
package/161.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Links Particles Interaction v4.0.0-alpha.5 by Matteo Bruni */
|
package/29.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 29.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[29],{29(i,n,t){t.d(n,{LinkInstance:()=>o});var e=t(303);function s(i,n){const t=((s=i.map((i=>i.id))).sort(((i,n)=>i-n)),s.join("_"));var s;let o=n.get(t);return void 0===o&&(o=(0,e.getRandom)(),n.set(t,o)),o}class o{constructor(i,n){this._drawLinkLine=(i,n)=>{const t=i.options.links;if(!t?.enable)return;const s=this._container,o=n.destination,a=i.getPosition(),r=o.getPosition();let l=n.opacity;s.canvas.draw((n=>{let c;const d=i.options.twinkle?.lines;if(d?.enable){const i=d.frequency,n=(0,e.rangeColorToRgb)(this._engine,d.color);(0,e.getRandom)()<i&&n&&(c=n,l=(0,e.getRangeValue)(d.opacity))}if(!c){const n=void 0!==t.id?s.particles.linksColors.get(t.id):s.particles.linksColor;c=(0,e.getLinkColor)(i,o,n)}if(!c)return;const g=i.retina.linksWidth??0,h=i.retina.linksDistance??0;!function(i){let n=!1;const{begin:t,end:s,engine:o,maxDistance:a,context:r,canvasSize:l,width:c,colorLine:d,opacity:g,links:h,hdr:y}=i;if((0,e.getDistance)(t,s)<=a)(0,e.drawLine)(r,t,s),n=!0;else if(h.warp){let i,o;const c={x:s.x-l.width,y:s.y},d=(0,e.getDistances)(t,c);if(d.distance<=a){const n=t.y-d.dy/d.dx*t.x;i={x:0,y:n},o={x:l.width,y:n}}else{const n={x:s.x,y:s.y-l.height},r=(0,e.getDistances)(t,n);if(r.distance<=a){const n=-(t.y-r.dy/r.dx*t.x)/(r.dy/r.dx);i={x:n,y:0},o={x:n,y:l.height}}else{const n={x:s.x-l.width,y:s.y-l.height},r=(0,e.getDistances)(t,n);if(r.distance<=a){const n=t.y-r.dy/r.dx*t.x;i={x:-n/(r.dy/r.dx),y:n},o={x:i.x+l.width,y:i.y+l.height}}}}i&&o&&((0,e.drawLine)(r,t,i),(0,e.drawLine)(r,s,o),n=!0)}if(!n)return;r.lineWidth=c,r.strokeStyle=(0,e.getStyleFromRgb)(d,y,g);const{shadow:k}=h;if(k.enable){const i=(0,e.rangeColorToRgb)(o,k.color);i&&(r.shadowBlur=k.blur,r.shadowColor=(0,e.getStyleFromRgb)(i,y))}r.stroke()}({context:n,width:g,begin:a,end:r,engine:this._engine,maxDistance:h,canvasSize:s.canvas.size,links:t,colorLine:c,opacity:l,hdr:s.hdr})}))},this._drawLinkTriangle=(i,n,t)=>{const s=i.options.links;if(!s?.enable)return;const o=s.triangles;if(!o.enable)return;const a=this._container,r=n.destination,l=t.destination,c=o.opacity??(n.opacity+t.opacity)*e.half;c<=0||a.canvas.draw((n=>{const t=i.getPosition(),d=r.getPosition(),g=l.getPosition(),h=i.retina.linksDistance??0;if((0,e.getDistance)(t,d)>h||(0,e.getDistance)(g,d)>h||(0,e.getDistance)(g,t)>h)return;let y=(0,e.rangeColorToRgb)(this._engine,o.color);if(!y){const n=void 0!==s.id?a.particles.linksColors.get(s.id):a.particles.linksColor;y=(0,e.getLinkColor)(i,r,n)}y&&function(i){const{context:n,hdr:t,pos1:s,pos2:o,pos3:a,colorTriangle:r,opacityTriangle:l}=i;!function(i,n,t,e){i.beginPath(),i.moveTo(n.x,n.y),i.lineTo(t.x,t.y),i.lineTo(e.x,e.y),i.closePath()}(n,s,o,a),n.fillStyle=(0,e.getStyleFromRgb)(r,t,l),n.fill()}({context:n,pos1:t,pos2:d,pos3:g,colorTriangle:y,opacityTriangle:c,hdr:a.hdr})}))},this._drawTriangles=(i,n,t,e)=>{const s=t.destination;if(!i.links?.triangles.enable||!s.options.links?.triangles.enable)return;const o=s.links?.filter((i=>{const n=this._getLinkFrequency(s,i.destination);return s.options.links&&n<=s.options.links.frequency&&e.findIndex((n=>n.destination===i.destination))>=0}));if(o?.length)for(const e of o){const o=e.destination;this._getTriangleFrequency(n,s,o)>i.links.triangles.frequency||this._drawLinkTriangle(n,t,e)}},this._getLinkFrequency=(i,n)=>s([i,n],this._freqs.links),this._getTriangleFrequency=(i,n,t)=>s([i,n,t],this._freqs.triangles),this._container=i,this._engine=n,this._freqs={links:new Map,triangles:new Map}}drawParticle(i,n){const{links:t,options:e}=n;if(!t?.length)return;const s=t.filter((i=>e.links&&(e.links.frequency>=1||this._getLinkFrequency(n,i.destination)<=e.links.frequency)));for(const i of s)this._drawTriangles(e,n,i,s),i.opacity>0&&(n.retina.linksWidth??0)>0&&this._drawLinkLine(n,i)}async init(){this._freqs.links=new Map,this._freqs.triangles=new Map,await Promise.resolve()}particleCreated(i){if(i.links=[],!i.options.links)return;const n=this._container.retina.pixelRatio,{retina:t}=i,{distance:e,width:s}=i.options.links;t.linksDistance=e*n,t.linksWidth=s*n}particleDestroyed(i){i.links=[]}}}}]);
|
package/29.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Links Particles Interaction v4.0.0-alpha.5 by Matteo Bruni */
|
package/94.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 94.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[94],{94(i,n,t){t.d(n,{Linker:()=>a});var s=t(303);class e extends s.Circle{constructor(i,n,t,s){super(i,n,t),this.canvasSize=s,this.canvasSize={...s}}contains(i){const{width:n,height:t}=this.canvasSize,{x:s,y:e}=i;return super.contains(i)||super.contains({x:s-n,y:e})||super.contains({x:s-n,y:e-t})||super.contains({x:s,y:e-t})}intersects(i){if(super.intersects(i))return!0;const n=i,t=i,e={x:i.position.x-this.canvasSize.width,y:i.position.y-this.canvasSize.height};if(Object.hasOwn(t,"radius")){const i=new s.Circle(e.x,e.y,t.radius*s.double);return super.intersects(i)}if(Object.hasOwn(n,"size")){const i=new s.Rectangle(e.x,e.y,n.size.width*s.double,n.size.height*s.double);return super.intersects(i)}return!1}}var o=t(880),r=t(702);function c(i,n,t,e,o){const{dx:r,dy:c,distance:a}=(0,s.getDistances)(i,n);if(!o||a<=t)return a;const l={x:Math.abs(r),y:Math.abs(c)},h=Math.min(l.x,e.width-l.x),p=Math.min(l.y,e.height-l.y);return Math.sqrt(h**2+p**2)}class a extends r.ParticlesInteractorBase{constructor(i,n){super(i),this._setColor=i=>{if(!i.options.links)return;const n=this.container,t=i.options.links;let e=void 0===t.id?n.particles.linksColor:n.particles.linksColors.get(t.id);if(e)return;const o=t.color;e=(0,s.getLinkRandomColor)(this._engine,o,t.blink,t.consent),void 0===t.id?n.particles.linksColor=e:n.particles.linksColors.set(t.id,e)},this._engine=n}clear(){}init(){this.container.particles.linksColor=void 0,this.container.particles.linksColors=new Map}interact(i){if(!i.options.links)return;i.links=[];const n=i.getPosition(),t=this.container,o=t.canvas.size;if(n.x<s.originPoint.x||n.y<s.originPoint.y||n.x>o.width||n.y>o.height)return;const r=i.options.links,a=r.opacity,l=i.retina.linksDistance??0,h=r.warp;let p;p=h?new e(n.x,n.y,l,o):new s.Circle(n.x,n.y,l);const u=t.particles.quadTree.query(p);for(const t of u){const e=t.options.links;if(i===t||!e?.enable||r.id!==e.id||t.spawning||t.destroyed||!t.links||i.links.some((i=>i.destination===t))||t.links.some((n=>n.destination===i)))continue;const p=t.getPosition();if(p.x<s.originPoint.x||p.y<s.originPoint.y||p.x>o.width||p.y>o.height)continue;const u=c(n,p,l,o,h&&e.warp);if(u>l)continue;const d=(1-u/l)*a;this._setColor(i),i.links.push({destination:t,opacity:d})}}isEnabled(i){return!!i.options.links?.enable}loadParticlesOptions(i,...n){i.links??=new o.q;for(const t of n)i.links.load(t?.links)}reset(){}}}}]);
|
package/94.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Links Particles Interaction v4.0.0-alpha.5 by Matteo Bruni */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Links Particles Interaction v4.0.0-alpha.5 by Matteo Bruni */
|