@atrament/web 2.2.0 → 2.2.1

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/dist/index.mjs CHANGED
@@ -1,2540 +1,2069 @@
1
- const J = {};
2
- let ce = "";
3
- function Te(t) {
4
- return `${ce}${t}`;
5
- }
6
- function wn() {
7
- ce = "", Object.keys(J).forEach((t) => delete J[t]);
8
- }
9
- function bn(t) {
10
- ce = `>>${t}<<`;
11
- }
12
- async function An(t) {
13
- return !!J[Te(t)];
14
- }
15
- async function Sn(t) {
16
- return JSON.parse(J[Te(t)]);
17
- }
18
- async function xn(t, n) {
19
- J[Te(t)] = JSON.stringify(n);
20
- }
21
- async function kn(t) {
22
- delete J[Te(t)];
23
- }
24
- async function Tn() {
25
- return Object.keys(J).filter((t) => t.includes(ce)).map((t) => t.replace(ce, ""));
26
- }
27
- const En = {
28
- gameState: J,
29
- reset: wn,
30
- init: bn,
31
- exists: An,
32
- get: Sn,
33
- set: xn,
34
- remove: kn,
35
- keys: Tn
36
- }, In = {
37
- init: () => {
38
- },
39
- mute: () => {
40
- },
41
- isMuted: () => {
42
- },
43
- setVolume: () => {
44
- },
45
- getVolume: () => {
46
- },
47
- playSound: () => {
48
- },
49
- playMusic: () => {
50
- },
51
- stopMusic: () => {
52
- }
53
- }, I = {
54
- settings: {},
55
- game: {},
56
- metadata: {},
57
- scenes: [],
58
- vars: {}
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), s = (e, i, o, s) => {
3
+ if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
4
+ get: ((e) => i[e]).bind(null, d),
5
+ enumerable: !(s = n(i, d)) || s.enumerable
6
+ });
7
+ return e;
8
+ }, c = (n, r, a) => (a = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule ? t(a, "default", {
9
+ value: n,
10
+ enumerable: !0
11
+ }) : a, n)), l = {}, u = "";
12
+ function d(e) {
13
+ return `${u}${e}`;
14
+ }
15
+ function f() {
16
+ u = "", Object.keys(l).forEach((e) => delete l[e]);
17
+ }
18
+ function p(e) {
19
+ u = `>>${e}<<`;
20
+ }
21
+ async function m(e) {
22
+ return !!l[d(e)];
23
+ }
24
+ async function h(e) {
25
+ return JSON.parse(l[d(e)]);
26
+ }
27
+ async function g(e, t) {
28
+ l[d(e)] = JSON.stringify(t);
29
+ }
30
+ async function _(e) {
31
+ delete l[d(e)];
32
+ }
33
+ async function ee() {
34
+ return Object.keys(l).filter((e) => e.includes(u)).map((e) => e.replace(u, ""));
35
+ }
36
+ var v = {
37
+ gameState: l,
38
+ reset: f,
39
+ init: p,
40
+ exists: m,
41
+ get: h,
42
+ set: g,
43
+ remove: _,
44
+ keys: ee
45
+ }, te = {
46
+ init: () => {},
47
+ mute: () => {},
48
+ isMuted: () => {},
49
+ setVolume: () => {},
50
+ getVolume: () => {},
51
+ playSound: () => {},
52
+ playMusic: () => {},
53
+ stopMusic: () => {}
54
+ }, y = {
55
+ settings: {},
56
+ game: {},
57
+ metadata: {},
58
+ scenes: [],
59
+ vars: {}
59
60
  };
60
- function Cn() {
61
- I.settings = {}, I.game = {}, I.metadata = {}, I.scenes = [], I.vars = {};
62
- }
63
- function On() {
64
- return I;
65
- }
66
- function Pn() {
67
- return JSON.parse(JSON.stringify(I));
68
- }
69
- function $n(t, n) {
70
- I[t] = n;
71
- }
72
- function Ln(t) {
73
- I[t] = !I[t];
74
- }
75
- function Fn(t, n) {
76
- I[t] = [...I[t], n];
77
- }
78
- function Mn(t, n, r) {
79
- I[t] = { ...I[t], [n]: r };
80
- }
81
- function Bn(t, n) {
82
- I[t] = { ...I[t], [n]: !I[t][n] };
83
- }
84
- function Nn(t, n, r) {
85
- I[t] = { ...I[t], [n]: [...I[t][n], r] };
86
- }
87
- const Dn = {
88
- reset: Cn,
89
- store: On,
90
- get: Pn,
91
- setKey: $n,
92
- toggleKey: Ln,
93
- appendKey: Fn,
94
- setSubkey: Mn,
95
- toggleSubkey: Bn,
96
- appendSubkey: Nn
97
- };
98
- let Re = {
99
- loader: null,
100
- persistent: En,
101
- sound: In,
102
- state: Dn
103
- };
104
- const y = () => Re;
105
- function Kn(t) {
106
- Re = { ...Re, ...t };
107
- }
108
- const Ve = {
109
- settings: {
110
- volume: 0,
111
- mute: !0
112
- }
113
- };
114
- function Ee() {
115
- return Ve;
116
- }
117
- function Un(t, n = {}) {
118
- if (!t)
119
- throw new Error("atrament.init: provide ink Story constructor as a first argument!");
120
- if (typeof t != "function")
121
- throw new Error("atrament.init: Story is not a constructor!");
122
- if (!n.applicationID)
123
- throw new Error("atrament.init: config.applicationID is not set!");
124
- Ve.InkStory = t, Object.entries(n).forEach(([r, i]) => {
125
- Ve[r] = JSON.parse(JSON.stringify(i));
126
- });
127
- }
128
- function Rn(t) {
129
- return { all: t = t || /* @__PURE__ */ new Map(), on: function(n, r) {
130
- var i = t.get(n);
131
- i ? i.push(r) : t.set(n, [r]);
132
- }, off: function(n, r) {
133
- var i = t.get(n);
134
- i && (r ? i.splice(i.indexOf(r) >>> 0, 1) : t.set(n, []));
135
- }, emit: function(n, r) {
136
- var i = t.get(n);
137
- i && i.slice().map(function(u) {
138
- u(r);
139
- }), (i = t.get("*")) && i.slice().map(function(u) {
140
- u(n, r);
141
- });
142
- } };
143
- }
144
- const Ge = Rn(), w = (...t) => Ge.emit(...t);
145
- function q(t) {
146
- return Array.isArray(t) ? t : [t];
147
- }
148
- function Vn(t) {
149
- return [...t].reduce((n, r) => Math.imul(31, n) + r.charCodeAt(0) | 0, 0);
150
- }
151
- async function kt(t) {
152
- const { persistent: n } = y(), r = await n.keys();
153
- await Promise.all(
154
- r.map(
155
- async (i) => {
156
- if (!i.includes("save"))
157
- return;
158
- const u = await n.get(i);
159
- await t(i, u);
160
- }
161
- )
162
- );
163
- }
164
- function ee(t) {
165
- return typeof t == "number" || typeof t == "string" ? t : "";
166
- }
167
- function Gn() {
168
- const { state: t } = y();
169
- return ee(t.get().game.$sessionID);
170
- }
171
- function Hn(t) {
172
- const { state: n } = y(), r = ee(t);
173
- n.setSubkey("game", "$sessionID", r), w("game/setSession", r);
174
- }
175
- async function Jn() {
176
- const t = {};
177
- return await kt(async (n, r) => {
178
- const i = ee(r.game.$sessionID);
179
- t[i] ? t[i] += 1 : t[i] = 1;
180
- }), w("game/getSessions", t), t;
181
- }
182
- async function qn(t) {
183
- const { persistent: n } = y(), r = ee(t);
184
- await kt(async (i, u) => {
185
- ee(u.game.$sessionID) === r && await n.remove(i);
186
- }), w("game/deleteSession", r);
187
- }
188
- function je(t) {
189
- if (!t)
190
- return {};
191
- const n = {};
192
- return t.forEach((r) => {
193
- let i, u;
194
- const d = r.match(/\s*(\w+)\s*:\s*(.+?)\s*$/);
195
- if (d) {
196
- const [, _, p] = d;
197
- i = _;
198
- try {
199
- u = JSON.parse(p);
200
- } catch {
201
- const h = p.substr(0, 1);
202
- h === "{" || h === "[" ? console.warn("Malformed JSON tag, ignored.", _, p) : u = p;
203
- }
204
- } else
205
- i = r, u = !0;
206
- Array.isArray(n[i]) ? n[i].push(u) : n[i] ? n[i] = [n[i], u] : n[i] = u;
207
- }), n;
208
- }
209
- let k = null;
210
- function Wn(t, n) {
211
- const { InkStory: r } = Ee();
212
- try {
213
- k = new r(t);
214
- } catch (i) {
215
- throw console.log(i), Error(`Failed to parse Ink script: ${n}`);
216
- }
217
- w("ink/initStory");
218
- }
219
- function jn() {
220
- let t = !1;
221
- k && (k.ResetState(), t = !0), w("ink/resetStory", t);
222
- }
223
- function He(t, n) {
224
- if (!t.canContinue)
225
- return;
226
- t.Continue();
227
- const r = t.currentText;
228
- r && r !== `
229
- ` && (n.isEmpty = !1), n.text.push(r);
230
- const i = je(t.currentTags);
231
- n.tags = { ...n.tags, ...i }, n.content.push({ text: r, tags: i }), r === `
232
- ` && He(t, n);
233
- }
234
- function zn(t) {
235
- const n = {
236
- content: [],
237
- text: [],
238
- tags: {},
239
- choices: [],
240
- isEmpty: !0,
241
- uuid: Date.now()
242
- };
243
- if (t)
244
- for (; k.canContinue; )
245
- He(k, n);
246
- else
247
- He(k, n), n.canContinue = k.canContinue;
248
- return k.currentChoices.forEach((r, i) => {
249
- n.choices.push({
250
- id: i,
251
- choice: r.text,
252
- tags: je(r.tags)
253
- });
254
- }), w("ink/getScene", n), n;
255
- }
256
- const $ = {
257
- initStory: Wn,
258
- resetStory: jn,
259
- story: () => k,
260
- loadState: (t) => k.state.LoadJson(t),
261
- getState: () => k.state.toJson(),
262
- makeChoice: (t) => {
263
- k.ChooseChoiceIndex(t), w("ink/makeChoice", t);
264
- },
265
- getVisitCount: (t) => {
266
- const n = k.VisitCountAtPathString(t);
267
- return w("ink/getVisitCount", { ref: t, visitCount: n }), n;
268
- },
269
- evaluateFunction: (t, n, r) => {
270
- const i = k.EvaluateFunction(t, n, r);
271
- return w("ink/evaluateFunction", { function: t, args: n, result: i }), i;
272
- },
273
- getGlobalTags: () => {
274
- const t = je(k.globalTags);
275
- return w("ink/getGlobalTags", t), t;
276
- },
277
- getVariable: (t) => {
278
- const n = k.variablesState[t];
279
- return w("ink/getVariable", { name: t, value: n }), n;
280
- },
281
- getVariables: () => {
282
- const t = k.variablesState, n = {};
283
- return t._globalVariables.forEach(
284
- /* eslint-disable-line no-underscore-dangle */
285
- (r, i) => {
286
- n[i] = t[i];
287
- }
288
- ), w("ink/getVariables", n), n;
289
- },
290
- setVariable: (t, n) => {
291
- k.variablesState[t] = n, w("ink/setVariable", { name: t, value: n });
292
- },
293
- observeVariable: (t, n) => k.ObserveVariable(t, n),
294
- goTo: (t) => {
295
- k.ChoosePathString(t), w("ink/goTo", t);
296
- },
297
- onError: (t) => {
298
- k.onError = (n) => {
299
- w("ink/onError", n), t(n);
300
- };
301
- },
302
- getScene: zn
61
+ function ne() {
62
+ y.settings = {}, y.game = {}, y.metadata = {}, y.scenes = [], y.vars = {};
63
+ }
64
+ function re() {
65
+ return y;
66
+ }
67
+ function ie() {
68
+ return JSON.parse(JSON.stringify(y));
69
+ }
70
+ function b(e, t) {
71
+ y[e] = t;
72
+ }
73
+ function ae(e) {
74
+ y[e] = !y[e];
75
+ }
76
+ function x(e, t) {
77
+ y[e] = [...y[e], t];
78
+ }
79
+ function oe(e, t, n) {
80
+ y[e] = {
81
+ ...y[e],
82
+ [t]: n
83
+ };
84
+ }
85
+ function se(e, t) {
86
+ y[e] = {
87
+ ...y[e],
88
+ [t]: !y[e][t]
89
+ };
90
+ }
91
+ function ce(e, t, n) {
92
+ y[e] = {
93
+ ...y[e],
94
+ [t]: [...y[e][t], n]
95
+ };
96
+ }
97
+ var S = {
98
+ loader: null,
99
+ persistent: v,
100
+ sound: te,
101
+ state: {
102
+ reset: ne,
103
+ store: re,
104
+ get: ie,
105
+ setKey: b,
106
+ toggleKey: ae,
107
+ appendKey: x,
108
+ setSubkey: oe,
109
+ toggleSubkey: se,
110
+ appendSubkey: ce
111
+ }
112
+ }, C = () => S;
113
+ function w(e) {
114
+ S = {
115
+ ...S,
116
+ ...e
117
+ };
118
+ }
119
+ var T = { settings: {
120
+ volume: 0,
121
+ mute: !0
122
+ } };
123
+ function E() {
124
+ return T;
125
+ }
126
+ function le(e, t = {}) {
127
+ if (!e) throw Error("atrament.init: provide ink Story constructor as a first argument!");
128
+ if (typeof e != "function") throw Error("atrament.init: Story is not a constructor!");
129
+ if (!t.applicationID) throw Error("atrament.init: config.applicationID is not set!");
130
+ T.InkStory = e, Object.entries(t).forEach(([e, t]) => {
131
+ T[e] = JSON.parse(JSON.stringify(t));
132
+ });
133
+ }
134
+ function ue(e) {
135
+ return {
136
+ all: e ||= /* @__PURE__ */ new Map(),
137
+ on: function(t, n) {
138
+ var r = e.get(t);
139
+ r ? r.push(n) : e.set(t, [n]);
140
+ },
141
+ off: function(t, n) {
142
+ var r = e.get(t);
143
+ r && (n ? r.splice(r.indexOf(n) >>> 0, 1) : e.set(t, []));
144
+ },
145
+ emit: function(t, n) {
146
+ var r = e.get(t);
147
+ r && r.slice().map(function(e) {
148
+ e(n);
149
+ }), (r = e.get("*")) && r.slice().map(function(e) {
150
+ e(t, n);
151
+ });
152
+ }
153
+ };
154
+ }
155
+ var D = ue(), O = (...e) => D.emit(...e);
156
+ function k(e) {
157
+ return Array.isArray(e) ? e : [e];
158
+ }
159
+ function A(e) {
160
+ return [...e].reduce((e, t) => Math.imul(31, e) + t.charCodeAt(0) | 0, 0);
161
+ }
162
+ async function de(e) {
163
+ let { persistent: t } = C(), n = await t.keys();
164
+ await Promise.all(n.map(async (n) => {
165
+ n.includes("save") && await e(n, await t.get(n));
166
+ }));
167
+ }
168
+ function j(e) {
169
+ return typeof e == "number" || typeof e == "string" ? e : "";
170
+ }
171
+ function fe() {
172
+ let { state: e } = C();
173
+ return j(e.get().game.$sessionID);
174
+ }
175
+ function pe(e) {
176
+ let { state: t } = C(), n = j(e);
177
+ t.setSubkey("game", "$sessionID", n), O("game/setSession", n);
178
+ }
179
+ async function me() {
180
+ let e = {};
181
+ return await de(async (t, n) => {
182
+ let r = j(n.game.$sessionID);
183
+ e[r] ? e[r] += 1 : e[r] = 1;
184
+ }), O("game/getSessions", e), e;
185
+ }
186
+ async function he(e) {
187
+ let { persistent: t } = C(), n = j(e);
188
+ await de(async (e, r) => {
189
+ j(r.game.$sessionID) === n && await t.remove(e);
190
+ }), O("game/deleteSession", n);
191
+ }
192
+ function ge(e) {
193
+ if (!e) return {};
194
+ let t = {};
195
+ return e.forEach((e) => {
196
+ let n, r, i = e.match(/\s*(\w+)\s*:\s*(.+?)\s*$/);
197
+ if (i) {
198
+ let [, e, t] = i;
199
+ n = e;
200
+ try {
201
+ r = JSON.parse(t);
202
+ } catch {
203
+ let n = t.substr(0, 1);
204
+ n === "{" || n === "[" ? console.warn("Malformed JSON tag, ignored.", e, t) : r = t;
205
+ }
206
+ } else n = e, r = !0;
207
+ Array.isArray(t[n]) ? t[n].push(r) : t[n] ? t[n] = [t[n], r] : t[n] = r;
208
+ }), t;
209
+ }
210
+ var M = null;
211
+ function _e(e, t) {
212
+ let { InkStory: n } = E();
213
+ try {
214
+ M = new n(e);
215
+ } catch (e) {
216
+ throw console.log(e), Error(`Failed to parse Ink script: ${t}`);
217
+ }
218
+ O("ink/initStory");
219
+ }
220
+ function ve() {
221
+ let e = !1;
222
+ M && (M.ResetState(), e = !0), O("ink/resetStory", e);
223
+ }
224
+ function ye(e, t) {
225
+ if (!e.canContinue) return;
226
+ e.Continue();
227
+ let n = e.currentText;
228
+ n && n !== "\n" && (t.isEmpty = !1), t.text.push(n);
229
+ let r = ge(e.currentTags);
230
+ t.tags = {
231
+ ...t.tags,
232
+ ...r
233
+ }, t.content.push({
234
+ text: n,
235
+ tags: r
236
+ }), n === "\n" && ye(e, t);
237
+ }
238
+ function be(e) {
239
+ let t = {
240
+ content: [],
241
+ text: [],
242
+ tags: {},
243
+ choices: [],
244
+ isEmpty: !0,
245
+ uuid: Date.now()
246
+ };
247
+ if (e) for (; M.canContinue;) ye(M, t);
248
+ else ye(M, t), t.canContinue = M.canContinue;
249
+ return M.currentChoices.forEach((e, n) => {
250
+ t.choices.push({
251
+ id: n,
252
+ choice: e.text,
253
+ tags: ge(e.tags)
254
+ });
255
+ }), O("ink/getScene", t), t;
256
+ }
257
+ var N = {
258
+ initStory: _e,
259
+ resetStory: ve,
260
+ story: () => M,
261
+ loadState: (e) => M.state.LoadJson(e),
262
+ getState: () => M.state.toJson(),
263
+ makeChoice: (e) => {
264
+ M.ChooseChoiceIndex(e), O("ink/makeChoice", e);
265
+ },
266
+ getVisitCount: (e) => {
267
+ let t = M.VisitCountAtPathString(e);
268
+ return O("ink/getVisitCount", {
269
+ ref: e,
270
+ visitCount: t
271
+ }), t;
272
+ },
273
+ evaluateFunction: (e, t, n) => {
274
+ let r = M.EvaluateFunction(e, t, n);
275
+ return O("ink/evaluateFunction", {
276
+ function: e,
277
+ args: t,
278
+ result: r
279
+ }), r;
280
+ },
281
+ getGlobalTags: () => {
282
+ let e = ge(M.globalTags);
283
+ return O("ink/getGlobalTags", e), e;
284
+ },
285
+ getVariable: (e) => {
286
+ let t = M.variablesState[e];
287
+ return O("ink/getVariable", {
288
+ name: e,
289
+ value: t
290
+ }), t;
291
+ },
292
+ getVariables: () => {
293
+ let e = M.variablesState, t = {};
294
+ return e._globalVariables.forEach((n, r) => {
295
+ t[r] = e[r];
296
+ }), O("ink/getVariables", t), t;
297
+ },
298
+ setVariable: (e, t) => {
299
+ M.variablesState[e] = t, O("ink/setVariable", {
300
+ name: e,
301
+ value: t
302
+ });
303
+ },
304
+ observeVariable: (e, t) => M.ObserveVariable(e, t),
305
+ goTo: (e) => {
306
+ M.ChoosePathString(e), O("ink/goTo", e);
307
+ },
308
+ onError: (e) => {
309
+ M.onError = (t) => {
310
+ O("ink/onError", t), e(t);
311
+ };
312
+ },
313
+ getScene: be
303
314
  };
304
- function vt(t) {
305
- const { sound: n, loader: r } = y();
306
- q(t).forEach(
307
- (i) => n.playSound(r.getAssetPath(i))
308
- );
309
- }
310
- function Me(t) {
311
- const { sound: n, loader: r } = y();
312
- q(t).forEach(
313
- (i) => n.stopSound(i ? r.getAssetPath(i) : null)
314
- );
315
- }
316
- function Tt(t) {
317
- const { sound: n, state: r, loader: i } = y(), u = r.get().game.$currentMusic || [];
318
- q(t).forEach((d) => {
319
- n.playMusic(i.getAssetPath(d)), u.push(d);
320
- }), r.setSubkey("game", "$currentMusic", u);
321
- }
322
- function Qn(t) {
323
- const { sound: n, state: r, loader: i } = y();
324
- n.stopMusic();
325
- const u = q(t).pop();
326
- n.playMusic(i.getAssetPath(u)), r.setSubkey("game", "$currentMusic", [u]);
327
- }
328
- function fe(t) {
329
- const { sound: n, state: r, loader: i } = y();
330
- let u = r.get().game.$currentMusic || [];
331
- q(t).forEach((d) => {
332
- d ? (n.stopMusic(i.getAssetPath(d)), u = u.filter((_) => _ !== d)) : (n.stopMusic(), u = []);
333
- }), r.setSubkey("game", "$currentMusic", u);
334
- }
335
- const xe = "game", Ie = "autosave", Ce = "checkpoint";
336
- function ze(t) {
337
- const { $gameUUID: n, $sessionID: r } = y().state.get().game;
338
- return [
339
- n,
340
- ee(r),
341
- t
342
- ].join("/");
343
- }
344
- function _e({ name: t, type: n }) {
345
- return [
346
- ze("save"),
347
- [xe, Ie, Ce].includes(n) ? n : xe,
348
- typeof t == "string" || typeof t == "number" ? t : ""
349
- ].join("/");
350
- }
351
- function Et(t) {
352
- const { state: n } = y();
353
- n.setKey("scenes", t.scenes), n.setKey("game", t.game), $.loadState(t.state);
354
- }
355
- async function It(t) {
356
- let n = t;
357
- typeof t == "object" && (n = _e(t));
358
- const { persistent: r } = y(), i = await r.get(n);
359
- Et(i), w("game/load", n);
360
- }
361
- function Ct() {
362
- const { state: t } = y(), n = t.get();
363
- return {
364
- date: Date.now(),
365
- state: $.getState(),
366
- game: n.game,
367
- scenes: n.scenes
368
- };
369
- }
370
- async function Qe({ name: t, description: n, type: r }) {
371
- const { persistent: i } = y(), u = Ct(), d = {
372
- name: t,
373
- description: n,
374
- type: r,
375
- ...u
376
- }, _ = _e({ name: t, type: r });
377
- await i.set(_, d), w("game/save", _, n);
378
- }
379
- async function Ye(t) {
380
- return await y().persistent.exists(t);
381
- }
382
- async function Yn(t) {
383
- await y().persistent.remove(t), w("game/removeSave", t);
384
- }
385
- async function Ot() {
386
- const { persistent: t } = y(), n = (await t.keys()).filter((i) => i.includes(ze("save"))), r = await Promise.all(
387
- n.map(
388
- async (i) => {
389
- const u = await t.get(i);
390
- return u.id = i, delete u.state, delete u.scenes, u;
391
- }
392
- )
393
- );
394
- return w("game/listSaves", r), r;
395
- }
396
- function ie(t, n, r) {
397
- t[r] || (t[r] = []), t.content = t.content.map((i) => {
398
- i[r] || (i[r] = []);
399
- const u = i.tags?.[n];
400
- if (u) {
401
- const d = q(u);
402
- t[r] = [...t[r], ...d], i[r] = [...i[r], ...d];
403
- }
404
- return i;
405
- });
406
- }
407
- function Xn(t) {
408
- t.choices = t.choices.map((n) => ((n.tags.UNCLICKABLE || n.tags.DISABLED || n.tags.INACTIVE) && (n.disabled = !0), n));
409
- }
410
- const Zn = [
411
- (t) => ie(t, "IMAGE", "images"),
412
- (t) => ie(t, "AUDIO", "sounds"),
413
- (t) => ie(t, "PLAY_SOUND", "sounds"),
414
- (t) => ie(t, "AUDIOLOOP", "music"),
415
- (t) => ie(t, "PLAY_MUSIC", "music"),
416
- Xn
417
- ];
418
- let Xe = null, Pt = null;
419
- const $t = [], Y = {};
420
- function Lt() {
421
- const { state: t } = y();
422
- t.setKey("scenes", []), t.setKey("vars", {});
423
- }
424
- function Ft(t) {
425
- const { state: n } = y(), r = n.get().metadata.observe;
426
- r && q(r).forEach(t);
427
- }
428
- async function er() {
429
- const { state: t, persistent: n } = y(), { game: r, metadata: i } = t.get(), u = i.persist;
430
- if (!u)
431
- return;
432
- const d = r.$gameUUID, _ = ze("persist");
433
- await n.exists(_) ? (Y[d] = await n.get(_), Object.entries(Y[d]).forEach(
434
- ([p, h]) => $.setVariable(p, h)
435
- )) : Y[d] || (Y[d] = {}), q(u).forEach((p) => {
436
- $.observeVariable(p, async (h, A) => {
437
- Y[d][h] = A, await n.set(_, Y[d]);
438
- });
439
- });
440
- }
441
- async function tr(t, n, r) {
442
- await y().loader.init(t);
443
- const i = {
444
- $path: t,
445
- $file: n,
446
- $gameUUID: r || Vn(`${t}|${n}`)
447
- };
448
- y().state.setKey("game", i), Xe = i.$gameUUID, w("game/init", { pathToInkFile: t, inkFile: n });
449
- }
450
- async function Mt() {
451
- const { game: t } = y().state.get();
452
- let n = await y().loader.loadInk(t.$file);
453
- return typeof n == "string" && (n = n.replace("\uFEFF", "")), w("game/loadInkFile", t.$file), n;
454
- }
455
- async function Bt() {
456
- const { state: t } = y(), n = await Mt(), { game: r } = t.get();
457
- $.initStory(n, `${r.$path}/${r.$file}`);
458
- const i = $.getGlobalTags();
459
- t.setKey("metadata", i), Ft((u) => {
460
- $.observeVariable(u, (d, _) => {
461
- t.setSubkey("vars", d, _), w("ink/variableObserver", { name: d, value: _ });
462
- });
463
- }), Pt = Xe, w("game/initInkStory");
464
- }
465
- async function Ze(t) {
466
- const { state: n } = y();
467
- fe(), Lt(), Pt !== Xe && await Bt();
468
- let r = !0;
469
- if (t && await Ye(t)) {
470
- await It(t);
471
- const { game: i } = n.get();
472
- i.$currentMusic && Tt(i.$currentMusic), r = !1;
473
- }
474
- await er(), Ft((i) => {
475
- n.setSubkey("vars", i, $.getVariable(i));
476
- }), w("game/start", { saveSlot: t }), (r || !r && n.get().metadata.continue_maximally !== !1) && Gt();
477
- }
478
- async function Nt() {
479
- let t = null;
480
- const n = _e({ type: Ie });
481
- if (await Ye(n))
482
- t = n;
483
- else {
484
- const r = (await Ot()).filter((i) => i.type === Ce);
485
- r.length && (t = r.sort((i, u) => u.date - i.date)[0].id);
486
- }
487
- return w("game/canResume", t), t;
488
- }
489
- async function nr() {
490
- const t = await Nt();
491
- w("game/resume", { saveSlot: t }), $.resetStory(), await Ze(t);
492
- }
493
- async function et(t) {
494
- w("game/restart", { saveSlot: t }), $.resetStory(), await Ze(t);
495
- }
496
- async function Dt(t) {
497
- await et(_e({ type: "checkpoint", name: t }));
498
- }
499
- function Kt() {
500
- fe(), Lt(), $.resetStory(), w("game/clear");
501
- }
502
- function rr() {
503
- const { state: t } = y();
504
- Kt(), t.setKey("metadata", {}), t.setKey("game", {}), w("game/reset");
505
- }
506
- async function Ut(t, n = "") {
507
- await Qe({ type: xe, name: t, description: n });
508
- }
509
- async function Rt(t) {
510
- await Qe({ type: Ce, name: t });
511
- }
512
- async function Vt() {
513
- await Qe({ type: Ie });
514
- }
515
- const mt = {
516
- CLEAR: () => y().state.setKey("scenes", []),
517
- AUDIO: (t) => t ? vt(t) : Me(),
518
- AUDIOLOOP: (t) => t ? Qn(t) : fe(),
519
- PLAY_SOUND: vt,
520
- STOP_SOUND: (t) => t === !0 ? Me() : Me(t),
521
- PLAY_MUSIC: Tt,
522
- STOP_MUSIC: (t) => t === !0 ? fe() : fe(t),
523
- CHECKPOINT: (t) => Rt(t),
524
- SAVEGAME: (t) => Ut(t)
525
- };
526
- function ht(t, n) {
527
- t.forEach((r) => {
528
- r in n && r in mt && (mt[r](n[r]), w("game/handletag", { [r]: n[r] }));
529
- });
530
- }
531
- function ar(t) {
532
- $t.push(t);
533
- }
534
- function Gt() {
535
- const { state: t } = y(), { metadata: n } = t.get(), r = n.continue_maximally !== !1, i = $.getScene(r);
536
- if (!i.content || i.content.length === 0)
537
- return;
538
- Zn.forEach((d) => d(i)), $t.forEach((d) => d(i));
539
- const { tags: u } = i;
540
- if (u.RESTART) {
541
- et();
542
- return;
543
- }
544
- if (u.RESTART_FROM_CHECKPOINT) {
545
- Dt(u.RESTART_FROM_CHECKPOINT);
546
- return;
547
- }
548
- ht(
549
- ["CLEAR", "STOP_SOUND", "STOP_MUSIC", "PLAY_SOUND", "PLAY_MUSIC", "AUDIO", "AUDIOLOOP"],
550
- u
551
- ), n.single_scene ? t.setKey("scenes", [i]) : t.appendKey("scenes", i), ht(
552
- ["CHECKPOINT", "SAVEGAME"],
553
- u
554
- ), n.autosave !== !1 && Vt(), w("game/continueStory");
555
- }
556
- const or = {
557
- // game-control
558
- init: tr,
559
- loadInkFile: Mt,
560
- initInkStory: Bt,
561
- start: Ze,
562
- clear: Kt,
563
- reset: rr,
564
- // game
565
- resume: nr,
566
- canResume: Nt,
567
- restart: et,
568
- restartFromCheckpoint: Dt,
569
- continueStory: Gt,
570
- makeChoice: (t) => $.makeChoice(t),
571
- getAssetPath: (t) => y().loader.getAssetPath(t),
572
- defineSceneProcessor: ar,
573
- // saves
574
- SAVE_GAME: xe,
575
- SAVE_AUTOSAVE: Ie,
576
- SAVE_CHECKPOINT: Ce,
577
- getSaveSlotKey: _e,
578
- saveGame: Ut,
579
- saveCheckpoint: Rt,
580
- saveAutosave: Vt,
581
- load: It,
582
- getState: Ct,
583
- setState: Et,
584
- listSaves: Ot,
585
- removeSave: Yn,
586
- existSave: Ye,
587
- // sessions
588
- getSession: Gn,
589
- setSession: Hn,
590
- getSessions: Jn,
591
- removeSession: qn
592
- }, le = {
593
- mute: (t, n) => y().sound.mute(n),
594
- volume: (t, n) => y().sound.setVolume(n)
595
- };
596
- async function ir() {
597
- const { state: t, persistent: n } = y(), r = JSON.parse(JSON.stringify(Ee().settings));
598
- let i = {};
599
- await n.exists("settings") && (i = await n.get("settings"));
600
- const u = { ...r, ...i };
601
- t.setKey("settings", u), tt(), w("settings/load", u);
602
- }
603
- async function sr() {
604
- const { state: t, persistent: n } = y(), r = t.get();
605
- await n.set("settings", r.settings), w("settings/save", r.settings);
606
- }
607
- function Ht(t) {
608
- const n = y().state.get().settings[t];
609
- return w("settings/get", { name: t, value: n }), n;
610
- }
611
- function Jt(t, n) {
612
- const { state: r } = y(), i = r.get().settings[t];
613
- r.setSubkey("settings", t, n), le[t] && le[t](i, n), w("settings/set", { name: t, value: n });
614
- }
615
- function ur(t) {
616
- const n = Ht(t);
617
- Jt(t, !n);
618
- }
619
- function fr(t, n) {
620
- le[t] = n;
315
+ function xe(e) {
316
+ let { sound: t, loader: n } = C();
317
+ k(e).forEach((e) => t.playSound(n.getAssetPath(e)));
318
+ }
319
+ function Se(e) {
320
+ let { sound: t, loader: n } = C();
321
+ k(e).forEach((e) => t.stopSound(e ? n.getAssetPath(e) : null));
322
+ }
323
+ function Ce(e) {
324
+ let { sound: t, state: n, loader: r } = C(), i = n.get().game.$currentMusic || [];
325
+ k(e).forEach((e) => {
326
+ t.playMusic(r.getAssetPath(e)), i.push(e);
327
+ }), n.setSubkey("game", "$currentMusic", i);
328
+ }
329
+ function we(e) {
330
+ let { sound: t, state: n, loader: r } = C();
331
+ t.stopMusic();
332
+ let i = k(e).pop();
333
+ t.playMusic(r.getAssetPath(i)), n.setSubkey("game", "$currentMusic", [i]);
334
+ }
335
+ function P(e) {
336
+ let { sound: t, state: n, loader: r } = C(), i = n.get().game.$currentMusic || [];
337
+ k(e).forEach((e) => {
338
+ e ? (t.stopMusic(r.getAssetPath(e)), i = i.filter((t) => t !== e)) : (t.stopMusic(), i = []);
339
+ }), n.setSubkey("game", "$currentMusic", i);
340
+ }
341
+ var Te = "game", Ee = "autosave", De = "checkpoint";
342
+ function Oe(e) {
343
+ let { $gameUUID: t, $sessionID: n } = C().state.get().game;
344
+ return [
345
+ t,
346
+ j(n),
347
+ e
348
+ ].join("/");
349
+ }
350
+ function ke({ name: e, type: t }) {
351
+ return [
352
+ Oe("save"),
353
+ [
354
+ Te,
355
+ Ee,
356
+ De
357
+ ].includes(t) ? t : Te,
358
+ typeof e == "string" || typeof e == "number" ? e : ""
359
+ ].join("/");
360
+ }
361
+ function Ae(e) {
362
+ let { state: t } = C();
363
+ t.setKey("scenes", e.scenes), t.setKey("game", e.game), N.loadState(e.state);
364
+ }
365
+ async function je(e) {
366
+ let t = e;
367
+ typeof e == "object" && (t = ke(e));
368
+ let { persistent: n } = C();
369
+ Ae(await n.get(t)), O("game/load", t);
370
+ }
371
+ function Me() {
372
+ let { state: e } = C(), t = e.get();
373
+ return {
374
+ date: Date.now(),
375
+ state: N.getState(),
376
+ game: t.game,
377
+ scenes: t.scenes
378
+ };
379
+ }
380
+ async function Ne({ name: e, description: t, type: n }) {
381
+ let { persistent: r } = C(), i = {
382
+ name: e,
383
+ description: t,
384
+ type: n,
385
+ ...Me()
386
+ }, a = ke({
387
+ name: e,
388
+ type: n
389
+ });
390
+ await r.set(a, i), O("game/save", a, t);
391
+ }
392
+ async function Pe(e) {
393
+ return await C().persistent.exists(e);
394
+ }
395
+ async function Fe(e) {
396
+ await C().persistent.remove(e), O("game/removeSave", e);
397
+ }
398
+ async function Ie() {
399
+ let { persistent: e } = C(), t = (await e.keys()).filter((e) => e.includes(Oe("save"))), n = await Promise.all(t.map(async (t) => {
400
+ let n = await e.get(t);
401
+ return n.id = t, delete n.state, delete n.scenes, n;
402
+ }));
403
+ return O("game/listSaves", n), n;
404
+ }
405
+ function Le(e, t, n) {
406
+ e[n] || (e[n] = []), e.content = e.content.map((r) => {
407
+ r[n] || (r[n] = []);
408
+ let i = r.tags?.[t];
409
+ if (i) {
410
+ let t = k(i);
411
+ e[n] = [...e[n], ...t], r[n] = [...r[n], ...t];
412
+ }
413
+ return r;
414
+ });
415
+ }
416
+ function Re(e) {
417
+ e.choices = e.choices.map((e) => ((e.tags.UNCLICKABLE || e.tags.DISABLED || e.tags.INACTIVE) && (e.disabled = !0), e));
418
+ }
419
+ var ze = [
420
+ (e) => Le(e, "IMAGE", "images"),
421
+ (e) => Le(e, "AUDIO", "sounds"),
422
+ (e) => Le(e, "PLAY_SOUND", "sounds"),
423
+ (e) => Le(e, "AUDIOLOOP", "music"),
424
+ (e) => Le(e, "PLAY_MUSIC", "music"),
425
+ Re
426
+ ], Be = null, Ve = null, He = [], F = {};
427
+ function Ue() {
428
+ let { state: e } = C();
429
+ e.setKey("scenes", []), e.setKey("vars", {});
430
+ }
431
+ function We(e) {
432
+ let { state: t } = C(), n = t.get().metadata.observe;
433
+ n && k(n).forEach(e);
434
+ }
435
+ async function Ge() {
436
+ let { state: e, persistent: t } = C(), { game: n, metadata: r } = e.get(), i = r.persist;
437
+ if (!i) return;
438
+ let a = n.$gameUUID, o = Oe("persist");
439
+ await t.exists(o) ? (F[a] = await t.get(o), Object.entries(F[a]).forEach(([e, t]) => N.setVariable(e, t))) : F[a] || (F[a] = {}), k(i).forEach((e) => {
440
+ N.observeVariable(e, async (e, n) => {
441
+ F[a][e] = n, await t.set(o, F[a]);
442
+ });
443
+ });
444
+ }
445
+ async function Ke(e, t, n) {
446
+ await C().loader.init(e);
447
+ let r = {
448
+ $path: e,
449
+ $file: t,
450
+ $gameUUID: n || A(`${e}|${t}`)
451
+ };
452
+ C().state.setKey("game", r), Be = r.$gameUUID, O("game/init", {
453
+ pathToInkFile: e,
454
+ inkFile: t
455
+ });
456
+ }
457
+ async function qe() {
458
+ let { game: e } = C().state.get(), t = await C().loader.loadInk(e.$file);
459
+ return typeof t == "string" && (t = t.replace("", "")), O("game/loadInkFile", e.$file), t;
460
+ }
461
+ async function Je() {
462
+ let { state: e } = C(), t = await qe(), { game: n } = e.get();
463
+ N.initStory(t, `${n.$path}/${n.$file}`);
464
+ let r = N.getGlobalTags();
465
+ e.setKey("metadata", r), We((t) => {
466
+ N.observeVariable(t, (t, n) => {
467
+ e.setSubkey("vars", t, n), O("ink/variableObserver", {
468
+ name: t,
469
+ value: n
470
+ });
471
+ });
472
+ }), Ve = Be, O("game/initInkStory");
473
+ }
474
+ async function Ye(e) {
475
+ let { state: t } = C();
476
+ P(), Ue(), Ve !== Be && await Je();
477
+ let n = !0;
478
+ if (e && await Pe(e)) {
479
+ await je(e);
480
+ let { game: r } = t.get();
481
+ r.$currentMusic && Ce(r.$currentMusic), n = !1;
482
+ }
483
+ await Ge(), We((e) => {
484
+ t.setSubkey("vars", e, N.getVariable(e));
485
+ }), O("game/start", { saveSlot: e }), (n || !n && t.get().metadata.continue_maximally !== !1) && ct();
486
+ }
487
+ async function Xe() {
488
+ let e = null, t = ke({ type: Ee });
489
+ if (await Pe(t)) e = t;
490
+ else {
491
+ let t = (await Ie()).filter((e) => e.type === De);
492
+ t.length && (e = t.sort((e, t) => t.date - e.date)[0].id);
493
+ }
494
+ return O("game/canResume", e), e;
495
+ }
496
+ async function Ze() {
497
+ let e = await Xe();
498
+ O("game/resume", { saveSlot: e }), N.resetStory(), await Ye(e);
499
+ }
500
+ async function Qe(e) {
501
+ O("game/restart", { saveSlot: e }), N.resetStory(), await Ye(e);
502
+ }
503
+ async function $e(e) {
504
+ await Qe(ke({
505
+ type: "checkpoint",
506
+ name: e
507
+ }));
508
+ }
509
+ function et() {
510
+ P(), Ue(), N.resetStory(), O("game/clear");
621
511
  }
622
512
  function tt() {
623
- const t = y().state.get().settings;
624
- Object.entries(t).forEach(([n, r]) => {
625
- le[n] && le[n](null, r);
626
- });
627
- }
628
- function cr() {
629
- const { state: t } = y(), n = JSON.parse(JSON.stringify(Ee().settings));
630
- t.setKey("settings", n), tt(), w("settings/reset", n);
631
- }
632
- const qt = {
633
- load: ir,
634
- save: sr,
635
- get: Ht,
636
- set: Jt,
637
- toggle: ur,
638
- defineHandler: fr,
639
- runHandlers: tt,
640
- reset: cr
641
- }, lr = "2.1.5";
642
- async function dr(t, n) {
643
- w("atrament/init");
644
- const { persistent: r } = y();
645
- Un(t, n), r.init(Ee().applicationID), await qt.load();
646
- }
647
- const _r = {
648
- get interfaces() {
649
- return y();
650
- },
651
- defineInterfaces: Kn,
652
- init: dr,
653
- get state() {
654
- return y().state;
655
- },
656
- get store() {
657
- return y().state.store();
658
- },
659
- on: (t, n) => Ge.on(t, n),
660
- off: (t, n) => Ge.off(t, n),
661
- emit: w,
662
- // sub-objects
663
- game: or,
664
- ink: $,
665
- settings: qt,
666
- version: lr
513
+ let { state: e } = C();
514
+ et(), e.setKey("metadata", {}), e.setKey("game", {}), O("game/reset");
515
+ }
516
+ async function nt(e, t = "") {
517
+ await Ne({
518
+ type: Te,
519
+ name: e,
520
+ description: t
521
+ });
522
+ }
523
+ async function rt(e) {
524
+ await Ne({
525
+ type: De,
526
+ name: e
527
+ });
528
+ }
529
+ async function it() {
530
+ await Ne({ type: Ee });
531
+ }
532
+ var at = {
533
+ CLEAR: () => C().state.setKey("scenes", []),
534
+ AUDIO: (e) => e ? xe(e) : Se(),
535
+ AUDIOLOOP: (e) => e ? we(e) : P(),
536
+ PLAY_SOUND: xe,
537
+ STOP_SOUND: (e) => e === !0 ? Se() : Se(e),
538
+ PLAY_MUSIC: Ce,
539
+ STOP_MUSIC: (e) => e === !0 ? P() : P(e),
540
+ CHECKPOINT: (e) => rt(e),
541
+ SAVEGAME: (e) => nt(e)
667
542
  };
668
- var gt = {}, pr = (function(t, n, r, i, u) {
669
- var d = new Worker(gt[n] || (gt[n] = URL.createObjectURL(new Blob([
670
- t + ';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'
671
- ], { type: "text/javascript" }))));
672
- return d.onmessage = function(_) {
673
- var p = _.data, h = p.$e$;
674
- if (h) {
675
- var A = new Error(h[0]);
676
- A.code = h[1], A.stack = h[2], u(A, null);
677
- } else
678
- u(null, p);
679
- }, d.postMessage(r, i), d;
680
- }), P = Uint8Array, j = Uint16Array, Wt = Int32Array, nt = new P([
681
- 0,
682
- 0,
683
- 0,
684
- 0,
685
- 0,
686
- 0,
687
- 0,
688
- 0,
689
- 1,
690
- 1,
691
- 1,
692
- 1,
693
- 2,
694
- 2,
695
- 2,
696
- 2,
697
- 3,
698
- 3,
699
- 3,
700
- 3,
701
- 4,
702
- 4,
703
- 4,
704
- 4,
705
- 5,
706
- 5,
707
- 5,
708
- 5,
709
- 0,
710
- /* unused */
711
- 0,
712
- 0,
713
- /* impossible */
714
- 0
715
- ]), rt = new P([
716
- 0,
717
- 0,
718
- 0,
719
- 0,
720
- 1,
721
- 1,
722
- 2,
723
- 2,
724
- 3,
725
- 3,
726
- 4,
727
- 4,
728
- 5,
729
- 5,
730
- 6,
731
- 6,
732
- 7,
733
- 7,
734
- 8,
735
- 8,
736
- 9,
737
- 9,
738
- 10,
739
- 10,
740
- 11,
741
- 11,
742
- 12,
743
- 12,
744
- 13,
745
- 13,
746
- /* unused */
747
- 0,
748
- 0
749
- ]), jt = new P([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), zt = function(t, n) {
750
- for (var r = new j(31), i = 0; i < 31; ++i)
751
- r[i] = n += 1 << t[i - 1];
752
- for (var u = new Wt(r[30]), i = 1; i < 30; ++i)
753
- for (var d = r[i]; d < r[i + 1]; ++d)
754
- u[d] = d - r[i] << 5 | i;
755
- return { b: r, r: u };
756
- }, Qt = zt(nt, 2), at = Qt.b, vr = Qt.r;
757
- at[28] = 258, vr[258] = 28;
758
- var mr = zt(rt, 0), Yt = mr.b, ke = new j(32768);
759
- for (var x = 0; x < 32768; ++x) {
760
- var G = (x & 43690) >> 1 | (x & 21845) << 1;
761
- G = (G & 52428) >> 2 | (G & 13107) << 2, G = (G & 61680) >> 4 | (G & 3855) << 4, ke[x] = ((G & 65280) >> 8 | (G & 255) << 8) >> 1;
762
- }
763
- var X = (function(t, n, r) {
764
- for (var i = t.length, u = 0, d = new j(n); u < i; ++u)
765
- t[u] && ++d[t[u] - 1];
766
- var _ = new j(n);
767
- for (u = 1; u < n; ++u)
768
- _[u] = _[u - 1] + d[u - 1] << 1;
769
- var p;
770
- if (r) {
771
- p = new j(1 << n);
772
- var h = 15 - n;
773
- for (u = 0; u < i; ++u)
774
- if (t[u])
775
- for (var A = u << 4 | t[u], m = n - t[u], e = _[t[u] - 1]++ << m, a = e | (1 << m) - 1; e <= a; ++e)
776
- p[ke[e] >> h] = A;
777
- } else
778
- for (p = new j(i), u = 0; u < i; ++u)
779
- t[u] && (p[u] = ke[_[t[u] - 1]++] >> 15 - t[u]);
780
- return p;
781
- }), pe = new P(288);
782
- for (var x = 0; x < 144; ++x)
783
- pe[x] = 8;
784
- for (var x = 144; x < 256; ++x)
785
- pe[x] = 9;
786
- for (var x = 256; x < 280; ++x)
787
- pe[x] = 7;
788
- for (var x = 280; x < 288; ++x)
789
- pe[x] = 8;
790
- var Xt = new P(32);
791
- for (var x = 0; x < 32; ++x)
792
- Xt[x] = 5;
793
- var Zt = /* @__PURE__ */ X(pe, 9, 1), en = /* @__PURE__ */ X(Xt, 5, 1), we = function(t) {
794
- for (var n = t[0], r = 1; r < t.length; ++r)
795
- t[r] > n && (n = t[r]);
796
- return n;
797
- }, F = function(t, n, r) {
798
- var i = n / 8 | 0;
799
- return (t[i] | t[i + 1] << 8) >> (n & 7) & r;
800
- }, be = function(t, n) {
801
- var r = n / 8 | 0;
802
- return (t[r] | t[r + 1] << 8 | t[r + 2] << 16) >> (n & 7);
803
- }, tn = function(t) {
804
- return (t + 7) / 8 | 0;
805
- }, Oe = function(t, n, r) {
806
- return (n == null || n < 0) && (n = 0), (r == null || r > t.length) && (r = t.length), new P(t.subarray(n, r));
807
- }, nn = [
808
- "unexpected EOF",
809
- "invalid block type",
810
- "invalid length/literal",
811
- "invalid distance",
812
- "stream finished",
813
- "no stream handler",
814
- ,
815
- "no callback",
816
- "invalid UTF-8 data",
817
- "extra field too long",
818
- "date not in range 1980-2099",
819
- "filename too long",
820
- "stream finishing",
821
- "invalid zip data"
822
- // determined by unknown compression method
823
- ], O = function(t, n, r) {
824
- var i = new Error(n || nn[t]);
825
- if (i.code = t, Error.captureStackTrace && Error.captureStackTrace(i, O), !r)
826
- throw i;
827
- return i;
828
- }, rn = function(t, n, r, i) {
829
- var u = t.length, d = i ? i.length : 0;
830
- if (!u || n.f && !n.l)
831
- return r || new P(0);
832
- var _ = !r, p = _ || n.i != 2, h = n.i;
833
- _ && (r = new P(u * 3));
834
- var A = function(dt) {
835
- var _t = r.length;
836
- if (dt > _t) {
837
- var pt = new P(Math.max(_t * 2, dt));
838
- pt.set(r), r = pt;
839
- }
840
- }, m = n.f || 0, e = n.p || 0, a = n.b || 0, o = n.l, s = n.d, c = n.m, l = n.n, f = u * 8;
841
- do {
842
- if (!o) {
843
- m = F(t, e, 1);
844
- var v = F(t, e + 1, 3);
845
- if (e += 3, v)
846
- if (v == 1)
847
- o = Zt, s = en, c = 9, l = 5;
848
- else if (v == 2) {
849
- var L = F(t, e, 31) + 257, K = F(t, e + 10, 15) + 4, M = L + F(t, e + 5, 31) + 1;
850
- e += 14;
851
- for (var b = new P(M), U = new P(19), E = 0; E < K; ++E)
852
- U[jt[E]] = F(t, e + E * 3, 7);
853
- e += K * 3;
854
- for (var W = we(U), ve = (1 << W) - 1, R = X(U, W, 1), E = 0; E < M; ) {
855
- var me = R[F(t, e, ve)];
856
- e += me & 15;
857
- var g = me >> 4;
858
- if (g < 16)
859
- b[E++] = g;
860
- else {
861
- var z = 0, he = 0;
862
- for (g == 16 ? (he = 3 + F(t, e, 3), e += 2, z = b[E - 1]) : g == 17 ? (he = 3 + F(t, e, 7), e += 3) : g == 18 && (he = 11 + F(t, e, 127), e += 7); he--; )
863
- b[E++] = z;
864
- }
865
- }
866
- var ut = b.subarray(0, L), V = b.subarray(L);
867
- c = we(ut), l = we(V), o = X(ut, c, 1), s = X(V, l, 1);
868
- } else
869
- O(1);
870
- else {
871
- var g = tn(e) + 4, S = t[g - 4] | t[g - 3] << 8, C = g + S;
872
- if (C > u) {
873
- h && O(0);
874
- break;
875
- }
876
- p && A(a + S), r.set(t.subarray(g, C), a), n.b = a += S, n.p = e = C * 8, n.f = m;
877
- continue;
878
- }
879
- if (e > f) {
880
- h && O(0);
881
- break;
882
- }
883
- }
884
- p && A(a + 131072);
885
- for (var hn = (1 << c) - 1, gn = (1 << l) - 1, $e = e; ; $e = e) {
886
- var z = o[be(t, e) & hn], Q = z >> 4;
887
- if (e += z & 15, e > f) {
888
- h && O(0);
889
- break;
890
- }
891
- if (z || O(2), Q < 256)
892
- r[a++] = Q;
893
- else if (Q == 256) {
894
- $e = e, o = null;
895
- break;
896
- } else {
897
- var ft = Q - 254;
898
- if (Q > 264) {
899
- var E = Q - 257, oe = nt[E];
900
- ft = F(t, e, (1 << oe) - 1) + at[E], e += oe;
901
- }
902
- var Le = s[be(t, e) & gn], Fe = Le >> 4;
903
- Le || O(3), e += Le & 15;
904
- var V = Yt[Fe];
905
- if (Fe > 3) {
906
- var oe = rt[Fe];
907
- V += be(t, e) & (1 << oe) - 1, e += oe;
908
- }
909
- if (e > f) {
910
- h && O(0);
911
- break;
912
- }
913
- p && A(a + 131072);
914
- var ct = a + ft;
915
- if (a < V) {
916
- var lt = d - V, yn = Math.min(V, ct);
917
- for (lt + a < 0 && O(3); a < yn; ++a)
918
- r[a] = i[lt + a];
919
- }
920
- for (; a < ct; ++a)
921
- r[a] = r[a - V];
922
- }
923
- }
924
- n.l = o, n.p = $e, n.b = a, n.f = m, o && (m = 1, n.m = c, n.d = s, n.n = l);
925
- } while (!m);
926
- return a != r.length && _ ? Oe(r, 0, a) : r.subarray(0, a);
927
- }, hr = /* @__PURE__ */ new P(0), gr = function(t, n) {
928
- var r = {};
929
- for (var i in t)
930
- r[i] = t[i];
931
- for (var i in n)
932
- r[i] = n[i];
933
- return r;
934
- }, yt = function(t, n, r) {
935
- for (var i = t(), u = t.toString(), d = u.slice(u.indexOf("[") + 1, u.lastIndexOf("]")).replace(/\s+/g, "").split(","), _ = 0; _ < i.length; ++_) {
936
- var p = i[_], h = d[_];
937
- if (typeof p == "function") {
938
- n += ";" + h + "=";
939
- var A = p.toString();
940
- if (p.prototype)
941
- if (A.indexOf("[native code]") != -1) {
942
- var m = A.indexOf(" ", 8) + 1;
943
- n += A.slice(m, A.indexOf("(", m));
944
- } else {
945
- n += A;
946
- for (var e in p.prototype)
947
- n += ";" + h + ".prototype." + e + "=" + p.prototype[e].toString();
948
- }
949
- else
950
- n += A;
951
- } else
952
- r[h] = p;
953
- }
954
- return n;
955
- }, ge = [], yr = function(t) {
956
- var n = [];
957
- for (var r in t)
958
- t[r].buffer && n.push((t[r] = new t[r].constructor(t[r])).buffer);
959
- return n;
960
- }, wr = function(t, n, r, i) {
961
- if (!ge[r]) {
962
- for (var u = "", d = {}, _ = t.length - 1, p = 0; p < _; ++p)
963
- u = yt(t[p], u, d);
964
- ge[r] = { c: yt(t[_], u, d), e: d };
965
- }
966
- var h = gr({}, ge[r].e);
967
- return pr(ge[r].c + ";onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=" + n.toString() + "}", r, h, yr(h), i);
968
- }, br = function() {
969
- return [P, j, Wt, nt, rt, jt, at, Yt, Zt, en, ke, nn, X, we, F, be, tn, Oe, O, rn, ot, an, on];
970
- }, an = function(t) {
971
- return postMessage(t, [t.buffer]);
972
- }, on = function(t) {
973
- return t && {
974
- out: t.size && new P(t.size),
975
- dictionary: t.dictionary
976
- };
977
- }, Ar = function(t, n, r, i, u, d) {
978
- var _ = wr(r, i, u, function(p, h) {
979
- _.terminate(), d(p, h);
980
- });
981
- return _.postMessage([t, n], n.consume ? [t.buffer] : []), function() {
982
- _.terminate();
983
- };
984
- }, D = function(t, n) {
985
- return t[n] | t[n + 1] << 8;
986
- }, N = function(t, n) {
987
- return (t[n] | t[n + 1] << 8 | t[n + 2] << 16 | t[n + 3] << 24) >>> 0;
988
- }, Be = function(t, n) {
989
- return N(t, n) + N(t, n + 4) * 4294967296;
543
+ function ot(e, t) {
544
+ e.forEach((e) => {
545
+ e in t && e in at && (at[e](t[e]), O("game/handletag", { [e]: t[e] }));
546
+ });
547
+ }
548
+ function st(e) {
549
+ He.push(e);
550
+ }
551
+ function ct() {
552
+ let { state: e } = C(), { metadata: t } = e.get(), n = t.continue_maximally !== !1, r = N.getScene(n);
553
+ if (!r.content || r.content.length === 0) return;
554
+ ze.forEach((e) => e(r)), He.forEach((e) => e(r));
555
+ let { tags: i } = r;
556
+ if (i.RESTART) {
557
+ Qe();
558
+ return;
559
+ }
560
+ if (i.RESTART_FROM_CHECKPOINT) {
561
+ $e(i.RESTART_FROM_CHECKPOINT);
562
+ return;
563
+ }
564
+ ot([
565
+ "CLEAR",
566
+ "STOP_SOUND",
567
+ "STOP_MUSIC",
568
+ "PLAY_SOUND",
569
+ "PLAY_MUSIC",
570
+ "AUDIO",
571
+ "AUDIOLOOP"
572
+ ], i), t.single_scene ? e.setKey("scenes", [r]) : e.appendKey("scenes", r), ot(["CHECKPOINT", "SAVEGAME"], i), t.autosave !== !1 && it(), O("game/continueStory");
573
+ }
574
+ var lt = {
575
+ init: Ke,
576
+ loadInkFile: qe,
577
+ initInkStory: Je,
578
+ start: Ye,
579
+ clear: et,
580
+ reset: tt,
581
+ resume: Ze,
582
+ canResume: Xe,
583
+ restart: Qe,
584
+ restartFromCheckpoint: $e,
585
+ continueStory: ct,
586
+ makeChoice: (e) => N.makeChoice(e),
587
+ getAssetPath: (e) => C().loader.getAssetPath(e),
588
+ defineSceneProcessor: st,
589
+ SAVE_GAME: Te,
590
+ SAVE_AUTOSAVE: Ee,
591
+ SAVE_CHECKPOINT: De,
592
+ getSaveSlotKey: ke,
593
+ saveGame: nt,
594
+ saveCheckpoint: rt,
595
+ saveAutosave: it,
596
+ load: je,
597
+ getState: Me,
598
+ setState: Ae,
599
+ listSaves: Ie,
600
+ removeSave: Fe,
601
+ existSave: Pe,
602
+ getSession: fe,
603
+ setSession: pe,
604
+ getSessions: me,
605
+ removeSession: he
606
+ }, ut = {
607
+ mute: (e, t) => C().sound.mute(t),
608
+ volume: (e, t) => C().sound.setVolume(t)
990
609
  };
991
- function Sr(t, n, r) {
992
- return r || (r = n, n = {}), typeof r != "function" && O(7), Ar(t, n, [
993
- br
994
- ], function(i) {
995
- return an(ot(i.data[0], on(i.data[1])));
996
- }, 1, r);
997
- }
998
- function ot(t, n) {
999
- return rn(t, { i: 2 }, n && n.out, n && n.dictionary);
610
+ async function dt() {
611
+ let { state: e, persistent: t } = C(), n = JSON.parse(JSON.stringify(E().settings)), r = {};
612
+ await t.exists("settings") && (r = await t.get("settings"));
613
+ let i = {
614
+ ...n,
615
+ ...r
616
+ };
617
+ e.setKey("settings", i), _t(), O("settings/load", i);
618
+ }
619
+ async function ft() {
620
+ let { state: e, persistent: t } = C(), n = e.get();
621
+ await t.set("settings", n.settings), O("settings/save", n.settings);
622
+ }
623
+ function pt(e) {
624
+ let t = C().state.get().settings[e];
625
+ return O("settings/get", {
626
+ name: e,
627
+ value: t
628
+ }), t;
629
+ }
630
+ function mt(e, t) {
631
+ let { state: n } = C(), r = n.get().settings[e];
632
+ n.setSubkey("settings", e, t), ut[e] && ut[e](r, t), O("settings/set", {
633
+ name: e,
634
+ value: t
635
+ });
636
+ }
637
+ function ht(e) {
638
+ mt(e, !pt(e));
639
+ }
640
+ function gt(e, t) {
641
+ ut[e] = t;
642
+ }
643
+ function _t() {
644
+ let e = C().state.get().settings;
645
+ Object.entries(e).forEach(([e, t]) => {
646
+ ut[e] && ut[e](null, t);
647
+ });
648
+ }
649
+ function vt() {
650
+ let { state: e } = C(), t = JSON.parse(JSON.stringify(E().settings));
651
+ e.setKey("settings", t), _t(), O("settings/reset", t);
652
+ }
653
+ var yt = {
654
+ load: dt,
655
+ save: ft,
656
+ get: pt,
657
+ set: mt,
658
+ toggle: ht,
659
+ defineHandler: gt,
660
+ runHandlers: _t,
661
+ reset: vt
662
+ }, bt = "2.1.5";
663
+ async function xt(e, t) {
664
+ O("atrament/init");
665
+ let { persistent: n } = C();
666
+ le(e, t), n.init(E().applicationID), await yt.load();
667
+ }
668
+ var St = {
669
+ get interfaces() {
670
+ return C();
671
+ },
672
+ defineInterfaces: w,
673
+ init: xt,
674
+ get state() {
675
+ return C().state;
676
+ },
677
+ get store() {
678
+ return C().state.store();
679
+ },
680
+ on: (e, t) => D.on(e, t),
681
+ off: (e, t) => D.off(e, t),
682
+ emit: O,
683
+ game: lt,
684
+ ink: N,
685
+ settings: yt,
686
+ version: bt
687
+ }, I = Uint8Array, L = Uint16Array, Ct = Int32Array, wt = new I([
688
+ 0,
689
+ 0,
690
+ 0,
691
+ 0,
692
+ 0,
693
+ 0,
694
+ 0,
695
+ 0,
696
+ 1,
697
+ 1,
698
+ 1,
699
+ 1,
700
+ 2,
701
+ 2,
702
+ 2,
703
+ 2,
704
+ 3,
705
+ 3,
706
+ 3,
707
+ 3,
708
+ 4,
709
+ 4,
710
+ 4,
711
+ 4,
712
+ 5,
713
+ 5,
714
+ 5,
715
+ 5,
716
+ 0,
717
+ 0,
718
+ 0,
719
+ 0
720
+ ]), Tt = new I([
721
+ 0,
722
+ 0,
723
+ 0,
724
+ 0,
725
+ 1,
726
+ 1,
727
+ 2,
728
+ 2,
729
+ 3,
730
+ 3,
731
+ 4,
732
+ 4,
733
+ 5,
734
+ 5,
735
+ 6,
736
+ 6,
737
+ 7,
738
+ 7,
739
+ 8,
740
+ 8,
741
+ 9,
742
+ 9,
743
+ 10,
744
+ 10,
745
+ 11,
746
+ 11,
747
+ 12,
748
+ 12,
749
+ 13,
750
+ 13,
751
+ 0,
752
+ 0
753
+ ]), Et = new I([
754
+ 16,
755
+ 17,
756
+ 18,
757
+ 0,
758
+ 8,
759
+ 7,
760
+ 9,
761
+ 6,
762
+ 10,
763
+ 5,
764
+ 11,
765
+ 4,
766
+ 12,
767
+ 3,
768
+ 13,
769
+ 2,
770
+ 14,
771
+ 1,
772
+ 15
773
+ ]), Dt = function(e, t) {
774
+ for (var n = new L(31), r = 0; r < 31; ++r) n[r] = t += 1 << e[r - 1];
775
+ for (var i = new Ct(n[30]), r = 1; r < 30; ++r) for (var a = n[r]; a < n[r + 1]; ++a) i[a] = a - n[r] << 5 | r;
776
+ return {
777
+ b: n,
778
+ r: i
779
+ };
780
+ }, Ot = Dt(wt, 2), kt = Ot.b, At = Ot.r;
781
+ kt[28] = 258, At[258] = 28;
782
+ var jt = Dt(Tt, 0), Mt = jt.b;
783
+ jt.r;
784
+ for (var Nt = new L(32768), R = 0; R < 32768; ++R) {
785
+ var z = (R & 43690) >> 1 | (R & 21845) << 1;
786
+ z = (z & 52428) >> 2 | (z & 13107) << 2, z = (z & 61680) >> 4 | (z & 3855) << 4, Nt[R] = ((z & 65280) >> 8 | (z & 255) << 8) >> 1;
787
+ }
788
+ for (var B = (function(e, t, n) {
789
+ for (var r = e.length, i = 0, a = new L(t); i < r; ++i) e[i] && ++a[e[i] - 1];
790
+ var o = new L(t);
791
+ for (i = 1; i < t; ++i) o[i] = o[i - 1] + a[i - 1] << 1;
792
+ var s;
793
+ if (n) {
794
+ s = new L(1 << t);
795
+ var c = 15 - t;
796
+ for (i = 0; i < r; ++i) if (e[i]) for (var l = i << 4 | e[i], u = t - e[i], d = o[e[i] - 1]++ << u, f = d | (1 << u) - 1; d <= f; ++d) s[Nt[d] >> c] = l;
797
+ } else for (s = new L(r), i = 0; i < r; ++i) e[i] && (s[i] = Nt[o[e[i] - 1]++] >> 15 - e[i]);
798
+ return s;
799
+ }), V = new I(288), R = 0; R < 144; ++R) V[R] = 8;
800
+ for (var R = 144; R < 256; ++R) V[R] = 9;
801
+ for (var R = 256; R < 280; ++R) V[R] = 7;
802
+ for (var R = 280; R < 288; ++R) V[R] = 8;
803
+ for (var Pt = new I(32), R = 0; R < 32; ++R) Pt[R] = 5;
804
+ var Ft = /* @__PURE__ */ B(V, 9, 1), It = /* @__PURE__ */ B(Pt, 5, 1), Lt = function(e) {
805
+ for (var t = e[0], n = 1; n < e.length; ++n) e[n] > t && (t = e[n]);
806
+ return t;
807
+ }, H = function(e, t, n) {
808
+ var r = t / 8 | 0;
809
+ return (e[r] | e[r + 1] << 8) >> (t & 7) & n;
810
+ }, Rt = function(e, t) {
811
+ var n = t / 8 | 0;
812
+ return (e[n] | e[n + 1] << 8 | e[n + 2] << 16) >> (t & 7);
813
+ }, zt = function(e) {
814
+ return (e + 7) / 8 | 0;
815
+ }, Bt = function(e, t, n) {
816
+ return (t == null || t < 0) && (t = 0), (n == null || n > e.length) && (n = e.length), new I(e.subarray(t, n));
817
+ }, Vt = [
818
+ "unexpected EOF",
819
+ "invalid block type",
820
+ "invalid length/literal",
821
+ "invalid distance",
822
+ "stream finished",
823
+ "no stream handler",
824
+ ,
825
+ "no callback",
826
+ "invalid UTF-8 data",
827
+ "extra field too long",
828
+ "date not in range 1980-2099",
829
+ "filename too long",
830
+ "stream finishing",
831
+ "invalid zip data"
832
+ ], U = function(e, t, n) {
833
+ var r = Error(t || Vt[e]);
834
+ if (r.code = e, Error.captureStackTrace && Error.captureStackTrace(r, U), !n) throw r;
835
+ return r;
836
+ }, Ht = function(e, t, n, r) {
837
+ var i = e.length, a = r ? r.length : 0;
838
+ if (!i || t.f && !t.l) return n || new I(0);
839
+ var o = !n, s = o || t.i != 2, c = t.i;
840
+ o && (n = new I(i * 3));
841
+ var l = function(e) {
842
+ var t = n.length;
843
+ if (e > t) {
844
+ var r = new I(Math.max(t * 2, e));
845
+ r.set(n), n = r;
846
+ }
847
+ }, u = t.f || 0, d = t.p || 0, f = t.b || 0, p = t.l, m = t.d, h = t.m, g = t.n, _ = i * 8;
848
+ do {
849
+ if (!p) {
850
+ u = H(e, d, 1);
851
+ var ee = H(e, d + 1, 3);
852
+ if (d += 3, !ee) {
853
+ var v = zt(d) + 4, te = e[v - 4] | e[v - 3] << 8, y = v + te;
854
+ if (y > i) {
855
+ c && U(0);
856
+ break;
857
+ }
858
+ s && l(f + te), n.set(e.subarray(v, y), f), t.b = f += te, t.p = d = y * 8, t.f = u;
859
+ continue;
860
+ } else if (ee == 1) p = Ft, m = It, h = 9, g = 5;
861
+ else if (ee == 2) {
862
+ var ne = H(e, d, 31) + 257, re = H(e, d + 10, 15) + 4, ie = ne + H(e, d + 5, 31) + 1;
863
+ d += 14;
864
+ for (var b = new I(ie), ae = new I(19), x = 0; x < re; ++x) ae[Et[x]] = H(e, d + x * 3, 7);
865
+ d += re * 3;
866
+ for (var oe = Lt(ae), se = (1 << oe) - 1, ce = B(ae, oe, 1), x = 0; x < ie;) {
867
+ var S = ce[H(e, d, se)];
868
+ d += S & 15;
869
+ var v = S >> 4;
870
+ if (v < 16) b[x++] = v;
871
+ else {
872
+ var C = 0, w = 0;
873
+ for (v == 16 ? (w = 3 + H(e, d, 3), d += 2, C = b[x - 1]) : v == 17 ? (w = 3 + H(e, d, 7), d += 3) : v == 18 && (w = 11 + H(e, d, 127), d += 7); w--;) b[x++] = C;
874
+ }
875
+ }
876
+ var T = b.subarray(0, ne), E = b.subarray(ne);
877
+ h = Lt(T), g = Lt(E), p = B(T, h, 1), m = B(E, g, 1);
878
+ } else U(1);
879
+ if (d > _) {
880
+ c && U(0);
881
+ break;
882
+ }
883
+ }
884
+ s && l(f + 131072);
885
+ for (var le = (1 << h) - 1, ue = (1 << g) - 1, D = d;; D = d) {
886
+ var C = p[Rt(e, d) & le], O = C >> 4;
887
+ if (d += C & 15, d > _) {
888
+ c && U(0);
889
+ break;
890
+ }
891
+ if (C || U(2), O < 256) n[f++] = O;
892
+ else if (O == 256) {
893
+ D = d, p = null;
894
+ break;
895
+ } else {
896
+ var k = O - 254;
897
+ if (O > 264) {
898
+ var x = O - 257, A = wt[x];
899
+ k = H(e, d, (1 << A) - 1) + kt[x], d += A;
900
+ }
901
+ var de = m[Rt(e, d) & ue], j = de >> 4;
902
+ de || U(3), d += de & 15;
903
+ var E = Mt[j];
904
+ if (j > 3) {
905
+ var A = Tt[j];
906
+ E += Rt(e, d) & (1 << A) - 1, d += A;
907
+ }
908
+ if (d > _) {
909
+ c && U(0);
910
+ break;
911
+ }
912
+ s && l(f + 131072);
913
+ var fe = f + k;
914
+ if (f < E) {
915
+ var pe = a - E, me = Math.min(E, fe);
916
+ for (pe + f < 0 && U(3); f < me; ++f) n[f] = r[pe + f];
917
+ }
918
+ for (; f < fe; ++f) n[f] = n[f - E];
919
+ }
920
+ }
921
+ t.l = p, t.p = D, t.b = f, t.f = u, p && (u = 1, t.m = h, t.d = m, t.n = g);
922
+ } while (!u);
923
+ return f != n.length && o ? Bt(n, 0, f) : n.subarray(0, f);
924
+ }, Ut = /* @__PURE__ */ new I(0), W = function(e, t) {
925
+ return e[t] | e[t + 1] << 8;
926
+ }, G = function(e, t) {
927
+ return (e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24) >>> 0;
928
+ }, Wt = function(e, t) {
929
+ return G(e, t) + G(e, t + 4) * 4294967296;
930
+ };
931
+ function Gt(e, t) {
932
+ return Ht(e, { i: 2 }, t && t.out, t && t.dictionary);
1000
933
  }
1001
- var Je = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), xr = 0;
934
+ var Kt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder();
1002
935
  try {
1003
- Je.decode(hr, { stream: !0 }), xr = 1;
1004
- } catch {
1005
- }
1006
- var kr = function(t) {
1007
- for (var n = "", r = 0; ; ) {
1008
- var i = t[r++], u = (i > 127) + (i > 223) + (i > 239);
1009
- if (r + u > t.length)
1010
- return { s: n, r: Oe(t, r - 1) };
1011
- u ? u == 3 ? (i = ((i & 15) << 18 | (t[r++] & 63) << 12 | (t[r++] & 63) << 6 | t[r++] & 63) - 65536, n += String.fromCharCode(55296 | i >> 10, 56320 | i & 1023)) : u & 1 ? n += String.fromCharCode((i & 31) << 6 | t[r++] & 63) : n += String.fromCharCode((i & 15) << 12 | (t[r++] & 63) << 6 | t[r++] & 63) : n += String.fromCharCode(i);
1012
- }
936
+ Kt.decode(Ut, { stream: !0 });
937
+ } catch {}
938
+ var qt = function(e) {
939
+ for (var t = "", n = 0;;) {
940
+ var r = e[n++], i = (r > 127) + (r > 223) + (r > 239);
941
+ if (n + i > e.length) return {
942
+ s: t,
943
+ r: Bt(e, n - 1)
944
+ };
945
+ i ? i == 3 ? (r = ((r & 15) << 18 | (e[n++] & 63) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) - 65536, t += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : i & 1 ? t += String.fromCharCode((r & 31) << 6 | e[n++] & 63) : t += String.fromCharCode((r & 15) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) : t += String.fromCharCode(r);
946
+ }
1013
947
  };
1014
- function Tr(t, n) {
1015
- if (n) {
1016
- for (var r = "", i = 0; i < t.length; i += 16384)
1017
- r += String.fromCharCode.apply(null, t.subarray(i, i + 16384));
1018
- return r;
1019
- } else {
1020
- if (Je)
1021
- return Je.decode(t);
1022
- var u = kr(t), d = u.s, r = u.r;
1023
- return r.length && O(8), d;
1024
- }
1025
- }
1026
- var Er = function(t, n) {
1027
- return n + 30 + D(t, n + 26) + D(t, n + 28);
1028
- }, Ir = function(t, n, r) {
1029
- var i = D(t, n + 28), u = Tr(t.subarray(n + 46, n + 46 + i), !(D(t, n + 8) & 2048)), d = n + 46 + i, _ = N(t, n + 20), p = r && _ == 4294967295 ? Cr(t, d) : [_, N(t, n + 24), N(t, n + 42)], h = p[0], A = p[1], m = p[2];
1030
- return [D(t, n + 10), h, A, u, d + D(t, n + 30) + D(t, n + 32), m];
1031
- }, Cr = function(t, n) {
1032
- for (; D(t, n) != 1; n += 4 + D(t, n + 2))
1033
- ;
1034
- return [Be(t, n + 12), Be(t, n + 4), Be(t, n + 20)];
1035
- }, wt = typeof queueMicrotask == "function" ? queueMicrotask : typeof setTimeout == "function" ? setTimeout : function(t) {
1036
- t();
948
+ function Jt(e, t) {
949
+ if (t) {
950
+ for (var n = "", r = 0; r < e.length; r += 16384) n += String.fromCharCode.apply(null, e.subarray(r, r + 16384));
951
+ return n;
952
+ } else if (Kt) return Kt.decode(e);
953
+ else {
954
+ var i = qt(e), a = i.s, n = i.r;
955
+ return n.length && U(8), a;
956
+ }
957
+ }
958
+ var Yt = function(e, t) {
959
+ return t + 30 + W(e, t + 26) + W(e, t + 28);
960
+ }, Xt = function(e, t, n) {
961
+ var r = W(e, t + 28), i = Jt(e.subarray(t + 46, t + 46 + r), !(W(e, t + 8) & 2048)), a = t + 46 + r, o = G(e, t + 20), s = n && o == 4294967295 ? Zt(e, a) : [
962
+ o,
963
+ G(e, t + 24),
964
+ G(e, t + 42)
965
+ ], c = s[0], l = s[1], u = s[2];
966
+ return [
967
+ W(e, t + 10),
968
+ c,
969
+ l,
970
+ i,
971
+ a + W(e, t + 30) + W(e, t + 32),
972
+ u
973
+ ];
974
+ }, Zt = function(e, t) {
975
+ for (; W(e, t) != 1; t += 4 + W(e, t + 2));
976
+ return [
977
+ Wt(e, t + 12),
978
+ Wt(e, t + 4),
979
+ Wt(e, t + 20)
980
+ ];
1037
981
  };
1038
- function Or(t, n, r) {
1039
- r || (r = n, n = {}), typeof r != "function" && O(7);
1040
- var i = [], u = function() {
1041
- for (var l = 0; l < i.length; ++l)
1042
- i[l]();
1043
- }, d = {}, _ = function(l, f) {
1044
- wt(function() {
1045
- r(l, f);
1046
- });
1047
- };
1048
- wt(function() {
1049
- _ = r;
1050
- });
1051
- for (var p = t.length - 22; N(t, p) != 101010256; --p)
1052
- if (!p || t.length - p > 65558)
1053
- return _(O(13, 0, 1), null), u;
1054
- var h = D(t, p + 8);
1055
- if (h) {
1056
- var A = h, m = N(t, p + 16), e = m == 4294967295 || A == 65535;
1057
- if (e) {
1058
- var a = N(t, p - 12);
1059
- e = N(t, a) == 101075792, e && (A = h = N(t, a + 32), m = N(t, a + 48));
1060
- }
1061
- for (var o = n && n.filter, s = function(l) {
1062
- var f = Ir(t, m, e), v = f[0], g = f[1], S = f[2], C = f[3], L = f[4], K = f[5], M = Er(t, K);
1063
- m = L;
1064
- var b = function(E, W) {
1065
- E ? (u(), _(E, null)) : (W && (d[C] = W), --h || _(null, d));
1066
- };
1067
- if (!o || o({
1068
- name: C,
1069
- size: g,
1070
- originalSize: S,
1071
- compression: v
1072
- }))
1073
- if (!v)
1074
- b(null, Oe(t, M, M + g));
1075
- else if (v == 8) {
1076
- var U = t.subarray(M, M + g);
1077
- if (S < 524288 || g > 0.8 * S)
1078
- try {
1079
- b(null, ot(U, { out: new P(S) }));
1080
- } catch (E) {
1081
- b(E, null);
1082
- }
1083
- else
1084
- i.push(Sr(U, { size: S }, b));
1085
- } else
1086
- b(O(14, "unknown compression type " + v, 1), null);
1087
- else
1088
- b(null, null);
1089
- }, c = 0; c < A; ++c)
1090
- s(c);
1091
- } else
1092
- _(null, {});
1093
- return u;
1094
- }
1095
- let sn = () => {
982
+ function Qt(e, t) {
983
+ for (var n = {}, r = e.length - 22; G(e, r) != 101010256; --r) (!r || e.length - r > 65558) && U(13);
984
+ var i = W(e, r + 8);
985
+ if (!i) return {};
986
+ var a = G(e, r + 16), o = a == 4294967295 || i == 65535;
987
+ if (o) {
988
+ var s = G(e, r - 12);
989
+ o = G(e, s) == 101075792, o && (i = G(e, s + 32), a = G(e, s + 48));
990
+ }
991
+ for (var c = t && t.filter, l = 0; l < i; ++l) {
992
+ var u = Xt(e, a, o), d = u[0], f = u[1], p = u[2], m = u[3], h = u[4], g = u[5], _ = Yt(e, g);
993
+ a = h, (!c || c({
994
+ name: m,
995
+ size: f,
996
+ originalSize: p,
997
+ compression: d
998
+ })) && (d ? d == 8 ? n[m] = Gt(e.subarray(_, _ + f), { out: new I(p) }) : U(14, "unknown compression type " + d) : n[m] = Bt(e, _, _ + f));
999
+ }
1000
+ return n;
1001
+ }
1002
+ //#endregion
1003
+ //#region src/interfaces/loader-common.js
1004
+ var $t = () => {};
1005
+ async function en(e) {
1006
+ let t = await rn(e);
1007
+ return new TextDecoder("utf-8").decode(t);
1008
+ }
1009
+ async function tn(e) {
1010
+ return new Promise((t, n) => {
1011
+ let r = document.createElement("script");
1012
+ r.src = e, r.addEventListener("load", t), r.addEventListener("error", n), document.body.append(r);
1013
+ });
1014
+ }
1015
+ async function nn(e) {
1016
+ let t = "";
1017
+ try {
1018
+ await tn(e);
1019
+ } catch (t) {
1020
+ throw console.error(t), Error(`Failed to fetch file: ${e}`);
1021
+ }
1022
+ try {
1023
+ t = JSON.stringify(window.storyContent);
1024
+ } catch (t) {
1025
+ throw console.error(t), Error(`Failed to parse Ink script: ${e}`);
1026
+ }
1027
+ return t;
1028
+ }
1029
+ async function rn(e) {
1030
+ let t = await fetch(e, { responseType: "arraybuffer" });
1031
+ if (!t.ok) {
1032
+ let n = await t.text();
1033
+ throw Error(`Failed to fetch file: ${e}. Error ${t.status} ${n}`);
1034
+ }
1035
+ let n = t.body.getReader(), r = +t.headers.get("Content-Length"), i = [], a = 0;
1036
+ for (;;) {
1037
+ let { done: e, value: t } = await n.read();
1038
+ if (e) break;
1039
+ i.push(t), a += t.length;
1040
+ let o = Math.round(a * 100 / r);
1041
+ $t({
1042
+ percent: o,
1043
+ receivedLength: a,
1044
+ contentLength: r
1045
+ });
1046
+ }
1047
+ let o = new Uint8Array(a), s = 0;
1048
+ return i.forEach((e) => {
1049
+ o.set(e, s), s += e.length;
1050
+ }), o;
1051
+ }
1052
+ function an(e) {
1053
+ $t = e;
1054
+ }
1055
+ //#endregion
1056
+ //#region src/interfaces/loader-web-fflate.js
1057
+ var on = "plain", sn = "", cn = {};
1058
+ async function ln(e) {
1059
+ if (e.endsWith(".zip") && (on = "zip"), on === "zip") {
1060
+ cn = {};
1061
+ let t = Qt(await rn(e));
1062
+ Object.entries(t).forEach(([e, t]) => {
1063
+ cn[e] = URL.createObjectURL(new Blob([t]));
1064
+ });
1065
+ } else sn = e;
1066
+ }
1067
+ function un(e) {
1068
+ if (!e) return null;
1069
+ let t = `${e}`;
1070
+ return t.startsWith("http://") || t.startsWith("https://") ? t : on === "zip" ? cn[t] : `${sn}/${t}`;
1071
+ }
1072
+ async function dn(e) {
1073
+ let t = un(e);
1074
+ return await (t.endsWith("js") ? nn(t) : en(t));
1075
+ }
1076
+ var fn = {
1077
+ init: ln,
1078
+ getAssetPath: un,
1079
+ loadInk: dn,
1080
+ onProgress: an
1096
1081
  };
1097
- async function Pr(t) {
1098
- const n = await un(t);
1099
- return new TextDecoder("utf-8").decode(n);
1100
- }
1101
- async function $r(t) {
1102
- return new Promise((n, r) => {
1103
- const i = document.createElement("script");
1104
- i.src = t, i.addEventListener("load", n), i.addEventListener("error", r), document.body.append(i);
1105
- });
1106
- }
1107
- async function Lr(t) {
1108
- let n = "";
1109
- try {
1110
- await $r(t);
1111
- } catch (r) {
1112
- throw console.error(r), Error(`Failed to fetch file: ${t}`);
1113
- }
1114
- try {
1115
- n = JSON.stringify(window.storyContent);
1116
- } catch (r) {
1117
- throw console.error(r), Error(`Failed to parse Ink script: ${t}`);
1118
- }
1119
- return n;
1120
- }
1121
- async function un(t) {
1122
- const n = await fetch(t, { responseType: "arraybuffer" });
1123
- if (!n.ok) {
1124
- const h = await n.text();
1125
- throw new Error(`Failed to fetch file: ${t}. Error ${n.status} ${h}`);
1126
- }
1127
- const r = n.body.getReader(), i = +n.headers.get("Content-Length"), u = [];
1128
- let d = 0;
1129
- for (; ; ) {
1130
- const { done: h, value: A } = await r.read();
1131
- if (h)
1132
- break;
1133
- u.push(A), d += A.length;
1134
- const m = Math.round(d * 100 / i);
1135
- sn({ percent: m, receivedLength: d, contentLength: i });
1136
- }
1137
- const _ = new Uint8Array(d);
1138
- let p = 0;
1139
- return u.forEach((h) => {
1140
- _.set(h, p), p += h.length;
1141
- }), _;
1142
- }
1143
- function Fr(t) {
1144
- sn = t;
1145
- }
1146
- let qe = "plain", fn = "", We = {};
1147
- async function Mr(t) {
1148
- if (t.endsWith(".zip") && (qe = "zip"), qe === "zip") {
1149
- We = {};
1150
- const n = await un(t);
1151
- await Or(
1152
- n,
1153
- (r, i) => Object.entries(i).forEach(([u, d]) => {
1154
- We[u] = URL.createObjectURL(new Blob([d]));
1155
- })
1156
- );
1157
- } else
1158
- fn = t;
1159
- }
1160
- function cn(t) {
1161
- if (!t)
1162
- return null;
1163
- const n = `${t}`;
1164
- return n.startsWith("http://") || n.startsWith("https://") ? n : qe === "zip" ? We[n] : `${fn}/${n}`;
1165
- }
1166
- async function Br(t) {
1167
- const n = cn(t);
1168
- return await (n.endsWith("js") ? Lr(n) : Pr(n));
1169
- }
1170
- const Nr = {
1171
- init: Mr,
1172
- getAssetPath: cn,
1173
- loadInk: Br,
1174
- onProgress: Fr
1175
- };
1176
- function ne(t) {
1177
- return new Promise((n, r) => {
1178
- t.oncomplete = t.onsuccess = () => n(t.result), t.onabort = t.onerror = () => r(t.error);
1179
- });
1180
- }
1181
- function ln(t, n) {
1182
- let r;
1183
- const i = () => {
1184
- if (r)
1185
- return r;
1186
- const u = indexedDB.open(t);
1187
- return u.onupgradeneeded = () => u.result.createObjectStore(n), r = ne(u), r.then((d) => {
1188
- d.onclose = () => r = void 0;
1189
- }, () => {
1190
- }), r;
1191
- };
1192
- return (u, d) => i().then((_) => d(_.transaction(n, u).objectStore(n)));
1193
- }
1194
- let Ne;
1195
- function Pe() {
1196
- return Ne || (Ne = ln("keyval-store", "keyval")), Ne;
1197
- }
1198
- function dn(t, n = Pe()) {
1199
- return n("readonly", (r) => ne(r.get(t)));
1200
- }
1201
- function Dr(t, n, r = Pe()) {
1202
- return r("readwrite", (i) => (i.put(n, t), ne(i.transaction)));
1203
- }
1204
- function Kr(t, n = Pe()) {
1205
- return n("readwrite", (r) => (r.delete(t), ne(r.transaction)));
1206
- }
1207
- function Ur(t, n) {
1208
- return t.openCursor().onsuccess = function() {
1209
- this.result && (n(this.result), this.result.continue());
1210
- }, ne(t.transaction);
1211
- }
1212
- function Rr(t = Pe()) {
1213
- return t("readonly", (n) => {
1214
- if (n.getAllKeys)
1215
- return ne(n.getAllKeys());
1216
- const r = [];
1217
- return Ur(n, (i) => r.push(i.key)).then(() => r);
1218
- });
1219
- }
1220
- let re;
1221
- function Vr(t) {
1222
- re = ln(t, "keyvaluepairs");
1223
- }
1224
- async function Gr(t) {
1225
- return await dn(t, re) !== void 0;
1226
- }
1227
- async function Hr(t) {
1228
- return await dn(t, re);
1229
- }
1230
- async function Jr(t, n) {
1231
- await Dr(t, n, re);
1232
- }
1233
- async function qr(t) {
1234
- await Kr(t, re);
1235
- }
1236
- async function Wr() {
1237
- return await Rr(re);
1238
- }
1239
- const jr = {
1240
- init: Vr,
1241
- exists: Gr,
1242
- get: Hr,
1243
- set: Jr,
1244
- remove: qr,
1245
- keys: Wr
1246
- };
1247
- var se = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
1248
- function zr(t) {
1249
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
1250
- }
1251
- var ue = { exports: {} }, De = { exports: {} }, bt;
1252
- function Qr() {
1253
- return bt || (bt = 1, (function(t) {
1254
- function n(r, i) {
1255
- var u, d, _, p, h, A, m, e;
1256
- for (u = r.length & 3, d = r.length - u, _ = i, h = 3432918353, A = 461845907, e = 0; e < d; )
1257
- m = r.charCodeAt(e) & 255 | (r.charCodeAt(++e) & 255) << 8 | (r.charCodeAt(++e) & 255) << 16 | (r.charCodeAt(++e) & 255) << 24, ++e, m = (m & 65535) * h + (((m >>> 16) * h & 65535) << 16) & 4294967295, m = m << 15 | m >>> 17, m = (m & 65535) * A + (((m >>> 16) * A & 65535) << 16) & 4294967295, _ ^= m, _ = _ << 13 | _ >>> 19, p = (_ & 65535) * 5 + (((_ >>> 16) * 5 & 65535) << 16) & 4294967295, _ = (p & 65535) + 27492 + (((p >>> 16) + 58964 & 65535) << 16);
1258
- switch (m = 0, u) {
1259
- case 3:
1260
- m ^= (r.charCodeAt(e + 2) & 255) << 16;
1261
- case 2:
1262
- m ^= (r.charCodeAt(e + 1) & 255) << 8;
1263
- case 1:
1264
- m ^= r.charCodeAt(e) & 255, m = (m & 65535) * h + (((m >>> 16) * h & 65535) << 16) & 4294967295, m = m << 15 | m >>> 17, m = (m & 65535) * A + (((m >>> 16) * A & 65535) << 16) & 4294967295, _ ^= m;
1265
- }
1266
- return _ ^= r.length, _ ^= _ >>> 16, _ = (_ & 65535) * 2246822507 + (((_ >>> 16) * 2246822507 & 65535) << 16) & 4294967295, _ ^= _ >>> 13, _ = (_ & 65535) * 3266489909 + (((_ >>> 16) * 3266489909 & 65535) << 16) & 4294967295, _ ^= _ >>> 16, _ >>> 0;
1267
- }
1268
- t.exports = n;
1269
- })(De)), De.exports;
1270
- }
1271
- var Ke = { exports: {} }, At;
1272
- function Yr() {
1273
- return At || (At = 1, (function(t) {
1274
- function n(r, i) {
1275
- for (var u = r.length, d = i ^ u, _ = 0, p; u >= 4; )
1276
- p = r.charCodeAt(_) & 255 | (r.charCodeAt(++_) & 255) << 8 | (r.charCodeAt(++_) & 255) << 16 | (r.charCodeAt(++_) & 255) << 24, p = (p & 65535) * 1540483477 + (((p >>> 16) * 1540483477 & 65535) << 16), p ^= p >>> 24, p = (p & 65535) * 1540483477 + (((p >>> 16) * 1540483477 & 65535) << 16), d = (d & 65535) * 1540483477 + (((d >>> 16) * 1540483477 & 65535) << 16) ^ p, u -= 4, ++_;
1277
- switch (u) {
1278
- case 3:
1279
- d ^= (r.charCodeAt(_ + 2) & 255) << 16;
1280
- case 2:
1281
- d ^= (r.charCodeAt(_ + 1) & 255) << 8;
1282
- case 1:
1283
- d ^= r.charCodeAt(_) & 255, d = (d & 65535) * 1540483477 + (((d >>> 16) * 1540483477 & 65535) << 16);
1284
- }
1285
- return d ^= d >>> 13, d = (d & 65535) * 1540483477 + (((d >>> 16) * 1540483477 & 65535) << 16), d ^= d >>> 15, d >>> 0;
1286
- }
1287
- t.exports = n;
1288
- })(Ke)), Ke.exports;
1289
- }
1290
- var St;
1291
- function Xr() {
1292
- if (St) return ue.exports;
1293
- St = 1;
1294
- var t = Qr(), n = Yr();
1295
- return ue.exports = t, ue.exports.murmur3 = t, ue.exports.murmur2 = n, ue.exports;
1296
- }
1297
- var Zr = Xr();
1298
- const ea = /* @__PURE__ */ zr(Zr), te = "__atrament_storage";
1299
- let Z = Promise.resolve();
1300
- async function de(t) {
1301
- try {
1302
- const n = await window.Neutralino.storage.getData(t);
1303
- return JSON.parse(n);
1304
- } catch (n) {
1305
- return console.warn(n.message), null;
1306
- }
1307
- }
1308
- async function it(t, n) {
1309
- const r = JSON.stringify(n);
1310
- return await window.Neutralino.storage.setData(t, r), r;
1311
- }
1312
- async function ta(t) {
1313
- return await window.Neutralino.storage.setData(t, null), !0;
1314
- }
1315
- function st(t) {
1316
- return `storage_${ea(t)}`;
1317
- }
1318
- async function na(t, n) {
1319
- return Z = Z.then(async () => {
1320
- let r = await de(te);
1321
- r === null && (r = {}), r[n] = t, await it(te, r);
1322
- }).catch((r) => console.error(r.message)), Z;
1323
- }
1324
- async function ra(t) {
1325
- return Z = Z.then(async () => {
1326
- let n = await de(te);
1327
- n === null && (n = {}), delete n[t], await it(te, n);
1328
- }).catch((n) => console.error(n.message)), Z;
1329
- }
1330
- function aa() {
1331
- }
1332
- async function oa(t) {
1333
- return (await _n()).includes(t);
1334
- }
1335
- async function ia(t) {
1336
- const n = await de(te), r = n === null ? st(t) : n[t];
1337
- return await de(r);
1338
- }
1339
- async function sa(t, n) {
1340
- const r = st(t);
1341
- try {
1342
- await it(r, n), await na(r, t);
1343
- } catch (i) {
1344
- console.error(i.message);
1345
- }
1346
- }
1347
- async function ua(t) {
1348
- const n = st(t);
1349
- try {
1350
- await ta(n), await ra(t);
1351
- } catch (r) {
1352
- console.error(r.message);
1353
- }
1354
- }
1355
- async function _n() {
1356
- const t = await de(te);
1357
- return t === null ? [] : Object.keys(t);
1358
- }
1359
- const fa = {
1360
- init: aa,
1361
- exists: oa,
1362
- get: ia,
1363
- set: sa,
1364
- remove: ua,
1365
- keys: _n
1366
- };
1367
- var Ue = {};
1368
- var xt;
1369
- function ca() {
1370
- return xt || (xt = 1, (function(t) {
1371
- (function() {
1372
- var n = function() {
1373
- this.init();
1374
- };
1375
- n.prototype = {
1376
- /**
1377
- * Initialize the global Howler object.
1378
- * @return {Howler}
1379
- */
1380
- init: function() {
1381
- var e = this || r;
1382
- return e._counter = 1e3, e._html5AudioPool = [], e.html5PoolSize = 10, e._codecs = {}, e._howls = [], e._muted = !1, e._volume = 1, e._canPlayEvent = "canplaythrough", e._navigator = typeof window < "u" && window.navigator ? window.navigator : null, e.masterGain = null, e.noAudio = !1, e.usingWebAudio = !0, e.autoSuspend = !0, e.ctx = null, e.autoUnlock = !0, e._setup(), e;
1383
- },
1384
- /**
1385
- * Get/set the global volume for all sounds.
1386
- * @param {Float} vol Volume from 0.0 to 1.0.
1387
- * @return {Howler/Float} Returns self or current volume.
1388
- */
1389
- volume: function(e) {
1390
- var a = this || r;
1391
- if (e = parseFloat(e), a.ctx || m(), typeof e < "u" && e >= 0 && e <= 1) {
1392
- if (a._volume = e, a._muted)
1393
- return a;
1394
- a.usingWebAudio && a.masterGain.gain.setValueAtTime(e, r.ctx.currentTime);
1395
- for (var o = 0; o < a._howls.length; o++)
1396
- if (!a._howls[o]._webAudio)
1397
- for (var s = a._howls[o]._getSoundIds(), c = 0; c < s.length; c++) {
1398
- var l = a._howls[o]._soundById(s[c]);
1399
- l && l._node && (l._node.volume = l._volume * e);
1400
- }
1401
- return a;
1402
- }
1403
- return a._volume;
1404
- },
1405
- /**
1406
- * Handle muting and unmuting globally.
1407
- * @param {Boolean} muted Is muted or not.
1408
- */
1409
- mute: function(e) {
1410
- var a = this || r;
1411
- a.ctx || m(), a._muted = e, a.usingWebAudio && a.masterGain.gain.setValueAtTime(e ? 0 : a._volume, r.ctx.currentTime);
1412
- for (var o = 0; o < a._howls.length; o++)
1413
- if (!a._howls[o]._webAudio)
1414
- for (var s = a._howls[o]._getSoundIds(), c = 0; c < s.length; c++) {
1415
- var l = a._howls[o]._soundById(s[c]);
1416
- l && l._node && (l._node.muted = e ? !0 : l._muted);
1417
- }
1418
- return a;
1419
- },
1420
- /**
1421
- * Handle stopping all sounds globally.
1422
- */
1423
- stop: function() {
1424
- for (var e = this || r, a = 0; a < e._howls.length; a++)
1425
- e._howls[a].stop();
1426
- return e;
1427
- },
1428
- /**
1429
- * Unload and destroy all currently loaded Howl objects.
1430
- * @return {Howler}
1431
- */
1432
- unload: function() {
1433
- for (var e = this || r, a = e._howls.length - 1; a >= 0; a--)
1434
- e._howls[a].unload();
1435
- return e.usingWebAudio && e.ctx && typeof e.ctx.close < "u" && (e.ctx.close(), e.ctx = null, m()), e;
1436
- },
1437
- /**
1438
- * Check for codec support of specific extension.
1439
- * @param {String} ext Audio file extention.
1440
- * @return {Boolean}
1441
- */
1442
- codecs: function(e) {
1443
- return (this || r)._codecs[e.replace(/^x-/, "")];
1444
- },
1445
- /**
1446
- * Setup various state values for global tracking.
1447
- * @return {Howler}
1448
- */
1449
- _setup: function() {
1450
- var e = this || r;
1451
- if (e.state = e.ctx && e.ctx.state || "suspended", e._autoSuspend(), !e.usingWebAudio)
1452
- if (typeof Audio < "u")
1453
- try {
1454
- var a = new Audio();
1455
- typeof a.oncanplaythrough > "u" && (e._canPlayEvent = "canplay");
1456
- } catch {
1457
- e.noAudio = !0;
1458
- }
1459
- else
1460
- e.noAudio = !0;
1461
- try {
1462
- var a = new Audio();
1463
- a.muted && (e.noAudio = !0);
1464
- } catch {
1465
- }
1466
- return e.noAudio || e._setupCodecs(), e;
1467
- },
1468
- /**
1469
- * Check for browser support for various codecs and cache the results.
1470
- * @return {Howler}
1471
- */
1472
- _setupCodecs: function() {
1473
- var e = this || r, a = null;
1474
- try {
1475
- a = typeof Audio < "u" ? new Audio() : null;
1476
- } catch {
1477
- return e;
1478
- }
1479
- if (!a || typeof a.canPlayType != "function")
1480
- return e;
1481
- var o = a.canPlayType("audio/mpeg;").replace(/^no$/, ""), s = e._navigator ? e._navigator.userAgent : "", c = s.match(/OPR\/(\d+)/g), l = c && parseInt(c[0].split("/")[1], 10) < 33, f = s.indexOf("Safari") !== -1 && s.indexOf("Chrome") === -1, v = s.match(/Version\/(.*?) /), g = f && v && parseInt(v[1], 10) < 15;
1482
- return e._codecs = {
1483
- mp3: !!(!l && (o || a.canPlayType("audio/mp3;").replace(/^no$/, ""))),
1484
- mpeg: !!o,
1485
- opus: !!a.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ""),
1486
- ogg: !!a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""),
1487
- oga: !!a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ""),
1488
- wav: !!(a.canPlayType('audio/wav; codecs="1"') || a.canPlayType("audio/wav")).replace(/^no$/, ""),
1489
- aac: !!a.canPlayType("audio/aac;").replace(/^no$/, ""),
1490
- caf: !!a.canPlayType("audio/x-caf;").replace(/^no$/, ""),
1491
- m4a: !!(a.canPlayType("audio/x-m4a;") || a.canPlayType("audio/m4a;") || a.canPlayType("audio/aac;")).replace(/^no$/, ""),
1492
- m4b: !!(a.canPlayType("audio/x-m4b;") || a.canPlayType("audio/m4b;") || a.canPlayType("audio/aac;")).replace(/^no$/, ""),
1493
- mp4: !!(a.canPlayType("audio/x-mp4;") || a.canPlayType("audio/mp4;") || a.canPlayType("audio/aac;")).replace(/^no$/, ""),
1494
- weba: !!(!g && a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, "")),
1495
- webm: !!(!g && a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, "")),
1496
- dolby: !!a.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/, ""),
1497
- flac: !!(a.canPlayType("audio/x-flac;") || a.canPlayType("audio/flac;")).replace(/^no$/, "")
1498
- }, e;
1499
- },
1500
- /**
1501
- * Some browsers/devices will only allow audio to be played after a user interaction.
1502
- * Attempt to automatically unlock audio on the first user interaction.
1503
- * Concept from: http://paulbakaus.com/tutorials/html5/web-audio-on-ios/
1504
- * @return {Howler}
1505
- */
1506
- _unlockAudio: function() {
1507
- var e = this || r;
1508
- if (!(e._audioUnlocked || !e.ctx)) {
1509
- e._audioUnlocked = !1, e.autoUnlock = !1, !e._mobileUnloaded && e.ctx.sampleRate !== 44100 && (e._mobileUnloaded = !0, e.unload()), e._scratchBuffer = e.ctx.createBuffer(1, 1, 22050);
1510
- var a = function(o) {
1511
- for (; e._html5AudioPool.length < e.html5PoolSize; )
1512
- try {
1513
- var s = new Audio();
1514
- s._unlocked = !0, e._releaseHtml5Audio(s);
1515
- } catch {
1516
- e.noAudio = !0;
1517
- break;
1518
- }
1519
- for (var c = 0; c < e._howls.length; c++)
1520
- if (!e._howls[c]._webAudio)
1521
- for (var l = e._howls[c]._getSoundIds(), f = 0; f < l.length; f++) {
1522
- var v = e._howls[c]._soundById(l[f]);
1523
- v && v._node && !v._node._unlocked && (v._node._unlocked = !0, v._node.load());
1524
- }
1525
- e._autoResume();
1526
- var g = e.ctx.createBufferSource();
1527
- g.buffer = e._scratchBuffer, g.connect(e.ctx.destination), typeof g.start > "u" ? g.noteOn(0) : g.start(0), typeof e.ctx.resume == "function" && e.ctx.resume(), g.onended = function() {
1528
- g.disconnect(0), e._audioUnlocked = !0, document.removeEventListener("touchstart", a, !0), document.removeEventListener("touchend", a, !0), document.removeEventListener("click", a, !0), document.removeEventListener("keydown", a, !0);
1529
- for (var S = 0; S < e._howls.length; S++)
1530
- e._howls[S]._emit("unlock");
1531
- };
1532
- };
1533
- return document.addEventListener("touchstart", a, !0), document.addEventListener("touchend", a, !0), document.addEventListener("click", a, !0), document.addEventListener("keydown", a, !0), e;
1534
- }
1535
- },
1536
- /**
1537
- * Get an unlocked HTML5 Audio object from the pool. If none are left,
1538
- * return a new Audio object and throw a warning.
1539
- * @return {Audio} HTML5 Audio object.
1540
- */
1541
- _obtainHtml5Audio: function() {
1542
- var e = this || r;
1543
- if (e._html5AudioPool.length)
1544
- return e._html5AudioPool.pop();
1545
- var a = new Audio().play();
1546
- return a && typeof Promise < "u" && (a instanceof Promise || typeof a.then == "function") && a.catch(function() {
1547
- console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.");
1548
- }), new Audio();
1549
- },
1550
- /**
1551
- * Return an activated HTML5 Audio object to the pool.
1552
- * @return {Howler}
1553
- */
1554
- _releaseHtml5Audio: function(e) {
1555
- var a = this || r;
1556
- return e._unlocked && a._html5AudioPool.push(e), a;
1557
- },
1558
- /**
1559
- * Automatically suspend the Web Audio AudioContext after no sound has played for 30 seconds.
1560
- * This saves processing/energy and fixes various browser-specific bugs with audio getting stuck.
1561
- * @return {Howler}
1562
- */
1563
- _autoSuspend: function() {
1564
- var e = this;
1565
- if (!(!e.autoSuspend || !e.ctx || typeof e.ctx.suspend > "u" || !r.usingWebAudio)) {
1566
- for (var a = 0; a < e._howls.length; a++)
1567
- if (e._howls[a]._webAudio) {
1568
- for (var o = 0; o < e._howls[a]._sounds.length; o++)
1569
- if (!e._howls[a]._sounds[o]._paused)
1570
- return e;
1571
- }
1572
- return e._suspendTimer && clearTimeout(e._suspendTimer), e._suspendTimer = setTimeout(function() {
1573
- if (e.autoSuspend) {
1574
- e._suspendTimer = null, e.state = "suspending";
1575
- var s = function() {
1576
- e.state = "suspended", e._resumeAfterSuspend && (delete e._resumeAfterSuspend, e._autoResume());
1577
- };
1578
- e.ctx.suspend().then(s, s);
1579
- }
1580
- }, 3e4), e;
1581
- }
1582
- },
1583
- /**
1584
- * Automatically resume the Web Audio AudioContext when a new sound is played.
1585
- * @return {Howler}
1586
- */
1587
- _autoResume: function() {
1588
- var e = this;
1589
- if (!(!e.ctx || typeof e.ctx.resume > "u" || !r.usingWebAudio))
1590
- return e.state === "running" && e.ctx.state !== "interrupted" && e._suspendTimer ? (clearTimeout(e._suspendTimer), e._suspendTimer = null) : e.state === "suspended" || e.state === "running" && e.ctx.state === "interrupted" ? (e.ctx.resume().then(function() {
1591
- e.state = "running";
1592
- for (var a = 0; a < e._howls.length; a++)
1593
- e._howls[a]._emit("resume");
1594
- }), e._suspendTimer && (clearTimeout(e._suspendTimer), e._suspendTimer = null)) : e.state === "suspending" && (e._resumeAfterSuspend = !0), e;
1595
- }
1596
- };
1597
- var r = new n(), i = function(e) {
1598
- var a = this;
1599
- if (!e.src || e.src.length === 0) {
1600
- console.error("An array of source files must be passed with any new Howl.");
1601
- return;
1602
- }
1603
- a.init(e);
1604
- };
1605
- i.prototype = {
1606
- /**
1607
- * Initialize a new Howl group object.
1608
- * @param {Object} o Passed in properties for this group.
1609
- * @return {Howl}
1610
- */
1611
- init: function(e) {
1612
- var a = this;
1613
- return r.ctx || m(), a._autoplay = e.autoplay || !1, a._format = typeof e.format != "string" ? e.format : [e.format], a._html5 = e.html5 || !1, a._muted = e.mute || !1, a._loop = e.loop || !1, a._pool = e.pool || 5, a._preload = typeof e.preload == "boolean" || e.preload === "metadata" ? e.preload : !0, a._rate = e.rate || 1, a._sprite = e.sprite || {}, a._src = typeof e.src != "string" ? e.src : [e.src], a._volume = e.volume !== void 0 ? e.volume : 1, a._xhr = {
1614
- method: e.xhr && e.xhr.method ? e.xhr.method : "GET",
1615
- headers: e.xhr && e.xhr.headers ? e.xhr.headers : null,
1616
- withCredentials: e.xhr && e.xhr.withCredentials ? e.xhr.withCredentials : !1
1617
- }, a._duration = 0, a._state = "unloaded", a._sounds = [], a._endTimers = {}, a._queue = [], a._playLock = !1, a._onend = e.onend ? [{ fn: e.onend }] : [], a._onfade = e.onfade ? [{ fn: e.onfade }] : [], a._onload = e.onload ? [{ fn: e.onload }] : [], a._onloaderror = e.onloaderror ? [{ fn: e.onloaderror }] : [], a._onplayerror = e.onplayerror ? [{ fn: e.onplayerror }] : [], a._onpause = e.onpause ? [{ fn: e.onpause }] : [], a._onplay = e.onplay ? [{ fn: e.onplay }] : [], a._onstop = e.onstop ? [{ fn: e.onstop }] : [], a._onmute = e.onmute ? [{ fn: e.onmute }] : [], a._onvolume = e.onvolume ? [{ fn: e.onvolume }] : [], a._onrate = e.onrate ? [{ fn: e.onrate }] : [], a._onseek = e.onseek ? [{ fn: e.onseek }] : [], a._onunlock = e.onunlock ? [{ fn: e.onunlock }] : [], a._onresume = [], a._webAudio = r.usingWebAudio && !a._html5, typeof r.ctx < "u" && r.ctx && r.autoUnlock && r._unlockAudio(), r._howls.push(a), a._autoplay && a._queue.push({
1618
- event: "play",
1619
- action: function() {
1620
- a.play();
1621
- }
1622
- }), a._preload && a._preload !== "none" && a.load(), a;
1623
- },
1624
- /**
1625
- * Load the audio file.
1626
- * @return {Howler}
1627
- */
1628
- load: function() {
1629
- var e = this, a = null;
1630
- if (r.noAudio) {
1631
- e._emit("loaderror", null, "No audio support.");
1632
- return;
1633
- }
1634
- typeof e._src == "string" && (e._src = [e._src]);
1635
- for (var o = 0; o < e._src.length; o++) {
1636
- var s, c;
1637
- if (e._format && e._format[o])
1638
- s = e._format[o];
1639
- else {
1640
- if (c = e._src[o], typeof c != "string") {
1641
- e._emit("loaderror", null, "Non-string found in selected audio sources - ignoring.");
1642
- continue;
1643
- }
1644
- s = /^data:audio\/([^;,]+);/i.exec(c), s || (s = /\.([^.]+)$/.exec(c.split("?", 1)[0])), s && (s = s[1].toLowerCase());
1645
- }
1646
- if (s || console.warn('No file extension was found. Consider using the "format" property or specify an extension.'), s && r.codecs(s)) {
1647
- a = e._src[o];
1648
- break;
1649
- }
1650
- }
1651
- if (!a) {
1652
- e._emit("loaderror", null, "No codec support for selected audio sources.");
1653
- return;
1654
- }
1655
- return e._src = a, e._state = "loading", window.location.protocol === "https:" && a.slice(0, 5) === "http:" && (e._html5 = !0, e._webAudio = !1), new u(e), e._webAudio && _(e), e;
1656
- },
1657
- /**
1658
- * Play a sound or resume previous playback.
1659
- * @param {String/Number} sprite Sprite name for sprite playback or sound id to continue previous.
1660
- * @param {Boolean} internal Internal Use: true prevents event firing.
1661
- * @return {Number} Sound ID.
1662
- */
1663
- play: function(e, a) {
1664
- var o = this, s = null;
1665
- if (typeof e == "number")
1666
- s = e, e = null;
1667
- else {
1668
- if (typeof e == "string" && o._state === "loaded" && !o._sprite[e])
1669
- return null;
1670
- if (typeof e > "u" && (e = "__default", !o._playLock)) {
1671
- for (var c = 0, l = 0; l < o._sounds.length; l++)
1672
- o._sounds[l]._paused && !o._sounds[l]._ended && (c++, s = o._sounds[l]._id);
1673
- c === 1 ? e = null : s = null;
1674
- }
1675
- }
1676
- var f = s ? o._soundById(s) : o._inactiveSound();
1677
- if (!f)
1678
- return null;
1679
- if (s && !e && (e = f._sprite || "__default"), o._state !== "loaded") {
1680
- f._sprite = e, f._ended = !1;
1681
- var v = f._id;
1682
- return o._queue.push({
1683
- event: "play",
1684
- action: function() {
1685
- o.play(v);
1686
- }
1687
- }), v;
1688
- }
1689
- if (s && !f._paused)
1690
- return a || o._loadQueue("play"), f._id;
1691
- o._webAudio && r._autoResume();
1692
- var g = Math.max(0, f._seek > 0 ? f._seek : o._sprite[e][0] / 1e3), S = Math.max(0, (o._sprite[e][0] + o._sprite[e][1]) / 1e3 - g), C = S * 1e3 / Math.abs(f._rate), L = o._sprite[e][0] / 1e3, K = (o._sprite[e][0] + o._sprite[e][1]) / 1e3;
1693
- f._sprite = e, f._ended = !1;
1694
- var M = function() {
1695
- f._paused = !1, f._seek = g, f._start = L, f._stop = K, f._loop = !!(f._loop || o._sprite[e][2]);
1696
- };
1697
- if (g >= K) {
1698
- o._ended(f);
1699
- return;
1700
- }
1701
- var b = f._node;
1702
- if (o._webAudio) {
1703
- var U = function() {
1704
- o._playLock = !1, M(), o._refreshBuffer(f);
1705
- var R = f._muted || o._muted ? 0 : f._volume;
1706
- b.gain.setValueAtTime(R, r.ctx.currentTime), f._playStart = r.ctx.currentTime, typeof b.bufferSource.start > "u" ? f._loop ? b.bufferSource.noteGrainOn(0, g, 86400) : b.bufferSource.noteGrainOn(0, g, S) : f._loop ? b.bufferSource.start(0, g, 86400) : b.bufferSource.start(0, g, S), C !== 1 / 0 && (o._endTimers[f._id] = setTimeout(o._ended.bind(o, f), C)), a || setTimeout(function() {
1707
- o._emit("play", f._id), o._loadQueue();
1708
- }, 0);
1709
- };
1710
- r.state === "running" && r.ctx.state !== "interrupted" ? U() : (o._playLock = !0, o.once("resume", U), o._clearTimer(f._id));
1711
- } else {
1712
- var E = function() {
1713
- b.currentTime = g, b.muted = f._muted || o._muted || r._muted || b.muted, b.volume = f._volume * r.volume(), b.playbackRate = f._rate;
1714
- try {
1715
- var R = b.play();
1716
- if (R && typeof Promise < "u" && (R instanceof Promise || typeof R.then == "function") ? (o._playLock = !0, M(), R.then(function() {
1717
- o._playLock = !1, b._unlocked = !0, a ? o._loadQueue() : o._emit("play", f._id);
1718
- }).catch(function() {
1719
- o._playLock = !1, o._emit("playerror", f._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."), f._ended = !0, f._paused = !0;
1720
- })) : a || (o._playLock = !1, M(), o._emit("play", f._id)), b.playbackRate = f._rate, b.paused) {
1721
- o._emit("playerror", f._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");
1722
- return;
1723
- }
1724
- e !== "__default" || f._loop ? o._endTimers[f._id] = setTimeout(o._ended.bind(o, f), C) : (o._endTimers[f._id] = function() {
1725
- o._ended(f), b.removeEventListener("ended", o._endTimers[f._id], !1);
1726
- }, b.addEventListener("ended", o._endTimers[f._id], !1));
1727
- } catch (me) {
1728
- o._emit("playerror", f._id, me);
1729
- }
1730
- };
1731
- b.src === "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA" && (b.src = o._src, b.load());
1732
- var W = window && window.ejecta || !b.readyState && r._navigator.isCocoonJS;
1733
- if (b.readyState >= 3 || W)
1734
- E();
1735
- else {
1736
- o._playLock = !0, o._state = "loading";
1737
- var ve = function() {
1738
- o._state = "loaded", E(), b.removeEventListener(r._canPlayEvent, ve, !1);
1739
- };
1740
- b.addEventListener(r._canPlayEvent, ve, !1), o._clearTimer(f._id);
1741
- }
1742
- }
1743
- return f._id;
1744
- },
1745
- /**
1746
- * Pause playback and save current position.
1747
- * @param {Number} id The sound ID (empty to pause all in group).
1748
- * @return {Howl}
1749
- */
1750
- pause: function(e) {
1751
- var a = this;
1752
- if (a._state !== "loaded" || a._playLock)
1753
- return a._queue.push({
1754
- event: "pause",
1755
- action: function() {
1756
- a.pause(e);
1757
- }
1758
- }), a;
1759
- for (var o = a._getSoundIds(e), s = 0; s < o.length; s++) {
1760
- a._clearTimer(o[s]);
1761
- var c = a._soundById(o[s]);
1762
- if (c && !c._paused && (c._seek = a.seek(o[s]), c._rateSeek = 0, c._paused = !0, a._stopFade(o[s]), c._node))
1763
- if (a._webAudio) {
1764
- if (!c._node.bufferSource)
1765
- continue;
1766
- typeof c._node.bufferSource.stop > "u" ? c._node.bufferSource.noteOff(0) : c._node.bufferSource.stop(0), a._cleanBuffer(c._node);
1767
- } else (!isNaN(c._node.duration) || c._node.duration === 1 / 0) && c._node.pause();
1768
- arguments[1] || a._emit("pause", c ? c._id : null);
1769
- }
1770
- return a;
1771
- },
1772
- /**
1773
- * Stop playback and reset to start.
1774
- * @param {Number} id The sound ID (empty to stop all in group).
1775
- * @param {Boolean} internal Internal Use: true prevents event firing.
1776
- * @return {Howl}
1777
- */
1778
- stop: function(e, a) {
1779
- var o = this;
1780
- if (o._state !== "loaded" || o._playLock)
1781
- return o._queue.push({
1782
- event: "stop",
1783
- action: function() {
1784
- o.stop(e);
1785
- }
1786
- }), o;
1787
- for (var s = o._getSoundIds(e), c = 0; c < s.length; c++) {
1788
- o._clearTimer(s[c]);
1789
- var l = o._soundById(s[c]);
1790
- l && (l._seek = l._start || 0, l._rateSeek = 0, l._paused = !0, l._ended = !0, o._stopFade(s[c]), l._node && (o._webAudio ? l._node.bufferSource && (typeof l._node.bufferSource.stop > "u" ? l._node.bufferSource.noteOff(0) : l._node.bufferSource.stop(0), o._cleanBuffer(l._node)) : (!isNaN(l._node.duration) || l._node.duration === 1 / 0) && (l._node.currentTime = l._start || 0, l._node.pause(), l._node.duration === 1 / 0 && o._clearSound(l._node))), a || o._emit("stop", l._id));
1791
- }
1792
- return o;
1793
- },
1794
- /**
1795
- * Mute/unmute a single sound or all sounds in this Howl group.
1796
- * @param {Boolean} muted Set to true to mute and false to unmute.
1797
- * @param {Number} id The sound ID to update (omit to mute/unmute all).
1798
- * @return {Howl}
1799
- */
1800
- mute: function(e, a) {
1801
- var o = this;
1802
- if (o._state !== "loaded" || o._playLock)
1803
- return o._queue.push({
1804
- event: "mute",
1805
- action: function() {
1806
- o.mute(e, a);
1807
- }
1808
- }), o;
1809
- if (typeof a > "u")
1810
- if (typeof e == "boolean")
1811
- o._muted = e;
1812
- else
1813
- return o._muted;
1814
- for (var s = o._getSoundIds(a), c = 0; c < s.length; c++) {
1815
- var l = o._soundById(s[c]);
1816
- l && (l._muted = e, l._interval && o._stopFade(l._id), o._webAudio && l._node ? l._node.gain.setValueAtTime(e ? 0 : l._volume, r.ctx.currentTime) : l._node && (l._node.muted = r._muted ? !0 : e), o._emit("mute", l._id));
1817
- }
1818
- return o;
1819
- },
1820
- /**
1821
- * Get/set the volume of this sound or of the Howl group. This method can optionally take 0, 1 or 2 arguments.
1822
- * volume() -> Returns the group's volume value.
1823
- * volume(id) -> Returns the sound id's current volume.
1824
- * volume(vol) -> Sets the volume of all sounds in this Howl group.
1825
- * volume(vol, id) -> Sets the volume of passed sound id.
1826
- * @return {Howl/Number} Returns self or current volume.
1827
- */
1828
- volume: function() {
1829
- var e = this, a = arguments, o, s;
1830
- if (a.length === 0)
1831
- return e._volume;
1832
- if (a.length === 1 || a.length === 2 && typeof a[1] > "u") {
1833
- var c = e._getSoundIds(), l = c.indexOf(a[0]);
1834
- l >= 0 ? s = parseInt(a[0], 10) : o = parseFloat(a[0]);
1835
- } else a.length >= 2 && (o = parseFloat(a[0]), s = parseInt(a[1], 10));
1836
- var f;
1837
- if (typeof o < "u" && o >= 0 && o <= 1) {
1838
- if (e._state !== "loaded" || e._playLock)
1839
- return e._queue.push({
1840
- event: "volume",
1841
- action: function() {
1842
- e.volume.apply(e, a);
1843
- }
1844
- }), e;
1845
- typeof s > "u" && (e._volume = o), s = e._getSoundIds(s);
1846
- for (var v = 0; v < s.length; v++)
1847
- f = e._soundById(s[v]), f && (f._volume = o, a[2] || e._stopFade(s[v]), e._webAudio && f._node && !f._muted ? f._node.gain.setValueAtTime(o, r.ctx.currentTime) : f._node && !f._muted && (f._node.volume = o * r.volume()), e._emit("volume", f._id));
1848
- } else
1849
- return f = s ? e._soundById(s) : e._sounds[0], f ? f._volume : 0;
1850
- return e;
1851
- },
1852
- /**
1853
- * Fade a currently playing sound between two volumes (if no id is passed, all sounds will fade).
1854
- * @param {Number} from The value to fade from (0.0 to 1.0).
1855
- * @param {Number} to The volume to fade to (0.0 to 1.0).
1856
- * @param {Number} len Time in milliseconds to fade.
1857
- * @param {Number} id The sound id (omit to fade all sounds).
1858
- * @return {Howl}
1859
- */
1860
- fade: function(e, a, o, s) {
1861
- var c = this;
1862
- if (c._state !== "loaded" || c._playLock)
1863
- return c._queue.push({
1864
- event: "fade",
1865
- action: function() {
1866
- c.fade(e, a, o, s);
1867
- }
1868
- }), c;
1869
- e = Math.min(Math.max(0, parseFloat(e)), 1), a = Math.min(Math.max(0, parseFloat(a)), 1), o = parseFloat(o), c.volume(e, s);
1870
- for (var l = c._getSoundIds(s), f = 0; f < l.length; f++) {
1871
- var v = c._soundById(l[f]);
1872
- if (v) {
1873
- if (s || c._stopFade(l[f]), c._webAudio && !v._muted) {
1874
- var g = r.ctx.currentTime, S = g + o / 1e3;
1875
- v._volume = e, v._node.gain.setValueAtTime(e, g), v._node.gain.linearRampToValueAtTime(a, S);
1876
- }
1877
- c._startFadeInterval(v, e, a, o, l[f], typeof s > "u");
1878
- }
1879
- }
1880
- return c;
1881
- },
1882
- /**
1883
- * Starts the internal interval to fade a sound.
1884
- * @param {Object} sound Reference to sound to fade.
1885
- * @param {Number} from The value to fade from (0.0 to 1.0).
1886
- * @param {Number} to The volume to fade to (0.0 to 1.0).
1887
- * @param {Number} len Time in milliseconds to fade.
1888
- * @param {Number} id The sound id to fade.
1889
- * @param {Boolean} isGroup If true, set the volume on the group.
1890
- */
1891
- _startFadeInterval: function(e, a, o, s, c, l) {
1892
- var f = this, v = a, g = o - a, S = Math.abs(g / 0.01), C = Math.max(4, S > 0 ? s / S : s), L = Date.now();
1893
- e._fadeTo = o, e._interval = setInterval(function() {
1894
- var K = (Date.now() - L) / s;
1895
- L = Date.now(), v += g * K, v = Math.round(v * 100) / 100, g < 0 ? v = Math.max(o, v) : v = Math.min(o, v), f._webAudio ? e._volume = v : f.volume(v, e._id, !0), l && (f._volume = v), (o < a && v <= o || o > a && v >= o) && (clearInterval(e._interval), e._interval = null, e._fadeTo = null, f.volume(o, e._id), f._emit("fade", e._id));
1896
- }, C);
1897
- },
1898
- /**
1899
- * Internal method that stops the currently playing fade when
1900
- * a new fade starts, volume is changed or the sound is stopped.
1901
- * @param {Number} id The sound id.
1902
- * @return {Howl}
1903
- */
1904
- _stopFade: function(e) {
1905
- var a = this, o = a._soundById(e);
1906
- return o && o._interval && (a._webAudio && o._node.gain.cancelScheduledValues(r.ctx.currentTime), clearInterval(o._interval), o._interval = null, a.volume(o._fadeTo, e), o._fadeTo = null, a._emit("fade", e)), a;
1907
- },
1908
- /**
1909
- * Get/set the loop parameter on a sound. This method can optionally take 0, 1 or 2 arguments.
1910
- * loop() -> Returns the group's loop value.
1911
- * loop(id) -> Returns the sound id's loop value.
1912
- * loop(loop) -> Sets the loop value for all sounds in this Howl group.
1913
- * loop(loop, id) -> Sets the loop value of passed sound id.
1914
- * @return {Howl/Boolean} Returns self or current loop value.
1915
- */
1916
- loop: function() {
1917
- var e = this, a = arguments, o, s, c;
1918
- if (a.length === 0)
1919
- return e._loop;
1920
- if (a.length === 1)
1921
- if (typeof a[0] == "boolean")
1922
- o = a[0], e._loop = o;
1923
- else
1924
- return c = e._soundById(parseInt(a[0], 10)), c ? c._loop : !1;
1925
- else a.length === 2 && (o = a[0], s = parseInt(a[1], 10));
1926
- for (var l = e._getSoundIds(s), f = 0; f < l.length; f++)
1927
- c = e._soundById(l[f]), c && (c._loop = o, e._webAudio && c._node && c._node.bufferSource && (c._node.bufferSource.loop = o, o && (c._node.bufferSource.loopStart = c._start || 0, c._node.bufferSource.loopEnd = c._stop, e.playing(l[f]) && (e.pause(l[f], !0), e.play(l[f], !0)))));
1928
- return e;
1929
- },
1930
- /**
1931
- * Get/set the playback rate of a sound. This method can optionally take 0, 1 or 2 arguments.
1932
- * rate() -> Returns the first sound node's current playback rate.
1933
- * rate(id) -> Returns the sound id's current playback rate.
1934
- * rate(rate) -> Sets the playback rate of all sounds in this Howl group.
1935
- * rate(rate, id) -> Sets the playback rate of passed sound id.
1936
- * @return {Howl/Number} Returns self or the current playback rate.
1937
- */
1938
- rate: function() {
1939
- var e = this, a = arguments, o, s;
1940
- if (a.length === 0)
1941
- s = e._sounds[0]._id;
1942
- else if (a.length === 1) {
1943
- var c = e._getSoundIds(), l = c.indexOf(a[0]);
1944
- l >= 0 ? s = parseInt(a[0], 10) : o = parseFloat(a[0]);
1945
- } else a.length === 2 && (o = parseFloat(a[0]), s = parseInt(a[1], 10));
1946
- var f;
1947
- if (typeof o == "number") {
1948
- if (e._state !== "loaded" || e._playLock)
1949
- return e._queue.push({
1950
- event: "rate",
1951
- action: function() {
1952
- e.rate.apply(e, a);
1953
- }
1954
- }), e;
1955
- typeof s > "u" && (e._rate = o), s = e._getSoundIds(s);
1956
- for (var v = 0; v < s.length; v++)
1957
- if (f = e._soundById(s[v]), f) {
1958
- e.playing(s[v]) && (f._rateSeek = e.seek(s[v]), f._playStart = e._webAudio ? r.ctx.currentTime : f._playStart), f._rate = o, e._webAudio && f._node && f._node.bufferSource ? f._node.bufferSource.playbackRate.setValueAtTime(o, r.ctx.currentTime) : f._node && (f._node.playbackRate = o);
1959
- var g = e.seek(s[v]), S = (e._sprite[f._sprite][0] + e._sprite[f._sprite][1]) / 1e3 - g, C = S * 1e3 / Math.abs(f._rate);
1960
- (e._endTimers[s[v]] || !f._paused) && (e._clearTimer(s[v]), e._endTimers[s[v]] = setTimeout(e._ended.bind(e, f), C)), e._emit("rate", f._id);
1961
- }
1962
- } else
1963
- return f = e._soundById(s), f ? f._rate : e._rate;
1964
- return e;
1965
- },
1966
- /**
1967
- * Get/set the seek position of a sound. This method can optionally take 0, 1 or 2 arguments.
1968
- * seek() -> Returns the first sound node's current seek position.
1969
- * seek(id) -> Returns the sound id's current seek position.
1970
- * seek(seek) -> Sets the seek position of the first sound node.
1971
- * seek(seek, id) -> Sets the seek position of passed sound id.
1972
- * @return {Howl/Number} Returns self or the current seek position.
1973
- */
1974
- seek: function() {
1975
- var e = this, a = arguments, o, s;
1976
- if (a.length === 0)
1977
- e._sounds.length && (s = e._sounds[0]._id);
1978
- else if (a.length === 1) {
1979
- var c = e._getSoundIds(), l = c.indexOf(a[0]);
1980
- l >= 0 ? s = parseInt(a[0], 10) : e._sounds.length && (s = e._sounds[0]._id, o = parseFloat(a[0]));
1981
- } else a.length === 2 && (o = parseFloat(a[0]), s = parseInt(a[1], 10));
1982
- if (typeof s > "u")
1983
- return 0;
1984
- if (typeof o == "number" && (e._state !== "loaded" || e._playLock))
1985
- return e._queue.push({
1986
- event: "seek",
1987
- action: function() {
1988
- e.seek.apply(e, a);
1989
- }
1990
- }), e;
1991
- var f = e._soundById(s);
1992
- if (f)
1993
- if (typeof o == "number" && o >= 0) {
1994
- var v = e.playing(s);
1995
- v && e.pause(s, !0), f._seek = o, f._ended = !1, e._clearTimer(s), !e._webAudio && f._node && !isNaN(f._node.duration) && (f._node.currentTime = o);
1996
- var g = function() {
1997
- v && e.play(s, !0), e._emit("seek", s);
1998
- };
1999
- if (v && !e._webAudio) {
2000
- var S = function() {
2001
- e._playLock ? setTimeout(S, 0) : g();
2002
- };
2003
- setTimeout(S, 0);
2004
- } else
2005
- g();
2006
- } else if (e._webAudio) {
2007
- var C = e.playing(s) ? r.ctx.currentTime - f._playStart : 0, L = f._rateSeek ? f._rateSeek - f._seek : 0;
2008
- return f._seek + (L + C * Math.abs(f._rate));
2009
- } else
2010
- return f._node.currentTime;
2011
- return e;
2012
- },
2013
- /**
2014
- * Check if a specific sound is currently playing or not (if id is provided), or check if at least one of the sounds in the group is playing or not.
2015
- * @param {Number} id The sound id to check. If none is passed, the whole sound group is checked.
2016
- * @return {Boolean} True if playing and false if not.
2017
- */
2018
- playing: function(e) {
2019
- var a = this;
2020
- if (typeof e == "number") {
2021
- var o = a._soundById(e);
2022
- return o ? !o._paused : !1;
2023
- }
2024
- for (var s = 0; s < a._sounds.length; s++)
2025
- if (!a._sounds[s]._paused)
2026
- return !0;
2027
- return !1;
2028
- },
2029
- /**
2030
- * Get the duration of this sound. Passing a sound id will return the sprite duration.
2031
- * @param {Number} id The sound id to check. If none is passed, return full source duration.
2032
- * @return {Number} Audio duration in seconds.
2033
- */
2034
- duration: function(e) {
2035
- var a = this, o = a._duration, s = a._soundById(e);
2036
- return s && (o = a._sprite[s._sprite][1] / 1e3), o;
2037
- },
2038
- /**
2039
- * Returns the current loaded state of this Howl.
2040
- * @return {String} 'unloaded', 'loading', 'loaded'
2041
- */
2042
- state: function() {
2043
- return this._state;
2044
- },
2045
- /**
2046
- * Unload and destroy the current Howl object.
2047
- * This will immediately stop all sound instances attached to this group.
2048
- */
2049
- unload: function() {
2050
- for (var e = this, a = e._sounds, o = 0; o < a.length; o++)
2051
- a[o]._paused || e.stop(a[o]._id), e._webAudio || (e._clearSound(a[o]._node), a[o]._node.removeEventListener("error", a[o]._errorFn, !1), a[o]._node.removeEventListener(r._canPlayEvent, a[o]._loadFn, !1), a[o]._node.removeEventListener("ended", a[o]._endFn, !1), r._releaseHtml5Audio(a[o]._node)), delete a[o]._node, e._clearTimer(a[o]._id);
2052
- var s = r._howls.indexOf(e);
2053
- s >= 0 && r._howls.splice(s, 1);
2054
- var c = !0;
2055
- for (o = 0; o < r._howls.length; o++)
2056
- if (r._howls[o]._src === e._src || e._src.indexOf(r._howls[o]._src) >= 0) {
2057
- c = !1;
2058
- break;
2059
- }
2060
- return d && c && delete d[e._src], r.noAudio = !1, e._state = "unloaded", e._sounds = [], e = null, null;
2061
- },
2062
- /**
2063
- * Listen to a custom event.
2064
- * @param {String} event Event name.
2065
- * @param {Function} fn Listener to call.
2066
- * @param {Number} id (optional) Only listen to events for this sound.
2067
- * @param {Number} once (INTERNAL) Marks event to fire only once.
2068
- * @return {Howl}
2069
- */
2070
- on: function(e, a, o, s) {
2071
- var c = this, l = c["_on" + e];
2072
- return typeof a == "function" && l.push(s ? { id: o, fn: a, once: s } : { id: o, fn: a }), c;
2073
- },
2074
- /**
2075
- * Remove a custom event. Call without parameters to remove all events.
2076
- * @param {String} event Event name.
2077
- * @param {Function} fn Listener to remove. Leave empty to remove all.
2078
- * @param {Number} id (optional) Only remove events for this sound.
2079
- * @return {Howl}
2080
- */
2081
- off: function(e, a, o) {
2082
- var s = this, c = s["_on" + e], l = 0;
2083
- if (typeof a == "number" && (o = a, a = null), a || o)
2084
- for (l = 0; l < c.length; l++) {
2085
- var f = o === c[l].id;
2086
- if (a === c[l].fn && f || !a && f) {
2087
- c.splice(l, 1);
2088
- break;
2089
- }
2090
- }
2091
- else if (e)
2092
- s["_on" + e] = [];
2093
- else {
2094
- var v = Object.keys(s);
2095
- for (l = 0; l < v.length; l++)
2096
- v[l].indexOf("_on") === 0 && Array.isArray(s[v[l]]) && (s[v[l]] = []);
2097
- }
2098
- return s;
2099
- },
2100
- /**
2101
- * Listen to a custom event and remove it once fired.
2102
- * @param {String} event Event name.
2103
- * @param {Function} fn Listener to call.
2104
- * @param {Number} id (optional) Only listen to events for this sound.
2105
- * @return {Howl}
2106
- */
2107
- once: function(e, a, o) {
2108
- var s = this;
2109
- return s.on(e, a, o, 1), s;
2110
- },
2111
- /**
2112
- * Emit all events of a specific type and pass the sound id.
2113
- * @param {String} event Event name.
2114
- * @param {Number} id Sound ID.
2115
- * @param {Number} msg Message to go with event.
2116
- * @return {Howl}
2117
- */
2118
- _emit: function(e, a, o) {
2119
- for (var s = this, c = s["_on" + e], l = c.length - 1; l >= 0; l--)
2120
- (!c[l].id || c[l].id === a || e === "load") && (setTimeout((function(f) {
2121
- f.call(this, a, o);
2122
- }).bind(s, c[l].fn), 0), c[l].once && s.off(e, c[l].fn, c[l].id));
2123
- return s._loadQueue(e), s;
2124
- },
2125
- /**
2126
- * Queue of actions initiated before the sound has loaded.
2127
- * These will be called in sequence, with the next only firing
2128
- * after the previous has finished executing (even if async like play).
2129
- * @return {Howl}
2130
- */
2131
- _loadQueue: function(e) {
2132
- var a = this;
2133
- if (a._queue.length > 0) {
2134
- var o = a._queue[0];
2135
- o.event === e && (a._queue.shift(), a._loadQueue()), e || o.action();
2136
- }
2137
- return a;
2138
- },
2139
- /**
2140
- * Fired when playback ends at the end of the duration.
2141
- * @param {Sound} sound The sound object to work with.
2142
- * @return {Howl}
2143
- */
2144
- _ended: function(e) {
2145
- var a = this, o = e._sprite;
2146
- if (!a._webAudio && e._node && !e._node.paused && !e._node.ended && e._node.currentTime < e._stop)
2147
- return setTimeout(a._ended.bind(a, e), 100), a;
2148
- var s = !!(e._loop || a._sprite[o][2]);
2149
- if (a._emit("end", e._id), !a._webAudio && s && a.stop(e._id, !0).play(e._id), a._webAudio && s) {
2150
- a._emit("play", e._id), e._seek = e._start || 0, e._rateSeek = 0, e._playStart = r.ctx.currentTime;
2151
- var c = (e._stop - e._start) * 1e3 / Math.abs(e._rate);
2152
- a._endTimers[e._id] = setTimeout(a._ended.bind(a, e), c);
2153
- }
2154
- return a._webAudio && !s && (e._paused = !0, e._ended = !0, e._seek = e._start || 0, e._rateSeek = 0, a._clearTimer(e._id), a._cleanBuffer(e._node), r._autoSuspend()), !a._webAudio && !s && a.stop(e._id, !0), a;
2155
- },
2156
- /**
2157
- * Clear the end timer for a sound playback.
2158
- * @param {Number} id The sound ID.
2159
- * @return {Howl}
2160
- */
2161
- _clearTimer: function(e) {
2162
- var a = this;
2163
- if (a._endTimers[e]) {
2164
- if (typeof a._endTimers[e] != "function")
2165
- clearTimeout(a._endTimers[e]);
2166
- else {
2167
- var o = a._soundById(e);
2168
- o && o._node && o._node.removeEventListener("ended", a._endTimers[e], !1);
2169
- }
2170
- delete a._endTimers[e];
2171
- }
2172
- return a;
2173
- },
2174
- /**
2175
- * Return the sound identified by this ID, or return null.
2176
- * @param {Number} id Sound ID
2177
- * @return {Object} Sound object or null.
2178
- */
2179
- _soundById: function(e) {
2180
- for (var a = this, o = 0; o < a._sounds.length; o++)
2181
- if (e === a._sounds[o]._id)
2182
- return a._sounds[o];
2183
- return null;
2184
- },
2185
- /**
2186
- * Return an inactive sound from the pool or create a new one.
2187
- * @return {Sound} Sound playback object.
2188
- */
2189
- _inactiveSound: function() {
2190
- var e = this;
2191
- e._drain();
2192
- for (var a = 0; a < e._sounds.length; a++)
2193
- if (e._sounds[a]._ended)
2194
- return e._sounds[a].reset();
2195
- return new u(e);
2196
- },
2197
- /**
2198
- * Drain excess inactive sounds from the pool.
2199
- */
2200
- _drain: function() {
2201
- var e = this, a = e._pool, o = 0, s = 0;
2202
- if (!(e._sounds.length < a)) {
2203
- for (s = 0; s < e._sounds.length; s++)
2204
- e._sounds[s]._ended && o++;
2205
- for (s = e._sounds.length - 1; s >= 0; s--) {
2206
- if (o <= a)
2207
- return;
2208
- e._sounds[s]._ended && (e._webAudio && e._sounds[s]._node && e._sounds[s]._node.disconnect(0), e._sounds.splice(s, 1), o--);
2209
- }
2210
- }
2211
- },
2212
- /**
2213
- * Get all ID's from the sounds pool.
2214
- * @param {Number} id Only return one ID if one is passed.
2215
- * @return {Array} Array of IDs.
2216
- */
2217
- _getSoundIds: function(e) {
2218
- var a = this;
2219
- if (typeof e > "u") {
2220
- for (var o = [], s = 0; s < a._sounds.length; s++)
2221
- o.push(a._sounds[s]._id);
2222
- return o;
2223
- } else
2224
- return [e];
2225
- },
2226
- /**
2227
- * Load the sound back into the buffer source.
2228
- * @param {Sound} sound The sound object to work with.
2229
- * @return {Howl}
2230
- */
2231
- _refreshBuffer: function(e) {
2232
- var a = this;
2233
- return e._node.bufferSource = r.ctx.createBufferSource(), e._node.bufferSource.buffer = d[a._src], e._panner ? e._node.bufferSource.connect(e._panner) : e._node.bufferSource.connect(e._node), e._node.bufferSource.loop = e._loop, e._loop && (e._node.bufferSource.loopStart = e._start || 0, e._node.bufferSource.loopEnd = e._stop || 0), e._node.bufferSource.playbackRate.setValueAtTime(e._rate, r.ctx.currentTime), a;
2234
- },
2235
- /**
2236
- * Prevent memory leaks by cleaning up the buffer source after playback.
2237
- * @param {Object} node Sound's audio node containing the buffer source.
2238
- * @return {Howl}
2239
- */
2240
- _cleanBuffer: function(e) {
2241
- var a = this, o = r._navigator && r._navigator.vendor.indexOf("Apple") >= 0;
2242
- if (!e.bufferSource)
2243
- return a;
2244
- if (r._scratchBuffer && e.bufferSource && (e.bufferSource.onended = null, e.bufferSource.disconnect(0), o))
2245
- try {
2246
- e.bufferSource.buffer = r._scratchBuffer;
2247
- } catch {
2248
- }
2249
- return e.bufferSource = null, a;
2250
- },
2251
- /**
2252
- * Set the source to a 0-second silence to stop any downloading (except in IE).
2253
- * @param {Object} node Audio node to clear.
2254
- */
2255
- _clearSound: function(e) {
2256
- var a = /MSIE |Trident\//.test(r._navigator && r._navigator.userAgent);
2257
- a || (e.src = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA");
2258
- }
2259
- };
2260
- var u = function(e) {
2261
- this._parent = e, this.init();
2262
- };
2263
- u.prototype = {
2264
- /**
2265
- * Initialize a new Sound object.
2266
- * @return {Sound}
2267
- */
2268
- init: function() {
2269
- var e = this, a = e._parent;
2270
- return e._muted = a._muted, e._loop = a._loop, e._volume = a._volume, e._rate = a._rate, e._seek = 0, e._paused = !0, e._ended = !0, e._sprite = "__default", e._id = ++r._counter, a._sounds.push(e), e.create(), e;
2271
- },
2272
- /**
2273
- * Create and setup a new sound object, whether HTML5 Audio or Web Audio.
2274
- * @return {Sound}
2275
- */
2276
- create: function() {
2277
- var e = this, a = e._parent, o = r._muted || e._muted || e._parent._muted ? 0 : e._volume;
2278
- return a._webAudio ? (e._node = typeof r.ctx.createGain > "u" ? r.ctx.createGainNode() : r.ctx.createGain(), e._node.gain.setValueAtTime(o, r.ctx.currentTime), e._node.paused = !0, e._node.connect(r.masterGain)) : r.noAudio || (e._node = r._obtainHtml5Audio(), e._errorFn = e._errorListener.bind(e), e._node.addEventListener("error", e._errorFn, !1), e._loadFn = e._loadListener.bind(e), e._node.addEventListener(r._canPlayEvent, e._loadFn, !1), e._endFn = e._endListener.bind(e), e._node.addEventListener("ended", e._endFn, !1), e._node.src = a._src, e._node.preload = a._preload === !0 ? "auto" : a._preload, e._node.volume = o * r.volume(), e._node.load()), e;
2279
- },
2280
- /**
2281
- * Reset the parameters of this sound to the original state (for recycle).
2282
- * @return {Sound}
2283
- */
2284
- reset: function() {
2285
- var e = this, a = e._parent;
2286
- return e._muted = a._muted, e._loop = a._loop, e._volume = a._volume, e._rate = a._rate, e._seek = 0, e._rateSeek = 0, e._paused = !0, e._ended = !0, e._sprite = "__default", e._id = ++r._counter, e;
2287
- },
2288
- /**
2289
- * HTML5 Audio error listener callback.
2290
- */
2291
- _errorListener: function() {
2292
- var e = this;
2293
- e._parent._emit("loaderror", e._id, e._node.error ? e._node.error.code : 0), e._node.removeEventListener("error", e._errorFn, !1);
2294
- },
2295
- /**
2296
- * HTML5 Audio canplaythrough listener callback.
2297
- */
2298
- _loadListener: function() {
2299
- var e = this, a = e._parent;
2300
- a._duration = Math.ceil(e._node.duration * 10) / 10, Object.keys(a._sprite).length === 0 && (a._sprite = { __default: [0, a._duration * 1e3] }), a._state !== "loaded" && (a._state = "loaded", a._emit("load"), a._loadQueue()), e._node.removeEventListener(r._canPlayEvent, e._loadFn, !1);
2301
- },
2302
- /**
2303
- * HTML5 Audio ended listener callback.
2304
- */
2305
- _endListener: function() {
2306
- var e = this, a = e._parent;
2307
- a._duration === 1 / 0 && (a._duration = Math.ceil(e._node.duration * 10) / 10, a._sprite.__default[1] === 1 / 0 && (a._sprite.__default[1] = a._duration * 1e3), a._ended(e)), e._node.removeEventListener("ended", e._endFn, !1);
2308
- }
2309
- };
2310
- var d = {}, _ = function(e) {
2311
- var a = e._src;
2312
- if (d[a]) {
2313
- e._duration = d[a].duration, A(e);
2314
- return;
2315
- }
2316
- if (/^data:[^;]+;base64,/.test(a)) {
2317
- for (var o = atob(a.split(",")[1]), s = new Uint8Array(o.length), c = 0; c < o.length; ++c)
2318
- s[c] = o.charCodeAt(c);
2319
- h(s.buffer, e);
2320
- } else {
2321
- var l = new XMLHttpRequest();
2322
- l.open(e._xhr.method, a, !0), l.withCredentials = e._xhr.withCredentials, l.responseType = "arraybuffer", e._xhr.headers && Object.keys(e._xhr.headers).forEach(function(f) {
2323
- l.setRequestHeader(f, e._xhr.headers[f]);
2324
- }), l.onload = function() {
2325
- var f = (l.status + "")[0];
2326
- if (f !== "0" && f !== "2" && f !== "3") {
2327
- e._emit("loaderror", null, "Failed loading audio file with status: " + l.status + ".");
2328
- return;
2329
- }
2330
- h(l.response, e);
2331
- }, l.onerror = function() {
2332
- e._webAudio && (e._html5 = !0, e._webAudio = !1, e._sounds = [], delete d[a], e.load());
2333
- }, p(l);
2334
- }
2335
- }, p = function(e) {
2336
- try {
2337
- e.send();
2338
- } catch {
2339
- e.onerror();
2340
- }
2341
- }, h = function(e, a) {
2342
- var o = function() {
2343
- a._emit("loaderror", null, "Decoding audio data failed.");
2344
- }, s = function(c) {
2345
- c && a._sounds.length > 0 ? (d[a._src] = c, A(a, c)) : o();
2346
- };
2347
- typeof Promise < "u" && r.ctx.decodeAudioData.length === 1 ? r.ctx.decodeAudioData(e).then(s).catch(o) : r.ctx.decodeAudioData(e, s, o);
2348
- }, A = function(e, a) {
2349
- a && !e._duration && (e._duration = a.duration), Object.keys(e._sprite).length === 0 && (e._sprite = { __default: [0, e._duration * 1e3] }), e._state !== "loaded" && (e._state = "loaded", e._emit("load"), e._loadQueue());
2350
- }, m = function() {
2351
- if (r.usingWebAudio) {
2352
- try {
2353
- typeof AudioContext < "u" ? r.ctx = new AudioContext() : typeof webkitAudioContext < "u" ? r.ctx = new webkitAudioContext() : r.usingWebAudio = !1;
2354
- } catch {
2355
- r.usingWebAudio = !1;
2356
- }
2357
- r.ctx || (r.usingWebAudio = !1);
2358
- var e = /iP(hone|od|ad)/.test(r._navigator && r._navigator.platform), a = r._navigator && r._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/), o = a ? parseInt(a[1], 10) : null;
2359
- if (e && o && o < 9) {
2360
- var s = /safari/.test(r._navigator && r._navigator.userAgent.toLowerCase());
2361
- r._navigator && !s && (r.usingWebAudio = !1);
2362
- }
2363
- r.usingWebAudio && (r.masterGain = typeof r.ctx.createGain > "u" ? r.ctx.createGainNode() : r.ctx.createGain(), r.masterGain.gain.setValueAtTime(r._muted ? 0 : r._volume, r.ctx.currentTime), r.masterGain.connect(r.ctx.destination)), r._setup();
2364
- }
2365
- };
2366
- t.Howler = r, t.Howl = i, typeof se < "u" ? (se.HowlerGlobal = n, se.Howler = r, se.Howl = i, se.Sound = u) : typeof window < "u" && (window.HowlerGlobal = n, window.Howler = r, window.Howl = i, window.Sound = u);
2367
- })();
2368
- })(Ue)), Ue;
2369
- }
2370
- var ae = ca();
2371
- const Ae = {}, Se = {};
2372
- function pn(t, n) {
2373
- t ? n[t] && n[t].stop() : Object.keys(n).forEach((r) => {
2374
- r && r.fade && r.fade(void 0, 0, 1), n[r].stop();
2375
- });
2376
- }
2377
- function la(t) {
2378
- vn(t.mute), mn(t.volume);
2379
- }
2380
- function vn(t = !0) {
2381
- ae.Howler.mute(t);
2382
- }
2383
- function da() {
2384
- return ae.Howler.muted;
2385
- }
2386
- function mn(t) {
2387
- ae.Howler.volume(t / 100);
2388
- }
2389
- function _a() {
2390
- return ae.Howler.volume * 100;
2391
- }
2392
- function pa(t) {
2393
- Ae[t] || (Ae[t] = new ae.Howl({
2394
- src: [t]
2395
- })), Ae[t].play();
2396
- }
2397
- function va(t) {
2398
- pn(t, Ae);
2399
- }
2400
- function ma(t, n = !0) {
2401
- Se[t] || (Se[t] = new ae.Howl({
2402
- src: [t],
2403
- html5: !0,
2404
- // streaming
2405
- loop: n
2406
- })), Se[t].play();
2407
- }
2408
- function ha(t) {
2409
- pn(t, Se);
2410
- }
2411
- const ga = {
2412
- init: la,
2413
- mute: vn,
2414
- isMuted: da,
2415
- setVolume: mn,
2416
- getVolume: _a,
2417
- playSound: pa,
2418
- stopSound: va,
2419
- playMusic: ma,
2420
- stopMusic: ha
2421
- };
2422
- let ya = /* @__PURE__ */ Symbol("clean"), B = [], H = 0;
2423
- const ye = 4, wa = /* @__NO_SIDE_EFFECTS__ */ (t) => {
2424
- let n = [], r = {
2425
- get() {
2426
- return r.lc || r.listen(() => {
2427
- })(), r.value;
2428
- },
2429
- lc: 0,
2430
- listen(i) {
2431
- return r.lc = n.push(i), () => {
2432
- for (let d = H + ye; d < B.length; )
2433
- B[d] === i ? B.splice(d, ye) : d += ye;
2434
- let u = n.indexOf(i);
2435
- ~u && (n.splice(u, 1), --r.lc || r.off());
2436
- };
2437
- },
2438
- notify(i, u) {
2439
- let d = !B.length;
2440
- for (let _ of n)
2441
- B.push(_, r.value, i, u);
2442
- if (d) {
2443
- for (H = 0; H < B.length; H += ye)
2444
- B[H](
2445
- B[H + 1],
2446
- B[H + 2],
2447
- B[H + 3]
2448
- );
2449
- B.length = 0;
2450
- }
2451
- },
2452
- /* It will be called on last listener unsubscribing.
2453
- We will redefine it in onMount and onStop. */
2454
- off() {
2455
- },
2456
- set(i) {
2457
- let u = r.value;
2458
- u !== i && (r.value = i, r.notify(u));
2459
- },
2460
- subscribe(i) {
2461
- let u = r.listen(i);
2462
- return i(r.value), u;
2463
- },
2464
- value: t
2465
- };
2466
- return process.env.NODE_ENV !== "production" && (r[ya] = () => {
2467
- n = [], r.lc = 0, r.off();
2468
- }), r;
2469
- }, ba = /* @__NO_SIDE_EFFECTS__ */ (t = {}) => {
2470
- let n = /* @__PURE__ */ wa(t);
2471
- return n.setKey = function(r, i) {
2472
- let u = n.value;
2473
- typeof i > "u" && r in n.value ? (n.value = { ...n.value }, delete n.value[r], n.notify(u, r)) : n.value[r] !== i && (n.value = {
2474
- ...n.value,
2475
- [r]: i
2476
- }, n.notify(u, r));
2477
- }, n;
2478
- }, T = /* @__PURE__ */ ba({
2479
- settings: {},
2480
- game: {},
2481
- metadata: {},
2482
- scenes: [],
2483
- vars: {}
1082
+ //#endregion
1083
+ //#region node_modules/idb-keyval/dist/index.js
1084
+ function K(e) {
1085
+ return new Promise((t, n) => {
1086
+ e.oncomplete = e.onsuccess = () => t(e.result), e.onabort = e.onerror = () => n(e.error);
1087
+ });
1088
+ }
1089
+ function pn(e, t) {
1090
+ let n, r = () => {
1091
+ if (n) return n;
1092
+ let r = indexedDB.open(e);
1093
+ return r.onupgradeneeded = () => r.result.createObjectStore(t), n = K(r), n.then((e) => {
1094
+ e.onclose = () => n = void 0;
1095
+ }, () => {}), n;
1096
+ };
1097
+ return (e, n) => r().then((r) => n(r.transaction(t, e).objectStore(t)));
1098
+ }
1099
+ var mn;
1100
+ function hn() {
1101
+ return mn ||= pn("keyval-store", "keyval"), mn;
1102
+ }
1103
+ function gn(e, t = hn()) {
1104
+ return t("readonly", (t) => K(t.get(e)));
1105
+ }
1106
+ function _n(e, t, n = hn()) {
1107
+ return n("readwrite", (n) => (n.put(t, e), K(n.transaction)));
1108
+ }
1109
+ function vn(e, t = hn()) {
1110
+ return t("readwrite", (t) => (t.delete(e), K(t.transaction)));
1111
+ }
1112
+ function yn(e, t) {
1113
+ return e.openCursor().onsuccess = function() {
1114
+ this.result && (t(this.result), this.result.continue());
1115
+ }, K(e.transaction);
1116
+ }
1117
+ function bn(e = hn()) {
1118
+ return e("readonly", (e) => {
1119
+ if (e.getAllKeys) return K(e.getAllKeys());
1120
+ let t = [];
1121
+ return yn(e, (e) => t.push(e.key)).then(() => t);
1122
+ });
1123
+ }
1124
+ //#endregion
1125
+ //#region src/interfaces/persistent-idb.js
1126
+ var q;
1127
+ function xn(e) {
1128
+ q = pn(e, "keyvaluepairs");
1129
+ }
1130
+ async function Sn(e) {
1131
+ return await gn(e, q) !== void 0;
1132
+ }
1133
+ async function Cn(e) {
1134
+ return await gn(e, q);
1135
+ }
1136
+ async function wn(e, t) {
1137
+ await _n(e, t, q);
1138
+ }
1139
+ async function Tn(e) {
1140
+ await vn(e, q);
1141
+ }
1142
+ async function En() {
1143
+ return await bn(q);
1144
+ }
1145
+ var Dn = {
1146
+ init: xn,
1147
+ exists: Sn,
1148
+ get: Cn,
1149
+ set: wn,
1150
+ remove: Tn,
1151
+ keys: En
1152
+ }, On = /* @__PURE__ */ o(((e, t) => {
1153
+ function n(e, t) {
1154
+ for (var n = e.length & 3, r = e.length - n, i = t, a, o = 3432918353, s = 461845907, c, l = 0; l < r;) c = e.charCodeAt(l) & 255 | (e.charCodeAt(++l) & 255) << 8 | (e.charCodeAt(++l) & 255) << 16 | (e.charCodeAt(++l) & 255) << 24, ++l, c = (c & 65535) * o + (((c >>> 16) * o & 65535) << 16) & 4294967295, c = c << 15 | c >>> 17, c = (c & 65535) * s + (((c >>> 16) * s & 65535) << 16) & 4294967295, i ^= c, i = i << 13 | i >>> 19, a = (i & 65535) * 5 + (((i >>> 16) * 5 & 65535) << 16) & 4294967295, i = (a & 65535) + 27492 + (((a >>> 16) + 58964 & 65535) << 16);
1155
+ switch (c = 0, n) {
1156
+ case 3: c ^= (e.charCodeAt(l + 2) & 255) << 16;
1157
+ case 2: c ^= (e.charCodeAt(l + 1) & 255) << 8;
1158
+ case 1: c ^= e.charCodeAt(l) & 255, c = (c & 65535) * o + (((c >>> 16) * o & 65535) << 16) & 4294967295, c = c << 15 | c >>> 17, c = (c & 65535) * s + (((c >>> 16) * s & 65535) << 16) & 4294967295, i ^= c;
1159
+ }
1160
+ return i ^= e.length, i ^= i >>> 16, i = (i & 65535) * 2246822507 + (((i >>> 16) * 2246822507 & 65535) << 16) & 4294967295, i ^= i >>> 13, i = (i & 65535) * 3266489909 + (((i >>> 16) * 3266489909 & 65535) << 16) & 4294967295, i ^= i >>> 16, i >>> 0;
1161
+ }
1162
+ t !== void 0 && (t.exports = n);
1163
+ })), kn = /* @__PURE__ */ o(((e, t) => {
1164
+ function n(e, t) {
1165
+ for (var n = e.length, r = t ^ n, i = 0, a; n >= 4;) a = e.charCodeAt(i) & 255 | (e.charCodeAt(++i) & 255) << 8 | (e.charCodeAt(++i) & 255) << 16 | (e.charCodeAt(++i) & 255) << 24, a = (a & 65535) * 1540483477 + (((a >>> 16) * 1540483477 & 65535) << 16), a ^= a >>> 24, a = (a & 65535) * 1540483477 + (((a >>> 16) * 1540483477 & 65535) << 16), r = (r & 65535) * 1540483477 + (((r >>> 16) * 1540483477 & 65535) << 16) ^ a, n -= 4, ++i;
1166
+ switch (n) {
1167
+ case 3: r ^= (e.charCodeAt(i + 2) & 255) << 16;
1168
+ case 2: r ^= (e.charCodeAt(i + 1) & 255) << 8;
1169
+ case 1: r ^= e.charCodeAt(i) & 255, r = (r & 65535) * 1540483477 + (((r >>> 16) * 1540483477 & 65535) << 16);
1170
+ }
1171
+ return r ^= r >>> 13, r = (r & 65535) * 1540483477 + (((r >>> 16) * 1540483477 & 65535) << 16), r ^= r >>> 15, r >>> 0;
1172
+ }
1173
+ t.exports = n;
1174
+ })), An = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
1175
+ var n = On(), r = kn();
1176
+ t.exports = n, t.exports.murmur3 = n, t.exports.murmur2 = r;
1177
+ })))(), 1), J = "__atrament_storage", Y = Promise.resolve();
1178
+ async function jn(e) {
1179
+ try {
1180
+ let t = await window.Neutralino.storage.getData(e);
1181
+ return JSON.parse(t);
1182
+ } catch (e) {
1183
+ return console.warn(e.message), null;
1184
+ }
1185
+ }
1186
+ async function Mn(e, t) {
1187
+ let n = JSON.stringify(t);
1188
+ return await window.Neutralino.storage.setData(e, n), n;
1189
+ }
1190
+ async function Nn(e) {
1191
+ return await window.Neutralino.storage.setData(e, null), !0;
1192
+ }
1193
+ function Pn(e) {
1194
+ return `storage_${(0, An.default)(e)}`;
1195
+ }
1196
+ async function Fn(e, t) {
1197
+ return Y = Y.then(async () => {
1198
+ let n = await jn(J);
1199
+ n === null && (n = {}), n[t] = e, await Mn(J, n);
1200
+ }).catch((e) => console.error(e.message)), Y;
1201
+ }
1202
+ async function In(e) {
1203
+ return Y = Y.then(async () => {
1204
+ let t = await jn(J);
1205
+ t === null && (t = {}), delete t[e], await Mn(J, t);
1206
+ }).catch((e) => console.error(e.message)), Y;
1207
+ }
1208
+ function Ln() {}
1209
+ async function Rn(e) {
1210
+ return (await Hn()).includes(e);
1211
+ }
1212
+ async function zn(e) {
1213
+ let t = await jn(J);
1214
+ return await jn(t === null ? Pn(e) : t[e]);
1215
+ }
1216
+ async function Bn(e, t) {
1217
+ let n = Pn(e);
1218
+ try {
1219
+ await Mn(n, t), await Fn(n, e);
1220
+ } catch (e) {
1221
+ console.error(e.message);
1222
+ }
1223
+ }
1224
+ async function Vn(e) {
1225
+ let t = Pn(e);
1226
+ try {
1227
+ await Nn(t), await In(e);
1228
+ } catch (e) {
1229
+ console.error(e.message);
1230
+ }
1231
+ }
1232
+ async function Hn() {
1233
+ let e = await jn(J);
1234
+ return e === null ? [] : Object.keys(e);
1235
+ }
1236
+ var Un = {
1237
+ init: Ln,
1238
+ exists: Rn,
1239
+ get: zn,
1240
+ set: Bn,
1241
+ remove: Vn,
1242
+ keys: Hn
1243
+ }, X = (/* @__PURE__ */ o(((e) => {
1244
+ (function() {
1245
+ var t = function() {
1246
+ this.init();
1247
+ };
1248
+ t.prototype = {
1249
+ init: function() {
1250
+ var e = this || n;
1251
+ return e._counter = 1e3, e._html5AudioPool = [], e.html5PoolSize = 10, e._codecs = {}, e._howls = [], e._muted = !1, e._volume = 1, e._canPlayEvent = "canplaythrough", e._navigator = typeof window < "u" && window.navigator ? window.navigator : null, e.masterGain = null, e.noAudio = !1, e.usingWebAudio = !0, e.autoSuspend = !0, e.ctx = null, e.autoUnlock = !0, e._setup(), e;
1252
+ },
1253
+ volume: function(e) {
1254
+ var t = this || n;
1255
+ if (e = parseFloat(e), t.ctx || u(), e !== void 0 && e >= 0 && e <= 1) {
1256
+ if (t._volume = e, t._muted) return t;
1257
+ t.usingWebAudio && t.masterGain.gain.setValueAtTime(e, n.ctx.currentTime);
1258
+ for (var r = 0; r < t._howls.length; r++) if (!t._howls[r]._webAudio) for (var i = t._howls[r]._getSoundIds(), a = 0; a < i.length; a++) {
1259
+ var o = t._howls[r]._soundById(i[a]);
1260
+ o && o._node && (o._node.volume = o._volume * e);
1261
+ }
1262
+ return t;
1263
+ }
1264
+ return t._volume;
1265
+ },
1266
+ mute: function(e) {
1267
+ var t = this || n;
1268
+ t.ctx || u(), t._muted = e, t.usingWebAudio && t.masterGain.gain.setValueAtTime(e ? 0 : t._volume, n.ctx.currentTime);
1269
+ for (var r = 0; r < t._howls.length; r++) if (!t._howls[r]._webAudio) for (var i = t._howls[r]._getSoundIds(), a = 0; a < i.length; a++) {
1270
+ var o = t._howls[r]._soundById(i[a]);
1271
+ o && o._node && (o._node.muted = e ? !0 : o._muted);
1272
+ }
1273
+ return t;
1274
+ },
1275
+ stop: function() {
1276
+ for (var e = this || n, t = 0; t < e._howls.length; t++) e._howls[t].stop();
1277
+ return e;
1278
+ },
1279
+ unload: function() {
1280
+ for (var e = this || n, t = e._howls.length - 1; t >= 0; t--) e._howls[t].unload();
1281
+ return e.usingWebAudio && e.ctx && e.ctx.close !== void 0 && (e.ctx.close(), e.ctx = null, u()), e;
1282
+ },
1283
+ codecs: function(e) {
1284
+ return (this || n)._codecs[e.replace(/^x-/, "")];
1285
+ },
1286
+ _setup: function() {
1287
+ var e = this || n;
1288
+ if (e.state = e.ctx && e.ctx.state || "suspended", e._autoSuspend(), !e.usingWebAudio) if (typeof Audio < "u") try {
1289
+ var t = new Audio();
1290
+ t.oncanplaythrough === void 0 && (e._canPlayEvent = "canplay");
1291
+ } catch {
1292
+ e.noAudio = !0;
1293
+ }
1294
+ else e.noAudio = !0;
1295
+ try {
1296
+ var t = new Audio();
1297
+ t.muted && (e.noAudio = !0);
1298
+ } catch {}
1299
+ return e.noAudio || e._setupCodecs(), e;
1300
+ },
1301
+ _setupCodecs: function() {
1302
+ var e = this || n, t = null;
1303
+ try {
1304
+ t = typeof Audio < "u" ? new Audio() : null;
1305
+ } catch {
1306
+ return e;
1307
+ }
1308
+ if (!t || typeof t.canPlayType != "function") return e;
1309
+ var r = t.canPlayType("audio/mpeg;").replace(/^no$/, ""), i = e._navigator ? e._navigator.userAgent : "", a = i.match(/OPR\/(\d+)/g), o = a && parseInt(a[0].split("/")[1], 10) < 33, s = i.indexOf("Safari") !== -1 && i.indexOf("Chrome") === -1, c = i.match(/Version\/(.*?) /), l = s && c && parseInt(c[1], 10) < 15;
1310
+ return e._codecs = {
1311
+ mp3: !!(!o && (r || t.canPlayType("audio/mp3;").replace(/^no$/, ""))),
1312
+ mpeg: !!r,
1313
+ opus: !!t.canPlayType("audio/ogg; codecs=\"opus\"").replace(/^no$/, ""),
1314
+ ogg: !!t.canPlayType("audio/ogg; codecs=\"vorbis\"").replace(/^no$/, ""),
1315
+ oga: !!t.canPlayType("audio/ogg; codecs=\"vorbis\"").replace(/^no$/, ""),
1316
+ wav: !!(t.canPlayType("audio/wav; codecs=\"1\"") || t.canPlayType("audio/wav")).replace(/^no$/, ""),
1317
+ aac: !!t.canPlayType("audio/aac;").replace(/^no$/, ""),
1318
+ caf: !!t.canPlayType("audio/x-caf;").replace(/^no$/, ""),
1319
+ m4a: !!(t.canPlayType("audio/x-m4a;") || t.canPlayType("audio/m4a;") || t.canPlayType("audio/aac;")).replace(/^no$/, ""),
1320
+ m4b: !!(t.canPlayType("audio/x-m4b;") || t.canPlayType("audio/m4b;") || t.canPlayType("audio/aac;")).replace(/^no$/, ""),
1321
+ mp4: !!(t.canPlayType("audio/x-mp4;") || t.canPlayType("audio/mp4;") || t.canPlayType("audio/aac;")).replace(/^no$/, ""),
1322
+ weba: !!(!l && t.canPlayType("audio/webm; codecs=\"vorbis\"").replace(/^no$/, "")),
1323
+ webm: !!(!l && t.canPlayType("audio/webm; codecs=\"vorbis\"").replace(/^no$/, "")),
1324
+ dolby: !!t.canPlayType("audio/mp4; codecs=\"ec-3\"").replace(/^no$/, ""),
1325
+ flac: !!(t.canPlayType("audio/x-flac;") || t.canPlayType("audio/flac;")).replace(/^no$/, "")
1326
+ }, e;
1327
+ },
1328
+ _unlockAudio: function() {
1329
+ var e = this || n;
1330
+ if (!(e._audioUnlocked || !e.ctx)) {
1331
+ e._audioUnlocked = !1, e.autoUnlock = !1, !e._mobileUnloaded && e.ctx.sampleRate !== 44100 && (e._mobileUnloaded = !0, e.unload()), e._scratchBuffer = e.ctx.createBuffer(1, 1, 22050);
1332
+ var t = function(n) {
1333
+ for (; e._html5AudioPool.length < e.html5PoolSize;) try {
1334
+ var r = new Audio();
1335
+ r._unlocked = !0, e._releaseHtml5Audio(r);
1336
+ } catch {
1337
+ e.noAudio = !0;
1338
+ break;
1339
+ }
1340
+ for (var i = 0; i < e._howls.length; i++) if (!e._howls[i]._webAudio) for (var a = e._howls[i]._getSoundIds(), o = 0; o < a.length; o++) {
1341
+ var s = e._howls[i]._soundById(a[o]);
1342
+ s && s._node && !s._node._unlocked && (s._node._unlocked = !0, s._node.load());
1343
+ }
1344
+ e._autoResume();
1345
+ var c = e.ctx.createBufferSource();
1346
+ c.buffer = e._scratchBuffer, c.connect(e.ctx.destination), c.start === void 0 ? c.noteOn(0) : c.start(0), typeof e.ctx.resume == "function" && e.ctx.resume(), c.onended = function() {
1347
+ c.disconnect(0), e._audioUnlocked = !0, document.removeEventListener("touchstart", t, !0), document.removeEventListener("touchend", t, !0), document.removeEventListener("click", t, !0), document.removeEventListener("keydown", t, !0);
1348
+ for (var n = 0; n < e._howls.length; n++) e._howls[n]._emit("unlock");
1349
+ };
1350
+ };
1351
+ return document.addEventListener("touchstart", t, !0), document.addEventListener("touchend", t, !0), document.addEventListener("click", t, !0), document.addEventListener("keydown", t, !0), e;
1352
+ }
1353
+ },
1354
+ _obtainHtml5Audio: function() {
1355
+ var e = this || n;
1356
+ if (e._html5AudioPool.length) return e._html5AudioPool.pop();
1357
+ var t = new Audio().play();
1358
+ return t && typeof Promise < "u" && (t instanceof Promise || typeof t.then == "function") && t.catch(function() {
1359
+ console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.");
1360
+ }), new Audio();
1361
+ },
1362
+ _releaseHtml5Audio: function(e) {
1363
+ var t = this || n;
1364
+ return e._unlocked && t._html5AudioPool.push(e), t;
1365
+ },
1366
+ _autoSuspend: function() {
1367
+ var e = this;
1368
+ if (!(!e.autoSuspend || !e.ctx || e.ctx.suspend === void 0 || !n.usingWebAudio)) {
1369
+ for (var t = 0; t < e._howls.length; t++) if (e._howls[t]._webAudio) {
1370
+ for (var r = 0; r < e._howls[t]._sounds.length; r++) if (!e._howls[t]._sounds[r]._paused) return e;
1371
+ }
1372
+ return e._suspendTimer && clearTimeout(e._suspendTimer), e._suspendTimer = setTimeout(function() {
1373
+ if (e.autoSuspend) {
1374
+ e._suspendTimer = null, e.state = "suspending";
1375
+ var t = function() {
1376
+ e.state = "suspended", e._resumeAfterSuspend && (delete e._resumeAfterSuspend, e._autoResume());
1377
+ };
1378
+ e.ctx.suspend().then(t, t);
1379
+ }
1380
+ }, 3e4), e;
1381
+ }
1382
+ },
1383
+ _autoResume: function() {
1384
+ var e = this;
1385
+ if (!(!e.ctx || e.ctx.resume === void 0 || !n.usingWebAudio)) return e.state === "running" && e.ctx.state !== "interrupted" && e._suspendTimer ? (clearTimeout(e._suspendTimer), e._suspendTimer = null) : e.state === "suspended" || e.state === "running" && e.ctx.state === "interrupted" ? (e.ctx.resume().then(function() {
1386
+ e.state = "running";
1387
+ for (var t = 0; t < e._howls.length; t++) e._howls[t]._emit("resume");
1388
+ }), e._suspendTimer &&= (clearTimeout(e._suspendTimer), null)) : e.state === "suspending" && (e._resumeAfterSuspend = !0), e;
1389
+ }
1390
+ };
1391
+ var n = new t(), r = function(e) {
1392
+ var t = this;
1393
+ if (!e.src || e.src.length === 0) {
1394
+ console.error("An array of source files must be passed with any new Howl.");
1395
+ return;
1396
+ }
1397
+ t.init(e);
1398
+ };
1399
+ r.prototype = {
1400
+ init: function(e) {
1401
+ var t = this;
1402
+ return n.ctx || u(), t._autoplay = e.autoplay || !1, t._format = typeof e.format == "string" ? [e.format] : e.format, t._html5 = e.html5 || !1, t._muted = e.mute || !1, t._loop = e.loop || !1, t._pool = e.pool || 5, t._preload = typeof e.preload == "boolean" || e.preload === "metadata" ? e.preload : !0, t._rate = e.rate || 1, t._sprite = e.sprite || {}, t._src = typeof e.src == "string" ? [e.src] : e.src, t._volume = e.volume === void 0 ? 1 : e.volume, t._xhr = {
1403
+ method: e.xhr && e.xhr.method ? e.xhr.method : "GET",
1404
+ headers: e.xhr && e.xhr.headers ? e.xhr.headers : null,
1405
+ withCredentials: e.xhr && e.xhr.withCredentials ? e.xhr.withCredentials : !1
1406
+ }, t._duration = 0, t._state = "unloaded", t._sounds = [], t._endTimers = {}, t._queue = [], t._playLock = !1, t._onend = e.onend ? [{ fn: e.onend }] : [], t._onfade = e.onfade ? [{ fn: e.onfade }] : [], t._onload = e.onload ? [{ fn: e.onload }] : [], t._onloaderror = e.onloaderror ? [{ fn: e.onloaderror }] : [], t._onplayerror = e.onplayerror ? [{ fn: e.onplayerror }] : [], t._onpause = e.onpause ? [{ fn: e.onpause }] : [], t._onplay = e.onplay ? [{ fn: e.onplay }] : [], t._onstop = e.onstop ? [{ fn: e.onstop }] : [], t._onmute = e.onmute ? [{ fn: e.onmute }] : [], t._onvolume = e.onvolume ? [{ fn: e.onvolume }] : [], t._onrate = e.onrate ? [{ fn: e.onrate }] : [], t._onseek = e.onseek ? [{ fn: e.onseek }] : [], t._onunlock = e.onunlock ? [{ fn: e.onunlock }] : [], t._onresume = [], t._webAudio = n.usingWebAudio && !t._html5, n.ctx !== void 0 && n.ctx && n.autoUnlock && n._unlockAudio(), n._howls.push(t), t._autoplay && t._queue.push({
1407
+ event: "play",
1408
+ action: function() {
1409
+ t.play();
1410
+ }
1411
+ }), t._preload && t._preload !== "none" && t.load(), t;
1412
+ },
1413
+ load: function() {
1414
+ var e = this, t = null;
1415
+ if (n.noAudio) {
1416
+ e._emit("loaderror", null, "No audio support.");
1417
+ return;
1418
+ }
1419
+ typeof e._src == "string" && (e._src = [e._src]);
1420
+ for (var r = 0; r < e._src.length; r++) {
1421
+ var a, s;
1422
+ if (e._format && e._format[r]) a = e._format[r];
1423
+ else {
1424
+ if (s = e._src[r], typeof s != "string") {
1425
+ e._emit("loaderror", null, "Non-string found in selected audio sources - ignoring.");
1426
+ continue;
1427
+ }
1428
+ a = /^data:audio\/([^;,]+);/i.exec(s), a ||= /\.([^.]+)$/.exec(s.split("?", 1)[0]), a &&= a[1].toLowerCase();
1429
+ }
1430
+ if (a || console.warn("No file extension was found. Consider using the \"format\" property or specify an extension."), a && n.codecs(a)) {
1431
+ t = e._src[r];
1432
+ break;
1433
+ }
1434
+ }
1435
+ if (!t) {
1436
+ e._emit("loaderror", null, "No codec support for selected audio sources.");
1437
+ return;
1438
+ }
1439
+ return e._src = t, e._state = "loading", window.location.protocol === "https:" && t.slice(0, 5) === "http:" && (e._html5 = !0, e._webAudio = !1), new i(e), e._webAudio && o(e), e;
1440
+ },
1441
+ play: function(e, t) {
1442
+ var r = this, i = null;
1443
+ if (typeof e == "number") i = e, e = null;
1444
+ else if (typeof e == "string" && r._state === "loaded" && !r._sprite[e]) return null;
1445
+ else if (e === void 0 && (e = "__default", !r._playLock)) {
1446
+ for (var a = 0, o = 0; o < r._sounds.length; o++) r._sounds[o]._paused && !r._sounds[o]._ended && (a++, i = r._sounds[o]._id);
1447
+ a === 1 ? e = null : i = null;
1448
+ }
1449
+ var s = i ? r._soundById(i) : r._inactiveSound();
1450
+ if (!s) return null;
1451
+ if (i && !e && (e = s._sprite || "__default"), r._state !== "loaded") {
1452
+ s._sprite = e, s._ended = !1;
1453
+ var c = s._id;
1454
+ return r._queue.push({
1455
+ event: "play",
1456
+ action: function() {
1457
+ r.play(c);
1458
+ }
1459
+ }), c;
1460
+ }
1461
+ if (i && !s._paused) return t || r._loadQueue("play"), s._id;
1462
+ r._webAudio && n._autoResume();
1463
+ var l = Math.max(0, s._seek > 0 ? s._seek : r._sprite[e][0] / 1e3), u = Math.max(0, (r._sprite[e][0] + r._sprite[e][1]) / 1e3 - l), d = u * 1e3 / Math.abs(s._rate), f = r._sprite[e][0] / 1e3, p = (r._sprite[e][0] + r._sprite[e][1]) / 1e3;
1464
+ s._sprite = e, s._ended = !1;
1465
+ var m = function() {
1466
+ s._paused = !1, s._seek = l, s._start = f, s._stop = p, s._loop = !!(s._loop || r._sprite[e][2]);
1467
+ };
1468
+ if (l >= p) {
1469
+ r._ended(s);
1470
+ return;
1471
+ }
1472
+ var h = s._node;
1473
+ if (r._webAudio) {
1474
+ var g = function() {
1475
+ r._playLock = !1, m(), r._refreshBuffer(s);
1476
+ var e = s._muted || r._muted ? 0 : s._volume;
1477
+ h.gain.setValueAtTime(e, n.ctx.currentTime), s._playStart = n.ctx.currentTime, h.bufferSource.start === void 0 ? s._loop ? h.bufferSource.noteGrainOn(0, l, 86400) : h.bufferSource.noteGrainOn(0, l, u) : s._loop ? h.bufferSource.start(0, l, 86400) : h.bufferSource.start(0, l, u), d !== Infinity && (r._endTimers[s._id] = setTimeout(r._ended.bind(r, s), d)), t || setTimeout(function() {
1478
+ r._emit("play", s._id), r._loadQueue();
1479
+ }, 0);
1480
+ };
1481
+ n.state === "running" && n.ctx.state !== "interrupted" ? g() : (r._playLock = !0, r.once("resume", g), r._clearTimer(s._id));
1482
+ } else {
1483
+ var _ = function() {
1484
+ h.currentTime = l, h.muted = s._muted || r._muted || n._muted || h.muted, h.volume = s._volume * n.volume(), h.playbackRate = s._rate;
1485
+ try {
1486
+ var i = h.play();
1487
+ if (i && typeof Promise < "u" && (i instanceof Promise || typeof i.then == "function") ? (r._playLock = !0, m(), i.then(function() {
1488
+ r._playLock = !1, h._unlocked = !0, t ? r._loadQueue() : r._emit("play", s._id);
1489
+ }).catch(function() {
1490
+ r._playLock = !1, r._emit("playerror", s._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction."), s._ended = !0, s._paused = !0;
1491
+ })) : t || (r._playLock = !1, m(), r._emit("play", s._id)), h.playbackRate = s._rate, h.paused) {
1492
+ r._emit("playerror", s._id, "Playback was unable to start. This is most commonly an issue on mobile devices and Chrome where playback was not within a user interaction.");
1493
+ return;
1494
+ }
1495
+ e !== "__default" || s._loop ? r._endTimers[s._id] = setTimeout(r._ended.bind(r, s), d) : (r._endTimers[s._id] = function() {
1496
+ r._ended(s), h.removeEventListener("ended", r._endTimers[s._id], !1);
1497
+ }, h.addEventListener("ended", r._endTimers[s._id], !1));
1498
+ } catch (e) {
1499
+ r._emit("playerror", s._id, e);
1500
+ }
1501
+ };
1502
+ h.src === "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA" && (h.src = r._src, h.load());
1503
+ var ee = window && window.ejecta || !h.readyState && n._navigator.isCocoonJS;
1504
+ if (h.readyState >= 3 || ee) _();
1505
+ else {
1506
+ r._playLock = !0, r._state = "loading";
1507
+ var v = function() {
1508
+ r._state = "loaded", _(), h.removeEventListener(n._canPlayEvent, v, !1);
1509
+ };
1510
+ h.addEventListener(n._canPlayEvent, v, !1), r._clearTimer(s._id);
1511
+ }
1512
+ }
1513
+ return s._id;
1514
+ },
1515
+ pause: function(e) {
1516
+ var t = this;
1517
+ if (t._state !== "loaded" || t._playLock) return t._queue.push({
1518
+ event: "pause",
1519
+ action: function() {
1520
+ t.pause(e);
1521
+ }
1522
+ }), t;
1523
+ for (var n = t._getSoundIds(e), r = 0; r < n.length; r++) {
1524
+ t._clearTimer(n[r]);
1525
+ var i = t._soundById(n[r]);
1526
+ if (i && !i._paused && (i._seek = t.seek(n[r]), i._rateSeek = 0, i._paused = !0, t._stopFade(n[r]), i._node)) if (t._webAudio) {
1527
+ if (!i._node.bufferSource) continue;
1528
+ i._node.bufferSource.stop === void 0 ? i._node.bufferSource.noteOff(0) : i._node.bufferSource.stop(0), t._cleanBuffer(i._node);
1529
+ } else (!isNaN(i._node.duration) || i._node.duration === Infinity) && i._node.pause();
1530
+ arguments[1] || t._emit("pause", i ? i._id : null);
1531
+ }
1532
+ return t;
1533
+ },
1534
+ stop: function(e, t) {
1535
+ var n = this;
1536
+ if (n._state !== "loaded" || n._playLock) return n._queue.push({
1537
+ event: "stop",
1538
+ action: function() {
1539
+ n.stop(e);
1540
+ }
1541
+ }), n;
1542
+ for (var r = n._getSoundIds(e), i = 0; i < r.length; i++) {
1543
+ n._clearTimer(r[i]);
1544
+ var a = n._soundById(r[i]);
1545
+ a && (a._seek = a._start || 0, a._rateSeek = 0, a._paused = !0, a._ended = !0, n._stopFade(r[i]), a._node && (n._webAudio ? a._node.bufferSource && (a._node.bufferSource.stop === void 0 ? a._node.bufferSource.noteOff(0) : a._node.bufferSource.stop(0), n._cleanBuffer(a._node)) : (!isNaN(a._node.duration) || a._node.duration === Infinity) && (a._node.currentTime = a._start || 0, a._node.pause(), a._node.duration === Infinity && n._clearSound(a._node))), t || n._emit("stop", a._id));
1546
+ }
1547
+ return n;
1548
+ },
1549
+ mute: function(e, t) {
1550
+ var r = this;
1551
+ if (r._state !== "loaded" || r._playLock) return r._queue.push({
1552
+ event: "mute",
1553
+ action: function() {
1554
+ r.mute(e, t);
1555
+ }
1556
+ }), r;
1557
+ if (t === void 0) if (typeof e == "boolean") r._muted = e;
1558
+ else return r._muted;
1559
+ for (var i = r._getSoundIds(t), a = 0; a < i.length; a++) {
1560
+ var o = r._soundById(i[a]);
1561
+ o && (o._muted = e, o._interval && r._stopFade(o._id), r._webAudio && o._node ? o._node.gain.setValueAtTime(e ? 0 : o._volume, n.ctx.currentTime) : o._node && (o._node.muted = n._muted ? !0 : e), r._emit("mute", o._id));
1562
+ }
1563
+ return r;
1564
+ },
1565
+ volume: function() {
1566
+ var e = this, t = arguments, r, i;
1567
+ if (t.length === 0) return e._volume;
1568
+ t.length === 1 || t.length === 2 && t[1] === void 0 ? e._getSoundIds().indexOf(t[0]) >= 0 ? i = parseInt(t[0], 10) : r = parseFloat(t[0]) : t.length >= 2 && (r = parseFloat(t[0]), i = parseInt(t[1], 10));
1569
+ var a;
1570
+ if (r !== void 0 && r >= 0 && r <= 1) {
1571
+ if (e._state !== "loaded" || e._playLock) return e._queue.push({
1572
+ event: "volume",
1573
+ action: function() {
1574
+ e.volume.apply(e, t);
1575
+ }
1576
+ }), e;
1577
+ i === void 0 && (e._volume = r), i = e._getSoundIds(i);
1578
+ for (var o = 0; o < i.length; o++) a = e._soundById(i[o]), a && (a._volume = r, t[2] || e._stopFade(i[o]), e._webAudio && a._node && !a._muted ? a._node.gain.setValueAtTime(r, n.ctx.currentTime) : a._node && !a._muted && (a._node.volume = r * n.volume()), e._emit("volume", a._id));
1579
+ } else return a = i ? e._soundById(i) : e._sounds[0], a ? a._volume : 0;
1580
+ return e;
1581
+ },
1582
+ fade: function(e, t, r, i) {
1583
+ var a = this;
1584
+ if (a._state !== "loaded" || a._playLock) return a._queue.push({
1585
+ event: "fade",
1586
+ action: function() {
1587
+ a.fade(e, t, r, i);
1588
+ }
1589
+ }), a;
1590
+ e = Math.min(Math.max(0, parseFloat(e)), 1), t = Math.min(Math.max(0, parseFloat(t)), 1), r = parseFloat(r), a.volume(e, i);
1591
+ for (var o = a._getSoundIds(i), s = 0; s < o.length; s++) {
1592
+ var c = a._soundById(o[s]);
1593
+ if (c) {
1594
+ if (i || a._stopFade(o[s]), a._webAudio && !c._muted) {
1595
+ var l = n.ctx.currentTime, u = l + r / 1e3;
1596
+ c._volume = e, c._node.gain.setValueAtTime(e, l), c._node.gain.linearRampToValueAtTime(t, u);
1597
+ }
1598
+ a._startFadeInterval(c, e, t, r, o[s], i === void 0);
1599
+ }
1600
+ }
1601
+ return a;
1602
+ },
1603
+ _startFadeInterval: function(e, t, n, r, i, a) {
1604
+ var o = this, s = t, c = n - t, l = Math.abs(c / .01), u = Math.max(4, l > 0 ? r / l : r), d = Date.now();
1605
+ e._fadeTo = n, e._interval = setInterval(function() {
1606
+ var i = (Date.now() - d) / r;
1607
+ d = Date.now(), s += c * i, s = Math.round(s * 100) / 100, s = c < 0 ? Math.max(n, s) : Math.min(n, s), o._webAudio ? e._volume = s : o.volume(s, e._id, !0), a && (o._volume = s), (n < t && s <= n || n > t && s >= n) && (clearInterval(e._interval), e._interval = null, e._fadeTo = null, o.volume(n, e._id), o._emit("fade", e._id));
1608
+ }, u);
1609
+ },
1610
+ _stopFade: function(e) {
1611
+ var t = this, r = t._soundById(e);
1612
+ return r && r._interval && (t._webAudio && r._node.gain.cancelScheduledValues(n.ctx.currentTime), clearInterval(r._interval), r._interval = null, t.volume(r._fadeTo, e), r._fadeTo = null, t._emit("fade", e)), t;
1613
+ },
1614
+ loop: function() {
1615
+ var e = this, t = arguments, n, r, i;
1616
+ if (t.length === 0) return e._loop;
1617
+ if (t.length === 1) if (typeof t[0] == "boolean") n = t[0], e._loop = n;
1618
+ else return i = e._soundById(parseInt(t[0], 10)), i ? i._loop : !1;
1619
+ else t.length === 2 && (n = t[0], r = parseInt(t[1], 10));
1620
+ for (var a = e._getSoundIds(r), o = 0; o < a.length; o++) i = e._soundById(a[o]), i && (i._loop = n, e._webAudio && i._node && i._node.bufferSource && (i._node.bufferSource.loop = n, n && (i._node.bufferSource.loopStart = i._start || 0, i._node.bufferSource.loopEnd = i._stop, e.playing(a[o]) && (e.pause(a[o], !0), e.play(a[o], !0)))));
1621
+ return e;
1622
+ },
1623
+ rate: function() {
1624
+ var e = this, t = arguments, r, i;
1625
+ t.length === 0 ? i = e._sounds[0]._id : t.length === 1 ? e._getSoundIds().indexOf(t[0]) >= 0 ? i = parseInt(t[0], 10) : r = parseFloat(t[0]) : t.length === 2 && (r = parseFloat(t[0]), i = parseInt(t[1], 10));
1626
+ var a;
1627
+ if (typeof r == "number") {
1628
+ if (e._state !== "loaded" || e._playLock) return e._queue.push({
1629
+ event: "rate",
1630
+ action: function() {
1631
+ e.rate.apply(e, t);
1632
+ }
1633
+ }), e;
1634
+ i === void 0 && (e._rate = r), i = e._getSoundIds(i);
1635
+ for (var o = 0; o < i.length; o++) if (a = e._soundById(i[o]), a) {
1636
+ e.playing(i[o]) && (a._rateSeek = e.seek(i[o]), a._playStart = e._webAudio ? n.ctx.currentTime : a._playStart), a._rate = r, e._webAudio && a._node && a._node.bufferSource ? a._node.bufferSource.playbackRate.setValueAtTime(r, n.ctx.currentTime) : a._node && (a._node.playbackRate = r);
1637
+ var s = e.seek(i[o]), c = ((e._sprite[a._sprite][0] + e._sprite[a._sprite][1]) / 1e3 - s) * 1e3 / Math.abs(a._rate);
1638
+ (e._endTimers[i[o]] || !a._paused) && (e._clearTimer(i[o]), e._endTimers[i[o]] = setTimeout(e._ended.bind(e, a), c)), e._emit("rate", a._id);
1639
+ }
1640
+ } else return a = e._soundById(i), a ? a._rate : e._rate;
1641
+ return e;
1642
+ },
1643
+ seek: function() {
1644
+ var e = this, t = arguments, r, i;
1645
+ if (t.length === 0 ? e._sounds.length && (i = e._sounds[0]._id) : t.length === 1 ? e._getSoundIds().indexOf(t[0]) >= 0 ? i = parseInt(t[0], 10) : e._sounds.length && (i = e._sounds[0]._id, r = parseFloat(t[0])) : t.length === 2 && (r = parseFloat(t[0]), i = parseInt(t[1], 10)), i === void 0) return 0;
1646
+ if (typeof r == "number" && (e._state !== "loaded" || e._playLock)) return e._queue.push({
1647
+ event: "seek",
1648
+ action: function() {
1649
+ e.seek.apply(e, t);
1650
+ }
1651
+ }), e;
1652
+ var a = e._soundById(i);
1653
+ if (a) if (typeof r == "number" && r >= 0) {
1654
+ var o = e.playing(i);
1655
+ o && e.pause(i, !0), a._seek = r, a._ended = !1, e._clearTimer(i), !e._webAudio && a._node && !isNaN(a._node.duration) && (a._node.currentTime = r);
1656
+ var s = function() {
1657
+ o && e.play(i, !0), e._emit("seek", i);
1658
+ };
1659
+ if (o && !e._webAudio) {
1660
+ var c = function() {
1661
+ e._playLock ? setTimeout(c, 0) : s();
1662
+ };
1663
+ setTimeout(c, 0);
1664
+ } else s();
1665
+ } else if (e._webAudio) {
1666
+ var l = e.playing(i) ? n.ctx.currentTime - a._playStart : 0, u = a._rateSeek ? a._rateSeek - a._seek : 0;
1667
+ return a._seek + (u + l * Math.abs(a._rate));
1668
+ } else return a._node.currentTime;
1669
+ return e;
1670
+ },
1671
+ playing: function(e) {
1672
+ var t = this;
1673
+ if (typeof e == "number") {
1674
+ var n = t._soundById(e);
1675
+ return n ? !n._paused : !1;
1676
+ }
1677
+ for (var r = 0; r < t._sounds.length; r++) if (!t._sounds[r]._paused) return !0;
1678
+ return !1;
1679
+ },
1680
+ duration: function(e) {
1681
+ var t = this, n = t._duration, r = t._soundById(e);
1682
+ return r && (n = t._sprite[r._sprite][1] / 1e3), n;
1683
+ },
1684
+ state: function() {
1685
+ return this._state;
1686
+ },
1687
+ unload: function() {
1688
+ for (var e = this, t = e._sounds, r = 0; r < t.length; r++) t[r]._paused || e.stop(t[r]._id), e._webAudio || (e._clearSound(t[r]._node), t[r]._node.removeEventListener("error", t[r]._errorFn, !1), t[r]._node.removeEventListener(n._canPlayEvent, t[r]._loadFn, !1), t[r]._node.removeEventListener("ended", t[r]._endFn, !1), n._releaseHtml5Audio(t[r]._node)), delete t[r]._node, e._clearTimer(t[r]._id);
1689
+ var i = n._howls.indexOf(e);
1690
+ i >= 0 && n._howls.splice(i, 1);
1691
+ var o = !0;
1692
+ for (r = 0; r < n._howls.length; r++) if (n._howls[r]._src === e._src || e._src.indexOf(n._howls[r]._src) >= 0) {
1693
+ o = !1;
1694
+ break;
1695
+ }
1696
+ return a && o && delete a[e._src], n.noAudio = !1, e._state = "unloaded", e._sounds = [], e = null, null;
1697
+ },
1698
+ on: function(e, t, n, r) {
1699
+ var i = this, a = i["_on" + e];
1700
+ return typeof t == "function" && a.push(r ? {
1701
+ id: n,
1702
+ fn: t,
1703
+ once: r
1704
+ } : {
1705
+ id: n,
1706
+ fn: t
1707
+ }), i;
1708
+ },
1709
+ off: function(e, t, n) {
1710
+ var r = this, i = r["_on" + e], a = 0;
1711
+ if (typeof t == "number" && (n = t, t = null), t || n) for (a = 0; a < i.length; a++) {
1712
+ var o = n === i[a].id;
1713
+ if (t === i[a].fn && o || !t && o) {
1714
+ i.splice(a, 1);
1715
+ break;
1716
+ }
1717
+ }
1718
+ else if (e) r["_on" + e] = [];
1719
+ else {
1720
+ var s = Object.keys(r);
1721
+ for (a = 0; a < s.length; a++) s[a].indexOf("_on") === 0 && Array.isArray(r[s[a]]) && (r[s[a]] = []);
1722
+ }
1723
+ return r;
1724
+ },
1725
+ once: function(e, t, n) {
1726
+ var r = this;
1727
+ return r.on(e, t, n, 1), r;
1728
+ },
1729
+ _emit: function(e, t, n) {
1730
+ for (var r = this, i = r["_on" + e], a = i.length - 1; a >= 0; a--) (!i[a].id || i[a].id === t || e === "load") && (setTimeout(function(e) {
1731
+ e.call(this, t, n);
1732
+ }.bind(r, i[a].fn), 0), i[a].once && r.off(e, i[a].fn, i[a].id));
1733
+ return r._loadQueue(e), r;
1734
+ },
1735
+ _loadQueue: function(e) {
1736
+ var t = this;
1737
+ if (t._queue.length > 0) {
1738
+ var n = t._queue[0];
1739
+ n.event === e && (t._queue.shift(), t._loadQueue()), e || n.action();
1740
+ }
1741
+ return t;
1742
+ },
1743
+ _ended: function(e) {
1744
+ var t = this, r = e._sprite;
1745
+ if (!t._webAudio && e._node && !e._node.paused && !e._node.ended && e._node.currentTime < e._stop) return setTimeout(t._ended.bind(t, e), 100), t;
1746
+ var i = !!(e._loop || t._sprite[r][2]);
1747
+ if (t._emit("end", e._id), !t._webAudio && i && t.stop(e._id, !0).play(e._id), t._webAudio && i) {
1748
+ t._emit("play", e._id), e._seek = e._start || 0, e._rateSeek = 0, e._playStart = n.ctx.currentTime;
1749
+ var a = (e._stop - e._start) * 1e3 / Math.abs(e._rate);
1750
+ t._endTimers[e._id] = setTimeout(t._ended.bind(t, e), a);
1751
+ }
1752
+ return t._webAudio && !i && (e._paused = !0, e._ended = !0, e._seek = e._start || 0, e._rateSeek = 0, t._clearTimer(e._id), t._cleanBuffer(e._node), n._autoSuspend()), !t._webAudio && !i && t.stop(e._id, !0), t;
1753
+ },
1754
+ _clearTimer: function(e) {
1755
+ var t = this;
1756
+ if (t._endTimers[e]) {
1757
+ if (typeof t._endTimers[e] != "function") clearTimeout(t._endTimers[e]);
1758
+ else {
1759
+ var n = t._soundById(e);
1760
+ n && n._node && n._node.removeEventListener("ended", t._endTimers[e], !1);
1761
+ }
1762
+ delete t._endTimers[e];
1763
+ }
1764
+ return t;
1765
+ },
1766
+ _soundById: function(e) {
1767
+ for (var t = this, n = 0; n < t._sounds.length; n++) if (e === t._sounds[n]._id) return t._sounds[n];
1768
+ return null;
1769
+ },
1770
+ _inactiveSound: function() {
1771
+ var e = this;
1772
+ e._drain();
1773
+ for (var t = 0; t < e._sounds.length; t++) if (e._sounds[t]._ended) return e._sounds[t].reset();
1774
+ return new i(e);
1775
+ },
1776
+ _drain: function() {
1777
+ var e = this, t = e._pool, n = 0, r = 0;
1778
+ if (!(e._sounds.length < t)) {
1779
+ for (r = 0; r < e._sounds.length; r++) e._sounds[r]._ended && n++;
1780
+ for (r = e._sounds.length - 1; r >= 0; r--) {
1781
+ if (n <= t) return;
1782
+ e._sounds[r]._ended && (e._webAudio && e._sounds[r]._node && e._sounds[r]._node.disconnect(0), e._sounds.splice(r, 1), n--);
1783
+ }
1784
+ }
1785
+ },
1786
+ _getSoundIds: function(e) {
1787
+ var t = this;
1788
+ if (e === void 0) {
1789
+ for (var n = [], r = 0; r < t._sounds.length; r++) n.push(t._sounds[r]._id);
1790
+ return n;
1791
+ } else return [e];
1792
+ },
1793
+ _refreshBuffer: function(e) {
1794
+ var t = this;
1795
+ return e._node.bufferSource = n.ctx.createBufferSource(), e._node.bufferSource.buffer = a[t._src], e._panner ? e._node.bufferSource.connect(e._panner) : e._node.bufferSource.connect(e._node), e._node.bufferSource.loop = e._loop, e._loop && (e._node.bufferSource.loopStart = e._start || 0, e._node.bufferSource.loopEnd = e._stop || 0), e._node.bufferSource.playbackRate.setValueAtTime(e._rate, n.ctx.currentTime), t;
1796
+ },
1797
+ _cleanBuffer: function(e) {
1798
+ var t = this, r = n._navigator && n._navigator.vendor.indexOf("Apple") >= 0;
1799
+ if (!e.bufferSource) return t;
1800
+ if (n._scratchBuffer && e.bufferSource && (e.bufferSource.onended = null, e.bufferSource.disconnect(0), r)) try {
1801
+ e.bufferSource.buffer = n._scratchBuffer;
1802
+ } catch {}
1803
+ return e.bufferSource = null, t;
1804
+ },
1805
+ _clearSound: function(e) {
1806
+ /MSIE |Trident\//.test(n._navigator && n._navigator.userAgent) || (e.src = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA");
1807
+ }
1808
+ };
1809
+ var i = function(e) {
1810
+ this._parent = e, this.init();
1811
+ };
1812
+ i.prototype = {
1813
+ init: function() {
1814
+ var e = this, t = e._parent;
1815
+ return e._muted = t._muted, e._loop = t._loop, e._volume = t._volume, e._rate = t._rate, e._seek = 0, e._paused = !0, e._ended = !0, e._sprite = "__default", e._id = ++n._counter, t._sounds.push(e), e.create(), e;
1816
+ },
1817
+ create: function() {
1818
+ var e = this, t = e._parent, r = n._muted || e._muted || e._parent._muted ? 0 : e._volume;
1819
+ return t._webAudio ? (e._node = n.ctx.createGain === void 0 ? n.ctx.createGainNode() : n.ctx.createGain(), e._node.gain.setValueAtTime(r, n.ctx.currentTime), e._node.paused = !0, e._node.connect(n.masterGain)) : n.noAudio || (e._node = n._obtainHtml5Audio(), e._errorFn = e._errorListener.bind(e), e._node.addEventListener("error", e._errorFn, !1), e._loadFn = e._loadListener.bind(e), e._node.addEventListener(n._canPlayEvent, e._loadFn, !1), e._endFn = e._endListener.bind(e), e._node.addEventListener("ended", e._endFn, !1), e._node.src = t._src, e._node.preload = t._preload === !0 ? "auto" : t._preload, e._node.volume = r * n.volume(), e._node.load()), e;
1820
+ },
1821
+ reset: function() {
1822
+ var e = this, t = e._parent;
1823
+ return e._muted = t._muted, e._loop = t._loop, e._volume = t._volume, e._rate = t._rate, e._seek = 0, e._rateSeek = 0, e._paused = !0, e._ended = !0, e._sprite = "__default", e._id = ++n._counter, e;
1824
+ },
1825
+ _errorListener: function() {
1826
+ var e = this;
1827
+ e._parent._emit("loaderror", e._id, e._node.error ? e._node.error.code : 0), e._node.removeEventListener("error", e._errorFn, !1);
1828
+ },
1829
+ _loadListener: function() {
1830
+ var e = this, t = e._parent;
1831
+ t._duration = Math.ceil(e._node.duration * 10) / 10, Object.keys(t._sprite).length === 0 && (t._sprite = { __default: [0, t._duration * 1e3] }), t._state !== "loaded" && (t._state = "loaded", t._emit("load"), t._loadQueue()), e._node.removeEventListener(n._canPlayEvent, e._loadFn, !1);
1832
+ },
1833
+ _endListener: function() {
1834
+ var e = this, t = e._parent;
1835
+ t._duration === Infinity && (t._duration = Math.ceil(e._node.duration * 10) / 10, t._sprite.__default[1] === Infinity && (t._sprite.__default[1] = t._duration * 1e3), t._ended(e)), e._node.removeEventListener("ended", e._endFn, !1);
1836
+ }
1837
+ };
1838
+ var a = {}, o = function(e) {
1839
+ var t = e._src;
1840
+ if (a[t]) {
1841
+ e._duration = a[t].duration, l(e);
1842
+ return;
1843
+ }
1844
+ if (/^data:[^;]+;base64,/.test(t)) {
1845
+ for (var n = atob(t.split(",")[1]), r = new Uint8Array(n.length), i = 0; i < n.length; ++i) r[i] = n.charCodeAt(i);
1846
+ c(r.buffer, e);
1847
+ } else {
1848
+ var o = new XMLHttpRequest();
1849
+ o.open(e._xhr.method, t, !0), o.withCredentials = e._xhr.withCredentials, o.responseType = "arraybuffer", e._xhr.headers && Object.keys(e._xhr.headers).forEach(function(t) {
1850
+ o.setRequestHeader(t, e._xhr.headers[t]);
1851
+ }), o.onload = function() {
1852
+ var t = (o.status + "")[0];
1853
+ if (t !== "0" && t !== "2" && t !== "3") {
1854
+ e._emit("loaderror", null, "Failed loading audio file with status: " + o.status + ".");
1855
+ return;
1856
+ }
1857
+ c(o.response, e);
1858
+ }, o.onerror = function() {
1859
+ e._webAudio && (e._html5 = !0, e._webAudio = !1, e._sounds = [], delete a[t], e.load());
1860
+ }, s(o);
1861
+ }
1862
+ }, s = function(e) {
1863
+ try {
1864
+ e.send();
1865
+ } catch {
1866
+ e.onerror();
1867
+ }
1868
+ }, c = function(e, t) {
1869
+ var r = function() {
1870
+ t._emit("loaderror", null, "Decoding audio data failed.");
1871
+ }, i = function(e) {
1872
+ e && t._sounds.length > 0 ? (a[t._src] = e, l(t, e)) : r();
1873
+ };
1874
+ typeof Promise < "u" && n.ctx.decodeAudioData.length === 1 ? n.ctx.decodeAudioData(e).then(i).catch(r) : n.ctx.decodeAudioData(e, i, r);
1875
+ }, l = function(e, t) {
1876
+ t && !e._duration && (e._duration = t.duration), Object.keys(e._sprite).length === 0 && (e._sprite = { __default: [0, e._duration * 1e3] }), e._state !== "loaded" && (e._state = "loaded", e._emit("load"), e._loadQueue());
1877
+ }, u = function() {
1878
+ if (n.usingWebAudio) {
1879
+ try {
1880
+ typeof AudioContext < "u" ? n.ctx = new AudioContext() : typeof webkitAudioContext < "u" ? n.ctx = new webkitAudioContext() : n.usingWebAudio = !1;
1881
+ } catch {
1882
+ n.usingWebAudio = !1;
1883
+ }
1884
+ n.ctx || (n.usingWebAudio = !1);
1885
+ var e = /iP(hone|od|ad)/.test(n._navigator && n._navigator.platform), t = n._navigator && n._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/), r = t ? parseInt(t[1], 10) : null;
1886
+ if (e && r && r < 9) {
1887
+ var i = /safari/.test(n._navigator && n._navigator.userAgent.toLowerCase());
1888
+ n._navigator && !i && (n.usingWebAudio = !1);
1889
+ }
1890
+ n.usingWebAudio && (n.masterGain = n.ctx.createGain === void 0 ? n.ctx.createGainNode() : n.ctx.createGain(), n.masterGain.gain.setValueAtTime(n._muted ? 0 : n._volume, n.ctx.currentTime), n.masterGain.connect(n.ctx.destination)), n._setup();
1891
+ }
1892
+ };
1893
+ typeof define == "function" && define.amd && define([], function() {
1894
+ return {
1895
+ Howler: n,
1896
+ Howl: r
1897
+ };
1898
+ }), e !== void 0 && (e.Howler = n, e.Howl = r), typeof global < "u" ? (global.HowlerGlobal = t, global.Howler = n, global.Howl = r, global.Sound = i) : typeof window < "u" && (window.HowlerGlobal = t, window.Howler = n, window.Howl = r, window.Sound = i);
1899
+ })();
1900
+ })))(), Wn = {}, Gn = {};
1901
+ function Kn(e, t) {
1902
+ e ? t[e] && t[e].stop() : Object.keys(t).forEach((e) => {
1903
+ e && e.fade && e.fade(void 0, 0, 1), t[e].stop();
1904
+ });
1905
+ }
1906
+ function qn(e) {
1907
+ Jn(e.mute), Xn(e.volume);
1908
+ }
1909
+ function Jn(e = !0) {
1910
+ X.Howler.mute(e);
1911
+ }
1912
+ function Yn() {
1913
+ return X.Howler.muted;
1914
+ }
1915
+ function Xn(e) {
1916
+ X.Howler.volume(e / 100);
1917
+ }
1918
+ function Zn() {
1919
+ return X.Howler.volume * 100;
1920
+ }
1921
+ function Qn(e) {
1922
+ Wn[e] || (Wn[e] = new X.Howl({ src: [e] })), Wn[e].play();
1923
+ }
1924
+ function $n(e) {
1925
+ Kn(e, Wn);
1926
+ }
1927
+ function er(e, t = !0) {
1928
+ Gn[e] || (Gn[e] = new X.Howl({
1929
+ src: [e],
1930
+ html5: !0,
1931
+ loop: t
1932
+ })), Gn[e].play();
1933
+ }
1934
+ function tr(e) {
1935
+ Kn(e, Gn);
1936
+ }
1937
+ var nr = {
1938
+ init: qn,
1939
+ mute: Jn,
1940
+ isMuted: Yn,
1941
+ setVolume: Xn,
1942
+ getVolume: Zn,
1943
+ playSound: Qn,
1944
+ stopSound: $n,
1945
+ playMusic: er,
1946
+ stopMusic: tr
1947
+ }, rr = Symbol("clean"), Z = [], Q = 0, ir = 4, ar = 0, or = /* @__NO_SIDE_EFFECTS__ */ (e) => {
1948
+ let t = [], n = {
1949
+ get() {
1950
+ return n.lc || n.listen(() => {})(), n.value;
1951
+ },
1952
+ init: e,
1953
+ lc: 0,
1954
+ listen(e) {
1955
+ return n.lc = t.push(e), () => {
1956
+ for (let t = Q + ir; t < Z.length;) Z[t] === e ? Z.splice(t, ir) : t += ir;
1957
+ let r = t.indexOf(e);
1958
+ ~r && (t.splice(r, 1), --n.lc || n.off());
1959
+ };
1960
+ },
1961
+ notify(e, r) {
1962
+ ar++;
1963
+ let i = !Z.length;
1964
+ for (let i of t) Z.push(i, n.value, e, r);
1965
+ if (i) {
1966
+ for (Q = 0; Q < Z.length; Q += ir) Z[Q](Z[Q + 1], Z[Q + 2], Z[Q + 3]);
1967
+ Z.length = 0;
1968
+ }
1969
+ },
1970
+ off() {},
1971
+ set(e) {
1972
+ let t = n.value;
1973
+ t !== e && (n.value = e, n.notify(t));
1974
+ },
1975
+ subscribe(e) {
1976
+ let t = n.listen(e);
1977
+ return e(n.value), t;
1978
+ },
1979
+ value: e
1980
+ };
1981
+ return process.env.NODE_ENV !== "production" && (n[rr] = () => {
1982
+ t = [], n.lc = 0, n.off();
1983
+ }), n;
1984
+ }, $ = /* @__PURE__ */ /* @__NO_SIDE_EFFECTS__ */ ((e = {}) => {
1985
+ let t = /* @__PURE__ */ or(e);
1986
+ return t.setKey = function(e, n) {
1987
+ let r = t.value;
1988
+ n === void 0 && e in t.value ? (t.value = { ...t.value }, delete t.value[e], t.notify(r, e)) : t.value[e] !== n && (t.value = {
1989
+ ...t.value,
1990
+ [e]: n
1991
+ }, t.notify(r, e));
1992
+ }, t;
1993
+ })({
1994
+ settings: {},
1995
+ game: {},
1996
+ metadata: {},
1997
+ scenes: [],
1998
+ vars: {}
2484
1999
  });
2485
- function Aa() {
2486
- return T;
2487
- }
2488
- function Sa() {
2489
- return T.get();
2490
- }
2491
- const xa = (t, n) => (T.setKey(t, n), T.get()), ka = (t) => (T.setKey(t, !T.get()[t]), T.get()), Ta = (t, n) => (T.setKey(t, [...T.get()[t], n]), T.get()), Ea = (t, n, r) => (T.setKey(t, { ...T.get()[t], [n]: r }), T.get()), Ia = (t, n) => (T.setKey(t, { ...T.get()[t], [n]: !T.get()[t][n] }), T.get()), Ca = (t, n, r) => (T.setKey(t, { ...T.get()[t], [n]: [...T.get()[t][n], r] }), T.get()), Oa = {
2492
- store: Aa,
2493
- get: Sa,
2494
- setKey: xa,
2495
- toggleKey: ka,
2496
- appendKey: Ta,
2497
- setSubkey: Ea,
2498
- toggleSubkey: Ia,
2499
- appendSubkey: Ca
2000
+ function sr() {
2001
+ return $;
2002
+ }
2003
+ function cr() {
2004
+ return $.get();
2005
+ }
2006
+ var lr = {
2007
+ store: sr,
2008
+ get: cr,
2009
+ setKey: (e, t) => ($.setKey(e, t), $.get()),
2010
+ toggleKey: (e) => ($.setKey(e, !$.get()[e]), $.get()),
2011
+ appendKey: (e, t) => ($.setKey(e, [...$.get()[e], t]), $.get()),
2012
+ setSubkey: (e, t, n) => ($.setKey(e, {
2013
+ ...$.get()[e],
2014
+ [t]: n
2015
+ }), $.get()),
2016
+ toggleSubkey: (e, t) => ($.setKey(e, {
2017
+ ...$.get()[e],
2018
+ [t]: !$.get()[e][t]
2019
+ }), $.get()),
2020
+ appendSubkey: (e, t, n) => ($.setKey(e, {
2021
+ ...$.get()[e],
2022
+ [t]: [...$.get()[e][t], n]
2023
+ }), $.get())
2500
2024
  };
2501
- async function Pa(t, n) {
2502
- if (t && !document.fullscreenElement)
2503
- try {
2504
- await document.documentElement.requestFullscreen();
2505
- } catch {
2506
- n(!1);
2507
- }
2508
- else document.fullscreenElement && document.exitFullscreen && document.exitFullscreen();
2509
- }
2510
- function $a(t) {
2511
- document.title = t;
2512
- }
2513
- const La = {
2514
- setFullscreen: Pa,
2515
- setTitle: $a
2025
+ //#endregion
2026
+ //#region src/interfaces/platform-web.js
2027
+ async function ur(e, t) {
2028
+ if (e && !document.fullscreenElement) try {
2029
+ await document.documentElement.requestFullscreen();
2030
+ } catch {
2031
+ t(!1);
2032
+ }
2033
+ else document.fullscreenElement && document.exitFullscreen && document.exitFullscreen();
2034
+ }
2035
+ function dr(e) {
2036
+ document.title = e;
2037
+ }
2038
+ var fr = {
2039
+ setFullscreen: ur,
2040
+ setTitle: dr
2516
2041
  };
2517
- async function Fa(t) {
2518
- t ? await window.Neutralino.window.setFullScreen() : await window.Neutralino.window.exitFullScreen();
2042
+ //#endregion
2043
+ //#region src/interfaces/platform-neutralino.js
2044
+ async function pr(e) {
2045
+ e ? await window.Neutralino.window.setFullScreen() : await window.Neutralino.window.exitFullScreen();
2519
2046
  }
2520
- async function Ma(t) {
2521
- await window.Neutralino.window.setTitle(t);
2047
+ async function mr(e) {
2048
+ await window.Neutralino.window.setTitle(e);
2522
2049
  }
2523
- async function Ba() {
2524
- await window.Neutralino.app.exit();
2050
+ async function hr() {
2051
+ await window.Neutralino.app.exit();
2525
2052
  }
2526
- const Na = {
2527
- setFullscreen: Fa,
2528
- setTitle: Ma,
2529
- exitApp: Ba
2053
+ var gr = {
2054
+ setFullscreen: pr,
2055
+ setTitle: mr,
2056
+ exitApp: hr
2530
2057
  };
2531
- _r.defineInterfaces({
2532
- loader: Nr,
2533
- persistent: window.Neutralino ? fa : jr,
2534
- sound: ga,
2535
- state: Oa,
2536
- platform: window.Neutralino ? Na : La
2058
+ //#endregion
2059
+ //#region src/index.js
2060
+ St.defineInterfaces({
2061
+ loader: fn,
2062
+ persistent: window.Neutralino ? Un : Dn,
2063
+ sound: nr,
2064
+ state: lr,
2065
+ platform: window.Neutralino ? gr : fr
2537
2066
  });
2538
- export {
2539
- _r as default
2540
- };
2067
+ var _r = St;
2068
+ //#endregion
2069
+ export { _r as default };