@tsparticles/engine 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/373.min.js +2 -0
- package/373.min.js.LICENSE.txt +1 -0
- package/438.min.js +2 -0
- package/438.min.js.LICENSE.txt +1 -0
- package/README.md +72 -71
- package/browser/Core/Canvas.js +85 -32
- package/browser/Core/Container.js +8 -7
- package/browser/Core/Engine.js +14 -15
- package/browser/Core/Particle.js +14 -15
- package/browser/Core/Particles.js +42 -35
- package/browser/Core/Utils/EventListeners.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +3 -2
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/browser/Utils/CanvasUtils.js +14 -14
- package/cjs/Core/Canvas.js +85 -32
- package/cjs/Core/Container.js +8 -7
- package/cjs/Core/Engine.js +37 -15
- package/cjs/Core/Particle.js +14 -15
- package/cjs/Core/Particles.js +65 -35
- package/cjs/Core/Utils/EventListeners.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +3 -2
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/cjs/Utils/CanvasUtils.js +14 -14
- package/dist_browser_Core_Container_js.js +92 -0
- package/dist_browser_Core_Particle_js.js +32 -0
- package/esm/Core/Canvas.js +85 -32
- package/esm/Core/Container.js +8 -7
- package/esm/Core/Engine.js +14 -15
- package/esm/Core/Particle.js +14 -15
- package/esm/Core/Particles.js +42 -35
- package/esm/Core/Utils/EventListeners.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +3 -2
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/esm/Utils/CanvasUtils.js +14 -14
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +894 -5820
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +5 -3
- package/types/Core/Container.d.ts +1 -1
- package/types/Core/Engine.d.ts +13 -8
- package/types/Core/Interfaces/IContainerPlugin.d.ts +3 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
- package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IPlugin.d.ts +1 -1
- package/types/Core/Interfaces/IShapeDrawer.d.ts +4 -4
- package/types/Core/Particle.d.ts +3 -3
- package/types/Core/Particles.d.ts +12 -8
- package/types/Core/Utils/InteractionManager.d.ts +2 -2
- package/types/Enums/Modes/OutMode.d.ts +0 -3
- package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +2 -1
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +6 -6
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMask.d.ts +2 -1
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.d.ts +2 -1
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IOutModes.d.ts +6 -6
- package/types/Utils/CanvasUtils.d.ts +6 -6
- package/umd/Core/Canvas.js +85 -32
- package/umd/Core/Container.js +8 -7
- package/umd/Core/Engine.js +39 -16
- package/umd/Core/Particle.js +14 -15
- package/umd/Core/Particles.js +67 -36
- package/umd/Core/Utils/EventListeners.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +3 -2
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/umd/Utils/CanvasUtils.js +14 -14
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* tsParticles Engine v3.2.0
|
|
3
|
+
* Author: Matteo Bruni
|
|
4
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
5
|
+
* Website: https://particles.js.org/
|
|
6
|
+
* Confetti Website: https://confetti.js.org
|
|
7
|
+
* GitHub: https://www.github.com/matteobruni/tsparticles
|
|
8
|
+
* How to use?: Check the GitHub README
|
|
9
|
+
* ------------------------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
"use strict";
|
|
12
|
+
/*
|
|
13
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
14
|
+
* This devtool is neither made for production nor for readable output files.
|
|
15
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
16
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
17
|
+
* or disable the default devtool with "devtool: false".
|
|
18
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
19
|
+
*/
|
|
20
|
+
(this["webpackChunk_tsparticles_engine"] = this["webpackChunk_tsparticles_engine"] || []).push([["dist_browser_Core_Container_js"],{
|
|
21
|
+
|
|
22
|
+
/***/ "./dist/browser/Core/Canvas.js":
|
|
23
|
+
/*!*************************************!*\
|
|
24
|
+
!*** ./dist/browser/Core/Canvas.js ***!
|
|
25
|
+
\*************************************/
|
|
26
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
27
|
+
|
|
28
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Canvas: () => (/* binding */ Canvas)\n/* harmony export */ });\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n\n\n\n\nfunction setTransformValue(factor, newFactor, key) {\n const newValue = newFactor[key],\n defaultValue = 1;\n if (newValue !== undefined) {\n factor[key] = (factor[key] ?? defaultValue) * newValue;\n }\n}\nfunction setStyle(canvas, style, important = false) {\n if (!style) {\n return;\n }\n const element = canvas;\n if (!element) {\n return;\n }\n const elementStyle = element.style;\n if (!elementStyle) {\n return;\n }\n for (const key in style) {\n const value = style[key];\n if (!value) {\n continue;\n }\n elementStyle.setProperty(key, value, important ? \"important\" : \"\");\n }\n}\nclass Canvas {\n constructor(container) {\n this.container = container;\n this._applyPostDrawUpdaters = particle => {\n for (const updater of this._postDrawUpdaters) {\n updater.afterDraw?.(particle);\n }\n };\n this._applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {\n for (const updater of this._preDrawUpdaters) {\n if (updater.getColorStyles) {\n const {\n fill,\n stroke\n } = updater.getColorStyles(particle, ctx, radius, zOpacity);\n if (fill) {\n colorStyles.fill = fill;\n }\n if (stroke) {\n colorStyles.stroke = stroke;\n }\n }\n if (updater.getTransformValues) {\n const updaterTransform = updater.getTransformValues(particle);\n for (const key in updaterTransform) {\n setTransformValue(transform, updaterTransform, key);\n }\n }\n updater.beforeDraw?.(particle);\n }\n };\n this._applyResizePlugins = () => {\n for (const plugin of this._resizePlugins) {\n plugin.resize?.();\n }\n };\n this._getPluginParticleColors = particle => {\n let fColor, sColor;\n for (const plugin of this._colorPlugins) {\n if (!fColor && plugin.particleFillColor) {\n fColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(plugin.particleFillColor(particle));\n }\n if (!sColor && plugin.particleStrokeColor) {\n sColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(plugin.particleStrokeColor(particle));\n }\n if (fColor && sColor) {\n break;\n }\n }\n return [fColor, sColor];\n };\n this._initCover = async () => {\n const options = this.container.actualOptions,\n cover = options.backgroundMask.cover,\n color = cover.color;\n if (color) {\n const coverRgb = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(color);\n if (coverRgb) {\n const coverColor = {\n ...coverRgb,\n a: cover.opacity\n };\n this._coverColorStyle = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(coverColor, coverColor.a);\n }\n } else {\n await new Promise((resolve, reject) => {\n if (!cover.image) {\n return;\n }\n const img = document.createElement(\"img\");\n img.addEventListener(\"load\", () => {\n this._coverImage = {\n image: img,\n opacity: cover.opacity\n };\n resolve();\n });\n img.addEventListener(\"error\", evt => {\n reject(evt.error);\n });\n img.src = cover.image;\n });\n }\n };\n this._initStyle = () => {\n const element = this.element,\n options = this.container.actualOptions;\n if (!element) {\n return;\n }\n if (this._fullScreen) {\n this._originalStyle = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.deepExtend)({}, element.style);\n this._setFullScreenStyle();\n } else {\n this._resetOriginalStyle();\n }\n for (const key in options.style) {\n if (!key || !options.style) {\n continue;\n }\n const value = options.style[key];\n if (!value) {\n continue;\n }\n element.style.setProperty(key, value, \"important\");\n }\n };\n this._initTrail = async () => {\n const options = this.container.actualOptions,\n trail = options.particles.move.trail,\n trailFill = trail.fill;\n if (!trail.enable) {\n return;\n }\n const factorNumerator = 1,\n opacity = factorNumerator / trail.length;\n if (trailFill.color) {\n const fillColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(trailFill.color);\n if (!fillColor) {\n return;\n }\n this._trailFill = {\n color: {\n ...fillColor\n },\n opacity\n };\n } else {\n await new Promise((resolve, reject) => {\n if (!trailFill.image) {\n return;\n }\n const img = document.createElement(\"img\");\n img.addEventListener(\"load\", () => {\n this._trailFill = {\n image: img,\n opacity\n };\n resolve();\n });\n img.addEventListener(\"error\", evt => {\n reject(evt.error);\n });\n img.src = trailFill.image;\n });\n }\n };\n this._paintBase = baseColor => {\n this.draw(ctx => (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.paintBase)(ctx, this.size, baseColor));\n };\n this._paintImage = (image, opacity) => {\n this.draw(ctx => (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.paintImage)(ctx, this.size, image, opacity));\n };\n this._repairStyle = () => {\n const element = this.element;\n if (!element) {\n return;\n }\n this._safeMutationObserver(observer => observer.disconnect());\n this._initStyle();\n this.initBackground();\n this._safeMutationObserver(observer => observer.observe(element, {\n attributes: true\n }));\n };\n this._resetOriginalStyle = () => {\n const element = this.element,\n originalStyle = this._originalStyle;\n if (!(element && originalStyle)) {\n return;\n }\n setStyle(element, originalStyle);\n };\n this._safeMutationObserver = callback => {\n if (!this._mutationObserver) {\n return;\n }\n callback(this._mutationObserver);\n };\n this._setFullScreenStyle = () => {\n const element = this.element;\n if (!element) {\n return;\n }\n const radix = 10;\n setStyle(element, {\n position: \"fixed\",\n zIndex: this.container.actualOptions.fullScreen.zIndex.toString(radix),\n top: \"0\",\n left: \"0\",\n width: \"100%\",\n height: \"100%\"\n }, true);\n };\n this.size = {\n height: 0,\n width: 0\n };\n this._context = null;\n this._generated = false;\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n this._resizePlugins = [];\n this._colorPlugins = [];\n }\n get _fullScreen() {\n return this.container.actualOptions.fullScreen.enable;\n }\n clear() {\n const options = this.container.actualOptions,\n trail = options.particles.move.trail,\n trailFill = this._trailFill,\n minimumLength = 0;\n if (options.backgroundMask.enable) {\n this.paint();\n } else if (trail.enable && trail.length > minimumLength && trailFill) {\n if (trailFill.color) {\n this._paintBase((0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(trailFill.color, trailFill.opacity));\n } else if (trailFill.image) {\n this._paintImage(trailFill.image, trailFill.opacity);\n }\n } else if (options.clear) {\n this.draw(ctx => {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.clear)(ctx, this.size);\n });\n }\n }\n destroy() {\n this.stop();\n if (this._generated) {\n const element = this.element;\n element?.remove();\n } else {\n this._resetOriginalStyle();\n }\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n this._resizePlugins = [];\n this._colorPlugins = [];\n }\n draw(cb) {\n const ctx = this._context;\n if (!ctx) {\n return;\n }\n return cb(ctx);\n }\n drawAsync(cb) {\n const ctx = this._context;\n if (!ctx) {\n return Promise.resolve(undefined);\n }\n return cb(ctx);\n }\n async drawParticle(particle, delta) {\n if (particle.spawning || particle.destroyed) {\n return;\n }\n const radius = particle.getRadius(),\n minimumSize = 0;\n if (radius <= minimumSize) {\n return;\n }\n const pfColor = particle.getFillColor(),\n psColor = particle.getStrokeColor() ?? pfColor;\n let [fColor, sColor] = this._getPluginParticleColors(particle);\n if (!fColor) {\n fColor = pfColor;\n }\n if (!sColor) {\n sColor = psColor;\n }\n if (!fColor && !sColor) {\n return;\n }\n await this.drawAsync(async ctx => {\n const container = this.container,\n options = container.actualOptions,\n zIndexOptions = particle.options.zIndex,\n zIndexFactorOffset = 1,\n zIndexFactor = zIndexFactorOffset - particle.zIndexFactor,\n zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate,\n defaultOpacity = 1,\n opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity,\n strokeOpacity = particle.strokeOpacity ?? opacity,\n zOpacity = opacity * zOpacityFactor,\n zStrokeOpacity = strokeOpacity * zOpacityFactor,\n transform = {},\n colorStyles = {\n fill: fColor ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.getStyleFromHsl)(fColor, zOpacity) : undefined\n };\n colorStyles.stroke = sColor ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.getStyleFromHsl)(sColor, zStrokeOpacity) : colorStyles.fill;\n this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);\n await (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.drawParticle)({\n container,\n context: ctx,\n particle,\n delta,\n colorStyles,\n backgroundMask: options.backgroundMask.enable,\n composite: options.backgroundMask.composite,\n radius: radius * zIndexFactor ** zIndexOptions.sizeRate,\n opacity: zOpacity,\n shadow: particle.options.shadow,\n transform\n });\n this._applyPostDrawUpdaters(particle);\n });\n }\n async drawParticlePlugin(plugin, particle, delta) {\n await this.drawAsync(ctx => (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.drawParticlePlugin)(ctx, plugin, particle, delta));\n }\n async drawPlugin(plugin, delta) {\n await this.drawAsync(ctx => (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.drawPlugin)(ctx, plugin, delta));\n }\n async init() {\n this._safeMutationObserver(obs => obs.disconnect());\n this._mutationObserver = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.safeMutationObserver)(records => {\n for (const record of records) {\n if (record.type === \"attributes\" && record.attributeName === \"style\") {\n this._repairStyle();\n }\n }\n });\n this.resize();\n this._initStyle();\n await this._initCover();\n try {\n await this._initTrail();\n } catch (e) {\n (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.getLogger)().error(e);\n }\n this.initBackground();\n this._safeMutationObserver(obs => {\n if (!this.element) {\n return;\n }\n obs.observe(this.element, {\n attributes: true\n });\n });\n this.initUpdaters();\n this.initPlugins();\n this.paint();\n }\n initBackground() {\n const options = this.container.actualOptions,\n background = options.background,\n element = this.element;\n if (!element) {\n return;\n }\n const elementStyle = element.style;\n if (!elementStyle) {\n return;\n }\n if (background.color) {\n const color = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(background.color);\n elementStyle.backgroundColor = color ? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(color, background.opacity) : \"\";\n } else {\n elementStyle.backgroundColor = \"\";\n }\n elementStyle.backgroundImage = background.image || \"\";\n elementStyle.backgroundPosition = background.position || \"\";\n elementStyle.backgroundRepeat = background.repeat || \"\";\n elementStyle.backgroundSize = background.size || \"\";\n }\n initPlugins() {\n this._resizePlugins = [];\n for (const [, plugin] of this.container.plugins) {\n if (plugin.resize) {\n this._resizePlugins.push(plugin);\n }\n if (plugin.particleFillColor ?? plugin.particleStrokeColor) {\n this._colorPlugins.push(plugin);\n }\n }\n }\n initUpdaters() {\n this._preDrawUpdaters = [];\n this._postDrawUpdaters = [];\n for (const updater of this.container.particles.updaters) {\n if (updater.afterDraw) {\n this._postDrawUpdaters.push(updater);\n }\n if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {\n this._preDrawUpdaters.push(updater);\n }\n }\n }\n loadCanvas(canvas) {\n if (this._generated && this.element) {\n this.element.remove();\n }\n this._generated = canvas.dataset && _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_3__.generatedAttribute in canvas.dataset ? canvas.dataset[_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_3__.generatedAttribute] === \"true\" : this._generated;\n this.element = canvas;\n this.element.ariaHidden = \"true\";\n this._originalStyle = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.deepExtend)({}, this.element.style);\n this.size.height = canvas.offsetHeight;\n this.size.width = canvas.offsetWidth;\n this._context = this.element.getContext(\"2d\");\n this._safeMutationObserver(obs => {\n if (!this.element) {\n return;\n }\n obs.observe(this.element, {\n attributes: true\n });\n });\n this.container.retina.init();\n this.initBackground();\n }\n paint() {\n const options = this.container.actualOptions;\n this.draw(ctx => {\n if (options.backgroundMask.enable && options.backgroundMask.cover) {\n (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.clear)(ctx, this.size);\n if (this._coverImage) {\n this._paintImage(this._coverImage.image, this._coverImage.opacity);\n } else if (this._coverColorStyle) {\n this._paintBase(this._coverColorStyle);\n } else {\n this._paintBase();\n }\n } else {\n this._paintBase();\n }\n });\n }\n resize() {\n if (!this.element) {\n return false;\n }\n const container = this.container,\n pxRatio = container.retina.pixelRatio,\n size = container.canvas.size,\n newSize = {\n width: this.element.offsetWidth * pxRatio,\n height: this.element.offsetHeight * pxRatio\n };\n if (newSize.height === size.height && newSize.width === size.width && newSize.height === this.element.height && newSize.width === this.element.width) {\n return false;\n }\n const oldSize = {\n ...size\n };\n this.element.width = size.width = this.element.offsetWidth * pxRatio;\n this.element.height = size.height = this.element.offsetHeight * pxRatio;\n if (this.container.started) {\n container.particles.setResizeFactor({\n width: size.width / oldSize.width,\n height: size.height / oldSize.height\n });\n }\n return true;\n }\n stop() {\n this._safeMutationObserver(obs => obs.disconnect());\n this._mutationObserver = undefined;\n this.draw(ctx => (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_2__.clear)(ctx, this.size));\n }\n async windowResize() {\n if (!this.element || !this.resize()) {\n return;\n }\n const container = this.container,\n needsRefresh = container.updateActualOptions();\n await container.particles.setDensity();\n this._applyResizePlugins();\n if (needsRefresh) {\n await container.refresh();\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Canvas.js?");
|
|
29
|
+
|
|
30
|
+
/***/ }),
|
|
31
|
+
|
|
32
|
+
/***/ "./dist/browser/Core/Container.js":
|
|
33
|
+
/*!****************************************!*\
|
|
34
|
+
!*** ./dist/browser/Core/Container.js ***!
|
|
35
|
+
\****************************************/
|
|
36
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
37
|
+
|
|
38
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Container: () => (/* binding */ Container)\n/* harmony export */ });\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Canvas_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./Canvas.js */ \"./dist/browser/Core/Canvas.js\");\n/* harmony import */ var _Utils_EventListeners_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Utils/EventListeners.js */ \"./dist/browser/Core/Utils/EventListeners.js\");\n/* harmony import */ var _Options_Classes_Options_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Options/Classes/Options.js */ \"./dist/browser/Options/Classes/Options.js\");\n/* harmony import */ var _Particles_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Particles.js */ \"./dist/browser/Core/Particles.js\");\n/* harmony import */ var _Retina_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Retina.js */ \"./dist/browser/Core/Retina.js\");\n/* harmony import */ var _Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Utils/NumberUtils.js */ \"./dist/browser/Utils/NumberUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n\n\n\n\n\n\n\n\n\nfunction guardCheck(container) {\n return container && !container.destroyed;\n}\nconst defaultFps = 60;\nfunction initDelta(value, fpsLimit = defaultFps, smooth = false) {\n return {\n value,\n factor: smooth ? defaultFps / fpsLimit : defaultFps * value / _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds\n };\n}\nfunction loadContainerOptions(engine, container, ...sourceOptionsArr) {\n const options = new _Options_Classes_Options_js__WEBPACK_IMPORTED_MODULE_1__.Options(engine, container);\n (0,_Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_2__.loadOptions)(options, ...sourceOptionsArr);\n return options;\n}\nclass Container {\n constructor(engine, id, sourceOptions) {\n this._intersectionManager = entries => {\n if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {\n return;\n }\n for (const entry of entries) {\n if (entry.target !== this.interactivity.element) {\n continue;\n }\n if (entry.isIntersecting) {\n this.play();\n } else {\n this.pause();\n }\n }\n };\n this._nextFrame = async timestamp => {\n try {\n if (!this._smooth && this._lastFrameTime !== undefined && timestamp < this._lastFrameTime + _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / this.fpsLimit) {\n this.draw(false);\n return;\n }\n this._lastFrameTime ??= timestamp;\n const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);\n this.addLifeTime(delta.value);\n this._lastFrameTime = timestamp;\n if (delta.value > _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds) {\n this.draw(false);\n return;\n }\n await this.particles.draw(delta);\n if (!this.alive()) {\n this.destroy();\n return;\n }\n if (this.animationStatus) {\n this.draw(false);\n }\n } catch (e) {\n (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.getLogger)().error(`${_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.errorPrefix} in animation loop`, e);\n }\n };\n this._engine = engine;\n this.id = Symbol(id);\n this.fpsLimit = 120;\n this._smooth = false;\n this._delay = 0;\n this._duration = 0;\n this._lifeTime = 0;\n this._firstStart = true;\n this.started = false;\n this.destroyed = false;\n this._paused = true;\n this._lastFrameTime = 0;\n this.zLayers = 100;\n this.pageHidden = false;\n this._sourceOptions = sourceOptions;\n this._initialSourceOptions = sourceOptions;\n this.retina = new _Retina_js__WEBPACK_IMPORTED_MODULE_4__.Retina(this);\n this.canvas = new _Canvas_js__WEBPACK_IMPORTED_MODULE_5__.Canvas(this);\n this.particles = new _Particles_js__WEBPACK_IMPORTED_MODULE_6__.Particles(this._engine, this);\n this.pathGenerators = new Map();\n this.interactivity = {\n mouse: {\n clicking: false,\n inside: false\n }\n };\n this.plugins = new Map();\n this.effectDrawers = new Map();\n this.shapeDrawers = new Map();\n this._options = loadContainerOptions(this._engine, this);\n this.actualOptions = loadContainerOptions(this._engine, this);\n this._eventListeners = new _Utils_EventListeners_js__WEBPACK_IMPORTED_MODULE_7__.EventListeners(this);\n this._intersectionObserver = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.safeIntersectionObserver)(entries => this._intersectionManager(entries));\n this._engine.dispatchEvent(\"containerBuilt\", {\n container: this\n });\n }\n get animationStatus() {\n return !this._paused && !this.pageHidden && guardCheck(this);\n }\n get options() {\n return this._options;\n }\n get sourceOptions() {\n return this._sourceOptions;\n }\n addClickHandler(callback) {\n if (!guardCheck(this)) {\n return;\n }\n const el = this.interactivity.element;\n if (!el) {\n return;\n }\n const clickOrTouchHandler = (e, pos, radius) => {\n if (!guardCheck(this)) {\n return;\n }\n const pxRatio = this.retina.pixelRatio,\n posRetina = {\n x: pos.x * pxRatio,\n y: pos.y * pxRatio\n },\n particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);\n callback(e, particles);\n };\n const clickHandler = e => {\n if (!guardCheck(this)) {\n return;\n }\n const mouseEvent = e,\n pos = {\n x: mouseEvent.offsetX || mouseEvent.clientX,\n y: mouseEvent.offsetY || mouseEvent.clientY\n },\n radius = 1;\n clickOrTouchHandler(e, pos, radius);\n };\n const touchStartHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touched = true;\n touchMoved = false;\n };\n const touchMoveHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touchMoved = true;\n };\n const touchEndHandler = e => {\n if (!guardCheck(this)) {\n return;\n }\n if (touched && !touchMoved) {\n const touchEvent = e;\n const lengthOffset = 1;\n let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];\n if (!lastTouch) {\n lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];\n if (!lastTouch) {\n return;\n }\n }\n const element = this.canvas.element,\n canvasRect = element ? element.getBoundingClientRect() : undefined,\n minCoordinate = 0,\n pos = {\n x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),\n y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate)\n };\n clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));\n }\n touched = false;\n touchMoved = false;\n };\n const touchCancelHandler = () => {\n if (!guardCheck(this)) {\n return;\n }\n touched = false;\n touchMoved = false;\n };\n let touched = false,\n touchMoved = false;\n el.addEventListener(\"click\", clickHandler);\n el.addEventListener(\"touchstart\", touchStartHandler);\n el.addEventListener(\"touchmove\", touchMoveHandler);\n el.addEventListener(\"touchend\", touchEndHandler);\n el.addEventListener(\"touchcancel\", touchCancelHandler);\n }\n addLifeTime(value) {\n this._lifeTime += value;\n }\n addPath(key, generator, override = false) {\n if (!guardCheck(this) || !override && this.pathGenerators.has(key)) {\n return false;\n }\n this.pathGenerators.set(key, generator);\n return true;\n }\n alive() {\n return !this._duration || this._lifeTime <= this._duration;\n }\n destroy() {\n if (!guardCheck(this)) {\n return;\n }\n this.stop();\n this.particles.destroy();\n this.canvas.destroy();\n for (const [, effectDrawer] of this.effectDrawers) {\n effectDrawer.destroy?.(this);\n }\n for (const [, shapeDrawer] of this.shapeDrawers) {\n shapeDrawer.destroy?.(this);\n }\n for (const key of this.effectDrawers.keys()) {\n this.effectDrawers.delete(key);\n }\n for (const key of this.shapeDrawers.keys()) {\n this.shapeDrawers.delete(key);\n }\n this._engine.clearPlugins(this);\n this.destroyed = true;\n const mainArr = this._engine.dom(),\n idx = mainArr.findIndex(t => t === this),\n minIndex = 0;\n if (idx >= minIndex) {\n const deleteCount = 1;\n mainArr.splice(idx, deleteCount);\n }\n this._engine.dispatchEvent(\"containerDestroyed\", {\n container: this\n });\n }\n draw(force) {\n if (!guardCheck(this)) {\n return;\n }\n let refreshTime = force;\n const frame = async timestamp => {\n if (refreshTime) {\n this._lastFrameTime = undefined;\n refreshTime = false;\n }\n await this._nextFrame(timestamp);\n };\n this._drawAnimationFrame = requestAnimationFrame(timestamp => void frame(timestamp));\n }\n async export(type, options = {}) {\n for (const [, plugin] of this.plugins) {\n if (!plugin.export) {\n continue;\n }\n const res = await plugin.export(type, options);\n if (!res.supported) {\n continue;\n }\n return res.blob;\n }\n (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_3__.getLogger)().error(`${_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.errorPrefix} - Export plugin with type ${type} not found`);\n }\n handleClickMode(mode) {\n if (!guardCheck(this)) {\n return;\n }\n this.particles.handleClickMode(mode);\n for (const [, plugin] of this.plugins) {\n plugin.handleClickMode?.(mode);\n }\n }\n async init() {\n if (!guardCheck(this)) {\n return;\n }\n const effects = this._engine.getSupportedEffects();\n for (const type of effects) {\n const drawer = this._engine.getEffectDrawer(type);\n if (drawer) {\n this.effectDrawers.set(type, drawer);\n }\n }\n const shapes = this._engine.getSupportedShapes();\n for (const type of shapes) {\n const drawer = this._engine.getShapeDrawer(type);\n if (drawer) {\n this.shapeDrawers.set(type, drawer);\n }\n }\n await this.particles.initPlugins();\n this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);\n this.actualOptions = loadContainerOptions(this._engine, this, this._options);\n const availablePlugins = await this._engine.getAvailablePlugins(this);\n for (const [id, plugin] of availablePlugins) {\n this.plugins.set(id, plugin);\n }\n this.retina.init();\n await this.canvas.init();\n this.updateActualOptions();\n this.canvas.initBackground();\n this.canvas.resize();\n this.zLayers = this.actualOptions.zLayers;\n this._duration = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_8__.getRangeValue)(this.actualOptions.duration) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n this._delay = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_8__.getRangeValue)(this.actualOptions.delay) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n this._lifeTime = 0;\n const defaultFpsLimit = 120,\n minFpsLimit = 0;\n this.fpsLimit = this.actualOptions.fpsLimit > minFpsLimit ? this.actualOptions.fpsLimit : defaultFpsLimit;\n this._smooth = this.actualOptions.smooth;\n for (const [, drawer] of this.effectDrawers) {\n await drawer.init?.(this);\n }\n for (const [, drawer] of this.shapeDrawers) {\n await drawer.init?.(this);\n }\n for (const [, plugin] of this.plugins) {\n await plugin.init?.();\n }\n this._engine.dispatchEvent(\"containerInit\", {\n container: this\n });\n await this.particles.init();\n await this.particles.setDensity();\n for (const [, plugin] of this.plugins) {\n plugin.particlesSetup?.();\n }\n this._engine.dispatchEvent(\"particlesSetup\", {\n container: this\n });\n }\n async loadTheme(name) {\n if (!guardCheck(this)) {\n return;\n }\n this._currentTheme = name;\n await this.refresh();\n }\n pause() {\n if (!guardCheck(this)) {\n return;\n }\n if (this._drawAnimationFrame !== undefined) {\n cancelAnimationFrame(this._drawAnimationFrame);\n delete this._drawAnimationFrame;\n }\n if (this._paused) {\n return;\n }\n for (const [, plugin] of this.plugins) {\n plugin.pause?.();\n }\n if (!this.pageHidden) {\n this._paused = true;\n }\n this._engine.dispatchEvent(\"containerPaused\", {\n container: this\n });\n }\n play(force) {\n if (!guardCheck(this)) {\n return;\n }\n const needsUpdate = this._paused || force;\n if (this._firstStart && !this.actualOptions.autoPlay) {\n this._firstStart = false;\n return;\n }\n if (this._paused) {\n this._paused = false;\n }\n if (needsUpdate) {\n for (const [, plugin] of this.plugins) {\n if (plugin.play) {\n plugin.play();\n }\n }\n }\n this._engine.dispatchEvent(\"containerPlay\", {\n container: this\n });\n this.draw(needsUpdate ?? false);\n }\n async refresh() {\n if (!guardCheck(this)) {\n return;\n }\n this.stop();\n return this.start();\n }\n async reset() {\n if (!guardCheck(this)) {\n return;\n }\n this._initialSourceOptions = undefined;\n this._options = loadContainerOptions(this._engine, this);\n this.actualOptions = loadContainerOptions(this._engine, this, this._options);\n return this.refresh();\n }\n async start() {\n if (!guardCheck(this) || this.started) {\n return;\n }\n await this.init();\n this.started = true;\n await new Promise(resolve => {\n const start = async () => {\n this._eventListeners.addListeners();\n if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {\n this._intersectionObserver.observe(this.interactivity.element);\n }\n for (const [, plugin] of this.plugins) {\n await plugin.start?.();\n }\n this._engine.dispatchEvent(\"containerStarted\", {\n container: this\n });\n this.play();\n resolve();\n };\n this._delayTimeout = setTimeout(() => void start(), this._delay);\n });\n }\n stop() {\n if (!guardCheck(this) || !this.started) {\n return;\n }\n if (this._delayTimeout) {\n clearTimeout(this._delayTimeout);\n delete this._delayTimeout;\n }\n this._firstStart = true;\n this.started = false;\n this._eventListeners.removeListeners();\n this.pause();\n this.particles.clear();\n this.canvas.stop();\n if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {\n this._intersectionObserver.unobserve(this.interactivity.element);\n }\n for (const [, plugin] of this.plugins) {\n plugin.stop?.();\n }\n for (const key of this.plugins.keys()) {\n this.plugins.delete(key);\n }\n this._sourceOptions = this._options;\n this._engine.dispatchEvent(\"containerStopped\", {\n container: this\n });\n }\n updateActualOptions() {\n this.actualOptions.responsive = [];\n const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);\n this.actualOptions.setTheme(this._currentTheme);\n if (this._responsiveMaxWidth === newMaxWidth) {\n return false;\n }\n this._responsiveMaxWidth = newMaxWidth;\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Container.js?");
|
|
39
|
+
|
|
40
|
+
/***/ }),
|
|
41
|
+
|
|
42
|
+
/***/ "./dist/browser/Core/Particles.js":
|
|
43
|
+
/*!****************************************!*\
|
|
44
|
+
!*** ./dist/browser/Core/Particles.js ***!
|
|
45
|
+
\****************************************/
|
|
46
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
47
|
+
|
|
48
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Particles: () => (/* binding */ Particles)\n/* harmony export */ });\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Utils_InteractionManager_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Utils/InteractionManager.js */ \"./dist/browser/Core/Utils/InteractionManager.js\");\n/* harmony import */ var _Utils_Point_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./Utils/Point.js */ \"./dist/browser/Core/Utils/Point.js\");\n/* harmony import */ var _Utils_QuadTree_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Utils/QuadTree.js */ \"./dist/browser/Core/Utils/QuadTree.js\");\n/* harmony import */ var _Utils_Rectangle_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils/Rectangle.js */ \"./dist/browser/Core/Utils/Rectangle.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n\n\n\n\n\n\nconst qTreeCapacity = 4,\n squareExp = 2,\n defaultRemoveQuantity = 1;\nconst qTreeRectangle = canvasSize => {\n const {\n height,\n width\n } = canvasSize,\n posOffset = -0.25,\n sizeFactor = 1.5;\n return new _Utils_Rectangle_js__WEBPACK_IMPORTED_MODULE_0__.Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);\n};\nclass Particles {\n constructor(engine, container) {\n this._addToPool = (...particles) => {\n for (const particle of particles) {\n this._pool.push(particle);\n }\n };\n this._applyDensity = async (options, manualCount, group) => {\n const numberOptions = options.number;\n if (!options.number.density?.enable) {\n if (group === undefined) {\n this._limit = numberOptions.limit.value;\n } else if (numberOptions.limit) {\n this._groupLimits.set(group, numberOptions.limit.value);\n }\n return;\n }\n const densityFactor = this._initDensityFactor(numberOptions.density),\n optParticlesNumber = numberOptions.value,\n minLimit = 0,\n optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber,\n particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount,\n particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);\n if (group === undefined) {\n this._limit = numberOptions.limit.value * densityFactor;\n } else {\n this._groupLimits.set(group, numberOptions.limit.value * densityFactor);\n }\n if (particlesCount < particlesNumber) {\n await this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);\n } else if (particlesCount > particlesNumber) {\n this.removeQuantity(particlesCount - particlesNumber, group);\n }\n };\n this._initDensityFactor = densityOptions => {\n const container = this._container,\n defaultFactor = 1;\n if (!container.canvas.element || !densityOptions.enable) {\n return defaultFactor;\n }\n const canvas = container.canvas.element,\n pxRatio = container.retina.pixelRatio;\n return canvas.width * canvas.height / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);\n };\n this._pushParticle = async (position, overrideOptions, group, initializer) => {\n try {\n let particle = this._pool.pop();\n if (!particle) {\n const {\n Particle\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_Core_Particle_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./Particle.js */ \"./dist/browser/Core/Particle.js\"));\n particle = new Particle(this._engine, this._container);\n }\n await particle.init(this._nextId, position, overrideOptions, group);\n let canAdd = true;\n if (initializer) {\n canAdd = initializer(particle);\n }\n if (!canAdd) {\n return;\n }\n this._array.push(particle);\n this._zArray.push(particle);\n this._nextId++;\n this._engine.dispatchEvent(\"particleAdded\", {\n container: this._container,\n data: {\n particle\n }\n });\n return particle;\n } catch (e) {\n (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.getLogger)().warning(`${_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_2__.errorPrefix} adding particle: ${e}`);\n }\n };\n this._removeParticle = (index, group, override) => {\n const particle = this._array[index];\n if (!particle || particle.group !== group) {\n return false;\n }\n const zIdx = this._zArray.indexOf(particle),\n deleteCount = 1;\n this._array.splice(index, deleteCount);\n this._zArray.splice(zIdx, deleteCount);\n particle.destroy(override);\n this._engine.dispatchEvent(\"particleRemoved\", {\n container: this._container,\n data: {\n particle\n }\n });\n this._addToPool(particle);\n return true;\n };\n this._engine = engine;\n this._container = container;\n this._nextId = 0;\n this._array = [];\n this._zArray = [];\n this._pool = [];\n this._limit = 0;\n this._groupLimits = new Map();\n this._needsSort = false;\n this._lastZIndex = 0;\n this._interactionManager = new _Utils_InteractionManager_js__WEBPACK_IMPORTED_MODULE_3__.InteractionManager(engine, container);\n this._pluginsInitialized = false;\n const canvasSize = container.canvas.size;\n this.quadTree = new _Utils_QuadTree_js__WEBPACK_IMPORTED_MODULE_4__.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);\n this.movers = [];\n this.updaters = [];\n }\n get count() {\n return this._array.length;\n }\n async addManualParticles() {\n const container = this._container,\n options = container.actualOptions;\n for (const particle of options.manualParticles) {\n await this.addParticle(particle.position ? (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_1__.getPosition)(particle.position, container.canvas.size) : undefined, particle.options);\n }\n }\n async addParticle(position, overrideOptions, group, initializer) {\n const limitOptions = this._container.actualOptions.particles.number.limit,\n limit = group === undefined ? this._limit : this._groupLimits.get(group) ?? this._limit,\n currentCount = this.count,\n minLimit = 0;\n if (limit > minLimit) {\n if (limitOptions.mode === \"delete\") {\n const countOffset = 1,\n minCount = 0,\n countToRemove = currentCount + countOffset - limit;\n if (countToRemove > minCount) {\n this.removeQuantity(countToRemove);\n }\n } else if (limitOptions.mode === \"wait\") {\n if (currentCount >= limit) {\n return;\n }\n }\n }\n return await this._pushParticle(position, overrideOptions, group, initializer);\n }\n clear() {\n this._array = [];\n this._zArray = [];\n this._pluginsInitialized = false;\n }\n destroy() {\n this._array = [];\n this._zArray = [];\n this.movers = [];\n this.updaters = [];\n }\n async draw(delta) {\n const container = this._container,\n canvas = container.canvas;\n canvas.clear();\n await this.update(delta);\n for (const [, plugin] of container.plugins) {\n await canvas.drawPlugin(plugin, delta);\n }\n for (const p of this._zArray) {\n await p.draw(delta);\n }\n }\n filter(condition) {\n return this._array.filter(condition);\n }\n find(condition) {\n return this._array.find(condition);\n }\n get(index) {\n return this._array[index];\n }\n handleClickMode(mode) {\n this._interactionManager.handleClickMode(mode);\n }\n async init() {\n const container = this._container,\n options = container.actualOptions;\n this._lastZIndex = 0;\n this._needsSort = false;\n await this.initPlugins();\n let handled = false;\n for (const [, plugin] of container.plugins) {\n if (plugin.particlesInitialization !== undefined) {\n handled = plugin.particlesInitialization();\n }\n if (handled) {\n break;\n }\n }\n await this.addManualParticles();\n if (!handled) {\n const particlesOptions = options.particles,\n groups = particlesOptions.groups;\n for (const group in groups) {\n const groupOptions = groups[group];\n for (let i = this.count, j = 0; j < groupOptions.number?.value && i < particlesOptions.number.value; i++, j++) {\n await this.addParticle(undefined, groupOptions, group);\n }\n }\n for (let i = this.count; i < particlesOptions.number.value; i++) {\n await this.addParticle();\n }\n }\n }\n async initPlugins() {\n if (this._pluginsInitialized) {\n return;\n }\n const container = this._container;\n this.movers = await this._engine.getMovers(container, true);\n this.updaters = await this._engine.getUpdaters(container, true);\n await this._interactionManager.init();\n for (const [, pathGenerator] of container.pathGenerators) {\n await pathGenerator.init(container);\n }\n }\n async push(nb, mouse, overrideOptions, group) {\n for (let i = 0; i < nb; i++) {\n await this.addParticle(mouse?.position, overrideOptions, group);\n }\n }\n async redraw() {\n this.clear();\n await this.init();\n await this.draw({\n value: 0,\n factor: 0\n });\n }\n remove(particle, group, override) {\n this.removeAt(this._array.indexOf(particle), undefined, group, override);\n }\n removeAt(index, quantity = defaultRemoveQuantity, group, override) {\n const minIndex = 0;\n if (index < minIndex || index > this.count) {\n return;\n }\n let deleted = 0;\n for (let i = index; deleted < quantity && i < this.count; i++) {\n if (this._removeParticle(i--, group, override)) {\n deleted++;\n }\n }\n }\n removeQuantity(quantity, group) {\n const defaultIndex = 0;\n this.removeAt(defaultIndex, quantity, group);\n }\n async setDensity() {\n const options = this._container.actualOptions,\n groups = options.particles.groups,\n manualCount = 0;\n for (const group in groups) {\n await this._applyDensity(groups[group], manualCount, group);\n }\n await this._applyDensity(options.particles, options.manualParticles.length);\n }\n setLastZIndex(zIndex) {\n this._lastZIndex = zIndex;\n this._needsSort = this._needsSort || this._lastZIndex < zIndex;\n }\n setResizeFactor(factor) {\n this._resizeFactor = factor;\n }\n async update(delta) {\n const container = this._container,\n particlesToDelete = new Set();\n this.quadTree = new _Utils_QuadTree_js__WEBPACK_IMPORTED_MODULE_4__.QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);\n for (const [, pathGenerator] of container.pathGenerators) {\n pathGenerator.update();\n }\n for (const [, plugin] of container.plugins) {\n await plugin.update?.(delta);\n }\n const resizeFactor = this._resizeFactor;\n for (const particle of this._array) {\n if (resizeFactor && !particle.ignoresResizeRatio) {\n particle.position.x *= resizeFactor.width;\n particle.position.y *= resizeFactor.height;\n particle.initialPosition.x *= resizeFactor.width;\n particle.initialPosition.y *= resizeFactor.height;\n }\n particle.ignoresResizeRatio = false;\n this._interactionManager.reset(particle);\n for (const [, plugin] of this._container.plugins) {\n if (particle.destroyed) {\n break;\n }\n plugin.particleUpdate?.(particle, delta);\n }\n for (const mover of this.movers) {\n if (mover.isEnabled(particle)) {\n await mover.move(particle, delta);\n }\n }\n if (particle.destroyed) {\n particlesToDelete.add(particle);\n continue;\n }\n this.quadTree.insert(new _Utils_Point_js__WEBPACK_IMPORTED_MODULE_5__.Point(particle.getPosition(), particle));\n }\n if (particlesToDelete.size) {\n const checkDelete = p => !particlesToDelete.has(p);\n this._array = this.filter(checkDelete);\n this._zArray = this._zArray.filter(checkDelete);\n for (const particle of particlesToDelete) {\n this._engine.dispatchEvent(\"particleRemoved\", {\n container: this._container,\n data: {\n particle\n }\n });\n }\n this._addToPool(...particlesToDelete);\n }\n await this._interactionManager.externalInteract(delta);\n for (const particle of this._array) {\n for (const updater of this.updaters) {\n await updater.update(particle, delta);\n }\n if (!particle.destroyed && !particle.spawning) {\n await this._interactionManager.particlesInteract(particle, delta);\n }\n }\n delete this._resizeFactor;\n if (this._needsSort) {\n const zArray = this._zArray;\n zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);\n const lengthOffset = 1;\n this._lastZIndex = zArray[zArray.length - lengthOffset].position.z;\n this._needsSort = false;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Particles.js?");
|
|
49
|
+
|
|
50
|
+
/***/ }),
|
|
51
|
+
|
|
52
|
+
/***/ "./dist/browser/Core/Retina.js":
|
|
53
|
+
/*!*************************************!*\
|
|
54
|
+
!*** ./dist/browser/Core/Retina.js ***!
|
|
55
|
+
\*************************************/
|
|
56
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
57
|
+
|
|
58
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Retina: () => (/* binding */ Retina)\n/* harmony export */ });\n/* harmony import */ var _Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Utils/NumberUtils.js */ \"./dist/browser/Utils/NumberUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n\n\nconst defaultRatio = 1,\n defaultReduceFactor = 1;\nclass Retina {\n constructor(container) {\n this.container = container;\n this.pixelRatio = defaultRatio;\n this.reduceFactor = defaultReduceFactor;\n }\n init() {\n const container = this.container,\n options = container.actualOptions;\n this.pixelRatio = !options.detectRetina || (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.isSsr)() ? defaultRatio : window.devicePixelRatio;\n this.reduceFactor = defaultReduceFactor;\n const ratio = this.pixelRatio,\n canvas = container.canvas;\n if (canvas.element) {\n const element = canvas.element;\n canvas.size.width = element.offsetWidth * ratio;\n canvas.size.height = element.offsetHeight * ratio;\n }\n const particles = options.particles,\n moveOptions = particles.move;\n this.maxSpeed = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;\n this.sizeAnimationSpeed = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(particles.size.animation.speed) * ratio;\n }\n initParticle(particle) {\n const options = particle.options,\n ratio = this.pixelRatio,\n moveOptions = options.move,\n moveDistance = moveOptions.distance,\n props = particle.retina;\n props.moveDrift = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.drift) * ratio;\n props.moveSpeed = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.speed) * ratio;\n props.sizeAnimationSpeed = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(options.size.animation.speed) * ratio;\n const maxDistance = props.maxDistance;\n maxDistance.horizontal = moveDistance.horizontal !== undefined ? moveDistance.horizontal * ratio : undefined;\n maxDistance.vertical = moveDistance.vertical !== undefined ? moveDistance.vertical * ratio : undefined;\n props.maxSpeed = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getRangeValue)(moveOptions.gravity.maxSpeed) * ratio;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Retina.js?");
|
|
59
|
+
|
|
60
|
+
/***/ }),
|
|
61
|
+
|
|
62
|
+
/***/ "./dist/browser/Core/Utils/EventListeners.js":
|
|
63
|
+
/*!***************************************************!*\
|
|
64
|
+
!*** ./dist/browser/Core/Utils/EventListeners.js ***!
|
|
65
|
+
\***************************************************/
|
|
66
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
67
|
+
|
|
68
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EventListeners: () => (/* binding */ EventListeners)\n/* harmony export */ });\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n\n\nconst double = 2;\nfunction manageListener(element, event, handler, add, options) {\n if (add) {\n let addOptions = {\n passive: true\n };\n if ((0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.isBoolean)(options)) {\n addOptions.capture = options;\n } else if (options !== undefined) {\n addOptions = options;\n }\n element.addEventListener(event, handler, addOptions);\n } else {\n const removeOptions = options;\n element.removeEventListener(event, handler, removeOptions);\n }\n}\nclass EventListeners {\n constructor(container) {\n this.container = container;\n this._doMouseTouchClick = e => {\n const container = this.container,\n options = container.actualOptions;\n if (this._canPush) {\n const mouseInteractivity = container.interactivity.mouse,\n mousePos = mouseInteractivity.position;\n if (!mousePos) {\n return;\n }\n mouseInteractivity.clickPosition = {\n ...mousePos\n };\n mouseInteractivity.clickTime = new Date().getTime();\n const onClick = options.interactivity.events.onClick;\n (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(onClick.mode, mode => this.container.handleClickMode(mode));\n }\n if (e.type === \"touchend\") {\n const touchDelay = 500;\n setTimeout(() => this._mouseTouchFinish(), touchDelay);\n }\n };\n this._handleThemeChange = e => {\n const mediaEvent = e,\n container = this.container,\n options = container.options,\n defaultThemes = options.defaultThemes,\n themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light,\n theme = options.themes.find(theme => theme.name === themeName);\n if (theme && theme.default.auto) {\n void container.loadTheme(themeName);\n }\n };\n this._handleVisibilityChange = () => {\n const container = this.container,\n options = container.actualOptions;\n this._mouseTouchFinish();\n if (!options.pauseOnBlur) {\n return;\n }\n if (document && document.hidden) {\n container.pageHidden = true;\n container.pause();\n } else {\n container.pageHidden = false;\n if (container.animationStatus) {\n container.play(true);\n } else {\n container.draw(true);\n }\n }\n };\n this._handleWindowResize = () => {\n if (this._resizeTimeout) {\n clearTimeout(this._resizeTimeout);\n delete this._resizeTimeout;\n }\n const handleResize = async () => {\n const canvas = this.container.canvas;\n await canvas?.windowResize();\n };\n this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.interactivity.events.resize.delay * _Constants_js__WEBPACK_IMPORTED_MODULE_1__.millisecondsToSeconds);\n };\n this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {\n const handlers = this._handlers,\n container = this.container,\n options = container.actualOptions;\n const interactivityEl = container.interactivity.element;\n if (!interactivityEl) {\n return;\n }\n const html = interactivityEl,\n canvasEl = container.canvas.element;\n if (canvasEl) {\n canvasEl.style.pointerEvents = html === canvasEl ? \"initial\" : \"none\";\n }\n if (!(options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable)) {\n return;\n }\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseMoveEvent, handlers.mouseMove, add);\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchStartEvent, handlers.touchStart, add);\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchMoveEvent, handlers.touchMove, add);\n if (!options.interactivity.events.onClick.enable) {\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchEndEvent, handlers.touchEnd, add);\n } else {\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchEndEvent, handlers.touchEndClick, add);\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseUpEvent, handlers.mouseUp, add);\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseDownEvent, handlers.mouseDown, add);\n }\n manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);\n manageListener(interactivityEl, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.touchCancelEvent, handlers.touchCancel, add);\n };\n this._manageListeners = add => {\n const handlers = this._handlers,\n container = this.container,\n options = container.actualOptions,\n detectType = options.interactivity.detectsOn,\n canvasEl = container.canvas.element;\n let mouseLeaveTmpEvent = _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseLeaveEvent;\n if (detectType === \"window\") {\n container.interactivity.element = window;\n mouseLeaveTmpEvent = _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseOutEvent;\n } else if (detectType === \"parent\" && canvasEl) {\n container.interactivity.element = canvasEl.parentElement ?? canvasEl.parentNode;\n } else {\n container.interactivity.element = canvasEl;\n }\n this._manageMediaMatch(add);\n this._manageResize(add);\n this._manageInteractivityListeners(mouseLeaveTmpEvent, add);\n if (document) {\n manageListener(document, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.visibilityChangeEvent, handlers.visibilityChange, add, false);\n }\n };\n this._manageMediaMatch = add => {\n const handlers = this._handlers,\n mediaMatch = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.safeMatchMedia)(\"(prefers-color-scheme: dark)\");\n if (!mediaMatch) {\n return;\n }\n if (mediaMatch.addEventListener !== undefined) {\n manageListener(mediaMatch, \"change\", handlers.themeChange, add);\n return;\n }\n if (mediaMatch.addListener === undefined) {\n return;\n }\n if (add) {\n mediaMatch.addListener(handlers.oldThemeChange);\n } else {\n mediaMatch.removeListener(handlers.oldThemeChange);\n }\n };\n this._manageResize = add => {\n const handlers = this._handlers,\n container = this.container,\n options = container.actualOptions;\n if (!options.interactivity.events.resize) {\n return;\n }\n if (typeof ResizeObserver === \"undefined\") {\n manageListener(window, _Constants_js__WEBPACK_IMPORTED_MODULE_1__.resizeEvent, handlers.resize, add);\n return;\n }\n const canvasEl = container.canvas.element;\n if (this._resizeObserver && !add) {\n if (canvasEl) {\n this._resizeObserver.unobserve(canvasEl);\n }\n this._resizeObserver.disconnect();\n delete this._resizeObserver;\n } else if (!this._resizeObserver && add && canvasEl) {\n this._resizeObserver = new ResizeObserver(entries => {\n const entry = entries.find(e => e.target === canvasEl);\n if (!entry) {\n return;\n }\n this._handleWindowResize();\n });\n this._resizeObserver.observe(canvasEl);\n }\n };\n this._mouseDown = () => {\n const {\n interactivity\n } = this.container;\n if (!interactivity) {\n return;\n }\n const {\n mouse\n } = interactivity;\n mouse.clicking = true;\n mouse.downPosition = mouse.position;\n };\n this._mouseTouchClick = e => {\n const container = this.container,\n options = container.actualOptions,\n {\n mouse\n } = container.interactivity;\n mouse.inside = true;\n let handled = false;\n const mousePosition = mouse.position;\n if (!mousePosition || !options.interactivity.events.onClick.enable) {\n return;\n }\n for (const [, plugin] of container.plugins) {\n if (!plugin.clickPositionValid) {\n continue;\n }\n handled = plugin.clickPositionValid(mousePosition);\n if (handled) {\n break;\n }\n }\n if (!handled) {\n this._doMouseTouchClick(e);\n }\n mouse.clicking = false;\n };\n this._mouseTouchFinish = () => {\n const interactivity = this.container.interactivity;\n if (!interactivity) {\n return;\n }\n const mouse = interactivity.mouse;\n delete mouse.position;\n delete mouse.clickPosition;\n delete mouse.downPosition;\n interactivity.status = _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseLeaveEvent;\n mouse.inside = false;\n mouse.clicking = false;\n };\n this._mouseTouchMove = e => {\n const container = this.container,\n options = container.actualOptions,\n interactivity = container.interactivity,\n canvasEl = container.canvas.element;\n if (!interactivity?.element) {\n return;\n }\n interactivity.mouse.inside = true;\n let pos;\n if (e.type.startsWith(\"pointer\")) {\n this._canPush = true;\n const mouseEvent = e;\n if (interactivity.element === window) {\n if (canvasEl) {\n const clientRect = canvasEl.getBoundingClientRect();\n pos = {\n x: mouseEvent.clientX - clientRect.left,\n y: mouseEvent.clientY - clientRect.top\n };\n }\n } else if (options.interactivity.detectsOn === \"parent\") {\n const source = mouseEvent.target,\n target = mouseEvent.currentTarget;\n if (source && target && canvasEl) {\n const sourceRect = source.getBoundingClientRect(),\n targetRect = target.getBoundingClientRect(),\n canvasRect = canvasEl.getBoundingClientRect();\n pos = {\n x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),\n y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top)\n };\n } else {\n pos = {\n x: mouseEvent.offsetX ?? mouseEvent.clientX,\n y: mouseEvent.offsetY ?? mouseEvent.clientY\n };\n }\n } else if (mouseEvent.target === canvasEl) {\n pos = {\n x: mouseEvent.offsetX ?? mouseEvent.clientX,\n y: mouseEvent.offsetY ?? mouseEvent.clientY\n };\n }\n } else {\n this._canPush = e.type !== \"touchmove\";\n if (canvasEl) {\n const touchEvent = e,\n lengthOffset = 1,\n lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset],\n canvasRect = canvasEl.getBoundingClientRect(),\n defaultCoordinate = 0;\n pos = {\n x: lastTouch.clientX - (canvasRect.left ?? defaultCoordinate),\n y: lastTouch.clientY - (canvasRect.top ?? defaultCoordinate)\n };\n }\n }\n const pxRatio = container.retina.pixelRatio;\n if (pos) {\n pos.x *= pxRatio;\n pos.y *= pxRatio;\n }\n interactivity.mouse.position = pos;\n interactivity.status = _Constants_js__WEBPACK_IMPORTED_MODULE_1__.mouseMoveEvent;\n };\n this._touchEnd = e => {\n const evt = e,\n touches = Array.from(evt.changedTouches);\n for (const touch of touches) {\n this._touches.delete(touch.identifier);\n }\n this._mouseTouchFinish();\n };\n this._touchEndClick = e => {\n const evt = e,\n touches = Array.from(evt.changedTouches);\n for (const touch of touches) {\n this._touches.delete(touch.identifier);\n }\n this._mouseTouchClick(e);\n };\n this._touchStart = e => {\n const evt = e,\n touches = Array.from(evt.changedTouches);\n for (const touch of touches) {\n this._touches.set(touch.identifier, performance.now());\n }\n this._mouseTouchMove(e);\n };\n this._canPush = true;\n this._touches = new Map();\n this._handlers = {\n mouseDown: () => this._mouseDown(),\n mouseLeave: () => this._mouseTouchFinish(),\n mouseMove: e => this._mouseTouchMove(e),\n mouseUp: e => this._mouseTouchClick(e),\n touchStart: e => this._touchStart(e),\n touchMove: e => this._mouseTouchMove(e),\n touchEnd: e => this._touchEnd(e),\n touchCancel: e => this._touchEnd(e),\n touchEndClick: e => this._touchEndClick(e),\n visibilityChange: () => this._handleVisibilityChange(),\n themeChange: e => this._handleThemeChange(e),\n oldThemeChange: e => this._handleThemeChange(e),\n resize: () => {\n this._handleWindowResize();\n }\n };\n }\n addListeners() {\n this._manageListeners(true);\n }\n removeListeners() {\n this._manageListeners(false);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Utils/EventListeners.js?");
|
|
69
|
+
|
|
70
|
+
/***/ }),
|
|
71
|
+
|
|
72
|
+
/***/ "./dist/browser/Core/Utils/InteractionManager.js":
|
|
73
|
+
/*!*******************************************************!*\
|
|
74
|
+
!*** ./dist/browser/Core/Utils/InteractionManager.js ***!
|
|
75
|
+
\*******************************************************/
|
|
76
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
77
|
+
|
|
78
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ InteractionManager: () => (/* binding */ InteractionManager)\n/* harmony export */ });\nclass InteractionManager {\n constructor(engine, container) {\n this.container = container;\n this._engine = engine;\n this._interactors = [];\n this._externalInteractors = [];\n this._particleInteractors = [];\n }\n async externalInteract(delta) {\n for (const interactor of this._externalInteractors) {\n if (interactor.isEnabled()) {\n await interactor.interact(delta);\n }\n }\n }\n handleClickMode(mode) {\n for (const interactor of this._externalInteractors) {\n interactor.handleClickMode?.(mode);\n }\n }\n async init() {\n this._interactors = await this._engine.getInteractors(this.container, true);\n this._externalInteractors = [];\n this._particleInteractors = [];\n for (const interactor of this._interactors) {\n switch (interactor.type) {\n case \"external\":\n this._externalInteractors.push(interactor);\n break;\n case \"particles\":\n this._particleInteractors.push(interactor);\n break;\n }\n interactor.init();\n }\n }\n async particlesInteract(particle, delta) {\n for (const interactor of this._externalInteractors) {\n interactor.clear(particle, delta);\n }\n for (const interactor of this._particleInteractors) {\n if (interactor.isEnabled(particle)) {\n await interactor.interact(particle, delta);\n }\n }\n }\n reset(particle) {\n for (const interactor of this._externalInteractors) {\n if (interactor.isEnabled()) {\n interactor.reset(particle);\n }\n }\n for (const interactor of this._particleInteractors) {\n if (interactor.isEnabled(particle)) {\n interactor.reset(particle);\n }\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Utils/InteractionManager.js?");
|
|
79
|
+
|
|
80
|
+
/***/ }),
|
|
81
|
+
|
|
82
|
+
/***/ "./dist/browser/Core/Utils/QuadTree.js":
|
|
83
|
+
/*!*********************************************!*\
|
|
84
|
+
!*** ./dist/browser/Core/Utils/QuadTree.js ***!
|
|
85
|
+
\*********************************************/
|
|
86
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
87
|
+
|
|
88
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ QuadTree: () => (/* binding */ QuadTree)\n/* harmony export */ });\n/* harmony import */ var _Circle_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Circle.js */ \"./dist/browser/Core/Utils/Circle.js\");\n/* harmony import */ var _Rectangle_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Rectangle.js */ \"./dist/browser/Core/Utils/Rectangle.js\");\n/* harmony import */ var _Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../Utils/NumberUtils.js */ \"./dist/browser/Utils/NumberUtils.js\");\n\n\n\nconst half = 0.5,\n double = 2,\n subdivideCount = 4;\nclass QuadTree {\n constructor(rectangle, capacity) {\n this.rectangle = rectangle;\n this.capacity = capacity;\n this._subdivide = () => {\n const {\n x,\n y\n } = this.rectangle.position,\n {\n width,\n height\n } = this.rectangle.size,\n {\n capacity\n } = this;\n for (let i = 0; i < subdivideCount; i++) {\n const fixedIndex = i % double;\n this._subs.push(new QuadTree(new _Rectangle_js__WEBPACK_IMPORTED_MODULE_0__.Rectangle(x + width * half * fixedIndex, y + height * half * (Math.round(i * half) - fixedIndex), width * half, height * half), capacity));\n }\n this._divided = true;\n };\n this._points = [];\n this._divided = false;\n this._subs = [];\n }\n insert(point) {\n if (!this.rectangle.contains(point.position)) {\n return false;\n }\n if (this._points.length < this.capacity) {\n this._points.push(point);\n return true;\n }\n if (!this._divided) {\n this._subdivide();\n }\n return this._subs.some(sub => sub.insert(point));\n }\n query(range, check, found) {\n const res = found ?? [];\n if (!range.intersects(this.rectangle)) {\n return [];\n }\n for (const p of this._points) {\n if (!range.contains(p.position) && (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_1__.getDistance)(range.position, p.position) > p.particle.getRadius() && (!check || check(p.particle))) {\n continue;\n }\n res.push(p.particle);\n }\n if (this._divided) {\n for (const sub of this._subs) {\n sub.query(range, check, res);\n }\n }\n return res;\n }\n queryCircle(position, radius, check) {\n return this.query(new _Circle_js__WEBPACK_IMPORTED_MODULE_2__.Circle(position.x, position.y, radius), check);\n }\n queryRectangle(position, size, check) {\n return this.query(new _Rectangle_js__WEBPACK_IMPORTED_MODULE_0__.Rectangle(position.x, position.y, size.width, size.height), check);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Utils/QuadTree.js?");
|
|
89
|
+
|
|
90
|
+
/***/ })
|
|
91
|
+
|
|
92
|
+
}]);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* tsParticles Engine v3.2.0
|
|
3
|
+
* Author: Matteo Bruni
|
|
4
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
5
|
+
* Website: https://particles.js.org/
|
|
6
|
+
* Confetti Website: https://confetti.js.org
|
|
7
|
+
* GitHub: https://www.github.com/matteobruni/tsparticles
|
|
8
|
+
* How to use?: Check the GitHub README
|
|
9
|
+
* ------------------------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
"use strict";
|
|
12
|
+
/*
|
|
13
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
14
|
+
* This devtool is neither made for production nor for readable output files.
|
|
15
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
16
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
17
|
+
* or disable the default devtool with "devtool: false".
|
|
18
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
19
|
+
*/
|
|
20
|
+
(this["webpackChunk_tsparticles_engine"] = this["webpackChunk_tsparticles_engine"] || []).push([["dist_browser_Core_Particle_js"],{
|
|
21
|
+
|
|
22
|
+
/***/ "./dist/browser/Core/Particle.js":
|
|
23
|
+
/*!***************************************!*\
|
|
24
|
+
!*** ./dist/browser/Core/Particle.js ***!
|
|
25
|
+
\***************************************/
|
|
26
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
27
|
+
|
|
28
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Particle: () => (/* binding */ Particle)\n/* harmony export */ });\n/* harmony import */ var _Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../Utils/NumberUtils.js */ \"./dist/browser/Utils/NumberUtils.js\");\n/* harmony import */ var _Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Utils/Utils.js */ \"./dist/browser/Utils/Utils.js\");\n/* harmony import */ var _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Utils/Constants.js */ \"./dist/browser/Core/Utils/Constants.js\");\n/* harmony import */ var _Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../Utils/ColorUtils.js */ \"./dist/browser/Utils/ColorUtils.js\");\n/* harmony import */ var _Options_Classes_Interactivity_Interactivity_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../Options/Classes/Interactivity/Interactivity.js */ \"./dist/browser/Options/Classes/Interactivity/Interactivity.js\");\n/* harmony import */ var _Utils_Vector_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./Utils/Vector.js */ \"./dist/browser/Core/Utils/Vector.js\");\n/* harmony import */ var _Utils_Vector3d_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils/Vector3d.js */ \"./dist/browser/Core/Utils/Vector3d.js\");\n/* harmony import */ var _Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../Utils/CanvasUtils.js */ \"./dist/browser/Utils/CanvasUtils.js\");\n/* harmony import */ var _Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../Utils/OptionsUtils.js */ \"./dist/browser/Utils/OptionsUtils.js\");\n\n\n\n\n\n\n\n\n\nconst defaultRetryCount = 0,\n double = 2,\n half = 0.5,\n squareExp = 2;\nfunction loadEffectData(effect, effectOptions, id, reduceDuplicates) {\n const effectData = effectOptions.options[effect];\n if (!effectData) {\n return;\n }\n return (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({\n close: effectOptions.close,\n fill: effectOptions.fill\n }, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(effectData, id, reduceDuplicates));\n}\nfunction loadShapeData(shape, shapeOptions, id, reduceDuplicates) {\n const shapeData = shapeOptions.options[shape];\n if (!shapeData) {\n return;\n }\n return (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({\n close: shapeOptions.close,\n fill: shapeOptions.fill\n }, (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(shapeData, id, reduceDuplicates));\n}\nfunction fixOutMode(data) {\n if (!(0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.isInArray)(data.outMode, data.checkModes)) {\n return;\n }\n const diameter = data.radius * double;\n if (data.coord > data.maxCoord - diameter) {\n data.setCb(-data.radius);\n } else if (data.coord < diameter) {\n data.setCb(data.radius);\n }\n}\nclass Particle {\n constructor(engine, container) {\n this.container = container;\n this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {\n for (const [, plugin] of container.plugins) {\n const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;\n if (pluginPos) {\n return _Utils_Vector3d_js__WEBPACK_IMPORTED_MODULE_1__.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);\n }\n }\n const canvasSize = container.canvas.size,\n exactPosition = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.calcExactPositionOrRandomFromSize)({\n size: canvasSize,\n position: position\n }),\n pos = _Utils_Vector3d_js__WEBPACK_IMPORTED_MODULE_1__.Vector3d.create(exactPosition.x, exactPosition.y, zIndex),\n radius = this.getRadius(),\n outModes = this.options.move.outModes,\n fixHorizontal = outMode => {\n fixOutMode({\n outMode,\n checkModes: [\"bounce\"],\n coord: pos.x,\n maxCoord: container.canvas.size.width,\n setCb: value => pos.x += value,\n radius\n });\n },\n fixVertical = outMode => {\n fixOutMode({\n outMode,\n checkModes: [\"bounce\"],\n coord: pos.y,\n maxCoord: container.canvas.size.height,\n setCb: value => pos.y += value,\n radius\n });\n };\n fixHorizontal(outModes.left ?? outModes.default);\n fixHorizontal(outModes.right ?? outModes.default);\n fixVertical(outModes.top ?? outModes.default);\n fixVertical(outModes.bottom ?? outModes.default);\n if (this._checkOverlap(pos, tryCount)) {\n const increment = 1;\n return this._calcPosition(container, undefined, zIndex, tryCount + increment);\n }\n return pos;\n };\n this._calculateVelocity = () => {\n const baseVelocity = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getParticleBaseVelocity)(this.direction),\n res = baseVelocity.copy(),\n moveOptions = this.options.move;\n if (moveOptions.direction === \"inside\" || moveOptions.direction === \"outside\") {\n return res;\n }\n const rad = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.degToRad)((0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getRangeValue)(moveOptions.angle.value)),\n radOffset = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.degToRad)((0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getRangeValue)(moveOptions.angle.offset)),\n range = {\n left: radOffset - rad * half,\n right: radOffset + rad * half\n };\n if (!moveOptions.straight) {\n res.angle += (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.randomInRange)((0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.setRangeValue)(range.left, range.right));\n }\n if (moveOptions.random && typeof moveOptions.speed === \"number\") {\n res.length *= (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getRandom)();\n }\n return res;\n };\n this._checkOverlap = (pos, tryCount = defaultRetryCount) => {\n const collisionsOptions = this.options.collisions,\n radius = this.getRadius();\n if (!collisionsOptions.enable) {\n return false;\n }\n const overlapOptions = collisionsOptions.overlap;\n if (overlapOptions.enable) {\n return false;\n }\n const retries = overlapOptions.retries,\n minRetries = 0;\n if (retries >= minRetries && tryCount > retries) {\n throw new Error(`${_Utils_Constants_js__WEBPACK_IMPORTED_MODULE_3__.errorPrefix} particle is overlapping and can't be placed`);\n }\n return !!this.container.particles.find(particle => (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getDistance)(pos, particle.position) < radius + particle.getRadius());\n };\n this._getRollColor = color => {\n if (!color || !this.roll || !this.backColor && !this.roll.alter) {\n return color;\n }\n const rollFactor = 1,\n none = 0,\n backFactor = this.roll.horizontal && this.roll.vertical ? double * rollFactor : rollFactor,\n backSum = this.roll.horizontal ? Math.PI * half : none,\n rolled = Math.floor(((this.roll.angle ?? none) + backSum) / (Math.PI / backFactor)) % double;\n if (!rolled) {\n return color;\n }\n if (this.backColor) {\n return this.backColor;\n }\n if (this.roll.alter) {\n return (0,_Utils_CanvasUtils_js__WEBPACK_IMPORTED_MODULE_4__.alterHsl)(color, this.roll.alter.type, this.roll.alter.value);\n }\n return color;\n };\n this._initPosition = position => {\n const container = this.container,\n zIndexValue = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getRangeValue)(this.options.zIndex.value),\n minZ = 0;\n this.position = this._calcPosition(container, position, (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.clamp)(zIndexValue, minZ, container.zLayers));\n this.initialPosition = this.position.copy();\n const canvasSize = container.canvas.size,\n defaultRadius = 0;\n this.moveCenter = {\n ...(0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.getPosition)(this.options.move.center, canvasSize),\n radius: this.options.move.center.radius ?? defaultRadius,\n mode: this.options.move.center.mode ?? \"percent\"\n };\n this.direction = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);\n switch (this.options.move.direction) {\n case \"inside\":\n this.outType = \"inside\";\n break;\n case \"outside\":\n this.outType = \"outside\";\n break;\n }\n this.offset = _Utils_Vector_js__WEBPACK_IMPORTED_MODULE_5__.Vector.origin;\n };\n this._engine = engine;\n }\n destroy(override) {\n if (this.unbreakable || this.destroyed) {\n return;\n }\n this.destroyed = true;\n this.bubble.inRange = false;\n this.slow.inRange = false;\n const container = this.container,\n pathGenerator = this.pathGenerator,\n shapeDrawer = container.shapeDrawers.get(this.shape);\n shapeDrawer?.particleDestroy?.(this);\n for (const [, plugin] of container.plugins) {\n plugin.particleDestroyed?.(this, override);\n }\n for (const updater of container.particles.updaters) {\n updater.particleDestroyed?.(this, override);\n }\n pathGenerator?.reset(this);\n this._engine.dispatchEvent(\"particleDestroyed\", {\n container: this.container,\n data: {\n particle: this\n }\n });\n }\n async draw(delta) {\n const container = this.container,\n canvas = container.canvas;\n for (const [, plugin] of container.plugins) {\n await canvas.drawParticlePlugin(plugin, this, delta);\n }\n await canvas.drawParticle(this, delta);\n }\n getFillColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_6__.getHslFromAnimation)(this.color));\n }\n getMass() {\n return this.getRadius() ** squareExp * Math.PI * half;\n }\n getPosition() {\n return {\n x: this.position.x + this.offset.x,\n y: this.position.y + this.offset.y,\n z: this.position.z\n };\n }\n getRadius() {\n return this.bubble.radius ?? this.size.value;\n }\n getStrokeColor() {\n return this._getRollColor(this.bubble.color ?? (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_6__.getHslFromAnimation)(this.strokeColor));\n }\n async init(id, position, overrideOptions, group) {\n const container = this.container,\n engine = this._engine;\n this.id = id;\n this.group = group;\n this.effectClose = true;\n this.effectFill = true;\n this.shapeClose = true;\n this.shapeFill = true;\n this.pathRotation = false;\n this.lastPathTime = 0;\n this.destroyed = false;\n this.unbreakable = false;\n this.rotation = 0;\n this.misplaced = false;\n this.retina = {\n maxDistance: {}\n };\n this.outType = \"normal\";\n this.ignoresResizeRatio = true;\n const pxRatio = container.retina.pixelRatio,\n mainOptions = container.actualOptions,\n particlesOptions = (0,_Utils_OptionsUtils_js__WEBPACK_IMPORTED_MODULE_7__.loadParticlesOptions)(this._engine, container, mainOptions.particles),\n effectType = particlesOptions.effect.type,\n shapeType = particlesOptions.shape.type,\n {\n reduceDuplicates\n } = particlesOptions;\n this.effect = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);\n this.shape = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);\n const effectOptions = particlesOptions.effect,\n shapeOptions = particlesOptions.shape;\n if (overrideOptions) {\n if (overrideOptions.effect?.type) {\n const overrideEffectType = overrideOptions.effect.type,\n effect = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);\n if (effect) {\n this.effect = effect;\n effectOptions.load(overrideOptions.effect);\n }\n }\n if (overrideOptions.shape?.type) {\n const overrideShapeType = overrideOptions.shape.type,\n shape = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);\n if (shape) {\n this.shape = shape;\n shapeOptions.load(overrideOptions.shape);\n }\n }\n }\n this.effectData = loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates);\n this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);\n particlesOptions.load(overrideOptions);\n const effectData = this.effectData;\n if (effectData) {\n particlesOptions.load(effectData.particles);\n }\n const shapeData = this.shapeData;\n if (shapeData) {\n particlesOptions.load(shapeData.particles);\n }\n const interactivity = new _Options_Classes_Interactivity_Interactivity_js__WEBPACK_IMPORTED_MODULE_8__.Interactivity(engine, container);\n interactivity.load(container.actualOptions.interactivity);\n interactivity.load(particlesOptions.interactivity);\n this.interactivity = interactivity;\n this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;\n this.effectClose = effectData?.close ?? particlesOptions.effect.close;\n this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;\n this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;\n this.options = particlesOptions;\n const pathOptions = this.options.move.path;\n this.pathDelay = (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getRangeValue)(pathOptions.delay.value) * _Utils_Constants_js__WEBPACK_IMPORTED_MODULE_3__.millisecondsToSeconds;\n if (pathOptions.generator) {\n this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);\n if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {\n await this.pathGenerator.init(container);\n }\n }\n container.retina.initParticle(this);\n this.size = (0,_Utils_Utils_js__WEBPACK_IMPORTED_MODULE_0__.initParticleNumericAnimationValue)(this.options.size, pxRatio);\n this.bubble = {\n inRange: false\n };\n this.slow = {\n inRange: false,\n factor: 1\n };\n this._initPosition(position);\n this.initialVelocity = this._calculateVelocity();\n this.velocity = this.initialVelocity.copy();\n const decayOffset = 1;\n this.moveDecay = decayOffset - (0,_Utils_NumberUtils_js__WEBPACK_IMPORTED_MODULE_2__.getRangeValue)(this.options.move.decay);\n const particles = container.particles;\n particles.setLastZIndex(this.position.z);\n this.zIndexFactor = this.position.z / container.zLayers;\n this.sides = 24;\n let effectDrawer = container.effectDrawers.get(this.effect);\n if (!effectDrawer) {\n effectDrawer = this._engine.getEffectDrawer(this.effect);\n if (effectDrawer) {\n container.effectDrawers.set(this.effect, effectDrawer);\n }\n }\n if (effectDrawer?.loadEffect) {\n await effectDrawer.loadEffect(this);\n }\n let shapeDrawer = container.shapeDrawers.get(this.shape);\n if (!shapeDrawer) {\n shapeDrawer = this._engine.getShapeDrawer(this.shape);\n if (shapeDrawer) {\n container.shapeDrawers.set(this.shape, shapeDrawer);\n }\n }\n if (shapeDrawer?.loadShape) {\n await shapeDrawer.loadShape(this);\n }\n const sideCountFunc = shapeDrawer?.getSidesCount;\n if (sideCountFunc) {\n this.sides = sideCountFunc(this);\n }\n this.spawning = false;\n this.shadowColor = (0,_Utils_ColorUtils_js__WEBPACK_IMPORTED_MODULE_6__.rangeColorToRgb)(this.options.shadow.color);\n for (const updater of particles.updaters) {\n await updater.init(this);\n }\n for (const mover of particles.movers) {\n await mover.init?.(this);\n }\n await effectDrawer?.particleInit?.(container, this);\n await shapeDrawer?.particleInit?.(container, this);\n for (const [, plugin] of container.plugins) {\n plugin.particleCreated?.(this);\n }\n }\n isInsideCanvas() {\n const radius = this.getRadius(),\n canvasSize = this.container.canvas.size,\n position = this.position;\n return position.x >= -radius && position.y >= -radius && position.y <= canvasSize.height + radius && position.x <= canvasSize.width + radius;\n }\n isVisible() {\n return !this.destroyed && !this.spawning && this.isInsideCanvas();\n }\n reset() {\n for (const updater of this.container.particles.updaters) {\n updater.reset?.(this);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/engine/./dist/browser/Core/Particle.js?");
|
|
29
|
+
|
|
30
|
+
/***/ })
|
|
31
|
+
|
|
32
|
+
}]);
|
package/esm/Core/Canvas.js
CHANGED
|
@@ -8,6 +8,26 @@ function setTransformValue(factor, newFactor, key) {
|
|
|
8
8
|
factor[key] = (factor[key] ?? defaultValue) * newValue;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
function setStyle(canvas, style, important = false) {
|
|
12
|
+
if (!style) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const element = canvas;
|
|
16
|
+
if (!element) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const elementStyle = element.style;
|
|
20
|
+
if (!elementStyle) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const key in style) {
|
|
24
|
+
const value = style[key];
|
|
25
|
+
if (!value) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
elementStyle.setProperty(key, value, important ? "important" : "");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
11
31
|
export class Canvas {
|
|
12
32
|
constructor(container) {
|
|
13
33
|
this.container = container;
|
|
@@ -56,14 +76,36 @@ export class Canvas {
|
|
|
56
76
|
}
|
|
57
77
|
return [fColor, sColor];
|
|
58
78
|
};
|
|
59
|
-
this._initCover = () => {
|
|
60
|
-
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
this._initCover = async () => {
|
|
80
|
+
const options = this.container.actualOptions, cover = options.backgroundMask.cover, color = cover.color;
|
|
81
|
+
if (color) {
|
|
82
|
+
const coverRgb = rangeColorToRgb(color);
|
|
83
|
+
if (coverRgb) {
|
|
84
|
+
const coverColor = {
|
|
85
|
+
...coverRgb,
|
|
86
|
+
a: cover.opacity,
|
|
87
|
+
};
|
|
88
|
+
this._coverColorStyle = getStyleFromRgb(coverColor, coverColor.a);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
await new Promise((resolve, reject) => {
|
|
93
|
+
if (!cover.image) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const img = document.createElement("img");
|
|
97
|
+
img.addEventListener("load", () => {
|
|
98
|
+
this._coverImage = {
|
|
99
|
+
image: img,
|
|
100
|
+
opacity: cover.opacity,
|
|
101
|
+
};
|
|
102
|
+
resolve();
|
|
103
|
+
});
|
|
104
|
+
img.addEventListener("error", (evt) => {
|
|
105
|
+
reject(evt.error);
|
|
106
|
+
});
|
|
107
|
+
img.src = cover.image;
|
|
108
|
+
});
|
|
67
109
|
}
|
|
68
110
|
};
|
|
69
111
|
this._initStyle = () => {
|
|
@@ -148,13 +190,7 @@ export class Canvas {
|
|
|
148
190
|
if (!(element && originalStyle)) {
|
|
149
191
|
return;
|
|
150
192
|
}
|
|
151
|
-
|
|
152
|
-
style.position = originalStyle.position;
|
|
153
|
-
style.zIndex = originalStyle.zIndex;
|
|
154
|
-
style.top = originalStyle.top;
|
|
155
|
-
style.left = originalStyle.left;
|
|
156
|
-
style.width = originalStyle.width;
|
|
157
|
-
style.height = originalStyle.height;
|
|
193
|
+
setStyle(element, originalStyle);
|
|
158
194
|
};
|
|
159
195
|
this._safeMutationObserver = (callback) => {
|
|
160
196
|
if (!this._mutationObserver) {
|
|
@@ -167,13 +203,15 @@ export class Canvas {
|
|
|
167
203
|
if (!element) {
|
|
168
204
|
return;
|
|
169
205
|
}
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
206
|
+
const radix = 10;
|
|
207
|
+
setStyle(element, {
|
|
208
|
+
position: "fixed",
|
|
209
|
+
zIndex: this.container.actualOptions.fullScreen.zIndex.toString(radix),
|
|
210
|
+
top: "0",
|
|
211
|
+
left: "0",
|
|
212
|
+
width: "100%",
|
|
213
|
+
height: "100%",
|
|
214
|
+
}, true);
|
|
177
215
|
};
|
|
178
216
|
this.size = {
|
|
179
217
|
height: 0,
|
|
@@ -229,7 +267,14 @@ export class Canvas {
|
|
|
229
267
|
}
|
|
230
268
|
return cb(ctx);
|
|
231
269
|
}
|
|
232
|
-
|
|
270
|
+
drawAsync(cb) {
|
|
271
|
+
const ctx = this._context;
|
|
272
|
+
if (!ctx) {
|
|
273
|
+
return Promise.resolve(undefined);
|
|
274
|
+
}
|
|
275
|
+
return cb(ctx);
|
|
276
|
+
}
|
|
277
|
+
async drawParticle(particle, delta) {
|
|
233
278
|
if (particle.spawning || particle.destroyed) {
|
|
234
279
|
return;
|
|
235
280
|
}
|
|
@@ -248,13 +293,13 @@ export class Canvas {
|
|
|
248
293
|
if (!fColor && !sColor) {
|
|
249
294
|
return;
|
|
250
295
|
}
|
|
251
|
-
this.
|
|
296
|
+
await this.drawAsync(async (ctx) => {
|
|
252
297
|
const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
|
|
253
298
|
fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined,
|
|
254
299
|
};
|
|
255
300
|
colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
|
|
256
301
|
this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
|
|
257
|
-
drawParticle({
|
|
302
|
+
await drawParticle({
|
|
258
303
|
container,
|
|
259
304
|
context: ctx,
|
|
260
305
|
particle,
|
|
@@ -270,11 +315,11 @@ export class Canvas {
|
|
|
270
315
|
this._applyPostDrawUpdaters(particle);
|
|
271
316
|
});
|
|
272
317
|
}
|
|
273
|
-
drawParticlePlugin(plugin, particle, delta) {
|
|
274
|
-
this.
|
|
318
|
+
async drawParticlePlugin(plugin, particle, delta) {
|
|
319
|
+
await this.drawAsync((ctx) => drawParticlePlugin(ctx, plugin, particle, delta));
|
|
275
320
|
}
|
|
276
|
-
drawPlugin(plugin, delta) {
|
|
277
|
-
this.
|
|
321
|
+
async drawPlugin(plugin, delta) {
|
|
322
|
+
await this.drawAsync((ctx) => drawPlugin(ctx, plugin, delta));
|
|
278
323
|
}
|
|
279
324
|
async init() {
|
|
280
325
|
this._safeMutationObserver((obs) => obs.disconnect());
|
|
@@ -287,7 +332,7 @@ export class Canvas {
|
|
|
287
332
|
});
|
|
288
333
|
this.resize();
|
|
289
334
|
this._initStyle();
|
|
290
|
-
this._initCover();
|
|
335
|
+
await this._initCover();
|
|
291
336
|
try {
|
|
292
337
|
await this._initTrail();
|
|
293
338
|
}
|
|
@@ -377,7 +422,15 @@ export class Canvas {
|
|
|
377
422
|
this.draw((ctx) => {
|
|
378
423
|
if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
|
379
424
|
clear(ctx, this.size);
|
|
380
|
-
|
|
425
|
+
if (this._coverImage) {
|
|
426
|
+
this._paintImage(this._coverImage.image, this._coverImage.opacity);
|
|
427
|
+
}
|
|
428
|
+
else if (this._coverColorStyle) {
|
|
429
|
+
this._paintBase(this._coverColorStyle);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
this._paintBase();
|
|
433
|
+
}
|
|
381
434
|
}
|
|
382
435
|
else {
|
|
383
436
|
this._paintBase();
|
|
@@ -419,7 +472,7 @@ export class Canvas {
|
|
|
419
472
|
return;
|
|
420
473
|
}
|
|
421
474
|
const container = this.container, needsRefresh = container.updateActualOptions();
|
|
422
|
-
container.particles.setDensity();
|
|
475
|
+
await container.particles.setDensity();
|
|
423
476
|
this._applyResizePlugins();
|
|
424
477
|
if (needsRefresh) {
|
|
425
478
|
await container.refresh();
|
package/esm/Core/Container.js
CHANGED
|
@@ -61,7 +61,7 @@ export class Container {
|
|
|
61
61
|
this.destroy();
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
if (this.
|
|
64
|
+
if (this.animationStatus) {
|
|
65
65
|
this.draw(false);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -104,6 +104,9 @@ export class Container {
|
|
|
104
104
|
this._intersectionObserver = safeIntersectionObserver((entries) => this._intersectionManager(entries));
|
|
105
105
|
this._engine.dispatchEvent("containerBuilt", { container: this });
|
|
106
106
|
}
|
|
107
|
+
get animationStatus() {
|
|
108
|
+
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
109
|
+
}
|
|
107
110
|
get options() {
|
|
108
111
|
return this._options;
|
|
109
112
|
}
|
|
@@ -256,9 +259,6 @@ export class Container {
|
|
|
256
259
|
}
|
|
257
260
|
getLogger().error(`${errorPrefix} - Export plugin with type ${type} not found`);
|
|
258
261
|
}
|
|
259
|
-
getAnimationStatus() {
|
|
260
|
-
return !this._paused && !this.pageHidden && guardCheck(this);
|
|
261
|
-
}
|
|
262
262
|
handleClickMode(mode) {
|
|
263
263
|
if (!guardCheck(this)) {
|
|
264
264
|
return;
|
|
@@ -286,9 +286,10 @@ export class Container {
|
|
|
286
286
|
this.shapeDrawers.set(type, drawer);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
+
await this.particles.initPlugins();
|
|
289
290
|
this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
|
290
291
|
this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
|
291
|
-
const availablePlugins = this._engine.getAvailablePlugins(this);
|
|
292
|
+
const availablePlugins = await this._engine.getAvailablePlugins(this);
|
|
292
293
|
for (const [id, plugin] of availablePlugins) {
|
|
293
294
|
this.plugins.set(id, plugin);
|
|
294
295
|
}
|
|
@@ -314,8 +315,8 @@ export class Container {
|
|
|
314
315
|
await plugin.init?.();
|
|
315
316
|
}
|
|
316
317
|
this._engine.dispatchEvent("containerInit", { container: this });
|
|
317
|
-
this.particles.init();
|
|
318
|
-
this.particles.setDensity();
|
|
318
|
+
await this.particles.init();
|
|
319
|
+
await this.particles.setDensity();
|
|
319
320
|
for (const [, plugin] of this.plugins) {
|
|
320
321
|
plugin.particlesSetup?.();
|
|
321
322
|
}
|