1 line
No EOL
35 KiB
JavaScript
1 line
No EOL
35 KiB
JavaScript
(()=>{var e,n;e=t=>{!function(){"use strict";function e(){this.init()}function n(e){e.src&&0!==e.src.length?this.init(e):console.error("An array of source files must be passed with any new Howl.")}e.prototype={init:function(){var e=this||v;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},volume:function(e){var n=this||v;if(e=parseFloat(e),n.ctx||l(),typeof e<"u"&&0<=e&&e<=1){if(n._volume=e,!n._muted){n.usingWebAudio&&n.masterGain.gain.setValueAtTime(e,v.ctx.currentTime);for(var t=0;t<n._howls.length;t++)if(!n._howls[t]._webAudio)for(var o=n._howls[t]._getSoundIds(),r=0;r<o.length;r++){var a=n._howls[t]._soundById(o[r]);a&&a._node&&(a._node.volume=a._volume*e)}}return n}return n._volume},mute:function(e){var n=this||v;n.ctx||l(),n._muted=e,n.usingWebAudio&&n.masterGain.gain.setValueAtTime(e?0:n._volume,v.ctx.currentTime);for(var t=0;t<n._howls.length;t++)if(!n._howls[t]._webAudio)for(var o=n._howls[t]._getSoundIds(),r=0;r<o.length;r++){var a=n._howls[t]._soundById(o[r]);a&&a._node&&(a._node.muted=!!e||a._muted)}return n},stop:function(){for(var e=this||v,n=0;n<e._howls.length;n++)e._howls[n].stop();return e},unload:function(){for(var e=this||v,n=e._howls.length-1;0<=n;n--)e._howls[n].unload();return e.usingWebAudio&&e.ctx&&typeof e.ctx.close<"u"&&(e.ctx.close(),e.ctx=null,l()),e},codecs:function(e){return(this||v)._codecs[e.replace(/^x-/,"")]},_setup:function(){var e=this||v;if(e.state=e.ctx&&e.ctx.state||"suspended",e._autoSuspend(),!e.usingWebAudio)if(typeof Audio<"u")try{"u"<typeof(new Audio).oncanplaythrough&&(e._canPlayEvent="canplay")}catch{e.noAudio=!0}else e.noAudio=!0;try{(new Audio).muted&&(e.noAudio=!0)}catch{}return e.noAudio||e._setupCodecs(),e},_setupCodecs:function(){var e,n,t,o,r=this||v,a=null;try{a=typeof Audio<"u"?new Audio:null}catch{return r}return a&&"function"==typeof a.canPlayType&&(e=a.canPlayType("audio/mpeg;").replace(/^no$/,""),n=(n=(t=r._navigator?r._navigator.userAgent:"").match(/OPR\/(\d+)/g))&&parseInt(n[0].split("/")[1],10)<33,o=-1!==t.indexOf("Safari")&&-1===t.indexOf("Chrome"),t=t.match(/Version\/(.*?) /),o=o&&t&&parseInt(t[1],10)<15,r._codecs={mp3:!(n||!e&&!a.canPlayType("audio/mp3;").replace(/^no$/,"")),mpeg:!!e,opus:!!a.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/,""),ogg:!!a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),oga:!!a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),wav:!!(a.canPlayType('audio/wav; codecs="1"')||a.canPlayType("audio/wav")).replace(/^no$/,""),aac:!!a.canPlayType("audio/aac;").replace(/^no$/,""),caf:!!a.canPlayType("audio/x-caf;").replace(/^no$/,""),m4a:!!(a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/m4a;")||a.canPlayType("audio/aac;")).replace(/^no$/,""),m4b:!!(a.canPlayType("audio/x-m4b;")||a.canPlayType("audio/m4b;")||a.canPlayType("audio/aac;")).replace(/^no$/,""),mp4:!!(a.canPlayType("audio/x-mp4;")||a.canPlayType("audio/mp4;")||a.canPlayType("audio/aac;")).replace(/^no$/,""),weba:!(o||!a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),webm:!(o||!a.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/,"")),dolby:!!a.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/,""),flac:!!(a.canPlayType("audio/x-flac;")||a.canPlayType("audio/flac;")).replace(/^no$/,"")}),r},_unlockAudio:function(){var u,s=this||v;if(!s._audioUnlocked&&s.ctx)return s._audioUnlocked=!1,s.autoUnlock=!1,s._mobileUnloaded||44100===s.ctx.sampleRate||(s._mobileUnloaded=!0,s.unload()),s._scratchBuffer=s.ctx.createBuffer(1,1,22050),u=function(e){for(;s._html5AudioPool.length<s.html5PoolSize;)try{var n=new Audio;n._unlocked=!0,s._releaseHtml5Audio(n)}catch{s.noAudio=!0;break}for(var t=0;t<s._howls.length;t++)if(!s._howls[t]._webAudio)for(var o=s._howls[t]._getSoundIds(),r=0;r<o.length;r++){var a=s._howls[t]._soundById(o[r]);a&&a._node&&!a._node._unlocked&&(a._node._unlocked=!0,a._node.load())}s._autoResume();var i=s.ctx.createBufferSource();i.buffer=s._scratchBuffer,i.connect(s.ctx.destination),"u"<typeof i.start?i.noteOn(0):i.start(0),"function"==typeof s.ctx.resume&&s.ctx.resume(),i.onended=function(){i.disconnect(0),s._audioUnlocked=!0,document.removeEventListener("touchstart",u,!0),document.removeEventListener("touchend",u,!0),document.removeEventListener("click",u,!0),document.removeEventListener("keydown",u,!0);for(var e=0;e<s._howls.length;e++)s._howls[e]._emit("unlock")}},document.addEventListener("touchstart",u,!0),document.addEventListener("touchend",u,!0),document.addEventListener("click",u,!0),document.addEventListener("keydown",u,!0),s},_obtainHtml5Audio:function(){var e=this||v;return e._html5AudioPool.length?e._html5AudioPool.pop():((e=(new Audio).play())&&typeof Promise<"u"&&(e instanceof Promise||"function"==typeof e.then)&&e.catch(function(){console.warn("HTML5 Audio pool exhausted, returning potentially locked audio object.")}),new Audio)},_releaseHtml5Audio:function(e){var n=this||v;return e._unlocked&&n._html5AudioPool.push(e),n},_autoSuspend:function(){var n=this;if(n.autoSuspend&&n.ctx&&!("u"<typeof n.ctx.suspend)&&v.usingWebAudio){for(var e=0;e<n._howls.length;e++)if(n._howls[e]._webAudio)for(var t=0;t<n._howls[e]._sounds.length;t++)if(!n._howls[e]._sounds[t]._paused)return n;return n._suspendTimer&&clearTimeout(n._suspendTimer),n._suspendTimer=setTimeout(function(){var e;n.autoSuspend&&(n._suspendTimer=null,n.state="suspending",e=function(){n.state="suspended",n._resumeAfterSuspend&&(delete n._resumeAfterSuspend,n._autoResume())},n.ctx.suspend().then(e,e))},3e4),n}},_autoResume:function(){var n=this;if(n.ctx&&!("u"<typeof n.ctx.resume)&&v.usingWebAudio)return"running"===n.state&&"interrupted"!==n.ctx.state&&n._suspendTimer?(clearTimeout(n._suspendTimer),n._suspendTimer=null):"suspended"===n.state||"running"===n.state&&"interrupted"===n.ctx.state?(n.ctx.resume().then(function(){n.state="running";for(var e=0;e<n._howls.length;e++)n._howls[e]._emit("resume")}),n._suspendTimer&&(clearTimeout(n._suspendTimer),n._suspendTimer=null)):"suspending"===n.state&&(n._resumeAfterSuspend=!0),n}};var v=new e,a=(n.prototype={init:function(e){var n=this;return v.ctx||l(),n._autoplay=e.autoplay||!1,n._format="string"!=typeof e.format?e.format:[e.format],n._html5=e.html5||!1,n._muted=e.mute||!1,n._loop=e.loop||!1,n._pool=e.pool||5,n._preload="boolean"!=typeof e.preload&&"metadata"!==e.preload||e.preload,n._rate=e.rate||1,n._sprite=e.sprite||{},n._src="string"!=typeof e.src?e.src:[e.src],n._volume=void 0!==e.volume?e.volume:1,n._xhr={method:e.xhr&&e.xhr.method?e.xhr.method:"GET",headers:e.xhr&&e.xhr.headers?e.xhr.headers:null,withCredentials:!(!e.xhr||!e.xhr.withCredentials)&&e.xhr.withCredentials},n._duration=0,n._state="unloaded",n._sounds=[],n._endTimers={},n._queue=[],n._playLock=!1,n._onend=e.onend?[{fn:e.onend}]:[],n._onfade=e.onfade?[{fn:e.onfade}]:[],n._onload=e.onload?[{fn:e.onload}]:[],n._onloaderror=e.onloaderror?[{fn:e.onloaderror}]:[],n._onplayerror=e.onplayerror?[{fn:e.onplayerror}]:[],n._onpause=e.onpause?[{fn:e.onpause}]:[],n._onplay=e.onplay?[{fn:e.onplay}]:[],n._onstop=e.onstop?[{fn:e.onstop}]:[],n._onmute=e.onmute?[{fn:e.onmute}]:[],n._onvolume=e.onvolume?[{fn:e.onvolume}]:[],n._onrate=e.onrate?[{fn:e.onrate}]:[],n._onseek=e.onseek?[{fn:e.onseek}]:[],n._onunlock=e.onunlock?[{fn:e.onunlock}]:[],n._onresume=[],n._webAudio=v.usingWebAudio&&!n._html5,typeof v.ctx<"u"&&v.ctx&&v.autoUnlock&&v._unlockAudio(),v._howls.push(n),n._autoplay&&n._queue.push({event:"play",action:function(){n.play()}}),n._preload&&"none"!==n._preload&&n.load(),n},load:function(){var e=this,n=null;if(v.noAudio)e._emit("loaderror",null,"No audio support.");else{"string"==typeof e._src&&(e._src=[e._src]);for(var t,o,r=0;r<e._src.length;r++){if(e._format&&e._format[r])t=e._format[r];else{if("string"!=typeof(o=e._src[r])){e._emit("loaderror",null,"Non-string found in selected audio sources - ignoring.");continue}t=(t=(t=/^data:audio\/([^;,]+);/i.exec(o))||/\.([^.]+)$/.exec(o.split("?",1)[0]))&&t[1].toLowerCase()}if(t||console.warn('No file extension was found. Consider using the "format" property or specify an extension.'),t&&v.codecs(t)){n=e._src[r];break}}if(n)return e._src=n,e._state="loading","https:"===window.location.protocol&&"http:"===n.slice(0,5)&&(e._html5=!0,e._webAudio=!1),new a(e),e._webAudio&&u(e),e;e._emit("loaderror",null,"No codec support for selected audio sources.")}},play:function(n,t){var o=this,e=null;if("number"==typeof n)e=n,n=null;else{if("string"==typeof n&&"loaded"===o._state&&!o._sprite[n])return null;if("u"<typeof n&&(n="__default",!o._playLock)){for(var r=0,a=0;a<o._sounds.length;a++)o._sounds[a]._paused&&!o._sounds[a]._ended&&(r++,e=o._sounds[a]._id);1===r?n=null:e=null}}var i,u=e?o._soundById(e):o._inactiveSound();if(!u)return null;if(e&&!n&&(n=u._sprite||"__default"),"loaded"!==o._state)return u._sprite=n,u._ended=!1,i=u._id,o._queue.push({event:"play",action:function(){o.play(i)}}),i;if(e&&!u._paused)return t||o._loadQueue("play"),u._id;o._webAudio&&v._autoResume();var s,_,d,l,c=Math.max(0,0<u._seek?u._seek:o._sprite[n][0]/1e3),p=Math.max(0,(o._sprite[n][0]+o._sprite[n][1])/1e3-c),f=1e3*p/Math.abs(u._rate),m=o._sprite[n][0]/1e3,h=(o._sprite[n][0]+o._sprite[n][1])/1e3,y=(u._sprite=n,u._ended=!1,function(){u._paused=!1,u._seek=c,u._start=m,u._stop=h,u._loop=!(!u._loop&&!o._sprite[n][2])});if(!(h<=c))return s=u._node,o._webAudio?(d=function(){o._playLock=!1,y(),o._refreshBuffer(u);var e=u._muted||o._muted?0:u._volume;s.gain.setValueAtTime(e,v.ctx.currentTime),u._playStart=v.ctx.currentTime,"u"<typeof s.bufferSource.start?u._loop?s.bufferSource.noteGrainOn(0,c,86400):s.bufferSource.noteGrainOn(0,c,p):u._loop?s.bufferSource.start(0,c,86400):s.bufferSource.start(0,c,p),f!==1/0&&(o._endTimers[u._id]=setTimeout(o._ended.bind(o,u),f)),t||setTimeout(function(){o._emit("play",u._id),o._loadQueue()},0)},"running"===v.state&&"interrupted"!==v.ctx.state?d():(o._playLock=!0,o.once("resume",d),o._clearTimer(u._id))):(_=function(){s.currentTime=c,s.muted=u._muted||o._muted||v._muted||s.muted,s.volume=u._volume*v.volume(),s.playbackRate=u._rate;try{var e=s.play();(e&&typeof Promise<"u"&&(e instanceof Promise||"function"==typeof e.then)?(o._playLock=!0,y(),e.then(function(){o._playLock=!1,s._unlocked=!0,t?o._loadQueue():o._emit("play",u._id)}).catch(function(){o._playLock=!1,o._emit("playerror",u._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."),u._ended=!0,u._paused=!0})):t||(o._playLock=!1,y(),o._emit("play",u._id)),s.playbackRate=u._rate,s.paused)?o._emit("playerror",u._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."):"__default"!==n||u._loop?o._endTimers[u._id]=setTimeout(o._ended.bind(o,u),f):(o._endTimers[u._id]=function(){o._ended(u),s.removeEventListener("ended",o._endTimers[u._id],!1)},s.addEventListener("ended",o._endTimers[u._id],!1))}catch(e){o._emit("playerror",u._id,e)}},"data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA"===s.src&&(s.src=o._src,s.load()),d=window&&window.ejecta||!s.readyState&&v._navigator.isCocoonJS,3<=s.readyState||d?_():(o._playLock=!0,o._state="loading",l=function(){o._state="loaded",_(),s.removeEventListener(v._canPlayEvent,l,!1)},s.addEventListener(v._canPlayEvent,l,!1),o._clearTimer(u._id))),u._id;o._ended(u)},pause:function(e){var n=this;if("loaded"!==n._state||n._playLock)n._queue.push({event:"pause",action:function(){n.pause(e)}});else for(var t=n._getSoundIds(e),o=0;o<t.length;o++){n._clearTimer(t[o]);var r=n._soundById(t[o]);if(r&&!r._paused&&(r._seek=n.seek(t[o]),r._rateSeek=0,r._paused=!0,n._stopFade(t[o]),r._node))if(n._webAudio){if(!r._node.bufferSource)continue;"u"<typeof r._node.bufferSource.stop?r._node.bufferSource.noteOff(0):r._node.bufferSource.stop(0),n._cleanBuffer(r._node)}else isNaN(r._node.duration)&&r._node.duration!==1/0||r._node.pause();arguments[1]||n._emit("pause",r?r._id:null)}return n},stop:function(e,n){var t=this;if("loaded"!==t._state||t._playLock)t._queue.push({event:"stop",action:function(){t.stop(e)}});else for(var o=t._getSoundIds(e),r=0;r<o.length;r++){t._clearTimer(o[r]);var a=t._soundById(o[r]);a&&(a._seek=a._start||0,a._rateSeek=0,a._paused=!0,a._ended=!0,t._stopFade(o[r]),a._node&&(t._webAudio?a._node.bufferSource&&("u"<typeof a._node.bufferSource.stop?a._node.bufferSource.noteOff(0):a._node.bufferSource.stop(0),t._cleanBuffer(a._node)):isNaN(a._node.duration)&&a._node.duration!==1/0||(a._node.currentTime=a._start||0,a._node.pause(),a._node.duration!==1/0)||t._clearSound(a._node)),n||t._emit("stop",a._id))}return t},mute:function(e,n){var t=this;if("loaded"!==t._state||t._playLock)t._queue.push({event:"mute",action:function(){t.mute(e,n)}});else{if("u"<typeof n){if("boolean"!=typeof e)return t._muted;t._muted=e}for(var o=t._getSoundIds(n),r=0;r<o.length;r++){var a=t._soundById(o[r]);a&&(a._muted=e,a._interval&&t._stopFade(a._id),t._webAudio&&a._node?a._node.gain.setValueAtTime(e?0:a._volume,v.ctx.currentTime):a._node&&(a._node.muted=!!v._muted||e),t._emit("mute",a._id))}}return t},volume:function(){var e,n,t=this,o=arguments;if(0===o.length)return t._volume;if(1===o.length||2===o.length&&"u"<typeof o[1]?0<=t._getSoundIds().indexOf(o[0])?r=parseInt(o[0],10):e=parseFloat(o[0]):2<=o.length&&(e=parseFloat(o[0]),r=parseInt(o[1],10)),!(typeof e<"u"&&0<=e&&e<=1))return(n=r?t._soundById(r):t._sounds[0])?n._volume:0;if("loaded"!==t._state||t._playLock)t._queue.push({event:"volume",action:function(){t.volume.apply(t,o)}});else{"u"<typeof r&&(t._volume=e);for(var r=t._getSoundIds(r),a=0;a<r.length;a++)(n=t._soundById(r[a]))&&(n._volume=e,o[2]||t._stopFade(r[a]),t._webAudio&&n._node&&!n._muted?n._node.gain.setValueAtTime(e,v.ctx.currentTime):n._node&&!n._muted&&(n._node.volume=e*v.volume()),t._emit("volume",n._id))}return t},fade:function(e,n,t,o){var r=this;if("loaded"!==r._state||r._playLock)r._queue.push({event:"fade",action:function(){r.fade(e,n,t,o)}});else{e=Math.min(Math.max(0,parseFloat(e)),1),n=Math.min(Math.max(0,parseFloat(n)),1),t=parseFloat(t),r.volume(e,o);for(var a=r._getSoundIds(o),i=0;i<a.length;i++){var u,s,_=r._soundById(a[i]);_&&(o||r._stopFade(a[i]),r._webAudio&&!_._muted&&(s=(u=v.ctx.currentTime)+t/1e3,_._volume=e,_._node.gain.setValueAtTime(e,u),_._node.gain.linearRampToValueAtTime(n,s)),r._startFadeInterval(_,e,n,t,a[i],"u"<typeof o))}}return r},_startFadeInterval:function(n,t,o,r,e,a){var i=this,u=t,s=o-t,_=Math.abs(s/.01),_=Math.max(4,0<_?r/_:r),d=Date.now();n._fadeTo=o,n._interval=setInterval(function(){var e=(Date.now()-d)/r;d=Date.now(),u+=s*e,u=Math.round(100*u)/100,u=s<0?Math.max(o,u):Math.min(o,u),i._webAudio?n._volume=u:i.volume(u,n._id,!0),a&&(i._volume=u),(o<t&&u<=o||t<o&&o<=u)&&(clearInterval(n._interval),n._interval=null,n._fadeTo=null,i.volume(o,n._id),i._emit("fade",n._id))},_)},_stopFade:function(e){var n=this,t=n._soundById(e);return t&&t._interval&&(n._webAudio&&t._node.gain.cancelScheduledValues(v.ctx.currentTime),clearInterval(t._interval),t._interval=null,n.volume(t._fadeTo,e),t._fadeTo=null,n._emit("fade",e)),n},loop:function(){var e,n,t,o=this,r=arguments;if(0===r.length)return o._loop;if(1===r.length){if("boolean"!=typeof r[0])return!!(t=o._soundById(parseInt(r[0],10)))&&t._loop;o._loop=e=r[0]}else 2===r.length&&(e=r[0],n=parseInt(r[1],10));for(var a=o._getSoundIds(n),i=0;i<a.length;i++)(t=o._soundById(a[i]))&&(t._loop=e,o._webAudio)&&t._node&&t._node.bufferSource&&(t._node.bufferSource.loop=e)&&(t._node.bufferSource.loopStart=t._start||0,t._node.bufferSource.loopEnd=t._stop,o.playing(a[i]))&&(o.pause(a[i],!0),o.play(a[i],!0));return o},rate:function(){var e,n=this,t=arguments;if(0===t.length?a=n._sounds[0]._id:1===t.length?0<=n._getSoundIds().indexOf(t[0])?a=parseInt(t[0],10):e=parseFloat(t[0]):2===t.length&&(e=parseFloat(t[0]),a=parseInt(t[1],10)),"number"!=typeof e)return((r=n._soundById(a))||n)._rate;if("loaded"!==n._state||n._playLock)n._queue.push({event:"rate",action:function(){n.rate.apply(n,t)}});else{"u"<typeof a&&(n._rate=e);for(var o,r,a=n._getSoundIds(a),i=0;i<a.length;i++)(r=n._soundById(a[i]))&&(n.playing(a[i])&&(r._rateSeek=n.seek(a[i]),r._playStart=n._webAudio?v.ctx.currentTime:r._playStart),r._rate=e,n._webAudio&&r._node&&r._node.bufferSource?r._node.bufferSource.playbackRate.setValueAtTime(e,v.ctx.currentTime):r._node&&(r._node.playbackRate=e),o=n.seek(a[i]),o=1e3*((n._sprite[r._sprite][0]+n._sprite[r._sprite][1])/1e3-o)/Math.abs(r._rate),!n._endTimers[a[i]]&&r._paused||(n._clearTimer(a[i]),n._endTimers[a[i]]=setTimeout(n._ended.bind(n,r),o)),n._emit("rate",r._id))}return n},seek:function(){var e,n,t=this,o=arguments;if(0===o.length?t._sounds.length&&(n=t._sounds[0]._id):1===o.length?0<=t._getSoundIds().indexOf(o[0])?n=parseInt(o[0],10):t._sounds.length&&(n=t._sounds[0]._id,e=parseFloat(o[0])):2===o.length&&(e=parseFloat(o[0]),n=parseInt(o[1],10)),"u"<typeof n)return 0;if("number"!=typeof e||"loaded"===t._state&&!t._playLock){var r,a,i,u,s,_=t._soundById(n);if(_){if(!("number"==typeof e&&0<=e))return t._webAudio?(u=t.playing(n)?v.ctx.currentTime-_._playStart:0,s=_._rateSeek?_._rateSeek-_._seek:0,_._seek+(s+u*Math.abs(_._rate))):_._node.currentTime;(r=t.playing(n))&&t.pause(n,!0),_._seek=e,_._ended=!1,t._clearTimer(n),t._webAudio||!_._node||isNaN(_._node.duration)||(_._node.currentTime=e),a=function(){r&&t.play(n,!0),t._emit("seek",n)},r&&!t._webAudio?(i=function(){t._playLock?setTimeout(i,0):a()},setTimeout(i,0)):a()}}else t._queue.push({event:"seek",action:function(){t.seek.apply(t,o)}});return t},playing:function(e){if("number"==typeof e)return!!(e=this._soundById(e))&&!e._paused;for(var n=0;n<this._sounds.length;n++)if(!this._sounds[n]._paused)return!0;return!1},duration:function(e){var n=this._duration,e=this._soundById(e);return n=e?this._sprite[e._sprite][1]/1e3:n},state:function(){return this._state},unload:function(){for(var e=this,n=e._sounds,t=0;t<n.length;t++)n[t]._paused||e.stop(n[t]._id),e._webAudio||(e._clearSound(n[t]._node),n[t]._node.removeEventListener("error",n[t]._errorFn,!1),n[t]._node.removeEventListener(v._canPlayEvent,n[t]._loadFn,!1),n[t]._node.removeEventListener("ended",n[t]._endFn,!1),v._releaseHtml5Audio(n[t]._node)),delete n[t]._node,e._clearTimer(n[t]._id);for(var o=v._howls.indexOf(e),r=(0<=o&&v._howls.splice(o,1),!0),t=0;t<v._howls.length;t++)if(v._howls[t]._src===e._src||0<=e._src.indexOf(v._howls[t]._src)){r=!1;break}return i&&r&&delete i[e._src],v.noAudio=!1,e._state="unloaded",e._sounds=[],null},on:function(e,n,t,o){e=this["_on"+e];return"function"==typeof n&&e.push(o?{id:t,fn:n,once:o}:{id:t,fn:n}),this},off:function(e,n,t){var o=this,r=o["_on"+e],a=0;if("number"==typeof n&&(t=n,n=null),n||t)for(a=0;a<r.length;a++){var i=t===r[a].id;if(n===r[a].fn&&i||!n&&i){r.splice(a,1);break}}else if(e)o["_on"+e]=[];else for(var u=Object.keys(o),a=0;a<u.length;a++)0===u[a].indexOf("_on")&&Array.isArray(o[u[a]])&&(o[u[a]]=[]);return o},once:function(e,n,t){return this.on(e,n,t,1),this},_emit:function(e,n,t){for(var o=this,r=o["_on"+e],a=r.length-1;0<=a;a--)r[a].id&&r[a].id!==n&&"load"!==e||(setTimeout(function(e){e.call(this,n,t)}.bind(o,r[a].fn),0),!r[a].once)||o.off(e,r[a].fn,r[a].id);return o._loadQueue(e),o},_loadQueue:function(e){var n,t=this;return 0<t._queue.length&&((n=t._queue[0]).event===e&&(t._queue.shift(),t._loadQueue()),e||n.action()),t},_ended:function(e){var n,t=this,o=e._sprite;return!t._webAudio&&e._node&&!e._node.paused&&!e._node.ended&&e._node.currentTime<e._stop?setTimeout(t._ended.bind(t,e),100):(o=!(!e._loop&&!t._sprite[o][2]),t._emit("end",e._id),!t._webAudio&&o&&t.stop(e._id,!0).play(e._id),t._webAudio&&o&&(t._emit("play",e._id),e._seek=e._start||0,e._rateSeek=0,e._playStart=v.ctx.currentTime,n=1e3*(e._stop-e._start)/Math.abs(e._rate),t._endTimers[e._id]=setTimeout(t._ended.bind(t,e),n)),t._webAudio&&!o&&(e._paused=!0,e._ended=!0,e._seek=e._start||0,e._rateSeek=0,t._clearTimer(e._id),t._cleanBuffer(e._node),v._autoSuspend()),t._webAudio||o||t.stop(e._id,!0)),t},_clearTimer:function(e){var n,t=this;return t._endTimers[e]&&("function"!=typeof t._endTimers[e]?clearTimeout(t._endTimers[e]):(n=t._soundById(e))&&n._node&&n._node.removeEventListener("ended",t._endTimers[e],!1),delete t._endTimers[e]),t},_soundById:function(e){for(var n=0;n<this._sounds.length;n++)if(e===this._sounds[n]._id)return this._sounds[n];return null},_inactiveSound:function(){var e=this;e._drain();for(var n=0;n<e._sounds.length;n++)if(e._sounds[n]._ended)return e._sounds[n].reset();return new a(e)},_drain:function(){var e=this,n=e._pool,t=0,o=0;if(!(e._sounds.length<n)){for(o=0;o<e._sounds.length;o++)e._sounds[o]._ended&&t++;for(o=e._sounds.length-1;0<=o;o--){if(t<=n)return;e._sounds[o]._ended&&(e._webAudio&&e._sounds[o]._node&&e._sounds[o]._node.disconnect(0),e._sounds.splice(o,1),t--)}}},_getSoundIds:function(e){if("u"<typeof e){for(var n=[],t=0;t<this._sounds.length;t++)n.push(this._sounds[t]._id);return n}return[e]},_refreshBuffer:function(e){return e._node.bufferSource=v.ctx.createBufferSource(),e._node.bufferSource.buffer=i[this._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,v.ctx.currentTime),this},_cleanBuffer:function(e){var n=v._navigator&&0<=v._navigator.vendor.indexOf("Apple");if(e.bufferSource){if(v._scratchBuffer&&e.bufferSource&&(e.bufferSource.onended=null,e.bufferSource.disconnect(0),n))try{e.bufferSource.buffer=v._scratchBuffer}catch{}e.bufferSource=null}return this},_clearSound:function(e){/MSIE |Trident\//.test(v._navigator&&v._navigator.userAgent)||(e.src="data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA")}},function(e){this._parent=e,this.init()}),i=(a.prototype={init:function(){var e=this,n=e._parent;return e._muted=n._muted,e._loop=n._loop,e._volume=n._volume,e._rate=n._rate,e._seek=0,e._paused=!0,e._ended=!0,e._sprite="__default",e._id=++v._counter,n._sounds.push(e),e.create(),e},create:function(){var e=this,n=e._parent,t=v._muted||e._muted||e._parent._muted?0:e._volume;return n._webAudio?(e._node="u"<typeof v.ctx.createGain?v.ctx.createGainNode():v.ctx.createGain(),e._node.gain.setValueAtTime(t,v.ctx.currentTime),e._node.paused=!0,e._node.connect(v.masterGain)):v.noAudio||(e._node=v._obtainHtml5Audio(),e._errorFn=e._errorListener.bind(e),e._node.addEventListener("error",e._errorFn,!1),e._loadFn=e._loadListener.bind(e),e._node.addEventListener(v._canPlayEvent,e._loadFn,!1),e._endFn=e._endListener.bind(e),e._node.addEventListener("ended",e._endFn,!1),e._node.src=n._src,e._node.preload=!0===n._preload?"auto":n._preload,e._node.volume=t*v.volume(),e._node.load()),e},reset:function(){var e=this,n=e._parent;return e._muted=n._muted,e._loop=n._loop,e._volume=n._volume,e._rate=n._rate,e._seek=0,e._rateSeek=0,e._paused=!0,e._ended=!0,e._sprite="__default",e._id=++v._counter,e},_errorListener:function(){var e=this;e._parent._emit("loaderror",e._id,e._node.error?e._node.error.code:0),e._node.removeEventListener("error",e._errorFn,!1)},_loadListener:function(){var e=this._parent;e._duration=Math.ceil(10*this._node.duration)/10,0===Object.keys(e._sprite).length&&(e._sprite={__default:[0,1e3*e._duration]}),"loaded"!==e._state&&(e._state="loaded",e._emit("load"),e._loadQueue()),this._node.removeEventListener(v._canPlayEvent,this._loadFn,!1)},_endListener:function(){var e=this,n=e._parent;n._duration===1/0&&(n._duration=Math.ceil(10*e._node.duration)/10,n._sprite.__default[1]===1/0&&(n._sprite.__default[1]=1e3*n._duration),n._ended(e)),e._node.removeEventListener("ended",e._endFn,!1)}},{}),u=function(n){var e=n._src;if(i[e])n._duration=i[e].duration,d(n);else if(/^data:[^;]+;base64,/.test(e)){for(var t=atob(e.split(",")[1]),o=new Uint8Array(t.length),r=0;r<t.length;++r)o[r]=t.charCodeAt(r);_(o.buffer,n)}else{var a=new XMLHttpRequest;a.open(n._xhr.method,e,!0),a.withCredentials=n._xhr.withCredentials,a.responseType="arraybuffer",n._xhr.headers&&Object.keys(n._xhr.headers).forEach(function(e){a.setRequestHeader(e,n._xhr.headers[e])}),a.onload=function(){var e=(a.status+"")[0];"0"!==e&&"2"!==e&&"3"!==e?n._emit("loaderror",null,"Failed loading audio file with status: "+a.status+"."):_(a.response,n)},a.onerror=function(){n._webAudio&&(n._html5=!0,n._webAudio=!1,n._sounds=[],delete i[e],n.load())},s(a)}},s=function(e){try{e.send()}catch{e.onerror()}},_=function(e,n){function t(){n._emit("loaderror",null,"Decoding audio data failed.")}function o(e){e&&0<n._sounds.length?(i[n._src]=e,d(n,e)):t()}typeof Promise<"u"&&1===v.ctx.decodeAudioData.length?v.ctx.decodeAudioData(e).then(o).catch(t):v.ctx.decodeAudioData(e,o,t)},d=function(e,n){n&&!e._duration&&(e._duration=n.duration),0===Object.keys(e._sprite).length&&(e._sprite={__default:[0,1e3*e._duration]}),"loaded"!==e._state&&(e._state="loaded",e._emit("load"),e._loadQueue())},l=function(){if(v.usingWebAudio){try{typeof AudioContext<"u"?v.ctx=new AudioContext:typeof webkitAudioContext<"u"?v.ctx=new webkitAudioContext:v.usingWebAudio=!1}catch{v.usingWebAudio=!1}v.ctx||(v.usingWebAudio=!1);var e=/iP(hone|od|ad)/.test(v._navigator&&v._navigator.platform),n=v._navigator&&v._navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),n=n?parseInt(n[1],10):null;e&&n&&n<9&&(e=/safari/.test(v._navigator&&v._navigator.userAgent.toLowerCase()),v._navigator)&&!e&&(v.usingWebAudio=!1),v.usingWebAudio&&(v.masterGain="u"<typeof v.ctx.createGain?v.ctx.createGainNode():v.ctx.createGain(),v.masterGain.gain.setValueAtTime(v._muted?0:v._volume,v.ctx.currentTime),v.masterGain.connect(v.ctx.destination)),v._setup()}};"function"==typeof define&&define.amd&&define([],function(){return{Howler:v,Howl:n}}),typeof t<"u"&&(t.Howler=v,t.Howl=n),typeof global<"u"?(global.HowlerGlobal=e,global.Howler=v,global.Howl=n,global.Sound=a):typeof window<"u"&&(window.HowlerGlobal=e,window.Howler=v,window.Howl=n,window.Sound=a)}(),function(){"use strict";HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(e){var n=this;if(n.ctx&&n.ctx.listener)for(var t=n._howls.length-1;0<=t;t--)n._howls[t].stereo(e);return n},HowlerGlobal.prototype.pos=function(e,n,t){var o=this;if(o.ctx&&o.ctx.listener){if(n="number"!=typeof n?o._pos[1]:n,t="number"!=typeof t?o._pos[2]:t,"number"!=typeof e)return o._pos;o._pos=[e,n,t],typeof o.ctx.listener.positionX<"u"?(o.ctx.listener.positionX.setTargetAtTime(o._pos[0],Howler.ctx.currentTime,.1),o.ctx.listener.positionY.setTargetAtTime(o._pos[1],Howler.ctx.currentTime,.1),o.ctx.listener.positionZ.setTargetAtTime(o._pos[2],Howler.ctx.currentTime,.1)):o.ctx.listener.setPosition(o._pos[0],o._pos[1],o._pos[2])}return o},HowlerGlobal.prototype.orientation=function(e,n,t,o,r,a){var i=this;if(i.ctx&&i.ctx.listener){var u=i._orientation;if(n="number"!=typeof n?u[1]:n,t="number"!=typeof t?u[2]:t,o="number"!=typeof o?u[3]:o,r="number"!=typeof r?u[4]:r,a="number"!=typeof a?u[5]:a,"number"!=typeof e)return u;i._orientation=[e,n,t,o,r,a],typeof i.ctx.listener.forwardX<"u"?(i.ctx.listener.forwardX.setTargetAtTime(e,Howler.ctx.currentTime,.1),i.ctx.listener.forwardY.setTargetAtTime(n,Howler.ctx.currentTime,.1),i.ctx.listener.forwardZ.setTargetAtTime(t,Howler.ctx.currentTime,.1),i.ctx.listener.upX.setTargetAtTime(o,Howler.ctx.currentTime,.1),i.ctx.listener.upY.setTargetAtTime(r,Howler.ctx.currentTime,.1),i.ctx.listener.upZ.setTargetAtTime(a,Howler.ctx.currentTime,.1)):i.ctx.listener.setOrientation(e,n,t,o,r,a)}return i},Howl.prototype.init=(r=Howl.prototype.init,function(e){var n=this;return n._orientation=e.orientation||[1,0,0],n._stereo=e.stereo||null,n._pos=e.pos||null,n._pannerAttr={coneInnerAngle:typeof e.coneInnerAngle<"u"?e.coneInnerAngle:360,coneOuterAngle:typeof e.coneOuterAngle<"u"?e.coneOuterAngle:360,coneOuterGain:typeof e.coneOuterGain<"u"?e.coneOuterGain:0,distanceModel:typeof e.distanceModel<"u"?e.distanceModel:"inverse",maxDistance:typeof e.maxDistance<"u"?e.maxDistance:1e4,panningModel:typeof e.panningModel<"u"?e.panningModel:"HRTF",refDistance:typeof e.refDistance<"u"?e.refDistance:1,rolloffFactor:typeof e.rolloffFactor<"u"?e.rolloffFactor:1},n._onstereo=e.onstereo?[{fn:e.onstereo}]:[],n._onpos=e.onpos?[{fn:e.onpos}]:[],n._onorientation=e.onorientation?[{fn:e.onorientation}]:[],r.call(this,e)}),Howl.prototype.stereo=function(e,n){var t=this;if(t._webAudio)if("loaded"!==t._state)t._queue.push({event:"stereo",action:function(){t.stereo(e,n)}});else{var o="u"<typeof Howler.ctx.createStereoPanner?"spatial":"stereo";if("u"<typeof n){if("number"!=typeof e)return t._stereo;t._stereo=e,t._pos=[e,0,0]}for(var r=t._getSoundIds(n),a=0;a<r.length;a++){var i=t._soundById(r[a]);if(i){if("number"!=typeof e)return i._stereo;i._stereo=e,i._pos=[e,0,0],i._node&&(i._pannerAttr.panningModel="equalpower",i._panner&&i._panner.pan||_(i,o),"spatial"==o?typeof i._panner.positionX<"u"?(i._panner.positionX.setValueAtTime(e,Howler.ctx.currentTime),i._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),i._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):i._panner.setPosition(e,0,0):i._panner.pan.setValueAtTime(e,Howler.ctx.currentTime)),t._emit("stereo",i._id)}}}return t},Howl.prototype.pos=function(e,n,t,o){var r=this;if(r._webAudio)if("loaded"!==r._state)r._queue.push({event:"pos",action:function(){r.pos(e,n,t,o)}});else{if(n="number"!=typeof n?0:n,t="number"!=typeof t?-.5:t,"u"<typeof o){if("number"!=typeof e)return r._pos;r._pos=[e,n,t]}for(var a=r._getSoundIds(o),i=0;i<a.length;i++){var u=r._soundById(a[i]);if(u){if("number"!=typeof e)return u._pos;u._pos=[e,n,t],u._node&&(u._panner&&!u._panner.pan||_(u,"spatial"),typeof u._panner.positionX<"u"?(u._panner.positionX.setValueAtTime(e,Howler.ctx.currentTime),u._panner.positionY.setValueAtTime(n,Howler.ctx.currentTime),u._panner.positionZ.setValueAtTime(t,Howler.ctx.currentTime)):u._panner.setPosition(e,n,t)),r._emit("pos",u._id)}}}return r},Howl.prototype.orientation=function(e,n,t,o){var r=this;if(r._webAudio)if("loaded"!==r._state)r._queue.push({event:"orientation",action:function(){r.orientation(e,n,t,o)}});else{if(n="number"!=typeof n?r._orientation[1]:n,t="number"!=typeof t?r._orientation[2]:t,"u"<typeof o){if("number"!=typeof e)return r._orientation;r._orientation=[e,n,t]}for(var a=r._getSoundIds(o),i=0;i<a.length;i++){var u=r._soundById(a[i]);if(u){if("number"!=typeof e)return u._orientation;u._orientation=[e,n,t],u._node&&(u._panner||(u._pos||(u._pos=r._pos||[0,0,-.5]),_(u,"spatial")),typeof u._panner.orientationX<"u"?(u._panner.orientationX.setValueAtTime(e,Howler.ctx.currentTime),u._panner.orientationY.setValueAtTime(n,Howler.ctx.currentTime),u._panner.orientationZ.setValueAtTime(t,Howler.ctx.currentTime)):u._panner.setOrientation(e,n,t)),r._emit("orientation",u._id)}}}return r},Howl.prototype.pannerAttr=function(){var e,n,t=this,o=arguments;if(t._webAudio){if(0===o.length)return t._pannerAttr;if(1===o.length){if("object"!=typeof o[0])return((i=t._soundById(parseInt(o[0],10)))||t)._pannerAttr;e=o[0],"u"<typeof n&&(e.pannerAttr||(e.pannerAttr={coneInnerAngle:e.coneInnerAngle,coneOuterAngle:e.coneOuterAngle,coneOuterGain:e.coneOuterGain,distanceModel:e.distanceModel,maxDistance:e.maxDistance,refDistance:e.refDistance,rolloffFactor:e.rolloffFactor,panningModel:e.panningModel}),t._pannerAttr={coneInnerAngle:typeof e.pannerAttr.coneInnerAngle<"u"?e.pannerAttr.coneInnerAngle:t._coneInnerAngle,coneOuterAngle:typeof e.pannerAttr.coneOuterAngle<"u"?e.pannerAttr.coneOuterAngle:t._coneOuterAngle,coneOuterGain:typeof e.pannerAttr.coneOuterGain<"u"?e.pannerAttr.coneOuterGain:t._coneOuterGain,distanceModel:typeof e.pannerAttr.distanceModel<"u"?e.pannerAttr.distanceModel:t._distanceModel,maxDistance:typeof e.pannerAttr.maxDistance<"u"?e.pannerAttr.maxDistance:t._maxDistance,refDistance:typeof e.pannerAttr.refDistance<"u"?e.pannerAttr.refDistance:t._refDistance,rolloffFactor:typeof e.pannerAttr.rolloffFactor<"u"?e.pannerAttr.rolloffFactor:t._rolloffFactor,panningModel:typeof e.pannerAttr.panningModel<"u"?e.pannerAttr.panningModel:t._panningModel})}else 2===o.length&&(e=o[0],n=parseInt(o[1],10));for(var r,a,i,u=t._getSoundIds(n),s=0;s<u.length;s++)(i=t._soundById(u[s]))&&(r=i._pannerAttr,r={coneInnerAngle:(typeof e.coneInnerAngle<"u"?e:r).coneInnerAngle,coneOuterAngle:(typeof e.coneOuterAngle<"u"?e:r).coneOuterAngle,coneOuterGain:(typeof e.coneOuterGain<"u"?e:r).coneOuterGain,distanceModel:(typeof e.distanceModel<"u"?e:r).distanceModel,maxDistance:(typeof e.maxDistance<"u"?e:r).maxDistance,refDistance:(typeof e.refDistance<"u"?e:r).refDistance,rolloffFactor:(typeof e.rolloffFactor<"u"?e:r).rolloffFactor,panningModel:(typeof e.panningModel<"u"?e:r).panningModel},(a=i._panner)||(i._pos||(i._pos=t._pos||[0,0,-.5]),_(i,"spatial"),a=i._panner),a.coneInnerAngle=r.coneInnerAngle,a.coneOuterAngle=r.coneOuterAngle,a.coneOuterGain=r.coneOuterGain,a.distanceModel=r.distanceModel,a.maxDistance=r.maxDistance,a.refDistance=r.refDistance,a.rolloffFactor=r.rolloffFactor,a.panningModel=r.panningModel)}return t},Sound.prototype.init=(o=Sound.prototype.init,function(){var e=this,n=e._parent;e._orientation=n._orientation,e._stereo=n._stereo,e._pos=n._pos,e._pannerAttr=n._pannerAttr,o.call(this),e._stereo?n.stereo(e._stereo):e._pos&&n.pos(e._pos[0],e._pos[1],e._pos[2],e._id)}),Sound.prototype.reset=(t=Sound.prototype.reset,function(){var e=this,n=e._parent;return e._orientation=n._orientation,e._stereo=n._stereo,e._pos=n._pos,e._pannerAttr=n._pannerAttr,e._stereo?n.stereo(e._stereo):e._pos?n.pos(e._pos[0],e._pos[1],e._pos[2],e._id):e._panner&&(e._panner.disconnect(0),e._panner=void 0,n._refreshBuffer(e)),t.call(this)});var t,o,r,_=function(e,n){"spatial"===(n=n||"spatial")?(e._panner=Howler.ctx.createPanner(),e._panner.coneInnerAngle=e._pannerAttr.coneInnerAngle,e._panner.coneOuterAngle=e._pannerAttr.coneOuterAngle,e._panner.coneOuterGain=e._pannerAttr.coneOuterGain,e._panner.distanceModel=e._pannerAttr.distanceModel,e._panner.maxDistance=e._pannerAttr.maxDistance,e._panner.refDistance=e._pannerAttr.refDistance,e._panner.rolloffFactor=e._pannerAttr.rolloffFactor,e._panner.panningModel=e._pannerAttr.panningModel,typeof e._panner.positionX<"u"?(e._panner.positionX.setValueAtTime(e._pos[0],Howler.ctx.currentTime),e._panner.positionY.setValueAtTime(e._pos[1],Howler.ctx.currentTime),e._panner.positionZ.setValueAtTime(e._pos[2],Howler.ctx.currentTime)):e._panner.setPosition(e._pos[0],e._pos[1],e._pos[2]),typeof e._panner.orientationX<"u"?(e._panner.orientationX.setValueAtTime(e._orientation[0],Howler.ctx.currentTime),e._panner.orientationY.setValueAtTime(e._orientation[1],Howler.ctx.currentTime),e._panner.orientationZ.setValueAtTime(e._orientation[2],Howler.ctx.currentTime)):e._panner.setOrientation(e._orientation[0],e._orientation[1],e._orientation[2])):(e._panner=Howler.ctx.createStereoPanner(),e._panner.pan.setValueAtTime(e._stereo,Howler.ctx.currentTime)),e._panner.connect(e._node),e._paused||e._parent.pause(e._id,!0).play(e._id,!0)}}()},(()=>(n||e((n={exports:{}}).exports,n),n.exports))()})(); |