@tsparticles/interaction-particles-links 3.0.3 → 3.2.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/356.min.js +2 -0
- package/356.min.js.LICENSE.txt +1 -0
- package/806.min.js +2 -0
- package/806.min.js.LICENSE.txt +1 -0
- package/838.min.js +2 -0
- package/838.min.js.LICENSE.txt +1 -0
- package/browser/CircleWarp.js +3 -2
- package/browser/LinkInstance.js +12 -9
- package/browser/Linker.js +18 -8
- package/browser/interaction.js +4 -2
- package/browser/plugin.js +2 -2
- package/cjs/CircleWarp.js +3 -2
- package/cjs/LinkInstance.js +12 -9
- package/cjs/Linker.js +41 -8
- package/cjs/interaction.js +27 -2
- package/cjs/plugin.js +26 -3
- package/dist_browser_CircleWarp_js.js +30 -0
- package/dist_browser_LinkInstance_js.js +40 -0
- package/dist_browser_Linker_js.js +30 -0
- package/esm/CircleWarp.js +3 -2
- package/esm/LinkInstance.js +12 -9
- package/esm/Linker.js +18 -8
- package/esm/interaction.js +4 -2
- package/esm/plugin.js +2 -2
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.interaction.particles.links.js +291 -620
- 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/Types.d.ts +4 -4
- package/umd/CircleWarp.js +3 -2
- package/umd/LinkInstance.js +12 -9
- package/umd/Linker.js +43 -9
- package/umd/interaction.js +29 -3
- package/umd/plugin.js +28 -4
package/356.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 356.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[356],{356:(s,i,t)=>{t.d(i,{CircleWarp:()=>n});var e=t(533);class n extends e.Circle{constructor(s,i,t,e){super(s,i,t),this.canvasSize=e,this.canvasSize={...e}}contains(s){const{width:i,height:t}=this.canvasSize,{x:e,y:n}=s;return super.contains(s)||super.contains({x:e-i,y:n})||super.contains({x:e-i,y:n-t})||super.contains({x:e,y:n-t})}intersects(s){if(super.intersects(s))return!0;const i=s,t=s,n={x:s.position.x-this.canvasSize.width,y:s.position.y-this.canvasSize.height};if(void 0!==t.radius){const s=new e.Circle(n.x,n.y,2*t.radius);return super.intersects(s)}if(void 0!==i.size){const s=new e.Rectangle(n.x,n.y,2*i.size.width,2*i.size.height);return super.intersects(s)}return!1}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v3.2.0 by Matteo Bruni */
|
package/806.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 806.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[806],{806:(i,n,t)=>{t.d(n,{Linker:()=>a});var s=t(533),e=t(515);const o=0,r=0;function l(i,n,t,e,o){const{dx:r,dy:l,distance:a}=(0,s.getDistances)(i,n);if(!o||a<=t)return a;const c={x:Math.abs(r),y:Math.abs(l)},k=Math.min(c.x,e.width-c.x),p=Math.min(c.y,e.height-c.y);return Math.sqrt(k**2+p**2)}class a extends s.ParticlesInteractorBase{constructor(i){super(i),this._setColor=i=>{if(!i.options.links)return;const n=this.linkContainer,t=i.options.links;let e=void 0===t.id?n.particles.linksColor:n.particles.linksColors.get(t.id);if(e)return;const o=t.color;e=(0,s.getLinkRandomColor)(o,t.blink,t.consent),void 0===t.id?n.particles.linksColor=e:n.particles.linksColors.set(t.id,e)},this.linkContainer=i}clear(){}init(){this.linkContainer.particles.linksColor=void 0,this.linkContainer.particles.linksColors=new Map}async interact(i){if(!i.options.links)return;i.links=[];const n=i.getPosition(),e=this.container,a=e.canvas.size;if(n.x<o||n.y<r||n.x>a.width||n.y>a.height)return;const c=i.options.links,k=c.opacity,p=i.retina.linksDistance??0,d=c.warp;let h;if(d){const{CircleWarp:i}=await t.e(356).then(t.bind(t,356));h=new i(n.x,n.y,p,a)}else h=new s.Circle(n.x,n.y,p);const u=e.particles.quadTree.query(h);for(const t of u){const s=t.options.links;if(i===t||!s?.enable||c.id!==s.id||t.spawning||t.destroyed||!t.links||i.links.some((i=>i.destination===t))||t.links.some((n=>n.destination===i)))continue;const e=t.getPosition();if(e.x<o||e.y<r||e.x>a.width||e.y>a.height)continue;const h=l(n,e,p,a,d&&s.warp);if(h>p)continue;const u=(1-h/p)*k;this._setColor(i),i.links.push({destination:t,opacity:u})}}isEnabled(i){return!!i.options.links?.enable}loadParticlesOptions(i,...n){i.links||(i.links=new e.y);for(const t of n)i.links.load(t?.links)}reset(){}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v3.2.0 by Matteo Bruni */
|
package/838.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 838.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).push([[838],{838:(i,n,t)=>{t.d(n,{LinkInstance:()=>o});var e=t(533);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){this.container=i,this._drawLinkLine=(i,n)=>{const t=i.options.links;if(!t?.enable)return;const s=this.container,o=s.actualOptions,a=n.destination,r=i.getPosition(),l=a.getPosition();let c=n.opacity;s.canvas.draw((n=>{let d;const g=i.options.twinkle?.lines;if(g?.enable){const i=g.frequency,n=(0,e.rangeColorToRgb)(g.color);(0,e.getRandom)()<i&&n&&(d=n,c=(0,e.getRangeValue)(g.opacity))}if(!d){const n=void 0!==t.id?s.particles.linksColors.get(t.id):s.particles.linksColor;d=(0,e.getLinkColor)(i,a,n)}if(!d)return;const k=i.retina.linksWidth??0,p=i.retina.linksDistance??0,{backgroundMask:h}=o;!function(i){let n=!1;const{begin:t,end:s,maxDistance:o,context:a,canvasSize:r,width:l,backgroundMask:c,colorLine:d,opacity:g,links:k}=i;if((0,e.getDistance)(t,s)<=o)(0,e.drawLine)(a,t,s),n=!0;else if(k.warp){let i,l;const c={x:s.x-r.width,y:s.y},d=(0,e.getDistances)(t,c);if(d.distance<=o){const n=t.y-d.dy/d.dx*t.x;i={x:0,y:n},l={x:r.width,y:n}}else{const n={x:s.x,y:s.y-r.height},a=(0,e.getDistances)(t,n);if(a.distance<=o){const n=-(t.y-a.dy/a.dx*t.x)/(a.dy/a.dx);i={x:n,y:0},l={x:n,y:r.height}}else{const n={x:s.x-r.width,y:s.y-r.height},a=(0,e.getDistances)(t,n);if(a.distance<=o){const n=t.y-a.dy/a.dx*t.x;i={x:-n/(a.dy/a.dx),y:n},l={x:i.x+r.width,y:i.y+r.height}}}}i&&l&&((0,e.drawLine)(a,t,i),(0,e.drawLine)(a,s,l),n=!0)}if(!n)return;a.lineWidth=l,c.enable&&(a.globalCompositeOperation=c.composite),a.strokeStyle=(0,e.getStyleFromRgb)(d,g);const{shadow:p}=k;if(p.enable){const i=(0,e.rangeColorToRgb)(p.color);i&&(a.shadowBlur=p.blur,a.shadowColor=(0,e.getStyleFromRgb)(i))}a.stroke()}({context:n,width:k,begin:r,end:l,maxDistance:p,canvasSize:s.canvas.size,links:t,backgroundMask:h,colorLine:d,opacity:c})}))},this._drawLinkTriangle=(i,n,t)=>{const s=i.options.links;if(!s?.enable)return;const o=s.triangles;if(!o.enable)return;const a=this.container,r=a.actualOptions,l=n.destination,c=t.destination,d=o.opacity??.5*(n.opacity+t.opacity);d<=0||a.canvas.draw((n=>{const t=i.getPosition(),g=l.getPosition(),k=c.getPosition(),p=i.retina.linksDistance??0;if((0,e.getDistance)(t,g)>p||(0,e.getDistance)(k,g)>p||(0,e.getDistance)(k,t)>p)return;let h=(0,e.rangeColorToRgb)(o.color);if(!h){const n=void 0!==s.id?a.particles.linksColors.get(s.id):a.particles.linksColor;h=(0,e.getLinkColor)(i,l,n)}h&&function(i){const{context:n,pos1:t,pos2:s,pos3:o,backgroundMask:a,colorTriangle:r,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,t,s,o),a.enable&&(n.globalCompositeOperation=a.composite),n.fillStyle=(0,e.getStyleFromRgb)(r,l),n.fill()}({context:n,pos1:t,pos2:g,pos3:k,backgroundMask:r.backgroundMask,colorTriangle:h,opacityTriangle:d})}))},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._freqs={links:new Map,triangles:new Map}}async drawParticle(i,n){const{links:t,options:e}=n;if(!t?.length)return;const s=t.filter((i=>e.links&&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);await Promise.resolve()}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=[]}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Links Particles Interaction v3.2.0 by Matteo Bruni */
|
package/browser/CircleWarp.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
2
|
+
const double = 2;
|
|
2
3
|
export class CircleWarp extends Circle {
|
|
3
4
|
constructor(x, y, radius, canvasSize) {
|
|
4
5
|
super(x, y, radius);
|
|
@@ -22,11 +23,11 @@ export class CircleWarp extends Circle {
|
|
|
22
23
|
y: range.position.y - this.canvasSize.height,
|
|
23
24
|
};
|
|
24
25
|
if (circle.radius !== undefined) {
|
|
25
|
-
const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius *
|
|
26
|
+
const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * double);
|
|
26
27
|
return super.intersects(biggerCircle);
|
|
27
28
|
}
|
|
28
29
|
else if (rect.size !== undefined) {
|
|
29
|
-
const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width *
|
|
30
|
+
const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * double, rect.size.height * double);
|
|
30
31
|
return super.intersects(rectSW);
|
|
31
32
|
}
|
|
32
33
|
return false;
|
package/browser/LinkInstance.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getDistance, getLinkColor, getRandom, getRangeValue, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
2
|
import { drawLinkLine, drawLinkTriangle, setLinkFrequency } from "./Utils.js";
|
|
3
|
+
const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5;
|
|
3
4
|
export class LinkInstance {
|
|
4
5
|
constructor(container) {
|
|
5
6
|
this.container = container;
|
|
@@ -29,7 +30,7 @@ export class LinkInstance {
|
|
|
29
30
|
if (!colorLine) {
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
const width = p1.retina.linksWidth ??
|
|
33
|
+
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance, { backgroundMask } = options;
|
|
33
34
|
drawLinkLine({
|
|
34
35
|
context: ctx,
|
|
35
36
|
width,
|
|
@@ -53,12 +54,12 @@ export class LinkInstance {
|
|
|
53
54
|
if (!triangleOptions.enable) {
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
|
-
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity)
|
|
57
|
-
if (opacityTriangle <=
|
|
57
|
+
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
|
|
58
|
+
if (opacityTriangle <= minOpacity) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
container.canvas.draw((ctx) => {
|
|
61
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ??
|
|
62
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? minDistance;
|
|
62
63
|
if (getDistance(pos1, pos2) > linksDistance ||
|
|
63
64
|
getDistance(pos3, pos2) > linksDistance ||
|
|
64
65
|
getDistance(pos3, pos1) > linksDistance) {
|
|
@@ -91,10 +92,10 @@ export class LinkInstance {
|
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
94
|
const vertices = p2.links?.filter((t) => {
|
|
94
|
-
const linkFreq = this._getLinkFrequency(p2, t.destination);
|
|
95
|
+
const linkFreq = this._getLinkFrequency(p2, t.destination), minCount = 0;
|
|
95
96
|
return (p2.options.links &&
|
|
96
97
|
linkFreq <= p2.options.links.frequency &&
|
|
97
|
-
p1Links.findIndex((l) => l.destination === t.destination) >=
|
|
98
|
+
p1Links.findIndex((l) => l.destination === t.destination) >= minCount);
|
|
98
99
|
});
|
|
99
100
|
if (!vertices?.length) {
|
|
100
101
|
return;
|
|
@@ -118,22 +119,24 @@ export class LinkInstance {
|
|
|
118
119
|
triangles: new Map(),
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
drawParticle(context, particle) {
|
|
122
|
+
async drawParticle(context, particle) {
|
|
122
123
|
const { links, options } = particle;
|
|
123
|
-
if (!links
|
|
124
|
+
if (!links?.length) {
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
126
127
|
const p1Links = links.filter((l) => options.links && this._getLinkFrequency(particle, l.destination) <= options.links.frequency);
|
|
127
128
|
for (const link of p1Links) {
|
|
128
129
|
this._drawTriangles(options, particle, link, p1Links);
|
|
129
|
-
if (link.opacity >
|
|
130
|
+
if (link.opacity > minOpacity && (particle.retina.linksWidth ?? minWidth) > minWidth) {
|
|
130
131
|
this._drawLinkLine(particle, link);
|
|
131
132
|
}
|
|
132
133
|
}
|
|
134
|
+
await Promise.resolve();
|
|
133
135
|
}
|
|
134
136
|
async init() {
|
|
135
137
|
this._freqs.links = new Map();
|
|
136
138
|
this._freqs.triangles = new Map();
|
|
139
|
+
await Promise.resolve();
|
|
137
140
|
}
|
|
138
141
|
particleCreated(particle) {
|
|
139
142
|
particle.links = [];
|
package/browser/Linker.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Circle, ParticlesInteractorBase, getDistances, getLinkRandomColor, } from "@tsparticles/engine";
|
|
2
|
-
import { CircleWarp } from "./CircleWarp.js";
|
|
3
2
|
import { Links } from "./Options/Classes/Links.js";
|
|
3
|
+
const squarePower = 2, opacityOffset = 1, origin = {
|
|
4
|
+
x: 0,
|
|
5
|
+
y: 0,
|
|
6
|
+
}, minDistance = 0;
|
|
4
7
|
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
5
8
|
const { dx, dy, distance } = getDistances(pos1, pos2);
|
|
6
9
|
if (!warp || distance <= optDistance) {
|
|
@@ -13,7 +16,7 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
|
13
16
|
x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),
|
|
14
17
|
y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y),
|
|
15
18
|
};
|
|
16
|
-
return Math.sqrt(warpDistances.x **
|
|
19
|
+
return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
|
|
17
20
|
}
|
|
18
21
|
export class Linker extends ParticlesInteractorBase {
|
|
19
22
|
constructor(container) {
|
|
@@ -52,12 +55,19 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
52
55
|
}
|
|
53
56
|
p1.links = [];
|
|
54
57
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
55
|
-
if (pos1.x <
|
|
58
|
+
if (pos1.x < origin.x || pos1.y < origin.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
|
-
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ??
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp;
|
|
62
|
+
let range;
|
|
63
|
+
if (warp) {
|
|
64
|
+
const { CircleWarp } = await import("./CircleWarp.js");
|
|
65
|
+
range = new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
range = new Circle(pos1.x, pos1.y, optDistance);
|
|
69
|
+
}
|
|
70
|
+
const query = container.particles.quadTree.query(range);
|
|
61
71
|
for (const p2 of query) {
|
|
62
72
|
const linkOpt2 = p2.options.links;
|
|
63
73
|
if (p1 === p2 ||
|
|
@@ -71,14 +81,14 @@ export class Linker extends ParticlesInteractorBase {
|
|
|
71
81
|
continue;
|
|
72
82
|
}
|
|
73
83
|
const pos2 = p2.getPosition();
|
|
74
|
-
if (pos2.x <
|
|
84
|
+
if (pos2.x < origin.x || pos2.y < origin.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
|
75
85
|
continue;
|
|
76
86
|
}
|
|
77
87
|
const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
|
78
88
|
if (distance > optDistance) {
|
|
79
89
|
continue;
|
|
80
90
|
}
|
|
81
|
-
const opacityLine = (
|
|
91
|
+
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
82
92
|
this._setColor(p1);
|
|
83
93
|
p1.links.push({
|
|
84
94
|
destination: p2,
|
package/browser/interaction.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Linker } from "./Linker.js";
|
|
2
1
|
export async function loadLinksInteraction(engine, refresh = true) {
|
|
3
|
-
await engine.addInteractor("particlesLinks", (container) =>
|
|
2
|
+
await engine.addInteractor("particlesLinks", async (container) => {
|
|
3
|
+
const { Linker } = await import("./Linker.js");
|
|
4
|
+
return new Linker(container);
|
|
5
|
+
}, refresh);
|
|
4
6
|
}
|
package/browser/plugin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { LinkInstance } from "./LinkInstance.js";
|
|
2
1
|
class LinksPlugin {
|
|
3
2
|
constructor() {
|
|
4
3
|
this.id = "links";
|
|
5
4
|
}
|
|
6
|
-
getPlugin(container) {
|
|
5
|
+
async getPlugin(container) {
|
|
6
|
+
const { LinkInstance } = await import("./LinkInstance.js");
|
|
7
7
|
return new LinkInstance(container);
|
|
8
8
|
}
|
|
9
9
|
loadOptions() {
|
package/cjs/CircleWarp.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CircleWarp = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const double = 2;
|
|
5
6
|
class CircleWarp extends engine_1.Circle {
|
|
6
7
|
constructor(x, y, radius, canvasSize) {
|
|
7
8
|
super(x, y, radius);
|
|
@@ -25,11 +26,11 @@ class CircleWarp extends engine_1.Circle {
|
|
|
25
26
|
y: range.position.y - this.canvasSize.height,
|
|
26
27
|
};
|
|
27
28
|
if (circle.radius !== undefined) {
|
|
28
|
-
const biggerCircle = new engine_1.Circle(newPos.x, newPos.y, circle.radius *
|
|
29
|
+
const biggerCircle = new engine_1.Circle(newPos.x, newPos.y, circle.radius * double);
|
|
29
30
|
return super.intersects(biggerCircle);
|
|
30
31
|
}
|
|
31
32
|
else if (rect.size !== undefined) {
|
|
32
|
-
const rectSW = new engine_1.Rectangle(newPos.x, newPos.y, rect.size.width *
|
|
33
|
+
const rectSW = new engine_1.Rectangle(newPos.x, newPos.y, rect.size.width * double, rect.size.height * double);
|
|
33
34
|
return super.intersects(rectSW);
|
|
34
35
|
}
|
|
35
36
|
return false;
|
package/cjs/LinkInstance.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LinkInstance = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const Utils_js_1 = require("./Utils.js");
|
|
6
|
+
const minOpacity = 0, minWidth = 0, minDistance = 0, half = 0.5;
|
|
6
7
|
class LinkInstance {
|
|
7
8
|
constructor(container) {
|
|
8
9
|
this.container = container;
|
|
@@ -32,7 +33,7 @@ class LinkInstance {
|
|
|
32
33
|
if (!colorLine) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
const width = p1.retina.linksWidth ??
|
|
36
|
+
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance, { backgroundMask } = options;
|
|
36
37
|
(0, Utils_js_1.drawLinkLine)({
|
|
37
38
|
context: ctx,
|
|
38
39
|
width,
|
|
@@ -56,12 +57,12 @@ class LinkInstance {
|
|
|
56
57
|
if (!triangleOptions.enable) {
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
|
-
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity)
|
|
60
|
-
if (opacityTriangle <=
|
|
60
|
+
const container = this.container, options = container.actualOptions, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;
|
|
61
|
+
if (opacityTriangle <= minOpacity) {
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
container.canvas.draw((ctx) => {
|
|
64
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ??
|
|
65
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? minDistance;
|
|
65
66
|
if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
|
|
66
67
|
(0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
|
|
67
68
|
(0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
|
|
@@ -94,10 +95,10 @@ class LinkInstance {
|
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
96
97
|
const vertices = p2.links?.filter((t) => {
|
|
97
|
-
const linkFreq = this._getLinkFrequency(p2, t.destination);
|
|
98
|
+
const linkFreq = this._getLinkFrequency(p2, t.destination), minCount = 0;
|
|
98
99
|
return (p2.options.links &&
|
|
99
100
|
linkFreq <= p2.options.links.frequency &&
|
|
100
|
-
p1Links.findIndex((l) => l.destination === t.destination) >=
|
|
101
|
+
p1Links.findIndex((l) => l.destination === t.destination) >= minCount);
|
|
101
102
|
});
|
|
102
103
|
if (!vertices?.length) {
|
|
103
104
|
return;
|
|
@@ -121,22 +122,24 @@ class LinkInstance {
|
|
|
121
122
|
triangles: new Map(),
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
|
-
drawParticle(context, particle) {
|
|
125
|
+
async drawParticle(context, particle) {
|
|
125
126
|
const { links, options } = particle;
|
|
126
|
-
if (!links
|
|
127
|
+
if (!links?.length) {
|
|
127
128
|
return;
|
|
128
129
|
}
|
|
129
130
|
const p1Links = links.filter((l) => options.links && this._getLinkFrequency(particle, l.destination) <= options.links.frequency);
|
|
130
131
|
for (const link of p1Links) {
|
|
131
132
|
this._drawTriangles(options, particle, link, p1Links);
|
|
132
|
-
if (link.opacity >
|
|
133
|
+
if (link.opacity > minOpacity && (particle.retina.linksWidth ?? minWidth) > minWidth) {
|
|
133
134
|
this._drawLinkLine(particle, link);
|
|
134
135
|
}
|
|
135
136
|
}
|
|
137
|
+
await Promise.resolve();
|
|
136
138
|
}
|
|
137
139
|
async init() {
|
|
138
140
|
this._freqs.links = new Map();
|
|
139
141
|
this._freqs.triangles = new Map();
|
|
142
|
+
await Promise.resolve();
|
|
140
143
|
}
|
|
141
144
|
particleCreated(particle) {
|
|
142
145
|
particle.links = [];
|
package/cjs/Linker.js
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Linker = void 0;
|
|
4
27
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const CircleWarp_js_1 = require("./CircleWarp.js");
|
|
6
28
|
const Links_js_1 = require("./Options/Classes/Links.js");
|
|
29
|
+
const squarePower = 2, opacityOffset = 1, origin = {
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0,
|
|
32
|
+
}, minDistance = 0;
|
|
7
33
|
function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
8
34
|
const { dx, dy, distance } = (0, engine_1.getDistances)(pos1, pos2);
|
|
9
35
|
if (!warp || distance <= optDistance) {
|
|
@@ -16,7 +42,7 @@ function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
|
|
16
42
|
x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),
|
|
17
43
|
y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y),
|
|
18
44
|
};
|
|
19
|
-
return Math.sqrt(warpDistances.x **
|
|
45
|
+
return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);
|
|
20
46
|
}
|
|
21
47
|
class Linker extends engine_1.ParticlesInteractorBase {
|
|
22
48
|
constructor(container) {
|
|
@@ -55,12 +81,19 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
55
81
|
}
|
|
56
82
|
p1.links = [];
|
|
57
83
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
58
|
-
if (pos1.x <
|
|
84
|
+
if (pos1.x < origin.x || pos1.y < origin.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
59
85
|
return;
|
|
60
86
|
}
|
|
61
|
-
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ??
|
|
62
|
-
|
|
63
|
-
|
|
87
|
+
const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp;
|
|
88
|
+
let range;
|
|
89
|
+
if (warp) {
|
|
90
|
+
const { CircleWarp } = await Promise.resolve().then(() => __importStar(require("./CircleWarp.js")));
|
|
91
|
+
range = new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
range = new engine_1.Circle(pos1.x, pos1.y, optDistance);
|
|
95
|
+
}
|
|
96
|
+
const query = container.particles.quadTree.query(range);
|
|
64
97
|
for (const p2 of query) {
|
|
65
98
|
const linkOpt2 = p2.options.links;
|
|
66
99
|
if (p1 === p2 ||
|
|
@@ -74,14 +107,14 @@ class Linker extends engine_1.ParticlesInteractorBase {
|
|
|
74
107
|
continue;
|
|
75
108
|
}
|
|
76
109
|
const pos2 = p2.getPosition();
|
|
77
|
-
if (pos2.x <
|
|
110
|
+
if (pos2.x < origin.x || pos2.y < origin.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
|
78
111
|
continue;
|
|
79
112
|
}
|
|
80
113
|
const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
|
81
114
|
if (distance > optDistance) {
|
|
82
115
|
continue;
|
|
83
116
|
}
|
|
84
|
-
const opacityLine = (
|
|
117
|
+
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
85
118
|
this._setColor(p1);
|
|
86
119
|
p1.links.push({
|
|
87
120
|
destination: p2,
|
package/cjs/interaction.js
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.loadLinksInteraction = void 0;
|
|
4
|
-
const Linker_js_1 = require("./Linker.js");
|
|
5
27
|
async function loadLinksInteraction(engine, refresh = true) {
|
|
6
|
-
await engine.addInteractor("particlesLinks", (container) =>
|
|
28
|
+
await engine.addInteractor("particlesLinks", async (container) => {
|
|
29
|
+
const { Linker } = await Promise.resolve().then(() => __importStar(require("./Linker.js")));
|
|
30
|
+
return new Linker(container);
|
|
31
|
+
}, refresh);
|
|
7
32
|
}
|
|
8
33
|
exports.loadLinksInteraction = loadLinksInteraction;
|
package/cjs/plugin.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.loadLinksPlugin = void 0;
|
|
4
|
-
const LinkInstance_js_1 = require("./LinkInstance.js");
|
|
5
27
|
class LinksPlugin {
|
|
6
28
|
constructor() {
|
|
7
29
|
this.id = "links";
|
|
8
30
|
}
|
|
9
|
-
getPlugin(container) {
|
|
10
|
-
|
|
31
|
+
async getPlugin(container) {
|
|
32
|
+
const { LinkInstance } = await Promise.resolve().then(() => __importStar(require("./LinkInstance.js")));
|
|
33
|
+
return new LinkInstance(container);
|
|
11
34
|
}
|
|
12
35
|
loadOptions() {
|
|
13
36
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v3.2.0
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_interaction_particles_links"] = this["webpackChunk_tsparticles_interaction_particles_links"] || []).push([["dist_browser_CircleWarp_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/CircleWarp.js":
|
|
21
|
+
/*!************************************!*\
|
|
22
|
+
!*** ./dist/browser/CircleWarp.js ***!
|
|
23
|
+
\************************************/
|
|
24
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
25
|
+
|
|
26
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ CircleWarp: () => (/* binding */ CircleWarp)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst double = 2;\nclass CircleWarp extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle {\n constructor(x, y, radius, canvasSize) {\n super(x, y, radius);\n this.canvasSize = canvasSize;\n this.canvasSize = {\n ...canvasSize\n };\n }\n contains(point) {\n const {\n width,\n height\n } = this.canvasSize;\n const {\n x,\n y\n } = point;\n return super.contains(point) || super.contains({\n x: x - width,\n y\n }) || super.contains({\n x: x - width,\n y: y - height\n }) || super.contains({\n x,\n y: y - height\n });\n }\n intersects(range) {\n if (super.intersects(range)) {\n return true;\n }\n const rect = range,\n circle = range,\n newPos = {\n x: range.position.x - this.canvasSize.width,\n y: range.position.y - this.canvasSize.height\n };\n if (circle.radius !== undefined) {\n const biggerCircle = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(newPos.x, newPos.y, circle.radius * double);\n return super.intersects(biggerCircle);\n } else if (rect.size !== undefined) {\n const rectSW = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle(newPos.x, newPos.y, rect.size.width * double, rect.size.height * double);\n return super.intersects(rectSW);\n }\n return false;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/CircleWarp.js?");
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
}]);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v3.2.0
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_interaction_particles_links"] = this["webpackChunk_tsparticles_interaction_particles_links"] || []).push([["dist_browser_LinkInstance_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/LinkInstance.js":
|
|
21
|
+
/*!**************************************!*\
|
|
22
|
+
!*** ./dist/browser/LinkInstance.js ***!
|
|
23
|
+
\**************************************/
|
|
24
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
25
|
+
|
|
26
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ LinkInstance: () => (/* binding */ LinkInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\nconst minOpacity = 0,\n minWidth = 0,\n minDistance = 0,\n half = 0.5;\nclass LinkInstance {\n constructor(container) {\n this.container = container;\n this._drawLinkLine = (p1, link) => {\n const p1LinksOptions = p1.options.links;\n if (!p1LinksOptions?.enable) {\n return;\n }\n const container = this.container,\n options = container.actualOptions,\n p2 = link.destination,\n pos1 = p1.getPosition(),\n pos2 = p2.getPosition();\n let opacity = link.opacity;\n container.canvas.draw(ctx => {\n let colorLine;\n const twinkle = p1.options.twinkle?.lines;\n if (twinkle?.enable) {\n const twinkleFreq = twinkle.frequency,\n twinkleRgb = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(twinkle.color),\n twinkling = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() < twinkleFreq;\n if (twinkling && twinkleRgb) {\n colorLine = twinkleRgb;\n opacity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(twinkle.opacity);\n }\n }\n if (!colorLine) {\n const linkColor = p1LinksOptions.id !== undefined ? container.particles.linksColors.get(p1LinksOptions.id) : container.particles.linksColor;\n colorLine = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLinkColor)(p1, p2, linkColor);\n }\n if (!colorLine) {\n return;\n }\n const width = p1.retina.linksWidth ?? minWidth,\n maxDistance = p1.retina.linksDistance ?? minDistance,\n {\n backgroundMask\n } = options;\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawLinkLine)({\n context: ctx,\n width,\n begin: pos1,\n end: pos2,\n maxDistance,\n canvasSize: container.canvas.size,\n links: p1LinksOptions,\n backgroundMask: backgroundMask,\n colorLine,\n opacity\n });\n });\n };\n this._drawLinkTriangle = (p1, link1, link2) => {\n const linksOptions = p1.options.links;\n if (!linksOptions?.enable) {\n return;\n }\n const triangleOptions = linksOptions.triangles;\n if (!triangleOptions.enable) {\n return;\n }\n const container = this.container,\n options = container.actualOptions,\n p2 = link1.destination,\n p3 = link2.destination,\n opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * half;\n if (opacityTriangle <= minOpacity) {\n return;\n }\n container.canvas.draw(ctx => {\n const pos1 = p1.getPosition(),\n pos2 = p2.getPosition(),\n pos3 = p3.getPosition(),\n linksDistance = p1.retina.linksDistance ?? minDistance;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(pos1, pos2) > linksDistance || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(pos3, pos2) > linksDistance || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(pos3, pos1) > linksDistance) {\n return;\n }\n let colorTriangle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(triangleOptions.color);\n if (!colorTriangle) {\n const linkColor = linksOptions.id !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;\n colorTriangle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLinkColor)(p1, p2, linkColor);\n }\n if (!colorTriangle) {\n return;\n }\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawLinkTriangle)({\n context: ctx,\n pos1,\n pos2,\n pos3,\n backgroundMask: options.backgroundMask,\n colorTriangle,\n opacityTriangle\n });\n });\n };\n this._drawTriangles = (options, p1, link, p1Links) => {\n const p2 = link.destination;\n if (!(options.links?.triangles.enable && p2.options.links?.triangles.enable)) {\n return;\n }\n const vertices = p2.links?.filter(t => {\n const linkFreq = this._getLinkFrequency(p2, t.destination),\n minCount = 0;\n return p2.options.links && linkFreq <= p2.options.links.frequency && p1Links.findIndex(l => l.destination === t.destination) >= minCount;\n });\n if (!vertices?.length) {\n return;\n }\n for (const vertex of vertices) {\n const p3 = vertex.destination,\n triangleFreq = this._getTriangleFrequency(p1, p2, p3);\n if (triangleFreq > options.links.triangles.frequency) {\n continue;\n }\n this._drawLinkTriangle(p1, link, vertex);\n }\n };\n this._getLinkFrequency = (p1, p2) => {\n return (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.setLinkFrequency)([p1, p2], this._freqs.links);\n };\n this._getTriangleFrequency = (p1, p2, p3) => {\n return (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);\n };\n this._freqs = {\n links: new Map(),\n triangles: new Map()\n };\n }\n async drawParticle(context, particle) {\n const {\n links,\n options\n } = particle;\n if (!links?.length) {\n return;\n }\n const p1Links = links.filter(l => options.links && this._getLinkFrequency(particle, l.destination) <= options.links.frequency);\n for (const link of p1Links) {\n this._drawTriangles(options, particle, link, p1Links);\n if (link.opacity > minOpacity && (particle.retina.linksWidth ?? minWidth) > minWidth) {\n this._drawLinkLine(particle, link);\n }\n }\n await Promise.resolve();\n }\n async init() {\n this._freqs.links = new Map();\n this._freqs.triangles = new Map();\n await Promise.resolve();\n }\n particleCreated(particle) {\n particle.links = [];\n if (!particle.options.links) {\n return;\n }\n const ratio = this.container.retina.pixelRatio,\n {\n retina\n } = particle,\n {\n distance,\n width\n } = particle.options.links;\n retina.linksDistance = distance * ratio;\n retina.linksWidth = width * ratio;\n }\n particleDestroyed(particle) {\n particle.links = [];\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/LinkInstance.js?");
|
|
27
|
+
|
|
28
|
+
/***/ }),
|
|
29
|
+
|
|
30
|
+
/***/ "./dist/browser/Utils.js":
|
|
31
|
+
/*!*******************************!*\
|
|
32
|
+
!*** ./dist/browser/Utils.js ***!
|
|
33
|
+
\*******************************/
|
|
34
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
35
|
+
|
|
36
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawLinkLine: () => (/* binding */ drawLinkLine),\n/* harmony export */ drawLinkTriangle: () => (/* binding */ drawLinkTriangle),\n/* harmony export */ drawTriangle: () => (/* binding */ drawTriangle),\n/* harmony export */ getLinkKey: () => (/* binding */ getLinkKey),\n/* harmony export */ setLinkFrequency: () => (/* binding */ setLinkFrequency)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nfunction drawTriangle(context, p1, p2, p3) {\n context.beginPath();\n context.moveTo(p1.x, p1.y);\n context.lineTo(p2.x, p2.y);\n context.lineTo(p3.x, p3.y);\n context.closePath();\n}\nfunction drawLinkLine(params) {\n let drawn = false;\n const {\n begin,\n end,\n maxDistance,\n context,\n canvasSize,\n width,\n backgroundMask,\n colorLine,\n opacity,\n links\n } = params;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistance)(begin, end) <= maxDistance) {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.drawLine)(context, begin, end);\n drawn = true;\n } else if (links.warp) {\n let pi1;\n let pi2;\n const endNE = {\n x: end.x - canvasSize.width,\n y: end.y\n };\n const d1 = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(begin, endNE);\n if (d1.distance <= maxDistance) {\n const yi = begin.y - d1.dy / d1.dx * begin.x;\n pi1 = {\n x: 0,\n y: yi\n };\n pi2 = {\n x: canvasSize.width,\n y: yi\n };\n } else {\n const endSW = {\n x: end.x,\n y: end.y - canvasSize.height\n };\n const d2 = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(begin, endSW);\n if (d2.distance <= maxDistance) {\n const yi = begin.y - d2.dy / d2.dx * begin.x;\n const xi = -yi / (d2.dy / d2.dx);\n pi1 = {\n x: xi,\n y: 0\n };\n pi2 = {\n x: xi,\n y: canvasSize.height\n };\n } else {\n const endSE = {\n x: end.x - canvasSize.width,\n y: end.y - canvasSize.height\n };\n const d3 = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(begin, endSE);\n if (d3.distance <= maxDistance) {\n const yi = begin.y - d3.dy / d3.dx * begin.x;\n const xi = -yi / (d3.dy / d3.dx);\n pi1 = {\n x: xi,\n y: yi\n };\n pi2 = {\n x: pi1.x + canvasSize.width,\n y: pi1.y + canvasSize.height\n };\n }\n }\n }\n if (pi1 && pi2) {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.drawLine)(context, begin, pi1);\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.drawLine)(context, end, pi2);\n drawn = true;\n }\n }\n if (!drawn) {\n return;\n }\n context.lineWidth = width;\n if (backgroundMask.enable) {\n context.globalCompositeOperation = backgroundMask.composite;\n }\n context.strokeStyle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(colorLine, opacity);\n const {\n shadow\n } = links;\n if (shadow.enable) {\n const shadowColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(shadow.color);\n if (shadowColor) {\n context.shadowBlur = shadow.blur;\n context.shadowColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(shadowColor);\n }\n }\n context.stroke();\n}\nfunction drawLinkTriangle(params) {\n const {\n context,\n pos1,\n pos2,\n pos3,\n backgroundMask,\n colorTriangle,\n opacityTriangle\n } = params;\n drawTriangle(context, pos1, pos2, pos3);\n if (backgroundMask.enable) {\n context.globalCompositeOperation = backgroundMask.composite;\n }\n context.fillStyle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(colorTriangle, opacityTriangle);\n context.fill();\n}\nfunction getLinkKey(ids) {\n ids.sort((a, b) => a - b);\n return ids.join(\"_\");\n}\nfunction setLinkFrequency(particles, dictionary) {\n const key = getLinkKey(particles.map(t => t.id));\n let res = dictionary.get(key);\n if (res === undefined) {\n res = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)();\n dictionary.set(key, res);\n }\n return res;\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/Utils.js?");
|
|
37
|
+
|
|
38
|
+
/***/ })
|
|
39
|
+
|
|
40
|
+
}]);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v3.2.0
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_interaction_particles_links"] = this["webpackChunk_tsparticles_interaction_particles_links"] || []).push([["dist_browser_Linker_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/Linker.js":
|
|
21
|
+
/*!********************************!*\
|
|
22
|
+
!*** ./dist/browser/Linker.js ***!
|
|
23
|
+
\********************************/
|
|
24
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
25
|
+
|
|
26
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Linker: () => (/* binding */ Linker)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Links.js */ \"./dist/browser/Options/Classes/Links.js\");\n\n\nconst squarePower = 2,\n opacityOffset = 1,\n origin = {\n x: 0,\n y: 0\n },\n minDistance = 0;\nfunction getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {\n const {\n dx,\n dy,\n distance\n } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(pos1, pos2);\n if (!warp || distance <= optDistance) {\n return distance;\n }\n const absDiffs = {\n x: Math.abs(dx),\n y: Math.abs(dy)\n },\n warpDistances = {\n x: Math.min(absDiffs.x, canvasSize.width - absDiffs.x),\n y: Math.min(absDiffs.y, canvasSize.height - absDiffs.y)\n };\n return Math.sqrt(warpDistances.x ** squarePower + warpDistances.y ** squarePower);\n}\nclass Linker extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ParticlesInteractorBase {\n constructor(container) {\n super(container);\n this._setColor = p1 => {\n if (!p1.options.links) {\n return;\n }\n const container = this.linkContainer,\n linksOptions = p1.options.links;\n let linkColor = linksOptions.id === undefined ? container.particles.linksColor : container.particles.linksColors.get(linksOptions.id);\n if (linkColor) {\n return;\n }\n const optColor = linksOptions.color;\n linkColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLinkRandomColor)(optColor, linksOptions.blink, linksOptions.consent);\n if (linksOptions.id === undefined) {\n container.particles.linksColor = linkColor;\n } else {\n container.particles.linksColors.set(linksOptions.id, linkColor);\n }\n };\n this.linkContainer = container;\n }\n clear() {}\n init() {\n this.linkContainer.particles.linksColor = undefined;\n this.linkContainer.particles.linksColors = new Map();\n }\n async interact(p1) {\n if (!p1.options.links) {\n return;\n }\n p1.links = [];\n const pos1 = p1.getPosition(),\n container = this.container,\n canvasSize = container.canvas.size;\n if (pos1.x < origin.x || pos1.y < origin.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {\n return;\n }\n const linkOpt1 = p1.options.links,\n optOpacity = linkOpt1.opacity,\n optDistance = p1.retina.linksDistance ?? minDistance,\n warp = linkOpt1.warp;\n let range;\n if (warp) {\n const {\n CircleWarp\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_CircleWarp_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./CircleWarp.js */ \"./dist/browser/CircleWarp.js\"));\n range = new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize);\n } else {\n range = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(pos1.x, pos1.y, optDistance);\n }\n const query = container.particles.quadTree.query(range);\n for (const p2 of query) {\n const linkOpt2 = p2.options.links;\n if (p1 === p2 || !linkOpt2?.enable || linkOpt1.id !== linkOpt2.id || p2.spawning || p2.destroyed || !p2.links || p1.links.some(t => t.destination === p2) || p2.links.some(t => t.destination === p1)) {\n continue;\n }\n const pos2 = p2.getPosition();\n if (pos2.x < origin.x || pos2.y < origin.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {\n continue;\n }\n const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);\n if (distance > optDistance) {\n continue;\n }\n const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;\n this._setColor(p1);\n p1.links.push({\n destination: p2,\n opacity: opacityLine\n });\n }\n }\n isEnabled(particle) {\n return !!particle.options.links?.enable;\n }\n loadParticlesOptions(options, ...sources) {\n if (!options.links) {\n options.links = new _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_1__.Links();\n }\n for (const source of sources) {\n options.links.load(source?.links);\n }\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/Linker.js?");
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
}]);
|
package/esm/CircleWarp.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
2
|
+
const double = 2;
|
|
2
3
|
export class CircleWarp extends Circle {
|
|
3
4
|
constructor(x, y, radius, canvasSize) {
|
|
4
5
|
super(x, y, radius);
|
|
@@ -22,11 +23,11 @@ export class CircleWarp extends Circle {
|
|
|
22
23
|
y: range.position.y - this.canvasSize.height,
|
|
23
24
|
};
|
|
24
25
|
if (circle.radius !== undefined) {
|
|
25
|
-
const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius *
|
|
26
|
+
const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * double);
|
|
26
27
|
return super.intersects(biggerCircle);
|
|
27
28
|
}
|
|
28
29
|
else if (rect.size !== undefined) {
|
|
29
|
-
const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width *
|
|
30
|
+
const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * double, rect.size.height * double);
|
|
30
31
|
return super.intersects(rectSW);
|
|
31
32
|
}
|
|
32
33
|
return false;
|