@tsparticles/plugin-sounds 3.9.1 → 4.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/902.min.js +2 -0
- package/902.min.js.LICENSE.txt +1 -0
- package/browser/Options/Classes/SoundsEvent.js +1 -1
- package/browser/SoundsInstance.js +26 -24
- package/browser/index.js +6 -4
- package/browser/utils.js +2 -2
- package/cjs/Options/Classes/Sounds.js +9 -13
- package/cjs/Options/Classes/SoundsAudio.js +4 -8
- package/cjs/Options/Classes/SoundsEvent.js +14 -18
- package/cjs/Options/Classes/SoundsIcon.js +3 -7
- package/cjs/Options/Classes/SoundsIcons.js +8 -12
- package/cjs/Options/Classes/SoundsMelody.js +5 -9
- package/cjs/Options/Classes/SoundsNote.js +3 -7
- package/cjs/Options/Classes/SoundsVolume.js +4 -8
- package/cjs/Options/Interfaces/ISounds.js +1 -2
- package/cjs/Options/Interfaces/ISoundsAudio.js +1 -2
- package/cjs/Options/Interfaces/ISoundsEvent.js +1 -2
- package/cjs/Options/Interfaces/ISoundsIcon.js +1 -2
- package/cjs/Options/Interfaces/ISoundsIcons.js +1 -2
- package/cjs/Options/Interfaces/ISoundsMelody.js +1 -2
- package/cjs/Options/Interfaces/ISoundsNote.js +1 -2
- package/cjs/Options/Interfaces/ISoundsVolume.js +1 -2
- package/cjs/SoundsInstance.js +53 -55
- package/cjs/SoundsPlugin.js +12 -16
- package/cjs/enums.js +4 -7
- package/cjs/index.js +6 -7
- package/cjs/types.js +1 -2
- package/cjs/utils.js +5 -11
- package/dist_browser_SoundsPlugin_js.js +140 -0
- package/esm/Options/Classes/SoundsEvent.js +1 -1
- package/esm/SoundsInstance.js +26 -24
- package/esm/index.js +6 -4
- package/esm/utils.js +2 -2
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.plugin.sounds.js +209 -140
- package/tsparticles.plugin.sounds.min.js +1 -1
- package/tsparticles.plugin.sounds.min.js.LICENSE.txt +1 -1
- package/types/SoundsInstance.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/umd/Options/Classes/SoundsEvent.js +1 -1
- package/umd/SoundsInstance.js +25 -23
- package/umd/index.js +41 -5
- package/umd/utils.js +2 -2
package/umd/SoundsInstance.js
CHANGED
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
const utils_js_1 = require("./utils.js");
|
|
16
16
|
const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
|
|
17
17
|
function initImage(data) {
|
|
18
|
-
const img =
|
|
18
|
+
const img = (0, engine_1.safeDocument)().createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, style, svg } = iconOptions, defaultAccumulator = 0;
|
|
19
19
|
setIconStyle(img, pos.top + margin, pos.right -
|
|
20
20
|
(margin * (rightOffsets.length + rightOffset) +
|
|
21
21
|
width +
|
|
22
22
|
rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
|
|
23
23
|
img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
|
|
24
|
-
const parent = container.canvas.element?.parentNode ??
|
|
24
|
+
const parent = container.canvas.element?.parentNode ?? (0, engine_1.safeDocument)().body;
|
|
25
25
|
parent.append(img);
|
|
26
26
|
img.addEventListener("click", () => {
|
|
27
27
|
void clickCb();
|
|
@@ -36,12 +36,11 @@
|
|
|
36
36
|
}
|
|
37
37
|
function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
|
|
38
38
|
icon.style.userSelect = "none";
|
|
39
|
-
icon.style.webkitUserSelect = "none";
|
|
40
39
|
icon.style.position = "absolute";
|
|
41
|
-
icon.style.top = `${top + margin}px`;
|
|
42
|
-
icon.style.left = `${left - margin - width}px`;
|
|
40
|
+
icon.style.top = `${(top + margin).toString()}px`;
|
|
41
|
+
icon.style.left = `${(left - margin - width).toString()}px`;
|
|
43
42
|
icon.style.display = display;
|
|
44
|
-
icon.style.zIndex =
|
|
43
|
+
icon.style.zIndex = (zIndex + zIndexOffset).toString();
|
|
45
44
|
icon.style.cssText += style;
|
|
46
45
|
}
|
|
47
46
|
class SoundsInstance {
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
if (this._container !== args.container) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
|
-
if (
|
|
70
|
+
if (!!this._container.muted || this._container.destroyed) {
|
|
72
71
|
(0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
|
|
73
72
|
this._engine.removeEventListener(item, cb);
|
|
74
73
|
});
|
|
@@ -79,10 +78,17 @@
|
|
|
79
78
|
}
|
|
80
79
|
const defaultNoteIndex = 0;
|
|
81
80
|
if (event.audio) {
|
|
82
|
-
|
|
81
|
+
const audio = (0, engine_1.itemFromSingleOrMultiple)(event.audio);
|
|
82
|
+
if (!audio) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this._playBuffer(audio);
|
|
83
86
|
}
|
|
84
87
|
else if (event.melodies) {
|
|
85
88
|
const melody = (0, engine_1.itemFromArray)(event.melodies);
|
|
89
|
+
if (!melody) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
86
92
|
if (melody.melodies.length) {
|
|
87
93
|
await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
|
|
88
94
|
}
|
|
@@ -92,6 +98,9 @@
|
|
|
92
98
|
}
|
|
93
99
|
else if (event.notes) {
|
|
94
100
|
const note = (0, engine_1.itemFromArray)(event.notes);
|
|
101
|
+
if (!note) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
95
104
|
await this._playNote([note], defaultNoteIndex, false);
|
|
96
105
|
}
|
|
97
106
|
})();
|
|
@@ -170,8 +179,7 @@
|
|
|
170
179
|
if (!note) {
|
|
171
180
|
return;
|
|
172
181
|
}
|
|
173
|
-
const value = note.value
|
|
174
|
-
const promises = (0, engine_1.executeOnSingleOrMultiple)(value, async (_, idx) => {
|
|
182
|
+
const value = note.value, promises = (0, engine_1.executeOnSingleOrMultiple)(value, async (_, idx) => {
|
|
175
183
|
return this._playNoteValue(notes, noteIdx, idx);
|
|
176
184
|
});
|
|
177
185
|
await ((0, engine_1.isArray)(promises) ? Promise.allSettled(promises) : promises);
|
|
@@ -180,9 +188,6 @@
|
|
|
180
188
|
if (loop && nextNoteIdx >= notes.length) {
|
|
181
189
|
nextNoteIdx = nextNoteIdx % notes.length;
|
|
182
190
|
}
|
|
183
|
-
if (this._container.muted) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
191
|
await this._playNote(notes, nextNoteIdx, loop);
|
|
187
192
|
};
|
|
188
193
|
this._playNoteValue = async (notes, noteIdx, valueIdx) => {
|
|
@@ -191,6 +196,9 @@
|
|
|
191
196
|
return;
|
|
192
197
|
}
|
|
193
198
|
const value = (0, engine_1.itemFromSingleOrMultiple)(note.value, valueIdx, true);
|
|
199
|
+
if (!value) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
194
202
|
try {
|
|
195
203
|
const freq = (0, utils_js_1.getNoteFrequency)(value);
|
|
196
204
|
if (!(0, engine_1.isNumber)(freq)) {
|
|
@@ -213,11 +221,7 @@
|
|
|
213
221
|
if (!soundsOptions) {
|
|
214
222
|
return;
|
|
215
223
|
}
|
|
216
|
-
const audioContext = this._getAudioContext();
|
|
217
|
-
if (!this._audioSources) {
|
|
218
|
-
this._audioSources = [];
|
|
219
|
-
}
|
|
220
|
-
const gain = audioContext.createGain();
|
|
224
|
+
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
221
225
|
gain.connect(audioContext.destination);
|
|
222
226
|
gain.gain.value = soundsOptions.volume.value / engine_1.percentDenominator;
|
|
223
227
|
this._gain = gain;
|
|
@@ -240,11 +244,11 @@
|
|
|
240
244
|
this._updateMuteStatus = async () => {
|
|
241
245
|
const container = this._container, audioContext = this._getAudioContext();
|
|
242
246
|
if (container.muted) {
|
|
243
|
-
await audioContext
|
|
247
|
+
await audioContext.suspend();
|
|
244
248
|
await this._mute();
|
|
245
249
|
}
|
|
246
250
|
else {
|
|
247
|
-
await audioContext
|
|
251
|
+
await audioContext.resume();
|
|
248
252
|
this._unmute();
|
|
249
253
|
this._playMuteSound();
|
|
250
254
|
}
|
|
@@ -428,9 +432,7 @@
|
|
|
428
432
|
}
|
|
429
433
|
_getAudioContext() {
|
|
430
434
|
const container = this._container;
|
|
431
|
-
|
|
432
|
-
container.audioContext = new AudioContext();
|
|
433
|
-
}
|
|
435
|
+
container.audioContext ??= new AudioContext();
|
|
434
436
|
return container.audioContext;
|
|
435
437
|
}
|
|
436
438
|
}
|
package/umd/index.js
CHANGED
|
@@ -1,18 +1,54 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
18
|
+
var ownKeys = function(o) {
|
|
19
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
20
|
+
var ar = [];
|
|
21
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
22
|
+
return ar;
|
|
23
|
+
};
|
|
24
|
+
return ownKeys(o);
|
|
25
|
+
};
|
|
26
|
+
return function (mod) {
|
|
27
|
+
if (mod && mod.__esModule) return mod;
|
|
28
|
+
var result = {};
|
|
29
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
30
|
+
__setModuleDefault(result, mod);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
1
34
|
(function (factory) {
|
|
2
35
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
36
|
var v = factory(require, exports);
|
|
4
37
|
if (v !== undefined) module.exports = v;
|
|
5
38
|
}
|
|
6
39
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"
|
|
40
|
+
define(["require", "exports"], factory);
|
|
8
41
|
}
|
|
9
42
|
})(function (require, exports) {
|
|
10
43
|
"use strict";
|
|
44
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
46
|
exports.loadSoundsPlugin = loadSoundsPlugin;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
engine.
|
|
16
|
-
|
|
47
|
+
function loadSoundsPlugin(engine) {
|
|
48
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
49
|
+
engine.register(async (e) => {
|
|
50
|
+
const { SoundsPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./SoundsPlugin.js"))) : new Promise((resolve_1, reject_1) => { require(["./SoundsPlugin.js"], resolve_1, reject_1); }).then(__importStar));
|
|
51
|
+
e.addPlugin(new SoundsPlugin(engine));
|
|
52
|
+
});
|
|
17
53
|
}
|
|
18
54
|
});
|
package/umd/utils.js
CHANGED
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
if (!result?.length) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
const noteKey = result[groupKey]
|
|
33
|
+
const noteKey = result[groupKey] ?? result[defaultMatchKey], noteItem = notes.get(noteKey);
|
|
34
34
|
if (!noteItem) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
return noteItem[parseInt(result[innerGroupKey]
|
|
37
|
+
return noteItem[parseInt(result[innerGroupKey] ?? "0")];
|
|
38
38
|
}
|
|
39
39
|
let muted = true;
|
|
40
40
|
const isWindowMuted = () => {
|