@tsparticles/interaction-particles-links 3.9.0 → 4.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/418.min.js +2 -0
- package/418.min.js.LICENSE.txt +1 -0
- package/497.min.js +2 -0
- package/497.min.js.LICENSE.txt +1 -0
- package/711.min.js +2 -0
- package/711.min.js.LICENSE.txt +1 -0
- package/956.min.js +2 -0
- package/956.min.js.LICENSE.txt +1 -0
- package/browser/CircleWarp.js +2 -2
- package/browser/LinkInstance.js +7 -7
- package/browser/Linker.js +4 -7
- package/browser/Utils.js +5 -11
- package/browser/index.js +7 -9
- package/browser/interaction.js +7 -5
- package/browser/plugin.js +5 -4
- package/cjs/CircleWarp.js +6 -10
- package/cjs/Interfaces.js +1 -2
- package/cjs/LinkInstance.js +22 -26
- package/cjs/Linker.js +12 -19
- package/cjs/LinksPlugin.js +3 -7
- package/cjs/Options/Classes/Links.js +9 -13
- package/cjs/Options/Classes/LinksShadow.js +5 -9
- package/cjs/Options/Classes/LinksTriangle.js +4 -8
- package/cjs/Options/Interfaces/ILinks.js +1 -2
- package/cjs/Options/Interfaces/ILinksShadow.js +1 -2
- package/cjs/Options/Interfaces/ILinksTriangle.js +1 -2
- package/cjs/Types.js +1 -2
- package/cjs/Utils.js +20 -33
- package/cjs/index.js +10 -29
- package/cjs/interaction.js +7 -8
- package/cjs/plugin.js +5 -7
- package/dist_browser_Linker_js.js +40 -0
- package/dist_browser_LinksPlugin_js.js +50 -0
- package/dist_browser_interaction_js.js +30 -0
- package/dist_browser_plugin_js.js +30 -0
- package/esm/CircleWarp.js +2 -2
- package/esm/LinkInstance.js +7 -7
- package/esm/Linker.js +4 -7
- package/esm/Utils.js +5 -11
- package/esm/index.js +7 -9
- package/esm/interaction.js +7 -5
- package/esm/plugin.js +5 -4
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.interaction.particles.links.js +221 -102
- package/tsparticles.interaction.particles.links.min.js +1 -1
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +1 -1
- package/types/LinkInstance.d.ts +1 -1
- package/types/Linker.d.ts +1 -2
- package/types/Types.d.ts +3 -3
- package/types/index.d.ts +4 -4
- package/types/interaction.d.ts +1 -1
- package/types/plugin.d.ts +1 -1
- package/umd/CircleWarp.js +2 -2
- package/umd/LinkInstance.js +7 -7
- package/umd/Linker.js +4 -7
- package/umd/Utils.js +5 -11
- package/umd/index.js +31 -10
- package/umd/interaction.js +42 -6
- package/umd/plugin.js +40 -5
package/418.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 418.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[418],{418(t,n,i){function e(t){t.register((n=>{n.addInteractor("particlesLinks",(async n=>{const{Linker:e}=await i.e(497).then(i.bind(i,497));return new e(n,t)}))}))}i.d(n,{loadLinksInteraction:()=>e})}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v4.0.0-alpha.0 by Matteo Bruni */
|
package/497.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 497.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[497],{497(i,t,s){s.d(t,{Linker:()=>l});var n=s(303);class e extends n.Circle{constructor(i,t,s,n){super(i,t,s),this.canvasSize=n,this.canvasSize={...n}}contains(i){const{width:t,height:s}=this.canvasSize,{x:n,y:e}=i;return super.contains(i)||super.contains({x:n-t,y:e})||super.contains({x:n-t,y:e-s})||super.contains({x:n,y:e-s})}intersects(i){if(super.intersects(i))return!0;const t=i,s=i,e={x:i.position.x-this.canvasSize.width,y:i.position.y-this.canvasSize.height};if(Object.hasOwn(s,"radius")){const i=new n.Circle(e.x,e.y,2*s.radius);return super.intersects(i)}if(Object.hasOwn(t,"size")){const i=new n.Rectangle(e.x,e.y,2*t.size.width,2*t.size.height);return super.intersects(i)}return!1}}var o=s(509);const r=0,c=0;function a(i,t,s,e,o){const{dx:r,dy:c,distance:a}=(0,n.getDistances)(i,t);if(!o||a<=s)return a;const l={x:Math.abs(r),y:Math.abs(c)},h=Math.min(l.x,e.width-l.x),p=Math.min(l.y,e.height-l.y);return Math.sqrt(h**2+p**2)}class l extends n.ParticlesInteractorBase{constructor(i,t){super(i),this._setColor=i=>{if(!i.options.links)return;const t=this.container,s=i.options.links;let e=void 0===s.id?t.particles.linksColor:t.particles.linksColors.get(s.id);if(e)return;const o=s.color;e=(0,n.getLinkRandomColor)(this._engine,o,s.blink,s.consent),void 0===s.id?t.particles.linksColor=e:t.particles.linksColors.set(s.id,e)},this._engine=t}clear(){}init(){this.container.particles.linksColor=void 0,this.container.particles.linksColors=new Map}interact(i){if(!i.options.links)return;i.links=[];const t=i.getPosition(),s=this.container,o=s.canvas.size;if(t.x<r||t.y<c||t.x>o.width||t.y>o.height)return;const l=i.options.links,h=l.opacity,p=i.retina.linksDistance??0,u=l.warp;let d;d=u?new e(t.x,t.y,p,o):new n.Circle(t.x,t.y,p);const k=s.particles.quadTree.query(d);for(const s of k){const n=s.options.links;if(i===s||!n?.enable||l.id!==n.id||s.spawning||s.destroyed||!s.links||i.links.some((i=>i.destination===s))||s.links.some((t=>t.destination===i)))continue;const e=s.getPosition();if(e.x<r||e.y<c||e.x>o.width||e.y>o.height)continue;const d=a(t,e,p,o,u&&n.warp);if(d>p)continue;const k=(1-d/p)*h;this._setColor(i),i.links.push({destination:s,opacity:k})}}isEnabled(i){return!!i.options.links?.enable}loadParticlesOptions(i,...t){i.links??=new o.q;for(const s of t)i.links.load(s?.links)}reset(){}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v4.0.0-alpha.0 by Matteo Bruni */
|
package/711.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 711.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[711],{711(i,n,t){function s(i){i.register((async i=>{const{LinksPlugin:n}=await t.e(956).then(t.bind(t,956));i.addPlugin(new n(i))}))}t.d(n,{loadLinksPlugin:()=>s})}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v4.0.0-alpha.0 by Matteo Bruni */
|
package/956.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 956.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[956],{956(i,n,t){t.d(n,{LinksPlugin:()=>r});var e=t(303);function s(i,n){const t=((s=i.map((i=>i.id))).sort(((i,n)=>i-n)),s.join("_"));var s;let o=n.get(t);return void 0===o&&(o=(0,e.getRandom)(),n.set(t,o)),o}class o{constructor(i,n){this._drawLinkLine=(i,n)=>{const t=i.options.links;if(!t?.enable)return;const s=this._container,o=n.destination,r=i.getPosition(),a=o.getPosition();let l=n.opacity;s.canvas.draw((n=>{let c;const g=i.options.twinkle?.lines;if(g?.enable){const i=g.frequency,n=(0,e.rangeColorToRgb)(this._engine,g.color);(0,e.getRandom)()<i&&n&&(c=n,l=(0,e.getRangeValue)(g.opacity))}if(!c){const n=void 0!==t.id?s.particles.linksColors.get(t.id):s.particles.linksColor;c=(0,e.getLinkColor)(i,o,n)}if(!c)return;const d=i.retina.linksWidth??0,h=i.retina.linksDistance??0;!function(i){let n=!1;const{begin:t,end:s,engine:o,maxDistance:r,context:a,canvasSize:l,width:c,colorLine:g,opacity:d,links:h,hdr:k}=i;if((0,e.getDistance)(t,s)<=r)(0,e.drawLine)(a,t,s),n=!0;else if(h.warp){let i,o;const c={x:s.x-l.width,y:s.y},g=(0,e.getDistances)(t,c);if(g.distance<=r){const n=t.y-g.dy/g.dx*t.x;i={x:0,y:n},o={x:l.width,y:n}}else{const n={x:s.x,y:s.y-l.height},a=(0,e.getDistances)(t,n);if(a.distance<=r){const n=-(t.y-a.dy/a.dx*t.x)/(a.dy/a.dx);i={x:n,y:0},o={x:n,y:l.height}}else{const n={x:s.x-l.width,y:s.y-l.height},a=(0,e.getDistances)(t,n);if(a.distance<=r){const n=t.y-a.dy/a.dx*t.x;i={x:-n/(a.dy/a.dx),y:n},o={x:i.x+l.width,y:i.y+l.height}}}}i&&o&&((0,e.drawLine)(a,t,i),(0,e.drawLine)(a,s,o),n=!0)}if(!n)return;a.lineWidth=c,a.strokeStyle=(0,e.getStyleFromRgb)(g,k,d);const{shadow:y}=h;if(y.enable){const i=(0,e.rangeColorToRgb)(o,y.color);i&&(a.shadowBlur=y.blur,a.shadowColor=(0,e.getStyleFromRgb)(i,k))}a.stroke()}({context:n,width:d,begin:r,end:a,engine:this._engine,maxDistance:h,canvasSize:s.canvas.size,links:t,colorLine:c,opacity:l,hdr:s.hdr})}))},this._drawLinkTriangle=(i,n,t)=>{const s=i.options.links;if(!s?.enable)return;const o=s.triangles;if(!o.enable)return;const r=this._container,a=n.destination,l=t.destination,c=o.opacity??.5*(n.opacity+t.opacity);c<=0||r.canvas.draw((n=>{const t=i.getPosition(),g=a.getPosition(),d=l.getPosition(),h=i.retina.linksDistance??0;if((0,e.getDistance)(t,g)>h||(0,e.getDistance)(d,g)>h||(0,e.getDistance)(d,t)>h)return;let k=(0,e.rangeColorToRgb)(this._engine,o.color);if(!k){const n=void 0!==s.id?r.particles.linksColors.get(s.id):r.particles.linksColor;k=(0,e.getLinkColor)(i,a,n)}k&&function(i){const{context:n,hdr:t,pos1:s,pos2:o,pos3:r,colorTriangle:a,opacityTriangle:l}=i;!function(i,n,t,e){i.beginPath(),i.moveTo(n.x,n.y),i.lineTo(t.x,t.y),i.lineTo(e.x,e.y),i.closePath()}(n,s,o,r),n.fillStyle=(0,e.getStyleFromRgb)(a,t,l),n.fill()}({context:n,pos1:t,pos2:g,pos3:d,colorTriangle:k,opacityTriangle:c,hdr:r.hdr})}))},this._drawTriangles=(i,n,t,e)=>{const s=t.destination;if(!i.links?.triangles.enable||!s.options.links?.triangles.enable)return;const o=s.links?.filter((i=>{const n=this._getLinkFrequency(s,i.destination);return s.options.links&&n<=s.options.links.frequency&&e.findIndex((n=>n.destination===i.destination))>=0}));if(o?.length)for(const e of o){const o=e.destination;this._getTriangleFrequency(n,s,o)>i.links.triangles.frequency||this._drawLinkTriangle(n,t,e)}},this._getLinkFrequency=(i,n)=>s([i,n],this._freqs.links),this._getTriangleFrequency=(i,n,t)=>s([i,n,t],this._freqs.triangles),this._container=i,this._engine=n,this._freqs={links:new Map,triangles:new Map}}drawParticle(i,n){const{links:t,options:e}=n;if(!t?.length)return;const s=t.filter((i=>e.links&&(e.links.frequency>=1||this._getLinkFrequency(n,i.destination)<=e.links.frequency)));for(const i of s)this._drawTriangles(e,n,i,s),i.opacity>0&&(n.retina.linksWidth??0)>0&&this._drawLinkLine(n,i)}async init(){this._freqs.links=new Map,this._freqs.triangles=new Map,await Promise.resolve()}particleCreated(i){if(i.links=[],!i.options.links)return;const n=this._container.retina.pixelRatio,{retina:t}=i,{distance:e,width:s}=i.options.links;t.linksDistance=e*n,t.linksWidth=s*n}particleDestroyed(i){i.links=[]}}class r{constructor(i){this.id="links",this._engine=i}getPlugin(i){return Promise.resolve(new o(i,this._engine))}loadOptions(){}needsPlugin(){return!0}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v4.0.0-alpha.0 by Matteo Bruni */
|
package/browser/CircleWarp.js
CHANGED
|
@@ -21,11 +21,11 @@ export class CircleWarp extends Circle {
|
|
|
21
21
|
x: range.position.x - this.canvasSize.width,
|
|
22
22
|
y: range.position.y - this.canvasSize.height,
|
|
23
23
|
};
|
|
24
|
-
if (circle
|
|
24
|
+
if (Object.hasOwn(circle, "radius")) {
|
|
25
25
|
const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * double);
|
|
26
26
|
return super.intersects(biggerCircle);
|
|
27
27
|
}
|
|
28
|
-
else if (rect
|
|
28
|
+
else if (Object.hasOwn(rect, "size")) {
|
|
29
29
|
const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * double, rect.size.height * double);
|
|
30
30
|
return super.intersects(rectSW);
|
|
31
31
|
}
|
package/browser/LinkInstance.js
CHANGED
|
@@ -8,11 +8,11 @@ export class LinkInstance {
|
|
|
8
8
|
if (!p1LinksOptions?.enable) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const container = this._container,
|
|
11
|
+
const container = this._container, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
12
12
|
let opacity = link.opacity;
|
|
13
13
|
container.canvas.draw(ctx => {
|
|
14
14
|
let colorLine;
|
|
15
|
-
const twinkle = p1.options
|
|
15
|
+
const twinkle = p1.options["twinkle"]?.lines;
|
|
16
16
|
if (twinkle?.enable) {
|
|
17
17
|
const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(this._engine, twinkle.color), twinkling = getRandom() < twinkleFreq;
|
|
18
18
|
if (twinkling && twinkleRgb) {
|
|
@@ -29,7 +29,7 @@ export class LinkInstance {
|
|
|
29
29
|
if (!colorLine) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance
|
|
32
|
+
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance;
|
|
33
33
|
drawLinkLine({
|
|
34
34
|
context: ctx,
|
|
35
35
|
width,
|
|
@@ -39,9 +39,9 @@ export class LinkInstance {
|
|
|
39
39
|
maxDistance,
|
|
40
40
|
canvasSize: container.canvas.size,
|
|
41
41
|
links: p1LinksOptions,
|
|
42
|
-
backgroundMask: backgroundMask,
|
|
43
42
|
colorLine,
|
|
44
43
|
opacity,
|
|
44
|
+
hdr: container.hdr,
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
};
|
|
@@ -54,7 +54,7 @@ export class LinkInstance {
|
|
|
54
54
|
if (!triangleOptions.enable) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
const container = this._container,
|
|
57
|
+
const container = this._container, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
|
|
58
58
|
if (opacityTriangle <= minOpacity) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
@@ -80,9 +80,9 @@ export class LinkInstance {
|
|
|
80
80
|
pos1,
|
|
81
81
|
pos2,
|
|
82
82
|
pos3,
|
|
83
|
-
backgroundMask: options.backgroundMask,
|
|
84
83
|
colorTriangle,
|
|
85
84
|
opacityTriangle,
|
|
85
|
+
hdr: container.hdr,
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
};
|
|
@@ -121,7 +121,7 @@ export class LinkInstance {
|
|
|
121
121
|
triangles: new Map(),
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
drawParticle(
|
|
124
|
+
drawParticle(_context, particle) {
|
|
125
125
|
const { links, options } = particle;
|
|
126
126
|
if (!links?.length) {
|
|
127
127
|
return;
|
package/browser/Linker.js
CHANGED
|
@@ -26,7 +26,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
26
26
|
if (!p1.options.links) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
const container = this.
|
|
29
|
+
const container = this.container, linksOptions = p1.options.links;
|
|
30
30
|
let linkColor = linksOptions.id === undefined
|
|
31
31
|
? container.particles.linksColor
|
|
32
32
|
: container.particles.linksColors.get(linksOptions.id);
|
|
@@ -42,14 +42,13 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
42
42
|
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
this._linkContainer = container;
|
|
46
45
|
this._engine = engine;
|
|
47
46
|
}
|
|
48
47
|
clear() {
|
|
49
48
|
}
|
|
50
49
|
init() {
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
50
|
+
this.container.particles.linksColor = undefined;
|
|
51
|
+
this.container.particles.linksColors = new Map();
|
|
53
52
|
}
|
|
54
53
|
interact(p1) {
|
|
55
54
|
if (!p1.options.links) {
|
|
@@ -101,9 +100,7 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
101
100
|
return !!particle.options.links?.enable;
|
|
102
101
|
}
|
|
103
102
|
loadParticlesOptions(options, ...sources) {
|
|
104
|
-
|
|
105
|
-
options.links = new Links();
|
|
106
|
-
}
|
|
103
|
+
options.links ??= new Links();
|
|
107
104
|
for (const source of sources) {
|
|
108
105
|
options.links.load(source?.links);
|
|
109
106
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -8,7 +8,7 @@ export function drawTriangle(context, p1, p2, p3) {
|
|
|
8
8
|
}
|
|
9
9
|
export function drawLinkLine(params) {
|
|
10
10
|
let drawn = false;
|
|
11
|
-
const { begin, end, engine, maxDistance, context, canvasSize, width,
|
|
11
|
+
const { begin, end, engine, maxDistance, context, canvasSize, width, colorLine, opacity, links, hdr } = params;
|
|
12
12
|
if (getDistance(begin, end) <= maxDistance) {
|
|
13
13
|
drawLine(context, begin, end);
|
|
14
14
|
drawn = true;
|
|
@@ -62,27 +62,21 @@ export function drawLinkLine(params) {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
context.lineWidth = width;
|
|
65
|
-
|
|
66
|
-
context.globalCompositeOperation = backgroundMask.composite;
|
|
67
|
-
}
|
|
68
|
-
context.strokeStyle = getStyleFromRgb(colorLine, opacity);
|
|
65
|
+
context.strokeStyle = getStyleFromRgb(colorLine, hdr, opacity);
|
|
69
66
|
const { shadow } = links;
|
|
70
67
|
if (shadow.enable) {
|
|
71
68
|
const shadowColor = rangeColorToRgb(engine, shadow.color);
|
|
72
69
|
if (shadowColor) {
|
|
73
70
|
context.shadowBlur = shadow.blur;
|
|
74
|
-
context.shadowColor = getStyleFromRgb(shadowColor);
|
|
71
|
+
context.shadowColor = getStyleFromRgb(shadowColor, hdr);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
context.stroke();
|
|
78
75
|
}
|
|
79
76
|
export function drawLinkTriangle(params) {
|
|
80
|
-
const { context, pos1, pos2, pos3,
|
|
77
|
+
const { context, hdr, pos1, pos2, pos3, colorTriangle, opacityTriangle } = params;
|
|
81
78
|
drawTriangle(context, pos1, pos2, pos3);
|
|
82
|
-
|
|
83
|
-
context.globalCompositeOperation = backgroundMask.composite;
|
|
84
|
-
}
|
|
85
|
-
context.fillStyle = getStyleFromRgb(colorTriangle, opacityTriangle);
|
|
79
|
+
context.fillStyle = getStyleFromRgb(colorTriangle, hdr, opacityTriangle);
|
|
86
80
|
context.fill();
|
|
87
81
|
}
|
|
88
82
|
export function getLinkKey(ids) {
|
package/browser/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function loadParticlesLinksInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { loadLinksInteraction } = await import("./interaction.js"), { loadLinksPlugin } = await import("./plugin.js");
|
|
5
|
+
loadLinksInteraction(e);
|
|
6
|
+
loadLinksPlugin(e);
|
|
7
|
+
});
|
|
7
8
|
}
|
|
8
9
|
export * from "./Options/Classes/Links.js";
|
|
9
10
|
export * from "./Options/Classes/LinksShadow.js";
|
|
10
11
|
export * from "./Options/Classes/LinksTriangle.js";
|
|
11
|
-
export * from "./Options/Interfaces/ILinks.js";
|
|
12
|
-
export * from "./Options/Interfaces/ILinksShadow.js";
|
|
13
|
-
export * from "./Options/Interfaces/ILinksTriangle.js";
|
package/browser/interaction.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export function loadLinksInteraction(engine) {
|
|
2
|
+
engine.register(e => {
|
|
3
|
+
e.addInteractor("particlesLinks", async (container) => {
|
|
4
|
+
const { Linker } = await import("./Linker.js");
|
|
5
|
+
return new Linker(container, engine);
|
|
6
|
+
});
|
|
7
|
+
});
|
|
6
8
|
}
|
package/browser/plugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export function loadLinksPlugin(engine) {
|
|
2
|
+
engine.register(async (e) => {
|
|
3
|
+
const { LinksPlugin } = await import("./LinksPlugin.js");
|
|
4
|
+
e.addPlugin(new LinksPlugin(e));
|
|
5
|
+
});
|
|
5
6
|
}
|
package/cjs/CircleWarp.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CircleWarp = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
5
2
|
const double = 2;
|
|
6
|
-
class CircleWarp extends
|
|
3
|
+
export class CircleWarp extends Circle {
|
|
7
4
|
constructor(x, y, radius, canvasSize) {
|
|
8
5
|
super(x, y, radius);
|
|
9
6
|
this.canvasSize = canvasSize;
|
|
@@ -24,15 +21,14 @@ class CircleWarp extends engine_1.Circle {
|
|
|
24
21
|
x: range.position.x - this.canvasSize.width,
|
|
25
22
|
y: range.position.y - this.canvasSize.height,
|
|
26
23
|
};
|
|
27
|
-
if (circle
|
|
28
|
-
const biggerCircle = new
|
|
24
|
+
if (Object.hasOwn(circle, "radius")) {
|
|
25
|
+
const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * double);
|
|
29
26
|
return super.intersects(biggerCircle);
|
|
30
27
|
}
|
|
31
|
-
else if (rect
|
|
32
|
-
const rectSW = new
|
|
28
|
+
else if (Object.hasOwn(rect, "size")) {
|
|
29
|
+
const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * double, rect.size.height * double);
|
|
33
30
|
return super.intersects(rectSW);
|
|
34
31
|
}
|
|
35
32
|
return false;
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.CircleWarp = CircleWarp;
|
package/cjs/Interfaces.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/LinkInstance.js
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.LinkInstance = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const Utils_js_1 = require("./Utils.js");
|
|
1
|
+
import { getDistance, getLinkColor, getRandom, getRangeValue, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
|
+
import { drawLinkLine, drawLinkTriangle, setLinkFrequency } from "./Utils.js";
|
|
6
3
|
const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5, maxFrequency = 1;
|
|
7
|
-
class LinkInstance {
|
|
4
|
+
export class LinkInstance {
|
|
8
5
|
constructor(container, engine) {
|
|
9
6
|
this._drawLinkLine = (p1, link) => {
|
|
10
7
|
const p1LinksOptions = p1.options.links;
|
|
11
8
|
if (!p1LinksOptions?.enable) {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
|
-
const container = this._container,
|
|
11
|
+
const container = this._container, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
15
12
|
let opacity = link.opacity;
|
|
16
13
|
container.canvas.draw(ctx => {
|
|
17
14
|
let colorLine;
|
|
18
|
-
const twinkle = p1.options
|
|
15
|
+
const twinkle = p1.options["twinkle"]?.lines;
|
|
19
16
|
if (twinkle?.enable) {
|
|
20
|
-
const twinkleFreq = twinkle.frequency, twinkleRgb =
|
|
17
|
+
const twinkleFreq = twinkle.frequency, twinkleRgb = rangeColorToRgb(this._engine, twinkle.color), twinkling = getRandom() < twinkleFreq;
|
|
21
18
|
if (twinkling && twinkleRgb) {
|
|
22
19
|
colorLine = twinkleRgb;
|
|
23
|
-
opacity =
|
|
20
|
+
opacity = getRangeValue(twinkle.opacity);
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
23
|
if (!colorLine) {
|
|
27
24
|
const linkColor = p1LinksOptions.id !== undefined
|
|
28
25
|
? container.particles.linksColors.get(p1LinksOptions.id)
|
|
29
26
|
: container.particles.linksColor;
|
|
30
|
-
colorLine =
|
|
27
|
+
colorLine = getLinkColor(p1, p2, linkColor);
|
|
31
28
|
}
|
|
32
29
|
if (!colorLine) {
|
|
33
30
|
return;
|
|
34
31
|
}
|
|
35
|
-
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance
|
|
36
|
-
|
|
32
|
+
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance;
|
|
33
|
+
drawLinkLine({
|
|
37
34
|
context: ctx,
|
|
38
35
|
width,
|
|
39
36
|
begin: pos1,
|
|
@@ -42,9 +39,9 @@ class LinkInstance {
|
|
|
42
39
|
maxDistance,
|
|
43
40
|
canvasSize: container.canvas.size,
|
|
44
41
|
links: p1LinksOptions,
|
|
45
|
-
backgroundMask: backgroundMask,
|
|
46
42
|
colorLine,
|
|
47
43
|
opacity,
|
|
44
|
+
hdr: container.hdr,
|
|
48
45
|
});
|
|
49
46
|
});
|
|
50
47
|
};
|
|
@@ -57,35 +54,35 @@ class LinkInstance {
|
|
|
57
54
|
if (!triangleOptions.enable) {
|
|
58
55
|
return;
|
|
59
56
|
}
|
|
60
|
-
const container = this._container,
|
|
57
|
+
const container = this._container, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
|
|
61
58
|
if (opacityTriangle <= minOpacity) {
|
|
62
59
|
return;
|
|
63
60
|
}
|
|
64
61
|
container.canvas.draw(ctx => {
|
|
65
62
|
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? minDistance;
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
if (getDistance(pos1, pos2) > linksDistance ||
|
|
64
|
+
getDistance(pos3, pos2) > linksDistance ||
|
|
65
|
+
getDistance(pos3, pos1) > linksDistance) {
|
|
69
66
|
return;
|
|
70
67
|
}
|
|
71
|
-
let colorTriangle =
|
|
68
|
+
let colorTriangle = rangeColorToRgb(this._engine, triangleOptions.color);
|
|
72
69
|
if (!colorTriangle) {
|
|
73
70
|
const linkColor = linksOptions.id !== undefined
|
|
74
71
|
? container.particles.linksColors.get(linksOptions.id)
|
|
75
72
|
: container.particles.linksColor;
|
|
76
|
-
colorTriangle =
|
|
73
|
+
colorTriangle = getLinkColor(p1, p2, linkColor);
|
|
77
74
|
}
|
|
78
75
|
if (!colorTriangle) {
|
|
79
76
|
return;
|
|
80
77
|
}
|
|
81
|
-
|
|
78
|
+
drawLinkTriangle({
|
|
82
79
|
context: ctx,
|
|
83
80
|
pos1,
|
|
84
81
|
pos2,
|
|
85
82
|
pos3,
|
|
86
|
-
backgroundMask: options.backgroundMask,
|
|
87
83
|
colorTriangle,
|
|
88
84
|
opacityTriangle,
|
|
85
|
+
hdr: container.hdr,
|
|
89
86
|
});
|
|
90
87
|
});
|
|
91
88
|
};
|
|
@@ -112,10 +109,10 @@ class LinkInstance {
|
|
|
112
109
|
}
|
|
113
110
|
};
|
|
114
111
|
this._getLinkFrequency = (p1, p2) => {
|
|
115
|
-
return
|
|
112
|
+
return setLinkFrequency([p1, p2], this._freqs.links);
|
|
116
113
|
};
|
|
117
114
|
this._getTriangleFrequency = (p1, p2, p3) => {
|
|
118
|
-
return
|
|
115
|
+
return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
|
|
119
116
|
};
|
|
120
117
|
this._container = container;
|
|
121
118
|
this._engine = engine;
|
|
@@ -124,7 +121,7 @@ class LinkInstance {
|
|
|
124
121
|
triangles: new Map(),
|
|
125
122
|
};
|
|
126
123
|
}
|
|
127
|
-
drawParticle(
|
|
124
|
+
drawParticle(_context, particle) {
|
|
128
125
|
const { links, options } = particle;
|
|
129
126
|
if (!links?.length) {
|
|
130
127
|
return;
|
|
@@ -157,4 +154,3 @@ class LinkInstance {
|
|
|
157
154
|
particle.links = [];
|
|
158
155
|
}
|
|
159
156
|
}
|
|
160
|
-
exports.LinkInstance = LinkInstance;
|
package/cjs/Linker.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const CircleWarp_js_1 = require("./CircleWarp.js");
|
|
6
|
-
const Links_js_1 = require("./Options/Classes/Links.js");
|
|
1
|
+
import { Circle, ParticlesInteractorBase, getDistances, getLinkRandomColor, } from "@tsparticles/engine";
|
|
2
|
+
import { CircleWarp } from "./CircleWarp.js";
|
|
3
|
+
import { Links } from "./Options/Classes/Links.js";
|
|
7
4
|
const squarePower = 2, opacityOffset = 1, origin = {
|
|
8
5
|
x: 0,
|
|
9
6
|
y: 0,
|
|
10
7
|
}, minDistance = 0;
|
|
11
8
|
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
12
|
-
const { dx, dy, distance } =
|
|
9
|
+
const { dx, dy, distance } = getDistances(pos1, pos2);
|
|
13
10
|
if (!warp || distance <= optDistance) {
|
|
14
11
|
return distance;
|
|
15
12
|
}
|
|
@@ -22,14 +19,14 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
|
22
19
|
};
|
|
23
20
|
return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
|
|
24
21
|
}
|
|
25
|
-
class Linker extends
|
|
22
|
+
export class Linker extends ParticlesInteractorBase {
|
|
26
23
|
constructor(container, engine) {
|
|
27
24
|
super(container);
|
|
28
25
|
this._setColor = p1 => {
|
|
29
26
|
if (!p1.options.links) {
|
|
30
27
|
return;
|
|
31
28
|
}
|
|
32
|
-
const container = this.
|
|
29
|
+
const container = this.container, linksOptions = p1.options.links;
|
|
33
30
|
let linkColor = linksOptions.id === undefined
|
|
34
31
|
? container.particles.linksColor
|
|
35
32
|
: container.particles.linksColors.get(linksOptions.id);
|
|
@@ -37,7 +34,7 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
37
34
|
return;
|
|
38
35
|
}
|
|
39
36
|
const optColor = linksOptions.color;
|
|
40
|
-
linkColor =
|
|
37
|
+
linkColor = getLinkRandomColor(this._engine, optColor, linksOptions.blink, linksOptions.consent);
|
|
41
38
|
if (linksOptions.id === undefined) {
|
|
42
39
|
container.particles.linksColor = linkColor;
|
|
43
40
|
}
|
|
@@ -45,14 +42,13 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
45
42
|
container.particles.linksColors.set(linksOptions.id, linkColor);
|
|
46
43
|
}
|
|
47
44
|
};
|
|
48
|
-
this._linkContainer = container;
|
|
49
45
|
this._engine = engine;
|
|
50
46
|
}
|
|
51
47
|
clear() {
|
|
52
48
|
}
|
|
53
49
|
init() {
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
50
|
+
this.container.particles.linksColor = undefined;
|
|
51
|
+
this.container.particles.linksColors = new Map();
|
|
56
52
|
}
|
|
57
53
|
interact(p1) {
|
|
58
54
|
if (!p1.options.links) {
|
|
@@ -66,10 +62,10 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
66
62
|
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp;
|
|
67
63
|
let range;
|
|
68
64
|
if (warp) {
|
|
69
|
-
range = new
|
|
65
|
+
range = new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);
|
|
70
66
|
}
|
|
71
67
|
else {
|
|
72
|
-
range = new
|
|
68
|
+
range = new Circle(pos1.x, pos1.y, optDistance);
|
|
73
69
|
}
|
|
74
70
|
const query = container.particles.quadTree.query(range);
|
|
75
71
|
for (const p2 of query) {
|
|
@@ -104,9 +100,7 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
104
100
|
return !!particle.options.links?.enable;
|
|
105
101
|
}
|
|
106
102
|
loadParticlesOptions(options, ...sources) {
|
|
107
|
-
|
|
108
|
-
options.links = new Links_js_1.Links();
|
|
109
|
-
}
|
|
103
|
+
options.links ??= new Links();
|
|
110
104
|
for (const source of sources) {
|
|
111
105
|
options.links.load(source?.links);
|
|
112
106
|
}
|
|
@@ -114,4 +108,3 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
114
108
|
reset() {
|
|
115
109
|
}
|
|
116
110
|
}
|
|
117
|
-
exports.Linker = Linker;
|
package/cjs/LinksPlugin.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.LinksPlugin = void 0;
|
|
4
|
-
const LinkInstance_js_1 = require("./LinkInstance.js");
|
|
5
|
-
class LinksPlugin {
|
|
1
|
+
import { LinkInstance } from "./LinkInstance.js";
|
|
2
|
+
export class LinksPlugin {
|
|
6
3
|
constructor(engine) {
|
|
7
4
|
this.id = "links";
|
|
8
5
|
this._engine = engine;
|
|
9
6
|
}
|
|
10
7
|
getPlugin(container) {
|
|
11
|
-
return Promise.resolve(new
|
|
8
|
+
return Promise.resolve(new LinkInstance(container, this._engine));
|
|
12
9
|
}
|
|
13
10
|
loadOptions() {
|
|
14
11
|
}
|
|
@@ -16,4 +13,3 @@ class LinksPlugin {
|
|
|
16
13
|
return true;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.LinksPlugin = LinksPlugin;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const LinksShadow_js_1 = require("./LinksShadow.js");
|
|
6
|
-
const LinksTriangle_js_1 = require("./LinksTriangle.js");
|
|
7
|
-
class Links {
|
|
1
|
+
import { OptionsColor, isNull } from "@tsparticles/engine";
|
|
2
|
+
import { LinksShadow } from "./LinksShadow.js";
|
|
3
|
+
import { LinksTriangle } from "./LinksTriangle.js";
|
|
4
|
+
export class Links {
|
|
8
5
|
constructor() {
|
|
9
6
|
this.blink = false;
|
|
10
|
-
this.color = new
|
|
7
|
+
this.color = new OptionsColor();
|
|
11
8
|
this.color.value = "#fff";
|
|
12
9
|
this.consent = false;
|
|
13
10
|
this.distance = 100;
|
|
14
11
|
this.enable = false;
|
|
15
12
|
this.frequency = 1;
|
|
16
13
|
this.opacity = 1;
|
|
17
|
-
this.shadow = new
|
|
18
|
-
this.triangles = new
|
|
14
|
+
this.shadow = new LinksShadow();
|
|
15
|
+
this.triangles = new LinksTriangle();
|
|
19
16
|
this.width = 1;
|
|
20
17
|
this.warp = false;
|
|
21
18
|
}
|
|
22
19
|
load(data) {
|
|
23
|
-
if (
|
|
20
|
+
if (isNull(data)) {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
26
23
|
if (data.id !== undefined) {
|
|
@@ -29,7 +26,7 @@ class Links {
|
|
|
29
26
|
if (data.blink !== undefined) {
|
|
30
27
|
this.blink = data.blink;
|
|
31
28
|
}
|
|
32
|
-
this.color =
|
|
29
|
+
this.color = OptionsColor.create(this.color, data.color);
|
|
33
30
|
if (data.consent !== undefined) {
|
|
34
31
|
this.consent = data.consent;
|
|
35
32
|
}
|
|
@@ -55,4 +52,3 @@ class Links {
|
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
|
-
exports.Links = Links;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.LinksShadow = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class LinksShadow {
|
|
1
|
+
import { OptionsColor, isNull } from "@tsparticles/engine";
|
|
2
|
+
export class LinksShadow {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.blur = 5;
|
|
8
|
-
this.color = new
|
|
5
|
+
this.color = new OptionsColor();
|
|
9
6
|
this.color.value = "#000";
|
|
10
7
|
this.enable = false;
|
|
11
8
|
}
|
|
12
9
|
load(data) {
|
|
13
|
-
if (
|
|
10
|
+
if (isNull(data)) {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
13
|
if (data.blur !== undefined) {
|
|
17
14
|
this.blur = data.blur;
|
|
18
15
|
}
|
|
19
|
-
this.color =
|
|
16
|
+
this.color = OptionsColor.create(this.color, data.color);
|
|
20
17
|
if (data.enable !== undefined) {
|
|
21
18
|
this.enable = data.enable;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.LinksShadow = LinksShadow;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.LinksTriangle = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class LinksTriangle {
|
|
1
|
+
import { OptionsColor, isNull } from "@tsparticles/engine";
|
|
2
|
+
export class LinksTriangle {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.enable = false;
|
|
8
5
|
this.frequency = 1;
|
|
9
6
|
}
|
|
10
7
|
load(data) {
|
|
11
|
-
if (
|
|
8
|
+
if (isNull(data)) {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
11
|
if (data.color !== undefined) {
|
|
15
|
-
this.color =
|
|
12
|
+
this.color = OptionsColor.create(this.color, data.color);
|
|
16
13
|
}
|
|
17
14
|
if (data.enable !== undefined) {
|
|
18
15
|
this.enable = data.enable;
|
|
@@ -25,4 +22,3 @@ class LinksTriangle {
|
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.LinksTriangle = LinksTriangle;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|