@tsparticles/plugin-sounds 4.0.0-alpha.2 → 4.0.0-alpha.20
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/249.min.js +1 -0
- package/807.min.js +33 -0
- package/browser/Options/Classes/Sounds.js +5 -0
- package/browser/Options/Classes/SoundsAudio.js +2 -0
- package/browser/Options/Classes/SoundsEvent.js +5 -0
- package/browser/Options/Classes/SoundsIcon.js +5 -0
- package/browser/Options/Classes/SoundsIcons.js +5 -0
- package/browser/Options/Classes/SoundsMelody.js +3 -0
- package/browser/Options/Classes/SoundsNote.js +2 -0
- package/browser/Options/Classes/SoundsVolume.js +4 -0
- package/browser/SoundsPlugin.js +7 -6
- package/browser/SoundsPluginInstance.js +437 -0
- package/browser/constants.js +1 -0
- package/browser/index.js +3 -3
- package/cjs/Options/Classes/Sounds.js +5 -0
- package/cjs/Options/Classes/SoundsAudio.js +2 -0
- package/cjs/Options/Classes/SoundsEvent.js +5 -0
- package/cjs/Options/Classes/SoundsIcon.js +5 -0
- package/cjs/Options/Classes/SoundsIcons.js +5 -0
- package/cjs/Options/Classes/SoundsMelody.js +3 -0
- package/cjs/Options/Classes/SoundsNote.js +2 -0
- package/cjs/Options/Classes/SoundsVolume.js +4 -0
- package/cjs/SoundsPlugin.js +7 -6
- package/cjs/SoundsPluginInstance.js +437 -0
- package/cjs/constants.js +1 -0
- package/cjs/index.js +3 -3
- package/dist_browser_SoundsPluginInstance_js.js +40 -0
- package/dist_browser_SoundsPlugin_js.js +16 -26
- package/esm/Options/Classes/Sounds.js +5 -0
- package/esm/Options/Classes/SoundsAudio.js +2 -0
- package/esm/Options/Classes/SoundsEvent.js +5 -0
- package/esm/Options/Classes/SoundsIcon.js +5 -0
- package/esm/Options/Classes/SoundsIcons.js +5 -0
- package/esm/Options/Classes/SoundsMelody.js +3 -0
- package/esm/Options/Classes/SoundsNote.js +2 -0
- package/esm/Options/Classes/SoundsVolume.js +4 -0
- package/esm/SoundsPlugin.js +7 -6
- package/esm/SoundsPluginInstance.js +437 -0
- package/esm/constants.js +1 -0
- package/esm/index.js +3 -3
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.sounds.js +11 -11
- package/tsparticles.plugin.sounds.min.js +2 -2
- package/types/SoundsPlugin.d.ts +4 -5
- package/types/{SoundsInstance.d.ts → SoundsPluginInstance.d.ts} +1 -1
- package/types/constants.d.ts +1 -0
- package/types/index.d.ts +1 -1
- package/umd/Options/Classes/Sounds.js +5 -0
- package/umd/Options/Classes/SoundsAudio.js +2 -0
- package/umd/Options/Classes/SoundsEvent.js +5 -0
- package/umd/Options/Classes/SoundsIcon.js +5 -0
- package/umd/Options/Classes/SoundsIcons.js +5 -0
- package/umd/Options/Classes/SoundsMelody.js +3 -0
- package/umd/Options/Classes/SoundsNote.js +2 -0
- package/umd/Options/Classes/SoundsVolume.js +4 -0
- package/umd/SoundsPlugin.js +46 -11
- package/umd/SoundsPluginInstance.js +451 -0
- package/umd/constants.js +14 -0
- package/umd/index.js +3 -3
- package/902.min.js +0 -2
- package/902.min.js.LICENSE.txt +0 -1
- package/browser/SoundsInstance.js +0 -426
- package/cjs/SoundsInstance.js +0 -426
- package/esm/SoundsInstance.js +0 -426
- package/tsparticles.plugin.sounds.min.js.LICENSE.txt +0 -1
- package/umd/SoundsInstance.js +0 -440
package/cjs/SoundsInstance.js
DELETED
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
import { clamp, executeOnSingleOrMultiple, getLogger, isArray, isNumber, itemFromArray, itemFromSingleOrMultiple, mouseDownEvent, percentDenominator, safeDocument, touchStartEvent, } from "@tsparticles/engine";
|
|
2
|
-
import { ImageDisplay, SoundsEventType } from "./enums.js";
|
|
3
|
-
import { getNoteFrequency, isWindowMuted, unmuteWindow } from "./utils.js";
|
|
4
|
-
const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
|
|
5
|
-
function initImage(data) {
|
|
6
|
-
const img = safeDocument().createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, style, svg } = iconOptions, defaultAccumulator = 0;
|
|
7
|
-
setIconStyle(img, pos.top + margin, pos.right -
|
|
8
|
-
(margin * (rightOffsets.length + rightOffset) +
|
|
9
|
-
width +
|
|
10
|
-
rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
|
|
11
|
-
img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
|
|
12
|
-
const parent = container.canvas.element?.parentNode ?? safeDocument().body;
|
|
13
|
-
parent.append(img);
|
|
14
|
-
img.addEventListener("click", () => {
|
|
15
|
-
void clickCb();
|
|
16
|
-
});
|
|
17
|
-
return img;
|
|
18
|
-
}
|
|
19
|
-
function removeImage(image) {
|
|
20
|
-
if (!image) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
image.remove();
|
|
24
|
-
}
|
|
25
|
-
function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
|
|
26
|
-
icon.style.userSelect = "none";
|
|
27
|
-
icon.style.position = "absolute";
|
|
28
|
-
icon.style.top = `${(top + margin).toString()}px`;
|
|
29
|
-
icon.style.left = `${(left - margin - width).toString()}px`;
|
|
30
|
-
icon.style.display = display;
|
|
31
|
-
icon.style.zIndex = (zIndex + zIndexOffset).toString();
|
|
32
|
-
icon.style.cssText += style;
|
|
33
|
-
}
|
|
34
|
-
export class SoundsInstance {
|
|
35
|
-
constructor(container, engine) {
|
|
36
|
-
this._addBuffer = audioCtx => {
|
|
37
|
-
const buffer = audioCtx.createBufferSource();
|
|
38
|
-
this._audioSources.push(buffer);
|
|
39
|
-
return buffer;
|
|
40
|
-
};
|
|
41
|
-
this._addOscillator = audioCtx => {
|
|
42
|
-
const oscillator = audioCtx.createOscillator();
|
|
43
|
-
this._audioSources.push(oscillator);
|
|
44
|
-
return oscillator;
|
|
45
|
-
};
|
|
46
|
-
this._initEvents = () => {
|
|
47
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
48
|
-
if (!soundsOptions?.enable || !container.canvas.element) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
for (const event of soundsOptions.events) {
|
|
52
|
-
const cb = (args) => {
|
|
53
|
-
void (async () => {
|
|
54
|
-
const filterNotValid = event.filter && !event.filter(args);
|
|
55
|
-
if (this._container !== args.container) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (!!this._container.muted || this._container.destroyed) {
|
|
59
|
-
executeOnSingleOrMultiple(event.event, item => {
|
|
60
|
-
this._engine.removeEventListener(item, cb);
|
|
61
|
-
});
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (filterNotValid) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const defaultNoteIndex = 0;
|
|
68
|
-
if (event.audio) {
|
|
69
|
-
const audio = itemFromSingleOrMultiple(event.audio);
|
|
70
|
-
if (!audio) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
this._playBuffer(audio);
|
|
74
|
-
}
|
|
75
|
-
else if (event.melodies) {
|
|
76
|
-
const melody = itemFromArray(event.melodies);
|
|
77
|
-
if (!melody) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (melody.melodies.length) {
|
|
81
|
-
await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else if (event.notes) {
|
|
88
|
-
const note = itemFromArray(event.notes);
|
|
89
|
-
if (!note) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
await this._playNote([note], defaultNoteIndex, false);
|
|
93
|
-
}
|
|
94
|
-
})();
|
|
95
|
-
};
|
|
96
|
-
executeOnSingleOrMultiple(event.event, item => {
|
|
97
|
-
this._engine.addEventListener(item, cb);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this._mute = async () => {
|
|
102
|
-
const container = this._container, audioContext = this._getAudioContext();
|
|
103
|
-
for (const source of this._audioSources) {
|
|
104
|
-
this._removeAudioSource(source);
|
|
105
|
-
}
|
|
106
|
-
if (this._gain) {
|
|
107
|
-
this._gain.disconnect();
|
|
108
|
-
}
|
|
109
|
-
await audioContext.close();
|
|
110
|
-
container.audioContext = undefined;
|
|
111
|
-
this._engine.dispatchEvent(SoundsEventType.mute, { container: this._container });
|
|
112
|
-
};
|
|
113
|
-
this._playBuffer = audio => {
|
|
114
|
-
const audioBuffer = this._audioMap.get(audio.source);
|
|
115
|
-
if (!audioBuffer) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const audioCtx = this._container.audioContext;
|
|
119
|
-
if (!audioCtx) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const source = this._addBuffer(audioCtx);
|
|
123
|
-
source.loop = audio.loop;
|
|
124
|
-
source.buffer = audioBuffer;
|
|
125
|
-
source.connect(this._gain ?? audioCtx.destination);
|
|
126
|
-
source.start();
|
|
127
|
-
};
|
|
128
|
-
this._playFrequency = async (frequency, duration) => {
|
|
129
|
-
if (!this._gain || this._container.muted) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const audioContext = this._getAudioContext(), oscillator = this._addOscillator(audioContext);
|
|
133
|
-
oscillator.connect(this._gain);
|
|
134
|
-
oscillator.type = "sine";
|
|
135
|
-
oscillator.frequency.value = frequency;
|
|
136
|
-
oscillator.start();
|
|
137
|
-
return new Promise(resolve => {
|
|
138
|
-
setTimeout(() => {
|
|
139
|
-
this._removeAudioSource(oscillator);
|
|
140
|
-
resolve();
|
|
141
|
-
}, duration);
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
this._playMuteSound = () => {
|
|
145
|
-
if (this._container.muted) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
149
|
-
gain.connect(audioContext.destination);
|
|
150
|
-
gain.gain.value = 0;
|
|
151
|
-
const oscillator = audioContext.createOscillator();
|
|
152
|
-
oscillator.connect(gain);
|
|
153
|
-
oscillator.type = "sine";
|
|
154
|
-
oscillator.frequency.value = 1;
|
|
155
|
-
oscillator.start();
|
|
156
|
-
setTimeout(() => {
|
|
157
|
-
oscillator.stop();
|
|
158
|
-
oscillator.disconnect();
|
|
159
|
-
gain.disconnect();
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
this._playNote = async (notes, noteIdx, loop) => {
|
|
163
|
-
if (this._container.muted) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const note = notes[noteIdx];
|
|
167
|
-
if (!note) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const value = note.value, promises = executeOnSingleOrMultiple(value, async (_, idx) => {
|
|
171
|
-
return this._playNoteValue(notes, noteIdx, idx);
|
|
172
|
-
});
|
|
173
|
-
await (isArray(promises) ? Promise.allSettled(promises) : promises);
|
|
174
|
-
const indexOffset = 1;
|
|
175
|
-
let nextNoteIdx = noteIdx + indexOffset;
|
|
176
|
-
if (loop && nextNoteIdx >= notes.length) {
|
|
177
|
-
nextNoteIdx = nextNoteIdx % notes.length;
|
|
178
|
-
}
|
|
179
|
-
await this._playNote(notes, nextNoteIdx, loop);
|
|
180
|
-
};
|
|
181
|
-
this._playNoteValue = async (notes, noteIdx, valueIdx) => {
|
|
182
|
-
const note = notes[noteIdx];
|
|
183
|
-
if (!note) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const value = itemFromSingleOrMultiple(note.value, valueIdx, true);
|
|
187
|
-
if (!value) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
const freq = getNoteFrequency(value);
|
|
192
|
-
if (!isNumber(freq)) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
await this._playFrequency(freq, note.duration);
|
|
196
|
-
}
|
|
197
|
-
catch (e) {
|
|
198
|
-
getLogger().error(e);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
this._removeAudioSource = source => {
|
|
202
|
-
source.stop();
|
|
203
|
-
source.disconnect();
|
|
204
|
-
const deleteCount = 1;
|
|
205
|
-
this._audioSources.splice(this._audioSources.indexOf(source), deleteCount);
|
|
206
|
-
};
|
|
207
|
-
this._unmute = () => {
|
|
208
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
209
|
-
if (!soundsOptions) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
213
|
-
gain.connect(audioContext.destination);
|
|
214
|
-
gain.gain.value = soundsOptions.volume.value / percentDenominator;
|
|
215
|
-
this._gain = gain;
|
|
216
|
-
this._initEvents();
|
|
217
|
-
this._engine.dispatchEvent(SoundsEventType.unmute, { container: this._container });
|
|
218
|
-
};
|
|
219
|
-
this._updateMuteIcons = () => {
|
|
220
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
221
|
-
if (!soundsOptions?.enable || !soundsOptions.icons.enable) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
const muteImg = this._muteImg, unmuteImg = this._unmuteImg;
|
|
225
|
-
if (muteImg) {
|
|
226
|
-
muteImg.style.display = container.muted ? "block" : "none";
|
|
227
|
-
}
|
|
228
|
-
if (unmuteImg) {
|
|
229
|
-
unmuteImg.style.display = container.muted ? "none" : "block";
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
this._updateMuteStatus = async () => {
|
|
233
|
-
const container = this._container, audioContext = this._getAudioContext();
|
|
234
|
-
if (container.muted) {
|
|
235
|
-
await audioContext.suspend();
|
|
236
|
-
await this._mute();
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
await audioContext.resume();
|
|
240
|
-
this._unmute();
|
|
241
|
-
this._playMuteSound();
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
this._updateVolume = async () => {
|
|
245
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
246
|
-
if (!soundsOptions?.enable) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
clamp(this._volume, soundsOptions.volume.min, soundsOptions.volume.max);
|
|
250
|
-
let stateChanged = false;
|
|
251
|
-
if (this._volume <= minVolume && !container.muted) {
|
|
252
|
-
this._volume = 0;
|
|
253
|
-
container.muted = true;
|
|
254
|
-
stateChanged = true;
|
|
255
|
-
}
|
|
256
|
-
else if (this._volume > minVolume && container.muted) {
|
|
257
|
-
container.muted = false;
|
|
258
|
-
stateChanged = true;
|
|
259
|
-
}
|
|
260
|
-
if (stateChanged) {
|
|
261
|
-
this._updateMuteIcons();
|
|
262
|
-
await this._updateMuteStatus();
|
|
263
|
-
}
|
|
264
|
-
if (this._gain?.gain) {
|
|
265
|
-
this._gain.gain.value = this._volume / percentDenominator;
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
this._container = container;
|
|
269
|
-
this._engine = engine;
|
|
270
|
-
this._volume = 0;
|
|
271
|
-
this._audioSources = [];
|
|
272
|
-
this._audioMap = new Map();
|
|
273
|
-
}
|
|
274
|
-
async init() {
|
|
275
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
276
|
-
if (!soundsOptions?.enable) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
if (soundsOptions.autoPlay && isWindowMuted()) {
|
|
280
|
-
const firstClickHandler = () => {
|
|
281
|
-
removeEventListener(mouseDownEvent, firstClickHandler);
|
|
282
|
-
removeEventListener(touchStartEvent, firstClickHandler);
|
|
283
|
-
unmuteWindow();
|
|
284
|
-
void this.unmute();
|
|
285
|
-
};
|
|
286
|
-
const listenerOptions = {
|
|
287
|
-
capture: true,
|
|
288
|
-
once: true,
|
|
289
|
-
};
|
|
290
|
-
addEventListener(mouseDownEvent, firstClickHandler, listenerOptions);
|
|
291
|
-
addEventListener(touchStartEvent, firstClickHandler, listenerOptions);
|
|
292
|
-
}
|
|
293
|
-
this._volume = soundsOptions.volume.value;
|
|
294
|
-
const events = soundsOptions.events;
|
|
295
|
-
this._audioMap = new Map();
|
|
296
|
-
for (const event of events) {
|
|
297
|
-
if (!event.audio) {
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
const promises = executeOnSingleOrMultiple(event.audio, async (audio) => {
|
|
301
|
-
const response = await fetch(audio.source);
|
|
302
|
-
if (!response.ok) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const arrayBuffer = await response.arrayBuffer(), audioContext = this._getAudioContext(), audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
306
|
-
this._audioMap.set(audio.source, audioBuffer);
|
|
307
|
-
});
|
|
308
|
-
if (promises instanceof Promise) {
|
|
309
|
-
await promises;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
await Promise.allSettled(promises);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
async mute() {
|
|
317
|
-
if (!this._container.muted) {
|
|
318
|
-
await this.toggleMute();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
async start() {
|
|
322
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
323
|
-
if (!soundsOptions?.enable || !container.canvas.element) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
container.muted = true;
|
|
327
|
-
const canvas = container.canvas.element, pos = {
|
|
328
|
-
top: canvas.offsetTop,
|
|
329
|
-
right: canvas.offsetLeft + canvas.offsetWidth,
|
|
330
|
-
}, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
|
|
331
|
-
await this.toggleMute();
|
|
332
|
-
}, enableIcons = soundsOptions.icons.enable, display = enableIcons ? ImageDisplay.Block : ImageDisplay.None;
|
|
333
|
-
this._muteImg = initImage({
|
|
334
|
-
container,
|
|
335
|
-
options,
|
|
336
|
-
pos,
|
|
337
|
-
display,
|
|
338
|
-
iconOptions: mute,
|
|
339
|
-
margin,
|
|
340
|
-
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
341
|
-
clickCb: toggleMute,
|
|
342
|
-
});
|
|
343
|
-
this._unmuteImg = initImage({
|
|
344
|
-
container,
|
|
345
|
-
options,
|
|
346
|
-
pos,
|
|
347
|
-
display: ImageDisplay.None,
|
|
348
|
-
iconOptions: unmute,
|
|
349
|
-
margin,
|
|
350
|
-
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
351
|
-
clickCb: toggleMute,
|
|
352
|
-
});
|
|
353
|
-
this._volumeDownImg = initImage({
|
|
354
|
-
container,
|
|
355
|
-
options,
|
|
356
|
-
pos,
|
|
357
|
-
display,
|
|
358
|
-
iconOptions: volumeDown,
|
|
359
|
-
margin,
|
|
360
|
-
rightOffsets: [volumeUp.width],
|
|
361
|
-
clickCb: async () => {
|
|
362
|
-
await this.volumeDown();
|
|
363
|
-
},
|
|
364
|
-
});
|
|
365
|
-
this._volumeUpImg = initImage({
|
|
366
|
-
container,
|
|
367
|
-
options,
|
|
368
|
-
pos,
|
|
369
|
-
display,
|
|
370
|
-
iconOptions: volumeUp,
|
|
371
|
-
margin,
|
|
372
|
-
rightOffsets: [],
|
|
373
|
-
clickCb: async () => {
|
|
374
|
-
await this.volumeUp();
|
|
375
|
-
},
|
|
376
|
-
});
|
|
377
|
-
if (!isWindowMuted() && soundsOptions.autoPlay) {
|
|
378
|
-
await this.unmute();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
stop() {
|
|
382
|
-
this._container.muted = true;
|
|
383
|
-
void (async () => {
|
|
384
|
-
await this._mute();
|
|
385
|
-
removeImage(this._muteImg);
|
|
386
|
-
removeImage(this._unmuteImg);
|
|
387
|
-
removeImage(this._volumeDownImg);
|
|
388
|
-
removeImage(this._volumeUpImg);
|
|
389
|
-
})();
|
|
390
|
-
}
|
|
391
|
-
async toggleMute() {
|
|
392
|
-
const container = this._container;
|
|
393
|
-
container.muted = !container.muted;
|
|
394
|
-
this._updateMuteIcons();
|
|
395
|
-
await this._updateMuteStatus();
|
|
396
|
-
}
|
|
397
|
-
async unmute() {
|
|
398
|
-
if (this._container.muted) {
|
|
399
|
-
await this.toggleMute();
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
async volumeDown() {
|
|
403
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
404
|
-
if (!soundsOptions?.enable) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (container.muted) {
|
|
408
|
-
this._volume = 0;
|
|
409
|
-
}
|
|
410
|
-
this._volume -= soundsOptions.volume.step;
|
|
411
|
-
await this._updateVolume();
|
|
412
|
-
}
|
|
413
|
-
async volumeUp() {
|
|
414
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
415
|
-
if (!soundsOptions?.enable) {
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
this._volume += soundsOptions.volume.step;
|
|
419
|
-
await this._updateVolume();
|
|
420
|
-
}
|
|
421
|
-
_getAudioContext() {
|
|
422
|
-
const container = this._container;
|
|
423
|
-
container.audioContext ??= new AudioContext();
|
|
424
|
-
return container.audioContext;
|
|
425
|
-
}
|
|
426
|
-
}
|