@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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +69 -0
  3. package/browser/CircleWarp.js +50 -0
  4. package/browser/ILink.js +1 -0
  5. package/browser/LinkContainer.js +1 -0
  6. package/browser/LinkInstance.js +143 -0
  7. package/browser/LinkParticle.js +1 -0
  8. package/browser/Linker.js +119 -0
  9. package/browser/Options/Classes/Links.js +54 -0
  10. package/browser/Options/Classes/LinksShadow.js +21 -0
  11. package/browser/Options/Classes/LinksTriangle.js +24 -0
  12. package/browser/Options/Classes/ParticlesLinkOptions.js +1 -0
  13. package/browser/Options/Interfaces/ILinks.js +1 -0
  14. package/browser/Options/Interfaces/ILinksShadow.js +1 -0
  15. package/browser/Options/Interfaces/ILinksTriangle.js +1 -0
  16. package/browser/Options/Interfaces/IParticlesLinkOptions.js +1 -0
  17. package/browser/Utils.js +77 -0
  18. package/browser/index.js +12 -0
  19. package/browser/interaction.js +4 -0
  20. package/browser/plugin.js +18 -0
  21. package/cjs/CircleWarp.js +54 -0
  22. package/cjs/ILink.js +2 -0
  23. package/cjs/LinkContainer.js +2 -0
  24. package/cjs/LinkInstance.js +158 -0
  25. package/cjs/LinkParticle.js +2 -0
  26. package/cjs/Linker.js +134 -0
  27. package/cjs/Options/Classes/Links.js +58 -0
  28. package/cjs/Options/Classes/LinksShadow.js +25 -0
  29. package/cjs/Options/Classes/LinksTriangle.js +28 -0
  30. package/cjs/Options/Classes/ParticlesLinkOptions.js +2 -0
  31. package/cjs/Options/Interfaces/ILinks.js +2 -0
  32. package/cjs/Options/Interfaces/ILinksShadow.js +2 -0
  33. package/cjs/Options/Interfaces/ILinksTriangle.js +2 -0
  34. package/cjs/Options/Interfaces/IParticlesLinkOptions.js +2 -0
  35. package/cjs/Utils.js +82 -0
  36. package/cjs/index.js +41 -0
  37. package/cjs/interaction.js +19 -0
  38. package/cjs/plugin.js +33 -0
  39. package/esm/CircleWarp.js +50 -0
  40. package/esm/ILink.js +1 -0
  41. package/esm/LinkContainer.js +1 -0
  42. package/esm/LinkInstance.js +143 -0
  43. package/esm/LinkParticle.js +1 -0
  44. package/esm/Linker.js +119 -0
  45. package/esm/Options/Classes/Links.js +54 -0
  46. package/esm/Options/Classes/LinksShadow.js +21 -0
  47. package/esm/Options/Classes/LinksTriangle.js +24 -0
  48. package/esm/Options/Classes/ParticlesLinkOptions.js +1 -0
  49. package/esm/Options/Interfaces/ILinks.js +1 -0
  50. package/esm/Options/Interfaces/ILinksShadow.js +1 -0
  51. package/esm/Options/Interfaces/ILinksTriangle.js +1 -0
  52. package/esm/Options/Interfaces/IParticlesLinkOptions.js +1 -0
  53. package/esm/Utils.js +77 -0
  54. package/esm/index.js +12 -0
  55. package/esm/interaction.js +4 -0
  56. package/esm/plugin.js +18 -0
  57. package/package.json +82 -0
  58. package/report.html +39 -0
  59. package/tsparticles.interaction.particles.links.js +658 -0
  60. package/tsparticles.interaction.particles.links.min.js +2 -0
  61. package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +8 -0
  62. package/types/CircleWarp.d.ts +8 -0
  63. package/types/ILink.d.ts +9 -0
  64. package/types/LinkContainer.d.ts +7 -0
  65. package/types/LinkInstance.d.ts +17 -0
  66. package/types/LinkParticle.d.ts +11 -0
  67. package/types/Linker.d.ts +17 -0
  68. package/types/Options/Classes/Links.d.ts +21 -0
  69. package/types/Options/Classes/LinksShadow.d.ts +10 -0
  70. package/types/Options/Classes/LinksTriangle.d.ts +11 -0
  71. package/types/Options/Classes/ParticlesLinkOptions.d.ts +5 -0
  72. package/types/Options/Interfaces/ILinks.d.ts +17 -0
  73. package/types/Options/Interfaces/ILinksShadow.d.ts +6 -0
  74. package/types/Options/Interfaces/ILinksTriangle.d.ts +7 -0
  75. package/types/Options/Interfaces/IParticlesLinkOptions.d.ts +7 -0
  76. package/types/Utils.d.ts +4 -0
  77. package/types/index.d.ts +8 -0
  78. package/types/interaction.d.ts +2 -0
  79. package/types/plugin.d.ts +2 -0
  80. package/umd/CircleWarp.js +64 -0
  81. package/umd/ILink.js +12 -0
  82. package/umd/LinkContainer.js +12 -0
  83. package/umd/LinkInstance.js +157 -0
  84. package/umd/LinkParticle.js +12 -0
  85. package/umd/Linker.js +133 -0
  86. package/umd/Options/Classes/Links.js +68 -0
  87. package/umd/Options/Classes/LinksShadow.js +35 -0
  88. package/umd/Options/Classes/LinksTriangle.js +38 -0
  89. package/umd/Options/Classes/ParticlesLinkOptions.js +12 -0
  90. package/umd/Options/Interfaces/ILinks.js +12 -0
  91. package/umd/Options/Interfaces/ILinksShadow.js +12 -0
  92. package/umd/Options/Interfaces/ILinksTriangle.js +12 -0
  93. package/umd/Options/Interfaces/IParticlesLinkOptions.js +12 -0
  94. package/umd/Utils.js +92 -0
  95. package/umd/index.js +40 -0
  96. package/umd/interaction.js +18 -0
  97. package/umd/plugin.js +32 -0
@@ -0,0 +1,50 @@
1
+ import { Circle, Rectangle } from "@tsparticles/engine";
2
+ export class CircleWarp extends Circle {
3
+ constructor(x, y, radius, canvasSize) {
4
+ super(x, y, radius);
5
+ this.canvasSize = canvasSize;
6
+ this.canvasSize = Object.assign({}, canvasSize);
7
+ }
8
+ contains(point) {
9
+ if (super.contains(point)) {
10
+ return true;
11
+ }
12
+ const posNE = {
13
+ x: point.x - this.canvasSize.width,
14
+ y: point.y,
15
+ };
16
+ if (super.contains(posNE)) {
17
+ return true;
18
+ }
19
+ const posSE = {
20
+ x: point.x - this.canvasSize.width,
21
+ y: point.y - this.canvasSize.height,
22
+ };
23
+ if (super.contains(posSE)) {
24
+ return true;
25
+ }
26
+ const posSW = {
27
+ x: point.x,
28
+ y: point.y - this.canvasSize.height,
29
+ };
30
+ return super.contains(posSW);
31
+ }
32
+ intersects(range) {
33
+ if (super.intersects(range)) {
34
+ return true;
35
+ }
36
+ const rect = range, circle = range, newPos = {
37
+ x: range.position.x - this.canvasSize.width,
38
+ y: range.position.y - this.canvasSize.height,
39
+ };
40
+ if (circle.radius !== undefined) {
41
+ const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * 2);
42
+ return super.intersects(biggerCircle);
43
+ }
44
+ else if (rect.size !== undefined) {
45
+ const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
46
+ return super.intersects(rectSW);
47
+ }
48
+ return false;
49
+ }
50
+ }
package/esm/ILink.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,143 @@
1
+ import { drawLinkLine, drawLinkTriangle } from "./Utils";
2
+ import { getDistance, getLinkColor, getRandom, getRangeValue, rangeColorToRgb } from "@tsparticles/engine";
3
+ function getLinkKey(ids) {
4
+ ids.sort((a, b) => a - b);
5
+ return ids.join("_");
6
+ }
7
+ function setLinkFrequency(particles, dictionary) {
8
+ const key = getLinkKey(particles.map((t) => t.id));
9
+ let res = dictionary.get(key);
10
+ if (res === undefined) {
11
+ res = getRandom();
12
+ dictionary.set(key, res);
13
+ }
14
+ return res;
15
+ }
16
+ export class LinkInstance {
17
+ constructor(container) {
18
+ this.container = container;
19
+ this._freqs = {
20
+ links: new Map(),
21
+ triangles: new Map(),
22
+ };
23
+ }
24
+ drawParticle(context, particle) {
25
+ var _a;
26
+ const pOptions = particle.options;
27
+ if (!particle.links || particle.links.length <= 0) {
28
+ return;
29
+ }
30
+ const p1Links = particle.links.filter((l) => pOptions.links && this.getLinkFrequency(particle, l.destination) <= pOptions.links.frequency);
31
+ for (const link of p1Links) {
32
+ this.drawTriangles(pOptions, particle, link, p1Links);
33
+ if (link.opacity > 0 && ((_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0) > 0) {
34
+ this.drawLinkLine(particle, link);
35
+ }
36
+ }
37
+ }
38
+ async init() {
39
+ this._freqs.links = new Map();
40
+ this._freqs.triangles = new Map();
41
+ }
42
+ particleCreated(particle) {
43
+ particle.links = [];
44
+ if (!particle.options.links) {
45
+ return;
46
+ }
47
+ const ratio = this.container.retina.pixelRatio;
48
+ particle.retina.linksDistance = particle.options.links.distance * ratio;
49
+ particle.retina.linksWidth = particle.options.links.width * ratio;
50
+ }
51
+ particleDestroyed(particle) {
52
+ particle.links = [];
53
+ }
54
+ drawLinkLine(p1, link) {
55
+ const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
56
+ let opacity = link.opacity;
57
+ container.canvas.draw((ctx) => {
58
+ var _a, _b, _c;
59
+ if (!p1.options.links) {
60
+ return;
61
+ }
62
+ let colorLine;
63
+ const twinkle = (_a = p1.options.twinkle) === null || _a === void 0 ? void 0 : _a.lines;
64
+ if (twinkle === null || twinkle === void 0 ? void 0 : twinkle.enable) {
65
+ const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(twinkle.color), twinkling = getRandom() < twinkleFreq;
66
+ if (twinkling && twinkleRgb) {
67
+ colorLine = twinkleRgb;
68
+ opacity = getRangeValue(twinkle.opacity);
69
+ }
70
+ }
71
+ if (!colorLine) {
72
+ const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
73
+ ? container.particles.linksColors.get(linksOptions.id)
74
+ : container.particles.linksColor;
75
+ colorLine = getLinkColor(p1, p2, linkColor);
76
+ }
77
+ if (!colorLine) {
78
+ return;
79
+ }
80
+ const width = (_b = p1.retina.linksWidth) !== null && _b !== void 0 ? _b : 0, maxDistance = (_c = p1.retina.linksDistance) !== null && _c !== void 0 ? _c : 0;
81
+ 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);
82
+ });
83
+ }
84
+ drawLinkTriangle(p1, link1, link2) {
85
+ var _a;
86
+ if (!p1.options.links) {
87
+ return;
88
+ }
89
+ 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;
90
+ if (opacityTriangle <= 0) {
91
+ return;
92
+ }
93
+ container.canvas.draw((ctx) => {
94
+ var _a;
95
+ const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0;
96
+ if (getDistance(pos1, pos2) > linksDistance ||
97
+ getDistance(pos3, pos2) > linksDistance ||
98
+ getDistance(pos3, pos1) > linksDistance) {
99
+ return;
100
+ }
101
+ let colorTriangle = rangeColorToRgb(triangleOptions.color);
102
+ if (!colorTriangle) {
103
+ const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
104
+ ? container.particles.linksColors.get(linksOptions.id)
105
+ : container.particles.linksColor;
106
+ colorTriangle = getLinkColor(p1, p2, linkColor);
107
+ }
108
+ if (!colorTriangle) {
109
+ return;
110
+ }
111
+ drawLinkTriangle(ctx, pos1, pos2, pos3, options.backgroundMask.enable, options.backgroundMask.composite, colorTriangle, opacityTriangle);
112
+ });
113
+ }
114
+ drawTriangles(options, p1, link, p1Links) {
115
+ var _a, _b, _c;
116
+ const p2 = link.destination;
117
+ 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))) {
118
+ return;
119
+ }
120
+ const vertices = (_c = p2.links) === null || _c === void 0 ? void 0 : _c.filter((t) => {
121
+ const linkFreq = this.getLinkFrequency(p2, t.destination);
122
+ return (p2.options.links &&
123
+ linkFreq <= p2.options.links.frequency &&
124
+ p1Links.findIndex((l) => l.destination === t.destination) >= 0);
125
+ });
126
+ if (!(vertices === null || vertices === void 0 ? void 0 : vertices.length)) {
127
+ return;
128
+ }
129
+ for (const vertex of vertices) {
130
+ const p3 = vertex.destination, triangleFreq = this.getTriangleFrequency(p1, p2, p3);
131
+ if (triangleFreq > options.links.triangles.frequency) {
132
+ continue;
133
+ }
134
+ this.drawLinkTriangle(p1, link, vertex);
135
+ }
136
+ }
137
+ getLinkFrequency(p1, p2) {
138
+ return setLinkFrequency([p1, p2], this._freqs.links);
139
+ }
140
+ getTriangleFrequency(p1, p2, p3) {
141
+ return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
142
+ }
143
+ }
@@ -0,0 +1 @@
1
+ export {};
package/esm/Linker.js ADDED
@@ -0,0 +1,119 @@
1
+ import { Circle, ParticlesInteractorBase, getDistance, getLinkRandomColor } from "@tsparticles/engine";
2
+ import { CircleWarp } from "./CircleWarp";
3
+ import { Links } from "./Options/Classes/Links";
4
+ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
5
+ let distance = getDistance(pos1, pos2);
6
+ if (!warp || distance <= optDistance) {
7
+ return distance;
8
+ }
9
+ const pos2NE = {
10
+ x: pos2.x - canvasSize.width,
11
+ y: pos2.y,
12
+ };
13
+ distance = getDistance(pos1, pos2NE);
14
+ if (distance <= optDistance) {
15
+ return distance;
16
+ }
17
+ const pos2SE = {
18
+ x: pos2.x - canvasSize.width,
19
+ y: pos2.y - canvasSize.height,
20
+ };
21
+ distance = getDistance(pos1, pos2SE);
22
+ if (distance <= optDistance) {
23
+ return distance;
24
+ }
25
+ const pos2SW = {
26
+ x: pos2.x,
27
+ y: pos2.y - canvasSize.height,
28
+ };
29
+ distance = getDistance(pos1, pos2SW);
30
+ return distance;
31
+ }
32
+ export class Linker extends ParticlesInteractorBase {
33
+ constructor(container) {
34
+ super(container);
35
+ this.linkContainer = container;
36
+ }
37
+ clear() {
38
+ }
39
+ init() {
40
+ this.linkContainer.particles.linksColor = undefined;
41
+ this.linkContainer.particles.linksColors = new Map();
42
+ }
43
+ async interact(p1) {
44
+ var _a;
45
+ if (!p1.options.links) {
46
+ return;
47
+ }
48
+ p1.links = [];
49
+ const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
50
+ if (pos1.x < 0 || pos1.y < 0 || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
51
+ return;
52
+ }
53
+ const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0, warp = linkOpt1.warp, range = warp
54
+ ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize)
55
+ : new Circle(pos1.x, pos1.y, optDistance), query = container.particles.quadTree.query(range);
56
+ for (const p2 of query) {
57
+ const linkOpt2 = p2.options.links;
58
+ if (p1 === p2 ||
59
+ !(linkOpt2 === null || linkOpt2 === void 0 ? void 0 : linkOpt2.enable) ||
60
+ linkOpt1.id !== linkOpt2.id ||
61
+ p2.spawning ||
62
+ p2.destroyed ||
63
+ !p2.links ||
64
+ p1.links.map((t) => t.destination).indexOf(p2) !== -1 ||
65
+ p2.links.map((t) => t.destination).indexOf(p1) !== -1) {
66
+ continue;
67
+ }
68
+ const pos2 = p2.getPosition();
69
+ if (pos2.x < 0 || pos2.y < 0 || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
70
+ continue;
71
+ }
72
+ const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
73
+ if (distance > optDistance) {
74
+ return;
75
+ }
76
+ const opacityLine = (1 - distance / optDistance) * optOpacity;
77
+ this.setColor(p1);
78
+ p1.links.push({
79
+ destination: p2,
80
+ opacity: opacityLine,
81
+ });
82
+ }
83
+ }
84
+ isEnabled(particle) {
85
+ var _a;
86
+ return !!((_a = particle.options.links) === null || _a === void 0 ? void 0 : _a.enable);
87
+ }
88
+ loadParticlesOptions(options, ...sources) {
89
+ var _a, _b;
90
+ if (!options.links) {
91
+ options.links = new Links();
92
+ }
93
+ for (const source of sources) {
94
+ 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);
95
+ }
96
+ }
97
+ reset() {
98
+ }
99
+ setColor(p1) {
100
+ if (!p1.options.links) {
101
+ return;
102
+ }
103
+ const container = this.linkContainer, linksOptions = p1.options.links;
104
+ let linkColor = linksOptions.id === undefined
105
+ ? container.particles.linksColor
106
+ : container.particles.linksColors.get(linksOptions.id);
107
+ if (linkColor) {
108
+ return;
109
+ }
110
+ const optColor = linksOptions.color;
111
+ linkColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
112
+ if (linksOptions.id === undefined) {
113
+ container.particles.linksColor = linkColor;
114
+ }
115
+ else {
116
+ container.particles.linksColors.set(linksOptions.id, linkColor);
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,54 @@
1
+ import { LinksShadow } from "./LinksShadow";
2
+ import { LinksTriangle } from "./LinksTriangle";
3
+ import { OptionsColor } from "@tsparticles/engine";
4
+ export class Links {
5
+ constructor() {
6
+ this.blink = false;
7
+ this.color = new OptionsColor();
8
+ this.color.value = "#fff";
9
+ this.consent = false;
10
+ this.distance = 100;
11
+ this.enable = false;
12
+ this.frequency = 1;
13
+ this.opacity = 1;
14
+ this.shadow = new LinksShadow();
15
+ this.triangles = new LinksTriangle();
16
+ this.width = 1;
17
+ this.warp = false;
18
+ }
19
+ load(data) {
20
+ if (!data) {
21
+ return;
22
+ }
23
+ if (data.id !== undefined) {
24
+ this.id = data.id;
25
+ }
26
+ if (data.blink !== undefined) {
27
+ this.blink = data.blink;
28
+ }
29
+ this.color = OptionsColor.create(this.color, data.color);
30
+ if (data.consent !== undefined) {
31
+ this.consent = data.consent;
32
+ }
33
+ if (data.distance !== undefined) {
34
+ this.distance = data.distance;
35
+ }
36
+ if (data.enable !== undefined) {
37
+ this.enable = data.enable;
38
+ }
39
+ if (data.frequency !== undefined) {
40
+ this.frequency = data.frequency;
41
+ }
42
+ if (data.opacity !== undefined) {
43
+ this.opacity = data.opacity;
44
+ }
45
+ this.shadow.load(data.shadow);
46
+ this.triangles.load(data.triangles);
47
+ if (data.width !== undefined) {
48
+ this.width = data.width;
49
+ }
50
+ if (data.warp !== undefined) {
51
+ this.warp = data.warp;
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,21 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ export class LinksShadow {
3
+ constructor() {
4
+ this.blur = 5;
5
+ this.color = new OptionsColor();
6
+ this.color.value = "#000";
7
+ this.enable = false;
8
+ }
9
+ load(data) {
10
+ if (!data) {
11
+ return;
12
+ }
13
+ if (data.blur !== undefined) {
14
+ this.blur = data.blur;
15
+ }
16
+ this.color = OptionsColor.create(this.color, data.color);
17
+ if (data.enable !== undefined) {
18
+ this.enable = data.enable;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,24 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ export class LinksTriangle {
3
+ constructor() {
4
+ this.enable = false;
5
+ this.frequency = 1;
6
+ }
7
+ load(data) {
8
+ if (!data) {
9
+ return;
10
+ }
11
+ if (data.color !== undefined) {
12
+ this.color = OptionsColor.create(this.color, data.color);
13
+ }
14
+ if (data.enable !== undefined) {
15
+ this.enable = data.enable;
16
+ }
17
+ if (data.frequency !== undefined) {
18
+ this.frequency = data.frequency;
19
+ }
20
+ if (data.opacity !== undefined) {
21
+ this.opacity = data.opacity;
22
+ }
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/esm/Utils.js ADDED
@@ -0,0 +1,77 @@
1
+ import { drawLine, drawTriangle, getDistance, getDistances, getStyleFromRgb, rangeColorToRgb, } from "@tsparticles/engine";
2
+ export function drawLinkLine(context, width, begin, end, maxDistance, canvasSize, warp, backgroundMask, composite, colorLine, opacity, shadow) {
3
+ let drawn = false;
4
+ if (getDistance(begin, end) <= maxDistance) {
5
+ drawLine(context, begin, end);
6
+ drawn = true;
7
+ }
8
+ else if (warp) {
9
+ let pi1;
10
+ let pi2;
11
+ const endNE = {
12
+ x: end.x - canvasSize.width,
13
+ y: end.y,
14
+ };
15
+ const d1 = getDistances(begin, endNE);
16
+ if (d1.distance <= maxDistance) {
17
+ const yi = begin.y - (d1.dy / d1.dx) * begin.x;
18
+ pi1 = { x: 0, y: yi };
19
+ pi2 = { x: canvasSize.width, y: yi };
20
+ }
21
+ else {
22
+ const endSW = {
23
+ x: end.x,
24
+ y: end.y - canvasSize.height,
25
+ };
26
+ const d2 = getDistances(begin, endSW);
27
+ if (d2.distance <= maxDistance) {
28
+ const yi = begin.y - (d2.dy / d2.dx) * begin.x;
29
+ const xi = -yi / (d2.dy / d2.dx);
30
+ pi1 = { x: xi, y: 0 };
31
+ pi2 = { x: xi, y: canvasSize.height };
32
+ }
33
+ else {
34
+ const endSE = {
35
+ x: end.x - canvasSize.width,
36
+ y: end.y - canvasSize.height,
37
+ };
38
+ const d3 = getDistances(begin, endSE);
39
+ if (d3.distance <= maxDistance) {
40
+ const yi = begin.y - (d3.dy / d3.dx) * begin.x;
41
+ const xi = -yi / (d3.dy / d3.dx);
42
+ pi1 = { x: xi, y: yi };
43
+ pi2 = { x: pi1.x + canvasSize.width, y: pi1.y + canvasSize.height };
44
+ }
45
+ }
46
+ }
47
+ if (pi1 && pi2) {
48
+ drawLine(context, begin, pi1);
49
+ drawLine(context, end, pi2);
50
+ drawn = true;
51
+ }
52
+ }
53
+ if (!drawn) {
54
+ return;
55
+ }
56
+ context.lineWidth = width;
57
+ if (backgroundMask) {
58
+ context.globalCompositeOperation = composite;
59
+ }
60
+ context.strokeStyle = getStyleFromRgb(colorLine, opacity);
61
+ if (shadow.enable) {
62
+ const shadowColor = rangeColorToRgb(shadow.color);
63
+ if (shadowColor) {
64
+ context.shadowBlur = shadow.blur;
65
+ context.shadowColor = getStyleFromRgb(shadowColor);
66
+ }
67
+ }
68
+ context.stroke();
69
+ }
70
+ export function drawLinkTriangle(context, pos1, pos2, pos3, backgroundMask, composite, colorTriangle, opacityTriangle) {
71
+ drawTriangle(context, pos1, pos2, pos3);
72
+ if (backgroundMask) {
73
+ context.globalCompositeOperation = composite;
74
+ }
75
+ context.fillStyle = getStyleFromRgb(colorTriangle, opacityTriangle);
76
+ context.fill();
77
+ }
package/esm/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { loadInteraction } from "./interaction";
2
+ import { loadPlugin } from "./plugin";
3
+ export async function loadParticlesLinksInteraction(engine) {
4
+ await loadInteraction(engine);
5
+ await loadPlugin(engine);
6
+ }
7
+ export * from "./Options/Classes/Links";
8
+ export * from "./Options/Classes/LinksShadow";
9
+ export * from "./Options/Classes/LinksTriangle";
10
+ export * from "./Options/Interfaces/ILinks";
11
+ export * from "./Options/Interfaces/ILinksShadow";
12
+ export * from "./Options/Interfaces/ILinksTriangle";
@@ -0,0 +1,4 @@
1
+ import { Linker } from "./Linker";
2
+ export async function loadInteraction(engine) {
3
+ await engine.addInteractor("particlesLinks", (container) => new Linker(container));
4
+ }
package/esm/plugin.js ADDED
@@ -0,0 +1,18 @@
1
+ import { LinkInstance } from "./LinkInstance";
2
+ class LinksPlugin {
3
+ constructor() {
4
+ this.id = "links";
5
+ }
6
+ getPlugin(container) {
7
+ return new LinkInstance(container);
8
+ }
9
+ loadOptions() {
10
+ }
11
+ needsPlugin() {
12
+ return true;
13
+ }
14
+ }
15
+ export async function loadPlugin(engine) {
16
+ const plugin = new LinksPlugin();
17
+ await engine.addPlugin(plugin);
18
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@tsparticles/interaction-particles-links",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles links particles interaction",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "interactions/particles/links"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin",
64
+ "@tsparticles/interaction"
65
+ ],
66
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "main": "cjs/index.js",
72
+ "jsdelivr": "tsparticles.interaction.particles.links.min.js",
73
+ "unpkg": "tsparticles.interaction.particles.links.min.js",
74
+ "module": "esm/index.js",
75
+ "types": "types/index.d.ts",
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "dependencies": {
80
+ "@tsparticles/engine": "^3.0.0-alpha.0"
81
+ }
82
+ }