@tsparticles/interaction-external-bounce 4.0.0-alpha.5 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/520.min.js +1 -0
- package/README.md +5 -0
- package/browser/Bouncer.js +6 -0
- package/browser/Options/Classes/Bounce.js +1 -0
- package/browser/Utils.js +1 -1
- package/browser/index.js +3 -3
- package/cjs/Bouncer.js +6 -0
- package/cjs/Options/Classes/Bounce.js +1 -0
- package/cjs/Utils.js +1 -1
- package/cjs/index.js +3 -3
- package/dist_browser_Bouncer_js.js +3 -3
- package/esm/Bouncer.js +6 -0
- package/esm/Options/Classes/Bounce.js +1 -0
- package/esm/Utils.js +1 -1
- package/esm/index.js +3 -3
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.interaction.external.bounce.js +41 -29
- package/tsparticles.interaction.external.bounce.min.js +2 -2
- package/types/Bouncer.d.ts +2 -0
- package/umd/Bouncer.js +6 -0
- package/umd/Options/Classes/Bounce.js +1 -0
- package/umd/Utils.js +1 -1
- package/umd/index.js +3 -3
- package/820.min.js +0 -2
- package/820.min.js.LICENSE.txt +0 -1
- package/tsparticles.interaction.external.bounce.min.js.LICENSE.txt +0 -1
package/520.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_interaction_external_bounce=this.webpackChunk_tsparticles_interaction_external_bounce||[]).push([[520],{520(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.grid.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(521);let s="bounce";class u extends o.ExternalInteractorBase{_maxDistance;constructor(e){super(e),this._maxDistance=0}get maxDistance(){return this._maxDistance}clear(){}init(){let e=this.container,t=e.actualOptions.interactivity?.modes.bounce;t&&(this._maxDistance=t.distance,e.retina.bounceModeDistance=t.distance*e.retina.pixelRatio)}interact(e){var t,i,a,r;let l=this.container.actualOptions,u=l.interactivity?.events,m=e.status===o.mouseMoveEvent;if(!u)return;let f=u.onHover.enable,d=u.onHover.mode,v=u.onDiv;if(m&&f&&(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,m=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,m)})})}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
|
@@ -4,8 +4,13 @@ import { divBounce, mouseBounce } from "./Utils.js";
|
|
|
4
4
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
|
5
5
|
const bounceMode = "bounce";
|
|
6
6
|
export class Bouncer extends ExternalInteractorBase {
|
|
7
|
+
_maxDistance;
|
|
7
8
|
constructor(container) {
|
|
8
9
|
super(container);
|
|
10
|
+
this._maxDistance = 0;
|
|
11
|
+
}
|
|
12
|
+
get maxDistance() {
|
|
13
|
+
return this._maxDistance;
|
|
9
14
|
}
|
|
10
15
|
clear() {
|
|
11
16
|
}
|
|
@@ -14,6 +19,7 @@ export class Bouncer extends ExternalInteractorBase {
|
|
|
14
19
|
if (!bounce) {
|
|
15
20
|
return;
|
|
16
21
|
}
|
|
22
|
+
this._maxDistance = bounce.distance;
|
|
17
23
|
container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
|
18
24
|
}
|
|
19
25
|
interact(interactivityData) {
|
package/browser/Utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Circle, Rectangle, Vector, calculateBounds, circleBounce, circleBounceD
|
|
|
2
2
|
import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
|
|
3
3
|
const squareExp = 2, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;
|
|
4
4
|
function processBounce(container, position, radius, area, enabledCb) {
|
|
5
|
-
const query = container.particles.
|
|
5
|
+
const query = container.particles.grid.query(area, enabledCb);
|
|
6
6
|
for (const particle of query) {
|
|
7
7
|
if (area instanceof Circle) {
|
|
8
8
|
circleBounce(circleBounceDataFromParticle(particle), {
|
package/browser/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function loadExternalBounceInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("externalBounce", async (container) => {
|
|
7
7
|
const { Bouncer } = await import("./Bouncer.js");
|
|
8
8
|
return new Bouncer(container);
|
package/cjs/Bouncer.js
CHANGED
|
@@ -4,8 +4,13 @@ import { divBounce, mouseBounce } from "./Utils.js";
|
|
|
4
4
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
|
5
5
|
const bounceMode = "bounce";
|
|
6
6
|
export class Bouncer extends ExternalInteractorBase {
|
|
7
|
+
_maxDistance;
|
|
7
8
|
constructor(container) {
|
|
8
9
|
super(container);
|
|
10
|
+
this._maxDistance = 0;
|
|
11
|
+
}
|
|
12
|
+
get maxDistance() {
|
|
13
|
+
return this._maxDistance;
|
|
9
14
|
}
|
|
10
15
|
clear() {
|
|
11
16
|
}
|
|
@@ -14,6 +19,7 @@ export class Bouncer extends ExternalInteractorBase {
|
|
|
14
19
|
if (!bounce) {
|
|
15
20
|
return;
|
|
16
21
|
}
|
|
22
|
+
this._maxDistance = bounce.distance;
|
|
17
23
|
container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
|
18
24
|
}
|
|
19
25
|
interact(interactivityData) {
|
package/cjs/Utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Circle, Rectangle, Vector, calculateBounds, circleBounce, circleBounceD
|
|
|
2
2
|
import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
|
|
3
3
|
const squareExp = 2, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;
|
|
4
4
|
function processBounce(container, position, radius, area, enabledCb) {
|
|
5
|
-
const query = container.particles.
|
|
5
|
+
const query = container.particles.grid.query(area, enabledCb);
|
|
6
6
|
for (const particle of query) {
|
|
7
7
|
if (area instanceof Circle) {
|
|
8
8
|
circleBounce(circleBounceDataFromParticle(particle), {
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function loadExternalBounceInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("externalBounce", async (container) => {
|
|
7
7
|
const { Bouncer } = await import("./Bouncer.js");
|
|
8
8
|
return new Bouncer(container);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v4.0.0-
|
|
7
|
+
* v4.0.0-beta.0
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\*********************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
25
|
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ 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
|
|
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 _maxDistance;\n constructor(container){\n super(container);\n this._maxDistance = 0;\n }\n get maxDistance() {\n return this._maxDistance;\n }\n clear() {}\n init() {\n const container = this.container, bounce = container.actualOptions.interactivity?.modes.bounce;\n if (!bounce) {\n return;\n }\n this._maxDistance = bounce.distance;\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/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n\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.grid.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
|
@@ -4,8 +4,13 @@ import { divBounce, mouseBounce } from "./Utils.js";
|
|
|
4
4
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
|
5
5
|
const bounceMode = "bounce";
|
|
6
6
|
export class Bouncer extends ExternalInteractorBase {
|
|
7
|
+
_maxDistance;
|
|
7
8
|
constructor(container) {
|
|
8
9
|
super(container);
|
|
10
|
+
this._maxDistance = 0;
|
|
11
|
+
}
|
|
12
|
+
get maxDistance() {
|
|
13
|
+
return this._maxDistance;
|
|
9
14
|
}
|
|
10
15
|
clear() {
|
|
11
16
|
}
|
|
@@ -14,6 +19,7 @@ export class Bouncer extends ExternalInteractorBase {
|
|
|
14
19
|
if (!bounce) {
|
|
15
20
|
return;
|
|
16
21
|
}
|
|
22
|
+
this._maxDistance = bounce.distance;
|
|
17
23
|
container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
|
18
24
|
}
|
|
19
25
|
interact(interactivityData) {
|
package/esm/Utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Circle, Rectangle, Vector, calculateBounds, circleBounce, circleBounceD
|
|
|
2
2
|
import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
|
|
3
3
|
const squareExp = 2, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0, minVelocity = 0;
|
|
4
4
|
function processBounce(container, position, radius, area, enabledCb) {
|
|
5
|
-
const query = container.particles.
|
|
5
|
+
const query = container.particles.grid.query(area, enabledCb);
|
|
6
6
|
for (const particle of query) {
|
|
7
7
|
if (area instanceof Circle) {
|
|
8
8
|
circleBounce(circleBounceDataFromParticle(particle), {
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export async function loadExternalBounceInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("externalBounce", async (container) => {
|
|
7
7
|
const { Bouncer } = await import("./Bouncer.js");
|
|
8
8
|
return new Bouncer(container);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-bounce",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles bounce external interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "4.0.0-
|
|
91
|
-
"@tsparticles/plugin-interactivity": "4.0.0-
|
|
90
|
+
"@tsparticles/engine": "4.0.0-beta.0",
|
|
91
|
+
"@tsparticles/plugin-interactivity": "4.0.0-beta.0"
|
|
92
92
|
},
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"access": "public"
|