UNPKG

@tsparticles/plugin-motion

Version:

tsParticles motion sickness plugin

168 lines (149 loc) 13 kB
/*! * 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 * v3.9.1 */ /* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ (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__tsparticles_engine__) => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./dist/browser/MotionInstance.js": /*!****************************************!*\ !*** ./dist/browser/MotionInstance.js ***! \****************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ MotionInstance: () => (/* binding */ MotionInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst defaultFactor = 1,\n defaultReduce = 1,\n disableReduce = 0,\n identity = 1;\nclass MotionInstance {\n constructor(container, engine) {\n this._handleMotionChange = mediaQuery => {\n const container = this._container,\n motion = container.actualOptions.motion;\n if (!motion) {\n return;\n }\n if (mediaQuery.matches) {\n if (motion.disable) {\n container.retina.reduceFactor = disableReduce;\n } else {\n container.retina.reduceFactor = motion.reduce.value ? identity / motion.reduce.factor : defaultFactor;\n }\n } else {\n container.retina.reduceFactor = defaultReduce;\n }\n };\n this._container = container;\n this._engine = engine;\n }\n async init() {\n const container = this._container,\n options = container.actualOptions.motion;\n if (!(options && (options.disable || options.reduce.value))) {\n container.retina.reduceFactor = 1;\n return;\n }\n const mediaQuery = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeMatchMedia)(\"(prefers-reduced-motion: reduce)\");\n if (!mediaQuery) {\n container.retina.reduceFactor = defaultFactor;\n return;\n }\n this._handleMotionChange(mediaQuery);\n const handleChange = () => {\n void (async () => {\n this._handleMotionChange(mediaQuery);\n try {\n await container.refresh();\n } catch {}\n })();\n };\n if (mediaQuery.addEventListener !== undefined) {\n mediaQuery.addEventListener(\"change\", handleChange);\n } else if (mediaQuery.addListener !== undefined) {\n mediaQuery.addListener(handleChange);\n }\n await Promise.resolve();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/MotionInstance.js?\n}"); /***/ }), /***/ "./dist/browser/MotionPlugin.js": /*!**************************************!*\ !*** ./dist/browser/MotionPlugin.js ***! \**************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ MotionPlugin: () => (/* binding */ MotionPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_Motion_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/Motion.js */ \"./dist/browser/Options/Classes/Motion.js\");\n/* harmony import */ var _MotionInstance_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./MotionInstance.js */ \"./dist/browser/MotionInstance.js\");\n\n\nclass MotionPlugin {\n constructor(engine) {\n this.id = \"motion\";\n this._engine = engine;\n }\n getPlugin(container) {\n return Promise.resolve(new _MotionInstance_js__WEBPACK_IMPORTED_MODULE_1__.MotionInstance(container, this._engine));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin()) {\n return;\n }\n let motionOptions = options.motion;\n if (!motionOptions?.load) {\n options.motion = motionOptions = new _Options_Classes_Motion_js__WEBPACK_IMPORTED_MODULE_0__.Motion();\n }\n motionOptions.load(source?.motion);\n }\n needsPlugin() {\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/MotionPlugin.js?\n}"); /***/ }), /***/ "./dist/browser/Options/Classes/Motion.js": /*!************************************************!*\ !*** ./dist/browser/Options/Classes/Motion.js ***! \************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Motion: () => (/* binding */ Motion)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _MotionReduce_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./MotionReduce.js */ \"./dist/browser/Options/Classes/MotionReduce.js\");\n\n\nclass Motion {\n constructor() {\n this.disable = true;\n this.reduce = new _MotionReduce_js__WEBPACK_IMPORTED_MODULE_1__.MotionReduce();\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.disable !== undefined) {\n this.disable = data.disable;\n }\n this.reduce.load(data.reduce);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/Options/Classes/Motion.js?\n}"); /***/ }), /***/ "./dist/browser/Options/Classes/MotionReduce.js": /*!******************************************************!*\ !*** ./dist/browser/Options/Classes/MotionReduce.js ***! \******************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ MotionReduce: () => (/* binding */ MotionReduce)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass MotionReduce {\n constructor() {\n this.factor = 4;\n this.value = true;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.factor !== undefined) {\n this.factor = data.factor;\n }\n if (data.value !== undefined) {\n this.value = data.value;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/Options/Classes/MotionReduce.js?\n}"); /***/ }), /***/ "./dist/browser/index.js": /*!*******************************!*\ !*** ./dist/browser/index.js ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadMotionPlugin: () => (/* binding */ loadMotionPlugin)\n/* harmony export */ });\n/* harmony import */ var _MotionPlugin_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./MotionPlugin.js */ \"./dist/browser/MotionPlugin.js\");\n\nasync function loadMotionPlugin(engine, refresh = true) {\n engine.checkVersion(\"3.9.1\");\n await engine.addPlugin(new _MotionPlugin_js__WEBPACK_IMPORTED_MODULE_0__.MotionPlugin(engine), refresh);\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-motion/./dist/browser/index.js?\n}"); /***/ }), /***/ "@tsparticles/engine": /*!*********************************************************************************************************************************!*\ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***! \*********************************************************************************************************************************/ /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__; /***/ }) /******/ }); /************************************************************************/ /******/ // 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/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* 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 }); /******/ }; /******/ })(); /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module can't be inlined because the eval devtool is used. /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js"); /******/ /******/ return __webpack_exports__; /******/ })() ; });