@tsparticles/interaction-external-bounce 4.0.0-alpha.2 → 4.0.0-alpha.20
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/918.min.js +1 -0
- package/README.md +5 -0
- package/browser/Bouncer.js +17 -8
- package/browser/Options/Classes/Bounce.js +1 -0
- package/browser/Utils.js +5 -4
- package/browser/index.js +6 -4
- package/cjs/Bouncer.js +17 -8
- package/cjs/Options/Classes/Bounce.js +1 -0
- package/cjs/Utils.js +5 -4
- package/cjs/index.js +6 -4
- package/dist_browser_Bouncer_js.js +3 -3
- package/esm/Bouncer.js +17 -8
- package/esm/Options/Classes/Bounce.js +1 -0
- package/esm/Utils.js +5 -4
- package/esm/index.js +6 -4
- package/package.json +3 -2
- package/report.html +3 -3
- package/tsparticles.interaction.external.bounce.js +57 -17
- package/tsparticles.interaction.external.bounce.min.js +2 -2
- package/types/Bouncer.d.ts +4 -3
- package/types/Options/Classes/BounceOptions.d.ts +3 -3
- package/types/Types.d.ts +2 -2
- package/types/Utils.d.ts +3 -2
- package/types/index.d.ts +1 -1
- package/umd/Bouncer.js +19 -10
- package/umd/Options/Classes/Bounce.js +1 -0
- package/umd/Utils.js +12 -11
- package/umd/index.js +7 -5
- package/85.min.js +0 -2
- package/85.min.js.LICENSE.txt +0 -1
- package/tsparticles.interaction.external.bounce.min.js.LICENSE.txt +0 -1
package/918.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_interaction_external_bounce=this.webpackChunk_tsparticles_interaction_external_bounce||[]).push([[918],{918(e,t,i){i.d(t,{Bouncer:()=>u});var o=i(702),n=i(303);let a=Math.PI*n.half;function c(e,t,i,o,c){for(let l of e.particles.quadTree.query(o,c))o instanceof n.Circle?(0,n.circleBounce)((0,n.circleBounceDataFromParticle)(l),{position:t,radius:i,mass:i**2*a,velocity:n.Vector.origin,factor:n.Vector.origin}):o instanceof n.Rectangle&&function(e,t){let i=e.getPosition(),o=e.getRadius(),a=(0,n.calculateBounds)(i,o),c=e.options.bounce,l=r({pSide:{min:a.left,max:a.right},pOtherSide:{min:a.top,max:a.bottom},rectSide:{min:t.left,max:t.right},rectOtherSide:{min:t.top,max:t.bottom},velocity:e.velocity.x,factor:(0,n.getRangeValue)(c.horizontal.value)});l.bounced&&(void 0!==l.velocity&&(e.velocity.x=l.velocity),void 0!==l.position&&(e.position.x=l.position));let s=r({pSide:{min:a.top,max:a.bottom},pOtherSide:{min:a.left,max:a.right},rectSide:{min:t.top,max:t.bottom},rectOtherSide:{min:t.left,max:t.right},velocity:e.velocity.y,factor:(0,n.getRangeValue)(c.vertical.value)});s.bounced&&(void 0!==s.velocity&&(e.velocity.y=s.velocity),void 0!==s.position&&(e.position.y=s.position))}(l,(0,n.calculateBounds)(t,i))}function r(e){let t={bounced:!1},{pSide:i,pOtherSide:o,rectSide:a,rectOtherSide:c,velocity:r,factor:l}=e;return o.min<c.min||o.min>c.max||o.max<c.min||o.max>c.max||(i.max>=a.min&&i.max<=(a.max+a.min)*n.half&&r>0||i.min<=a.max&&i.min>(a.max+a.min)*n.half&&r<0)&&(t.velocity=-(r*l),t.bounced=!0),t}var l=i(846);let s="bounce";class u extends o.ExternalInteractorBase{constructor(e){super(e)}clear(){}init(){let e=this.container,t=e.actualOptions.interactivity?.modes.bounce;t&&(e.retina.bounceModeDistance=t.distance*e.retina.pixelRatio)}interact(e){var t,i,a,r;let l=this.container.actualOptions,u=l.interactivity?.events,f=e.status===o.mouseMoveEvent;if(!u)return;let m=u.onHover.enable,d=u.onHover.mode,v=u.onDiv;if(f&&m&&(0,n.isInArray)(s,d)){let o,a,r;t=this.container,i=t=>this.isEnabled(e,t),o=t.retina.pixelRatio,a=e.mouse.position,(r=t.retina.bounceModeDistance)&&!(r<0)&&a&&c(t,a,r,new n.Circle(a.x,a.y,r+10*o),i)}else a=this.container,r=t=>this.isEnabled(e,t),(0,o.divModeExecute)(s,v,(e,t)=>{let i;(i=(0,n.safeDocument)().querySelectorAll(e)).length&&i.forEach(e=>{let i=a.retina.pixelRatio,l={x:(e.offsetLeft+e.offsetWidth*n.half)*i,y:(e.offsetTop+e.offsetHeight*n.half)*i},s=e.offsetWidth*n.half*i,u=10*i,f=t.type===o.DivType.circle?new n.Circle(l.x,l.y,s+u):new n.Rectangle(e.offsetLeft*i-u,e.offsetTop*i-u,e.offsetWidth*i+u*n.double,e.offsetHeight*i+u*n.double);((e,t,i)=>{c(a,e,t,i,r)})(l,s,f)})})}isEnabled(e,t){let i=this.container.actualOptions,a=e.mouse,c=(t?.interactivity??i.interactivity)?.events;if(!c)return!1;let r=c.onDiv;return!!a.position&&c.onHover.enable&&(0,n.isInArray)(s,c.onHover.mode)||(0,o.isDivModeEnabled)(s,r)}loadModeOptions(e,...t){for(let i of(e.bounce??=new l.b,t))e.bounce.load(i?.bounce)}reset(){}}}}]);
|
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ Once the scripts are loaded you can set up `tsParticles` and the interaction plu
|
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
30
|
(async () => {
|
|
31
|
+
await loadInteractivityPlugin(tsParticles);
|
|
31
32
|
await loadExternalBounceInteraction(tsParticles);
|
|
32
33
|
|
|
33
34
|
await tsParticles.load({
|
|
@@ -57,9 +58,11 @@ Then you need to import it in the app, like this:
|
|
|
57
58
|
|
|
58
59
|
```javascript
|
|
59
60
|
const { tsParticles } = require("@tsparticles/engine");
|
|
61
|
+
const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
|
|
60
62
|
const { loadExternalBounceInteraction } = require("@tsparticles/interaction-external-bounce");
|
|
61
63
|
|
|
62
64
|
(async () => {
|
|
65
|
+
await loadInteractivityPlugin(tsParticles);
|
|
63
66
|
await loadExternalBounceInteraction(tsParticles);
|
|
64
67
|
})();
|
|
65
68
|
```
|
|
@@ -68,9 +71,11 @@ or
|
|
|
68
71
|
|
|
69
72
|
```javascript
|
|
70
73
|
import { tsParticles } from "@tsparticles/engine";
|
|
74
|
+
import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
|
|
71
75
|
import { loadExternalBounceInteraction } from "@tsparticles/interaction-external-bounce";
|
|
72
76
|
|
|
73
77
|
(async () => {
|
|
78
|
+
await loadInteractivityPlugin(tsParticles);
|
|
74
79
|
await loadExternalBounceInteraction(tsParticles);
|
|
75
80
|
})();
|
|
76
81
|
```
|
package/browser/Bouncer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isDivModeEnabled,
|
|
1
|
+
import { ExternalInteractorBase, isDivModeEnabled, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
|
|
2
|
+
import { isInArray } from "@tsparticles/engine";
|
|
2
3
|
import { divBounce, mouseBounce } from "./Utils.js";
|
|
3
4
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
|
4
5
|
const bounceMode = "bounce";
|
|
@@ -9,23 +10,31 @@ export class Bouncer extends ExternalInteractorBase {
|
|
|
9
10
|
clear() {
|
|
10
11
|
}
|
|
11
12
|
init() {
|
|
12
|
-
const container = this.container, bounce = container.actualOptions.interactivity
|
|
13
|
+
const container = this.container, bounce = container.actualOptions.interactivity?.modes.bounce;
|
|
13
14
|
if (!bounce) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
|
17
18
|
}
|
|
18
|
-
interact() {
|
|
19
|
-
const container = this.container, options = container.actualOptions, events = options.interactivity
|
|
19
|
+
interact(interactivityData) {
|
|
20
|
+
const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === mouseMoveEvent;
|
|
21
|
+
if (!events) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;
|
|
20
25
|
if (mouseMoveStatus && hoverEnabled && isInArray(bounceMode, hoverMode)) {
|
|
21
|
-
mouseBounce(this.container, p => this.isEnabled(p));
|
|
26
|
+
mouseBounce(this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
22
27
|
}
|
|
23
28
|
else {
|
|
24
|
-
divBounce(this.container, divs, bounceMode, p => this.isEnabled(p));
|
|
29
|
+
divBounce(this.container, divs, bounceMode, p => this.isEnabled(interactivityData, p));
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
|
-
isEnabled(particle) {
|
|
28
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
32
|
+
isEnabled(interactivityData, particle) {
|
|
33
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
34
|
+
if (!events) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const divs = events.onDiv;
|
|
29
38
|
return ((!!mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
|
30
39
|
isDivModeEnabled(bounceMode, divs));
|
|
31
40
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Circle,
|
|
2
|
-
|
|
1
|
+
import { Circle, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, double, getRangeValue, half, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
|
|
3
|
+
const squareExp = 2, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;
|
|
3
4
|
function processBounce(container, position, radius, area, enabledCb) {
|
|
4
5
|
const query = container.particles.quadTree.query(area, enabledCb);
|
|
5
6
|
for (const particle of query) {
|
|
@@ -39,8 +40,8 @@ export function divBounce(container, divs, bounceMode, enabledCb) {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
export function mouseBounce(container, enabledCb) {
|
|
43
|
-
const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos =
|
|
43
|
+
export function mouseBounce(container, interactivityData, enabledCb) {
|
|
44
|
+
const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.bounceModeDistance;
|
|
44
45
|
if (!radius || radius < minRadius || !mousePos) {
|
|
45
46
|
return;
|
|
46
47
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadExternalBounceInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(e => {
|
|
4
|
-
|
|
1
|
+
export async function loadExternalBounceInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.20");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
|
+
e.addInteractor?.("externalBounce", async (container) => {
|
|
5
7
|
const { Bouncer } = await import("./Bouncer.js");
|
|
6
8
|
return new Bouncer(container);
|
|
7
9
|
});
|
package/cjs/Bouncer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isDivModeEnabled,
|
|
1
|
+
import { ExternalInteractorBase, isDivModeEnabled, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
|
|
2
|
+
import { isInArray } from "@tsparticles/engine";
|
|
2
3
|
import { divBounce, mouseBounce } from "./Utils.js";
|
|
3
4
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
|
4
5
|
const bounceMode = "bounce";
|
|
@@ -9,23 +10,31 @@ export class Bouncer extends ExternalInteractorBase {
|
|
|
9
10
|
clear() {
|
|
10
11
|
}
|
|
11
12
|
init() {
|
|
12
|
-
const container = this.container, bounce = container.actualOptions.interactivity
|
|
13
|
+
const container = this.container, bounce = container.actualOptions.interactivity?.modes.bounce;
|
|
13
14
|
if (!bounce) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
|
17
18
|
}
|
|
18
|
-
interact() {
|
|
19
|
-
const container = this.container, options = container.actualOptions, events = options.interactivity
|
|
19
|
+
interact(interactivityData) {
|
|
20
|
+
const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === mouseMoveEvent;
|
|
21
|
+
if (!events) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;
|
|
20
25
|
if (mouseMoveStatus && hoverEnabled && isInArray(bounceMode, hoverMode)) {
|
|
21
|
-
mouseBounce(this.container, p => this.isEnabled(p));
|
|
26
|
+
mouseBounce(this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
22
27
|
}
|
|
23
28
|
else {
|
|
24
|
-
divBounce(this.container, divs, bounceMode, p => this.isEnabled(p));
|
|
29
|
+
divBounce(this.container, divs, bounceMode, p => this.isEnabled(interactivityData, p));
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
|
-
isEnabled(particle) {
|
|
28
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
32
|
+
isEnabled(interactivityData, particle) {
|
|
33
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
34
|
+
if (!events) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const divs = events.onDiv;
|
|
29
38
|
return ((!!mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
|
30
39
|
isDivModeEnabled(bounceMode, divs));
|
|
31
40
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Circle,
|
|
2
|
-
|
|
1
|
+
import { Circle, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, double, getRangeValue, half, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
|
|
3
|
+
const squareExp = 2, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;
|
|
3
4
|
function processBounce(container, position, radius, area, enabledCb) {
|
|
4
5
|
const query = container.particles.quadTree.query(area, enabledCb);
|
|
5
6
|
for (const particle of query) {
|
|
@@ -39,8 +40,8 @@ export function divBounce(container, divs, bounceMode, enabledCb) {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
export function mouseBounce(container, enabledCb) {
|
|
43
|
-
const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos =
|
|
43
|
+
export function mouseBounce(container, interactivityData, enabledCb) {
|
|
44
|
+
const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.bounceModeDistance;
|
|
44
45
|
if (!radius || radius < minRadius || !mousePos) {
|
|
45
46
|
return;
|
|
46
47
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadExternalBounceInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(e => {
|
|
4
|
-
|
|
1
|
+
export async function loadExternalBounceInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.20");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
|
+
e.addInteractor?.("externalBounce", async (container) => {
|
|
5
7
|
const { Bouncer } = await import("./Bouncer.js");
|
|
6
8
|
return new Bouncer(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.20
|
|
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 */ Bouncer: () => (/* binding */ Bouncer)\n/* harmony export */ });\n/* harmony import */ var
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Bouncer: () => (/* binding */ Bouncer)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _Options_Classes_Bounce_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Options/Classes/Bounce.js */ \"./dist/browser/Options/Classes/Bounce.js\");\n\n\n\n\nconst bounceMode = \"bounce\";\nclass Bouncer extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.ExternalInteractorBase {\n constructor(container){\n super(container);\n }\n clear() {}\n init() {\n const container = this.container, bounce = container.actualOptions.interactivity?.modes.bounce;\n if (!bounce) {\n return;\n }\n container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;\n }\n interact(interactivityData) {\n const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.mouseMoveEvent;\n if (!events) {\n return;\n }\n const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;\n if (mouseMoveStatus && hoverEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.isInArray)(bounceMode, hoverMode)) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.mouseBounce)(this.container, interactivityData, (p)=>this.isEnabled(interactivityData, p));\n } else {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.divBounce)(this.container, divs, bounceMode, (p)=>this.isEnabled(interactivityData, p));\n }\n }\n isEnabled(interactivityData, particle) {\n const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;\n if (!events) {\n return false;\n }\n const divs = events.onDiv;\n return !!mouse.position && events.onHover.enable && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.isInArray)(bounceMode, events.onHover.mode) || (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.isDivModeEnabled)(bounceMode, divs);\n }\n loadModeOptions(options, ...sources) {\n options.bounce ??= new _Options_Classes_Bounce_js__WEBPACK_IMPORTED_MODULE_3__.Bounce();\n for (const source of sources){\n options.bounce.load(source?.bounce);\n }\n }\n reset() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-bounce/./dist/browser/Bouncer.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 */ divBounce: () => (/* binding */ divBounce),\n/* harmony export */ mouseBounce: () => (/* binding */ mouseBounce),\n/* harmony export */ rectBounce: () => (/* binding */ rectBounce)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst squareExp = 2
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ divBounce: () => (/* binding */ divBounce),\n/* harmony export */ mouseBounce: () => (/* binding */ mouseBounce),\n/* harmony export */ rectBounce: () => (/* binding */ rectBounce)\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 squareExp = 2, halfPI = Math.PI * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;\nfunction processBounce(container, position, radius, area, enabledCb) {\n const query = container.particles.quadTree.query(area, enabledCb);\n for (const particle of query){\n if (area instanceof _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle) {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.circleBounce)((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.circleBounceDataFromParticle)(particle), {\n position,\n radius,\n mass: radius ** squareExp * halfPI,\n velocity: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin,\n factor: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin\n });\n } else if (area instanceof _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle) {\n rectBounce(particle, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.calculateBounds)(position, radius));\n }\n }\n}\nfunction singleSelectorBounce(container, selector, div, bounceCb) {\n const query = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().querySelectorAll(selector);\n if (!query.length) {\n return;\n }\n query.forEach((item)=>{\n const elem = item, pxRatio = container.retina.pixelRatio, pos = {\n x: (elem.offsetLeft + elem.offsetWidth * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio,\n y: (elem.offsetTop + elem.offsetHeight * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio\n }, radius = elem.offsetWidth * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.DivType.circle ? new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(pos.x, pos.y, radius + tolerance) : new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double, elem.offsetHeight * pxRatio + tolerance * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double);\n bounceCb(pos, radius, area);\n });\n}\nfunction divBounce(container, divs, bounceMode, enabledCb) {\n (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.divModeExecute)(bounceMode, divs, (selector, div)=>{\n singleSelectorBounce(container, selector, div, (pos, radius, area)=>{\n processBounce(container, pos, radius, area, enabledCb);\n });\n });\n}\nfunction mouseBounce(container, interactivityData, enabledCb) {\n const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.bounceModeDistance;\n if (!radius || radius < minRadius || !mousePos) {\n return;\n }\n processBounce(container, mousePos, radius, new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(mousePos.x, mousePos.y, radius + tolerance), enabledCb);\n}\nfunction rectSideBounce(data) {\n const res = {\n bounced: false\n }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data;\n if (pOtherSide.min < rectOtherSide.min || pOtherSide.min > rectOtherSide.max || pOtherSide.max < rectOtherSide.min || pOtherSide.max > rectOtherSide.max) {\n return res;\n }\n if (pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half && velocity > minVelocity || pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half && velocity < minVelocity) {\n res.velocity = velocity * -factor;\n res.bounced = true;\n }\n return res;\n}\nfunction rectBounce(particle, divBounds) {\n const pPos = particle.getPosition(), size = particle.getRadius(), bounds = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.calculateBounds)(pPos, size), bounceOptions = particle.options.bounce, resH = rectSideBounce({\n pSide: {\n min: bounds.left,\n max: bounds.right\n },\n pOtherSide: {\n min: bounds.top,\n max: bounds.bottom\n },\n rectSide: {\n min: divBounds.left,\n max: divBounds.right\n },\n rectOtherSide: {\n min: divBounds.top,\n max: divBounds.bottom\n },\n velocity: particle.velocity.x,\n factor: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(bounceOptions.horizontal.value)\n });\n if (resH.bounced) {\n if (resH.velocity !== undefined) {\n particle.velocity.x = resH.velocity;\n }\n if (resH.position !== undefined) {\n particle.position.x = resH.position;\n }\n }\n const resV = rectSideBounce({\n pSide: {\n min: bounds.top,\n max: bounds.bottom\n },\n pOtherSide: {\n min: bounds.left,\n max: bounds.right\n },\n rectSide: {\n min: divBounds.top,\n max: divBounds.bottom\n },\n rectOtherSide: {\n min: divBounds.left,\n max: divBounds.right\n },\n velocity: particle.velocity.y,\n factor: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(bounceOptions.vertical.value)\n });\n if (resV.bounced) {\n if (resV.velocity !== undefined) {\n particle.velocity.y = resV.velocity;\n }\n if (resV.position !== undefined) {\n particle.position.y = resV.position;\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-bounce/./dist/browser/Utils.js?\n}");
|
|
37
37
|
|
|
38
38
|
/***/ }
|
|
39
39
|
|
package/esm/Bouncer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isDivModeEnabled,
|
|
1
|
+
import { ExternalInteractorBase, isDivModeEnabled, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
|
|
2
|
+
import { isInArray } from "@tsparticles/engine";
|
|
2
3
|
import { divBounce, mouseBounce } from "./Utils.js";
|
|
3
4
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
|
4
5
|
const bounceMode = "bounce";
|
|
@@ -9,23 +10,31 @@ export class Bouncer extends ExternalInteractorBase {
|
|
|
9
10
|
clear() {
|
|
10
11
|
}
|
|
11
12
|
init() {
|
|
12
|
-
const container = this.container, bounce = container.actualOptions.interactivity
|
|
13
|
+
const container = this.container, bounce = container.actualOptions.interactivity?.modes.bounce;
|
|
13
14
|
if (!bounce) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
|
17
18
|
}
|
|
18
|
-
interact() {
|
|
19
|
-
const container = this.container, options = container.actualOptions, events = options.interactivity
|
|
19
|
+
interact(interactivityData) {
|
|
20
|
+
const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === mouseMoveEvent;
|
|
21
|
+
if (!events) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;
|
|
20
25
|
if (mouseMoveStatus && hoverEnabled && isInArray(bounceMode, hoverMode)) {
|
|
21
|
-
mouseBounce(this.container, p => this.isEnabled(p));
|
|
26
|
+
mouseBounce(this.container, interactivityData, p => this.isEnabled(interactivityData, p));
|
|
22
27
|
}
|
|
23
28
|
else {
|
|
24
|
-
divBounce(this.container, divs, bounceMode, p => this.isEnabled(p));
|
|
29
|
+
divBounce(this.container, divs, bounceMode, p => this.isEnabled(interactivityData, p));
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
|
-
isEnabled(particle) {
|
|
28
|
-
const container = this.container, options = container.actualOptions, mouse =
|
|
32
|
+
isEnabled(interactivityData, particle) {
|
|
33
|
+
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
|
|
34
|
+
if (!events) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const divs = events.onDiv;
|
|
29
38
|
return ((!!mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
|
30
39
|
isDivModeEnabled(bounceMode, divs));
|
|
31
40
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Circle,
|
|
2
|
-
|
|
1
|
+
import { Circle, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, double, getRangeValue, half, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
|
|
3
|
+
const squareExp = 2, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;
|
|
3
4
|
function processBounce(container, position, radius, area, enabledCb) {
|
|
4
5
|
const query = container.particles.quadTree.query(area, enabledCb);
|
|
5
6
|
for (const particle of query) {
|
|
@@ -39,8 +40,8 @@ export function divBounce(container, divs, bounceMode, enabledCb) {
|
|
|
39
40
|
});
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
export function mouseBounce(container, enabledCb) {
|
|
43
|
-
const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos =
|
|
43
|
+
export function mouseBounce(container, interactivityData, enabledCb) {
|
|
44
|
+
const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.bounceModeDistance;
|
|
44
45
|
if (!radius || radius < minRadius || !mousePos) {
|
|
45
46
|
return;
|
|
46
47
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadExternalBounceInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(e => {
|
|
4
|
-
|
|
1
|
+
export async function loadExternalBounceInteraction(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.20");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
|
+
e.addInteractor?.("externalBounce", async (container) => {
|
|
5
7
|
const { Bouncer } = await import("./Bouncer.js");
|
|
6
8
|
return new Bouncer(container);
|
|
7
9
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-bounce",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.20",
|
|
4
4
|
"description": "tsParticles bounce 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.20",
|
|
91
|
+
"@tsparticles/plugin-interactivity": "4.0.0-alpha.20"
|
|
91
92
|
},
|
|
92
93
|
"publishConfig": {
|
|
93
94
|
"access": "public"
|