@tsparticles/interaction-external-attract 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/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,6 +31,7 @@
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");
@@ -16,54 +40,6 @@
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 < 0 || !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
- return;
45
- };
46
- this._hoverAttract = () => {
47
- const container = this.container, mousePos = container.interactivity.mouse.position, attractRadius = container.retina.attractModeDistance;
48
- if (!attractRadius || attractRadius < 0 || !mousePos) {
49
- return;
50
- }
51
- this._processAttract(mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius));
52
- };
53
- this._processAttract = (position, attractRadius, area) => {
54
- const container = this.container, attractOptions = container.actualOptions.interactivity.modes.attract;
55
- if (!attractOptions) {
56
- return;
57
- }
58
- const query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
59
- for (const particle of query) {
60
- const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position);
61
- const velocity = attractOptions.speed * attractOptions.factor;
62
- const attractFactor = (0, engine_1.clamp)((0, engine_1.getEasing)(attractOptions.easing)(1 - distance / attractRadius) * velocity, 0, attractOptions.maxSpeed);
63
- const normVec = engine_1.Vector.create(distance === 0 ? velocity : (dx / distance) * attractFactor, distance === 0 ? velocity : (dy / distance) * attractFactor);
64
- particle.position.subFrom(normVec);
65
- }
66
- };
67
43
  this._engine = engine;
68
44
  if (!container.attract) {
69
45
  container.attract = { particles: [] };
@@ -94,7 +70,7 @@
94
70
  container.attract = { particles: [] };
95
71
  }
96
72
  container.attract.clicking = false;
97
- }, attract.duration * 1000);
73
+ }, attract.duration * engine_1.millisecondsToSeconds);
98
74
  };
99
75
  }
100
76
  clear() {
@@ -107,12 +83,14 @@
107
83
  container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
108
84
  }
109
85
  async interact() {
110
- 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;
111
87
  if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)(attractMode, hoverMode)) {
112
- 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));
113
90
  }
114
91
  else if (clickEnabled && (0, engine_1.isInArray)(attractMode, clickMode)) {
115
- 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));
116
94
  }
117
95
  }
118
96
  isEnabled(particle) {
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);