@tsparticles/interaction-particles-links 3.0.0-alpha.1 → 3.0.0-beta.1

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 (79) hide show
  1. package/README.md +25 -19
  2. package/browser/CircleWarp.js +7 -23
  3. package/browser/LinkInstance.js +121 -114
  4. package/browser/Linker.js +39 -56
  5. package/browser/Options/Classes/Links.js +2 -2
  6. package/browser/Utils.js +24 -8
  7. package/browser/index.js +11 -11
  8. package/browser/interaction.js +3 -3
  9. package/browser/package.json +1 -0
  10. package/browser/plugin.js +3 -3
  11. package/cjs/CircleWarp.js +7 -23
  12. package/cjs/LinkInstance.js +123 -127
  13. package/cjs/Linker.js +69 -97
  14. package/cjs/Options/Classes/Links.js +4 -4
  15. package/cjs/Utils.js +26 -8
  16. package/cjs/index.js +11 -22
  17. package/cjs/interaction.js +5 -16
  18. package/cjs/package.json +1 -0
  19. package/cjs/plugin.js +7 -18
  20. package/esm/CircleWarp.js +7 -23
  21. package/esm/LinkInstance.js +121 -114
  22. package/esm/Linker.js +39 -56
  23. package/esm/Options/Classes/Links.js +2 -2
  24. package/esm/Utils.js +24 -8
  25. package/esm/index.js +11 -11
  26. package/esm/interaction.js +3 -3
  27. package/esm/package.json +1 -0
  28. package/esm/plugin.js +3 -3
  29. package/package.json +19 -6
  30. package/report.html +4 -4
  31. package/tsparticles.interaction.particles.links.js +244 -204
  32. package/tsparticles.interaction.particles.links.min.js +1 -1
  33. package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +1 -8
  34. package/types/CircleWarp.d.ts +1 -2
  35. package/types/Interfaces.d.ts +22 -0
  36. package/types/LinkInstance.d.ts +7 -8
  37. package/types/Linker.d.ts +3 -7
  38. package/types/Options/Classes/Links.d.ts +4 -5
  39. package/types/Options/Classes/LinksShadow.d.ts +2 -3
  40. package/types/Options/Classes/LinksTriangle.d.ts +2 -3
  41. package/types/Options/Interfaces/ILinks.d.ts +2 -2
  42. package/types/Types.d.ts +47 -0
  43. package/types/Utils.d.ts +5 -4
  44. package/types/index.d.ts +7 -7
  45. package/types/interaction.d.ts +1 -1
  46. package/types/plugin.d.ts +1 -1
  47. package/umd/CircleWarp.js +7 -23
  48. package/umd/LinkInstance.js +121 -114
  49. package/umd/Linker.js +41 -58
  50. package/umd/Options/Classes/Links.js +5 -5
  51. package/umd/Utils.js +26 -8
  52. package/umd/index.js +12 -12
  53. package/umd/interaction.js +6 -6
  54. package/umd/plugin.js +7 -7
  55. package/browser/Options/Interfaces/IParticlesLinkOptions.js +0 -1
  56. package/cjs/LinkParticle.js +0 -2
  57. package/cjs/Options/Classes/ParticlesLinkOptions.js +0 -2
  58. package/cjs/Options/Interfaces/IParticlesLinkOptions.js +0 -2
  59. package/esm/ILink.js +0 -1
  60. package/esm/LinkContainer.js +0 -1
  61. package/esm/LinkParticle.js +0 -1
  62. package/esm/Options/Classes/ParticlesLinkOptions.js +0 -1
  63. package/esm/Options/Interfaces/IParticlesLinkOptions.js +0 -1
  64. package/types/ILink.d.ts +0 -9
  65. package/types/LinkContainer.d.ts +0 -7
  66. package/types/LinkParticle.d.ts +0 -11
  67. package/types/Options/Classes/ParticlesLinkOptions.d.ts +0 -5
  68. package/types/Options/Interfaces/IParticlesLinkOptions.d.ts +0 -7
  69. package/umd/LinkParticle.js +0 -12
  70. package/umd/Options/Classes/ParticlesLinkOptions.js +0 -12
  71. package/umd/Options/Interfaces/IParticlesLinkOptions.js +0 -12
  72. /package/browser/{ILink.js → Interfaces.js} +0 -0
  73. /package/browser/{LinkContainer.js → Types.js} +0 -0
  74. /package/cjs/{ILink.js → Interfaces.js} +0 -0
  75. /package/cjs/{LinkContainer.js → Types.js} +0 -0
  76. /package/{browser/LinkParticle.js → esm/Interfaces.js} +0 -0
  77. /package/{browser/Options/Classes/ParticlesLinkOptions.js → esm/Types.js} +0 -0
  78. /package/umd/{ILink.js → Interfaces.js} +0 -0
  79. /package/umd/{LinkContainer.js → Types.js} +0 -0
@@ -0,0 +1,22 @@
1
+ import type { IRangeColor, RangeValue } from "@tsparticles/engine";
2
+ import type { LinkParticle } from "./Types.js";
3
+ export interface ILink {
4
+ destination: LinkParticle;
5
+ opacity: number;
6
+ }
7
+ export interface ILinkTriangle {
8
+ opacity: number;
9
+ vertices: LinkParticle[];
10
+ }
11
+ export interface IParticlesFrequencies {
12
+ links: Map<string, number>;
13
+ triangles: Map<string, number>;
14
+ }
15
+ export interface ITwinkle {
16
+ lines: {
17
+ color: IRangeColor;
18
+ enable: boolean;
19
+ frequency: number;
20
+ opacity: RangeValue;
21
+ };
22
+ }
@@ -1,6 +1,5 @@
1
- import type { IContainerPlugin } from "@tsparticles/engine";
2
- import type { LinkContainer } from "./LinkContainer";
3
- import type { LinkParticle } from "./LinkParticle";
1
+ import { type IContainerPlugin } from "@tsparticles/engine";
2
+ import type { LinkContainer, LinkParticle } from "./Types.js";
4
3
  export declare class LinkInstance implements IContainerPlugin {
5
4
  private readonly container;
6
5
  private readonly _freqs;
@@ -9,9 +8,9 @@ export declare class LinkInstance implements IContainerPlugin {
9
8
  init(): Promise<void>;
10
9
  particleCreated(particle: LinkParticle): void;
11
10
  particleDestroyed(particle: LinkParticle): void;
12
- private drawLinkLine;
13
- private drawLinkTriangle;
14
- private drawTriangles;
15
- private getLinkFrequency;
16
- private getTriangleFrequency;
11
+ private readonly _drawLinkLine;
12
+ private readonly _drawLinkTriangle;
13
+ private readonly _drawTriangles;
14
+ private readonly _getLinkFrequency;
15
+ private readonly _getTriangleFrequency;
17
16
  }
package/types/Linker.d.ts CHANGED
@@ -1,9 +1,5 @@
1
- import { ParticlesInteractorBase } from "@tsparticles/engine";
2
- import type { RecursivePartial } from "@tsparticles/engine";
3
- import type { IParticlesLinkOptions } from "./Options/Interfaces/IParticlesLinkOptions";
4
- import type { LinkContainer } from "./LinkContainer";
5
- import type { LinkParticle } from "./LinkParticle";
6
- import type { ParticlesLinkOptions } from "./Options/Classes/ParticlesLinkOptions";
1
+ import { ParticlesInteractorBase, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { IParticlesLinkOptions, LinkContainer, LinkParticle, ParticlesLinkOptions } from "./Types.js";
7
3
  export declare class Linker extends ParticlesInteractorBase {
8
4
  linkContainer: LinkContainer;
9
5
  constructor(container: LinkContainer);
@@ -13,5 +9,5 @@ export declare class Linker extends ParticlesInteractorBase {
13
9
  isEnabled(particle: LinkParticle): boolean;
14
10
  loadParticlesOptions(options: ParticlesLinkOptions, ...sources: (RecursivePartial<IParticlesLinkOptions> | undefined)[]): void;
15
11
  reset(): void;
16
- private setColor;
12
+ private readonly _setColor;
17
13
  }
@@ -1,8 +1,7 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
- import type { ILinks } from "../Interfaces/ILinks";
3
- import { LinksShadow } from "./LinksShadow";
4
- import { LinksTriangle } from "./LinksTriangle";
5
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { ILinks } from "../Interfaces/ILinks.js";
3
+ import { LinksShadow } from "./LinksShadow.js";
4
+ import { LinksTriangle } from "./LinksTriangle.js";
6
5
  export declare class Links implements ILinks, IOptionLoader<ILinks> {
7
6
  blink: boolean;
8
7
  color: OptionsColor;
@@ -1,6 +1,5 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
- import type { ILinksShadow } from "../Interfaces/ILinksShadow";
3
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { ILinksShadow } from "../Interfaces/ILinksShadow.js";
4
3
  export declare class LinksShadow implements ILinksShadow, IOptionLoader<ILinksShadow> {
5
4
  blur: number;
6
5
  color: OptionsColor;
@@ -1,6 +1,5 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
- import type { ILinksTriangle } from "../Interfaces/ILinksTriangle";
3
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { ILinksTriangle } from "../Interfaces/ILinksTriangle.js";
4
3
  export declare class LinksTriangle implements ILinksTriangle, IOptionLoader<ILinksTriangle> {
5
4
  color?: OptionsColor;
6
5
  enable: boolean;
@@ -1,5 +1,5 @@
1
- import type { ILinksShadow } from "./ILinksShadow";
2
- import type { ILinksTriangle } from "./ILinksTriangle";
1
+ import type { ILinksShadow } from "./ILinksShadow.js";
2
+ import type { ILinksTriangle } from "./ILinksTriangle.js";
3
3
  import type { IOptionsColor } from "@tsparticles/engine";
4
4
  export interface ILinks {
5
5
  blink: boolean;
@@ -0,0 +1,47 @@
1
+ import type { BackgroundMask, Container, ICoordinates, IDimension, IParticlesOptions, IRgb, Particle, ParticlesOptions } from "@tsparticles/engine";
2
+ import type { ILink } from "./Interfaces.js";
3
+ import type { ILinks } from "./Options/Interfaces/ILinks.js";
4
+ import type { Links } from "./Options/Classes/Links.js";
5
+ export type LinkContainer = Container & {
6
+ particles: {
7
+ linksColor?: IRgb | string;
8
+ linksColors: Map<string, IRgb | string | undefined>;
9
+ };
10
+ };
11
+ export type LinkParticle = Particle & {
12
+ links?: ILink[];
13
+ options: ParticlesLinkOptions;
14
+ retina: {
15
+ linksDistance?: number;
16
+ linksWidth?: number;
17
+ };
18
+ };
19
+ export type LinkLineDrawParams = {
20
+ backgroundMask: BackgroundMask;
21
+ begin: ICoordinates;
22
+ canvasSize: IDimension;
23
+ colorLine: IRgb;
24
+ context: CanvasRenderingContext2D;
25
+ end: ICoordinates;
26
+ links: Links;
27
+ maxDistance: number;
28
+ opacity: number;
29
+ width: number;
30
+ };
31
+ export type LinkTriangleDrawParams = {
32
+ backgroundMask: BackgroundMask;
33
+ colorTriangle: IRgb;
34
+ context: CanvasRenderingContext2D;
35
+ opacityTriangle: number;
36
+ pos1: ICoordinates;
37
+ pos2: ICoordinates;
38
+ pos3: ICoordinates;
39
+ };
40
+ export type IParticlesLinkOptions = IParticlesOptions & {
41
+ lineLinked?: ILinks;
42
+ line_linked?: ILinks;
43
+ links?: ILinks;
44
+ };
45
+ export type ParticlesLinkOptions = ParticlesOptions & {
46
+ links?: Links;
47
+ };
package/types/Utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { ICoordinates, IDimension, IRgb } from "@tsparticles/engine";
2
- import type { ILinksShadow } from "./Options/Interfaces/ILinksShadow";
3
- export declare function drawLinkLine(context: CanvasRenderingContext2D, width: number, begin: ICoordinates, end: ICoordinates, maxDistance: number, canvasSize: IDimension, warp: boolean, backgroundMask: boolean, composite: GlobalCompositeOperation, colorLine: IRgb, opacity: number, shadow: ILinksShadow): void;
4
- export declare function drawLinkTriangle(context: CanvasRenderingContext2D, pos1: ICoordinates, pos2: ICoordinates, pos3: ICoordinates, backgroundMask: boolean, composite: GlobalCompositeOperation, colorTriangle: IRgb, opacityTriangle: number): void;
1
+ import type { LinkLineDrawParams, LinkParticle, LinkTriangleDrawParams } from "./Types.js";
2
+ export declare function drawLinkLine(params: LinkLineDrawParams): void;
3
+ export declare function drawLinkTriangle(params: LinkTriangleDrawParams): void;
4
+ export declare function getLinkKey(ids: number[]): string;
5
+ export declare function setLinkFrequency(particles: LinkParticle[], dictionary: Map<string, number>): number;
package/types/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadParticlesLinksInteraction(engine: Engine): Promise<void>;
3
- export * from "./Options/Classes/Links";
4
- export * from "./Options/Classes/LinksShadow";
5
- export * from "./Options/Classes/LinksTriangle";
6
- export * from "./Options/Interfaces/ILinks";
7
- export * from "./Options/Interfaces/ILinksShadow";
8
- export * from "./Options/Interfaces/ILinksTriangle";
2
+ export declare function loadParticlesLinksInteraction(engine: Engine, refresh?: boolean): Promise<void>;
3
+ export * from "./Options/Classes/Links.js";
4
+ export * from "./Options/Classes/LinksShadow.js";
5
+ export * from "./Options/Classes/LinksTriangle.js";
6
+ export * from "./Options/Interfaces/ILinks.js";
7
+ export * from "./Options/Interfaces/ILinksShadow.js";
8
+ export * from "./Options/Interfaces/ILinksTriangle.js";
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadInteraction(engine: Engine): Promise<void>;
2
+ export declare function loadLinksInteraction(engine: Engine, refresh?: boolean): Promise<void>;
package/types/plugin.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadPlugin(engine: Engine): Promise<void>;
2
+ export declare function loadLinksPlugin(engine: Engine, refresh?: boolean): Promise<void>;
package/umd/CircleWarp.js CHANGED
@@ -15,31 +15,15 @@
15
15
  constructor(x, y, radius, canvasSize) {
16
16
  super(x, y, radius);
17
17
  this.canvasSize = canvasSize;
18
- this.canvasSize = Object.assign({}, canvasSize);
18
+ this.canvasSize = { ...canvasSize };
19
19
  }
20
20
  contains(point) {
21
- if (super.contains(point)) {
22
- return true;
23
- }
24
- const posNE = {
25
- x: point.x - this.canvasSize.width,
26
- y: point.y,
27
- };
28
- if (super.contains(posNE)) {
29
- return true;
30
- }
31
- const posSE = {
32
- x: point.x - this.canvasSize.width,
33
- y: point.y - this.canvasSize.height,
34
- };
35
- if (super.contains(posSE)) {
36
- return true;
37
- }
38
- const posSW = {
39
- x: point.x,
40
- y: point.y - this.canvasSize.height,
41
- };
42
- return super.contains(posSW);
21
+ const { width, height } = this.canvasSize;
22
+ const { x, y } = point;
23
+ return (super.contains(point) ||
24
+ super.contains({ x: x - width, y }) ||
25
+ super.contains({ x: x - width, y: y - height }) ||
26
+ super.contains({ x, y: y - height }));
43
27
  }
44
28
  intersects(range) {
45
29
  if (super.intersects(range)) {
@@ -4,46 +4,142 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./Utils", "@tsparticles/engine"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Utils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.LinkInstance = void 0;
13
- const Utils_1 = require("./Utils");
14
13
  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
- }
14
+ const Utils_js_1 = require("./Utils.js");
28
15
  class LinkInstance {
29
16
  constructor(container) {
30
17
  this.container = container;
18
+ this._drawLinkLine = (p1, link) => {
19
+ const p1LinksOptions = p1.options.links;
20
+ if (!p1LinksOptions?.enable) {
21
+ return;
22
+ }
23
+ const container = this.container, options = container.actualOptions, 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)(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 ?? 0, maxDistance = p1.retina.linksDistance ?? 0, { backgroundMask } = options;
45
+ (0, Utils_js_1.drawLinkLine)({
46
+ context: ctx,
47
+ width,
48
+ begin: pos1,
49
+ end: pos2,
50
+ maxDistance,
51
+ canvasSize: container.canvas.size,
52
+ links: p1LinksOptions,
53
+ backgroundMask: backgroundMask,
54
+ colorLine,
55
+ opacity,
56
+ });
57
+ });
58
+ };
59
+ this._drawLinkTriangle = (p1, link1, link2) => {
60
+ const linksOptions = p1.options.links;
61
+ if (!linksOptions?.enable) {
62
+ return;
63
+ }
64
+ const triangleOptions = linksOptions.triangles;
65
+ if (!triangleOptions.enable) {
66
+ return;
67
+ }
68
+ const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) / 2;
69
+ if (opacityTriangle <= 0) {
70
+ return;
71
+ }
72
+ container.canvas.draw((ctx) => {
73
+ const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? 0;
74
+ if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
75
+ (0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
76
+ (0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
77
+ return;
78
+ }
79
+ let colorTriangle = (0, engine_1.rangeColorToRgb)(triangleOptions.color);
80
+ if (!colorTriangle) {
81
+ const linkColor = linksOptions.id !== undefined
82
+ ? container.particles.linksColors.get(linksOptions.id)
83
+ : container.particles.linksColor;
84
+ colorTriangle = (0, engine_1.getLinkColor)(p1, p2, linkColor);
85
+ }
86
+ if (!colorTriangle) {
87
+ return;
88
+ }
89
+ (0, Utils_js_1.drawLinkTriangle)({
90
+ context: ctx,
91
+ pos1,
92
+ pos2,
93
+ pos3,
94
+ backgroundMask: options.backgroundMask,
95
+ colorTriangle,
96
+ opacityTriangle,
97
+ });
98
+ });
99
+ };
100
+ this._drawTriangles = (options, p1, link, p1Links) => {
101
+ const p2 = link.destination;
102
+ if (!(options.links?.triangles.enable && p2.options.links?.triangles.enable)) {
103
+ return;
104
+ }
105
+ const vertices = p2.links?.filter((t) => {
106
+ const linkFreq = this._getLinkFrequency(p2, t.destination);
107
+ return (p2.options.links &&
108
+ linkFreq <= p2.options.links.frequency &&
109
+ p1Links.findIndex((l) => l.destination === t.destination) >= 0);
110
+ });
111
+ if (!vertices?.length) {
112
+ return;
113
+ }
114
+ for (const vertex of vertices) {
115
+ const p3 = vertex.destination, triangleFreq = this._getTriangleFrequency(p1, p2, p3);
116
+ if (triangleFreq > options.links.triangles.frequency) {
117
+ continue;
118
+ }
119
+ this._drawLinkTriangle(p1, link, vertex);
120
+ }
121
+ };
122
+ this._getLinkFrequency = (p1, p2) => {
123
+ return (0, Utils_js_1.setLinkFrequency)([p1, p2], this._freqs.links);
124
+ };
125
+ this._getTriangleFrequency = (p1, p2, p3) => {
126
+ return (0, Utils_js_1.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);
127
+ };
31
128
  this._freqs = {
32
129
  links: new Map(),
33
130
  triangles: new Map(),
34
131
  };
35
132
  }
36
133
  drawParticle(context, particle) {
37
- var _a;
38
- const pOptions = particle.options;
39
- if (!particle.links || particle.links.length <= 0) {
134
+ const { links, options } = particle;
135
+ if (!links || links.length <= 0) {
40
136
  return;
41
137
  }
42
- const p1Links = particle.links.filter((l) => pOptions.links && this.getLinkFrequency(particle, l.destination) <= pOptions.links.frequency);
138
+ const p1Links = links.filter((l) => options.links && this._getLinkFrequency(particle, l.destination) <= options.links.frequency);
43
139
  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);
140
+ this._drawTriangles(options, particle, link, p1Links);
141
+ if (link.opacity > 0 && (particle.retina.linksWidth ?? 0) > 0) {
142
+ this._drawLinkLine(particle, link);
47
143
  }
48
144
  }
49
145
  }
@@ -56,102 +152,13 @@
56
152
  if (!particle.options.links) {
57
153
  return;
58
154
  }
59
- const ratio = this.container.retina.pixelRatio;
60
- particle.retina.linksDistance = particle.options.links.distance * ratio;
61
- particle.retina.linksWidth = particle.options.links.width * ratio;
155
+ const ratio = this.container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
156
+ retina.linksDistance = distance * ratio;
157
+ retina.linksWidth = width * ratio;
62
158
  }
63
159
  particleDestroyed(particle) {
64
160
  particle.links = [];
65
161
  }
66
- drawLinkLine(p1, link) {
67
- const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
68
- let opacity = link.opacity;
69
- container.canvas.draw((ctx) => {
70
- var _a, _b, _c;
71
- if (!p1.options.links) {
72
- return;
73
- }
74
- let colorLine;
75
- const twinkle = (_a = p1.options.twinkle) === null || _a === void 0 ? void 0 : _a.lines;
76
- if (twinkle === null || twinkle === void 0 ? void 0 : twinkle.enable) {
77
- const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
78
- if (twinkling && twinkleRgb) {
79
- colorLine = twinkleRgb;
80
- opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
81
- }
82
- }
83
- if (!colorLine) {
84
- const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
85
- ? container.particles.linksColors.get(linksOptions.id)
86
- : container.particles.linksColor;
87
- colorLine = (0, engine_1.getLinkColor)(p1, p2, linkColor);
88
- }
89
- if (!colorLine) {
90
- return;
91
- }
92
- const width = (_b = p1.retina.linksWidth) !== null && _b !== void 0 ? _b : 0, maxDistance = (_c = p1.retina.linksDistance) !== null && _c !== void 0 ? _c : 0;
93
- (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);
94
- });
95
- }
96
- drawLinkTriangle(p1, link1, link2) {
97
- var _a;
98
- if (!p1.options.links) {
99
- return;
100
- }
101
- 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;
102
- if (opacityTriangle <= 0) {
103
- return;
104
- }
105
- container.canvas.draw((ctx) => {
106
- var _a;
107
- const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0;
108
- if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
109
- (0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
110
- (0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
111
- return;
112
- }
113
- let colorTriangle = (0, engine_1.rangeColorToRgb)(triangleOptions.color);
114
- if (!colorTriangle) {
115
- const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
116
- ? container.particles.linksColors.get(linksOptions.id)
117
- : container.particles.linksColor;
118
- colorTriangle = (0, engine_1.getLinkColor)(p1, p2, linkColor);
119
- }
120
- if (!colorTriangle) {
121
- return;
122
- }
123
- (0, Utils_1.drawLinkTriangle)(ctx, pos1, pos2, pos3, options.backgroundMask.enable, options.backgroundMask.composite, colorTriangle, opacityTriangle);
124
- });
125
- }
126
- drawTriangles(options, p1, link, p1Links) {
127
- var _a, _b, _c;
128
- const p2 = link.destination;
129
- 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))) {
130
- return;
131
- }
132
- const vertices = (_c = p2.links) === null || _c === void 0 ? void 0 : _c.filter((t) => {
133
- const linkFreq = this.getLinkFrequency(p2, t.destination);
134
- return (p2.options.links &&
135
- linkFreq <= p2.options.links.frequency &&
136
- p1Links.findIndex((l) => l.destination === t.destination) >= 0);
137
- });
138
- if (!(vertices === null || vertices === void 0 ? void 0 : vertices.length)) {
139
- return;
140
- }
141
- for (const vertex of vertices) {
142
- const p3 = vertex.destination, triangleFreq = this.getTriangleFrequency(p1, p2, p3);
143
- if (triangleFreq > options.links.triangles.frequency) {
144
- continue;
145
- }
146
- this.drawLinkTriangle(p1, link, vertex);
147
- }
148
- }
149
- getLinkFrequency(p1, p2) {
150
- return setLinkFrequency([p1, p2], this._freqs.links);
151
- }
152
- getTriangleFrequency(p1, p2, p3) {
153
- return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
154
- }
155
162
  }
156
163
  exports.LinkInstance = LinkInstance;
157
164
  });