@eatsjobs/howler-es 3.0.0-alpha.1 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -4
- package/dist/howler.core.d.ts +34 -1
- package/dist/howler.core.d.ts.map +1 -1
- package/dist/howler.core.js +1 -1
- package/dist/howler.core.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/plugins/spatial.js +1 -1
- package/dist/plugins/spatial.js.map +1 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -247,9 +247,13 @@ Adds 3D spatial audio and stereo panning support:
|
|
|
247
247
|
**TypeScript/ES Modules:**
|
|
248
248
|
|
|
249
249
|
```typescript
|
|
250
|
-
import { Howler, Howl } from 'howler';
|
|
251
|
-
import {
|
|
252
|
-
|
|
250
|
+
import { Howler, Howl } from '@eatsjobs/howler-es';
|
|
251
|
+
import {
|
|
252
|
+
SpatialAudioPlugin,
|
|
253
|
+
type SpatialHowler,
|
|
254
|
+
type SpatialHowl,
|
|
255
|
+
type SpatialHowlOptions
|
|
256
|
+
} from '@eatsjobs/howler-es/plugins/spatial';
|
|
253
257
|
|
|
254
258
|
// Register the plugin
|
|
255
259
|
Howler.addPlugin(new SpatialAudioPlugin());
|
|
@@ -735,7 +739,7 @@ Each HTML5 Audio object must be unlocked individually, so we keep a global pool
|
|
|
735
739
|
|
|
736
740
|
#### autoSuspend `Boolean` `true`
|
|
737
741
|
|
|
738
|
-
Automatically suspends the Web Audio AudioContext after
|
|
742
|
+
Automatically suspends the Web Audio AudioContext after 15 seconds of inactivity to decrease processing and energy usage. Automatically resumes upon new playback. Set this property to `false` to disable this behavior.
|
|
739
743
|
|
|
740
744
|
#### ctx `Boolean` *`Web Audio Only`*
|
|
741
745
|
|
|
@@ -775,6 +779,40 @@ Check supported audio codecs. Returns `true` if the codec is supported in the cu
|
|
|
775
779
|
|
|
776
780
|
Unload and destroy all currently loaded Howl objects. This will immediately stop all sounds and remove them from cache.
|
|
777
781
|
|
|
782
|
+
### Type Guards
|
|
783
|
+
|
|
784
|
+
#### isSpatialAudio(sound)
|
|
785
|
+
|
|
786
|
+
A TypeScript type guard function to check if a sound or Howl instance has spatial audio enabled. This is useful when working with spatial audio to safely access panner node properties without type assertions.
|
|
787
|
+
|
|
788
|
+
Returns `true` if the object has a panner node (indicating spatial audio is active), allowing TypeScript to narrow the type for type-safe access to spatial properties.
|
|
789
|
+
|
|
790
|
+
* **sound**: `unknown` The sound object to check (Sound or Howl instance).
|
|
791
|
+
* **returns**: `boolean` True if the sound has spatial audio enabled.
|
|
792
|
+
|
|
793
|
+
```typescript
|
|
794
|
+
import { Howl, isSpatialAudio } from '@eatsjobs/howler-es';
|
|
795
|
+
|
|
796
|
+
const sound = new Howl({
|
|
797
|
+
src: ['sound.mp3'],
|
|
798
|
+
pos: [10, 20, 30], // Enable spatial audio
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
// Type-safe check for spatial audio
|
|
802
|
+
if (isSpatialAudio(sound)) {
|
|
803
|
+
// sound._panner is now guaranteed to be PannerNode | StereoPannerNode
|
|
804
|
+
sound._panner.disconnect();
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// Can also be used to filter arrays
|
|
808
|
+
const allSounds = [sound1, sound2, sound3];
|
|
809
|
+
const spatialSounds = allSounds.filter(isSpatialAudio);
|
|
810
|
+
spatialSounds.forEach(s => {
|
|
811
|
+
// All sounds in this array have spatial audio enabled
|
|
812
|
+
console.log(s._panner);
|
|
813
|
+
});
|
|
814
|
+
```
|
|
815
|
+
|
|
778
816
|
## Plugin: Spatial
|
|
779
817
|
|
|
780
818
|
### Options
|
package/dist/howler.core.d.ts
CHANGED
|
@@ -131,6 +131,36 @@ interface GainNodeWithBufferSource extends GainNode {
|
|
|
131
131
|
/** The AudioBufferSourceNode connected to this gain node. */
|
|
132
132
|
bufferSource?: AudioBufferSourceNodeWithLegacy;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Type guard to check if a sound or Howl instance has spatial audio enabled.
|
|
136
|
+
*
|
|
137
|
+
* This function verifies that a sound has spatial audio properties (panner node)
|
|
138
|
+
* and narrows the type to allow safe access to spatial audio-specific properties.
|
|
139
|
+
* Useful for checking if spatial audio has been initialized on a sound before
|
|
140
|
+
* accessing or manipulating panner nodes.
|
|
141
|
+
*
|
|
142
|
+
* @param sound - The sound object to check (Sound or Howl instance)
|
|
143
|
+
* @returns True if the object has a panner node for spatial audio
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Check before accessing panner
|
|
148
|
+
* if (isSpatialAudio(sound)) {
|
|
149
|
+
* sound._panner.disconnect();
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* // Use in type-safe code
|
|
153
|
+
* const sounds = getAllSounds();
|
|
154
|
+
* const spatialSounds = sounds.filter(isSpatialAudio);
|
|
155
|
+
* spatialSounds.forEach(sound => {
|
|
156
|
+
* // sound._panner is guaranteed to exist here
|
|
157
|
+
* configurePanner(sound._panner);
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare function isSpatialAudio(sound: unknown): sound is Record<string, unknown> & {
|
|
162
|
+
_panner: PannerNode | StereoPannerNode;
|
|
163
|
+
};
|
|
134
164
|
//#endregion
|
|
135
165
|
//#region src/sound.d.ts
|
|
136
166
|
declare class Sound {
|
|
@@ -386,6 +416,9 @@ declare class HowlerGlobal {
|
|
|
386
416
|
autoUnlock: boolean;
|
|
387
417
|
state: string;
|
|
388
418
|
_audioUnlocked: boolean;
|
|
419
|
+
_isUnlocking: boolean;
|
|
420
|
+
_unlockedListeners: ((event: Event) => void) | null;
|
|
421
|
+
_unlockTimeoutId: ReturnType<typeof setTimeout> | null;
|
|
389
422
|
_scratchBuffer: AudioBuffer | null;
|
|
390
423
|
_suspendTimer: ReturnType<typeof setTimeout> | null;
|
|
391
424
|
_resumeAfterSuspend?: boolean;
|
|
@@ -428,5 +461,5 @@ declare class HowlerGlobal {
|
|
|
428
461
|
//#region src/howler.core.d.ts
|
|
429
462
|
declare const Howler: HowlerGlobal;
|
|
430
463
|
//#endregion
|
|
431
|
-
export { PluginManager as a, Sound as c, PluginHooks as i, HowlOptions as l, HowlerGlobal as n, globalPluginManager as o, HowlerPlugin as r, Howl as s, Howler as t };
|
|
464
|
+
export { PluginManager as a, Sound as c, PluginHooks as i, HowlOptions as l, HowlerGlobal as n, globalPluginManager as o, HowlerPlugin as r, Howl as s, Howler as t, isSpatialAudio as u };
|
|
432
465
|
//# sourceMappingURL=howler.core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"howler.core.d.ts","names":[],"sources":["../src/types.ts","../src/sound.ts","../src/howl.ts","../src/plugins/plugin.ts","../src/howler-global.ts","../src/howler.core.ts"],"mappings":";;;AAaA;;;;;;;;;;;;UAAiB,WAAA;EAoBhB;EAlBA,GAAA;EAoBA;EAlBA,QAAA;EAsBC;EApBD,MAAA;EAsBW;EApBX,KAAA;EAyBA;EAvBA,IAAA;EA2BA;EAzBA,IAAA;EA2Be;EAzBf,IAAA;EA2BA;EAzBA,OAAA;EAyB2B;EAvB3B,IAAA;EA2BA;EAzBA,MAAA,GAAS,MAAA;EA6BT;EA3BA,MAAA;EA+BA;EA7BA,GAAA;IAiCA,+CA/BC,MAAA,WA+BO;IA7BP,OAAA,GAAU,MAAA,kBAqCkB;IAnC5B,eAAA;EAAA;EAqCD;EAlCA,KAAA;EAoCQ;EAlCR,MAAA;EAoCI;EAlCJ,MAAA;EA0CgB;EAxChB,WAAA,IAAe,EAAA,UAAY,GAAA;;EAE3B,WAAA,IAAe,EAAA,UAAY,GAAA;EA0CrB;EAxCN,OAAA;EAgD6C;EA9C7C,MAAA;EA8CqD;EA5CrD,MAAA;EAuDgB;EArDhB,MAAA;;EAEA,QAAA;EAoDQ;EAlDR,MAAA;EAoDA;EAlDA,MAAA;EAsDA;EApDA,QAAA;AAAA;AAwED;;;;;AAAA,UAhEiB,aAAA;EAuEyB;EArEzC,EAAA;EAqEyD;EAnEzD,EAAA,MAAQ,IAAA;EAqER;EAnEA,IAAA;AAAA
|
|
1
|
+
{"version":3,"file":"howler.core.d.ts","names":[],"sources":["../src/types.ts","../src/sound.ts","../src/howl.ts","../src/plugins/plugin.ts","../src/howler-global.ts","../src/howler.core.ts"],"mappings":";;;AAaA;;;;;;;;;;;;UAAiB,WAAA;EAoBhB;EAlBA,GAAA;EAoBA;EAlBA,QAAA;EAsBC;EApBD,MAAA;EAsBW;EApBX,KAAA;EAyBA;EAvBA,IAAA;EA2BA;EAzBA,IAAA;EA2Be;EAzBf,IAAA;EA2BA;EAzBA,OAAA;EAyB2B;EAvB3B,IAAA;EA2BA;EAzBA,MAAA,GAAS,MAAA;EA6BT;EA3BA,MAAA;EA+BA;EA7BA,GAAA;IAiCA,+CA/BC,MAAA,WA+BO;IA7BP,OAAA,GAAU,MAAA,kBAqCkB;IAnC5B,eAAA;EAAA;EAqCD;EAlCA,KAAA;EAoCQ;EAlCR,MAAA;EAoCI;EAlCJ,MAAA;EA0CgB;EAxChB,WAAA,IAAe,EAAA,UAAY,GAAA;;EAE3B,WAAA,IAAe,EAAA,UAAY,GAAA;EA0CrB;EAxCN,OAAA;EAgD6C;EA9C7C,MAAA;EA8CqD;EA5CrD,MAAA;EAuDgB;EArDhB,MAAA;;EAEA,QAAA;EAoDQ;EAlDR,MAAA;EAoDA;EAlDA,MAAA;EAsDA;EApDA,QAAA;AAAA;AAwED;;;;;AAAA,UAhEiB,aAAA;EAuEyB;EArEzC,EAAA;EAqEyD;EAnEzD,EAAA,MAAQ,IAAA;EAqER;EAnEA,IAAA;AAAA;;AAgLD;;;;UAxKiB,SAAA;EA4KM;EA1KtB,KAAA;EA0KsC;EAxKtC,MAAA;AAAA;;;;;;UAQgB,4BAAA,SAAqC,gBAAA;;EAErD,SAAA;AAAA;ACjGD;;;;;;AAAA,UD0GiB,+BAAA,SACR,IAAA,CAAK,qBAAA;EC5FK;ED8FlB,IAAA;EC1FU;ED4FV,SAAA;EC1F8B;ED4F9B,OAAA;AAAA;;;;;;UAoBgB,qBAAA,SAA8B,SAAA;;;;;;UAO9B,wBAAA,SAAiC,QAAA;EC7HjD;ED+HA,YAAA,GAAe,+BAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6GA,cAAA,CAAe,KAAA,YAAiB,KAAA,IAAS,MAAA;EAIxD,OAAA,EAAS,UAAA,GAAa,gBAAA;AAAA;;;cC/PV,KAAA;EACZ,OAAA,EAAS,IAAA;EACT,MAAA;EACA,KAAA;EACA,OAAA;EACA,KAAA;EACA,KAAA;EACA,OAAA;EACA,MAAA;EACA,OAAA;EACA,GAAA;EACA,KAAA,EAAO,4BAAA,GAA+B,wBAAA;EACtC,UAAA;EACA,SAAA;EACA,QAAA,IAAY,KAAA,EAAO,KAAA;EACnB,OAAA,IAAW,KAAA,EAAO,KAAA;EAClB,MAAA,IAAU,KAAA,EAAO,KAAA;EACjB,MAAA;EACA,KAAA;EACA,OAAA,GAAU,UAAA,GAAa,gBAAA;EACvB,OAAA;EACA,SAAA,GAAY,UAAA,QAAkB,WAAA;cAElB,IAAA,EAAM,IAAA;EAKlB,IAAA,CAAA,GAAQ,KAAA;EAwBR,MAAA,CAAA,GAAU,KAAA;EAwDV,KAAA,CAAA,GAAS,KAAA;EAkBT,cAAA,CAAA;EAUA,aAAA,CAAA;EA2BA,YAAA,CAAA;AAAA;;;cC1JK,IAAA;EACL,SAAA;EACA,OAAA;EACA,MAAA;EACA,MAAA;EACA,KAAA;EACA,KAAA;EACA,QAAA;EACA,KAAA;EACA,OAAA,EAAS,MAAA;EACT,IAAA;EACA,OAAA;EACA,IAAA;IACC,MAAA;IACA,OAAA,GAAU,WAAA;IACV,eAAA;EAAA;EAED,SAAA;EACA,MAAA;EACA,OAAA,EAAS,KAAA;EACT,UAAA,EAAY,MAAA,SAAe,UAAA,QAAkB,UAAA;EAC7C,MAAA,EAAQ,SAAA;EACR,SAAA;EACA,SAAA;EACA,MAAA,EAAQ,aAAA;EACR,OAAA,EAAS,aAAA;EACT,OAAA,EAAS,aAAA;EACT,YAAA,EAAc,aAAA;EACd,YAAA,EAAc,aAAA;EACd,QAAA,EAAU,aAAA;EACV,OAAA,EAAS,aAAA;EACT,OAAA,EAAS,aAAA;EACT,OAAA,EAAS,aAAA;EACT,SAAA,EAAW,aAAA;EACX,OAAA,EAAS,aAAA;EACT,OAAA,EAAS,aAAA;EACT,SAAA,EAAW,aAAA;EACX,SAAA,EAAW,aAAA;cAEC,CAAA,EAAG,WAAA;EAWf,IAAA,CAAK,CAAA,EAAG,WAAA,GAAc,IAAA;EAuGtB,IAAA,CAAA,GAAQ,IAAA;EA8ER,IAAA,CAAK,MAAA,oBAA0B,QAAA;EA4P/B,KAAA,CAAM,EAAA,WAAa,QAAA,aAAqB,IAAA;EAsDxC,IAAA,CAAK,EAAA,WAAa,QAAA,aAAqB,IAAA;EAyDvC,IAAA,CAAK,KAAA,WAAgB,EAAA,sBAAwB,IAAA;EAgD7C,MAAA,CAAA;EACA,MAAA,CAAO,GAAA,WAAc,IAAA;EACrB,MAAA,CAAO,GAAA,UAAa,EAAA,WAAa,IAAA;EACjC,MAAA,CAAO,GAAA,UAAa,EAAA,UAAY,QAAA,YAAoB,IAAA;EA0FpD,IAAA,CAAK,IAAA,UAAc,EAAA,UAAY,GAAA,UAAa,EAAA,YAAc,IAAA;EAuD1D,kBAAA,CACC,KAAA,EAAO,KAAA,EACP,IAAA,UACA,EAAA,UACA,GAAA,UACA,EAAA,UACA,OAAA;EA6CD,SAAA,CAAU,EAAA,WAAa,IAAA;EAoBvB,IAAA,CAAA;EACA,IAAA,CAAK,IAAA,YAAgB,IAAA;EAmDrB,IAAA,CAAA;EACA,IAAA,CAAK,IAAA,WAAe,IAAA;EACpB,IAAA,CAAK,IAAA,UAAc,EAAA,WAAa,IAAA;EAsGhC,IAAA,CAAA;EACA,IAAA,CAAK,IAAA,WAAe,IAAA;EACpB,IAAA,CAAK,IAAA,UAAc,EAAA,WAAa,IAAA;EA2GhC,OAAA,CAAQ,EAAA;EAeR,QAAA,CAAS,EAAA;EAaT,KAAA,CAAA;EAIA,MAAA,CAAA;EAmEA,EAAA,CACC,KAAA,UACA,EAAA,MAAQ,IAAA,sBACR,EAAA,WACA,IAAA,aACE,IAAA;EAYH,GAAA,CAAI,KAAA,UAAe,EAAA,OAAS,IAAA,sBAA0B,EAAA,YAAc,IAAA;EAsCpE,IAAA,CAAK,KAAA,UAAe,EAAA,MAAQ,IAAA,sBAA0B,EAAA,YAAc,IAAA;EAMpE,KAAA,CAAM,KAAA,UAAe,EAAA,kBAAoB,GAAA,YAAe,IAAA;EAuBxD,UAAA,CAAW,KAAA,YAAiB,IAAA;EAiB5B,MAAA,CAAO,KAAA,EAAO,KAAA,GAAQ,IAAA;EAwDtB,WAAA,CAAY,EAAA,WAAa,IAAA;EAiBzB,UAAA,CAAW,EAAA,WAAa,KAAA;EAUxB,cAAA,CAAA,GAAkB,KAAA;EAYlB,MAAA,CAAA;EA4CA,YAAA,CAAa,EAAA;EAab,cAAA,CAAe,KAAA,EAAO,KAAA,GAAQ,IAAA;EAkC9B,YAAA,CAAa,IAAA,QAAY,IAAA;EAqBzB,WAAA,CAAY,IAAA,EAAM,4BAAA;AAAA;;;;;;UCzgDF,WAAA;EHWhB;;;;;;EGJA,YAAA,IAAgB,MAAA,EAAQ,YAAA;EHkBxB;;;EGbA,YAAA,IAAgB,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,WAAA;EHmBrC;;;EGdA,aAAA,IAAiB,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,IAAA;EHoBtC;;;EGfD,UAAA,IAAc,IAAA,EAAM,IAAA;EHwBpB;;;EGnBA,aAAA,IAAiB,IAAA,EAAM,IAAA;AAAA;;;;;uBAOF,YAAA;EHwBrB;;;EAAA,kBGpBkB,IAAA;EH0BV;;AAQT;EARS,SGrBC,OAAA;;;;WAKA,QAAA,CAAA,GAAY,WAAA;EH4Bb;;;;EGtBR,YAAA,CAAA,CAAA;AAAA;;;;UAMgB,gBAAA;EAChB,MAAA,EAAQ,YAAA;EACR,KAAA,EAAO,WAAA;AAAA;;AH+CR;;cGzCa,aAAA;EAAA,QACJ,OAAA;EAAA,QACA,cAAA;EHwCK;;;;;EGjCb,QAAA,CAAS,MAAA,EAAQ,YAAA;EH2DD;;;;EG7BhB,UAAA,CAAW,UAAA;EHoCK;;;;EGXhB,YAAA,CAAa,UAAA;EHab;;;;AA6GD;EGjHC,iBAAA,CAAkB,MAAA,EAAQ,YAAA;;;;;EAe1B,iBAAA,CAAA,GAAqB,YAAA;EHsGiB;;;EG/FtC,UAAA,CAAA,GAAc,WAAA,SAAoB,gBAAA;EH+FlC;;;EGxFA,iBAAA,CAAkB,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,WAAA;EHwFD;;;EG7EtC,kBAAA,CAAmB,KAAA,EAAO,KAAA,EAAO,MAAA,EAAQ,IAAA;EFlL7B;;;EE6LZ,eAAA,CAAgB,IAAA,EAAM,IAAA;EFlLf;;;EE6LP,kBAAA,CAAmB,IAAA,EAAM,IAAA;EFxLR;;;EAAA,QEmMT,aAAA;AAAA;;;;cAoBI,mBAAA,EAAmB,aAAA;;;cCpOnB,YAAA;EACZ,QAAA;EACA,eAAA,EAAiB,gBAAA;EACjB,aAAA;EACA,OAAA,EAAS,MAAA;EACT,MAAA,EAAQ,IAAA;EACR,MAAA;EACA,OAAA;EACA,aAAA;EACA,UAAA,EAAY,qBAAA;EACZ,UAAA,EAAY,QAAA;EACZ,OAAA;EACA,aAAA;EACA,WAAA;EACA,GAAA,EAAK,YAAA;EACL,UAAA;EACA,KAAA;EACA,cAAA;EACA,YAAA;EACA,kBAAA,IAAsB,KAAA,EAAO,KAAA;EAC7B,gBAAA,EAAkB,UAAA,QAAkB,UAAA;EACpC,cAAA,EAAgB,WAAA;EAChB,aAAA,EAAe,UAAA,QAAkB,UAAA;EACjC,mBAAA;EACA,eAAA;;EA+BA,MAAA,CAAO,GAAA,qBAAwB,YAAA;EAsC/B,IAAA,CAAK,KAAA,YAAiB,YAAA;EA6BtB,IAAA,CAAA,GAAQ,YAAA;EAQR,MAAA,CAAA,GAAU,YAAA;EAkBV,MAAA,CAAO,GAAA;EJlGP;;;;;;EI4GA,SAAA,CAAU,MAAA,EAAQ,YAAA,GAAe,YAAA;EJ5FjB;;;;;;EIuGhB,YAAA,CAAa,MAAA,EAAQ,YAAA,GAAe,YAAA;EJjGpC;;;AAQD;;EImGC,SAAA,CAAU,UAAA;EAIV,MAAA,CAAA,GAAU,YAAA;EAiCV,YAAA,CAAA,GAAgB,YAAA;EAqEhB,YAAA,CAAA;EAwGA,iBAAA,CAAA,GAAqB,4BAAA;EAiCrB,kBAAA,CAAmB,KAAA,EAAO,4BAAA,GAA+B,YAAA;EAQzD,YAAA,CAAA;EA6CA,WAAA,CAAA;AAAA;;;cCjeK,MAAA,EAAM,YAAA"}
|
package/dist/howler.core.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
// https://github.com/eatsjobs/howler.es
|
|
3
3
|
// (c) 2013-2025, James Simpson of GoldFire Studios
|
|
4
4
|
// MIT License
|
|
5
|
-
const cache={};function getUserAgent(e){return(e==null?void 0:e.userAgent)||``}function getPlatform(e){return(e==null?void 0:e.platform)||``}function isIOS(e){return/iP(hone|od|ad)/.test(getPlatform(e))}function getIOSVersion(e){var t;if(!isIOS(e))return null;let n=e==null||(t=e.appVersion)==null?void 0:t.match(/OS (\d+)_(\d+)_?(\d+)?/);return n?parseInt(n[1],10):null}function isSafari(e){let n=getUserAgent(e);return n.indexOf(`Safari`)!==-1&&n.indexOf(`Chrome`)===-1}function isAppleVendor(e){var t,n;return((t=e==null||(n=e.vendor)==null?void 0:n.indexOf(`Apple`))==null?-1:t)>=0}const setupAudioContext=()=>{if(!Howler.usingWebAudio)return;try{window.AudioContext===void 0?Howler.usingWebAudio=!1:Howler.ctx=new window.AudioContext}catch(e){Howler.usingWebAudio=!1}Howler.ctx||(Howler.usingWebAudio=!1);let e=isIOS(Howler._navigator),t=getIOSVersion(Howler._navigator);if(e&&t&&t<9){let e=isSafari(Howler._navigator);Howler._navigator&&!e&&(Howler.usingWebAudio=!1)}Howler.usingWebAudio&&Howler.ctx&&(Howler.masterGain=Howler.ctx.createGain(),Howler.masterGain&&(Howler.masterGain.gain.setValueAtTime(Howler._muted?0:Howler._volume,Howler.ctx.currentTime),Howler.masterGain.connect(Howler.ctx.destination))),Howler._setup()};var HowlerPlugin=class{},PluginManager=class{constructor(){this.plugins=new Map,this.howlerInstance=null}register(e){if(this.plugins.has(e.name))throw Error(`Plugin "${e.name}" is already registered`);let t=e.getHooks(),n={plugin:e,hooks:t};if(this.plugins.set(e.name,n),this.howlerInstance&&t.onHowlerInit)try{t.onHowlerInit(this.howlerInstance)}catch(t){console.error(`Error during onHowlerInit for plugin "${e.name}":`,t)}}unregister(e){let t=this.plugins.get(e);if(!t)throw Error(`Plugin "${e}" is not registered`);if(t.plugin.onUnregister)try{t.plugin.onUnregister()}catch(t){console.error(`Error during onUnregister for plugin "${e}":`,t)}this.plugins.delete(e)}isRegistered(e){return this.plugins.has(e)}setHowlerInstance(e){this.howlerInstance=e,this._executeHooks(`onHowlerInit`,t=>{t.onHowlerInit&&t.onHowlerInit(e)})}getHowlerInstance(){return this.howlerInstance}getPlugins(){return new Map(this.plugins)}executeHowlCreate(e,t){this._executeHooks(`onHowlCreate`,n=>{n.onHowlCreate&&n.onHowlCreate(e,t)})}executeSoundCreate(e,t){this._executeHooks(`onSoundCreate`,n=>{n.onSoundCreate&&n.onSoundCreate(e,t)})}executeHowlLoad(e){this._executeHooks(`onHowlLoad`,t=>{t.onHowlLoad&&t.onHowlLoad(e)})}executeHowlDestroy(e){this._executeHooks(`onHowlDestroy`,t=>{t.onHowlDestroy&&t.onHowlDestroy(e)})}_executeHooks(e,t){for(let[n,r]of this.plugins)try{t(r.hooks)}catch(t){console.error(`Error in hook "${e}" for plugin "${n}":`,t)}}};const globalPluginManager=new PluginManager,loadBuffer=t=>{let n=t._src;if(cache[n]){t._duration=cache[n].duration,loadSound(t);return}if(/^data:[^;]+;base64,/.test(n)){let e=atob(n.split(`,`)[1]),r=new Uint8Array(e.length);for(let t=0;t<e.length;++t)r[t]=e.charCodeAt(t);decodeAudioData(r.buffer,t)}else{let r={method:t._xhr.method,credentials:t._xhr.withCredentials?`include`:`same-origin`};t._xhr.headers&&(r.headers=t._xhr.headers),fetch(n,r).then(e=>{if(!e.ok){t._emit(`loaderror`,null,`Failed loading audio file with status: ${e.status}.`);return}return e.arrayBuffer()}).then(e=>{e&&decodeAudioData(e,t)}).catch(()=>{t._webAudio&&(t._html5=!0,t._webAudio=!1,t._sounds=[],delete cache[n],t.load())})}},decodeAudioData=(t,n)=>{var r;let i=()=>{n._emit(`loaderror`,null,`Decoding audio data failed.`)},a=t=>{t&&n._sounds.length>0?(cache[n._src]=t,loadSound(n,t)):i()};if(typeof Promise<`u`&&((r=Howler.ctx)==null?void 0:r.decodeAudioData.length)===1){var o;((o=Howler.ctx)==null?void 0:o.decodeAudioData(t)).then(a).catch(i)}else{var s;(s=Howler.ctx)==null||s.decodeAudioData(t,a,i)}},loadSound=(e,t)=>{t&&!e._duration&&(e._duration=t.duration),Object.keys(e._sprite).length===0&&(e._sprite={__default:[0,e._duration*1e3]}),e._state!==`loaded`&&(e._state=`loaded`,e._emit(`load`),e._loadQueue(),globalPluginManager.executeHowlLoad(e))};function isHTMLAudioElement(e){return e!==null&&e instanceof HTMLAudioElement&&`src`in e&&`play`in e&&!(`videoWidth`in e)}function isGainNode(e){return e!==null&&`gain`in e&&`connect`in e}var Sound=class{constructor(e){this._muted=!1,this._loop=!1,this._volume=1,this._rate=1,this._seek=0,this._paused=!0,this._ended=!0,this._sprite=`__default`,this._id=0,this._node=null,this._playStart=0,this._rateSeek=0,this._parent=e,this.init()}init(){let e=this._parent;return this._muted=e._muted,this._loop=e._loop,this._volume=e._volume,this._rate=e._rate,this._seek=0,this._paused=!0,this._ended=!0,this._sprite=`__default`,this._id=++Howler._counter,e._sounds.push(this),this.create(),globalPluginManager.executeSoundCreate(this,e),this}create(){let e=this._parent,t=Howler._muted||this._muted||e._muted?0:this._volume;if(this._errorFn=this._errorListener.bind(this),this._loadFn=this._loadListener.bind(this),this._endFn=this._endListener.bind(this),e._webAudio&&Howler.ctx){let e=Howler.ctx.createGain();e&&(this._node=e,this._node.gain.setValueAtTime(t,Howler.ctx.currentTime),this._node.paused=!0,this._node.connect(Howler.masterGain))}else if(!Howler.noAudio){this._node=Howler._obtainHtml5Audio(),this._errorFn=this._errorListener.bind(this),this._node.addEventListener(`error`,this._errorFn,!1),this._loadFn=this._loadListener.bind(this),this._node.addEventListener(Howler._canPlayEvent,this._loadFn,!1),this._endFn=this._endListener.bind(this),this._node.addEventListener(`ended`,this._endFn,!1);let n=typeof e._src==`string`?e._src:Array.isArray(e._src)&&e._src.length>0?e._src[0]:``;this._node.src=n;let r=e._preload===!0?`auto`:e._preload===!1?`none`:e._preload===`metadata`?`metadata`:`auto`;this._node.preload=r;let i=Howler.volume();typeof i==`number`&&(this._node.volume=t*i),this._node.load()}return this}reset(){let e=this._parent;return this._muted=e._muted,this._loop=e._loop,this._volume=e._volume,this._rate=e._rate,this._seek=0,this._rateSeek=0,this._paused=!0,this._ended=!0,this._sprite=`__default`,this._id=++Howler._counter,this}_errorListener(){if(this._node&&isHTMLAudioElement(this._node)){let e=this._node.error?this._node.error.code:0;this._parent._emit(`loaderror`,this._id,String(e)),this._errorFn&&this._node.removeEventListener(`error`,this._errorFn,!1)}}_loadListener(){if(!this._node||!isHTMLAudioElement(this._node))return;let e=this._parent;e._duration=Math.ceil(this._node.duration*10)/10,Object.keys(e._sprite).length===0&&(e._sprite={__default:[0,e._duration*1e3]}),e._state!==`loaded`&&(e._state=`loaded`,e._emit(`load`),e._loadQueue(),globalPluginManager.executeHowlLoad(e)),this._loadFn&&this._node.removeEventListener(Howler._canPlayEvent,this._loadFn,!1)}_endListener(){let e=this._parent;e._duration===1/0&&this._node&&isHTMLAudioElement(this._node)&&(e._duration=Math.ceil(this._node.duration*10)/10,e._sprite.__default[1]===1/0&&(e._sprite.__default[1]=e._duration*1e3),e._ended(this)),this._endFn&&this._node&&this._node.removeEventListener(`ended`,this._endFn,!1)}},Howl=class{constructor(e){if(this._autoplay=!1,this._format=[],this._html5=!1,this._muted=!1,this._loop=!1,this._pool=5,this._preload=!0,this._rate=1,this._sprite={},this._src=[],this._volume=1,this._xhr={method:`GET`,withCredentials:!1},this._duration=0,this._state=`unloaded`,this._sounds=[],this._endTimers={},this._queue=[],this._playLock=!1,this._webAudio=!1,this._onend=[],this._onfade=[],this._onload=[],this._onloaderror=[],this._onplayerror=[],this._onpause=[],this._onplay=[],this._onstop=[],this._onmute=[],this._onvolume=[],this._onrate=[],this._onseek=[],this._onunlock=[],this._onresume=[],!e.src||e.src.length===0){console.error(`An array of source files must be passed with any new Howl.`);return}this.init(e)}init(e){return Howler.ctx||setupAudioContext(),this._autoplay=e.autoplay||!1,this._format=typeof e.format==`string`?[e.format]:e.format||[],this._html5=e.html5||!1,this._muted=e.mute||!1,this._loop=e.loop||!1,this._pool=e.pool||5,this._preload=typeof e.preload==`boolean`||e.preload===`metadata`?e.preload:!0,this._rate=e.rate||1,this._sprite=e.sprite||{},this._src=typeof e.src==`string`?[e.src]:e.src,this._volume=e.volume===void 0?1:e.volume,this._xhr={method:e.xhr&&e.xhr.method?e.xhr.method:`GET`,headers:e.xhr&&e.xhr.headers?e.xhr.headers:void 0,withCredentials:e.xhr&&e.xhr.withCredentials?e.xhr.withCredentials:!1},this._duration=0,this._state=`unloaded`,this._sounds=[],this._endTimers={},this._queue=[],this._playLock=!1,this._onend=e.onend?[{fn:e.onend}]:[],this._onfade=e.onfade?[{fn:e.onfade}]:[],this._onload=e.onload?[{fn:e.onload}]:[],this._onloaderror=e.onloaderror?[{fn:(...t)=>{e.onloaderror&&typeof t[0]==`number`&&typeof t[1]==`string`&&e.onloaderror(t[0],t[1])}}]:[],this._onplayerror=e.onplayerror?[{fn:(...t)=>{e.onplayerror&&typeof t[0]==`number`&&typeof t[1]==`string`&&e.onplayerror(t[0],t[1])}}]:[],this._onpause=e.onpause?[{fn:e.onpause}]:[],this._onplay=e.onplay?[{fn:e.onplay}]:[],this._onstop=e.onstop?[{fn:e.onstop}]:[],this._onmute=e.onmute?[{fn:e.onmute}]:[],this._onvolume=e.onvolume?[{fn:e.onvolume}]:[],this._onrate=e.onrate?[{fn:e.onrate}]:[],this._onseek=e.onseek?[{fn:e.onseek}]:[],this._onunlock=e.onunlock?[{fn:e.onunlock}]:[],this._onresume=[],this._webAudio=Howler.usingWebAudio&&!this._html5,Howler.ctx!==void 0&&Howler.ctx&&Howler.autoUnlock&&Howler._unlockAudio(),Howler._howls.push(this),globalPluginManager.executeHowlCreate(this,e),this._autoplay&&this._queue.push({event:`play`,action:()=>{this.play()}}),(this._preload===!0||this._preload===`metadata`)&&this.load(),this}load(){let e=null;if(Howler.noAudio)return this._emit(`loaderror`,null,`No audio support.`),this;typeof this._src==`string`&&(this._src=[this._src]);for(let n=0;n<this._src.length;n++){var t;let r,i=this._src[n];if((t=this._format)!=null&&t[n])r=this._format[n];else{if(typeof i!=`string`){this._emit(`loaderror`,null,`Non-string found in selected audio sources - ignoring.`);continue}let e=/^data:audio\/([^;,]+);/i.exec(i);e||(e=/\.([^.]+)$/.exec(i.split(`?`,1)[0])),r=e?e[1].toLowerCase():null}if(r||console.warn(`No file extension was found. Consider using the "format" property or specify an extension.`),r&&Howler.codecs(r)){e=this._src[n];break}}return e?(this._src=e,this._state=`loading`,typeof window<`u`&&window.location.protocol===`https:`&&e.slice(0,5)===`http:`&&(this._html5=!0,this._webAudio=!1),new Sound(this),this._webAudio&&loadBuffer(this),this):(this._emit(`loaderror`,null,`No codec support for selected audio sources.`),this)}play(e,t){let n=null;if(typeof e==`number`)n=e,e=void 0;else if(typeof e==`string`&&this._state===`loaded`&&!this._sprite[e])return null;else if(e===void 0&&(e=`__default`,!this._playLock)){let t=0;for(let e=0;e<this._sounds.length;e++)this._sounds[e]._paused&&!this._sounds[e]._ended&&(t++,n=this._sounds[e]._id);t===1?e=void 0:n=null}let r=n?this._soundById(n):this._inactiveSound();if(!r)return null;if(n&&!e&&(e=r._sprite||`__default`),this._state!==`loaded`){r._sprite=e||`__default`,r._ended=!1;let t=r._id;return this._queue.push({event:`play`,action:()=>{this.play(t)}}),t}if(n&&!r._paused)return t||this._loadQueue(`play`),r._id;this._webAudio&&Howler._autoResume();let i=Math.max(0,r._seek>0?r._seek:this._sprite[e][0]/1e3),a=Math.max(0,(this._sprite[e][0]+this._sprite[e][1])/1e3-i),o=a*1e3/Math.abs(r._rate),s=this._sprite[e][0]/1e3,c=(this._sprite[e][0]+this._sprite[e][1])/1e3;r._sprite=e,r._ended=!1;let l=()=>{r._paused=!1,r._seek=i,r._start=s,r._stop=c,r._loop=!!(r._loop||this._sprite[e][2])};if(i>=c)return this._ended(r),r._id;let u=r._node;if(this._webAudio&&u&&isGainNode(u)){var d;let e=()=>{this._playLock=!1,l(),this._refreshBuffer(r);let e=r._muted||this._muted?0:r._volume;u.gain.setValueAtTime(e,Howler.ctx.currentTime),r._playStart=Howler.ctx.currentTime,u.bufferSource&&u.bufferSource.start(0,i,r._loop?86400:a),o!==1/0&&(this._endTimers[r._id]=setTimeout(this._ended.bind(this,r),o)),t||setTimeout(()=>{this._emit(`play`,r._id),this._loadQueue()},0)};Howler.state===`running`&&((d=Howler.ctx)==null?void 0:d.state)!==`interrupted`?e():(this._playLock=!0,this.once(`resume`,e),this._clearTimer(r._id))}else if(u&&isHTMLAudioElement(u)){let n=()=>{u.currentTime=i,u.muted=r._muted||this._muted||Howler._muted||u.muted;let n=Howler.volume();u.volume=r._volume*(typeof n==`number`?n:1),u.playbackRate=r._rate;try{let n=u.play();if(n&&typeof Promise<`u`&&(n instanceof Promise||typeof n.then==`function`)?(this._playLock=!0,l(),n.then(()=>{this._playLock=!1,`_unlocked`in u&&(u._unlocked=!0),t?this._loadQueue():this._emit(`play`,r._id)}).catch(()=>{this._playLock=!1,this._emit(`playerror`,r._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.`),r._ended=!0,r._paused=!0})):t||(this._playLock=!1,l(),this._emit(`play`,r._id)),u.playbackRate=r._rate,u.paused){this._emit(`playerror`,r._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.`);return}if(e!==`__default`||r._loop)this._endTimers[r._id]=setTimeout(this._ended.bind(this,r),o);else{let e=()=>{this._ended(r),u.removeEventListener(`ended`,e,!1)};this._endTimers[r._id]=setTimeout(e,o),u.addEventListener(`ended`,e,!1)}}catch(e){this._emit(`playerror`,r._id,e instanceof Error?e.message:String(e))}};if(u.src===`data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA`&&(u.src=typeof this._src==`string`?this._src:Array.isArray(this._src)&&this._src.length>0?this._src[0]:``,u.load()),u.readyState>=3)n();else{this._playLock=!0,this._state=`loading`;let e=()=>{this._state=`loaded`,n(),u.removeEventListener(Howler._canPlayEvent,e,!1)};u.addEventListener(Howler._canPlayEvent,e,!1),this._clearTimer(r._id)}}return r._id}pause(e,t){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`pause`,action:()=>{this.pause(e)}}),this;let n=this._getSoundIds(e);for(let e=0;e<n.length;e++){this._clearTimer(n[e]);let t=this._soundById(n[e]);if(t&&!t._paused){let r=this.seek(n[e]);if(t._seek=typeof r==`number`?r:0,t._rateSeek=0,t._paused=!0,this._stopFade(n[e]),t._node)if(this._webAudio&&isGainNode(t._node)){if(!t._node.bufferSource)continue;t._node.bufferSource.stop(0),this._cleanBuffer(t._node)}else isHTMLAudioElement(t._node)&&(!Number.isNaN(t._node.duration)||t._node.duration===1/0)&&t._node.pause()}arguments[1]||this._emit(`pause`,t?t._id:null)}return this}stop(e,t){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`stop`,action:()=>{this.stop(e)}}),this;let n=this._getSoundIds(e);for(let e=0;e<n.length;e++){this._clearTimer(n[e]);let r=this._soundById(n[e]);r&&(r._seek=r._start||0,r._rateSeek=0,r._paused=!0,r._ended=!0,this._stopFade(n[e]),r._node&&(this._webAudio&&isGainNode(r._node)?r._node.bufferSource&&(r._node.bufferSource.stop(0),this._cleanBuffer(r._node)):isHTMLAudioElement(r._node)&&(!Number.isNaN(r._node.duration)||r._node.duration===1/0)&&(r._node.currentTime=r._start||0,r._node.pause(),r._node.duration===1/0&&this._clearSound(r._node))),t||this._emit(`stop`,r._id))}return this}mute(e,t){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`mute`,action:()=>{this.mute(e,t)}}),this;if(t===void 0)if(typeof e==`boolean`)this._muted=e;else return this._muted;let n=this._getSoundIds(t);for(let t=0;t<n.length;t++){let a=this._soundById(n[t]);if(a){if(a._muted=e,a._interval&&this._stopFade(a._id),this._webAudio&&a._node&&isGainNode(a._node)){var r,i;a._node.gain.setValueAtTime(e?0:a._volume,(r=(i=Howler.ctx)==null?void 0:i.currentTime)==null?0:r)}else a._node&&isHTMLAudioElement(a._node)&&(a._node.muted=Howler._muted?!0:e);this._emit(`mute`,a._id)}}return this}volume(e){let t=arguments,n,r;if(t.length===0)return this._volume;t.length===1||t.length===2&&t[1]===void 0?this._getSoundIds().indexOf(t[0])>=0?r=parseInt(String(t[0]),10):n=parseFloat(String(t[0])):t.length>=2&&(n=parseFloat(String(t[0])),r=parseInt(String(t[1]),10));let i=null;if(n!==void 0&&n>=0&&n<=1){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`volume`,action:()=>{t.length>=1&&typeof t[0]==`number`&&(t.length>=2&&typeof t[1]==`number`?this.volume(t[0],t[1]):this.volume(t[0]))}}),this;r===void 0&&(this._volume=n);let e=this._getSoundIds(r);for(let r=0;r<e.length;r++)if(i=this._soundById(e[r]),i){if(i._volume=n,t[2]||this._stopFade(e[r]),this._webAudio&&i._node&&isGainNode(i._node)&&!i._muted){var a,o;i._node.gain.setValueAtTime(n,(a=(o=Howler.ctx)==null?void 0:o.currentTime)==null?0:a)}else if(i._node&&isHTMLAudioElement(i._node)&&!i._muted){let e=Howler.volume();typeof e==`number`&&(i._node.volume=n*e)}this._emit(`volume`,i._id)}}else return i=r?this._soundById(r):this._sounds[0],i?i._volume:0;return this}fade(e,t,n,r){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`fade`,action:()=>{this.fade(e,t,n,r)}}),this;e=Math.min(Math.max(0,parseFloat(String(e))),1),t=Math.min(Math.max(0,parseFloat(String(t))),1),n=parseFloat(String(n)),r===void 0?this.volume(e):this.volume(e,r);let i=this._getSoundIds(r);for(let s=0;s<i.length;s++){let c=this._soundById(i[s]);if(c){if(r||this._stopFade(i[s]),this._webAudio&&!c._muted){var a,o;let r=(a=(o=Howler.ctx)==null?void 0:o.currentTime)==null?0:a,i=r+n/1e3;c._volume=e,c._node&&isGainNode(c._node)&&(c._node.gain.setValueAtTime(e,r),c._node.gain.linearRampToValueAtTime(t,i))}this._startFadeInterval(c,e,t,n,i[s],r===void 0)}}return this}_startFadeInterval(e,t,n,r,i,a){let o=t,s=n-t,c=Math.abs(s/.01),l=Math.max(4,c>0?r/c:r),u=Date.now();e._fadeTo=n,e._interval=setInterval(()=>{let i=(Date.now()-u)/r;u=Date.now(),o+=s*i,o=Math.round(o*100)/100,o=s<0?Math.max(n,o):Math.min(n,o),this._webAudio?e._volume=o:this.volume(o,e._id,!0),a&&(this._volume=o),(n<t&&o<=n||n>t&&o>=n)&&(e._interval&&clearInterval(e._interval),e._interval=void 0,e._fadeTo=void 0,this.volume(n,e._id),this._emit(`fade`,e._id))},l)}_stopFade(e){let t=this._soundById(e);return t&&t._interval&&(this._webAudio&&t._node&&isGainNode(t._node)&&t._node.gain.cancelScheduledValues(Howler.ctx.currentTime),t._interval&&(clearInterval(t._interval),t._interval=void 0),this.volume(t._fadeTo,e),t._fadeTo=void 0,this._emit(`fade`,e)),this}loop(e){let t=arguments,n,r,i=null;if(t.length===0)return this._loop;if(t.length===1)if(typeof t[0]==`boolean`)n=t[0],this._loop=n;else return i=this._soundById(parseInt(String(t[0]),10)),i?i._loop:!1;else t.length===2&&(n=t[0],r=parseInt(String(t[1]),10));let a=this._getSoundIds(r);for(let e=0;e<a.length;e++)i=this._soundById(a[e]),i&&(i._loop=n,this._webAudio&&i._node&&isGainNode(i._node)&&i._node.bufferSource&&(i._node.bufferSource.loop=n,n&&(i._node.bufferSource.loopStart=i._start||0,i._node.bufferSource.loopEnd=i._stop,this.playing(a[e])&&(this.pause(a[e],!0),this.play(a[e],!0)))));return this}rate(e){let t=arguments,n,r;t.length===0?r=this._sounds[0]._id:t.length===1?this._getSoundIds().indexOf(t[0])>=0?r=parseInt(String(t[0]),10):n=parseFloat(String(t[0])):t.length===2&&(n=parseFloat(String(t[0])),r=parseInt(String(t[1]),10));let i=null;if(typeof n==`number`){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`rate`,action:()=>{t.length>=1&&typeof t[0]==`number`&&(t.length>=2&&typeof t[1]==`number`?this.rate(t[0],t[1]):this.rate(t[0]))}}),this;r===void 0&&(this._rate=n);let e=this._getSoundIds(r);for(let t=0;t<e.length;t++)if(i=this._soundById(e[t]),i){if(this.playing(e[t])){let n=this.seek(e[t]);i._rateSeek=typeof n==`number`?n:0,i._playStart=this._webAudio?Howler.ctx.currentTime:i._playStart}i._rate=n,this._webAudio&&i._node&&isGainNode(i._node)&&i._node.bufferSource?i._node.bufferSource.playbackRate.setValueAtTime(n,Howler.ctx.currentTime):i._node&&isHTMLAudioElement(i._node)&&(i._node.playbackRate=n);let r=this.seek(e[t]),a=typeof r==`number`?r:0,o=((this._sprite[i._sprite][0]+this._sprite[i._sprite][1])/1e3-a)*1e3/Math.abs(i._rate);(this._endTimers[e[t]]||!i._paused)&&(this._clearTimer(e[t]),this._endTimers[e[t]]=setTimeout(this._ended.bind(this,i),o)),this._emit(`rate`,i._id)}}else return r===void 0?this._rate:(i=this._soundById(r),i?i._rate:this._rate);return this}seek(e){let t=arguments,n,r;if(t.length===0?this._sounds.length&&(r=this._sounds[0]._id):t.length===1?this._getSoundIds().indexOf(t[0])>=0?r=parseInt(String(t[0]),10):this._sounds.length&&(r=this._sounds[0]._id,n=parseFloat(String(t[0]))):t.length===2&&(n=parseFloat(String(t[0])),r=parseInt(String(t[1]),10)),r===void 0)return 0;if(typeof n==`number`&&(this._state!==`loaded`||this._playLock))return this._queue.push({event:`seek`,action:()=>{t.length>=1&&typeof t[0]==`number`&&(t.length>=2&&typeof t[1]==`number`?this.seek(t[0],t[1]):this.seek(t[0]))}}),this;let i=this._soundById(r);if(i)if(typeof n==`number`&&n>=0){let e=this.playing(r);e&&this.pause(r,!0),i._seek=n,i._ended=!1,this._clearTimer(r),!this._webAudio&&i._node&&isHTMLAudioElement(i._node)&&!isNaN(i._node.duration)&&(i._node.currentTime=n);let t=()=>{e&&this.play(r,!0),this._emit(`seek`,r)};if(e&&!this._webAudio){let e=()=>{this._playLock?setTimeout(e,0):t()};setTimeout(e,0)}else t()}else{if(this._webAudio){let e=this.playing(r)?Howler.ctx.currentTime-i._playStart:0,t=i._rateSeek?i._rateSeek-i._seek:0;return i._seek+(t+e*Math.abs(i._rate))}else if(i._node&&isHTMLAudioElement(i._node))return i._node.currentTime;return 0}return this}playing(e){if(typeof e==`number`){let t=this._soundById(e);return t?!t._paused:!1}for(let e=0;e<this._sounds.length;e++)if(!this._sounds[e]._paused)return!0;return!1}duration(e){let t=this._duration;if(e!==void 0){let n=this._soundById(e);n&&(t=this._sprite[n._sprite][1]/1e3)}return t}state(){return this._state}unload(){globalPluginManager.executeHowlDestroy(this);let t=this._sounds;for(let e=0;e<t.length;e++){t[e]._paused||this.stop(t[e]._id);let n=t[e]._node;if(!this._webAudio&&n&&isHTMLAudioElement(n)){this._clearSound(n);let r=t[e]._errorFn;r&&n.removeEventListener(`error`,r,!1);let i=t[e]._loadFn;i&&n.removeEventListener(Howler._canPlayEvent,i,!1);let a=t[e]._endFn;a&&n.removeEventListener(`ended`,a,!1),Howler._releaseHtml5Audio(n)}t[e]._node=null,this._clearTimer(t[e]._id)}let n=Howler._howls.indexOf(this);n>=0&&Howler._howls.splice(n,1);let r=!0;for(let e=0;e<Howler._howls.length;e++)if(Howler._howls[e]._src===this._src||this._src.indexOf(Howler._howls[e]._src)>=0){r=!1;break}return cache&&r&&delete cache[this._src],Howler.noAudio=!1,this._state=`unloaded`,this._sounds=[],null}on(e,t,n,r){return typeof t==`function`&&this[`_on${e}`].push(r?{id:n,fn:t,once:r}:{id:n,fn:t}),this}off(e,t,n){let r=this[`_on${e}`],i=0;if(typeof t==`number`&&(n=t,t=void 0),t||n)for(i=0;i<r.length;i++){let e=n===r[i].id;if(t===r[i].fn&&e||!t&&e){r.splice(i,1);break}}else if(e)this[`_on${e}`]=[];else{let e=Object.keys(this);for(i=0;i<e.length;i++)e[i].indexOf(`_on`)===0&&Array.isArray(this[e[i]])&&(this[e[i]]=[])}return this}once(e,t,n){return this.on(e,t,n,!0),this}_emit(e,t,n){let r=this[`_on${e}`];for(let i=r.length-1;i>=0;i--)if(!r[i].id||r[i].id===t||e===`load`){let a=r[i].fn;setTimeout(()=>{a(t,n)},0),r[i].once&&this.off(e,r[i].fn,r[i].id)}return this._loadQueue(e),this}_loadQueue(e){if(this._queue.length>0){let t=this._queue[0];t.event===e&&(this._queue.shift(),this._loadQueue()),e||t.action()}return this}_ended(e){let t=e._sprite;if(!this._webAudio&&e._node&&isHTMLAudioElement(e._node)&&!e._node.paused&&!e._node.ended&&e._node.currentTime<e._stop)return setTimeout(this._ended.bind(this,e),100),this;let n=!!(e._loop||this._sprite[t][2]);if(this._emit(`end`,e._id),!this._webAudio&&n&&this.stop(e._id,!0).play(e._id),this._webAudio&&n){this._emit(`play`,e._id),e._seek=e._start||0,e._rateSeek=0,e._playStart=Howler.ctx.currentTime;let t=(e._stop-(e._start||0))*1e3/Math.abs(e._rate);this._endTimers[e._id]=setTimeout(this._ended.bind(this,e),t)}return this._webAudio&&!n&&(e._paused=!0,e._ended=!0,e._seek=e._start||0,e._rateSeek=0,this._clearTimer(e._id),this._cleanBuffer(e._node),Howler._autoSuspend()),!this._webAudio&&!n&&this.stop(e._id,!0),this}_clearTimer(e){if(this._endTimers[e]){if(typeof this._endTimers[e]!=`function`)clearTimeout(this._endTimers[e]);else{let t=this._soundById(e);t&&t._node&&t._node.removeEventListener(`ended`,this._endTimers[e],!1)}delete this._endTimers[e]}return this}_soundById(e){for(let t=0;t<this._sounds.length;t++)if(e===this._sounds[t]._id)return this._sounds[t];return null}_inactiveSound(){this._drain();for(let e=0;e<this._sounds.length;e++)if(this._sounds[e]._ended)return this._sounds[e].reset();return new Sound(this)}_drain(){let e=this._pool,t=0;if(!(this._sounds.length<e)){for(let e=0;e<this._sounds.length;e++)this._sounds[e]._ended&&t++;for(let n=this._sounds.length-1;n>=0;n--){if(t<=e)return;if(this._sounds[n]._ended){let e=this._sounds[n]._node;this._webAudio&&e&&isGainNode(e)&&e.disconnect(0),this._sounds.splice(n,1),t--}}}}_getSoundIds(e){if(e===void 0){let e=[];for(let t=0;t<this._sounds.length;t++)e.push(this._sounds[t]._id);return e}else return[e]}_refreshBuffer(t){if(!t._node||!isGainNode(t._node)||!Howler.ctx)return this;t._node.bufferSource=Howler.ctx.createBufferSource();let n=typeof this._src==`string`?this._src:Array.isArray(this._src)&&this._src.length>0?this._src[0]:``;return t._node.bufferSource.buffer=cache[n],t._panner?t._node.bufferSource.connect(t._panner):t._node.bufferSource.connect(t._node),t._node.bufferSource.loop=t._loop,t._loop&&(t._node.bufferSource.loopStart=t._start||0,t._node.bufferSource.loopEnd=t._stop||0),t._node.bufferSource.playbackRate.setValueAtTime(t._rate,Howler.ctx.currentTime),this}_cleanBuffer(e){let t=isAppleVendor(Howler._navigator);if(!e.bufferSource)return this;if(Howler._scratchBuffer&&e.bufferSource&&(e.bufferSource.onended=null,e.bufferSource.disconnect(0),t))try{e.bufferSource.buffer=Howler._scratchBuffer}catch(e){}return e.bufferSource=null,this}_clearSound(e){e.src=`data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA`}};const Howler=new class{constructor(){this._counter=1e3,this._html5AudioPool=[],this.html5PoolSize=10,this._codecs={},this._howls=[],this._muted=!1,this._volume=1,this._canPlayEvent=`canplaythrough`,this._navigator=null,this.masterGain=null,this.noAudio=!1,this.usingWebAudio=!0,this.autoSuspend=!0,this.ctx=null,this.autoUnlock=!0,this.state=`suspended`,this._audioUnlocked=!1,this._scratchBuffer=null,this._suspendTimer=null,this._counter=1e3,this._html5AudioPool=[],this.html5PoolSize=10,this._codecs={},this._howls=[],this._muted=!1,this._volume=1,this._canPlayEvent=`canplaythrough`,this._navigator=typeof window<`u`&&window.navigator?window.navigator:null,this.masterGain=null,this.noAudio=!1,this.usingWebAudio=!0,this.autoSuspend=!0,this.ctx=null,this.autoUnlock=!0,this._setup(),globalPluginManager.setHowlerInstance(this)}volume(e){if(e!==void 0&&(e=parseFloat(String(e)),this.ctx||setupAudioContext(),typeof e==`number`&&e>=0&&e<=1)){if(this._volume=e,this._muted)return this;this.usingWebAudio&&this.ctx&&this.masterGain&&this.masterGain.gain.setValueAtTime(e,this.ctx.currentTime);for(let t=0;t<this._howls.length;t++)if(!this._howls[t]._webAudio){let n=this._howls[t]._getSoundIds();for(let r=0;r<n.length;r++){let i=this._howls[t]._soundById(n[r]);i!=null&&i._node&&isHTMLAudioElement(i._node)&&(i._node.volume=i._volume*e)}}return this}return this._volume}mute(e){this.ctx||setupAudioContext(),this._muted=e,this.usingWebAudio&&this.ctx&&this.masterGain&&this.masterGain.gain.setValueAtTime(e?0:this._volume,this.ctx.currentTime);for(let t=0;t<this._howls.length;t++)if(!this._howls[t]._webAudio){let n=this._howls[t]._getSoundIds();for(let r=0;r<n.length;r++){let i=this._howls[t]._soundById(n[r]);i!=null&&i._node&&isHTMLAudioElement(i._node)&&(i._node.muted=e?!0:i._muted)}}return this}stop(){for(let e=0;e<this._howls.length;e++)this._howls[e].stop();return this}unload(){for(let e=this._howls.length-1;e>=0;e--)this._howls[e].unload();return this.usingWebAudio&&this.ctx&&this.ctx.close!==void 0&&(this.ctx.close(),this.ctx=null,setupAudioContext()),this}codecs(e){return this._codecs[e.replace(/^x-/,``)]}addPlugin(e){return globalPluginManager.register(e),this}removePlugin(e){return globalPluginManager.unregister(e.name),this}hasPlugin(e){return globalPluginManager.isRegistered(e)}_setup(){if(this.state=this.ctx&&this.ctx.state||`suspended`,this._autoSuspend(),!this.usingWebAudio)if(window.Audio!==void 0)try{new window.Audio().oncanplaythrough===void 0&&(this._canPlayEvent=`canplay`)}catch(e){this.noAudio=!0}else this.noAudio=!0;try{new window.Audio().muted&&(this.noAudio=!0)}catch(e){}return this.noAudio||this._setupCodecs(),this}_setupCodecs(){let e=null;try{e=window.Audio===void 0?null:new window.Audio}catch(e){return this}if(!e||typeof e.canPlayType!=`function`)return this;let t=e.canPlayType(`audio/mpeg;`).replace(/^no$/,``);return this._codecs={mp3:!!(t||e.canPlayType(`audio/mp3;`).replace(/^no$/,``)),mpeg:!!t,opus:!!e.canPlayType(`audio/ogg; codecs="opus"`).replace(/^no$/,``),ogg:!!e.canPlayType(`audio/ogg; codecs="vorbis"`).replace(/^no$/,``),oga:!!e.canPlayType(`audio/ogg; codecs="vorbis"`).replace(/^no$/,``),wav:!!(e.canPlayType(`audio/wav; codecs="1"`)||e.canPlayType(`audio/wav`)).replace(/^no$/,``),aac:!!e.canPlayType(`audio/aac;`).replace(/^no$/,``),caf:!!e.canPlayType(`audio/x-caf;`).replace(/^no$/,``),m4a:!!(e.canPlayType(`audio/x-m4a;`)||e.canPlayType(`audio/m4a;`)||e.canPlayType(`audio/aac;`)).replace(/^no$/,``),m4b:!!(e.canPlayType(`audio/x-m4b;`)||e.canPlayType(`audio/m4b;`)||e.canPlayType(`audio/aac;`)).replace(/^no$/,``),mp4:!!(e.canPlayType(`audio/x-mp4;`)||e.canPlayType(`audio/mp4;`)||e.canPlayType(`audio/aac;`)).replace(/^no$/,``),weba:!!e.canPlayType(`audio/webm; codecs="vorbis"`).replace(/^no$/,``),webm:!!e.canPlayType(`audio/webm; codecs="vorbis"`).replace(/^no$/,``),dolby:!!e.canPlayType(`audio/mp4; codecs="ec-3"`).replace(/^no$/,``),flac:!!(e.canPlayType(`audio/x-flac;`)||e.canPlayType(`audio/flac;`)).replace(/^no$/,``)},this}_unlockAudio(){if(this._audioUnlocked||!this.ctx)return;this._audioUnlocked=!1,this.autoUnlock=!1,!this._mobileUnloaded&&this.ctx.sampleRate!==44100&&(this._mobileUnloaded=!0,this.unload()),this._scratchBuffer=this.ctx.createBuffer(1,1,22050);let e=()=>{for(;this._html5AudioPool.length<this.html5PoolSize;)try{let e=new window.Audio;e._unlocked=!0,this._releaseHtml5Audio(e)}catch(e){this.noAudio=!0;break}for(let e=0;e<this._howls.length;e++)if(!this._howls[e]._webAudio){let t=this._howls[e]._getSoundIds();for(let n=0;n<t.length;n++){let r=this._howls[e]._soundById(t[n]);r!=null&&r._node&&isHTMLAudioElement(r._node)&&!r._node._unlocked&&(r._node._unlocked=!0,r._node.load())}}this._autoResume();let t=this.ctx,n=t.createBufferSource();n.buffer=this._scratchBuffer,n.connect(t.destination),n.start(0),typeof t.resume==`function`&&t.resume(),n.onended=()=>{n.disconnect(0),this._audioUnlocked=!0,document.removeEventListener(`touchstart`,e,!0),document.removeEventListener(`touchend`,e,!0),document.removeEventListener(`click`,e,!0),document.removeEventListener(`keydown`,e,!0);for(let e=0;e<this._howls.length;e++)this._howls[e]._emit(`unlock`)}};document.addEventListener(`touchstart`,e,!0),document.addEventListener(`touchend`,e,!0),document.addEventListener(`click`,e,!0),document.addEventListener(`keydown`,e,!0)}_obtainHtml5Audio(){if(this._html5AudioPool.length)return this._html5AudioPool.pop();let e=new window.Audio().play();return e&&typeof Promise<`u`&&(e instanceof Promise||typeof e==`object`&&e&&`then`in e&&typeof e.then==`function`)&&e.catch(()=>{console.warn(`HTML5 Audio pool exhausted, returning potentially locked audio object.`)}),new window.Audio}_releaseHtml5Audio(e){return e._unlocked&&this._html5AudioPool.push(e),this}_autoSuspend(){if(!(!this.autoSuspend||!this.ctx||this.ctx.suspend===void 0||!this.usingWebAudio)){for(let e=0;e<this._howls.length;e++)if(this._howls[e]._webAudio){for(let t=0;t<this._howls[e]._sounds.length;t++)if(!this._howls[e]._sounds[t]._paused)return}this._suspendTimer&&clearTimeout(this._suspendTimer),this._suspendTimer=setTimeout(()=>{var e;if(!this.autoSuspend)return;this._suspendTimer=null,this.state=`suspending`;let t=()=>{this.state=`suspended`,this._resumeAfterSuspend&&(delete this._resumeAfterSuspend,this._autoResume())};(e=this.ctx)==null||e.suspend().then(t,t)},3e4)}}_autoResume(){!this.ctx||this.ctx.resume===void 0||!this.usingWebAudio||(this.state===`running`&&this.ctx.state!==`interrupted`&&this._suspendTimer?(clearTimeout(this._suspendTimer),this._suspendTimer=null):this.state===`suspended`||this.state===`running`&&this.ctx.state===`interrupted`?(this.ctx.resume().then(()=>{this.state=`running`;for(let e=0;e<this._howls.length;e++)this._howls[e]._emit(`resume`)}),this._suspendTimer&&(clearTimeout(this._suspendTimer),this._suspendTimer=null)):this.state===`suspending`&&(this._resumeAfterSuspend=!0))}};export{HowlerPlugin as a,isGainNode as i,Howl as n,PluginManager as o,Sound as r,globalPluginManager as s,Howler as t};
|
|
5
|
+
const cache={};function getUserAgent(e){return(e==null?void 0:e.userAgent)||``}function getPlatform(e){return(e==null?void 0:e.platform)||``}function isIOS(e){return/iP(hone|od|ad)/.test(getPlatform(e))}function getIOSVersion(e){var t;if(!isIOS(e))return null;let n=e==null||(t=e.appVersion)==null?void 0:t.match(/OS (\d+)_(\d+)_?(\d+)?/);return n?parseInt(n[1],10):null}function isSafari(e){let n=getUserAgent(e);return n.indexOf(`Safari`)!==-1&&n.indexOf(`Chrome`)===-1}function isAppleVendor(e){var t,n;return((t=e==null||(n=e.vendor)==null?void 0:n.indexOf(`Apple`))==null?-1:t)>=0}const setupAudioContext=()=>{if(!Howler.usingWebAudio)return;try{window.AudioContext===void 0?Howler.usingWebAudio=!1:Howler.ctx=new window.AudioContext}catch(e){Howler.usingWebAudio=!1}Howler.ctx||(Howler.usingWebAudio=!1);let e=isIOS(Howler._navigator),t=getIOSVersion(Howler._navigator);if(e&&t&&t<9){let e=isSafari(Howler._navigator);Howler._navigator&&!e&&(Howler.usingWebAudio=!1)}Howler.usingWebAudio&&Howler.ctx&&(Howler.masterGain=Howler.ctx.createGain(),Howler.masterGain&&(Howler.masterGain.gain.setValueAtTime(Howler._muted?0:Howler._volume,Howler.ctx.currentTime),Howler.masterGain.connect(Howler.ctx.destination))),Howler._setup()};var HowlerPlugin=class{},PluginManager=class{constructor(){this.plugins=new Map,this.howlerInstance=null}register(e){if(this.plugins.has(e.name))throw Error(`Plugin "${e.name}" is already registered`);let t=e.getHooks(),n={plugin:e,hooks:t};if(this.plugins.set(e.name,n),this.howlerInstance&&t.onHowlerInit)try{t.onHowlerInit(this.howlerInstance)}catch(t){console.error(`Error during onHowlerInit for plugin "${e.name}":`,t)}}unregister(e){let t=this.plugins.get(e);if(!t)throw Error(`Plugin "${e}" is not registered`);if(t.plugin.onUnregister)try{t.plugin.onUnregister()}catch(t){console.error(`Error during onUnregister for plugin "${e}":`,t)}this.plugins.delete(e)}isRegistered(e){return this.plugins.has(e)}setHowlerInstance(e){this.howlerInstance=e,this._executeHooks(`onHowlerInit`,t=>{t.onHowlerInit&&t.onHowlerInit(e)})}getHowlerInstance(){return this.howlerInstance}getPlugins(){return new Map(this.plugins)}executeHowlCreate(e,t){this._executeHooks(`onHowlCreate`,n=>{n.onHowlCreate&&n.onHowlCreate(e,t)})}executeSoundCreate(e,t){this._executeHooks(`onSoundCreate`,n=>{n.onSoundCreate&&n.onSoundCreate(e,t)})}executeHowlLoad(e){this._executeHooks(`onHowlLoad`,t=>{t.onHowlLoad&&t.onHowlLoad(e)})}executeHowlDestroy(e){this._executeHooks(`onHowlDestroy`,t=>{t.onHowlDestroy&&t.onHowlDestroy(e)})}_executeHooks(e,t){for(let[n,r]of this.plugins)try{t(r.hooks)}catch(t){console.error(`Error in hook "${e}" for plugin "${n}":`,t)}}};const globalPluginManager=new PluginManager,loadBuffer=t=>{let n=t._src;if(cache[n]){t._duration=cache[n].duration,loadSound(t);return}if(/^data:[^;]+;base64,/.test(n)){let e=atob(n.split(`,`)[1]),r=new Uint8Array(e.length);for(let t=0;t<e.length;++t)r[t]=e.charCodeAt(t);decodeAudioData(r.buffer,t)}else{let r={method:t._xhr.method,credentials:t._xhr.withCredentials?`include`:`same-origin`};t._xhr.headers&&(r.headers=t._xhr.headers),fetch(n,r).then(e=>{if(!e.ok){t._emit(`loaderror`,null,`Failed loading audio file with status: ${e.status}.`);return}return e.arrayBuffer()}).then(e=>{e&&decodeAudioData(e,t)}).catch(()=>{t._webAudio&&(t._html5=!0,t._webAudio=!1,t._sounds=[],delete cache[n],t.load())})}},decodeAudioData=(t,n)=>{var r;let i=()=>{n._emit(`loaderror`,null,`Decoding audio data failed.`)},a=t=>{t&&n._sounds.length>0?(cache[n._src]=t,loadSound(n,t)):i()};if(typeof Promise<`u`&&((r=Howler.ctx)==null?void 0:r.decodeAudioData.length)===1){var o;((o=Howler.ctx)==null?void 0:o.decodeAudioData(t)).then(a).catch(i)}else{var s;(s=Howler.ctx)==null||s.decodeAudioData(t,a,i)}},loadSound=(e,t)=>{t&&!e._duration&&(e._duration=t.duration),Object.keys(e._sprite).length===0&&(e._sprite={__default:[0,e._duration*1e3]}),e._state!==`loaded`&&(e._state=`loaded`,e._emit(`load`),e._loadQueue(),globalPluginManager.executeHowlLoad(e))};function isHTMLAudioElement(e){return e!==null&&e instanceof HTMLAudioElement&&`src`in e&&`play`in e&&!(`videoWidth`in e)}function isGainNode(e){return e!==null&&`gain`in e&&`connect`in e}function isSpatialAudio(e){return typeof e==`object`&&!!e&&`_panner`in e}var Sound=class{constructor(e){this._muted=!1,this._loop=!1,this._volume=1,this._rate=1,this._seek=0,this._paused=!0,this._ended=!0,this._sprite=`__default`,this._id=0,this._node=null,this._playStart=0,this._rateSeek=0,this._parent=e,this.init()}init(){let e=this._parent;return this._muted=e._muted,this._loop=e._loop,this._volume=e._volume,this._rate=e._rate,this._seek=0,this._paused=!0,this._ended=!0,this._sprite=`__default`,this._id=++Howler._counter,e._sounds.push(this),this.create(),globalPluginManager.executeSoundCreate(this,e),this}create(){let e=this._parent,t=Howler._muted||this._muted||e._muted?0:this._volume;if(this._errorFn=this._errorListener.bind(this),this._loadFn=this._loadListener.bind(this),this._endFn=this._endListener.bind(this),e._webAudio&&Howler.ctx){let e=Howler.ctx.createGain();e&&(this._node=e,this._node.gain.setValueAtTime(t,Howler.ctx.currentTime),this._node.paused=!0,this._node.connect(Howler.masterGain))}else if(!Howler.noAudio){this._node=Howler._obtainHtml5Audio(),this._errorFn=this._errorListener.bind(this),this._node.addEventListener(`error`,this._errorFn,!1),this._loadFn=this._loadListener.bind(this),this._node.addEventListener(Howler._canPlayEvent,this._loadFn,!1),this._endFn=this._endListener.bind(this),this._node.addEventListener(`ended`,this._endFn,!1);let n=typeof e._src==`string`?e._src:Array.isArray(e._src)&&e._src.length>0?e._src[0]:``;this._node.src=n;let r=e._preload===!0?`auto`:e._preload===!1?`none`:e._preload===`metadata`?`metadata`:`auto`;this._node.preload=r;let i=Howler.volume();typeof i==`number`&&(this._node.volume=t*i),this._node.load()}return this}reset(){let e=this._parent;return this._muted=e._muted,this._loop=e._loop,this._volume=e._volume,this._rate=e._rate,this._seek=0,this._rateSeek=0,this._paused=!0,this._ended=!0,this._sprite=`__default`,this._id=++Howler._counter,this}_errorListener(){if(this._node&&isHTMLAudioElement(this._node)){let e=this._node.error?this._node.error.code:0;this._parent._emit(`loaderror`,this._id,String(e)),this._errorFn&&this._node.removeEventListener(`error`,this._errorFn,!1)}}_loadListener(){if(!this._node||!isHTMLAudioElement(this._node))return;let e=this._parent;e._duration=Math.ceil(this._node.duration*10)/10,Object.keys(e._sprite).length===0&&(e._sprite={__default:[0,e._duration*1e3]}),e._state!==`loaded`&&(e._state=`loaded`,e._emit(`load`),e._loadQueue(),globalPluginManager.executeHowlLoad(e)),this._loadFn&&this._node.removeEventListener(Howler._canPlayEvent,this._loadFn,!1)}_endListener(){let e=this._parent;e._duration===1/0&&this._node&&isHTMLAudioElement(this._node)&&(e._duration=Math.ceil(this._node.duration*10)/10,e._sprite.__default[1]===1/0&&(e._sprite.__default[1]=e._duration*1e3),e._ended(this)),this._endFn&&this._node&&this._node.removeEventListener(`ended`,this._endFn,!1)}},Howl=class{constructor(e){if(this._autoplay=!1,this._format=[],this._html5=!1,this._muted=!1,this._loop=!1,this._pool=5,this._preload=!0,this._rate=1,this._sprite={},this._src=[],this._volume=1,this._xhr={method:`GET`,withCredentials:!1},this._duration=0,this._state=`unloaded`,this._sounds=[],this._endTimers={},this._queue=[],this._playLock=!1,this._webAudio=!1,this._onend=[],this._onfade=[],this._onload=[],this._onloaderror=[],this._onplayerror=[],this._onpause=[],this._onplay=[],this._onstop=[],this._onmute=[],this._onvolume=[],this._onrate=[],this._onseek=[],this._onunlock=[],this._onresume=[],!e.src||e.src.length===0){console.error(`An array of source files must be passed with any new Howl.`);return}this.init(e)}init(e){return Howler.ctx||setupAudioContext(),this._autoplay=e.autoplay||!1,this._format=typeof e.format==`string`?[e.format]:e.format||[],this._html5=e.html5||!1,this._muted=e.mute||!1,this._loop=e.loop||!1,this._pool=e.pool||5,this._preload=typeof e.preload==`boolean`||e.preload===`metadata`?e.preload:!0,this._rate=e.rate||1,this._sprite=e.sprite||{},this._src=typeof e.src==`string`?[e.src]:e.src,this._volume=e.volume===void 0?1:e.volume,this._xhr={method:e.xhr&&e.xhr.method?e.xhr.method:`GET`,headers:e.xhr&&e.xhr.headers?e.xhr.headers:void 0,withCredentials:e.xhr&&e.xhr.withCredentials?e.xhr.withCredentials:!1},this._duration=0,this._state=`unloaded`,this._sounds=[],this._endTimers={},this._queue=[],this._playLock=!1,this._onend=e.onend?[{fn:e.onend}]:[],this._onfade=e.onfade?[{fn:e.onfade}]:[],this._onload=e.onload?[{fn:e.onload}]:[],this._onloaderror=e.onloaderror?[{fn:(...t)=>{e.onloaderror&&typeof t[0]==`number`&&typeof t[1]==`string`&&e.onloaderror(t[0],t[1])}}]:[],this._onplayerror=e.onplayerror?[{fn:(...t)=>{e.onplayerror&&typeof t[0]==`number`&&typeof t[1]==`string`&&e.onplayerror(t[0],t[1])}}]:[],this._onpause=e.onpause?[{fn:e.onpause}]:[],this._onplay=e.onplay?[{fn:e.onplay}]:[],this._onstop=e.onstop?[{fn:e.onstop}]:[],this._onmute=e.onmute?[{fn:e.onmute}]:[],this._onvolume=e.onvolume?[{fn:e.onvolume}]:[],this._onrate=e.onrate?[{fn:e.onrate}]:[],this._onseek=e.onseek?[{fn:e.onseek}]:[],this._onunlock=e.onunlock?[{fn:e.onunlock}]:[],this._onresume=[],this._webAudio=Howler.usingWebAudio&&!this._html5,Howler.ctx!==void 0&&Howler.ctx&&Howler.autoUnlock&&Howler._unlockAudio(),Howler._howls.push(this),globalPluginManager.executeHowlCreate(this,e),this._autoplay&&this._queue.push({event:`play`,action:()=>{this.play()}}),(this._preload===!0||this._preload===`metadata`)&&this.load(),this}load(){let e=null;if(Howler.noAudio)return this._emit(`loaderror`,null,`No audio support.`),this;typeof this._src==`string`&&(this._src=[this._src]);for(let n=0;n<this._src.length;n++){var t;let r,i=this._src[n];if((t=this._format)!=null&&t[n])r=this._format[n];else{if(typeof i!=`string`){this._emit(`loaderror`,null,`Non-string found in selected audio sources - ignoring.`);continue}let e=/^data:audio\/([^;,]+);/i.exec(i);e||(e=/\.([^.]+)$/.exec(i.split(`?`,1)[0])),r=e?e[1].toLowerCase():null}if(r||console.warn(`No file extension was found. Consider using the "format" property or specify an extension.`),r&&Howler.codecs(r)){e=this._src[n];break}}return e?(this._src=e,this._state=`loading`,typeof window<`u`&&window.location.protocol===`https:`&&e.slice(0,5)===`http:`&&(this._html5=!0,this._webAudio=!1),new Sound(this),this._webAudio&&loadBuffer(this),this):(this._emit(`loaderror`,null,`No codec support for selected audio sources.`),this)}play(e,t){let n=null;if(typeof e==`number`)n=e,e=void 0;else if(typeof e==`string`&&this._state===`loaded`&&!this._sprite[e])return null;else if(e===void 0&&(e=`__default`,!this._playLock)){let t=0;for(let e=0;e<this._sounds.length;e++)this._sounds[e]._paused&&!this._sounds[e]._ended&&(t++,n=this._sounds[e]._id);t===1?e=void 0:n=null}let r=n?this._soundById(n):this._inactiveSound();if(!r)return null;if(n&&!e&&(e=r._sprite||`__default`),this._state!==`loaded`){r._sprite=e||`__default`,r._ended=!1;let t=r._id;return this._queue.push({event:`play`,action:()=>{this.play(t)}}),t}if(n&&!r._paused)return t||this._loadQueue(`play`),r._id;this._webAudio&&Howler._autoResume();let i=Math.max(0,r._seek>0?r._seek:this._sprite[e][0]/1e3),a=Math.max(0,(this._sprite[e][0]+this._sprite[e][1])/1e3-i),o=a*1e3/Math.abs(r._rate),s=this._sprite[e][0]/1e3,c=(this._sprite[e][0]+this._sprite[e][1])/1e3;r._sprite=e,r._ended=!1;let l=()=>{r._paused=!1,r._seek=i,r._start=s,r._stop=c,r._loop=!!(r._loop||this._sprite[e][2])};if(i>=c)return this._ended(r),r._id;let u=r._node;if(this._webAudio&&u&&isGainNode(u)){var d;let e=()=>{this._playLock=!1,l(),this._refreshBuffer(r);let e=r._muted||this._muted?0:r._volume;u.gain.setValueAtTime(e,Howler.ctx.currentTime),r._playStart=Howler.ctx.currentTime,u.bufferSource&&u.bufferSource.start(0,i,r._loop?86400:a),o!==1/0&&(this._endTimers[r._id]=setTimeout(this._ended.bind(this,r),o)),t||setTimeout(()=>{this._emit(`play`,r._id),this._loadQueue()},0)};Howler.state===`running`&&((d=Howler.ctx)==null?void 0:d.state)!==`interrupted`?e():(this._playLock=!0,this.once(`resume`,e),this._clearTimer(r._id))}else if(u&&isHTMLAudioElement(u)){let n=()=>{u.currentTime=i,u.muted=r._muted||this._muted||Howler._muted||u.muted;let n=Howler.volume();u.volume=r._volume*(typeof n==`number`?n:1),u.playbackRate=r._rate;try{let n=u.play();if(n&&typeof Promise<`u`&&(n instanceof Promise||typeof n.then==`function`)?(this._playLock=!0,l(),n.then(()=>{this._playLock=!1,`_unlocked`in u&&(u._unlocked=!0),t?this._loadQueue():this._emit(`play`,r._id)}).catch(()=>{this._playLock=!1,this._emit(`playerror`,r._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.`),r._ended=!0,r._paused=!0})):t||(this._playLock=!1,l(),this._emit(`play`,r._id)),u.playbackRate=r._rate,u.paused){this._emit(`playerror`,r._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.`);return}if(e!==`__default`||r._loop)this._endTimers[r._id]=setTimeout(this._ended.bind(this,r),o);else{let e=()=>{this._ended(r),u.removeEventListener(`ended`,e,!1)};this._endTimers[r._id]=setTimeout(e,o),u.addEventListener(`ended`,e,!1)}}catch(e){this._emit(`playerror`,r._id,e instanceof Error?e.message:String(e))}};if(u.src===`data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA`&&(u.src=typeof this._src==`string`?this._src:Array.isArray(this._src)&&this._src.length>0?this._src[0]:``,u.load()),u.readyState>=3)n();else{this._playLock=!0,this._state=`loading`;let e=()=>{this._state=`loaded`,n(),u.removeEventListener(Howler._canPlayEvent,e,!1)};u.addEventListener(Howler._canPlayEvent,e,!1),this._clearTimer(r._id)}}return r._id}pause(e,t){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`pause`,action:()=>{this.pause(e)}}),this;let n=this._getSoundIds(e);for(let e=0;e<n.length;e++){this._clearTimer(n[e]);let t=this._soundById(n[e]);if(t&&!t._paused){let r=this.seek(n[e]);if(t._seek=typeof r==`number`?r:0,t._rateSeek=0,t._paused=!0,this._stopFade(n[e]),t._node)if(this._webAudio&&isGainNode(t._node)){if(!t._node.bufferSource)continue;t._node.bufferSource.stop(0),this._cleanBuffer(t._node)}else isHTMLAudioElement(t._node)&&(!Number.isNaN(t._node.duration)||t._node.duration===1/0)&&t._node.pause()}arguments[1]||this._emit(`pause`,t?t._id:null)}return this}stop(e,t){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`stop`,action:()=>{this.stop(e)}}),this;let n=this._getSoundIds(e);for(let e=0;e<n.length;e++){this._clearTimer(n[e]);let r=this._soundById(n[e]);r&&(r._seek=r._start||0,r._rateSeek=0,r._paused=!0,r._ended=!0,this._stopFade(n[e]),r._node&&(this._webAudio&&isGainNode(r._node)?r._node.bufferSource&&(r._node.bufferSource.stop(0),this._cleanBuffer(r._node)):isHTMLAudioElement(r._node)&&(!Number.isNaN(r._node.duration)||r._node.duration===1/0)&&(r._node.currentTime=r._start||0,r._node.pause(),r._node.duration===1/0&&this._clearSound(r._node))),t||this._emit(`stop`,r._id))}return this}mute(e,t){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`mute`,action:()=>{this.mute(e,t)}}),this;if(t===void 0)if(typeof e==`boolean`)this._muted=e;else return this._muted;let n=this._getSoundIds(t);for(let t=0;t<n.length;t++){let a=this._soundById(n[t]);if(a){if(a._muted=e,a._interval&&this._stopFade(a._id),this._webAudio&&a._node&&isGainNode(a._node)){var r,i;a._node.gain.setValueAtTime(e?0:a._volume,(r=(i=Howler.ctx)==null?void 0:i.currentTime)==null?0:r)}else a._node&&isHTMLAudioElement(a._node)&&(a._node.muted=Howler._muted?!0:e);this._emit(`mute`,a._id)}}return this}volume(e){let t=arguments,n,r;if(t.length===0)return this._volume;t.length===1||t.length===2&&t[1]===void 0?this._getSoundIds().indexOf(t[0])>=0?r=parseInt(String(t[0]),10):n=parseFloat(String(t[0])):t.length>=2&&(n=parseFloat(String(t[0])),r=parseInt(String(t[1]),10));let i=null;if(n!==void 0&&n>=0&&n<=1){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`volume`,action:()=>{t.length>=1&&typeof t[0]==`number`&&(t.length>=2&&typeof t[1]==`number`?this.volume(t[0],t[1]):this.volume(t[0]))}}),this;r===void 0&&(this._volume=n);let e=this._getSoundIds(r);for(let r=0;r<e.length;r++)if(i=this._soundById(e[r]),i){if(i._volume=n,t[2]||this._stopFade(e[r]),this._webAudio&&i._node&&isGainNode(i._node)&&!i._muted){var a,o;i._node.gain.setValueAtTime(n,(a=(o=Howler.ctx)==null?void 0:o.currentTime)==null?0:a)}else if(i._node&&isHTMLAudioElement(i._node)&&!i._muted){let e=Howler.volume();typeof e==`number`&&(i._node.volume=n*e)}this._emit(`volume`,i._id)}}else return i=r?this._soundById(r):this._sounds[0],i?i._volume:0;return this}fade(e,t,n,r){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`fade`,action:()=>{this.fade(e,t,n,r)}}),this;e=Math.min(Math.max(0,parseFloat(String(e))),1),t=Math.min(Math.max(0,parseFloat(String(t))),1),n=parseFloat(String(n)),r===void 0?this.volume(e):this.volume(e,r);let i=this._getSoundIds(r);for(let s=0;s<i.length;s++){let c=this._soundById(i[s]);if(c){if(r||this._stopFade(i[s]),this._webAudio&&!c._muted){var a,o;let r=(a=(o=Howler.ctx)==null?void 0:o.currentTime)==null?0:a,i=r+n/1e3;c._volume=e,c._node&&isGainNode(c._node)&&(c._node.gain.setValueAtTime(e,r),c._node.gain.linearRampToValueAtTime(t,i))}this._startFadeInterval(c,e,t,n,i[s],r===void 0)}}return this}_startFadeInterval(e,t,n,r,i,a){let o=t,s=n-t,c=Math.abs(s/.01),l=Math.max(4,c>0?r/c:r),u=Date.now();e._fadeTo=n,e._interval=setInterval(()=>{let i=(Date.now()-u)/r;u=Date.now(),o+=s*i,o=Math.round(o*100)/100,o=s<0?Math.max(n,o):Math.min(n,o),this._webAudio?e._volume=o:this.volume(o,e._id,!0),a&&(this._volume=o),(n<t&&o<=n||n>t&&o>=n)&&(e._interval&&clearInterval(e._interval),e._interval=void 0,e._fadeTo=void 0,this.volume(n,e._id),this._emit(`fade`,e._id))},l)}_stopFade(e){let t=this._soundById(e);return t&&t._interval&&(this._webAudio&&t._node&&isGainNode(t._node)&&t._node.gain.cancelScheduledValues(Howler.ctx.currentTime),t._interval&&(clearInterval(t._interval),t._interval=void 0),this.volume(t._fadeTo,e),t._fadeTo=void 0,this._emit(`fade`,e)),this}loop(e){let t=arguments,n,r,i=null;if(t.length===0)return this._loop;if(t.length===1)if(typeof t[0]==`boolean`)n=t[0],this._loop=n;else return i=this._soundById(parseInt(String(t[0]),10)),i?i._loop:!1;else t.length===2&&(n=t[0],r=parseInt(String(t[1]),10));let a=this._getSoundIds(r);for(let e=0;e<a.length;e++)i=this._soundById(a[e]),i&&(i._loop=n,this._webAudio&&i._node&&isGainNode(i._node)&&i._node.bufferSource&&(i._node.bufferSource.loop=n,n&&(i._node.bufferSource.loopStart=i._start||0,i._node.bufferSource.loopEnd=i._stop,this.playing(a[e])&&(this.pause(a[e],!0),this.play(a[e],!0)))));return this}rate(e){let t=arguments,n,r;t.length===0?r=this._sounds[0]._id:t.length===1?this._getSoundIds().indexOf(t[0])>=0?r=parseInt(String(t[0]),10):n=parseFloat(String(t[0])):t.length===2&&(n=parseFloat(String(t[0])),r=parseInt(String(t[1]),10));let i=null;if(typeof n==`number`){if(this._state!==`loaded`||this._playLock)return this._queue.push({event:`rate`,action:()=>{t.length>=1&&typeof t[0]==`number`&&(t.length>=2&&typeof t[1]==`number`?this.rate(t[0],t[1]):this.rate(t[0]))}}),this;r===void 0&&(this._rate=n);let e=this._getSoundIds(r);for(let t=0;t<e.length;t++)if(i=this._soundById(e[t]),i){if(this.playing(e[t])){let n=this.seek(e[t]);i._rateSeek=typeof n==`number`?n:0,i._playStart=this._webAudio?Howler.ctx.currentTime:i._playStart}i._rate=n,this._webAudio&&i._node&&isGainNode(i._node)&&i._node.bufferSource?i._node.bufferSource.playbackRate.setValueAtTime(n,Howler.ctx.currentTime):i._node&&isHTMLAudioElement(i._node)&&(i._node.playbackRate=n);let r=this.seek(e[t]),a=typeof r==`number`?r:0,o=((this._sprite[i._sprite][0]+this._sprite[i._sprite][1])/1e3-a)*1e3/Math.abs(i._rate);(this._endTimers[e[t]]||!i._paused)&&(this._clearTimer(e[t]),this._endTimers[e[t]]=setTimeout(this._ended.bind(this,i),o)),this._emit(`rate`,i._id)}}else return r===void 0?this._rate:(i=this._soundById(r),i?i._rate:this._rate);return this}seek(e){let t=arguments,n,r;if(t.length===0?this._sounds.length&&(r=this._sounds[0]._id):t.length===1?this._getSoundIds().indexOf(t[0])>=0?r=parseInt(String(t[0]),10):this._sounds.length&&(r=this._sounds[0]._id,n=parseFloat(String(t[0]))):t.length===2&&(n=parseFloat(String(t[0])),r=parseInt(String(t[1]),10)),r===void 0)return 0;if(typeof n==`number`&&(this._state!==`loaded`||this._playLock))return this._queue.push({event:`seek`,action:()=>{t.length>=1&&typeof t[0]==`number`&&(t.length>=2&&typeof t[1]==`number`?this.seek(t[0],t[1]):this.seek(t[0]))}}),this;let i=this._soundById(r);if(i)if(typeof n==`number`&&n>=0){let e=this.playing(r);e&&this.pause(r,!0),i._seek=n,i._ended=!1,this._clearTimer(r),!this._webAudio&&i._node&&isHTMLAudioElement(i._node)&&!isNaN(i._node.duration)&&(i._node.currentTime=n);let t=()=>{e&&this.play(r,!0),this._emit(`seek`,r)};if(e&&!this._webAudio){let e=()=>{this._playLock?setTimeout(e,0):t()};setTimeout(e,0)}else t()}else{if(this._webAudio){let e=this.playing(r)?Howler.ctx.currentTime-i._playStart:0,t=i._rateSeek?i._rateSeek-i._seek:0;return i._seek+(t+e*Math.abs(i._rate))}else if(i._node&&isHTMLAudioElement(i._node))return i._node.currentTime;return 0}return this}playing(e){if(typeof e==`number`){let t=this._soundById(e);return t?!t._paused:!1}for(let e=0;e<this._sounds.length;e++)if(!this._sounds[e]._paused)return!0;return!1}duration(e){let t=this._duration;if(e!==void 0){let n=this._soundById(e);n&&(t=this._sprite[n._sprite][1]/1e3)}return t}state(){return this._state}unload(){globalPluginManager.executeHowlDestroy(this);let t=this._sounds;for(let e=0;e<t.length;e++){t[e]._paused||this.stop(t[e]._id);let n=t[e]._node;if(!this._webAudio&&n&&isHTMLAudioElement(n)){this._clearSound(n);let r=t[e]._errorFn;r&&n.removeEventListener(`error`,r,!1);let i=t[e]._loadFn;i&&n.removeEventListener(Howler._canPlayEvent,i,!1);let a=t[e]._endFn;a&&n.removeEventListener(`ended`,a,!1),Howler._releaseHtml5Audio(n)}t[e]._node=null,this._clearTimer(t[e]._id)}let n=Howler._howls.indexOf(this);n>=0&&Howler._howls.splice(n,1);let r=!0;for(let e=0;e<Howler._howls.length;e++)if(Howler._howls[e]._src===this._src||this._src.indexOf(Howler._howls[e]._src)>=0){r=!1;break}return cache&&r&&delete cache[this._src],Howler.noAudio=!1,this._state=`unloaded`,this._sounds=[],null}on(e,t,n,r){return typeof t==`function`&&this[`_on${e}`].push(r?{id:n,fn:t,once:r}:{id:n,fn:t}),this}off(e,t,n){let r=this[`_on${e}`],i=0;if(typeof t==`number`&&(n=t,t=void 0),t||n)for(i=0;i<r.length;i++){let e=n===r[i].id;if(t===r[i].fn&&e||!t&&e){r.splice(i,1);break}}else if(e)this[`_on${e}`]=[];else{let e=Object.keys(this);for(i=0;i<e.length;i++)e[i].indexOf(`_on`)===0&&Array.isArray(this[e[i]])&&(this[e[i]]=[])}return this}once(e,t,n){return this.on(e,t,n,!0),this}_emit(e,t,n){let r=this[`_on${e}`];for(let i=r.length-1;i>=0;i--)if(!r[i].id||r[i].id===t||e===`load`){let a=r[i].fn;setTimeout(()=>{a(t,n)},0),r[i].once&&this.off(e,r[i].fn,r[i].id)}return this._loadQueue(e),this}_loadQueue(e){if(this._queue.length>0){let t=this._queue[0];t.event===e&&(this._queue.shift(),this._loadQueue()),e||t.action()}return this}_ended(e){let t=e._sprite;if(!this._webAudio&&e._node&&isHTMLAudioElement(e._node)&&!e._node.paused&&!e._node.ended&&e._node.currentTime<e._stop)return setTimeout(this._ended.bind(this,e),100),this;let n=!!(e._loop||this._sprite[t][2]);if(this._emit(`end`,e._id),!this._webAudio&&n&&this.stop(e._id,!0).play(e._id),this._webAudio&&n){this._emit(`play`,e._id),e._seek=e._start||0,e._rateSeek=0,e._playStart=Howler.ctx.currentTime;let t=(e._stop-(e._start||0))*1e3/Math.abs(e._rate);this._endTimers[e._id]=setTimeout(this._ended.bind(this,e),t)}return this._webAudio&&!n&&(e._paused=!0,e._ended=!0,e._seek=e._start||0,e._rateSeek=0,this._clearTimer(e._id),this._cleanBuffer(e._node),Howler._autoSuspend()),!this._webAudio&&!n&&this.stop(e._id,!0),this}_clearTimer(e){if(this._endTimers[e]){if(typeof this._endTimers[e]!=`function`)clearTimeout(this._endTimers[e]);else{let t=this._soundById(e);t&&t._node&&t._node.removeEventListener(`ended`,this._endTimers[e],!1)}delete this._endTimers[e]}return this}_soundById(e){for(let t=0;t<this._sounds.length;t++)if(e===this._sounds[t]._id)return this._sounds[t];return null}_inactiveSound(){this._drain();for(let e=0;e<this._sounds.length;e++)if(this._sounds[e]._ended)return this._sounds[e].reset();return new Sound(this)}_drain(){let e=this._pool,t=0;if(!(this._sounds.length<e)){for(let e=0;e<this._sounds.length;e++)this._sounds[e]._ended&&t++;for(let n=this._sounds.length-1;n>=0;n--){if(t<=e)return;if(this._sounds[n]._ended){let e=this._sounds[n],r=e._node;if(this._webAudio&&r&&isGainNode(r)&&r.disconnect(0),isSpatialAudio(e)&&e._panner){try{e._panner.disconnect(0)}catch(e){}e._panner=void 0}this._sounds.splice(n,1),t--}}}}_getSoundIds(e){if(e===void 0){let e=[];for(let t=0;t<this._sounds.length;t++)e.push(this._sounds[t]._id);return e}else return[e]}_refreshBuffer(t){if(!t._node||!isGainNode(t._node)||!Howler.ctx)return this;t._node.bufferSource=Howler.ctx.createBufferSource();let n=typeof this._src==`string`?this._src:Array.isArray(this._src)&&this._src.length>0?this._src[0]:``;return t._node.bufferSource.buffer=cache[n],t._panner?t._node.bufferSource.connect(t._panner):t._node.bufferSource.connect(t._node),t._node.bufferSource.loop=t._loop,t._loop&&(t._node.bufferSource.loopStart=t._start||0,t._node.bufferSource.loopEnd=t._stop||0),t._node.bufferSource.playbackRate.setValueAtTime(t._rate,Howler.ctx.currentTime),this}_cleanBuffer(e){let t=isAppleVendor(Howler._navigator);if(!e.bufferSource)return this;if(Howler._scratchBuffer&&e.bufferSource&&(e.bufferSource.onended=null,e.bufferSource.disconnect(0),t))try{e.bufferSource.buffer=Howler._scratchBuffer}catch(e){}return e.bufferSource=null,this}_clearSound(e){e.src=`data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA`}};const Howler=new class{constructor(){this._counter=1e3,this._html5AudioPool=[],this.html5PoolSize=10,this._codecs={},this._howls=[],this._muted=!1,this._volume=1,this._canPlayEvent=`canplaythrough`,this._navigator=null,this.masterGain=null,this.noAudio=!1,this.usingWebAudio=!0,this.autoSuspend=!0,this.ctx=null,this.autoUnlock=!0,this.state=`suspended`,this._audioUnlocked=!1,this._isUnlocking=!1,this._unlockedListeners=null,this._unlockTimeoutId=null,this._scratchBuffer=null,this._suspendTimer=null,this._counter=1e3,this._html5AudioPool=[],this.html5PoolSize=10,this._codecs={},this._howls=[],this._muted=!1,this._volume=1,this._canPlayEvent=`canplaythrough`,this._navigator=typeof window<`u`&&window.navigator?window.navigator:null,this.masterGain=null,this.noAudio=!1,this.usingWebAudio=!0,this.autoSuspend=!0,this.ctx=null,this.autoUnlock=!0,this._setup(),globalPluginManager.setHowlerInstance(this)}volume(e){if(e!==void 0&&(e=parseFloat(String(e)),this.ctx||setupAudioContext(),typeof e==`number`&&e>=0&&e<=1)){if(this._volume=e,this._muted)return this;this.usingWebAudio&&this.ctx&&this.masterGain&&this.masterGain.gain.setValueAtTime(e,this.ctx.currentTime);for(let t=0;t<this._howls.length;t++)if(!this._howls[t]._webAudio){let n=this._howls[t]._getSoundIds();for(let r=0;r<n.length;r++){let i=this._howls[t]._soundById(n[r]);i!=null&&i._node&&isHTMLAudioElement(i._node)&&(i._node.volume=i._volume*e)}}return this}return this._volume}mute(e){this.ctx||setupAudioContext(),this._muted=e,this.usingWebAudio&&this.ctx&&this.masterGain&&this.masterGain.gain.setValueAtTime(e?0:this._volume,this.ctx.currentTime);for(let t=0;t<this._howls.length;t++)if(!this._howls[t]._webAudio){let n=this._howls[t]._getSoundIds();for(let r=0;r<n.length;r++){let i=this._howls[t]._soundById(n[r]);i!=null&&i._node&&isHTMLAudioElement(i._node)&&(i._node.muted=e?!0:i._muted)}}return this}stop(){for(let e=0;e<this._howls.length;e++)this._howls[e].stop();return this}unload(){for(let e=this._howls.length-1;e>=0;e--)this._howls[e].unload();return this.usingWebAudio&&this.ctx&&this.ctx.close!==void 0&&(this.ctx.close(),this.ctx=null,setupAudioContext()),this}codecs(e){return this._codecs[e.replace(/^x-/,``)]}addPlugin(e){return globalPluginManager.register(e),this}removePlugin(e){return globalPluginManager.unregister(e.name),this}hasPlugin(e){return globalPluginManager.isRegistered(e)}_setup(){if(this.state=this.ctx&&this.ctx.state||`suspended`,this._autoSuspend(),!this.usingWebAudio)if(window.Audio!==void 0)try{new window.Audio().oncanplaythrough===void 0&&(this._canPlayEvent=`canplay`)}catch(e){this.noAudio=!0}else this.noAudio=!0;try{new window.Audio().muted&&(this.noAudio=!0)}catch(e){}return this.noAudio||this._setupCodecs(),this}_setupCodecs(){let e=null;try{e=window.Audio===void 0?null:new window.Audio}catch(e){return this}if(!e||typeof e.canPlayType!=`function`)return this;let t=e.canPlayType(`audio/mpeg;`).replace(/^no$/,``);return this._codecs={mp3:!!(t||e.canPlayType(`audio/mp3;`).replace(/^no$/,``)),mpeg:!!t,opus:!!e.canPlayType(`audio/ogg; codecs="opus"`).replace(/^no$/,``),ogg:!!e.canPlayType(`audio/ogg; codecs="vorbis"`).replace(/^no$/,``),oga:!!e.canPlayType(`audio/ogg; codecs="vorbis"`).replace(/^no$/,``),wav:!!(e.canPlayType(`audio/wav; codecs="1"`)||e.canPlayType(`audio/wav`)).replace(/^no$/,``),aac:!!e.canPlayType(`audio/aac;`).replace(/^no$/,``),caf:!!e.canPlayType(`audio/x-caf;`).replace(/^no$/,``),m4a:!!(e.canPlayType(`audio/x-m4a;`)||e.canPlayType(`audio/m4a;`)||e.canPlayType(`audio/aac;`)).replace(/^no$/,``),m4b:!!(e.canPlayType(`audio/x-m4b;`)||e.canPlayType(`audio/m4b;`)||e.canPlayType(`audio/aac;`)).replace(/^no$/,``),mp4:!!(e.canPlayType(`audio/x-mp4;`)||e.canPlayType(`audio/mp4;`)||e.canPlayType(`audio/aac;`)).replace(/^no$/,``),weba:!!e.canPlayType(`audio/webm; codecs="vorbis"`).replace(/^no$/,``),webm:!!e.canPlayType(`audio/webm; codecs="vorbis"`).replace(/^no$/,``),dolby:!!e.canPlayType(`audio/mp4; codecs="ec-3"`).replace(/^no$/,``),flac:!!(e.canPlayType(`audio/x-flac;`)||e.canPlayType(`audio/flac;`)).replace(/^no$/,``)},this}_unlockAudio(){if(this._isUnlocking||this._audioUnlocked||!this.ctx)return;this._isUnlocking=!0,this.autoUnlock=!1,!this._mobileUnloaded&&this.ctx.sampleRate!==44100&&(this._mobileUnloaded=!0,this.unload()),this._scratchBuffer=this.ctx.createBuffer(1,1,22050);let e=()=>{for(;this._html5AudioPool.length<this.html5PoolSize;)try{let e=new window.Audio;e._unlocked=!0,this._releaseHtml5Audio(e)}catch(e){this.noAudio=!0;break}for(let e=0;e<this._howls.length;e++)if(!this._howls[e]._webAudio){let t=this._howls[e]._getSoundIds();for(let n=0;n<t.length;n++){let r=this._howls[e]._soundById(t[n]);r!=null&&r._node&&isHTMLAudioElement(r._node)&&!r._node._unlocked&&(r._node._unlocked=!0,r._node.load())}}this._autoResume();let t=this.ctx,n=t.createBufferSource();n.buffer=this._scratchBuffer,n.connect(t.destination),n.start(0),typeof t.resume==`function`&&t.resume(),n.onended=()=>{n.disconnect(0),this._audioUnlocked=!0,this._isUnlocking=!1,this._unlockedListeners=null,this._unlockTimeoutId!==null&&(clearTimeout(this._unlockTimeoutId),this._unlockTimeoutId=null),document.removeEventListener(`touchstart`,e,!0),document.removeEventListener(`touchend`,e,!0),document.removeEventListener(`click`,e,!0),document.removeEventListener(`keydown`,e,!0);for(let e=0;e<this._howls.length;e++)this._howls[e]._emit(`unlock`)}};this._unlockedListeners=e,document.addEventListener(`touchstart`,e,!0),document.addEventListener(`touchend`,e,!0),document.addEventListener(`click`,e,!0),document.addEventListener(`keydown`,e,!0),this._unlockTimeoutId=setTimeout(()=>{if(!this._audioUnlocked&&this._unlockedListeners){this._isUnlocking=!1;let e=this._unlockedListeners;document.removeEventListener(`touchstart`,e,!0),document.removeEventListener(`touchend`,e,!0),document.removeEventListener(`click`,e,!0),document.removeEventListener(`keydown`,e,!0),this._unlockedListeners=null,this._unlockTimeoutId=null}},15e3)}_obtainHtml5Audio(){if(this._html5AudioPool.length)return this._html5AudioPool.pop();let e=new window.Audio().play();return e&&typeof Promise<`u`&&(e instanceof Promise||typeof e==`object`&&e&&`then`in e&&typeof e.then==`function`)&&e.catch(()=>{console.warn(`HTML5 Audio pool exhausted, returning potentially locked audio object.`)}),new window.Audio}_releaseHtml5Audio(e){return e._unlocked&&this._html5AudioPool.push(e),this}_autoSuspend(){if(!(!this.autoSuspend||!this.ctx||this.ctx.suspend===void 0||!this.usingWebAudio)){for(let e=0;e<this._howls.length;e++)if(this._howls[e]._webAudio){for(let t=0;t<this._howls[e]._sounds.length;t++)if(!this._howls[e]._sounds[t]._paused)return}this._suspendTimer&&clearTimeout(this._suspendTimer),this._suspendTimer=setTimeout(()=>{var e;if(!this.autoSuspend)return;this._suspendTimer=null,this.state=`suspending`;let t=()=>{this.state=`suspended`,this._resumeAfterSuspend&&(delete this._resumeAfterSuspend,this._autoResume())};(e=this.ctx)==null||e.suspend().then(t,t)},15e3)}}_autoResume(){!this.ctx||this.ctx.resume===void 0||!this.usingWebAudio||(this.state===`running`&&this.ctx.state!==`interrupted`&&this._suspendTimer?(clearTimeout(this._suspendTimer),this._suspendTimer=null):this.state===`suspended`||this.state===`running`&&this.ctx.state===`interrupted`?(this.ctx.resume().then(()=>{this.state=`running`;for(let e=0;e<this._howls.length;e++)this._howls[e]._emit(`resume`)}),this._suspendTimer&&(clearTimeout(this._suspendTimer),this._suspendTimer=null)):this.state===`suspending`&&(this._resumeAfterSuspend=!0))}};export{isSpatialAudio as a,globalPluginManager as c,isGainNode as i,Howl as n,HowlerPlugin as o,Sound as r,PluginManager as s,Howler as t};
|
|
6
6
|
//# sourceMappingURL=howler.core.js.map
|