@tsparticles/plugin-sounds 3.0.3 → 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.
Files changed (55) hide show
  1. package/265.min.js +2 -0
  2. package/265.min.js.LICENSE.txt +1 -0
  3. package/714.min.js +2 -0
  4. package/714.min.js.LICENSE.txt +1 -0
  5. package/browser/Options/Classes/Sounds.js +4 -0
  6. package/browser/Options/Classes/SoundsEvent.js +4 -3
  7. package/browser/Options/Classes/SoundsIcon.js +1 -0
  8. package/browser/Options/Classes/SoundsIcons.js +4 -0
  9. package/browser/SoundsInstance.js +130 -69
  10. package/browser/SoundsPlugin.js +37 -0
  11. package/browser/index.js +1 -24
  12. package/browser/utils.js +11 -4
  13. package/cjs/Options/Classes/Sounds.js +4 -0
  14. package/cjs/Options/Classes/SoundsEvent.js +4 -3
  15. package/cjs/Options/Classes/SoundsIcon.js +1 -0
  16. package/cjs/Options/Classes/SoundsIcons.js +4 -0
  17. package/cjs/SoundsInstance.js +128 -67
  18. package/cjs/SoundsPlugin.js +64 -0
  19. package/cjs/index.js +24 -24
  20. package/cjs/utils.js +14 -5
  21. package/dist_browser_SoundsInstance_js.js +30 -0
  22. package/dist_browser_SoundsPlugin_js.js +120 -0
  23. package/esm/Options/Classes/Sounds.js +4 -0
  24. package/esm/Options/Classes/SoundsEvent.js +4 -3
  25. package/esm/Options/Classes/SoundsIcon.js +1 -0
  26. package/esm/Options/Classes/SoundsIcons.js +4 -0
  27. package/esm/SoundsInstance.js +130 -69
  28. package/esm/SoundsPlugin.js +37 -0
  29. package/esm/index.js +1 -24
  30. package/esm/utils.js +11 -4
  31. package/package.json +2 -2
  32. package/report.html +3 -3
  33. package/tsparticles.plugin.sounds.js +241 -738
  34. package/tsparticles.plugin.sounds.min.js +1 -1
  35. package/tsparticles.plugin.sounds.min.js.LICENSE.txt +1 -1
  36. package/types/Options/Classes/Sounds.d.ts +1 -0
  37. package/types/Options/Classes/SoundsEvent.d.ts +0 -5
  38. package/types/Options/Classes/SoundsIcon.d.ts +1 -0
  39. package/types/Options/Classes/SoundsIcons.d.ts +1 -0
  40. package/types/Options/Interfaces/ISounds.d.ts +1 -0
  41. package/types/Options/Interfaces/ISoundsIcon.d.ts +1 -0
  42. package/types/Options/Interfaces/ISoundsIcons.d.ts +1 -0
  43. package/types/SoundsInstance.d.ts +6 -0
  44. package/types/SoundsPlugin.d.ts +11 -0
  45. package/types/index.d.ts +1 -1
  46. package/types/types.d.ts +5 -5
  47. package/types/utils.d.ts +2 -0
  48. package/umd/Options/Classes/Sounds.js +4 -0
  49. package/umd/Options/Classes/SoundsEvent.js +4 -3
  50. package/umd/Options/Classes/SoundsIcon.js +1 -0
  51. package/umd/Options/Classes/SoundsIcons.js +4 -0
  52. package/umd/SoundsInstance.js +128 -67
  53. package/umd/SoundsPlugin.js +75 -0
  54. package/umd/index.js +26 -25
  55. package/umd/utils.js +14 -5
@@ -0,0 +1,120 @@
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
+ * v3.2.0
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_sounds"] = this["webpackChunk_tsparticles_plugin_sounds"] || []).push([["dist_browser_SoundsPlugin_js"],{
19
+
20
+ /***/ "./dist/browser/Options/Classes/Sounds.js":
21
+ /*!************************************************!*\
22
+ !*** ./dist/browser/Options/Classes/Sounds.js ***!
23
+ \************************************************/
24
+ /***/ ((__unused_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 */ Sounds: () => (/* binding */ Sounds)\n/* harmony export */ });\n/* harmony import */ var _SoundsEvent_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SoundsEvent.js */ \"./dist/browser/Options/Classes/SoundsEvent.js\");\n/* harmony import */ var _SoundsIcons_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./SoundsIcons.js */ \"./dist/browser/Options/Classes/SoundsIcons.js\");\n/* harmony import */ var _SoundsVolume_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./SoundsVolume.js */ \"./dist/browser/Options/Classes/SoundsVolume.js\");\n\n\n\nclass Sounds {\n constructor() {\n this.autoPlay = true;\n this.enable = false;\n this.events = [];\n this.icons = new _SoundsIcons_js__WEBPACK_IMPORTED_MODULE_0__.SoundsIcons();\n this.volume = new _SoundsVolume_js__WEBPACK_IMPORTED_MODULE_1__.SoundsVolume();\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.autoPlay !== undefined) {\n this.autoPlay = data.autoPlay;\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n if (data.events !== undefined) {\n this.events = data.events.map(t => {\n const event = new _SoundsEvent_js__WEBPACK_IMPORTED_MODULE_2__.SoundsEvent();\n event.load(t);\n return event;\n });\n }\n this.icons.load(data.icons);\n if (data.volume !== undefined) {\n this.volume.load(data.volume);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/Sounds.js?");
27
+
28
+ /***/ }),
29
+
30
+ /***/ "./dist/browser/Options/Classes/SoundsAudio.js":
31
+ /*!*****************************************************!*\
32
+ !*** ./dist/browser/Options/Classes/SoundsAudio.js ***!
33
+ \*****************************************************/
34
+ /***/ ((__unused_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 */ SoundsAudio: () => (/* binding */ SoundsAudio)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass SoundsAudio {\n constructor() {\n this.loop = false;\n this.source = \"\";\n }\n load(data) {\n if (data === undefined) {\n return;\n }\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isObject)(data)) {\n if (data.loop !== undefined) {\n this.loop = data.loop;\n }\n if (data.source !== undefined) {\n this.source = data.source;\n }\n } else {\n this.source = data;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsAudio.js?");
37
+
38
+ /***/ }),
39
+
40
+ /***/ "./dist/browser/Options/Classes/SoundsEvent.js":
41
+ /*!*****************************************************!*\
42
+ !*** ./dist/browser/Options/Classes/SoundsEvent.js ***!
43
+ \*****************************************************/
44
+ /***/ ((__unused_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 */ SoundsEvent: () => (/* binding */ SoundsEvent)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _SoundsAudio_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./SoundsAudio.js */ \"./dist/browser/Options/Classes/SoundsAudio.js\");\n/* harmony import */ var _SoundsMelody_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./SoundsMelody.js */ \"./dist/browser/Options/Classes/SoundsMelody.js\");\n/* harmony import */ var _SoundsNote_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SoundsNote.js */ \"./dist/browser/Options/Classes/SoundsNote.js\");\n\n\n\n\nclass SoundsEvent {\n constructor() {\n this.event = [];\n this.notes = [];\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.event !== undefined) {\n this.event = data.event;\n }\n if (data.audio !== undefined) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(data.audio)) {\n this.audio = data.audio.map(s => {\n const tmp = new _SoundsAudio_js__WEBPACK_IMPORTED_MODULE_1__.SoundsAudio();\n tmp.load(s);\n return tmp;\n });\n } else {\n this.audio = new _SoundsAudio_js__WEBPACK_IMPORTED_MODULE_1__.SoundsAudio();\n this.audio.load(data.audio);\n }\n }\n if (data.notes !== undefined) {\n this.notes = data.notes.map(t => {\n const tmp = new _SoundsNote_js__WEBPACK_IMPORTED_MODULE_2__.SoundsNote();\n tmp.load(t);\n return tmp;\n });\n }\n if (data.melodies !== undefined) {\n this.melodies = data.melodies.map(t => {\n const tmp = new _SoundsMelody_js__WEBPACK_IMPORTED_MODULE_3__.SoundsMelody();\n tmp.load(t);\n return tmp;\n });\n }\n if (data.filter) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isString)(data.filter)) {\n const filterFunc = window[data.filter];\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isFunction)(filterFunc)) {\n this.filter = filterFunc;\n }\n } else {\n this.filter = data.filter;\n }\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsEvent.js?");
47
+
48
+ /***/ }),
49
+
50
+ /***/ "./dist/browser/Options/Classes/SoundsIcon.js":
51
+ /*!****************************************************!*\
52
+ !*** ./dist/browser/Options/Classes/SoundsIcon.js ***!
53
+ \****************************************************/
54
+ /***/ ((__unused_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 */ SoundsIcon: () => (/* binding */ SoundsIcon)\n/* harmony export */ });\nclass SoundsIcon {\n constructor() {\n this.width = 24;\n this.height = 24;\n this.style = \"\";\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.path !== undefined) {\n this.path = data.path;\n }\n if (data.svg !== undefined) {\n this.svg = data.svg;\n }\n if (data.width !== undefined) {\n this.width = data.width;\n }\n if (data.height !== undefined) {\n this.height = data.height;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsIcon.js?");
57
+
58
+ /***/ }),
59
+
60
+ /***/ "./dist/browser/Options/Classes/SoundsIcons.js":
61
+ /*!*****************************************************!*\
62
+ !*** ./dist/browser/Options/Classes/SoundsIcons.js ***!
63
+ \*****************************************************/
64
+ /***/ ((__unused_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 */ SoundsIcons: () => (/* binding */ SoundsIcons)\n/* harmony export */ });\n/* harmony import */ var _SoundsIcon_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./SoundsIcon.js */ \"./dist/browser/Options/Classes/SoundsIcon.js\");\n\nclass SoundsIcons {\n constructor() {\n this.mute = new _SoundsIcon_js__WEBPACK_IMPORTED_MODULE_0__.SoundsIcon();\n this.unmute = new _SoundsIcon_js__WEBPACK_IMPORTED_MODULE_0__.SoundsIcon();\n this.volumeDown = new _SoundsIcon_js__WEBPACK_IMPORTED_MODULE_0__.SoundsIcon();\n this.volumeUp = new _SoundsIcon_js__WEBPACK_IMPORTED_MODULE_0__.SoundsIcon();\n this.enable = false;\n this.mute.svg = `<?xml version=\"1.0\"?>\n<svg baseProfile=\"tiny\" height=\"24px\" version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24px\"\n xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <g id=\"Layer_1\">\n <path fill=\"#fff\" d=\"M19.707,5.293c-0.391-0.391-1.023-0.391-1.414,0l-1.551,1.551c-0.345-0.688-0.987-1.02-1.604-1.02c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C10.357,8.561,8.904,9,8,9c-1.654,0-3,1.346-3,3v2c0,1.237,0.754,2.302,1.826,2.76l-1.533,1.533c-0.391,0.391-0.391,1.023,0,1.414C5.488,19.902,5.744,20,6,20s0.512-0.098,0.707-0.293l2.527-2.527c0.697,0.174,1.416,0.455,1.875,0.762l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C16.035,20.176,17,19.495,17,18V9.414l2.707-2.707C20.098,6.316,20.098,5.684,19.707,5.293z M14.891,7.941c0.038-0.025,0.073-0.046,0.104-0.062C14.998,7.914,15,7.954,15,8v1.293l-2,2V9.202L14.891,7.941z M7,12c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v2.439l-2.83,2.83C8.757,15.046,8.356,15,8,15c-0.552,0-1-0.448-1-1V12z M10.301,15.406L12,13.707v2.439C11.519,15.859,10.925,15.604,10.301,15.406z M14.994,18.12c-0.03-0.016-0.065-0.036-0.104-0.062L13,16.798v-4.091l2-2V18C15,18.046,14.998,18.086,14.994,18.12z\"/>\n </g>\n</svg>`;\n this.unmute.svg = `<?xml version=\"1.0\"?>\n<svg baseProfile=\"tiny\" height=\"24px\" version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24px\"\n xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <g id=\"Layer_1\">\n <path fill=\"#fff\" d=\"M17.138,5.824c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C12.357,8.561,10.904,9,10,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C18.035,20.176,19,19.495,19,18V8C19,6.505,18.035,5.824,17.138,5.824z M14,16.146C12.907,15.495,11.211,15,10,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146V16.146z M17,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L15,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C16.998,7.914,17,7.954,17,8V18z\"/>\n </g>\n</svg>`;\n this.volumeDown.svg = `<?xml version=\"1.0\"?>\n<svg baseProfile=\"tiny\" height=\"24px\" version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24px\"\n xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <g id=\"Layer_1\">\n <path fill=\"#fff\" d=\"M15.138,5.824c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C10.357,8.561,8.904,9,8,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C16.035,20.176,17,19.495,17,18V8C17,6.505,16.035,5.824,15.138,5.824z M8,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v6.293C10.907,15.495,9.211,15,8,15z M15,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L13,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C14.998,7.914,15,7.954,15,8V18z\"/>\n <path fill=\"#fff\" d=\"M18.292,10.294c-0.39,0.391-0.39,1.023,0.002,1.414c0.345,0.345,0.535,0.803,0.535,1.291c0,0.489-0.19,0.948-0.536,1.294c-0.391,0.39-0.391,1.023,0,1.414C18.488,15.902,18.744,16,19,16s0.512-0.098,0.707-0.293c0.724-0.723,1.122-1.685,1.122-2.708s-0.398-1.984-1.123-2.707C19.317,9.903,18.683,9.901,18.292,10.294z\"/>\n </g>\n</svg>`;\n this.volumeUp.svg = `<?xml version=\"1.0\"?>\n<svg baseProfile=\"tiny\" height=\"24px\" version=\"1.2\" viewBox=\"0 0 24 24\" width=\"24px\"\n xml:space=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <g id=\"Layer_1\">\n <path fill=\"#fff\" d=\"M16.706,10.292c-0.389-0.389-1.023-0.391-1.414,0.002c-0.39,0.391-0.39,1.023,0.002,1.414c0.345,0.345,0.535,0.803,0.535,1.291c0,0.489-0.19,0.948-0.536,1.294c-0.391,0.39-0.391,1.023,0,1.414C15.488,15.902,15.744,16,16,16s0.512-0.098,0.707-0.293c0.724-0.723,1.122-1.685,1.122-2.708S17.431,11.015,16.706,10.292z\"/>\n <path fill=\"#fff\" d=\"M18.706,8.292c-0.391-0.389-1.023-0.39-1.414,0.002c-0.39,0.391-0.39,1.024,0.002,1.414c0.879,0.877,1.363,2.044,1.364,3.287c0.001,1.246-0.484,2.417-1.365,3.298c-0.391,0.391-0.391,1.023,0,1.414C17.488,17.902,17.744,18,18,18s0.512-0.098,0.707-0.293c1.259-1.259,1.952-2.933,1.951-4.713C20.657,11.217,19.964,9.547,18.706,8.292z\"/>\n <path fill=\"#fff\" d=\"M20.706,6.292c-0.391-0.389-1.023-0.39-1.414,0.002c-0.39,0.391-0.39,1.024,0.002,1.414c1.412,1.409,2.191,3.285,2.192,5.284c0.002,2.002-0.777,3.885-2.193,5.301c-0.391,0.391-0.391,1.023,0,1.414C19.488,19.902,19.744,20,20,20s0.512-0.098,0.707-0.293c1.794-1.794,2.781-4.18,2.779-6.717C23.485,10.457,22.497,8.078,20.706,6.292z\"/>\n <path fill=\"#fff\" d=\"M12.138,5.824c-0.449,0-0.905,0.152-1.356,0.453L8.109,8.059C7.357,8.561,5.904,9,5,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C13.035,20.176,14,19.495,14,18V8C14,6.505,13.035,5.824,12.138,5.824z M5,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v6.293C7.907,15.495,6.211,15,5,15z M12,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L10,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C11.998,7.914,12,7.954,12,8V18z\"/>\n </g>\n</svg>`;\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n this.mute.load(data.mute);\n this.unmute.load(data.unmute);\n this.volumeDown.load(data.volumeDown);\n this.volumeUp.load(data.volumeUp);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsIcons.js?");
67
+
68
+ /***/ }),
69
+
70
+ /***/ "./dist/browser/Options/Classes/SoundsMelody.js":
71
+ /*!******************************************************!*\
72
+ !*** ./dist/browser/Options/Classes/SoundsMelody.js ***!
73
+ \******************************************************/
74
+ /***/ ((__unused_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 */ SoundsMelody: () => (/* binding */ SoundsMelody)\n/* harmony export */ });\n/* harmony import */ var _SoundsNote_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./SoundsNote.js */ \"./dist/browser/Options/Classes/SoundsNote.js\");\n\nclass SoundsMelody {\n constructor() {\n this.loop = false;\n this.melodies = [];\n this.notes = [];\n }\n load(data) {\n if (data === undefined) {\n return;\n }\n if (data.loop !== undefined) {\n this.loop = data.loop;\n }\n if (data.melodies !== undefined) {\n this.melodies = data.melodies.map(s => {\n const tmp = new SoundsMelody();\n tmp.load(s);\n return tmp;\n });\n }\n if (data.notes !== undefined) {\n this.notes = data.notes.map(s => {\n const tmp = new _SoundsNote_js__WEBPACK_IMPORTED_MODULE_0__.SoundsNote();\n tmp.load(s);\n return tmp;\n });\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsMelody.js?");
77
+
78
+ /***/ }),
79
+
80
+ /***/ "./dist/browser/Options/Classes/SoundsNote.js":
81
+ /*!****************************************************!*\
82
+ !*** ./dist/browser/Options/Classes/SoundsNote.js ***!
83
+ \****************************************************/
84
+ /***/ ((__unused_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 */ SoundsNote: () => (/* binding */ SoundsNote)\n/* harmony export */ });\nclass SoundsNote {\n constructor() {\n this.duration = 500;\n this.value = [];\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.duration !== undefined) {\n this.duration = data.duration;\n }\n if (data.value !== undefined) {\n this.value = data.value;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsNote.js?");
87
+
88
+ /***/ }),
89
+
90
+ /***/ "./dist/browser/Options/Classes/SoundsVolume.js":
91
+ /*!******************************************************!*\
92
+ !*** ./dist/browser/Options/Classes/SoundsVolume.js ***!
93
+ \******************************************************/
94
+ /***/ ((__unused_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 */ SoundsVolume: () => (/* binding */ SoundsVolume)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass SoundsVolume {\n constructor() {\n this.value = 100;\n this.max = 100;\n this.min = 0;\n this.step = 10;\n }\n load(data) {\n if (data === undefined) {\n return;\n }\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isObject)(data)) {\n if (data.max !== undefined) {\n this.max = data.max;\n }\n if (data.min !== undefined) {\n this.min = data.min;\n }\n if (data.step !== undefined) {\n this.step = data.step;\n }\n if (data.value !== undefined) {\n this.value = data.value;\n }\n } else {\n this.value = data;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/Options/Classes/SoundsVolume.js?");
97
+
98
+ /***/ }),
99
+
100
+ /***/ "./dist/browser/SoundsPlugin.js":
101
+ /*!**************************************!*\
102
+ !*** ./dist/browser/SoundsPlugin.js ***!
103
+ \**************************************/
104
+ /***/ ((__unused_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 */ SoundsPlugin: () => (/* binding */ SoundsPlugin)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Options_Classes_Sounds_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Sounds.js */ \"./dist/browser/Options/Classes/Sounds.js\");\n/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils.js */ \"./dist/browser/utils.js\");\n\n\n\nconst generalFirstClickHandler = () => {\n removeEventListener(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.mouseDownEvent, generalFirstClickHandler);\n removeEventListener(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.touchStartEvent, generalFirstClickHandler);\n (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.unmuteWindow)();\n};\nclass SoundsPlugin {\n constructor(engine) {\n this.id = \"sounds\";\n this._engine = engine;\n const listenerOptions = {\n capture: true,\n once: true\n };\n addEventListener(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.mouseDownEvent, generalFirstClickHandler, listenerOptions);\n addEventListener(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.touchStartEvent, generalFirstClickHandler, listenerOptions);\n }\n async getPlugin(container) {\n const {\n SoundsInstance\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_SoundsInstance_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./SoundsInstance.js */ \"./dist/browser/SoundsInstance.js\"));\n return new SoundsInstance(container, this._engine);\n }\n loadOptions(options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n let soundsOptions = options.sounds;\n if (soundsOptions?.load === undefined) {\n options.sounds = soundsOptions = new _Options_Classes_Sounds_js__WEBPACK_IMPORTED_MODULE_2__.Sounds();\n }\n soundsOptions.load(source?.sounds);\n }\n needsPlugin(options) {\n return options?.sounds?.enable ?? false;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/SoundsPlugin.js?");
107
+
108
+ /***/ }),
109
+
110
+ /***/ "./dist/browser/utils.js":
111
+ /*!*******************************!*\
112
+ !*** ./dist/browser/utils.js ***!
113
+ \*******************************/
114
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
115
+
116
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ getNoteFrequency: () => (/* binding */ getNoteFrequency),\n/* harmony export */ isWindowMuted: () => (/* binding */ isWindowMuted),\n/* harmony export */ unmuteWindow: () => (/* binding */ unmuteWindow)\n/* harmony export */ });\nconst notes = new Map();\nnotes.set(\"C\", [16.35, 32.7, 65.41, 130.81, 261.63, 523.25, 1046.5, 2093.0, 4186.01]);\nnotes.set(\"Db\", [17.32, 34.65, 69.3, 138.59, 277.18, 554.37, 1108.73, 2217.46, 4434.92]);\nnotes.set(\"D\", [18.35, 36.71, 73.42, 146.83, 293.66, 587.33, 1174.66, 2349.32, 4698.63]);\nnotes.set(\"Eb\", [19.45, 38.89, 77.78, 155.56, 311.13, 622.25, 1244.51, 2489.02, 4978.03]);\nnotes.set(\"E\", [20.6, 41.2, 82.41, 164.81, 329.63, 659.25, 1318.51, 2637.02, 5274.04]);\nnotes.set(\"F\", [21.83, 43.65, 87.31, 174.61, 349.23, 698.46, 1396.91, 2793.83, 5587.65]);\nnotes.set(\"Gb\", [23.12, 46.25, 92.5, 185.0, 369.99, 739.99, 1479.98, 2959.96, 5919.91]);\nnotes.set(\"G\", [24.5, 49.0, 98.0, 196.0, 392.0, 783.99, 1567.98, 3135.96, 6271.93]);\nnotes.set(\"Ab\", [25.96, 51.91, 103.83, 207.65, 415.3, 830.61, 1661.22, 3322.44, 6644.88]);\nnotes.set(\"A\", [27.5, 55.0, 110.0, 220.0, 440.0, 880.0, 1760.0, 3520.0, 7040.0]);\nnotes.set(\"Bb\", [29.14, 58.27, 116.54, 233.08, 466.16, 932.33, 1864.66, 3729.31, 7458.62]);\nnotes.set(\"B\", [30.87, 61.74, 123.47, 246.94, 493.88, 987.77, 1975.53, 3951.07, 7902.13]);\nnotes.set(\"pause\", [0]);\nfunction getNoteFrequency(note) {\n const regex = /(([A-G]b?)(\\d))|pause/i,\n result = regex.exec(note),\n groupKey = 2,\n defaultMatchKey = 0,\n innerGroupKey = 3;\n if (!result?.length) {\n return;\n }\n const noteKey = result[groupKey] || result[defaultMatchKey],\n noteItem = notes.get(noteKey);\n if (!noteItem) {\n return;\n }\n return noteItem[parseInt(result[innerGroupKey] || \"0\")];\n}\nlet muted = true;\nconst isWindowMuted = () => {\n return muted;\n};\nconst unmuteWindow = () => {\n muted = false;\n};\n\n//# sourceURL=webpack://@tsparticles/plugin-sounds/./dist/browser/utils.js?");
117
+
118
+ /***/ })
119
+
120
+ }]);
@@ -3,6 +3,7 @@ import { SoundsIcons } from "./SoundsIcons.js";
3
3
  import { SoundsVolume } from "./SoundsVolume.js";
4
4
  export class Sounds {
5
5
  constructor() {
6
+ this.autoPlay = true;
6
7
  this.enable = false;
7
8
  this.events = [];
8
9
  this.icons = new SoundsIcons();
@@ -12,6 +13,9 @@ export class Sounds {
12
13
  if (!data) {
13
14
  return;
14
15
  }
16
+ if (data.autoPlay !== undefined) {
17
+ this.autoPlay = data.autoPlay;
18
+ }
15
19
  if (data.enable !== undefined) {
16
20
  this.enable = data.enable;
17
21
  }
@@ -41,10 +41,11 @@ export class SoundsEvent {
41
41
  return tmp;
42
42
  });
43
43
  }
44
- if (data.filter !== undefined) {
44
+ if (data.filter) {
45
45
  if (isString(data.filter)) {
46
- if (isFunction(window[data.filter])) {
47
- this.filter = window[data.filter];
46
+ const filterFunc = window[data.filter];
47
+ if (isFunction(filterFunc)) {
48
+ this.filter = filterFunc;
48
49
  }
49
50
  }
50
51
  else {
@@ -2,6 +2,7 @@ export class SoundsIcon {
2
2
  constructor() {
3
3
  this.width = 24;
4
4
  this.height = 24;
5
+ this.style = "";
5
6
  }
6
7
  load(data) {
7
8
  if (!data) {
@@ -5,6 +5,7 @@ export class SoundsIcons {
5
5
  this.unmute = new SoundsIcon();
6
6
  this.volumeDown = new SoundsIcon();
7
7
  this.volumeUp = new SoundsIcon();
8
+ this.enable = false;
8
9
  this.mute.svg = `<?xml version="1.0"?>
9
10
  <svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"
10
11
  xml:space="preserve" xmlns="http://www.w3.org/2000/svg"
@@ -46,6 +47,9 @@ export class SoundsIcons {
46
47
  if (!data) {
47
48
  return;
48
49
  }
50
+ if (data.enable !== undefined) {
51
+ this.enable = data.enable;
52
+ }
49
53
  this.mute.load(data.mute);
50
54
  this.unmute.load(data.unmute);
51
55
  this.volumeDown.load(data.volumeDown);
@@ -1,12 +1,18 @@
1
- import { clamp, executeOnSingleOrMultiple, getLogger, isArray, isNumber, itemFromArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
- import { getNoteFrequency } from "./utils.js";
1
+ import { clamp, executeOnSingleOrMultiple, getLogger, isArray, isNumber, itemFromArray, itemFromSingleOrMultiple, mouseDownEvent, percentDenominator, touchStartEvent, } from "@tsparticles/engine";
2
+ import { getNoteFrequency, isWindowMuted, unmuteWindow } from "./utils.js";
3
+ const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
3
4
  function initImage(data) {
4
- const img = document.createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, svg } = iconOptions;
5
- setIconStyle(img, pos.top + margin, pos.right - (margin * (rightOffsets.length + 1) + width + rightOffsets.reduce((a, b) => a + b, 0)), display, options.fullScreen.zIndex + 1, width, margin);
5
+ const img = document.createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, style, svg } = iconOptions, defaultAccumulator = 0;
6
+ setIconStyle(img, pos.top + margin, pos.right -
7
+ (margin * (rightOffsets.length + rightOffset) +
8
+ width +
9
+ rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
6
10
  img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
7
- const parent = container.canvas.element?.parentNode || document.body;
11
+ const parent = container.canvas.element?.parentNode ?? document.body;
8
12
  parent.append(img);
9
- img.addEventListener("click", clickCb);
13
+ img.addEventListener("click", () => {
14
+ void clickCb();
15
+ });
10
16
  return img;
11
17
  }
12
18
  function removeImage(image) {
@@ -15,14 +21,15 @@ function removeImage(image) {
15
21
  }
16
22
  image.remove();
17
23
  }
18
- function setIconStyle(icon, top, left, display, zIndex, width, margin) {
24
+ function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
19
25
  icon.style.userSelect = "none";
20
26
  icon.style.webkitUserSelect = "none";
21
27
  icon.style.position = "absolute";
22
28
  icon.style.top = `${top + margin}px`;
23
29
  icon.style.left = `${left - margin - width}px`;
24
30
  icon.style.display = display;
25
- icon.style.zIndex = `${zIndex + 1}`;
31
+ icon.style.zIndex = `${zIndex + zIndexOffset}`;
32
+ icon.style.cssText += style;
26
33
  }
27
34
  export class SoundsInstance {
28
35
  constructor(container, engine) {
@@ -43,12 +50,12 @@ export class SoundsInstance {
43
50
  }
44
51
  for (const event of soundsOptions.events) {
45
52
  const cb = (args) => {
46
- (async () => {
53
+ void (async () => {
47
54
  const filterNotValid = event.filter && !event.filter(args);
48
55
  if (this._container !== args.container) {
49
56
  return;
50
57
  }
51
- if (!this._container || this._container.muted || this._container.destroyed) {
58
+ if (!this._container || !!this._container.muted || this._container.destroyed) {
52
59
  executeOnSingleOrMultiple(event.event, (item) => {
53
60
  this._engine.removeEventListener(item, cb);
54
61
  });
@@ -57,21 +64,22 @@ export class SoundsInstance {
57
64
  if (filterNotValid) {
58
65
  return;
59
66
  }
67
+ const defaultNoteIndex = 0;
60
68
  if (event.audio) {
61
69
  this._playBuffer(itemFromSingleOrMultiple(event.audio));
62
70
  }
63
71
  else if (event.melodies) {
64
72
  const melody = itemFromArray(event.melodies);
65
73
  if (melody.melodies.length) {
66
- await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes, 0, melody.loop)));
74
+ await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
67
75
  }
68
76
  else {
69
- await this._playNote(melody.notes, 0, melody.loop);
77
+ await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
70
78
  }
71
79
  }
72
80
  else if (event.notes) {
73
81
  const note = itemFromArray(event.notes);
74
- await this._playNote([note], 0, false);
82
+ await this._playNote([note], defaultNoteIndex, false);
75
83
  }
76
84
  })();
77
85
  };
@@ -80,18 +88,15 @@ export class SoundsInstance {
80
88
  });
81
89
  }
82
90
  };
83
- this._mute = () => {
84
- const container = this._container;
85
- if (!container.audioContext) {
86
- return;
87
- }
91
+ this._mute = async () => {
92
+ const container = this._container, audioContext = this._getAudioContext();
88
93
  for (const source of this._audioSources) {
89
94
  this._removeAudioSource(source);
90
95
  }
91
96
  if (this._gain) {
92
97
  this._gain.disconnect();
93
98
  }
94
- container.audioContext.close();
99
+ await audioContext.close();
95
100
  container.audioContext = undefined;
96
101
  this._engine.dispatchEvent("soundsMuted", { container: this._container });
97
102
  };
@@ -111,10 +116,10 @@ export class SoundsInstance {
111
116
  source.start();
112
117
  };
113
118
  this._playFrequency = async (frequency, duration) => {
114
- if (!this._container.audioContext || !this._gain) {
119
+ if (!this._gain || this._container.muted) {
115
120
  return;
116
121
  }
117
- const oscillator = this._addOscillator(this._container.audioContext);
122
+ const audioContext = this._getAudioContext(), oscillator = this._addOscillator(audioContext);
118
123
  oscillator.connect(this._gain);
119
124
  oscillator.type = "sine";
120
125
  oscillator.frequency.value = frequency;
@@ -127,14 +132,13 @@ export class SoundsInstance {
127
132
  });
128
133
  };
129
134
  this._playMuteSound = () => {
130
- const container = this._container;
131
- if (!container.audioContext) {
135
+ if (this._container.muted) {
132
136
  return;
133
137
  }
134
- const gain = container.audioContext.createGain();
135
- gain.connect(container.audioContext.destination);
138
+ const audioContext = this._getAudioContext(), gain = audioContext.createGain();
139
+ gain.connect(audioContext.destination);
136
140
  gain.gain.value = 0;
137
- const oscillator = container.audioContext.createOscillator();
141
+ const oscillator = audioContext.createOscillator();
138
142
  oscillator.connect(gain);
139
143
  oscillator.type = "sine";
140
144
  oscillator.frequency.value = 1;
@@ -158,7 +162,8 @@ export class SoundsInstance {
158
162
  return this._playNoteValue(notes, noteIdx, idx);
159
163
  });
160
164
  await (isArray(promises) ? Promise.allSettled(promises) : promises);
161
- let nextNoteIdx = noteIdx + 1;
165
+ const indexOffset = 1;
166
+ let nextNoteIdx = noteIdx + indexOffset;
162
167
  if (loop && nextNoteIdx >= notes.length) {
163
168
  nextNoteIdx = nextNoteIdx % notes.length;
164
169
  }
@@ -187,29 +192,31 @@ export class SoundsInstance {
187
192
  this._removeAudioSource = (source) => {
188
193
  source.stop();
189
194
  source.disconnect();
190
- this._audioSources.splice(this._audioSources.indexOf(source), 1);
195
+ const deleteCount = 1;
196
+ this._audioSources.splice(this._audioSources.indexOf(source), deleteCount);
191
197
  };
192
198
  this._unmute = () => {
193
199
  const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
194
200
  if (!soundsOptions) {
195
201
  return;
196
202
  }
197
- if (!container.audioContext) {
198
- container.audioContext = new AudioContext();
199
- }
200
- const { audioContext } = container;
203
+ const audioContext = this._getAudioContext();
201
204
  if (!this._audioSources) {
202
205
  this._audioSources = [];
203
206
  }
204
207
  const gain = audioContext.createGain();
205
208
  gain.connect(audioContext.destination);
206
- gain.gain.value = soundsOptions.volume.value / 100;
209
+ gain.gain.value = soundsOptions.volume.value / percentDenominator;
207
210
  this._gain = gain;
208
211
  this._initEvents();
209
212
  this._engine.dispatchEvent("soundsUnmuted", { container: this._container });
210
213
  };
211
214
  this._updateMuteIcons = () => {
212
- const container = this._container, muteImg = this._muteImg, unmuteImg = this._unmuteImg;
215
+ const container = this._container, soundsOptions = container.actualOptions.sounds;
216
+ if (!soundsOptions?.enable || !soundsOptions.icons.enable) {
217
+ return;
218
+ }
219
+ const muteImg = this._muteImg, unmuteImg = this._unmuteImg;
213
220
  if (muteImg) {
214
221
  muteImg.style.display = container.muted ? "block" : "none";
215
222
  }
@@ -218,13 +225,13 @@ export class SoundsInstance {
218
225
  }
219
226
  };
220
227
  this._updateMuteStatus = async () => {
221
- const container = this._container;
228
+ const container = this._container, audioContext = this._getAudioContext();
222
229
  if (container.muted) {
223
- await container.audioContext?.suspend();
224
- this._mute();
230
+ await audioContext?.suspend();
231
+ await this._mute();
225
232
  }
226
233
  else {
227
- await container.audioContext?.resume();
234
+ await audioContext?.resume();
228
235
  this._unmute();
229
236
  this._playMuteSound();
230
237
  }
@@ -236,12 +243,12 @@ export class SoundsInstance {
236
243
  }
237
244
  clamp(this._volume, soundsOptions.volume.min, soundsOptions.volume.max);
238
245
  let stateChanged = false;
239
- if (this._volume <= 0 && !container.muted) {
246
+ if (this._volume <= minVolume && !container.muted) {
240
247
  this._volume = 0;
241
248
  container.muted = true;
242
249
  stateChanged = true;
243
250
  }
244
- else if (this._volume > 0 && container.muted) {
251
+ else if (this._volume > minVolume && container.muted) {
245
252
  container.muted = false;
246
253
  stateChanged = true;
247
254
  }
@@ -250,7 +257,7 @@ export class SoundsInstance {
250
257
  await this._updateMuteStatus();
251
258
  }
252
259
  if (this._gain?.gain) {
253
- this._gain.gain.value = this._volume / 100;
260
+ this._gain.gain.value = this._volume / percentDenominator;
254
261
  }
255
262
  };
256
263
  this._container = container;
@@ -264,6 +271,20 @@ export class SoundsInstance {
264
271
  if (!soundsOptions?.enable) {
265
272
  return;
266
273
  }
274
+ if (soundsOptions.autoPlay && isWindowMuted()) {
275
+ const firstClickHandler = () => {
276
+ removeEventListener(mouseDownEvent, firstClickHandler);
277
+ removeEventListener(touchStartEvent, firstClickHandler);
278
+ unmuteWindow();
279
+ void this.unmute();
280
+ };
281
+ const listenerOptions = {
282
+ capture: true,
283
+ once: true,
284
+ };
285
+ addEventListener(mouseDownEvent, firstClickHandler, listenerOptions);
286
+ addEventListener(touchStartEvent, firstClickHandler, listenerOptions);
287
+ }
267
288
  this._volume = soundsOptions.volume.value;
268
289
  const events = soundsOptions.events;
269
290
  this._audioMap = new Map();
@@ -271,16 +292,25 @@ export class SoundsInstance {
271
292
  if (!event.audio) {
272
293
  continue;
273
294
  }
274
- executeOnSingleOrMultiple(event.audio, async (audio) => {
295
+ const promises = executeOnSingleOrMultiple(event.audio, async (audio) => {
275
296
  const response = await fetch(audio.source);
276
297
  if (!response.ok) {
277
298
  return;
278
299
  }
279
- const arrayBuffer = await response.arrayBuffer();
280
- container.audioContext = new AudioContext();
281
- const audioBuffer = await container.audioContext.decodeAudioData(arrayBuffer);
300
+ const arrayBuffer = await response.arrayBuffer(), audioContext = this._getAudioContext(), audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
282
301
  this._audioMap.set(audio.source, audioBuffer);
283
302
  });
303
+ if (promises instanceof Promise) {
304
+ await promises;
305
+ }
306
+ else {
307
+ await Promise.allSettled(promises);
308
+ }
309
+ }
310
+ }
311
+ async mute() {
312
+ if (!this._container.muted) {
313
+ await this.toggleMute();
284
314
  }
285
315
  }
286
316
  async start() {
@@ -292,17 +322,14 @@ export class SoundsInstance {
292
322
  const canvas = container.canvas.element, pos = {
293
323
  top: canvas.offsetTop,
294
324
  right: canvas.offsetLeft + canvas.offsetWidth,
295
- }, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10;
296
- const toggleMute = async () => {
297
- container.muted = !container.muted;
298
- this._updateMuteIcons();
299
- await this._updateMuteStatus();
300
- };
325
+ }, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
326
+ await this.toggleMute();
327
+ }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? "block" : "none";
301
328
  this._muteImg = initImage({
302
329
  container,
303
330
  options,
304
331
  pos,
305
- display: "block",
332
+ display,
306
333
  iconOptions: mute,
307
334
  margin,
308
335
  rightOffsets: [volumeDown.width, volumeUp.width],
@@ -322,41 +349,75 @@ export class SoundsInstance {
322
349
  container,
323
350
  options,
324
351
  pos,
325
- display: "block",
352
+ display,
326
353
  iconOptions: volumeDown,
327
354
  margin,
328
355
  rightOffsets: [volumeUp.width],
329
356
  clickCb: async () => {
330
- if (container.muted) {
331
- this._volume = 0;
332
- }
333
- this._volume -= soundsOptions.volume.step;
334
- await this._updateVolume();
357
+ await this.volumeDown();
335
358
  },
336
359
  });
337
360
  this._volumeUpImg = initImage({
338
361
  container,
339
362
  options,
340
363
  pos,
341
- display: "block",
364
+ display,
342
365
  iconOptions: volumeUp,
343
366
  margin,
344
367
  rightOffsets: [],
345
368
  clickCb: async () => {
346
- if (container.muted) {
347
- this._volume = 0;
348
- }
349
- this._volume += soundsOptions.volume.step;
350
- await this._updateVolume();
369
+ await this.volumeUp();
351
370
  },
352
371
  });
372
+ if (!isWindowMuted() && soundsOptions.autoPlay) {
373
+ await this.unmute();
374
+ }
353
375
  }
354
376
  stop() {
355
377
  this._container.muted = true;
356
- this._mute();
357
- removeImage(this._muteImg);
358
- removeImage(this._unmuteImg);
359
- removeImage(this._volumeDownImg);
360
- removeImage(this._volumeUpImg);
378
+ void (async () => {
379
+ await this._mute();
380
+ removeImage(this._muteImg);
381
+ removeImage(this._unmuteImg);
382
+ removeImage(this._volumeDownImg);
383
+ removeImage(this._volumeUpImg);
384
+ })();
385
+ }
386
+ async toggleMute() {
387
+ const container = this._container;
388
+ container.muted = !container.muted;
389
+ this._updateMuteIcons();
390
+ await this._updateMuteStatus();
391
+ }
392
+ async unmute() {
393
+ if (this._container.muted) {
394
+ await this.toggleMute();
395
+ }
396
+ }
397
+ async volumeDown() {
398
+ const container = this._container, soundsOptions = container.actualOptions.sounds;
399
+ if (!soundsOptions?.enable) {
400
+ return;
401
+ }
402
+ if (container.muted) {
403
+ this._volume = 0;
404
+ }
405
+ this._volume -= soundsOptions.volume.step;
406
+ await this._updateVolume();
407
+ }
408
+ async volumeUp() {
409
+ const container = this._container, soundsOptions = container.actualOptions.sounds;
410
+ if (!soundsOptions?.enable) {
411
+ return;
412
+ }
413
+ this._volume += soundsOptions.volume.step;
414
+ await this._updateVolume();
415
+ }
416
+ _getAudioContext() {
417
+ const container = this._container;
418
+ if (!container.audioContext) {
419
+ container.audioContext = new AudioContext();
420
+ }
421
+ return container.audioContext;
361
422
  }
362
423
  }
@@ -0,0 +1,37 @@
1
+ import { mouseDownEvent, touchStartEvent, } from "@tsparticles/engine";
2
+ import { Sounds } from "./Options/Classes/Sounds.js";
3
+ import { unmuteWindow } from "./utils.js";
4
+ const generalFirstClickHandler = () => {
5
+ removeEventListener(mouseDownEvent, generalFirstClickHandler);
6
+ removeEventListener(touchStartEvent, generalFirstClickHandler);
7
+ unmuteWindow();
8
+ };
9
+ export class SoundsPlugin {
10
+ constructor(engine) {
11
+ this.id = "sounds";
12
+ this._engine = engine;
13
+ const listenerOptions = {
14
+ capture: true,
15
+ once: true,
16
+ };
17
+ addEventListener(mouseDownEvent, generalFirstClickHandler, listenerOptions);
18
+ addEventListener(touchStartEvent, generalFirstClickHandler, listenerOptions);
19
+ }
20
+ async getPlugin(container) {
21
+ const { SoundsInstance } = await import("./SoundsInstance.js");
22
+ return new SoundsInstance(container, this._engine);
23
+ }
24
+ loadOptions(options, source) {
25
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
26
+ return;
27
+ }
28
+ let soundsOptions = options.sounds;
29
+ if (soundsOptions?.load === undefined) {
30
+ options.sounds = soundsOptions = new Sounds();
31
+ }
32
+ soundsOptions.load(source?.sounds);
33
+ }
34
+ needsPlugin(options) {
35
+ return options?.sounds?.enable ?? false;
36
+ }
37
+ }