@tsparticles/interaction-external-connect 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/Connector.js +95 -0
  4. package/browser/Options/Classes/Connect.js +33 -0
  5. package/browser/Options/Classes/ConnectLinks.js +13 -0
  6. package/browser/Options/Classes/ConnectOptions.js +1 -0
  7. package/browser/Options/Interfaces/IConnect.js +1 -0
  8. package/browser/Options/Interfaces/IConnectLinks.js +1 -0
  9. package/browser/Types.js +1 -0
  10. package/browser/index.js +8 -0
  11. package/cjs/Connector.js +110 -0
  12. package/cjs/Options/Classes/Connect.js +37 -0
  13. package/cjs/Options/Classes/ConnectLinks.js +17 -0
  14. package/cjs/Options/Classes/ConnectOptions.js +2 -0
  15. package/cjs/Options/Interfaces/IConnect.js +2 -0
  16. package/cjs/Options/Interfaces/IConnectLinks.js +2 -0
  17. package/cjs/Types.js +2 -0
  18. package/cjs/index.js +37 -0
  19. package/esm/Connector.js +95 -0
  20. package/esm/Options/Classes/Connect.js +33 -0
  21. package/esm/Options/Classes/ConnectLinks.js +13 -0
  22. package/esm/Options/Classes/ConnectOptions.js +1 -0
  23. package/esm/Options/Interfaces/IConnect.js +1 -0
  24. package/esm/Options/Interfaces/IConnectLinks.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.connect.js +268 -0
  30. package/tsparticles.interaction.external.connect.min.js +2 -0
  31. package/tsparticles.interaction.external.connect.min.js.LICENSE.txt +8 -0
  32. package/types/Connector.d.ts +12 -0
  33. package/types/Options/Classes/Connect.d.ts +14 -0
  34. package/types/Options/Classes/ConnectLinks.d.ts +7 -0
  35. package/types/Options/Classes/ConnectOptions.d.ts +7 -0
  36. package/types/Options/Interfaces/IConnect.d.ts +8 -0
  37. package/types/Options/Interfaces/IConnectLinks.d.ts +3 -0
  38. package/types/Types.d.ts +17 -0
  39. package/types/index.d.ts +6 -0
  40. package/umd/Connector.js +109 -0
  41. package/umd/Options/Classes/Connect.js +47 -0
  42. package/umd/Options/Classes/ConnectLinks.js +27 -0
  43. package/umd/Options/Classes/ConnectOptions.js +12 -0
  44. package/umd/Options/Interfaces/IConnect.js +12 -0
  45. package/umd/Options/Interfaces/IConnectLinks.js +12 -0
  46. package/umd/Types.js +12 -0
  47. package/umd/index.js +36 -0
@@ -0,0 +1,268 @@
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
+ "Connect": () => (/* reexport */ Connect),
95
+ "ConnectLinks": () => (/* reexport */ ConnectLinks),
96
+ "loadExternalConnectInteraction": () => (/* binding */ loadExternalConnectInteraction)
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/ConnectLinks.js
102
+ class ConnectLinks {
103
+ constructor() {
104
+ this.opacity = 0.5;
105
+ }
106
+ load(data) {
107
+ if (!data) {
108
+ return;
109
+ }
110
+ if (data.opacity !== undefined) {
111
+ this.opacity = data.opacity;
112
+ }
113
+ }
114
+ }
115
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Connect.js
116
+
117
+ class Connect {
118
+ constructor() {
119
+ this.distance = 80;
120
+ this.links = new ConnectLinks();
121
+ this.radius = 60;
122
+ }
123
+ get lineLinked() {
124
+ return this.links;
125
+ }
126
+ set lineLinked(value) {
127
+ this.links = value;
128
+ }
129
+ get line_linked() {
130
+ return this.links;
131
+ }
132
+ set line_linked(value) {
133
+ this.links = value;
134
+ }
135
+ load(data) {
136
+ var _a, _b;
137
+ if (!data) {
138
+ return;
139
+ }
140
+ if (data.distance !== undefined) {
141
+ this.distance = data.distance;
142
+ }
143
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
144
+ if (data.radius !== undefined) {
145
+ this.radius = data.radius;
146
+ }
147
+ }
148
+ }
149
+ ;// CONCATENATED MODULE: ./dist/browser/Connector.js
150
+
151
+
152
+ function gradient(context, p1, p2, opacity) {
153
+ const gradStop = Math.floor(p2.getRadius() / p1.getRadius()),
154
+ color1 = p1.getFillColor(),
155
+ color2 = p2.getFillColor();
156
+ if (!color1 || !color2) {
157
+ return;
158
+ }
159
+ const sourcePos = p1.getPosition(),
160
+ destPos = p2.getPosition(),
161
+ midRgb = (0,engine_root_window_.colorMix)(color1, color2, p1.getRadius(), p2.getRadius()),
162
+ grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
163
+ grad.addColorStop(0, (0,engine_root_window_.getStyleFromHsl)(color1, opacity));
164
+ grad.addColorStop(gradStop > 1 ? 1 : gradStop, (0,engine_root_window_.getStyleFromRgb)(midRgb, opacity));
165
+ grad.addColorStop(1, (0,engine_root_window_.getStyleFromHsl)(color2, opacity));
166
+ return grad;
167
+ }
168
+ function drawConnectLine(context, width, lineStyle, begin, end) {
169
+ (0,engine_root_window_.drawLine)(context, begin, end);
170
+ context.lineWidth = width;
171
+ context.strokeStyle = lineStyle;
172
+ context.stroke();
173
+ }
174
+ function lineStyle(container, ctx, p1, p2) {
175
+ const options = container.actualOptions,
176
+ connectOptions = options.interactivity.modes.connect;
177
+ if (!connectOptions) {
178
+ return;
179
+ }
180
+ return gradient(ctx, p1, p2, connectOptions.links.opacity);
181
+ }
182
+ function drawConnection(container, p1, p2) {
183
+ container.canvas.draw(ctx => {
184
+ var _a;
185
+ const ls = lineStyle(container, ctx, p1, p2);
186
+ if (!ls) {
187
+ return;
188
+ }
189
+ const pos1 = p1.getPosition(),
190
+ pos2 = p2.getPosition();
191
+ drawConnectLine(ctx, (_a = p1.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, ls, pos1, pos2);
192
+ });
193
+ }
194
+ class Connector extends engine_root_window_.ExternalInteractorBase {
195
+ constructor(container) {
196
+ super(container);
197
+ }
198
+ clear() {}
199
+ init() {
200
+ const container = this.container,
201
+ connect = container.actualOptions.interactivity.modes.connect;
202
+ if (!connect) {
203
+ return;
204
+ }
205
+ container.retina.connectModeDistance = connect.distance * container.retina.pixelRatio;
206
+ container.retina.connectModeRadius = connect.radius * container.retina.pixelRatio;
207
+ }
208
+ async interact() {
209
+ const container = this.container,
210
+ options = container.actualOptions;
211
+ if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
212
+ const mousePos = container.interactivity.mouse.position;
213
+ if (!container.retina.connectModeDistance || container.retina.connectModeDistance < 0 || !container.retina.connectModeRadius || container.retina.connectModeRadius < 0 || !mousePos) {
214
+ return;
215
+ }
216
+ const distance = Math.abs(container.retina.connectModeRadius),
217
+ query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
218
+ let i = 0;
219
+ for (const p1 of query) {
220
+ const pos1 = p1.getPosition();
221
+ for (const p2 of query.slice(i + 1)) {
222
+ const pos2 = p2.getPosition(),
223
+ distMax = Math.abs(container.retina.connectModeDistance),
224
+ xDiff = Math.abs(pos1.x - pos2.x),
225
+ yDiff = Math.abs(pos1.y - pos2.y);
226
+ if (xDiff < distMax && yDiff < distMax) {
227
+ drawConnection(container, p1, p2);
228
+ }
229
+ }
230
+ ++i;
231
+ }
232
+ }
233
+ }
234
+ isEnabled(particle) {
235
+ var _a;
236
+ const container = this.container,
237
+ mouse = container.interactivity.mouse,
238
+ events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
239
+ if (!(events.onHover.enable && mouse.position)) {
240
+ return false;
241
+ }
242
+ return (0,engine_root_window_.isInArray)("connect", events.onHover.mode);
243
+ }
244
+ loadModeOptions(options, ...sources) {
245
+ if (!options.connect) {
246
+ options.connect = new Connect();
247
+ }
248
+ for (const source of sources) {
249
+ options.connect.load(source === null || source === void 0 ? void 0 : source.connect);
250
+ }
251
+ }
252
+ reset() {}
253
+ }
254
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
255
+
256
+ async function loadExternalConnectInteraction(engine) {
257
+ await engine.addInteractor("externalConnect", container => new Connector(container));
258
+ }
259
+
260
+
261
+
262
+
263
+ })();
264
+
265
+ /******/ return __webpack_exports__;
266
+ /******/ })()
267
+ ;
268
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.interaction.external.connect.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 n="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},n={};function i(t){var o=n[t];if(void 0!==o)return o.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,i),r.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{i.r(o),i.d(o,{Connect:()=>n,ConnectLinks:()=>e,loadExternalConnectInteraction:()=>c});var t=i(533);class e{constructor(){this.opacity=.5}load(t){t&&void 0!==t.opacity&&(this.opacity=t.opacity)}}class n{constructor(){this.distance=80,this.links=new e,this.radius=60}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,n;t&&(void 0!==t.distance&&(this.distance=t.distance),this.links.load(null!==(n=null!==(e=t.links)&&void 0!==e?e:t.lineLinked)&&void 0!==n?n:t.line_linked),void 0!==t.radius&&(this.radius=t.radius))}}function r(e,n,i,o){const r=e.actualOptions.interactivity.modes.connect;if(r)return function(e,n,i,o){const r=Math.floor(i.getRadius()/n.getRadius()),s=n.getFillColor(),a=i.getFillColor();if(!s||!a)return;const c=n.getPosition(),l=i.getPosition(),d=(0,t.colorMix)(s,a,n.getRadius(),i.getRadius()),u=e.createLinearGradient(c.x,c.y,l.x,l.y);return u.addColorStop(0,(0,t.getStyleFromHsl)(s,o)),u.addColorStop(r>1?1:r,(0,t.getStyleFromRgb)(d,o)),u.addColorStop(1,(0,t.getStyleFromHsl)(a,o)),u}(n,i,o,r.links.opacity)}function s(e,n,i){e.canvas.draw((o=>{var s;const a=r(e,o,n,i);if(!a)return;const c=n.getPosition(),l=i.getPosition();!function(e,n,i,o,r){(0,t.drawLine)(e,o,r),e.lineWidth=n,e.strokeStyle=i,e.stroke()}(o,null!==(s=n.retina.linksWidth)&&void 0!==s?s:0,a,c,l)}))}class a extends t.ExternalInteractorBase{constructor(t){super(t)}clear(){}init(){const t=this.container,e=t.actualOptions.interactivity.modes.connect;e&&(t.retina.connectModeDistance=e.distance*t.retina.pixelRatio,t.retina.connectModeRadius=e.radius*t.retina.pixelRatio)}async interact(){const t=this.container;if(t.actualOptions.interactivity.events.onHover.enable&&"pointermove"===t.interactivity.status){const e=t.interactivity.mouse.position;if(!t.retina.connectModeDistance||t.retina.connectModeDistance<0||!t.retina.connectModeRadius||t.retina.connectModeRadius<0||!e)return;const n=Math.abs(t.retina.connectModeRadius),i=t.particles.quadTree.queryCircle(e,n,(t=>this.isEnabled(t)));let o=0;for(const e of i){const n=e.getPosition();for(const r of i.slice(o+1)){const i=r.getPosition(),o=Math.abs(t.retina.connectModeDistance),a=Math.abs(n.x-i.x),c=Math.abs(n.y-i.y);a<o&&c<o&&s(t,e,r)}++o}}}isEnabled(e){var n;const i=this.container,o=i.interactivity.mouse,r=(null!==(n=null==e?void 0:e.interactivity)&&void 0!==n?n:i.actualOptions.interactivity).events;return!(!r.onHover.enable||!o.position)&&(0,t.isInArray)("connect",r.onHover.mode)}loadModeOptions(t,...e){t.connect||(t.connect=new n);for(const n of e)t.connect.load(null==n?void 0:n.connect)}reset(){}}async function c(t){await t.addInteractor("externalConnect",(t=>new a(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,12 @@
1
+ import type { ConnectContainer, ConnectMode, IConnectMode } from "./Types";
2
+ import { ExternalInteractorBase } from "@tsparticles/engine";
3
+ import type { IModes, Modes, Particle, RecursivePartial } from "@tsparticles/engine";
4
+ export declare class Connector extends ExternalInteractorBase<ConnectContainer> {
5
+ constructor(container: ConnectContainer);
6
+ clear(): void;
7
+ init(): void;
8
+ interact(): Promise<void>;
9
+ isEnabled(particle?: Particle): boolean;
10
+ loadModeOptions(options: Modes & ConnectMode, ...sources: RecursivePartial<(IModes & IConnectMode) | undefined>[]): void;
11
+ reset(): void;
12
+ }
@@ -0,0 +1,14 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import { ConnectLinks } from "./ConnectLinks";
3
+ import type { IConnect } from "../Interfaces/IConnect";
4
+ export declare class Connect implements IConnect, IOptionLoader<IConnect> {
5
+ distance: number;
6
+ links: ConnectLinks;
7
+ radius: number;
8
+ constructor();
9
+ get lineLinked(): ConnectLinks;
10
+ set lineLinked(value: ConnectLinks);
11
+ get line_linked(): ConnectLinks;
12
+ set line_linked(value: ConnectLinks);
13
+ load(data?: RecursivePartial<IConnect>): void;
14
+ }
@@ -0,0 +1,7 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IConnectLinks } from "../Interfaces/IConnectLinks";
3
+ export declare class ConnectLinks implements IConnectLinks, IOptionLoader<IConnectLinks> {
4
+ opacity: number;
5
+ constructor();
6
+ load(data?: RecursivePartial<IConnectLinks>): void;
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { ConnectMode } from "../../Types";
2
+ import type { Options } from "@tsparticles/engine";
3
+ export type ConnectOptions = Options & {
4
+ interactivity: {
5
+ modes: ConnectMode;
6
+ };
7
+ };
@@ -0,0 +1,8 @@
1
+ import type { IConnectLinks } from "./IConnectLinks";
2
+ export interface IConnect {
3
+ distance: number;
4
+ lineLinked: IConnectLinks;
5
+ line_linked: IConnectLinks;
6
+ links: IConnectLinks;
7
+ radius: number;
8
+ }
@@ -0,0 +1,3 @@
1
+ export interface IConnectLinks {
2
+ opacity: number;
3
+ }
@@ -0,0 +1,17 @@
1
+ import type { Connect } from "./Options/Classes/Connect";
2
+ import type { ConnectOptions } from "./Options/Classes/ConnectOptions";
3
+ import type { Container } from "@tsparticles/engine";
4
+ import type { IConnect } from "./Options/Interfaces/IConnect";
5
+ export type IConnectMode = {
6
+ connect: IConnect;
7
+ };
8
+ export type ConnectMode = {
9
+ connect?: Connect;
10
+ };
11
+ export type ConnectContainer = Container & {
12
+ actualOptions: ConnectOptions;
13
+ retina: {
14
+ connectModeDistance?: number;
15
+ connectModeRadius?: number;
16
+ };
17
+ };
@@ -0,0 +1,6 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadExternalConnectInteraction(engine: Engine): Promise<void>;
3
+ export * from "./Options/Classes/Connect";
4
+ export * from "./Options/Classes/ConnectLinks";
5
+ export * from "./Options/Interfaces/IConnect";
6
+ export * from "./Options/Interfaces/IConnectLinks";
@@ -0,0 +1,109 @@
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/Connect"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Connector = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Connect_1 = require("./Options/Classes/Connect");
15
+ function gradient(context, p1, p2, opacity) {
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
+ }
50
+ class Connector extends engine_1.ExternalInteractorBase {
51
+ constructor(container) {
52
+ super(container);
53
+ }
54
+ clear() {
55
+ }
56
+ init() {
57
+ const container = this.container, connect = container.actualOptions.interactivity.modes.connect;
58
+ if (!connect) {
59
+ return;
60
+ }
61
+ container.retina.connectModeDistance = connect.distance * container.retina.pixelRatio;
62
+ container.retina.connectModeRadius = connect.radius * container.retina.pixelRatio;
63
+ }
64
+ async interact() {
65
+ const container = this.container, options = container.actualOptions;
66
+ if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
67
+ const mousePos = container.interactivity.mouse.position;
68
+ if (!container.retina.connectModeDistance ||
69
+ container.retina.connectModeDistance < 0 ||
70
+ !container.retina.connectModeRadius ||
71
+ container.retina.connectModeRadius < 0 ||
72
+ !mousePos) {
73
+ return;
74
+ }
75
+ const distance = Math.abs(container.retina.connectModeRadius), query = container.particles.quadTree.queryCircle(mousePos, distance, (p) => this.isEnabled(p));
76
+ let i = 0;
77
+ for (const p1 of query) {
78
+ const pos1 = p1.getPosition();
79
+ for (const p2 of query.slice(i + 1)) {
80
+ const pos2 = p2.getPosition(), distMax = Math.abs(container.retina.connectModeDistance), xDiff = Math.abs(pos1.x - pos2.x), yDiff = Math.abs(pos1.y - pos2.y);
81
+ if (xDiff < distMax && yDiff < distMax) {
82
+ drawConnection(container, p1, p2);
83
+ }
84
+ }
85
+ ++i;
86
+ }
87
+ }
88
+ }
89
+ isEnabled(particle) {
90
+ var _a;
91
+ 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;
92
+ if (!(events.onHover.enable && mouse.position)) {
93
+ return false;
94
+ }
95
+ return (0, engine_1.isInArray)("connect", events.onHover.mode);
96
+ }
97
+ loadModeOptions(options, ...sources) {
98
+ if (!options.connect) {
99
+ options.connect = new Connect_1.Connect();
100
+ }
101
+ for (const source of sources) {
102
+ options.connect.load(source === null || source === void 0 ? void 0 : source.connect);
103
+ }
104
+ }
105
+ reset() {
106
+ }
107
+ }
108
+ exports.Connector = Connector;
109
+ });
@@ -0,0 +1,47 @@
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", "./ConnectLinks"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Connect = void 0;
13
+ const ConnectLinks_1 = require("./ConnectLinks");
14
+ class Connect {
15
+ constructor() {
16
+ this.distance = 80;
17
+ this.links = new ConnectLinks_1.ConnectLinks();
18
+ this.radius = 60;
19
+ }
20
+ get lineLinked() {
21
+ return this.links;
22
+ }
23
+ set lineLinked(value) {
24
+ this.links = value;
25
+ }
26
+ get line_linked() {
27
+ return this.links;
28
+ }
29
+ set line_linked(value) {
30
+ this.links = value;
31
+ }
32
+ load(data) {
33
+ var _a, _b;
34
+ if (!data) {
35
+ return;
36
+ }
37
+ if (data.distance !== undefined) {
38
+ this.distance = data.distance;
39
+ }
40
+ this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
41
+ if (data.radius !== undefined) {
42
+ this.radius = data.radius;
43
+ }
44
+ }
45
+ }
46
+ exports.Connect = Connect;
47
+ });
@@ -0,0 +1,27 @@
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
+ exports.ConnectLinks = void 0;
13
+ class ConnectLinks {
14
+ constructor() {
15
+ this.opacity = 0.5;
16
+ }
17
+ load(data) {
18
+ if (!data) {
19
+ return;
20
+ }
21
+ if (data.opacity !== undefined) {
22
+ this.opacity = data.opacity;
23
+ }
24
+ }
25
+ }
26
+ exports.ConnectLinks = ConnectLinks;
27
+ });
@@ -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", "./Connector", "./Options/Classes/Connect", "./Options/Classes/ConnectLinks", "./Options/Interfaces/IConnect", "./Options/Interfaces/IConnectLinks"], factory);
22
+ }
23
+ })(function (require, exports) {
24
+ "use strict";
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.loadExternalConnectInteraction = void 0;
27
+ const Connector_1 = require("./Connector");
28
+ async function loadExternalConnectInteraction(engine) {
29
+ await engine.addInteractor("externalConnect", (container) => new Connector_1.Connector(container));
30
+ }
31
+ exports.loadExternalConnectInteraction = loadExternalConnectInteraction;
32
+ __exportStar(require("./Options/Classes/Connect"), exports);
33
+ __exportStar(require("./Options/Classes/ConnectLinks"), exports);
34
+ __exportStar(require("./Options/Interfaces/IConnect"), exports);
35
+ __exportStar(require("./Options/Interfaces/IConnectLinks"), exports);
36
+ });