@tsparticles/plugin-sounds 3.0.0-alpha.0 → 3.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.
Files changed (37) hide show
  1. package/README.md +15 -11
  2. package/browser/Options/Classes/SoundsAudio.js +2 -1
  3. package/browser/Options/Classes/SoundsEvent.js +4 -3
  4. package/browser/Options/Classes/SoundsVolume.js +2 -1
  5. package/browser/SoundsInstance.js +300 -279
  6. package/browser/index.js +6 -8
  7. package/browser/utils.js +0 -1
  8. package/cjs/Options/Classes/SoundsAudio.js +2 -1
  9. package/cjs/Options/Classes/SoundsEvent.js +4 -3
  10. package/cjs/Options/Classes/SoundsVolume.js +2 -1
  11. package/cjs/SoundsInstance.js +283 -281
  12. package/cjs/index.js +6 -19
  13. package/cjs/utils.js +0 -1
  14. package/esm/Options/Classes/SoundsAudio.js +2 -1
  15. package/esm/Options/Classes/SoundsEvent.js +4 -3
  16. package/esm/Options/Classes/SoundsVolume.js +2 -1
  17. package/esm/SoundsInstance.js +300 -279
  18. package/esm/index.js +6 -8
  19. package/esm/utils.js +0 -1
  20. package/package.json +6 -5
  21. package/report.html +4 -4
  22. package/tsparticles.plugin.sounds.js +343 -305
  23. package/tsparticles.plugin.sounds.min.js +1 -1
  24. package/tsparticles.plugin.sounds.min.js.LICENSE.txt +1 -8
  25. package/types/Options/Classes/SoundsAudio.d.ts +1 -1
  26. package/types/Options/Classes/SoundsEvent.d.ts +1 -1
  27. package/types/Options/Classes/SoundsVolume.d.ts +1 -1
  28. package/types/SoundsInstance.d.ts +15 -15
  29. package/types/enums.d.ts +4 -0
  30. package/types/index.d.ts +1 -1
  31. package/types/types.d.ts +16 -0
  32. package/umd/Options/Classes/SoundsAudio.js +3 -2
  33. package/umd/Options/Classes/SoundsEvent.js +5 -4
  34. package/umd/Options/Classes/SoundsVolume.js +3 -2
  35. package/umd/SoundsInstance.js +301 -280
  36. package/umd/index.js +6 -8
  37. package/umd/utils.js +0 -1
package/cjs/index.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.loadSoundsPlugin = void 0;
13
4
  const Sounds_1 = require("./Options/Classes/Sounds");
@@ -21,24 +12,20 @@ class SoundsPlugin {
21
12
  return new SoundsInstance_1.SoundsInstance(container, this._engine);
22
13
  }
23
14
  loadOptions(options, source) {
24
- if (!this.needsPlugin(source)) {
15
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
25
16
  return;
26
17
  }
27
18
  let soundsOptions = options.sounds;
28
- if ((soundsOptions === null || soundsOptions === void 0 ? void 0 : soundsOptions.load) === undefined) {
19
+ if (soundsOptions?.load === undefined) {
29
20
  options.sounds = soundsOptions = new Sounds_1.Sounds();
30
21
  }
31
- soundsOptions.load(source === null || source === void 0 ? void 0 : source.sounds);
22
+ soundsOptions.load(source?.sounds);
32
23
  }
33
24
  needsPlugin(options) {
34
- var _a, _b;
35
- return (_b = (_a = options === null || options === void 0 ? void 0 : options.sounds) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : false;
25
+ return options?.sounds?.enable ?? false;
36
26
  }
37
27
  }
38
- function loadSoundsPlugin(engine) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const plugin = new SoundsPlugin(engine);
41
- yield engine.addPlugin(plugin);
42
- });
28
+ async function loadSoundsPlugin(engine, refresh = true) {
29
+ await engine.addPlugin(new SoundsPlugin(engine), refresh);
43
30
  }
44
31
  exports.loadSoundsPlugin = loadSoundsPlugin;
package/cjs/utils.js CHANGED
@@ -20,7 +20,6 @@ function getNoteFrequency(note) {
20
20
  if (!result || !result.length) {
21
21
  return;
22
22
  }
23
- console.log(result);
24
23
  const noteKey = result[2] || result[0], noteItem = notes.get(noteKey);
25
24
  if (!noteItem) {
26
25
  return;
@@ -1,3 +1,4 @@
1
+ import { isObject } from "@tsparticles/engine";
1
2
  export class SoundsAudio {
2
3
  constructor() {
3
4
  this.loop = false;
@@ -7,7 +8,7 @@ export class SoundsAudio {
7
8
  if (data === undefined) {
8
9
  return;
9
10
  }
10
- if (typeof data === "object") {
11
+ if (isObject(data)) {
11
12
  if (data.loop !== undefined) {
12
13
  this.loop = data.loop;
13
14
  }
@@ -1,3 +1,4 @@
1
+ import { isArray, isFunction, isString, } from "@tsparticles/engine";
1
2
  import { SoundsAudio } from "./SoundsAudio";
2
3
  import { SoundsMelody } from "./SoundsMelody";
3
4
  import { SoundsNote } from "./SoundsNote";
@@ -14,7 +15,7 @@ export class SoundsEvent {
14
15
  this.event = data.event;
15
16
  }
16
17
  if (data.audio !== undefined) {
17
- if (data.audio instanceof Array) {
18
+ if (isArray(data.audio)) {
18
19
  this.audio = data.audio.map((s) => {
19
20
  const tmp = new SoundsAudio();
20
21
  tmp.load(s);
@@ -41,8 +42,8 @@ export class SoundsEvent {
41
42
  });
42
43
  }
43
44
  if (data.filter !== undefined) {
44
- if (typeof data.filter === "string") {
45
- if (typeof window[data.filter] === "function") {
45
+ if (isString(data.filter)) {
46
+ if (isFunction(window[data.filter])) {
46
47
  this.filter = window[data.filter];
47
48
  }
48
49
  }
@@ -1,3 +1,4 @@
1
+ import { isObject } from "@tsparticles/engine";
1
2
  export class SoundsVolume {
2
3
  constructor() {
3
4
  this.value = 100;
@@ -9,7 +10,7 @@ export class SoundsVolume {
9
10
  if (data === undefined) {
10
11
  return;
11
12
  }
12
- if (typeof data === "object") {
13
+ if (isObject(data)) {
13
14
  if (data.max !== undefined) {
14
15
  this.max = data.max;
15
16
  }