@tsparticles/interaction-particles-links 3.0.3 → 3.2.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/356.min.js +2 -0
- package/356.min.js.LICENSE.txt +1 -0
- package/806.min.js +2 -0
- package/806.min.js.LICENSE.txt +1 -0
- package/838.min.js +2 -0
- package/838.min.js.LICENSE.txt +1 -0
- package/browser/CircleWarp.js +3 -2
- package/browser/LinkInstance.js +12 -9
- package/browser/Linker.js +18 -8
- package/browser/interaction.js +4 -2
- package/browser/plugin.js +2 -2
- package/cjs/CircleWarp.js +3 -2
- package/cjs/LinkInstance.js +12 -9
- package/cjs/Linker.js +41 -8
- package/cjs/interaction.js +27 -2
- package/cjs/plugin.js +26 -3
- package/dist_browser_CircleWarp_js.js +30 -0
- package/dist_browser_LinkInstance_js.js +40 -0
- package/dist_browser_Linker_js.js +30 -0
- package/esm/CircleWarp.js +3 -2
- package/esm/LinkInstance.js +12 -9
- package/esm/Linker.js +18 -8
- package/esm/interaction.js +4 -2
- package/esm/plugin.js +2 -2
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.interaction.particles.links.js +291 -620
- package/tsparticles.interaction.particles.links.min.js +1 -1
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +1 -1
- package/types/LinkInstance.d.ts +1 -1
- package/types/Types.d.ts +4 -4
- package/umd/CircleWarp.js +3 -2
- package/umd/LinkInstance.js +12 -9
- package/umd/Linker.js +43 -9
- package/umd/interaction.js +29 -3
- package/umd/plugin.js +28 -4
package/esm/LinkInstance.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getDistance, getLinkColor, getRandom, getRangeValue, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
2
|
import { drawLinkLine, drawLinkTriangle, setLinkFrequency } from "./Utils.js";
|
|
3
|
+
const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5;
|
|
3
4
|
export class LinkInstance {
|
|
4
5
|
constructor(container) {
|
|
5
6
|
this.container = container;
|
|
@@ -29,7 +30,7 @@ export class LinkInstance {
|
|
|
29
30
|
if (!colorLine) {
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
const width = p1.retina.linksWidth ??
|
|
33
|
+
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance, { backgroundMask } = options;
|
|
33
34
|
drawLinkLine({
|
|
34
35
|
context: ctx,
|
|
35
36
|
width,
|
|
@@ -53,12 +54,12 @@ export class LinkInstance {
|
|
|
53
54
|
if (!triangleOptions.enable) {
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
|
-
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity)
|
|
57
|
-
if (opacityTriangle <=
|
|
57
|
+
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
|
|
58
|
+
if (opacityTriangle <= minOpacity) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
container.canvas.draw((ctx) => {
|
|
61
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ??
|
|
62
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? minDistance;
|
|
62
63
|
if (getDistance(pos1, pos2) > linksDistance ||
|
|
63
64
|
getDistance(pos3, pos2) > linksDistance ||
|
|
64
65
|
getDistance(pos3, pos1) > linksDistance) {
|
|
@@ -91,10 +92,10 @@ export class LinkInstance {
|
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
94
|
const vertices = p2.links?.filter((t) => {
|
|
94
|
-
const linkFreq = this._getLinkFrequency(p2, t.destination);
|
|
95
|
+
const linkFreq = this._getLinkFrequency(p2, t.destination), minCount = 0;
|
|
95
96
|
return (p2.options.links &&
|
|
96
97
|
linkFreq <= p2.options.links.frequency &&
|
|
97
|
-
p1Links.findIndex((l) => l.destination === t.destination) >=
|
|
98
|
+
p1Links.findIndex((l) => l.destination === t.destination) >= minCount);
|
|
98
99
|
});
|
|
99
100
|
if (!vertices?.length) {
|
|
100
101
|
return;
|
|
@@ -118,22 +119,24 @@ export class LinkInstance {
|
|
|
118
119
|
triangles: new Map(),
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
drawParticle(context, particle) {
|
|
122
|
+
async drawParticle(context, particle) {
|
|
122
123
|
const { links, options } = particle;
|
|
123
|
-
if (!links
|
|
124
|
+
if (!links?.length) {
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
126
127
|
const p1Links = links.filter((l) => options.links && this._getLinkFrequency(particle, l.destination) <= options.links.frequency);
|
|
127
128
|
for (const link of p1Links) {
|
|
128
129
|
this._drawTriangles(options, particle, link, p1Links);
|
|
129
|
-
if (link.opacity >
|
|
130
|
+
if (link.opacity > minOpacity && (particle.retina.linksWidth ?? minWidth) > minWidth) {
|
|
130
131
|
this._drawLinkLine(particle, link);
|
|
131
132
|
}
|
|
132
133
|
}
|
|
134
|
+
await Promise.resolve();
|
|
133
135
|
}
|
|
134
136
|
async init() {
|
|
135
137
|
this._freqs.links = new Map();
|
|
136
138
|
this._freqs.triangles = new Map();
|
|
139
|
+
await Promise.resolve();
|
|
137
140
|
}
|
|
138
141
|
particleCreated(particle) {
|
|
139
142
|
particle.links = [];
|
package/esm/Linker.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Circle, ParticlesInteractorBase, getDistances, getLinkRandomColor, } from "@tsparticles/engine";
|
|
2
|
-
import { CircleWarp } from "./CircleWarp.js";
|
|
3
2
|
import { Links } from "./Options/Classes/Links.js";
|
|
3
|
+
const squarePower = 2, opacityOffset = 1, origin = {
|
|
4
|
+
x: 0,
|
|
5
|
+
y: 0,
|
|
6
|
+
}, minDistance = 0;
|
|
4
7
|
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
5
8
|
const { dx, dy, distance } = getDistances(pos1, pos2);
|
|
6
9
|
if (!warp || distance <= optDistance) {
|
|
@@ -13,7 +16,7 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
|
13
16
|
x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),
|
|
14
17
|
y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y),
|
|
15
18
|
};
|
|
16
|
-
return Math.sqrt(warpDistances.x **
|
|
19
|
+
return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
|
|
17
20
|
}
|
|
18
21
|
export class Linker extends ParticlesInteractorBase {
|
|
19
22
|
constructor(container) {
|
|
@@ -52,12 +55,19 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
52
55
|
}
|
|
53
56
|
p1.links = [];
|
|
54
57
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
55
|
-
if (pos1.x <
|
|
58
|
+
if (pos1.x < origin.x || pos1.y < origin.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
|
-
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ??
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp;
|
|
62
|
+
let range;
|
|
63
|
+
if (warp) {
|
|
64
|
+
const { CircleWarp } = await import("./CircleWarp.js");
|
|
65
|
+
range = new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
range = new Circle(pos1.x, pos1.y, optDistance);
|
|
69
|
+
}
|
|
70
|
+
const query = container.particles.quadTree.query(range);
|
|
61
71
|
for (const p2 of query) {
|
|
62
72
|
const linkOpt2 = p2.options.links;
|
|
63
73
|
if (p1 === p2 ||
|
|
@@ -71,14 +81,14 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
71
81
|
continue;
|
|
72
82
|
}
|
|
73
83
|
const pos2 = p2.getPosition();
|
|
74
|
-
if (pos2.x <
|
|
84
|
+
if (pos2.x < origin.x || pos2.y < origin.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
|
75
85
|
continue;
|
|
76
86
|
}
|
|
77
87
|
const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
|
78
88
|
if (distance > optDistance) {
|
|
79
89
|
continue;
|
|
80
90
|
}
|
|
81
|
-
const opacityLine = (
|
|
91
|
+
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
82
92
|
this._setColor(p1);
|
|
83
93
|
p1.links.push({
|
|
84
94
|
destination: p2,
|
package/esm/interaction.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Linker } from "./Linker.js";
|
|
2
1
|
export async function loadLinksInteraction(engine, refresh = true) {
|
|
3
|
-
await engine.addInteractor("particlesLinks", (container) =>
|
|
2
|
+
await engine.addInteractor("particlesLinks", async (container) => {
|
|
3
|
+
const { Linker } = await import("./Linker.js");
|
|
4
|
+
return new Linker(container);
|
|
5
|
+
}, refresh);
|
|
4
6
|
}
|
package/esm/plugin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { LinkInstance } from "./LinkInstance.js";
|
|
2
1
|
class LinksPlugin {
|
|
3
2
|
constructor() {
|
|
4
3
|
this.id = "links";
|
|
5
4
|
}
|
|
6
|
-
getPlugin(container) {
|
|
5
|
+
async getPlugin(container) {
|
|
6
|
+
const { LinkInstance } = await import("./LinkInstance.js");
|
|
7
7
|
return new LinkInstance(container);
|
|
8
8
|
}
|
|
9
9
|
loadOptions() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-particles-links",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "tsParticles links particles interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "^3.0
|
|
90
|
+
"@tsparticles/engine": "^3.2.0"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
package/report.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8"/>
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
6
|
-
<title>@tsparticles/interaction-particles-links [
|
|
6
|
+
<title>@tsparticles/interaction-particles-links [31 Jan 2024 at 02:05]</title>
|
|
7
7
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2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fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
|
|
8
8
|
|
|
9
9
|
<script>
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
<body>
|
|
32
32
|
<div id="app"></div>
|
|
33
33
|
<script>
|
|
34
|
-
window.chartData = [
|
|
35
|
-
window.entrypoints = ["tsparticles.interaction.particles.links
|
|
34
|
+
window.chartData = [];
|
|
35
|
+
window.entrypoints = ["tsparticles.interaction.particles.links.min"];
|
|
36
36
|
window.defaultSizes = "parsed";
|
|
37
37
|
</script>
|
|
38
38
|
</body>
|