@tsparticles/plugin-interactivity 4.0.0-alpha.21 → 4.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/221.min.js +1 -1
- package/703.min.js +1 -1
- package/{esm → browser/BaseClasses}/ExternalInteractorBase.js +1 -1
- package/browser/BaseClasses/GlobalInteractorBase.js +8 -0
- package/browser/{ParticlesInteractorBase.js → BaseClasses/ParticlesInteractorBase.js} +1 -1
- package/browser/{InteractorType.js → Enums/InteractorType.js} +1 -0
- package/browser/InteractionManager.js +24 -9
- package/browser/InteractivityEventListeners.js +13 -5
- package/browser/InteractivityPlugin.js +1 -3
- package/browser/InteractivityPluginInstance.js +5 -2
- package/browser/Options/Classes/Events/DivEvent.js +1 -1
- package/browser/Options/Classes/Interactivity.js +1 -1
- package/browser/index.js +7 -6
- package/{browser → cjs/BaseClasses}/ExternalInteractorBase.js +1 -1
- package/cjs/BaseClasses/GlobalInteractorBase.js +8 -0
- package/{esm → cjs/BaseClasses}/ParticlesInteractorBase.js +1 -1
- package/cjs/{InteractorType.js → Enums/InteractorType.js} +1 -0
- package/cjs/InteractionManager.js +24 -9
- package/cjs/InteractivityEventListeners.js +13 -5
- package/cjs/InteractivityPlugin.js +1 -3
- package/cjs/InteractivityPluginInstance.js +5 -2
- package/cjs/Options/Classes/Events/DivEvent.js +1 -1
- package/cjs/Options/Classes/Interactivity.js +1 -1
- package/cjs/index.js +7 -6
- package/dist_browser_InteractivityPluginInstance_js.js +4 -4
- package/dist_browser_InteractivityPlugin_js.js +3 -3
- package/{cjs → esm/BaseClasses}/ExternalInteractorBase.js +1 -1
- package/esm/BaseClasses/GlobalInteractorBase.js +8 -0
- package/{cjs → esm/BaseClasses}/ParticlesInteractorBase.js +1 -1
- package/esm/{InteractorType.js → Enums/InteractorType.js} +1 -0
- package/esm/InteractionManager.js +24 -9
- package/esm/InteractivityEventListeners.js +13 -5
- package/esm/InteractivityPlugin.js +1 -3
- package/esm/InteractivityPluginInstance.js +5 -2
- package/esm/Interfaces/IGlobalInteractor.js +1 -0
- package/esm/Interfaces/IInteractivityData.js +1 -0
- package/esm/Interfaces/IInteractor.js +1 -0
- package/esm/Interfaces/IMouseData.js +1 -0
- package/esm/Interfaces/IParticleInteractorBase.js +1 -0
- package/esm/Interfaces/IParticlesInteractor.js +1 -0
- package/esm/Options/Classes/Events/DivEvent.js +1 -1
- package/esm/Options/Classes/Interactivity.js +1 -1
- package/esm/index.js +7 -6
- package/package.json +2 -2
- package/report.html +1 -1
- package/tsparticles.plugin.interactivity.js +48 -38
- package/tsparticles.plugin.interactivity.min.js +2 -2
- package/types/{ExternalInteractorBase.d.ts → BaseClasses/ExternalInteractorBase.d.ts} +4 -4
- package/types/BaseClasses/GlobalInteractorBase.d.ts +12 -0
- package/types/{ParticlesInteractorBase.d.ts → BaseClasses/ParticlesInteractorBase.d.ts} +4 -4
- package/types/{InteractorType.d.ts → Enums/InteractorType.d.ts} +1 -0
- package/types/InteractionManager.d.ts +5 -2
- package/types/{IExternalInteractor.d.ts → Interfaces/IExternalInteractor.d.ts} +4 -4
- package/types/Interfaces/IGlobalInteractor.d.ts +11 -0
- package/types/Interfaces/IInteractor.d.ts +7 -0
- package/types/{IInteractor.d.ts → Interfaces/IParticleInteractorBase.d.ts} +4 -7
- package/types/{IParticlesInteractor.d.ts → Interfaces/IParticlesInteractor.d.ts} +2 -2
- package/types/Options/Classes/Events/DivEvent.d.ts +1 -1
- package/types/Options/Classes/Interactivity.d.ts +1 -1
- package/types/Options/Interfaces/Events/IDivEvent.d.ts +1 -1
- package/types/Options/Interfaces/IInteractivity.d.ts +1 -1
- package/types/index.d.ts +12 -9
- package/types/types.d.ts +1 -1
- package/umd/{ExternalInteractorBase.js → BaseClasses/ExternalInteractorBase.js} +2 -2
- package/umd/BaseClasses/GlobalInteractorBase.js +22 -0
- package/umd/{ParticlesInteractorBase.js → BaseClasses/ParticlesInteractorBase.js} +2 -2
- package/umd/{InteractorType.js → Enums/InteractorType.js} +1 -0
- package/umd/InteractionManager.js +25 -10
- package/umd/InteractivityEventListeners.js +14 -6
- package/umd/InteractivityPlugin.js +1 -3
- package/umd/InteractivityPluginInstance.js +5 -2
- package/umd/Interfaces/IParticleInteractorBase.js +12 -0
- package/umd/Interfaces/IParticlesInteractor.js +12 -0
- package/umd/Options/Classes/Events/DivEvent.js +2 -2
- package/umd/Options/Classes/Interactivity.js +2 -2
- package/umd/index.js +8 -7
- /package/browser/{DivType.js → Enums/DivType.js} +0 -0
- /package/browser/{InteractivityDetect.js → Enums/InteractivityDetect.js} +0 -0
- /package/browser/{IExternalInteractor.js → Interfaces/IExternalInteractor.js} +0 -0
- /package/browser/{IInteractivityData.js → Interfaces/IGlobalInteractor.js} +0 -0
- /package/{cjs → browser/Interfaces}/IInteractivityData.js +0 -0
- /package/browser/{IInteractor.js → Interfaces/IInteractor.js} +0 -0
- /package/browser/{IMouseData.js → Interfaces/IMouseData.js} +0 -0
- /package/browser/{IParticlesInteractor.js → Interfaces/IParticleInteractorBase.js} +0 -0
- /package/{cjs → browser/Interfaces}/IParticlesInteractor.js +0 -0
- /package/cjs/{DivType.js → Enums/DivType.js} +0 -0
- /package/cjs/{InteractivityDetect.js → Enums/InteractivityDetect.js} +0 -0
- /package/cjs/{IExternalInteractor.js → Interfaces/IExternalInteractor.js} +0 -0
- /package/cjs/{IInteractor.js → Interfaces/IGlobalInteractor.js} +0 -0
- /package/{esm → cjs/Interfaces}/IInteractivityData.js +0 -0
- /package/{esm → cjs/Interfaces}/IInteractor.js +0 -0
- /package/cjs/{IMouseData.js → Interfaces/IMouseData.js} +0 -0
- /package/{esm/IExternalInteractor.js → cjs/Interfaces/IParticleInteractorBase.js} +0 -0
- /package/{esm → cjs/Interfaces}/IParticlesInteractor.js +0 -0
- /package/esm/{DivType.js → Enums/DivType.js} +0 -0
- /package/esm/{InteractivityDetect.js → Enums/InteractivityDetect.js} +0 -0
- /package/esm/{IMouseData.js → Interfaces/IExternalInteractor.js} +0 -0
- /package/types/{DivType.d.ts → Enums/DivType.d.ts} +0 -0
- /package/types/{InteractivityDetect.d.ts → Enums/InteractivityDetect.d.ts} +0 -0
- /package/types/{IInteractivityData.d.ts → Interfaces/IInteractivityData.d.ts} +0 -0
- /package/types/{IMouseData.d.ts → Interfaces/IMouseData.d.ts} +0 -0
- /package/umd/{DivType.js → Enums/DivType.js} +0 -0
- /package/umd/{InteractivityDetect.js → Enums/InteractivityDetect.js} +0 -0
- /package/umd/{IExternalInteractor.js → Interfaces/IExternalInteractor.js} +0 -0
- /package/umd/{IInteractivityData.js → Interfaces/IGlobalInteractor.js} +0 -0
- /package/umd/{IInteractor.js → Interfaces/IInteractivityData.js} +0 -0
- /package/umd/{IMouseData.js → Interfaces/IInteractor.js} +0 -0
- /package/umd/{IParticlesInteractor.js → Interfaces/IMouseData.js} +0 -0
package/221.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(this.webpackChunk_tsparticles_plugin_interactivity=this.webpackChunk_tsparticles_plugin_interactivity||[]).push([[221],{221(e,t,i){i.d(t,{InteractivityPluginInstance:()=>h});var n=i(303),s=i(731),a=i(
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_interactivity=this.webpackChunk_tsparticles_plugin_interactivity||[]).push([[221],{221(e,t,i){i.d(t,{InteractivityPluginInstance:()=>h});var n=i(303),s=i(731),a=i(366);class r{_canPush=!0;_clickPositionPlugins;_container;_handlers;_interactionManager;_touches;constructor(e,t){this._container=e,this._clickPositionPlugins=[],this._interactionManager=t,this._touches=new Map,this._handlers={mouseDown:()=>{this._mouseDown()},mouseLeave:()=>{this._mouseTouchFinish()},mouseMove:e=>{this._mouseTouchMove(e)},mouseUp:e=>{this._mouseTouchClick(e)},touchStart:e=>{this._touchStart(e)},touchMove:e=>{this._mouseTouchMove(e)},touchEnd:e=>{this._touchEnd(e)},touchCancel:e=>{this._touchEnd(e)},touchEndClick:e=>{this._touchEndClick(e)},visibilityChange:()=>{this._handleVisibilityChange()}}}addListeners(){this._manageListeners(!0)}init(){for(let e of(this._clickPositionPlugins.length=0,this._container.plugins.filter(e=>!!e.clickPositionValid)))this._clickPositionPlugins.push(e)}removeListeners(){this._manageListeners(!1)}_doMouseTouchClick=e=>{let t=this._container,i=this._interactionManager,s=t.actualOptions;if(this._canPush){let e=i.interactivityData.mouse,t=e.position;if(!t)return;e.clickPosition={...t},e.clickTime=performance.now();let a=s.interactivity?.events.onClick;if(!a?.mode)return;(0,n.executeOnSingleOrMultiple)(a.mode,e=>{i.handleClickMode(e)})}"touchend"===e.type&&setTimeout(()=>{this._mouseTouchFinish()},n.touchDelay)};_handleVisibilityChange=()=>{this._mouseTouchFinish()};_manageInteractivityListeners=(e,t)=>{let i=this._handlers,a=this._container,r=this._interactionManager,o=a.actualOptions,c=r.interactivityData.element;if(!c)return;let l=a.canvas;l.setPointerEvents(c===l.element?"initial":"none"),(!t||o.interactivity?.events.onHover.enable||o.interactivity?.events.onClick.enable)&&((0,n.manageListener)(c,s.Rb,i.mouseMove,t),(0,n.manageListener)(c,s.s7,i.touchStart,t),(0,n.manageListener)(c,s.DG,i.touchMove,t),t?o.interactivity?.events.onClick.enable?((0,n.manageListener)(c,s.Bp,i.touchEndClick,t),(0,n.manageListener)(c,s.vo,i.mouseUp,t),(0,n.manageListener)(c,s.ms,i.mouseDown,t)):(0,n.manageListener)(c,s.Bp,i.touchEnd,t):((0,n.manageListener)(c,s.Bp,i.touchEndClick,t),(0,n.manageListener)(c,s.vo,i.mouseUp,t),(0,n.manageListener)(c,s.ms,i.mouseDown,t),(0,n.manageListener)(c,s.Bp,i.touchEnd,t)),(0,n.manageListener)(c,e,i.mouseLeave,t),(0,n.manageListener)(c,s.G3,i.touchCancel,t))};_manageListeners=e=>{let t=this._handlers,i=this._container,r=this._interactionManager,o=i.actualOptions,c=o.interactivity?.detectsOn,l=i.canvas.element,h=s.Z0;c===a.h.window?(r.interactivityData.element=globalThis,h=s.sf):c===a.h.parent&&l?r.interactivityData.element=l.parentElement??l.parentNode:r.interactivityData.element=l,this._manageInteractivityListeners(h,e),(0,n.manageListener)(document,n.visibilityChangeEvent,t.visibilityChange,e,!1)};_mouseDown=()=>{let{interactivityData:e}=this._interactionManager,{mouse:t}=e;t.clicking=!0,t.downPosition=t.position};_mouseTouchClick=e=>{let t=this._container,i=this._interactionManager,n=t.actualOptions,{mouse:s}=i.interactivityData;s.inside=!0;let a=!1,r=s.position;if(r&&n.interactivity?.events.onClick.enable){for(let e of this._clickPositionPlugins)if(a=e.clickPositionValid?.(r)??!1)break;a||this._doMouseTouchClick(e),s.clicking=!1}};_mouseTouchFinish=()=>{let{interactivityData:e}=this._interactionManager,{mouse:t}=e;delete t.position,delete t.clickPosition,delete t.downPosition,e.status=s.Z0,t.inside=!1,t.clicking=!1};_mouseTouchMove=e=>{let t,i=this._container,r=this._interactionManager,o=i.actualOptions,c=r.interactivityData,l=i.canvas.element;if(!c.element)return;if(c.mouse.inside=!0,e.type.startsWith("pointer"))if(this._canPush=!0,c.element===globalThis){if(l){let i=l.getBoundingClientRect();t={x:e.clientX-i.left,y:e.clientY-i.top}}}else if(o.interactivity?.detectsOn===a.h.parent){let i=e.target,s=e.currentTarget;if(l){let a=i.getBoundingClientRect(),r=s.getBoundingClientRect(),o=l.getBoundingClientRect();t={x:e.offsetX+n.double*a.left-(r.left+o.left),y:e.offsetY+n.double*a.top-(r.top+o.top)}}else t={x:e.offsetX,y:e.offsetY}}else e.target===l&&(t={x:e.offsetX,y:e.offsetY});else if(this._canPush="touchmove"!==e.type,l){let i=e.touches[e.touches.length-n.lengthOffset],s=l.getBoundingClientRect();if(!i)return;t={x:i.clientX-s.left,y:i.clientY-s.top}}let h=i.retina.pixelRatio;t&&(t.x*=h,t.y*=h),c.mouse.position=t,c.status=s.Rb};_touchEnd=e=>{for(let t of Array.from(e.changedTouches))this._touches.delete(t.identifier);this._mouseTouchFinish()};_touchEndClick=e=>{for(let t of Array.from(e.changedTouches))this._touches.delete(t.identifier);this._mouseTouchClick(e)};_touchStart=e=>{for(let t of Array.from(e.changedTouches))this._touches.set(t.identifier,performance.now());this._mouseTouchMove(e)}}var o=i(839);class c{container;interactivityData;_clickHandlers;_engine;_eventListeners;_externalInteractors;_globalInteractors;_interactors;_intersectionObserver;_particleInteractors;constructor(e,t){this.container=t,this._engine=e,this._interactors=[],this._externalInteractors=[],this._globalInteractors=[],this._particleInteractors=[],this._clickHandlers=new Map,this._eventListeners=new r(t,this),this.interactivityData={mouse:{clicking:!1,inside:!1}},this._intersectionObserver=(0,n.safeIntersectionObserver)(e=>{this._intersectionManager(e)})}addClickHandler(e){let{container:t,interactivityData:i}=this;if(t.destroyed)return;let a=i.element;if(!a)return;let r=(i,n,s)=>{if(t.destroyed)return;let a=t.retina.pixelRatio,r={x:n.x*a,y:n.y*a};e(i,t.particles.quadTree.queryCircle(r,s*a))},o=!1,c=!1;for(let[e,i]of(this._clickHandlers.set(s.xO,e=>{if(t.destroyed)return;let i={x:e.offsetX,y:e.offsetY};r(e,i,n.clickRadius)}),this._clickHandlers.set(s.s7,()=>{t.destroyed||(o=!0,c=!1)}),this._clickHandlers.set(s.DG,()=>{t.destroyed||(c=!0)}),this._clickHandlers.set(s.Bp,e=>{if(!t.destroyed){if(o&&!c){let i=e.touches[e.touches.length-n.touchEndLengthOffset];if(!i)return;let s=t.canvas.element,a=s?s.getBoundingClientRect():void 0;r(e,{x:i.clientX-(a?a.left:n.minCoordinate),y:i.clientY-(a?a.top:n.minCoordinate)},Math.max(i.radiusX,i.radiusY))}o=!1,c=!1}}),this._clickHandlers.set(s.G3,()=>{t.destroyed||(o=!1,c=!1)}),this._clickHandlers))a.addEventListener(e,i)}addListeners(){this._eventListeners.addListeners()}clearClickHandlers(){let{container:e,interactivityData:t}=this;if(!e.destroyed){for(let[e,i]of this._clickHandlers)t.element?.removeEventListener(e,i);this._clickHandlers.clear()}}externalInteract(e){for(let t of this._externalInteractors){let{interactivityData:i}=this;t.isEnabled(i)&&t.interact(i,e)}}globalInteract(e){for(let t of this._globalInteractors){let{interactivityData:i}=this;t.isEnabled(i)&&t.interact(i,e)}}handleClickMode(e){if(this.container.destroyed)return;let{interactivityData:t}=this;for(let i of this._externalInteractors)i.handleClickMode?.(e,t)}init(){for(let e of(this._eventListeners.init(),this._interactors)){switch(e.type){case o.e.external:this._externalInteractors.push(e);break;case o.e.particles:this._particleInteractors.push(e);break;case o.e.global:this._globalInteractors.push(e)}e.init()}}async initInteractors(){let e=await this._engine.getInteractors?.(this.container,!0);e&&(this._interactors=e,this._externalInteractors=[],this._particleInteractors=[])}particlesInteract(e,t){let{interactivityData:i}=this;for(let i of this._externalInteractors)i.clear(e,t);for(let n of this._particleInteractors)n.isEnabled(e,i)&&n.interact(e,i,t)}removeListeners(){this._eventListeners.removeListeners()}reset(e){let{interactivityData:t}=this;for(let i of this._externalInteractors)i.isEnabled(t)&&i.reset(t,e);for(let i of this._particleInteractors)i.isEnabled(e,t)&&i.reset(t,e)}startObserving(){let{interactivityData:e}=this;e.element instanceof HTMLElement&&this._intersectionObserver&&this._intersectionObserver.observe(e.element)}stopObserving(){let{interactivityData:e}=this;e.element instanceof HTMLElement&&this._intersectionObserver&&this._intersectionObserver.unobserve(e.element)}_intersectionManager=e=>{let{container:t}=this;if(!t.destroyed&&t.actualOptions.pauseOnOutsideViewport)for(let i of e)i.target===this.interactivityData.element&&(i.isIntersecting?t.play():t.pause())}}var l=i(626);class h{interactionManager;_container;_engine;constructor(e,t){this._container=t,this._engine=e,this.interactionManager=new c(e,t),this._container.addClickHandler=e=>{this.interactionManager.addClickHandler(e)}}addClickHandler(e){this.interactionManager.addClickHandler(e)}clearClickHandlers(){this.interactionManager.clearClickHandlers()}destroy(){this.clearClickHandlers(),this._engine.interactors?.delete(this._container)}particleCreated(e){let t=new l.k(this._engine,this._container);t.load(this._container.actualOptions.interactivity),t.load(e.options.interactivity),e.interactivity=t}particleReset(e){this.interactionManager.reset(e)}postParticleUpdate(e,t){this.interactionManager.particlesInteract(e,t)}postUpdate(e){this.interactionManager.globalInteract(e),this.interactionManager.externalInteract(e)}async preInit(){await this.interactionManager.initInteractors(),this.interactionManager.init()}async redrawInit(){await this.interactionManager.initInteractors(),this.interactionManager.init()}start(){return this.interactionManager.addListeners(),this.interactionManager.startObserving(),Promise.resolve()}stop(){this.interactionManager.removeListeners(),this.interactionManager.stopObserving()}}}}]);
|
package/703.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(this.webpackChunk_tsparticles_plugin_interactivity=this.webpackChunk_tsparticles_plugin_interactivity||[]).push([[703],{703(e,t,i){i.d(t,{InteractivityPlugin:()=>o});var n=i(303),s=i(626);class o{id="interactivity";_engine;constructor(e){this._engine=e}async getPlugin(e){let{InteractivityPluginInstance:t}=await i.e(221).then(i.bind(i,221));return new t(this._engine,e)}loadOptions(e,t,i){if(!this.needsPlugin())return;let n=t.interactivity;n?.load||(t.interactivity=n=new s.k(this._engine,e)),n.load(i?.interactivity);let o=this._engine.interactors?.get(e);if(o)for(let e of o)e.loadOptions&&e.loadOptions(t,i)}loadParticlesOptions(e,t,i){i?.interactivity&&(t.interactivity=(0,n.deepExtend)({},i.interactivity));let s=this._engine.interactors?.get(e);if(s)for(let e of s)e.loadParticlesOptions
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_interactivity=this.webpackChunk_tsparticles_plugin_interactivity||[]).push([[703],{703(e,t,i){i.d(t,{InteractivityPlugin:()=>o});var n=i(303),s=i(626);class o{id="interactivity";_engine;constructor(e){this._engine=e}async getPlugin(e){let{InteractivityPluginInstance:t}=await i.e(221).then(i.bind(i,221));return new t(this._engine,e)}loadOptions(e,t,i){if(!this.needsPlugin())return;let n=t.interactivity;n?.load||(t.interactivity=n=new s.k(this._engine,e)),n.load(i?.interactivity);let o=this._engine.interactors?.get(e);if(o)for(let e of o)e.loadOptions&&e.loadOptions(t,i)}loadParticlesOptions(e,t,i){i?.interactivity&&(t.interactivity=(0,n.deepExtend)({},i.interactivity));let s=this._engine.interactors?.get(e);if(s)for(let e of s)e.loadParticlesOptions?.(t,i)}needsPlugin(){return!0}}},626(e,t,i){i.d(t,{k:()=>c});var n=i(303);class s{enable;mode;constructor(){this.enable=!1,this.mode=[]}load(e){(0,n.isNull)(e)||(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.mode&&(this.mode=e.mode))}}var o=i(646);class l{enable;mode;constructor(){this.enable=!1,this.mode=[]}load(e){(0,n.isNull)(e)||(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.mode&&(this.mode=e.mode))}}class a{onClick;onDiv;onHover;constructor(){this.onClick=new s,this.onDiv=new o.G,this.onHover=new l}load(e){if((0,n.isNull)(e))return;this.onClick.load(e.onClick);let t=e.onDiv;void 0!==t&&(this.onDiv=(0,n.executeOnSingleOrMultiple)(t,e=>{let t=new o.G;return t.load(e),t})),this.onHover.load(e.onHover)}}var r=i(366),d=i(802);class c{detectsOn;events;modes;constructor(e,t){this.detectsOn=r.h.window,this.events=new a,this.modes=new d.d(e,t)}load(e){if((0,n.isNull)(e))return;let t=e.detectsOn;void 0!==t&&(this.detectsOn=t),this.events.load(e.events),this.modes.load(e.modes)}}}}]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clickRadius, minCoordinate, safeIntersectionObserver, touchEndLengthOffset, } from "@tsparticles/engine";
|
|
2
2
|
import { clickEvent, touchCancelEvent, touchEndEvent, touchMoveEvent, touchStartEvent, } from "./InteractivityConstants.js";
|
|
3
3
|
import { InteractivityEventListeners } from "./InteractivityEventListeners.js";
|
|
4
|
-
import { InteractorType } from "./InteractorType.js";
|
|
4
|
+
import { InteractorType } from "./Enums/InteractorType.js";
|
|
5
5
|
export class InteractionManager {
|
|
6
6
|
container;
|
|
7
7
|
interactivityData;
|
|
@@ -9,6 +9,7 @@ export class InteractionManager {
|
|
|
9
9
|
_engine;
|
|
10
10
|
_eventListeners;
|
|
11
11
|
_externalInteractors;
|
|
12
|
+
_globalInteractors;
|
|
12
13
|
_interactors;
|
|
13
14
|
_intersectionObserver;
|
|
14
15
|
_particleInteractors;
|
|
@@ -17,6 +18,7 @@ export class InteractionManager {
|
|
|
17
18
|
this._engine = engine;
|
|
18
19
|
this._interactors = [];
|
|
19
20
|
this._externalInteractors = [];
|
|
21
|
+
this._globalInteractors = [];
|
|
20
22
|
this._particleInteractors = [];
|
|
21
23
|
this._clickHandlers = new Map();
|
|
22
24
|
this._eventListeners = new InteractivityEventListeners(container, this);
|
|
@@ -123,6 +125,14 @@ export class InteractionManager {
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
128
|
+
globalInteract(delta) {
|
|
129
|
+
for (const interactor of this._globalInteractors) {
|
|
130
|
+
const { interactivityData } = this;
|
|
131
|
+
if (interactor.isEnabled(interactivityData)) {
|
|
132
|
+
interactor.interact(interactivityData, delta);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
126
136
|
handleClickMode(mode) {
|
|
127
137
|
if (this.container.destroyed) {
|
|
128
138
|
return;
|
|
@@ -132,14 +142,7 @@ export class InteractionManager {
|
|
|
132
142
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
|
-
|
|
136
|
-
const interactors = await this._engine.getInteractors?.(this.container, true);
|
|
137
|
-
if (!interactors) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this._interactors = interactors;
|
|
141
|
-
this._externalInteractors = [];
|
|
142
|
-
this._particleInteractors = [];
|
|
145
|
+
init() {
|
|
143
146
|
this._eventListeners.init();
|
|
144
147
|
for (const interactor of this._interactors) {
|
|
145
148
|
switch (interactor.type) {
|
|
@@ -149,10 +152,22 @@ export class InteractionManager {
|
|
|
149
152
|
case InteractorType.particles:
|
|
150
153
|
this._particleInteractors.push(interactor);
|
|
151
154
|
break;
|
|
155
|
+
case InteractorType.global:
|
|
156
|
+
this._globalInteractors.push(interactor);
|
|
157
|
+
break;
|
|
152
158
|
}
|
|
153
159
|
interactor.init();
|
|
154
160
|
}
|
|
155
161
|
}
|
|
162
|
+
async initInteractors() {
|
|
163
|
+
const interactors = await this._engine.getInteractors?.(this.container, true);
|
|
164
|
+
if (!interactors) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this._interactors = interactors;
|
|
168
|
+
this._externalInteractors = [];
|
|
169
|
+
this._particleInteractors = [];
|
|
170
|
+
}
|
|
156
171
|
particlesInteract(particle, delta) {
|
|
157
172
|
const { interactivityData } = this;
|
|
158
173
|
for (const interactor of this._externalInteractors) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { double, executeOnSingleOrMultiple, lengthOffset, manageListener, touchDelay, visibilityChangeEvent, } from "@tsparticles/engine";
|
|
2
2
|
import { mouseDownEvent, mouseLeaveEvent, mouseMoveEvent, mouseOutEvent, mouseUpEvent, touchCancelEvent, touchEndEvent, touchMoveEvent, touchStartEvent, } from "./InteractivityConstants.js";
|
|
3
|
-
import { InteractivityDetect } from "./InteractivityDetect.js";
|
|
3
|
+
import { InteractivityDetect } from "./Enums/InteractivityDetect.js";
|
|
4
4
|
export class InteractivityEventListeners {
|
|
5
5
|
_canPush = true;
|
|
6
6
|
_clickPositionPlugins;
|
|
@@ -91,18 +91,26 @@ export class InteractivityEventListeners {
|
|
|
91
91
|
}
|
|
92
92
|
const html = interactivityEl, canvas = container.canvas;
|
|
93
93
|
canvas.setPointerEvents(html === canvas.element ? "initial" : "none");
|
|
94
|
-
if (!(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
|
|
94
|
+
if (add && !(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
|
|
98
98
|
manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
|
|
99
99
|
manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
|
|
100
|
-
if (
|
|
100
|
+
if (add) {
|
|
101
|
+
if (options.interactivity?.events.onClick.enable) {
|
|
102
|
+
manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
|
|
103
|
+
manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
|
104
|
+
manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
101
111
|
manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
|
|
102
112
|
manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
|
103
113
|
manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
114
|
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
|
107
115
|
}
|
|
108
116
|
manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
|
|
@@ -38,9 +38,7 @@ export class InteractivityPlugin {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
for (const interactor of interactors) {
|
|
41
|
-
|
|
42
|
-
interactor.loadParticlesOptions(options, source);
|
|
43
|
-
}
|
|
41
|
+
interactor.loadParticlesOptions?.(options, source);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
needsPlugin() {
|
|
@@ -35,13 +35,16 @@ export class InteractivityPluginInstance {
|
|
|
35
35
|
this.interactionManager.particlesInteract(particle, delta);
|
|
36
36
|
}
|
|
37
37
|
postUpdate(delta) {
|
|
38
|
+
this.interactionManager.globalInteract(delta);
|
|
38
39
|
this.interactionManager.externalInteract(delta);
|
|
39
40
|
}
|
|
40
41
|
async preInit() {
|
|
41
|
-
await this.interactionManager.
|
|
42
|
+
await this.interactionManager.initInteractors();
|
|
43
|
+
this.interactionManager.init();
|
|
42
44
|
}
|
|
43
45
|
async redrawInit() {
|
|
44
|
-
await this.interactionManager.
|
|
46
|
+
await this.interactionManager.initInteractors();
|
|
47
|
+
this.interactionManager.init();
|
|
45
48
|
}
|
|
46
49
|
start() {
|
|
47
50
|
this.interactionManager.addListeners();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNull } from "@tsparticles/engine";
|
|
2
2
|
import { Events } from "./Events/Events.js";
|
|
3
|
-
import { InteractivityDetect } from "../../InteractivityDetect.js";
|
|
3
|
+
import { InteractivityDetect } from "../../Enums/InteractivityDetect.js";
|
|
4
4
|
import { Modes } from "./Modes/Modes.js";
|
|
5
5
|
export class Interactivity {
|
|
6
6
|
detectsOn;
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getItemsFromInitializer } from "@tsparticles/engine";
|
|
2
2
|
export async function loadInteractivityPlugin(engine) {
|
|
3
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.22");
|
|
4
4
|
await engine.register(async (e) => {
|
|
5
5
|
const interactivityEngine = e, { InteractivityPlugin } = await import("./InteractivityPlugin.js");
|
|
6
6
|
interactivityEngine.addPlugin(new InteractivityPlugin(interactivityEngine));
|
|
@@ -32,12 +32,13 @@ export function ensureInteractivityPluginLoaded(e) {
|
|
|
32
32
|
throw new Error("tsParticles Interactivity Plugin is not loaded");
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export * from "./
|
|
36
|
-
export * from "./
|
|
35
|
+
export * from "./BaseClasses/ExternalInteractorBase.js";
|
|
36
|
+
export * from "./BaseClasses/GlobalInteractorBase.js";
|
|
37
|
+
export * from "./BaseClasses/ParticlesInteractorBase.js";
|
|
37
38
|
export * from "./InteractivityConstants.js";
|
|
38
|
-
export * from "./
|
|
39
|
-
export * from "./
|
|
40
|
-
export * from "./
|
|
39
|
+
export * from "./Enums/DivType.js";
|
|
40
|
+
export * from "./Enums/InteractivityDetect.js";
|
|
41
|
+
export * from "./Enums/InteractorType.js";
|
|
41
42
|
export * from "./utils.js";
|
|
42
43
|
export * from "./Options/Classes/Events/DivEvent.js";
|
|
43
44
|
export * from "./Options/Classes/Modes/Modes.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clickRadius, minCoordinate, safeIntersectionObserver, touchEndLengthOffset, } from "@tsparticles/engine";
|
|
2
2
|
import { clickEvent, touchCancelEvent, touchEndEvent, touchMoveEvent, touchStartEvent, } from "./InteractivityConstants.js";
|
|
3
3
|
import { InteractivityEventListeners } from "./InteractivityEventListeners.js";
|
|
4
|
-
import { InteractorType } from "./InteractorType.js";
|
|
4
|
+
import { InteractorType } from "./Enums/InteractorType.js";
|
|
5
5
|
export class InteractionManager {
|
|
6
6
|
container;
|
|
7
7
|
interactivityData;
|
|
@@ -9,6 +9,7 @@ export class InteractionManager {
|
|
|
9
9
|
_engine;
|
|
10
10
|
_eventListeners;
|
|
11
11
|
_externalInteractors;
|
|
12
|
+
_globalInteractors;
|
|
12
13
|
_interactors;
|
|
13
14
|
_intersectionObserver;
|
|
14
15
|
_particleInteractors;
|
|
@@ -17,6 +18,7 @@ export class InteractionManager {
|
|
|
17
18
|
this._engine = engine;
|
|
18
19
|
this._interactors = [];
|
|
19
20
|
this._externalInteractors = [];
|
|
21
|
+
this._globalInteractors = [];
|
|
20
22
|
this._particleInteractors = [];
|
|
21
23
|
this._clickHandlers = new Map();
|
|
22
24
|
this._eventListeners = new InteractivityEventListeners(container, this);
|
|
@@ -123,6 +125,14 @@ export class InteractionManager {
|
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
128
|
+
globalInteract(delta) {
|
|
129
|
+
for (const interactor of this._globalInteractors) {
|
|
130
|
+
const { interactivityData } = this;
|
|
131
|
+
if (interactor.isEnabled(interactivityData)) {
|
|
132
|
+
interactor.interact(interactivityData, delta);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
126
136
|
handleClickMode(mode) {
|
|
127
137
|
if (this.container.destroyed) {
|
|
128
138
|
return;
|
|
@@ -132,14 +142,7 @@ export class InteractionManager {
|
|
|
132
142
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
133
143
|
}
|
|
134
144
|
}
|
|
135
|
-
|
|
136
|
-
const interactors = await this._engine.getInteractors?.(this.container, true);
|
|
137
|
-
if (!interactors) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this._interactors = interactors;
|
|
141
|
-
this._externalInteractors = [];
|
|
142
|
-
this._particleInteractors = [];
|
|
145
|
+
init() {
|
|
143
146
|
this._eventListeners.init();
|
|
144
147
|
for (const interactor of this._interactors) {
|
|
145
148
|
switch (interactor.type) {
|
|
@@ -149,10 +152,22 @@ export class InteractionManager {
|
|
|
149
152
|
case InteractorType.particles:
|
|
150
153
|
this._particleInteractors.push(interactor);
|
|
151
154
|
break;
|
|
155
|
+
case InteractorType.global:
|
|
156
|
+
this._globalInteractors.push(interactor);
|
|
157
|
+
break;
|
|
152
158
|
}
|
|
153
159
|
interactor.init();
|
|
154
160
|
}
|
|
155
161
|
}
|
|
162
|
+
async initInteractors() {
|
|
163
|
+
const interactors = await this._engine.getInteractors?.(this.container, true);
|
|
164
|
+
if (!interactors) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this._interactors = interactors;
|
|
168
|
+
this._externalInteractors = [];
|
|
169
|
+
this._particleInteractors = [];
|
|
170
|
+
}
|
|
156
171
|
particlesInteract(particle, delta) {
|
|
157
172
|
const { interactivityData } = this;
|
|
158
173
|
for (const interactor of this._externalInteractors) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { double, executeOnSingleOrMultiple, lengthOffset, manageListener, touchDelay, visibilityChangeEvent, } from "@tsparticles/engine";
|
|
2
2
|
import { mouseDownEvent, mouseLeaveEvent, mouseMoveEvent, mouseOutEvent, mouseUpEvent, touchCancelEvent, touchEndEvent, touchMoveEvent, touchStartEvent, } from "./InteractivityConstants.js";
|
|
3
|
-
import { InteractivityDetect } from "./InteractivityDetect.js";
|
|
3
|
+
import { InteractivityDetect } from "./Enums/InteractivityDetect.js";
|
|
4
4
|
export class InteractivityEventListeners {
|
|
5
5
|
_canPush = true;
|
|
6
6
|
_clickPositionPlugins;
|
|
@@ -91,18 +91,26 @@ export class InteractivityEventListeners {
|
|
|
91
91
|
}
|
|
92
92
|
const html = interactivityEl, canvas = container.canvas;
|
|
93
93
|
canvas.setPointerEvents(html === canvas.element ? "initial" : "none");
|
|
94
|
-
if (!(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
|
|
94
|
+
if (add && !(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
|
|
98
98
|
manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
|
|
99
99
|
manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
|
|
100
|
-
if (
|
|
100
|
+
if (add) {
|
|
101
|
+
if (options.interactivity?.events.onClick.enable) {
|
|
102
|
+
manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
|
|
103
|
+
manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
|
104
|
+
manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
101
111
|
manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
|
|
102
112
|
manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
|
103
113
|
manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
114
|
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
|
107
115
|
}
|
|
108
116
|
manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
|
|
@@ -38,9 +38,7 @@ export class InteractivityPlugin {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
for (const interactor of interactors) {
|
|
41
|
-
|
|
42
|
-
interactor.loadParticlesOptions(options, source);
|
|
43
|
-
}
|
|
41
|
+
interactor.loadParticlesOptions?.(options, source);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
needsPlugin() {
|
|
@@ -35,13 +35,16 @@ export class InteractivityPluginInstance {
|
|
|
35
35
|
this.interactionManager.particlesInteract(particle, delta);
|
|
36
36
|
}
|
|
37
37
|
postUpdate(delta) {
|
|
38
|
+
this.interactionManager.globalInteract(delta);
|
|
38
39
|
this.interactionManager.externalInteract(delta);
|
|
39
40
|
}
|
|
40
41
|
async preInit() {
|
|
41
|
-
await this.interactionManager.
|
|
42
|
+
await this.interactionManager.initInteractors();
|
|
43
|
+
this.interactionManager.init();
|
|
42
44
|
}
|
|
43
45
|
async redrawInit() {
|
|
44
|
-
await this.interactionManager.
|
|
46
|
+
await this.interactionManager.initInteractors();
|
|
47
|
+
this.interactionManager.init();
|
|
45
48
|
}
|
|
46
49
|
start() {
|
|
47
50
|
this.interactionManager.addListeners();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNull } from "@tsparticles/engine";
|
|
2
2
|
import { Events } from "./Events/Events.js";
|
|
3
|
-
import { InteractivityDetect } from "../../InteractivityDetect.js";
|
|
3
|
+
import { InteractivityDetect } from "../../Enums/InteractivityDetect.js";
|
|
4
4
|
import { Modes } from "./Modes/Modes.js";
|
|
5
5
|
export class Interactivity {
|
|
6
6
|
detectsOn;
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getItemsFromInitializer } from "@tsparticles/engine";
|
|
2
2
|
export async function loadInteractivityPlugin(engine) {
|
|
3
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.22");
|
|
4
4
|
await engine.register(async (e) => {
|
|
5
5
|
const interactivityEngine = e, { InteractivityPlugin } = await import("./InteractivityPlugin.js");
|
|
6
6
|
interactivityEngine.addPlugin(new InteractivityPlugin(interactivityEngine));
|
|
@@ -32,12 +32,13 @@ export function ensureInteractivityPluginLoaded(e) {
|
|
|
32
32
|
throw new Error("tsParticles Interactivity Plugin is not loaded");
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
export * from "./
|
|
36
|
-
export * from "./
|
|
35
|
+
export * from "./BaseClasses/ExternalInteractorBase.js";
|
|
36
|
+
export * from "./BaseClasses/GlobalInteractorBase.js";
|
|
37
|
+
export * from "./BaseClasses/ParticlesInteractorBase.js";
|
|
37
38
|
export * from "./InteractivityConstants.js";
|
|
38
|
-
export * from "./
|
|
39
|
-
export * from "./
|
|
40
|
-
export * from "./
|
|
39
|
+
export * from "./Enums/DivType.js";
|
|
40
|
+
export * from "./Enums/InteractivityDetect.js";
|
|
41
|
+
export * from "./Enums/InteractorType.js";
|
|
41
42
|
export * from "./utils.js";
|
|
42
43
|
export * from "./Options/Classes/Events/DivEvent.js";
|
|
43
44
|
export * from "./Options/Classes/Modes/Modes.js";
|