@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,401 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
55
+ /******/
56
+ /************************************************************************/
57
+ /******/ /* webpack/runtime/define property getters */
58
+ /******/ (() => {
59
+ /******/ // define getter functions for harmony exports
60
+ /******/ __webpack_require__.d = (exports, definition) => {
61
+ /******/ for(var key in definition) {
62
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
63
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
64
+ /******/ }
65
+ /******/ }
66
+ /******/ };
67
+ /******/ })();
68
+ /******/
69
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
+ /******/ (() => {
71
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
+ /******/ })();
73
+ /******/
74
+ /******/ /* webpack/runtime/make namespace object */
75
+ /******/ (() => {
76
+ /******/ // define __esModule on exports
77
+ /******/ __webpack_require__.r = (exports) => {
78
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
79
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
80
+ /******/ }
81
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
82
+ /******/ };
83
+ /******/ })();
84
+ /******/
85
+ /************************************************************************/
86
+ var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
89
+ // ESM COMPAT FLAG
90
+ __webpack_require__.r(__webpack_exports__);
91
+
92
+ // EXPORTS
93
+ __webpack_require__.d(__webpack_exports__, {
94
+ "Repulse": () => (/* reexport */ Repulse),
95
+ "RepulseBase": () => (/* reexport */ RepulseBase),
96
+ "RepulseDiv": () => (/* reexport */ RepulseDiv),
97
+ "loadExternalRepulseInteraction": () => (/* binding */ loadExternalRepulseInteraction)
98
+ });
99
+
100
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
101
+ var engine_root_window_ = __webpack_require__(533);
102
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/RepulseBase.js
103
+ class RepulseBase {
104
+ constructor() {
105
+ this.distance = 200;
106
+ this.duration = 0.4;
107
+ this.factor = 100;
108
+ this.speed = 1;
109
+ this.maxSpeed = 50;
110
+ this.easing = "ease-out-quad";
111
+ }
112
+ load(data) {
113
+ if (!data) {
114
+ return;
115
+ }
116
+ if (data.distance !== undefined) {
117
+ this.distance = data.distance;
118
+ }
119
+ if (data.duration !== undefined) {
120
+ this.duration = data.duration;
121
+ }
122
+ if (data.easing !== undefined) {
123
+ this.easing = data.easing;
124
+ }
125
+ if (data.factor !== undefined) {
126
+ this.factor = data.factor;
127
+ }
128
+ if (data.speed !== undefined) {
129
+ this.speed = data.speed;
130
+ }
131
+ if (data.maxSpeed !== undefined) {
132
+ this.maxSpeed = data.maxSpeed;
133
+ }
134
+ }
135
+ }
136
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/RepulseDiv.js
137
+
138
+
139
+ class RepulseDiv extends RepulseBase {
140
+ constructor() {
141
+ super();
142
+ this.selectors = [];
143
+ }
144
+ get ids() {
145
+ return (0,engine_root_window_.executeOnSingleOrMultiple)(this.selectors, t => t.replace("#", ""));
146
+ }
147
+ set ids(value) {
148
+ this.selectors = (0,engine_root_window_.executeOnSingleOrMultiple)(value, t => `#${t}`);
149
+ }
150
+ load(data) {
151
+ super.load(data);
152
+ if (!data) {
153
+ return;
154
+ }
155
+ if (data.ids !== undefined) {
156
+ this.ids = data.ids;
157
+ }
158
+ if (data.selectors !== undefined) {
159
+ this.selectors = data.selectors;
160
+ }
161
+ }
162
+ }
163
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Repulse.js
164
+
165
+
166
+
167
+ class Repulse extends RepulseBase {
168
+ load(data) {
169
+ super.load(data);
170
+ if (!data) {
171
+ return;
172
+ }
173
+ this.divs = (0,engine_root_window_.executeOnSingleOrMultiple)(data.divs, div => {
174
+ const tmp = new RepulseDiv();
175
+ tmp.load(div);
176
+ return tmp;
177
+ });
178
+ }
179
+ }
180
+ ;// CONCATENATED MODULE: ./dist/browser/Repulser.js
181
+
182
+
183
+ class Repulser extends engine_root_window_.ExternalInteractorBase {
184
+ constructor(engine, container) {
185
+ super(container);
186
+ this._engine = engine;
187
+ if (!container.repulse) {
188
+ container.repulse = {
189
+ particles: []
190
+ };
191
+ }
192
+ this.handleClickMode = mode => {
193
+ const options = this.container.actualOptions,
194
+ repulse = options.interactivity.modes.repulse;
195
+ if (!repulse || mode !== "repulse") {
196
+ return;
197
+ }
198
+ if (!container.repulse) {
199
+ container.repulse = {
200
+ particles: []
201
+ };
202
+ }
203
+ container.repulse.clicking = true;
204
+ container.repulse.count = 0;
205
+ for (const particle of container.repulse.particles) {
206
+ if (!this.isEnabled(particle)) {
207
+ continue;
208
+ }
209
+ particle.velocity.setTo(particle.initialVelocity);
210
+ }
211
+ container.repulse.particles = [];
212
+ container.repulse.finish = false;
213
+ setTimeout(() => {
214
+ if (!container.destroyed) {
215
+ if (!container.repulse) {
216
+ container.repulse = {
217
+ particles: []
218
+ };
219
+ }
220
+ container.repulse.clicking = false;
221
+ }
222
+ }, repulse.duration * 1000);
223
+ };
224
+ }
225
+ clear() {}
226
+ init() {
227
+ const container = this.container,
228
+ repulse = container.actualOptions.interactivity.modes.repulse;
229
+ if (!repulse) {
230
+ return;
231
+ }
232
+ container.retina.repulseModeDistance = repulse.distance * container.retina.pixelRatio;
233
+ }
234
+ async interact() {
235
+ const container = this.container,
236
+ options = container.actualOptions,
237
+ mouseMoveStatus = container.interactivity.status === engine_root_window_.mouseMoveEvent,
238
+ events = options.interactivity.events,
239
+ hoverEnabled = events.onHover.enable,
240
+ hoverMode = events.onHover.mode,
241
+ clickEnabled = events.onClick.enable,
242
+ clickMode = events.onClick.mode,
243
+ divs = events.onDiv;
244
+ if (mouseMoveStatus && hoverEnabled && (0,engine_root_window_.isInArray)("repulse", hoverMode)) {
245
+ this.hoverRepulse();
246
+ } else if (clickEnabled && (0,engine_root_window_.isInArray)("repulse", clickMode)) {
247
+ this.clickRepulse();
248
+ } else {
249
+ (0,engine_root_window_.divModeExecute)("repulse", divs, (selector, div) => this.singleSelectorRepulse(selector, div));
250
+ }
251
+ }
252
+ isEnabled(particle) {
253
+ var _a;
254
+ const container = this.container,
255
+ options = container.actualOptions,
256
+ mouse = container.interactivity.mouse,
257
+ events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events,
258
+ divs = events.onDiv,
259
+ divRepulse = (0,engine_root_window_.isDivModeEnabled)("repulse", divs);
260
+ if (!(divRepulse || events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
261
+ return false;
262
+ }
263
+ const hoverMode = events.onHover.mode,
264
+ clickMode = events.onClick.mode;
265
+ return (0,engine_root_window_.isInArray)("repulse", hoverMode) || (0,engine_root_window_.isInArray)("repulse", clickMode) || divRepulse;
266
+ }
267
+ loadModeOptions(options, ...sources) {
268
+ if (!options.repulse) {
269
+ options.repulse = new Repulse();
270
+ }
271
+ for (const source of sources) {
272
+ options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
273
+ }
274
+ }
275
+ reset() {}
276
+ clickRepulse() {
277
+ const container = this.container,
278
+ repulse = container.actualOptions.interactivity.modes.repulse;
279
+ if (!repulse) {
280
+ return;
281
+ }
282
+ if (!container.repulse) {
283
+ container.repulse = {
284
+ particles: []
285
+ };
286
+ }
287
+ if (!container.repulse.finish) {
288
+ if (!container.repulse.count) {
289
+ container.repulse.count = 0;
290
+ }
291
+ container.repulse.count++;
292
+ if (container.repulse.count === container.particles.count) {
293
+ container.repulse.finish = true;
294
+ }
295
+ }
296
+ if (container.repulse.clicking) {
297
+ const repulseDistance = container.retina.repulseModeDistance;
298
+ if (!repulseDistance || repulseDistance < 0) {
299
+ return;
300
+ }
301
+ const repulseRadius = Math.pow(repulseDistance / 6, 3),
302
+ mouseClickPos = container.interactivity.mouse.clickPosition;
303
+ if (mouseClickPos === undefined) {
304
+ return;
305
+ }
306
+ const range = new engine_root_window_.Circle(mouseClickPos.x, mouseClickPos.y, repulseRadius),
307
+ query = container.particles.quadTree.query(range, p => this.isEnabled(p));
308
+ for (const particle of query) {
309
+ const {
310
+ dx,
311
+ dy,
312
+ distance
313
+ } = (0,engine_root_window_.getDistances)(mouseClickPos, particle.position),
314
+ d = distance ** 2,
315
+ velocity = repulse.speed,
316
+ force = -repulseRadius * velocity / d;
317
+ if (d <= repulseRadius) {
318
+ container.repulse.particles.push(particle);
319
+ const vect = engine_root_window_.Vector.create(dx, dy);
320
+ vect.length = force;
321
+ particle.velocity.setTo(vect);
322
+ }
323
+ }
324
+ } else if (container.repulse.clicking === false) {
325
+ for (const particle of container.repulse.particles) {
326
+ particle.velocity.setTo(particle.initialVelocity);
327
+ }
328
+ container.repulse.particles = [];
329
+ }
330
+ }
331
+ hoverRepulse() {
332
+ const container = this.container,
333
+ mousePos = container.interactivity.mouse.position,
334
+ repulseRadius = container.retina.repulseModeDistance;
335
+ if (!repulseRadius || repulseRadius < 0 || !mousePos) {
336
+ return;
337
+ }
338
+ this.processRepulse(mousePos, repulseRadius, new engine_root_window_.Circle(mousePos.x, mousePos.y, repulseRadius));
339
+ }
340
+ processRepulse(position, repulseRadius, area, divRepulse) {
341
+ var _a;
342
+ const container = this.container,
343
+ query = container.particles.quadTree.query(area, p => this.isEnabled(p)),
344
+ repulseOptions = container.actualOptions.interactivity.modes.repulse;
345
+ if (!repulseOptions) {
346
+ return;
347
+ }
348
+ for (const particle of query) {
349
+ const {
350
+ dx,
351
+ dy,
352
+ distance
353
+ } = (0,engine_root_window_.getDistances)(particle.position, position),
354
+ velocity = ((_a = divRepulse === null || divRepulse === void 0 ? void 0 : divRepulse.speed) !== null && _a !== void 0 ? _a : repulseOptions.speed) * repulseOptions.factor,
355
+ repulseFactor = (0,engine_root_window_.clamp)((0,engine_root_window_.getEasing)(repulseOptions.easing)(1 - distance / repulseRadius) * velocity, 0, repulseOptions.maxSpeed),
356
+ normVec = engine_root_window_.Vector.create(distance === 0 ? velocity : dx / distance * repulseFactor, distance === 0 ? velocity : dy / distance * repulseFactor);
357
+ particle.position.addTo(normVec);
358
+ }
359
+ }
360
+ singleSelectorRepulse(selector, div) {
361
+ const container = this.container,
362
+ repulse = container.actualOptions.interactivity.modes.repulse;
363
+ if (!repulse) {
364
+ return;
365
+ }
366
+ const query = document.querySelectorAll(selector);
367
+ if (!query.length) {
368
+ return;
369
+ }
370
+ query.forEach(item => {
371
+ const elem = item,
372
+ pxRatio = container.retina.pixelRatio,
373
+ pos = {
374
+ x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
375
+ y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
376
+ },
377
+ repulseRadius = elem.offsetWidth / 2 * pxRatio,
378
+ area = div.type === "circle" ? new engine_root_window_.Circle(pos.x, pos.y, repulseRadius) : new engine_root_window_.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio),
379
+ divs = repulse.divs,
380
+ divRepulse = (0,engine_root_window_.divMode)(divs, elem);
381
+ this.processRepulse(pos, repulseRadius, area, divRepulse);
382
+ });
383
+ }
384
+ }
385
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
386
+
387
+ async function loadExternalRepulseInteraction(engine) {
388
+ await engine.addInteractor("externalRepulse", container => new Repulser(engine, container));
389
+ }
390
+
391
+
392
+
393
+
394
+
395
+
396
+ })();
397
+
398
+ /******/ return __webpack_exports__;
399
+ /******/ })()
400
+ ;
401
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.interaction.external.repulse.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 s="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in s)("object"==typeof exports?exports:e)[i]=s[i]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},s={};function i(e){var o=s[e];if(void 0!==o)return o.exports;var r=s[e]={exports:{}};return t[e](r,r.exports,i),r.exports}i.d=(e,t)=>{for(var s in t)i.o(t,s)&&!i.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{i.r(o),i.d(o,{Repulse:()=>r,RepulseBase:()=>t,RepulseDiv:()=>s,loadExternalRepulseInteraction:()=>l});var e=i(533);class t{constructor(){this.distance=200,this.duration=.4,this.factor=100,this.speed=1,this.maxSpeed=50,this.easing="ease-out-quad"}load(e){e&&(void 0!==e.distance&&(this.distance=e.distance),void 0!==e.duration&&(this.duration=e.duration),void 0!==e.easing&&(this.easing=e.easing),void 0!==e.factor&&(this.factor=e.factor),void 0!==e.speed&&(this.speed=e.speed),void 0!==e.maxSpeed&&(this.maxSpeed=e.maxSpeed))}}class s extends t{constructor(){super(),this.selectors=[]}get ids(){return(0,e.executeOnSingleOrMultiple)(this.selectors,(e=>e.replace("#","")))}set ids(t){this.selectors=(0,e.executeOnSingleOrMultiple)(t,(e=>`#${e}`))}load(e){super.load(e),e&&(void 0!==e.ids&&(this.ids=e.ids),void 0!==e.selectors&&(this.selectors=e.selectors))}}class r extends t{load(t){super.load(t),t&&(this.divs=(0,e.executeOnSingleOrMultiple)(t.divs,(e=>{const t=new s;return t.load(e),t})))}}class n extends e.ExternalInteractorBase{constructor(e,t){super(t),this._engine=e,t.repulse||(t.repulse={particles:[]}),this.handleClickMode=e=>{const s=this.container.actualOptions.interactivity.modes.repulse;if(s&&"repulse"===e){t.repulse||(t.repulse={particles:[]}),t.repulse.clicking=!0,t.repulse.count=0;for(const e of t.repulse.particles)this.isEnabled(e)&&e.velocity.setTo(e.initialVelocity);t.repulse.particles=[],t.repulse.finish=!1,setTimeout((()=>{t.destroyed||(t.repulse||(t.repulse={particles:[]}),t.repulse.clicking=!1)}),1e3*s.duration)}}}clear(){}init(){const e=this.container,t=e.actualOptions.interactivity.modes.repulse;t&&(e.retina.repulseModeDistance=t.distance*e.retina.pixelRatio)}async interact(){const t=this.container,s=t.actualOptions,i=t.interactivity.status===e.mouseMoveEvent,o=s.interactivity.events,r=o.onHover.enable,n=o.onHover.mode,l=o.onClick.enable,c=o.onClick.mode,a=o.onDiv;i&&r&&(0,e.isInArray)("repulse",n)?this.hoverRepulse():l&&(0,e.isInArray)("repulse",c)?this.clickRepulse():(0,e.divModeExecute)("repulse",a,((e,t)=>this.singleSelectorRepulse(e,t)))}isEnabled(t){var s;const i=this.container,o=i.actualOptions,r=i.interactivity.mouse,n=(null!==(s=null==t?void 0:t.interactivity)&&void 0!==s?s:o.interactivity).events,l=n.onDiv,c=(0,e.isDivModeEnabled)("repulse",l);if(!(c||n.onHover.enable&&r.position||n.onClick.enable&&r.clickPosition))return!1;const a=n.onHover.mode,p=n.onClick.mode;return(0,e.isInArray)("repulse",a)||(0,e.isInArray)("repulse",p)||c}loadModeOptions(e,...t){e.repulse||(e.repulse=new r);for(const s of t)e.repulse.load(null==s?void 0:s.repulse)}reset(){}clickRepulse(){const t=this.container,s=t.actualOptions.interactivity.modes.repulse;if(s)if(t.repulse||(t.repulse={particles:[]}),t.repulse.finish||(t.repulse.count||(t.repulse.count=0),t.repulse.count++,t.repulse.count===t.particles.count&&(t.repulse.finish=!0)),t.repulse.clicking){const i=t.retina.repulseModeDistance;if(!i||i<0)return;const o=Math.pow(i/6,3),r=t.interactivity.mouse.clickPosition;if(void 0===r)return;const n=new e.Circle(r.x,r.y,o),l=t.particles.quadTree.query(n,(e=>this.isEnabled(e)));for(const i of l){const{dx:n,dy:l,distance:c}=(0,e.getDistances)(r,i.position),a=c**2,p=-o*s.speed/a;if(a<=o){t.repulse.particles.push(i);const s=e.Vector.create(n,l);s.length=p,i.velocity.setTo(s)}}}else if(!1===t.repulse.clicking){for(const e of t.repulse.particles)e.velocity.setTo(e.initialVelocity);t.repulse.particles=[]}}hoverRepulse(){const t=this.container,s=t.interactivity.mouse.position,i=t.retina.repulseModeDistance;!i||i<0||!s||this.processRepulse(s,i,new e.Circle(s.x,s.y,i))}processRepulse(t,s,i,o){var r;const n=this.container,l=n.particles.quadTree.query(i,(e=>this.isEnabled(e))),c=n.actualOptions.interactivity.modes.repulse;if(c)for(const i of l){const{dx:n,dy:l,distance:a}=(0,e.getDistances)(i.position,t),p=(null!==(r=null==o?void 0:o.speed)&&void 0!==r?r:c.speed)*c.factor,u=(0,e.clamp)((0,e.getEasing)(c.easing)(1-a/s)*p,0,c.maxSpeed),d=e.Vector.create(0===a?p:n/a*u,0===a?p:l/a*u);i.position.addTo(d)}}singleSelectorRepulse(t,s){const i=this.container,o=i.actualOptions.interactivity.modes.repulse;if(!o)return;const r=document.querySelectorAll(t);r.length&&r.forEach((t=>{const r=t,n=i.retina.pixelRatio,l={x:(r.offsetLeft+r.offsetWidth/2)*n,y:(r.offsetTop+r.offsetHeight/2)*n},c=r.offsetWidth/2*n,a="circle"===s.type?new e.Circle(l.x,l.y,c):new e.Rectangle(r.offsetLeft*n,r.offsetTop*n,r.offsetWidth*n,r.offsetHeight*n),p=o.divs,u=(0,e.divMode)(p,r);this.processRepulse(l,c,a,u)}))}}async function l(e){await e.addInteractor("externalRepulse",(t=>new n(e,t)))}})(),o})()));
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
@@ -0,0 +1,8 @@
1
+ import type { IOptionLoader, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import type { IRepulse } from "../Interfaces/IRepulse";
3
+ import { RepulseBase } from "./RepulseBase";
4
+ import { RepulseDiv } from "./RepulseDiv";
5
+ export declare class Repulse extends RepulseBase implements IRepulse, IOptionLoader<IRepulse> {
6
+ divs?: SingleOrMultiple<RepulseDiv>;
7
+ load(data?: RecursivePartial<IRepulse>): void;
8
+ }
@@ -0,0 +1,13 @@
1
+ import type { EasingTypeAlt, IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import { EasingType } from "@tsparticles/engine";
3
+ import type { IRepulseBase } from "../Interfaces/IRepulseBase";
4
+ export declare abstract class RepulseBase implements IRepulseBase, IOptionLoader<IRepulseBase> {
5
+ distance: number;
6
+ duration: number;
7
+ easing: EasingType | EasingTypeAlt;
8
+ factor: number;
9
+ maxSpeed: number;
10
+ speed: number;
11
+ constructor();
12
+ load(data?: RecursivePartial<IRepulseBase>): void;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { IOptionLoader, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import type { IRepulseDiv } from "../Interfaces/IRepulseDiv";
3
+ import { RepulseBase } from "./RepulseBase";
4
+ export declare class RepulseDiv extends RepulseBase implements IRepulseDiv, IOptionLoader<IRepulseDiv> {
5
+ selectors: SingleOrMultiple<string>;
6
+ constructor();
7
+ get ids(): SingleOrMultiple<string>;
8
+ set ids(value: SingleOrMultiple<string>);
9
+ load(data?: RecursivePartial<IRepulseDiv>): void;
10
+ }
@@ -0,0 +1,7 @@
1
+ import type { Options } from "@tsparticles/engine";
2
+ import type { RepulseMode } from "../../Types";
3
+ export type RepulseOptions = Options & {
4
+ interactivity: {
5
+ modes: RepulseMode;
6
+ };
7
+ };
@@ -0,0 +1,6 @@
1
+ import type { IRepulseBase } from "./IRepulseBase";
2
+ import type { IRepulseDiv } from "./IRepulseDiv";
3
+ import type { SingleOrMultiple } from "@tsparticles/engine";
4
+ export interface IRepulse extends IRepulseBase {
5
+ divs?: SingleOrMultiple<IRepulseDiv>;
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { EasingType, EasingTypeAlt } from "@tsparticles/engine";
2
+ export interface IRepulseBase {
3
+ distance: number;
4
+ duration: number;
5
+ easing: EasingType | EasingTypeAlt;
6
+ factor: number;
7
+ maxSpeed: number;
8
+ speed: number;
9
+ }
@@ -0,0 +1,4 @@
1
+ import type { IModeDiv } from "@tsparticles/engine";
2
+ import type { IRepulseBase } from "./IRepulseBase";
3
+ export interface IRepulseDiv extends IRepulseBase, IModeDiv {
4
+ }
@@ -0,0 +1,18 @@
1
+ import { ExternalInteractorBase } from "@tsparticles/engine";
2
+ import type { Engine, IModes, Modes, Particle, RecursivePartial } from "@tsparticles/engine";
3
+ import type { IRepulseMode, RepulseContainer, RepulseMode } from "./Types";
4
+ export declare class Repulser extends ExternalInteractorBase<RepulseContainer> {
5
+ handleClickMode: (mode: string) => void;
6
+ private readonly _engine;
7
+ constructor(engine: Engine, container: RepulseContainer);
8
+ clear(): void;
9
+ init(): void;
10
+ interact(): Promise<void>;
11
+ isEnabled(particle?: Particle): boolean;
12
+ loadModeOptions(options: Modes & RepulseMode, ...sources: RecursivePartial<(IModes & IRepulseMode) | undefined>[]): void;
13
+ reset(): void;
14
+ private clickRepulse;
15
+ private hoverRepulse;
16
+ private processRepulse;
17
+ private singleSelectorRepulse;
18
+ }
@@ -0,0 +1,24 @@
1
+ import type { Container, Particle } from "@tsparticles/engine";
2
+ import type { IRepulse } from "./Options/Interfaces/IRepulse";
3
+ import type { Repulse } from "./Options/Classes/Repulse";
4
+ import type { RepulseOptions } from "./Options/Classes/RepulseOptions";
5
+ export type IRepulseMode = {
6
+ repulse: IRepulse;
7
+ };
8
+ export type RepulseMode = {
9
+ repulse?: Repulse;
10
+ };
11
+ interface IContainerRepulse {
12
+ clicking?: boolean;
13
+ count?: number;
14
+ finish?: boolean;
15
+ particles: Particle[];
16
+ }
17
+ export type RepulseContainer = Container & {
18
+ actualOptions: RepulseOptions;
19
+ repulse?: IContainerRepulse;
20
+ retina: {
21
+ repulseModeDistance?: number;
22
+ };
23
+ };
24
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadExternalRepulseInteraction(engine: Engine): Promise<void>;
3
+ export * from "./Options/Classes/RepulseBase";
4
+ export * from "./Options/Classes/RepulseDiv";
5
+ export * from "./Options/Classes/Repulse";
6
+ export * from "./Options/Interfaces/IRepulseBase";
7
+ export * from "./Options/Interfaces/IRepulseDiv";
8
+ export * from "./Options/Interfaces/IRepulse";
@@ -0,0 +1,30 @@
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", "./RepulseBase", "./RepulseDiv", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Repulse = void 0;
13
+ const RepulseBase_1 = require("./RepulseBase");
14
+ const RepulseDiv_1 = require("./RepulseDiv");
15
+ const engine_1 = require("@tsparticles/engine");
16
+ class Repulse extends RepulseBase_1.RepulseBase {
17
+ load(data) {
18
+ super.load(data);
19
+ if (!data) {
20
+ return;
21
+ }
22
+ this.divs = (0, engine_1.executeOnSingleOrMultiple)(data.divs, (div) => {
23
+ const tmp = new RepulseDiv_1.RepulseDiv();
24
+ tmp.load(div);
25
+ return tmp;
26
+ });
27
+ }
28
+ }
29
+ exports.Repulse = Repulse;
30
+ });
@@ -0,0 +1,47 @@
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
+ exports.RepulseBase = void 0;
13
+ class RepulseBase {
14
+ constructor() {
15
+ this.distance = 200;
16
+ this.duration = 0.4;
17
+ this.factor = 100;
18
+ this.speed = 1;
19
+ this.maxSpeed = 50;
20
+ this.easing = "ease-out-quad";
21
+ }
22
+ load(data) {
23
+ if (!data) {
24
+ return;
25
+ }
26
+ if (data.distance !== undefined) {
27
+ this.distance = data.distance;
28
+ }
29
+ if (data.duration !== undefined) {
30
+ this.duration = data.duration;
31
+ }
32
+ if (data.easing !== undefined) {
33
+ this.easing = data.easing;
34
+ }
35
+ if (data.factor !== undefined) {
36
+ this.factor = data.factor;
37
+ }
38
+ if (data.speed !== undefined) {
39
+ this.speed = data.speed;
40
+ }
41
+ if (data.maxSpeed !== undefined) {
42
+ this.maxSpeed = data.maxSpeed;
43
+ }
44
+ }
45
+ }
46
+ exports.RepulseBase = RepulseBase;
47
+ });
@@ -0,0 +1,40 @@
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", "./RepulseBase", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RepulseDiv = void 0;
13
+ const RepulseBase_1 = require("./RepulseBase");
14
+ const engine_1 = require("@tsparticles/engine");
15
+ class RepulseDiv extends RepulseBase_1.RepulseBase {
16
+ constructor() {
17
+ super();
18
+ this.selectors = [];
19
+ }
20
+ get ids() {
21
+ return (0, engine_1.executeOnSingleOrMultiple)(this.selectors, (t) => t.replace("#", ""));
22
+ }
23
+ set ids(value) {
24
+ this.selectors = (0, engine_1.executeOnSingleOrMultiple)(value, (t) => `#${t}`);
25
+ }
26
+ load(data) {
27
+ super.load(data);
28
+ if (!data) {
29
+ return;
30
+ }
31
+ if (data.ids !== undefined) {
32
+ this.ids = data.ids;
33
+ }
34
+ if (data.selectors !== undefined) {
35
+ this.selectors = data.selectors;
36
+ }
37
+ }
38
+ }
39
+ exports.RepulseDiv = RepulseDiv;
40
+ });