@tsparticles/interaction-particles-links 3.0.0-alpha.1 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -19
- package/browser/CircleWarp.js +7 -23
- package/browser/LinkInstance.js +121 -114
- package/browser/Linker.js +37 -54
- package/browser/Options/Classes/Links.js +1 -1
- package/browser/Utils.js +24 -8
- package/browser/index.js +5 -5
- package/browser/interaction.js +2 -2
- package/browser/plugin.js +2 -2
- package/cjs/CircleWarp.js +7 -23
- package/cjs/LinkInstance.js +123 -127
- package/cjs/Linker.js +66 -94
- package/cjs/Options/Classes/Links.js +1 -1
- package/cjs/Utils.js +26 -8
- package/cjs/index.js +3 -14
- package/cjs/interaction.js +4 -15
- package/cjs/plugin.js +5 -16
- package/esm/CircleWarp.js +7 -23
- package/esm/LinkInstance.js +121 -114
- package/esm/Linker.js +37 -54
- package/esm/Options/Classes/Links.js +1 -1
- package/esm/Utils.js +24 -8
- package/esm/index.js +5 -5
- package/esm/interaction.js +2 -2
- package/esm/plugin.js +2 -2
- package/package.json +6 -5
- package/report.html +4 -4
- package/tsparticles.interaction.particles.links.js +244 -204
- package/tsparticles.interaction.particles.links.min.js +1 -1
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +1 -8
- package/types/CircleWarp.d.ts +1 -2
- package/types/Interfaces.d.ts +22 -0
- package/types/LinkInstance.d.ts +7 -8
- package/types/Linker.d.ts +3 -7
- package/types/Options/Classes/Links.d.ts +1 -2
- package/types/Options/Classes/LinksShadow.d.ts +1 -2
- package/types/Options/Classes/LinksTriangle.d.ts +1 -2
- package/types/Types.d.ts +47 -0
- package/types/Utils.d.ts +5 -4
- package/types/index.d.ts +1 -1
- package/types/interaction.d.ts +1 -1
- package/types/plugin.d.ts +1 -1
- package/umd/CircleWarp.js +7 -23
- package/umd/LinkInstance.js +121 -114
- package/umd/Linker.js +36 -53
- package/umd/Options/Classes/Links.js +2 -2
- package/umd/Utils.js +26 -8
- package/umd/index.js +3 -3
- package/umd/interaction.js +4 -4
- package/umd/plugin.js +4 -4
- package/browser/Options/Interfaces/IParticlesLinkOptions.js +0 -1
- package/cjs/LinkParticle.js +0 -2
- package/cjs/Options/Classes/ParticlesLinkOptions.js +0 -2
- package/cjs/Options/Interfaces/IParticlesLinkOptions.js +0 -2
- package/esm/ILink.js +0 -1
- package/esm/LinkContainer.js +0 -1
- package/esm/LinkParticle.js +0 -1
- package/esm/Options/Classes/ParticlesLinkOptions.js +0 -1
- package/esm/Options/Interfaces/IParticlesLinkOptions.js +0 -1
- package/types/ILink.d.ts +0 -9
- package/types/LinkContainer.d.ts +0 -7
- package/types/LinkParticle.d.ts +0 -11
- package/types/Options/Classes/ParticlesLinkOptions.d.ts +0 -5
- package/types/Options/Interfaces/IParticlesLinkOptions.d.ts +0 -7
- package/umd/LinkParticle.js +0 -12
- package/umd/Options/Classes/ParticlesLinkOptions.js +0 -12
- package/umd/Options/Interfaces/IParticlesLinkOptions.js +0 -12
- /package/browser/{ILink.js → Interfaces.js} +0 -0
- /package/browser/{LinkContainer.js → Types.js} +0 -0
- /package/cjs/{ILink.js → Interfaces.js} +0 -0
- /package/cjs/{LinkContainer.js → Types.js} +0 -0
- /package/{browser/LinkParticle.js → esm/Interfaces.js} +0 -0
- /package/{browser/Options/Classes/ParticlesLinkOptions.js → esm/Types.js} +0 -0
- /package/umd/{ILink.js → Interfaces.js} +0 -0
- /package/umd/{LinkContainer.js → Types.js} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IRangeColor, RangeValue } from "@tsparticles/engine";
|
|
2
|
+
import type { LinkParticle } from "./Types";
|
|
3
|
+
export interface ILink {
|
|
4
|
+
destination: LinkParticle;
|
|
5
|
+
opacity: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ILinkTriangle {
|
|
8
|
+
opacity: number;
|
|
9
|
+
vertices: LinkParticle[];
|
|
10
|
+
}
|
|
11
|
+
export interface IParticlesFrequencies {
|
|
12
|
+
links: Map<string, number>;
|
|
13
|
+
triangles: Map<string, number>;
|
|
14
|
+
}
|
|
15
|
+
export interface ITwinkle {
|
|
16
|
+
lines: {
|
|
17
|
+
color: IRangeColor;
|
|
18
|
+
enable: boolean;
|
|
19
|
+
frequency: number;
|
|
20
|
+
opacity: RangeValue;
|
|
21
|
+
};
|
|
22
|
+
}
|
package/types/LinkInstance.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { LinkContainer } from "./
|
|
3
|
-
import type { LinkParticle } from "./LinkParticle";
|
|
1
|
+
import { type IContainerPlugin } from "@tsparticles/engine";
|
|
2
|
+
import type { LinkContainer, LinkParticle } from "./Types";
|
|
4
3
|
export declare class LinkInstance implements IContainerPlugin {
|
|
5
4
|
private readonly container;
|
|
6
5
|
private readonly _freqs;
|
|
@@ -9,9 +8,9 @@ export declare class LinkInstance implements IContainerPlugin {
|
|
|
9
8
|
init(): Promise<void>;
|
|
10
9
|
particleCreated(particle: LinkParticle): void;
|
|
11
10
|
particleDestroyed(particle: LinkParticle): void;
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
11
|
+
private readonly _drawLinkLine;
|
|
12
|
+
private readonly _drawLinkTriangle;
|
|
13
|
+
private readonly _drawTriangles;
|
|
14
|
+
private readonly _getLinkFrequency;
|
|
15
|
+
private readonly _getTriangleFrequency;
|
|
17
16
|
}
|
package/types/Linker.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { ParticlesInteractorBase } from "@tsparticles/engine";
|
|
2
|
-
import type {
|
|
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";
|
|
1
|
+
import { ParticlesInteractorBase, type RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IParticlesLinkOptions, LinkContainer, LinkParticle, ParticlesLinkOptions } from "./Types";
|
|
7
3
|
export declare class Linker extends ParticlesInteractorBase {
|
|
8
4
|
linkContainer: LinkContainer;
|
|
9
5
|
constructor(container: LinkContainer);
|
|
@@ -13,5 +9,5 @@ export declare class Linker extends ParticlesInteractorBase {
|
|
|
13
9
|
isEnabled(particle: LinkParticle): boolean;
|
|
14
10
|
loadParticlesOptions(options: ParticlesLinkOptions, ...sources: (RecursivePartial<IParticlesLinkOptions> | undefined)[]): void;
|
|
15
11
|
reset(): void;
|
|
16
|
-
private
|
|
12
|
+
private readonly _setColor;
|
|
17
13
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
|
|
2
2
|
import type { ILinks } from "../Interfaces/ILinks";
|
|
3
3
|
import { LinksShadow } from "./LinksShadow";
|
|
4
4
|
import { LinksTriangle } from "./LinksTriangle";
|
|
5
|
-
import { OptionsColor } from "@tsparticles/engine";
|
|
6
5
|
export declare class Links implements ILinks, IOptionLoader<ILinks> {
|
|
7
6
|
blink: boolean;
|
|
8
7
|
color: OptionsColor;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
|
|
2
2
|
import type { ILinksShadow } from "../Interfaces/ILinksShadow";
|
|
3
|
-
import { OptionsColor } from "@tsparticles/engine";
|
|
4
3
|
export declare class LinksShadow implements ILinksShadow, IOptionLoader<ILinksShadow> {
|
|
5
4
|
blur: number;
|
|
6
5
|
color: OptionsColor;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
|
|
2
2
|
import type { ILinksTriangle } from "../Interfaces/ILinksTriangle";
|
|
3
|
-
import { OptionsColor } from "@tsparticles/engine";
|
|
4
3
|
export declare class LinksTriangle implements ILinksTriangle, IOptionLoader<ILinksTriangle> {
|
|
5
4
|
color?: OptionsColor;
|
|
6
5
|
enable: boolean;
|
package/types/Types.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BackgroundMask, Container, ICoordinates, IDimension, IParticlesOptions, IRgb, Particle, ParticlesOptions } from "@tsparticles/engine";
|
|
2
|
+
import type { ILink } from "./Interfaces";
|
|
3
|
+
import type { ILinks } from "./Options/Interfaces/ILinks";
|
|
4
|
+
import type { Links } from "./Options/Classes/Links";
|
|
5
|
+
export type LinkContainer = Container & {
|
|
6
|
+
particles: {
|
|
7
|
+
linksColor?: IRgb | string;
|
|
8
|
+
linksColors: Map<string, IRgb | string | undefined>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type LinkParticle = Particle & {
|
|
12
|
+
links?: ILink[];
|
|
13
|
+
options: ParticlesLinkOptions;
|
|
14
|
+
retina: {
|
|
15
|
+
linksDistance?: number;
|
|
16
|
+
linksWidth?: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export type LinkLineDrawParams = {
|
|
20
|
+
backgroundMask: BackgroundMask;
|
|
21
|
+
begin: ICoordinates;
|
|
22
|
+
canvasSize: IDimension;
|
|
23
|
+
colorLine: IRgb;
|
|
24
|
+
context: CanvasRenderingContext2D;
|
|
25
|
+
end: ICoordinates;
|
|
26
|
+
links: Links;
|
|
27
|
+
maxDistance: number;
|
|
28
|
+
opacity: number;
|
|
29
|
+
width: number;
|
|
30
|
+
};
|
|
31
|
+
export type LinkTriangleDrawParams = {
|
|
32
|
+
backgroundMask: BackgroundMask;
|
|
33
|
+
colorTriangle: IRgb;
|
|
34
|
+
context: CanvasRenderingContext2D;
|
|
35
|
+
opacityTriangle: number;
|
|
36
|
+
pos1: ICoordinates;
|
|
37
|
+
pos2: ICoordinates;
|
|
38
|
+
pos3: ICoordinates;
|
|
39
|
+
};
|
|
40
|
+
export type IParticlesLinkOptions = IParticlesOptions & {
|
|
41
|
+
lineLinked?: ILinks;
|
|
42
|
+
line_linked?: ILinks;
|
|
43
|
+
links?: ILinks;
|
|
44
|
+
};
|
|
45
|
+
export type ParticlesLinkOptions = ParticlesOptions & {
|
|
46
|
+
links?: Links;
|
|
47
|
+
};
|
package/types/Utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
1
|
+
import type { LinkLineDrawParams, LinkParticle, LinkTriangleDrawParams } from "./Types";
|
|
2
|
+
export declare function drawLinkLine(params: LinkLineDrawParams): void;
|
|
3
|
+
export declare function drawLinkTriangle(params: LinkTriangleDrawParams): void;
|
|
4
|
+
export declare function getLinkKey(ids: number[]): string;
|
|
5
|
+
export declare function setLinkFrequency(particles: LinkParticle[], dictionary: Map<string, number>): number;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
export declare function loadParticlesLinksInteraction(engine: Engine): Promise<void>;
|
|
2
|
+
export declare function loadParticlesLinksInteraction(engine: Engine, refresh?: boolean): Promise<void>;
|
|
3
3
|
export * from "./Options/Classes/Links";
|
|
4
4
|
export * from "./Options/Classes/LinksShadow";
|
|
5
5
|
export * from "./Options/Classes/LinksTriangle";
|
package/types/interaction.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function loadLinksInteraction(engine: Engine, refresh?: boolean): Promise<void>;
|
package/types/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function loadLinksPlugin(engine: Engine, refresh?: boolean): Promise<void>;
|
package/umd/CircleWarp.js
CHANGED
|
@@ -15,31 +15,15 @@
|
|
|
15
15
|
constructor(x, y, radius, canvasSize) {
|
|
16
16
|
super(x, y, radius);
|
|
17
17
|
this.canvasSize = canvasSize;
|
|
18
|
-
this.canvasSize =
|
|
18
|
+
this.canvasSize = { ...canvasSize };
|
|
19
19
|
}
|
|
20
20
|
contains(point) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
x:
|
|
26
|
-
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);
|
|
21
|
+
const { width, height } = this.canvasSize;
|
|
22
|
+
const { x, y } = point;
|
|
23
|
+
return (super.contains(point) ||
|
|
24
|
+
super.contains({ x: x - width, y }) ||
|
|
25
|
+
super.contains({ x: x - width, y: y - height }) ||
|
|
26
|
+
super.contains({ x, y: y - height }));
|
|
43
27
|
}
|
|
44
28
|
intersects(range) {
|
|
45
29
|
if (super.intersects(range)) {
|
package/umd/LinkInstance.js
CHANGED
|
@@ -4,46 +4,142 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./Utils"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.LinkInstance = void 0;
|
|
13
|
-
const Utils_1 = require("./Utils");
|
|
14
13
|
const engine_1 = require("@tsparticles/engine");
|
|
15
|
-
|
|
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
|
-
}
|
|
14
|
+
const Utils_1 = require("./Utils");
|
|
28
15
|
class LinkInstance {
|
|
29
16
|
constructor(container) {
|
|
30
17
|
this.container = container;
|
|
18
|
+
this._drawLinkLine = (p1, link) => {
|
|
19
|
+
const p1LinksOptions = p1.options.links;
|
|
20
|
+
if (!p1LinksOptions?.enable) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const container = this.container, options = container.actualOptions, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
24
|
+
let opacity = link.opacity;
|
|
25
|
+
container.canvas.draw((ctx) => {
|
|
26
|
+
let colorLine;
|
|
27
|
+
const twinkle = p1.options.twinkle?.lines;
|
|
28
|
+
if (twinkle?.enable) {
|
|
29
|
+
const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
|
|
30
|
+
if (twinkling && twinkleRgb) {
|
|
31
|
+
colorLine = twinkleRgb;
|
|
32
|
+
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!colorLine) {
|
|
36
|
+
const linkColor = p1LinksOptions.id !== undefined
|
|
37
|
+
? container.particles.linksColors.get(p1LinksOptions.id)
|
|
38
|
+
: container.particles.linksColor;
|
|
39
|
+
colorLine = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
40
|
+
}
|
|
41
|
+
if (!colorLine) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const width = p1.retina.linksWidth ?? 0, maxDistance = p1.retina.linksDistance ?? 0, { backgroundMask } = options;
|
|
45
|
+
(0, Utils_1.drawLinkLine)({
|
|
46
|
+
context: ctx,
|
|
47
|
+
width,
|
|
48
|
+
begin: pos1,
|
|
49
|
+
end: pos2,
|
|
50
|
+
maxDistance,
|
|
51
|
+
canvasSize: container.canvas.size,
|
|
52
|
+
links: p1LinksOptions,
|
|
53
|
+
backgroundMask: backgroundMask,
|
|
54
|
+
colorLine,
|
|
55
|
+
opacity,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
this._drawLinkTriangle = (p1, link1, link2) => {
|
|
60
|
+
const linksOptions = p1.options.links;
|
|
61
|
+
if (!linksOptions?.enable) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const triangleOptions = linksOptions.triangles;
|
|
65
|
+
if (!triangleOptions.enable) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) / 2;
|
|
69
|
+
if (opacityTriangle <= 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
container.canvas.draw((ctx) => {
|
|
73
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? 0;
|
|
74
|
+
if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
|
|
75
|
+
(0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
|
|
76
|
+
(0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let colorTriangle = (0, engine_1.rangeColorToRgb)(triangleOptions.color);
|
|
80
|
+
if (!colorTriangle) {
|
|
81
|
+
const linkColor = linksOptions.id !== undefined
|
|
82
|
+
? container.particles.linksColors.get(linksOptions.id)
|
|
83
|
+
: container.particles.linksColor;
|
|
84
|
+
colorTriangle = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
85
|
+
}
|
|
86
|
+
if (!colorTriangle) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
(0, Utils_1.drawLinkTriangle)({
|
|
90
|
+
context: ctx,
|
|
91
|
+
pos1,
|
|
92
|
+
pos2,
|
|
93
|
+
pos3,
|
|
94
|
+
backgroundMask: options.backgroundMask,
|
|
95
|
+
colorTriangle,
|
|
96
|
+
opacityTriangle,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
this._drawTriangles = (options, p1, link, p1Links) => {
|
|
101
|
+
const p2 = link.destination;
|
|
102
|
+
if (!(options.links?.triangles.enable && p2.options.links?.triangles.enable)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const vertices = p2.links?.filter((t) => {
|
|
106
|
+
const linkFreq = this._getLinkFrequency(p2, t.destination);
|
|
107
|
+
return (p2.options.links &&
|
|
108
|
+
linkFreq <= p2.options.links.frequency &&
|
|
109
|
+
p1Links.findIndex((l) => l.destination === t.destination) >= 0);
|
|
110
|
+
});
|
|
111
|
+
if (!vertices?.length) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
for (const vertex of vertices) {
|
|
115
|
+
const p3 = vertex.destination, triangleFreq = this._getTriangleFrequency(p1, p2, p3);
|
|
116
|
+
if (triangleFreq > options.links.triangles.frequency) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
this._drawLinkTriangle(p1, link, vertex);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
this._getLinkFrequency = (p1, p2) => {
|
|
123
|
+
return (0, Utils_1.setLinkFrequency)([p1, p2], this._freqs.links);
|
|
124
|
+
};
|
|
125
|
+
this._getTriangleFrequency = (p1, p2, p3) => {
|
|
126
|
+
return (0, Utils_1.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);
|
|
127
|
+
};
|
|
31
128
|
this._freqs = {
|
|
32
129
|
links: new Map(),
|
|
33
130
|
triangles: new Map(),
|
|
34
131
|
};
|
|
35
132
|
}
|
|
36
133
|
drawParticle(context, particle) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!particle.links || particle.links.length <= 0) {
|
|
134
|
+
const { links, options } = particle;
|
|
135
|
+
if (!links || links.length <= 0) {
|
|
40
136
|
return;
|
|
41
137
|
}
|
|
42
|
-
const p1Links =
|
|
138
|
+
const p1Links = links.filter((l) => options.links && this._getLinkFrequency(particle, l.destination) <= options.links.frequency);
|
|
43
139
|
for (const link of p1Links) {
|
|
44
|
-
this.
|
|
45
|
-
if (link.opacity > 0 && (
|
|
46
|
-
this.
|
|
140
|
+
this._drawTriangles(options, particle, link, p1Links);
|
|
141
|
+
if (link.opacity > 0 && (particle.retina.linksWidth ?? 0) > 0) {
|
|
142
|
+
this._drawLinkLine(particle, link);
|
|
47
143
|
}
|
|
48
144
|
}
|
|
49
145
|
}
|
|
@@ -56,102 +152,13 @@
|
|
|
56
152
|
if (!particle.options.links) {
|
|
57
153
|
return;
|
|
58
154
|
}
|
|
59
|
-
const ratio = this.container.retina.pixelRatio;
|
|
60
|
-
|
|
61
|
-
|
|
155
|
+
const ratio = this.container.retina.pixelRatio, { retina } = particle, { distance, width } = particle.options.links;
|
|
156
|
+
retina.linksDistance = distance * ratio;
|
|
157
|
+
retina.linksWidth = width * ratio;
|
|
62
158
|
}
|
|
63
159
|
particleDestroyed(particle) {
|
|
64
160
|
particle.links = [];
|
|
65
161
|
}
|
|
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
162
|
}
|
|
156
163
|
exports.LinkInstance = LinkInstance;
|
|
157
164
|
});
|
package/umd/Linker.js
CHANGED
|
@@ -14,36 +14,42 @@
|
|
|
14
14
|
const CircleWarp_1 = require("./CircleWarp");
|
|
15
15
|
const Links_1 = require("./Options/Classes/Links");
|
|
16
16
|
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
17
|
-
|
|
17
|
+
const { dx, dy, distance } = (0, engine_1.getDistances)(pos1, pos2);
|
|
18
18
|
if (!warp || distance <= optDistance) {
|
|
19
19
|
return distance;
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
x:
|
|
23
|
-
y:
|
|
21
|
+
const absDiffs = {
|
|
22
|
+
x: Math.abs(dx),
|
|
23
|
+
y: Math.abs(dy),
|
|
24
|
+
}, warpDistances = {
|
|
25
|
+
x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),
|
|
26
|
+
y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y),
|
|
24
27
|
};
|
|
25
|
-
|
|
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;
|
|
28
|
+
return Math.sqrt(warpDistances.x ** 2 + warpDistances.y ** 2);
|
|
43
29
|
}
|
|
44
30
|
class Linker extends engine_1.ParticlesInteractorBase {
|
|
45
31
|
constructor(container) {
|
|
46
32
|
super(container);
|
|
33
|
+
this._setColor = (p1) => {
|
|
34
|
+
if (!p1.options.links) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const container = this.linkContainer, linksOptions = p1.options.links;
|
|
38
|
+
let linkColor = linksOptions.id === undefined
|
|
39
|
+
? container.particles.linksColor
|
|
40
|
+
: container.particles.linksColors.get(linksOptions.id);
|
|
41
|
+
if (linkColor) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const optColor = linksOptions.color;
|
|
45
|
+
linkColor = (0, engine_1.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);
|
|
46
|
+
if (linksOptions.id === undefined) {
|
|
47
|
+
container.particles.linksColor = linkColor;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
47
53
|
this.linkContainer = container;
|
|
48
54
|
}
|
|
49
55
|
clear() {
|
|
@@ -53,7 +59,6 @@
|
|
|
53
59
|
this.linkContainer.particles.linksColors = new Map();
|
|
54
60
|
}
|
|
55
61
|
async interact(p1) {
|
|
56
|
-
var _a;
|
|
57
62
|
if (!p1.options.links) {
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
@@ -62,19 +67,19 @@
|
|
|
62
67
|
if (pos1.x < 0 || pos1.y < 0 || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
63
68
|
return;
|
|
64
69
|
}
|
|
65
|
-
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance =
|
|
70
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? 0, warp = linkOpt1.warp, range = warp
|
|
66
71
|
? new CircleWarp_1.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize)
|
|
67
72
|
: new engine_1.Circle(pos1.x, pos1.y, optDistance), query = container.particles.quadTree.query(range);
|
|
68
73
|
for (const p2 of query) {
|
|
69
74
|
const linkOpt2 = p2.options.links;
|
|
70
75
|
if (p1 === p2 ||
|
|
71
|
-
!
|
|
76
|
+
!linkOpt2?.enable ||
|
|
72
77
|
linkOpt1.id !== linkOpt2.id ||
|
|
73
78
|
p2.spawning ||
|
|
74
79
|
p2.destroyed ||
|
|
75
80
|
!p2.links ||
|
|
76
|
-
p1.links.
|
|
77
|
-
p2.links.
|
|
81
|
+
p1.links.some((t) => t.destination === p2) ||
|
|
82
|
+
p2.links.some((t) => t.destination === p1)) {
|
|
78
83
|
continue;
|
|
79
84
|
}
|
|
80
85
|
const pos2 = p2.getPosition();
|
|
@@ -83,10 +88,10 @@
|
|
|
83
88
|
}
|
|
84
89
|
const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
|
85
90
|
if (distance > optDistance) {
|
|
86
|
-
|
|
91
|
+
continue;
|
|
87
92
|
}
|
|
88
93
|
const opacityLine = (1 - distance / optDistance) * optOpacity;
|
|
89
|
-
this.
|
|
94
|
+
this._setColor(p1);
|
|
90
95
|
p1.links.push({
|
|
91
96
|
destination: p2,
|
|
92
97
|
opacity: opacityLine,
|
|
@@ -94,40 +99,18 @@
|
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
isEnabled(particle) {
|
|
97
|
-
|
|
98
|
-
return !!((_a = particle.options.links) === null || _a === void 0 ? void 0 : _a.enable);
|
|
102
|
+
return !!particle.options.links?.enable;
|
|
99
103
|
}
|
|
100
104
|
loadParticlesOptions(options, ...sources) {
|
|
101
|
-
var _a, _b;
|
|
102
105
|
if (!options.links) {
|
|
103
106
|
options.links = new Links_1.Links();
|
|
104
107
|
}
|
|
105
108
|
for (const source of sources) {
|
|
106
|
-
options.links.load(
|
|
109
|
+
options.links.load(source?.links ?? source?.lineLinked ?? source?.line_linked);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
reset() {
|
|
110
113
|
}
|
|
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
114
|
}
|
|
132
115
|
exports.Linker = Linker;
|
|
133
116
|
});
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./LinksShadow", "./LinksTriangle"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Links = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
13
14
|
const LinksShadow_1 = require("./LinksShadow");
|
|
14
15
|
const LinksTriangle_1 = require("./LinksTriangle");
|
|
15
|
-
const engine_1 = require("@tsparticles/engine");
|
|
16
16
|
class Links {
|
|
17
17
|
constructor() {
|
|
18
18
|
this.blink = false;
|