@tsparticles/interaction-particles-links 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/browser/CircleWarp.js +50 -0
- package/browser/ILink.js +1 -0
- package/browser/LinkContainer.js +1 -0
- package/browser/LinkInstance.js +143 -0
- package/browser/LinkParticle.js +1 -0
- package/browser/Linker.js +119 -0
- package/browser/Options/Classes/Links.js +54 -0
- package/browser/Options/Classes/LinksShadow.js +21 -0
- package/browser/Options/Classes/LinksTriangle.js +24 -0
- package/browser/Options/Classes/ParticlesLinkOptions.js +1 -0
- package/browser/Options/Interfaces/ILinks.js +1 -0
- package/browser/Options/Interfaces/ILinksShadow.js +1 -0
- package/browser/Options/Interfaces/ILinksTriangle.js +1 -0
- package/browser/Options/Interfaces/IParticlesLinkOptions.js +1 -0
- package/browser/Utils.js +77 -0
- package/browser/index.js +12 -0
- package/browser/interaction.js +4 -0
- package/browser/plugin.js +18 -0
- package/cjs/CircleWarp.js +54 -0
- package/cjs/ILink.js +2 -0
- package/cjs/LinkContainer.js +2 -0
- package/cjs/LinkInstance.js +158 -0
- package/cjs/LinkParticle.js +2 -0
- package/cjs/Linker.js +134 -0
- package/cjs/Options/Classes/Links.js +58 -0
- package/cjs/Options/Classes/LinksShadow.js +25 -0
- package/cjs/Options/Classes/LinksTriangle.js +28 -0
- package/cjs/Options/Classes/ParticlesLinkOptions.js +2 -0
- package/cjs/Options/Interfaces/ILinks.js +2 -0
- package/cjs/Options/Interfaces/ILinksShadow.js +2 -0
- package/cjs/Options/Interfaces/ILinksTriangle.js +2 -0
- package/cjs/Options/Interfaces/IParticlesLinkOptions.js +2 -0
- package/cjs/Utils.js +82 -0
- package/cjs/index.js +41 -0
- package/cjs/interaction.js +19 -0
- package/cjs/plugin.js +33 -0
- package/esm/CircleWarp.js +50 -0
- package/esm/ILink.js +1 -0
- package/esm/LinkContainer.js +1 -0
- package/esm/LinkInstance.js +143 -0
- package/esm/LinkParticle.js +1 -0
- package/esm/Linker.js +119 -0
- package/esm/Options/Classes/Links.js +54 -0
- package/esm/Options/Classes/LinksShadow.js +21 -0
- package/esm/Options/Classes/LinksTriangle.js +24 -0
- package/esm/Options/Classes/ParticlesLinkOptions.js +1 -0
- package/esm/Options/Interfaces/ILinks.js +1 -0
- package/esm/Options/Interfaces/ILinksShadow.js +1 -0
- package/esm/Options/Interfaces/ILinksTriangle.js +1 -0
- package/esm/Options/Interfaces/IParticlesLinkOptions.js +1 -0
- package/esm/Utils.js +77 -0
- package/esm/index.js +12 -0
- package/esm/interaction.js +4 -0
- package/esm/plugin.js +18 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.interaction.particles.links.js +658 -0
- package/tsparticles.interaction.particles.links.min.js +2 -0
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +8 -0
- package/types/CircleWarp.d.ts +8 -0
- package/types/ILink.d.ts +9 -0
- package/types/LinkContainer.d.ts +7 -0
- package/types/LinkInstance.d.ts +17 -0
- package/types/LinkParticle.d.ts +11 -0
- package/types/Linker.d.ts +17 -0
- package/types/Options/Classes/Links.d.ts +21 -0
- package/types/Options/Classes/LinksShadow.d.ts +10 -0
- package/types/Options/Classes/LinksTriangle.d.ts +11 -0
- package/types/Options/Classes/ParticlesLinkOptions.d.ts +5 -0
- package/types/Options/Interfaces/ILinks.d.ts +17 -0
- package/types/Options/Interfaces/ILinksShadow.d.ts +6 -0
- package/types/Options/Interfaces/ILinksTriangle.d.ts +7 -0
- package/types/Options/Interfaces/IParticlesLinkOptions.d.ts +7 -0
- package/types/Utils.d.ts +4 -0
- package/types/index.d.ts +8 -0
- package/types/interaction.d.ts +2 -0
- package/types/plugin.d.ts +2 -0
- package/umd/CircleWarp.js +64 -0
- package/umd/ILink.js +12 -0
- package/umd/LinkContainer.js +12 -0
- package/umd/LinkInstance.js +157 -0
- package/umd/LinkParticle.js +12 -0
- package/umd/Linker.js +133 -0
- package/umd/Options/Classes/Links.js +68 -0
- package/umd/Options/Classes/LinksShadow.js +35 -0
- package/umd/Options/Classes/LinksTriangle.js +38 -0
- package/umd/Options/Classes/ParticlesLinkOptions.js +12 -0
- package/umd/Options/Interfaces/ILinks.js +12 -0
- package/umd/Options/Interfaces/ILinksShadow.js +12 -0
- package/umd/Options/Interfaces/ILinksTriangle.js +12 -0
- package/umd/Options/Interfaces/IParticlesLinkOptions.js +12 -0
- package/umd/Utils.js +92 -0
- package/umd/index.js +40 -0
- package/umd/interaction.js +18 -0
- package/umd/plugin.js +32 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CircleWarp = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class CircleWarp extends engine_1.Circle {
|
|
6
|
+
constructor(x, y, radius, canvasSize) {
|
|
7
|
+
super(x, y, radius);
|
|
8
|
+
this.canvasSize = canvasSize;
|
|
9
|
+
this.canvasSize = Object.assign({}, canvasSize);
|
|
10
|
+
}
|
|
11
|
+
contains(point) {
|
|
12
|
+
if (super.contains(point)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const posNE = {
|
|
16
|
+
x: point.x - this.canvasSize.width,
|
|
17
|
+
y: point.y,
|
|
18
|
+
};
|
|
19
|
+
if (super.contains(posNE)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const posSE = {
|
|
23
|
+
x: point.x - this.canvasSize.width,
|
|
24
|
+
y: point.y - this.canvasSize.height,
|
|
25
|
+
};
|
|
26
|
+
if (super.contains(posSE)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
const posSW = {
|
|
30
|
+
x: point.x,
|
|
31
|
+
y: point.y - this.canvasSize.height,
|
|
32
|
+
};
|
|
33
|
+
return super.contains(posSW);
|
|
34
|
+
}
|
|
35
|
+
intersects(range) {
|
|
36
|
+
if (super.intersects(range)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
const rect = range, circle = range, newPos = {
|
|
40
|
+
x: range.position.x - this.canvasSize.width,
|
|
41
|
+
y: range.position.y - this.canvasSize.height,
|
|
42
|
+
};
|
|
43
|
+
if (circle.radius !== undefined) {
|
|
44
|
+
const biggerCircle = new engine_1.Circle(newPos.x, newPos.y, circle.radius * 2);
|
|
45
|
+
return super.intersects(biggerCircle);
|
|
46
|
+
}
|
|
47
|
+
else if (rect.size !== undefined) {
|
|
48
|
+
const rectSW = new engine_1.Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
|
|
49
|
+
return super.intersects(rectSW);
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CircleWarp = CircleWarp;
|
package/cjs/ILink.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LinkInstance = void 0;
|
|
13
|
+
const Utils_1 = require("./Utils");
|
|
14
|
+
const engine_1 = require("@tsparticles/engine");
|
|
15
|
+
function getLinkKey(ids) {
|
|
16
|
+
ids.sort((a, b) => a - b);
|
|
17
|
+
return ids.join("_");
|
|
18
|
+
}
|
|
19
|
+
function setLinkFrequency(particles, dictionary) {
|
|
20
|
+
const key = getLinkKey(particles.map((t) => t.id));
|
|
21
|
+
let res = dictionary.get(key);
|
|
22
|
+
if (res === undefined) {
|
|
23
|
+
res = (0, engine_1.getRandom)();
|
|
24
|
+
dictionary.set(key, res);
|
|
25
|
+
}
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
class LinkInstance {
|
|
29
|
+
constructor(container) {
|
|
30
|
+
this.container = container;
|
|
31
|
+
this._freqs = {
|
|
32
|
+
links: new Map(),
|
|
33
|
+
triangles: new Map(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
drawParticle(context, particle) {
|
|
37
|
+
var _a;
|
|
38
|
+
const pOptions = particle.options;
|
|
39
|
+
if (!particle.links || particle.links.length <= 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const p1Links = particle.links.filter((l) => pOptions.links && this.getLinkFrequency(particle, l.destination) <= pOptions.links.frequency);
|
|
43
|
+
for (const link of p1Links) {
|
|
44
|
+
this.drawTriangles(pOptions, particle, link, p1Links);
|
|
45
|
+
if (link.opacity > 0 && ((_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0) > 0) {
|
|
46
|
+
this.drawLinkLine(particle, link);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
init() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
this._freqs.links = new Map();
|
|
53
|
+
this._freqs.triangles = new Map();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
particleCreated(particle) {
|
|
57
|
+
particle.links = [];
|
|
58
|
+
if (!particle.options.links) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const ratio = this.container.retina.pixelRatio;
|
|
62
|
+
particle.retina.linksDistance = particle.options.links.distance * ratio;
|
|
63
|
+
particle.retina.linksWidth = particle.options.links.width * ratio;
|
|
64
|
+
}
|
|
65
|
+
particleDestroyed(particle) {
|
|
66
|
+
particle.links = [];
|
|
67
|
+
}
|
|
68
|
+
drawLinkLine(p1, link) {
|
|
69
|
+
const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
70
|
+
let opacity = link.opacity;
|
|
71
|
+
container.canvas.draw((ctx) => {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
if (!p1.options.links) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
let colorLine;
|
|
77
|
+
const twinkle = (_a = p1.options.twinkle) === null || _a === void 0 ? void 0 : _a.lines;
|
|
78
|
+
if (twinkle === null || twinkle === void 0 ? void 0 : twinkle.enable) {
|
|
79
|
+
const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
|
|
80
|
+
if (twinkling && twinkleRgb) {
|
|
81
|
+
colorLine = twinkleRgb;
|
|
82
|
+
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!colorLine) {
|
|
86
|
+
const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
|
|
87
|
+
? container.particles.linksColors.get(linksOptions.id)
|
|
88
|
+
: container.particles.linksColor;
|
|
89
|
+
colorLine = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
90
|
+
}
|
|
91
|
+
if (!colorLine) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const width = (_b = p1.retina.linksWidth) !== null && _b !== void 0 ? _b : 0, maxDistance = (_c = p1.retina.linksDistance) !== null && _c !== void 0 ? _c : 0;
|
|
95
|
+
(0, Utils_1.drawLinkLine)(ctx, width, pos1, pos2, maxDistance, container.canvas.size, p1.options.links.warp, options.backgroundMask.enable, options.backgroundMask.composite, colorLine, opacity, p1.options.links.shadow);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
drawLinkTriangle(p1, link1, link2) {
|
|
99
|
+
var _a;
|
|
100
|
+
if (!p1.options.links) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, triangleOptions = p1.options.links.triangles, opacityTriangle = (_a = triangleOptions.opacity) !== null && _a !== void 0 ? _a : (link1.opacity + link2.opacity) / 2;
|
|
104
|
+
if (opacityTriangle <= 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
container.canvas.draw((ctx) => {
|
|
108
|
+
var _a;
|
|
109
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0;
|
|
110
|
+
if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
|
|
111
|
+
(0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
|
|
112
|
+
(0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
let colorTriangle = (0, engine_1.rangeColorToRgb)(triangleOptions.color);
|
|
116
|
+
if (!colorTriangle) {
|
|
117
|
+
const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
|
|
118
|
+
? container.particles.linksColors.get(linksOptions.id)
|
|
119
|
+
: container.particles.linksColor;
|
|
120
|
+
colorTriangle = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
121
|
+
}
|
|
122
|
+
if (!colorTriangle) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
(0, Utils_1.drawLinkTriangle)(ctx, pos1, pos2, pos3, options.backgroundMask.enable, options.backgroundMask.composite, colorTriangle, opacityTriangle);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
drawTriangles(options, p1, link, p1Links) {
|
|
129
|
+
var _a, _b, _c;
|
|
130
|
+
const p2 = link.destination;
|
|
131
|
+
if (!(((_a = options.links) === null || _a === void 0 ? void 0 : _a.triangles.enable) && ((_b = p2.options.links) === null || _b === void 0 ? void 0 : _b.triangles.enable))) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const vertices = (_c = p2.links) === null || _c === void 0 ? void 0 : _c.filter((t) => {
|
|
135
|
+
const linkFreq = this.getLinkFrequency(p2, t.destination);
|
|
136
|
+
return (p2.options.links &&
|
|
137
|
+
linkFreq <= p2.options.links.frequency &&
|
|
138
|
+
p1Links.findIndex((l) => l.destination === t.destination) >= 0);
|
|
139
|
+
});
|
|
140
|
+
if (!(vertices === null || vertices === void 0 ? void 0 : vertices.length)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
for (const vertex of vertices) {
|
|
144
|
+
const p3 = vertex.destination, triangleFreq = this.getTriangleFrequency(p1, p2, p3);
|
|
145
|
+
if (triangleFreq > options.links.triangles.frequency) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
this.drawLinkTriangle(p1, link, vertex);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
getLinkFrequency(p1, p2) {
|
|
152
|
+
return setLinkFrequency([p1, p2], this._freqs.links);
|
|
153
|
+
}
|
|
154
|
+
getTriangleFrequency(p1, p2, p3) {
|
|
155
|
+
return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.LinkInstance = LinkInstance;
|
package/cjs/Linker.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Linker = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const CircleWarp_1 = require("./CircleWarp");
|
|
15
|
+
const Links_1 = require("./Options/Classes/Links");
|
|
16
|
+
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
17
|
+
let distance = (0, engine_1.getDistance)(pos1, pos2);
|
|
18
|
+
if (!warp || distance <= optDistance) {
|
|
19
|
+
return distance;
|
|
20
|
+
}
|
|
21
|
+
const pos2NE = {
|
|
22
|
+
x: pos2.x - canvasSize.width,
|
|
23
|
+
y: pos2.y,
|
|
24
|
+
};
|
|
25
|
+
distance = (0, engine_1.getDistance)(pos1, pos2NE);
|
|
26
|
+
if (distance <= optDistance) {
|
|
27
|
+
return distance;
|
|
28
|
+
}
|
|
29
|
+
const pos2SE = {
|
|
30
|
+
x: pos2.x - canvasSize.width,
|
|
31
|
+
y: pos2.y - canvasSize.height,
|
|
32
|
+
};
|
|
33
|
+
distance = (0, engine_1.getDistance)(pos1, pos2SE);
|
|
34
|
+
if (distance <= optDistance) {
|
|
35
|
+
return distance;
|
|
36
|
+
}
|
|
37
|
+
const pos2SW = {
|
|
38
|
+
x: pos2.x,
|
|
39
|
+
y: pos2.y - canvasSize.height,
|
|
40
|
+
};
|
|
41
|
+
distance = (0, engine_1.getDistance)(pos1, pos2SW);
|
|
42
|
+
return distance;
|
|
43
|
+
}
|
|
44
|
+
class Linker extends engine_1.ParticlesInteractorBase {
|
|
45
|
+
constructor(container) {
|
|
46
|
+
super(container);
|
|
47
|
+
this.linkContainer = container;
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
}
|
|
51
|
+
init() {
|
|
52
|
+
this.linkContainer.particles.linksColor = undefined;
|
|
53
|
+
this.linkContainer.particles.linksColors = new Map();
|
|
54
|
+
}
|
|
55
|
+
interact(p1) {
|
|
56
|
+
var _a;
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (!p1.options.links) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
p1.links = [];
|
|
62
|
+
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
63
|
+
if (pos1.x < 0 || pos1.y < 0 || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0, warp = linkOpt1.warp, range = warp
|
|
67
|
+
? new CircleWarp_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize)
|
|
68
|
+
: new engine_1.Circle(pos1.x, pos1.y, optDistance), query = container.particles.quadTree.query(range);
|
|
69
|
+
for (const p2 of query) {
|
|
70
|
+
const linkOpt2 = p2.options.links;
|
|
71
|
+
if (p1 === p2 ||
|
|
72
|
+
!(linkOpt2 === null || linkOpt2 === void 0 ? void 0 : linkOpt2.enable) ||
|
|
73
|
+
linkOpt1.id !== linkOpt2.id ||
|
|
74
|
+
p2.spawning ||
|
|
75
|
+
p2.destroyed ||
|
|
76
|
+
!p2.links ||
|
|
77
|
+
p1.links.map((t) => t.destination).indexOf(p2) !== -1 ||
|
|
78
|
+
p2.links.map((t) => t.destination).indexOf(p1) !== -1) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const pos2 = p2.getPosition();
|
|
82
|
+
if (pos2.x < 0 || pos2.y < 0 || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
|
86
|
+
if (distance > optDistance) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const opacityLine = (1 - distance / optDistance) * optOpacity;
|
|
90
|
+
this.setColor(p1);
|
|
91
|
+
p1.links.push({
|
|
92
|
+
destination: p2,
|
|
93
|
+
opacity: opacityLine,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
isEnabled(particle) {
|
|
99
|
+
var _a;
|
|
100
|
+
return !!((_a = particle.options.links) === null || _a === void 0 ? void 0 : _a.enable);
|
|
101
|
+
}
|
|
102
|
+
loadParticlesOptions(options, ...sources) {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
if (!options.links) {
|
|
105
|
+
options.links = new Links_1.Links();
|
|
106
|
+
}
|
|
107
|
+
for (const source of sources) {
|
|
108
|
+
options.links.load((_b = (_a = source === null || source === void 0 ? void 0 : source.links) !== null && _a !== void 0 ? _a : source === null || source === void 0 ? void 0 : source.lineLinked) !== null && _b !== void 0 ? _b : source === null || source === void 0 ? void 0 : source.line_linked);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
reset() {
|
|
112
|
+
}
|
|
113
|
+
setColor(p1) {
|
|
114
|
+
if (!p1.options.links) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const container = this.linkContainer, linksOptions = p1.options.links;
|
|
118
|
+
let linkColor = linksOptions.id === undefined
|
|
119
|
+
? container.particles.linksColor
|
|
120
|
+
: container.particles.linksColors.get(linksOptions.id);
|
|
121
|
+
if (linkColor) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const optColor = linksOptions.color;
|
|
125
|
+
linkColor = (0, engine_1.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
|
|
126
|
+
if (linksOptions.id === undefined) {
|
|
127
|
+
container.particles.linksColor = linkColor;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.Linker = Linker;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Links = void 0;
|
|
4
|
+
const LinksShadow_1 = require("./LinksShadow");
|
|
5
|
+
const LinksTriangle_1 = require("./LinksTriangle");
|
|
6
|
+
const engine_1 = require("@tsparticles/engine");
|
|
7
|
+
class Links {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.blink = false;
|
|
10
|
+
this.color = new engine_1.OptionsColor();
|
|
11
|
+
this.color.value = "#fff";
|
|
12
|
+
this.consent = false;
|
|
13
|
+
this.distance = 100;
|
|
14
|
+
this.enable = false;
|
|
15
|
+
this.frequency = 1;
|
|
16
|
+
this.opacity = 1;
|
|
17
|
+
this.shadow = new LinksShadow_1.LinksShadow();
|
|
18
|
+
this.triangles = new LinksTriangle_1.LinksTriangle();
|
|
19
|
+
this.width = 1;
|
|
20
|
+
this.warp = false;
|
|
21
|
+
}
|
|
22
|
+
load(data) {
|
|
23
|
+
if (!data) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (data.id !== undefined) {
|
|
27
|
+
this.id = data.id;
|
|
28
|
+
}
|
|
29
|
+
if (data.blink !== undefined) {
|
|
30
|
+
this.blink = data.blink;
|
|
31
|
+
}
|
|
32
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
33
|
+
if (data.consent !== undefined) {
|
|
34
|
+
this.consent = data.consent;
|
|
35
|
+
}
|
|
36
|
+
if (data.distance !== undefined) {
|
|
37
|
+
this.distance = data.distance;
|
|
38
|
+
}
|
|
39
|
+
if (data.enable !== undefined) {
|
|
40
|
+
this.enable = data.enable;
|
|
41
|
+
}
|
|
42
|
+
if (data.frequency !== undefined) {
|
|
43
|
+
this.frequency = data.frequency;
|
|
44
|
+
}
|
|
45
|
+
if (data.opacity !== undefined) {
|
|
46
|
+
this.opacity = data.opacity;
|
|
47
|
+
}
|
|
48
|
+
this.shadow.load(data.shadow);
|
|
49
|
+
this.triangles.load(data.triangles);
|
|
50
|
+
if (data.width !== undefined) {
|
|
51
|
+
this.width = data.width;
|
|
52
|
+
}
|
|
53
|
+
if (data.warp !== undefined) {
|
|
54
|
+
this.warp = data.warp;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Links = Links;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinksShadow = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class LinksShadow {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.blur = 5;
|
|
8
|
+
this.color = new engine_1.OptionsColor();
|
|
9
|
+
this.color.value = "#000";
|
|
10
|
+
this.enable = false;
|
|
11
|
+
}
|
|
12
|
+
load(data) {
|
|
13
|
+
if (!data) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (data.blur !== undefined) {
|
|
17
|
+
this.blur = data.blur;
|
|
18
|
+
}
|
|
19
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
20
|
+
if (data.enable !== undefined) {
|
|
21
|
+
this.enable = data.enable;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.LinksShadow = LinksShadow;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinksTriangle = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class LinksTriangle {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.enable = false;
|
|
8
|
+
this.frequency = 1;
|
|
9
|
+
}
|
|
10
|
+
load(data) {
|
|
11
|
+
if (!data) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (data.color !== undefined) {
|
|
15
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
16
|
+
}
|
|
17
|
+
if (data.enable !== undefined) {
|
|
18
|
+
this.enable = data.enable;
|
|
19
|
+
}
|
|
20
|
+
if (data.frequency !== undefined) {
|
|
21
|
+
this.frequency = data.frequency;
|
|
22
|
+
}
|
|
23
|
+
if (data.opacity !== undefined) {
|
|
24
|
+
this.opacity = data.opacity;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.LinksTriangle = LinksTriangle;
|
package/cjs/Utils.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.drawLinkTriangle = exports.drawLinkLine = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
function drawLinkLine(context, width, begin, end, maxDistance, canvasSize, warp, backgroundMask, composite, colorLine, opacity, shadow) {
|
|
6
|
+
let drawn = false;
|
|
7
|
+
if ((0, engine_1.getDistance)(begin, end) <= maxDistance) {
|
|
8
|
+
(0, engine_1.drawLine)(context, begin, end);
|
|
9
|
+
drawn = true;
|
|
10
|
+
}
|
|
11
|
+
else if (warp) {
|
|
12
|
+
let pi1;
|
|
13
|
+
let pi2;
|
|
14
|
+
const endNE = {
|
|
15
|
+
x: end.x - canvasSize.width,
|
|
16
|
+
y: end.y,
|
|
17
|
+
};
|
|
18
|
+
const d1 = (0, engine_1.getDistances)(begin, endNE);
|
|
19
|
+
if (d1.distance <= maxDistance) {
|
|
20
|
+
const yi = begin.y - (d1.dy / d1.dx) * begin.x;
|
|
21
|
+
pi1 = { x: 0, y: yi };
|
|
22
|
+
pi2 = { x: canvasSize.width, y: yi };
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const endSW = {
|
|
26
|
+
x: end.x,
|
|
27
|
+
y: end.y - canvasSize.height,
|
|
28
|
+
};
|
|
29
|
+
const d2 = (0, engine_1.getDistances)(begin, endSW);
|
|
30
|
+
if (d2.distance <= maxDistance) {
|
|
31
|
+
const yi = begin.y - (d2.dy / d2.dx) * begin.x;
|
|
32
|
+
const xi = -yi / (d2.dy / d2.dx);
|
|
33
|
+
pi1 = { x: xi, y: 0 };
|
|
34
|
+
pi2 = { x: xi, y: canvasSize.height };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const endSE = {
|
|
38
|
+
x: end.x - canvasSize.width,
|
|
39
|
+
y: end.y - canvasSize.height,
|
|
40
|
+
};
|
|
41
|
+
const d3 = (0, engine_1.getDistances)(begin, endSE);
|
|
42
|
+
if (d3.distance <= maxDistance) {
|
|
43
|
+
const yi = begin.y - (d3.dy / d3.dx) * begin.x;
|
|
44
|
+
const xi = -yi / (d3.dy / d3.dx);
|
|
45
|
+
pi1 = { x: xi, y: yi };
|
|
46
|
+
pi2 = { x: pi1.x + canvasSize.width, y: pi1.y + canvasSize.height };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (pi1 && pi2) {
|
|
51
|
+
(0, engine_1.drawLine)(context, begin, pi1);
|
|
52
|
+
(0, engine_1.drawLine)(context, end, pi2);
|
|
53
|
+
drawn = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!drawn) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
context.lineWidth = width;
|
|
60
|
+
if (backgroundMask) {
|
|
61
|
+
context.globalCompositeOperation = composite;
|
|
62
|
+
}
|
|
63
|
+
context.strokeStyle = (0, engine_1.getStyleFromRgb)(colorLine, opacity);
|
|
64
|
+
if (shadow.enable) {
|
|
65
|
+
const shadowColor = (0, engine_1.rangeColorToRgb)(shadow.color);
|
|
66
|
+
if (shadowColor) {
|
|
67
|
+
context.shadowBlur = shadow.blur;
|
|
68
|
+
context.shadowColor = (0, engine_1.getStyleFromRgb)(shadowColor);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
context.stroke();
|
|
72
|
+
}
|
|
73
|
+
exports.drawLinkLine = drawLinkLine;
|
|
74
|
+
function drawLinkTriangle(context, pos1, pos2, pos3, backgroundMask, composite, colorTriangle, opacityTriangle) {
|
|
75
|
+
(0, engine_1.drawTriangle)(context, pos1, pos2, pos3);
|
|
76
|
+
if (backgroundMask) {
|
|
77
|
+
context.globalCompositeOperation = composite;
|
|
78
|
+
}
|
|
79
|
+
context.fillStyle = (0, engine_1.getStyleFromRgb)(colorTriangle, opacityTriangle);
|
|
80
|
+
context.fill();
|
|
81
|
+
}
|
|
82
|
+
exports.drawLinkTriangle = drawLinkTriangle;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadParticlesLinksInteraction = void 0;
|
|
27
|
+
const interaction_1 = require("./interaction");
|
|
28
|
+
const plugin_1 = require("./plugin");
|
|
29
|
+
function loadParticlesLinksInteraction(engine) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield (0, interaction_1.loadInteraction)(engine);
|
|
32
|
+
yield (0, plugin_1.loadPlugin)(engine);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.loadParticlesLinksInteraction = loadParticlesLinksInteraction;
|
|
36
|
+
__exportStar(require("./Options/Classes/Links"), exports);
|
|
37
|
+
__exportStar(require("./Options/Classes/LinksShadow"), exports);
|
|
38
|
+
__exportStar(require("./Options/Classes/LinksTriangle"), exports);
|
|
39
|
+
__exportStar(require("./Options/Interfaces/ILinks"), exports);
|
|
40
|
+
__exportStar(require("./Options/Interfaces/ILinksShadow"), exports);
|
|
41
|
+
__exportStar(require("./Options/Interfaces/ILinksTriangle"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadInteraction = void 0;
|
|
13
|
+
const Linker_1 = require("./Linker");
|
|
14
|
+
function loadInteraction(engine) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
yield engine.addInteractor("particlesLinks", (container) => new Linker_1.Linker(container));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.loadInteraction = loadInteraction;
|
package/cjs/plugin.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadPlugin = void 0;
|
|
13
|
+
const LinkInstance_1 = require("./LinkInstance");
|
|
14
|
+
class LinksPlugin {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.id = "links";
|
|
17
|
+
}
|
|
18
|
+
getPlugin(container) {
|
|
19
|
+
return new LinkInstance_1.LinkInstance(container);
|
|
20
|
+
}
|
|
21
|
+
loadOptions() {
|
|
22
|
+
}
|
|
23
|
+
needsPlugin() {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function loadPlugin(engine) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const plugin = new LinksPlugin();
|
|
30
|
+
yield engine.addPlugin(plugin);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.loadPlugin = loadPlugin;
|