@tsparticles/plugin-sounds 4.0.0-beta.1 → 4.0.0-beta.10
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/{414.min.js → 300.min.js} +2 -2
- package/86.min.js +1 -0
- package/README.md +22 -0
- package/browser/index.js +1 -1
- package/cjs/index.js +1 -1
- package/dist_browser_SoundsPluginInstance_js.js +1 -1
- package/dist_browser_SoundsPlugin_js.js +1 -1
- package/esm/index.js +1 -1
- package/package.json +4 -5
- package/report.html +1 -1
- package/tsparticles.plugin.sounds.js +2 -2
- package/tsparticles.plugin.sounds.min.js +1 -1
- package/4.min.js +0 -1
- package/umd/Options/Classes/Sounds.js +0 -54
- package/umd/Options/Classes/SoundsAudio.js +0 -39
- package/umd/Options/Classes/SoundsEvent.js +0 -75
- package/umd/Options/Classes/SoundsIcon.js +0 -44
- package/umd/Options/Classes/SoundsIcons.js +0 -78
- package/umd/Options/Classes/SoundsMelody.js +0 -48
- package/umd/Options/Classes/SoundsNote.js +0 -34
- package/umd/Options/Classes/SoundsVolume.js +0 -49
- package/umd/Options/Interfaces/ISounds.js +0 -12
- package/umd/Options/Interfaces/ISoundsAudio.js +0 -12
- package/umd/Options/Interfaces/ISoundsEvent.js +0 -12
- package/umd/Options/Interfaces/ISoundsIcon.js +0 -12
- package/umd/Options/Interfaces/ISoundsIcons.js +0 -12
- package/umd/Options/Interfaces/ISoundsMelody.js +0 -12
- package/umd/Options/Interfaces/ISoundsNote.js +0 -12
- package/umd/Options/Interfaces/ISoundsVolume.js +0 -12
- package/umd/SoundsPlugin.js +0 -86
- package/umd/SoundsPluginInstance.js +0 -451
- package/umd/constants.js +0 -14
- package/umd/enums.js +0 -23
- package/umd/index.js +0 -54
- package/umd/types.js +0 -12
- package/umd/utils.js +0 -48
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine", "./enums.js", "./utils.js", "./constants.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SoundsPluginInstance = void 0;
|
|
13
|
-
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const enums_js_1 = require("./enums.js");
|
|
15
|
-
const utils_js_1 = require("./utils.js");
|
|
16
|
-
const constants_js_1 = require("./constants.js");
|
|
17
|
-
const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
|
|
18
|
-
function initImage(data) {
|
|
19
|
-
const img = (0, engine_1.safeDocument)().createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, style, svg } = iconOptions, defaultAccumulator = 0;
|
|
20
|
-
setIconStyle(img, pos.top + margin, pos.right -
|
|
21
|
-
(margin * (rightOffsets.length + rightOffset) + width + rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
|
|
22
|
-
img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
|
|
23
|
-
const parent = container.canvas.element?.parentNode ?? (0, engine_1.safeDocument)().body;
|
|
24
|
-
parent.append(img);
|
|
25
|
-
img.addEventListener("click", () => {
|
|
26
|
-
void clickCb();
|
|
27
|
-
});
|
|
28
|
-
return img;
|
|
29
|
-
}
|
|
30
|
-
function removeImage(image) {
|
|
31
|
-
if (!image) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
image.remove();
|
|
35
|
-
}
|
|
36
|
-
function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
|
|
37
|
-
icon.style.userSelect = "none";
|
|
38
|
-
icon.style.position = "absolute";
|
|
39
|
-
icon.style.top = `${(top + margin).toString()}px`;
|
|
40
|
-
icon.style.left = `${(left - margin - width).toString()}px`;
|
|
41
|
-
icon.style.display = display;
|
|
42
|
-
icon.style.zIndex = (zIndex + zIndexOffset).toString();
|
|
43
|
-
icon.style.cssText += style;
|
|
44
|
-
}
|
|
45
|
-
class SoundsPluginInstance {
|
|
46
|
-
_audioMap;
|
|
47
|
-
_audioSources;
|
|
48
|
-
_container;
|
|
49
|
-
_engine;
|
|
50
|
-
_gain;
|
|
51
|
-
_muteImg;
|
|
52
|
-
_unmuteImg;
|
|
53
|
-
_volume;
|
|
54
|
-
_volumeDownImg;
|
|
55
|
-
_volumeUpImg;
|
|
56
|
-
constructor(container, engine) {
|
|
57
|
-
this._container = container;
|
|
58
|
-
this._engine = engine;
|
|
59
|
-
this._volume = 0;
|
|
60
|
-
this._audioSources = [];
|
|
61
|
-
this._audioMap = new Map();
|
|
62
|
-
}
|
|
63
|
-
async init() {
|
|
64
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
65
|
-
if (!soundsOptions?.enable) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (soundsOptions.autoPlay && (0, utils_js_1.isWindowMuted)()) {
|
|
69
|
-
const firstClickHandler = () => {
|
|
70
|
-
removeEventListener(constants_js_1.mouseDownEvent, firstClickHandler);
|
|
71
|
-
removeEventListener(constants_js_1.touchStartEvent, firstClickHandler);
|
|
72
|
-
(0, utils_js_1.unmuteWindow)();
|
|
73
|
-
void this.unmute();
|
|
74
|
-
}, listenerOptions = {
|
|
75
|
-
capture: true,
|
|
76
|
-
once: true,
|
|
77
|
-
};
|
|
78
|
-
addEventListener(constants_js_1.mouseDownEvent, firstClickHandler, listenerOptions);
|
|
79
|
-
addEventListener(constants_js_1.touchStartEvent, firstClickHandler, listenerOptions);
|
|
80
|
-
}
|
|
81
|
-
this._volume = soundsOptions.volume.value;
|
|
82
|
-
const events = soundsOptions.events;
|
|
83
|
-
this._audioMap = new Map();
|
|
84
|
-
for (const event of events) {
|
|
85
|
-
if (!event.audio) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const promises = (0, engine_1.executeOnSingleOrMultiple)(event.audio, async (audio) => {
|
|
89
|
-
const response = await fetch(audio.source);
|
|
90
|
-
if (!response.ok) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const arrayBuffer = await response.arrayBuffer(), audioContext = this._getAudioContext(), audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
94
|
-
this._audioMap.set(audio.source, audioBuffer);
|
|
95
|
-
});
|
|
96
|
-
if (promises instanceof Promise) {
|
|
97
|
-
await promises;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
await Promise.allSettled(promises);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async mute() {
|
|
105
|
-
if (!this._container.muted) {
|
|
106
|
-
await this.toggleMute();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async start() {
|
|
110
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
111
|
-
if (!soundsOptions?.enable || !container.canvas.element) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
container.muted = true;
|
|
115
|
-
const canvas = container.canvas.element, pos = {
|
|
116
|
-
top: canvas.offsetTop,
|
|
117
|
-
right: canvas.offsetLeft + canvas.offsetWidth,
|
|
118
|
-
}, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
|
|
119
|
-
await this.toggleMute();
|
|
120
|
-
}, enableIcons = soundsOptions.icons.enable, display = enableIcons ? enums_js_1.ImageDisplay.Block : enums_js_1.ImageDisplay.None;
|
|
121
|
-
this._muteImg = initImage({
|
|
122
|
-
container,
|
|
123
|
-
options,
|
|
124
|
-
pos,
|
|
125
|
-
display,
|
|
126
|
-
iconOptions: mute,
|
|
127
|
-
margin,
|
|
128
|
-
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
129
|
-
clickCb: toggleMute,
|
|
130
|
-
});
|
|
131
|
-
this._unmuteImg = initImage({
|
|
132
|
-
container,
|
|
133
|
-
options,
|
|
134
|
-
pos,
|
|
135
|
-
display: enums_js_1.ImageDisplay.None,
|
|
136
|
-
iconOptions: unmute,
|
|
137
|
-
margin,
|
|
138
|
-
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
139
|
-
clickCb: toggleMute,
|
|
140
|
-
});
|
|
141
|
-
this._volumeDownImg = initImage({
|
|
142
|
-
container,
|
|
143
|
-
options,
|
|
144
|
-
pos,
|
|
145
|
-
display,
|
|
146
|
-
iconOptions: volumeDown,
|
|
147
|
-
margin,
|
|
148
|
-
rightOffsets: [volumeUp.width],
|
|
149
|
-
clickCb: async () => {
|
|
150
|
-
await this.volumeDown();
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
this._volumeUpImg = initImage({
|
|
154
|
-
container,
|
|
155
|
-
options,
|
|
156
|
-
pos,
|
|
157
|
-
display,
|
|
158
|
-
iconOptions: volumeUp,
|
|
159
|
-
margin,
|
|
160
|
-
rightOffsets: [],
|
|
161
|
-
clickCb: async () => {
|
|
162
|
-
await this.volumeUp();
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
if (!(0, utils_js_1.isWindowMuted)() && soundsOptions.autoPlay) {
|
|
166
|
-
await this.unmute();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
stop() {
|
|
170
|
-
this._container.muted = true;
|
|
171
|
-
void (async () => {
|
|
172
|
-
await this._mute();
|
|
173
|
-
removeImage(this._muteImg);
|
|
174
|
-
removeImage(this._unmuteImg);
|
|
175
|
-
removeImage(this._volumeDownImg);
|
|
176
|
-
removeImage(this._volumeUpImg);
|
|
177
|
-
})();
|
|
178
|
-
}
|
|
179
|
-
async toggleMute() {
|
|
180
|
-
const container = this._container;
|
|
181
|
-
container.muted = !container.muted;
|
|
182
|
-
this._updateMuteIcons();
|
|
183
|
-
await this._updateMuteStatus();
|
|
184
|
-
}
|
|
185
|
-
async unmute() {
|
|
186
|
-
if (this._container.muted) {
|
|
187
|
-
await this.toggleMute();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
async volumeDown() {
|
|
191
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
192
|
-
if (!soundsOptions?.enable) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (container.muted) {
|
|
196
|
-
this._volume = 0;
|
|
197
|
-
}
|
|
198
|
-
this._volume -= soundsOptions.volume.step;
|
|
199
|
-
await this._updateVolume();
|
|
200
|
-
}
|
|
201
|
-
async volumeUp() {
|
|
202
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
203
|
-
if (!soundsOptions?.enable) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
this._volume += soundsOptions.volume.step;
|
|
207
|
-
await this._updateVolume();
|
|
208
|
-
}
|
|
209
|
-
_addBuffer = audioCtx => {
|
|
210
|
-
const buffer = audioCtx.createBufferSource();
|
|
211
|
-
this._audioSources.push(buffer);
|
|
212
|
-
return buffer;
|
|
213
|
-
};
|
|
214
|
-
_addOscillator = audioCtx => {
|
|
215
|
-
const oscillator = audioCtx.createOscillator();
|
|
216
|
-
this._audioSources.push(oscillator);
|
|
217
|
-
return oscillator;
|
|
218
|
-
};
|
|
219
|
-
_getAudioContext() {
|
|
220
|
-
const container = this._container;
|
|
221
|
-
container.audioContext ??= new AudioContext();
|
|
222
|
-
return container.audioContext;
|
|
223
|
-
}
|
|
224
|
-
_initEvents = () => {
|
|
225
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
226
|
-
if (!soundsOptions?.enable || !container.canvas.element) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
for (const event of soundsOptions.events) {
|
|
230
|
-
const cb = (args) => {
|
|
231
|
-
if (!args) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
void (async () => {
|
|
235
|
-
const filterNotValid = event.filter && !event.filter(args);
|
|
236
|
-
if (this._container !== args.container) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
if (!!this._container.muted || this._container.destroyed) {
|
|
240
|
-
(0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
|
|
241
|
-
this._engine.removeEventListener(item, cb);
|
|
242
|
-
});
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (filterNotValid) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
const defaultNoteIndex = 0;
|
|
249
|
-
if (event.audio) {
|
|
250
|
-
const audio = (0, engine_1.itemFromSingleOrMultiple)(event.audio);
|
|
251
|
-
if (!audio) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
this._playBuffer(audio);
|
|
255
|
-
}
|
|
256
|
-
else if (event.melodies) {
|
|
257
|
-
const melody = (0, engine_1.itemFromArray)(event.melodies);
|
|
258
|
-
if (!melody) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
if (melody.melodies.length) {
|
|
262
|
-
await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
else if (event.notes) {
|
|
269
|
-
const note = (0, engine_1.itemFromArray)(event.notes);
|
|
270
|
-
if (!note) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
await this._playNote([note], defaultNoteIndex, false);
|
|
274
|
-
}
|
|
275
|
-
})();
|
|
276
|
-
};
|
|
277
|
-
(0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
|
|
278
|
-
this._engine.addEventListener(item, cb);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
_mute = async () => {
|
|
283
|
-
const container = this._container, audioContext = this._getAudioContext();
|
|
284
|
-
for (const source of this._audioSources) {
|
|
285
|
-
this._removeAudioSource(source);
|
|
286
|
-
}
|
|
287
|
-
if (this._gain) {
|
|
288
|
-
this._gain.disconnect();
|
|
289
|
-
}
|
|
290
|
-
await audioContext.close();
|
|
291
|
-
container.audioContext = undefined;
|
|
292
|
-
this._container.dispatchEvent(enums_js_1.SoundsEventType.mute);
|
|
293
|
-
};
|
|
294
|
-
_playBuffer = audio => {
|
|
295
|
-
const audioBuffer = this._audioMap.get(audio.source);
|
|
296
|
-
if (!audioBuffer) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
const audioCtx = this._container.audioContext;
|
|
300
|
-
if (!audioCtx) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
const source = this._addBuffer(audioCtx);
|
|
304
|
-
source.loop = audio.loop;
|
|
305
|
-
source.buffer = audioBuffer;
|
|
306
|
-
source.connect(this._gain ?? audioCtx.destination);
|
|
307
|
-
source.start();
|
|
308
|
-
};
|
|
309
|
-
_playFrequency = async (frequency, duration) => {
|
|
310
|
-
if (!this._gain || this._container.muted) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const audioContext = this._getAudioContext(), oscillator = this._addOscillator(audioContext);
|
|
314
|
-
oscillator.connect(this._gain);
|
|
315
|
-
oscillator.type = "sine";
|
|
316
|
-
oscillator.frequency.value = frequency;
|
|
317
|
-
oscillator.start();
|
|
318
|
-
return new Promise(resolve => {
|
|
319
|
-
setTimeout(() => {
|
|
320
|
-
this._removeAudioSource(oscillator);
|
|
321
|
-
resolve();
|
|
322
|
-
}, duration);
|
|
323
|
-
});
|
|
324
|
-
};
|
|
325
|
-
_playMuteSound = () => {
|
|
326
|
-
if (this._container.muted) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
330
|
-
gain.connect(audioContext.destination);
|
|
331
|
-
gain.gain.value = 0;
|
|
332
|
-
const oscillator = audioContext.createOscillator();
|
|
333
|
-
oscillator.connect(gain);
|
|
334
|
-
oscillator.type = "sine";
|
|
335
|
-
oscillator.frequency.value = 1;
|
|
336
|
-
oscillator.start();
|
|
337
|
-
setTimeout(() => {
|
|
338
|
-
oscillator.stop();
|
|
339
|
-
oscillator.disconnect();
|
|
340
|
-
gain.disconnect();
|
|
341
|
-
});
|
|
342
|
-
};
|
|
343
|
-
_playNote = async (notes, noteIdx, loop) => {
|
|
344
|
-
if (this._container.muted) {
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
const note = notes[noteIdx];
|
|
348
|
-
if (!note) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
const value = note.value, promises = (0, engine_1.executeOnSingleOrMultiple)(value, async (_, idx) => {
|
|
352
|
-
return this._playNoteValue(notes, noteIdx, idx);
|
|
353
|
-
});
|
|
354
|
-
await ((0, engine_1.isArray)(promises) ? Promise.allSettled(promises) : promises);
|
|
355
|
-
const indexOffset = 1;
|
|
356
|
-
let nextNoteIdx = noteIdx + indexOffset;
|
|
357
|
-
if (loop && nextNoteIdx >= notes.length) {
|
|
358
|
-
nextNoteIdx = nextNoteIdx % notes.length;
|
|
359
|
-
}
|
|
360
|
-
await this._playNote(notes, nextNoteIdx, loop);
|
|
361
|
-
};
|
|
362
|
-
_playNoteValue = async (notes, noteIdx, valueIdx) => {
|
|
363
|
-
const note = notes[noteIdx];
|
|
364
|
-
if (!note) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
const value = (0, engine_1.itemFromSingleOrMultiple)(note.value, valueIdx, true);
|
|
368
|
-
if (!value) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
try {
|
|
372
|
-
const freq = (0, utils_js_1.getNoteFrequency)(value);
|
|
373
|
-
if (!(0, engine_1.isNumber)(freq)) {
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
await this._playFrequency(freq, note.duration);
|
|
377
|
-
}
|
|
378
|
-
catch (e) {
|
|
379
|
-
(0, engine_1.getLogger)().error(e);
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
_removeAudioSource = source => {
|
|
383
|
-
source.stop();
|
|
384
|
-
source.disconnect();
|
|
385
|
-
const deleteCount = 1;
|
|
386
|
-
this._audioSources.splice(this._audioSources.indexOf(source), deleteCount);
|
|
387
|
-
};
|
|
388
|
-
_unmute = () => {
|
|
389
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
390
|
-
if (!soundsOptions) {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
394
|
-
gain.connect(audioContext.destination);
|
|
395
|
-
gain.gain.value = soundsOptions.volume.value / engine_1.percentDenominator;
|
|
396
|
-
this._gain = gain;
|
|
397
|
-
this._initEvents();
|
|
398
|
-
this._container.dispatchEvent(enums_js_1.SoundsEventType.unmute);
|
|
399
|
-
};
|
|
400
|
-
_updateMuteIcons = () => {
|
|
401
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
402
|
-
if (!soundsOptions?.enable || !soundsOptions.icons.enable) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
const muteImg = this._muteImg, unmuteImg = this._unmuteImg;
|
|
406
|
-
if (muteImg) {
|
|
407
|
-
muteImg.style.display = container.muted ? "block" : "none";
|
|
408
|
-
}
|
|
409
|
-
if (unmuteImg) {
|
|
410
|
-
unmuteImg.style.display = container.muted ? "none" : "block";
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
_updateMuteStatus = async () => {
|
|
414
|
-
const container = this._container, audioContext = this._getAudioContext();
|
|
415
|
-
if (container.muted) {
|
|
416
|
-
await audioContext.suspend();
|
|
417
|
-
await this._mute();
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
await audioContext.resume();
|
|
421
|
-
this._unmute();
|
|
422
|
-
this._playMuteSound();
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
_updateVolume = async () => {
|
|
426
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
427
|
-
if (!soundsOptions?.enable) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
(0, engine_1.clamp)(this._volume, soundsOptions.volume.min, soundsOptions.volume.max);
|
|
431
|
-
let stateChanged = false;
|
|
432
|
-
if (this._volume <= minVolume && !container.muted) {
|
|
433
|
-
this._volume = 0;
|
|
434
|
-
container.muted = true;
|
|
435
|
-
stateChanged = true;
|
|
436
|
-
}
|
|
437
|
-
else if (this._volume > minVolume && container.muted) {
|
|
438
|
-
container.muted = false;
|
|
439
|
-
stateChanged = true;
|
|
440
|
-
}
|
|
441
|
-
if (stateChanged) {
|
|
442
|
-
this._updateMuteIcons();
|
|
443
|
-
await this._updateMuteStatus();
|
|
444
|
-
}
|
|
445
|
-
if (this._gain?.gain) {
|
|
446
|
-
this._gain.gain.value = this._volume / engine_1.percentDenominator;
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
exports.SoundsPluginInstance = SoundsPluginInstance;
|
|
451
|
-
});
|
package/umd/constants.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.touchStartEvent = exports.mouseDownEvent = void 0;
|
|
13
|
-
exports.mouseDownEvent = "pointerdown", exports.touchStartEvent = "touchstart";
|
|
14
|
-
});
|
package/umd/enums.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ImageDisplay = exports.SoundsEventType = void 0;
|
|
13
|
-
var SoundsEventType;
|
|
14
|
-
(function (SoundsEventType) {
|
|
15
|
-
SoundsEventType["mute"] = "soundsMuted";
|
|
16
|
-
SoundsEventType["unmute"] = "soundsUnmuted";
|
|
17
|
-
})(SoundsEventType || (exports.SoundsEventType = SoundsEventType = {}));
|
|
18
|
-
var ImageDisplay;
|
|
19
|
-
(function (ImageDisplay) {
|
|
20
|
-
ImageDisplay["Block"] = "block";
|
|
21
|
-
ImageDisplay["None"] = "none";
|
|
22
|
-
})(ImageDisplay || (exports.ImageDisplay = ImageDisplay = {}));
|
|
23
|
-
});
|
package/umd/index.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
})();
|
|
34
|
-
(function (factory) {
|
|
35
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
36
|
-
var v = factory(require, exports);
|
|
37
|
-
if (v !== undefined) module.exports = v;
|
|
38
|
-
}
|
|
39
|
-
else if (typeof define === "function" && define.amd) {
|
|
40
|
-
define(["require", "exports"], factory);
|
|
41
|
-
}
|
|
42
|
-
})(function (require, exports) {
|
|
43
|
-
"use strict";
|
|
44
|
-
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.loadSoundsPlugin = loadSoundsPlugin;
|
|
47
|
-
async function loadSoundsPlugin(engine) {
|
|
48
|
-
engine.checkVersion("4.0.0-beta.1");
|
|
49
|
-
await engine.pluginManager.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.pluginManager.addPlugin(new SoundsPlugin(e));
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
});
|
package/umd/types.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
});
|
package/umd/utils.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.unmuteWindow = exports.isWindowMuted = void 0;
|
|
13
|
-
exports.getNoteFrequency = getNoteFrequency;
|
|
14
|
-
const notes = new Map();
|
|
15
|
-
notes.set("C", [16.35, 32.7, 65.41, 130.81, 261.63, 523.25, 1046.5, 2093.0, 4186.01]);
|
|
16
|
-
notes.set("Db", [17.32, 34.65, 69.3, 138.59, 277.18, 554.37, 1108.73, 2217.46, 4434.92]);
|
|
17
|
-
notes.set("D", [18.35, 36.71, 73.42, 146.83, 293.66, 587.33, 1174.66, 2349.32, 4698.63]);
|
|
18
|
-
notes.set("Eb", [19.45, 38.89, 77.78, 155.56, 311.13, 622.25, 1244.51, 2489.02, 4978.03]);
|
|
19
|
-
notes.set("E", [20.6, 41.2, 82.41, 164.81, 329.63, 659.25, 1318.51, 2637.02, 5274.04]);
|
|
20
|
-
notes.set("F", [21.83, 43.65, 87.31, 174.61, 349.23, 698.46, 1396.91, 2793.83, 5587.65]);
|
|
21
|
-
notes.set("Gb", [23.12, 46.25, 92.5, 185.0, 369.99, 739.99, 1479.98, 2959.96, 5919.91]);
|
|
22
|
-
notes.set("G", [24.5, 49.0, 98.0, 196.0, 392.0, 783.99, 1567.98, 3135.96, 6271.93]);
|
|
23
|
-
notes.set("Ab", [25.96, 51.91, 103.83, 207.65, 415.3, 830.61, 1661.22, 3322.44, 6644.88]);
|
|
24
|
-
notes.set("A", [27.5, 55.0, 110.0, 220.0, 440.0, 880.0, 1760.0, 3520.0, 7040.0]);
|
|
25
|
-
notes.set("Bb", [29.14, 58.27, 116.54, 233.08, 466.16, 932.33, 1864.66, 3729.31, 7458.62]);
|
|
26
|
-
notes.set("B", [30.87, 61.74, 123.47, 246.94, 493.88, 987.77, 1975.53, 3951.07, 7902.13]);
|
|
27
|
-
notes.set("pause", [0]);
|
|
28
|
-
function getNoteFrequency(note) {
|
|
29
|
-
const regex = /(([A-G]b?)(\d))|pause/i, result = regex.exec(note), groupKey = 2, defaultMatchKey = 0, innerGroupKey = 3;
|
|
30
|
-
if (!result?.length) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const noteKey = result[groupKey] ?? result[defaultMatchKey], noteItem = notes.get(noteKey);
|
|
34
|
-
if (!noteItem) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
return noteItem[parseInt(result[innerGroupKey] ?? "0")];
|
|
38
|
-
}
|
|
39
|
-
let muted = true;
|
|
40
|
-
const isWindowMuted = () => {
|
|
41
|
-
return muted;
|
|
42
|
-
};
|
|
43
|
-
exports.isWindowMuted = isWindowMuted;
|
|
44
|
-
const unmuteWindow = () => {
|
|
45
|
-
muted = false;
|
|
46
|
-
};
|
|
47
|
-
exports.unmuteWindow = unmuteWindow;
|
|
48
|
-
});
|