@tsparticles/interaction-external-bounce 3.0.3 → 3.2.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/umd/Utils.js ADDED
@@ -0,0 +1,59 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.mouseBounce = exports.divBounce = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const squareExp = 2, half = 0.5, halfPI = Math.PI * half, double = 2, toleranceFactor = 10, minRadius = 0;
15
+ function processBounce(container, position, radius, area, enabledCb) {
16
+ const query = container.particles.quadTree.query(area, enabledCb);
17
+ for (const particle of query) {
18
+ if (area instanceof engine_1.Circle) {
19
+ (0, engine_1.circleBounce)((0, engine_1.circleBounceDataFromParticle)(particle), {
20
+ position,
21
+ radius,
22
+ mass: radius ** squareExp * halfPI,
23
+ velocity: engine_1.Vector.origin,
24
+ factor: engine_1.Vector.origin,
25
+ });
26
+ }
27
+ else if (area instanceof engine_1.Rectangle) {
28
+ (0, engine_1.rectBounce)(particle, (0, engine_1.calculateBounds)(position, radius));
29
+ }
30
+ }
31
+ }
32
+ function singleSelectorBounce(container, selector, div, bounceCb) {
33
+ const query = document.querySelectorAll(selector);
34
+ if (!query.length) {
35
+ return;
36
+ }
37
+ query.forEach((item) => {
38
+ const elem = item, pxRatio = container.retina.pixelRatio, pos = {
39
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
40
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
41
+ }, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === "circle"
42
+ ? new engine_1.Circle(pos.x, pos.y, radius + tolerance)
43
+ : new engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
44
+ bounceCb(pos, radius, area);
45
+ });
46
+ }
47
+ function divBounce(container, divs, bounceMode, enabledCb) {
48
+ (0, engine_1.divModeExecute)(bounceMode, divs, (selector, div) => singleSelectorBounce(container, selector, div, (pos, radius, area) => processBounce(container, pos, radius, area, enabledCb)));
49
+ }
50
+ exports.divBounce = divBounce;
51
+ function mouseBounce(container, enabledCb) {
52
+ const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance;
53
+ if (!radius || radius < minRadius || !mousePos) {
54
+ return;
55
+ }
56
+ processBounce(container, mousePos, radius, new engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance), enabledCb);
57
+ }
58
+ exports.mouseBounce = mouseBounce;
59
+ });
package/umd/index.js CHANGED
@@ -9,6 +9,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
9
  if (k2 === undefined) k2 = k;
10
10
  o[k2] = m[k];
11
11
  }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
12
24
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
13
25
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
26
  };
@@ -18,15 +30,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
30
  if (v !== undefined) module.exports = v;
19
31
  }
20
32
  else if (typeof define === "function" && define.amd) {
21
- define(["require", "exports", "./Bouncer.js", "./Options/Classes/Bounce.js", "./Options/Interfaces/IBounce.js"], factory);
33
+ define(["require", "exports", "./Options/Classes/Bounce.js", "./Options/Interfaces/IBounce.js"], factory);
22
34
  }
23
35
  })(function (require, exports) {
24
36
  "use strict";
37
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
25
38
  Object.defineProperty(exports, "__esModule", { value: true });
26
39
  exports.loadExternalBounceInteraction = void 0;
27
- const Bouncer_js_1 = require("./Bouncer.js");
28
40
  async function loadExternalBounceInteraction(engine, refresh = true) {
29
- await engine.addInteractor("externalBounce", (container) => new Bouncer_js_1.Bouncer(container), refresh);
41
+ await engine.addInteractor("externalBounce", async (container) => {
42
+ const { Bouncer } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Bouncer.js"))) : new Promise((resolve_1, reject_1) => { require(["./Bouncer.js"], resolve_1, reject_1); }).then(__importStar));
43
+ return new Bouncer(container);
44
+ }, refresh);
30
45
  }
31
46
  exports.loadExternalBounceInteraction = loadExternalBounceInteraction;
32
47
  __exportStar(require("./Options/Classes/Bounce.js"), exports);