@tsparticles/plugin-emitters 3.9.1 → 4.0.0-alpha.1
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/214.min.js +2 -0
- package/214.min.js.LICENSE.txt +1 -0
- package/921.min.js +2 -0
- package/921.min.js.LICENSE.txt +1 -0
- package/browser/EmitterInstance.js +12 -13
- package/browser/Emitters.js +9 -8
- package/browser/EmittersPlugin.js +19 -32
- package/browser/Options/Classes/Emitter.js +2 -6
- package/browser/ShapeManager.js +0 -3
- package/browser/index.js +10 -18
- package/cjs/EmitterContainer.js +1 -2
- package/cjs/EmitterInstance.js +34 -39
- package/cjs/EmitterShapeBase.js +1 -5
- package/cjs/Emitters.js +21 -24
- package/cjs/EmittersEngine.js +1 -2
- package/cjs/EmittersPlugin.js +31 -48
- package/cjs/Enums/EmitterClickMode.js +2 -5
- package/cjs/IEmitterShape.js +1 -2
- package/cjs/IEmitterShapeGenerator.js +1 -2
- package/cjs/IRandomPositionData.js +1 -2
- package/cjs/Options/Classes/Emitter.js +16 -24
- package/cjs/Options/Classes/EmitterLife.js +5 -9
- package/cjs/Options/Classes/EmitterRate.js +5 -9
- package/cjs/Options/Classes/EmitterShape.js +6 -10
- package/cjs/Options/Classes/EmitterShapeReplace.js +3 -7
- package/cjs/Options/Classes/EmitterSize.js +4 -8
- package/cjs/Options/Interfaces/IEmitter.js +1 -2
- package/cjs/Options/Interfaces/IEmitterLife.js +1 -2
- package/cjs/Options/Interfaces/IEmitterRate.js +1 -2
- package/cjs/Options/Interfaces/IEmitterShape.js +1 -2
- package/cjs/Options/Interfaces/IEmitterShapeReplace.js +1 -2
- package/cjs/Options/Interfaces/IEmitterSize.js +1 -2
- package/cjs/ShapeManager.js +1 -8
- package/cjs/index.js +12 -37
- package/cjs/types.js +1 -2
- package/dist_browser_EmittersPlugin_js.js +110 -0
- package/dist_browser_ShapeManager_js.js +30 -0
- package/esm/EmitterInstance.js +12 -13
- package/esm/Emitters.js +9 -8
- package/esm/EmittersPlugin.js +19 -32
- package/esm/Options/Classes/Emitter.js +2 -6
- package/esm/ShapeManager.js +0 -3
- package/esm/index.js +10 -18
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.plugin.emitters.js +215 -126
- package/tsparticles.plugin.emitters.min.js +1 -1
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -1
- package/types/Options/Classes/EmitterShape.d.ts +1 -1
- package/types/Options/Classes/EmitterShapeReplace.d.ts +1 -1
- package/types/ShapeManager.d.ts +0 -3
- package/types/index.d.ts +7 -7
- package/umd/EmitterInstance.js +13 -14
- package/umd/Emitters.js +9 -8
- package/umd/EmittersPlugin.js +19 -32
- package/umd/Options/Classes/Emitter.js +2 -6
- package/umd/ShapeManager.js +0 -3
- package/umd/index.js +34 -19
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.1
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_emitters"] = this["webpackChunk_tsparticles_plugin_emitters"] || []).push([["dist_browser_EmittersPlugin_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/EmitterInstance.js"
|
|
21
|
+
/*!*****************************************!*\
|
|
22
|
+
!*** ./dist/browser/EmitterInstance.js ***!
|
|
23
|
+
\*****************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterInstance: () => (/* binding */ EmitterInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Options_Classes_EmitterSize_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/EmitterSize.js */ \"./dist/browser/Options/Classes/EmitterSize.js\");\n\n\n\nconst defaultLifeDelay = 0,\n minLifeCount = 0,\n defaultSpawnDelay = 0,\n defaultEmitDelay = 0,\n defaultLifeCount = -1,\n defaultColorAnimationFactor = 1;\nfunction setParticlesOptionsColor(particlesOptions, color) {\n if (particlesOptions.color) {\n particlesOptions.color.value = color;\n } else {\n particlesOptions.color = {\n value: color\n };\n }\n}\nclass EmitterInstance {\n constructor(engine, emitters, container, options, position) {\n this.emitters = emitters;\n this.container = container;\n this._destroy = () => {\n this._mutationObserver?.disconnect();\n this._mutationObserver = undefined;\n this._resizeObserver?.disconnect();\n this._resizeObserver = undefined;\n this.emitters.removeEmitter(this);\n this._engine.dispatchEvent(\"emitterDestroyed\", {\n container: this.container,\n data: {\n emitter: this\n }\n });\n };\n this._prepareToDie = () => {\n if (this._paused) {\n return;\n }\n const duration = this.options.life.duration !== undefined ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.duration) : undefined,\n minDuration = 0,\n minLifeCount = 0;\n if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {\n this._duration = duration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n }\n };\n this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {\n const container = this.container;\n if (!animation.enable) {\n return initValue;\n }\n const colorOffset = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRangeValue)(animation.offset),\n delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.delay),\n emitFactor = container.retina.reduceFactor ? delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity,\n colorSpeed = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(animation.speed);\n return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * factor) % maxValue;\n };\n this._engine = engine;\n this._currentDuration = 0;\n this._currentEmitDelay = 0;\n this._currentSpawnDelay = 0;\n this._initialPosition = position;\n if (options instanceof _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter) {\n this.options = options;\n } else {\n this.options = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n this.options.load(options);\n }\n this._spawnDelay = container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n this.position = this._initialPosition ?? this._calcPosition();\n this.name = this.options.name;\n this.fill = this.options.fill;\n this._firstSpawn = !this.options.life.wait;\n this._startParticlesAdded = false;\n const particlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, this.options.particles);\n particlesOptions.move ??= {};\n particlesOptions.move.direction ??= this.options.direction;\n if (this.options.spawnColor) {\n this.spawnColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(this._engine, this.options.spawnColor);\n }\n this._paused = !this.options.autoPlay;\n this._particlesOptions = particlesOptions;\n this._size = this._calcSize();\n this.size = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getSize)(this._size, this.container.canvas.size);\n this._lifeCount = this.options.life.count ?? defaultLifeCount;\n this._immortal = this._lifeCount <= minLifeCount;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n this._mutationObserver = new MutationObserver(() => {\n this.resize();\n });\n this._resizeObserver = new ResizeObserver(() => {\n this.resize();\n });\n this._mutationObserver.observe(element, {\n attributes: true,\n attributeFilter: [\"style\", \"width\", \"height\"]\n });\n this._resizeObserver.observe(element);\n }\n }\n const shapeOptions = this.options.shape,\n shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);\n if (shapeGenerator) {\n this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);\n }\n this._engine.dispatchEvent(\"emitterCreated\", {\n container,\n data: {\n emitter: this\n }\n });\n this.play();\n }\n externalPause() {\n this._paused = true;\n this.pause();\n }\n externalPlay() {\n this._paused = false;\n this.play();\n }\n async init() {\n await this._shape?.init();\n }\n pause() {\n if (this._paused) {\n return;\n }\n delete this._emitDelay;\n }\n play() {\n if (this._paused) {\n return;\n }\n if (!((this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {\n return;\n }\n const container = this.container;\n if (this._emitDelay === undefined) {\n const delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.delay);\n this._emitDelay = container.retina.reduceFactor ? delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n }\n if (this._lifeCount > minLifeCount || this._immortal) {\n this._prepareToDie();\n }\n }\n resize() {\n const initialPosition = this._initialPosition,\n container = this.container;\n this.position = initialPosition && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isPointInside)(initialPosition, container.canvas.size, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin) ? initialPosition : this._calcPosition();\n this._size = this._calcSize();\n this.size = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getSize)(this._size, container.canvas.size);\n this._shape?.resize(this.position, this.size);\n }\n update(delta) {\n if (this._paused) {\n return;\n }\n const container = this.container;\n if (this._firstSpawn) {\n this._firstSpawn = false;\n this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;\n this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay;\n }\n if (!this._startParticlesAdded) {\n this._startParticlesAdded = true;\n this._emitParticles(this.options.startCount);\n }\n if (this._duration !== undefined) {\n this._currentDuration += delta.value;\n if (this._currentDuration >= this._duration) {\n this.pause();\n if (this._spawnDelay !== undefined) {\n delete this._spawnDelay;\n }\n if (!this._immortal) {\n this._lifeCount--;\n }\n if (this._lifeCount > minLifeCount || this._immortal) {\n this.position = this._calcPosition();\n this._shape?.resize(this.position, this.size);\n this._spawnDelay = container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n } else {\n this._destroy();\n }\n this._currentDuration -= this._duration;\n delete this._duration;\n }\n }\n if (this._spawnDelay !== undefined) {\n this._currentSpawnDelay += delta.value;\n if (this._currentSpawnDelay >= this._spawnDelay) {\n this._engine.dispatchEvent(\"emitterPlay\", {\n container: this.container\n });\n this.play();\n this._currentSpawnDelay -= this._currentSpawnDelay;\n delete this._spawnDelay;\n }\n }\n if (this._emitDelay !== undefined) {\n this._currentEmitDelay += delta.value;\n if (this._currentEmitDelay >= this._emitDelay) {\n this._emit();\n this._currentEmitDelay -= this._emitDelay;\n }\n }\n }\n _calcPosition() {\n const container = this.container;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n const elRect = element.getBoundingClientRect(),\n pxRatio = container.retina.pixelRatio;\n return {\n x: (elRect.x + elRect.width * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio,\n y: (elRect.y + elRect.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio\n };\n }\n }\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.calcPositionOrRandomFromSizeRanged)({\n size: container.canvas.size,\n position: this.options.position\n });\n }\n _calcSize() {\n const container = this.container;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n const elRect = element.getBoundingClientRect();\n return {\n width: elRect.width * container.retina.pixelRatio,\n height: elRect.height * container.retina.pixelRatio,\n mode: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.precise\n };\n }\n }\n return this.options.size ?? (() => {\n const size = new _Options_Classes_EmitterSize_js__WEBPACK_IMPORTED_MODULE_2__.EmitterSize();\n size.load({\n height: 0,\n mode: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.percent,\n width: 0\n });\n return size;\n })();\n }\n _emit() {\n if (this._paused) {\n return;\n }\n const quantity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.quantity);\n this._emitParticles(quantity);\n }\n _emitParticles(quantity) {\n const singleParticlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(this._particlesOptions),\n reduceFactor = this.container.retina.reduceFactor;\n for (let i = 0; i < quantity * reduceFactor; i++) {\n const particlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, singleParticlesOptions);\n if (this.spawnColor) {\n const hslAnimation = this.options.spawnColor?.animation;\n if (hslAnimation) {\n const maxValues = {\n h: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.hMax,\n s: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.sMax,\n l: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.lMax\n },\n colorFactor = 3.6;\n this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);\n this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);\n this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);\n }\n setParticlesOptionsColor(particlesOptions, this.spawnColor);\n }\n const shapeOptions = this.options.shape;\n let position = this.position;\n if (this._shape) {\n const shapePosData = this._shape.randomPosition();\n if (shapePosData) {\n position = shapePosData.position;\n const replaceData = shapeOptions.replace;\n if (replaceData.color && shapePosData.color) {\n setParticlesOptionsColor(particlesOptions, shapePosData.color);\n }\n if (replaceData.opacity) {\n if (particlesOptions.opacity) {\n particlesOptions.opacity.value = shapePosData.opacity;\n } else {\n particlesOptions.opacity = {\n value: shapePosData.opacity\n };\n }\n }\n } else {\n position = null;\n }\n }\n if (position) {\n this.container.particles.addParticle(position, particlesOptions);\n }\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmitterInstance.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ },
|
|
29
|
+
|
|
30
|
+
/***/ "./dist/browser/Emitters.js"
|
|
31
|
+
/*!**********************************!*\
|
|
32
|
+
!*** ./dist/browser/Emitters.js ***!
|
|
33
|
+
\**********************************/
|
|
34
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
|
+
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Emitters: () => (/* binding */ Emitters)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\n/* harmony import */ var _EmitterInstance_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EmitterInstance.js */ \"./dist/browser/EmitterInstance.js\");\n\n\n\n\nclass Emitters {\n constructor(engine, container) {\n this.container = container;\n this._engine = engine;\n this.array = [];\n this.emitters = [];\n this.interactivityEmitters = {\n random: {\n count: 1,\n enable: false\n },\n value: []\n };\n const defaultIndex = 0;\n container.getEmitter = idxOrName => idxOrName === undefined || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNumber)(idxOrName) ? this.array[idxOrName ?? defaultIndex] : this.array.find(t => t.name === idxOrName);\n container.addEmitter = async (options, position) => this.addEmitter(options, position);\n container.removeEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n this.removeEmitter(emitter);\n }\n };\n container.playEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n emitter.externalPlay();\n }\n };\n container.pauseEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n emitter.externalPause();\n }\n };\n }\n async addEmitter(options, position) {\n const emitterOptions = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n emitterOptions.load(options);\n const emitter = new _EmitterInstance_js__WEBPACK_IMPORTED_MODULE_3__.EmitterInstance(this._engine, this, this.container, emitterOptions, position);\n await emitter.init();\n this.array.push(emitter);\n return emitter;\n }\n handleClickMode(mode) {\n const modeEmitters = this.interactivityEmitters;\n if (mode !== _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__.EmitterClickMode.emitter) {\n return;\n }\n let emittersModeOptions;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(modeEmitters.value)) {\n const minLength = 0;\n if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {\n emittersModeOptions = [];\n const usedIndexes = [];\n for (let i = 0; i < modeEmitters.random.count; i++) {\n const idx = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.arrayRandomIndex)(modeEmitters.value);\n if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {\n i--;\n continue;\n }\n usedIndexes.push(idx);\n const selectedOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromArray)(modeEmitters.value, idx);\n if (!selectedOptions) {\n continue;\n }\n emittersModeOptions.push(selectedOptions);\n }\n } else {\n emittersModeOptions = modeEmitters.value;\n }\n } else {\n emittersModeOptions = modeEmitters.value;\n }\n const emittersOptions = emittersModeOptions,\n ePosition = this.container.interactivity.mouse.clickPosition;\n void (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(emittersOptions, async emitter => {\n await this.addEmitter(emitter, ePosition);\n });\n }\n async init() {\n this.emitters = this.container.actualOptions.emitters;\n this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(this.emitters)) {\n for (const emitterOptions of this.emitters) {\n await this.addEmitter(emitterOptions);\n }\n } else {\n await this.addEmitter(this.emitters);\n }\n }\n pause() {\n for (const emitter of this.array) {\n emitter.pause();\n }\n }\n play() {\n for (const emitter of this.array) {\n emitter.play();\n }\n }\n removeEmitter(emitter) {\n const index = this.array.indexOf(emitter),\n minIndex = 0,\n deleteCount = 1;\n if (index >= minIndex) {\n this.array.splice(index, deleteCount);\n }\n }\n resize() {\n for (const emitter of this.array) {\n emitter.resize();\n }\n }\n stop() {\n this.array = [];\n }\n update(delta) {\n for (const emitter of this.array) {\n emitter.update(delta);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Emitters.js?\n}");
|
|
37
|
+
|
|
38
|
+
/***/ },
|
|
39
|
+
|
|
40
|
+
/***/ "./dist/browser/EmittersPlugin.js"
|
|
41
|
+
/*!****************************************!*\
|
|
42
|
+
!*** ./dist/browser/EmittersPlugin.js ***!
|
|
43
|
+
\****************************************/
|
|
44
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
45
|
+
|
|
46
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmittersPlugin: () => (/* binding */ EmittersPlugin)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\n/* harmony import */ var _Emitters_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Emitters.js */ \"./dist/browser/Emitters.js\");\n\n\n\n\nclass EmittersPlugin {\n constructor(engine) {\n this._engine = engine;\n this.id = \"emitters\";\n }\n getPlugin(container) {\n return Promise.resolve(new _Emitters_js__WEBPACK_IMPORTED_MODULE_3__.Emitters(this._engine, container));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n if (source?.emitters) {\n options.emitters = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(source.emitters, emitter => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitter);\n return tmp;\n });\n }\n const interactivityEmitters = source?.interactivity?.modes?.emitters;\n if (interactivityEmitters) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(interactivityEmitters)) {\n options.interactivity.modes.emitters = {\n random: {\n count: 1,\n enable: true\n },\n value: interactivityEmitters.map(s => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(s);\n return tmp;\n })\n };\n } else {\n const emitterMode = interactivityEmitters;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(emitterMode.value)) {\n options.interactivity.modes.emitters = {\n random: {\n count: emitterMode.random.count,\n enable: emitterMode.random.enable\n },\n value: emitterMode.value.map(s => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(s);\n return tmp;\n })\n };\n } else {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitterMode.value);\n options.interactivity.modes.emitters = {\n random: {\n count: emitterMode.random.count,\n enable: emitterMode.random.enable\n },\n value: tmp\n };\n }\n }\n }\n }\n needsPlugin(options) {\n if (!options) {\n return false;\n }\n const emitters = options.emitters;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(emitters) && !!emitters.length || emitters !== undefined || !!options.interactivity?.events?.onClick?.mode && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(_Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__.EmitterClickMode.emitter, options.interactivity.events.onClick.mode);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmittersPlugin.js?\n}");
|
|
47
|
+
|
|
48
|
+
/***/ },
|
|
49
|
+
|
|
50
|
+
/***/ "./dist/browser/Options/Classes/Emitter.js"
|
|
51
|
+
/*!*************************************************!*\
|
|
52
|
+
!*** ./dist/browser/Options/Classes/Emitter.js ***!
|
|
53
|
+
\*************************************************/
|
|
54
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
55
|
+
|
|
56
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Emitter: () => (/* binding */ Emitter)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _EmitterLife_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EmitterLife.js */ \"./dist/browser/Options/Classes/EmitterLife.js\");\n/* harmony import */ var _EmitterRate_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./EmitterRate.js */ \"./dist/browser/Options/Classes/EmitterRate.js\");\n/* harmony import */ var _EmitterShape_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EmitterShape.js */ \"./dist/browser/Options/Classes/EmitterShape.js\");\n/* harmony import */ var _EmitterSize_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./EmitterSize.js */ \"./dist/browser/Options/Classes/EmitterSize.js\");\n\n\n\n\n\nclass Emitter {\n constructor() {\n this.autoPlay = true;\n this.fill = true;\n this.life = new _EmitterLife_js__WEBPACK_IMPORTED_MODULE_1__.EmitterLife();\n this.rate = new _EmitterRate_js__WEBPACK_IMPORTED_MODULE_2__.EmitterRate();\n this.shape = new _EmitterShape_js__WEBPACK_IMPORTED_MODULE_3__.EmitterShape();\n this.startCount = 0;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.autoPlay !== undefined) {\n this.autoPlay = data.autoPlay;\n }\n if (data.size !== undefined) {\n this.size ??= new _EmitterSize_js__WEBPACK_IMPORTED_MODULE_4__.EmitterSize();\n this.size.load(data.size);\n }\n if (data.direction !== undefined) {\n this.direction = data.direction;\n }\n this.domId = data.domId;\n if (data.fill !== undefined) {\n this.fill = data.fill;\n }\n this.life.load(data.life);\n this.name = data.name;\n this.particles = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(data.particles, particles => {\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, particles);\n });\n this.rate.load(data.rate);\n this.shape.load(data.shape);\n if (data.position !== undefined) {\n this.position = {};\n if (data.position.x !== undefined) {\n this.position.x = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.position.x);\n }\n if (data.position.y !== undefined) {\n this.position.y = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.position.y);\n }\n }\n if (data.spawnColor !== undefined) {\n this.spawnColor ??= new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimatableColor();\n this.spawnColor.load(data.spawnColor);\n }\n if (data.startCount !== undefined) {\n this.startCount = data.startCount;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Options/Classes/Emitter.js?\n}");
|
|
57
|
+
|
|
58
|
+
/***/ },
|
|
59
|
+
|
|
60
|
+
/***/ "./dist/browser/Options/Classes/EmitterLife.js"
|
|
61
|
+
/*!*****************************************************!*\
|
|
62
|
+
!*** ./dist/browser/Options/Classes/EmitterLife.js ***!
|
|
63
|
+
\*****************************************************/
|
|
64
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
65
|
+
|
|
66
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterLife: () => (/* binding */ EmitterLife)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass EmitterLife {\n constructor() {\n this.wait = false;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.count !== undefined) {\n this.count = data.count;\n }\n if (data.delay !== undefined) {\n this.delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.delay);\n }\n if (data.duration !== undefined) {\n this.duration = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.duration);\n }\n if (data.wait !== undefined) {\n this.wait = data.wait;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Options/Classes/EmitterLife.js?\n}");
|
|
67
|
+
|
|
68
|
+
/***/ },
|
|
69
|
+
|
|
70
|
+
/***/ "./dist/browser/Options/Classes/EmitterRate.js"
|
|
71
|
+
/*!*****************************************************!*\
|
|
72
|
+
!*** ./dist/browser/Options/Classes/EmitterRate.js ***!
|
|
73
|
+
\*****************************************************/
|
|
74
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
75
|
+
|
|
76
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterRate: () => (/* binding */ EmitterRate)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass EmitterRate {\n constructor() {\n this.quantity = 1;\n this.delay = 0.1;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.quantity !== undefined) {\n this.quantity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.quantity);\n }\n if (data.delay !== undefined) {\n this.delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.setRangeValue)(data.delay);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Options/Classes/EmitterRate.js?\n}");
|
|
77
|
+
|
|
78
|
+
/***/ },
|
|
79
|
+
|
|
80
|
+
/***/ "./dist/browser/Options/Classes/EmitterShape.js"
|
|
81
|
+
/*!******************************************************!*\
|
|
82
|
+
!*** ./dist/browser/Options/Classes/EmitterShape.js ***!
|
|
83
|
+
\******************************************************/
|
|
84
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
85
|
+
|
|
86
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterShape: () => (/* binding */ EmitterShape)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _EmitterShapeReplace_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./EmitterShapeReplace.js */ \"./dist/browser/Options/Classes/EmitterShapeReplace.js\");\n\n\nclass EmitterShape {\n constructor() {\n this.options = {};\n this.replace = new _EmitterShapeReplace_js__WEBPACK_IMPORTED_MODULE_1__.EmitterShapeReplace();\n this.type = \"square\";\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.options !== undefined) {\n this.options = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, data.options ?? {});\n }\n this.replace.load(data.replace);\n if (data.type !== undefined) {\n this.type = data.type;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Options/Classes/EmitterShape.js?\n}");
|
|
87
|
+
|
|
88
|
+
/***/ },
|
|
89
|
+
|
|
90
|
+
/***/ "./dist/browser/Options/Classes/EmitterShapeReplace.js"
|
|
91
|
+
/*!*************************************************************!*\
|
|
92
|
+
!*** ./dist/browser/Options/Classes/EmitterShapeReplace.js ***!
|
|
93
|
+
\*************************************************************/
|
|
94
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
95
|
+
|
|
96
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterShapeReplace: () => (/* binding */ EmitterShapeReplace)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass EmitterShapeReplace {\n constructor() {\n this.color = false;\n this.opacity = false;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.color !== undefined) {\n this.color = data.color;\n }\n if (data.opacity !== undefined) {\n this.opacity = data.opacity;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Options/Classes/EmitterShapeReplace.js?\n}");
|
|
97
|
+
|
|
98
|
+
/***/ },
|
|
99
|
+
|
|
100
|
+
/***/ "./dist/browser/Options/Classes/EmitterSize.js"
|
|
101
|
+
/*!*****************************************************!*\
|
|
102
|
+
!*** ./dist/browser/Options/Classes/EmitterSize.js ***!
|
|
103
|
+
\*****************************************************/
|
|
104
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
105
|
+
|
|
106
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterSize: () => (/* binding */ EmitterSize)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass EmitterSize {\n constructor() {\n this.mode = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.percent;\n this.height = 0;\n this.width = 0;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.mode !== undefined) {\n this.mode = data.mode;\n }\n if (data.height !== undefined) {\n this.height = data.height;\n }\n if (data.width !== undefined) {\n this.width = data.width;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Options/Classes/EmitterSize.js?\n}");
|
|
107
|
+
|
|
108
|
+
/***/ }
|
|
109
|
+
|
|
110
|
+
}]);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.1
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_emitters"] = this["webpackChunk_tsparticles_plugin_emitters"] || []).push([["dist_browser_ShapeManager_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/ShapeManager.js"
|
|
21
|
+
/*!**************************************!*\
|
|
22
|
+
!*** ./dist/browser/ShapeManager.js ***!
|
|
23
|
+
\**************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ShapeManager: () => (/* binding */ ShapeManager)\n/* harmony export */ });\nconst shapeGeneratorss = new Map();\nclass ShapeManager {\n addShapeGenerator(name, generator) {\n if (!this.getShapeGenerator(name)) {\n shapeGeneratorss.set(name, generator);\n }\n }\n getShapeGenerator(name) {\n return shapeGeneratorss.get(name);\n }\n getSupportedShapeGenerators() {\n return shapeGeneratorss.keys();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/ShapeManager.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ }
|
|
29
|
+
|
|
30
|
+
}]);
|
package/esm/EmitterInstance.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PixelMode, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, millisecondsToSeconds,
|
|
1
|
+
import { PixelMode, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, hMax, half, isPointInside, itemFromSingleOrMultiple, lMax, millisecondsToSeconds, randomInRangeValue, rangeColorToHsl, sMax, safeDocument, } from "@tsparticles/engine";
|
|
2
2
|
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
3
|
import { EmitterSize } from "./Options/Classes/EmitterSize.js";
|
|
4
|
-
const
|
|
4
|
+
const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1;
|
|
5
5
|
function setParticlesOptionsColor(particlesOptions, color) {
|
|
6
6
|
if (particlesOptions.color) {
|
|
7
7
|
particlesOptions.color.value = color;
|
|
@@ -33,7 +33,7 @@ export class EmitterInstance {
|
|
|
33
33
|
if (this._paused) {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
const duration = this.options.life
|
|
36
|
+
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
37
37
|
if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
|
|
38
38
|
this._duration = duration * millisecondsToSeconds;
|
|
39
39
|
}
|
|
@@ -43,9 +43,9 @@ export class EmitterInstance {
|
|
|
43
43
|
if (!animation.enable) {
|
|
44
44
|
return initValue;
|
|
45
45
|
}
|
|
46
|
-
const colorOffset =
|
|
46
|
+
const colorOffset = randomInRangeValue(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = container.retina.reduceFactor
|
|
47
47
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
48
|
-
: Infinity,
|
|
48
|
+
: Infinity, colorSpeed = getRangeValue(animation.speed);
|
|
49
49
|
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
|
|
50
50
|
};
|
|
51
51
|
this._engine = engine;
|
|
@@ -69,8 +69,7 @@ export class EmitterInstance {
|
|
|
69
69
|
this.fill = this.options.fill;
|
|
70
70
|
this._firstSpawn = !this.options.life.wait;
|
|
71
71
|
this._startParticlesAdded = false;
|
|
72
|
-
|
|
73
|
-
particlesOptions ??= {};
|
|
72
|
+
const particlesOptions = deepExtend({}, this.options.particles);
|
|
74
73
|
particlesOptions.move ??= {};
|
|
75
74
|
particlesOptions.move.direction ??= this.options.direction;
|
|
76
75
|
if (this.options.spawnColor) {
|
|
@@ -83,7 +82,7 @@ export class EmitterInstance {
|
|
|
83
82
|
this._lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
84
83
|
this._immortal = this._lifeCount <= minLifeCount;
|
|
85
84
|
if (this.options.domId) {
|
|
86
|
-
const element =
|
|
85
|
+
const element = safeDocument().getElementById(this.options.domId);
|
|
87
86
|
if (element) {
|
|
88
87
|
this._mutationObserver = new MutationObserver(() => {
|
|
89
88
|
this.resize();
|
|
@@ -217,7 +216,7 @@ export class EmitterInstance {
|
|
|
217
216
|
_calcPosition() {
|
|
218
217
|
const container = this.container;
|
|
219
218
|
if (this.options.domId) {
|
|
220
|
-
const element =
|
|
219
|
+
const element = safeDocument().getElementById(this.options.domId);
|
|
221
220
|
if (element) {
|
|
222
221
|
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio;
|
|
223
222
|
return {
|
|
@@ -234,7 +233,7 @@ export class EmitterInstance {
|
|
|
234
233
|
_calcSize() {
|
|
235
234
|
const container = this.container;
|
|
236
235
|
if (this.options.domId) {
|
|
237
|
-
const element =
|
|
236
|
+
const element = safeDocument().getElementById(this.options.domId);
|
|
238
237
|
if (element) {
|
|
239
238
|
const elRect = element.getBoundingClientRect();
|
|
240
239
|
return {
|
|
@@ -270,9 +269,9 @@ export class EmitterInstance {
|
|
|
270
269
|
const hslAnimation = this.options.spawnColor?.animation;
|
|
271
270
|
if (hslAnimation) {
|
|
272
271
|
const maxValues = {
|
|
273
|
-
h:
|
|
274
|
-
s:
|
|
275
|
-
l:
|
|
272
|
+
h: hMax,
|
|
273
|
+
s: sMax,
|
|
274
|
+
l: lMax,
|
|
276
275
|
}, colorFactor = 3.6;
|
|
277
276
|
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
|
|
278
277
|
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
|
package/esm/Emitters.js
CHANGED
|
@@ -48,12 +48,12 @@ export class Emitters {
|
|
|
48
48
|
return emitter;
|
|
49
49
|
}
|
|
50
50
|
handleClickMode(mode) {
|
|
51
|
-
const
|
|
51
|
+
const modeEmitters = this.interactivityEmitters;
|
|
52
52
|
if (mode !== EmitterClickMode.emitter) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
let emittersModeOptions;
|
|
56
|
-
if (
|
|
56
|
+
if (isArray(modeEmitters.value)) {
|
|
57
57
|
const minLength = 0;
|
|
58
58
|
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {
|
|
59
59
|
emittersModeOptions = [];
|
|
@@ -65,7 +65,11 @@ export class Emitters {
|
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
67
|
usedIndexes.push(idx);
|
|
68
|
-
|
|
68
|
+
const selectedOptions = itemFromArray(modeEmitters.value, idx);
|
|
69
|
+
if (!selectedOptions) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
emittersModeOptions.push(selectedOptions);
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
@@ -73,9 +77,9 @@ export class Emitters {
|
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
else {
|
|
76
|
-
emittersModeOptions = modeEmitters
|
|
80
|
+
emittersModeOptions = modeEmitters.value;
|
|
77
81
|
}
|
|
78
|
-
const emittersOptions = emittersModeOptions
|
|
82
|
+
const emittersOptions = emittersModeOptions, ePosition = this.container.interactivity.mouse.clickPosition;
|
|
79
83
|
void executeOnSingleOrMultiple(emittersOptions, async (emitter) => {
|
|
80
84
|
await this.addEmitter(emitter, ePosition);
|
|
81
85
|
});
|
|
@@ -83,9 +87,6 @@ export class Emitters {
|
|
|
83
87
|
async init() {
|
|
84
88
|
this.emitters = this.container.actualOptions.emitters;
|
|
85
89
|
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
|
|
86
|
-
if (!this.emitters) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
90
|
if (isArray(this.emitters)) {
|
|
90
91
|
for (const emitterOptions of this.emitters) {
|
|
91
92
|
await this.addEmitter(emitterOptions);
|
package/esm/EmittersPlugin.js
CHANGED
|
@@ -38,42 +38,29 @@ export class EmittersPlugin {
|
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
const emitterMode = interactivityEmitters;
|
|
41
|
-
if (emitterMode.value
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const tmp = new Emitter();
|
|
58
|
-
tmp.load(emitterMode.value);
|
|
59
|
-
options.interactivity.modes.emitters = {
|
|
60
|
-
random: {
|
|
61
|
-
count: emitterMode.random.count ?? defaultCount,
|
|
62
|
-
enable: emitterMode.random.enable ?? false,
|
|
63
|
-
},
|
|
64
|
-
value: tmp,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
41
|
+
if (isArray(emitterMode.value)) {
|
|
42
|
+
options.interactivity.modes.emitters = {
|
|
43
|
+
random: {
|
|
44
|
+
count: emitterMode.random.count,
|
|
45
|
+
enable: emitterMode.random.enable,
|
|
46
|
+
},
|
|
47
|
+
value: emitterMode.value.map(s => {
|
|
48
|
+
const tmp = new Emitter();
|
|
49
|
+
tmp.load(s);
|
|
50
|
+
return tmp;
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
67
53
|
}
|
|
68
54
|
else {
|
|
69
|
-
const
|
|
55
|
+
const tmp = new Emitter();
|
|
56
|
+
tmp.load(emitterMode.value);
|
|
57
|
+
options.interactivity.modes.emitters = {
|
|
70
58
|
random: {
|
|
71
|
-
count:
|
|
72
|
-
enable:
|
|
59
|
+
count: emitterMode.random.count,
|
|
60
|
+
enable: emitterMode.random.enable,
|
|
73
61
|
},
|
|
74
|
-
value:
|
|
75
|
-
}
|
|
76
|
-
emitterOptions.value.load(interactivityEmitters);
|
|
62
|
+
value: tmp,
|
|
63
|
+
};
|
|
77
64
|
}
|
|
78
65
|
}
|
|
79
66
|
}
|
|
@@ -20,9 +20,7 @@ export class Emitter {
|
|
|
20
20
|
this.autoPlay = data.autoPlay;
|
|
21
21
|
}
|
|
22
22
|
if (data.size !== undefined) {
|
|
23
|
-
|
|
24
|
-
this.size = new EmitterSize();
|
|
25
|
-
}
|
|
23
|
+
this.size ??= new EmitterSize();
|
|
26
24
|
this.size.load(data.size);
|
|
27
25
|
}
|
|
28
26
|
if (data.direction !== undefined) {
|
|
@@ -49,9 +47,7 @@ export class Emitter {
|
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
if (data.spawnColor !== undefined) {
|
|
52
|
-
|
|
53
|
-
this.spawnColor = new AnimatableColor();
|
|
54
|
-
}
|
|
50
|
+
this.spawnColor ??= new AnimatableColor();
|
|
55
51
|
this.spawnColor.load(data.spawnColor);
|
|
56
52
|
}
|
|
57
53
|
if (data.startCount !== undefined) {
|
package/esm/ShapeManager.js
CHANGED
package/esm/index.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!engine.addEmitterShapeGenerator) {
|
|
9
|
-
engine.addEmitterShapeGenerator = (name, generator) => {
|
|
10
|
-
engine.emitterShapeManager?.addShapeGenerator(name, generator);
|
|
1
|
+
export function loadEmittersPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.1");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { ShapeManager } = await import("./ShapeManager.js"), { EmittersPlugin } = await import("./EmittersPlugin.js");
|
|
5
|
+
e.emitterShapeManager ??= new ShapeManager();
|
|
6
|
+
e.addEmitterShapeGenerator ??= (name, generator) => {
|
|
7
|
+
e.emitterShapeManager?.addShapeGenerator(name, generator);
|
|
11
8
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const plugin = new EmittersPlugin(e);
|
|
10
|
+
e.addPlugin(plugin);
|
|
11
|
+
});
|
|
15
12
|
}
|
|
16
|
-
export * from "./EmitterContainer.js";
|
|
17
13
|
export * from "./EmitterShapeBase.js";
|
|
18
|
-
export * from "./EmittersEngine.js";
|
|
19
|
-
export * from "./IEmitterShape.js";
|
|
20
|
-
export * from "./IEmitterShapeGenerator.js";
|
|
21
14
|
export * from "./Enums/EmitterClickMode.js";
|
|
22
|
-
export * from "./IRandomPositionData.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-emitters",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "tsParticles emitters plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -86,9 +86,10 @@
|
|
|
86
86
|
"./package.json": "./package.json"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@tsparticles/engine": "
|
|
89
|
+
"@tsparticles/engine": "4.0.0-alpha.1"
|
|
90
90
|
},
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
|
-
}
|
|
93
|
+
},
|
|
94
|
+
"type": "module"
|
|
94
95
|
}
|