@tsparticles/plugin-sounds 4.0.0-alpha.5 → 4.0.0-beta.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/30.min.js +33 -0
- package/915.min.js +1 -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 +2 -1
- package/browser/SoundsPluginInstance.js +247 -240
- package/browser/index.js +1 -1
- 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 +2 -1
- package/cjs/SoundsPluginInstance.js +247 -240
- package/cjs/index.js +1 -1
- package/dist_browser_SoundsPluginInstance_js.js +3 -3
- package/dist_browser_SoundsPlugin_js.js +12 -12
- 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 +2 -1
- package/esm/SoundsPluginInstance.js +247 -240
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.sounds.js +31 -19
- package/tsparticles.plugin.sounds.min.js +2 -2
- package/types/SoundsPlugin.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 +2 -1
- package/umd/SoundsPluginInstance.js +247 -240
- package/umd/index.js +1 -1
- package/296.min.js +0 -2
- package/296.min.js.LICENSE.txt +0 -1
- package/340.min.js +0 -2
- package/340.min.js.LICENSE.txt +0 -1
- package/tsparticles.plugin.sounds.min.js.LICENSE.txt +0 -1
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
function initImage(data) {
|
|
19
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
20
|
setIconStyle(img, pos.top + margin, pos.right -
|
|
21
|
-
(margin * (rightOffsets.length + rightOffset) +
|
|
22
|
-
width +
|
|
23
|
-
rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
|
|
21
|
+
(margin * (rightOffsets.length + rightOffset) + width + rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
|
|
24
22
|
img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
|
|
25
23
|
const parent = container.canvas.element?.parentNode ?? (0, engine_1.safeDocument)().body;
|
|
26
24
|
parent.append(img);
|
|
@@ -45,242 +43,17 @@
|
|
|
45
43
|
icon.style.cssText += style;
|
|
46
44
|
}
|
|
47
45
|
class SoundsPluginInstance {
|
|
46
|
+
_audioMap;
|
|
47
|
+
_audioSources;
|
|
48
|
+
_container;
|
|
49
|
+
_engine;
|
|
50
|
+
_gain;
|
|
51
|
+
_muteImg;
|
|
52
|
+
_unmuteImg;
|
|
53
|
+
_volume;
|
|
54
|
+
_volumeDownImg;
|
|
55
|
+
_volumeUpImg;
|
|
48
56
|
constructor(container, engine) {
|
|
49
|
-
this._addBuffer = audioCtx => {
|
|
50
|
-
const buffer = audioCtx.createBufferSource();
|
|
51
|
-
this._audioSources.push(buffer);
|
|
52
|
-
return buffer;
|
|
53
|
-
};
|
|
54
|
-
this._addOscillator = audioCtx => {
|
|
55
|
-
const oscillator = audioCtx.createOscillator();
|
|
56
|
-
this._audioSources.push(oscillator);
|
|
57
|
-
return oscillator;
|
|
58
|
-
};
|
|
59
|
-
this._initEvents = () => {
|
|
60
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
61
|
-
if (!soundsOptions?.enable || !container.canvas.element) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
for (const event of soundsOptions.events) {
|
|
65
|
-
const cb = (args) => {
|
|
66
|
-
if (!args) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
void (async () => {
|
|
70
|
-
const filterNotValid = event.filter && !event.filter(args);
|
|
71
|
-
if (this._container !== args.container) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (!!this._container.muted || this._container.destroyed) {
|
|
75
|
-
(0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
|
|
76
|
-
this._engine.removeEventListener(item, cb);
|
|
77
|
-
});
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (filterNotValid) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const defaultNoteIndex = 0;
|
|
84
|
-
if (event.audio) {
|
|
85
|
-
const audio = (0, engine_1.itemFromSingleOrMultiple)(event.audio);
|
|
86
|
-
if (!audio) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this._playBuffer(audio);
|
|
90
|
-
}
|
|
91
|
-
else if (event.melodies) {
|
|
92
|
-
const melody = (0, engine_1.itemFromArray)(event.melodies);
|
|
93
|
-
if (!melody) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (melody.melodies.length) {
|
|
97
|
-
await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (event.notes) {
|
|
104
|
-
const note = (0, engine_1.itemFromArray)(event.notes);
|
|
105
|
-
if (!note) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
await this._playNote([note], defaultNoteIndex, false);
|
|
109
|
-
}
|
|
110
|
-
})();
|
|
111
|
-
};
|
|
112
|
-
(0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
|
|
113
|
-
this._engine.addEventListener(item, cb);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
this._mute = async () => {
|
|
118
|
-
const container = this._container, audioContext = this._getAudioContext();
|
|
119
|
-
for (const source of this._audioSources) {
|
|
120
|
-
this._removeAudioSource(source);
|
|
121
|
-
}
|
|
122
|
-
if (this._gain) {
|
|
123
|
-
this._gain.disconnect();
|
|
124
|
-
}
|
|
125
|
-
await audioContext.close();
|
|
126
|
-
container.audioContext = undefined;
|
|
127
|
-
this._engine.dispatchEvent(enums_js_1.SoundsEventType.mute, { container: this._container });
|
|
128
|
-
};
|
|
129
|
-
this._playBuffer = audio => {
|
|
130
|
-
const audioBuffer = this._audioMap.get(audio.source);
|
|
131
|
-
if (!audioBuffer) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const audioCtx = this._container.audioContext;
|
|
135
|
-
if (!audioCtx) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const source = this._addBuffer(audioCtx);
|
|
139
|
-
source.loop = audio.loop;
|
|
140
|
-
source.buffer = audioBuffer;
|
|
141
|
-
source.connect(this._gain ?? audioCtx.destination);
|
|
142
|
-
source.start();
|
|
143
|
-
};
|
|
144
|
-
this._playFrequency = async (frequency, duration) => {
|
|
145
|
-
if (!this._gain || this._container.muted) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const audioContext = this._getAudioContext(), oscillator = this._addOscillator(audioContext);
|
|
149
|
-
oscillator.connect(this._gain);
|
|
150
|
-
oscillator.type = "sine";
|
|
151
|
-
oscillator.frequency.value = frequency;
|
|
152
|
-
oscillator.start();
|
|
153
|
-
return new Promise(resolve => {
|
|
154
|
-
setTimeout(() => {
|
|
155
|
-
this._removeAudioSource(oscillator);
|
|
156
|
-
resolve();
|
|
157
|
-
}, duration);
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
this._playMuteSound = () => {
|
|
161
|
-
if (this._container.muted) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
165
|
-
gain.connect(audioContext.destination);
|
|
166
|
-
gain.gain.value = 0;
|
|
167
|
-
const oscillator = audioContext.createOscillator();
|
|
168
|
-
oscillator.connect(gain);
|
|
169
|
-
oscillator.type = "sine";
|
|
170
|
-
oscillator.frequency.value = 1;
|
|
171
|
-
oscillator.start();
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
oscillator.stop();
|
|
174
|
-
oscillator.disconnect();
|
|
175
|
-
gain.disconnect();
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
this._playNote = async (notes, noteIdx, loop) => {
|
|
179
|
-
if (this._container.muted) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const note = notes[noteIdx];
|
|
183
|
-
if (!note) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const value = note.value, promises = (0, engine_1.executeOnSingleOrMultiple)(value, async (_, idx) => {
|
|
187
|
-
return this._playNoteValue(notes, noteIdx, idx);
|
|
188
|
-
});
|
|
189
|
-
await ((0, engine_1.isArray)(promises) ? Promise.allSettled(promises) : promises);
|
|
190
|
-
const indexOffset = 1;
|
|
191
|
-
let nextNoteIdx = noteIdx + indexOffset;
|
|
192
|
-
if (loop && nextNoteIdx >= notes.length) {
|
|
193
|
-
nextNoteIdx = nextNoteIdx % notes.length;
|
|
194
|
-
}
|
|
195
|
-
await this._playNote(notes, nextNoteIdx, loop);
|
|
196
|
-
};
|
|
197
|
-
this._playNoteValue = async (notes, noteIdx, valueIdx) => {
|
|
198
|
-
const note = notes[noteIdx];
|
|
199
|
-
if (!note) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const value = (0, engine_1.itemFromSingleOrMultiple)(note.value, valueIdx, true);
|
|
203
|
-
if (!value) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
const freq = (0, utils_js_1.getNoteFrequency)(value);
|
|
208
|
-
if (!(0, engine_1.isNumber)(freq)) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
await this._playFrequency(freq, note.duration);
|
|
212
|
-
}
|
|
213
|
-
catch (e) {
|
|
214
|
-
(0, engine_1.getLogger)().error(e);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
this._removeAudioSource = source => {
|
|
218
|
-
source.stop();
|
|
219
|
-
source.disconnect();
|
|
220
|
-
const deleteCount = 1;
|
|
221
|
-
this._audioSources.splice(this._audioSources.indexOf(source), deleteCount);
|
|
222
|
-
};
|
|
223
|
-
this._unmute = () => {
|
|
224
|
-
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
225
|
-
if (!soundsOptions) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
229
|
-
gain.connect(audioContext.destination);
|
|
230
|
-
gain.gain.value = soundsOptions.volume.value / engine_1.percentDenominator;
|
|
231
|
-
this._gain = gain;
|
|
232
|
-
this._initEvents();
|
|
233
|
-
this._engine.dispatchEvent(enums_js_1.SoundsEventType.unmute, { container: this._container });
|
|
234
|
-
};
|
|
235
|
-
this._updateMuteIcons = () => {
|
|
236
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
237
|
-
if (!soundsOptions?.enable || !soundsOptions.icons.enable) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const muteImg = this._muteImg, unmuteImg = this._unmuteImg;
|
|
241
|
-
if (muteImg) {
|
|
242
|
-
muteImg.style.display = container.muted ? "block" : "none";
|
|
243
|
-
}
|
|
244
|
-
if (unmuteImg) {
|
|
245
|
-
unmuteImg.style.display = container.muted ? "none" : "block";
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
this._updateMuteStatus = async () => {
|
|
249
|
-
const container = this._container, audioContext = this._getAudioContext();
|
|
250
|
-
if (container.muted) {
|
|
251
|
-
await audioContext.suspend();
|
|
252
|
-
await this._mute();
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
await audioContext.resume();
|
|
256
|
-
this._unmute();
|
|
257
|
-
this._playMuteSound();
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
this._updateVolume = async () => {
|
|
261
|
-
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
262
|
-
if (!soundsOptions?.enable) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
(0, engine_1.clamp)(this._volume, soundsOptions.volume.min, soundsOptions.volume.max);
|
|
266
|
-
let stateChanged = false;
|
|
267
|
-
if (this._volume <= minVolume && !container.muted) {
|
|
268
|
-
this._volume = 0;
|
|
269
|
-
container.muted = true;
|
|
270
|
-
stateChanged = true;
|
|
271
|
-
}
|
|
272
|
-
else if (this._volume > minVolume && container.muted) {
|
|
273
|
-
container.muted = false;
|
|
274
|
-
stateChanged = true;
|
|
275
|
-
}
|
|
276
|
-
if (stateChanged) {
|
|
277
|
-
this._updateMuteIcons();
|
|
278
|
-
await this._updateMuteStatus();
|
|
279
|
-
}
|
|
280
|
-
if (this._gain?.gain) {
|
|
281
|
-
this._gain.gain.value = this._volume / engine_1.percentDenominator;
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
57
|
this._container = container;
|
|
285
58
|
this._engine = engine;
|
|
286
59
|
this._volume = 0;
|
|
@@ -298,8 +71,7 @@
|
|
|
298
71
|
removeEventListener(constants_js_1.touchStartEvent, firstClickHandler);
|
|
299
72
|
(0, utils_js_1.unmuteWindow)();
|
|
300
73
|
void this.unmute();
|
|
301
|
-
}
|
|
302
|
-
const listenerOptions = {
|
|
74
|
+
}, listenerOptions = {
|
|
303
75
|
capture: true,
|
|
304
76
|
once: true,
|
|
305
77
|
};
|
|
@@ -434,11 +206,246 @@
|
|
|
434
206
|
this._volume += soundsOptions.volume.step;
|
|
435
207
|
await this._updateVolume();
|
|
436
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
|
+
};
|
|
437
219
|
_getAudioContext() {
|
|
438
220
|
const container = this._container;
|
|
439
221
|
container.audioContext ??= new AudioContext();
|
|
440
222
|
return container.audioContext;
|
|
441
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._engine.dispatchEvent(enums_js_1.SoundsEventType.mute, { container: this._container });
|
|
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._engine.dispatchEvent(enums_js_1.SoundsEventType.unmute, { container: this._container });
|
|
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
|
+
};
|
|
442
449
|
}
|
|
443
450
|
exports.SoundsPluginInstance = SoundsPluginInstance;
|
|
444
451
|
});
|
package/umd/index.js
CHANGED
|
@@ -45,7 +45,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.loadSoundsPlugin = loadSoundsPlugin;
|
|
47
47
|
async function loadSoundsPlugin(engine) {
|
|
48
|
-
engine.checkVersion("4.0.0-
|
|
48
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
49
49
|
await engine.register(async (e) => {
|
|
50
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
51
|
e.addPlugin(new SoundsPlugin(engine));
|
package/296.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 296.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_plugin_sounds=this.webpackChunk_tsparticles_plugin_sounds||[]).push([[296],{193(s,t,e){e.d(t,{m:()=>i,s:()=>n});const i="pointerdown",n="touchstart"},296(s,t,e){e.d(t,{SoundsPlugin:()=>w});var i=e(193),n=e(303);class o{constructor(){this.loop=!1,this.source=""}load(s){(0,n.isNull)(s)||((0,n.isObject)(s)?(void 0!==s.loop&&(this.loop=s.loop),void 0!==s.source&&(this.source=s.source)):this.source=s)}}class l{constructor(){this.duration=500,this.value=[]}load(s){(0,n.isNull)(s)||(void 0!==s.duration&&(this.duration=s.duration),void 0!==s.value&&(this.value=s.value))}}class c{constructor(){this.loop=!1,this.melodies=[],this.notes=[]}load(s){(0,n.isNull)(s)||(void 0!==s.loop&&(this.loop=s.loop),void 0!==s.melodies&&(this.melodies=s.melodies.map((s=>{const t=new c;return t.load(s),t}))),void 0!==s.notes&&(this.notes=s.notes.map((s=>{const t=new l;return t.load(s),t}))))}}class a{constructor(){this.event=[],this.notes=[]}load(s){if(!(0,n.isNull)(s)&&(void 0!==s.event&&(this.event=s.event),void 0!==s.audio&&((0,n.isArray)(s.audio)?this.audio=s.audio.map((s=>{const t=new o;return t.load(s),t})):(this.audio=new o,this.audio.load(s.audio))),void 0!==s.notes&&(this.notes=s.notes.map((s=>{const t=new l;return t.load(s),t}))),void 0!==s.melodies&&(this.melodies=s.melodies.map((s=>{const t=new c;return t.load(s),t}))),s.filter))if((0,n.isString)(s.filter)){const t=globalThis[s.filter];(0,n.isFunction)(t)&&(this.filter=t)}else this.filter=s.filter}}class h{constructor(){this.width=24,this.height=24,this.style=""}load(s){(0,n.isNull)(s)||(void 0!==s.path&&(this.path=s.path),void 0!==s.svg&&(this.svg=s.svg),void 0!==s.width&&(this.width=s.width),void 0!==s.height&&(this.height=s.height))}}class d{constructor(){this.mute=new h,this.unmute=new h,this.volumeDown=new h,this.volumeUp=new h,this.enable=!1,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>',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>',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>',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>'}load(s){(0,n.isNull)(s)||(void 0!==s.enable&&(this.enable=s.enable),this.mute.load(s.mute),this.unmute.load(s.unmute),this.volumeDown.load(s.volumeDown),this.volumeUp.load(s.volumeUp))}}class v{constructor(){this.value=100,this.max=100,this.min=0,this.step=10}load(s){(0,n.isNull)(s)||((0,n.isObject)(s)?(void 0!==s.max&&(this.max=s.max),void 0!==s.min&&(this.min=s.min),void 0!==s.step&&(this.step=s.step),void 0!==s.value&&(this.value=s.value)):this.value=s)}}class u{constructor(){this.autoPlay=!0,this.enable=!1,this.events=[],this.icons=new d,this.volume=new v}load(s){(0,n.isNull)(s)||(void 0!==s.autoPlay&&(this.autoPlay=s.autoPlay),void 0!==s.enable&&(this.enable=s.enable),void 0!==s.events&&(this.events=s.events.map((s=>{const t=new a;return t.load(s),t}))),this.icons.load(s.icons),void 0!==s.volume&&this.volume.load(s.volume))}}var r=e(669);const p=()=>{removeEventListener(i.m,p),removeEventListener(i.s,p),(0,r.XK)()};class w{constructor(s){this.id="sounds",this._engine=s;const t={capture:!0,once:!0};addEventListener(i.m,p,t),addEventListener(i.s,p,t)}async getPlugin(s){const{SoundsPluginInstance:t}=await e.e(340).then(e.bind(e,340));return new t(s,this._engine)}loadOptions(s,t,e){if(!this.needsPlugin(t)&&!this.needsPlugin(e))return;let i=t.sounds;void 0===i?.load&&(t.sounds=i=new u),i.load(e?.sounds)}needsPlugin(s){return s?.sounds?.enable??!1}}},669(s,t,e){e.d(t,{E3:()=>l,XK:()=>c,jE:()=>n});const i=new Map;function n(s){const t=/(([A-G]b?)(\d))|pause/i.exec(s);if(!t?.length)return;const e=t[2]??t[0],n=i.get(e);return n?n[parseInt(t[3]??"0")]:void 0}i.set("C",[16.35,32.7,65.41,130.81,261.63,523.25,1046.5,2093,4186.01]),i.set("Db",[17.32,34.65,69.3,138.59,277.18,554.37,1108.73,2217.46,4434.92]),i.set("D",[18.35,36.71,73.42,146.83,293.66,587.33,1174.66,2349.32,4698.63]),i.set("Eb",[19.45,38.89,77.78,155.56,311.13,622.25,1244.51,2489.02,4978.03]),i.set("E",[20.6,41.2,82.41,164.81,329.63,659.25,1318.51,2637.02,5274.04]),i.set("F",[21.83,43.65,87.31,174.61,349.23,698.46,1396.91,2793.83,5587.65]),i.set("Gb",[23.12,46.25,92.5,185,369.99,739.99,1479.98,2959.96,5919.91]),i.set("G",[24.5,49,98,196,392,783.99,1567.98,3135.96,6271.93]),i.set("Ab",[25.96,51.91,103.83,207.65,415.3,830.61,1661.22,3322.44,6644.88]),i.set("A",[27.5,55,110,220,440,880,1760,3520,7040]),i.set("Bb",[29.14,58.27,116.54,233.08,466.16,932.33,1864.66,3729.31,7458.62]),i.set("B",[30.87,61.74,123.47,246.94,493.88,987.77,1975.53,3951.07,7902.13]),i.set("pause",[0]);let o=!0;const l=()=>o,c=()=>{o=!1}}}]);
|
package/296.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Sounds Plugin v4.0.0-alpha.5 by Matteo Bruni */
|
package/340.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 340.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_plugin_sounds=this.webpackChunk_tsparticles_plugin_sounds||[]).push([[340],{340(t,e,n){n.d(e,{SoundsPluginInstance:()=>l});var i,s,o=n(303);!function(t){t.mute="soundsMuted",t.unmute="soundsUnmuted"}(i||(i={})),function(t){t.Block="block",t.None="none"}(s||(s={}));var a=n(669),u=n(193);function c(t){const e=(0,o.safeDocument)().createElement("img"),{clickCb:n,container:i,display:s,iconOptions:a,margin:u,options:c,pos:r,rightOffsets:l}=t,{width:h,path:d,style:m,svg:_}=a;!function(t,e,n,i,s,o,a,u){t.style.userSelect="none",t.style.position="absolute",t.style.top=`${(e+a).toString()}px`,t.style.left=`${(n-a-o).toString()}px`,t.style.display=i,t.style.zIndex=(s+1).toString(),t.style.cssText+=u}(e,r.top+u,r.right-(u*(l.length+1)+h+l.reduce(((t,e)=>t+e),0)),s,c.fullScreen.zIndex+1,h,u,m),e.src=d??(_?`data:image/svg+xml;base64,${btoa(_)}`:"");return(i.canvas.element?.parentNode??(0,o.safeDocument)().body).append(e),e.addEventListener("click",(()=>{n()})),e}function r(t){t&&t.remove()}class l{constructor(t,e){this._addBuffer=t=>{const e=t.createBufferSource();return this._audioSources.push(e),e},this._addOscillator=t=>{const e=t.createOscillator();return this._audioSources.push(e),e},this._initEvents=()=>{const t=this._container,e=t.actualOptions.sounds;if(e?.enable&&t.canvas.element)for(const t of e.events){const e=n=>{n&&(async()=>{const i=t.filter&&!t.filter(n);if(this._container!==n.container)return;if(this._container.muted||this._container.destroyed)return void(0,o.executeOnSingleOrMultiple)(t.event,(t=>{this._engine.removeEventListener(t,e)}));if(i)return;if(t.audio){const e=(0,o.itemFromSingleOrMultiple)(t.audio);if(!e)return;this._playBuffer(e)}else if(t.melodies){const e=(0,o.itemFromArray)(t.melodies);if(!e)return;e.melodies.length?await Promise.allSettled(e.melodies.map((t=>this._playNote(t.notes,0,e.loop)))):await this._playNote(e.notes,0,e.loop)}else if(t.notes){const e=(0,o.itemFromArray)(t.notes);if(!e)return;await this._playNote([e],0,!1)}})()};(0,o.executeOnSingleOrMultiple)(t.event,(t=>{this._engine.addEventListener(t,e)}))}},this._mute=async()=>{const t=this._container,e=this._getAudioContext();for(const t of this._audioSources)this._removeAudioSource(t);this._gain&&this._gain.disconnect(),await e.close(),t.audioContext=void 0,this._engine.dispatchEvent(i.mute,{container:this._container})},this._playBuffer=t=>{const e=this._audioMap.get(t.source);if(!e)return;const n=this._container.audioContext;if(!n)return;const i=this._addBuffer(n);i.loop=t.loop,i.buffer=e,i.connect(this._gain??n.destination),i.start()},this._playFrequency=async(t,e)=>{if(!this._gain||this._container.muted)return;const n=this._getAudioContext(),i=this._addOscillator(n);return i.connect(this._gain),i.type="sine",i.frequency.value=t,i.start(),new Promise((t=>{setTimeout((()=>{this._removeAudioSource(i),t()}),e)}))},this._playMuteSound=()=>{if(this._container.muted)return;const t=this._getAudioContext(),e=t.createGain();e.connect(t.destination),e.gain.value=0;const n=t.createOscillator();n.connect(e),n.type="sine",n.frequency.value=1,n.start(),setTimeout((()=>{n.stop(),n.disconnect(),e.disconnect()}))},this._playNote=async(t,e,n)=>{if(this._container.muted)return;const i=t[e];if(!i)return;const s=i.value,a=(0,o.executeOnSingleOrMultiple)(s,(async(n,i)=>this._playNoteValue(t,e,i)));await((0,o.isArray)(a)?Promise.allSettled(a):a);let u=e+1;n&&u>=t.length&&(u%=t.length),await this._playNote(t,u,n)},this._playNoteValue=async(t,e,n)=>{const i=t[e];if(!i)return;const s=(0,o.itemFromSingleOrMultiple)(i.value,n,!0);if(s)try{const t=(0,a.jE)(s);if(!(0,o.isNumber)(t))return;await this._playFrequency(t,i.duration)}catch(t){(0,o.getLogger)().error(t)}},this._removeAudioSource=t=>{t.stop(),t.disconnect();this._audioSources.splice(this._audioSources.indexOf(t),1)},this._unmute=()=>{const t=this._container.actualOptions.sounds;if(!t)return;const e=this._getAudioContext(),n=e.createGain();n.connect(e.destination),n.gain.value=t.volume.value/o.percentDenominator,this._gain=n,this._initEvents(),this._engine.dispatchEvent(i.unmute,{container:this._container})},this._updateMuteIcons=()=>{const t=this._container,e=t.actualOptions.sounds;if(!e?.enable||!e.icons.enable)return;const n=this._muteImg,i=this._unmuteImg;n&&(n.style.display=t.muted?"block":"none"),i&&(i.style.display=t.muted?"none":"block")},this._updateMuteStatus=async()=>{const t=this._container,e=this._getAudioContext();t.muted?(await e.suspend(),await this._mute()):(await e.resume(),this._unmute(),this._playMuteSound())},this._updateVolume=async()=>{const t=this._container,e=t.actualOptions.sounds;if(!e?.enable)return;(0,o.clamp)(this._volume,e.volume.min,e.volume.max);let n=!1;this._volume<=0&&!t.muted?(this._volume=0,t.muted=!0,n=!0):this._volume>0&&t.muted&&(t.muted=!1,n=!0),n&&(this._updateMuteIcons(),await this._updateMuteStatus()),this._gain?.gain&&(this._gain.gain.value=this._volume/o.percentDenominator)},this._container=t,this._engine=e,this._volume=0,this._audioSources=[],this._audioMap=new Map}async init(){const t=this._container.actualOptions.sounds;if(!t?.enable)return;if(t.autoPlay&&(0,a.E3)()){const t=()=>{removeEventListener(u.m,t),removeEventListener(u.s,t),(0,a.XK)(),this.unmute()},e={capture:!0,once:!0};addEventListener(u.m,t,e),addEventListener(u.s,t,e)}this._volume=t.volume.value;const e=t.events;this._audioMap=new Map;for(const t of e){if(!t.audio)continue;const e=(0,o.executeOnSingleOrMultiple)(t.audio,(async t=>{const e=await fetch(t.source);if(!e.ok)return;const n=await e.arrayBuffer(),i=this._getAudioContext(),s=await i.decodeAudioData(n);this._audioMap.set(t.source,s)}));e instanceof Promise?await e:await Promise.allSettled(e)}}async mute(){this._container.muted||await this.toggleMute()}async start(){const t=this._container,e=t.actualOptions,n=e.sounds;if(!n?.enable||!t.canvas.element)return;t.muted=!0;const i=t.canvas.element,o={top:i.offsetTop,right:i.offsetLeft+i.offsetWidth},{mute:u,unmute:r,volumeDown:l,volumeUp:h}=n.icons,d=async()=>{await this.toggleMute()},m=n.icons.enable?s.Block:s.None;this._muteImg=c({container:t,options:e,pos:o,display:m,iconOptions:u,margin:10,rightOffsets:[l.width,h.width],clickCb:d}),this._unmuteImg=c({container:t,options:e,pos:o,display:s.None,iconOptions:r,margin:10,rightOffsets:[l.width,h.width],clickCb:d}),this._volumeDownImg=c({container:t,options:e,pos:o,display:m,iconOptions:l,margin:10,rightOffsets:[h.width],clickCb:async()=>{await this.volumeDown()}}),this._volumeUpImg=c({container:t,options:e,pos:o,display:m,iconOptions:h,margin:10,rightOffsets:[],clickCb:async()=>{await this.volumeUp()}}),!(0,a.E3)()&&n.autoPlay&&await this.unmute()}stop(){this._container.muted=!0,(async()=>{await this._mute(),r(this._muteImg),r(this._unmuteImg),r(this._volumeDownImg),r(this._volumeUpImg)})()}async toggleMute(){const t=this._container;t.muted=!t.muted,this._updateMuteIcons(),await this._updateMuteStatus()}async unmute(){this._container.muted&&await this.toggleMute()}async volumeDown(){const t=this._container,e=t.actualOptions.sounds;e?.enable&&(t.muted&&(this._volume=0),this._volume-=e.volume.step,await this._updateVolume())}async volumeUp(){const t=this._container.actualOptions.sounds;t?.enable&&(this._volume+=t.volume.step,await this._updateVolume())}_getAudioContext(){const t=this._container;return t.audioContext??=new AudioContext,t.audioContext}}}}]);
|
package/340.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Sounds Plugin v4.0.0-alpha.5 by Matteo Bruni */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Sounds Plugin v4.0.0-alpha.5 by Matteo Bruni */
|