@tsparticles/interaction-particles-links 4.0.0-alpha.5 → 4.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/13.min.js +1 -0
- package/342.min.js +1 -0
- package/823.min.js +1 -0
- package/README.md +5 -0
- package/browser/CircleWarp.js +34 -18
- package/browser/LinkInstance.js +138 -131
- package/browser/Linker.js +49 -50
- package/browser/LinksPlugin.js +2 -1
- package/browser/Options/Classes/Links.js +12 -0
- package/browser/Options/Classes/LinksShadow.js +3 -0
- package/browser/Options/Classes/LinksTriangle.js +4 -0
- package/browser/Utils.js +2 -83
- package/browser/index.js +7 -4
- package/cjs/CircleWarp.js +34 -18
- package/cjs/LinkInstance.js +138 -131
- package/cjs/Linker.js +49 -50
- package/cjs/LinksPlugin.js +2 -1
- package/cjs/Options/Classes/Links.js +12 -0
- package/cjs/Options/Classes/LinksShadow.js +3 -0
- package/cjs/Options/Classes/LinksTriangle.js +4 -0
- package/cjs/Utils.js +2 -83
- package/cjs/index.js +7 -4
- package/dist_browser_LinkInstance_js.js +3 -3
- package/dist_browser_Linker_js.js +3 -3
- package/dist_browser_LinksPlugin_js.js +2 -2
- package/esm/CircleWarp.js +34 -18
- package/esm/LinkInstance.js +138 -131
- package/esm/Linker.js +49 -50
- package/esm/LinksPlugin.js +2 -1
- package/esm/Options/Classes/Links.js +12 -0
- package/esm/Options/Classes/LinksShadow.js +3 -0
- package/esm/Options/Classes/LinksTriangle.js +4 -0
- package/esm/Utils.js +2 -83
- package/esm/index.js +7 -4
- package/package.json +4 -3
- package/report.html +3 -3
- package/tsparticles.interaction.particles.links.js +45 -33
- package/tsparticles.interaction.particles.links.min.js +2 -2
- package/types/CircleWarp.d.ts +2 -2
- package/types/Interfaces.d.ts +4 -2
- package/types/LinkInstance.d.ts +6 -6
- package/types/Linker.d.ts +4 -1
- package/types/LinksPlugin.d.ts +1 -1
- package/types/Types.d.ts +11 -20
- package/types/Utils.d.ts +1 -5
- package/umd/CircleWarp.js +33 -17
- package/umd/LinkInstance.js +136 -129
- package/umd/Linker.js +48 -49
- package/umd/LinksPlugin.js +2 -1
- package/umd/Options/Classes/Links.js +12 -0
- package/umd/Options/Classes/LinksShadow.js +3 -0
- package/umd/Options/Classes/LinksTriangle.js +4 -0
- package/umd/Utils.js +1 -85
- package/umd/index.js +7 -4
- package/161.min.js +0 -2
- package/161.min.js.LICENSE.txt +0 -1
- package/29.min.js +0 -2
- package/29.min.js.LICENSE.txt +0 -1
- package/94.min.js +0 -2
- package/94.min.js.LICENSE.txt +0 -1
- package/tsparticles.interaction.particles.links.min.js.LICENSE.txt +0 -1
package/cjs/Utils.js
CHANGED
|
@@ -1,87 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function drawTriangle(context, p1, p2, p3) {
|
|
3
|
-
context.beginPath();
|
|
4
|
-
context.moveTo(p1.x, p1.y);
|
|
5
|
-
context.lineTo(p2.x, p2.y);
|
|
6
|
-
context.lineTo(p3.x, p3.y);
|
|
7
|
-
context.closePath();
|
|
8
|
-
}
|
|
9
|
-
export function drawLinkLine(params) {
|
|
10
|
-
let drawn = false;
|
|
11
|
-
const { begin, end, engine, maxDistance, context, canvasSize, width, colorLine, opacity, links, hdr } = params;
|
|
12
|
-
if (getDistance(begin, end) <= maxDistance) {
|
|
13
|
-
drawLine(context, begin, end);
|
|
14
|
-
drawn = true;
|
|
15
|
-
}
|
|
16
|
-
else if (links.warp) {
|
|
17
|
-
let pi1;
|
|
18
|
-
let pi2;
|
|
19
|
-
const endNE = {
|
|
20
|
-
x: end.x - canvasSize.width,
|
|
21
|
-
y: end.y,
|
|
22
|
-
};
|
|
23
|
-
const d1 = getDistances(begin, endNE);
|
|
24
|
-
if (d1.distance <= maxDistance) {
|
|
25
|
-
const yi = begin.y - (d1.dy / d1.dx) * begin.x;
|
|
26
|
-
pi1 = { x: 0, y: yi };
|
|
27
|
-
pi2 = { x: canvasSize.width, y: yi };
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const endSW = {
|
|
31
|
-
x: end.x,
|
|
32
|
-
y: end.y - canvasSize.height,
|
|
33
|
-
};
|
|
34
|
-
const d2 = getDistances(begin, endSW);
|
|
35
|
-
if (d2.distance <= maxDistance) {
|
|
36
|
-
const yi = begin.y - (d2.dy / d2.dx) * begin.x;
|
|
37
|
-
const xi = -yi / (d2.dy / d2.dx);
|
|
38
|
-
pi1 = { x: xi, y: 0 };
|
|
39
|
-
pi2 = { x: xi, y: canvasSize.height };
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const endSE = {
|
|
43
|
-
x: end.x - canvasSize.width,
|
|
44
|
-
y: end.y - canvasSize.height,
|
|
45
|
-
};
|
|
46
|
-
const d3 = getDistances(begin, endSE);
|
|
47
|
-
if (d3.distance <= maxDistance) {
|
|
48
|
-
const yi = begin.y - (d3.dy / d3.dx) * begin.x;
|
|
49
|
-
const xi = -yi / (d3.dy / d3.dx);
|
|
50
|
-
pi1 = { x: xi, y: yi };
|
|
51
|
-
pi2 = { x: pi1.x + canvasSize.width, y: pi1.y + canvasSize.height };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (pi1 && pi2) {
|
|
56
|
-
drawLine(context, begin, pi1);
|
|
57
|
-
drawLine(context, end, pi2);
|
|
58
|
-
drawn = true;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (!drawn) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
context.lineWidth = width;
|
|
65
|
-
context.strokeStyle = getStyleFromRgb(colorLine, hdr, opacity);
|
|
66
|
-
const { shadow } = links;
|
|
67
|
-
if (shadow.enable) {
|
|
68
|
-
const shadowColor = rangeColorToRgb(engine, shadow.color);
|
|
69
|
-
if (shadowColor) {
|
|
70
|
-
context.shadowBlur = shadow.blur;
|
|
71
|
-
context.shadowColor = getStyleFromRgb(shadowColor, hdr);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
context.stroke();
|
|
75
|
-
}
|
|
76
|
-
export function drawLinkTriangle(params) {
|
|
77
|
-
const { context, hdr, pos1, pos2, pos3, colorTriangle, opacityTriangle } = params;
|
|
78
|
-
drawTriangle(context, pos1, pos2, pos3);
|
|
79
|
-
context.fillStyle = getStyleFromRgb(colorTriangle, hdr, opacityTriangle);
|
|
80
|
-
context.fill();
|
|
81
|
-
}
|
|
1
|
+
import { getRandom } from "@tsparticles/engine";
|
|
82
2
|
export function getLinkKey(ids) {
|
|
83
|
-
ids.sort((a, b) => a - b);
|
|
84
|
-
return ids.join("_");
|
|
3
|
+
return [...ids].sort((a, b) => a - b).join("_");
|
|
85
4
|
}
|
|
86
5
|
export function setLinkFrequency(particles, dictionary) {
|
|
87
6
|
const key = getLinkKey(particles.map(t => t.id));
|
package/cjs/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export async function loadParticlesLinksInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const [{ ensureInteractivityPluginLoaded }, { LinksPlugin },] = await Promise.all([
|
|
5
|
+
import("@tsparticles/plugin-interactivity"),
|
|
6
|
+
import("./LinksPlugin.js"),
|
|
7
|
+
]);
|
|
8
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
9
|
e.addPlugin(new LinksPlugin(e));
|
|
7
10
|
e.addInteractor?.("particlesLinks", async (container) => {
|
|
8
11
|
const { Linker } = await import("./Linker.js");
|
|
9
|
-
return new Linker(container,
|
|
12
|
+
return new Linker(container, e);
|
|
10
13
|
});
|
|
11
14
|
});
|
|
12
15
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v4.0.0-
|
|
7
|
+
* v4.0.0-beta.0
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\**************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
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 _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\nconst minOpacity = 0
|
|
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 _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\nconst minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;\nclass LinkInstance {\n _colorCache = new Map();\n _container;\n _engine;\n _freqs;\n constructor(container, engine){\n this._container = container;\n this._engine = engine;\n this._freqs = {\n links: new Map(),\n triangles: new Map()\n };\n }\n drawParticle(context, particle) {\n const { links, options } = particle;\n if (!links?.length || !options.links) {\n return;\n }\n const linkOpts = options.links, width = particle.retina.linksWidth ?? minWidth, pos1 = particle.getPosition(), twinkle = particle.options[\"twinkle\"]?.links, trianglesEnabled = linkOpts.triangles.enable, p1Destinations = trianglesEnabled ? new Set(links.map((l)=>l.destination.id)) : null, originalAlpha = context.globalAlpha;\n let currentColorStyle = \"\", currentWidth = -1, currentAlpha = -1, pathOpen = false;\n const flushLines = ()=>{\n if (pathOpen) {\n context.stroke();\n pathOpen = false;\n }\n };\n for (const link of links){\n if (linkOpts.frequency < maxFrequency && this._getLinkFrequency(particle, link.destination) > linkOpts.frequency) {\n continue;\n }\n const pos2 = link.destination.getPosition();\n if (trianglesEnabled && !link.isWarped && p1Destinations) {\n flushLines();\n this._drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);\n }\n if (link.opacity <= minOpacity || width <= minWidth) {\n continue;\n }\n if (!linkOpts.enable) {\n continue;\n }\n let opacity = link.opacity, colorLine = link.color;\n const twinkleRgb = twinkle?.enable && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() < twinkle.frequency ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, twinkle.color) : undefined;\n if (twinkle && twinkleRgb) {\n colorLine = twinkleRgb;\n opacity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(twinkle.opacity);\n }\n if (!colorLine) {\n const linkColor = linkOpts.id !== undefined ? this._container.particles.linksColors.get(linkOpts.id) : this._container.particles.linksColor;\n colorLine = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLinkColor)(particle, link.destination, linkColor);\n }\n if (!colorLine) {\n continue;\n }\n const colorStyle = this._getCachedStyle(colorLine);\n if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {\n flushLines();\n context.strokeStyle = colorStyle;\n context.lineWidth = width;\n context.globalAlpha = opacity;\n currentColorStyle = colorStyle;\n currentWidth = width;\n currentAlpha = opacity;\n context.beginPath();\n pathOpen = true;\n }\n if (link.isWarped) {\n const canvasSize = this._container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;\n let sx = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, sy = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y;\n if (Math.abs(dx) > canvasSize.width * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) {\n sx = dx > minDistance ? -canvasSize.width : canvasSize.width;\n }\n if (Math.abs(dy) > canvasSize.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) {\n sy = dy > minDistance ? -canvasSize.height : canvasSize.height;\n }\n context.moveTo(pos1.x, pos1.y);\n context.lineTo(pos2.x + sx, pos2.y + sy);\n context.moveTo(pos1.x - sx, pos1.y - sy);\n context.lineTo(pos2.x, pos2.y);\n } else {\n context.moveTo(pos1.x, pos1.y);\n context.lineTo(pos2.x, pos2.y);\n }\n }\n flushLines();\n context.globalAlpha = originalAlpha;\n }\n init() {\n this._freqs.links.clear();\n this._freqs.triangles.clear();\n this._colorCache.clear();\n return Promise.resolve();\n }\n particleCreated(particle) {\n particle.links = [];\n if (!particle.options.links) {\n return;\n }\n particle.linksDistance = particle.options.links.distance;\n particle.linksWidth = particle.options.links.width;\n const ratio = this._container.retina.pixelRatio;\n particle.retina.linksDistance = particle.linksDistance * ratio;\n particle.retina.linksWidth = particle.linksWidth * ratio;\n }\n particleDestroyed(particle) {\n particle.links = [];\n }\n _drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {\n const p2 = link.destination, triangleOptions = options.links?.triangles;\n if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {\n return;\n }\n const p2Links = p2.links;\n if (!p2Links?.length) {\n return;\n }\n for (const vertex of p2Links){\n if (vertex.isWarped || this._getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency || !p1Destinations.has(vertex.destination.id)) {\n continue;\n }\n const p3 = vertex.destination;\n if (this._getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {\n continue;\n }\n const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half, colorTriangle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, triangleOptions.color) ?? link.color;\n if (!colorTriangle || opacityTriangle <= minOpacity) {\n continue;\n }\n const pos3 = p3.getPosition();\n context.save();\n context.fillStyle = this._getCachedStyle(colorTriangle);\n context.globalAlpha = opacityTriangle;\n context.beginPath();\n context.moveTo(pos1.x, pos1.y);\n context.lineTo(pos2.x, pos2.y);\n context.lineTo(pos3.x, pos3.y);\n context.closePath();\n context.fill();\n context.restore();\n }\n }\n _getCachedStyle(rgb) {\n const key = `${rgb.r},${rgb.g},${rgb.b}`;\n let style = this._colorCache.get(key);\n if (!style) {\n style = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(rgb, this._container.hdr);\n this._colorCache.set(key, style);\n }\n return style;\n }\n _getLinkFrequency(p1, p2) {\n return (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.setLinkFrequency)([\n p1,\n p2\n ], this._freqs.links);\n }\n _getTriangleFrequency(p1, p2, p3) {\n return (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.setLinkFrequency)([\n p1,\n p2,\n p3\n ], this._freqs.triangles);\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/LinkInstance.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ },
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
33
33
|
\*******************************/
|
|
34
34
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
35
|
|
|
36
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\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\nfunction getLinkKey(ids) {\n return [\n ...ids\n ].sort((a, b)=>a - b).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\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/Utils.js?\n}");
|
|
37
37
|
|
|
38
38
|
/***/ }
|
|
39
39
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v4.0.0-
|
|
7
|
+
* v4.0.0-beta.0
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
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\nclass CircleWarp extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle {\n
|
|
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\nclass CircleWarp extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle {\n canvasSize;\n constructor(x, y, radius, canvasSize){\n super(x, y, radius);\n this.canvasSize = canvasSize;\n }\n contains(point) {\n if (super.contains(point)) return true;\n const { width, height } = this.canvasSize, { x, y } = point;\n return super.contains({\n x: x - width,\n y\n }) || super.contains({\n x: x + width,\n y\n }) || super.contains({\n x,\n y: y - height\n }) || super.contains({\n x,\n y: y + height\n }) || super.contains({\n x: x - width,\n y: y - height\n }) || super.contains({\n x: x + width,\n y: y + height\n }) || super.contains({\n x: x - width,\n y: y + height\n }) || super.contains({\n x: x + width,\n y: y - height\n });\n }\n intersects(range) {\n if (super.intersects(range)) return true;\n const { width, height } = this.canvasSize, pos = range.position, shifts = [\n {\n x: -width,\n y: 0\n },\n {\n x: width,\n y: 0\n },\n {\n x: 0,\n y: -height\n },\n {\n x: 0,\n y: height\n },\n {\n x: -width,\n y: -height\n },\n {\n x: width,\n y: height\n },\n {\n x: -width,\n y: height\n },\n {\n x: width,\n y: -height\n }\n ];\n for (const shift of shifts){\n const shiftedPos = {\n x: pos.x + shift.x,\n y: pos.y + shift.y\n };\n let shiftedRange;\n if (range instanceof _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle) {\n shiftedRange = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(shiftedPos.x, shiftedPos.y, range.radius);\n } else {\n const rect = range;\n shiftedRange = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle(shiftedPos.x, shiftedPos.y, rect.size.width, rect.size.height);\n }\n if (super.intersects(shiftedRange)) return true;\n }\n return false;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/CircleWarp.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ },
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
33
33
|
\********************************/
|
|
34
34
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
35
|
|
|
36
|
-
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 _CircleWarp_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CircleWarp.js */ \"./dist/browser/CircleWarp.js\");\n/* harmony import */ var _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Links.js */ \"./dist/browser/Options/Classes/Links.js\");\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n\n\n\n\nconst
|
|
36
|
+
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 _CircleWarp_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CircleWarp.js */ \"./dist/browser/CircleWarp.js\");\n/* harmony import */ var _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Links.js */ \"./dist/browser/Options/Classes/Links.js\");\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n\n\n\n\nconst opacityOffset = 1, minDistance = 0;\nfunction getWarpDistance(pos1, pos2, canvasSize) {\n const { dx, dy } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(pos1, pos2), absDiffs = {\n x: Math.abs(dx),\n y: Math.abs(dy)\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.hypot(warpDistances.x, warpDistances.y);\n}\nclass Linker extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_3__.ParticlesInteractorBase {\n _engine;\n _maxDistance;\n constructor(container, engine){\n super(container);\n this._engine = engine;\n this._maxDistance = 0;\n }\n get maxDistance() {\n return this._maxDistance;\n }\n clear() {}\n init() {\n this.container.particles.linksColor = undefined;\n this.container.particles.linksColors = new Map();\n }\n interact(p1) {\n if (!p1.options.links) {\n return;\n }\n p1.links = [];\n if (p1.linksDistance && p1.linksDistance > this._maxDistance) {\n this._maxDistance = p1.linksDistance;\n }\n const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;\n if (pos1.x < _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x || pos1.y < _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {\n return;\n }\n const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance, warp = linkOpt1.warp, range = warp ? new _CircleWarp_js__WEBPACK_IMPORTED_MODULE_1__.CircleWarp(pos1.x, pos1.y, optDistance, canvasSize) : new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(pos1.x, pos1.y, optDistance), query = container.particles.grid.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 < _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x || pos2.y < _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {\n continue;\n }\n const distDirect = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(pos1, pos2).distance, distWarp = warp && linkOpt2.warp ? getWarpDistance(pos1, pos2, canvasSize) : distDirect, distance = Math.min(distDirect, distWarp);\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 color: this._getLinkColor(p1, p2),\n isWarped: distWarp < distDirect\n });\n }\n }\n isEnabled(particle) {\n return !!particle.options.links?.enable;\n }\n loadParticlesOptions(options, ...sources) {\n options.links ??= new _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_2__.Links();\n for (const source of sources){\n options.links.load(source?.links);\n }\n }\n reset() {}\n _getLinkColor(p1, p2) {\n const container = this.container, linksOptions = p1.options.links;\n if (!linksOptions) {\n return;\n }\n const linkColor = linksOptions.id !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLinkColor)(p1, p2, linkColor);\n }\n _setColor(p1) {\n if (!p1.options.links) {\n return;\n }\n const container = this.container, 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 linkColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLinkRandomColor)(this._engine, linksOptions.color, 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}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/Linker.js?\n}");
|
|
37
37
|
|
|
38
38
|
/***/ }
|
|
39
39
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v4.0.0-
|
|
7
|
+
* v4.0.0-beta.0
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\*************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
25
|
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ LinksPlugin: () => (/* binding */ LinksPlugin)\n/* harmony export */ });\nclass LinksPlugin {\n
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ LinksPlugin: () => (/* binding */ LinksPlugin)\n/* harmony export */ });\nclass LinksPlugin {\n id = \"links\";\n _engine;\n constructor(engine){\n this._engine = engine;\n }\n async getPlugin(container) {\n const { LinkInstance } = await __webpack_require__.e(/*! import() */ \"dist_browser_LinkInstance_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./LinkInstance.js */ \"./dist/browser/LinkInstance.js\"));\n return new LinkInstance(container, this._engine);\n }\n loadOptions() {}\n needsPlugin() {\n return true;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/LinksPlugin.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ }
|
|
29
29
|
|
package/esm/CircleWarp.js
CHANGED
|
@@ -1,32 +1,48 @@
|
|
|
1
|
-
import { Circle, Rectangle
|
|
1
|
+
import { Circle, Rectangle } from "@tsparticles/engine";
|
|
2
2
|
export class CircleWarp extends Circle {
|
|
3
|
+
canvasSize;
|
|
3
4
|
constructor(x, y, radius, canvasSize) {
|
|
4
5
|
super(x, y, radius);
|
|
5
6
|
this.canvasSize = canvasSize;
|
|
6
|
-
this.canvasSize = { ...canvasSize };
|
|
7
7
|
}
|
|
8
8
|
contains(point) {
|
|
9
|
+
if (super.contains(point))
|
|
10
|
+
return true;
|
|
9
11
|
const { width, height } = this.canvasSize, { x, y } = point;
|
|
10
|
-
return (super.contains(
|
|
11
|
-
super.contains({ x: x
|
|
12
|
+
return (super.contains({ x: x - width, y }) ||
|
|
13
|
+
super.contains({ x: x + width, y }) ||
|
|
14
|
+
super.contains({ x, y: y - height }) ||
|
|
15
|
+
super.contains({ x, y: y + height }) ||
|
|
12
16
|
super.contains({ x: x - width, y: y - height }) ||
|
|
13
|
-
super.contains({ x, y: y
|
|
17
|
+
super.contains({ x: x + width, y: y + height }) ||
|
|
18
|
+
super.contains({ x: x - width, y: y + height }) ||
|
|
19
|
+
super.contains({ x: x + width, y: y - height }));
|
|
14
20
|
}
|
|
15
21
|
intersects(range) {
|
|
16
|
-
if (super.intersects(range))
|
|
22
|
+
if (super.intersects(range))
|
|
17
23
|
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
x:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const { width, height } = this.canvasSize, pos = range.position, shifts = [
|
|
25
|
+
{ x: -width, y: 0 },
|
|
26
|
+
{ x: width, y: 0 },
|
|
27
|
+
{ x: 0, y: -height },
|
|
28
|
+
{ x: 0, y: height },
|
|
29
|
+
{ x: -width, y: -height },
|
|
30
|
+
{ x: width, y: height },
|
|
31
|
+
{ x: -width, y: height },
|
|
32
|
+
{ x: width, y: -height },
|
|
33
|
+
];
|
|
34
|
+
for (const shift of shifts) {
|
|
35
|
+
const shiftedPos = { x: pos.x + shift.x, y: pos.y + shift.y };
|
|
36
|
+
let shiftedRange;
|
|
37
|
+
if (range instanceof Circle) {
|
|
38
|
+
shiftedRange = new Circle(shiftedPos.x, shiftedPos.y, range.radius);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const rect = range;
|
|
42
|
+
shiftedRange = new Rectangle(shiftedPos.x, shiftedPos.y, rect.size.width, rect.size.height);
|
|
43
|
+
}
|
|
44
|
+
if (super.intersects(shiftedRange))
|
|
45
|
+
return true;
|
|
30
46
|
}
|
|
31
47
|
return false;
|
|
32
48
|
}
|