@tsparticles/interaction-external-grab 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Grabber.js +82 -0
  4. package/browser/Options/Classes/Grab.js +29 -0
  5. package/browser/Options/Classes/GrabLinks.js +25 -0
  6. package/browser/Options/Classes/GrabOptions.js +1 -0
  7. package/browser/Options/Interfaces/IGrab.js +1 -0
  8. package/browser/Options/Interfaces/IGrabLinks.js +1 -0
  9. package/browser/Types.js +1 -0
  10. package/browser/index.js +8 -0
  11. package/cjs/Grabber.js +98 -0
  12. package/cjs/Options/Classes/Grab.js +33 -0
  13. package/cjs/Options/Classes/GrabLinks.js +29 -0
  14. package/cjs/Options/Classes/GrabOptions.js +2 -0
  15. package/cjs/Options/Interfaces/IGrab.js +2 -0
  16. package/cjs/Options/Interfaces/IGrabLinks.js +2 -0
  17. package/cjs/Types.js +2 -0
  18. package/cjs/index.js +37 -0
  19. package/esm/Grabber.js +82 -0
  20. package/esm/Options/Classes/Grab.js +29 -0
  21. package/esm/Options/Classes/GrabLinks.js +25 -0
  22. package/esm/Options/Classes/GrabOptions.js +1 -0
  23. package/esm/Options/Interfaces/IGrab.js +1 -0
  24. package/esm/Options/Interfaces/IGrabLinks.js +1 -0
  25. package/esm/Types.js +1 -0
  26. package/esm/index.js +8 -0
  27. package/package.json +82 -0
  28. package/report.html +39 -0
  29. package/tsparticles.interaction.external.grab.js +258 -0
  30. package/tsparticles.interaction.external.grab.min.js +2 -0
  31. package/tsparticles.interaction.external.grab.min.js.LICENSE.txt +8 -0
  32. package/types/Grabber.d.ts +13 -0
  33. package/types/Options/Classes/Grab.d.ts +13 -0
  34. package/types/Options/Classes/GrabLinks.d.ts +11 -0
  35. package/types/Options/Classes/GrabOptions.d.ts +7 -0
  36. package/types/Options/Interfaces/IGrab.d.ts +7 -0
  37. package/types/Options/Interfaces/IGrabLinks.d.ts +7 -0
  38. package/types/Types.d.ts +19 -0
  39. package/types/index.d.ts +6 -0
  40. package/umd/Grabber.js +97 -0
  41. package/umd/Options/Classes/Grab.js +43 -0
  42. package/umd/Options/Classes/GrabLinks.js +39 -0
  43. package/umd/Options/Classes/GrabOptions.js +12 -0
  44. package/umd/Options/Interfaces/IGrab.js +12 -0
  45. package/umd/Options/Interfaces/IGrabLinks.js +12 -0
  46. package/umd/Types.js +12 -0
  47. package/umd/index.js +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles External Grab Interaction
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-interaction-external-grab/badge)](https://www.jsdelivr.com/package/npm/tsparticles-interaction-external-grab)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-interaction-external-grab.svg)](https://www.npmjs.com/package/tsparticles-interaction-external-grab)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-interaction-external-grab)](https://www.npmjs.com/package/tsparticles-interaction-external-grab) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for grab effect around mouse or HTML
10
+ elements.
11
+
12
+ ## How to use it
13
+
14
+ ### CDN / Vanilla JS / jQuery
15
+
16
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
17
+
18
+ Including the `tsparticles.interaction.external.grab.min.js` file will export the function to load the interaction
19
+ plugin:
20
+
21
+ ```javascript
22
+ loadExternalGrabInteraction;
23
+ ```
24
+
25
+ ### Usage
26
+
27
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
28
+
29
+ ```javascript
30
+ loadExternalGrabInteraction(tsParticles);
31
+
32
+ tsParticles.load({
33
+ id: "tsparticles",
34
+ options: {
35
+ /* options */
36
+ },
37
+ });
38
+ ```
39
+
40
+ ### ESM / CommonJS
41
+
42
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
+
44
+ ```shell
45
+ $ npm install tsparticles-interaction-external-grab
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add tsparticles-interaction-external-grab
52
+ ```
53
+
54
+ Then you need to import it in the app, like this:
55
+
56
+ ```javascript
57
+ const { tsParticles } = require("tsparticles-engine");
58
+ const { loadExternalGrabInteraction } = require("tsparticles-interaction-external-grab");
59
+
60
+ loadExternalGrabInteraction(tsParticles);
61
+ ```
62
+
63
+ or
64
+
65
+ ```javascript
66
+ import { tsParticles } from "tsparticles-engine";
67
+ import { loadExternalGrabInteraction } from "tsparticles-interaction-external-grab";
68
+
69
+ loadExternalGrabInteraction(tsParticles);
70
+ ```
@@ -0,0 +1,82 @@
1
+ import { ExternalInteractorBase, drawLine, getDistance, getLinkColor, getLinkRandomColor, getStyleFromRgb, isInArray, mouseMoveEvent, } from "@tsparticles/engine";
2
+ import { Grab } from "./Options/Classes/Grab";
3
+ export function drawGrabLine(context, width, begin, end, colorLine, opacity) {
4
+ drawLine(context, begin, end);
5
+ context.strokeStyle = getStyleFromRgb(colorLine, opacity);
6
+ context.lineWidth = width;
7
+ context.stroke();
8
+ }
9
+ function drawGrab(container, particle, lineColor, opacity, mousePos) {
10
+ container.canvas.draw((ctx) => {
11
+ var _a;
12
+ const beginPos = particle.getPosition();
13
+ drawGrabLine(ctx, (_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, beginPos, mousePos, lineColor, opacity);
14
+ });
15
+ }
16
+ export class Grabber extends ExternalInteractorBase {
17
+ constructor(container) {
18
+ super(container);
19
+ }
20
+ clear() {
21
+ }
22
+ init() {
23
+ const container = this.container, grab = container.actualOptions.interactivity.modes.grab;
24
+ if (!grab) {
25
+ return;
26
+ }
27
+ container.retina.grabModeDistance = grab.distance * container.retina.pixelRatio;
28
+ }
29
+ async interact() {
30
+ var _a, _b;
31
+ const container = this.container, options = container.actualOptions, interactivity = options.interactivity;
32
+ if (!interactivity.modes.grab ||
33
+ !interactivity.events.onHover.enable ||
34
+ container.interactivity.status !== mouseMoveEvent) {
35
+ return;
36
+ }
37
+ const mousePos = container.interactivity.mouse.position;
38
+ if (!mousePos) {
39
+ return;
40
+ }
41
+ const distance = container.retina.grabModeDistance;
42
+ if (!distance || distance < 0) {
43
+ return;
44
+ }
45
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
46
+ for (const particle of query) {
47
+ const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos);
48
+ if (pointDistance > distance) {
49
+ continue;
50
+ }
51
+ const grabLineOptions = interactivity.modes.grab.links, lineOpacity = grabLineOptions.opacity, opacityLine = lineOpacity - (pointDistance * lineOpacity) / distance;
52
+ if (opacityLine <= 0) {
53
+ continue;
54
+ }
55
+ const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : (_b = particle.options.links) === null || _b === void 0 ? void 0 : _b.color;
56
+ if (!container.particles.grabLineColor && optColor) {
57
+ const linksOptions = interactivity.modes.grab.links;
58
+ container.particles.grabLineColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
59
+ }
60
+ const colorLine = getLinkColor(particle, undefined, container.particles.grabLineColor);
61
+ if (!colorLine) {
62
+ return;
63
+ }
64
+ drawGrab(container, particle, colorLine, opacityLine, mousePos);
65
+ }
66
+ }
67
+ isEnabled(particle) {
68
+ var _a;
69
+ 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;
70
+ return events.onHover.enable && !!mouse.position && isInArray("grab", events.onHover.mode);
71
+ }
72
+ loadModeOptions(options, ...sources) {
73
+ if (!options.grab) {
74
+ options.grab = new Grab();
75
+ }
76
+ for (const source of sources) {
77
+ options.grab.load(source === null || source === void 0 ? void 0 : source.grab);
78
+ }
79
+ }
80
+ reset() {
81
+ }
82
+ }
@@ -0,0 +1,29 @@
1
+ import { GrabLinks } from "./GrabLinks";
2
+ export class Grab {
3
+ constructor() {
4
+ this.distance = 100;
5
+ this.links = new GrabLinks();
6
+ }
7
+ get lineLinked() {
8
+ return this.links;
9
+ }
10
+ set lineLinked(value) {
11
+ this.links = value;
12
+ }
13
+ get line_linked() {
14
+ return this.links;
15
+ }
16
+ set line_linked(value) {
17
+ this.links = value;
18
+ }
19
+ load(data) {
20
+ var _a, _b;
21
+ if (!data) {
22
+ return;
23
+ }
24
+ if (data.distance !== undefined) {
25
+ this.distance = data.distance;
26
+ }
27
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
28
+ }
29
+ }
@@ -0,0 +1,25 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ export class GrabLinks {
3
+ constructor() {
4
+ this.blink = false;
5
+ this.consent = false;
6
+ this.opacity = 1;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.blink !== undefined) {
13
+ this.blink = data.blink;
14
+ }
15
+ if (data.color !== undefined) {
16
+ this.color = OptionsColor.create(this.color, data.color);
17
+ }
18
+ if (data.consent !== undefined) {
19
+ this.consent = data.consent;
20
+ }
21
+ if (data.opacity !== undefined) {
22
+ this.opacity = data.opacity;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Grabber } from "./Grabber";
2
+ export async function loadExternalGrabInteraction(engine) {
3
+ await engine.addInteractor("externalGrab", (container) => new Grabber(container));
4
+ }
5
+ export * from "./Options/Classes/Grab";
6
+ export * from "./Options/Classes/GrabLinks";
7
+ export * from "./Options/Interfaces/IGrab";
8
+ export * from "./Options/Interfaces/IGrabLinks";
package/cjs/Grabber.js ADDED
@@ -0,0 +1,98 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Grabber = exports.drawGrabLine = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Grab_1 = require("./Options/Classes/Grab");
15
+ function drawGrabLine(context, width, begin, end, colorLine, opacity) {
16
+ (0, engine_1.drawLine)(context, begin, end);
17
+ context.strokeStyle = (0, engine_1.getStyleFromRgb)(colorLine, opacity);
18
+ context.lineWidth = width;
19
+ context.stroke();
20
+ }
21
+ exports.drawGrabLine = drawGrabLine;
22
+ function drawGrab(container, particle, lineColor, opacity, mousePos) {
23
+ container.canvas.draw((ctx) => {
24
+ var _a;
25
+ const beginPos = particle.getPosition();
26
+ drawGrabLine(ctx, (_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, beginPos, mousePos, lineColor, opacity);
27
+ });
28
+ }
29
+ class Grabber extends engine_1.ExternalInteractorBase {
30
+ constructor(container) {
31
+ super(container);
32
+ }
33
+ clear() {
34
+ }
35
+ init() {
36
+ const container = this.container, grab = container.actualOptions.interactivity.modes.grab;
37
+ if (!grab) {
38
+ return;
39
+ }
40
+ container.retina.grabModeDistance = grab.distance * container.retina.pixelRatio;
41
+ }
42
+ interact() {
43
+ var _a, _b;
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const container = this.container, options = container.actualOptions, interactivity = options.interactivity;
46
+ if (!interactivity.modes.grab ||
47
+ !interactivity.events.onHover.enable ||
48
+ container.interactivity.status !== engine_1.mouseMoveEvent) {
49
+ return;
50
+ }
51
+ const mousePos = container.interactivity.mouse.position;
52
+ if (!mousePos) {
53
+ return;
54
+ }
55
+ const distance = container.retina.grabModeDistance;
56
+ if (!distance || distance < 0) {
57
+ return;
58
+ }
59
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
60
+ for (const particle of query) {
61
+ const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos);
62
+ if (pointDistance > distance) {
63
+ continue;
64
+ }
65
+ const grabLineOptions = interactivity.modes.grab.links, lineOpacity = grabLineOptions.opacity, opacityLine = lineOpacity - (pointDistance * lineOpacity) / distance;
66
+ if (opacityLine <= 0) {
67
+ continue;
68
+ }
69
+ const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : (_b = particle.options.links) === null || _b === void 0 ? void 0 : _b.color;
70
+ if (!container.particles.grabLineColor && optColor) {
71
+ const linksOptions = interactivity.modes.grab.links;
72
+ container.particles.grabLineColor = (0, engine_1.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
73
+ }
74
+ const colorLine = (0, engine_1.getLinkColor)(particle, undefined, container.particles.grabLineColor);
75
+ if (!colorLine) {
76
+ return;
77
+ }
78
+ drawGrab(container, particle, colorLine, opacityLine, mousePos);
79
+ }
80
+ });
81
+ }
82
+ isEnabled(particle) {
83
+ var _a;
84
+ 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;
85
+ return events.onHover.enable && !!mouse.position && (0, engine_1.isInArray)("grab", events.onHover.mode);
86
+ }
87
+ loadModeOptions(options, ...sources) {
88
+ if (!options.grab) {
89
+ options.grab = new Grab_1.Grab();
90
+ }
91
+ for (const source of sources) {
92
+ options.grab.load(source === null || source === void 0 ? void 0 : source.grab);
93
+ }
94
+ }
95
+ reset() {
96
+ }
97
+ }
98
+ exports.Grabber = Grabber;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Grab = void 0;
4
+ const GrabLinks_1 = require("./GrabLinks");
5
+ class Grab {
6
+ constructor() {
7
+ this.distance = 100;
8
+ this.links = new GrabLinks_1.GrabLinks();
9
+ }
10
+ get lineLinked() {
11
+ return this.links;
12
+ }
13
+ set lineLinked(value) {
14
+ this.links = value;
15
+ }
16
+ get line_linked() {
17
+ return this.links;
18
+ }
19
+ set line_linked(value) {
20
+ this.links = value;
21
+ }
22
+ load(data) {
23
+ var _a, _b;
24
+ if (!data) {
25
+ return;
26
+ }
27
+ if (data.distance !== undefined) {
28
+ this.distance = data.distance;
29
+ }
30
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
31
+ }
32
+ }
33
+ exports.Grab = Grab;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GrabLinks = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class GrabLinks {
6
+ constructor() {
7
+ this.blink = false;
8
+ this.consent = false;
9
+ this.opacity = 1;
10
+ }
11
+ load(data) {
12
+ if (!data) {
13
+ return;
14
+ }
15
+ if (data.blink !== undefined) {
16
+ this.blink = data.blink;
17
+ }
18
+ if (data.color !== undefined) {
19
+ this.color = engine_1.OptionsColor.create(this.color, data.color);
20
+ }
21
+ if (data.consent !== undefined) {
22
+ this.consent = data.consent;
23
+ }
24
+ if (data.opacity !== undefined) {
25
+ this.opacity = data.opacity;
26
+ }
27
+ }
28
+ }
29
+ exports.GrabLinks = GrabLinks;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/Types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.loadExternalGrabInteraction = void 0;
27
+ const Grabber_1 = require("./Grabber");
28
+ function loadExternalGrabInteraction(engine) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ yield engine.addInteractor("externalGrab", (container) => new Grabber_1.Grabber(container));
31
+ });
32
+ }
33
+ exports.loadExternalGrabInteraction = loadExternalGrabInteraction;
34
+ __exportStar(require("./Options/Classes/Grab"), exports);
35
+ __exportStar(require("./Options/Classes/GrabLinks"), exports);
36
+ __exportStar(require("./Options/Interfaces/IGrab"), exports);
37
+ __exportStar(require("./Options/Interfaces/IGrabLinks"), exports);
package/esm/Grabber.js ADDED
@@ -0,0 +1,82 @@
1
+ import { ExternalInteractorBase, drawLine, getDistance, getLinkColor, getLinkRandomColor, getStyleFromRgb, isInArray, mouseMoveEvent, } from "@tsparticles/engine";
2
+ import { Grab } from "./Options/Classes/Grab";
3
+ export function drawGrabLine(context, width, begin, end, colorLine, opacity) {
4
+ drawLine(context, begin, end);
5
+ context.strokeStyle = getStyleFromRgb(colorLine, opacity);
6
+ context.lineWidth = width;
7
+ context.stroke();
8
+ }
9
+ function drawGrab(container, particle, lineColor, opacity, mousePos) {
10
+ container.canvas.draw((ctx) => {
11
+ var _a;
12
+ const beginPos = particle.getPosition();
13
+ drawGrabLine(ctx, (_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, beginPos, mousePos, lineColor, opacity);
14
+ });
15
+ }
16
+ export class Grabber extends ExternalInteractorBase {
17
+ constructor(container) {
18
+ super(container);
19
+ }
20
+ clear() {
21
+ }
22
+ init() {
23
+ const container = this.container, grab = container.actualOptions.interactivity.modes.grab;
24
+ if (!grab) {
25
+ return;
26
+ }
27
+ container.retina.grabModeDistance = grab.distance * container.retina.pixelRatio;
28
+ }
29
+ async interact() {
30
+ var _a, _b;
31
+ const container = this.container, options = container.actualOptions, interactivity = options.interactivity;
32
+ if (!interactivity.modes.grab ||
33
+ !interactivity.events.onHover.enable ||
34
+ container.interactivity.status !== mouseMoveEvent) {
35
+ return;
36
+ }
37
+ const mousePos = container.interactivity.mouse.position;
38
+ if (!mousePos) {
39
+ return;
40
+ }
41
+ const distance = container.retina.grabModeDistance;
42
+ if (!distance || distance < 0) {
43
+ return;
44
+ }
45
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
46
+ for (const particle of query) {
47
+ const pos = particle.getPosition(), pointDistance = getDistance(pos, mousePos);
48
+ if (pointDistance > distance) {
49
+ continue;
50
+ }
51
+ const grabLineOptions = interactivity.modes.grab.links, lineOpacity = grabLineOptions.opacity, opacityLine = lineOpacity - (pointDistance * lineOpacity) / distance;
52
+ if (opacityLine <= 0) {
53
+ continue;
54
+ }
55
+ const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : (_b = particle.options.links) === null || _b === void 0 ? void 0 : _b.color;
56
+ if (!container.particles.grabLineColor && optColor) {
57
+ const linksOptions = interactivity.modes.grab.links;
58
+ container.particles.grabLineColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
59
+ }
60
+ const colorLine = getLinkColor(particle, undefined, container.particles.grabLineColor);
61
+ if (!colorLine) {
62
+ return;
63
+ }
64
+ drawGrab(container, particle, colorLine, opacityLine, mousePos);
65
+ }
66
+ }
67
+ isEnabled(particle) {
68
+ var _a;
69
+ 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;
70
+ return events.onHover.enable && !!mouse.position && isInArray("grab", events.onHover.mode);
71
+ }
72
+ loadModeOptions(options, ...sources) {
73
+ if (!options.grab) {
74
+ options.grab = new Grab();
75
+ }
76
+ for (const source of sources) {
77
+ options.grab.load(source === null || source === void 0 ? void 0 : source.grab);
78
+ }
79
+ }
80
+ reset() {
81
+ }
82
+ }
@@ -0,0 +1,29 @@
1
+ import { GrabLinks } from "./GrabLinks";
2
+ export class Grab {
3
+ constructor() {
4
+ this.distance = 100;
5
+ this.links = new GrabLinks();
6
+ }
7
+ get lineLinked() {
8
+ return this.links;
9
+ }
10
+ set lineLinked(value) {
11
+ this.links = value;
12
+ }
13
+ get line_linked() {
14
+ return this.links;
15
+ }
16
+ set line_linked(value) {
17
+ this.links = value;
18
+ }
19
+ load(data) {
20
+ var _a, _b;
21
+ if (!data) {
22
+ return;
23
+ }
24
+ if (data.distance !== undefined) {
25
+ this.distance = data.distance;
26
+ }
27
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
28
+ }
29
+ }
@@ -0,0 +1,25 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ export class GrabLinks {
3
+ constructor() {
4
+ this.blink = false;
5
+ this.consent = false;
6
+ this.opacity = 1;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.blink !== undefined) {
13
+ this.blink = data.blink;
14
+ }
15
+ if (data.color !== undefined) {
16
+ this.color = OptionsColor.create(this.color, data.color);
17
+ }
18
+ if (data.consent !== undefined) {
19
+ this.consent = data.consent;
20
+ }
21
+ if (data.opacity !== undefined) {
22
+ this.opacity = data.opacity;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { Grabber } from "./Grabber";
2
+ export async function loadExternalGrabInteraction(engine) {
3
+ await engine.addInteractor("externalGrab", (container) => new Grabber(container));
4
+ }
5
+ export * from "./Options/Classes/Grab";
6
+ export * from "./Options/Classes/GrabLinks";
7
+ export * from "./Options/Interfaces/IGrab";
8
+ export * from "./Options/Interfaces/IGrabLinks";