@tsparticles/plugin-sounds 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/browser/Options/Classes/Sounds.js +1 -1
  2. package/browser/Options/Classes/SoundsEvent.js +3 -3
  3. package/browser/Options/Classes/SoundsMelody.js +2 -2
  4. package/browser/SoundsInstance.js +13 -12
  5. package/browser/SoundsPlugin.js +3 -3
  6. package/browser/enums.js +10 -1
  7. package/browser/index.js +1 -1
  8. package/cjs/Options/Classes/Sounds.js +1 -1
  9. package/cjs/Options/Classes/SoundsEvent.js +3 -3
  10. package/cjs/Options/Classes/SoundsMelody.js +2 -2
  11. package/cjs/SoundsInstance.js +13 -12
  12. package/cjs/SoundsPlugin.js +3 -3
  13. package/cjs/enums.js +11 -0
  14. package/cjs/index.js +2 -2
  15. package/esm/Options/Classes/Sounds.js +1 -1
  16. package/esm/Options/Classes/SoundsEvent.js +3 -3
  17. package/esm/Options/Classes/SoundsMelody.js +2 -2
  18. package/esm/SoundsInstance.js +13 -12
  19. package/esm/SoundsPlugin.js +3 -3
  20. package/esm/enums.js +10 -1
  21. package/esm/index.js +1 -1
  22. package/package.json +2 -2
  23. package/report.html +1 -1
  24. package/tsparticles.plugin.sounds.js +122 -200
  25. package/tsparticles.plugin.sounds.min.js +1 -1
  26. package/tsparticles.plugin.sounds.min.js.LICENSE.txt +1 -1
  27. package/types/SoundsPlugin.d.ts +1 -1
  28. package/types/enums.d.ts +2 -2
  29. package/umd/Options/Classes/Sounds.js +1 -1
  30. package/umd/Options/Classes/SoundsEvent.js +3 -3
  31. package/umd/Options/Classes/SoundsMelody.js +2 -2
  32. package/umd/SoundsInstance.js +14 -13
  33. package/umd/SoundsPlugin.js +4 -28
  34. package/umd/enums.js +11 -0
  35. package/umd/index.js +3 -27
  36. package/826.min.js +0 -2
  37. package/826.min.js.LICENSE.txt +0 -1
  38. package/999.min.js +0 -2
  39. package/999.min.js.LICENSE.txt +0 -1
  40. package/dist_browser_SoundsInstance_js.js +0 -30
  41. package/dist_browser_SoundsPlugin_js.js +0 -120
@@ -20,7 +20,7 @@ export class Sounds {
20
20
  this.enable = data.enable;
21
21
  }
22
22
  if (data.events !== undefined) {
23
- this.events = data.events.map((t) => {
23
+ this.events = data.events.map(t => {
24
24
  const event = new SoundsEvent();
25
25
  event.load(t);
26
26
  return event;
@@ -16,7 +16,7 @@ export class SoundsEvent {
16
16
  }
17
17
  if (data.audio !== undefined) {
18
18
  if (isArray(data.audio)) {
19
- this.audio = data.audio.map((s) => {
19
+ this.audio = data.audio.map(s => {
20
20
  const tmp = new SoundsAudio();
21
21
  tmp.load(s);
22
22
  return tmp;
@@ -28,14 +28,14 @@ export class SoundsEvent {
28
28
  }
29
29
  }
30
30
  if (data.notes !== undefined) {
31
- this.notes = data.notes.map((t) => {
31
+ this.notes = data.notes.map(t => {
32
32
  const tmp = new SoundsNote();
33
33
  tmp.load(t);
34
34
  return tmp;
35
35
  });
36
36
  }
37
37
  if (data.melodies !== undefined) {
38
- this.melodies = data.melodies.map((t) => {
38
+ this.melodies = data.melodies.map(t => {
39
39
  const tmp = new SoundsMelody();
40
40
  tmp.load(t);
41
41
  return tmp;
@@ -13,14 +13,14 @@ export class SoundsMelody {
13
13
  this.loop = data.loop;
14
14
  }
15
15
  if (data.melodies !== undefined) {
16
- this.melodies = data.melodies.map((s) => {
16
+ this.melodies = data.melodies.map(s => {
17
17
  const tmp = new SoundsMelody();
18
18
  tmp.load(s);
19
19
  return tmp;
20
20
  });
21
21
  }
22
22
  if (data.notes !== undefined) {
23
- this.notes = data.notes.map((s) => {
23
+ this.notes = data.notes.map(s => {
24
24
  const tmp = new SoundsNote();
25
25
  tmp.load(s);
26
26
  return tmp;
@@ -1,4 +1,5 @@
1
1
  import { clamp, executeOnSingleOrMultiple, getLogger, isArray, isNumber, itemFromArray, itemFromSingleOrMultiple, mouseDownEvent, percentDenominator, touchStartEvent, } from "@tsparticles/engine";
2
+ import { ImageDisplay, SoundsEventType } from "./enums.js";
2
3
  import { getNoteFrequency, isWindowMuted, unmuteWindow } from "./utils.js";
3
4
  const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
4
5
  function initImage(data) {
@@ -33,12 +34,12 @@ function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
33
34
  }
34
35
  export class SoundsInstance {
35
36
  constructor(container, engine) {
36
- this._addBuffer = (audioCtx) => {
37
+ this._addBuffer = audioCtx => {
37
38
  const buffer = audioCtx.createBufferSource();
38
39
  this._audioSources.push(buffer);
39
40
  return buffer;
40
41
  };
41
- this._addOscillator = (audioCtx) => {
42
+ this._addOscillator = audioCtx => {
42
43
  const oscillator = audioCtx.createOscillator();
43
44
  this._audioSources.push(oscillator);
44
45
  return oscillator;
@@ -56,7 +57,7 @@ export class SoundsInstance {
56
57
  return;
57
58
  }
58
59
  if (!this._container || !!this._container.muted || this._container.destroyed) {
59
- executeOnSingleOrMultiple(event.event, (item) => {
60
+ executeOnSingleOrMultiple(event.event, item => {
60
61
  this._engine.removeEventListener(item, cb);
61
62
  });
62
63
  return;
@@ -71,7 +72,7 @@ export class SoundsInstance {
71
72
  else if (event.melodies) {
72
73
  const melody = itemFromArray(event.melodies);
73
74
  if (melody.melodies.length) {
74
- await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
75
+ await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
75
76
  }
76
77
  else {
77
78
  await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
@@ -83,7 +84,7 @@ export class SoundsInstance {
83
84
  }
84
85
  })();
85
86
  };
86
- executeOnSingleOrMultiple(event.event, (item) => {
87
+ executeOnSingleOrMultiple(event.event, item => {
87
88
  this._engine.addEventListener(item, cb);
88
89
  });
89
90
  }
@@ -98,9 +99,9 @@ export class SoundsInstance {
98
99
  }
99
100
  await audioContext.close();
100
101
  container.audioContext = undefined;
101
- this._engine.dispatchEvent("soundsMuted", { container: this._container });
102
+ this._engine.dispatchEvent(SoundsEventType.mute, { container: this._container });
102
103
  };
103
- this._playBuffer = (audio) => {
104
+ this._playBuffer = audio => {
104
105
  const audioBuffer = this._audioMap.get(audio.source);
105
106
  if (!audioBuffer) {
106
107
  return;
@@ -124,7 +125,7 @@ export class SoundsInstance {
124
125
  oscillator.type = "sine";
125
126
  oscillator.frequency.value = frequency;
126
127
  oscillator.start();
127
- return new Promise((resolve) => {
128
+ return new Promise(resolve => {
128
129
  setTimeout(() => {
129
130
  this._removeAudioSource(oscillator);
130
131
  resolve();
@@ -189,7 +190,7 @@ export class SoundsInstance {
189
190
  getLogger().error(e);
190
191
  }
191
192
  };
192
- this._removeAudioSource = (source) => {
193
+ this._removeAudioSource = source => {
193
194
  source.stop();
194
195
  source.disconnect();
195
196
  const deleteCount = 1;
@@ -209,7 +210,7 @@ export class SoundsInstance {
209
210
  gain.gain.value = soundsOptions.volume.value / percentDenominator;
210
211
  this._gain = gain;
211
212
  this._initEvents();
212
- this._engine.dispatchEvent("soundsUnmuted", { container: this._container });
213
+ this._engine.dispatchEvent(SoundsEventType.unmute, { container: this._container });
213
214
  };
214
215
  this._updateMuteIcons = () => {
215
216
  const container = this._container, soundsOptions = container.actualOptions.sounds;
@@ -324,7 +325,7 @@ export class SoundsInstance {
324
325
  right: canvas.offsetLeft + canvas.offsetWidth,
325
326
  }, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
326
327
  await this.toggleMute();
327
- }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? "block" : "none";
328
+ }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? ImageDisplay.Block : ImageDisplay.None;
328
329
  this._muteImg = initImage({
329
330
  container,
330
331
  options,
@@ -339,7 +340,7 @@ export class SoundsInstance {
339
340
  container,
340
341
  options,
341
342
  pos,
342
- display: "none",
343
+ display: ImageDisplay.None,
343
344
  iconOptions: unmute,
344
345
  margin,
345
346
  rightOffsets: [volumeDown.width, volumeUp.width],
@@ -1,5 +1,6 @@
1
1
  import { mouseDownEvent, touchStartEvent, } from "@tsparticles/engine";
2
2
  import { Sounds } from "./Options/Classes/Sounds.js";
3
+ import { SoundsInstance } from "./SoundsInstance.js";
3
4
  import { unmuteWindow } from "./utils.js";
4
5
  const generalFirstClickHandler = () => {
5
6
  removeEventListener(mouseDownEvent, generalFirstClickHandler);
@@ -17,9 +18,8 @@ export class SoundsPlugin {
17
18
  addEventListener(mouseDownEvent, generalFirstClickHandler, listenerOptions);
18
19
  addEventListener(touchStartEvent, generalFirstClickHandler, listenerOptions);
19
20
  }
20
- async getPlugin(container) {
21
- const { SoundsInstance } = await import("./SoundsInstance.js");
22
- return new SoundsInstance(container, this._engine);
21
+ getPlugin(container) {
22
+ return Promise.resolve(new SoundsInstance(container, this._engine));
23
23
  }
24
24
  loadOptions(options, source) {
25
25
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
package/browser/enums.js CHANGED
@@ -1 +1,10 @@
1
- export {};
1
+ export var SoundsEventType;
2
+ (function (SoundsEventType) {
3
+ SoundsEventType["mute"] = "soundsMuted";
4
+ SoundsEventType["unmute"] = "soundsUnmuted";
5
+ })(SoundsEventType || (SoundsEventType = {}));
6
+ export var ImageDisplay;
7
+ (function (ImageDisplay) {
8
+ ImageDisplay["Block"] = "block";
9
+ ImageDisplay["None"] = "none";
10
+ })(ImageDisplay || (ImageDisplay = {}));
package/browser/index.js CHANGED
@@ -1,4 +1,4 @@
1
+ import { SoundsPlugin } from "./SoundsPlugin.js";
1
2
  export async function loadSoundsPlugin(engine, refresh = true) {
2
- const { SoundsPlugin } = await import("./SoundsPlugin.js");
3
3
  await engine.addPlugin(new SoundsPlugin(engine), refresh);
4
4
  }
@@ -23,7 +23,7 @@ class Sounds {
23
23
  this.enable = data.enable;
24
24
  }
25
25
  if (data.events !== undefined) {
26
- this.events = data.events.map((t) => {
26
+ this.events = data.events.map(t => {
27
27
  const event = new SoundsEvent_js_1.SoundsEvent();
28
28
  event.load(t);
29
29
  return event;
@@ -19,7 +19,7 @@ class SoundsEvent {
19
19
  }
20
20
  if (data.audio !== undefined) {
21
21
  if ((0, engine_1.isArray)(data.audio)) {
22
- this.audio = data.audio.map((s) => {
22
+ this.audio = data.audio.map(s => {
23
23
  const tmp = new SoundsAudio_js_1.SoundsAudio();
24
24
  tmp.load(s);
25
25
  return tmp;
@@ -31,14 +31,14 @@ class SoundsEvent {
31
31
  }
32
32
  }
33
33
  if (data.notes !== undefined) {
34
- this.notes = data.notes.map((t) => {
34
+ this.notes = data.notes.map(t => {
35
35
  const tmp = new SoundsNote_js_1.SoundsNote();
36
36
  tmp.load(t);
37
37
  return tmp;
38
38
  });
39
39
  }
40
40
  if (data.melodies !== undefined) {
41
- this.melodies = data.melodies.map((t) => {
41
+ this.melodies = data.melodies.map(t => {
42
42
  const tmp = new SoundsMelody_js_1.SoundsMelody();
43
43
  tmp.load(t);
44
44
  return tmp;
@@ -16,14 +16,14 @@ class SoundsMelody {
16
16
  this.loop = data.loop;
17
17
  }
18
18
  if (data.melodies !== undefined) {
19
- this.melodies = data.melodies.map((s) => {
19
+ this.melodies = data.melodies.map(s => {
20
20
  const tmp = new SoundsMelody();
21
21
  tmp.load(s);
22
22
  return tmp;
23
23
  });
24
24
  }
25
25
  if (data.notes !== undefined) {
26
- this.notes = data.notes.map((s) => {
26
+ this.notes = data.notes.map(s => {
27
27
  const tmp = new SoundsNote_js_1.SoundsNote();
28
28
  tmp.load(s);
29
29
  return tmp;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SoundsInstance = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
+ const enums_js_1 = require("./enums.js");
5
6
  const utils_js_1 = require("./utils.js");
6
7
  const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
7
8
  function initImage(data) {
@@ -36,12 +37,12 @@ function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
36
37
  }
37
38
  class SoundsInstance {
38
39
  constructor(container, engine) {
39
- this._addBuffer = (audioCtx) => {
40
+ this._addBuffer = audioCtx => {
40
41
  const buffer = audioCtx.createBufferSource();
41
42
  this._audioSources.push(buffer);
42
43
  return buffer;
43
44
  };
44
- this._addOscillator = (audioCtx) => {
45
+ this._addOscillator = audioCtx => {
45
46
  const oscillator = audioCtx.createOscillator();
46
47
  this._audioSources.push(oscillator);
47
48
  return oscillator;
@@ -59,7 +60,7 @@ class SoundsInstance {
59
60
  return;
60
61
  }
61
62
  if (!this._container || !!this._container.muted || this._container.destroyed) {
62
- (0, engine_1.executeOnSingleOrMultiple)(event.event, (item) => {
63
+ (0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
63
64
  this._engine.removeEventListener(item, cb);
64
65
  });
65
66
  return;
@@ -74,7 +75,7 @@ class SoundsInstance {
74
75
  else if (event.melodies) {
75
76
  const melody = (0, engine_1.itemFromArray)(event.melodies);
76
77
  if (melody.melodies.length) {
77
- await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
78
+ await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
78
79
  }
79
80
  else {
80
81
  await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
@@ -86,7 +87,7 @@ class SoundsInstance {
86
87
  }
87
88
  })();
88
89
  };
89
- (0, engine_1.executeOnSingleOrMultiple)(event.event, (item) => {
90
+ (0, engine_1.executeOnSingleOrMultiple)(event.event, item => {
90
91
  this._engine.addEventListener(item, cb);
91
92
  });
92
93
  }
@@ -101,9 +102,9 @@ class SoundsInstance {
101
102
  }
102
103
  await audioContext.close();
103
104
  container.audioContext = undefined;
104
- this._engine.dispatchEvent("soundsMuted", { container: this._container });
105
+ this._engine.dispatchEvent(enums_js_1.SoundsEventType.mute, { container: this._container });
105
106
  };
106
- this._playBuffer = (audio) => {
107
+ this._playBuffer = audio => {
107
108
  const audioBuffer = this._audioMap.get(audio.source);
108
109
  if (!audioBuffer) {
109
110
  return;
@@ -127,7 +128,7 @@ class SoundsInstance {
127
128
  oscillator.type = "sine";
128
129
  oscillator.frequency.value = frequency;
129
130
  oscillator.start();
130
- return new Promise((resolve) => {
131
+ return new Promise(resolve => {
131
132
  setTimeout(() => {
132
133
  this._removeAudioSource(oscillator);
133
134
  resolve();
@@ -192,7 +193,7 @@ class SoundsInstance {
192
193
  (0, engine_1.getLogger)().error(e);
193
194
  }
194
195
  };
195
- this._removeAudioSource = (source) => {
196
+ this._removeAudioSource = source => {
196
197
  source.stop();
197
198
  source.disconnect();
198
199
  const deleteCount = 1;
@@ -212,7 +213,7 @@ class SoundsInstance {
212
213
  gain.gain.value = soundsOptions.volume.value / engine_1.percentDenominator;
213
214
  this._gain = gain;
214
215
  this._initEvents();
215
- this._engine.dispatchEvent("soundsUnmuted", { container: this._container });
216
+ this._engine.dispatchEvent(enums_js_1.SoundsEventType.unmute, { container: this._container });
216
217
  };
217
218
  this._updateMuteIcons = () => {
218
219
  const container = this._container, soundsOptions = container.actualOptions.sounds;
@@ -327,7 +328,7 @@ class SoundsInstance {
327
328
  right: canvas.offsetLeft + canvas.offsetWidth,
328
329
  }, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
329
330
  await this.toggleMute();
330
- }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? "block" : "none";
331
+ }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? enums_js_1.ImageDisplay.Block : enums_js_1.ImageDisplay.None;
331
332
  this._muteImg = initImage({
332
333
  container,
333
334
  options,
@@ -342,7 +343,7 @@ class SoundsInstance {
342
343
  container,
343
344
  options,
344
345
  pos,
345
- display: "none",
346
+ display: enums_js_1.ImageDisplay.None,
346
347
  iconOptions: unmute,
347
348
  margin,
348
349
  rightOffsets: [volumeDown.width, volumeUp.width],
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SoundsPlugin = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const Sounds_js_1 = require("./Options/Classes/Sounds.js");
6
+ const SoundsInstance_js_1 = require("./SoundsInstance.js");
6
7
  const utils_js_1 = require("./utils.js");
7
8
  const generalFirstClickHandler = () => {
8
9
  removeEventListener(engine_1.mouseDownEvent, generalFirstClickHandler);
@@ -20,9 +21,8 @@ class SoundsPlugin {
20
21
  addEventListener(engine_1.mouseDownEvent, generalFirstClickHandler, listenerOptions);
21
22
  addEventListener(engine_1.touchStartEvent, generalFirstClickHandler, listenerOptions);
22
23
  }
23
- async getPlugin(container) {
24
- const { SoundsInstance } = await import("./SoundsInstance.js");
25
- return new SoundsInstance(container, this._engine);
24
+ getPlugin(container) {
25
+ return Promise.resolve(new SoundsInstance_js_1.SoundsInstance(container, this._engine));
26
26
  }
27
27
  loadOptions(options, source) {
28
28
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
package/cjs/enums.js CHANGED
@@ -1,2 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImageDisplay = exports.SoundsEventType = void 0;
4
+ var SoundsEventType;
5
+ (function (SoundsEventType) {
6
+ SoundsEventType["mute"] = "soundsMuted";
7
+ SoundsEventType["unmute"] = "soundsUnmuted";
8
+ })(SoundsEventType || (exports.SoundsEventType = SoundsEventType = {}));
9
+ var ImageDisplay;
10
+ (function (ImageDisplay) {
11
+ ImageDisplay["Block"] = "block";
12
+ ImageDisplay["None"] = "none";
13
+ })(ImageDisplay || (exports.ImageDisplay = ImageDisplay = {}));
package/cjs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadSoundsPlugin = void 0;
4
+ const SoundsPlugin_js_1 = require("./SoundsPlugin.js");
4
5
  async function loadSoundsPlugin(engine, refresh = true) {
5
- const { SoundsPlugin } = await import("./SoundsPlugin.js");
6
- await engine.addPlugin(new SoundsPlugin(engine), refresh);
6
+ await engine.addPlugin(new SoundsPlugin_js_1.SoundsPlugin(engine), refresh);
7
7
  }
8
8
  exports.loadSoundsPlugin = loadSoundsPlugin;
@@ -20,7 +20,7 @@ export class Sounds {
20
20
  this.enable = data.enable;
21
21
  }
22
22
  if (data.events !== undefined) {
23
- this.events = data.events.map((t) => {
23
+ this.events = data.events.map(t => {
24
24
  const event = new SoundsEvent();
25
25
  event.load(t);
26
26
  return event;
@@ -16,7 +16,7 @@ export class SoundsEvent {
16
16
  }
17
17
  if (data.audio !== undefined) {
18
18
  if (isArray(data.audio)) {
19
- this.audio = data.audio.map((s) => {
19
+ this.audio = data.audio.map(s => {
20
20
  const tmp = new SoundsAudio();
21
21
  tmp.load(s);
22
22
  return tmp;
@@ -28,14 +28,14 @@ export class SoundsEvent {
28
28
  }
29
29
  }
30
30
  if (data.notes !== undefined) {
31
- this.notes = data.notes.map((t) => {
31
+ this.notes = data.notes.map(t => {
32
32
  const tmp = new SoundsNote();
33
33
  tmp.load(t);
34
34
  return tmp;
35
35
  });
36
36
  }
37
37
  if (data.melodies !== undefined) {
38
- this.melodies = data.melodies.map((t) => {
38
+ this.melodies = data.melodies.map(t => {
39
39
  const tmp = new SoundsMelody();
40
40
  tmp.load(t);
41
41
  return tmp;
@@ -13,14 +13,14 @@ export class SoundsMelody {
13
13
  this.loop = data.loop;
14
14
  }
15
15
  if (data.melodies !== undefined) {
16
- this.melodies = data.melodies.map((s) => {
16
+ this.melodies = data.melodies.map(s => {
17
17
  const tmp = new SoundsMelody();
18
18
  tmp.load(s);
19
19
  return tmp;
20
20
  });
21
21
  }
22
22
  if (data.notes !== undefined) {
23
- this.notes = data.notes.map((s) => {
23
+ this.notes = data.notes.map(s => {
24
24
  const tmp = new SoundsNote();
25
25
  tmp.load(s);
26
26
  return tmp;
@@ -1,4 +1,5 @@
1
1
  import { clamp, executeOnSingleOrMultiple, getLogger, isArray, isNumber, itemFromArray, itemFromSingleOrMultiple, mouseDownEvent, percentDenominator, touchStartEvent, } from "@tsparticles/engine";
2
+ import { ImageDisplay, SoundsEventType } from "./enums.js";
2
3
  import { getNoteFrequency, isWindowMuted, unmuteWindow } from "./utils.js";
3
4
  const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
4
5
  function initImage(data) {
@@ -33,12 +34,12 @@ function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
33
34
  }
34
35
  export class SoundsInstance {
35
36
  constructor(container, engine) {
36
- this._addBuffer = (audioCtx) => {
37
+ this._addBuffer = audioCtx => {
37
38
  const buffer = audioCtx.createBufferSource();
38
39
  this._audioSources.push(buffer);
39
40
  return buffer;
40
41
  };
41
- this._addOscillator = (audioCtx) => {
42
+ this._addOscillator = audioCtx => {
42
43
  const oscillator = audioCtx.createOscillator();
43
44
  this._audioSources.push(oscillator);
44
45
  return oscillator;
@@ -56,7 +57,7 @@ export class SoundsInstance {
56
57
  return;
57
58
  }
58
59
  if (!this._container || !!this._container.muted || this._container.destroyed) {
59
- executeOnSingleOrMultiple(event.event, (item) => {
60
+ executeOnSingleOrMultiple(event.event, item => {
60
61
  this._engine.removeEventListener(item, cb);
61
62
  });
62
63
  return;
@@ -71,7 +72,7 @@ export class SoundsInstance {
71
72
  else if (event.melodies) {
72
73
  const melody = itemFromArray(event.melodies);
73
74
  if (melody.melodies.length) {
74
- await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
75
+ await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
75
76
  }
76
77
  else {
77
78
  await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
@@ -83,7 +84,7 @@ export class SoundsInstance {
83
84
  }
84
85
  })();
85
86
  };
86
- executeOnSingleOrMultiple(event.event, (item) => {
87
+ executeOnSingleOrMultiple(event.event, item => {
87
88
  this._engine.addEventListener(item, cb);
88
89
  });
89
90
  }
@@ -98,9 +99,9 @@ export class SoundsInstance {
98
99
  }
99
100
  await audioContext.close();
100
101
  container.audioContext = undefined;
101
- this._engine.dispatchEvent("soundsMuted", { container: this._container });
102
+ this._engine.dispatchEvent(SoundsEventType.mute, { container: this._container });
102
103
  };
103
- this._playBuffer = (audio) => {
104
+ this._playBuffer = audio => {
104
105
  const audioBuffer = this._audioMap.get(audio.source);
105
106
  if (!audioBuffer) {
106
107
  return;
@@ -124,7 +125,7 @@ export class SoundsInstance {
124
125
  oscillator.type = "sine";
125
126
  oscillator.frequency.value = frequency;
126
127
  oscillator.start();
127
- return new Promise((resolve) => {
128
+ return new Promise(resolve => {
128
129
  setTimeout(() => {
129
130
  this._removeAudioSource(oscillator);
130
131
  resolve();
@@ -189,7 +190,7 @@ export class SoundsInstance {
189
190
  getLogger().error(e);
190
191
  }
191
192
  };
192
- this._removeAudioSource = (source) => {
193
+ this._removeAudioSource = source => {
193
194
  source.stop();
194
195
  source.disconnect();
195
196
  const deleteCount = 1;
@@ -209,7 +210,7 @@ export class SoundsInstance {
209
210
  gain.gain.value = soundsOptions.volume.value / percentDenominator;
210
211
  this._gain = gain;
211
212
  this._initEvents();
212
- this._engine.dispatchEvent("soundsUnmuted", { container: this._container });
213
+ this._engine.dispatchEvent(SoundsEventType.unmute, { container: this._container });
213
214
  };
214
215
  this._updateMuteIcons = () => {
215
216
  const container = this._container, soundsOptions = container.actualOptions.sounds;
@@ -324,7 +325,7 @@ export class SoundsInstance {
324
325
  right: canvas.offsetLeft + canvas.offsetWidth,
325
326
  }, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
326
327
  await this.toggleMute();
327
- }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? "block" : "none";
328
+ }, enableIcons = soundsOptions.icons.enable, display = enableIcons ? ImageDisplay.Block : ImageDisplay.None;
328
329
  this._muteImg = initImage({
329
330
  container,
330
331
  options,
@@ -339,7 +340,7 @@ export class SoundsInstance {
339
340
  container,
340
341
  options,
341
342
  pos,
342
- display: "none",
343
+ display: ImageDisplay.None,
343
344
  iconOptions: unmute,
344
345
  margin,
345
346
  rightOffsets: [volumeDown.width, volumeUp.width],
@@ -1,5 +1,6 @@
1
1
  import { mouseDownEvent, touchStartEvent, } from "@tsparticles/engine";
2
2
  import { Sounds } from "./Options/Classes/Sounds.js";
3
+ import { SoundsInstance } from "./SoundsInstance.js";
3
4
  import { unmuteWindow } from "./utils.js";
4
5
  const generalFirstClickHandler = () => {
5
6
  removeEventListener(mouseDownEvent, generalFirstClickHandler);
@@ -17,9 +18,8 @@ export class SoundsPlugin {
17
18
  addEventListener(mouseDownEvent, generalFirstClickHandler, listenerOptions);
18
19
  addEventListener(touchStartEvent, generalFirstClickHandler, listenerOptions);
19
20
  }
20
- async getPlugin(container) {
21
- const { SoundsInstance } = await import("./SoundsInstance.js");
22
- return new SoundsInstance(container, this._engine);
21
+ getPlugin(container) {
22
+ return Promise.resolve(new SoundsInstance(container, this._engine));
23
23
  }
24
24
  loadOptions(options, source) {
25
25
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
package/esm/enums.js CHANGED
@@ -1 +1,10 @@
1
- export {};
1
+ export var SoundsEventType;
2
+ (function (SoundsEventType) {
3
+ SoundsEventType["mute"] = "soundsMuted";
4
+ SoundsEventType["unmute"] = "soundsUnmuted";
5
+ })(SoundsEventType || (SoundsEventType = {}));
6
+ export var ImageDisplay;
7
+ (function (ImageDisplay) {
8
+ ImageDisplay["Block"] = "block";
9
+ ImageDisplay["None"] = "none";
10
+ })(ImageDisplay || (ImageDisplay = {}));
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
+ import { SoundsPlugin } from "./SoundsPlugin.js";
1
2
  export async function loadSoundsPlugin(engine, refresh = true) {
2
- const { SoundsPlugin } = await import("./SoundsPlugin.js");
3
3
  await engine.addPlugin(new SoundsPlugin(engine), refresh);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-sounds",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "tsParticles sounds plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -86,7 +86,7 @@
86
86
  "./package.json": "./package.json"
87
87
  },
88
88
  "dependencies": {
89
- "@tsparticles/engine": "^3.3.0"
89
+ "@tsparticles/engine": "^3.4.0"
90
90
  },
91
91
  "publishConfig": {
92
92
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/plugin-sounds [27 Feb 2024 at 12:19]</title>
6
+ <title>@tsparticles/plugin-sounds [13 May 2024 at 00:12]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYv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