@atrament/web 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,2540 @@
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: {}
59
+ };
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
303
+ };
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;
621
+ }
622
+ 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
667
+ };
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;
990
+ };
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);
1000
+ }
1001
+ var Je = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), xr = 0;
1002
+ 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
+ }
1013
+ };
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();
1037
+ };
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 = () => {
1096
+ };
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: {}
2484
+ });
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
2500
+ };
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
2516
+ };
2517
+ async function Fa(t) {
2518
+ t ? await window.Neutralino.window.setFullScreen() : await window.Neutralino.window.exitFullScreen();
2519
+ }
2520
+ async function Ma(t) {
2521
+ await window.Neutralino.window.setTitle(t);
2522
+ }
2523
+ async function Ba() {
2524
+ await window.Neutralino.app.exit();
2525
+ }
2526
+ const Na = {
2527
+ setFullscreen: Fa,
2528
+ setTitle: Ma,
2529
+ exitApp: Ba
2530
+ };
2531
+ _r.defineInterfaces({
2532
+ loader: Nr,
2533
+ persistent: window.Neutralino ? fa : jr,
2534
+ sound: ga,
2535
+ state: Oa,
2536
+ platform: window.Neutralino ? Na : La
2537
+ });
2538
+ export {
2539
+ _r as default
2540
+ };