@tsparticles/interaction-particles-links 4.0.0-alpha.21 → 4.0.0-alpha.23

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/umd/Linker.js CHANGED
@@ -15,15 +15,8 @@
15
15
  const Links_js_1 = require("./Options/Classes/Links.js");
16
16
  const plugin_interactivity_1 = require("@tsparticles/plugin-interactivity");
17
17
  const squarePower = 2, opacityOffset = 1, minDistance = 0;
18
- function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
19
- const { dx, dy, distance } = (0, engine_1.getDistances)(pos1, pos2);
20
- if (!warp || distance <= optDistance) {
21
- return distance;
22
- }
23
- const absDiffs = {
24
- x: Math.abs(dx),
25
- y: Math.abs(dy),
26
- }, warpDistances = {
18
+ function getWarpDistance(pos1, pos2, canvasSize) {
19
+ const { dx, dy } = (0, engine_1.getDistances)(pos1, pos2), absDiffs = { x: Math.abs(dx), y: Math.abs(dy) }, warpDistances = {
27
20
  x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),
28
21
  y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y),
29
22
  };
@@ -50,15 +43,7 @@
50
43
  if (pos1.x < engine_1.originPoint.x || pos1.y < engine_1.originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
51
44
  return;
52
45
  }
53
- const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp;
54
- let range;
55
- if (warp) {
56
- range = new CircleWarp_js_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);
57
- }
58
- else {
59
- range = new engine_1.Circle(pos1.x, pos1.y, optDistance);
60
- }
61
- const query = container.particles.quadTree.query(range);
46
+ const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp, range = warp ? new CircleWarp_js_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize) : new engine_1.Circle(pos1.x, pos1.y, optDistance), query = container.particles.quadTree.query(range);
62
47
  for (const p2 of query) {
63
48
  const linkOpt2 = p2.options.links;
64
49
  if (p1 === p2 ||
@@ -75,7 +60,7 @@
75
60
  if (pos2.x < engine_1.originPoint.x || pos2.y < engine_1.originPoint.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
76
61
  continue;
77
62
  }
78
- const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
63
+ const distDirect = (0, engine_1.getDistances)(pos1, pos2).distance, distWarp = warp && linkOpt2.warp ? getWarpDistance(pos1, pos2, canvasSize) : distDirect, distance = Math.min(distDirect, distWarp);
79
64
  if (distance > optDistance) {
80
65
  continue;
81
66
  }
@@ -84,6 +69,8 @@
84
69
  p1.links.push({
85
70
  destination: p2,
86
71
  opacity: opacityLine,
72
+ color: this._getLinkColor(p1, p2),
73
+ isWarped: distWarp < distDirect,
87
74
  });
88
75
  }
89
76
  }
@@ -98,7 +85,17 @@
98
85
  }
99
86
  reset() {
100
87
  }
101
- _setColor = p1 => {
88
+ _getLinkColor(p1, p2) {
89
+ const container = this.container, linksOptions = p1.options.links;
90
+ if (!linksOptions) {
91
+ return;
92
+ }
93
+ const linkColor = linksOptions.id !== undefined
94
+ ? container.particles.linksColors.get(linksOptions.id)
95
+ : container.particles.linksColor;
96
+ return (0, engine_1.getLinkColor)(p1, p2, linkColor);
97
+ }
98
+ _setColor(p1) {
102
99
  if (!p1.options.links) {
103
100
  return;
104
101
  }
@@ -109,15 +106,14 @@
109
106
  if (linkColor) {
110
107
  return;
111
108
  }
112
- const optColor = linksOptions.color;
113
- linkColor = (0, engine_1.getLinkRandomColor)(this._engine, optColor, linksOptions.blink, linksOptions.consent);
109
+ linkColor = (0, engine_1.getLinkRandomColor)(this._engine, linksOptions.color, linksOptions.blink, linksOptions.consent);
114
110
  if (linksOptions.id === undefined) {
115
111
  container.particles.linksColor = linkColor;
116
112
  }
117
113
  else {
118
114
  container.particles.linksColors.set(linksOptions.id, linkColor);
119
115
  }
120
- };
116
+ }
121
117
  }
122
118
  exports.Linker = Linker;
123
119
  });
package/umd/Utils.js CHANGED
@@ -4,92 +4,14 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "@tsparticles/canvas-utils"], factory);
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.drawTriangle = drawTriangle;
13
- exports.drawLinkLine = drawLinkLine;
14
- exports.drawLinkTriangle = drawLinkTriangle;
15
12
  exports.getLinkKey = getLinkKey;
16
13
  exports.setLinkFrequency = setLinkFrequency;
17
14
  const engine_1 = require("@tsparticles/engine");
18
- const canvas_utils_1 = require("@tsparticles/canvas-utils");
19
- function drawTriangle(context, p1, p2, p3) {
20
- context.beginPath();
21
- context.moveTo(p1.x, p1.y);
22
- context.lineTo(p2.x, p2.y);
23
- context.lineTo(p3.x, p3.y);
24
- context.closePath();
25
- }
26
- function drawLinkLine(params) {
27
- let drawn = false;
28
- const { begin, end, engine, maxDistance, context, canvasSize, width, colorLine, opacity, links, hdr } = params;
29
- if ((0, engine_1.getDistance)(begin, end) <= maxDistance) {
30
- (0, canvas_utils_1.drawLine)(context, begin, end);
31
- drawn = true;
32
- }
33
- else if (links.warp) {
34
- let pi1, pi2;
35
- const endNE = {
36
- x: end.x - canvasSize.width,
37
- y: end.y,
38
- }, d1 = (0, engine_1.getDistances)(begin, endNE);
39
- if (d1.distance <= maxDistance) {
40
- const yi = begin.y - (d1.dy / d1.dx) * begin.x;
41
- pi1 = { x: 0, y: yi };
42
- pi2 = { x: canvasSize.width, y: yi };
43
- }
44
- else {
45
- const endSW = {
46
- x: end.x,
47
- y: end.y - canvasSize.height,
48
- }, d2 = (0, engine_1.getDistances)(begin, endSW);
49
- if (d2.distance <= maxDistance) {
50
- const yi = begin.y - (d2.dy / d2.dx) * begin.x, xi = -yi / (d2.dy / d2.dx);
51
- pi1 = { x: xi, y: 0 };
52
- pi2 = { x: xi, y: canvasSize.height };
53
- }
54
- else {
55
- const endSE = {
56
- x: end.x - canvasSize.width,
57
- y: end.y - canvasSize.height,
58
- }, d3 = (0, engine_1.getDistances)(begin, endSE);
59
- if (d3.distance <= maxDistance) {
60
- const yi = begin.y - (d3.dy / d3.dx) * begin.x, xi = -yi / (d3.dy / d3.dx);
61
- pi1 = { x: xi, y: yi };
62
- pi2 = { x: pi1.x + canvasSize.width, y: pi1.y + canvasSize.height };
63
- }
64
- }
65
- }
66
- if (pi1 && pi2) {
67
- (0, canvas_utils_1.drawLine)(context, begin, pi1);
68
- (0, canvas_utils_1.drawLine)(context, end, pi2);
69
- drawn = true;
70
- }
71
- }
72
- if (!drawn) {
73
- return;
74
- }
75
- context.lineWidth = width;
76
- context.strokeStyle = (0, engine_1.getStyleFromRgb)(colorLine, hdr, opacity);
77
- const { shadow } = links;
78
- if (shadow.enable) {
79
- const shadowColor = (0, engine_1.rangeColorToRgb)(engine, shadow.color);
80
- if (shadowColor) {
81
- context.shadowBlur = shadow.blur;
82
- context.shadowColor = (0, engine_1.getStyleFromRgb)(shadowColor, hdr);
83
- }
84
- }
85
- context.stroke();
86
- }
87
- function drawLinkTriangle(params) {
88
- const { context, hdr, pos1, pos2, pos3, colorTriangle, opacityTriangle } = params;
89
- drawTriangle(context, pos1, pos2, pos3);
90
- context.fillStyle = (0, engine_1.getStyleFromRgb)(colorTriangle, hdr, opacityTriangle);
91
- context.fill();
92
- }
93
15
  function getLinkKey(ids) {
94
16
  ids.sort((a, b) => a - b);
95
17
  return ids.join("_");
package/umd/index.js CHANGED
@@ -48,7 +48,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.loadParticlesLinksInteraction = loadParticlesLinksInteraction;
50
50
  async function loadParticlesLinksInteraction(engine) {
51
- engine.checkVersion("4.0.0-alpha.21");
51
+ engine.checkVersion("4.0.0-alpha.23");
52
52
  await engine.register(async (e) => {
53
53
  const [{ ensureInteractivityPluginLoaded }, { LinksPlugin },] = await Promise.all([
54
54
  __syncRequire ? Promise.resolve().then(() => __importStar(require("@tsparticles/plugin-interactivity"))) : new Promise((resolve_1, reject_1) => { require(["@tsparticles/plugin-interactivity"], resolve_1, reject_1); }).then(__importStar),
@@ -58,7 +58,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
58
58
  e.addPlugin(new LinksPlugin(e));
59
59
  e.addInteractor?.("particlesLinks", async (container) => {
60
60
  const { Linker } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Linker.js"))) : new Promise((resolve_3, reject_3) => { require(["./Linker.js"], resolve_3, reject_3); }).then(__importStar));
61
- return new Linker(container, engine);
61
+ return new Linker(container, e);
62
62
  });
63
63
  });
64
64
  }