@tsparticles/interaction-external-repulse 3.0.0-beta.2 → 3.0.0-beta.4

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.
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-beta.2
7
+ * v3.0.0-beta.4
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -170,6 +170,7 @@ class Repulse extends RepulseBase {
170
170
  ;// CONCATENATED MODULE: ./dist/browser/Repulser.js
171
171
 
172
172
 
173
+ const repulseMode = "repulse";
173
174
  class Repulser extends engine_root_window_.ExternalInteractorBase {
174
175
  constructor(engine, container) {
175
176
  super(container);
@@ -242,14 +243,21 @@ class Repulser extends engine_root_window_.ExternalInteractorBase {
242
243
  if (!repulseOptions) {
243
244
  return;
244
245
  }
246
+ const {
247
+ easing,
248
+ speed,
249
+ factor,
250
+ maxSpeed
251
+ } = repulseOptions,
252
+ easingFunc = (0,engine_root_window_.getEasing)(easing),
253
+ velocity = (divRepulse?.speed ?? speed) * factor;
245
254
  for (const particle of query) {
246
255
  const {
247
256
  dx,
248
257
  dy,
249
258
  distance
250
259
  } = (0,engine_root_window_.getDistances)(particle.position, position),
251
- velocity = (divRepulse?.speed ?? repulseOptions.speed) * repulseOptions.factor,
252
- repulseFactor = (0,engine_root_window_.clamp)((0,engine_root_window_.getEasing)(repulseOptions.easing)(1 - distance / repulseRadius) * velocity, 0, repulseOptions.maxSpeed),
260
+ repulseFactor = (0,engine_root_window_.clamp)(easingFunc(1 - distance / repulseRadius) * velocity, 0, maxSpeed),
253
261
  normVec = engine_root_window_.Vector.create(distance === 0 ? velocity : dx / distance * repulseFactor, distance === 0 ? velocity : dy / distance * repulseFactor);
254
262
  particle.position.addTo(normVec);
255
263
  }
@@ -287,7 +295,7 @@ class Repulser extends engine_root_window_.ExternalInteractorBase {
287
295
  this.handleClickMode = mode => {
288
296
  const options = this.container.actualOptions,
289
297
  repulseOpts = options.interactivity.modes.repulse;
290
- if (!repulseOpts || mode !== "repulse") {
298
+ if (!repulseOpts || mode !== repulseMode) {
291
299
  return;
292
300
  }
293
301
  if (!container.repulse) {
@@ -335,12 +343,12 @@ class Repulser extends engine_root_window_.ExternalInteractorBase {
335
343
  clickEnabled = click.enable,
336
344
  clickMode = click.mode,
337
345
  divs = events.onDiv;
338
- if (mouseMoveStatus && hoverEnabled && (0,engine_root_window_.isInArray)("repulse", hoverMode)) {
346
+ if (mouseMoveStatus && hoverEnabled && (0,engine_root_window_.isInArray)(repulseMode, hoverMode)) {
339
347
  this._hoverRepulse();
340
- } else if (clickEnabled && (0,engine_root_window_.isInArray)("repulse", clickMode)) {
348
+ } else if (clickEnabled && (0,engine_root_window_.isInArray)(repulseMode, clickMode)) {
341
349
  this._clickRepulse();
342
350
  } else {
343
- (0,engine_root_window_.divModeExecute)("repulse", divs, (selector, div) => this._singleSelectorRepulse(selector, div));
351
+ (0,engine_root_window_.divModeExecute)(repulseMode, divs, (selector, div) => this._singleSelectorRepulse(selector, div));
344
352
  }
345
353
  }
346
354
  isEnabled(particle) {
@@ -351,13 +359,13 @@ class Repulser extends engine_root_window_.ExternalInteractorBase {
351
359
  divs = events.onDiv,
352
360
  hover = events.onHover,
353
361
  click = events.onClick,
354
- divRepulse = (0,engine_root_window_.isDivModeEnabled)("repulse", divs);
362
+ divRepulse = (0,engine_root_window_.isDivModeEnabled)(repulseMode, divs);
355
363
  if (!(divRepulse || hover.enable && mouse.position || click.enable && mouse.clickPosition)) {
356
364
  return false;
357
365
  }
358
366
  const hoverMode = hover.mode,
359
367
  clickMode = click.mode;
360
- return (0,engine_root_window_.isInArray)("repulse", hoverMode) || (0,engine_root_window_.isInArray)("repulse", clickMode) || divRepulse;
368
+ return (0,engine_root_window_.isInArray)(repulseMode, hoverMode) || (0,engine_root_window_.isInArray)(repulseMode, clickMode) || divRepulse;
361
369
  }
362
370
  loadModeOptions(options, ...sources) {
363
371
  if (!options.repulse) {
@@ -1,2 +1,2 @@
1
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 i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var s in i)("object"==typeof exports?exports:e)[s]=i[s]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function s(e){var o=i[e];if(void 0!==o)return o.exports;var n=i[e]={exports:{}};return t[e](n,n.exports,s),n.exports}s.d=(e,t)=>{for(var i in t)s.o(t,i)&&!s.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{s.r(o),s.d(o,{Repulse:()=>n,RepulseBase:()=>t,RepulseDiv:()=>i,loadExternalRepulseInteraction:()=>c});var e=s(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 i extends t{constructor(){super(),this.selectors=[]}load(e){super.load(e),e&&void 0!==e.selectors&&(this.selectors=e.selectors)}}class n extends t{load(t){super.load(t),t&&(this.divs=(0,e.executeOnSingleOrMultiple)(t.divs,(e=>{const t=new i;return t.load(e),t})))}}class r extends e.ExternalInteractorBase{constructor(t,i){super(i),this._clickRepulse=()=>{const t=this.container,i=t.actualOptions.interactivity.modes.repulse;if(!i)return;const s=t.repulse||{particles:[]};if(s.finish||(s.count||(s.count=0),s.count++,s.count===t.particles.count&&(s.finish=!0)),s.clicking){const o=t.retina.repulseModeDistance;if(!o||o<0)return;const n=Math.pow(o/6,3),r=t.interactivity.mouse.clickPosition;if(void 0===r)return;const c=new e.Circle(r.x,r.y,n),a=t.particles.quadTree.query(c,(e=>this.isEnabled(e)));for(const t of a){const{dx:o,dy:c,distance:a}=(0,e.getDistances)(r,t.position),l=a**2,p=-n*i.speed/l;if(l<=n){s.particles.push(t);const i=e.Vector.create(o,c);i.length=p,t.velocity.setTo(i)}}}else if(!1===s.clicking){for(const e of s.particles)e.velocity.setTo(e.initialVelocity);s.particles=[]}},this._hoverRepulse=()=>{const t=this.container,i=t.interactivity.mouse.position,s=t.retina.repulseModeDistance;!s||s<0||!i||this._processRepulse(i,s,new e.Circle(i.x,i.y,s))},this._processRepulse=(t,i,s,o)=>{const n=this.container,r=n.particles.quadTree.query(s,(e=>this.isEnabled(e))),c=n.actualOptions.interactivity.modes.repulse;if(c)for(const s of r){const{dx:n,dy:r,distance:a}=(0,e.getDistances)(s.position,t),l=(o?.speed??c.speed)*c.factor,p=(0,e.clamp)((0,e.getEasing)(c.easing)(1-a/i)*l,0,c.maxSpeed),u=e.Vector.create(0===a?l:n/a*p,0===a?l:r/a*p);s.position.addTo(u)}},this._singleSelectorRepulse=(t,i)=>{const s=this.container,o=s.actualOptions.interactivity.modes.repulse;if(!o)return;const n=document.querySelectorAll(t);n.length&&n.forEach((t=>{const n=t,r=s.retina.pixelRatio,c={x:(n.offsetLeft+n.offsetWidth/2)*r,y:(n.offsetTop+n.offsetHeight/2)*r},a=n.offsetWidth/2*r,l="circle"===i.type?new e.Circle(c.x,c.y,a):new e.Rectangle(n.offsetLeft*r,n.offsetTop*r,n.offsetWidth*r,n.offsetHeight*r),p=o.divs,u=(0,e.divMode)(p,n);this._processRepulse(c,a,l,u)}))},this._engine=t,i.repulse||(i.repulse={particles:[]}),this.handleClickMode=e=>{const t=this.container.actualOptions.interactivity.modes.repulse;if(!t||"repulse"!==e)return;i.repulse||(i.repulse={particles:[]});const s=i.repulse;s.clicking=!0,s.count=0;for(const e of i.repulse.particles)this.isEnabled(e)&&e.velocity.setTo(e.initialVelocity);s.particles=[],s.finish=!1,setTimeout((()=>{i.destroyed||(s.clicking=!1)}),1e3*t.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,i=t.actualOptions,s=t.interactivity.status===e.mouseMoveEvent,o=i.interactivity.events,n=o.onHover,r=n.enable,c=n.mode,a=o.onClick,l=a.enable,p=a.mode,u=o.onDiv;s&&r&&(0,e.isInArray)("repulse",c)?this._hoverRepulse():l&&(0,e.isInArray)("repulse",p)?this._clickRepulse():(0,e.divModeExecute)("repulse",u,((e,t)=>this._singleSelectorRepulse(e,t)))}isEnabled(t){const i=this.container,s=i.actualOptions,o=i.interactivity.mouse,n=(t?.interactivity??s.interactivity).events,r=n.onDiv,c=n.onHover,a=n.onClick,l=(0,e.isDivModeEnabled)("repulse",r);if(!(l||c.enable&&o.position||a.enable&&o.clickPosition))return!1;const p=c.mode,u=a.mode;return(0,e.isInArray)("repulse",p)||(0,e.isInArray)("repulse",u)||l}loadModeOptions(e,...t){e.repulse||(e.repulse=new n);for(const i of t)e.repulse.load(i?.repulse)}reset(){}}async function c(e,t=!0){await e.addInteractor("externalRepulse",(t=>new r(e,t)),t)}})(),o})()));
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 i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var s in i)("object"==typeof exports?exports:e)[s]=i[s]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function s(e){var o=i[e];if(void 0!==o)return o.exports;var n=i[e]={exports:{}};return t[e](n,n.exports,s),n.exports}s.d=(e,t)=>{for(var i in t)s.o(t,i)&&!s.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{s.r(o),s.d(o,{Repulse:()=>n,RepulseBase:()=>t,RepulseDiv:()=>i,loadExternalRepulseInteraction:()=>a});var e=s(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 i extends t{constructor(){super(),this.selectors=[]}load(e){super.load(e),e&&void 0!==e.selectors&&(this.selectors=e.selectors)}}class n extends t{load(t){super.load(t),t&&(this.divs=(0,e.executeOnSingleOrMultiple)(t.divs,(e=>{const t=new i;return t.load(e),t})))}}const r="repulse";class c extends e.ExternalInteractorBase{constructor(t,i){super(i),this._clickRepulse=()=>{const t=this.container,i=t.actualOptions.interactivity.modes.repulse;if(!i)return;const s=t.repulse||{particles:[]};if(s.finish||(s.count||(s.count=0),s.count++,s.count===t.particles.count&&(s.finish=!0)),s.clicking){const o=t.retina.repulseModeDistance;if(!o||o<0)return;const n=Math.pow(o/6,3),r=t.interactivity.mouse.clickPosition;if(void 0===r)return;const c=new e.Circle(r.x,r.y,n),a=t.particles.quadTree.query(c,(e=>this.isEnabled(e)));for(const t of a){const{dx:o,dy:c,distance:a}=(0,e.getDistances)(r,t.position),l=a**2,p=-n*i.speed/l;if(l<=n){s.particles.push(t);const i=e.Vector.create(o,c);i.length=p,t.velocity.setTo(i)}}}else if(!1===s.clicking){for(const e of s.particles)e.velocity.setTo(e.initialVelocity);s.particles=[]}},this._hoverRepulse=()=>{const t=this.container,i=t.interactivity.mouse.position,s=t.retina.repulseModeDistance;!s||s<0||!i||this._processRepulse(i,s,new e.Circle(i.x,i.y,s))},this._processRepulse=(t,i,s,o)=>{const n=this.container,r=n.particles.quadTree.query(s,(e=>this.isEnabled(e))),c=n.actualOptions.interactivity.modes.repulse;if(!c)return;const{easing:a,speed:l,factor:p,maxSpeed:d}=c,u=(0,e.getEasing)(a),f=(o?.speed??l)*p;for(const s of r){const{dx:o,dy:n,distance:r}=(0,e.getDistances)(s.position,t),c=(0,e.clamp)(u(1-r/i)*f,0,d),a=e.Vector.create(0===r?f:o/r*c,0===r?f:n/r*c);s.position.addTo(a)}},this._singleSelectorRepulse=(t,i)=>{const s=this.container,o=s.actualOptions.interactivity.modes.repulse;if(!o)return;const n=document.querySelectorAll(t);n.length&&n.forEach((t=>{const n=t,r=s.retina.pixelRatio,c={x:(n.offsetLeft+n.offsetWidth/2)*r,y:(n.offsetTop+n.offsetHeight/2)*r},a=n.offsetWidth/2*r,l="circle"===i.type?new e.Circle(c.x,c.y,a):new e.Rectangle(n.offsetLeft*r,n.offsetTop*r,n.offsetWidth*r,n.offsetHeight*r),p=o.divs,d=(0,e.divMode)(p,n);this._processRepulse(c,a,l,d)}))},this._engine=t,i.repulse||(i.repulse={particles:[]}),this.handleClickMode=e=>{const t=this.container.actualOptions.interactivity.modes.repulse;if(!t||e!==r)return;i.repulse||(i.repulse={particles:[]});const s=i.repulse;s.clicking=!0,s.count=0;for(const e of i.repulse.particles)this.isEnabled(e)&&e.velocity.setTo(e.initialVelocity);s.particles=[],s.finish=!1,setTimeout((()=>{i.destroyed||(s.clicking=!1)}),1e3*t.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,i=t.actualOptions,s=t.interactivity.status===e.mouseMoveEvent,o=i.interactivity.events,n=o.onHover,c=n.enable,a=n.mode,l=o.onClick,p=l.enable,d=l.mode,u=o.onDiv;s&&c&&(0,e.isInArray)(r,a)?this._hoverRepulse():p&&(0,e.isInArray)(r,d)?this._clickRepulse():(0,e.divModeExecute)(r,u,((e,t)=>this._singleSelectorRepulse(e,t)))}isEnabled(t){const i=this.container,s=i.actualOptions,o=i.interactivity.mouse,n=(t?.interactivity??s.interactivity).events,c=n.onDiv,a=n.onHover,l=n.onClick,p=(0,e.isDivModeEnabled)(r,c);if(!(p||a.enable&&o.position||l.enable&&o.clickPosition))return!1;const d=a.mode,u=l.mode;return(0,e.isInArray)(r,d)||(0,e.isInArray)(r,u)||p}loadModeOptions(e,...t){e.repulse||(e.repulse=new n);for(const i of t)e.repulse.load(i?.repulse)}reset(){}}async function a(e,t=!0){await e.addInteractor("externalRepulse",(t=>new c(e,t)),t)}})(),o})()));
@@ -1 +1 @@
1
- /*! tsParticles Repulse External Interaction v3.0.0-beta.2 by Matteo Bruni */
1
+ /*! tsParticles Repulse External Interaction v3.0.0-beta.4 by Matteo Bruni */
package/umd/Repulser.js CHANGED
@@ -12,6 +12,7 @@
12
12
  exports.Repulser = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  const Repulse_js_1 = require("./Options/Classes/Repulse.js");
15
+ const repulseMode = "repulse";
15
16
  class Repulser extends engine_1.ExternalInteractorBase {
16
17
  constructor(engine, container) {
17
18
  super(container);
@@ -69,8 +70,9 @@
69
70
  if (!repulseOptions) {
70
71
  return;
71
72
  }
73
+ const { easing, speed, factor, maxSpeed } = repulseOptions, easingFunc = (0, engine_1.getEasing)(easing), velocity = (divRepulse?.speed ?? speed) * factor;
72
74
  for (const particle of query) {
73
- const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), velocity = (divRepulse?.speed ?? 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);
75
+ const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), repulseFactor = (0, engine_1.clamp)(easingFunc(1 - distance / repulseRadius) * velocity, 0, maxSpeed), normVec = engine_1.Vector.create(distance === 0 ? velocity : (dx / distance) * repulseFactor, distance === 0 ? velocity : (dy / distance) * repulseFactor);
74
76
  particle.position.addTo(normVec);
75
77
  }
76
78
  };
@@ -99,7 +101,7 @@
99
101
  }
100
102
  this.handleClickMode = (mode) => {
101
103
  const options = this.container.actualOptions, repulseOpts = options.interactivity.modes.repulse;
102
- if (!repulseOpts || mode !== "repulse") {
104
+ if (!repulseOpts || mode !== repulseMode) {
103
105
  return;
104
106
  }
105
107
  if (!container.repulse) {
@@ -135,23 +137,23 @@
135
137
  }
136
138
  async interact() {
137
139
  const container = this.container, options = container.actualOptions, mouseMoveStatus = container.interactivity.status === engine_1.mouseMoveEvent, events = options.interactivity.events, hover = events.onHover, hoverEnabled = hover.enable, hoverMode = hover.mode, click = events.onClick, clickEnabled = click.enable, clickMode = click.mode, divs = events.onDiv;
138
- if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)("repulse", hoverMode)) {
140
+ if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)(repulseMode, hoverMode)) {
139
141
  this._hoverRepulse();
140
142
  }
141
- else if (clickEnabled && (0, engine_1.isInArray)("repulse", clickMode)) {
143
+ else if (clickEnabled && (0, engine_1.isInArray)(repulseMode, clickMode)) {
142
144
  this._clickRepulse();
143
145
  }
144
146
  else {
145
- (0, engine_1.divModeExecute)("repulse", divs, (selector, div) => this._singleSelectorRepulse(selector, div));
147
+ (0, engine_1.divModeExecute)(repulseMode, divs, (selector, div) => this._singleSelectorRepulse(selector, div));
146
148
  }
147
149
  }
148
150
  isEnabled(particle) {
149
- const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv, hover = events.onHover, click = events.onClick, divRepulse = (0, engine_1.isDivModeEnabled)("repulse", divs);
151
+ const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv, hover = events.onHover, click = events.onClick, divRepulse = (0, engine_1.isDivModeEnabled)(repulseMode, divs);
150
152
  if (!(divRepulse || (hover.enable && mouse.position) || (click.enable && mouse.clickPosition))) {
151
153
  return false;
152
154
  }
153
155
  const hoverMode = hover.mode, clickMode = click.mode;
154
- return (0, engine_1.isInArray)("repulse", hoverMode) || (0, engine_1.isInArray)("repulse", clickMode) || divRepulse;
156
+ return (0, engine_1.isInArray)(repulseMode, hoverMode) || (0, engine_1.isInArray)(repulseMode, clickMode) || divRepulse;
155
157
  }
156
158
  loadModeOptions(options, ...sources) {
157
159
  if (!options.repulse) {