UNPKG

@tsparticles/updater-orbit

Version:

tsParticles particles orbit updater

178 lines (156 loc) 16.7 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/Enums.js": /*!*******************************!*\ !*** ./dist/browser/Enums.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 */ OrbitType: () => (/* binding */ OrbitType)\n/* harmony export */ });\nvar OrbitType;\n(function (OrbitType) {\n OrbitType[\"front\"] = \"front\";\n OrbitType[\"back\"] = \"back\";\n})(OrbitType || (OrbitType = {}));\n\n//# sourceURL=webpack://@tsparticles/updater-orbit/./dist/browser/Enums.js?\n}"); /***/ }), /***/ "./dist/browser/Options/Classes/Orbit.js": /*!***********************************************!*\ !*** ./dist/browser/Options/Classes/Orbit.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 */ Orbit: () => (/* binding */ Orbit)\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 _OrbitRotation_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OrbitRotation.js */ \"./dist/browser/Options/Classes/OrbitRotation.js\");\n\n\nclass Orbit {\n constructor() {\n this.animation = new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimationOptions();\n this.enable = false;\n this.opacity = 1;\n this.rotation = new _OrbitRotation_js__WEBPACK_IMPORTED_MODULE_1__.OrbitRotation();\n this.width = 1;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n this.animation.load(data.animation);\n this.rotation.load(data.rotation);\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n if (data.opacity !== undefined) {\n this.opacity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.opacity);\n }\n if (data.width !== undefined) {\n this.width = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.width);\n }\n if (data.radius !== undefined) {\n this.radius = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.radius);\n }\n if (data.color !== undefined) {\n this.color = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.OptionsColor.create(this.color, data.color);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-orbit/./dist/browser/Options/Classes/Orbit.js?\n}"); /***/ }), /***/ "./dist/browser/Options/Classes/OrbitRotation.js": /*!*******************************************************!*\ !*** ./dist/browser/Options/Classes/OrbitRotation.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 */ OrbitRotation: () => (/* binding */ OrbitRotation)\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 OrbitRotation extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ValueWithRandom {\n constructor() {\n super();\n this.value = 45;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n super.load(data);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-orbit/./dist/browser/Options/Classes/OrbitRotation.js?\n}"); /***/ }), /***/ "./dist/browser/OrbitUpdater.js": /*!**************************************!*\ !*** ./dist/browser/OrbitUpdater.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 */ OrbitUpdater: () => (/* binding */ OrbitUpdater)\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 _Options_Classes_Orbit_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Orbit.js */ \"./dist/browser/Options/Classes/Orbit.js\");\n/* harmony import */ var _Enums_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums.js */ \"./dist/browser/Enums.js\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\n\n\nconst double = 2,\n half = 0.5,\n doublePI = Math.PI * double,\n defaultOrbitSpeed = 0,\n halfPI = Math.PI * half,\n piAndAHalf = Math.PI + halfPI,\n startAngle = 0,\n defaultOpacity = 1,\n defaultWidth = 1,\n defaultRotation = 0;\nclass OrbitUpdater {\n constructor(container, engine) {\n this._engine = engine;\n this._container = container;\n }\n afterDraw(particle) {\n const orbitOptions = particle.options.orbit;\n if (orbitOptions?.enable) {\n this.drawOrbit(particle, _Enums_js__WEBPACK_IMPORTED_MODULE_2__.OrbitType.front);\n }\n }\n beforeDraw(particle) {\n const orbitOptions = particle.options.orbit;\n if (orbitOptions?.enable) {\n this.drawOrbit(particle, _Enums_js__WEBPACK_IMPORTED_MODULE_2__.OrbitType.back);\n }\n }\n drawOrbit(particle, type) {\n const container = this._container;\n let start, end;\n switch (type) {\n case _Enums_js__WEBPACK_IMPORTED_MODULE_2__.OrbitType.back:\n start = halfPI;\n end = piAndAHalf;\n break;\n case _Enums_js__WEBPACK_IMPORTED_MODULE_2__.OrbitType.front:\n start = piAndAHalf;\n end = halfPI;\n break;\n default:\n start = startAngle;\n end = doublePI;\n }\n container.canvas.draw(ctx => {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_3__.drawEllipse)(ctx, particle, particle.orbitColor ?? particle.getFillColor(), particle.retina.orbitRadius ?? container.retina.orbitRadius ?? particle.getRadius(), particle.orbitOpacity ?? defaultOpacity, particle.orbitWidth ?? defaultWidth, (particle.orbitRotation ?? defaultRotation) * container.retina.pixelRatio, start, end);\n });\n }\n init(particle) {\n const container = this._container,\n particlesOptions = particle.options,\n orbitOptions = particlesOptions.orbit;\n if (!orbitOptions?.enable) {\n return;\n }\n particle.orbitRotation = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(orbitOptions.rotation.value);\n particle.orbitColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(this._engine, orbitOptions.color);\n particle.retina.orbitRadius = orbitOptions.radius !== undefined ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(orbitOptions.radius) * container.retina.pixelRatio : undefined;\n container.retina.orbitRadius = particle.retina.orbitRadius;\n particle.orbitAnimationSpeed = orbitOptions.animation.enable ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(orbitOptions.animation.speed) : defaultOrbitSpeed;\n particle.orbitWidth = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(orbitOptions.width);\n particle.orbitOpacity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(orbitOptions.opacity);\n }\n isEnabled(particle) {\n const orbitAnimations = particle.options.orbit?.animation;\n return !particle.destroyed && !particle.spawning && !!orbitAnimations?.enable;\n }\n loadOptions(options, ...sources) {\n if (!options.orbit) {\n options.orbit = new _Options_Classes_Orbit_js__WEBPACK_IMPORTED_MODULE_1__.Orbit();\n }\n for (const source of sources) {\n options.orbit.load(source?.orbit);\n }\n }\n update(particle, delta) {\n if (!this.isEnabled(particle)) {\n return;\n }\n if (particle.orbitRotation === undefined) {\n particle.orbitRotation = defaultRotation;\n }\n particle.orbitRotation += (particle.orbitAnimationSpeed ?? defaultOrbitSpeed / doublePI) * delta.factor;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-orbit/./dist/browser/OrbitUpdater.js?\n}"); /***/ }), /***/ "./dist/browser/Utils.js": /*!*******************************!*\ !*** ./dist/browser/Utils.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 */ drawEllipse: () => (/* binding */ drawEllipse)\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 minWidth = 0,\n half = 0.5,\n double = 2;\nfunction drawEllipse(context, particle, fillColorValue, radius, opacity, width, rotation, start, end) {\n if (width <= minWidth) {\n return;\n }\n const pos = particle.getPosition();\n if (fillColorValue) {\n context.strokeStyle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromHsl)(fillColorValue, opacity);\n }\n context.lineWidth = width;\n const rotationRadian = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.degToRad)(rotation);\n context.beginPath();\n context.ellipse(pos.x, pos.y, radius * half, radius * double, rotationRadian, start, end);\n context.stroke();\n}\n\n//# sourceURL=webpack://@tsparticles/updater-orbit/./dist/browser/Utils.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 */ loadOrbitUpdater: () => (/* binding */ loadOrbitUpdater)\n/* harmony export */ });\n/* harmony import */ var _OrbitUpdater_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./OrbitUpdater.js */ \"./dist/browser/OrbitUpdater.js\");\n\nasync function loadOrbitUpdater(engine, refresh = true) {\n engine.checkVersion(\"3.9.1\");\n await engine.addParticleUpdater(\"orbit\", container => {\n return Promise.resolve(new _OrbitUpdater_js__WEBPACK_IMPORTED_MODULE_0__.OrbitUpdater(container, engine));\n }, refresh);\n}\n\n//# sourceURL=webpack://@tsparticles/updater-orbit/./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__; /******/ })() ; });