@tsparticles/interaction-external-repulse 3.0.0-alpha.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Options/Classes/Repulse.js +16 -0
  4. package/browser/Options/Classes/RepulseBase.js +33 -0
  5. package/browser/Options/Classes/RepulseDiv.js +26 -0
  6. package/browser/Options/Classes/RepulseOptions.js +1 -0
  7. package/browser/Options/Interfaces/IRepulse.js +1 -0
  8. package/browser/Options/Interfaces/IRepulseBase.js +1 -0
  9. package/browser/Options/Interfaces/IRepulseDiv.js +1 -0
  10. package/browser/Repulser.js +159 -0
  11. package/browser/Types.js +1 -0
  12. package/browser/index.js +10 -0
  13. package/cjs/Options/Classes/Repulse.js +20 -0
  14. package/cjs/Options/Classes/RepulseBase.js +37 -0
  15. package/cjs/Options/Classes/RepulseDiv.js +30 -0
  16. package/cjs/Options/Classes/RepulseOptions.js +2 -0
  17. package/cjs/Options/Interfaces/IRepulse.js +2 -0
  18. package/cjs/Options/Interfaces/IRepulseBase.js +2 -0
  19. package/cjs/Options/Interfaces/IRepulseDiv.js +2 -0
  20. package/cjs/Repulser.js +174 -0
  21. package/cjs/Types.js +2 -0
  22. package/cjs/index.js +39 -0
  23. package/esm/Options/Classes/Repulse.js +16 -0
  24. package/esm/Options/Classes/RepulseBase.js +33 -0
  25. package/esm/Options/Classes/RepulseDiv.js +26 -0
  26. package/esm/Options/Classes/RepulseOptions.js +1 -0
  27. package/esm/Options/Interfaces/IRepulse.js +1 -0
  28. package/esm/Options/Interfaces/IRepulseBase.js +1 -0
  29. package/esm/Options/Interfaces/IRepulseDiv.js +1 -0
  30. package/esm/Repulser.js +159 -0
  31. package/esm/Types.js +1 -0
  32. package/esm/index.js +10 -0
  33. package/package.json +82 -0
  34. package/report.html +39 -0
  35. package/tsparticles.interaction.external.repulse.js +401 -0
  36. package/tsparticles.interaction.external.repulse.min.js +2 -0
  37. package/tsparticles.interaction.external.repulse.min.js.LICENSE.txt +8 -0
  38. package/types/Options/Classes/Repulse.d.ts +8 -0
  39. package/types/Options/Classes/RepulseBase.d.ts +13 -0
  40. package/types/Options/Classes/RepulseDiv.d.ts +10 -0
  41. package/types/Options/Classes/RepulseOptions.d.ts +7 -0
  42. package/types/Options/Interfaces/IRepulse.d.ts +6 -0
  43. package/types/Options/Interfaces/IRepulseBase.d.ts +9 -0
  44. package/types/Options/Interfaces/IRepulseDiv.d.ts +4 -0
  45. package/types/Repulser.d.ts +18 -0
  46. package/types/Types.d.ts +24 -0
  47. package/types/index.d.ts +8 -0
  48. package/umd/Options/Classes/Repulse.js +30 -0
  49. package/umd/Options/Classes/RepulseBase.js +47 -0
  50. package/umd/Options/Classes/RepulseDiv.js +40 -0
  51. package/umd/Options/Classes/RepulseOptions.js +12 -0
  52. package/umd/Options/Interfaces/IRepulse.js +12 -0
  53. package/umd/Options/Interfaces/IRepulseBase.js +12 -0
  54. package/umd/Options/Interfaces/IRepulseDiv.js +12 -0
  55. package/umd/Repulser.js +173 -0
  56. package/umd/Types.js +12 -0
  57. package/umd/index.js +38 -0
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,173 @@
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", "./Options/Classes/Repulse"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Repulser = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Repulse_1 = require("./Options/Classes/Repulse");
15
+ class Repulser extends engine_1.ExternalInteractorBase {
16
+ constructor(engine, container) {
17
+ super(container);
18
+ this._engine = engine;
19
+ if (!container.repulse) {
20
+ container.repulse = { particles: [] };
21
+ }
22
+ this.handleClickMode = (mode) => {
23
+ const options = this.container.actualOptions, repulse = options.interactivity.modes.repulse;
24
+ if (!repulse || mode !== "repulse") {
25
+ return;
26
+ }
27
+ if (!container.repulse) {
28
+ container.repulse = { particles: [] };
29
+ }
30
+ container.repulse.clicking = true;
31
+ container.repulse.count = 0;
32
+ for (const particle of container.repulse.particles) {
33
+ if (!this.isEnabled(particle)) {
34
+ continue;
35
+ }
36
+ particle.velocity.setTo(particle.initialVelocity);
37
+ }
38
+ container.repulse.particles = [];
39
+ container.repulse.finish = false;
40
+ setTimeout(() => {
41
+ if (!container.destroyed) {
42
+ if (!container.repulse) {
43
+ container.repulse = { particles: [] };
44
+ }
45
+ container.repulse.clicking = false;
46
+ }
47
+ }, repulse.duration * 1000);
48
+ };
49
+ }
50
+ clear() {
51
+ }
52
+ init() {
53
+ const container = this.container, repulse = container.actualOptions.interactivity.modes.repulse;
54
+ if (!repulse) {
55
+ return;
56
+ }
57
+ container.retina.repulseModeDistance = repulse.distance * container.retina.pixelRatio;
58
+ }
59
+ async interact() {
60
+ 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, divs = events.onDiv;
61
+ if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)("repulse", hoverMode)) {
62
+ this.hoverRepulse();
63
+ }
64
+ else if (clickEnabled && (0, engine_1.isInArray)("repulse", clickMode)) {
65
+ this.clickRepulse();
66
+ }
67
+ else {
68
+ (0, engine_1.divModeExecute)("repulse", divs, (selector, div) => this.singleSelectorRepulse(selector, div));
69
+ }
70
+ }
71
+ isEnabled(particle) {
72
+ var _a;
73
+ const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events, divs = events.onDiv, divRepulse = (0, engine_1.isDivModeEnabled)("repulse", divs);
74
+ if (!(divRepulse || (events.onHover.enable && mouse.position) || (events.onClick.enable && mouse.clickPosition))) {
75
+ return false;
76
+ }
77
+ const hoverMode = events.onHover.mode, clickMode = events.onClick.mode;
78
+ return (0, engine_1.isInArray)("repulse", hoverMode) || (0, engine_1.isInArray)("repulse", clickMode) || divRepulse;
79
+ }
80
+ loadModeOptions(options, ...sources) {
81
+ if (!options.repulse) {
82
+ options.repulse = new Repulse_1.Repulse();
83
+ }
84
+ for (const source of sources) {
85
+ options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
86
+ }
87
+ }
88
+ reset() {
89
+ }
90
+ clickRepulse() {
91
+ const container = this.container, repulse = container.actualOptions.interactivity.modes.repulse;
92
+ if (!repulse) {
93
+ return;
94
+ }
95
+ if (!container.repulse) {
96
+ container.repulse = { particles: [] };
97
+ }
98
+ if (!container.repulse.finish) {
99
+ if (!container.repulse.count) {
100
+ container.repulse.count = 0;
101
+ }
102
+ container.repulse.count++;
103
+ if (container.repulse.count === container.particles.count) {
104
+ container.repulse.finish = true;
105
+ }
106
+ }
107
+ if (container.repulse.clicking) {
108
+ const repulseDistance = container.retina.repulseModeDistance;
109
+ if (!repulseDistance || repulseDistance < 0) {
110
+ return;
111
+ }
112
+ const repulseRadius = Math.pow(repulseDistance / 6, 3), mouseClickPos = container.interactivity.mouse.clickPosition;
113
+ if (mouseClickPos === undefined) {
114
+ return;
115
+ }
116
+ const range = new engine_1.Circle(mouseClickPos.x, mouseClickPos.y, repulseRadius), query = container.particles.quadTree.query(range, (p) => this.isEnabled(p));
117
+ for (const particle of query) {
118
+ const { dx, dy, distance } = (0, engine_1.getDistances)(mouseClickPos, particle.position), d = distance ** 2, velocity = repulse.speed, force = (-repulseRadius * velocity) / d;
119
+ if (d <= repulseRadius) {
120
+ container.repulse.particles.push(particle);
121
+ const vect = engine_1.Vector.create(dx, dy);
122
+ vect.length = force;
123
+ particle.velocity.setTo(vect);
124
+ }
125
+ }
126
+ }
127
+ else if (container.repulse.clicking === false) {
128
+ for (const particle of container.repulse.particles) {
129
+ particle.velocity.setTo(particle.initialVelocity);
130
+ }
131
+ container.repulse.particles = [];
132
+ }
133
+ }
134
+ hoverRepulse() {
135
+ const container = this.container, mousePos = container.interactivity.mouse.position, repulseRadius = container.retina.repulseModeDistance;
136
+ if (!repulseRadius || repulseRadius < 0 || !mousePos) {
137
+ return;
138
+ }
139
+ this.processRepulse(mousePos, repulseRadius, new engine_1.Circle(mousePos.x, mousePos.y, repulseRadius));
140
+ }
141
+ processRepulse(position, repulseRadius, area, divRepulse) {
142
+ var _a;
143
+ const container = this.container, query = container.particles.quadTree.query(area, (p) => this.isEnabled(p)), repulseOptions = container.actualOptions.interactivity.modes.repulse;
144
+ if (!repulseOptions) {
145
+ return;
146
+ }
147
+ for (const particle of query) {
148
+ const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), velocity = ((_a = divRepulse === null || divRepulse === void 0 ? void 0 : divRepulse.speed) !== null && _a !== void 0 ? _a : repulseOptions.speed) * repulseOptions.factor, repulseFactor = (0, engine_1.clamp)((0, engine_1.getEasing)(repulseOptions.easing)(1 - distance / repulseRadius) * velocity, 0, repulseOptions.maxSpeed), normVec = engine_1.Vector.create(distance === 0 ? velocity : (dx / distance) * repulseFactor, distance === 0 ? velocity : (dy / distance) * repulseFactor);
149
+ particle.position.addTo(normVec);
150
+ }
151
+ }
152
+ singleSelectorRepulse(selector, div) {
153
+ const container = this.container, repulse = container.actualOptions.interactivity.modes.repulse;
154
+ if (!repulse) {
155
+ return;
156
+ }
157
+ const query = document.querySelectorAll(selector);
158
+ if (!query.length) {
159
+ return;
160
+ }
161
+ query.forEach((item) => {
162
+ const elem = item, pxRatio = container.retina.pixelRatio, pos = {
163
+ x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
164
+ y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio,
165
+ }, repulseRadius = (elem.offsetWidth / 2) * pxRatio, area = div.type === "circle"
166
+ ? new engine_1.Circle(pos.x, pos.y, repulseRadius)
167
+ : new engine_1.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), divs = repulse.divs, divRepulse = (0, engine_1.divMode)(divs, elem);
168
+ this.processRepulse(pos, repulseRadius, area, divRepulse);
169
+ });
170
+ }
171
+ }
172
+ exports.Repulser = Repulser;
173
+ });
package/umd/Types.js ADDED
@@ -0,0 +1,12 @@
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"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/index.js ADDED
@@ -0,0 +1,38 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
13
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
14
+ };
15
+ (function (factory) {
16
+ if (typeof module === "object" && typeof module.exports === "object") {
17
+ var v = factory(require, exports);
18
+ if (v !== undefined) module.exports = v;
19
+ }
20
+ else if (typeof define === "function" && define.amd) {
21
+ define(["require", "exports", "./Repulser", "./Options/Classes/RepulseBase", "./Options/Classes/RepulseDiv", "./Options/Classes/Repulse", "./Options/Interfaces/IRepulseBase", "./Options/Interfaces/IRepulseDiv", "./Options/Interfaces/IRepulse"], factory);
22
+ }
23
+ })(function (require, exports) {
24
+ "use strict";
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.loadExternalRepulseInteraction = void 0;
27
+ const Repulser_1 = require("./Repulser");
28
+ async function loadExternalRepulseInteraction(engine) {
29
+ await engine.addInteractor("externalRepulse", (container) => new Repulser_1.Repulser(engine, container));
30
+ }
31
+ exports.loadExternalRepulseInteraction = loadExternalRepulseInteraction;
32
+ __exportStar(require("./Options/Classes/RepulseBase"), exports);
33
+ __exportStar(require("./Options/Classes/RepulseDiv"), exports);
34
+ __exportStar(require("./Options/Classes/Repulse"), exports);
35
+ __exportStar(require("./Options/Interfaces/IRepulseBase"), exports);
36
+ __exportStar(require("./Options/Interfaces/IRepulseDiv"), exports);
37
+ __exportStar(require("./Options/Interfaces/IRepulse"), exports);
38
+ });