@tsparticles/interaction-particles-links 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.
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/browser/CircleWarp.js +50 -0
- package/browser/ILink.js +1 -0
- package/browser/LinkContainer.js +1 -0
- package/browser/LinkInstance.js +143 -0
- package/browser/LinkParticle.js +1 -0
- package/browser/Linker.js +119 -0
- package/browser/Options/Classes/Links.js +54 -0
- package/browser/Options/Classes/LinksShadow.js +21 -0
- package/browser/Options/Classes/LinksTriangle.js +24 -0
- package/browser/Options/Classes/ParticlesLinkOptions.js +1 -0
- package/browser/Options/Interfaces/ILinks.js +1 -0
- package/browser/Options/Interfaces/ILinksShadow.js +1 -0
- package/browser/Options/Interfaces/ILinksTriangle.js +1 -0
- package/browser/Options/Interfaces/IParticlesLinkOptions.js +1 -0
- package/browser/Utils.js +77 -0
- package/browser/index.js +12 -0
- package/browser/interaction.js +4 -0
- package/browser/plugin.js +18 -0
- package/cjs/CircleWarp.js +54 -0
- package/cjs/ILink.js +2 -0
- package/cjs/LinkContainer.js +2 -0
- package/cjs/LinkInstance.js +158 -0
- package/cjs/LinkParticle.js +2 -0
- package/cjs/Linker.js +134 -0
- package/cjs/Options/Classes/Links.js +58 -0
- package/cjs/Options/Classes/LinksShadow.js +25 -0
- package/cjs/Options/Classes/LinksTriangle.js +28 -0
- package/cjs/Options/Classes/ParticlesLinkOptions.js +2 -0
- package/cjs/Options/Interfaces/ILinks.js +2 -0
- package/cjs/Options/Interfaces/ILinksShadow.js +2 -0
- package/cjs/Options/Interfaces/ILinksTriangle.js +2 -0
- package/cjs/Options/Interfaces/IParticlesLinkOptions.js +2 -0
- package/cjs/Utils.js +82 -0
- package/cjs/index.js +41 -0
- package/cjs/interaction.js +19 -0
- package/cjs/plugin.js +33 -0
- package/esm/CircleWarp.js +50 -0
- package/esm/ILink.js +1 -0
- package/esm/LinkContainer.js +1 -0
- package/esm/LinkInstance.js +143 -0
- package/esm/LinkParticle.js +1 -0
- package/esm/Linker.js +119 -0
- package/esm/Options/Classes/Links.js +54 -0
- package/esm/Options/Classes/LinksShadow.js +21 -0
- package/esm/Options/Classes/LinksTriangle.js +24 -0
- package/esm/Options/Classes/ParticlesLinkOptions.js +1 -0
- package/esm/Options/Interfaces/ILinks.js +1 -0
- package/esm/Options/Interfaces/ILinksShadow.js +1 -0
- package/esm/Options/Interfaces/ILinksTriangle.js +1 -0
- package/esm/Options/Interfaces/IParticlesLinkOptions.js +1 -0
- package/esm/Utils.js +77 -0
- package/esm/index.js +12 -0
- package/esm/interaction.js +4 -0
- package/esm/plugin.js +18 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.interaction.particles.links.js +658 -0
- package/tsparticles.interaction.particles.links.min.js +2 -0
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +8 -0
- package/types/CircleWarp.d.ts +8 -0
- package/types/ILink.d.ts +9 -0
- package/types/LinkContainer.d.ts +7 -0
- package/types/LinkInstance.d.ts +17 -0
- package/types/LinkParticle.d.ts +11 -0
- package/types/Linker.d.ts +17 -0
- package/types/Options/Classes/Links.d.ts +21 -0
- package/types/Options/Classes/LinksShadow.d.ts +10 -0
- package/types/Options/Classes/LinksTriangle.d.ts +11 -0
- package/types/Options/Classes/ParticlesLinkOptions.d.ts +5 -0
- package/types/Options/Interfaces/ILinks.d.ts +17 -0
- package/types/Options/Interfaces/ILinksShadow.d.ts +6 -0
- package/types/Options/Interfaces/ILinksTriangle.d.ts +7 -0
- package/types/Options/Interfaces/IParticlesLinkOptions.d.ts +7 -0
- package/types/Utils.d.ts +4 -0
- package/types/index.d.ts +8 -0
- package/types/interaction.d.ts +2 -0
- package/types/plugin.d.ts +2 -0
- package/umd/CircleWarp.js +64 -0
- package/umd/ILink.js +12 -0
- package/umd/LinkContainer.js +12 -0
- package/umd/LinkInstance.js +157 -0
- package/umd/LinkParticle.js +12 -0
- package/umd/Linker.js +133 -0
- package/umd/Options/Classes/Links.js +68 -0
- package/umd/Options/Classes/LinksShadow.js +35 -0
- package/umd/Options/Classes/LinksTriangle.js +38 -0
- package/umd/Options/Classes/ParticlesLinkOptions.js +12 -0
- package/umd/Options/Interfaces/ILinks.js +12 -0
- package/umd/Options/Interfaces/ILinksShadow.js +12 -0
- package/umd/Options/Interfaces/ILinksTriangle.js +12 -0
- package/umd/Options/Interfaces/IParticlesLinkOptions.js +12 -0
- package/umd/Utils.js +92 -0
- package/umd/index.js +40 -0
- package/umd/interaction.js +18 -0
- package/umd/plugin.js +32 -0
package/types/ILink.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IContainerPlugin } from "@tsparticles/engine";
|
|
2
|
+
import type { LinkContainer } from "./LinkContainer";
|
|
3
|
+
import type { LinkParticle } from "./LinkParticle";
|
|
4
|
+
export declare class LinkInstance implements IContainerPlugin {
|
|
5
|
+
private readonly container;
|
|
6
|
+
private readonly _freqs;
|
|
7
|
+
constructor(container: LinkContainer);
|
|
8
|
+
drawParticle(context: CanvasRenderingContext2D, particle: LinkParticle): void;
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
particleCreated(particle: LinkParticle): void;
|
|
11
|
+
particleDestroyed(particle: LinkParticle): void;
|
|
12
|
+
private drawLinkLine;
|
|
13
|
+
private drawLinkTriangle;
|
|
14
|
+
private drawTriangles;
|
|
15
|
+
private getLinkFrequency;
|
|
16
|
+
private getTriangleFrequency;
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ILink } from "./ILink";
|
|
2
|
+
import type { Particle } from "@tsparticles/engine";
|
|
3
|
+
import type { ParticlesLinkOptions } from "./Options/Classes/ParticlesLinkOptions";
|
|
4
|
+
export type LinkParticle = Particle & {
|
|
5
|
+
links?: ILink[];
|
|
6
|
+
options: ParticlesLinkOptions;
|
|
7
|
+
retina: {
|
|
8
|
+
linksDistance?: number;
|
|
9
|
+
linksWidth?: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ParticlesInteractorBase } from "@tsparticles/engine";
|
|
2
|
+
import type { RecursivePartial } from "@tsparticles/engine";
|
|
3
|
+
import type { IParticlesLinkOptions } from "./Options/Interfaces/IParticlesLinkOptions";
|
|
4
|
+
import type { LinkContainer } from "./LinkContainer";
|
|
5
|
+
import type { LinkParticle } from "./LinkParticle";
|
|
6
|
+
import type { ParticlesLinkOptions } from "./Options/Classes/ParticlesLinkOptions";
|
|
7
|
+
export declare class Linker extends ParticlesInteractorBase {
|
|
8
|
+
linkContainer: LinkContainer;
|
|
9
|
+
constructor(container: LinkContainer);
|
|
10
|
+
clear(): void;
|
|
11
|
+
init(): void;
|
|
12
|
+
interact(p1: LinkParticle): Promise<void>;
|
|
13
|
+
isEnabled(particle: LinkParticle): boolean;
|
|
14
|
+
loadParticlesOptions(options: ParticlesLinkOptions, ...sources: (RecursivePartial<IParticlesLinkOptions> | undefined)[]): void;
|
|
15
|
+
reset(): void;
|
|
16
|
+
private setColor;
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILinks } from "../Interfaces/ILinks";
|
|
3
|
+
import { LinksShadow } from "./LinksShadow";
|
|
4
|
+
import { LinksTriangle } from "./LinksTriangle";
|
|
5
|
+
import { OptionsColor } from "@tsparticles/engine";
|
|
6
|
+
export declare class Links implements ILinks, IOptionLoader<ILinks> {
|
|
7
|
+
blink: boolean;
|
|
8
|
+
color: OptionsColor;
|
|
9
|
+
consent: boolean;
|
|
10
|
+
distance: number;
|
|
11
|
+
enable: boolean;
|
|
12
|
+
frequency: number;
|
|
13
|
+
id?: string;
|
|
14
|
+
opacity: number;
|
|
15
|
+
shadow: LinksShadow;
|
|
16
|
+
triangles: LinksTriangle;
|
|
17
|
+
warp: boolean;
|
|
18
|
+
width: number;
|
|
19
|
+
constructor();
|
|
20
|
+
load(data?: RecursivePartial<ILinks>): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILinksShadow } from "../Interfaces/ILinksShadow";
|
|
3
|
+
import { OptionsColor } from "@tsparticles/engine";
|
|
4
|
+
export declare class LinksShadow implements ILinksShadow, IOptionLoader<ILinksShadow> {
|
|
5
|
+
blur: number;
|
|
6
|
+
color: OptionsColor;
|
|
7
|
+
enable: boolean;
|
|
8
|
+
constructor();
|
|
9
|
+
load(data?: RecursivePartial<ILinksShadow>): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ILinksTriangle } from "../Interfaces/ILinksTriangle";
|
|
3
|
+
import { OptionsColor } from "@tsparticles/engine";
|
|
4
|
+
export declare class LinksTriangle implements ILinksTriangle, IOptionLoader<ILinksTriangle> {
|
|
5
|
+
color?: OptionsColor;
|
|
6
|
+
enable: boolean;
|
|
7
|
+
frequency: number;
|
|
8
|
+
opacity?: number;
|
|
9
|
+
constructor();
|
|
10
|
+
load(data?: RecursivePartial<ILinksTriangle>): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ILinksShadow } from "./ILinksShadow";
|
|
2
|
+
import type { ILinksTriangle } from "./ILinksTriangle";
|
|
3
|
+
import type { IOptionsColor } from "@tsparticles/engine";
|
|
4
|
+
export interface ILinks {
|
|
5
|
+
blink: boolean;
|
|
6
|
+
color: string | IOptionsColor;
|
|
7
|
+
consent: boolean;
|
|
8
|
+
distance: number;
|
|
9
|
+
enable: boolean;
|
|
10
|
+
frequency: number;
|
|
11
|
+
id?: string;
|
|
12
|
+
opacity: number;
|
|
13
|
+
shadow: ILinksShadow;
|
|
14
|
+
triangles: ILinksTriangle;
|
|
15
|
+
warp: boolean;
|
|
16
|
+
width: number;
|
|
17
|
+
}
|
package/types/Utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ICoordinates, IDimension, IRgb } from "@tsparticles/engine";
|
|
2
|
+
import type { ILinksShadow } from "./Options/Interfaces/ILinksShadow";
|
|
3
|
+
export declare function drawLinkLine(context: CanvasRenderingContext2D, width: number, begin: ICoordinates, end: ICoordinates, maxDistance: number, canvasSize: IDimension, warp: boolean, backgroundMask: boolean, composite: GlobalCompositeOperation, colorLine: IRgb, opacity: number, shadow: ILinksShadow): void;
|
|
4
|
+
export declare function drawLinkTriangle(context: CanvasRenderingContext2D, pos1: ICoordinates, pos2: ICoordinates, pos3: ICoordinates, backgroundMask: boolean, composite: GlobalCompositeOperation, colorTriangle: IRgb, opacityTriangle: number): void;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Engine } from "@tsparticles/engine";
|
|
2
|
+
export declare function loadParticlesLinksInteraction(engine: Engine): Promise<void>;
|
|
3
|
+
export * from "./Options/Classes/Links";
|
|
4
|
+
export * from "./Options/Classes/LinksShadow";
|
|
5
|
+
export * from "./Options/Classes/LinksTriangle";
|
|
6
|
+
export * from "./Options/Interfaces/ILinks";
|
|
7
|
+
export * from "./Options/Interfaces/ILinksShadow";
|
|
8
|
+
export * from "./Options/Interfaces/ILinksTriangle";
|
|
@@ -0,0 +1,64 @@
|
|
|
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.CircleWarp = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class CircleWarp extends engine_1.Circle {
|
|
15
|
+
constructor(x, y, radius, canvasSize) {
|
|
16
|
+
super(x, y, radius);
|
|
17
|
+
this.canvasSize = canvasSize;
|
|
18
|
+
this.canvasSize = Object.assign({}, canvasSize);
|
|
19
|
+
}
|
|
20
|
+
contains(point) {
|
|
21
|
+
if (super.contains(point)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const posNE = {
|
|
25
|
+
x: point.x - this.canvasSize.width,
|
|
26
|
+
y: point.y,
|
|
27
|
+
};
|
|
28
|
+
if (super.contains(posNE)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const posSE = {
|
|
32
|
+
x: point.x - this.canvasSize.width,
|
|
33
|
+
y: point.y - this.canvasSize.height,
|
|
34
|
+
};
|
|
35
|
+
if (super.contains(posSE)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const posSW = {
|
|
39
|
+
x: point.x,
|
|
40
|
+
y: point.y - this.canvasSize.height,
|
|
41
|
+
};
|
|
42
|
+
return super.contains(posSW);
|
|
43
|
+
}
|
|
44
|
+
intersects(range) {
|
|
45
|
+
if (super.intersects(range)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const rect = range, circle = range, newPos = {
|
|
49
|
+
x: range.position.x - this.canvasSize.width,
|
|
50
|
+
y: range.position.y - this.canvasSize.height,
|
|
51
|
+
};
|
|
52
|
+
if (circle.radius !== undefined) {
|
|
53
|
+
const biggerCircle = new engine_1.Circle(newPos.x, newPos.y, circle.radius * 2);
|
|
54
|
+
return super.intersects(biggerCircle);
|
|
55
|
+
}
|
|
56
|
+
else if (rect.size !== undefined) {
|
|
57
|
+
const rectSW = new engine_1.Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
|
|
58
|
+
return super.intersects(rectSW);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.CircleWarp = CircleWarp;
|
|
64
|
+
});
|
package/umd/ILink.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
|
+
});
|
|
@@ -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,157 @@
|
|
|
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", "./Utils", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LinkInstance = void 0;
|
|
13
|
+
const Utils_1 = require("./Utils");
|
|
14
|
+
const engine_1 = require("@tsparticles/engine");
|
|
15
|
+
function getLinkKey(ids) {
|
|
16
|
+
ids.sort((a, b) => a - b);
|
|
17
|
+
return ids.join("_");
|
|
18
|
+
}
|
|
19
|
+
function setLinkFrequency(particles, dictionary) {
|
|
20
|
+
const key = getLinkKey(particles.map((t) => t.id));
|
|
21
|
+
let res = dictionary.get(key);
|
|
22
|
+
if (res === undefined) {
|
|
23
|
+
res = (0, engine_1.getRandom)();
|
|
24
|
+
dictionary.set(key, res);
|
|
25
|
+
}
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
class LinkInstance {
|
|
29
|
+
constructor(container) {
|
|
30
|
+
this.container = container;
|
|
31
|
+
this._freqs = {
|
|
32
|
+
links: new Map(),
|
|
33
|
+
triangles: new Map(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
drawParticle(context, particle) {
|
|
37
|
+
var _a;
|
|
38
|
+
const pOptions = particle.options;
|
|
39
|
+
if (!particle.links || particle.links.length <= 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const p1Links = particle.links.filter((l) => pOptions.links && this.getLinkFrequency(particle, l.destination) <= pOptions.links.frequency);
|
|
43
|
+
for (const link of p1Links) {
|
|
44
|
+
this.drawTriangles(pOptions, particle, link, p1Links);
|
|
45
|
+
if (link.opacity > 0 && ((_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0) > 0) {
|
|
46
|
+
this.drawLinkLine(particle, link);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async init() {
|
|
51
|
+
this._freqs.links = new Map();
|
|
52
|
+
this._freqs.triangles = new Map();
|
|
53
|
+
}
|
|
54
|
+
particleCreated(particle) {
|
|
55
|
+
particle.links = [];
|
|
56
|
+
if (!particle.options.links) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const ratio = this.container.retina.pixelRatio;
|
|
60
|
+
particle.retina.linksDistance = particle.options.links.distance * ratio;
|
|
61
|
+
particle.retina.linksWidth = particle.options.links.width * ratio;
|
|
62
|
+
}
|
|
63
|
+
particleDestroyed(particle) {
|
|
64
|
+
particle.links = [];
|
|
65
|
+
}
|
|
66
|
+
drawLinkLine(p1, link) {
|
|
67
|
+
const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
68
|
+
let opacity = link.opacity;
|
|
69
|
+
container.canvas.draw((ctx) => {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
if (!p1.options.links) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let colorLine;
|
|
75
|
+
const twinkle = (_a = p1.options.twinkle) === null || _a === void 0 ? void 0 : _a.lines;
|
|
76
|
+
if (twinkle === null || twinkle === void 0 ? void 0 : twinkle.enable) {
|
|
77
|
+
const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
|
|
78
|
+
if (twinkling && twinkleRgb) {
|
|
79
|
+
colorLine = twinkleRgb;
|
|
80
|
+
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!colorLine) {
|
|
84
|
+
const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
|
|
85
|
+
? container.particles.linksColors.get(linksOptions.id)
|
|
86
|
+
: container.particles.linksColor;
|
|
87
|
+
colorLine = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
88
|
+
}
|
|
89
|
+
if (!colorLine) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const width = (_b = p1.retina.linksWidth) !== null && _b !== void 0 ? _b : 0, maxDistance = (_c = p1.retina.linksDistance) !== null && _c !== void 0 ? _c : 0;
|
|
93
|
+
(0, Utils_1.drawLinkLine)(ctx, width, pos1, pos2, maxDistance, container.canvas.size, p1.options.links.warp, options.backgroundMask.enable, options.backgroundMask.composite, colorLine, opacity, p1.options.links.shadow);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
drawLinkTriangle(p1, link1, link2) {
|
|
97
|
+
var _a;
|
|
98
|
+
if (!p1.options.links) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, triangleOptions = p1.options.links.triangles, opacityTriangle = (_a = triangleOptions.opacity) !== null && _a !== void 0 ? _a : (link1.opacity + link2.opacity) / 2;
|
|
102
|
+
if (opacityTriangle <= 0) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
container.canvas.draw((ctx) => {
|
|
106
|
+
var _a;
|
|
107
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0;
|
|
108
|
+
if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
|
|
109
|
+
(0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
|
|
110
|
+
(0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let colorTriangle = (0, engine_1.rangeColorToRgb)(triangleOptions.color);
|
|
114
|
+
if (!colorTriangle) {
|
|
115
|
+
const linksOptions = p1.options.links, linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined
|
|
116
|
+
? container.particles.linksColors.get(linksOptions.id)
|
|
117
|
+
: container.particles.linksColor;
|
|
118
|
+
colorTriangle = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
119
|
+
}
|
|
120
|
+
if (!colorTriangle) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
(0, Utils_1.drawLinkTriangle)(ctx, pos1, pos2, pos3, options.backgroundMask.enable, options.backgroundMask.composite, colorTriangle, opacityTriangle);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
drawTriangles(options, p1, link, p1Links) {
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
const p2 = link.destination;
|
|
129
|
+
if (!(((_a = options.links) === null || _a === void 0 ? void 0 : _a.triangles.enable) && ((_b = p2.options.links) === null || _b === void 0 ? void 0 : _b.triangles.enable))) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const vertices = (_c = p2.links) === null || _c === void 0 ? void 0 : _c.filter((t) => {
|
|
133
|
+
const linkFreq = this.getLinkFrequency(p2, t.destination);
|
|
134
|
+
return (p2.options.links &&
|
|
135
|
+
linkFreq <= p2.options.links.frequency &&
|
|
136
|
+
p1Links.findIndex((l) => l.destination === t.destination) >= 0);
|
|
137
|
+
});
|
|
138
|
+
if (!(vertices === null || vertices === void 0 ? void 0 : vertices.length)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
for (const vertex of vertices) {
|
|
142
|
+
const p3 = vertex.destination, triangleFreq = this.getTriangleFrequency(p1, p2, p3);
|
|
143
|
+
if (triangleFreq > options.links.triangles.frequency) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
this.drawLinkTriangle(p1, link, vertex);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
getLinkFrequency(p1, p2) {
|
|
150
|
+
return setLinkFrequency([p1, p2], this._freqs.links);
|
|
151
|
+
}
|
|
152
|
+
getTriangleFrequency(p1, p2, p3) {
|
|
153
|
+
return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.LinkInstance = LinkInstance;
|
|
157
|
+
});
|
|
@@ -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/Linker.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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", "./CircleWarp", "./Options/Classes/Links"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Linker = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const CircleWarp_1 = require("./CircleWarp");
|
|
15
|
+
const Links_1 = require("./Options/Classes/Links");
|
|
16
|
+
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
17
|
+
let distance = (0, engine_1.getDistance)(pos1, pos2);
|
|
18
|
+
if (!warp || distance <= optDistance) {
|
|
19
|
+
return distance;
|
|
20
|
+
}
|
|
21
|
+
const pos2NE = {
|
|
22
|
+
x: pos2.x - canvasSize.width,
|
|
23
|
+
y: pos2.y,
|
|
24
|
+
};
|
|
25
|
+
distance = (0, engine_1.getDistance)(pos1, pos2NE);
|
|
26
|
+
if (distance <= optDistance) {
|
|
27
|
+
return distance;
|
|
28
|
+
}
|
|
29
|
+
const pos2SE = {
|
|
30
|
+
x: pos2.x - canvasSize.width,
|
|
31
|
+
y: pos2.y - canvasSize.height,
|
|
32
|
+
};
|
|
33
|
+
distance = (0, engine_1.getDistance)(pos1, pos2SE);
|
|
34
|
+
if (distance <= optDistance) {
|
|
35
|
+
return distance;
|
|
36
|
+
}
|
|
37
|
+
const pos2SW = {
|
|
38
|
+
x: pos2.x,
|
|
39
|
+
y: pos2.y - canvasSize.height,
|
|
40
|
+
};
|
|
41
|
+
distance = (0, engine_1.getDistance)(pos1, pos2SW);
|
|
42
|
+
return distance;
|
|
43
|
+
}
|
|
44
|
+
class Linker extends engine_1.ParticlesInteractorBase {
|
|
45
|
+
constructor(container) {
|
|
46
|
+
super(container);
|
|
47
|
+
this.linkContainer = container;
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
}
|
|
51
|
+
init() {
|
|
52
|
+
this.linkContainer.particles.linksColor = undefined;
|
|
53
|
+
this.linkContainer.particles.linksColors = new Map();
|
|
54
|
+
}
|
|
55
|
+
async interact(p1) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (!p1.options.links) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
p1.links = [];
|
|
61
|
+
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
62
|
+
if (pos1.x < 0 || pos1.y < 0 || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0, warp = linkOpt1.warp, range = warp
|
|
66
|
+
? new CircleWarp_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize)
|
|
67
|
+
: new engine_1.Circle(pos1.x, pos1.y, optDistance), query = container.particles.quadTree.query(range);
|
|
68
|
+
for (const p2 of query) {
|
|
69
|
+
const linkOpt2 = p2.options.links;
|
|
70
|
+
if (p1 === p2 ||
|
|
71
|
+
!(linkOpt2 === null || linkOpt2 === void 0 ? void 0 : linkOpt2.enable) ||
|
|
72
|
+
linkOpt1.id !== linkOpt2.id ||
|
|
73
|
+
p2.spawning ||
|
|
74
|
+
p2.destroyed ||
|
|
75
|
+
!p2.links ||
|
|
76
|
+
p1.links.map((t) => t.destination).indexOf(p2) !== -1 ||
|
|
77
|
+
p2.links.map((t) => t.destination).indexOf(p1) !== -1) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const pos2 = p2.getPosition();
|
|
81
|
+
if (pos2.x < 0 || pos2.y < 0 || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
|
85
|
+
if (distance > optDistance) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const opacityLine = (1 - distance / optDistance) * optOpacity;
|
|
89
|
+
this.setColor(p1);
|
|
90
|
+
p1.links.push({
|
|
91
|
+
destination: p2,
|
|
92
|
+
opacity: opacityLine,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
isEnabled(particle) {
|
|
97
|
+
var _a;
|
|
98
|
+
return !!((_a = particle.options.links) === null || _a === void 0 ? void 0 : _a.enable);
|
|
99
|
+
}
|
|
100
|
+
loadParticlesOptions(options, ...sources) {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
if (!options.links) {
|
|
103
|
+
options.links = new Links_1.Links();
|
|
104
|
+
}
|
|
105
|
+
for (const source of sources) {
|
|
106
|
+
options.links.load((_b = (_a = source === null || source === void 0 ? void 0 : source.links) !== null && _a !== void 0 ? _a : source === null || source === void 0 ? void 0 : source.lineLinked) !== null && _b !== void 0 ? _b : source === null || source === void 0 ? void 0 : source.line_linked);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
reset() {
|
|
110
|
+
}
|
|
111
|
+
setColor(p1) {
|
|
112
|
+
if (!p1.options.links) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const container = this.linkContainer, linksOptions = p1.options.links;
|
|
116
|
+
let linkColor = linksOptions.id === undefined
|
|
117
|
+
? container.particles.linksColor
|
|
118
|
+
: container.particles.linksColors.get(linksOptions.id);
|
|
119
|
+
if (linkColor) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const optColor = linksOptions.color;
|
|
123
|
+
linkColor = (0, engine_1.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
|
|
124
|
+
if (linksOptions.id === undefined) {
|
|
125
|
+
container.particles.linksColor = linkColor;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.Linker = Linker;
|
|
133
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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", "./LinksShadow", "./LinksTriangle", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Links = void 0;
|
|
13
|
+
const LinksShadow_1 = require("./LinksShadow");
|
|
14
|
+
const LinksTriangle_1 = require("./LinksTriangle");
|
|
15
|
+
const engine_1 = require("@tsparticles/engine");
|
|
16
|
+
class Links {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.blink = false;
|
|
19
|
+
this.color = new engine_1.OptionsColor();
|
|
20
|
+
this.color.value = "#fff";
|
|
21
|
+
this.consent = false;
|
|
22
|
+
this.distance = 100;
|
|
23
|
+
this.enable = false;
|
|
24
|
+
this.frequency = 1;
|
|
25
|
+
this.opacity = 1;
|
|
26
|
+
this.shadow = new LinksShadow_1.LinksShadow();
|
|
27
|
+
this.triangles = new LinksTriangle_1.LinksTriangle();
|
|
28
|
+
this.width = 1;
|
|
29
|
+
this.warp = false;
|
|
30
|
+
}
|
|
31
|
+
load(data) {
|
|
32
|
+
if (!data) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (data.id !== undefined) {
|
|
36
|
+
this.id = data.id;
|
|
37
|
+
}
|
|
38
|
+
if (data.blink !== undefined) {
|
|
39
|
+
this.blink = data.blink;
|
|
40
|
+
}
|
|
41
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
42
|
+
if (data.consent !== undefined) {
|
|
43
|
+
this.consent = data.consent;
|
|
44
|
+
}
|
|
45
|
+
if (data.distance !== undefined) {
|
|
46
|
+
this.distance = data.distance;
|
|
47
|
+
}
|
|
48
|
+
if (data.enable !== undefined) {
|
|
49
|
+
this.enable = data.enable;
|
|
50
|
+
}
|
|
51
|
+
if (data.frequency !== undefined) {
|
|
52
|
+
this.frequency = data.frequency;
|
|
53
|
+
}
|
|
54
|
+
if (data.opacity !== undefined) {
|
|
55
|
+
this.opacity = data.opacity;
|
|
56
|
+
}
|
|
57
|
+
this.shadow.load(data.shadow);
|
|
58
|
+
this.triangles.load(data.triangles);
|
|
59
|
+
if (data.width !== undefined) {
|
|
60
|
+
this.width = data.width;
|
|
61
|
+
}
|
|
62
|
+
if (data.warp !== undefined) {
|
|
63
|
+
this.warp = data.warp;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Links = Links;
|
|
68
|
+
});
|