@tsparticles/interaction-external-attract 4.0.0-alpha.3 → 4.0.0-alpha.5
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/689.min.js +2 -0
- package/689.min.js.LICENSE.txt +1 -0
- package/browser/Attractor.js +17 -12
- package/browser/Utils.js +7 -7
- package/browser/index.js +6 -4
- package/cjs/Attractor.js +17 -12
- package/cjs/Utils.js +7 -7
- package/cjs/index.js +6 -4
- package/dist_browser_Attractor_js.js +3 -3
- package/esm/Attractor.js +17 -12
- package/esm/Utils.js +7 -7
- package/esm/index.js +6 -4
- package/package.json +3 -2
- package/report.html +1 -1
- package/tsparticles.interaction.external.attract.js +48 -20
- package/tsparticles.interaction.external.attract.min.js +1 -1
- package/tsparticles.interaction.external.attract.min.js.LICENSE.txt +1 -1
- package/types/Attractor.d.ts +5 -4
- package/types/Options/Classes/AttractOptions.d.ts +3 -3
- package/types/Types.d.ts +3 -3
- package/types/Utils.d.ts +3 -2
- package/types/index.d.ts +1 -1
- package/umd/Attractor.js +18 -13
- package/umd/Utils.js +7 -7
- package/umd/index.js +7 -5
- package/62.min.js +0 -2
- package/62.min.js.LICENSE.txt +0 -1
package/689.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 689.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_interaction_external_attract=this.webpackChunk_tsparticles_interaction_external_attract||[]).push([[689],{689(t,i,e){e.d(i,{Attractor:()=>r});var n=e(303),a=e(702);function c(t,i,e,a,c,s){const o=i.actualOptions.interactivity?.modes.attract;if(!o)return;const r=i.particles.quadTree.query(c,s);for(const i of r){const{dx:c,dy:s,distance:r}=(0,n.getDistances)(i.position,e),l=o.speed*o.factor,d=(0,n.clamp)(t.getEasing(o.easing)(n.identity-r/a)*l,1,o.maxSpeed),u=n.Vector.create(r?c/r*d:l,r?s/r*d:l);i.position.subFrom(u)}}var s=e(604);const o="attract";class r extends a.ExternalInteractorBase{constructor(t,i){super(i),this._engine=t,i.attract??={particles:[]},this.handleClickMode=(t,e)=>{const a=this.container.actualOptions,c=a.interactivity?.modes.attract;if(c&&t===o){i.attract??={particles:[]},i.attract.clicking=!0,i.attract.count=0;for(const t of i.attract.particles)this.isEnabled(e,t)&&t.velocity.setTo(t.initialVelocity);i.attract.particles=[],i.attract.finish=!1,setTimeout((()=>{i.destroyed||(i.attract??={particles:[]},i.attract.clicking=!1)}),c.duration*n.millisecondsToSeconds)}}}clear(){}init(){const t=this.container,i=t.actualOptions.interactivity?.modes.attract;i&&(t.retina.attractModeDistance=i.distance*t.retina.pixelRatio)}interact(t){const i=this.container.actualOptions,e=t.status===a.mouseMoveEvent,s=i.interactivity?.events;if(!s)return;const{enable:r,mode:l}=s.onHover,{enable:d,mode:u}=s.onClick;e&&r&&(0,n.isInArray)(o,l)?function(t,i,e,a){const s=e.mouse.position,o=i.retina.attractModeDistance;!o||o<0||!s||c(t,i,s,o,new n.Circle(s.x,s.y,o),(t=>a(t)))}(this._engine,this.container,t,(i=>this.isEnabled(t,i))):d&&(0,n.isInArray)(o,u)&&function(t,i,e,a){i.attract??={particles:[]};const{attract:s}=i;if(s.finish||(s.count??=0,s.count++,s.count===i.particles.count&&(s.finish=!0)),s.clicking){const s=e.mouse.clickPosition,o=i.retina.attractModeDistance;if(!o||o<0||!s)return;c(t,i,s,o,new n.Circle(s.x,s.y,o),(t=>a(t)))}else!1===s.clicking&&(s.particles=[])}(this._engine,this.container,t,(i=>this.isEnabled(t,i)))}isEnabled(t,i){const e=this.container.actualOptions,a=t.mouse,c=(i?.interactivity??e.interactivity)?.events;if(!(a.position&&c?.onHover.enable||a.clickPosition&&c?.onClick.enable))return!1;const s=c.onHover.mode,r=c.onClick.mode;return(0,n.isInArray)(o,s)||(0,n.isInArray)(o,r)}loadModeOptions(t,...i){t.attract??=new s.K;for(const e of i)t.attract.load(e?.attract)}reset(){}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Attract External Interaction v4.0.0-alpha.5 by Matteo Bruni */
|
package/browser/Attractor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isInArray, millisecondsToSeconds } from "@tsparticles/engine";
|
|
2
|
+
import { ExternalInteractorBase, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
|
|
2
3
|
import { clickAttract, hoverAttract } from "./Utils.js";
|
|
3
4
|
import { Attract } from "./Options/Classes/Attract.js";
|
|
4
5
|
const attractMode = "attract";
|
|
@@ -7,8 +8,8 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
7
8
|
super(container);
|
|
8
9
|
this._engine = engine;
|
|
9
10
|
container.attract ??= { particles: [] };
|
|
10
|
-
this.handleClickMode = (mode) => {
|
|
11
|
-
const options = this.container.actualOptions, attract = options.interactivity
|
|
11
|
+
this.handleClickMode = (mode, interactivityData) => {
|
|
12
|
+
const options = this.container.actualOptions, attract = options.interactivity?.modes.attract;
|
|
12
13
|
if (!attract || mode !== attractMode) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
@@ -16,7 +17,7 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
16
17
|
container.attract.clicking = true;
|
|
17
18
|
container.attract.count = 0;
|
|
18
19
|
for (const particle of container.attract.particles) {
|
|
19
|
-
if (!this.isEnabled(particle)) {
|
|
20
|
+
if (!this.isEnabled(interactivityData, particle)) {
|
|
20
21
|
continue;
|
|
21
22
|
}
|
|
22
23
|
particle.velocity.setTo(particle.initialVelocity);
|
|
@@ -35,24 +36,28 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
35
36
|
clear() {
|
|
36
37
|
}
|
|
37
38
|
init() {
|
|
38
|
-
const container = this.container, attract = container.actualOptions.interactivity
|
|
39
|
+
const container = this.container, attract = container.actualOptions.interactivity?.modes.attract;
|
|
39
40
|
if (!attract) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
|
43
44
|
}
|
|
44
|
-
interact() {
|
|
45
|
-
const container = this.container, options = container.actualOptions, mouseMoveStatus =
|
|
45
|
+
interact(interactivityData) {
|
|
46
|
+
const container = this.container, options = container.actualOptions, mouseMoveStatus = interactivityData.status === mouseMoveEvent, events = options.interactivity?.events;
|
|
47
|
+
if (!events) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { enable: hoverEnabled, mode: hoverMode } = events.onHover, { enable: clickEnabled, mode: clickMode } = events.onClick;
|
|
46
51
|
if (mouseMoveStatus && hoverEnabled && isInArray(attractMode, hoverMode)) {
|
|
47
|
-
hoverAttract(this._engine, this.container, p => this.isEnabled(p));
|
|
52
|
+
hoverAttract(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
48
53
|
}
|
|
49
54
|
else if (clickEnabled && isInArray(attractMode, clickMode)) {
|
|
50
|
-
clickAttract(this._engine, this.container, p => this.isEnabled(p));
|
|
55
|
+
clickAttract(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
|
-
isEnabled(particle) {
|
|
54
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
55
|
-
if ((!mouse.position || !events
|
|
58
|
+
isEnabled(interactivityData, particle) {
|
|
59
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
60
|
+
if ((!mouse.position || !events?.onHover.enable) && (!mouse.clickPosition || !events?.onClick.enable)) {
|
|
56
61
|
return false;
|
|
57
62
|
}
|
|
58
63
|
const hoverMode = events.onHover.mode, clickMode = events.onClick.mode;
|
package/browser/Utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Circle, Vector, clamp, getDistances, } from "@tsparticles/engine";
|
|
2
|
-
const minFactor = 1,
|
|
1
|
+
import { Circle, Vector, clamp, getDistances, identity, } from "@tsparticles/engine";
|
|
2
|
+
const minFactor = 1, minRadius = 0;
|
|
3
3
|
function processAttract(engine, container, position, attractRadius, area, queryCb) {
|
|
4
|
-
const attractOptions = container.actualOptions.interactivity
|
|
4
|
+
const attractOptions = container.actualOptions.interactivity?.modes.attract;
|
|
5
5
|
if (!attractOptions) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ function processAttract(engine, container, position, attractRadius, area, queryC
|
|
|
11
11
|
particle.position.subFrom(normVec);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export function clickAttract(engine, container, enabledCb) {
|
|
14
|
+
export function clickAttract(engine, container, interactivityData, enabledCb) {
|
|
15
15
|
container.attract ??= { particles: [] };
|
|
16
16
|
const { attract } = container;
|
|
17
17
|
if (!attract.finish) {
|
|
@@ -22,7 +22,7 @@ export function clickAttract(engine, container, enabledCb) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
if (attract.clicking) {
|
|
25
|
-
const mousePos =
|
|
25
|
+
const mousePos = interactivityData.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
|
|
26
26
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -32,8 +32,8 @@ export function clickAttract(engine, container, enabledCb) {
|
|
|
32
32
|
attract.particles = [];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export function hoverAttract(engine, container, enabledCb) {
|
|
36
|
-
const mousePos =
|
|
35
|
+
export function hoverAttract(engine, container, interactivityData, enabledCb) {
|
|
36
|
+
const mousePos = interactivityData.mouse.position, attractRadius = container.retina.attractModeDistance;
|
|
37
37
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadExternalAttractInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(e => {
|
|
4
|
-
|
|
1
|
+
export async function loadExternalAttractInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.5");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
await loadInteractivityPlugin(e);
|
|
6
|
+
e.addInteractor?.("externalAttract", async (container) => {
|
|
5
7
|
const { Attractor } = await import("./Attractor.js");
|
|
6
8
|
return new Attractor(e, container);
|
|
7
9
|
});
|
package/cjs/Attractor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isInArray, millisecondsToSeconds } from "@tsparticles/engine";
|
|
2
|
+
import { ExternalInteractorBase, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
|
|
2
3
|
import { clickAttract, hoverAttract } from "./Utils.js";
|
|
3
4
|
import { Attract } from "./Options/Classes/Attract.js";
|
|
4
5
|
const attractMode = "attract";
|
|
@@ -7,8 +8,8 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
7
8
|
super(container);
|
|
8
9
|
this._engine = engine;
|
|
9
10
|
container.attract ??= { particles: [] };
|
|
10
|
-
this.handleClickMode = (mode) => {
|
|
11
|
-
const options = this.container.actualOptions, attract = options.interactivity
|
|
11
|
+
this.handleClickMode = (mode, interactivityData) => {
|
|
12
|
+
const options = this.container.actualOptions, attract = options.interactivity?.modes.attract;
|
|
12
13
|
if (!attract || mode !== attractMode) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
@@ -16,7 +17,7 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
16
17
|
container.attract.clicking = true;
|
|
17
18
|
container.attract.count = 0;
|
|
18
19
|
for (const particle of container.attract.particles) {
|
|
19
|
-
if (!this.isEnabled(particle)) {
|
|
20
|
+
if (!this.isEnabled(interactivityData, particle)) {
|
|
20
21
|
continue;
|
|
21
22
|
}
|
|
22
23
|
particle.velocity.setTo(particle.initialVelocity);
|
|
@@ -35,24 +36,28 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
35
36
|
clear() {
|
|
36
37
|
}
|
|
37
38
|
init() {
|
|
38
|
-
const container = this.container, attract = container.actualOptions.interactivity
|
|
39
|
+
const container = this.container, attract = container.actualOptions.interactivity?.modes.attract;
|
|
39
40
|
if (!attract) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
|
43
44
|
}
|
|
44
|
-
interact() {
|
|
45
|
-
const container = this.container, options = container.actualOptions, mouseMoveStatus =
|
|
45
|
+
interact(interactivityData) {
|
|
46
|
+
const container = this.container, options = container.actualOptions, mouseMoveStatus = interactivityData.status === mouseMoveEvent, events = options.interactivity?.events;
|
|
47
|
+
if (!events) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { enable: hoverEnabled, mode: hoverMode } = events.onHover, { enable: clickEnabled, mode: clickMode } = events.onClick;
|
|
46
51
|
if (mouseMoveStatus && hoverEnabled && isInArray(attractMode, hoverMode)) {
|
|
47
|
-
hoverAttract(this._engine, this.container, p => this.isEnabled(p));
|
|
52
|
+
hoverAttract(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
48
53
|
}
|
|
49
54
|
else if (clickEnabled && isInArray(attractMode, clickMode)) {
|
|
50
|
-
clickAttract(this._engine, this.container, p => this.isEnabled(p));
|
|
55
|
+
clickAttract(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
|
-
isEnabled(particle) {
|
|
54
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
55
|
-
if ((!mouse.position || !events
|
|
58
|
+
isEnabled(interactivityData, particle) {
|
|
59
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
60
|
+
if ((!mouse.position || !events?.onHover.enable) && (!mouse.clickPosition || !events?.onClick.enable)) {
|
|
56
61
|
return false;
|
|
57
62
|
}
|
|
58
63
|
const hoverMode = events.onHover.mode, clickMode = events.onClick.mode;
|
package/cjs/Utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Circle, Vector, clamp, getDistances, } from "@tsparticles/engine";
|
|
2
|
-
const minFactor = 1,
|
|
1
|
+
import { Circle, Vector, clamp, getDistances, identity, } from "@tsparticles/engine";
|
|
2
|
+
const minFactor = 1, minRadius = 0;
|
|
3
3
|
function processAttract(engine, container, position, attractRadius, area, queryCb) {
|
|
4
|
-
const attractOptions = container.actualOptions.interactivity
|
|
4
|
+
const attractOptions = container.actualOptions.interactivity?.modes.attract;
|
|
5
5
|
if (!attractOptions) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ function processAttract(engine, container, position, attractRadius, area, queryC
|
|
|
11
11
|
particle.position.subFrom(normVec);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export function clickAttract(engine, container, enabledCb) {
|
|
14
|
+
export function clickAttract(engine, container, interactivityData, enabledCb) {
|
|
15
15
|
container.attract ??= { particles: [] };
|
|
16
16
|
const { attract } = container;
|
|
17
17
|
if (!attract.finish) {
|
|
@@ -22,7 +22,7 @@ export function clickAttract(engine, container, enabledCb) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
if (attract.clicking) {
|
|
25
|
-
const mousePos =
|
|
25
|
+
const mousePos = interactivityData.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
|
|
26
26
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -32,8 +32,8 @@ export function clickAttract(engine, container, enabledCb) {
|
|
|
32
32
|
attract.particles = [];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export function hoverAttract(engine, container, enabledCb) {
|
|
36
|
-
const mousePos =
|
|
35
|
+
export function hoverAttract(engine, container, interactivityData, enabledCb) {
|
|
36
|
+
const mousePos = interactivityData.mouse.position, attractRadius = container.retina.attractModeDistance;
|
|
37
37
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadExternalAttractInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(e => {
|
|
4
|
-
|
|
1
|
+
export async function loadExternalAttractInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.5");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
await loadInteractivityPlugin(e);
|
|
6
|
+
e.addInteractor?.("externalAttract", async (container) => {
|
|
5
7
|
const { Attractor } = await import("./Attractor.js");
|
|
6
8
|
return new Attractor(e, container);
|
|
7
9
|
});
|
|
@@ -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.5
|
|
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 */ 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
|
|
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/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Options/Classes/Attract.js */ \"./dist/browser/Options/Classes/Attract.js\");\n\n\n\n\nconst attractMode = \"attract\";\nclass Attractor extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.ExternalInteractorBase {\n constructor(engine, container) {\n super(container);\n this._engine = engine;\n container.attract ??= {\n particles: []\n };\n this.handleClickMode = (mode, interactivityData) => {\n const options = this.container.actualOptions,\n attract = options.interactivity?.modes.attract;\n if (!attract || mode !== attractMode) {\n return;\n }\n container.attract ??= {\n particles: []\n };\n container.attract.clicking = true;\n container.attract.count = 0;\n for (const particle of container.attract.particles) {\n if (!this.isEnabled(interactivityData, particle)) {\n continue;\n }\n particle.velocity.setTo(particle.initialVelocity);\n }\n container.attract.particles = [];\n container.attract.finish = false;\n setTimeout(() => {\n if (container.destroyed) {\n return;\n }\n container.attract ??= {\n particles: []\n };\n container.attract.clicking = false;\n }, attract.duration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds);\n };\n }\n clear() {}\n init() {\n const container = this.container,\n attract = container.actualOptions.interactivity?.modes.attract;\n if (!attract) {\n return;\n }\n container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;\n }\n interact(interactivityData) {\n const container = this.container,\n options = container.actualOptions,\n mouseMoveStatus = interactivityData.status === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.mouseMoveEvent,\n events = options.interactivity?.events;\n if (!events) {\n return;\n }\n const {\n enable: hoverEnabled,\n mode: hoverMode\n } = events.onHover,\n {\n enable: clickEnabled,\n mode: clickMode\n } = events.onClick;\n if (mouseMoveStatus && hoverEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(attractMode, hoverMode)) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.hoverAttract)(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));\n } else if (clickEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(attractMode, clickMode)) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.clickAttract)(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));\n }\n }\n isEnabled(interactivityData, particle) {\n const container = this.container,\n options = container.actualOptions,\n mouse = interactivityData.mouse,\n events = (particle?.interactivity ?? options.interactivity)?.events;\n if ((!mouse.position || !events?.onHover.enable) && (!mouse.clickPosition || !events?.onClick.enable)) {\n return false;\n }\n const hoverMode = events.onHover.mode,\n clickMode = events.onClick.mode;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(attractMode, hoverMode) || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(attractMode, clickMode);\n }\n loadModeOptions(options, ...sources) {\n options.attract ??= new _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_3__.Attract();\n for (const source of sources) {\n options.attract.load(source?.attract);\n }\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-external-attract/./dist/browser/Attractor.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 */ clickAttract: () => (/* binding */ clickAttract),\n/* harmony export */ hoverAttract: () => (/* binding */ hoverAttract)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst minFactor = 1,\n
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ clickAttract: () => (/* binding */ clickAttract),\n/* harmony export */ hoverAttract: () => (/* binding */ hoverAttract)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst minFactor = 1,\n minRadius = 0;\nfunction processAttract(engine, container, position, attractRadius, area, queryCb) {\n const attractOptions = container.actualOptions.interactivity?.modes.attract;\n if (!attractOptions) {\n return;\n }\n const query = container.particles.quadTree.query(area, queryCb);\n for (const particle of query) {\n const {\n dx,\n dy,\n distance\n } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(particle.position, position),\n velocity = attractOptions.speed * attractOptions.factor,\n attractFactor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.clamp)(engine.getEasing(attractOptions.easing)(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.identity - distance / attractRadius) * velocity, minFactor, attractOptions.maxSpeed),\n normVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.create(!distance ? velocity : dx / distance * attractFactor, !distance ? velocity : dy / distance * attractFactor);\n particle.position.subFrom(normVec);\n }\n}\nfunction clickAttract(engine, container, interactivityData, enabledCb) {\n container.attract ??= {\n particles: []\n };\n const {\n attract\n } = container;\n if (!attract.finish) {\n attract.count ??= 0;\n attract.count++;\n if (attract.count === container.particles.count) {\n attract.finish = true;\n }\n }\n if (attract.clicking) {\n const mousePos = interactivityData.mouse.clickPosition,\n attractRadius = container.retina.attractModeDistance;\n if (!attractRadius || attractRadius < minRadius || !mousePos) {\n return;\n }\n processAttract(engine, container, mousePos, attractRadius, new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(mousePos.x, mousePos.y, attractRadius), p => enabledCb(p));\n } else if (attract.clicking === false) {\n attract.particles = [];\n }\n}\nfunction hoverAttract(engine, container, interactivityData, enabledCb) {\n const mousePos = interactivityData.mouse.position,\n attractRadius = container.retina.attractModeDistance;\n if (!attractRadius || attractRadius < minRadius || !mousePos) {\n return;\n }\n processAttract(engine, container, mousePos, attractRadius, new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(mousePos.x, mousePos.y, attractRadius), p => enabledCb(p));\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-external-attract/./dist/browser/Utils.js?\n}");
|
|
37
37
|
|
|
38
38
|
/***/ }
|
|
39
39
|
|
package/esm/Attractor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isInArray, millisecondsToSeconds } from "@tsparticles/engine";
|
|
2
|
+
import { ExternalInteractorBase, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
|
|
2
3
|
import { clickAttract, hoverAttract } from "./Utils.js";
|
|
3
4
|
import { Attract } from "./Options/Classes/Attract.js";
|
|
4
5
|
const attractMode = "attract";
|
|
@@ -7,8 +8,8 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
7
8
|
super(container);
|
|
8
9
|
this._engine = engine;
|
|
9
10
|
container.attract ??= { particles: [] };
|
|
10
|
-
this.handleClickMode = (mode) => {
|
|
11
|
-
const options = this.container.actualOptions, attract = options.interactivity
|
|
11
|
+
this.handleClickMode = (mode, interactivityData) => {
|
|
12
|
+
const options = this.container.actualOptions, attract = options.interactivity?.modes.attract;
|
|
12
13
|
if (!attract || mode !== attractMode) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
@@ -16,7 +17,7 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
16
17
|
container.attract.clicking = true;
|
|
17
18
|
container.attract.count = 0;
|
|
18
19
|
for (const particle of container.attract.particles) {
|
|
19
|
-
if (!this.isEnabled(particle)) {
|
|
20
|
+
if (!this.isEnabled(interactivityData, particle)) {
|
|
20
21
|
continue;
|
|
21
22
|
}
|
|
22
23
|
particle.velocity.setTo(particle.initialVelocity);
|
|
@@ -35,24 +36,28 @@ export class Attractor extends ExternalInteractorBase {
|
|
|
35
36
|
clear() {
|
|
36
37
|
}
|
|
37
38
|
init() {
|
|
38
|
-
const container = this.container, attract = container.actualOptions.interactivity
|
|
39
|
+
const container = this.container, attract = container.actualOptions.interactivity?.modes.attract;
|
|
39
40
|
if (!attract) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
|
43
44
|
}
|
|
44
|
-
interact() {
|
|
45
|
-
const container = this.container, options = container.actualOptions, mouseMoveStatus =
|
|
45
|
+
interact(interactivityData) {
|
|
46
|
+
const container = this.container, options = container.actualOptions, mouseMoveStatus = interactivityData.status === mouseMoveEvent, events = options.interactivity?.events;
|
|
47
|
+
if (!events) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { enable: hoverEnabled, mode: hoverMode } = events.onHover, { enable: clickEnabled, mode: clickMode } = events.onClick;
|
|
46
51
|
if (mouseMoveStatus && hoverEnabled && isInArray(attractMode, hoverMode)) {
|
|
47
|
-
hoverAttract(this._engine, this.container, p => this.isEnabled(p));
|
|
52
|
+
hoverAttract(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
48
53
|
}
|
|
49
54
|
else if (clickEnabled && isInArray(attractMode, clickMode)) {
|
|
50
|
-
clickAttract(this._engine, this.container, p => this.isEnabled(p));
|
|
55
|
+
clickAttract(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
|
-
isEnabled(particle) {
|
|
54
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
55
|
-
if ((!mouse.position || !events
|
|
58
|
+
isEnabled(interactivityData, particle) {
|
|
59
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
60
|
+
if ((!mouse.position || !events?.onHover.enable) && (!mouse.clickPosition || !events?.onClick.enable)) {
|
|
56
61
|
return false;
|
|
57
62
|
}
|
|
58
63
|
const hoverMode = events.onHover.mode, clickMode = events.onClick.mode;
|
package/esm/Utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Circle, Vector, clamp, getDistances, } from "@tsparticles/engine";
|
|
2
|
-
const minFactor = 1,
|
|
1
|
+
import { Circle, Vector, clamp, getDistances, identity, } from "@tsparticles/engine";
|
|
2
|
+
const minFactor = 1, minRadius = 0;
|
|
3
3
|
function processAttract(engine, container, position, attractRadius, area, queryCb) {
|
|
4
|
-
const attractOptions = container.actualOptions.interactivity
|
|
4
|
+
const attractOptions = container.actualOptions.interactivity?.modes.attract;
|
|
5
5
|
if (!attractOptions) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ function processAttract(engine, container, position, attractRadius, area, queryC
|
|
|
11
11
|
particle.position.subFrom(normVec);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export function clickAttract(engine, container, enabledCb) {
|
|
14
|
+
export function clickAttract(engine, container, interactivityData, enabledCb) {
|
|
15
15
|
container.attract ??= { particles: [] };
|
|
16
16
|
const { attract } = container;
|
|
17
17
|
if (!attract.finish) {
|
|
@@ -22,7 +22,7 @@ export function clickAttract(engine, container, enabledCb) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
if (attract.clicking) {
|
|
25
|
-
const mousePos =
|
|
25
|
+
const mousePos = interactivityData.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
|
|
26
26
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -32,8 +32,8 @@ export function clickAttract(engine, container, enabledCb) {
|
|
|
32
32
|
attract.particles = [];
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export function hoverAttract(engine, container, enabledCb) {
|
|
36
|
-
const mousePos =
|
|
35
|
+
export function hoverAttract(engine, container, interactivityData, enabledCb) {
|
|
36
|
+
const mousePos = interactivityData.mouse.position, attractRadius = container.retina.attractModeDistance;
|
|
37
37
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadExternalAttractInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(e => {
|
|
4
|
-
|
|
1
|
+
export async function loadExternalAttractInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.5");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
await loadInteractivityPlugin(e);
|
|
6
|
+
e.addInteractor?.("externalAttract", async (container) => {
|
|
5
7
|
const { Attractor } = await import("./Attractor.js");
|
|
6
8
|
return new Attractor(e, container);
|
|
7
9
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-attract",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.5",
|
|
4
4
|
"description": "tsParticles attract external interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,7 +87,8 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "4.0.0-alpha.
|
|
90
|
+
"@tsparticles/engine": "4.0.0-alpha.5",
|
|
91
|
+
"@tsparticles/plugin-interactivity": "4.0.0-alpha.5"
|
|
91
92
|
},
|
|
92
93
|
"publishConfig": {
|
|
93
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-external-attract [
|
|
6
|
+
<title>@tsparticles/interaction-external-attract [21 Jan 2026 at 19:01]</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.
|
|
7
|
+
* v4.0.0-alpha.5
|
|
8
8
|
*/
|
|
9
9
|
/*
|
|
10
10
|
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
*/
|
|
17
17
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
18
18
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
19
|
-
module.exports = factory(require("@tsparticles/engine"));
|
|
19
|
+
module.exports = factory(require("@tsparticles/engine"), require("@tsparticles/plugin-interactivity"));
|
|
20
20
|
else if(typeof define === 'function' && define.amd)
|
|
21
|
-
define(["@tsparticles/engine"], factory);
|
|
21
|
+
define(["@tsparticles/engine", "@tsparticles/plugin-interactivity"], factory);
|
|
22
22
|
else {
|
|
23
|
-
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
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__) => {
|
|
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__ = ({
|
|
@@ -44,7 +44,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
44
44
|
\*******************************/
|
|
45
45
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
46
46
|
|
|
47
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Attract: () => (/* reexport safe */ _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_0__.Attract),\n/* harmony export */ loadExternalAttractInteraction: () => (/* binding */ loadExternalAttractInteraction)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Attract.js */ \"./dist/browser/Options/Classes/Attract.js\");\
|
|
47
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Attract: () => (/* reexport safe */ _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_0__.Attract),\n/* harmony export */ loadExternalAttractInteraction: () => (/* binding */ loadExternalAttractInteraction)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Attract_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Attract.js */ \"./dist/browser/Options/Classes/Attract.js\");\nasync function loadExternalAttractInteraction(engine) {\n engine.checkVersion(\"4.0.0-alpha.5\");\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?.(\"externalAttract\", 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(e, container);\n });\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-attract/./dist/browser/index.js?\n}");
|
|
48
48
|
|
|
49
49
|
/***/ },
|
|
50
50
|
|
|
@@ -56,6 +56,16 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
56
56
|
|
|
57
57
|
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
58
58
|
|
|
59
|
+
/***/ },
|
|
60
|
+
|
|
61
|
+
/***/ "@tsparticles/plugin-interactivity"
|
|
62
|
+
/*!***************************************************************************************************************************************************************************!*\
|
|
63
|
+
!*** external {"commonjs":"@tsparticles/plugin-interactivity","commonjs2":"@tsparticles/plugin-interactivity","amd":"@tsparticles/plugin-interactivity","root":"window"} ***!
|
|
64
|
+
\***************************************************************************************************************************************************************************/
|
|
65
|
+
(module) {
|
|
66
|
+
|
|
67
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_interactivity__;
|
|
68
|
+
|
|
59
69
|
/***/ }
|
|
60
70
|
|
|
61
71
|
/******/ });
|
|
@@ -94,6 +104,36 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
94
104
|
/******/ __webpack_require__.m = __webpack_modules__;
|
|
95
105
|
/******/
|
|
96
106
|
/************************************************************************/
|
|
107
|
+
/******/ /* webpack/runtime/create fake namespace object */
|
|
108
|
+
/******/ (() => {
|
|
109
|
+
/******/ var getProto = Object.getPrototypeOf ? (obj) => (Object.getPrototypeOf(obj)) : (obj) => (obj.__proto__);
|
|
110
|
+
/******/ var leafPrototypes;
|
|
111
|
+
/******/ // create a fake namespace object
|
|
112
|
+
/******/ // mode & 1: value is a module id, require it
|
|
113
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
114
|
+
/******/ // mode & 4: return value when already ns object
|
|
115
|
+
/******/ // mode & 16: return value when it's Promise-like
|
|
116
|
+
/******/ // mode & 8|1: behave like require
|
|
117
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
118
|
+
/******/ if(mode & 1) value = this(value);
|
|
119
|
+
/******/ if(mode & 8) return value;
|
|
120
|
+
/******/ if(typeof value === 'object' && value) {
|
|
121
|
+
/******/ if((mode & 4) && value.__esModule) return value;
|
|
122
|
+
/******/ if((mode & 16) && typeof value.then === 'function') return value;
|
|
123
|
+
/******/ }
|
|
124
|
+
/******/ var ns = Object.create(null);
|
|
125
|
+
/******/ __webpack_require__.r(ns);
|
|
126
|
+
/******/ var def = {};
|
|
127
|
+
/******/ leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
|
|
128
|
+
/******/ for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) {
|
|
129
|
+
/******/ Object.getOwnPropertyNames(current).forEach((key) => (def[key] = () => (value[key])));
|
|
130
|
+
/******/ }
|
|
131
|
+
/******/ def['default'] = () => (value);
|
|
132
|
+
/******/ __webpack_require__.d(ns, def);
|
|
133
|
+
/******/ return ns;
|
|
134
|
+
/******/ };
|
|
135
|
+
/******/ })();
|
|
136
|
+
/******/
|
|
97
137
|
/******/ /* webpack/runtime/define property getters */
|
|
98
138
|
/******/ (() => {
|
|
99
139
|
/******/ // define getter functions for harmony exports
|
|
@@ -128,18 +168,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
128
168
|
/******/ };
|
|
129
169
|
/******/ })();
|
|
130
170
|
/******/
|
|
131
|
-
/******/ /* webpack/runtime/global */
|
|
132
|
-
/******/ (() => {
|
|
133
|
-
/******/ __webpack_require__.g = (function() {
|
|
134
|
-
/******/ if (typeof globalThis === 'object') return globalThis;
|
|
135
|
-
/******/ try {
|
|
136
|
-
/******/ return this || new Function('return this')();
|
|
137
|
-
/******/ } catch (e) {
|
|
138
|
-
/******/ if (typeof window === 'object') return window;
|
|
139
|
-
/******/ }
|
|
140
|
-
/******/ })();
|
|
141
|
-
/******/ })();
|
|
142
|
-
/******/
|
|
143
171
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
144
172
|
/******/ (() => {
|
|
145
173
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
@@ -204,8 +232,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
204
232
|
/******/ /* webpack/runtime/publicPath */
|
|
205
233
|
/******/ (() => {
|
|
206
234
|
/******/ var scriptUrl;
|
|
207
|
-
/******/ if (
|
|
208
|
-
/******/ var document =
|
|
235
|
+
/******/ if (globalThis.importScripts) scriptUrl = globalThis.location + "";
|
|
236
|
+
/******/ var document = globalThis.document;
|
|
209
237
|
/******/ if (!scriptUrl && document) {
|
|
210
238
|
/******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
|
|
211
239
|
/******/ scriptUrl = document.currentScript.src;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.interaction.external.attract.min.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e=>(()=>{var
|
|
2
|
+
!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)=>(()=>{var r,i,a,o,n={303(t){t.exports=e},604(e,t,r){r.d(t,{K:()=>a});var i=r(303);class a{constructor(){this.distance=200,this.duration=.4,this.easing=i.EasingType.easeOutQuad,this.factor=1,this.maxSpeed=50,this.speed=1}load(e){(0,i.isNull)(e)||(void 0!==e.distance&&(this.distance=e.distance),void 0!==e.duration&&(this.duration=e.duration),void 0!==e.easing&&(this.easing=e.easing),void 0!==e.factor&&(this.factor=e.factor),void 0!==e.maxSpeed&&(this.maxSpeed=e.maxSpeed),void 0!==e.speed&&(this.speed=e.speed))}}},702(e){e.exports=t}},s={};function c(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return n[e](r,r.exports,c),r.exports}c.m=n,i=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,c.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 a=Object.create(null);c.r(a);var o={};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=>o[t]=()=>e[t]));return o.default=()=>e,c.d(a,o),a},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.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a={},o="@tsparticles/interaction-external-attract:",c.l=(e,t,r,i)=>{if(a[e])a[e].push(t);else{var n,s;if(void 0!==r)for(var l=document.getElementsByTagName("script"),p=0;p<l.length;p++){var d=l[p];if(d.getAttribute("src")==e||d.getAttribute("data-webpack")==o+r){n=d;break}}n||(s=!0,(n=document.createElement("script")).charset="utf-8",c.nc&&n.setAttribute("nonce",c.nc),n.setAttribute("data-webpack",o+r),n.src=e),a[e]=[t];var u=(t,r)=>{n.onerror=n.onload=null,clearTimeout(f);var i=a[e];if(delete a[e],n.parentNode&&n.parentNode.removeChild(n),i&&i.forEach((e=>e(r))),t)return t(r)},f=setTimeout(u.bind(null,void 0,{type:"timeout",target:n}),12e4);n.onerror=u.bind(null,n.onerror),n.onload=u.bind(null,n.onload),s&&document.head.appendChild(n)}},c.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(/\/[^\/]+$/,"/"),c.p=e})(),(()=>{var e={261:0};c.f.j=(t,r)=>{var i=c.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var a=new Promise(((r,a)=>i=e[t]=[r,a]));r.push(i[2]=a);var o=c.p+c.u(t),n=new Error;c.l(o,(r=>{if(c.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var a=r&&("load"===r.type?"missing":r.type),o=r&&r.target&&r.target.src;n.message="Loading chunk "+t+" failed.\n("+a+": "+o+")",n.name="ChunkLoadError",n.type=a,n.request=o,i[1](n)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,a,[o,n,s]=r,l=0;if(o.some((t=>0!==e[t]))){for(i in n)c.o(n,i)&&(c.m[i]=n[i]);if(s)s(c)}for(t&&t(r);l<o.length;l++)a=o[l],c.o(e,a)&&e[a]&&e[a][0](),e[a]=0},r=this.webpackChunk_tsparticles_interaction_external_attract=this.webpackChunk_tsparticles_interaction_external_attract||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var l={};c.r(l),c.d(l,{Attract:()=>p.K,loadExternalAttractInteraction:()=>d});var p=c(604);async function d(e){e.checkVersion("4.0.0-alpha.5"),await e.register((async e=>{const{loadInteractivityPlugin:t}=await Promise.resolve().then(c.t.bind(c,702,19));await t(e),e.addInteractor?.("externalAttract",(async t=>{const{Attractor:r}=await c.e(689).then(c.bind(c,689));return new r(e,t)}))}))}return l})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! tsParticles Attract External Interaction v4.0.0-alpha.
|
|
1
|
+
/*! tsParticles Attract External Interaction v4.0.0-alpha.5 by Matteo Bruni */
|
package/types/Attractor.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { AttractContainer, AttractMode, IAttractMode } from "./Types.js";
|
|
2
|
-
import { type Engine,
|
|
2
|
+
import { type Engine, type RecursivePartial } from "@tsparticles/engine";
|
|
3
|
+
import { ExternalInteractorBase, type IInteractivityData, type IModes, type InteractivityParticle, type Modes } from "@tsparticles/plugin-interactivity";
|
|
3
4
|
export declare class Attractor extends ExternalInteractorBase<AttractContainer> {
|
|
4
|
-
handleClickMode: (mode: string) => void;
|
|
5
|
+
handleClickMode: (mode: string, interactivityData: IInteractivityData) => void;
|
|
5
6
|
private readonly _engine;
|
|
6
7
|
constructor(engine: Engine, container: AttractContainer);
|
|
7
8
|
clear(): void;
|
|
8
9
|
init(): void;
|
|
9
|
-
interact(): void;
|
|
10
|
-
isEnabled(particle?:
|
|
10
|
+
interact(interactivityData: IInteractivityData): void;
|
|
11
|
+
isEnabled(interactivityData: IInteractivityData, particle?: InteractivityParticle): boolean;
|
|
11
12
|
loadModeOptions(options: Modes & AttractMode, ...sources: RecursivePartial<(IModes & IAttractMode) | undefined>[]): void;
|
|
12
13
|
reset(): void;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AttractMode } from "../../Types.js";
|
|
2
|
-
import type {
|
|
3
|
-
export type AttractOptions =
|
|
4
|
-
interactivity
|
|
2
|
+
import type { InteractivityOptions } from "@tsparticles/plugin-interactivity";
|
|
3
|
+
export type AttractOptions = InteractivityOptions & {
|
|
4
|
+
interactivity?: {
|
|
5
5
|
modes: AttractMode;
|
|
6
6
|
};
|
|
7
7
|
};
|
package/types/Types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InteractivityContainer, InteractivityParticle } from "@tsparticles/plugin-interactivity";
|
|
2
2
|
import type { Attract } from "./Options/Classes/Attract.js";
|
|
3
3
|
import type { AttractOptions } from "./Options/Classes/AttractOptions.js";
|
|
4
4
|
import type { IAttract } from "./Options/Interfaces/IAttract.js";
|
|
@@ -12,9 +12,9 @@ interface IContainerAttract {
|
|
|
12
12
|
clicking?: boolean;
|
|
13
13
|
count?: number;
|
|
14
14
|
finish?: boolean;
|
|
15
|
-
particles:
|
|
15
|
+
particles: InteractivityParticle[];
|
|
16
16
|
}
|
|
17
|
-
export type AttractContainer =
|
|
17
|
+
export type AttractContainer = InteractivityContainer & {
|
|
18
18
|
actualOptions: AttractOptions;
|
|
19
19
|
attract?: IContainerAttract;
|
|
20
20
|
retina: {
|
package/types/Utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Engine, type Particle } from "@tsparticles/engine";
|
|
2
2
|
import type { AttractContainer } from "./Types.js";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
3
|
+
import type { IInteractivityData } from "@tsparticles/plugin-interactivity";
|
|
4
|
+
export declare function clickAttract(engine: Engine, container: AttractContainer, interactivityData: IInteractivityData, enabledCb: (particle: Particle) => boolean): void;
|
|
5
|
+
export declare function hoverAttract(engine: Engine, container: AttractContainer, interactivityData: IInteractivityData, enabledCb: (particle: Particle) => boolean): void;
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Engine } from "@tsparticles/engine";
|
|
2
|
-
export declare function loadExternalAttractInteraction(engine: Engine): void
|
|
2
|
+
export declare function loadExternalAttractInteraction(engine: Engine): Promise<void>;
|
|
3
3
|
export * from "./Options/Classes/Attract.js";
|
|
4
4
|
export type * from "./Options/Interfaces/IAttract.js";
|
package/umd/Attractor.js
CHANGED
|
@@ -4,23 +4,24 @@
|
|
|
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", "./Utils.js", "./Options/Classes/Attract.js"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "@tsparticles/plugin-interactivity", "./Utils.js", "./Options/Classes/Attract.js"], 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 plugin_interactivity_1 = require("@tsparticles/plugin-interactivity");
|
|
14
15
|
const Utils_js_1 = require("./Utils.js");
|
|
15
16
|
const Attract_js_1 = require("./Options/Classes/Attract.js");
|
|
16
17
|
const attractMode = "attract";
|
|
17
|
-
class Attractor extends
|
|
18
|
+
class Attractor extends plugin_interactivity_1.ExternalInteractorBase {
|
|
18
19
|
constructor(engine, container) {
|
|
19
20
|
super(container);
|
|
20
21
|
this._engine = engine;
|
|
21
22
|
container.attract ??= { particles: [] };
|
|
22
|
-
this.handleClickMode = (mode) => {
|
|
23
|
-
const options = this.container.actualOptions, attract = options.interactivity
|
|
23
|
+
this.handleClickMode = (mode, interactivityData) => {
|
|
24
|
+
const options = this.container.actualOptions, attract = options.interactivity?.modes.attract;
|
|
24
25
|
if (!attract || mode !== attractMode) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
container.attract.clicking = true;
|
|
29
30
|
container.attract.count = 0;
|
|
30
31
|
for (const particle of container.attract.particles) {
|
|
31
|
-
if (!this.isEnabled(particle)) {
|
|
32
|
+
if (!this.isEnabled(interactivityData, particle)) {
|
|
32
33
|
continue;
|
|
33
34
|
}
|
|
34
35
|
particle.velocity.setTo(particle.initialVelocity);
|
|
@@ -47,24 +48,28 @@
|
|
|
47
48
|
clear() {
|
|
48
49
|
}
|
|
49
50
|
init() {
|
|
50
|
-
const container = this.container, attract = container.actualOptions.interactivity
|
|
51
|
+
const container = this.container, attract = container.actualOptions.interactivity?.modes.attract;
|
|
51
52
|
if (!attract) {
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
|
55
56
|
}
|
|
56
|
-
interact() {
|
|
57
|
-
const container = this.container, options = container.actualOptions, mouseMoveStatus =
|
|
57
|
+
interact(interactivityData) {
|
|
58
|
+
const container = this.container, options = container.actualOptions, mouseMoveStatus = interactivityData.status === plugin_interactivity_1.mouseMoveEvent, events = options.interactivity?.events;
|
|
59
|
+
if (!events) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const { enable: hoverEnabled, mode: hoverMode } = events.onHover, { enable: clickEnabled, mode: clickMode } = events.onClick;
|
|
58
63
|
if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)(attractMode, hoverMode)) {
|
|
59
|
-
(0, Utils_js_1.hoverAttract)(this._engine, this.container, p => this.isEnabled(p));
|
|
64
|
+
(0, Utils_js_1.hoverAttract)(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
60
65
|
}
|
|
61
66
|
else if (clickEnabled && (0, engine_1.isInArray)(attractMode, clickMode)) {
|
|
62
|
-
(0, Utils_js_1.clickAttract)(this._engine, this.container, p => this.isEnabled(p));
|
|
67
|
+
(0, Utils_js_1.clickAttract)(this._engine, this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
|
-
isEnabled(particle) {
|
|
66
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
67
|
-
if ((!mouse.position || !events
|
|
70
|
+
isEnabled(interactivityData, particle) {
|
|
71
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
72
|
+
if ((!mouse.position || !events?.onHover.enable) && (!mouse.clickPosition || !events?.onClick.enable)) {
|
|
68
73
|
return false;
|
|
69
74
|
}
|
|
70
75
|
const hoverMode = events.onHover.mode, clickMode = events.onClick.mode;
|
package/umd/Utils.js
CHANGED
|
@@ -12,19 +12,19 @@
|
|
|
12
12
|
exports.clickAttract = clickAttract;
|
|
13
13
|
exports.hoverAttract = hoverAttract;
|
|
14
14
|
const engine_1 = require("@tsparticles/engine");
|
|
15
|
-
const minFactor = 1,
|
|
15
|
+
const minFactor = 1, minRadius = 0;
|
|
16
16
|
function processAttract(engine, container, position, attractRadius, area, queryCb) {
|
|
17
|
-
const attractOptions = container.actualOptions.interactivity
|
|
17
|
+
const attractOptions = container.actualOptions.interactivity?.modes.attract;
|
|
18
18
|
if (!attractOptions) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
const query = container.particles.quadTree.query(area, queryCb);
|
|
22
22
|
for (const particle of query) {
|
|
23
|
-
const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), velocity = attractOptions.speed * attractOptions.factor, attractFactor = (0, engine_1.clamp)(engine.getEasing(attractOptions.easing)(identity - distance / attractRadius) * velocity, minFactor, attractOptions.maxSpeed), normVec = engine_1.Vector.create(!distance ? velocity : (dx / distance) * attractFactor, !distance ? velocity : (dy / distance) * attractFactor);
|
|
23
|
+
const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), velocity = attractOptions.speed * attractOptions.factor, attractFactor = (0, engine_1.clamp)(engine.getEasing(attractOptions.easing)(engine_1.identity - distance / attractRadius) * velocity, minFactor, attractOptions.maxSpeed), normVec = engine_1.Vector.create(!distance ? velocity : (dx / distance) * attractFactor, !distance ? velocity : (dy / distance) * attractFactor);
|
|
24
24
|
particle.position.subFrom(normVec);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function clickAttract(engine, container, enabledCb) {
|
|
27
|
+
function clickAttract(engine, container, interactivityData, enabledCb) {
|
|
28
28
|
container.attract ??= { particles: [] };
|
|
29
29
|
const { attract } = container;
|
|
30
30
|
if (!attract.finish) {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
if (attract.clicking) {
|
|
38
|
-
const mousePos =
|
|
38
|
+
const mousePos = interactivityData.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
|
|
39
39
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
attract.particles = [];
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function hoverAttract(engine, container, enabledCb) {
|
|
49
|
-
const mousePos =
|
|
48
|
+
function hoverAttract(engine, container, interactivityData, enabledCb) {
|
|
49
|
+
const mousePos = interactivityData.mouse.position, attractRadius = container.retina.attractModeDistance;
|
|
50
50
|
if (!attractRadius || attractRadius < minRadius || !mousePos) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
package/umd/index.js
CHANGED
|
@@ -47,11 +47,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
47
47
|
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.loadExternalAttractInteraction = loadExternalAttractInteraction;
|
|
50
|
-
function loadExternalAttractInteraction(engine) {
|
|
51
|
-
engine.checkVersion("4.0.0-alpha.
|
|
52
|
-
engine.register(e => {
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
async function loadExternalAttractInteraction(engine) {
|
|
51
|
+
engine.checkVersion("4.0.0-alpha.5");
|
|
52
|
+
await engine.register(async (e) => {
|
|
53
|
+
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));
|
|
54
|
+
await loadInteractivityPlugin(e);
|
|
55
|
+
e.addInteractor?.("externalAttract", async (container) => {
|
|
56
|
+
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));
|
|
55
57
|
return new Attractor(e, container);
|
|
56
58
|
});
|
|
57
59
|
});
|
package/62.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 62.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_interaction_external_attract=this.webpackChunk_tsparticles_interaction_external_attract||[]).push([[62],{62(t,i,a){a.d(i,{Attractor:()=>s});var e=a(303);function n(t,i,a,n,c,r){const s=i.actualOptions.interactivity.modes.attract;if(!s)return;const o=i.particles.quadTree.query(c,r);for(const i of o){const{dx:c,dy:r,distance:o}=(0,e.getDistances)(i.position,a),l=s.speed*s.factor,d=(0,e.clamp)(t.getEasing(s.easing)(1-o/n)*l,1,s.maxSpeed),u=e.Vector.create(o?c/o*d:l,o?r/o*d:l);i.position.subFrom(u)}}var c=a(773);const r="attract";class s extends e.ExternalInteractorBase{constructor(t,i){super(i),this._engine=t,i.attract??={particles:[]},this.handleClickMode=t=>{const a=this.container.actualOptions.interactivity.modes.attract;if(a&&t===r){i.attract??={particles:[]},i.attract.clicking=!0,i.attract.count=0;for(const t of i.attract.particles)this.isEnabled(t)&&t.velocity.setTo(t.initialVelocity);i.attract.particles=[],i.attract.finish=!1,setTimeout((()=>{i.destroyed||(i.attract??={particles:[]},i.attract.clicking=!1)}),a.duration*e.millisecondsToSeconds)}}}clear(){}init(){const t=this.container,i=t.actualOptions.interactivity.modes.attract;i&&(t.retina.attractModeDistance=i.distance*t.retina.pixelRatio)}interact(){const t=this.container,i=t.actualOptions,a=t.interactivity.status===e.mouseMoveEvent,c=i.interactivity.events,{enable:s,mode:o}=c.onHover,{enable:l,mode:d}=c.onClick;a&&s&&(0,e.isInArray)(r,o)?function(t,i,a){const c=i.interactivity.mouse.position,r=i.retina.attractModeDistance;!r||r<0||!c||n(t,i,c,r,new e.Circle(c.x,c.y,r),(t=>a(t)))}(this._engine,this.container,(t=>this.isEnabled(t))):l&&(0,e.isInArray)(r,d)&&function(t,i,a){i.attract??={particles:[]};const{attract:c}=i;if(c.finish||(c.count??=0,c.count++,c.count===i.particles.count&&(c.finish=!0)),c.clicking){const c=i.interactivity.mouse.clickPosition,r=i.retina.attractModeDistance;if(!r||r<0||!c)return;n(t,i,c,r,new e.Circle(c.x,c.y,r),(t=>a(t)))}else!1===c.clicking&&(c.particles=[])}(this._engine,this.container,(t=>this.isEnabled(t)))}isEnabled(t){const i=this.container,a=i.actualOptions,n=i.interactivity.mouse,c=(t?.interactivity??a.interactivity).events;if(!(n.position&&c.onHover.enable||n.clickPosition&&c.onClick.enable))return!1;const s=c.onHover.mode,o=c.onClick.mode;return(0,e.isInArray)(r,s)||(0,e.isInArray)(r,o)}loadModeOptions(t,...i){t.attract??=new c.K;for(const a of i)t.attract.load(a?.attract)}reset(){}}}}]);
|
package/62.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Attract External Interaction v4.0.0-alpha.3 by Matteo Bruni */
|