UNPKG

@tsparticles/interaction-external-push

Version:

tsParticles push external interaction

91 lines (84 loc) 7.33 kB
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this); /* External Interaction v4.3.2 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/plugin-interactivity'), require('@tsparticles/engine')) : typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/plugin-interactivity', '@tsparticles/engine'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.interactions = global.__tsParticlesInternals.interactions || {}, global.__tsParticlesInternals.interactions.externalPush = global.__tsParticlesInternals.interactions.externalPush || {}), global.__tsParticlesInternals.plugins.interactivity, global.__tsParticlesInternals.engine)); })(this, (function (exports, pluginInteractivity, engine) { 'use strict'; class Push { default = true; groups = []; particles; quantity = 4; load(data) { if (engine.isNull(data)) { return; } engine.loadProperty(this, "default", data.default); if (data.groups !== undefined) { this.groups = data.groups.map(t => t); } if (!this.groups.length) { this.default = true; } engine.loadRangeProperty(this, "quantity", data.quantity); this.particles = engine.executeOnSingleOrMultiple(data.particles, particles => { return engine.deepExtend({}, particles); }); } } const pushMode = "push", minQuantity = 0; class Pusher extends pluginInteractivity.ExternalInteractorBase { handleClickMode; maxDistance = 0; constructor(container) { super(container); this.handleClickMode = (mode, interactivityData) => { if (mode !== pushMode) { return; } const container = this.container, options = container.actualOptions, pushOptions = options.interactivity?.modes.push; if (!pushOptions) { return; } const quantity = engine.getRangeValue(pushOptions.quantity); if (quantity <= minQuantity) { return; } const group = engine.itemFromArray([undefined, ...pushOptions.groups]), groupOptions = group !== undefined ? container.actualOptions.particles.groups[group] : undefined, particlesOptions = engine.itemFromSingleOrMultiple(pushOptions.particles), overrideOptions = engine.deepExtend(groupOptions, particlesOptions); container.particles.push(quantity, interactivityData.mouse.position, overrideOptions, group); }; } clear() { } init() { } interact() { } isEnabled(interactivityData, particle) { const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events; return !!events && mouse.clicking && mouse.inside && !!mouse.position && engine.isInArray(pushMode, events.onClick.mode); } loadModeOptions(options, ...sources) { engine.loadOptionProperty(options, "push", Push, ...sources); } reset() { } } async function loadExternalPushInteraction(engine) { engine.checkVersion("4.3.2"); await engine.pluginManager.register((e) => { pluginInteractivity.ensureInteractivityPluginLoaded(e); e.pluginManager.addInteractor?.("externalPush", container => { return Promise.resolve(new Pusher(container)); }); }); } const globalObject = globalThis; globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {}; globalObject.loadExternalPushInteraction = loadExternalPushInteraction; exports.Push = Push; exports.loadExternalPushInteraction = loadExternalPushInteraction; })); Object.assign(globalThis.window || globalThis, { loadExternalPushInteraction: (globalThis.__tsParticlesInternals.interactions.externalPush || {}).loadExternalPushInteraction }); delete (globalThis.window || globalThis).tsparticlesInternalExports;