@tsparticles/interaction-particles-links 4.0.0-alpha.21 → 4.0.0-alpha.23
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/919.min.js +1 -1
- package/973.min.js +1 -1
- package/browser/CircleWarp.js +33 -18
- package/browser/LinkInstance.js +126 -115
- package/browser/Linker.js +20 -24
- package/browser/Utils.js +1 -76
- package/browser/index.js +2 -2
- package/cjs/CircleWarp.js +33 -18
- package/cjs/LinkInstance.js +126 -115
- package/cjs/Linker.js +20 -24
- package/cjs/Utils.js +1 -76
- package/cjs/index.js +2 -2
- package/dist_browser_LinkInstance_js.js +3 -3
- package/dist_browser_Linker_js.js +3 -3
- package/dist_browser_LinksPlugin_js.js +1 -1
- package/esm/CircleWarp.js +33 -18
- package/esm/LinkInstance.js +126 -115
- package/esm/Linker.js +20 -24
- package/esm/Utils.js +1 -76
- package/esm/index.js +2 -2
- package/package.json +4 -4
- package/report.html +1 -1
- package/tsparticles.interaction.particles.links.js +6 -16
- package/tsparticles.interaction.particles.links.min.js +2 -2
- package/types/CircleWarp.d.ts +2 -2
- package/types/Interfaces.d.ts +3 -1
- package/types/LinkInstance.d.ts +8 -5
- package/types/Linker.d.ts +2 -1
- package/types/Types.d.ts +9 -20
- package/types/Utils.d.ts +1 -5
- package/umd/CircleWarp.js +32 -17
- package/umd/LinkInstance.js +124 -113
- package/umd/Linker.js +19 -23
- package/umd/Utils.js +1 -79
- package/umd/index.js +2 -2
|
@@ -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-alpha.
|
|
7
|
+
* v4.0.0-alpha.23
|
|
8
8
|
*/
|
|
9
9
|
/*
|
|
10
10
|
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
@@ -16,28 +16,18 @@
|
|
|
16
16
|
*/
|
|
17
17
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
18
18
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
19
|
-
module.exports = factory(require("@tsparticles/engine"), require("@tsparticles/plugin-interactivity")
|
|
19
|
+
module.exports = factory(require("@tsparticles/engine"), require("@tsparticles/plugin-interactivity"));
|
|
20
20
|
else if(typeof define === 'function' && define.amd)
|
|
21
|
-
define(["@tsparticles/engine", "@tsparticles/plugin-interactivity"
|
|
21
|
+
define(["@tsparticles/engine", "@tsparticles/plugin-interactivity"], factory);
|
|
22
22
|
else {
|
|
23
|
-
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine"), require("@tsparticles/plugin-interactivity")
|
|
23
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine"), require("@tsparticles/plugin-interactivity")) : factory(root["window"], root["window"]);
|
|
24
24
|
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
25
25
|
}
|
|
26
|
-
})(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__, __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__
|
|
26
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__, __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__) => {
|
|
27
27
|
return /******/ (() => { // webpackBootstrap
|
|
28
28
|
/******/ "use strict";
|
|
29
29
|
/******/ var __webpack_modules__ = ({
|
|
30
30
|
|
|
31
|
-
/***/ "@tsparticles/canvas-utils"
|
|
32
|
-
/*!***************************************************************************************************************************************************!*\
|
|
33
|
-
!*** external {"commonjs":"@tsparticles/canvas-utils","commonjs2":"@tsparticles/canvas-utils","amd":"@tsparticles/canvas-utils","root":"window"} ***!
|
|
34
|
-
\***************************************************************************************************************************************************/
|
|
35
|
-
(module) {
|
|
36
|
-
|
|
37
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__;
|
|
38
|
-
|
|
39
|
-
/***/ },
|
|
40
|
-
|
|
41
31
|
/***/ "@tsparticles/engine"
|
|
42
32
|
/*!*********************************************************************************************************************************!*\
|
|
43
33
|
!*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
|
|
@@ -94,7 +84,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
94
84
|
\*******************************/
|
|
95
85
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
96
86
|
|
|
97
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Links: () => (/* reexport safe */ _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_0__.Links),\n/* harmony export */ LinksShadow: () => (/* reexport safe */ _Options_Classes_LinksShadow_js__WEBPACK_IMPORTED_MODULE_1__.LinksShadow),\n/* harmony export */ LinksTriangle: () => (/* reexport safe */ _Options_Classes_LinksTriangle_js__WEBPACK_IMPORTED_MODULE_2__.LinksTriangle),\n/* harmony export */ loadParticlesLinksInteraction: () => (/* binding */ loadParticlesLinksInteraction)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Links.js */ \"./dist/browser/Options/Classes/Links.js\");\n/* harmony import */ var _Options_Classes_LinksShadow_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/LinksShadow.js */ \"./dist/browser/Options/Classes/LinksShadow.js\");\n/* harmony import */ var _Options_Classes_LinksTriangle_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/LinksTriangle.js */ \"./dist/browser/Options/Classes/LinksTriangle.js\");\nasync function loadParticlesLinksInteraction(engine) {\n engine.checkVersion(\"4.0.0-alpha.
|
|
87
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Links: () => (/* reexport safe */ _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_0__.Links),\n/* harmony export */ LinksShadow: () => (/* reexport safe */ _Options_Classes_LinksShadow_js__WEBPACK_IMPORTED_MODULE_1__.LinksShadow),\n/* harmony export */ LinksTriangle: () => (/* reexport safe */ _Options_Classes_LinksTriangle_js__WEBPACK_IMPORTED_MODULE_2__.LinksTriangle),\n/* harmony export */ loadParticlesLinksInteraction: () => (/* binding */ loadParticlesLinksInteraction)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Links_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Links.js */ \"./dist/browser/Options/Classes/Links.js\");\n/* harmony import */ var _Options_Classes_LinksShadow_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/LinksShadow.js */ \"./dist/browser/Options/Classes/LinksShadow.js\");\n/* harmony import */ var _Options_Classes_LinksTriangle_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/LinksTriangle.js */ \"./dist/browser/Options/Classes/LinksTriangle.js\");\nasync function loadParticlesLinksInteraction(engine) {\n engine.checkVersion(\"4.0.0-alpha.23\");\n await engine.register(async (e)=>{\n const [{ ensureInteractivityPluginLoaded }, { LinksPlugin }] = await Promise.all([\n Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\", 19)),\n __webpack_require__.e(/*! import() */ \"dist_browser_LinksPlugin_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./LinksPlugin.js */ \"./dist/browser/LinksPlugin.js\"))\n ]);\n ensureInteractivityPluginLoaded(e);\n e.addPlugin(new LinksPlugin(e));\n e.addInteractor?.(\"particlesLinks\", async (container)=>{\n const { Linker } = await __webpack_require__.e(/*! import() */ \"dist_browser_Linker_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./Linker.js */ \"./dist/browser/Linker.js\"));\n return new Linker(container, e);\n });\n });\n}\n\n\n\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-links/./dist/browser/index.js?\n}");
|
|
98
88
|
|
|
99
89
|
/***/ }
|
|
100
90
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"),require("@tsparticles/plugin-interactivity")
|
|
2
|
-
(`+o+": "+n+")",s.name="ChunkLoadError",s.type=o,s.request=n,i[1](s)}},"chunk-"+e,e)}},
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"),require("@tsparticles/plugin-interactivity"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine","@tsparticles/plugin-interactivity"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine"),require("@tsparticles/plugin-interactivity")):t(e.window,e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e,t)=>(()=>{"use strict";var r,i,o,n={303(t){t.exports=e},702(e){e.exports=t},153(e,t,r){r.d(t,{q:()=>s});var i=r(303),o=r(889),n=r(337);class s{blink;color;consent;distance;enable;frequency;id;opacity;shadow;triangles;warp;width;constructor(){this.blink=!1,this.color=new i.OptionsColor,this.color.value="#fff",this.consent=!1,this.distance=100,this.enable=!1,this.frequency=1,this.opacity=1,this.shadow=new o.s,this.triangles=new n.G,this.width=1,this.warp=!1}load(e){(0,i.isNull)(e)||(void 0!==e.id&&(this.id=e.id),void 0!==e.blink&&(this.blink=e.blink),this.color=i.OptionsColor.create(this.color,e.color),void 0!==e.consent&&(this.consent=e.consent),void 0!==e.distance&&(this.distance=e.distance),void 0!==e.enable&&(this.enable=e.enable),void 0!==e.frequency&&(this.frequency=e.frequency),void 0!==e.opacity&&(this.opacity=e.opacity),this.shadow.load(e.shadow),this.triangles.load(e.triangles),void 0!==e.width&&(this.width=e.width),void 0!==e.warp&&(this.warp=e.warp))}}},889(e,t,r){r.d(t,{s:()=>o});var i=r(303);class o{blur;color;enable;constructor(){this.blur=5,this.color=new i.OptionsColor,this.color.value="#000",this.enable=!1}load(e){(0,i.isNull)(e)||(void 0!==e.blur&&(this.blur=e.blur),this.color=i.OptionsColor.create(this.color,e.color),void 0!==e.enable&&(this.enable=e.enable))}}},337(e,t,r){r.d(t,{G:()=>o});var i=r(303);class o{color;enable;frequency;opacity;constructor(){this.enable=!1,this.frequency=1}load(e){(0,i.isNull)(e)||(void 0!==e.color&&(this.color=i.OptionsColor.create(this.color,e.color)),void 0!==e.enable&&(this.enable=e.enable),void 0!==e.frequency&&(this.frequency=e.frequency),void 0!==e.opacity&&(this.opacity=e.opacity))}}}},s={};function a(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return n[e](r,r.exports,a),r.exports}a.m=n,c=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,t){if(1&t&&(e=this(e)),8&t||"object"==typeof e&&e&&(4&t&&e.__esModule||16&t&&"function"==typeof e.then))return e;var r=Object.create(null);a.r(r);var i={};l=l||[null,c({}),c([]),c(c)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~l.indexOf(o);o=c(o))Object.getOwnPropertyNames(o).forEach(t=>i[t]=()=>e[t]);return i.default=()=>e,a.d(r,i),r},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce((t,r)=>(a.f[r](e,t),t),[])),a.u=e=>""+e+".min.js",a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),p={},a.l=(e,t,r,i)=>{if(p[e])return void p[e].push(t);if(void 0!==r)for(var o,n,s=document.getElementsByTagName("script"),l=0;l<s.length;l++){var c=s[l];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")=="@tsparticles/interaction-particles-links:"+r){o=c;break}}o||(n=!0,(o=document.createElement("script")).charset="utf-8",a.nc&&o.setAttribute("nonce",a.nc),o.setAttribute("data-webpack","@tsparticles/interaction-particles-links:"+r),o.src=e),p[e]=[t];var d=(t,r)=>{o.onerror=o.onload=null,clearTimeout(u);var i=p[e];if(delete p[e],o.parentNode&&o.parentNode.removeChild(o),i&&i.forEach(e=>e(r)),t)return t(r)},u=setTimeout(d.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=d.bind(null,o.onerror),o.onload=d.bind(null,o.onload),n&&document.head.appendChild(o)},a.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.g.importScripts&&(d=a.g.location+"");var l,c,p,d,u=a.g.document;if(!d&&u&&(u.currentScript&&"SCRIPT"===u.currentScript.tagName.toUpperCase()&&(d=u.currentScript.src),!d)){var h=u.getElementsByTagName("script");if(h.length)for(var f=h.length-1;f>-1&&(!d||!/^http(s?):/.test(d));)d=h[f--].src}if(!d)throw Error("Automatic publicPath is not supported in this browser");a.p=d=d.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={203:0},a.f.j=(e,t)=>{var i=a.o(r,e)?r[e]:void 0;if(0!==i)if(i)t.push(i[2]);else{var o=new Promise((t,o)=>i=r[e]=[t,o]);t.push(i[2]=o);var n=a.p+a.u(e),s=Error();a.l(n,t=>{if(a.o(r,e)&&(0!==(i=r[e])&&(r[e]=void 0),i)){var o=t&&("load"===t.type?"missing":t.type),n=t&&t.target&&t.target.src;s.message="Loading chunk "+e+` failed.
|
|
2
|
+
(`+o+": "+n+")",s.name="ChunkLoadError",s.type=o,s.request=n,i[1](s)}},"chunk-"+e,e)}},i=(e,t)=>{var i,o,[n,s,l]=t,c=0;if(n.some(e=>0!==r[e])){for(i in s)a.o(s,i)&&(a.m[i]=s[i]);l&&l(a)}for(e&&e(t);c<n.length;c++)o=n[c],a.o(r,o)&&r[o]&&r[o][0](),r[o]=0},(o=this.webpackChunk_tsparticles_interaction_particles_links=this.webpackChunk_tsparticles_interaction_particles_links||[]).forEach(i.bind(null,0)),o.push=i.bind(null,o.push.bind(o));var b={};a.r(b),a.d(b,{Links:()=>v.q,LinksShadow:()=>y.s,LinksTriangle:()=>g.G,loadParticlesLinksInteraction:()=>w});var v=a(153),y=a(889),g=a(337);async function w(e){e.checkVersion("4.0.0-alpha.23"),await e.register(async e=>{let[{ensureInteractivityPluginLoaded:t},{LinksPlugin:r}]=await Promise.all([Promise.resolve().then(a.t.bind(a,702,19)),a.e(272).then(a.bind(a,272))]);t(e),e.addPlugin(new r(e)),e.addInteractor?.("particlesLinks",async t=>{let{Linker:r}=await a.e(973).then(a.bind(a,973));return new r(t,e)})})}return b})());
|
package/types/CircleWarp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Circle, type ICoordinates, type IDimension, Rectangle } from "@tsparticles/engine";
|
|
2
2
|
export declare class CircleWarp extends Circle {
|
|
3
3
|
private readonly canvasSize;
|
|
4
4
|
constructor(x: number, y: number, radius: number, canvasSize: IDimension);
|
|
5
5
|
contains(point: ICoordinates): boolean;
|
|
6
|
-
intersects(range:
|
|
6
|
+
intersects(range: Rectangle | Circle): boolean;
|
|
7
7
|
}
|
package/types/Interfaces.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { IRangeColor, RangeValue } from "@tsparticles/engine";
|
|
1
|
+
import type { IRangeColor, IRgb, RangeValue } from "@tsparticles/engine";
|
|
2
2
|
import type { LinkParticle } from "./Types.js";
|
|
3
3
|
export interface ILink {
|
|
4
|
+
color?: IRgb;
|
|
4
5
|
destination: LinkParticle;
|
|
6
|
+
isWarped?: boolean;
|
|
5
7
|
opacity: number;
|
|
6
8
|
}
|
|
7
9
|
export interface ILinkTriangle {
|
package/types/LinkInstance.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { type Engine, type IContainerPlugin } from "@tsparticles/engine";
|
|
2
2
|
import type { LinkContainer, LinkParticle } from "./Types.js";
|
|
3
3
|
export declare class LinkInstance implements IContainerPlugin {
|
|
4
|
+
private readonly _colorCache;
|
|
4
5
|
private readonly _container;
|
|
5
6
|
private readonly _engine;
|
|
6
7
|
private readonly _freqs;
|
|
8
|
+
private readonly _lineBatches;
|
|
9
|
+
private readonly _triangleBatches;
|
|
7
10
|
constructor(container: LinkContainer, engine: Engine);
|
|
11
|
+
draw(context: CanvasRenderingContext2D): void;
|
|
8
12
|
drawParticle(_context: CanvasRenderingContext2D, particle: LinkParticle): void;
|
|
9
13
|
init(): Promise<void>;
|
|
10
14
|
particleCreated(particle: LinkParticle): void;
|
|
11
15
|
particleDestroyed(particle: LinkParticle): void;
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private readonly _getTriangleFrequency;
|
|
16
|
+
private _collectTriangles;
|
|
17
|
+
private _getCachedStyle;
|
|
18
|
+
private _getLinkFrequency;
|
|
19
|
+
private _getTriangleFrequency;
|
|
17
20
|
}
|
package/types/Linker.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare class Linker extends ParticlesInteractorBase<LinkContainer, LinkP
|
|
|
10
10
|
isEnabled(particle: LinkParticle): boolean;
|
|
11
11
|
loadParticlesOptions(options: ParticlesLinkOptions, ...sources: (RecursivePartial<IParticlesLinkOptions> | undefined)[]): void;
|
|
12
12
|
reset(): void;
|
|
13
|
-
private
|
|
13
|
+
private _getLinkColor;
|
|
14
|
+
private _setColor;
|
|
14
15
|
}
|
package/types/Types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { IInteractivityParticlesOptions, InteractivityContainer, InteractivityEngine, InteractivityParticle, InteractivityParticlesOptions } from "@tsparticles/plugin-interactivity";
|
|
1
|
+
import type { IInteractivityParticlesOptions, InteractivityContainer, InteractivityParticle, InteractivityParticlesOptions } from "@tsparticles/plugin-interactivity";
|
|
3
2
|
import type { ILink } from "./Interfaces.js";
|
|
4
3
|
import type { ILinks } from "./Options/Interfaces/ILinks.js";
|
|
4
|
+
import type { IRgb } from "@tsparticles/engine";
|
|
5
5
|
import type { Links } from "./Options/Classes/Links.js";
|
|
6
6
|
export type LinkContainer = InteractivityContainer & {
|
|
7
7
|
particles: {
|
|
@@ -17,27 +17,16 @@ export type LinkParticle = InteractivityParticle & {
|
|
|
17
17
|
linksWidth?: number;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
export interface
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
colorLine: IRgb;
|
|
24
|
-
context: CanvasRenderingContext2D;
|
|
25
|
-
end: ICoordinates;
|
|
26
|
-
engine: InteractivityEngine;
|
|
27
|
-
hdr: boolean;
|
|
28
|
-
links: Links;
|
|
29
|
-
maxDistance: number;
|
|
20
|
+
export interface LinkBatch {
|
|
21
|
+
colorStyle: string;
|
|
22
|
+
coords: number[];
|
|
30
23
|
opacity: number;
|
|
31
24
|
width: number;
|
|
32
25
|
}
|
|
33
|
-
export interface
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
opacityTriangle: number;
|
|
38
|
-
pos1: ICoordinates;
|
|
39
|
-
pos2: ICoordinates;
|
|
40
|
-
pos3: ICoordinates;
|
|
26
|
+
export interface TriangleBatch {
|
|
27
|
+
colorStyle: string;
|
|
28
|
+
coords: number[];
|
|
29
|
+
opacity: number;
|
|
41
30
|
}
|
|
42
31
|
export type IParticlesLinkOptions = IInteractivityParticlesOptions & {
|
|
43
32
|
links?: ILinks;
|
package/types/Utils.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { LinkLineDrawParams, LinkParticle, LinkTriangleDrawParams } from "./Types.js";
|
|
3
|
-
export declare function drawTriangle(context: CanvasRenderingContext2D, p1: ICoordinates, p2: ICoordinates, p3: ICoordinates): void;
|
|
4
|
-
export declare function drawLinkLine(params: LinkLineDrawParams): void;
|
|
5
|
-
export declare function drawLinkTriangle(params: LinkTriangleDrawParams): void;
|
|
1
|
+
import type { LinkParticle } from "./Types.js";
|
|
6
2
|
export declare function getLinkKey(ids: number[]): string;
|
|
7
3
|
export declare function setLinkFrequency(particles: LinkParticle[], dictionary: Map<string, number>): number;
|
package/umd/CircleWarp.js
CHANGED
|
@@ -16,30 +16,45 @@
|
|
|
16
16
|
constructor(x, y, radius, canvasSize) {
|
|
17
17
|
super(x, y, radius);
|
|
18
18
|
this.canvasSize = canvasSize;
|
|
19
|
-
this.canvasSize = { ...canvasSize };
|
|
20
19
|
}
|
|
21
20
|
contains(point) {
|
|
21
|
+
if (super.contains(point))
|
|
22
|
+
return true;
|
|
22
23
|
const { width, height } = this.canvasSize, { x, y } = point;
|
|
23
|
-
return (super.contains(
|
|
24
|
-
super.contains({ x: x
|
|
24
|
+
return (super.contains({ x: x - width, y }) ||
|
|
25
|
+
super.contains({ x: x + width, y }) ||
|
|
26
|
+
super.contains({ x, y: y - height }) ||
|
|
27
|
+
super.contains({ x, y: y + height }) ||
|
|
25
28
|
super.contains({ x: x - width, y: y - height }) ||
|
|
26
|
-
super.contains({ x, y: y
|
|
29
|
+
super.contains({ x: x + width, y: y + height }) ||
|
|
30
|
+
super.contains({ x: x - width, y: y + height }) ||
|
|
31
|
+
super.contains({ x: x + width, y: y - height }));
|
|
27
32
|
}
|
|
28
33
|
intersects(range) {
|
|
29
|
-
if (super.intersects(range))
|
|
34
|
+
if (super.intersects(range))
|
|
30
35
|
return true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
x:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
const { width, height } = this.canvasSize, pos = range.position, shifts = [
|
|
37
|
+
{ x: -width, y: 0 },
|
|
38
|
+
{ x: width, y: 0 },
|
|
39
|
+
{ x: 0, y: -height },
|
|
40
|
+
{ x: 0, y: height },
|
|
41
|
+
{ x: -width, y: -height },
|
|
42
|
+
{ x: width, y: height },
|
|
43
|
+
{ x: -width, y: height },
|
|
44
|
+
{ x: width, y: -height },
|
|
45
|
+
];
|
|
46
|
+
for (const shift of shifts) {
|
|
47
|
+
const shiftedPos = { x: pos.x + shift.x, y: pos.y + shift.y };
|
|
48
|
+
let shiftedRange;
|
|
49
|
+
if (range instanceof engine_1.Circle) {
|
|
50
|
+
shiftedRange = new engine_1.Circle(shiftedPos.x, shiftedPos.y, range.radius);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const rect = range;
|
|
54
|
+
shiftedRange = new engine_1.Rectangle(shiftedPos.x, shiftedPos.y, rect.size.width, rect.size.height);
|
|
55
|
+
}
|
|
56
|
+
if (super.intersects(shiftedRange))
|
|
57
|
+
return true;
|
|
43
58
|
}
|
|
44
59
|
return false;
|
|
45
60
|
}
|
package/umd/LinkInstance.js
CHANGED
|
@@ -12,37 +12,111 @@
|
|
|
12
12
|
exports.LinkInstance = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Utils_js_1 = require("./Utils.js");
|
|
15
|
-
const minOpacity = 0,
|
|
15
|
+
const minOpacity = 0, minDistance = 0, minWidth = 0, maxFrequency = 1, defaultFrequency = 0, opacitySteps = 10, defaultWidth = 0, triangleCoordsCount = 6, lineCoordsCount = 4, x1Offset = 0, y1Offset = 1, x2Offset = 2, y2Offset = 3, x3Offset = 4, y3Offset = 5;
|
|
16
16
|
class LinkInstance {
|
|
17
|
+
_colorCache = new Map();
|
|
17
18
|
_container;
|
|
18
19
|
_engine;
|
|
19
20
|
_freqs;
|
|
21
|
+
_lineBatches = new Map();
|
|
22
|
+
_triangleBatches = new Map();
|
|
20
23
|
constructor(container, engine) {
|
|
21
24
|
this._container = container;
|
|
22
25
|
this._engine = engine;
|
|
23
|
-
this._freqs = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
this._freqs = { links: new Map(), triangles: new Map() };
|
|
27
|
+
}
|
|
28
|
+
draw(context) {
|
|
29
|
+
for (const [, batch] of this._triangleBatches) {
|
|
30
|
+
context.save();
|
|
31
|
+
context.fillStyle = batch.colorStyle;
|
|
32
|
+
context.globalAlpha = batch.opacity;
|
|
33
|
+
context.beginPath();
|
|
34
|
+
for (let i = 0; i < batch.coords.length; i += triangleCoordsCount) {
|
|
35
|
+
const x1 = batch.coords[i + x1Offset] ?? engine_1.originPoint.x, y1 = batch.coords[i + y1Offset] ?? engine_1.originPoint.y, x2 = batch.coords[i + x2Offset] ?? engine_1.originPoint.x, y2 = batch.coords[i + y2Offset] ?? engine_1.originPoint.y, x3 = batch.coords[i + x3Offset] ?? engine_1.originPoint.x, y3 = batch.coords[i + y3Offset] ?? engine_1.originPoint.y;
|
|
36
|
+
context.moveTo(x1, y1);
|
|
37
|
+
context.lineTo(x2, y2);
|
|
38
|
+
context.lineTo(x3, y3);
|
|
39
|
+
}
|
|
40
|
+
context.fill();
|
|
41
|
+
context.restore();
|
|
42
|
+
}
|
|
43
|
+
for (const [, batch] of this._lineBatches) {
|
|
44
|
+
context.save();
|
|
45
|
+
context.strokeStyle = batch.colorStyle;
|
|
46
|
+
context.lineWidth = batch.width;
|
|
47
|
+
context.globalAlpha = batch.opacity;
|
|
48
|
+
context.beginPath();
|
|
49
|
+
for (let i = 0; i < batch.coords.length; i += lineCoordsCount) {
|
|
50
|
+
const x1 = batch.coords[i + x1Offset] ?? engine_1.originPoint.x, y1 = batch.coords[i + y1Offset] ?? engine_1.originPoint.y, x2 = batch.coords[i + x2Offset] ?? engine_1.originPoint.x, y2 = batch.coords[i + y2Offset] ?? engine_1.originPoint.y;
|
|
51
|
+
context.moveTo(x1, y1);
|
|
52
|
+
context.lineTo(x2, y2);
|
|
53
|
+
}
|
|
54
|
+
context.stroke();
|
|
55
|
+
context.restore();
|
|
56
|
+
}
|
|
57
|
+
this._lineBatches.clear();
|
|
58
|
+
this._triangleBatches.clear();
|
|
27
59
|
}
|
|
28
60
|
drawParticle(_context, particle) {
|
|
29
61
|
const { links, options } = particle;
|
|
30
|
-
if (!links?.length) {
|
|
62
|
+
if (!links?.length || !options.links) {
|
|
31
63
|
return;
|
|
32
64
|
}
|
|
33
|
-
const p1Links = links.filter(l => options.links &&
|
|
65
|
+
const canvasSize = this._container.canvas.size, p1Links = links.filter(l => options.links &&
|
|
34
66
|
(options.links.frequency >= maxFrequency ||
|
|
35
|
-
this._getLinkFrequency(particle, l.destination) <= options.links.frequency));
|
|
67
|
+
this._getLinkFrequency(particle, l.destination) <= options.links.frequency)), pos1 = particle.getPosition();
|
|
36
68
|
for (const link of p1Links) {
|
|
37
|
-
|
|
69
|
+
if (!link.isWarped) {
|
|
70
|
+
this._collectTriangles(options, particle, link, p1Links);
|
|
71
|
+
}
|
|
38
72
|
if (link.opacity > minOpacity && (particle.retina.linksWidth ?? minWidth) > minWidth) {
|
|
39
|
-
|
|
73
|
+
let opacity = link.opacity, colorLine = link.color;
|
|
74
|
+
const twinkle = particle.options["twinkle"]?.lines;
|
|
75
|
+
if (twinkle?.enable && (0, engine_1.getRandom)() < twinkle.frequency) {
|
|
76
|
+
const twinkleRgb = (0, engine_1.rangeColorToRgb)(this._engine, twinkle.color);
|
|
77
|
+
if (twinkleRgb) {
|
|
78
|
+
colorLine = twinkleRgb;
|
|
79
|
+
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!colorLine) {
|
|
83
|
+
const linkColor = options.links.id !== undefined
|
|
84
|
+
? this._container.particles.linksColors.get(options.links.id)
|
|
85
|
+
: this._container.particles.linksColor;
|
|
86
|
+
colorLine = (0, engine_1.getLinkColor)(particle, link.destination, linkColor);
|
|
87
|
+
}
|
|
88
|
+
if (colorLine) {
|
|
89
|
+
const qOpacity = Math.ceil(opacity * opacitySteps) / opacitySteps, colorStyle = this._getCachedStyle(colorLine), width = particle.retina.linksWidth ?? defaultWidth, key = `${colorStyle}_${qOpacity}_${width}`;
|
|
90
|
+
let batch = this._lineBatches.get(key);
|
|
91
|
+
if (!batch) {
|
|
92
|
+
batch = { colorStyle, opacity: qOpacity, width, coords: [] };
|
|
93
|
+
this._lineBatches.set(key, batch);
|
|
94
|
+
}
|
|
95
|
+
const pos2 = link.destination.getPosition();
|
|
96
|
+
if (link.isWarped) {
|
|
97
|
+
const dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
98
|
+
let sx = engine_1.originPoint.x, sy = engine_1.originPoint.y;
|
|
99
|
+
if (Math.abs(dx) > canvasSize.width * engine_1.half) {
|
|
100
|
+
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
101
|
+
}
|
|
102
|
+
if (Math.abs(dy) > canvasSize.height * engine_1.half) {
|
|
103
|
+
sy = dy > minDistance ? -canvasSize.height : canvasSize.height;
|
|
104
|
+
}
|
|
105
|
+
const v2 = { x: pos2.x + sx, y: pos2.y + sy }, v1 = { x: pos1.x - sx, y: pos1.y - sy };
|
|
106
|
+
batch.coords.push(pos1.x, pos1.y, v2.x, v2.y);
|
|
107
|
+
batch.coords.push(v1.x, v1.y, pos2.x, pos2.y);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
batch.coords.push(pos1.x, pos1.y, pos2.x, pos2.y);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
40
113
|
}
|
|
41
114
|
}
|
|
42
115
|
}
|
|
43
116
|
async init() {
|
|
44
|
-
this._freqs.links
|
|
45
|
-
this._freqs.triangles
|
|
117
|
+
this._freqs.links.clear();
|
|
118
|
+
this._freqs.triangles.clear();
|
|
119
|
+
this._colorCache.clear();
|
|
46
120
|
await Promise.resolve();
|
|
47
121
|
}
|
|
48
122
|
particleCreated(particle) {
|
|
@@ -50,124 +124,61 @@
|
|
|
50
124
|
if (!particle.options.links) {
|
|
51
125
|
return;
|
|
52
126
|
}
|
|
53
|
-
const ratio = this._container.retina.pixelRatio
|
|
54
|
-
retina.linksDistance = distance * ratio;
|
|
55
|
-
retina.linksWidth = width * ratio;
|
|
127
|
+
const ratio = this._container.retina.pixelRatio;
|
|
128
|
+
particle.retina.linksDistance = particle.options.links.distance * ratio;
|
|
129
|
+
particle.retina.linksWidth = particle.options.links.width * ratio;
|
|
56
130
|
}
|
|
57
131
|
particleDestroyed(particle) {
|
|
58
132
|
particle.links = [];
|
|
59
133
|
}
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
if (!
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const container = this._container, p2 = link.destination, pos1 = p1.getPosition(), pos2 = p2.getPosition();
|
|
66
|
-
let opacity = link.opacity;
|
|
67
|
-
container.canvas.draw(ctx => {
|
|
68
|
-
let colorLine;
|
|
69
|
-
const twinkle = p1.options["twinkle"]?.lines;
|
|
70
|
-
if (twinkle?.enable) {
|
|
71
|
-
const twinkleFreq = twinkle.frequency, twinkleRgb = (0, engine_1.rangeColorToRgb)(this._engine, twinkle.color), twinkling = (0, engine_1.getRandom)() < twinkleFreq;
|
|
72
|
-
if (twinkling && twinkleRgb) {
|
|
73
|
-
colorLine = twinkleRgb;
|
|
74
|
-
opacity = (0, engine_1.getRangeValue)(twinkle.opacity);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (!colorLine) {
|
|
78
|
-
const linkColor = p1LinksOptions.id !== undefined
|
|
79
|
-
? container.particles.linksColors.get(p1LinksOptions.id)
|
|
80
|
-
: container.particles.linksColor;
|
|
81
|
-
colorLine = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
82
|
-
}
|
|
83
|
-
if (!colorLine) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const width = p1.retina.linksWidth ?? minWidth, maxDistance = p1.retina.linksDistance ?? minDistance;
|
|
87
|
-
(0, Utils_js_1.drawLinkLine)({
|
|
88
|
-
context: ctx,
|
|
89
|
-
width,
|
|
90
|
-
begin: pos1,
|
|
91
|
-
end: pos2,
|
|
92
|
-
engine: this._engine,
|
|
93
|
-
maxDistance,
|
|
94
|
-
canvasSize: container.canvas.size,
|
|
95
|
-
links: p1LinksOptions,
|
|
96
|
-
colorLine,
|
|
97
|
-
opacity,
|
|
98
|
-
hdr: container.hdr,
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
_drawLinkTriangle = (p1, link1, link2) => {
|
|
103
|
-
const linksOptions = p1.options.links;
|
|
104
|
-
if (!linksOptions?.enable) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const triangleOptions = linksOptions.triangles;
|
|
108
|
-
if (!triangleOptions.enable) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const container = this._container, p2 = link1.destination, p3 = link2.destination, opacityTriangle = triangleOptions.opacity ?? (link1.opacity + link2.opacity) * engine_1.half;
|
|
112
|
-
if (opacityTriangle <= minOpacity) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
container.canvas.draw(ctx => {
|
|
116
|
-
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition(), linksDistance = p1.retina.linksDistance ?? minDistance;
|
|
117
|
-
if ((0, engine_1.getDistance)(pos1, pos2) > linksDistance ||
|
|
118
|
-
(0, engine_1.getDistance)(pos3, pos2) > linksDistance ||
|
|
119
|
-
(0, engine_1.getDistance)(pos3, pos1) > linksDistance) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
let colorTriangle = (0, engine_1.rangeColorToRgb)(this._engine, triangleOptions.color);
|
|
123
|
-
if (!colorTriangle) {
|
|
124
|
-
const linkColor = linksOptions.id !== undefined
|
|
125
|
-
? container.particles.linksColors.get(linksOptions.id)
|
|
126
|
-
: container.particles.linksColor;
|
|
127
|
-
colorTriangle = (0, engine_1.getLinkColor)(p1, p2, linkColor);
|
|
128
|
-
}
|
|
129
|
-
if (!colorTriangle) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
(0, Utils_js_1.drawLinkTriangle)({
|
|
133
|
-
context: ctx,
|
|
134
|
-
pos1,
|
|
135
|
-
pos2,
|
|
136
|
-
pos3,
|
|
137
|
-
colorTriangle,
|
|
138
|
-
opacityTriangle,
|
|
139
|
-
hdr: container.hdr,
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
_drawTriangles = (options, p1, link, p1Links) => {
|
|
144
|
-
const p2 = link.destination;
|
|
145
|
-
if (!(options.links?.triangles.enable && p2.options.links?.triangles.enable)) {
|
|
134
|
+
_collectTriangles(options, p1, link, p1Links) {
|
|
135
|
+
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
136
|
+
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
146
137
|
return;
|
|
147
138
|
}
|
|
148
139
|
const vertices = p2.links?.filter(t => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
p1Links.
|
|
140
|
+
return (!t.isWarped &&
|
|
141
|
+
p2.options.links &&
|
|
142
|
+
this._getLinkFrequency(p2, t.destination) <= p2.options.links.frequency &&
|
|
143
|
+
p1Links.some(l => l.destination === t.destination));
|
|
153
144
|
});
|
|
154
145
|
if (!vertices?.length) {
|
|
155
146
|
return;
|
|
156
147
|
}
|
|
157
148
|
for (const vertex of vertices) {
|
|
158
|
-
const p3 = vertex.destination
|
|
159
|
-
if (
|
|
149
|
+
const p3 = vertex.destination;
|
|
150
|
+
if (this._getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
160
151
|
continue;
|
|
161
152
|
}
|
|
162
|
-
|
|
153
|
+
const opacityTriangle = Math.ceil((link.opacity + vertex.opacity) * engine_1.half * opacitySteps) / opacitySteps, colorTriangle = (0, engine_1.rangeColorToRgb)(this._engine, triangleOptions.color) ?? link.color;
|
|
154
|
+
if (!colorTriangle) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const colorStyle = this._getCachedStyle(colorTriangle), key = `${colorStyle}_${opacityTriangle}`;
|
|
158
|
+
let batch = this._triangleBatches.get(key);
|
|
159
|
+
if (!batch) {
|
|
160
|
+
batch = { colorStyle, opacity: opacityTriangle, coords: [] };
|
|
161
|
+
this._triangleBatches.set(key, batch);
|
|
162
|
+
}
|
|
163
|
+
const pos1 = p1.getPosition(), pos2 = p2.getPosition(), pos3 = p3.getPosition();
|
|
164
|
+
batch.coords.push(pos1.x, pos1.y, pos2.x, pos2.y, pos3.x, pos3.y);
|
|
163
165
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
+
}
|
|
167
|
+
_getCachedStyle(rgb) {
|
|
168
|
+
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
169
|
+
let style = this._colorCache.get(key);
|
|
170
|
+
if (!style) {
|
|
171
|
+
style = (0, engine_1.getStyleFromRgb)(rgb, this._container.hdr);
|
|
172
|
+
this._colorCache.set(key, style);
|
|
173
|
+
}
|
|
174
|
+
return style;
|
|
175
|
+
}
|
|
176
|
+
_getLinkFrequency(p1, p2) {
|
|
166
177
|
return (0, Utils_js_1.setLinkFrequency)([p1, p2], this._freqs.links);
|
|
167
|
-
}
|
|
168
|
-
_getTriangleFrequency
|
|
178
|
+
}
|
|
179
|
+
_getTriangleFrequency(p1, p2, p3) {
|
|
169
180
|
return (0, Utils_js_1.setLinkFrequency)([p1, p2, p3], this._freqs.triangles);
|
|
170
|
-
}
|
|
181
|
+
}
|
|
171
182
|
}
|
|
172
183
|
exports.LinkInstance = LinkInstance;
|
|
173
184
|
});
|