@tsparticles/interaction-external-repulse 4.0.0-beta.9 → 4.0.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.
@@ -1,2 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"),require("@tsparticles/plugin-interactivity"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine","@tsparticles/plugin-interactivity"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine"),require("@tsparticles/plugin-interactivity")):t(e.window,e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e,t)=>(()=>{"use strict";var r,i,o,n={303(t){t.exports=e},702(e){e.exports=t},54(e,t,r){r.d(t,{Z:()=>a});var i=r(303),o=r(503),n=r(103);class a extends o._{divs;load(e){super.load(e),(0,i.isNull)(e)||(this.divs=(0,i.executeOnSingleOrMultiple)(e.divs,e=>{let t=new n.W;return t.load(e),t}))}}},503(e,t,r){r.d(t,{_:()=>o});var i=r(303);class o{distance;duration;easing;factor;maxSpeed;speed;constructor(){this.distance=200,this.duration=.4,this.factor=100,this.speed=1,this.maxSpeed=50,this.easing=i.EasingType.easeOutQuad}load(e){(0,i.isNull)(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))}}},103(e,t,r){r.d(t,{W:()=>n});var i=r(303),o=r(503);class n extends o._{selectors;constructor(){super(),this.selectors=[]}load(e){super.load(e),(0,i.isNull)(e)||void 0!==e.selectors&&(this.selectors=e.selectors)}}}},a={};function s(e){var t=a[e];if(void 0!==t)return t.exports;var r=a[e]={exports:{}};return n[e](r,r.exports,s),r.exports}s.m=n,c=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,s.t=function(e,t){if(1&t&&(e=this(e)),8&t||"object"==typeof e&&e&&(4&t&&e.__esModule||16&t&&"function"==typeof e.then))return e;var r=Object.create(null);s.r(r);var i={};l=l||[null,c({}),c([]),c(c)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~l.indexOf(o);o=c(o))Object.getOwnPropertyNames(o).forEach(t=>i[t]=()=>e[t]);return i.default=()=>e,s.d(r,i),r},s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.f={},s.e=e=>Promise.all(Object.keys(s.f).reduce((t,r)=>(s.f[r](e,t),t),[])),s.u=e=>""+e+".min.js",s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),p={},s.l=(e,t,r,i)=>{if(p[e])return void p[e].push(t);if(void 0!==r)for(var o,n,a=document.getElementsByTagName("script"),l=0;l<a.length;l++){var c=a[l];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")=="@tsparticles/interaction-external-repulse:"+r){o=c;break}}o||(n=!0,(o=document.createElement("script")).charset="utf-8",s.nc&&o.setAttribute("nonce",s.nc),o.setAttribute("data-webpack","@tsparticles/interaction-external-repulse:"+r),o.src=e),p[e]=[t];var u=(t,r)=>{o.onerror=o.onload=null,clearTimeout(d);var i=p[e];if(delete p[e],o.parentNode&&o.parentNode.removeChild(o),i&&i.forEach(e=>e(r)),t)return t(r)},d=setTimeout(u.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=u.bind(null,o.onerror),o.onload=u.bind(null,o.onload),n&&document.head.appendChild(o)},s.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.g.importScripts&&(u=s.g.location+"");var l,c,p,u,d=s.g.document;if(!u&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(u=d.currentScript.src),!u)){var f=d.getElementsByTagName("script");if(f.length)for(var h=f.length-1;h>-1&&(!u||!/^http(s?):/.test(u));)u=f[h--].src}if(!u)throw Error("Automatic publicPath is not supported in this browser");s.p=u=u.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={64:0},s.f.j=(e,t)=>{var i=s.o(r,e)?r[e]:void 0;if(0!==i)if(i)t.push(i[2]);else{var o=new Promise((t,o)=>i=r[e]=[t,o]);t.push(i[2]=o);var n=s.p+s.u(e),a=Error();s.l(n,t=>{if(s.o(r,e)&&(0!==(i=r[e])&&(r[e]=void 0),i)){var o=t&&("load"===t.type?"missing":t.type),n=t&&t.target&&t.target.src;a.message="Loading chunk "+e+` failed.
2
- (`+o+": "+n+")",a.name="ChunkLoadError",a.type=o,a.request=n,i[1](a)}},"chunk-"+e,e)}},i=(e,t)=>{var i,o,[n,a,l]=t,c=0;if(n.some(e=>0!==r[e])){for(i in a)s.o(a,i)&&(s.m[i]=a[i]);l&&l(s)}for(e&&e(t);c<n.length;c++)o=n[c],s.o(r,o)&&r[o]&&r[o][0](),r[o]=0},(o=this.webpackChunk_tsparticles_interaction_external_repulse=this.webpackChunk_tsparticles_interaction_external_repulse||[]).forEach(i.bind(null,0)),o.push=i.bind(null,o.push.bind(o));var v={};s.r(v),s.d(v,{Repulse:()=>m.Z,RepulseBase:()=>g._,RepulseDiv:()=>b.W,loadExternalRepulseInteraction:()=>y});var g=s(503),b=s(103),m=s(54);async function y(e){e.checkVersion("4.0.0-beta.9"),await e.pluginManager.register(async e=>{let{ensureInteractivityPluginLoaded:t}=await Promise.resolve().then(s.t.bind(s,702,19));t(e);let r=e.pluginManager;r.addInteractor?.("externalRepulse",async e=>{let{Repulser:t}=await s.e(456).then(s.bind(s,456));return new t(r,e)})})}return v})());
1
+ !function(e){e.__tsParticlesInternals=e.__tsParticlesInternals||{},e.__tsParticlesInternals.bundles=e.__tsParticlesInternals.bundles||{},e.__tsParticlesInternals.effects=e.__tsParticlesInternals.effects||{},e.__tsParticlesInternals.engine=e.__tsParticlesInternals.engine||{},e.__tsParticlesInternals.interactions=e.__tsParticlesInternals.interactions||{},e.__tsParticlesInternals.palettes=e.__tsParticlesInternals.palettes||{},e.__tsParticlesInternals.paths=e.__tsParticlesInternals.paths||{},e.__tsParticlesInternals.plugins=e.__tsParticlesInternals.plugins||{},e.__tsParticlesInternals.plugins=e.__tsParticlesInternals.plugins||{},e.__tsParticlesInternals.plugins.emittersShapes=e.__tsParticlesInternals.plugins.emittersShapes||{},e.__tsParticlesInternals.presets=e.__tsParticlesInternals.presets||{},e.__tsParticlesInternals.shapes=e.__tsParticlesInternals.shapes||{},e.__tsParticlesInternals.updaters=e.__tsParticlesInternals.updaters||{},e.__tsParticlesInternals.utils=e.__tsParticlesInternals.utils||{},e.__tsParticlesInternals.canvas=e.__tsParticlesInternals.canvas||{},e.__tsParticlesInternals.canvas=e.__tsParticlesInternals.canvas||{},e.__tsParticlesInternals.canvas.utils=e.__tsParticlesInternals.canvas.utils||{},e.__tsParticlesInternals.path=e.__tsParticlesInternals.path||{},e.__tsParticlesInternals.path=e.__tsParticlesInternals.path||{},e.__tsParticlesInternals.path.utils=e.__tsParticlesInternals.path.utils||{};var t="undefined"!=typeof Proxy?function(e){return new Proxy(e,{get:function(e,t){return t in e||(e[t]={}),e[t]}})}:function(e){return e};e.__tsParticlesInternals.bundles=t(e.__tsParticlesInternals.bundles),e.__tsParticlesInternals.effects=t(e.__tsParticlesInternals.effects),e.__tsParticlesInternals.interactions=t(e.__tsParticlesInternals.interactions),e.__tsParticlesInternals.palettes=t(e.__tsParticlesInternals.palettes),e.__tsParticlesInternals.paths=t(e.__tsParticlesInternals.paths),e.__tsParticlesInternals.plugins=t(e.__tsParticlesInternals.plugins),e.__tsParticlesInternals.plugins.emittersShapes=t(e.__tsParticlesInternals.plugins.emittersShapes),e.__tsParticlesInternals.presets=t(e.__tsParticlesInternals.presets),e.__tsParticlesInternals.shapes=t(e.__tsParticlesInternals.shapes),e.__tsParticlesInternals.updaters=t(e.__tsParticlesInternals.updaters),e.__tsParticlesInternals.utils=t(e.__tsParticlesInternals.utils),e.__tsParticlesInternals.canvas=t(e.__tsParticlesInternals.canvas),e.__tsParticlesInternals.path=t(e.__tsParticlesInternals.path),e.tsparticlesInternalExports=e.tsparticlesInternalExports||{}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this),function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine")):"function"==typeof define&&define.amd?define(["exports","@tsparticles/plugin-interactivity","@tsparticles/engine"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).__tsParticlesInternals=e.__tsParticlesInternals||{},e.__tsParticlesInternals.interactions=e.__tsParticlesInternals.interactions||{},e.__tsParticlesInternals.interactions.externalRepulse=e.__tsParticlesInternals.interactions.externalRepulse||{}),e.__tsParticlesInternals.plugins.interactivity,e.__tsParticlesInternals.engine)}(this,function(e,t,s){"use strict";class i{distance;duration;easing;factor;maxSpeed;restore;speed;constructor(){this.distance=200,this.duration=.4,this.factor=100,this.speed=1,this.maxSpeed=50,this.easing=s.EasingType.easeOutQuad,this.restore={enable:!1,delay:0,speed:.08,follow:!0}}load(e){s.isNull(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),void 0!==e.restore&&(this.restore.enable=e.restore.enable??this.restore.enable,this.restore.delay=e.restore.delay??this.restore.delay,this.restore.speed=e.restore.speed??this.restore.speed,this.restore.follow=e.restore.follow??this.restore.follow))}}class n extends i{selectors;constructor(){super(),this.selectors=[]}load(e){super.load(e),s.isNull(e)||void 0!==e.selectors&&(this.selectors=e.selectors)}}class a extends i{divs;load(e){super.load(e),s.isNull(e)||(this.divs=s.executeOnSingleOrMultiple(e.divs,e=>{const t=new n;return t.load(e),t}))}}const r="repulse";class l extends t.ExternalInteractorBase{handleClickMode;_clickVec;_interactedThisFrame;_maxDistance;_normVec;_pluginManager;_restoreData;constructor(e,t){super(t),this._pluginManager=e,this._maxDistance=0,this._normVec=s.Vector.origin,this._interactedThisFrame=new Set,this._clickVec=s.Vector.origin,this._restoreData=new Map,t.repulse??={particles:[]},this.handleClickMode=(e,i)=>{const n=this.container.actualOptions,a=n.interactivity?.modes.repulse;if(!a||e!==r)return;t.repulse??={particles:[]};const l=t.repulse;l.clicking=!0,l.count=0;for(const e of t.repulse.particles)this.isEnabled(i,e)&&e.velocity.setTo(e.initialVelocity);l.particles=[],l.finish=!1,setTimeout(()=>{t.destroyed||(l.clicking=!1)},a.duration*s.millisecondsToSeconds)}}get maxDistance(){return this._maxDistance}clear(){}init(){const e=this.container,t=e.actualOptions.interactivity?.modes.repulse;t&&(this._maxDistance=t.distance,e.retina.repulseModeDistance=t.distance*e.retina.pixelRatio)}interact(e){this._interactedThisFrame.clear();const i=this.container.actualOptions,n=e.status===t.mouseMoveEvent,a=i.interactivity?.events;if(!a)return;const l=a.onHover,c=l.enable,o=l.mode,_=a.onClick,p=_.enable,d=_.mode,u=a.onDiv;n&&c&&s.isInArray(r,o)?this._hoverRepulse(e):p&&s.isInArray(r,d)?this._clickRepulse(e):t.divModeExecute(r,u,(t,s)=>{this._singleSelectorRepulse(e,t,s)}),this._restoreParticles()}isEnabled(e,i){const n=this.container.actualOptions,a=e.mouse,l=(i?.interactivity??n.interactivity)?.events;if(!l)return!1;const c=l.onDiv,o=l.onHover,_=l.onClick,p=t.isDivModeEnabled(r,c);if(!(p||o.enable&&a.position||_.enable&&a.clickPosition))return!1;const d=o.mode,u=_.mode;return s.isInArray(r,d)||s.isInArray(r,u)||p}loadModeOptions(e,...t){e.repulse??=new a;for(const s of t)e.repulse.load(s?.repulse)}reset(){}_clickRepulse=e=>{const t=this.container,i=t.actualOptions.interactivity?.modes.repulse;if(!i)return;const n=t.repulse??{particles:[]};if(n.finish||(n.count??=0,n.count++,n.count===t.particles.count&&(n.finish=!0)),n.clicking){const a=t.retina.repulseModeDistance;if(!a||a<0)return;const r=Math.pow(a/6,3),l=e.mouse.clickPosition;if(void 0===l)return;const c=new s.Circle(l.x,l.y,r),o=t.particles.grid.query(c,t=>this.isEnabled(e,t));for(const e of o){const{dx:t,dy:a,distance:c}=s.getDistances(l,e.position),o=c**2,_=-r*i.speed/o;o<=r&&(this._trackInteractedParticle(e),n.particles.push(e),this._clickVec.x=t,this._clickVec.y=a,this._clickVec.length=_,e.velocity.setTo(this._clickVec))}}else if(!1===n.clicking){for(const e of n.particles)e.velocity.setTo(e.initialVelocity);n.particles=[]}};_hoverRepulse=e=>{const t=this.container,i=e.mouse.position,n=t.retina.repulseModeDistance;!n||n<0||!i||this._processRepulse(e,i,n,new s.Circle(i.x,i.y,n))};_processRepulse=(e,t,i,n,a)=>{const r=this.container,l=r.particles.grid.query(n,t=>this.isEnabled(e,t)),c=r.actualOptions.interactivity?.modes.repulse;if(!c)return;const{easing:o,speed:_,factor:p,maxSpeed:d}=c,u=this._pluginManager.getEasing(o),h=(a?.speed??_)*p;for(const e of l){const{dx:n,dy:a,distance:r}=s.getDistances(e.position,t),l=s.clamp(u(1-r/i)*h,0,d);this._normVec.x=r?n/r*l:h,this._normVec.y=r?a/r*l:h,this._trackInteractedParticle(e),e.position.addTo(this._normVec)}};_restoreParticles(){const e=this.container.actualOptions.interactivity?.modes.repulse?.restore;if(!e?.enable||!this._restoreData.size)return;const t=Date.now(),i=e.delay*s.millisecondsToSeconds,n=Math.max(.001,Math.min(1,e.speed));for(const[s,a]of this._restoreData){if(this._interactedThisFrame.has(s))continue;if(s.destroyed){this._restoreData.delete(s);continue}const r=a.target;if(t-a.lastInteractionTime<i)continue;e.follow&&s.options.move.enable&&(r.x+=s.velocity.x,r.y+=s.velocity.y,r.z+=s.velocity.z);const l=r.x-s.position.x,c=r.y-s.position.y,o=r.z-s.position.z;s.position.x+=l*n,s.position.y+=c*n,s.position.z+=o*n,Math.abs(l)<=.5&&Math.abs(c)<=.5&&(s.position.x=r.x,s.position.y=r.y,s.position.z=r.z,this._restoreData.delete(s))}}_singleSelectorRepulse=(e,i,n)=>{const a=this.container,r=a.actualOptions.interactivity?.modes.repulse;if(!r)return;const l=s.safeDocument().querySelectorAll(i);l.length&&l.forEach(i=>{const l=i,c=a.retina.pixelRatio,o={x:(l.offsetLeft+l.offsetWidth*s.half)*c,y:(l.offsetTop+l.offsetHeight*s.half)*c},_=l.offsetWidth*s.half*c,p=n.type===t.DivType.circle?new s.Circle(o.x,o.y,_):new s.Rectangle(l.offsetLeft*c,l.offsetTop*c,l.offsetWidth*c,l.offsetHeight*c),d=r.divs,u=t.divMode(d,l);this._processRepulse(e,o,_,p,u)})};_trackInteractedParticle(e){this._interactedThisFrame.add(e);const t=this.container.actualOptions.interactivity?.modes.repulse?.restore;if(!t?.enable)return;const s=Date.now();let i=this._restoreData.get(e);i||(i={target:e.position.copy(),lastInteractionTime:s},this._restoreData.set(e,i)),i.lastInteractionTime=s,t.follow&&e.options.move.enable&&(i.target.x+=e.velocity.x,i.target.y+=e.velocity.y,i.target.z+=e.velocity.z)}}async function c(e){e.checkVersion("4.0.0"),await e.pluginManager.register(e=>{t.ensureInteractivityPluginLoaded(e);const s=e.pluginManager;s.addInteractor?.("externalRepulse",e=>Promise.resolve(new l(s,e)))})}const o=globalThis;o.__tsParticlesInternals=o.__tsParticlesInternals??{},o.loadExternalRepulseInteraction=c,e.Repulse=a,e.RepulseBase=i,e.RepulseDiv=n,e.loadExternalRepulseInteraction=c}),Object.assign(globalThis.window||globalThis,{loadExternalRepulseInteraction:(globalThis.__tsParticlesInternals.interactions.externalRepulse||{}).loadExternalRepulseInteraction}),delete(globalThis.window||globalThis).tsparticlesInternalExports;
@@ -1,11 +1,12 @@
1
1
  import { EasingType, type EasingTypeAlt, type IOptionLoader, type RecursivePartial } from "@tsparticles/engine";
2
- import type { IRepulseBase } from "../Interfaces/IRepulseBase.js";
2
+ import type { IRepulseBase, IRepulseRestore } from "../Interfaces/IRepulseBase.js";
3
3
  export declare abstract class RepulseBase implements IRepulseBase, IOptionLoader<IRepulseBase> {
4
4
  distance: number;
5
5
  duration: number;
6
6
  easing: EasingType | EasingTypeAlt;
7
7
  factor: number;
8
8
  maxSpeed: number;
9
+ restore: IRepulseRestore;
9
10
  speed: number;
10
11
  constructor();
11
12
  load(data?: RecursivePartial<IRepulseBase>): void;
@@ -1,9 +1,16 @@
1
1
  import type { EasingType, EasingTypeAlt } from "@tsparticles/engine";
2
+ export interface IRepulseRestore {
3
+ delay: number;
4
+ enable: boolean;
5
+ follow: boolean;
6
+ speed: number;
7
+ }
2
8
  export interface IRepulseBase {
3
9
  distance: number;
4
10
  duration: number;
5
11
  easing: EasingType | EasingTypeAlt;
6
12
  factor: number;
7
13
  maxSpeed: number;
14
+ restore: IRepulseRestore;
8
15
  speed: number;
9
16
  }
@@ -4,9 +4,11 @@ import type { IRepulseMode, RepulseContainer, RepulseMode } from "./Types.js";
4
4
  export declare class Repulser extends ExternalInteractorBase<RepulseContainer> {
5
5
  handleClickMode: (mode: string, interactivityData: IInteractivityData) => void;
6
6
  private readonly _clickVec;
7
+ private readonly _interactedThisFrame;
7
8
  private _maxDistance;
8
9
  private readonly _normVec;
9
10
  private readonly _pluginManager;
11
+ private readonly _restoreData;
10
12
  constructor(pluginManager: PluginManager, container: RepulseContainer);
11
13
  get maxDistance(): number;
12
14
  clear(): void;
@@ -18,5 +20,7 @@ export declare class Repulser extends ExternalInteractorBase<RepulseContainer> {
18
20
  private readonly _clickRepulse;
19
21
  private readonly _hoverRepulse;
20
22
  private readonly _processRepulse;
23
+ private _restoreParticles;
21
24
  private readonly _singleSelectorRepulse;
25
+ private _trackInteractedParticle;
22
26
  }
package/types/Types.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface IRepulseMode {
9
9
  export interface RepulseMode {
10
10
  repulse?: Repulse;
11
11
  }
12
- interface IContainerRepulse {
12
+ export interface IContainerRepulse {
13
13
  clicking?: boolean;
14
14
  count?: number;
15
15
  finish?: boolean;
@@ -22,4 +22,3 @@ export type RepulseContainer = InteractivityContainer & {
22
22
  repulseModeDistance?: number;
23
23
  };
24
24
  };
25
- export {};
@@ -0,0 +1 @@
1
+ export * from "./index.js";
@@ -0,0 +1,8 @@
1
+ import { type Engine } from "@tsparticles/engine/lazy";
2
+ export declare function loadExternalRepulseInteraction(engine: Engine): Promise<void>;
3
+ export * from "./Options/Classes/RepulseBase.js";
4
+ export * from "./Options/Classes/RepulseDiv.js";
5
+ export * from "./Options/Classes/Repulse.js";
6
+ export type * from "./Options/Interfaces/IRepulseBase.js";
7
+ export type * from "./Options/Interfaces/IRepulseDiv.js";
8
+ export type * from "./Options/Interfaces/IRepulse.js";
package/456.min.js DELETED
@@ -1 +0,0 @@
1
- "use strict";(this.webpackChunk_tsparticles_interaction_external_repulse=this.webpackChunk_tsparticles_interaction_external_repulse||[]).push([[456],{456(e,t,i){i.d(t,{Repulser:()=>c});var s=i(303),n=i(702),l=i(54);let r="repulse";class c extends n.ExternalInteractorBase{handleClickMode;_clickVec;_maxDistance;_normVec;_pluginManager;constructor(e,t){super(t),this._pluginManager=e,this._maxDistance=0,this._normVec=s.Vector.origin,this._clickVec=s.Vector.origin,t.repulse??={particles:[]},this.handleClickMode=(e,i)=>{let n=this.container.actualOptions,l=n.interactivity?.modes.repulse;if(!l||e!==r)return;t.repulse??={particles:[]};let c=t.repulse;for(let e of(c.clicking=!0,c.count=0,t.repulse.particles))this.isEnabled(i,e)&&e.velocity.setTo(e.initialVelocity);c.particles=[],c.finish=!1,setTimeout(()=>{t.destroyed||(c.clicking=!1)},l.duration*s.millisecondsToSeconds)}}get maxDistance(){return this._maxDistance}clear(){}init(){let e=this.container,t=e.actualOptions.interactivity?.modes.repulse;t&&(this._maxDistance=t.distance,e.retina.repulseModeDistance=t.distance*e.retina.pixelRatio)}interact(e){let t=this.container.actualOptions,i=e.status===n.mouseMoveEvent,l=t.interactivity?.events;if(!l)return;let c=l.onHover,o=c.enable,a=c.mode,p=l.onClick,u=p.enable,h=p.mode,d=l.onDiv;i&&o&&(0,s.isInArray)(r,a)?this._hoverRepulse(e):u&&(0,s.isInArray)(r,h)?this._clickRepulse(e):(0,n.divModeExecute)(r,d,(t,i)=>{this._singleSelectorRepulse(e,t,i)})}isEnabled(e,t){let i=this.container.actualOptions,l=e.mouse,c=(t?.interactivity??i.interactivity)?.events;if(!c)return!1;let o=c.onDiv,a=c.onHover,p=c.onClick,u=(0,n.isDivModeEnabled)(r,o);if(!(u||a.enable&&l.position||p.enable&&l.clickPosition))return!1;let h=a.mode,d=p.mode;return(0,s.isInArray)(r,h)||(0,s.isInArray)(r,d)||u}loadModeOptions(e,...t){for(let i of(e.repulse??=new l.Z,t))e.repulse.load(i?.repulse)}reset(){}_clickRepulse=e=>{let t=this.container,i=t.actualOptions.interactivity?.modes.repulse;if(!i)return;let n=t.repulse??{particles:[]};if(n.finish||(n.count??=0,n.count++,n.count===t.particles.count&&(n.finish=!0)),n.clicking){let l=t.retina.repulseModeDistance;if(!l||l<0)return;let r=Math.pow(l/6,3),c=e.mouse.clickPosition;if(void 0===c)return;let o=new s.Circle(c.x,c.y,r);for(let l of t.particles.grid.query(o,t=>this.isEnabled(e,t))){let{dx:e,dy:t,distance:o}=(0,s.getDistances)(c,l.position),a=o**2,p=-r*i.speed/a;a<=r&&(n.particles.push(l),this._clickVec.x=e,this._clickVec.y=t,this._clickVec.length=p,l.velocity.setTo(this._clickVec))}}else if(!1===n.clicking){for(let e of n.particles)e.velocity.setTo(e.initialVelocity);n.particles=[]}};_hoverRepulse=e=>{let t=this.container,i=e.mouse.position,n=t.retina.repulseModeDistance;n&&!(n<0)&&i&&this._processRepulse(e,i,n,new s.Circle(i.x,i.y,n))};_processRepulse=(e,t,i,n,l)=>{let r=this.container,c=r.particles.grid.query(n,t=>this.isEnabled(e,t)),o=r.actualOptions.interactivity?.modes.repulse;if(!o)return;let{easing:a,speed:p,factor:u,maxSpeed:h}=o,d=this._pluginManager.getEasing(a),f=(l?.speed??p)*u;for(let e of c){let{dx:n,dy:l,distance:r}=(0,s.getDistances)(e.position,t),c=(0,s.clamp)(d(1-r/i)*f,0,h);this._normVec.x=r?n/r*c:f,this._normVec.y=r?l/r*c:f,e.position.addTo(this._normVec)}};_singleSelectorRepulse=(e,t,i)=>{let l=this.container,r=l.actualOptions.interactivity?.modes.repulse;if(!r)return;let c=(0,s.safeDocument)().querySelectorAll(t);c.length&&c.forEach(t=>{let c=l.retina.pixelRatio,o={x:(t.offsetLeft+t.offsetWidth*s.half)*c,y:(t.offsetTop+t.offsetHeight*s.half)*c},a=t.offsetWidth*s.half*c,p=i.type===n.DivType.circle?new s.Circle(o.x,o.y,a):new s.Rectangle(t.offsetLeft*c,t.offsetTop*c,t.offsetWidth*c,t.offsetHeight*c),u=r.divs,h=(0,n.divMode)(u,t);this._processRepulse(e,o,a,p,h)})}}}}]);
@@ -1,30 +0,0 @@
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
- * v4.0.0-beta.9
8
- */
9
- "use strict";
10
- /*
11
- * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
- * This devtool is neither made for production nor for readable output files.
13
- * It uses "eval()" calls to create a separate source file in the browser devtools.
14
- * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
- * or disable the default devtool with "devtool: false".
16
- * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
- */
18
- (this["webpackChunk_tsparticles_interaction_external_repulse"] = this["webpackChunk_tsparticles_interaction_external_repulse"] || []).push([["dist_browser_Repulser_js"],{
19
-
20
- /***/ "./dist/browser/Repulser.js"
21
- /*!**********************************!*\
22
- !*** ./dist/browser/Repulser.js ***!
23
- \**********************************/
24
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
-
26
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Repulser: () => (/* binding */ Repulser)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n/* harmony import */ var _Options_Classes_Repulse_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Repulse.js */ \"./dist/browser/Options/Classes/Repulse.js\");\n\n\n\nconst repulseMode = \"repulse\", minDistance = 0, repulseRadiusFactor = 6, repulseRadiusPower = 3, squarePower = 2, minRadius = 0, minSpeed = 0, easingOffset = 1;\nclass Repulser extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.ExternalInteractorBase {\n handleClickMode;\n _clickVec;\n _maxDistance;\n _normVec;\n _pluginManager;\n constructor(pluginManager, container){\n super(container);\n this._pluginManager = pluginManager;\n this._maxDistance = 0;\n this._normVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n this._clickVec = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n container.repulse ??= {\n particles: []\n };\n this.handleClickMode = (mode, interactivityData)=>{\n const options = this.container.actualOptions, repulseOpts = options.interactivity?.modes.repulse;\n if (!repulseOpts || mode !== repulseMode) {\n return;\n }\n container.repulse ??= {\n particles: []\n };\n const repulse = container.repulse;\n repulse.clicking = true;\n repulse.count = 0;\n for (const particle of container.repulse.particles){\n if (!this.isEnabled(interactivityData, particle)) {\n continue;\n }\n particle.velocity.setTo(particle.initialVelocity);\n }\n repulse.particles = [];\n repulse.finish = false;\n setTimeout(()=>{\n if (container.destroyed) {\n return;\n }\n repulse.clicking = false;\n }, repulseOpts.duration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds);\n };\n }\n get maxDistance() {\n return this._maxDistance;\n }\n clear() {}\n init() {\n const container = this.container, repulse = container.actualOptions.interactivity?.modes.repulse;\n if (!repulse) {\n return;\n }\n this._maxDistance = repulse.distance;\n container.retina.repulseModeDistance = repulse.distance * container.retina.pixelRatio;\n }\n interact(interactivityData) {\n const container = this.container, options = container.actualOptions, mouseMoveStatus = interactivityData.status === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.mouseMoveEvent, events = options.interactivity?.events;\n if (!events) {\n return;\n }\n const hover = events.onHover, hoverEnabled = hover.enable, hoverMode = hover.mode, click = events.onClick, clickEnabled = click.enable, clickMode = click.mode, divs = events.onDiv;\n if (mouseMoveStatus && hoverEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(repulseMode, hoverMode)) {\n this._hoverRepulse(interactivityData);\n } else if (clickEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(repulseMode, clickMode)) {\n this._clickRepulse(interactivityData);\n } else {\n (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.divModeExecute)(repulseMode, divs, (selector, div)=>{\n this._singleSelectorRepulse(interactivityData, selector, div);\n });\n }\n }\n isEnabled(interactivityData, particle) {\n const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;\n if (!events) {\n return false;\n }\n const divs = events.onDiv, hover = events.onHover, click = events.onClick, divRepulse = (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.isDivModeEnabled)(repulseMode, divs);\n if (!(divRepulse || hover.enable && !!mouse.position || click.enable && mouse.clickPosition)) {\n return false;\n }\n const hoverMode = hover.mode, clickMode = click.mode;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(repulseMode, hoverMode) || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(repulseMode, clickMode) || divRepulse;\n }\n loadModeOptions(options, ...sources) {\n options.repulse ??= new _Options_Classes_Repulse_js__WEBPACK_IMPORTED_MODULE_2__.Repulse();\n for (const source of sources){\n options.repulse.load(source?.repulse);\n }\n }\n reset() {}\n _clickRepulse = (interactivityData)=>{\n const container = this.container, repulseOptions = container.actualOptions.interactivity?.modes.repulse;\n if (!repulseOptions) {\n return;\n }\n const repulse = container.repulse ?? {\n particles: []\n };\n if (!repulse.finish) {\n repulse.count ??= 0;\n repulse.count++;\n if (repulse.count === container.particles.count) {\n repulse.finish = true;\n }\n }\n if (repulse.clicking) {\n const repulseDistance = container.retina.repulseModeDistance;\n if (!repulseDistance || repulseDistance < minDistance) {\n return;\n }\n const repulseRadius = Math.pow(repulseDistance / repulseRadiusFactor, repulseRadiusPower), mouseClickPos = interactivityData.mouse.clickPosition;\n if (mouseClickPos === undefined) {\n return;\n }\n const range = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(mouseClickPos.x, mouseClickPos.y, repulseRadius), query = container.particles.grid.query(range, (p)=>this.isEnabled(interactivityData, p));\n for (const particle of query){\n const { dx, dy, distance } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(mouseClickPos, particle.position), d = distance ** squarePower, velocity = repulseOptions.speed, force = -repulseRadius * velocity / d;\n if (d <= repulseRadius) {\n repulse.particles.push(particle);\n this._clickVec.x = dx;\n this._clickVec.y = dy;\n this._clickVec.length = force;\n particle.velocity.setTo(this._clickVec);\n }\n }\n } else if (repulse.clicking === false) {\n for (const particle of repulse.particles){\n particle.velocity.setTo(particle.initialVelocity);\n }\n repulse.particles = [];\n }\n };\n _hoverRepulse = (interactivityData)=>{\n const container = this.container, mousePos = interactivityData.mouse.position, repulseRadius = container.retina.repulseModeDistance;\n if (!repulseRadius || repulseRadius < minRadius || !mousePos) {\n return;\n }\n this._processRepulse(interactivityData, mousePos, repulseRadius, new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(mousePos.x, mousePos.y, repulseRadius));\n };\n _processRepulse = (interactivityData, position, repulseRadius, area, divRepulse)=>{\n const container = this.container, query = container.particles.grid.query(area, (p)=>this.isEnabled(interactivityData, p)), repulseOptions = container.actualOptions.interactivity?.modes.repulse;\n if (!repulseOptions) {\n return;\n }\n const { easing, speed, factor, maxSpeed } = repulseOptions, easingFunc = this._pluginManager.getEasing(easing), velocity = (divRepulse?.speed ?? speed) * factor;\n for (const particle of query){\n const { dx, dy, distance } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(particle.position, position), repulseFactor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.clamp)(easingFunc(easingOffset - distance / repulseRadius) * velocity, minSpeed, maxSpeed);\n this._normVec.x = !distance ? velocity : dx / distance * repulseFactor;\n this._normVec.y = !distance ? velocity : dy / distance * repulseFactor;\n particle.position.addTo(this._normVec);\n }\n };\n _singleSelectorRepulse = (interactivityData, selector, div)=>{\n const container = this.container, repulse = container.actualOptions.interactivity?.modes.repulse;\n if (!repulse) {\n return;\n }\n const query = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().querySelectorAll(selector);\n if (!query.length) {\n return;\n }\n query.forEach((item)=>{\n const elem = item, pxRatio = container.retina.pixelRatio, pos = {\n x: (elem.offsetLeft + elem.offsetWidth * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio,\n y: (elem.offsetTop + elem.offsetHeight * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio\n }, repulseRadius = elem.offsetWidth * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half * pxRatio, area = div.type === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.DivType.circle ? new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(pos.x, pos.y, repulseRadius) : new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), divs = repulse.divs, divRepulse = (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.divMode)(divs, elem);\n this._processRepulse(interactivityData, pos, repulseRadius, area, divRepulse);\n });\n };\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-repulse/./dist/browser/Repulser.js?\n}");
27
-
28
- /***/ }
29
-
30
- }]);