@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
@@ -0,0 +1,258 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
55
+ /******/
56
+ /************************************************************************/
57
+ /******/ /* webpack/runtime/define property getters */
58
+ /******/ (() => {
59
+ /******/ // define getter functions for harmony exports
60
+ /******/ __webpack_require__.d = (exports, definition) => {
61
+ /******/ for(var key in definition) {
62
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
63
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
64
+ /******/ }
65
+ /******/ }
66
+ /******/ };
67
+ /******/ })();
68
+ /******/
69
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
+ /******/ (() => {
71
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
+ /******/ })();
73
+ /******/
74
+ /******/ /* webpack/runtime/make namespace object */
75
+ /******/ (() => {
76
+ /******/ // define __esModule on exports
77
+ /******/ __webpack_require__.r = (exports) => {
78
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
79
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
80
+ /******/ }
81
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
82
+ /******/ };
83
+ /******/ })();
84
+ /******/
85
+ /************************************************************************/
86
+ var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
89
+ // ESM COMPAT FLAG
90
+ __webpack_require__.r(__webpack_exports__);
91
+
92
+ // EXPORTS
93
+ __webpack_require__.d(__webpack_exports__, {
94
+ "Grab": () => (/* reexport */ Grab),
95
+ "GrabLinks": () => (/* reexport */ GrabLinks),
96
+ "loadExternalGrabInteraction": () => (/* binding */ loadExternalGrabInteraction)
97
+ });
98
+
99
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
100
+ var engine_root_window_ = __webpack_require__(533);
101
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/GrabLinks.js
102
+
103
+ class GrabLinks {
104
+ constructor() {
105
+ this.blink = false;
106
+ this.consent = false;
107
+ this.opacity = 1;
108
+ }
109
+ load(data) {
110
+ if (!data) {
111
+ return;
112
+ }
113
+ if (data.blink !== undefined) {
114
+ this.blink = data.blink;
115
+ }
116
+ if (data.color !== undefined) {
117
+ this.color = engine_root_window_.OptionsColor.create(this.color, data.color);
118
+ }
119
+ if (data.consent !== undefined) {
120
+ this.consent = data.consent;
121
+ }
122
+ if (data.opacity !== undefined) {
123
+ this.opacity = data.opacity;
124
+ }
125
+ }
126
+ }
127
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Grab.js
128
+
129
+ class Grab {
130
+ constructor() {
131
+ this.distance = 100;
132
+ this.links = new GrabLinks();
133
+ }
134
+ get lineLinked() {
135
+ return this.links;
136
+ }
137
+ set lineLinked(value) {
138
+ this.links = value;
139
+ }
140
+ get line_linked() {
141
+ return this.links;
142
+ }
143
+ set line_linked(value) {
144
+ this.links = value;
145
+ }
146
+ load(data) {
147
+ var _a, _b;
148
+ if (!data) {
149
+ return;
150
+ }
151
+ if (data.distance !== undefined) {
152
+ this.distance = data.distance;
153
+ }
154
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
155
+ }
156
+ }
157
+ ;// CONCATENATED MODULE: ./dist/browser/Grabber.js
158
+
159
+
160
+ function drawGrabLine(context, width, begin, end, colorLine, opacity) {
161
+ (0,engine_root_window_.drawLine)(context, begin, end);
162
+ context.strokeStyle = (0,engine_root_window_.getStyleFromRgb)(colorLine, opacity);
163
+ context.lineWidth = width;
164
+ context.stroke();
165
+ }
166
+ function drawGrab(container, particle, lineColor, opacity, mousePos) {
167
+ container.canvas.draw(ctx => {
168
+ var _a;
169
+ const beginPos = particle.getPosition();
170
+ drawGrabLine(ctx, (_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, beginPos, mousePos, lineColor, opacity);
171
+ });
172
+ }
173
+ class Grabber extends engine_root_window_.ExternalInteractorBase {
174
+ constructor(container) {
175
+ super(container);
176
+ }
177
+ clear() {}
178
+ init() {
179
+ const container = this.container,
180
+ grab = container.actualOptions.interactivity.modes.grab;
181
+ if (!grab) {
182
+ return;
183
+ }
184
+ container.retina.grabModeDistance = grab.distance * container.retina.pixelRatio;
185
+ }
186
+ async interact() {
187
+ var _a, _b;
188
+ const container = this.container,
189
+ options = container.actualOptions,
190
+ interactivity = options.interactivity;
191
+ if (!interactivity.modes.grab || !interactivity.events.onHover.enable || container.interactivity.status !== engine_root_window_.mouseMoveEvent) {
192
+ return;
193
+ }
194
+ const mousePos = container.interactivity.mouse.position;
195
+ if (!mousePos) {
196
+ return;
197
+ }
198
+ const distance = container.retina.grabModeDistance;
199
+ if (!distance || distance < 0) {
200
+ return;
201
+ }
202
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
203
+ for (const particle of query) {
204
+ const pos = particle.getPosition(),
205
+ pointDistance = (0,engine_root_window_.getDistance)(pos, mousePos);
206
+ if (pointDistance > distance) {
207
+ continue;
208
+ }
209
+ const grabLineOptions = interactivity.modes.grab.links,
210
+ lineOpacity = grabLineOptions.opacity,
211
+ opacityLine = lineOpacity - pointDistance * lineOpacity / distance;
212
+ if (opacityLine <= 0) {
213
+ continue;
214
+ }
215
+ const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : (_b = particle.options.links) === null || _b === void 0 ? void 0 : _b.color;
216
+ if (!container.particles.grabLineColor && optColor) {
217
+ const linksOptions = interactivity.modes.grab.links;
218
+ container.particles.grabLineColor = (0,engine_root_window_.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
219
+ }
220
+ const colorLine = (0,engine_root_window_.getLinkColor)(particle, undefined, container.particles.grabLineColor);
221
+ if (!colorLine) {
222
+ return;
223
+ }
224
+ drawGrab(container, particle, colorLine, opacityLine, mousePos);
225
+ }
226
+ }
227
+ isEnabled(particle) {
228
+ var _a;
229
+ const container = this.container,
230
+ mouse = container.interactivity.mouse,
231
+ events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
232
+ return events.onHover.enable && !!mouse.position && (0,engine_root_window_.isInArray)("grab", events.onHover.mode);
233
+ }
234
+ loadModeOptions(options, ...sources) {
235
+ if (!options.grab) {
236
+ options.grab = new Grab();
237
+ }
238
+ for (const source of sources) {
239
+ options.grab.load(source === null || source === void 0 ? void 0 : source.grab);
240
+ }
241
+ }
242
+ reset() {}
243
+ }
244
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
245
+
246
+ async function loadExternalGrabInteraction(engine) {
247
+ await engine.addInteractor("externalGrab", container => new Grabber(container));
248
+ }
249
+
250
+
251
+
252
+
253
+ })();
254
+
255
+ /******/ return __webpack_exports__;
256
+ /******/ })()
257
+ ;
258
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.interaction.external.grab.min.js.LICENSE.txt */
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function n(t){var o=i[t];if(void 0!==o)return o.exports;var r=i[t]={exports:{}};return e[t](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{Grab:()=>i,GrabLinks:()=>e,loadExternalGrabInteraction:()=>a});var t=n(533);class e{constructor(){this.blink=!1,this.consent=!1,this.opacity=1}load(e){e&&(void 0!==e.blink&&(this.blink=e.blink),void 0!==e.color&&(this.color=t.OptionsColor.create(this.color,e.color)),void 0!==e.consent&&(this.consent=e.consent),void 0!==e.opacity&&(this.opacity=e.opacity))}}class i{constructor(){this.distance=100,this.links=new e}get lineLinked(){return this.links}set lineLinked(t){this.links=t}get line_linked(){return this.links}set line_linked(t){this.links=t}load(t){var e,i;t&&(void 0!==t.distance&&(this.distance=t.distance),this.links.load(null!==(i=null!==(e=t.links)&&void 0!==e?e:t.lineLinked)&&void 0!==i?i:t.line_linked))}}function r(e,i,n,o,r){e.canvas.draw((e=>{var s;const a=i.getPosition();!function(e,i,n,o,r,s){(0,t.drawLine)(e,n,o),e.strokeStyle=(0,t.getStyleFromRgb)(r,s),e.lineWidth=i,e.stroke()}(e,null!==(s=i.retina.linksWidth)&&void 0!==s?s:0,a,r,n,o)}))}class s extends t.ExternalInteractorBase{constructor(t){super(t)}clear(){}init(){const t=this.container,e=t.actualOptions.interactivity.modes.grab;e&&(t.retina.grabModeDistance=e.distance*t.retina.pixelRatio)}async interact(){var e,i;const n=this.container,o=n.actualOptions.interactivity;if(!o.modes.grab||!o.events.onHover.enable||n.interactivity.status!==t.mouseMoveEvent)return;const s=n.interactivity.mouse.position;if(!s)return;const a=n.retina.grabModeDistance;if(!a||a<0)return;const l=n.particles.quadTree.queryCircle(s,a,(t=>this.isEnabled(t)));for(const c of l){const l=c.getPosition(),d=(0,t.getDistance)(l,s);if(d>a)continue;const u=o.modes.grab.links,v=u.opacity,p=v-d*v/a;if(p<=0)continue;const b=null!==(e=u.color)&&void 0!==e?e:null===(i=c.options.links)||void 0===i?void 0:i.color;if(!n.particles.grabLineColor&&b){const e=o.modes.grab.links;n.particles.grabLineColor=(0,t.getLinkRandomColor)(b,e.blink,e.consent)}const f=(0,t.getLinkColor)(c,void 0,n.particles.grabLineColor);if(!f)return;r(n,c,f,p,s)}}isEnabled(e){var i;const n=this.container,o=n.interactivity.mouse,r=(null!==(i=null==e?void 0:e.interactivity)&&void 0!==i?i:n.actualOptions.interactivity).events;return r.onHover.enable&&!!o.position&&(0,t.isInArray)("grab",r.onHover.mode)}loadModeOptions(t,...e){t.grab||(t.grab=new i);for(const i of e)t.grab.load(null==i?void 0:i.grab)}reset(){}}async function a(t){await t.addInteractor("externalGrab",(t=>new s(t)))}})(),o})()));
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
@@ -0,0 +1,13 @@
1
+ import { ExternalInteractorBase } from "@tsparticles/engine";
2
+ import type { GrabContainer, GrabMode, IGrabMode } from "./Types";
3
+ import type { ICoordinates, IModes, IRgb, Modes, Particle, RecursivePartial } from "@tsparticles/engine";
4
+ export declare function drawGrabLine(context: CanvasRenderingContext2D, width: number, begin: ICoordinates, end: ICoordinates, colorLine: IRgb, opacity: number): void;
5
+ export declare class Grabber extends ExternalInteractorBase<GrabContainer> {
6
+ constructor(container: GrabContainer);
7
+ clear(): void;
8
+ init(): void;
9
+ interact(): Promise<void>;
10
+ isEnabled(particle?: Particle): boolean;
11
+ loadModeOptions(options: Modes & GrabMode, ...sources: RecursivePartial<(IModes & IGrabMode) | undefined>[]): void;
12
+ reset(): void;
13
+ }
@@ -0,0 +1,13 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import { GrabLinks } from "./GrabLinks";
3
+ import type { IGrab } from "../Interfaces/IGrab";
4
+ export declare class Grab implements IGrab, IOptionLoader<IGrab> {
5
+ distance: number;
6
+ links: GrabLinks;
7
+ constructor();
8
+ get lineLinked(): GrabLinks;
9
+ set lineLinked(value: GrabLinks);
10
+ get line_linked(): GrabLinks;
11
+ set line_linked(value: GrabLinks);
12
+ load(data?: RecursivePartial<IGrab>): void;
13
+ }
@@ -0,0 +1,11 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IGrabLinks } from "../Interfaces/IGrabLinks";
3
+ import { OptionsColor } from "@tsparticles/engine";
4
+ export declare class GrabLinks implements IGrabLinks, IOptionLoader<IGrabLinks> {
5
+ blink: boolean;
6
+ color?: OptionsColor;
7
+ consent: boolean;
8
+ opacity: number;
9
+ constructor();
10
+ load(data?: RecursivePartial<IGrabLinks>): void;
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { GrabMode } from "../../Types";
2
+ import type { Options } from "@tsparticles/engine";
3
+ export type GrabOptions = Options & {
4
+ interactivity: {
5
+ modes: GrabMode;
6
+ };
7
+ };
@@ -0,0 +1,7 @@
1
+ import type { IGrabLinks } from "./IGrabLinks";
2
+ export interface IGrab {
3
+ distance: number;
4
+ lineLinked: IGrabLinks;
5
+ line_linked: IGrabLinks;
6
+ links: IGrabLinks;
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { IOptionsColor } from "@tsparticles/engine";
2
+ export interface IGrabLinks {
3
+ blink: boolean;
4
+ color?: string | IOptionsColor;
5
+ consent: boolean;
6
+ opacity: number;
7
+ }
@@ -0,0 +1,19 @@
1
+ import type { Container, IRgb } from "@tsparticles/engine";
2
+ import type { Grab } from "./Options/Classes/Grab";
3
+ import type { GrabOptions } from "./Options/Classes/GrabOptions";
4
+ import type { IGrab } from "./Options/Interfaces/IGrab";
5
+ export type IGrabMode = {
6
+ grab: IGrab;
7
+ };
8
+ export type GrabMode = {
9
+ grab?: Grab;
10
+ };
11
+ export type GrabContainer = Container & {
12
+ actualOptions: GrabOptions;
13
+ particles: {
14
+ grabLineColor?: IRgb | string;
15
+ };
16
+ retina: {
17
+ grabModeDistance?: number;
18
+ };
19
+ };
@@ -0,0 +1,6 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadExternalGrabInteraction(engine: Engine): Promise<void>;
3
+ export * from "./Options/Classes/Grab";
4
+ export * from "./Options/Classes/GrabLinks";
5
+ export * from "./Options/Interfaces/IGrab";
6
+ export * from "./Options/Interfaces/IGrabLinks";
package/umd/Grabber.js ADDED
@@ -0,0 +1,97 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Grab"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
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
+ async interact() {
43
+ var _a, _b;
44
+ const container = this.container, options = container.actualOptions, interactivity = options.interactivity;
45
+ if (!interactivity.modes.grab ||
46
+ !interactivity.events.onHover.enable ||
47
+ container.interactivity.status !== engine_1.mouseMoveEvent) {
48
+ return;
49
+ }
50
+ const mousePos = container.interactivity.mouse.position;
51
+ if (!mousePos) {
52
+ return;
53
+ }
54
+ const distance = container.retina.grabModeDistance;
55
+ if (!distance || distance < 0) {
56
+ return;
57
+ }
58
+ const query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
59
+ for (const particle of query) {
60
+ const pos = particle.getPosition(), pointDistance = (0, engine_1.getDistance)(pos, mousePos);
61
+ if (pointDistance > distance) {
62
+ continue;
63
+ }
64
+ const grabLineOptions = interactivity.modes.grab.links, lineOpacity = grabLineOptions.opacity, opacityLine = lineOpacity - (pointDistance * lineOpacity) / distance;
65
+ if (opacityLine <= 0) {
66
+ continue;
67
+ }
68
+ const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : (_b = particle.options.links) === null || _b === void 0 ? void 0 : _b.color;
69
+ if (!container.particles.grabLineColor && optColor) {
70
+ const linksOptions = interactivity.modes.grab.links;
71
+ container.particles.grabLineColor = (0, engine_1.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
72
+ }
73
+ const colorLine = (0, engine_1.getLinkColor)(particle, undefined, container.particles.grabLineColor);
74
+ if (!colorLine) {
75
+ return;
76
+ }
77
+ drawGrab(container, particle, colorLine, opacityLine, mousePos);
78
+ }
79
+ }
80
+ isEnabled(particle) {
81
+ var _a;
82
+ 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;
83
+ return events.onHover.enable && !!mouse.position && (0, engine_1.isInArray)("grab", events.onHover.mode);
84
+ }
85
+ loadModeOptions(options, ...sources) {
86
+ if (!options.grab) {
87
+ options.grab = new Grab_1.Grab();
88
+ }
89
+ for (const source of sources) {
90
+ options.grab.load(source === null || source === void 0 ? void 0 : source.grab);
91
+ }
92
+ }
93
+ reset() {
94
+ }
95
+ }
96
+ exports.Grabber = Grabber;
97
+ });
@@ -0,0 +1,43 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./GrabLinks"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Grab = void 0;
13
+ const GrabLinks_1 = require("./GrabLinks");
14
+ class Grab {
15
+ constructor() {
16
+ this.distance = 100;
17
+ this.links = new GrabLinks_1.GrabLinks();
18
+ }
19
+ get lineLinked() {
20
+ return this.links;
21
+ }
22
+ set lineLinked(value) {
23
+ this.links = value;
24
+ }
25
+ get line_linked() {
26
+ return this.links;
27
+ }
28
+ set line_linked(value) {
29
+ this.links = value;
30
+ }
31
+ load(data) {
32
+ var _a, _b;
33
+ if (!data) {
34
+ return;
35
+ }
36
+ if (data.distance !== undefined) {
37
+ this.distance = data.distance;
38
+ }
39
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
40
+ }
41
+ }
42
+ exports.Grab = Grab;
43
+ });
@@ -0,0 +1,39 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GrabLinks = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class GrabLinks {
15
+ constructor() {
16
+ this.blink = false;
17
+ this.consent = false;
18
+ this.opacity = 1;
19
+ }
20
+ load(data) {
21
+ if (!data) {
22
+ return;
23
+ }
24
+ if (data.blink !== undefined) {
25
+ this.blink = data.blink;
26
+ }
27
+ if (data.color !== undefined) {
28
+ this.color = engine_1.OptionsColor.create(this.color, data.color);
29
+ }
30
+ if (data.consent !== undefined) {
31
+ this.consent = data.consent;
32
+ }
33
+ if (data.opacity !== undefined) {
34
+ this.opacity = data.opacity;
35
+ }
36
+ }
37
+ }
38
+ exports.GrabLinks = GrabLinks;
39
+ });
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/Types.js ADDED
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/index.js ADDED
@@ -0,0 +1,36 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
+ };
15
+ (function (factory) {
16
+ if (typeof module === "object" && typeof module.exports === "object") {
17
+ var v = factory(require, exports);
18
+ if (v !== undefined) module.exports = v;
19
+ }
20
+ else if (typeof define === "function" && define.amd) {
21
+ define(["require", "exports", "./Grabber", "./Options/Classes/Grab", "./Options/Classes/GrabLinks", "./Options/Interfaces/IGrab", "./Options/Interfaces/IGrabLinks"], factory);
22
+ }
23
+ })(function (require, exports) {
24
+ "use strict";
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.loadExternalGrabInteraction = void 0;
27
+ const Grabber_1 = require("./Grabber");
28
+ async function loadExternalGrabInteraction(engine) {
29
+ await engine.addInteractor("externalGrab", (container) => new Grabber_1.Grabber(container));
30
+ }
31
+ exports.loadExternalGrabInteraction = loadExternalGrabInteraction;
32
+ __exportStar(require("./Options/Classes/Grab"), exports);
33
+ __exportStar(require("./Options/Classes/GrabLinks"), exports);
34
+ __exportStar(require("./Options/Interfaces/IGrab"), exports);
35
+ __exportStar(require("./Options/Interfaces/IGrabLinks"), exports);
36
+ });