@tsparticles/interaction-particles-links 3.6.0-beta.1 → 3.7.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 (50) hide show
  1. package/browser/LinkInstance.js +9 -7
  2. package/browser/Linker.js +7 -6
  3. package/browser/LinksPlugin.js +3 -2
  4. package/browser/Options/Classes/Links.js +2 -2
  5. package/browser/Options/Classes/LinksShadow.js +2 -2
  6. package/browser/Options/Classes/LinksTriangle.js +2 -2
  7. package/browser/Utils.js +2 -2
  8. package/browser/index.js +2 -0
  9. package/browser/interaction.js +1 -1
  10. package/browser/plugin.js +1 -1
  11. package/cjs/LinkInstance.js +9 -7
  12. package/cjs/Linker.js +7 -6
  13. package/cjs/LinksPlugin.js +3 -2
  14. package/cjs/Options/Classes/Links.js +1 -1
  15. package/cjs/Options/Classes/LinksShadow.js +1 -1
  16. package/cjs/Options/Classes/LinksTriangle.js +1 -1
  17. package/cjs/Utils.js +2 -2
  18. package/cjs/index.js +2 -0
  19. package/cjs/interaction.js +1 -1
  20. package/cjs/plugin.js +1 -1
  21. package/esm/LinkInstance.js +9 -7
  22. package/esm/Linker.js +7 -6
  23. package/esm/LinksPlugin.js +3 -2
  24. package/esm/Options/Classes/Links.js +2 -2
  25. package/esm/Options/Classes/LinksShadow.js +2 -2
  26. package/esm/Options/Classes/LinksTriangle.js +2 -2
  27. package/esm/Utils.js +2 -2
  28. package/esm/index.js +2 -0
  29. package/esm/interaction.js +1 -1
  30. package/esm/plugin.js +1 -1
  31. package/package.json +2 -2
  32. package/report.html +1 -1
  33. package/tsparticles.interaction.particles.links.js +11 -11
  34. package/tsparticles.interaction.particles.links.min.js +1 -1
  35. package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +1 -1
  36. package/types/LinkInstance.d.ts +4 -3
  37. package/types/Linker.d.ts +4 -3
  38. package/types/LinksPlugin.d.ts +3 -2
  39. package/types/Types.d.ts +2 -1
  40. package/types/index.d.ts +1 -1
  41. package/umd/LinkInstance.js +9 -7
  42. package/umd/Linker.js +7 -6
  43. package/umd/LinksPlugin.js +3 -2
  44. package/umd/Options/Classes/Links.js +1 -1
  45. package/umd/Options/Classes/LinksShadow.js +1 -1
  46. package/umd/Options/Classes/LinksTriangle.js +1 -1
  47. package/umd/Utils.js +2 -2
  48. package/umd/index.js +3 -1
  49. package/umd/interaction.js +1 -1
  50. package/umd/plugin.js +1 -1
@@ -2,20 +2,19 @@ import { getDistance, getLinkColor, getRandom, getRangeValue, rangeColorToRgb, }
2
2
  import { drawLinkLine, drawLinkTriangle, setLinkFrequency } from "./Utils.js";
3
3
  const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5, maxFrequency = 1;
4
4
  export class LinkInstance {
5
- constructor(container) {
6
- this.container = container;
5
+ constructor(container, engine) {
7
6
  this._drawLinkLine = (p1, link) => {
8
7
  const p1LinksOptions = p1.options.links;
9
8
  if (!p1LinksOptions?.enable) {
10
9
  return;
11
10
  }
12
- const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
11
+ const container = this._container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
13
12
  let opacity = link.opacity;
14
13
  container.canvas.draw(ctx => {
15
14
  let colorLine;
16
15
  const twinkle = p1.options.twinkle?.lines;
17
16
  if (twinkle?.enable) {
18
- const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(twinkle.color), twinkling = getRandom() < twinkleFreq;
17
+ const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(this._engine, twinkle.color), twinkling = getRandom() < twinkleFreq;
19
18
  if (twinkling && twinkleRgb) {
20
19
  colorLine = twinkleRgb;
21
20
  opacity = getRangeValue(twinkle.opacity);
@@ -36,6 +35,7 @@ export class LinkInstance {
36
35
  width,
37
36
  begin: pos1,
38
37
  end: pos2,
38
+ engine: this._engine,
39
39
  maxDistance,
40
40
  canvasSize: container.canvas.size,
41
41
  links: p1LinksOptions,
@@ -54,7 +54,7 @@ export class LinkInstance {
54
54
  if (!triangleOptions.enable) {
55
55
  return;
56
56
  }
57
- const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
57
+ const container = this._container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
58
58
  if (opacityTriangle <= minOpacity) {
59
59
  return;
60
60
  }
@@ -65,7 +65,7 @@ export class LinkInstance {
65
65
  getDistance(pos3, pos1) > linksDistance) {
66
66
  return;
67
67
  }
68
- let colorTriangle = rangeColorToRgb(triangleOptions.color);
68
+ let colorTriangle = rangeColorToRgb(this._engine, triangleOptions.color);
69
69
  if (!colorTriangle) {
70
70
  const linkColor = linksOptions.id !== undefined
71
71
  ? container.particles.linksColors.get(linksOptions.id)
@@ -114,6 +114,8 @@ export class LinkInstance {
114
114
  this._getTriangleFrequency = (p1, p2, p3) => {
115
115
  return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
116
116
  };
117
+ this._container = container;
118
+ this._engine = engine;
117
119
  this._freqs = {
118
120
  links: new Map(),
119
121
  triangles: new Map(),
@@ -144,7 +146,7 @@ export class LinkInstance {
144
146
  if (!particle.options.links) {
145
147
  return;
146
148
  }
147
- const ratio = this.container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
149
+ const ratio = this._container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
148
150
  retina.linksDistance = distance * ratio;
149
151
  retina.linksWidth = width * ratio;
150
152
  }
package/browser/Linker.js CHANGED
@@ -20,13 +20,13 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
20
20
  return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
21
21
  }
22
22
  export class Linker extends ParticlesInteractorBase {
23
- constructor(container) {
23
+ constructor(container, engine) {
24
24
  super(container);
25
25
  this._setColor = p1 => {
26
26
  if (!p1.options.links) {
27
27
  return;
28
28
  }
29
- const container = this.linkContainer, linksOptions = p1.options.links;
29
+ const container = this._linkContainer, linksOptions = p1.options.links;
30
30
  let linkColor = linksOptions.id === undefined
31
31
  ? container.particles.linksColor
32
32
  : container.particles.linksColors.get(linksOptions.id);
@@ -34,7 +34,7 @@ export class Linker extends ParticlesInteractorBase {
34
34
  return;
35
35
  }
36
36
  const optColor = linksOptions.color;
37
- linkColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
37
+ linkColor = getLinkRandomColor(this._engine, optColor, linksOptions.blink, linksOptions.consent);
38
38
  if (linksOptions.id === undefined) {
39
39
  container.particles.linksColor = linkColor;
40
40
  }
@@ -42,13 +42,14 @@ export class Linker extends ParticlesInteractorBase {
42
42
  container.particles.linksColors.set(linksOptions.id, linkColor);
43
43
  }
44
44
  };
45
- this.linkContainer = container;
45
+ this._linkContainer = container;
46
+ this._engine = engine;
46
47
  }
47
48
  clear() {
48
49
  }
49
50
  init() {
50
- this.linkContainer.particles.linksColor = undefined;
51
- this.linkContainer.particles.linksColors = new Map();
51
+ this._linkContainer.particles.linksColor = undefined;
52
+ this._linkContainer.particles.linksColors = new Map();
52
53
  }
53
54
  interact(p1) {
54
55
  if (!p1.options.links) {
@@ -1,10 +1,11 @@
1
1
  import { LinkInstance } from "./LinkInstance.js";
2
2
  export class LinksPlugin {
3
- constructor() {
3
+ constructor(engine) {
4
4
  this.id = "links";
5
+ this._engine = engine;
5
6
  }
6
7
  getPlugin(container) {
7
- return Promise.resolve(new LinkInstance(container));
8
+ return Promise.resolve(new LinkInstance(container, this._engine));
8
9
  }
9
10
  loadOptions() {
10
11
  }
@@ -1,4 +1,4 @@
1
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
2
  import { LinksShadow } from "./LinksShadow.js";
3
3
  import { LinksTriangle } from "./LinksTriangle.js";
4
4
  export class Links {
@@ -17,7 +17,7 @@ export class Links {
17
17
  this.warp = false;
18
18
  }
19
19
  load(data) {
20
- if (!data) {
20
+ if (isNull(data)) {
21
21
  return;
22
22
  }
23
23
  if (data.id !== undefined) {
@@ -1,4 +1,4 @@
1
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
2
  export class LinksShadow {
3
3
  constructor() {
4
4
  this.blur = 5;
@@ -7,7 +7,7 @@ export class LinksShadow {
7
7
  this.enable = false;
8
8
  }
9
9
  load(data) {
10
- if (!data) {
10
+ if (isNull(data)) {
11
11
  return;
12
12
  }
13
13
  if (data.blur !== undefined) {
@@ -1,11 +1,11 @@
1
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
2
  export class LinksTriangle {
3
3
  constructor() {
4
4
  this.enable = false;
5
5
  this.frequency = 1;
6
6
  }
7
7
  load(data) {
8
- if (!data) {
8
+ if (isNull(data)) {
9
9
  return;
10
10
  }
11
11
  if (data.color !== undefined) {
package/browser/Utils.js CHANGED
@@ -8,7 +8,7 @@ export function drawTriangle(context, p1, p2, p3) {
8
8
  }
9
9
  export function drawLinkLine(params) {
10
10
  let drawn = false;
11
- const { begin, end, maxDistance, context, canvasSize, width, backgroundMask, colorLine, opacity, links } = params;
11
+ const { begin, end, engine, maxDistance, context, canvasSize, width, backgroundMask, colorLine, opacity, links } = params;
12
12
  if (getDistance(begin, end) <= maxDistance) {
13
13
  drawLine(context, begin, end);
14
14
  drawn = true;
@@ -68,7 +68,7 @@ export function drawLinkLine(params) {
68
68
  context.strokeStyle = getStyleFromRgb(colorLine, opacity);
69
69
  const { shadow } = links;
70
70
  if (shadow.enable) {
71
- const shadowColor = rangeColorToRgb(shadow.color);
71
+ const shadowColor = rangeColorToRgb(engine, shadow.color);
72
72
  if (shadowColor) {
73
73
  context.shadowBlur = shadow.blur;
74
74
  context.shadowColor = getStyleFromRgb(shadowColor);
package/browser/index.js CHANGED
@@ -1,6 +1,8 @@
1
+ import { assertValidVersion } from "@tsparticles/engine";
1
2
  import { loadLinksInteraction } from "./interaction.js";
2
3
  import { loadLinksPlugin } from "./plugin.js";
3
4
  export async function loadParticlesLinksInteraction(engine, refresh = true) {
5
+ assertValidVersion(engine, "3.7.0");
4
6
  await loadLinksInteraction(engine, refresh);
5
7
  await loadLinksPlugin(engine, refresh);
6
8
  }
@@ -1,6 +1,6 @@
1
1
  import { Linker } from "./Linker.js";
2
2
  export async function loadLinksInteraction(engine, refresh = true) {
3
3
  await engine.addInteractor("particlesLinks", async (container) => {
4
- return Promise.resolve(new Linker(container));
4
+ return Promise.resolve(new Linker(container, engine));
5
5
  }, refresh);
6
6
  }
package/browser/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LinksPlugin } from "./LinksPlugin.js";
2
2
  export async function loadLinksPlugin(engine, refresh = true) {
3
- const plugin = new LinksPlugin();
3
+ const plugin = new LinksPlugin(engine);
4
4
  await engine.addPlugin(plugin, refresh);
5
5
  }
@@ -5,20 +5,19 @@ const engine_1 = require("@tsparticles/engine");
5
5
  const Utils_js_1 = require("./Utils.js");
6
6
  const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5, maxFrequency = 1;
7
7
  class LinkInstance {
8
- constructor(container) {
9
- this.container = container;
8
+ constructor(container, engine) {
10
9
  this._drawLinkLine = (p1, link) => {
11
10
  const p1LinksOptions = p1.options.links;
12
11
  if (!p1LinksOptions?.enable) {
13
12
  return;
14
13
  }
15
- const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
14
+ const container = this._container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
16
15
  let opacity = link.opacity;
17
16
  container.canvas.draw(ctx => {
18
17
  let colorLine;
19
18
  const twinkle = p1.options.twinkle?.lines;
20
19
  if (twinkle?.enable) {
21
- const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
20
+ const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(this._engine, twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
22
21
  if (twinkling && twinkleRgb) {
23
22
  colorLine = twinkleRgb;
24
23
  opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
@@ -39,6 +38,7 @@ class LinkInstance {
39
38
  width,
40
39
  begin: pos1,
41
40
  end: pos2,
41
+ engine: this._engine,
42
42
  maxDistance,
43
43
  canvasSize: container.canvas.size,
44
44
  links: p1LinksOptions,
@@ -57,7 +57,7 @@ class LinkInstance {
57
57
  if (!triangleOptions.enable) {
58
58
  return;
59
59
  }
60
- const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
60
+ const container = this._container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
61
61
  if (opacityTriangle <= minOpacity) {
62
62
  return;
63
63
  }
@@ -68,7 +68,7 @@ class LinkInstance {
68
68
  (0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
69
69
  return;
70
70
  }
71
- let colorTriangle = (0, engine_1.rangeColorToRgb)(triangleOptions.color);
71
+ let colorTriangle = (0, engine_1.rangeColorToRgb)(this._engine, triangleOptions.color);
72
72
  if (!colorTriangle) {
73
73
  const linkColor = linksOptions.id !== undefined
74
74
  ? container.particles.linksColors.get(linksOptions.id)
@@ -117,6 +117,8 @@ class LinkInstance {
117
117
  this._getTriangleFrequency = (p1, p2, p3) => {
118
118
  return (0, Utils_js_1.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);
119
119
  };
120
+ this._container = container;
121
+ this._engine = engine;
120
122
  this._freqs = {
121
123
  links: new Map(),
122
124
  triangles: new Map(),
@@ -147,7 +149,7 @@ class LinkInstance {
147
149
  if (!particle.options.links) {
148
150
  return;
149
151
  }
150
- const ratio = this.container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
152
+ const ratio = this._container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
151
153
  retina.linksDistance = distance * ratio;
152
154
  retina.linksWidth = width * ratio;
153
155
  }
package/cjs/Linker.js CHANGED
@@ -23,13 +23,13 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
23
23
  return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
24
24
  }
25
25
  class Linker extends engine_1.ParticlesInteractorBase {
26
- constructor(container) {
26
+ constructor(container, engine) {
27
27
  super(container);
28
28
  this._setColor = p1 => {
29
29
  if (!p1.options.links) {
30
30
  return;
31
31
  }
32
- const container = this.linkContainer, linksOptions = p1.options.links;
32
+ const container = this._linkContainer, linksOptions = p1.options.links;
33
33
  let linkColor = linksOptions.id === undefined
34
34
  ? container.particles.linksColor
35
35
  : container.particles.linksColors.get(linksOptions.id);
@@ -37,7 +37,7 @@ class Linker extends engine_1.ParticlesInteractorBase {
37
37
  return;
38
38
  }
39
39
  const optColor = linksOptions.color;
40
- linkColor = (0, engine_1.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
40
+ linkColor = (0, engine_1.getLinkRandomColor)(this._engine, optColor, linksOptions.blink, linksOptions.consent);
41
41
  if (linksOptions.id === undefined) {
42
42
  container.particles.linksColor = linkColor;
43
43
  }
@@ -45,13 +45,14 @@ class Linker extends engine_1.ParticlesInteractorBase {
45
45
  container.particles.linksColors.set(linksOptions.id, linkColor);
46
46
  }
47
47
  };
48
- this.linkContainer = container;
48
+ this._linkContainer = container;
49
+ this._engine = engine;
49
50
  }
50
51
  clear() {
51
52
  }
52
53
  init() {
53
- this.linkContainer.particles.linksColor = undefined;
54
- this.linkContainer.particles.linksColors = new Map();
54
+ this._linkContainer.particles.linksColor = undefined;
55
+ this._linkContainer.particles.linksColors = new Map();
55
56
  }
56
57
  interact(p1) {
57
58
  if (!p1.options.links) {
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinksPlugin = void 0;
4
4
  const LinkInstance_js_1 = require("./LinkInstance.js");
5
5
  class LinksPlugin {
6
- constructor() {
6
+ constructor(engine) {
7
7
  this.id = "links";
8
+ this._engine = engine;
8
9
  }
9
10
  getPlugin(container) {
10
- return Promise.resolve(new LinkInstance_js_1.LinkInstance(container));
11
+ return Promise.resolve(new LinkInstance_js_1.LinkInstance(container, this._engine));
11
12
  }
12
13
  loadOptions() {
13
14
  }
@@ -20,7 +20,7 @@ class Links {
20
20
  this.warp = false;
21
21
  }
22
22
  load(data) {
23
- if (!data) {
23
+ if ((0, engine_1.isNull)(data)) {
24
24
  return;
25
25
  }
26
26
  if (data.id !== undefined) {
@@ -10,7 +10,7 @@ class LinksShadow {
10
10
  this.enable = false;
11
11
  }
12
12
  load(data) {
13
- if (!data) {
13
+ if ((0, engine_1.isNull)(data)) {
14
14
  return;
15
15
  }
16
16
  if (data.blur !== undefined) {
@@ -8,7 +8,7 @@ class LinksTriangle {
8
8
  this.frequency = 1;
9
9
  }
10
10
  load(data) {
11
- if (!data) {
11
+ if ((0, engine_1.isNull)(data)) {
12
12
  return;
13
13
  }
14
14
  if (data.color !== undefined) {
package/cjs/Utils.js CHANGED
@@ -15,7 +15,7 @@ function drawTriangle(context, p1, p2, p3) {
15
15
  }
16
16
  function drawLinkLine(params) {
17
17
  let drawn = false;
18
- const { begin, end, maxDistance, context, canvasSize, width, backgroundMask, colorLine, opacity, links } = params;
18
+ const { begin, end, engine, maxDistance, context, canvasSize, width, backgroundMask, colorLine, opacity, links } = params;
19
19
  if ((0, engine_1.getDistance)(begin, end) <= maxDistance) {
20
20
  (0, engine_1.drawLine)(context, begin, end);
21
21
  drawn = true;
@@ -75,7 +75,7 @@ function drawLinkLine(params) {
75
75
  context.strokeStyle = (0, engine_1.getStyleFromRgb)(colorLine, opacity);
76
76
  const { shadow } = links;
77
77
  if (shadow.enable) {
78
- const shadowColor = (0, engine_1.rangeColorToRgb)(shadow.color);
78
+ const shadowColor = (0, engine_1.rangeColorToRgb)(engine, shadow.color);
79
79
  if (shadowColor) {
80
80
  context.shadowBlur = shadow.blur;
81
81
  context.shadowColor = (0, engine_1.getStyleFromRgb)(shadowColor);
package/cjs/index.js CHANGED
@@ -15,9 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.loadParticlesLinksInteraction = loadParticlesLinksInteraction;
18
+ const engine_1 = require("@tsparticles/engine");
18
19
  const interaction_js_1 = require("./interaction.js");
19
20
  const plugin_js_1 = require("./plugin.js");
20
21
  async function loadParticlesLinksInteraction(engine, refresh = true) {
22
+ (0, engine_1.assertValidVersion)(engine, "3.7.0");
21
23
  await (0, interaction_js_1.loadLinksInteraction)(engine, refresh);
22
24
  await (0, plugin_js_1.loadLinksPlugin)(engine, refresh);
23
25
  }
@@ -4,6 +4,6 @@ exports.loadLinksInteraction = loadLinksInteraction;
4
4
  const Linker_js_1 = require("./Linker.js");
5
5
  async function loadLinksInteraction(engine, refresh = true) {
6
6
  await engine.addInteractor("particlesLinks", async (container) => {
7
- return Promise.resolve(new Linker_js_1.Linker(container));
7
+ return Promise.resolve(new Linker_js_1.Linker(container, engine));
8
8
  }, refresh);
9
9
  }
package/cjs/plugin.js CHANGED
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadLinksPlugin = loadLinksPlugin;
4
4
  const LinksPlugin_js_1 = require("./LinksPlugin.js");
5
5
  async function loadLinksPlugin(engine, refresh = true) {
6
- const plugin = new LinksPlugin_js_1.LinksPlugin();
6
+ const plugin = new LinksPlugin_js_1.LinksPlugin(engine);
7
7
  await engine.addPlugin(plugin, refresh);
8
8
  }
@@ -2,20 +2,19 @@ import { getDistance, getLinkColor, getRandom, getRangeValue, rangeColorToRgb, }
2
2
  import { drawLinkLine, drawLinkTriangle, setLinkFrequency } from "./Utils.js";
3
3
  const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5, maxFrequency = 1;
4
4
  export class LinkInstance {
5
- constructor(container) {
6
- this.container = container;
5
+ constructor(container, engine) {
7
6
  this._drawLinkLine = (p1, link) => {
8
7
  const p1LinksOptions = p1.options.links;
9
8
  if (!p1LinksOptions?.enable) {
10
9
  return;
11
10
  }
12
- const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
11
+ const container = this._container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
13
12
  let opacity = link.opacity;
14
13
  container.canvas.draw(ctx => {
15
14
  let colorLine;
16
15
  const twinkle = p1.options.twinkle?.lines;
17
16
  if (twinkle?.enable) {
18
- const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(twinkle.color), twinkling = getRandom() < twinkleFreq;
17
+ const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(this._engine, twinkle.color), twinkling = getRandom() < twinkleFreq;
19
18
  if (twinkling && twinkleRgb) {
20
19
  colorLine = twinkleRgb;
21
20
  opacity = getRangeValue(twinkle.opacity);
@@ -36,6 +35,7 @@ export class LinkInstance {
36
35
  width,
37
36
  begin: pos1,
38
37
  end: pos2,
38
+ engine: this._engine,
39
39
  maxDistance,
40
40
  canvasSize: container.canvas.size,
41
41
  links: p1LinksOptions,
@@ -54,7 +54,7 @@ export class LinkInstance {
54
54
  if (!triangleOptions.enable) {
55
55
  return;
56
56
  }
57
- const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
57
+ const container = this._container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
58
58
  if (opacityTriangle <= minOpacity) {
59
59
  return;
60
60
  }
@@ -65,7 +65,7 @@ export class LinkInstance {
65
65
  getDistance(pos3, pos1) > linksDistance) {
66
66
  return;
67
67
  }
68
- let colorTriangle = rangeColorToRgb(triangleOptions.color);
68
+ let colorTriangle = rangeColorToRgb(this._engine, triangleOptions.color);
69
69
  if (!colorTriangle) {
70
70
  const linkColor = linksOptions.id !== undefined
71
71
  ? container.particles.linksColors.get(linksOptions.id)
@@ -114,6 +114,8 @@ export class LinkInstance {
114
114
  this._getTriangleFrequency = (p1, p2, p3) => {
115
115
  return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
116
116
  };
117
+ this._container = container;
118
+ this._engine = engine;
117
119
  this._freqs = {
118
120
  links: new Map(),
119
121
  triangles: new Map(),
@@ -144,7 +146,7 @@ export class LinkInstance {
144
146
  if (!particle.options.links) {
145
147
  return;
146
148
  }
147
- const ratio = this.container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
149
+ const ratio = this._container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
148
150
  retina.linksDistance = distance * ratio;
149
151
  retina.linksWidth = width * ratio;
150
152
  }
package/esm/Linker.js CHANGED
@@ -20,13 +20,13 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
20
20
  return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
21
21
  }
22
22
  export class Linker extends ParticlesInteractorBase {
23
- constructor(container) {
23
+ constructor(container, engine) {
24
24
  super(container);
25
25
  this._setColor = p1 => {
26
26
  if (!p1.options.links) {
27
27
  return;
28
28
  }
29
- const container = this.linkContainer, linksOptions = p1.options.links;
29
+ const container = this._linkContainer, linksOptions = p1.options.links;
30
30
  let linkColor = linksOptions.id === undefined
31
31
  ? container.particles.linksColor
32
32
  : container.particles.linksColors.get(linksOptions.id);
@@ -34,7 +34,7 @@ export class Linker extends ParticlesInteractorBase {
34
34
  return;
35
35
  }
36
36
  const optColor = linksOptions.color;
37
- linkColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
37
+ linkColor = getLinkRandomColor(this._engine, optColor, linksOptions.blink, linksOptions.consent);
38
38
  if (linksOptions.id === undefined) {
39
39
  container.particles.linksColor = linkColor;
40
40
  }
@@ -42,13 +42,14 @@ export class Linker extends ParticlesInteractorBase {
42
42
  container.particles.linksColors.set(linksOptions.id, linkColor);
43
43
  }
44
44
  };
45
- this.linkContainer = container;
45
+ this._linkContainer = container;
46
+ this._engine = engine;
46
47
  }
47
48
  clear() {
48
49
  }
49
50
  init() {
50
- this.linkContainer.particles.linksColor = undefined;
51
- this.linkContainer.particles.linksColors = new Map();
51
+ this._linkContainer.particles.linksColor = undefined;
52
+ this._linkContainer.particles.linksColors = new Map();
52
53
  }
53
54
  interact(p1) {
54
55
  if (!p1.options.links) {
@@ -1,10 +1,11 @@
1
1
  import { LinkInstance } from "./LinkInstance.js";
2
2
  export class LinksPlugin {
3
- constructor() {
3
+ constructor(engine) {
4
4
  this.id = "links";
5
+ this._engine = engine;
5
6
  }
6
7
  getPlugin(container) {
7
- return Promise.resolve(new LinkInstance(container));
8
+ return Promise.resolve(new LinkInstance(container, this._engine));
8
9
  }
9
10
  loadOptions() {
10
11
  }
@@ -1,4 +1,4 @@
1
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
2
  import { LinksShadow } from "./LinksShadow.js";
3
3
  import { LinksTriangle } from "./LinksTriangle.js";
4
4
  export class Links {
@@ -17,7 +17,7 @@ export class Links {
17
17
  this.warp = false;
18
18
  }
19
19
  load(data) {
20
- if (!data) {
20
+ if (isNull(data)) {
21
21
  return;
22
22
  }
23
23
  if (data.id !== undefined) {
@@ -1,4 +1,4 @@
1
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
2
  export class LinksShadow {
3
3
  constructor() {
4
4
  this.blur = 5;
@@ -7,7 +7,7 @@ export class LinksShadow {
7
7
  this.enable = false;
8
8
  }
9
9
  load(data) {
10
- if (!data) {
10
+ if (isNull(data)) {
11
11
  return;
12
12
  }
13
13
  if (data.blur !== undefined) {
@@ -1,11 +1,11 @@
1
- import { OptionsColor } from "@tsparticles/engine";
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
2
  export class LinksTriangle {
3
3
  constructor() {
4
4
  this.enable = false;
5
5
  this.frequency = 1;
6
6
  }
7
7
  load(data) {
8
- if (!data) {
8
+ if (isNull(data)) {
9
9
  return;
10
10
  }
11
11
  if (data.color !== undefined) {
package/esm/Utils.js CHANGED
@@ -8,7 +8,7 @@ export function drawTriangle(context, p1, p2, p3) {
8
8
  }
9
9
  export function drawLinkLine(params) {
10
10
  let drawn = false;
11
- const { begin, end, maxDistance, context, canvasSize, width, backgroundMask, colorLine, opacity, links } = params;
11
+ const { begin, end, engine, maxDistance, context, canvasSize, width, backgroundMask, colorLine, opacity, links } = params;
12
12
  if (getDistance(begin, end) <= maxDistance) {
13
13
  drawLine(context, begin, end);
14
14
  drawn = true;
@@ -68,7 +68,7 @@ export function drawLinkLine(params) {
68
68
  context.strokeStyle = getStyleFromRgb(colorLine, opacity);
69
69
  const { shadow } = links;
70
70
  if (shadow.enable) {
71
- const shadowColor = rangeColorToRgb(shadow.color);
71
+ const shadowColor = rangeColorToRgb(engine, shadow.color);
72
72
  if (shadowColor) {
73
73
  context.shadowBlur = shadow.blur;
74
74
  context.shadowColor = getStyleFromRgb(shadowColor);
package/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
+ import { assertValidVersion } from "@tsparticles/engine";
1
2
  import { loadLinksInteraction } from "./interaction.js";
2
3
  import { loadLinksPlugin } from "./plugin.js";
3
4
  export async function loadParticlesLinksInteraction(engine, refresh = true) {
5
+ assertValidVersion(engine, "3.7.0");
4
6
  await loadLinksInteraction(engine, refresh);
5
7
  await loadLinksPlugin(engine, refresh);
6
8
  }
@@ -1,6 +1,6 @@
1
1
  import { Linker } from "./Linker.js";
2
2
  export async function loadLinksInteraction(engine, refresh = true) {
3
3
  await engine.addInteractor("particlesLinks", async (container) => {
4
- return Promise.resolve(new Linker(container));
4
+ return Promise.resolve(new Linker(container, engine));
5
5
  }, refresh);
6
6
  }
package/esm/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LinksPlugin } from "./LinksPlugin.js";
2
2
  export async function loadLinksPlugin(engine, refresh = true) {
3
- const plugin = new LinksPlugin();
3
+ const plugin = new LinksPlugin(engine);
4
4
  await engine.addPlugin(plugin, refresh);
5
5
  }