lecoffre-back/node_modules/tsparticles-interaction-external-attract/tsparticles.interaction.external.attract.js
2023-02-17 11:06:01 +01:00

294 lines
11 KiB
JavaScript

/*!
* Author : Matteo Bruni
* MIT license: https://opensource.org/licenses/MIT
* Demo / Generator : https://particles.js.org/
* GitHub : https://www.github.com/matteobruni/tsparticles
* How to use? : Check the GitHub README
* v2.8.0
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("tsparticles-engine"));
else if(typeof define === 'function' && define.amd)
define(["tsparticles-engine"], factory);
else {
var a = typeof exports === 'object' ? factory(require("tsparticles-engine")) : factory(root["window"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, (__WEBPACK_EXTERNAL_MODULE__961__) => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 961:
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_MODULE__961__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"Attract": () => (/* reexport */ Attract),
"loadExternalAttractInteraction": () => (/* binding */ loadExternalAttractInteraction)
});
// EXTERNAL MODULE: external {"commonjs":"tsparticles-engine","commonjs2":"tsparticles-engine","amd":"tsparticles-engine","root":"window"}
var external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_ = __webpack_require__(961);
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Attract.js
class Attract {
constructor() {
this.distance = 200;
this.duration = 0.4;
this.easing = "ease-out-quad";
this.factor = 1;
this.maxSpeed = 50;
this.speed = 1;
}
load(data) {
if (!data) {
return;
}
if (data.distance !== undefined) {
this.distance = data.distance;
}
if (data.duration !== undefined) {
this.duration = data.duration;
}
if (data.easing !== undefined) {
this.easing = data.easing;
}
if (data.factor !== undefined) {
this.factor = data.factor;
}
if (data.maxSpeed !== undefined) {
this.maxSpeed = data.maxSpeed;
}
if (data.speed !== undefined) {
this.speed = data.speed;
}
}
}
;// CONCATENATED MODULE: ./dist/browser/Attractor.js
class Attractor extends external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.ExternalInteractorBase {
constructor(engine, container) {
super(container);
this._engine = engine;
if (!container.attract) {
container.attract = {
particles: []
};
}
this.handleClickMode = mode => {
const options = this.container.actualOptions,
attract = options.interactivity.modes.attract;
if (!attract || mode !== "attract") {
return;
}
if (!container.attract) {
container.attract = {
particles: []
};
}
container.attract.clicking = true;
container.attract.count = 0;
for (const particle of container.attract.particles) {
if (!this.isEnabled(particle)) {
continue;
}
particle.velocity.setTo(particle.initialVelocity);
}
container.attract.particles = [];
container.attract.finish = false;
setTimeout(() => {
if (!container.destroyed) {
if (!container.attract) {
container.attract = {
particles: []
};
}
container.attract.clicking = false;
}
}, attract.duration * 1000);
};
}
clear() {}
init() {
const container = this.container,
attract = container.actualOptions.interactivity.modes.attract;
if (!attract) {
return;
}
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
}
async interact() {
const container = this.container,
options = container.actualOptions,
mouseMoveStatus = container.interactivity.status === external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.mouseMoveEvent,
events = options.interactivity.events,
hoverEnabled = events.onHover.enable,
hoverMode = events.onHover.mode,
clickEnabled = events.onClick.enable,
clickMode = events.onClick.mode;
if (mouseMoveStatus && hoverEnabled && (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isInArray)("attract", hoverMode)) {
this.hoverAttract();
} else if (clickEnabled && (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isInArray)("attract", clickMode)) {
this.clickAttract();
}
}
isEnabled(particle) {
var _a;
const container = this.container,
options = container.actualOptions,
mouse = container.interactivity.mouse,
events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
if ((!mouse.position || !events.onHover.enable) && (!mouse.clickPosition || !events.onClick.enable)) {
return false;
}
const hoverMode = events.onHover.mode,
clickMode = events.onClick.mode;
return (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isInArray)("attract", hoverMode) || (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isInArray)("attract", clickMode);
}
loadModeOptions(options, ...sources) {
if (!options.attract) {
options.attract = new Attract();
}
for (const source of sources) {
options.attract.load(source === null || source === void 0 ? void 0 : source.attract);
}
}
reset() {}
clickAttract() {
const container = this.container;
if (!container.attract) {
container.attract = {
particles: []
};
}
if (!container.attract.finish) {
if (!container.attract.count) {
container.attract.count = 0;
}
container.attract.count++;
if (container.attract.count === container.particles.count) {
container.attract.finish = true;
}
}
if (container.attract.clicking) {
const mousePos = container.interactivity.mouse.clickPosition,
attractRadius = container.retina.attractModeDistance;
if (!attractRadius || attractRadius < 0 || !mousePos) {
return;
}
this.processAttract(mousePos, attractRadius, new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle(mousePos.x, mousePos.y, attractRadius));
} else if (container.attract.clicking === false) {
container.attract.particles = [];
}
return;
}
hoverAttract() {
const container = this.container,
mousePos = container.interactivity.mouse.position,
attractRadius = container.retina.attractModeDistance;
if (!attractRadius || attractRadius < 0 || !mousePos) {
return;
}
this.processAttract(mousePos, attractRadius, new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle(mousePos.x, mousePos.y, attractRadius));
}
processAttract(position, attractRadius, area) {
const container = this.container,
attractOptions = container.actualOptions.interactivity.modes.attract;
if (!attractOptions) {
return;
}
const query = container.particles.quadTree.query(area, p => this.isEnabled(p));
for (const particle of query) {
const {
dx,
dy,
distance
} = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getDistances)(particle.position, position);
const velocity = attractOptions.speed * attractOptions.factor;
const attractFactor = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.clamp)((0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getEasing)(attractOptions.easing)(1 - distance / attractRadius) * velocity, 0, attractOptions.maxSpeed);
const normVec = external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Vector.create(distance === 0 ? velocity : dx / distance * attractFactor, distance === 0 ? velocity : dy / distance * attractFactor);
particle.position.subFrom(normVec);
}
}
}
;// CONCATENATED MODULE: ./dist/browser/index.js
async function loadExternalAttractInteraction(engine) {
await engine.addInteractor("externalAttract", container => new Attractor(engine, container));
}
})();
/******/ return __webpack_exports__;
/******/ })()
;
});