@tsparticles/interaction-external-bounce 3.0.3 → 3.1.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/browser/Bouncer.js +10 -9
- package/cjs/Bouncer.js +10 -9
- package/esm/Bouncer.js +10 -9
- package/package.json +2 -2
- package/report.html +2 -2
- package/tsparticles.interaction.external.bounce.js +18 -11
- package/tsparticles.interaction.external.bounce.min.js +1 -1
- package/tsparticles.interaction.external.bounce.min.js.LICENSE.txt +1 -1
- package/types/Types.d.ts +4 -4
- package/umd/Bouncer.js +10 -9
package/browser/Bouncer.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Circle, ExternalInteractorBase, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, divModeExecute, isDivModeEnabled, isInArray, mouseMoveEvent, rectBounce, } from "@tsparticles/engine";
|
2
2
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
3
|
-
const bounceMode = "bounce";
|
3
|
+
const bounceMode = "bounce", squareExp = 2, double = 2, half = 0.5, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0;
|
4
4
|
export class Bouncer extends ExternalInteractorBase {
|
5
5
|
constructor(container) {
|
6
6
|
super(container);
|
@@ -11,7 +11,7 @@ export class Bouncer extends ExternalInteractorBase {
|
|
11
11
|
circleBounce(circleBounceDataFromParticle(particle), {
|
12
12
|
position,
|
13
13
|
radius,
|
14
|
-
mass:
|
14
|
+
mass: radius ** squareExp * halfPI,
|
15
15
|
velocity: Vector.origin,
|
16
16
|
factor: Vector.origin,
|
17
17
|
});
|
@@ -22,8 +22,8 @@ export class Bouncer extends ExternalInteractorBase {
|
|
22
22
|
}
|
23
23
|
};
|
24
24
|
this._processMouseBounce = () => {
|
25
|
-
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance =
|
26
|
-
if (!radius || radius <
|
25
|
+
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance;
|
26
|
+
if (!radius || radius < minRadius || !mousePos) {
|
27
27
|
return;
|
28
28
|
}
|
29
29
|
this._processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance));
|
@@ -35,11 +35,11 @@ export class Bouncer extends ExternalInteractorBase {
|
|
35
35
|
}
|
36
36
|
query.forEach((item) => {
|
37
37
|
const elem = item, pxRatio = container.retina.pixelRatio, pos = {
|
38
|
-
x: (elem.offsetLeft + elem.offsetWidth
|
39
|
-
y: (elem.offsetTop + elem.offsetHeight
|
40
|
-
}, radius =
|
38
|
+
x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
|
39
|
+
y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
|
40
|
+
}, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === "circle"
|
41
41
|
? new Circle(pos.x, pos.y, radius + tolerance)
|
42
|
-
: new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance *
|
42
|
+
: new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
|
43
43
|
this._processBounce(pos, radius, area);
|
44
44
|
});
|
45
45
|
};
|
@@ -61,10 +61,11 @@ export class Bouncer extends ExternalInteractorBase {
|
|
61
61
|
else {
|
62
62
|
divModeExecute(bounceMode, divs, (selector, div) => this._singleSelectorBounce(selector, div));
|
63
63
|
}
|
64
|
+
await Promise.resolve();
|
64
65
|
}
|
65
66
|
isEnabled(particle) {
|
66
67
|
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv;
|
67
|
-
return ((mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
68
|
+
return ((!!mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
68
69
|
isDivModeEnabled(bounceMode, divs));
|
69
70
|
}
|
70
71
|
loadModeOptions(options, ...sources) {
|
package/cjs/Bouncer.js
CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Bouncer = void 0;
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
5
5
|
const Bounce_js_1 = require("./Options/Classes/Bounce.js");
|
6
|
-
const bounceMode = "bounce";
|
6
|
+
const bounceMode = "bounce", squareExp = 2, double = 2, half = 0.5, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0;
|
7
7
|
class Bouncer extends engine_1.ExternalInteractorBase {
|
8
8
|
constructor(container) {
|
9
9
|
super(container);
|
@@ -14,7 +14,7 @@ class Bouncer extends engine_1.ExternalInteractorBase {
|
|
14
14
|
(0, engine_1.circleBounce)((0, engine_1.circleBounceDataFromParticle)(particle), {
|
15
15
|
position,
|
16
16
|
radius,
|
17
|
-
mass:
|
17
|
+
mass: radius ** squareExp * halfPI,
|
18
18
|
velocity: engine_1.Vector.origin,
|
19
19
|
factor: engine_1.Vector.origin,
|
20
20
|
});
|
@@ -25,8 +25,8 @@ class Bouncer extends engine_1.ExternalInteractorBase {
|
|
25
25
|
}
|
26
26
|
};
|
27
27
|
this._processMouseBounce = () => {
|
28
|
-
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance =
|
29
|
-
if (!radius || radius <
|
28
|
+
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance;
|
29
|
+
if (!radius || radius < minRadius || !mousePos) {
|
30
30
|
return;
|
31
31
|
}
|
32
32
|
this._processBounce(mousePos, radius, new engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance));
|
@@ -38,11 +38,11 @@ class Bouncer extends engine_1.ExternalInteractorBase {
|
|
38
38
|
}
|
39
39
|
query.forEach((item) => {
|
40
40
|
const elem = item, pxRatio = container.retina.pixelRatio, pos = {
|
41
|
-
x: (elem.offsetLeft + elem.offsetWidth
|
42
|
-
y: (elem.offsetTop + elem.offsetHeight
|
43
|
-
}, radius =
|
41
|
+
x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
|
42
|
+
y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
|
43
|
+
}, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === "circle"
|
44
44
|
? new engine_1.Circle(pos.x, pos.y, radius + tolerance)
|
45
|
-
: new engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance *
|
45
|
+
: new engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
|
46
46
|
this._processBounce(pos, radius, area);
|
47
47
|
});
|
48
48
|
};
|
@@ -64,10 +64,11 @@ class Bouncer extends engine_1.ExternalInteractorBase {
|
|
64
64
|
else {
|
65
65
|
(0, engine_1.divModeExecute)(bounceMode, divs, (selector, div) => this._singleSelectorBounce(selector, div));
|
66
66
|
}
|
67
|
+
await Promise.resolve();
|
67
68
|
}
|
68
69
|
isEnabled(particle) {
|
69
70
|
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv;
|
70
|
-
return ((mouse.position && events.onHover.enable && (0, engine_1.isInArray)(bounceMode, events.onHover.mode)) ||
|
71
|
+
return ((!!mouse.position && events.onHover.enable && (0, engine_1.isInArray)(bounceMode, events.onHover.mode)) ||
|
71
72
|
(0, engine_1.isDivModeEnabled)(bounceMode, divs));
|
72
73
|
}
|
73
74
|
loadModeOptions(options, ...sources) {
|
package/esm/Bouncer.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Circle, ExternalInteractorBase, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, divModeExecute, isDivModeEnabled, isInArray, mouseMoveEvent, rectBounce, } from "@tsparticles/engine";
|
2
2
|
import { Bounce } from "./Options/Classes/Bounce.js";
|
3
|
-
const bounceMode = "bounce";
|
3
|
+
const bounceMode = "bounce", squareExp = 2, double = 2, half = 0.5, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0;
|
4
4
|
export class Bouncer extends ExternalInteractorBase {
|
5
5
|
constructor(container) {
|
6
6
|
super(container);
|
@@ -11,7 +11,7 @@ export class Bouncer extends ExternalInteractorBase {
|
|
11
11
|
circleBounce(circleBounceDataFromParticle(particle), {
|
12
12
|
position,
|
13
13
|
radius,
|
14
|
-
mass:
|
14
|
+
mass: radius ** squareExp * halfPI,
|
15
15
|
velocity: Vector.origin,
|
16
16
|
factor: Vector.origin,
|
17
17
|
});
|
@@ -22,8 +22,8 @@ export class Bouncer extends ExternalInteractorBase {
|
|
22
22
|
}
|
23
23
|
};
|
24
24
|
this._processMouseBounce = () => {
|
25
|
-
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance =
|
26
|
-
if (!radius || radius <
|
25
|
+
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance;
|
26
|
+
if (!radius || radius < minRadius || !mousePos) {
|
27
27
|
return;
|
28
28
|
}
|
29
29
|
this._processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance));
|
@@ -35,11 +35,11 @@ export class Bouncer extends ExternalInteractorBase {
|
|
35
35
|
}
|
36
36
|
query.forEach((item) => {
|
37
37
|
const elem = item, pxRatio = container.retina.pixelRatio, pos = {
|
38
|
-
x: (elem.offsetLeft + elem.offsetWidth
|
39
|
-
y: (elem.offsetTop + elem.offsetHeight
|
40
|
-
}, radius =
|
38
|
+
x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
|
39
|
+
y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
|
40
|
+
}, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === "circle"
|
41
41
|
? new Circle(pos.x, pos.y, radius + tolerance)
|
42
|
-
: new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance *
|
42
|
+
: new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
|
43
43
|
this._processBounce(pos, radius, area);
|
44
44
|
});
|
45
45
|
};
|
@@ -61,10 +61,11 @@ export class Bouncer extends ExternalInteractorBase {
|
|
61
61
|
else {
|
62
62
|
divModeExecute(bounceMode, divs, (selector, div) => this._singleSelectorBounce(selector, div));
|
63
63
|
}
|
64
|
+
await Promise.resolve();
|
64
65
|
}
|
65
66
|
isEnabled(particle) {
|
66
67
|
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv;
|
67
|
-
return ((mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
68
|
+
return ((!!mouse.position && events.onHover.enable && isInArray(bounceMode, events.onHover.mode)) ||
|
68
69
|
isDivModeEnabled(bounceMode, divs));
|
69
70
|
}
|
70
71
|
loadModeOptions(options, ...sources) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tsparticles/interaction-external-bounce",
|
3
|
-
"version": "3.0
|
3
|
+
"version": "3.1.0",
|
4
4
|
"description": "tsParticles bounce external interaction",
|
5
5
|
"homepage": "https://particles.js.org",
|
6
6
|
"repository": {
|
@@ -87,7 +87,7 @@
|
|
87
87
|
"./package.json": "./package.json"
|
88
88
|
},
|
89
89
|
"dependencies": {
|
90
|
-
"@tsparticles/engine": "^3.0
|
90
|
+
"@tsparticles/engine": "^3.1.0"
|
91
91
|
},
|
92
92
|
"publishConfig": {
|
93
93
|
"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-bounce [
|
6
|
+
<title>@tsparticles/interaction-external-bounce [13 Jan 2024 at 22:58]</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>
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<body>
|
32
32
|
<div id="app"></div>
|
33
33
|
<script>
|
34
|
-
window.chartData = [{"label":"tsparticles.interaction.external.bounce.js","isAsset":true,"statSize":
|
34
|
+
window.chartData = [{"label":"tsparticles.interaction.external.bounce.js","isAsset":true,"statSize":4544,"parsedSize":8532,"gzipSize":2539,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":4502,"groups":[{"id":199,"label":"index.js + 2 modules (concatenated)","path":"./dist/browser/index.js + 2 modules (concatenated)","statSize":4502,"parsedSize":8532,"gzipSize":2539,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser","statSize":4502,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/index.js","statSize":307,"parsedSize":581,"gzipSize":173,"inaccurateSizes":true},{"id":null,"label":"Bouncer.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/Bouncer.js","statSize":3987,"parsedSize":7555,"gzipSize":2248,"inaccurateSizes":true},{"label":"Options/Classes","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/Options/Classes","statSize":208,"groups":[{"id":null,"label":"Bounce.js","path":"./dist/browser/index.js + 2 modules (concatenated)/dist/browser/Options/Classes/Bounce.js","statSize":208,"parsedSize":394,"gzipSize":117,"inaccurateSizes":true}],"parsedSize":394,"gzipSize":117,"inaccurateSizes":true}],"parsedSize":8532,"gzipSize":2539,"inaccurateSizes":true}]}],"parsedSize":8532,"gzipSize":2539},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.interaction.external.bounce":true}}];
|
35
35
|
window.entrypoints = ["tsparticles.interaction.external.bounce","tsparticles.interaction.external.bounce.min"];
|
36
36
|
window.defaultSizes = "parsed";
|
37
37
|
</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
|
-
* v3.0
|
7
|
+
* v3.1.0
|
8
8
|
*/
|
9
9
|
(function webpackUniversalModuleDefinition(root, factory) {
|
10
10
|
if(typeof exports === 'object' && typeof module === 'object')
|
@@ -114,7 +114,13 @@ class Bounce {
|
|
114
114
|
;// CONCATENATED MODULE: ./dist/browser/Bouncer.js
|
115
115
|
|
116
116
|
|
117
|
-
const bounceMode = "bounce"
|
117
|
+
const bounceMode = "bounce",
|
118
|
+
squareExp = 2,
|
119
|
+
Bouncer_double = 2,
|
120
|
+
half = 0.5,
|
121
|
+
halfPI = Math.PI * half,
|
122
|
+
toleranceFactor = 10,
|
123
|
+
minRadius = 0;
|
118
124
|
class Bouncer extends engine_root_window_.ExternalInteractorBase {
|
119
125
|
constructor(container) {
|
120
126
|
super(container);
|
@@ -125,7 +131,7 @@ class Bouncer extends engine_root_window_.ExternalInteractorBase {
|
|
125
131
|
(0,engine_root_window_.circleBounce)((0,engine_root_window_.circleBounceDataFromParticle)(particle), {
|
126
132
|
position,
|
127
133
|
radius,
|
128
|
-
mass: radius **
|
134
|
+
mass: radius ** squareExp * halfPI,
|
129
135
|
velocity: engine_root_window_.Vector.origin,
|
130
136
|
factor: engine_root_window_.Vector.origin
|
131
137
|
});
|
@@ -137,10 +143,10 @@ class Bouncer extends engine_root_window_.ExternalInteractorBase {
|
|
137
143
|
this._processMouseBounce = () => {
|
138
144
|
const container = this.container,
|
139
145
|
pxRatio = container.retina.pixelRatio,
|
140
|
-
tolerance =
|
146
|
+
tolerance = toleranceFactor * pxRatio,
|
141
147
|
mousePos = container.interactivity.mouse.position,
|
142
148
|
radius = container.retina.bounceModeDistance;
|
143
|
-
if (!radius || radius <
|
149
|
+
if (!radius || radius < minRadius || !mousePos) {
|
144
150
|
return;
|
145
151
|
}
|
146
152
|
this._processBounce(mousePos, radius, new engine_root_window_.Circle(mousePos.x, mousePos.y, radius + tolerance));
|
@@ -155,12 +161,12 @@ class Bouncer extends engine_root_window_.ExternalInteractorBase {
|
|
155
161
|
const elem = item,
|
156
162
|
pxRatio = container.retina.pixelRatio,
|
157
163
|
pos = {
|
158
|
-
x: (elem.offsetLeft + elem.offsetWidth
|
159
|
-
y: (elem.offsetTop + elem.offsetHeight
|
164
|
+
x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
|
165
|
+
y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio
|
160
166
|
},
|
161
|
-
radius = elem.offsetWidth
|
162
|
-
tolerance =
|
163
|
-
area = div.type === "circle" ? new engine_root_window_.Circle(pos.x, pos.y, radius + tolerance) : new engine_root_window_.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance *
|
167
|
+
radius = elem.offsetWidth * half * pxRatio,
|
168
|
+
tolerance = toleranceFactor * pxRatio,
|
169
|
+
area = div.type === "circle" ? new engine_root_window_.Circle(pos.x, pos.y, radius + tolerance) : new engine_root_window_.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * Bouncer_double, elem.offsetHeight * pxRatio + tolerance * Bouncer_double);
|
164
170
|
this._processBounce(pos, radius, area);
|
165
171
|
});
|
166
172
|
};
|
@@ -187,6 +193,7 @@ class Bouncer extends engine_root_window_.ExternalInteractorBase {
|
|
187
193
|
} else {
|
188
194
|
(0,engine_root_window_.divModeExecute)(bounceMode, divs, (selector, div) => this._singleSelectorBounce(selector, div));
|
189
195
|
}
|
196
|
+
await Promise.resolve();
|
190
197
|
}
|
191
198
|
isEnabled(particle) {
|
192
199
|
const container = this.container,
|
@@ -194,7 +201,7 @@ class Bouncer extends engine_root_window_.ExternalInteractorBase {
|
|
194
201
|
mouse = container.interactivity.mouse,
|
195
202
|
events = (particle?.interactivity ?? options.interactivity).events,
|
196
203
|
divs = events.onDiv;
|
197
|
-
return mouse.position && events.onHover.enable && (0,engine_root_window_.isInArray)(bounceMode, events.onHover.mode) || (0,engine_root_window_.isDivModeEnabled)(bounceMode, divs);
|
204
|
+
return !!mouse.position && events.onHover.enable && (0,engine_root_window_.isInArray)(bounceMode, events.onHover.mode) || (0,engine_root_window_.isDivModeEnabled)(bounceMode, divs);
|
198
205
|
}
|
199
206
|
loadModeOptions(options, ...sources) {
|
200
207
|
if (!options.bounce) {
|
@@ -1,2 +1,2 @@
|
|
1
1
|
/*! For license information please see tsparticles.interaction.external.bounce.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 o="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},o={};function n(e){var i=o[e];if(void 0!==i)return i.exports;var r=o[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.r(i),n.d(i,{Bounce:()=>t,loadExternalBounceInteraction:()=>
|
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 o="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},o={};function n(e){var i=o[e];if(void 0!==i)return i.exports;var r=o[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.r(i),n.d(i,{Bounce:()=>t,loadExternalBounceInteraction:()=>a});var e=n(533);class t{constructor(){this.distance=200}load(e){e&&void 0!==e.distance&&(this.distance=e.distance)}}const o="bounce",r=.5,s=Math.PI*r;class c extends e.ExternalInteractorBase{constructor(t){super(t),this._processBounce=(t,o,n)=>{const i=this.container.particles.quadTree.query(n,(e=>this.isEnabled(e)));for(const r of i)n instanceof e.Circle?(0,e.circleBounce)((0,e.circleBounceDataFromParticle)(r),{position:t,radius:o,mass:o**2*s,velocity:e.Vector.origin,factor:e.Vector.origin}):n instanceof e.Rectangle&&(0,e.rectBounce)(r,(0,e.calculateBounds)(t,o))},this._processMouseBounce=()=>{const t=this.container,o=10*t.retina.pixelRatio,n=t.interactivity.mouse.position,i=t.retina.bounceModeDistance;!i||i<0||!n||this._processBounce(n,i,new e.Circle(n.x,n.y,i+o))},this._singleSelectorBounce=(t,o)=>{const n=this.container,i=document.querySelectorAll(t);i.length&&i.forEach((t=>{const i=t,s=n.retina.pixelRatio,c={x:(i.offsetLeft+i.offsetWidth*r)*s,y:(i.offsetTop+i.offsetHeight*r)*s},a=i.offsetWidth*r*s,l=10*s,u="circle"===o.type?new e.Circle(c.x,c.y,a+l):new e.Rectangle(i.offsetLeft*s-l,i.offsetTop*s-l,i.offsetWidth*s+2*l,i.offsetHeight*s+2*l);this._processBounce(c,a,u)}))}}clear(){}init(){const e=this.container,t=e.actualOptions.interactivity.modes.bounce;t&&(e.retina.bounceModeDistance=t.distance*e.retina.pixelRatio)}async interact(){const t=this.container,n=t.actualOptions.interactivity.events,i=t.interactivity.status===e.mouseMoveEvent,r=n.onHover.enable,s=n.onHover.mode,c=n.onDiv;i&&r&&(0,e.isInArray)(o,s)?this._processMouseBounce():(0,e.divModeExecute)(o,c,((e,t)=>this._singleSelectorBounce(e,t))),await Promise.resolve()}isEnabled(t){const n=this.container,i=n.actualOptions,r=n.interactivity.mouse,s=(t?.interactivity??i.interactivity).events,c=s.onDiv;return!!r.position&&s.onHover.enable&&(0,e.isInArray)(o,s.onHover.mode)||(0,e.isDivModeEnabled)(o,c)}loadModeOptions(e,...o){e.bounce||(e.bounce=new t);for(const t of o)e.bounce.load(t?.bounce)}reset(){}}async function a(e,t=!0){await e.addInteractor("externalBounce",(e=>new c(e)),t)}})(),i})()));
|
@@ -1 +1 @@
|
|
1
|
-
/*! tsParticles Bounce External Interaction v3.0
|
1
|
+
/*! tsParticles Bounce External Interaction v3.1.0 by Matteo Bruni */
|
package/types/Types.d.ts
CHANGED
@@ -2,12 +2,12 @@ import type { Bounce } from "./Options/Classes/Bounce.js";
|
|
2
2
|
import type { BounceOptions } from "./Options/Classes/BounceOptions.js";
|
3
3
|
import type { Container } from "@tsparticles/engine";
|
4
4
|
import type { IBounce } from "./Options/Interfaces/IBounce.js";
|
5
|
-
export
|
5
|
+
export interface IBounceMode {
|
6
6
|
bounce: IBounce;
|
7
|
-
}
|
8
|
-
export
|
7
|
+
}
|
8
|
+
export interface BounceMode {
|
9
9
|
bounce?: Bounce;
|
10
|
-
}
|
10
|
+
}
|
11
11
|
export type BounceContainer = Container & {
|
12
12
|
actualOptions: BounceOptions;
|
13
13
|
retina: {
|
package/umd/Bouncer.js
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
exports.Bouncer = void 0;
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
14
14
|
const Bounce_js_1 = require("./Options/Classes/Bounce.js");
|
15
|
-
const bounceMode = "bounce";
|
15
|
+
const bounceMode = "bounce", squareExp = 2, double = 2, half = 0.5, halfPI = Math.PI * half, toleranceFactor = 10, minRadius = 0;
|
16
16
|
class Bouncer extends engine_1.ExternalInteractorBase {
|
17
17
|
constructor(container) {
|
18
18
|
super(container);
|
@@ -23,7 +23,7 @@
|
|
23
23
|
(0, engine_1.circleBounce)((0, engine_1.circleBounceDataFromParticle)(particle), {
|
24
24
|
position,
|
25
25
|
radius,
|
26
|
-
mass:
|
26
|
+
mass: radius ** squareExp * halfPI,
|
27
27
|
velocity: engine_1.Vector.origin,
|
28
28
|
factor: engine_1.Vector.origin,
|
29
29
|
});
|
@@ -34,8 +34,8 @@
|
|
34
34
|
}
|
35
35
|
};
|
36
36
|
this._processMouseBounce = () => {
|
37
|
-
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance =
|
38
|
-
if (!radius || radius <
|
37
|
+
const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance;
|
38
|
+
if (!radius || radius < minRadius || !mousePos) {
|
39
39
|
return;
|
40
40
|
}
|
41
41
|
this._processBounce(mousePos, radius, new engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance));
|
@@ -47,11 +47,11 @@
|
|
47
47
|
}
|
48
48
|
query.forEach((item) => {
|
49
49
|
const elem = item, pxRatio = container.retina.pixelRatio, pos = {
|
50
|
-
x: (elem.offsetLeft + elem.offsetWidth
|
51
|
-
y: (elem.offsetTop + elem.offsetHeight
|
52
|
-
}, radius =
|
50
|
+
x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
|
51
|
+
y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
|
52
|
+
}, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === "circle"
|
53
53
|
? new engine_1.Circle(pos.x, pos.y, radius + tolerance)
|
54
|
-
: new engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance *
|
54
|
+
: new engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
|
55
55
|
this._processBounce(pos, radius, area);
|
56
56
|
});
|
57
57
|
};
|
@@ -73,10 +73,11 @@
|
|
73
73
|
else {
|
74
74
|
(0, engine_1.divModeExecute)(bounceMode, divs, (selector, div) => this._singleSelectorBounce(selector, div));
|
75
75
|
}
|
76
|
+
await Promise.resolve();
|
76
77
|
}
|
77
78
|
isEnabled(particle) {
|
78
79
|
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv;
|
79
|
-
return ((mouse.position && events.onHover.enable && (0, engine_1.isInArray)(bounceMode, events.onHover.mode)) ||
|
80
|
+
return ((!!mouse.position && events.onHover.enable && (0, engine_1.isInArray)(bounceMode, events.onHover.mode)) ||
|
80
81
|
(0, engine_1.isDivModeEnabled)(bounceMode, divs));
|
81
82
|
}
|
82
83
|
loadModeOptions(options, ...sources) {
|