@tsparticles/interaction-particles-attract 4.0.0-alpha.8 → 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.
Files changed (35) hide show
  1. package/356.min.js +1 -0
  2. package/README.md +5 -0
  3. package/browser/Attractor.js +27 -6
  4. package/browser/Options/Classes/Attract.js +35 -0
  5. package/browser/index.js +3 -3
  6. package/cjs/Attractor.js +27 -6
  7. package/cjs/Options/Classes/Attract.js +35 -0
  8. package/cjs/Types.js +1 -0
  9. package/cjs/index.js +3 -3
  10. package/dist_browser_Attractor_js.js +12 -2
  11. package/esm/Attractor.js +27 -6
  12. package/esm/Options/Classes/Attract.js +35 -0
  13. package/esm/Options/Interfaces/IAttract.js +1 -0
  14. package/esm/Types.js +1 -0
  15. package/esm/index.js +3 -3
  16. package/package.json +3 -3
  17. package/report.html +1 -1
  18. package/tsparticles.interaction.particles.attract.js +31 -19
  19. package/tsparticles.interaction.particles.attract.min.js +2 -2
  20. package/types/Attractor.d.ts +6 -3
  21. package/types/Options/Classes/Attract.d.ts +9 -0
  22. package/types/Options/Interfaces/IAttract.d.ts +6 -0
  23. package/types/Types.d.ts +13 -0
  24. package/umd/Attractor.js +27 -6
  25. package/umd/Options/Classes/Attract.js +49 -0
  26. package/umd/Types.js +12 -0
  27. package/umd/index.js +3 -3
  28. package/63.min.js +0 -2
  29. package/63.min.js.LICENSE.txt +0 -1
  30. package/tsparticles.interaction.particles.attract.min.js.LICENSE.txt +0 -1
  31. package/types/AttractParticle.d.ts +0 -4
  32. /package/browser/{AttractParticle.js → Options/Interfaces/IAttract.js} +0 -0
  33. /package/{cjs/AttractParticle.js → browser/Types.js} +0 -0
  34. /package/{esm/AttractParticle.js → cjs/Options/Interfaces/IAttract.js} +0 -0
  35. /package/umd/{AttractParticle.js → Options/Interfaces/IAttract.js} +0 -0
package/356.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_interaction_particles_attract=this.webpackChunk_tsparticles_interaction_particles_attract||[]).push([[356],{356(t,e,a){a.d(e,{Attractor:()=>c});var i=a(303);class s{distance;enable;rotate;constructor(){this.distance=200,this.enable=!1,this.rotate={x:3e3,y:3e3}}load(t){if(!(0,i.isNull)(t)&&(void 0!==t.distance&&(this.distance=(0,i.setRangeValue)(t.distance)),void 0!==t.enable&&(this.enable=t.enable),t.rotate)){let e=t.rotate.x;void 0!==e&&(this.rotate.x=e);let a=t.rotate.y;void 0!==a&&(this.rotate.y=a)}}}var r=a(702);class c extends r.ParticlesInteractorBase{_maxDistance;constructor(t){super(t),this._maxDistance=0}get maxDistance(){return this._maxDistance}clear(){}init(){}interact(t){if(!t.options.attract?.enable)return;let e=this.container;if((0,i.isNull)(t.attractDistance)){let a=(0,i.getRangeValue)(t.options.attract.distance);a>this._maxDistance&&(this._maxDistance=a),t.attractDistance=a*e.retina.pixelRatio}let a=t.attractDistance,s=t.getPosition();for(let r of e.particles.grid.queryCircle(s,a)){if(t===r||!r.options.attract?.enable||r.destroyed||r.spawning)continue;let e=r.getPosition(),{dx:a,dy:c}=(0,i.getDistances)(s,e),n=t.options.attract.rotate,o=a/(1e3*n.x),l=c/(1e3*n.y),d=r.size.value/t.size.value,u=1/d;t.velocity.x-=o*d,t.velocity.y-=l*d,r.velocity.x+=o*u,r.velocity.y+=l*u}}isEnabled(t){return t.options.attract?.enable??!1}loadParticlesOptions(t,...e){for(let a of(t.attract??=new s,e))t.attract.load(a?.attract)}reset(){}}}}]);
package/README.md CHANGED
@@ -27,6 +27,7 @@ Once the scripts are loaded you can set up `tsParticles` and the interaction plu
27
27
 
28
28
  ```javascript
29
29
  (async () => {
30
+ await loadInteractivityPlugin(tsParticles);
30
31
  await loadParticlesAttractInteraction(tsParticles);
31
32
 
32
33
  await tsParticles.load({
@@ -56,9 +57,11 @@ Then you need to import it in the app, like this:
56
57
 
57
58
  ```javascript
58
59
  const { tsParticles } = require("@tsparticles/engine");
60
+ const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
59
61
  const { loadParticlesAttractInteraction } = require("@tsparticles/interaction-particles-attract");
60
62
 
61
63
  (async () => {
64
+ await loadInteractivityPlugin(tsParticles);
62
65
  await loadParticlesAttractInteraction(tsParticles);
63
66
  })();
64
67
  ```
@@ -67,9 +70,11 @@ or
67
70
 
68
71
  ```javascript
69
72
  import { tsParticles } from "@tsparticles/engine";
73
+ import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
70
74
  import { loadParticlesAttractInteraction } from "@tsparticles/interaction-particles-attract";
71
75
 
72
76
  (async () => {
77
+ await loadInteractivityPlugin(tsParticles);
73
78
  await loadParticlesAttractInteraction(tsParticles);
74
79
  })();
75
80
  ```
@@ -1,23 +1,38 @@
1
- import { getDistances, getRangeValue } from "@tsparticles/engine";
1
+ import { getDistances, getRangeValue, isNull } from "@tsparticles/engine";
2
+ import { Attract } from "./Options/Classes/Attract.js";
2
3
  import { ParticlesInteractorBase } from "@tsparticles/plugin-interactivity";
3
4
  const attractFactor = 1000, identity = 1;
4
5
  export class Attractor extends ParticlesInteractorBase {
6
+ _maxDistance;
5
7
  constructor(container) {
6
8
  super(container);
9
+ this._maxDistance = 0;
10
+ }
11
+ get maxDistance() {
12
+ return this._maxDistance;
7
13
  }
8
14
  clear() {
9
15
  }
10
16
  init() {
11
17
  }
12
18
  interact(p1) {
19
+ if (!p1.options.attract?.enable) {
20
+ return;
21
+ }
13
22
  const container = this.container;
14
- p1.attractDistance ??= getRangeValue(p1.options.move.attract.distance) * container.retina.pixelRatio;
15
- const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
23
+ if (isNull(p1.attractDistance)) {
24
+ const attractDistance = getRangeValue(p1.options.attract.distance);
25
+ if (attractDistance > this._maxDistance) {
26
+ this._maxDistance = attractDistance;
27
+ }
28
+ p1.attractDistance = attractDistance * container.retina.pixelRatio;
29
+ }
30
+ const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, distance);
16
31
  for (const p2 of query) {
17
- if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
32
+ if (p1 === p2 || !p2.options.attract?.enable || p2.destroyed || p2.spawning) {
18
33
  continue;
19
34
  }
20
- const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
35
+ const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
21
36
  p1.velocity.x -= ax * p1Factor;
22
37
  p1.velocity.y -= ay * p1Factor;
23
38
  p2.velocity.x += ax * p2Factor;
@@ -25,7 +40,13 @@ export class Attractor extends ParticlesInteractorBase {
25
40
  }
26
41
  }
27
42
  isEnabled(particle) {
28
- return particle.options.move.attract.enable;
43
+ return particle.options.attract?.enable ?? false;
44
+ }
45
+ loadParticlesOptions(options, ...sources) {
46
+ options.attract ??= new Attract();
47
+ for (const source of sources) {
48
+ options.attract.load(source?.attract);
49
+ }
29
50
  }
30
51
  reset() {
31
52
  }
@@ -0,0 +1,35 @@
1
+ import { isNull, setRangeValue, } from "@tsparticles/engine";
2
+ export class Attract {
3
+ distance;
4
+ enable;
5
+ rotate;
6
+ constructor() {
7
+ this.distance = 200;
8
+ this.enable = false;
9
+ this.rotate = {
10
+ x: 3000,
11
+ y: 3000,
12
+ };
13
+ }
14
+ load(data) {
15
+ if (isNull(data)) {
16
+ return;
17
+ }
18
+ if (data.distance !== undefined) {
19
+ this.distance = setRangeValue(data.distance);
20
+ }
21
+ if (data.enable !== undefined) {
22
+ this.enable = data.enable;
23
+ }
24
+ if (data.rotate) {
25
+ const rotateX = data.rotate.x;
26
+ if (rotateX !== undefined) {
27
+ this.rotate.x = rotateX;
28
+ }
29
+ const rotateY = data.rotate.y;
30
+ if (rotateY !== undefined) {
31
+ this.rotate.y = rotateY;
32
+ }
33
+ }
34
+ }
35
+ }
package/browser/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export async function loadParticlesAttractInteraction(engine) {
2
- engine.checkVersion("4.0.0-alpha.8");
2
+ engine.checkVersion("4.0.0-beta.0");
3
3
  await engine.register(async (e) => {
4
- const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity");
5
- await loadInteractivityPlugin(e);
4
+ const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
5
+ ensureInteractivityPluginLoaded(e);
6
6
  e.addInteractor?.("particlesAttract", async (container) => {
7
7
  const { Attractor } = await import("./Attractor.js");
8
8
  return new Attractor(container);
package/cjs/Attractor.js CHANGED
@@ -1,23 +1,38 @@
1
- import { getDistances, getRangeValue } from "@tsparticles/engine";
1
+ import { getDistances, getRangeValue, isNull } from "@tsparticles/engine";
2
+ import { Attract } from "./Options/Classes/Attract.js";
2
3
  import { ParticlesInteractorBase } from "@tsparticles/plugin-interactivity";
3
4
  const attractFactor = 1000, identity = 1;
4
5
  export class Attractor extends ParticlesInteractorBase {
6
+ _maxDistance;
5
7
  constructor(container) {
6
8
  super(container);
9
+ this._maxDistance = 0;
10
+ }
11
+ get maxDistance() {
12
+ return this._maxDistance;
7
13
  }
8
14
  clear() {
9
15
  }
10
16
  init() {
11
17
  }
12
18
  interact(p1) {
19
+ if (!p1.options.attract?.enable) {
20
+ return;
21
+ }
13
22
  const container = this.container;
14
- p1.attractDistance ??= getRangeValue(p1.options.move.attract.distance) * container.retina.pixelRatio;
15
- const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
23
+ if (isNull(p1.attractDistance)) {
24
+ const attractDistance = getRangeValue(p1.options.attract.distance);
25
+ if (attractDistance > this._maxDistance) {
26
+ this._maxDistance = attractDistance;
27
+ }
28
+ p1.attractDistance = attractDistance * container.retina.pixelRatio;
29
+ }
30
+ const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, distance);
16
31
  for (const p2 of query) {
17
- if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
32
+ if (p1 === p2 || !p2.options.attract?.enable || p2.destroyed || p2.spawning) {
18
33
  continue;
19
34
  }
20
- const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
35
+ const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
21
36
  p1.velocity.x -= ax * p1Factor;
22
37
  p1.velocity.y -= ay * p1Factor;
23
38
  p2.velocity.x += ax * p2Factor;
@@ -25,7 +40,13 @@ export class Attractor extends ParticlesInteractorBase {
25
40
  }
26
41
  }
27
42
  isEnabled(particle) {
28
- return particle.options.move.attract.enable;
43
+ return particle.options.attract?.enable ?? false;
44
+ }
45
+ loadParticlesOptions(options, ...sources) {
46
+ options.attract ??= new Attract();
47
+ for (const source of sources) {
48
+ options.attract.load(source?.attract);
49
+ }
29
50
  }
30
51
  reset() {
31
52
  }
@@ -0,0 +1,35 @@
1
+ import { isNull, setRangeValue, } from "@tsparticles/engine";
2
+ export class Attract {
3
+ distance;
4
+ enable;
5
+ rotate;
6
+ constructor() {
7
+ this.distance = 200;
8
+ this.enable = false;
9
+ this.rotate = {
10
+ x: 3000,
11
+ y: 3000,
12
+ };
13
+ }
14
+ load(data) {
15
+ if (isNull(data)) {
16
+ return;
17
+ }
18
+ if (data.distance !== undefined) {
19
+ this.distance = setRangeValue(data.distance);
20
+ }
21
+ if (data.enable !== undefined) {
22
+ this.enable = data.enable;
23
+ }
24
+ if (data.rotate) {
25
+ const rotateX = data.rotate.x;
26
+ if (rotateX !== undefined) {
27
+ this.rotate.x = rotateX;
28
+ }
29
+ const rotateY = data.rotate.y;
30
+ if (rotateY !== undefined) {
31
+ this.rotate.y = rotateY;
32
+ }
33
+ }
34
+ }
35
+ }
package/cjs/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/cjs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export async function loadParticlesAttractInteraction(engine) {
2
- engine.checkVersion("4.0.0-alpha.8");
2
+ engine.checkVersion("4.0.0-beta.0");
3
3
  await engine.register(async (e) => {
4
- const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity");
5
- await loadInteractivityPlugin(e);
4
+ const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
5
+ ensureInteractivityPluginLoaded(e);
6
6
  e.addInteractor?.("particlesAttract", async (container) => {
7
7
  const { Attractor } = await import("./Attractor.js");
8
8
  return new Attractor(container);
@@ -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.8
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  "use strict";
10
10
  /*
@@ -23,7 +23,17 @@
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 */ Attractor: () => (/* binding */ Attractor)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n\n\nconst attractFactor = 1000,\n identity = 1;\nclass Attractor extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.ParticlesInteractorBase {\n constructor(container) {\n super(container);\n }\n clear() {}\n init() {}\n interact(p1) {\n const container = this.container;\n p1.attractDistance ??= (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(p1.options.move.attract.distance) * container.retina.pixelRatio;\n const distance = p1.attractDistance,\n pos1 = p1.getPosition(),\n query = container.particles.quadTree.queryCircle(pos1, distance);\n for (const p2 of query) {\n if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {\n continue;\n }\n const pos2 = p2.getPosition(),\n {\n dx,\n dy\n } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(pos1, pos2),\n rotate = p1.options.move.attract.rotate,\n ax = dx / (rotate.x * attractFactor),\n ay = dy / (rotate.y * attractFactor),\n p1Factor = p2.size.value / p1.size.value,\n p2Factor = identity / p1Factor;\n p1.velocity.x -= ax * p1Factor;\n p1.velocity.y -= ay * p1Factor;\n p2.velocity.x += ax * p2Factor;\n p2.velocity.y += ay * p2Factor;\n }\n }\n isEnabled(particle) {\n return particle.options.move.attract.enable;\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-attract/./dist/browser/Attractor.js?\n}");
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Attractor: () => (/* binding */ Attractor)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Attract.js */ \"./dist/browser/Options/Classes/Attract.js\");\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n\n\n\nconst attractFactor = 1000, identity = 1;\nclass Attractor extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_2__.ParticlesInteractorBase {\n _maxDistance;\n constructor(container){\n super(container);\n this._maxDistance = 0;\n }\n get maxDistance() {\n return this._maxDistance;\n }\n clear() {}\n init() {}\n interact(p1) {\n if (!p1.options.attract?.enable) {\n return;\n }\n const container = this.container;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(p1.attractDistance)) {\n const attractDistance = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(p1.options.attract.distance);\n if (attractDistance > this._maxDistance) {\n this._maxDistance = attractDistance;\n }\n p1.attractDistance = attractDistance * container.retina.pixelRatio;\n }\n const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, distance);\n for (const p2 of query){\n if (p1 === p2 || !p2.options.attract?.enable || p2.destroyed || p2.spawning) {\n continue;\n }\n const pos2 = p2.getPosition(), { dx, dy } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(pos1, pos2), rotate = p1.options.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;\n p1.velocity.x -= ax * p1Factor;\n p1.velocity.y -= ay * p1Factor;\n p2.velocity.x += ax * p2Factor;\n p2.velocity.y += ay * p2Factor;\n }\n }\n isEnabled(particle) {\n return particle.options.attract?.enable ?? false;\n }\n loadParticlesOptions(options, ...sources) {\n options.attract ??= new _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_1__.Attract();\n for (const source of sources){\n options.attract.load(source?.attract);\n }\n }\n reset() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-attract/./dist/browser/Attractor.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Options/Classes/Attract.js"
31
+ /*!*************************************************!*\
32
+ !*** ./dist/browser/Options/Classes/Attract.js ***!
33
+ \*************************************************/
34
+ (__unused_webpack___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 */ Attract: () => (/* binding */ Attract)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass Attract {\n distance;\n enable;\n rotate;\n constructor(){\n this.distance = 200;\n this.enable = false;\n this.rotate = {\n x: 3000,\n y: 3000\n };\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.distance !== undefined) {\n this.distance = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.distance);\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n if (data.rotate) {\n const rotateX = data.rotate.x;\n if (rotateX !== undefined) {\n this.rotate.x = rotateX;\n }\n const rotateY = data.rotate.y;\n if (rotateY !== undefined) {\n this.rotate.y = rotateY;\n }\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-attract/./dist/browser/Options/Classes/Attract.js?\n}");
27
37
 
28
38
  /***/ }
29
39
 
package/esm/Attractor.js CHANGED
@@ -1,23 +1,38 @@
1
- import { getDistances, getRangeValue } from "@tsparticles/engine";
1
+ import { getDistances, getRangeValue, isNull } from "@tsparticles/engine";
2
+ import { Attract } from "./Options/Classes/Attract.js";
2
3
  import { ParticlesInteractorBase } from "@tsparticles/plugin-interactivity";
3
4
  const attractFactor = 1000, identity = 1;
4
5
  export class Attractor extends ParticlesInteractorBase {
6
+ _maxDistance;
5
7
  constructor(container) {
6
8
  super(container);
9
+ this._maxDistance = 0;
10
+ }
11
+ get maxDistance() {
12
+ return this._maxDistance;
7
13
  }
8
14
  clear() {
9
15
  }
10
16
  init() {
11
17
  }
12
18
  interact(p1) {
19
+ if (!p1.options.attract?.enable) {
20
+ return;
21
+ }
13
22
  const container = this.container;
14
- p1.attractDistance ??= getRangeValue(p1.options.move.attract.distance) * container.retina.pixelRatio;
15
- const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
23
+ if (isNull(p1.attractDistance)) {
24
+ const attractDistance = getRangeValue(p1.options.attract.distance);
25
+ if (attractDistance > this._maxDistance) {
26
+ this._maxDistance = attractDistance;
27
+ }
28
+ p1.attractDistance = attractDistance * container.retina.pixelRatio;
29
+ }
30
+ const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, distance);
16
31
  for (const p2 of query) {
17
- if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
32
+ if (p1 === p2 || !p2.options.attract?.enable || p2.destroyed || p2.spawning) {
18
33
  continue;
19
34
  }
20
- const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
35
+ const pos2 = p2.getPosition(), { dx, dy } = getDistances(pos1, pos2), rotate = p1.options.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
21
36
  p1.velocity.x -= ax * p1Factor;
22
37
  p1.velocity.y -= ay * p1Factor;
23
38
  p2.velocity.x += ax * p2Factor;
@@ -25,7 +40,13 @@ export class Attractor extends ParticlesInteractorBase {
25
40
  }
26
41
  }
27
42
  isEnabled(particle) {
28
- return particle.options.move.attract.enable;
43
+ return particle.options.attract?.enable ?? false;
44
+ }
45
+ loadParticlesOptions(options, ...sources) {
46
+ options.attract ??= new Attract();
47
+ for (const source of sources) {
48
+ options.attract.load(source?.attract);
49
+ }
29
50
  }
30
51
  reset() {
31
52
  }
@@ -0,0 +1,35 @@
1
+ import { isNull, setRangeValue, } from "@tsparticles/engine";
2
+ export class Attract {
3
+ distance;
4
+ enable;
5
+ rotate;
6
+ constructor() {
7
+ this.distance = 200;
8
+ this.enable = false;
9
+ this.rotate = {
10
+ x: 3000,
11
+ y: 3000,
12
+ };
13
+ }
14
+ load(data) {
15
+ if (isNull(data)) {
16
+ return;
17
+ }
18
+ if (data.distance !== undefined) {
19
+ this.distance = setRangeValue(data.distance);
20
+ }
21
+ if (data.enable !== undefined) {
22
+ this.enable = data.enable;
23
+ }
24
+ if (data.rotate) {
25
+ const rotateX = data.rotate.x;
26
+ if (rotateX !== undefined) {
27
+ this.rotate.x = rotateX;
28
+ }
29
+ const rotateY = data.rotate.y;
30
+ if (rotateY !== undefined) {
31
+ this.rotate.y = rotateY;
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ export {};
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  export async function loadParticlesAttractInteraction(engine) {
2
- engine.checkVersion("4.0.0-alpha.8");
2
+ engine.checkVersion("4.0.0-beta.0");
3
3
  await engine.register(async (e) => {
4
- const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity");
5
- await loadInteractivityPlugin(e);
4
+ const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
5
+ ensureInteractivityPluginLoaded(e);
6
6
  e.addInteractor?.("particlesAttract", async (container) => {
7
7
  const { Attractor } = await import("./Attractor.js");
8
8
  return new Attractor(container);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/interaction-particles-attract",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "tsParticles attract particles interaction",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -87,8 +87,8 @@
87
87
  "./package.json": "./package.json"
88
88
  },
89
89
  "dependencies": {
90
- "@tsparticles/engine": "4.0.0-alpha.8",
91
- "@tsparticles/plugin-interactivity": "4.0.0-alpha.8"
90
+ "@tsparticles/engine": "4.0.0-beta.0",
91
+ "@tsparticles/plugin-interactivity": "4.0.0-beta.0"
92
92
  },
93
93
  "publishConfig": {
94
94
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/interaction-particles-attract [23 Jan 2026 at 23:54]</title>
6
+ <title>@tsparticles/interaction-particles-attract [19 Mar 2026 at 14:00]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -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.8
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  /*
10
10
  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
@@ -28,16 +28,6 @@ return /******/ (() => { // webpackBootstrap
28
28
  /******/ "use strict";
29
29
  /******/ var __webpack_modules__ = ({
30
30
 
31
- /***/ "./dist/browser/index.js"
32
- /*!*******************************!*\
33
- !*** ./dist/browser/index.js ***!
34
- \*******************************/
35
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
36
-
37
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadParticlesAttractInteraction: () => (/* binding */ loadParticlesAttractInteraction)\n/* harmony export */ });\nasync function loadParticlesAttractInteraction(engine) {\n engine.checkVersion(\"4.0.0-alpha.8\");\n await engine.register(async e => {\n const {\n loadInteractivityPlugin\n } = await Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\", 19));\n await loadInteractivityPlugin(e);\n e.addInteractor?.(\"particlesAttract\", async container => {\n const {\n Attractor\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_Attractor_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./Attractor.js */ \"./dist/browser/Attractor.js\"));\n return new Attractor(container);\n });\n });\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-attract/./dist/browser/index.js?\n}");
38
-
39
- /***/ },
40
-
41
31
  /***/ "@tsparticles/engine"
42
32
  /*!*********************************************************************************************************************************!*\
43
33
  !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
@@ -56,6 +46,16 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
56
46
 
57
47
  module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__;
58
48
 
49
+ /***/ },
50
+
51
+ /***/ "./dist/browser/index.js"
52
+ /*!*******************************!*\
53
+ !*** ./dist/browser/index.js ***!
54
+ \*******************************/
55
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
56
+
57
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadParticlesAttractInteraction: () => (/* binding */ loadParticlesAttractInteraction)\n/* harmony export */ });\nasync function loadParticlesAttractInteraction(engine) {\n engine.checkVersion(\"4.0.0-beta.0\");\n await engine.register(async (e)=>{\n const { ensureInteractivityPluginLoaded } = await Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\", 19));\n ensureInteractivityPluginLoaded(e);\n e.addInteractor?.(\"particlesAttract\", async (container)=>{\n const { Attractor } = await __webpack_require__.e(/*! import() */ \"dist_browser_Attractor_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./Attractor.js */ \"./dist/browser/Attractor.js\"));\n return new Attractor(container);\n });\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-particles-attract/./dist/browser/index.js?\n}");
58
+
59
59
  /***/ }
60
60
 
61
61
  /******/ });
@@ -70,12 +70,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__;
70
70
  /******/ if (cachedModule !== undefined) {
71
71
  /******/ return cachedModule.exports;
72
72
  /******/ }
73
- /******/ // Check if module exists (development only)
74
- /******/ if (__webpack_modules__[moduleId] === undefined) {
75
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
76
- /******/ e.code = 'MODULE_NOT_FOUND';
77
- /******/ throw e;
78
- /******/ }
79
73
  /******/ // Create a new module (and put it into the cache)
80
74
  /******/ var module = __webpack_module_cache__[moduleId] = {
81
75
  /******/ // no module.id needed
@@ -84,6 +78,12 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__;
84
78
  /******/ };
85
79
  /******/
86
80
  /******/ // Execute the module function
81
+ /******/ if (!(moduleId in __webpack_modules__)) {
82
+ /******/ delete __webpack_module_cache__[moduleId];
83
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
84
+ /******/ e.code = 'MODULE_NOT_FOUND';
85
+ /******/ throw e;
86
+ /******/ }
87
87
  /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
88
88
  /******/
89
89
  /******/ // Return the exports of the module
@@ -158,6 +158,18 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__;
158
158
  /******/ };
159
159
  /******/ })();
160
160
  /******/
161
+ /******/ /* webpack/runtime/global */
162
+ /******/ (() => {
163
+ /******/ __webpack_require__.g = (function() {
164
+ /******/ if (typeof globalThis === 'object') return globalThis;
165
+ /******/ try {
166
+ /******/ return this || new Function('return this')();
167
+ /******/ } catch (e) {
168
+ /******/ if (typeof window === 'object') return window;
169
+ /******/ }
170
+ /******/ })();
171
+ /******/ })();
172
+ /******/
161
173
  /******/ /* webpack/runtime/hasOwnProperty shorthand */
162
174
  /******/ (() => {
163
175
  /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
@@ -222,8 +234,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__;
222
234
  /******/ /* webpack/runtime/publicPath */
223
235
  /******/ (() => {
224
236
  /******/ var scriptUrl;
225
- /******/ if (globalThis.importScripts) scriptUrl = globalThis.location + "";
226
- /******/ var document = globalThis.document;
237
+ /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
238
+ /******/ var document = __webpack_require__.g.document;
227
239
  /******/ if (!scriptUrl && document) {
228
240
  /******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
229
241
  /******/ scriptUrl = document.currentScript.src;
@@ -1,2 +1,2 @@
1
- /*! For license information please see tsparticles.interaction.particles.attract.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-interactivity","@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine")):t(e.window,e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,((e,t)=>(()=>{var r,i,o,a,n={303(e){e.exports=t},702(t){t.exports=e}},c={};function s(e){var t=c[e];if(void 0!==t)return t.exports;var r=c[e]={exports:{}};return n[e](r,r.exports,s),r.exports}s.m=n,i=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,s.t=function(e,t){if(1&t&&(e=this(e)),8&t)return e;if("object"==typeof e&&e){if(4&t&&e.__esModule)return e;if(16&t&&"function"==typeof e.then)return e}var o=Object.create(null);s.r(o);var a={};r=r||[null,i({}),i([]),i(i)];for(var n=2&t&&e;("object"==typeof n||"function"==typeof n)&&!~r.indexOf(n);n=i(n))Object.getOwnPropertyNames(n).forEach((t=>a[t]=()=>e[t]));return a.default=()=>e,s.d(o,a),o},s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.f={},s.e=e=>Promise.all(Object.keys(s.f).reduce(((t,r)=>(s.f[r](e,t),t)),[])),s.u=e=>e+".min.js",s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o={},a="@tsparticles/interaction-particles-attract:",s.l=(e,t,r,i)=>{if(o[e])o[e].push(t);else{var n,c;if(void 0!==r)for(var l=document.getElementsByTagName("script"),p=0;p<l.length;p++){var u=l[p];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==a+r){n=u;break}}n||(c=!0,(n=document.createElement("script")).charset="utf-8",s.nc&&n.setAttribute("nonce",s.nc),n.setAttribute("data-webpack",a+r),n.src=e),o[e]=[t];var f=(t,r)=>{n.onerror=n.onload=null,clearTimeout(d);var i=o[e];if(delete o[e],n.parentNode&&n.parentNode.removeChild(n),i&&i.forEach((e=>e(r))),t)return t(r)},d=setTimeout(f.bind(null,void 0,{type:"timeout",target:n}),12e4);n.onerror=f.bind(null,n.onerror),n.onload=f.bind(null,n.onload),c&&document.head.appendChild(n)}},s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var t=globalThis.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!e||!/^http(s?):/.test(e));)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})(),(()=>{var e={807:0};s.f.j=(t,r)=>{var i=s.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var o=new Promise(((r,o)=>i=e[t]=[r,o]));r.push(i[2]=o);var a=s.p+s.u(t),n=new Error;s.l(a,(r=>{if(s.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var o=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;n.message="Loading chunk "+t+" failed.\n("+o+": "+a+")",n.name="ChunkLoadError",n.type=o,n.request=a,i[1](n)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,o,[a,n,c]=r,l=0;if(a.some((t=>0!==e[t]))){for(i in n)s.o(n,i)&&(s.m[i]=n[i]);if(c)c(s)}for(t&&t(r);l<a.length;l++)o=a[l],s.o(e,o)&&e[o]&&e[o][0](),e[o]=0},r=this.webpackChunk_tsparticles_interaction_particles_attract=this.webpackChunk_tsparticles_interaction_particles_attract||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var l={};async function p(e){e.checkVersion("4.0.0-alpha.8"),await e.register((async e=>{const{loadInteractivityPlugin:t}=await Promise.resolve().then(s.t.bind(s,702,19));await t(e),e.addInteractor?.("particlesAttract",(async e=>{const{Attractor:t}=await s.e(63).then(s.bind(s,63));return new t(e)}))}))}return s.r(l),s.d(l,{loadParticlesAttractInteraction:()=>p}),l})()));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-interactivity","@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine")):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(e){e.exports=t},702(t){t.exports=e}},a={};function c(e){var t=a[e];if(void 0!==t)return t.exports;var r=a[e]={exports:{}};return n[e](r,r.exports,c),r.exports}c.m=n,p=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,c.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);c.r(r);var i={};s=s||[null,p({}),p([]),p(p)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~s.indexOf(o);o=p(o))Object.getOwnPropertyNames(o).forEach(t=>i[t]=()=>e[t]);return i.default=()=>e,c.d(r,i),r},c.d=(e,t)=>{for(var r in t)c.o(t,r)&&!c.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},c.f={},c.e=e=>Promise.all(Object.keys(c.f).reduce((t,r)=>(c.f[r](e,t),t),[])),c.u=e=>""+e+".min.js",c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l={},c.l=(e,t,r,i)=>{if(l[e])return void l[e].push(t);if(void 0!==r)for(var o,n,a=document.getElementsByTagName("script"),s=0;s<a.length;s++){var p=a[s];if(p.getAttribute("src")==e||p.getAttribute("data-webpack")=="@tsparticles/interaction-particles-attract:"+r){o=p;break}}o||(n=!0,(o=document.createElement("script")).charset="utf-8",c.nc&&o.setAttribute("nonce",c.nc),o.setAttribute("data-webpack","@tsparticles/interaction-particles-attract:"+r),o.src=e),l[e]=[t];var u=(t,r)=>{o.onerror=o.onload=null,clearTimeout(f);var i=l[e];if(delete l[e],o.parentNode&&o.parentNode.removeChild(o),i&&i.forEach(e=>e(r)),t)return t(r)},f=setTimeout(u.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=u.bind(null,o.onerror),o.onload=u.bind(null,o.onload),n&&document.head.appendChild(o)},c.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.g.importScripts&&(u=c.g.location+"");var s,p,l,u,f=c.g.document;if(!u&&f&&(f.currentScript&&"SCRIPT"===f.currentScript.tagName.toUpperCase()&&(u=f.currentScript.src),!u)){var d=f.getElementsByTagName("script");if(d.length)for(var b=d.length-1;b>-1&&(!u||!/^http(s?):/.test(u));)u=d[b--].src}if(!u)throw Error("Automatic publicPath is not supported in this browser");c.p=u=u.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={807:0},c.f.j=(e,t)=>{var i=c.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=c.p+c.u(e),a=Error();c.l(n,t=>{if(c.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;a.message="Loading chunk "+e+` failed.
2
+ (`+o+": "+n+")",a.name="ChunkLoadError",a.type=o,a.request=n,i[1](a)}},"chunk-"+e,e)}},i=(e,t)=>{var i,o,[n,a,s]=t,p=0;if(n.some(e=>0!==r[e])){for(i in a)c.o(a,i)&&(c.m[i]=a[i]);s&&s(c)}for(e&&e(t);p<n.length;p++)o=n[p],c.o(r,o)&&r[o]&&r[o][0](),r[o]=0},(o=this.webpackChunk_tsparticles_interaction_particles_attract=this.webpackChunk_tsparticles_interaction_particles_attract||[]).forEach(i.bind(null,0)),o.push=i.bind(null,o.push.bind(o));var h={};async function g(e){e.checkVersion("4.0.0-beta.0"),await e.register(async e=>{let{ensureInteractivityPluginLoaded:t}=await Promise.resolve().then(c.t.bind(c,702,19));t(e),e.addInteractor?.("particlesAttract",async e=>{let{Attractor:t}=await c.e(356).then(c.bind(c,356));return new t(e)})})}return c.r(h),c.d(h,{loadParticlesAttractInteraction:()=>g}),h})());
@@ -1,11 +1,14 @@
1
- import { type Container, type Particle } from "@tsparticles/engine";
2
- import type { AttractParticle } from "./AttractParticle.js";
1
+ import type { AttractParticle, IParticlesAttractOptions, ParticlesAttractOptions } from "./Types.js";
2
+ import { type Container, type RecursivePartial } from "@tsparticles/engine";
3
3
  import { ParticlesInteractorBase } from "@tsparticles/plugin-interactivity";
4
4
  export declare class Attractor extends ParticlesInteractorBase<Container, AttractParticle> {
5
+ private _maxDistance;
5
6
  constructor(container: Container);
7
+ get maxDistance(): number;
6
8
  clear(): void;
7
9
  init(): void;
8
10
  interact(p1: AttractParticle): void;
9
- isEnabled(particle: Particle): boolean;
11
+ isEnabled(particle: AttractParticle): boolean;
12
+ loadParticlesOptions(options: ParticlesAttractOptions, ...sources: (RecursivePartial<IParticlesAttractOptions> | undefined)[]): void;
10
13
  reset(): void;
11
14
  }
@@ -0,0 +1,9 @@
1
+ import { type ICoordinates, type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
2
+ import type { IAttract } from "../Interfaces/IAttract.js";
3
+ export declare class Attract implements IAttract, IOptionLoader<IAttract> {
4
+ distance: RangeValue;
5
+ enable: boolean;
6
+ rotate: ICoordinates;
7
+ constructor();
8
+ load(data?: RecursivePartial<IAttract>): void;
9
+ }
@@ -0,0 +1,6 @@
1
+ import type { ICoordinates, RangeValue } from "@tsparticles/engine";
2
+ export interface IAttract {
3
+ distance: RangeValue;
4
+ enable: boolean;
5
+ rotate: ICoordinates;
6
+ }
@@ -0,0 +1,13 @@
1
+ import type { IInteractivityParticlesOptions, InteractivityParticle, InteractivityParticlesOptions } from "@tsparticles/plugin-interactivity";
2
+ import type { Attract } from "./Options/Classes/Attract.js";
3
+ import type { IAttract } from "./Options/Interfaces/IAttract.js";
4
+ export type IParticlesAttractOptions = IInteractivityParticlesOptions & {
5
+ attract?: IAttract;
6
+ };
7
+ export type ParticlesAttractOptions = InteractivityParticlesOptions & {
8
+ attract?: Attract;
9
+ };
10
+ export type AttractParticle = InteractivityParticle & {
11
+ attractDistance?: number;
12
+ options: ParticlesAttractOptions;
13
+ };
package/umd/Attractor.js CHANGED
@@ -4,32 +4,47 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "@tsparticles/plugin-interactivity"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Attract.js", "@tsparticles/plugin-interactivity"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Attractor = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
+ const Attract_js_1 = require("./Options/Classes/Attract.js");
14
15
  const plugin_interactivity_1 = require("@tsparticles/plugin-interactivity");
15
16
  const attractFactor = 1000, identity = 1;
16
17
  class Attractor extends plugin_interactivity_1.ParticlesInteractorBase {
18
+ _maxDistance;
17
19
  constructor(container) {
18
20
  super(container);
21
+ this._maxDistance = 0;
22
+ }
23
+ get maxDistance() {
24
+ return this._maxDistance;
19
25
  }
20
26
  clear() {
21
27
  }
22
28
  init() {
23
29
  }
24
30
  interact(p1) {
31
+ if (!p1.options.attract?.enable) {
32
+ return;
33
+ }
25
34
  const container = this.container;
26
- p1.attractDistance ??= (0, engine_1.getRangeValue)(p1.options.move.attract.distance) * container.retina.pixelRatio;
27
- const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
35
+ if ((0, engine_1.isNull)(p1.attractDistance)) {
36
+ const attractDistance = (0, engine_1.getRangeValue)(p1.options.attract.distance);
37
+ if (attractDistance > this._maxDistance) {
38
+ this._maxDistance = attractDistance;
39
+ }
40
+ p1.attractDistance = attractDistance * container.retina.pixelRatio;
41
+ }
42
+ const distance = p1.attractDistance, pos1 = p1.getPosition(), query = container.particles.grid.queryCircle(pos1, distance);
28
43
  for (const p2 of query) {
29
- if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
44
+ if (p1 === p2 || !p2.options.attract?.enable || p2.destroyed || p2.spawning) {
30
45
  continue;
31
46
  }
32
- const pos2 = p2.getPosition(), { dx, dy } = (0, engine_1.getDistances)(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
47
+ const pos2 = p2.getPosition(), { dx, dy } = (0, engine_1.getDistances)(pos1, pos2), rotate = p1.options.attract.rotate, ax = dx / (rotate.x * attractFactor), ay = dy / (rotate.y * attractFactor), p1Factor = p2.size.value / p1.size.value, p2Factor = identity / p1Factor;
33
48
  p1.velocity.x -= ax * p1Factor;
34
49
  p1.velocity.y -= ay * p1Factor;
35
50
  p2.velocity.x += ax * p2Factor;
@@ -37,7 +52,13 @@
37
52
  }
38
53
  }
39
54
  isEnabled(particle) {
40
- return particle.options.move.attract.enable;
55
+ return particle.options.attract?.enable ?? false;
56
+ }
57
+ loadParticlesOptions(options, ...sources) {
58
+ options.attract ??= new Attract_js_1.Attract();
59
+ for (const source of sources) {
60
+ options.attract.load(source?.attract);
61
+ }
41
62
  }
42
63
  reset() {
43
64
  }
@@ -0,0 +1,49 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Attract = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class Attract {
15
+ distance;
16
+ enable;
17
+ rotate;
18
+ constructor() {
19
+ this.distance = 200;
20
+ this.enable = false;
21
+ this.rotate = {
22
+ x: 3000,
23
+ y: 3000,
24
+ };
25
+ }
26
+ load(data) {
27
+ if ((0, engine_1.isNull)(data)) {
28
+ return;
29
+ }
30
+ if (data.distance !== undefined) {
31
+ this.distance = (0, engine_1.setRangeValue)(data.distance);
32
+ }
33
+ if (data.enable !== undefined) {
34
+ this.enable = data.enable;
35
+ }
36
+ if (data.rotate) {
37
+ const rotateX = data.rotate.x;
38
+ if (rotateX !== undefined) {
39
+ this.rotate.x = rotateX;
40
+ }
41
+ const rotateY = data.rotate.y;
42
+ if (rotateY !== undefined) {
43
+ this.rotate.y = rotateY;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ exports.Attract = Attract;
49
+ });
package/umd/Types.js ADDED
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/index.js CHANGED
@@ -45,10 +45,10 @@ var __importStar = (this && this.__importStar) || (function () {
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.loadParticlesAttractInteraction = loadParticlesAttractInteraction;
47
47
  async function loadParticlesAttractInteraction(engine) {
48
- engine.checkVersion("4.0.0-alpha.8");
48
+ engine.checkVersion("4.0.0-beta.0");
49
49
  await engine.register(async (e) => {
50
- const { loadInteractivityPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("@tsparticles/plugin-interactivity"))) : new Promise((resolve_1, reject_1) => { require(["@tsparticles/plugin-interactivity"], resolve_1, reject_1); }).then(__importStar));
51
- await loadInteractivityPlugin(e);
50
+ const { ensureInteractivityPluginLoaded } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("@tsparticles/plugin-interactivity"))) : new Promise((resolve_1, reject_1) => { require(["@tsparticles/plugin-interactivity"], resolve_1, reject_1); }).then(__importStar));
51
+ ensureInteractivityPluginLoaded(e);
52
52
  e.addInteractor?.("particlesAttract", async (container) => {
53
53
  const { Attractor } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Attractor.js"))) : new Promise((resolve_2, reject_2) => { require(["./Attractor.js"], resolve_2, reject_2); }).then(__importStar));
54
54
  return new Attractor(container);
package/63.min.js DELETED
@@ -1,2 +0,0 @@
1
- /*! For license information please see 63.min.js.LICENSE.txt */
2
- (this.webpackChunk_tsparticles_interaction_particles_attract=this.webpackChunk_tsparticles_interaction_particles_attract||[]).push([[63],{63(t,e,a){a.d(e,{Attractor:()=>s});var i=a(303),c=a(702);class s extends c.ParticlesInteractorBase{constructor(t){super(t)}clear(){}init(){}interact(t){const e=this.container;t.attractDistance??=(0,i.getRangeValue)(t.options.move.attract.distance)*e.retina.pixelRatio;const a=t.attractDistance,c=t.getPosition(),s=e.particles.quadTree.queryCircle(c,a);for(const e of s){if(t===e||!e.options.move.attract.enable||e.destroyed||e.spawning)continue;const a=e.getPosition(),{dx:s,dy:n}=(0,i.getDistances)(c,a),o=t.options.move.attract.rotate,r=s/(1e3*o.x),l=n/(1e3*o.y),p=e.size.value/t.size.value,u=1/p;t.velocity.x-=r*p,t.velocity.y-=l*p,e.velocity.x+=r*u,e.velocity.y+=l*u}}isEnabled(t){return t.options.move.attract.enable}reset(){}}}}]);
@@ -1 +0,0 @@
1
- /*! tsParticles Attract Particles Interaction v4.0.0-alpha.8 by Matteo Bruni */
@@ -1 +0,0 @@
1
- /*! tsParticles Attract Particles Interaction v4.0.0-alpha.8 by Matteo Bruni */
@@ -1,4 +0,0 @@
1
- import type { InteractivityParticle } from "@tsparticles/plugin-interactivity";
2
- export interface AttractParticle extends InteractivityParticle {
3
- attractDistance?: number;
4
- }
File without changes