@tsparticles/interaction-external-connect 3.0.0-alpha.0 → 3.0.0-beta.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/README.md +25 -19
- package/browser/Connector.js +4 -39
- package/browser/Options/Classes/Connect.js +1 -14
- package/browser/Utils.js +35 -0
- package/browser/index.js +2 -2
- package/cjs/Connector.js +24 -70
- package/cjs/Options/Classes/Connect.js +1 -14
- package/cjs/Utils.js +42 -0
- package/cjs/index.js +2 -13
- package/esm/Connector.js +4 -39
- package/esm/Options/Classes/Connect.js +1 -14
- package/esm/Utils.js +35 -0
- package/esm/index.js +2 -2
- package/package.json +6 -5
- package/report.html +4 -4
- package/tsparticles.interaction.external.connect.js +15 -27
- package/tsparticles.interaction.external.connect.min.js +1 -1
- package/tsparticles.interaction.external.connect.min.js.LICENSE.txt +1 -8
- package/types/Connector.d.ts +1 -2
- package/types/Options/Classes/Connect.d.ts +0 -4
- package/types/Options/Interfaces/IConnect.d.ts +0 -2
- package/types/Types.d.ts +6 -1
- package/types/Utils.d.ts +6 -0
- package/types/index.d.ts +1 -1
- package/umd/Connector.js +5 -40
- package/umd/Options/Classes/Connect.js +1 -14
- package/umd/Utils.js +52 -0
- package/umd/index.js +2 -2
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles External Connect Interaction
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-external-connect)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/interaction-external-connect)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/interaction-external-connect) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for connect effect around mouse or HTML
|
|
10
10
|
elements.
|
|
@@ -27,14 +27,16 @@ loadExternalConnectInteraction;
|
|
|
27
27
|
Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
30
|
+
(async () => {
|
|
31
|
+
await loadExternalConnectInteraction(tsParticles);
|
|
32
|
+
|
|
33
|
+
await tsParticles.load({
|
|
34
|
+
id: "tsparticles",
|
|
35
|
+
options: {
|
|
36
|
+
/* options */
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
### ESM / CommonJS
|
|
@@ -42,29 +44,33 @@ tsParticles.load({
|
|
|
42
44
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
45
|
|
|
44
46
|
```shell
|
|
45
|
-
$ npm install tsparticles
|
|
47
|
+
$ npm install @tsparticles/interaction-external-connect
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
or
|
|
49
51
|
|
|
50
52
|
```shell
|
|
51
|
-
$ yarn add tsparticles
|
|
53
|
+
$ yarn add @tsparticles/interaction-external-connect
|
|
52
54
|
```
|
|
53
55
|
|
|
54
56
|
Then you need to import it in the app, like this:
|
|
55
57
|
|
|
56
58
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
-
const { loadExternalConnectInteraction } = require("tsparticles
|
|
59
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
60
|
+
const { loadExternalConnectInteraction } = require("@tsparticles/interaction-external-connect");
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
(async () => {
|
|
63
|
+
await loadExternalConnectInteraction(tsParticles);
|
|
64
|
+
})();
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
or
|
|
64
68
|
|
|
65
69
|
```javascript
|
|
66
|
-
import { tsParticles } from "tsparticles
|
|
67
|
-
import { loadExternalConnectInteraction } from "tsparticles
|
|
70
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
71
|
+
import { loadExternalConnectInteraction } from "@tsparticles/interaction-external-connect";
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
(async () => {
|
|
74
|
+
await loadExternalConnectInteraction(tsParticles);
|
|
75
|
+
})();
|
|
70
76
|
```
|
package/browser/Connector.js
CHANGED
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
import { ExternalInteractorBase,
|
|
1
|
+
import { ExternalInteractorBase, isInArray, } from "@tsparticles/engine";
|
|
2
2
|
import { Connect } from "./Options/Classes/Connect";
|
|
3
|
-
|
|
4
|
-
const gradStop = Math.floor(p2.getRadius() / p1.getRadius()), color1 = p1.getFillColor(), color2 = p2.getFillColor();
|
|
5
|
-
if (!color1 || !color2) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const sourcePos = p1.getPosition(), destPos = p2.getPosition(), midRgb = colorMix(color1, color2, p1.getRadius(), p2.getRadius()), grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
|
9
|
-
grad.addColorStop(0, getStyleFromHsl(color1, opacity));
|
|
10
|
-
grad.addColorStop(gradStop > 1 ? 1 : gradStop, getStyleFromRgb(midRgb, opacity));
|
|
11
|
-
grad.addColorStop(1, getStyleFromHsl(color2, opacity));
|
|
12
|
-
return grad;
|
|
13
|
-
}
|
|
14
|
-
function drawConnectLine(context, width, lineStyle, begin, end) {
|
|
15
|
-
drawLine(context, begin, end);
|
|
16
|
-
context.lineWidth = width;
|
|
17
|
-
context.strokeStyle = lineStyle;
|
|
18
|
-
context.stroke();
|
|
19
|
-
}
|
|
20
|
-
function lineStyle(container, ctx, p1, p2) {
|
|
21
|
-
const options = container.actualOptions, connectOptions = options.interactivity.modes.connect;
|
|
22
|
-
if (!connectOptions) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
|
26
|
-
}
|
|
27
|
-
function drawConnection(container, p1, p2) {
|
|
28
|
-
container.canvas.draw((ctx) => {
|
|
29
|
-
var _a;
|
|
30
|
-
const ls = lineStyle(container, ctx, p1, p2);
|
|
31
|
-
if (!ls) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
35
|
-
drawConnectLine(ctx, (_a = p1.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, ls, pos1, pos2);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
3
|
+
import { drawConnection } from "./Utils";
|
|
38
4
|
export class Connector extends ExternalInteractorBase {
|
|
39
5
|
constructor(container) {
|
|
40
6
|
super(container);
|
|
@@ -75,8 +41,7 @@ export class Connector extends ExternalInteractorBase {
|
|
|
75
41
|
}
|
|
76
42
|
}
|
|
77
43
|
isEnabled(particle) {
|
|
78
|
-
|
|
79
|
-
const container = this.container, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
|
44
|
+
const container = this.container, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? container.actualOptions.interactivity).events;
|
|
80
45
|
if (!(events.onHover.enable && mouse.position)) {
|
|
81
46
|
return false;
|
|
82
47
|
}
|
|
@@ -87,7 +52,7 @@ export class Connector extends ExternalInteractorBase {
|
|
|
87
52
|
options.connect = new Connect();
|
|
88
53
|
}
|
|
89
54
|
for (const source of sources) {
|
|
90
|
-
options.connect.load(source
|
|
55
|
+
options.connect.load(source?.connect);
|
|
91
56
|
}
|
|
92
57
|
}
|
|
93
58
|
reset() {
|
|
@@ -5,27 +5,14 @@ export class Connect {
|
|
|
5
5
|
this.links = new ConnectLinks();
|
|
6
6
|
this.radius = 60;
|
|
7
7
|
}
|
|
8
|
-
get lineLinked() {
|
|
9
|
-
return this.links;
|
|
10
|
-
}
|
|
11
|
-
set lineLinked(value) {
|
|
12
|
-
this.links = value;
|
|
13
|
-
}
|
|
14
|
-
get line_linked() {
|
|
15
|
-
return this.links;
|
|
16
|
-
}
|
|
17
|
-
set line_linked(value) {
|
|
18
|
-
this.links = value;
|
|
19
|
-
}
|
|
20
8
|
load(data) {
|
|
21
|
-
var _a, _b;
|
|
22
9
|
if (!data) {
|
|
23
10
|
return;
|
|
24
11
|
}
|
|
25
12
|
if (data.distance !== undefined) {
|
|
26
13
|
this.distance = data.distance;
|
|
27
14
|
}
|
|
28
|
-
this.links.load(
|
|
15
|
+
this.links.load(data.links);
|
|
29
16
|
if (data.radius !== undefined) {
|
|
30
17
|
this.radius = data.radius;
|
|
31
18
|
}
|
package/browser/Utils.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { colorMix, drawLine, getStyleFromHsl, getStyleFromRgb, } from "@tsparticles/engine";
|
|
2
|
+
export function gradient(context, p1, p2, opacity) {
|
|
3
|
+
const gradStop = Math.floor(p2.getRadius() / p1.getRadius()), color1 = p1.getFillColor(), color2 = p2.getFillColor();
|
|
4
|
+
if (!color1 || !color2) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const sourcePos = p1.getPosition(), destPos = p2.getPosition(), midRgb = colorMix(color1, color2, p1.getRadius(), p2.getRadius()), grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
|
8
|
+
grad.addColorStop(0, getStyleFromHsl(color1, opacity));
|
|
9
|
+
grad.addColorStop(gradStop > 1 ? 1 : gradStop, getStyleFromRgb(midRgb, opacity));
|
|
10
|
+
grad.addColorStop(1, getStyleFromHsl(color2, opacity));
|
|
11
|
+
return grad;
|
|
12
|
+
}
|
|
13
|
+
export function drawConnectLine(context, width, lineStyle, begin, end) {
|
|
14
|
+
drawLine(context, begin, end);
|
|
15
|
+
context.lineWidth = width;
|
|
16
|
+
context.strokeStyle = lineStyle;
|
|
17
|
+
context.stroke();
|
|
18
|
+
}
|
|
19
|
+
export function lineStyle(container, ctx, p1, p2) {
|
|
20
|
+
const options = container.actualOptions, connectOptions = options.interactivity.modes.connect;
|
|
21
|
+
if (!connectOptions) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
|
25
|
+
}
|
|
26
|
+
export function drawConnection(container, p1, p2) {
|
|
27
|
+
container.canvas.draw((ctx) => {
|
|
28
|
+
const ls = lineStyle(container, ctx, p1, p2);
|
|
29
|
+
if (!ls) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
33
|
+
drawConnectLine(ctx, p1.retina.linksWidth ?? 0, ls, pos1, pos2);
|
|
34
|
+
});
|
|
35
|
+
}
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connector } from "./Connector";
|
|
2
|
-
export async function loadExternalConnectInteraction(engine) {
|
|
3
|
-
await engine.addInteractor("externalConnect", (container) => new Connector(container));
|
|
2
|
+
export async function loadExternalConnectInteraction(engine, refresh = true) {
|
|
3
|
+
await engine.addInteractor("externalConnect", (container) => new Connector(container), refresh);
|
|
4
4
|
}
|
|
5
5
|
export * from "./Options/Classes/Connect";
|
|
6
6
|
export * from "./Options/Classes/ConnectLinks";
|
package/cjs/Connector.js
CHANGED
|
@@ -1,52 +1,9 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.Connector = void 0;
|
|
13
4
|
const engine_1 = require("@tsparticles/engine");
|
|
14
5
|
const Connect_1 = require("./Options/Classes/Connect");
|
|
15
|
-
|
|
16
|
-
const gradStop = Math.floor(p2.getRadius() / p1.getRadius()), color1 = p1.getFillColor(), color2 = p2.getFillColor();
|
|
17
|
-
if (!color1 || !color2) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const sourcePos = p1.getPosition(), destPos = p2.getPosition(), midRgb = (0, engine_1.colorMix)(color1, color2, p1.getRadius(), p2.getRadius()), grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
|
21
|
-
grad.addColorStop(0, (0, engine_1.getStyleFromHsl)(color1, opacity));
|
|
22
|
-
grad.addColorStop(gradStop > 1 ? 1 : gradStop, (0, engine_1.getStyleFromRgb)(midRgb, opacity));
|
|
23
|
-
grad.addColorStop(1, (0, engine_1.getStyleFromHsl)(color2, opacity));
|
|
24
|
-
return grad;
|
|
25
|
-
}
|
|
26
|
-
function drawConnectLine(context, width, lineStyle, begin, end) {
|
|
27
|
-
(0, engine_1.drawLine)(context, begin, end);
|
|
28
|
-
context.lineWidth = width;
|
|
29
|
-
context.strokeStyle = lineStyle;
|
|
30
|
-
context.stroke();
|
|
31
|
-
}
|
|
32
|
-
function lineStyle(container, ctx, p1, p2) {
|
|
33
|
-
const options = container.actualOptions, connectOptions = options.interactivity.modes.connect;
|
|
34
|
-
if (!connectOptions) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
|
38
|
-
}
|
|
39
|
-
function drawConnection(container, p1, p2) {
|
|
40
|
-
container.canvas.draw((ctx) => {
|
|
41
|
-
var _a;
|
|
42
|
-
const ls = lineStyle(container, ctx, p1, p2);
|
|
43
|
-
if (!ls) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
47
|
-
drawConnectLine(ctx, (_a = p1.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, ls, pos1, pos2);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
6
|
+
const Utils_1 = require("./Utils");
|
|
50
7
|
class Connector extends engine_1.ExternalInteractorBase {
|
|
51
8
|
constructor(container) {
|
|
52
9
|
super(container);
|
|
@@ -61,36 +18,33 @@ class Connector extends engine_1.ExternalInteractorBase {
|
|
|
61
18
|
container.retina.connectModeDistance = connect.distance * container.retina.pixelRatio;
|
|
62
19
|
container.retina.connectModeRadius = connect.radius * container.retina.pixelRatio;
|
|
63
20
|
}
|
|
64
|
-
interact() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
drawConnection(container, p1, p2);
|
|
84
|
-
}
|
|
21
|
+
async interact() {
|
|
22
|
+
const container = this.container, options = container.actualOptions;
|
|
23
|
+
if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
|
|
24
|
+
const mousePos = container.interactivity.mouse.position;
|
|
25
|
+
if (!container.retina.connectModeDistance ||
|
|
26
|
+
container.retina.connectModeDistance < 0 ||
|
|
27
|
+
!container.retina.connectModeRadius ||
|
|
28
|
+
container.retina.connectModeRadius < 0 ||
|
|
29
|
+
!mousePos) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const distance = Math.abs(container.retina.connectModeRadius), query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
|
|
33
|
+
let i = 0;
|
|
34
|
+
for (const p1 of query) {
|
|
35
|
+
const pos1 = p1.getPosition();
|
|
36
|
+
for (const p2 of query.slice(i + 1)) {
|
|
37
|
+
const pos2 = p2.getPosition(), distMax = Math.abs(container.retina.connectModeDistance), xDiff = Math.abs(pos1.x - pos2.x), yDiff = Math.abs(pos1.y - pos2.y);
|
|
38
|
+
if (xDiff < distMax && yDiff < distMax) {
|
|
39
|
+
(0, Utils_1.drawConnection)(container, p1, p2);
|
|
85
40
|
}
|
|
86
|
-
++i;
|
|
87
41
|
}
|
|
42
|
+
++i;
|
|
88
43
|
}
|
|
89
|
-
}
|
|
44
|
+
}
|
|
90
45
|
}
|
|
91
46
|
isEnabled(particle) {
|
|
92
|
-
|
|
93
|
-
const container = this.container, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
|
47
|
+
const container = this.container, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? container.actualOptions.interactivity).events;
|
|
94
48
|
if (!(events.onHover.enable && mouse.position)) {
|
|
95
49
|
return false;
|
|
96
50
|
}
|
|
@@ -101,7 +55,7 @@ class Connector extends engine_1.ExternalInteractorBase {
|
|
|
101
55
|
options.connect = new Connect_1.Connect();
|
|
102
56
|
}
|
|
103
57
|
for (const source of sources) {
|
|
104
|
-
options.connect.load(source
|
|
58
|
+
options.connect.load(source?.connect);
|
|
105
59
|
}
|
|
106
60
|
}
|
|
107
61
|
reset() {
|
|
@@ -8,27 +8,14 @@ class Connect {
|
|
|
8
8
|
this.links = new ConnectLinks_1.ConnectLinks();
|
|
9
9
|
this.radius = 60;
|
|
10
10
|
}
|
|
11
|
-
get lineLinked() {
|
|
12
|
-
return this.links;
|
|
13
|
-
}
|
|
14
|
-
set lineLinked(value) {
|
|
15
|
-
this.links = value;
|
|
16
|
-
}
|
|
17
|
-
get line_linked() {
|
|
18
|
-
return this.links;
|
|
19
|
-
}
|
|
20
|
-
set line_linked(value) {
|
|
21
|
-
this.links = value;
|
|
22
|
-
}
|
|
23
11
|
load(data) {
|
|
24
|
-
var _a, _b;
|
|
25
12
|
if (!data) {
|
|
26
13
|
return;
|
|
27
14
|
}
|
|
28
15
|
if (data.distance !== undefined) {
|
|
29
16
|
this.distance = data.distance;
|
|
30
17
|
}
|
|
31
|
-
this.links.load(
|
|
18
|
+
this.links.load(data.links);
|
|
32
19
|
if (data.radius !== undefined) {
|
|
33
20
|
this.radius = data.radius;
|
|
34
21
|
}
|
package/cjs/Utils.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.drawConnection = exports.lineStyle = exports.drawConnectLine = exports.gradient = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
function gradient(context, p1, p2, opacity) {
|
|
6
|
+
const gradStop = Math.floor(p2.getRadius() / p1.getRadius()), color1 = p1.getFillColor(), color2 = p2.getFillColor();
|
|
7
|
+
if (!color1 || !color2) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const sourcePos = p1.getPosition(), destPos = p2.getPosition(), midRgb = (0, engine_1.colorMix)(color1, color2, p1.getRadius(), p2.getRadius()), grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
|
11
|
+
grad.addColorStop(0, (0, engine_1.getStyleFromHsl)(color1, opacity));
|
|
12
|
+
grad.addColorStop(gradStop > 1 ? 1 : gradStop, (0, engine_1.getStyleFromRgb)(midRgb, opacity));
|
|
13
|
+
grad.addColorStop(1, (0, engine_1.getStyleFromHsl)(color2, opacity));
|
|
14
|
+
return grad;
|
|
15
|
+
}
|
|
16
|
+
exports.gradient = gradient;
|
|
17
|
+
function drawConnectLine(context, width, lineStyle, begin, end) {
|
|
18
|
+
(0, engine_1.drawLine)(context, begin, end);
|
|
19
|
+
context.lineWidth = width;
|
|
20
|
+
context.strokeStyle = lineStyle;
|
|
21
|
+
context.stroke();
|
|
22
|
+
}
|
|
23
|
+
exports.drawConnectLine = drawConnectLine;
|
|
24
|
+
function lineStyle(container, ctx, p1, p2) {
|
|
25
|
+
const options = container.actualOptions, connectOptions = options.interactivity.modes.connect;
|
|
26
|
+
if (!connectOptions) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
|
30
|
+
}
|
|
31
|
+
exports.lineStyle = lineStyle;
|
|
32
|
+
function drawConnection(container, p1, p2) {
|
|
33
|
+
container.canvas.draw((ctx) => {
|
|
34
|
+
const ls = lineStyle(container, ctx, p1, p2);
|
|
35
|
+
if (!ls) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
39
|
+
drawConnectLine(ctx, p1.retina.linksWidth ?? 0, ls, pos1, pos2);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.drawConnection = drawConnection;
|
package/cjs/index.js
CHANGED
|
@@ -13,22 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
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
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
17
|
exports.loadExternalConnectInteraction = void 0;
|
|
27
18
|
const Connector_1 = require("./Connector");
|
|
28
|
-
function loadExternalConnectInteraction(engine) {
|
|
29
|
-
|
|
30
|
-
yield engine.addInteractor("externalConnect", (container) => new Connector_1.Connector(container));
|
|
31
|
-
});
|
|
19
|
+
async function loadExternalConnectInteraction(engine, refresh = true) {
|
|
20
|
+
await engine.addInteractor("externalConnect", (container) => new Connector_1.Connector(container), refresh);
|
|
32
21
|
}
|
|
33
22
|
exports.loadExternalConnectInteraction = loadExternalConnectInteraction;
|
|
34
23
|
__exportStar(require("./Options/Classes/Connect"), exports);
|
package/esm/Connector.js
CHANGED
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
import { ExternalInteractorBase,
|
|
1
|
+
import { ExternalInteractorBase, isInArray, } from "@tsparticles/engine";
|
|
2
2
|
import { Connect } from "./Options/Classes/Connect";
|
|
3
|
-
|
|
4
|
-
const gradStop = Math.floor(p2.getRadius() / p1.getRadius()), color1 = p1.getFillColor(), color2 = p2.getFillColor();
|
|
5
|
-
if (!color1 || !color2) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const sourcePos = p1.getPosition(), destPos = p2.getPosition(), midRgb = colorMix(color1, color2, p1.getRadius(), p2.getRadius()), grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
|
9
|
-
grad.addColorStop(0, getStyleFromHsl(color1, opacity));
|
|
10
|
-
grad.addColorStop(gradStop > 1 ? 1 : gradStop, getStyleFromRgb(midRgb, opacity));
|
|
11
|
-
grad.addColorStop(1, getStyleFromHsl(color2, opacity));
|
|
12
|
-
return grad;
|
|
13
|
-
}
|
|
14
|
-
function drawConnectLine(context, width, lineStyle, begin, end) {
|
|
15
|
-
drawLine(context, begin, end);
|
|
16
|
-
context.lineWidth = width;
|
|
17
|
-
context.strokeStyle = lineStyle;
|
|
18
|
-
context.stroke();
|
|
19
|
-
}
|
|
20
|
-
function lineStyle(container, ctx, p1, p2) {
|
|
21
|
-
const options = container.actualOptions, connectOptions = options.interactivity.modes.connect;
|
|
22
|
-
if (!connectOptions) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
|
26
|
-
}
|
|
27
|
-
function drawConnection(container, p1, p2) {
|
|
28
|
-
container.canvas.draw((ctx) => {
|
|
29
|
-
var _a;
|
|
30
|
-
const ls = lineStyle(container, ctx, p1, p2);
|
|
31
|
-
if (!ls) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
35
|
-
drawConnectLine(ctx, (_a = p1.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, ls, pos1, pos2);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
3
|
+
import { drawConnection } from "./Utils";
|
|
38
4
|
export class Connector extends ExternalInteractorBase {
|
|
39
5
|
constructor(container) {
|
|
40
6
|
super(container);
|
|
@@ -75,8 +41,7 @@ export class Connector extends ExternalInteractorBase {
|
|
|
75
41
|
}
|
|
76
42
|
}
|
|
77
43
|
isEnabled(particle) {
|
|
78
|
-
|
|
79
|
-
const container = this.container, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
|
44
|
+
const container = this.container, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? container.actualOptions.interactivity).events;
|
|
80
45
|
if (!(events.onHover.enable && mouse.position)) {
|
|
81
46
|
return false;
|
|
82
47
|
}
|
|
@@ -87,7 +52,7 @@ export class Connector extends ExternalInteractorBase {
|
|
|
87
52
|
options.connect = new Connect();
|
|
88
53
|
}
|
|
89
54
|
for (const source of sources) {
|
|
90
|
-
options.connect.load(source
|
|
55
|
+
options.connect.load(source?.connect);
|
|
91
56
|
}
|
|
92
57
|
}
|
|
93
58
|
reset() {
|
|
@@ -5,27 +5,14 @@ export class Connect {
|
|
|
5
5
|
this.links = new ConnectLinks();
|
|
6
6
|
this.radius = 60;
|
|
7
7
|
}
|
|
8
|
-
get lineLinked() {
|
|
9
|
-
return this.links;
|
|
10
|
-
}
|
|
11
|
-
set lineLinked(value) {
|
|
12
|
-
this.links = value;
|
|
13
|
-
}
|
|
14
|
-
get line_linked() {
|
|
15
|
-
return this.links;
|
|
16
|
-
}
|
|
17
|
-
set line_linked(value) {
|
|
18
|
-
this.links = value;
|
|
19
|
-
}
|
|
20
8
|
load(data) {
|
|
21
|
-
var _a, _b;
|
|
22
9
|
if (!data) {
|
|
23
10
|
return;
|
|
24
11
|
}
|
|
25
12
|
if (data.distance !== undefined) {
|
|
26
13
|
this.distance = data.distance;
|
|
27
14
|
}
|
|
28
|
-
this.links.load(
|
|
15
|
+
this.links.load(data.links);
|
|
29
16
|
if (data.radius !== undefined) {
|
|
30
17
|
this.radius = data.radius;
|
|
31
18
|
}
|
package/esm/Utils.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { colorMix, drawLine, getStyleFromHsl, getStyleFromRgb, } from "@tsparticles/engine";
|
|
2
|
+
export function gradient(context, p1, p2, opacity) {
|
|
3
|
+
const gradStop = Math.floor(p2.getRadius() / p1.getRadius()), color1 = p1.getFillColor(), color2 = p2.getFillColor();
|
|
4
|
+
if (!color1 || !color2) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const sourcePos = p1.getPosition(), destPos = p2.getPosition(), midRgb = colorMix(color1, color2, p1.getRadius(), p2.getRadius()), grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
|
8
|
+
grad.addColorStop(0, getStyleFromHsl(color1, opacity));
|
|
9
|
+
grad.addColorStop(gradStop > 1 ? 1 : gradStop, getStyleFromRgb(midRgb, opacity));
|
|
10
|
+
grad.addColorStop(1, getStyleFromHsl(color2, opacity));
|
|
11
|
+
return grad;
|
|
12
|
+
}
|
|
13
|
+
export function drawConnectLine(context, width, lineStyle, begin, end) {
|
|
14
|
+
drawLine(context, begin, end);
|
|
15
|
+
context.lineWidth = width;
|
|
16
|
+
context.strokeStyle = lineStyle;
|
|
17
|
+
context.stroke();
|
|
18
|
+
}
|
|
19
|
+
export function lineStyle(container, ctx, p1, p2) {
|
|
20
|
+
const options = container.actualOptions, connectOptions = options.interactivity.modes.connect;
|
|
21
|
+
if (!connectOptions) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
|
25
|
+
}
|
|
26
|
+
export function drawConnection(container, p1, p2) {
|
|
27
|
+
container.canvas.draw((ctx) => {
|
|
28
|
+
const ls = lineStyle(container, ctx, p1, p2);
|
|
29
|
+
if (!ls) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
33
|
+
drawConnectLine(ctx, p1.retina.linksWidth ?? 0, ls, pos1, pos2);
|
|
34
|
+
});
|
|
35
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connector } from "./Connector";
|
|
2
|
-
export async function loadExternalConnectInteraction(engine) {
|
|
3
|
-
await engine.addInteractor("externalConnect", (container) => new Connector(container));
|
|
2
|
+
export async function loadExternalConnectInteraction(engine, refresh = true) {
|
|
3
|
+
await engine.addInteractor("externalConnect", (container) => new Connector(container), refresh);
|
|
4
4
|
}
|
|
5
5
|
export * from "./Options/Classes/Connect";
|
|
6
6
|
export * from "./Options/Classes/ConnectLinks";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-connect",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles connect external interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -73,10 +73,11 @@
|
|
|
73
73
|
"unpkg": "tsparticles.interaction.external.connect.min.js",
|
|
74
74
|
"module": "esm/index.js",
|
|
75
75
|
"types": "types/index.d.ts",
|
|
76
|
+
"sideEffects": false,
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"@tsparticles/engine": "^3.0.0-beta.0"
|
|
79
|
+
},
|
|
76
80
|
"publishConfig": {
|
|
77
81
|
"access": "public"
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
80
|
-
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|