@eva/plugin-sound 1.1.1-beta.0 → 1.1.1-fix.2

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 (106) hide show
  1. package/dist/EVA.plugin.sound.js +731 -514
  2. package/dist/EVA.plugin.sound.min.js +1 -0
  3. package/dist/EVA.plugin.sound.min.js.map +1 -0
  4. package/dist/plugin-sound.cjs.js +33 -27
  5. package/dist/plugin-sound.cjs.prod.js +1 -0
  6. package/dist/plugin-sound.cjs.prod.js.map +1 -0
  7. package/dist/plugin-sound.esm.js +32 -26
  8. package/package.json +2 -2
  9. package/dist/vite-test/dist/assets/Graphics.f535ed8f.d.ts +0 -6
  10. package/dist/vite-test/dist/assets/Graphics.f535ed8f.d.ts.map +0 -1
  11. package/dist/vite-test/dist/assets/Sprite.703a9f94.d.ts +0 -9
  12. package/dist/vite-test/dist/assets/Sprite.703a9f94.d.ts.map +0 -1
  13. package/dist/vite-test/dist/assets/a11y.9b3ce839.d.ts +0 -4
  14. package/dist/vite-test/dist/assets/a11y.9b3ce839.d.ts.map +0 -1
  15. package/dist/vite-test/dist/assets/component.caf56816.d.ts +0 -4
  16. package/dist/vite-test/dist/assets/component.caf56816.d.ts.map +0 -1
  17. package/dist/vite-test/dist/assets/compressed-texture-animation.6dcf9ab4.d.ts +0 -4
  18. package/dist/vite-test/dist/assets/compressed-texture-animation.6dcf9ab4.d.ts.map +0 -1
  19. package/dist/vite-test/dist/assets/compressed-texture-mipmap.cc4fada9.d.ts +0 -4
  20. package/dist/vite-test/dist/assets/compressed-texture-mipmap.cc4fada9.d.ts.map +0 -1
  21. package/dist/vite-test/dist/assets/compressed-texture.07a67c9f.d.ts +0 -4
  22. package/dist/vite-test/dist/assets/compressed-texture.07a67c9f.d.ts.map +0 -1
  23. package/dist/vite-test/dist/assets/dragonbone.bfd80a38.d.ts +0 -4
  24. package/dist/vite-test/dist/assets/dragonbone.bfd80a38.d.ts.map +0 -1
  25. package/dist/vite-test/dist/assets/event.0de0fd28.d.ts +0 -4
  26. package/dist/vite-test/dist/assets/event.0de0fd28.d.ts.map +0 -1
  27. package/dist/vite-test/dist/assets/graphics.df3659e9.d.ts +0 -4
  28. package/dist/vite-test/dist/assets/graphics.df3659e9.d.ts.map +0 -1
  29. package/dist/vite-test/dist/assets/image.9d7f7b54.d.ts +0 -4
  30. package/dist/vite-test/dist/assets/image.9d7f7b54.d.ts.map +0 -1
  31. package/dist/vite-test/dist/assets/index.cf7bfffd.d.ts +0 -2
  32. package/dist/vite-test/dist/assets/index.cf7bfffd.d.ts.map +0 -1
  33. package/dist/vite-test/dist/assets/loader.03643d14.d.ts +0 -4
  34. package/dist/vite-test/dist/assets/loader.03643d14.d.ts.map +0 -1
  35. package/dist/vite-test/dist/assets/lottie.8e29b509.d.ts +0 -4
  36. package/dist/vite-test/dist/assets/lottie.8e29b509.d.ts.map +0 -1
  37. package/dist/vite-test/dist/assets/mask.c3592934.d.ts +0 -4
  38. package/dist/vite-test/dist/assets/mask.c3592934.d.ts.map +0 -1
  39. package/dist/vite-test/dist/assets/matter.bcb02c9e.d.ts +0 -4
  40. package/dist/vite-test/dist/assets/matter.bcb02c9e.d.ts.map +0 -1
  41. package/dist/vite-test/dist/assets/multi-canvas.a081d481.d.ts +0 -4
  42. package/dist/vite-test/dist/assets/multi-canvas.a081d481.d.ts.map +0 -1
  43. package/dist/vite-test/dist/assets/ninePatch.ec5000f5.d.ts +0 -4
  44. package/dist/vite-test/dist/assets/ninePatch.ec5000f5.d.ts.map +0 -1
  45. package/dist/vite-test/dist/assets/sound.81f19bb0.d.ts +0 -4
  46. package/dist/vite-test/dist/assets/sound.81f19bb0.d.ts.map +0 -1
  47. package/dist/vite-test/dist/assets/spine.08037e2f.d.ts +0 -4
  48. package/dist/vite-test/dist/assets/spine.08037e2f.d.ts.map +0 -1
  49. package/dist/vite-test/dist/assets/sprite.ab61ce04.d.ts +0 -4
  50. package/dist/vite-test/dist/assets/sprite.ab61ce04.d.ts.map +0 -1
  51. package/dist/vite-test/dist/assets/spriteAnimation.fbd1b62d.d.ts +0 -4
  52. package/dist/vite-test/dist/assets/spriteAnimation.fbd1b62d.d.ts.map +0 -1
  53. package/dist/vite-test/dist/assets/text.3e406bba.d.ts +0 -4
  54. package/dist/vite-test/dist/assets/text.3e406bba.d.ts.map +0 -1
  55. package/dist/vite-test/dist/assets/tilingSprite.3f09d780.d.ts +0 -4
  56. package/dist/vite-test/dist/assets/tilingSprite.3f09d780.d.ts.map +0 -1
  57. package/dist/vite-test/dist/assets/transition.f3d6a6eb.d.ts +0 -4
  58. package/dist/vite-test/dist/assets/transition.f3d6a6eb.d.ts.map +0 -1
  59. package/dist/vite-test/dist/assets/vendor.1f31f96e.d.ts +0 -5
  60. package/dist/vite-test/dist/assets/vendor.1f31f96e.d.ts.map +0 -1
  61. package/dist/vite-test/index.d.ts +0 -2
  62. package/dist/vite-test/index.d.ts.map +0 -1
  63. package/dist/vite-test/ts/a11y.d.ts +0 -3
  64. package/dist/vite-test/ts/a11y.d.ts.map +0 -1
  65. package/dist/vite-test/ts/component.d.ts +0 -3
  66. package/dist/vite-test/ts/component.d.ts.map +0 -1
  67. package/dist/vite-test/ts/compressed-texture-animation.d.ts +0 -3
  68. package/dist/vite-test/ts/compressed-texture-animation.d.ts.map +0 -1
  69. package/dist/vite-test/ts/compressed-texture-mipmap.d.ts +0 -3
  70. package/dist/vite-test/ts/compressed-texture-mipmap.d.ts.map +0 -1
  71. package/dist/vite-test/ts/compressed-texture.d.ts +0 -3
  72. package/dist/vite-test/ts/compressed-texture.d.ts.map +0 -1
  73. package/dist/vite-test/ts/dragonbone.d.ts +0 -3
  74. package/dist/vite-test/ts/dragonbone.d.ts.map +0 -1
  75. package/dist/vite-test/ts/event.d.ts +0 -3
  76. package/dist/vite-test/ts/event.d.ts.map +0 -1
  77. package/dist/vite-test/ts/graphics.d.ts +0 -3
  78. package/dist/vite-test/ts/graphics.d.ts.map +0 -1
  79. package/dist/vite-test/ts/image.d.ts +0 -3
  80. package/dist/vite-test/ts/image.d.ts.map +0 -1
  81. package/dist/vite-test/ts/loader.d.ts +0 -3
  82. package/dist/vite-test/ts/loader.d.ts.map +0 -1
  83. package/dist/vite-test/ts/lottie.d.ts +0 -3
  84. package/dist/vite-test/ts/lottie.d.ts.map +0 -1
  85. package/dist/vite-test/ts/mask.d.ts +0 -4
  86. package/dist/vite-test/ts/mask.d.ts.map +0 -1
  87. package/dist/vite-test/ts/matter.d.ts +0 -3
  88. package/dist/vite-test/ts/matter.d.ts.map +0 -1
  89. package/dist/vite-test/ts/multi-canvas.d.ts +0 -3
  90. package/dist/vite-test/ts/multi-canvas.d.ts.map +0 -1
  91. package/dist/vite-test/ts/ninePatch.d.ts +0 -3
  92. package/dist/vite-test/ts/ninePatch.d.ts.map +0 -1
  93. package/dist/vite-test/ts/sound.d.ts +0 -3
  94. package/dist/vite-test/ts/sound.d.ts.map +0 -1
  95. package/dist/vite-test/ts/spine.d.ts +0 -3
  96. package/dist/vite-test/ts/spine.d.ts.map +0 -1
  97. package/dist/vite-test/ts/sprite.d.ts +0 -3
  98. package/dist/vite-test/ts/sprite.d.ts.map +0 -1
  99. package/dist/vite-test/ts/spriteAnimation.d.ts +0 -3
  100. package/dist/vite-test/ts/spriteAnimation.d.ts.map +0 -1
  101. package/dist/vite-test/ts/text.d.ts +0 -3
  102. package/dist/vite-test/ts/text.d.ts.map +0 -1
  103. package/dist/vite-test/ts/tilingSprite.d.ts +0 -3
  104. package/dist/vite-test/ts/tilingSprite.d.ts.map +0 -1
  105. package/dist/vite-test/ts/transition.d.ts +0 -3
  106. package/dist/vite-test/ts/transition.d.ts.map +0 -1
@@ -1,516 +1,733 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@eva/eva.js')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@eva/eva.js'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.EVA = global.EVA || {}, global.EVA.plugin = global.EVA.plugin || {}, global.EVA.plugin.sound = {}), global.EVA));
5
- }(this, (function (exports, eva_js) { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise */
22
-
23
- var extendStatics = function(d, b) {
24
- extendStatics = Object.setPrototypeOf ||
25
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
27
- return extendStatics(d, b);
28
- };
29
-
30
- function __extends(d, b) {
31
- extendStatics(d, b);
32
- function __() { this.constructor = d; }
33
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
- }
35
-
36
- function __decorate(decorators, target, key, desc) {
37
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
38
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
39
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
40
- return c > 3 && r && Object.defineProperty(target, key, r), r;
41
- }
42
-
43
- function __awaiter(thisArg, _arguments, P, generator) {
44
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
45
- return new (P || (P = Promise))(function (resolve, reject) {
46
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
47
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
48
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
49
- step((generator = generator.apply(thisArg, _arguments || [])).next());
50
- });
51
- }
52
-
53
- function __generator(thisArg, body) {
54
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
55
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
56
- function verb(n) { return function (v) { return step([n, v]); }; }
57
- function step(op) {
58
- if (f) throw new TypeError("Generator is already executing.");
59
- while (_) try {
60
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
61
- if (y = 0, t) op = [op[0] & 2, t.value];
62
- switch (op[0]) {
63
- case 0: case 1: t = op; break;
64
- case 4: _.label++; return { value: op[1], done: false };
65
- case 5: _.label++; y = op[1]; op = [0]; continue;
66
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
67
- default:
68
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
69
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
70
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
71
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
72
- if (t[2]) _.ops.pop();
73
- _.trys.pop(); continue;
74
- }
75
- op = body.call(thisArg, _);
76
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
77
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
78
- }
79
- }
80
-
81
- function __values(o) {
82
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
83
- if (m) return m.call(o);
84
- if (o && typeof o.length === "number") return {
85
- next: function () {
86
- if (o && i >= o.length) o = void 0;
87
- return { value: o && o[i++], done: !o };
88
- }
89
- };
90
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ window.EVA = window.EVA || {};
4
+ window.EVA.plugin = window.EVA.plugin || {};
5
+
6
+ var _EVA_IIFE_sound = function (exports, eva_js) {
7
+ 'use strict';
8
+
9
+ var _extendStatics = function extendStatics(d, b) {
10
+ _extendStatics = Object.setPrototypeOf || {
11
+ __proto__: []
12
+ } instanceof Array && function (d, b) {
13
+ d.__proto__ = b;
14
+ } || function (d, b) {
15
+ for (var p in b) {
16
+ if (b.hasOwnProperty(p)) d[p] = b[p];
17
+ }
18
+ };
19
+
20
+ return _extendStatics(d, b);
21
+ };
22
+
23
+ function __extends(d, b) {
24
+ _extendStatics(d, b);
25
+
26
+ function __() {
27
+ this.constructor = d;
28
+ }
29
+
30
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
+ }
32
+
33
+ function __decorate(decorators, target, key, desc) {
34
+ var c = arguments.length,
35
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
36
+ d;
37
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
38
+ if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
39
+ }
40
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
41
+ }
42
+
43
+ function __awaiter(thisArg, _arguments, P, generator) {
44
+ function adopt(value) {
45
+ return value instanceof P ? value : new P(function (resolve) {
46
+ resolve(value);
47
+ });
48
+ }
49
+
50
+ return new (P || (P = Promise))(function (resolve, reject) {
51
+ function fulfilled(value) {
52
+ try {
53
+ step(generator.next(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ }
58
+
59
+ function rejected(value) {
60
+ try {
61
+ step(generator["throw"](value));
62
+ } catch (e) {
63
+ reject(e);
64
+ }
65
+ }
66
+
67
+ function step(result) {
68
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
69
+ }
70
+
71
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
72
+ });
73
+ }
74
+
75
+ function __generator(thisArg, body) {
76
+ var _ = {
77
+ label: 0,
78
+ sent: function sent() {
79
+ if (t[0] & 1) throw t[1];
80
+ return t[1];
81
+ },
82
+ trys: [],
83
+ ops: []
84
+ },
85
+ f,
86
+ y,
87
+ t,
88
+ g;
89
+ return g = {
90
+ next: verb(0),
91
+ "throw": verb(1),
92
+ "return": verb(2)
93
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
94
+ return this;
95
+ }), g;
96
+
97
+ function verb(n) {
98
+ return function (v) {
99
+ return step([n, v]);
100
+ };
101
+ }
102
+
103
+ function step(op) {
104
+ if (f) throw new TypeError("Generator is already executing.");
105
+
106
+ while (_) {
107
+ try {
108
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
109
+ if (y = 0, t) op = [op[0] & 2, t.value];
110
+
111
+ switch (op[0]) {
112
+ case 0:
113
+ case 1:
114
+ t = op;
115
+ break;
116
+
117
+ case 4:
118
+ _.label++;
119
+ return {
120
+ value: op[1],
121
+ done: false
122
+ };
123
+
124
+ case 5:
125
+ _.label++;
126
+ y = op[1];
127
+ op = [0];
128
+ continue;
129
+
130
+ case 7:
131
+ op = _.ops.pop();
132
+
133
+ _.trys.pop();
134
+
135
+ continue;
136
+
137
+ default:
138
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
139
+ _ = 0;
140
+ continue;
141
+ }
142
+
143
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
144
+ _.label = op[1];
145
+ break;
146
+ }
147
+
148
+ if (op[0] === 6 && _.label < t[1]) {
149
+ _.label = t[1];
150
+ t = op;
151
+ break;
152
+ }
153
+
154
+ if (t && _.label < t[2]) {
155
+ _.label = t[2];
156
+
157
+ _.ops.push(op);
158
+
159
+ break;
160
+ }
161
+
162
+ if (t[2]) _.ops.pop();
163
+
164
+ _.trys.pop();
165
+
166
+ continue;
167
+ }
168
+
169
+ op = body.call(thisArg, _);
170
+ } catch (e) {
171
+ op = [6, e];
172
+ y = 0;
173
+ } finally {
174
+ f = t = 0;
175
+ }
176
+ }
177
+
178
+ if (op[0] & 5) throw op[1];
179
+ return {
180
+ value: op[0] ? op[1] : void 0,
181
+ done: true
182
+ };
183
+ }
184
+ }
185
+
186
+ function __values(o) {
187
+ var s = typeof Symbol === "function" && Symbol.iterator,
188
+ m = s && o[s],
189
+ i = 0;
190
+ if (m) return m.call(o);
191
+ if (o && typeof o.length === "number") return {
192
+ next: function next() {
193
+ if (o && i >= o.length) o = void 0;
194
+ return {
195
+ value: o && o[i++],
196
+ done: !o
197
+ };
198
+ }
199
+ };
200
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
201
+ }
202
+
203
+ var SoundSystem = function (_super) {
204
+ __extends(SoundSystem, _super);
205
+
206
+ function SoundSystem(obj) {
207
+ var _this = _super.call(this) || this;
208
+
209
+ _this.autoPauseAndStart = true;
210
+ _this.components = [];
211
+ _this.pausedComponents = [];
212
+ _this.audioBufferCache = {};
213
+ _this.decodeAudioPromiseMap = {};
214
+
215
+ _extends(_this, obj);
216
+
217
+ return _this;
91
218
  }
92
219
 
93
- var SoundSystem = (function (_super) {
94
- __extends(SoundSystem, _super);
95
- function SoundSystem(obj) {
96
- var _this = _super.call(this) || this;
97
- _this.autoPauseAndStart = true;
98
- _this.components = [];
99
- _this.pausedComponents = [];
100
- _this.audioBufferCache = {};
101
- _this.decodeAudioPromiseMap = {};
102
- Object.assign(_this, obj);
103
- return _this;
104
- }
105
- Object.defineProperty(SoundSystem.prototype, "muted", {
106
- get: function () {
107
- return this.gainNode ? this.gainNode.gain.value === 0 : false;
108
- },
109
- set: function (v) {
110
- if (!this.gainNode) {
111
- return;
112
- }
113
- this.gainNode.gain.setValueAtTime(v ? 0 : 1, 0);
114
- },
115
- enumerable: false,
116
- configurable: true
117
- });
118
- Object.defineProperty(SoundSystem.prototype, "volume", {
119
- get: function () {
120
- return this.gainNode ? this.gainNode.gain.value : 1;
121
- },
122
- set: function (v) {
123
- if (!this.gainNode || typeof v !== 'number' || v < 0 || v > 1) {
124
- return;
125
- }
126
- this.gainNode.gain.setValueAtTime(v, 0);
127
- },
128
- enumerable: false,
129
- configurable: true
130
- });
131
- Object.defineProperty(SoundSystem.prototype, "audioLocked", {
132
- get: function () {
133
- if (!this.ctx) {
134
- return true;
135
- }
136
- return this.ctx.state !== 'running';
137
- },
138
- enumerable: false,
139
- configurable: true
140
- });
141
- SoundSystem.prototype.resumeAll = function () {
142
- var _this = this;
143
- var handleResume = function () {
144
- _this.pausedComponents.forEach(function (component) {
145
- component.play();
146
- });
147
- _this.pausedComponents = [];
148
- };
149
- this.ctx.resume().then(handleResume, handleResume);
150
- };
151
- SoundSystem.prototype.pauseAll = function () {
152
- var _this = this;
153
- this.components.forEach(function (component) {
154
- if (component.playing) {
155
- _this.pausedComponents.push(component);
156
- component.pause();
157
- }
158
- });
159
- this.ctx.suspend().then();
160
- };
161
- SoundSystem.prototype.stopAll = function () {
162
- this.components.forEach(function (component) {
163
- if (component.playing) {
164
- component.stop();
165
- }
166
- });
167
- this.pausedComponents = [];
168
- this.ctx.suspend().then();
169
- };
170
- SoundSystem.prototype.init = function () {
171
- this.setupAudioContext();
172
- };
173
- SoundSystem.prototype.update = function () {
174
- var e_1, _a;
175
- var changes = this.componentObserver.clear();
176
- try {
177
- for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
178
- var changed = changes_1_1.value;
179
- this.componentChanged(changed);
180
- }
181
- }
182
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
183
- finally {
184
- try {
185
- if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
186
- }
187
- finally { if (e_1) throw e_1.error; }
188
- }
189
- };
190
- SoundSystem.prototype.onPlay = function () {
191
- if (!this.autoPauseAndStart) {
192
- return;
193
- }
194
- this.resumeAll();
195
- };
196
- SoundSystem.prototype.onPause = function () {
197
- if (!this.autoPauseAndStart) {
198
- return;
199
- }
200
- this.pauseAll();
201
- };
202
- SoundSystem.prototype.onDestroy = function () {
203
- this.components.forEach(function (component) {
204
- component.onDestroy();
205
- });
206
- this.components = [];
207
- if (this.ctx) {
208
- this.gainNode.disconnect();
209
- this.gainNode = null;
210
- this.ctx.close();
211
- this.ctx = null;
212
- }
213
- };
214
- SoundSystem.prototype.componentChanged = function (changed) {
215
- return __awaiter(this, void 0, void 0, function () {
216
- return __generator(this, function (_a) {
217
- if (changed.componentName !== 'Sound') {
218
- return [2];
219
- }
220
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
221
- this.add(changed);
222
- }
223
- return [2];
224
- });
225
- });
226
- };
227
- SoundSystem.prototype.setupAudioContext = function () {
228
- try {
229
- var AudioContext_1 = window.AudioContext || window.webkitAudioContext;
230
- this.ctx = new AudioContext_1();
231
- }
232
- catch (error) {
233
- console.error(error);
234
- if (this.onError) {
235
- this.onError(error);
236
- }
237
- }
238
- if (!this.ctx) {
239
- return;
240
- }
241
- this.gainNode =
242
- typeof this.ctx.createGain === 'undefined' ? this.ctx.createGainNode() : this.ctx.createGain();
243
- this.gainNode.gain.setValueAtTime(this.muted ? 0 : this.volume, this.ctx.currentTime);
244
- this.gainNode.connect(this.ctx.destination);
245
- this.unlockAudio();
246
- };
247
- SoundSystem.prototype.unlockAudio = function () {
248
- var _this = this;
249
- if (!this.ctx || !this.audioLocked) {
250
- return;
251
- }
252
- var unlock = function () {
253
- if (_this.ctx) {
254
- var removeListenerFn = function () {
255
- document.body.removeEventListener('touchstart', unlock);
256
- document.body.removeEventListener('touchend', unlock);
257
- document.body.removeEventListener('click', unlock);
258
- };
259
- _this.ctx.resume().then(removeListenerFn, removeListenerFn);
260
- }
261
- };
262
- document.body.addEventListener('touchstart', unlock);
263
- document.body.addEventListener('touchend', unlock);
264
- document.body.addEventListener('click', unlock);
265
- };
266
- SoundSystem.prototype.add = function (changed) {
267
- return __awaiter(this, void 0, void 0, function () {
268
- var component, config, audio, _a, _b, error_1;
269
- return __generator(this, function (_c) {
270
- switch (_c.label) {
271
- case 0:
272
- component = changed.component;
273
- this.components.push(component);
274
- _c.label = 1;
275
- case 1:
276
- _c.trys.push([1, 5, , 6]);
277
- config = component.config;
278
- component.state = 'loading';
279
- return [4, eva_js.resource.getResource(config.resource)];
280
- case 2:
281
- audio = _c.sent();
282
- if (!!this.audioBufferCache[audio.name]) return [3, 4];
283
- _a = this.audioBufferCache;
284
- _b = audio.name;
285
- return [4, this.decodeAudioData(audio.data.audio, audio.name)];
286
- case 3:
287
- _a[_b] = _c.sent();
288
- _c.label = 4;
289
- case 4:
290
- if (this.audioBufferCache[audio.name]) {
291
- component.systemContext = this.ctx;
292
- component.systemDestination = this.gainNode;
293
- component.onload(this.audioBufferCache[audio.name]);
294
- }
295
- return [3, 6];
296
- case 5:
297
- error_1 = _c.sent();
298
- console.error(error_1);
299
- if (this.onError) {
300
- this.onError(error_1);
301
- }
302
- return [3, 6];
303
- case 6: return [2];
304
- }
305
- });
306
- });
307
- };
308
- SoundSystem.prototype.decodeAudioData = function (arraybuffer, name) {
309
- var _this = this;
310
- if (this.decodeAudioPromiseMap[name]) {
311
- return this.decodeAudioPromiseMap[name];
312
- }
313
- var promise = new Promise(function (resolve, reject) {
314
- if (!_this.ctx) {
315
- reject(new Error('No audio support'));
316
- }
317
- var error = function (err) {
318
- if (_this.decodeAudioPromiseMap[name]) {
319
- delete _this.decodeAudioPromiseMap[name];
320
- }
321
- reject(new Error(err + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
322
- };
323
- var success = function (decodedData) {
324
- if (_this.decodeAudioPromiseMap[name]) {
325
- delete _this.decodeAudioPromiseMap[name];
326
- }
327
- if (decodedData) {
328
- resolve(decodedData);
329
- }
330
- else {
331
- reject(new Error("Error decoding audio " + name));
332
- }
333
- };
334
- _this.ctx.decodeAudioData(arraybuffer, success, error);
335
- });
336
- this.decodeAudioPromiseMap[name] = promise;
337
- return promise;
338
- };
339
- SoundSystem.systemName = 'SoundSystem';
340
- SoundSystem = __decorate([
341
- eva_js.decorators.componentObserver({
342
- Sound: [],
343
- })
344
- ], SoundSystem);
345
- return SoundSystem;
346
- }(eva_js.System));
347
-
348
- var Sound = (function (_super) {
349
- __extends(Sound, _super);
350
- function Sound() {
351
- var _this = _super !== null && _super.apply(this, arguments) || this;
352
- _this.state = 'unloaded';
353
- _this.config = {
354
- resource: '',
355
- autoplay: false,
356
- muted: false,
357
- volume: 1,
358
- loop: false,
359
- seek: 0,
360
- };
361
- _this.playTime = 0;
362
- _this.startTime = 0;
363
- _this.duration = 0;
364
- _this.actionQueue = [];
365
- return _this;
366
- }
367
- Object.defineProperty(Sound.prototype, "muted", {
368
- get: function () {
369
- return this.gainNode ? this.gainNode.gain.value === 0 : false;
370
- },
371
- set: function (v) {
372
- if (!this.gainNode) {
373
- return;
374
- }
375
- this.gainNode.gain.setValueAtTime(v ? 0 : this.config.volume, 0);
376
- },
377
- enumerable: false,
378
- configurable: true
379
- });
380
- Object.defineProperty(Sound.prototype, "volume", {
381
- get: function () {
382
- return this.gainNode ? this.gainNode.gain.value : 1;
383
- },
384
- set: function (v) {
385
- if (typeof v !== 'number' || v < 0 || v > 1) {
386
- return;
387
- }
388
- this.config.volume = v;
389
- if (!this.gainNode) {
390
- return;
391
- }
392
- this.gainNode.gain.setValueAtTime(v, 0);
393
- },
394
- enumerable: false,
395
- configurable: true
396
- });
397
- Sound.prototype.init = function (obj) {
398
- if (!obj) {
399
- return;
400
- }
401
- Object.assign(this.config, obj);
402
- if (this.config.autoplay) {
403
- this.actionQueue.push(this.play.bind(this));
404
- }
405
- };
406
- Sound.prototype.play = function () {
407
- var _this = this;
408
- if (this.state !== 'loaded') {
409
- this.actionQueue.push(this.play.bind(this));
410
- }
411
- this.destroySource();
412
- this.createSource();
413
- if (!this.sourceNode) {
414
- return;
415
- }
416
- var when = this.systemContext.currentTime;
417
- var offset = this.config.seek;
418
- var duration = this.config.duration;
419
- this.sourceNode.start(0, offset, duration);
420
- this.startTime = when;
421
- this.playTime = when - offset;
422
- this.paused = false;
423
- this.playing = true;
424
- this.resetConfig();
425
- this.endedListener = function () {
426
- if (!_this.sourceNode) {
427
- return;
428
- }
429
- if (_this.config.onEnd) {
430
- _this.config.onEnd();
431
- }
432
- if (_this.playing) {
433
- _this.destroySource();
434
- }
435
- };
436
- this.sourceNode.addEventListener('ended', this.endedListener);
437
- };
438
- Sound.prototype.pause = function () {
439
- if (this.state !== 'loaded') {
440
- this.actionQueue.push(this.pause.bind(this));
441
- }
442
- if (this.paused || !this.playing) {
443
- return;
444
- }
445
- this.paused = true;
446
- this.playing = false;
447
- this.config.seek = this.getCurrentTime();
448
- this.destroySource();
449
- };
450
- Sound.prototype.stop = function () {
451
- if (this.state !== 'loaded') {
452
- this.actionQueue.push(this.stop.bind(this));
453
- }
454
- if (!this.paused && !this.playing) {
455
- return;
456
- }
457
- this.playing = false;
458
- this.paused = false;
459
- this.destroySource();
460
- this.resetConfig();
461
- };
462
- Sound.prototype.onload = function (buffer) {
463
- this.state = 'loaded';
464
- this.buffer = buffer;
465
- this.duration = this.buffer.duration;
466
- this.actionQueue.forEach(function (action) { return action(); });
467
- this.actionQueue.length = 0;
468
- };
469
- Sound.prototype.onDestroy = function () {
470
- this.actionQueue.length = 0;
471
- this.destroySource();
472
- };
473
- Sound.prototype.resetConfig = function () {
474
- this.config.seek = 0;
475
- };
476
- Sound.prototype.getCurrentTime = function () {
477
- if (this.config.loop && this.duration > 0) {
478
- return (this.systemContext.currentTime - this.playTime) % this.duration;
479
- }
480
- return this.systemContext.currentTime - this.playTime;
481
- };
482
- Sound.prototype.createSource = function () {
483
- if (!this.systemContext || this.state !== 'loaded') {
484
- return;
485
- }
486
- this.sourceNode = this.systemContext.createBufferSource();
487
- this.sourceNode.buffer = this.buffer;
488
- this.sourceNode.loop = this.config.loop;
489
- if (!this.gainNode) {
490
- this.gainNode = this.systemContext.createGain();
491
- this.gainNode.connect(this.systemDestination);
492
- Object.assign(this, this.config);
493
- }
494
- this.sourceNode.connect(this.gainNode);
495
- };
496
- Sound.prototype.destroySource = function () {
497
- if (!this.sourceNode)
498
- return;
499
- this.sourceNode.removeEventListener('ended', this.endedListener);
500
- this.sourceNode.stop();
501
- this.sourceNode.disconnect();
502
- this.sourceNode = null;
503
- this.startTime = 0;
504
- this.playTime = 0;
505
- this.playing = false;
506
- };
507
- Sound.componentName = 'Sound';
508
- return Sound;
509
- }(eva_js.Component));
510
-
511
- exports.Sound = Sound;
512
- exports.SoundSystem = SoundSystem;
513
-
514
- Object.defineProperty(exports, '__esModule', { value: true });
515
-
516
- })));
220
+ Object.defineProperty(SoundSystem.prototype, "muted", {
221
+ get: function get() {
222
+ return this.gainNode ? this.gainNode.gain.value === 0 : false;
223
+ },
224
+ set: function set(v) {
225
+ if (!this.gainNode) {
226
+ return;
227
+ }
228
+
229
+ this.gainNode.gain.setValueAtTime(v ? 0 : 1, 0);
230
+ },
231
+ enumerable: false,
232
+ configurable: true
233
+ });
234
+ Object.defineProperty(SoundSystem.prototype, "volume", {
235
+ get: function get() {
236
+ return this.gainNode ? this.gainNode.gain.value : 1;
237
+ },
238
+ set: function set(v) {
239
+ if (!this.gainNode || typeof v !== 'number' || v < 0 || v > 1) {
240
+ return;
241
+ }
242
+
243
+ this.gainNode.gain.setValueAtTime(v, 0);
244
+ },
245
+ enumerable: false,
246
+ configurable: true
247
+ });
248
+ Object.defineProperty(SoundSystem.prototype, "audioLocked", {
249
+ get: function get() {
250
+ if (!this.ctx) {
251
+ return true;
252
+ }
253
+
254
+ return this.ctx.state !== 'running';
255
+ },
256
+ enumerable: false,
257
+ configurable: true
258
+ });
259
+
260
+ SoundSystem.prototype.resumeAll = function () {
261
+ var _this = this;
262
+
263
+ var handleResume = function handleResume() {
264
+ _this.pausedComponents.forEach(function (component) {
265
+ component.play();
266
+ });
267
+
268
+ _this.pausedComponents = [];
269
+ };
270
+
271
+ this.ctx.resume().then(handleResume, handleResume);
272
+ };
273
+
274
+ SoundSystem.prototype.pauseAll = function () {
275
+ var _this = this;
276
+
277
+ this.components.forEach(function (component) {
278
+ if (component.playing) {
279
+ _this.pausedComponents.push(component);
280
+
281
+ component.pause();
282
+ }
283
+ });
284
+ this.ctx.suspend().then();
285
+ };
286
+
287
+ SoundSystem.prototype.stopAll = function () {
288
+ this.components.forEach(function (component) {
289
+ if (component.playing) {
290
+ component.stop();
291
+ }
292
+ });
293
+ this.pausedComponents = [];
294
+ this.ctx.suspend().then();
295
+ };
296
+
297
+ SoundSystem.prototype.init = function () {
298
+ this.setupAudioContext();
299
+ };
300
+
301
+ SoundSystem.prototype.update = function () {
302
+ var e_1, _a;
303
+
304
+ var changes = this.componentObserver.clear();
305
+
306
+ try {
307
+ for (var changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
308
+ var changed = changes_1_1.value;
309
+ this.componentChanged(changed);
310
+ }
311
+ } catch (e_1_1) {
312
+ e_1 = {
313
+ error: e_1_1
314
+ };
315
+ } finally {
316
+ try {
317
+ if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
318
+ } finally {
319
+ if (e_1) throw e_1.error;
320
+ }
321
+ }
322
+ };
323
+
324
+ SoundSystem.prototype.onResume = function () {
325
+ if (!this.autoPauseAndStart) {
326
+ return;
327
+ }
328
+
329
+ this.resumeAll();
330
+ };
331
+
332
+ SoundSystem.prototype.onPause = function () {
333
+ if (!this.autoPauseAndStart) {
334
+ return;
335
+ }
336
+
337
+ this.pauseAll();
338
+ };
339
+
340
+ SoundSystem.prototype.onDestroy = function () {
341
+ this.components.forEach(function (component) {
342
+ component.onDestroy();
343
+ });
344
+ this.components = [];
345
+
346
+ if (this.ctx) {
347
+ this.gainNode.disconnect();
348
+ this.gainNode = null;
349
+ this.ctx.close();
350
+ this.ctx = null;
351
+ }
352
+ };
353
+
354
+ SoundSystem.prototype.componentChanged = function (changed) {
355
+ return __awaiter(this, void 0, void 0, function () {
356
+ return __generator(this, function (_a) {
357
+ if (changed.componentName !== 'Sound') return [2];
358
+
359
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
360
+ this.add(changed);
361
+ }
362
+
363
+ return [2];
364
+ });
365
+ });
366
+ };
367
+
368
+ SoundSystem.prototype.setupAudioContext = function () {
369
+ try {
370
+ var AudioContext_1 = window.AudioContext || window.webkitAudioContext;
371
+ this.ctx = new AudioContext_1();
372
+ } catch (error) {
373
+ console.error(error);
374
+
375
+ if (this.onError) {
376
+ this.onError(error);
377
+ }
378
+ }
379
+
380
+ if (!this.ctx) {
381
+ return;
382
+ }
383
+
384
+ this.gainNode = typeof this.ctx.createGain === 'undefined' ? this.ctx.createGainNode() : this.ctx.createGain();
385
+ this.gainNode.gain.setValueAtTime(this.muted ? 0 : this.volume, this.ctx.currentTime);
386
+ this.gainNode.connect(this.ctx.destination);
387
+ this.unlockAudio();
388
+ };
389
+
390
+ SoundSystem.prototype.unlockAudio = function () {
391
+ var _this = this;
392
+
393
+ if (!this.ctx || !this.audioLocked) {
394
+ return;
395
+ }
396
+
397
+ var unlock = function unlock() {
398
+ if (_this.ctx) {
399
+ var removeListenerFn = function removeListenerFn() {
400
+ document.body.removeEventListener('touchstart', unlock);
401
+ document.body.removeEventListener('touchend', unlock);
402
+ document.body.removeEventListener('click', unlock);
403
+ };
404
+
405
+ _this.ctx.resume().then(removeListenerFn, removeListenerFn);
406
+ }
407
+ };
408
+
409
+ document.body.addEventListener('touchstart', unlock);
410
+ document.body.addEventListener('touchend', unlock);
411
+ document.body.addEventListener('click', unlock);
412
+ };
413
+
414
+ SoundSystem.prototype.add = function (changed) {
415
+ var _a;
416
+
417
+ return __awaiter(this, void 0, void 0, function () {
418
+ var component, config, audio, _b, _c, error_1;
419
+
420
+ return __generator(this, function (_d) {
421
+ switch (_d.label) {
422
+ case 0:
423
+ component = changed.component;
424
+ this.components.push(component);
425
+ _d.label = 1;
426
+
427
+ case 1:
428
+ _d.trys.push([1, 5,, 6]);
429
+
430
+ config = component.config;
431
+ component.state = 'loading';
432
+ return [4, eva_js.resource.getResource(config.resource)];
433
+
434
+ case 2:
435
+ audio = _d.sent();
436
+ if (!(!this.audioBufferCache[audio.name] && ((_a = audio === null || audio === void 0 ? void 0 : audio.data) === null || _a === void 0 ? void 0 : _a.audio))) return [3, 4];
437
+ _b = this.audioBufferCache;
438
+ _c = audio.name;
439
+ return [4, this.decodeAudioData(audio.data.audio, audio.name)];
440
+
441
+ case 3:
442
+ _b[_c] = _d.sent();
443
+ _d.label = 4;
444
+
445
+ case 4:
446
+ if (this.audioBufferCache[audio.name]) {
447
+ component.systemContext = this.ctx;
448
+ component.systemDestination = this.gainNode;
449
+ component.onload(this.audioBufferCache[audio.name]);
450
+ }
451
+
452
+ return [3, 6];
453
+
454
+ case 5:
455
+ error_1 = _d.sent();
456
+
457
+ if (this.onError) {
458
+ this.onError(error_1);
459
+ }
460
+
461
+ return [3, 6];
462
+
463
+ case 6:
464
+ return [2];
465
+ }
466
+ });
467
+ });
468
+ };
469
+
470
+ SoundSystem.prototype.decodeAudioData = function (arraybuffer, name) {
471
+ var _this = this;
472
+
473
+ if (this.decodeAudioPromiseMap[name]) {
474
+ return this.decodeAudioPromiseMap[name];
475
+ }
476
+
477
+ var promise = new Promise(function (resolve, reject) {
478
+ if (!_this.ctx) {
479
+ reject(new Error('No audio support'));
480
+ }
481
+
482
+ var success = function success(decodedData) {
483
+ if (_this.decodeAudioPromiseMap[name]) {
484
+ delete _this.decodeAudioPromiseMap[name];
485
+ }
486
+
487
+ if (decodedData) {
488
+ resolve(decodedData);
489
+ } else {
490
+ reject(new Error("Error decoding audio " + name));
491
+ }
492
+ };
493
+
494
+ var error = function error(err) {
495
+ if (_this.decodeAudioPromiseMap[name]) {
496
+ delete _this.decodeAudioPromiseMap[name];
497
+ }
498
+
499
+ reject(new Error(err + ". arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
500
+ };
501
+
502
+ var promise = _this.ctx.decodeAudioData(arraybuffer, success, error);
503
+
504
+ if (promise instanceof Promise) {
505
+ promise.catch(function (err) {
506
+ reject(new Error("catch " + err + ", arrayBuffer byteLength: " + (arraybuffer ? arraybuffer.byteLength : 0)));
507
+ });
508
+ }
509
+ });
510
+ this.decodeAudioPromiseMap[name] = promise;
511
+ return promise;
512
+ };
513
+
514
+ SoundSystem.systemName = 'SoundSystem';
515
+ SoundSystem = __decorate([eva_js.decorators.componentObserver({
516
+ Sound: []
517
+ })], SoundSystem);
518
+ return SoundSystem;
519
+ }(eva_js.System);
520
+
521
+ var SoundSystem$1 = SoundSystem;
522
+
523
+ var Sound = function (_super) {
524
+ __extends(Sound, _super);
525
+
526
+ function Sound() {
527
+ var _this = _super !== null && _super.apply(this, arguments) || this;
528
+
529
+ _this.state = 'unloaded';
530
+ _this.config = {
531
+ resource: '',
532
+ autoplay: false,
533
+ muted: false,
534
+ volume: 1,
535
+ loop: false,
536
+ seek: 0
537
+ };
538
+ _this.playTime = 0;
539
+ _this.startTime = 0;
540
+ _this.duration = 0;
541
+ _this.actionQueue = [];
542
+ return _this;
543
+ }
544
+
545
+ Object.defineProperty(Sound.prototype, "muted", {
546
+ get: function get() {
547
+ return this.gainNode ? this.gainNode.gain.value === 0 : false;
548
+ },
549
+ set: function set(v) {
550
+ if (!this.gainNode) {
551
+ return;
552
+ }
553
+
554
+ this.gainNode.gain.setValueAtTime(v ? 0 : this.config.volume, 0);
555
+ },
556
+ enumerable: false,
557
+ configurable: true
558
+ });
559
+ Object.defineProperty(Sound.prototype, "volume", {
560
+ get: function get() {
561
+ return this.gainNode ? this.gainNode.gain.value : 1;
562
+ },
563
+ set: function set(v) {
564
+ if (typeof v !== 'number' || v < 0 || v > 1) {
565
+ return;
566
+ }
567
+
568
+ this.config.volume = v;
569
+
570
+ if (!this.gainNode) {
571
+ return;
572
+ }
573
+
574
+ this.gainNode.gain.setValueAtTime(v, 0);
575
+ },
576
+ enumerable: false,
577
+ configurable: true
578
+ });
579
+
580
+ Sound.prototype.init = function (obj) {
581
+ if (!obj) {
582
+ return;
583
+ }
584
+
585
+ _extends(this.config, obj);
586
+
587
+ if (this.config.autoplay) {
588
+ this.actionQueue.push(this.play.bind(this));
589
+ }
590
+ };
591
+
592
+ Sound.prototype.play = function () {
593
+ var _this = this;
594
+
595
+ if (this.state !== 'loaded') {
596
+ this.actionQueue.push(this.play.bind(this));
597
+ }
598
+
599
+ this.destroySource();
600
+ this.createSource();
601
+
602
+ if (!this.sourceNode) {
603
+ return;
604
+ }
605
+
606
+ var when = this.systemContext.currentTime;
607
+ var offset = this.config.seek;
608
+ var duration = this.config.duration;
609
+ this.sourceNode.start(0, offset, duration);
610
+ this.startTime = when;
611
+ this.playTime = when - offset;
612
+ this.paused = false;
613
+ this.playing = true;
614
+ this.resetConfig();
615
+
616
+ this.endedListener = function () {
617
+ if (!_this.sourceNode) {
618
+ return;
619
+ }
620
+
621
+ if (_this.config.onEnd) {
622
+ _this.config.onEnd();
623
+ }
624
+
625
+ if (_this.playing) {
626
+ _this.destroySource();
627
+ }
628
+ };
629
+
630
+ this.sourceNode.addEventListener('ended', this.endedListener);
631
+ };
632
+
633
+ Sound.prototype.pause = function () {
634
+ if (this.state !== 'loaded') {
635
+ this.actionQueue.push(this.pause.bind(this));
636
+ }
637
+
638
+ if (this.paused || !this.playing) {
639
+ return;
640
+ }
641
+
642
+ this.paused = true;
643
+ this.playing = false;
644
+ this.config.seek = this.getCurrentTime();
645
+ this.destroySource();
646
+ };
647
+
648
+ Sound.prototype.stop = function () {
649
+ if (this.state !== 'loaded') {
650
+ this.actionQueue.push(this.stop.bind(this));
651
+ }
652
+
653
+ if (!this.paused && !this.playing) {
654
+ return;
655
+ }
656
+
657
+ this.playing = false;
658
+ this.paused = false;
659
+ this.destroySource();
660
+ this.resetConfig();
661
+ };
662
+
663
+ Sound.prototype.onload = function (buffer) {
664
+ this.state = 'loaded';
665
+ this.buffer = buffer;
666
+ this.duration = this.buffer.duration;
667
+ this.actionQueue.forEach(function (action) {
668
+ return action();
669
+ });
670
+ this.actionQueue.length = 0;
671
+ };
672
+
673
+ Sound.prototype.onDestroy = function () {
674
+ this.actionQueue.length = 0;
675
+ this.destroySource();
676
+ };
677
+
678
+ Sound.prototype.resetConfig = function () {
679
+ this.config.seek = 0;
680
+ };
681
+
682
+ Sound.prototype.getCurrentTime = function () {
683
+ if (this.config.loop && this.duration > 0) {
684
+ return (this.systemContext.currentTime - this.playTime) % this.duration;
685
+ }
686
+
687
+ return this.systemContext.currentTime - this.playTime;
688
+ };
689
+
690
+ Sound.prototype.createSource = function () {
691
+ if (!this.systemContext || this.state !== 'loaded') {
692
+ return;
693
+ }
694
+
695
+ this.sourceNode = this.systemContext.createBufferSource();
696
+ this.sourceNode.buffer = this.buffer;
697
+ this.sourceNode.loop = this.config.loop;
698
+
699
+ if (!this.gainNode) {
700
+ this.gainNode = this.systemContext.createGain();
701
+ this.gainNode.connect(this.systemDestination);
702
+
703
+ _extends(this, this.config);
704
+ }
705
+
706
+ this.sourceNode.connect(this.gainNode);
707
+ };
708
+
709
+ Sound.prototype.destroySource = function () {
710
+ if (!this.sourceNode) return;
711
+ this.sourceNode.removeEventListener('ended', this.endedListener);
712
+ this.sourceNode.stop();
713
+ this.sourceNode.disconnect();
714
+ this.sourceNode = null;
715
+ this.startTime = 0;
716
+ this.playTime = 0;
717
+ this.playing = false;
718
+ };
719
+
720
+ Sound.componentName = 'Sound';
721
+ return Sound;
722
+ }(eva_js.Component);
723
+
724
+ var Sound$1 = Sound;
725
+ exports.Sound = Sound$1;
726
+ exports.SoundSystem = SoundSystem$1;
727
+ Object.defineProperty(exports, '__esModule', {
728
+ value: true
729
+ });
730
+ return exports;
731
+ }({}, EVA);
732
+
733
+ window.EVA.plugin.sound = window.EVA.plugin.sound || _EVA_IIFE_sound;