@tsparticles/interaction-external-attract 3.1.0 → 3.2.1

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/Attractor.js CHANGED
@@ -1,3 +1,26 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
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
+ };
1
24
  (function (factory) {
2
25
  if (typeof module === "object" && typeof module.exports === "object") {
3
26
  var v = factory(require, exports);
@@ -8,58 +31,15 @@
8
31
  }
9
32
  })(function (require, exports) {
10
33
  "use strict";
34
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
11
35
  Object.defineProperty(exports, "__esModule", { value: true });
12
36
  exports.Attractor = void 0;
13
37
  const engine_1 = require("@tsparticles/engine");
14
38
  const Attract_js_1 = require("./Options/Classes/Attract.js");
15
- const attractMode = "attract", minRadius = 0, minFactor = 1, identity = 1;
39
+ const attractMode = "attract";
16
40
  class Attractor extends engine_1.ExternalInteractorBase {
17
41
  constructor(engine, container) {
18
42
  super(container);
19
- this._clickAttract = () => {
20
- const container = this.container;
21
- if (!container.attract) {
22
- container.attract = { particles: [] };
23
- }
24
- const { attract } = container;
25
- if (!attract.finish) {
26
- if (!attract.count) {
27
- attract.count = 0;
28
- }
29
- attract.count++;
30
- if (attract.count === container.particles.count) {
31
- attract.finish = true;
32
- }
33
- }
34
- if (attract.clicking) {
35
- const mousePos = container.interactivity.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
36
- if (!attractRadius || attractRadius < minRadius || !mousePos) {
37
- return;
38
- }
39
- this._processAttract(mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius));
40
- }
41
- else if (attract.clicking === false) {
42
- attract.particles = [];
43
- }
44
- };
45
- this._hoverAttract = () => {
46
- const container = this.container, mousePos = container.interactivity.mouse.position, attractRadius = container.retina.attractModeDistance;
47
- if (!attractRadius || attractRadius < minRadius || !mousePos) {
48
- return;
49
- }
50
- this._processAttract(mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius));
51
- };
52
- this._processAttract = (position, attractRadius, area) => {
53
- const container = this.container, attractOptions = container.actualOptions.interactivity.modes.attract;
54
- if (!attractOptions) {
55
- return;
56
- }
57
- const query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
58
- for (const particle of query) {
59
- const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), velocity = attractOptions.speed * attractOptions.factor, attractFactor = (0, engine_1.clamp)((0, engine_1.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);
60
- particle.position.subFrom(normVec);
61
- }
62
- };
63
43
  this._engine = engine;
64
44
  if (!container.attract) {
65
45
  container.attract = { particles: [] };
@@ -103,14 +83,15 @@
103
83
  container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
104
84
  }
105
85
  async interact() {
106
- const container = this.container, options = container.actualOptions, mouseMoveStatus = container.interactivity.status === engine_1.mouseMoveEvent, events = options.interactivity.events, hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, clickEnabled = events.onClick.enable, clickMode = events.onClick.mode;
86
+ const container = this.container, options = container.actualOptions, mouseMoveStatus = container.interactivity.status === engine_1.mouseMoveEvent, events = options.interactivity.events, { enable: hoverEnabled, mode: hoverMode } = events.onHover, { enable: clickEnabled, mode: clickMode } = events.onClick;
107
87
  if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)(attractMode, hoverMode)) {
108
- this._hoverAttract();
88
+ const { hoverAttract } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_1, reject_1) => { require(["./Utils.js"], resolve_1, reject_1); }).then(__importStar));
89
+ hoverAttract(this.container, (p) => this.isEnabled(p));
109
90
  }
110
91
  else if (clickEnabled && (0, engine_1.isInArray)(attractMode, clickMode)) {
111
- this._clickAttract();
92
+ const { clickAttract } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_2, reject_2) => { require(["./Utils.js"], resolve_2, reject_2); }).then(__importStar));
93
+ clickAttract(this.container, (p) => this.isEnabled(p));
112
94
  }
113
- await Promise.resolve();
114
95
  }
115
96
  isEnabled(particle) {
116
97
  const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
package/umd/Utils.js ADDED
@@ -0,0 +1,60 @@
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.hoverAttract = exports.clickAttract = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const minFactor = 1, identity = 1, minRadius = 0;
15
+ function processAttract(container, position, attractRadius, area, queryCb) {
16
+ const attractOptions = container.actualOptions.interactivity.modes.attract;
17
+ if (!attractOptions) {
18
+ return;
19
+ }
20
+ const query = container.particles.quadTree.query(area, queryCb);
21
+ for (const particle of query) {
22
+ const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), velocity = attractOptions.speed * attractOptions.factor, attractFactor = (0, engine_1.clamp)((0, engine_1.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
+ particle.position.subFrom(normVec);
24
+ }
25
+ }
26
+ function clickAttract(container, enabledCb) {
27
+ if (!container.attract) {
28
+ container.attract = { particles: [] };
29
+ }
30
+ const { attract } = container;
31
+ if (!attract.finish) {
32
+ if (!attract.count) {
33
+ attract.count = 0;
34
+ }
35
+ attract.count++;
36
+ if (attract.count === container.particles.count) {
37
+ attract.finish = true;
38
+ }
39
+ }
40
+ if (attract.clicking) {
41
+ const mousePos = container.interactivity.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
42
+ if (!attractRadius || attractRadius < minRadius || !mousePos) {
43
+ return;
44
+ }
45
+ processAttract(container, mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius), (p) => enabledCb(p));
46
+ }
47
+ else if (attract.clicking === false) {
48
+ attract.particles = [];
49
+ }
50
+ }
51
+ exports.clickAttract = clickAttract;
52
+ function hoverAttract(container, enabledCb) {
53
+ const mousePos = container.interactivity.mouse.position, attractRadius = container.retina.attractModeDistance;
54
+ if (!attractRadius || attractRadius < minRadius || !mousePos) {
55
+ return;
56
+ }
57
+ processAttract(container, mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius), (p) => enabledCb(p));
58
+ }
59
+ exports.hoverAttract = hoverAttract;
60
+ });
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", "./Attractor.js", "./Options/Classes/Attract.js", "./Options/Interfaces/IAttract.js"], factory);
33
+ define(["require", "exports", "./Options/Classes/Attract.js", "./Options/Interfaces/IAttract.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.loadExternalAttractInteraction = void 0;
27
- const Attractor_js_1 = require("./Attractor.js");
28
40
  async function loadExternalAttractInteraction(engine, refresh = true) {
29
- await engine.addInteractor("externalAttract", (container) => new Attractor_js_1.Attractor(engine, container), refresh);
41
+ await engine.addInteractor("externalAttract", async (container) => {
42
+ const { Attractor } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Attractor.js"))) : new Promise((resolve_1, reject_1) => { require(["./Attractor.js"], resolve_1, reject_1); }).then(__importStar));
43
+ return new Attractor(engine, container);
44
+ }, refresh);
30
45
  }
31
46
  exports.loadExternalAttractInteraction = loadExternalAttractInteraction;
32
47
  __exportStar(require("./Options/Classes/Attract.js"), exports);