@tsparticles/interaction-external-bounce
Version:
tsParticles bounce external interaction
2 lines (1 loc) • 6.91 kB
JavaScript
!function(t){t.__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.bundles=t.__tsParticlesInternals.bundles||{},t.__tsParticlesInternals.effects=t.__tsParticlesInternals.effects||{},t.__tsParticlesInternals.engine=t.__tsParticlesInternals.engine||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.palettes=t.__tsParticlesInternals.palettes||{},t.__tsParticlesInternals.paths=t.__tsParticlesInternals.paths||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins.emittersShapes=t.__tsParticlesInternals.plugins.emittersShapes||{},t.__tsParticlesInternals.presets=t.__tsParticlesInternals.presets||{},t.__tsParticlesInternals.shapes=t.__tsParticlesInternals.shapes||{},t.__tsParticlesInternals.updaters=t.__tsParticlesInternals.updaters||{},t.__tsParticlesInternals.utils=t.__tsParticlesInternals.utils||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas.utils=t.__tsParticlesInternals.canvas.utils||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path.utils=t.__tsParticlesInternals.path.utils||{};var e="undefined"!=typeof Proxy?function(t){return new Proxy(t,{get:function(t,e){return e in t||(t[e]={}),t[e]}})}:function(t){return t};t.__tsParticlesInternals.bundles=e(t.__tsParticlesInternals.bundles),t.__tsParticlesInternals.effects=e(t.__tsParticlesInternals.effects),t.__tsParticlesInternals.interactions=e(t.__tsParticlesInternals.interactions),t.__tsParticlesInternals.palettes=e(t.__tsParticlesInternals.palettes),t.__tsParticlesInternals.paths=e(t.__tsParticlesInternals.paths),t.__tsParticlesInternals.plugins=e(t.__tsParticlesInternals.plugins),t.__tsParticlesInternals.plugins.emittersShapes=e(t.__tsParticlesInternals.plugins.emittersShapes),t.__tsParticlesInternals.presets=e(t.__tsParticlesInternals.presets),t.__tsParticlesInternals.shapes=e(t.__tsParticlesInternals.shapes),t.__tsParticlesInternals.updaters=e(t.__tsParticlesInternals.updaters),t.__tsParticlesInternals.utils=e(t.__tsParticlesInternals.utils),t.__tsParticlesInternals.canvas=e(t.__tsParticlesInternals.canvas),t.__tsParticlesInternals.path=e(t.__tsParticlesInternals.path),t.tsparticlesInternalExports=t.tsparticlesInternalExports||{}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine")):"function"==typeof define&&define.amd?define(["exports","@tsparticles/plugin-interactivity","@tsparticles/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.interactions.externalBounce=t.__tsParticlesInternals.interactions.externalBounce||{}),t.__tsParticlesInternals.plugins.interactivity,t.__tsParticlesInternals.engine)}(this,function(t,e,s){"use strict";const n=Math.PI*s.half;function a(t,e,a,i,r){const c=t.particles.grid.query(i,r);for(const t of c)i instanceof s.Circle?s.circleBounce(s.circleBounceDataFromParticle(t),{position:e,radius:a,mass:a**s.squareExp*n,velocity:s.Vector.origin,factor:s.Vector.origin}):i instanceof s.Rectangle&&l(t,s.calculateBounds(e,a))}function i(t,n,i,r){e.divModeExecute(i,n,(n,i)=>{!function(t,n,a,i){const r=s.safeDocument().querySelectorAll(n);r.length&&r.forEach(n=>{const r=n,l=t.retina.pixelRatio,c={x:(r.offsetLeft+r.offsetWidth*s.half)*l,y:(r.offsetTop+r.offsetHeight*s.half)*l},o=r.offsetWidth*s.half*l,_=10*l,u=a.type===e.DivType.circle?new s.Circle(c.x,c.y,o+_):new s.Rectangle(r.offsetLeft*l-_,r.offsetTop*l-_,r.offsetWidth*l+_*s.double,r.offsetHeight*l+_*s.double);i(c,o,u)})}(t,n,i,(e,s,n)=>{a(t,e,s,n,r)})})}function r(t){const e={bounced:!1},{pSide:n,pOtherSide:a,rectSide:i,rectOtherSide:r,velocity:l,factor:c}=t;return a.min<r.min||a.min>r.max||a.max<r.min||a.max>r.max||(n.max>=i.min&&n.max<=(i.max+i.min)*s.half&&l>s.minVelocity||n.min<=i.max&&n.min>(i.max+i.min)*s.half&&l<s.minVelocity)&&(e.velocity=l*-c,e.bounced=!0),e}function l(t,e){const n=t.getPosition(),a=t.getRadius(),i=s.calculateBounds(n,a),l=t.options.bounce,c=r({pSide:{min:i.left,max:i.right},pOtherSide:{min:i.top,max:i.bottom},rectSide:{min:e.left,max:e.right},rectOtherSide:{min:e.top,max:e.bottom},velocity:t.velocity.x,factor:s.getRangeValue(l.horizontal.value)});c.bounced&&(void 0!==c.velocity&&(t.velocity.x=c.velocity),void 0!==c.position&&(t.position.x=c.position));const o=r({pSide:{min:i.top,max:i.bottom},pOtherSide:{min:i.left,max:i.right},rectSide:{min:e.top,max:e.bottom},rectOtherSide:{min:e.left,max:e.right},velocity:t.velocity.y,factor:s.getRangeValue(l.vertical.value)});o.bounced&&(void 0!==o.velocity&&(t.velocity.y=o.velocity),void 0!==o.position&&(t.position.y=o.position))}class c{distance=200;load(t){s.isNull(t)||s.loadProperty(this,"distance",t.distance)}}const o="bounce";class _ extends e.ExternalInteractorBase{#t;constructor(t){super(t),this.#t=0}get maxDistance(){return this.#t}clear(){}init(){const t=this.container,e=t.actualOptions.interactivity?.modes.bounce;e&&(this.#t=e.distance,t.retina.bounceModeDistance=e.distance*t.retina.pixelRatio)}interact(t){const n=this.container.actualOptions,r=n.interactivity?.events,l=t.status===e.mouseMoveEvent;if(!r)return;const c=r.onHover.enable,_=r.onHover.mode,u=r.onDiv;l&&c&&s.isInArray(o,_)?function(t,e,n){const i=10*t.retina.pixelRatio,r=e.mouse.position,l=t.retina.bounceModeDistance;!l||l<s.minRadius||!r||a(t,r,l,new s.Circle(r.x,r.y,l+i),n)}(this.container,t,e=>this.isEnabled(t,e)):i(this.container,u,o,e=>this.isEnabled(t,e))}isEnabled(t,n){const a=this.container.actualOptions,i=t.mouse,r=(n?.interactivity??a.interactivity)?.events;if(!r)return!1;const l=r.onDiv;return!!i.position&&r.onHover.enable&&s.isInArray(o,r.onHover.mode)||e.isDivModeEnabled(o,l)}loadModeOptions(t,...e){s.loadOptionProperty(t,"bounce",c,...e)}reset(){}}async function u(t){t.checkVersion("4.3.2"),await t.pluginManager.register(t=>{e.ensureInteractivityPluginLoaded(t),t.pluginManager.addInteractor?.("externalBounce",t=>Promise.resolve(new _(t)))})}const p=globalThis;p.__tsParticlesInternals=p.__tsParticlesInternals??{},p.loadExternalBounceInteraction=u,t.Bounce=c,t.loadExternalBounceInteraction=u}),Object.assign(globalThis.window||globalThis,{loadExternalBounceInteraction:(globalThis.__tsParticlesInternals.interactions.externalBounce||{}).loadExternalBounceInteraction}),delete(globalThis.window||globalThis).tsparticlesInternalExports;